Various formatting fixes
[tar.git] / doc / tar.texi
blobddbf8cba01b75c4c5f3e0f9f54d668d98b00f540
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
8 @documentencoding UTF-8
9 @c These two commands require Texinfo 5.0; for now use the older
10 @c equivalent @set commands supported in Texinfo 4.11 and later.
11 @ignore
12 @codequotebacktick on
13 @codequoteundirected on
14 @end ignore
15 @set txicodequoteundirected
16 @set txicodequotebacktick
18 @finalout
20 @smallbook
21 @c %**end of header
23 @c Maintenance notes:
24 @c  1. Pay attention to @FIXME{}s and @UNREVISED{}s
25 @c  2. Before creating final variant:
26 @c    2.1. Run 'make check-options' to make sure all options are properly
27 @c         documented;
28 @c    2.2. Run 'make master-menu' (see comment before the master menu).
30 @include rendition.texi
31 @include value.texi
33 @defcodeindex op
34 @defcodeindex kw
36 @c Put everything in one index (arbitrarily chosen to be the concept index).
37 @syncodeindex fn cp
38 @syncodeindex ky cp
39 @syncodeindex pg cp
40 @syncodeindex vr cp
41 @syncodeindex kw cp
43 @copying
45 This manual is for @acronym{GNU} @command{tar} (version
46 @value{VERSION}, @value{UPDATED}), which creates and extracts files
47 from archives.
49 Copyright @copyright{} 1992, 1994--1997, 1999--2001, 2003--2017,
50 2021--2024 Free Software Foundation, Inc.
52 @quotation
53 Permission is granted to copy, distribute and/or modify this document
54 under the terms of the GNU Free Documentation License, Version 1.3 or
55 any later version published by the Free Software Foundation; with the
56 Invariant Sections being ``GNU General Public License'', with the
57 Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
58 as in (a) below.  A copy of the license is included in the section
59 entitled ``GNU Free Documentation License''.
61 (a) The FSF's Back-Cover Text is: ``You have the freedom to
62 copy and modify this GNU manual.''
63 @end quotation
64 @end copying
66 @dircategory Archiving
67 @direntry
68 * Tar: (tar).                   Making tape (or disk) archives.
69 @end direntry
71 @dircategory Individual utilities
72 @direntry
73 * tar: (tar)tar invocation.                     Invoking @GNUTAR{}.
74 @end direntry
76 @shorttitlepage @acronym{GNU} @command{tar}
78 @titlepage
79 @title @acronym{GNU} tar: an archiver tool
80 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
81 @author John Gilmore, Jay Fenlason et al.
83 @page
84 @vskip 0pt plus 1filll
85 @insertcopying
86 @end titlepage
88 @ifnottex
89 @node Top
90 @top @acronym{GNU} tar: an archiver tool
92 @insertcopying
94 @cindex file archival
95 @cindex archiving files
97 The first part of this master menu lists the major nodes in this Info
98 document.  The rest of the menu lists all the lower level nodes.
99 @end ifnottex
101 @c The master menu goes here.
103 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
104 @c loaded and run texinfo-master-menu.
105 @c To update it from the command line, run
107 @c    make master-menu
109 @menu
110 * Introduction::
111 * Tutorial::
112 * tar invocation::
113 * operations::
114 * Backups::
115 * Choosing::
116 * Date input formats::
117 * Formats::
118 * Media::
119 * Reliability and security::
121 Appendices
123 * Changes::
124 * Recipes:: Frequently used tar recipes
125 * Configuring Help Summary::
126 * Fixing Snapshot Files::
127 * Tar Internals::
128 * Genfile::
129 * GNU Free Documentation License::
130 * Index of Command Line Options::
131 * Index::
133 @detailmenu
134  --- The Detailed Node Listing ---
136 Introduction
138 * Book Contents::               What this Book Contains
139 * Definitions::                 Some Definitions
140 * What tar Does::               What @command{tar} Does
141 * Naming tar Archives::         How @command{tar} Archives are Named
142 * Authors::                     @GNUTAR{} Authors
143 * Reports::                     Reporting bugs or suggestions
145 Tutorial Introduction to @command{tar}
147 * assumptions::
148 * stylistic conventions::
149 * basic tar options::           Basic @command{tar} Operations and Options
150 * frequent operations::
151 * Two Frequent Options::
152 * create::                      How to Create Archives
153 * list::                        How to List Archives
154 * extract::                     How to Extract Members from an Archive
155 * going further::
157 Two Frequently Used Options
159 * file tutorial::
160 * verbose tutorial::
161 * help tutorial::
163 How to Create Archives
165 * prepare for examples::
166 * Creating the archive::
167 * create verbose::
168 * short create::
169 * create dir::
171 How to List Archives
173 * list dir::
175 How to Extract Members from an Archive
177 * extracting archives::
178 * extracting files::
179 * extract dir::
180 * extracting untrusted archives::
181 * failing commands::
183 Invoking @GNUTAR{}
185 * Synopsis::
186 * using tar options::
187 * Styles::
188 * All Options::           All @command{tar} Options.
189 * help::                  Where to Get Help.
190 * defaults::              What are the Default Values.
191 * verbose::               Checking @command{tar} progress.
192 * checkpoints::           Checkpoints.
193 * warnings::              Controlling Warning Messages.
194 * interactive::           Asking for Confirmation During Operations.
195 * external::              Running External Commands.
197 The Three Option Styles
199 * Long Options::                Long Option Style
200 * Short Options::               Short Option Style
201 * Old Options::                 Old Option Style
202 * Mixing::                      Mixing Option Styles
204 All @command{tar} Options
206 * Operation Summary::
207 * Option Summary::
208 * Short Option Summary::
209 * Position-Sensitive Options::
211 Controlling Warning Messages
213 * General Warnings::  Keywords applicable for @command{tar --create}.
214 * Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
215 * Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
216 * Incremental Extraction Warnings:: Keywords controlling incremental extraction.
217 * Warning Classes:: Convenience keywords control multiple warnings.
218 * Warning Defaults:: Default settings for warnings.
220 @GNUTAR{} Operations
222 * Basic tar::
223 * Advanced tar::
224 * create options::
225 * extract options::
226 * backup::
227 * looking ahead::
229 Advanced @GNUTAR{} Operations
231 * Operations::
232 * append::
233 * update::
234 * concatenate::
235 * delete::
236 * compare::
238 How to Add Files to Existing Archives: @option{--append}
240 * appending files::             Appending Files to an Archive
241 * multiple::
243 Updating an Archive
245 * how to update::
247 Options Used by @option{--create}
249 * override::                  Overriding File Metadata.
250 * Extended File Attributes::
251 * Ignore Failed Read::
253 Options Used by @option{--extract}
255 * Reading::                     Options to Help Read Archives
256 * Writing::                     Changing How @command{tar} Writes Files
257 * Scarce::                      Coping with Scarce Resources
259 Options to Help Read Archives
261 * read full records::
262 * Ignore Zeros::
264 Changing How @command{tar} Writes Files
266 * Dealing with Old Files::
267 * Overwrite Old Files::
268 * Keep Old Files::
269 * Keep Newer Files::
270 * Unlink First::
271 * Recursive Unlink::
272 * Data Modification Times::
273 * Setting Access Permissions::
274 * Directory Modification Times and Permissions::
275 * Writing to Standard Output::
276 * Writing to an External Program::
277 * remove files::
279 Coping with Scarce Resources
281 * Starting File::
282 * Same Order::
284 Performing Backups and Restoring Files
286 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
287 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
288 * Backup Levels::               Levels of Backups
289 * Backup Parameters::           Setting Parameters for Backups and Restoration
290 * Scripted Backups::            Using the Backup Scripts
291 * Scripted Restoration::        Using the Restore Script
293 Setting Parameters for Backups and Restoration
295 * General-Purpose Variables::
296 * Magnetic Tape Control::
297 * User Hooks::
298 * backup-specs example::        An Example Text of @file{Backup-specs}
300 Choosing Files and Names for @command{tar}
302 * file::                        Choosing the Archive's Name
303 * Selecting Archive Members::
304 * files::                       Reading Names from a File
305 * exclude::                     Excluding Some Files
306 * wildcards::                   Wildcards Patterns and Matching
307 * quoting styles::              Ways of Quoting Special Characters in Names
308 * transform::                   Modifying File and Member Names
309 * after::                       Operating Only on New Files
310 * recurse::                     Descending into Directories
311 * one::                         Crossing File System Boundaries
313 Reading Names from a File
315 * nul::
317 Excluding Some Files
319 * problems with exclude::
321 Wildcards Patterns and Matching
323 * controlling pattern-matching::
325 Crossing File System Boundaries
327 * directory::                   Changing Directory
328 * absolute::                    Absolute File Names
330 Date input formats
332 * General date syntax::          Common rules
333 * Calendar date items::          21 Jul 2020
334 * Time of day items::            9:20pm
335 * Time zone items::              UTC, -0700, +0900, @dots{}
336 * Combined date and time of day items:: 2020-07-21T20:02:00,000000-0400
337 * Day of week items::            Monday and others
338 * Relative items in date strings:: next tuesday, 2 years ago
339 * Pure numbers in date strings:: 20200721, 1440
340 * Seconds since the Epoch::      @@1595289600
341 * Specifying time zone rules::   TZ="America/New_York", TZ="UTC0"
342 * Authors of parse_datetime::    Bellovin, Eggert, Salz, Berets, et al.
344 Controlling the Archive Format
346 * Compression::                 Using Less Space through Compression
347 * Attributes::                  Handling File Attributes
348 * Portability::                 Making @command{tar} Archives More Portable
349 * Reproducibility::             Making @command{tar} Archives More Reproducible
350 * cpio::                        Comparison of @command{tar} and @command{cpio}
352 Using Less Space through Compression
354 * gzip::                        Creating and Reading Compressed Archives
355 * sparse::                      Archiving Sparse Files
357 Creating and Reading Compressed Archives
359 * lbzip2::  Using lbzip2 with @GNUTAR{}.
361 Making @command{tar} Archives More Portable
363 * Portable Names::              Portable Names
364 * dereference::                 Symbolic Links
365 * hard links::                  Hard Links
366 * old::                         Old V7 Archives
367 * ustar::                       Ustar Archives
368 * gnu::                         GNU and old GNU format archives.
369 * posix::                       @acronym{POSIX} archives
370 * Checksumming::                Checksumming Problems
371 * Large or Negative Values::    Large files, negative time stamps, etc.
372 * Other Tars::                  How to Extract GNU-Specific Data Using
373                                 Other @command{tar} Implementations
375 @GNUTAR{} and @acronym{POSIX} @command{tar}
377 * PAX keywords:: Controlling Extended Header Keywords.
379 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
381 * Split Recovery::       Members Split Between Volumes
382 * Sparse Recovery::      Sparse Members
384 Tapes and Other Archive Media
386 * Device::                      Device selection and switching
387 * Remote Tape Server::
388 * Common Problems and Solutions::
389 * Blocking::                    Blocking
390 * Many::                        Many archives on one tape
391 * Using Multiple Tapes::        Using Multiple Tapes
392 * label::                       Including a Label in the Archive
393 * verify::
394 * Write Protection::
396 Blocking
398 * Format Variations::           Format Variations
399 * Blocking Factor::             The Blocking Factor of an Archive
401 Many Archives on One Tape
403 * Tape Positioning::            Tape Positions and Tape Marks
404 * mt::                          The @command{mt} Utility
406 Using Multiple Tapes
408 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
409 * Tape Files::                  Tape Files
410 * Tarcat::                      Concatenate Volumes into a Single Archive
413 Reliability and Security
415 * Reliability::
416 * Security::
418 Reliability
420 * Permissions problems::
421 * Data corruption and repair::
422 * Race conditions::
424 Security
426 * Privacy::
427 * Integrity::
428 * Live untrusted data::
429 * Security rules of thumb::
431 Recipes
433 * copy directory hierarchy::
434 * intermediate directories::
436 Tar Internals
438 * Standard::           Basic Tar Format
439 * Extensions::         @acronym{GNU} Extensions to the Archive Format
440 * Sparse Formats::     Storing Sparse Files
441 * Snapshot Files::
442 * Dumpdir::
444 Storing Sparse Files
446 * Old GNU Format::
447 * PAX 0::                PAX Format, Versions 0.0 and 0.1
448 * PAX 1::                PAX Format, Version 1.0
450 Genfile
452 * Generate Mode::     File Generation Mode.
453 * Status Mode::       File Status Mode.
454 * Exec Mode::         Synchronous Execution mode.
456 Copying This Manual
458 * GNU Free Documentation License::  License for copying this manual.
460 @end detailmenu
461 @end menu
463 @node Introduction
464 @chapter Introduction
466 @GNUTAR{} creates
467 and manipulates @dfn{archives} which are actually collections of
468 many other files; the program provides users with an organized and
469 systematic method for controlling a large amount of data.
470 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
471 archives need not (and these days, typically do not) reside on tapes.
473 @menu
474 * Book Contents::               What this Book Contains
475 * Definitions::                 Some Definitions
476 * What tar Does::               What @command{tar} Does
477 * Naming tar Archives::         How @command{tar} Archives are Named
478 * Authors::                     @GNUTAR{} Authors
479 * Reports::                     Reporting bugs or suggestions
480 @end menu
482 @node Book Contents
483 @section What this Book Contains
485 The first part of this chapter introduces you to various terms that will
486 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
487 and its documentation, and where you should send bug reports
488 or comments.
490 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
491 gentle introduction for people who are new to using @command{tar}.  It is
492 meant to be self-contained, not requiring any reading from subsequent
493 chapters to make sense.  It moves from topic to topic in a logical,
494 progressive order, building on information already explained.
496 Although the tutorial is paced and structured to allow beginners to
497 learn how to use @command{tar}, it is not intended solely for beginners.
498 The tutorial explains how to use the three most frequently used
499 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
500 two frequently used options (@samp{file} and @samp{verbose}).  The other
501 chapters do not refer to the tutorial frequently; however, if a section
502 discusses something which is a complex variant of a basic concept, there
503 may be a cross-reference to that basic concept.  (The entire book,
504 including the tutorial, assumes that the reader understands some basic
505 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
507 The third chapter presents the remaining five operations, and
508 information about using @command{tar} options and option syntax.
510 The other chapters are meant to be used as a reference.  Each chapter
511 presents everything that needs to be said about a specific topic.
513 One of the chapters (@pxref{Date input formats}) exists in its
514 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
515 In addition, one section of this manual (@pxref{Standard}) contains a
516 big quote which is taken directly from @command{tar} sources.
518 In general, we give both long and short (abbreviated) option names
519 at least once in each section where the relevant option is covered, so
520 that novice readers will become familiar with both styles.  (A few
521 options have no short versions, and the relevant sections will
522 indicate this.)
524 @node Definitions
525 @section Some Definitions
527 @cindex archive
528 @cindex tar archive
529 The @command{tar} program is used to create and manipulate @command{tar}
530 archives.  An @dfn{archive} is a single file which contains the contents
531 of many files, while still identifying the names of the files, their
532 owner(s), and so forth.  (In addition, archives record access
533 permissions, user and group, size in bytes, and data modification time.
534 Some archives also record the file names in each archived directory, as
535 well as other file and directory information.)  You can use @command{tar}
536 to @dfn{create} a new archive in a specified directory.
538 @cindex member
539 @cindex archive member
540 @cindex file name
541 @cindex member name
542 The files inside an archive are called @dfn{members}.  Within this
543 manual, we use the term @dfn{file} to refer only to files accessible in
544 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
545 @dfn{member} to refer only to the members of an archive.  Similarly, a
546 @dfn{file name} is the name of a file, as it resides in the file system,
547 and a @dfn{member name} is the name of an archive member within the
548 archive.
550 @cindex extraction
551 @cindex unpacking
552 The term @dfn{extraction} refers to the process of copying an archive
553 member (or multiple members) into a file in the file system.  Extracting
554 all the members of an archive is often called @dfn{extracting the
555 archive}.  The term @dfn{unpack} can also be used to refer to the
556 extraction of many or all the members of an archive.  Extracting an
557 archive does not destroy the archive's structure, just as creating an
558 archive does not destroy the copies of the files that exist outside of
559 the archive.  You may also @dfn{list} the members in a given archive
560 (this is often thought of as ``printing'' them to the standard output,
561 or the command line), or @dfn{append} members to a pre-existing archive.
562 All of these operations can be performed using @command{tar}.
564 @node What tar Does
565 @section What @command{tar} Does
567 @cindex tar
568 The @command{tar} program provides the ability to create @command{tar}
569 archives, as well as various other kinds of manipulation.  For example,
570 you can use @command{tar} on previously created archives to extract files,
571 to store additional files, or to update or list files which were already
572 stored.
574 Initially, @command{tar} archives were used to store files conveniently on
575 magnetic tape.  The name @command{tar} comes from this use; it stands for
576 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
577 direct its output to available devices, files, or other programs (using
578 pipes).  @command{tar} may even access remote devices or files (as archives).
580 You can use @command{tar} archives in many ways.  We want to stress a few
581 of them: storage, backup, and transportation.
583 @FIXME{the following table entries need a bit of work.}
584 @table @asis
585 @item Storage
586 Often, @command{tar} archives are used to store related files for
587 convenient file transfer over a network.  For example, the
588 @acronym{GNU} Project distributes its software bundled into
589 @command{tar} archives, so that all the files relating to a particular
590 program (or set of related programs) can be transferred as a single
591 unit.
593 A magnetic tape can store several files in sequence.  However, the tape
594 has no names for these files; it only knows their relative position on
595 the tape.  One way to store several files on one tape and retain their
596 names is by creating a @command{tar} archive.  Even when the basic transfer
597 mechanism can keep track of names, as FTP can, the nuisance of handling
598 multiple files, directories, and multiple links makes @command{tar}
599 archives useful.
601 Archive files are also used for long-term storage.  You can think of
602 this as transportation from the present into the future.  (It is a
603 science-fiction idiom that you can move through time as well as in
604 space; the idea here is that @command{tar} can be used to move archives in
605 all dimensions, even time!)
607 @item Backup
608 Because the archive created by @command{tar} is capable of preserving
609 file information and directory structure, @command{tar} is commonly
610 used for performing full and incremental backups of disks.  A backup
611 puts a collection of files (possibly pertaining to many users and
612 projects) together on a disk or a tape.  This guards against
613 accidental destruction of the information in those files.
614 @GNUTAR{} has special features that allow it to be
615 used to make incremental and full dumps of all the files in a
616 file system.
618 @item Transportation
619 You can create an archive on one system, transfer it to another system,
620 and extract the contents there.  This allows you to transport a group of
621 files from one system to another.
622 @end table
624 @node Naming tar Archives
625 @section How @command{tar} Archives are Named
627 Conventionally, @command{tar} archives are given names ending with
628 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
629 but this manual follows that convention in order to accustom readers to
630 it and to make examples more clear.
632 @cindex tar file
633 @cindex entry
634 @cindex tar entry
635 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
636 archive members as ``files'' or ``entries''.  For people familiar with
637 the operation of @command{tar}, this causes no difficulty.  However, in
638 this manual, we consistently refer to ``archives'' and ``archive
639 members'' to make learning to use @command{tar} easier for novice users.
641 @node Authors
642 @section @GNUTAR{} Authors
644 @GNUTAR{} was originally written by John Gilmore,
645 and modified by many people.  The @acronym{GNU} enhancements were
646 written by Jay Fenlason, then Joy Kendall, and the whole package has
647 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
648 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
649 numerous and kind users.
651 We wish to stress that @command{tar} is a collective work, and owes much to
652 all those people who reported problems, offered solutions and other
653 insights, or shared their thoughts and suggestions.  An impressive, yet
654 partial list of those contributors can be found in the @file{THANKS}
655 file from the @GNUTAR{} distribution.
657 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
658 sure i want to spell out the history in this detail, at least not for
659 the printed book.  i'm just not sure it needs to be said this way.
660 i'll think about it.}
662 @FIXME{History is more important, and surely more interesting, than
663 actual names.  Quoting names without history would be meaningless.  FP}
665 Jay Fenlason put together a draft of a @GNUTAR{}
666 manual, borrowing notes from the original man page from John Gilmore.
667 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
668 Gorin worked on a tutorial and manual for @GNUTAR{}.
669 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
670 taking information from all these sources and merging them.  Melissa
671 Weisshaus finally edited and redesigned the book to create version
672 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
673 by the current maintainer, Sergey Poznyakoff.
675 For version 1.12, Daniel Hagerty contributed a great deal of technical
676 consulting.  In particular, he is the primary author of @ref{Backups}.
678 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
679 (see @url{https://savannah.gnu.org/projects/tar}), and
680 active development and maintenance work has started
681 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
682 Poznyakoff and Jeff Bailey.
684 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
686 @node Reports
687 @section Reporting bugs or suggestions
689 @cindex bug reports
690 @cindex reporting bugs
691 If you find problems or have suggestions about this program or manual,
692 please report them to @file{bug-tar@@gnu.org}.
694 When reporting a bug, please be sure to include as much detail as
695 possible, in order to reproduce it.
696 @FIXME{Be more specific, I'd like to make this node as detailed as
697 'Bug reporting' node in Emacs manual.}
699 @node Tutorial
700 @chapter Tutorial Introduction to @command{tar}
702 This chapter guides you through some basic examples of three @command{tar}
703 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
704 you already know how to use some other version of @command{tar}, then you
705 may not need to read this chapter.  This chapter omits most complicated
706 details about how @command{tar} works.
708 @menu
709 * assumptions::
710 * stylistic conventions::
711 * basic tar options::           Basic @command{tar} Operations and Options
712 * frequent operations::
713 * Two Frequent Options::
714 * create::                      How to Create Archives
715 * list::                        How to List Archives
716 * extract::                     How to Extract Members from an Archive
717 * going further::
718 @end menu
720 @node assumptions
721 @section Assumptions this Tutorial Makes
723 This chapter is paced to allow beginners to learn about @command{tar}
724 slowly.  At the same time, we will try to cover all the basic aspects of
725 these three operations.  In order to accomplish both of these tasks, we
726 have made certain assumptions about your knowledge before reading this
727 manual, and the hardware you will be using:
729 @itemize @bullet
730 @item
731 Before you start to work through this tutorial, you should understand
732 what the terms ``archive'' and ``archive member'' mean
733 (@pxref{Definitions}).  In addition, you should understand something
734 about how Unix-type operating systems work, and you should know how to
735 use some basic utilities.  For example, you should know how to create,
736 list, copy, rename, edit, and delete files and directories; how to
737 change between directories; and how to figure out where you are in the
738 file system.  You should have some basic understanding of directory
739 structure and how files are named according to which directory they are
740 in.  You should understand concepts such as standard output and standard
741 input, what various definitions of the term @samp{argument} mean, and the
742 differences between relative and absolute file names.
743 @FIXME{and what else?}
745 @item
746 This manual assumes that you are working from your own home directory
747 (unless we state otherwise).  In this tutorial, you will create a
748 directory to practice @command{tar} commands in.  When we show file names,
749 we will assume that those names are relative to your home directory.
750 For example, my home directory is @file{/home/fsf/melissa}.  All of
751 my examples are in a subdirectory of the directory named by that file
752 name; the subdirectory is called @file{practice}.
754 @item
755 In general, we show examples of archives which exist on (or can be
756 written to, or worked with from) a directory on a hard disk.  In most
757 cases, you could write those archives to, or work with them on any other
758 device, such as a tape drive.  However, some of the later examples in
759 the tutorial and next chapter will not work on tape drives.
760 Additionally, working with tapes is much more complicated than working
761 with hard disks.  For these reasons, the tutorial does not cover working
762 with tape drives.  @xref{Media}, for complete information on using
763 @command{tar} archives with tape drives.
765 @FIXME{this is a cop out.  need to add some simple tape drive info.}
766 @end itemize
768 @node stylistic conventions
769 @section Stylistic Conventions
771 In the examples, @samp{$} represents a typical shell prompt.  It
772 precedes lines you should type; to make this more clear, those lines are
773 shown in @kbd{this font}, as opposed to lines which represent the
774 computer's response; those lines are shown in @code{this font}, or
775 sometimes @samp{like this}.
777 @c When we have lines which are too long to be
778 @c displayed in any other way, we will show them like this:
780 @node basic tar options
781 @section Basic @command{tar} Operations and Options
783 @command{tar} can take a wide variety of arguments which specify and define
784 the actions it will have on the particular set of files or the archive.
785 The main types of arguments to @command{tar} fall into one of two classes:
786 operations, and options.
788 Some arguments fall into a class called @dfn{operations}; exactly one of
789 these is both allowed and required for any instance of using @command{tar};
790 you may @emph{not} specify more than one.  People sometimes speak of
791 @dfn{operating modes}.  You are in a particular operating mode when you
792 have specified the operation which specifies it; there are eight
793 operations in total, and thus there are eight operating modes.
795 The other arguments fall into the class known as @dfn{options}.  You are
796 not required to specify any options, and you are allowed to specify more
797 than one at a time (depending on the way you are using @command{tar} at
798 that time).  Some options are used so frequently, and are so useful for
799 helping you type commands more carefully that they are effectively
800 ``required''.  We will discuss them in this chapter.
802 You can write most of the @command{tar} operations and options in any
803 of three forms: long (mnemonic) form, short form, and old style.  Some
804 of the operations and options have no short or ``old'' forms; however,
805 the operations and options which we will cover in this tutorial have
806 corresponding abbreviations.  We will indicate those abbreviations
807 appropriately to get you used to seeing them.  Note, that the ``old
808 style'' option forms exist in @GNUTAR{} for compatibility with Unix
809 @command{tar}.  In this book we present a full discussion of this way
810 of writing options and operations (@pxref{Old Options}), and we discuss
811 the other two styles of writing options (@xref{Long Options}, and
812 @pxref{Short Options}).
814 In the examples and in the text of this tutorial, we usually use the
815 long forms of operations and options; but the ``short'' forms produce
816 the same result and can make typing long @command{tar} commands easier.
817 For example, instead of typing
819 @smallexample
820 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
821 @end smallexample
823 @noindent
824 you can type
825 @smallexample
826 @kbd{tar -c -v -f afiles.tar apple angst aspic}
827 @end smallexample
829 @noindent
830 or even
831 @smallexample
832 @kbd{tar -cvf afiles.tar apple angst aspic}
833 @end smallexample
835 @noindent
836 For more information on option syntax, see @ref{Advanced tar}.  In
837 discussions in the text, when we name an option by its long form, we
838 also give the corresponding short option in parentheses.
840 The term, ``option'', can be confusing at times, since ``operations''
841 are often lumped in with the actual, @emph{optional} ``options'' in certain
842 general class statements.  For example, we just talked about ``short and
843 long forms of options and operations''.  However, experienced @command{tar}
844 users often refer to these by shorthand terms such as, ``short and long
845 options''.  This term assumes that the ``operations'' are included, also.
846 Context will help you determine which definition of ``options'' to use.
848 Similarly, the term ``command'' can be confusing, as it is often used in
849 two different ways.  People sometimes refer to @command{tar} ``commands''.
850 A @command{tar} @dfn{command} is the entire command line of user input
851 which tells @command{tar} what to do --- including the operation, options,
852 and any arguments (file names, pipes, other commands, etc.).  However,
853 you will also sometimes hear the term ``the @command{tar} command''.  When
854 the word ``command'' is used specifically like this, a person is usually
855 referring to the @command{tar} @emph{operation}, not the whole line.
856 Again, use context to figure out which of the meanings the speaker
857 intends.
859 @node frequent operations
860 @section The Three Most Frequently Used Operations
862 Here are the three most frequently used operations (both short and long
863 forms), as well as a brief description of their meanings.  The rest of
864 this chapter will cover how to use these operations in detail.  We will
865 present the rest of the operations in the next chapter.
867 @table @option
868 @item --create
869 @itemx -c
870 Create a new @command{tar} archive.
871 @item --list
872 @itemx -t
873 List the contents of an archive.
874 @item --extract
875 @itemx -x
876 Extract one or more members from an archive.
877 @end table
879 @node Two Frequent Options
880 @section Two Frequently Used Options
882 To understand how to run @command{tar} in the three operating modes listed
883 previously, you also need to understand how to use two of the options to
884 @command{tar}: @option{--file} (which takes an archive file as an argument)
885 and @option{--verbose}.  (You are usually not @emph{required} to specify
886 either of these options when you run @command{tar}, but they can be very
887 useful in making things more clear and helping you avoid errors.)
889 @menu
890 * file tutorial::
891 * verbose tutorial::
892 * help tutorial::
893 @end menu
895 @node file tutorial
896 @unnumberedsubsec The @option{--file} Option
898 @table @option
899 @xopindex{file, tutorial}
900 @item --file=@var{archive-name}
901 @itemx -f @var{archive-name}
902 Specify the name of an archive file.
903 @end table
905 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
906 use @command{tar}; this option determines the name of the archive file
907 that @command{tar} will work on.
909 @vrindex TAPE
910 If you don't specify this argument, then @command{tar} will examine
911 the environment variable @env{TAPE}.  If it is set, its value will be
912 used as the archive name.  Otherwise, @command{tar} will use the
913 default archive, determined at compile time. Usually it is
914 standard output or some physical tape drive attached to your machine
915 (you can verify what the default is by running @kbd{tar
916 --show-defaults}, @pxref{defaults}).  If there is no tape drive
917 attached, or the default is not meaningful, then @command{tar} will
918 print an error message.  The error message might look roughly like one
919 of the following:
921 @smallexample
922 tar: can't open /dev/rmt8 : No such device or address
923 tar: can't open /dev/rsmt0 : I/O error
924 @end smallexample
926 @noindent
927 To avoid confusion, we recommend that you always specify an archive file
928 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
929 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
930 @ref{file}.
932 @node verbose tutorial
933 @unnumberedsubsec The @option{--verbose} Option
935 @table @option
936 @xopindex{verbose, introduced}
937 @item --verbose
938 @itemx -v
939 Show the files being worked on as @command{tar} is running.
940 @end table
942 @option{--verbose} (@option{-v}) shows details about the results of running
943 @command{tar}.  This can be especially useful when the results might not be
944 obvious.  For example, if you want to see the progress of @command{tar} as
945 it writes files into the archive, you can use the @option{--verbose}
946 option.  In the beginning, you may find it useful to use
947 @option{--verbose} at all times; when you are more accustomed to
948 @command{tar}, you will likely want to use it at certain times but not at
949 others.  We will use @option{--verbose} at times to help make something
950 clear, and we will give many examples both using and not using
951 @option{--verbose} to show the differences.
953 Each instance of @option{--verbose} on the command line increases the
954 verbosity level by one, so if you need more details on the output,
955 specify it twice.
957 When reading archives (@option{--list}, @option{--extract},
958 @option{--diff}), @command{tar} by default prints only the names of
959 the members being extracted.  Using @option{--verbose} will show a full,
960 @command{ls} style member listing.
962 In contrast, when writing archives (@option{--create}, @option{--append},
963 @option{--update}), @command{tar} does not print file names by
964 default.  So, a single @option{--verbose} option shows the file names
965 being added to the archive, while two @option{--verbose} options
966 enable the full listing.
968 For example, to create an archive in verbose mode:
970 @smallexample
971 $ @kbd{tar -cvf afiles.tar apple angst aspic}
972 apple
973 angst
974 aspic
975 @end smallexample
977 @noindent
978 Creating the same archive with the verbosity level 2 could give:
980 @smallexample
981 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
982 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
983 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
984 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
985 @end smallexample
987 @noindent
988 This works equally well using short or long forms of options.  Using
989 long forms, you would simply write out the mnemonic form of the option
990 twice, like this:
992 @smallexample
993 $ @kbd{tar --create --verbose --verbose @dots{}}
994 @end smallexample
996 @noindent
997 Note that you must double the hyphens properly each time.
999 Later in the tutorial, we will give examples using @w{@option{--verbose
1000 --verbose}}.
1002 The @option{--verbose} option also enables several @dfn{warning
1003 messages}, that tar does not issue otherwise, such as the
1004 warning about record size being used (@pxref{Blocking Factor}), selecting
1005 the decompress program and the like.  If these are of no interest to
1006 you, you can suppress them using the @option{--warning} option
1007 @emph{after} @option{--verbose}, e.g.:
1009 @example
1010 $ @kbd{tar -c -v --warning=no-verbose -f afiles.tar apple angst aspic}
1011 @end example
1013 @xref{Warning Classes, verbose}, for details.
1015 @anchor{verbose member listing}
1016 The full output consists of six fields:
1018 @itemize @bullet
1019 @item File type and permissions in symbolic form.
1020 These are displayed in the same format as the first column of
1021 @command{ls -l} output (@pxref{What information is listed,
1022 format=verbose, Verbose listing, coreutils, GNU core utilities}).
1024 @item Owner name and group separated by a slash character.
1025 If these data are not available (for example, when listing a @samp{v7} format
1026 archive), numeric @acronym{ID} values are printed instead.
1028 @item Size of the file, in bytes.
1030 @item File modification date in ISO 8601 format.
1032 @item File modification time.
1034 @item File name.
1035 If the name contains any special characters (white space, newlines,
1036 etc.)@: these are displayed in an unambiguous form using so called
1037 @dfn{quoting style}.  For the detailed discussion of available styles
1038 and on how to use them, see @ref{quoting styles}.
1040 Depending on the file type, the name can be followed by some
1041 additional information, described in the following table:
1043 @table @samp
1044 @item -> @var{link-name}
1045 The file or archive member is a @dfn{symbolic link} and
1046 @var{link-name} is the name of file it links to.
1048 @item link to @var{link-name}
1049 The file or archive member is a @dfn{hard link} and @var{link-name} is
1050 the name of file it links to.
1052 @item --Long Link--
1053 The archive member is an old GNU format long link.  You will normally
1054 not encounter this.
1056 @item --Long Name--
1057 The archive member is an old GNU format long name.  You will normally
1058 not encounter this.
1060 @item --Volume Header--
1061 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1063 @item --Continued at byte @var{n}--
1064 Encountered only at the beginning of a multi-volume archive
1065 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1066 from the previous volume. The number @var{n} gives the offset where
1067 the original file was split.
1069 @item  unknown file type @var{c}
1070 An archive member of unknown type. @var{c} is the type character from
1071 the archive header.  If you encounter such a message, it means that
1072 either your archive contains proprietary member types @GNUTAR{} is not
1073 able to handle, or the archive is corrupted.
1074 @end table
1076 @end itemize
1078 For example, here is an archive listing containing most of the special
1079 suffixes explained above:
1081 @smallexample
1082 @group
1083 V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
1084 -rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1085 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
1086 lrwxrwxrwx gray/staff        0 2006-06-09 13:01 angst -> apple
1087 -rw-r--r-- gray/staff    35793 2006-06-09 12:06 blues
1088 hrw-r--r-- gray/staff        0 2006-06-09 12:06 music link to blues
1089 @end group
1090 @end smallexample
1092 @node help tutorial
1093 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1095 @table @option
1096 @opindex help
1097 @item --help
1099 The @option{--help} option to @command{tar} prints out a very brief list of
1100 all operations and option available for the current version of
1101 @command{tar} available on your system.
1102 @end table
1104 @node create
1105 @section How to Create Archives
1107 @cindex Creation of the archive
1108 @cindex Archive, creation of
1109 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1110 you use to create a @command{tar} archive.  We will explain
1111 @option{--create} first because, in order to learn about the other
1112 operations, you will find it useful to have an archive available to
1113 practice on.
1115 To make this easier, in this section you will first create a directory
1116 containing three files.  Then, we will show you how to create an
1117 @emph{archive} (inside the new directory).  Both the directory, and
1118 the archive are specifically for you to practice on.  The rest of this
1119 chapter and the next chapter will show many examples using this
1120 directory and the files you will create: some of those files may be
1121 other directories and other archives.
1123 The three files you will archive in this example are called
1124 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1125 @file{collection.tar}.
1127 This section will proceed slowly, detailing how to use @option{--create}
1128 in @code{verbose} mode, and showing examples using both short and long
1129 forms.  In the rest of the tutorial, and in the examples in the next
1130 chapter, we will proceed at a slightly quicker pace.  This section
1131 moves more slowly to allow beginning users to understand how
1132 @command{tar} works.
1134 @menu
1135 * prepare for examples::
1136 * Creating the archive::
1137 * create verbose::
1138 * short create::
1139 * create dir::
1140 @end menu
1142 @node prepare for examples
1143 @subsection Preparing a Practice Directory for Examples
1145 To follow along with this and future examples, create a new directory
1146 called @file{practice} containing files called @file{blues}, @file{folk}
1147 and @file{jazz}.  The files can contain any information you like:
1148 ideally, they should contain information which relates to their names,
1149 and be of different lengths.  Our examples assume that @file{practice}
1150 is a subdirectory of your home directory.
1152 Now @command{cd} to the directory named @file{practice}; @file{practice}
1153 is now your @dfn{working directory}.  (@emph{Please note}: Although
1154 the full file name of this directory is
1155 @file{/@var{homedir}/practice}, in our examples we will refer to
1156 this directory as @file{practice}; the @var{homedir} is presumed.)
1158 In general, you should check that the files to be archived exist where
1159 you think they do (in the working directory) by running @command{ls}.
1160 Because you just created the directory and the files and have changed to
1161 that directory, you probably don't need to do that this time.
1163 It is very important to make sure there isn't already a file in the
1164 working directory with the archive name you intend to use (in this case,
1165 @samp{collection.tar}), or that you don't care about its contents.
1166 Whenever you use @samp{create}, @command{tar} will erase the current
1167 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1168 will not tell you if you are about to overwrite an archive unless you
1169 specify an option which does this (@pxref{backup}, for the
1170 information on how to do so).  To add files to an existing archive,
1171 you need to use a different option, such as @option{--append} (@option{-r}); see
1172 @ref{append} for information on how to do this.
1174 @node Creating the archive
1175 @subsection Creating the Archive
1177 @xopindex{create, introduced}
1178 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1179 archive named @file{collection.tar}, use the following command:
1181 @smallexample
1182 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1183 @end smallexample
1185 The order of the arguments is not very important, @emph{when using long
1186 option forms}, however you should always remember to use option as the
1187 first argument to tar.   For example, the following is wrong:
1189 @smallexample
1190 $ @kbd{tar blues -c folk -f collection.tar jazz}
1191 tar: -c: Invalid blocking factor
1192 Try 'tar --help' or 'tar --usage' for more information.
1193 @end smallexample
1195 The error message is produced because @command{tar} always treats its
1196 first argument as an option (or cluster of options), even if it does
1197 not start with dash.  This is @dfn{traditional} or @dfn{old option}
1198 style, called so because all implementations of @command{tar} have
1199 used it since the very inception of the tar archiver in 1970s.  This
1200 option style will be explained later (@pxref{Old Options}), for now
1201 just remember to always place option as the first argument.
1203 That being said, you could issue the following command:
1205 @smallexample
1206 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1207 @end smallexample
1209 @noindent
1210 However, you can see that this order is harder to understand; this is
1211 why we will list the arguments in the order that makes the commands
1212 easiest to understand (and we encourage you to do the same when you use
1213 @command{tar}, to avoid errors).
1215 Note that the sequence
1216 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1217 If you substituted any other string of characters for
1218 @kbd{collection.tar},  then that string would become the name of the
1219 archive file you create.
1221 The order of the options becomes more important when you begin to use
1222 short forms.  With short forms, if you type commands in the wrong order
1223 (even if you type them correctly in all other ways), you may end up with
1224 results you don't expect.  For this reason, it is a good idea to get
1225 into the habit of typing options in the order that makes inherent sense.
1226 @xref{short create}, for more information on this.
1228 In this example, you type the command as shown above: @option{--create}
1229 is the operation which creates the new archive
1230 (@file{collection.tar}), and @option{--file} is the option which lets
1231 you give it the name you chose.  The files, @file{blues}, @file{folk},
1232 and @file{jazz}, are now members of the archive, @file{collection.tar}
1233 (they are @dfn{file name arguments} to the @option{--create} operation.
1234 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1235 in the archive, they are called @emph{archive members}, not files.
1236 (@pxref{Definitions,members}).
1238 When you create an archive, you @emph{must} specify which files you
1239 want placed in the archive.  If you do not specify any archive
1240 members, @GNUTAR{} will complain.
1242 If you now list the contents of the working directory (@command{ls}), you will
1243 find the archive file listed as well as the files you saw previously:
1245 @smallexample
1246 blues   folk   jazz   collection.tar
1247 @end smallexample
1249 @noindent
1250 Creating the archive @samp{collection.tar} did not destroy the copies of
1251 the files in the directory.
1253 Keep in mind that if you don't indicate an operation, @command{tar} will not
1254 run and will prompt you for one.  If you don't name any files, @command{tar}
1255 will complain.  You must have write access to the working directory,
1256 or else you will not be able to create an archive in that directory.
1258 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1259 an existing archive; it will delete the archive and write a new one.
1260 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1262 @node create verbose
1263 @subsection Running @option{--create} with @option{--verbose}
1265 @xopindex{create, using with @option{--verbose}}
1266 @xopindex{verbose, using with @option{--create}}
1267 If you include the @option{--verbose} (@option{-v}) option on the command line,
1268 @command{tar} will list the files it is acting on as it is working.  In
1269 verbose mode, the @code{create} example above would appear as:
1271 @smallexample
1272 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1273 blues
1274 folk
1275 jazz
1276 @end smallexample
1278 This example is just like the example we showed which did not use
1279 @option{--verbose}, except that @command{tar} generated three output
1280 lines.
1282 In the rest of the examples in this chapter, we will frequently use
1283 @code{verbose} mode so we can show actions or @command{tar} responses that
1284 you would otherwise not see, and which are important for you to
1285 understand.
1287 @node short create
1288 @subsection Short Forms with @samp{create}
1290 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1291 basic uses of @command{tar}, and you will use it countless times.
1292 Eventually, you will probably want to use abbreviated (or ``short'')
1293 forms of options.  A full discussion of the three different forms that
1294 options can take appears in @ref{Styles}; for now, here is what the
1295 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1296 using short option forms:
1298 @smallexample
1299 $ @kbd{tar -cvf collection.tar blues folk jazz}
1300 blues
1301 folk
1302 jazz
1303 @end smallexample
1305 @noindent
1306 As you can see, the system responds the same no matter whether you use
1307 long or short option forms.
1309 @FIXME{i don't like how this is worded:} One difference between using
1310 short and long option forms is that, although the exact placement of
1311 arguments following options is no more specific when using short forms,
1312 it is easier to become confused and make a mistake when using short
1313 forms.  For example, suppose you attempted the above example in the
1314 following way:
1316 @smallexample
1317 $ @kbd{tar -cfv collection.tar blues folk jazz}
1318 @end smallexample
1320 @noindent
1321 In this case, @command{tar} will make an archive file called @file{v},
1322 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1323 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1324 is thus taken to be the chosen archive file name.  @command{tar} will try
1325 to add a file called @file{collection.tar} to the @file{v} archive file;
1326 if the file @file{collection.tar} did not already exist, @command{tar} will
1327 report an error indicating that this file does not exist.  If the file
1328 @file{collection.tar} does already exist (e.g., from a previous command
1329 you may have run), then @command{tar} will add this file to the archive.
1330 Because the @option{-v} option did not get registered, @command{tar} will not
1331 run under @samp{verbose} mode, and will not report its progress.
1333 The end result is that you may be quite confused about what happened,
1334 and possibly overwrite a file.  To illustrate this further, we will show
1335 you how an example we showed previously would look using short forms.
1337 This example,
1339 @smallexample
1340 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1341 @end smallexample
1343 @noindent
1344 is confusing as it is.  It becomes even more so when using short forms:
1346 @smallexample
1347 $ @kbd{tar -c folk blues -f collection.tar jazz}
1348 @end smallexample
1350 @noindent
1351 It would be very easy to put the wrong string of characters
1352 immediately following the @option{-f}, but doing that could sacrifice
1353 valuable data.
1355 For this reason, we recommend that you pay very careful attention to
1356 the order of options and placement of file and archive names,
1357 especially when using short option forms.  Not having the option name
1358 written out mnemonically can affect how well you remember which option
1359 does what, and therefore where different names have to be placed.
1361 @node create dir
1362 @subsection Archiving Directories
1364 @cindex Archiving Directories
1365 @cindex Directories, Archiving
1366 You can archive a directory by specifying its directory name as a
1367 file name argument to @command{tar}.  The files in the directory will be
1368 archived relative to the working directory, and the directory will be
1369 re-created along with its contents when the archive is extracted.
1371 To archive a directory, first move to its superior directory.  If you
1372 have followed the previous instructions in this tutorial, you should
1373 type:
1375 @smallexample
1376 $ @kbd{cd ..}
1378 @end smallexample
1380 @noindent
1381 This will put you into the directory which contains @file{practice},
1382 i.e., your home directory.  Once in the superior directory, you can
1383 specify the subdirectory, @file{practice}, as a file name argument.  To
1384 store @file{practice} in the new archive file @file{music.tar}, type:
1386 @smallexample
1387 $ @kbd{tar --create --verbose --file=music.tar practice}
1388 @end smallexample
1390 @noindent
1391 @command{tar} should output:
1393 @smallexample
1394 practice/
1395 practice/blues
1396 practice/folk
1397 practice/jazz
1398 practice/collection.tar
1399 @end smallexample
1401 Note that the archive thus created is not in the subdirectory
1402 @file{practice}, but rather in the current working directory---the
1403 directory from which @command{tar} was invoked.  Before trying to archive a
1404 directory from its superior directory, you should make sure you have
1405 write access to the superior directory itself, not only the directory
1406 you are trying archive with @command{tar}.  For example, you will probably
1407 not be able to store your home directory in an archive by invoking
1408 @command{tar} from the root directory; @xref{absolute}.  (Note
1409 also that @file{collection.tar}, the original archive file, has itself
1410 been archived.  @command{tar} will accept any file as a file to be
1411 archived, regardless of its content.  When @file{music.tar} is
1412 extracted, the archive file @file{collection.tar} will be re-written
1413 into the file system).
1415 If you give @command{tar} a command such as
1417 @smallexample
1418 $ @kbd{tar --create --file=foo.tar .}
1419 @end smallexample
1421 @noindent
1422 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1423 dumped}.  This happens because @command{tar} creates the archive
1424 @file{foo.tar} in the current directory before putting any files into
1425 it.  Then, when @command{tar} attempts to add all the files in the
1426 directory @file{.} to the archive, it notices that the file
1427 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1428 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1429 will continue in this case, and create the archive
1430 normally, except for the exclusion of that one file.  (@emph{Please
1431 note:} Other implementations of @command{tar} may not be so clever;
1432 they will enter an infinite loop when this happens, so you should not
1433 depend on this behavior unless you are certain you are running
1434 @GNUTAR{}.  In general, it is wise to always place the archive outside
1435 of the directory being dumped.)
1437 @node list
1438 @section How to List Archives
1440 @opindex list
1441 Frequently, you will find yourself wanting to determine exactly what a
1442 particular archive contains.  You can use the @option{--list}
1443 (@option{-t}) operation to get the member names as they currently
1444 appear in the archive, as well as various attributes of the files at
1445 the time they were archived.  For example, assuming @file{practice} is
1446 your working directory, you can examine the archive
1447 @file{collection.tar} that you created in the last section with the
1448 command,
1450 @smallexample
1451 $ @kbd{tar --list --file=collection.tar}
1452 @end smallexample
1454 @noindent
1455 The output of @command{tar} would then be:
1457 @smallexample
1458 blues
1459 folk
1460 jazz
1461 @end smallexample
1463 @noindent
1464 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1465 @var{archive-name}}) option just as with @option{--create}
1466 (@option{-c}) to specify the name of the archive.
1468 @cindex File name arguments, using @option{--list} with
1469 @xopindex{list, using with file name arguments}
1470 You can specify one or more individual member names as arguments when
1471 using @samp{list}.  In this case, @command{tar} will only list the
1472 names of members you identify.  For example, @w{@kbd{tar --list
1473 --file=collection.tar folk}} would only print @file{folk}:
1475 @smallexample
1476 $ @kbd{tar --list --file=collection.tar folk}
1477 folk
1478 @end smallexample
1480 @xopindex{list, using with @option{--verbose}}
1481 @xopindex{verbose, using with @option{--list}}
1482 If you use the @option{--verbose} (@option{-v}) option with
1483 @option{--list}, then @command{tar} will print out a listing
1484 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1485 forth.  This output is described in detail in @ref{verbose member listing}.
1487 If you had used @option{--verbose} (@option{-v}) mode, the example
1488 above would look like:
1490 @smallexample
1491 $ @kbd{tar --list --verbose --file=collection.tar folk}
1492 -rw-r--r-- myself/user      62 1990-05-23 10:55 folk
1493 @end smallexample
1495 @cindex listing member and file names
1496 @anchor{listing member and file names}
1497 It is important to notice that the output of @kbd{tar --list
1498 --verbose} does not necessarily match that produced by @kbd{tar
1499 --create --verbose} while creating the archive.  It is because
1500 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1501 prefixes from file names before storing them in the archive
1502 (@xref{absolute}, for more information).  In other
1503 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1504 an archive and @dfn{member names} when listing it.  Consider this
1505 example, run from your home directory:
1507 @smallexample
1508 @group
1509 $ @kbd{tar --create --verbose --file practice.tar ~/practice}
1510 tar: Removing leading '/' from member names
1511 /home/myself/practice/
1512 /home/myself/practice/blues
1513 /home/myself/practice/folk
1514 /home/myself/practice/jazz
1515 /home/myself/practice/collection.tar
1516 $ @kbd{tar --list --file practice.tar}
1517 home/myself/practice/
1518 home/myself/practice/blues
1519 home/myself/practice/folk
1520 home/myself/practice/jazz
1521 home/myself/practice/collection.tar
1522 @end group
1523 @end smallexample
1525 @opindex show-stored-names
1526   This default behavior can sometimes be inconvenient.  You can force
1527 @GNUTAR{} show member names when creating archive by supplying
1528 @option{--show-stored-names} option.
1530 @table @option
1531 @item --show-stored-names
1532 Print member (as opposed to @emph{file}) names when creating the archive.
1533 @end table
1535 With this option, both commands produce the same output:
1537 @smallexample
1538 @group
1539 $ @kbd{tar --create --verbose --show-stored-names \
1540            --file practice.tar ~/practice}
1541 tar: Removing leading '/' from member names
1542 home/myself/practice/
1543 home/myself/practice/blues
1544 home/myself/practice/folk
1545 home/myself/practice/jazz
1546 home/myself/practice/collection.tar
1547 $ @kbd{tar --list --file practice.tar}
1548 home/myself/practice/
1549 home/myself/practice/blues
1550 home/myself/practice/folk
1551 home/myself/practice/jazz
1552 home/myself/practice/collection.tar
1553 @end group
1554 @end smallexample
1556 Since @command{tar} preserves file names, those you wish to list must be
1557 specified as they appear in the archive (i.e., relative to the
1558 directory from which the archive was created).  Continuing the example
1559 above:
1561 @smallexample
1562 @group
1563 $ @kbd{tar --list --file=practice.tar folk}
1564 tar: folk: Not found in archive
1565 tar: Exiting with failure status due to previous errors
1566 @end group
1567 @end smallexample
1569 the error message is produced because there is no member named
1570 @file{folk}, only one named @file{home/myself/folk}.
1572 If you are not sure of the exact file name, use @dfn{globbing
1573 patterns}, for example:
1575 @smallexample
1576 $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
1577 home/myself/practice/folk
1578 @end smallexample
1580 @noindent
1581 @xref{wildcards}, for a detailed discussion of globbing patterns and related
1582 @command{tar} command line options.
1584 @menu
1585 * list dir::
1586 @end menu
1588 @node list dir
1589 @unnumberedsubsec Listing the Contents of a Stored Directory
1591 To get information about the contents of an archived directory,
1592 use the directory name as a file name argument in conjunction with
1593 @option{--list} (@option{-t}).  To find out file attributes, include the
1594 @option{--verbose} (@option{-v}) option.
1596 For example, to find out about files in the directory @file{practice}, in
1597 the archive file @file{music.tar}, type:
1599 @smallexample
1600 $ @kbd{tar --list --verbose --file=music.tar practice}
1601 @end smallexample
1603 @command{tar} responds:
1605 @smallexample
1606 drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
1607 -rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
1608 -rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
1609 -rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
1610 -rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar
1611 @end smallexample
1613 When you use a directory name as a file name argument, @command{tar} acts on
1614 all the files (including sub-directories) in that directory.
1616 @node extract
1617 @section How to Extract Members from an Archive
1618 @cindex Extraction
1619 @cindex Retrieving files from an archive
1620 @cindex Resurrecting files from an archive
1622 @opindex extract
1623 Creating an archive is only half the job---there is no point in storing
1624 files in an archive if you can't retrieve them.  The act of retrieving
1625 members from an archive so they can be used and manipulated as
1626 unarchived files again is called @dfn{extraction}.  To extract files
1627 from an archive, use the @option{--extract} (@option{--get} or
1628 @option{-x}) operation.  As with @option{--create}, specify the name
1629 of the archive with @option{--file} (@option{-f}) option. Extracting
1630 an archive does not modify the archive in any way; you can extract it
1631 multiple times if you want or need to.
1633 Using @option{--extract}, you can extract an entire archive, or specific
1634 files.  The files can be directories containing other files, or not.  As
1635 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1636 long form of the operation without affecting the performance.
1638 @menu
1639 * extracting archives::
1640 * extracting files::
1641 * extract dir::
1642 * extracting untrusted archives::
1643 * failing commands::
1644 @end menu
1646 @node extracting archives
1647 @subsection Extracting an Entire Archive
1649 To extract an entire archive, specify the archive file name only, with
1650 no individual file names as arguments.  For example,
1652 @smallexample
1653 $ @kbd{tar -xvf collection.tar}
1654 @end smallexample
1656 @noindent
1657 produces this:
1659 @smallexample
1660 -rw-r--r-- myself/user      28 1996-10-18 16:31 jazz
1661 -rw-r--r-- myself/user      21 1996-09-23 16:44 blues
1662 -rw-r--r-- myself/user      20 1996-09-23 16:44 folk
1663 @end smallexample
1665 @node extracting files
1666 @subsection Extracting Specific Files
1668 To extract specific archive members, give their exact member names as
1669 arguments, as printed by @option{--list} (@option{-t}).  If you had
1670 mistakenly deleted one of the files you had placed in the archive
1671 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1672 from the archive without changing the archive's structure.  Its
1673 contents will be identical to the original file @file{blues} that you
1674 deleted.
1676 First, make sure you are in the @file{practice} directory, and list the
1677 files in the directory.  Now, delete the file, @samp{blues}, and list
1678 the files in the directory again.
1680 You can now extract the member @file{blues} from the archive file
1681 @file{collection.tar} like this:
1683 @smallexample
1684 $ @kbd{tar --extract --file=collection.tar blues}
1685 @end smallexample
1687 @noindent
1688 If you list the files in the directory again, you will see that the file
1689 @file{blues} has been restored, with its original permissions, data
1690 modification times, and owner.@footnote{This is only accidentally
1691 true, but not in general.  Whereas modification times are always
1692 restored, in most cases, one has to be root for restoring the owner,
1693 and use a special option for restoring permissions.  Here, it just
1694 happens that the restoring user is also the owner of the archived
1695 members, and that the current @code{umask} is compatible with original
1696 permissions.}  (These parameters will be identical to those which
1697 the file had when you originally placed it in the archive; any changes
1698 you may have made before deleting the file from the file system,
1699 however, will @emph{not} have been made to the archive member.)  The
1700 archive file, @samp{collection.tar}, is the same as it was before you
1701 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1702 @option{--list} (@option{-t}).
1704 Remember that as with other operations, specifying the exact member
1705 name is important (@xref{failing commands}, for more examples).
1707 You can extract a file to standard output by combining the above options
1708 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1709 Output}).
1711 If you give the @option{--verbose} option, then @option{--extract}
1712 will print the names of the archive members as it extracts them.
1714 @node extract dir
1715 @subsection Extracting Files that are Directories
1717 Extracting directories which are members of an archive is similar to
1718 extracting other files.  The main difference to be aware of is that if
1719 the extracted directory has the same name as any directory already in
1720 the working directory, then files in the extracted directory will be
1721 placed into the directory of the same name.  Likewise, if there are
1722 files in the pre-existing directory with the same names as the members
1723 which you extract, the files from the extracted archive will replace
1724 the files already in the working directory (and possible
1725 subdirectories).  This will happen regardless of whether or not the
1726 files in the working directory were more recent than those extracted
1727 (there exist, however, special options that alter this behavior
1728 @pxref{Writing}).
1730 However, if a file was stored with a directory name as part of its file
1731 name, and that directory does not exist under the working directory when
1732 the file is extracted, @command{tar} will create the directory.
1734 We can demonstrate how to use @option{--extract} to extract a directory
1735 file with an example.  Change to the @file{practice} directory if you
1736 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1737 go back to the parent directory and extract the archive
1738 @file{music.tar}.  You may either extract the entire archive, or you may
1739 extract only the files you just deleted.  To extract the entire archive,
1740 don't give any file names as arguments after the archive name
1741 @file{music.tar}.  To extract only the files you deleted, use the
1742 following command:
1744 @smallexample
1745 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1746 practice/folk
1747 practice/jazz
1748 @end smallexample
1750 @noindent
1751 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1752 would have displayed more detail about the extracted files, as shown
1753 in the example below:
1755 @smallexample
1756 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1757 -rw-r--r-- me/user          28 1996-10-18 16:31 practice/jazz
1758 -rw-r--r-- me/user          20 1996-09-23 16:44 practice/folk
1759 @end smallexample
1761 @noindent
1762 Because you created the directory with @file{practice} as part of the
1763 file names of each of the files by archiving the @file{practice}
1764 directory as @file{practice}, you must give @file{practice} as part
1765 of the file names when you extract those files from the archive.
1767 @node extracting untrusted archives
1768 @subsection Extracting Archives from Untrusted Sources
1770 Extracting files from archives can overwrite files that already exist.
1771 If you receive an archive from an untrusted source, you should make a
1772 new directory and extract into that directory, so that you don't have
1773 to worry about the extraction overwriting one of your existing files.
1774 For example, if @file{untrusted.tar} came from somewhere else on the
1775 Internet, and you don't necessarily trust its contents, you can
1776 extract it as follows:
1778 @smallexample
1779 $ @kbd{mkdir newdir}
1780 $ @kbd{cd newdir}
1781 $ @kbd{tar -xvf ../untrusted.tar}
1782 @end smallexample
1784 It is also a good practice to examine contents of the archive
1785 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1786 with @option{--verbose} (@option{-v}).
1788 @node failing commands
1789 @subsection Commands That Will Fail
1791 Here are some sample commands you might try which will not work, and why
1792 they won't work.
1794 If you try to use this command,
1796 @smallexample
1797 $ @kbd{tar -xvf music.tar folk jazz}
1798 @end smallexample
1800 @noindent
1801 you will get the following response:
1803 @smallexample
1804 tar: folk: Not found in archive
1805 tar: jazz: Not found in archive
1806 @end smallexample
1808 @noindent
1809 This is because these files were not originally @emph{in} the parent
1810 directory @file{..}, where the archive is located; they were in the
1811 @file{practice} directory, and their file names reflect this:
1813 @smallexample
1814 $ @kbd{tar -tvf music.tar}
1815 practice/blues
1816 practice/folk
1817 practice/jazz
1818 @end smallexample
1820 @noindent
1821 Likewise, if you try to use this command,
1823 @smallexample
1824 $ @kbd{tar -tvf music.tar folk jazz}
1825 @end smallexample
1827 @noindent
1828 you would get a similar response.  Members with those names are not in the
1829 archive.  You must use the correct member names, or wildcards, in order
1830 to extract the files from the archive.
1832 If you have forgotten the correct names of the files in the archive,
1833 use @w{@kbd{tar --list --verbose}} to list them correctly.
1835 To extract the member named @file{practice/folk}, you must specify
1837 @smallexample
1838 $ @kbd{tar --extract --file=music.tar practice/folk}
1839 @end smallexample
1841 @noindent
1842 Notice also, that as explained above, the @file{practice} directory
1843 will be created, if it didn't already exist.  There are options that
1844 allow you to strip away a certain number of leading directory
1845 components (@pxref{transform}).  For example,
1847 @smallexample
1848 $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
1849 @end smallexample
1851 @noindent
1852 will extract the file @file{folk} into the current working directory.
1854 @node going further
1855 @section Going Further Ahead in this Manual
1856 @UNREVISED{}
1858 @FIXME{need to write up a node here about the things that are going to
1859 be in the rest of the manual.}
1861 @node tar invocation
1862 @chapter Invoking @GNUTAR{}
1864 This chapter is about how one invokes the @GNUTAR{}
1865 command, from the command synopsis (@pxref{Synopsis}).  There are
1866 numerous options, and many styles for writing them.  One mandatory
1867 option specifies the operation @command{tar} should perform
1868 (@pxref{Operation Summary}), other options are meant to detail how
1869 this operation should be performed (@pxref{Option Summary}).
1870 Non-option arguments are not always interpreted the same way,
1871 depending on what the operation is.
1873 You will find in this chapter everything about option styles and rules for
1874 writing them (@pxref{Styles}).  On the other hand, operations and options
1875 are fully described elsewhere, in other chapters.  Here, you will find
1876 only synthetic descriptions for operations and options, together with
1877 pointers to other parts of the @command{tar} manual.
1879 Some options are so special they are fully described right in this
1880 chapter.  They have the effect of inhibiting the normal operation of
1881 @command{tar} or else, they globally alter the amount of feedback the user
1882 receives about what is going on.  These are the @option{--help} and
1883 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1884 and @option{--interactive} options (@pxref{interactive}).
1886 @menu
1887 * Synopsis::
1888 * using tar options::
1889 * Styles::
1890 * All Options::           All @command{tar} Options.
1891 * help::                  Where to Get Help.
1892 * defaults::              What are the Default Values.
1893 * verbose::               Checking @command{tar} progress.
1894 * checkpoints::           Checkpoints.
1895 * warnings::              Controlling Warning Messages.
1896 * interactive::           Asking for Confirmation During Operations.
1897 * external::              Running External Commands.
1898 @end menu
1900 @node Synopsis
1901 @section General Synopsis of @command{tar}
1903 The @GNUTAR{} program is invoked as either one of:
1905 @smallexample
1906 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1907 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1908 @end smallexample
1910 The second form is for when old options are being used.
1912 You can use @command{tar} to store files in an archive, to extract them from
1913 an archive, and to do other types of archive manipulation.  The primary
1914 argument to @command{tar}, which is called the @dfn{operation}, specifies
1915 which action to take.  The other arguments to @command{tar} are either
1916 @dfn{options}, which change the way @command{tar} performs an operation,
1917 or file names or archive members, which specify the files or members
1918 @command{tar} is to act on.
1920 You can actually type in arguments in any order, even if in this manual
1921 the options always precede the other arguments, to make examples easier
1922 to understand.  Further, the option stating the main operation mode
1923 (the @command{tar} main command) is usually given first.
1925 Each @var{name} in the synopsis above is interpreted as an archive member
1926 name when the main command is one of @option{--compare}
1927 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1928 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1929 @option{--update} (@option{-u}).  When naming archive members, you
1930 must give the exact name of the member in the archive, as it is
1931 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1932 @option{--create} (@option{-c}), these @var{name} arguments specify
1933 the names of either files or directory hierarchies to place in the archive.
1934 These files or hierarchies should already exist in the file system,
1935 prior to the execution of the @command{tar} command.
1937 @command{tar} interprets relative file names as being relative to the
1938 working directory.  @command{tar} will make all file names relative
1939 (by removing leading slashes when archiving or restoring files),
1940 unless you specify otherwise (using the @option{--absolute-names}
1941 option).  @xref{absolute}, for more information about
1942 @option{--absolute-names}.
1944 If you give the name of a directory as either a file name or a member
1945 name, then @command{tar} acts recursively on all the files and directories
1946 beneath that directory.  For example, the name @file{/} identifies all
1947 the files in the file system to @command{tar}.
1949 The distinction between file names and archive member names is especially
1950 important when shell globbing is used, and sometimes a source of confusion
1951 for newcomers.  @xref{wildcards}, for more information about globbing.
1952 The problem is that shells may only glob using existing files in the
1953 file system.  Only @command{tar} itself may glob on archive members, so when
1954 needed, you must ensure that wildcard characters reach @command{tar} without
1955 being interpreted by the shell first.  Using a backslash before @samp{*}
1956 or @samp{?}, or putting the whole argument between quotes, is usually
1957 sufficient for this.
1959 Even if @var{name}s are often specified on the command line, they
1960 can also be read from a text file in the file system, using the
1961 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1963 If you don't use any file name arguments, @option{--append} (@option{-r}),
1964 @option{--delete} and @option{--concatenate} (@option{--catenate},
1965 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1966 will usually yield a diagnostic and inhibit @command{tar} execution.
1967 The other operations of @command{tar} (@option{--list},
1968 @option{--extract}, @option{--compare}, and @option{--update})
1969 will act on the entire contents of the archive.
1971 @anchor{exit status}
1972 @cindex exit status
1973 @cindex return status
1974 Besides successful exits, @GNUTAR{} may fail for
1975 many reasons.  Some reasons correspond to bad usage, that is, when the
1976 @command{tar} command line is improperly written.  Errors may be
1977 encountered later, while processing the archive or the files.  Some
1978 errors are recoverable, in which case the failure is delayed until
1979 @command{tar} has completed all its work.  Some errors are such that
1980 it would be not meaningful, or at least risky, to continue processing:
1981 @command{tar} then aborts processing immediately.  All abnormal exits,
1982 whether immediate or delayed, should always be clearly diagnosed on
1983 @code{stderr}, after a line stating the nature of the error.
1985 Possible exit codes of @GNUTAR{} are summarized in the following
1986 table:
1988 @table @asis
1989 @item 0
1990 @samp{Successful termination}.
1992 @item 1
1993 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1994 (@option{--diff}, @option{-d}) command line option, this means that
1995 some files in the archive differ from their disk counterparts
1996 (@pxref{compare}).  If tar was given @option{--create},
1997 @option{--append} or @option{--update} option, this exit code means
1998 that some files were changed while being archived and so the resulting
1999 archive does not contain the exact copy of the file set.
2001 @item 2
2002 @samp{Fatal error}.  This means that some fatal, unrecoverable error
2003 occurred.
2004 @end table
2006 If @command{tar} has invoked a subprocess and that subprocess exited with a
2007 nonzero exit code, @command{tar} exits with that code as well.
2008 This can happen, for example, if @command{tar} was given some
2009 compression option (@pxref{gzip}) and the external compressor program
2010 failed.  Another example is @command{rmt} failure during backup to the
2011 remote device (@pxref{Remote Tape Server}).
2013 @node using tar options
2014 @section Using @command{tar} Options
2016 @GNUTAR{} has a total of eight operating modes which
2017 allow you to perform a variety of tasks.  You are required to choose
2018 one operating mode each time you employ the @command{tar} program by
2019 specifying one, and only one operation as an argument to the
2020 @command{tar} command (the corresponding options may be found
2021 at @ref{frequent operations} and @ref{Operations}).  Depending on
2022 circumstances, you may also wish to customize how the chosen operating
2023 mode behaves.  For example, you may wish to change the way the output
2024 looks, or the format of the files that you wish to archive may require
2025 you to do something special in order to make the archive look right.
2027 You can customize and control @command{tar}'s performance by running
2028 @command{tar} with one or more options (such as @option{--verbose}
2029 (@option{-v}), which we used in the tutorial).  As we said in the
2030 tutorial, @dfn{options} are arguments to @command{tar} which are (as
2031 their name suggests) optional. Depending on the operating mode, you
2032 may specify one or more options. Different options will have different
2033 effects, but in general they all change details of the operation, such
2034 as archive format, archive name, or level of user interaction.  Some
2035 options make sense with all operating modes, while others are
2036 meaningful only with particular modes. You will likely use some
2037 options frequently, while you will only use others infrequently, or
2038 not at all.  (A full list of options is available in @pxref{All Options}.)
2040 @vrindex TAR_OPTIONS, environment variable
2041 @anchor{TAR_OPTIONS}
2042 The @env{TAR_OPTIONS} environment variable specifies default options to
2043 be placed in front of any explicit options.  For example, if
2044 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
2045 if the two options @option{-v} and @option{--unlink-first} had been
2046 specified before any explicit options.  Option specifications are
2047 separated by whitespace.  A backslash escapes the next character, so it
2048 can be used to specify an option containing whitespace or a backslash.
2050 Note that @command{tar} options are case sensitive.  For example, the
2051 options @option{-T} and @option{-t} are different; the first requires an
2052 argument for stating the name of a file providing a list of @var{name}s,
2053 while the second does not require an argument and is another way to
2054 write @option{--list} (@option{-t}).
2056 In addition to the eight operations, there are many options to
2057 @command{tar}, and three different styles for writing both: long (mnemonic)
2058 form, short form, and old style.  These styles are discussed below.
2059 Both the options and the operations can be written in any of these three
2060 styles.
2062 @FIXME{menu at end of this node.  need to think of an actual outline
2063 for this chapter; probably do that after stuff from chapter 4 is
2064 incorporated.}
2066 @node Styles
2067 @section The Three Option Styles
2069 There are three styles for writing operations and options to the command
2070 line invoking @command{tar}.  The different styles were developed at
2071 different times during the history of @command{tar}.  These styles will be
2072 presented below, from the most recent to the oldest.
2074 Some options must take an argument@footnote{For example, @option{--file}
2075 (@option{-f}) takes the name of an archive file as an argument.  If
2076 you do not supply an archive file name, @command{tar} will use a
2077 default, but this can be confusing; thus, we recommend that you always
2078 supply a specific archive file name.}.  Where you @emph{place} the
2079 arguments generally depends on which style of options you choose.  We
2080 will detail specific information relevant to each option style in the
2081 sections on the different option styles, below.  The differences are
2082 subtle, yet can often be very important; incorrect option placement
2083 can cause you to overwrite a number of important files.  We urge you
2084 to note these differences, and only use the option style(s) which
2085 makes the most sense to you until you feel comfortable with the others.
2087 Some options @emph{may} take an argument.  Such options may have at
2088 most long and short forms, they do not have old style equivalent.  The
2089 rules for specifying an argument for such options are stricter than
2090 those for specifying mandatory arguments.  Please, pay special
2091 attention to them.
2093 @menu
2094 * Long Options::                Long Option Style
2095 * Short Options::               Short Option Style
2096 * Old Options::                 Old Option Style
2097 * Mixing::                      Mixing Option Styles
2098 @end menu
2100 @node Long Options
2101 @subsection Long Option Style
2103 @cindex long options
2104 @cindex options, long style
2105 @cindex options, GNU style
2106 @cindex options, mnemonic names
2107 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2108 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2109 their corresponding short or old names.  It sometimes happens that a
2110 single long option has many different names which are
2111 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2112 long option names can be given unique abbreviations.  For example,
2113 @option{--cre} can be used in place of @option{--create} because there is no
2114 other long option which begins with @samp{cre}.  (One way to find
2115 this out is by trying it and seeing what happens; if a particular
2116 abbreviation could represent more than one option, @command{tar} will tell
2117 you that that abbreviation is ambiguous and you'll know that that
2118 abbreviation won't work.  You may also choose to run @samp{tar --help}
2119 to see a list of options.  Be aware that if you run @command{tar} with a
2120 unique abbreviation for the long name of an option you didn't want to
2121 use, you are stuck; @command{tar} will perform the command as ordered.)
2123 Long options are meant to be obvious and easy to remember, and their
2124 meanings are generally easier to discern than those of their
2125 corresponding short options (see below).  For example:
2127 @smallexample
2128 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2129 @end smallexample
2131 @noindent
2132 gives a fairly good set of hints about what the command does, even
2133 for those not fully acquainted with @command{tar}.
2135 @cindex arguments to long options
2136 @cindex long options with mandatory arguments
2137 Long options which require arguments take those arguments
2138 immediately following the option name.  There are two ways of
2139 specifying a mandatory argument.  It can be separated from the
2140 option name either by an equal sign, or by any amount of
2141 white space characters.  For example, the @option{--file} option (which
2142 tells the name of the @command{tar} archive) is given a file such as
2143 @file{archive.tar} as argument by using any of the following notations:
2144 @option{--file=archive.tar} or @option{--file archive.tar}.
2146 @cindex optional arguments to long options
2147 @cindex long options with optional arguments
2148 In contrast, optional arguments must always be introduced using
2149 an equal sign.  For example, the @option{--backup} option takes
2150 an optional argument specifying backup type.  It must be used
2151 as @option{--backup=@var{backup-type}}.
2153 @node Short Options
2154 @subsection Short Option Style
2156 @cindex short options
2157 @cindex options, short style
2158 @cindex options, traditional
2159 Most options also have a @dfn{short option} name.  Short options start with
2160 a single dash, and are followed by a single character, e.g., @option{-t}
2161 (which is equivalent to @option{--list}).  The forms are absolutely
2162 identical in function; they are interchangeable.
2164 The short option names are faster to type than long option names.
2166 @cindex arguments to short options
2167 @cindex short options with mandatory arguments
2168 Short options which require arguments take their arguments immediately
2169 following the option, usually separated by white space.  It is also
2170 possible to stick the argument right after the short option name, using
2171 no intervening space.  For example, you might write @w{@option{-f
2172 archive.tar}} or @option{-farchive.tar} instead of using
2173 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2174 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2175 specific archive, here named @file{archive.tar}.
2177 @cindex optional arguments to short options
2178 @cindex short options with optional arguments
2179 Short options which take optional arguments take their arguments
2180 immediately following the option letter, @emph{without any intervening
2181 white space characters}.
2183 Short options' letters may be clumped together, but you are not
2184 required to do this (as compared to old options; see below).  When
2185 short options are clumped as a set, use one (single) dash for them
2186 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2187 such a set is allowed to have an argument@footnote{Clustering many
2188 options, the last of which has an argument, is a rather opaque way to
2189 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2190 even be made helpful enough for considering such usages as invalid.}.
2192 When the options are separated, the argument for each option which requires
2193 an argument directly follows that option, as is usual for Unix programs.
2194 For example:
2196 @smallexample
2197 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2198 @end smallexample
2200 If you reorder short options' locations, be sure to move any arguments
2201 that belong to them.  If you do not move the arguments properly, you may
2202 end up overwriting files.
2204 @node Old Options
2205 @subsection Old Option Style
2206 @cindex options, old style
2207 @cindex old option style
2208 @cindex option syntax, traditional
2210 As far as we know, all @command{tar} programs, @acronym{GNU} and
2211 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2212 argument does not start with @samp{-}, it is assumed to specify option
2213 letters.  @GNUTAR{} supports old options not only for historical
2214 reasons, but also because many people are used to them.  If the first
2215 argument does not start with a dash, you are announcing the old option
2216 style instead of the short option style; old options are decoded
2217 differently.
2219 Like short options, old options are single letters.  However, old options
2220 must be written together as a single clumped set, without spaces separating
2221 them or dashes preceding them.  This set
2222 of letters must be the first to appear on the command line, after the
2223 @command{tar} program name and some white space; old options cannot appear
2224 anywhere else.  The letter of an old option is exactly the same letter as
2225 the corresponding short option.  For example, the old option @samp{t} is
2226 the same as the short option @option{-t}, and consequently, the same as the
2227 long option @option{--list}.  So for example, the command @w{@samp{tar
2228 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2230 @cindex arguments to old options
2231 @cindex old options with mandatory arguments
2232 When options that need arguments are given together with the command,
2233 all the associated arguments follow, in the same order as the options.
2234 Thus, the example given previously could also be written in the old
2235 style as follows:
2237 @smallexample
2238 $ @kbd{tar cvbf 20 /dev/rmt0}
2239 @end smallexample
2241 @noindent
2242 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2243 the argument of @option{-f}.
2245 The old style syntax can make it difficult to match
2246 option letters with their corresponding arguments, and is often
2247 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2248 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2249 argument for @option{-f}, and @option{-v} does not have a corresponding
2250 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2251 /dev/rmt0}} is clearer, putting all arguments next to the option they
2252 pertain to.
2254 If you want to reorder the letters in the old option argument, be
2255 sure to reorder any corresponding argument appropriately.
2257 This old way of writing @command{tar} options can surprise even experienced
2258 users.  For example, the two commands:
2260 @smallexample
2261 @kbd{tar cfz archive.tar.gz file}
2262 @kbd{tar -cfz archive.tar.gz file}
2263 @end smallexample
2265 @noindent
2266 are quite different.  The first example uses @file{archive.tar.gz} as
2267 the value for option @samp{f} and recognizes the option @samp{z}.  The
2268 second example, however, uses @file{z} as the value for option
2269 @samp{f} --- probably not what was intended.
2271 This second example could be corrected in many ways, among which the
2272 following are equivalent:
2274 @smallexample
2275 @kbd{tar -czf archive.tar.gz file}
2276 @kbd{tar -cf archive.tar.gz -z file}
2277 @kbd{tar cf archive.tar.gz -z file}
2278 @end smallexample
2280 @node Mixing
2281 @subsection Mixing Option Styles
2283 @cindex options, mixing different styles
2284 All three styles may be intermixed in a single @command{tar} command,
2285 so long as the rules for each style are fully
2286 respected@footnote{Before @GNUTAR{} version 1.11.6,
2287 a bug prevented intermixing old style options with long options in
2288 some cases.}.  Old style options and either of the modern styles of
2289 options may be mixed within a single @command{tar} command.  However,
2290 old style options must be introduced as the first arguments only,
2291 following the rule for old options (old options must appear directly
2292 after the @command{tar} command and some white space).  Modern options
2293 may be given only after all arguments to the old options have been
2294 collected.  If this rule is not respected, a modern option might be
2295 falsely interpreted as the value of the argument to one of the old
2296 style options.
2298 For example, all the following commands are wholly equivalent, and
2299 illustrate the many combinations and orderings of option styles.
2301 @smallexample
2302 @kbd{tar --create --file=archive.tar}
2303 @kbd{tar --create -f archive.tar}
2304 @kbd{tar --create -farchive.tar}
2305 @kbd{tar --file=archive.tar --create}
2306 @kbd{tar --file=archive.tar -c}
2307 @kbd{tar -c --file=archive.tar}
2308 @kbd{tar -c -f archive.tar}
2309 @kbd{tar -c -farchive.tar}
2310 @kbd{tar -cf archive.tar}
2311 @kbd{tar -cfarchive.tar}
2312 @kbd{tar -f archive.tar --create}
2313 @kbd{tar -f archive.tar -c}
2314 @kbd{tar -farchive.tar --create}
2315 @kbd{tar -farchive.tar -c}
2316 @kbd{tar c --file=archive.tar}
2317 @kbd{tar c -f archive.tar}
2318 @kbd{tar c -farchive.tar}
2319 @kbd{tar cf archive.tar}
2320 @kbd{tar f archive.tar --create}
2321 @kbd{tar f archive.tar -c}
2322 @kbd{tar fc archive.tar}
2323 @end smallexample
2325 On the other hand, the following commands are @emph{not} equivalent to
2326 the previous set:
2328 @smallexample
2329 @kbd{tar -f -c archive.tar}
2330 @kbd{tar -fc archive.tar}
2331 @kbd{tar -fcarchive.tar}
2332 @kbd{tar -farchive.tarc}
2333 @kbd{tar cfarchive.tar}
2334 @end smallexample
2336 @noindent
2337 These last examples mean something completely different from what the
2338 user intended (judging based on the example in the previous set which
2339 uses long options, whose intent is therefore very clear).  The first
2340 four specify that the @command{tar} archive would be a file named
2341 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2342 respectively.  The first two examples also specify a single non-option,
2343 @var{name} argument having the value @samp{archive.tar}.  The last
2344 example contains only old style option letters (repeating option
2345 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2346 @samp{h}, or @samp{i}), with no argument value.
2347 @FIXME{not sure i liked
2348 the first sentence of this paragraph..}
2350 @node All Options
2351 @section All @command{tar} Options
2353 The coming manual sections contain an alphabetical listing of all
2354 @command{tar} operations and options, with brief descriptions and
2355 cross-references to more in-depth explanations in the body of the manual.
2356 They also contain an alphabetically arranged table of the short option
2357 forms with their corresponding long option.  You can use this table as
2358 a reference for deciphering @command{tar} commands in scripts.
2360 @menu
2361 * Operation Summary::
2362 * Option Summary::
2363 * Short Option Summary::
2364 * Position-Sensitive Options::
2365 @end menu
2367 @node Operation Summary
2368 @subsection Operations
2370 @table @option
2372 @opsummary{append}
2373 @item --append
2374 @itemx -r
2376 Appends files to the end of the archive.  @xref{append}.
2378 @opsummary{catenate}
2379 @item --catenate
2380 @itemx -A
2382 Same as @option{--concatenate}.  @xref{concatenate}.
2384 @opsummary{compare}
2385 @item --compare
2386 @itemx -d
2388 Compares archive members with their counterparts in the file
2389 system, and reports differences in file size, mode, owner,
2390 modification date and contents.  @xref{compare}.
2392 @opsummary{concatenate}
2393 @item --concatenate
2394 @itemx -A
2396 Appends other @command{tar} archives to the end of the archive.
2397 @xref{concatenate}.
2399 @opsummary{create}
2400 @item --create
2401 @itemx -c
2403 Creates a new @command{tar} archive.  @xref{create}.
2405 @opsummary{delete}
2406 @item --delete
2408 Deletes members from the archive.  Don't try this on an archive on a
2409 tape!  @xref{delete}.
2411 @opsummary{diff}
2412 @item --diff
2413 @itemx -d
2415 Same as @option{--compare}.  @xref{compare}.
2417 @opsummary{extract}
2418 @item --extract
2419 @itemx -x
2421 Extracts members from the archive into the file system.  @xref{extract}.
2423 @opsummary{get}
2424 @item --get
2425 @itemx -x
2427 Same as @option{--extract}.  @xref{extract}.
2429 @opsummary{list}
2430 @item --list
2431 @itemx -t
2433 Lists the members in an archive.  @xref{list}.
2435 @opsummary{update}
2436 @item --update
2437 @itemx -u
2439 Adds files to the end of the archive, but only if they are newer than
2440 their counterparts already in the archive, or if they do not already
2441 exist in the archive. @xref{update}.
2443 @end table
2445 @node Option Summary
2446 @subsection @command{tar} Options
2448 @table @option
2450 @opsummary{absolute-names}
2451 @item --absolute-names
2452 @itemx -P
2454 Normally when creating an archive, @command{tar} strips an initial
2455 @samp{/} from member names, and when extracting from an archive @command{tar}
2456 treats names specially if they have initial @samp{/} or internal
2457 @samp{..}.  This option disables that behavior.  @xref{absolute}.
2459 @opsummary{acls}
2460 @item --acls
2461 Enable POSIX ACLs support.  @xref{Extended File Attributes, acls}.
2463 @opsummary{after-date}
2464 @item --after-date
2466 (See @option{--newer}, @pxref{after})
2468 @opsummary{anchored}
2469 @item --anchored
2470 A pattern must match an initial subsequence of the name's components.
2471 @xref{controlling pattern-matching}.
2473 @opsummary{atime-preserve}
2474 @item --atime-preserve
2475 @itemx --atime-preserve=replace
2476 @itemx --atime-preserve=system
2478 Attempt to preserve the access time of files when reading them.  This
2479 option currently is effective only on files that you own, unless you
2480 have superuser privileges.
2482 @option{--atime-preserve=replace} remembers the access time of a file
2483 before reading it, and then restores the access time afterwards.  This
2484 may cause problems if other programs are reading the file at the same
2485 time, as the times of their accesses will be lost.  On most platforms
2486 restoring the access time also requires @command{tar} to restore the
2487 data modification time too, so this option may also cause problems if
2488 other programs are writing the file at the same time (@command{tar} attempts
2489 to detect this situation, but cannot do so reliably due to race
2490 conditions).  Worse, on most platforms restoring the access time also
2491 updates the status change time, which means that this option is
2492 incompatible with incremental backups.
2494 @option{--atime-preserve=system} avoids changing time stamps on files,
2495 without interfering with time stamp updates
2496 caused by other programs, so it works better with incremental backups.
2497 However, it requires a special @code{O_NOATIME} option from the
2498 underlying operating and file system implementation, and it also requires
2499 that searching directories does not update their access times.  As of
2500 this writing (November 2005) this works only with Linux, and only with
2501 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2502 way to know whether this feature actually works.  Sometimes
2503 @command{tar} knows that it does not work, and if you use
2504 @option{--atime-preserve=system} then @command{tar} complains and
2505 exits right away.  But other times @command{tar} might think that the
2506 option works when it actually does not.
2508 Currently @option{--atime-preserve} with no operand defaults to
2509 @option{--atime-preserve=replace}, but this may change in the future
2510 as support for @option{--atime-preserve=system} improves.
2512 If your operating or file system does not support
2513 @option{--atime-preserve=@-system}, you might be able to preserve access
2514 times reliably by using the @command{mount} command.  For example,
2515 you can mount the file system read-only, or access the file system via
2516 a read-only loopback mount, or use the @samp{noatime} mount option
2517 available on some systems.  However, mounting typically requires
2518 superuser privileges and can be a pain to manage.
2520 @opsummary{auto-compress}
2521 @item --auto-compress
2522 @itemx -a
2524 During a @option{--create} operation, enables automatic compressed
2525 format recognition based on the archive suffix.  The effect of this
2526 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2528 @opsummary{backup}
2529 @item --backup=@var{backup-type}
2531 Rather than deleting files from the file system, @command{tar} will
2532 back them up using simple or numbered backups, depending upon
2533 @var{backup-type}.  @xref{backup}.
2535 @opsummary{block-number}
2536 @item --block-number
2537 @itemx -R
2539 With this option present, @command{tar} prints error messages for read errors
2540 with the block number in the archive file.  @xref{block-number}.
2542 @opsummary{blocking-factor}
2543 @item --blocking-factor=@var{blocking}
2544 @itemx -b @var{blocking}
2546 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2547 record.  @xref{Blocking Factor}.
2549 @opsummary{bzip2}
2550 @item --bzip2
2551 @itemx -j
2553 This option tells @command{tar} to read or write archives through
2554 @code{bzip2}.  @xref{gzip}.
2556 @opsummary{check-device}
2557 @item --check-device
2558 Check device numbers when creating a list of modified files for
2559 incremental archiving.  This is the default.  @xref{device numbers},
2560 for a detailed description.
2562 @opsummary{checkpoint}
2563 @item --checkpoint[=@var{number}]
2565 This option directs @command{tar} to print periodic checkpoint
2566 messages as it reads through the archive.  It is intended for when you
2567 want a visual indication that @command{tar} is still running, but
2568 don't want to see @option{--verbose} output.  You can also instruct
2569 @command{tar} to execute a list of actions on each checkpoint, see
2570 @option{--checkpoint-action} below.  For a detailed description, see
2571 @ref{checkpoints}.
2573 @opsummary{checkpoint-action}
2574 @item --checkpoint-action=@var{action}
2575 Instruct @command{tar} to execute an action upon hitting a
2576 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2577 for a complete description.
2579 The @var{action} argument can be one of the following:
2581 @table @asis
2582 @item bell
2583 Produce an audible bell on the console.
2585 @item dot
2586 @itemx .
2587 Print a single dot on the standard listing stream.
2589 @item echo
2590 Display a textual message on the standard error, with the status and
2591 number of the checkpoint.  This is the default.
2593 @item echo=@var{string}
2594 Display @var{string} on the standard error.  Before output, the string
2595 is subject to meta-character expansion.
2597 @item exec=@var{command}
2598 Execute the given @var{command}.
2600 @item sleep=@var{time}
2601 Wait for @var{time} seconds.
2603 @item ttyout=@var{string}
2604 Output @var{string} on the current console (@file{/dev/tty}).
2606 @item totals
2607 Print statistics (see @pxref{totals}).
2609 @item wait=@var{signo}
2610 Wait for signal @var{signo}.
2611 @end table
2613 Several @option{--checkpoint-action} options can be specified.  The
2614 supplied actions will be executed in order of their appearance in the
2615 command line.
2617 Using @option{--checkpoint-action} without @option{--checkpoint}
2618 assumes default checkpoint frequency of one checkpoint per 10 records.
2620 @opsummary{check-links}
2621 @item --check-links
2622 @itemx -l
2623 If this option was given, @command{tar} will check the number of links
2624 dumped for each processed file.  If this number does not match the
2625 total number of hard links for the file, a warning message will be
2626 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2627 synonym for @option{--one-file-system}.  The current semantics, which
2628 complies to UNIX98, was introduced with version
2629 1.15.91. @xref{Changes}, for more information.}.
2631 @xref{hard links}.
2633 @opsummary{compress}
2634 @opsummary{uncompress}
2635 @item --compress
2636 @itemx --uncompress
2637 @itemx -Z
2639 @command{tar} will use the @command{compress} program when reading or
2640 writing the archive.  This allows you to directly act on archives
2641 while saving space.  @xref{gzip}.
2643 @opsummary{clamp-mtime}
2644 @item --clamp-mtime
2646 (See @option{--mtime}.)
2648 @opsummary{confirmation}
2649 @item --confirmation
2651 (See @option{--interactive}.)  @xref{interactive}.
2653 @opsummary{delay-directory-restore}
2654 @item --delay-directory-restore
2656 Delay setting modification times and permissions of extracted
2657 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2659 @opsummary{dereference}
2660 @item --dereference
2661 @itemx -h
2663 When reading or writing a file to be archived, @command{tar} accesses
2664 the file that a symbolic link points to, rather than the symlink
2665 itself.  @xref{dereference}.
2667 @opsummary{directory}
2668 @item --directory=@var{dir}
2669 @itemx -C @var{dir}
2671 When this option is specified, @command{tar} will change its current directory
2672 to @var{dir} before performing any operations.  When this option is used
2673 during archive creation, it is order sensitive.  @xref{directory}.
2675 @opsummary{exclude}
2676 @item --exclude=@var{pattern}
2678 When performing operations, @command{tar} will skip files that match
2679 @var{pattern}.  @xref{exclude}.
2681 @opsummary{exclude-backups}
2682 @item --exclude-backups
2683 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2685 @opsummary{exclude-from}
2686 @item --exclude-from=@var{file}
2687 @itemx -X @var{file}
2689 Similar to @option{--exclude}, except @command{tar} will use the list of
2690 patterns in the file @var{file}.  @xref{exclude}.
2692 @opsummary{exclude-caches}
2693 @item --exclude-caches
2695 Exclude from dump any directory containing a valid cache directory
2696 tag file, but still dump the directory node and the tag file itself.
2698 @xref{exclude,, exclude-caches}.
2700 @opsummary{exclude-caches-under}
2701 @item --exclude-caches-under
2703 Exclude from dump any directory containing a valid cache directory
2704 tag file, but still dump the directory node itself.
2706 @xref{exclude}.
2708 @opsummary{exclude-caches-all}
2709 @item --exclude-caches-all
2711 Exclude from dump any directory containing a valid cache directory
2712 tag file.  @xref{exclude}.
2714 @opsummary{exclude-ignore}
2715 @item --exclude-ignore=@var{file}
2716 Before dumping a directory, @command{tar} checks if it contains
2717 @var{file}.  If so, exclusion patterns are read from this file.
2718 The patterns affect only the directory itself.  @xref{exclude}.
2720 @opsummary{exclude-ignore-recursive}
2721 @item --exclude-ignore-recursive=@var{file}
2722 Before dumping a directory, @command{tar} checks if it contains
2723 @var{file}.  If so, exclusion patterns are read from this file.
2724 The patterns affect the directory and all its subdirectories.
2725 @xref{exclude}.
2727 @opsummary{exclude-tag}
2728 @item --exclude-tag=@var{file}
2730 Exclude from dump any directory containing file named @var{file}, but
2731 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2733 @opsummary{exclude-tag-under}
2734 @item --exclude-tag-under=@var{file}
2736 Exclude from dump the contents of any directory containing file
2737 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2738 exclude-tag-under}.
2740 @opsummary{exclude-tag-all}
2741 @item --exclude-tag-all=@var{file}
2743 Exclude from dump any directory containing file named @var{file}.
2744 @xref{exclude,,exclude-tag-all}.
2746 @opsummary{exclude-vcs}
2747 @item --exclude-vcs
2749 Exclude from dump directories and files, that are internal for some
2750 widely used version control systems.
2752 @xref{exclude-vcs}.
2754 @opsummary{exclude-vcs-ignores}
2755 @item --exclude-vcs-ignores
2756 Exclude files that match patterns read from VCS-specific ignore
2757 files.  Supported files are: @file{.cvsignore}, @file{.gitignore},
2758 @file{.bzrignore}, and @file{.hgignore}.  The semantics of each file
2759 is the same as for the corresponding VCS, e.g. patterns read from
2760 @file{.gitignore} affect the directory and all its subdirectories.
2761 @xref{exclude-vcs-ignores}.
2763 @opsummary{file}
2764 @item --file=@var{archive}
2765 @itemx -f @var{archive}
2767 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2768 performs operations on, rather than @command{tar}'s compilation dependent
2769 default.  @xref{file tutorial}.
2771 @opsummary{files-from}
2772 @item --files-from=@var{file}
2773 @itemx -T @var{file}
2775 @command{tar} will use the contents of @var{file} as a list of archive members
2776 or files to operate on, in addition to those specified on the
2777 command-line.  @xref{files}.
2779 @opsummary{force-local}
2780 @item --force-local
2782 Forces @command{tar} to interpret the file name given to @option{--file}
2783 as a local file, even if it looks like a remote tape drive name.
2784 @xref{local and remote archives}.
2786 @opsummary{format}
2787 @item --format=@var{format}
2788 @itemx -H @var{format}
2790 Selects output archive format.  @var{Format} may be one of the
2791 following:
2793 @table @samp
2794 @item v7
2795 Creates an archive that is compatible with Unix V7 @command{tar}.
2797 @item oldgnu
2798 Creates an archive that is compatible with GNU @command{tar} version
2799 1.12 or earlier.
2801 @item gnu
2802 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2803 @samp{oldgnu} with the only difference in the way it handles long
2804 numeric fields.
2806 @item ustar
2807 Creates a @acronym{POSIX.1-1988} compatible archive.
2809 @item posix
2810 Creates a @acronym{POSIX.1-2001} archive.
2812 @end table
2814 @xref{Formats}, for a detailed discussion of these formats.
2816 @opsummary{full-time}
2817 @item --full-time
2818 This option instructs @command{tar} to print file times to their full
2819 resolution.  Usually this means 1-second resolution, but that depends
2820 on the underlying file system.  The @option{--full-time} option takes
2821 effect only when detailed output (verbosity level 2 or higher) has
2822 been requested using the @option{--verbose} option, e.g., when listing
2823 or extracting archives:
2825 @smallexample
2826 $ @kbd{tar -t -v --full-time -f archive.tar}
2827 @end smallexample
2829 @noindent
2830 or, when creating an archive:
2832 @smallexample
2833 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2834 @end smallexample
2836 Notice, thar when creating the archive you need to specify
2837 @option{--verbose} twice to get a detailed output (@pxref{verbose
2838 tutorial}).
2840 @opsummary{group}
2841 @item --group=@var{group}
2843 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2844 rather than the group from the source file.  @var{group} can specify a
2845 symbolic name, or a numeric @acronym{ID}, or both as
2846 @var{name}:@var{id}.  @xref{override}.
2848 Also see the @option{--group-map} option and comments for the
2849 @option{--owner=@var{user}} option.
2851 @opsummary{group-map}
2852 @item --group-map=@var{file}
2854 Read owner group translation map from @var{file}.  This option allows to
2855 translate only certain group names and/or UIDs.  @xref{override}, for a
2856 detailed description.  When used together with @option{--group}
2857 option, the latter affects only those files whose owner group is not listed
2858 in the @var{file}.
2860 This option does not affect extraction from archives.
2862 @opsummary{gzip}
2863 @opsummary{gunzip}
2864 @opsummary{ungzip}
2865 @item --gzip
2866 @itemx --gunzip
2867 @itemx --ungzip
2868 @itemx -z
2870 This option tells @command{tar} to read or write archives through
2871 @command{gzip}, allowing @command{tar} to directly operate on several
2872 kinds of compressed archives transparently.  @xref{gzip}.
2874 @opsummary{hard-dereference}
2875 @item --hard-dereference
2876 When creating an archive, dereference hard links and store the files
2877 they refer to, instead of creating usual hard link members.
2879 @xref{hard links}.
2881 @opsummary{help}
2882 @item --help
2883 @itemx -?
2885 @command{tar} will print out a short message summarizing the operations and
2886 options to @command{tar} and exit. @xref{help}.
2888 @opsummary{hole-detection}
2889 @item --hole-detection=@var{method}
2890 Use @var{method} to detect holes in sparse files.  This option implies
2891 @option{--sparse}.  Valid methods are @samp{seek} and @samp{raw}.
2892 Default is @samp{seek} with fallback to @samp{raw} when not
2893 applicable. @xref{sparse}.
2895 @opsummary{ignore-case}
2896 @item --ignore-case
2897 Ignore case when matching member or file names with
2898 patterns. @xref{controlling pattern-matching}.
2900 @opsummary{ignore-command-error}
2901 @item --ignore-command-error
2902 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2904 @opsummary{ignore-failed-read}
2905 @item --ignore-failed-read
2907 Do not exit unsuccessfully merely because reading failed.
2908 @xref{Ignore Failed Read}.
2910 @opsummary{ignore-zeros}
2911 @item --ignore-zeros
2912 @itemx -i
2914 With this option, @command{tar} will ignore zeroed blocks in the
2915 archive, which normally signals EOF.  This option also suppresses
2916 warnings about missing or incomplete zero blocks at the end of the
2917 archive.  @xref{Ignore Zeros}.
2919 @opsummary{incremental}
2920 @item --incremental
2921 @itemx -G
2923 Informs @command{tar} that it is working with an old
2924 @acronym{GNU}-format incremental backup archive.  It is intended
2925 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2926 for a detailed discussion of incremental archives.
2928 @opsummary{index-file}
2929 @item --index-file=@var{file}
2931 Send verbose output to @var{file} instead of to standard output.
2933 @opsummary{info-script}
2934 @opsummary{new-volume-script}
2935 @item --info-script=@var{command}
2936 @itemx --new-volume-script=@var{command}
2937 @itemx -F @var{command}
2939 When @command{tar} is performing multi-tape backups, @var{command} is run
2940 at the end of each tape.  If it exits with nonzero status,
2941 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2942 discussion of this feature.
2944 @opsummary{interactive}
2945 @item --interactive
2946 @itemx --confirmation
2947 @itemx -w
2949 Specifies that @command{tar} should ask the user for confirmation before
2950 performing potentially destructive options, such as overwriting files.
2951 @xref{interactive}.
2953 @opsummary{keep-directory-symlink}
2954 @item --keep-directory-symlink
2956 This option changes the behavior of tar when it encounters a symlink
2957 with the same name as the directory that it is about to extract.  By
2958 default, in this case tar would first remove the symlink and then
2959 proceed extracting the directory.
2961 The @option{--keep-directory-symlink} option disables this behavior
2962 and instructs tar to follow symlinks to directories when extracting
2963 from the archive.
2965 It is mainly intended to provide compatibility with the Slackware
2966 installation scripts.
2968 @opsummary{keep-newer-files}
2969 @item --keep-newer-files
2971 Do not replace existing files that are newer than their archive copies
2972 when extracting files from an archive.
2974 @opsummary{keep-old-files}
2975 @item --keep-old-files
2976 @itemx -k
2978 Do not overwrite existing files when extracting files from an
2979 archive.  Return error if such files exist.  See also
2980 @ref{--skip-old-files}.
2982 @xref{Keep Old Files}.
2984 @opsummary{label}
2985 @item --label=@var{name}
2986 @itemx -V @var{name}
2988 When creating an archive, instructs @command{tar} to write @var{name}
2989 as a name record in the archive.  When extracting or listing archives,
2990 @command{tar} will only operate on archives that have a label matching
2991 the pattern specified in @var{name}.  @xref{Tape Files}.
2993 @opsummary{level}
2994 @item --level=@var{n}
2995 Force incremental backup of level @var{n}.  As of @GNUTAR{} version
2996 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2997 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2998 effectively ignored.  @xref{--level=0}, for details and examples.
3000 The use of this option is valid only in conjunction with the
3001 @option{--listed-incremental} option.  @xref{Incremental Dumps},
3002 for a detailed description.
3004 @opsummary{listed-incremental}
3005 @item --listed-incremental=@var{snapshot-file}
3006 @itemx -g @var{snapshot-file}
3008 During a @option{--create} operation, specifies that the archive that
3009 @command{tar} creates is a new @acronym{GNU}-format incremental
3010 backup, using @var{snapshot-file} to determine which files to backup.
3011 With other operations, informs @command{tar} that the archive is in
3012 incremental format.  @xref{Incremental Dumps}.
3014 @opsummary{lzip}
3015 @item --lzip
3017 This option tells @command{tar} to read or write archives through
3018 @command{lzip}.  @xref{gzip}.
3020 @opsummary{lzma}
3021 @item --lzma
3023 This option tells @command{tar} to read or write archives through
3024 @command{lzma}.  @xref{gzip}.
3026 @item --lzop
3028 This option tells @command{tar} to read or write archives through
3029 @command{lzop}.  @xref{gzip}.
3031 @opsummary{mode}
3032 @item --mode=@var{permissions}
3034 When adding files to an archive, @command{tar} will use
3035 @var{permissions} for the archive members, rather than the permissions
3036 from the files.  @var{permissions} can be specified either as an octal
3037 number or as symbolic permissions, like with
3038 @command{chmod}. @xref{override}.
3040 @opsummary{mtime}
3041 @item --mtime=@var{date}
3043 When adding files to an archive, @command{tar} will use @var{date} as
3044 the modification time of members when creating archives, instead of
3045 their actual modification times.  The value of @var{date} can be
3046 either a textual date representation (@pxref{Date input formats}) or a
3047 name of the existing file, starting with @samp{/} or @samp{.}.  In the
3048 latter case, the modification time of that file is used. @xref{override}.
3050 When @command{--clamp-mtime} is also specified, files with
3051 modification times earlier than @var{date} will retain their actual
3052 modification times, and @var{date} will be used only for files with
3053 modification times later than @var{date}.
3055 @opsummary{multi-volume}
3056 @item --multi-volume
3057 @itemx -M
3059 Informs @command{tar} that it should create or otherwise operate on a
3060 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
3062 @opsummary{new-volume-script}
3063 @item --new-volume-script
3065 (see @option{--info-script})
3067 @opsummary{newer}
3068 @item --newer=@var{date}
3069 @itemx --after-date=@var{date}
3070 @itemx -N
3072 When creating an archive, @command{tar} will only add files that have changed
3073 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
3074 is taken to be the name of a file whose data modification time specifies
3075 the date.  @xref{after}.
3077 @opsummary{newer-mtime}
3078 @item --newer-mtime=@var{date}
3080 Like @option{--newer}, but add only files whose
3081 contents have changed (as opposed to just @option{--newer}, which will
3082 also back up files for which any status information has
3083 changed).  @xref{after}.
3085 @opsummary{no-acls}
3086 @item --no-acls
3087 Disable the POSIX ACLs support.  @xref{Extended File Attributes, acls}.
3089 @opsummary{no-anchored}
3090 @item --no-anchored
3091 An exclude pattern can match any subsequence of the name's components.
3092 @xref{controlling pattern-matching}.
3094 @opsummary{no-auto-compress}
3095 @item --no-auto-compress
3097 Disables automatic compressed format recognition based on the archive
3098 suffix.  @xref{--auto-compress}.  @xref{gzip}.
3100 @opsummary{no-check-device}
3101 @item --no-check-device
3102 Do not check device numbers when creating a list of modified files
3103 for incremental archiving.  @xref{device numbers}, for
3104 a detailed description.
3106 @opsummary{no-delay-directory-restore}
3107 @item --no-delay-directory-restore
3109 Modification times and permissions of extracted
3110 directories are set when all files from this directory have been
3111 extracted.  This is the default.
3112 @xref{Directory Modification Times and Permissions}.
3114 @opsummary{no-ignore-case}
3115 @item --no-ignore-case
3116 Use case-sensitive matching.
3117 @xref{controlling pattern-matching}.
3119 @opsummary{no-ignore-command-error}
3120 @item --no-ignore-command-error
3121 Print warnings about subprocesses that terminated with a nonzero exit
3122 code. @xref{Writing to an External Program}.
3124 @opsummary{no-null}
3125 @item --no-null
3127 If the @option{--null} option was given previously, this option
3128 cancels its effect, so that any following @option{--files-from}
3129 options will expect their file lists to be newline-terminated.
3131 @opsummary{no-overwrite-dir}
3132 @item --no-overwrite-dir
3134 Preserve metadata of existing directories when extracting files
3135 from an archive.  @xref{Overwrite Old Files}.
3137 @opsummary{no-quote-chars}
3138 @item --no-quote-chars=@var{string}
3139 Remove characters listed in @var{string} from the list of quoted
3140 characters set by the previous @option{--quote-chars} option
3141 (@pxref{quoting styles}).
3143 @opsummary{no-recursion}
3144 @item --no-recursion
3146 With this option, @command{tar} will not recurse into directories.
3147 @xref{recurse}.
3149 @opsummary{no-same-owner}
3150 @item --no-same-owner
3151 @itemx -o
3153 When extracting an archive, do not attempt to preserve the owner
3154 specified in the @command{tar} archive.  This the default behavior
3155 for ordinary users.
3157 @opsummary{no-same-permissions}
3158 @item --no-same-permissions
3160 When extracting an archive, subtract the user's umask from files from
3161 the permissions specified in the archive.  This is the default behavior
3162 for ordinary users.
3164 @opsummary{no-seek}
3165 @item --no-seek
3167 The archive media does not support seeks to arbitrary
3168 locations.  Usually @command{tar} determines automatically whether
3169 the archive can be seeked or not.  Use this option to disable this
3170 mechanism.
3172 @opsummary{no-selinux}
3173 @item --no-selinux
3174 Disable SELinux context support.  @xref{Extended File Attributes, SELinux}.
3176 @opsummary{no-unquote}
3177 @item --no-unquote
3178 Treat all input file or member names literally, do not interpret
3179 escape sequences.  @xref{input name quoting}.
3181 @opsummary{no-verbatim-files-from}
3182 @item --no-verbatim-files-from
3184 Instructs @GNUTAR{} to treat each line read from a file list as if it
3185 were supplied in the command line.  I.e., leading and trailing
3186 whitespace is removed and, if the result begins with a dash, it is
3187 treated as a @GNUTAR{} command line option.
3189 This is default behavior.  This option is provided as a way to restore
3190 it after @option{--verbatim-files-from} option.
3192 It is implied by the @option{--no-null} option.
3194 @xref{no-verbatim-files-from}.
3196 @opsummary{no-wildcards}
3197 @item --no-wildcards
3198 Do not use wildcards.
3199 @xref{controlling pattern-matching}.
3201 @opsummary{no-wildcards-match-slash}
3202 @item --no-wildcards-match-slash
3203 Wildcards do not match @samp{/}.
3204 @xref{controlling pattern-matching}.
3206 @opsummary{no-xattrs}
3207 @item --no-xattrs
3208 Disable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3210 @opsummary{null}
3211 @item --null
3213 When @command{tar} is using the @option{--files-from} option, this option
3214 instructs @command{tar} to expect file names terminated with
3215 @acronym{NUL}, and to process file names verbatim.
3217 This means that @command{tar} correctly works with file names that
3218 contain newlines or begin with a dash.
3220 @xref{nul}.
3222 See also @ref{verbatim-files-from}.
3224 @opsummary{numeric-owner}
3225 @item --numeric-owner
3227 This option will notify @command{tar} that it should use numeric user
3228 and group IDs when creating a @command{tar} file, rather than names.
3229 @xref{Attributes}.
3231 @item -o
3232 The function of this option depends on the action @command{tar} is
3233 performing.  When extracting files, @option{-o} is a synonym for
3234 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3235 restoring ownership of files being extracted.
3237 When creating an archive, it is a synonym for
3238 @option{--old-archive}.  This behavior is for compatibility
3239 with previous versions of @GNUTAR{}, and will be
3240 removed in future releases.
3242 @xref{Changes}, for more information.
3244 @opsummary{occurrence}
3245 @item --occurrence[=@var{number}]
3247 This option can be used in conjunction with one of the subcommands
3248 @option{--delete}, @option{--diff}, @option{--extract} or
3249 @option{--list} when a list of files is given either on the command
3250 line or via @option{-T} option.
3252 This option instructs @command{tar} to process only the @var{number}th
3253 occurrence of each named file.  @var{Number} defaults to 1, so
3255 @smallexample
3256 tar -x -f archive.tar --occurrence filename
3257 @end smallexample
3259 @noindent
3260 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3261 and will terminate without scanning to the end of the archive.
3263 @opsummary{old-archive}
3264 @item --old-archive
3265 Synonym for @option{--format=v7}.
3267 @opsummary{one-file-system}
3268 @item --one-file-system
3269 Used when creating an archive.  Prevents @command{tar} from recursing into
3270 directories that are on different file systems from the current
3271 directory.
3273 @opsummary{one-top-level}
3274 @item --one-top-level[=@var{dir}]
3275 Tells @command{tar} to create a new directory beneath the extraction directory
3276 (or the one passed to @option{-C}) and use it to guard against
3277 tarbombs.  In the absence of @var{dir} argument, the name of the new directory
3278 will be equal to the base name of the archive (file name minus the
3279 archive suffix, if recognized).  Any member names that do not begin
3280 with that directory name (after
3281 transformations from @option{--transform} and
3282 @option{--strip-components}) will be prefixed with it.  Recognized
3283 file name suffixes are @samp{.tar}, and any compression suffixes
3284 recognizable by @xref{--auto-compress}.
3286 @opsummary{overwrite}
3287 @item --overwrite
3289 Overwrite existing files and directory metadata when extracting files
3290 from an archive.  @xref{Overwrite Old Files}.
3292 @opsummary{overwrite-dir}
3293 @item --overwrite-dir
3295 Overwrite the metadata of existing directories when extracting files
3296 from an archive.  @xref{Overwrite Old Files}.
3298 @opsummary{owner}
3299 @item --owner=@var{user}
3301 Specifies that @command{tar} should use @var{user} as the owner of members
3302 when creating archives, instead of the user associated with the source
3303 file.  @var{user} can specify a symbolic name, or a numeric
3304 @acronym{ID}, or both as @var{name}:@var{id}.
3305 @xref{override}.
3307 This option does not affect extraction from archives.  See also
3308 @option{--owner-map}, below.
3310 @opsummary{owner-map}
3311 @item --owner-map=@var{file}
3313 Read owner translation map from @var{file}.  This option allows to
3314 translate only certain owner names or UIDs.  @xref{override}, for a
3315 detailed description.  When used together with @option{--owner}
3316 option, the latter affects only those files whose owner is not listed
3317 in the @var{file}.
3319 This option does not affect extraction from archives.
3321 @opsummary{pax-option}
3322 @item --pax-option=@var{keyword-list}
3323 This option enables creation of the archive in @acronym{POSIX.1-2001}
3324 format (@pxref{posix}) and modifies the way @command{tar} handles the
3325 extended header keywords.  @var{Keyword-list} is a comma-separated
3326 list of keyword options.  @xref{PAX keywords}, for a detailed
3327 discussion.
3329 @opsummary{portability}
3330 @item --portability
3331 @itemx --old-archive
3332 Synonym for @option{--format=v7}.
3334 @opsummary{posix}
3335 @item --posix
3336 Same as @option{--format=posix}.
3338 @opsummary{preserve-order}
3339 @item --preserve-order
3341 (See @option{--same-order}; @pxref{Same Order}.)
3343 @opsummary{preserve-permissions}
3344 @opsummary{same-permissions}
3345 @item --preserve-permissions
3346 @itemx --same-permissions
3347 @itemx -p
3349 When @command{tar} is extracting an archive, it normally subtracts the
3350 users' umask from the permissions specified in the archive and uses
3351 that number as the permissions to create the destination file.
3352 Specifying this option instructs @command{tar} that it should use the
3353 permissions directly from the archive.  @xref{Setting Access Permissions}.
3355 @opsummary{quote-chars}
3356 @item --quote-chars=@var{string}
3357 Always quote characters from @var{string}, even if the selected
3358 quoting style would not quote them (@pxref{quoting styles}).
3360 @opsummary{quoting-style}
3361 @item --quoting-style=@var{style}
3362 Set quoting style to use when printing member and file names
3363 (@pxref{quoting styles}). Valid @var{style} values are:
3364 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3365 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3366 style is @code{escape}, unless overridden while configuring the
3367 package.
3369 @opsummary{read-full-records}
3370 @item --read-full-records
3371 @itemx -B
3373 Specifies that @command{tar} should reblock its input, for reading
3374 from pipes on systems with buggy implementations.  @xref{Reading}.
3376 @opsummary{record-size}
3377 @item --record-size=@var{size}[@var{suf}]
3379 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3380 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3381 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3382 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3383 description of this option.
3385 @opsummary{recursion}
3386 @item --recursion
3388 With this option, @command{tar} recurses into directories (default).
3389 @xref{recurse}.
3391 @opsummary{recursive-unlink}
3392 @item --recursive-unlink
3394 Remove existing
3395 directory hierarchies before extracting directories of the same name
3396 from the archive.  @xref{Recursive Unlink}.
3398 @opsummary{remove-files}
3399 @item --remove-files
3401 Directs @command{tar} to remove the source file from the file system after
3402 appending it to an archive.  @xref{remove files}.
3404 @opsummary{restrict}
3405 @item --restrict
3407 Disable use of some potentially harmful @command{tar} options.
3408 Currently this option disables shell invocation from multi-volume menu
3409 (@pxref{Using Multiple Tapes}).
3411 @opsummary{rmt-command}
3412 @item --rmt-command=@var{cmd}
3414 Notifies @command{tar} that it should use @var{cmd} instead of
3415 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3417 @opsummary{rsh-command}
3418 @item --rsh-command=@var{cmd}
3420 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3421 devices.  @xref{Device}.
3423 @opsummary{same-order}
3424 @item --same-order
3425 @itemx --preserve-order
3426 @itemx -s
3428 This option is an optimization for @command{tar} when running on machines with
3429 small amounts of memory.  It informs @command{tar} that the list of file
3430 arguments has already been sorted to match the order of files in the
3431 archive.  @xref{Same Order}.
3433 @opsummary{same-owner}
3434 @item --same-owner
3436 When extracting an archive, @command{tar} will attempt to preserve the owner
3437 specified in the @command{tar} archive with this option present.
3438 This is the default behavior for the superuser; this option has an
3439 effect only for ordinary users.  @xref{Attributes}.
3441 @opsummary{same-permissions}
3442 @item --same-permissions
3444 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3446 @opsummary{seek}
3447 @item --seek
3448 @itemx -n
3450 Assume that the archive media supports seeks to arbitrary
3451 locations.  Usually @command{tar} determines automatically whether
3452 the archive can be seeked or not.  This option is intended for use
3453 in cases when such recognition fails.  It takes effect only if the
3454 archive is open for reading (e.g. with @option{--list} or
3455 @option{--extract} options).
3457 @opsummary{selinux}
3458 @item --selinux
3459 Enable the SELinux context support.
3460 @xref{Extended File Attributes, selinux}.
3462 @opsummary{show-defaults}
3463 @item --show-defaults
3465 Displays the default options used by @command{tar} and exits
3466 successfully.  This option is intended for use in shell scripts.
3467 Here is an example of what you can see using this option:
3469 @smallexample
3470 $ @kbd{tar --show-defaults}
3471 --format=gnu -f- -b20 --quoting-style=escape
3472 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3473 @end smallexample
3475 @noindent
3476 Notice, that this option outputs only one line.  The example output
3477 above has been split to fit page boundaries. @xref{defaults}.
3479 @opsummary{show-omitted-dirs}
3480 @item --show-omitted-dirs
3482 Instructs @command{tar} to mention the directories it is skipping when
3483 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3485 @opsummary{show-snapshot-field-ranges}
3486 @item --show-snapshot-field-ranges
3488 Displays the range of values allowed by this version of @command{tar}
3489 for each field in the snapshot file, then exits successfully.
3490 @xref{Snapshot Files}.
3492 @opsummary{show-transformed-names}
3493 @opsummary{show-stored-names}
3494 @item --show-transformed-names
3495 @itemx --show-stored-names
3497 Display file or member names after applying any transformations
3498 (@pxref{transform}).  In particular, when used in conjunction with one of
3499 the archive creation operations it instructs @command{tar} to list the
3500 member names stored in the archive, as opposed to the actual file
3501 names.  @xref{listing member and file names}.
3503 @opsummary{skip-old-files}
3504 @item --skip-old-files
3506 Do not overwrite existing files when extracting files from an
3507 archive.  @xref{Keep Old Files}.
3509 This option differs from @option{--keep-old-files} in that it does not
3510 treat such files as an error, instead it just silently avoids
3511 overwriting them.
3513 The @option{--warning=existing-file} option can be used together with
3514 this option to produce warning messages about existing old files
3515 (@pxref{warnings}).
3517 @opsummary{sort}
3518 @item --sort=@var{order}
3519 Specify the directory sorting order when reading directories.
3520 @var{Order} may be one of the following:
3522 @table @samp
3523 @item none
3524 No directory sorting is performed. This is the default.
3526 @item name
3527 Sort the directory entries on name. The operating system may deliver
3528 directory entries in a more or less random order, and sorting them
3529 makes archive creation more reproducible.  @xref{Reproducibility}.
3531 @item inode
3532 Sort the directory entries on inode number. Sorting directories on
3533 inode number may reduce the amount of disk seek operations when
3534 creating an archive for some file systems.
3536 @end table
3538 @opsummary{sparse}
3539 @item --sparse
3540 @itemx -S
3542 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3543 sparse files efficiently.  @xref{sparse}.
3545 @opsummary{sparse-version}
3546 @item --sparse-version=@var{version}
3548 Specifies the @dfn{format version} to use when archiving sparse
3549 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3550 of the supported sparse formats, @xref{Sparse Formats}.
3552 @opsummary{starting-file}
3553 @item --starting-file=@var{name}
3554 @itemx -K @var{name}
3556 This option affects extraction only; @command{tar} will skip extracting
3557 files in the archive until it finds one that matches @var{name}.
3558 @xref{Scarce}.
3560 @opsummary{strip-components}
3561 @item --strip-components=@var{number}
3562 Strip given @var{number} of leading components from file names before
3563 extraction.  For example, if archive @file{archive.tar} contained
3564 @file{/some/file/name}, then running
3566 @smallexample
3567 tar --extract --file archive.tar --strip-components=2
3568 @end smallexample
3570 @noindent
3571 would extract this file to file @file{name}.
3573 @xref{transform}.
3575 @opsummary{suffix}
3576 @item --suffix=@var{suffix}
3578 Alters the suffix @command{tar} uses when backing up files from the default
3579 @samp{~}.  @xref{backup}.
3581 @opsummary{tape-length}
3582 @item --tape-length=@var{num}[@var{suf}]
3583 @itemx -L @var{num}[@var{suf}]
3585 Specifies the length of tapes that @command{tar} is writing as being
3586 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3587 specifies a multiplicative factor to be used instead of 1024.  For
3588 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3589 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3590 discussion of this option.
3592 @opsummary{test-label}
3593 @item --test-label
3595 Reads the volume label.  If an argument is specified, test whether it
3596 matches the volume label.  @xref{--test-label option}.
3598 @opsummary{to-command}
3599 @item --to-command=@var{command}
3601 During extraction @command{tar} will pipe extracted files to the
3602 standard input of @var{command}.  @xref{Writing to an External Program}.
3604 @opsummary{to-stdout}
3605 @item --to-stdout
3606 @itemx -O
3608 During extraction, @command{tar} will extract files to stdout rather
3609 than to the file system.  @xref{Writing to Standard Output}.
3611 @opsummary{totals}
3612 @item --totals[=@var{signo}]
3614 Displays the total number of bytes transferred when processing an
3615 archive.  If an argument is given, these data are displayed on
3616 request, when signal @var{signo} is delivered to @command{tar}.
3617 @xref{totals}.
3619 @opsummary{touch}
3620 @item --touch
3621 @itemx -m
3623 Sets the data modification time of extracted files to the extraction time,
3624 rather than the data modification time stored in the archive.
3625 @xref{Data Modification Times}.
3627 @opsummary{transform}
3628 @opsummary{xform}
3629 @item --transform=@var{sed-expr}
3630 @itemx --xform=@var{sed-expr}
3631 Transform file or member names using @command{sed} replacement expression
3632 @var{sed-expr}.  For example,
3634 @smallexample
3635 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3636 @end smallexample
3638 @noindent
3639 will add to @file{archive} files from the current working directory,
3640 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3641 discussion, @xref{transform}.
3643 To see transformed member names in verbose listings, use
3644 @option{--show-transformed-names} option
3645 (@pxref{show-transformed-names}).
3647 @opsummary{uncompress}
3648 @item --uncompress
3650 (See @option{--compress}, @pxref{gzip})
3652 @opsummary{ungzip}
3653 @item --ungzip
3655 (See @option{--gzip}, @pxref{gzip})
3657 @opsummary{unlink-first}
3658 @item --unlink-first
3659 @itemx -U
3661 Directs @command{tar} to remove the corresponding file from the file
3662 system before extracting it from the archive.  @xref{Unlink First}.
3664 @opsummary{unquote}
3665 @item --unquote
3666 Enable unquoting input file or member names (default).  @xref{input
3667 name quoting}.
3669 @opsummary{use-compress-program}
3670 @item --use-compress-program=@var{prog}
3671 @itemx -I=@var{prog}
3673 Instructs @command{tar} to access the archive through @var{prog}, which is
3674 presumed to be a compression program of some sort.  @xref{gzip}.
3676 @opsummary{utc}
3677 @item --utc
3679 Display file modification dates in @acronym{UTC}.  This option implies
3680 @option{--verbose}.
3682 @opsummary{verbatim-files-from}
3683 @item --verbatim-files-from
3685 Instructs @GNUTAR{} to treat each line read from a file list as a file
3686 name, even if it starts with a dash.
3688 File lists are supplied with the @option{--files-from} (@option{-T})
3689 option.  By default, each line read from a file list is first trimmed
3690 off the leading and trailing whitespace and, if the result begins with
3691 a dash, it is treated as a @GNUTAR{} command line option.
3693 Use the @option{--verbatim-files-from} option to disable this special
3694 handling.  This facilitates the use of @command{tar} with file lists
3695 created by @command{file} command.
3697 This option affects all @option{--files-from} options that occur after
3698 it in the command line.  Its effect is reverted by the
3699 @option{--no-verbatim-files-from} option.
3701 This option is implied by the @option{--null} option.
3703 @xref{verbatim-files-from}.
3705 @opsummary{verbose}
3706 @item --verbose
3707 @itemx -v
3709 Specifies that @command{tar} should be more verbose about the
3710 operations it is performing.  This option can be specified multiple
3711 times for some operations to increase the amount of information displayed.
3712 @xref{verbose}.
3714 @opsummary{verify}
3715 @item --verify
3716 @itemx -W
3718 Verifies that the archive was correctly written when creating an
3719 archive.  @xref{verify}.
3721 @opsummary{version}
3722 @item --version
3724 Print information about the program's name, version, origin and legal
3725 status, all on standard output, and then exit successfully.
3726 @xref{help}.
3728 @opsummary{volno-file}
3729 @item --volno-file=@var{file}
3731 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3732 keep track of which volume of a multi-volume archive it is working in
3733 @var{file}.  @xref{volno-file}.
3735 @opsummary{warning}
3736 @item --warning=@var{keyword}
3738 Enable or disable warning messages identified by @var{keyword}.  The
3739 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3740 @xref{warnings}.
3742 @opsummary{wildcards}
3743 @item --wildcards
3744 Use wildcards when matching member names with patterns.
3745 @xref{controlling pattern-matching}.
3747 @opsummary{wildcards-match-slash}
3748 @item --wildcards-match-slash
3749 Wildcards match @samp{/}.
3750 @xref{controlling pattern-matching}.
3752 @opsummary{xattrs}
3753 @item --xattrs
3754 Enable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3756 @opsummary{xattrs-exclude}
3757 @item --xattrs-exclude=@var{pattern}
3758 Specify exclude pattern for xattr keys.
3759 @xref{Extended File Attributes, xattrs-exclude}.
3761 @opsummary{xattrs-include}
3762 @item --xattrs-include=@var{pattern}.
3763 Specify include pattern for xattr keys.  @var{pattern} is a globbing
3764 pattern, e.g. @samp{--xattrs-include='user.*'} to include
3765 only attributes from the user namespace.
3766 @xref{Extended File Attributes, xattrs-include}.
3768 @opsummary{xz}
3769 @item --xz
3770 @itemx -J
3771 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3773 @item --zstd
3774 Use @command{zstd} for compressing or decompressing the archives.  @xref{gzip}.
3776 @end table
3778 @node Short Option Summary
3779 @subsection Short Options Cross Reference
3781 Here is an alphabetized list of all of the short option forms, matching
3782 them with the equivalent long option.
3784 @multitable @columnfractions 0.20 0.80
3785 @headitem Short Option  @tab Reference
3787 @item -A @tab @ref{--concatenate}.
3789 @item -B @tab @ref{--read-full-records}.
3791 @item -C @tab @ref{--directory}.
3793 @item -F @tab @ref{--info-script}.
3795 @item -G @tab @ref{--incremental}.
3797 @item -J @tab @ref{--xz}.
3799 @item -K @tab @ref{--starting-file}.
3801 @item -L @tab @ref{--tape-length}.
3803 @item -M @tab @ref{--multi-volume}.
3805 @item -N @tab @ref{--newer}.
3807 @item -O @tab @ref{--to-stdout}.
3809 @item -P @tab @ref{--absolute-names}.
3811 @item -R @tab @ref{--block-number}.
3813 @item -S @tab @ref{--sparse}.
3815 @item -T @tab @ref{--files-from}.
3817 @item -U @tab @ref{--unlink-first}.
3819 @item -V @tab @ref{--label}.
3821 @item -W @tab @ref{--verify}.
3823 @item -X @tab @ref{--exclude-from}.
3825 @item -Z @tab @ref{--compress}.
3827 @item -b @tab @ref{--blocking-factor}.
3829 @item -c @tab @ref{--create}.
3831 @item -d @tab @ref{--compare}.
3833 @item -f @tab @ref{--file}.
3835 @item -g @tab @ref{--listed-incremental}.
3837 @item -h @tab @ref{--dereference}.
3839 @item -i @tab @ref{--ignore-zeros}.
3841 @item -j @tab @ref{--bzip2}.
3843 @item -k @tab @ref{--keep-old-files}.
3845 @item -l @tab @ref{--check-links}.
3847 @item -m @tab @ref{--touch}.
3849 @item -o @tab When extracting, same as @ref{--no-same-owner}. When creating,
3850 -- @ref{--old-archive}.
3852 The latter usage is deprecated.  It is retained for compatibility with
3853 the earlier versions of @GNUTAR{}.  In future releases
3854 @option{-o} will be equivalent to @option{--no-same-owner} only.
3856 @item -p @tab @ref{--preserve-permissions}.
3858 @item -r @tab @ref{--append}.
3860 @item -s @tab @ref{--same-order}.
3862 @item -t @tab @ref{--list}.
3864 @item -u @tab @ref{--update}.
3866 @item -v @tab @ref{--verbose}.
3868 @item -w @tab @ref{--interactive}.
3870 @item -x @tab @ref{--extract}.
3872 @item -z @tab @ref{--gzip}.
3874 @end multitable
3876 @node Position-Sensitive Options
3877 @subsection Position-Sensitive Options
3879 Some @GNUTAR{} options can be used multiple times in the same
3880 invocation and affect all arguments that appear after them.  These are
3881 options that control how file names are selected and what kind of
3882 pattern matching is used.
3884 The most obvious example is the @option{-C} option.  It instructs @command{tar}
3885 to change to the directory given as its argument prior to processing
3886 the rest of command line (@pxref{directory}).  Thus, in the following
3887 command:
3889 @example
3890 @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
3891 @end example
3893 @noindent
3894 the file @file{passwd} will be searched in the directory @file{/etc},
3895 and files @file{log} and @file{spool} -- in @file{/var}.
3897 These options can also be used in a file list supplied with the
3898 @option{--files-from} (@option{-T}) option (@pxref{files}).  In that
3899 case they affect all files (patterns) appearing in that file after
3900 them and remain in effect for any arguments processed after that file.
3901 For example, if the file @file{list.txt} contained:
3903 @example
3904 README
3905 -C src
3906 main.c
3907 @end example
3909 @noindent
3910 and @command{tar} were invoked as follows:
3912 @example
3913 @kbd{tar -c -f a.tar -T list.txt Makefile}
3914 @end example
3916 @noindent
3917 then the file @file{README} would be looked up in the current working
3918 directory, and files @file{main.c} and @file{Makefile} would be looked
3919 up in the directory @file{src}.
3921 Many options can be prefixed with @option{--no-} to cancel the effect
3922 of the original option.
3924 For example, the @option{--recursion} option controls whether to
3925 recurse in the subdirectories.  It's counterpart
3926 @option{--no-recursion} disables this.  Consider the command below.  It will
3927 store in the archive the directory @file{/usr} with all files and
3928 directories that are located in it as well as any files and
3929 directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
3930 option is the default and is used here for clarity.  The same example
3931 can be written as:
3933 @example
3934 tar -cf a.tar /usr --no-recursion /var/*
3935 @end example
3938 @example
3939 tar -cf a.tar --recursion /usr --no-recursion /var/*
3940 @end example
3942 During archive creation, @GNUTAR{} keeps track of positional options
3943 used and arguments affected by them.  If it finds out that any such
3944 options are used in an obviously erroneous way, the fact is reported
3945 and exit code is set to 2.  E.g.:
3947 @example
3948 @group
3949 $ @kbd{tar -cf a.tar . --exclude '*.o'}
3950 tar: The following options were used after any non-optional
3951 arguments in archive create or update mode.  These options are
3952 positional and affect only arguments that follow them.  Please,
3953 rearrange them properly.
3954 tar: --exclude '*.o' has no effect
3955 tar: Exiting with failure status due to previous errors
3956 @end group
3957 @end example
3959 The following table summarizes all position-sensitive options.
3961 @table @option
3962 @item --directory=@var{dir}
3963 @itemx -C @var{dir}
3964 @xref{directory}.
3966 @item --null
3967 @itemx --no-null
3968 @xref{nul}.
3970 @item --unquote
3971 @itemx --no-unquote
3972 @xref{input name quoting}.
3974 @item --verbatim-files-from
3975 @itemx --no-verbatim-files-from
3976 @xref{verbatim-files-from}.
3978 @item --recursion
3979 @itemx --no-recursion
3980 @xref{recurse}.
3982 @item --anchored
3983 @itemx --no-anchored
3984 @xref{anchored patterns}.
3986 @item --ignore-case
3987 @itemx --no-ignore-case
3988 @xref{case-insensitive matches}.
3990 @item --wildcards
3991 @itemx --no-wildcards
3992 @xref{controlling pattern-matching}.
3994 @item --wildcards-match-slash
3995 @itemx --no-wildcards-match-slash
3996 @xref{controlling pattern-matching}.
3998 @item --exclude
3999 @xref{exclude}.
4001 @item --exclude-from
4002 @itemx -X
4003 @itemx --exclude-caches
4004 @itemx --exclude-caches-under
4005 @itemx --exclude-caches-all
4006 @itemx --exclude-tag
4007 @itemx --exclude-ignore
4008 @itemx --exclude-ignore-recursive
4009 @itemx --exclude-tag-under
4010 @itemx --exclude-tag-all
4011 @itemx --exclude-vcs
4012 @itemx --exclude-vcs-ignores
4013 @itemx --exclude-backups
4014 @xref{exclude}.
4015 @end table
4017 @node help
4018 @section @GNUTAR{} documentation
4020 @cindex Getting program version number
4021 @opindex version
4022 @cindex Version of the @command{tar} program
4023 Being careful, the first thing is really checking that you are using
4024 @GNUTAR{}, indeed.  The @option{--version} option
4025 causes @command{tar} to print information about its name, version,
4026 origin and legal status, all on standard output, and then exit
4027 successfully.  For example, @w{@samp{tar --version}} might print:
4029 @smallexample
4030 tar (GNU tar) @value{VERSION}
4031 Copyright (C) 2024 Free Software Foundation, Inc.
4032 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
4033 This is free software: you are free to change and redistribute it.
4034 There is NO WARRANTY, to the extent permitted by law.
4036 Written by John Gilmore and Jay Fenlason.
4037 @end smallexample
4039 @noindent
4040 The first occurrence of @samp{tar} in the result above is the program
4041 name in the package (for example, @command{rmt} is another program),
4042 while the second occurrence of @samp{tar} is the name of the package
4043 itself, containing possibly many programs.  The package is currently
4044 named @samp{tar}, after the name of the main program it
4045 contains@footnote{There are plans to merge the @command{cpio} and
4046 @command{tar} packages into a single one which would be called
4047 @code{paxutils}.  So, who knows, one of these days
4048 @option{--version} might output @w{@samp{tar (@acronym{GNU}
4049 paxutils) 3.2}}.}.
4051 @cindex Obtaining help
4052 @cindex Listing all @command{tar} options
4053 @xopindex{help, introduction}
4054 Another thing you might want to do is check the spelling or meaning
4055 of some particular @command{tar} option, without resorting to this
4056 manual, once you have carefully read it.  @GNUTAR{}
4057 has a short help feature, triggerable through the
4058 @option{--help} option.  By using this option, @command{tar} will
4059 print a usage message listing all available options on standard
4060 output, then exit successfully, without doing anything else and
4061 ignoring all other options.  Even if this is only a brief summary, it
4062 may be several screens long.  So, if you are not using some kind of
4063 scrollable window, you might prefer to use something like:
4065 @smallexample
4066 $ @kbd{tar --help | less}
4067 @end smallexample
4069 @noindent
4070 presuming, here, that you like using @command{less} for a pager.  Other
4071 popular pagers are @command{more} and @command{pg}.  If you know about some
4072 @var{keyword} which interests you and do not want to read all the
4073 @option{--help} output, another common idiom is doing:
4075 @smallexample
4076 tar --help | grep @var{keyword}
4077 @end smallexample
4079 @noindent
4080 for getting only the pertinent lines.  Notice, however, that some
4081 @command{tar} options have long description lines and the above
4082 command will list only the first of them.
4084 The exact look of the option summary displayed by @kbd{tar --help} is
4085 configurable. @xref{Configuring Help Summary}, for a detailed description.
4087 @opindex usage
4088 If you only wish to check the spelling of an option, running @kbd{tar
4089 --usage} may be a better choice.  This will display a terse list of
4090 @command{tar} options without accompanying explanations.
4092 The short help output is quite succinct, and you might have to get
4093 back to the full documentation for precise points.  If you are reading
4094 this paragraph, you already have the @command{tar} manual in some
4095 form.  This manual is available in a variety of forms from
4096 @url{https://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
4097 distribution, provided you have @TeX{} already installed somewhere,
4098 and a laser printer around.  Just configure the distribution, execute
4099 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
4100 usual way (contact your local guru to know how).  If @GNUTAR{}
4101 has been conveniently installed at your place, this
4102 manual is also available in interactive, hypertextual form as an Info
4103 file.  Just call @w{@samp{info tar}} or, if you do not have the
4104 @command{info} program handy, use the Info reader provided within
4105 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
4107 Since 2014, @GNUTAR{} also has a @code{man} page.
4108 It briefly explains all the options and operations.
4109 This might be preferable when you don't need any background.
4110 But bear in mind that the authoritative source of
4111 information about @GNUTAR{} is this Texinfo documentation.
4113 @node defaults
4114 @section Obtaining @GNUTAR{} default values
4116 @opindex show-defaults
4117 @GNUTAR{} has some predefined defaults that are used when you do not
4118 explicitly specify another values.  To obtain a list of such
4119 defaults, use @option{--show-defaults} option.  This will output the
4120 values in the form of @command{tar} command line options:
4122 @smallexample
4123 @group
4124 $ @kbd{tar --show-defaults}
4125 --format=gnu -f- -b20 --quoting-style=escape
4126 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
4127 @end group
4128 @end smallexample
4130 @noindent
4131 Notice, that this option outputs only one line.  The example output above
4132 has been split to fit page boundaries.
4134 @noindent
4135 The above output shows that this version of @GNUTAR{} defaults to
4136 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
4137 output as the archive, if no @option{--file} option has been given
4138 (@pxref{file tutorial}), the default blocking factor is 20
4139 (@pxref{Blocking Factor}).  It also shows the default locations where
4140 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
4142 @node verbose
4143 @section Checking @command{tar} progress
4145 Typically, @command{tar} performs most operations without reporting any
4146 information to the user except error messages.  When using @command{tar}
4147 with many options, particularly ones with complicated or
4148 difficult-to-predict behavior, it is possible to make serious mistakes.
4149 @command{tar} provides several options that make observing @command{tar}
4150 easier.  These options cause @command{tar} to print information as it
4151 progresses in its job, and you might want to use them just for being
4152 more careful about what is going on, or merely for entertaining
4153 yourself.  If you have encountered a problem when operating on an
4154 archive, however, you may need more information than just an error
4155 message in order to solve the problem.  The following options can be
4156 helpful diagnostic tools.
4158 @cindex Verbose operation
4159 @opindex verbose
4160 Normally, the @option{--list} (@option{-t}) command to list an archive
4161 prints just the file names (one per line) and the other commands are
4162 silent. When used with most operations, the @option{--verbose}
4163 (@option{-v}) option causes @command{tar} to print the name of each
4164 file or archive member as it is processed.  This and the other options
4165 which make @command{tar} print status information can be useful in
4166 monitoring @command{tar}.
4168 With @option{--create} or @option{--extract}, @option{--verbose} used
4169 once just prints the names of the files or members as they are processed.
4170 Using it twice causes @command{tar} to print a longer listing
4171 (@xref{verbose member listing}, for the description) for each member.
4172 Since @option{--list} already prints  the names of the members,
4173 @option{--verbose} used once with @option{--list} causes @command{tar}
4174 to print an @samp{ls -l} type listing of the files in the archive.
4175 The following examples both extract members with long list output:
4177 @smallexample
4178 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
4179 $ @kbd{tar xvvf archive.tar}
4180 @end smallexample
4182 Verbose output appears on the standard output except when an archive is
4183 being written to the standard output, as with @samp{tar --create
4184 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
4185 installer let standard output be the default archive).  In that case
4186 @command{tar} writes verbose output to the standard error stream.
4188 If @option{--index-file=@var{file}} is specified, @command{tar} sends
4189 verbose output to @var{file} rather than to standard output or standard
4190 error.
4192 @anchor{totals}
4193 @cindex Obtaining total status information
4194 @opindex totals
4195 The @option{--totals} option causes @command{tar} to print on the
4196 standard error the total amount of bytes transferred when processing
4197 an archive.  When creating or appending to an archive, this option
4198 prints the number of bytes written to the archive and the average
4199 speed at which they have been written, e.g.:
4201 @smallexample
4202 @group
4203 $ @kbd{tar -c -f archive.tar --totals /home}
4204 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
4205 @end group
4206 @end smallexample
4208 When reading an archive, this option displays the number of bytes
4209 read:
4211 @smallexample
4212 @group
4213 $ @kbd{tar -x -f archive.tar --totals}
4214 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
4215 @end group
4216 @end smallexample
4218 Notice, that since @command{tar} operates on @dfn{records}, the number
4219 of bytes reported can be rounded up to the nearest full record.  This
4220 can happen, in particular, when the last record in the archive is
4221 partial.  @xref{Blocking}.
4223 Finally, when deleting from an archive, the @option{--totals} option
4224 displays both numbers plus number of bytes removed from the archive:
4226 @smallexample
4227 @group
4228 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
4229 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
4230 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
4231 Total bytes deleted: 1474048
4232 @end group
4233 @end smallexample
4235 You can also obtain this information on request.  When
4236 @option{--totals} is used with an argument, this argument is
4237 interpreted as a symbolic name of a signal, upon delivery of which the
4238 statistics is to be printed:
4240 @table @option
4241 @item --totals=@var{signo}
4242 Print statistics upon delivery of signal @var{signo}.  Valid arguments
4243 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4244 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
4245 accepted.
4246 @end table
4248 Both forms of @option{--totals} option can be used simultaneously.
4249 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
4250 extract all members from its default archive and print statistics
4251 after finishing the extraction, as well as when receiving signal
4252 @code{SIGUSR1}.
4254 @anchor{Progress information}
4255 @cindex Progress information
4256 The @option{--checkpoint} option prints an occasional message
4257 as @command{tar} reads or writes the archive.  It is designed for
4258 those who don't need the more detailed (and voluminous) output of
4259 @option{--block-number} (@option{-R}), but do want visual confirmation
4260 that @command{tar} is actually making forward progress.  By default it
4261 prints a message each 10 records read or written.  This can be changed
4262 by giving it a numeric argument after an equal sign:
4264 @smallexample
4265 $ @kbd{tar -c --checkpoint=1000} /var
4266 tar: Write checkpoint 1000
4267 tar: Write checkpoint 2000
4268 tar: Write checkpoint 3000
4269 @end smallexample
4271 This example shows the default checkpoint message used by
4272 @command{tar}.  If you place a dot immediately after the equal
4273 sign, it will print a @samp{.} at each checkpoint@footnote{This is
4274 actually a shortcut for @option{--checkpoint=@var{n}
4275 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
4277 @smallexample
4278 $ @kbd{tar -c --checkpoint=.1000} /var
4280 @end smallexample
4282 The @option{--checkpoint} option provides a flexible mechanism for
4283 executing arbitrary actions upon hitting checkpoints, see the next
4284 section (@pxref{checkpoints}), for more information on it.
4286 @opindex show-omitted-dirs
4287 @anchor{show-omitted-dirs}
4288 The @option{--show-omitted-dirs} option, when reading an archive---with
4289 @option{--list} or @option{--extract}, for example---causes a message
4290 to be printed for each directory in the archive which is skipped.
4291 This happens regardless of the reason for skipping: the directory might
4292 not have been named on the command line (implicitly or explicitly),
4293 it might be excluded by the use of the
4294 @option{--exclude=@var{pattern}} option, or some other reason.
4296 @opindex block-number
4297 @cindex Block number where error occurred
4298 @anchor{block-number}
4299 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
4300 every message it would normally produce, the block number within the
4301 archive where the message was triggered.  Also, supplementary messages
4302 are triggered when reading blocks full of NULs, or when hitting end of
4303 file on the archive.  As of now, if the archive is properly terminated
4304 with a NUL block, the reading of the file may stop before end of file
4305 is met, so the position of end of file will not usually show when
4306 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
4307 drains the archive before exiting when reading the
4308 archive from a pipe.
4310 @cindex Error message, block number of
4311 This option is especially useful when reading damaged archives, since
4312 it helps pinpoint the damaged sections.  It can also be used with
4313 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
4314 choose among several backup tapes when retrieving a file later, in
4315 favor of the tape where the file appears earliest (closest to the
4316 front of the tape).  @xref{backup}.
4318 @node checkpoints
4319 @section Checkpoints
4320 @cindex checkpoints, defined
4321 @opindex checkpoint
4322 @opindex checkpoint-action
4324 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
4325 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
4326 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
4327 periodically execute arbitrary actions.
4329 The checkpoint facility is enabled using the following option:
4331 @table @option
4332 @xopindex{checkpoint, defined}
4333 @item --checkpoint[=@var{n}]
4334 Schedule checkpoints before writing or reading each @var{n}th record.
4335 The default value for @var{n} is 10.
4336 @end table
4338 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
4339 These actions include: pausing, displaying textual messages, and
4340 executing arbitrary external programs.  Actions are defined using
4341 the @option{--checkpoint-action} option.
4343 @table @option
4344 @xopindex{checkpoint-action, defined}
4345 @item --checkpoint-action=@var{action}
4346 Execute an @var{action} at each checkpoint.
4347 @end table
4349 @cindex @code{echo}, checkpoint action
4350 The simplest value of @var{action} is @samp{echo}.  It instructs
4351 @command{tar} to display the default message on the standard error
4352 stream upon arriving at each checkpoint.  The default message is (in
4353 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
4354 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
4355 Here, @var{n} represents ordinal number of the checkpoint.
4357 In another locales, translated versions of this message are used.
4359 This is the default action, so running:
4361 @smallexample
4362 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
4363 @end smallexample
4365 @noindent
4366 is equivalent to:
4368 @smallexample
4369 $ @kbd{tar -c --checkpoint=1000} /var
4370 @end smallexample
4372 The @samp{echo} action also allows to supply a customized message.
4373 You do so by placing an equals sign and the message right after it,
4374 e.g.:
4376 @smallexample
4377 --checkpoint-action="echo=Hit %s checkpoint #%u"
4378 @end smallexample
4380 The @samp{%s} and @samp{%u} in the above example are
4381 @dfn{format specifiers}.  The @samp{%s} specifier is replaced with
4382 the @dfn{type} of the checkpoint: @samp{write} or
4383 @samp{read} (or a corresponding translated version in locales other
4384 than @acronym{POSIX}).  The @samp{%u} specifier is replaced with
4385 the ordinal number of the checkpoint.  Thus, the above example could
4386 produce the following output when used with the @option{--create}
4387 option:
4389 @smallexample
4390 tar: Hit write checkpoint #10
4391 tar: Hit write checkpoint #20
4392 tar: Hit write checkpoint #30
4393 @end smallexample
4395 The complete list of available format specifiers follows.  Some of
4396 them can take optional arguments.  These arguments, if given, are
4397 supplied in curly braces between the percent sign and the specifier
4398 letter.
4400 @table @samp
4401 @item %s
4402 Print type of the checkpoint (@samp{write} or @samp{read}).
4404 @item %u
4405 Print number of the checkpoint.
4407 @item %@{r,w,d@}T
4408 Print number of bytes transferred so far and approximate transfer
4409 speed.  Optional arguments supply prefixes to be used before number
4410 of bytes read, written and deleted, correspondingly.  If absent,
4411 they default to @samp{R}. @samp{W}, @samp{D}.  Any or all of them can
4412 be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
4413 statistics without any prefixes.  Any surplus arguments, if present,
4414 are silently ignored.
4416 @example
4417 $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
4418 tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
4419 tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
4420 @end example
4422 @noindent
4423 See also the @samp{totals} action, described below.
4425 @item %@{@var{fmt}@}t
4426 Output current local time using @var{fmt} as format for @command{strftime}
4427 (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}).  The
4428 @samp{@{@var{fmt}@}} part is optional.  If not present, the default
4429 format is @samp{%c}, i.e. the preferred date and time representation
4430 for the current locale.
4432 @item %@{@var{n}@}*
4433 Pad output with spaces to the @var{n}th column.  If the
4434 @samp{@{@var{n}@}} part is omitted, the current screen width
4435 is assumed.
4437 @item %c
4438 This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
4439 intended mainly for use with @samp{ttyout} action (see below).
4440 @end table
4442 Aside from format expansion, the message string is subject to
4443 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
4444 replaced with their corresponding @acronym{ASCII} characters
4445 (@pxref{escape sequences}).  E.g. the following action will produce an
4446 audible bell and the message described above at each checkpoint:
4448 @smallexample
4449 --checkpoint-action='echo=\aHit %s checkpoint #%u'
4450 @end smallexample
4452 @cindex @code{bell}, checkpoint action
4453 There is also a special action which produces an audible signal:
4454 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
4455 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
4456 whereas @samp{echo='\a'} sends it to the standard error.
4458 @cindex @code{ttyout}, checkpoint action
4459 The @samp{ttyout=@var{string}} action outputs @var{string} to
4460 @file{/dev/tty}, so it can be used even if the standard output is
4461 redirected elsewhere.  The @var{string} is subject to the same
4462 modifications as with @samp{echo} action.  In contrast to the latter,
4463 @samp{ttyout} does not prepend @command{tar} executable name to the
4464 string, nor does it output a newline after it.  For example, the
4465 following action will print the checkpoint message at the same screen
4466 line, overwriting any previous message:
4468 @smallexample
4469 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
4470 @end smallexample
4472 @noindent
4473 Notice the use of @samp{%*} specifier to clear out any eventual
4474 remains of the prior output line.  As as more complex example,
4475 consider this:
4477 @smallexample
4478 --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
4479 @end smallexample
4481 @noindent
4482 This prints the current local time, number of seconds expired since
4483 tar was started, the checkpoint ordinal number, transferred bytes and
4484 average computed I/O speed.
4486 @cindex @code{dot}, checkpoint action
4487 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
4488 instructs @command{tar} to print a single dot on the standard listing
4489 stream, e.g.:
4491 @smallexample
4492 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4494 @end smallexample
4496 For compatibility with previous @GNUTAR{} versions, this action can
4497 be abbreviated by placing a dot in front of the checkpoint frequency,
4498 as shown in the previous section.
4500 @cindex @code{totals}, checkpoint action
4501 The @samp{totals} action prints the total number of bytes transferred
4502 so far.  The format of the data is the same as for the
4503 @option{--totals} option (@pxref{totals}).  See also @samp{%T} format
4504 specifier of the @samp{echo} or @samp{ttyout} action.
4506 @cindex @code{sleep}, checkpoint action
4507 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4508 amount of seconds.  The following example will stop for 30 seconds at each
4509 checkpoint:
4511 @smallexample
4512 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4513 @end smallexample
4515 @anchor{checkpoint wait}
4516 @cindex @code{wait}, checkpoint action
4517 The @code{wait=@var{signo}} action stops further execution until the
4518 signal @var{signo} is delivered.  Valid values for @var{signo} are:
4519 @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4520 @code{SIGUSR2}.  The @samp{SIG} prefix is optional.  For example:
4522 @example
4523 $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
4524 @end example
4526 In this example, @GNUTAR{} will stop archivation at each 1000th
4527 checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
4528 and resume processing.
4530 This action is used by the @command{genfile} utility to perform
4531 modifications on the input files upon hitting certain checkpoints
4532 (@pxref{Exec Mode, genfile}).
4534 @anchor{checkpoint exec}
4535 @cindex @code{exec}, checkpoint action
4536 Finally, the @code{exec} action executes a given external command.
4537 For example:
4539 @smallexample
4540 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4541 @end smallexample
4543 The supplied command can be any valid command invocation, with or
4544 without additional command line arguments.  If it does contain
4545 arguments, don't forget to quote it to prevent it from being split by
4546 the shell.  @xref{external, Running External Commands}, for more detail.
4548 The command gets a copy of @command{tar}'s environment plus the
4549 following variables:
4551 @table @env
4552 @vrindex TAR_VERSION, checkpoint script environment
4553 @item TAR_VERSION
4554 @GNUTAR{} version number.
4556 @vrindex TAR_ARCHIVE, checkpoint script environment
4557 @item TAR_ARCHIVE
4558 The name of the archive @command{tar} is processing.
4560 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4561 @item TAR_BLOCKING_FACTOR
4562 Current blocking factor (@pxref{Blocking}).
4564 @vrindex TAR_CHECKPOINT, checkpoint script environment
4565 @item TAR_CHECKPOINT
4566 Number of the checkpoint.
4568 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4569 @item TAR_SUBCOMMAND
4570 A short option describing the operation @command{tar} is executing.
4571 @xref{Operations}, for a complete list of subcommand options.
4573 @vrindex TAR_FORMAT, checkpoint script environment
4574 @item TAR_FORMAT
4575 Format of the archive being processed. @xref{Formats}, for a complete
4576 list of archive format names.
4577 @end table
4579 These environment variables can also be passed as arguments to the
4580 command, provided that they are properly escaped, for example:
4582 @smallexample
4583 @kbd{tar -c -f arc.tar \
4584      --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
4585 @end smallexample
4587 @noindent
4588 Notice single quotes to prevent variable names from being expanded by
4589 the shell when invoking @command{tar}.
4591 Any number of actions can be defined, by supplying several
4592 @option{--checkpoint-action} options in the command line.  For
4593 example, the command below displays two messages, pauses
4594 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4596 @example
4597 @group
4598 $ @kbd{tar -c -f arc.tar \
4599        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4600        --checkpoint-action='echo=Sleeping for 30 seconds' \
4601        --checkpoint-action='sleep=30' \
4602        --checkpoint-action='exec=/sbin/cpoint'}
4603 @end group
4604 @end example
4606 This example also illustrates the fact that
4607 @option{--checkpoint-action} can be used without
4608 @option{--checkpoint}.  In this case, the default checkpoint frequency
4609 (at each 10th record) is assumed.
4611 @node warnings
4612 @section Controlling Warning Messages
4614 Sometimes, while performing the requested task, @GNUTAR{} notices
4615 some conditions that are not exactly errors, but which the user
4616 should be aware of.  When this happens, @command{tar} issues a
4617 @dfn{warning message} describing the condition.  Warning messages
4618 are output to the standard error and they do not affect the exit
4619 code of @command{tar} command.
4621 @xopindex{warning, explained}
4622 @GNUTAR{} allows the user to suppress some or all of its warning
4623 messages:
4625 @table @option
4626 @item --warning=@var{keyword}
4627 Control display of the warning messages identified by @var{keyword}.
4628 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4629 suppressed.  Otherwise, they are enabled.
4631 Multiple @option{--warning} options accumulate.
4632 @end table
4634 By default, @GNUTAR enables all messages, except those that are
4635 enabled in verbose mode (@pxref{verbose tutorial}).  @xref{Warning
4636 Defaults}, for details.
4638 The subsections below discuss allowed values for @var{keyword} along with the
4639 warning messages they control.
4641 @menu
4642 * General Warnings::  Keywords applicable for @command{tar --create}.
4643 * Archive Creation Warnings:: Keywords applicable for @command{tar --create}.
4644 * Archive Extraction Warnings:: Keywords applicable for @command{tar --extract}.
4645 * Incremental Extraction Warnings:: Keywords controlling incremental extraction.
4646 * Warning Classes:: Convenience keywords control multiple warnings.
4647 * Warning Defaults:: Default settings for warnings.
4648 @end menu
4650 @node General Warnings
4651 @subsection Keywords controlling @command{tar} operation
4653 These keywords control warnings that may appear in any @GNUTAR{}
4654 operation mode:
4656 @defvr {warning} filename-with-nuls
4657 @cindex @samp{file name read contains nul character}, warning message
4658 @samp{file name read contains nul character}
4659 @end defvr
4661 @defvr {warning} filename-with-nuls
4662 @cindex @samp{file name read contains nul character}, warning message
4663 @samp{%s: file name read contains nul character}
4664 @end defvr
4666 @defvr {warning} alone-zero-block
4667 @cindex @samp{A lone zero block at}, warning message
4668 @samp{A lone zero block at %s}.  Notice, that this warning is
4669 suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
4670 Zeros}).
4671 @end defvr
4673 @defvr {warning} missing-zero-blocks
4674 @cindex @samp{Terminating zero blocks missing}, warning message.
4675 @samp{Terminating zero blocks missing at %s}.  This warning is
4676 suppressed if @option{--ignore-zeros} is in effect (@pxref{Ignore
4677 Zeros}).
4678 @end defvr
4680 @node Archive Creation Warnings
4681 @subsection Keywords applicable for @command{tar --create}
4683 The following keywords control messages that can be issued while
4684 creating archives.
4686 @defvr {warning} cachedir
4687 @cindex @samp{contains a cache directory tag}, warning message
4688 @samp{%s: contains a cache directory tag %s; %s}
4689 @end defvr
4691 @defvr {warning} file-shrank
4692 @cindex @samp{File shrank by %s bytes}, warning message
4693 @samp{%s: File shrank by %s bytes; padding with zeros}
4694 @end defvr
4696 @defvr {warning} xdev
4697 @cindex @samp{file is on a different filesystem}, warning message
4698 @samp{%s: file is on a different filesystem; not dumped}
4699 @end defvr
4701 @defvr {warning} file-ignored
4702 @cindex @samp{Unknown file type; file ignored}, warning message
4703 @cindex @samp{socket ignored}, warning message
4704 @cindex @samp{door ignored}, warning message
4705 @samp{%s: Unknown file type; file ignored}
4706 @*@samp{%s: socket ignored}
4707 @*@samp{%s: door ignored}
4708 @end defvr
4710 @defvr {warning} file-unchanged
4711 @cindex @samp{file is unchanged; not dumped}, warning message
4712 @samp{%s: file is unchanged; not dumped}
4713 @end defvr
4715 @defvr {warning} ignore-archive
4716 @cindex @samp{archive cannot contain itself; not dumped}, warning message
4717 @samp{%s: archive cannot contain itself; not dumped}
4718 @end defvr
4720 @defvr {warning} file-removed
4721 @cindex @samp{File removed before we read it}, warning message
4722 @samp{%s: File removed before we read it}
4723 @end defvr
4725 @defvr {warning} file-changed
4726 @cindex @samp{file changed as we read it}, warning message
4727 @samp{%s: file changed as we read it}
4729 Suppresses warnings about read failures, which can occur if files
4730 or directories are unreadable, or if they change while being read.  This
4731 keyword applies only if used together with the @option{--ignore-failed-read}
4732 option. @xref{Ignore Failed Read}.
4733 @end defvr
4735 @node Archive Extraction Warnings
4736 @subsection Keywords applicable for @command{tar --extract}
4738 The following keywords control warnings that can be issued during
4739 archive extraction.
4741 @defvr {warning} existing-file
4742 @cindex @samp{%s: skipping existing file}, warning message
4743 @samp{%s: skipping existing file}
4744 @end defvr
4746 @defvr {warning} timestamp
4747 @cindex @samp{implausibly old time stamp %s}, warning message
4748 @cindex @samp{time stamp %s is %s s in the future}, warning message
4749 @samp{%s: implausibly old time stamp %s}
4750 @*@samp{%s: time stamp %s is %s s in the future}
4751 @end defvr
4753 @defvr {warning} contiguous-cast
4754 @cindex @samp{Extracting contiguous files as regular files}, warning message
4755 @samp{Extracting contiguous files as regular files}
4756 @end defvr
4758 @defvr {warning} symlink-cast
4759 @samp{Attempting extraction of symbolic links as hard links}, warning message
4760 @samp{Attempting extraction of symbolic links as hard links}
4761 @end defvr
4763 @defvr {warning} unknown-cast
4764 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4765 @samp{%s: Unknown file type '%c', extracted as normal file}
4766 @end defvr
4768 @defvr {warning} ignore-newer
4769 @cindex @samp{Current %s is newer or same age}, warning message
4770 @samp{Current %s is newer or same age}
4771 @end defvr
4773 @defvr {warning} unknown-keyword
4774 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4775 @samp{Ignoring unknown extended header keyword '%s'}
4776 @end defvr
4778 @defvr {warning} decompress-program
4779 Controls verbose description of failures occurring when trying to run
4780 alternative decompressor programs (@pxref{alternative decompression
4781 programs}).  This warning is disabled by default (unless
4782 @option{--verbose} is used).  A common example of what you can get
4783 when using this warning is:
4785 @smallexample
4786 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4787 tar (child): cannot run compress: No such file or directory
4788 tar (child): trying gzip
4789 @end smallexample
4791 This means that @command{tar} first tried to decompress
4792 @file{archive.Z} using @command{compress}, and, when that
4793 failed, switched to @command{gzip}.
4794 @end defvr
4796 @defvr {warning} record-size
4797 @cindex @samp{Record size = %lu blocks}, warning message
4798 @samp{Record size = %lu blocks}
4799 @end defvr
4801 @node Incremental Extraction Warnings
4802 @subsection Keywords controlling incremental extraction
4804 These keywords control warnings that may appear when extracting from
4805 incremental archives.
4807 @defvr {warning} rename-directory
4808 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4809 @cindex @samp{%s: Directory has been renamed}, warning message
4810 @samp{%s: Directory has been renamed from %s}
4811 @*@samp{%s: Directory has been renamed}
4812 @end defvr
4814 @defvr {warning} new-directory
4815 @cindex @samp{%s: Directory is new}, warning message
4816 @samp{%s: Directory is new}
4817 @end defvr
4819 @defvr {warning} xdev
4820 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4821 @samp{%s: directory is on a different device: not purging}
4822 @end defvr
4824 @defvr {warning} bad-dumpdir
4825 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4826 @samp{Malformed dumpdir: 'X' never used}
4827 @end defvr
4829 @node Warning Classes
4830 @subsection Warning Classes
4832 These convenience keywords define @dfn{warning classes}.  When used,
4833 they affect several warnings at once.
4835 @defvr {warning} all
4836 Enable all warning messages.
4837 @end defvr
4839 @defvr {warning} none
4840 Disable all warning messages.
4841 @end defvr
4843 @defvr {warning} verbose
4844 A shorthand for all messages enabled when @option{--verbose}
4845 (@pxref{verbose tutorial}) is in effect.  These are:
4846 @code{decompress-program}, @code{existing-file}, @code{new-directory},
4847 @code{record-size}, @code{rename-directory}.
4848 @end defvr
4850 @node Warning Defaults
4851 @subsection Default Warning Settings
4852 @GNUTAR default settings correspond to:
4854 @example
4855 --warning=all --warning=no-verbose --warning=no-missing-zero-blocks
4856 @end example
4858 @node interactive
4859 @section Asking for Confirmation During Operations
4860 @cindex Interactive operation
4862 Typically, @command{tar} carries out a command without stopping for
4863 further instructions.  In some situations however, you may want to
4864 exclude some files and archive members from the operation (for instance
4865 if disk or storage space is tight).  You can do this by excluding
4866 certain files automatically (@pxref{Choosing}), or by performing
4867 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4868 @command{tar} also accepts @option{--confirmation} for this option.
4870 @opindex interactive
4871 When the @option{--interactive} (@option{-w}) option is specified, before
4872 reading, writing, or deleting files, @command{tar} first prints a message
4873 for each such file, telling what operation it intends to take, then asks
4874 for confirmation on the terminal.  The actions which require
4875 confirmation include adding a file to the archive, extracting a file
4876 from the archive, deleting a file from the archive, and deleting a file
4877 from disk.  To confirm the action, you must type a line of input
4878 beginning with @samp{y}.  If your input line begins with anything other
4879 than @samp{y}, @command{tar} skips that file.
4881 If @command{tar} is reading the archive from the standard input,
4882 @command{tar} opens the file @file{/dev/tty} to support the interactive
4883 communications.
4885 Verbose output is normally sent to standard output, separate from
4886 other error messages.  However, if the archive is produced directly
4887 on standard output, then verbose output is mixed with errors on
4888 @code{stderr}.  Producing the archive on standard output may be used
4889 as a way to avoid using disk space, when the archive is soon to be
4890 consumed by another process reading it, say.  Some people felt the need
4891 of producing an archive on stdout, still willing to segregate between
4892 verbose output and error output.  A possible approach would be using a
4893 named pipe to receive the archive, and having the consumer process to
4894 read from that named pipe.  This has the advantage of letting standard
4895 output free to receive verbose output, all separate from errors.
4897 @node external
4898 @section Running External Commands
4900 Certain @GNUTAR{} operations imply running external commands that you
4901 supply on the command line.  One of such operations is checkpointing,
4902 described above (@pxref{checkpoint exec}).  Another example of this
4903 feature is the @option{-I} option, which allows you to supply the
4904 program to use for compressing or decompressing the archive
4905 (@pxref{use-compress-program}).
4907 Whenever such operation is requested, @command{tar} first splits the
4908 supplied command into words much like the shell does.  It then treats
4909 the first word as the name of the program or the shell script to execute
4910 and the rest of words as its command line arguments.  The program,
4911 unless given as an absolute file name, is searched in the shell's
4912 @env{PATH}.
4914 Any additional information is normally supplied to external commands
4915 in environment variables, specific to each particular operation.  For
4916 example, the @option{--checkpoint-action=exec} option, defines the
4917 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4918 upon.  You can, should the need be, use these variables in the
4919 command line of the external command.  For example:
4921 @smallexample
4922 $ @kbd{tar -x -f archive.tar \
4923     --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4924 @end smallexample
4926 @noindent
4927 This command prints for each checkpoint its number and the name of the
4928 archive, using the same output line on the screen.
4930 Notice the use of single quotes to prevent variable names from being
4931 expanded by the shell when invoking @command{tar}.
4933 @node operations
4934 @chapter @GNUTAR{} Operations
4936 @menu
4937 * Basic tar::
4938 * Advanced tar::
4939 * create options::
4940 * extract options::
4941 * backup::
4942 * looking ahead::
4943 @end menu
4945 @node Basic tar
4946 @section Basic @GNUTAR{} Operations
4948 The basic @command{tar} operations, @option{--create} (@option{-c}),
4949 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4950 @option{-x}), are currently presented and described in the tutorial
4951 chapter of this manual.  This section provides some complementary notes
4952 for these operations.
4954 @table @option
4955 @xopindex{create, complementary notes}
4956 @item --create
4957 @itemx -c
4959 Creating an empty archive would have some kind of elegance.  One can
4960 initialize an empty archive and later use @option{--append}
4961 (@option{-r}) for adding all members.  Some applications would not
4962 welcome making an exception in the way of adding the first archive
4963 member.  On the other hand, many people reported that it is
4964 dangerously too easy for @command{tar} to destroy a magnetic tape with
4965 an empty archive@footnote{This is well described in @cite{Unix-haters
4966 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4967 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4969 @enumerate
4970 @item
4971 Mistakingly using @code{create} instead of @code{extract}, when the
4972 intent was to extract the full contents of an archive.  This error
4973 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4974 the QWERTY keyboard.  Instead of being unpacked, the archive then
4975 gets wholly destroyed.  When users speak about @dfn{exploding} an
4976 archive, they usually mean something else :-).
4978 @item
4979 Forgetting the argument to @code{file}, when the intent was to create
4980 an archive with a single file in it.  This error is likely because a
4981 tired user can easily add the @kbd{f} key to the cluster of option
4982 letters, by the mere force of habit, without realizing the full
4983 consequence of doing so.  The usual consequence is that the single
4984 file, which was meant to be saved, is rather destroyed.
4985 @end enumerate
4987 So, recognizing the likelihood and the catastrophic nature of these
4988 errors, @GNUTAR{} now takes some distance from elegance, and
4989 cowardly refuses to create an archive when @option{--create} option is
4990 given, there are no arguments besides options, and
4991 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4992 around the cautiousness of @GNUTAR{} and nevertheless create an
4993 archive with nothing in it, one may still use, as the value for the
4994 @option{--files-from} option, a file with no names in it, as shown in
4995 the following commands:
4997 @smallexample
4998 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4999 @kbd{tar -cf empty-archive.tar -T /dev/null}
5000 @end smallexample
5002 @xopindex{extract, complementary notes}
5003 @item --extract
5004 @itemx --get
5005 @itemx -x
5007 A socket is stored, within a @GNUTAR{} archive, as a pipe.
5009 @item @option{--list} (@option{-t})
5011 @GNUTAR{} now shows dates as @samp{1996-08-30},
5012 while it used to show them as @samp{Aug 30 1996}. Preferably,
5013 people should get used to ISO 8601 dates.  Local American dates should
5014 be made available again with full date localization support, once
5015 ready.  In the meantime, programs not being localizable for dates
5016 should prefer international dates, that's really the way to go.
5018 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
5019 are curious, it contains a detailed explanation of the ISO 8601 standard.
5021 @end table
5023 @node Advanced tar
5024 @section Advanced @GNUTAR{} Operations
5026 Now that you have learned the basics of using @GNUTAR{}, you may want
5027 to learn about further ways in which @command{tar} can help you.
5029 This chapter presents five, more advanced operations which you probably
5030 won't use on a daily basis, but which serve more specialized functions.
5031 We also explain the different styles of options and why you might want
5032 to use one or another, or a combination of them in your @command{tar}
5033 commands.  Additionally, this chapter includes options which allow you to
5034 define the output from @command{tar} more carefully, and provide help and
5035 error correction in special circumstances.
5037 @FIXME{check this after the chapter is actually revised to make sure
5038 it still introduces the info in the chapter correctly : ).}
5040 @menu
5041 * Operations::
5042 * append::
5043 * update::
5044 * concatenate::
5045 * delete::
5046 * compare::
5047 @end menu
5049 @node Operations
5050 @subsection The Five Advanced @command{tar} Operations
5052 @cindex basic operations
5053 In the last chapter, you learned about the first three operations to
5054 @command{tar}.  This chapter presents the remaining five operations to
5055 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
5056 @option{--delete}, and @option{--compare}.
5058 You are not likely to use these operations as frequently as those
5059 covered in the last chapter; however, since they perform specialized
5060 functions, they are quite useful when you do need to use them.  We
5061 will give examples using the same directory and files that you created
5062 in the last chapter.  As you may recall, the directory is called
5063 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
5064 and the two archive files you created are
5065 @samp{collection.tar} and @samp{music.tar}.
5067 We will also use the archive files @samp{afiles.tar} and
5068 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
5069 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
5070 @samp{./birds}, @samp{baboon}, and @samp{./box}.
5072 Unless we state otherwise, all practicing you do and examples you follow
5073 in this chapter will take place in the @file{practice} directory that
5074 you created in the previous chapter; see @ref{prepare for examples}.
5075 (Below in this section, we will remind you of the state of the examples
5076 where the last chapter left them.)
5078 The five operations that we will cover in this chapter are:
5080 @table @option
5081 @item --append
5082 @itemx -r
5083 Add new entries to an archive that already exists.
5084 @item --update
5085 @itemx -u
5086 Add more recent copies of archive members to the end of an archive, if
5087 they exist.
5088 @item --concatenate
5089 @itemx --catenate
5090 @itemx -A
5091 Add one or more pre-existing archives to the end of another archive.
5092 @item --delete
5093 Delete items from an archive (does not work on tapes).
5094 @item --compare
5095 @itemx --diff
5096 @itemx -d
5097 Compare archive members to their counterparts in the file system.
5098 @end table
5100 @node append
5101 @subsection How to Add Files to Existing Archives: @option{--append}
5103 @cindex appending files to existing archive
5104 @opindex append
5105 If you want to add files to an existing archive, you don't need to
5106 create a new archive; you can use @option{--append} (@option{-r}).
5107 The archive must already exist in order to use @option{--append}.  (A
5108 related operation is the @option{--update} operation; you can use this
5109 to add newer versions of archive members to an existing archive.  To learn how to
5110 do this with @option{--update}, @pxref{update}.)
5112 If you use @option{--append} to add a file that has the same name as an
5113 archive member to an archive containing that archive member, then the
5114 old member is not deleted.  What does happen, however, is somewhat
5115 complex.  @command{tar} @emph{allows} you to have infinite number of files
5116 with the same name.  Some operations treat these same-named members no
5117 differently than any other set of archive members: for example, if you
5118 view an archive with @option{--list} (@option{-t}), you will see all
5119 of those members listed, with their data modification times, owners, etc.
5121 Other operations don't deal with these members as perfectly as you might
5122 prefer; if you were to use @option{--extract} to extract the archive,
5123 only the most recently added copy of a member with the same name as
5124 other members would end up in the working directory.  This is because
5125 @option{--extract} extracts an archive in the order the members appeared
5126 in the archive; the most recently archived members will be extracted
5127 last.  Additionally, an extracted member will @emph{replace} a file of
5128 the same name which existed in the directory already, and @command{tar}
5129 will not prompt you about this@footnote{Unless you give it
5130 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
5131 the disk copy is newer than the one in the archive and you invoke
5132 @command{tar} with @option{--keep-newer-files} option.}.  Thus, only
5133 the most recently archived member will end up being extracted, as it
5134 will replace the one extracted before it, and so on.
5136 @cindex extracting @var{n}th copy of the file
5137 @xopindex{occurrence, described}
5138 There exists a special option that allows you to get around this
5139 behavior and extract (or list) only a particular copy of the file.
5140 This is @option{--occurrence} option.  If you run @command{tar} with
5141 this option, it will extract only the first copy of the file.  You
5142 may also give this option an argument specifying the number of
5143 copy to be extracted.  Thus, for example if the archive
5144 @file{archive.tar} contained three copies of file @file{myfile}, then
5145 the command
5147 @smallexample
5148 tar --extract --file archive.tar --occurrence=2 myfile
5149 @end smallexample
5151 @noindent
5152 would extract only the second copy.  @xref{Option
5153 Summary,---occurrence}, for the description of @option{--occurrence}
5154 option.
5156 @FIXME{ hag -- you might want to incorporate some of the above into the
5157 MMwtSN node; not sure.  i didn't know how to make it simpler...
5159 There are a few ways to get around this.  Xref to Multiple Members
5160 with the Same Name, maybe.}
5162 @cindex Members, replacing with other members
5163 @cindex Replacing members with other members
5164 @xopindex{delete, using before --append}
5165 If you want to replace an archive member, use @option{--delete} to
5166 delete the member you want to remove from the archive, and then use
5167 @option{--append} to add the member you want to be in the archive.  Note
5168 that you can not change the order of the archive; the most recently
5169 added member will still appear last.  In this sense, you cannot truly
5170 ``replace'' one member with another.  (Replacing one member with another
5171 will not work on certain types of media, such as tapes; see @ref{delete}
5172 and @ref{Media}, for more information.)
5174 @menu
5175 * appending files::             Appending Files to an Archive
5176 * multiple::
5177 @end menu
5179 @node appending files
5180 @subsubsection Appending Files to an Archive
5181 @cindex Adding files to an Archive
5182 @cindex Appending files to an Archive
5183 @cindex Archives, Appending files to
5184 @opindex append
5186 The simplest way to add a file to an already existing archive is the
5187 @option{--append} (@option{-r}) operation, which writes specified
5188 files into the archive whether or not they are already among the
5189 archived files.
5191 When you use @option{--append}, you @emph{must} specify file name
5192 arguments, as there is no default.  If you specify a file that already
5193 exists in the archive, another copy of the file will be added to the
5194 end of the archive.  As with other operations, the member names of the
5195 newly added files will be exactly the same as their names given on the
5196 command line.  The @option{--verbose} (@option{-v}) option will print
5197 out the names of the files as they are written into the archive.
5199 @option{--append} cannot be performed on some tape drives, unfortunately,
5200 due to deficiencies in the formats those tape drives use.  The archive
5201 must be a valid @command{tar} archive, or else the results of using this
5202 operation will be unpredictable.  @xref{Media}.
5204 To demonstrate using @option{--append} to add a file to an archive,
5205 create a file called @file{rock} in the @file{practice} directory.
5206 Make sure you are in the @file{practice} directory.  Then, run the
5207 following @command{tar} command to add @file{rock} to
5208 @file{collection.tar}:
5210 @smallexample
5211 $ @kbd{tar --append --file=collection.tar rock}
5212 @end smallexample
5214 @noindent
5215 If you now use the @option{--list} (@option{-t}) operation, you will see that
5216 @file{rock} has been added to the archive:
5218 @smallexample
5219 $ @kbd{tar --list --file=collection.tar}
5220 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5221 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5222 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5223 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5224 @end smallexample
5226 @node multiple
5227 @subsubsection Multiple Members with the Same Name
5228 @cindex members, multiple
5229 @cindex multiple members
5231 You can use @option{--append} (@option{-r}) to add copies of files
5232 which have been updated since the archive was created.  (However, we
5233 do not recommend doing this since there is another @command{tar}
5234 option called @option{--update}; @xref{update}, for more information.
5235 We describe this use of @option{--append} here for the sake of
5236 completeness.)  When you extract the archive, the older version will
5237 be effectively lost.  This works because files are extracted from an
5238 archive in the order in which they were archived.  Thus, when the
5239 archive is extracted, a file archived later in time will replace a
5240 file of the same name which was archived earlier, even though the
5241 older version of the file will remain in the archive unless you delete
5242 all versions of the file.
5244 Supposing you change the file @file{blues} and then append the changed
5245 version to @file{collection.tar}.  As you saw above, the original
5246 @file{blues} is in the archive @file{collection.tar}.  If you change the
5247 file and append the new version of the file to the archive, there will
5248 be two copies in the archive.  When you extract the archive, the older
5249 version of the file will be extracted first, and then replaced by the
5250 newer version when it is extracted.
5252 You can append the new, changed copy of the file @file{blues} to the
5253 archive in this way:
5255 @smallexample
5256 $ @kbd{tar --append --verbose --file=collection.tar blues}
5257 blues
5258 @end smallexample
5260 @noindent
5261 Because you specified the @option{--verbose} option, @command{tar} has
5262 printed the name of the file being appended as it was acted on.  Now
5263 list the contents of the archive:
5265 @smallexample
5266 $ @kbd{tar --list --verbose --file=collection.tar}
5267 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5268 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5269 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5270 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5271 -rw-r--r-- me/user          58 1996-10-24 18:30 blues
5272 @end smallexample
5274 @noindent
5275 The newest version of @file{blues} is now at the end of the archive
5276 (note the different creation dates and file sizes).  If you extract
5277 the archive, the older version of the file @file{blues} will be
5278 replaced by the newer version.  You can confirm this by extracting
5279 the archive and running @samp{ls} on the directory.
5281 If you wish to extract the first occurrence of the file @file{blues}
5282 from the archive, use @option{--occurrence} option, as shown in
5283 the following example:
5285 @smallexample
5286 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
5287 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5288 @end smallexample
5290 @xref{Writing}, for more information on @option{--extract} and
5291 see @ref{Option Summary, --occurrence}, for a description of
5292 @option{--occurrence} option.
5294 @node update
5295 @subsection Updating an Archive
5296 @cindex Updating an archive
5297 @opindex update
5299 In the previous section, you learned how to use @option{--append} to
5300 add a file to an existing archive.  A related operation is
5301 @option{--update} (@option{-u}).  The @option{--update} operation
5302 updates a @command{tar} archive by comparing the date of the specified
5303 archive members against the date of the file with the same name.  If
5304 the file has been modified more recently than the archive member, then
5305 the newer version of the file is added to the archive (as with
5306 @option{--append}).
5308 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
5309 The operation will fail.
5311 @FIXME{other examples of media on which --update will fail?  need to ask
5312 charles and/or mib/thomas/dave shevett..}
5314 Both @option{--update} and @option{--append} work by adding to the end
5315 of the archive.  When you extract a file from the archive, only the
5316 version stored last will wind up in the file system, unless you use
5317 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
5319 @menu
5320 * how to update::
5321 @end menu
5323 @node how to update
5324 @subsubsection How to Update an Archive Using @option{--update}
5325 @opindex update
5327 You must use file name arguments with the @option{--update}
5328 (@option{-u}) operation.  If you don't specify any files,
5329 @command{tar} won't act on any files and won't tell you that it didn't
5330 do anything (which may end up confusing you).
5332 @c note: the above parenthetical added because in fact, this
5333 @c behavior just confused the author. :-)
5335 To see the @option{--update} option at work, create a new file,
5336 @file{classical}, in your practice directory, and some extra text to the
5337 file @file{blues}, using any text editor.  Then invoke @command{tar} with
5338 the @samp{update} operation and the @option{--verbose} (@option{-v})
5339 option specified, using the names of all the files in the @file{practice}
5340 directory as file name arguments:
5342 @smallexample
5343 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
5344 blues
5345 classical
5347 @end smallexample
5349 @noindent
5350 Because we have specified verbose mode, @command{tar} prints out the names
5351 of the files it is working on, which in this case are the names of the
5352 files that needed to be updated.  If you run @samp{tar --list} and look
5353 at the archive, you will see @file{blues} and @file{classical} at its
5354 end.  There will be a total of two versions of the member @samp{blues};
5355 the one at the end will be newer and larger, since you added text before
5356 updating it.
5358 The reason @command{tar} does not overwrite the older file when updating
5359 it is that writing to the middle of a section of tape is a difficult
5360 process.  Tapes are not designed to go backward.  @xref{Media}, for more
5361 information about tapes.
5363 @option{--update} (@option{-u}) is not suitable for performing backups for two
5364 reasons: it does not change directory content entries, and it
5365 lengthens the archive every time it is used.  The @GNUTAR{}
5366 options intended specifically for backups are more
5367 efficient.  If you need to run backups, please consult @ref{Backups}.
5369 @node concatenate
5370 @subsection Combining Archives with @option{--concatenate}
5372 @cindex Adding archives to an archive
5373 @cindex Concatenating Archives
5374 @opindex concatenate
5375 @opindex catenate
5376 @c @cindex @option{-A} described
5377 Sometimes it may be convenient to add a second archive onto the end of
5378 an archive rather than adding individual files to the archive.  To add
5379 one or more archives to the end of another archive, you should use the
5380 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
5382 To use @option{--concatenate}, give the first archive with
5383 @option{--file} option and name the rest of archives to be
5384 concatenated on the command line.  The members, and their member
5385 names, will be copied verbatim from those archives to the first
5386 one@footnote{This can cause multiple members to have the same name.  For
5387 information on how this affects reading the archive, see @ref{multiple}.}.
5388 The new, concatenated archive will be called by the same name as the
5389 one given with the @option{--file} option.  As usual, if you omit
5390 @option{--file}, @command{tar} will use the value of the environment
5391 variable @env{TAPE}, or, if this has not been set, the default archive name.
5393 @FIXME{There is no way to specify a new name...}
5395 To demonstrate how @option{--concatenate} works, create two small archives
5396 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
5397 files from @file{practice}:
5399 @smallexample
5400 $ @kbd{tar -cvf bluesrock.tar blues rock}
5401 blues
5402 rock
5403 $ @kbd{tar -cvf folkjazz.tar folk jazz}
5404 folk
5405 jazz
5406 @end smallexample
5408 @noindent
5409 If you like, you can run @samp{tar --list} to make sure the archives
5410 contain what they are supposed to:
5412 @smallexample
5413 $ @kbd{tar -tvf bluesrock.tar}
5414 -rw-r--r-- melissa/user    105 1997-01-21 19:42 blues
5415 -rw-r--r-- melissa/user     33 1997-01-20 15:34 rock
5416 $ @kbd{tar -tvf jazzfolk.tar}
5417 -rw-r--r-- melissa/user     20 1996-09-23 16:44 folk
5418 -rw-r--r-- melissa/user     65 1997-01-30 14:15 jazz
5419 @end smallexample
5421 We can concatenate these two archives with @command{tar}:
5423 @smallexample
5424 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
5425 @end smallexample
5427 If you now list the contents of the @file{bluesrock.tar}, you will see
5428 that now it also contains the archive members of @file{jazzfolk.tar}:
5430 @smallexample
5431 $ @kbd{tar --list --file=bluesrock.tar}
5432 blues
5433 rock
5434 folk
5435 jazz
5436 @end smallexample
5438 When you use @option{--concatenate}, the source and target archives must
5439 already exist and must have been created using compatible format
5440 parameters.  Notice, that @command{tar} does not check whether the
5441 archives it concatenates have compatible formats, it does not
5442 even check if the files are really tar archives.
5444 Like @option{--append} (@option{-r}), this operation cannot be performed on some
5445 tape drives, due to deficiencies in the formats those tape drives use.
5447 @cindex @code{concatenate} vs @command{cat}
5448 @cindex @command{cat} vs @code{concatenate}
5449 It may seem more intuitive to you to want or try to use @command{cat} to
5450 concatenate two archives instead of using the @option{--concatenate}
5451 operation; after all, @command{cat} is the utility for combining files.
5453 However, @command{tar} archives incorporate an end-of-file marker which
5454 must be removed if the concatenated archives are to be read properly as
5455 one archive.  @option{--concatenate} removes the end-of-archive marker
5456 from the target archive before each new archive is appended.  If you use
5457 @command{cat} to combine the archives, the result will not be a valid
5458 @command{tar} format archive.  If you need to retrieve files from an
5459 archive that was added to using the @command{cat} utility, use the
5460 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
5461 information on dealing with archives improperly combined using the
5462 @command{cat} shell utility.
5464 @node delete
5465 @subsection Removing Archive Members Using @option{--delete}
5466 @cindex Deleting files from an archive
5467 @cindex Removing files from an archive
5469 @opindex delete
5470 You can remove members from an archive by using the @option{--delete}
5471 option.  Specify the name of the archive with @option{--file}
5472 (@option{-f}) and then specify the names of the members to be deleted;
5473 if you list no member names, nothing will be deleted.  The
5474 @option{--verbose} option will cause @command{tar} to print the names
5475 of the members as they are deleted. As with @option{--extract}, you
5476 must give the exact member names when using @samp{tar --delete}.
5477 @option{--delete} will remove all versions of the named file from the
5478 archive.  The @option{--delete} operation can run very slowly.
5480 Unlike other operations, @option{--delete} has no short form.
5482 @cindex Tapes, using @option{--delete} and
5483 @cindex Deleting from tape archives
5484 This operation will rewrite the archive.  You can only use
5485 @option{--delete} on an archive if the archive device allows you to
5486 write to any point on the media, such as a disk; because of this, it
5487 does not work on magnetic tapes.  Do not try to delete an archive member
5488 from a magnetic tape; the action will not succeed, and you will be
5489 likely to scramble the archive and damage your tape.  There is no safe
5490 way (except by completely re-writing the archive) to delete files from
5491 most kinds of magnetic tape.  @xref{Media}.
5493 To delete all versions of the file @file{blues} from the archive
5494 @file{collection.tar} in the @file{practice} directory, make sure you
5495 are in that directory, and then,
5497 @smallexample
5498 $ @kbd{tar --list --file=collection.tar}
5499 blues
5500 folk
5501 jazz
5502 rock
5503 $ @kbd{tar --delete --file=collection.tar blues}
5504 $ @kbd{tar --list --file=collection.tar}
5505 folk
5506 jazz
5507 rock
5508 @end smallexample
5510 @FIXME{Check if the above listing is actually produced after running
5511 all the examples on collection.tar.}
5513 The @option{--delete} option has been reported to work properly when
5514 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
5516 @node compare
5517 @subsection Comparing Archive Members with the File System
5518 @cindex Verifying the currency of an archive
5520 @opindex compare
5521 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
5522 specified archive members against files with the same names, and then
5523 reports differences in file size, mode, owner, modification date and
5524 contents.  You should @emph{only} specify archive member names, not file
5525 names.  If you do not name any members, then @command{tar} will compare the
5526 entire archive.  If a file is represented in the archive but does not
5527 exist in the file system, @command{tar} reports a difference.
5529 You have to specify the record size of the archive when modifying an
5530 archive with a non-default record size.
5532 @command{tar} ignores files in the file system that do not have
5533 corresponding members in the archive.
5535 The following example compares the archive members @file{rock},
5536 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
5537 files of the same name in the file system.  (Note that there is no file,
5538 @file{funk}; @command{tar} will report an error message.)
5540 @smallexample
5541 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
5542 rock
5543 blues
5544 tar: funk not found in archive
5545 @end smallexample
5547 The spirit behind the @option{--compare} (@option{--diff},
5548 @option{-d}) option is to check whether the archive represents the
5549 current state of files on disk, more than validating the integrity of
5550 the archive media.  For this latter goal, see @ref{verify}.
5552 @node create options
5553 @section Options Used by @option{--create}
5555 @xopindex{create, additional options}
5556 The previous chapter described the basics of how to use
5557 @option{--create} (@option{-c}) to create an archive from a set of files.
5558 @xref{create}.  This section described advanced options to be used with
5559 @option{--create}.
5561 @menu
5562 * override::                  Overriding File Metadata.
5563 * Extended File Attributes::
5564 * Ignore Failed Read::
5565 @end menu
5567 @node override
5568 @subsection Overriding File Metadata
5570 As described above, a @command{tar} archive keeps, for each member it contains,
5571 its @dfn{metadata}, such as modification time, mode and ownership of
5572 the file.  @GNUTAR{} allows to replace these data with other values
5573 when adding files to the archive.  The options described in this
5574 section affect creation of archives of any type.  For POSIX archives,
5575 see also @ref{PAX keywords}, for additional ways of controlling
5576 metadata, stored in the archive.
5578 @table @option
5579 @opindex mode
5580 @item --mode=@var{permissions}
5582 When adding files to an archive, @command{tar} will use
5583 @var{permissions} for the archive members, rather than the permissions
5584 from the files.  @var{permissions} can be specified either as an octal
5585 number or as symbolic permissions, like with
5586 @command{chmod} (@xref{File permissions, Permissions, File
5587 permissions, coreutils, @acronym{GNU} core utilities}.  This reference
5588 also has useful information for those not being overly familiar with
5589 the UNIX permission system).  Using latter syntax allows for
5590 more flexibility.  For example, the value @samp{a+rw} adds read and write
5591 permissions for everybody, while retaining executable bits on directories
5592 or on any other file already marked as executable:
5594 @smallexample
5595 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5596 @end smallexample
5598 @item --mtime=@var{date}
5599 @opindex mtime
5601 When adding files to an archive, @command{tar} uses @var{date} as
5602 the modification time of members when creating archives, instead of
5603 their actual modification times.  The argument @var{date} can be
5604 either a textual date representation in almost arbitrary format
5605 (@pxref{Date input formats}) or a name of an existing file, starting
5606 with @samp{/} or @samp{.}.  In the latter case, the modification time
5607 of that file is used.
5609 The following example sets the modification date to 00:00:00 @sc{utc} on
5610 January 1, 1970:
5612 @smallexample
5613 $ @kbd{tar -c -f archive.tar --mtime='@@0' .}
5614 @end smallexample
5616 @noindent
5617 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5618 converts the specified date back to a textual form and compares it
5619 with the one given with @option{--mtime}.
5620 If the two forms differ, @command{tar} prints both forms in a message,
5621 to help the user check that the right date is being used.
5623 For example:
5625 @smallexample
5626 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5627 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5628 13:06:29.152478
5629 @dots{}
5630 @end smallexample
5632 @noindent
5633 When used with @option{--clamp-mtime} @GNUTAR{} sets the
5634 modification date to @var{date} only on files whose actual modification
5635 date is later than @var{date}.  This makes it easier to build
5636 reproducible archives given a common timestamp for generated files
5637 while still retaining the original timestamps of untouched files.
5638 @xref{Reproducibility}.
5640 @smallexample
5641 $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime="$SOURCE_EPOCH" .}
5642 @end smallexample
5644 @item --owner=@var{user}
5645 @opindex owner
5647 Specifies that @command{tar} should use @var{user} as the owner of members
5648 when creating archives, instead of the user associated with the source
5649 file.
5651 If @var{user} contains a colon, it is taken to be of the form
5652 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5653 name and a nonempty @var{id} specifies the decimal numeric user
5654 @acronym{ID}.  If @var{user} does not contain a colon, it is taken to
5655 be a user number if it is one or more decimal digits; otherwise it is
5656 taken to be a user name.
5658 If a name is given but no number, the number is inferred from the
5659 current host's user database if possible, and the file's user number
5660 is used otherwise.  If a number is given but no name, the name is
5661 inferred from the number if possible, and an empty name is used
5662 otherwise.  If both name and number are given, the user database is
5663 not consulted, and the name and number need not be valid on the
5664 current host.
5666 There is no value indicating a missing number, and @samp{0} usually means
5667 @code{root}.  Some people like to force @samp{0} as the value to offer in
5668 their distributions for the owner of files, because the @code{root} user is
5669 anonymous anyway, so that might as well be the owner of anonymous
5670 archives.  For example:
5672 @smallexample
5673 $ @kbd{tar -c -f archive.tar --owner=0 .}
5674 @end smallexample
5676 @noindent
5679 @smallexample
5680 $ @kbd{tar -c -f archive.tar --owner=root .}
5681 @end smallexample
5683 @item --group=@var{group}
5684 @opindex group
5686 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5687 rather than the group from the source file.  As with @option{--owner},
5688 the argument @var{group} can be an existing group symbolic name, or a
5689 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5690 @end table
5692 The @option{--owner} and @option{--group} options affect all files
5693 added to the archive.  @GNUTAR{} provides also two options that allow
5694 for more detailed control over owner translation:
5696 @table @option
5697 @item --owner-map=@var{file}
5698 Read UID translation map from @var{file}.
5700 When reading, empty lines are ignored.  The @samp{#} sign, unless
5701 quoted, introduces a comment, which extends to the end of the line.
5702 Each nonempty line defines mapping for a single UID.  It must consist
5703 of two fields separated by any amount of whitespace.  The first field
5704 defines original username and UID.  It can be a valid user name or
5705 a valid UID prefixed with a plus sign.  In both cases the
5706 corresponding UID or user name is inferred from the current host's
5707 user database.
5709 The second field defines the UID and username to map the original one
5710 to.  Its format can be the same as described above.  Otherwise, it can
5711 have the form @var{newname}:@var{newuid}, in which case neither
5712 @var{newname} nor @var{newuid} are required to be valid as per the
5713 user database.
5715 For example, consider the following file:
5717 @example
5718 +10     bin
5719 smith   root:0
5720 @end example
5722 @noindent
5723 Given this file, each input file that is owner by UID 10 will be
5724 stored in archive with owner name @samp{bin} and owner UID
5725 corresponding to @samp{bin}.  Each file owned by user @samp{smith}
5726 will be stored with owner name @samp{root} and owner ID 0.  Other
5727 files will remain unchanged.
5729 When used together with @option{--owner-map}, the @option{--owner}
5730 option affects only files whose owner is not listed in the map file.
5732 @item --group-map=@var{file}
5733 Read GID translation map from @var{file}.
5735 The format of @var{file} is the same as for @option{--owner-map}
5736 option:
5738 Each nonempty line defines mapping for a single GID.  It must consist
5739 of two fields separated by any amount of whitespace.  The first field
5740 defines original group name and GID.  It can be a valid group name or
5741 a valid GID prefixed with a plus sign.  In both cases the
5742 corresponding GID or user name is inferred from the current host's
5743 group database.
5745 The second field defines the GID and group name to map the original one
5746 to.  Its format can be the same as described above.  Otherwise, it can
5747 have the form @var{newname}:@var{newgid}, in which case neither
5748 @var{newname} nor @var{newgid} are required to be valid as per the
5749 group database.
5751 When used together with @option{--group-map}, the @option{--group}
5752 option affects only files whose owner group is not rewritten using the
5753 map file.
5754 @end table
5756 @node Extended File Attributes
5757 @subsection Extended File Attributes
5759 Extended file attributes are name-value pairs that can be
5760 associated with each node in a file system.  Despite the fact that
5761 POSIX.1e draft which proposed them has been withdrawn, the extended
5762 file attributes are supported by many file systems.  @GNUTAR{} can
5763 store extended file attributes along with the files.  This feature is
5764 controlled by the following command line arguments:
5766 @table @option
5767 @item --xattrs
5768 Enable extended attributes support.  When used with @option{--create},
5769 this option instructs @GNUTAR{} to store extended file attribute in the
5770 created archive.  This implies POSIX.1-2001 archive format
5771 (@option{--format=pax}).
5773 When used with @option{--extract}, this option tells @command{tar},
5774 for each file extracted, to read stored attributes from the archive
5775 and to apply them to the file.
5777 @item --no-xattrs
5778 Disable extended attributes support.  This is the default.
5779 @end table
5781 Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
5782 Currently, four namespaces exist: @samp{user}, @samp{trusted},
5783 @samp{security} and @samp{system}.  By default, when @option{--xattrs}
5784 is used, all names are stored in the archive (with @option{--create}),
5785 but only @samp{user} namespace is extracted (if using @option{--extract}).
5786 The reason for this behavior is that any other, system defined attributes
5787 don't provide us sufficient compatibility promise.  Storing all attributes
5788 is safe operation for the archiving purposes.  Though extracting those
5789 (often security related) attributes on a different system than originally
5790 archived can lead to extraction failures, or even misinterpretations.
5791 This behavior can be controlled using the following options:
5793 @table @option
5794 @item --xattrs-exclude=@var{pattern}
5795 Specify exclude pattern for extended attributes.
5797 @item --xattrs-include=@var{pattern}
5798 Specify include pattern for extended attributes.
5799 @end table
5801 Here, the @var{pattern} is a globbing pattern.  For example, the
5802 following command:
5804 @example
5805 $ @kbd{tar --xattrs --xattrs-exclude='user.*' -cf a.tar .}
5806 @end example
5808 will include in the archive @file{a.tar} all attributes, except those
5809 from the @samp{user} namespace.
5811 Users shall check the attributes are binary compatible with the target system
5812 before any other namespace is extracted with an explicit
5813 @option{--xattrs-include} option.
5815 Any number of these options can be given, thereby creating lists of
5816 include and exclude patterns.
5818 When both options are used, first @option{--xattrs-include} is applied
5819 to select the set of attribute names to keep, and then
5820 @option{--xattrs-exclude} is applied to the resulting set.  In other
5821 words, only those attributes will be stored, whose names match one
5822 of the regexps in @option{--xattrs-include} and don't match any of
5823 the regexps from @option{--xattrs-exclude}.
5825 When listing the archive, if both @option{--xattrs} and
5826 @option{--verbose} options are given, files that have extended
5827 attributes are marked with an asterisk following their permission
5828 mask.  For example:
5830 @example
5831 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5832 @end example
5834 When two or more @option{--verbose} options are given, a detailed
5835 listing of extended attributes is printed after each file entry.  Each
5836 attribute is listed on a separate line, which begins with two spaces
5837 and the letter @samp{x} indicating extended attribute.  It is followed
5838 by a colon, length of the attribute and its name, e.g.:
5840 @example
5841 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5842   x:  7 user.mime_type
5843   x: 32 trusted.md5sum
5844 @end example
5846 File access control lists (@dfn{ACL}) are another actively used feature
5847 proposed by the POSIX.1e standard.  Each ACL consists of a set of ACL
5848 entries, each of which describes the access permissions on the file for
5849 an individual user or a group of users as a combination of read, write
5850 and search/execute permissions.
5852 Whether or not to use ACLs is controlled by the following two options:
5854 @table @option
5855 @item --acls
5856 Enable POSIX ACLs support.  When used with @option{--create},
5857 this option instructs @GNUTAR{} to store ACLs in the
5858 created archive.  This implies POSIX.1-2001 archive format
5859 (@option{--format=pax}).
5861 When used with @option{--extract}, this option tells @command{tar},
5862 to restore ACLs for each file extracted (provided they are present
5863 in the archive).
5865 @item --no-acls
5866 Disable POSIX ACLs support.  This is the default.
5867 @end table
5869 When listing the archive, if both @option{--acls} and
5870 @option{--verbose} options are given, files that have ACLs are marked
5871 with a plus sign following their permission mask.  For example:
5873 @example
5874 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5875 @end example
5877 When two or more @option{--verbose} options are given, a detailed
5878 listing of ACL is printed after each file entry:
5880 @example
5881 @group
5882 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5883   a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
5884 @end group
5885 @end example
5887 @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
5888 kernel security module that provides a mechanism for supporting access
5889 control security policies, including so-called mandatory access
5890 controls (@dfn{MAC}).  Support for SELinux attributes is controlled by
5891 the following command line options:
5893 @table @option
5894 @item --selinux
5895 Enable the SELinux context support.
5897 @item --no-selinux
5898 Disable SELinux context support.
5899 @end table
5901 @node Ignore Failed Read
5902 @subsection Ignore Failed Read
5904 @table @option
5905 @item --ignore-failed-read
5906 @opindex ignore-failed-read
5907 Do not exit with nonzero if there are mild problems while reading.
5908 @end table
5910 This option has effect only during creation.  It instructs tar to
5911 treat as mild conditions any missing or unreadable files (directories),
5912 or files that change while reading.
5913 Such failures don't affect the program exit code, and the
5914 corresponding diagnostic messages are marked as warnings, not errors.
5915 These warnings can be suppressed using the
5916 @option{--warning=failed-read} option (@pxref{warnings}).
5918 @node extract options
5919 @section Options Used by @option{--extract}
5920 @cindex options for use with @option{--extract}
5922 @xopindex{extract, additional options}
5923 The previous chapter showed how to use @option{--extract} to extract
5924 an archive into the file system.  Various options cause @command{tar} to
5925 extract more information than just file contents, such as the owner,
5926 the permissions, the modification date, and so forth.  This section
5927 presents options to be used with @option{--extract} when certain special
5928 considerations arise.  You may review the information presented in
5929 @ref{extract} for more basic information about the
5930 @option{--extract} operation.
5932 @menu
5933 * Reading::                     Options to Help Read Archives
5934 * Writing::                     Changing How @command{tar} Writes Files
5935 * Scarce::                      Coping with Scarce Resources
5936 @end menu
5938 @node Reading
5939 @subsection Options to Help Read Archives
5940 @cindex Options when reading archives
5942 @cindex Reading incomplete records
5943 @cindex Records, incomplete
5944 @opindex read-full-records
5945 Normally, @command{tar} will request data in full record increments from
5946 an archive storage device.  If the device cannot return a full record,
5947 @command{tar} will report an error.  However, some devices do not always
5948 return full records, or do not require the last record of an archive to
5949 be padded out to the next record boundary.  To keep reading until you
5950 obtain a full record, or to accept an incomplete record if it contains
5951 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5952 in conjunction with the @option{--extract} or @option{--list} operations.
5953 @xref{Blocking}.
5955 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5956 @command{tar} reads an archive from standard input, or from a remote
5957 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5958 pipe returns however much happens to be in the pipe, even if it is
5959 less than was requested.  If this option were not enabled, @command{tar}
5960 would fail as soon as it read an incomplete record from the pipe.
5962 If you're not sure of the blocking factor of an archive, you can
5963 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5964 @option{--blocking-factor=@var{512-size}} (@option{-b
5965 @var{512-size}}), using a blocking factor larger than what the archive
5966 uses.  This lets you avoid having to determine the blocking factor
5967 of an archive.  @xref{Blocking Factor}.
5969 @menu
5970 * read full records::
5971 * Ignore Zeros::
5972 @end menu
5974 @node read full records
5975 @unnumberedsubsubsec Reading Full Records
5977 @FIXME{need sentence or so of intro here}
5979 @table @option
5980 @opindex read-full-records
5981 @item --read-full-records
5982 @item -B
5983 Use in conjunction with @option{--extract} (@option{--get},
5984 @option{-x}) to read an archive which contains incomplete records, or
5985 one which has a blocking factor less than the one specified.
5986 @end table
5988 @node Ignore Zeros
5989 @unnumberedsubsubsec Ignoring Blocks of Zeros
5991 @cindex End-of-archive blocks, ignoring
5992 @cindex Ignoring end-of-archive blocks
5993 @opindex ignore-zeros
5994 Normally, @command{tar} stops reading when it encounters a block of zeros
5995 between file entries (which usually indicates the end of the archive).
5996 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5997 completely read an archive which contains a block of zeros before the
5998 end (i.e., a damaged archive, or one that was created by concatenating
5999 several archives together).  This option also suppresses warnings
6000 about missing or incomplete zero blocks at the end of the archive.
6001 This can be turned on, if the need be, using the
6002 @option{--warning=alone-zero-block --warning=missing-zero-blocks}
6003 options (@pxref{warnings}).
6005 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
6006 versions of @command{tar} write garbage after the end-of-archive entry,
6007 since that part of the media is never supposed to be read.  @GNUTAR{}
6008 does not write after the end of an archive, but seeks to
6009 maintain compatibility among archiving utilities.
6011 @table @option
6012 @item --ignore-zeros
6013 @itemx -i
6014 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
6015 encountered while reading an archive.  Use in conjunction with
6016 @option{--extract} or @option{--list}.
6017 @end table
6019 @node Writing
6020 @subsection Changing How @command{tar} Writes Files
6021 @UNREVISED{}
6023 @FIXME{Introductory paragraph}
6025 @menu
6026 * Dealing with Old Files::
6027 * Overwrite Old Files::
6028 * Keep Old Files::
6029 * Keep Newer Files::
6030 * Unlink First::
6031 * Recursive Unlink::
6032 * Data Modification Times::
6033 * Setting Access Permissions::
6034 * Directory Modification Times and Permissions::
6035 * Writing to Standard Output::
6036 * Writing to an External Program::
6037 * remove files::
6038 @end menu
6040 @node Dealing with Old Files
6041 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
6043 @xopindex{overwrite-dir, introduced}
6044 When extracting files, if @command{tar} discovers that the extracted
6045 file already exists, it normally replaces the file by removing it before
6046 extracting it, to prevent confusion in the presence of hard or symbolic
6047 links.  (If the existing file is a symbolic link, it is removed, not
6048 followed.)  However, if a directory cannot be removed because it is
6049 nonempty, @command{tar} normally overwrites its metadata (ownership,
6050 permission, etc.).  The @option{--overwrite-dir} option enables this
6051 default behavior.  To be more cautious and preserve the metadata of
6052 such a directory, use the @option{--no-overwrite-dir} option.
6054 @cindex Overwriting old files, prevention
6055 @xopindex{keep-old-files, introduced}
6056 To be even more cautious and prevent existing files from being replaced, use
6057 the @option{--keep-old-files} (@option{-k}) option.  It causes
6058 @command{tar} to refuse to replace or update a file that already
6059 exists, i.e., a file with the same name as an archive member prevents
6060 extraction of that archive member.  Instead, it reports an error.  For
6061 example:
6063 @example
6064 $ @kbd{ls}
6065 blues
6066 $ @kbd{tar -x -k -f archive.tar}
6067 tar: blues: Cannot open: File exists
6068 tar: Exiting with failure status due to previous errors
6069 @end example
6071 @xopindex{skip-old-files, introduced}
6072 If you wish to preserve old files untouched, but don't want
6073 @command{tar} to treat them as errors, use the
6074 @option{--skip-old-files} option.  This option causes @command{tar} to
6075 silently skip extracting over existing files.
6077 @xopindex{overwrite, introduced}
6078 To be more aggressive about altering existing files, use the
6079 @option{--overwrite} option.  It causes @command{tar} to overwrite
6080 existing files and to follow existing symbolic links when extracting.
6082 @cindex Protecting old files
6083 Some people argue that @GNUTAR{} should not hesitate
6084 to overwrite files with other files when extracting.  When extracting
6085 a @command{tar} archive, they expect to see a faithful copy of the
6086 state of the file system when the archive was created.  It is debatable
6087 that this would always be a proper behavior.  For example, suppose one
6088 has an archive in which @file{usr/local} is a link to
6089 @file{usr/local2}.  Since then, maybe the site removed the link and
6090 renamed the whole hierarchy from @file{/usr/local2} to
6091 @file{/usr/local}.  Such things happen all the time.  I guess it would
6092 not be welcome at all that @GNUTAR{} removes the
6093 whole hierarchy just to make room for the link to be reinstated
6094 (unless it @emph{also} simultaneously restores the full
6095 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
6096 able to remove a whole hierarchy to reestablish a symbolic link, for
6097 example, but @emph{only if} @option{--recursive-unlink} is specified
6098 to allow this behavior.  In any case, single files are silently
6099 removed.
6101 @xopindex{unlink-first, introduced}
6102 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
6103 some cases by causing @command{tar} to remove files unconditionally
6104 before extracting them.
6106 @node Overwrite Old Files
6107 @unnumberedsubsubsec Overwrite Old Files
6109 @table @option
6110 @opindex overwrite
6111 @item --overwrite
6112 Overwrite existing files and directory metadata when extracting files
6113 from an archive.
6115 This causes @command{tar} to write extracted files into the file system without
6116 regard to the files already on the system; i.e., files with the same
6117 names as archive members are overwritten when the archive is extracted.
6118 It also causes @command{tar} to extract the ownership, permissions,
6119 and time stamps onto any preexisting files or directories.
6120 If the name of a corresponding file name is a symbolic link, the file
6121 pointed to by the symbolic link will be overwritten instead of the
6122 symbolic link itself (if this is possible).  Moreover, special devices,
6123 empty directories and even symbolic links are automatically removed if
6124 they are in the way of extraction.
6126 Be careful when using the @option{--overwrite} option, particularly when
6127 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
6128 can change the contents, ownership or permissions of any file on your
6129 system.  Also, many systems do not take kindly to overwriting files that
6130 are currently being executed.
6132 @opindex overwrite-dir
6133 @item --overwrite-dir
6134 Overwrite the metadata of directories when extracting files from an
6135 archive, but remove other files before extracting.
6136 @end table
6138 @node Keep Old Files
6139 @unnumberedsubsubsec Keep Old Files
6141 @GNUTAR{} provides two options to control its actions in a situation
6142 when it is about to extract a file which already exists on disk.
6144 @table @option
6145 @opindex keep-old-files
6146 @item --keep-old-files
6147 @itemx -k
6148 Do not replace existing files from archive.  When such a file is
6149 encountered, @command{tar} issues an error message.  Upon end of
6150 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
6152 @item --skip-old-files
6153 Do not replace existing files from archive, but do not treat that
6154 as error.  Such files are silently skipped and do not affect
6155 @command{tar} exit status.
6157 Additional verbosity can be obtained using @option{--warning=existing-file}
6158 together with that option (@pxref{warnings}).
6159 @end table
6161 @node Keep Newer Files
6162 @unnumberedsubsubsec Keep Newer Files
6164 @table @option
6165 @opindex keep-newer-files
6166 @item --keep-newer-files
6167 Do not replace existing files that are newer than their archive
6168 copies.  This option is meaningless with @option{--list} (@option{-t}).
6169 @end table
6171 @node Unlink First
6172 @unnumberedsubsubsec Unlink First
6174 @table @option
6175 @opindex unlink-first
6176 @item --unlink-first
6177 @itemx -U
6178 Remove files before extracting over them.
6179 This can make @command{tar} run a bit faster if you know in advance
6180 that the extracted files all need to be removed.  Normally this option
6181 slows @command{tar} down slightly, so it is disabled by default.
6182 @end table
6184 @node Recursive Unlink
6185 @unnumberedsubsubsec Recursive Unlink
6187 @table @option
6188 @opindex recursive-unlink
6189 @item --recursive-unlink
6190 When this option is specified, try removing files and directory hierarchies
6191 before extracting over them.  @emph{This is a dangerous option!}
6192 @end table
6194 If you specify the @option{--recursive-unlink} option,
6195 @command{tar} removes @emph{anything} that keeps you from extracting a file
6196 as far as current permissions will allow it.  This could include removal
6197 of the contents of a full directory hierarchy.
6199 @node Data Modification Times
6200 @unnumberedsubsubsec Setting Data Modification Times
6202 @cindex Data modification times of extracted files
6203 @cindex Modification times of extracted files
6204 Normally, @command{tar} sets the data modification times of extracted
6205 files to the corresponding times recorded for the files in the archive, but
6206 limits the permissions of extracted files by the current @code{umask}
6207 setting.
6209 To set the data modification times of extracted files to the time when
6210 the files were extracted, use the @option{--touch} (@option{-m}) option in
6211 conjunction with @option{--extract} (@option{--get}, @option{-x}).
6213 @table @option
6214 @opindex touch
6215 @item --touch
6216 @itemx -m
6217 Sets the data modification time of extracted archive members to the time
6218 they were extracted, not the time recorded for them in the archive.
6219 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
6220 @end table
6222 @node Setting Access Permissions
6223 @unnumberedsubsubsec Setting Access Permissions
6225 @cindex Permissions of extracted files
6226 @cindex Modes of extracted files
6227 To set the modes (access permissions) of extracted files to those
6228 recorded for those files in the archive, use @option{--same-permissions}
6229 in conjunction with the @option{--extract} (@option{--get},
6230 @option{-x}) operation.
6232 @table @option
6233 @opindex preserve-permissions
6234 @opindex same-permissions
6235 @item --preserve-permissions
6236 @itemx --same-permissions
6237 @c @itemx --ignore-umask
6238 @itemx -p
6239 Set modes of extracted archive members to those recorded in the
6240 archive, instead of current umask settings.  Use in conjunction with
6241 @option{--extract} (@option{--get}, @option{-x}).
6242 @end table
6244 @node Directory Modification Times and Permissions
6245 @unnumberedsubsubsec Directory Modification Times and Permissions
6247 After successfully extracting a file member, @GNUTAR{} normally
6248 restores its permissions and modification times, as described in the
6249 previous sections.  This cannot be done for directories, because
6250 after extracting a directory @command{tar} will almost certainly
6251 extract files into that directory and this will cause the directory
6252 modification time to be updated.  Moreover, restoring that directory
6253 permissions may not permit file creation within it.  Thus, restoring
6254 directory permissions and modification times must be delayed at least
6255 until all files have been extracted into that directory.  @GNUTAR{}
6256 restores directories using the following approach.
6258 The extracted directories are created with the mode specified in the
6259 archive, as modified by the umask of the user, which gives sufficient
6260 permissions to allow file creation.  The meta-information about the
6261 directory is recorded in the temporary list of directories.  When
6262 preparing to extract next archive member, @GNUTAR{} checks if the
6263 directory prefix of this file contains the remembered directory.  If
6264 it does not, the program assumes that all files have been extracted
6265 into that directory, restores its modification time and permissions
6266 and removes its entry from the internal list.  This approach allows
6267 to correctly restore directory meta-information in the majority of
6268 cases, while keeping memory requirements sufficiently small.  It is
6269 based on the fact, that most @command{tar} archives use the predefined
6270 order of members: first the directory, then all the files and
6271 subdirectories in that directory.
6273 However, this is not always true.  The most important exception are
6274 incremental archives (@pxref{Incremental Dumps}).  The member order in
6275 an incremental archive is reversed: first all directory members are
6276 stored, followed by other (non-directory) members.  So, when extracting
6277 from incremental archives, @GNUTAR{} alters the above procedure.  It
6278 remembers all restored directories, and restores their meta-data
6279 only after the entire archive has been processed.  Notice, that you do
6280 not need to specify any special options for that, as @GNUTAR{}
6281 automatically detects archives in incremental format.
6283 There may be cases, when such processing is required for normal archives
6284 too.  Consider the following example:
6286 @smallexample
6287 @group
6288 $ @kbd{tar --no-recursion -cvf archive \
6289     foo foo/file1 bar bar/file foo/file2}
6290 foo/
6291 foo/file1
6292 bar/
6293 bar/file
6294 foo/file2
6295 @end group
6296 @end smallexample
6298 During the normal operation, after encountering @file{bar}
6299 @GNUTAR{} will assume that all files from the directory @file{foo}
6300 were already extracted and will therefore restore its timestamp and
6301 permission bits.  However, after extracting @file{foo/file2} the
6302 directory timestamp will be offset again.
6304 To correctly restore directory meta-information in such cases, use
6305 the @option{--delay-directory-restore} command line option:
6307 @table @option
6308 @opindex delay-directory-restore
6309 @item --delay-directory-restore
6310 Delays restoring of the modification times and permissions of extracted
6311 directories until the end of extraction.  This way, correct
6312 meta-information is restored even if the archive has unusual member
6313 ordering.
6315 @opindex no-delay-directory-restore
6316 @item --no-delay-directory-restore
6317 Cancel the effect of the previous @option{--delay-directory-restore}.
6318 Use this option if you have used @option{--delay-directory-restore} in
6319 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
6320 temporarily disable it.
6321 @end table
6323 @node Writing to Standard Output
6324 @unnumberedsubsubsec Writing to Standard Output
6326 @cindex Writing extracted files to standard output
6327 @cindex Standard output, writing extracted files to
6328 To write the extracted files to the standard output, instead of
6329 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
6330 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
6331 extracting files to send them through a pipe, and do not need to
6332 preserve them in the file system.  If you extract multiple members,
6333 they appear on standard output concatenated, in the order they are
6334 found in the archive.
6336 @table @option
6337 @opindex to-stdout
6338 @item --to-stdout
6339 @itemx -O
6340 Writes files to the standard output.  Use only in conjunction with
6341 @option{--extract} (@option{--get}, @option{-x}).  When this option is
6342 used, instead of creating the files specified, @command{tar} writes
6343 the contents of the files extracted to its standard output.  This may
6344 be useful if you are only extracting the files in order to send them
6345 through a pipe.  This option is meaningless with @option{--list}
6346 (@option{-t}).
6347 @end table
6349 This can be useful, for example, if you have a tar archive containing
6350 a big file and don't want to store the file on disk before processing
6351 it.  You can use a command like this:
6353 @smallexample
6354 tar -xOzf foo.tgz bigfile | process
6355 @end smallexample
6357 or even like this if you want to process the concatenation of the files:
6359 @smallexample
6360 tar -xOzf foo.tgz bigfile1 bigfile2 | process
6361 @end smallexample
6363 However, @option{--to-command} may be more convenient for use with
6364 multiple files. See the next section.
6366 @node Writing to an External Program
6367 @unnumberedsubsubsec Writing to an External Program
6369 You can instruct @command{tar} to send the contents of each extracted
6370 file to the standard input of an external program:
6372 @table @option
6373 @opindex to-command
6374 @item --to-command=@var{command}
6375 Extract files and pipe their contents to the standard input of
6376 @var{command}.  When this option is used, instead of creating the
6377 files specified, @command{tar} invokes @var{command} and pipes the
6378 contents of the files to its standard output.  The @var{command} may
6379 contain command line arguments (see @ref{external, Running External Commands},
6380 for more detail).
6382 Notice, that @var{command} is executed once for each regular file
6383 extracted.  Non-regular files (directories, etc.)@: are ignored when this
6384 option is used.
6385 @end table
6387 The command can obtain the information about the file it processes
6388 from the following environment variables:
6390 @table @env
6391 @vrindex TAR_FILETYPE, to-command environment
6392 @item TAR_FILETYPE
6393 Type of the file. It is a single letter with the following meaning:
6395 @multitable @columnfractions 0.10 0.90
6396 @item f @tab Regular file
6397 @item d @tab Directory
6398 @item l @tab Symbolic link
6399 @item h @tab Hard link
6400 @item b @tab Block device
6401 @item c @tab Character device
6402 @end multitable
6404 Currently only regular files are supported.
6406 @vrindex TAR_MODE, to-command environment
6407 @item TAR_MODE
6408 File mode, an octal number.
6410 @vrindex TAR_FILENAME, to-command environment
6411 @item TAR_FILENAME
6412 The name of the file.
6414 @vrindex TAR_REALNAME, to-command environment
6415 @item TAR_REALNAME
6416 Name of the file as stored in the archive.
6418 @vrindex TAR_UNAME, to-command environment
6419 @item TAR_UNAME
6420 Name of the file owner.
6422 @vrindex TAR_GNAME, to-command environment
6423 @item TAR_GNAME
6424 Name of the file owner group.
6426 @vrindex TAR_ATIME, to-command environment
6427 @item TAR_ATIME
6428 Time of last access. It is a decimal number, representing seconds
6429 since the Epoch.  If the archive provides times with nanosecond
6430 precision, the nanoseconds are appended to the timestamp after a
6431 decimal point.
6433 @vrindex TAR_MTIME, to-command environment
6434 @item TAR_MTIME
6435 Time of last modification.
6437 @vrindex TAR_CTIME, to-command environment
6438 @item TAR_CTIME
6439 Time of last status change.
6441 @vrindex TAR_SIZE, to-command environment
6442 @item TAR_SIZE
6443 Size of the file.
6445 @vrindex TAR_UID, to-command environment
6446 @item TAR_UID
6447 UID of the file owner.
6449 @vrindex TAR_GID, to-command environment
6450 @item TAR_GID
6451 GID of the file owner.
6452 @end table
6454 Additionally, the following variables contain information about
6455 tar mode and the archive being processed:
6457 @table @env
6458 @vrindex TAR_VERSION, to-command environment
6459 @item TAR_VERSION
6460 @GNUTAR{} version number.
6462 @vrindex TAR_ARCHIVE, to-command environment
6463 @item TAR_ARCHIVE
6464 The name of the archive @command{tar} is processing.
6466 @vrindex TAR_BLOCKING_FACTOR, to-command environment
6467 @item TAR_BLOCKING_FACTOR
6468 Current blocking factor (@pxref{Blocking}).
6470 @vrindex TAR_VOLUME, to-command environment
6471 @item TAR_VOLUME
6472 Ordinal number of the volume @command{tar} is processing.
6474 @vrindex TAR_FORMAT, to-command environment
6475 @item TAR_FORMAT
6476 Format of the archive being processed. @xref{Formats}, for a complete
6477 list of archive format names.
6478 @end table
6480 These variables are defined prior to executing the command, so you can
6481 pass them as arguments, if you prefer.  For example, if the command
6482 @var{proc} takes the member name and size as its arguments, then you
6483 could do:
6485 @smallexample
6486 $ @kbd{tar -x -f archive.tar \
6487        --to-command='proc $TAR_FILENAME $TAR_SIZE'}
6488 @end smallexample
6490 @noindent
6491 Notice single quotes to prevent variable names from being expanded by
6492 the shell when invoking @command{tar}.
6494 If @var{command} exits with a non-0 status, @command{tar} will print
6495 an error message similar to the following:
6497 @smallexample
6498 tar: 2345: Child returned status 1
6499 @end smallexample
6501 Here, @samp{2345} is the PID of the finished process.
6503 If this behavior is not wanted, use @option{--ignore-command-error}:
6505 @table @option
6506 @opindex ignore-command-error
6507 @item --ignore-command-error
6508 Ignore exit codes of subprocesses.  Notice that if the program
6509 exits on signal or otherwise terminates abnormally, the error message
6510 will be printed even if this option is used.
6512 @opindex no-ignore-command-error
6513 @item --no-ignore-command-error
6514 Cancel the effect of any previous @option{--ignore-command-error}
6515 option. This option is useful if you have set
6516 @option{--ignore-command-error} in @env{TAR_OPTIONS}
6517 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
6518 @end table
6520 @node remove files
6521 @unnumberedsubsubsec Removing Files
6523 @FIXME{The section is too terse. Something more to add? An example,
6524 maybe?}
6526 @table @option
6527 @opindex remove-files
6528 @item --remove-files
6529 Remove files after adding them to the archive.
6530 @end table
6532 @node Scarce
6533 @subsection Coping with Scarce Resources
6534 @UNREVISED{}
6536 @cindex Small memory
6537 @cindex Running out of space
6539 @menu
6540 * Starting File::
6541 * Same Order::
6542 @end menu
6544 @node Starting File
6545 @unnumberedsubsubsec Starting File
6547 @table @option
6548 @opindex starting-file
6549 @item --starting-file=@var{name}
6550 @itemx -K @var{name}
6551 Starts an operation in the middle of an archive.  Use in conjunction
6552 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
6553 @end table
6555 @cindex Middle of the archive, starting in the
6556 If a previous attempt to extract files failed due to lack of disk
6557 space, you can use @option{--starting-file=@var{name}} (@option{-K
6558 @var{name}}) to start extracting only after member @var{name} of the
6559 archive.  This assumes, of course, that there is now free space, or
6560 that you are now extracting into a different file system.  (You could
6561 also choose to suspend @command{tar}, remove unnecessary files from
6562 the file system, and then resume the same @command{tar} operation.
6563 In this case, @option{--starting-file} is not necessary.)  See also
6564 @ref{interactive}, and @ref{exclude}.
6566 @node Same Order
6567 @unnumberedsubsubsec Same Order
6569 @table @option
6570 @cindex Large lists of file names on small machines
6571 @opindex same-order
6572 @opindex preserve-order
6573 @item --same-order
6574 @itemx --preserve-order
6575 @itemx -s
6576 To process large lists of file names on machines with small amounts of
6577 memory.  Use in conjunction with @option{--compare} (@option{--diff},
6578 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
6579 (@option{--get}, @option{-x}).
6580 @end table
6582 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
6583 names to be listed or extracted is sorted in the same order as the
6584 files in the archive.  This allows a large list of names to be used,
6585 even on a small machine that would not otherwise be able to hold all
6586 the names in memory at the same time.  Such a sorted list can easily be
6587 created by running @samp{tar -t} on the archive and editing its output.
6589 This option is probably never needed on modern computer systems.
6591 @node backup
6592 @section Backup options
6594 @cindex backup options
6596 @GNUTAR{} offers options for making backups of files
6597 before writing new versions.  These options control the details of
6598 these backups.  They may apply to the archive itself before it is
6599 created or rewritten, as well as individual extracted members.  Other
6600 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
6601 and @command{mv}, for example) offer similar options.
6603 Backup options may prove unexpectedly useful when extracting archives
6604 containing many members having identical name, or when extracting archives
6605 on systems having file name limitations, making different members appear
6606 as having similar names through the side-effect of name truncation.
6607 @FIXME{This is true only if we have a good scheme for truncated backup names,
6608 which I'm not sure at all: I suspect work is needed in this area.}
6609 When any existing file is backed up before being overwritten by extraction,
6610 then clashing files are automatically be renamed to be unique, and the
6611 true name is kept for only the last file of a series of clashing files.
6612 By using verbose mode, users may track exactly what happens.
6614 At the detail level, some decisions are still experimental, and may
6615 change in the future, we are waiting comments from our users.  So, please
6616 do not learn to depend blindly on the details of the backup features.
6617 For example, currently, directories themselves are never renamed through
6618 using these options, so, extracting a file over a directory still has
6619 good chances to fail.  Also, backup options apply to created archives,
6620 not only to extracted members.  For created archives, backups will not
6621 be attempted when the archive is a block or character device, or when it
6622 refers to a remote file.
6624 For the sake of simplicity and efficiency, backups are made by renaming old
6625 files prior to creation or extraction, and not by copying.  The original
6626 name is restored if the file creation fails.  If a failure occurs after a
6627 partial extraction of a file, both the backup and the partially extracted
6628 file are kept.
6630 @table @samp
6631 @item --backup[=@var{method}]
6632 @opindex backup
6633 @vindex VERSION_CONTROL
6634 @cindex backups
6635 Back up files that are about to be overwritten or removed.
6636 Without this option, the original versions are destroyed.
6638 Use @var{method} to determine the type of backups made.
6639 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
6640 environment variable.  And if @env{VERSION_CONTROL} is not set,
6641 use the @samp{existing} method.
6643 @vindex version-control @r{Emacs variable}
6644 This option corresponds to the Emacs variable @samp{version-control};
6645 the same values for @var{method} are accepted as in Emacs.  This option
6646 also allows more descriptive names.  The valid @var{method}s are:
6648 @table @samp
6649 @item t
6650 @itemx numbered
6651 @cindex numbered @r{backup method}
6652 Always make numbered backups.
6654 @item nil
6655 @itemx existing
6656 @cindex existing @r{backup method}
6657 Make numbered backups of files that already have them, simple backups
6658 of the others.
6660 @item never
6661 @itemx simple
6662 @cindex simple @r{backup method}
6663 Always make simple backups.
6665 @end table
6667 @item --suffix=@var{suffix}
6668 @opindex suffix
6669 @cindex backup suffix
6670 @vindex SIMPLE_BACKUP_SUFFIX
6671 Append @var{suffix} to each backup file made with @option{--backup}.  If this
6672 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
6673 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
6674 set, the default is @samp{~}, just as in Emacs.
6676 @end table
6678 @node looking ahead
6679 @section Looking Ahead: The Rest of this Manual
6681 You have now seen how to use all eight of the operations available to
6682 @command{tar}, and a number of the possible options.  The next chapter
6683 explains how to choose and change file and archive names, how to use
6684 files to store names of other files which you can then call as
6685 arguments to @command{tar} (this can help you save time if you expect to
6686 archive the same list of files a number of times), and so forth.
6687 @FIXME{in case it's not obvious, i'm making this up in some sense
6688 based on my limited memory of what the next chapter *really* does.  i
6689 just wanted to flesh out this final section a little bit so i'd
6690 remember to stick it in here. :-)}
6692 If there are too many files to conveniently list on the command line,
6693 you can list the names in a file, and @command{tar} will read that file.
6694 @xref{files}.
6696 There are various ways of causing @command{tar} to skip over some files,
6697 and not archive them.  @xref{Choosing}.
6699 @node Backups
6700 @chapter Performing Backups and Restoring Files
6701 @cindex backups
6703 @GNUTAR{} is distributed along with the scripts for performing backups
6704 and restores.  Even if there is a good chance those scripts may be
6705 satisfying to you, they are not the only scripts or methods available for doing
6706 backups and restore.  You may well create your own, or use more
6707 sophisticated packages dedicated to that purpose.
6709 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
6710 Automatic Network Disk Archiver), a backup system developed by James
6711 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
6712 This is free software, and it is available from @uref{http://www.amanda.org}.
6714 @FIXME{
6716 Here is a possible plan for a future documentation about the backuping
6717 scripts which are provided within the @GNUTAR{}
6718 distribution.
6720 @itemize @bullet
6721 @item dumps
6722  @itemize @minus
6723  @item what are dumps
6724  @item different levels of dumps
6725   @itemize +
6726   @item full dump = dump everything
6727   @item level 1, level 2 dumps etc
6728         A level @var{n} dump dumps everything changed since the last level
6729         @var{n}-1 dump (?)
6730   @end itemize
6731  @item how to use scripts for dumps  (ie, the concept)
6732   @itemize +
6733   @item scripts to run after editing backup specs (details)
6734   @end itemize
6735  @item Backup Specs, what is it.
6736   @itemize +
6737   @item how to customize
6738   @item actual text of script  [/sp/dump/backup-specs]
6739   @end itemize
6740  @item Problems
6741   @itemize +
6742    @item rsh doesn't work
6743    @item rtape isn't installed
6744    @item (others?)
6745   @end itemize
6746  @item the @option{--incremental} option of tar
6747  @item tapes
6748   @itemize +
6749   @item write protection
6750   @item types of media, different sizes and types, useful for different things
6751   @item files and tape marks
6752      one tape mark between files, two at end.
6753   @item positioning the tape
6754      MT writes two at end of write,
6755      backspaces over one when writing again.
6756   @end itemize
6757  @end itemize
6758 @end itemize
6761 This chapter documents both the provided shell scripts and @command{tar}
6762 options which are more specific to usage as a backup tool.
6764 To @dfn{back up} a file system means to create archives that contain
6765 all the files in that file system.  Those archives can then be used to
6766 restore any or all of those files (for instance if a disk crashes or a
6767 file is accidentally deleted).  File system @dfn{backups} are also
6768 called @dfn{dumps}.
6770 @menu
6771 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
6772 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
6773 * Backup Levels::               Levels of Backups
6774 * Backup Parameters::           Setting Parameters for Backups and Restoration
6775 * Scripted Backups::            Using the Backup Scripts
6776 * Scripted Restoration::        Using the Restore Script
6777 @end menu
6779 @node Full Dumps
6780 @section Using @command{tar} to Perform Full Dumps
6781 @UNREVISED{}
6783 @cindex full dumps
6784 @cindex dumps, full
6786 @cindex corrupted archives
6787 Full dumps should only be made when no other people or programs
6788 are modifying files in the file system.  If files are modified while
6789 @command{tar} is making the backup, they may not be stored properly in
6790 the archive, in which case you won't be able to restore them if you
6791 have to.  (Files not being modified are written with no trouble, and do
6792 not corrupt the entire archive.)
6794 You will want to use the @option{--label=@var{archive-label}}
6795 (@option{-V @var{archive-label}}) option to give the archive a
6796 volume label, so you can tell what this archive is even if the label
6797 falls off the tape, or anything like that.
6799 Unless the file system you are dumping is guaranteed to fit on
6800 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6801 Make sure you have enough tapes on hand to complete the backup.
6803 If you want to dump each file system separately you will need to use
6804 the @option{--one-file-system} option to prevent
6805 @command{tar} from crossing file system boundaries when storing
6806 (sub)directories.
6808 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6809 option is not needed, since this is a complete copy of everything in
6810 the file system, and a full restore from this backup would only be
6811 done onto a completely
6812 empty disk.
6814 Unless you are in a hurry, and trust the @command{tar} program (and your
6815 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6816 option, to make sure your files really made it onto the dump properly.
6817 This will also detect cases where the file was modified while (or just
6818 after) it was being archived.  Not all media (notably cartridge tapes)
6819 are capable of being verified, unfortunately.
6821 @node Incremental Dumps
6822 @section Using @command{tar} to Perform Incremental Dumps
6824 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6825 stores additional metadata so that exact state of the file system
6826 can be restored when extracting the archive.
6828 @GNUTAR{} currently offers two options for handling incremental
6829 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6830 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6832 @xopindex{listed-incremental, described}
6833 The option @option{--listed-incremental} instructs tar to operate on
6834 an incremental archive with additional metadata stored in a standalone
6835 file, called a @dfn{snapshot file}.  The purpose of this file is to help
6836 determine which files have been changed, added or deleted since the
6837 last backup, so that the next incremental backup will contain only
6838 modified files.  The name of the snapshot file is given as an argument
6839 to the option:
6841 @table @option
6842 @item --listed-incremental=@var{file}
6843 @itemx -g @var{file}
6844   Handle incremental backups with snapshot data in @var{file}.
6845 @end table
6847 To create an incremental backup, you would use
6848 @option{--listed-incremental} together with @option{--create}
6849 (@pxref{create}).  For example:
6851 @smallexample
6852 $ @kbd{tar --create \
6853            --file=archive.1.tar \
6854            --listed-incremental=/var/log/usr.snar \
6855            /usr}
6856 @end smallexample
6858 This will create in @file{archive.1.tar} an incremental backup of
6859 the @file{/usr} file system, storing additional metadata in the file
6860 @file{/var/log/usr.snar}.  If this file does not exist, it will be
6861 created.  The created archive will then be a @dfn{level 0 backup};
6862 please see the next section for more on backup levels.
6864 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6865 determines which files are modified.  In this case only these files will be
6866 stored in the archive.  Suppose, for example, that after running the
6867 above command, you delete file @file{/usr/doc/old} and create
6868 directory @file{/usr/local/db} with the following contents:
6870 @smallexample
6871 $ @kbd{ls /usr/local/db}
6872 /usr/local/db/data
6873 /usr/local/db/index
6874 @end smallexample
6876 Some time later you create another incremental backup.  You will
6877 then see:
6879 @smallexample
6880 $ @kbd{tar --create \
6881            --file=archive.2.tar \
6882            --listed-incremental=/var/log/usr.snar \
6883            /usr}
6884 tar: usr/local/db: Directory is new
6885 usr/local/db/
6886 usr/local/db/data
6887 usr/local/db/index
6888 @end smallexample
6890 @noindent
6891 The created archive @file{archive.2.tar} will contain only these
6892 three members.  This archive is called a @dfn{level 1 backup}.  Notice
6893 that @file{/var/log/usr.snar} will be updated with the new data, so if
6894 you plan to create more @samp{level 1} backups, it is necessary to
6895 create a working copy of the snapshot file before running
6896 @command{tar}.  The above example will then be modified as follows:
6898 @smallexample
6899 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6900 $ @kbd{tar --create \
6901            --file=archive.2.tar \
6902            --listed-incremental=/var/log/usr.snar-1 \
6903            /usr}
6904 @end smallexample
6906 @anchor{--level=0}
6907 @xopindex{level, described}
6908 You can force @samp{level 0} backups either by removing the snapshot
6909 file before running @command{tar}, or by supplying the
6910 @option{--level=0} option, e.g.:
6912 @smallexample
6913 $ @kbd{tar --create \
6914            --file=archive.2.tar \
6915            --listed-incremental=/var/log/usr.snar-0 \
6916            --level=0 \
6917            /usr}
6918 @end smallexample
6920 Incremental dumps depend crucially on time stamps, so the results are
6921 unreliable if you modify a file's time stamps during dumping (e.g.,
6922 with the @option{--atime-preserve=replace} option), or if you set the clock
6923 backwards.
6925 @anchor{device numbers}
6926 @cindex Device numbers, using in incremental backups
6927 Metadata stored in snapshot files include device numbers, which,
6928 obviously are supposed to be non-volatile values.  However, it turns
6929 out that @acronym{NFS} devices have undependable values when an automounter
6930 gets in the picture.  This can lead to a great deal of spurious
6931 redumping in incremental dumps, so it is somewhat useless to compare
6932 two @acronym{NFS} devices numbers over time.  The solution implemented
6933 currently is to consider all @acronym{NFS} devices as being equal
6934 when it comes to comparing directories; this is fairly gross, but
6935 there does not seem to be a better way to go.
6937 Apart from using @acronym{NFS}, there are a number of cases where
6938 relying on device numbers can cause spurious redumping of unmodified
6939 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6940 volumes.  To avoid this, use @option{--no-check-device} option:
6942 @table @option
6943 @xopindex{no-check-device, described}
6944 @item --no-check-device
6945 Do not rely on device numbers when preparing a list of changed files
6946 for an incremental dump.
6948 @xopindex{check-device, described}
6949 @item --check-device
6950 Use device numbers when preparing a list of changed files
6951 for an incremental dump.  This is the default behavior.  The purpose
6952 of this option is to undo the effect of the @option{--no-check-device}
6953 if it was given in @env{TAR_OPTIONS} environment variable
6954 (@pxref{TAR_OPTIONS}).
6955 @end table
6957 There is also another way to cope with changing device numbers.  It is
6958 described in detail in @ref{Fixing Snapshot Files}.
6960 Note that incremental archives use @command{tar} extensions and may
6961 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6963 @xopindex{listed-incremental, using with @option{--extract}}
6964 @xopindex{extract, using with @option{--listed-incremental}}
6965 To extract from the incremental dumps, use
6966 @option{--listed-incremental} together with @option{--extract}
6967 option (@pxref{extracting files}).  In this case, @command{tar} does
6968 not need to access snapshot file, since all the data necessary for
6969 extraction are stored in the archive itself.  So, when extracting, you
6970 can give whatever argument to @option{--listed-incremental}, the usual
6971 practice is to use @option{--listed-incremental=/dev/null}.
6972 Alternatively, you can use @option{--incremental}, which needs no
6973 arguments.  In general, @option{--incremental} (@option{-G}) can be
6974 used as a shortcut for @option{--listed-incremental} when listing or
6975 extracting incremental backups (for more information regarding this
6976 option, @pxref{incremental-op}).
6978 When extracting from the incremental backup @GNUTAR{} attempts to
6979 restore the exact state the file system had when the archive was
6980 created.  In particular, it will @emph{delete} those files in the file
6981 system that did not exist in their directories when the archive was
6982 created.  If you have created several levels of incremental files,
6983 then in order to restore the exact contents the file system  had when
6984 the last level was created, you will need to restore from all backups
6985 in turn.  Continuing our example, to restore the state of @file{/usr}
6986 file system, one would do@footnote{Notice, that since both archives
6987 were created without @option{-P} option (@pxref{absolute}), these
6988 commands should be run from the root file system.}:
6990 @smallexample
6991 $ @kbd{tar --extract \
6992            --listed-incremental=/dev/null \
6993            --file archive.1.tar}
6994 $ @kbd{tar --extract \
6995            --listed-incremental=/dev/null \
6996            --file archive.2.tar}
6997 @end smallexample
6999 To list the contents of an incremental archive, use @option{--list}
7000 (@pxref{list}), as usual.  To obtain more information about the
7001 archive, use @option{--listed-incremental} or @option{--incremental}
7002 combined with two @option{--verbose} options@footnote{Two
7003 @option{--verbose} options were selected to avoid breaking usual
7004 verbose listing output (@option{--list --verbose}) when using in
7005 scripts.
7007 @xopindex{incremental, using with @option{--list}}
7008 @xopindex{listed-incremental, using with @option{--list}}
7009 @xopindex{list, using with @option{--incremental}}
7010 @xopindex{list, using with @option{--listed-incremental}}
7011 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
7012 contents of the DUMPDIR header (with terminating nulls) when
7013 @option{--incremental} or @option{--listed-incremental} option was
7014 given, no matter what the verbosity level.  This behavior, and,
7015 especially, the binary output it produced were considered inconvenient
7016 and were changed in version 1.16.}:
7018 @smallexample
7019 @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
7020 @end smallexample
7022 This command will print, for each directory in the archive, the list
7023 of files in that directory at the time the archive was created.  This
7024 information is put out in a format which is both human-readable and
7025 unambiguous for a program: each file name is printed as
7027 @smallexample
7028 @var{x} @var{file}
7029 @end smallexample
7031 @noindent
7032 where @var{x} is a letter describing the status of the file: @samp{Y}
7033 if the file  is present in the archive, @samp{N} if the file is not
7034 included in the archive, or a @samp{D} if the file is a directory (and
7035 is included in the archive).  @xref{Dumpdir}, for the detailed
7036 description of dumpdirs and status codes.  Each such
7037 line is terminated by a newline character.  The last line is followed
7038 by an additional newline to indicate the end of the data.
7040 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
7041 gives the same behavior as @option{--listed-incremental} when used
7042 with @option{--list} and @option{--extract} options.  When used with
7043 @option{--create} option, it creates an incremental archive without
7044 creating snapshot file.  Thus, it is impossible to create several
7045 levels of incremental backups with @option{--incremental} option.
7047 @node Backup Levels
7048 @section Levels of Backups
7050 An archive containing all the files in the file system is called a
7051 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
7052 creating a full dump every day.  This strategy, however, would waste a
7053 substantial amount of archive media and user time, as unchanged files
7054 are daily re-archived.
7056 It is more efficient to do a full dump only occasionally.  To back up
7057 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
7058 one} dump archives all the files that have changed since the last full
7059 dump.
7061 A typical dump strategy would be to perform a full dump once a week,
7062 and a level one dump once a day.  This means some versions of files
7063 will in fact be archived more than once, but this dump strategy makes
7064 it possible to restore a file system to within one day of accuracy by
7065 only extracting two archives---the last weekly (full) dump and the
7066 last daily (level one) dump.  The only information lost would be in
7067 files changed or created since the last daily backup.  (Doing dumps
7068 more than once a day is usually not worth the trouble.)
7070 @GNUTAR{} comes with scripts you can use to do full
7071 and level-one (actually, even level-two and so on) dumps.  Using
7072 scripts (shell programs) to perform backups and restoration is a
7073 convenient and reliable alternative to typing out file name lists
7074 and @command{tar} commands by hand.
7076 Before you use these scripts, you need to edit the file
7077 @file{backup-specs}, which specifies parameters used by the backup
7078 scripts and by the restore script.  This file is usually located
7079 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
7080 detailed description.  Once the backup parameters are set, you can
7081 perform backups or restoration by running the appropriate script.
7083 The name of the backup script is @code{backup}.  The name of the
7084 restore script is @code{restore}.  The following sections describe
7085 their use in detail.
7087 @emph{Please Note:} The backup and restoration scripts are
7088 designed to be used together.  While it is possible to restore files by
7089 hand from an archive which was created using a backup script, and to create
7090 an archive by hand which could then be extracted using the restore script,
7091 it is easier to use the scripts.  @xref{Incremental Dumps}, before
7092 making such an attempt.
7094 @node Backup Parameters
7095 @section Setting Parameters for Backups and Restoration
7097 The file @file{backup-specs} specifies backup parameters for the
7098 backup and restoration scripts provided with @command{tar}.  You must
7099 edit @file{backup-specs} to fit your system configuration and schedule
7100 before using these scripts.
7102 Syntactically, @file{backup-specs} is a shell script, containing
7103 mainly variable assignments.  However, any valid shell construct
7104 is allowed in this file.  Particularly, you may wish to define
7105 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
7106 For more information about shell script syntax, please refer to
7107 @url{https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html,
7108 the definition of the Shell Command Language}.  See also
7109 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
7111 The shell variables controlling behavior of @code{backup} and
7112 @code{restore} are described in the following subsections.
7114 @menu
7115 * General-Purpose Variables::
7116 * Magnetic Tape Control::
7117 * User Hooks::
7118 * backup-specs example::        An Example Text of @file{Backup-specs}
7119 @end menu
7121 @node General-Purpose Variables
7122 @subsection General-Purpose Variables
7124 @defvr {Backup variable} ADMINISTRATOR
7125 The user name of the backup administrator.  @code{Backup} scripts
7126 sends a backup report to this address.
7127 @end defvr
7129 @defvr {Backup variable} BACKUP_HOUR
7130 The hour at which the backups are done.  This can be a number from 0
7131 to 23, or the time specification in form @var{hours}:@var{minutes},
7132 or the string @samp{now}.
7134 This variable is used by @code{backup}.  Its value may be overridden
7135 using @option{--time} option (@pxref{Scripted Backups}).
7136 @end defvr
7138 @defvr {Backup variable} TAPE_FILE
7140 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
7141 is a remote archive (@pxref{remote-dev}), backup script will suppose
7142 that your @command{mt} is able to access remote devices.  If @var{RSH}
7143 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
7144 invocations of @command{mt}.
7145 @end defvr
7147 @defvr {Backup variable} BLOCKING
7149 The blocking factor @command{tar} will use when writing the dump archive.
7150 @xref{Blocking Factor}.
7151 @end defvr
7153 @defvr {Backup variable} BACKUP_DIRS
7155 A list of file systems to be dumped (for @code{backup}), or restored
7156 (for @code{restore}).  You can include any directory
7157 name in the list --- subdirectories on that file system will be
7158 included, regardless of how they may look to other networked machines.
7159 Subdirectories on other file systems will be ignored.
7161 The host name specifies which host to run @command{tar} on, and should
7162 normally be the host that actually contains the file system.  However,
7163 the host machine must have @GNUTAR{} installed, and
7164 must be able to access the directory containing the backup scripts and
7165 their support files using the same file name that is used on the
7166 machine where the scripts are run (i.e., what @command{pwd} will print
7167 when in that directory on that machine).  If the host that contains
7168 the file system does not have this capability, you can specify another
7169 host as long as it can access the file system through @acronym{NFS}.
7171 If the list of file systems is very long you may wish to put it
7172 in a separate file.  This file is usually named
7173 @file{/etc/backup/dirs}, but this name may be overridden in
7174 @file{backup-specs} using @code{DIRLIST} variable.
7175 @end defvr
7177 @defvr {Backup variable} DIRLIST
7179 The name of the file that contains a list of file systems to backup
7180 or restore.  By default it is @file{/etc/backup/dirs}.
7181 @end defvr
7183 @defvr {Backup variable} BACKUP_FILES
7185 A list of individual files to be dumped (for @code{backup}), or restored
7186 (for @code{restore}).  These should be accessible from the machine on
7187 which the backup script is run.
7189 If the list of individual files is very long you may wish to store it
7190 in a separate file.  This file is usually named
7191 @file{/etc/backup/files}, but this name may be overridden in
7192 @file{backup-specs} using @code{FILELIST} variable.
7193 @end defvr
7195 @defvr {Backup variable} FILELIST
7197 The name of the file that contains a list of individual files to backup
7198 or restore.  By default it is @file{/etc/backup/files}.
7199 @end defvr
7201 @defvr {Backup variable} MT
7203 Full file name of @command{mt} binary.
7204 @end defvr
7206 @defvr {Backup variable} RSH
7207 @anchor{RSH}
7208 Full file name of @command{rsh} binary or its equivalent.  You may wish to
7209 set it to @code{ssh}, to improve security.  In this case you will have
7210 to use public key authentication.
7211 @end defvr
7213 @defvr {Backup variable} RSH_COMMAND
7215 Full file name of @command{rsh} binary on remote machines.  This will
7216 be passed via @option{--rsh-command} option to the remote invocation
7217 of @GNUTAR{}.
7218 @end defvr
7220 @defvr {Backup variable} VOLNO_FILE
7222 Name of temporary file to hold volume numbers.  This needs to be accessible
7223 by all the machines which have file systems to be dumped.
7224 @end defvr
7226 @defvr {Backup variable} XLIST
7228 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
7229 located on the remote machine and containing the list of files to
7230 be excluded from the backup.  Exclude file lists are searched in
7231 /etc/tar-backup directory.  A common use for exclude file lists
7232 is to exclude files containing security-sensitive information
7233 (e.g., @file{/etc/shadow} from backups).
7235 This variable affects only @code{backup}.
7236 @end defvr
7238 @defvr {Backup variable} SLEEP_TIME
7240 Time to sleep between dumps of any two successive file systems
7242 This variable affects only @code{backup}.
7243 @end defvr
7245 @defvr {Backup variable} DUMP_REMIND_SCRIPT
7247 Script to be run when it's time to insert a new tape in for the next
7248 volume.  Administrators may want to tailor this script for their site.
7249 If this variable isn't set, @GNUTAR{} will display its built-in
7250 prompt, and will expect confirmation from the console.  For the
7251 description of the default prompt, see @ref{change volume prompt}.
7253 @end defvr
7255 @defvr {Backup variable} SLEEP_MESSAGE
7257 Message to display on the terminal while waiting for dump time.  Usually
7258 this will just be some literal text.
7259 @end defvr
7261 @defvr {Backup variable} TAR
7263 Full file name of the @GNUTAR{} executable.  If this is not set, backup
7264 scripts will search @command{tar} in the current shell path.
7265 @end defvr
7267 @node Magnetic Tape Control
7268 @subsection Magnetic Tape Control
7270 Backup scripts access tape device using special @dfn{hook functions}.
7271 These functions take a single argument --- the name of the tape
7272 device.  Their names are kept in the following variables:
7274 @defvr {Backup variable} MT_BEGIN
7275 The name of @dfn{begin} function.  This function is called before
7276 accessing the drive.  By default it retensions the tape:
7278 @smallexample
7279 MT_BEGIN=mt_begin
7281 mt_begin() @{
7282     mt -f "$1" retension
7284 @end smallexample
7285 @end defvr
7287 @defvr {Backup variable} MT_REWIND
7288 The name of @dfn{rewind} function.  The default definition is as
7289 follows:
7291 @smallexample
7292 MT_REWIND=mt_rewind
7294 mt_rewind() @{
7295     mt -f "$1" rewind
7297 @end smallexample
7299 @end defvr
7301 @defvr {Backup variable} MT_OFFLINE
7302 The name of the function switching the tape off line.  By default
7303 it is defined as follows:
7305 @smallexample
7306 MT_OFFLINE=mt_offline
7308 mt_offline() @{
7309     mt -f "$1" offl
7311 @end smallexample
7312 @end defvr
7314 @defvr {Backup variable} MT_STATUS
7315 The name of the function used to obtain the status of the archive device,
7316 including error count.  Default definition:
7318 @smallexample
7319 MT_STATUS=mt_status
7321 mt_status() @{
7322     mt -f "$1" status
7324 @end smallexample
7325 @end defvr
7327 @node User Hooks
7328 @subsection User Hooks
7330 @dfn{User hooks} are shell functions executed before and after
7331 each @command{tar} invocation.  Thus, there are @dfn{backup
7332 hooks}, which are executed before and after dumping each file
7333 system, and @dfn{restore hooks}, executed before and
7334 after restoring a file system.  Each user hook is a shell function
7335 taking four arguments:
7337 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
7338 Its arguments are:
7340 @table @var
7341 @item level
7342 Current backup or restore level.
7344 @item host
7345 Name or IP address of the host machine being dumped or restored.
7347 @item fs
7348 Full file name of the file system being dumped or restored.
7350 @item fsname
7351 File system name with directory separators replaced with colons.  This
7352 is useful, e.g., for creating unique files.
7353 @end table
7354 @end deffn
7356 Following variables keep the names of user hook functions:
7358 @defvr {Backup variable} DUMP_BEGIN
7359 Dump begin function.  It is executed before dumping the file system.
7360 @end defvr
7362 @defvr {Backup variable} DUMP_END
7363 Executed after dumping the file system.
7364 @end defvr
7366 @defvr {Backup variable} RESTORE_BEGIN
7367 Executed before restoring the file system.
7368 @end defvr
7370 @defvr {Backup variable} RESTORE_END
7371 Executed after restoring the file system.
7372 @end defvr
7374 @node backup-specs example
7375 @subsection An Example Text of @file{Backup-specs}
7377 The following is an example of @file{backup-specs}:
7379 @smallexample
7380 # site-specific parameters for file system backup.
7382 ADMINISTRATOR=friedman
7383 BACKUP_HOUR=1
7384 TAPE_FILE=/dev/nrsmt0
7386 # Use @code{ssh} instead of the less secure @code{rsh}
7387 RSH=/usr/bin/ssh
7388 RSH_COMMAND=/usr/bin/ssh
7390 # Override MT_STATUS function:
7391 my_status() @{
7392       mts -t $TAPE_FILE
7394 MT_STATUS=my_status
7396 # Disable MT_OFFLINE function
7397 MT_OFFLINE=:
7399 BLOCKING=124
7400 BACKUP_DIRS="
7401         albert:/fs/fsf
7402         apple-gunkies:/gd
7403         albert:/fs/gd2
7404         albert:/fs/gp
7405         geech:/usr/jla
7406         churchy:/usr/roland
7407         albert:/
7408         albert:/usr
7409         apple-gunkies:/
7410         apple-gunkies:/usr
7411         gnu:/hack
7412         gnu:/u
7413         apple-gunkies:/com/mailer/gnu
7414         apple-gunkies:/com/archive/gnu"
7416 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
7418 @end smallexample
7420 @node Scripted Backups
7421 @section Using the Backup Scripts
7423 The syntax for running a backup script is:
7425 @smallexample
7426 backup --level=@var{level} --time=@var{time}
7427 @end smallexample
7429 The @option{--level} option requests the dump level.  Thus, to produce
7430 a full dump, specify @code{--level=0} (this is the default, so
7431 @option{--level} may be omitted if its value is
7432 @code{0})@footnote{For backward compatibility, the @code{backup} will also
7433 try to deduce the requested dump level from the name of the
7434 script itself.  If the name consists of a string @samp{level-}
7435 followed by a single decimal digit, that digit is taken as
7436 the dump level number.  Thus, you may create a link from @code{backup}
7437 to @code{level-1} and then run @code{level-1} whenever you need to
7438 create a level one dump.}.
7440 The @option{--time} option determines when should the backup be
7441 run.  @var{Time} may take three forms:
7443 @table @asis
7444 @item @var{hh}:@var{mm}
7446 The dump must be run at @var{hh} hours @var{mm} minutes.
7448 @item @var{hh}
7450 The dump must be run at @var{hh} hours.
7452 @item now
7454 The dump must be run immediately.
7455 @end table
7457 You should start a script with a tape or disk mounted.  Once you
7458 start a script, it prompts you for new tapes or disks as it
7459 needs them.  Media volumes don't have to correspond to archive
7460 files --- a multi-volume archive can be started in the middle of a
7461 tape that already contains the end of another multi-volume archive.
7462 The @code{restore} script prompts for media by its archive volume,
7463 so to avoid an error message you should keep track of which tape
7464 (or disk) contains which volume of the archive (@pxref{Scripted
7465 Restoration}).
7467 The backup scripts write two files on the file system.  The first is a
7468 record file in @file{/etc/tar-backup/}, which is used by the scripts
7469 to store and retrieve information about which files were dumped.  This
7470 file is not meant to be read by humans, and should not be deleted by
7471 them.  @xref{Snapshot Files}, for a more detailed explanation of this
7472 file.
7474 The second file is a log file containing the names of the file systems
7475 and files dumped, what time the backup was made, and any error
7476 messages that were generated, as well as how much space was left in
7477 the media volume after the last volume of the archive was written.
7478 You should check this log file after every backup.  The file name is
7479 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
7480 represents current date, and @var{n} represents current dump level number.
7482 The script also prints the name of each system being dumped to the
7483 standard output.
7485 Following is the full list of options accepted by @code{backup}
7486 script:
7488 @table @option
7489 @item -l @var{level}
7490 @itemx --level=@var{level}
7491 Do backup level @var{level} (default 0).
7493 @item -f
7494 @itemx --force
7495 Force backup even if today's log file already exists.
7497 @item -v[@var{level}]
7498 @itemx --verbose[=@var{level}]
7499 Set verbosity level.  The higher the level is, the more debugging
7500 information will be output during execution.  Default @var{level}
7501 is 100, which means the highest debugging level.
7503 @item -t @var{start-time}
7504 @itemx --time=@var{start-time}
7505 Wait till @var{time}, then do backup.
7507 @item -h
7508 @itemx --help
7509 Display short help message and exit.
7511 @item -V
7512 @itemx --version
7513 Display information about the program's name, version, origin and legal
7514 status, all on standard output, and then exit successfully.
7515 @end table
7518 @node Scripted Restoration
7519 @section Using the Restore Script
7521 To restore files that were archived using a scripted backup, use the
7522 @code{restore} script.  Its usage is quite straightforward.  In the
7523 simplest form, invoke @code{restore --all}, it will
7524 then restore all the file systems and files specified in
7525 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
7527 You may select the file systems (and/or files) to restore by
7528 giving @code{restore} a list of @dfn{patterns} in its command
7529 line.  For example, running
7531 @smallexample
7532 restore 'albert:*'
7533 @end smallexample
7535 @noindent
7536 will restore all file systems on the machine @samp{albert}.  A more
7537 complicated example:
7539 @smallexample
7540 restore 'albert:*' '*:/var'
7541 @end smallexample
7543 @noindent
7544 This command will restore all file systems on the machine @samp{albert}
7545 as well as @file{/var} file system on all machines.
7547 By default @code{restore} will start restoring files from the lowest
7548 available dump level (usually zero) and will continue through
7549 all available dump levels.  There may be situations where such a
7550 thorough restore is not necessary.  For example, you may wish to
7551 restore only files from the recent level one backup.  To do so,
7552 use @option{--level} option, as shown in the example below:
7554 @smallexample
7555 restore --level=1
7556 @end smallexample
7558 The full list of options accepted by @code{restore} follows:
7560 @table @option
7561 @item -a
7562 @itemx --all
7563 Restore all file systems and files specified in @file{backup-specs}.
7565 @item -l @var{level}
7566 @itemx --level=@var{level}
7567 Start restoring from the given backup level, instead of the default 0.
7569 @item -v[@var{level}]
7570 @itemx --verbose[=@var{level}]
7571 Set verbosity level.  The higher the level is, the more debugging
7572 information will be output during execution.  Default @var{level}
7573 is 100, which means the highest debugging level.
7575 @item -h
7576 @itemx --help
7577 Display short help message and exit.
7579 @item -V
7580 @itemx --version
7581 Display information about the program's name, version, origin and legal
7582 status, all on standard output, and then exit successfully.
7583 @end table
7585 You should start the restore script with the media containing the
7586 first volume of the archive mounted.  The script will prompt for other
7587 volumes as they are needed.  If the archive is on tape, you don't need
7588 to rewind the tape to to its beginning---if the tape head is
7589 positioned past the beginning of the archive, the script will rewind
7590 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
7591 positioning.
7593 @quotation
7594 @strong{Warning:} The script will delete files from the active file
7595 system if they were not in the file system when the archive was made.
7596 @end quotation
7598 @xref{Incremental Dumps}, for an explanation of how the script makes
7599 that determination.
7601 @node Choosing
7602 @chapter Choosing Files and Names for @command{tar}
7604 Certain options to @command{tar} enable you to specify a name for your
7605 archive.  Other options let you decide which files to include or exclude
7606 from the archive, based on when or whether files were modified, whether
7607 the file names do or don't match specified patterns, or whether files
7608 are in specified directories.
7610 This chapter discusses these options in detail.
7612 @menu
7613 * file::                        Choosing the Archive's Name
7614 * Selecting Archive Members::
7615 * files::                       Reading Names from a File
7616 * exclude::                     Excluding Some Files
7617 * wildcards::                   Wildcards Patterns and Matching
7618 * quoting styles::              Ways of Quoting Special Characters in Names
7619 * transform::                   Modifying File and Member Names
7620 * after::                       Operating Only on New Files
7621 * recurse::                     Descending into Directories
7622 * one::                         Crossing File System Boundaries
7623 @end menu
7625 @node file
7626 @section Choosing and Naming Archive Files
7628 @cindex Naming an archive
7629 @cindex Archive Name
7630 @cindex Choosing an archive file
7631 @cindex Where is the archive?
7632 @opindex file
7633 By default, @command{tar} uses an archive file name that was compiled when
7634 it was built on the system; usually this name refers to some physical
7635 tape drive on the machine.  However, the person who installed @command{tar}
7636 on the system may not have set the default to a meaningful value as far as
7637 most users are concerned.  As a result, you will usually want to tell
7638 @command{tar} where to find (or create) the archive.  The
7639 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
7640 option allows you to either specify or name a file to use as the archive
7641 instead of the default archive file location.
7643 @table @option
7644 @xopindex{file, short description}
7645 @item --file=@var{archive-name}
7646 @itemx -f @var{archive-name}
7647 Name the archive to create or operate on.  Use in conjunction with
7648 any operation.
7649 @end table
7651 For example, in this @command{tar} command,
7653 @smallexample
7654 $ @kbd{tar -cvf collection.tar blues folk jazz}
7655 @end smallexample
7657 @noindent
7658 @file{collection.tar} is the name of the archive.  It must directly
7659 follow the @option{-f} option, since whatever directly follows @option{-f}
7660 @emph{will} end up naming the archive.  If you neglect to specify an
7661 archive name, you may end up overwriting a file in the working directory
7662 with the archive you create since @command{tar} will use this file's name
7663 for the archive name.
7665 An archive can be saved as a file in the file system, sent through a
7666 pipe or over a network, or written to an I/O device such as a tape,
7667 floppy disk, or CD write drive.
7669 @cindex Writing new archives
7670 @cindex Archive creation
7671 If you do not name the archive, @command{tar} uses the value of the
7672 environment variable @env{TAPE} as the file name for the archive.  If
7673 that is not available, @command{tar} uses a default, compiled-in archive
7674 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
7676 @cindex Standard input and output
7677 @cindex tar to standard input and output
7678 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
7679 archive from standard input (when listing or extracting files), or
7680 writes it to standard output (when creating an archive).  If you use
7681 @file{-} as an @var{archive-name} when modifying an archive,
7682 @command{tar} reads the original archive from its standard input and
7683 writes the entire new archive to its standard output.
7685 The following example is a convenient way of copying directory
7686 hierarchy from @file{sourcedir} to @file{targetdir}.
7688 @smallexample
7689 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
7690 @end smallexample
7692 The @option{-C} option allows to avoid using subshells:
7694 @smallexample
7695 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
7696 @end smallexample
7698 In both examples above, the leftmost @command{tar} invocation archives
7699 the contents of @file{sourcedir} to the standard output, while the
7700 rightmost one reads this archive from its standard input and
7701 extracts it.  The @option{-p} option tells it to restore permissions
7702 of the extracted files.
7704 @cindex Remote devices
7705 @cindex tar to a remote device
7706 @anchor{remote-dev}
7707 To specify an archive file on a device attached to a remote machine,
7708 use the following:
7710 @smallexample
7711 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
7712 @end smallexample
7714 @noindent
7715 @command{tar} will set up the remote connection, if possible, and
7716 prompt you for a username and password.  If you use
7717 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
7718 will attempt to set up the remote connection using your username
7719 as the username on the remote machine.
7721 @cindex Local and remote archives
7722 @anchor{local and remote archives}
7723 If the archive file name includes a colon (@samp{:}), then it is assumed
7724 to be a file on another machine.  If the archive file is
7725 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
7726 host @var{host}.  The remote host is accessed using the @command{rsh}
7727 program, with a username of @var{user}.  If the username is omitted
7728 (along with the @samp{@@} sign), then your user name will be used.
7729 (This is the normal @command{rsh} behavior.)  It is necessary for the
7730 remote machine, in addition to permitting your @command{rsh} access, to
7731 have the @file{rmt} program installed (this command is included in
7732 the @GNUTAR{} distribution and by default is installed under
7733 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
7734 installation prefix).  If you need to use a file whose name includes a
7735 colon, then the remote tape drive behavior
7736 can be inhibited by using the @option{--force-local} option.
7738 When the archive is being created to @file{/dev/null}, @GNUTAR{}
7739 tries to minimize input and output operations.  The Amanda backup
7740 system, when used with @GNUTAR{}, has an initial sizing pass which
7741 uses this feature.
7743 @node Selecting Archive Members
7744 @section Selecting Archive Members
7745 @cindex Specifying files to act on
7746 @cindex Specifying archive members
7748 @dfn{File Name arguments} specify which files in the file system
7749 @command{tar} operates on, when creating or adding to an archive, or which
7750 archive members @command{tar} operates on, when reading or deleting from
7751 an archive.  @xref{Operations}.
7753 To specify file names, you can include them as the last arguments on
7754 the command line, as follows:
7755 @smallexample
7756 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
7757 @end smallexample
7759 If a file name begins with dash (@samp{-}), precede it with
7760 @option{--add-file} option to prevent it from being treated as an
7761 option.
7763 @anchor{input name quoting}
7764 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7765 name, replacing @dfn{escape sequences} according to the following
7766 table:
7768 @multitable @columnfractions 0.20 0.60
7769 @headitem Escape @tab Replaced with
7770 @item \a         @tab Audible bell (@acronym{ASCII} 7)
7771 @item \b         @tab Backspace (@acronym{ASCII} 8)
7772 @item \f         @tab Form feed (@acronym{ASCII} 12)
7773 @item \n         @tab New line (@acronym{ASCII} 10)
7774 @item \r         @tab Carriage return (@acronym{ASCII} 13)
7775 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
7776 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
7777 @item \?         @tab @acronym{ASCII} 127
7778 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7779                  of up to 3 digits)
7780 @end multitable
7782 A backslash followed by any other symbol is retained.
7784 This default behavior is controlled by the following command line
7785 option:
7787 @table @option
7788 @opindex unquote
7789 @item --unquote
7790 Enable unquoting input file or member names (default).
7792 @opindex no-unquote
7793 @item --no-unquote
7794 Disable unquoting input file or member names.
7795 @end table
7797 If you specify a directory name as a file name argument, all the files
7798 in that directory are operated on by @command{tar}.
7800 If you do not specify files, @command{tar} behavior differs depending
7801 on the operation mode as described below:
7803 When @command{tar} is invoked with @option{--create} (@option{-c}),
7804 @command{tar} will stop immediately, reporting the following:
7806 @smallexample
7807 @group
7808 $ @kbd{tar cf a.tar}
7809 tar: Cowardly refusing to create an empty archive
7810 Try 'tar --help' or 'tar --usage' for more information.
7811 @end group
7812 @end smallexample
7814 If you specify either @option{--list} (@option{-t}) or
7815 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7816 operates on all the archive members in the archive.
7818 If run with @option{--diff} option, tar will compare the archive with
7819 the contents of the current working directory.
7821 If you specify any other operation, @command{tar} does nothing.
7823 By default, @command{tar} takes file names from the command line.  However,
7824 there are other ways to specify file or member names, or to modify the
7825 manner in which @command{tar} selects the files or members upon which to
7826 operate.  In general, these methods work both for specifying the names
7827 of files and archive members.
7829 @node files
7830 @section Reading Names from a File
7832 @cindex Reading file names from a file
7833 @cindex Lists of file names
7834 @cindex File Name arguments, alternatives
7835 @cindex @command{find}, using with @command{tar}
7836 Instead of giving the names of files or archive members on the command
7837 line, you can put the names into a file, and then use the
7838 @option{--files-from=@var{file-of-names}} (@option{-T
7839 @var{file-of-names}}) option to @command{tar}.  Give the name of the
7840 file which contains the list of files to include as the argument to
7841 @option{--files-from}.  In the list, the file names should be separated by
7842 newlines.  You will frequently use this option when you have generated
7843 the list of files to archive with the @command{find} utility.
7845 @table @option
7846 @opindex files-from
7847 @item --files-from=@var{file-name}
7848 @itemx -T @var{file-name}
7849 Get names to extract or create from file @var{file-name}.
7850 @end table
7852 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7853 you specify either @code{--files-from=-} or @code{-T -}), then the file
7854 names are read from standard input.
7856 Unless you are running @command{tar} with @option{--create}, you cannot use
7857 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7858 command.
7860 Any number of @option{-T} options can be given in the command line.
7862 The following example shows how to use @command{find} to generate a list of
7863 files smaller than 400 blocks in length@footnote{A file system block
7864 is usually 512 bytes, so this amounts to 200K.  Use the @samp{c}
7865 suffix to specify size in @emph{bytes}.  Also, when using
7866 GNU find, you can specify other size units, such as @samp{k},
7867 @samp{m}, etc.  @xref{Size,,,find.info,GNU Findutils}, for details.} and put that list into a file
7868 called @file{small-files}.  You can then use the @option{-T} option to
7869 @command{tar} to specify the files from that file, @file{small-files}, to
7870 create the archive @file{little.tgz}.  (The @option{-z} option to
7871 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7872 more information.)
7874 @smallexample
7875 $ @kbd{find . -size -400 -print > small-files}
7876 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7877 @end smallexample
7879 @noindent
7880 By default, each line read from the file list is first stripped off
7881 any leading and trailing whitespace.  If the resulting string begins
7882 with @samp{-} character, it is considered a @command{tar} option and is
7883 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7884 recognized only @option{-C} option in file lists, and only if the
7885 option and its argument occupied two consecutive lines.}.  Only a
7886 subset of @GNUTAR{} options is allowed for use in file lists.  For
7887 a list of such options, @ref{Position-Sensitive Options}.
7889 For example, the common use of this feature is to change to another
7890 directory by specifying @option{-C} option:
7892 @smallexample
7893 @group
7894 $ @kbd{cat list}
7895 -C/etc
7896 passwd
7897 hosts
7898 -C/lib
7899 libc.a
7900 $ @kbd{tar -c -f foo.tar --files-from list}
7901 @end group
7902 @end smallexample
7904 @noindent
7905 In this example, @command{tar} will first switch to @file{/etc}
7906 directory and add files @file{passwd} and @file{hosts} to the
7907 archive.  Then it will change to @file{/lib} directory and will archive
7908 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
7909 contain:
7911 @smallexample
7912 @group
7913 $ @kbd{tar tf foo.tar}
7914 passwd
7915 hosts
7916 libc.a
7917 @end group
7918 @end smallexample
7920 Note, that any options used in the file list remain in effect for the
7921 rest of the command line.  For example, using the same @file{list}
7922 file as above, the following command
7924 @smallexample
7925 $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
7926 @end smallexample
7928 @noindent
7929 will look for file @file{libcurses.a} in the directory @file{/lib},
7930 because it was used with the last @option{-C} option
7931 (@pxref{Position-Sensitive Options}).
7933 @anchor{verbatim-files-from}
7934 @opindex verbatim-files-from
7935 If such option handling is undesirable, use the
7936 @option{--verbatim-files-from} option.  When this option is in effect,
7937 each line read from the file list is treated as a file name.  Notice,
7938 that this means, in particular, that no whitespace trimming is
7939 performed.
7941 @anchor{no-verbatim-files-from}
7942 @opindex no-verbatim-files-from
7943 The @option{--verbatim-files-from} affects all @option{-T} options
7944 that follow it in the command line.  The default behavior can be
7945 restored using @option{--no-verbatim-files-from} option.
7947 @opindex add-file
7948 To disable option handling for a single file name, use the
7949 @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
7951 You can use any @GNUTAR{} command line options in the file list file,
7952 including @option{--files-from} option itself.  This allows for
7953 including contents of a file list into another file list file.
7954 Note however, that options that control file list processing, such as
7955 @option{--verbatim-files-from} or @option{--null} won't affect the
7956 file they appear in.  They will affect next @option{--files-from}
7957 option, if there is any.
7959 @menu
7960 * nul::
7961 @end menu
7963 @node nul
7964 @subsection @code{NUL}-Terminated File Names
7966 @cindex File names, terminated by @code{NUL}
7967 @cindex @code{NUL}-terminated file names
7968 The @option{--null} option causes
7969 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7970 to read file names terminated by a @code{NUL} instead of a newline, so
7971 files whose names contain newlines can be archived using
7972 @option{--files-from}.
7974 @table @option
7975 @xopindex{null, described}
7976 @item --null
7977 Only consider @code{NUL}-terminated file names, instead of files that
7978 terminate in a newline.
7980 @xopindex{no-null, described}
7981 @item --no-null
7982 Undo the effect of any previous @option{--null} option.
7983 @end table
7985 The @option{--null} option is just like the one in @acronym{GNU}
7986 @command{xargs} and @command{cpio}, and is useful with the
7987 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7988 @command{tar}, @option{--null} also disables special handling for
7989 file names that begin with dash (similar to
7990 @option{--verbatim-files-from} option).
7992 This example shows how to use @command{find} to generate a list of files
7993 larger than 800 blocks in length and put that list into a file called
7994 @file{long-files}.  The @option{-print0} option to @command{find} is just
7995 like @option{-print}, except that it separates files with a @code{NUL}
7996 rather than with a newline.  You can then run @command{tar} with both the
7997 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7998 files from that file, @file{long-files}, to create the archive
7999 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
8000 @command{tar} to recognize the @code{NUL} separator between files.
8002 @smallexample
8003 $ @kbd{find . -size +800 -print0 > long-files}
8004 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
8005 @end smallexample
8007 The @option{--no-null} option can be used if you need to read both
8008 @code{NUL}-terminated and newline-terminated files on the same command line.
8009 For example, if @file{flist} is a newline-terminated file, then the
8010 following command can be used to combine it with the above command:
8012 @smallexample
8013 @group
8014 $ @kbd{find . -size +800 -print0 |
8015   tar -c -f big.tar --null -T - --no-null -T flist}
8016 @end group
8017 @end smallexample
8019 This example uses short options for typographic reasons, to avoid
8020 very long lines.
8022 @GNUTAR{} is tries to automatically detect @code{NUL}-terminated file
8023 lists, so in many cases it is safe to use them even without the
8024 @option{--null} option.  In this case @command{tar} will print a
8025 warning and continue reading such a file as if @option{--null} were
8026 actually given:
8028 @smallexample
8029 @group
8030 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
8031 tar: -: file name read contains nul character
8032 @end group
8033 @end smallexample
8035 The null terminator, however, remains in effect only for this
8036 particular file, any following @option{-T} options will assume
8037 newline termination.  Of course, the null autodetection applies
8038 to these eventual surplus @option{-T} options as well.
8040 @node exclude
8041 @section Excluding Some Files
8043 @cindex File names, excluding files by
8044 @cindex Excluding files by name and pattern
8045 @cindex Excluding files by file system
8046 @opindex exclude
8047 @opindex exclude-from
8048 To avoid operating on files whose names match a particular pattern,
8049 use the @option{--exclude} or @option{--exclude-from} options.
8051 @table @option
8052 @opindex exclude
8053 @item --exclude=@var{pattern}
8054 Causes @command{tar} to ignore files that match the @var{pattern}.
8055 @end table
8057 @findex exclude
8058 The @option{--exclude=@var{pattern}} option prevents any file or
8059 member whose name matches the shell wildcard (@var{pattern}) from
8060 being operated on.
8061 For example, to create an archive with all the contents of the directory
8062 @file{src} except for files whose names end in @file{.o}, use the
8063 command @samp{tar -cf src.tar --exclude='*.o' src}.
8065 You may give multiple @option{--exclude} options.
8067 @table @option
8068 @opindex exclude-from
8069 @item --exclude-from=@var{file}
8070 @itemx -X @var{file}
8071 Causes @command{tar} to ignore files that match the patterns listed in
8072 @var{file}.
8073 @end table
8075 @findex exclude-from
8076 Use the @option{--exclude-from} option to read a
8077 list of patterns, one per line, from @var{file}; @command{tar} will
8078 ignore files matching those patterns.  Thus if @command{tar} is
8079 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
8080 single line @file{*.o}, no files whose names end in @file{.o} will be
8081 added to the archive.
8083 Notice, that lines from @var{file} are read verbatim. One of the
8084 frequent errors is leaving some extra whitespace after a file name,
8085 which is difficult to catch using text editors.
8087 However, empty lines are OK.
8089 @cindex VCS, excluding patterns from ignore files
8090 @cindex VCS, ignore files
8091 @cindex CVS, ignore files
8092 @cindex Git, ignore files
8093 @cindex Bazaar, ignore files
8094 @cindex Mercurial, ignore files
8095 When archiving directories that are under some version control system (VCS),
8096 it is often convenient to read exclusion patterns from this VCS'
8097 ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.)  The
8098 following options provide such possibility:
8100 @table @option
8101 @anchor{exclude-vcs-ignores}
8102 @opindex exclude-vcs-ignores
8103 @item --exclude-vcs-ignores
8104 Before archiving a directory, see if it contains any of the following
8105 files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
8106 @file{.hgignore}.  If so, read ignore patterns from these files.
8108 The patterns are treated much as the corresponding VCS would treat
8109 them, i.e.:
8111 @table @file
8112 @findex .cvsignore
8113 @item .cvsignore
8114 Contains shell-style globbing patterns that apply only to the
8115 directory where this file resides.  No comments are allowed in the
8116 file.  Empty lines are ignored.
8118 @findex .gitignore
8119 @item .gitignore
8120 Contains shell-style globbing patterns.  Applies to the directory
8121 where @file{.gitfile} is located and all its subdirectories.
8123 Any line beginning with a @samp{#} is a comment.  Backslash escapes
8124 the comment character.
8126 @findex .bzrignore
8127 @item .bzrignore
8128 Contains shell globbing-patterns and regular expressions (if prefixed
8129 with @samp{RE:}@footnote{According to the Bazaar docs,
8130 globbing-patterns are Korn-shell style and regular expressions are
8131 perl-style.  As of @GNUTAR{} version @value{VERSION}, these are
8132 treated as shell-style globs and POSIX extended regexps.  This will be
8133 fixed in future releases.}.  Patterns affect the directory and all its
8134 subdirectories.
8136 Any line beginning with a @samp{#} is a comment.
8138 @findex .hgignore
8139 @item .hgignore
8140 Contains POSIX regular expressions@footnote{Support for perl-style
8141 regexps will appear in future releases.}.  The line @samp{syntax:
8142 glob} switches to shell globbing patterns.  The line @samp{syntax:
8143 regexp} switches back.  Comments begin with a @samp{#}.  Patterns
8144 affect the directory and all its subdirectories.
8145 @end table
8147 @opindex exclude-ignore
8148 @item --exclude-ignore=@var{file}
8149 Before dumping a directory, @command{tar} checks if it contains
8150 @var{file}.  If so, exclusion patterns are read from this file.
8151 The patterns affect only the directory itself.
8153 @opindex exclude-ignore-recursive
8154 @item --exclude-ignore-recursive=@var{file}
8155 Same as @option{--exclude-ignore}, except that the patterns read
8156 affect both the directory where @var{file} resides and all its
8157 subdirectories.
8158 @end table
8160 @table @option
8161 @cindex version control system, excluding files
8162 @cindex VCS, excluding files
8163 @cindex SCCS, excluding files
8164 @cindex RCS, excluding files
8165 @cindex CVS, excluding files
8166 @cindex SVN, excluding files
8167 @cindex git, excluding files
8168 @cindex Bazaar, excluding files
8169 @cindex Arch, excluding files
8170 @cindex Mercurial, excluding files
8171 @cindex Darcs, excluding files
8172 @anchor{exclude-vcs}
8173 @opindex exclude-vcs
8174 @item --exclude-vcs
8175 Exclude files and directories used by following version control
8176 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
8177 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
8179 As of version @value{VERSION}, the following files are excluded:
8181 @itemize @bullet
8182 @item @file{CVS/}, and everything under it
8183 @item @file{RCS/}, and everything under it
8184 @item @file{SCCS/}, and everything under it
8185 @item @file{.git/}, and everything under it
8186 @item @file{.gitignore}
8187 @item @file{.gitmodules}
8188 @item @file{.gitattributes}
8189 @item @file{.cvsignore}
8190 @item @file{.svn/}, and everything under it
8191 @item @file{.arch-ids/}, and everything under it
8192 @item @file{@{arch@}/}, and everything under it
8193 @item @file{=RELEASE-ID}
8194 @item @file{=meta-update}
8195 @item @file{=update}
8196 @item @file{.bzr}
8197 @item @file{.bzrignore}
8198 @item @file{.bzrtags}
8199 @item @file{.hg}
8200 @item @file{.hgignore}
8201 @item @file{.hgrags}
8202 @item @file{_darcs}
8203 @end itemize
8205 @opindex exclude-backups
8206 @item --exclude-backups
8207 Exclude backup and lock files.  This option causes exclusion of files
8208 that match the following shell globbing patterns:
8210 @table @asis
8211 @item .#*
8212 @item *~
8213 @item #*#
8214 @end table
8216 @end table
8218 @findex exclude-caches
8219 When creating an archive, the @option{--exclude-caches} option family
8220 causes @command{tar} to exclude all directories that contain a @dfn{cache
8221 directory tag}. A cache directory tag is a regular file with the
8222 well-known name @file{CACHEDIR.TAG} whose first 43 octets
8223 consist of the following ASCII header string:
8225 @example
8226 Signature: 8a477f597d28d172789f06886806bc55
8227 @end example
8229 Any remaining bytes are not relevant, in particular the signature
8230 string does not have to be followed by an LF or CR/LF pair@footnote{The
8231 cache directory tagging specification is set forth in
8232 @url{https://bford.info/cachedir/}}.
8234 Various applications write cache directory tags into directories they
8235 use to hold regenerable, non-precious data, so that such data can be
8236 more easily excluded from backups.
8238 There are three @samp{exclude-caches} options, each providing a different
8239 exclusion semantics:
8241 @table @option
8242 @opindex exclude-caches
8243 @item --exclude-caches
8244 Do not archive the contents of the directory, but archive the
8245 directory itself and the @file{CACHEDIR.TAG} file.
8247 @opindex exclude-caches-under
8248 @item --exclude-caches-under
8249 Do not archive the contents of the directory, nor the
8250 @file{CACHEDIR.TAG} file, archive only the directory itself.
8252 @opindex exclude-caches-all
8253 @item --exclude-caches-all
8254 Omit directories containing @file{CACHEDIR.TAG} file entirely.
8255 @end table
8257 @findex exclude-tag
8258 Another option family, @option{--exclude-tag}, provides a generalization of
8259 this concept.  It takes a single argument, a file name to look for.
8260 Any directory that contains this file will be excluded from the dump.
8261 Similarly to @samp{exclude-caches}, there are three options in this
8262 option family:
8264 @table @option
8265 @opindex exclude-tag
8266 @item --exclude-tag=@var{file}
8267 Do not dump the contents of the directory, but dump the
8268 directory itself and the @var{file}.
8270 @opindex exclude-tag-under
8271 @item --exclude-tag-under=@var{file}
8272 Do not dump the contents of the directory, nor the
8273 @var{file}, archive only the directory itself.
8275 @opindex exclude-tag-all
8276 @item --exclude-tag-all=@var{file}
8277 Omit directories containing @var{file} file entirely.
8278 @end table
8280 Multiple @option{--exclude-tag*} options can be given.
8282 For example, given this directory:
8284 @smallexample
8285 @group
8286 $ @kbd{find dir}
8288 dir/blues
8289 dir/jazz
8290 dir/folk
8291 dir/folk/tagfile
8292 dir/folk/sanjuan
8293 dir/folk/trote
8294 @end group
8295 @end smallexample
8297 The @option{--exclude-tag} will produce the following:
8299 @smallexample
8300 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
8301 dir/
8302 dir/blues
8303 dir/jazz
8304 dir/folk/
8305 tar: dir/folk/: contains a cache directory tag tagfile;
8306   contents not dumped
8307 dir/folk/tagfile
8308 @end smallexample
8310 Both the @file{dir/folk} directory and its tagfile are preserved in
8311 the archive, however the rest of files in this directory are not.
8313 Now, using the @option{--exclude-tag-under} option will exclude
8314 @file{tagfile} from the dump, while still preserving the directory
8315 itself, as shown in this example:
8317 @smallexample
8318 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
8319 dir/
8320 dir/blues
8321 dir/jazz
8322 dir/folk/
8323 ./tar: dir/folk/: contains a cache directory tag tagfile;
8324   contents not dumped
8325 @end smallexample
8327 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
8328 directory entirely:
8330 @smallexample
8331 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
8332 dir/
8333 dir/blues
8334 dir/jazz
8335 ./tar: dir/folk/: contains a cache directory tag tagfile;
8336   directory not dumped
8337 @end smallexample
8339 @menu
8340 * problems with exclude::
8341 @end menu
8343 @node problems with exclude
8344 @unnumberedsubsec Problems with Using the @code{exclude} Options
8346 @xopindex{exclude, potential problems with}
8347 Some users find @samp{exclude} options confusing.  Here are some common
8348 pitfalls:
8350 @itemize @bullet
8351 @item
8352 The main operating mode of @command{tar} does not act on a file name
8353 explicitly listed on the command line, if one of its file name
8354 components is excluded.  In the example above, if
8355 you create an archive and exclude files that end with @samp{*.o}, but
8356 explicitly name the file @samp{dir.o/foo} after all the options have been
8357 listed, @samp{dir.o/foo} will be excluded from the archive.
8359 @item
8360 You can sometimes confuse the meanings of @option{--exclude} and
8361 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
8362 to be excluded are given as a pattern on the command line.  Use
8363 @option{--exclude-from} to introduce the name of a file which contains
8364 a list of patterns, one per line; each of these patterns can exclude
8365 zero, one, or many files.
8367 @item
8368 When you use @option{--exclude=@var{pattern}}, be sure to quote the
8369 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
8370 like @samp{*}.  If you do not do this, the shell might expand the
8371 @samp{*} itself using files at hand, so @command{tar} might receive a
8372 list of files instead of one pattern, or none at all, making the
8373 command somewhat illegal.  This might not correspond to what you want.
8375 For example, write:
8377 @smallexample
8378 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
8379 @end smallexample
8381 @noindent
8382 rather than:
8384 @smallexample
8385 # @emph{Wrong!}
8386 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
8387 @end smallexample
8389 @item
8390 You must use use shell syntax, or globbing, rather than @code{regexp}
8391 syntax, when using exclude options in @command{tar}.  If you try to use
8392 @code{regexp} syntax to describe files to be excluded, your command
8393 might fail.
8395 @item
8396 @FIXME{The change in semantics must have occurred before 1.11,
8397 so I doubt if it is worth mentioning at all. Anyway, should at
8398 least specify in which version the semantics changed.}
8399 In earlier versions of @command{tar}, what is now the
8400 @option{--exclude-from} option was called @option{--exclude} instead.
8401 Now, @option{--exclude} applies to patterns listed on the command
8402 line and @option{--exclude-from} applies to patterns listed in a
8403 file.
8405 @end itemize
8407 @node wildcards
8408 @section Wildcards Patterns and Matching
8410 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
8411 @samp{*} or @samp{?} for example, are replaced and expanded into all
8412 existing files matching the given pattern.  @GNUTAR{} can use wildcard
8413 patterns for matching (or globbing) archive members when extracting
8414 from or listing an archive.  Wildcard patterns are also used for
8415 verifying volume labels of @command{tar} archives.  This section has the
8416 purpose of explaining wildcard syntax for @command{tar}.
8418 @FIXME{the next few paragraphs need work.}
8420 A @var{pattern} should be written according to shell syntax, using wildcard
8421 characters to effect globbing.  Most characters in the pattern stand
8422 for themselves in the matched string, and case is significant: @samp{a}
8423 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
8424 pattern matches any single character in the matched string.  The character
8425 @samp{*} in the pattern matches zero, one, or more single characters in
8426 the matched string.  The character @samp{\} says to take the following
8427 character of the pattern @emph{literally}; it is useful when one needs to
8428 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
8430 The character @samp{[}, up to the matching @samp{]}, introduces a character
8431 class.  A @dfn{character class} is a list of acceptable characters
8432 for the next single character of the matched string.  For example,
8433 @samp{[abcde]} would match any of the first five letters of the alphabet.
8434 Note that within a character class, all of the ``special characters''
8435 listed above other than @samp{\} lose their special meaning; for example,
8436 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
8437 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
8438 the characters @samp{-} and @samp{]} must either come @emph{first} or
8439 @emph{last} in a character class.)
8441 @cindex Excluding characters from a character class
8442 @cindex Character class, excluding characters from
8443 If the first character of the class after the opening @samp{[}
8444 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
8445 Rather than listing character to match, it lists those characters which
8446 are @emph{forbidden} as the next single character of the matched string.
8448 Other characters of the class stand for themselves.  The special
8449 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
8450 letters, is meant to represent all characters between @var{a} and
8451 @var{e}, inclusive.
8453 @FIXME{need to add a sentence or so here to make this clear for those
8454 who don't have dan around.}
8456 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
8457 special for wildcard matches.  However, if a pattern completely matches
8458 a directory prefix of a matched string, then it matches the full matched
8459 string: thus, excluding a directory also excludes all the files beneath it.
8461 @menu
8462 * controlling pattern-matching::
8463 @end menu
8465 @node controlling pattern-matching
8466 @unnumberedsubsec Controlling Pattern-Matching
8468 For the purposes of this section, we call @dfn{exclusion members} all
8469 member names obtained while processing @option{--exclude} and
8470 @option{--exclude-from} options, and @dfn{inclusion members} those
8471 member names that were given in the command line or read from the file
8472 specified with @option{--files-from} option.
8474 These two pairs of member lists are used in the following operations:
8475 @option{--diff}, @option{--extract}, @option{--list},
8476 @option{--update}.
8478 There are no inclusion members in create mode (@option{--create} and
8479 @option{--append}), since in this mode the names obtained from the
8480 command line refer to @emph{files}, not archive members.
8482 By default, inclusion members are compared with archive members
8483 literally @footnote{Notice that earlier @GNUTAR{} versions used
8484 globbing for inclusion members, which contradicted to UNIX98
8485 specification and was not documented. @xref{Changes}, for more
8486 information on this and other changes.} and exclusion members are
8487 treated as globbing patterns.  For example:
8489 @smallexample
8490 @group
8491 $ @kbd{tar tf foo.tar}
8494 a.txt
8495 [remarks]
8496 # @i{Member names are used verbatim:}
8497 $ @kbd{tar -xf foo.tar -v '[remarks]'}
8498 [remarks]
8499 # @i{Exclude member names are globbed:}
8500 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
8501 a.txt
8502 [remarks]
8503 @end group
8504 @end smallexample
8506 This behavior can be altered by using the following options:
8508 @table @option
8509 @opindex wildcards
8510 @item --wildcards
8511 Treat all member names as wildcards.
8513 @opindex no-wildcards
8514 @item --no-wildcards
8515 Treat all member names as literal strings.
8516 @end table
8518 Thus, to extract files whose names end in @samp{.c}, you can use:
8520 @smallexample
8521 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
8524 @end smallexample
8526 @noindent
8527 Notice quoting of the pattern to prevent the shell from interpreting
8530 The effect of @option{--wildcards} option is canceled by
8531 @option{--no-wildcards}.  This can be used to pass part of
8532 the command line arguments verbatim and other part as globbing
8533 patterns.  For example, the following invocation:
8535 @smallexample
8536 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
8537 @end smallexample
8539 @noindent
8540 instructs @command{tar} to extract from @file{foo.tar} all files whose
8541 names end in @samp{.txt} and the file named @file{[remarks]}.
8543 Normally, a pattern matches a name if an initial subsequence of the
8544 name's components matches the pattern, where @samp{*}, @samp{?}, and
8545 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
8546 and wildcards can match @samp{/}.
8548 Other than optionally stripping leading @samp{/} from names
8549 (@pxref{absolute}), patterns and names are used as-is.  For
8550 example, trailing @samp{/} is not trimmed from a user-specified name
8551 before deciding whether to exclude it.
8553 However, this matching procedure can be altered by the options listed
8554 below.  These options accumulate.  For example:
8556 @smallexample
8557 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
8558 @end smallexample
8560 @noindent
8561 ignores case when excluding @samp{makefile}, but not when excluding
8562 @samp{readme}.
8564 @table @option
8565 @anchor{anchored patterns}
8566 @opindex anchored
8567 @opindex no-anchored
8568 @item --anchored
8569 @itemx --no-anchored
8570 If anchored, a pattern must match an initial subsequence
8571 of the name's components.  Otherwise, the pattern can match any
8572 subsequence.  Default is @option{--no-anchored} for exclusion members
8573 and @option{--anchored} inclusion members.
8575 @anchor{case-insensitive matches}
8576 @opindex ignore-case
8577 @opindex no-ignore-case
8578 @item --ignore-case
8579 @itemx --no-ignore-case
8580 When ignoring case, upper-case patterns match lower-case names and vice versa.
8581 When not ignoring case (the default), matching is case-sensitive.
8583 @opindex wildcards-match-slash
8584 @opindex no-wildcards-match-slash
8585 @item --wildcards-match-slash
8586 @itemx --no-wildcards-match-slash
8587 When wildcards match slash (the default for exclusion members), a
8588 wildcard like @samp{*} in the pattern can match a @samp{/} in the
8589 name.  Otherwise, @samp{/} is matched only by @samp{/}.
8591 @end table
8593 The @option{--recursion} and @option{--no-recursion} options
8594 (@pxref{recurse}) also affect how member patterns are interpreted.  If
8595 recursion is in effect, a pattern matches a name if it matches any of
8596 the name's parent directories.
8598 The following table summarizes pattern-matching default values:
8600 @multitable @columnfractions .3 .7
8601 @headitem Members @tab Default settings
8602 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
8603 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
8604 @end multitable
8606 @node quoting styles
8607 @section Quoting Member Names
8609 When displaying member names, @command{tar} takes care to avoid
8610 ambiguities caused by certain characters.  This is called @dfn{name
8611 quoting}.  The characters in question are:
8613 @itemize @bullet
8614 @item Non-printable control characters:
8615 @anchor{escape sequences}
8616 @multitable @columnfractions 0.20 0.10 0.60
8617 @headitem Character @tab @acronym{ASCII} @tab Character name
8618 @item \a @tab 7  @tab Audible bell
8619 @item \b @tab 8  @tab Backspace
8620 @item \f @tab 12 @tab Form feed
8621 @item \n @tab 10 @tab New line
8622 @item \r @tab 13 @tab Carriage return
8623 @item \t @tab 9  @tab Horizontal tabulation
8624 @item \v @tab 11 @tab Vertical tabulation
8625 @end multitable
8627 @item Space (@acronym{ASCII} 32)
8629 @item Single and double quotes (@samp{'} and @samp{"})
8631 @item Backslash (@samp{\})
8632 @end itemize
8634 The exact way @command{tar} uses to quote these characters depends on
8635 the @dfn{quoting style}.  The default quoting style, called
8636 @dfn{escape} (see below), uses backslash notation to represent control
8637 characters and backslash.
8639 @GNUTAR{} offers seven distinct quoting styles, which can be selected
8640 using @option{--quoting-style} option:
8642 @table @option
8643 @item --quoting-style=@var{style}
8644 @opindex quoting-style
8646 Sets quoting style.  Valid values for @var{style} argument are:
8647 literal, shell, shell-always, c, escape, locale, clocale.
8648 @end table
8650 These styles are described in detail below.  To illustrate their
8651 effect, we will use an imaginary tar archive @file{arch.tar}
8652 containing the following members:
8654 @smallexample
8655 @group
8656 # 1. Contains horizontal tabulation character.
8657 a       tab
8658 # 2. Contains newline character
8660 newline
8661 # 3. Contains a space
8662 a space
8663 # 4. Contains double quotes
8664 a"double"quote
8665 # 5. Contains single quotes
8666 a'single'quote
8667 # 6. Contains a backslash character:
8668 a\backslash
8669 @end group
8670 @end smallexample
8672 Here is how usual @command{ls} command would have listed them, if they
8673 had existed in the current working directory:
8675 @smallexample
8676 @group
8677 $ @kbd{ls}
8678 a\ttab
8679 a\nnewline
8680 a\ space
8681 a"double"quote
8682 a'single'quote
8683 a\\backslash
8684 @end group
8685 @end smallexample
8687 Quoting styles:
8689 @table @samp
8690 @item literal
8691 No quoting, display each character as is:
8693 @smallexample
8694 @group
8695 $ @kbd{tar tf arch.tar --quoting-style=literal}
8697 ./a space
8698 ./a'single'quote
8699 ./a"double"quote
8700 ./a\backslash
8701 ./a     tab
8703 newline
8704 @end group
8705 @end smallexample
8707 @item shell
8708 Display characters the same way Bourne shell does:
8709 control characters, except @samp{\t} and @samp{\n}, are printed using
8710 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
8711 single quote is printed as @samp{\'}.  If a name contains any quoted
8712 characters, it is enclosed in single quotes.  In particular, if a name
8713 contains single quotes, it is printed as several single-quoted strings:
8715 @smallexample
8716 @group
8717 $ @kbd{tar tf arch.tar --quoting-style=shell}
8719 './a space'
8720 './a'\''single'\''quote'
8721 './a"double"quote'
8722 './a\backslash'
8723 './a    tab'
8724 './a
8725 newline'
8726 @end group
8727 @end smallexample
8729 @item shell-always
8730 Same as @samp{shell}, but the names are always enclosed in single
8731 quotes:
8733 @smallexample
8734 @group
8735 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
8736 './'
8737 './a space'
8738 './a'\''single'\''quote'
8739 './a"double"quote'
8740 './a\backslash'
8741 './a    tab'
8742 './a
8743 newline'
8744 @end group
8745 @end smallexample
8747 @item c
8748 Use the notation of the C programming language.  All names are
8749 enclosed in double quotes.  Control characters are quoted using
8750 backslash notations, double quotes are represented as @samp{\"},
8751 backslash characters are represented as @samp{\\}.  Single quotes and
8752 spaces are not quoted:
8754 @smallexample
8755 @group
8756 $ @kbd{tar tf arch.tar --quoting-style=c}
8757 "./"
8758 "./a space"
8759 "./a'single'quote"
8760 "./a\"double\"quote"
8761 "./a\\backslash"
8762 "./a\ttab"
8763 "./a\nnewline"
8764 @end group
8765 @end smallexample
8767 @item escape
8768 Control characters are printed using backslash notation, and a
8769 backslash as @samp{\\}.  This is the default quoting style, unless it
8770 was changed when configured the package.
8772 @smallexample
8773 @group
8774 $ @kbd{tar tf arch.tar --quoting-style=escape}
8776 ./a space
8777 ./a'single'quote
8778 ./a"double"quote
8779 ./a\\backslash
8780 ./a\ttab
8781 ./a\nnewline
8782 @end group
8783 @end smallexample
8785 @item locale
8786 Control characters, single quote and backslash are printed using
8787 backslash notation.  All names are quoted using left and right
8788 quotation marks, appropriate to the current locale.  If it does not
8789 define quotation marks, use @samp{'} as left and as right
8790 quotation marks.  Any occurrences of the right quotation mark in a
8791 name are escaped with @samp{\}, for example:
8793 For example:
8795 @smallexample
8796 @group
8797 $ @kbd{tar tf arch.tar --quoting-style=locale}
8798 './'
8799 './a space'
8800 './a\'single\'quote'
8801 './a"double"quote'
8802 './a\\backslash'
8803 './a\ttab'
8804 './a\nnewline'
8805 @end group
8806 @end smallexample
8808 @item clocale
8809 Same as @samp{locale}, but @samp{"} is used for both left and right
8810 quotation marks, if not provided by the currently selected locale:
8812 @smallexample
8813 @group
8814 $ @kbd{tar tf arch.tar --quoting-style=clocale}
8815 "./"
8816 "./a space"
8817 "./a'single'quote"
8818 "./a\"double\"quote"
8819 "./a\\backslash"
8820 "./a\ttab"
8821 "./a\nnewline"
8822 @end group
8823 @end smallexample
8824 @end table
8826 You can specify which characters should be quoted in addition to those
8827 implied by the current quoting style:
8829 @table @option
8830 @item --quote-chars=@var{string}
8831 Always quote characters from @var{string}, even if the selected
8832 quoting style would not quote them.
8833 @end table
8835 For example, using @samp{escape} quoting (compare with the usual
8836 escape listing above):
8838 @smallexample
8839 @group
8840 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
8842 ./a\ space
8843 ./a'single'quote
8844 ./a\"double\"quote
8845 ./a\\backslash
8846 ./a\ttab
8847 ./a\nnewline
8848 @end group
8849 @end smallexample
8851 To disable quoting of such additional characters, use the following
8852 option:
8854 @table @option
8855 @item --no-quote-chars=@var{string}
8856 Remove characters listed in @var{string} from the list of quoted
8857 characters set by the previous @option{--quote-chars} option.
8858 @end table
8860 This option is particularly useful if you have added
8861 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
8862 and wish to disable it for the current invocation.
8864 Note, that @option{--no-quote-chars} does @emph{not} disable those
8865 characters that are quoted by default in the selected quoting style.
8867 @node transform
8868 @section Modifying File and Member Names
8870 @command{Tar} archives contain detailed information about files stored
8871 in them and full file names are part of that information.  When
8872 storing a file to an archive, its file name is recorded in it,
8873 along with the actual file contents.  When restoring from an archive,
8874 a file is created on disk with exactly the same name as that stored
8875 in the archive.  In the majority of cases this is the desired behavior
8876 of a file archiver.  However, there are some cases when it is not.
8878 First of all, it is often unsafe to extract archive members with
8879 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
8880 takes special precautions when extracting such names and provides a
8881 special option for handling them, which is described in
8882 @ref{absolute}.
8884 Secondly, you may wish to extract file names without some leading
8885 directory components, or with otherwise modified names.  In other
8886 cases it is desirable to store files under differing names in the
8887 archive.
8889 @GNUTAR{} provides several options for these needs.
8891 @table @option
8892 @opindex strip-components
8893 @item --strip-components=@var{number}
8894 Strip given @var{number} of leading components from file names before
8895 extraction.
8896 @end table
8898 For example, suppose you have archived whole @file{/usr} hierarchy to
8899 a tar archive named @file{usr.tar}.  Among other files, this archive
8900 contains @file{usr/include/stdlib.h}, which you wish to extract to
8901 the current working directory.  To do so, you type:
8903 @smallexample
8904 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8905 @end smallexample
8907 The option @option{--strip=2} instructs @command{tar} to strip the
8908 two leading components (@file{usr/} and @file{include/}) off the file
8909 name.
8911 If you add the @option{--verbose} (@option{-v}) option to the invocation
8912 above, you will note that the verbose listing still contains the
8913 full file name, with the two removed components still in place.  This
8914 can be inconvenient, so @command{tar} provides a special option for
8915 altering this behavior:
8917 @anchor{show-transformed-names}
8918 @table @option
8919 @opindex show-transformed-names
8920 @item --show-transformed-names
8921 Display file or member names with all requested transformations
8922 applied.
8923 @end table
8925 @noindent
8926 For example:
8928 @smallexample
8929 @group
8930 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8931 usr/include/stdlib.h
8932 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8933 stdlib.h
8934 @end group
8935 @end smallexample
8937 Notice that in both cases the file @file{stdlib.h} is extracted to the
8938 current working directory, @option{--show-transformed-names} affects
8939 only the way its name is displayed.
8941 This option is especially useful for verifying whether the invocation
8942 will have the desired effect.  Thus, before running
8944 @smallexample
8945 $ @kbd{tar -x --strip=@var{n}}
8946 @end smallexample
8948 @noindent
8949 it is often advisable to run
8951 @smallexample
8952 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8953 @end smallexample
8955 @noindent
8956 to make sure the command will produce the intended results.
8958 In case you need to apply more complex modifications to the file name,
8959 @GNUTAR{} provides a general-purpose transformation option:
8961 @table @option
8962 @opindex transform
8963 @opindex xform
8964 @item --transform=@var{expression}
8965 @itemx --xform=@var{expression}
8966 Modify file names using supplied @var{expression}.
8967 @end table
8969 @noindent
8970 The @var{expression} is a @command{sed}-like replace expression of the
8971 form:
8973 @smallexample
8974 s/@var{regexp}/@var{replace}/[@var{flags}]
8975 @end smallexample
8977 @noindent
8978 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8979 replacement for each file name part that matches @var{regexp}.  Both
8980 @var{regexp} and @var{replace} are described in detail in
8981 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8983 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8984 that it be used consistently throughout the expression. For example,
8985 the following two expressions are equivalent:
8987 @smallexample
8988 @group
8989 s/one/two/
8990 s,one,two,
8991 @end group
8992 @end smallexample
8994 Changing delimiters is often useful when the @var{regex} contains
8995 slashes.  For example, it is more convenient to write @code{s,/,-,} than
8996 @code{s/\//-/}.
8998 As in @command{sed}, you can give several replace expressions,
8999 separated by a semicolon.
9001 Supported @var{flags} are:
9003 @table @samp
9004 @item g
9005 Apply the replacement to @emph{all} matches to the @var{regexp}, not
9006 just the first.
9008 @item i
9009 Use case-insensitive matching.
9011 @item x
9012 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
9013 regexps, Extended regular expressions, Extended regular expressions,
9014 sed, GNU sed}).
9016 @item @var{number}
9017 Only replace the @var{number}th match of the @var{regexp}.
9019 Note: the @acronym{POSIX} standard does not specify what should happen
9020 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
9021 follows the GNU @command{sed} implementation in this regard, so
9022 the interaction is defined to be: ignore matches before the
9023 @var{number}th, and then match and replace all matches from the
9024 @var{number}th on.
9026 @end table
9028 In addition, several @dfn{transformation scope} flags are supported,
9029 that control to what files transformations apply.  These are:
9031 @table @samp
9032 @item r
9033 Apply transformation to regular archive members.
9035 @item R
9036 Do not apply transformation to regular archive members.
9038 @item s
9039 Apply transformation to symbolic link targets.
9041 @item S
9042 Do not apply transformation to symbolic link targets.
9044 @item h
9045 Apply transformation to hard link targets.
9047 @item H
9048 Do not apply transformation to hard link targets.
9049 @end table
9051 Default is @samp{rsh}, which means to apply transformations to both archive
9052 members and targets of symbolic and hard links.
9054 Default scope flags can also be changed using @samp{flags=} statement
9055 in the transform expression.  The flags set this way remain in force
9056 until next @samp{flags=} statement or end of expression, whichever
9057 occurs first.  For example:
9059 @smallexample
9060   --transform 'flags=S;s|^|/usr/local/|'
9061 @end smallexample
9063 Here are several examples of @option{--transform} usage:
9065 @enumerate
9066 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
9068 @smallexample
9069 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
9070 @end smallexample
9072 @item Strip two leading directory components (equivalent to
9073 @option{--strip-components=2}):
9075 @smallexample
9076 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
9077 @end smallexample
9079 @item Convert each file name to lower case:
9081 @smallexample
9082 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
9083 @end smallexample
9085 @item Prepend @file{/prefix/}  to each file name:
9087 @smallexample
9088 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
9089 @end smallexample
9091 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
9092 to each archive member:
9094 @smallexample
9095 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
9096 @end smallexample
9097 @end enumerate
9099 Notice the use of flags in the last example.  The @file{/lib}
9100 directory often contains many symbolic links to files within it.
9101 It may look, for example, like this:
9103 @smallexample
9104 $ @kbd{ls -l}
9105 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
9106 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
9107 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
9109 @end smallexample
9111 Using the expression @samp{s,^,/usr/local/,} would mean adding
9112 @samp{/usr/local} to both regular archive members and to link
9113 targets. In this case, @file{/lib/libc.so.6} would become:
9115 @smallexample
9116   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
9117 @end smallexample
9119 This is definitely not desired.  To avoid this, the @samp{S} flag
9120 is used, which excludes symbolic link targets from filename
9121 transformations.  The result is:
9123 @smallexample
9124 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
9125        --show-transformed /lib}
9126 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
9127 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
9128 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
9129  -> libc-2.3.2.so
9130 @end smallexample
9132 Unlike @option{--strip-components}, @option{--transform} can be used
9133 in any @GNUTAR{} operation mode.  For example, the following command
9134 adds files to the archive while replacing the leading @file{usr/}
9135 component with @file{var/}:
9137 @smallexample
9138 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
9139 @end smallexample
9141 To test @option{--transform} effect we suggest using
9142 @option{--show-transformed-names} option:
9144 @smallexample
9145 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
9146        --verbose --show-transformed-names /}
9147 @end smallexample
9149 If both @option{--strip-components} and @option{--transform} are used
9150 together, then @option{--transform} is applied first, and the required
9151 number of components is then stripped from its result.
9153 You can use as many @option{--transform} options in a single command
9154 line as you want.  The specified expressions will then be applied in
9155 order of their appearance.  For example, the following two invocations
9156 are equivalent:
9158 @smallexample
9159 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
9160                         --transform='s,/usr/local,/usr/,'}
9161 $ @kbd{tar -cf arch.tar \
9162                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
9163 @end smallexample
9165 @node after
9166 @section Operating Only on New Files
9168 @cindex Excluding file by age
9169 @cindex Data Modification time, excluding files by
9170 @cindex Modification time, excluding files by
9171 @cindex Age, excluding files by
9172 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
9173 @option{-N @var{date}}) option causes @command{tar} to only work on
9174 files whose data modification or status change times are newer than
9175 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
9176 it is taken to be a file name; the data modification time of that file
9177 is used as the date. If you use this option when creating or appending
9178 to an archive, the archive will only include new files.  If you use
9179 @option{--after-date} when extracting an archive, @command{tar} will
9180 only extract files newer than the @var{date} you specify.
9182 If you want @command{tar} to make the date comparison based only on
9183 modification of the file's data (rather than status
9184 changes), then use the @option{--newer-mtime=@var{date}} option.
9186 @cindex --after-date and --update compared
9187 @cindex --newer-mtime and --update compared
9188 You may use these options with any operation.  Note that these options
9189 differ from the @option{--update} (@option{-u}) operation in that they
9190 allow you to specify a particular date against which @command{tar} can
9191 compare when deciding whether or not to archive the files.
9193 @table @option
9194 @opindex after-date
9195 @opindex newer
9196 @item --after-date=@var{date}
9197 @itemx --newer=@var{date}
9198 @itemx -N @var{date}
9199 Only store files newer than @var{date}.
9201 Acts on files only if their data modification or status change times are
9202 later than @var{date}.  Use in conjunction with any operation.
9204 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
9205 name; the data modification time of that file is used as the date.
9207 @opindex newer-mtime
9208 @item --newer-mtime=@var{date}
9209 Act like @option{--after-date}, but look only at data modification times.
9210 @end table
9212 These options limit @command{tar} to operate only on files which have
9213 been modified after the date specified.  A file's status is considered to have
9214 changed if its contents have been modified, or if its owner,
9215 permissions, and so forth, have been changed.  (For more information on
9216 how to specify a date, see @ref{Date input formats}; remember that the
9217 entire date argument must be quoted if it contains any spaces.)
9219 Gurus would say that @option{--after-date} tests both the data
9220 modification time (@code{mtime}, the time the contents of the file
9221 were last modified) and the status change time (@code{ctime}, the time
9222 the file's status was last changed: owner, permissions, etc.@:)
9223 fields, while @option{--newer-mtime} tests only the @code{mtime}
9224 field.
9226 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
9227 @code{ctime} and processes the file if either one is more recent than
9228 @var{date}, while @option{--newer-mtime} checks only @code{mtime} and
9229 disregards @code{ctime}.  Neither option uses @code{atime} (the last time the
9230 contents of the file were looked at).
9232 Date specifiers can have embedded spaces.  Because of this, you may need
9233 to quote date arguments to keep the shell from parsing them as separate
9234 arguments.  For example, the following command will add to the archive
9235 all the files modified less than two days ago:
9237 @smallexample
9238 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
9239 @end smallexample
9241 When any of these options is used with the option @option{--verbose}
9242 (@pxref{verbose tutorial}) @GNUTAR{} converts the specified
9243 date back to a textual form and compares that with the
9244 one given with the option.  If the two forms differ, @command{tar}
9245 prints both forms in a message, to help the user check that the right
9246 date is being used.  For example:
9248 @smallexample
9249 @group
9250 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
9251 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
9252 13:19:37.232434
9253 @end group
9254 @end smallexample
9256 @quotation
9257 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
9258 should not be used for incremental backups.  @xref{Incremental Dumps},
9259 for proper way of creating incremental backups.
9260 @end quotation
9262 @node recurse
9263 @section Descending into Directories
9264 @cindex Avoiding recursion in directories
9265 @cindex Descending directories, avoiding
9266 @cindex Directories, avoiding recursion
9267 @cindex Recursion in directories, avoiding
9269 Usually, @command{tar} will recursively explore all directories (either
9270 those given on the command line or through the @option{--files-from}
9271 option) for the various files they contain.  However, you may not always
9272 want @command{tar} to act this way.
9274 @opindex no-recursion
9275 @cindex @command{find}, using with @command{tar}
9276 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
9277 into specified directories.  If you specify @option{--no-recursion}, you can
9278 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
9279 utility for hunting through levels of directories to
9280 construct a list of file names which you could then pass to @command{tar}.
9281 @command{find} allows you to be more selective when choosing which files to
9282 archive; see @ref{files}, for more information on using @command{find} with
9283 @command{tar}.
9285 @table @option
9286 @item --no-recursion
9287 Prevents @command{tar} from recursively descending directories.
9289 @opindex recursion
9290 @item --recursion
9291 Requires @command{tar} to recursively descend directories.
9292 This is the default.
9293 @end table
9295 When you use @option{--no-recursion}, @GNUTAR{} grabs
9296 directory entries themselves, but does not descend on them
9297 recursively.  Many people use @command{find} for locating files they
9298 want to back up, and since @command{tar} @emph{usually} recursively
9299 descends on directories, they have to use the @samp{@w{-not -type d}}
9300 test in their @command{find} invocation (@pxref{Type, Type, Type test,
9301 find, Finding Files}), as they usually do not want all the files in a
9302 directory. They then use the @option{--files-from} option to archive
9303 the files located via @command{find}.
9305 The problem when restoring files archived in this manner is that the
9306 directories themselves are not in the archive; so the
9307 @option{--same-permissions} (@option{--preserve-permissions},
9308 @option{-p}) option does not affect them---while users might really
9309 like it to.  Specifying @option{--no-recursion} is a way to tell
9310 @command{tar} to grab only the directory entries given to it, adding
9311 no new files on its own.  To summarize, if you use @command{find} to
9312 create a list of files to be stored in an archive, use it as follows:
9314 @smallexample
9315 @group
9316 $ @kbd{find @var{dir} @var{tests} | \
9317   tar -cf @var{archive} --no-recursion -T -}
9318 @end group
9319 @end smallexample
9321 The @option{--no-recursion} option also applies when extracting: it
9322 causes @command{tar} to extract only the matched directory entries, not
9323 the files under those directories.
9325 The @option{--no-recursion} option also affects how globbing patterns
9326 are interpreted (@pxref{controlling pattern-matching}).
9328 The @option{--no-recursion} and @option{--recursion} options apply to
9329 later options and operands, and can be overridden by later occurrences
9330 of @option{--no-recursion} and @option{--recursion}.  For example:
9332 @smallexample
9333 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
9334 @end smallexample
9336 @noindent
9337 creates an archive with one entry for @file{grape}, and the recursive
9338 contents of @file{grape/concord}, but no entries under @file{grape}
9339 other than @file{grape/concord}.
9341 @node one
9342 @section Crossing File System Boundaries
9343 @cindex File system boundaries, not crossing
9345 @command{tar} will normally automatically cross file system boundaries in
9346 order to archive files which are part of a directory tree.  You can
9347 change this behavior by running @command{tar} and specifying
9348 @option{--one-file-system}.  This option only affects files that are
9349 archived because they are in a directory that is being archived;
9350 @command{tar} will still archive files explicitly named on the command line
9351 or through @option{--files-from}, regardless of where they reside.
9353 @table @option
9354 @opindex one-file-system
9355 @item --one-file-system
9356 Prevents @command{tar} from crossing file system boundaries when
9357 archiving.  Use in conjunction with any write operation.
9358 @end table
9360 The @option{--one-file-system} option causes @command{tar} to modify its
9361 normal behavior in archiving the contents of directories.  If a file in
9362 a directory is not on the same file system as the directory itself, then
9363 @command{tar} will not archive that file.  If the file is a directory
9364 itself, @command{tar} will not archive anything beneath it; in other words,
9365 @command{tar} will not cross mount points.
9367 This option is useful for making full or incremental archival backups of
9368 a file system.  If this option is used in conjunction with
9369 @option{--verbose} (@option{-v}), files that are excluded are
9370 mentioned by name on the standard error.
9372 @menu
9373 * directory::                   Changing Directory
9374 * absolute::                    Absolute File Names
9375 @end menu
9377 @node directory
9378 @subsection Changing the Working Directory
9380 @FIXME{need to read over this node now for continuity; i've switched
9381 things around some.}
9383 @cindex Changing directory mid-stream
9384 @cindex Directory, changing mid-stream
9385 @cindex Working directory, specifying
9386 To change the working directory in the middle of a list of file names,
9387 either on the command line or in a file specified using
9388 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
9389 This will change the working directory to the specified directory
9390 after that point in the list.
9392 @table @option
9393 @opindex directory
9394 @item --directory=@var{directory}
9395 @itemx -C @var{directory}
9396 Changes the working directory in the middle of a command line.
9397 @end table
9399 For example,
9401 @smallexample
9402 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
9403 @end smallexample
9405 @noindent
9406 will place the files @file{grape} and @file{prune} from the current
9407 directory into the archive @file{jams.tar}, followed by the file
9408 @file{cherry} from the directory @file{food}.  This option is especially
9409 useful when you have several widely separated files that you want to
9410 store in the same archive.
9412 Note that the file @file{cherry} is recorded in the archive under the
9413 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
9414 archive will contain three files that all appear to have come from the
9415 same directory; if the archive is extracted with plain @samp{tar
9416 --extract}, all three files will be written in the current directory.
9418 Contrast this with the command,
9420 @smallexample
9421 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
9422 @end smallexample
9424 @noindent
9425 which records the third file in the archive under the name
9426 @file{red/cherry} so that, if the archive is extracted using
9427 @samp{tar --extract}, the third file will be written in a subdirectory
9428 named @file{red}.
9430 You can use the @option{--directory} option to make the archive
9431 independent of the original name of the directory holding the files.
9432 The following command places the files @file{/etc/passwd},
9433 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
9434 @file{foo.tar}:
9436 @smallexample
9437 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
9438 @end smallexample
9440 @noindent
9441 However, the names of the archive members will be exactly what they were
9442 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
9443 They will not appear to be related by file name to the original
9444 directories where those files were located.
9446 Note that @option{--directory} options are interpreted consecutively.  If
9447 @option{--directory} specifies a relative file name, it is interpreted
9448 relative to the then current directory, which might not be the same as
9449 the original current working directory of @command{tar}, due to a previous
9450 @option{--directory} option.
9452 When using @option{--files-from} (@pxref{files}), you can put various
9453 @command{tar} options (including @option{-C}) in the file list.  Notice,
9454 however, that in this case the option and its argument may not be
9455 separated by whitespace.  If you use short option, its argument must
9456 either follow the option letter immediately, without any intervening
9457 whitespace, or occupy the next line.  Otherwise, if you use long
9458 option, separate its argument by an equal sign.
9460 For instance, the file list for the above example will be:
9462 @smallexample
9463 @group
9464 -C/etc
9465 passwd
9466 hosts
9467 --directory=/lib
9468 libc.a
9469 @end group
9470 @end smallexample
9472 @noindent
9473 To use it, you would invoke @command{tar} as follows:
9475 @smallexample
9476 $ @kbd{tar -c -f foo.tar --files-from list}
9477 @end smallexample
9479 The interpretation of options in file lists is disabled by
9480 @option{--verbatim-files-from} and @option{--null} options.
9482 @node absolute
9483 @subsection Absolute File Names
9484 @cindex absolute file names
9485 @cindex file names, absolute
9487 By default, @GNUTAR{} drops a leading @samp{/} on
9488 input or output, and complains about file names containing a @file{..}
9489 component.  There is an option that turns off this behavior:
9491 @table @option
9492 @opindex absolute-names
9493 @item --absolute-names
9494 @itemx -P
9495 Do not strip leading slashes from file names, and permit file names
9496 containing a @file{..} file name component.
9497 @end table
9499 When @command{tar} extracts archive members from an archive, it strips any
9500 leading slashes (@samp{/}) from the member name.  This causes absolute
9501 member names in the archive to be treated as relative file names.  This
9502 allows you to have such members extracted wherever you want, instead of
9503 being restricted to extracting the member in the exact directory named
9504 in the archive.  For example, if the archive member has the name
9505 @file{/etc/passwd}, @command{tar} will extract it as if the name were
9506 really @file{etc/passwd}.
9508 File names containing @file{..} can cause problems when extracting, so
9509 @command{tar} normally warns you about such files when creating an
9510 archive, and rejects attempts to extracts such files.
9512 Other @command{tar} programs do not do this.  As a result, if you
9513 create an archive whose member names start with a slash, they will be
9514 difficult for other people with a non-@GNUTAR{}
9515 program to use.  Therefore, @GNUTAR{} also strips
9516 leading slashes from member names when putting members into the
9517 archive.  For example, if you ask @command{tar} to add the file
9518 @file{/bin/ls} to an archive, it will do so, but the member name will
9519 be @file{bin/ls}@footnote{A side effect of this is that when
9520 @option{--create} is used with @option{--verbose} the resulting output
9521 is not, generally speaking, the same as the one you'd get running
9522 @kbd{tar --list} command.  This may be important if you use some
9523 scripts for comparing both outputs.  @xref{listing member and file names},
9524 for the information on how to handle this case.}.
9526 Symbolic links containing @file{..} or leading @samp{/} can also cause
9527 problems when extracting, so @command{tar} normally extracts them last;
9528 it may create empty files as placeholders during extraction.
9530 If you use the @option{--absolute-names} (@option{-P}) option,
9531 @command{tar} will do none of these transformations.
9533 To archive or extract files relative to the root directory, specify
9534 the @option{--absolute-names} (@option{-P}) option.
9536 Normally, @command{tar} acts on files relative to the working
9537 directory---ignoring superior directory names when archiving, and
9538 ignoring leading slashes when extracting.
9540 When you specify @option{--absolute-names} (@option{-P}),
9541 @command{tar} stores file names including all superior directory
9542 names, and preserves leading slashes.  If you only invoked
9543 @command{tar} from the root directory you would never need the
9544 @option{--absolute-names} option, but using this option
9545 may be more convenient than switching to root.
9547 @FIXME{Should be an example in the tutorial/wizardry section using this
9548 to transfer files between systems.}
9550 @table @option
9551 @item --absolute-names
9552 Preserves full file names (including superior directory names) when
9553 archiving and extracting files.
9555 @end table
9557 @command{tar} prints out a message about removing the @samp{/} from
9558 file names.  This message appears once per @GNUTAR{}
9559 invocation.  It represents something which ought to be told; ignoring
9560 what it means can cause very serious surprises, later.
9562 Some people, nevertheless, do not want to see this message.  Wanting to
9563 play really dangerously, one may of course redirect @command{tar} standard
9564 error to the sink.  For example, under @command{sh}:
9566 @smallexample
9567 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
9568 @end smallexample
9570 @noindent
9571 Another solution, both nicer and simpler, would be to change to
9572 the @file{/} directory first, and then avoid absolute notation.
9573 For example:
9575 @smallexample
9576 $ @kbd{tar -c -f archive.tar -C / home}
9577 @end smallexample
9579 @xref{Integrity}, for some of the security-related implications
9580 of using this option.
9582 @include parse-datetime.texi
9584 @node Formats
9585 @chapter Controlling the Archive Format
9587 @cindex Tar archive formats
9588 Due to historical reasons, there are several formats of tar archives.
9589 All of them are based on the same principles, but have some subtle
9590 differences that often make them incompatible with each other.
9592 GNU tar is able to create and handle archives in a variety of formats.
9593 The most frequently used formats are (in alphabetical order):
9595 @table @asis
9596 @item gnu
9597 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
9598 from an early @acronym{POSIX} standard, adding some improvements such as
9599 sparse file handling and incremental archives.  Unfortunately these
9600 features were implemented in a way incompatible with other archive
9601 formats.
9603 Archives in @samp{gnu} format are able to hold file names of unlimited
9604 length.
9606 @item oldgnu
9607 Format used by @GNUTAR{} of versions prior to 1.12.
9609 @item v7
9610 Archive format, compatible with the V7 implementation of tar.  This
9611 format imposes a number of limitations.  The most important of them
9612 are:
9614 @enumerate
9615 @item
9616 File names and symbolic links can contain at most 100 bytes.
9617 @item
9618 File sizes must be less than 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
9619 @item
9620 It is impossible to store special files (block and character
9621 devices, fifos etc.)
9622 @item
9623 UIDs and GIDs must be less than @math{2^21} (2,097,152).
9624 @item
9625 V7 archives do not contain symbolic ownership information (user
9626 and group name of the file owner).
9627 @end enumerate
9629 This format has traditionally been used by Automake when producing
9630 Makefiles.  This practice will change in the future, in the meantime,
9631 however this means that projects containing file names more than 100
9632 bytes long will not be able to use @GNUTAR{} @value{VERSION} and
9633 Automake prior to 1.9.
9635 @item ustar
9636 Archive format defined by @acronym{POSIX.1-1988} and later.  It stores
9637 symbolic ownership information.  It is also able to store
9638 special files.  However, it imposes several restrictions as well:
9640 @enumerate
9641 @item
9642 File names can contain at most 255 bytes.
9643 @item
9644 File names longer than 100 bytes must be split at a directory separator in
9645 two parts, the first being at most 155 bytes long.
9646 So, in most cases file names must be a bit shorter than 255 bytes.
9647 @item
9648 Symbolic links can contain at most 100 bytes.
9649 @item
9650 Files can contain at most 8 GiB (@math{2^33} bytes = 8,589,934,592 bytes).
9651 @item
9652 UIDs, GIDs, device major numbers, and device minor numbers
9653 must be less than @math{2^21} (2,097,152).
9654 @end enumerate
9656 @item star
9657 The format used by the late J@"org Schilling's @command{star}
9658 implementation.  @GNUTAR{} is able to read @samp{star} archives but
9659 currently does not produce them.
9661 @item posix
9662 The format defined by @acronym{POSIX.1-2001} and later.  This is the
9663 most flexible and feature-rich format.  It does not impose arbitrary
9664 restrictions on file sizes or file name lengths.  This format is more
9665 recent, so some @command{tar} implementations cannot handle it properly.
9666 However, any @command{tar} implementation able to read @samp{ustar}
9667 archives should be able to read most @samp{posix} archives as well,
9668 except that it will extract any additional information (such as long
9669 file names) as extra plain text files.
9671 This archive format will be the default format for future versions
9672 of @GNUTAR{}.
9674 @end table
9676 The following table summarizes the limitations of each of these
9677 formats:
9679 @multitable @columnfractions .10 .20 .20 .20 .20
9680 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
9681 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9682 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9683 @item v7     @tab 2097151 @tab 8 GiB @minus{} 1 @tab 99 @tab n/a
9684 @item ustar  @tab 2097151 @tab 8 GiB @minus{} 1 @tab 255 @tab 21
9685 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
9686 @end multitable
9688 The default format for @GNUTAR{} is defined at compilation
9689 time.  You may check it by running @command{tar --help}, and examining
9690 the last lines of its output.  Usually, @GNUTAR{} is configured
9691 to create archives in @samp{gnu} format, however, a future version will
9692 switch to @samp{posix}.
9694 @menu
9695 * Compression::                 Using Less Space through Compression
9696 * Attributes::                  Handling File Attributes
9697 * Portability::                 Making @command{tar} Archives More Portable
9698 * Reproducibility::             Making @command{tar} Archives More Reproducible
9699 * cpio::                        Comparison of @command{tar} and @command{cpio}
9700 @end menu
9702 @node Compression
9703 @section Using Less Space through Compression
9705 @menu
9706 * gzip::                        Creating and Reading Compressed Archives
9707 * sparse::                      Archiving Sparse Files
9708 @end menu
9710 @node gzip
9711 @subsection Creating and Reading Compressed Archives
9712 @cindex Compressed archives
9713 @cindex Storing archives in compressed format
9715 @cindex gzip
9716 @cindex bzip2
9717 @cindex lzip
9718 @cindex lzma
9719 @cindex lzop
9720 @cindex compress
9721 @cindex zstd
9722 @GNUTAR{} is able to create and read compressed archives.  It supports
9723 a wide variety of compression programs, namely: @command{gzip},
9724 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
9725 @command{zstd}, @command{xz} and traditional @command{compress}. The
9726 latter is supported mostly for backward compatibility, and we recommend
9727 against using it, because it is by far less effective than the other
9728 compression programs@footnote{It also had patent problems in the past.}.
9730 Creating a compressed archive is simple: you just specify a
9731 @dfn{compression option} along with the usual archive creation
9732 commands.  Available compression options are summarized in the
9733 table below:
9735 @multitable @columnfractions 0.4 0.2 0.4
9736 @headitem Long            @tab Short       @tab Archive format
9737 @item @option{--gzip}     @tab @option{-z} @tab @command{gzip}
9738 @item @option{--bzip2}    @tab @option{-j} @tab @command{bzip2}
9739 @item @option{--xz}       @tab @option{-J} @tab @command{xz}
9740 @item @option{--lzip}     @tab             @tab @command{lzip}
9741 @item @option{--lzma}     @tab             @tab @command{lzma}
9742 @item @option{--lzop}     @tab             @tab @command{lzop}
9743 @item @option{--zstd}     @tab             @tab @command{zstd}
9744 @item @option{--compress} @tab @option{-Z} @tab @command{compress}
9745 @end multitable
9747 For example:
9749 @smallexample
9750 $ @kbd{tar czf archive.tar.gz .}
9751 @end smallexample
9753 You can also let @GNUTAR{} select the compression program based on
9754 the suffix of the archive file name. This is done using
9755 @option{--auto-compress} (@option{-a}) command line option. For
9756 example, the following invocation will use @command{bzip2} for
9757 compression:
9759 @smallexample
9760 $ @kbd{tar caf archive.tar.bz2 .}
9761 @end smallexample
9763 @noindent
9764 whereas the following one will use @command{lzma}:
9766 @smallexample
9767 $ @kbd{tar caf archive.tar.lzma .}
9768 @end smallexample
9770 For a complete list of file name suffixes recognized by @GNUTAR{},
9771 see @ref{auto-compress}.
9773 Reading compressed archive is even simpler: you don't need to specify
9774 any additional options as @GNUTAR{} recognizes its format
9775 automatically.  Thus, the following commands will list and extract the
9776 archive created in previous example:
9778 @smallexample
9779 # List the compressed archive
9780 $ @kbd{tar tf archive.tar.gz}
9781 # Extract the compressed archive
9782 $ @kbd{tar xf archive.tar.gz}
9783 @end smallexample
9785 The format recognition algorithm is based on @dfn{signatures}, a
9786 special byte sequences in the beginning of file, that are specific for
9787 certain compression formats.  If this approach fails, @command{tar}
9788 falls back to using archive name suffix to determine its format
9789 (@pxref{auto-compress}, for a list of recognized suffixes).
9791 @anchor{alternative decompression programs}
9792 @cindex alternative decompression programs
9793 Some compression programs are able to handle different compression
9794 formats.  @GNUTAR{} uses this, if the principal decompressor for the
9795 given format is not available.  For example, if @command{compress} is
9796 not installed, @command{tar} will try to use @command{gzip}.  As of
9797 version @value{VERSION} the following alternatives are
9798 tried@footnote{To verbosely trace the decompressor selection, use the
9799 @option{--warning=decompress-program} option
9800 (@pxref{warnings,decompress-program}).}:
9802 @multitable @columnfractions 0.3 0.3 0.3
9803 @headitem Format @tab Main decompressor @tab Alternatives
9804 @item compress @tab compress @tab gzip
9805 @item lzma     @tab lzma     @tab xz
9806 @item bzip2    @tab bzip2    @tab lbzip2
9807 @end multitable
9809 The only case when you have to specify a decompression option while
9810 reading the archive is when reading from a pipe or from a tape drive
9811 that does not support random access.  However, in this case @GNUTAR{}
9812 will indicate which option you should use.  For example:
9814 @smallexample
9815 $ @kbd{cat archive.tar.gz | tar tf -}
9816 tar: Archive is compressed.  Use -z option
9817 tar: Error is not recoverable: exiting now
9818 @end smallexample
9820 If you see such diagnostics, just add the suggested option to the
9821 invocation of @GNUTAR{}:
9823 @smallexample
9824 $ @kbd{cat archive.tar.gz | tar tzf -}
9825 @end smallexample
9827 Notice also, that there are several restrictions on operations on
9828 compressed archives.  First of all, compressed archives cannot be
9829 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
9830 them or delete (@option{--delete}) members from them or
9831 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
9832 cannot append another @command{tar} archive to a compressed archive using
9833 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
9834 archives cannot be compressed.
9836 The following options allow to select a particular compressor program:
9838 @table @option
9839 @opindex gzip
9840 @opindex ungzip
9841 @item -z
9842 @itemx --gzip
9843 @itemx --ungzip
9844 Filter the archive through @command{gzip}.
9846 @opindex xz
9847 @item -J
9848 @itemx --xz
9849 Filter the archive through @code{xz}.
9851 @item -j
9852 @itemx --bzip2
9853 Filter the archive through @code{bzip2}.
9855 @opindex lzip
9856 @item --lzip
9857 Filter the archive through @command{lzip}.
9859 @opindex lzma
9860 @item --lzma
9861 Filter the archive through @command{lzma}.
9863 @opindex lzop
9864 @item --lzop
9865 Filter the archive through @command{lzop}.
9867 @opindex zstd
9868 @item --zstd
9869 Filter the archive through @command{zstd}.
9871 @opindex compress
9872 @opindex uncompress
9873 @item -Z
9874 @itemx --compress
9875 @itemx --uncompress
9876 Filter the archive through @command{compress}.
9877 @end table
9879 When any of these options is given, @GNUTAR{} searches the compressor
9880 binary in the current path and invokes it.  The name of the compressor
9881 program is specified at compilation time using a corresponding
9882 @option{--with-@var{compname}} option to @command{configure}, e.g.
9883 @option{--with-bzip2} to select a specific @command{bzip2} binary.
9884 @xref{lbzip2}, for a detailed discussion.
9886 The output produced by @command{tar --help} shows the actual
9887 compressor names along with each of these options.
9889 You can use any of these options on physical devices (tape drives,
9890 etc.)@: and remote files as well as on normal files; data to or from
9891 such devices or remote files is reblocked by another copy of the
9892 @command{tar} program to enforce the specified (or default) record
9893 size.  The default compression parameters are used.
9894 You can override them by using the @option{-I} option (see
9895 below), e.g.:
9897 @smallexample
9898 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9899 @end smallexample
9901 @noindent
9902 A more traditional way to do this is to use a pipe:
9904 @smallexample
9905 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9906 @end smallexample
9908 @cindex corrupted archives
9909 Compressed archives are easily corrupted, because compressed files
9910 have little redundancy.  The adaptive nature of the
9911 compression scheme means that the compression tables are implicitly
9912 spread all over the archive.  If you lose a few blocks, the dynamic
9913 construction of the compression tables becomes unsynchronized, and there
9914 is little chance that you could recover later in the archive.
9916 Other compression options provide better control over creating
9917 compressed archives.  These are:
9919 @table @option
9920 @anchor{auto-compress}
9921 @opindex auto-compress
9922 @item --auto-compress
9923 @itemx -a
9924 Select a compression program to use by the archive file name
9925 suffix.  The following suffixes are recognized:
9927 @multitable @columnfractions 0.3 0.6
9928 @headitem Suffix @tab Compression program
9929 @item @samp{.gz} @tab @command{gzip}
9930 @item @samp{.tgz} @tab @command{gzip}
9931 @item @samp{.taz} @tab @command{gzip}
9932 @item @samp{.Z} @tab @command{compress}
9933 @item @samp{.taZ} @tab @command{compress}
9934 @item @samp{.bz2} @tab @command{bzip2}
9935 @item @samp{.tz2} @tab @command{bzip2}
9936 @item @samp{.tbz2} @tab @command{bzip2}
9937 @item @samp{.tbz} @tab @command{bzip2}
9938 @item @samp{.lz} @tab @command{lzip}
9939 @item @samp{.lzma} @tab @command{lzma}
9940 @item @samp{.tlz} @tab @command{lzma}
9941 @item @samp{.lzo} @tab @command{lzop}
9942 @item @samp{.xz} @tab @command{xz}
9943 @item @samp{.zst} @tab @command{zstd}
9944 @item @samp{.tzst} @tab @command{zstd}
9945 @end multitable
9947 @anchor{use-compress-program}
9948 @opindex use-compress-program
9949 @item --use-compress-program=@var{command}
9950 @itemx -I=@var{command}
9951 Use external compression program @var{command}.  Use this option if you
9952 want to specify options for the compression program, or if you
9953 are not happy with the compression program associated with the suffix
9954 at compile time, or if you have a compression program that @GNUTAR{}
9955 does not support.  The @var{command} argument is a valid command
9956 invocation, as you would type it at the command line prompt, with any
9957 additional options as needed.  Enclose it in quotes if it contains
9958 white space (@pxref{external, Running External Commands}).
9960 The @var{command} should follow two conventions:
9962 First, when invoked without additional options, it should read data
9963 from standard input, compress it and output it on standard output.
9965 Secondly, if invoked with the additional @option{-d} option, it should
9966 do exactly the opposite, i.e., read the compressed data from the
9967 standard input and produce uncompressed data on the standard output.
9969 The latter requirement means that you must not use the @option{-d}
9970 option as a part of the @var{command} itself.
9971 @end table
9973 @cindex gpg, using with tar
9974 @cindex gnupg, using with tar
9975 @cindex Using encrypted archives
9976 The @option{--use-compress-program} option, in particular, lets you
9977 implement your own filters, not necessarily dealing with
9978 compression/decompression.  For example, suppose you wish to implement
9979 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9980 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9981 Manual}).  The following script does that:
9983 @smallexample
9984 @group
9985 #! /bin/sh
9986 case $1 in
9987 -d) gpg --decrypt - | gzip -d -c;;
9988 '') gzip -c | gpg -s;;
9989 *)  echo "Unknown option $1">&2; exit 1;;
9990 esac
9991 @end group
9992 @end smallexample
9994 Suppose you name it @file{gpgz} and save it somewhere in your
9995 @env{PATH}.  Then the following command will create a compressed
9996 archive signed with your private key:
9998 @smallexample
9999 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
10000 @end smallexample
10002 @noindent
10003 Likewise, the command below will list its contents:
10005 @smallexample
10006 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
10007 @end smallexample
10009 @ignore
10010 The above is based on the following discussion:
10012      I have one question, or maybe it's a suggestion if there isn't a way
10013      to do it now.  I would like to use @option{--gzip}, but I'd also like
10014      the output to be fed through a program like @acronym{GNU}
10015      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
10016      to use :-)), basically adding ECC protection on top of compression.
10017      It seems as if this should be quite easy to do, but I can't work out
10018      exactly how to go about it.  Of course, I can pipe the standard output
10019      of @command{tar} through @command{ecc}, but then I lose (though I
10020      haven't started using it yet, I confess) the ability to have
10021      @command{tar} use @command{rmt} for it's I/O (I think).
10023      I think the most straightforward thing would be to let me specify a
10024      general set of filters outboard of compression (preferably ordered,
10025      so the order can be automatically reversed on input operations, and
10026      with the options they require specifiable), but beggars shouldn't be
10027      choosers and anything you decide on would be fine with me.
10029      By the way, I like @command{ecc} but if (as the comments say) it can't
10030      deal with loss of block sync, I'm tempted to throw some time at adding
10031      that capability.  Supposing I were to actually do such a thing and
10032      get it (apparently) working, do you accept contributed changes to
10033      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
10035   Isn't that exactly the role of the
10036   @option{--use-compress-prog=@var{program}} option?
10037   I never tried it myself, but I suspect you may want to write a
10038   @var{prog} script or program able to filter stdin to stdout to
10039   way you want.  It should recognize the @option{-d} option, for when
10040   extraction is needed rather than creation.
10042   It has been reported that if one writes compressed data (through the
10043   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
10044   the DLT compression mode, the data will actually get bigger and one will
10045   end up with less space on the tape.
10046 @end ignore
10048 @menu
10049 * lbzip2::  Using lbzip2 with @GNUTAR{}.
10050 @end menu
10052 @node lbzip2
10053 @subsubsection Using lbzip2 with @GNUTAR{}.
10054 @cindex lbzip2
10055 @cindex Laszlo Ersek
10056   @command{Lbzip2} is a multithreaded utility for handling
10057 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
10058 multiple processors to speed up its operation and in general works
10059 considerably faster than @command{bzip2}.  For a detailed description
10060 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
10061 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
10062 lbzip2: parallel bzip2 utility}.
10064   Recent versions of @command{lbzip2} are mostly command line compatible
10065 with @command{bzip2}, which makes it possible to automatically invoke
10066 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
10067 @GNUTAR{} must be configured with the @option{--with-bzip2} command
10068 line option, like this:
10070 @smallexample
10071 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
10072 @end smallexample
10074   Once configured and compiled this way, @command{tar --help} will show the
10075 following:
10077 @smallexample
10078 @group
10079 $ @kbd{tar --help | grep -- --bzip2}
10080   -j, --bzip2                filter the archive through lbzip2
10081 @end group
10082 @end smallexample
10084 @noindent
10085 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
10087 @node sparse
10088 @subsection Archiving Sparse Files
10089 @cindex Sparse Files
10091 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
10092 in a file is a section of the file's contents which was never written.
10093 The contents of a hole reads as all zeros.  On many operating systems,
10094 actual disk storage is not allocated for holes, but they are counted
10095 in the length of the file.  If you archive such a file, @command{tar}
10096 could create an archive longer than the original.  To have @command{tar}
10097 attempt to recognize the holes in a file, use @option{--sparse}
10098 (@option{-S}).  When you use this option, then, for any file using
10099 less disk space than would be expected from its length, @command{tar}
10100 searches the file for holes.  It then records in the archive for the file where
10101 the holes (consecutive stretches of zeros) are, and only archives the
10102 ``real contents'' of the file.  On extraction (using @option{--sparse} is not
10103 needed on extraction) any such files have also holes created wherever the holes
10104 were found.  Thus, if you use @option{--sparse}, @command{tar} archives won't
10105 take more space than the original.
10107 @GNUTAR{} uses two methods for detecting holes in sparse files.  These
10108 methods are described later in this subsection.
10110 @table @option
10111 @opindex sparse
10112 @item -S
10113 @itemx --sparse
10114 This option instructs @command{tar} to test each file for sparseness
10115 before attempting to archive it.  If the file is found to be sparse it
10116 is treated specially, thus allowing to decrease the amount of space
10117 used by its image in the archive.
10119 This option is meaningful only when creating or updating archives.  It
10120 has no effect on extraction.
10121 @end table
10123 Consider using @option{--sparse} when performing file system backups,
10124 to avoid archiving the expanded forms of files stored sparsely in the
10125 system.
10127 Even if your system has no sparse files currently, some may be
10128 created in the future.  If you use @option{--sparse} while making file
10129 system backups as a matter of course, you can be assured the archive
10130 will never take more space on the media than the files take on disk
10131 (otherwise, archiving a disk filled with sparse files might take
10132 hundreds of tapes).  @xref{Incremental Dumps}.
10134 However, be aware that @option{--sparse} option may present a serious
10135 drawback.  Namely, in order to determine the positions of holes in a file
10136 @command{tar} may have to read it before trying to archive it, so in total
10137 the file may be read @strong{twice}.  This may happen when your OS or your FS
10138 does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
10139 @option{--hole-detection}, below).
10141 @cindex sparse formats, defined
10142 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
10143 sparse files using in three distinct ways, called @dfn{sparse
10144 formats}.  A sparse format is identified by its @dfn{number},
10145 consisting, as usual of two decimal numbers, delimited by a dot.  By
10146 default, format @samp{1.0} is used.  If, for some reason, you wish to
10147 use an earlier format, you can select it using
10148 @option{--sparse-version} option.
10150 @table @option
10151 @opindex sparse-version
10152 @item --sparse-version=@var{version}
10153 Select the format to store sparse files in.  Valid @var{version} values
10154 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
10155 for a detailed description of each format.
10156 @end table
10158 Using @option{--sparse-format} option implies @option{--sparse}.
10160 @table @option
10161 @opindex hole-detection
10162 @cindex hole detection
10163 @item --hole-detection=@var{method}
10164 Enforce concrete hole detection method.  Before the real contents of sparse
10165 file are stored, @command{tar} needs to gather knowledge about file
10166 sparseness.  This is because it needs to have the file's map of holes
10167 stored into tar header before it starts archiving the file contents.
10168 Currently, two methods of hole detection are implemented:
10170 @itemize @bullet
10171 @item @option{--hole-detection=seek}
10172 Seeking the file for data and holes.  It uses enhancement of the @code{lseek}
10173 system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
10174 reuse file system knowledge about sparse file contents - so the
10175 detection is usually very fast.  To use this feature, your file system
10176 and operating system must support it.  At the time of this writing
10177 (2015) this feature, in spite of not being accepted by POSIX, is
10178 fairly widely supported by different operating systems.
10180 @item @option{--hole-detection=raw}
10181 Reading byte-by-byte the whole sparse file before the archiving.  This
10182 method detects holes like consecutive stretches of zeroes.  Comparing to
10183 the previous method, it is usually much slower, although more
10184 portable.
10185 @end itemize
10186 @end table
10188 When no @option{--hole-detection} option is given, @command{tar} uses
10189 the @samp{seek}, if supported by the operating system.
10191 Using @option{--hole-detection} option implies @option{--sparse}.
10193 @node Attributes
10194 @section Handling File Attributes
10195 @cindex attributes, files
10196 @cindex file attributes
10198 When @command{tar} reads files, it updates their access times.  To
10199 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
10200 reset the access time retroactively or avoid changing it in the first
10201 place.
10203 @table @option
10204 @opindex atime-preserve
10205 @item --atime-preserve
10206 @itemx --atime-preserve=replace
10207 @itemx --atime-preserve=system
10208 Preserve the access times of files that are read.  This works only for
10209 files that you own, unless you have superuser privileges.
10211 @option{--atime-preserve=replace} works on most systems, but it also
10212 restores the data modification time and updates the status change
10213 time.  Hence it doesn't interact with incremental dumps nicely
10214 (@pxref{Incremental Dumps}), and it can set access or data modification times
10215 incorrectly if other programs access the file while @command{tar} is
10216 running.
10218 @option{--atime-preserve=system} avoids changing the access time in
10219 the first place, if the operating system supports this.
10220 Unfortunately, this may or may not work on any given operating system
10221 or file system.  If @command{tar} knows for sure it won't work, it
10222 complains right away.
10224 Currently @option{--atime-preserve} with no operand defaults to
10225 @option{--atime-preserve=replace}, but this is intended to change to
10226 @option{--atime-preserve=system} when the latter is better-supported.
10228 @opindex touch
10229 @item -m
10230 @itemx --touch
10231 Do not extract data modification time.
10233 When this option is used, @command{tar} leaves the data modification times
10234 of the files it extracts as the times when the files were extracted,
10235 instead of setting it to the times recorded in the archive.
10237 This option is meaningless with @option{--list} (@option{-t}).
10239 @opindex same-owner
10240 @item --same-owner
10241 Create extracted files with the same ownership they have in the
10242 archive.
10244 This is the default behavior for the superuser,
10245 so this option is meaningful only for non-root users, when @command{tar}
10246 is executed on those systems able to give files away.  This is
10247 considered as a security flaw by many people, at least because it
10248 makes quite difficult to correctly account users for the disk space
10249 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
10250 files are easily and silently lost when files are given away.
10252 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
10253 separately.  If it can't find a user name (because the user @acronym{ID} is not
10254 in @file{/etc/passwd}), then it does not write one.  When restoring,
10255 it tries to look the name (if one was written) up in
10256 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
10257 the archive instead.
10259 @opindex no-same-owner
10260 @item --no-same-owner
10261 @itemx -o
10262 Do not attempt to restore ownership when extracting.  This is the
10263 default behavior for ordinary users, so this option has an effect
10264 only for the superuser.
10266 @opindex numeric-owner
10267 @item --numeric-owner
10268 The @option{--numeric-owner} option allows (ANSI) archives to be written
10269 without user/group name information or such information to be ignored
10270 when extracting.  It effectively disables the generation and/or use
10271 of user/group name information.  This option forces extraction using
10272 the numeric ids from the archive, ignoring the names.
10274 This is useful in certain circumstances, when restoring a backup from
10275 an emergency floppy with different passwd/group files for example.
10276 It is otherwise impossible to extract files with the right ownerships
10277 if the password file in use during the extraction does not match the
10278 one belonging to the file system(s) being extracted.  This occurs,
10279 for example, if you are restoring your files after a major crash and
10280 had booted from an emergency floppy with no password file or put your
10281 disk into another machine to do the restore.
10283 The numeric ids are @emph{always} saved into @command{tar} archives.
10284 The identifying names are added at create time when provided by the
10285 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
10286 used when moving archives between a collection of machines using
10287 a centralized management for attribution of numeric ids to users
10288 and groups.  This is often made through using the NIS capabilities.
10290 When making a @command{tar} file for distribution to other sites, it
10291 is sometimes cleaner to use a single owner for all files in the
10292 distribution, and nicer to specify the write permission bits of the
10293 files as stored in the archive independently of their actual value on
10294 the file system.  The way to prepare a clean distribution is usually
10295 to have some Makefile rule creating a directory, copying all needed
10296 files in that directory, then setting ownership and permissions as
10297 wanted (there are a lot of possible schemes), and only then making a
10298 @command{tar} archive out of this directory, before cleaning
10299 everything out.  Of course, we could add a lot of options to
10300 @GNUTAR{} for fine tuning permissions and ownership.
10301 This is not the good way, I think.  @GNUTAR{} is
10302 already crowded with options and moreover, the approach just explained
10303 gives you a great deal of control already.
10305 @xopindex{same-permissions, short description}
10306 @xopindex{preserve-permissions, short description}
10307 @item -p
10308 @itemx --same-permissions
10309 @itemx --preserve-permissions
10310 Extract all protection information.
10312 This option causes @command{tar} to set the modes (access permissions) of
10313 extracted files exactly as recorded in the archive.  If this option
10314 is not used, the current @code{umask} setting limits the permissions
10315 on extracted files.  This option is by default enabled when
10316 @command{tar} is executed by a superuser.
10319 This option is meaningless with @option{--list} (@option{-t}).
10320 @end table
10322 @node Portability
10323 @section Making @command{tar} Archives More Portable
10325 @cindex portable archives
10326 Creating a @command{tar} archive on a particular system that is meant to be
10327 useful later on many other machines and with other versions of @command{tar}
10328 is more challenging than you might think.  @command{tar} archive formats
10329 have been evolving since the first versions of Unix.  Many such formats
10330 are around, and are not always compatible with each other.  This section
10331 discusses a few problems, and gives some advice about making @command{tar}
10332 archives more portable.
10334 One golden rule is simplicity.  For example, limit your @command{tar}
10335 archives to contain only regular files and directories, avoiding
10336 other kind of special files.  Do not attempt to save sparse files or
10337 contiguous files as such.  Let's discuss a few more problems, in turn.
10339 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
10340 archives and archive labels) in GNU and PAX formats.}
10342 @menu
10343 * Portable Names::              Portable Names
10344 * dereference::                 Symbolic Links
10345 * hard links::                  Hard Links
10346 * old::                         Old V7 Archives
10347 * ustar::                       Ustar Archives
10348 * gnu::                         GNU and old GNU format archives.
10349 * posix::                       @acronym{POSIX} archives
10350 * Checksumming::                Checksumming Problems
10351 * Large or Negative Values::    Large files, negative time stamps, etc.
10352 * Other Tars::                  How to Extract GNU-Specific Data Using
10353                                 Other @command{tar} Implementations
10354 @end menu
10356 @node Portable Names
10357 @subsection Portable Names
10359 Use portable file and member names.  A name is portable if it contains
10360 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
10361 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
10362 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
10363 old Unix hosts, limit your file name components to 14 characters or
10364 less.
10366 If you intend to have your @command{tar} archives to be read on
10367 case-insensitive file systems like FAT32,
10368 you should not rely on case distinction for file names.
10370 @node dereference
10371 @subsection Symbolic Links
10372 @cindex File names, using symbolic links
10373 @cindex Symbolic link as file name
10375 @opindex dereference
10376 Normally, when @command{tar} archives a symbolic link, it writes a
10377 block to the archive naming the target of the link.  In that way, the
10378 @command{tar} archive is a faithful record of the file system contents.
10379 When @option{--dereference} (@option{-h}) is used with
10380 @option{--create} (@option{-c}), @command{tar} archives the files
10381 symbolic links point to, instead of
10382 the links themselves.
10384 When creating portable archives, use @option{--dereference}
10385 (@option{-h}): some systems do not support
10386 symbolic links, and moreover, your distribution might be unusable if
10387 it contains unresolved symbolic links.
10389 When reading from an archive, the @option{--dereference} (@option{-h})
10390 option causes @command{tar} to follow an already-existing symbolic
10391 link when @command{tar} writes or reads a file named in the archive.
10392 Ordinarily, @command{tar} does not follow such a link, though it may
10393 remove the link before writing a new file.  @xref{Dealing with Old
10394 Files}.
10396 The @option{--dereference} option is unsafe if an untrusted user can
10397 modify directories while @command{tar} is running.  @xref{Security}.
10399 @node hard links
10400 @subsection Hard Links
10401 @cindex File names, using hard links
10402 @cindex hard links, dereferencing
10403 @cindex dereferencing hard links
10405 Normally, when @command{tar} archives a hard link, it writes a
10406 block to the archive naming the target of the link (a @samp{1} type
10407 block).  In that way, the actual file contents is stored in file only
10408 once.  For example, consider the following two files:
10410 @smallexample
10411 @group
10412 $ ls -l
10413 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
10414 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
10415 @end group
10416 @end smallexample
10418 Here, @file{jeden} is a link to @file{one}.  When archiving this
10419 directory with a verbose level 2, you will get an output similar to
10420 the following:
10422 @smallexample
10423 $ tar cvvf ../archive.tar .
10424 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10425 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10426 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
10427 @end smallexample
10429 The last line shows that, instead of storing two copies of the file,
10430 @command{tar} stored it only once, under the name @file{jeden}, and
10431 stored file @file{one} as a hard link to this file.
10433 It may be important to know that all hard links to the given file are
10434 stored in the archive.  For example, this may be necessary for exact
10435 reproduction of the file system.  The following option does that:
10437 @table @option
10438 @xopindex{check-links, described}
10439 @item --check-links
10440 @itemx -l
10441 Check the number of links dumped for each processed file.  If this
10442 number does not match the total number of hard links for the file, print
10443 a warning message.
10444 @end table
10446 For example, trying to archive only file @file{jeden} with this option
10447 produces the following diagnostics:
10449 @smallexample
10450 $ tar -c -f ../archive.tar -l jeden
10451 tar: Missing links to 'jeden'.
10452 @end smallexample
10454 Although creating special records for hard links helps keep a faithful
10455 record of the file system contents and makes archives more compact, it
10456 may present some difficulties when extracting individual members from
10457 the archive.  For example, trying to extract file @file{one} from the
10458 archive created in previous examples produces, in the absence of file
10459 @file{jeden}:
10461 @smallexample
10462 $ tar xf archive.tar ./one
10463 tar: ./one: Cannot hard link to './jeden': No such file or directory
10464 tar: Error exit delayed from previous errors
10465 @end smallexample
10467 The reason for this behavior is that @command{tar} cannot seek back in
10468 the archive to the previous member (in this case, @file{one}), to
10469 extract it@footnote{There are plans to fix this in future releases.}.
10470 If you wish to avoid such problems at the cost of a bigger archive,
10471 use the following option:
10473 @table @option
10474 @xopindex{hard-dereference, described}
10475 @item --hard-dereference
10476 Dereference hard links and store the files they refer to.
10477 @end table
10479 For example, trying this option on our two sample files, we get two
10480 copies in the archive, each of which can then be extracted
10481 independently of the other:
10483 @smallexample
10484 @group
10485 $ tar -c -vv -f ../archive.tar --hard-dereference .
10486 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10487 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10488 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
10489 @end group
10490 @end smallexample
10492 @node old
10493 @subsection Old V7 Archives
10494 @cindex Format, old style
10495 @cindex Old style format
10496 @cindex Old style archives
10497 @cindex v7 archive format
10499 Certain old versions of @command{tar} cannot handle additional
10500 information recorded by newer @command{tar} programs.  To create an
10501 archive in V7 format (not ANSI), which can be read by these old
10502 versions, specify the @option{--format=v7} option in
10503 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
10504 accepts @option{--portability} or @option{--old-archive} for this
10505 option).  When you specify it,
10506 @command{tar} leaves out information about directories, pipes, fifos,
10507 contiguous files, and device files, and specifies file ownership by
10508 group and user IDs instead of group and user names.
10510 When updating an archive, do not use @option{--format=v7}
10511 unless the archive was created using this option.
10513 In most cases, a @emph{new} format archive can be read by an @emph{old}
10514 @command{tar} program without serious trouble, so this option should
10515 seldom be needed.  On the other hand, most modern @command{tar}s are
10516 able to read old format archives, so it might be safer for you to
10517 always use @option{--format=v7} for your distributions.  Notice,
10518 however, that @samp{ustar} format is a better alternative, as it is
10519 free from many of @samp{v7}'s drawbacks.
10521 @node ustar
10522 @subsection Ustar Archive Format
10524 @cindex ustar archive format
10525 The archive format defined by the @acronym{POSIX}.1-1988 specification is
10526 called @code{ustar}.  Although it is more flexible than the V7 format, it
10527 still has many restrictions (@pxref{Formats,ustar}, for the detailed
10528 description of @code{ustar} format).  Along with V7 format,
10529 @code{ustar} format is a good choice for archives intended to be read
10530 with other implementations of @command{tar}.
10532 To create an archive in @code{ustar} format, use the @option{--format=ustar}
10533 option in conjunction with @option{--create} (@option{-c}).
10535 @node gnu
10536 @subsection @acronym{GNU} and old @GNUTAR{} format
10538 @cindex GNU archive format
10539 @cindex Old GNU archive format
10540 @GNUTAR{} was based on an early draft of the
10541 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
10542 @command{tar}, such as the support for file names longer than 100
10543 characters, use portions of the @command{tar} header record which were
10544 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
10545 @acronym{POSIX} have allocated the same parts of the header record for
10546 other purposes.  As a result, @GNUTAR{} format is
10547 incompatible with the current @acronym{POSIX} specification, and with
10548 @command{tar} programs that follow it.
10550 In the majority of cases, @command{tar} will be configured to create
10551 this format by default.  This will change in future releases, since
10552 we plan to make @samp{POSIX} format the default.
10554 To force creation a @GNUTAR{} archive, use option
10555 @option{--format=gnu}.
10557 @node posix
10558 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
10560 @cindex POSIX archive format
10561 @cindex PAX archive format
10562 Starting from version 1.14 @GNUTAR{} features full support for
10563 @acronym{POSIX.1-2001} archives.
10565 A @acronym{POSIX} conformant archive will be created if @command{tar}
10566 was given @option{--format=posix} (@option{--format=pax}) option.  No
10567 special option is required to read and extract from a @acronym{POSIX}
10568 archive.
10570 @menu
10571 * PAX keywords:: Controlling Extended Header Keywords.
10572 @end menu
10574 @node PAX keywords
10575 @subsubsection Controlling Extended Header Keywords
10577 @table @option
10578 @opindex pax-option
10579 @item --pax-option=@var{keyword-list}
10580 Handle keywords in @acronym{PAX} extended headers.  This option is
10581 equivalent to @option{-o} option of the @command{pax} utility.
10582 @end table
10584 @var{Keyword-list} is a comma-separated
10585 list of keyword options, each keyword option taking one of
10586 the following forms:
10588 @table @code
10589 @item delete=@var{pattern}
10590 When used with one of archive-creation commands,
10591 this option instructs @command{tar} to omit from extended header records
10592 that it produces any keywords matching the string @var{pattern}.
10593 If the pattern contains shell metacharacters like @samp{*}, it should
10594 be quoted to prevent the shell from expanding the pattern before
10595 @command{tar} sees it.
10597 When used in extract or list mode, this option instructs tar
10598 to ignore any keywords matching the given @var{pattern} in the extended
10599 header records.  In both cases, matching is performed using the pattern
10600 matching notation described in @acronym{POSIX 1003.2}, 3.13
10601 (@pxref{wildcards}).  For example:
10603 @smallexample
10604 --pax-option 'delete=security.*'
10605 @end smallexample
10607 would suppress security-related information.
10609 @item exthdr.name=@var{string}
10611 This keyword allows user control over the name that is written into the
10612 ustar header blocks for the extended headers.  The name is obtained
10613 from @var{string} after making the following substitutions:
10615 @multitable @columnfractions .25 .55
10616 @headitem Meta-character @tab Replaced By
10617 @item %d @tab  The directory name of the file, equivalent to the
10618 result of the @command{dirname} utility on the translated file name.
10619 @item %f @tab  The name of the file with the directory information
10620 stripped, equivalent to the result of the @command{basename} utility
10621 on the translated file name.
10622 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
10623 @item %% @tab  A @samp{%} character.
10624 @end multitable
10626 Any other @samp{%} characters in @var{string} produce undefined
10627 results.
10629 If no option @samp{exthdr.name=string} is specified, @command{tar}
10630 will use the following default value:
10632 @smallexample
10633 %d/PaxHeaders/%f
10634 @end smallexample
10636 This default helps make the archive more reproducible.
10637 @xref{Reproducibility}.  @acronym{POSIX} recommends using
10638 @samp{%d/PaxHeaders.%p/%f} instead, which means the two archives
10639 created with the same set of options and containing the same set
10640 of files will be byte-to-byte different. This default will be used
10641 if the environment variable @env{POSIXLY_CORRECT} is set.
10643 @item exthdr.mtime=@var{value}
10645 This keyword defines the value of the @samp{mtime} field that
10646 is written into the ustar header blocks for the extended headers.
10647 By default, the @samp{mtime} field is set to the modification time
10648 of the archive member described by that extended header (or to the
10649 value of the @option{--mtime} option, if supplied).
10651 @item globexthdr.name=@var{string}
10652 This keyword allows user control over the name that is written into
10653 the ustar header blocks for global extended header records.  The name
10654 is obtained from the contents of @var{string}, after making
10655 the following substitutions:
10657 @multitable @columnfractions .25 .55
10658 @headitem Meta-character @tab Replaced By
10659 @item %n @tab An integer that represents the
10660 sequence number of the global extended header record in the archive,
10661 starting at 1.
10662 @item %p @tab The process @acronym{ID} of the @command{tar} process.
10663 @item %% @tab A @samp{%} character.
10664 @end multitable
10666 Any other @samp{%} characters in @var{string} produce undefined results.
10668 If no option @samp{globexthdr.name=string} is specified, @command{tar}
10669 will use the following default value:
10671 @smallexample
10672 $TMPDIR/GlobalHead.%n
10673 @end smallexample
10675 If the environment variable @env{POSIXLY_CORRECT} is set, the
10676 following value is used instead:
10678 @smallexample
10679 $TMPDIR/GlobalHead.%p.%n
10680 @end smallexample
10682 In both cases, @samp{$TMPDIR} stands for the value of the @var{TMPDIR}
10683 environment variable.  If @var{TMPDIR} is not set, @command{tar}
10684 uses @samp{/tmp}.
10686 @item globexthdr.mtime=@var{value}
10688 This keyword defines the value of the @samp{mtime} field that
10689 is written into the ustar header blocks for the global extended headers.
10690 By default, the @samp{mtime} field is set to the time when
10691 @command{tar} was invoked.
10693 @item @var{keyword}=@var{value}
10694 When used with one of archive-creation commands, these keyword/value pairs
10695 will be included at the beginning of the archive in a global extended
10696 header record.  When used with one of archive-reading commands,
10697 @command{tar} will behave as if it has encountered these keyword/value
10698 pairs at the beginning of the archive in a global extended header
10699 record.
10701 @item @var{keyword}:=@var{value}
10702 When used with one of archive-creation commands, these keyword/value pairs
10703 will be included as records at the beginning of an extended header for
10704 each file.  This is effectively equivalent to @var{keyword}=@var{value}
10705 form except that it creates no global extended header records.
10707 When used with one of archive-reading commands, @command{tar} will
10708 behave as if these keyword/value pairs were included as records at the
10709 end of each extended header; thus, they will override any global or
10710 file-specific extended header record keywords of the same names.
10711 For example, in the command:
10713 @smallexample
10714 tar --format=posix --create \
10715     --file archive --pax-option gname:=user .
10716 @end smallexample
10718 the group name will be forced to a new value for all files
10719 stored in the archive.
10720 @end table
10722 In any of the forms described above, the @var{value} may be
10723 a string enclosed in curly braces.  In that case, the string
10724 between the braces is understood either as a textual time
10725 representation, as described in @ref{Date input formats}, or a name of
10726 the existing file, starting with @samp{/} or @samp{.}.  In the latter
10727 case, the modification time of that file is used.
10729 For example, to set all modification times to the current date, you
10730 use the following option:
10732 @smallexample
10733 --pax-option 'mtime:=@{now@}'
10734 @end smallexample
10736 @cindex archives, binary equivalent
10737 @cindex binary equivalent archives, creating
10738 As another example, the following option helps make the archive
10739 more reproducible.  @xref{Reproducibility}.
10741 @smallexample
10742 --pax-option delete=atime
10743 @end smallexample
10745 @noindent
10746 If you extract files from such an archive and recreate the archive
10747 from them, you will also need to eliminate changes due to ctime:
10749 @smallexample
10750 --pax-option 'delete=atime,delete=ctime'
10751 @end smallexample
10753 Normally @command{tar} saves an mtime value with subsecond resolution
10754 in an extended header for any file with a timestamp that is not on a
10755 one-second boundary.  This is in addition to the traditional mtime
10756 timestamp in the header block.  Although you can suppress subsecond
10757 timestamp resolution with @option{--pax-option delete=mtime},
10758 this hack will not work for timestamps before 1970 or after 2242-03-16
10759 12:56:31 @sc{utc}.
10761 If the environment variable @env{POSIXLY_CORRECT} is set, two POSIX
10762 archives created using the same options on the same set of files might
10763 not be byte-to-byte equivalent even with the above options.  This is
10764 because the POSIX default for extended header names includes
10765 the @command{tar} process @acronym{ID}, which typically differs at each
10766 run.  To produce byte-to-byte equivalent archives in this case, either
10767 unset @env{POSIXLY_CORRECT}, or use the following option, which can be
10768 combined with the above options:
10770 @smallexample
10771 --pax-option exthdr.name=%d/PaxHeaders/%f
10772 @end smallexample
10774 @node Checksumming
10775 @subsection Checksumming Problems
10777 SunOS and HP-UX @command{tar} fail to accept archives created using
10778 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
10779 is, file names having characters with the eighth bit set, because they
10780 use signed checksums, while @GNUTAR{} uses unsigned
10781 checksums while creating archives, as per @acronym{POSIX} standards.  On
10782 reading, @GNUTAR{} computes both checksums and accepts either of them.
10783 It is somewhat worrying that a lot of people may go
10784 around doing backup of their files using faulty (or at least
10785 non-standard) software, not learning about it until it's time to
10786 restore their missing files with an incompatible file extractor, or
10787 vice versa.
10789 @GNUTAR{} computes checksums both ways, and accepts either of them
10790 on read, so @acronym{GNU} tar can read Sun tapes even with their
10791 wrong checksums.  @GNUTAR{} produces the standard
10792 checksum, however, raising incompatibilities with Sun.  That is to
10793 say, @GNUTAR{} has not been modified to
10794 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
10795 I've been told that more recent Sun @command{tar} now read standard
10796 archives, so maybe Sun did a similar patch, after all?
10798 The story seems to be that when Sun first imported @command{tar}
10799 sources on their system, they recompiled it without realizing that
10800 the checksums were computed differently, because of a change in
10801 the default signing of @code{char}'s in their compiler.  So they
10802 started computing checksums wrongly.  When they later realized their
10803 mistake, they merely decided to stay compatible with it, and with
10804 themselves afterwards.  Presumably, but I do not really know, HP-UX
10805 has chosen their @command{tar} archives to be compatible with Sun's.
10806 The current standards do not favor Sun @command{tar} format.  In any
10807 case, it now falls on the shoulders of SunOS and HP-UX users to get
10808 a @command{tar} able to read the good archives they receive.
10810 @node Large or Negative Values
10811 @subsection Large or Negative Values
10812 @cindex large values
10813 @cindex future time stamps
10814 @cindex negative time stamps
10815 @UNREVISED{}
10817 The above sections suggest to use @samp{oldest possible} archive
10818 format if in doubt.  However, sometimes it is not possible.  If you
10819 attempt to archive a file whose metadata cannot be represented using
10820 required format, @GNUTAR{} will print error message and ignore such a
10821 file.  You will than have to switch to a format that is able to
10822 handle such values.  The format summary table (@pxref{Formats}) will
10823 help you to do so.
10825 In particular, when trying to archive files 8 GiB or larger, or with
10826 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
10827 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
10828 @acronym{POSIX} archive formats.  When considering which format to
10829 choose, bear in mind that the @acronym{GNU} format uses
10830 two's-complement base-256 notation to store values that do not fit
10831 into standard @acronym{ustar} range.  Such archives can generally be
10832 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
10833 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
10834 example, using two's complement representation for negative time
10835 stamps that assumes a signed 32-bit @code{time_t} generates archives
10836 that are not portable to hosts with differing @code{time_t}
10837 representations.
10839 On the other hand, @acronym{POSIX} archives, generally speaking, can
10840 be extracted by any tar implementation that understands older
10841 @acronym{ustar} format.  The exceptions are files 8 GiB or larger,
10842 or files dated before 1970-01-01 00:00:00 or after 2242-03-16
10843 12:56:31 @sc{utc}
10845 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
10846 POSIX-aware tars.}
10848 @node Other Tars
10849 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
10851 In previous sections you became acquainted with various quirks
10852 necessary to make your archives portable.  Sometimes you may need to
10853 extract archives containing GNU-specific members using some
10854 third-party @command{tar} implementation or an older version of
10855 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
10856 but if it is for some reason impossible, this section will explain
10857 how to cope without it.
10859 When we speak about @dfn{GNU-specific} members we mean two classes of
10860 them: members split between the volumes of a multi-volume archive and
10861 sparse members.  You will be able to always recover such members if
10862 the archive is in PAX format.  In addition split members can be
10863 recovered from archives in old GNU format.  The following subsections
10864 describe the required procedures in detail.
10866 @menu
10867 * Split Recovery::       Members Split Between Volumes
10868 * Sparse Recovery::      Sparse Members
10869 @end menu
10871 @node Split Recovery
10872 @subsubsection Extracting Members Split Between Volumes
10874 @cindex Multi-volume archives, extracting using non-GNU tars
10875 If a member is split between several volumes of an old GNU format archive
10876 most third party @command{tar} implementation will fail to extract
10877 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
10878 This program is available from
10879 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
10880 home page}.  It concatenates several archive volumes into a single
10881 valid archive.  For example, if you have three volumes named from
10882 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
10883 extract them using a third-party @command{tar}:
10885 @smallexample
10886 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
10887 @end smallexample
10889 @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
10890 You could use this approach for most (although not all) PAX
10891 format archives as well.  However, extracting split members from a PAX
10892 archive is a much easier task, because PAX volumes are constructed in
10893 such a way that each part of a split member is extracted to a
10894 different file by @command{tar} implementations that are not aware of
10895 GNU extensions.  More specifically, the very first part retains its
10896 original name, and all subsequent parts are named using the pattern:
10898 @smallexample
10899 %d/GNUFileParts/%f.%n
10900 @end smallexample
10902 @noindent
10903 where symbols preceded by @samp{%} are @dfn{macro characters} that
10904 have the following meaning:
10906 @multitable @columnfractions .25 .55
10907 @headitem Meta-character @tab Replaced By
10908 @item %d @tab  The directory name of the file, equivalent to the
10909 result of the @command{dirname} utility on its full name.
10910 @item %f @tab  The file name of the file, equivalent to the result
10911 of the @command{basename} utility on its full name.
10912 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
10913 created the archive.
10914 @item %n @tab  Ordinal number of this particular part.
10915 @end multitable
10917 For example, if the file @file{var/longfile} was split during archive
10918 creation between three volumes, then the member names will be:
10920 @smallexample
10921 var/longfile
10922 var/GNUFileParts/longfile.1
10923 var/GNUFileParts/longfile.2
10924 @end smallexample
10926 When you extract your archive using a third-party @command{tar}, these
10927 files will be created on your disk, and the only thing you will need
10928 to do to restore your file in its original form is concatenate them in
10929 the proper order, for example:
10931 @smallexample
10932 @group
10933 $ @kbd{cd var}
10934 $ @kbd{cat GNUFileParts/longfile.1 \
10935   GNUFileParts/longfile.2 >> longfile}
10936 $ rm -f GNUFileParts
10937 @end group
10938 @end smallexample
10940 Notice, that if the @command{tar} implementation you use supports PAX
10941 format archives, it will probably emit warnings about unknown keywords
10942 during extraction.  They will look like this:
10944 @smallexample
10945 @group
10946 Tar file too small
10947 Unknown extended header keyword 'GNU.volume.filename' ignored.
10948 Unknown extended header keyword 'GNU.volume.size' ignored.
10949 Unknown extended header keyword 'GNU.volume.offset' ignored.
10950 @end group
10951 @end smallexample
10953 @noindent
10954 You can safely ignore these warnings.
10956 If your @command{tar} implementation is not PAX-aware, you will get
10957 more warnings and more files generated on your disk, e.g.:
10959 @smallexample
10960 @group
10961 $ @kbd{tar xf vol-1.tar}
10962 var/PaxHeaders/longfile: Unknown file type 'x', extracted as
10963 normal file
10964 Unexpected EOF in archive
10965 $ @kbd{tar xf vol-2.tar}
10966 tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file
10967 GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type
10968 'x', extracted as normal file
10969 @end group
10970 @end smallexample
10972 Ignore these warnings.  The @file{PaxHeaders.*} directories created
10973 will contain files with @dfn{extended header keywords} describing the
10974 extracted files.  You can delete them, unless they describe sparse
10975 members.  Read further to learn more about them.
10977 @node Sparse Recovery
10978 @subsubsection Extracting Sparse Members
10980 @cindex sparse files, extracting with non-GNU tars
10981 Any @command{tar} implementation will be able to extract sparse members from a
10982 PAX archive.  However, the extracted files will be @dfn{condensed},
10983 i.e., any zero blocks will be removed from them.  When we restore such
10984 a condensed file to its original form, by adding zero blocks (or
10985 @dfn{holes}) back to their original locations, we call this process
10986 @dfn{expanding} a compressed sparse file.
10988 @pindex xsparse
10989 To expand a file, you will need a simple auxiliary program called
10990 @command{xsparse}.  It is available in source form from
10991 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10992 home page}.
10994 @cindex sparse files v.1.0, extracting with non-GNU tars
10995 Let's begin with archive members in @dfn{sparse format
10996 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10997 The condensed file will contain both file map and file data, so no
10998 additional data will be needed to restore it.  If the original file
10999 name was @file{@var{dir}/@var{name}}, then the condensed file will be
11000 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
11001 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
11002 @dfn{process @acronym{ID}} of the @command{tar} process which created the
11003 archive (@pxref{PAX keywords}).}.
11005 To expand a version 1.0 file, run @command{xsparse} as follows:
11007 @smallexample
11008 $ @kbd{xsparse @file{cond-file}}
11009 @end smallexample
11011 @noindent
11012 where @file{cond-file} is the name of the condensed file.  The utility
11013 will deduce the name for the resulting expanded file using the
11014 following algorithm:
11016 @enumerate 1
11017 @item If @file{cond-file} does not contain any directories,
11018 @file{../cond-file} will be used;
11020 @item If @file{cond-file} has the form
11021 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
11022 are simple names, with no @samp{/} characters in them, the output file
11023 name will be @file{@var{dir}/@var{name}}.
11025 @item Otherwise, if @file{cond-file} has the form
11026 @file{@var{dir}/@var{name}}, the output file name will be
11027 @file{@var{name}}.
11028 @end enumerate
11030 In the unlikely case when this algorithm does not suit your needs,
11031 you can explicitly specify output file name as a second argument to
11032 the command:
11034 @smallexample
11035 $ @kbd{xsparse @file{cond-file} @file{out-file}}
11036 @end smallexample
11038 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
11039 first.  In this mode, the command does not actually expand the file,
11040 but verbosely lists all actions it would be taking to do so.  The dry
11041 run mode is enabled by @option{-n} command line argument:
11043 @smallexample
11044 @group
11045 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
11046 Reading v.1.0 sparse map
11047 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
11048 '/home/gray/sparsefile'
11049 Finished dry run
11050 @end group
11051 @end smallexample
11053 To actually expand the file, you would run:
11055 @smallexample
11056 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
11057 @end smallexample
11059 @noindent
11060 The program behaves the same way all UNIX utilities do: it will keep
11061 quiet unless it has something important to tell you (e.g. an error
11062 condition or something).  If you wish it to produce verbose output,
11063 similar to that from the dry run mode, use @option{-v} option:
11065 @smallexample
11066 @group
11067 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
11068 Reading v.1.0 sparse map
11069 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
11070 '/home/gray/sparsefile'
11071 Done
11072 @end group
11073 @end smallexample
11075 Additionally, if your @command{tar} implementation has extracted the
11076 @dfn{extended headers} for this file, you can instruct @command{xstar}
11077 to use them in order to verify the integrity of the expanded file.
11078 The option @option{-x} sets the name of the extended header file to
11079 use.  Continuing our example:
11081 @smallexample
11082 @group
11083 $ @kbd{xsparse -v -x /home/gray/PaxHeaders/sparsefile \
11084   /home/gray/GNUSparseFile/sparsefile}
11085 Reading extended header file
11086 Found variable GNU.sparse.major = 1
11087 Found variable GNU.sparse.minor = 0
11088 Found variable GNU.sparse.name = sparsefile
11089 Found variable GNU.sparse.realsize = 217481216
11090 Reading v.1.0 sparse map
11091 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
11092 '/home/gray/sparsefile'
11093 Done
11094 @end group
11095 @end smallexample
11097 @anchor{extracting sparse v0x}
11098 @cindex sparse files v.0.1, extracting with non-GNU tars
11099 @cindex sparse files v.0.0, extracting with non-GNU tars
11100 An @dfn{extended header} is a special @command{tar} archive header
11101 that precedes an archive member and contains a set of
11102 @dfn{variables}, describing the member properties that cannot be
11103 stored in the standard @code{ustar} header.  While optional for
11104 expanding sparse version 1.0 members, the use of extended headers is
11105 mandatory when expanding sparse members in older sparse formats: v.0.0
11106 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
11107 Formats}.)  So, for these formats, the question is: how to obtain
11108 extended headers from the archive?
11110 If you use a @command{tar} implementation that does not support PAX
11111 format, extended headers for each member will be extracted as a
11112 separate file.  If we represent the member name as
11113 @file{@var{dir}/@var{name}}, then the extended header file will be
11114 named @file{@var{dir}/@/PaxHeaders/@/@var{name}}.
11116 Things become more difficult if your @command{tar} implementation
11117 does support PAX headers, because in this case you will have to
11118 manually extract the headers.  We recommend the following algorithm:
11120 @enumerate 1
11121 @item
11122 Consult the documentation of your @command{tar} implementation for an
11123 option that prints @dfn{block numbers} along with the archive
11124 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
11125 @command{star} has @option{-block-number}.
11127 @item
11128 Obtain verbose listing using the @samp{block number} option, and
11129 find block numbers of the sparse member in question and the member
11130 immediately following it.  For example, running @command{star} on our
11131 archive we obtain:
11133 @smallexample
11134 @group
11135 $ @kbd{star -t -v -block-number -f arc.tar}
11136 @dots{}
11137 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
11138 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
11139 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
11140 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
11141 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
11142 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
11143 @dots{}
11144 @end group
11145 @end smallexample
11147 @noindent
11148 (as usual, ignore the warnings about unknown keywords.)
11150 @item
11151 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
11152 and @var{Bn} be the block number of the next member.
11153 Compute:
11155 @smallexample
11156 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
11157 @end smallexample
11159 @noindent
11160 This number gives the size of the extended header part in tar @dfn{blocks}.
11161 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
11162 = 7}.
11164 @item
11165 Use @command{dd} to extract the headers:
11167 @smallexample
11168 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
11169 @end smallexample
11171 @noindent
11172 where @var{archive} is the archive name, @var{hname} is a name of the
11173 file to store the extended header in, @var{Bs} and @var{N} are
11174 computed in previous steps.
11176 In our example, this command will be
11178 @smallexample
11179 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
11180 @end smallexample
11181 @end enumerate
11183 Finally, you can expand the condensed file, using the obtained header:
11185 @smallexample
11186 @group
11187 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
11188 Reading extended header file
11189 Found variable GNU.sparse.size = 217481216
11190 Found variable GNU.sparse.numblocks = 208
11191 Found variable GNU.sparse.name = sparsefile
11192 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
11193 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
11194 Done
11195 @end group
11196 @end smallexample
11198 @node Reproducibility
11199 @section Making @command{tar} Archives More Reproducible
11201 @cindex reproducible archives
11202 Sometimes it is important for an archive to be @dfn{reproducible},
11203 so that one can easily verify it to have been derived solely from
11204 its input.  We call an archive reproducible, if an archive
11205 created from the same set of input files with the same command line
11206 options is byte-to-byte equivalent to the original one.
11208 However, two archives created by @GNUTAR{} from two sets of input
11209 files normally might differ even if the input files have the same
11210 contents and @GNUTAR{} was invoked the same way on both sets of input.
11211 This can happen if the inputs have different modification dates or
11212 other metadata, or if the input directories' entries are in different orders.
11214 To avoid this problem when creating an archive, and thus make the
11215 archive reproducible, you can run @GNUTAR{} in the C locale with
11216 some or all of the following options:
11218 @table @option
11219 @item --sort=name
11220 Omit irrelevant information about directory entry order.
11222 @item --format=posix
11223 Avoid problems with large files or files with unusual timestamps.
11224 This also enables @option{--pax-option} options mentioned below.
11226 @item --pax-option='exthdr.name=%d/PaxHeaders/%f'
11227 Omit the process ID of @command{tar}.
11228 This option is needed only if @env{POSIXLY_CORRECT} is set in the environment.
11230 @item --pax-option='delete=atime,delete=ctime'
11231 Omit irrelevant information about file access or status change time.
11233 @item --clamp-mtime --mtime="$SOURCE_EPOCH"
11234 Omit irrelevant information about file timestamps after
11235 @samp{$SOURCE_EPOCH}, which should be a time no less than any
11236 timestamp of any source file.
11238 @item --numeric-owner
11239 Omit irrelevant information about user and group names.
11241 @item --owner=0
11242 @itemx --group=0
11243 Omit irrelevant information about file ownership and group.
11245 @item --mode='go+u,go-w'
11246 Omit irrelevant information about file permissions.
11247 @end table
11249 When creating a reproducible archive from version-controlled source files,
11250 it can be useful to set each file's modification time
11251 to be that of its last commit, so that the timestamps
11252 are reproducible from the version-control repository.
11253 If these timestamps are all on integer second boundaries, and if you use
11254 @option{--format=posix --pax-option='delete=atime,delete=ctime'
11255 --clamp-mtime --mtime="$SOURCE_EPOCH"}
11256 where @code{$SOURCE_EPOCH} is the the time of the most recent commit,
11257 and if all non-source files have timestamps greater than @code{$SOURCE_EPOCH},
11258 then @GNUTAR{} should generate an archive in @acronym{ustar} format,
11259 since no POSIX features will be needed and the archive will be in the
11260 @acronym{ustar} subset of @acronym{posix} format.
11262 Also, if compressing, use a reproducible compression format; e.g.,
11263 with @command{gzip} you should use the @option{--no-name} (@option{-n}) option.
11265 Here is an example set of shell commands to produce a reproducible
11266 tarball with @command{git} and @command{gzip}, which you can tailor to
11267 your project's needs.
11269 @example
11270 function get_commit_time() @{
11271   TZ=UTC0 git log -1 \
11272     --format=tformat:%cd \
11273     --date=format:%Y-%m-%dT%H:%M:%SZ \
11274     "$@@"
11277 # Set each source file timestamp to that of its latest commit.
11278 git ls-files | while read -r file; do
11279   commit_time=$(get_commit_time "$file") &&
11280   touch -md $commit_time "$file"
11281 done
11283 # Set timestamp of each directory under $FILES
11284 # to the latest timestamp of any descendant.
11285 find $FILES -depth -type d -exec sh -c \
11286   'touch -r "$0/$(ls -At "$0" | head -n 1)" "$0"' \
11287   @{@} ';'
11289 # Create $ARCHIVE.tgz from $FILES, pretending that
11290 # the modification time for each newer file
11291 # is that of the most recent commit of any source file.
11292 SOURCE_EPOCH=$(get_commit_time)
11293 TARFLAGS="
11294   --sort=name --format=posix
11295   --pax-option=exthdr.name=%d/PaxHeaders/%f
11296   --pax-option=delete=atime,delete=ctime
11297   --clamp-mtime --mtime=$SOURCE_EPOCH
11298   --numeric-owner --owner=0 --group=0
11299   --mode=go+u,go-w
11301 GZIPFLAGS="--no-name --best"
11302 LC_ALL=C tar $TARFLAGS -cf - $FILES |
11303   gzip $GZIPFLAGS > $ARCHIVE.tgz
11304 @end example
11306 @node cpio
11307 @section Comparison of @command{tar} and @command{cpio}
11308 @UNREVISED{}
11310 @FIXME{Reorganize the following material}
11312 The @command{cpio} archive formats, like @command{tar}, do have maximum
11313 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
11314 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
11315 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
11316 with arbitrary file name lengths, but other @command{cpio} implementations
11317 may crash unexplainedly trying to read them.
11319 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
11320 @command{cpio} doesn't handle symbolic links in the form in which it comes
11321 in System V prior to SVR4, and some vendors may have added symlinks
11322 to their system without enhancing @command{cpio} to know about them.
11323 Others may have enhanced it in a way other than the way I did it
11324 at Sun, and which was adopted by AT&T (and which is, I think, also
11325 present in the @command{cpio} that Berkeley picked up from AT&T and put
11326 into a later @acronym{BSD} release---I think I gave them my changes).
11328 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
11329 can handle @command{tar} format input, and write it on output, and it
11330 probably handles symbolic links.  They may not have bothered doing
11331 anything to enhance @command{tar} as a result.)
11333 @command{cpio} handles special files; traditional @command{tar} doesn't.
11335 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
11336 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
11337 (4.3-tahoe and later).
11339 @command{tar}'s way of handling multiple hard links to a file can handle
11340 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
11341 @command{cpio}s way requires you to play some games (in its ``binary''
11342 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
11343 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
11344 field of the header to make sure that the file system @acronym{ID}/i-number pairs
11345 of different files were always different), and I don't know which
11346 @command{cpio}s, if any, play those games.  Those that don't might get
11347 confused and think two files are the same file when they're not, and
11348 make hard links between them.
11350 @command{tar}s way of handling multiple hard links to a file places only
11351 one copy of the link on the tape, but the name attached to that copy
11352 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
11353 way puts one copy for every link, but you can retrieve it using any
11354 of the names.
11356 @quotation
11357 What type of check sum (if any) is used, and how is this calculated.
11358 @end quotation
11360 See the attached manual pages for @command{tar} and @command{cpio} format.
11361 @command{tar} uses a checksum which is the sum of all the bytes in the
11362 @command{tar} header for a file; @command{cpio} uses no checksum.
11364 @quotation
11365 If anyone knows why @command{cpio} was made when @command{tar} was present
11366 at the unix scene,
11367 @end quotation
11369 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
11370 generally-available version of UNIX had @command{tar} at the time.  I don't
11371 know whether any version that was generally available @emph{within AT&T}
11372 had @command{tar}, or, if so, whether the people within AT&T who did
11373 @command{cpio} knew about it.
11375 On restore, if there is a corruption on a tape @command{tar} will stop at
11376 that point, while @command{cpio} will skip over it and try to restore the
11377 rest of the files.
11379 The main difference is just in the command syntax and header format.
11381 @command{tar} is a little more tape-oriented in that everything is blocked
11382 to start on a record boundary.
11384 @quotation
11385 Is there any differences between the ability to recover crashed
11386 archives between the two of them.  (Is there any chance of recovering
11387 crashed archives at all.)
11388 @end quotation
11390 Theoretically it should be easier under @command{tar} since the blocking
11391 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
11392 However, modern @command{cpio}'s and variations have an option to just
11393 search for the next file header after an error with a reasonable chance
11394 of resyncing.  However, lots of tape driver software won't allow you to
11395 continue past a media error which should be the only reason for getting
11396 out of sync unless a file changed sizes while you were writing the
11397 archive.
11399 @quotation
11400 If anyone knows why @command{cpio} was made when @command{tar} was present
11401 at the unix scene, please tell me about this too.
11402 @end quotation
11404 Probably because it is more media efficient (by not blocking everything
11405 and using only the space needed for the headers where @command{tar}
11406 always uses 512 bytes per file header) and it knows how to archive
11407 special files.
11409 You might want to look at the freely available alternatives.  The
11410 major ones are @command{afio}, @GNUTAR{}, and
11411 @command{pax}, each of which have their own extensions with some
11412 backwards compatibility.
11414 Sparse files were @command{tar}red as sparse files (which you can
11415 easily test, because the resulting archive gets smaller, and
11416 @acronym{GNU} @command{cpio} can no longer read it).
11418 @node Media
11419 @chapter Tapes and Other Archive Media
11420 @UNREVISED{}
11422 A few special cases about tape handling warrant more detailed
11423 description.  These special cases are discussed below.
11425 Many complexities surround the use of @command{tar} on tape drives.  Since
11426 the creation and manipulation of archives located on magnetic tape was
11427 the original purpose of @command{tar}, it contains many features making
11428 such manipulation easier.
11430 Archives are usually written on dismountable media---tape cartridges,
11431 mag tapes, or floppy disks.
11433 The amount of data a tape or disk holds depends not only on its size,
11434 but also on how it is formatted.  A 2400 foot long reel of mag tape
11435 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
11436 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
11438 Magnetic media are re-usable---once the archive on a tape is no longer
11439 needed, the archive can be erased and the tape or disk used over.
11440 Media quality does deteriorate with use, however.  Most tapes or disks
11441 should be discarded when they begin to produce data errors.  EXABYTE
11442 tape cartridges should be discarded when they generate an @dfn{error
11443 count} (number of non-usable bits) of more than 10k.
11445 Magnetic media are written and erased using magnetic fields, and
11446 should be protected from such fields to avoid damage to stored data.
11447 Sticking a floppy disk to a filing cabinet using a magnet is probably
11448 not a good idea.
11450 @menu
11451 * Device::                      Device selection and switching
11452 * Remote Tape Server::
11453 * Common Problems and Solutions::
11454 * Blocking::                    Blocking
11455 * Many::                        Many archives on one tape
11456 * Using Multiple Tapes::        Using Multiple Tapes
11457 * label::                       Including a Label in the Archive
11458 * verify::
11459 * Write Protection::
11460 @end menu
11462 @node Device
11463 @section Device Selection and Switching
11464 @UNREVISED{}
11466 @table @option
11467 @item -f [@var{hostname}:]@var{file}
11468 @itemx --file=[@var{hostname}:]@var{file}
11469 Use archive file or device @var{file} on @var{hostname}.
11470 @end table
11472 This option is used to specify the file name of the archive @command{tar}
11473 works on.
11475 If the file name is @samp{-}, @command{tar} reads the archive from standard
11476 input (when listing or extracting), or writes it to standard output
11477 (when creating).  If the @samp{-} file name is given when updating an
11478 archive, @command{tar} will read the original archive from its standard
11479 input, and will write the entire new archive to its standard output.
11481 If the file name contains a @samp{:}, it is interpreted as
11482 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
11483 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
11484 either case, @command{tar} will invoke the command @command{rsh} (or
11485 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
11486 machine.  If you give an alternate login name, it will be given to the
11487 @command{rsh}.
11488 Naturally, the remote machine must have an executable
11489 @command{/usr/libexec/rmt}.  This program is free software from the
11490 University of California, and a copy of the source code can be found
11491 with the sources for @command{tar}; it's compiled and installed by default.
11492 The exact path to this utility is determined when configuring the package.
11493 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
11494 your installation prefix.  This location may also be overridden at
11495 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
11496 ---rmt-command}, for detailed description of this option.  @xref{Remote
11497 Tape Server}, for the description of @command{rmt} command).
11499 If this option is not given, but the environment variable @env{TAPE}
11500 is set, its value is used; otherwise, old versions of @command{tar}
11501 used a default archive name (which was picked when @command{tar} was
11502 compiled).  The default is normally set up to be the @dfn{first} tape
11503 drive or other transportable I/O medium on the system.
11505 Starting with version 1.11.5, @GNUTAR{} uses
11506 standard input and standard output as the default device, and I will
11507 not try anymore supporting automatic device detection at installation
11508 time.  This was failing really in too many cases, it was hopeless.
11509 This is now completely left to the installer to override standard
11510 input and standard output for default device, if this seems
11511 preferable.  Further, I think @emph{most} actual usages of
11512 @command{tar} are done with pipes or disks, not really tapes,
11513 cartridges or diskettes.
11515 Some users think that using standard input and output is running
11516 after trouble.  This could lead to a nasty surprise on your screen if
11517 you forget to specify an output file name---especially if you are going
11518 through a network or terminal server capable of buffering large amounts
11519 of output.  We had so many bug reports in that area of configuring
11520 default tapes automatically, and so many contradicting requests, that
11521 we finally consider the problem to be portably intractable.  We could
11522 of course use something like @samp{/dev/tape} as a default, but this
11523 is @emph{also} running after various kind of trouble, going from hung
11524 processes to accidental destruction of real tapes.  After having seen
11525 all this mess, using standard input and output as a default really
11526 sounds like the only clean choice left, and a very useful one too.
11528 @GNUTAR{} reads and writes archive in records, I
11529 suspect this is the main reason why block devices are preferred over
11530 character devices.  Most probably, block devices are more efficient
11531 too.  The installer could also check for @samp{DEFTAPE} in
11532 @file{<sys/mtio.h>}.
11534 @table @option
11535 @xopindex{force-local, short description}
11536 @item --force-local
11537 Archive file is local even if it contains a colon.
11539 @opindex rsh-command
11540 @item --rsh-command=@var{command}
11541 Use remote @var{command} instead of @command{rsh}.  This option exists
11542 so that people who use something other than the standard @command{rsh}
11543 (e.g., a Kerberized @command{rsh}) can access a remote device.
11545 When this command is not used, the shell command found when
11546 the @command{tar} program was installed is used instead.  This is
11547 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
11548 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
11549 The installer may have overridden this by defining the environment
11550 variable @env{RSH} @emph{at installation time}.
11552 @item -[0-7][lmh]
11553 Specify drive and density.
11555 @xopindex{multi-volume, short description}
11556 @item -M
11557 @itemx --multi-volume
11558 Create/list/extract multi-volume archive.
11560 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
11561 that may be larger than will fit on the medium used to hold it.
11562 @xref{Multi-Volume Archives}.
11564 @xopindex{tape-length, short description}
11565 @item -L @var{num}
11566 @itemx --tape-length=@var{size}[@var{suf}]
11567 Change tape after writing @var{size} units of data.  Unless @var{suf} is
11568 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
11569 1024} bytes.  The following suffixes alter this behavior:
11571 @float Table, size-suffixes
11572 @caption{Size Suffixes}
11573 @multitable @columnfractions 0.2 0.3 0.3
11574 @headitem Suffix @tab Units            @tab Byte Equivalent
11575 @item b          @tab Blocks           @tab @var{size} x 512
11576 @item B          @tab Kilobytes        @tab @var{size} x 1024
11577 @item c          @tab Bytes            @tab @var{size}
11578 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
11579 @item K          @tab Kilobytes        @tab @var{size} x 1024
11580 @item k          @tab Kilobytes        @tab @var{size} x 1024
11581 @item M          @tab Megabytes        @tab @var{size} x 1024^2
11582 @item P          @tab Petabytes        @tab @var{size} x 1024^5
11583 @item T          @tab Terabytes        @tab @var{size} x 1024^4
11584 @item w          @tab Words            @tab @var{size} x 2
11585 @end multitable
11586 @end float
11588 This option might be useful when your tape drivers do not properly
11589 detect end of physical tapes.  By being slightly conservative on the
11590 maximum tape length, you might avoid the problem entirely.
11592 @xopindex{info-script, short description}
11593 @xopindex{new-volume-script, short description}
11594 @item -F @var{command}
11595 @itemx --info-script=@var{command}
11596 @itemx --new-volume-script=@var{command}
11597 Execute @var{command} at end of each tape.  This implies
11598 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
11599 description of this option.
11600 @end table
11602 @node Remote Tape Server
11603 @section Remote Tape Server
11605 @cindex remote tape drive
11606 @pindex rmt
11607 In order to access the tape drive on a remote machine, @command{tar}
11608 uses the remote tape server written at the University of California at
11609 Berkeley.  The remote tape server must be installed as
11610 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
11611 want to use.  @command{tar} calls @command{rmt} by running an
11612 @command{rsh} or @command{remsh} to the remote machine, optionally
11613 using a different login name if one is supplied.
11615 A copy of the source for the remote tape server is provided.  Its
11616 source code can be freely distributed.  It is compiled and
11617 installed by default.
11619 @cindex absolute file names
11620 Unless you use the @option{--absolute-names} (@option{-P}) option,
11621 @GNUTAR{} will not allow you to create an archive that contains
11622 absolute file names (a file name beginning with @samp{/}).  If you try,
11623 @command{tar} will automatically remove the leading @samp{/} from the
11624 file names it stores in the archive.  It will also type a warning
11625 message telling you what it is doing.
11627 When reading an archive that was created with a different
11628 @command{tar} program, @GNUTAR{} automatically
11629 extracts entries in the archive which have absolute file names as if
11630 the file names were not absolute.  This is an important feature.  A
11631 visitor here once gave a @command{tar} tape to an operator to restore;
11632 the operator used Sun @command{tar} instead of @GNUTAR{},
11633 and the result was that it replaced large portions of
11634 our @file{/bin} and friends with versions from the tape; needless to
11635 say, we were unhappy about having to recover the file system from
11636 backup tapes.
11638 For example, if the archive contained a file @file{/usr/bin/computoy},
11639 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
11640 relative to the current directory.  If you want to extract the files in
11641 an archive to the same absolute names that they had when the archive
11642 was created, you should do a @samp{cd /} before extracting the files
11643 from the archive, or you should either use the @option{--absolute-names}
11644 option, or use the command @samp{tar -C / @dots{}}.
11646 @cindex Ultrix 3.1 and write failure
11647 Some versions of Unix (Ultrix 3.1 is known to have this problem),
11648 can claim that a short write near the end of a tape succeeded,
11649 when it actually failed.  This will result in the -M option not
11650 working correctly.  The best workaround at the moment is to use a
11651 significantly larger blocking factor than the default 20.
11653 In order to update an archive, @command{tar} must be able to backspace the
11654 archive in order to reread or rewrite a record that was just read (or
11655 written).  This is currently possible only on two kinds of files: normal
11656 disk files (or any other file that can be backspaced with @samp{lseek}),
11657 and industry-standard 9-track magnetic tape (or any other kind of tape
11658 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
11660 This means that the @option{--append}, @option{--concatenate}, and
11661 @option{--delete} commands will not work on any other kind of file.
11662 Some media simply cannot be backspaced, which means these commands and
11663 options will never be able to work on them.  These non-backspacing
11664 media include pipes and cartridge tape drives.
11666 Some other media can be backspaced, and @command{tar} will work on them
11667 once @command{tar} is modified to do so.
11669 Archives created with the @option{--multi-volume}, @option{--label}, and
11670 @option{--incremental} (@option{-G}) options may not be readable by other version
11671 of @command{tar}.  In particular, restoring a file that was split over
11672 a volume boundary will require some careful work with @command{dd}, if
11673 it can be done at all.  Other versions of @command{tar} may also create
11674 an empty file whose name is that of the volume header.  Some versions
11675 of @command{tar} may create normal files instead of directories archived
11676 with the @option{--incremental} (@option{-G}) option.
11678 @node Common Problems and Solutions
11679 @section Some Common Problems and their Solutions
11681 @ifclear PUBLISH
11683 @format
11684 errors from system:
11685 permission denied
11686 no such file or directory
11687 not owner
11689 errors from @command{tar}:
11690 directory checksum error
11691 header format error
11693 errors from media/system:
11694 i/o error
11695 device busy
11696 @end format
11698 @end ifclear
11700 @node Blocking
11701 @section Blocking
11702 @cindex block
11703 @cindex record
11705 @dfn{Block} and @dfn{record} terminology is rather confused, and it
11706 is also confusing to the expert reader.  On the other hand, readers
11707 who are new to the field have a fresh mind, and they may safely skip
11708 the next two paragraphs, as the remainder of this manual uses those
11709 two terms in a quite consistent way.
11711 John Gilmore, the writer of the public domain @command{tar} from which
11712 @GNUTAR{} was originally derived, wrote (June 1995):
11714 @quotation
11715 The nomenclature of tape drives comes from IBM, where I believe
11716 they were invented for the IBM 650 or so.  On IBM mainframes, what
11717 is recorded on tape are tape blocks.  The logical organization of
11718 data is into records.  There are various ways of putting records into
11719 blocks, including @code{F} (fixed sized records), @code{V} (variable
11720 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
11721 to a block), @code{VB} (variable size records, @var{n} to a block),
11722 @code{VSB} (variable spanned blocked: variable sized records that can
11723 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
11724 parameter specified this to the operating system.
11726 The Unix man page on @command{tar} was totally confused about this.
11727 When I wrote @code{PD TAR}, I used the historically correct terminology
11728 (@command{tar} writes data records, which are grouped into blocks).
11729 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
11730 here), and now Fran@,{c}ois has migrated that terminology back
11731 into the source code too.
11732 @end quotation
11734 The term @dfn{physical block} means the basic transfer chunk from or
11735 to a device, after which reading or writing may stop without anything
11736 being lost.  In this manual, the term @dfn{block} usually refers to
11737 a disk physical block, @emph{assuming} that each disk block is 512
11738 bytes in length.  It is true that some disk devices have different
11739 physical blocks, but @command{tar} ignore these differences in its own
11740 format, which is meant to be portable, so a @command{tar} block is always
11741 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
11742 The term @dfn{logical block} often represents the basic chunk of
11743 allocation of many disk blocks as a single entity, which the operating
11744 system treats somewhat atomically; this concept is only barely used
11745 in @GNUTAR{}.
11747 The term @dfn{physical record} is another way to speak of a physical
11748 block, those two terms are somewhat interchangeable.  In this manual,
11749 the term @dfn{record} usually refers to a tape physical block,
11750 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
11751 It is true that archives may be put on disk or used with pipes,
11752 but nevertheless, @command{tar} tries to read and write the archive one
11753 @dfn{record} at a time, whatever the medium in use.  One record is made
11754 up of an integral number of blocks, and this operation of putting many
11755 disk blocks into a single tape block is called @dfn{reblocking}, or
11756 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
11757 the logical organization of many characters into something meaningful
11758 to the application.  The term @dfn{unit record} describes a small set
11759 of characters which are transmitted whole to or by the application,
11760 and often refers to a line of text.  Those two last terms are unrelated
11761 to what we call a @dfn{record} in @GNUTAR{}.
11763 When writing to tapes, @command{tar} writes the contents of the archive
11764 in chunks known as @dfn{records}.  To change the default blocking
11765 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
11766 @var{512-size}}) option.  Each record will then be composed of
11767 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
11768 @xref{Standard}.)  Each file written to the archive uses at least one
11769 full record.  As a result, using a larger record size can result in
11770 more wasted space for small files.  On the other hand, a larger record
11771 size can often be read and written much more efficiently.
11773 Further complicating the problem is that some tape drives ignore the
11774 blocking entirely.  For these, a larger record size can still improve
11775 performance (because the software layers above the tape drive still
11776 honor the blocking), but not as dramatically as on tape drives that
11777 honor blocking.
11779 When reading an archive, @command{tar} can usually figure out the
11780 record size on itself.  When this is the case, and a non-standard
11781 record size was used when the archive was created, @command{tar} will
11782 print a message about a non-standard blocking factor, and then operate
11783 normally@footnote{If this message is not needed, you can turn it off
11784 using the @option{--warning=no-record-size} option.}.  On some tape
11785 devices, however, @command{tar} cannot figure out the record size
11786 itself.  On most of those, you can specify a blocking factor (with
11787 @option{--blocking-factor}) larger than the actual blocking factor,
11788 and then use the @option{--read-full-records} (@option{-B}) option.
11789 (If you specify a blocking factor with @option{--blocking-factor} and
11790 don't use the @option{--read-full-records} option, then @command{tar}
11791 will not attempt to figure out the recording size itself.)  On some
11792 devices, you must always specify the record size exactly with
11793 @option{--blocking-factor} when reading, because @command{tar} cannot
11794 figure it out.  In any case, use @option{--list} (@option{-t}) before
11795 doing any extractions to see whether @command{tar} is reading the archive
11796 correctly.
11798 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
11799 putting them into records is to put a whole number of them (one or
11800 more) into each record.  @command{tar} records are all the same size;
11801 at the end of the file there's a block containing all zeros, which
11802 is how you tell that the remainder of the last record(s) are garbage.
11804 In a standard @command{tar} file (no options), the block size is 512
11805 and the record size is 10240, for a blocking factor of 20.  What the
11806 @option{--blocking-factor} option does is sets the blocking factor,
11807 changing the record size while leaving the block size at 512 bytes.
11808 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
11809 most tape drives these days prefer much bigger records in order to
11810 stream and not waste tape.  When writing tapes for myself, some tend
11811 to use a factor of the order of 2048, say, giving a record size of
11812 around one megabyte.
11814 If you use a blocking factor larger than 20, older @command{tar}
11815 programs might not be able to read the archive, so we recommend this
11816 as a limit to use in practice.  @GNUTAR{}, however,
11817 will support arbitrarily large record sizes, limited only by the
11818 amount of virtual memory or the physical characteristics of the tape
11819 device.
11821 @menu
11822 * Format Variations::           Format Variations
11823 * Blocking Factor::             The Blocking Factor of an Archive
11824 @end menu
11826 @node Format Variations
11827 @subsection Format Variations
11828 @cindex Format Parameters
11829 @cindex Format Options
11830 @cindex Options, archive format specifying
11831 @cindex Options, format specifying
11832 @UNREVISED{}
11834 Format parameters specify how an archive is written on the archive
11835 media.  The best choice of format parameters will vary depending on
11836 the type and number of files being archived, and on the media used to
11837 store the archive.
11839 To specify format parameters when accessing or creating an archive,
11840 you can use the options described in the following sections.
11841 If you do not specify any format parameters, @command{tar} uses
11842 default parameters.  You cannot modify a compressed archive.
11843 If you create an archive with the @option{--blocking-factor} option
11844 specified (@pxref{Blocking Factor}), you must specify that
11845 blocking-factor when operating on the archive.  @xref{Formats}, for other
11846 examples of format parameter considerations.
11848 @node Blocking Factor
11849 @subsection The Blocking Factor of an Archive
11850 @cindex Blocking Factor
11851 @cindex Record Size
11852 @cindex Number of blocks per record
11853 @cindex Number of bytes per record
11854 @cindex Bytes per record
11855 @cindex Blocks per record
11856 @UNREVISED{}
11858 @opindex blocking-factor
11859 The data in an archive is grouped into blocks, which are 512 bytes.
11860 Blocks are read and written in whole number multiples called
11861 @dfn{records}.  The number of blocks in a record (i.e., the size of a
11862 record in units of 512 bytes) is called the @dfn{blocking factor}.
11863 The @option{--blocking-factor=@var{512-size}} (@option{-b
11864 @var{512-size}}) option specifies the blocking factor of an archive.
11865 The default blocking factor is typically 20 (i.e., 10240 bytes), but
11866 can be specified at installation.  To find out the blocking factor of
11867 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
11868 This may not work on some devices.
11870 Records are separated by gaps, which waste space on the archive media.
11871 If you are archiving on magnetic tape, using a larger blocking factor
11872 (and therefore larger records) provides faster throughput and allows you
11873 to fit more data on a tape (because there are fewer gaps).  If you are
11874 archiving on cartridge, a very large blocking factor (say 126 or more)
11875 greatly increases performance.  A smaller blocking factor, on the other
11876 hand, may be useful when archiving small files, to avoid archiving lots
11877 of nulls as @command{tar} fills out the archive to the end of the record.
11878 In general, the ideal record size depends on the size of the
11879 inter-record gaps on the tape you are using, and the average size of the
11880 files you are archiving.  @xref{create}, for information on
11881 writing archives.
11883 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
11885 Archives with blocking factors larger than 20 cannot be read
11886 by very old versions of @command{tar}, or by some newer versions
11887 of @command{tar} running on old machines with small address spaces.
11888 With @GNUTAR{}, the blocking factor of an archive is limited
11889 only by the maximum record size of the device containing the archive,
11890 or by the amount of available virtual memory.
11892 Also, on some systems, not using adequate blocking factors, as sometimes
11893 imposed by the device drivers, may yield unexpected diagnostics.  For
11894 example, this has been reported:
11896 @smallexample
11897 Cannot write to /dev/dlt: Invalid argument
11898 @end smallexample
11900 @noindent
11901 In such cases, it sometimes happen that the @command{tar} bundled by
11902 the system is aware of block size idiosyncrasies, while @GNUTAR{}
11903 requires an explicit specification for the block size,
11904 which it cannot guess.  This yields some people to consider
11905 @GNUTAR{} is misbehaving, because by comparison,
11906 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
11907 for example, might resolve the problem.
11909 If you use a non-default blocking factor when you create an archive, you
11910 must specify the same blocking factor when you modify that archive.  Some
11911 archive devices will also require you to specify the blocking factor when
11912 reading that archive, however this is not typically the case.  Usually, you
11913 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
11914 reports a non-default record size and then lists the archive members as
11915 it would normally.  To extract files from an archive with a non-standard
11916 blocking factor (particularly if you're not sure what the blocking factor
11917 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
11918 specifying a blocking factor larger then the blocking factor of the archive
11919 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
11920 @xref{list}, for more information on the @option{--list} (@option{-t})
11921 operation.  @xref{Reading}, for a more detailed explanation of that option.
11923 @table @option
11924 @item --blocking-factor=@var{number}
11925 @itemx -b @var{number}
11926 Specifies the blocking factor of an archive.  Can be used with any
11927 operation, but is usually not necessary with @option{--list} (@option{-t}).
11928 @end table
11930 Device blocking
11932 @table @option
11933 @item -b @var{blocks}
11934 @itemx --blocking-factor=@var{blocks}
11935 Set record size to @math{@var{blocks}*512} bytes.
11937 This option is used to specify a @dfn{blocking factor} for the archive.
11938 When reading or writing the archive, @command{tar}, will do reads and writes
11939 of the archive in records of @math{@var{block}*512} bytes.  This is true
11940 even when the archive is compressed.  Some devices requires that all
11941 write operations be a multiple of a certain size, and so, @command{tar}
11942 pads the archive out to the next record boundary.
11944 The default blocking factor is set when @command{tar} is compiled, and is
11945 typically 20.  Blocking factors larger than 20 cannot be read by very
11946 old versions of @command{tar}, or by some newer versions of @command{tar}
11947 running on old machines with small address spaces.
11949 With a magnetic tape, larger records give faster throughput and fit
11950 more data on a tape (because there are fewer inter-record gaps).
11951 If the archive is in a disk file or a pipe, you may want to specify
11952 a smaller blocking factor, since a large one will result in a large
11953 number of null bytes at the end of the archive.
11955 When writing cartridge or other streaming tapes, a much larger
11956 blocking factor (say 126 or more) will greatly increase performance.
11957 However, you must specify the same blocking factor when reading or
11958 updating the archive.
11960 Apparently, Exabyte drives have a physical block size of 8K bytes.
11961 If we choose our blocksize as a multiple of 8k bytes, then the problem
11962 seems to disappear.  Id est, we are using block size of 112 right
11963 now, and we haven't had the problem since we switched@dots{}
11965 With @GNUTAR{} the blocking factor is limited only
11966 by the maximum record size of the device containing the archive, or by
11967 the amount of available virtual memory.
11969 However, deblocking or reblocking is virtually avoided in a special
11970 case which often occurs in practice, but which requires all the
11971 following conditions to be simultaneously true:
11972 @itemize @bullet
11973 @item
11974 the archive is subject to a compression option,
11975 @item
11976 the archive is not handled through standard input or output, nor
11977 redirected nor piped,
11978 @item
11979 the archive is directly handled to a local disk, instead of any special
11980 device,
11981 @item
11982 @option{--blocking-factor} is not explicitly specified on the @command{tar}
11983 invocation.
11984 @end itemize
11986 If the output goes directly to a local disk, and not through
11987 stdout, then the last write is not extended to a full record size.
11988 Otherwise, reblocking occurs.  Here are a few other remarks on this
11989 topic:
11991 @itemize @bullet
11993 @item
11994 @command{gzip} will complain about trailing garbage if asked to
11995 uncompress a compressed archive on tape, there is an option to turn
11996 the message off, but it breaks the regularity of simply having to use
11997 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
11998 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
11999 Gailly, by sending a copy of this message to him.
12001 @item
12002 @command{compress} does not show this problem, but as Jean-loup pointed
12003 out to Michael, @samp{compress -d} silently adds garbage after
12004 the result of decompression, which tar ignores because it already
12005 recognized its end-of-file indicator.  So this bug may be safely
12006 ignored.
12008 @item
12009 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
12010 but will still return an exit status of 2 which tar reports in turn.
12011 @command{tar} might ignore the exit status returned, but I hate doing
12012 that, as it weakens the protection @command{tar} offers users against
12013 other possible problems at decompression time.  If @command{gzip} was
12014 silently skipping trailing zeros @emph{and} also avoiding setting the
12015 exit status in this innocuous case, that would solve this situation.
12017 @item
12018 @command{tar} should become more solid at not stopping to read a pipe at
12019 the first null block encountered.  This inelegantly breaks the pipe.
12020 @command{tar} should rather drain the pipe out before exiting itself.
12021 @end itemize
12023 @xopindex{ignore-zeros, short description}
12024 @item -i
12025 @itemx --ignore-zeros
12026 Ignore blocks of zeros in archive (means EOF).
12028 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
12029 of zeros in the archive.  Normally a block of zeros indicates the
12030 end of the archive, but when reading a damaged archive, or one which
12031 was created by concatenating several archives together, this option
12032 allows @command{tar} to read the entire archive.  This option is not on
12033 by default because many versions of @command{tar} write garbage after
12034 the zeroed blocks.
12036 Note that this option causes @command{tar} to read to the end of the
12037 archive file, which may sometimes avoid problems when multiple files
12038 are stored on a single physical tape.
12040 @xopindex{read-full-records, short description}
12041 @item -B
12042 @itemx --read-full-records
12043 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
12045 If @option{--read-full-records} is used, @command{tar}
12046 will not panic if an attempt to read a record from the archive does
12047 not return a full record.  Instead, @command{tar} will keep reading
12048 until it has obtained a full
12049 record.
12051 This option is turned on by default when @command{tar} is reading
12052 an archive from standard input, or from a remote machine.  This is
12053 because on @acronym{BSD} Unix systems, a read of a pipe will return however
12054 much happens to be in the pipe, even if it is less than @command{tar}
12055 requested.  If this option was not used, @command{tar} would fail as
12056 soon as it read an incomplete record from the pipe.
12058 This option is also useful with the commands for updating an archive.
12060 @end table
12062 Tape blocking
12064 @FIXME{Appropriate options should be moved here from elsewhere.}
12066 @cindex blocking factor
12067 @cindex tape blocking
12069 When handling various tapes or cartridges, you have to take care of
12070 selecting a proper blocking, that is, the number of disk blocks you
12071 put together as a single tape block on the tape, without intervening
12072 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
12073 with no information on it, used for decelerating the tape to a
12074 full stop, and for later regaining the reading or writing speed.
12075 When the tape driver starts reading a record, the record has to
12076 be read whole without stopping, as a tape gap is needed to stop the
12077 tape motion without losing information.
12079 @cindex Exabyte blocking
12080 @cindex DAT blocking
12081 Using higher blocking (putting more disk blocks per tape block) will use
12082 the tape more efficiently as there will be less tape gaps.  But reading
12083 such tapes may be more difficult for the system, as more memory will be
12084 required to receive at once the whole record.  Further, if there is a
12085 reading error on a huge record, this is less likely that the system will
12086 succeed in recovering the information.  So, blocking should not be too
12087 low, nor it should be too high.  @command{tar} uses by default a blocking of
12088 20 for historical reasons, and it does not really matter when reading or
12089 writing to disk.  Current tape technology would easily accommodate higher
12090 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
12091 We were told that for some DLT drives, the blocking should be a multiple
12092 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
12093 Other manufacturers may use different recommendations for the same tapes.
12094 This might also depends of the buffering techniques used inside modern
12095 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
12096 Others request blocking to be some exponent of two.
12098 So, there is no fixed rule for blocking.  But blocking at read time
12099 should ideally be the same as blocking used at write time.  At one place
12100 I know, with a wide variety of equipment, they found it best to use a
12101 blocking of 32 to guarantee that their tapes are fully interchangeable.
12103 I was also told that, for recycled tapes, prior erasure (by the same
12104 drive unit that will be used to create the archives) sometimes lowers
12105 the error rates observed at rewriting time.
12107 I might also use @option{--number-blocks} instead of
12108 @option{--block-number}, so @option{--block} will then expand to
12109 @option{--blocking-factor} unambiguously.
12111 @node Many
12112 @section Many Archives on One Tape
12114 @FIXME{Appropriate options should be moved here from elsewhere.}
12116 @findex ntape @r{device}
12117 Most tape devices have two entries in the @file{/dev} directory, or
12118 entries that come in pairs, which differ only in the minor number for
12119 this device.  Let's take for example @file{/dev/tape}, which often
12120 points to the only or usual tape device of a given system.  There might
12121 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
12122 name is the @emph{rewinding} version of the device, while the name
12123 having @samp{nr} in it is the @emph{no rewinding} version of the same
12124 device.
12126 A rewinding tape device will bring back the tape to its beginning point
12127 automatically when this device is opened or closed.  Since @command{tar}
12128 opens the archive file before using it and closes it afterwards, this
12129 means that a simple:
12131 @smallexample
12132 $ @kbd{tar cf /dev/tape @var{directory}}
12133 @end smallexample
12135 @noindent
12136 will reposition the tape to its beginning both prior and after saving
12137 @var{directory} contents to it, thus erasing prior tape contents and
12138 making it so that any subsequent write operation will destroy what has
12139 just been saved.
12141 @cindex tape positioning
12142 So, a rewinding device is normally meant to hold one and only one file.
12143 If you want to put more than one @command{tar} archive on a given tape, you
12144 will need to avoid using the rewinding version of the tape device.  You
12145 will also have to pay special attention to tape positioning.  Errors in
12146 positioning may overwrite the valuable data already on your tape.  Many
12147 people, burnt by past experiences, will only use rewinding devices and
12148 limit themselves to one file per tape, precisely to avoid the risk of
12149 such errors.  Be fully aware that writing at the wrong position on a
12150 tape loses all information past this point and most probably until the
12151 end of the tape, and this destroyed information @emph{cannot} be
12152 recovered.
12154 To save @var{directory-1} as a first archive at the beginning of a
12155 tape, and leave that tape ready for a second archive, you should use:
12157 @smallexample
12158 $ @kbd{mt -f /dev/nrtape rewind}
12159 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
12160 @end smallexample
12162 @cindex tape marks
12163 @dfn{Tape marks} are special magnetic patterns written on the tape
12164 media, which are later recognizable by the reading hardware.  These
12165 marks are used after each file, when there are many on a single tape.
12166 An empty file (that is to say, two tape marks in a row) signal the
12167 logical end of the tape, after which no file exist.  Usually,
12168 non-rewinding tape device drivers will react to the close request issued
12169 by @command{tar} by first writing two tape marks after your archive, and by
12170 backspacing over one of these.  So, if you remove the tape at that time
12171 from the tape drive, it is properly terminated.  But if you write
12172 another file at the current position, the second tape mark will be
12173 erased by the new information, leaving only one tape mark between files.
12175 So, you may now save @var{directory-2} as a second archive after the
12176 first on the same tape by issuing the command:
12178 @smallexample
12179 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
12180 @end smallexample
12182 @noindent
12183 and so on for all the archives you want to put on the same tape.
12185 Another usual case is that you do not write all the archives the same
12186 day, and you need to remove and store the tape between two archive
12187 sessions.  In general, you must remember how many files are already
12188 saved on your tape.  Suppose your tape already has 16 files on it, and
12189 that you are ready to write the 17th.  You have to take care of skipping
12190 the first 16 tape marks before saving @var{directory-17}, say, by using
12191 these commands:
12193 @smallexample
12194 $ @kbd{mt -f /dev/nrtape rewind}
12195 $ @kbd{mt -f /dev/nrtape fsf 16}
12196 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
12197 @end smallexample
12199 In all the previous examples, we put aside blocking considerations, but
12200 you should do the proper things for that as well.  @xref{Blocking}.
12202 @menu
12203 * Tape Positioning::            Tape Positions and Tape Marks
12204 * mt::                          The @command{mt} Utility
12205 @end menu
12207 @node Tape Positioning
12208 @subsection Tape Positions and Tape Marks
12209 @UNREVISED{}
12211 Just as archives can store more than one file from the file system,
12212 tapes can store more than one archive file.  To keep track of where
12213 archive files (or any other type of file stored on tape) begin and
12214 end, tape archive devices write magnetic @dfn{tape marks} on the
12215 archive media.  Tape drives write one tape mark between files,
12216 two at the end of all the file entries.
12218 If you think of data as a series of records "rrrr"'s, and tape marks as
12219 "*"'s, a tape might look like the following:
12221 @smallexample
12222 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
12223 @end smallexample
12225 Tape devices read and write tapes using a read/write @dfn{tape
12226 head}---a physical part of the device which can only access one
12227 point on the tape at a time.  When you use @command{tar} to read or
12228 write archive data from a tape device, the device will begin reading
12229 or writing from wherever on the tape the tape head happens to be,
12230 regardless of which archive or what part of the archive the tape
12231 head is on.  Before writing an archive, you should make sure that no
12232 data on the tape will be overwritten (unless it is no longer needed).
12233 Before reading an archive, you should make sure the tape head is at
12234 the beginning of the archive you want to read.  You can do it manually
12235 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
12236 that automatically (@pxref{Scripted Restoration}).
12238 If you want to add new archive file entries to a tape, you should
12239 advance the tape to the end of the existing file entries, backspace
12240 over the last tape mark, and write the new archive file.  If you were
12241 to add two archives to the example above, the tape might look like the
12242 following:
12244 @smallexample
12245 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
12246 @end smallexample
12248 @node mt
12249 @subsection The @command{mt} Utility
12250 @UNREVISED{}
12252 @FIXME{Is it true that this only works on non-block devices?
12253 should explain the difference, (fixed or variable).}
12254 @xref{Blocking Factor}.
12256 You can use the @command{mt} utility to advance or rewind a tape past a
12257 specified number of archive files on the tape.  This will allow you
12258 to move to the beginning of an archive before extracting or reading
12259 it, or to the end of all the archives before writing a new one.
12260 @FIXME{Why isn't there an "advance 'til you find two tape marks
12261 together"?}
12263 The syntax of the @command{mt} command is:
12265 @smallexample
12266 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
12267 @end smallexample
12269 where @var{tapename} is the name of the tape device, @var{number} is
12270 the number of times an operation is performed (with a default of one),
12271 and @var{operation} is one of the following:
12273 @FIXME{is there any use for record operations?}
12275 @table @option
12276 @item eof
12277 @itemx weof
12278 Writes @var{number} tape marks at the current position on the tape.
12280 @item fsf
12281 Moves tape position forward @var{number} files.
12283 @item bsf
12284 Moves tape position back @var{number} files.
12286 @item rewind
12287 Rewinds the tape.  (Ignores @var{number}.)
12289 @item offline
12290 @itemx rewoff1
12291 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
12293 @item status
12294 Prints status information about the tape unit.
12296 @end table
12298 If you don't specify a @var{tapename}, @command{mt} uses the environment
12299 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
12300 the default device specified in your @file{sys/mtio.h} file
12301 (@code{DEFTAPE} variable).  If this is not defined, the program will
12302 display a descriptive error message and exit with code 1.
12304 @command{mt} returns a 0 exit status when the operation(s) were
12305 successful, 1 if the command was unrecognized, and 2 if an operation
12306 failed.
12308 @node Using Multiple Tapes
12309 @section Using Multiple Tapes
12311 Often you might want to write a large archive, one larger than will fit
12312 on the actual tape you are using.  In such a case, you can run multiple
12313 @command{tar} commands, but this can be inconvenient, particularly if you
12314 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
12315 Therefore, @command{tar} provides a special mode for creating
12316 multi-volume archives.
12318 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
12319 on several media volumes of fixed size.  Although in this section we will
12320 often call @samp{volume} a @dfn{tape}, there is absolutely no
12321 requirement for multi-volume archives to be stored on tapes.  Instead,
12322 they can use whatever media type the user finds convenient, they can
12323 even be located on files.
12325 When creating a multi-volume archive, @GNUTAR{} continues to fill
12326 current volume until it runs out of space, then it switches to
12327 next volume (usually the operator is queried to replace the tape on
12328 this point), and continues working on the new volume.  This operation
12329 continues until all requested files are dumped.  If @GNUTAR{} detects
12330 end of media while dumping a file, such a file is archived in split
12331 form.  Some very big files can even be split across several volumes.
12333 Each volume is itself a valid @GNUTAR{} archive, so it can be read
12334 without any special options.  Consequently any file member residing
12335 entirely on one volume can be extracted or otherwise operated upon
12336 without needing the other volume.  Sure enough, to extract a split
12337 member you would need all volumes its parts reside on.
12339 Multi-volume archives suffer from several limitations.  In particular,
12340 they cannot be compressed.
12342 @GNUTAR{} is able to create multi-volume archives of two formats
12343 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
12345 @menu
12346 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
12347 * Tape Files::                  Tape Files
12348 * Tarcat::                      Concatenate Volumes into a Single Archive
12350 @end menu
12352 @node Multi-Volume Archives
12353 @subsection Archives Longer than One Tape or Disk
12354 @cindex Multi-volume archives
12356 @opindex multi-volume
12357 To create an archive that is larger than will fit on a single unit of
12358 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
12359 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
12360 archive can be manipulated like any other archive (provided the
12361 @option{--multi-volume} option is specified), but is stored on more
12362 than one tape or file.
12364 When you specify @option{--multi-volume}, @command{tar} does not report an
12365 error when it comes to the end of an archive volume (when reading), or
12366 the end of the media (when writing).  Instead, it prompts you to load
12367 a new storage volume.  If the archive is on a magnetic tape, you
12368 should change tapes when you see the prompt; if the archive is on a
12369 floppy disk, you should change disks; etc.
12371 @table @option
12372 @item --multi-volume
12373 @itemx -M
12374 Creates a multi-volume archive, when used in conjunction with
12375 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
12376 archive, specify @option{--multi-volume} in conjunction with that
12377 operation.
12378 For example:
12380 @smallexample
12381 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
12382 @end smallexample
12383 @end table
12385 The method @command{tar} uses to detect end of tape is not perfect, and
12386 fails on some operating systems or on some devices.  If @command{tar}
12387 cannot detect the end of the tape itself, you can use
12388 @option{--tape-length} option to inform it about the capacity of the
12389 tape:
12391 @anchor{tape-length}
12392 @table @option
12393 @opindex tape-length
12394 @item --tape-length=@var{size}[@var{suf}]
12395 @itemx -L @var{size}[@var{suf}]
12396 Set maximum length of a volume.  The @var{suf}, if given, specifies
12397 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
12398 megabytes (@pxref{size-suffixes}, for a list of allowed size
12399 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
12400 assumed.
12402 This option selects @option{--multi-volume} automatically.  For example:
12404 @smallexample
12405 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
12406 @end smallexample
12408 @noindent
12409 or, which is equivalent:
12411 @smallexample
12412 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
12413 @end smallexample
12414 @end table
12416 @anchor{change volume prompt}
12417 When @GNUTAR{} comes to the end of a storage media, it asks you to
12418 change the volume.  The built-in prompt for POSIX locale
12419 is@footnote{If you run @GNUTAR{} under a different locale, the
12420 translation to the locale's language will be used.}:
12422 @smallexample
12423 Prepare volume #@var{n} for '@var{archive}' and hit return:
12424 @end smallexample
12426 @noindent
12427 where @var{n} is the ordinal number of the volume to be created and
12428 @var{archive} is archive file or device name.
12430 When prompting for a new tape, @command{tar} accepts any of the following
12431 responses:
12433 @table @kbd
12434 @item ?
12435 Request @command{tar} to explain possible responses.
12436 @item q
12437 Request @command{tar} to exit immediately.
12438 @item n @var{file-name}
12439 Request @command{tar} to write the next volume on the file @var{file-name}.
12440 @item !
12441 Request @command{tar} to run a subshell.  This option can be disabled
12442 by giving @option{--restrict} command line option to
12443 @command{tar}@footnote{@xref{--restrict}, for more information about
12444 this option.}.
12445 @item y
12446 Request @command{tar} to begin writing the next volume.
12447 @end table
12449 (You should only type @samp{y} after you have changed the tape;
12450 otherwise @command{tar} will write over the volume it just finished.)
12452 @cindex Volume number file
12453 @cindex volno file
12454 @anchor{volno-file}
12455 @opindex volno-file
12456 The volume number used by @command{tar} in its tape-changing prompt
12457 can be changed; if you give the
12458 @option{--volno-file=@var{file-of-number}} option, then
12459 @var{file-of-number} should be an non-existing file to be created, or
12460 else, a file already containing a decimal number.  That number will be
12461 used as the volume number of the first volume written.  When
12462 @command{tar} is finished, it will rewrite the file with the
12463 now-current volume number. (This does not change the volume number
12464 written on a tape label, as per @ref{label}, it @emph{only} affects
12465 the number used in the prompt.)
12467 @cindex End-of-archive info script
12468 @cindex Info script
12469 @anchor{info-script}
12470 @opindex info-script
12471 @opindex new-volume-script
12472 If you want more elaborate behavior than this, you can write a special
12473 @dfn{new volume script}, that will be responsible for changing the
12474 volume, and instruct @command{tar} to use it instead of its normal
12475 prompting procedure:
12477 @table @option
12478 @item --info-script=@var{command}
12479 @itemx --new-volume-script=@var{command}
12480 @itemx -F @var{command}
12481 Specify the command to invoke when switching volumes.  The @var{command}
12482 can be used to eject cassettes, or to broadcast messages such as
12483 @samp{Someone please come change my tape} when performing unattended
12484 backups.
12485 @end table
12487 The @var{command} can contain additional options, if such are needed.
12488 @xref{external, Running External Commands}, for a detailed discussion
12489 of the way @GNUTAR{} runs external commands.  It inherits
12490 @command{tar}'s shell environment.  Additional data is passed to it
12491 via the following environment variables:
12493 @table @env
12494 @vrindex TAR_VERSION, info script environment variable
12495 @item TAR_VERSION
12496 @GNUTAR{} version number.
12498 @vrindex TAR_ARCHIVE, info script environment variable
12499 @item TAR_ARCHIVE
12500 The name of the archive @command{tar} is processing.
12502 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
12503 @item TAR_BLOCKING_FACTOR
12504 Current blocking factor (@pxref{Blocking}).
12506 @vrindex TAR_VOLUME, info script environment variable
12507 @item TAR_VOLUME
12508 Ordinal number of the volume @command{tar} is about to start.
12510 @vrindex TAR_SUBCOMMAND, info script environment variable
12511 @item TAR_SUBCOMMAND
12512 A short option describing the operation @command{tar} is executing.
12513 @xref{Operations}, for a complete list of subcommand options.
12515 @vrindex TAR_FORMAT, info script environment variable
12516 @item TAR_FORMAT
12517 Format of the archive being processed. @xref{Formats}, for a complete
12518 list of archive format names.
12520 @vrindex TAR_FD, info script environment variable
12521 @item TAR_FD
12522 File descriptor which can be used to communicate the new volume
12523 name to @command{tar}.
12524 @end table
12526 These variables can be used in the @var{command} itself, provided that
12527 they are properly quoted to prevent them from being expanded by the
12528 shell that invokes @command{tar}.
12530 The volume script can instruct @command{tar} to use new archive name,
12531 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
12533 If the info script fails, @command{tar} exits; otherwise, it begins
12534 writing the next volume.
12536 If you want @command{tar} to cycle through a series of files or tape
12537 drives, there are three approaches to choose from.  First of all, you
12538 can give @command{tar} multiple @option{--file} options.  In this case
12539 the specified files will be used, in sequence, as the successive
12540 volumes of the archive.  Only when the first one in the sequence needs
12541 to be used again will @command{tar} prompt for a tape change (or run
12542 the info script).  For example, suppose someone has two tape drives on
12543 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
12544 @GNUTAR{} to switch to the second drive when it needs to write the
12545 second tape, and then back to the first tape, etc., just do either of:
12547 @smallexample
12548 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
12549 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
12550 @end smallexample
12552 The second method is to use the @samp{n} response to the tape-change
12553 prompt.
12555 Finally, the most flexible approach is to use a volume script, that
12556 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
12557 following volume script will create a series of archive files, named
12558 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
12559 archive being created (as given by @option{--file} option) and
12560 @var{vol} is the ordinal number of the archive being created:
12562 @smallexample
12563 @group
12564 #! /bin/bash
12565 # For this script it's advisable to use a shell, such as Bash,
12566 # that supports a TAR_FD value greater than 9.
12568 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
12570 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
12571 case $TAR_SUBCOMMAND in
12572 -c)       ;;
12573 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
12574           ;;
12575 *)        exit 1
12576 esac
12578 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
12579 @end group
12580 @end smallexample
12582 The same script can be used while listing, comparing or extracting
12583 from the created archive.  For example:
12585 @smallexample
12586 @group
12587 # @r{Create a multi-volume archive:}
12588 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
12589 # @r{Extract from the created archive:}
12590 $ @kbd{tar -x -f archive.tar -F new-volume .}
12591 @end group
12592 @end smallexample
12594 @noindent
12595 Notice, that the first command had to use @option{-L} option, since
12596 otherwise @GNUTAR{} will end up writing everything to file
12597 @file{archive.tar}.
12599 You can read each individual volume of a multi-volume archive as if it
12600 were an archive by itself.  For example, to list the contents of one
12601 volume, use @option{--list}, without @option{--multi-volume} specified.
12602 To extract an archive member from one volume (assuming it is described
12603 that volume), use @option{--extract}, again without
12604 @option{--multi-volume}.
12606 If an archive member is split across volumes (i.e., its entry begins on
12607 one volume of the media and ends on another), you need to specify
12608 @option{--multi-volume} to extract it successfully.  In this case, you
12609 should load the volume where the archive member starts, and use
12610 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
12611 volumes as it needs them.  @xref{extracting archives}, for more
12612 information about extracting archives.
12614 Multi-volume archives can be modified like any other archive.  To add
12615 files to a multi-volume archive, you need to only mount the last
12616 volume of the archive media (and new volumes, if needed).  For all
12617 other operations, you need to use the entire archive.
12619 If a multi-volume archive was labeled using
12620 @option{--label=@var{archive-label}} (@pxref{label}) when it was
12621 created, @command{tar} will not automatically label volumes which are
12622 added later.  To label subsequent volumes, specify
12623 @option{--label=@var{archive-label}} again in conjunction with the
12624 @option{--append}, @option{--update} or @option{--concatenate} operation.
12626 Notice that multi-volume support is a GNU extension and the archives
12627 created in this mode should be read only using @GNUTAR{}.  If you
12628 absolutely have to process such archives using a third-party @command{tar}
12629 implementation, read @ref{Split Recovery}.
12631 @node Tape Files
12632 @subsection Tape Files
12633 @cindex labeling archives
12634 @opindex label
12635 @UNREVISED{}
12637 To give the archive a name which will be recorded in it, use the
12638 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
12639 option.  This will write a special block identifying
12640 @var{volume-label} as the name of the archive to the front of the
12641 archive which will be displayed when the archive is listed with
12642 @option{--list}.  If you are creating a multi-volume archive with
12643 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
12644 volume label will have @samp{Volume @var{nnn}} appended to the name
12645 you give, where @var{nnn} is the number of the volume of the archive.
12646 If you use the @option{--label=@var{volume-label}} option when
12647 reading an archive, it checks to make sure the label on the tape
12648 matches the one you gave.  @xref{label}.
12650 When @command{tar} writes an archive to tape, it creates a single
12651 tape file.  If multiple archives are written to the same tape, one
12652 after the other, they each get written as separate tape files.  When
12653 extracting, it is necessary to position the tape at the right place
12654 before running @command{tar}.  To do this, use the @command{mt} command.
12655 For more information on the @command{mt} command and on the organization
12656 of tapes into a sequence of tape files, see @ref{mt}.
12658 People seem to often do:
12660 @smallexample
12661 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
12662 @end smallexample
12664 or such, for pushing a common date in all volumes or an archive set.
12666 @node Tarcat
12667 @subsection Concatenate Volumes into a Single Archive
12669 @pindex tarcat
12670   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
12671 archive to a single @command{tar} archive.  Simply concatenating all
12672 volumes into one will not work, since each volume carries an additional
12673 information at the beginning.  @GNUTAR{} is shipped with the shell
12674 script @command{tarcat} designed for this purpose.
12676   The script takes a list of files comprising a multi-volume archive
12677 and creates the resulting archive at the standard output.  For example:
12679 @smallexample
12680 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
12681 @end smallexample
12683   The script implements a simple heuristics to determine the format of
12684 the first volume file and to decide how to process the rest of the
12685 files.  However, it makes no attempt to verify whether the files are
12686 given in order or even if they are valid @command{tar} archives.
12687 It uses @command{dd} and does not filter its standard error, so you
12688 will usually see lots of spurious messages.
12690 @FIXME{The script is not installed.  Should we install it?}
12692 @node label
12693 @section Including a Label in the Archive
12694 @cindex Labeling an archive
12695 @cindex Labels on the archive media
12696 @cindex Labeling multi-volume archives
12698 @opindex label
12699   To avoid problems caused by misplaced paper labels on the archive
12700 media, you can include a @dfn{label} entry --- an archive member which
12701 contains the name of the archive --- in the archive itself.  Use the
12702 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12703 option@footnote{Until version 1.10, that option was called
12704 @option{--volume}, but is not available under that name anymore.} in
12705 conjunction with the @option{--create} operation to include a label
12706 entry in the archive as it is being created.
12708 @table @option
12709 @item --label=@var{archive-label}
12710 @itemx -V @var{archive-label}
12711 Includes an @dfn{archive-label} at the beginning of the archive when
12712 the archive is being created, when used in conjunction with the
12713 @option{--create} operation.  Checks to make sure the archive label
12714 matches the one specified (when used in conjunction with any other
12715 operation).
12716 @end table
12718   If you create an archive using both
12719 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12720 and @option{--multi-volume} (@option{-M}), each volume of the archive
12721 will have an archive label of the form @samp{@var{archive-label}
12722 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
12723 next, and so on. @xref{Using Multiple Tapes}, for information on
12724 creating multiple volume archives.
12726 @cindex Volume label, listing
12727 @cindex Listing volume label
12728   The volume label will be displayed by @option{--list} along with
12729 the file contents.  If verbose display is requested, it will also be
12730 explicitly marked as in the example below:
12732 @smallexample
12733 @group
12734 $ @kbd{tar --verbose --list --file=iamanarchive}
12735 V--------- 0/0               0 1992-03-07 12:01 iamalabel--Volume Header--
12736 -rw-r--r-- ringo/user       40 1990-05-21 13:30 iamafilename
12737 @end group
12738 @end smallexample
12740 @opindex test-label
12741 @anchor{--test-label option}
12742   However, @option{--list} option will cause listing entire
12743 contents of the archive, which may be undesirable (for example, if the
12744 archive is stored on a tape).  You can request checking only the volume
12745 label by specifying @option{--test-label} option.  This option reads only the
12746 first block of an archive, so it can be used with slow storage
12747 devices.  For example:
12749 @smallexample
12750 @group
12751 $ @kbd{tar --test-label --file=iamanarchive}
12752 iamalabel
12753 @end group
12754 @end smallexample
12756   If @option{--test-label} is used with one or more command line
12757 arguments, @command{tar} compares the volume label with each
12758 argument.  It exits with code 0 if a match is found, and with code 1
12759 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
12760 mismatch with an exit code 2 and printed a spurious diagnostics on
12761 stderr.}.  No output is displayed, unless you also used the
12762 @option{--verbose} option.  For example:
12764 @smallexample
12765 @group
12766 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
12767 @result{} 0
12768 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
12769 @result{} 1
12770 @end group
12771 @end smallexample
12773   When used with the @option{--verbose} option, @command{tar}
12774 prints the actual volume label (if any), and a verbose diagnostics in
12775 case of a mismatch:
12777 @smallexample
12778 @group
12779 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
12780 iamalabel
12781 @result{} 0
12782 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
12783 iamalabel
12784 tar: Archive label mismatch
12785 @result{} 1
12786 @end group
12787 @end smallexample
12789   If you request any operation, other than @option{--create}, along
12790 with using @option{--label} option, @command{tar} will first check if
12791 the archive label matches the one specified and will refuse to proceed
12792 if it does not.  Use this as a safety precaution to avoid accidentally
12793 overwriting existing archives.  For example, if you wish to add files
12794 to @file{archive}, presumably labeled with string @samp{My volume},
12795 you will get:
12797 @smallexample
12798 @group
12799 $ @kbd{tar -rf archive --label 'My volume' .}
12800 tar: Archive not labeled to match 'My volume'
12801 @end group
12802 @end smallexample
12804 @noindent
12805 in case its label does not match.  This will work even if
12806 @file{archive} is not labeled at all.
12808   Similarly, @command{tar} will refuse to list or extract the
12809 archive if its label doesn't match the @var{archive-label}
12810 specified.  In those cases, @var{archive-label} argument is interpreted
12811 as a globbing-style pattern which must match the actual magnetic
12812 volume label.  @xref{exclude}, for a precise description of how match
12813 is attempted@footnote{Previous versions of @command{tar} used full
12814 regular expression matching, or before that, only exact string
12815 matching, instead of wildcard matchers.  We decided for the sake of
12816 simplicity to use a uniform matching device through
12817 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
12818 the volume label matcher will also suffix @var{archive-label} by
12819 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
12820 up.  Since the volume numbering is automatically added in labels at
12821 creation time, it sounded logical to equally help the user taking care
12822 of it when the archive is being read.
12824   You can also use @option{--label} to get a common information on
12825 all tapes of a series.  For having this information different in each
12826 series created through a single script used on a regular basis, just
12827 manage to get some date string as part of the label.  For example:
12829 @smallexample
12830 @group
12831 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
12832 $ @kbd{tar --create --file=/dev/tape --multi-volume \
12833      --label="Daily backup for `date +%Y-%m-%d`"}
12834 @end group
12835 @end smallexample
12837   Some more notes about volume labels:
12839 @itemize @bullet
12840 @item Each label has its own date and time, which corresponds
12841 to the time when @GNUTAR{} initially attempted to write it,
12842 often soon after the operator launches @command{tar} or types the
12843 carriage return telling that the next tape is ready.
12845 @item Comparing date labels to get an idea of tape throughput is
12846 unreliable.  It gives correct results only if the delays for rewinding
12847 tapes and the operator switching them were negligible, which is
12848 usually not the case.
12849 @end itemize
12851 @node verify
12852 @section Verifying Data as It is Stored
12853 @cindex Verifying a write operation
12854 @cindex Double-checking a write operation
12856 @table @option
12857 @item -W
12858 @itemx --verify
12859 @opindex verify, short description
12860 Attempt to verify the archive after writing.
12861 @end table
12863 This option causes @command{tar} to verify the archive after writing it.
12864 Each volume is checked after it is written, and any discrepancies
12865 are recorded on the standard error output.
12867 Verification requires that the archive be on a back-space-able medium.
12868 This means pipes, some cartridge tape drives, and some other devices
12869 cannot be verified.
12871 You can insure the accuracy of an archive by comparing files in the
12872 system with archive members.  @command{tar} can compare an archive to the
12873 file system as the archive is being written, to verify a write
12874 operation, or can compare a previously written archive, to insure that
12875 it is up to date.
12877 @xopindex{verify, using with @option{--create}}
12878 @xopindex{create, using with @option{--verify}}
12879 To check for discrepancies in an archive immediately after it is
12880 written, use the @option{--verify} (@option{-W}) option in conjunction with
12881 the @option{--create} operation.  When this option is
12882 specified, @command{tar} checks archive members against their counterparts
12883 in the file system, and reports discrepancies on the standard error.
12885 To verify an archive, you must be able to read it from before the end
12886 of the last written entry.  This option is useful for detecting data
12887 errors on some tapes.  Archives written to pipes, some cartridge tape
12888 drives, and some other devices cannot be verified.
12890 One can explicitly compare an already made archive with the file
12891 system by using the @option{--compare} (@option{--diff}, @option{-d})
12892 option, instead of using the more automatic @option{--verify} option.
12893 @xref{compare}.
12895 Note that these two options have a slightly different intent.  The
12896 @option{--compare} option checks how identical are the logical contents of some
12897 archive with what is on your disks, while the @option{--verify} option is
12898 really for checking if the physical contents agree and if the recording
12899 media itself is of dependable quality.  So, for the @option{--verify}
12900 operation, @command{tar} tries to defeat all in-memory cache pertaining to
12901 the archive, while it lets the speed optimization undisturbed for the
12902 @option{--compare} option.  If you nevertheless use @option{--compare} for
12903 media verification, you may have to defeat the in-memory cache yourself,
12904 maybe by opening and reclosing the door latch of your recording unit,
12905 forcing some doubt in your operating system about the fact this is really
12906 the same volume as the one just written or read.
12908 The @option{--verify} option would not be necessary if drivers were indeed
12909 able to detect dependably all write failures.  This sometimes require many
12910 magnetic heads, some able to read after the writes occurred.  One would
12911 not say that drivers unable to detect all cases are necessarily flawed,
12912 as long as programming is concerned.
12914 The @option{--verify} (@option{-W}) option will not work in
12915 conjunction with the @option{--multi-volume} (@option{-M}) option or
12916 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
12917 and @option{--delete} operations.  @xref{Operations}, for more
12918 information on these operations.
12920 Also, since @command{tar} normally strips leading @samp{/} from file
12921 names (@pxref{absolute}), a command like @samp{tar --verify -cf
12922 /tmp/foo.tar /etc} will work as desired only if the working directory is
12923 @file{/}, as @command{tar} uses the archive's relative member names
12924 (e.g., @file{etc/motd}) when verifying the archive.
12926 @node Write Protection
12927 @section Write Protection
12929 Almost all tapes and diskettes, and in a few rare cases, even disks can
12930 be @dfn{write protected}, to protect data on them from being changed.
12931 Once an archive is written, you should write protect the media to prevent
12932 the archive from being accidentally overwritten or deleted.  (This will
12933 protect the archive from being changed with a tape or floppy drive---it
12934 will not protect it from magnet fields or other physical hazards.)
12936 The write protection device itself is usually an integral part of the
12937 physical media, and can be a two position (write enabled/write
12938 disabled) switch, a notch which can be popped out or covered, a ring
12939 which can be removed from the center of a tape reel, or some other
12940 changeable feature.
12942 @node Reliability and security
12943 @chapter Reliability and Security
12945 The @command{tar} command reads and writes files as any other
12946 application does, and is subject to the usual caveats about
12947 reliability and security.  This section contains some commonsense
12948 advice on the topic.
12950 @menu
12951 * Reliability::
12952 * Security::
12953 @end menu
12955 @node Reliability
12956 @section Reliability
12958 Ideally, when @command{tar} is creating an archive, it reads from a
12959 file system that is not being modified, and encounters no errors or
12960 inconsistencies while reading and writing.  If this is the case, the
12961 archive should faithfully reflect what was read.  Similarly, when
12962 extracting from an archive, ideally @command{tar} ideally encounters
12963 no errors and the extracted files faithfully reflect what was in the
12964 archive.
12966 However, when reading or writing real-world file systems, several
12967 things can go wrong; these include permissions problems, corruption of
12968 data, and race conditions.
12970 @menu
12971 * Permissions problems::
12972 * Data corruption and repair::
12973 * Race conditions::
12974 @end menu
12976 @node Permissions problems
12977 @subsection Permissions Problems
12979 If @command{tar} encounters errors while reading or writing files, it
12980 normally reports an error and exits with nonzero status.  The work it
12981 does may therefore be incomplete.  For example, when creating an
12982 archive, if @command{tar} cannot read a file then it cannot copy the
12983 file into the archive.
12985 @node Data corruption and repair
12986 @subsection Data Corruption and Repair
12988 If an archive becomes corrupted by an I/O error, this may corrupt the
12989 data in an extracted file.  Worse, it may corrupt the file's metadata,
12990 which may cause later parts of the archive to become misinterpreted.
12991 An tar-format archive contains a checksum that most likely will detect
12992 errors in the metadata, but it will not detect errors in the data.
12994 If data corruption is a concern, you can compute and check your own
12995 checksums of an archive by using other programs, such as
12996 @command{cksum}.
12998 When attempting to recover from a read error or data corruption in an
12999 archive, you may need to skip past the questionable data and read the
13000 rest of the archive.  This requires some expertise in the archive
13001 format and in other software tools.
13003 @node Race conditions
13004 @subsection Race conditions
13006 If some other process is modifying the file system while @command{tar}
13007 is reading or writing files, the result may well be inconsistent due
13008 to race conditions.  For example, if another process creates some
13009 files in a directory while @command{tar} is creating an archive
13010 containing the directory's files, @command{tar} may see some of the
13011 files but not others, or it may see a file that is in the process of
13012 being created.  The resulting archive may not be a snapshot of the
13013 file system at any point in time.  If an application such as a
13014 database system depends on an accurate snapshot, restoring from the
13015 @command{tar} archive of a live file system may therefore break that
13016 consistency and may break the application.  The simplest way to avoid
13017 the consistency issues is to avoid making other changes to the file
13018 system while tar is reading it or writing it.
13020 When creating an archive, several options are available to avoid race
13021 conditions.  Some hosts have a way of snapshotting a file system, or
13022 of temporarily suspending all changes to a file system, by (say)
13023 suspending the only virtual machine that can modify a file system; if
13024 you use these facilities and have @command{tar -c} read from a
13025 snapshot when creating an archive, you can avoid inconsistency
13026 problems.  More drastically, before starting @command{tar} you could
13027 suspend or shut down all processes other than @command{tar} that have
13028 access to the file system, or you could unmount the file system and
13029 then mount it read-only.
13031 When extracting from an archive, one approach to avoid race conditions
13032 is to create a directory that no other process can write to, and
13033 extract into that.
13035 @node Security
13036 @section Security
13038 In some cases @command{tar} may be used in an adversarial situation,
13039 where an untrusted user is attempting to gain information about or
13040 modify otherwise-inaccessible files.  Dealing with untrusted data
13041 (that is, data generated by an untrusted user) typically requires
13042 extra care, because even the smallest mistake in the use of
13043 @command{tar} is more likely to be exploited by an adversary than by a
13044 race condition.
13046 @menu
13047 * Privacy::
13048 * Integrity::
13049 * Live untrusted data::
13050 * Security rules of thumb::
13051 @end menu
13053 @node Privacy
13054 @subsection Privacy
13056 Standard privacy concerns apply when using @command{tar}.  For
13057 example, suppose you are archiving your home directory into a file
13058 @file{/archive/myhome.tar}.  Any secret information in your home
13059 directory, such as your SSH secret keys, are copied faithfully into
13060 the archive.  Therefore, if your home directory contains any file that
13061 should not be read by some other user, the archive itself should be
13062 not be readable by that user.  And even if the archive's data are
13063 inaccessible to untrusted users, its metadata (such as size or
13064 last-modified date) may reveal some information about your home
13065 directory; if the metadata are intended to be private, the archive's
13066 parent directory should also be inaccessible to untrusted users.
13068 One precaution is to create @file{/archive} so that it is not
13069 accessible to any user, unless that user also has permission to access
13070 all the files in your home directory.
13072 Similarly, when extracting from an archive, take care that the
13073 permissions of the extracted files are not more generous than what you
13074 want.  Even if the archive itself is readable only to you, files
13075 extracted from it have their own permissions that may differ.
13077 @node Integrity
13078 @subsection Integrity
13080 When creating archives, take care that they are not writable by a
13081 untrusted user; otherwise, that user could modify the archive, and
13082 when you later extract from the archive you will get incorrect data.
13084 When @command{tar} extracts from an archive, by default it writes into
13085 files relative to the working directory.  If the archive was generated
13086 by an untrusted user, that user therefore can write into any file
13087 under the working directory.  If the working directory contains a
13088 symbolic link to another directory, the untrusted user can also write
13089 into any file under the referenced directory.  When extracting from an
13090 untrusted archive, it is therefore good practice to create an empty
13091 directory and run @command{tar} in that directory.
13093 When extracting from two or more untrusted archives, each one should
13094 be extracted independently, into different empty directories.
13095 Otherwise, the first archive could create a symbolic link into an area
13096 outside the working directory, and the second one could follow the
13097 link and overwrite data that is not under the working directory.  For
13098 example, when restoring from a series of incremental dumps, the
13099 archives should have been created by a trusted process, as otherwise
13100 the incremental restores might alter data outside the working
13101 directory.
13103 If you use the @option{--absolute-names} (@option{-P}) option when
13104 extracting, @command{tar} respects any file names in the archive, even
13105 file names that begin with @file{/} or contain @file{..}.  As this
13106 lets the archive overwrite any file in your system that you can write,
13107 the @option{--absolute-names} (@option{-P}) option should be used only
13108 for trusted archives.
13110 Conversely, with the @option{--keep-old-files} (@option{-k}) and
13111 @option{--skip-old-files} options, @command{tar} refuses to replace
13112 existing files when extracting.  The difference between the two
13113 options is that the former treats existing files as errors whereas the
13114 latter just silently ignores them.
13116 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
13117 refuses to replace the permissions or ownership of already-existing
13118 directories.  These options may help when extracting from untrusted
13119 archives.
13121 @node Live untrusted data
13122 @subsection Dealing with Live Untrusted Data
13124 Extra care is required when creating from or extracting into a file
13125 system that is accessible to untrusted users.  For example, superusers
13126 who invoke @command{tar} must be wary about its actions being hijacked
13127 by an adversary who is reading or writing the file system at the same
13128 time that @command{tar} is operating.
13130 When creating an archive from a live file system, @command{tar} is
13131 vulnerable to denial-of-service attacks.  For example, an adversarial
13132 user could create the illusion of an indefinitely-deep directory
13133 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
13134 @command{tar}, or the illusion of an indefinitely-long file by
13135 creating a sparse file but arranging for blocks to be allocated just
13136 before @command{tar} reads them.  There is no easy way for
13137 @command{tar} to distinguish these scenarios from legitimate uses, so
13138 you may need to monitor @command{tar}, just as you'd need to monitor
13139 any other system service, to detect such attacks.
13141 While a superuser is extracting from an archive into a live file
13142 system, an untrusted user might replace a directory with a symbolic
13143 link, in hopes that @command{tar} will follow the symbolic link and
13144 extract data into files that the untrusted user does not have access
13145 to.  Even if the archive was generated by the superuser, it may
13146 contain a file such as @file{d/etc/passwd} that the untrusted user
13147 earlier created in order to break in; if the untrusted user replaces
13148 the directory @file{d/etc} with a symbolic link to @file{/etc} while
13149 @command{tar} is running, @command{tar} will overwrite
13150 @file{/etc/passwd}.  This attack can be prevented by extracting into a
13151 directory that is inaccessible to untrusted users.
13153 Similar attacks via symbolic links are also possible when creating an
13154 archive, if the untrusted user can modify an ancestor of a top-level
13155 argument of @command{tar}.  For example, an untrusted user that can
13156 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
13157 - /home/eve/Documents/yesterday} by replacing
13158 @file{/home/eve/Documents} with a symbolic link to some other
13159 location.  Attacks like these can be prevented by making sure that
13160 untrusted users cannot modify any files that are top-level arguments
13161 to @command{tar}, or any ancestor directories of these files.
13163 @node Security rules of thumb
13164 @subsection Security Rules of Thumb
13166 This section briefly summarizes rules of thumb for avoiding security
13167 pitfalls.
13169 @itemize @bullet
13171 @item
13172 Protect archives at least as much as you protect any of the files
13173 being archived.
13175 @item
13176 Extract from an untrusted archive only into an otherwise-empty
13177 directory.  This directory and its parent should be accessible only to
13178 trusted users.  For example:
13180 @example
13181 @group
13182 $ @kbd{chmod go-rwx .}
13183 $ @kbd{mkdir -m go-rwx dir}
13184 $ @kbd{cd dir}
13185 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
13186 @end group
13187 @end example
13189 As a corollary, do not do an incremental restore from an untrusted archive.
13191 @item
13192 Do not let untrusted users access files extracted from untrusted
13193 archives without checking first for problems such as setuid programs.
13195 @item
13196 Do not let untrusted users modify directories that are ancestors of
13197 top-level arguments of @command{tar}.  For example, while you are
13198 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
13199 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
13201 @item
13202 Pay attention to the diagnostics and exit status of @command{tar}.
13204 @item
13205 When archiving live file systems, monitor running instances of
13206 @command{tar} to detect denial-of-service attacks.
13208 @item
13209 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
13210 @option{--dereference} (@option{-h}), @option{--overwrite},
13211 @option{--recursive-unlink}, and @option{--remove-files} unless you
13212 understand their security implications.
13214 @end itemize
13216 @node Changes
13217 @appendix Changes
13219 This appendix lists some important user-visible changes between
13220 various versions of @GNUTAR{}. An up-to-date version of this document
13221 is available at
13222 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
13223 @GNUTAR{} documentation page}.
13225 @table @asis
13226 @item Use of globbing patterns when listing and extracting.
13228 Previous versions of GNU tar assumed shell-style globbing when
13229 extracting from or listing an archive.  For example:
13231 @smallexample
13232 $ @kbd{tar xf foo.tar '*.c'}
13233 @end smallexample
13235 would extract all files whose names end in @samp{.c}.  This behavior
13236 was not documented and was incompatible with traditional tar
13237 implementations.  Therefore, starting from version 1.15.91, GNU tar
13238 no longer uses globbing by default.  For example, the above invocation
13239 is now interpreted as a request to extract from the archive the file
13240 named @file{*.c}.
13242 To facilitate transition to the new behavior for those users who got
13243 used to the previous incorrect one, @command{tar} will print a warning
13244 if it finds out that a requested member was not found in the archive
13245 and its name looks like a globbing pattern.  For example:
13247 @smallexample
13248 $ @kbd{tar xf foo.tar  '*.c'}
13249 tar: Pattern matching characters used in file names. Please,
13250 tar: use --wildcards to enable pattern matching, or --no-wildcards to
13251 tar: suppress this warning.
13252 tar: *.c: Not found in archive
13253 tar: Error exit delayed from previous errors
13254 @end smallexample
13256 To treat member names as globbing patterns, use the @option{--wildcards} option.
13257 If you want to tar to mimic the behavior of versions prior to 1.15.91,
13258 add this option to your @env{TAR_OPTIONS} variable.
13260 @xref{wildcards}, for the detailed discussion of the use of globbing
13261 patterns by @GNUTAR{}.
13263 @item Use of short option @option{-o}.
13265 Earlier versions of @GNUTAR{} understood @option{-o} command line
13266 option as a synonym for @option{--old-archive}.
13268 @GNUTAR{} starting from version 1.13.90 understands this option as
13269 a synonym for @option{--no-same-owner}.  This is compatible with
13270 UNIX98 @command{tar} implementations.
13272 However, to facilitate transition, @option{-o} option retains its
13273 old semantics when it is used with one of archive-creation commands.
13274 Users are encouraged to use @option{--format=oldgnu} instead.
13276 It is especially important, since versions of @acronym{GNU} Automake
13277 up to and including 1.8.4 invoke tar with this option to produce
13278 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
13279 of this issue and its implications.
13281 @xref{Options, tar-formats, Changing Automake's Behavior,
13282 automake, GNU Automake}, for a description on how to use various
13283 archive formats with @command{automake}.
13285 Future versions of @GNUTAR{} will understand @option{-o} only as a
13286 synonym for @option{--no-same-owner}.
13288 @item Use of short option @option{-l}
13290 Earlier versions of @GNUTAR{} understood @option{-l} option as a
13291 synonym for @option{--one-file-system}.  Since such usage contradicted
13292 to UNIX98 specification and harmed compatibility with other
13293 implementations, it was declared deprecated in version 1.14.  However,
13294 to facilitate transition to its new semantics, it was supported by
13295 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
13296 variant of @option{--check-links} was introduced in version 1.15.91.
13298 @item Use of options @option{--portability} and @option{--old-archive}
13300 These options are deprecated.  Please use @option{--format=v7} instead.
13302 @item Use of option @option{--posix}
13304 This option is deprecated.  Please use @option{--format=posix} instead.
13305 @end table
13307 @node Recipes
13308 @appendix Recipes
13309 @include recipes.texi
13311 @node Configuring Help Summary
13312 @appendix Configuring Help Summary
13314 Running @kbd{tar --help} displays the short @command{tar} option
13315 summary (@pxref{help}). This summary is organized by @dfn{groups} of
13316 semantically close options. The options within each group are printed
13317 in the following order: a short option, eventually followed by a list
13318 of corresponding long option names, followed by a short description of
13319 the option. For example, here is an excerpt from the actual @kbd{tar
13320 --help} output:
13322 @verbatim
13323  Main operation mode:
13325   -A, --catenate, --concatenate   append tar files to an archive
13326   -c, --create               create a new archive
13327   -d, --diff, --compare      find differences between archive and
13328                              file system
13329       --delete               delete from the archive
13330 @end verbatim
13332 @vrindex ARGP_HELP_FMT, environment variable
13333 The exact visual representation of the help output is configurable via
13334 @env{ARGP_HELP_FMT} environment variable. The value of this variable
13335 is a comma-separated list of @dfn{format variable} assignments. There
13336 are two kinds of format variables. An @dfn{offset variable} keeps the
13337 offset of some part of help output text from the leftmost column on
13338 the screen. A @dfn{boolean} variable is a flag that toggles some
13339 output feature on or off. Depending on the type of the corresponding
13340 variable, there are two kinds of assignments:
13342 @table @asis
13343 @item Offset assignment
13345 The assignment to an offset variable has the following syntax:
13347 @smallexample
13348 @var{variable}=@var{value}
13349 @end smallexample
13351 @noindent
13352 where @var{variable} is the variable name, and @var{value} is a
13353 numeric value to be assigned to the variable.
13355 @item Boolean assignment
13357 To assign @code{true} value to a variable, simply put this variable name. To
13358 assign @code{false} value, prefix the variable name with @samp{no-}. For
13359 example:
13361 @smallexample
13362 @group
13363 # Assign @code{true} value:
13364 dup-args
13365 # Assign @code{false} value:
13366 no-dup-args
13367 @end group
13368 @end smallexample
13369 @end table
13371 Following variables are declared:
13373 @deftypevr {Help Output} boolean dup-args
13374 If true, arguments for an option are shown with both short and long
13375 options, even when a given option has both forms, for example:
13377 @smallexample
13378   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
13379 @end smallexample
13381 If false, then if an option has both short and long forms, the
13382 argument is only shown with the long one, for example:
13384 @smallexample
13385   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13386 @end smallexample
13388 @noindent
13389 and a message indicating that the argument is applicable to both
13390 forms is printed below the options. This message can be disabled
13391 using @code{dup-args-note} (see below).
13393 The default is false.
13394 @end deftypevr
13396 @deftypevr {Help Output} boolean dup-args-note
13397 If this variable is true, which is the default, the following notice
13398 is displayed at the end of the help output:
13400 @quotation
13401 Mandatory or optional arguments to long options are also mandatory or
13402 optional for any corresponding short options.
13403 @end quotation
13405 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
13406 variables @code{dup-args} or @code{dup-args-note} should be set.
13407 @end deftypevr
13409 @deftypevr {Help Output} offset short-opt-col
13410 Column in which short options start. Default is 2.
13412 @smallexample
13413 @group
13414 $ @kbd{tar --help|grep ARCHIVE}
13415   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13416 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
13417       -f, --file=ARCHIVE   use archive file or device ARCHIVE
13418 @end group
13419 @end smallexample
13420 @end deftypevr
13422 @deftypevr {Help Output} offset long-opt-col
13423 Column in which long options start. Default is 6. For example:
13425 @smallexample
13426 @group
13427 $ @kbd{tar --help|grep ARCHIVE}
13428   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13429 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
13430   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
13431 @end group
13432 @end smallexample
13433 @end deftypevr
13435 @deftypevr {Help Output} offset doc-opt-col
13436 Column in which @dfn{doc options} start.  A doc option isn't actually
13437 an option, but rather an arbitrary piece of documentation that is
13438 displayed in much the same manner as the options.  For example, in
13439 the description of @option{--format} option:
13441 @smallexample
13442 @group
13443   -H, --format=FORMAT        create archive of the given format.
13445  FORMAT is one of the following:
13447     gnu                      GNU tar 1.13.x format
13448     oldgnu                   GNU format as per tar <= 1.12
13449     pax                      POSIX 1003.1-2001 (pax) format
13450     posix                    same as pax
13451     ustar                    POSIX 1003.1-1988 (ustar) format
13452     v7                       old V7 tar format
13453 @end group
13454 @end smallexample
13456 @noindent
13457 the format names are doc options. Thus, if you set
13458 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
13459 will look as follows:
13461 @smallexample
13462 @group
13463   -H, --format=FORMAT        create archive of the given format.
13465  FORMAT is one of the following:
13467         gnu                      GNU tar 1.13.x format
13468         oldgnu                   GNU format as per tar <= 1.12
13469         pax                      POSIX 1003.1-2001 (pax) format
13470         posix                    same as pax
13471         ustar                    POSIX 1003.1-1988 (ustar) format
13472         v7                       old V7 tar format
13473 @end group
13474 @end smallexample
13475 @end deftypevr
13477 @deftypevr {Help Output} offset opt-doc-col
13478 Column in which option description starts. Default is 29.
13480 @smallexample
13481 @group
13482 $ @kbd{tar --help|grep ARCHIVE}
13483   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13484 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
13485   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13486 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
13487   -f, --file=ARCHIVE
13488            use archive file or device ARCHIVE
13489 @end group
13490 @end smallexample
13492 @noindent
13493 Notice, that the description starts on a separate line if
13494 @code{opt-doc-col} value is too small.
13495 @end deftypevr
13497 @deftypevr {Help Output} offset header-col
13498 Column in which @dfn{group headers} are printed.  A group header is a
13499 descriptive text preceding an option group.  For example, in the
13500 following text:
13502 @verbatim
13503  Main operation mode:
13505   -A, --catenate, --concatenate   append tar files to
13506                              an archive
13507   -c, --create               create a new archive
13508 @end verbatim
13509 @noindent
13510 @samp{Main operation mode:} is the group header.
13512 The default value is 1.
13513 @end deftypevr
13515 @deftypevr {Help Output} offset usage-indent
13516 Indentation of wrapped usage lines. Affects @option{--usage}
13517 output. Default is 12.
13518 @end deftypevr
13520 @deftypevr {Help Output} offset rmargin
13521 Right margin of the text output. Used for wrapping.
13522 @end deftypevr
13524 @node Fixing Snapshot Files
13525 @appendix Fixing Snapshot Files
13526 @include tar-snapshot-edit.texi
13528 @node Tar Internals
13529 @appendix Tar Internals
13530 @include intern.texi
13532 @node Genfile
13533 @appendix Genfile
13534 @include genfile.texi
13536 @node GNU Free Documentation License
13537 @appendix GNU Free Documentation License
13539 @include fdl.texi
13541 @node Index of Command Line Options
13542 @appendix Index of Command Line Options
13544 This appendix contains an index of all @GNUTAR{} long command line
13545 options. The options are listed without the preceding double-dash.
13546 For a cross-reference of short command line options, see
13547 @ref{Short Option Summary}.
13549 @printindex op
13551 @node Index
13552 @appendix Index
13554 @printindex cp
13556 @summarycontents
13557 @contents
13558 @bye
13560 @c Local variables:
13561 @c texinfo-column-for-description: 32
13562 @c End: