Fix example use of find command in documentation
[tar.git] / doc / tar.texi
blobedce69a399e2a9c24e781e314c8280ffeec2eeab
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--2022 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::
189 * help::
190 * defaults::
191 * verbose::
192 * checkpoints::
193 * warnings::
194 * interactive::
196 The Three Option Styles
198 * Long Options::                Long Option Style
199 * Short Options::               Short Option Style
200 * Old Options::                 Old Option Style
201 * Mixing::                      Mixing Option Styles
203 All @command{tar} Options
205 * Operation Summary::
206 * Option Summary::
207 * Short Option Summary::
208 * Position-Sensitive Options::
210 @GNUTAR{} Operations
212 * Basic tar::
213 * Advanced tar::
214 * create options::
215 * extract options::
216 * backup::
217 * looking ahead::
219 Advanced @GNUTAR{} Operations
221 * Operations::
222 * append::
223 * update::
224 * concatenate::
225 * delete::
226 * compare::
228 How to Add Files to Existing Archives: @option{--append}
230 * appending files::             Appending Files to an Archive
231 * multiple::
233 Updating an Archive
235 * how to update::
237 Options Used by @option{--create}
239 * override::                  Overriding File Metadata.
240 * Extended File Attributes::
241 * Ignore Failed Read::
243 Options Used by @option{--extract}
245 * Reading::                     Options to Help Read Archives
246 * Writing::                     Changing How @command{tar} Writes Files
247 * Scarce::                      Coping with Scarce Resources
249 Options to Help Read Archives
251 * read full records::
252 * Ignore Zeros::
254 Changing How @command{tar} Writes Files
256 * Dealing with Old Files::
257 * Overwrite Old Files::
258 * Keep Old Files::
259 * Keep Newer Files::
260 * Unlink First::
261 * Recursive Unlink::
262 * Data Modification Times::
263 * Setting Access Permissions::
264 * Directory Modification Times and Permissions::
265 * Writing to Standard Output::
266 * Writing to an External Program::
267 * remove files::
269 Coping with Scarce Resources
271 * Starting File::
272 * Same Order::
274 Performing Backups and Restoring Files
276 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
277 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
278 * Backup Levels::               Levels of Backups
279 * Backup Parameters::           Setting Parameters for Backups and Restoration
280 * Scripted Backups::            Using the Backup Scripts
281 * Scripted Restoration::        Using the Restore Script
283 Setting Parameters for Backups and Restoration
285 * General-Purpose Variables::
286 * Magnetic Tape Control::
287 * User Hooks::
288 * backup-specs example::        An Example Text of @file{Backup-specs}
290 Choosing Files and Names for @command{tar}
292 * file::                        Choosing the Archive's Name
293 * Selecting Archive Members::
294 * files::                       Reading Names from a File
295 * exclude::                     Excluding Some Files
296 * wildcards::                   Wildcards Patterns and Matching
297 * quoting styles::              Ways of Quoting Special Characters in Names
298 * transform::                   Modifying File and Member Names
299 * after::                       Operating Only on New Files
300 * recurse::                     Descending into Directories
301 * one::                         Crossing File System Boundaries
303 Reading Names from a File
305 * nul::
307 Excluding Some Files
309 * problems with exclude::
311 Wildcards Patterns and Matching
313 * controlling pattern-matching::
315 Crossing File System Boundaries
317 * directory::                   Changing Directory
318 * absolute::                    Absolute File Names
320 Date input formats
322 * General date syntax::            Common rules.
323 * Calendar date items::            19 Dec 1994.
324 * Time of day items::              9:20pm.
325 * Time zone items::                @sc{est}, @sc{pdt}, @sc{gmt}.
326 * Day of week items::              Monday and others.
327 * Relative items in date strings:: next tuesday, 2 years ago.
328 * Pure numbers in date strings::   19931219, 1440.
329 * Seconds since the Epoch::        @@1078100502.
330 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
331 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
333 Controlling the Archive Format
335 * Compression::                 Using Less Space through Compression
336 * Attributes::                  Handling File Attributes
337 * Portability::                 Making @command{tar} Archives More Portable
338 * cpio::                        Comparison of @command{tar} and @command{cpio}
340 Using Less Space through Compression
342 * gzip::                        Creating and Reading Compressed Archives
343 * sparse::                      Archiving Sparse Files
345 Creating and Reading Compressed Archives
347 * lbzip2::  Using lbzip2 with @GNUTAR{}.
349 Making @command{tar} Archives More Portable
351 * Portable Names::              Portable Names
352 * dereference::                 Symbolic Links
353 * hard links::                  Hard Links
354 * old::                         Old V7 Archives
355 * ustar::                       Ustar Archives
356 * gnu::                         GNU and old GNU format archives.
357 * posix::                       @acronym{POSIX} archives
358 * Checksumming::                Checksumming Problems
359 * Large or Negative Values::    Large files, negative time stamps, etc.
360 * Other Tars::                  How to Extract GNU-Specific Data Using
361                                 Other @command{tar} Implementations
363 @GNUTAR{} and @acronym{POSIX} @command{tar}
365 * PAX keywords:: Controlling Extended Header Keywords.
367 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
369 * Split Recovery::       Members Split Between Volumes
370 * Sparse Recovery::      Sparse Members
372 Tapes and Other Archive Media
374 * Device::                      Device selection and switching
375 * Remote Tape Server::
376 * Common Problems and Solutions::
377 * Blocking::                    Blocking
378 * Many::                        Many archives on one tape
379 * Using Multiple Tapes::        Using Multiple Tapes
380 * label::                       Including a Label in the Archive
381 * verify::
382 * Write Protection::
384 Blocking
386 * Format Variations::           Format Variations
387 * Blocking Factor::             The Blocking Factor of an Archive
389 Many Archives on One Tape
391 * Tape Positioning::            Tape Positions and Tape Marks
392 * mt::                          The @command{mt} Utility
394 Using Multiple Tapes
396 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
397 * Tape Files::                  Tape Files
398 * Tarcat::                      Concatenate Volumes into a Single Archive
401 Tar Internals
403 * Standard::           Basic Tar Format
404 * Extensions::         @acronym{GNU} Extensions to the Archive Format
405 * Sparse Formats::     Storing Sparse Files
406 * Snapshot Files::
407 * Dumpdir::
409 Storing Sparse Files
411 * Old GNU Format::
412 * PAX 0::                PAX Format, Versions 0.0 and 0.1
413 * PAX 1::                PAX Format, Version 1.0
415 Genfile
417 * Generate Mode::     File Generation Mode.
418 * Status Mode::       File Status Mode.
419 * Exec Mode::         Synchronous Execution mode.
421 Copying This Manual
423 * GNU Free Documentation License::  License for copying this manual
425 @end detailmenu
426 @end menu
428 @node Introduction
429 @chapter Introduction
431 @GNUTAR{} creates
432 and manipulates @dfn{archives} which are actually collections of
433 many other files; the program provides users with an organized and
434 systematic method for controlling a large amount of data.
435 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
436 archives need not (and these days, typically do not) reside on tapes.
438 @menu
439 * Book Contents::               What this Book Contains
440 * Definitions::                 Some Definitions
441 * What tar Does::               What @command{tar} Does
442 * Naming tar Archives::         How @command{tar} Archives are Named
443 * Authors::                     @GNUTAR{} Authors
444 * Reports::                     Reporting bugs or suggestions
445 @end menu
447 @node Book Contents
448 @section What this Book Contains
450 The first part of this chapter introduces you to various terms that will
451 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
452 and its documentation, and where you should send bug reports
453 or comments.
455 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
456 gentle introduction for people who are new to using @command{tar}.  It is
457 meant to be self-contained, not requiring any reading from subsequent
458 chapters to make sense.  It moves from topic to topic in a logical,
459 progressive order, building on information already explained.
461 Although the tutorial is paced and structured to allow beginners to
462 learn how to use @command{tar}, it is not intended solely for beginners.
463 The tutorial explains how to use the three most frequently used
464 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
465 two frequently used options (@samp{file} and @samp{verbose}).  The other
466 chapters do not refer to the tutorial frequently; however, if a section
467 discusses something which is a complex variant of a basic concept, there
468 may be a cross-reference to that basic concept.  (The entire book,
469 including the tutorial, assumes that the reader understands some basic
470 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
472 The third chapter presents the remaining five operations, and
473 information about using @command{tar} options and option syntax.
475 The other chapters are meant to be used as a reference.  Each chapter
476 presents everything that needs to be said about a specific topic.
478 One of the chapters (@pxref{Date input formats}) exists in its
479 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
480 In addition, one section of this manual (@pxref{Standard}) contains a
481 big quote which is taken directly from @command{tar} sources.
483 In general, we give both long and short (abbreviated) option names
484 at least once in each section where the relevant option is covered, so
485 that novice readers will become familiar with both styles.  (A few
486 options have no short versions, and the relevant sections will
487 indicate this.)
489 @node Definitions
490 @section Some Definitions
492 @cindex archive
493 @cindex tar archive
494 The @command{tar} program is used to create and manipulate @command{tar}
495 archives.  An @dfn{archive} is a single file which contains the contents
496 of many files, while still identifying the names of the files, their
497 owner(s), and so forth.  (In addition, archives record access
498 permissions, user and group, size in bytes, and data modification time.
499 Some archives also record the file names in each archived directory, as
500 well as other file and directory information.)  You can use @command{tar}
501 to @dfn{create} a new archive in a specified directory.
503 @cindex member
504 @cindex archive member
505 @cindex file name
506 @cindex member name
507 The files inside an archive are called @dfn{members}.  Within this
508 manual, we use the term @dfn{file} to refer only to files accessible in
509 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
510 @dfn{member} to refer only to the members of an archive.  Similarly, a
511 @dfn{file name} is the name of a file, as it resides in the file system,
512 and a @dfn{member name} is the name of an archive member within the
513 archive.
515 @cindex extraction
516 @cindex unpacking
517 The term @dfn{extraction} refers to the process of copying an archive
518 member (or multiple members) into a file in the file system.  Extracting
519 all the members of an archive is often called @dfn{extracting the
520 archive}.  The term @dfn{unpack} can also be used to refer to the
521 extraction of many or all the members of an archive.  Extracting an
522 archive does not destroy the archive's structure, just as creating an
523 archive does not destroy the copies of the files that exist outside of
524 the archive.  You may also @dfn{list} the members in a given archive
525 (this is often thought of as ``printing'' them to the standard output,
526 or the command line), or @dfn{append} members to a pre-existing archive.
527 All of these operations can be performed using @command{tar}.
529 @node What tar Does
530 @section What @command{tar} Does
532 @cindex tar
533 The @command{tar} program provides the ability to create @command{tar}
534 archives, as well as various other kinds of manipulation.  For example,
535 you can use @command{tar} on previously created archives to extract files,
536 to store additional files, or to update or list files which were already
537 stored.
539 Initially, @command{tar} archives were used to store files conveniently on
540 magnetic tape.  The name @command{tar} comes from this use; it stands for
541 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
542 direct its output to available devices, files, or other programs (using
543 pipes).  @command{tar} may even access remote devices or files (as archives).
545 You can use @command{tar} archives in many ways.  We want to stress a few
546 of them: storage, backup, and transportation.
548 @FIXME{the following table entries need a bit of work.}
549 @table @asis
550 @item Storage
551 Often, @command{tar} archives are used to store related files for
552 convenient file transfer over a network.  For example, the
553 @acronym{GNU} Project distributes its software bundled into
554 @command{tar} archives, so that all the files relating to a particular
555 program (or set of related programs) can be transferred as a single
556 unit.
558 A magnetic tape can store several files in sequence.  However, the tape
559 has no names for these files; it only knows their relative position on
560 the tape.  One way to store several files on one tape and retain their
561 names is by creating a @command{tar} archive.  Even when the basic transfer
562 mechanism can keep track of names, as FTP can, the nuisance of handling
563 multiple files, directories, and multiple links makes @command{tar}
564 archives useful.
566 Archive files are also used for long-term storage.  You can think of
567 this as transportation from the present into the future.  (It is a
568 science-fiction idiom that you can move through time as well as in
569 space; the idea here is that @command{tar} can be used to move archives in
570 all dimensions, even time!)
572 @item Backup
573 Because the archive created by @command{tar} is capable of preserving
574 file information and directory structure, @command{tar} is commonly
575 used for performing full and incremental backups of disks.  A backup
576 puts a collection of files (possibly pertaining to many users and
577 projects) together on a disk or a tape.  This guards against
578 accidental destruction of the information in those files.
579 @GNUTAR{} has special features that allow it to be
580 used to make incremental and full dumps of all the files in a
581 file system.
583 @item Transportation
584 You can create an archive on one system, transfer it to another system,
585 and extract the contents there.  This allows you to transport a group of
586 files from one system to another.
587 @end table
589 @node Naming tar Archives
590 @section How @command{tar} Archives are Named
592 Conventionally, @command{tar} archives are given names ending with
593 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
594 but this manual follows that convention in order to accustom readers to
595 it and to make examples more clear.
597 @cindex tar file
598 @cindex entry
599 @cindex tar entry
600 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
601 archive members as ``files'' or ``entries''.  For people familiar with
602 the operation of @command{tar}, this causes no difficulty.  However, in
603 this manual, we consistently refer to ``archives'' and ``archive
604 members'' to make learning to use @command{tar} easier for novice users.
606 @node Authors
607 @section @GNUTAR{} Authors
609 @GNUTAR{} was originally written by John Gilmore,
610 and modified by many people.  The @acronym{GNU} enhancements were
611 written by Jay Fenlason, then Joy Kendall, and the whole package has
612 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
613 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
614 numerous and kind users.
616 We wish to stress that @command{tar} is a collective work, and owes much to
617 all those people who reported problems, offered solutions and other
618 insights, or shared their thoughts and suggestions.  An impressive, yet
619 partial list of those contributors can be found in the @file{THANKS}
620 file from the @GNUTAR{} distribution.
622 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
623 sure i want to spell out the history in this detail, at least not for
624 the printed book.  i'm just not sure it needs to be said this way.
625 i'll think about it.}
627 @FIXME{History is more important, and surely more interesting, than
628 actual names.  Quoting names without history would be meaningless.  FP}
630 Jay Fenlason put together a draft of a @GNUTAR{}
631 manual, borrowing notes from the original man page from John Gilmore.
632 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
633 Gorin worked on a tutorial and manual for @GNUTAR{}.
634 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
635 taking information from all these sources and merging them.  Melissa
636 Weisshaus finally edited and redesigned the book to create version
637 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
638 by the current maintainer, Sergey Poznyakoff.
640 For version 1.12, Daniel Hagerty contributed a great deal of technical
641 consulting.  In particular, he is the primary author of @ref{Backups}.
643 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
644 (see @url{http://savannah.gnu.org/projects/tar}), and
645 active development and maintenance work has started
646 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
647 Poznyakoff and Jeff Bailey.
649 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
651 @node Reports
652 @section Reporting bugs or suggestions
654 @cindex bug reports
655 @cindex reporting bugs
656 If you find problems or have suggestions about this program or manual,
657 please report them to @file{bug-tar@@gnu.org}.
659 When reporting a bug, please be sure to include as much detail as
660 possible, in order to reproduce it.
661 @FIXME{Be more specific, I'd like to make this node as detailed as
662 'Bug reporting' node in Emacs manual.}
664 @node Tutorial
665 @chapter Tutorial Introduction to @command{tar}
667 This chapter guides you through some basic examples of three @command{tar}
668 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
669 you already know how to use some other version of @command{tar}, then you
670 may not need to read this chapter.  This chapter omits most complicated
671 details about how @command{tar} works.
673 @menu
674 * assumptions::
675 * stylistic conventions::
676 * basic tar options::           Basic @command{tar} Operations and Options
677 * frequent operations::
678 * Two Frequent Options::
679 * create::                      How to Create Archives
680 * list::                        How to List Archives
681 * extract::                     How to Extract Members from an Archive
682 * going further::
683 @end menu
685 @node assumptions
686 @section Assumptions this Tutorial Makes
688 This chapter is paced to allow beginners to learn about @command{tar}
689 slowly.  At the same time, we will try to cover all the basic aspects of
690 these three operations.  In order to accomplish both of these tasks, we
691 have made certain assumptions about your knowledge before reading this
692 manual, and the hardware you will be using:
694 @itemize @bullet
695 @item
696 Before you start to work through this tutorial, you should understand
697 what the terms ``archive'' and ``archive member'' mean
698 (@pxref{Definitions}).  In addition, you should understand something
699 about how Unix-type operating systems work, and you should know how to
700 use some basic utilities.  For example, you should know how to create,
701 list, copy, rename, edit, and delete files and directories; how to
702 change between directories; and how to figure out where you are in the
703 file system.  You should have some basic understanding of directory
704 structure and how files are named according to which directory they are
705 in.  You should understand concepts such as standard output and standard
706 input, what various definitions of the term @samp{argument} mean, and the
707 differences between relative and absolute file names.
708 @FIXME{and what else?}
710 @item
711 This manual assumes that you are working from your own home directory
712 (unless we state otherwise).  In this tutorial, you will create a
713 directory to practice @command{tar} commands in.  When we show file names,
714 we will assume that those names are relative to your home directory.
715 For example, my home directory is @file{/home/fsf/melissa}.  All of
716 my examples are in a subdirectory of the directory named by that file
717 name; the subdirectory is called @file{practice}.
719 @item
720 In general, we show examples of archives which exist on (or can be
721 written to, or worked with from) a directory on a hard disk.  In most
722 cases, you could write those archives to, or work with them on any other
723 device, such as a tape drive.  However, some of the later examples in
724 the tutorial and next chapter will not work on tape drives.
725 Additionally, working with tapes is much more complicated than working
726 with hard disks.  For these reasons, the tutorial does not cover working
727 with tape drives.  @xref{Media}, for complete information on using
728 @command{tar} archives with tape drives.
730 @FIXME{this is a cop out.  need to add some simple tape drive info.}
731 @end itemize
733 @node stylistic conventions
734 @section Stylistic Conventions
736 In the examples, @samp{$} represents a typical shell prompt.  It
737 precedes lines you should type; to make this more clear, those lines are
738 shown in @kbd{this font}, as opposed to lines which represent the
739 computer's response; those lines are shown in @code{this font}, or
740 sometimes @samp{like this}.
742 @c When we have lines which are too long to be
743 @c displayed in any other way, we will show them like this:
745 @node basic tar options
746 @section Basic @command{tar} Operations and Options
748 @command{tar} can take a wide variety of arguments which specify and define
749 the actions it will have on the particular set of files or the archive.
750 The main types of arguments to @command{tar} fall into one of two classes:
751 operations, and options.
753 Some arguments fall into a class called @dfn{operations}; exactly one of
754 these is both allowed and required for any instance of using @command{tar};
755 you may @emph{not} specify more than one.  People sometimes speak of
756 @dfn{operating modes}.  You are in a particular operating mode when you
757 have specified the operation which specifies it; there are eight
758 operations in total, and thus there are eight operating modes.
760 The other arguments fall into the class known as @dfn{options}.  You are
761 not required to specify any options, and you are allowed to specify more
762 than one at a time (depending on the way you are using @command{tar} at
763 that time).  Some options are used so frequently, and are so useful for
764 helping you type commands more carefully that they are effectively
765 ``required''.  We will discuss them in this chapter.
767 You can write most of the @command{tar} operations and options in any
768 of three forms: long (mnemonic) form, short form, and old style.  Some
769 of the operations and options have no short or ``old'' forms; however,
770 the operations and options which we will cover in this tutorial have
771 corresponding abbreviations.  We will indicate those abbreviations
772 appropriately to get you used to seeing them.  Note, that the ``old
773 style'' option forms exist in @GNUTAR{} for compatibility with Unix
774 @command{tar}.  In this book we present a full discussion of this way
775 of writing options and operations (@pxref{Old Options}), and we discuss
776 the other two styles of writing options (@xref{Long Options}, and
777 @pxref{Short Options}).
779 In the examples and in the text of this tutorial, we usually use the
780 long forms of operations and options; but the ``short'' forms produce
781 the same result and can make typing long @command{tar} commands easier.
782 For example, instead of typing
784 @smallexample
785 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
786 @end smallexample
788 @noindent
789 you can type
790 @smallexample
791 @kbd{tar -c -v -f afiles.tar apple angst aspic}
792 @end smallexample
794 @noindent
795 or even
796 @smallexample
797 @kbd{tar -cvf afiles.tar apple angst aspic}
798 @end smallexample
800 @noindent
801 For more information on option syntax, see @ref{Advanced tar}.  In
802 discussions in the text, when we name an option by its long form, we
803 also give the corresponding short option in parentheses.
805 The term, ``option'', can be confusing at times, since ``operations''
806 are often lumped in with the actual, @emph{optional} ``options'' in certain
807 general class statements.  For example, we just talked about ``short and
808 long forms of options and operations''.  However, experienced @command{tar}
809 users often refer to these by shorthand terms such as, ``short and long
810 options''.  This term assumes that the ``operations'' are included, also.
811 Context will help you determine which definition of ``options'' to use.
813 Similarly, the term ``command'' can be confusing, as it is often used in
814 two different ways.  People sometimes refer to @command{tar} ``commands''.
815 A @command{tar} @dfn{command} is the entire command line of user input
816 which tells @command{tar} what to do --- including the operation, options,
817 and any arguments (file names, pipes, other commands, etc.).  However,
818 you will also sometimes hear the term ``the @command{tar} command''.  When
819 the word ``command'' is used specifically like this, a person is usually
820 referring to the @command{tar} @emph{operation}, not the whole line.
821 Again, use context to figure out which of the meanings the speaker
822 intends.
824 @node frequent operations
825 @section The Three Most Frequently Used Operations
827 Here are the three most frequently used operations (both short and long
828 forms), as well as a brief description of their meanings.  The rest of
829 this chapter will cover how to use these operations in detail.  We will
830 present the rest of the operations in the next chapter.
832 @table @option
833 @item --create
834 @itemx -c
835 Create a new @command{tar} archive.
836 @item --list
837 @itemx -t
838 List the contents of an archive.
839 @item --extract
840 @itemx -x
841 Extract one or more members from an archive.
842 @end table
844 @node Two Frequent Options
845 @section Two Frequently Used Options
847 To understand how to run @command{tar} in the three operating modes listed
848 previously, you also need to understand how to use two of the options to
849 @command{tar}: @option{--file} (which takes an archive file as an argument)
850 and @option{--verbose}.  (You are usually not @emph{required} to specify
851 either of these options when you run @command{tar}, but they can be very
852 useful in making things more clear and helping you avoid errors.)
854 @menu
855 * file tutorial::
856 * verbose tutorial::
857 * help tutorial::
858 @end menu
860 @node file tutorial
861 @unnumberedsubsec The @option{--file} Option
863 @table @option
864 @xopindex{file, tutorial}
865 @item --file=@var{archive-name}
866 @itemx -f @var{archive-name}
867 Specify the name of an archive file.
868 @end table
870 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
871 use @command{tar}; this option determines the name of the archive file
872 that @command{tar} will work on.
874 @vrindex TAPE
875 If you don't specify this argument, then @command{tar} will examine
876 the environment variable @env{TAPE}.  If it is set, its value will be
877 used as the archive name.  Otherwise, @command{tar} will use the
878 default archive, determined at compile time. Usually it is
879 standard output or some physical tape drive attached to your machine
880 (you can verify what the default is by running @kbd{tar
881 --show-defaults}, @pxref{defaults}).  If there is no tape drive
882 attached, or the default is not meaningful, then @command{tar} will
883 print an error message.  The error message might look roughly like one
884 of the following:
886 @smallexample
887 tar: can't open /dev/rmt8 : No such device or address
888 tar: can't open /dev/rsmt0 : I/O error
889 @end smallexample
891 @noindent
892 To avoid confusion, we recommend that you always specify an archive file
893 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
894 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
895 @ref{file}.
897 @node verbose tutorial
898 @unnumberedsubsec The @option{--verbose} Option
900 @table @option
901 @xopindex{verbose, introduced}
902 @item --verbose
903 @itemx -v
904 Show the files being worked on as @command{tar} is running.
905 @end table
907 @option{--verbose} (@option{-v}) shows details about the results of running
908 @command{tar}.  This can be especially useful when the results might not be
909 obvious.  For example, if you want to see the progress of @command{tar} as
910 it writes files into the archive, you can use the @option{--verbose}
911 option.  In the beginning, you may find it useful to use
912 @option{--verbose} at all times; when you are more accustomed to
913 @command{tar}, you will likely want to use it at certain times but not at
914 others.  We will use @option{--verbose} at times to help make something
915 clear, and we will give many examples both using and not using
916 @option{--verbose} to show the differences.
918 Each instance of @option{--verbose} on the command line increases the
919 verbosity level by one, so if you need more details on the output,
920 specify it twice.
922 When reading archives (@option{--list}, @option{--extract},
923 @option{--diff}), @command{tar} by default prints only the names of
924 the members being extracted.  Using @option{--verbose} will show a full,
925 @command{ls} style member listing.
927 In contrast, when writing archives (@option{--create}, @option{--append},
928 @option{--update}), @command{tar} does not print file names by
929 default.  So, a single @option{--verbose} option shows the file names
930 being added to the archive, while two @option{--verbose} options
931 enable the full listing.
933 For example, to create an archive in verbose mode:
935 @smallexample
936 $ @kbd{tar -cvf afiles.tar apple angst aspic}
937 apple
938 angst
939 aspic
940 @end smallexample
942 @noindent
943 Creating the same archive with the verbosity level 2 could give:
945 @smallexample
946 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
947 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
948 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
949 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
950 @end smallexample
952 @noindent
953 This works equally well using short or long forms of options.  Using
954 long forms, you would simply write out the mnemonic form of the option
955 twice, like this:
957 @smallexample
958 $ @kbd{tar --create --verbose --verbose @dots{}}
959 @end smallexample
961 @noindent
962 Note that you must double the hyphens properly each time.
964 Later in the tutorial, we will give examples using @w{@option{--verbose
965 --verbose}}.
967 @anchor{verbose member listing}
968 The full output consists of six fields:
970 @itemize @bullet
971 @item File type and permissions in symbolic form.
972 These are displayed in the same format as the first column of
973 @command{ls -l} output (@pxref{What information is listed,
974 format=verbose, Verbose listing, fileutils, GNU file utilities}).
976 @item Owner name and group separated by a slash character.
977 If these data are not available (for example, when listing a @samp{v7} format
978 archive), numeric @acronym{ID} values are printed instead.
980 @item Size of the file, in bytes.
982 @item File modification date in ISO 8601 format.
984 @item File modification time.
986 @item File name.
987 If the name contains any special characters (white space, newlines,
988 etc.)@: these are displayed in an unambiguous form using so called
989 @dfn{quoting style}.  For the detailed discussion of available styles
990 and on how to use them, see @ref{quoting styles}.
992 Depending on the file type, the name can be followed by some
993 additional information, described in the following table:
995 @table @samp
996 @item -> @var{link-name}
997 The file or archive member is a @dfn{symbolic link} and
998 @var{link-name} is the name of file it links to.
1000 @item link to @var{link-name}
1001 The file or archive member is a @dfn{hard link} and @var{link-name} is
1002 the name of file it links to.
1004 @item --Long Link--
1005 The archive member is an old GNU format long link.  You will normally
1006 not encounter this.
1008 @item --Long Name--
1009 The archive member is an old GNU format long name.  You will normally
1010 not encounter this.
1012 @item --Volume Header--
1013 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1015 @item --Continued at byte @var{n}--
1016 Encountered only at the beginning of a multi-volume archive
1017 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1018 from the previous volume. The number @var{n} gives the offset where
1019 the original file was split.
1021 @item  unknown file type @var{c}
1022 An archive member of unknown type. @var{c} is the type character from
1023 the archive header.  If you encounter such a message, it means that
1024 either your archive contains proprietary member types @GNUTAR{} is not
1025 able to handle, or the archive is corrupted.
1026 @end table
1028 @end itemize
1030 For example, here is an archive listing containing most of the special
1031 suffixes explained above:
1033 @smallexample
1034 @group
1035 V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
1036 -rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1037 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
1038 lrwxrwxrwx gray/staff        0 2006-06-09 13:01 angst -> apple
1039 -rw-r--r-- gray/staff    35793 2006-06-09 12:06 blues
1040 hrw-r--r-- gray/staff        0 2006-06-09 12:06 music link to blues
1041 @end group
1042 @end smallexample
1044 @smallexample
1045 @end smallexample
1047 @node help tutorial
1048 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1050 @table @option
1051 @opindex help
1052 @item --help
1054 The @option{--help} option to @command{tar} prints out a very brief list of
1055 all operations and option available for the current version of
1056 @command{tar} available on your system.
1057 @end table
1059 @node create
1060 @section How to Create Archives
1062 @cindex Creation of the archive
1063 @cindex Archive, creation of
1064 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1065 you use to create a @command{tar} archive.  We will explain
1066 @option{--create} first because, in order to learn about the other
1067 operations, you will find it useful to have an archive available to
1068 practice on.
1070 To make this easier, in this section you will first create a directory
1071 containing three files.  Then, we will show you how to create an
1072 @emph{archive} (inside the new directory).  Both the directory, and
1073 the archive are specifically for you to practice on.  The rest of this
1074 chapter and the next chapter will show many examples using this
1075 directory and the files you will create: some of those files may be
1076 other directories and other archives.
1078 The three files you will archive in this example are called
1079 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1080 @file{collection.tar}.
1082 This section will proceed slowly, detailing how to use @option{--create}
1083 in @code{verbose} mode, and showing examples using both short and long
1084 forms.  In the rest of the tutorial, and in the examples in the next
1085 chapter, we will proceed at a slightly quicker pace.  This section
1086 moves more slowly to allow beginning users to understand how
1087 @command{tar} works.
1089 @menu
1090 * prepare for examples::
1091 * Creating the archive::
1092 * create verbose::
1093 * short create::
1094 * create dir::
1095 @end menu
1097 @node prepare for examples
1098 @subsection Preparing a Practice Directory for Examples
1100 To follow along with this and future examples, create a new directory
1101 called @file{practice} containing files called @file{blues}, @file{folk}
1102 and @file{jazz}.  The files can contain any information you like:
1103 ideally, they should contain information which relates to their names,
1104 and be of different lengths.  Our examples assume that @file{practice}
1105 is a subdirectory of your home directory.
1107 Now @command{cd} to the directory named @file{practice}; @file{practice}
1108 is now your @dfn{working directory}.  (@emph{Please note}: Although
1109 the full file name of this directory is
1110 @file{/@var{homedir}/practice}, in our examples we will refer to
1111 this directory as @file{practice}; the @var{homedir} is presumed.)
1113 In general, you should check that the files to be archived exist where
1114 you think they do (in the working directory) by running @command{ls}.
1115 Because you just created the directory and the files and have changed to
1116 that directory, you probably don't need to do that this time.
1118 It is very important to make sure there isn't already a file in the
1119 working directory with the archive name you intend to use (in this case,
1120 @samp{collection.tar}), or that you don't care about its contents.
1121 Whenever you use @samp{create}, @command{tar} will erase the current
1122 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1123 will not tell you if you are about to overwrite an archive unless you
1124 specify an option which does this (@pxref{backup}, for the
1125 information on how to do so).  To add files to an existing archive,
1126 you need to use a different option, such as @option{--append} (@option{-r}); see
1127 @ref{append} for information on how to do this.
1129 @node Creating the archive
1130 @subsection Creating the Archive
1132 @xopindex{create, introduced}
1133 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1134 archive named @file{collection.tar}, use the following command:
1136 @smallexample
1137 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1138 @end smallexample
1140 The order of the arguments is not very important, @emph{when using long
1141 option forms}, however you should always remember to use option as the
1142 first argument to tar.   For example, the following is wrong:
1144 @smallexample
1145 $ @kbd{tar blues -c folk -f collection.tar jazz}
1146 tar: -c: Invalid blocking factor
1147 Try 'tar --help' or 'tar --usage' for more information.
1148 @end smallexample
1150 The error message is produced because @command{tar} always treats its
1151 first argument as an option (or cluster of options), even if it does
1152 not start with dash.  This is @dfn{traditional} or @dfn{old option}
1153 style, called so because all implementations of @command{tar} have
1154 used it since the very inception of the tar archiver in 1970s.  This
1155 option style will be explained later (@pxref{Old Options}), for now
1156 just remember to always place option as the first argument.
1158 That being said, you could issue the following command:
1160 @smallexample
1161 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1162 @end smallexample
1164 @noindent
1165 However, you can see that this order is harder to understand; this is
1166 why we will list the arguments in the order that makes the commands
1167 easiest to understand (and we encourage you to do the same when you use
1168 @command{tar}, to avoid errors).
1170 Note that the sequence
1171 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1172 If you substituted any other string of characters for
1173 @kbd{collection.tar},  then that string would become the name of the
1174 archive file you create.
1176 The order of the options becomes more important when you begin to use
1177 short forms.  With short forms, if you type commands in the wrong order
1178 (even if you type them correctly in all other ways), you may end up with
1179 results you don't expect.  For this reason, it is a good idea to get
1180 into the habit of typing options in the order that makes inherent sense.
1181 @xref{short create}, for more information on this.
1183 In this example, you type the command as shown above: @option{--create}
1184 is the operation which creates the new archive
1185 (@file{collection.tar}), and @option{--file} is the option which lets
1186 you give it the name you chose.  The files, @file{blues}, @file{folk},
1187 and @file{jazz}, are now members of the archive, @file{collection.tar}
1188 (they are @dfn{file name arguments} to the @option{--create} operation.
1189 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1190 in the archive, they are called @emph{archive members}, not files.
1191 (@pxref{Definitions,members}).
1193 When you create an archive, you @emph{must} specify which files you
1194 want placed in the archive.  If you do not specify any archive
1195 members, @GNUTAR{} will complain.
1197 If you now list the contents of the working directory (@command{ls}), you will
1198 find the archive file listed as well as the files you saw previously:
1200 @smallexample
1201 blues   folk   jazz   collection.tar
1202 @end smallexample
1204 @noindent
1205 Creating the archive @samp{collection.tar} did not destroy the copies of
1206 the files in the directory.
1208 Keep in mind that if you don't indicate an operation, @command{tar} will not
1209 run and will prompt you for one.  If you don't name any files, @command{tar}
1210 will complain.  You must have write access to the working directory,
1211 or else you will not be able to create an archive in that directory.
1213 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1214 an existing archive; it will delete the archive and write a new one.
1215 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1217 @node create verbose
1218 @subsection Running @option{--create} with @option{--verbose}
1220 @xopindex{create, using with @option{--verbose}}
1221 @xopindex{verbose, using with @option{--create}}
1222 If you include the @option{--verbose} (@option{-v}) option on the command line,
1223 @command{tar} will list the files it is acting on as it is working.  In
1224 verbose mode, the @code{create} example above would appear as:
1226 @smallexample
1227 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1228 blues
1229 folk
1230 jazz
1231 @end smallexample
1233 This example is just like the example we showed which did not use
1234 @option{--verbose}, except that @command{tar} generated three output
1235 lines.
1237 In the rest of the examples in this chapter, we will frequently use
1238 @code{verbose} mode so we can show actions or @command{tar} responses that
1239 you would otherwise not see, and which are important for you to
1240 understand.
1242 @node short create
1243 @subsection Short Forms with @samp{create}
1245 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1246 basic uses of @command{tar}, and you will use it countless times.
1247 Eventually, you will probably want to use abbreviated (or ``short'')
1248 forms of options.  A full discussion of the three different forms that
1249 options can take appears in @ref{Styles}; for now, here is what the
1250 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1251 using short option forms:
1253 @smallexample
1254 $ @kbd{tar -cvf collection.tar blues folk jazz}
1255 blues
1256 folk
1257 jazz
1258 @end smallexample
1260 @noindent
1261 As you can see, the system responds the same no matter whether you use
1262 long or short option forms.
1264 @FIXME{i don't like how this is worded:} One difference between using
1265 short and long option forms is that, although the exact placement of
1266 arguments following options is no more specific when using short forms,
1267 it is easier to become confused and make a mistake when using short
1268 forms.  For example, suppose you attempted the above example in the
1269 following way:
1271 @smallexample
1272 $ @kbd{tar -cfv collection.tar blues folk jazz}
1273 @end smallexample
1275 @noindent
1276 In this case, @command{tar} will make an archive file called @file{v},
1277 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1278 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1279 is thus taken to be the chosen archive file name.  @command{tar} will try
1280 to add a file called @file{collection.tar} to the @file{v} archive file;
1281 if the file @file{collection.tar} did not already exist, @command{tar} will
1282 report an error indicating that this file does not exist.  If the file
1283 @file{collection.tar} does already exist (e.g., from a previous command
1284 you may have run), then @command{tar} will add this file to the archive.
1285 Because the @option{-v} option did not get registered, @command{tar} will not
1286 run under @samp{verbose} mode, and will not report its progress.
1288 The end result is that you may be quite confused about what happened,
1289 and possibly overwrite a file.  To illustrate this further, we will show
1290 you how an example we showed previously would look using short forms.
1292 This example,
1294 @smallexample
1295 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1296 @end smallexample
1298 @noindent
1299 is confusing as it is.  It becomes even more so when using short forms:
1301 @smallexample
1302 $ @kbd{tar -c folk blues -f collection.tar jazz}
1303 @end smallexample
1305 @noindent
1306 It would be very easy to put the wrong string of characters
1307 immediately following the @option{-f}, but doing that could sacrifice
1308 valuable data.
1310 For this reason, we recommend that you pay very careful attention to
1311 the order of options and placement of file and archive names,
1312 especially when using short option forms.  Not having the option name
1313 written out mnemonically can affect how well you remember which option
1314 does what, and therefore where different names have to be placed.
1316 @node create dir
1317 @subsection Archiving Directories
1319 @cindex Archiving Directories
1320 @cindex Directories, Archiving
1321 You can archive a directory by specifying its directory name as a
1322 file name argument to @command{tar}.  The files in the directory will be
1323 archived relative to the working directory, and the directory will be
1324 re-created along with its contents when the archive is extracted.
1326 To archive a directory, first move to its superior directory.  If you
1327 have followed the previous instructions in this tutorial, you should
1328 type:
1330 @smallexample
1331 $ @kbd{cd ..}
1333 @end smallexample
1335 @noindent
1336 This will put you into the directory which contains @file{practice},
1337 i.e., your home directory.  Once in the superior directory, you can
1338 specify the subdirectory, @file{practice}, as a file name argument.  To
1339 store @file{practice} in the new archive file @file{music.tar}, type:
1341 @smallexample
1342 $ @kbd{tar --create --verbose --file=music.tar practice}
1343 @end smallexample
1345 @noindent
1346 @command{tar} should output:
1348 @smallexample
1349 practice/
1350 practice/blues
1351 practice/folk
1352 practice/jazz
1353 practice/collection.tar
1354 @end smallexample
1356 Note that the archive thus created is not in the subdirectory
1357 @file{practice}, but rather in the current working directory---the
1358 directory from which @command{tar} was invoked.  Before trying to archive a
1359 directory from its superior directory, you should make sure you have
1360 write access to the superior directory itself, not only the directory
1361 you are trying archive with @command{tar}.  For example, you will probably
1362 not be able to store your home directory in an archive by invoking
1363 @command{tar} from the root directory; @xref{absolute}.  (Note
1364 also that @file{collection.tar}, the original archive file, has itself
1365 been archived.  @command{tar} will accept any file as a file to be
1366 archived, regardless of its content.  When @file{music.tar} is
1367 extracted, the archive file @file{collection.tar} will be re-written
1368 into the file system).
1370 If you give @command{tar} a command such as
1372 @smallexample
1373 $ @kbd{tar --create --file=foo.tar .}
1374 @end smallexample
1376 @noindent
1377 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1378 dumped}.  This happens because @command{tar} creates the archive
1379 @file{foo.tar} in the current directory before putting any files into
1380 it.  Then, when @command{tar} attempts to add all the files in the
1381 directory @file{.} to the archive, it notices that the file
1382 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1383 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1384 will continue in this case, and create the archive
1385 normally, except for the exclusion of that one file.  (@emph{Please
1386 note:} Other implementations of @command{tar} may not be so clever;
1387 they will enter an infinite loop when this happens, so you should not
1388 depend on this behavior unless you are certain you are running
1389 @GNUTAR{}.  In general, it is wise to always place the archive outside
1390 of the directory being dumped.)
1392 @node list
1393 @section How to List Archives
1395 @opindex list
1396 Frequently, you will find yourself wanting to determine exactly what a
1397 particular archive contains.  You can use the @option{--list}
1398 (@option{-t}) operation to get the member names as they currently
1399 appear in the archive, as well as various attributes of the files at
1400 the time they were archived.  For example, assuming @file{practice} is
1401 your working directory, you can examine the archive
1402 @file{collection.tar} that you created in the last section with the
1403 command,
1405 @smallexample
1406 $ @kbd{tar --list --file=collection.tar}
1407 @end smallexample
1409 @noindent
1410 The output of @command{tar} would then be:
1412 @smallexample
1413 blues
1414 folk
1415 jazz
1416 @end smallexample
1418 @noindent
1419 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1420 @var{archive-name}}) option just as with @option{--create}
1421 (@option{-c}) to specify the name of the archive.
1423 @cindex File name arguments, using @option{--list} with
1424 @xopindex{list, using with file name arguments}
1425 You can specify one or more individual member names as arguments when
1426 using @samp{list}.  In this case, @command{tar} will only list the
1427 names of members you identify.  For example, @w{@kbd{tar --list
1428 --file=collection.tar folk}} would only print @file{folk}:
1430 @smallexample
1431 $ @kbd{tar --list --file=collection.tar folk}
1432 folk
1433 @end smallexample
1435 @xopindex{list, using with @option{--verbose}}
1436 @xopindex{verbose, using with @option{--list}}
1437 If you use the @option{--verbose} (@option{-v}) option with
1438 @option{--list}, then @command{tar} will print out a listing
1439 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1440 forth.  This output is described in detail in @ref{verbose member listing}.
1442 If you had used @option{--verbose} (@option{-v}) mode, the example
1443 above would look like:
1445 @smallexample
1446 $ @kbd{tar --list --verbose --file=collection.tar folk}
1447 -rw-r--r-- myself/user      62 1990-05-23 10:55 folk
1448 @end smallexample
1450 @cindex listing member and file names
1451 @anchor{listing member and file names}
1452 It is important to notice that the output of @kbd{tar --list
1453 --verbose} does not necessarily match that produced by @kbd{tar
1454 --create --verbose} while creating the archive.  It is because
1455 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1456 prefixes from file names before storing them in the archive
1457 (@xref{absolute}, for more information).  In other
1458 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1459 an archive and @dfn{member names} when listing it.  Consider this
1460 example, run from your home directory:
1462 @smallexample
1463 @group
1464 $ @kbd{tar --create --verbose --file practice.tar ~/practice}
1465 tar: Removing leading '/' from member names
1466 /home/myself/practice/
1467 /home/myself/practice/blues
1468 /home/myself/practice/folk
1469 /home/myself/practice/jazz
1470 /home/myself/practice/collection.tar
1471 $ @kbd{tar --list --file practice.tar}
1472 home/myself/practice/
1473 home/myself/practice/blues
1474 home/myself/practice/folk
1475 home/myself/practice/jazz
1476 home/myself/practice/collection.tar
1477 @end group
1478 @end smallexample
1480 @opindex show-stored-names
1481   This default behavior can sometimes be inconvenient.  You can force
1482 @GNUTAR{} show member names when creating archive by supplying
1483 @option{--show-stored-names} option.
1485 @table @option
1486 @item --show-stored-names
1487 Print member (as opposed to @emph{file}) names when creating the archive.
1488 @end table
1490 With this option, both commands produce the same output:
1492 @smallexample
1493 @group
1494 $ @kbd{tar --create --verbose --show-stored-names \
1495            --file practice.tar ~/practice}
1496 tar: Removing leading '/' from member names
1497 home/myself/practice/
1498 home/myself/practice/blues
1499 home/myself/practice/folk
1500 home/myself/practice/jazz
1501 home/myself/practice/collection.tar
1502 $ @kbd{tar --list --file practice.tar}
1503 home/myself/practice/
1504 home/myself/practice/blues
1505 home/myself/practice/folk
1506 home/myself/practice/jazz
1507 home/myself/practice/collection.tar
1508 @end group
1509 @end smallexample
1511 Since @command{tar} preserves file names, those you wish to list must be
1512 specified as they appear in the archive (i.e., relative to the
1513 directory from which the archive was created).  Continuing the example
1514 above:
1516 @smallexample
1517 @group
1518 $ @kbd{tar --list --file=practice.tar folk}
1519 tar: folk: Not found in archive
1520 tar: Exiting with failure status due to previous errors
1521 @end group
1522 @end smallexample
1524 the error message is produced because there is no member named
1525 @file{folk}, only one named @file{home/myself/folk}.
1527 If you are not sure of the exact file name, use @dfn{globbing
1528 patterns}, for example:
1530 @smallexample
1531 $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
1532 home/myself/practice/folk
1533 @end smallexample
1535 @noindent
1536 @xref{wildcards}, for a detailed discussion of globbing patterns and related
1537 @command{tar} command line options.
1539 @menu
1540 * list dir::
1541 @end menu
1543 @node list dir
1544 @unnumberedsubsec Listing the Contents of a Stored Directory
1546 To get information about the contents of an archived directory,
1547 use the directory name as a file name argument in conjunction with
1548 @option{--list} (@option{-t}).  To find out file attributes, include the
1549 @option{--verbose} (@option{-v}) option.
1551 For example, to find out about files in the directory @file{practice}, in
1552 the archive file @file{music.tar}, type:
1554 @smallexample
1555 $ @kbd{tar --list --verbose --file=music.tar practice}
1556 @end smallexample
1558 @command{tar} responds:
1560 @smallexample
1561 drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
1562 -rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
1563 -rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
1564 -rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
1565 -rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar
1566 @end smallexample
1568 When you use a directory name as a file name argument, @command{tar} acts on
1569 all the files (including sub-directories) in that directory.
1571 @node extract
1572 @section How to Extract Members from an Archive
1573 @cindex Extraction
1574 @cindex Retrieving files from an archive
1575 @cindex Resurrecting files from an archive
1577 @opindex extract
1578 Creating an archive is only half the job---there is no point in storing
1579 files in an archive if you can't retrieve them.  The act of retrieving
1580 members from an archive so they can be used and manipulated as
1581 unarchived files again is called @dfn{extraction}.  To extract files
1582 from an archive, use the @option{--extract} (@option{--get} or
1583 @option{-x}) operation.  As with @option{--create}, specify the name
1584 of the archive with @option{--file} (@option{-f}) option. Extracting
1585 an archive does not modify the archive in any way; you can extract it
1586 multiple times if you want or need to.
1588 Using @option{--extract}, you can extract an entire archive, or specific
1589 files.  The files can be directories containing other files, or not.  As
1590 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1591 long form of the operation without affecting the performance.
1593 @menu
1594 * extracting archives::
1595 * extracting files::
1596 * extract dir::
1597 * extracting untrusted archives::
1598 * failing commands::
1599 @end menu
1601 @node extracting archives
1602 @subsection Extracting an Entire Archive
1604 To extract an entire archive, specify the archive file name only, with
1605 no individual file names as arguments.  For example,
1607 @smallexample
1608 $ @kbd{tar -xvf collection.tar}
1609 @end smallexample
1611 @noindent
1612 produces this:
1614 @smallexample
1615 -rw-r--r-- myself/user      28 1996-10-18 16:31 jazz
1616 -rw-r--r-- myself/user      21 1996-09-23 16:44 blues
1617 -rw-r--r-- myself/user      20 1996-09-23 16:44 folk
1618 @end smallexample
1620 @node extracting files
1621 @subsection Extracting Specific Files
1623 To extract specific archive members, give their exact member names as
1624 arguments, as printed by @option{--list} (@option{-t}).  If you had
1625 mistakenly deleted one of the files you had placed in the archive
1626 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1627 from the archive without changing the archive's structure.  Its
1628 contents will be identical to the original file @file{blues} that you
1629 deleted.
1631 First, make sure you are in the @file{practice} directory, and list the
1632 files in the directory.  Now, delete the file, @samp{blues}, and list
1633 the files in the directory again.
1635 You can now extract the member @file{blues} from the archive file
1636 @file{collection.tar} like this:
1638 @smallexample
1639 $ @kbd{tar --extract --file=collection.tar blues}
1640 @end smallexample
1642 @noindent
1643 If you list the files in the directory again, you will see that the file
1644 @file{blues} has been restored, with its original permissions, data
1645 modification times, and owner.@footnote{This is only accidentally
1646 true, but not in general.  Whereas modification times are always
1647 restored, in most cases, one has to be root for restoring the owner,
1648 and use a special option for restoring permissions.  Here, it just
1649 happens that the restoring user is also the owner of the archived
1650 members, and that the current @code{umask} is compatible with original
1651 permissions.}  (These parameters will be identical to those which
1652 the file had when you originally placed it in the archive; any changes
1653 you may have made before deleting the file from the file system,
1654 however, will @emph{not} have been made to the archive member.)  The
1655 archive file, @samp{collection.tar}, is the same as it was before you
1656 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1657 @option{--list} (@option{-t}).
1659 Remember that as with other operations, specifying the exact member
1660 name is important (@xref{failing commands}, for more examples).
1662 You can extract a file to standard output by combining the above options
1663 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1664 Output}).
1666 If you give the @option{--verbose} option, then @option{--extract}
1667 will print the names of the archive members as it extracts them.
1669 @node extract dir
1670 @subsection Extracting Files that are Directories
1672 Extracting directories which are members of an archive is similar to
1673 extracting other files.  The main difference to be aware of is that if
1674 the extracted directory has the same name as any directory already in
1675 the working directory, then files in the extracted directory will be
1676 placed into the directory of the same name.  Likewise, if there are
1677 files in the pre-existing directory with the same names as the members
1678 which you extract, the files from the extracted archive will replace
1679 the files already in the working directory (and possible
1680 subdirectories).  This will happen regardless of whether or not the
1681 files in the working directory were more recent than those extracted
1682 (there exist, however, special options that alter this behavior
1683 @pxref{Writing}).
1685 However, if a file was stored with a directory name as part of its file
1686 name, and that directory does not exist under the working directory when
1687 the file is extracted, @command{tar} will create the directory.
1689 We can demonstrate how to use @option{--extract} to extract a directory
1690 file with an example.  Change to the @file{practice} directory if you
1691 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1692 go back to the parent directory and extract the archive
1693 @file{music.tar}.  You may either extract the entire archive, or you may
1694 extract only the files you just deleted.  To extract the entire archive,
1695 don't give any file names as arguments after the archive name
1696 @file{music.tar}.  To extract only the files you deleted, use the
1697 following command:
1699 @smallexample
1700 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1701 practice/folk
1702 practice/jazz
1703 @end smallexample
1705 @noindent
1706 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1707 would have displayed more detail about the extracted files, as shown
1708 in the example below:
1710 @smallexample
1711 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1712 -rw-r--r-- me/user          28 1996-10-18 16:31 practice/jazz
1713 -rw-r--r-- me/user          20 1996-09-23 16:44 practice/folk
1714 @end smallexample
1716 @noindent
1717 Because you created the directory with @file{practice} as part of the
1718 file names of each of the files by archiving the @file{practice}
1719 directory as @file{practice}, you must give @file{practice} as part
1720 of the file names when you extract those files from the archive.
1722 @node extracting untrusted archives
1723 @subsection Extracting Archives from Untrusted Sources
1725 Extracting files from archives can overwrite files that already exist.
1726 If you receive an archive from an untrusted source, you should make a
1727 new directory and extract into that directory, so that you don't have
1728 to worry about the extraction overwriting one of your existing files.
1729 For example, if @file{untrusted.tar} came from somewhere else on the
1730 Internet, and you don't necessarily trust its contents, you can
1731 extract it as follows:
1733 @smallexample
1734 $ @kbd{mkdir newdir}
1735 $ @kbd{cd newdir}
1736 $ @kbd{tar -xvf ../untrusted.tar}
1737 @end smallexample
1739 It is also a good practice to examine contents of the archive
1740 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1741 with @option{--verbose} (@option{-v}).
1743 @node failing commands
1744 @subsection Commands That Will Fail
1746 Here are some sample commands you might try which will not work, and why
1747 they won't work.
1749 If you try to use this command,
1751 @smallexample
1752 $ @kbd{tar -xvf music.tar folk jazz}
1753 @end smallexample
1755 @noindent
1756 you will get the following response:
1758 @smallexample
1759 tar: folk: Not found in archive
1760 tar: jazz: Not found in archive
1761 @end smallexample
1763 @noindent
1764 This is because these files were not originally @emph{in} the parent
1765 directory @file{..}, where the archive is located; they were in the
1766 @file{practice} directory, and their file names reflect this:
1768 @smallexample
1769 $ @kbd{tar -tvf music.tar}
1770 practice/blues
1771 practice/folk
1772 practice/jazz
1773 @end smallexample
1775 @noindent
1776 Likewise, if you try to use this command,
1778 @smallexample
1779 $ @kbd{tar -tvf music.tar folk jazz}
1780 @end smallexample
1782 @noindent
1783 you would get a similar response.  Members with those names are not in the
1784 archive.  You must use the correct member names, or wildcards, in order
1785 to extract the files from the archive.
1787 If you have forgotten the correct names of the files in the archive,
1788 use @w{@kbd{tar --list --verbose}} to list them correctly.
1790 To extract the member named @file{practice/folk}, you must specify
1792 @smallexample
1793 $ @kbd{tar --extract --file=music.tar practice/folk}
1794 @end smallexample
1796 @noindent
1797 Notice also, that as explained above, the @file{practice} directory
1798 will be created, if it didn't already exist.  There are options that
1799 allow you to strip away a certain number of leading directory
1800 components (@pxref{transform}).  For example,
1802 @smallexample
1803 $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
1804 @end smallexample
1806 @noindent
1807 will extract the file @file{folk} into the current working directory.
1809 @node going further
1810 @section Going Further Ahead in this Manual
1811 @UNREVISED{}
1813 @FIXME{need to write up a node here about the things that are going to
1814 be in the rest of the manual.}
1816 @node tar invocation
1817 @chapter Invoking @GNUTAR{}
1819 This chapter is about how one invokes the @GNUTAR{}
1820 command, from the command synopsis (@pxref{Synopsis}).  There are
1821 numerous options, and many styles for writing them.  One mandatory
1822 option specifies the operation @command{tar} should perform
1823 (@pxref{Operation Summary}), other options are meant to detail how
1824 this operation should be performed (@pxref{Option Summary}).
1825 Non-option arguments are not always interpreted the same way,
1826 depending on what the operation is.
1828 You will find in this chapter everything about option styles and rules for
1829 writing them (@pxref{Styles}).  On the other hand, operations and options
1830 are fully described elsewhere, in other chapters.  Here, you will find
1831 only synthetic descriptions for operations and options, together with
1832 pointers to other parts of the @command{tar} manual.
1834 Some options are so special they are fully described right in this
1835 chapter.  They have the effect of inhibiting the normal operation of
1836 @command{tar} or else, they globally alter the amount of feedback the user
1837 receives about what is going on.  These are the @option{--help} and
1838 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1839 and @option{--interactive} options (@pxref{interactive}).
1841 @menu
1842 * Synopsis::
1843 * using tar options::
1844 * Styles::
1845 * All Options::           All @command{tar} Options.
1846 * help::                  Where to Get Help.
1847 * defaults::              What are the Default Values.
1848 * verbose::               Checking @command{tar} progress.
1849 * checkpoints::           Checkpoints.
1850 * warnings::              Controlling Warning Messages.
1851 * interactive::           Asking for Confirmation During Operations.
1852 * external::              Running External Commands.
1853 @end menu
1855 @node Synopsis
1856 @section General Synopsis of @command{tar}
1858 The @GNUTAR{} program is invoked as either one of:
1860 @smallexample
1861 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1862 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1863 @end smallexample
1865 The second form is for when old options are being used.
1867 You can use @command{tar} to store files in an archive, to extract them from
1868 an archive, and to do other types of archive manipulation.  The primary
1869 argument to @command{tar}, which is called the @dfn{operation}, specifies
1870 which action to take.  The other arguments to @command{tar} are either
1871 @dfn{options}, which change the way @command{tar} performs an operation,
1872 or file names or archive members, which specify the files or members
1873 @command{tar} is to act on.
1875 You can actually type in arguments in any order, even if in this manual
1876 the options always precede the other arguments, to make examples easier
1877 to understand.  Further, the option stating the main operation mode
1878 (the @command{tar} main command) is usually given first.
1880 Each @var{name} in the synopsis above is interpreted as an archive member
1881 name when the main command is one of @option{--compare}
1882 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1883 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1884 @option{--update} (@option{-u}).  When naming archive members, you
1885 must give the exact name of the member in the archive, as it is
1886 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1887 @option{--create} (@option{-c}), these @var{name} arguments specify
1888 the names of either files or directory hierarchies to place in the archive.
1889 These files or hierarchies should already exist in the file system,
1890 prior to the execution of the @command{tar} command.
1892 @command{tar} interprets relative file names as being relative to the
1893 working directory.  @command{tar} will make all file names relative
1894 (by removing leading slashes when archiving or restoring files),
1895 unless you specify otherwise (using the @option{--absolute-names}
1896 option).  @xref{absolute}, for more information about
1897 @option{--absolute-names}.
1899 If you give the name of a directory as either a file name or a member
1900 name, then @command{tar} acts recursively on all the files and directories
1901 beneath that directory.  For example, the name @file{/} identifies all
1902 the files in the file system to @command{tar}.
1904 The distinction between file names and archive member names is especially
1905 important when shell globbing is used, and sometimes a source of confusion
1906 for newcomers.  @xref{wildcards}, for more information about globbing.
1907 The problem is that shells may only glob using existing files in the
1908 file system.  Only @command{tar} itself may glob on archive members, so when
1909 needed, you must ensure that wildcard characters reach @command{tar} without
1910 being interpreted by the shell first.  Using a backslash before @samp{*}
1911 or @samp{?}, or putting the whole argument between quotes, is usually
1912 sufficient for this.
1914 Even if @var{name}s are often specified on the command line, they
1915 can also be read from a text file in the file system, using the
1916 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1918 If you don't use any file name arguments, @option{--append} (@option{-r}),
1919 @option{--delete} and @option{--concatenate} (@option{--catenate},
1920 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1921 will usually yield a diagnostic and inhibit @command{tar} execution.
1922 The other operations of @command{tar} (@option{--list},
1923 @option{--extract}, @option{--compare}, and @option{--update})
1924 will act on the entire contents of the archive.
1926 @anchor{exit status}
1927 @cindex exit status
1928 @cindex return status
1929 Besides successful exits, @GNUTAR{} may fail for
1930 many reasons.  Some reasons correspond to bad usage, that is, when the
1931 @command{tar} command line is improperly written.  Errors may be
1932 encountered later, while processing the archive or the files.  Some
1933 errors are recoverable, in which case the failure is delayed until
1934 @command{tar} has completed all its work.  Some errors are such that
1935 it would be not meaningful, or at least risky, to continue processing:
1936 @command{tar} then aborts processing immediately.  All abnormal exits,
1937 whether immediate or delayed, should always be clearly diagnosed on
1938 @code{stderr}, after a line stating the nature of the error.
1940 Possible exit codes of @GNUTAR{} are summarized in the following
1941 table:
1943 @table @asis
1944 @item 0
1945 @samp{Successful termination}.
1947 @item 1
1948 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1949 (@option{--diff}, @option{-d}) command line option, this means that
1950 some files in the archive differ from their disk counterparts
1951 (@pxref{compare}).  If tar was given @option{--create},
1952 @option{--append} or @option{--update} option, this exit code means
1953 that some files were changed while being archived and so the resulting
1954 archive does not contain the exact copy of the file set.
1956 @item 2
1957 @samp{Fatal error}.  This means that some fatal, unrecoverable error
1958 occurred.
1959 @end table
1961 If @command{tar} has invoked a subprocess and that subprocess exited with a
1962 nonzero exit code, @command{tar} exits with that code as well.
1963 This can happen, for example, if @command{tar} was given some
1964 compression option (@pxref{gzip}) and the external compressor program
1965 failed.  Another example is @command{rmt} failure during backup to the
1966 remote device (@pxref{Remote Tape Server}).
1968 @node using tar options
1969 @section Using @command{tar} Options
1971 @GNUTAR{} has a total of eight operating modes which
1972 allow you to perform a variety of tasks.  You are required to choose
1973 one operating mode each time you employ the @command{tar} program by
1974 specifying one, and only one operation as an argument to the
1975 @command{tar} command (the corresponding options may be found
1976 at @ref{frequent operations} and @ref{Operations}).  Depending on
1977 circumstances, you may also wish to customize how the chosen operating
1978 mode behaves.  For example, you may wish to change the way the output
1979 looks, or the format of the files that you wish to archive may require
1980 you to do something special in order to make the archive look right.
1982 You can customize and control @command{tar}'s performance by running
1983 @command{tar} with one or more options (such as @option{--verbose}
1984 (@option{-v}), which we used in the tutorial).  As we said in the
1985 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1986 their name suggests) optional. Depending on the operating mode, you
1987 may specify one or more options. Different options will have different
1988 effects, but in general they all change details of the operation, such
1989 as archive format, archive name, or level of user interaction.  Some
1990 options make sense with all operating modes, while others are
1991 meaningful only with particular modes. You will likely use some
1992 options frequently, while you will only use others infrequently, or
1993 not at all.  (A full list of options is available in @pxref{All Options}.)
1995 @vrindex TAR_OPTIONS, environment variable
1996 @anchor{TAR_OPTIONS}
1997 The @env{TAR_OPTIONS} environment variable specifies default options to
1998 be placed in front of any explicit options.  For example, if
1999 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
2000 if the two options @option{-v} and @option{--unlink-first} had been
2001 specified before any explicit options.  Option specifications are
2002 separated by whitespace.  A backslash escapes the next character, so it
2003 can be used to specify an option containing whitespace or a backslash.
2005 Note that @command{tar} options are case sensitive.  For example, the
2006 options @option{-T} and @option{-t} are different; the first requires an
2007 argument for stating the name of a file providing a list of @var{name}s,
2008 while the second does not require an argument and is another way to
2009 write @option{--list} (@option{-t}).
2011 In addition to the eight operations, there are many options to
2012 @command{tar}, and three different styles for writing both: long (mnemonic)
2013 form, short form, and old style.  These styles are discussed below.
2014 Both the options and the operations can be written in any of these three
2015 styles.
2017 @FIXME{menu at end of this node.  need to think of an actual outline
2018 for this chapter; probably do that after stuff from chapter 4 is
2019 incorporated.}
2021 @node Styles
2022 @section The Three Option Styles
2024 There are three styles for writing operations and options to the command
2025 line invoking @command{tar}.  The different styles were developed at
2026 different times during the history of @command{tar}.  These styles will be
2027 presented below, from the most recent to the oldest.
2029 Some options must take an argument@footnote{For example, @option{--file}
2030 (@option{-f}) takes the name of an archive file as an argument.  If
2031 you do not supply an archive file name, @command{tar} will use a
2032 default, but this can be confusing; thus, we recommend that you always
2033 supply a specific archive file name.}.  Where you @emph{place} the
2034 arguments generally depends on which style of options you choose.  We
2035 will detail specific information relevant to each option style in the
2036 sections on the different option styles, below.  The differences are
2037 subtle, yet can often be very important; incorrect option placement
2038 can cause you to overwrite a number of important files.  We urge you
2039 to note these differences, and only use the option style(s) which
2040 makes the most sense to you until you feel comfortable with the others.
2042 Some options @emph{may} take an argument.  Such options may have at
2043 most long and short forms, they do not have old style equivalent.  The
2044 rules for specifying an argument for such options are stricter than
2045 those for specifying mandatory arguments.  Please, pay special
2046 attention to them.
2048 @menu
2049 * Long Options::                Long Option Style
2050 * Short Options::               Short Option Style
2051 * Old Options::                 Old Option Style
2052 * Mixing::                      Mixing Option Styles
2053 @end menu
2055 @node Long Options
2056 @subsection Long Option Style
2058 @cindex long options
2059 @cindex options, long style
2060 @cindex options, GNU style
2061 @cindex options, mnemonic names
2062 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2063 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2064 their corresponding short or old names.  It sometimes happens that a
2065 single long option has many different names which are
2066 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2067 long option names can be given unique abbreviations.  For example,
2068 @option{--cre} can be used in place of @option{--create} because there is no
2069 other long option which begins with @samp{cre}.  (One way to find
2070 this out is by trying it and seeing what happens; if a particular
2071 abbreviation could represent more than one option, @command{tar} will tell
2072 you that that abbreviation is ambiguous and you'll know that that
2073 abbreviation won't work.  You may also choose to run @samp{tar --help}
2074 to see a list of options.  Be aware that if you run @command{tar} with a
2075 unique abbreviation for the long name of an option you didn't want to
2076 use, you are stuck; @command{tar} will perform the command as ordered.)
2078 Long options are meant to be obvious and easy to remember, and their
2079 meanings are generally easier to discern than those of their
2080 corresponding short options (see below).  For example:
2082 @smallexample
2083 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2084 @end smallexample
2086 @noindent
2087 gives a fairly good set of hints about what the command does, even
2088 for those not fully acquainted with @command{tar}.
2090 @cindex arguments to long options
2091 @cindex long options with mandatory arguments
2092 Long options which require arguments take those arguments
2093 immediately following the option name.  There are two ways of
2094 specifying a mandatory argument.  It can be separated from the
2095 option name either by an equal sign, or by any amount of
2096 white space characters.  For example, the @option{--file} option (which
2097 tells the name of the @command{tar} archive) is given a file such as
2098 @file{archive.tar} as argument by using any of the following notations:
2099 @option{--file=archive.tar} or @option{--file archive.tar}.
2101 @cindex optional arguments to long options
2102 @cindex long options with optional arguments
2103 In contrast, optional arguments must always be introduced using
2104 an equal sign.  For example, the @option{--backup} option takes
2105 an optional argument specifying backup type.  It must be used
2106 as @option{--backup=@var{backup-type}}.
2108 @node Short Options
2109 @subsection Short Option Style
2111 @cindex short options
2112 @cindex options, short style
2113 @cindex options, traditional
2114 Most options also have a @dfn{short option} name.  Short options start with
2115 a single dash, and are followed by a single character, e.g., @option{-t}
2116 (which is equivalent to @option{--list}).  The forms are absolutely
2117 identical in function; they are interchangeable.
2119 The short option names are faster to type than long option names.
2121 @cindex arguments to short options
2122 @cindex short options with mandatory arguments
2123 Short options which require arguments take their arguments immediately
2124 following the option, usually separated by white space.  It is also
2125 possible to stick the argument right after the short option name, using
2126 no intervening space.  For example, you might write @w{@option{-f
2127 archive.tar}} or @option{-farchive.tar} instead of using
2128 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2129 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2130 specific archive, here named @file{archive.tar}.
2132 @cindex optional arguments to short options
2133 @cindex short options with optional arguments
2134 Short options which take optional arguments take their arguments
2135 immediately following the option letter, @emph{without any intervening
2136 white space characters}.
2138 Short options' letters may be clumped together, but you are not
2139 required to do this (as compared to old options; see below).  When
2140 short options are clumped as a set, use one (single) dash for them
2141 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2142 such a set is allowed to have an argument@footnote{Clustering many
2143 options, the last of which has an argument, is a rather opaque way to
2144 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2145 even be made helpful enough for considering such usages as invalid.}.
2147 When the options are separated, the argument for each option which requires
2148 an argument directly follows that option, as is usual for Unix programs.
2149 For example:
2151 @smallexample
2152 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2153 @end smallexample
2155 If you reorder short options' locations, be sure to move any arguments
2156 that belong to them.  If you do not move the arguments properly, you may
2157 end up overwriting files.
2159 @node Old Options
2160 @subsection Old Option Style
2161 @cindex options, old style
2162 @cindex old option style
2163 @cindex option syntax, traditional
2165 As far as we know, all @command{tar} programs, @acronym{GNU} and
2166 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2167 argument does not start with @samp{-}, it is assumed to specify option
2168 letters.  @GNUTAR{} supports old options not only for historical
2169 reasons, but also because many people are used to them.  If the first
2170 argument does not start with a dash, you are announcing the old option
2171 style instead of the short option style; old options are decoded
2172 differently.
2174 Like short options, old options are single letters.  However, old options
2175 must be written together as a single clumped set, without spaces separating
2176 them or dashes preceding them.  This set
2177 of letters must be the first to appear on the command line, after the
2178 @command{tar} program name and some white space; old options cannot appear
2179 anywhere else.  The letter of an old option is exactly the same letter as
2180 the corresponding short option.  For example, the old option @samp{t} is
2181 the same as the short option @option{-t}, and consequently, the same as the
2182 long option @option{--list}.  So for example, the command @w{@samp{tar
2183 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2185 @cindex arguments to old options
2186 @cindex old options with mandatory arguments
2187 When options that need arguments are given together with the command,
2188 all the associated arguments follow, in the same order as the options.
2189 Thus, the example given previously could also be written in the old
2190 style as follows:
2192 @smallexample
2193 $ @kbd{tar cvbf 20 /dev/rmt0}
2194 @end smallexample
2196 @noindent
2197 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2198 the argument of @option{-f}.
2200 The old style syntax can make it difficult to match
2201 option letters with their corresponding arguments, and is often
2202 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2203 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2204 argument for @option{-f}, and @option{-v} does not have a corresponding
2205 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2206 /dev/rmt0}} is clearer, putting all arguments next to the option they
2207 pertain to.
2209 If you want to reorder the letters in the old option argument, be
2210 sure to reorder any corresponding argument appropriately.
2212 This old way of writing @command{tar} options can surprise even experienced
2213 users.  For example, the two commands:
2215 @smallexample
2216 @kbd{tar cfz archive.tar.gz file}
2217 @kbd{tar -cfz archive.tar.gz file}
2218 @end smallexample
2220 @noindent
2221 are quite different.  The first example uses @file{archive.tar.gz} as
2222 the value for option @samp{f} and recognizes the option @samp{z}.  The
2223 second example, however, uses @file{z} as the value for option
2224 @samp{f} --- probably not what was intended.
2226 This second example could be corrected in many ways, among which the
2227 following are equivalent:
2229 @smallexample
2230 @kbd{tar -czf archive.tar.gz file}
2231 @kbd{tar -cf archive.tar.gz -z file}
2232 @kbd{tar cf archive.tar.gz -z file}
2233 @end smallexample
2235 @node Mixing
2236 @subsection Mixing Option Styles
2238 @cindex options, mixing different styles
2239 All three styles may be intermixed in a single @command{tar} command,
2240 so long as the rules for each style are fully
2241 respected@footnote{Before @GNUTAR{} version 1.11.6,
2242 a bug prevented intermixing old style options with long options in
2243 some cases.}.  Old style options and either of the modern styles of
2244 options may be mixed within a single @command{tar} command.  However,
2245 old style options must be introduced as the first arguments only,
2246 following the rule for old options (old options must appear directly
2247 after the @command{tar} command and some white space).  Modern options
2248 may be given only after all arguments to the old options have been
2249 collected.  If this rule is not respected, a modern option might be
2250 falsely interpreted as the value of the argument to one of the old
2251 style options.
2253 For example, all the following commands are wholly equivalent, and
2254 illustrate the many combinations and orderings of option styles.
2256 @smallexample
2257 @kbd{tar --create --file=archive.tar}
2258 @kbd{tar --create -f archive.tar}
2259 @kbd{tar --create -farchive.tar}
2260 @kbd{tar --file=archive.tar --create}
2261 @kbd{tar --file=archive.tar -c}
2262 @kbd{tar -c --file=archive.tar}
2263 @kbd{tar -c -f archive.tar}
2264 @kbd{tar -c -farchive.tar}
2265 @kbd{tar -cf archive.tar}
2266 @kbd{tar -cfarchive.tar}
2267 @kbd{tar -f archive.tar --create}
2268 @kbd{tar -f archive.tar -c}
2269 @kbd{tar -farchive.tar --create}
2270 @kbd{tar -farchive.tar -c}
2271 @kbd{tar c --file=archive.tar}
2272 @kbd{tar c -f archive.tar}
2273 @kbd{tar c -farchive.tar}
2274 @kbd{tar cf archive.tar}
2275 @kbd{tar f archive.tar --create}
2276 @kbd{tar f archive.tar -c}
2277 @kbd{tar fc archive.tar}
2278 @end smallexample
2280 On the other hand, the following commands are @emph{not} equivalent to
2281 the previous set:
2283 @smallexample
2284 @kbd{tar -f -c archive.tar}
2285 @kbd{tar -fc archive.tar}
2286 @kbd{tar -fcarchive.tar}
2287 @kbd{tar -farchive.tarc}
2288 @kbd{tar cfarchive.tar}
2289 @end smallexample
2291 @noindent
2292 These last examples mean something completely different from what the
2293 user intended (judging based on the example in the previous set which
2294 uses long options, whose intent is therefore very clear).  The first
2295 four specify that the @command{tar} archive would be a file named
2296 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2297 respectively.  The first two examples also specify a single non-option,
2298 @var{name} argument having the value @samp{archive.tar}.  The last
2299 example contains only old style option letters (repeating option
2300 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2301 @samp{h}, or @samp{i}), with no argument value.
2302 @FIXME{not sure i liked
2303 the first sentence of this paragraph..}
2305 @node All Options
2306 @section All @command{tar} Options
2308 The coming manual sections contain an alphabetical listing of all
2309 @command{tar} operations and options, with brief descriptions and
2310 cross-references to more in-depth explanations in the body of the manual.
2311 They also contain an alphabetically arranged table of the short option
2312 forms with their corresponding long option.  You can use this table as
2313 a reference for deciphering @command{tar} commands in scripts.
2315 @menu
2316 * Operation Summary::
2317 * Option Summary::
2318 * Short Option Summary::
2319 * Position-Sensitive Options::
2320 @end menu
2322 @node Operation Summary
2323 @subsection Operations
2325 @table @option
2327 @opsummary{append}
2328 @item --append
2329 @itemx -r
2331 Appends files to the end of the archive.  @xref{append}.
2333 @opsummary{catenate}
2334 @item --catenate
2335 @itemx -A
2337 Same as @option{--concatenate}.  @xref{concatenate}.
2339 @opsummary{compare}
2340 @item --compare
2341 @itemx -d
2343 Compares archive members with their counterparts in the file
2344 system, and reports differences in file size, mode, owner,
2345 modification date and contents.  @xref{compare}.
2347 @opsummary{concatenate}
2348 @item --concatenate
2349 @itemx -A
2351 Appends other @command{tar} archives to the end of the archive.
2352 @xref{concatenate}.
2354 @opsummary{create}
2355 @item --create
2356 @itemx -c
2358 Creates a new @command{tar} archive.  @xref{create}.
2360 @opsummary{delete}
2361 @item --delete
2363 Deletes members from the archive.  Don't try this on an archive on a
2364 tape!  @xref{delete}.
2366 @opsummary{diff}
2367 @item --diff
2368 @itemx -d
2370 Same @option{--compare}.  @xref{compare}.
2372 @opsummary{extract}
2373 @item --extract
2374 @itemx -x
2376 Extracts members from the archive into the file system.  @xref{extract}.
2378 @opsummary{get}
2379 @item --get
2380 @itemx -x
2382 Same as @option{--extract}.  @xref{extract}.
2384 @opsummary{list}
2385 @item --list
2386 @itemx -t
2388 Lists the members in an archive.  @xref{list}.
2390 @opsummary{update}
2391 @item --update
2392 @itemx -u
2394 Adds files to the end of the archive, but only if they are newer than
2395 their counterparts already in the archive, or if they do not already
2396 exist in the archive. @xref{update}.
2398 @end table
2400 @node Option Summary
2401 @subsection @command{tar} Options
2403 @table @option
2405 @opsummary{absolute-names}
2406 @item --absolute-names
2407 @itemx -P
2409 Normally when creating an archive, @command{tar} strips an initial
2410 @samp{/} from member names, and when extracting from an archive @command{tar}
2411 treats names specially if they have initial @samp{/} or internal
2412 @samp{..}.  This option disables that behavior.  @xref{absolute}.
2414 @opsummary{acls}
2415 @item --acls
2416 Enable POSIX ACLs support.  @xref{Extended File Attributes, acls}.
2418 @opsummary{after-date}
2419 @item --after-date
2421 (See @option{--newer}, @pxref{after})
2423 @opsummary{anchored}
2424 @item --anchored
2425 A pattern must match an initial subsequence of the name's components.
2426 @xref{controlling pattern-matching}.
2428 @opsummary{atime-preserve}
2429 @item --atime-preserve
2430 @itemx --atime-preserve=replace
2431 @itemx --atime-preserve=system
2433 Attempt to preserve the access time of files when reading them.  This
2434 option currently is effective only on files that you own, unless you
2435 have superuser privileges.
2437 @option{--atime-preserve=replace} remembers the access time of a file
2438 before reading it, and then restores the access time afterwards.  This
2439 may cause problems if other programs are reading the file at the same
2440 time, as the times of their accesses will be lost.  On most platforms
2441 restoring the access time also requires @command{tar} to restore the
2442 data modification time too, so this option may also cause problems if
2443 other programs are writing the file at the same time (@command{tar} attempts
2444 to detect this situation, but cannot do so reliably due to race
2445 conditions).  Worse, on most platforms restoring the access time also
2446 updates the status change time, which means that this option is
2447 incompatible with incremental backups.
2449 @option{--atime-preserve=system} avoids changing time stamps on files,
2450 without interfering with time stamp updates
2451 caused by other programs, so it works better with incremental backups.
2452 However, it requires a special @code{O_NOATIME} option from the
2453 underlying operating and file system implementation, and it also requires
2454 that searching directories does not update their access times.  As of
2455 this writing (November 2005) this works only with Linux, and only with
2456 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2457 way to know whether this feature actually works.  Sometimes
2458 @command{tar} knows that it does not work, and if you use
2459 @option{--atime-preserve=system} then @command{tar} complains and
2460 exits right away.  But other times @command{tar} might think that the
2461 option works when it actually does not.
2463 Currently @option{--atime-preserve} with no operand defaults to
2464 @option{--atime-preserve=replace}, but this may change in the future
2465 as support for @option{--atime-preserve=system} improves.
2467 If your operating or file system does not support
2468 @option{--atime-preserve=@-system}, you might be able to preserve access
2469 times reliably by using the @command{mount} command.  For example,
2470 you can mount the file system read-only, or access the file system via
2471 a read-only loopback mount, or use the @samp{noatime} mount option
2472 available on some systems.  However, mounting typically requires
2473 superuser privileges and can be a pain to manage.
2475 @opsummary{auto-compress}
2476 @item --auto-compress
2477 @itemx -a
2479 During a @option{--create} operation, enables automatic compressed
2480 format recognition based on the archive suffix.  The effect of this
2481 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2483 @opsummary{backup}
2484 @item --backup=@var{backup-type}
2486 Rather than deleting files from the file system, @command{tar} will
2487 back them up using simple or numbered backups, depending upon
2488 @var{backup-type}.  @xref{backup}.
2490 @opsummary{block-number}
2491 @item --block-number
2492 @itemx -R
2494 With this option present, @command{tar} prints error messages for read errors
2495 with the block number in the archive file.  @xref{block-number}.
2497 @opsummary{blocking-factor}
2498 @item --blocking-factor=@var{blocking}
2499 @itemx -b @var{blocking}
2501 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2502 record.  @xref{Blocking Factor}.
2504 @opsummary{bzip2}
2505 @item --bzip2
2506 @itemx -j
2508 This option tells @command{tar} to read or write archives through
2509 @code{bzip2}.  @xref{gzip}.
2511 @opsummary{check-device}
2512 @item --check-device
2513 Check device numbers when creating a list of modified files for
2514 incremental archiving.  This is the default.  @xref{device numbers},
2515 for a detailed description.
2517 @opsummary{checkpoint}
2518 @item --checkpoint[=@var{number}]
2520 This option directs @command{tar} to print periodic checkpoint
2521 messages as it reads through the archive.  It is intended for when you
2522 want a visual indication that @command{tar} is still running, but
2523 don't want to see @option{--verbose} output.  You can also instruct
2524 @command{tar} to execute a list of actions on each checkpoint, see
2525 @option{--checkpoint-action} below.  For a detailed description, see
2526 @ref{checkpoints}.
2528 @opsummary{checkpoint-action}
2529 @item --checkpoint-action=@var{action}
2530 Instruct @command{tar} to execute an action upon hitting a
2531 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2532 for a complete description.
2534 The @var{action} argument can be one of the following:
2536 @table @asis
2537 @item bell
2538 Produce an audible bell on the console.
2540 @item dot
2541 @itemx .
2542 Print a single dot on the standard listing stream.
2544 @item echo
2545 Display a textual message on the standard error, with the status and
2546 number of the checkpoint.  This is the default.
2548 @item echo=@var{string}
2549 Display @var{string} on the standard error.  Before output, the string
2550 is subject to meta-character expansion.
2552 @item exec=@var{command}
2553 Execute the given @var{command}.
2555 @item sleep=@var{time}
2556 Wait for @var{time} seconds.
2558 @item ttyout=@var{string}
2559 Output @var{string} on the current console (@file{/dev/tty}).
2561 @item totals
2562 Print statistics (see @pxref{totals}).
2564 @item wait=@var{signo}
2565 Wait for signal @var{signo}.
2566 @end table
2568 Several @option{--checkpoint-action} options can be specified.  The
2569 supplied actions will be executed in order of their appearance in the
2570 command line.
2572 Using @option{--checkpoint-action} without @option{--checkpoint}
2573 assumes default checkpoint frequency of one checkpoint per 10 records.
2575 @opsummary{check-links}
2576 @item --check-links
2577 @itemx -l
2578 If this option was given, @command{tar} will check the number of links
2579 dumped for each processed file.  If this number does not match the
2580 total number of hard links for the file, a warning message will be
2581 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2582 synonym for @option{--one-file-system}.  The current semantics, which
2583 complies to UNIX98, was introduced with version
2584 1.15.91. @xref{Changes}, for more information.}.
2586 @xref{hard links}.
2588 @opsummary{compress}
2589 @opsummary{uncompress}
2590 @item --compress
2591 @itemx --uncompress
2592 @itemx -Z
2594 @command{tar} will use the @command{compress} program when reading or
2595 writing the archive.  This allows you to directly act on archives
2596 while saving space.  @xref{gzip}.
2598 @opsummary{clamp-mtime}
2599 @item --clamp-mtime
2601 (See @option{--mtime}.)
2603 @opsummary{confirmation}
2604 @item --confirmation
2606 (See @option{--interactive}.)  @xref{interactive}.
2608 @opsummary{delay-directory-restore}
2609 @item --delay-directory-restore
2611 Delay setting modification times and permissions of extracted
2612 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2614 @opsummary{dereference}
2615 @item --dereference
2616 @itemx -h
2618 When reading or writing a file to be archived, @command{tar} accesses
2619 the file that a symbolic link points to, rather than the symlink
2620 itself.  @xref{dereference}.
2622 @opsummary{directory}
2623 @item --directory=@var{dir}
2624 @itemx -C @var{dir}
2626 When this option is specified, @command{tar} will change its current directory
2627 to @var{dir} before performing any operations.  When this option is used
2628 during archive creation, it is order sensitive.  @xref{directory}.
2630 @opsummary{exclude}
2631 @item --exclude=@var{pattern}
2633 When performing operations, @command{tar} will skip files that match
2634 @var{pattern}.  @xref{exclude}.
2636 @opsummary{exclude-backups}
2637 @item --exclude-backups
2638 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2640 @opsummary{exclude-from}
2641 @item --exclude-from=@var{file}
2642 @itemx -X @var{file}
2644 Similar to @option{--exclude}, except @command{tar} will use the list of
2645 patterns in the file @var{file}.  @xref{exclude}.
2647 @opsummary{exclude-caches}
2648 @item --exclude-caches
2650 Exclude from dump any directory containing a valid cache directory
2651 tag file, but still dump the directory node and the tag file itself.
2653 @xref{exclude,, exclude-caches}.
2655 @opsummary{exclude-caches-under}
2656 @item --exclude-caches-under
2658 Exclude from dump any directory containing a valid cache directory
2659 tag file, but still dump the directory node itself.
2661 @xref{exclude}.
2663 @opsummary{exclude-caches-all}
2664 @item --exclude-caches-all
2666 Exclude from dump any directory containing a valid cache directory
2667 tag file.  @xref{exclude}.
2669 @opsummary{exclude-ignore}
2670 @item --exclude-ignore=@var{file}
2671 Before dumping a directory, @command{tar} checks if it contains
2672 @var{file}.  If so, exclusion patterns are read from this file.
2673 The patterns affect only the directory itself.  @xref{exclude}.
2675 @opsummary{exclude-ignore-recursive}
2676 @item --exclude-ignore-recursive=@var{file}
2677 Before dumping a directory, @command{tar} checks if it contains
2678 @var{file}.  If so, exclusion patterns are read from this file.
2679 The patterns affect the directory and all itssubdirectories.
2680 @xref{exclude}.
2682 @opsummary{exclude-tag}
2683 @item --exclude-tag=@var{file}
2685 Exclude from dump any directory containing file named @var{file}, but
2686 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2688 @opsummary{exclude-tag-under}
2689 @item --exclude-tag-under=@var{file}
2691 Exclude from dump the contents of any directory containing file
2692 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2693 exclude-tag-under}.
2695 @opsummary{exclude-tag-all}
2696 @item --exclude-tag-all=@var{file}
2698 Exclude from dump any directory containing file named @var{file}.
2699 @xref{exclude,,exclude-tag-all}.
2701 @opsummary{exclude-vcs}
2702 @item --exclude-vcs
2704 Exclude from dump directories and files, that are internal for some
2705 widely used version control systems.
2707 @xref{exclude-vcs}.
2709 @opsummary{exclude-vcs-ignores}
2710 @item --exclude-vcs-ignores
2711 Exclude files that match patterns read from VCS-specific ignore
2712 files.  Supported files are: @file{.cvsignore}, @file{.gitignore},
2713 @file{.bzrignore}, and @file{.hgignore}.  The semantics of each file
2714 is the same as for the corresponding VCS, e.g. patterns read from
2715 @file{.gitignore} affect the directory and all its subdirectories.
2716 @xref{exclude-vcs-ignores}.
2718 @opsummary{file}
2719 @item --file=@var{archive}
2720 @itemx -f @var{archive}
2722 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2723 performs operations on, rather than @command{tar}'s compilation dependent
2724 default.  @xref{file tutorial}.
2726 @opsummary{files-from}
2727 @item --files-from=@var{file}
2728 @itemx -T @var{file}
2730 @command{tar} will use the contents of @var{file} as a list of archive members
2731 or files to operate on, in addition to those specified on the
2732 command-line.  @xref{files}.
2734 @opsummary{force-local}
2735 @item --force-local
2737 Forces @command{tar} to interpret the file name given to @option{--file}
2738 as a local file, even if it looks like a remote tape drive name.
2739 @xref{local and remote archives}.
2741 @opsummary{format}
2742 @item --format=@var{format}
2743 @itemx -H @var{format}
2745 Selects output archive format.  @var{Format} may be one of the
2746 following:
2748 @table @samp
2749 @item v7
2750 Creates an archive that is compatible with Unix V7 @command{tar}.
2752 @item oldgnu
2753 Creates an archive that is compatible with GNU @command{tar} version
2754 1.12 or earlier.
2756 @item gnu
2757 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2758 @samp{oldgnu} with the only difference in the way it handles long
2759 numeric fields.
2761 @item ustar
2762 Creates a @acronym{POSIX.1-1988} compatible archive.
2764 @item posix
2765 Creates a @acronym{POSIX.1-2001 archive}.
2767 @end table
2769 @xref{Formats}, for a detailed discussion of these formats.
2771 @opsummary{full-time}
2772 @item --full-time
2773 This option instructs @command{tar} to print file times to their full
2774 resolution.  Usually this means 1-second resolution, but that depends
2775 on the underlying file system.  The @option{--full-time} option takes
2776 effect only when detailed output (verbosity level 2 or higher) has
2777 been requested using the @option{--verbose} option, e.g., when listing
2778 or extracting archives:
2780 @smallexample
2781 $ @kbd{tar -t -v --full-time -f archive.tar}
2782 @end smallexample
2784 @noindent
2785 or, when creating an archive:
2787 @smallexample
2788 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2789 @end smallexample
2791 Notice, thar when creating the archive you need to specify
2792 @option{--verbose} twice to get a detailed output (@pxref{verbose
2793 tutorial}).
2795 @opsummary{group}
2796 @item --group=@var{group}
2798 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2799 rather than the group from the source file.  @var{group} can specify a
2800 symbolic name, or a numeric @acronym{ID}, or both as
2801 @var{name}:@var{id}.  @xref{override}.
2803 Also see the @option{--group-map} option and comments for the
2804 @option{--owner=@var{user}} option.
2806 @opsummary{group-map}
2807 @item --group-map=@var{file}
2809 Read owner group translation map from @var{file}.  This option allows to
2810 translate only certain group names and/or UIDs.  @xref{override}, for a
2811 detailed description.  When used together with @option{--group}
2812 option, the latter affects only those files whose owner group is not listed
2813 in the @var{file}.
2815 This option does not affect extraction from archives.
2817 @opsummary{gzip}
2818 @opsummary{gunzip}
2819 @opsummary{ungzip}
2820 @item --gzip
2821 @itemx --gunzip
2822 @itemx --ungzip
2823 @itemx -z
2825 This option tells @command{tar} to read or write archives through
2826 @command{gzip}, allowing @command{tar} to directly operate on several
2827 kinds of compressed archives transparently.  @xref{gzip}.
2829 @opsummary{hard-dereference}
2830 @item --hard-dereference
2831 When creating an archive, dereference hard links and store the files
2832 they refer to, instead of creating usual hard link members.
2834 @xref{hard links}.
2836 @opsummary{help}
2837 @item --help
2838 @itemx -?
2840 @command{tar} will print out a short message summarizing the operations and
2841 options to @command{tar} and exit. @xref{help}.
2843 @opsummary{hole-detection}
2844 @item --hole-detection=@var{method}
2845 Use @var{method} to detect holes in sparse files.  This option implies
2846 @option{--sparse}.  Valid methods are @samp{seek} and @samp{raw}.
2847 Default is @samp{seek} with fallback to @samp{raw} when not
2848 applicable. @xref{sparse}.
2850 @opsummary{ignore-case}
2851 @item --ignore-case
2852 Ignore case when matching member or file names with
2853 patterns. @xref{controlling pattern-matching}.
2855 @opsummary{ignore-command-error}
2856 @item --ignore-command-error
2857 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2859 @opsummary{ignore-failed-read}
2860 @item --ignore-failed-read
2862 Do not exit unsuccessfully merely because reading failed.
2863 @xref{Ignore Failed Read}.
2865 @opsummary{ignore-zeros}
2866 @item --ignore-zeros
2867 @itemx -i
2869 With this option, @command{tar} will ignore zeroed blocks in the
2870 archive, which normally signals EOF.  @xref{Reading}.
2872 @opsummary{incremental}
2873 @item --incremental
2874 @itemx -G
2876 Informs @command{tar} that it is working with an old
2877 @acronym{GNU}-format incremental backup archive.  It is intended
2878 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2879 for a detailed discussion of incremental archives.
2881 @opsummary{index-file}
2882 @item --index-file=@var{file}
2884 Send verbose output to @var{file} instead of to standard output.
2886 @opsummary{info-script}
2887 @opsummary{new-volume-script}
2888 @item --info-script=@var{command}
2889 @itemx --new-volume-script=@var{command}
2890 @itemx -F @var{command}
2892 When @command{tar} is performing multi-tape backups, @var{command} is run
2893 at the end of each tape.  If it exits with nonzero status,
2894 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2895 discussion of this feature.
2897 @opsummary{interactive}
2898 @item --interactive
2899 @itemx --confirmation
2900 @itemx -w
2902 Specifies that @command{tar} should ask the user for confirmation before
2903 performing potentially destructive options, such as overwriting files.
2904 @xref{interactive}.
2906 @opsummary{keep-directory-symlink}
2907 @item --keep-directory-symlink
2909 This option changes the behavior of tar when it encounters a symlink
2910 with the same name as the directory that it is about to extract.  By
2911 default, in this case tar would first remove the symlink and then
2912 proceed extracting the directory.
2914 The @option{--keep-directory-symlink} option disables this behavior
2915 and instructs tar to follow symlinks to directories when extracting
2916 from the archive.
2918 It is mainly intended to provide compatibility with the Slackware
2919 installation scripts.
2921 @opsummary{keep-newer-files}
2922 @item --keep-newer-files
2924 Do not replace existing files that are newer than their archive copies
2925 when extracting files from an archive.
2927 @opsummary{keep-old-files}
2928 @item --keep-old-files
2929 @itemx -k
2931 Do not overwrite existing files when extracting files from an
2932 archive.  Return error if such files exist.  See also
2933 @ref{--skip-old-files}.
2935 @xref{Keep Old Files}.
2937 @opsummary{label}
2938 @item --label=@var{name}
2939 @itemx -V @var{name}
2941 When creating an archive, instructs @command{tar} to write @var{name}
2942 as a name record in the archive.  When extracting or listing archives,
2943 @command{tar} will only operate on archives that have a label matching
2944 the pattern specified in @var{name}.  @xref{Tape Files}.
2946 @opsummary{level}
2947 @item --level=@var{n}
2948 Force incremental backup of level @var{n}.  As of @GNUTAR{} version
2949 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2950 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2951 effectively ignored.  @xref{--level=0}, for details and examples.
2953 The use of this option is valid only in conjunction with the
2954 @option{--listed-incremental} option.  @xref{Incremental Dumps},
2955 for a detailed description.
2957 @opsummary{listed-incremental}
2958 @item --listed-incremental=@var{snapshot-file}
2959 @itemx -g @var{snapshot-file}
2961 During a @option{--create} operation, specifies that the archive that
2962 @command{tar} creates is a new @acronym{GNU}-format incremental
2963 backup, using @var{snapshot-file} to determine which files to backup.
2964 With other operations, informs @command{tar} that the archive is in
2965 incremental format.  @xref{Incremental Dumps}.
2967 @opsummary{lzip}
2968 @item --lzip
2970 This option tells @command{tar} to read or write archives through
2971 @command{lzip}.  @xref{gzip}.
2973 @opsummary{lzma}
2974 @item --lzma
2976 This option tells @command{tar} to read or write archives through
2977 @command{lzma}.  @xref{gzip}.
2979 @item --lzop
2981 This option tells @command{tar} to read or write archives through
2982 @command{lzop}.  @xref{gzip}.
2984 @opsummary{mode}
2985 @item --mode=@var{permissions}
2987 When adding files to an archive, @command{tar} will use
2988 @var{permissions} for the archive members, rather than the permissions
2989 from the files.  @var{permissions} can be specified either as an octal
2990 number or as symbolic permissions, like with
2991 @command{chmod}. @xref{override}.
2993 @opsummary{mtime}
2994 @item --mtime=@var{date}
2996 When adding files to an archive, @command{tar} will use @var{date} as
2997 the modification time of members when creating archives, instead of
2998 their actual modification times.  The value of @var{date} can be
2999 either a textual date representation (@pxref{Date input formats}) or a
3000 name of the existing file, starting with @samp{/} or @samp{.}.  In the
3001 latter case, the modification time of that file is used. @xref{override}.
3003 When @command{--clamp-mtime} is also specified, files with
3004 modification times earlier than @var{date} will retain their actual
3005 modification times, and @var{date} will only be used for files whose
3006 modification times are later than @var{date}.
3008 @opsummary{multi-volume}
3009 @item --multi-volume
3010 @itemx -M
3012 Informs @command{tar} that it should create or otherwise operate on a
3013 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
3015 @opsummary{new-volume-script}
3016 @item --new-volume-script
3018 (see @option{--info-script})
3020 @opsummary{newer}
3021 @item --newer=@var{date}
3022 @itemx --after-date=@var{date}
3023 @itemx -N
3025 When creating an archive, @command{tar} will only add files that have changed
3026 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
3027 is taken to be the name of a file whose data modification time specifies
3028 the date.  @xref{after}.
3030 @opsummary{newer-mtime}
3031 @item --newer-mtime=@var{date}
3033 Like @option{--newer}, but add only files whose
3034 contents have changed (as opposed to just @option{--newer}, which will
3035 also back up files for which any status information has
3036 changed).  @xref{after}.
3038 @opsummary{no-acls}
3039 @item --no-acls
3040 Disable the POSIX ACLs support.  @xref{Extended File Attributes, acls}.
3042 @opsummary{no-anchored}
3043 @item --no-anchored
3044 An exclude pattern can match any subsequence of the name's components.
3045 @xref{controlling pattern-matching}.
3047 @opsummary{no-auto-compress}
3048 @item --no-auto-compress
3050 Disables automatic compressed format recognition based on the archive
3051 suffix.  @xref{--auto-compress}.  @xref{gzip}.
3053 @opsummary{no-check-device}
3054 @item --no-check-device
3055 Do not check device numbers when creating a list of modified files
3056 for incremental archiving.  @xref{device numbers}, for
3057 a detailed description.
3059 @opsummary{no-delay-directory-restore}
3060 @item --no-delay-directory-restore
3062 Modification times and permissions of extracted
3063 directories are set when all files from this directory have been
3064 extracted.  This is the default.
3065 @xref{Directory Modification Times and Permissions}.
3067 @opsummary{no-ignore-case}
3068 @item --no-ignore-case
3069 Use case-sensitive matching.
3070 @xref{controlling pattern-matching}.
3072 @opsummary{no-ignore-command-error}
3073 @item --no-ignore-command-error
3074 Print warnings about subprocesses that terminated with a nonzero exit
3075 code. @xref{Writing to an External Program}.
3077 @opsummary{no-null}
3078 @item --no-null
3080 If the @option{--null} option was given previously, this option
3081 cancels its effect, so that any following @option{--files-from}
3082 options will expect their file lists to be newline-terminated.
3084 @opsummary{no-overwrite-dir}
3085 @item --no-overwrite-dir
3087 Preserve metadata of existing directories when extracting files
3088 from an archive.  @xref{Overwrite Old Files}.
3090 @opsummary{no-quote-chars}
3091 @item --no-quote-chars=@var{string}
3092 Remove characters listed in @var{string} from the list of quoted
3093 characters set by the previous @option{--quote-chars} option
3094 (@pxref{quoting styles}).
3096 @opsummary{no-recursion}
3097 @item --no-recursion
3099 With this option, @command{tar} will not recurse into directories.
3100 @xref{recurse}.
3102 @opsummary{no-same-owner}
3103 @item --no-same-owner
3104 @itemx -o
3106 When extracting an archive, do not attempt to preserve the owner
3107 specified in the @command{tar} archive.  This the default behavior
3108 for ordinary users.
3110 @opsummary{no-same-permissions}
3111 @item --no-same-permissions
3113 When extracting an archive, subtract the user's umask from files from
3114 the permissions specified in the archive.  This is the default behavior
3115 for ordinary users.
3117 @opsummary{no-seek}
3118 @item --no-seek
3120 The archive media does not support seeks to arbitrary
3121 locations.  Usually @command{tar} determines automatically whether
3122 the archive can be seeked or not.  Use this option to disable this
3123 mechanism.
3125 @opsummary{no-selinux}
3126 @item --no-selinux
3127 Disable SELinux context support.  @xref{Extended File Attributes, SELinux}.
3129 @opsummary{no-unquote}
3130 @item --no-unquote
3131 Treat all input file or member names literally, do not interpret
3132 escape sequences.  @xref{input name quoting}.
3134 @opsummary{no-verbatim-files-from}
3135 @item --no-verbatim-files-from
3137 Instructs @GNUTAR{} to treat each line read from a file list as if it
3138 were supplied in the command line.  I.e., leading and trailing
3139 whitespace is removed and, if the result begins with a dash, it is
3140 treated as a @GNUTAR{} command line option.
3142 This is default behavior.  This option is provided as a way to restore
3143 it after @option{--verbatim-files-from} option.
3145 It is implied by the @option{--no-null} option.
3147 @xref{no-verbatim-files-from}.
3149 @opsummary{no-wildcards}
3150 @item --no-wildcards
3151 Do not use wildcards.
3152 @xref{controlling pattern-matching}.
3154 @opsummary{no-wildcards-match-slash}
3155 @item --no-wildcards-match-slash
3156 Wildcards do not match @samp{/}.
3157 @xref{controlling pattern-matching}.
3159 @opsummary{no-xattrs}
3160 @item --no-xattrs
3161 Disable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3163 @opsummary{null}
3164 @item --null
3166 When @command{tar} is using the @option{--files-from} option, this option
3167 instructs @command{tar} to expect file names terminated with
3168 @acronym{NUL}, and to process file names verbatim.
3170 This means that @command{tar} correctly works with file names that
3171 contain newlines or begin with a dash.
3173 @xref{nul}.
3175 See also @ref{verbatim-files-from}.
3177 @opsummary{numeric-owner}
3178 @item --numeric-owner
3180 This option will notify @command{tar} that it should use numeric user
3181 and group IDs when creating a @command{tar} file, rather than names.
3182 @xref{Attributes}.
3184 @item -o
3185 The function of this option depends on the action @command{tar} is
3186 performing.  When extracting files, @option{-o} is a synonym for
3187 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3188 restoring ownership of files being extracted.
3190 When creating an archive, it is a synonym for
3191 @option{--old-archive}.  This behavior is for compatibility
3192 with previous versions of @GNUTAR{}, and will be
3193 removed in future releases.
3195 @xref{Changes}, for more information.
3197 @opsummary{occurrence}
3198 @item --occurrence[=@var{number}]
3200 This option can be used in conjunction with one of the subcommands
3201 @option{--delete}, @option{--diff}, @option{--extract} or
3202 @option{--list} when a list of files is given either on the command
3203 line or via @option{-T} option.
3205 This option instructs @command{tar} to process only the @var{number}th
3206 occurrence of each named file.  @var{Number} defaults to 1, so
3208 @smallexample
3209 tar -x -f archive.tar --occurrence filename
3210 @end smallexample
3212 @noindent
3213 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3214 and will terminate without scanning to the end of the archive.
3216 @opsummary{old-archive}
3217 @item --old-archive
3218 Synonym for @option{--format=v7}.
3220 @opsummary{one-file-system}
3221 @item --one-file-system
3222 Used when creating an archive.  Prevents @command{tar} from recursing into
3223 directories that are on different file systems from the current
3224 directory.
3226 @opsummary{one-top-level}
3227 @item --one-top-level[=@var{dir}]
3228 Tells @command{tar} to create a new directory beneath the extraction directory
3229 (or the one passed to @option{-C}) and use it to guard against
3230 tarbombs.  In the absence of @var{dir} argument, the name of the new directory
3231 will be equal to the base name of the archive (file name minus the
3232 archive suffix, if recognized).  Any member names that do not begin
3233 with that directory name (after
3234 transformations from @option{--transform} and
3235 @option{--strip-components}) will be prefixed with it.  Recognized
3236 file name suffixes are @samp{.tar}, and any compression suffixes
3237 recognizable by @xref{--auto-compress}.
3239 @opsummary{overwrite}
3240 @item --overwrite
3242 Overwrite existing files and directory metadata when extracting files
3243 from an archive.  @xref{Overwrite Old Files}.
3245 @opsummary{overwrite-dir}
3246 @item --overwrite-dir
3248 Overwrite the metadata of existing directories when extracting files
3249 from an archive.  @xref{Overwrite Old Files}.
3251 @opsummary{owner}
3252 @item --owner=@var{user}
3254 Specifies that @command{tar} should use @var{user} as the owner of members
3255 when creating archives, instead of the user associated with the source
3256 file.  @var{user} can specify a symbolic name, or a numeric
3257 @acronym{ID}, or both as @var{name}:@var{id}.
3258 @xref{override}.
3260 This option does not affect extraction from archives.  See also
3261 @option{--owner-map}, below.
3263 @opsummary{owner-map}
3264 @item --owner-map=@var{file}
3266 Read owner translation map from @var{file}.  This option allows to
3267 translate only certain owner names or UIDs.  @xref{override}, for a
3268 detailed description.  When used together with @option{--owner}
3269 option, the latter affects only those files whose owner is not listed
3270 in the @var{file}.
3272 This option does not affect extraction from archives.
3274 @opsummary{pax-option}
3275 @item --pax-option=@var{keyword-list}
3276 This option enables creation of the archive in @acronym{POSIX.1-2001}
3277 format (@pxref{posix}) and modifies the way @command{tar} handles the
3278 extended header keywords.  @var{Keyword-list} is a comma-separated
3279 list of keyword options.  @xref{PAX keywords}, for a detailed
3280 discussion.
3282 @opsummary{portability}
3283 @item --portability
3284 @itemx --old-archive
3285 Synonym for @option{--format=v7}.
3287 @opsummary{posix}
3288 @item --posix
3289 Same as @option{--format=posix}.
3291 @opsummary{preserve-order}
3292 @item --preserve-order
3294 (See @option{--same-order}; @pxref{Reading}.)
3296 @opsummary{preserve-permissions}
3297 @opsummary{same-permissions}
3298 @item --preserve-permissions
3299 @itemx --same-permissions
3300 @itemx -p
3302 When @command{tar} is extracting an archive, it normally subtracts the
3303 users' umask from the permissions specified in the archive and uses
3304 that number as the permissions to create the destination file.
3305 Specifying this option instructs @command{tar} that it should use the
3306 permissions directly from the archive.  @xref{Setting Access Permissions}.
3308 @opsummary{quote-chars}
3309 @item --quote-chars=@var{string}
3310 Always quote characters from @var{string}, even if the selected
3311 quoting style would not quote them (@pxref{quoting styles}).
3313 @opsummary{quoting-style}
3314 @item --quoting-style=@var{style}
3315 Set quoting style to use when printing member and file names
3316 (@pxref{quoting styles}). Valid @var{style} values are:
3317 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3318 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3319 style is @code{escape}, unless overridden while configuring the
3320 package.
3322 @opsummary{read-full-records}
3323 @item --read-full-records
3324 @itemx -B
3326 Specifies that @command{tar} should reblock its input, for reading
3327 from pipes on systems with buggy implementations.  @xref{Reading}.
3329 @opsummary{record-size}
3330 @item --record-size=@var{size}[@var{suf}]
3332 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3333 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3334 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3335 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3336 description of this option.
3338 @opsummary{recursion}
3339 @item --recursion
3341 With this option, @command{tar} recurses into directories (default).
3342 @xref{recurse}.
3344 @opsummary{recursive-unlink}
3345 @item --recursive-unlink
3347 Remove existing
3348 directory hierarchies before extracting directories of the same name
3349 from the archive.  @xref{Recursive Unlink}.
3351 @opsummary{remove-files}
3352 @item --remove-files
3354 Directs @command{tar} to remove the source file from the file system after
3355 appending it to an archive.  @xref{remove files}.
3357 @opsummary{restrict}
3358 @item --restrict
3360 Disable use of some potentially harmful @command{tar} options.
3361 Currently this option disables shell invocation from multi-volume menu
3362 (@pxref{Using Multiple Tapes}).
3364 @opsummary{rmt-command}
3365 @item --rmt-command=@var{cmd}
3367 Notifies @command{tar} that it should use @var{cmd} instead of
3368 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3370 @opsummary{rsh-command}
3371 @item --rsh-command=@var{cmd}
3373 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3374 devices.  @xref{Device}.
3376 @opsummary{same-order}
3377 @item --same-order
3378 @itemx --preserve-order
3379 @itemx -s
3381 This option is an optimization for @command{tar} when running on machines with
3382 small amounts of memory.  It informs @command{tar} that the list of file
3383 arguments has already been sorted to match the order of files in the
3384 archive.  @xref{Reading}.
3386 @opsummary{same-owner}
3387 @item --same-owner
3389 When extracting an archive, @command{tar} will attempt to preserve the owner
3390 specified in the @command{tar} archive with this option present.
3391 This is the default behavior for the superuser; this option has an
3392 effect only for ordinary users.  @xref{Attributes}.
3394 @opsummary{same-permissions}
3395 @item --same-permissions
3397 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3399 @opsummary{seek}
3400 @item --seek
3401 @itemx -n
3403 Assume that the archive media supports seeks to arbitrary
3404 locations.  Usually @command{tar} determines automatically whether
3405 the archive can be seeked or not.  This option is intended for use
3406 in cases when such recognition fails.  It takes effect only if the
3407 archive is open for reading (e.g. with @option{--list} or
3408 @option{--extract} options).
3410 @opsummary{selinux}
3411 @item --selinux
3412 Enable the SELinux context support.
3413 @xref{Extended File Attributes, selinux}.
3415 @opsummary{show-defaults}
3416 @item --show-defaults
3418 Displays the default options used by @command{tar} and exits
3419 successfully.  This option is intended for use in shell scripts.
3420 Here is an example of what you can see using this option:
3422 @smallexample
3423 $ @kbd{tar --show-defaults}
3424 --format=gnu -f- -b20 --quoting-style=escape
3425 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3426 @end smallexample
3428 @noindent
3429 Notice, that this option outputs only one line.  The example output
3430 above has been split to fit page boundaries. @xref{defaults}.
3432 @opsummary{show-omitted-dirs}
3433 @item --show-omitted-dirs
3435 Instructs @command{tar} to mention the directories it is skipping when
3436 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3438 @opsummary{show-snapshot-field-ranges}
3439 @item --show-snapshot-field-ranges
3441 Displays the range of values allowed by this version of @command{tar}
3442 for each field in the snapshot file, then exits successfully.
3443 @xref{Snapshot Files}.
3445 @opsummary{show-transformed-names}
3446 @opsummary{show-stored-names}
3447 @item --show-transformed-names
3448 @itemx --show-stored-names
3450 Display file or member names after applying any transformations
3451 (@pxref{transform}).  In particular, when used in conjunction with one of
3452 the archive creation operations it instructs @command{tar} to list the
3453 member names stored in the archive, as opposed to the actual file
3454 names.  @xref{listing member and file names}.
3456 @opsummary{skip-old-files}
3457 @item --skip-old-files
3459 Do not overwrite existing files when extracting files from an
3460 archive.  @xref{Keep Old Files}.
3462 This option differs from @option{--keep-old-files} in that it does not
3463 treat such files as an error, instead it just silently avoids
3464 overwriting them.
3466 The @option{--warning=existing-file} option can be used together with
3467 this option to produce warning messages about existing old files
3468 (@pxref{warnings}).
3470 @opsummary{sort}
3471 @item --sort=@var{order}
3472 Specify the directory sorting order when reading directories.
3473 @var{Order} may be one of the following:
3475 @table @samp
3476 @item none
3477 No directory sorting is performed. This is the default.
3479 @item name
3480 Sort the directory entries on name. The operating system may deliver
3481 directory entries in a more or less random order, and sorting them
3482 makes archive creation reproducible.
3484 @item inode
3485 Sort the directory entries on inode number. Sorting directories on
3486 inode number may reduce the amount of disk seek operations when
3487 creating an archive for some file systems.
3489 @end table
3491 @opsummary{sparse}
3492 @item --sparse
3493 @itemx -S
3495 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3496 sparse files efficiently.  @xref{sparse}.
3498 @opsummary{sparse-version}
3499 @item --sparse-version=@var{version}
3501 Specifies the @dfn{format version} to use when archiving sparse
3502 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3503 of the supported sparse formats, @xref{Sparse Formats}.
3505 @opsummary{starting-file}
3506 @item --starting-file=@var{name}
3507 @itemx -K @var{name}
3509 This option affects extraction only; @command{tar} will skip extracting
3510 files in the archive until it finds one that matches @var{name}.
3511 @xref{Scarce}.
3513 @opsummary{strip-components}
3514 @item --strip-components=@var{number}
3515 Strip given @var{number} of leading components from file names before
3516 extraction.  For example, if archive @file{archive.tar} contained
3517 @file{/some/file/name}, then running
3519 @smallexample
3520 tar --extract --file archive.tar --strip-components=2
3521 @end smallexample
3523 @noindent
3524 would extract this file to file @file{name}.
3526 @xref{transform}.
3528 @opsummary{suffix}
3529 @item --suffix=@var{suffix}
3531 Alters the suffix @command{tar} uses when backing up files from the default
3532 @samp{~}.  @xref{backup}.
3534 @opsummary{tape-length}
3535 @item --tape-length=@var{num}[@var{suf}]
3536 @itemx -L @var{num}[@var{suf}]
3538 Specifies the length of tapes that @command{tar} is writing as being
3539 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3540 specifies a multiplicative factor to be used instead of 1024.  For
3541 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3542 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3543 discussion of this option.
3545 @opsummary{test-label}
3546 @item --test-label
3548 Reads the volume label.  If an argument is specified, test whether it
3549 matches the volume label.  @xref{--test-label option}.
3551 @opsummary{to-command}
3552 @item --to-command=@var{command}
3554 During extraction @command{tar} will pipe extracted files to the
3555 standard input of @var{command}.  @xref{Writing to an External Program}.
3557 @opsummary{to-stdout}
3558 @item --to-stdout
3559 @itemx -O
3561 During extraction, @command{tar} will extract files to stdout rather
3562 than to the file system.  @xref{Writing to Standard Output}.
3564 @opsummary{totals}
3565 @item --totals[=@var{signo}]
3567 Displays the total number of bytes transferred when processing an
3568 archive.  If an argument is given, these data are displayed on
3569 request, when signal @var{signo} is delivered to @command{tar}.
3570 @xref{totals}.
3572 @opsummary{touch}
3573 @item --touch
3574 @itemx -m
3576 Sets the data modification time of extracted files to the extraction time,
3577 rather than the data modification time stored in the archive.
3578 @xref{Data Modification Times}.
3580 @opsummary{transform}
3581 @opsummary{xform}
3582 @item --transform=@var{sed-expr}
3583 @itemx --xform=@var{sed-expr}
3584 Transform file or member names using @command{sed} replacement expression
3585 @var{sed-expr}.  For example,
3587 @smallexample
3588 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3589 @end smallexample
3591 @noindent
3592 will add to @file{archive} files from the current working directory,
3593 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3594 discussion, @xref{transform}.
3596 To see transformed member names in verbose listings, use
3597 @option{--show-transformed-names} option
3598 (@pxref{show-transformed-names}).
3600 @opsummary{uncompress}
3601 @item --uncompress
3603 (See @option{--compress}, @pxref{gzip})
3605 @opsummary{ungzip}
3606 @item --ungzip
3608 (See @option{--gzip}, @pxref{gzip})
3610 @opsummary{unlink-first}
3611 @item --unlink-first
3612 @itemx -U
3614 Directs @command{tar} to remove the corresponding file from the file
3615 system before extracting it from the archive.  @xref{Unlink First}.
3617 @opsummary{unquote}
3618 @item --unquote
3619 Enable unquoting input file or member names (default).  @xref{input
3620 name quoting}.
3622 @opsummary{use-compress-program}
3623 @item --use-compress-program=@var{prog}
3624 @itemx -I=@var{prog}
3626 Instructs @command{tar} to access the archive through @var{prog}, which is
3627 presumed to be a compression program of some sort.  @xref{gzip}.
3629 @opsummary{utc}
3630 @item --utc
3632 Display file modification dates in @acronym{UTC}.  This option implies
3633 @option{--verbose}.
3635 @opsummary{verbatim-files-from}
3636 @item --verbatim-files-from
3638 Instructs @GNUTAR{} to treat each line read from a file list as a file
3639 name, even if it starts with a dash.
3641 File lists are supplied with the @option{--files-from} (@option{-T})
3642 option.  By default, each line read from a file list is first trimmed
3643 off the leading and trailing whitespace and, if the result begins with
3644 a dash, it is treated as a @GNUTAR{} command line option.
3646 Use the @option{--verbatim-files-from} option to disable this special
3647 handling.  This facilitates the use of @command{tar} with file lists
3648 created by @command{file} command.
3650 This option affects all @option{--files-from} options that occur after
3651 it in the command line.  Its effect is reverted by the
3652 @option{--no-verbatim-files-from} option.
3654 This option is implied by the @option{--null} option.
3656 @xref{verbatim-files-from}.
3658 @opsummary{verbose}
3659 @item --verbose
3660 @itemx -v
3662 Specifies that @command{tar} should be more verbose about the
3663 operations it is performing.  This option can be specified multiple
3664 times for some operations to increase the amount of information displayed.
3665 @xref{verbose}.
3667 @opsummary{verify}
3668 @item --verify
3669 @itemx -W
3671 Verifies that the archive was correctly written when creating an
3672 archive.  @xref{verify}.
3674 @opsummary{version}
3675 @item --version
3677 Print information about the program's name, version, origin and legal
3678 status, all on standard output, and then exit successfully.
3679 @xref{help}.
3681 @opsummary{volno-file}
3682 @item --volno-file=@var{file}
3684 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3685 keep track of which volume of a multi-volume archive it is working in
3686 @var{file}.  @xref{volno-file}.
3688 @opsummary{warning}
3689 @item --warning=@var{keyword}
3691 Enable or disable warning messages identified by @var{keyword}.  The
3692 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3693 @xref{warnings}.
3695 @opsummary{wildcards}
3696 @item --wildcards
3697 Use wildcards when matching member names with patterns.
3698 @xref{controlling pattern-matching}.
3700 @opsummary{wildcards-match-slash}
3701 @item --wildcards-match-slash
3702 Wildcards match @samp{/}.
3703 @xref{controlling pattern-matching}.
3705 @opsummary{xattrs}
3706 @item --xattrs
3707 Enable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3709 @opsummary{xattrs-exclude}
3710 @item --xattrs-exclude=@var{pattern}
3711 Specify exclude pattern for xattr keys.
3712 @xref{Extended File Attributes, xattrs-exclude}.
3714 @opsummary{xattrs-include}
3715 @item --xattrs-include=@var{pattern}.
3716 Specify include pattern for xattr keys.  @var{pattern} is a globbing
3717 pattern, e.g. @samp{--xattrs-include='user.*'} to include
3718 only attributes from the user namespace.
3719 @xref{Extended File Attributes, xattrs-include}.
3721 @opsummary{xz}
3722 @item --xz
3723 @itemx -J
3724 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3726 @item --zstd
3727 Use @command{zstd} for compressing or decompressing the archives.  @xref{gzip}.
3729 @end table
3731 @node Short Option Summary
3732 @subsection Short Options Cross Reference
3734 Here is an alphabetized list of all of the short option forms, matching
3735 them with the equivalent long option.
3737 @multitable @columnfractions 0.20 0.80
3738 @headitem Short Option  @tab Reference
3740 @item -A @tab @ref{--concatenate}.
3742 @item -B @tab @ref{--read-full-records}.
3744 @item -C @tab @ref{--directory}.
3746 @item -F @tab @ref{--info-script}.
3748 @item -G @tab @ref{--incremental}.
3750 @item -J @tab @ref{--xz}.
3752 @item -K @tab @ref{--starting-file}.
3754 @item -L @tab @ref{--tape-length}.
3756 @item -M @tab @ref{--multi-volume}.
3758 @item -N @tab @ref{--newer}.
3760 @item -O @tab @ref{--to-stdout}.
3762 @item -P @tab @ref{--absolute-names}.
3764 @item -R @tab @ref{--block-number}.
3766 @item -S @tab @ref{--sparse}.
3768 @item -T @tab @ref{--files-from}.
3770 @item -U @tab @ref{--unlink-first}.
3772 @item -V @tab @ref{--label}.
3774 @item -W @tab @ref{--verify}.
3776 @item -X @tab @ref{--exclude-from}.
3778 @item -Z @tab @ref{--compress}.
3780 @item -b @tab @ref{--blocking-factor}.
3782 @item -c @tab @ref{--create}.
3784 @item -d @tab @ref{--compare}.
3786 @item -f @tab @ref{--file}.
3788 @item -g @tab @ref{--listed-incremental}.
3790 @item -h @tab @ref{--dereference}.
3792 @item -i @tab @ref{--ignore-zeros}.
3794 @item -j @tab @ref{--bzip2}.
3796 @item -k @tab @ref{--keep-old-files}.
3798 @item -l @tab @ref{--check-links}.
3800 @item -m @tab @ref{--touch}.
3802 @item -o @tab When extracting, same as @ref{--no-same-owner}. When creating,
3803 -- @ref{--old-archive}.
3805 The latter usage is deprecated.  It is retained for compatibility with
3806 the earlier versions of @GNUTAR{}.  In future releases
3807 @option{-o} will be equivalent to @option{--no-same-owner} only.
3809 @item -p @tab @ref{--preserve-permissions}.
3811 @item -r @tab @ref{--append}.
3813 @item -s @tab @ref{--same-order}.
3815 @item -t @tab @ref{--list}.
3817 @item -u @tab @ref{--update}.
3819 @item -v @tab @ref{--verbose}.
3821 @item -w @tab @ref{--interactive}.
3823 @item -x @tab @ref{--extract}.
3825 @item -z @tab @ref{--gzip}.
3827 @end multitable
3829 @node Position-Sensitive Options
3830 @subsection Position-Sensitive Options
3832 Some @GNUTAR{} options can be used multiple times in the same
3833 invocation and affect all arguments that appear after them.  These are
3834 options that control how file names are selected and what kind of
3835 pattern matching is used.
3837 The most obvious example is the @option{-C} option.  It instructs @command{tar}
3838 to change to the directory given as its argument prior to processing
3839 the rest of command line (@pxref{directory}).  Thus, in the following
3840 command:
3842 @example
3843 @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
3844 @end example
3846 @noindent
3847 the file @file{passwd} will be searched in the directory @file{/etc},
3848 and files @file{log} and @file{spool} -- in @file{/var}.
3850 These options can also be used in a file list supplied with the
3851 @option{--files-from} (@option{-T}) option (@pxref{files}).  In that
3852 case they affect all files (patterns) appearing in that file after
3853 them and remain in effect for any arguments processed after that file.
3854 For example, if the file @file{list.txt} contained:
3856 @example
3857 README
3858 -C src
3859 main.c
3860 @end example
3862 @noindent
3863 and @command{tar} were invoked as follows:
3865 @example
3866 @kbd{tar -c -f a.tar -T list.txt Makefile}
3867 @end example
3869 @noindent
3870 then the file @file{README} would be looked up in the current working
3871 directory, and files @file{main.c} and @file{Makefile} would be looked
3872 up in the directory @file{src}.
3874 Many options can be prefixed with @option{--no-} to cancel the effect
3875 of the original option.
3877 For example, the @option{--recursion} option controls whether to
3878 recurse in the subdirectories.  It's counterpart
3879 @option{--no-recursion} disables this.  Consider the command below.  It will
3880 store in the archive the directory @file{/usr} with all files and
3881 directories that are located in it as well as any files and
3882 directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
3883 option is the default and is used here for clarity.  The same example
3884 can be written as:
3886 @example
3887 tar -cf a.tar /usr --no-recursion /var/*
3888 @end example
3891 @example
3892 tar -cf a.tar --recursion /usr --no-recursion /var/*
3893 @end example
3895 During archive creation, @GNUTAR{} keeps track of positional options
3896 used and arguments affected by them.  If it finds out that any such
3897 options are used in an obviously erroneous way, the fact is reported
3898 and exit code is set to 2.  E.g.:
3900 @example
3901 @group
3902 $ @kbd{tar -cf a.tar . --exclude '*.o'}
3903 tar: The following options were used after any non-optional
3904 arguments in archive create or update mode.  These options are
3905 positional and affect only arguments that follow them.  Please,
3906 rearrange them properly.
3907 tar: --exclude '*.o' has no effect
3908 tar: Exiting with failure status due to previous errors
3909 @end group
3910 @end example
3912 The following table summarizes all position-sensitive options.
3914 @table @option
3915 @item --directory=@var{dir}
3916 @itemx -C @var{dir}
3917 @xref{directory}.
3919 @item --null
3920 @itemx --no-null
3921 @xref{nul}.
3923 @item --unquote
3924 @itemx --no-unquote
3925 @xref{input name quoting}.
3927 @item --verbatim-files-from
3928 @itemx --no-verbatim-files-from
3929 @xref{verbatim-files-from}.
3931 @item --recursion
3932 @itemx --no-recursion
3933 @xref{recurse}.
3935 @item --anchored
3936 @itemx --no-anchored
3937 @xref{anchored patterns}.
3939 @item --ignore-case
3940 @itemx --no-ignore-case
3941 @xref{case-insensitive matches}.
3943 @item --wildcards
3944 @itemx --no-wildcards
3945 @xref{controlling pattern-matching}.
3947 @item --wildcards-match-slash
3948 @itemx --no-wildcards-match-slash
3949 @xref{controlling pattern-matching}.
3951 @item --exclude
3952 @xref{exclude}.
3954 @item --exclude-from
3955 @itemx -X
3956 @itemx --exclude-caches
3957 @itemx --exclude-caches-under
3958 @itemx --exclude-caches-all
3959 @itemx --exclude-tag
3960 @itemx --exclude-ignore
3961 @itemx --exclude-ignore-recursive
3962 @itemx --exclude-tag-under
3963 @itemx --exclude-tag-all
3964 @itemx --exclude-vcs
3965 @itemx --exclude-vcs-ignores
3966 @itemx --exclude-backups
3967 @xref{exclude}.
3968 @end table
3970 @node help
3971 @section @GNUTAR{} documentation
3973 @cindex Getting program version number
3974 @opindex version
3975 @cindex Version of the @command{tar} program
3976 Being careful, the first thing is really checking that you are using
3977 @GNUTAR{}, indeed.  The @option{--version} option
3978 causes @command{tar} to print information about its name, version,
3979 origin and legal status, all on standard output, and then exit
3980 successfully.  For example, @w{@samp{tar --version}} might print:
3982 @smallexample
3983 tar (GNU tar) @value{VERSION}
3984 Copyright (C) 2013-2020 Free Software Foundation, Inc.
3985 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3986 This is free software: you are free to change and redistribute it.
3987 There is NO WARRANTY, to the extent permitted by law.
3989 Written by John Gilmore and Jay Fenlason.
3990 @end smallexample
3992 @noindent
3993 The first occurrence of @samp{tar} in the result above is the program
3994 name in the package (for example, @command{rmt} is another program),
3995 while the second occurrence of @samp{tar} is the name of the package
3996 itself, containing possibly many programs.  The package is currently
3997 named @samp{tar}, after the name of the main program it
3998 contains@footnote{There are plans to merge the @command{cpio} and
3999 @command{tar} packages into a single one which would be called
4000 @code{paxutils}.  So, who knows if, one of this days, the
4001 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
4002 paxutils) 3.2}}.}.
4004 @cindex Obtaining help
4005 @cindex Listing all @command{tar} options
4006 @xopindex{help, introduction}
4007 Another thing you might want to do is checking the spelling or meaning
4008 of some particular @command{tar} option, without resorting to this
4009 manual, for once you have carefully read it.  @GNUTAR{}
4010 has a short help feature, triggerable through the
4011 @option{--help} option.  By using this option, @command{tar} will
4012 print a usage message listing all available options on standard
4013 output, then exit successfully, without doing anything else and
4014 ignoring all other options.  Even if this is only a brief summary, it
4015 may be several screens long.  So, if you are not using some kind of
4016 scrollable window, you might prefer to use something like:
4018 @smallexample
4019 $ @kbd{tar --help | less}
4020 @end smallexample
4022 @noindent
4023 presuming, here, that you like using @command{less} for a pager.  Other
4024 popular pagers are @command{more} and @command{pg}.  If you know about some
4025 @var{keyword} which interests you and do not want to read all the
4026 @option{--help} output, another common idiom is doing:
4028 @smallexample
4029 tar --help | grep @var{keyword}
4030 @end smallexample
4032 @noindent
4033 for getting only the pertinent lines.  Notice, however, that some
4034 @command{tar} options have long description lines and the above
4035 command will list only the first of them.
4037 The exact look of the option summary displayed by @kbd{tar --help} is
4038 configurable. @xref{Configuring Help Summary}, for a detailed description.
4040 @opindex usage
4041 If you only wish to check the spelling of an option, running @kbd{tar
4042 --usage} may be a better choice.  This will display a terse list of
4043 @command{tar} options without accompanying explanations.
4045 The short help output is quite succinct, and you might have to get
4046 back to the full documentation for precise points.  If you are reading
4047 this paragraph, you already have the @command{tar} manual in some
4048 form.  This manual is available in a variety of forms from
4049 @url{http://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
4050 distribution, provided you have @TeX{} already installed somewhere,
4051 and a laser printer around.  Just configure the distribution, execute
4052 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
4053 usual way (contact your local guru to know how).  If @GNUTAR{}
4054 has been conveniently installed at your place, this
4055 manual is also available in interactive, hypertextual form as an Info
4056 file.  Just call @w{@samp{info tar}} or, if you do not have the
4057 @command{info} program handy, use the Info reader provided within
4058 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
4060 There is currently no @code{man} page for @GNUTAR{}.
4061 If you observe such a @code{man} page on the system you are running,
4062 either it does not belong to @GNUTAR{}, or it has not
4063 been produced by @acronym{GNU}.  Some package maintainers convert
4064 @kbd{tar --help} output to a man page, using @command{help2man}.  In
4065 any case, please bear in mind that the authoritative source of
4066 information about @GNUTAR{} is this Texinfo documentation.
4068 @node defaults
4069 @section Obtaining @GNUTAR{} default values
4071 @opindex show-defaults
4072 @GNUTAR{} has some predefined defaults that are used when you do not
4073 explicitly specify another values.  To obtain a list of such
4074 defaults, use @option{--show-defaults} option.  This will output the
4075 values in the form of @command{tar} command line options:
4077 @smallexample
4078 @group
4079 $ @kbd{tar --show-defaults}
4080 --format=gnu -f- -b20 --quoting-style=escape
4081 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
4082 @end group
4083 @end smallexample
4085 @noindent
4086 Notice, that this option outputs only one line.  The example output above
4087 has been split to fit page boundaries.
4089 @noindent
4090 The above output shows that this version of @GNUTAR{} defaults to
4091 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
4092 output as the archive, if no @option{--file} option has been given
4093 (@pxref{file tutorial}), the default blocking factor is 20
4094 (@pxref{Blocking Factor}).  It also shows the default locations where
4095 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
4097 @node verbose
4098 @section Checking @command{tar} progress
4100 Typically, @command{tar} performs most operations without reporting any
4101 information to the user except error messages.  When using @command{tar}
4102 with many options, particularly ones with complicated or
4103 difficult-to-predict behavior, it is possible to make serious mistakes.
4104 @command{tar} provides several options that make observing @command{tar}
4105 easier.  These options cause @command{tar} to print information as it
4106 progresses in its job, and you might want to use them just for being
4107 more careful about what is going on, or merely for entertaining
4108 yourself.  If you have encountered a problem when operating on an
4109 archive, however, you may need more information than just an error
4110 message in order to solve the problem.  The following options can be
4111 helpful diagnostic tools.
4113 @cindex Verbose operation
4114 @opindex verbose
4115 Normally, the @option{--list} (@option{-t}) command to list an archive
4116 prints just the file names (one per line) and the other commands are
4117 silent. When used with most operations, the @option{--verbose}
4118 (@option{-v}) option causes @command{tar} to print the name of each
4119 file or archive member as it is processed.  This and the other options
4120 which make @command{tar} print status information can be useful in
4121 monitoring @command{tar}.
4123 With @option{--create} or @option{--extract}, @option{--verbose} used
4124 once just prints the names of the files or members as they are processed.
4125 Using it twice causes @command{tar} to print a longer listing
4126 (@xref{verbose member listing}, for the description) for each member.
4127 Since @option{--list} already prints  the names of the members,
4128 @option{--verbose} used once with @option{--list} causes @command{tar}
4129 to print an @samp{ls -l} type listing of the files in the archive.
4130 The following examples both extract members with long list output:
4132 @smallexample
4133 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
4134 $ @kbd{tar xvvf archive.tar}
4135 @end smallexample
4137 Verbose output appears on the standard output except when an archive is
4138 being written to the standard output, as with @samp{tar --create
4139 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
4140 installer let standard output be the default archive).  In that case
4141 @command{tar} writes verbose output to the standard error stream.
4143 If @option{--index-file=@var{file}} is specified, @command{tar} sends
4144 verbose output to @var{file} rather than to standard output or standard
4145 error.
4147 @anchor{totals}
4148 @cindex Obtaining total status information
4149 @opindex totals
4150 The @option{--totals} option causes @command{tar} to print on the
4151 standard error the total amount of bytes transferred when processing
4152 an archive.  When creating or appending to an archive, this option
4153 prints the number of bytes written to the archive and the average
4154 speed at which they have been written, e.g.:
4156 @smallexample
4157 @group
4158 $ @kbd{tar -c -f archive.tar --totals /home}
4159 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
4160 @end group
4161 @end smallexample
4163 When reading an archive, this option displays the number of bytes
4164 read:
4166 @smallexample
4167 @group
4168 $ @kbd{tar -x -f archive.tar --totals}
4169 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
4170 @end group
4171 @end smallexample
4173 Finally, when deleting from an archive, the @option{--totals} option
4174 displays both numbers plus number of bytes removed from the archive:
4176 @smallexample
4177 @group
4178 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
4179 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
4180 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
4181 Total bytes deleted: 1474048
4182 @end group
4183 @end smallexample
4185 You can also obtain this information on request.  When
4186 @option{--totals} is used with an argument, this argument is
4187 interpreted as a symbolic name of a signal, upon delivery of which the
4188 statistics is to be printed:
4190 @table @option
4191 @item --totals=@var{signo}
4192 Print statistics upon delivery of signal @var{signo}.  Valid arguments
4193 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4194 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
4195 accepted.
4196 @end table
4198 Both forms of @option{--totals} option can be used simultaneously.
4199 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
4200 extract all members from its default archive and print statistics
4201 after finishing the extraction, as well as when receiving signal
4202 @code{SIGUSR1}.
4204 @anchor{Progress information}
4205 @cindex Progress information
4206 The @option{--checkpoint} option prints an occasional message
4207 as @command{tar} reads or writes the archive.  It is designed for
4208 those who don't need the more detailed (and voluminous) output of
4209 @option{--block-number} (@option{-R}), but do want visual confirmation
4210 that @command{tar} is actually making forward progress.  By default it
4211 prints a message each 10 records read or written.  This can be changed
4212 by giving it a numeric argument after an equal sign:
4214 @smallexample
4215 $ @kbd{tar -c --checkpoint=1000} /var
4216 tar: Write checkpoint 1000
4217 tar: Write checkpoint 2000
4218 tar: Write checkpoint 3000
4219 @end smallexample
4221 This example shows the default checkpoint message used by
4222 @command{tar}.  If you place a dot immediately after the equal
4223 sign, it will print a @samp{.} at each checkpoint@footnote{This is
4224 actually a shortcut for @option{--checkpoint=@var{n}
4225 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
4227 @smallexample
4228 $ @kbd{tar -c --checkpoint=.1000} /var
4230 @end smallexample
4232 The @option{--checkpoint} option provides a flexible mechanism for
4233 executing arbitrary actions upon hitting checkpoints, see the next
4234 section (@pxref{checkpoints}), for more information on it.
4236 @opindex show-omitted-dirs
4237 @anchor{show-omitted-dirs}
4238 The @option{--show-omitted-dirs} option, when reading an archive---with
4239 @option{--list} or @option{--extract}, for example---causes a message
4240 to be printed for each directory in the archive which is skipped.
4241 This happens regardless of the reason for skipping: the directory might
4242 not have been named on the command line (implicitly or explicitly),
4243 it might be excluded by the use of the
4244 @option{--exclude=@var{pattern}} option, or some other reason.
4246 @opindex block-number
4247 @cindex Block number where error occurred
4248 @anchor{block-number}
4249 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
4250 every message it would normally produce, the block number within the
4251 archive where the message was triggered.  Also, supplementary messages
4252 are triggered when reading blocks full of NULs, or when hitting end of
4253 file on the archive.  As of now, if the archive is properly terminated
4254 with a NUL block, the reading of the file may stop before end of file
4255 is met, so the position of end of file will not usually show when
4256 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
4257 drains the archive before exiting when reading the
4258 archive from a pipe.
4260 @cindex Error message, block number of
4261 This option is especially useful when reading damaged archives, since
4262 it helps pinpoint the damaged sections.  It can also be used with
4263 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
4264 choose among several backup tapes when retrieving a file later, in
4265 favor of the tape where the file appears earliest (closest to the
4266 front of the tape).  @xref{backup}.
4268 @node checkpoints
4269 @section Checkpoints
4270 @cindex checkpoints, defined
4271 @opindex checkpoint
4272 @opindex checkpoint-action
4274 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
4275 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
4276 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
4277 periodically execute arbitrary actions.
4279 The checkpoint facility is enabled using the following option:
4281 @table @option
4282 @xopindex{checkpoint, defined}
4283 @item --checkpoint[=@var{n}]
4284 Schedule checkpoints before writing or reading each @var{n}th record.
4285 The default value for @var{n} is 10.
4286 @end table
4288 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
4289 These actions include: pausing, displaying textual messages, and
4290 executing arbitrary external programs.  Actions are defined using
4291 the @option{--checkpoint-action} option.
4293 @table @option
4294 @xopindex{checkpoint-action, defined}
4295 @item --checkpoint-action=@var{action}
4296 Execute an @var{action} at each checkpoint.
4297 @end table
4299 @cindex @code{echo}, checkpoint action
4300 The simplest value of @var{action} is @samp{echo}.  It instructs
4301 @command{tar} to display the default message on the standard error
4302 stream upon arriving at each checkpoint.  The default message is (in
4303 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
4304 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
4305 Here, @var{n} represents ordinal number of the checkpoint.
4307 In another locales, translated versions of this message are used.
4309 This is the default action, so running:
4311 @smallexample
4312 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
4313 @end smallexample
4315 @noindent
4316 is equivalent to:
4318 @smallexample
4319 $ @kbd{tar -c --checkpoint=1000} /var
4320 @end smallexample
4322 The @samp{echo} action also allows to supply a customized message.
4323 You do so by placing an equals sign and the message right after it,
4324 e.g.:
4326 @smallexample
4327 --checkpoint-action="echo=Hit %s checkpoint #%u"
4328 @end smallexample
4330 The @samp{%s} and @samp{%u} in the above example are
4331 @dfn{format specifiers}.  The @samp{%s} specifier is replaced with
4332 the @dfn{type} of the checkpoint: @samp{write} or
4333 @samp{read} (or a corresponding translated version in locales other
4334 than @acronym{POSIX}).  The @samp{%u} specifier is replaced with
4335 the ordinal number of the checkpoint.  Thus, the above example could
4336 produce the following output when used with the @option{--create}
4337 option:
4339 @smallexample
4340 tar: Hit write checkpoint #10
4341 tar: Hit write checkpoint #20
4342 tar: Hit write checkpoint #30
4343 @end smallexample
4345 The complete list of available format specifiers follows.  Some of
4346 them can take optional arguments.  These arguments, if given, are
4347 supplied in curly braces between the percent sign and the specifier
4348 letter.
4350 @table @samp
4351 @item %s
4352 Print type of the checkpoint (@samp{write} or @samp{read}).
4354 @item %u
4355 Print number of the checkpoint.
4357 @item %@{r,w,d@}T
4358 Print number of bytes transferred so far and approximate transfer
4359 speed.  Optional arguments supply prefixes to be used before number
4360 of bytes read, written and deleted, correspondingly.  If absent,
4361 they default to @samp{R}. @samp{W}, @samp{D}.  Any or all of them can
4362 be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
4363 statistics without any prefixes.  Any surplus arguments, if present,
4364 are silently ignored.
4366 @example
4367 $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
4368 tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
4369 tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
4370 @end example
4372 @noindent
4373 See also the @samp{totals} action, described below.
4375 @item %@{@var{fmt}@}t
4376 Output current local time using @var{fmt} as format for @command{strftime}
4377 (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}).  The
4378 @samp{@{@var{fmt}@}} part is optional.  If not present, the default
4379 format is @samp{%c}, i.e. the preferred date and time representation
4380 for the current locale.
4382 @item %@{@var{n}@}*
4383 Pad output with spaces to the @var{n}th column.  If the
4384 @samp{@{@var{n}@}} part is omitted, the current screen width
4385 is assumed.
4387 @item %c
4388 This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
4389 intended mainly for use with @samp{ttyout} action (see below).
4390 @end table
4392 Aside from format expansion, the message string is subject to
4393 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
4394 replaced with their corresponding @acronym{ASCII} characters
4395 (@pxref{escape sequences}).  E.g. the following action will produce an
4396 audible bell and the message described above at each checkpoint:
4398 @smallexample
4399 --checkpoint-action='echo=\aHit %s checkpoint #%u'
4400 @end smallexample
4402 @cindex @code{bell}, checkpoint action
4403 There is also a special action which produces an audible signal:
4404 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
4405 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
4406 whereas @samp{echo='\a'} sends it to the standard error.
4408 @cindex @code{ttyout}, checkpoint action
4409 The @samp{ttyout=@var{string}} action outputs @var{string} to
4410 @file{/dev/tty}, so it can be used even if the standard output is
4411 redirected elsewhere.  The @var{string} is subject to the same
4412 modifications as with @samp{echo} action.  In contrast to the latter,
4413 @samp{ttyout} does not prepend @command{tar} executable name to the
4414 string, nor does it output a newline after it.  For example, the
4415 following action will print the checkpoint message at the same screen
4416 line, overwriting any previous message:
4418 @smallexample
4419 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
4420 @end smallexample
4422 @noindent
4423 Notice the use of @samp{%*} specifier to clear out any eventual
4424 remains of the prior output line.  As as more complex example,
4425 consider this:
4427 @smallexample
4428 --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
4429 @end smallexample
4431 @noindent
4432 This prints the current local time, number of seconds expired since
4433 tar was started, the checkpoint ordinal number, transferred bytes and
4434 average computed I/O speed.
4436 @cindex @code{dot}, checkpoint action
4437 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
4438 instructs @command{tar} to print a single dot on the standard listing
4439 stream, e.g.:
4441 @smallexample
4442 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4444 @end smallexample
4446 For compatibility with previous @GNUTAR{} versions, this action can
4447 be abbreviated by placing a dot in front of the checkpoint frequency,
4448 as shown in the previous section.
4450 @cindex @code{totals}, checkpoint action
4451 The @samp{totals} action prints the total number of bytes transferred
4452 so far.  The format of the data is the same as for the
4453 @option{--totals} option (@pxref{totals}).  See also @samp{%T} format
4454 specifier of the @samp{echo} or @samp{ttyout} action.
4456 @cindex @code{sleep}, checkpoint action
4457 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4458 amount of seconds.  The following example will stop for 30 seconds at each
4459 checkpoint:
4461 @smallexample
4462 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4463 @end smallexample
4465 @anchor{checkpoint wait}
4466 @cindex @code{wait}, checkpoint action
4467 The @code{wait=@var{signo}} action stops further execution until the
4468 signal @var{signo} is delivered.  Valid values for @var{signo} are:
4469 @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4470 @code{SIGUSR2}.  The @samp{SIG} prefix is optional.  For example:
4472 @example
4473 $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
4474 @end example
4476 In this example, @GNUTAR{} will stop archivation at each 1000th
4477 checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
4478 and resume processing.
4480 This action is used by the @command{genfile} utility to perform
4481 modifications on the input files upon hitting certain checkpoints
4482 (@pxref{Exec Mode, genfile}).
4484 @anchor{checkpoint exec}
4485 @cindex @code{exec}, checkpoint action
4486 Finally, the @code{exec} action executes a given external command.
4487 For example:
4489 @smallexample
4490 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4491 @end smallexample
4493 The supplied command can be any valid command invocation, with or
4494 without additional command line arguments.  If it does contain
4495 arguments, don't forget to quote it to prevent it from being split by
4496 the shell.  @xref{external, Running External Commands}, for more detail.
4498 The command gets a copy of @command{tar}'s environment plus the
4499 following variables:
4501 @table @env
4502 @vrindex TAR_VERSION, checkpoint script environment
4503 @item TAR_VERSION
4504 @GNUTAR{} version number.
4506 @vrindex TAR_ARCHIVE, checkpoint script environment
4507 @item TAR_ARCHIVE
4508 The name of the archive @command{tar} is processing.
4510 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4511 @item TAR_BLOCKING_FACTOR
4512 Current blocking factor (@pxref{Blocking}).
4514 @vrindex TAR_CHECKPOINT, checkpoint script environment
4515 @item TAR_CHECKPOINT
4516 Number of the checkpoint.
4518 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4519 @item TAR_SUBCOMMAND
4520 A short option describing the operation @command{tar} is executing.
4521 @xref{Operations}, for a complete list of subcommand options.
4523 @vrindex TAR_FORMAT, checkpoint script environment
4524 @item TAR_FORMAT
4525 Format of the archive being processed. @xref{Formats}, for a complete
4526 list of archive format names.
4527 @end table
4529 These environment variables can also be passed as arguments to the
4530 command, provided that they are properly escaped, for example:
4532 @smallexample
4533 @kbd{tar -c -f arc.tar \
4534      --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
4535 @end smallexample
4537 @noindent
4538 Notice single quotes to prevent variable names from being expanded by
4539 the shell when invoking @command{tar}.
4541 Any number of actions can be defined, by supplying several
4542 @option{--checkpoint-action} options in the command line.  For
4543 example, the command below displays two messages, pauses
4544 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4546 @example
4547 @group
4548 $ @kbd{tar -c -f arc.tar \
4549        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4550        --checkpoint-action='echo=Sleeping for 30 seconds' \
4551        --checkpoint-action='sleep=30' \
4552        --checkpoint-action='exec=/sbin/cpoint'}
4553 @end group
4554 @end example
4556 This example also illustrates the fact that
4557 @option{--checkpoint-action} can be used without
4558 @option{--checkpoint}.  In this case, the default checkpoint frequency
4559 (at each 10th record) is assumed.
4561 @node warnings
4562 @section Controlling Warning Messages
4564 Sometimes, while performing the requested task, @GNUTAR{} notices
4565 some conditions that are not exactly errors, but which the user
4566 should be aware of.  When this happens, @command{tar} issues a
4567 @dfn{warning message} describing the condition.  Warning messages
4568 are output to the standard error and they do not affect the exit
4569 code of @command{tar} command.
4571 @xopindex{warning, explained}
4572 @GNUTAR{} allows the user to suppress some or all of its warning
4573 messages:
4575 @table @option
4576 @item --warning=@var{keyword}
4577 Control display of the warning messages identified by @var{keyword}.
4578 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4579 suppressed.  Otherwise, they are enabled.
4581 Multiple @option{--warning} messages accumulate.
4583 The tables below list allowed values for @var{keyword} along with the
4584 warning messages they control.
4585 @end table
4587 @subheading Keywords controlling @command{tar} operation
4588 @table @asis
4589 @kwindex all
4590 @item all
4591 Enable all warning messages.  This is the default.
4592 @kwindex none
4593 @item none
4594 Disable all warning messages.
4595 @kwindex filename-with-nuls
4596 @cindex @samp{file name read contains nul character}, warning message
4597 @item filename-with-nuls
4598 @samp{%s: file name read contains nul character}
4599 @kwindex alone-zero-block
4600 @cindex @samp{A lone zero block at}, warning message
4601 @item alone-zero-block
4602 @samp{A lone zero block at %s}
4603 @end table
4605 @subheading Keywords applicable for @command{tar --create}
4606 @table @asis
4607 @kwindex cachedir
4608 @cindex @samp{contains a cache directory tag}, warning message
4609 @item cachedir
4610 @samp{%s: contains a cache directory tag %s; %s}
4611 @kwindex file-shrank
4612 @cindex @samp{File shrank by %s bytes}, warning message
4613 @item file-shrank
4614 @samp{%s: File shrank by %s bytes; padding with zeros}
4615 @kwindex xdev
4616 @cindex @samp{file is on a different filesystem}, warning message
4617 @item xdev
4618 @samp{%s: file is on a different filesystem; not dumped}
4619 @kwindex file-ignored
4620 @cindex @samp{Unknown file type; file ignored}, warning message
4621 @cindex @samp{socket ignored}, warning message
4622 @cindex @samp{door ignored}, warning message
4623 @item file-ignored
4624 @samp{%s: Unknown file type; file ignored}
4625 @*@samp{%s: socket ignored}
4626 @*@samp{%s: door ignored}
4627 @kwindex file-unchanged
4628 @cindex @samp{file is unchanged; not dumped}, warning message
4629 @item file-unchanged
4630 @samp{%s: file is unchanged; not dumped}
4631 @kwindex ignore-archive
4632 @cindex @samp{archive cannot contain itself; not dumped}, warning message
4633 @item ignore-archive
4634 @samp{%s: archive cannot contain itself; not dumped}
4635 @kwindex file-removed
4636 @cindex @samp{File removed before we read it}, warning message
4637 @item file-removed
4638 @samp{%s: File removed before we read it}
4639 @kwindex file-changed
4640 @cindex @samp{file changed as we read it}, warning message
4641 @item file-changed
4642 @samp{%s: file changed as we read it}
4643 @item failed-read
4644 Suppresses warnings about read failures, which can occur if files
4645 or directories are unreadable, or if they change while being read.  This
4646 keyword applies only if used together with the @option{--ignore-failed-read}
4647 option. @xref{Ignore Failed Read}.
4648 @end table
4650 @subheading Keywords applicable for @command{tar --extract}
4651 @table @asis
4652 @kwindex existing-file
4653 @cindex @samp{%s: skipping existing file}, warning message
4654 @item existing-file
4655 @samp{%s: skipping existing file}
4656 @kwindex timestamp
4657 @cindex @samp{implausibly old time stamp %s}, warning message
4658 @cindex @samp{time stamp %s is %s s in the future}, warning message
4659 @item timestamp
4660 @samp{%s: implausibly old time stamp %s}
4661 @*@samp{%s: time stamp %s is %s s in the future}
4662 @kwindex contiguous-cast
4663 @cindex @samp{Extracting contiguous files as regular files}, warning message
4664 @item contiguous-cast
4665 @samp{Extracting contiguous files as regular files}
4666 @kwindex symlink-cast
4667 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4668 @item symlink-cast
4669 @samp{Attempting extraction of symbolic links as hard links}
4670 @kwindex unknown-cast
4671 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4672 @item unknown-cast
4673 @samp{%s: Unknown file type '%c', extracted as normal file}
4674 @kwindex ignore-newer
4675 @cindex @samp{Current %s is newer or same age}, warning message
4676 @item ignore-newer
4677 @samp{Current %s is newer or same age}
4678 @kwindex unknown-keyword
4679 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4680 @item unknown-keyword
4681 @samp{Ignoring unknown extended header keyword '%s'}
4682 @kwindex decompress-program
4683 @item decompress-program
4684 Controls verbose description of failures occurring when trying to run
4685 alternative decompressor programs (@pxref{alternative decompression
4686 programs}).  This warning is disabled by default (unless
4687 @option{--verbose} is used).  A common example of what you can get
4688 when using this warning is:
4690 @smallexample
4691 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4692 tar (child): cannot run compress: No such file or directory
4693 tar (child): trying gzip
4694 @end smallexample
4696 This means that @command{tar} first tried to decompress
4697 @file{archive.Z} using @command{compress}, and, when that
4698 failed, switched to @command{gzip}.
4699 @kwindex record-size
4700 @cindex @samp{Record size = %lu blocks}, warning message
4701 @item record-size
4702 @samp{Record size = %lu blocks}
4703 @end table
4705 @subheading Keywords controlling incremental extraction:
4706 @table @asis
4707 @kwindex rename-directory
4708 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4709 @cindex @samp{%s: Directory has been renamed}, warning message
4710 @item rename-directory
4711 @samp{%s: Directory has been renamed from %s}
4712 @*@samp{%s: Directory has been renamed}
4713 @kwindex new-directory
4714 @cindex @samp{%s: Directory is new}, warning message
4715 @item new-directory
4716 @samp{%s: Directory is new}
4717 @kwindex xdev
4718 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4719 @item xdev
4720 @samp{%s: directory is on a different device: not purging}
4721 @kwindex bad-dumpdir
4722 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4723 @item bad-dumpdir
4724 @samp{Malformed dumpdir: 'X' never used}
4725 @end table
4727 @node interactive
4728 @section Asking for Confirmation During Operations
4729 @cindex Interactive operation
4731 Typically, @command{tar} carries out a command without stopping for
4732 further instructions.  In some situations however, you may want to
4733 exclude some files and archive members from the operation (for instance
4734 if disk or storage space is tight).  You can do this by excluding
4735 certain files automatically (@pxref{Choosing}), or by performing
4736 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4737 @command{tar} also accepts @option{--confirmation} for this option.
4739 @opindex interactive
4740 When the @option{--interactive} (@option{-w}) option is specified, before
4741 reading, writing, or deleting files, @command{tar} first prints a message
4742 for each such file, telling what operation it intends to take, then asks
4743 for confirmation on the terminal.  The actions which require
4744 confirmation include adding a file to the archive, extracting a file
4745 from the archive, deleting a file from the archive, and deleting a file
4746 from disk.  To confirm the action, you must type a line of input
4747 beginning with @samp{y}.  If your input line begins with anything other
4748 than @samp{y}, @command{tar} skips that file.
4750 If @command{tar} is reading the archive from the standard input,
4751 @command{tar} opens the file @file{/dev/tty} to support the interactive
4752 communications.
4754 Verbose output is normally sent to standard output, separate from
4755 other error messages.  However, if the archive is produced directly
4756 on standard output, then verbose output is mixed with errors on
4757 @code{stderr}.  Producing the archive on standard output may be used
4758 as a way to avoid using disk space, when the archive is soon to be
4759 consumed by another process reading it, say.  Some people felt the need
4760 of producing an archive on stdout, still willing to segregate between
4761 verbose output and error output.  A possible approach would be using a
4762 named pipe to receive the archive, and having the consumer process to
4763 read from that named pipe.  This has the advantage of letting standard
4764 output free to receive verbose output, all separate from errors.
4766 @node external
4767 @section Running External Commands
4769 Certain @GNUTAR{} operations imply running external commands that you
4770 supply on the command line.  One of such operations is checkpointing,
4771 described above (@pxref{checkpoint exec}).  Another example of this
4772 feature is the @option{-I} option, which allows you to supply the
4773 program to use for compressing or decompressing the archive
4774 (@pxref{use-compress-program}).
4776 Whenever such operation is requested, @command{tar} first splits the
4777 supplied command into words much like the shell does.  It then treats
4778 the first word as the name of the program or the shell script to execute
4779 and the rest of words as its command line arguments.  The program,
4780 unless given as an absolute file name, is searched in the shell's
4781 @env{PATH}.
4783 Any additional information is normally supplied to external commands
4784 in environment variables, specific to each particular operation.  For
4785 example, the @option{--checkpoint-action=exec} option, defines the
4786 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4787 upon.  You can, should the need be, use these variables in the
4788 command line of the external command.  For example:
4790 @smallexample
4791 $ @kbd{tar -x -f archive.tar \
4792     --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4793 @end smallexample
4795 @noindent
4796 This command prints for each checkpoint its number and the name of the
4797 archive, using the same output line on the screen.
4799 Notice the use of single quotes to prevent variable names from being
4800 expanded by the shell when invoking @command{tar}.
4802 @node operations
4803 @chapter @GNUTAR{} Operations
4805 @menu
4806 * Basic tar::
4807 * Advanced tar::
4808 * create options::
4809 * extract options::
4810 * backup::
4811 * looking ahead::
4812 @end menu
4814 @node Basic tar
4815 @section Basic @GNUTAR{} Operations
4817 The basic @command{tar} operations, @option{--create} (@option{-c}),
4818 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4819 @option{-x}), are currently presented and described in the tutorial
4820 chapter of this manual.  This section provides some complementary notes
4821 for these operations.
4823 @table @option
4824 @xopindex{create, complementary notes}
4825 @item --create
4826 @itemx -c
4828 Creating an empty archive would have some kind of elegance.  One can
4829 initialize an empty archive and later use @option{--append}
4830 (@option{-r}) for adding all members.  Some applications would not
4831 welcome making an exception in the way of adding the first archive
4832 member.  On the other hand, many people reported that it is
4833 dangerously too easy for @command{tar} to destroy a magnetic tape with
4834 an empty archive@footnote{This is well described in @cite{Unix-haters
4835 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4836 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4838 @enumerate
4839 @item
4840 Mistakingly using @code{create} instead of @code{extract}, when the
4841 intent was to extract the full contents of an archive.  This error
4842 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4843 the QWERTY keyboard.  Instead of being unpacked, the archive then
4844 gets wholly destroyed.  When users speak about @dfn{exploding} an
4845 archive, they usually mean something else :-).
4847 @item
4848 Forgetting the argument to @code{file}, when the intent was to create
4849 an archive with a single file in it.  This error is likely because a
4850 tired user can easily add the @kbd{f} key to the cluster of option
4851 letters, by the mere force of habit, without realizing the full
4852 consequence of doing so.  The usual consequence is that the single
4853 file, which was meant to be saved, is rather destroyed.
4854 @end enumerate
4856 So, recognizing the likelihood and the catastrophic nature of these
4857 errors, @GNUTAR{} now takes some distance from elegance, and
4858 cowardly refuses to create an archive when @option{--create} option is
4859 given, there are no arguments besides options, and
4860 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4861 around the cautiousness of @GNUTAR{} and nevertheless create an
4862 archive with nothing in it, one may still use, as the value for the
4863 @option{--files-from} option, a file with no names in it, as shown in
4864 the following commands:
4866 @smallexample
4867 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4868 @kbd{tar -cf empty-archive.tar -T /dev/null}
4869 @end smallexample
4871 @xopindex{extract, complementary notes}
4872 @item --extract
4873 @itemx --get
4874 @itemx -x
4876 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4878 @item @option{--list} (@option{-t})
4880 @GNUTAR{} now shows dates as @samp{1996-08-30},
4881 while it used to show them as @samp{Aug 30 1996}. Preferably,
4882 people should get used to ISO 8601 dates.  Local American dates should
4883 be made available again with full date localization support, once
4884 ready.  In the meantime, programs not being localizable for dates
4885 should prefer international dates, that's really the way to go.
4887 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4888 are curious, it contains a detailed explanation of the ISO 8601 standard.
4890 @end table
4892 @node Advanced tar
4893 @section Advanced @GNUTAR{} Operations
4895 Now that you have learned the basics of using @GNUTAR{}, you may want
4896 to learn about further ways in which @command{tar} can help you.
4898 This chapter presents five, more advanced operations which you probably
4899 won't use on a daily basis, but which serve more specialized functions.
4900 We also explain the different styles of options and why you might want
4901 to use one or another, or a combination of them in your @command{tar}
4902 commands.  Additionally, this chapter includes options which allow you to
4903 define the output from @command{tar} more carefully, and provide help and
4904 error correction in special circumstances.
4906 @FIXME{check this after the chapter is actually revised to make sure
4907 it still introduces the info in the chapter correctly : ).}
4909 @menu
4910 * Operations::
4911 * append::
4912 * update::
4913 * concatenate::
4914 * delete::
4915 * compare::
4916 @end menu
4918 @node Operations
4919 @subsection The Five Advanced @command{tar} Operations
4921 @cindex basic operations
4922 In the last chapter, you learned about the first three operations to
4923 @command{tar}.  This chapter presents the remaining five operations to
4924 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4925 @option{--delete}, and @option{--compare}.
4927 You are not likely to use these operations as frequently as those
4928 covered in the last chapter; however, since they perform specialized
4929 functions, they are quite useful when you do need to use them.  We
4930 will give examples using the same directory and files that you created
4931 in the last chapter.  As you may recall, the directory is called
4932 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4933 and the two archive files you created are
4934 @samp{collection.tar} and @samp{music.tar}.
4936 We will also use the archive files @samp{afiles.tar} and
4937 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
4938 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4939 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4941 Unless we state otherwise, all practicing you do and examples you follow
4942 in this chapter will take place in the @file{practice} directory that
4943 you created in the previous chapter; see @ref{prepare for examples}.
4944 (Below in this section, we will remind you of the state of the examples
4945 where the last chapter left them.)
4947 The five operations that we will cover in this chapter are:
4949 @table @option
4950 @item --append
4951 @itemx -r
4952 Add new entries to an archive that already exists.
4953 @item --update
4954 @itemx -u
4955 Add more recent copies of archive members to the end of an archive, if
4956 they exist.
4957 @item --concatenate
4958 @itemx --catenate
4959 @itemx -A
4960 Add one or more pre-existing archives to the end of another archive.
4961 @item --delete
4962 Delete items from an archive (does not work on tapes).
4963 @item --compare
4964 @itemx --diff
4965 @itemx -d
4966 Compare archive members to their counterparts in the file system.
4967 @end table
4969 @node append
4970 @subsection How to Add Files to Existing Archives: @option{--append}
4972 @cindex appending files to existing archive
4973 @opindex append
4974 If you want to add files to an existing archive, you don't need to
4975 create a new archive; you can use @option{--append} (@option{-r}).
4976 The archive must already exist in order to use @option{--append}.  (A
4977 related operation is the @option{--update} operation; you can use this
4978 to add newer versions of archive members to an existing archive.  To learn how to
4979 do this with @option{--update}, @pxref{update}.)
4981 If you use @option{--append} to add a file that has the same name as an
4982 archive member to an archive containing that archive member, then the
4983 old member is not deleted.  What does happen, however, is somewhat
4984 complex.  @command{tar} @emph{allows} you to have infinite number of files
4985 with the same name.  Some operations treat these same-named members no
4986 differently than any other set of archive members: for example, if you
4987 view an archive with @option{--list} (@option{-t}), you will see all
4988 of those members listed, with their data modification times, owners, etc.
4990 Other operations don't deal with these members as perfectly as you might
4991 prefer; if you were to use @option{--extract} to extract the archive,
4992 only the most recently added copy of a member with the same name as
4993 other members would end up in the working directory.  This is because
4994 @option{--extract} extracts an archive in the order the members appeared
4995 in the archive; the most recently archived members will be extracted
4996 last.  Additionally, an extracted member will @emph{replace} a file of
4997 the same name which existed in the directory already, and @command{tar}
4998 will not prompt you about this@footnote{Unless you give it
4999 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
5000 the disk copy is newer than the one in the archive and you invoke
5001 @command{tar} with @option{--keep-newer-files} option.}.  Thus, only
5002 the most recently archived member will end up being extracted, as it
5003 will replace the one extracted before it, and so on.
5005 @cindex extracting @var{n}th copy of the file
5006 @xopindex{occurrence, described}
5007 There exists a special option that allows you to get around this
5008 behavior and extract (or list) only a particular copy of the file.
5009 This is @option{--occurrence} option.  If you run @command{tar} with
5010 this option, it will extract only the first copy of the file.  You
5011 may also give this option an argument specifying the number of
5012 copy to be extracted.  Thus, for example if the archive
5013 @file{archive.tar} contained three copies of file @file{myfile}, then
5014 the command
5016 @smallexample
5017 tar --extract --file archive.tar --occurrence=2 myfile
5018 @end smallexample
5020 @noindent
5021 would extract only the second copy.  @xref{Option
5022 Summary,---occurrence}, for the description of @option{--occurrence}
5023 option.
5025 @FIXME{ hag -- you might want to incorporate some of the above into the
5026 MMwtSN node; not sure.  i didn't know how to make it simpler...
5028 There are a few ways to get around this.  Xref to Multiple Members
5029 with the Same Name, maybe.}
5031 @cindex Members, replacing with other members
5032 @cindex Replacing members with other members
5033 @xopindex{delete, using before --append}
5034 If you want to replace an archive member, use @option{--delete} to
5035 delete the member you want to remove from the archive, and then use
5036 @option{--append} to add the member you want to be in the archive.  Note
5037 that you can not change the order of the archive; the most recently
5038 added member will still appear last.  In this sense, you cannot truly
5039 ``replace'' one member with another.  (Replacing one member with another
5040 will not work on certain types of media, such as tapes; see @ref{delete}
5041 and @ref{Media}, for more information.)
5043 @menu
5044 * appending files::             Appending Files to an Archive
5045 * multiple::
5046 @end menu
5048 @node appending files
5049 @subsubsection Appending Files to an Archive
5050 @cindex Adding files to an Archive
5051 @cindex Appending files to an Archive
5052 @cindex Archives, Appending files to
5053 @opindex append
5055 The simplest way to add a file to an already existing archive is the
5056 @option{--append} (@option{-r}) operation, which writes specified
5057 files into the archive whether or not they are already among the
5058 archived files.
5060 When you use @option{--append}, you @emph{must} specify file name
5061 arguments, as there is no default.  If you specify a file that already
5062 exists in the archive, another copy of the file will be added to the
5063 end of the archive.  As with other operations, the member names of the
5064 newly added files will be exactly the same as their names given on the
5065 command line.  The @option{--verbose} (@option{-v}) option will print
5066 out the names of the files as they are written into the archive.
5068 @option{--append} cannot be performed on some tape drives, unfortunately,
5069 due to deficiencies in the formats those tape drives use.  The archive
5070 must be a valid @command{tar} archive, or else the results of using this
5071 operation will be unpredictable.  @xref{Media}.
5073 To demonstrate using @option{--append} to add a file to an archive,
5074 create a file called @file{rock} in the @file{practice} directory.
5075 Make sure you are in the @file{practice} directory.  Then, run the
5076 following @command{tar} command to add @file{rock} to
5077 @file{collection.tar}:
5079 @smallexample
5080 $ @kbd{tar --append --file=collection.tar rock}
5081 @end smallexample
5083 @noindent
5084 If you now use the @option{--list} (@option{-t}) operation, you will see that
5085 @file{rock} has been added to the archive:
5087 @smallexample
5088 $ @kbd{tar --list --file=collection.tar}
5089 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5090 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5091 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5092 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5093 @end smallexample
5095 @node multiple
5096 @subsubsection Multiple Members with the Same Name
5097 @cindex members, multiple
5098 @cindex multiple members
5100 You can use @option{--append} (@option{-r}) to add copies of files
5101 which have been updated since the archive was created.  (However, we
5102 do not recommend doing this since there is another @command{tar}
5103 option called @option{--update}; @xref{update}, for more information.
5104 We describe this use of @option{--append} here for the sake of
5105 completeness.)  When you extract the archive, the older version will
5106 be effectively lost.  This works because files are extracted from an
5107 archive in the order in which they were archived.  Thus, when the
5108 archive is extracted, a file archived later in time will replace a
5109 file of the same name which was archived earlier, even though the
5110 older version of the file will remain in the archive unless you delete
5111 all versions of the file.
5113 Supposing you change the file @file{blues} and then append the changed
5114 version to @file{collection.tar}.  As you saw above, the original
5115 @file{blues} is in the archive @file{collection.tar}.  If you change the
5116 file and append the new version of the file to the archive, there will
5117 be two copies in the archive.  When you extract the archive, the older
5118 version of the file will be extracted first, and then replaced by the
5119 newer version when it is extracted.
5121 You can append the new, changed copy of the file @file{blues} to the
5122 archive in this way:
5124 @smallexample
5125 $ @kbd{tar --append --verbose --file=collection.tar blues}
5126 blues
5127 @end smallexample
5129 @noindent
5130 Because you specified the @option{--verbose} option, @command{tar} has
5131 printed the name of the file being appended as it was acted on.  Now
5132 list the contents of the archive:
5134 @smallexample
5135 $ @kbd{tar --list --verbose --file=collection.tar}
5136 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5137 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5138 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5139 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5140 -rw-r--r-- me/user          58 1996-10-24 18:30 blues
5141 @end smallexample
5143 @noindent
5144 The newest version of @file{blues} is now at the end of the archive
5145 (note the different creation dates and file sizes).  If you extract
5146 the archive, the older version of the file @file{blues} will be
5147 replaced by the newer version.  You can confirm this by extracting
5148 the archive and running @samp{ls} on the directory.
5150 If you wish to extract the first occurrence of the file @file{blues}
5151 from the archive, use @option{--occurrence} option, as shown in
5152 the following example:
5154 @smallexample
5155 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
5156 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5157 @end smallexample
5159 @xref{Writing}, for more information on @option{--extract} and
5160 see @ref{Option Summary, --occurrence}, for a description of
5161 @option{--occurrence} option.
5163 @node update
5164 @subsection Updating an Archive
5165 @cindex Updating an archive
5166 @opindex update
5168 In the previous section, you learned how to use @option{--append} to
5169 add a file to an existing archive.  A related operation is
5170 @option{--update} (@option{-u}).  The @option{--update} operation
5171 updates a @command{tar} archive by comparing the date of the specified
5172 archive members against the date of the file with the same name.  If
5173 the file has been modified more recently than the archive member, then
5174 the newer version of the file is added to the archive (as with
5175 @option{--append}).
5177 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
5178 The operation will fail.
5180 @FIXME{other examples of media on which --update will fail?  need to ask
5181 charles and/or mib/thomas/dave shevett..}
5183 Both @option{--update} and @option{--append} work by adding to the end
5184 of the archive.  When you extract a file from the archive, only the
5185 version stored last will wind up in the file system, unless you use
5186 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
5188 @menu
5189 * how to update::
5190 @end menu
5192 @node how to update
5193 @subsubsection How to Update an Archive Using @option{--update}
5194 @opindex update
5196 You must use file name arguments with the @option{--update}
5197 (@option{-u}) operation.  If you don't specify any files,
5198 @command{tar} won't act on any files and won't tell you that it didn't
5199 do anything (which may end up confusing you).
5201 @c note: the above parenthetical added because in fact, this
5202 @c behavior just confused the author. :-)
5204 To see the @option{--update} option at work, create a new file,
5205 @file{classical}, in your practice directory, and some extra text to the
5206 file @file{blues}, using any text editor.  Then invoke @command{tar} with
5207 the @samp{update} operation and the @option{--verbose} (@option{-v})
5208 option specified, using the names of all the files in the @file{practice}
5209 directory as file name arguments:
5211 @smallexample
5212 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
5213 blues
5214 classical
5216 @end smallexample
5218 @noindent
5219 Because we have specified verbose mode, @command{tar} prints out the names
5220 of the files it is working on, which in this case are the names of the
5221 files that needed to be updated.  If you run @samp{tar --list} and look
5222 at the archive, you will see @file{blues} and @file{classical} at its
5223 end.  There will be a total of two versions of the member @samp{blues};
5224 the one at the end will be newer and larger, since you added text before
5225 updating it.
5227 The reason @command{tar} does not overwrite the older file when updating
5228 it is that writing to the middle of a section of tape is a difficult
5229 process.  Tapes are not designed to go backward.  @xref{Media}, for more
5230 information about tapes.
5232 @option{--update} (@option{-u}) is not suitable for performing backups for two
5233 reasons: it does not change directory content entries, and it
5234 lengthens the archive every time it is used.  The @GNUTAR{}
5235 options intended specifically for backups are more
5236 efficient.  If you need to run backups, please consult @ref{Backups}.
5238 @node concatenate
5239 @subsection Combining Archives with @option{--concatenate}
5241 @cindex Adding archives to an archive
5242 @cindex Concatenating Archives
5243 @opindex concatenate
5244 @opindex catenate
5245 @c @cindex @option{-A} described
5246 Sometimes it may be convenient to add a second archive onto the end of
5247 an archive rather than adding individual files to the archive.  To add
5248 one or more archives to the end of another archive, you should use the
5249 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
5251 To use @option{--concatenate}, give the first archive with
5252 @option{--file} option and name the rest of archives to be
5253 concatenated on the command line.  The members, and their member
5254 names, will be copied verbatim from those archives to the first
5255 one@footnote{This can cause multiple members to have the same name.  For
5256 information on how this affects reading the archive, see @ref{multiple}.}.
5257 The new, concatenated archive will be called by the same name as the
5258 one given with the @option{--file} option.  As usual, if you omit
5259 @option{--file}, @command{tar} will use the value of the environment
5260 variable @env{TAPE}, or, if this has not been set, the default archive name.
5262 @FIXME{There is no way to specify a new name...}
5264 To demonstrate how @option{--concatenate} works, create two small archives
5265 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
5266 files from @file{practice}:
5268 @smallexample
5269 $ @kbd{tar -cvf bluesrock.tar blues rock}
5270 blues
5271 rock
5272 $ @kbd{tar -cvf folkjazz.tar folk jazz}
5273 folk
5274 jazz
5275 @end smallexample
5277 @noindent
5278 If you like, You can run @samp{tar --list} to make sure the archives
5279 contain what they are supposed to:
5281 @smallexample
5282 $ @kbd{tar -tvf bluesrock.tar}
5283 -rw-r--r-- melissa/user    105 1997-01-21 19:42 blues
5284 -rw-r--r-- melissa/user     33 1997-01-20 15:34 rock
5285 $ @kbd{tar -tvf jazzfolk.tar}
5286 -rw-r--r-- melissa/user     20 1996-09-23 16:44 folk
5287 -rw-r--r-- melissa/user     65 1997-01-30 14:15 jazz
5288 @end smallexample
5290 We can concatenate these two archives with @command{tar}:
5292 @smallexample
5293 $ @kbd{cd ..}
5294 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
5295 @end smallexample
5297 If you now list the contents of the @file{bluesrock.tar}, you will see
5298 that now it also contains the archive members of @file{jazzfolk.tar}:
5300 @smallexample
5301 $ @kbd{tar --list --file=bluesrock.tar}
5302 blues
5303 rock
5304 folk
5305 jazz
5306 @end smallexample
5308 When you use @option{--concatenate}, the source and target archives must
5309 already exist and must have been created using compatible format
5310 parameters.  Notice, that @command{tar} does not check whether the
5311 archives it concatenates have compatible formats, it does not
5312 even check if the files are really tar archives.
5314 Like @option{--append} (@option{-r}), this operation cannot be performed on some
5315 tape drives, due to deficiencies in the formats those tape drives use.
5317 @cindex @code{concatenate} vs @command{cat}
5318 @cindex @command{cat} vs @code{concatenate}
5319 It may seem more intuitive to you to want or try to use @command{cat} to
5320 concatenate two archives instead of using the @option{--concatenate}
5321 operation; after all, @command{cat} is the utility for combining files.
5323 However, @command{tar} archives incorporate an end-of-file marker which
5324 must be removed if the concatenated archives are to be read properly as
5325 one archive.  @option{--concatenate} removes the end-of-archive marker
5326 from the target archive before each new archive is appended.  If you use
5327 @command{cat} to combine the archives, the result will not be a valid
5328 @command{tar} format archive.  If you need to retrieve files from an
5329 archive that was added to using the @command{cat} utility, use the
5330 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
5331 information on dealing with archives improperly combined using the
5332 @command{cat} shell utility.
5334 @node delete
5335 @subsection Removing Archive Members Using @option{--delete}
5336 @cindex Deleting files from an archive
5337 @cindex Removing files from an archive
5339 @opindex delete
5340 You can remove members from an archive by using the @option{--delete}
5341 option.  Specify the name of the archive with @option{--file}
5342 (@option{-f}) and then specify the names of the members to be deleted;
5343 if you list no member names, nothing will be deleted.  The
5344 @option{--verbose} option will cause @command{tar} to print the names
5345 of the members as they are deleted. As with @option{--extract}, you
5346 must give the exact member names when using @samp{tar --delete}.
5347 @option{--delete} will remove all versions of the named file from the
5348 archive.  The @option{--delete} operation can run very slowly.
5350 Unlike other operations, @option{--delete} has no short form.
5352 @cindex Tapes, using @option{--delete} and
5353 @cindex Deleting from tape archives
5354 This operation will rewrite the archive.  You can only use
5355 @option{--delete} on an archive if the archive device allows you to
5356 write to any point on the media, such as a disk; because of this, it
5357 does not work on magnetic tapes.  Do not try to delete an archive member
5358 from a magnetic tape; the action will not succeed, and you will be
5359 likely to scramble the archive and damage your tape.  There is no safe
5360 way (except by completely re-writing the archive) to delete files from
5361 most kinds of magnetic tape.  @xref{Media}.
5363 To delete all versions of the file @file{blues} from the archive
5364 @file{collection.tar} in the @file{practice} directory, make sure you
5365 are in that directory, and then,
5367 @smallexample
5368 $ @kbd{tar --list --file=collection.tar}
5369 blues
5370 folk
5371 jazz
5372 rock
5373 $ @kbd{tar --delete --file=collection.tar blues}
5374 $ @kbd{tar --list --file=collection.tar}
5375 folk
5376 jazz
5377 rock
5378 @end smallexample
5380 @FIXME{Check if the above listing is actually produced after running
5381 all the examples on collection.tar.}
5383 The @option{--delete} option has been reported to work properly when
5384 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
5386 @node compare
5387 @subsection Comparing Archive Members with the File System
5388 @cindex Verifying the currency of an archive
5390 @opindex compare
5391 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
5392 specified archive members against files with the same names, and then
5393 reports differences in file size, mode, owner, modification date and
5394 contents.  You should @emph{only} specify archive member names, not file
5395 names.  If you do not name any members, then @command{tar} will compare the
5396 entire archive.  If a file is represented in the archive but does not
5397 exist in the file system, @command{tar} reports a difference.
5399 You have to specify the record size of the archive when modifying an
5400 archive with a non-default record size.
5402 @command{tar} ignores files in the file system that do not have
5403 corresponding members in the archive.
5405 The following example compares the archive members @file{rock},
5406 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
5407 files of the same name in the file system.  (Note that there is no file,
5408 @file{funk}; @command{tar} will report an error message.)
5410 @smallexample
5411 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
5412 rock
5413 blues
5414 tar: funk not found in archive
5415 @end smallexample
5417 The spirit behind the @option{--compare} (@option{--diff},
5418 @option{-d}) option is to check whether the archive represents the
5419 current state of files on disk, more than validating the integrity of
5420 the archive media.  For this latter goal, see @ref{verify}.
5422 @node create options
5423 @section Options Used by @option{--create}
5425 @xopindex{create, additional options}
5426 The previous chapter described the basics of how to use
5427 @option{--create} (@option{-c}) to create an archive from a set of files.
5428 @xref{create}.  This section described advanced options to be used with
5429 @option{--create}.
5431 @menu
5432 * override::                  Overriding File Metadata.
5433 * Extended File Attributes::
5434 * Ignore Failed Read::
5435 @end menu
5437 @node override
5438 @subsection Overriding File Metadata
5440 As described above, a @command{tar} archive keeps, for each member it contains,
5441 its @dfn{metadata}, such as modification time, mode and ownership of
5442 the file.  @GNUTAR{} allows to replace these data with other values
5443 when adding files to the archive.  The options described in this
5444 section affect creation of archives of any type.  For POSIX archives,
5445 see also @ref{PAX keywords}, for additional ways of controlling
5446 metadata, stored in the archive.
5448 @table @option
5449 @opindex mode
5450 @item --mode=@var{permissions}
5452 When adding files to an archive, @command{tar} will use
5453 @var{permissions} for the archive members, rather than the permissions
5454 from the files.  @var{permissions} can be specified either as an octal
5455 number or as symbolic permissions, like with
5456 @command{chmod} (@xref{File permissions, Permissions, File
5457 permissions, fileutils, @acronym{GNU} file utilities}.  This reference
5458 also has useful information for those not being overly familiar with
5459 the UNIX permission system).  Using latter syntax allows for
5460 more flexibility.  For example, the value @samp{a+rw} adds read and write
5461 permissions for everybody, while retaining executable bits on directories
5462 or on any other file already marked as executable:
5464 @smallexample
5465 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5466 @end smallexample
5468 @item --mtime=@var{date}
5469 @opindex mtime
5471 When adding files to an archive, @command{tar} will use @var{date} as
5472 the modification time of members when creating archives, instead of
5473 their actual modification times.  The argument @var{date} can be
5474 either a textual date representation in almost arbitrary format
5475 (@pxref{Date input formats}) or a name of an existing file, starting
5476 with @samp{/} or @samp{.}.  In the latter case, the modification time
5477 of that file will be used.
5479 The following example will set the modification date to 00:00:00,
5480 January 1, 1970:
5482 @smallexample
5483 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
5484 @end smallexample
5486 @noindent
5487 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5488 will try to convert the specified date back to its textual
5489 representation and compare it with the one given with
5490 @option{--mtime} options.  If the two dates differ, @command{tar} will
5491 print a warning saying what date it will use.  This is to help user
5492 ensure he is using the right date.
5494 For example:
5496 @smallexample
5497 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5498 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5499 13:06:29.152478
5500 @dots{}
5501 @end smallexample
5503 @noindent
5504 When used with @option{--clamp-mtime} @GNUTAR{} will only set the
5505 modification date to @var{date} on files whose actual modification
5506 date is later than @var{date}.  This is to make it easy to build
5507 reproducible archives given a common timestamp for generated files
5508 while still retaining the original timestamps of untouched files.
5510 @smallexample
5511 $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime=@@$SOURCE_DATE_EPOCH .}
5512 @end smallexample
5514 @item --owner=@var{user}
5515 @opindex owner
5517 Specifies that @command{tar} should use @var{user} as the owner of members
5518 when creating archives, instead of the user associated with the source
5519 file.
5521 If @var{user} contains a colon, it is taken to be of the form
5522 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5523 name and a nonempty @var{id} specifies the decimal numeric user
5524 @acronym{ID}.  If @var{user} does not contain a colon, it is taken to
5525 be a user number if it is one or more decimal digits; otherwise it is
5526 taken to be a user name.
5528 If a name is given but no number, the number is inferred from the
5529 current host's user database if possible, and the file's user number
5530 is used otherwise.  If a number is given but no name, the name is
5531 inferred from the number if possible, and an empty name is used
5532 otherwise.  If both name and number are given, the user database is
5533 not consulted, and the name and number need not be valid on the
5534 current host.
5536 There is no value indicating a missing number, and @samp{0} usually means
5537 @code{root}.  Some people like to force @samp{0} as the value to offer in
5538 their distributions for the owner of files, because the @code{root} user is
5539 anonymous anyway, so that might as well be the owner of anonymous
5540 archives.  For example:
5542 @smallexample
5543 $ @kbd{tar -c -f archive.tar --owner=0 .}
5544 @end smallexample
5546 @noindent
5549 @smallexample
5550 $ @kbd{tar -c -f archive.tar --owner=root .}
5551 @end smallexample
5553 @item --group=@var{group}
5554 @opindex group
5556 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5557 rather than the group from the source file.  As with @option{--owner},
5558 the argument @var{group} can be an existing group symbolic name, or a
5559 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5560 @end table
5562 The @option{--owner} and @option{--group} options affect all files
5563 added to the archive.  @GNUTAR{} provides also two options that allow
5564 for more detailed control over owner translation:
5566 @table @option
5567 @item --owner-map=@var{file}
5568 Read UID translation map from @var{file}.
5570 When reading, empty lines are ignored.  The @samp{#} sign, unless
5571 quoted, introduces a comment, which extends to the end of the line.
5572 Each nonempty line defines mapping for a single UID.  It must consist
5573 of two fields separated by any amount of whitespace.  The first field
5574 defines original username and UID.  It can be a valid user name or
5575 a valid UID prefixed with a plus sign.  In both cases the
5576 corresponding UID or user name is inferred from the current host's
5577 user database.
5579 The second field defines the UID and username to map the original one
5580 to.  Its format can be the same as described above.  Otherwise, it can
5581 have the form @var{newname}:@var{newuid}, in which case neither
5582 @var{newname} nor @var{newuid} are required to be valid as per the
5583 user database.
5585 For example, consider the following file:
5587 @example
5588 +10     bin
5589 smith   root:0
5590 @end example
5592 @noindent
5593 Given this file, each input file that is owner by UID 10 will be
5594 stored in archive with owner name @samp{bin} and owner UID
5595 corresponding to @samp{bin}.  Each file owned by user @samp{smith}
5596 will be stored with owner name @samp{root} and owner ID 0.  Other
5597 files will remain unchanged.
5599 When used together with @option{--owner-map}, the @option{--owner}
5600 option affects only files whose owner is not listed in the map file.
5602 @item --group-map=@var{file}
5603 Read GID translation map from @var{file}.
5605 The format of @var{file} is the same as for @option{--owner-map}
5606 option:
5608 Each nonempty line defines mapping for a single GID.  It must consist
5609 of two fields separated by any amount of whitespace.  The first field
5610 defines original group name and GID.  It can be a valid group name or
5611 a valid GID prefixed with a plus sign.  In both cases the
5612 corresponding GID or user name is inferred from the current host's
5613 group database.
5615 The second field defines the GID and group name to map the original one
5616 to.  Its format can be the same as described above.  Otherwise, it can
5617 have the form @var{newname}:@var{newgid}, in which case neither
5618 @var{newname} nor @var{newgid} are required to be valid as per the
5619 group database.
5621 When used together with @option{--group-map}, the @option{--group}
5622 option affects only files whose owner group is not rewritten using the
5623 map file.
5624 @end table
5626 @node Extended File Attributes
5627 @subsection Extended File Attributes
5629 Extended file attributes are name-value pairs that can be
5630 associated with each node in a file system.  Despite the fact that
5631 POSIX.1e draft which proposed them has been withdrawn, the extended
5632 file attributes are supported by many file systems.  @GNUTAR{} can
5633 store extended file attributes along with the files.  This feature is
5634 controlled by the following command line arguments:
5636 @table @option
5637 @item --xattrs
5638 Enable extended attributes support.  When used with @option{--create},
5639 this option instructs @GNUTAR{} to store extended file attribute in the
5640 created archive.  This implies POSIX.1-2001 archive format
5641 (@option{--format=pax}).
5643 When used with @option{--extract}, this option tells @command{tar},
5644 for each file extracted, to read stored attributes from the archive
5645 and to apply them to the file.
5647 @item --no-xattrs
5648 Disable extended attributes support.  This is the default.
5649 @end table
5651 Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
5652 Currently, four namespaces exist: @samp{user}, @samp{trusted},
5653 @samp{security} and @samp{system}.  By default, when @option{--xattr}
5654 is used, all names are stored in the archive (or extracted, if using
5655 @option{--extract}).  This can be controlled using the following
5656 options:
5658 @table @option
5659 @item --xattrs-exclude=@var{pattern}
5660 Specify exclude pattern for extended attributes.
5662 @item --xattrs-include=@var{pattern}
5663 Specify include pattern for extended attributes.
5664 @end table
5666 Here, the @var{pattern} is a globbing pattern.  For example, the
5667 following command:
5669 @example
5670 $ @kbd{tar --xattrs --xattrs-exclude='user.*' -cf a.tar .}
5671 @end example
5673 will include in the archive @file{a.tar} all attributes, except those
5674 from the @samp{user} namespace.
5676 Any number of these options can be given, thereby creating lists of
5677 include and exclude patterns.
5679 When both options are used, first @option{--xattrs-include} is applied
5680 to select the set of attribute names to keep, and then
5681 @option{--xattrs-exclude} is applied to the resulting set.  In other
5682 words, only those attributes will be stored, whose names match one
5683 of the regexps in @option{--xattrs-include} and don't match any of
5684 the regexps from @option{--xattrs-exclude}.
5686 When listing the archive, if both @option{--xattrs} and
5687 @option{--verbose} options are given, files that have extended
5688 attributes are marked with an asterisk following their permission
5689 mask.  For example:
5691 @example
5692 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5693 @end example
5695 When two or more @option{--verbose} options are given, a detailed
5696 listing of extended attributes is printed after each file entry.  Each
5697 attribute is listed on a separate line, which begins with two spaces
5698 and the letter @samp{x} indicating extended attribute.  It is followed
5699 by a colon, length of the attribute and its name, e.g.:
5701 @example
5702 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5703   x:  7 user.mime_type
5704   x: 32 trusted.md5sum
5705 @end example
5707 File access control lists (@dfn{ACL}) are another actively used feature
5708 proposed by the POSIX.1e standard.  Each ACL consists of a set of ACL
5709 entries, each of which describes the access permissions on the file for
5710 an individual user or a group of users as a combination of read, write
5711 and search/execute permissions.
5713 Whether or not to use ACLs is controlled by the following two options:
5715 @table @option
5716 @item --acls
5717 Enable POSIX ACLs support.  When used with @option{--create},
5718 this option instructs @GNUTAR{} to store ACLs in the
5719 created archive.  This implies POSIX.1-2001 archive format
5720 (@option{--format=pax}).
5722 When used with @option{--extract}, this option tells @command{tar},
5723 to restore ACLs for each file extracted (provided they are present
5724 in the archive).
5726 @item --no-acls
5727 Disable POSIX ACLs support.  This is the default.
5728 @end table
5730 When listing the archive, if both @option{--acls} and
5731 @option{--verbose} options are given, files that have ACLs are marked
5732 with a plus sign following their permission mask.  For example:
5734 @example
5735 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5736 @end example
5738 When two or more @option{--verbose} options are given, a detailed
5739 listing of ACL is printed after each file entry:
5741 @example
5742 @group
5743 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5744   a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
5745 @end group
5746 @end example
5748 @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
5749 kernel security module that provides a mechanism for supporting access
5750 control security policies, including so-called mandatory access
5751 controls (@dfn{MAC}).  Support for SELinux attributes is controlled by
5752 the following command line options:
5754 @table @option
5755 @item --selinux
5756 Enable the SELinux context support.
5758 @item --no-selinux
5759 Disable SELinux context support.
5760 @end table
5762 @node Ignore Failed Read
5763 @subsection Ignore Failed Read
5765 @table @option
5766 @item --ignore-failed-read
5767 @opindex ignore-failed-read
5768 Do not exit with nonzero if there are mild problems while reading.
5769 @end table
5771 This option has effect only during creation.  It instructs tar to
5772 treat as mild conditions any missing or unreadable files (directories),
5773 or files that change while reading.
5774 Such failures don't affect the program exit code, and the
5775 corresponding diagnostic messages are marked as warnings, not errors.
5776 These warnings can be suppressed using the
5777 @option{--warning=failed-read} option (@pxref{warnings}).
5779 @node extract options
5780 @section Options Used by @option{--extract}
5781 @cindex options for use with @option{--extract}
5783 @xopindex{extract, additional options}
5784 The previous chapter showed how to use @option{--extract} to extract
5785 an archive into the file system.  Various options cause @command{tar} to
5786 extract more information than just file contents, such as the owner,
5787 the permissions, the modification date, and so forth.  This section
5788 presents options to be used with @option{--extract} when certain special
5789 considerations arise.  You may review the information presented in
5790 @ref{extract} for more basic information about the
5791 @option{--extract} operation.
5793 @menu
5794 * Reading::                     Options to Help Read Archives
5795 * Writing::                     Changing How @command{tar} Writes Files
5796 * Scarce::                      Coping with Scarce Resources
5797 @end menu
5799 @node Reading
5800 @subsection Options to Help Read Archives
5801 @cindex Options when reading archives
5803 @cindex Reading incomplete records
5804 @cindex Records, incomplete
5805 @opindex read-full-records
5806 Normally, @command{tar} will request data in full record increments from
5807 an archive storage device.  If the device cannot return a full record,
5808 @command{tar} will report an error.  However, some devices do not always
5809 return full records, or do not require the last record of an archive to
5810 be padded out to the next record boundary.  To keep reading until you
5811 obtain a full record, or to accept an incomplete record if it contains
5812 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5813 in conjunction with the @option{--extract} or @option{--list} operations.
5814 @xref{Blocking}.
5816 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5817 @command{tar} reads an archive from standard input, or from a remote
5818 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5819 pipe returns however much happens to be in the pipe, even if it is
5820 less than was requested.  If this option were not enabled, @command{tar}
5821 would fail as soon as it read an incomplete record from the pipe.
5823 If you're not sure of the blocking factor of an archive, you can
5824 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5825 @option{--blocking-factor=@var{512-size}} (@option{-b
5826 @var{512-size}}), using a blocking factor larger than what the archive
5827 uses.  This lets you avoid having to determine the blocking factor
5828 of an archive.  @xref{Blocking Factor}.
5830 @menu
5831 * read full records::
5832 * Ignore Zeros::
5833 @end menu
5835 @node read full records
5836 @unnumberedsubsubsec Reading Full Records
5838 @FIXME{need sentence or so of intro here}
5840 @table @option
5841 @opindex read-full-records
5842 @item --read-full-records
5843 @item -B
5844 Use in conjunction with @option{--extract} (@option{--get},
5845 @option{-x}) to read an archive which contains incomplete records, or
5846 one which has a blocking factor less than the one specified.
5847 @end table
5849 @node Ignore Zeros
5850 @unnumberedsubsubsec Ignoring Blocks of Zeros
5852 @cindex End-of-archive blocks, ignoring
5853 @cindex Ignoring end-of-archive blocks
5854 @opindex ignore-zeros
5855 Normally, @command{tar} stops reading when it encounters a block of zeros
5856 between file entries (which usually indicates the end of the archive).
5857 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5858 completely read an archive which contains a block of zeros before the
5859 end (i.e., a damaged archive, or one that was created by concatenating
5860 several archives together).
5862 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5863 versions of @command{tar} write garbage after the end-of-archive entry,
5864 since that part of the media is never supposed to be read.  @GNUTAR{}
5865 does not write after the end of an archive, but seeks to
5866 maintain compatibility among archiving utilities.
5868 @table @option
5869 @item --ignore-zeros
5870 @itemx -i
5871 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5872 encountered while reading an archive.  Use in conjunction with
5873 @option{--extract} or @option{--list}.
5874 @end table
5876 @node Writing
5877 @subsection Changing How @command{tar} Writes Files
5878 @UNREVISED{}
5880 @FIXME{Introductory paragraph}
5882 @menu
5883 * Dealing with Old Files::
5884 * Overwrite Old Files::
5885 * Keep Old Files::
5886 * Keep Newer Files::
5887 * Unlink First::
5888 * Recursive Unlink::
5889 * Data Modification Times::
5890 * Setting Access Permissions::
5891 * Directory Modification Times and Permissions::
5892 * Writing to Standard Output::
5893 * Writing to an External Program::
5894 * remove files::
5895 @end menu
5897 @node Dealing with Old Files
5898 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5900 @xopindex{overwrite-dir, introduced}
5901 When extracting files, if @command{tar} discovers that the extracted
5902 file already exists, it normally replaces the file by removing it before
5903 extracting it, to prevent confusion in the presence of hard or symbolic
5904 links.  (If the existing file is a symbolic link, it is removed, not
5905 followed.)  However, if a directory cannot be removed because it is
5906 nonempty, @command{tar} normally overwrites its metadata (ownership,
5907 permission, etc.).  The @option{--overwrite-dir} option enables this
5908 default behavior.  To be more cautious and preserve the metadata of
5909 such a directory, use the @option{--no-overwrite-dir} option.
5911 @cindex Overwriting old files, prevention
5912 @xopindex{keep-old-files, introduced}
5913 To be even more cautious and prevent existing files from being replaced, use
5914 the @option{--keep-old-files} (@option{-k}) option.  It causes
5915 @command{tar} to refuse to replace or update a file that already
5916 exists, i.e., a file with the same name as an archive member prevents
5917 extraction of that archive member.  Instead, it reports an error.  For
5918 example:
5920 @example
5921 $ @kbd{ls}
5922 blues
5923 $ @kbd{tar -x -k -f archive.tar}
5924 tar: blues: Cannot open: File exists
5925 tar: Exiting with failure status due to previous errors
5926 @end example
5928 @xopindex{skip-old-files, introduced}
5929 If you wish to preserve old files untouched, but don't want
5930 @command{tar} to treat them as errors, use the
5931 @option{--skip-old-files} option.  This option causes @command{tar} to
5932 silently skip extracting over existing files.
5934 @xopindex{overwrite, introduced}
5935 To be more aggressive about altering existing files, use the
5936 @option{--overwrite} option.  It causes @command{tar} to overwrite
5937 existing files and to follow existing symbolic links when extracting.
5939 @cindex Protecting old files
5940 Some people argue that @GNUTAR{} should not hesitate
5941 to overwrite files with other files when extracting.  When extracting
5942 a @command{tar} archive, they expect to see a faithful copy of the
5943 state of the file system when the archive was created.  It is debatable
5944 that this would always be a proper behavior.  For example, suppose one
5945 has an archive in which @file{usr/local} is a link to
5946 @file{usr/local2}.  Since then, maybe the site removed the link and
5947 renamed the whole hierarchy from @file{/usr/local2} to
5948 @file{/usr/local}.  Such things happen all the time.  I guess it would
5949 not be welcome at all that @GNUTAR{} removes the
5950 whole hierarchy just to make room for the link to be reinstated
5951 (unless it @emph{also} simultaneously restores the full
5952 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
5953 able to remove a whole hierarchy to reestablish a symbolic link, for
5954 example, but @emph{only if} @option{--recursive-unlink} is specified
5955 to allow this behavior.  In any case, single files are silently
5956 removed.
5958 @xopindex{unlink-first, introduced}
5959 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5960 some cases by causing @command{tar} to remove files unconditionally
5961 before extracting them.
5963 @node Overwrite Old Files
5964 @unnumberedsubsubsec Overwrite Old Files
5966 @table @option
5967 @opindex overwrite
5968 @item --overwrite
5969 Overwrite existing files and directory metadata when extracting files
5970 from an archive.
5972 This causes @command{tar} to write extracted files into the file system without
5973 regard to the files already on the system; i.e., files with the same
5974 names as archive members are overwritten when the archive is extracted.
5975 It also causes @command{tar} to extract the ownership, permissions,
5976 and time stamps onto any preexisting files or directories.
5977 If the name of a corresponding file name is a symbolic link, the file
5978 pointed to by the symbolic link will be overwritten instead of the
5979 symbolic link itself (if this is possible).  Moreover, special devices,
5980 empty directories and even symbolic links are automatically removed if
5981 they are in the way of extraction.
5983 Be careful when using the @option{--overwrite} option, particularly when
5984 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5985 can change the contents, ownership or permissions of any file on your
5986 system.  Also, many systems do not take kindly to overwriting files that
5987 are currently being executed.
5989 @opindex overwrite-dir
5990 @item --overwrite-dir
5991 Overwrite the metadata of directories when extracting files from an
5992 archive, but remove other files before extracting.
5993 @end table
5995 @node Keep Old Files
5996 @unnumberedsubsubsec Keep Old Files
5998 @GNUTAR{} provides two options to control its actions in a situation
5999 when it is about to extract a file which already exists on disk.
6001 @table @option
6002 @opindex keep-old-files
6003 @item --keep-old-files
6004 @itemx -k
6005 Do not replace existing files from archive.  When such a file is
6006 encountered, @command{tar} issues an error message.  Upon end of
6007 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
6009 @item --skip-old-files
6010 Do not replace existing files from archive, but do not treat that
6011 as error.  Such files are silently skipped and do not affect
6012 @command{tar} exit status.
6014 Additional verbosity can be obtained using @option{--warning=existing-file}
6015 together with that option (@pxref{warnings}).
6016 @end table
6018 @node Keep Newer Files
6019 @unnumberedsubsubsec Keep Newer Files
6021 @table @option
6022 @opindex keep-newer-files
6023 @item --keep-newer-files
6024 Do not replace existing files that are newer than their archive
6025 copies.  This option is meaningless with @option{--list} (@option{-t}).
6026 @end table
6028 @node Unlink First
6029 @unnumberedsubsubsec Unlink First
6031 @table @option
6032 @opindex unlink-first
6033 @item --unlink-first
6034 @itemx -U
6035 Remove files before extracting over them.
6036 This can make @command{tar} run a bit faster if you know in advance
6037 that the extracted files all need to be removed.  Normally this option
6038 slows @command{tar} down slightly, so it is disabled by default.
6039 @end table
6041 @node Recursive Unlink
6042 @unnumberedsubsubsec Recursive Unlink
6044 @table @option
6045 @opindex recursive-unlink
6046 @item --recursive-unlink
6047 When this option is specified, try removing files and directory hierarchies
6048 before extracting over them.  @emph{This is a dangerous option!}
6049 @end table
6051 If you specify the @option{--recursive-unlink} option,
6052 @command{tar} removes @emph{anything} that keeps you from extracting a file
6053 as far as current permissions will allow it.  This could include removal
6054 of the contents of a full directory hierarchy.
6056 @node Data Modification Times
6057 @unnumberedsubsubsec Setting Data Modification Times
6059 @cindex Data modification times of extracted files
6060 @cindex Modification times of extracted files
6061 Normally, @command{tar} sets the data modification times of extracted
6062 files to the corresponding times recorded for the files in the archive, but
6063 limits the permissions of extracted files by the current @code{umask}
6064 setting.
6066 To set the data modification times of extracted files to the time when
6067 the files were extracted, use the @option{--touch} (@option{-m}) option in
6068 conjunction with @option{--extract} (@option{--get}, @option{-x}).
6070 @table @option
6071 @opindex touch
6072 @item --touch
6073 @itemx -m
6074 Sets the data modification time of extracted archive members to the time
6075 they were extracted, not the time recorded for them in the archive.
6076 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
6077 @end table
6079 @node Setting Access Permissions
6080 @unnumberedsubsubsec Setting Access Permissions
6082 @cindex Permissions of extracted files
6083 @cindex Modes of extracted files
6084 To set the modes (access permissions) of extracted files to those
6085 recorded for those files in the archive, use @option{--same-permissions}
6086 in conjunction with the @option{--extract} (@option{--get},
6087 @option{-x}) operation.
6089 @table @option
6090 @opindex preserve-permissions
6091 @opindex same-permissions
6092 @item --preserve-permissions
6093 @itemx --same-permissions
6094 @c @itemx --ignore-umask
6095 @itemx -p
6096 Set modes of extracted archive members to those recorded in the
6097 archive, instead of current umask settings.  Use in conjunction with
6098 @option{--extract} (@option{--get}, @option{-x}).
6099 @end table
6101 @node Directory Modification Times and Permissions
6102 @unnumberedsubsubsec Directory Modification Times and Permissions
6104 After successfully extracting a file member, @GNUTAR{} normally
6105 restores its permissions and modification times, as described in the
6106 previous sections.  This cannot be done for directories, because
6107 after extracting a directory @command{tar} will almost certainly
6108 extract files into that directory and this will cause the directory
6109 modification time to be updated.  Moreover, restoring that directory
6110 permissions may not permit file creation within it.  Thus, restoring
6111 directory permissions and modification times must be delayed at least
6112 until all files have been extracted into that directory.  @GNUTAR{}
6113 restores directories using the following approach.
6115 The extracted directories are created with the mode specified in the
6116 archive, as modified by the umask of the user, which gives sufficient
6117 permissions to allow file creation.  The meta-information about the
6118 directory is recorded in the temporary list of directories.  When
6119 preparing to extract next archive member, @GNUTAR{} checks if the
6120 directory prefix of this file contains the remembered directory.  If
6121 it does not, the program assumes that all files have been extracted
6122 into that directory, restores its modification time and permissions
6123 and removes its entry from the internal list.  This approach allows
6124 to correctly restore directory meta-information in the majority of
6125 cases, while keeping memory requirements sufficiently small.  It is
6126 based on the fact, that most @command{tar} archives use the predefined
6127 order of members: first the directory, then all the files and
6128 subdirectories in that directory.
6130 However, this is not always true.  The most important exception are
6131 incremental archives (@pxref{Incremental Dumps}).  The member order in
6132 an incremental archive is reversed: first all directory members are
6133 stored, followed by other (non-directory) members.  So, when extracting
6134 from incremental archives, @GNUTAR{} alters the above procedure.  It
6135 remembers all restored directories, and restores their meta-data
6136 only after the entire archive has been processed.  Notice, that you do
6137 not need to specify any special options for that, as @GNUTAR{}
6138 automatically detects archives in incremental format.
6140 There may be cases, when such processing is required for normal archives
6141 too.  Consider the following example:
6143 @smallexample
6144 @group
6145 $ @kbd{tar --no-recursion -cvf archive \
6146     foo foo/file1 bar bar/file foo/file2}
6147 foo/
6148 foo/file1
6149 bar/
6150 bar/file
6151 foo/file2
6152 @end group
6153 @end smallexample
6155 During the normal operation, after encountering @file{bar}
6156 @GNUTAR{} will assume that all files from the directory @file{foo}
6157 were already extracted and will therefore restore its timestamp and
6158 permission bits.  However, after extracting @file{foo/file2} the
6159 directory timestamp will be offset again.
6161 To correctly restore directory meta-information in such cases, use
6162 the @option{--delay-directory-restore} command line option:
6164 @table @option
6165 @opindex delay-directory-restore
6166 @item --delay-directory-restore
6167 Delays restoring of the modification times and permissions of extracted
6168 directories until the end of extraction.  This way, correct
6169 meta-information is restored even if the archive has unusual member
6170 ordering.
6172 @opindex no-delay-directory-restore
6173 @item --no-delay-directory-restore
6174 Cancel the effect of the previous @option{--delay-directory-restore}.
6175 Use this option if you have used @option{--delay-directory-restore} in
6176 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
6177 temporarily disable it.
6178 @end table
6180 @node Writing to Standard Output
6181 @unnumberedsubsubsec Writing to Standard Output
6183 @cindex Writing extracted files to standard output
6184 @cindex Standard output, writing extracted files to
6185 To write the extracted files to the standard output, instead of
6186 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
6187 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
6188 extracting files to send them through a pipe, and do not need to
6189 preserve them in the file system.  If you extract multiple members,
6190 they appear on standard output concatenated, in the order they are
6191 found in the archive.
6193 @table @option
6194 @opindex to-stdout
6195 @item --to-stdout
6196 @itemx -O
6197 Writes files to the standard output.  Use only in conjunction with
6198 @option{--extract} (@option{--get}, @option{-x}).  When this option is
6199 used, instead of creating the files specified, @command{tar} writes
6200 the contents of the files extracted to its standard output.  This may
6201 be useful if you are only extracting the files in order to send them
6202 through a pipe.  This option is meaningless with @option{--list}
6203 (@option{-t}).
6204 @end table
6206 This can be useful, for example, if you have a tar archive containing
6207 a big file and don't want to store the file on disk before processing
6208 it.  You can use a command like this:
6210 @smallexample
6211 tar -xOzf foo.tgz bigfile | process
6212 @end smallexample
6214 or even like this if you want to process the concatenation of the files:
6216 @smallexample
6217 tar -xOzf foo.tgz bigfile1 bigfile2 | process
6218 @end smallexample
6220 However, @option{--to-command} may be more convenient for use with
6221 multiple files. See the next section.
6223 @node Writing to an External Program
6224 @unnumberedsubsubsec Writing to an External Program
6226 You can instruct @command{tar} to send the contents of each extracted
6227 file to the standard input of an external program:
6229 @table @option
6230 @opindex to-command
6231 @item --to-command=@var{command}
6232 Extract files and pipe their contents to the standard input of
6233 @var{command}.  When this option is used, instead of creating the
6234 files specified, @command{tar} invokes @var{command} and pipes the
6235 contents of the files to its standard output.  The @var{command} may
6236 contain command line arguments (see @ref{external, Running External Commands},
6237 for more detail).
6239 Notice, that @var{command} is executed once for each regular file
6240 extracted.  Non-regular files (directories, etc.)@: are ignored when this
6241 option is used.
6242 @end table
6244 The command can obtain the information about the file it processes
6245 from the following environment variables:
6247 @table @env
6248 @vrindex TAR_FILETYPE, to-command environment
6249 @item TAR_FILETYPE
6250 Type of the file. It is a single letter with the following meaning:
6252 @multitable @columnfractions 0.10 0.90
6253 @item f @tab Regular file
6254 @item d @tab Directory
6255 @item l @tab Symbolic link
6256 @item h @tab Hard link
6257 @item b @tab Block device
6258 @item c @tab Character device
6259 @end multitable
6261 Currently only regular files are supported.
6263 @vrindex TAR_MODE, to-command environment
6264 @item TAR_MODE
6265 File mode, an octal number.
6267 @vrindex TAR_FILENAME, to-command environment
6268 @item TAR_FILENAME
6269 The name of the file.
6271 @vrindex TAR_REALNAME, to-command environment
6272 @item TAR_REALNAME
6273 Name of the file as stored in the archive.
6275 @vrindex TAR_UNAME, to-command environment
6276 @item TAR_UNAME
6277 Name of the file owner.
6279 @vrindex TAR_GNAME, to-command environment
6280 @item TAR_GNAME
6281 Name of the file owner group.
6283 @vrindex TAR_ATIME, to-command environment
6284 @item TAR_ATIME
6285 Time of last access. It is a decimal number, representing seconds
6286 since the Epoch.  If the archive provides times with nanosecond
6287 precision, the nanoseconds are appended to the timestamp after a
6288 decimal point.
6290 @vrindex TAR_MTIME, to-command environment
6291 @item TAR_MTIME
6292 Time of last modification.
6294 @vrindex TAR_CTIME, to-command environment
6295 @item TAR_CTIME
6296 Time of last status change.
6298 @vrindex TAR_SIZE, to-command environment
6299 @item TAR_SIZE
6300 Size of the file.
6302 @vrindex TAR_UID, to-command environment
6303 @item TAR_UID
6304 UID of the file owner.
6306 @vrindex TAR_GID, to-command environment
6307 @item TAR_GID
6308 GID of the file owner.
6309 @end table
6311 Additionally, the following variables contain information about
6312 tar mode and the archive being processed:
6314 @table @env
6315 @vrindex TAR_VERSION, to-command environment
6316 @item TAR_VERSION
6317 @GNUTAR{} version number.
6319 @vrindex TAR_ARCHIVE, to-command environment
6320 @item TAR_ARCHIVE
6321 The name of the archive @command{tar} is processing.
6323 @vrindex TAR_BLOCKING_FACTOR, to-command environment
6324 @item TAR_BLOCKING_FACTOR
6325 Current blocking factor (@pxref{Blocking}).
6327 @vrindex TAR_VOLUME, to-command environment
6328 @item TAR_VOLUME
6329 Ordinal number of the volume @command{tar} is processing.
6331 @vrindex TAR_FORMAT, to-command environment
6332 @item TAR_FORMAT
6333 Format of the archive being processed. @xref{Formats}, for a complete
6334 list of archive format names.
6335 @end table
6337 These variables are defined prior to executing the command, so you can
6338 pass them as arguments, if you prefer.  For example, if the command
6339 @var{proc} takes the member name and size as its arguments, then you
6340 could do:
6342 @smallexample
6343 $ @kbd{tar -x -f archive.tar \
6344        --to-command='proc $TAR_FILENAME $TAR_SIZE'}
6345 @end smallexample
6347 @noindent
6348 Notice single quotes to prevent variable names from being expanded by
6349 the shell when invoking @command{tar}.
6351 If @var{command} exits with a non-0 status, @command{tar} will print
6352 an error message similar to the following:
6354 @smallexample
6355 tar: 2345: Child returned status 1
6356 @end smallexample
6358 Here, @samp{2345} is the PID of the finished process.
6360 If this behavior is not wanted, use @option{--ignore-command-error}:
6362 @table @option
6363 @opindex ignore-command-error
6364 @item --ignore-command-error
6365 Ignore exit codes of subprocesses.  Notice that if the program
6366 exits on signal or otherwise terminates abnormally, the error message
6367 will be printed even if this option is used.
6369 @opindex no-ignore-command-error
6370 @item --no-ignore-command-error
6371 Cancel the effect of any previous @option{--ignore-command-error}
6372 option. This option is useful if you have set
6373 @option{--ignore-command-error} in @env{TAR_OPTIONS}
6374 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
6375 @end table
6377 @node remove files
6378 @unnumberedsubsubsec Removing Files
6380 @FIXME{The section is too terse. Something more to add? An example,
6381 maybe?}
6383 @table @option
6384 @opindex remove-files
6385 @item --remove-files
6386 Remove files after adding them to the archive.
6387 @end table
6389 @node Scarce
6390 @subsection Coping with Scarce Resources
6391 @UNREVISED{}
6393 @cindex Small memory
6394 @cindex Running out of space
6396 @menu
6397 * Starting File::
6398 * Same Order::
6399 @end menu
6401 @node Starting File
6402 @unnumberedsubsubsec Starting File
6404 @table @option
6405 @opindex starting-file
6406 @item --starting-file=@var{name}
6407 @itemx -K @var{name}
6408 Starts an operation in the middle of an archive.  Use in conjunction
6409 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
6410 @end table
6412 @cindex Middle of the archive, starting in the
6413 If a previous attempt to extract files failed due to lack of disk
6414 space, you can use @option{--starting-file=@var{name}} (@option{-K
6415 @var{name}}) to start extracting only after member @var{name} of the
6416 archive.  This assumes, of course, that there is now free space, or
6417 that you are now extracting into a different file system.  (You could
6418 also choose to suspend @command{tar}, remove unnecessary files from
6419 the file system, and then resume the same @command{tar} operation.
6420 In this case, @option{--starting-file} is not necessary.)  See also
6421 @ref{interactive}, and @ref{exclude}.
6423 @node Same Order
6424 @unnumberedsubsubsec Same Order
6426 @table @option
6427 @cindex Large lists of file names on small machines
6428 @opindex same-order
6429 @opindex preserve-order
6430 @item --same-order
6431 @itemx --preserve-order
6432 @itemx -s
6433 To process large lists of file names on machines with small amounts of
6434 memory.  Use in conjunction with @option{--compare} (@option{--diff},
6435 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
6436 (@option{--get}, @option{-x}).
6437 @end table
6439 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
6440 names to be listed or extracted is sorted in the same order as the
6441 files in the archive.  This allows a large list of names to be used,
6442 even on a small machine that would not otherwise be able to hold all
6443 the names in memory at the same time.  Such a sorted list can easily be
6444 created by running @samp{tar -t} on the archive and editing its output.
6446 This option is probably never needed on modern computer systems.
6448 @node backup
6449 @section Backup options
6451 @cindex backup options
6453 @GNUTAR{} offers options for making backups of files
6454 before writing new versions.  These options control the details of
6455 these backups.  They may apply to the archive itself before it is
6456 created or rewritten, as well as individual extracted members.  Other
6457 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
6458 and @command{mv}, for example) offer similar options.
6460 Backup options may prove unexpectedly useful when extracting archives
6461 containing many members having identical name, or when extracting archives
6462 on systems having file name limitations, making different members appear
6463 as having similar names through the side-effect of name truncation.
6464 @FIXME{This is true only if we have a good scheme for truncated backup names,
6465 which I'm not sure at all: I suspect work is needed in this area.}
6466 When any existing file is backed up before being overwritten by extraction,
6467 then clashing files are automatically be renamed to be unique, and the
6468 true name is kept for only the last file of a series of clashing files.
6469 By using verbose mode, users may track exactly what happens.
6471 At the detail level, some decisions are still experimental, and may
6472 change in the future, we are waiting comments from our users.  So, please
6473 do not learn to depend blindly on the details of the backup features.
6474 For example, currently, directories themselves are never renamed through
6475 using these options, so, extracting a file over a directory still has
6476 good chances to fail.  Also, backup options apply to created archives,
6477 not only to extracted members.  For created archives, backups will not
6478 be attempted when the archive is a block or character device, or when it
6479 refers to a remote file.
6481 For the sake of simplicity and efficiency, backups are made by renaming old
6482 files prior to creation or extraction, and not by copying.  The original
6483 name is restored if the file creation fails.  If a failure occurs after a
6484 partial extraction of a file, both the backup and the partially extracted
6485 file are kept.
6487 @table @samp
6488 @item --backup[=@var{method}]
6489 @opindex backup
6490 @vindex VERSION_CONTROL
6491 @cindex backups
6492 Back up files that are about to be overwritten or removed.
6493 Without this option, the original versions are destroyed.
6495 Use @var{method} to determine the type of backups made.
6496 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
6497 environment variable.  And if @env{VERSION_CONTROL} is not set,
6498 use the @samp{existing} method.
6500 @vindex version-control @r{Emacs variable}
6501 This option corresponds to the Emacs variable @samp{version-control};
6502 the same values for @var{method} are accepted as in Emacs.  This option
6503 also allows more descriptive names.  The valid @var{method}s are:
6505 @table @samp
6506 @item t
6507 @itemx numbered
6508 @cindex numbered @r{backup method}
6509 Always make numbered backups.
6511 @item nil
6512 @itemx existing
6513 @cindex existing @r{backup method}
6514 Make numbered backups of files that already have them, simple backups
6515 of the others.
6517 @item never
6518 @itemx simple
6519 @cindex simple @r{backup method}
6520 Always make simple backups.
6522 @end table
6524 @item --suffix=@var{suffix}
6525 @opindex suffix
6526 @cindex backup suffix
6527 @vindex SIMPLE_BACKUP_SUFFIX
6528 Append @var{suffix} to each backup file made with @option{--backup}.  If this
6529 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
6530 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
6531 set, the default is @samp{~}, just as in Emacs.
6533 @end table
6535 @node looking ahead
6536 @section Looking Ahead: The Rest of this Manual
6538 You have now seen how to use all eight of the operations available to
6539 @command{tar}, and a number of the possible options.  The next chapter
6540 explains how to choose and change file and archive names, how to use
6541 files to store names of other files which you can then call as
6542 arguments to @command{tar} (this can help you save time if you expect to
6543 archive the same list of files a number of times), and so forth.
6544 @FIXME{in case it's not obvious, i'm making this up in some sense
6545 based on my limited memory of what the next chapter *really* does.  i
6546 just wanted to flesh out this final section a little bit so i'd
6547 remember to stick it in here. :-)}
6549 If there are too many files to conveniently list on the command line,
6550 you can list the names in a file, and @command{tar} will read that file.
6551 @xref{files}.
6553 There are various ways of causing @command{tar} to skip over some files,
6554 and not archive them.  @xref{Choosing}.
6556 @node Backups
6557 @chapter Performing Backups and Restoring Files
6558 @cindex backups
6560 @GNUTAR{} is distributed along with the scripts for performing backups
6561 and restores.  Even if there is a good chance those scripts may be
6562 satisfying to you, they are not the only scripts or methods available for doing
6563 backups and restore.  You may well create your own, or use more
6564 sophisticated packages dedicated to that purpose.
6566 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
6567 Automatic Network Disk Archiver), a backup system developed by James
6568 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
6569 This is free software, and it is available from @uref{http://www.amanda.org}.
6571 @FIXME{
6573 Here is a possible plan for a future documentation about the backuping
6574 scripts which are provided within the @GNUTAR{}
6575 distribution.
6577 @itemize @bullet
6578 @item dumps
6579  @itemize @minus
6580  @item what are dumps
6581  @item different levels of dumps
6582   @itemize +
6583   @item full dump = dump everything
6584   @item level 1, level 2 dumps etc
6585         A level @var{n} dump dumps everything changed since the last level
6586         @var{n}-1 dump (?)
6587   @end itemize
6588  @item how to use scripts for dumps  (ie, the concept)
6589   @itemize +
6590   @item scripts to run after editing backup specs (details)
6591   @end itemize
6592  @item Backup Specs, what is it.
6593   @itemize +
6594   @item how to customize
6595   @item actual text of script  [/sp/dump/backup-specs]
6596   @end itemize
6597  @item Problems
6598   @itemize +
6599    @item rsh doesn't work
6600    @item rtape isn't installed
6601    @item (others?)
6602   @end itemize
6603  @item the @option{--incremental} option of tar
6604  @item tapes
6605   @itemize +
6606   @item write protection
6607   @item types of media, different sizes and types, useful for different things
6608   @item files and tape marks
6609      one tape mark between files, two at end.
6610   @item positioning the tape
6611      MT writes two at end of write,
6612      backspaces over one when writing again.
6613   @end itemize
6614  @end itemize
6615 @end itemize
6618 This chapter documents both the provided shell scripts and @command{tar}
6619 options which are more specific to usage as a backup tool.
6621 To @dfn{back up} a file system means to create archives that contain
6622 all the files in that file system.  Those archives can then be used to
6623 restore any or all of those files (for instance if a disk crashes or a
6624 file is accidentally deleted).  File system @dfn{backups} are also
6625 called @dfn{dumps}.
6627 @menu
6628 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
6629 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
6630 * Backup Levels::               Levels of Backups
6631 * Backup Parameters::           Setting Parameters for Backups and Restoration
6632 * Scripted Backups::            Using the Backup Scripts
6633 * Scripted Restoration::        Using the Restore Script
6634 @end menu
6636 @node Full Dumps
6637 @section Using @command{tar} to Perform Full Dumps
6638 @UNREVISED{}
6640 @cindex full dumps
6641 @cindex dumps, full
6643 @cindex corrupted archives
6644 Full dumps should only be made when no other people or programs
6645 are modifying files in the file system.  If files are modified while
6646 @command{tar} is making the backup, they may not be stored properly in
6647 the archive, in which case you won't be able to restore them if you
6648 have to.  (Files not being modified are written with no trouble, and do
6649 not corrupt the entire archive.)
6651 You will want to use the @option{--label=@var{archive-label}}
6652 (@option{-V @var{archive-label}}) option to give the archive a
6653 volume label, so you can tell what this archive is even if the label
6654 falls off the tape, or anything like that.
6656 Unless the file system you are dumping is guaranteed to fit on
6657 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6658 Make sure you have enough tapes on hand to complete the backup.
6660 If you want to dump each file system separately you will need to use
6661 the @option{--one-file-system} option to prevent
6662 @command{tar} from crossing file system boundaries when storing
6663 (sub)directories.
6665 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6666 option is not needed, since this is a complete copy of everything in
6667 the file system, and a full restore from this backup would only be
6668 done onto a completely
6669 empty disk.
6671 Unless you are in a hurry, and trust the @command{tar} program (and your
6672 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6673 option, to make sure your files really made it onto the dump properly.
6674 This will also detect cases where the file was modified while (or just
6675 after) it was being archived.  Not all media (notably cartridge tapes)
6676 are capable of being verified, unfortunately.
6678 @node Incremental Dumps
6679 @section Using @command{tar} to Perform Incremental Dumps
6681 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6682 stores additional metadata so that exact state of the file system
6683 can be restored when extracting the archive.
6685 @GNUTAR{} currently offers two options for handling incremental
6686 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6687 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6689 @xopindex{listed-incremental, described}
6690 The option @option{--listed-incremental} instructs tar to operate on
6691 an incremental archive with additional metadata stored in a standalone
6692 file, called a @dfn{snapshot file}.  The purpose of this file is to help
6693 determine which files have been changed, added or deleted since the
6694 last backup, so that the next incremental backup will contain only
6695 modified files.  The name of the snapshot file is given as an argument
6696 to the option:
6698 @table @option
6699 @item --listed-incremental=@var{file}
6700 @itemx -g @var{file}
6701   Handle incremental backups with snapshot data in @var{file}.
6702 @end table
6704 To create an incremental backup, you would use
6705 @option{--listed-incremental} together with @option{--create}
6706 (@pxref{create}).  For example:
6708 @smallexample
6709 $ @kbd{tar --create \
6710            --file=archive.1.tar \
6711            --listed-incremental=/var/log/usr.snar \
6712            /usr}
6713 @end smallexample
6715 This will create in @file{archive.1.tar} an incremental backup of
6716 the @file{/usr} file system, storing additional metadata in the file
6717 @file{/var/log/usr.snar}.  If this file does not exist, it will be
6718 created.  The created archive will then be a @dfn{level 0 backup};
6719 please see the next section for more on backup levels.
6721 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6722 determines which files are modified.  In this case only these files will be
6723 stored in the archive.  Suppose, for example, that after running the
6724 above command, you delete file @file{/usr/doc/old} and create
6725 directory @file{/usr/local/db} with the following contents:
6727 @smallexample
6728 $ @kbd{ls /usr/local/db}
6729 /usr/local/db/data
6730 /usr/local/db/index
6731 @end smallexample
6733 Some time later you create another incremental backup.  You will
6734 then see:
6736 @smallexample
6737 $ @kbd{tar --create \
6738            --file=archive.2.tar \
6739            --listed-incremental=/var/log/usr.snar \
6740            /usr}
6741 tar: usr/local/db: Directory is new
6742 usr/local/db/
6743 usr/local/db/data
6744 usr/local/db/index
6745 @end smallexample
6747 @noindent
6748 The created archive @file{archive.2.tar} will contain only these
6749 three members.  This archive is called a @dfn{level 1 backup}.  Notice
6750 that @file{/var/log/usr.snar} will be updated with the new data, so if
6751 you plan to create more @samp{level 1} backups, it is necessary to
6752 create a working copy of the snapshot file before running
6753 @command{tar}.  The above example will then be modified as follows:
6755 @smallexample
6756 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6757 $ @kbd{tar --create \
6758            --file=archive.2.tar \
6759            --listed-incremental=/var/log/usr.snar-1 \
6760            /usr}
6761 @end smallexample
6763 @anchor{--level=0}
6764 @xopindex{level, described}
6765 You can force @samp{level 0} backups either by removing the snapshot
6766 file before running @command{tar}, or by supplying the
6767 @option{--level=0} option, e.g.:
6769 @smallexample
6770 $ @kbd{tar --create \
6771            --file=archive.2.tar \
6772            --listed-incremental=/var/log/usr.snar-0 \
6773            --level=0 \
6774            /usr}
6775 @end smallexample
6777 Incremental dumps depend crucially on time stamps, so the results are
6778 unreliable if you modify a file's time stamps during dumping (e.g.,
6779 with the @option{--atime-preserve=replace} option), or if you set the clock
6780 backwards.
6782 @anchor{device numbers}
6783 @cindex Device numbers, using in incremental backups
6784 Metadata stored in snapshot files include device numbers, which,
6785 obviously are supposed to be non-volatile values.  However, it turns
6786 out that @acronym{NFS} devices have undependable values when an automounter
6787 gets in the picture.  This can lead to a great deal of spurious
6788 redumping in incremental dumps, so it is somewhat useless to compare
6789 two @acronym{NFS} devices numbers over time.  The solution implemented
6790 currently is to consider all @acronym{NFS} devices as being equal
6791 when it comes to comparing directories; this is fairly gross, but
6792 there does not seem to be a better way to go.
6794 Apart from using @acronym{NFS}, there are a number of cases where
6795 relying on device numbers can cause spurious redumping of unmodified
6796 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6797 volumes.  To avoid this, use @option{--no-check-device} option:
6799 @table @option
6800 @xopindex{no-check-device, described}
6801 @item --no-check-device
6802 Do not rely on device numbers when preparing a list of changed files
6803 for an incremental dump.
6805 @xopindex{check-device, described}
6806 @item --check-device
6807 Use device numbers when preparing a list of changed files
6808 for an incremental dump.  This is the default behavior.  The purpose
6809 of this option is to undo the effect of the @option{--no-check-device}
6810 if it was given in @env{TAR_OPTIONS} environment variable
6811 (@pxref{TAR_OPTIONS}).
6812 @end table
6814 There is also another way to cope with changing device numbers.  It is
6815 described in detail in @ref{Fixing Snapshot Files}.
6817 Note that incremental archives use @command{tar} extensions and may
6818 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6820 @xopindex{listed-incremental, using with @option{--extract}}
6821 @xopindex{extract, using with @option{--listed-incremental}}
6822 To extract from the incremental dumps, use
6823 @option{--listed-incremental} together with @option{--extract}
6824 option (@pxref{extracting files}).  In this case, @command{tar} does
6825 not need to access snapshot file, since all the data necessary for
6826 extraction are stored in the archive itself.  So, when extracting, you
6827 can give whatever argument to @option{--listed-incremental}, the usual
6828 practice is to use @option{--listed-incremental=/dev/null}.
6829 Alternatively, you can use @option{--incremental}, which needs no
6830 arguments.  In general, @option{--incremental} (@option{-G}) can be
6831 used as a shortcut for @option{--listed-incremental} when listing or
6832 extracting incremental backups (for more information regarding this
6833 option, @pxref{incremental-op}).
6835 When extracting from the incremental backup @GNUTAR{} attempts to
6836 restore the exact state the file system had when the archive was
6837 created.  In particular, it will @emph{delete} those files in the file
6838 system that did not exist in their directories when the archive was
6839 created.  If you have created several levels of incremental files,
6840 then in order to restore the exact contents the file system  had when
6841 the last level was created, you will need to restore from all backups
6842 in turn.  Continuing our example, to restore the state of @file{/usr}
6843 file system, one would do@footnote{Notice, that since both archives
6844 were created without @option{-P} option (@pxref{absolute}), these
6845 commands should be run from the root file system.}:
6847 @smallexample
6848 $ @kbd{tar --extract \
6849            --listed-incremental=/dev/null \
6850            --file archive.1.tar}
6851 $ @kbd{tar --extract \
6852            --listed-incremental=/dev/null \
6853            --file archive.2.tar}
6854 @end smallexample
6856 To list the contents of an incremental archive, use @option{--list}
6857 (@pxref{list}), as usual.  To obtain more information about the
6858 archive, use @option{--listed-incremental} or @option{--incremental}
6859 combined with two @option{--verbose} options@footnote{Two
6860 @option{--verbose} options were selected to avoid breaking usual
6861 verbose listing output (@option{--list --verbose}) when using in
6862 scripts.
6864 @xopindex{incremental, using with @option{--list}}
6865 @xopindex{listed-incremental, using with @option{--list}}
6866 @xopindex{list, using with @option{--incremental}}
6867 @xopindex{list, using with @option{--listed-incremental}}
6868 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6869 contents of the DUMPDIR header (with terminating nulls) when
6870 @option{--incremental} or @option{--listed-incremental} option was
6871 given, no matter what the verbosity level.  This behavior, and,
6872 especially, the binary output it produced were considered inconvenient
6873 and were changed in version 1.16.}:
6875 @smallexample
6876 @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
6877 @end smallexample
6879 This command will print, for each directory in the archive, the list
6880 of files in that directory at the time the archive was created.  This
6881 information is put out in a format which is both human-readable and
6882 unambiguous for a program: each file name is printed as
6884 @smallexample
6885 @var{x} @var{file}
6886 @end smallexample
6888 @noindent
6889 where @var{x} is a letter describing the status of the file: @samp{Y}
6890 if the file  is present in the archive, @samp{N} if the file is not
6891 included in the archive, or a @samp{D} if the file is a directory (and
6892 is included in the archive).  @xref{Dumpdir}, for the detailed
6893 description of dumpdirs and status codes.  Each such
6894 line is terminated by a newline character.  The last line is followed
6895 by an additional newline to indicate the end of the data.
6897 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6898 gives the same behavior as @option{--listed-incremental} when used
6899 with @option{--list} and @option{--extract} options.  When used with
6900 @option{--create} option, it creates an incremental archive without
6901 creating snapshot file.  Thus, it is impossible to create several
6902 levels of incremental backups with @option{--incremental} option.
6904 @node Backup Levels
6905 @section Levels of Backups
6907 An archive containing all the files in the file system is called a
6908 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
6909 creating a full dump every day.  This strategy, however, would waste a
6910 substantial amount of archive media and user time, as unchanged files
6911 are daily re-archived.
6913 It is more efficient to do a full dump only occasionally.  To back up
6914 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
6915 one} dump archives all the files that have changed since the last full
6916 dump.
6918 A typical dump strategy would be to perform a full dump once a week,
6919 and a level one dump once a day.  This means some versions of files
6920 will in fact be archived more than once, but this dump strategy makes
6921 it possible to restore a file system to within one day of accuracy by
6922 only extracting two archives---the last weekly (full) dump and the
6923 last daily (level one) dump.  The only information lost would be in
6924 files changed or created since the last daily backup.  (Doing dumps
6925 more than once a day is usually not worth the trouble.)
6927 @GNUTAR{} comes with scripts you can use to do full
6928 and level-one (actually, even level-two and so on) dumps.  Using
6929 scripts (shell programs) to perform backups and restoration is a
6930 convenient and reliable alternative to typing out file name lists
6931 and @command{tar} commands by hand.
6933 Before you use these scripts, you need to edit the file
6934 @file{backup-specs}, which specifies parameters used by the backup
6935 scripts and by the restore script.  This file is usually located
6936 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
6937 detailed description.  Once the backup parameters are set, you can
6938 perform backups or restoration by running the appropriate script.
6940 The name of the backup script is @code{backup}.  The name of the
6941 restore script is @code{restore}.  The following sections describe
6942 their use in detail.
6944 @emph{Please Note:} The backup and restoration scripts are
6945 designed to be used together.  While it is possible to restore files by
6946 hand from an archive which was created using a backup script, and to create
6947 an archive by hand which could then be extracted using the restore script,
6948 it is easier to use the scripts.  @xref{Incremental Dumps}, before
6949 making such an attempt.
6951 @node Backup Parameters
6952 @section Setting Parameters for Backups and Restoration
6954 The file @file{backup-specs} specifies backup parameters for the
6955 backup and restoration scripts provided with @command{tar}.  You must
6956 edit @file{backup-specs} to fit your system configuration and schedule
6957 before using these scripts.
6959 Syntactically, @file{backup-specs} is a shell script, containing
6960 mainly variable assignments.  However, any valid shell construct
6961 is allowed in this file.  Particularly, you may wish to define
6962 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6963 For more information about shell script syntax, please refer to
6964 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6965 g_02, the definition of the Shell Command Language}.  See also
6966 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6968 The shell variables controlling behavior of @code{backup} and
6969 @code{restore} are described in the following subsections.
6971 @menu
6972 * General-Purpose Variables::
6973 * Magnetic Tape Control::
6974 * User Hooks::
6975 * backup-specs example::        An Example Text of @file{Backup-specs}
6976 @end menu
6978 @node General-Purpose Variables
6979 @subsection General-Purpose Variables
6981 @defvr {Backup variable} ADMINISTRATOR
6982 The user name of the backup administrator.  @code{Backup} scripts
6983 sends a backup report to this address.
6984 @end defvr
6986 @defvr {Backup variable} BACKUP_HOUR
6987 The hour at which the backups are done.  This can be a number from 0
6988 to 23, or the time specification in form @var{hours}:@var{minutes},
6989 or the string @samp{now}.
6991 This variable is used by @code{backup}.  Its value may be overridden
6992 using @option{--time} option (@pxref{Scripted Backups}).
6993 @end defvr
6995 @defvr {Backup variable} TAPE_FILE
6997 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
6998 is a remote archive (@pxref{remote-dev}), backup script will suppose
6999 that your @command{mt} is able to access remote devices.  If @var{RSH}
7000 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
7001 invocations of @command{mt}.
7002 @end defvr
7004 @defvr {Backup variable} BLOCKING
7006 The blocking factor @command{tar} will use when writing the dump archive.
7007 @xref{Blocking Factor}.
7008 @end defvr
7010 @defvr {Backup variable} BACKUP_DIRS
7012 A list of file systems to be dumped (for @code{backup}), or restored
7013 (for @code{restore}).  You can include any directory
7014 name in the list --- subdirectories on that file system will be
7015 included, regardless of how they may look to other networked machines.
7016 Subdirectories on other file systems will be ignored.
7018 The host name specifies which host to run @command{tar} on, and should
7019 normally be the host that actually contains the file system.  However,
7020 the host machine must have @GNUTAR{} installed, and
7021 must be able to access the directory containing the backup scripts and
7022 their support files using the same file name that is used on the
7023 machine where the scripts are run (i.e., what @command{pwd} will print
7024 when in that directory on that machine).  If the host that contains
7025 the file system does not have this capability, you can specify another
7026 host as long as it can access the file system through @acronym{NFS}.
7028 If the list of file systems is very long you may wish to put it
7029 in a separate file.  This file is usually named
7030 @file{/etc/backup/dirs}, but this name may be overridden in
7031 @file{backup-specs} using @code{DIRLIST} variable.
7032 @end defvr
7034 @defvr {Backup variable} DIRLIST
7036 The name of the file that contains a list of file systems to backup
7037 or restore.  By default it is @file{/etc/backup/dirs}.
7038 @end defvr
7040 @defvr {Backup variable} BACKUP_FILES
7042 A list of individual files to be dumped (for @code{backup}), or restored
7043 (for @code{restore}).  These should be accessible from the machine on
7044 which the backup script is run.
7046 If the list of individual files is very long you may wish to store it
7047 in a separate file.  This file is usually named
7048 @file{/etc/backup/files}, but this name may be overridden in
7049 @file{backup-specs} using @code{FILELIST} variable.
7050 @end defvr
7052 @defvr {Backup variable} FILELIST
7054 The name of the file that contains a list of individual files to backup
7055 or restore.  By default it is @file{/etc/backup/files}.
7056 @end defvr
7058 @defvr {Backup variable} MT
7060 Full file name of @command{mt} binary.
7061 @end defvr
7063 @defvr {Backup variable} RSH
7064 @anchor{RSH}
7065 Full file name of @command{rsh} binary or its equivalent.  You may wish to
7066 set it to @code{ssh}, to improve security.  In this case you will have
7067 to use public key authentication.
7068 @end defvr
7070 @defvr {Backup variable} RSH_COMMAND
7072 Full file name of @command{rsh} binary on remote machines.  This will
7073 be passed via @option{--rsh-command} option to the remote invocation
7074 of @GNUTAR{}.
7075 @end defvr
7077 @defvr {Backup variable} VOLNO_FILE
7079 Name of temporary file to hold volume numbers.  This needs to be accessible
7080 by all the machines which have file systems to be dumped.
7081 @end defvr
7083 @defvr {Backup variable} XLIST
7085 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
7086 located on the remote machine and containing the list of files to
7087 be excluded from the backup.  Exclude file lists are searched in
7088 /etc/tar-backup directory.  A common use for exclude file lists
7089 is to exclude files containing security-sensitive information
7090 (e.g., @file{/etc/shadow} from backups).
7092 This variable affects only @code{backup}.
7093 @end defvr
7095 @defvr {Backup variable} SLEEP_TIME
7097 Time to sleep between dumps of any two successive file systems
7099 This variable affects only @code{backup}.
7100 @end defvr
7102 @defvr {Backup variable} DUMP_REMIND_SCRIPT
7104 Script to be run when it's time to insert a new tape in for the next
7105 volume.  Administrators may want to tailor this script for their site.
7106 If this variable isn't set, @GNUTAR{} will display its built-in
7107 prompt, and will expect confirmation from the console.  For the
7108 description of the default prompt, see @ref{change volume prompt}.
7110 @end defvr
7112 @defvr {Backup variable} SLEEP_MESSAGE
7114 Message to display on the terminal while waiting for dump time.  Usually
7115 this will just be some literal text.
7116 @end defvr
7118 @defvr {Backup variable} TAR
7120 Full file name of the @GNUTAR{} executable.  If this is not set, backup
7121 scripts will search @command{tar} in the current shell path.
7122 @end defvr
7124 @node Magnetic Tape Control
7125 @subsection Magnetic Tape Control
7127 Backup scripts access tape device using special @dfn{hook functions}.
7128 These functions take a single argument --- the name of the tape
7129 device.  Their names are kept in the following variables:
7131 @defvr {Backup variable} MT_BEGIN
7132 The name of @dfn{begin} function.  This function is called before
7133 accessing the drive.  By default it retensions the tape:
7135 @smallexample
7136 MT_BEGIN=mt_begin
7138 mt_begin() @{
7139     mt -f "$1" retension
7141 @end smallexample
7142 @end defvr
7144 @defvr {Backup variable} MT_REWIND
7145 The name of @dfn{rewind} function.  The default definition is as
7146 follows:
7148 @smallexample
7149 MT_REWIND=mt_rewind
7151 mt_rewind() @{
7152     mt -f "$1" rewind
7154 @end smallexample
7156 @end defvr
7158 @defvr {Backup variable} MT_OFFLINE
7159 The name of the function switching the tape off line.  By default
7160 it is defined as follows:
7162 @smallexample
7163 MT_OFFLINE=mt_offline
7165 mt_offline() @{
7166     mt -f "$1" offl
7168 @end smallexample
7169 @end defvr
7171 @defvr {Backup variable} MT_STATUS
7172 The name of the function used to obtain the status of the archive device,
7173 including error count.  Default definition:
7175 @smallexample
7176 MT_STATUS=mt_status
7178 mt_status() @{
7179     mt -f "$1" status
7181 @end smallexample
7182 @end defvr
7184 @node User Hooks
7185 @subsection User Hooks
7187 @dfn{User hooks} are shell functions executed before and after
7188 each @command{tar} invocation.  Thus, there are @dfn{backup
7189 hooks}, which are executed before and after dumping each file
7190 system, and @dfn{restore hooks}, executed before and
7191 after restoring a file system.  Each user hook is a shell function
7192 taking four arguments:
7194 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
7195 Its arguments are:
7197 @table @var
7198 @item level
7199 Current backup or restore level.
7201 @item host
7202 Name or IP address of the host machine being dumped or restored.
7204 @item fs
7205 Full file name of the file system being dumped or restored.
7207 @item fsname
7208 File system name with directory separators replaced with colons.  This
7209 is useful, e.g., for creating unique files.
7210 @end table
7211 @end deffn
7213 Following variables keep the names of user hook functions:
7215 @defvr {Backup variable} DUMP_BEGIN
7216 Dump begin function.  It is executed before dumping the file system.
7217 @end defvr
7219 @defvr {Backup variable} DUMP_END
7220 Executed after dumping the file system.
7221 @end defvr
7223 @defvr {Backup variable} RESTORE_BEGIN
7224 Executed before restoring the file system.
7225 @end defvr
7227 @defvr {Backup variable} RESTORE_END
7228 Executed after restoring the file system.
7229 @end defvr
7231 @node backup-specs example
7232 @subsection An Example Text of @file{Backup-specs}
7234 The following is an example of @file{backup-specs}:
7236 @smallexample
7237 # site-specific parameters for file system backup.
7239 ADMINISTRATOR=friedman
7240 BACKUP_HOUR=1
7241 TAPE_FILE=/dev/nrsmt0
7243 # Use @code{ssh} instead of the less secure @code{rsh}
7244 RSH=/usr/bin/ssh
7245 RSH_COMMAND=/usr/bin/ssh
7247 # Override MT_STATUS function:
7248 my_status() @{
7249       mts -t $TAPE_FILE
7251 MT_STATUS=my_status
7253 # Disable MT_OFFLINE function
7254 MT_OFFLINE=:
7256 BLOCKING=124
7257 BACKUP_DIRS="
7258         albert:/fs/fsf
7259         apple-gunkies:/gd
7260         albert:/fs/gd2
7261         albert:/fs/gp
7262         geech:/usr/jla
7263         churchy:/usr/roland
7264         albert:/
7265         albert:/usr
7266         apple-gunkies:/
7267         apple-gunkies:/usr
7268         gnu:/hack
7269         gnu:/u
7270         apple-gunkies:/com/mailer/gnu
7271         apple-gunkies:/com/archive/gnu"
7273 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
7275 @end smallexample
7277 @node Scripted Backups
7278 @section Using the Backup Scripts
7280 The syntax for running a backup script is:
7282 @smallexample
7283 backup --level=@var{level} --time=@var{time}
7284 @end smallexample
7286 The @option{--level} option requests the dump level.  Thus, to produce
7287 a full dump, specify @code{--level=0} (this is the default, so
7288 @option{--level} may be omitted if its value is
7289 @code{0})@footnote{For backward compatibility, the @code{backup} will also
7290 try to deduce the requested dump level from the name of the
7291 script itself.  If the name consists of a string @samp{level-}
7292 followed by a single decimal digit, that digit is taken as
7293 the dump level number.  Thus, you may create a link from @code{backup}
7294 to @code{level-1} and then run @code{level-1} whenever you need to
7295 create a level one dump.}.
7297 The @option{--time} option determines when should the backup be
7298 run.  @var{Time} may take three forms:
7300 @table @asis
7301 @item @var{hh}:@var{mm}
7303 The dump must be run at @var{hh} hours @var{mm} minutes.
7305 @item @var{hh}
7307 The dump must be run at @var{hh} hours.
7309 @item now
7311 The dump must be run immediately.
7312 @end table
7314 You should start a script with a tape or disk mounted.  Once you
7315 start a script, it prompts you for new tapes or disks as it
7316 needs them.  Media volumes don't have to correspond to archive
7317 files --- a multi-volume archive can be started in the middle of a
7318 tape that already contains the end of another multi-volume archive.
7319 The @code{restore} script prompts for media by its archive volume,
7320 so to avoid an error message you should keep track of which tape
7321 (or disk) contains which volume of the archive (@pxref{Scripted
7322 Restoration}).
7324 The backup scripts write two files on the file system.  The first is a
7325 record file in @file{/etc/tar-backup/}, which is used by the scripts
7326 to store and retrieve information about which files were dumped.  This
7327 file is not meant to be read by humans, and should not be deleted by
7328 them.  @xref{Snapshot Files}, for a more detailed explanation of this
7329 file.
7331 The second file is a log file containing the names of the file systems
7332 and files dumped, what time the backup was made, and any error
7333 messages that were generated, as well as how much space was left in
7334 the media volume after the last volume of the archive was written.
7335 You should check this log file after every backup.  The file name is
7336 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
7337 represents current date, and @var{n} represents current dump level number.
7339 The script also prints the name of each system being dumped to the
7340 standard output.
7342 Following is the full list of options accepted by @code{backup}
7343 script:
7345 @table @option
7346 @item -l @var{level}
7347 @itemx --level=@var{level}
7348 Do backup level @var{level} (default 0).
7350 @item -f
7351 @itemx --force
7352 Force backup even if today's log file already exists.
7354 @item -v[@var{level}]
7355 @itemx --verbose[=@var{level}]
7356 Set verbosity level.  The higher the level is, the more debugging
7357 information will be output during execution.  Default @var{level}
7358 is 100, which means the highest debugging level.
7360 @item -t @var{start-time}
7361 @itemx --time=@var{start-time}
7362 Wait till @var{time}, then do backup.
7364 @item -h
7365 @itemx --help
7366 Display short help message and exit.
7368 @item -V
7369 @itemx --version
7370 Display information about the program's name, version, origin and legal
7371 status, all on standard output, and then exit successfully.
7372 @end table
7375 @node Scripted Restoration
7376 @section Using the Restore Script
7378 To restore files that were archived using a scripted backup, use the
7379 @code{restore} script.  Its usage is quite straightforward.  In the
7380 simplest form, invoke @code{restore --all}, it will
7381 then restore all the file systems and files specified in
7382 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
7384 You may select the file systems (and/or files) to restore by
7385 giving @code{restore} a list of @dfn{patterns} in its command
7386 line.  For example, running
7388 @smallexample
7389 restore 'albert:*'
7390 @end smallexample
7392 @noindent
7393 will restore all file systems on the machine @samp{albert}.  A more
7394 complicated example:
7396 @smallexample
7397 restore 'albert:*' '*:/var'
7398 @end smallexample
7400 @noindent
7401 This command will restore all file systems on the machine @samp{albert}
7402 as well as @file{/var} file system on all machines.
7404 By default @code{restore} will start restoring files from the lowest
7405 available dump level (usually zero) and will continue through
7406 all available dump levels.  There may be situations where such a
7407 thorough restore is not necessary.  For example, you may wish to
7408 restore only files from the recent level one backup.  To do so,
7409 use @option{--level} option, as shown in the example below:
7411 @smallexample
7412 restore --level=1
7413 @end smallexample
7415 The full list of options accepted by @code{restore} follows:
7417 @table @option
7418 @item -a
7419 @itemx --all
7420 Restore all file systems and files specified in @file{backup-specs}.
7422 @item -l @var{level}
7423 @itemx --level=@var{level}
7424 Start restoring from the given backup level, instead of the default 0.
7426 @item -v[@var{level}]
7427 @itemx --verbose[=@var{level}]
7428 Set verbosity level.  The higher the level is, the more debugging
7429 information will be output during execution.  Default @var{level}
7430 is 100, which means the highest debugging level.
7432 @item -h
7433 @itemx --help
7434 Display short help message and exit.
7436 @item -V
7437 @itemx --version
7438 Display information about the program's name, version, origin and legal
7439 status, all on standard output, and then exit successfully.
7440 @end table
7442 You should start the restore script with the media containing the
7443 first volume of the archive mounted.  The script will prompt for other
7444 volumes as they are needed.  If the archive is on tape, you don't need
7445 to rewind the tape to to its beginning---if the tape head is
7446 positioned past the beginning of the archive, the script will rewind
7447 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
7448 positioning.
7450 @quotation
7451 @strong{Warning:} The script will delete files from the active file
7452 system if they were not in the file system when the archive was made.
7453 @end quotation
7455 @xref{Incremental Dumps}, for an explanation of how the script makes
7456 that determination.
7458 @node Choosing
7459 @chapter Choosing Files and Names for @command{tar}
7461 Certain options to @command{tar} enable you to specify a name for your
7462 archive.  Other options let you decide which files to include or exclude
7463 from the archive, based on when or whether files were modified, whether
7464 the file names do or don't match specified patterns, or whether files
7465 are in specified directories.
7467 This chapter discusses these options in detail.
7469 @menu
7470 * file::                        Choosing the Archive's Name
7471 * Selecting Archive Members::
7472 * files::                       Reading Names from a File
7473 * exclude::                     Excluding Some Files
7474 * wildcards::                   Wildcards Patterns and Matching
7475 * quoting styles::              Ways of Quoting Special Characters in Names
7476 * transform::                   Modifying File and Member Names
7477 * after::                       Operating Only on New Files
7478 * recurse::                     Descending into Directories
7479 * one::                         Crossing File System Boundaries
7480 @end menu
7482 @node file
7483 @section Choosing and Naming Archive Files
7485 @cindex Naming an archive
7486 @cindex Archive Name
7487 @cindex Choosing an archive file
7488 @cindex Where is the archive?
7489 @opindex file
7490 By default, @command{tar} uses an archive file name that was compiled when
7491 it was built on the system; usually this name refers to some physical
7492 tape drive on the machine.  However, the person who installed @command{tar}
7493 on the system may not have set the default to a meaningful value as far as
7494 most users are concerned.  As a result, you will usually want to tell
7495 @command{tar} where to find (or create) the archive.  The
7496 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
7497 option allows you to either specify or name a file to use as the archive
7498 instead of the default archive file location.
7500 @table @option
7501 @xopindex{file, short description}
7502 @item --file=@var{archive-name}
7503 @itemx -f @var{archive-name}
7504 Name the archive to create or operate on.  Use in conjunction with
7505 any operation.
7506 @end table
7508 For example, in this @command{tar} command,
7510 @smallexample
7511 $ @kbd{tar -cvf collection.tar blues folk jazz}
7512 @end smallexample
7514 @noindent
7515 @file{collection.tar} is the name of the archive.  It must directly
7516 follow the @option{-f} option, since whatever directly follows @option{-f}
7517 @emph{will} end up naming the archive.  If you neglect to specify an
7518 archive name, you may end up overwriting a file in the working directory
7519 with the archive you create since @command{tar} will use this file's name
7520 for the archive name.
7522 An archive can be saved as a file in the file system, sent through a
7523 pipe or over a network, or written to an I/O device such as a tape,
7524 floppy disk, or CD write drive.
7526 @cindex Writing new archives
7527 @cindex Archive creation
7528 If you do not name the archive, @command{tar} uses the value of the
7529 environment variable @env{TAPE} as the file name for the archive.  If
7530 that is not available, @command{tar} uses a default, compiled-in archive
7531 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
7533 @cindex Standard input and output
7534 @cindex tar to standard input and output
7535 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
7536 archive from standard input (when listing or extracting files), or
7537 writes it to standard output (when creating an archive).  If you use
7538 @file{-} as an @var{archive-name} when modifying an archive,
7539 @command{tar} reads the original archive from its standard input and
7540 writes the entire new archive to its standard output.
7542 The following example is a convenient way of copying directory
7543 hierarchy from @file{sourcedir} to @file{targetdir}.
7545 @smallexample
7546 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
7547 @end smallexample
7549 The @option{-C} option allows to avoid using subshells:
7551 @smallexample
7552 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
7553 @end smallexample
7555 In both examples above, the leftmost @command{tar} invocation archives
7556 the contents of @file{sourcedir} to the standard output, while the
7557 rightmost one reads this archive from its standard input and
7558 extracts it.  The @option{-p} option tells it to restore permissions
7559 of the extracted files.
7561 @cindex Remote devices
7562 @cindex tar to a remote device
7563 @anchor{remote-dev}
7564 To specify an archive file on a device attached to a remote machine,
7565 use the following:
7567 @smallexample
7568 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
7569 @end smallexample
7571 @noindent
7572 @command{tar} will set up the remote connection, if possible, and
7573 prompt you for a username and password.  If you use
7574 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
7575 will attempt to set up the remote connection using your username
7576 as the username on the remote machine.
7578 @cindex Local and remote archives
7579 @anchor{local and remote archives}
7580 If the archive file name includes a colon (@samp{:}), then it is assumed
7581 to be a file on another machine.  If the archive file is
7582 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
7583 host @var{host}.  The remote host is accessed using the @command{rsh}
7584 program, with a username of @var{user}.  If the username is omitted
7585 (along with the @samp{@@} sign), then your user name will be used.
7586 (This is the normal @command{rsh} behavior.)  It is necessary for the
7587 remote machine, in addition to permitting your @command{rsh} access, to
7588 have the @file{rmt} program installed (this command is included in
7589 the @GNUTAR{} distribution and by default is installed under
7590 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
7591 installation prefix).  If you need to use a file whose name includes a
7592 colon, then the remote tape drive behavior
7593 can be inhibited by using the @option{--force-local} option.
7595 When the archive is being created to @file{/dev/null}, @GNUTAR{}
7596 tries to minimize input and output operations.  The Amanda backup
7597 system, when used with @GNUTAR{}, has an initial sizing pass which
7598 uses this feature.
7600 @node Selecting Archive Members
7601 @section Selecting Archive Members
7602 @cindex Specifying files to act on
7603 @cindex Specifying archive members
7605 @dfn{File Name arguments} specify which files in the file system
7606 @command{tar} operates on, when creating or adding to an archive, or which
7607 archive members @command{tar} operates on, when reading or deleting from
7608 an archive.  @xref{Operations}.
7610 To specify file names, you can include them as the last arguments on
7611 the command line, as follows:
7612 @smallexample
7613 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
7614 @end smallexample
7616 If a file name begins with dash (@samp{-}), precede it with
7617 @option{--add-file} option to prevent it from being treated as an
7618 option.
7620 @anchor{input name quoting}
7621 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7622 name, replacing @dfn{escape sequences} according to the following
7623 table:
7625 @multitable @columnfractions 0.20 0.60
7626 @headitem Escape @tab Replaced with
7627 @item \a         @tab Audible bell (@acronym{ASCII} 7)
7628 @item \b         @tab Backspace (@acronym{ASCII} 8)
7629 @item \f         @tab Form feed (@acronym{ASCII} 12)
7630 @item \n         @tab New line (@acronym{ASCII} 10)
7631 @item \r         @tab Carriage return (@acronym{ASCII} 13)
7632 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
7633 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
7634 @item \?         @tab @acronym{ASCII} 127
7635 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7636                  of up to 3 digits)
7637 @end multitable
7639 A backslash followed by any other symbol is retained.
7641 This default behavior is controlled by the following command line
7642 option:
7644 @table @option
7645 @opindex unquote
7646 @item --unquote
7647 Enable unquoting input file or member names (default).
7649 @opindex no-unquote
7650 @item --no-unquote
7651 Disable unquoting input file or member names.
7652 @end table
7654 If you specify a directory name as a file name argument, all the files
7655 in that directory are operated on by @command{tar}.
7657 If you do not specify files, @command{tar} behavior differs depending
7658 on the operation mode as described below:
7660 When @command{tar} is invoked with @option{--create} (@option{-c}),
7661 @command{tar} will stop immediately, reporting the following:
7663 @smallexample
7664 @group
7665 $ @kbd{tar cf a.tar}
7666 tar: Cowardly refusing to create an empty archive
7667 Try 'tar --help' or 'tar --usage' for more information.
7668 @end group
7669 @end smallexample
7671 If you specify either @option{--list} (@option{-t}) or
7672 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7673 operates on all the archive members in the archive.
7675 If run with @option{--diff} option, tar will compare the archive with
7676 the contents of the current working directory.
7678 If you specify any other operation, @command{tar} does nothing.
7680 By default, @command{tar} takes file names from the command line.  However,
7681 there are other ways to specify file or member names, or to modify the
7682 manner in which @command{tar} selects the files or members upon which to
7683 operate.  In general, these methods work both for specifying the names
7684 of files and archive members.
7686 @node files
7687 @section Reading Names from a File
7689 @cindex Reading file names from a file
7690 @cindex Lists of file names
7691 @cindex File Name arguments, alternatives
7692 @cindex @command{find}, using with @command{tar}
7693 Instead of giving the names of files or archive members on the command
7694 line, you can put the names into a file, and then use the
7695 @option{--files-from=@var{file-of-names}} (@option{-T
7696 @var{file-of-names}}) option to @command{tar}.  Give the name of the
7697 file which contains the list of files to include as the argument to
7698 @option{--files-from}.  In the list, the file names should be separated by
7699 newlines.  You will frequently use this option when you have generated
7700 the list of files to archive with the @command{find} utility.
7702 @table @option
7703 @opindex files-from
7704 @item --files-from=@var{file-name}
7705 @itemx -T @var{file-name}
7706 Get names to extract or create from file @var{file-name}.
7707 @end table
7709 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7710 you specify either @code{--files-from=-} or @code{-T -}), then the file
7711 names are read from standard input.
7713 Unless you are running @command{tar} with @option{--create}, you cannot use
7714 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7715 command.
7717 Any number of @option{-T} options can be given in the command line.
7719 The following example shows how to use @command{find} to generate a list of
7720 files smaller than 400 blocks in length@footnote{A file system block
7721 is usually 512 bytes, so this amounts to 200K.  Use the @samp{c}
7722 suffix to specify size in @emph{bytes}.  Also, when using
7723 GNU find, you can specify other size units, such as @samp{k},
7724 @samp{m}, etc.  @xref{Size,,,find.info,GNU Findutils}, for details.} and put that list into a file
7725 called @file{small-files}.  You can then use the @option{-T} option to
7726 @command{tar} to specify the files from that file, @file{small-files}, to
7727 create the archive @file{little.tgz}.  (The @option{-z} option to
7728 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7729 more information.)
7731 @smallexample
7732 $ @kbd{find . -size -400 -print > small-files}
7733 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7734 @end smallexample
7736 @noindent
7737 By default, each line read from the file list is first stripped off
7738 any leading and trailing whitespace.  If the resulting string begins
7739 with @samp{-} character, it is considered a @command{tar} option and is
7740 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7741 recognized only @option{-C} option in file lists, and only if the
7742 option and its argument occupied two consecutive lines.}.  Only a
7743 subset of @GNUTAR{} options is allowed for use in file lists.  For
7744 a list of such options, @ref{Position-Sensitive Options}.
7746 For example, the common use of this feature is to change to another
7747 directory by specifying @option{-C} option:
7749 @smallexample
7750 @group
7751 $ @kbd{cat list}
7752 -C/etc
7753 passwd
7754 hosts
7755 -C/lib
7756 libc.a
7757 $ @kbd{tar -c -f foo.tar --files-from list}
7758 @end group
7759 @end smallexample
7761 @noindent
7762 In this example, @command{tar} will first switch to @file{/etc}
7763 directory and add files @file{passwd} and @file{hosts} to the
7764 archive.  Then it will change to @file{/lib} directory and will archive
7765 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
7766 contain:
7768 @smallexample
7769 @group
7770 $ @kbd{tar tf foo.tar}
7771 passwd
7772 hosts
7773 libc.a
7774 @end group
7775 @end smallexample
7777 Note, that any options used in the file list remain in effect for the
7778 rest of the command line.  For example, using the same @file{list}
7779 file as above, the following command
7781 @smallexample
7782 $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
7783 @end smallexample
7785 @noindent
7786 will look for file @file{libcurses.a} in the directory @file{/lib},
7787 because it was used with the last @option{-C} option
7788 (@pxref{Position-Sensitive Options}).
7790 @anchor{verbatim-files-from}
7791 @opindex verbatim-files-from
7792 If such option handling is undesirable, use the
7793 @option{--verbatim-files-from} option.  When this option is in effect,
7794 each line read from the file list is treated as a file name.  Notice,
7795 that this means, in particular, that no whitespace trimming is
7796 performed.
7798 @anchor{no-verbatim-files-from}
7799 @opindex no-verbatim-files-from
7800 The @option{--verbatim-files-from} affects all @option{-T} options
7801 that follow it in the command line.  The default behavior can be
7802 restored using @option{--no-verbatim-files-from} option.
7804 @opindex add-file
7805 To disable option handling for a single file name, use the
7806 @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
7808 You can use any @GNUTAR{} command line options in the file list file,
7809 including @option{--files-from} option itself.  This allows for
7810 including contents of a file list into another file list file.
7811 Note however, that options that control file list processing, such as
7812 @option{--verbatim-files-from} or @option{--null} won't affect the
7813 file they appear in.  They will affect next @option{--files-from}
7814 option, if there is any.
7816 @menu
7817 * nul::
7818 @end menu
7820 @node nul
7821 @subsection @code{NUL}-Terminated File Names
7823 @cindex File names, terminated by @code{NUL}
7824 @cindex @code{NUL}-terminated file names
7825 The @option{--null} option causes
7826 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7827 to read file names terminated by a @code{NUL} instead of a newline, so
7828 files whose names contain newlines can be archived using
7829 @option{--files-from}.
7831 @table @option
7832 @xopindex{null, described}
7833 @item --null
7834 Only consider @code{NUL}-terminated file names, instead of files that
7835 terminate in a newline.
7837 @xopindex{no-null, described}
7838 @item --no-null
7839 Undo the effect of any previous @option{--null} option.
7840 @end table
7842 The @option{--null} option is just like the one in @acronym{GNU}
7843 @command{xargs} and @command{cpio}, and is useful with the
7844 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7845 @command{tar}, @option{--null} also disables special handling for
7846 file names that begin with dash (similar to
7847 @option{--verbatim-files-from} option).
7849 This example shows how to use @command{find} to generate a list of files
7850 larger than 800 blocks in length and put that list into a file called
7851 @file{long-files}.  The @option{-print0} option to @command{find} is just
7852 like @option{-print}, except that it separates files with a @code{NUL}
7853 rather than with a newline.  You can then run @command{tar} with both the
7854 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7855 files from that file, @file{long-files}, to create the archive
7856 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
7857 @command{tar} to recognize the @code{NUL} separator between files.
7859 @smallexample
7860 $ @kbd{find . -size +800 -print0 > long-files}
7861 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7862 @end smallexample
7864 The @option{--no-null} option can be used if you need to read both
7865 @code{NUL}-terminated and newline-terminated files on the same command line.
7866 For example, if @file{flist} is a newline-terminated file, then the
7867 following command can be used to combine it with the above command:
7869 @smallexample
7870 @group
7871 $ @kbd{find . -size +800 -print0 |
7872   tar -c -f big.tar --null -T - --no-null -T flist}
7873 @end group
7874 @end smallexample
7876 This example uses short options for typographic reasons, to avoid
7877 very long lines.
7879 @GNUTAR{} is tries to automatically detect @code{NUL}-terminated file
7880 lists, so in many cases it is safe to use them even without the
7881 @option{--null} option.  In this case @command{tar} will print a
7882 warning and continue reading such a file as if @option{--null} were
7883 actually given:
7885 @smallexample
7886 @group
7887 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7888 tar: -: file name read contains nul character
7889 @end group
7890 @end smallexample
7892 The null terminator, however, remains in effect only for this
7893 particular file, any following @option{-T} options will assume
7894 newline termination.  Of course, the null autodetection applies
7895 to these eventual surplus @option{-T} options as well.
7897 @node exclude
7898 @section Excluding Some Files
7900 @cindex File names, excluding files by
7901 @cindex Excluding files by name and pattern
7902 @cindex Excluding files by file system
7903 @opindex exclude
7904 @opindex exclude-from
7905 To avoid operating on files whose names match a particular pattern,
7906 use the @option{--exclude} or @option{--exclude-from} options.
7908 @table @option
7909 @opindex exclude
7910 @item --exclude=@var{pattern}
7911 Causes @command{tar} to ignore files that match the @var{pattern}.
7912 @end table
7914 @findex exclude
7915 The @option{--exclude=@var{pattern}} option prevents any file or
7916 member whose name matches the shell wildcard (@var{pattern}) from
7917 being operated on.
7918 For example, to create an archive with all the contents of the directory
7919 @file{src} except for files whose names end in @file{.o}, use the
7920 command @samp{tar -cf src.tar --exclude='*.o' src}.
7922 You may give multiple @option{--exclude} options.
7924 @table @option
7925 @opindex exclude-from
7926 @item --exclude-from=@var{file}
7927 @itemx -X @var{file}
7928 Causes @command{tar} to ignore files that match the patterns listed in
7929 @var{file}.
7930 @end table
7932 @findex exclude-from
7933 Use the @option{--exclude-from} option to read a
7934 list of patterns, one per line, from @var{file}; @command{tar} will
7935 ignore files matching those patterns.  Thus if @command{tar} is
7936 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7937 single line @file{*.o}, no files whose names end in @file{.o} will be
7938 added to the archive.
7940 Notice, that lines from @var{file} are read verbatim. One of the
7941 frequent errors is leaving some extra whitespace after a file name,
7942 which is difficult to catch using text editors.
7944 However, empty lines are OK.
7946 @cindex VCS, excluding patterns from ignore files
7947 @cindex VCS, ignore files
7948 @cindex CVS, ignore files
7949 @cindex Git, ignore files
7950 @cindex Bazaar, ignore files
7951 @cindex Mercurial, ignore files
7952 When archiving directories that are under some version control system (VCS),
7953 it is often convenient to read exclusion patterns from this VCS'
7954 ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.)  The
7955 following options provide such possibility:
7957 @table @option
7958 @anchor{exclude-vcs-ignores}
7959 @opindex exclude-vcs-ignores
7960 @item --exclude-vcs-ignores
7961 Before archiving a directory, see if it contains any of the following
7962 files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
7963 @file{.hgignore}.  If so, read ignore patterns from these files.
7965 The patterns are treated much as the corresponding VCS would treat
7966 them, i.e.:
7968 @table @file
7969 @findex .cvsignore
7970 @item .cvsignore
7971 Contains shell-style globbing patterns that apply only to the
7972 directory where this file resides.  No comments are allowed in the
7973 file.  Empty lines are ignored.
7975 @findex .gitignore
7976 @item .gitignore
7977 Contains shell-style globbing patterns.  Applies to the directory
7978 where @file{.gitfile} is located and all its subdirectories.
7980 Any line beginning with a @samp{#} is a comment.  Backslash escapes
7981 the comment character.
7983 @findex .bzrignore
7984 @item .bzrignore
7985 Contains shell globbing-patterns and regular expressions (if prefixed
7986 with @samp{RE:}@footnote{According to the Bazaar docs,
7987 globbing-patterns are Korn-shell style and regular expressions are
7988 perl-style.  As of @GNUTAR{} version @value{VERSION}, these are
7989 treated as shell-style globs and posix extended regexps.  This will be
7990 fixed in future releases.}.  Patterns affect the directory and all its
7991 subdirectories.
7993 Any line beginning with a @samp{#} is a comment.
7995 @findex .hgignore
7996 @item .hgignore
7997 Contains posix regular expressions@footnote{Support for perl-style
7998 regexps will appear in future releases.}.  The line @samp{syntax:
7999 glob} switches to shell globbing patterns.  The line @samp{syntax:
8000 regexp} switches back.  Comments begin with a @samp{#}.  Patterns
8001 affect the directory and all its subdirectories.
8002 @end table
8004 @opindex exclude-ignore
8005 @item --exclude-ignore=@var{file}
8006 Before dumping a directory, @command{tar} checks if it contains
8007 @var{file}.  If so, exclusion patterns are read from this file.
8008 The patterns affect only the directory itself.
8010 @opindex exclude-ignore-recursive
8011 @item --exclude-ignore-recursive=@var{file}
8012 Same as @option{--exclude-ignore}, except that the patterns read
8013 affect both the directory where @var{file} resides and all its
8014 subdirectories.
8015 @end table
8017 @table @option
8018 @cindex version control system, excluding files
8019 @cindex VCS, excluding files
8020 @cindex SCCS, excluding files
8021 @cindex RCS, excluding files
8022 @cindex CVS, excluding files
8023 @cindex SVN, excluding files
8024 @cindex git, excluding files
8025 @cindex Bazaar, excluding files
8026 @cindex Arch, excluding files
8027 @cindex Mercurial, excluding files
8028 @cindex Darcs, excluding files
8029 @anchor{exclude-vcs}
8030 @opindex exclude-vcs
8031 @item --exclude-vcs
8032 Exclude files and directories used by following version control
8033 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
8034 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
8036 As of version @value{VERSION}, the following files are excluded:
8038 @itemize @bullet
8039 @item @file{CVS/}, and everything under it
8040 @item @file{RCS/}, and everything under it
8041 @item @file{SCCS/}, and everything under it
8042 @item @file{.git/}, and everything under it
8043 @item @file{.gitignore}
8044 @item @file{.gitmodules}
8045 @item @file{.gitattributes}
8046 @item @file{.cvsignore}
8047 @item @file{.svn/}, and everything under it
8048 @item @file{.arch-ids/}, and everything under it
8049 @item @file{@{arch@}/}, and everything under it
8050 @item @file{=RELEASE-ID}
8051 @item @file{=meta-update}
8052 @item @file{=update}
8053 @item @file{.bzr}
8054 @item @file{.bzrignore}
8055 @item @file{.bzrtags}
8056 @item @file{.hg}
8057 @item @file{.hgignore}
8058 @item @file{.hgrags}
8059 @item @file{_darcs}
8060 @end itemize
8062 @opindex exclude-backups
8063 @item --exclude-backups
8064 Exclude backup and lock files.  This option causes exclusion of files
8065 that match the following shell globbing patterns:
8067 @table @asis
8068 @item .#*
8069 @item *~
8070 @item #*#
8071 @end table
8073 @end table
8075 @findex exclude-caches
8076 When creating an archive, the @option{--exclude-caches} option family
8077 causes @command{tar} to exclude all directories that contain a @dfn{cache
8078 directory tag}. A cache directory tag is a short file with the
8079 well-known name @file{CACHEDIR.TAG} and having a standard header
8080 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
8081 Various applications write cache directory tags into directories they
8082 use to hold regenerable, non-precious data, so that such data can be
8083 more easily excluded from backups.
8085 There are three @samp{exclude-caches} options, each providing a different
8086 exclusion semantics:
8088 @table @option
8089 @opindex exclude-caches
8090 @item --exclude-caches
8091 Do not archive the contents of the directory, but archive the
8092 directory itself and the @file{CACHEDIR.TAG} file.
8094 @opindex exclude-caches-under
8095 @item --exclude-caches-under
8096 Do not archive the contents of the directory, nor the
8097 @file{CACHEDIR.TAG} file, archive only the directory itself.
8099 @opindex exclude-caches-all
8100 @item --exclude-caches-all
8101 Omit directories containing @file{CACHEDIR.TAG} file entirely.
8102 @end table
8104 @findex exclude-tag
8105 Another option family, @option{--exclude-tag}, provides a generalization of
8106 this concept.  It takes a single argument, a file name to look for.
8107 Any directory that contains this file will be excluded from the dump.
8108 Similarly to @samp{exclude-caches}, there are three options in this
8109 option family:
8111 @table @option
8112 @opindex exclude-tag
8113 @item --exclude-tag=@var{file}
8114 Do not dump the contents of the directory, but dump the
8115 directory itself and the @var{file}.
8117 @opindex exclude-tag-under
8118 @item --exclude-tag-under=@var{file}
8119 Do not dump the contents of the directory, nor the
8120 @var{file}, archive only the directory itself.
8122 @opindex exclude-tag-all
8123 @item --exclude-tag-all=@var{file}
8124 Omit directories containing @var{file} file entirely.
8125 @end table
8127 Multiple @option{--exclude-tag*} options can be given.
8129 For example, given this directory:
8131 @smallexample
8132 @group
8133 $ @kbd{find dir}
8135 dir/blues
8136 dir/jazz
8137 dir/folk
8138 dir/folk/tagfile
8139 dir/folk/sanjuan
8140 dir/folk/trote
8141 @end group
8142 @end smallexample
8144 The @option{--exclude-tag} will produce the following:
8146 @smallexample
8147 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
8148 dir/
8149 dir/blues
8150 dir/jazz
8151 dir/folk/
8152 tar: dir/folk/: contains a cache directory tag tagfile;
8153   contents not dumped
8154 dir/folk/tagfile
8155 @end smallexample
8157 Both the @file{dir/folk} directory and its tagfile are preserved in
8158 the archive, however the rest of files in this directory are not.
8160 Now, using the @option{--exclude-tag-under} option will exclude
8161 @file{tagfile} from the dump, while still preserving the directory
8162 itself, as shown in this example:
8164 @smallexample
8165 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
8166 dir/
8167 dir/blues
8168 dir/jazz
8169 dir/folk/
8170 ./tar: dir/folk/: contains a cache directory tag tagfile;
8171   contents not dumped
8172 @end smallexample
8174 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
8175 directory entirely:
8177 @smallexample
8178 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
8179 dir/
8180 dir/blues
8181 dir/jazz
8182 ./tar: dir/folk/: contains a cache directory tag tagfile;
8183   directory not dumped
8184 @end smallexample
8186 @menu
8187 * problems with exclude::
8188 @end menu
8190 @node problems with exclude
8191 @unnumberedsubsec Problems with Using the @code{exclude} Options
8193 @xopindex{exclude, potential problems with}
8194 Some users find @samp{exclude} options confusing.  Here are some common
8195 pitfalls:
8197 @itemize @bullet
8198 @item
8199 The main operating mode of @command{tar} does not act on a file name
8200 explicitly listed on the command line, if one of its file name
8201 components is excluded.  In the example above, if
8202 you create an archive and exclude files that end with @samp{*.o}, but
8203 explicitly name the file @samp{dir.o/foo} after all the options have been
8204 listed, @samp{dir.o/foo} will be excluded from the archive.
8206 @item
8207 You can sometimes confuse the meanings of @option{--exclude} and
8208 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
8209 to be excluded are given as a pattern on the command line.  Use
8210 @option{--exclude-from} to introduce the name of a file which contains
8211 a list of patterns, one per line; each of these patterns can exclude
8212 zero, one, or many files.
8214 @item
8215 When you use @option{--exclude=@var{pattern}}, be sure to quote the
8216 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
8217 like @samp{*}.  If you do not do this, the shell might expand the
8218 @samp{*} itself using files at hand, so @command{tar} might receive a
8219 list of files instead of one pattern, or none at all, making the
8220 command somewhat illegal.  This might not correspond to what you want.
8222 For example, write:
8224 @smallexample
8225 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
8226 @end smallexample
8228 @noindent
8229 rather than:
8231 @smallexample
8232 # @emph{Wrong!}
8233 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
8234 @end smallexample
8236 @item
8237 You must use use shell syntax, or globbing, rather than @code{regexp}
8238 syntax, when using exclude options in @command{tar}.  If you try to use
8239 @code{regexp} syntax to describe files to be excluded, your command
8240 might fail.
8242 @item
8243 @FIXME{The change in semantics must have occurred before 1.11,
8244 so I doubt if it is worth mentioning at all. Anyway, should at
8245 least specify in which version the semantics changed.}
8246 In earlier versions of @command{tar}, what is now the
8247 @option{--exclude-from} option was called @option{--exclude} instead.
8248 Now, @option{--exclude} applies to patterns listed on the command
8249 line and @option{--exclude-from} applies to patterns listed in a
8250 file.
8252 @end itemize
8254 @node wildcards
8255 @section Wildcards Patterns and Matching
8257 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
8258 @samp{*} or @samp{?} for example, are replaced and expanded into all
8259 existing files matching the given pattern.  @GNUTAR{} can use wildcard
8260 patterns for matching (or globbing) archive members when extracting
8261 from or listing an archive.  Wildcard patterns are also used for
8262 verifying volume labels of @command{tar} archives.  This section has the
8263 purpose of explaining wildcard syntax for @command{tar}.
8265 @FIXME{the next few paragraphs need work.}
8267 A @var{pattern} should be written according to shell syntax, using wildcard
8268 characters to effect globbing.  Most characters in the pattern stand
8269 for themselves in the matched string, and case is significant: @samp{a}
8270 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
8271 pattern matches any single character in the matched string.  The character
8272 @samp{*} in the pattern matches zero, one, or more single characters in
8273 the matched string.  The character @samp{\} says to take the following
8274 character of the pattern @emph{literally}; it is useful when one needs to
8275 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
8277 The character @samp{[}, up to the matching @samp{]}, introduces a character
8278 class.  A @dfn{character class} is a list of acceptable characters
8279 for the next single character of the matched string.  For example,
8280 @samp{[abcde]} would match any of the first five letters of the alphabet.
8281 Note that within a character class, all of the ``special characters''
8282 listed above other than @samp{\} lose their special meaning; for example,
8283 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
8284 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
8285 the characters @samp{-} and @samp{]} must either come @emph{first} or
8286 @emph{last} in a character class.)
8288 @cindex Excluding characters from a character class
8289 @cindex Character class, excluding characters from
8290 If the first character of the class after the opening @samp{[}
8291 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
8292 Rather than listing character to match, it lists those characters which
8293 are @emph{forbidden} as the next single character of the matched string.
8295 Other characters of the class stand for themselves.  The special
8296 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
8297 letters, is meant to represent all characters between @var{a} and
8298 @var{e}, inclusive.
8300 @FIXME{need to add a sentence or so here to make this clear for those
8301 who don't have dan around.}
8303 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
8304 special for wildcard matches.  However, if a pattern completely matches
8305 a directory prefix of a matched string, then it matches the full matched
8306 string: thus, excluding a directory also excludes all the files beneath it.
8308 @menu
8309 * controlling pattern-matching::
8310 @end menu
8312 @node controlling pattern-matching
8313 @unnumberedsubsec Controlling Pattern-Matching
8315 For the purposes of this section, we call @dfn{exclusion members} all
8316 member names obtained while processing @option{--exclude} and
8317 @option{--exclude-from} options, and @dfn{inclusion members} those
8318 member names that were given in the command line or read from the file
8319 specified with @option{--files-from} option.
8321 These two pairs of member lists are used in the following operations:
8322 @option{--diff}, @option{--extract}, @option{--list},
8323 @option{--update}.
8325 There are no inclusion members in create mode (@option{--create} and
8326 @option{--append}), since in this mode the names obtained from the
8327 command line refer to @emph{files}, not archive members.
8329 By default, inclusion members are compared with archive members
8330 literally @footnote{Notice that earlier @GNUTAR{} versions used
8331 globbing for inclusion members, which contradicted to UNIX98
8332 specification and was not documented. @xref{Changes}, for more
8333 information on this and other changes.} and exclusion members are
8334 treated as globbing patterns.  For example:
8336 @smallexample
8337 @group
8338 $ @kbd{tar tf foo.tar}
8341 a.txt
8342 [remarks]
8343 # @i{Member names are used verbatim:}
8344 $ @kbd{tar -xf foo.tar -v '[remarks]'}
8345 [remarks]
8346 # @i{Exclude member names are globbed:}
8347 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
8348 a.txt
8349 [remarks]
8350 @end group
8351 @end smallexample
8353 This behavior can be altered by using the following options:
8355 @table @option
8356 @opindex wildcards
8357 @item --wildcards
8358 Treat all member names as wildcards.
8360 @opindex no-wildcards
8361 @item --no-wildcards
8362 Treat all member names as literal strings.
8363 @end table
8365 Thus, to extract files whose names end in @samp{.c}, you can use:
8367 @smallexample
8368 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
8371 @end smallexample
8373 @noindent
8374 Notice quoting of the pattern to prevent the shell from interpreting
8377 The effect of @option{--wildcards} option is canceled by
8378 @option{--no-wildcards}.  This can be used to pass part of
8379 the command line arguments verbatim and other part as globbing
8380 patterns.  For example, the following invocation:
8382 @smallexample
8383 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
8384 @end smallexample
8386 @noindent
8387 instructs @command{tar} to extract from @file{foo.tar} all files whose
8388 names end in @samp{.txt} and the file named @file{[remarks]}.
8390 Normally, a pattern matches a name if an initial subsequence of the
8391 name's components matches the pattern, where @samp{*}, @samp{?}, and
8392 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
8393 and wildcards can match @samp{/}.
8395 Other than optionally stripping leading @samp{/} from names
8396 (@pxref{absolute}), patterns and names are used as-is.  For
8397 example, trailing @samp{/} is not trimmed from a user-specified name
8398 before deciding whether to exclude it.
8400 However, this matching procedure can be altered by the options listed
8401 below.  These options accumulate.  For example:
8403 @smallexample
8404 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
8405 @end smallexample
8407 @noindent
8408 ignores case when excluding @samp{makefile}, but not when excluding
8409 @samp{readme}.
8411 @table @option
8412 @anchor{anchored patterns}
8413 @opindex anchored
8414 @opindex no-anchored
8415 @item --anchored
8416 @itemx --no-anchored
8417 If anchored, a pattern must match an initial subsequence
8418 of the name's components.  Otherwise, the pattern can match any
8419 subsequence.  Default is @option{--no-anchored} for exclusion members
8420 and @option{--anchored} inclusion members.
8422 @anchor{case-insensitive matches}
8423 @opindex ignore-case
8424 @opindex no-ignore-case
8425 @item --ignore-case
8426 @itemx --no-ignore-case
8427 When ignoring case, upper-case patterns match lower-case names and vice versa.
8428 When not ignoring case (the default), matching is case-sensitive.
8430 @opindex wildcards-match-slash
8431 @opindex no-wildcards-match-slash
8432 @item --wildcards-match-slash
8433 @itemx --no-wildcards-match-slash
8434 When wildcards match slash (the default for exclusion members), a
8435 wildcard like @samp{*} in the pattern can match a @samp{/} in the
8436 name.  Otherwise, @samp{/} is matched only by @samp{/}.
8438 @end table
8440 The @option{--recursion} and @option{--no-recursion} options
8441 (@pxref{recurse}) also affect how member patterns are interpreted.  If
8442 recursion is in effect, a pattern matches a name if it matches any of
8443 the name's parent directories.
8445 The following table summarizes pattern-matching default values:
8447 @multitable @columnfractions .3 .7
8448 @headitem Members @tab Default settings
8449 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
8450 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
8451 @end multitable
8453 @node quoting styles
8454 @section Quoting Member Names
8456 When displaying member names, @command{tar} takes care to avoid
8457 ambiguities caused by certain characters.  This is called @dfn{name
8458 quoting}.  The characters in question are:
8460 @itemize @bullet
8461 @item Non-printable control characters:
8462 @anchor{escape sequences}
8463 @multitable @columnfractions 0.20 0.10 0.60
8464 @headitem Character @tab @acronym{ASCII} @tab Character name
8465 @item \a @tab 7  @tab Audible bell
8466 @item \b @tab 8  @tab Backspace
8467 @item \f @tab 12 @tab Form feed
8468 @item \n @tab 10 @tab New line
8469 @item \r @tab 13 @tab Carriage return
8470 @item \t @tab 9  @tab Horizontal tabulation
8471 @item \v @tab 11 @tab Vertical tabulation
8472 @end multitable
8474 @item Space (@acronym{ASCII} 32)
8476 @item Single and double quotes (@samp{'} and @samp{"})
8478 @item Backslash (@samp{\})
8479 @end itemize
8481 The exact way @command{tar} uses to quote these characters depends on
8482 the @dfn{quoting style}.  The default quoting style, called
8483 @dfn{escape} (see below), uses backslash notation to represent control
8484 characters and backslash.
8486 @GNUTAR{} offers seven distinct quoting styles, which can be selected
8487 using @option{--quoting-style} option:
8489 @table @option
8490 @item --quoting-style=@var{style}
8491 @opindex quoting-style
8493 Sets quoting style.  Valid values for @var{style} argument are:
8494 literal, shell, shell-always, c, escape, locale, clocale.
8495 @end table
8497 These styles are described in detail below.  To illustrate their
8498 effect, we will use an imaginary tar archive @file{arch.tar}
8499 containing the following members:
8501 @smallexample
8502 @group
8503 # 1. Contains horizontal tabulation character.
8504 a       tab
8505 # 2. Contains newline character
8507 newline
8508 # 3. Contains a space
8509 a space
8510 # 4. Contains double quotes
8511 a"double"quote
8512 # 5. Contains single quotes
8513 a'single'quote
8514 # 6. Contains a backslash character:
8515 a\backslash
8516 @end group
8517 @end smallexample
8519 Here is how usual @command{ls} command would have listed them, if they
8520 had existed in the current working directory:
8522 @smallexample
8523 @group
8524 $ @kbd{ls}
8525 a\ttab
8526 a\nnewline
8527 a\ space
8528 a"double"quote
8529 a'single'quote
8530 a\\backslash
8531 @end group
8532 @end smallexample
8534 Quoting styles:
8536 @table @samp
8537 @item literal
8538 No quoting, display each character as is:
8540 @smallexample
8541 @group
8542 $ @kbd{tar tf arch.tar --quoting-style=literal}
8544 ./a space
8545 ./a'single'quote
8546 ./a"double"quote
8547 ./a\backslash
8548 ./a     tab
8550 newline
8551 @end group
8552 @end smallexample
8554 @item shell
8555 Display characters the same way Bourne shell does:
8556 control characters, except @samp{\t} and @samp{\n}, are printed using
8557 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
8558 single quote is printed as @samp{\'}.  If a name contains any quoted
8559 characters, it is enclosed in single quotes.  In particular, if a name
8560 contains single quotes, it is printed as several single-quoted strings:
8562 @smallexample
8563 @group
8564 $ @kbd{tar tf arch.tar --quoting-style=shell}
8566 './a space'
8567 './a'\''single'\''quote'
8568 './a"double"quote'
8569 './a\backslash'
8570 './a    tab'
8571 './a
8572 newline'
8573 @end group
8574 @end smallexample
8576 @item shell-always
8577 Same as @samp{shell}, but the names are always enclosed in single
8578 quotes:
8580 @smallexample
8581 @group
8582 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
8583 './'
8584 './a space'
8585 './a'\''single'\''quote'
8586 './a"double"quote'
8587 './a\backslash'
8588 './a    tab'
8589 './a
8590 newline'
8591 @end group
8592 @end smallexample
8594 @item c
8595 Use the notation of the C programming language.  All names are
8596 enclosed in double quotes.  Control characters are quoted using
8597 backslash notations, double quotes are represented as @samp{\"},
8598 backslash characters are represented as @samp{\\}.  Single quotes and
8599 spaces are not quoted:
8601 @smallexample
8602 @group
8603 $ @kbd{tar tf arch.tar --quoting-style=c}
8604 "./"
8605 "./a space"
8606 "./a'single'quote"
8607 "./a\"double\"quote"
8608 "./a\\backslash"
8609 "./a\ttab"
8610 "./a\nnewline"
8611 @end group
8612 @end smallexample
8614 @item escape
8615 Control characters are printed using backslash notation, and a
8616 backslash as @samp{\\}.  This is the default quoting style, unless it
8617 was changed when configured the package.
8619 @smallexample
8620 @group
8621 $ @kbd{tar tf arch.tar --quoting-style=escape}
8623 ./a space
8624 ./a'single'quote
8625 ./a"double"quote
8626 ./a\\backslash
8627 ./a\ttab
8628 ./a\nnewline
8629 @end group
8630 @end smallexample
8632 @item locale
8633 Control characters, single quote and backslash are printed using
8634 backslash notation.  All names are quoted using left and right
8635 quotation marks, appropriate to the current locale.  If it does not
8636 define quotation marks, use @samp{'} as left and as right
8637 quotation marks.  Any occurrences of the right quotation mark in a
8638 name are escaped with @samp{\}, for example:
8640 For example:
8642 @smallexample
8643 @group
8644 $ @kbd{tar tf arch.tar --quoting-style=locale}
8645 './'
8646 './a space'
8647 './a\'single\'quote'
8648 './a"double"quote'
8649 './a\\backslash'
8650 './a\ttab'
8651 './a\nnewline'
8652 @end group
8653 @end smallexample
8655 @item clocale
8656 Same as @samp{locale}, but @samp{"} is used for both left and right
8657 quotation marks, if not provided by the currently selected locale:
8659 @smallexample
8660 @group
8661 $ @kbd{tar tf arch.tar --quoting-style=clocale}
8662 "./"
8663 "./a space"
8664 "./a'single'quote"
8665 "./a\"double\"quote"
8666 "./a\\backslash"
8667 "./a\ttab"
8668 "./a\nnewline"
8669 @end group
8670 @end smallexample
8671 @end table
8673 You can specify which characters should be quoted in addition to those
8674 implied by the current quoting style:
8676 @table @option
8677 @item --quote-chars=@var{string}
8678 Always quote characters from @var{string}, even if the selected
8679 quoting style would not quote them.
8680 @end table
8682 For example, using @samp{escape} quoting (compare with the usual
8683 escape listing above):
8685 @smallexample
8686 @group
8687 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
8689 ./a\ space
8690 ./a'single'quote
8691 ./a\"double\"quote
8692 ./a\\backslash
8693 ./a\ttab
8694 ./a\nnewline
8695 @end group
8696 @end smallexample
8698 To disable quoting of such additional characters, use the following
8699 option:
8701 @table @option
8702 @item --no-quote-chars=@var{string}
8703 Remove characters listed in @var{string} from the list of quoted
8704 characters set by the previous @option{--quote-chars} option.
8705 @end table
8707 This option is particularly useful if you have added
8708 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
8709 and wish to disable it for the current invocation.
8711 Note, that @option{--no-quote-chars} does @emph{not} disable those
8712 characters that are quoted by default in the selected quoting style.
8714 @node transform
8715 @section Modifying File and Member Names
8717 @command{Tar} archives contain detailed information about files stored
8718 in them and full file names are part of that information.  When
8719 storing a file to an archive, its file name is recorded in it,
8720 along with the actual file contents.  When restoring from an archive,
8721 a file is created on disk with exactly the same name as that stored
8722 in the archive.  In the majority of cases this is the desired behavior
8723 of a file archiver.  However, there are some cases when it is not.
8725 First of all, it is often unsafe to extract archive members with
8726 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
8727 takes special precautions when extracting such names and provides a
8728 special option for handling them, which is described in
8729 @ref{absolute}.
8731 Secondly, you may wish to extract file names without some leading
8732 directory components, or with otherwise modified names.  In other
8733 cases it is desirable to store files under differing names in the
8734 archive.
8736 @GNUTAR{} provides several options for these needs.
8738 @table @option
8739 @opindex strip-components
8740 @item --strip-components=@var{number}
8741 Strip given @var{number} of leading components from file names before
8742 extraction.
8743 @end table
8745 For example, suppose you have archived whole @file{/usr} hierarchy to
8746 a tar archive named @file{usr.tar}.  Among other files, this archive
8747 contains @file{usr/include/stdlib.h}, which you wish to extract to
8748 the current working directory.  To do so, you type:
8750 @smallexample
8751 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8752 @end smallexample
8754 The option @option{--strip=2} instructs @command{tar} to strip the
8755 two leading components (@file{usr/} and @file{include/}) off the file
8756 name.
8758 If you add the @option{--verbose} (@option{-v}) option to the invocation
8759 above, you will note that the verbose listing still contains the
8760 full file name, with the two removed components still in place.  This
8761 can be inconvenient, so @command{tar} provides a special option for
8762 altering this behavior:
8764 @anchor{show-transformed-names}
8765 @table @option
8766 @opindex show-transformed-names
8767 @item --show-transformed-names
8768 Display file or member names with all requested transformations
8769 applied.
8770 @end table
8772 @noindent
8773 For example:
8775 @smallexample
8776 @group
8777 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8778 usr/include/stdlib.h
8779 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8780 stdlib.h
8781 @end group
8782 @end smallexample
8784 Notice that in both cases the file @file{stdlib.h} is extracted to the
8785 current working directory, @option{--show-transformed-names} affects
8786 only the way its name is displayed.
8788 This option is especially useful for verifying whether the invocation
8789 will have the desired effect.  Thus, before running
8791 @smallexample
8792 $ @kbd{tar -x --strip=@var{n}}
8793 @end smallexample
8795 @noindent
8796 it is often advisable to run
8798 @smallexample
8799 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8800 @end smallexample
8802 @noindent
8803 to make sure the command will produce the intended results.
8805 In case you need to apply more complex modifications to the file name,
8806 @GNUTAR{} provides a general-purpose transformation option:
8808 @table @option
8809 @opindex transform
8810 @opindex xform
8811 @item --transform=@var{expression}
8812 @itemx --xform=@var{expression}
8813 Modify file names using supplied @var{expression}.
8814 @end table
8816 @noindent
8817 The @var{expression} is a @command{sed}-like replace expression of the
8818 form:
8820 @smallexample
8821 s/@var{regexp}/@var{replace}/[@var{flags}]
8822 @end smallexample
8824 @noindent
8825 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8826 replacement for each file name part that matches @var{regexp}.  Both
8827 @var{regexp} and @var{replace} are described in detail in
8828 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8830 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8831 that it be used consistently throughout the expression. For example,
8832 the following two expressions are equivalent:
8834 @smallexample
8835 @group
8836 s/one/two/
8837 s,one,two,
8838 @end group
8839 @end smallexample
8841 Changing delimiters is often useful when the @var{regex} contains
8842 slashes.  For example, it is more convenient to write @code{s,/,-,} than
8843 @code{s/\//-/}.
8845 As in @command{sed}, you can give several replace expressions,
8846 separated by a semicolon.
8848 Supported @var{flags} are:
8850 @table @samp
8851 @item g
8852 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8853 just the first.
8855 @item i
8856 Use case-insensitive matching.
8858 @item x
8859 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8860 regexps, Extended regular expressions, Extended regular expressions,
8861 sed, GNU sed}).
8863 @item @var{number}
8864 Only replace the @var{number}th match of the @var{regexp}.
8866 Note: the @acronym{POSIX} standard does not specify what should happen
8867 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
8868 follows the GNU @command{sed} implementation in this regard, so
8869 the interaction is defined to be: ignore matches before the
8870 @var{number}th, and then match and replace all matches from the
8871 @var{number}th on.
8873 @end table
8875 In addition, several @dfn{transformation scope} flags are supported,
8876 that control to what files transformations apply.  These are:
8878 @table @samp
8879 @item r
8880 Apply transformation to regular archive members.
8882 @item R
8883 Do not apply transformation to regular archive members.
8885 @item s
8886 Apply transformation to symbolic link targets.
8888 @item S
8889 Do not apply transformation to symbolic link targets.
8891 @item h
8892 Apply transformation to hard link targets.
8894 @item H
8895 Do not apply transformation to hard link targets.
8896 @end table
8898 Default is @samp{rsh}, which means to apply transformations to both archive
8899 members and targets of symbolic and hard links.
8901 Default scope flags can also be changed using @samp{flags=} statement
8902 in the transform expression.  The flags set this way remain in force
8903 until next @samp{flags=} statement or end of expression, whichever
8904 occurs first.  For example:
8906 @smallexample
8907   --transform 'flags=S;s|^|/usr/local/|'
8908 @end smallexample
8910 Here are several examples of @option{--transform} usage:
8912 @enumerate
8913 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8915 @smallexample
8916 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8917 @end smallexample
8919 @item Strip two leading directory components (equivalent to
8920 @option{--strip-components=2}):
8922 @smallexample
8923 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8924 @end smallexample
8926 @item Convert each file name to lower case:
8928 @smallexample
8929 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8930 @end smallexample
8932 @item Prepend @file{/prefix/}  to each file name:
8934 @smallexample
8935 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8936 @end smallexample
8938 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8939 to each archive member:
8941 @smallexample
8942 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8943 @end smallexample
8944 @end enumerate
8946 Notice the use of flags in the last example.  The @file{/lib}
8947 directory often contains many symbolic links to files within it.
8948 It may look, for example, like this:
8950 @smallexample
8951 $ @kbd{ls -l}
8952 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
8953 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8954 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8956 @end smallexample
8958 Using the expression @samp{s,^,/usr/local/,} would mean adding
8959 @samp{/usr/local} to both regular archive members and to link
8960 targets. In this case, @file{/lib/libc.so.6} would become:
8962 @smallexample
8963   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8964 @end smallexample
8966 This is definitely not desired.  To avoid this, the @samp{S} flag
8967 is used, which excludes symbolic link targets from filename
8968 transformations.  The result is:
8970 @smallexample
8971 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
8972        --show-transformed /lib}
8973 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
8974 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8975 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8976  -> libc-2.3.2.so
8977 @end smallexample
8979 Unlike @option{--strip-components}, @option{--transform} can be used
8980 in any @GNUTAR{} operation mode.  For example, the following command
8981 adds files to the archive while replacing the leading @file{usr/}
8982 component with @file{var/}:
8984 @smallexample
8985 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8986 @end smallexample
8988 To test @option{--transform} effect we suggest using
8989 @option{--show-transformed-names} option:
8991 @smallexample
8992 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8993        --verbose --show-transformed-names /}
8994 @end smallexample
8996 If both @option{--strip-components} and @option{--transform} are used
8997 together, then @option{--transform} is applied first, and the required
8998 number of components is then stripped from its result.
9000 You can use as many @option{--transform} options in a single command
9001 line as you want.  The specified expressions will then be applied in
9002 order of their appearance.  For example, the following two invocations
9003 are equivalent:
9005 @smallexample
9006 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
9007                         --transform='s,/usr/local,/usr/,'}
9008 $ @kbd{tar -cf arch.tar \
9009                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
9010 @end smallexample
9012 @node after
9013 @section Operating Only on New Files
9015 @cindex Excluding file by age
9016 @cindex Data Modification time, excluding files by
9017 @cindex Modification time, excluding files by
9018 @cindex Age, excluding files by
9019 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
9020 @option{-N @var{date}}) option causes @command{tar} to only work on
9021 files whose data modification or status change times are newer than
9022 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
9023 it is taken to be a file name; the data modification time of that file
9024 is used as the date. If you use this option when creating or appending
9025 to an archive, the archive will only include new files.  If you use
9026 @option{--after-date} when extracting an archive, @command{tar} will
9027 only extract files newer than the @var{date} you specify.
9029 If you only want @command{tar} to make the date comparison based on
9030 modification of the file's data (rather than status
9031 changes), then use the @option{--newer-mtime=@var{date}} option.
9033 @cindex --after-date and --update compared
9034 @cindex --newer-mtime and --update compared
9035 You may use these options with any operation.  Note that these options
9036 differ from the @option{--update} (@option{-u}) operation in that they
9037 allow you to specify a particular date against which @command{tar} can
9038 compare when deciding whether or not to archive the files.
9040 @table @option
9041 @opindex after-date
9042 @opindex newer
9043 @item --after-date=@var{date}
9044 @itemx --newer=@var{date}
9045 @itemx -N @var{date}
9046 Only store files newer than @var{date}.
9048 Acts on files only if their data modification or status change times are
9049 later than @var{date}.  Use in conjunction with any operation.
9051 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
9052 name; the data modification time of that file is used as the date.
9054 @opindex newer-mtime
9055 @item --newer-mtime=@var{date}
9056 Acts like @option{--after-date}, but only looks at data modification times.
9057 @end table
9059 These options limit @command{tar} to operate only on files which have
9060 been modified after the date specified.  A file's status is considered to have
9061 changed if its contents have been modified, or if its owner,
9062 permissions, and so forth, have been changed.  (For more information on
9063 how to specify a date, see @ref{Date input formats}; remember that the
9064 entire date argument must be quoted if it contains any spaces.)
9066 Gurus would say that @option{--after-date} tests both the data
9067 modification time (@code{mtime}, the time the contents of the file
9068 were last modified) and the status change time (@code{ctime}, the time
9069 the file's status was last changed: owner, permissions, etc.@:)
9070 fields, while @option{--newer-mtime} tests only the @code{mtime}
9071 field.
9073 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
9074 @code{ctime} and processes the file if either one is more recent than
9075 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
9076 disregards @code{ctime}.  Neither does it use @code{atime} (the last time the
9077 contents of the file were looked at).
9079 Date specifiers can have embedded spaces.  Because of this, you may need
9080 to quote date arguments to keep the shell from parsing them as separate
9081 arguments.  For example, the following command will add to the archive
9082 all the files modified less than two days ago:
9084 @smallexample
9085 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
9086 @end smallexample
9088 When any of these options is used with the option @option{--verbose}
9089 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
9090 date back to its textual representation and compare that with the
9091 one given with the option.  If the two dates differ, @command{tar} will
9092 print a warning saying what date it will use.  This is to help user
9093 ensure he is using the right date.  For example:
9095 @smallexample
9096 @group
9097 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
9098 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
9099 13:19:37.232434
9100 @end group
9101 @end smallexample
9103 @quotation
9104 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
9105 should not be used for incremental backups.  @xref{Incremental Dumps},
9106 for proper way of creating incremental backups.
9107 @end quotation
9109 @node recurse
9110 @section Descending into Directories
9111 @cindex Avoiding recursion in directories
9112 @cindex Descending directories, avoiding
9113 @cindex Directories, avoiding recursion
9114 @cindex Recursion in directories, avoiding
9116 Usually, @command{tar} will recursively explore all directories (either
9117 those given on the command line or through the @option{--files-from}
9118 option) for the various files they contain.  However, you may not always
9119 want @command{tar} to act this way.
9121 @opindex no-recursion
9122 @cindex @command{find}, using with @command{tar}
9123 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
9124 into specified directories.  If you specify @option{--no-recursion}, you can
9125 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
9126 utility for hunting through levels of directories to
9127 construct a list of file names which you could then pass to @command{tar}.
9128 @command{find} allows you to be more selective when choosing which files to
9129 archive; see @ref{files}, for more information on using @command{find} with
9130 @command{tar}.
9132 @table @option
9133 @item --no-recursion
9134 Prevents @command{tar} from recursively descending directories.
9136 @opindex recursion
9137 @item --recursion
9138 Requires @command{tar} to recursively descend directories.
9139 This is the default.
9140 @end table
9142 When you use @option{--no-recursion}, @GNUTAR{} grabs
9143 directory entries themselves, but does not descend on them
9144 recursively.  Many people use @command{find} for locating files they
9145 want to back up, and since @command{tar} @emph{usually} recursively
9146 descends on directories, they have to use the @samp{@w{-not -type d}}
9147 test in their @command{find} invocation (@pxref{Type, Type, Type test,
9148 find, Finding Files}), as they usually do not want all the files in a
9149 directory. They then use the @option{--files-from} option to archive
9150 the files located via @command{find}.
9152 The problem when restoring files archived in this manner is that the
9153 directories themselves are not in the archive; so the
9154 @option{--same-permissions} (@option{--preserve-permissions},
9155 @option{-p}) option does not affect them---while users might really
9156 like it to.  Specifying @option{--no-recursion} is a way to tell
9157 @command{tar} to grab only the directory entries given to it, adding
9158 no new files on its own.  To summarize, if you use @command{find} to
9159 create a list of files to be stored in an archive, use it as follows:
9161 @smallexample
9162 @group
9163 $ @kbd{find @var{dir} @var{tests} | \
9164   tar -cf @var{archive} --no-recursion -T -}
9165 @end group
9166 @end smallexample
9168 The @option{--no-recursion} option also applies when extracting: it
9169 causes @command{tar} to extract only the matched directory entries, not
9170 the files under those directories.
9172 The @option{--no-recursion} option also affects how globbing patterns
9173 are interpreted (@pxref{controlling pattern-matching}).
9175 The @option{--no-recursion} and @option{--recursion} options apply to
9176 later options and operands, and can be overridden by later occurrences
9177 of @option{--no-recursion} and @option{--recursion}.  For example:
9179 @smallexample
9180 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
9181 @end smallexample
9183 @noindent
9184 creates an archive with one entry for @file{grape}, and the recursive
9185 contents of @file{grape/concord}, but no entries under @file{grape}
9186 other than @file{grape/concord}.
9188 @node one
9189 @section Crossing File System Boundaries
9190 @cindex File system boundaries, not crossing
9192 @command{tar} will normally automatically cross file system boundaries in
9193 order to archive files which are part of a directory tree.  You can
9194 change this behavior by running @command{tar} and specifying
9195 @option{--one-file-system}.  This option only affects files that are
9196 archived because they are in a directory that is being archived;
9197 @command{tar} will still archive files explicitly named on the command line
9198 or through @option{--files-from}, regardless of where they reside.
9200 @table @option
9201 @opindex one-file-system
9202 @item --one-file-system
9203 Prevents @command{tar} from crossing file system boundaries when
9204 archiving.  Use in conjunction with any write operation.
9205 @end table
9207 The @option{--one-file-system} option causes @command{tar} to modify its
9208 normal behavior in archiving the contents of directories.  If a file in
9209 a directory is not on the same file system as the directory itself, then
9210 @command{tar} will not archive that file.  If the file is a directory
9211 itself, @command{tar} will not archive anything beneath it; in other words,
9212 @command{tar} will not cross mount points.
9214 This option is useful for making full or incremental archival backups of
9215 a file system.  If this option is used in conjunction with
9216 @option{--verbose} (@option{-v}), files that are excluded are
9217 mentioned by name on the standard error.
9219 @menu
9220 * directory::                   Changing Directory
9221 * absolute::                    Absolute File Names
9222 @end menu
9224 @node directory
9225 @subsection Changing the Working Directory
9227 @FIXME{need to read over this node now for continuity; i've switched
9228 things around some.}
9230 @cindex Changing directory mid-stream
9231 @cindex Directory, changing mid-stream
9232 @cindex Working directory, specifying
9233 To change the working directory in the middle of a list of file names,
9234 either on the command line or in a file specified using
9235 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
9236 This will change the working directory to the specified directory
9237 after that point in the list.
9239 @table @option
9240 @opindex directory
9241 @item --directory=@var{directory}
9242 @itemx -C @var{directory}
9243 Changes the working directory in the middle of a command line.
9244 @end table
9246 For example,
9248 @smallexample
9249 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
9250 @end smallexample
9252 @noindent
9253 will place the files @file{grape} and @file{prune} from the current
9254 directory into the archive @file{jams.tar}, followed by the file
9255 @file{cherry} from the directory @file{food}.  This option is especially
9256 useful when you have several widely separated files that you want to
9257 store in the same archive.
9259 Note that the file @file{cherry} is recorded in the archive under the
9260 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
9261 archive will contain three files that all appear to have come from the
9262 same directory; if the archive is extracted with plain @samp{tar
9263 --extract}, all three files will be written in the current directory.
9265 Contrast this with the command,
9267 @smallexample
9268 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
9269 @end smallexample
9271 @noindent
9272 which records the third file in the archive under the name
9273 @file{red/cherry} so that, if the archive is extracted using
9274 @samp{tar --extract}, the third file will be written in a subdirectory
9275 named @file{red}.
9277 You can use the @option{--directory} option to make the archive
9278 independent of the original name of the directory holding the files.
9279 The following command places the files @file{/etc/passwd},
9280 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
9281 @file{foo.tar}:
9283 @smallexample
9284 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
9285 @end smallexample
9287 @noindent
9288 However, the names of the archive members will be exactly what they were
9289 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
9290 They will not appear to be related by file name to the original
9291 directories where those files were located.
9293 Note that @option{--directory} options are interpreted consecutively.  If
9294 @option{--directory} specifies a relative file name, it is interpreted
9295 relative to the then current directory, which might not be the same as
9296 the original current working directory of @command{tar}, due to a previous
9297 @option{--directory} option.
9299 When using @option{--files-from} (@pxref{files}), you can put various
9300 @command{tar} options (including @option{-C}) in the file list.  Notice,
9301 however, that in this case the option and its argument may not be
9302 separated by whitespace.  If you use short option, its argument must
9303 either follow the option letter immediately, without any intervening
9304 whitespace, or occupy the next line.  Otherwise, if you use long
9305 option, separate its argument by an equal sign.
9307 For instance, the file list for the above example will be:
9309 @smallexample
9310 @group
9311 -C/etc
9312 passwd
9313 hosts
9314 --directory=/lib
9315 libc.a
9316 @end group
9317 @end smallexample
9319 @noindent
9320 To use it, you would invoke @command{tar} as follows:
9322 @smallexample
9323 $ @kbd{tar -c -f foo.tar --files-from list}
9324 @end smallexample
9326 The interpretation of options in file lists is disabled by
9327 @option{--verbatim-files-from} and @option{--null} options.
9329 @node absolute
9330 @subsection Absolute File Names
9331 @cindex absolute file names
9332 @cindex file names, absolute
9334 By default, @GNUTAR{} drops a leading @samp{/} on
9335 input or output, and complains about file names containing a @file{..}
9336 component.  There is an option that turns off this behavior:
9338 @table @option
9339 @opindex absolute-names
9340 @item --absolute-names
9341 @itemx -P
9342 Do not strip leading slashes from file names, and permit file names
9343 containing a @file{..} file name component.
9344 @end table
9346 When @command{tar} extracts archive members from an archive, it strips any
9347 leading slashes (@samp{/}) from the member name.  This causes absolute
9348 member names in the archive to be treated as relative file names.  This
9349 allows you to have such members extracted wherever you want, instead of
9350 being restricted to extracting the member in the exact directory named
9351 in the archive.  For example, if the archive member has the name
9352 @file{/etc/passwd}, @command{tar} will extract it as if the name were
9353 really @file{etc/passwd}.
9355 File names containing @file{..} can cause problems when extracting, so
9356 @command{tar} normally warns you about such files when creating an
9357 archive, and rejects attempts to extracts such files.
9359 Other @command{tar} programs do not do this.  As a result, if you
9360 create an archive whose member names start with a slash, they will be
9361 difficult for other people with a non-@GNUTAR{}
9362 program to use.  Therefore, @GNUTAR{} also strips
9363 leading slashes from member names when putting members into the
9364 archive.  For example, if you ask @command{tar} to add the file
9365 @file{/bin/ls} to an archive, it will do so, but the member name will
9366 be @file{bin/ls}@footnote{A side effect of this is that when
9367 @option{--create} is used with @option{--verbose} the resulting output
9368 is not, generally speaking, the same as the one you'd get running
9369 @kbd{tar --list} command.  This may be important if you use some
9370 scripts for comparing both outputs.  @xref{listing member and file names},
9371 for the information on how to handle this case.}.
9373 Symbolic links containing @file{..} or leading @samp{/} can also cause
9374 problems when extracting, so @command{tar} normally extracts them last;
9375 it may create empty files as placeholders during extraction.
9377 If you use the @option{--absolute-names} (@option{-P}) option,
9378 @command{tar} will do none of these transformations.
9380 To archive or extract files relative to the root directory, specify
9381 the @option{--absolute-names} (@option{-P}) option.
9383 Normally, @command{tar} acts on files relative to the working
9384 directory---ignoring superior directory names when archiving, and
9385 ignoring leading slashes when extracting.
9387 When you specify @option{--absolute-names} (@option{-P}),
9388 @command{tar} stores file names including all superior directory
9389 names, and preserves leading slashes.  If you only invoked
9390 @command{tar} from the root directory you would never need the
9391 @option{--absolute-names} option, but using this option
9392 may be more convenient than switching to root.
9394 @FIXME{Should be an example in the tutorial/wizardry section using this
9395 to transfer files between systems.}
9397 @table @option
9398 @item --absolute-names
9399 Preserves full file names (including superior directory names) when
9400 archiving and extracting files.
9402 @end table
9404 @command{tar} prints out a message about removing the @samp{/} from
9405 file names.  This message appears once per @GNUTAR{}
9406 invocation.  It represents something which ought to be told; ignoring
9407 what it means can cause very serious surprises, later.
9409 Some people, nevertheless, do not want to see this message.  Wanting to
9410 play really dangerously, one may of course redirect @command{tar} standard
9411 error to the sink.  For example, under @command{sh}:
9413 @smallexample
9414 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
9415 @end smallexample
9417 @noindent
9418 Another solution, both nicer and simpler, would be to change to
9419 the @file{/} directory first, and then avoid absolute notation.
9420 For example:
9422 @smallexample
9423 $ @kbd{tar -c -f archive.tar -C / home}
9424 @end smallexample
9426 @xref{Integrity}, for some of the security-related implications
9427 of using this option.
9429 @include parse-datetime.texi
9431 @node Formats
9432 @chapter Controlling the Archive Format
9434 @cindex Tar archive formats
9435 Due to historical reasons, there are several formats of tar archives.
9436 All of them are based on the same principles, but have some subtle
9437 differences that often make them incompatible with each other.
9439 GNU tar is able to create and handle archives in a variety of formats.
9440 The most frequently used formats are (in alphabetical order):
9442 @table @asis
9443 @item gnu
9444 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
9445 from an early @acronym{POSIX} standard, adding some improvements such as
9446 sparse file handling and incremental archives.  Unfortunately these
9447 features were implemented in a way incompatible with other archive
9448 formats.
9450 Archives in @samp{gnu} format are able to hold file names of unlimited
9451 length.
9453 @item oldgnu
9454 Format used by @GNUTAR{} of versions prior to 1.12.
9456 @item v7
9457 Archive format, compatible with the V7 implementation of tar.  This
9458 format imposes a number of limitations.  The most important of them
9459 are:
9461 @enumerate
9462 @item The maximum length of a file name is limited to 99 characters.
9463 @item The maximum length of a symbolic link is limited to 99 characters.
9464 @item It is impossible to store special files (block and character
9465 devices, fifos etc.)
9466 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
9467 octal)
9468 @item V7 archives do not contain symbolic ownership information (user
9469 and group name of the file owner).
9470 @end enumerate
9472 This format has traditionally been used by Automake when producing
9473 Makefiles.  This practice will change in the future, in the meantime,
9474 however this means that projects containing file names more than 99
9475 characters long will not be able to use @GNUTAR{} @value{VERSION} and
9476 Automake prior to 1.9.
9478 @item ustar
9479 Archive format defined by @acronym{POSIX.1-1988} specification.  It stores
9480 symbolic ownership information.  It is also able to store
9481 special files.  However, it imposes several restrictions as well:
9483 @enumerate
9484 @item The maximum length of a file name is limited to 256 characters,
9485 provided that the file name can be split at a directory separator in
9486 two parts, first of them being at most 155 bytes long.  So, in most
9487 cases the maximum file name length will be shorter than 256
9488 characters.
9489 @item The maximum length of a symbolic link name is limited to
9490 100 characters.
9491 @item Maximum size of a file the archive is able to accommodate
9492 is 8GB
9493 @item Maximum value of UID/GID is 2097151.
9494 @item Maximum number of bits in device major and minor numbers is 21.
9495 @end enumerate
9497 @item star
9498 Format used by J@"org Schilling @command{star}
9499 implementation.  @GNUTAR{} is able to read @samp{star} archives but
9500 currently does not produce them.
9502 @item posix
9503 Archive format defined by @acronym{POSIX.1-2001} specification.  This is the
9504 most flexible and feature-rich format.  It does not impose any
9505 restrictions on file sizes or file name lengths.  This format is quite
9506 recent, so not all tar implementations are able to handle it properly.
9507 However, this format is designed in such a way that any tar
9508 implementation able to read @samp{ustar} archives will be able to read
9509 most @samp{posix} archives as well, with the only exception that any
9510 additional information (such as long file names etc.)@: will in such
9511 case be extracted as plain text files along with the files it refers to.
9513 This archive format will be the default format for future versions
9514 of @GNUTAR{}.
9516 @end table
9518 The following table summarizes the limitations of each of these
9519 formats:
9521 @multitable @columnfractions .10 .20 .20 .20 .20
9522 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
9523 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9524 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9525 @item v7     @tab 2097151 @tab 8GB @tab 99 @tab n/a
9526 @item ustar  @tab 2097151 @tab 8GB @tab 256 @tab 21
9527 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
9528 @end multitable
9530 The default format for @GNUTAR{} is defined at compilation
9531 time.  You may check it by running @command{tar --help}, and examining
9532 the last lines of its output.  Usually, @GNUTAR{} is configured
9533 to create archives in @samp{gnu} format, however, future version will
9534 switch to @samp{posix}.
9536 @menu
9537 * Compression::                 Using Less Space through Compression
9538 * Attributes::                  Handling File Attributes
9539 * Portability::                 Making @command{tar} Archives More Portable
9540 * cpio::                        Comparison of @command{tar} and @command{cpio}
9541 @end menu
9543 @node Compression
9544 @section Using Less Space through Compression
9546 @menu
9547 * gzip::                        Creating and Reading Compressed Archives
9548 * sparse::                      Archiving Sparse Files
9549 @end menu
9551 @node gzip
9552 @subsection Creating and Reading Compressed Archives
9553 @cindex Compressed archives
9554 @cindex Storing archives in compressed format
9556 @cindex gzip
9557 @cindex bzip2
9558 @cindex lzip
9559 @cindex lzma
9560 @cindex lzop
9561 @cindex compress
9562 @cindex zstd
9563 @GNUTAR{} is able to create and read compressed archives.  It supports
9564 a wide variety of compression programs, namely: @command{gzip},
9565 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
9566 @command{zstd}, @command{xz} and traditional @command{compress}. The
9567 latter is supported mostly for backward compatibility, and we recommend
9568 against using it, because it is by far less effective than the other
9569 compression programs@footnote{It also had patent problems in the past.}.
9571 Creating a compressed archive is simple: you just specify a
9572 @dfn{compression option} along with the usual archive creation
9573 commands.  Available compression options are summarized in the
9574 table below:
9576 @multitable @columnfractions 0.4 0.2 0.4
9577 @headitem Long            @tab Short       @tab Archive format
9578 @item @option{--gzip}     @tab @option{-z} @tab @command{gzip}
9579 @item @option{--bzip2}    @tab @option{-j} @tab @command{bzip2}
9580 @item @option{--xz}       @tab @option{-J} @tab @command{xz}
9581 @item @option{--lzip}     @tab             @tab @command{lzip}
9582 @item @option{--lzma}     @tab             @tab @command{lzma}
9583 @item @option{--lzop}     @tab             @tab @command{lzop}
9584 @item @option{--zstd}     @tab             @tab @command{zstd}
9585 @item @option{--compress} @tab @option{-Z} @tab @command{compress}
9586 @end multitable
9588 For example:
9590 @smallexample
9591 $ @kbd{tar czf archive.tar.gz .}
9592 @end smallexample
9594 You can also let @GNUTAR{} select the compression program based on
9595 the suffix of the archive file name. This is done using
9596 @option{--auto-compress} (@option{-a}) command line option. For
9597 example, the following invocation will use @command{bzip2} for
9598 compression:
9600 @smallexample
9601 $ @kbd{tar caf archive.tar.bz2 .}
9602 @end smallexample
9604 @noindent
9605 whereas the following one will use @command{lzma}:
9607 @smallexample
9608 $ @kbd{tar caf archive.tar.lzma .}
9609 @end smallexample
9611 For a complete list of file name suffixes recognized by @GNUTAR{},
9612 see @ref{auto-compress}.
9614 Reading compressed archive is even simpler: you don't need to specify
9615 any additional options as @GNUTAR{} recognizes its format
9616 automatically.  Thus, the following commands will list and extract the
9617 archive created in previous example:
9619 @smallexample
9620 # List the compressed archive
9621 $ @kbd{tar tf archive.tar.gz}
9622 # Extract the compressed archive
9623 $ @kbd{tar xf archive.tar.gz}
9624 @end smallexample
9626 The format recognition algorithm is based on @dfn{signatures}, a
9627 special byte sequences in the beginning of file, that are specific for
9628 certain compression formats.  If this approach fails, @command{tar}
9629 falls back to using archive name suffix to determine its format
9630 (@pxref{auto-compress}, for a list of recognized suffixes).
9632 @anchor{alternative decompression programs}
9633 @cindex alternative decompression programs
9634 Some compression programs are able to handle different compression
9635 formats.  @GNUTAR{} uses this, if the principal decompressor for the
9636 given format is not available.  For example, if @command{compress} is
9637 not installed, @command{tar} will try to use @command{gzip}.  As of
9638 version @value{VERSION} the following alternatives are
9639 tried@footnote{To verbosely trace the decompressor selection, use the
9640 @option{--warning=decompress-program} option
9641 (@pxref{warnings,decompress-program}).}:
9643 @multitable @columnfractions 0.3 0.3 0.3
9644 @headitem Format @tab Main decompressor @tab Alternatives
9645 @item compress @tab compress @tab gzip
9646 @item lzma     @tab lzma     @tab xz
9647 @item bzip2    @tab bzip2    @tab lbzip2
9648 @end multitable
9650 The only case when you have to specify a decompression option while
9651 reading the archive is when reading from a pipe or from a tape drive
9652 that does not support random access.  However, in this case @GNUTAR{}
9653 will indicate which option you should use.  For example:
9655 @smallexample
9656 $ @kbd{cat archive.tar.gz | tar tf -}
9657 tar: Archive is compressed.  Use -z option
9658 tar: Error is not recoverable: exiting now
9659 @end smallexample
9661 If you see such diagnostics, just add the suggested option to the
9662 invocation of @GNUTAR{}:
9664 @smallexample
9665 $ @kbd{cat archive.tar.gz | tar tzf -}
9666 @end smallexample
9668 Notice also, that there are several restrictions on operations on
9669 compressed archives.  First of all, compressed archives cannot be
9670 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
9671 them or delete (@option{--delete}) members from them or
9672 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
9673 cannot append another @command{tar} archive to a compressed archive using
9674 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
9675 archives cannot be compressed.
9677 The following options allow to select a particular compressor program:
9679 @table @option
9680 @opindex gzip
9681 @opindex ungzip
9682 @item -z
9683 @itemx --gzip
9684 @itemx --ungzip
9685 Filter the archive through @command{gzip}.
9687 @opindex xz
9688 @item -J
9689 @itemx --xz
9690 Filter the archive through @code{xz}.
9692 @item -j
9693 @itemx --bzip2
9694 Filter the archive through @code{bzip2}.
9696 @opindex lzip
9697 @item --lzip
9698 Filter the archive through @command{lzip}.
9700 @opindex lzma
9701 @item --lzma
9702 Filter the archive through @command{lzma}.
9704 @opindex lzop
9705 @item --lzop
9706 Filter the archive through @command{lzop}.
9708 @opindex zstd
9709 @item --zstd
9710 Filter the archive through @command{zstd}.
9712 @opindex compress
9713 @opindex uncompress
9714 @item -Z
9715 @itemx --compress
9716 @itemx --uncompress
9717 Filter the archive through @command{compress}.
9718 @end table
9720 When any of these options is given, @GNUTAR{} searches the compressor
9721 binary in the current path and invokes it.  The name of the compressor
9722 program is specified at compilation time using a corresponding
9723 @option{--with-@var{compname}} option to @command{configure}, e.g.
9724 @option{--with-bzip2} to select a specific @command{bzip2} binary.
9725 @xref{lbzip2}, for a detailed discussion.
9727 The output produced by @command{tar --help} shows the actual
9728 compressor names along with each of these options.
9730 You can use any of these options on physical devices (tape drives,
9731 etc.)@: and remote files as well as on normal files; data to or from
9732 such devices or remote files is reblocked by another copy of the
9733 @command{tar} program to enforce the specified (or default) record
9734 size.  The default compression parameters are used.
9735 You can override them by using the @option{-I} option (see
9736 below), e.g.:
9738 @smallexample
9739 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9740 @end smallexample
9742 @noindent
9743 A more traditional way to do this is to use a pipe:
9745 @smallexample
9746 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9747 @end smallexample
9749 @cindex corrupted archives
9750 Compressed archives are easily corrupted, because compressed files
9751 have little redundancy.  The adaptive nature of the
9752 compression scheme means that the compression tables are implicitly
9753 spread all over the archive.  If you lose a few blocks, the dynamic
9754 construction of the compression tables becomes unsynchronized, and there
9755 is little chance that you could recover later in the archive.
9757 Other compression options provide better control over creating
9758 compressed archives.  These are:
9760 @table @option
9761 @anchor{auto-compress}
9762 @opindex auto-compress
9763 @item --auto-compress
9764 @itemx -a
9765 Select a compression program to use by the archive file name
9766 suffix.  The following suffixes are recognized:
9768 @multitable @columnfractions 0.3 0.6
9769 @headitem Suffix @tab Compression program
9770 @item @samp{.gz} @tab @command{gzip}
9771 @item @samp{.tgz} @tab @command{gzip}
9772 @item @samp{.taz} @tab @command{gzip}
9773 @item @samp{.Z} @tab @command{compress}
9774 @item @samp{.taZ} @tab @command{compress}
9775 @item @samp{.bz2} @tab @command{bzip2}
9776 @item @samp{.tz2} @tab @command{bzip2}
9777 @item @samp{.tbz2} @tab @command{bzip2}
9778 @item @samp{.tbz} @tab @command{bzip2}
9779 @item @samp{.lz} @tab @command{lzip}
9780 @item @samp{.lzma} @tab @command{lzma}
9781 @item @samp{.tlz} @tab @command{lzma}
9782 @item @samp{.lzo} @tab @command{lzop}
9783 @item @samp{.xz} @tab @command{xz}
9784 @item @samp{.zst} @tab @command{zstd}
9785 @item @samp{.tzst} @tab @command{zstd}
9786 @end multitable
9788 @anchor{use-compress-program}
9789 @opindex use-compress-program
9790 @item --use-compress-program=@var{command}
9791 @itemx -I=@var{command}
9792 Use external compression program @var{command}.  Use this option if you
9793 want to specify options for the compression program, or if you
9794 are not happy with the compression program associated with the suffix
9795 at compile time, or if you have a compression program that @GNUTAR{}
9796 does not support.  The @var{command} argument is a valid command
9797 invocation, as you would type it at the command line prompt, with any
9798 additional options as needed.  Enclose it in quotes if it contains
9799 white space (@pxref{external, Running External Commands}).
9801 The @var{command} should follow two conventions:
9803 First, when invoked without additional options, it should read data
9804 from standard input, compress it and output it on standard output.
9806 Secondly, if invoked with the additional @option{-d} option, it should
9807 do exactly the opposite, i.e., read the compressed data from the
9808 standard input and produce uncompressed data on the standard output.
9810 The latter requirement means that you must not use the @option{-d}
9811 option as a part of the @var{command} itself.
9812 @end table
9814 @cindex gpg, using with tar
9815 @cindex gnupg, using with tar
9816 @cindex Using encrypted archives
9817 The @option{--use-compress-program} option, in particular, lets you
9818 implement your own filters, not necessarily dealing with
9819 compression/decompression.  For example, suppose you wish to implement
9820 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9821 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9822 Manual}).  The following script does that:
9824 @smallexample
9825 @group
9826 #! /bin/sh
9827 case $1 in
9828 -d) gpg --decrypt - | gzip -d -c;;
9829 '') gzip -c | gpg -s;;
9830 *)  echo "Unknown option $1">&2; exit 1;;
9831 esac
9832 @end group
9833 @end smallexample
9835 Suppose you name it @file{gpgz} and save it somewhere in your
9836 @env{PATH}.  Then the following command will create a compressed
9837 archive signed with your private key:
9839 @smallexample
9840 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9841 @end smallexample
9843 @noindent
9844 Likewise, the command below will list its contents:
9846 @smallexample
9847 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9848 @end smallexample
9850 @ignore
9851 The above is based on the following discussion:
9853      I have one question, or maybe it's a suggestion if there isn't a way
9854      to do it now.  I would like to use @option{--gzip}, but I'd also like
9855      the output to be fed through a program like @acronym{GNU}
9856      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9857      to use :-)), basically adding ECC protection on top of compression.
9858      It seems as if this should be quite easy to do, but I can't work out
9859      exactly how to go about it.  Of course, I can pipe the standard output
9860      of @command{tar} through @command{ecc}, but then I lose (though I
9861      haven't started using it yet, I confess) the ability to have
9862      @command{tar} use @command{rmt} for it's I/O (I think).
9864      I think the most straightforward thing would be to let me specify a
9865      general set of filters outboard of compression (preferably ordered,
9866      so the order can be automatically reversed on input operations, and
9867      with the options they require specifiable), but beggars shouldn't be
9868      choosers and anything you decide on would be fine with me.
9870      By the way, I like @command{ecc} but if (as the comments say) it can't
9871      deal with loss of block sync, I'm tempted to throw some time at adding
9872      that capability.  Supposing I were to actually do such a thing and
9873      get it (apparently) working, do you accept contributed changes to
9874      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9876   Isn't that exactly the role of the
9877   @option{--use-compress-prog=@var{program}} option?
9878   I never tried it myself, but I suspect you may want to write a
9879   @var{prog} script or program able to filter stdin to stdout to
9880   way you want.  It should recognize the @option{-d} option, for when
9881   extraction is needed rather than creation.
9883   It has been reported that if one writes compressed data (through the
9884   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9885   the DLT compression mode, the data will actually get bigger and one will
9886   end up with less space on the tape.
9887 @end ignore
9889 @menu
9890 * lbzip2::  Using lbzip2 with @GNUTAR{}.
9891 @end menu
9893 @node lbzip2
9894 @subsubsection Using lbzip2 with @GNUTAR{}.
9895 @cindex lbzip2
9896 @cindex Laszlo Ersek
9897   @command{Lbzip2} is a multithreaded utility for handling
9898 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
9899 multiple processors to speed up its operation and in general works
9900 considerably faster than @command{bzip2}.  For a detailed description
9901 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9902 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9903 lbzip2: parallel bzip2 utility}.
9905   Recent versions of @command{lbzip2} are mostly command line compatible
9906 with @command{bzip2}, which makes it possible to automatically invoke
9907 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
9908 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9909 line option, like this:
9911 @smallexample
9912 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9913 @end smallexample
9915   Once configured and compiled this way, @command{tar --help} will show the
9916 following:
9918 @smallexample
9919 @group
9920 $ @kbd{tar --help | grep -- --bzip2}
9921   -j, --bzip2                filter the archive through lbzip2
9922 @end group
9923 @end smallexample
9925 @noindent
9926 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9928 @node sparse
9929 @subsection Archiving Sparse Files
9930 @cindex Sparse Files
9932 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
9933 in a file is a section of the file's contents which was never written.
9934 The contents of a hole reads as all zeros.  On many operating systems,
9935 actual disk storage is not allocated for holes, but they are counted
9936 in the length of the file.  If you archive such a file, @command{tar}
9937 could create an archive longer than the original.  To have @command{tar}
9938 attempt to recognize the holes in a file, use @option{--sparse}
9939 (@option{-S}).  When you use this option, then, for any file using
9940 less disk space than would be expected from its length, @command{tar}
9941 searches the file for holes.  It then records in the archive for the file where
9942 the holes (consecutive stretches of zeros) are, and only archives the
9943 ``real contents'' of the file.  On extraction (using @option{--sparse} is not
9944 needed on extraction) any such files have also holes created wherever the holes
9945 were found.  Thus, if you use @option{--sparse}, @command{tar} archives won't
9946 take more space than the original.
9948 @GNUTAR{} uses two methods for detecting holes in sparse files.  These
9949 methods are described later in this subsection.
9951 @table @option
9952 @opindex sparse
9953 @item -S
9954 @itemx --sparse
9955 This option instructs @command{tar} to test each file for sparseness
9956 before attempting to archive it.  If the file is found to be sparse it
9957 is treated specially, thus allowing to decrease the amount of space
9958 used by its image in the archive.
9960 This option is meaningful only when creating or updating archives.  It
9961 has no effect on extraction.
9962 @end table
9964 Consider using @option{--sparse} when performing file system backups,
9965 to avoid archiving the expanded forms of files stored sparsely in the
9966 system.
9968 Even if your system has no sparse files currently, some may be
9969 created in the future.  If you use @option{--sparse} while making file
9970 system backups as a matter of course, you can be assured the archive
9971 will never take more space on the media than the files take on disk
9972 (otherwise, archiving a disk filled with sparse files might take
9973 hundreds of tapes).  @xref{Incremental Dumps}.
9975 However, be aware that @option{--sparse} option may present a serious
9976 drawback.  Namely, in order to determine the positions of holes in a file
9977 @command{tar} may have to read it before trying to archive it, so in total
9978 the file may be read @strong{twice}.  This may happen when your OS or your FS
9979 does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
9980 @option{--hole-detection}, below).
9982 @cindex sparse formats, defined
9983 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9984 sparse files using in three distinct ways, called @dfn{sparse
9985 formats}.  A sparse format is identified by its @dfn{number},
9986 consisting, as usual of two decimal numbers, delimited by a dot.  By
9987 default, format @samp{1.0} is used.  If, for some reason, you wish to
9988 use an earlier format, you can select it using
9989 @option{--sparse-version} option.
9991 @table @option
9992 @opindex sparse-version
9993 @item --sparse-version=@var{version}
9994 Select the format to store sparse files in.  Valid @var{version} values
9995 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
9996 for a detailed description of each format.
9997 @end table
9999 Using @option{--sparse-format} option implies @option{--sparse}.
10001 @table @option
10002 @opindex hole-detection
10003 @cindex hole detection
10004 @item --hole-detection=@var{method}
10005 Enforce concrete hole detection method.  Before the real contents of sparse
10006 file are stored, @command{tar} needs to gather knowledge about file
10007 sparseness.  This is because it needs to have the file's map of holes
10008 stored into tar header before it starts archiving the file contents.
10009 Currently, two methods of hole detection are implemented:
10011 @itemize @bullet
10012 @item @option{--hole-detection=seek}
10013 Seeking the file for data and holes.  It uses enhancement of the @code{lseek}
10014 system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
10015 reuse file system knowledge about sparse file contents - so the
10016 detection is usually very fast.  To use this feature, your file system
10017 and operating system must support it.  At the time of this writing
10018 (2015) this feature, in spite of not being accepted by POSIX, is
10019 fairly widely supported by different operating systems.
10021 @item @option{--hole-detection=raw}
10022 Reading byte-by-byte the whole sparse file before the archiving.  This
10023 method detects holes like consecutive stretches of zeroes.  Comparing to
10024 the previous method, it is usually much slower, although more
10025 portable.
10026 @end itemize
10027 @end table
10029 When no @option{--hole-detection} option is given, @command{tar} uses
10030 the @samp{seek}, if supported by the operating system.
10032 Using @option{--hole-detection} option implies @option{--sparse}.
10034 @node Attributes
10035 @section Handling File Attributes
10036 @cindex attributes, files
10037 @cindex file attributes
10039 When @command{tar} reads files, it updates their access times.  To
10040 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
10041 reset the access time retroactively or avoid changing it in the first
10042 place.
10044 @table @option
10045 @opindex atime-preserve
10046 @item --atime-preserve
10047 @itemx --atime-preserve=replace
10048 @itemx --atime-preserve=system
10049 Preserve the access times of files that are read.  This works only for
10050 files that you own, unless you have superuser privileges.
10052 @option{--atime-preserve=replace} works on most systems, but it also
10053 restores the data modification time and updates the status change
10054 time.  Hence it doesn't interact with incremental dumps nicely
10055 (@pxref{Incremental Dumps}), and it can set access or data modification times
10056 incorrectly if other programs access the file while @command{tar} is
10057 running.
10059 @option{--atime-preserve=system} avoids changing the access time in
10060 the first place, if the operating system supports this.
10061 Unfortunately, this may or may not work on any given operating system
10062 or file system.  If @command{tar} knows for sure it won't work, it
10063 complains right away.
10065 Currently @option{--atime-preserve} with no operand defaults to
10066 @option{--atime-preserve=replace}, but this is intended to change to
10067 @option{--atime-preserve=system} when the latter is better-supported.
10069 @opindex touch
10070 @item -m
10071 @itemx --touch
10072 Do not extract data modification time.
10074 When this option is used, @command{tar} leaves the data modification times
10075 of the files it extracts as the times when the files were extracted,
10076 instead of setting it to the times recorded in the archive.
10078 This option is meaningless with @option{--list} (@option{-t}).
10080 @opindex same-owner
10081 @item --same-owner
10082 Create extracted files with the same ownership they have in the
10083 archive.
10085 This is the default behavior for the superuser,
10086 so this option is meaningful only for non-root users, when @command{tar}
10087 is executed on those systems able to give files away.  This is
10088 considered as a security flaw by many people, at least because it
10089 makes quite difficult to correctly account users for the disk space
10090 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
10091 files are easily and silently lost when files are given away.
10093 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
10094 separately.  If it can't find a user name (because the user @acronym{ID} is not
10095 in @file{/etc/passwd}), then it does not write one.  When restoring,
10096 it tries to look the name (if one was written) up in
10097 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
10098 the archive instead.
10100 @opindex no-same-owner
10101 @item --no-same-owner
10102 @itemx -o
10103 Do not attempt to restore ownership when extracting.  This is the
10104 default behavior for ordinary users, so this option has an effect
10105 only for the superuser.
10107 @opindex numeric-owner
10108 @item --numeric-owner
10109 The @option{--numeric-owner} option allows (ANSI) archives to be written
10110 without user/group name information or such information to be ignored
10111 when extracting.  It effectively disables the generation and/or use
10112 of user/group name information.  This option forces extraction using
10113 the numeric ids from the archive, ignoring the names.
10115 This is useful in certain circumstances, when restoring a backup from
10116 an emergency floppy with different passwd/group files for example.
10117 It is otherwise impossible to extract files with the right ownerships
10118 if the password file in use during the extraction does not match the
10119 one belonging to the file system(s) being extracted.  This occurs,
10120 for example, if you are restoring your files after a major crash and
10121 had booted from an emergency floppy with no password file or put your
10122 disk into another machine to do the restore.
10124 The numeric ids are @emph{always} saved into @command{tar} archives.
10125 The identifying names are added at create time when provided by the
10126 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
10127 used when moving archives between a collection of machines using
10128 a centralized management for attribution of numeric ids to users
10129 and groups.  This is often made through using the NIS capabilities.
10131 When making a @command{tar} file for distribution to other sites, it
10132 is sometimes cleaner to use a single owner for all files in the
10133 distribution, and nicer to specify the write permission bits of the
10134 files as stored in the archive independently of their actual value on
10135 the file system.  The way to prepare a clean distribution is usually
10136 to have some Makefile rule creating a directory, copying all needed
10137 files in that directory, then setting ownership and permissions as
10138 wanted (there are a lot of possible schemes), and only then making a
10139 @command{tar} archive out of this directory, before cleaning
10140 everything out.  Of course, we could add a lot of options to
10141 @GNUTAR{} for fine tuning permissions and ownership.
10142 This is not the good way, I think.  @GNUTAR{} is
10143 already crowded with options and moreover, the approach just explained
10144 gives you a great deal of control already.
10146 @xopindex{same-permissions, short description}
10147 @xopindex{preserve-permissions, short description}
10148 @item -p
10149 @itemx --same-permissions
10150 @itemx --preserve-permissions
10151 Extract all protection information.
10153 This option causes @command{tar} to set the modes (access permissions) of
10154 extracted files exactly as recorded in the archive.  If this option
10155 is not used, the current @code{umask} setting limits the permissions
10156 on extracted files.  This option is by default enabled when
10157 @command{tar} is executed by a superuser.
10160 This option is meaningless with @option{--list} (@option{-t}).
10161 @end table
10163 @node Portability
10164 @section Making @command{tar} Archives More Portable
10166 Creating a @command{tar} archive on a particular system that is meant to be
10167 useful later on many other machines and with other versions of @command{tar}
10168 is more challenging than you might think.  @command{tar} archive formats
10169 have been evolving since the first versions of Unix.  Many such formats
10170 are around, and are not always compatible with each other.  This section
10171 discusses a few problems, and gives some advice about making @command{tar}
10172 archives more portable.
10174 One golden rule is simplicity.  For example, limit your @command{tar}
10175 archives to contain only regular files and directories, avoiding
10176 other kind of special files.  Do not attempt to save sparse files or
10177 contiguous files as such.  Let's discuss a few more problems, in turn.
10179 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
10180 archives and archive labels) in GNU and PAX formats.}
10182 @menu
10183 * Portable Names::              Portable Names
10184 * dereference::                 Symbolic Links
10185 * hard links::                  Hard Links
10186 * old::                         Old V7 Archives
10187 * ustar::                       Ustar Archives
10188 * gnu::                         GNU and old GNU format archives.
10189 * posix::                       @acronym{POSIX} archives
10190 * Checksumming::                Checksumming Problems
10191 * Large or Negative Values::    Large files, negative time stamps, etc.
10192 * Other Tars::                  How to Extract GNU-Specific Data Using
10193                                 Other @command{tar} Implementations
10194 @end menu
10196 @node Portable Names
10197 @subsection Portable Names
10199 Use portable file and member names.  A name is portable if it contains
10200 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
10201 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
10202 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
10203 old Unix hosts, limit your file name components to 14 characters or
10204 less.
10206 If you intend to have your @command{tar} archives to be read on
10207 case-insensitive file systems like FAT32,
10208 you should not rely on case distinction for file names.
10210 @node dereference
10211 @subsection Symbolic Links
10212 @cindex File names, using symbolic links
10213 @cindex Symbolic link as file name
10215 @opindex dereference
10216 Normally, when @command{tar} archives a symbolic link, it writes a
10217 block to the archive naming the target of the link.  In that way, the
10218 @command{tar} archive is a faithful record of the file system contents.
10219 When @option{--dereference} (@option{-h}) is used with
10220 @option{--create} (@option{-c}), @command{tar} archives the files
10221 symbolic links point to, instead of
10222 the links themselves.
10224 When creating portable archives, use @option{--dereference}
10225 (@option{-h}): some systems do not support
10226 symbolic links, and moreover, your distribution might be unusable if
10227 it contains unresolved symbolic links.
10229 When reading from an archive, the @option{--dereference} (@option{-h})
10230 option causes @command{tar} to follow an already-existing symbolic
10231 link when @command{tar} writes or reads a file named in the archive.
10232 Ordinarily, @command{tar} does not follow such a link, though it may
10233 remove the link before writing a new file.  @xref{Dealing with Old
10234 Files}.
10236 The @option{--dereference} option is unsafe if an untrusted user can
10237 modify directories while @command{tar} is running.  @xref{Security}.
10239 @node hard links
10240 @subsection Hard Links
10241 @cindex File names, using hard links
10242 @cindex hard links, dereferencing
10243 @cindex dereferencing hard links
10245 Normally, when @command{tar} archives a hard link, it writes a
10246 block to the archive naming the target of the link (a @samp{1} type
10247 block).  In that way, the actual file contents is stored in file only
10248 once.  For example, consider the following two files:
10250 @smallexample
10251 @group
10252 $ ls -l
10253 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
10254 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
10255 @end group
10256 @end smallexample
10258 Here, @file{jeden} is a link to @file{one}.  When archiving this
10259 directory with a verbose level 2, you will get an output similar to
10260 the following:
10262 @smallexample
10263 $ tar cvvf ../archive.tar .
10264 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10265 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10266 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
10267 @end smallexample
10269 The last line shows that, instead of storing two copies of the file,
10270 @command{tar} stored it only once, under the name @file{jeden}, and
10271 stored file @file{one} as a hard link to this file.
10273 It may be important to know that all hard links to the given file are
10274 stored in the archive.  For example, this may be necessary for exact
10275 reproduction of the file system.  The following option does that:
10277 @table @option
10278 @xopindex{check-links, described}
10279 @item --check-links
10280 @itemx -l
10281 Check the number of links dumped for each processed file.  If this
10282 number does not match the total number of hard links for the file, print
10283 a warning message.
10284 @end table
10286 For example, trying to archive only file @file{jeden} with this option
10287 produces the following diagnostics:
10289 @smallexample
10290 $ tar -c -f ../archive.tar -l jeden
10291 tar: Missing links to 'jeden'.
10292 @end smallexample
10294 Although creating special records for hard links helps keep a faithful
10295 record of the file system contents and makes archives more compact, it
10296 may present some difficulties when extracting individual members from
10297 the archive.  For example, trying to extract file @file{one} from the
10298 archive created in previous examples produces, in the absence of file
10299 @file{jeden}:
10301 @smallexample
10302 $ tar xf archive.tar ./one
10303 tar: ./one: Cannot hard link to './jeden': No such file or directory
10304 tar: Error exit delayed from previous errors
10305 @end smallexample
10307 The reason for this behavior is that @command{tar} cannot seek back in
10308 the archive to the previous member (in this case, @file{one}), to
10309 extract it@footnote{There are plans to fix this in future releases.}.
10310 If you wish to avoid such problems at the cost of a bigger archive,
10311 use the following option:
10313 @table @option
10314 @xopindex{hard-dereference, described}
10315 @item --hard-dereference
10316 Dereference hard links and store the files they refer to.
10317 @end table
10319 For example, trying this option on our two sample files, we get two
10320 copies in the archive, each of which can then be extracted
10321 independently of the other:
10323 @smallexample
10324 @group
10325 $ tar -c -vv -f ../archive.tar --hard-dereference .
10326 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10327 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10328 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
10329 @end group
10330 @end smallexample
10332 @node old
10333 @subsection Old V7 Archives
10334 @cindex Format, old style
10335 @cindex Old style format
10336 @cindex Old style archives
10337 @cindex v7 archive format
10339 Certain old versions of @command{tar} cannot handle additional
10340 information recorded by newer @command{tar} programs.  To create an
10341 archive in V7 format (not ANSI), which can be read by these old
10342 versions, specify the @option{--format=v7} option in
10343 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
10344 accepts @option{--portability} or @option{--old-archive} for this
10345 option).  When you specify it,
10346 @command{tar} leaves out information about directories, pipes, fifos,
10347 contiguous files, and device files, and specifies file ownership by
10348 group and user IDs instead of group and user names.
10350 When updating an archive, do not use @option{--format=v7}
10351 unless the archive was created using this option.
10353 In most cases, a @emph{new} format archive can be read by an @emph{old}
10354 @command{tar} program without serious trouble, so this option should
10355 seldom be needed.  On the other hand, most modern @command{tar}s are
10356 able to read old format archives, so it might be safer for you to
10357 always use @option{--format=v7} for your distributions.  Notice,
10358 however, that @samp{ustar} format is a better alternative, as it is
10359 free from many of @samp{v7}'s drawbacks.
10361 @node ustar
10362 @subsection Ustar Archive Format
10364 @cindex ustar archive format
10365 The archive format defined by the @acronym{POSIX}.1-1988 specification is
10366 called @code{ustar}.  Although it is more flexible than the V7 format, it
10367 still has many restrictions (@pxref{Formats,ustar}, for the detailed
10368 description of @code{ustar} format).  Along with V7 format,
10369 @code{ustar} format is a good choice for archives intended to be read
10370 with other implementations of @command{tar}.
10372 To create an archive in @code{ustar} format, use the @option{--format=ustar}
10373 option in conjunction with @option{--create} (@option{-c}).
10375 @node gnu
10376 @subsection @acronym{GNU} and old @GNUTAR{} format
10378 @cindex GNU archive format
10379 @cindex Old GNU archive format
10380 @GNUTAR{} was based on an early draft of the
10381 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
10382 @command{tar}, such as the support for file names longer than 100
10383 characters, use portions of the @command{tar} header record which were
10384 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
10385 @acronym{POSIX} have allocated the same parts of the header record for
10386 other purposes.  As a result, @GNUTAR{} format is
10387 incompatible with the current @acronym{POSIX} specification, and with
10388 @command{tar} programs that follow it.
10390 In the majority of cases, @command{tar} will be configured to create
10391 this format by default.  This will change in future releases, since
10392 we plan to make @samp{POSIX} format the default.
10394 To force creation a @GNUTAR{} archive, use option
10395 @option{--format=gnu}.
10397 @node posix
10398 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
10400 @cindex POSIX archive format
10401 @cindex PAX archive format
10402 Starting from version 1.14 @GNUTAR{} features full support for
10403 @acronym{POSIX.1-2001} archives.
10405 A @acronym{POSIX} conformant archive will be created if @command{tar}
10406 was given @option{--format=posix} (@option{--format=pax}) option.  No
10407 special option is required to read and extract from a @acronym{POSIX}
10408 archive.
10410 @menu
10411 * PAX keywords:: Controlling Extended Header Keywords.
10412 @end menu
10414 @node PAX keywords
10415 @subsubsection Controlling Extended Header Keywords
10417 @table @option
10418 @opindex pax-option
10419 @item --pax-option=@var{keyword-list}
10420 Handle keywords in @acronym{PAX} extended headers.  This option is
10421 equivalent to @option{-o} option of the @command{pax} utility.
10422 @end table
10424 @var{Keyword-list} is a comma-separated
10425 list of keyword options, each keyword option taking one of
10426 the following forms:
10428 @table @code
10429 @item delete=@var{pattern}
10430 When used with one of archive-creation commands,
10431 this option instructs @command{tar} to omit from extended header records
10432 that it produces any keywords matching the string @var{pattern}.
10433 If the pattern contains shell metacharacters like @samp{*}, it should
10434 be quoted to prevent the shell from expanding the pattern before
10435 @command{tar} sees it.
10437 When used in extract or list mode, this option instructs tar
10438 to ignore any keywords matching the given @var{pattern} in the extended
10439 header records.  In both cases, matching is performed using the pattern
10440 matching notation described in @acronym{POSIX 1003.2}, 3.13
10441 (@pxref{wildcards}).  For example:
10443 @smallexample
10444 --pax-option 'delete=security.*'
10445 @end smallexample
10447 would suppress security-related information.
10449 @item exthdr.name=@var{string}
10451 This keyword allows user control over the name that is written into the
10452 ustar header blocks for the extended headers.  The name is obtained
10453 from @var{string} after making the following substitutions:
10455 @multitable @columnfractions .25 .55
10456 @headitem Meta-character @tab Replaced By
10457 @item %d @tab  The directory name of the file, equivalent to the
10458 result of the @command{dirname} utility on the translated file name.
10459 @item %f @tab  The name of the file with the directory information
10460 stripped, equivalent to the result of the @command{basename} utility
10461 on the translated file name.
10462 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
10463 @item %% @tab  A @samp{%} character.
10464 @end multitable
10466 Any other @samp{%} characters in @var{string} produce undefined
10467 results.
10469 If no option @samp{exthdr.name=string} is specified, @command{tar}
10470 will use the following default value:
10472 @smallexample
10473 %d/PaxHeaders/%f
10474 @end smallexample
10476 This default is selected to ensure the reproducibility of the
10477 archive. @acronym{POSIX} standard recommends to use
10478 @samp{%d/PaxHeaders.%p/%f} instead, which means the two archives
10479 created with the same set of options and containing the same set
10480 of files will be byte-to-byte different. This default will be used
10481 if the environment variable @env{POSIXLY_CORRECT} is set.
10483 @item exthdr.mtime=@var{value}
10485 This keyword defines the value of the @samp{mtime} field that
10486 is written into the ustar header blocks for the extended headers.
10487 By default, the @samp{mtime} field is set to the modification time
10488 of the archive member described by that extended header (or to the
10489 value of the @option{--mtime} option, if supplied).
10491 @item globexthdr.name=@var{string}
10492 This keyword allows user control over the name that is written into
10493 the ustar header blocks for global extended header records.  The name
10494 is obtained from the contents of @var{string}, after making
10495 the following substitutions:
10497 @multitable @columnfractions .25 .55
10498 @headitem Meta-character @tab Replaced By
10499 @item %n @tab An integer that represents the
10500 sequence number of the global extended header record in the archive,
10501 starting at 1.
10502 @item %p @tab The process @acronym{ID} of the @command{tar} process.
10503 @item %% @tab A @samp{%} character.
10504 @end multitable
10506 Any other @samp{%} characters in @var{string} produce undefined results.
10508 If no option @samp{globexthdr.name=string} is specified, @command{tar}
10509 will use the following default value:
10511 @smallexample
10512 $TMPDIR/GlobalHead.%n
10513 @end smallexample
10515 If the environment variable @env{POSIXLY_CORRECT} is set, the
10516 following value is used instead:
10518 @smallexample
10519 $TMPDIR/GlobalHead.%p.%n
10520 @end smallexample
10522 In both cases, @samp{$TMPDIR} stands for the value of the @var{TMPDIR}
10523 environment variable.  If @var{TMPDIR} is not set, @command{tar}
10524 uses @samp{/tmp}.
10526 @item globexthdr.mtime=@var{value}
10528 This keyword defines the value of the @samp{mtime} field that
10529 is written into the ustar header blocks for the global extended headers.
10530 By default, the @samp{mtime} field is set to the time when
10531 @command{tar} was invoked.
10533 @item @var{keyword}=@var{value}
10534 When used with one of archive-creation commands, these keyword/value pairs
10535 will be included at the beginning of the archive in a global extended
10536 header record.  When used with one of archive-reading commands,
10537 @command{tar} will behave as if it has encountered these keyword/value
10538 pairs at the beginning of the archive in a global extended header
10539 record.
10541 @item @var{keyword}:=@var{value}
10542 When used with one of archive-creation commands, these keyword/value pairs
10543 will be included as records at the beginning of an extended header for
10544 each file.  This is effectively equivalent to @var{keyword}=@var{value}
10545 form except that it creates no global extended header records.
10547 When used with one of archive-reading commands, @command{tar} will
10548 behave as if these keyword/value pairs were included as records at the
10549 end of each extended header; thus, they will override any global or
10550 file-specific extended header record keywords of the same names.
10551 For example, in the command:
10553 @smallexample
10554 tar --format=posix --create \
10555     --file archive --pax-option gname:=user .
10556 @end smallexample
10558 the group name will be forced to a new value for all files
10559 stored in the archive.
10560 @end table
10562 In any of the forms described above, the @var{value} may be
10563 a string enclosed in curly braces.  In that case, the string
10564 between the braces is understood either as a textual time
10565 representation, as described in @ref{Date input formats}, or a name of
10566 the existing file, starting with @samp{/} or @samp{.}.  In the latter
10567 case, the modification time of that file is used.
10569 For example, to set all modification times to the current date, you
10570 use the following option:
10572 @smallexample
10573 --pax-option 'mtime:=@{now@}'
10574 @end smallexample
10576 @cindex archives, binary equivalent
10577 @cindex binary equivalent archives, creating
10578 As another example, here is the option that ensures that any two
10579 archives created using it, will be binary equivalent if they have the
10580 same contents:
10582 @smallexample
10583 --pax-option delete=atime
10584 @end smallexample
10586 @noindent
10587 If you extract files from such an archive and recreate the archive
10588 from them, you will also need to eliminate changes due to ctime:
10590 @smallexample
10591 --pax-option 'delete=atime,delete=ctime'
10592 @end smallexample
10594 Normally @command{tar} saves an mtime value with subsecond resolution
10595 in an extended header for any file with a timestamp that is not on a
10596 one-second boundary.  This is in addition to the traditional mtime
10597 timestamp in the header block.  Although you can suppress subsecond
10598 timestamp resolution with @option{--pax-option delete=mtime},
10599 this hack will not work for timestamps before 1970 or after 2242-03-16
10600 12:56:31 @sc{utc}.
10602 If the environment variable @env{POSIXLY_CORRECT} is set, two POSIX
10603 archives created using the same options on the same set of files might
10604 not be byte-to-byte equivalent even with the above options.  This is
10605 because the POSIX default for extended header names includes
10606 the @command{tar} process @acronym{ID}, which typically differs at each
10607 run.  To produce byte-to-byte equivalent archives in this case, either
10608 unset @env{POSIXLY_CORRECT}, or use the following option, which can be
10609 combined with the above options:
10611 @smallexample
10612 --pax-option exthdr.name=%d/PaxHeaders/%f
10613 @end smallexample
10615 @node Checksumming
10616 @subsection Checksumming Problems
10618 SunOS and HP-UX @command{tar} fail to accept archives created using
10619 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
10620 is, file names having characters with the eighth bit set, because they
10621 use signed checksums, while @GNUTAR{} uses unsigned
10622 checksums while creating archives, as per @acronym{POSIX} standards.  On
10623 reading, @GNUTAR{} computes both checksums and accepts either of them.
10624 It is somewhat worrying that a lot of people may go
10625 around doing backup of their files using faulty (or at least
10626 non-standard) software, not learning about it until it's time to
10627 restore their missing files with an incompatible file extractor, or
10628 vice versa.
10630 @GNUTAR{} computes checksums both ways, and accepts either of them
10631 on read, so @acronym{GNU} tar can read Sun tapes even with their
10632 wrong checksums.  @GNUTAR{} produces the standard
10633 checksum, however, raising incompatibilities with Sun.  That is to
10634 say, @GNUTAR{} has not been modified to
10635 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
10636 I've been told that more recent Sun @command{tar} now read standard
10637 archives, so maybe Sun did a similar patch, after all?
10639 The story seems to be that when Sun first imported @command{tar}
10640 sources on their system, they recompiled it without realizing that
10641 the checksums were computed differently, because of a change in
10642 the default signing of @code{char}'s in their compiler.  So they
10643 started computing checksums wrongly.  When they later realized their
10644 mistake, they merely decided to stay compatible with it, and with
10645 themselves afterwards.  Presumably, but I do not really know, HP-UX
10646 has chosen their @command{tar} archives to be compatible with Sun's.
10647 The current standards do not favor Sun @command{tar} format.  In any
10648 case, it now falls on the shoulders of SunOS and HP-UX users to get
10649 a @command{tar} able to read the good archives they receive.
10651 @node Large or Negative Values
10652 @subsection Large or Negative Values
10653 @cindex large values
10654 @cindex future time stamps
10655 @cindex negative time stamps
10656 @UNREVISED{}
10658 The above sections suggest to use @samp{oldest possible} archive
10659 format if in doubt.  However, sometimes it is not possible.  If you
10660 attempt to archive a file whose metadata cannot be represented using
10661 required format, @GNUTAR{} will print error message and ignore such a
10662 file.  You will than have to switch to a format that is able to
10663 handle such values.  The format summary table (@pxref{Formats}) will
10664 help you to do so.
10666 In particular, when trying to archive files larger than 8GB or with
10667 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
10668 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
10669 @acronym{POSIX} archive formats.  When considering which format to
10670 choose, bear in mind that the @acronym{GNU} format uses
10671 two's-complement base-256 notation to store values that do not fit
10672 into standard @acronym{ustar} range.  Such archives can generally be
10673 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
10674 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
10675 example, using two's complement representation for negative time
10676 stamps that assumes a signed 32-bit @code{time_t} generates archives
10677 that are not portable to hosts with differing @code{time_t}
10678 representations.
10680 On the other hand, @acronym{POSIX} archives, generally speaking, can
10681 be extracted by any tar implementation that understands older
10682 @acronym{ustar} format.  The only exception are files larger than 8GB.
10684 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
10685 POSIX-aware tars.}
10687 @node Other Tars
10688 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
10690 In previous sections you became acquainted with various quirks
10691 necessary to make your archives portable.  Sometimes you may need to
10692 extract archives containing GNU-specific members using some
10693 third-party @command{tar} implementation or an older version of
10694 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
10695 but if it is for some reason impossible, this section will explain
10696 how to cope without it.
10698 When we speak about @dfn{GNU-specific} members we mean two classes of
10699 them: members split between the volumes of a multi-volume archive and
10700 sparse members.  You will be able to always recover such members if
10701 the archive is in PAX format.  In addition split members can be
10702 recovered from archives in old GNU format.  The following subsections
10703 describe the required procedures in detail.
10705 @menu
10706 * Split Recovery::       Members Split Between Volumes
10707 * Sparse Recovery::      Sparse Members
10708 @end menu
10710 @node Split Recovery
10711 @subsubsection Extracting Members Split Between Volumes
10713 @cindex Multi-volume archives, extracting using non-GNU tars
10714 If a member is split between several volumes of an old GNU format archive
10715 most third party @command{tar} implementation will fail to extract
10716 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
10717 This program is available from
10718 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
10719 home page}.  It concatenates several archive volumes into a single
10720 valid archive.  For example, if you have three volumes named from
10721 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
10722 extract them using a third-party @command{tar}:
10724 @smallexample
10725 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
10726 @end smallexample
10728 @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
10729 You could use this approach for most (although not all) PAX
10730 format archives as well.  However, extracting split members from a PAX
10731 archive is a much easier task, because PAX volumes are constructed in
10732 such a way that each part of a split member is extracted to a
10733 different file by @command{tar} implementations that are not aware of
10734 GNU extensions.  More specifically, the very first part retains its
10735 original name, and all subsequent parts are named using the pattern:
10737 @smallexample
10738 %d/GNUFileParts/%f.%n
10739 @end smallexample
10741 @noindent
10742 where symbols preceded by @samp{%} are @dfn{macro characters} that
10743 have the following meaning:
10745 @multitable @columnfractions .25 .55
10746 @headitem Meta-character @tab Replaced By
10747 @item %d @tab  The directory name of the file, equivalent to the
10748 result of the @command{dirname} utility on its full name.
10749 @item %f @tab  The file name of the file, equivalent to the result
10750 of the @command{basename} utility on its full name.
10751 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
10752 created the archive.
10753 @item %n @tab  Ordinal number of this particular part.
10754 @end multitable
10756 For example, if the file @file{var/longfile} was split during archive
10757 creation between three volumes, then the member names will be:
10759 @smallexample
10760 var/longfile
10761 var/GNUFileParts/longfile.1
10762 var/GNUFileParts/longfile.2
10763 @end smallexample
10765 When you extract your archive using a third-party @command{tar}, these
10766 files will be created on your disk, and the only thing you will need
10767 to do to restore your file in its original form is concatenate them in
10768 the proper order, for example:
10770 @smallexample
10771 @group
10772 $ @kbd{cd var}
10773 $ @kbd{cat GNUFileParts/longfile.1 \
10774   GNUFileParts/longfile.2 >> longfile}
10775 $ rm -f GNUFileParts
10776 @end group
10777 @end smallexample
10779 Notice, that if the @command{tar} implementation you use supports PAX
10780 format archives, it will probably emit warnings about unknown keywords
10781 during extraction.  They will look like this:
10783 @smallexample
10784 @group
10785 Tar file too small
10786 Unknown extended header keyword 'GNU.volume.filename' ignored.
10787 Unknown extended header keyword 'GNU.volume.size' ignored.
10788 Unknown extended header keyword 'GNU.volume.offset' ignored.
10789 @end group
10790 @end smallexample
10792 @noindent
10793 You can safely ignore these warnings.
10795 If your @command{tar} implementation is not PAX-aware, you will get
10796 more warnings and more files generated on your disk, e.g.:
10798 @smallexample
10799 @group
10800 $ @kbd{tar xf vol-1.tar}
10801 var/PaxHeaders/longfile: Unknown file type 'x', extracted as
10802 normal file
10803 Unexpected EOF in archive
10804 $ @kbd{tar xf vol-2.tar}
10805 tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file
10806 GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type
10807 'x', extracted as normal file
10808 @end group
10809 @end smallexample
10811 Ignore these warnings.  The @file{PaxHeaders.*} directories created
10812 will contain files with @dfn{extended header keywords} describing the
10813 extracted files.  You can delete them, unless they describe sparse
10814 members.  Read further to learn more about them.
10816 @node Sparse Recovery
10817 @subsubsection Extracting Sparse Members
10819 @cindex sparse files, extracting with non-GNU tars
10820 Any @command{tar} implementation will be able to extract sparse members from a
10821 PAX archive.  However, the extracted files will be @dfn{condensed},
10822 i.e., any zero blocks will be removed from them.  When we restore such
10823 a condensed file to its original form, by adding zero blocks (or
10824 @dfn{holes}) back to their original locations, we call this process
10825 @dfn{expanding} a compressed sparse file.
10827 @pindex xsparse
10828 To expand a file, you will need a simple auxiliary program called
10829 @command{xsparse}.  It is available in source form from
10830 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10831 home page}.
10833 @cindex sparse files v.1.0, extracting with non-GNU tars
10834 Let's begin with archive members in @dfn{sparse format
10835 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10836 The condensed file will contain both file map and file data, so no
10837 additional data will be needed to restore it.  If the original file
10838 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10839 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10840 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10841 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10842 archive (@pxref{PAX keywords}).}.
10844 To expand a version 1.0 file, run @command{xsparse} as follows:
10846 @smallexample
10847 $ @kbd{xsparse @file{cond-file}}
10848 @end smallexample
10850 @noindent
10851 where @file{cond-file} is the name of the condensed file.  The utility
10852 will deduce the name for the resulting expanded file using the
10853 following algorithm:
10855 @enumerate 1
10856 @item If @file{cond-file} does not contain any directories,
10857 @file{../cond-file} will be used;
10859 @item If @file{cond-file} has the form
10860 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10861 are simple names, with no @samp{/} characters in them, the output file
10862 name will be @file{@var{dir}/@var{name}}.
10864 @item Otherwise, if @file{cond-file} has the form
10865 @file{@var{dir}/@var{name}}, the output file name will be
10866 @file{@var{name}}.
10867 @end enumerate
10869 In the unlikely case when this algorithm does not suit your needs,
10870 you can explicitly specify output file name as a second argument to
10871 the command:
10873 @smallexample
10874 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10875 @end smallexample
10877 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10878 first.  In this mode, the command does not actually expand the file,
10879 but verbosely lists all actions it would be taking to do so.  The dry
10880 run mode is enabled by @option{-n} command line argument:
10882 @smallexample
10883 @group
10884 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10885 Reading v.1.0 sparse map
10886 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10887 '/home/gray/sparsefile'
10888 Finished dry run
10889 @end group
10890 @end smallexample
10892 To actually expand the file, you would run:
10894 @smallexample
10895 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10896 @end smallexample
10898 @noindent
10899 The program behaves the same way all UNIX utilities do: it will keep
10900 quiet unless it has something important to tell you (e.g. an error
10901 condition or something).  If you wish it to produce verbose output,
10902 similar to that from the dry run mode, use @option{-v} option:
10904 @smallexample
10905 @group
10906 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10907 Reading v.1.0 sparse map
10908 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10909 '/home/gray/sparsefile'
10910 Done
10911 @end group
10912 @end smallexample
10914 Additionally, if your @command{tar} implementation has extracted the
10915 @dfn{extended headers} for this file, you can instruct @command{xstar}
10916 to use them in order to verify the integrity of the expanded file.
10917 The option @option{-x} sets the name of the extended header file to
10918 use.  Continuing our example:
10920 @smallexample
10921 @group
10922 $ @kbd{xsparse -v -x /home/gray/PaxHeaders/sparsefile \
10923   /home/gray/GNUSparseFile/sparsefile}
10924 Reading extended header file
10925 Found variable GNU.sparse.major = 1
10926 Found variable GNU.sparse.minor = 0
10927 Found variable GNU.sparse.name = sparsefile
10928 Found variable GNU.sparse.realsize = 217481216
10929 Reading v.1.0 sparse map
10930 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10931 '/home/gray/sparsefile'
10932 Done
10933 @end group
10934 @end smallexample
10936 @anchor{extracting sparse v0x}
10937 @cindex sparse files v.0.1, extracting with non-GNU tars
10938 @cindex sparse files v.0.0, extracting with non-GNU tars
10939 An @dfn{extended header} is a special @command{tar} archive header
10940 that precedes an archive member and contains a set of
10941 @dfn{variables}, describing the member properties that cannot be
10942 stored in the standard @code{ustar} header.  While optional for
10943 expanding sparse version 1.0 members, the use of extended headers is
10944 mandatory when expanding sparse members in older sparse formats: v.0.0
10945 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10946 Formats}.)  So, for these formats, the question is: how to obtain
10947 extended headers from the archive?
10949 If you use a @command{tar} implementation that does not support PAX
10950 format, extended headers for each member will be extracted as a
10951 separate file.  If we represent the member name as
10952 @file{@var{dir}/@var{name}}, then the extended header file will be
10953 named @file{@var{dir}/@/PaxHeaders/@/@var{name}}.
10955 Things become more difficult if your @command{tar} implementation
10956 does support PAX headers, because in this case you will have to
10957 manually extract the headers.  We recommend the following algorithm:
10959 @enumerate 1
10960 @item
10961 Consult the documentation of your @command{tar} implementation for an
10962 option that prints @dfn{block numbers} along with the archive
10963 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
10964 @command{star} has @option{-block-number}.
10966 @item
10967 Obtain verbose listing using the @samp{block number} option, and
10968 find block numbers of the sparse member in question and the member
10969 immediately following it.  For example, running @command{star} on our
10970 archive we obtain:
10972 @smallexample
10973 @group
10974 $ @kbd{star -t -v -block-number -f arc.tar}
10975 @dots{}
10976 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10977 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10978 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10979 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10980 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10981 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
10982 @dots{}
10983 @end group
10984 @end smallexample
10986 @noindent
10987 (as usual, ignore the warnings about unknown keywords.)
10989 @item
10990 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10991 and @var{Bn} be the block number of the next member.
10992 Compute:
10994 @smallexample
10995 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10996 @end smallexample
10998 @noindent
10999 This number gives the size of the extended header part in tar @dfn{blocks}.
11000 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
11001 = 7}.
11003 @item
11004 Use @command{dd} to extract the headers:
11006 @smallexample
11007 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
11008 @end smallexample
11010 @noindent
11011 where @var{archive} is the archive name, @var{hname} is a name of the
11012 file to store the extended header in, @var{Bs} and @var{N} are
11013 computed in previous steps.
11015 In our example, this command will be
11017 @smallexample
11018 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
11019 @end smallexample
11020 @end enumerate
11022 Finally, you can expand the condensed file, using the obtained header:
11024 @smallexample
11025 @group
11026 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
11027 Reading extended header file
11028 Found variable GNU.sparse.size = 217481216
11029 Found variable GNU.sparse.numblocks = 208
11030 Found variable GNU.sparse.name = sparsefile
11031 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
11032 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
11033 Done
11034 @end group
11035 @end smallexample
11037 @node cpio
11038 @section Comparison of @command{tar} and @command{cpio}
11039 @UNREVISED{}
11041 @FIXME{Reorganize the following material}
11043 The @command{cpio} archive formats, like @command{tar}, do have maximum
11044 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
11045 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
11046 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
11047 with arbitrary file name lengths, but other @command{cpio} implementations
11048 may crash unexplainedly trying to read them.
11050 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
11051 @command{cpio} doesn't handle symbolic links in the form in which it comes
11052 in System V prior to SVR4, and some vendors may have added symlinks
11053 to their system without enhancing @command{cpio} to know about them.
11054 Others may have enhanced it in a way other than the way I did it
11055 at Sun, and which was adopted by AT&T (and which is, I think, also
11056 present in the @command{cpio} that Berkeley picked up from AT&T and put
11057 into a later @acronym{BSD} release---I think I gave them my changes).
11059 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
11060 can handle @command{tar} format input, and write it on output, and it
11061 probably handles symbolic links.  They may not have bothered doing
11062 anything to enhance @command{tar} as a result.)
11064 @command{cpio} handles special files; traditional @command{tar} doesn't.
11066 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
11067 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
11068 (4.3-tahoe and later).
11070 @command{tar}'s way of handling multiple hard links to a file can handle
11071 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
11072 @command{cpio}s way requires you to play some games (in its ``binary''
11073 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
11074 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
11075 field of the header to make sure that the file system @acronym{ID}/i-number pairs
11076 of different files were always different), and I don't know which
11077 @command{cpio}s, if any, play those games.  Those that don't might get
11078 confused and think two files are the same file when they're not, and
11079 make hard links between them.
11081 @command{tar}s way of handling multiple hard links to a file places only
11082 one copy of the link on the tape, but the name attached to that copy
11083 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
11084 way puts one copy for every link, but you can retrieve it using any
11085 of the names.
11087 @quotation
11088 What type of check sum (if any) is used, and how is this calculated.
11089 @end quotation
11091 See the attached manual pages for @command{tar} and @command{cpio} format.
11092 @command{tar} uses a checksum which is the sum of all the bytes in the
11093 @command{tar} header for a file; @command{cpio} uses no checksum.
11095 @quotation
11096 If anyone knows why @command{cpio} was made when @command{tar} was present
11097 at the unix scene,
11098 @end quotation
11100 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
11101 generally-available version of UNIX had @command{tar} at the time.  I don't
11102 know whether any version that was generally available @emph{within AT&T}
11103 had @command{tar}, or, if so, whether the people within AT&T who did
11104 @command{cpio} knew about it.
11106 On restore, if there is a corruption on a tape @command{tar} will stop at
11107 that point, while @command{cpio} will skip over it and try to restore the
11108 rest of the files.
11110 The main difference is just in the command syntax and header format.
11112 @command{tar} is a little more tape-oriented in that everything is blocked
11113 to start on a record boundary.
11115 @quotation
11116 Is there any differences between the ability to recover crashed
11117 archives between the two of them.  (Is there any chance of recovering
11118 crashed archives at all.)
11119 @end quotation
11121 Theoretically it should be easier under @command{tar} since the blocking
11122 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
11123 However, modern @command{cpio}'s and variations have an option to just
11124 search for the next file header after an error with a reasonable chance
11125 of resyncing.  However, lots of tape driver software won't allow you to
11126 continue past a media error which should be the only reason for getting
11127 out of sync unless a file changed sizes while you were writing the
11128 archive.
11130 @quotation
11131 If anyone knows why @command{cpio} was made when @command{tar} was present
11132 at the unix scene, please tell me about this too.
11133 @end quotation
11135 Probably because it is more media efficient (by not blocking everything
11136 and using only the space needed for the headers where @command{tar}
11137 always uses 512 bytes per file header) and it knows how to archive
11138 special files.
11140 You might want to look at the freely available alternatives.  The
11141 major ones are @command{afio}, @GNUTAR{}, and
11142 @command{pax}, each of which have their own extensions with some
11143 backwards compatibility.
11145 Sparse files were @command{tar}red as sparse files (which you can
11146 easily test, because the resulting archive gets smaller, and
11147 @acronym{GNU} @command{cpio} can no longer read it).
11149 @node Media
11150 @chapter Tapes and Other Archive Media
11151 @UNREVISED{}
11153 A few special cases about tape handling warrant more detailed
11154 description.  These special cases are discussed below.
11156 Many complexities surround the use of @command{tar} on tape drives.  Since
11157 the creation and manipulation of archives located on magnetic tape was
11158 the original purpose of @command{tar}, it contains many features making
11159 such manipulation easier.
11161 Archives are usually written on dismountable media---tape cartridges,
11162 mag tapes, or floppy disks.
11164 The amount of data a tape or disk holds depends not only on its size,
11165 but also on how it is formatted.  A 2400 foot long reel of mag tape
11166 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
11167 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
11169 Magnetic media are re-usable---once the archive on a tape is no longer
11170 needed, the archive can be erased and the tape or disk used over.
11171 Media quality does deteriorate with use, however.  Most tapes or disks
11172 should be discarded when they begin to produce data errors.  EXABYTE
11173 tape cartridges should be discarded when they generate an @dfn{error
11174 count} (number of non-usable bits) of more than 10k.
11176 Magnetic media are written and erased using magnetic fields, and
11177 should be protected from such fields to avoid damage to stored data.
11178 Sticking a floppy disk to a filing cabinet using a magnet is probably
11179 not a good idea.
11181 @menu
11182 * Device::                      Device selection and switching
11183 * Remote Tape Server::
11184 * Common Problems and Solutions::
11185 * Blocking::                    Blocking
11186 * Many::                        Many archives on one tape
11187 * Using Multiple Tapes::        Using Multiple Tapes
11188 * label::                       Including a Label in the Archive
11189 * verify::
11190 * Write Protection::
11191 @end menu
11193 @node Device
11194 @section Device Selection and Switching
11195 @UNREVISED{}
11197 @table @option
11198 @item -f [@var{hostname}:]@var{file}
11199 @itemx --file=[@var{hostname}:]@var{file}
11200 Use archive file or device @var{file} on @var{hostname}.
11201 @end table
11203 This option is used to specify the file name of the archive @command{tar}
11204 works on.
11206 If the file name is @samp{-}, @command{tar} reads the archive from standard
11207 input (when listing or extracting), or writes it to standard output
11208 (when creating).  If the @samp{-} file name is given when updating an
11209 archive, @command{tar} will read the original archive from its standard
11210 input, and will write the entire new archive to its standard output.
11212 If the file name contains a @samp{:}, it is interpreted as
11213 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
11214 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
11215 either case, @command{tar} will invoke the command @command{rsh} (or
11216 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
11217 machine.  If you give an alternate login name, it will be given to the
11218 @command{rsh}.
11219 Naturally, the remote machine must have an executable
11220 @command{/usr/libexec/rmt}.  This program is free software from the
11221 University of California, and a copy of the source code can be found
11222 with the sources for @command{tar}; it's compiled and installed by default.
11223 The exact path to this utility is determined when configuring the package.
11224 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
11225 your installation prefix.  This location may also be overridden at
11226 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
11227 ---rmt-command}, for detailed description of this option.  @xref{Remote
11228 Tape Server}, for the description of @command{rmt} command).
11230 If this option is not given, but the environment variable @env{TAPE}
11231 is set, its value is used; otherwise, old versions of @command{tar}
11232 used a default archive name (which was picked when @command{tar} was
11233 compiled).  The default is normally set up to be the @dfn{first} tape
11234 drive or other transportable I/O medium on the system.
11236 Starting with version 1.11.5, @GNUTAR{} uses
11237 standard input and standard output as the default device, and I will
11238 not try anymore supporting automatic device detection at installation
11239 time.  This was failing really in too many cases, it was hopeless.
11240 This is now completely left to the installer to override standard
11241 input and standard output for default device, if this seems
11242 preferable.  Further, I think @emph{most} actual usages of
11243 @command{tar} are done with pipes or disks, not really tapes,
11244 cartridges or diskettes.
11246 Some users think that using standard input and output is running
11247 after trouble.  This could lead to a nasty surprise on your screen if
11248 you forget to specify an output file name---especially if you are going
11249 through a network or terminal server capable of buffering large amounts
11250 of output.  We had so many bug reports in that area of configuring
11251 default tapes automatically, and so many contradicting requests, that
11252 we finally consider the problem to be portably intractable.  We could
11253 of course use something like @samp{/dev/tape} as a default, but this
11254 is @emph{also} running after various kind of trouble, going from hung
11255 processes to accidental destruction of real tapes.  After having seen
11256 all this mess, using standard input and output as a default really
11257 sounds like the only clean choice left, and a very useful one too.
11259 @GNUTAR{} reads and writes archive in records, I
11260 suspect this is the main reason why block devices are preferred over
11261 character devices.  Most probably, block devices are more efficient
11262 too.  The installer could also check for @samp{DEFTAPE} in
11263 @file{<sys/mtio.h>}.
11265 @table @option
11266 @xopindex{force-local, short description}
11267 @item --force-local
11268 Archive file is local even if it contains a colon.
11270 @opindex rsh-command
11271 @item --rsh-command=@var{command}
11272 Use remote @var{command} instead of @command{rsh}.  This option exists
11273 so that people who use something other than the standard @command{rsh}
11274 (e.g., a Kerberized @command{rsh}) can access a remote device.
11276 When this command is not used, the shell command found when
11277 the @command{tar} program was installed is used instead.  This is
11278 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
11279 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
11280 The installer may have overridden this by defining the environment
11281 variable @env{RSH} @emph{at installation time}.
11283 @item -[0-7][lmh]
11284 Specify drive and density.
11286 @xopindex{multi-volume, short description}
11287 @item -M
11288 @itemx --multi-volume
11289 Create/list/extract multi-volume archive.
11291 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
11292 that may be larger than will fit on the medium used to hold it.
11293 @xref{Multi-Volume Archives}.
11295 @xopindex{tape-length, short description}
11296 @item -L @var{num}
11297 @itemx --tape-length=@var{size}[@var{suf}]
11298 Change tape after writing @var{size} units of data.  Unless @var{suf} is
11299 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
11300 1024} bytes.  The following suffixes alter this behavior:
11302 @float Table, size-suffixes
11303 @caption{Size Suffixes}
11304 @multitable @columnfractions 0.2 0.3 0.3
11305 @headitem Suffix @tab Units            @tab Byte Equivalent
11306 @item b          @tab Blocks           @tab @var{size} x 512
11307 @item B          @tab Kilobytes        @tab @var{size} x 1024
11308 @item c          @tab Bytes            @tab @var{size}
11309 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
11310 @item K          @tab Kilobytes        @tab @var{size} x 1024
11311 @item k          @tab Kilobytes        @tab @var{size} x 1024
11312 @item M          @tab Megabytes        @tab @var{size} x 1024^2
11313 @item P          @tab Petabytes        @tab @var{size} x 1024^5
11314 @item T          @tab Terabytes        @tab @var{size} x 1024^4
11315 @item w          @tab Words            @tab @var{size} x 2
11316 @end multitable
11317 @end float
11319 This option might be useful when your tape drivers do not properly
11320 detect end of physical tapes.  By being slightly conservative on the
11321 maximum tape length, you might avoid the problem entirely.
11323 @xopindex{info-script, short description}
11324 @xopindex{new-volume-script, short description}
11325 @item -F @var{command}
11326 @itemx --info-script=@var{command}
11327 @itemx --new-volume-script=@var{command}
11328 Execute @var{command} at end of each tape.  This implies
11329 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
11330 description of this option.
11331 @end table
11333 @node Remote Tape Server
11334 @section Remote Tape Server
11336 @cindex remote tape drive
11337 @pindex rmt
11338 In order to access the tape drive on a remote machine, @command{tar}
11339 uses the remote tape server written at the University of California at
11340 Berkeley.  The remote tape server must be installed as
11341 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
11342 want to use.  @command{tar} calls @command{rmt} by running an
11343 @command{rsh} or @command{remsh} to the remote machine, optionally
11344 using a different login name if one is supplied.
11346 A copy of the source for the remote tape server is provided.  Its
11347 source code can be freely distributed.  It is compiled and
11348 installed by default.
11350 @cindex absolute file names
11351 Unless you use the @option{--absolute-names} (@option{-P}) option,
11352 @GNUTAR{} will not allow you to create an archive that contains
11353 absolute file names (a file name beginning with @samp{/}).  If you try,
11354 @command{tar} will automatically remove the leading @samp{/} from the
11355 file names it stores in the archive.  It will also type a warning
11356 message telling you what it is doing.
11358 When reading an archive that was created with a different
11359 @command{tar} program, @GNUTAR{} automatically
11360 extracts entries in the archive which have absolute file names as if
11361 the file names were not absolute.  This is an important feature.  A
11362 visitor here once gave a @command{tar} tape to an operator to restore;
11363 the operator used Sun @command{tar} instead of @GNUTAR{},
11364 and the result was that it replaced large portions of
11365 our @file{/bin} and friends with versions from the tape; needless to
11366 say, we were unhappy about having to recover the file system from
11367 backup tapes.
11369 For example, if the archive contained a file @file{/usr/bin/computoy},
11370 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
11371 relative to the current directory.  If you want to extract the files in
11372 an archive to the same absolute names that they had when the archive
11373 was created, you should do a @samp{cd /} before extracting the files
11374 from the archive, or you should either use the @option{--absolute-names}
11375 option, or use the command @samp{tar -C / @dots{}}.
11377 @cindex Ultrix 3.1 and write failure
11378 Some versions of Unix (Ultrix 3.1 is known to have this problem),
11379 can claim that a short write near the end of a tape succeeded,
11380 when it actually failed.  This will result in the -M option not
11381 working correctly.  The best workaround at the moment is to use a
11382 significantly larger blocking factor than the default 20.
11384 In order to update an archive, @command{tar} must be able to backspace the
11385 archive in order to reread or rewrite a record that was just read (or
11386 written).  This is currently possible only on two kinds of files: normal
11387 disk files (or any other file that can be backspaced with @samp{lseek}),
11388 and industry-standard 9-track magnetic tape (or any other kind of tape
11389 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
11391 This means that the @option{--append}, @option{--concatenate}, and
11392 @option{--delete} commands will not work on any other kind of file.
11393 Some media simply cannot be backspaced, which means these commands and
11394 options will never be able to work on them.  These non-backspacing
11395 media include pipes and cartridge tape drives.
11397 Some other media can be backspaced, and @command{tar} will work on them
11398 once @command{tar} is modified to do so.
11400 Archives created with the @option{--multi-volume}, @option{--label}, and
11401 @option{--incremental} (@option{-G}) options may not be readable by other version
11402 of @command{tar}.  In particular, restoring a file that was split over
11403 a volume boundary will require some careful work with @command{dd}, if
11404 it can be done at all.  Other versions of @command{tar} may also create
11405 an empty file whose name is that of the volume header.  Some versions
11406 of @command{tar} may create normal files instead of directories archived
11407 with the @option{--incremental} (@option{-G}) option.
11409 @node Common Problems and Solutions
11410 @section Some Common Problems and their Solutions
11412 @ifclear PUBLISH
11414 @format
11415 errors from system:
11416 permission denied
11417 no such file or directory
11418 not owner
11420 errors from @command{tar}:
11421 directory checksum error
11422 header format error
11424 errors from media/system:
11425 i/o error
11426 device busy
11427 @end format
11429 @end ifclear
11431 @node Blocking
11432 @section Blocking
11433 @cindex block
11434 @cindex record
11436 @dfn{Block} and @dfn{record} terminology is rather confused, and it
11437 is also confusing to the expert reader.  On the other hand, readers
11438 who are new to the field have a fresh mind, and they may safely skip
11439 the next two paragraphs, as the remainder of this manual uses those
11440 two terms in a quite consistent way.
11442 John Gilmore, the writer of the public domain @command{tar} from which
11443 @GNUTAR{} was originally derived, wrote (June 1995):
11445 @quotation
11446 The nomenclature of tape drives comes from IBM, where I believe
11447 they were invented for the IBM 650 or so.  On IBM mainframes, what
11448 is recorded on tape are tape blocks.  The logical organization of
11449 data is into records.  There are various ways of putting records into
11450 blocks, including @code{F} (fixed sized records), @code{V} (variable
11451 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
11452 to a block), @code{VB} (variable size records, @var{n} to a block),
11453 @code{VSB} (variable spanned blocked: variable sized records that can
11454 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
11455 parameter specified this to the operating system.
11457 The Unix man page on @command{tar} was totally confused about this.
11458 When I wrote @code{PD TAR}, I used the historically correct terminology
11459 (@command{tar} writes data records, which are grouped into blocks).
11460 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
11461 here), and now Fran@,{c}ois has migrated that terminology back
11462 into the source code too.
11463 @end quotation
11465 The term @dfn{physical block} means the basic transfer chunk from or
11466 to a device, after which reading or writing may stop without anything
11467 being lost.  In this manual, the term @dfn{block} usually refers to
11468 a disk physical block, @emph{assuming} that each disk block is 512
11469 bytes in length.  It is true that some disk devices have different
11470 physical blocks, but @command{tar} ignore these differences in its own
11471 format, which is meant to be portable, so a @command{tar} block is always
11472 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
11473 The term @dfn{logical block} often represents the basic chunk of
11474 allocation of many disk blocks as a single entity, which the operating
11475 system treats somewhat atomically; this concept is only barely used
11476 in @GNUTAR{}.
11478 The term @dfn{physical record} is another way to speak of a physical
11479 block, those two terms are somewhat interchangeable.  In this manual,
11480 the term @dfn{record} usually refers to a tape physical block,
11481 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
11482 It is true that archives may be put on disk or used with pipes,
11483 but nevertheless, @command{tar} tries to read and write the archive one
11484 @dfn{record} at a time, whatever the medium in use.  One record is made
11485 up of an integral number of blocks, and this operation of putting many
11486 disk blocks into a single tape block is called @dfn{reblocking}, or
11487 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
11488 the logical organization of many characters into something meaningful
11489 to the application.  The term @dfn{unit record} describes a small set
11490 of characters which are transmitted whole to or by the application,
11491 and often refers to a line of text.  Those two last terms are unrelated
11492 to what we call a @dfn{record} in @GNUTAR{}.
11494 When writing to tapes, @command{tar} writes the contents of the archive
11495 in chunks known as @dfn{records}.  To change the default blocking
11496 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
11497 @var{512-size}}) option.  Each record will then be composed of
11498 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
11499 @xref{Standard}.)  Each file written to the archive uses at least one
11500 full record.  As a result, using a larger record size can result in
11501 more wasted space for small files.  On the other hand, a larger record
11502 size can often be read and written much more efficiently.
11504 Further complicating the problem is that some tape drives ignore the
11505 blocking entirely.  For these, a larger record size can still improve
11506 performance (because the software layers above the tape drive still
11507 honor the blocking), but not as dramatically as on tape drives that
11508 honor blocking.
11510 When reading an archive, @command{tar} can usually figure out the
11511 record size on itself.  When this is the case, and a non-standard
11512 record size was used when the archive was created, @command{tar} will
11513 print a message about a non-standard blocking factor, and then operate
11514 normally@footnote{If this message is not needed, you can turn it off
11515 using the @option{--warning=no-record-size} option.}.  On some tape
11516 devices, however, @command{tar} cannot figure out the record size
11517 itself.  On most of those, you can specify a blocking factor (with
11518 @option{--blocking-factor}) larger than the actual blocking factor,
11519 and then use the @option{--read-full-records} (@option{-B}) option.
11520 (If you specify a blocking factor with @option{--blocking-factor} and
11521 don't use the @option{--read-full-records} option, then @command{tar}
11522 will not attempt to figure out the recording size itself.)  On some
11523 devices, you must always specify the record size exactly with
11524 @option{--blocking-factor} when reading, because @command{tar} cannot
11525 figure it out.  In any case, use @option{--list} (@option{-t}) before
11526 doing any extractions to see whether @command{tar} is reading the archive
11527 correctly.
11529 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
11530 putting them into records is to put a whole number of them (one or
11531 more) into each record.  @command{tar} records are all the same size;
11532 at the end of the file there's a block containing all zeros, which
11533 is how you tell that the remainder of the last record(s) are garbage.
11535 In a standard @command{tar} file (no options), the block size is 512
11536 and the record size is 10240, for a blocking factor of 20.  What the
11537 @option{--blocking-factor} option does is sets the blocking factor,
11538 changing the record size while leaving the block size at 512 bytes.
11539 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
11540 most tape drives these days prefer much bigger records in order to
11541 stream and not waste tape.  When writing tapes for myself, some tend
11542 to use a factor of the order of 2048, say, giving a record size of
11543 around one megabyte.
11545 If you use a blocking factor larger than 20, older @command{tar}
11546 programs might not be able to read the archive, so we recommend this
11547 as a limit to use in practice.  @GNUTAR{}, however,
11548 will support arbitrarily large record sizes, limited only by the
11549 amount of virtual memory or the physical characteristics of the tape
11550 device.
11552 @menu
11553 * Format Variations::           Format Variations
11554 * Blocking Factor::             The Blocking Factor of an Archive
11555 @end menu
11557 @node Format Variations
11558 @subsection Format Variations
11559 @cindex Format Parameters
11560 @cindex Format Options
11561 @cindex Options, archive format specifying
11562 @cindex Options, format specifying
11563 @UNREVISED{}
11565 Format parameters specify how an archive is written on the archive
11566 media.  The best choice of format parameters will vary depending on
11567 the type and number of files being archived, and on the media used to
11568 store the archive.
11570 To specify format parameters when accessing or creating an archive,
11571 you can use the options described in the following sections.
11572 If you do not specify any format parameters, @command{tar} uses
11573 default parameters.  You cannot modify a compressed archive.
11574 If you create an archive with the @option{--blocking-factor} option
11575 specified (@pxref{Blocking Factor}), you must specify that
11576 blocking-factor when operating on the archive.  @xref{Formats}, for other
11577 examples of format parameter considerations.
11579 @node Blocking Factor
11580 @subsection The Blocking Factor of an Archive
11581 @cindex Blocking Factor
11582 @cindex Record Size
11583 @cindex Number of blocks per record
11584 @cindex Number of bytes per record
11585 @cindex Bytes per record
11586 @cindex Blocks per record
11587 @UNREVISED{}
11589 @opindex blocking-factor
11590 The data in an archive is grouped into blocks, which are 512 bytes.
11591 Blocks are read and written in whole number multiples called
11592 @dfn{records}.  The number of blocks in a record (i.e., the size of a
11593 record in units of 512 bytes) is called the @dfn{blocking factor}.
11594 The @option{--blocking-factor=@var{512-size}} (@option{-b
11595 @var{512-size}}) option specifies the blocking factor of an archive.
11596 The default blocking factor is typically 20 (i.e., 10240 bytes), but
11597 can be specified at installation.  To find out the blocking factor of
11598 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
11599 This may not work on some devices.
11601 Records are separated by gaps, which waste space on the archive media.
11602 If you are archiving on magnetic tape, using a larger blocking factor
11603 (and therefore larger records) provides faster throughput and allows you
11604 to fit more data on a tape (because there are fewer gaps).  If you are
11605 archiving on cartridge, a very large blocking factor (say 126 or more)
11606 greatly increases performance.  A smaller blocking factor, on the other
11607 hand, may be useful when archiving small files, to avoid archiving lots
11608 of nulls as @command{tar} fills out the archive to the end of the record.
11609 In general, the ideal record size depends on the size of the
11610 inter-record gaps on the tape you are using, and the average size of the
11611 files you are archiving.  @xref{create}, for information on
11612 writing archives.
11614 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
11616 Archives with blocking factors larger than 20 cannot be read
11617 by very old versions of @command{tar}, or by some newer versions
11618 of @command{tar} running on old machines with small address spaces.
11619 With @GNUTAR{}, the blocking factor of an archive is limited
11620 only by the maximum record size of the device containing the archive,
11621 or by the amount of available virtual memory.
11623 Also, on some systems, not using adequate blocking factors, as sometimes
11624 imposed by the device drivers, may yield unexpected diagnostics.  For
11625 example, this has been reported:
11627 @smallexample
11628 Cannot write to /dev/dlt: Invalid argument
11629 @end smallexample
11631 @noindent
11632 In such cases, it sometimes happen that the @command{tar} bundled by
11633 the system is aware of block size idiosyncrasies, while @GNUTAR{}
11634 requires an explicit specification for the block size,
11635 which it cannot guess.  This yields some people to consider
11636 @GNUTAR{} is misbehaving, because by comparison,
11637 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
11638 for example, might resolve the problem.
11640 If you use a non-default blocking factor when you create an archive, you
11641 must specify the same blocking factor when you modify that archive.  Some
11642 archive devices will also require you to specify the blocking factor when
11643 reading that archive, however this is not typically the case.  Usually, you
11644 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
11645 reports a non-default record size and then lists the archive members as
11646 it would normally.  To extract files from an archive with a non-standard
11647 blocking factor (particularly if you're not sure what the blocking factor
11648 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
11649 specifying a blocking factor larger then the blocking factor of the archive
11650 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
11651 @xref{list}, for more information on the @option{--list} (@option{-t})
11652 operation.  @xref{Reading}, for a more detailed explanation of that option.
11654 @table @option
11655 @item --blocking-factor=@var{number}
11656 @itemx -b @var{number}
11657 Specifies the blocking factor of an archive.  Can be used with any
11658 operation, but is usually not necessary with @option{--list} (@option{-t}).
11659 @end table
11661 Device blocking
11663 @table @option
11664 @item -b @var{blocks}
11665 @itemx --blocking-factor=@var{blocks}
11666 Set record size to @math{@var{blocks}*512} bytes.
11668 This option is used to specify a @dfn{blocking factor} for the archive.
11669 When reading or writing the archive, @command{tar}, will do reads and writes
11670 of the archive in records of @math{@var{block}*512} bytes.  This is true
11671 even when the archive is compressed.  Some devices requires that all
11672 write operations be a multiple of a certain size, and so, @command{tar}
11673 pads the archive out to the next record boundary.
11675 The default blocking factor is set when @command{tar} is compiled, and is
11676 typically 20.  Blocking factors larger than 20 cannot be read by very
11677 old versions of @command{tar}, or by some newer versions of @command{tar}
11678 running on old machines with small address spaces.
11680 With a magnetic tape, larger records give faster throughput and fit
11681 more data on a tape (because there are fewer inter-record gaps).
11682 If the archive is in a disk file or a pipe, you may want to specify
11683 a smaller blocking factor, since a large one will result in a large
11684 number of null bytes at the end of the archive.
11686 When writing cartridge or other streaming tapes, a much larger
11687 blocking factor (say 126 or more) will greatly increase performance.
11688 However, you must specify the same blocking factor when reading or
11689 updating the archive.
11691 Apparently, Exabyte drives have a physical block size of 8K bytes.
11692 If we choose our blocksize as a multiple of 8k bytes, then the problem
11693 seems to disappear.  Id est, we are using block size of 112 right
11694 now, and we haven't had the problem since we switched@dots{}
11696 With @GNUTAR{} the blocking factor is limited only
11697 by the maximum record size of the device containing the archive, or by
11698 the amount of available virtual memory.
11700 However, deblocking or reblocking is virtually avoided in a special
11701 case which often occurs in practice, but which requires all the
11702 following conditions to be simultaneously true:
11703 @itemize @bullet
11704 @item
11705 the archive is subject to a compression option,
11706 @item
11707 the archive is not handled through standard input or output, nor
11708 redirected nor piped,
11709 @item
11710 the archive is directly handled to a local disk, instead of any special
11711 device,
11712 @item
11713 @option{--blocking-factor} is not explicitly specified on the @command{tar}
11714 invocation.
11715 @end itemize
11717 If the output goes directly to a local disk, and not through
11718 stdout, then the last write is not extended to a full record size.
11719 Otherwise, reblocking occurs.  Here are a few other remarks on this
11720 topic:
11722 @itemize @bullet
11724 @item
11725 @command{gzip} will complain about trailing garbage if asked to
11726 uncompress a compressed archive on tape, there is an option to turn
11727 the message off, but it breaks the regularity of simply having to use
11728 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
11729 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
11730 Gailly, by sending a copy of this message to him.
11732 @item
11733 @command{compress} does not show this problem, but as Jean-loup pointed
11734 out to Michael, @samp{compress -d} silently adds garbage after
11735 the result of decompression, which tar ignores because it already
11736 recognized its end-of-file indicator.  So this bug may be safely
11737 ignored.
11739 @item
11740 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
11741 but will still return an exit status of 2 which tar reports in turn.
11742 @command{tar} might ignore the exit status returned, but I hate doing
11743 that, as it weakens the protection @command{tar} offers users against
11744 other possible problems at decompression time.  If @command{gzip} was
11745 silently skipping trailing zeros @emph{and} also avoiding setting the
11746 exit status in this innocuous case, that would solve this situation.
11748 @item
11749 @command{tar} should become more solid at not stopping to read a pipe at
11750 the first null block encountered.  This inelegantly breaks the pipe.
11751 @command{tar} should rather drain the pipe out before exiting itself.
11752 @end itemize
11754 @xopindex{ignore-zeros, short description}
11755 @item -i
11756 @itemx --ignore-zeros
11757 Ignore blocks of zeros in archive (means EOF).
11759 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
11760 of zeros in the archive.  Normally a block of zeros indicates the
11761 end of the archive, but when reading a damaged archive, or one which
11762 was created by concatenating several archives together, this option
11763 allows @command{tar} to read the entire archive.  This option is not on
11764 by default because many versions of @command{tar} write garbage after
11765 the zeroed blocks.
11767 Note that this option causes @command{tar} to read to the end of the
11768 archive file, which may sometimes avoid problems when multiple files
11769 are stored on a single physical tape.
11771 @xopindex{read-full-records, short description}
11772 @item -B
11773 @itemx --read-full-records
11774 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
11776 If @option{--read-full-records} is used, @command{tar}
11777 will not panic if an attempt to read a record from the archive does
11778 not return a full record.  Instead, @command{tar} will keep reading
11779 until it has obtained a full
11780 record.
11782 This option is turned on by default when @command{tar} is reading
11783 an archive from standard input, or from a remote machine.  This is
11784 because on @acronym{BSD} Unix systems, a read of a pipe will return however
11785 much happens to be in the pipe, even if it is less than @command{tar}
11786 requested.  If this option was not used, @command{tar} would fail as
11787 soon as it read an incomplete record from the pipe.
11789 This option is also useful with the commands for updating an archive.
11791 @end table
11793 Tape blocking
11795 @FIXME{Appropriate options should be moved here from elsewhere.}
11797 @cindex blocking factor
11798 @cindex tape blocking
11800 When handling various tapes or cartridges, you have to take care of
11801 selecting a proper blocking, that is, the number of disk blocks you
11802 put together as a single tape block on the tape, without intervening
11803 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
11804 with no information on it, used for decelerating the tape to a
11805 full stop, and for later regaining the reading or writing speed.
11806 When the tape driver starts reading a record, the record has to
11807 be read whole without stopping, as a tape gap is needed to stop the
11808 tape motion without losing information.
11810 @cindex Exabyte blocking
11811 @cindex DAT blocking
11812 Using higher blocking (putting more disk blocks per tape block) will use
11813 the tape more efficiently as there will be less tape gaps.  But reading
11814 such tapes may be more difficult for the system, as more memory will be
11815 required to receive at once the whole record.  Further, if there is a
11816 reading error on a huge record, this is less likely that the system will
11817 succeed in recovering the information.  So, blocking should not be too
11818 low, nor it should be too high.  @command{tar} uses by default a blocking of
11819 20 for historical reasons, and it does not really matter when reading or
11820 writing to disk.  Current tape technology would easily accommodate higher
11821 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11822 We were told that for some DLT drives, the blocking should be a multiple
11823 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11824 Other manufacturers may use different recommendations for the same tapes.
11825 This might also depends of the buffering techniques used inside modern
11826 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
11827 Others request blocking to be some exponent of two.
11829 So, there is no fixed rule for blocking.  But blocking at read time
11830 should ideally be the same as blocking used at write time.  At one place
11831 I know, with a wide variety of equipment, they found it best to use a
11832 blocking of 32 to guarantee that their tapes are fully interchangeable.
11834 I was also told that, for recycled tapes, prior erasure (by the same
11835 drive unit that will be used to create the archives) sometimes lowers
11836 the error rates observed at rewriting time.
11838 I might also use @option{--number-blocks} instead of
11839 @option{--block-number}, so @option{--block} will then expand to
11840 @option{--blocking-factor} unambiguously.
11842 @node Many
11843 @section Many Archives on One Tape
11845 @FIXME{Appropriate options should be moved here from elsewhere.}
11847 @findex ntape @r{device}
11848 Most tape devices have two entries in the @file{/dev} directory, or
11849 entries that come in pairs, which differ only in the minor number for
11850 this device.  Let's take for example @file{/dev/tape}, which often
11851 points to the only or usual tape device of a given system.  There might
11852 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
11853 name is the @emph{rewinding} version of the device, while the name
11854 having @samp{nr} in it is the @emph{no rewinding} version of the same
11855 device.
11857 A rewinding tape device will bring back the tape to its beginning point
11858 automatically when this device is opened or closed.  Since @command{tar}
11859 opens the archive file before using it and closes it afterwards, this
11860 means that a simple:
11862 @smallexample
11863 $ @kbd{tar cf /dev/tape @var{directory}}
11864 @end smallexample
11866 @noindent
11867 will reposition the tape to its beginning both prior and after saving
11868 @var{directory} contents to it, thus erasing prior tape contents and
11869 making it so that any subsequent write operation will destroy what has
11870 just been saved.
11872 @cindex tape positioning
11873 So, a rewinding device is normally meant to hold one and only one file.
11874 If you want to put more than one @command{tar} archive on a given tape, you
11875 will need to avoid using the rewinding version of the tape device.  You
11876 will also have to pay special attention to tape positioning.  Errors in
11877 positioning may overwrite the valuable data already on your tape.  Many
11878 people, burnt by past experiences, will only use rewinding devices and
11879 limit themselves to one file per tape, precisely to avoid the risk of
11880 such errors.  Be fully aware that writing at the wrong position on a
11881 tape loses all information past this point and most probably until the
11882 end of the tape, and this destroyed information @emph{cannot} be
11883 recovered.
11885 To save @var{directory-1} as a first archive at the beginning of a
11886 tape, and leave that tape ready for a second archive, you should use:
11888 @smallexample
11889 $ @kbd{mt -f /dev/nrtape rewind}
11890 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11891 @end smallexample
11893 @cindex tape marks
11894 @dfn{Tape marks} are special magnetic patterns written on the tape
11895 media, which are later recognizable by the reading hardware.  These
11896 marks are used after each file, when there are many on a single tape.
11897 An empty file (that is to say, two tape marks in a row) signal the
11898 logical end of the tape, after which no file exist.  Usually,
11899 non-rewinding tape device drivers will react to the close request issued
11900 by @command{tar} by first writing two tape marks after your archive, and by
11901 backspacing over one of these.  So, if you remove the tape at that time
11902 from the tape drive, it is properly terminated.  But if you write
11903 another file at the current position, the second tape mark will be
11904 erased by the new information, leaving only one tape mark between files.
11906 So, you may now save @var{directory-2} as a second archive after the
11907 first on the same tape by issuing the command:
11909 @smallexample
11910 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11911 @end smallexample
11913 @noindent
11914 and so on for all the archives you want to put on the same tape.
11916 Another usual case is that you do not write all the archives the same
11917 day, and you need to remove and store the tape between two archive
11918 sessions.  In general, you must remember how many files are already
11919 saved on your tape.  Suppose your tape already has 16 files on it, and
11920 that you are ready to write the 17th.  You have to take care of skipping
11921 the first 16 tape marks before saving @var{directory-17}, say, by using
11922 these commands:
11924 @smallexample
11925 $ @kbd{mt -f /dev/nrtape rewind}
11926 $ @kbd{mt -f /dev/nrtape fsf 16}
11927 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11928 @end smallexample
11930 In all the previous examples, we put aside blocking considerations, but
11931 you should do the proper things for that as well.  @xref{Blocking}.
11933 @menu
11934 * Tape Positioning::            Tape Positions and Tape Marks
11935 * mt::                          The @command{mt} Utility
11936 @end menu
11938 @node Tape Positioning
11939 @subsection Tape Positions and Tape Marks
11940 @UNREVISED{}
11942 Just as archives can store more than one file from the file system,
11943 tapes can store more than one archive file.  To keep track of where
11944 archive files (or any other type of file stored on tape) begin and
11945 end, tape archive devices write magnetic @dfn{tape marks} on the
11946 archive media.  Tape drives write one tape mark between files,
11947 two at the end of all the file entries.
11949 If you think of data as a series of records "rrrr"'s, and tape marks as
11950 "*"'s, a tape might look like the following:
11952 @smallexample
11953 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11954 @end smallexample
11956 Tape devices read and write tapes using a read/write @dfn{tape
11957 head}---a physical part of the device which can only access one
11958 point on the tape at a time.  When you use @command{tar} to read or
11959 write archive data from a tape device, the device will begin reading
11960 or writing from wherever on the tape the tape head happens to be,
11961 regardless of which archive or what part of the archive the tape
11962 head is on.  Before writing an archive, you should make sure that no
11963 data on the tape will be overwritten (unless it is no longer needed).
11964 Before reading an archive, you should make sure the tape head is at
11965 the beginning of the archive you want to read.  You can do it manually
11966 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
11967 that automatically (@pxref{Scripted Restoration}).
11969 If you want to add new archive file entries to a tape, you should
11970 advance the tape to the end of the existing file entries, backspace
11971 over the last tape mark, and write the new archive file.  If you were
11972 to add two archives to the example above, the tape might look like the
11973 following:
11975 @smallexample
11976 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11977 @end smallexample
11979 @node mt
11980 @subsection The @command{mt} Utility
11981 @UNREVISED{}
11983 @FIXME{Is it true that this only works on non-block devices?
11984 should explain the difference, (fixed or variable).}
11985 @xref{Blocking Factor}.
11987 You can use the @command{mt} utility to advance or rewind a tape past a
11988 specified number of archive files on the tape.  This will allow you
11989 to move to the beginning of an archive before extracting or reading
11990 it, or to the end of all the archives before writing a new one.
11991 @FIXME{Why isn't there an "advance 'til you find two tape marks
11992 together"?}
11994 The syntax of the @command{mt} command is:
11996 @smallexample
11997 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11998 @end smallexample
12000 where @var{tapename} is the name of the tape device, @var{number} is
12001 the number of times an operation is performed (with a default of one),
12002 and @var{operation} is one of the following:
12004 @FIXME{is there any use for record operations?}
12006 @table @option
12007 @item eof
12008 @itemx weof
12009 Writes @var{number} tape marks at the current position on the tape.
12011 @item fsf
12012 Moves tape position forward @var{number} files.
12014 @item bsf
12015 Moves tape position back @var{number} files.
12017 @item rewind
12018 Rewinds the tape.  (Ignores @var{number}.)
12020 @item offline
12021 @itemx rewoff1
12022 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
12024 @item status
12025 Prints status information about the tape unit.
12027 @end table
12029 If you don't specify a @var{tapename}, @command{mt} uses the environment
12030 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
12031 the default device specified in your @file{sys/mtio.h} file
12032 (@code{DEFTAPE} variable).  If this is not defined, the program will
12033 display a descriptive error message and exit with code 1.
12035 @command{mt} returns a 0 exit status when the operation(s) were
12036 successful, 1 if the command was unrecognized, and 2 if an operation
12037 failed.
12039 @node Using Multiple Tapes
12040 @section Using Multiple Tapes
12042 Often you might want to write a large archive, one larger than will fit
12043 on the actual tape you are using.  In such a case, you can run multiple
12044 @command{tar} commands, but this can be inconvenient, particularly if you
12045 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
12046 Therefore, @command{tar} provides a special mode for creating
12047 multi-volume archives.
12049 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
12050 on several media volumes of fixed size.  Although in this section we will
12051 often call @samp{volume} a @dfn{tape}, there is absolutely no
12052 requirement for multi-volume archives to be stored on tapes.  Instead,
12053 they can use whatever media type the user finds convenient, they can
12054 even be located on files.
12056 When creating a multi-volume archive, @GNUTAR{} continues to fill
12057 current volume until it runs out of space, then it switches to
12058 next volume (usually the operator is queried to replace the tape on
12059 this point), and continues working on the new volume.  This operation
12060 continues until all requested files are dumped.  If @GNUTAR{} detects
12061 end of media while dumping a file, such a file is archived in split
12062 form.  Some very big files can even be split across several volumes.
12064 Each volume is itself a valid @GNUTAR{} archive, so it can be read
12065 without any special options.  Consequently any file member residing
12066 entirely on one volume can be extracted or otherwise operated upon
12067 without needing the other volume.  Sure enough, to extract a split
12068 member you would need all volumes its parts reside on.
12070 Multi-volume archives suffer from several limitations.  In particular,
12071 they cannot be compressed.
12073 @GNUTAR{} is able to create multi-volume archives of two formats
12074 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
12076 @menu
12077 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
12078 * Tape Files::                  Tape Files
12079 * Tarcat::                      Concatenate Volumes into a Single Archive
12081 @end menu
12083 @node Multi-Volume Archives
12084 @subsection Archives Longer than One Tape or Disk
12085 @cindex Multi-volume archives
12087 @opindex multi-volume
12088 To create an archive that is larger than will fit on a single unit of
12089 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
12090 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
12091 archive can be manipulated like any other archive (provided the
12092 @option{--multi-volume} option is specified), but is stored on more
12093 than one tape or file.
12095 When you specify @option{--multi-volume}, @command{tar} does not report an
12096 error when it comes to the end of an archive volume (when reading), or
12097 the end of the media (when writing).  Instead, it prompts you to load
12098 a new storage volume.  If the archive is on a magnetic tape, you
12099 should change tapes when you see the prompt; if the archive is on a
12100 floppy disk, you should change disks; etc.
12102 @table @option
12103 @item --multi-volume
12104 @itemx -M
12105 Creates a multi-volume archive, when used in conjunction with
12106 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
12107 archive, specify @option{--multi-volume} in conjunction with that
12108 operation.
12109 For example:
12111 @smallexample
12112 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
12113 @end smallexample
12114 @end table
12116 The method @command{tar} uses to detect end of tape is not perfect, and
12117 fails on some operating systems or on some devices.  If @command{tar}
12118 cannot detect the end of the tape itself, you can use
12119 @option{--tape-length} option to inform it about the capacity of the
12120 tape:
12122 @anchor{tape-length}
12123 @table @option
12124 @opindex tape-length
12125 @item --tape-length=@var{size}[@var{suf}]
12126 @itemx -L @var{size}[@var{suf}]
12127 Set maximum length of a volume.  The @var{suf}, if given, specifies
12128 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
12129 megabytes (@pxref{size-suffixes}, for a list of allowed size
12130 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
12131 assumed.
12133 This option selects @option{--multi-volume} automatically.  For example:
12135 @smallexample
12136 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
12137 @end smallexample
12139 @noindent
12140 or, which is equivalent:
12142 @smallexample
12143 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
12144 @end smallexample
12145 @end table
12147 @anchor{change volume prompt}
12148 When @GNUTAR{} comes to the end of a storage media, it asks you to
12149 change the volume.  The built-in prompt for POSIX locale
12150 is@footnote{If you run @GNUTAR{} under a different locale, the
12151 translation to the locale's language will be used.}:
12153 @smallexample
12154 Prepare volume #@var{n} for '@var{archive}' and hit return:
12155 @end smallexample
12157 @noindent
12158 where @var{n} is the ordinal number of the volume to be created and
12159 @var{archive} is archive file or device name.
12161 When prompting for a new tape, @command{tar} accepts any of the following
12162 responses:
12164 @table @kbd
12165 @item ?
12166 Request @command{tar} to explain possible responses.
12167 @item q
12168 Request @command{tar} to exit immediately.
12169 @item n @var{file-name}
12170 Request @command{tar} to write the next volume on the file @var{file-name}.
12171 @item !
12172 Request @command{tar} to run a subshell.  This option can be disabled
12173 by giving @option{--restrict} command line option to
12174 @command{tar}@footnote{@xref{--restrict}, for more information about
12175 this option.}.
12176 @item y
12177 Request @command{tar} to begin writing the next volume.
12178 @end table
12180 (You should only type @samp{y} after you have changed the tape;
12181 otherwise @command{tar} will write over the volume it just finished.)
12183 @cindex Volume number file
12184 @cindex volno file
12185 @anchor{volno-file}
12186 @opindex volno-file
12187 The volume number used by @command{tar} in its tape-changing prompt
12188 can be changed; if you give the
12189 @option{--volno-file=@var{file-of-number}} option, then
12190 @var{file-of-number} should be an non-existing file to be created, or
12191 else, a file already containing a decimal number.  That number will be
12192 used as the volume number of the first volume written.  When
12193 @command{tar} is finished, it will rewrite the file with the
12194 now-current volume number. (This does not change the volume number
12195 written on a tape label, as per @ref{label}, it @emph{only} affects
12196 the number used in the prompt.)
12198 @cindex End-of-archive info script
12199 @cindex Info script
12200 @anchor{info-script}
12201 @opindex info-script
12202 @opindex new-volume-script
12203 If you want more elaborate behavior than this, you can write a special
12204 @dfn{new volume script}, that will be responsible for changing the
12205 volume, and instruct @command{tar} to use it instead of its normal
12206 prompting procedure:
12208 @table @option
12209 @item --info-script=@var{command}
12210 @itemx --new-volume-script=@var{command}
12211 @itemx -F @var{command}
12212 Specify the command to invoke when switching volumes.  The @var{command}
12213 can be used to eject cassettes, or to broadcast messages such as
12214 @samp{Someone please come change my tape} when performing unattended
12215 backups.
12216 @end table
12218 The @var{command} can contain additional options, if such are needed.
12219 @xref{external, Running External Commands}, for a detailed discussion
12220 of the way @GNUTAR{} runs external commands.  It inherits
12221 @command{tar}'s shell environment.  Additional data is passed to it
12222 via the following environment variables:
12224 @table @env
12225 @vrindex TAR_VERSION, info script environment variable
12226 @item TAR_VERSION
12227 @GNUTAR{} version number.
12229 @vrindex TAR_ARCHIVE, info script environment variable
12230 @item TAR_ARCHIVE
12231 The name of the archive @command{tar} is processing.
12233 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
12234 @item TAR_BLOCKING_FACTOR
12235 Current blocking factor (@pxref{Blocking}).
12237 @vrindex TAR_VOLUME, info script environment variable
12238 @item TAR_VOLUME
12239 Ordinal number of the volume @command{tar} is about to start.
12241 @vrindex TAR_SUBCOMMAND, info script environment variable
12242 @item TAR_SUBCOMMAND
12243 A short option describing the operation @command{tar} is executing.
12244 @xref{Operations}, for a complete list of subcommand options.
12246 @vrindex TAR_FORMAT, info script environment variable
12247 @item TAR_FORMAT
12248 Format of the archive being processed. @xref{Formats}, for a complete
12249 list of archive format names.
12251 @vrindex TAR_FD, info script environment variable
12252 @item TAR_FD
12253 File descriptor which can be used to communicate the new volume
12254 name to @command{tar}.
12255 @end table
12257 These variables can be used in the @var{command} itself, provided that
12258 they are properly quoted to prevent them from being expanded by the
12259 shell that invokes @command{tar}.
12261 The volume script can instruct @command{tar} to use new archive name,
12262 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
12264 If the info script fails, @command{tar} exits; otherwise, it begins
12265 writing the next volume.
12267 If you want @command{tar} to cycle through a series of files or tape
12268 drives, there are three approaches to choose from.  First of all, you
12269 can give @command{tar} multiple @option{--file} options.  In this case
12270 the specified files will be used, in sequence, as the successive
12271 volumes of the archive.  Only when the first one in the sequence needs
12272 to be used again will @command{tar} prompt for a tape change (or run
12273 the info script).  For example, suppose someone has two tape drives on
12274 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
12275 @GNUTAR{} to switch to the second drive when it needs to write the
12276 second tape, and then back to the first tape, etc., just do either of:
12278 @smallexample
12279 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
12280 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
12281 @end smallexample
12283 The second method is to use the @samp{n} response to the tape-change
12284 prompt.
12286 Finally, the most flexible approach is to use a volume script, that
12287 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
12288 following volume script will create a series of archive files, named
12289 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
12290 archive being created (as given by @option{--file} option) and
12291 @var{vol} is the ordinal number of the archive being created:
12293 @smallexample
12294 @group
12295 #! /bin/bash
12296 # For this script it's advisable to use a shell, such as Bash,
12297 # that supports a TAR_FD value greater than 9.
12299 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
12301 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
12302 case $TAR_SUBCOMMAND in
12303 -c)       ;;
12304 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
12305           ;;
12306 *)        exit 1
12307 esac
12309 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
12310 @end group
12311 @end smallexample
12313 The same script can be used while listing, comparing or extracting
12314 from the created archive.  For example:
12316 @smallexample
12317 @group
12318 # @r{Create a multi-volume archive:}
12319 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
12320 # @r{Extract from the created archive:}
12321 $ @kbd{tar -x -f archive.tar -F new-volume .}
12322 @end group
12323 @end smallexample
12325 @noindent
12326 Notice, that the first command had to use @option{-L} option, since
12327 otherwise @GNUTAR{} will end up writing everything to file
12328 @file{archive.tar}.
12330 You can read each individual volume of a multi-volume archive as if it
12331 were an archive by itself.  For example, to list the contents of one
12332 volume, use @option{--list}, without @option{--multi-volume} specified.
12333 To extract an archive member from one volume (assuming it is described
12334 that volume), use @option{--extract}, again without
12335 @option{--multi-volume}.
12337 If an archive member is split across volumes (i.e., its entry begins on
12338 one volume of the media and ends on another), you need to specify
12339 @option{--multi-volume} to extract it successfully.  In this case, you
12340 should load the volume where the archive member starts, and use
12341 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
12342 volumes as it needs them.  @xref{extracting archives}, for more
12343 information about extracting archives.
12345 Multi-volume archives can be modified like any other archive.  To add
12346 files to a multi-volume archive, you need to only mount the last
12347 volume of the archive media (and new volumes, if needed).  For all
12348 other operations, you need to use the entire archive.
12350 If a multi-volume archive was labeled using
12351 @option{--label=@var{archive-label}} (@pxref{label}) when it was
12352 created, @command{tar} will not automatically label volumes which are
12353 added later.  To label subsequent volumes, specify
12354 @option{--label=@var{archive-label}} again in conjunction with the
12355 @option{--append}, @option{--update} or @option{--concatenate} operation.
12357 Notice that multi-volume support is a GNU extension and the archives
12358 created in this mode should be read only using @GNUTAR{}.  If you
12359 absolutely have to process such archives using a third-party @command{tar}
12360 implementation, read @ref{Split Recovery}.
12362 @node Tape Files
12363 @subsection Tape Files
12364 @cindex labeling archives
12365 @opindex label
12366 @UNREVISED{}
12368 To give the archive a name which will be recorded in it, use the
12369 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
12370 option.  This will write a special block identifying
12371 @var{volume-label} as the name of the archive to the front of the
12372 archive which will be displayed when the archive is listed with
12373 @option{--list}.  If you are creating a multi-volume archive with
12374 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
12375 volume label will have @samp{Volume @var{nnn}} appended to the name
12376 you give, where @var{nnn} is the number of the volume of the archive.
12377 If you use the @option{--label=@var{volume-label}} option when
12378 reading an archive, it checks to make sure the label on the tape
12379 matches the one you gave.  @xref{label}.
12381 When @command{tar} writes an archive to tape, it creates a single
12382 tape file.  If multiple archives are written to the same tape, one
12383 after the other, they each get written as separate tape files.  When
12384 extracting, it is necessary to position the tape at the right place
12385 before running @command{tar}.  To do this, use the @command{mt} command.
12386 For more information on the @command{mt} command and on the organization
12387 of tapes into a sequence of tape files, see @ref{mt}.
12389 People seem to often do:
12391 @smallexample
12392 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
12393 @end smallexample
12395 or such, for pushing a common date in all volumes or an archive set.
12397 @node Tarcat
12398 @subsection Concatenate Volumes into a Single Archive
12400 @pindex tarcat
12401   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
12402 archive to a single @command{tar} archive.  Simply concatenating all
12403 volumes into one will not work, since each volume carries an additional
12404 information at the beginning.  @GNUTAR{} is shipped with the shell
12405 script @command{tarcat} designed for this purpose.
12407   The script takes a list of files comprising a multi-volume archive
12408 and creates the resulting archive at the standard output.  For example:
12410 @smallexample
12411 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
12412 @end smallexample
12414   The script implements a simple heuristics to determine the format of
12415 the first volume file and to decide how to process the rest of the
12416 files.  However, it makes no attempt to verify whether the files are
12417 given in order or even if they are valid @command{tar} archives.
12418 It uses @command{dd} and does not filter its standard error, so you
12419 will usually see lots of spurious messages.
12421 @FIXME{The script is not installed.  Should we install it?}
12423 @node label
12424 @section Including a Label in the Archive
12425 @cindex Labeling an archive
12426 @cindex Labels on the archive media
12427 @cindex Labeling multi-volume archives
12429 @opindex label
12430   To avoid problems caused by misplaced paper labels on the archive
12431 media, you can include a @dfn{label} entry --- an archive member which
12432 contains the name of the archive --- in the archive itself.  Use the
12433 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12434 option@footnote{Until version 1.10, that option was called
12435 @option{--volume}, but is not available under that name anymore.} in
12436 conjunction with the @option{--create} operation to include a label
12437 entry in the archive as it is being created.
12439 @table @option
12440 @item --label=@var{archive-label}
12441 @itemx -V @var{archive-label}
12442 Includes an @dfn{archive-label} at the beginning of the archive when
12443 the archive is being created, when used in conjunction with the
12444 @option{--create} operation.  Checks to make sure the archive label
12445 matches the one specified (when used in conjunction with any other
12446 operation).
12447 @end table
12449   If you create an archive using both
12450 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12451 and @option{--multi-volume} (@option{-M}), each volume of the archive
12452 will have an archive label of the form @samp{@var{archive-label}
12453 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
12454 next, and so on. @xref{Using Multiple Tapes}, for information on
12455 creating multiple volume archives.
12457 @cindex Volume label, listing
12458 @cindex Listing volume label
12459   The volume label will be displayed by @option{--list} along with
12460 the file contents.  If verbose display is requested, it will also be
12461 explicitly marked as in the example below:
12463 @smallexample
12464 @group
12465 $ @kbd{tar --verbose --list --file=iamanarchive}
12466 V--------- 0/0               0 1992-03-07 12:01 iamalabel--Volume Header--
12467 -rw-r--r-- ringo/user       40 1990-05-21 13:30 iamafilename
12468 @end group
12469 @end smallexample
12471 @opindex test-label
12472 @anchor{--test-label option}
12473   However, @option{--list} option will cause listing entire
12474 contents of the archive, which may be undesirable (for example, if the
12475 archive is stored on a tape).  You can request checking only the volume
12476 label by specifying @option{--test-label} option.  This option reads only the
12477 first block of an archive, so it can be used with slow storage
12478 devices.  For example:
12480 @smallexample
12481 @group
12482 $ @kbd{tar --test-label --file=iamanarchive}
12483 iamalabel
12484 @end group
12485 @end smallexample
12487   If @option{--test-label} is used with one or more command line
12488 arguments, @command{tar} compares the volume label with each
12489 argument.  It exits with code 0 if a match is found, and with code 1
12490 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
12491 mismatch with an exit code 2 and printed a spurious diagnostics on
12492 stderr.}.  No output is displayed, unless you also used the
12493 @option{--verbose} option.  For example:
12495 @smallexample
12496 @group
12497 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
12498 @result{} 0
12499 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
12500 @result{} 1
12501 @end group
12502 @end smallexample
12504   When used with the @option{--verbose} option, @command{tar}
12505 prints the actual volume label (if any), and a verbose diagnostics in
12506 case of a mismatch:
12508 @smallexample
12509 @group
12510 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
12511 iamalabel
12512 @result{} 0
12513 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
12514 iamalabel
12515 tar: Archive label mismatch
12516 @result{} 1
12517 @end group
12518 @end smallexample
12520   If you request any operation, other than @option{--create}, along
12521 with using @option{--label} option, @command{tar} will first check if
12522 the archive label matches the one specified and will refuse to proceed
12523 if it does not.  Use this as a safety precaution to avoid accidentally
12524 overwriting existing archives.  For example, if you wish to add files
12525 to @file{archive}, presumably labeled with string @samp{My volume},
12526 you will get:
12528 @smallexample
12529 @group
12530 $ @kbd{tar -rf archive --label 'My volume' .}
12531 tar: Archive not labeled to match 'My volume'
12532 @end group
12533 @end smallexample
12535 @noindent
12536 in case its label does not match.  This will work even if
12537 @file{archive} is not labeled at all.
12539   Similarly, @command{tar} will refuse to list or extract the
12540 archive if its label doesn't match the @var{archive-label}
12541 specified.  In those cases, @var{archive-label} argument is interpreted
12542 as a globbing-style pattern which must match the actual magnetic
12543 volume label.  @xref{exclude}, for a precise description of how match
12544 is attempted@footnote{Previous versions of @command{tar} used full
12545 regular expression matching, or before that, only exact string
12546 matching, instead of wildcard matchers.  We decided for the sake of
12547 simplicity to use a uniform matching device through
12548 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
12549 the volume label matcher will also suffix @var{archive-label} by
12550 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
12551 up.  Since the volume numbering is automatically added in labels at
12552 creation time, it sounded logical to equally help the user taking care
12553 of it when the archive is being read.
12555   You can also use @option{--label} to get a common information on
12556 all tapes of a series.  For having this information different in each
12557 series created through a single script used on a regular basis, just
12558 manage to get some date string as part of the label.  For example:
12560 @smallexample
12561 @group
12562 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
12563 $ @kbd{tar --create --file=/dev/tape --multi-volume \
12564      --label="Daily backup for `date +%Y-%m-%d`"}
12565 @end group
12566 @end smallexample
12568   Some more notes about volume labels:
12570 @itemize @bullet
12571 @item Each label has its own date and time, which corresponds
12572 to the time when @GNUTAR{} initially attempted to write it,
12573 often soon after the operator launches @command{tar} or types the
12574 carriage return telling that the next tape is ready.
12576 @item Comparing date labels to get an idea of tape throughput is
12577 unreliable.  It gives correct results only if the delays for rewinding
12578 tapes and the operator switching them were negligible, which is
12579 usually not the case.
12580 @end itemize
12582 @node verify
12583 @section Verifying Data as It is Stored
12584 @cindex Verifying a write operation
12585 @cindex Double-checking a write operation
12587 @table @option
12588 @item -W
12589 @itemx --verify
12590 @opindex verify, short description
12591 Attempt to verify the archive after writing.
12592 @end table
12594 This option causes @command{tar} to verify the archive after writing it.
12595 Each volume is checked after it is written, and any discrepancies
12596 are recorded on the standard error output.
12598 Verification requires that the archive be on a back-space-able medium.
12599 This means pipes, some cartridge tape drives, and some other devices
12600 cannot be verified.
12602 You can insure the accuracy of an archive by comparing files in the
12603 system with archive members.  @command{tar} can compare an archive to the
12604 file system as the archive is being written, to verify a write
12605 operation, or can compare a previously written archive, to insure that
12606 it is up to date.
12608 @xopindex{verify, using with @option{--create}}
12609 @xopindex{create, using with @option{--verify}}
12610 To check for discrepancies in an archive immediately after it is
12611 written, use the @option{--verify} (@option{-W}) option in conjunction with
12612 the @option{--create} operation.  When this option is
12613 specified, @command{tar} checks archive members against their counterparts
12614 in the file system, and reports discrepancies on the standard error.
12616 To verify an archive, you must be able to read it from before the end
12617 of the last written entry.  This option is useful for detecting data
12618 errors on some tapes.  Archives written to pipes, some cartridge tape
12619 drives, and some other devices cannot be verified.
12621 One can explicitly compare an already made archive with the file
12622 system by using the @option{--compare} (@option{--diff}, @option{-d})
12623 option, instead of using the more automatic @option{--verify} option.
12624 @xref{compare}.
12626 Note that these two options have a slightly different intent.  The
12627 @option{--compare} option checks how identical are the logical contents of some
12628 archive with what is on your disks, while the @option{--verify} option is
12629 really for checking if the physical contents agree and if the recording
12630 media itself is of dependable quality.  So, for the @option{--verify}
12631 operation, @command{tar} tries to defeat all in-memory cache pertaining to
12632 the archive, while it lets the speed optimization undisturbed for the
12633 @option{--compare} option.  If you nevertheless use @option{--compare} for
12634 media verification, you may have to defeat the in-memory cache yourself,
12635 maybe by opening and reclosing the door latch of your recording unit,
12636 forcing some doubt in your operating system about the fact this is really
12637 the same volume as the one just written or read.
12639 The @option{--verify} option would not be necessary if drivers were indeed
12640 able to detect dependably all write failures.  This sometimes require many
12641 magnetic heads, some able to read after the writes occurred.  One would
12642 not say that drivers unable to detect all cases are necessarily flawed,
12643 as long as programming is concerned.
12645 The @option{--verify} (@option{-W}) option will not work in
12646 conjunction with the @option{--multi-volume} (@option{-M}) option or
12647 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
12648 and @option{--delete} operations.  @xref{Operations}, for more
12649 information on these operations.
12651 Also, since @command{tar} normally strips leading @samp{/} from file
12652 names (@pxref{absolute}), a command like @samp{tar --verify -cf
12653 /tmp/foo.tar /etc} will work as desired only if the working directory is
12654 @file{/}, as @command{tar} uses the archive's relative member names
12655 (e.g., @file{etc/motd}) when verifying the archive.
12657 @node Write Protection
12658 @section Write Protection
12660 Almost all tapes and diskettes, and in a few rare cases, even disks can
12661 be @dfn{write protected}, to protect data on them from being changed.
12662 Once an archive is written, you should write protect the media to prevent
12663 the archive from being accidentally overwritten or deleted.  (This will
12664 protect the archive from being changed with a tape or floppy drive---it
12665 will not protect it from magnet fields or other physical hazards.)
12667 The write protection device itself is usually an integral part of the
12668 physical media, and can be a two position (write enabled/write
12669 disabled) switch, a notch which can be popped out or covered, a ring
12670 which can be removed from the center of a tape reel, or some other
12671 changeable feature.
12673 @node Reliability and security
12674 @chapter Reliability and Security
12676 The @command{tar} command reads and writes files as any other
12677 application does, and is subject to the usual caveats about
12678 reliability and security.  This section contains some commonsense
12679 advice on the topic.
12681 @menu
12682 * Reliability::
12683 * Security::
12684 @end menu
12686 @node Reliability
12687 @section Reliability
12689 Ideally, when @command{tar} is creating an archive, it reads from a
12690 file system that is not being modified, and encounters no errors or
12691 inconsistencies while reading and writing.  If this is the case, the
12692 archive should faithfully reflect what was read.  Similarly, when
12693 extracting from an archive, ideally @command{tar} ideally encounters
12694 no errors and the extracted files faithfully reflect what was in the
12695 archive.
12697 However, when reading or writing real-world file systems, several
12698 things can go wrong; these include permissions problems, corruption of
12699 data, and race conditions.
12701 @menu
12702 * Permissions problems::
12703 * Data corruption and repair::
12704 * Race conditions::
12705 @end menu
12707 @node Permissions problems
12708 @subsection Permissions Problems
12710 If @command{tar} encounters errors while reading or writing files, it
12711 normally reports an error and exits with nonzero status.  The work it
12712 does may therefore be incomplete.  For example, when creating an
12713 archive, if @command{tar} cannot read a file then it cannot copy the
12714 file into the archive.
12716 @node Data corruption and repair
12717 @subsection Data Corruption and Repair
12719 If an archive becomes corrupted by an I/O error, this may corrupt the
12720 data in an extracted file.  Worse, it may corrupt the file's metadata,
12721 which may cause later parts of the archive to become misinterpreted.
12722 An tar-format archive contains a checksum that most likely will detect
12723 errors in the metadata, but it will not detect errors in the data.
12725 If data corruption is a concern, you can compute and check your own
12726 checksums of an archive by using other programs, such as
12727 @command{cksum}.
12729 When attempting to recover from a read error or data corruption in an
12730 archive, you may need to skip past the questionable data and read the
12731 rest of the archive.  This requires some expertise in the archive
12732 format and in other software tools.
12734 @node Race conditions
12735 @subsection Race conditions
12737 If some other process is modifying the file system while @command{tar}
12738 is reading or writing files, the result may well be inconsistent due
12739 to race conditions.  For example, if another process creates some
12740 files in a directory while @command{tar} is creating an archive
12741 containing the directory's files, @command{tar} may see some of the
12742 files but not others, or it may see a file that is in the process of
12743 being created.  The resulting archive may not be a snapshot of the
12744 file system at any point in time.  If an application such as a
12745 database system depends on an accurate snapshot, restoring from the
12746 @command{tar} archive of a live file system may therefore break that
12747 consistency and may break the application.  The simplest way to avoid
12748 the consistency issues is to avoid making other changes to the file
12749 system while tar is reading it or writing it.
12751 When creating an archive, several options are available to avoid race
12752 conditions.  Some hosts have a way of snapshotting a file system, or
12753 of temporarily suspending all changes to a file system, by (say)
12754 suspending the only virtual machine that can modify a file system; if
12755 you use these facilities and have @command{tar -c} read from a
12756 snapshot when creating an archive, you can avoid inconsistency
12757 problems.  More drastically, before starting @command{tar} you could
12758 suspend or shut down all processes other than @command{tar} that have
12759 access to the file system, or you could unmount the file system and
12760 then mount it read-only.
12762 When extracting from an archive, one approach to avoid race conditions
12763 is to create a directory that no other process can write to, and
12764 extract into that.
12766 @node Security
12767 @section Security
12769 In some cases @command{tar} may be used in an adversarial situation,
12770 where an untrusted user is attempting to gain information about or
12771 modify otherwise-inaccessible files.  Dealing with untrusted data
12772 (that is, data generated by an untrusted user) typically requires
12773 extra care, because even the smallest mistake in the use of
12774 @command{tar} is more likely to be exploited by an adversary than by a
12775 race condition.
12777 @menu
12778 * Privacy::
12779 * Integrity::
12780 * Live untrusted data::
12781 * Security rules of thumb::
12782 @end menu
12784 @node Privacy
12785 @subsection Privacy
12787 Standard privacy concerns apply when using @command{tar}.  For
12788 example, suppose you are archiving your home directory into a file
12789 @file{/archive/myhome.tar}.  Any secret information in your home
12790 directory, such as your SSH secret keys, are copied faithfully into
12791 the archive.  Therefore, if your home directory contains any file that
12792 should not be read by some other user, the archive itself should be
12793 not be readable by that user.  And even if the archive's data are
12794 inaccessible to untrusted users, its metadata (such as size or
12795 last-modified date) may reveal some information about your home
12796 directory; if the metadata are intended to be private, the archive's
12797 parent directory should also be inaccessible to untrusted users.
12799 One precaution is to create @file{/archive} so that it is not
12800 accessible to any user, unless that user also has permission to access
12801 all the files in your home directory.
12803 Similarly, when extracting from an archive, take care that the
12804 permissions of the extracted files are not more generous than what you
12805 want.  Even if the archive itself is readable only to you, files
12806 extracted from it have their own permissions that may differ.
12808 @node Integrity
12809 @subsection Integrity
12811 When creating archives, take care that they are not writable by a
12812 untrusted user; otherwise, that user could modify the archive, and
12813 when you later extract from the archive you will get incorrect data.
12815 When @command{tar} extracts from an archive, by default it writes into
12816 files relative to the working directory.  If the archive was generated
12817 by an untrusted user, that user therefore can write into any file
12818 under the working directory.  If the working directory contains a
12819 symbolic link to another directory, the untrusted user can also write
12820 into any file under the referenced directory.  When extracting from an
12821 untrusted archive, it is therefore good practice to create an empty
12822 directory and run @command{tar} in that directory.
12824 When extracting from two or more untrusted archives, each one should
12825 be extracted independently, into different empty directories.
12826 Otherwise, the first archive could create a symbolic link into an area
12827 outside the working directory, and the second one could follow the
12828 link and overwrite data that is not under the working directory.  For
12829 example, when restoring from a series of incremental dumps, the
12830 archives should have been created by a trusted process, as otherwise
12831 the incremental restores might alter data outside the working
12832 directory.
12834 If you use the @option{--absolute-names} (@option{-P}) option when
12835 extracting, @command{tar} respects any file names in the archive, even
12836 file names that begin with @file{/} or contain @file{..}.  As this
12837 lets the archive overwrite any file in your system that you can write,
12838 the @option{--absolute-names} (@option{-P}) option should be used only
12839 for trusted archives.
12841 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12842 @option{--skip-old-files} options, @command{tar} refuses to replace
12843 existing files when extracting.  The difference between the two
12844 options is that the former treats existing files as errors whereas the
12845 latter just silently ignores them.
12847 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12848 refuses to replace the permissions or ownership of already-existing
12849 directories.  These options may help when extracting from untrusted
12850 archives.
12852 @node Live untrusted data
12853 @subsection Dealing with Live Untrusted Data
12855 Extra care is required when creating from or extracting into a file
12856 system that is accessible to untrusted users.  For example, superusers
12857 who invoke @command{tar} must be wary about its actions being hijacked
12858 by an adversary who is reading or writing the file system at the same
12859 time that @command{tar} is operating.
12861 When creating an archive from a live file system, @command{tar} is
12862 vulnerable to denial-of-service attacks.  For example, an adversarial
12863 user could create the illusion of an indefinitely-deep directory
12864 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12865 @command{tar}, or the illusion of an indefinitely-long file by
12866 creating a sparse file but arranging for blocks to be allocated just
12867 before @command{tar} reads them.  There is no easy way for
12868 @command{tar} to distinguish these scenarios from legitimate uses, so
12869 you may need to monitor @command{tar}, just as you'd need to monitor
12870 any other system service, to detect such attacks.
12872 While a superuser is extracting from an archive into a live file
12873 system, an untrusted user might replace a directory with a symbolic
12874 link, in hopes that @command{tar} will follow the symbolic link and
12875 extract data into files that the untrusted user does not have access
12876 to.  Even if the archive was generated by the superuser, it may
12877 contain a file such as @file{d/etc/passwd} that the untrusted user
12878 earlier created in order to break in; if the untrusted user replaces
12879 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12880 @command{tar} is running, @command{tar} will overwrite
12881 @file{/etc/passwd}.  This attack can be prevented by extracting into a
12882 directory that is inaccessible to untrusted users.
12884 Similar attacks via symbolic links are also possible when creating an
12885 archive, if the untrusted user can modify an ancestor of a top-level
12886 argument of @command{tar}.  For example, an untrusted user that can
12887 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12888 - /home/eve/Documents/yesterday} by replacing
12889 @file{/home/eve/Documents} with a symbolic link to some other
12890 location.  Attacks like these can be prevented by making sure that
12891 untrusted users cannot modify any files that are top-level arguments
12892 to @command{tar}, or any ancestor directories of these files.
12894 @node Security rules of thumb
12895 @subsection Security Rules of Thumb
12897 This section briefly summarizes rules of thumb for avoiding security
12898 pitfalls.
12900 @itemize @bullet
12902 @item
12903 Protect archives at least as much as you protect any of the files
12904 being archived.
12906 @item
12907 Extract from an untrusted archive only into an otherwise-empty
12908 directory.  This directory and its parent should be accessible only to
12909 trusted users.  For example:
12911 @example
12912 @group
12913 $ @kbd{chmod go-rwx .}
12914 $ @kbd{mkdir -m go-rwx dir}
12915 $ @kbd{cd dir}
12916 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12917 @end group
12918 @end example
12920 As a corollary, do not do an incremental restore from an untrusted archive.
12922 @item
12923 Do not let untrusted users access files extracted from untrusted
12924 archives without checking first for problems such as setuid programs.
12926 @item
12927 Do not let untrusted users modify directories that are ancestors of
12928 top-level arguments of @command{tar}.  For example, while you are
12929 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12930 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12932 @item
12933 Pay attention to the diagnostics and exit status of @command{tar}.
12935 @item
12936 When archiving live file systems, monitor running instances of
12937 @command{tar} to detect denial-of-service attacks.
12939 @item
12940 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12941 @option{--dereference} (@option{-h}), @option{--overwrite},
12942 @option{--recursive-unlink}, and @option{--remove-files} unless you
12943 understand their security implications.
12945 @end itemize
12947 @node Changes
12948 @appendix Changes
12950 This appendix lists some important user-visible changes between
12951 various versions of @GNUTAR{}. An up-to-date version of this document
12952 is available at
12953 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12954 @GNUTAR{} documentation page}.
12956 @table @asis
12957 @item Use of globbing patterns when listing and extracting.
12959 Previous versions of GNU tar assumed shell-style globbing when
12960 extracting from or listing an archive.  For example:
12962 @smallexample
12963 $ @kbd{tar xf foo.tar '*.c'}
12964 @end smallexample
12966 would extract all files whose names end in @samp{.c}.  This behavior
12967 was not documented and was incompatible with traditional tar
12968 implementations.  Therefore, starting from version 1.15.91, GNU tar
12969 no longer uses globbing by default.  For example, the above invocation
12970 is now interpreted as a request to extract from the archive the file
12971 named @file{*.c}.
12973 To facilitate transition to the new behavior for those users who got
12974 used to the previous incorrect one, @command{tar} will print a warning
12975 if it finds out that a requested member was not found in the archive
12976 and its name looks like a globbing pattern.  For example:
12978 @smallexample
12979 $ @kbd{tar xf foo.tar  '*.c'}
12980 tar: Pattern matching characters used in file names. Please,
12981 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12982 tar: suppress this warning.
12983 tar: *.c: Not found in archive
12984 tar: Error exit delayed from previous errors
12985 @end smallexample
12987 To treat member names as globbing patterns, use the @option{--wildcards} option.
12988 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12989 add this option to your @env{TAR_OPTIONS} variable.
12991 @xref{wildcards}, for the detailed discussion of the use of globbing
12992 patterns by @GNUTAR{}.
12994 @item Use of short option @option{-o}.
12996 Earlier versions of @GNUTAR{} understood @option{-o} command line
12997 option as a synonym for @option{--old-archive}.
12999 @GNUTAR{} starting from version 1.13.90 understands this option as
13000 a synonym for @option{--no-same-owner}.  This is compatible with
13001 UNIX98 @command{tar} implementations.
13003 However, to facilitate transition, @option{-o} option retains its
13004 old semantics when it is used with one of archive-creation commands.
13005 Users are encouraged to use @option{--format=oldgnu} instead.
13007 It is especially important, since versions of @acronym{GNU} Automake
13008 up to and including 1.8.4 invoke tar with this option to produce
13009 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
13010 of this issue and its implications.
13012 @xref{Options, tar-formats, Changing Automake's Behavior,
13013 automake, GNU Automake}, for a description on how to use various
13014 archive formats with @command{automake}.
13016 Future versions of @GNUTAR{} will understand @option{-o} only as a
13017 synonym for @option{--no-same-owner}.
13019 @item Use of short option @option{-l}
13021 Earlier versions of @GNUTAR{} understood @option{-l} option as a
13022 synonym for @option{--one-file-system}.  Since such usage contradicted
13023 to UNIX98 specification and harmed compatibility with other
13024 implementations, it was declared deprecated in version 1.14.  However,
13025 to facilitate transition to its new semantics, it was supported by
13026 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
13027 variant of @option{--check-links} was introduced in version 1.15.91.
13029 @item Use of options @option{--portability} and @option{--old-archive}
13031 These options are deprecated.  Please use @option{--format=v7} instead.
13033 @item Use of option @option{--posix}
13035 This option is deprecated.  Please use @option{--format=posix} instead.
13036 @end table
13038 @node Recipes
13039 @appendix Recipes
13040 @include recipes.texi
13042 @node Configuring Help Summary
13043 @appendix Configuring Help Summary
13045 Running @kbd{tar --help} displays the short @command{tar} option
13046 summary (@pxref{help}). This summary is organized by @dfn{groups} of
13047 semantically close options. The options within each group are printed
13048 in the following order: a short option, eventually followed by a list
13049 of corresponding long option names, followed by a short description of
13050 the option. For example, here is an excerpt from the actual @kbd{tar
13051 --help} output:
13053 @verbatim
13054  Main operation mode:
13056   -A, --catenate, --concatenate   append tar files to an archive
13057   -c, --create               create a new archive
13058   -d, --diff, --compare      find differences between archive and
13059                              file system
13060       --delete               delete from the archive
13061 @end verbatim
13063 @vrindex ARGP_HELP_FMT, environment variable
13064 The exact visual representation of the help output is configurable via
13065 @env{ARGP_HELP_FMT} environment variable. The value of this variable
13066 is a comma-separated list of @dfn{format variable} assignments. There
13067 are two kinds of format variables. An @dfn{offset variable} keeps the
13068 offset of some part of help output text from the leftmost column on
13069 the screen. A @dfn{boolean} variable is a flag that toggles some
13070 output feature on or off. Depending on the type of the corresponding
13071 variable, there are two kinds of assignments:
13073 @table @asis
13074 @item Offset assignment
13076 The assignment to an offset variable has the following syntax:
13078 @smallexample
13079 @var{variable}=@var{value}
13080 @end smallexample
13082 @noindent
13083 where @var{variable} is the variable name, and @var{value} is a
13084 numeric value to be assigned to the variable.
13086 @item Boolean assignment
13088 To assign @code{true} value to a variable, simply put this variable name. To
13089 assign @code{false} value, prefix the variable name with @samp{no-}. For
13090 example:
13092 @smallexample
13093 @group
13094 # Assign @code{true} value:
13095 dup-args
13096 # Assign @code{false} value:
13097 no-dup-args
13098 @end group
13099 @end smallexample
13100 @end table
13102 Following variables are declared:
13104 @deftypevr {Help Output} boolean dup-args
13105 If true, arguments for an option are shown with both short and long
13106 options, even when a given option has both forms, for example:
13108 @smallexample
13109   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
13110 @end smallexample
13112 If false, then if an option has both short and long forms, the
13113 argument is only shown with the long one, for example:
13115 @smallexample
13116   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13117 @end smallexample
13119 @noindent
13120 and a message indicating that the argument is applicable to both
13121 forms is printed below the options. This message can be disabled
13122 using @code{dup-args-note} (see below).
13124 The default is false.
13125 @end deftypevr
13127 @deftypevr {Help Output} boolean dup-args-note
13128 If this variable is true, which is the default, the following notice
13129 is displayed at the end of the help output:
13131 @quotation
13132 Mandatory or optional arguments to long options are also mandatory or
13133 optional for any corresponding short options.
13134 @end quotation
13136 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
13137 variables @code{dup-args} or @code{dup-args-note} should be set.
13138 @end deftypevr
13140 @deftypevr {Help Output} offset short-opt-col
13141 Column in which short options start. Default is 2.
13143 @smallexample
13144 @group
13145 $ @kbd{tar --help|grep ARCHIVE}
13146   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13147 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
13148       -f, --file=ARCHIVE   use archive file or device ARCHIVE
13149 @end group
13150 @end smallexample
13151 @end deftypevr
13153 @deftypevr {Help Output} offset long-opt-col
13154 Column in which long options start. Default is 6. For example:
13156 @smallexample
13157 @group
13158 $ @kbd{tar --help|grep ARCHIVE}
13159   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13160 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
13161   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
13162 @end group
13163 @end smallexample
13164 @end deftypevr
13166 @deftypevr {Help Output} offset doc-opt-col
13167 Column in which @dfn{doc options} start.  A doc option isn't actually
13168 an option, but rather an arbitrary piece of documentation that is
13169 displayed in much the same manner as the options.  For example, in
13170 the description of @option{--format} option:
13172 @smallexample
13173 @group
13174   -H, --format=FORMAT        create archive of the given format.
13176  FORMAT is one of the following:
13178     gnu                      GNU tar 1.13.x format
13179     oldgnu                   GNU format as per tar <= 1.12
13180     pax                      POSIX 1003.1-2001 (pax) format
13181     posix                    same as pax
13182     ustar                    POSIX 1003.1-1988 (ustar) format
13183     v7                       old V7 tar format
13184 @end group
13185 @end smallexample
13187 @noindent
13188 the format names are doc options. Thus, if you set
13189 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
13190 will look as follows:
13192 @smallexample
13193 @group
13194   -H, --format=FORMAT        create archive of the given format.
13196  FORMAT is one of the following:
13198         gnu                      GNU tar 1.13.x format
13199         oldgnu                   GNU format as per tar <= 1.12
13200         pax                      POSIX 1003.1-2001 (pax) format
13201         posix                    same as pax
13202         ustar                    POSIX 1003.1-1988 (ustar) format
13203         v7                       old V7 tar format
13204 @end group
13205 @end smallexample
13206 @end deftypevr
13208 @deftypevr {Help Output} offset opt-doc-col
13209 Column in which option description starts. Default is 29.
13211 @smallexample
13212 @group
13213 $ @kbd{tar --help|grep ARCHIVE}
13214   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13215 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
13216   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13217 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
13218   -f, --file=ARCHIVE
13219            use archive file or device ARCHIVE
13220 @end group
13221 @end smallexample
13223 @noindent
13224 Notice, that the description starts on a separate line if
13225 @code{opt-doc-col} value is too small.
13226 @end deftypevr
13228 @deftypevr {Help Output} offset header-col
13229 Column in which @dfn{group headers} are printed.  A group header is a
13230 descriptive text preceding an option group.  For example, in the
13231 following text:
13233 @verbatim
13234  Main operation mode:
13236   -A, --catenate, --concatenate   append tar files to
13237                              an archive
13238   -c, --create               create a new archive
13239 @end verbatim
13240 @noindent
13241 @samp{Main operation mode:} is the group header.
13243 The default value is 1.
13244 @end deftypevr
13246 @deftypevr {Help Output} offset usage-indent
13247 Indentation of wrapped usage lines. Affects @option{--usage}
13248 output. Default is 12.
13249 @end deftypevr
13251 @deftypevr {Help Output} offset rmargin
13252 Right margin of the text output. Used for wrapping.
13253 @end deftypevr
13255 @node Fixing Snapshot Files
13256 @appendix Fixing Snapshot Files
13257 @include tar-snapshot-edit.texi
13259 @node Tar Internals
13260 @appendix Tar Internals
13261 @include intern.texi
13263 @node Genfile
13264 @appendix Genfile
13265 @include genfile.texi
13267 @node GNU Free Documentation License
13268 @appendix GNU Free Documentation License
13270 @include fdl.texi
13272 @node Index of Command Line Options
13273 @appendix Index of Command Line Options
13275 This appendix contains an index of all @GNUTAR{} long command line
13276 options. The options are listed without the preceding double-dash.
13277 For a cross-reference of short command line options, see
13278 @ref{Short Option Summary}.
13280 @printindex op
13282 @node Index
13283 @appendix Index
13285 @printindex cp
13287 @summarycontents
13288 @contents
13289 @bye
13291 @c Local variables:
13292 @c texinfo-column-for-description: 32
13293 @c End: