Fix typos in the documentation
[tar.git] / doc / tar.texi
bloba475c9b2f2d72fbed7de56f2cca879dfcb2796e2
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 @finalout
10 @smallbook
11 @c %**end of header
13 @c Maintenance notes:
14 @c  1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c  2. Before creating final variant:
16 @c    2.1. Run 'make check-options' to make sure all options are properly
17 @c         documented;
18 @c    2.2. Run 'make master-menu' (see comment before the master menu).
20 @include rendition.texi
21 @include value.texi
23 @defcodeindex op
24 @defcodeindex kw
26 @c Put everything in one index (arbitrarily chosen to be the concept index).
27 @syncodeindex fn cp
28 @syncodeindex ky cp
29 @syncodeindex pg cp
30 @syncodeindex vr cp
31 @syncodeindex kw cp
33 @copying
35 This manual is for @acronym{GNU} @command{tar} (version
36 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 from archives.
39 Copyright @copyright{} 1992, 1994--1997, 1999--2001, 2003--2017 Free
40 Software Foundation, Inc.
42 @quotation
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with the
46 Invariant Sections being ``GNU General Public License'', with the
47 Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
48 as in (a) below.  A copy of the license is included in the section
49 entitled ``GNU Free Documentation License''.
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual.''
53 @end quotation
54 @end copying
56 @dircategory Archiving
57 @direntry
58 * Tar: (tar).                   Making tape (or disk) archives.
59 @end direntry
61 @dircategory Individual utilities
62 @direntry
63 * tar: (tar)tar invocation.                     Invoking @GNUTAR{}.
64 @end direntry
66 @shorttitlepage @acronym{GNU} @command{tar}
68 @titlepage
69 @title @acronym{GNU} tar: an archiver tool
70 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
71 @author John Gilmore, Jay Fenlason et al.
73 @page
74 @vskip 0pt plus 1filll
75 @insertcopying
76 @end titlepage
78 @ifnottex
79 @node Top
80 @top @acronym{GNU} tar: an archiver tool
82 @insertcopying
84 @cindex file archival
85 @cindex archiving files
87 The first part of this master menu lists the major nodes in this Info
88 document.  The rest of the menu lists all the lower level nodes.
89 @end ifnottex
91 @c The master menu goes here.
93 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
94 @c loaded and run texinfo-master-menu.
95 @c To update it from the command line, run
97 @c    make master-menu
99 @menu
100 * Introduction::
101 * Tutorial::
102 * tar invocation::
103 * operations::
104 * Backups::
105 * Choosing::
106 * Date input formats::
107 * Formats::
108 * Media::
109 * Reliability and security::
111 Appendices
113 * Changes::
114 * Recipes:: Frequently used tar recipes
115 * Configuring Help Summary::
116 * Fixing Snapshot Files::
117 * Tar Internals::
118 * Genfile::
119 * Free Software Needs Free Documentation::
120 * GNU Free Documentation License::
121 * Index of Command Line Options::
122 * Index::
124 @detailmenu
125  --- The Detailed Node Listing ---
127 Introduction
129 * Book Contents::               What this Book Contains
130 * Definitions::                 Some Definitions
131 * What tar Does::               What @command{tar} Does
132 * Naming tar Archives::         How @command{tar} Archives are Named
133 * Authors::                     @GNUTAR{} Authors
134 * Reports::                     Reporting bugs or suggestions
136 Tutorial Introduction to @command{tar}
138 * assumptions::
139 * stylistic conventions::
140 * basic tar options::           Basic @command{tar} Operations and Options
141 * frequent operations::
142 * Two Frequent Options::
143 * create::                      How to Create Archives
144 * list::                        How to List Archives
145 * extract::                     How to Extract Members from an Archive
146 * going further::
148 Two Frequently Used Options
150 * file tutorial::
151 * verbose tutorial::
152 * help tutorial::
154 How to Create Archives
156 * prepare for examples::
157 * Creating the archive::
158 * create verbose::
159 * short create::
160 * create dir::
162 How to List Archives
164 * list dir::
166 How to Extract Members from an Archive
168 * extracting archives::
169 * extracting files::
170 * extract dir::
171 * extracting untrusted archives::
172 * failing commands::
174 Invoking @GNUTAR{}
176 * Synopsis::
177 * using tar options::
178 * Styles::
179 * All Options::
180 * help::
181 * defaults::
182 * verbose::
183 * checkpoints::
184 * warnings::
185 * interactive::
187 The Three Option Styles
189 * Long Options::                Long Option Style
190 * Short Options::               Short Option Style
191 * Old Options::                 Old Option Style
192 * Mixing::                      Mixing Option Styles
194 All @command{tar} Options
196 * Operation Summary::
197 * Option Summary::
198 * Short Option Summary::
199 * Position-Sensitive Options::
201 @GNUTAR{} Operations
203 * Basic tar::
204 * Advanced tar::
205 * create options::
206 * extract options::
207 * backup::
208 * looking ahead::
210 Advanced @GNUTAR{} Operations
212 * Operations::
213 * append::
214 * update::
215 * concatenate::
216 * delete::
217 * compare::
219 How to Add Files to Existing Archives: @option{--append}
221 * appending files::             Appending Files to an Archive
222 * multiple::
224 Updating an Archive
226 * how to update::
228 Options Used by @option{--create}
230 * override::                  Overriding File Metadata.
231 * Extended File Attributes::
232 * Ignore Failed Read::
234 Options Used by @option{--extract}
236 * Reading::                     Options to Help Read Archives
237 * Writing::                     Changing How @command{tar} Writes Files
238 * Scarce::                      Coping with Scarce Resources
240 Options to Help Read Archives
242 * read full records::
243 * Ignore Zeros::
245 Changing How @command{tar} Writes Files
247 * Dealing with Old Files::
248 * Overwrite Old Files::
249 * Keep Old Files::
250 * Keep Newer Files::
251 * Unlink First::
252 * Recursive Unlink::
253 * Data Modification Times::
254 * Setting Access Permissions::
255 * Directory Modification Times and Permissions::
256 * Writing to Standard Output::
257 * Writing to an External Program::
258 * remove files::
260 Coping with Scarce Resources
262 * Starting File::
263 * Same Order::
265 Performing Backups and Restoring Files
267 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
268 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
269 * Backup Levels::               Levels of Backups
270 * Backup Parameters::           Setting Parameters for Backups and Restoration
271 * Scripted Backups::            Using the Backup Scripts
272 * Scripted Restoration::        Using the Restore Script
274 Setting Parameters for Backups and Restoration
276 * General-Purpose Variables::
277 * Magnetic Tape Control::
278 * User Hooks::
279 * backup-specs example::        An Example Text of @file{Backup-specs}
281 Choosing Files and Names for @command{tar}
283 * file::                        Choosing the Archive's Name
284 * Selecting Archive Members::
285 * files::                       Reading Names from a File
286 * exclude::                     Excluding Some Files
287 * wildcards::                   Wildcards Patterns and Matching
288 * quoting styles::              Ways of Quoting Special Characters in Names
289 * transform::                   Modifying File and Member Names
290 * after::                       Operating Only on New Files
291 * recurse::                     Descending into Directories
292 * one::                         Crossing File System Boundaries
294 Reading Names from a File
296 * nul::
298 Excluding Some Files
300 * problems with exclude::
302 Wildcards Patterns and Matching
304 * controlling pattern-matching::
306 Crossing File System Boundaries
308 * directory::                   Changing Directory
309 * absolute::                    Absolute File Names
311 Date input formats
313 * General date syntax::            Common rules.
314 * Calendar date items::            19 Dec 1994.
315 * Time of day items::              9:20pm.
316 * Time zone items::                @sc{est}, @sc{pdt}, @sc{gmt}.
317 * Day of week items::              Monday and others.
318 * Relative items in date strings:: next tuesday, 2 years ago.
319 * Pure numbers in date strings::   19931219, 1440.
320 * Seconds since the Epoch::        @@1078100502.
321 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
322 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
324 Controlling the Archive Format
326 * Compression::                 Using Less Space through Compression
327 * Attributes::                  Handling File Attributes
328 * Portability::                 Making @command{tar} Archives More Portable
329 * cpio::                        Comparison of @command{tar} and @command{cpio}
331 Using Less Space through Compression
333 * gzip::                        Creating and Reading Compressed Archives
334 * sparse::                      Archiving Sparse Files
336 Creating and Reading Compressed Archives
338 * lbzip2::  Using lbzip2 with @GNUTAR{}.
340 Making @command{tar} Archives More Portable
342 * Portable Names::              Portable Names
343 * dereference::                 Symbolic Links
344 * hard links::                  Hard Links
345 * old::                         Old V7 Archives
346 * ustar::                       Ustar Archives
347 * gnu::                         GNU and old GNU format archives.
348 * posix::                       @acronym{POSIX} archives
349 * Checksumming::                Checksumming Problems
350 * Large or Negative Values::    Large files, negative time stamps, etc.
351 * Other Tars::                  How to Extract GNU-Specific Data Using
352                                 Other @command{tar} Implementations
354 @GNUTAR{} and @acronym{POSIX} @command{tar}
356 * PAX keywords:: Controlling Extended Header Keywords.
358 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
360 * Split Recovery::       Members Split Between Volumes
361 * Sparse Recovery::      Sparse Members
363 Tapes and Other Archive Media
365 * Device::                      Device selection and switching
366 * Remote Tape Server::
367 * Common Problems and Solutions::
368 * Blocking::                    Blocking
369 * Many::                        Many archives on one tape
370 * Using Multiple Tapes::        Using Multiple Tapes
371 * label::                       Including a Label in the Archive
372 * verify::
373 * Write Protection::
375 Blocking
377 * Format Variations::           Format Variations
378 * Blocking Factor::             The Blocking Factor of an Archive
380 Many Archives on One Tape
382 * Tape Positioning::            Tape Positions and Tape Marks
383 * mt::                          The @command{mt} Utility
385 Using Multiple Tapes
387 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
388 * Tape Files::                  Tape Files
389 * Tarcat::                      Concatenate Volumes into a Single Archive
392 Tar Internals
394 * Standard::           Basic Tar Format
395 * Extensions::         @acronym{GNU} Extensions to the Archive Format
396 * Sparse Formats::     Storing Sparse Files
397 * Snapshot Files::
398 * Dumpdir::
400 Storing Sparse Files
402 * Old GNU Format::
403 * PAX 0::                PAX Format, Versions 0.0 and 0.1
404 * PAX 1::                PAX Format, Version 1.0
406 Genfile
408 * Generate Mode::     File Generation Mode.
409 * Status Mode::       File Status Mode.
410 * Exec Mode::         Synchronous Execution mode.
412 Copying This Manual
414 * GNU Free Documentation License::  License for copying this manual
416 @end detailmenu
417 @end menu
419 @node Introduction
420 @chapter Introduction
422 @GNUTAR{} creates
423 and manipulates @dfn{archives} which are actually collections of
424 many other files; the program provides users with an organized and
425 systematic method for controlling a large amount of data.
426 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
427 archives need not (and these days, typically do not) reside on tapes.
429 @menu
430 * Book Contents::               What this Book Contains
431 * Definitions::                 Some Definitions
432 * What tar Does::               What @command{tar} Does
433 * Naming tar Archives::         How @command{tar} Archives are Named
434 * Authors::                     @GNUTAR{} Authors
435 * Reports::                     Reporting bugs or suggestions
436 @end menu
438 @node Book Contents
439 @section What this Book Contains
441 The first part of this chapter introduces you to various terms that will
442 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
443 and its documentation, and where you should send bug reports
444 or comments.
446 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
447 gentle introduction for people who are new to using @command{tar}.  It is
448 meant to be self-contained, not requiring any reading from subsequent
449 chapters to make sense.  It moves from topic to topic in a logical,
450 progressive order, building on information already explained.
452 Although the tutorial is paced and structured to allow beginners to
453 learn how to use @command{tar}, it is not intended solely for beginners.
454 The tutorial explains how to use the three most frequently used
455 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
456 two frequently used options (@samp{file} and @samp{verbose}).  The other
457 chapters do not refer to the tutorial frequently; however, if a section
458 discusses something which is a complex variant of a basic concept, there
459 may be a cross-reference to that basic concept.  (The entire book,
460 including the tutorial, assumes that the reader understands some basic
461 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
463 The third chapter presents the remaining five operations, and
464 information about using @command{tar} options and option syntax.
466 The other chapters are meant to be used as a reference.  Each chapter
467 presents everything that needs to be said about a specific topic.
469 One of the chapters (@pxref{Date input formats}) exists in its
470 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
471 In addition, one section of this manual (@pxref{Standard}) contains a
472 big quote which is taken directly from @command{tar} sources.
474 In general, we give both long and short (abbreviated) option names
475 at least once in each section where the relevant option is covered, so
476 that novice readers will become familiar with both styles.  (A few
477 options have no short versions, and the relevant sections will
478 indicate this.)
480 @node Definitions
481 @section Some Definitions
483 @cindex archive
484 @cindex tar archive
485 The @command{tar} program is used to create and manipulate @command{tar}
486 archives.  An @dfn{archive} is a single file which contains the contents
487 of many files, while still identifying the names of the files, their
488 owner(s), and so forth.  (In addition, archives record access
489 permissions, user and group, size in bytes, and data modification time.
490 Some archives also record the file names in each archived directory, as
491 well as other file and directory information.)  You can use @command{tar}
492 to @dfn{create} a new archive in a specified directory.
494 @cindex member
495 @cindex archive member
496 @cindex file name
497 @cindex member name
498 The files inside an archive are called @dfn{members}.  Within this
499 manual, we use the term @dfn{file} to refer only to files accessible in
500 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
501 @dfn{member} to refer only to the members of an archive.  Similarly, a
502 @dfn{file name} is the name of a file, as it resides in the file system,
503 and a @dfn{member name} is the name of an archive member within the
504 archive.
506 @cindex extraction
507 @cindex unpacking
508 The term @dfn{extraction} refers to the process of copying an archive
509 member (or multiple members) into a file in the file system.  Extracting
510 all the members of an archive is often called @dfn{extracting the
511 archive}.  The term @dfn{unpack} can also be used to refer to the
512 extraction of many or all the members of an archive.  Extracting an
513 archive does not destroy the archive's structure, just as creating an
514 archive does not destroy the copies of the files that exist outside of
515 the archive.  You may also @dfn{list} the members in a given archive
516 (this is often thought of as ``printing'' them to the standard output,
517 or the command line), or @dfn{append} members to a pre-existing archive.
518 All of these operations can be performed using @command{tar}.
520 @node What tar Does
521 @section What @command{tar} Does
523 @cindex tar
524 The @command{tar} program provides the ability to create @command{tar}
525 archives, as well as various other kinds of manipulation.  For example,
526 you can use @command{tar} on previously created archives to extract files,
527 to store additional files, or to update or list files which were already
528 stored.
530 Initially, @command{tar} archives were used to store files conveniently on
531 magnetic tape.  The name @command{tar} comes from this use; it stands for
532 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
533 direct its output to available devices, files, or other programs (using
534 pipes).  @command{tar} may even access remote devices or files (as archives).
536 You can use @command{tar} archives in many ways.  We want to stress a few
537 of them: storage, backup, and transportation.
539 @FIXME{the following table entries need a bit of work.}
540 @table @asis
541 @item Storage
542 Often, @command{tar} archives are used to store related files for
543 convenient file transfer over a network.  For example, the
544 @acronym{GNU} Project distributes its software bundled into
545 @command{tar} archives, so that all the files relating to a particular
546 program (or set of related programs) can be transferred as a single
547 unit.
549 A magnetic tape can store several files in sequence.  However, the tape
550 has no names for these files; it only knows their relative position on
551 the tape.  One way to store several files on one tape and retain their
552 names is by creating a @command{tar} archive.  Even when the basic transfer
553 mechanism can keep track of names, as FTP can, the nuisance of handling
554 multiple files, directories, and multiple links makes @command{tar}
555 archives useful.
557 Archive files are also used for long-term storage.  You can think of
558 this as transportation from the present into the future.  (It is a
559 science-fiction idiom that you can move through time as well as in
560 space; the idea here is that @command{tar} can be used to move archives in
561 all dimensions, even time!)
563 @item Backup
564 Because the archive created by @command{tar} is capable of preserving
565 file information and directory structure, @command{tar} is commonly
566 used for performing full and incremental backups of disks.  A backup
567 puts a collection of files (possibly pertaining to many users and
568 projects) together on a disk or a tape.  This guards against
569 accidental destruction of the information in those files.
570 @GNUTAR{} has special features that allow it to be
571 used to make incremental and full dumps of all the files in a
572 file system.
574 @item Transportation
575 You can create an archive on one system, transfer it to another system,
576 and extract the contents there.  This allows you to transport a group of
577 files from one system to another.
578 @end table
580 @node Naming tar Archives
581 @section How @command{tar} Archives are Named
583 Conventionally, @command{tar} archives are given names ending with
584 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
585 but this manual follows that convention in order to accustom readers to
586 it and to make examples more clear.
588 @cindex tar file
589 @cindex entry
590 @cindex tar entry
591 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
592 archive members as ``files'' or ``entries''.  For people familiar with
593 the operation of @command{tar}, this causes no difficulty.  However, in
594 this manual, we consistently refer to ``archives'' and ``archive
595 members'' to make learning to use @command{tar} easier for novice users.
597 @node Authors
598 @section @GNUTAR{} Authors
600 @GNUTAR{} was originally written by John Gilmore,
601 and modified by many people.  The @acronym{GNU} enhancements were
602 written by Jay Fenlason, then Joy Kendall, and the whole package has
603 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
604 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
605 numerous and kind users.
607 We wish to stress that @command{tar} is a collective work, and owes much to
608 all those people who reported problems, offered solutions and other
609 insights, or shared their thoughts and suggestions.  An impressive, yet
610 partial list of those contributors can be found in the @file{THANKS}
611 file from the @GNUTAR{} distribution.
613 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
614 sure i want to spell out the history in this detail, at least not for
615 the printed book.  i'm just not sure it needs to be said this way.
616 i'll think about it.}
618 @FIXME{History is more important, and surely more interesting, than
619 actual names.  Quoting names without history would be meaningless.  FP}
621 Jay Fenlason put together a draft of a @GNUTAR{}
622 manual, borrowing notes from the original man page from John Gilmore.
623 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
624 Gorin worked on a tutorial and manual for @GNUTAR{}.
625 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
626 taking information from all these sources and merging them.  Melissa
627 Weisshaus finally edited and redesigned the book to create version
628 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
629 by the current maintainer, Sergey Poznyakoff.
631 For version 1.12, Daniel Hagerty contributed a great deal of technical
632 consulting.  In particular, he is the primary author of @ref{Backups}.
634 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
635 (see @url{http://savannah.gnu.org/projects/tar}), and
636 active development and maintenance work has started
637 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
638 Poznyakoff and Jeff Bailey.
640 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
642 @node Reports
643 @section Reporting bugs or suggestions
645 @cindex bug reports
646 @cindex reporting bugs
647 If you find problems or have suggestions about this program or manual,
648 please report them to @file{bug-tar@@gnu.org}.
650 When reporting a bug, please be sure to include as much detail as
651 possible, in order to reproduce it.
652 @FIXME{Be more specific, I'd like to make this node as detailed as
653 'Bug reporting' node in Emacs manual.}
655 @node Tutorial
656 @chapter Tutorial Introduction to @command{tar}
658 This chapter guides you through some basic examples of three @command{tar}
659 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
660 you already know how to use some other version of @command{tar}, then you
661 may not need to read this chapter.  This chapter omits most complicated
662 details about how @command{tar} works.
664 @menu
665 * assumptions::
666 * stylistic conventions::
667 * basic tar options::           Basic @command{tar} Operations and Options
668 * frequent operations::
669 * Two Frequent Options::
670 * create::                      How to Create Archives
671 * list::                        How to List Archives
672 * extract::                     How to Extract Members from an Archive
673 * going further::
674 @end menu
676 @node assumptions
677 @section Assumptions this Tutorial Makes
679 This chapter is paced to allow beginners to learn about @command{tar}
680 slowly.  At the same time, we will try to cover all the basic aspects of
681 these three operations.  In order to accomplish both of these tasks, we
682 have made certain assumptions about your knowledge before reading this
683 manual, and the hardware you will be using:
685 @itemize @bullet
686 @item
687 Before you start to work through this tutorial, you should understand
688 what the terms ``archive'' and ``archive member'' mean
689 (@pxref{Definitions}).  In addition, you should understand something
690 about how Unix-type operating systems work, and you should know how to
691 use some basic utilities.  For example, you should know how to create,
692 list, copy, rename, edit, and delete files and directories; how to
693 change between directories; and how to figure out where you are in the
694 file system.  You should have some basic understanding of directory
695 structure and how files are named according to which directory they are
696 in.  You should understand concepts such as standard output and standard
697 input, what various definitions of the term @samp{argument} mean, and the
698 differences between relative and absolute file names.
699 @FIXME{and what else?}
701 @item
702 This manual assumes that you are working from your own home directory
703 (unless we state otherwise).  In this tutorial, you will create a
704 directory to practice @command{tar} commands in.  When we show file names,
705 we will assume that those names are relative to your home directory.
706 For example, my home directory is @file{/home/fsf/melissa}.  All of
707 my examples are in a subdirectory of the directory named by that file
708 name; the subdirectory is called @file{practice}.
710 @item
711 In general, we show examples of archives which exist on (or can be
712 written to, or worked with from) a directory on a hard disk.  In most
713 cases, you could write those archives to, or work with them on any other
714 device, such as a tape drive.  However, some of the later examples in
715 the tutorial and next chapter will not work on tape drives.
716 Additionally, working with tapes is much more complicated than working
717 with hard disks.  For these reasons, the tutorial does not cover working
718 with tape drives.  @xref{Media}, for complete information on using
719 @command{tar} archives with tape drives.
721 @FIXME{this is a cop out.  need to add some simple tape drive info.}
722 @end itemize
724 @node stylistic conventions
725 @section Stylistic Conventions
727 In the examples, @samp{$} represents a typical shell prompt.  It
728 precedes lines you should type; to make this more clear, those lines are
729 shown in @kbd{this font}, as opposed to lines which represent the
730 computer's response; those lines are shown in @code{this font}, or
731 sometimes @samp{like this}.
733 @c When we have lines which are too long to be
734 @c displayed in any other way, we will show them like this:
736 @node basic tar options
737 @section Basic @command{tar} Operations and Options
739 @command{tar} can take a wide variety of arguments which specify and define
740 the actions it will have on the particular set of files or the archive.
741 The main types of arguments to @command{tar} fall into one of two classes:
742 operations, and options.
744 Some arguments fall into a class called @dfn{operations}; exactly one of
745 these is both allowed and required for any instance of using @command{tar};
746 you may @emph{not} specify more than one.  People sometimes speak of
747 @dfn{operating modes}.  You are in a particular operating mode when you
748 have specified the operation which specifies it; there are eight
749 operations in total, and thus there are eight operating modes.
751 The other arguments fall into the class known as @dfn{options}.  You are
752 not required to specify any options, and you are allowed to specify more
753 than one at a time (depending on the way you are using @command{tar} at
754 that time).  Some options are used so frequently, and are so useful for
755 helping you type commands more carefully that they are effectively
756 ``required''.  We will discuss them in this chapter.
758 You can write most of the @command{tar} operations and options in any
759 of three forms: long (mnemonic) form, short form, and old style.  Some
760 of the operations and options have no short or ``old'' forms; however,
761 the operations and options which we will cover in this tutorial have
762 corresponding abbreviations.  We will indicate those abbreviations
763 appropriately to get you used to seeing them.  Note, that the ``old
764 style'' option forms exist in @GNUTAR{} for compatibility with Unix
765 @command{tar}.  In this book we present a full discussion of this way
766 of writing options and operations (@pxref{Old Options}), and we discuss
767 the other two styles of writing options (@xref{Long Options}, and
768 @pxref{Short Options}).
770 In the examples and in the text of this tutorial, we usually use the
771 long forms of operations and options; but the ``short'' forms produce
772 the same result and can make typing long @command{tar} commands easier.
773 For example, instead of typing
775 @smallexample
776 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
777 @end smallexample
779 @noindent
780 you can type
781 @smallexample
782 @kbd{tar -c -v -f afiles.tar apple angst aspic}
783 @end smallexample
785 @noindent
786 or even
787 @smallexample
788 @kbd{tar -cvf afiles.tar apple angst aspic}
789 @end smallexample
791 @noindent
792 For more information on option syntax, see @ref{Advanced tar}.  In
793 discussions in the text, when we name an option by its long form, we
794 also give the corresponding short option in parentheses.
796 The term, ``option'', can be confusing at times, since ``operations''
797 are often lumped in with the actual, @emph{optional} ``options'' in certain
798 general class statements.  For example, we just talked about ``short and
799 long forms of options and operations''.  However, experienced @command{tar}
800 users often refer to these by shorthand terms such as, ``short and long
801 options''.  This term assumes that the ``operations'' are included, also.
802 Context will help you determine which definition of ``options'' to use.
804 Similarly, the term ``command'' can be confusing, as it is often used in
805 two different ways.  People sometimes refer to @command{tar} ``commands''.
806 A @command{tar} @dfn{command} is the entire command line of user input
807 which tells @command{tar} what to do --- including the operation, options,
808 and any arguments (file names, pipes, other commands, etc.).  However,
809 you will also sometimes hear the term ``the @command{tar} command''.  When
810 the word ``command'' is used specifically like this, a person is usually
811 referring to the @command{tar} @emph{operation}, not the whole line.
812 Again, use context to figure out which of the meanings the speaker
813 intends.
815 @node frequent operations
816 @section The Three Most Frequently Used Operations
818 Here are the three most frequently used operations (both short and long
819 forms), as well as a brief description of their meanings.  The rest of
820 this chapter will cover how to use these operations in detail.  We will
821 present the rest of the operations in the next chapter.
823 @table @option
824 @item --create
825 @itemx -c
826 Create a new @command{tar} archive.
827 @item --list
828 @itemx -t
829 List the contents of an archive.
830 @item --extract
831 @itemx -x
832 Extract one or more members from an archive.
833 @end table
835 @node Two Frequent Options
836 @section Two Frequently Used Options
838 To understand how to run @command{tar} in the three operating modes listed
839 previously, you also need to understand how to use two of the options to
840 @command{tar}: @option{--file} (which takes an archive file as an argument)
841 and @option{--verbose}.  (You are usually not @emph{required} to specify
842 either of these options when you run @command{tar}, but they can be very
843 useful in making things more clear and helping you avoid errors.)
845 @menu
846 * file tutorial::
847 * verbose tutorial::
848 * help tutorial::
849 @end menu
851 @node file tutorial
852 @unnumberedsubsec The @option{--file} Option
854 @table @option
855 @xopindex{file, tutorial}
856 @item --file=@var{archive-name}
857 @itemx -f @var{archive-name}
858 Specify the name of an archive file.
859 @end table
861 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
862 use @command{tar}; this option determines the name of the archive file
863 that @command{tar} will work on.
865 @vrindex TAPE
866 If you don't specify this argument, then @command{tar} will examine
867 the environment variable @env{TAPE}.  If it is set, its value will be
868 used as the archive name.  Otherwise, @command{tar} will use the
869 default archive, determined at compile time. Usually it is
870 standard output or some physical tape drive attached to your machine
871 (you can verify what the default is by running @kbd{tar
872 --show-defaults}, @pxref{defaults}).  If there is no tape drive
873 attached, or the default is not meaningful, then @command{tar} will
874 print an error message.  The error message might look roughly like one
875 of the following:
877 @smallexample
878 tar: can't open /dev/rmt8 : No such device or address
879 tar: can't open /dev/rsmt0 : I/O error
880 @end smallexample
882 @noindent
883 To avoid confusion, we recommend that you always specify an archive file
884 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
885 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
886 @ref{file}.
888 @node verbose tutorial
889 @unnumberedsubsec The @option{--verbose} Option
891 @table @option
892 @xopindex{verbose, introduced}
893 @item --verbose
894 @itemx -v
895 Show the files being worked on as @command{tar} is running.
896 @end table
898 @option{--verbose} (@option{-v}) shows details about the results of running
899 @command{tar}.  This can be especially useful when the results might not be
900 obvious.  For example, if you want to see the progress of @command{tar} as
901 it writes files into the archive, you can use the @option{--verbose}
902 option.  In the beginning, you may find it useful to use
903 @option{--verbose} at all times; when you are more accustomed to
904 @command{tar}, you will likely want to use it at certain times but not at
905 others.  We will use @option{--verbose} at times to help make something
906 clear, and we will give many examples both using and not using
907 @option{--verbose} to show the differences.
909 Each instance of @option{--verbose} on the command line increases the
910 verbosity level by one, so if you need more details on the output,
911 specify it twice.
913 When reading archives (@option{--list}, @option{--extract},
914 @option{--diff}), @command{tar} by default prints only the names of
915 the members being extracted.  Using @option{--verbose} will show a full,
916 @command{ls} style member listing.
918 In contrast, when writing archives (@option{--create}, @option{--append},
919 @option{--update}), @command{tar} does not print file names by
920 default.  So, a single @option{--verbose} option shows the file names
921 being added to the archive, while two @option{--verbose} options
922 enable the full listing.
924 For example, to create an archive in verbose mode:
926 @smallexample
927 $ @kbd{tar -cvf afiles.tar apple angst aspic}
928 apple
929 angst
930 aspic
931 @end smallexample
933 @noindent
934 Creating the same archive with the verbosity level 2 could give:
936 @smallexample
937 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
938 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
939 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
940 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
941 @end smallexample
943 @noindent
944 This works equally well using short or long forms of options.  Using
945 long forms, you would simply write out the mnemonic form of the option
946 twice, like this:
948 @smallexample
949 $ @kbd{tar --create --verbose --verbose @dots{}}
950 @end smallexample
952 @noindent
953 Note that you must double the hyphens properly each time.
955 Later in the tutorial, we will give examples using @w{@option{--verbose
956 --verbose}}.
958 @anchor{verbose member listing}
959 The full output consists of six fields:
961 @itemize @bullet
962 @item File type and permissions in symbolic form.
963 These are displayed in the same format as the first column of
964 @command{ls -l} output (@pxref{What information is listed,
965 format=verbose, Verbose listing, fileutils, GNU file utilities}).
967 @item Owner name and group separated by a slash character.
968 If these data are not available (for example, when listing a @samp{v7} format
969 archive), numeric @acronym{ID} values are printed instead.
971 @item Size of the file, in bytes.
973 @item File modification date in ISO 8601 format.
975 @item File modification time.
977 @item File name.
978 If the name contains any special characters (white space, newlines,
979 etc.)@: these are displayed in an unambiguous form using so called
980 @dfn{quoting style}.  For the detailed discussion of available styles
981 and on how to use them, see @ref{quoting styles}.
983 Depending on the file type, the name can be followed by some
984 additional information, described in the following table:
986 @table @samp
987 @item -> @var{link-name}
988 The file or archive member is a @dfn{symbolic link} and
989 @var{link-name} is the name of file it links to.
991 @item link to @var{link-name}
992 The file or archive member is a @dfn{hard link} and @var{link-name} is
993 the name of file it links to.
995 @item --Long Link--
996 The archive member is an old GNU format long link.  You will normally
997 not encounter this.
999 @item --Long Name--
1000 The archive member is an old GNU format long name.  You will normally
1001 not encounter this.
1003 @item --Volume Header--
1004 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1006 @item --Continued at byte @var{n}--
1007 Encountered only at the beginning of a multi-volume archive
1008 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1009 from the previous volume. The number @var{n} gives the offset where
1010 the original file was split.
1012 @item  unknown file type @var{c}
1013 An archive member of unknown type. @var{c} is the type character from
1014 the archive header.  If you encounter such a message, it means that
1015 either your archive contains proprietary member types @GNUTAR{} is not
1016 able to handle, or the archive is corrupted.
1017 @end table
1019 @end itemize
1021 For example, here is an archive listing containing most of the special
1022 suffixes explained above:
1024 @smallexample
1025 @group
1026 V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
1027 -rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1028 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
1029 lrwxrwxrwx gray/staff        0 2006-06-09 13:01 angst -> apple
1030 -rw-r--r-- gray/staff    35793 2006-06-09 12:06 blues
1031 hrw-r--r-- gray/staff        0 2006-06-09 12:06 music link to blues
1032 @end group
1033 @end smallexample
1035 @smallexample
1036 @end smallexample
1038 @node help tutorial
1039 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1041 @table @option
1042 @opindex help
1043 @item --help
1045 The @option{--help} option to @command{tar} prints out a very brief list of
1046 all operations and option available for the current version of
1047 @command{tar} available on your system.
1048 @end table
1050 @node create
1051 @section How to Create Archives
1053 @cindex Creation of the archive
1054 @cindex Archive, creation of
1055 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1056 you use to create a @command{tar} archive.  We will explain
1057 @option{--create} first because, in order to learn about the other
1058 operations, you will find it useful to have an archive available to
1059 practice on.
1061 To make this easier, in this section you will first create a directory
1062 containing three files.  Then, we will show you how to create an
1063 @emph{archive} (inside the new directory).  Both the directory, and
1064 the archive are specifically for you to practice on.  The rest of this
1065 chapter and the next chapter will show many examples using this
1066 directory and the files you will create: some of those files may be
1067 other directories and other archives.
1069 The three files you will archive in this example are called
1070 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1071 @file{collection.tar}.
1073 This section will proceed slowly, detailing how to use @option{--create}
1074 in @code{verbose} mode, and showing examples using both short and long
1075 forms.  In the rest of the tutorial, and in the examples in the next
1076 chapter, we will proceed at a slightly quicker pace.  This section
1077 moves more slowly to allow beginning users to understand how
1078 @command{tar} works.
1080 @menu
1081 * prepare for examples::
1082 * Creating the archive::
1083 * create verbose::
1084 * short create::
1085 * create dir::
1086 @end menu
1088 @node prepare for examples
1089 @subsection Preparing a Practice Directory for Examples
1091 To follow along with this and future examples, create a new directory
1092 called @file{practice} containing files called @file{blues}, @file{folk}
1093 and @file{jazz}.  The files can contain any information you like:
1094 ideally, they should contain information which relates to their names,
1095 and be of different lengths.  Our examples assume that @file{practice}
1096 is a subdirectory of your home directory.
1098 Now @command{cd} to the directory named @file{practice}; @file{practice}
1099 is now your @dfn{working directory}.  (@emph{Please note}: Although
1100 the full file name of this directory is
1101 @file{/@var{homedir}/practice}, in our examples we will refer to
1102 this directory as @file{practice}; the @var{homedir} is presumed.)
1104 In general, you should check that the files to be archived exist where
1105 you think they do (in the working directory) by running @command{ls}.
1106 Because you just created the directory and the files and have changed to
1107 that directory, you probably don't need to do that this time.
1109 It is very important to make sure there isn't already a file in the
1110 working directory with the archive name you intend to use (in this case,
1111 @samp{collection.tar}), or that you don't care about its contents.
1112 Whenever you use @samp{create}, @command{tar} will erase the current
1113 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1114 will not tell you if you are about to overwrite an archive unless you
1115 specify an option which does this (@pxref{backup}, for the
1116 information on how to do so).  To add files to an existing archive,
1117 you need to use a different option, such as @option{--append} (@option{-r}); see
1118 @ref{append} for information on how to do this.
1120 @node Creating the archive
1121 @subsection Creating the Archive
1123 @xopindex{create, introduced}
1124 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1125 archive named @file{collection.tar}, use the following command:
1127 @smallexample
1128 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1129 @end smallexample
1131 The order of the arguments is not very important, @emph{when using long
1132 option forms}, however you should always remember to use option as the
1133 first argument to tar.   For example, the following is wrong:
1135 @smallexample
1136 $ @kbd{tar blues -c folk -f collection.tar jazz}
1137 tar: -c: Invalid blocking factor
1138 Try 'tar --help' or 'tar --usage' for more information.
1139 @end smallexample
1141 The error message is produced because @command{tar} always treats its
1142 first argument as an option (or cluster of options), even if it does
1143 not start with dash.  This is @dfn{traditional} or @dfn{old option}
1144 style, called so because all implementations of @command{tar} have
1145 used it since the very inception of the tar archiver in 1970s.  This
1146 option style will be explained later (@pxref{Old Options}), for now
1147 just remember to always place option as the first argument.
1149 That being said, you could issue the following command:
1151 @smallexample
1152 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1153 @end smallexample
1155 @noindent
1156 However, you can see that this order is harder to understand; this is
1157 why we will list the arguments in the order that makes the commands
1158 easiest to understand (and we encourage you to do the same when you use
1159 @command{tar}, to avoid errors).
1161 Note that the sequence
1162 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1163 If you substituted any other string of characters for
1164 @kbd{collection.tar},  then that string would become the name of the
1165 archive file you create.
1167 The order of the options becomes more important when you begin to use
1168 short forms.  With short forms, if you type commands in the wrong order
1169 (even if you type them correctly in all other ways), you may end up with
1170 results you don't expect.  For this reason, it is a good idea to get
1171 into the habit of typing options in the order that makes inherent sense.
1172 @xref{short create}, for more information on this.
1174 In this example, you type the command as shown above: @option{--create}
1175 is the operation which creates the new archive
1176 (@file{collection.tar}), and @option{--file} is the option which lets
1177 you give it the name you chose.  The files, @file{blues}, @file{folk},
1178 and @file{jazz}, are now members of the archive, @file{collection.tar}
1179 (they are @dfn{file name arguments} to the @option{--create} operation.
1180 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1181 in the archive, they are called @emph{archive members}, not files.
1182 (@pxref{Definitions,members}).
1184 When you create an archive, you @emph{must} specify which files you
1185 want placed in the archive.  If you do not specify any archive
1186 members, @GNUTAR{} will complain.
1188 If you now list the contents of the working directory (@command{ls}), you will
1189 find the archive file listed as well as the files you saw previously:
1191 @smallexample
1192 blues   folk   jazz   collection.tar
1193 @end smallexample
1195 @noindent
1196 Creating the archive @samp{collection.tar} did not destroy the copies of
1197 the files in the directory.
1199 Keep in mind that if you don't indicate an operation, @command{tar} will not
1200 run and will prompt you for one.  If you don't name any files, @command{tar}
1201 will complain.  You must have write access to the working directory,
1202 or else you will not be able to create an archive in that directory.
1204 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1205 an existing archive; it will delete the archive and write a new one.
1206 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1208 @node create verbose
1209 @subsection Running @option{--create} with @option{--verbose}
1211 @xopindex{create, using with @option{--verbose}}
1212 @xopindex{verbose, using with @option{--create}}
1213 If you include the @option{--verbose} (@option{-v}) option on the command line,
1214 @command{tar} will list the files it is acting on as it is working.  In
1215 verbose mode, the @code{create} example above would appear as:
1217 @smallexample
1218 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1219 blues
1220 folk
1221 jazz
1222 @end smallexample
1224 This example is just like the example we showed which did not use
1225 @option{--verbose}, except that @command{tar} generated the remaining
1226 @iftex
1227 lines (note the different font styles).
1228 @end iftex
1229 @ifinfo
1230 lines.
1231 @end ifinfo
1233 In the rest of the examples in this chapter, we will frequently use
1234 @code{verbose} mode so we can show actions or @command{tar} responses that
1235 you would otherwise not see, and which are important for you to
1236 understand.
1238 @node short create
1239 @subsection Short Forms with @samp{create}
1241 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1242 basic uses of @command{tar}, and you will use it countless times.
1243 Eventually, you will probably want to use abbreviated (or ``short'')
1244 forms of options.  A full discussion of the three different forms that
1245 options can take appears in @ref{Styles}; for now, here is what the
1246 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1247 using short option forms:
1249 @smallexample
1250 $ @kbd{tar -cvf collection.tar blues folk jazz}
1251 blues
1252 folk
1253 jazz
1254 @end smallexample
1256 @noindent
1257 As you can see, the system responds the same no matter whether you use
1258 long or short option forms.
1260 @FIXME{i don't like how this is worded:} One difference between using
1261 short and long option forms is that, although the exact placement of
1262 arguments following options is no more specific when using short forms,
1263 it is easier to become confused and make a mistake when using short
1264 forms.  For example, suppose you attempted the above example in the
1265 following way:
1267 @smallexample
1268 $ @kbd{tar -cfv collection.tar blues folk jazz}
1269 @end smallexample
1271 @noindent
1272 In this case, @command{tar} will make an archive file called @file{v},
1273 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1274 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1275 is thus taken to be the chosen archive file name.  @command{tar} will try
1276 to add a file called @file{collection.tar} to the @file{v} archive file;
1277 if the file @file{collection.tar} did not already exist, @command{tar} will
1278 report an error indicating that this file does not exist.  If the file
1279 @file{collection.tar} does already exist (e.g., from a previous command
1280 you may have run), then @command{tar} will add this file to the archive.
1281 Because the @option{-v} option did not get registered, @command{tar} will not
1282 run under @samp{verbose} mode, and will not report its progress.
1284 The end result is that you may be quite confused about what happened,
1285 and possibly overwrite a file.  To illustrate this further, we will show
1286 you how an example we showed previously would look using short forms.
1288 This example,
1290 @smallexample
1291 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1292 @end smallexample
1294 @noindent
1295 is confusing as it is.  It becomes even more so when using short forms:
1297 @smallexample
1298 $ @kbd{tar -c folk blues -f collection.tar jazz}
1299 @end smallexample
1301 @noindent
1302 It would be very easy to put the wrong string of characters
1303 immediately following the @option{-f}, but doing that could sacrifice
1304 valuable data.
1306 For this reason, we recommend that you pay very careful attention to
1307 the order of options and placement of file and archive names,
1308 especially when using short option forms.  Not having the option name
1309 written out mnemonically can affect how well you remember which option
1310 does what, and therefore where different names have to be placed.
1312 @node create dir
1313 @subsection Archiving Directories
1315 @cindex Archiving Directories
1316 @cindex Directories, Archiving
1317 You can archive a directory by specifying its directory name as a
1318 file name argument to @command{tar}.  The files in the directory will be
1319 archived relative to the working directory, and the directory will be
1320 re-created along with its contents when the archive is extracted.
1322 To archive a directory, first move to its superior directory.  If you
1323 have followed the previous instructions in this tutorial, you should
1324 type:
1326 @smallexample
1327 $ @kbd{cd ..}
1329 @end smallexample
1331 @noindent
1332 This will put you into the directory which contains @file{practice},
1333 i.e., your home directory.  Once in the superior directory, you can
1334 specify the subdirectory, @file{practice}, as a file name argument.  To
1335 store @file{practice} in the new archive file @file{music.tar}, type:
1337 @smallexample
1338 $ @kbd{tar --create --verbose --file=music.tar practice}
1339 @end smallexample
1341 @noindent
1342 @command{tar} should output:
1344 @smallexample
1345 practice/
1346 practice/blues
1347 practice/folk
1348 practice/jazz
1349 practice/collection.tar
1350 @end smallexample
1352 Note that the archive thus created is not in the subdirectory
1353 @file{practice}, but rather in the current working directory---the
1354 directory from which @command{tar} was invoked.  Before trying to archive a
1355 directory from its superior directory, you should make sure you have
1356 write access to the superior directory itself, not only the directory
1357 you are trying archive with @command{tar}.  For example, you will probably
1358 not be able to store your home directory in an archive by invoking
1359 @command{tar} from the root directory; @xref{absolute}.  (Note
1360 also that @file{collection.tar}, the original archive file, has itself
1361 been archived.  @command{tar} will accept any file as a file to be
1362 archived, regardless of its content.  When @file{music.tar} is
1363 extracted, the archive file @file{collection.tar} will be re-written
1364 into the file system).
1366 If you give @command{tar} a command such as
1368 @smallexample
1369 $ @kbd{tar --create --file=foo.tar .}
1370 @end smallexample
1372 @noindent
1373 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1374 dumped}.  This happens because @command{tar} creates the archive
1375 @file{foo.tar} in the current directory before putting any files into
1376 it.  Then, when @command{tar} attempts to add all the files in the
1377 directory @file{.} to the archive, it notices that the file
1378 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1379 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1380 will continue in this case, and create the archive
1381 normally, except for the exclusion of that one file.  (@emph{Please
1382 note:} Other implementations of @command{tar} may not be so clever;
1383 they will enter an infinite loop when this happens, so you should not
1384 depend on this behavior unless you are certain you are running
1385 @GNUTAR{}.  In general, it is wise to always place the archive outside
1386 of the directory being dumped.)
1388 @node list
1389 @section How to List Archives
1391 @opindex list
1392 Frequently, you will find yourself wanting to determine exactly what a
1393 particular archive contains.  You can use the @option{--list}
1394 (@option{-t}) operation to get the member names as they currently
1395 appear in the archive, as well as various attributes of the files at
1396 the time they were archived.  For example, assuming @file{practice} is
1397 your working directory, you can examine the archive
1398 @file{collection.tar} that you created in the last section with the
1399 command,
1401 @smallexample
1402 $ @kbd{tar --list --file=collection.tar}
1403 @end smallexample
1405 @noindent
1406 The output of @command{tar} would then be:
1408 @smallexample
1409 blues
1410 folk
1411 jazz
1412 @end smallexample
1414 @noindent
1415 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1416 @var{archive-name}}) option just as with @option{--create}
1417 (@option{-c}) to specify the name of the archive.
1419 @cindex File name arguments, using @option{--list} with
1420 @xopindex{list, using with file name arguments}
1421 You can specify one or more individual member names as arguments when
1422 using @samp{list}.  In this case, @command{tar} will only list the
1423 names of members you identify.  For example, @w{@kbd{tar --list
1424 --file=collection.tar folk}} would only print @file{folk}:
1426 @smallexample
1427 $ @kbd{tar --list --file=collection.tar folk}
1428 folk
1429 @end smallexample
1431 @xopindex{list, using with @option{--verbose}}
1432 @xopindex{verbose, using with @option{--list}}
1433 If you use the @option{--verbose} (@option{-v}) option with
1434 @option{--list}, then @command{tar} will print out a listing
1435 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1436 forth.  This output is described in detail in @ref{verbose member listing}.
1438 If you had used @option{--verbose} (@option{-v}) mode, the example
1439 above would look like:
1441 @smallexample
1442 $ @kbd{tar --list --verbose --file=collection.tar folk}
1443 -rw-r--r-- myself/user      62 1990-05-23 10:55 folk
1444 @end smallexample
1446 @cindex listing member and file names
1447 @anchor{listing member and file names}
1448 It is important to notice that the output of @kbd{tar --list
1449 --verbose} does not necessarily match that produced by @kbd{tar
1450 --create --verbose} while creating the archive.  It is because
1451 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1452 prefixes from file names before storing them in the archive
1453 (@xref{absolute}, for more information).  In other
1454 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1455 an archive and @dfn{member names} when listing it.  Consider this
1456 example, run from your home directory:
1458 @smallexample
1459 @group
1460 $ @kbd{tar --create --verbose --file practice.tar ~/practice}
1461 tar: Removing leading '/' from member names
1462 /home/myself/practice/
1463 /home/myself/practice/blues
1464 /home/myself/practice/folk
1465 /home/myself/practice/jazz
1466 /home/myself/practice/collection.tar
1467 $ @kbd{tar --list --file practice.tar}
1468 home/myself/practice/
1469 home/myself/practice/blues
1470 home/myself/practice/folk
1471 home/myself/practice/jazz
1472 home/myself/practice/collection.tar
1473 @end group
1474 @end smallexample
1476 @opindex show-stored-names
1477   This default behavior can sometimes be inconvenient.  You can force
1478 @GNUTAR{} show member names when creating archive by supplying
1479 @option{--show-stored-names} option.
1481 @table @option
1482 @item --show-stored-names
1483 Print member (as opposed to @emph{file}) names when creating the archive.
1484 @end table
1486 With this option, both commands produce the same output:
1488 @smallexample
1489 @group
1490 $ @kbd{tar --create --verbose --show-stored-names \
1491            --file practice.tar ~/practice}
1492 tar: Removing leading '/' from member names
1493 home/myself/practice/
1494 home/myself/practice/blues
1495 home/myself/practice/folk
1496 home/myself/practice/jazz
1497 home/myself/practice/collection.tar
1498 $ @kbd{tar --list --file practice.tar}
1499 home/myself/practice/
1500 home/myself/practice/blues
1501 home/myself/practice/folk
1502 home/myself/practice/jazz
1503 home/myself/practice/collection.tar
1504 @end group
1505 @end smallexample
1507 Since @command{tar} preserves file names, those you wish to list must be
1508 specified as they appear in the archive (i.e., relative to the
1509 directory from which the archive was created).  Continuing the example
1510 above:
1512 @smallexample
1513 @group
1514 $ @kbd{tar --list --file=practice.tar folk}
1515 tar: folk: Not found in archive
1516 tar: Exiting with failure status due to previous errors
1517 @end group
1518 @end smallexample
1520 the error message is produced because there is no member named
1521 @file{folk}, only one named @file{home/myself/folk}.
1523 If you are not sure of the exact file name, use @dfn{globbing
1524 patterns}, for example:
1526 @smallexample
1527 $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
1528 home/myself/practice/folk
1529 @end smallexample
1531 @noindent
1532 @xref{wildcards}, for a detailed discussion of globbing patterns and related
1533 @command{tar} command line options.
1535 @menu
1536 * list dir::
1537 @end menu
1539 @node list dir
1540 @unnumberedsubsec Listing the Contents of a Stored Directory
1542 To get information about the contents of an archived directory,
1543 use the directory name as a file name argument in conjunction with
1544 @option{--list} (@option{-t}).  To find out file attributes, include the
1545 @option{--verbose} (@option{-v}) option.
1547 For example, to find out about files in the directory @file{practice}, in
1548 the archive file @file{music.tar}, type:
1550 @smallexample
1551 $ @kbd{tar --list --verbose --file=music.tar practice}
1552 @end smallexample
1554 @command{tar} responds:
1556 @smallexample
1557 drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
1558 -rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
1559 -rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
1560 -rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
1561 -rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar
1562 @end smallexample
1564 When you use a directory name as a file name argument, @command{tar} acts on
1565 all the files (including sub-directories) in that directory.
1567 @node extract
1568 @section How to Extract Members from an Archive
1569 @cindex Extraction
1570 @cindex Retrieving files from an archive
1571 @cindex Resurrecting files from an archive
1573 @opindex extract
1574 Creating an archive is only half the job---there is no point in storing
1575 files in an archive if you can't retrieve them.  The act of retrieving
1576 members from an archive so they can be used and manipulated as
1577 unarchived files again is called @dfn{extraction}.  To extract files
1578 from an archive, use the @option{--extract} (@option{--get} or
1579 @option{-x}) operation.  As with @option{--create}, specify the name
1580 of the archive with @option{--file} (@option{-f}) option. Extracting
1581 an archive does not modify the archive in any way; you can extract it
1582 multiple times if you want or need to.
1584 Using @option{--extract}, you can extract an entire archive, or specific
1585 files.  The files can be directories containing other files, or not.  As
1586 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1587 long form of the operation without affecting the performance.
1589 @menu
1590 * extracting archives::
1591 * extracting files::
1592 * extract dir::
1593 * extracting untrusted archives::
1594 * failing commands::
1595 @end menu
1597 @node extracting archives
1598 @subsection Extracting an Entire Archive
1600 To extract an entire archive, specify the archive file name only, with
1601 no individual file names as arguments.  For example,
1603 @smallexample
1604 $ @kbd{tar -xvf collection.tar}
1605 @end smallexample
1607 @noindent
1608 produces this:
1610 @smallexample
1611 -rw-r--r-- myself/user      28 1996-10-18 16:31 jazz
1612 -rw-r--r-- myself/user      21 1996-09-23 16:44 blues
1613 -rw-r--r-- myself/user      20 1996-09-23 16:44 folk
1614 @end smallexample
1616 @node extracting files
1617 @subsection Extracting Specific Files
1619 To extract specific archive members, give their exact member names as
1620 arguments, as printed by @option{--list} (@option{-t}).  If you had
1621 mistakenly deleted one of the files you had placed in the archive
1622 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1623 from the archive without changing the archive's structure.  Its
1624 contents will be identical to the original file @file{blues} that you
1625 deleted.
1627 First, make sure you are in the @file{practice} directory, and list the
1628 files in the directory.  Now, delete the file, @samp{blues}, and list
1629 the files in the directory again.
1631 You can now extract the member @file{blues} from the archive file
1632 @file{collection.tar} like this:
1634 @smallexample
1635 $ @kbd{tar --extract --file=collection.tar blues}
1636 @end smallexample
1638 @noindent
1639 If you list the files in the directory again, you will see that the file
1640 @file{blues} has been restored, with its original permissions, data
1641 modification times, and owner.@footnote{This is only accidentally
1642 true, but not in general.  Whereas modification times are always
1643 restored, in most cases, one has to be root for restoring the owner,
1644 and use a special option for restoring permissions.  Here, it just
1645 happens that the restoring user is also the owner of the archived
1646 members, and that the current @code{umask} is compatible with original
1647 permissions.}  (These parameters will be identical to those which
1648 the file had when you originally placed it in the archive; any changes
1649 you may have made before deleting the file from the file system,
1650 however, will @emph{not} have been made to the archive member.)  The
1651 archive file, @samp{collection.tar}, is the same as it was before you
1652 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1653 @option{--list} (@option{-t}).
1655 Remember that as with other operations, specifying the exact member
1656 name is important (@xref{failing commands}, for more examples).
1658 You can extract a file to standard output by combining the above options
1659 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1660 Output}).
1662 If you give the @option{--verbose} option, then @option{--extract}
1663 will print the names of the archive members as it extracts them.
1665 @node extract dir
1666 @subsection Extracting Files that are Directories
1668 Extracting directories which are members of an archive is similar to
1669 extracting other files.  The main difference to be aware of is that if
1670 the extracted directory has the same name as any directory already in
1671 the working directory, then files in the extracted directory will be
1672 placed into the directory of the same name.  Likewise, if there are
1673 files in the pre-existing directory with the same names as the members
1674 which you extract, the files from the extracted archive will replace
1675 the files already in the working directory (and possible
1676 subdirectories).  This will happen regardless of whether or not the
1677 files in the working directory were more recent than those extracted
1678 (there exist, however, special options that alter this behavior
1679 @pxref{Writing}).
1681 However, if a file was stored with a directory name as part of its file
1682 name, and that directory does not exist under the working directory when
1683 the file is extracted, @command{tar} will create the directory.
1685 We can demonstrate how to use @option{--extract} to extract a directory
1686 file with an example.  Change to the @file{practice} directory if you
1687 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1688 go back to the parent directory and extract the archive
1689 @file{music.tar}.  You may either extract the entire archive, or you may
1690 extract only the files you just deleted.  To extract the entire archive,
1691 don't give any file names as arguments after the archive name
1692 @file{music.tar}.  To extract only the files you deleted, use the
1693 following command:
1695 @smallexample
1696 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1697 practice/folk
1698 practice/jazz
1699 @end smallexample
1701 @noindent
1702 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1703 would have displayed more detail about the extracted files, as shown
1704 in the example below:
1706 @smallexample
1707 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1708 -rw-r--r-- me/user          28 1996-10-18 16:31 practice/jazz
1709 -rw-r--r-- me/user          20 1996-09-23 16:44 practice/folk
1710 @end smallexample
1712 @noindent
1713 Because you created the directory with @file{practice} as part of the
1714 file names of each of the files by archiving the @file{practice}
1715 directory as @file{practice}, you must give @file{practice} as part
1716 of the file names when you extract those files from the archive.
1718 @node extracting untrusted archives
1719 @subsection Extracting Archives from Untrusted Sources
1721 Extracting files from archives can overwrite files that already exist.
1722 If you receive an archive from an untrusted source, you should make a
1723 new directory and extract into that directory, so that you don't have
1724 to worry about the extraction overwriting one of your existing files.
1725 For example, if @file{untrusted.tar} came from somewhere else on the
1726 Internet, and you don't necessarily trust its contents, you can
1727 extract it as follows:
1729 @smallexample
1730 $ @kbd{mkdir newdir}
1731 $ @kbd{cd newdir}
1732 $ @kbd{tar -xvf ../untrusted.tar}
1733 @end smallexample
1735 It is also a good practice to examine contents of the archive
1736 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1737 with @option{--verbose} (@option{-v}).
1739 @node failing commands
1740 @subsection Commands That Will Fail
1742 Here are some sample commands you might try which will not work, and why
1743 they won't work.
1745 If you try to use this command,
1747 @smallexample
1748 $ @kbd{tar -xvf music.tar folk jazz}
1749 @end smallexample
1751 @noindent
1752 you will get the following response:
1754 @smallexample
1755 tar: folk: Not found in archive
1756 tar: jazz: Not found in archive
1757 @end smallexample
1759 @noindent
1760 This is because these files were not originally @emph{in} the parent
1761 directory @file{..}, where the archive is located; they were in the
1762 @file{practice} directory, and their file names reflect this:
1764 @smallexample
1765 $ @kbd{tar -tvf music.tar}
1766 practice/blues
1767 practice/folk
1768 practice/jazz
1769 @end smallexample
1771 @noindent
1772 Likewise, if you try to use this command,
1774 @smallexample
1775 $ @kbd{tar -tvf music.tar folk jazz}
1776 @end smallexample
1778 @noindent
1779 you would get a similar response.  Members with those names are not in the
1780 archive.  You must use the correct member names, or wildcards, in order
1781 to extract the files from the archive.
1783 If you have forgotten the correct names of the files in the archive,
1784 use @w{@kbd{tar --list --verbose}} to list them correctly.
1786 To extract the member named @file{practice/folk}, you must specify
1788 @smallexample
1789 $ @kbd{tar --extract --file=music.tar practice/folk}
1790 @end smallexample
1792 @noindent
1793 Notice also, that as explained above, the @file{practice} directory
1794 will be created, if it didn't already exist.  There are options that
1795 allow you to strip away a certain number of leading directory
1796 components (@pxref{transform}).  For example,
1798 @smallexample
1799 $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
1800 @end smallexample
1802 @noindent
1803 will extract the file @file{folk} into the current working directory.
1805 @node going further
1806 @section Going Further Ahead in this Manual
1807 @UNREVISED
1809 @FIXME{need to write up a node here about the things that are going to
1810 be in the rest of the manual.}
1812 @node tar invocation
1813 @chapter Invoking @GNUTAR{}
1815 This chapter is about how one invokes the @GNUTAR{}
1816 command, from the command synopsis (@pxref{Synopsis}).  There are
1817 numerous options, and many styles for writing them.  One mandatory
1818 option specifies the operation @command{tar} should perform
1819 (@pxref{Operation Summary}), other options are meant to detail how
1820 this operation should be performed (@pxref{Option Summary}).
1821 Non-option arguments are not always interpreted the same way,
1822 depending on what the operation is.
1824 You will find in this chapter everything about option styles and rules for
1825 writing them (@pxref{Styles}).  On the other hand, operations and options
1826 are fully described elsewhere, in other chapters.  Here, you will find
1827 only synthetic descriptions for operations and options, together with
1828 pointers to other parts of the @command{tar} manual.
1830 Some options are so special they are fully described right in this
1831 chapter.  They have the effect of inhibiting the normal operation of
1832 @command{tar} or else, they globally alter the amount of feedback the user
1833 receives about what is going on.  These are the @option{--help} and
1834 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1835 and @option{--interactive} options (@pxref{interactive}).
1837 @menu
1838 * Synopsis::
1839 * using tar options::
1840 * Styles::
1841 * All Options::           All @command{tar} Options.
1842 * help::                  Where to Get Help.
1843 * defaults::              What are the Default Values.
1844 * verbose::               Checking @command{tar} progress.
1845 * checkpoints::           Checkpoints.
1846 * warnings::              Controlling Warning Messages.
1847 * interactive::           Asking for Confirmation During Operations.
1848 * external::              Running External Commands.
1849 @end menu
1851 @node Synopsis
1852 @section General Synopsis of @command{tar}
1854 The @GNUTAR{} program is invoked as either one of:
1856 @smallexample
1857 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1858 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1859 @end smallexample
1861 The second form is for when old options are being used.
1863 You can use @command{tar} to store files in an archive, to extract them from
1864 an archive, and to do other types of archive manipulation.  The primary
1865 argument to @command{tar}, which is called the @dfn{operation}, specifies
1866 which action to take.  The other arguments to @command{tar} are either
1867 @dfn{options}, which change the way @command{tar} performs an operation,
1868 or file names or archive members, which specify the files or members
1869 @command{tar} is to act on.
1871 You can actually type in arguments in any order, even if in this manual
1872 the options always precede the other arguments, to make examples easier
1873 to understand.  Further, the option stating the main operation mode
1874 (the @command{tar} main command) is usually given first.
1876 Each @var{name} in the synopsis above is interpreted as an archive member
1877 name when the main command is one of @option{--compare}
1878 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1879 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1880 @option{--update} (@option{-u}).  When naming archive members, you
1881 must give the exact name of the member in the archive, as it is
1882 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1883 @option{--create} (@option{-c}), these @var{name} arguments specify
1884 the names of either files or directory hierarchies to place in the archive.
1885 These files or hierarchies should already exist in the file system,
1886 prior to the execution of the @command{tar} command.
1888 @command{tar} interprets relative file names as being relative to the
1889 working directory.  @command{tar} will make all file names relative
1890 (by removing leading slashes when archiving or restoring files),
1891 unless you specify otherwise (using the @option{--absolute-names}
1892 option).  @xref{absolute}, for more information about
1893 @option{--absolute-names}.
1895 If you give the name of a directory as either a file name or a member
1896 name, then @command{tar} acts recursively on all the files and directories
1897 beneath that directory.  For example, the name @file{/} identifies all
1898 the files in the file system to @command{tar}.
1900 The distinction between file names and archive member names is especially
1901 important when shell globbing is used, and sometimes a source of confusion
1902 for newcomers.  @xref{wildcards}, for more information about globbing.
1903 The problem is that shells may only glob using existing files in the
1904 file system.  Only @command{tar} itself may glob on archive members, so when
1905 needed, you must ensure that wildcard characters reach @command{tar} without
1906 being interpreted by the shell first.  Using a backslash before @samp{*}
1907 or @samp{?}, or putting the whole argument between quotes, is usually
1908 sufficient for this.
1910 Even if @var{name}s are often specified on the command line, they
1911 can also be read from a text file in the file system, using the
1912 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1914 If you don't use any file name arguments, @option{--append} (@option{-r}),
1915 @option{--delete} and @option{--concatenate} (@option{--catenate},
1916 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1917 will usually yield a diagnostic and inhibit @command{tar} execution.
1918 The other operations of @command{tar} (@option{--list},
1919 @option{--extract}, @option{--compare}, and @option{--update})
1920 will act on the entire contents of the archive.
1922 @anchor{exit status}
1923 @cindex exit status
1924 @cindex return status
1925 Besides successful exits, @GNUTAR{} may fail for
1926 many reasons.  Some reasons correspond to bad usage, that is, when the
1927 @command{tar} command line is improperly written.  Errors may be
1928 encountered later, while processing the archive or the files.  Some
1929 errors are recoverable, in which case the failure is delayed until
1930 @command{tar} has completed all its work.  Some errors are such that
1931 it would be not meaningful, or at least risky, to continue processing:
1932 @command{tar} then aborts processing immediately.  All abnormal exits,
1933 whether immediate or delayed, should always be clearly diagnosed on
1934 @code{stderr}, after a line stating the nature of the error.
1936 Possible exit codes of @GNUTAR{} are summarized in the following
1937 table:
1939 @table @asis
1940 @item 0
1941 @samp{Successful termination}.
1943 @item 1
1944 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1945 (@option{--diff}, @option{-d}) command line option, this means that
1946 some files in the archive differ from their disk counterparts
1947 (@pxref{compare}).  If tar was given @option{--create},
1948 @option{--append} or @option{--update} option, this exit code means
1949 that some files were changed while being archived and so the resulting
1950 archive does not contain the exact copy of the file set.
1952 @item 2
1953 @samp{Fatal error}.  This means that some fatal, unrecoverable error
1954 occurred.
1955 @end table
1957 If @command{tar} has invoked a subprocess and that subprocess exited with a
1958 nonzero exit code, @command{tar} exits with that code as well.
1959 This can happen, for example, if @command{tar} was given some
1960 compression option (@pxref{gzip}) and the external compressor program
1961 failed.  Another example is @command{rmt} failure during backup to the
1962 remote device (@pxref{Remote Tape Server}).
1964 @node using tar options
1965 @section Using @command{tar} Options
1967 @GNUTAR{} has a total of eight operating modes which
1968 allow you to perform a variety of tasks.  You are required to choose
1969 one operating mode each time you employ the @command{tar} program by
1970 specifying one, and only one operation as an argument to the
1971 @command{tar} command (the corresponding options may be found
1972 at @ref{frequent operations} and @ref{Operations}).  Depending on
1973 circumstances, you may also wish to customize how the chosen operating
1974 mode behaves.  For example, you may wish to change the way the output
1975 looks, or the format of the files that you wish to archive may require
1976 you to do something special in order to make the archive look right.
1978 You can customize and control @command{tar}'s performance by running
1979 @command{tar} with one or more options (such as @option{--verbose}
1980 (@option{-v}), which we used in the tutorial).  As we said in the
1981 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1982 their name suggests) optional. Depending on the operating mode, you
1983 may specify one or more options. Different options will have different
1984 effects, but in general they all change details of the operation, such
1985 as archive format, archive name, or level of user interaction.  Some
1986 options make sense with all operating modes, while others are
1987 meaningful only with particular modes. You will likely use some
1988 options frequently, while you will only use others infrequently, or
1989 not at all.  (A full list of options is available in @pxref{All Options}.)
1991 @vrindex TAR_OPTIONS, environment variable
1992 @anchor{TAR_OPTIONS}
1993 The @env{TAR_OPTIONS} environment variable specifies default options to
1994 be placed in front of any explicit options.  For example, if
1995 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1996 if the two options @option{-v} and @option{--unlink-first} had been
1997 specified before any explicit options.  Option specifications are
1998 separated by whitespace.  A backslash escapes the next character, so it
1999 can be used to specify an option containing whitespace or a backslash.
2001 Note that @command{tar} options are case sensitive.  For example, the
2002 options @option{-T} and @option{-t} are different; the first requires an
2003 argument for stating the name of a file providing a list of @var{name}s,
2004 while the second does not require an argument and is another way to
2005 write @option{--list} (@option{-t}).
2007 In addition to the eight operations, there are many options to
2008 @command{tar}, and three different styles for writing both: long (mnemonic)
2009 form, short form, and old style.  These styles are discussed below.
2010 Both the options and the operations can be written in any of these three
2011 styles.
2013 @FIXME{menu at end of this node.  need to think of an actual outline
2014 for this chapter; probably do that after stuff from chapter 4 is
2015 incorporated.}
2017 @node Styles
2018 @section The Three Option Styles
2020 There are three styles for writing operations and options to the command
2021 line invoking @command{tar}.  The different styles were developed at
2022 different times during the history of @command{tar}.  These styles will be
2023 presented below, from the most recent to the oldest.
2025 Some options must take an argument@footnote{For example, @option{--file}
2026 (@option{-f}) takes the name of an archive file as an argument.  If
2027 you do not supply an archive file name, @command{tar} will use a
2028 default, but this can be confusing; thus, we recommend that you always
2029 supply a specific archive file name.}.  Where you @emph{place} the
2030 arguments generally depends on which style of options you choose.  We
2031 will detail specific information relevant to each option style in the
2032 sections on the different option styles, below.  The differences are
2033 subtle, yet can often be very important; incorrect option placement
2034 can cause you to overwrite a number of important files.  We urge you
2035 to note these differences, and only use the option style(s) which
2036 makes the most sense to you until you feel comfortable with the others.
2038 Some options @emph{may} take an argument.  Such options may have at
2039 most long and short forms, they do not have old style equivalent.  The
2040 rules for specifying an argument for such options are stricter than
2041 those for specifying mandatory arguments.  Please, pay special
2042 attention to them.
2044 @menu
2045 * Long Options::                Long Option Style
2046 * Short Options::               Short Option Style
2047 * Old Options::                 Old Option Style
2048 * Mixing::                      Mixing Option Styles
2049 @end menu
2051 @node Long Options
2052 @subsection Long Option Style
2054 @cindex long options
2055 @cindex options, long style
2056 @cindex options, GNU style
2057 @cindex options, mnemonic names
2058 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2059 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2060 their corresponding short or old names.  It sometimes happens that a
2061 single long option has many different names which are
2062 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2063 long option names can be given unique abbreviations.  For example,
2064 @option{--cre} can be used in place of @option{--create} because there is no
2065 other long option which begins with @samp{cre}.  (One way to find
2066 this out is by trying it and seeing what happens; if a particular
2067 abbreviation could represent more than one option, @command{tar} will tell
2068 you that that abbreviation is ambiguous and you'll know that that
2069 abbreviation won't work.  You may also choose to run @samp{tar --help}
2070 to see a list of options.  Be aware that if you run @command{tar} with a
2071 unique abbreviation for the long name of an option you didn't want to
2072 use, you are stuck; @command{tar} will perform the command as ordered.)
2074 Long options are meant to be obvious and easy to remember, and their
2075 meanings are generally easier to discern than those of their
2076 corresponding short options (see below).  For example:
2078 @smallexample
2079 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2080 @end smallexample
2082 @noindent
2083 gives a fairly good set of hints about what the command does, even
2084 for those not fully acquainted with @command{tar}.
2086 @cindex arguments to long options
2087 @cindex long options with mandatory arguments
2088 Long options which require arguments take those arguments
2089 immediately following the option name.  There are two ways of
2090 specifying a mandatory argument.  It can be separated from the
2091 option name either by an equal sign, or by any amount of
2092 white space characters.  For example, the @option{--file} option (which
2093 tells the name of the @command{tar} archive) is given a file such as
2094 @file{archive.tar} as argument by using any of the following notations:
2095 @option{--file=archive.tar} or @option{--file archive.tar}.
2097 @cindex optional arguments to long options
2098 @cindex long options with optional arguments
2099 In contrast, optional arguments must always be introduced using
2100 an equal sign.  For example, the @option{--backup} option takes
2101 an optional argument specifying backup type.  It must be used
2102 as @option{--backup=@var{backup-type}}.
2104 @node Short Options
2105 @subsection Short Option Style
2107 @cindex short options
2108 @cindex options, short style
2109 @cindex options, traditional
2110 Most options also have a @dfn{short option} name.  Short options start with
2111 a single dash, and are followed by a single character, e.g., @option{-t}
2112 (which is equivalent to @option{--list}).  The forms are absolutely
2113 identical in function; they are interchangeable.
2115 The short option names are faster to type than long option names.
2117 @cindex arguments to short options
2118 @cindex short options with mandatory arguments
2119 Short options which require arguments take their arguments immediately
2120 following the option, usually separated by white space.  It is also
2121 possible to stick the argument right after the short option name, using
2122 no intervening space.  For example, you might write @w{@option{-f
2123 archive.tar}} or @option{-farchive.tar} instead of using
2124 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2125 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2126 specific archive, here named @file{archive.tar}.
2128 @cindex optional arguments to short options
2129 @cindex short options with optional arguments
2130 Short options which take optional arguments take their arguments
2131 immediately following the option letter, @emph{without any intervening
2132 white space characters}.
2134 Short options' letters may be clumped together, but you are not
2135 required to do this (as compared to old options; see below).  When
2136 short options are clumped as a set, use one (single) dash for them
2137 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2138 such a set is allowed to have an argument@footnote{Clustering many
2139 options, the last of which has an argument, is a rather opaque way to
2140 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2141 even be made helpful enough for considering such usages as invalid.}.
2143 When the options are separated, the argument for each option which requires
2144 an argument directly follows that option, as is usual for Unix programs.
2145 For example:
2147 @smallexample
2148 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2149 @end smallexample
2151 If you reorder short options' locations, be sure to move any arguments
2152 that belong to them.  If you do not move the arguments properly, you may
2153 end up overwriting files.
2155 @node Old Options
2156 @subsection Old Option Style
2157 @cindex options, old style
2158 @cindex old option style
2159 @cindex option syntax, traditional
2161 As far as we know, all @command{tar} programs, @acronym{GNU} and
2162 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2163 argument does not start with @samp{-}, it is assumed to specify option
2164 letters.  @GNUTAR{} supports old options not only for historical
2165 reasons, but also because many people are used to them.  If the first
2166 argument does not start with a dash, you are announcing the old option
2167 style instead of the short option style; old options are decoded
2168 differently.
2170 Like short options, old options are single letters.  However, old options
2171 must be written together as a single clumped set, without spaces separating
2172 them or dashes preceding them.  This set
2173 of letters must be the first to appear on the command line, after the
2174 @command{tar} program name and some white space; old options cannot appear
2175 anywhere else.  The letter of an old option is exactly the same letter as
2176 the corresponding short option.  For example, the old option @samp{t} is
2177 the same as the short option @option{-t}, and consequently, the same as the
2178 long option @option{--list}.  So for example, the command @w{@samp{tar
2179 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2181 @cindex arguments to old options
2182 @cindex old options with mandatory arguments
2183 When options that need arguments are given together with the command,
2184 all the associated arguments follow, in the same order as the options.
2185 Thus, the example given previously could also be written in the old
2186 style as follows:
2188 @smallexample
2189 $ @kbd{tar cvbf 20 /dev/rmt0}
2190 @end smallexample
2192 @noindent
2193 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2194 the argument of @option{-f}.
2196 The old style syntax can make it difficult to match
2197 option letters with their corresponding arguments, and is often
2198 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2199 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2200 argument for @option{-f}, and @option{-v} does not have a corresponding
2201 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2202 /dev/rmt0}} is clearer, putting all arguments next to the option they
2203 pertain to.
2205 If you want to reorder the letters in the old option argument, be
2206 sure to reorder any corresponding argument appropriately.
2208 This old way of writing @command{tar} options can surprise even experienced
2209 users.  For example, the two commands:
2211 @smallexample
2212 @kbd{tar cfz archive.tar.gz file}
2213 @kbd{tar -cfz archive.tar.gz file}
2214 @end smallexample
2216 @noindent
2217 are quite different.  The first example uses @file{archive.tar.gz} as
2218 the value for option @samp{f} and recognizes the option @samp{z}.  The
2219 second example, however, uses @file{z} as the value for option
2220 @samp{f} --- probably not what was intended.
2222 This second example could be corrected in many ways, among which the
2223 following are equivalent:
2225 @smallexample
2226 @kbd{tar -czf archive.tar.gz file}
2227 @kbd{tar -cf archive.tar.gz -z file}
2228 @kbd{tar cf archive.tar.gz -z file}
2229 @end smallexample
2231 @node Mixing
2232 @subsection Mixing Option Styles
2234 @cindex options, mixing different styles
2235 All three styles may be intermixed in a single @command{tar} command,
2236 so long as the rules for each style are fully
2237 respected@footnote{Before @GNUTAR{} version 1.11.6,
2238 a bug prevented intermixing old style options with long options in
2239 some cases.}.  Old style options and either of the modern styles of
2240 options may be mixed within a single @command{tar} command.  However,
2241 old style options must be introduced as the first arguments only,
2242 following the rule for old options (old options must appear directly
2243 after the @command{tar} command and some white space).  Modern options
2244 may be given only after all arguments to the old options have been
2245 collected.  If this rule is not respected, a modern option might be
2246 falsely interpreted as the value of the argument to one of the old
2247 style options.
2249 For example, all the following commands are wholly equivalent, and
2250 illustrate the many combinations and orderings of option styles.
2252 @smallexample
2253 @kbd{tar --create --file=archive.tar}
2254 @kbd{tar --create -f archive.tar}
2255 @kbd{tar --create -farchive.tar}
2256 @kbd{tar --file=archive.tar --create}
2257 @kbd{tar --file=archive.tar -c}
2258 @kbd{tar -c --file=archive.tar}
2259 @kbd{tar -c -f archive.tar}
2260 @kbd{tar -c -farchive.tar}
2261 @kbd{tar -cf archive.tar}
2262 @kbd{tar -cfarchive.tar}
2263 @kbd{tar -f archive.tar --create}
2264 @kbd{tar -f archive.tar -c}
2265 @kbd{tar -farchive.tar --create}
2266 @kbd{tar -farchive.tar -c}
2267 @kbd{tar c --file=archive.tar}
2268 @kbd{tar c -f archive.tar}
2269 @kbd{tar c -farchive.tar}
2270 @kbd{tar cf archive.tar}
2271 @kbd{tar f archive.tar --create}
2272 @kbd{tar f archive.tar -c}
2273 @kbd{tar fc archive.tar}
2274 @end smallexample
2276 On the other hand, the following commands are @emph{not} equivalent to
2277 the previous set:
2279 @smallexample
2280 @kbd{tar -f -c archive.tar}
2281 @kbd{tar -fc archive.tar}
2282 @kbd{tar -fcarchive.tar}
2283 @kbd{tar -farchive.tarc}
2284 @kbd{tar cfarchive.tar}
2285 @end smallexample
2287 @noindent
2288 These last examples mean something completely different from what the
2289 user intended (judging based on the example in the previous set which
2290 uses long options, whose intent is therefore very clear).  The first
2291 four specify that the @command{tar} archive would be a file named
2292 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2293 respectively.  The first two examples also specify a single non-option,
2294 @var{name} argument having the value @samp{archive.tar}.  The last
2295 example contains only old style option letters (repeating option
2296 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2297 @samp{h}, or @samp{i}), with no argument value.
2298 @FIXME{not sure i liked
2299 the first sentence of this paragraph..}
2301 @node All Options
2302 @section All @command{tar} Options
2304 The coming manual sections contain an alphabetical listing of all
2305 @command{tar} operations and options, with brief descriptions and
2306 cross-references to more in-depth explanations in the body of the manual.
2307 They also contain an alphabetically arranged table of the short option
2308 forms with their corresponding long option.  You can use this table as
2309 a reference for deciphering @command{tar} commands in scripts.
2311 @menu
2312 * Operation Summary::
2313 * Option Summary::
2314 * Short Option Summary::
2315 * Position-Sensitive Options::
2316 @end menu
2318 @node Operation Summary
2319 @subsection Operations
2321 @table @option
2323 @opsummary{append}
2324 @item --append
2325 @itemx -r
2327 Appends files to the end of the archive.  @xref{append}.
2329 @opsummary{catenate}
2330 @item --catenate
2331 @itemx -A
2333 Same as @option{--concatenate}.  @xref{concatenate}.
2335 @opsummary{compare}
2336 @item --compare
2337 @itemx -d
2339 Compares archive members with their counterparts in the file
2340 system, and reports differences in file size, mode, owner,
2341 modification date and contents.  @xref{compare}.
2343 @opsummary{concatenate}
2344 @item --concatenate
2345 @itemx -A
2347 Appends other @command{tar} archives to the end of the archive.
2348 @xref{concatenate}.
2350 @opsummary{create}
2351 @item --create
2352 @itemx -c
2354 Creates a new @command{tar} archive.  @xref{create}.
2356 @opsummary{delete}
2357 @item --delete
2359 Deletes members from the archive.  Don't try this on an archive on a
2360 tape!  @xref{delete}.
2362 @opsummary{diff}
2363 @item --diff
2364 @itemx -d
2366 Same @option{--compare}.  @xref{compare}.
2368 @opsummary{extract}
2369 @item --extract
2370 @itemx -x
2372 Extracts members from the archive into the file system.  @xref{extract}.
2374 @opsummary{get}
2375 @item --get
2376 @itemx -x
2378 Same as @option{--extract}.  @xref{extract}.
2380 @opsummary{list}
2381 @item --list
2382 @itemx -t
2384 Lists the members in an archive.  @xref{list}.
2386 @opsummary{update}
2387 @item --update
2388 @itemx -u
2390 Adds files to the end of the archive, but only if they are newer than
2391 their counterparts already in the archive, or if they do not already
2392 exist in the archive. @xref{update}.
2394 @end table
2396 @node Option Summary
2397 @subsection @command{tar} Options
2399 @table @option
2401 @opsummary{absolute-names}
2402 @item --absolute-names
2403 @itemx -P
2405 Normally when creating an archive, @command{tar} strips an initial
2406 @samp{/} from member names, and when extracting from an archive @command{tar}
2407 treats names specially if they have initial @samp{/} or internal
2408 @samp{..}.  This option disables that behavior.  @xref{absolute}.
2410 @opsummary{acls}
2411 @item --acls
2412 Enable POSIX ACLs support.  @xref{Extended File Attributes, acls}.
2414 @opsummary{after-date}
2415 @item --after-date
2417 (See @option{--newer}, @pxref{after})
2419 @opsummary{anchored}
2420 @item --anchored
2421 A pattern must match an initial subsequence of the name's components.
2422 @xref{controlling pattern-matching}.
2424 @opsummary{atime-preserve}
2425 @item --atime-preserve
2426 @itemx --atime-preserve=replace
2427 @itemx --atime-preserve=system
2429 Attempt to preserve the access time of files when reading them.  This
2430 option currently is effective only on files that you own, unless you
2431 have superuser privileges.
2433 @option{--atime-preserve=replace} remembers the access time of a file
2434 before reading it, and then restores the access time afterwards.  This
2435 may cause problems if other programs are reading the file at the same
2436 time, as the times of their accesses will be lost.  On most platforms
2437 restoring the access time also requires @command{tar} to restore the
2438 data modification time too, so this option may also cause problems if
2439 other programs are writing the file at the same time (@command{tar} attempts
2440 to detect this situation, but cannot do so reliably due to race
2441 conditions).  Worse, on most platforms restoring the access time also
2442 updates the status change time, which means that this option is
2443 incompatible with incremental backups.
2445 @option{--atime-preserve=system} avoids changing time stamps on files,
2446 without interfering with time stamp updates
2447 caused by other programs, so it works better with incremental backups.
2448 However, it requires a special @code{O_NOATIME} option from the
2449 underlying operating and file system implementation, and it also requires
2450 that searching directories does not update their access times.  As of
2451 this writing (November 2005) this works only with Linux, and only with
2452 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2453 way to know whether this feature actually works.  Sometimes
2454 @command{tar} knows that it does not work, and if you use
2455 @option{--atime-preserve=system} then @command{tar} complains and
2456 exits right away.  But other times @command{tar} might think that the
2457 option works when it actually does not.
2459 Currently @option{--atime-preserve} with no operand defaults to
2460 @option{--atime-preserve=replace}, but this may change in the future
2461 as support for @option{--atime-preserve=system} improves.
2463 If your operating or file system does not support
2464 @option{--atime-preserve=@-system}, you might be able to preserve access
2465 times reliably by using the @command{mount} command.  For example,
2466 you can mount the file system read-only, or access the file system via
2467 a read-only loopback mount, or use the @samp{noatime} mount option
2468 available on some systems.  However, mounting typically requires
2469 superuser privileges and can be a pain to manage.
2471 @opsummary{auto-compress}
2472 @item --auto-compress
2473 @itemx -a
2475 During a @option{--create} operation, enables automatic compressed
2476 format recognition based on the archive suffix.  The effect of this
2477 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2479 @opsummary{backup}
2480 @item --backup=@var{backup-type}
2482 Rather than deleting files from the file system, @command{tar} will
2483 back them up using simple or numbered backups, depending upon
2484 @var{backup-type}.  @xref{backup}.
2486 @opsummary{block-number}
2487 @item --block-number
2488 @itemx -R
2490 With this option present, @command{tar} prints error messages for read errors
2491 with the block number in the archive file.  @xref{block-number}.
2493 @opsummary{blocking-factor}
2494 @item --blocking-factor=@var{blocking}
2495 @itemx -b @var{blocking}
2497 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2498 record.  @xref{Blocking Factor}.
2500 @opsummary{bzip2}
2501 @item --bzip2
2502 @itemx -j
2504 This option tells @command{tar} to read or write archives through
2505 @code{bzip2}.  @xref{gzip}.
2507 @opsummary{check-device}
2508 @item --check-device
2509 Check device numbers when creating a list of modified files for
2510 incremental archiving.  This is the default.  @xref{device numbers},
2511 for a detailed description.
2513 @opsummary{checkpoint}
2514 @item --checkpoint[=@var{number}]
2516 This option directs @command{tar} to print periodic checkpoint
2517 messages as it reads through the archive.  It is intended for when you
2518 want a visual indication that @command{tar} is still running, but
2519 don't want to see @option{--verbose} output.  You can also instruct
2520 @command{tar} to execute a list of actions on each checkpoint, see
2521 @option{--checkpoint-action} below.  For a detailed description, see
2522 @ref{checkpoints}.
2524 @opsummary{checkpoint-action}
2525 @item --checkpoint-action=@var{action}
2526 Instruct @command{tar} to execute an action upon hitting a
2527 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2528 for a complete description.
2530 The @var{action} argument can be one of the following:
2532 @table @asis
2533 @item bell
2534 Produce an audible bell on the console.
2536 @item dot
2537 @itemx .
2538 Print a single dot on the standard listing stream.
2540 @item echo
2541 Display a textual message on the standard error, with the status and
2542 number of the checkpoint.  This is the default.
2544 @item echo=@var{string}
2545 Display @var{string} on the standard error.  Before output, the string
2546 is subject to meta-character expansion.
2548 @item exec=@var{command}
2549 Execute the given @var{command}.
2551 @item sleep=@var{time}
2552 Wait for @var{time} seconds.
2554 @item ttyout=@var{string}
2555 Output @var{string} on the current console (@file{/dev/tty}).
2557 @item totals
2558 Print statistics (see @pxref{totals}).
2560 @item wait=@var{signo}
2561 Wait for signal @var{signo}.
2562 @end table
2564 Several @option{--checkpoint-action} options can be specified.  The
2565 supplied actions will be executed in order of their appearance in the
2566 command line.
2568 Using @option{--checkpoint-action} without @option{--checkpoint}
2569 assumes default checkpoint frequency of one checkpoint per 10 records.
2571 @opsummary{check-links}
2572 @item --check-links
2573 @itemx -l
2574 If this option was given, @command{tar} will check the number of links
2575 dumped for each processed file.  If this number does not match the
2576 total number of hard links for the file, a warning message will be
2577 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2578 synonym for @option{--one-file-system}.  The current semantics, which
2579 complies to UNIX98, was introduced with version
2580 1.15.91. @xref{Changes}, for more information.}.
2582 @xref{hard links}.
2584 @opsummary{compress}
2585 @opsummary{uncompress}
2586 @item --compress
2587 @itemx --uncompress
2588 @itemx -Z
2590 @command{tar} will use the @command{compress} program when reading or
2591 writing the archive.  This allows you to directly act on archives
2592 while saving space.  @xref{gzip}.
2594 @opsummary{clamp-mtime}
2595 @item --clamp-mtime
2597 (See @option{--mtime}.)
2599 @opsummary{confirmation}
2600 @item --confirmation
2602 (See @option{--interactive}.)  @xref{interactive}.
2604 @opsummary{delay-directory-restore}
2605 @item --delay-directory-restore
2607 Delay setting modification times and permissions of extracted
2608 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2610 @opsummary{dereference}
2611 @item --dereference
2612 @itemx -h
2614 When reading or writing a file to be archived, @command{tar} accesses
2615 the file that a symbolic link points to, rather than the symlink
2616 itself.  @xref{dereference}.
2618 @opsummary{directory}
2619 @item --directory=@var{dir}
2620 @itemx -C @var{dir}
2622 When this option is specified, @command{tar} will change its current directory
2623 to @var{dir} before performing any operations.  When this option is used
2624 during archive creation, it is order sensitive.  @xref{directory}.
2626 @opsummary{exclude}
2627 @item --exclude=@var{pattern}
2629 When performing operations, @command{tar} will skip files that match
2630 @var{pattern}.  @xref{exclude}.
2632 @opsummary{exclude-backups}
2633 @item --exclude-backups
2634 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2636 @opsummary{exclude-from}
2637 @item --exclude-from=@var{file}
2638 @itemx -X @var{file}
2640 Similar to @option{--exclude}, except @command{tar} will use the list of
2641 patterns in the file @var{file}.  @xref{exclude}.
2643 @opsummary{exclude-caches}
2644 @item --exclude-caches
2646 Exclude from dump any directory containing a valid cache directory
2647 tag file, but still dump the directory node and the tag file itself.
2649 @xref{exclude,, exclude-caches}.
2651 @opsummary{exclude-caches-under}
2652 @item --exclude-caches-under
2654 Exclude from dump any directory containing a valid cache directory
2655 tag file, but still dump the directory node itself.
2657 @xref{exclude}.
2659 @opsummary{exclude-caches-all}
2660 @item --exclude-caches-all
2662 Exclude from dump any directory containing a valid cache directory
2663 tag file.  @xref{exclude}.
2665 @opsummary{exclude-ignore}
2666 @item --exclude-ignore=@var{file}
2667 Before dumping a directory, @command{tar} checks if it contains
2668 @var{file}.  If so, exclusion patterns are read from this file.
2669 The patterns affect only the directory itself.  @xref{exclude}.
2671 @opsummary{exclude-ignore-recursive}
2672 @item --exclude-ignore-recursive=@var{file}
2673 Before dumping a directory, @command{tar} checks if it contains
2674 @var{file}.  If so, exclusion patterns are read from this file.
2675 The patterns affect the directory and all itssubdirectories.
2676 @xref{exclude}.
2678 @opsummary{exclude-tag}
2679 @item --exclude-tag=@var{file}
2681 Exclude from dump any directory containing file named @var{file}, but
2682 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2684 @opsummary{exclude-tag-under}
2685 @item --exclude-tag-under=@var{file}
2687 Exclude from dump the contents of any directory containing file
2688 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2689 exclude-tag-under}.
2691 @opsummary{exclude-tag-all}
2692 @item --exclude-tag-all=@var{file}
2694 Exclude from dump any directory containing file named @var{file}.
2695 @xref{exclude,,exclude-tag-all}.
2697 @opsummary{exclude-vcs}
2698 @item --exclude-vcs
2700 Exclude from dump directories and files, that are internal for some
2701 widely used version control systems.
2703 @xref{exclude-vcs}.
2705 @opsummary{exclude-vcs-ignores}
2706 @item --exclude-vcs-ignores
2707 Exclude files that match patterns read from VCS-specific ignore
2708 files.  Supported files are: @file{.cvsignore}, @file{.gitignore},
2709 @file{.bzrignore}, and @file{.hgignore}.  The semantics of each file
2710 is the same as for the corresponding VCS, e.g. patterns read from
2711 @file{.gitignore} affect the directory and all its subdirectories.
2712 @xref{exclude-vcs-ignores}.
2714 @opsummary{file}
2715 @item --file=@var{archive}
2716 @itemx -f @var{archive}
2718 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2719 performs operations on, rather than @command{tar}'s compilation dependent
2720 default.  @xref{file tutorial}.
2722 @opsummary{files-from}
2723 @item --files-from=@var{file}
2724 @itemx -T @var{file}
2726 @command{tar} will use the contents of @var{file} as a list of archive members
2727 or files to operate on, in addition to those specified on the
2728 command-line.  @xref{files}.
2730 @opsummary{force-local}
2731 @item --force-local
2733 Forces @command{tar} to interpret the file name given to @option{--file}
2734 as a local file, even if it looks like a remote tape drive name.
2735 @xref{local and remote archives}.
2737 @opsummary{format}
2738 @item --format=@var{format}
2739 @itemx -H @var{format}
2741 Selects output archive format.  @var{Format} may be one of the
2742 following:
2744 @table @samp
2745 @item v7
2746 Creates an archive that is compatible with Unix V7 @command{tar}.
2748 @item oldgnu
2749 Creates an archive that is compatible with GNU @command{tar} version
2750 1.12 or earlier.
2752 @item gnu
2753 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2754 @samp{oldgnu} with the only difference in the way it handles long
2755 numeric fields.
2757 @item ustar
2758 Creates a @acronym{POSIX.1-1988} compatible archive.
2760 @item posix
2761 Creates a @acronym{POSIX.1-2001 archive}.
2763 @end table
2765 @xref{Formats}, for a detailed discussion of these formats.
2767 @opsummary{full-time}
2768 @item --full-time
2769 This option instructs @command{tar} to print file times to their full
2770 resolution.  Usually this means 1-second resolution, but that depends
2771 on the underlying file system.  The @option{--full-time} option takes
2772 effect only when detailed output (verbosity level 2 or higher) has
2773 been requested using the @option{--verbose} option, e.g., when listing
2774 or extracting archives:
2776 @smallexample
2777 $ @kbd{tar -t -v --full-time -f archive.tar}
2778 @end smallexample
2780 @noindent
2781 or, when creating an archive:
2783 @smallexample
2784 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2785 @end smallexample
2787 Notice, thar when creating the archive you need to specify
2788 @option{--verbose} twice to get a detailed output (@pxref{verbose
2789 tutorial}).
2791 @opsummary{group}
2792 @item --group=@var{group}
2794 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2795 rather than the group from the source file.  @var{group} can specify a
2796 symbolic name, or a numeric @acronym{ID}, or both as
2797 @var{name}:@var{id}.  @xref{override}.
2799 Also see the @option{--group-map} option and comments for the
2800 @option{--owner=@var{user}} option.
2802 @opsummary{group-map}
2803 @item --group-map=@var{file}
2805 Read owner group translation map from @var{file}.  This option allows to
2806 translate only certain group names and/or UIDs.  @xref{override}, for a
2807 detailed description.  When used together with @option{--group}
2808 option, the latter affects only those files whose owner group is not listed
2809 in the @var{file}.
2811 This option does not affect extraction from archives.
2813 @opsummary{gzip}
2814 @opsummary{gunzip}
2815 @opsummary{ungzip}
2816 @item --gzip
2817 @itemx --gunzip
2818 @itemx --ungzip
2819 @itemx -z
2821 This option tells @command{tar} to read or write archives through
2822 @command{gzip}, allowing @command{tar} to directly operate on several
2823 kinds of compressed archives transparently.  @xref{gzip}.
2825 @opsummary{hard-dereference}
2826 @item --hard-dereference
2827 When creating an archive, dereference hard links and store the files
2828 they refer to, instead of creating usual hard link members.
2830 @xref{hard links}.
2832 @opsummary{help}
2833 @item --help
2834 @itemx -?
2836 @command{tar} will print out a short message summarizing the operations and
2837 options to @command{tar} and exit. @xref{help}.
2839 @opsummary{hole-detection}
2840 @item --hole-detection=@var{method}
2841 Use @var{method} to detect holes in sparse files.  This option implies
2842 @option{--sparse}.  Valid methods are @samp{seek} and @samp{raw}.
2843 Default is @samp{seek} with fallback to @samp{raw} when not
2844 applicable. @xref{sparse}.
2846 @opsummary{ignore-case}
2847 @item --ignore-case
2848 Ignore case when matching member or file names with
2849 patterns. @xref{controlling pattern-matching}.
2851 @opsummary{ignore-command-error}
2852 @item --ignore-command-error
2853 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2855 @opsummary{ignore-failed-read}
2856 @item --ignore-failed-read
2858 Do not exit unsuccessfully merely because an unreadable file was encountered.
2859 @xref{Ignore Failed Read}.
2861 @opsummary{ignore-zeros}
2862 @item --ignore-zeros
2863 @itemx -i
2865 With this option, @command{tar} will ignore zeroed blocks in the
2866 archive, which normally signals EOF.  @xref{Reading}.
2868 @opsummary{incremental}
2869 @item --incremental
2870 @itemx -G
2872 Informs @command{tar} that it is working with an old
2873 @acronym{GNU}-format incremental backup archive.  It is intended
2874 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2875 for a detailed discussion of incremental archives.
2877 @opsummary{index-file}
2878 @item --index-file=@var{file}
2880 Send verbose output to @var{file} instead of to standard output.
2882 @opsummary{info-script}
2883 @opsummary{new-volume-script}
2884 @item --info-script=@var{command}
2885 @itemx --new-volume-script=@var{command}
2886 @itemx -F @var{command}
2888 When @command{tar} is performing multi-tape backups, @var{command} is run
2889 at the end of each tape.  If it exits with nonzero status,
2890 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2891 discussion of this feature.
2893 @opsummary{interactive}
2894 @item --interactive
2895 @itemx --confirmation
2896 @itemx -w
2898 Specifies that @command{tar} should ask the user for confirmation before
2899 performing potentially destructive options, such as overwriting files.
2900 @xref{interactive}.
2902 @opsummary{keep-directory-symlink}
2903 @item --keep-directory-symlink
2905 This option changes the behavior of tar when it encounters a symlink
2906 with the same name as the directory that it is about to extract.  By
2907 default, in this case tar would first remove the symlink and then
2908 proceed extracting the directory.
2910 The @option{--keep-directory-symlink} option disables this behavior
2911 and instructs tar to follow symlinks to directories when extracting
2912 from the archive.
2914 It is mainly intended to provide compatibility with the Slackware
2915 installation scripts.
2917 @opsummary{keep-newer-files}
2918 @item --keep-newer-files
2920 Do not replace existing files that are newer than their archive copies
2921 when extracting files from an archive.
2923 @opsummary{keep-old-files}
2924 @item --keep-old-files
2925 @itemx -k
2927 Do not overwrite existing files when extracting files from an
2928 archive.  Return error if such files exist.  See also
2929 @ref{--skip-old-files}.
2931 @xref{Keep Old Files}.
2933 @opsummary{label}
2934 @item --label=@var{name}
2935 @itemx -V @var{name}
2937 When creating an archive, instructs @command{tar} to write @var{name}
2938 as a name record in the archive.  When extracting or listing archives,
2939 @command{tar} will only operate on archives that have a label matching
2940 the pattern specified in @var{name}.  @xref{Tape Files}.
2942 @opsummary{level}
2943 @item --level=@var{n}
2944 Force incremental backup of level @var{n}.  As of @GNUTAR version
2945 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2946 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2947 effectively ignored.  @xref{--level=0}, for details and examples.
2949 The use of this option is valid only in conjunction with the
2950 @option{--listed-incremental} option.  @xref{Incremental Dumps},
2951 for a detailed description.
2953 @opsummary{listed-incremental}
2954 @item --listed-incremental=@var{snapshot-file}
2955 @itemx -g @var{snapshot-file}
2957 During a @option{--create} operation, specifies that the archive that
2958 @command{tar} creates is a new @acronym{GNU}-format incremental
2959 backup, using @var{snapshot-file} to determine which files to backup.
2960 With other operations, informs @command{tar} that the archive is in
2961 incremental format.  @xref{Incremental Dumps}.
2963 @opsummary{lzip}
2964 @item --lzip
2966 This option tells @command{tar} to read or write archives through
2967 @command{lzip}.  @xref{gzip}.
2969 @opsummary{lzma}
2970 @item --lzma
2972 This option tells @command{tar} to read or write archives through
2973 @command{lzma}.  @xref{gzip}.
2975 @item --lzop
2977 This option tells @command{tar} to read or write archives through
2978 @command{lzop}.  @xref{gzip}.
2980 @opsummary{mode}
2981 @item --mode=@var{permissions}
2983 When adding files to an archive, @command{tar} will use
2984 @var{permissions} for the archive members, rather than the permissions
2985 from the files.  @var{permissions} can be specified either as an octal
2986 number or as symbolic permissions, like with
2987 @command{chmod}. @xref{override}.
2989 @opsummary{mtime}
2990 @item --mtime=@var{date}
2992 When adding files to an archive, @command{tar} will use @var{date} as
2993 the modification time of members when creating archives, instead of
2994 their actual modification times.  The value of @var{date} can be
2995 either a textual date representation (@pxref{Date input formats}) or a
2996 name of the existing file, starting with @samp{/} or @samp{.}.  In the
2997 latter case, the modification time of that file is used. @xref{override}.
2999 When @command{--clamp-mtime} is also specified, files with
3000 modification times earlier than @var{date} will retain their actual
3001 modification times, and @var{date} will only be used for files whose
3002 modification times are later than @var{date}.
3004 @opsummary{multi-volume}
3005 @item --multi-volume
3006 @itemx -M
3008 Informs @command{tar} that it should create or otherwise operate on a
3009 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
3011 @opsummary{new-volume-script}
3012 @item --new-volume-script
3014 (see @option{--info-script})
3016 @opsummary{newer}
3017 @item --newer=@var{date}
3018 @itemx --after-date=@var{date}
3019 @itemx -N
3021 When creating an archive, @command{tar} will only add files that have changed
3022 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
3023 is taken to be the name of a file whose data modification time specifies
3024 the date.  @xref{after}.
3026 @opsummary{newer-mtime}
3027 @item --newer-mtime=@var{date}
3029 Like @option{--newer}, but add only files whose
3030 contents have changed (as opposed to just @option{--newer}, which will
3031 also back up files for which any status information has
3032 changed).  @xref{after}.
3034 @opsummary{no-acls}
3035 @item --no-acls
3036 Disable the POSIX ACLs support.  @xref{Extended File Attributes, acls}.
3038 @opsummary{no-anchored}
3039 @item --no-anchored
3040 An exclude pattern can match any subsequence of the name's components.
3041 @xref{controlling pattern-matching}.
3043 @opsummary{no-auto-compress}
3044 @item --no-auto-compress
3046 Disables automatic compressed format recognition based on the archive
3047 suffix.  @xref{--auto-compress}.  @xref{gzip}.
3049 @opsummary{no-check-device}
3050 @item --no-check-device
3051 Do not check device numbers when creating a list of modified files
3052 for incremental archiving.  @xref{device numbers}, for
3053 a detailed description.
3055 @opsummary{no-delay-directory-restore}
3056 @item --no-delay-directory-restore
3058 Modification times and permissions of extracted
3059 directories are set when all files from this directory have been
3060 extracted.  This is the default.
3061 @xref{Directory Modification Times and Permissions}.
3063 @opsummary{no-ignore-case}
3064 @item --no-ignore-case
3065 Use case-sensitive matching.
3066 @xref{controlling pattern-matching}.
3068 @opsummary{no-ignore-command-error}
3069 @item --no-ignore-command-error
3070 Print warnings about subprocesses that terminated with a nonzero exit
3071 code. @xref{Writing to an External Program}.
3073 @opsummary{no-null}
3074 @item --no-null
3076 If the @option{--null} option was given previously, this option
3077 cancels its effect, so that any following @option{--files-from}
3078 options will expect their file lists to be newline-terminated.
3080 @opsummary{no-overwrite-dir}
3081 @item --no-overwrite-dir
3083 Preserve metadata of existing directories when extracting files
3084 from an archive.  @xref{Overwrite Old Files}.
3086 @opsummary{no-quote-chars}
3087 @item --no-quote-chars=@var{string}
3088 Remove characters listed in @var{string} from the list of quoted
3089 characters set by the previous @option{--quote-chars} option
3090 (@pxref{quoting styles}).
3092 @opsummary{no-recursion}
3093 @item --no-recursion
3095 With this option, @command{tar} will not recurse into directories.
3096 @xref{recurse}.
3098 @opsummary{no-same-owner}
3099 @item --no-same-owner
3100 @itemx -o
3102 When extracting an archive, do not attempt to preserve the owner
3103 specified in the @command{tar} archive.  This the default behavior
3104 for ordinary users.
3106 @opsummary{no-same-permissions}
3107 @item --no-same-permissions
3109 When extracting an archive, subtract the user's umask from files from
3110 the permissions specified in the archive.  This is the default behavior
3111 for ordinary users.
3113 @opsummary{no-seek}
3114 @item --no-seek
3116 The archive media does not support seeks to arbitrary
3117 locations.  Usually @command{tar} determines automatically whether
3118 the archive can be seeked or not.  Use this option to disable this
3119 mechanism.
3121 @opsummary{no-selinux}
3122 @item --no-selinux
3123 Disable SELinux context support.  @xref{Extended File Attributes, SELinux}.
3125 @opsummary{no-unquote}
3126 @item --no-unquote
3127 Treat all input file or member names literally, do not interpret
3128 escape sequences.  @xref{input name quoting}.
3130 @opsummary{no-verbatim-files-from}
3131 @item --no-verbatim-files-from
3133 Instructs @GNUTAR{} to treat each line read from a file list as if it
3134 were supplied in the command line.  I.e., leading and trailing
3135 whitespace is removed and, if the result begins with a dash, it is
3136 treated as a @GNUTAR{} command line option.
3138 This is default behavior.  This option is provided as a way to restore
3139 it after @option{--verbatim-files-from} option.
3141 It is implied by the @option{--no-null} option.
3143 @xref{no-verbatim-files-from}.
3145 @opsummary{no-wildcards}
3146 @item --no-wildcards
3147 Do not use wildcards.
3148 @xref{controlling pattern-matching}.
3150 @opsummary{no-wildcards-match-slash}
3151 @item --no-wildcards-match-slash
3152 Wildcards do not match @samp{/}.
3153 @xref{controlling pattern-matching}.
3155 @opsummary{no-xattrs}
3156 @item --no-xattrs
3157 Disable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3159 @opsummary{null}
3160 @item --null
3162 When @command{tar} is using the @option{--files-from} option, this option
3163 instructs @command{tar} to expect file names terminated with
3164 @acronym{NUL}, and to process file names verbatim.
3166 This means that @command{tar} correctly works with file names that
3167 contain newlines or begin with a dash.
3169 @xref{nul}.
3171 See also @ref{verbatim-files-from}.
3173 @opsummary{numeric-owner}
3174 @item --numeric-owner
3176 This option will notify @command{tar} that it should use numeric user
3177 and group IDs when creating a @command{tar} file, rather than names.
3178 @xref{Attributes}.
3180 @item -o
3181 The function of this option depends on the action @command{tar} is
3182 performing.  When extracting files, @option{-o} is a synonym for
3183 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3184 restoring ownership of files being extracted.
3186 When creating an archive, it is a synonym for
3187 @option{--old-archive}.  This behavior is for compatibility
3188 with previous versions of @GNUTAR{}, and will be
3189 removed in future releases.
3191 @xref{Changes}, for more information.
3193 @opsummary{occurrence}
3194 @item --occurrence[=@var{number}]
3196 This option can be used in conjunction with one of the subcommands
3197 @option{--delete}, @option{--diff}, @option{--extract} or
3198 @option{--list} when a list of files is given either on the command
3199 line or via @option{-T} option.
3201 This option instructs @command{tar} to process only the @var{number}th
3202 occurrence of each named file.  @var{Number} defaults to 1, so
3204 @smallexample
3205 tar -x -f archive.tar --occurrence filename
3206 @end smallexample
3208 @noindent
3209 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3210 and will terminate without scanning to the end of the archive.
3212 @opsummary{old-archive}
3213 @item --old-archive
3214 Synonym for @option{--format=v7}.
3216 @opsummary{one-file-system}
3217 @item --one-file-system
3218 Used when creating an archive.  Prevents @command{tar} from recursing into
3219 directories that are on different file systems from the current
3220 directory.
3222 @opsummary{one-top-level}
3223 @item --one-top-level[=@var{dir}]
3224 Tells @command{tar} to create a new directory beneath the extraction directory
3225 (or the one passed to @option{-C}) and use it to guard against
3226 tarbombs.  In the absence of @var{dir} argument, the name of the new directory
3227 will be equal to the base name of the archive (file name minus the
3228 archive suffix, if recognized).  Any member names that do not begin
3229 with that directory name (after
3230 transformations from @option{--transform} and
3231 @option{--strip-components}) will be prefixed with it.  Recognized
3232 file name suffixes are @samp{.tar}, and any compression suffixes
3233 recognizable by @xref{--auto-compress}.
3235 @opsummary{overwrite}
3236 @item --overwrite
3238 Overwrite existing files and directory metadata when extracting files
3239 from an archive.  @xref{Overwrite Old Files}.
3241 @opsummary{overwrite-dir}
3242 @item --overwrite-dir
3244 Overwrite the metadata of existing directories when extracting files
3245 from an archive.  @xref{Overwrite Old Files}.
3247 @opsummary{owner}
3248 @item --owner=@var{user}
3250 Specifies that @command{tar} should use @var{user} as the owner of members
3251 when creating archives, instead of the user associated with the source
3252 file.  @var{user} can specify a symbolic name, or a numeric
3253 @acronym{ID}, or both as @var{name}:@var{id}.
3254 @xref{override}.
3256 This option does not affect extraction from archives.  See also
3257 @option{--owner-map}, below.
3259 @opsummary{owner-map}
3260 @item --owner-map=@var{file}
3262 Read owner translation map from @var{file}.  This option allows to
3263 translate only certain owner names or UIDs.  @xref{override}, for a
3264 detailed description.  When used together with @option{--owner}
3265 option, the latter affects only those files whose owner is not listed
3266 in the @var{file}.
3268 This option does not affect extraction from archives.
3270 @opsummary{pax-option}
3271 @item --pax-option=@var{keyword-list}
3272 This option enables creation of the archive in @acronym{POSIX.1-2001}
3273 format (@pxref{posix}) and modifies the way @command{tar} handles the
3274 extended header keywords.  @var{Keyword-list} is a comma-separated
3275 list of keyword options.  @xref{PAX keywords}, for a detailed
3276 discussion.
3278 @opsummary{portability}
3279 @item --portability
3280 @itemx --old-archive
3281 Synonym for @option{--format=v7}.
3283 @opsummary{posix}
3284 @item --posix
3285 Same as @option{--format=posix}.
3287 @opsummary{preserve-order}
3288 @item --preserve-order
3290 (See @option{--same-order}; @pxref{Reading}.)
3292 @opsummary{preserve-permissions}
3293 @opsummary{same-permissions}
3294 @item --preserve-permissions
3295 @itemx --same-permissions
3296 @itemx -p
3298 When @command{tar} is extracting an archive, it normally subtracts the
3299 users' umask from the permissions specified in the archive and uses
3300 that number as the permissions to create the destination file.
3301 Specifying this option instructs @command{tar} that it should use the
3302 permissions directly from the archive.  @xref{Setting Access Permissions}.
3304 @opsummary{quote-chars}
3305 @item --quote-chars=@var{string}
3306 Always quote characters from @var{string}, even if the selected
3307 quoting style would not quote them (@pxref{quoting styles}).
3309 @opsummary{quoting-style}
3310 @item --quoting-style=@var{style}
3311 Set quoting style to use when printing member and file names
3312 (@pxref{quoting styles}). Valid @var{style} values are:
3313 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3314 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3315 style is @code{escape}, unless overridden while configuring the
3316 package.
3318 @opsummary{read-full-records}
3319 @item --read-full-records
3320 @itemx -B
3322 Specifies that @command{tar} should reblock its input, for reading
3323 from pipes on systems with buggy implementations.  @xref{Reading}.
3325 @opsummary{record-size}
3326 @item --record-size=@var{size}[@var{suf}]
3328 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3329 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3330 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3331 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3332 description of this option.
3334 @opsummary{recursion}
3335 @item --recursion
3337 With this option, @command{tar} recurses into directories (default).
3338 @xref{recurse}.
3340 @opsummary{recursive-unlink}
3341 @item --recursive-unlink
3343 Remove existing
3344 directory hierarchies before extracting directories of the same name
3345 from the archive.  @xref{Recursive Unlink}.
3347 @opsummary{remove-files}
3348 @item --remove-files
3350 Directs @command{tar} to remove the source file from the file system after
3351 appending it to an archive.  @xref{remove files}.
3353 @opsummary{restrict}
3354 @item --restrict
3356 Disable use of some potentially harmful @command{tar} options.
3357 Currently this option disables shell invocation from multi-volume menu
3358 (@pxref{Using Multiple Tapes}).
3360 @opsummary{rmt-command}
3361 @item --rmt-command=@var{cmd}
3363 Notifies @command{tar} that it should use @var{cmd} instead of
3364 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3366 @opsummary{rsh-command}
3367 @item --rsh-command=@var{cmd}
3369 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3370 devices.  @xref{Device}.
3372 @opsummary{same-order}
3373 @item --same-order
3374 @itemx --preserve-order
3375 @itemx -s
3377 This option is an optimization for @command{tar} when running on machines with
3378 small amounts of memory.  It informs @command{tar} that the list of file
3379 arguments has already been sorted to match the order of files in the
3380 archive.  @xref{Reading}.
3382 @opsummary{same-owner}
3383 @item --same-owner
3385 When extracting an archive, @command{tar} will attempt to preserve the owner
3386 specified in the @command{tar} archive with this option present.
3387 This is the default behavior for the superuser; this option has an
3388 effect only for ordinary users.  @xref{Attributes}.
3390 @opsummary{same-permissions}
3391 @item --same-permissions
3393 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3395 @opsummary{seek}
3396 @item --seek
3397 @itemx -n
3399 Assume that the archive media supports seeks to arbitrary
3400 locations.  Usually @command{tar} determines automatically whether
3401 the archive can be seeked or not.  This option is intended for use
3402 in cases when such recognition fails.  It takes effect only if the
3403 archive is open for reading (e.g. with @option{--list} or
3404 @option{--extract} options).
3406 @opsummary{selinux}
3407 @item --selinux
3408 Enable the SELinux context support.
3409 @xref{Extended File Attributes, selinux}.
3411 @opsummary{show-defaults}
3412 @item --show-defaults
3414 Displays the default options used by @command{tar} and exits
3415 successfully.  This option is intended for use in shell scripts.
3416 Here is an example of what you can see using this option:
3418 @smallexample
3419 $ @kbd{tar --show-defaults}
3420 --format=gnu -f- -b20 --quoting-style=escape
3421 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3422 @end smallexample
3424 @noindent
3425 Notice, that this option outputs only one line.  The example output
3426 above has been split to fit page boundaries. @xref{defaults}.
3428 @opsummary{show-omitted-dirs}
3429 @item --show-omitted-dirs
3431 Instructs @command{tar} to mention the directories it is skipping when
3432 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3434 @opsummary{show-snapshot-field-ranges}
3435 @item --show-snapshot-field-ranges
3437 Displays the range of values allowed by this version of @command{tar}
3438 for each field in the snapshot file, then exits successfully.
3439 @xref{Snapshot Files}.
3441 @opsummary{show-transformed-names}
3442 @opsummary{show-stored-names}
3443 @item --show-transformed-names
3444 @itemx --show-stored-names
3446 Display file or member names after applying any transformations
3447 (@pxref{transform}).  In particular, when used in conjunction with one of
3448 the archive creation operations it instructs @command{tar} to list the
3449 member names stored in the archive, as opposed to the actual file
3450 names.  @xref{listing member and file names}.
3452 @opsummary{skip-old-files}
3453 @item --skip-old-files
3455 Do not overwrite existing files when extracting files from an
3456 archive.  @xref{Keep Old Files}.
3458 This option differs from @option{--keep-old-files} in that it does not
3459 treat such files as an error, instead it just silently avoids
3460 overwriting them.
3462 The @option{--warning=existing-file} option can be used together with
3463 this option to produce warning messages about existing old files
3464 (@pxref{warnings}).
3466 @opsummary{sort}
3467 @item --sort=@var{order}
3468 Specify the directory sorting order when reading directories.
3469 @var{Order} may be one of the following:
3471 @table @samp
3472 @item none
3473 No directory sorting is performed. This is the default.
3475 @item name
3476 Sort the directory entries on name. The operating system may deliver
3477 directory entries in a more or less random order, and sorting them
3478 makes archive creation reproducible.
3480 @item inode
3481 Sort the directory entries on inode number. Sorting directories on
3482 inode number may reduce the amount of disk seek operations when
3483 creating an archive for some file systems.
3485 @end table
3487 @opsummary{sparse}
3488 @item --sparse
3489 @itemx -S
3491 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3492 sparse files efficiently.  @xref{sparse}.
3494 @opsummary{sparse-version}
3495 @item --sparse-version=@var{version}
3497 Specifies the @dfn{format version} to use when archiving sparse
3498 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3499 of the supported sparse formats, @xref{Sparse Formats}.
3501 @opsummary{starting-file}
3502 @item --starting-file=@var{name}
3503 @itemx -K @var{name}
3505 This option affects extraction only; @command{tar} will skip extracting
3506 files in the archive until it finds one that matches @var{name}.
3507 @xref{Scarce}.
3509 @opsummary{strip-components}
3510 @item --strip-components=@var{number}
3511 Strip given @var{number} of leading components from file names before
3512 extraction.  For example, if archive @file{archive.tar} contained
3513 @file{/some/file/name}, then running
3515 @smallexample
3516 tar --extract --file archive.tar --strip-components=2
3517 @end smallexample
3519 @noindent
3520 would extract this file to file @file{name}.
3522 @xref{transform}.
3524 @opsummary{suffix}
3525 @item --suffix=@var{suffix}
3527 Alters the suffix @command{tar} uses when backing up files from the default
3528 @samp{~}.  @xref{backup}.
3530 @opsummary{tape-length}
3531 @item --tape-length=@var{num}[@var{suf}]
3532 @itemx -L @var{num}[@var{suf}]
3534 Specifies the length of tapes that @command{tar} is writing as being
3535 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3536 specifies a multiplicative factor to be used instead of 1024.  For
3537 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3538 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3539 discussion of this option.
3541 @opsummary{test-label}
3542 @item --test-label
3544 Reads the volume label.  If an argument is specified, test whether it
3545 matches the volume label.  @xref{--test-label option}.
3547 @opsummary{to-command}
3548 @item --to-command=@var{command}
3550 During extraction @command{tar} will pipe extracted files to the
3551 standard input of @var{command}.  @xref{Writing to an External Program}.
3553 @opsummary{to-stdout}
3554 @item --to-stdout
3555 @itemx -O
3557 During extraction, @command{tar} will extract files to stdout rather
3558 than to the file system.  @xref{Writing to Standard Output}.
3560 @opsummary{totals}
3561 @item --totals[=@var{signo}]
3563 Displays the total number of bytes transferred when processing an
3564 archive.  If an argument is given, these data are displayed on
3565 request, when signal @var{signo} is delivered to @command{tar}.
3566 @xref{totals}.
3568 @opsummary{touch}
3569 @item --touch
3570 @itemx -m
3572 Sets the data modification time of extracted files to the extraction time,
3573 rather than the data modification time stored in the archive.
3574 @xref{Data Modification Times}.
3576 @opsummary{transform}
3577 @opsummary{xform}
3578 @item --transform=@var{sed-expr}
3579 @itemx --xform=@var{sed-expr}
3580 Transform file or member names using @command{sed} replacement expression
3581 @var{sed-expr}.  For example,
3583 @smallexample
3584 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3585 @end smallexample
3587 @noindent
3588 will add to @file{archive} files from the current working directory,
3589 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3590 discussion, @xref{transform}.
3592 To see transformed member names in verbose listings, use
3593 @option{--show-transformed-names} option
3594 (@pxref{show-transformed-names}).
3596 @opsummary{uncompress}
3597 @item --uncompress
3599 (See @option{--compress}, @pxref{gzip})
3601 @opsummary{ungzip}
3602 @item --ungzip
3604 (See @option{--gzip}, @pxref{gzip})
3606 @opsummary{unlink-first}
3607 @item --unlink-first
3608 @itemx -U
3610 Directs @command{tar} to remove the corresponding file from the file
3611 system before extracting it from the archive.  @xref{Unlink First}.
3613 @opsummary{unquote}
3614 @item --unquote
3615 Enable unquoting input file or member names (default).  @xref{input
3616 name quoting}.
3618 @opsummary{use-compress-program}
3619 @item --use-compress-program=@var{prog}
3620 @itemx -I=@var{prog}
3622 Instructs @command{tar} to access the archive through @var{prog}, which is
3623 presumed to be a compression program of some sort.  @xref{gzip}.
3625 @opsummary{utc}
3626 @item --utc
3628 Display file modification dates in @acronym{UTC}.  This option implies
3629 @option{--verbose}.
3631 @opsummary{verbatim-files-from}
3632 @item --verbatim-files-from
3634 Instructs @GNUTAR{} to treat each line read from a file list as a file
3635 name, even if it starts with a dash.
3637 File lists are supplied with the @option{--files-from} (@option{-T})
3638 option.  By default, each line read from a file list is first trimmed
3639 off the leading and trailing whitespace and, if the result begins with
3640 a dash, it is treated as a @GNUTAR{} command line option.
3642 Use the @option{--verbatim-files-from} option to disable this special
3643 handling.  This facilitates the use of @command{tar} with file lists
3644 created by @command{file} command.
3646 This option affects all @option{--files-from} options that occur after
3647 it in the command line.  Its effect is reverted by the
3648 @option{--no-verbatim-files-from} option.
3650 This option is implied by the @option{--null} option.
3652 @xref{verbatim-files-from}.
3654 @opsummary{verbose}
3655 @item --verbose
3656 @itemx -v
3658 Specifies that @command{tar} should be more verbose about the
3659 operations it is performing.  This option can be specified multiple
3660 times for some operations to increase the amount of information displayed.
3661 @xref{verbose}.
3663 @opsummary{verify}
3664 @item --verify
3665 @itemx -W
3667 Verifies that the archive was correctly written when creating an
3668 archive.  @xref{verify}.
3670 @opsummary{version}
3671 @item --version
3673 Print information about the program's name, version, origin and legal
3674 status, all on standard output, and then exit successfully.
3675 @xref{help}.
3677 @opsummary{volno-file}
3678 @item --volno-file=@var{file}
3680 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3681 keep track of which volume of a multi-volume archive it is working in
3682 @var{file}.  @xref{volno-file}.
3684 @opsummary{warning}
3685 @item --warning=@var{keyword}
3687 Enable or disable warning messages identified by @var{keyword}.  The
3688 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3689 @xref{warnings}.
3691 @opsummary{wildcards}
3692 @item --wildcards
3693 Use wildcards when matching member names with patterns.
3694 @xref{controlling pattern-matching}.
3696 @opsummary{wildcards-match-slash}
3697 @item --wildcards-match-slash
3698 Wildcards match @samp{/}.
3699 @xref{controlling pattern-matching}.
3701 @opsummary{xattrs}
3702 @item --xattrs
3703 Enable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3705 @opsummary{xattrs-exclude}
3706 @item --xattrs-exclude=@var{pattern}
3707 Specify exclude pattern for xattr keys.
3708 @xref{Extended File Attributes, xattrs-exclude}.
3710 @opsummary{xattrs-include}
3711 @item --xattrs-include=@var{pattern}.
3712 Specify include pattern for xattr keys.  @var{pattern} is a globbing
3713 pattern, e.g. @samp{--xattrs-include='user.*'} to include
3714 only attributes from the user namespace.
3715 @xref{Extended File Attributes, xattrs-include}.
3717 @opsummary{xz}
3718 @item --xz
3719 @itemx -J
3720 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3722 @item --zstd
3723 Use @command{zstd} for compressing or decompressing the archives.  @xref{gzip}.
3725 @end table
3727 @node Short Option Summary
3728 @subsection Short Options Cross Reference
3730 Here is an alphabetized list of all of the short option forms, matching
3731 them with the equivalent long option.
3733 @multitable @columnfractions 0.20 0.80
3734 @headitem Short Option  @tab Reference
3736 @item -A @tab @ref{--concatenate}.
3738 @item -B @tab @ref{--read-full-records}.
3740 @item -C @tab @ref{--directory}.
3742 @item -F @tab @ref{--info-script}.
3744 @item -G @tab @ref{--incremental}.
3746 @item -J @tab @ref{--xz}.
3748 @item -K @tab @ref{--starting-file}.
3750 @item -L @tab @ref{--tape-length}.
3752 @item -M @tab @ref{--multi-volume}.
3754 @item -N @tab @ref{--newer}.
3756 @item -O @tab @ref{--to-stdout}.
3758 @item -P @tab @ref{--absolute-names}.
3760 @item -R @tab @ref{--block-number}.
3762 @item -S @tab @ref{--sparse}.
3764 @item -T @tab @ref{--files-from}.
3766 @item -U @tab @ref{--unlink-first}.
3768 @item -V @tab @ref{--label}.
3770 @item -W @tab @ref{--verify}.
3772 @item -X @tab @ref{--exclude-from}.
3774 @item -Z @tab @ref{--compress}.
3776 @item -b @tab @ref{--blocking-factor}.
3778 @item -c @tab @ref{--create}.
3780 @item -d @tab @ref{--compare}.
3782 @item -f @tab @ref{--file}.
3784 @item -g @tab @ref{--listed-incremental}.
3786 @item -h @tab @ref{--dereference}.
3788 @item -i @tab @ref{--ignore-zeros}.
3790 @item -j @tab @ref{--bzip2}.
3792 @item -k @tab @ref{--keep-old-files}.
3794 @item -l @tab @ref{--check-links}.
3796 @item -m @tab @ref{--touch}.
3798 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3799 @ref{--portability}.
3801 The latter usage is deprecated.  It is retained for compatibility with
3802 the earlier versions of @GNUTAR{}.  In future releases
3803 @option{-o} will be equivalent to @option{--no-same-owner} only.
3805 @item -p @tab @ref{--preserve-permissions}.
3807 @item -r @tab @ref{--append}.
3809 @item -s @tab @ref{--same-order}.
3811 @item -t @tab @ref{--list}.
3813 @item -u @tab @ref{--update}.
3815 @item -v @tab @ref{--verbose}.
3817 @item -w @tab @ref{--interactive}.
3819 @item -x @tab @ref{--extract}.
3821 @item -z @tab @ref{--gzip}.
3823 @end multitable
3825 @node Position-Sensitive Options
3826 @subsection Position-Sensitive Options
3828 Some @GNUTAR{} options can be used multiple times in the same
3829 invocation and affect all arguments that appear after them.  These are
3830 options that control how file names are selected and what kind of
3831 pattern matching is used.
3833 The most obvious example is the @option{-C} option.  It instructs @command{tar}
3834 to change to the directory given as its argument prior to processing
3835 the rest of command line (@pxref{directory}).  Thus, in the following
3836 command:
3838 @example
3839 @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
3840 @end example
3842 @noindent
3843 the file @file{passwd} will be searched in the directory @file{/etc},
3844 and files @file{log} and @file{spool} -- in @file{/var}.
3846 These options can also be used in a file list supplied with the
3847 @option{--files-from} (@option{-T}) option (@pxref{files}).  In that
3848 case they affect all files (patterns) appearing in that file after
3849 them and remain in effect for any arguments processed after that file.
3850 For example, if the file @file{list.txt} contained:
3852 @example
3853 README
3854 -C src
3855 main.c
3856 @end example
3858 @noindent
3859 and @command{tar} were invoked as follows:
3861 @example
3862 @kbd{tar -c -f a.tar -T list.txt Makefile}
3863 @end example
3865 @noindent
3866 then the file @file{README} would be looked up in the current working
3867 directory, and files @file{main.c} and @file{Makefile} would be looked
3868 up in the directory @file{src}.
3870 Many options can be prefixed with @option{--no-} to cancel the effect
3871 of the original option.
3873 For example, the @option{--recursion} option controls whether to
3874 recurse in the subdirectories.  It's counterpart
3875 @option{--no-recursion} disables this.  Consider the command below.  It will
3876 store in the archive the directory @file{/usr} with all files and
3877 directories that are located in it as well as any files and
3878 directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
3879 option is the default and is used here for clarity.  The same example
3880 can be written as:
3882 @example
3883 tar -cf a.tar /usr --no-recursion /var/*
3884 @end example
3887 @example
3888 tar -cf a.tar --recursion /usr --no-recursion /var/*
3889 @end example
3891 During archive creation, @GNUTAR{} keeps track of positional options
3892 used and arguments affected by them.  If it finds out that any such
3893 options are used in an obviously erroneous way, the fact is reported
3894 and exit code is set to 2.  E.g.:
3896 @example
3897 @group
3898 $ @kbd{tar -cf a.tar . --exclude '*.o'}
3899 tar: The following options were used after any non-optional
3900 arguments in archive create or update mode.  These options are
3901 positional and affect only arguments that follow them.  Please,
3902 rearrange them properly.
3903 tar: --exclude '*.o' has no effect
3904 tar: Exiting with failure status due to previous errors
3905 @end group
3906 @end example
3908 The following table summarizes all position-sensitive options.
3910 @table @option
3911 @item --directory=@var{dir}
3912 @itemx -C @var{dir}
3913 @xref{directory}.
3915 @item --null
3916 @itemx --no-null
3917 @xref{nul}.
3919 @item --unquote
3920 @itemx --no-unquote
3921 @xref{input name quoting}.
3923 @item --verbatim-files-from
3924 @itemx --no-verbatim-files-from
3925 @xref{verbatim-files-from}.
3927 @item --recursion
3928 @itemx --no-recursion
3929 @xref{recurse}.
3931 @item --anchored
3932 @itemx --no-anchored
3933 @xref{anchored patterns}.
3935 @item --ignore-case
3936 @itemx --no-ignore-case
3937 @xref{case-insensitive matches}.
3939 @item --wildcards
3940 @itemx --no-wildcards
3941 @xref{controlling pattern-matching}.
3943 @item --wildcards-match-slash
3944 @itemx --no-wildcards-match-slash
3945 @xref{controlling pattern-matching}.
3947 @item --exclude
3948 @xref{exclude}.
3950 @item --exclude-from
3951 @itemx -X
3952 @itemx --exclude-caches
3953 @itemx --exclude-caches-under
3954 @itemx --exclude-caches-all
3955 @itemx --exclude-tag
3956 @itemx --exclude-ignore
3957 @itemx --exclude-ignore-recursive
3958 @itemx --exclude-tag-under
3959 @itemx --exclude-tag-all
3960 @itemx --exclude-vcs
3961 @itemx --exclude-vcs-ignores
3962 @itemx --exclude-backups
3963 @xref{exclude}.
3964 @end table
3966 @node help
3967 @section @GNUTAR{} documentation
3969 @cindex Getting program version number
3970 @opindex version
3971 @cindex Version of the @command{tar} program
3972 Being careful, the first thing is really checking that you are using
3973 @GNUTAR{}, indeed.  The @option{--version} option
3974 causes @command{tar} to print information about its name, version,
3975 origin and legal status, all on standard output, and then exit
3976 successfully.  For example, @w{@samp{tar --version}} might print:
3978 @smallexample
3979 tar (GNU tar) @value{VERSION}
3980 Copyright (C) 2013-2019 Free Software Foundation, Inc.
3981 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3982 This is free software: you are free to change and redistribute it.
3983 There is NO WARRANTY, to the extent permitted by law.
3985 Written by John Gilmore and Jay Fenlason.
3986 @end smallexample
3988 @noindent
3989 The first occurrence of @samp{tar} in the result above is the program
3990 name in the package (for example, @command{rmt} is another program),
3991 while the second occurrence of @samp{tar} is the name of the package
3992 itself, containing possibly many programs.  The package is currently
3993 named @samp{tar}, after the name of the main program it
3994 contains@footnote{There are plans to merge the @command{cpio} and
3995 @command{tar} packages into a single one which would be called
3996 @code{paxutils}.  So, who knows if, one of this days, the
3997 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3998 paxutils) 3.2}}.}.
4000 @cindex Obtaining help
4001 @cindex Listing all @command{tar} options
4002 @xopindex{help, introduction}
4003 Another thing you might want to do is checking the spelling or meaning
4004 of some particular @command{tar} option, without resorting to this
4005 manual, for once you have carefully read it.  @GNUTAR{}
4006 has a short help feature, triggerable through the
4007 @option{--help} option.  By using this option, @command{tar} will
4008 print a usage message listing all available options on standard
4009 output, then exit successfully, without doing anything else and
4010 ignoring all other options.  Even if this is only a brief summary, it
4011 may be several screens long.  So, if you are not using some kind of
4012 scrollable window, you might prefer to use something like:
4014 @smallexample
4015 $ @kbd{tar --help | less}
4016 @end smallexample
4018 @noindent
4019 presuming, here, that you like using @command{less} for a pager.  Other
4020 popular pagers are @command{more} and @command{pg}.  If you know about some
4021 @var{keyword} which interests you and do not want to read all the
4022 @option{--help} output, another common idiom is doing:
4024 @smallexample
4025 tar --help | grep @var{keyword}
4026 @end smallexample
4028 @noindent
4029 for getting only the pertinent lines.  Notice, however, that some
4030 @command{tar} options have long description lines and the above
4031 command will list only the first of them.
4033 The exact look of the option summary displayed by @kbd{tar --help} is
4034 configurable. @xref{Configuring Help Summary}, for a detailed description.
4036 @opindex usage
4037 If you only wish to check the spelling of an option, running @kbd{tar
4038 --usage} may be a better choice.  This will display a terse list of
4039 @command{tar} options without accompanying explanations.
4041 The short help output is quite succinct, and you might have to get
4042 back to the full documentation for precise points.  If you are reading
4043 this paragraph, you already have the @command{tar} manual in some
4044 form.  This manual is available in a variety of forms from
4045 @url{http://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
4046 distribution, provided you have @TeX{} already installed somewhere,
4047 and a laser printer around.  Just configure the distribution, execute
4048 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
4049 usual way (contact your local guru to know how).  If @GNUTAR{}
4050 has been conveniently installed at your place, this
4051 manual is also available in interactive, hypertextual form as an Info
4052 file.  Just call @w{@samp{info tar}} or, if you do not have the
4053 @command{info} program handy, use the Info reader provided within
4054 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
4056 There is currently no @code{man} page for @GNUTAR{}.
4057 If you observe such a @code{man} page on the system you are running,
4058 either it does not belong to @GNUTAR{}, or it has not
4059 been produced by @acronym{GNU}.  Some package maintainers convert
4060 @kbd{tar --help} output to a man page, using @command{help2man}.  In
4061 any case, please bear in mind that the authoritative source of
4062 information about @GNUTAR{} is this Texinfo documentation.
4064 @node defaults
4065 @section Obtaining @GNUTAR{} default values
4067 @opindex show-defaults
4068 @GNUTAR{} has some predefined defaults that are used when you do not
4069 explicitly specify another values.  To obtain a list of such
4070 defaults, use @option{--show-defaults} option.  This will output the
4071 values in the form of @command{tar} command line options:
4073 @smallexample
4074 @group
4075 $ @kbd{tar --show-defaults}
4076 --format=gnu -f- -b20 --quoting-style=escape
4077 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
4078 @end group
4079 @end smallexample
4081 @noindent
4082 Notice, that this option outputs only one line.  The example output above
4083 has been split to fit page boundaries.
4085 @noindent
4086 The above output shows that this version of @GNUTAR{} defaults to
4087 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
4088 output as the archive, if no @option{--file} option has been given
4089 (@pxref{file tutorial}), the default blocking factor is 20
4090 (@pxref{Blocking Factor}).  It also shows the default locations where
4091 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
4093 @node verbose
4094 @section Checking @command{tar} progress
4096 Typically, @command{tar} performs most operations without reporting any
4097 information to the user except error messages.  When using @command{tar}
4098 with many options, particularly ones with complicated or
4099 difficult-to-predict behavior, it is possible to make serious mistakes.
4100 @command{tar} provides several options that make observing @command{tar}
4101 easier.  These options cause @command{tar} to print information as it
4102 progresses in its job, and you might want to use them just for being
4103 more careful about what is going on, or merely for entertaining
4104 yourself.  If you have encountered a problem when operating on an
4105 archive, however, you may need more information than just an error
4106 message in order to solve the problem.  The following options can be
4107 helpful diagnostic tools.
4109 @cindex Verbose operation
4110 @opindex verbose
4111 Normally, the @option{--list} (@option{-t}) command to list an archive
4112 prints just the file names (one per line) and the other commands are
4113 silent. When used with most operations, the @option{--verbose}
4114 (@option{-v}) option causes @command{tar} to print the name of each
4115 file or archive member as it is processed.  This and the other options
4116 which make @command{tar} print status information can be useful in
4117 monitoring @command{tar}.
4119 With @option{--create} or @option{--extract}, @option{--verbose} used
4120 once just prints the names of the files or members as they are processed.
4121 Using it twice causes @command{tar} to print a longer listing
4122 (@xref{verbose member listing}, for the description) for each member.
4123 Since @option{--list} already prints  the names of the members,
4124 @option{--verbose} used once with @option{--list} causes @command{tar}
4125 to print an @samp{ls -l} type listing of the files in the archive.
4126 The following examples both extract members with long list output:
4128 @smallexample
4129 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
4130 $ @kbd{tar xvvf archive.tar}
4131 @end smallexample
4133 Verbose output appears on the standard output except when an archive is
4134 being written to the standard output, as with @samp{tar --create
4135 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
4136 installer let standard output be the default archive).  In that case
4137 @command{tar} writes verbose output to the standard error stream.
4139 If @option{--index-file=@var{file}} is specified, @command{tar} sends
4140 verbose output to @var{file} rather than to standard output or standard
4141 error.
4143 @anchor{totals}
4144 @cindex Obtaining total status information
4145 @opindex totals
4146 The @option{--totals} option causes @command{tar} to print on the
4147 standard error the total amount of bytes transferred when processing
4148 an archive.  When creating or appending to an archive, this option
4149 prints the number of bytes written to the archive and the average
4150 speed at which they have been written, e.g.:
4152 @smallexample
4153 @group
4154 $ @kbd{tar -c -f archive.tar --totals /home}
4155 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
4156 @end group
4157 @end smallexample
4159 When reading an archive, this option displays the number of bytes
4160 read:
4162 @smallexample
4163 @group
4164 $ @kbd{tar -x -f archive.tar --totals}
4165 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
4166 @end group
4167 @end smallexample
4169 Finally, when deleting from an archive, the @option{--totals} option
4170 displays both numbers plus number of bytes removed from the archive:
4172 @smallexample
4173 @group
4174 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
4175 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
4176 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
4177 Total bytes deleted: 1474048
4178 @end group
4179 @end smallexample
4181 You can also obtain this information on request.  When
4182 @option{--totals} is used with an argument, this argument is
4183 interpreted as a symbolic name of a signal, upon delivery of which the
4184 statistics is to be printed:
4186 @table @option
4187 @item --totals=@var{signo}
4188 Print statistics upon delivery of signal @var{signo}.  Valid arguments
4189 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4190 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
4191 accepted.
4192 @end table
4194 Both forms of @option{--totals} option can be used simultaneously.
4195 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
4196 extract all members from its default archive and print statistics
4197 after finishing the extraction, as well as when receiving signal
4198 @code{SIGUSR1}.
4200 @anchor{Progress information}
4201 @cindex Progress information
4202 The @option{--checkpoint} option prints an occasional message
4203 as @command{tar} reads or writes the archive.  It is designed for
4204 those who don't need the more detailed (and voluminous) output of
4205 @option{--block-number} (@option{-R}), but do want visual confirmation
4206 that @command{tar} is actually making forward progress.  By default it
4207 prints a message each 10 records read or written.  This can be changed
4208 by giving it a numeric argument after an equal sign:
4210 @smallexample
4211 $ @kbd{tar -c --checkpoint=1000} /var
4212 tar: Write checkpoint 1000
4213 tar: Write checkpoint 2000
4214 tar: Write checkpoint 3000
4215 @end smallexample
4217 This example shows the default checkpoint message used by
4218 @command{tar}.  If you place a dot immediately after the equal
4219 sign, it will print a @samp{.} at each checkpoint@footnote{This is
4220 actually a shortcut for @option{--checkpoint=@var{n}
4221 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
4223 @smallexample
4224 $ @kbd{tar -c --checkpoint=.1000} /var
4226 @end smallexample
4228 The @option{--checkpoint} option provides a flexible mechanism for
4229 executing arbitrary actions upon hitting checkpoints, see the next
4230 section (@pxref{checkpoints}), for more information on it.
4232 @opindex show-omitted-dirs
4233 @anchor{show-omitted-dirs}
4234 The @option{--show-omitted-dirs} option, when reading an archive---with
4235 @option{--list} or @option{--extract}, for example---causes a message
4236 to be printed for each directory in the archive which is skipped.
4237 This happens regardless of the reason for skipping: the directory might
4238 not have been named on the command line (implicitly or explicitly),
4239 it might be excluded by the use of the
4240 @option{--exclude=@var{pattern}} option, or some other reason.
4242 @opindex block-number
4243 @cindex Block number where error occurred
4244 @anchor{block-number}
4245 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
4246 every message it would normally produce, the block number within the
4247 archive where the message was triggered.  Also, supplementary messages
4248 are triggered when reading blocks full of NULs, or when hitting end of
4249 file on the archive.  As of now, if the archive is properly terminated
4250 with a NUL block, the reading of the file may stop before end of file
4251 is met, so the position of end of file will not usually show when
4252 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
4253 drains the archive before exiting when reading the
4254 archive from a pipe.
4256 @cindex Error message, block number of
4257 This option is especially useful when reading damaged archives, since
4258 it helps pinpoint the damaged sections.  It can also be used with
4259 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
4260 choose among several backup tapes when retrieving a file later, in
4261 favor of the tape where the file appears earliest (closest to the
4262 front of the tape).  @xref{backup}.
4264 @node checkpoints
4265 @section Checkpoints
4266 @cindex checkpoints, defined
4267 @opindex checkpoint
4268 @opindex checkpoint-action
4270 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
4271 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
4272 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
4273 periodically execute arbitrary actions.
4275 The checkpoint facility is enabled using the following option:
4277 @table @option
4278 @xopindex{checkpoint, defined}
4279 @item --checkpoint[=@var{n}]
4280 Schedule checkpoints before writing or reading each @var{n}th record.
4281 The default value for @var{n} is 10.
4282 @end table
4284 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
4285 These actions include: pausing, displaying textual messages, and
4286 executing arbitrary external programs.  Actions are defined using
4287 the @option{--checkpoint-action} option.
4289 @table @option
4290 @xopindex{checkpoint-action, defined}
4291 @item --checkpoint-action=@var{action}
4292 Execute an @var{action} at each checkpoint.
4293 @end table
4295 @cindex @code{echo}, checkpoint action
4296 The simplest value of @var{action} is @samp{echo}.  It instructs
4297 @command{tar} to display the default message on the standard error
4298 stream upon arriving at each checkpoint.  The default message is (in
4299 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
4300 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
4301 Here, @var{n} represents ordinal number of the checkpoint.
4303 In another locales, translated versions of this message are used.
4305 This is the default action, so running:
4307 @smallexample
4308 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
4309 @end smallexample
4311 @noindent
4312 is equivalent to:
4314 @smallexample
4315 $ @kbd{tar -c --checkpoint=1000} /var
4316 @end smallexample
4318 The @samp{echo} action also allows to supply a customized message.
4319 You do so by placing an equals sign and the message right after it,
4320 e.g.:
4322 @smallexample
4323 --checkpoint-action="echo=Hit %s checkpoint #%u"
4324 @end smallexample
4326 The @samp{%s} and @samp{%u} in the above example are
4327 @dfn{format specifiers}.  The @samp{%s} specifier is replaced with
4328 the @dfn{type} of the checkpoint: @samp{write} or
4329 @samp{read} (or a corresponding translated version in locales other
4330 than @acronym{POSIX}).  The @samp{%u} specifier is replaced with
4331 the ordinal number of the checkpoint.  Thus, the above example could
4332 produce the following output when used with the @option{--create}
4333 option:
4335 @smallexample
4336 tar: Hit write checkpoint #10
4337 tar: Hit write checkpoint #20
4338 tar: Hit write checkpoint #30
4339 @end smallexample
4341 The complete list of available format specifiers follows.  Some of
4342 them can take optional arguments.  These arguments, if given, are
4343 supplied in curly braces between the percent sign and the specifier
4344 letter.
4346 @table @samp
4347 @item %s
4348 Print type of the checkpoint (@samp{write} or @samp{read}).
4350 @item %u
4351 Print number of the checkpoint.
4353 @item %@{r,w,d@}T
4354 Print number of bytes transferred so far and approximate transfer
4355 speed.  Optional arguments supply prefixes to be used before number
4356 of bytes read, written and deleted, correspondingly.  If absent,
4357 they default to @samp{R}. @samp{W}, @samp{D}.  Any or all of them can
4358 be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
4359 statistics without any prefixes.  Any surplus arguments, if present,
4360 are silently ignored.
4362 @example
4363 $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
4364 tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
4365 tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
4366 @end example
4368 @noindent
4369 See also the @samp{totals} action, described below.
4371 @item %@{@var{fmt}@}t
4372 Output current local time using @var{fmt} as format for @command{strftime}
4373 (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}).  The
4374 @samp{@{@var{fmt}@}} part is optional.  If not present, the default
4375 format is @samp{%c}, i.e. the preferred date and time representation
4376 for the current locale.
4378 @item %@{@var{n}@}*
4379 Pad output with spaces to the @var{n}th column.  If the
4380 @samp{@{@var{n}@}} part is omitted, the current screen width
4381 is assumed.
4383 @item %c
4384 This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
4385 intended mainly for use with @samp{ttyout} action (see below).
4386 @end table
4388 Aside from format expansion, the message string is subject to
4389 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
4390 replaced with their corresponding @acronym{ASCII} characters
4391 (@pxref{escape sequences}).  E.g. the following action will produce an
4392 audible bell and the message described above at each checkpoint:
4394 @smallexample
4395 --checkpoint-action='echo=\aHit %s checkpoint #%u'
4396 @end smallexample
4398 @cindex @code{bell}, checkpoint action
4399 There is also a special action which produces an audible signal:
4400 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
4401 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
4402 whereas @samp{echo='\a'} sends it to the standard error.
4404 @cindex @code{ttyout}, checkpoint action
4405 The @samp{ttyout=@var{string}} action outputs @var{string} to
4406 @file{/dev/tty}, so it can be used even if the standard output is
4407 redirected elsewhere.  The @var{string} is subject to the same
4408 modifications as with @samp{echo} action.  In contrast to the latter,
4409 @samp{ttyout} does not prepend @command{tar} executable name to the
4410 string, nor does it output a newline after it.  For example, the
4411 following action will print the checkpoint message at the same screen
4412 line, overwriting any previous message:
4414 @smallexample
4415 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
4416 @end smallexample
4418 @noindent
4419 Notice the use of @samp{%*} specifier to clear out any eventual
4420 remains of the prior output line.  As as more complex example,
4421 consider this:
4423 @smallexample
4424 --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
4425 @end smallexample
4427 @noindent
4428 This prints the current local time, number of seconds expired since
4429 tar was started, the checkpoint ordinal number, transferred bytes and
4430 average computed I/O speed.
4432 @cindex @code{dot}, checkpoint action
4433 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
4434 instructs @command{tar} to print a single dot on the standard listing
4435 stream, e.g.:
4437 @smallexample
4438 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4440 @end smallexample
4442 For compatibility with previous @GNUTAR{} versions, this action can
4443 be abbreviated by placing a dot in front of the checkpoint frequency,
4444 as shown in the previous section.
4446 @cindex @code{totals}, checkpoint action
4447 The @samp{totals} action prints the total number of bytes transferred
4448 so far.  The format of the data is the same as for the
4449 @option{--totals} option (@pxref{totals}).  See also @samp{%T} format
4450 specifier of the @samp{echo} or @samp{ttyout} action.
4452 @cindex @code{sleep}, checkpoint action
4453 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4454 amount of seconds.  The following example will stop for 30 seconds at each
4455 checkpoint:
4457 @smallexample
4458 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4459 @end smallexample
4461 @anchor{checkpoint wait}
4462 @cindex @code{wait}, checkpoint action
4463 The @code{wait=@var{signo}} action stops further execution until the
4464 signal @var{signo} is delivered.  Valid values for @var{signo} are:
4465 @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4466 @code{SIGUSR2}.  The @samp{SIG} prefix is optional.  For example:
4468 @example
4469 $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
4470 @end example
4472 In this example, @GNUTAR{} will stop archivation at each 1000th
4473 checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
4474 and resume processing.
4476 This action is used by the @command{genfile} utility to perform
4477 modifications on the input files upon hitting certain checkpoints
4478 (@pxref{Exec Mode, genfile}).
4480 @anchor{checkpoint exec}
4481 @cindex @code{exec}, checkpoint action
4482 Finally, the @code{exec} action executes a given external command.
4483 For example:
4485 @smallexample
4486 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4487 @end smallexample
4489 The supplied command can be any valid command invocation, with or
4490 without additional command line arguments.  If it does contain
4491 arguments, don't forget to quote it to prevent it from being split by
4492 the shell.  @xref{external, Running External Commands}, for more detail.
4494 The command gets a copy of @command{tar}'s environment plus the
4495 following variables:
4497 @table @env
4498 @vrindex TAR_VERSION, checkpoint script environment
4499 @item TAR_VERSION
4500 @GNUTAR{} version number.
4502 @vrindex TAR_ARCHIVE, checkpoint script environment
4503 @item TAR_ARCHIVE
4504 The name of the archive @command{tar} is processing.
4506 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4507 @item TAR_BLOCKING_FACTOR
4508 Current blocking factor (@pxref{Blocking}).
4510 @vrindex TAR_CHECKPOINT, checkpoint script environment
4511 @item TAR_CHECKPOINT
4512 Number of the checkpoint.
4514 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4515 @item TAR_SUBCOMMAND
4516 A short option describing the operation @command{tar} is executing.
4517 @xref{Operations}, for a complete list of subcommand options.
4519 @vrindex TAR_FORMAT, checkpoint script environment
4520 @item TAR_FORMAT
4521 Format of the archive being processed. @xref{Formats}, for a complete
4522 list of archive format names.
4523 @end table
4525 These environment variables can also be passed as arguments to the
4526 command, provided that they are properly escaped, for example:
4528 @smallexample
4529 @kbd{tar -c -f arc.tar \
4530      --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
4531 @end smallexample
4533 @noindent
4534 Notice single quotes to prevent variable names from being expanded by
4535 the shell when invoking @command{tar}.
4537 Any number of actions can be defined, by supplying several
4538 @option{--checkpoint-action} options in the command line.  For
4539 example, the command below displays two messages, pauses
4540 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4542 @example
4543 @group
4544 $ @kbd{tar -c -f arc.tar \
4545        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4546        --checkpoint-action='echo=Sleeping for 30 seconds' \
4547        --checkpoint-action='sleep=30' \
4548        --checkpoint-action='exec=/sbin/cpoint'}
4549 @end group
4550 @end example
4552 This example also illustrates the fact that
4553 @option{--checkpoint-action} can be used without
4554 @option{--checkpoint}.  In this case, the default checkpoint frequency
4555 (at each 10th record) is assumed.
4557 @node warnings
4558 @section Controlling Warning Messages
4560 Sometimes, while performing the requested task, @GNUTAR{} notices
4561 some conditions that are not exactly errors, but which the user
4562 should be aware of.  When this happens, @command{tar} issues a
4563 @dfn{warning message} describing the condition.  Warning messages
4564 are output to the standard error and they do not affect the exit
4565 code of @command{tar} command.
4567 @xopindex{warning, explained}
4568 @GNUTAR{} allows the user to suppress some or all of its warning
4569 messages:
4571 @table @option
4572 @item --warning=@var{keyword}
4573 Control display of the warning messages identified by @var{keyword}.
4574 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4575 suppressed.  Otherwise, they are enabled.
4577 Multiple @option{--warning} messages accumulate.
4579 The tables below list allowed values for @var{keyword} along with the
4580 warning messages they control.
4581 @end table
4583 @subheading Keywords controlling @command{tar} operation
4584 @table @asis
4585 @kwindex all
4586 @item all
4587 Enable all warning messages.  This is the default.
4588 @kwindex none
4589 @item none
4590 Disable all warning messages.
4591 @kwindex filename-with-nuls
4592 @cindex @samp{file name read contains nul character}, warning message
4593 @item filename-with-nuls
4594 @samp{%s: file name read contains nul character}
4595 @kwindex alone-zero-block
4596 @cindex @samp{A lone zero block at}, warning message
4597 @item alone-zero-block
4598 @samp{A lone zero block at %s}
4599 @end table
4601 @subheading Keywords applicable for @command{tar --create}
4602 @table @asis
4603 @kwindex cachedir
4604 @cindex @samp{contains a cache directory tag}, warning message
4605 @item cachedir
4606 @samp{%s: contains a cache directory tag %s; %s}
4607 @kwindex file-shrank
4608 @cindex @samp{File shrank by %s bytes}, warning message
4609 @item file-shrank
4610 @samp{%s: File shrank by %s bytes; padding with zeros}
4611 @kwindex xdev
4612 @cindex @samp{file is on a different filesystem}, warning message
4613 @item xdev
4614 @samp{%s: file is on a different filesystem; not dumped}
4615 @kwindex file-ignored
4616 @cindex @samp{Unknown file type; file ignored}, warning message
4617 @cindex @samp{socket ignored}, warning message
4618 @cindex @samp{door ignored}, warning message
4619 @item file-ignored
4620 @samp{%s: Unknown file type; file ignored}
4621 @*@samp{%s: socket ignored}
4622 @*@samp{%s: door ignored}
4623 @kwindex file-unchanged
4624 @cindex @samp{file is unchanged; not dumped}, warning message
4625 @item file-unchanged
4626 @samp{%s: file is unchanged; not dumped}
4627 @kwindex ignore-archive
4628 @cindex @samp{file is the archive; not dumped}, warning message
4629 @kwindex ignore-archive
4630 @cindex @samp{file is the archive; not dumped}, warning message
4631 @item ignore-archive
4632 @samp{%s: file is the archive; not dumped}
4633 @kwindex file-removed
4634 @cindex @samp{File removed before we read it}, warning message
4635 @item file-removed
4636 @samp{%s: File removed before we read it}
4637 @kwindex file-changed
4638 @cindex @samp{file changed as we read it}, warning message
4639 @item file-changed
4640 @samp{%s: file changed as we read it}
4641 @item failed-read
4642 Suppresses warnings about unreadable files or directories. This
4643 keyword applies only if used together with the @option{--ignore-failed-read}
4644 option. @xref{Ignore Failed Read}.
4645 @end table
4647 @subheading Keywords applicable for @command{tar --extract}
4648 @table @asis
4649 @kwindex existing-file
4650 @cindex @samp{%s: skipping existing file}, warning message
4651 @item existing-file
4652 @samp{%s: skipping existing file}
4653 @kwindex timestamp
4654 @cindex @samp{implausibly old time stamp %s}, warning message
4655 @cindex @samp{time stamp %s is %s s in the future}, warning message
4656 @item timestamp
4657 @samp{%s: implausibly old time stamp %s}
4658 @*@samp{%s: time stamp %s is %s s in the future}
4659 @kwindex contiguous-cast
4660 @cindex @samp{Extracting contiguous files as regular files}, warning message
4661 @item contiguous-cast
4662 @samp{Extracting contiguous files as regular files}
4663 @kwindex symlink-cast
4664 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4665 @item symlink-cast
4666 @samp{Attempting extraction of symbolic links as hard links}
4667 @kwindex unknown-cast
4668 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4669 @item unknown-cast
4670 @samp{%s: Unknown file type '%c', extracted as normal file}
4671 @kwindex ignore-newer
4672 @cindex @samp{Current %s is newer or same age}, warning message
4673 @item ignore-newer
4674 @samp{Current %s is newer or same age}
4675 @kwindex unknown-keyword
4676 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4677 @item unknown-keyword
4678 @samp{Ignoring unknown extended header keyword '%s'}
4679 @kwindex decompress-program
4680 @item decompress-program
4681 Controls verbose description of failures occurring when trying to run
4682 alternative decompressor programs (@pxref{alternative decompression
4683 programs}).  This warning is disabled by default (unless
4684 @option{--verbose} is used).  A common example of what you can get
4685 when using this warning is:
4687 @smallexample
4688 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4689 tar (child): cannot run compress: No such file or directory
4690 tar (child): trying gzip
4691 @end smallexample
4693 This means that @command{tar} first tried to decompress
4694 @file{archive.Z} using @command{compress}, and, when that
4695 failed, switched to @command{gzip}.
4696 @kwindex record-size
4697 @cindex @samp{Record size = %lu blocks}, warning message
4698 @item record-size
4699 @samp{Record size = %lu blocks}
4700 @end table
4702 @subheading Keywords controlling incremental extraction:
4703 @table @asis
4704 @kwindex rename-directory
4705 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4706 @cindex @samp{%s: Directory has been renamed}, warning message
4707 @item rename-directory
4708 @samp{%s: Directory has been renamed from %s}
4709 @*@samp{%s: Directory has been renamed}
4710 @kwindex new-directory
4711 @cindex @samp{%s: Directory is new}, warning message
4712 @item new-directory
4713 @samp{%s: Directory is new}
4714 @kwindex xdev
4715 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4716 @item xdev
4717 @samp{%s: directory is on a different device: not purging}
4718 @kwindex bad-dumpdir
4719 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4720 @item bad-dumpdir
4721 @samp{Malformed dumpdir: 'X' never used}
4722 @end table
4724 @node interactive
4725 @section Asking for Confirmation During Operations
4726 @cindex Interactive operation
4728 Typically, @command{tar} carries out a command without stopping for
4729 further instructions.  In some situations however, you may want to
4730 exclude some files and archive members from the operation (for instance
4731 if disk or storage space is tight).  You can do this by excluding
4732 certain files automatically (@pxref{Choosing}), or by performing
4733 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4734 @command{tar} also accepts @option{--confirmation} for this option.
4736 @opindex interactive
4737 When the @option{--interactive} (@option{-w}) option is specified, before
4738 reading, writing, or deleting files, @command{tar} first prints a message
4739 for each such file, telling what operation it intends to take, then asks
4740 for confirmation on the terminal.  The actions which require
4741 confirmation include adding a file to the archive, extracting a file
4742 from the archive, deleting a file from the archive, and deleting a file
4743 from disk.  To confirm the action, you must type a line of input
4744 beginning with @samp{y}.  If your input line begins with anything other
4745 than @samp{y}, @command{tar} skips that file.
4747 If @command{tar} is reading the archive from the standard input,
4748 @command{tar} opens the file @file{/dev/tty} to support the interactive
4749 communications.
4751 Verbose output is normally sent to standard output, separate from
4752 other error messages.  However, if the archive is produced directly
4753 on standard output, then verbose output is mixed with errors on
4754 @code{stderr}.  Producing the archive on standard output may be used
4755 as a way to avoid using disk space, when the archive is soon to be
4756 consumed by another process reading it, say.  Some people felt the need
4757 of producing an archive on stdout, still willing to segregate between
4758 verbose output and error output.  A possible approach would be using a
4759 named pipe to receive the archive, and having the consumer process to
4760 read from that named pipe.  This has the advantage of letting standard
4761 output free to receive verbose output, all separate from errors.
4763 @node external
4764 @section Running External Commands
4766 Certain @GNUTAR{} operations imply running external commands that you
4767 supply on the command line.  One of such operations is checkpointing,
4768 described above (@pxref{checkpoint exec}).  Another example of this
4769 feature is the @option{-I} option, which allows you to supply the
4770 program to use for compressing or decompressing the archive
4771 (@pxref{use-compress-program}).
4773 Whenever such operation is requested, @command{tar} first splits the
4774 supplied command into words much like the shell does.  It then treats
4775 the first word as the name of the program or the shell script to execute
4776 and the rest of words as its command line arguments.  The program,
4777 unless given as an absolute file name, is searched in the shell's
4778 @env{PATH}.
4780 Any additional information is normally supplied to external commands
4781 in environment variables, specific to each particular operation.  For
4782 example, the @option{--checkpoint-action=exec} option, defines the
4783 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4784 upon.  You can, should the need be, use these variables in the
4785 command line of the external command.  For example:
4787 @smallexample
4788 $ @kbd{tar -x -f archive.tar \
4789     --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4790 @end smallexample
4792 @noindent
4793 This command prints for each checkpoint its number and the name of the
4794 archive, using the same output line on the screen.
4796 Notice the use of single quotes to prevent variable names from being
4797 expanded by the shell when invoking @command{tar}.
4799 @node operations
4800 @chapter @GNUTAR{} Operations
4802 @menu
4803 * Basic tar::
4804 * Advanced tar::
4805 * create options::
4806 * extract options::
4807 * backup::
4808 * looking ahead::
4809 @end menu
4811 @node Basic tar
4812 @section Basic @GNUTAR{} Operations
4814 The basic @command{tar} operations, @option{--create} (@option{-c}),
4815 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4816 @option{-x}), are currently presented and described in the tutorial
4817 chapter of this manual.  This section provides some complementary notes
4818 for these operations.
4820 @table @option
4821 @xopindex{create, complementary notes}
4822 @item --create
4823 @itemx -c
4825 Creating an empty archive would have some kind of elegance.  One can
4826 initialize an empty archive and later use @option{--append}
4827 (@option{-r}) for adding all members.  Some applications would not
4828 welcome making an exception in the way of adding the first archive
4829 member.  On the other hand, many people reported that it is
4830 dangerously too easy for @command{tar} to destroy a magnetic tape with
4831 an empty archive@footnote{This is well described in @cite{Unix-haters
4832 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4833 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4835 @enumerate
4836 @item
4837 Mistakingly using @code{create} instead of @code{extract}, when the
4838 intent was to extract the full contents of an archive.  This error
4839 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4840 the QWERTY keyboard.  Instead of being unpacked, the archive then
4841 gets wholly destroyed.  When users speak about @dfn{exploding} an
4842 archive, they usually mean something else :-).
4844 @item
4845 Forgetting the argument to @code{file}, when the intent was to create
4846 an archive with a single file in it.  This error is likely because a
4847 tired user can easily add the @kbd{f} key to the cluster of option
4848 letters, by the mere force of habit, without realizing the full
4849 consequence of doing so.  The usual consequence is that the single
4850 file, which was meant to be saved, is rather destroyed.
4851 @end enumerate
4853 So, recognizing the likelihood and the catastrophic nature of these
4854 errors, @GNUTAR{} now takes some distance from elegance, and
4855 cowardly refuses to create an archive when @option{--create} option is
4856 given, there are no arguments besides options, and
4857 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4858 around the cautiousness of @GNUTAR{} and nevertheless create an
4859 archive with nothing in it, one may still use, as the value for the
4860 @option{--files-from} option, a file with no names in it, as shown in
4861 the following commands:
4863 @smallexample
4864 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4865 @kbd{tar -cf empty-archive.tar -T /dev/null}
4866 @end smallexample
4868 @xopindex{extract, complementary notes}
4869 @item --extract
4870 @itemx --get
4871 @itemx -x
4873 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4875 @item @option{--list} (@option{-t})
4877 @GNUTAR{} now shows dates as @samp{1996-08-30},
4878 while it used to show them as @samp{Aug 30 1996}. Preferably,
4879 people should get used to ISO 8601 dates.  Local American dates should
4880 be made available again with full date localization support, once
4881 ready.  In the meantime, programs not being localizable for dates
4882 should prefer international dates, that's really the way to go.
4884 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4885 are curious, it contains a detailed explanation of the ISO 8601 standard.
4887 @end table
4889 @node Advanced tar
4890 @section Advanced @GNUTAR{} Operations
4892 Now that you have learned the basics of using @GNUTAR{}, you may want
4893 to learn about further ways in which @command{tar} can help you.
4895 This chapter presents five, more advanced operations which you probably
4896 won't use on a daily basis, but which serve more specialized functions.
4897 We also explain the different styles of options and why you might want
4898 to use one or another, or a combination of them in your @command{tar}
4899 commands.  Additionally, this chapter includes options which allow you to
4900 define the output from @command{tar} more carefully, and provide help and
4901 error correction in special circumstances.
4903 @FIXME{check this after the chapter is actually revised to make sure
4904 it still introduces the info in the chapter correctly : ).}
4906 @menu
4907 * Operations::
4908 * append::
4909 * update::
4910 * concatenate::
4911 * delete::
4912 * compare::
4913 @end menu
4915 @node Operations
4916 @subsection The Five Advanced @command{tar} Operations
4918 @cindex basic operations
4919 In the last chapter, you learned about the first three operations to
4920 @command{tar}.  This chapter presents the remaining five operations to
4921 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4922 @option{--delete}, and @option{--compare}.
4924 You are not likely to use these operations as frequently as those
4925 covered in the last chapter; however, since they perform specialized
4926 functions, they are quite useful when you do need to use them.  We
4927 will give examples using the same directory and files that you created
4928 in the last chapter.  As you may recall, the directory is called
4929 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4930 and the two archive files you created are
4931 @samp{collection.tar} and @samp{music.tar}.
4933 We will also use the archive files @samp{afiles.tar} and
4934 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
4935 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4936 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4938 Unless we state otherwise, all practicing you do and examples you follow
4939 in this chapter will take place in the @file{practice} directory that
4940 you created in the previous chapter; see @ref{prepare for examples}.
4941 (Below in this section, we will remind you of the state of the examples
4942 where the last chapter left them.)
4944 The five operations that we will cover in this chapter are:
4946 @table @option
4947 @item --append
4948 @itemx -r
4949 Add new entries to an archive that already exists.
4950 @item --update
4951 @itemx -u
4952 Add more recent copies of archive members to the end of an archive, if
4953 they exist.
4954 @item --concatenate
4955 @itemx --catenate
4956 @itemx -A
4957 Add one or more pre-existing archives to the end of another archive.
4958 @item --delete
4959 Delete items from an archive (does not work on tapes).
4960 @item --compare
4961 @itemx --diff
4962 @itemx -d
4963 Compare archive members to their counterparts in the file system.
4964 @end table
4966 @node append
4967 @subsection How to Add Files to Existing Archives: @option{--append}
4969 @cindex appending files to existing archive
4970 @opindex append
4971 If you want to add files to an existing archive, you don't need to
4972 create a new archive; you can use @option{--append} (@option{-r}).
4973 The archive must already exist in order to use @option{--append}.  (A
4974 related operation is the @option{--update} operation; you can use this
4975 to add newer versions of archive members to an existing archive.  To learn how to
4976 do this with @option{--update}, @pxref{update}.)
4978 If you use @option{--append} to add a file that has the same name as an
4979 archive member to an archive containing that archive member, then the
4980 old member is not deleted.  What does happen, however, is somewhat
4981 complex.  @command{tar} @emph{allows} you to have infinite number of files
4982 with the same name.  Some operations treat these same-named members no
4983 differently than any other set of archive members: for example, if you
4984 view an archive with @option{--list} (@option{-t}), you will see all
4985 of those members listed, with their data modification times, owners, etc.
4987 Other operations don't deal with these members as perfectly as you might
4988 prefer; if you were to use @option{--extract} to extract the archive,
4989 only the most recently added copy of a member with the same name as
4990 other members would end up in the working directory.  This is because
4991 @option{--extract} extracts an archive in the order the members appeared
4992 in the archive; the most recently archived members will be extracted
4993 last.  Additionally, an extracted member will @emph{replace} a file of
4994 the same name which existed in the directory already, and @command{tar}
4995 will not prompt you about this@footnote{Unless you give it
4996 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4997 the disk copy is newer than the one in the archive and you invoke
4998 @command{tar} with @option{--keep-newer-files} option.}.  Thus, only
4999 the most recently archived member will end up being extracted, as it
5000 will replace the one extracted before it, and so on.
5002 @cindex extracting @var{n}th copy of the file
5003 @xopindex{occurrence, described}
5004 There exists a special option that allows you to get around this
5005 behavior and extract (or list) only a particular copy of the file.
5006 This is @option{--occurrence} option.  If you run @command{tar} with
5007 this option, it will extract only the first copy of the file.  You
5008 may also give this option an argument specifying the number of
5009 copy to be extracted.  Thus, for example if the archive
5010 @file{archive.tar} contained three copies of file @file{myfile}, then
5011 the command
5013 @smallexample
5014 tar --extract --file archive.tar --occurrence=2 myfile
5015 @end smallexample
5017 @noindent
5018 would extract only the second copy.  @xref{Option
5019 Summary,---occurrence}, for the description of @option{--occurrence}
5020 option.
5022 @FIXME{ hag -- you might want to incorporate some of the above into the
5023 MMwtSN node; not sure.  i didn't know how to make it simpler...
5025 There are a few ways to get around this.  Xref to Multiple Members
5026 with the Same Name, maybe.}
5028 @cindex Members, replacing with other members
5029 @cindex Replacing members with other members
5030 @xopindex{delete, using before --append}
5031 If you want to replace an archive member, use @option{--delete} to
5032 delete the member you want to remove from the archive, and then use
5033 @option{--append} to add the member you want to be in the archive.  Note
5034 that you can not change the order of the archive; the most recently
5035 added member will still appear last.  In this sense, you cannot truly
5036 ``replace'' one member with another.  (Replacing one member with another
5037 will not work on certain types of media, such as tapes; see @ref{delete}
5038 and @ref{Media}, for more information.)
5040 @menu
5041 * appending files::             Appending Files to an Archive
5042 * multiple::
5043 @end menu
5045 @node appending files
5046 @subsubsection Appending Files to an Archive
5047 @cindex Adding files to an Archive
5048 @cindex Appending files to an Archive
5049 @cindex Archives, Appending files to
5050 @opindex append
5052 The simplest way to add a file to an already existing archive is the
5053 @option{--append} (@option{-r}) operation, which writes specified
5054 files into the archive whether or not they are already among the
5055 archived files.
5057 When you use @option{--append}, you @emph{must} specify file name
5058 arguments, as there is no default.  If you specify a file that already
5059 exists in the archive, another copy of the file will be added to the
5060 end of the archive.  As with other operations, the member names of the
5061 newly added files will be exactly the same as their names given on the
5062 command line.  The @option{--verbose} (@option{-v}) option will print
5063 out the names of the files as they are written into the archive.
5065 @option{--append} cannot be performed on some tape drives, unfortunately,
5066 due to deficiencies in the formats those tape drives use.  The archive
5067 must be a valid @command{tar} archive, or else the results of using this
5068 operation will be unpredictable.  @xref{Media}.
5070 To demonstrate using @option{--append} to add a file to an archive,
5071 create a file called @file{rock} in the @file{practice} directory.
5072 Make sure you are in the @file{practice} directory.  Then, run the
5073 following @command{tar} command to add @file{rock} to
5074 @file{collection.tar}:
5076 @smallexample
5077 $ @kbd{tar --append --file=collection.tar rock}
5078 @end smallexample
5080 @noindent
5081 If you now use the @option{--list} (@option{-t}) operation, you will see that
5082 @file{rock} has been added to the archive:
5084 @smallexample
5085 $ @kbd{tar --list --file=collection.tar}
5086 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5087 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5088 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5089 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5090 @end smallexample
5092 @node multiple
5093 @subsubsection Multiple Members with the Same Name
5094 @cindex members, multiple
5095 @cindex multiple members
5097 You can use @option{--append} (@option{-r}) to add copies of files
5098 which have been updated since the archive was created.  (However, we
5099 do not recommend doing this since there is another @command{tar}
5100 option called @option{--update}; @xref{update}, for more information.
5101 We describe this use of @option{--append} here for the sake of
5102 completeness.)  When you extract the archive, the older version will
5103 be effectively lost.  This works because files are extracted from an
5104 archive in the order in which they were archived.  Thus, when the
5105 archive is extracted, a file archived later in time will replace a
5106 file of the same name which was archived earlier, even though the
5107 older version of the file will remain in the archive unless you delete
5108 all versions of the file.
5110 Supposing you change the file @file{blues} and then append the changed
5111 version to @file{collection.tar}.  As you saw above, the original
5112 @file{blues} is in the archive @file{collection.tar}.  If you change the
5113 file and append the new version of the file to the archive, there will
5114 be two copies in the archive.  When you extract the archive, the older
5115 version of the file will be extracted first, and then replaced by the
5116 newer version when it is extracted.
5118 You can append the new, changed copy of the file @file{blues} to the
5119 archive in this way:
5121 @smallexample
5122 $ @kbd{tar --append --verbose --file=collection.tar blues}
5123 blues
5124 @end smallexample
5126 @noindent
5127 Because you specified the @option{--verbose} option, @command{tar} has
5128 printed the name of the file being appended as it was acted on.  Now
5129 list the contents of the archive:
5131 @smallexample
5132 $ @kbd{tar --list --verbose --file=collection.tar}
5133 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5134 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5135 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5136 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5137 -rw-r--r-- me/user          58 1996-10-24 18:30 blues
5138 @end smallexample
5140 @noindent
5141 The newest version of @file{blues} is now at the end of the archive
5142 (note the different creation dates and file sizes).  If you extract
5143 the archive, the older version of the file @file{blues} will be
5144 replaced by the newer version.  You can confirm this by extracting
5145 the archive and running @samp{ls} on the directory.
5147 If you wish to extract the first occurrence of the file @file{blues}
5148 from the archive, use @option{--occurrence} option, as shown in
5149 the following example:
5151 @smallexample
5152 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
5153 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5154 @end smallexample
5156 @xref{Writing}, for more information on @option{--extract} and
5157 see @ref{Option Summary, --occurrence}, for a description of
5158 @option{--occurrence} option.
5160 @node update
5161 @subsection Updating an Archive
5162 @cindex Updating an archive
5163 @opindex update
5165 In the previous section, you learned how to use @option{--append} to
5166 add a file to an existing archive.  A related operation is
5167 @option{--update} (@option{-u}).  The @option{--update} operation
5168 updates a @command{tar} archive by comparing the date of the specified
5169 archive members against the date of the file with the same name.  If
5170 the file has been modified more recently than the archive member, then
5171 the newer version of the file is added to the archive (as with
5172 @option{--append}).
5174 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
5175 The operation will fail.
5177 @FIXME{other examples of media on which --update will fail?  need to ask
5178 charles and/or mib/thomas/dave shevett..}
5180 Both @option{--update} and @option{--append} work by adding to the end
5181 of the archive.  When you extract a file from the archive, only the
5182 version stored last will wind up in the file system, unless you use
5183 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
5185 @menu
5186 * how to update::
5187 @end menu
5189 @node how to update
5190 @subsubsection How to Update an Archive Using @option{--update}
5191 @opindex update
5193 You must use file name arguments with the @option{--update}
5194 (@option{-u}) operation.  If you don't specify any files,
5195 @command{tar} won't act on any files and won't tell you that it didn't
5196 do anything (which may end up confusing you).
5198 @c note: the above parenthetical added because in fact, this
5199 @c behavior just confused the author. :-)
5201 To see the @option{--update} option at work, create a new file,
5202 @file{classical}, in your practice directory, and some extra text to the
5203 file @file{blues}, using any text editor.  Then invoke @command{tar} with
5204 the @samp{update} operation and the @option{--verbose} (@option{-v})
5205 option specified, using the names of all the files in the @file{practice}
5206 directory as file name arguments:
5208 @smallexample
5209 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
5210 blues
5211 classical
5213 @end smallexample
5215 @noindent
5216 Because we have specified verbose mode, @command{tar} prints out the names
5217 of the files it is working on, which in this case are the names of the
5218 files that needed to be updated.  If you run @samp{tar --list} and look
5219 at the archive, you will see @file{blues} and @file{classical} at its
5220 end.  There will be a total of two versions of the member @samp{blues};
5221 the one at the end will be newer and larger, since you added text before
5222 updating it.
5224 The reason @command{tar} does not overwrite the older file when updating
5225 it is that writing to the middle of a section of tape is a difficult
5226 process.  Tapes are not designed to go backward.  @xref{Media}, for more
5227 information about tapes.
5229 @option{--update} (@option{-u}) is not suitable for performing backups for two
5230 reasons: it does not change directory content entries, and it
5231 lengthens the archive every time it is used.  The @GNUTAR{}
5232 options intended specifically for backups are more
5233 efficient.  If you need to run backups, please consult @ref{Backups}.
5235 @node concatenate
5236 @subsection Combining Archives with @option{--concatenate}
5238 @cindex Adding archives to an archive
5239 @cindex Concatenating Archives
5240 @opindex concatenate
5241 @opindex catenate
5242 @c @cindex @option{-A} described
5243 Sometimes it may be convenient to add a second archive onto the end of
5244 an archive rather than adding individual files to the archive.  To add
5245 one or more archives to the end of another archive, you should use the
5246 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
5248 To use @option{--concatenate}, give the first archive with
5249 @option{--file} option and name the rest of archives to be
5250 concatenated on the command line.  The members, and their member
5251 names, will be copied verbatim from those archives to the first
5252 one@footnote{This can cause multiple members to have the same name.  For
5253 information on how this affects reading the archive, see @ref{multiple}.}.
5254 The new, concatenated archive will be called by the same name as the
5255 one given with the @option{--file} option.  As usual, if you omit
5256 @option{--file}, @command{tar} will use the value of the environment
5257 variable @env{TAPE}, or, if this has not been set, the default archive name.
5259 @FIXME{There is no way to specify a new name...}
5261 To demonstrate how @option{--concatenate} works, create two small archives
5262 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
5263 files from @file{practice}:
5265 @smallexample
5266 $ @kbd{tar -cvf bluesrock.tar blues rock}
5267 blues
5268 rock
5269 $ @kbd{tar -cvf folkjazz.tar folk jazz}
5270 folk
5271 jazz
5272 @end smallexample
5274 @noindent
5275 If you like, You can run @samp{tar --list} to make sure the archives
5276 contain what they are supposed to:
5278 @smallexample
5279 $ @kbd{tar -tvf bluesrock.tar}
5280 -rw-r--r-- melissa/user    105 1997-01-21 19:42 blues
5281 -rw-r--r-- melissa/user     33 1997-01-20 15:34 rock
5282 $ @kbd{tar -tvf jazzfolk.tar}
5283 -rw-r--r-- melissa/user     20 1996-09-23 16:44 folk
5284 -rw-r--r-- melissa/user     65 1997-01-30 14:15 jazz
5285 @end smallexample
5287 We can concatenate these two archives with @command{tar}:
5289 @smallexample
5290 $ @kbd{cd ..}
5291 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
5292 @end smallexample
5294 If you now list the contents of the @file{bluesrock.tar}, you will see
5295 that now it also contains the archive members of @file{jazzfolk.tar}:
5297 @smallexample
5298 $ @kbd{tar --list --file=bluesrock.tar}
5299 blues
5300 rock
5301 folk
5302 jazz
5303 @end smallexample
5305 When you use @option{--concatenate}, the source and target archives must
5306 already exist and must have been created using compatible format
5307 parameters.  Notice, that @command{tar} does not check whether the
5308 archives it concatenates have compatible formats, it does not
5309 even check if the files are really tar archives.
5311 Like @option{--append} (@option{-r}), this operation cannot be performed on some
5312 tape drives, due to deficiencies in the formats those tape drives use.
5314 @cindex @code{concatenate} vs @command{cat}
5315 @cindex @command{cat} vs @code{concatenate}
5316 It may seem more intuitive to you to want or try to use @command{cat} to
5317 concatenate two archives instead of using the @option{--concatenate}
5318 operation; after all, @command{cat} is the utility for combining files.
5320 However, @command{tar} archives incorporate an end-of-file marker which
5321 must be removed if the concatenated archives are to be read properly as
5322 one archive.  @option{--concatenate} removes the end-of-archive marker
5323 from the target archive before each new archive is appended.  If you use
5324 @command{cat} to combine the archives, the result will not be a valid
5325 @command{tar} format archive.  If you need to retrieve files from an
5326 archive that was added to using the @command{cat} utility, use the
5327 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
5328 information on dealing with archives improperly combined using the
5329 @command{cat} shell utility.
5331 @node delete
5332 @subsection Removing Archive Members Using @option{--delete}
5333 @cindex Deleting files from an archive
5334 @cindex Removing files from an archive
5336 @opindex delete
5337 You can remove members from an archive by using the @option{--delete}
5338 option.  Specify the name of the archive with @option{--file}
5339 (@option{-f}) and then specify the names of the members to be deleted;
5340 if you list no member names, nothing will be deleted.  The
5341 @option{--verbose} option will cause @command{tar} to print the names
5342 of the members as they are deleted. As with @option{--extract}, you
5343 must give the exact member names when using @samp{tar --delete}.
5344 @option{--delete} will remove all versions of the named file from the
5345 archive.  The @option{--delete} operation can run very slowly.
5347 Unlike other operations, @option{--delete} has no short form.
5349 @cindex Tapes, using @option{--delete} and
5350 @cindex Deleting from tape archives
5351 This operation will rewrite the archive.  You can only use
5352 @option{--delete} on an archive if the archive device allows you to
5353 write to any point on the media, such as a disk; because of this, it
5354 does not work on magnetic tapes.  Do not try to delete an archive member
5355 from a magnetic tape; the action will not succeed, and you will be
5356 likely to scramble the archive and damage your tape.  There is no safe
5357 way (except by completely re-writing the archive) to delete files from
5358 most kinds of magnetic tape.  @xref{Media}.
5360 To delete all versions of the file @file{blues} from the archive
5361 @file{collection.tar} in the @file{practice} directory, make sure you
5362 are in that directory, and then,
5364 @smallexample
5365 $ @kbd{tar --list --file=collection.tar}
5366 blues
5367 folk
5368 jazz
5369 rock
5370 $ @kbd{tar --delete --file=collection.tar blues}
5371 $ @kbd{tar --list --file=collection.tar}
5372 folk
5373 jazz
5374 rock
5375 @end smallexample
5377 @FIXME{Check if the above listing is actually produced after running
5378 all the examples on collection.tar.}
5380 The @option{--delete} option has been reported to work properly when
5381 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
5383 @node compare
5384 @subsection Comparing Archive Members with the File System
5385 @cindex Verifying the currency of an archive
5387 @opindex compare
5388 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
5389 specified archive members against files with the same names, and then
5390 reports differences in file size, mode, owner, modification date and
5391 contents.  You should @emph{only} specify archive member names, not file
5392 names.  If you do not name any members, then @command{tar} will compare the
5393 entire archive.  If a file is represented in the archive but does not
5394 exist in the file system, @command{tar} reports a difference.
5396 You have to specify the record size of the archive when modifying an
5397 archive with a non-default record size.
5399 @command{tar} ignores files in the file system that do not have
5400 corresponding members in the archive.
5402 The following example compares the archive members @file{rock},
5403 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
5404 files of the same name in the file system.  (Note that there is no file,
5405 @file{funk}; @command{tar} will report an error message.)
5407 @smallexample
5408 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
5409 rock
5410 blues
5411 tar: funk not found in archive
5412 @end smallexample
5414 The spirit behind the @option{--compare} (@option{--diff},
5415 @option{-d}) option is to check whether the archive represents the
5416 current state of files on disk, more than validating the integrity of
5417 the archive media.  For this latter goal, see @ref{verify}.
5419 @node create options
5420 @section Options Used by @option{--create}
5422 @xopindex{create, additional options}
5423 The previous chapter described the basics of how to use
5424 @option{--create} (@option{-c}) to create an archive from a set of files.
5425 @xref{create}.  This section described advanced options to be used with
5426 @option{--create}.
5428 @menu
5429 * override::                  Overriding File Metadata.
5430 * Extended File Attributes::
5431 * Ignore Failed Read::
5432 @end menu
5434 @node override
5435 @subsection Overriding File Metadata
5437 As described above, a @command{tar} archive keeps, for each member it contains,
5438 its @dfn{metadata}, such as modification time, mode and ownership of
5439 the file.  @GNUTAR{} allows to replace these data with other values
5440 when adding files to the archive.  The options described in this
5441 section affect creation of archives of any type.  For POSIX archives,
5442 see also @ref{PAX keywords}, for additional ways of controlling
5443 metadata, stored in the archive.
5445 @table @option
5446 @opindex mode
5447 @item --mode=@var{permissions}
5449 When adding files to an archive, @command{tar} will use
5450 @var{permissions} for the archive members, rather than the permissions
5451 from the files.  @var{permissions} can be specified either as an octal
5452 number or as symbolic permissions, like with
5453 @command{chmod} (@xref{File permissions, Permissions, File
5454 permissions, fileutils, @acronym{GNU} file utilities}.  This reference
5455 also has useful information for those not being overly familiar with
5456 the UNIX permission system).  Using latter syntax allows for
5457 more flexibility.  For example, the value @samp{a+rw} adds read and write
5458 permissions for everybody, while retaining executable bits on directories
5459 or on any other file already marked as executable:
5461 @smallexample
5462 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5463 @end smallexample
5465 @item --mtime=@var{date}
5466 @opindex mtime
5468 When adding files to an archive, @command{tar} will use @var{date} as
5469 the modification time of members when creating archives, instead of
5470 their actual modification times.  The argument @var{date} can be
5471 either a textual date representation in almost arbitrary format
5472 (@pxref{Date input formats}) or a name of an existing file, starting
5473 with @samp{/} or @samp{.}.  In the latter case, the modification time
5474 of that file will be used.
5476 The following example will set the modification date to 00:00:00,
5477 January 1, 1970:
5479 @smallexample
5480 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
5481 @end smallexample
5483 @noindent
5484 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5485 will try to convert the specified date back to its textual
5486 representation and compare it with the one given with
5487 @option{--mtime} options.  If the two dates differ, @command{tar} will
5488 print a warning saying what date it will use.  This is to help user
5489 ensure he is using the right date.
5491 For example:
5493 @smallexample
5494 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5495 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5496 13:06:29.152478
5497 @dots{}
5498 @end smallexample
5500 @noindent
5501 When used with @option{--clamp-mtime} @GNUTAR{} will only set the
5502 modification date to @var{date} on files whose actual modification
5503 date is later than @var{date}.  This is to make it easy to build
5504 reproducible archives given a common timestamp for generated files
5505 while still retaining the original timestamps of untouched files.
5507 @smallexample
5508 $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime=@@$SOURCE_DATE_EPOCH .}
5509 @end smallexample
5511 @item --owner=@var{user}
5512 @opindex owner
5514 Specifies that @command{tar} should use @var{user} as the owner of members
5515 when creating archives, instead of the user associated with the source
5516 file.
5518 If @var{user} contains a colon, it is taken to be of the form
5519 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5520 name and a nonempty @var{id} specifies the decimal numeric user
5521 @acronym{ID}.  If @var{user} does not contain a colon, it is taken to
5522 be a user number if it is one or more decimal digits; otherwise it is
5523 taken to be a user name.
5525 If a name is given but no number, the number is inferred from the
5526 current host's user database if possible, and the file's user number
5527 is used otherwise.  If a number is given but no name, the name is
5528 inferred from the number if possible, and an empty name is used
5529 otherwise.  If both name and number are given, the user database is
5530 not consulted, and the name and number need not be valid on the
5531 current host.
5533 There is no value indicating a missing number, and @samp{0} usually means
5534 @code{root}.  Some people like to force @samp{0} as the value to offer in
5535 their distributions for the owner of files, because the @code{root} user is
5536 anonymous anyway, so that might as well be the owner of anonymous
5537 archives.  For example:
5539 @smallexample
5540 $ @kbd{tar -c -f archive.tar --owner=0 .}
5541 @end smallexample
5543 @noindent
5546 @smallexample
5547 $ @kbd{tar -c -f archive.tar --owner=root .}
5548 @end smallexample
5550 @item --group=@var{group}
5551 @opindex group
5553 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5554 rather than the group from the source file.  As with @option{--owner},
5555 the argument @var{group} can be an existing group symbolic name, or a
5556 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5557 @end table
5559 The @option{--owner} and @option{--group} options affect all files
5560 added to the archive.  @GNUTAR{} provides also two options that allow
5561 for more detailed control over owner translation:
5563 @table @option
5564 @item --owner-map=@var{file}
5565 Read UID translation map from @var{file}.
5567 When reading, empty lines are ignored.  The @samp{#} sign, unless
5568 quoted, introduces a comment, which extends to the end of the line.
5569 Each nonempty line defines mapping for a single UID.  It must consist
5570 of two fields separated by any amount of whitespace.  The first field
5571 defines original username and UID.  It can be a valid user name or
5572 a valid UID prefixed with a plus sign.  In both cases the
5573 corresponding UID or user name is inferred from the current host's
5574 user database.
5576 The second field defines the UID and username to map the original one
5577 to.  Its format can be the same as described above.  Otherwise, it can
5578 have the form @var{newname}:@var{newuid}, in which case neither
5579 @var{newname} nor @var{newuid} are required to be valid as per the
5580 user database.
5582 For example, consider the following file:
5584 @example
5585 +10     bin
5586 smith   root:0
5587 @end example
5589 @noindent
5590 Given this file, each input file that is owner by UID 10 will be
5591 stored in archive with owner name @samp{bin} and owner UID
5592 corresponding to @samp{bin}.  Each file owned by user @samp{smith}
5593 will be stored with owner name @samp{root} and owner ID 0.  Other
5594 files will remain unchanged.
5596 When used together with @option{--owner-map}, the @option{--owner}
5597 option affects only files whose owner is not listed in the map file.
5599 @item --group-map=@var{file}
5600 Read GID translation map from @var{file}.
5602 The format of @var{file} is the same as for @option{--owner-map}
5603 option:
5605 Each nonempty line defines mapping for a single GID.  It must consist
5606 of two fields separated by any amount of whitespace.  The first field
5607 defines original group name and GID.  It can be a valid group name or
5608 a valid GID prefixed with a plus sign.  In both cases the
5609 corresponding GID or user name is inferred from the current host's
5610 group database.
5612 The second field defines the GID and group name to map the original one
5613 to.  Its format can be the same as described above.  Otherwise, it can
5614 have the form @var{newname}:@var{newgid}, in which case neither
5615 @var{newname} nor @var{newgid} are required to be valid as per the
5616 group database.
5618 When used together with @option{--group-map}, the @option{--group}
5619 option affects only files whose owner group is not rewritten using the
5620 map file.
5621 @end table
5623 @node Extended File Attributes
5624 @subsection Extended File Attributes
5626 Extended file attributes are name-value pairs that can be
5627 associated with each node in a file system.  Despite the fact that
5628 POSIX.1e draft which proposed them has been withdrawn, the extended
5629 file attributes are supported by many file systems.  @GNUTAR{} can
5630 store extended file attributes along with the files.  This feature is
5631 controlled by the following command line arguments:
5633 @table @option
5634 @item --xattrs
5635 Enable extended attributes support.  When used with @option{--create},
5636 this option instructs @GNUTAR to store extended file attribute in the
5637 created archive.  This implies POSIX.1-2001 archive format
5638 (@option{--format=pax}).
5640 When used with @option{--extract}, this option tells @command{tar},
5641 for each file extracted, to read stored attributes from the archive
5642 and to apply them to the file.
5644 @item --no-xattrs
5645 Disable extended attributes support.  This is the default.
5646 @end table
5648 Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
5649 Currently, four namespaces exist: @samp{user}, @samp{trusted},
5650 @samp{security} and @samp{system}.  By default, when @option{--xattr}
5651 is used, all names are stored in the archive (or extracted, if using
5652 @option{--extract}).  This can be controlled using the following
5653 options:
5655 @table @option
5656 @item --xattrs-exclude=@var{pattern}
5657 Specify exclude pattern for extended attributes.
5659 @item --xattrs-include=@var{pattern}
5660 Specify include pattern for extended attributes.
5661 @end table
5663 Here, the @var{pattern} is a globbing pattern.  For example, the
5664 following command:
5666 @example
5667 $ @kbd{tar --xattrs --xattrs-exclude='user.*' -c a.tar .}
5668 @end example
5670 will include in the archive @file{a.tar} all attributes, except those
5671 from the @samp{user} namespace.
5673 Any number of these options can be given, thereby creating lists of
5674 include and exclude patterns.
5676 When both options are used, first @option{--xattrs-include} is applied
5677 to select the set of attribute names to keep, and then
5678 @option{--xattrs-exclude} is applied to the resulting set.  In other
5679 words, only those attributes will be stored, whose names match one
5680 of the regexps in @option{--xattrs-include} and don't match any of
5681 the regexps from @option{--xattrs-exclude}.
5683 When listing the archive, if both @option{--xattrs} and
5684 @option{--verbose} options are given, files that have extended
5685 attributes are marked with an asterisk following their permission
5686 mask.  For example:
5688 @example
5689 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5690 @end example
5692 When two or more @option{--verbose} options are given, a detailed
5693 listing of extended attributes is printed after each file entry.  Each
5694 attribute is listed on a separate line, which begins with two spaces
5695 and the letter @samp{x} indicating extended attribute.  It is followed
5696 by a colon, length of the attribute and its name, e.g.:
5698 @example
5699 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5700   x:  7 user.mime_type
5701   x: 32 trusted.md5sum
5702 @end example
5704 File access control lists (@dfn{ACL}) are another actively used feature
5705 proposed by the POSIX.1e standard.  Each ACL consists of a set of ACL
5706 entries, each of which describes the access permissions on the file for
5707 an individual user or a group of users as a combination of read, write
5708 and search/execute permissions.
5710 Whether or not to use ACLs is controlled by the following two options:
5712 @table @option
5713 @item --acls
5714 Enable POSIX ACLs support.  When used with @option{--create},
5715 this option instructs @GNUTAR{} to store ACLs in the
5716 created archive.  This implies POSIX.1-2001 archive format
5717 (@option{--format=pax}).
5719 When used with @option{--extract}, this option tells @command{tar},
5720 to restore ACLs for each file extracted (provided they are present
5721 in the archive).
5723 @item --no-acls
5724 Disable POSIX ACLs support.  This is the default.
5725 @end table
5727 When listing the archive, if both @option{--acls} and
5728 @option{--verbose} options are given, files that have ACLs are marked
5729 with a plus sing following their permission mask.  For example:
5731 @example
5732 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5733 @end example
5735 When two or more @option{--verbose} options are given, a detailed
5736 listing of ACL is printed after each file entry:
5738 @example
5739 @group
5740 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5741   a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
5742 @end group
5743 @end example
5745 @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
5746 kernel security module that provides a mechanism for supporting access
5747 control security policies, including so-called mandatory access
5748 controls (@dfn{MAC}).  Support for SELinux attributes is controlled by
5749 the following command line options:
5751 @table @option
5752 @item --selinux
5753 Enable the SELinux context support.
5755 @item --no-selinux
5756 Disable SELinux context support.
5757 @end table
5759 @node Ignore Failed Read
5760 @subsection Ignore Failed Read
5762 @table @option
5763 @item --ignore-failed-read
5764 @opindex ignore-failed-read
5765 Do not exit with nonzero on unreadable files or directories.
5766 @end table
5768 This option has effect only during creation.  It instructs tar to
5769 treat as mild conditions any missing or unreadable files (directories).
5770 Such failures don't affect the program exit code, and the
5771 corresponding diagnostic messages are marked as warnings, not errors.
5772 These warnings can be suppressed using the
5773 @option{--warning=failed-read} option (@pxref{warnings}).
5775 @node extract options
5776 @section Options Used by @option{--extract}
5777 @cindex options for use with @option{--extract}
5779 @xopindex{extract, additional options}
5780 The previous chapter showed how to use @option{--extract} to extract
5781 an archive into the file system.  Various options cause @command{tar} to
5782 extract more information than just file contents, such as the owner,
5783 the permissions, the modification date, and so forth.  This section
5784 presents options to be used with @option{--extract} when certain special
5785 considerations arise.  You may review the information presented in
5786 @ref{extract} for more basic information about the
5787 @option{--extract} operation.
5789 @menu
5790 * Reading::                     Options to Help Read Archives
5791 * Writing::                     Changing How @command{tar} Writes Files
5792 * Scarce::                      Coping with Scarce Resources
5793 @end menu
5795 @node Reading
5796 @subsection Options to Help Read Archives
5797 @cindex Options when reading archives
5799 @cindex Reading incomplete records
5800 @cindex Records, incomplete
5801 @opindex read-full-records
5802 Normally, @command{tar} will request data in full record increments from
5803 an archive storage device.  If the device cannot return a full record,
5804 @command{tar} will report an error.  However, some devices do not always
5805 return full records, or do not require the last record of an archive to
5806 be padded out to the next record boundary.  To keep reading until you
5807 obtain a full record, or to accept an incomplete record if it contains
5808 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5809 in conjunction with the @option{--extract} or @option{--list} operations.
5810 @xref{Blocking}.
5812 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5813 @command{tar} reads an archive from standard input, or from a remote
5814 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5815 pipe returns however much happens to be in the pipe, even if it is
5816 less than was requested.  If this option were not enabled, @command{tar}
5817 would fail as soon as it read an incomplete record from the pipe.
5819 If you're not sure of the blocking factor of an archive, you can
5820 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5821 @option{--blocking-factor=@var{512-size}} (@option{-b
5822 @var{512-size}}), using a blocking factor larger than what the archive
5823 uses.  This lets you avoid having to determine the blocking factor
5824 of an archive.  @xref{Blocking Factor}.
5826 @menu
5827 * read full records::
5828 * Ignore Zeros::
5829 @end menu
5831 @node read full records
5832 @unnumberedsubsubsec Reading Full Records
5834 @FIXME{need sentence or so of intro here}
5836 @table @option
5837 @opindex read-full-records
5838 @item --read-full-records
5839 @item -B
5840 Use in conjunction with @option{--extract} (@option{--get},
5841 @option{-x}) to read an archive which contains incomplete records, or
5842 one which has a blocking factor less than the one specified.
5843 @end table
5845 @node Ignore Zeros
5846 @unnumberedsubsubsec Ignoring Blocks of Zeros
5848 @cindex End-of-archive blocks, ignoring
5849 @cindex Ignoring end-of-archive blocks
5850 @opindex ignore-zeros
5851 Normally, @command{tar} stops reading when it encounters a block of zeros
5852 between file entries (which usually indicates the end of the archive).
5853 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5854 completely read an archive which contains a block of zeros before the
5855 end (i.e., a damaged archive, or one that was created by concatenating
5856 several archives together).
5858 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5859 versions of @command{tar} write garbage after the end-of-archive entry,
5860 since that part of the media is never supposed to be read.  @GNUTAR{}
5861 does not write after the end of an archive, but seeks to
5862 maintain compatibility among archiving utilities.
5864 @table @option
5865 @item --ignore-zeros
5866 @itemx -i
5867 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5868 encountered while reading an archive.  Use in conjunction with
5869 @option{--extract} or @option{--list}.
5870 @end table
5872 @node Writing
5873 @subsection Changing How @command{tar} Writes Files
5874 @UNREVISED
5876 @FIXME{Introductory paragraph}
5878 @menu
5879 * Dealing with Old Files::
5880 * Overwrite Old Files::
5881 * Keep Old Files::
5882 * Keep Newer Files::
5883 * Unlink First::
5884 * Recursive Unlink::
5885 * Data Modification Times::
5886 * Setting Access Permissions::
5887 * Directory Modification Times and Permissions::
5888 * Writing to Standard Output::
5889 * Writing to an External Program::
5890 * remove files::
5891 @end menu
5893 @node Dealing with Old Files
5894 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5896 @xopindex{overwrite-dir, introduced}
5897 When extracting files, if @command{tar} discovers that the extracted
5898 file already exists, it normally replaces the file by removing it before
5899 extracting it, to prevent confusion in the presence of hard or symbolic
5900 links.  (If the existing file is a symbolic link, it is removed, not
5901 followed.)  However, if a directory cannot be removed because it is
5902 nonempty, @command{tar} normally overwrites its metadata (ownership,
5903 permission, etc.).  The @option{--overwrite-dir} option enables this
5904 default behavior.  To be more cautious and preserve the metadata of
5905 such a directory, use the @option{--no-overwrite-dir} option.
5907 @cindex Overwriting old files, prevention
5908 @xopindex{keep-old-files, introduced}
5909 To be even more cautious and prevent existing files from being replaced, use
5910 the @option{--keep-old-files} (@option{-k}) option.  It causes
5911 @command{tar} to refuse to replace or update a file that already
5912 exists, i.e., a file with the same name as an archive member prevents
5913 extraction of that archive member.  Instead, it reports an error.  For
5914 example:
5916 @example
5917 $ @kbd{ls}
5918 blues
5919 $ @kbd{tar -x -k -f archive.tar}
5920 tar: blues: Cannot open: File exists
5921 tar: Exiting with failure status due to previous errors
5922 @end example
5924 @xopindex{skip-old-files, introduced}
5925 If you wish to preserve old files untouched, but don't want
5926 @command{tar} to treat them as errors, use the
5927 @option{--skip-old-files} option.  This option causes @command{tar} to
5928 silently skip extracting over existing files.
5930 @xopindex{overwrite, introduced}
5931 To be more aggressive about altering existing files, use the
5932 @option{--overwrite} option.  It causes @command{tar} to overwrite
5933 existing files and to follow existing symbolic links when extracting.
5935 @cindex Protecting old files
5936 Some people argue that @GNUTAR{} should not hesitate
5937 to overwrite files with other files when extracting.  When extracting
5938 a @command{tar} archive, they expect to see a faithful copy of the
5939 state of the file system when the archive was created.  It is debatable
5940 that this would always be a proper behavior.  For example, suppose one
5941 has an archive in which @file{usr/local} is a link to
5942 @file{usr/local2}.  Since then, maybe the site removed the link and
5943 renamed the whole hierarchy from @file{/usr/local2} to
5944 @file{/usr/local}.  Such things happen all the time.  I guess it would
5945 not be welcome at all that @GNUTAR{} removes the
5946 whole hierarchy just to make room for the link to be reinstated
5947 (unless it @emph{also} simultaneously restores the full
5948 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
5949 able to remove a whole hierarchy to reestablish a symbolic link, for
5950 example, but @emph{only if} @option{--recursive-unlink} is specified
5951 to allow this behavior.  In any case, single files are silently
5952 removed.
5954 @xopindex{unlink-first, introduced}
5955 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5956 some cases by causing @command{tar} to remove files unconditionally
5957 before extracting them.
5959 @node Overwrite Old Files
5960 @unnumberedsubsubsec Overwrite Old Files
5962 @table @option
5963 @opindex overwrite
5964 @item --overwrite
5965 Overwrite existing files and directory metadata when extracting files
5966 from an archive.
5968 This causes @command{tar} to write extracted files into the file system without
5969 regard to the files already on the system; i.e., files with the same
5970 names as archive members are overwritten when the archive is extracted.
5971 It also causes @command{tar} to extract the ownership, permissions,
5972 and time stamps onto any preexisting files or directories.
5973 If the name of a corresponding file name is a symbolic link, the file
5974 pointed to by the symbolic link will be overwritten instead of the
5975 symbolic link itself (if this is possible).  Moreover, special devices,
5976 empty directories and even symbolic links are automatically removed if
5977 they are in the way of extraction.
5979 Be careful when using the @option{--overwrite} option, particularly when
5980 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5981 can change the contents, ownership or permissions of any file on your
5982 system.  Also, many systems do not take kindly to overwriting files that
5983 are currently being executed.
5985 @opindex overwrite-dir
5986 @item --overwrite-dir
5987 Overwrite the metadata of directories when extracting files from an
5988 archive, but remove other files before extracting.
5989 @end table
5991 @node Keep Old Files
5992 @unnumberedsubsubsec Keep Old Files
5994 @GNUTAR{} provides two options to control its actions in a situation
5995 when it is about to extract a file which already exists on disk.
5997 @table @option
5998 @opindex keep-old-files
5999 @item --keep-old-files
6000 @itemx -k
6001 Do not replace existing files from archive.  When such a file is
6002 encountered, @command{tar} issues an error message.  Upon end of
6003 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
6005 @item --skip-old-files
6006 Do not replace existing files from archive, but do not treat that
6007 as error.  Such files are silently skipped and do not affect
6008 @command{tar} exit status.
6010 Additional verbosity can be obtained using @option{--warning=existing-file}
6011 together with that option (@pxref{warnings}).
6012 @end table
6014 @node Keep Newer Files
6015 @unnumberedsubsubsec Keep Newer Files
6017 @table @option
6018 @opindex keep-newer-files
6019 @item --keep-newer-files
6020 Do not replace existing files that are newer than their archive
6021 copies.  This option is meaningless with @option{--list} (@option{-t}).
6022 @end table
6024 @node Unlink First
6025 @unnumberedsubsubsec Unlink First
6027 @table @option
6028 @opindex unlink-first
6029 @item --unlink-first
6030 @itemx -U
6031 Remove files before extracting over them.
6032 This can make @command{tar} run a bit faster if you know in advance
6033 that the extracted files all need to be removed.  Normally this option
6034 slows @command{tar} down slightly, so it is disabled by default.
6035 @end table
6037 @node Recursive Unlink
6038 @unnumberedsubsubsec Recursive Unlink
6040 @table @option
6041 @opindex recursive-unlink
6042 @item --recursive-unlink
6043 When this option is specified, try removing files and directory hierarchies
6044 before extracting over them.  @emph{This is a dangerous option!}
6045 @end table
6047 If you specify the @option{--recursive-unlink} option,
6048 @command{tar} removes @emph{anything} that keeps you from extracting a file
6049 as far as current permissions will allow it.  This could include removal
6050 of the contents of a full directory hierarchy.
6052 @node Data Modification Times
6053 @unnumberedsubsubsec Setting Data Modification Times
6055 @cindex Data modification times of extracted files
6056 @cindex Modification times of extracted files
6057 Normally, @command{tar} sets the data modification times of extracted
6058 files to the corresponding times recorded for the files in the archive, but
6059 limits the permissions of extracted files by the current @code{umask}
6060 setting.
6062 To set the data modification times of extracted files to the time when
6063 the files were extracted, use the @option{--touch} (@option{-m}) option in
6064 conjunction with @option{--extract} (@option{--get}, @option{-x}).
6066 @table @option
6067 @opindex touch
6068 @item --touch
6069 @itemx -m
6070 Sets the data modification time of extracted archive members to the time
6071 they were extracted, not the time recorded for them in the archive.
6072 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
6073 @end table
6075 @node Setting Access Permissions
6076 @unnumberedsubsubsec Setting Access Permissions
6078 @cindex Permissions of extracted files
6079 @cindex Modes of extracted files
6080 To set the modes (access permissions) of extracted files to those
6081 recorded for those files in the archive, use @option{--same-permissions}
6082 in conjunction with the @option{--extract} (@option{--get},
6083 @option{-x}) operation.
6085 @table @option
6086 @opindex preserve-permissions
6087 @opindex same-permissions
6088 @item --preserve-permissions
6089 @itemx --same-permissions
6090 @c @itemx --ignore-umask
6091 @itemx -p
6092 Set modes of extracted archive members to those recorded in the
6093 archive, instead of current umask settings.  Use in conjunction with
6094 @option{--extract} (@option{--get}, @option{-x}).
6095 @end table
6097 @node Directory Modification Times and Permissions
6098 @unnumberedsubsubsec Directory Modification Times and Permissions
6100 After successfully extracting a file member, @GNUTAR{} normally
6101 restores its permissions and modification times, as described in the
6102 previous sections.  This cannot be done for directories, because
6103 after extracting a directory @command{tar} will almost certainly
6104 extract files into that directory and this will cause the directory
6105 modification time to be updated.  Moreover, restoring that directory
6106 permissions may not permit file creation within it.  Thus, restoring
6107 directory permissions and modification times must be delayed at least
6108 until all files have been extracted into that directory.  @GNUTAR{}
6109 restores directories using the following approach.
6111 The extracted directories are created with the mode specified in the
6112 archive, as modified by the umask of the user, which gives sufficient
6113 permissions to allow file creation.  The meta-information about the
6114 directory is recorded in the temporary list of directories.  When
6115 preparing to extract next archive member, @GNUTAR{} checks if the
6116 directory prefix of this file contains the remembered directory.  If
6117 it does not, the program assumes that all files have been extracted
6118 into that directory, restores its modification time and permissions
6119 and removes its entry from the internal list.  This approach allows
6120 to correctly restore directory meta-information in the majority of
6121 cases, while keeping memory requirements sufficiently small.  It is
6122 based on the fact, that most @command{tar} archives use the predefined
6123 order of members: first the directory, then all the files and
6124 subdirectories in that directory.
6126 However, this is not always true.  The most important exception are
6127 incremental archives (@pxref{Incremental Dumps}).  The member order in
6128 an incremental archive is reversed: first all directory members are
6129 stored, followed by other (non-directory) members.  So, when extracting
6130 from incremental archives, @GNUTAR{} alters the above procedure.  It
6131 remembers all restored directories, and restores their meta-data
6132 only after the entire archive has been processed.  Notice, that you do
6133 not need to specify any special options for that, as @GNUTAR{}
6134 automatically detects archives in incremental format.
6136 There may be cases, when such processing is required for normal archives
6137 too.  Consider the following example:
6139 @smallexample
6140 @group
6141 $ @kbd{tar --no-recursion -cvf archive \
6142     foo foo/file1 bar bar/file foo/file2}
6143 foo/
6144 foo/file1
6145 bar/
6146 bar/file
6147 foo/file2
6148 @end group
6149 @end smallexample
6151 During the normal operation, after encountering @file{bar}
6152 @GNUTAR{} will assume that all files from the directory @file{foo}
6153 were already extracted and will therefore restore its timestamp and
6154 permission bits.  However, after extracting @file{foo/file2} the
6155 directory timestamp will be offset again.
6157 To correctly restore directory meta-information in such cases, use
6158 the @option{--delay-directory-restore} command line option:
6160 @table @option
6161 @opindex delay-directory-restore
6162 @item --delay-directory-restore
6163 Delays restoring of the modification times and permissions of extracted
6164 directories until the end of extraction.  This way, correct
6165 meta-information is restored even if the archive has unusual member
6166 ordering.
6168 @opindex no-delay-directory-restore
6169 @item --no-delay-directory-restore
6170 Cancel the effect of the previous @option{--delay-directory-restore}.
6171 Use this option if you have used @option{--delay-directory-restore} in
6172 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
6173 temporarily disable it.
6174 @end table
6176 @node Writing to Standard Output
6177 @unnumberedsubsubsec Writing to Standard Output
6179 @cindex Writing extracted files to standard output
6180 @cindex Standard output, writing extracted files to
6181 To write the extracted files to the standard output, instead of
6182 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
6183 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
6184 extracting files to send them through a pipe, and do not need to
6185 preserve them in the file system.  If you extract multiple members,
6186 they appear on standard output concatenated, in the order they are
6187 found in the archive.
6189 @table @option
6190 @opindex to-stdout
6191 @item --to-stdout
6192 @itemx -O
6193 Writes files to the standard output.  Use only in conjunction with
6194 @option{--extract} (@option{--get}, @option{-x}).  When this option is
6195 used, instead of creating the files specified, @command{tar} writes
6196 the contents of the files extracted to its standard output.  This may
6197 be useful if you are only extracting the files in order to send them
6198 through a pipe.  This option is meaningless with @option{--list}
6199 (@option{-t}).
6200 @end table
6202 This can be useful, for example, if you have a tar archive containing
6203 a big file and don't want to store the file on disk before processing
6204 it.  You can use a command like this:
6206 @smallexample
6207 tar -xOzf foo.tgz bigfile | process
6208 @end smallexample
6210 or even like this if you want to process the concatenation of the files:
6212 @smallexample
6213 tar -xOzf foo.tgz bigfile1 bigfile2 | process
6214 @end smallexample
6216 However, @option{--to-command} may be more convenient for use with
6217 multiple files. See the next section.
6219 @node Writing to an External Program
6220 @unnumberedsubsubsec Writing to an External Program
6222 You can instruct @command{tar} to send the contents of each extracted
6223 file to the standard input of an external program:
6225 @table @option
6226 @opindex to-command
6227 @item --to-command=@var{command}
6228 Extract files and pipe their contents to the standard input of
6229 @var{command}.  When this option is used, instead of creating the
6230 files specified, @command{tar} invokes @var{command} and pipes the
6231 contents of the files to its standard output.  The @var{command} may
6232 contain command line arguments (see @ref{external, Running External Commands},
6233 for more detail).
6235 Notice, that @var{command} is executed once for each regular file
6236 extracted.  Non-regular files (directories, etc.)@: are ignored when this
6237 option is used.
6238 @end table
6240 The command can obtain the information about the file it processes
6241 from the following environment variables:
6243 @table @env
6244 @vrindex TAR_FILETYPE, to-command environment
6245 @item TAR_FILETYPE
6246 Type of the file. It is a single letter with the following meaning:
6248 @multitable @columnfractions 0.10 0.90
6249 @item f @tab Regular file
6250 @item d @tab Directory
6251 @item l @tab Symbolic link
6252 @item h @tab Hard link
6253 @item b @tab Block device
6254 @item c @tab Character device
6255 @end multitable
6257 Currently only regular files are supported.
6259 @vrindex TAR_MODE, to-command environment
6260 @item TAR_MODE
6261 File mode, an octal number.
6263 @vrindex TAR_FILENAME, to-command environment
6264 @item TAR_FILENAME
6265 The name of the file.
6267 @vrindex TAR_REALNAME, to-command environment
6268 @item TAR_REALNAME
6269 Name of the file as stored in the archive.
6271 @vrindex TAR_UNAME, to-command environment
6272 @item TAR_UNAME
6273 Name of the file owner.
6275 @vrindex TAR_GNAME, to-command environment
6276 @item TAR_GNAME
6277 Name of the file owner group.
6279 @vrindex TAR_ATIME, to-command environment
6280 @item TAR_ATIME
6281 Time of last access. It is a decimal number, representing seconds
6282 since the Epoch.  If the archive provides times with nanosecond
6283 precision, the nanoseconds are appended to the timestamp after a
6284 decimal point.
6286 @vrindex TAR_MTIME, to-command environment
6287 @item TAR_MTIME
6288 Time of last modification.
6290 @vrindex TAR_CTIME, to-command environment
6291 @item TAR_CTIME
6292 Time of last status change.
6294 @vrindex TAR_SIZE, to-command environment
6295 @item TAR_SIZE
6296 Size of the file.
6298 @vrindex TAR_UID, to-command environment
6299 @item TAR_UID
6300 UID of the file owner.
6302 @vrindex TAR_GID, to-command environment
6303 @item TAR_GID
6304 GID of the file owner.
6305 @end table
6307 Additionally, the following variables contain information about
6308 tar mode and the archive being processed:
6310 @table @env
6311 @vrindex TAR_VERSION, to-command environment
6312 @item TAR_VERSION
6313 @GNUTAR{} version number.
6315 @vrindex TAR_ARCHIVE, to-command environment
6316 @item TAR_ARCHIVE
6317 The name of the archive @command{tar} is processing.
6319 @vrindex TAR_BLOCKING_FACTOR, to-command environment
6320 @item TAR_BLOCKING_FACTOR
6321 Current blocking factor (@pxref{Blocking}).
6323 @vrindex TAR_VOLUME, to-command environment
6324 @item TAR_VOLUME
6325 Ordinal number of the volume @command{tar} is processing.
6327 @vrindex TAR_FORMAT, to-command environment
6328 @item TAR_FORMAT
6329 Format of the archive being processed. @xref{Formats}, for a complete
6330 list of archive format names.
6331 @end table
6333 These variables are defined prior to executing the command, so you can
6334 pass them as arguments, if you prefer.  For example, if the command
6335 @var{proc} takes the member name and size as its arguments, then you
6336 could do:
6338 @smallexample
6339 $ @kbd{tar -x -f archive.tar \
6340        --to-command='proc $TAR_FILENAME $TAR_SIZE'}
6341 @end smallexample
6343 @noindent
6344 Notice single quotes to prevent variable names from being expanded by
6345 the shell when invoking @command{tar}.
6347 If @var{command} exits with a non-0 status, @command{tar} will print
6348 an error message similar to the following:
6350 @smallexample
6351 tar: 2345: Child returned status 1
6352 @end smallexample
6354 Here, @samp{2345} is the PID of the finished process.
6356 If this behavior is not wanted, use @option{--ignore-command-error}:
6358 @table @option
6359 @opindex ignore-command-error
6360 @item --ignore-command-error
6361 Ignore exit codes of subprocesses.  Notice that if the program
6362 exits on signal or otherwise terminates abnormally, the error message
6363 will be printed even if this option is used.
6365 @opindex no-ignore-command-error
6366 @item --no-ignore-command-error
6367 Cancel the effect of any previous @option{--ignore-command-error}
6368 option. This option is useful if you have set
6369 @option{--ignore-command-error} in @env{TAR_OPTIONS}
6370 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
6371 @end table
6373 @node remove files
6374 @unnumberedsubsubsec Removing Files
6376 @FIXME{The section is too terse. Something more to add? An example,
6377 maybe?}
6379 @table @option
6380 @opindex remove-files
6381 @item --remove-files
6382 Remove files after adding them to the archive.
6383 @end table
6385 @node Scarce
6386 @subsection Coping with Scarce Resources
6387 @UNREVISED
6389 @cindex Small memory
6390 @cindex Running out of space
6392 @menu
6393 * Starting File::
6394 * Same Order::
6395 @end menu
6397 @node Starting File
6398 @unnumberedsubsubsec Starting File
6400 @table @option
6401 @opindex starting-file
6402 @item --starting-file=@var{name}
6403 @itemx -K @var{name}
6404 Starts an operation in the middle of an archive.  Use in conjunction
6405 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
6406 @end table
6408 @cindex Middle of the archive, starting in the
6409 If a previous attempt to extract files failed due to lack of disk
6410 space, you can use @option{--starting-file=@var{name}} (@option{-K
6411 @var{name}}) to start extracting only after member @var{name} of the
6412 archive.  This assumes, of course, that there is now free space, or
6413 that you are now extracting into a different file system.  (You could
6414 also choose to suspend @command{tar}, remove unnecessary files from
6415 the file system, and then resume the same @command{tar} operation.
6416 In this case, @option{--starting-file} is not necessary.)  See also
6417 @ref{interactive}, and @ref{exclude}.
6419 @node Same Order
6420 @unnumberedsubsubsec Same Order
6422 @table @option
6423 @cindex Large lists of file names on small machines
6424 @opindex same-order
6425 @opindex preserve-order
6426 @item --same-order
6427 @itemx --preserve-order
6428 @itemx -s
6429 To process large lists of file names on machines with small amounts of
6430 memory.  Use in conjunction with @option{--compare} (@option{--diff},
6431 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
6432 (@option{--get}, @option{-x}).
6433 @end table
6435 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
6436 names to be listed or extracted is sorted in the same order as the
6437 files in the archive.  This allows a large list of names to be used,
6438 even on a small machine that would not otherwise be able to hold all
6439 the names in memory at the same time.  Such a sorted list can easily be
6440 created by running @samp{tar -t} on the archive and editing its output.
6442 This option is probably never needed on modern computer systems.
6444 @node backup
6445 @section Backup options
6447 @cindex backup options
6449 @GNUTAR{} offers options for making backups of files
6450 before writing new versions.  These options control the details of
6451 these backups.  They may apply to the archive itself before it is
6452 created or rewritten, as well as individual extracted members.  Other
6453 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
6454 and @command{mv}, for example) offer similar options.
6456 Backup options may prove unexpectedly useful when extracting archives
6457 containing many members having identical name, or when extracting archives
6458 on systems having file name limitations, making different members appear
6459 as having similar names through the side-effect of name truncation.
6460 @FIXME{This is true only if we have a good scheme for truncated backup names,
6461 which I'm not sure at all: I suspect work is needed in this area.}
6462 When any existing file is backed up before being overwritten by extraction,
6463 then clashing files are automatically be renamed to be unique, and the
6464 true name is kept for only the last file of a series of clashing files.
6465 By using verbose mode, users may track exactly what happens.
6467 At the detail level, some decisions are still experimental, and may
6468 change in the future, we are waiting comments from our users.  So, please
6469 do not learn to depend blindly on the details of the backup features.
6470 For example, currently, directories themselves are never renamed through
6471 using these options, so, extracting a file over a directory still has
6472 good chances to fail.  Also, backup options apply to created archives,
6473 not only to extracted members.  For created archives, backups will not
6474 be attempted when the archive is a block or character device, or when it
6475 refers to a remote file.
6477 For the sake of simplicity and efficiency, backups are made by renaming old
6478 files prior to creation or extraction, and not by copying.  The original
6479 name is restored if the file creation fails.  If a failure occurs after a
6480 partial extraction of a file, both the backup and the partially extracted
6481 file are kept.
6483 @table @samp
6484 @item --backup[=@var{method}]
6485 @opindex backup
6486 @vindex VERSION_CONTROL
6487 @cindex backups
6488 Back up files that are about to be overwritten or removed.
6489 Without this option, the original versions are destroyed.
6491 Use @var{method} to determine the type of backups made.
6492 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
6493 environment variable.  And if @env{VERSION_CONTROL} is not set,
6494 use the @samp{existing} method.
6496 @vindex version-control @r{Emacs variable}
6497 This option corresponds to the Emacs variable @samp{version-control};
6498 the same values for @var{method} are accepted as in Emacs.  This option
6499 also allows more descriptive names.  The valid @var{method}s are:
6501 @table @samp
6502 @item t
6503 @itemx numbered
6504 @cindex numbered @r{backup method}
6505 Always make numbered backups.
6507 @item nil
6508 @itemx existing
6509 @cindex existing @r{backup method}
6510 Make numbered backups of files that already have them, simple backups
6511 of the others.
6513 @item never
6514 @itemx simple
6515 @cindex simple @r{backup method}
6516 Always make simple backups.
6518 @end table
6520 @item --suffix=@var{suffix}
6521 @opindex suffix
6522 @cindex backup suffix
6523 @vindex SIMPLE_BACKUP_SUFFIX
6524 Append @var{suffix} to each backup file made with @option{--backup}.  If this
6525 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
6526 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
6527 set, the default is @samp{~}, just as in Emacs.
6529 @end table
6531 @node looking ahead
6532 @section Looking Ahead: The Rest of this Manual
6534 You have now seen how to use all eight of the operations available to
6535 @command{tar}, and a number of the possible options.  The next chapter
6536 explains how to choose and change file and archive names, how to use
6537 files to store names of other files which you can then call as
6538 arguments to @command{tar} (this can help you save time if you expect to
6539 archive the same list of files a number of times), and so forth.
6540 @FIXME{in case it's not obvious, i'm making this up in some sense
6541 based on my limited memory of what the next chapter *really* does.  i
6542 just wanted to flesh out this final section a little bit so i'd
6543 remember to stick it in here. :-)}
6545 If there are too many files to conveniently list on the command line,
6546 you can list the names in a file, and @command{tar} will read that file.
6547 @xref{files}.
6549 There are various ways of causing @command{tar} to skip over some files,
6550 and not archive them.  @xref{Choosing}.
6552 @node Backups
6553 @chapter Performing Backups and Restoring Files
6554 @cindex backups
6556 @GNUTAR{} is distributed along with the scripts for performing backups
6557 and restores.  Even if there is a good chance those scripts may be
6558 satisfying to you, they are not the only scripts or methods available for doing
6559 backups and restore.  You may well create your own, or use more
6560 sophisticated packages dedicated to that purpose.
6562 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
6563 Automatic Network Disk Archiver), a backup system developed by James
6564 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
6565 This is free software, and it is available from @uref{http://www.amanda.org}.
6567 @FIXME{
6569 Here is a possible plan for a future documentation about the backuping
6570 scripts which are provided within the @GNUTAR{}
6571 distribution.
6573 @itemize @bullet
6574 @item dumps
6575  @itemize @minus
6576  @item what are dumps
6577  @item different levels of dumps
6578   @itemize +
6579   @item full dump = dump everything
6580   @item level 1, level 2 dumps etc
6581         A level @var{n} dump dumps everything changed since the last level
6582         @var{n}-1 dump (?)
6583   @end itemize
6584  @item how to use scripts for dumps  (ie, the concept)
6585   @itemize +
6586   @item scripts to run after editing backup specs (details)
6587   @end itemize
6588  @item Backup Specs, what is it.
6589   @itemize +
6590   @item how to customize
6591   @item actual text of script  [/sp/dump/backup-specs]
6592   @end itemize
6593  @item Problems
6594   @itemize +
6595    @item rsh doesn't work
6596    @item rtape isn't installed
6597    @item (others?)
6598   @end itemize
6599  @item the @option{--incremental} option of tar
6600  @item tapes
6601   @itemize +
6602   @item write protection
6603   @item types of media, different sizes and types, useful for different things
6604   @item files and tape marks
6605      one tape mark between files, two at end.
6606   @item positioning the tape
6607      MT writes two at end of write,
6608      backspaces over one when writing again.
6609   @end itemize
6610  @end itemize
6611 @end itemize
6614 This chapter documents both the provided shell scripts and @command{tar}
6615 options which are more specific to usage as a backup tool.
6617 To @dfn{back up} a file system means to create archives that contain
6618 all the files in that file system.  Those archives can then be used to
6619 restore any or all of those files (for instance if a disk crashes or a
6620 file is accidentally deleted).  File system @dfn{backups} are also
6621 called @dfn{dumps}.
6623 @menu
6624 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
6625 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
6626 * Backup Levels::               Levels of Backups
6627 * Backup Parameters::           Setting Parameters for Backups and Restoration
6628 * Scripted Backups::            Using the Backup Scripts
6629 * Scripted Restoration::        Using the Restore Script
6630 @end menu
6632 @node Full Dumps
6633 @section Using @command{tar} to Perform Full Dumps
6634 @UNREVISED
6636 @cindex full dumps
6637 @cindex dumps, full
6639 @cindex corrupted archives
6640 Full dumps should only be made when no other people or programs
6641 are modifying files in the file system.  If files are modified while
6642 @command{tar} is making the backup, they may not be stored properly in
6643 the archive, in which case you won't be able to restore them if you
6644 have to.  (Files not being modified are written with no trouble, and do
6645 not corrupt the entire archive.)
6647 You will want to use the @option{--label=@var{archive-label}}
6648 (@option{-V @var{archive-label}}) option to give the archive a
6649 volume label, so you can tell what this archive is even if the label
6650 falls off the tape, or anything like that.
6652 Unless the file system you are dumping is guaranteed to fit on
6653 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6654 Make sure you have enough tapes on hand to complete the backup.
6656 If you want to dump each file system separately you will need to use
6657 the @option{--one-file-system} option to prevent
6658 @command{tar} from crossing file system boundaries when storing
6659 (sub)directories.
6661 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6662 option is not needed, since this is a complete copy of everything in
6663 the file system, and a full restore from this backup would only be
6664 done onto a completely
6665 empty disk.
6667 Unless you are in a hurry, and trust the @command{tar} program (and your
6668 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6669 option, to make sure your files really made it onto the dump properly.
6670 This will also detect cases where the file was modified while (or just
6671 after) it was being archived.  Not all media (notably cartridge tapes)
6672 are capable of being verified, unfortunately.
6674 @node Incremental Dumps
6675 @section Using @command{tar} to Perform Incremental Dumps
6677 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6678 stores additional metadata so that exact state of the file system
6679 can be restored when extracting the archive.
6681 @GNUTAR{} currently offers two options for handling incremental
6682 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6683 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6685 @xopindex{listed-incremental, described}
6686 The option @option{--listed-incremental} instructs tar to operate on
6687 an incremental archive with additional metadata stored in a standalone
6688 file, called a @dfn{snapshot file}.  The purpose of this file is to help
6689 determine which files have been changed, added or deleted since the
6690 last backup, so that the next incremental backup will contain only
6691 modified files.  The name of the snapshot file is given as an argument
6692 to the option:
6694 @table @option
6695 @item --listed-incremental=@var{file}
6696 @itemx -g @var{file}
6697   Handle incremental backups with snapshot data in @var{file}.
6698 @end table
6700 To create an incremental backup, you would use
6701 @option{--listed-incremental} together with @option{--create}
6702 (@pxref{create}).  For example:
6704 @smallexample
6705 $ @kbd{tar --create \
6706            --file=archive.1.tar \
6707            --listed-incremental=/var/log/usr.snar \
6708            /usr}
6709 @end smallexample
6711 This will create in @file{archive.1.tar} an incremental backup of
6712 the @file{/usr} file system, storing additional metadata in the file
6713 @file{/var/log/usr.snar}.  If this file does not exist, it will be
6714 created.  The created archive will then be a @dfn{level 0 backup};
6715 please see the next section for more on backup levels.
6717 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6718 determines which files are modified.  In this case only these files will be
6719 stored in the archive.  Suppose, for example, that after running the
6720 above command, you delete file @file{/usr/doc/old} and create
6721 directory @file{/usr/local/db} with the following contents:
6723 @smallexample
6724 $ @kbd{ls /usr/local/db}
6725 /usr/local/db/data
6726 /usr/local/db/index
6727 @end smallexample
6729 Some time later you create another incremental backup.  You will
6730 then see:
6732 @smallexample
6733 $ @kbd{tar --create \
6734            --file=archive.2.tar \
6735            --listed-incremental=/var/log/usr.snar \
6736            /usr}
6737 tar: usr/local/db: Directory is new
6738 usr/local/db/
6739 usr/local/db/data
6740 usr/local/db/index
6741 @end smallexample
6743 @noindent
6744 The created archive @file{archive.2.tar} will contain only these
6745 three members.  This archive is called a @dfn{level 1 backup}.  Notice
6746 that @file{/var/log/usr.snar} will be updated with the new data, so if
6747 you plan to create more @samp{level 1} backups, it is necessary to
6748 create a working copy of the snapshot file before running
6749 @command{tar}.  The above example will then be modified as follows:
6751 @smallexample
6752 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6753 $ @kbd{tar --create \
6754            --file=archive.2.tar \
6755            --listed-incremental=/var/log/usr.snar-1 \
6756            /usr}
6757 @end smallexample
6759 @anchor{--level=0}
6760 @xopindex{level, described}
6761 You can force @samp{level 0} backups either by removing the snapshot
6762 file before running @command{tar}, or by supplying the
6763 @option{--level=0} option, e.g.:
6765 @smallexample
6766 $ @kbd{tar --create \
6767            --file=archive.2.tar \
6768            --listed-incremental=/var/log/usr.snar-0 \
6769            --level=0 \
6770            /usr}
6771 @end smallexample
6773 Incremental dumps depend crucially on time stamps, so the results are
6774 unreliable if you modify a file's time stamps during dumping (e.g.,
6775 with the @option{--atime-preserve=replace} option), or if you set the clock
6776 backwards.
6778 @anchor{device numbers}
6779 @cindex Device numbers, using in incremental backups
6780 Metadata stored in snapshot files include device numbers, which,
6781 obviously are supposed to be non-volatile values.  However, it turns
6782 out that @acronym{NFS} devices have undependable values when an automounter
6783 gets in the picture.  This can lead to a great deal of spurious
6784 redumping in incremental dumps, so it is somewhat useless to compare
6785 two @acronym{NFS} devices numbers over time.  The solution implemented
6786 currently is to consider all @acronym{NFS} devices as being equal
6787 when it comes to comparing directories; this is fairly gross, but
6788 there does not seem to be a better way to go.
6790 Apart from using @acronym{NFS}, there are a number of cases where
6791 relying on device numbers can cause spurious redumping of unmodified
6792 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6793 volumes.  To avoid this, use @option{--no-check-device} option:
6795 @table @option
6796 @xopindex{no-check-device, described}
6797 @item --no-check-device
6798 Do not rely on device numbers when preparing a list of changed files
6799 for an incremental dump.
6801 @xopindex{check-device, described}
6802 @item --check-device
6803 Use device numbers when preparing a list of changed files
6804 for an incremental dump.  This is the default behavior.  The purpose
6805 of this option is to undo the effect of the @option{--no-check-device}
6806 if it was given in @env{TAR_OPTIONS} environment variable
6807 (@pxref{TAR_OPTIONS}).
6808 @end table
6810 There is also another way to cope with changing device numbers.  It is
6811 described in detail in @ref{Fixing Snapshot Files}.
6813 Note that incremental archives use @command{tar} extensions and may
6814 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6816 @xopindex{listed-incremental, using with @option{--extract}}
6817 @xopindex{extract, using with @option{--listed-incremental}}
6818 To extract from the incremental dumps, use
6819 @option{--listed-incremental} together with @option{--extract}
6820 option (@pxref{extracting files}).  In this case, @command{tar} does
6821 not need to access snapshot file, since all the data necessary for
6822 extraction are stored in the archive itself.  So, when extracting, you
6823 can give whatever argument to @option{--listed-incremental}, the usual
6824 practice is to use @option{--listed-incremental=/dev/null}.
6825 Alternatively, you can use @option{--incremental}, which needs no
6826 arguments.  In general, @option{--incremental} (@option{-G}) can be
6827 used as a shortcut for @option{--listed-incremental} when listing or
6828 extracting incremental backups (for more information regarding this
6829 option, @pxref{incremental-op}).
6831 When extracting from the incremental backup @GNUTAR{} attempts to
6832 restore the exact state the file system had when the archive was
6833 created.  In particular, it will @emph{delete} those files in the file
6834 system that did not exist in their directories when the archive was
6835 created.  If you have created several levels of incremental files,
6836 then in order to restore the exact contents the file system  had when
6837 the last level was created, you will need to restore from all backups
6838 in turn.  Continuing our example, to restore the state of @file{/usr}
6839 file system, one would do@footnote{Notice, that since both archives
6840 were created without @option{-P} option (@pxref{absolute}), these
6841 commands should be run from the root file system.}:
6843 @smallexample
6844 $ @kbd{tar --extract \
6845            --listed-incremental=/dev/null \
6846            --file archive.1.tar}
6847 $ @kbd{tar --extract \
6848            --listed-incremental=/dev/null \
6849            --file archive.2.tar}
6850 @end smallexample
6852 To list the contents of an incremental archive, use @option{--list}
6853 (@pxref{list}), as usual.  To obtain more information about the
6854 archive, use @option{--listed-incremental} or @option{--incremental}
6855 combined with two @option{--verbose} options@footnote{Two
6856 @option{--verbose} options were selected to avoid breaking usual
6857 verbose listing output (@option{--list --verbose}) when using in
6858 scripts.
6860 @xopindex{incremental, using with @option{--list}}
6861 @xopindex{listed-incremental, using with @option{--list}}
6862 @xopindex{list, using with @option{--incremental}}
6863 @xopindex{list, using with @option{--listed-incremental}}
6864 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6865 contents of the DUMPDIR header (with terminating nulls) when
6866 @option{--incremental} or @option{--listed-incremental} option was
6867 given, no matter what the verbosity level.  This behavior, and,
6868 especially, the binary output it produced were considered inconvenient
6869 and were changed in version 1.16.}:
6871 @smallexample
6872 @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
6873 @end smallexample
6875 This command will print, for each directory in the archive, the list
6876 of files in that directory at the time the archive was created.  This
6877 information is put out in a format which is both human-readable and
6878 unambiguous for a program: each file name is printed as
6880 @smallexample
6881 @var{x} @var{file}
6882 @end smallexample
6884 @noindent
6885 where @var{x} is a letter describing the status of the file: @samp{Y}
6886 if the file  is present in the archive, @samp{N} if the file is not
6887 included in the archive, or a @samp{D} if the file is a directory (and
6888 is included in the archive).  @xref{Dumpdir}, for the detailed
6889 description of dumpdirs and status codes.  Each such
6890 line is terminated by a newline character.  The last line is followed
6891 by an additional newline to indicate the end of the data.
6893 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6894 gives the same behavior as @option{--listed-incremental} when used
6895 with @option{--list} and @option{--extract} options.  When used with
6896 @option{--create} option, it creates an incremental archive without
6897 creating snapshot file.  Thus, it is impossible to create several
6898 levels of incremental backups with @option{--incremental} option.
6900 @node Backup Levels
6901 @section Levels of Backups
6903 An archive containing all the files in the file system is called a
6904 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
6905 creating a full dump every day.  This strategy, however, would waste a
6906 substantial amount of archive media and user time, as unchanged files
6907 are daily re-archived.
6909 It is more efficient to do a full dump only occasionally.  To back up
6910 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
6911 one} dump archives all the files that have changed since the last full
6912 dump.
6914 A typical dump strategy would be to perform a full dump once a week,
6915 and a level one dump once a day.  This means some versions of files
6916 will in fact be archived more than once, but this dump strategy makes
6917 it possible to restore a file system to within one day of accuracy by
6918 only extracting two archives---the last weekly (full) dump and the
6919 last daily (level one) dump.  The only information lost would be in
6920 files changed or created since the last daily backup.  (Doing dumps
6921 more than once a day is usually not worth the trouble.)
6923 @GNUTAR{} comes with scripts you can use to do full
6924 and level-one (actually, even level-two and so on) dumps.  Using
6925 scripts (shell programs) to perform backups and restoration is a
6926 convenient and reliable alternative to typing out file name lists
6927 and @command{tar} commands by hand.
6929 Before you use these scripts, you need to edit the file
6930 @file{backup-specs}, which specifies parameters used by the backup
6931 scripts and by the restore script.  This file is usually located
6932 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
6933 detailed description.  Once the backup parameters are set, you can
6934 perform backups or restoration by running the appropriate script.
6936 The name of the backup script is @code{backup}.  The name of the
6937 restore script is @code{restore}.  The following sections describe
6938 their use in detail.
6940 @emph{Please Note:} The backup and restoration scripts are
6941 designed to be used together.  While it is possible to restore files by
6942 hand from an archive which was created using a backup script, and to create
6943 an archive by hand which could then be extracted using the restore script,
6944 it is easier to use the scripts.  @xref{Incremental Dumps}, before
6945 making such an attempt.
6947 @node Backup Parameters
6948 @section Setting Parameters for Backups and Restoration
6950 The file @file{backup-specs} specifies backup parameters for the
6951 backup and restoration scripts provided with @command{tar}.  You must
6952 edit @file{backup-specs} to fit your system configuration and schedule
6953 before using these scripts.
6955 Syntactically, @file{backup-specs} is a shell script, containing
6956 mainly variable assignments.  However, any valid shell construct
6957 is allowed in this file.  Particularly, you may wish to define
6958 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6959 For more information about shell script syntax, please refer to
6960 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6961 g_02, the definition of the Shell Command Language}.  See also
6962 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6964 The shell variables controlling behavior of @code{backup} and
6965 @code{restore} are described in the following subsections.
6967 @menu
6968 * General-Purpose Variables::
6969 * Magnetic Tape Control::
6970 * User Hooks::
6971 * backup-specs example::        An Example Text of @file{Backup-specs}
6972 @end menu
6974 @node General-Purpose Variables
6975 @subsection General-Purpose Variables
6977 @defvr {Backup variable} ADMINISTRATOR
6978 The user name of the backup administrator.  @code{Backup} scripts
6979 sends a backup report to this address.
6980 @end defvr
6982 @defvr {Backup variable} BACKUP_HOUR
6983 The hour at which the backups are done.  This can be a number from 0
6984 to 23, or the time specification in form @var{hours}:@var{minutes},
6985 or the string @samp{now}.
6987 This variable is used by @code{backup}.  Its value may be overridden
6988 using @option{--time} option (@pxref{Scripted Backups}).
6989 @end defvr
6991 @defvr {Backup variable} TAPE_FILE
6993 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
6994 is a remote archive (@pxref{remote-dev}), backup script will suppose
6995 that your @command{mt} is able to access remote devices.  If @var{RSH}
6996 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6997 invocations of @command{mt}.
6998 @end defvr
7000 @defvr {Backup variable} BLOCKING
7002 The blocking factor @command{tar} will use when writing the dump archive.
7003 @xref{Blocking Factor}.
7004 @end defvr
7006 @defvr {Backup variable} BACKUP_DIRS
7008 A list of file systems to be dumped (for @code{backup}), or restored
7009 (for @code{restore}).  You can include any directory
7010 name in the list --- subdirectories on that file system will be
7011 included, regardless of how they may look to other networked machines.
7012 Subdirectories on other file systems will be ignored.
7014 The host name specifies which host to run @command{tar} on, and should
7015 normally be the host that actually contains the file system.  However,
7016 the host machine must have @GNUTAR{} installed, and
7017 must be able to access the directory containing the backup scripts and
7018 their support files using the same file name that is used on the
7019 machine where the scripts are run (i.e., what @command{pwd} will print
7020 when in that directory on that machine).  If the host that contains
7021 the file system does not have this capability, you can specify another
7022 host as long as it can access the file system through @acronym{NFS}.
7024 If the list of file systems is very long you may wish to put it
7025 in a separate file.  This file is usually named
7026 @file{/etc/backup/dirs}, but this name may be overridden in
7027 @file{backup-specs} using @code{DIRLIST} variable.
7028 @end defvr
7030 @defvr {Backup variable} DIRLIST
7032 The name of the file that contains a list of file systems to backup
7033 or restore.  By default it is @file{/etc/backup/dirs}.
7034 @end defvr
7036 @defvr {Backup variable} BACKUP_FILES
7038 A list of individual files to be dumped (for @code{backup}), or restored
7039 (for @code{restore}).  These should be accessible from the machine on
7040 which the backup script is run.
7042 If the list of individual files is very long you may wish to store it
7043 in a separate file.  This file is usually named
7044 @file{/etc/backup/files}, but this name may be overridden in
7045 @file{backup-specs} using @code{FILELIST} variable.
7046 @end defvr
7048 @defvr {Backup variable} FILELIST
7050 The name of the file that contains a list of individual files to backup
7051 or restore.  By default it is @file{/etc/backup/files}.
7052 @end defvr
7054 @defvr {Backup variable} MT
7056 Full file name of @command{mt} binary.
7057 @end defvr
7059 @defvr {Backup variable} RSH
7060 @anchor{RSH}
7061 Full file name of @command{rsh} binary or its equivalent.  You may wish to
7062 set it to @code{ssh}, to improve security.  In this case you will have
7063 to use public key authentication.
7064 @end defvr
7066 @defvr {Backup variable} RSH_COMMAND
7068 Full file name of @command{rsh} binary on remote machines.  This will
7069 be passed via @option{--rsh-command} option to the remote invocation
7070 of @GNUTAR{}.
7071 @end defvr
7073 @defvr {Backup variable} VOLNO_FILE
7075 Name of temporary file to hold volume numbers.  This needs to be accessible
7076 by all the machines which have file systems to be dumped.
7077 @end defvr
7079 @defvr {Backup variable} XLIST
7081 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
7082 located on the remote machine and containing the list of files to
7083 be excluded from the backup.  Exclude file lists are searched in
7084 /etc/tar-backup directory.  A common use for exclude file lists
7085 is to exclude files containing security-sensitive information
7086 (e.g., @file{/etc/shadow} from backups).
7088 This variable affects only @code{backup}.
7089 @end defvr
7091 @defvr {Backup variable} SLEEP_TIME
7093 Time to sleep between dumps of any two successive file systems
7095 This variable affects only @code{backup}.
7096 @end defvr
7098 @defvr {Backup variable} DUMP_REMIND_SCRIPT
7100 Script to be run when it's time to insert a new tape in for the next
7101 volume.  Administrators may want to tailor this script for their site.
7102 If this variable isn't set, @GNUTAR{} will display its built-in
7103 prompt, and will expect confirmation from the console.  For the
7104 description of the default prompt, see @ref{change volume prompt}.
7106 @end defvr
7108 @defvr {Backup variable} SLEEP_MESSAGE
7110 Message to display on the terminal while waiting for dump time.  Usually
7111 this will just be some literal text.
7112 @end defvr
7114 @defvr {Backup variable} TAR
7116 Full file name of the @GNUTAR{} executable.  If this is not set, backup
7117 scripts will search @command{tar} in the current shell path.
7118 @end defvr
7120 @node Magnetic Tape Control
7121 @subsection Magnetic Tape Control
7123 Backup scripts access tape device using special @dfn{hook functions}.
7124 These functions take a single argument --- the name of the tape
7125 device.  Their names are kept in the following variables:
7127 @defvr {Backup variable} MT_BEGIN
7128 The name of @dfn{begin} function.  This function is called before
7129 accessing the drive.  By default it retensions the tape:
7131 @smallexample
7132 MT_BEGIN=mt_begin
7134 mt_begin() @{
7135     mt -f "$1" retension
7137 @end smallexample
7138 @end defvr
7140 @defvr {Backup variable} MT_REWIND
7141 The name of @dfn{rewind} function.  The default definition is as
7142 follows:
7144 @smallexample
7145 MT_REWIND=mt_rewind
7147 mt_rewind() @{
7148     mt -f "$1" rewind
7150 @end smallexample
7152 @end defvr
7154 @defvr {Backup variable} MT_OFFLINE
7155 The name of the function switching the tape off line.  By default
7156 it is defined as follows:
7158 @smallexample
7159 MT_OFFLINE=mt_offline
7161 mt_offline() @{
7162     mt -f "$1" offl
7164 @end smallexample
7165 @end defvr
7167 @defvr {Backup variable} MT_STATUS
7168 The name of the function used to obtain the status of the archive device,
7169 including error count.  Default definition:
7171 @smallexample
7172 MT_STATUS=mt_status
7174 mt_status() @{
7175     mt -f "$1" status
7177 @end smallexample
7178 @end defvr
7180 @node User Hooks
7181 @subsection User Hooks
7183 @dfn{User hooks} are shell functions executed before and after
7184 each @command{tar} invocation.  Thus, there are @dfn{backup
7185 hooks}, which are executed before and after dumping each file
7186 system, and @dfn{restore hooks}, executed before and
7187 after restoring a file system.  Each user hook is a shell function
7188 taking four arguments:
7190 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
7191 Its arguments are:
7193 @table @var
7194 @item level
7195 Current backup or restore level.
7197 @item host
7198 Name or IP address of the host machine being dumped or restored.
7200 @item fs
7201 Full file name of the file system being dumped or restored.
7203 @item fsname
7204 File system name with directory separators replaced with colons.  This
7205 is useful, e.g., for creating unique files.
7206 @end table
7207 @end deffn
7209 Following variables keep the names of user hook functions:
7211 @defvr {Backup variable} DUMP_BEGIN
7212 Dump begin function.  It is executed before dumping the file system.
7213 @end defvr
7215 @defvr {Backup variable} DUMP_END
7216 Executed after dumping the file system.
7217 @end defvr
7219 @defvr {Backup variable} RESTORE_BEGIN
7220 Executed before restoring the file system.
7221 @end defvr
7223 @defvr {Backup variable} RESTORE_END
7224 Executed after restoring the file system.
7225 @end defvr
7227 @node backup-specs example
7228 @subsection An Example Text of @file{Backup-specs}
7230 The following is an example of @file{backup-specs}:
7232 @smallexample
7233 # site-specific parameters for file system backup.
7235 ADMINISTRATOR=friedman
7236 BACKUP_HOUR=1
7237 TAPE_FILE=/dev/nrsmt0
7239 # Use @code{ssh} instead of the less secure @code{rsh}
7240 RSH=/usr/bin/ssh
7241 RSH_COMMAND=/usr/bin/ssh
7243 # Override MT_STATUS function:
7244 my_status() @{
7245       mts -t $TAPE_FILE
7247 MT_STATUS=my_status
7249 # Disable MT_OFFLINE function
7250 MT_OFFLINE=:
7252 BLOCKING=124
7253 BACKUP_DIRS="
7254         albert:/fs/fsf
7255         apple-gunkies:/gd
7256         albert:/fs/gd2
7257         albert:/fs/gp
7258         geech:/usr/jla
7259         churchy:/usr/roland
7260         albert:/
7261         albert:/usr
7262         apple-gunkies:/
7263         apple-gunkies:/usr
7264         gnu:/hack
7265         gnu:/u
7266         apple-gunkies:/com/mailer/gnu
7267         apple-gunkies:/com/archive/gnu"
7269 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
7271 @end smallexample
7273 @node Scripted Backups
7274 @section Using the Backup Scripts
7276 The syntax for running a backup script is:
7278 @smallexample
7279 backup --level=@var{level} --time=@var{time}
7280 @end smallexample
7282 The @option{--level} option requests the dump level.  Thus, to produce
7283 a full dump, specify @code{--level=0} (this is the default, so
7284 @option{--level} may be omitted if its value is
7285 @code{0})@footnote{For backward compatibility, the @code{backup} will also
7286 try to deduce the requested dump level from the name of the
7287 script itself.  If the name consists of a string @samp{level-}
7288 followed by a single decimal digit, that digit is taken as
7289 the dump level number.  Thus, you may create a link from @code{backup}
7290 to @code{level-1} and then run @code{level-1} whenever you need to
7291 create a level one dump.}.
7293 The @option{--time} option determines when should the backup be
7294 run.  @var{Time} may take three forms:
7296 @table @asis
7297 @item @var{hh}:@var{mm}
7299 The dump must be run at @var{hh} hours @var{mm} minutes.
7301 @item @var{hh}
7303 The dump must be run at @var{hh} hours.
7305 @item now
7307 The dump must be run immediately.
7308 @end table
7310 You should start a script with a tape or disk mounted.  Once you
7311 start a script, it prompts you for new tapes or disks as it
7312 needs them.  Media volumes don't have to correspond to archive
7313 files --- a multi-volume archive can be started in the middle of a
7314 tape that already contains the end of another multi-volume archive.
7315 The @code{restore} script prompts for media by its archive volume,
7316 so to avoid an error message you should keep track of which tape
7317 (or disk) contains which volume of the archive (@pxref{Scripted
7318 Restoration}).
7320 The backup scripts write two files on the file system.  The first is a
7321 record file in @file{/etc/tar-backup/}, which is used by the scripts
7322 to store and retrieve information about which files were dumped.  This
7323 file is not meant to be read by humans, and should not be deleted by
7324 them.  @xref{Snapshot Files}, for a more detailed explanation of this
7325 file.
7327 The second file is a log file containing the names of the file systems
7328 and files dumped, what time the backup was made, and any error
7329 messages that were generated, as well as how much space was left in
7330 the media volume after the last volume of the archive was written.
7331 You should check this log file after every backup.  The file name is
7332 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
7333 represents current date, and @var{n} represents current dump level number.
7335 The script also prints the name of each system being dumped to the
7336 standard output.
7338 Following is the full list of options accepted by @code{backup}
7339 script:
7341 @table @option
7342 @item -l @var{level}
7343 @itemx --level=@var{level}
7344 Do backup level @var{level} (default 0).
7346 @item -f
7347 @itemx --force
7348 Force backup even if today's log file already exists.
7350 @item -v[@var{level}]
7351 @itemx --verbose[=@var{level}]
7352 Set verbosity level.  The higher the level is, the more debugging
7353 information will be output during execution.  Default @var{level}
7354 is 100, which means the highest debugging level.
7356 @item -t @var{start-time}
7357 @itemx --time=@var{start-time}
7358 Wait till @var{time}, then do backup.
7360 @item -h
7361 @itemx --help
7362 Display short help message and exit.
7364 @item -V
7365 @itemx --version
7366 Display information about the program's name, version, origin and legal
7367 status, all on standard output, and then exit successfully.
7368 @end table
7371 @node Scripted Restoration
7372 @section Using the Restore Script
7374 To restore files that were archived using a scripted backup, use the
7375 @code{restore} script.  Its usage is quite straightforward.  In the
7376 simplest form, invoke @code{restore --all}, it will
7377 then restore all the file systems and files specified in
7378 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
7380 You may select the file systems (and/or files) to restore by
7381 giving @code{restore} a list of @dfn{patterns} in its command
7382 line.  For example, running
7384 @smallexample
7385 restore 'albert:*'
7386 @end smallexample
7388 @noindent
7389 will restore all file systems on the machine @samp{albert}.  A more
7390 complicated example:
7392 @smallexample
7393 restore 'albert:*' '*:/var'
7394 @end smallexample
7396 @noindent
7397 This command will restore all file systems on the machine @samp{albert}
7398 as well as @file{/var} file system on all machines.
7400 By default @code{restore} will start restoring files from the lowest
7401 available dump level (usually zero) and will continue through
7402 all available dump levels.  There may be situations where such a
7403 thorough restore is not necessary.  For example, you may wish to
7404 restore only files from the recent level one backup.  To do so,
7405 use @option{--level} option, as shown in the example below:
7407 @smallexample
7408 restore --level=1
7409 @end smallexample
7411 The full list of options accepted by @code{restore} follows:
7413 @table @option
7414 @item -a
7415 @itemx --all
7416 Restore all file systems and files specified in @file{backup-specs}.
7418 @item -l @var{level}
7419 @itemx --level=@var{level}
7420 Start restoring from the given backup level, instead of the default 0.
7422 @item -v[@var{level}]
7423 @itemx --verbose[=@var{level}]
7424 Set verbosity level.  The higher the level is, the more debugging
7425 information will be output during execution.  Default @var{level}
7426 is 100, which means the highest debugging level.
7428 @item -h
7429 @itemx --help
7430 Display short help message and exit.
7432 @item -V
7433 @itemx --version
7434 Display information about the program's name, version, origin and legal
7435 status, all on standard output, and then exit successfully.
7436 @end table
7438 You should start the restore script with the media containing the
7439 first volume of the archive mounted.  The script will prompt for other
7440 volumes as they are needed.  If the archive is on tape, you don't need
7441 to rewind the tape to to its beginning---if the tape head is
7442 positioned past the beginning of the archive, the script will rewind
7443 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
7444 positioning.
7446 @quotation
7447 @strong{Warning:} The script will delete files from the active file
7448 system if they were not in the file system when the archive was made.
7449 @end quotation
7451 @xref{Incremental Dumps}, for an explanation of how the script makes
7452 that determination.
7454 @node Choosing
7455 @chapter Choosing Files and Names for @command{tar}
7457 Certain options to @command{tar} enable you to specify a name for your
7458 archive.  Other options let you decide which files to include or exclude
7459 from the archive, based on when or whether files were modified, whether
7460 the file names do or don't match specified patterns, or whether files
7461 are in specified directories.
7463 This chapter discusses these options in detail.
7465 @menu
7466 * file::                        Choosing the Archive's Name
7467 * Selecting Archive Members::
7468 * files::                       Reading Names from a File
7469 * exclude::                     Excluding Some Files
7470 * wildcards::                   Wildcards Patterns and Matching
7471 * quoting styles::              Ways of Quoting Special Characters in Names
7472 * transform::                   Modifying File and Member Names
7473 * after::                       Operating Only on New Files
7474 * recurse::                     Descending into Directories
7475 * one::                         Crossing File System Boundaries
7476 @end menu
7478 @node file
7479 @section Choosing and Naming Archive Files
7481 @cindex Naming an archive
7482 @cindex Archive Name
7483 @cindex Choosing an archive file
7484 @cindex Where is the archive?
7485 @opindex file
7486 By default, @command{tar} uses an archive file name that was compiled when
7487 it was built on the system; usually this name refers to some physical
7488 tape drive on the machine.  However, the person who installed @command{tar}
7489 on the system may not have set the default to a meaningful value as far as
7490 most users are concerned.  As a result, you will usually want to tell
7491 @command{tar} where to find (or create) the archive.  The
7492 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
7493 option allows you to either specify or name a file to use as the archive
7494 instead of the default archive file location.
7496 @table @option
7497 @xopindex{file, short description}
7498 @item --file=@var{archive-name}
7499 @itemx -f @var{archive-name}
7500 Name the archive to create or operate on.  Use in conjunction with
7501 any operation.
7502 @end table
7504 For example, in this @command{tar} command,
7506 @smallexample
7507 $ @kbd{tar -cvf collection.tar blues folk jazz}
7508 @end smallexample
7510 @noindent
7511 @file{collection.tar} is the name of the archive.  It must directly
7512 follow the @option{-f} option, since whatever directly follows @option{-f}
7513 @emph{will} end up naming the archive.  If you neglect to specify an
7514 archive name, you may end up overwriting a file in the working directory
7515 with the archive you create since @command{tar} will use this file's name
7516 for the archive name.
7518 An archive can be saved as a file in the file system, sent through a
7519 pipe or over a network, or written to an I/O device such as a tape,
7520 floppy disk, or CD write drive.
7522 @cindex Writing new archives
7523 @cindex Archive creation
7524 If you do not name the archive, @command{tar} uses the value of the
7525 environment variable @env{TAPE} as the file name for the archive.  If
7526 that is not available, @command{tar} uses a default, compiled-in archive
7527 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
7529 @cindex Standard input and output
7530 @cindex tar to standard input and output
7531 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
7532 archive from standard input (when listing or extracting files), or
7533 writes it to standard output (when creating an archive).  If you use
7534 @file{-} as an @var{archive-name} when modifying an archive,
7535 @command{tar} reads the original archive from its standard input and
7536 writes the entire new archive to its standard output.
7538 The following example is a convenient way of copying directory
7539 hierarchy from @file{sourcedir} to @file{targetdir}.
7541 @smallexample
7542 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
7543 @end smallexample
7545 The @option{-C} option allows to avoid using subshells:
7547 @smallexample
7548 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
7549 @end smallexample
7551 In both examples above, the leftmost @command{tar} invocation archives
7552 the contents of @file{sourcedir} to the standard output, while the
7553 rightmost one reads this archive from its standard input and
7554 extracts it.  The @option{-p} option tells it to restore permissions
7555 of the extracted files.
7557 @cindex Remote devices
7558 @cindex tar to a remote device
7559 @anchor{remote-dev}
7560 To specify an archive file on a device attached to a remote machine,
7561 use the following:
7563 @smallexample
7564 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
7565 @end smallexample
7567 @noindent
7568 @command{tar} will set up the remote connection, if possible, and
7569 prompt you for a username and password.  If you use
7570 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
7571 will attempt to set up the remote connection using your username
7572 as the username on the remote machine.
7574 @cindex Local and remote archives
7575 @anchor{local and remote archives}
7576 If the archive file name includes a colon (@samp{:}), then it is assumed
7577 to be a file on another machine.  If the archive file is
7578 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
7579 host @var{host}.  The remote host is accessed using the @command{rsh}
7580 program, with a username of @var{user}.  If the username is omitted
7581 (along with the @samp{@@} sign), then your user name will be used.
7582 (This is the normal @command{rsh} behavior.)  It is necessary for the
7583 remote machine, in addition to permitting your @command{rsh} access, to
7584 have the @file{rmt} program installed (this command is included in
7585 the @GNUTAR{} distribution and by default is installed under
7586 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
7587 installation prefix).  If you need to use a file whose name includes a
7588 colon, then the remote tape drive behavior
7589 can be inhibited by using the @option{--force-local} option.
7591 When the archive is being created to @file{/dev/null}, @GNUTAR{}
7592 tries to minimize input and output operations.  The Amanda backup
7593 system, when used with @GNUTAR{}, has an initial sizing pass which
7594 uses this feature.
7596 @node Selecting Archive Members
7597 @section Selecting Archive Members
7598 @cindex Specifying files to act on
7599 @cindex Specifying archive members
7601 @dfn{File Name arguments} specify which files in the file system
7602 @command{tar} operates on, when creating or adding to an archive, or which
7603 archive members @command{tar} operates on, when reading or deleting from
7604 an archive.  @xref{Operations}.
7606 To specify file names, you can include them as the last arguments on
7607 the command line, as follows:
7608 @smallexample
7609 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
7610 @end smallexample
7612 If a file name begins with dash (@samp{-}), precede it with
7613 @option{--add-file} option to prevent it from being treated as an
7614 option.
7616 @anchor{input name quoting}
7617 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7618 name, replacing @dfn{escape sequences} according to the following
7619 table:
7621 @multitable @columnfractions 0.20 0.60
7622 @headitem Escape @tab Replaced with
7623 @item \a         @tab Audible bell (@acronym{ASCII} 7)
7624 @item \b         @tab Backspace (@acronym{ASCII} 8)
7625 @item \f         @tab Form feed (@acronym{ASCII} 12)
7626 @item \n         @tab New line (@acronym{ASCII} 10)
7627 @item \r         @tab Carriage return (@acronym{ASCII} 13)
7628 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
7629 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
7630 @item \?         @tab @acronym{ASCII} 127
7631 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7632                  of up to 3 digits)
7633 @end multitable
7635 A backslash followed by any other symbol is retained.
7637 This default behavior is controlled by the following command line
7638 option:
7640 @table @option
7641 @opindex unquote
7642 @item --unquote
7643 Enable unquoting input file or member names (default).
7645 @opindex no-unquote
7646 @item --no-unquote
7647 Disable unquoting input file or member names.
7648 @end table
7650 If you specify a directory name as a file name argument, all the files
7651 in that directory are operated on by @command{tar}.
7653 If you do not specify files, @command{tar} behavior differs depending
7654 on the operation mode as described below:
7656 When @command{tar} is invoked with @option{--create} (@option{-c}),
7657 @command{tar} will stop immediately, reporting the following:
7659 @smallexample
7660 @group
7661 $ @kbd{tar cf a.tar}
7662 tar: Cowardly refusing to create an empty archive
7663 Try 'tar --help' or 'tar --usage' for more information.
7664 @end group
7665 @end smallexample
7667 If you specify either @option{--list} (@option{-t}) or
7668 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7669 operates on all the archive members in the archive.
7671 If run with @option{--diff} option, tar will compare the archive with
7672 the contents of the current working directory.
7674 If you specify any other operation, @command{tar} does nothing.
7676 By default, @command{tar} takes file names from the command line.  However,
7677 there are other ways to specify file or member names, or to modify the
7678 manner in which @command{tar} selects the files or members upon which to
7679 operate.  In general, these methods work both for specifying the names
7680 of files and archive members.
7682 @node files
7683 @section Reading Names from a File
7685 @cindex Reading file names from a file
7686 @cindex Lists of file names
7687 @cindex File Name arguments, alternatives
7688 @cindex @command{find}, using with @command{tar}
7689 Instead of giving the names of files or archive members on the command
7690 line, you can put the names into a file, and then use the
7691 @option{--files-from=@var{file-of-names}} (@option{-T
7692 @var{file-of-names}}) option to @command{tar}.  Give the name of the
7693 file which contains the list of files to include as the argument to
7694 @option{--files-from}.  In the list, the file names should be separated by
7695 newlines.  You will frequently use this option when you have generated
7696 the list of files to archive with the @command{find} utility.
7698 @table @option
7699 @opindex files-from
7700 @item --files-from=@var{file-name}
7701 @itemx -T @var{file-name}
7702 Get names to extract or create from file @var{file-name}.
7703 @end table
7705 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7706 you specify either @code{--files-from=-} or @code{-T -}), then the file
7707 names are read from standard input.
7709 Unless you are running @command{tar} with @option{--create}, you cannot use
7710 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7711 command.
7713 Any number of @option{-T} options can be given in the command line.
7715 The following example shows how to use @command{find} to generate a list of
7716 files smaller than 400K in length and put that list into a file
7717 called @file{small-files}.  You can then use the @option{-T} option to
7718 @command{tar} to specify the files from that file, @file{small-files}, to
7719 create the archive @file{little.tgz}.  (The @option{-z} option to
7720 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7721 more information.)
7723 @smallexample
7724 $ @kbd{find . -size -400 -print > small-files}
7725 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7726 @end smallexample
7728 @noindent
7729 By default, each line read from the file list is first stripped off
7730 any leading and trailing whitespace.  If the resulting string begins
7731 with @samp{-} character, it is considered a @command{tar} option and is
7732 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7733 recognized only @option{-C} option in file lists, and only if the
7734 option and its argument occupied two consecutive lines.}. For example,
7735 the common use of this feature is to change to another directory by
7736 specifying @option{-C} option:
7738 @smallexample
7739 @group
7740 $ @kbd{cat list}
7741 -C/etc
7742 passwd
7743 hosts
7744 -C/lib
7745 libc.a
7746 $ @kbd{tar -c -f foo.tar --files-from list}
7747 @end group
7748 @end smallexample
7750 @noindent
7751 In this example, @command{tar} will first switch to @file{/etc}
7752 directory and add files @file{passwd} and @file{hosts} to the
7753 archive.  Then it will change to @file{/lib} directory and will archive
7754 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
7755 contain:
7757 @smallexample
7758 @group
7759 $ @kbd{tar tf foo.tar}
7760 passwd
7761 hosts
7762 libc.a
7763 @end group
7764 @end smallexample
7766 Note, that any options used in the file list remain in effect for the
7767 rest of the command line.  For example, using the same @file{list}
7768 file as above, the following command
7770 @smallexample
7771 $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
7772 @end smallexample
7774 @noindent
7775 will look for file @file{libcurses.a} in the directory @file{/lib},
7776 because it was used with the last @option{-C} option
7777 (@pxref{Position-Sensitive Options}).
7779 @anchor{verbatim-files-from}
7780 @opindex verbatim-files-from
7781 If such option handling is undesirable, use the
7782 @option{--verbatim-files-from} option.  When this option is in effect,
7783 each line read from the file list is treated as a file name.  Notice,
7784 that this means, in particular, that no whitespace trimming is
7785 performed.
7787 @anchor{no-verbatim-files-from}
7788 @opindex no-verbatim-files-from
7789 The @option{--verbatim-files-from} affects all @option{-T} options
7790 that follow it in the command line.  The default behavior can be
7791 restored using @option{--no-verbatim-files-from} option.
7793 @opindex add-file
7794 To disable option handling for a single file name, use the
7795 @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
7797 You can use any @GNUTAR{} command line options in the file list file,
7798 including @option{--files-from} option itself.  This allows for
7799 including contents of a file list into another file list file.
7800 Note however, that options that control file list processing, such as
7801 @option{--verbatim-files-from} or @option{--null} won't affect the
7802 file they appear in.  They will affect next @option{--files-from}
7803 option, if there is any.
7805 @menu
7806 * nul::
7807 @end menu
7809 @node nul
7810 @subsection @code{NUL}-Terminated File Names
7812 @cindex File names, terminated by @code{NUL}
7813 @cindex @code{NUL}-terminated file names
7814 The @option{--null} option causes
7815 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7816 to read file names terminated by a @code{NUL} instead of a newline, so
7817 files whose names contain newlines can be archived using
7818 @option{--files-from}.
7820 @table @option
7821 @xopindex{null, described}
7822 @item --null
7823 Only consider @code{NUL}-terminated file names, instead of files that
7824 terminate in a newline.
7826 @xopindex{no-null, described}
7827 @item --no-null
7828 Undo the effect of any previous @option{--null} option.
7829 @end table
7831 The @option{--null} option is just like the one in @acronym{GNU}
7832 @command{xargs} and @command{cpio}, and is useful with the
7833 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7834 @command{tar}, @option{--null} also disables special handling for
7835 file names that begin with dash (similar to
7836 @option{--verbatim-files-from} option).
7838 This example shows how to use @command{find} to generate a list of files
7839 larger than 800K in length and put that list into a file called
7840 @file{long-files}.  The @option{-print0} option to @command{find} is just
7841 like @option{-print}, except that it separates files with a @code{NUL}
7842 rather than with a newline.  You can then run @command{tar} with both the
7843 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7844 files from that file, @file{long-files}, to create the archive
7845 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
7846 @command{tar} to recognize the @code{NUL} separator between files.
7848 @smallexample
7849 $ @kbd{find . -size +800 -print0 > long-files}
7850 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7851 @end smallexample
7853 The @option{--no-null} option can be used if you need to read both
7854 @code{NUL}-terminated and newline-terminated files on the same command line.
7855 For example, if @file{flist} is a newline-terminated file, then the
7856 following command can be used to combine it with the above command:
7858 @smallexample
7859 @group
7860 $ @kbd{find . -size +800 -print0 |
7861   tar -c -f big.tar --null -T - --no-null -T flist}
7862 @end group
7863 @end smallexample
7865 This example uses short options for typographic reasons, to avoid
7866 very long lines.
7868 @GNUTAR is tries to automatically detect @code{NUL}-terminated file
7869 lists, so in many cases it is safe to use them even without the
7870 @option{--null} option.  In this case @command{tar} will print a
7871 warning and continue reading such a file as if @option{--null} were
7872 actually given:
7874 @smallexample
7875 @group
7876 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7877 tar: -: file name read contains nul character
7878 @end group
7879 @end smallexample
7881 The null terminator, however, remains in effect only for this
7882 particular file, any following @option{-T} options will assume
7883 newline termination.  Of course, the null autodetection applies
7884 to these eventual surplus @option{-T} options as well.
7886 @node exclude
7887 @section Excluding Some Files
7889 @cindex File names, excluding files by
7890 @cindex Excluding files by name and pattern
7891 @cindex Excluding files by file system
7892 @opindex exclude
7893 @opindex exclude-from
7894 To avoid operating on files whose names match a particular pattern,
7895 use the @option{--exclude} or @option{--exclude-from} options.
7897 @table @option
7898 @opindex exclude
7899 @item --exclude=@var{pattern}
7900 Causes @command{tar} to ignore files that match the @var{pattern}.
7901 @end table
7903 @findex exclude
7904 The @option{--exclude=@var{pattern}} option prevents any file or
7905 member whose name matches the shell wildcard (@var{pattern}) from
7906 being operated on.
7907 For example, to create an archive with all the contents of the directory
7908 @file{src} except for files whose names end in @file{.o}, use the
7909 command @samp{tar -cf src.tar --exclude='*.o' src}.
7911 You may give multiple @option{--exclude} options.
7913 @table @option
7914 @opindex exclude-from
7915 @item --exclude-from=@var{file}
7916 @itemx -X @var{file}
7917 Causes @command{tar} to ignore files that match the patterns listed in
7918 @var{file}.
7919 @end table
7921 @findex exclude-from
7922 Use the @option{--exclude-from} option to read a
7923 list of patterns, one per line, from @var{file}; @command{tar} will
7924 ignore files matching those patterns.  Thus if @command{tar} is
7925 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7926 single line @file{*.o}, no files whose names end in @file{.o} will be
7927 added to the archive.
7929 Notice, that lines from @var{file} are read verbatim. One of the
7930 frequent errors is leaving some extra whitespace after a file name,
7931 which is difficult to catch using text editors.
7933 However, empty lines are OK.
7935 @cindex VCS, excluding patterns from ignore files
7936 @cindex VCS, ignore files
7937 @cindex CVS, ignore files
7938 @cindex Git, ignore files
7939 @cindex Bazaar, ignore files
7940 @cindex Mercurial, ignore files
7941 When archiving directories that are under some version control system (VCS),
7942 it is often convenient to read exclusion patterns from this VCS'
7943 ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.)  The
7944 following options provide such possibility:
7946 @table @option
7947 @anchor{exclude-vcs-ignores}
7948 @opindex exclude-vcs-ignores
7949 @item --exclude-vcs-ignores
7950 Before archiving a directory, see if it contains any of the following
7951 files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
7952 @file{.hgignore}.  If so, read ignore patterns from these files.
7954 The patterns are treated much as the corresponding VCS would treat
7955 them, i.e.:
7957 @table @file
7958 @findex .cvsignore
7959 @item .cvsignore
7960 Contains shell-style globbing patterns that apply only to the
7961 directory where this file resides.  No comments are allowed in the
7962 file.  Empty lines are ignored.
7964 @findex .gitignore
7965 @item .gitignore
7966 Contains shell-style globbing patterns.  Applies to the directory
7967 where @file{.gitfile} is located and all its subdirectories.
7969 Any line beginning with a @samp{#} is a comment.  Backslash escapes
7970 the comment character.
7972 @findex .bzrignore
7973 @item .bzrignore
7974 Contains shell globbing-patterns and regular expressions (if prefixed
7975 with @samp{RE:}@footnote{According to the Bazaar docs,
7976 globbing-patterns are Korn-shell style and regular expressions are
7977 perl-style.  As of @GNUTAR{} version @value{VERSION}, these are
7978 treated as shell-style globs and posix extended regexps.  This will be
7979 fixed in future releases.}.  Patterns affect the directory and all its
7980 subdirectories.
7982 Any line beginning with a @samp{#} is a comment.
7984 @findex .hgignore
7985 @item .hgignore
7986 Contains posix regular expressions@footnote{Support for perl-style
7987 regexps will appear in future releases.}.  The line @samp{syntax:
7988 glob} switches to shell globbing patterns.  The line @samp{syntax:
7989 regexp} switches back.  Comments begin with a @samp{#}.  Patterns
7990 affect the directory and all its subdirectories.
7991 @end table
7993 @opindex exclude-ignore
7994 @item --exclude-ignore=@var{file}
7995 Before dumping a directory, @command{tar} checks if it contains
7996 @var{file}.  If so, exclusion patterns are read from this file.
7997 The patterns affect only the directory itself.
7999 @opindex exclude-ignore-recursive
8000 @item --exclude-ignore-recursive=@var{file}
8001 Same as @option{--exclude-ignore}, except that the patterns read
8002 affect both the directory where @var{file} resides and all its
8003 subdirectories.
8004 @end table
8006 @table @option
8007 @cindex version control system, excluding files
8008 @cindex VCS, excluding files
8009 @cindex SCCS, excluding files
8010 @cindex RCS, excluding files
8011 @cindex CVS, excluding files
8012 @cindex SVN, excluding files
8013 @cindex git, excluding files
8014 @cindex Bazaar, excluding files
8015 @cindex Arch, excluding files
8016 @cindex Mercurial, excluding files
8017 @cindex Darcs, excluding files
8018 @anchor{exclude-vcs}
8019 @opindex exclude-vcs
8020 @item --exclude-vcs
8021 Exclude files and directories used by following version control
8022 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
8023 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
8025 As of version @value{VERSION}, the following files are excluded:
8027 @itemize @bullet
8028 @item @file{CVS/}, and everything under it
8029 @item @file{RCS/}, and everything under it
8030 @item @file{SCCS/}, and everything under it
8031 @item @file{.git/}, and everything under it
8032 @item @file{.gitignore}
8033 @item @file{.gitmodules}
8034 @item @file{.gitattributes}
8035 @item @file{.cvsignore}
8036 @item @file{.svn/}, and everything under it
8037 @item @file{.arch-ids/}, and everything under it
8038 @item @file{@{arch@}/}, and everything under it
8039 @item @file{=RELEASE-ID}
8040 @item @file{=meta-update}
8041 @item @file{=update}
8042 @item @file{.bzr}
8043 @item @file{.bzrignore}
8044 @item @file{.bzrtags}
8045 @item @file{.hg}
8046 @item @file{.hgignore}
8047 @item @file{.hgrags}
8048 @item @file{_darcs}
8049 @end itemize
8051 @opindex exclude-backups
8052 @item --exclude-backups
8053 Exclude backup and lock files.  This option causes exclusion of files
8054 that match the following shell globbing patterns:
8056 @table @asis
8057 @item .#*
8058 @item *~
8059 @item #*#
8060 @end table
8062 @end table
8064 @findex exclude-caches
8065 When creating an archive, the @option{--exclude-caches} option family
8066 causes @command{tar} to exclude all directories that contain a @dfn{cache
8067 directory tag}. A cache directory tag is a short file with the
8068 well-known name @file{CACHEDIR.TAG} and having a standard header
8069 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
8070 Various applications write cache directory tags into directories they
8071 use to hold regenerable, non-precious data, so that such data can be
8072 more easily excluded from backups.
8074 There are three @samp{exclude-caches} options, each providing a different
8075 exclusion semantics:
8077 @table @option
8078 @opindex exclude-caches
8079 @item --exclude-caches
8080 Do not archive the contents of the directory, but archive the
8081 directory itself and the @file{CACHEDIR.TAG} file.
8083 @opindex exclude-caches-under
8084 @item --exclude-caches-under
8085 Do not archive the contents of the directory, nor the
8086 @file{CACHEDIR.TAG} file, archive only the directory itself.
8088 @opindex exclude-caches-all
8089 @item --exclude-caches-all
8090 Omit directories containing @file{CACHEDIR.TAG} file entirely.
8091 @end table
8093 @findex exclude-tag
8094 Another option family, @option{--exclude-tag}, provides a generalization of
8095 this concept.  It takes a single argument, a file name to look for.
8096 Any directory that contains this file will be excluded from the dump.
8097 Similarly to @samp{exclude-caches}, there are three options in this
8098 option family:
8100 @table @option
8101 @opindex exclude-tag
8102 @item --exclude-tag=@var{file}
8103 Do not dump the contents of the directory, but dump the
8104 directory itself and the @var{file}.
8106 @opindex exclude-tag-under
8107 @item --exclude-tag-under=@var{file}
8108 Do not dump the contents of the directory, nor the
8109 @var{file}, archive only the directory itself.
8111 @opindex exclude-tag-all
8112 @item --exclude-tag-all=@var{file}
8113 Omit directories containing @var{file} file entirely.
8114 @end table
8116 Multiple @option{--exclude-tag*} options can be given.
8118 For example, given this directory:
8120 @smallexample
8121 @group
8122 $ @kbd{find dir}
8124 dir/blues
8125 dir/jazz
8126 dir/folk
8127 dir/folk/tagfile
8128 dir/folk/sanjuan
8129 dir/folk/trote
8130 @end group
8131 @end smallexample
8133 The @option{--exclude-tag} will produce the following:
8135 @smallexample
8136 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
8137 dir/
8138 dir/blues
8139 dir/jazz
8140 dir/folk/
8141 tar: dir/folk/: contains a cache directory tag tagfile;
8142   contents not dumped
8143 dir/folk/tagfile
8144 @end smallexample
8146 Both the @file{dir/folk} directory and its tagfile are preserved in
8147 the archive, however the rest of files in this directory are not.
8149 Now, using the @option{--exclude-tag-under} option will exclude
8150 @file{tagfile} from the dump, while still preserving the directory
8151 itself, as shown in this example:
8153 @smallexample
8154 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
8155 dir/
8156 dir/blues
8157 dir/jazz
8158 dir/folk/
8159 ./tar: dir/folk/: contains a cache directory tag tagfile;
8160   contents not dumped
8161 @end smallexample
8163 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
8164 directory entirely:
8166 @smallexample
8167 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
8168 dir/
8169 dir/blues
8170 dir/jazz
8171 ./tar: dir/folk/: contains a cache directory tag tagfile;
8172   directory not dumped
8173 @end smallexample
8175 @menu
8176 * problems with exclude::
8177 @end menu
8179 @node problems with exclude
8180 @unnumberedsubsec Problems with Using the @code{exclude} Options
8182 @xopindex{exclude, potential problems with}
8183 Some users find @samp{exclude} options confusing.  Here are some common
8184 pitfalls:
8186 @itemize @bullet
8187 @item
8188 The main operating mode of @command{tar} does not act on a file name
8189 explicitly listed on the command line, if one of its file name
8190 components is excluded.  In the example above, if
8191 you create an archive and exclude files that end with @samp{*.o}, but
8192 explicitly name the file @samp{dir.o/foo} after all the options have been
8193 listed, @samp{dir.o/foo} will be excluded from the archive.
8195 @item
8196 You can sometimes confuse the meanings of @option{--exclude} and
8197 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
8198 to be excluded are given as a pattern on the command line.  Use
8199 @option{--exclude-from} to introduce the name of a file which contains
8200 a list of patterns, one per line; each of these patterns can exclude
8201 zero, one, or many files.
8203 @item
8204 When you use @option{--exclude=@var{pattern}}, be sure to quote the
8205 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
8206 like @samp{*}.  If you do not do this, the shell might expand the
8207 @samp{*} itself using files at hand, so @command{tar} might receive a
8208 list of files instead of one pattern, or none at all, making the
8209 command somewhat illegal.  This might not correspond to what you want.
8211 For example, write:
8213 @smallexample
8214 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
8215 @end smallexample
8217 @noindent
8218 rather than:
8220 @smallexample
8221 # @emph{Wrong!}
8222 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
8223 @end smallexample
8225 @item
8226 You must use use shell syntax, or globbing, rather than @code{regexp}
8227 syntax, when using exclude options in @command{tar}.  If you try to use
8228 @code{regexp} syntax to describe files to be excluded, your command
8229 might fail.
8231 @item
8232 @FIXME{The change in semantics must have occurred before 1.11,
8233 so I doubt if it is worth mentioning at all. Anyway, should at
8234 least specify in which version the semantics changed.}
8235 In earlier versions of @command{tar}, what is now the
8236 @option{--exclude-from} option was called @option{--exclude} instead.
8237 Now, @option{--exclude} applies to patterns listed on the command
8238 line and @option{--exclude-from} applies to patterns listed in a
8239 file.
8241 @end itemize
8243 @node wildcards
8244 @section Wildcards Patterns and Matching
8246 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
8247 @samp{*} or @samp{?} for example, are replaced and expanded into all
8248 existing files matching the given pattern.  @GNUTAR{} can use wildcard
8249 patterns for matching (or globbing) archive members when extracting
8250 from or listing an archive.  Wildcard patterns are also used for
8251 verifying volume labels of @command{tar} archives.  This section has the
8252 purpose of explaining wildcard syntax for @command{tar}.
8254 @FIXME{the next few paragraphs need work.}
8256 A @var{pattern} should be written according to shell syntax, using wildcard
8257 characters to effect globbing.  Most characters in the pattern stand
8258 for themselves in the matched string, and case is significant: @samp{a}
8259 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
8260 pattern matches any single character in the matched string.  The character
8261 @samp{*} in the pattern matches zero, one, or more single characters in
8262 the matched string.  The character @samp{\} says to take the following
8263 character of the pattern @emph{literally}; it is useful when one needs to
8264 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
8266 The character @samp{[}, up to the matching @samp{]}, introduces a character
8267 class.  A @dfn{character class} is a list of acceptable characters
8268 for the next single character of the matched string.  For example,
8269 @samp{[abcde]} would match any of the first five letters of the alphabet.
8270 Note that within a character class, all of the ``special characters''
8271 listed above other than @samp{\} lose their special meaning; for example,
8272 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
8273 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
8274 the characters @samp{-} and @samp{]} must either come @emph{first} or
8275 @emph{last} in a character class.)
8277 @cindex Excluding characters from a character class
8278 @cindex Character class, excluding characters from
8279 If the first character of the class after the opening @samp{[}
8280 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
8281 Rather than listing character to match, it lists those characters which
8282 are @emph{forbidden} as the next single character of the matched string.
8284 Other characters of the class stand for themselves.  The special
8285 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
8286 letters, is meant to represent all characters between @var{a} and
8287 @var{e}, inclusive.
8289 @FIXME{need to add a sentence or so here to make this clear for those
8290 who don't have dan around.}
8292 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
8293 special for wildcard matches.  However, if a pattern completely matches
8294 a directory prefix of a matched string, then it matches the full matched
8295 string: thus, excluding a directory also excludes all the files beneath it.
8297 @menu
8298 * controlling pattern-matching::
8299 @end menu
8301 @node controlling pattern-matching
8302 @unnumberedsubsec Controlling Pattern-Matching
8304 For the purposes of this section, we call @dfn{exclusion members} all
8305 member names obtained while processing @option{--exclude} and
8306 @option{--exclude-from} options, and @dfn{inclusion members} those
8307 member names that were given in the command line or read from the file
8308 specified with @option{--files-from} option.
8310 These two pairs of member lists are used in the following operations:
8311 @option{--diff}, @option{--extract}, @option{--list},
8312 @option{--update}.
8314 There are no inclusion members in create mode (@option{--create} and
8315 @option{--append}), since in this mode the names obtained from the
8316 command line refer to @emph{files}, not archive members.
8318 By default, inclusion members are compared with archive members
8319 literally @footnote{Notice that earlier @GNUTAR{} versions used
8320 globbing for inclusion members, which contradicted to UNIX98
8321 specification and was not documented. @xref{Changes}, for more
8322 information on this and other changes.} and exclusion members are
8323 treated as globbing patterns.  For example:
8325 @smallexample
8326 @group
8327 $ @kbd{tar tf foo.tar}
8330 a.txt
8331 [remarks]
8332 # @i{Member names are used verbatim:}
8333 $ @kbd{tar -xf foo.tar -v '[remarks]'}
8334 [remarks]
8335 # @i{Exclude member names are globbed:}
8336 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
8337 a.txt
8338 [remarks]
8339 @end group
8340 @end smallexample
8342 This behavior can be altered by using the following options:
8344 @table @option
8345 @opindex wildcards
8346 @item --wildcards
8347 Treat all member names as wildcards.
8349 @opindex no-wildcards
8350 @item --no-wildcards
8351 Treat all member names as literal strings.
8352 @end table
8354 Thus, to extract files whose names end in @samp{.c}, you can use:
8356 @smallexample
8357 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
8360 @end smallexample
8362 @noindent
8363 Notice quoting of the pattern to prevent the shell from interpreting
8366 The effect of @option{--wildcards} option is canceled by
8367 @option{--no-wildcards}.  This can be used to pass part of
8368 the command line arguments verbatim and other part as globbing
8369 patterns.  For example, the following invocation:
8371 @smallexample
8372 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
8373 @end smallexample
8375 @noindent
8376 instructs @command{tar} to extract from @file{foo.tar} all files whose
8377 names end in @samp{.txt} and the file named @file{[remarks]}.
8379 Normally, a pattern matches a name if an initial subsequence of the
8380 name's components matches the pattern, where @samp{*}, @samp{?}, and
8381 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
8382 and wildcards can match @samp{/}.
8384 Other than optionally stripping leading @samp{/} from names
8385 (@pxref{absolute}), patterns and names are used as-is.  For
8386 example, trailing @samp{/} is not trimmed from a user-specified name
8387 before deciding whether to exclude it.
8389 However, this matching procedure can be altered by the options listed
8390 below.  These options accumulate.  For example:
8392 @smallexample
8393 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
8394 @end smallexample
8396 @noindent
8397 ignores case when excluding @samp{makefile}, but not when excluding
8398 @samp{readme}.
8400 @table @option
8401 @anchor{anchored patterns}
8402 @opindex anchored
8403 @opindex no-anchored
8404 @item --anchored
8405 @itemx --no-anchored
8406 If anchored, a pattern must match an initial subsequence
8407 of the name's components.  Otherwise, the pattern can match any
8408 subsequence.  Default is @option{--no-anchored} for exclusion members
8409 and @option{--anchored} inclusion members.
8411 @anchor{case-insensitive matches}
8412 @opindex ignore-case
8413 @opindex no-ignore-case
8414 @item --ignore-case
8415 @itemx --no-ignore-case
8416 When ignoring case, upper-case patterns match lower-case names and vice versa.
8417 When not ignoring case (the default), matching is case-sensitive.
8419 @opindex wildcards-match-slash
8420 @opindex no-wildcards-match-slash
8421 @item --wildcards-match-slash
8422 @itemx --no-wildcards-match-slash
8423 When wildcards match slash (the default for exclusion members), a
8424 wildcard like @samp{*} in the pattern can match a @samp{/} in the
8425 name.  Otherwise, @samp{/} is matched only by @samp{/}.
8427 @end table
8429 The @option{--recursion} and @option{--no-recursion} options
8430 (@pxref{recurse}) also affect how member patterns are interpreted.  If
8431 recursion is in effect, a pattern matches a name if it matches any of
8432 the name's parent directories.
8434 The following table summarizes pattern-matching default values:
8436 @multitable @columnfractions .3 .7
8437 @headitem Members @tab Default settings
8438 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
8439 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
8440 @end multitable
8442 @node quoting styles
8443 @section Quoting Member Names
8445 When displaying member names, @command{tar} takes care to avoid
8446 ambiguities caused by certain characters.  This is called @dfn{name
8447 quoting}.  The characters in question are:
8449 @itemize @bullet
8450 @item Non-printable control characters:
8451 @anchor{escape sequences}
8452 @multitable @columnfractions 0.20 0.10 0.60
8453 @headitem Character @tab @acronym{ASCII} @tab Character name
8454 @item \a @tab 7  @tab Audible bell
8455 @item \b @tab 8  @tab Backspace
8456 @item \f @tab 12 @tab Form feed
8457 @item \n @tab 10 @tab New line
8458 @item \r @tab 13 @tab Carriage return
8459 @item \t @tab 9  @tab Horizontal tabulation
8460 @item \v @tab 11 @tab Vertical tabulation
8461 @end multitable
8463 @item Space (@acronym{ASCII} 32)
8465 @item Single and double quotes (@samp{'} and @samp{"})
8467 @item Backslash (@samp{\})
8468 @end itemize
8470 The exact way @command{tar} uses to quote these characters depends on
8471 the @dfn{quoting style}.  The default quoting style, called
8472 @dfn{escape} (see below), uses backslash notation to represent control
8473 characters and backslash.
8475 @GNUTAR{} offers seven distinct quoting styles, which can be selected
8476 using @option{--quoting-style} option:
8478 @table @option
8479 @item --quoting-style=@var{style}
8480 @opindex quoting-style
8482 Sets quoting style.  Valid values for @var{style} argument are:
8483 literal, shell, shell-always, c, escape, locale, clocale.
8484 @end table
8486 These styles are described in detail below.  To illustrate their
8487 effect, we will use an imaginary tar archive @file{arch.tar}
8488 containing the following members:
8490 @smallexample
8491 @group
8492 # 1. Contains horizontal tabulation character.
8493 a       tab
8494 # 2. Contains newline character
8496 newline
8497 # 3. Contains a space
8498 a space
8499 # 4. Contains double quotes
8500 a"double"quote
8501 # 5. Contains single quotes
8502 a'single'quote
8503 # 6. Contains a backslash character:
8504 a\backslash
8505 @end group
8506 @end smallexample
8508 Here is how usual @command{ls} command would have listed them, if they
8509 had existed in the current working directory:
8511 @smallexample
8512 @group
8513 $ @kbd{ls}
8514 a\ttab
8515 a\nnewline
8516 a\ space
8517 a"double"quote
8518 a'single'quote
8519 a\\backslash
8520 @end group
8521 @end smallexample
8523 Quoting styles:
8525 @table @samp
8526 @item literal
8527 No quoting, display each character as is:
8529 @smallexample
8530 @group
8531 $ @kbd{tar tf arch.tar --quoting-style=literal}
8533 ./a space
8534 ./a'single'quote
8535 ./a"double"quote
8536 ./a\backslash
8537 ./a     tab
8539 newline
8540 @end group
8541 @end smallexample
8543 @item shell
8544 Display characters the same way Bourne shell does:
8545 control characters, except @samp{\t} and @samp{\n}, are printed using
8546 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
8547 single quote is printed as @samp{\'}.  If a name contains any quoted
8548 characters, it is enclosed in single quotes.  In particular, if a name
8549 contains single quotes, it is printed as several single-quoted strings:
8551 @smallexample
8552 @group
8553 $ @kbd{tar tf arch.tar --quoting-style=shell}
8555 './a space'
8556 './a'\''single'\''quote'
8557 './a"double"quote'
8558 './a\backslash'
8559 './a    tab'
8560 './a
8561 newline'
8562 @end group
8563 @end smallexample
8565 @item shell-always
8566 Same as @samp{shell}, but the names are always enclosed in single
8567 quotes:
8569 @smallexample
8570 @group
8571 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
8572 './'
8573 './a space'
8574 './a'\''single'\''quote'
8575 './a"double"quote'
8576 './a\backslash'
8577 './a    tab'
8578 './a
8579 newline'
8580 @end group
8581 @end smallexample
8583 @item c
8584 Use the notation of the C programming language.  All names are
8585 enclosed in double quotes.  Control characters are quoted using
8586 backslash notations, double quotes are represented as @samp{\"},
8587 backslash characters are represented as @samp{\\}.  Single quotes and
8588 spaces are not quoted:
8590 @smallexample
8591 @group
8592 $ @kbd{tar tf arch.tar --quoting-style=c}
8593 "./"
8594 "./a space"
8595 "./a'single'quote"
8596 "./a\"double\"quote"
8597 "./a\\backslash"
8598 "./a\ttab"
8599 "./a\nnewline"
8600 @end group
8601 @end smallexample
8603 @item escape
8604 Control characters are printed using backslash notation, and a
8605 backslash as @samp{\\}.  This is the default quoting style, unless it
8606 was changed when configured the package.
8608 @smallexample
8609 @group
8610 $ @kbd{tar tf arch.tar --quoting-style=escape}
8612 ./a space
8613 ./a'single'quote
8614 ./a"double"quote
8615 ./a\\backslash
8616 ./a\ttab
8617 ./a\nnewline
8618 @end group
8619 @end smallexample
8621 @item locale
8622 Control characters, single quote and backslash are printed using
8623 backslash notation.  All names are quoted using left and right
8624 quotation marks, appropriate to the current locale.  If it does not
8625 define quotation marks, use @samp{'} as left and as right
8626 quotation marks.  Any occurrences of the right quotation mark in a
8627 name are escaped with @samp{\}, for example:
8629 For example:
8631 @smallexample
8632 @group
8633 $ @kbd{tar tf arch.tar --quoting-style=locale}
8634 './'
8635 './a space'
8636 './a\'single\'quote'
8637 './a"double"quote'
8638 './a\\backslash'
8639 './a\ttab'
8640 './a\nnewline'
8641 @end group
8642 @end smallexample
8644 @item clocale
8645 Same as @samp{locale}, but @samp{"} is used for both left and right
8646 quotation marks, if not provided by the currently selected locale:
8648 @smallexample
8649 @group
8650 $ @kbd{tar tf arch.tar --quoting-style=clocale}
8651 "./"
8652 "./a space"
8653 "./a'single'quote"
8654 "./a\"double\"quote"
8655 "./a\\backslash"
8656 "./a\ttab"
8657 "./a\nnewline"
8658 @end group
8659 @end smallexample
8660 @end table
8662 You can specify which characters should be quoted in addition to those
8663 implied by the current quoting style:
8665 @table @option
8666 @item --quote-chars=@var{string}
8667 Always quote characters from @var{string}, even if the selected
8668 quoting style would not quote them.
8669 @end table
8671 For example, using @samp{escape} quoting (compare with the usual
8672 escape listing above):
8674 @smallexample
8675 @group
8676 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
8678 ./a\ space
8679 ./a'single'quote
8680 ./a\"double\"quote
8681 ./a\\backslash
8682 ./a\ttab
8683 ./a\nnewline
8684 @end group
8685 @end smallexample
8687 To disable quoting of such additional characters, use the following
8688 option:
8690 @table @option
8691 @item --no-quote-chars=@var{string}
8692 Remove characters listed in @var{string} from the list of quoted
8693 characters set by the previous @option{--quote-chars} option.
8694 @end table
8696 This option is particularly useful if you have added
8697 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
8698 and wish to disable it for the current invocation.
8700 Note, that @option{--no-quote-chars} does @emph{not} disable those
8701 characters that are quoted by default in the selected quoting style.
8703 @node transform
8704 @section Modifying File and Member Names
8706 @command{Tar} archives contain detailed information about files stored
8707 in them and full file names are part of that information.  When
8708 storing a file to an archive, its file name is recorded in it,
8709 along with the actual file contents.  When restoring from an archive,
8710 a file is created on disk with exactly the same name as that stored
8711 in the archive.  In the majority of cases this is the desired behavior
8712 of a file archiver.  However, there are some cases when it is not.
8714 First of all, it is often unsafe to extract archive members with
8715 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
8716 takes special precautions when extracting such names and provides a
8717 special option for handling them, which is described in
8718 @ref{absolute}.
8720 Secondly, you may wish to extract file names without some leading
8721 directory components, or with otherwise modified names.  In other
8722 cases it is desirable to store files under differing names in the
8723 archive.
8725 @GNUTAR{} provides several options for these needs.
8727 @table @option
8728 @opindex strip-components
8729 @item --strip-components=@var{number}
8730 Strip given @var{number} of leading components from file names before
8731 extraction.
8732 @end table
8734 For example, suppose you have archived whole @file{/usr} hierarchy to
8735 a tar archive named @file{usr.tar}.  Among other files, this archive
8736 contains @file{usr/include/stdlib.h}, which you wish to extract to
8737 the current working directory.  To do so, you type:
8739 @smallexample
8740 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8741 @end smallexample
8743 The option @option{--strip=2} instructs @command{tar} to strip the
8744 two leading components (@file{usr/} and @file{include/}) off the file
8745 name.
8747 If you add the @option{--verbose} (@option{-v}) option to the invocation
8748 above, you will note that the verbose listing still contains the
8749 full file name, with the two removed components still in place.  This
8750 can be inconvenient, so @command{tar} provides a special option for
8751 altering this behavior:
8753 @anchor{show-transformed-names}
8754 @table @option
8755 @opindex show-transformed-names
8756 @item --show-transformed-names
8757 Display file or member names with all requested transformations
8758 applied.
8759 @end table
8761 @noindent
8762 For example:
8764 @smallexample
8765 @group
8766 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8767 usr/include/stdlib.h
8768 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8769 stdlib.h
8770 @end group
8771 @end smallexample
8773 Notice that in both cases the file @file{stdlib.h} is extracted to the
8774 current working directory, @option{--show-transformed-names} affects
8775 only the way its name is displayed.
8777 This option is especially useful for verifying whether the invocation
8778 will have the desired effect.  Thus, before running
8780 @smallexample
8781 $ @kbd{tar -x --strip=@var{n}}
8782 @end smallexample
8784 @noindent
8785 it is often advisable to run
8787 @smallexample
8788 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8789 @end smallexample
8791 @noindent
8792 to make sure the command will produce the intended results.
8794 In case you need to apply more complex modifications to the file name,
8795 @GNUTAR{} provides a general-purpose transformation option:
8797 @table @option
8798 @opindex transform
8799 @opindex xform
8800 @item --transform=@var{expression}
8801 @itemx --xform=@var{expression}
8802 Modify file names using supplied @var{expression}.
8803 @end table
8805 @noindent
8806 The @var{expression} is a @command{sed}-like replace expression of the
8807 form:
8809 @smallexample
8810 s/@var{regexp}/@var{replace}/[@var{flags}]
8811 @end smallexample
8813 @noindent
8814 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8815 replacement for each file name part that matches @var{regexp}.  Both
8816 @var{regexp} and @var{replace} are described in detail in
8817 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8819 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8820 that it be used consistently throughout the expression. For example,
8821 the following two expressions are equivalent:
8823 @smallexample
8824 @group
8825 s/one/two/
8826 s,one,two,
8827 @end group
8828 @end smallexample
8830 Changing delimiters is often useful when the @var{regex} contains
8831 slashes.  For example, it is more convenient to write @code{s,/,-,} than
8832 @code{s/\//-/}.
8834 As in @command{sed}, you can give several replace expressions,
8835 separated by a semicolon.
8837 Supported @var{flags} are:
8839 @table @samp
8840 @item g
8841 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8842 just the first.
8844 @item i
8845 Use case-insensitive matching.
8847 @item x
8848 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8849 regexps, Extended regular expressions, Extended regular expressions,
8850 sed, GNU sed}).
8852 @item @var{number}
8853 Only replace the @var{number}th match of the @var{regexp}.
8855 Note: the @acronym{POSIX} standard does not specify what should happen
8856 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
8857 follows the GNU @command{sed} implementation in this regard, so
8858 the interaction is defined to be: ignore matches before the
8859 @var{number}th, and then match and replace all matches from the
8860 @var{number}th on.
8862 @end table
8864 In addition, several @dfn{transformation scope} flags are supported,
8865 that control to what files transformations apply.  These are:
8867 @table @samp
8868 @item r
8869 Apply transformation to regular archive members.
8871 @item R
8872 Do not apply transformation to regular archive members.
8874 @item s
8875 Apply transformation to symbolic link targets.
8877 @item S
8878 Do not apply transformation to symbolic link targets.
8880 @item h
8881 Apply transformation to hard link targets.
8883 @item H
8884 Do not apply transformation to hard link targets.
8885 @end table
8887 Default is @samp{rsh}, which means to apply transformations to both archive
8888 members and targets of symbolic and hard links.
8890 Default scope flags can also be changed using @samp{flags=} statement
8891 in the transform expression.  The flags set this way remain in force
8892 until next @samp{flags=} statement or end of expression, whichever
8893 occurs first.  For example:
8895 @smallexample
8896   --transform 'flags=S;s|^|/usr/local/|'
8897 @end smallexample
8899 Here are several examples of @option{--transform} usage:
8901 @enumerate
8902 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8904 @smallexample
8905 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8906 @end smallexample
8908 @item Strip two leading directory components (equivalent to
8909 @option{--strip-components=2}):
8911 @smallexample
8912 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8913 @end smallexample
8915 @item Convert each file name to lower case:
8917 @smallexample
8918 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8919 @end smallexample
8921 @item Prepend @file{/prefix/}  to each file name:
8923 @smallexample
8924 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8925 @end smallexample
8927 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8928 to each archive member:
8930 @smallexample
8931 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8932 @end smallexample
8933 @end enumerate
8935 Notice the use of flags in the last example.  The @file{/lib}
8936 directory often contains many symbolic links to files within it.
8937 It may look, for example, like this:
8939 @smallexample
8940 $ @kbd{ls -l}
8941 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
8942 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8943 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8945 @end smallexample
8947 Using the expression @samp{s,^,/usr/local/,} would mean adding
8948 @samp{/usr/local} to both regular archive members and to link
8949 targets. In this case, @file{/lib/libc.so.6} would become:
8951 @smallexample
8952   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8953 @end smallexample
8955 This is definitely not desired.  To avoid this, the @samp{S} flag
8956 is used, which excludes symbolic link targets from filename
8957 transformations.  The result is:
8959 @smallexample
8960 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
8961        --show-transformed /lib}
8962 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
8963 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8964 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8965  -> libc-2.3.2.so
8966 @end smallexample
8968 Unlike @option{--strip-components}, @option{--transform} can be used
8969 in any @GNUTAR{} operation mode.  For example, the following command
8970 adds files to the archive while replacing the leading @file{usr/}
8971 component with @file{var/}:
8973 @smallexample
8974 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8975 @end smallexample
8977 To test @option{--transform} effect we suggest using
8978 @option{--show-transformed-names} option:
8980 @smallexample
8981 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8982        --verbose --show-transformed-names /}
8983 @end smallexample
8985 If both @option{--strip-components} and @option{--transform} are used
8986 together, then @option{--transform} is applied first, and the required
8987 number of components is then stripped from its result.
8989 You can use as many @option{--transform} options in a single command
8990 line as you want.  The specified expressions will then be applied in
8991 order of their appearance.  For example, the following two invocations
8992 are equivalent:
8994 @smallexample
8995 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8996                         --transform='s,/usr/local,/usr/,'}
8997 $ @kbd{tar -cf arch.tar \
8998                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8999 @end smallexample
9001 @node after
9002 @section Operating Only on New Files
9004 @cindex Excluding file by age
9005 @cindex Data Modification time, excluding files by
9006 @cindex Modification time, excluding files by
9007 @cindex Age, excluding files by
9008 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
9009 @option{-N @var{date}}) option causes @command{tar} to only work on
9010 files whose data modification or status change times are newer than
9011 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
9012 it is taken to be a file name; the data modification time of that file
9013 is used as the date. If you use this option when creating or appending
9014 to an archive, the archive will only include new files.  If you use
9015 @option{--after-date} when extracting an archive, @command{tar} will
9016 only extract files newer than the @var{date} you specify.
9018 If you only want @command{tar} to make the date comparison based on
9019 modification of the file's data (rather than status
9020 changes), then use the @option{--newer-mtime=@var{date}} option.
9022 @cindex --after-date and --update compared
9023 @cindex --newer-mtime and --update compared
9024 You may use these options with any operation.  Note that these options
9025 differ from the @option{--update} (@option{-u}) operation in that they
9026 allow you to specify a particular date against which @command{tar} can
9027 compare when deciding whether or not to archive the files.
9029 @table @option
9030 @opindex after-date
9031 @opindex newer
9032 @item --after-date=@var{date}
9033 @itemx --newer=@var{date}
9034 @itemx -N @var{date}
9035 Only store files newer than @var{date}.
9037 Acts on files only if their data modification or status change times are
9038 later than @var{date}.  Use in conjunction with any operation.
9040 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
9041 name; the data modification time of that file is used as the date.
9043 @opindex newer-mtime
9044 @item --newer-mtime=@var{date}
9045 Acts like @option{--after-date}, but only looks at data modification times.
9046 @end table
9048 These options limit @command{tar} to operate only on files which have
9049 been modified after the date specified.  A file's status is considered to have
9050 changed if its contents have been modified, or if its owner,
9051 permissions, and so forth, have been changed.  (For more information on
9052 how to specify a date, see @ref{Date input formats}; remember that the
9053 entire date argument must be quoted if it contains any spaces.)
9055 Gurus would say that @option{--after-date} tests both the data
9056 modification time (@code{mtime}, the time the contents of the file
9057 were last modified) and the status change time (@code{ctime}, the time
9058 the file's status was last changed: owner, permissions, etc.@:)
9059 fields, while @option{--newer-mtime} tests only the @code{mtime}
9060 field.
9062 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
9063 @code{ctime} and processes the file if either one is more recent than
9064 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
9065 disregards @code{ctime}.  Neither does it use @code{atime} (the last time the
9066 contents of the file were looked at).
9068 Date specifiers can have embedded spaces.  Because of this, you may need
9069 to quote date arguments to keep the shell from parsing them as separate
9070 arguments.  For example, the following command will add to the archive
9071 all the files modified less than two days ago:
9073 @smallexample
9074 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
9075 @end smallexample
9077 When any of these options is used with the option @option{--verbose}
9078 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
9079 date back to its textual representation and compare that with the
9080 one given with the option.  If the two dates differ, @command{tar} will
9081 print a warning saying what date it will use.  This is to help user
9082 ensure he is using the right date.  For example:
9084 @smallexample
9085 @group
9086 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
9087 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
9088 13:19:37.232434
9089 @end group
9090 @end smallexample
9092 @quotation
9093 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
9094 should not be used for incremental backups.  @xref{Incremental Dumps},
9095 for proper way of creating incremental backups.
9096 @end quotation
9098 @node recurse
9099 @section Descending into Directories
9100 @cindex Avoiding recursion in directories
9101 @cindex Descending directories, avoiding
9102 @cindex Directories, avoiding recursion
9103 @cindex Recursion in directories, avoiding
9105 Usually, @command{tar} will recursively explore all directories (either
9106 those given on the command line or through the @option{--files-from}
9107 option) for the various files they contain.  However, you may not always
9108 want @command{tar} to act this way.
9110 @opindex no-recursion
9111 @cindex @command{find}, using with @command{tar}
9112 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
9113 into specified directories.  If you specify @option{--no-recursion}, you can
9114 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
9115 utility for hunting through levels of directories to
9116 construct a list of file names which you could then pass to @command{tar}.
9117 @command{find} allows you to be more selective when choosing which files to
9118 archive; see @ref{files}, for more information on using @command{find} with
9119 @command{tar}.
9121 @table @option
9122 @item --no-recursion
9123 Prevents @command{tar} from recursively descending directories.
9125 @opindex recursion
9126 @item --recursion
9127 Requires @command{tar} to recursively descend directories.
9128 This is the default.
9129 @end table
9131 When you use @option{--no-recursion}, @GNUTAR{} grabs
9132 directory entries themselves, but does not descend on them
9133 recursively.  Many people use @command{find} for locating files they
9134 want to back up, and since @command{tar} @emph{usually} recursively
9135 descends on directories, they have to use the @samp{@w{-not -type d}}
9136 test in their @command{find} invocation (@pxref{Type, Type, Type test,
9137 find, Finding Files}), as they usually do not want all the files in a
9138 directory. They then use the @option{--files-from} option to archive
9139 the files located via @command{find}.
9141 The problem when restoring files archived in this manner is that the
9142 directories themselves are not in the archive; so the
9143 @option{--same-permissions} (@option{--preserve-permissions},
9144 @option{-p}) option does not affect them---while users might really
9145 like it to.  Specifying @option{--no-recursion} is a way to tell
9146 @command{tar} to grab only the directory entries given to it, adding
9147 no new files on its own.  To summarize, if you use @command{find} to
9148 create a list of files to be stored in an archive, use it as follows:
9150 @smallexample
9151 @group
9152 $ @kbd{find @var{dir} @var{tests} | \
9153   tar -cf @var{archive} --no-recursion -T -}
9154 @end group
9155 @end smallexample
9157 The @option{--no-recursion} option also applies when extracting: it
9158 causes @command{tar} to extract only the matched directory entries, not
9159 the files under those directories.
9161 The @option{--no-recursion} option also affects how globbing patterns
9162 are interpreted (@pxref{controlling pattern-matching}).
9164 The @option{--no-recursion} and @option{--recursion} options apply to
9165 later options and operands, and can be overridden by later occurrences
9166 of @option{--no-recursion} and @option{--recursion}.  For example:
9168 @smallexample
9169 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
9170 @end smallexample
9172 @noindent
9173 creates an archive with one entry for @file{grape}, and the recursive
9174 contents of @file{grape/concord}, but no entries under @file{grape}
9175 other than @file{grape/concord}.
9177 @node one
9178 @section Crossing File System Boundaries
9179 @cindex File system boundaries, not crossing
9181 @command{tar} will normally automatically cross file system boundaries in
9182 order to archive files which are part of a directory tree.  You can
9183 change this behavior by running @command{tar} and specifying
9184 @option{--one-file-system}.  This option only affects files that are
9185 archived because they are in a directory that is being archived;
9186 @command{tar} will still archive files explicitly named on the command line
9187 or through @option{--files-from}, regardless of where they reside.
9189 @table @option
9190 @opindex one-file-system
9191 @item --one-file-system
9192 Prevents @command{tar} from crossing file system boundaries when
9193 archiving.  Use in conjunction with any write operation.
9194 @end table
9196 The @option{--one-file-system} option causes @command{tar} to modify its
9197 normal behavior in archiving the contents of directories.  If a file in
9198 a directory is not on the same file system as the directory itself, then
9199 @command{tar} will not archive that file.  If the file is a directory
9200 itself, @command{tar} will not archive anything beneath it; in other words,
9201 @command{tar} will not cross mount points.
9203 This option is useful for making full or incremental archival backups of
9204 a file system.  If this option is used in conjunction with
9205 @option{--verbose} (@option{-v}), files that are excluded are
9206 mentioned by name on the standard error.
9208 @menu
9209 * directory::                   Changing Directory
9210 * absolute::                    Absolute File Names
9211 @end menu
9213 @node directory
9214 @subsection Changing the Working Directory
9216 @FIXME{need to read over this node now for continuity; i've switched
9217 things around some.}
9219 @cindex Changing directory mid-stream
9220 @cindex Directory, changing mid-stream
9221 @cindex Working directory, specifying
9222 To change the working directory in the middle of a list of file names,
9223 either on the command line or in a file specified using
9224 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
9225 This will change the working directory to the specified directory
9226 after that point in the list.
9228 @table @option
9229 @opindex directory
9230 @item --directory=@var{directory}
9231 @itemx -C @var{directory}
9232 Changes the working directory in the middle of a command line.
9233 @end table
9235 For example,
9237 @smallexample
9238 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
9239 @end smallexample
9241 @noindent
9242 will place the files @file{grape} and @file{prune} from the current
9243 directory into the archive @file{jams.tar}, followed by the file
9244 @file{cherry} from the directory @file{food}.  This option is especially
9245 useful when you have several widely separated files that you want to
9246 store in the same archive.
9248 Note that the file @file{cherry} is recorded in the archive under the
9249 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
9250 archive will contain three files that all appear to have come from the
9251 same directory; if the archive is extracted with plain @samp{tar
9252 --extract}, all three files will be written in the current directory.
9254 Contrast this with the command,
9256 @smallexample
9257 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
9258 @end smallexample
9260 @noindent
9261 which records the third file in the archive under the name
9262 @file{red/cherry} so that, if the archive is extracted using
9263 @samp{tar --extract}, the third file will be written in a subdirectory
9264 named @file{red}.
9266 You can use the @option{--directory} option to make the archive
9267 independent of the original name of the directory holding the files.
9268 The following command places the files @file{/etc/passwd},
9269 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
9270 @file{foo.tar}:
9272 @smallexample
9273 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
9274 @end smallexample
9276 @noindent
9277 However, the names of the archive members will be exactly what they were
9278 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
9279 They will not appear to be related by file name to the original
9280 directories where those files were located.
9282 Note that @option{--directory} options are interpreted consecutively.  If
9283 @option{--directory} specifies a relative file name, it is interpreted
9284 relative to the then current directory, which might not be the same as
9285 the original current working directory of @command{tar}, due to a previous
9286 @option{--directory} option.
9288 When using @option{--files-from} (@pxref{files}), you can put various
9289 @command{tar} options (including @option{-C}) in the file list.  Notice,
9290 however, that in this case the option and its argument may not be
9291 separated by whitespace.  If you use short option, its argument must
9292 either follow the option letter immediately, without any intervening
9293 whitespace, or occupy the next line.  Otherwise, if you use long
9294 option, separate its argument by an equal sign.
9296 For instance, the file list for the above example will be:
9298 @smallexample
9299 @group
9300 -C/etc
9301 passwd
9302 hosts
9303 --directory=/lib
9304 libc.a
9305 @end group
9306 @end smallexample
9308 @noindent
9309 To use it, you would invoke @command{tar} as follows:
9311 @smallexample
9312 $ @kbd{tar -c -f foo.tar --files-from list}
9313 @end smallexample
9315 The interpretation of options in file lists is disabled by
9316 @option{--verbatim-files-from} and @option{--null} options.
9318 @node absolute
9319 @subsection Absolute File Names
9320 @cindex absolute file names
9321 @cindex file names, absolute
9323 By default, @GNUTAR{} drops a leading @samp{/} on
9324 input or output, and complains about file names containing a @file{..}
9325 component.  There is an option that turns off this behavior:
9327 @table @option
9328 @opindex absolute-names
9329 @item --absolute-names
9330 @itemx -P
9331 Do not strip leading slashes from file names, and permit file names
9332 containing a @file{..} file name component.
9333 @end table
9335 When @command{tar} extracts archive members from an archive, it strips any
9336 leading slashes (@samp{/}) from the member name.  This causes absolute
9337 member names in the archive to be treated as relative file names.  This
9338 allows you to have such members extracted wherever you want, instead of
9339 being restricted to extracting the member in the exact directory named
9340 in the archive.  For example, if the archive member has the name
9341 @file{/etc/passwd}, @command{tar} will extract it as if the name were
9342 really @file{etc/passwd}.
9344 File names containing @file{..} can cause problems when extracting, so
9345 @command{tar} normally warns you about such files when creating an
9346 archive, and rejects attempts to extracts such files.
9348 Other @command{tar} programs do not do this.  As a result, if you
9349 create an archive whose member names start with a slash, they will be
9350 difficult for other people with a non-@GNUTAR{}
9351 program to use.  Therefore, @GNUTAR{} also strips
9352 leading slashes from member names when putting members into the
9353 archive.  For example, if you ask @command{tar} to add the file
9354 @file{/bin/ls} to an archive, it will do so, but the member name will
9355 be @file{bin/ls}@footnote{A side effect of this is that when
9356 @option{--create} is used with @option{--verbose} the resulting output
9357 is not, generally speaking, the same as the one you'd get running
9358 @kbd{tar --list} command.  This may be important if you use some
9359 scripts for comparing both outputs.  @xref{listing member and file names},
9360 for the information on how to handle this case.}.
9362 Symbolic links containing @file{..} or leading @samp{/} can also cause
9363 problems when extracting, so @command{tar} normally extracts them last;
9364 it may create empty files as placeholders during extraction.
9366 If you use the @option{--absolute-names} (@option{-P}) option,
9367 @command{tar} will do none of these transformations.
9369 To archive or extract files relative to the root directory, specify
9370 the @option{--absolute-names} (@option{-P}) option.
9372 Normally, @command{tar} acts on files relative to the working
9373 directory---ignoring superior directory names when archiving, and
9374 ignoring leading slashes when extracting.
9376 When you specify @option{--absolute-names} (@option{-P}),
9377 @command{tar} stores file names including all superior directory
9378 names, and preserves leading slashes.  If you only invoked
9379 @command{tar} from the root directory you would never need the
9380 @option{--absolute-names} option, but using this option
9381 may be more convenient than switching to root.
9383 @FIXME{Should be an example in the tutorial/wizardry section using this
9384 to transfer files between systems.}
9386 @table @option
9387 @item --absolute-names
9388 Preserves full file names (including superior directory names) when
9389 archiving and extracting files.
9391 @end table
9393 @command{tar} prints out a message about removing the @samp{/} from
9394 file names.  This message appears once per @GNUTAR{}
9395 invocation.  It represents something which ought to be told; ignoring
9396 what it means can cause very serious surprises, later.
9398 Some people, nevertheless, do not want to see this message.  Wanting to
9399 play really dangerously, one may of course redirect @command{tar} standard
9400 error to the sink.  For example, under @command{sh}:
9402 @smallexample
9403 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
9404 @end smallexample
9406 @noindent
9407 Another solution, both nicer and simpler, would be to change to
9408 the @file{/} directory first, and then avoid absolute notation.
9409 For example:
9411 @smallexample
9412 $ @kbd{tar -c -f archive.tar -C / home}
9413 @end smallexample
9415 @xref{Integrity}, for some of the security-related implications
9416 of using this option.
9418 @include parse-datetime.texi
9420 @node Formats
9421 @chapter Controlling the Archive Format
9423 @cindex Tar archive formats
9424 Due to historical reasons, there are several formats of tar archives.
9425 All of them are based on the same principles, but have some subtle
9426 differences that often make them incompatible with each other.
9428 GNU tar is able to create and handle archives in a variety of formats.
9429 The most frequently used formats are (in alphabetical order):
9431 @table @asis
9432 @item gnu
9433 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
9434 from an early @acronym{POSIX} standard, adding some improvements such as
9435 sparse file handling and incremental archives.  Unfortunately these
9436 features were implemented in a way incompatible with other archive
9437 formats.
9439 Archives in @samp{gnu} format are able to hold file names of unlimited
9440 length.
9442 @item oldgnu
9443 Format used by @GNUTAR{} of versions prior to 1.12.
9445 @item v7
9446 Archive format, compatible with the V7 implementation of tar.  This
9447 format imposes a number of limitations.  The most important of them
9448 are:
9450 @enumerate
9451 @item The maximum length of a file name is limited to 99 characters.
9452 @item The maximum length of a symbolic link is limited to 99 characters.
9453 @item It is impossible to store special files (block and character
9454 devices, fifos etc.)
9455 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
9456 octal)
9457 @item V7 archives do not contain symbolic ownership information (user
9458 and group name of the file owner).
9459 @end enumerate
9461 This format has traditionally been used by Automake when producing
9462 Makefiles.  This practice will change in the future, in the meantime,
9463 however this means that projects containing file names more than 99
9464 characters long will not be able to use @GNUTAR{} @value{VERSION} and
9465 Automake prior to 1.9.
9467 @item ustar
9468 Archive format defined by @acronym{POSIX.1-1988} specification.  It stores
9469 symbolic ownership information.  It is also able to store
9470 special files.  However, it imposes several restrictions as well:
9472 @enumerate
9473 @item The maximum length of a file name is limited to 256 characters,
9474 provided that the file name can be split at a directory separator in
9475 two parts, first of them being at most 155 bytes long.  So, in most
9476 cases the maximum file name length will be shorter than 256
9477 characters.
9478 @item The maximum length of a symbolic link name is limited to
9479 100 characters.
9480 @item Maximum size of a file the archive is able to accommodate
9481 is 8GB
9482 @item Maximum value of UID/GID is 2097151.
9483 @item Maximum number of bits in device major and minor numbers is 21.
9484 @end enumerate
9486 @item star
9487 Format used by J@"org Schilling @command{star}
9488 implementation.  @GNUTAR{} is able to read @samp{star} archives but
9489 currently does not produce them.
9491 @item posix
9492 Archive format defined by @acronym{POSIX.1-2001} specification.  This is the
9493 most flexible and feature-rich format.  It does not impose any
9494 restrictions on file sizes or file name lengths.  This format is quite
9495 recent, so not all tar implementations are able to handle it properly.
9496 However, this format is designed in such a way that any tar
9497 implementation able to read @samp{ustar} archives will be able to read
9498 most @samp{posix} archives as well, with the only exception that any
9499 additional information (such as long file names etc.)@: will in such
9500 case be extracted as plain text files along with the files it refers to.
9502 This archive format will be the default format for future versions
9503 of @GNUTAR{}.
9505 @end table
9507 The following table summarizes the limitations of each of these
9508 formats:
9510 @multitable @columnfractions .10 .20 .20 .20 .20
9511 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
9512 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9513 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9514 @item v7     @tab 2097151 @tab 8GB @tab 99 @tab n/a
9515 @item ustar  @tab 2097151 @tab 8GB @tab 256 @tab 21
9516 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
9517 @end multitable
9519 The default format for @GNUTAR{} is defined at compilation
9520 time.  You may check it by running @command{tar --help}, and examining
9521 the last lines of its output.  Usually, @GNUTAR{} is configured
9522 to create archives in @samp{gnu} format, however, future version will
9523 switch to @samp{posix}.
9525 @menu
9526 * Compression::                 Using Less Space through Compression
9527 * Attributes::                  Handling File Attributes
9528 * Portability::                 Making @command{tar} Archives More Portable
9529 * cpio::                        Comparison of @command{tar} and @command{cpio}
9530 @end menu
9532 @node Compression
9533 @section Using Less Space through Compression
9535 @menu
9536 * gzip::                        Creating and Reading Compressed Archives
9537 * sparse::                      Archiving Sparse Files
9538 @end menu
9540 @node gzip
9541 @subsection Creating and Reading Compressed Archives
9542 @cindex Compressed archives
9543 @cindex Storing archives in compressed format
9545 @cindex gzip
9546 @cindex bzip2
9547 @cindex lzip
9548 @cindex lzma
9549 @cindex lzop
9550 @cindex compress
9551 @cindex zstd
9552 @GNUTAR{} is able to create and read compressed archives.  It supports
9553 a wide variety of compression programs, namely: @command{gzip},
9554 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
9555 @command{zstd}, @command{xz} and traditional @command{compress}. The
9556 latter is supported mostly for backward compatibility, and we recommend
9557 against using it, because it is by far less effective than the other
9558 compression programs@footnote{It also had patent problems in the past.}.
9560 Creating a compressed archive is simple: you just specify a
9561 @dfn{compression option} along with the usual archive creation
9562 commands.  Available compression options are summarized in the
9563 table below:
9565 @multitable @columnfractions 0.4 0.2 0.4
9566 @headitem Long            @tab Short       @tab Archive format
9567 @item @option{--gzip}     @tab @option{-z} @tab @command{gzip}
9568 @item @option{--bzip2}    @tab @option{-j} @tab @command{bzip2}
9569 @item @option{--xz}       @tab @option{-J} @tab @command{xz}
9570 @item @option{--lzip}     @tab             @tab @command{lzip}
9571 @item @option{--lzma}     @tab             @tab @command{lzma}
9572 @item @option{--lzop}     @tab             @tab @command{lzop}
9573 @item @option{--zstd}     @tab             @tab @command{zstd}
9574 @item @option{--compress} @tab @option{-Z} @tab @command{compress}
9575 @end multitable
9577 For example:
9579 @smallexample
9580 $ @kbd{tar czf archive.tar.gz .}
9581 @end smallexample
9583 You can also let @GNUTAR{} select the compression program based on
9584 the suffix of the archive file name. This is done using
9585 @option{--auto-compress} (@option{-a}) command line option. For
9586 example, the following invocation will use @command{bzip2} for
9587 compression:
9589 @smallexample
9590 $ @kbd{tar caf archive.tar.bz2 .}
9591 @end smallexample
9593 @noindent
9594 whereas the following one will use @command{lzma}:
9596 @smallexample
9597 $ @kbd{tar caf archive.tar.lzma .}
9598 @end smallexample
9600 For a complete list of file name suffixes recognized by @GNUTAR{},
9601 see @ref{auto-compress}.
9603 Reading compressed archive is even simpler: you don't need to specify
9604 any additional options as @GNUTAR{} recognizes its format
9605 automatically.  Thus, the following commands will list and extract the
9606 archive created in previous example:
9608 @smallexample
9609 # List the compressed archive
9610 $ @kbd{tar tf archive.tar.gz}
9611 # Extract the compressed archive
9612 $ @kbd{tar xf archive.tar.gz}
9613 @end smallexample
9615 The format recognition algorithm is based on @dfn{signatures}, a
9616 special byte sequences in the beginning of file, that are specific for
9617 certain compression formats.  If this approach fails, @command{tar}
9618 falls back to using archive name suffix to determine its format
9619 (@pxref{auto-compress}, for a list of recognized suffixes).
9621 @anchor{alternative decompression programs}
9622 @cindex alternative decompression programs
9623 Some compression programs are able to handle different compression
9624 formats.  @GNUTAR{} uses this, if the principal decompressor for the
9625 given format is not available.  For example, if @command{compress} is
9626 not installed, @command{tar} will try to use @command{gzip}.  As of
9627 version @value{VERSION} the following alternatives are
9628 tried@footnote{To verbosely trace the decompressor selection, use the
9629 @option{--warning=decompress-program} option
9630 (@pxref{warnings,decompress-program}).}:
9632 @multitable @columnfractions 0.3 0.3 0.3
9633 @headitem Format @tab Main decompressor @tab Alternatives
9634 @item compress @tab compress @tab gzip
9635 @item lzma     @tab lzma     @tab xz
9636 @item bzip2    @tab bzip2    @tab lbzip2
9637 @end multitable
9639 The only case when you have to specify a decompression option while
9640 reading the archive is when reading from a pipe or from a tape drive
9641 that does not support random access.  However, in this case @GNUTAR{}
9642 will indicate which option you should use.  For example:
9644 @smallexample
9645 $ @kbd{cat archive.tar.gz | tar tf -}
9646 tar: Archive is compressed.  Use -z option
9647 tar: Error is not recoverable: exiting now
9648 @end smallexample
9650 If you see such diagnostics, just add the suggested option to the
9651 invocation of @GNUTAR{}:
9653 @smallexample
9654 $ @kbd{cat archive.tar.gz | tar tzf -}
9655 @end smallexample
9657 Notice also, that there are several restrictions on operations on
9658 compressed archives.  First of all, compressed archives cannot be
9659 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
9660 them or delete (@option{--delete}) members from them or
9661 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
9662 cannot append another @command{tar} archive to a compressed archive using
9663 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
9664 archives cannot be compressed.
9666 The following options allow to select a particular compressor program:
9668 @table @option
9669 @opindex gzip
9670 @opindex ungzip
9671 @item -z
9672 @itemx --gzip
9673 @itemx --ungzip
9674 Filter the archive through @command{gzip}.
9676 @opindex xz
9677 @item -J
9678 @itemx --xz
9679 Filter the archive through @code{xz}.
9681 @item -j
9682 @itemx --bzip2
9683 Filter the archive through @code{bzip2}.
9685 @opindex lzip
9686 @item --lzip
9687 Filter the archive through @command{lzip}.
9689 @opindex lzma
9690 @item --lzma
9691 Filter the archive through @command{lzma}.
9693 @opindex lzop
9694 @item --lzop
9695 Filter the archive through @command{lzop}.
9697 @opindex zstd
9698 @item --zstd
9699 Filter the archive through @command{zstd}.
9701 @opindex compress
9702 @opindex uncompress
9703 @item -Z
9704 @itemx --compress
9705 @itemx --uncompress
9706 Filter the archive through @command{compress}.
9707 @end table
9709 When any of these options is given, @GNUTAR{} searches the compressor
9710 binary in the current path and invokes it.  The name of the compressor
9711 program is specified at compilation time using a corresponding
9712 @option{--with-@var{compname}} option to @command{configure}, e.g.
9713 @option{--with-bzip2} to select a specific @command{bzip2} binary.
9714 @xref{lbzip2}, for a detailed discussion.
9716 The output produced by @command{tar --help} shows the actual
9717 compressor names along with each of these options.
9719 You can use any of these options on physical devices (tape drives,
9720 etc.)@: and remote files as well as on normal files; data to or from
9721 such devices or remote files is reblocked by another copy of the
9722 @command{tar} program to enforce the specified (or default) record
9723 size.  The default compression parameters are used.
9724 You can override them by using the @option{-I} option (see
9725 below), e.g.:
9727 @smallexample
9728 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9729 @end smallexample
9731 @noindent
9732 A more traditional way to do this is to use a pipe:
9734 @smallexample
9735 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9736 @end smallexample
9738 @cindex corrupted archives
9739 Compressed archives are easily corrupted, because compressed files
9740 have little redundancy.  The adaptive nature of the
9741 compression scheme means that the compression tables are implicitly
9742 spread all over the archive.  If you lose a few blocks, the dynamic
9743 construction of the compression tables becomes unsynchronized, and there
9744 is little chance that you could recover later in the archive.
9746 Other compression options provide better control over creating
9747 compressed archives.  These are:
9749 @table @option
9750 @anchor{auto-compress}
9751 @opindex auto-compress
9752 @item --auto-compress
9753 @itemx -a
9754 Select a compression program to use by the archive file name
9755 suffix.  The following suffixes are recognized:
9757 @multitable @columnfractions 0.3 0.6
9758 @headitem Suffix @tab Compression program
9759 @item @samp{.gz} @tab @command{gzip}
9760 @item @samp{.tgz} @tab @command{gzip}
9761 @item @samp{.taz} @tab @command{gzip}
9762 @item @samp{.Z} @tab @command{compress}
9763 @item @samp{.taZ} @tab @command{compress}
9764 @item @samp{.bz2} @tab @command{bzip2}
9765 @item @samp{.tz2} @tab @command{bzip2}
9766 @item @samp{.tbz2} @tab @command{bzip2}
9767 @item @samp{.tbz} @tab @command{bzip2}
9768 @item @samp{.lz} @tab @command{lzip}
9769 @item @samp{.lzma} @tab @command{lzma}
9770 @item @samp{.tlz} @tab @command{lzma}
9771 @item @samp{.lzo} @tab @command{lzop}
9772 @item @samp{.xz} @tab @command{xz}
9773 @item @samp{.zst} @tab @command{zstd}
9774 @item @samp{.tzst} @tab @command{zstd}
9775 @end multitable
9777 @anchor{use-compress-program}
9778 @opindex use-compress-program
9779 @item --use-compress-program=@var{command}
9780 @itemx -I=@var{command}
9781 Use external compression program @var{command}.  Use this option if you
9782 want to specify options for the compression program, or if you
9783 are not happy with the compression program associated with the suffix
9784 at compile time, or if you have a compression program that @GNUTAR{}
9785 does not support.  The @var{command} argument is a valid command
9786 invocation, as you would type it at the command line prompt, with any
9787 additional options as needed.  Enclose it in quotes if it contains
9788 white space (@pxref{external, Running External Commands}).
9790 The @var{command} should follow two conventions:
9792 First, when invoked without additional options, it should read data
9793 from standard input, compress it and output it on standard output.
9795 Secondly, if invoked with the additional @option{-d} option, it should
9796 do exactly the opposite, i.e., read the compressed data from the
9797 standard input and produce uncompressed data on the standard output.
9799 The latter requirement means that you must not use the @option{-d}
9800 option as a part of the @var{command} itself.
9801 @end table
9803 @cindex gpg, using with tar
9804 @cindex gnupg, using with tar
9805 @cindex Using encrypted archives
9806 The @option{--use-compress-program} option, in particular, lets you
9807 implement your own filters, not necessarily dealing with
9808 compression/decompression.  For example, suppose you wish to implement
9809 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9810 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9811 Manual}).  The following script does that:
9813 @smallexample
9814 @group
9815 #! /bin/sh
9816 case $1 in
9817 -d) gpg --decrypt - | gzip -d -c;;
9818 '') gzip -c | gpg -s;;
9819 *)  echo "Unknown option $1">&2; exit 1;;
9820 esac
9821 @end group
9822 @end smallexample
9824 Suppose you name it @file{gpgz} and save it somewhere in your
9825 @env{PATH}.  Then the following command will create a compressed
9826 archive signed with your private key:
9828 @smallexample
9829 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9830 @end smallexample
9832 @noindent
9833 Likewise, the command below will list its contents:
9835 @smallexample
9836 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9837 @end smallexample
9839 @ignore
9840 The above is based on the following discussion:
9842      I have one question, or maybe it's a suggestion if there isn't a way
9843      to do it now.  I would like to use @option{--gzip}, but I'd also like
9844      the output to be fed through a program like @acronym{GNU}
9845      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9846      to use :-)), basically adding ECC protection on top of compression.
9847      It seems as if this should be quite easy to do, but I can't work out
9848      exactly how to go about it.  Of course, I can pipe the standard output
9849      of @command{tar} through @command{ecc}, but then I lose (though I
9850      haven't started using it yet, I confess) the ability to have
9851      @command{tar} use @command{rmt} for it's I/O (I think).
9853      I think the most straightforward thing would be to let me specify a
9854      general set of filters outboard of compression (preferably ordered,
9855      so the order can be automatically reversed on input operations, and
9856      with the options they require specifiable), but beggars shouldn't be
9857      choosers and anything you decide on would be fine with me.
9859      By the way, I like @command{ecc} but if (as the comments say) it can't
9860      deal with loss of block sync, I'm tempted to throw some time at adding
9861      that capability.  Supposing I were to actually do such a thing and
9862      get it (apparently) working, do you accept contributed changes to
9863      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9865   Isn't that exactly the role of the
9866   @option{--use-compress-prog=@var{program}} option?
9867   I never tried it myself, but I suspect you may want to write a
9868   @var{prog} script or program able to filter stdin to stdout to
9869   way you want.  It should recognize the @option{-d} option, for when
9870   extraction is needed rather than creation.
9872   It has been reported that if one writes compressed data (through the
9873   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9874   the DLT compression mode, the data will actually get bigger and one will
9875   end up with less space on the tape.
9876 @end ignore
9878 @menu
9879 * lbzip2::  Using lbzip2 with @GNUTAR{}.
9880 @end menu
9882 @node lbzip2
9883 @subsubsection Using lbzip2 with @GNUTAR{}.
9884 @cindex lbzip2
9885 @cindex Laszlo Ersek
9886   @command{Lbzip2} is a multithreaded utility for handling
9887 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
9888 multiple processors to speed up its operation and in general works
9889 considerably faster than @command{bzip2}.  For a detailed description
9890 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9891 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9892 lbzip2: parallel bzip2 utility}.
9894   Recent versions of @command{lbzip2} are mostly command line compatible
9895 with @command{bzip2}, which makes it possible to automatically invoke
9896 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
9897 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9898 line option, like this:
9900 @smallexample
9901 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9902 @end smallexample
9904   Once configured and compiled this way, @command{tar --help} will show the
9905 following:
9907 @smallexample
9908 @group
9909 $ @kbd{tar --help | grep -- --bzip2}
9910   -j, --bzip2                filter the archive through lbzip2
9911 @end group
9912 @end smallexample
9914 @noindent
9915 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9917 @node sparse
9918 @subsection Archiving Sparse Files
9919 @cindex Sparse Files
9921 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
9922 in a file is a section of the file's contents which was never written.
9923 The contents of a hole reads as all zeros.  On many operating systems,
9924 actual disk storage is not allocated for holes, but they are counted
9925 in the length of the file.  If you archive such a file, @command{tar}
9926 could create an archive longer than the original.  To have @command{tar}
9927 attempt to recognize the holes in a file, use @option{--sparse}
9928 (@option{-S}).  When you use this option, then, for any file using
9929 less disk space than would be expected from its length, @command{tar}
9930 searches the file for holes.  It then records in the archive for the file where
9931 the holes (consecutive stretches of zeros) are, and only archives the
9932 ``real contents'' of the file.  On extraction (using @option{--sparse} is not
9933 needed on extraction) any such files have also holes created wherever the holes
9934 were found.  Thus, if you use @option{--sparse}, @command{tar} archives won't
9935 take more space than the original.
9937 @GNUTAR{} uses two methods for detecting holes in sparse files.  These
9938 methods are described later in this subsection.
9940 @table @option
9941 @opindex sparse
9942 @item -S
9943 @itemx --sparse
9944 This option instructs @command{tar} to test each file for sparseness
9945 before attempting to archive it.  If the file is found to be sparse it
9946 is treated specially, thus allowing to decrease the amount of space
9947 used by its image in the archive.
9949 This option is meaningful only when creating or updating archives.  It
9950 has no effect on extraction.
9951 @end table
9953 Consider using @option{--sparse} when performing file system backups,
9954 to avoid archiving the expanded forms of files stored sparsely in the
9955 system.
9957 Even if your system has no sparse files currently, some may be
9958 created in the future.  If you use @option{--sparse} while making file
9959 system backups as a matter of course, you can be assured the archive
9960 will never take more space on the media than the files take on disk
9961 (otherwise, archiving a disk filled with sparse files might take
9962 hundreds of tapes).  @xref{Incremental Dumps}.
9964 However, be aware that @option{--sparse} option may present a serious
9965 drawback.  Namely, in order to determine the positions of holes in a file
9966 @command{tar} may have to read it before trying to archive it, so in total
9967 the file may be read @strong{twice}.  This may happen when your OS or your FS
9968 does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
9969 @option{--hole-detection}, below).
9971 @cindex sparse formats, defined
9972 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9973 sparse files using in three distinct ways, called @dfn{sparse
9974 formats}.  A sparse format is identified by its @dfn{number},
9975 consisting, as usual of two decimal numbers, delimited by a dot.  By
9976 default, format @samp{1.0} is used.  If, for some reason, you wish to
9977 use an earlier format, you can select it using
9978 @option{--sparse-version} option.
9980 @table @option
9981 @opindex sparse-version
9982 @item --sparse-version=@var{version}
9983 Select the format to store sparse files in.  Valid @var{version} values
9984 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
9985 for a detailed description of each format.
9986 @end table
9988 Using @option{--sparse-format} option implies @option{--sparse}.
9990 @table @option
9991 @opindex hole-detection
9992 @cindex hole detection
9993 @item --hole-detection=@var{method}
9994 Enforce concrete hole detection method.  Before the real contents of sparse
9995 file are stored, @command{tar} needs to gather knowledge about file
9996 sparseness.  This is because it needs to have the file's map of holes
9997 stored into tar header before it starts archiving the file contents.
9998 Currently, two methods of hole detection are implemented:
10000 @itemize @bullet
10001 @item @option{--hole-detection=seek}
10002 Seeking the file for data and holes.  It uses enhancement of the @code{lseek}
10003 system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
10004 reuse file system knowledge about sparse file contents - so the
10005 detection is usually very fast.  To use this feature, your file system
10006 and operating system must support it.  At the time of this writing
10007 (2015) this feature, in spite of not being accepted by POSIX, is
10008 fairly widely supported by different operating systems.
10010 @item @option{--hole-detection=raw}
10011 Reading byte-by-byte the whole sparse file before the archiving.  This
10012 method detects holes like consecutive stretches of zeroes.  Comparing to
10013 the previous method, it is usually much slower, although more
10014 portable.
10015 @end itemize
10016 @end table
10018 When no @option{--hole-detection} option is given, @command{tar} uses
10019 the @samp{seek}, if supported by the operating system.
10021 Using @option{--hole-detection} option implies @option{--sparse}.
10023 @node Attributes
10024 @section Handling File Attributes
10025 @cindex attributes, files
10026 @cindex file attributes
10028 When @command{tar} reads files, it updates their access times.  To
10029 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
10030 reset the access time retroactively or avoid changing it in the first
10031 place.
10033 @table @option
10034 @opindex atime-preserve
10035 @item --atime-preserve
10036 @itemx --atime-preserve=replace
10037 @itemx --atime-preserve=system
10038 Preserve the access times of files that are read.  This works only for
10039 files that you own, unless you have superuser privileges.
10041 @option{--atime-preserve=replace} works on most systems, but it also
10042 restores the data modification time and updates the status change
10043 time.  Hence it doesn't interact with incremental dumps nicely
10044 (@pxref{Incremental Dumps}), and it can set access or data modification times
10045 incorrectly if other programs access the file while @command{tar} is
10046 running.
10048 @option{--atime-preserve=system} avoids changing the access time in
10049 the first place, if the operating system supports this.
10050 Unfortunately, this may or may not work on any given operating system
10051 or file system.  If @command{tar} knows for sure it won't work, it
10052 complains right away.
10054 Currently @option{--atime-preserve} with no operand defaults to
10055 @option{--atime-preserve=replace}, but this is intended to change to
10056 @option{--atime-preserve=system} when the latter is better-supported.
10058 @opindex touch
10059 @item -m
10060 @itemx --touch
10061 Do not extract data modification time.
10063 When this option is used, @command{tar} leaves the data modification times
10064 of the files it extracts as the times when the files were extracted,
10065 instead of setting it to the times recorded in the archive.
10067 This option is meaningless with @option{--list} (@option{-t}).
10069 @opindex same-owner
10070 @item --same-owner
10071 Create extracted files with the same ownership they have in the
10072 archive.
10074 This is the default behavior for the superuser,
10075 so this option is meaningful only for non-root users, when @command{tar}
10076 is executed on those systems able to give files away.  This is
10077 considered as a security flaw by many people, at least because it
10078 makes quite difficult to correctly account users for the disk space
10079 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
10080 files are easily and silently lost when files are given away.
10082 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
10083 separately.  If it can't find a user name (because the user @acronym{ID} is not
10084 in @file{/etc/passwd}), then it does not write one.  When restoring,
10085 it tries to look the name (if one was written) up in
10086 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
10087 the archive instead.
10089 @opindex no-same-owner
10090 @item --no-same-owner
10091 @itemx -o
10092 Do not attempt to restore ownership when extracting.  This is the
10093 default behavior for ordinary users, so this option has an effect
10094 only for the superuser.
10096 @opindex numeric-owner
10097 @item --numeric-owner
10098 The @option{--numeric-owner} option allows (ANSI) archives to be written
10099 without user/group name information or such information to be ignored
10100 when extracting.  It effectively disables the generation and/or use
10101 of user/group name information.  This option forces extraction using
10102 the numeric ids from the archive, ignoring the names.
10104 This is useful in certain circumstances, when restoring a backup from
10105 an emergency floppy with different passwd/group files for example.
10106 It is otherwise impossible to extract files with the right ownerships
10107 if the password file in use during the extraction does not match the
10108 one belonging to the file system(s) being extracted.  This occurs,
10109 for example, if you are restoring your files after a major crash and
10110 had booted from an emergency floppy with no password file or put your
10111 disk into another machine to do the restore.
10113 The numeric ids are @emph{always} saved into @command{tar} archives.
10114 The identifying names are added at create time when provided by the
10115 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
10116 used when moving archives between a collection of machines using
10117 a centralized management for attribution of numeric ids to users
10118 and groups.  This is often made through using the NIS capabilities.
10120 When making a @command{tar} file for distribution to other sites, it
10121 is sometimes cleaner to use a single owner for all files in the
10122 distribution, and nicer to specify the write permission bits of the
10123 files as stored in the archive independently of their actual value on
10124 the file system.  The way to prepare a clean distribution is usually
10125 to have some Makefile rule creating a directory, copying all needed
10126 files in that directory, then setting ownership and permissions as
10127 wanted (there are a lot of possible schemes), and only then making a
10128 @command{tar} archive out of this directory, before cleaning
10129 everything out.  Of course, we could add a lot of options to
10130 @GNUTAR{} for fine tuning permissions and ownership.
10131 This is not the good way, I think.  @GNUTAR{} is
10132 already crowded with options and moreover, the approach just explained
10133 gives you a great deal of control already.
10135 @xopindex{same-permissions, short description}
10136 @xopindex{preserve-permissions, short description}
10137 @item -p
10138 @itemx --same-permissions
10139 @itemx --preserve-permissions
10140 Extract all protection information.
10142 This option causes @command{tar} to set the modes (access permissions) of
10143 extracted files exactly as recorded in the archive.  If this option
10144 is not used, the current @code{umask} setting limits the permissions
10145 on extracted files.  This option is by default enabled when
10146 @command{tar} is executed by a superuser.
10149 This option is meaningless with @option{--list} (@option{-t}).
10150 @end table
10152 @node Portability
10153 @section Making @command{tar} Archives More Portable
10155 Creating a @command{tar} archive on a particular system that is meant to be
10156 useful later on many other machines and with other versions of @command{tar}
10157 is more challenging than you might think.  @command{tar} archive formats
10158 have been evolving since the first versions of Unix.  Many such formats
10159 are around, and are not always compatible with each other.  This section
10160 discusses a few problems, and gives some advice about making @command{tar}
10161 archives more portable.
10163 One golden rule is simplicity.  For example, limit your @command{tar}
10164 archives to contain only regular files and directories, avoiding
10165 other kind of special files.  Do not attempt to save sparse files or
10166 contiguous files as such.  Let's discuss a few more problems, in turn.
10168 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
10169 archives and archive labels) in GNU and PAX formats.}
10171 @menu
10172 * Portable Names::              Portable Names
10173 * dereference::                 Symbolic Links
10174 * hard links::                  Hard Links
10175 * old::                         Old V7 Archives
10176 * ustar::                       Ustar Archives
10177 * gnu::                         GNU and old GNU format archives.
10178 * posix::                       @acronym{POSIX} archives
10179 * Checksumming::                Checksumming Problems
10180 * Large or Negative Values::    Large files, negative time stamps, etc.
10181 * Other Tars::                  How to Extract GNU-Specific Data Using
10182                                 Other @command{tar} Implementations
10183 @end menu
10185 @node Portable Names
10186 @subsection Portable Names
10188 Use portable file and member names.  A name is portable if it contains
10189 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
10190 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
10191 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
10192 old Unix hosts, limit your file name components to 14 characters or
10193 less.
10195 If you intend to have your @command{tar} archives to be read under
10196 MSDOS, you should not rely on case distinction for file names, and you
10197 might use the @acronym{GNU} @command{doschk} program for helping you
10198 further diagnosing illegal MSDOS names, which are even more limited
10199 than System V's.
10201 @node dereference
10202 @subsection Symbolic Links
10203 @cindex File names, using symbolic links
10204 @cindex Symbolic link as file name
10206 @opindex dereference
10207 Normally, when @command{tar} archives a symbolic link, it writes a
10208 block to the archive naming the target of the link.  In that way, the
10209 @command{tar} archive is a faithful record of the file system contents.
10210 When @option{--dereference} (@option{-h}) is used with
10211 @option{--create} (@option{-c}), @command{tar} archives the files
10212 symbolic links point to, instead of
10213 the links themselves.
10215 When creating portable archives, use @option{--dereference}
10216 (@option{-h}): some systems do not support
10217 symbolic links, and moreover, your distribution might be unusable if
10218 it contains unresolved symbolic links.
10220 When reading from an archive, the @option{--dereference} (@option{-h})
10221 option causes @command{tar} to follow an already-existing symbolic
10222 link when @command{tar} writes or reads a file named in the archive.
10223 Ordinarily, @command{tar} does not follow such a link, though it may
10224 remove the link before writing a new file.  @xref{Dealing with Old
10225 Files}.
10227 The @option{--dereference} option is unsafe if an untrusted user can
10228 modify directories while @command{tar} is running.  @xref{Security}.
10230 @node hard links
10231 @subsection Hard Links
10232 @cindex File names, using hard links
10233 @cindex hard links, dereferencing
10234 @cindex dereferencing hard links
10236 Normally, when @command{tar} archives a hard link, it writes a
10237 block to the archive naming the target of the link (a @samp{1} type
10238 block).  In that way, the actual file contents is stored in file only
10239 once.  For example, consider the following two files:
10241 @smallexample
10242 @group
10243 $ ls -l
10244 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
10245 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
10246 @end group
10247 @end smallexample
10249 Here, @file{jeden} is a link to @file{one}.  When archiving this
10250 directory with a verbose level 2, you will get an output similar to
10251 the following:
10253 @smallexample
10254 $ tar cvvf ../archive.tar .
10255 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10256 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10257 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
10258 @end smallexample
10260 The last line shows that, instead of storing two copies of the file,
10261 @command{tar} stored it only once, under the name @file{jeden}, and
10262 stored file @file{one} as a hard link to this file.
10264 It may be important to know that all hard links to the given file are
10265 stored in the archive.  For example, this may be necessary for exact
10266 reproduction of the file system.  The following option does that:
10268 @table @option
10269 @xopindex{check-links, described}
10270 @item --check-links
10271 @itemx -l
10272 Check the number of links dumped for each processed file.  If this
10273 number does not match the total number of hard links for the file, print
10274 a warning message.
10275 @end table
10277 For example, trying to archive only file @file{jeden} with this option
10278 produces the following diagnostics:
10280 @smallexample
10281 $ tar -c -f ../archive.tar -l jeden
10282 tar: Missing links to 'jeden'.
10283 @end smallexample
10285 Although creating special records for hard links helps keep a faithful
10286 record of the file system contents and makes archives more compact, it
10287 may present some difficulties when extracting individual members from
10288 the archive.  For example, trying to extract file @file{one} from the
10289 archive created in previous examples produces, in the absence of file
10290 @file{jeden}:
10292 @smallexample
10293 $ tar xf archive.tar ./one
10294 tar: ./one: Cannot hard link to './jeden': No such file or directory
10295 tar: Error exit delayed from previous errors
10296 @end smallexample
10298 The reason for this behavior is that @command{tar} cannot seek back in
10299 the archive to the previous member (in this case, @file{one}), to
10300 extract it@footnote{There are plans to fix this in future releases.}.
10301 If you wish to avoid such problems at the cost of a bigger archive,
10302 use the following option:
10304 @table @option
10305 @xopindex{hard-dereference, described}
10306 @item --hard-dereference
10307 Dereference hard links and store the files they refer to.
10308 @end table
10310 For example, trying this option on our two sample files, we get two
10311 copies in the archive, each of which can then be extracted
10312 independently of the other:
10314 @smallexample
10315 @group
10316 $ tar -c -vv -f ../archive.tar --hard-dereference .
10317 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10318 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10319 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
10320 @end group
10321 @end smallexample
10323 @node old
10324 @subsection Old V7 Archives
10325 @cindex Format, old style
10326 @cindex Old style format
10327 @cindex Old style archives
10328 @cindex v7 archive format
10330 Certain old versions of @command{tar} cannot handle additional
10331 information recorded by newer @command{tar} programs.  To create an
10332 archive in V7 format (not ANSI), which can be read by these old
10333 versions, specify the @option{--format=v7} option in
10334 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
10335 accepts @option{--portability} or @option{--old-archive} for this
10336 option).  When you specify it,
10337 @command{tar} leaves out information about directories, pipes, fifos,
10338 contiguous files, and device files, and specifies file ownership by
10339 group and user IDs instead of group and user names.
10341 When updating an archive, do not use @option{--format=v7}
10342 unless the archive was created using this option.
10344 In most cases, a @emph{new} format archive can be read by an @emph{old}
10345 @command{tar} program without serious trouble, so this option should
10346 seldom be needed.  On the other hand, most modern @command{tar}s are
10347 able to read old format archives, so it might be safer for you to
10348 always use @option{--format=v7} for your distributions.  Notice,
10349 however, that @samp{ustar} format is a better alternative, as it is
10350 free from many of @samp{v7}'s drawbacks.
10352 @node ustar
10353 @subsection Ustar Archive Format
10355 @cindex ustar archive format
10356 The archive format defined by the @acronym{POSIX}.1-1988 specification is
10357 called @code{ustar}.  Although it is more flexible than the V7 format, it
10358 still has many restrictions (@pxref{Formats,ustar}, for the detailed
10359 description of @code{ustar} format).  Along with V7 format,
10360 @code{ustar} format is a good choice for archives intended to be read
10361 with other implementations of @command{tar}.
10363 To create an archive in @code{ustar} format, use the @option{--format=ustar}
10364 option in conjunction with @option{--create} (@option{-c}).
10366 @node gnu
10367 @subsection @acronym{GNU} and old @GNUTAR{} format
10369 @cindex GNU archive format
10370 @cindex Old GNU archive format
10371 @GNUTAR{} was based on an early draft of the
10372 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
10373 @command{tar}, such as the support for file names longer than 100
10374 characters, use portions of the @command{tar} header record which were
10375 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
10376 @acronym{POSIX} have allocated the same parts of the header record for
10377 other purposes.  As a result, @GNUTAR{} format is
10378 incompatible with the current @acronym{POSIX} specification, and with
10379 @command{tar} programs that follow it.
10381 In the majority of cases, @command{tar} will be configured to create
10382 this format by default.  This will change in future releases, since
10383 we plan to make @samp{POSIX} format the default.
10385 To force creation a @GNUTAR{} archive, use option
10386 @option{--format=gnu}.
10388 @node posix
10389 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
10391 @cindex POSIX archive format
10392 @cindex PAX archive format
10393 Starting from version 1.14 @GNUTAR{} features full support for
10394 @acronym{POSIX.1-2001} archives.
10396 A @acronym{POSIX} conformant archive will be created if @command{tar}
10397 was given @option{--format=posix} (@option{--format=pax}) option.  No
10398 special option is required to read and extract from a @acronym{POSIX}
10399 archive.
10401 @menu
10402 * PAX keywords:: Controlling Extended Header Keywords.
10403 @end menu
10405 @node PAX keywords
10406 @subsubsection Controlling Extended Header Keywords
10408 @table @option
10409 @opindex pax-option
10410 @item --pax-option=@var{keyword-list}
10411 Handle keywords in @acronym{PAX} extended headers.  This option is
10412 equivalent to @option{-o} option of the @command{pax} utility.
10413 @end table
10415 @var{Keyword-list} is a comma-separated
10416 list of keyword options, each keyword option taking one of
10417 the following forms:
10419 @table @code
10420 @item delete=@var{pattern}
10421 When used with one of archive-creation commands,
10422 this option instructs @command{tar} to omit from extended header records
10423 that it produces any keywords matching the string @var{pattern}.
10425 When used in extract or list mode, this option instructs tar
10426 to ignore any keywords matching the given @var{pattern} in the extended
10427 header records.  In both cases, matching is performed using the pattern
10428 matching notation described in @acronym{POSIX 1003.2}, 3.13
10429 (@pxref{wildcards}).  For example:
10431 @smallexample
10432 --pax-option delete=security.*
10433 @end smallexample
10435 would suppress security-related information.
10437 @item exthdr.name=@var{string}
10439 This keyword allows user control over the name that is written into the
10440 ustar header blocks for the extended headers.  The name is obtained
10441 from @var{string} after making the following substitutions:
10443 @multitable @columnfractions .25 .55
10444 @headitem Meta-character @tab Replaced By
10445 @item %d @tab  The directory name of the file, equivalent to the
10446 result of the @command{dirname} utility on the translated file name.
10447 @item %f @tab  The name of the file with the directory information
10448 stripped, equivalent to the result of the @command{basename} utility
10449 on the translated file name.
10450 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
10451 @item %% @tab  A @samp{%} character.
10452 @end multitable
10454 Any other @samp{%} characters in @var{string} produce undefined
10455 results.
10457 If no option @samp{exthdr.name=string} is specified, @command{tar}
10458 will use the following default value:
10460 @smallexample
10461 %d/PaxHeaders.%p/%f
10462 @end smallexample
10464 @item exthdr.mtime=@var{value}
10466 This keyword defines the value of the @samp{mtime} field that
10467 is written into the ustar header blocks for the extended headers.
10468 By default, the @samp{mtime} field is set to the modification time
10469 of the archive member described by that extended header (or to the
10470 value of the @option{--mtime} option, if supplied).
10472 @item globexthdr.name=@var{string}
10473 This keyword allows user control over the name that is written into
10474 the ustar header blocks for global extended header records.  The name
10475 is obtained from the contents of @var{string}, after making
10476 the following substitutions:
10478 @multitable @columnfractions .25 .55
10479 @headitem Meta-character @tab Replaced By
10480 @item %n @tab An integer that represents the
10481 sequence number of the global extended header record in the archive,
10482 starting at 1.
10483 @item %p @tab The process @acronym{ID} of the @command{tar} process.
10484 @item %% @tab A @samp{%} character.
10485 @end multitable
10487 Any other @samp{%} characters in @var{string} produce undefined results.
10489 If no option @samp{globexthdr.name=string} is specified, @command{tar}
10490 will use the following default value:
10492 @smallexample
10493 $TMPDIR/GlobalHead.%p.%n
10494 @end smallexample
10496 @noindent
10497 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
10498 environment variable.  If @var{TMPDIR} is not set, @command{tar}
10499 uses @samp{/tmp}.
10501 @item globexthdr.mtime=@var{value}
10503 This keyword defines the value of the @samp{mtime} field that
10504 is written into the ustar header blocks for the global extended headers.
10505 By default, the @samp{mtime} field is set to the time when
10506 @command{tar} was invoked.
10508 @item @var{keyword}=@var{value}
10509 When used with one of archive-creation commands, these keyword/value pairs
10510 will be included at the beginning of the archive in a global extended
10511 header record.  When used with one of archive-reading commands,
10512 @command{tar} will behave as if it has encountered these keyword/value
10513 pairs at the beginning of the archive in a global extended header
10514 record.
10516 @item @var{keyword}:=@var{value}
10517 When used with one of archive-creation commands, these keyword/value pairs
10518 will be included as records at the beginning of an extended header for
10519 each file.  This is effectively equivalent to @var{keyword}=@var{value}
10520 form except that it creates no global extended header records.
10522 When used with one of archive-reading commands, @command{tar} will
10523 behave as if these keyword/value pairs were included as records at the
10524 end of each extended header; thus, they will override any global or
10525 file-specific extended header record keywords of the same names.
10526 For example, in the command:
10528 @smallexample
10529 tar --format=posix --create \
10530     --file archive --pax-option gname:=user .
10531 @end smallexample
10533 the group name will be forced to a new value for all files
10534 stored in the archive.
10535 @end table
10537 In any of the forms described above, the @var{value} may be
10538 a string enclosed in curly braces.  In that case, the string
10539 between the braces is understood either as a textual time
10540 representation, as described in @ref{Date input formats}, or a name of
10541 the existing file, starting with @samp{/} or @samp{.}.  In the latter
10542 case, the modification time of that file is used.
10544 For example, to set all modification times to the current date, you
10545 use the following option:
10547 @smallexample
10548 --pax-option='mtime:=@{now@}'
10549 @end smallexample
10551 Note quoting of the option's argument.
10553 @cindex archives, binary equivalent
10554 @cindex binary equivalent archives, creating
10555 As another example, here is the option that ensures that any two
10556 archives created using it, will be binary equivalent if they have the
10557 same contents:
10559 @smallexample
10560 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
10561 @end smallexample
10563 @noindent
10564 If you extract files from such an archive and recreate the archive
10565 from them, you will also need to eliminate changes due to ctime, as
10566 shown in examples below:
10568 @smallexample
10569 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,ctime:=0
10570 @end smallexample
10572 @noindent
10575 @smallexample
10576 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,delete=ctime
10577 @end smallexample
10579 @node Checksumming
10580 @subsection Checksumming Problems
10582 SunOS and HP-UX @command{tar} fail to accept archives created using
10583 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
10584 is, file names having characters with the eighth bit set, because they
10585 use signed checksums, while @GNUTAR{} uses unsigned
10586 checksums while creating archives, as per @acronym{POSIX} standards.  On
10587 reading, @GNUTAR{} computes both checksums and accepts either of them.
10588 It is somewhat worrying that a lot of people may go
10589 around doing backup of their files using faulty (or at least
10590 non-standard) software, not learning about it until it's time to
10591 restore their missing files with an incompatible file extractor, or
10592 vice versa.
10594 @GNUTAR{} computes checksums both ways, and accepts either of them
10595 on read, so @acronym{GNU} tar can read Sun tapes even with their
10596 wrong checksums.  @GNUTAR{} produces the standard
10597 checksum, however, raising incompatibilities with Sun.  That is to
10598 say, @GNUTAR{} has not been modified to
10599 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
10600 I've been told that more recent Sun @command{tar} now read standard
10601 archives, so maybe Sun did a similar patch, after all?
10603 The story seems to be that when Sun first imported @command{tar}
10604 sources on their system, they recompiled it without realizing that
10605 the checksums were computed differently, because of a change in
10606 the default signing of @code{char}'s in their compiler.  So they
10607 started computing checksums wrongly.  When they later realized their
10608 mistake, they merely decided to stay compatible with it, and with
10609 themselves afterwards.  Presumably, but I do not really know, HP-UX
10610 has chosen their @command{tar} archives to be compatible with Sun's.
10611 The current standards do not favor Sun @command{tar} format.  In any
10612 case, it now falls on the shoulders of SunOS and HP-UX users to get
10613 a @command{tar} able to read the good archives they receive.
10615 @node Large or Negative Values
10616 @subsection Large or Negative Values
10617 @cindex large values
10618 @cindex future time stamps
10619 @cindex negative time stamps
10620 @UNREVISED
10622 The above sections suggest to use @samp{oldest possible} archive
10623 format if in doubt.  However, sometimes it is not possible.  If you
10624 attempt to archive a file whose metadata cannot be represented using
10625 required format, @GNUTAR{} will print error message and ignore such a
10626 file.  You will than have to switch to a format that is able to
10627 handle such values.  The format summary table (@pxref{Formats}) will
10628 help you to do so.
10630 In particular, when trying to archive files larger than 8GB or with
10631 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
10632 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
10633 @acronym{POSIX} archive formats.  When considering which format to
10634 choose, bear in mind that the @acronym{GNU} format uses
10635 two's-complement base-256 notation to store values that do not fit
10636 into standard @acronym{ustar} range.  Such archives can generally be
10637 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
10638 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
10639 example, using two's complement representation for negative time
10640 stamps that assumes a signed 32-bit @code{time_t} generates archives
10641 that are not portable to hosts with differing @code{time_t}
10642 representations.
10644 On the other hand, @acronym{POSIX} archives, generally speaking, can
10645 be extracted by any tar implementation that understands older
10646 @acronym{ustar} format.  The only exception are files larger than 8GB.
10648 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
10649 POSIX-aware tars.}
10651 @node Other Tars
10652 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
10654 In previous sections you became acquainted with various quirks
10655 necessary to make your archives portable.  Sometimes you may need to
10656 extract archives containing GNU-specific members using some
10657 third-party @command{tar} implementation or an older version of
10658 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
10659 but if it is for some reason impossible, this section will explain
10660 how to cope without it.
10662 When we speak about @dfn{GNU-specific} members we mean two classes of
10663 them: members split between the volumes of a multi-volume archive and
10664 sparse members.  You will be able to always recover such members if
10665 the archive is in PAX format.  In addition split members can be
10666 recovered from archives in old GNU format.  The following subsections
10667 describe the required procedures in detail.
10669 @menu
10670 * Split Recovery::       Members Split Between Volumes
10671 * Sparse Recovery::      Sparse Members
10672 @end menu
10674 @node Split Recovery
10675 @subsubsection Extracting Members Split Between Volumes
10677 @cindex Multi-volume archives, extracting using non-GNU tars
10678 If a member is split between several volumes of an old GNU format archive
10679 most third party @command{tar} implementation will fail to extract
10680 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
10681 This program is available from
10682 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
10683 home page}.  It concatenates several archive volumes into a single
10684 valid archive.  For example, if you have three volumes named from
10685 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
10686 extract them using a third-party @command{tar}:
10688 @smallexample
10689 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
10690 @end smallexample
10692 @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
10693 You could use this approach for most (although not all) PAX
10694 format archives as well.  However, extracting split members from a PAX
10695 archive is a much easier task, because PAX volumes are constructed in
10696 such a way that each part of a split member is extracted to a
10697 different file by @command{tar} implementations that are not aware of
10698 GNU extensions.  More specifically, the very first part retains its
10699 original name, and all subsequent parts are named using the pattern:
10701 @smallexample
10702 %d/GNUFileParts.%p/%f.%n
10703 @end smallexample
10705 @noindent
10706 where symbols preceded by @samp{%} are @dfn{macro characters} that
10707 have the following meaning:
10709 @multitable @columnfractions .25 .55
10710 @headitem Meta-character @tab Replaced By
10711 @item %d @tab  The directory name of the file, equivalent to the
10712 result of the @command{dirname} utility on its full name.
10713 @item %f @tab  The file name of the file, equivalent to the result
10714 of the @command{basename} utility on its full name.
10715 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
10716 created the archive.
10717 @item %n @tab  Ordinal number of this particular part.
10718 @end multitable
10720 For example, if the file @file{var/longfile} was split during archive
10721 creation between three volumes, and the creator @command{tar} process
10722 had process @acronym{ID} @samp{27962}, then the member names will be:
10724 @smallexample
10725 var/longfile
10726 var/GNUFileParts.27962/longfile.1
10727 var/GNUFileParts.27962/longfile.2
10728 @end smallexample
10730 When you extract your archive using a third-party @command{tar}, these
10731 files will be created on your disk, and the only thing you will need
10732 to do to restore your file in its original form is concatenate them in
10733 the proper order, for example:
10735 @smallexample
10736 @group
10737 $ @kbd{cd var}
10738 $ @kbd{cat GNUFileParts.27962/longfile.1 \
10739   GNUFileParts.27962/longfile.2 >> longfile}
10740 $ rm -f GNUFileParts.27962
10741 @end group
10742 @end smallexample
10744 Notice, that if the @command{tar} implementation you use supports PAX
10745 format archives, it will probably emit warnings about unknown keywords
10746 during extraction.  They will look like this:
10748 @smallexample
10749 @group
10750 Tar file too small
10751 Unknown extended header keyword 'GNU.volume.filename' ignored.
10752 Unknown extended header keyword 'GNU.volume.size' ignored.
10753 Unknown extended header keyword 'GNU.volume.offset' ignored.
10754 @end group
10755 @end smallexample
10757 @noindent
10758 You can safely ignore these warnings.
10760 If your @command{tar} implementation is not PAX-aware, you will get
10761 more warnings and more files generated on your disk, e.g.:
10763 @smallexample
10764 @group
10765 $ @kbd{tar xf vol-1.tar}
10766 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
10767 normal file
10768 Unexpected EOF in archive
10769 $ @kbd{tar xf vol-2.tar}
10770 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
10771 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
10772 'x', extracted as normal file
10773 @end group
10774 @end smallexample
10776 Ignore these warnings.  The @file{PaxHeaders.*} directories created
10777 will contain files with @dfn{extended header keywords} describing the
10778 extracted files.  You can delete them, unless they describe sparse
10779 members.  Read further to learn more about them.
10781 @node Sparse Recovery
10782 @subsubsection Extracting Sparse Members
10784 @cindex sparse files, extracting with non-GNU tars
10785 Any @command{tar} implementation will be able to extract sparse members from a
10786 PAX archive.  However, the extracted files will be @dfn{condensed},
10787 i.e., any zero blocks will be removed from them.  When we restore such
10788 a condensed file to its original form, by adding zero blocks (or
10789 @dfn{holes}) back to their original locations, we call this process
10790 @dfn{expanding} a compressed sparse file.
10792 @pindex xsparse
10793 To expand a file, you will need a simple auxiliary program called
10794 @command{xsparse}.  It is available in source form from
10795 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10796 home page}.
10798 @cindex sparse files v.1.0, extracting with non-GNU tars
10799 Let's begin with archive members in @dfn{sparse format
10800 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10801 The condensed file will contain both file map and file data, so no
10802 additional data will be needed to restore it.  If the original file
10803 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10804 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10805 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10806 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10807 archive (@pxref{PAX keywords}).}.
10809 To expand a version 1.0 file, run @command{xsparse} as follows:
10811 @smallexample
10812 $ @kbd{xsparse @file{cond-file}}
10813 @end smallexample
10815 @noindent
10816 where @file{cond-file} is the name of the condensed file.  The utility
10817 will deduce the name for the resulting expanded file using the
10818 following algorithm:
10820 @enumerate 1
10821 @item If @file{cond-file} does not contain any directories,
10822 @file{../cond-file} will be used;
10824 @item If @file{cond-file} has the form
10825 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10826 are simple names, with no @samp{/} characters in them, the output file
10827 name will be @file{@var{dir}/@var{name}}.
10829 @item Otherwise, if @file{cond-file} has the form
10830 @file{@var{dir}/@var{name}}, the output file name will be
10831 @file{@var{name}}.
10832 @end enumerate
10834 In the unlikely case when this algorithm does not suit your needs,
10835 you can explicitly specify output file name as a second argument to
10836 the command:
10838 @smallexample
10839 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10840 @end smallexample
10842 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10843 first.  In this mode, the command does not actually expand the file,
10844 but verbosely lists all actions it would be taking to do so.  The dry
10845 run mode is enabled by @option{-n} command line argument:
10847 @smallexample
10848 @group
10849 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10850 Reading v.1.0 sparse map
10851 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10852 '/home/gray/sparsefile'
10853 Finished dry run
10854 @end group
10855 @end smallexample
10857 To actually expand the file, you would run:
10859 @smallexample
10860 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10861 @end smallexample
10863 @noindent
10864 The program behaves the same way all UNIX utilities do: it will keep
10865 quiet unless it has something important to tell you (e.g. an error
10866 condition or something).  If you wish it to produce verbose output,
10867 similar to that from the dry run mode, use @option{-v} option:
10869 @smallexample
10870 @group
10871 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10872 Reading v.1.0 sparse map
10873 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10874 '/home/gray/sparsefile'
10875 Done
10876 @end group
10877 @end smallexample
10879 Additionally, if your @command{tar} implementation has extracted the
10880 @dfn{extended headers} for this file, you can instruct @command{xstar}
10881 to use them in order to verify the integrity of the expanded file.
10882 The option @option{-x} sets the name of the extended header file to
10883 use.  Continuing our example:
10885 @smallexample
10886 @group
10887 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10888   /home/gray/GNUSparseFile.6058/sparsefile}
10889 Reading extended header file
10890 Found variable GNU.sparse.major = 1
10891 Found variable GNU.sparse.minor = 0
10892 Found variable GNU.sparse.name = sparsefile
10893 Found variable GNU.sparse.realsize = 217481216
10894 Reading v.1.0 sparse map
10895 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10896 '/home/gray/sparsefile'
10897 Done
10898 @end group
10899 @end smallexample
10901 @anchor{extracting sparse v0x}
10902 @cindex sparse files v.0.1, extracting with non-GNU tars
10903 @cindex sparse files v.0.0, extracting with non-GNU tars
10904 An @dfn{extended header} is a special @command{tar} archive header
10905 that precedes an archive member and contains a set of
10906 @dfn{variables}, describing the member properties that cannot be
10907 stored in the standard @code{ustar} header.  While optional for
10908 expanding sparse version 1.0 members, the use of extended headers is
10909 mandatory when expanding sparse members in older sparse formats: v.0.0
10910 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10911 Formats}.)  So, for these formats, the question is: how to obtain
10912 extended headers from the archive?
10914 If you use a @command{tar} implementation that does not support PAX
10915 format, extended headers for each member will be extracted as a
10916 separate file.  If we represent the member name as
10917 @file{@var{dir}/@var{name}}, then the extended header file will be
10918 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10919 @var{n} is an integer number.
10921 Things become more difficult if your @command{tar} implementation
10922 does support PAX headers, because in this case you will have to
10923 manually extract the headers.  We recommend the following algorithm:
10925 @enumerate 1
10926 @item
10927 Consult the documentation of your @command{tar} implementation for an
10928 option that prints @dfn{block numbers} along with the archive
10929 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
10930 @command{star} has @option{-block-number}.
10932 @item
10933 Obtain verbose listing using the @samp{block number} option, and
10934 find block numbers of the sparse member in question and the member
10935 immediately following it.  For example, running @command{star} on our
10936 archive we obtain:
10938 @smallexample
10939 @group
10940 $ @kbd{star -t -v -block-number -f arc.tar}
10941 @dots{}
10942 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10943 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10944 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10945 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10946 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10947 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
10948 @dots{}
10949 @end group
10950 @end smallexample
10952 @noindent
10953 (as usual, ignore the warnings about unknown keywords.)
10955 @item
10956 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10957 and @var{Bn} be the block number of the next member.
10958 Compute:
10960 @smallexample
10961 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10962 @end smallexample
10964 @noindent
10965 This number gives the size of the extended header part in tar @dfn{blocks}.
10966 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10967 = 7}.
10969 @item
10970 Use @command{dd} to extract the headers:
10972 @smallexample
10973 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10974 @end smallexample
10976 @noindent
10977 where @var{archive} is the archive name, @var{hname} is a name of the
10978 file to store the extended header in, @var{Bs} and @var{N} are
10979 computed in previous steps.
10981 In our example, this command will be
10983 @smallexample
10984 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10985 @end smallexample
10986 @end enumerate
10988 Finally, you can expand the condensed file, using the obtained header:
10990 @smallexample
10991 @group
10992 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10993 Reading extended header file
10994 Found variable GNU.sparse.size = 217481216
10995 Found variable GNU.sparse.numblocks = 208
10996 Found variable GNU.sparse.name = sparsefile
10997 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10998 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
10999 Done
11000 @end group
11001 @end smallexample
11003 @node cpio
11004 @section Comparison of @command{tar} and @command{cpio}
11005 @UNREVISED
11007 @FIXME{Reorganize the following material}
11009 The @command{cpio} archive formats, like @command{tar}, do have maximum
11010 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
11011 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
11012 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
11013 with arbitrary file name lengths, but other @command{cpio} implementations
11014 may crash unexplainedly trying to read them.
11016 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
11017 @command{cpio} doesn't handle symbolic links in the form in which it comes
11018 in System V prior to SVR4, and some vendors may have added symlinks
11019 to their system without enhancing @command{cpio} to know about them.
11020 Others may have enhanced it in a way other than the way I did it
11021 at Sun, and which was adopted by AT&T (and which is, I think, also
11022 present in the @command{cpio} that Berkeley picked up from AT&T and put
11023 into a later @acronym{BSD} release---I think I gave them my changes).
11025 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
11026 can handle @command{tar} format input, and write it on output, and it
11027 probably handles symbolic links.  They may not have bothered doing
11028 anything to enhance @command{tar} as a result.)
11030 @command{cpio} handles special files; traditional @command{tar} doesn't.
11032 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
11033 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
11034 (4.3-tahoe and later).
11036 @command{tar}'s way of handling multiple hard links to a file can handle
11037 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
11038 @command{cpio}s way requires you to play some games (in its ``binary''
11039 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
11040 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
11041 field of the header to make sure that the file system @acronym{ID}/i-number pairs
11042 of different files were always different), and I don't know which
11043 @command{cpio}s, if any, play those games.  Those that don't might get
11044 confused and think two files are the same file when they're not, and
11045 make hard links between them.
11047 @command{tar}s way of handling multiple hard links to a file places only
11048 one copy of the link on the tape, but the name attached to that copy
11049 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
11050 way puts one copy for every link, but you can retrieve it using any
11051 of the names.
11053 @quotation
11054 What type of check sum (if any) is used, and how is this calculated.
11055 @end quotation
11057 See the attached manual pages for @command{tar} and @command{cpio} format.
11058 @command{tar} uses a checksum which is the sum of all the bytes in the
11059 @command{tar} header for a file; @command{cpio} uses no checksum.
11061 @quotation
11062 If anyone knows why @command{cpio} was made when @command{tar} was present
11063 at the unix scene,
11064 @end quotation
11066 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
11067 generally-available version of UNIX had @command{tar} at the time.  I don't
11068 know whether any version that was generally available @emph{within AT&T}
11069 had @command{tar}, or, if so, whether the people within AT&T who did
11070 @command{cpio} knew about it.
11072 On restore, if there is a corruption on a tape @command{tar} will stop at
11073 that point, while @command{cpio} will skip over it and try to restore the
11074 rest of the files.
11076 The main difference is just in the command syntax and header format.
11078 @command{tar} is a little more tape-oriented in that everything is blocked
11079 to start on a record boundary.
11081 @quotation
11082 Is there any differences between the ability to recover crashed
11083 archives between the two of them.  (Is there any chance of recovering
11084 crashed archives at all.)
11085 @end quotation
11087 Theoretically it should be easier under @command{tar} since the blocking
11088 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
11089 However, modern @command{cpio}'s and variations have an option to just
11090 search for the next file header after an error with a reasonable chance
11091 of resyncing.  However, lots of tape driver software won't allow you to
11092 continue past a media error which should be the only reason for getting
11093 out of sync unless a file changed sizes while you were writing the
11094 archive.
11096 @quotation
11097 If anyone knows why @command{cpio} was made when @command{tar} was present
11098 at the unix scene, please tell me about this too.
11099 @end quotation
11101 Probably because it is more media efficient (by not blocking everything
11102 and using only the space needed for the headers where @command{tar}
11103 always uses 512 bytes per file header) and it knows how to archive
11104 special files.
11106 You might want to look at the freely available alternatives.  The
11107 major ones are @command{afio}, @GNUTAR{}, and
11108 @command{pax}, each of which have their own extensions with some
11109 backwards compatibility.
11111 Sparse files were @command{tar}red as sparse files (which you can
11112 easily test, because the resulting archive gets smaller, and
11113 @acronym{GNU} @command{cpio} can no longer read it).
11115 @node Media
11116 @chapter Tapes and Other Archive Media
11117 @UNREVISED
11119 A few special cases about tape handling warrant more detailed
11120 description.  These special cases are discussed below.
11122 Many complexities surround the use of @command{tar} on tape drives.  Since
11123 the creation and manipulation of archives located on magnetic tape was
11124 the original purpose of @command{tar}, it contains many features making
11125 such manipulation easier.
11127 Archives are usually written on dismountable media---tape cartridges,
11128 mag tapes, or floppy disks.
11130 The amount of data a tape or disk holds depends not only on its size,
11131 but also on how it is formatted.  A 2400 foot long reel of mag tape
11132 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
11133 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
11135 Magnetic media are re-usable---once the archive on a tape is no longer
11136 needed, the archive can be erased and the tape or disk used over.
11137 Media quality does deteriorate with use, however.  Most tapes or disks
11138 should be discarded when they begin to produce data errors.  EXABYTE
11139 tape cartridges should be discarded when they generate an @dfn{error
11140 count} (number of non-usable bits) of more than 10k.
11142 Magnetic media are written and erased using magnetic fields, and
11143 should be protected from such fields to avoid damage to stored data.
11144 Sticking a floppy disk to a filing cabinet using a magnet is probably
11145 not a good idea.
11147 @menu
11148 * Device::                      Device selection and switching
11149 * Remote Tape Server::
11150 * Common Problems and Solutions::
11151 * Blocking::                    Blocking
11152 * Many::                        Many archives on one tape
11153 * Using Multiple Tapes::        Using Multiple Tapes
11154 * label::                       Including a Label in the Archive
11155 * verify::
11156 * Write Protection::
11157 @end menu
11159 @node Device
11160 @section Device Selection and Switching
11161 @UNREVISED
11163 @table @option
11164 @item -f [@var{hostname}:]@var{file}
11165 @itemx --file=[@var{hostname}:]@var{file}
11166 Use archive file or device @var{file} on @var{hostname}.
11167 @end table
11169 This option is used to specify the file name of the archive @command{tar}
11170 works on.
11172 If the file name is @samp{-}, @command{tar} reads the archive from standard
11173 input (when listing or extracting), or writes it to standard output
11174 (when creating).  If the @samp{-} file name is given when updating an
11175 archive, @command{tar} will read the original archive from its standard
11176 input, and will write the entire new archive to its standard output.
11178 If the file name contains a @samp{:}, it is interpreted as
11179 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
11180 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
11181 either case, @command{tar} will invoke the command @command{rsh} (or
11182 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
11183 machine.  If you give an alternate login name, it will be given to the
11184 @command{rsh}.
11185 Naturally, the remote machine must have an executable
11186 @command{/usr/libexec/rmt}.  This program is free software from the
11187 University of California, and a copy of the source code can be found
11188 with the sources for @command{tar}; it's compiled and installed by default.
11189 The exact path to this utility is determined when configuring the package.
11190 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
11191 your installation prefix.  This location may also be overridden at
11192 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
11193 ---rmt-command}, for detailed description of this option.  @xref{Remote
11194 Tape Server}, for the description of @command{rmt} command).
11196 If this option is not given, but the environment variable @env{TAPE}
11197 is set, its value is used; otherwise, old versions of @command{tar}
11198 used a default archive name (which was picked when @command{tar} was
11199 compiled).  The default is normally set up to be the @dfn{first} tape
11200 drive or other transportable I/O medium on the system.
11202 Starting with version 1.11.5, @GNUTAR{} uses
11203 standard input and standard output as the default device, and I will
11204 not try anymore supporting automatic device detection at installation
11205 time.  This was failing really in too many cases, it was hopeless.
11206 This is now completely left to the installer to override standard
11207 input and standard output for default device, if this seems
11208 preferable.  Further, I think @emph{most} actual usages of
11209 @command{tar} are done with pipes or disks, not really tapes,
11210 cartridges or diskettes.
11212 Some users think that using standard input and output is running
11213 after trouble.  This could lead to a nasty surprise on your screen if
11214 you forget to specify an output file name---especially if you are going
11215 through a network or terminal server capable of buffering large amounts
11216 of output.  We had so many bug reports in that area of configuring
11217 default tapes automatically, and so many contradicting requests, that
11218 we finally consider the problem to be portably intractable.  We could
11219 of course use something like @samp{/dev/tape} as a default, but this
11220 is @emph{also} running after various kind of trouble, going from hung
11221 processes to accidental destruction of real tapes.  After having seen
11222 all this mess, using standard input and output as a default really
11223 sounds like the only clean choice left, and a very useful one too.
11225 @GNUTAR{} reads and writes archive in records, I
11226 suspect this is the main reason why block devices are preferred over
11227 character devices.  Most probably, block devices are more efficient
11228 too.  The installer could also check for @samp{DEFTAPE} in
11229 @file{<sys/mtio.h>}.
11231 @table @option
11232 @xopindex{force-local, short description}
11233 @item --force-local
11234 Archive file is local even if it contains a colon.
11236 @opindex rsh-command
11237 @item --rsh-command=@var{command}
11238 Use remote @var{command} instead of @command{rsh}.  This option exists
11239 so that people who use something other than the standard @command{rsh}
11240 (e.g., a Kerberized @command{rsh}) can access a remote device.
11242 When this command is not used, the shell command found when
11243 the @command{tar} program was installed is used instead.  This is
11244 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
11245 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
11246 The installer may have overridden this by defining the environment
11247 variable @env{RSH} @emph{at installation time}.
11249 @item -[0-7][lmh]
11250 Specify drive and density.
11252 @xopindex{multi-volume, short description}
11253 @item -M
11254 @itemx --multi-volume
11255 Create/list/extract multi-volume archive.
11257 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
11258 that may be larger than will fit on the medium used to hold it.
11259 @xref{Multi-Volume Archives}.
11261 @xopindex{tape-length, short description}
11262 @item -L @var{num}
11263 @itemx --tape-length=@var{size}[@var{suf}]
11264 Change tape after writing @var{size} units of data.  Unless @var{suf} is
11265 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
11266 1024} bytes.  The following suffixes alter this behavior:
11268 @float Table, size-suffixes
11269 @caption{Size Suffixes}
11270 @multitable @columnfractions 0.2 0.3 0.3
11271 @headitem Suffix @tab Units            @tab Byte Equivalent
11272 @item b          @tab Blocks           @tab @var{size} x 512
11273 @item B          @tab Kilobytes        @tab @var{size} x 1024
11274 @item c          @tab Bytes            @tab @var{size}
11275 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
11276 @item K          @tab Kilobytes        @tab @var{size} x 1024
11277 @item k          @tab Kilobytes        @tab @var{size} x 1024
11278 @item M          @tab Megabytes        @tab @var{size} x 1024^2
11279 @item P          @tab Petabytes        @tab @var{size} x 1024^5
11280 @item T          @tab Terabytes        @tab @var{size} x 1024^4
11281 @item w          @tab Words            @tab @var{size} x 2
11282 @end multitable
11283 @end float
11285 This option might be useful when your tape drivers do not properly
11286 detect end of physical tapes.  By being slightly conservative on the
11287 maximum tape length, you might avoid the problem entirely.
11289 @xopindex{info-script, short description}
11290 @xopindex{new-volume-script, short description}
11291 @item -F @var{command}
11292 @itemx --info-script=@var{command}
11293 @itemx --new-volume-script=@var{command}
11294 Execute @var{command} at end of each tape.  This implies
11295 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
11296 description of this option.
11297 @end table
11299 @node Remote Tape Server
11300 @section Remote Tape Server
11302 @cindex remote tape drive
11303 @pindex rmt
11304 In order to access the tape drive on a remote machine, @command{tar}
11305 uses the remote tape server written at the University of California at
11306 Berkeley.  The remote tape server must be installed as
11307 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
11308 want to use.  @command{tar} calls @command{rmt} by running an
11309 @command{rsh} or @command{remsh} to the remote machine, optionally
11310 using a different login name if one is supplied.
11312 A copy of the source for the remote tape server is provided.  Its
11313 source code can be freely distributed.  It is compiled and
11314 installed by default.
11316 @cindex absolute file names
11317 Unless you use the @option{--absolute-names} (@option{-P}) option,
11318 @GNUTAR{} will not allow you to create an archive that contains
11319 absolute file names (a file name beginning with @samp{/}).  If you try,
11320 @command{tar} will automatically remove the leading @samp{/} from the
11321 file names it stores in the archive.  It will also type a warning
11322 message telling you what it is doing.
11324 When reading an archive that was created with a different
11325 @command{tar} program, @GNUTAR{} automatically
11326 extracts entries in the archive which have absolute file names as if
11327 the file names were not absolute.  This is an important feature.  A
11328 visitor here once gave a @command{tar} tape to an operator to restore;
11329 the operator used Sun @command{tar} instead of @GNUTAR{},
11330 and the result was that it replaced large portions of
11331 our @file{/bin} and friends with versions from the tape; needless to
11332 say, we were unhappy about having to recover the file system from
11333 backup tapes.
11335 For example, if the archive contained a file @file{/usr/bin/computoy},
11336 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
11337 relative to the current directory.  If you want to extract the files in
11338 an archive to the same absolute names that they had when the archive
11339 was created, you should do a @samp{cd /} before extracting the files
11340 from the archive, or you should either use the @option{--absolute-names}
11341 option, or use the command @samp{tar -C / @dots{}}.
11343 @cindex Ultrix 3.1 and write failure
11344 Some versions of Unix (Ultrix 3.1 is known to have this problem),
11345 can claim that a short write near the end of a tape succeeded,
11346 when it actually failed.  This will result in the -M option not
11347 working correctly.  The best workaround at the moment is to use a
11348 significantly larger blocking factor than the default 20.
11350 In order to update an archive, @command{tar} must be able to backspace the
11351 archive in order to reread or rewrite a record that was just read (or
11352 written).  This is currently possible only on two kinds of files: normal
11353 disk files (or any other file that can be backspaced with @samp{lseek}),
11354 and industry-standard 9-track magnetic tape (or any other kind of tape
11355 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
11357 This means that the @option{--append}, @option{--concatenate}, and
11358 @option{--delete} commands will not work on any other kind of file.
11359 Some media simply cannot be backspaced, which means these commands and
11360 options will never be able to work on them.  These non-backspacing
11361 media include pipes and cartridge tape drives.
11363 Some other media can be backspaced, and @command{tar} will work on them
11364 once @command{tar} is modified to do so.
11366 Archives created with the @option{--multi-volume}, @option{--label}, and
11367 @option{--incremental} (@option{-G}) options may not be readable by other version
11368 of @command{tar}.  In particular, restoring a file that was split over
11369 a volume boundary will require some careful work with @command{dd}, if
11370 it can be done at all.  Other versions of @command{tar} may also create
11371 an empty file whose name is that of the volume header.  Some versions
11372 of @command{tar} may create normal files instead of directories archived
11373 with the @option{--incremental} (@option{-G}) option.
11375 @node Common Problems and Solutions
11376 @section Some Common Problems and their Solutions
11378 @ifclear PUBLISH
11380 @format
11381 errors from system:
11382 permission denied
11383 no such file or directory
11384 not owner
11386 errors from @command{tar}:
11387 directory checksum error
11388 header format error
11390 errors from media/system:
11391 i/o error
11392 device busy
11393 @end format
11395 @end ifclear
11397 @node Blocking
11398 @section Blocking
11399 @cindex block
11400 @cindex record
11402 @dfn{Block} and @dfn{record} terminology is rather confused, and it
11403 is also confusing to the expert reader.  On the other hand, readers
11404 who are new to the field have a fresh mind, and they may safely skip
11405 the next two paragraphs, as the remainder of this manual uses those
11406 two terms in a quite consistent way.
11408 John Gilmore, the writer of the public domain @command{tar} from which
11409 @GNUTAR{} was originally derived, wrote (June 1995):
11411 @quotation
11412 The nomenclature of tape drives comes from IBM, where I believe
11413 they were invented for the IBM 650 or so.  On IBM mainframes, what
11414 is recorded on tape are tape blocks.  The logical organization of
11415 data is into records.  There are various ways of putting records into
11416 blocks, including @code{F} (fixed sized records), @code{V} (variable
11417 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
11418 to a block), @code{VB} (variable size records, @var{n} to a block),
11419 @code{VSB} (variable spanned blocked: variable sized records that can
11420 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
11421 parameter specified this to the operating system.
11423 The Unix man page on @command{tar} was totally confused about this.
11424 When I wrote @code{PD TAR}, I used the historically correct terminology
11425 (@command{tar} writes data records, which are grouped into blocks).
11426 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
11427 here), and now Fran@,{c}ois has migrated that terminology back
11428 into the source code too.
11429 @end quotation
11431 The term @dfn{physical block} means the basic transfer chunk from or
11432 to a device, after which reading or writing may stop without anything
11433 being lost.  In this manual, the term @dfn{block} usually refers to
11434 a disk physical block, @emph{assuming} that each disk block is 512
11435 bytes in length.  It is true that some disk devices have different
11436 physical blocks, but @command{tar} ignore these differences in its own
11437 format, which is meant to be portable, so a @command{tar} block is always
11438 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
11439 The term @dfn{logical block} often represents the basic chunk of
11440 allocation of many disk blocks as a single entity, which the operating
11441 system treats somewhat atomically; this concept is only barely used
11442 in @GNUTAR{}.
11444 The term @dfn{physical record} is another way to speak of a physical
11445 block, those two terms are somewhat interchangeable.  In this manual,
11446 the term @dfn{record} usually refers to a tape physical block,
11447 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
11448 It is true that archives may be put on disk or used with pipes,
11449 but nevertheless, @command{tar} tries to read and write the archive one
11450 @dfn{record} at a time, whatever the medium in use.  One record is made
11451 up of an integral number of blocks, and this operation of putting many
11452 disk blocks into a single tape block is called @dfn{reblocking}, or
11453 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
11454 the logical organization of many characters into something meaningful
11455 to the application.  The term @dfn{unit record} describes a small set
11456 of characters which are transmitted whole to or by the application,
11457 and often refers to a line of text.  Those two last terms are unrelated
11458 to what we call a @dfn{record} in @GNUTAR{}.
11460 When writing to tapes, @command{tar} writes the contents of the archive
11461 in chunks known as @dfn{records}.  To change the default blocking
11462 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
11463 @var{512-size}}) option.  Each record will then be composed of
11464 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
11465 @xref{Standard}.)  Each file written to the archive uses at least one
11466 full record.  As a result, using a larger record size can result in
11467 more wasted space for small files.  On the other hand, a larger record
11468 size can often be read and written much more efficiently.
11470 Further complicating the problem is that some tape drives ignore the
11471 blocking entirely.  For these, a larger record size can still improve
11472 performance (because the software layers above the tape drive still
11473 honor the blocking), but not as dramatically as on tape drives that
11474 honor blocking.
11476 When reading an archive, @command{tar} can usually figure out the
11477 record size on itself.  When this is the case, and a non-standard
11478 record size was used when the archive was created, @command{tar} will
11479 print a message about a non-standard blocking factor, and then operate
11480 normally@footnote{If this message is not needed, you can turn it off
11481 using the @option{--warning=no-record-size} option.}.  On some tape
11482 devices, however, @command{tar} cannot figure out the record size
11483 itself.  On most of those, you can specify a blocking factor (with
11484 @option{--blocking-factor}) larger than the actual blocking factor,
11485 and then use the @option{--read-full-records} (@option{-B}) option.
11486 (If you specify a blocking factor with @option{--blocking-factor} and
11487 don't use the @option{--read-full-records} option, then @command{tar}
11488 will not attempt to figure out the recording size itself.)  On some
11489 devices, you must always specify the record size exactly with
11490 @option{--blocking-factor} when reading, because @command{tar} cannot
11491 figure it out.  In any case, use @option{--list} (@option{-t}) before
11492 doing any extractions to see whether @command{tar} is reading the archive
11493 correctly.
11495 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
11496 putting them into records is to put a whole number of them (one or
11497 more) into each record.  @command{tar} records are all the same size;
11498 at the end of the file there's a block containing all zeros, which
11499 is how you tell that the remainder of the last record(s) are garbage.
11501 In a standard @command{tar} file (no options), the block size is 512
11502 and the record size is 10240, for a blocking factor of 20.  What the
11503 @option{--blocking-factor} option does is sets the blocking factor,
11504 changing the record size while leaving the block size at 512 bytes.
11505 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
11506 most tape drives these days prefer much bigger records in order to
11507 stream and not waste tape.  When writing tapes for myself, some tend
11508 to use a factor of the order of 2048, say, giving a record size of
11509 around one megabyte.
11511 If you use a blocking factor larger than 20, older @command{tar}
11512 programs might not be able to read the archive, so we recommend this
11513 as a limit to use in practice.  @GNUTAR{}, however,
11514 will support arbitrarily large record sizes, limited only by the
11515 amount of virtual memory or the physical characteristics of the tape
11516 device.
11518 @menu
11519 * Format Variations::           Format Variations
11520 * Blocking Factor::             The Blocking Factor of an Archive
11521 @end menu
11523 @node Format Variations
11524 @subsection Format Variations
11525 @cindex Format Parameters
11526 @cindex Format Options
11527 @cindex Options, archive format specifying
11528 @cindex Options, format specifying
11529 @UNREVISED
11531 Format parameters specify how an archive is written on the archive
11532 media.  The best choice of format parameters will vary depending on
11533 the type and number of files being archived, and on the media used to
11534 store the archive.
11536 To specify format parameters when accessing or creating an archive,
11537 you can use the options described in the following sections.
11538 If you do not specify any format parameters, @command{tar} uses
11539 default parameters.  You cannot modify a compressed archive.
11540 If you create an archive with the @option{--blocking-factor} option
11541 specified (@pxref{Blocking Factor}), you must specify that
11542 blocking-factor when operating on the archive.  @xref{Formats}, for other
11543 examples of format parameter considerations.
11545 @node Blocking Factor
11546 @subsection The Blocking Factor of an Archive
11547 @cindex Blocking Factor
11548 @cindex Record Size
11549 @cindex Number of blocks per record
11550 @cindex Number of bytes per record
11551 @cindex Bytes per record
11552 @cindex Blocks per record
11553 @UNREVISED
11555 @opindex blocking-factor
11556 The data in an archive is grouped into blocks, which are 512 bytes.
11557 Blocks are read and written in whole number multiples called
11558 @dfn{records}.  The number of blocks in a record (i.e., the size of a
11559 record in units of 512 bytes) is called the @dfn{blocking factor}.
11560 The @option{--blocking-factor=@var{512-size}} (@option{-b
11561 @var{512-size}}) option specifies the blocking factor of an archive.
11562 The default blocking factor is typically 20 (i.e., 10240 bytes), but
11563 can be specified at installation.  To find out the blocking factor of
11564 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
11565 This may not work on some devices.
11567 Records are separated by gaps, which waste space on the archive media.
11568 If you are archiving on magnetic tape, using a larger blocking factor
11569 (and therefore larger records) provides faster throughput and allows you
11570 to fit more data on a tape (because there are fewer gaps).  If you are
11571 archiving on cartridge, a very large blocking factor (say 126 or more)
11572 greatly increases performance.  A smaller blocking factor, on the other
11573 hand, may be useful when archiving small files, to avoid archiving lots
11574 of nulls as @command{tar} fills out the archive to the end of the record.
11575 In general, the ideal record size depends on the size of the
11576 inter-record gaps on the tape you are using, and the average size of the
11577 files you are archiving.  @xref{create}, for information on
11578 writing archives.
11580 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
11582 Archives with blocking factors larger than 20 cannot be read
11583 by very old versions of @command{tar}, or by some newer versions
11584 of @command{tar} running on old machines with small address spaces.
11585 With @GNUTAR{}, the blocking factor of an archive is limited
11586 only by the maximum record size of the device containing the archive,
11587 or by the amount of available virtual memory.
11589 Also, on some systems, not using adequate blocking factors, as sometimes
11590 imposed by the device drivers, may yield unexpected diagnostics.  For
11591 example, this has been reported:
11593 @smallexample
11594 Cannot write to /dev/dlt: Invalid argument
11595 @end smallexample
11597 @noindent
11598 In such cases, it sometimes happen that the @command{tar} bundled by
11599 the system is aware of block size idiosyncrasies, while @GNUTAR{}
11600 requires an explicit specification for the block size,
11601 which it cannot guess.  This yields some people to consider
11602 @GNUTAR{} is misbehaving, because by comparison,
11603 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
11604 for example, might resolve the problem.
11606 If you use a non-default blocking factor when you create an archive, you
11607 must specify the same blocking factor when you modify that archive.  Some
11608 archive devices will also require you to specify the blocking factor when
11609 reading that archive, however this is not typically the case.  Usually, you
11610 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
11611 reports a non-default record size and then lists the archive members as
11612 it would normally.  To extract files from an archive with a non-standard
11613 blocking factor (particularly if you're not sure what the blocking factor
11614 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
11615 specifying a blocking factor larger then the blocking factor of the archive
11616 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
11617 @xref{list}, for more information on the @option{--list} (@option{-t})
11618 operation.  @xref{Reading}, for a more detailed explanation of that option.
11620 @table @option
11621 @item --blocking-factor=@var{number}
11622 @itemx -b @var{number}
11623 Specifies the blocking factor of an archive.  Can be used with any
11624 operation, but is usually not necessary with @option{--list} (@option{-t}).
11625 @end table
11627 Device blocking
11629 @table @option
11630 @item -b @var{blocks}
11631 @itemx --blocking-factor=@var{blocks}
11632 Set record size to @math{@var{blocks}*512} bytes.
11634 This option is used to specify a @dfn{blocking factor} for the archive.
11635 When reading or writing the archive, @command{tar}, will do reads and writes
11636 of the archive in records of @math{@var{block}*512} bytes.  This is true
11637 even when the archive is compressed.  Some devices requires that all
11638 write operations be a multiple of a certain size, and so, @command{tar}
11639 pads the archive out to the next record boundary.
11641 The default blocking factor is set when @command{tar} is compiled, and is
11642 typically 20.  Blocking factors larger than 20 cannot be read by very
11643 old versions of @command{tar}, or by some newer versions of @command{tar}
11644 running on old machines with small address spaces.
11646 With a magnetic tape, larger records give faster throughput and fit
11647 more data on a tape (because there are fewer inter-record gaps).
11648 If the archive is in a disk file or a pipe, you may want to specify
11649 a smaller blocking factor, since a large one will result in a large
11650 number of null bytes at the end of the archive.
11652 When writing cartridge or other streaming tapes, a much larger
11653 blocking factor (say 126 or more) will greatly increase performance.
11654 However, you must specify the same blocking factor when reading or
11655 updating the archive.
11657 Apparently, Exabyte drives have a physical block size of 8K bytes.
11658 If we choose our blocksize as a multiple of 8k bytes, then the problem
11659 seems to disappear.  Id est, we are using block size of 112 right
11660 now, and we haven't had the problem since we switched@dots{}
11662 With @GNUTAR{} the blocking factor is limited only
11663 by the maximum record size of the device containing the archive, or by
11664 the amount of available virtual memory.
11666 However, deblocking or reblocking is virtually avoided in a special
11667 case which often occurs in practice, but which requires all the
11668 following conditions to be simultaneously true:
11669 @itemize @bullet
11670 @item
11671 the archive is subject to a compression option,
11672 @item
11673 the archive is not handled through standard input or output, nor
11674 redirected nor piped,
11675 @item
11676 the archive is directly handled to a local disk, instead of any special
11677 device,
11678 @item
11679 @option{--blocking-factor} is not explicitly specified on the @command{tar}
11680 invocation.
11681 @end itemize
11683 If the output goes directly to a local disk, and not through
11684 stdout, then the last write is not extended to a full record size.
11685 Otherwise, reblocking occurs.  Here are a few other remarks on this
11686 topic:
11688 @itemize @bullet
11690 @item
11691 @command{gzip} will complain about trailing garbage if asked to
11692 uncompress a compressed archive on tape, there is an option to turn
11693 the message off, but it breaks the regularity of simply having to use
11694 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
11695 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
11696 Gailly, by sending a copy of this message to him.
11698 @item
11699 @command{compress} does not show this problem, but as Jean-loup pointed
11700 out to Michael, @samp{compress -d} silently adds garbage after
11701 the result of decompression, which tar ignores because it already
11702 recognized its end-of-file indicator.  So this bug may be safely
11703 ignored.
11705 @item
11706 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
11707 but will still return an exit status of 2 which tar reports in turn.
11708 @command{tar} might ignore the exit status returned, but I hate doing
11709 that, as it weakens the protection @command{tar} offers users against
11710 other possible problems at decompression time.  If @command{gzip} was
11711 silently skipping trailing zeros @emph{and} also avoiding setting the
11712 exit status in this innocuous case, that would solve this situation.
11714 @item
11715 @command{tar} should become more solid at not stopping to read a pipe at
11716 the first null block encountered.  This inelegantly breaks the pipe.
11717 @command{tar} should rather drain the pipe out before exiting itself.
11718 @end itemize
11720 @xopindex{ignore-zeros, short description}
11721 @item -i
11722 @itemx --ignore-zeros
11723 Ignore blocks of zeros in archive (means EOF).
11725 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
11726 of zeros in the archive.  Normally a block of zeros indicates the
11727 end of the archive, but when reading a damaged archive, or one which
11728 was created by concatenating several archives together, this option
11729 allows @command{tar} to read the entire archive.  This option is not on
11730 by default because many versions of @command{tar} write garbage after
11731 the zeroed blocks.
11733 Note that this option causes @command{tar} to read to the end of the
11734 archive file, which may sometimes avoid problems when multiple files
11735 are stored on a single physical tape.
11737 @xopindex{read-full-records, short description}
11738 @item -B
11739 @itemx --read-full-records
11740 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
11742 If @option{--read-full-records} is used, @command{tar}
11743 will not panic if an attempt to read a record from the archive does
11744 not return a full record.  Instead, @command{tar} will keep reading
11745 until it has obtained a full
11746 record.
11748 This option is turned on by default when @command{tar} is reading
11749 an archive from standard input, or from a remote machine.  This is
11750 because on @acronym{BSD} Unix systems, a read of a pipe will return however
11751 much happens to be in the pipe, even if it is less than @command{tar}
11752 requested.  If this option was not used, @command{tar} would fail as
11753 soon as it read an incomplete record from the pipe.
11755 This option is also useful with the commands for updating an archive.
11757 @end table
11759 Tape blocking
11761 @FIXME{Appropriate options should be moved here from elsewhere.}
11763 @cindex blocking factor
11764 @cindex tape blocking
11766 When handling various tapes or cartridges, you have to take care of
11767 selecting a proper blocking, that is, the number of disk blocks you
11768 put together as a single tape block on the tape, without intervening
11769 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
11770 with no information on it, used for decelerating the tape to a
11771 full stop, and for later regaining the reading or writing speed.
11772 When the tape driver starts reading a record, the record has to
11773 be read whole without stopping, as a tape gap is needed to stop the
11774 tape motion without losing information.
11776 @cindex Exabyte blocking
11777 @cindex DAT blocking
11778 Using higher blocking (putting more disk blocks per tape block) will use
11779 the tape more efficiently as there will be less tape gaps.  But reading
11780 such tapes may be more difficult for the system, as more memory will be
11781 required to receive at once the whole record.  Further, if there is a
11782 reading error on a huge record, this is less likely that the system will
11783 succeed in recovering the information.  So, blocking should not be too
11784 low, nor it should be too high.  @command{tar} uses by default a blocking of
11785 20 for historical reasons, and it does not really matter when reading or
11786 writing to disk.  Current tape technology would easily accommodate higher
11787 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11788 We were told that for some DLT drives, the blocking should be a multiple
11789 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11790 Other manufacturers may use different recommendations for the same tapes.
11791 This might also depends of the buffering techniques used inside modern
11792 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
11793 Others request blocking to be some exponent of two.
11795 So, there is no fixed rule for blocking.  But blocking at read time
11796 should ideally be the same as blocking used at write time.  At one place
11797 I know, with a wide variety of equipment, they found it best to use a
11798 blocking of 32 to guarantee that their tapes are fully interchangeable.
11800 I was also told that, for recycled tapes, prior erasure (by the same
11801 drive unit that will be used to create the archives) sometimes lowers
11802 the error rates observed at rewriting time.
11804 I might also use @option{--number-blocks} instead of
11805 @option{--block-number}, so @option{--block} will then expand to
11806 @option{--blocking-factor} unambiguously.
11808 @node Many
11809 @section Many Archives on One Tape
11811 @FIXME{Appropriate options should be moved here from elsewhere.}
11813 @findex ntape @r{device}
11814 Most tape devices have two entries in the @file{/dev} directory, or
11815 entries that come in pairs, which differ only in the minor number for
11816 this device.  Let's take for example @file{/dev/tape}, which often
11817 points to the only or usual tape device of a given system.  There might
11818 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
11819 name is the @emph{rewinding} version of the device, while the name
11820 having @samp{nr} in it is the @emph{no rewinding} version of the same
11821 device.
11823 A rewinding tape device will bring back the tape to its beginning point
11824 automatically when this device is opened or closed.  Since @command{tar}
11825 opens the archive file before using it and closes it afterwards, this
11826 means that a simple:
11828 @smallexample
11829 $ @kbd{tar cf /dev/tape @var{directory}}
11830 @end smallexample
11832 @noindent
11833 will reposition the tape to its beginning both prior and after saving
11834 @var{directory} contents to it, thus erasing prior tape contents and
11835 making it so that any subsequent write operation will destroy what has
11836 just been saved.
11838 @cindex tape positioning
11839 So, a rewinding device is normally meant to hold one and only one file.
11840 If you want to put more than one @command{tar} archive on a given tape, you
11841 will need to avoid using the rewinding version of the tape device.  You
11842 will also have to pay special attention to tape positioning.  Errors in
11843 positioning may overwrite the valuable data already on your tape.  Many
11844 people, burnt by past experiences, will only use rewinding devices and
11845 limit themselves to one file per tape, precisely to avoid the risk of
11846 such errors.  Be fully aware that writing at the wrong position on a
11847 tape loses all information past this point and most probably until the
11848 end of the tape, and this destroyed information @emph{cannot} be
11849 recovered.
11851 To save @var{directory-1} as a first archive at the beginning of a
11852 tape, and leave that tape ready for a second archive, you should use:
11854 @smallexample
11855 $ @kbd{mt -f /dev/nrtape rewind}
11856 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11857 @end smallexample
11859 @cindex tape marks
11860 @dfn{Tape marks} are special magnetic patterns written on the tape
11861 media, which are later recognizable by the reading hardware.  These
11862 marks are used after each file, when there are many on a single tape.
11863 An empty file (that is to say, two tape marks in a row) signal the
11864 logical end of the tape, after which no file exist.  Usually,
11865 non-rewinding tape device drivers will react to the close request issued
11866 by @command{tar} by first writing two tape marks after your archive, and by
11867 backspacing over one of these.  So, if you remove the tape at that time
11868 from the tape drive, it is properly terminated.  But if you write
11869 another file at the current position, the second tape mark will be
11870 erased by the new information, leaving only one tape mark between files.
11872 So, you may now save @var{directory-2} as a second archive after the
11873 first on the same tape by issuing the command:
11875 @smallexample
11876 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11877 @end smallexample
11879 @noindent
11880 and so on for all the archives you want to put on the same tape.
11882 Another usual case is that you do not write all the archives the same
11883 day, and you need to remove and store the tape between two archive
11884 sessions.  In general, you must remember how many files are already
11885 saved on your tape.  Suppose your tape already has 16 files on it, and
11886 that you are ready to write the 17th.  You have to take care of skipping
11887 the first 16 tape marks before saving @var{directory-17}, say, by using
11888 these commands:
11890 @smallexample
11891 $ @kbd{mt -f /dev/nrtape rewind}
11892 $ @kbd{mt -f /dev/nrtape fsf 16}
11893 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11894 @end smallexample
11896 In all the previous examples, we put aside blocking considerations, but
11897 you should do the proper things for that as well.  @xref{Blocking}.
11899 @menu
11900 * Tape Positioning::            Tape Positions and Tape Marks
11901 * mt::                          The @command{mt} Utility
11902 @end menu
11904 @node Tape Positioning
11905 @subsection Tape Positions and Tape Marks
11906 @UNREVISED
11908 Just as archives can store more than one file from the file system,
11909 tapes can store more than one archive file.  To keep track of where
11910 archive files (or any other type of file stored on tape) begin and
11911 end, tape archive devices write magnetic @dfn{tape marks} on the
11912 archive media.  Tape drives write one tape mark between files,
11913 two at the end of all the file entries.
11915 If you think of data as a series of records "rrrr"'s, and tape marks as
11916 "*"'s, a tape might look like the following:
11918 @smallexample
11919 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11920 @end smallexample
11922 Tape devices read and write tapes using a read/write @dfn{tape
11923 head}---a physical part of the device which can only access one
11924 point on the tape at a time.  When you use @command{tar} to read or
11925 write archive data from a tape device, the device will begin reading
11926 or writing from wherever on the tape the tape head happens to be,
11927 regardless of which archive or what part of the archive the tape
11928 head is on.  Before writing an archive, you should make sure that no
11929 data on the tape will be overwritten (unless it is no longer needed).
11930 Before reading an archive, you should make sure the tape head is at
11931 the beginning of the archive you want to read.  You can do it manually
11932 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
11933 that automatically (@pxref{Scripted Restoration}).
11935 If you want to add new archive file entries to a tape, you should
11936 advance the tape to the end of the existing file entries, backspace
11937 over the last tape mark, and write the new archive file.  If you were
11938 to add two archives to the example above, the tape might look like the
11939 following:
11941 @smallexample
11942 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11943 @end smallexample
11945 @node mt
11946 @subsection The @command{mt} Utility
11947 @UNREVISED
11949 @FIXME{Is it true that this only works on non-block devices?
11950 should explain the difference, (fixed or variable).}
11951 @xref{Blocking Factor}.
11953 You can use the @command{mt} utility to advance or rewind a tape past a
11954 specified number of archive files on the tape.  This will allow you
11955 to move to the beginning of an archive before extracting or reading
11956 it, or to the end of all the archives before writing a new one.
11957 @FIXME{Why isn't there an "advance 'til you find two tape marks
11958 together"?}
11960 The syntax of the @command{mt} command is:
11962 @smallexample
11963 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11964 @end smallexample
11966 where @var{tapename} is the name of the tape device, @var{number} is
11967 the number of times an operation is performed (with a default of one),
11968 and @var{operation} is one of the following:
11970 @FIXME{is there any use for record operations?}
11972 @table @option
11973 @item eof
11974 @itemx weof
11975 Writes @var{number} tape marks at the current position on the tape.
11977 @item fsf
11978 Moves tape position forward @var{number} files.
11980 @item bsf
11981 Moves tape position back @var{number} files.
11983 @item rewind
11984 Rewinds the tape.  (Ignores @var{number}.)
11986 @item offline
11987 @itemx rewoff1
11988 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
11990 @item status
11991 Prints status information about the tape unit.
11993 @end table
11995 If you don't specify a @var{tapename}, @command{mt} uses the environment
11996 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11997 the default device specified in your @file{sys/mtio.h} file
11998 (@code{DEFTAPE} variable).  If this is not defined, the program will
11999 display a descriptive error message and exit with code 1.
12001 @command{mt} returns a 0 exit status when the operation(s) were
12002 successful, 1 if the command was unrecognized, and 2 if an operation
12003 failed.
12005 @node Using Multiple Tapes
12006 @section Using Multiple Tapes
12008 Often you might want to write a large archive, one larger than will fit
12009 on the actual tape you are using.  In such a case, you can run multiple
12010 @command{tar} commands, but this can be inconvenient, particularly if you
12011 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
12012 Therefore, @command{tar} provides a special mode for creating
12013 multi-volume archives.
12015 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
12016 on several media volumes of fixed size.  Although in this section we will
12017 often call @samp{volume} a @dfn{tape}, there is absolutely no
12018 requirement for multi-volume archives to be stored on tapes.  Instead,
12019 they can use whatever media type the user finds convenient, they can
12020 even be located on files.
12022 When creating a multi-volume archive, @GNUTAR{} continues to fill
12023 current volume until it runs out of space, then it switches to
12024 next volume (usually the operator is queried to replace the tape on
12025 this point), and continues working on the new volume.  This operation
12026 continues until all requested files are dumped.  If @GNUTAR{} detects
12027 end of media while dumping a file, such a file is archived in split
12028 form.  Some very big files can even be split across several volumes.
12030 Each volume is itself a valid @GNUTAR{} archive, so it can be read
12031 without any special options.  Consequently any file member residing
12032 entirely on one volume can be extracted or otherwise operated upon
12033 without needing the other volume.  Sure enough, to extract a split
12034 member you would need all volumes its parts reside on.
12036 Multi-volume archives suffer from several limitations.  In particular,
12037 they cannot be compressed.
12039 @GNUTAR{} is able to create multi-volume archives of two formats
12040 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
12042 @menu
12043 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
12044 * Tape Files::                  Tape Files
12045 * Tarcat::                      Concatenate Volumes into a Single Archive
12047 @end menu
12049 @node Multi-Volume Archives
12050 @subsection Archives Longer than One Tape or Disk
12051 @cindex Multi-volume archives
12053 @opindex multi-volume
12054 To create an archive that is larger than will fit on a single unit of
12055 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
12056 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
12057 archive can be manipulated like any other archive (provided the
12058 @option{--multi-volume} option is specified), but is stored on more
12059 than one tape or file.
12061 When you specify @option{--multi-volume}, @command{tar} does not report an
12062 error when it comes to the end of an archive volume (when reading), or
12063 the end of the media (when writing).  Instead, it prompts you to load
12064 a new storage volume.  If the archive is on a magnetic tape, you
12065 should change tapes when you see the prompt; if the archive is on a
12066 floppy disk, you should change disks; etc.
12068 @table @option
12069 @item --multi-volume
12070 @itemx -M
12071 Creates a multi-volume archive, when used in conjunction with
12072 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
12073 archive, specify @option{--multi-volume} in conjunction with that
12074 operation.
12075 For example:
12077 @smallexample
12078 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
12079 @end smallexample
12080 @end table
12082 The method @command{tar} uses to detect end of tape is not perfect, and
12083 fails on some operating systems or on some devices.  If @command{tar}
12084 cannot detect the end of the tape itself, you can use
12085 @option{--tape-length} option to inform it about the capacity of the
12086 tape:
12088 @anchor{tape-length}
12089 @table @option
12090 @opindex tape-length
12091 @item --tape-length=@var{size}[@var{suf}]
12092 @itemx -L @var{size}[@var{suf}]
12093 Set maximum length of a volume.  The @var{suf}, if given, specifies
12094 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
12095 megabytes (@pxref{size-suffixes}, for a list of allowed size
12096 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
12097 assumed.
12099 This option selects @option{--multi-volume} automatically.  For example:
12101 @smallexample
12102 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
12103 @end smallexample
12105 @noindent
12106 or, which is equivalent:
12108 @smallexample
12109 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
12110 @end smallexample
12111 @end table
12113 @anchor{change volume prompt}
12114 When @GNUTAR{} comes to the end of a storage media, it asks you to
12115 change the volume.  The built-in prompt for POSIX locale
12116 is@footnote{If you run @GNUTAR{} under a different locale, the
12117 translation to the locale's language will be used.}:
12119 @smallexample
12120 Prepare volume #@var{n} for '@var{archive}' and hit return:
12121 @end smallexample
12123 @noindent
12124 where @var{n} is the ordinal number of the volume to be created and
12125 @var{archive} is archive file or device name.
12127 When prompting for a new tape, @command{tar} accepts any of the following
12128 responses:
12130 @table @kbd
12131 @item ?
12132 Request @command{tar} to explain possible responses.
12133 @item q
12134 Request @command{tar} to exit immediately.
12135 @item n @var{file-name}
12136 Request @command{tar} to write the next volume on the file @var{file-name}.
12137 @item !
12138 Request @command{tar} to run a subshell.  This option can be disabled
12139 by giving @option{--restrict} command line option to
12140 @command{tar}@footnote{@xref{--restrict}, for more information about
12141 this option.}.
12142 @item y
12143 Request @command{tar} to begin writing the next volume.
12144 @end table
12146 (You should only type @samp{y} after you have changed the tape;
12147 otherwise @command{tar} will write over the volume it just finished.)
12149 @cindex Volume number file
12150 @cindex volno file
12151 @anchor{volno-file}
12152 @opindex volno-file
12153 The volume number used by @command{tar} in its tape-changing prompt
12154 can be changed; if you give the
12155 @option{--volno-file=@var{file-of-number}} option, then
12156 @var{file-of-number} should be an non-existing file to be created, or
12157 else, a file already containing a decimal number.  That number will be
12158 used as the volume number of the first volume written.  When
12159 @command{tar} is finished, it will rewrite the file with the
12160 now-current volume number. (This does not change the volume number
12161 written on a tape label, as per @ref{label}, it @emph{only} affects
12162 the number used in the prompt.)
12164 @cindex End-of-archive info script
12165 @cindex Info script
12166 @anchor{info-script}
12167 @opindex info-script
12168 @opindex new-volume-script
12169 If you want more elaborate behavior than this, you can write a special
12170 @dfn{new volume script}, that will be responsible for changing the
12171 volume, and instruct @command{tar} to use it instead of its normal
12172 prompting procedure:
12174 @table @option
12175 @item --info-script=@var{command}
12176 @itemx --new-volume-script=@var{command}
12177 @itemx -F @var{command}
12178 Specify the command to invoke when switching volumes.  The @var{command}
12179 can be used to eject cassettes, or to broadcast messages such as
12180 @samp{Someone please come change my tape} when performing unattended
12181 backups.
12182 @end table
12184 The @var{command} can contain additional options, if such are needed.
12185 @xref{external, Running External Commands}, for a detailed discussion
12186 of the way @GNUTAR{} runs external commands.  It inherits
12187 @command{tar}'s shell environment.  Additional data is passed to it
12188 via the following environment variables:
12190 @table @env
12191 @vrindex TAR_VERSION, info script environment variable
12192 @item TAR_VERSION
12193 @GNUTAR{} version number.
12195 @vrindex TAR_ARCHIVE, info script environment variable
12196 @item TAR_ARCHIVE
12197 The name of the archive @command{tar} is processing.
12199 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
12200 @item TAR_BLOCKING_FACTOR
12201 Current blocking factor (@pxref{Blocking}).
12203 @vrindex TAR_VOLUME, info script environment variable
12204 @item TAR_VOLUME
12205 Ordinal number of the volume @command{tar} is about to start.
12207 @vrindex TAR_SUBCOMMAND, info script environment variable
12208 @item TAR_SUBCOMMAND
12209 A short option describing the operation @command{tar} is executing.
12210 @xref{Operations}, for a complete list of subcommand options.
12212 @vrindex TAR_FORMAT, info script environment variable
12213 @item TAR_FORMAT
12214 Format of the archive being processed. @xref{Formats}, for a complete
12215 list of archive format names.
12217 @vrindex TAR_FD, info script environment variable
12218 @item TAR_FD
12219 File descriptor which can be used to communicate the new volume
12220 name to @command{tar}.
12221 @end table
12223 These variables can be used in the @var{command} itself, provided that
12224 they are properly quoted to prevent them from being expanded by the
12225 shell that invokes @command{tar}.
12227 The volume script can instruct @command{tar} to use new archive name,
12228 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
12230 If the info script fails, @command{tar} exits; otherwise, it begins
12231 writing the next volume.
12233 If you want @command{tar} to cycle through a series of files or tape
12234 drives, there are three approaches to choose from.  First of all, you
12235 can give @command{tar} multiple @option{--file} options.  In this case
12236 the specified files will be used, in sequence, as the successive
12237 volumes of the archive.  Only when the first one in the sequence needs
12238 to be used again will @command{tar} prompt for a tape change (or run
12239 the info script).  For example, suppose someone has two tape drives on
12240 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
12241 @GNUTAR{} to switch to the second drive when it needs to write the
12242 second tape, and then back to the first tape, etc., just do either of:
12244 @smallexample
12245 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
12246 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
12247 @end smallexample
12249 The second method is to use the @samp{n} response to the tape-change
12250 prompt.
12252 Finally, the most flexible approach is to use a volume script, that
12253 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
12254 following volume script will create a series of archive files, named
12255 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
12256 archive being created (as given by @option{--file} option) and
12257 @var{vol} is the ordinal number of the archive being created:
12259 @smallexample
12260 @group
12261 #! /bin/bash
12262 # For this script it's advisable to use a shell, such as Bash,
12263 # that supports a TAR_FD value greater than 9.
12265 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
12267 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
12268 case $TAR_SUBCOMMAND in
12269 -c)       ;;
12270 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
12271           ;;
12272 *)        exit 1
12273 esac
12275 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
12276 @end group
12277 @end smallexample
12279 The same script can be used while listing, comparing or extracting
12280 from the created archive.  For example:
12282 @smallexample
12283 @group
12284 # @r{Create a multi-volume archive:}
12285 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
12286 # @r{Extract from the created archive:}
12287 $ @kbd{tar -x -f archive.tar -F new-volume .}
12288 @end group
12289 @end smallexample
12291 @noindent
12292 Notice, that the first command had to use @option{-L} option, since
12293 otherwise @GNUTAR{} will end up writing everything to file
12294 @file{archive.tar}.
12296 You can read each individual volume of a multi-volume archive as if it
12297 were an archive by itself.  For example, to list the contents of one
12298 volume, use @option{--list}, without @option{--multi-volume} specified.
12299 To extract an archive member from one volume (assuming it is described
12300 that volume), use @option{--extract}, again without
12301 @option{--multi-volume}.
12303 If an archive member is split across volumes (i.e., its entry begins on
12304 one volume of the media and ends on another), you need to specify
12305 @option{--multi-volume} to extract it successfully.  In this case, you
12306 should load the volume where the archive member starts, and use
12307 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
12308 volumes as it needs them.  @xref{extracting archives}, for more
12309 information about extracting archives.
12311 Multi-volume archives can be modified like any other archive.  To add
12312 files to a multi-volume archive, you need to only mount the last
12313 volume of the archive media (and new volumes, if needed).  For all
12314 other operations, you need to use the entire archive.
12316 If a multi-volume archive was labeled using
12317 @option{--label=@var{archive-label}} (@pxref{label}) when it was
12318 created, @command{tar} will not automatically label volumes which are
12319 added later.  To label subsequent volumes, specify
12320 @option{--label=@var{archive-label}} again in conjunction with the
12321 @option{--append}, @option{--update} or @option{--concatenate} operation.
12323 Notice that multi-volume support is a GNU extension and the archives
12324 created in this mode should be read only using @GNUTAR{}.  If you
12325 absolutely have to process such archives using a third-party @command{tar}
12326 implementation, read @ref{Split Recovery}.
12328 @node Tape Files
12329 @subsection Tape Files
12330 @cindex labeling archives
12331 @opindex label
12332 @UNREVISED
12334 To give the archive a name which will be recorded in it, use the
12335 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
12336 option.  This will write a special block identifying
12337 @var{volume-label} as the name of the archive to the front of the
12338 archive which will be displayed when the archive is listed with
12339 @option{--list}.  If you are creating a multi-volume archive with
12340 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
12341 volume label will have @samp{Volume @var{nnn}} appended to the name
12342 you give, where @var{nnn} is the number of the volume of the archive.
12343 If you use the @option{--label=@var{volume-label}} option when
12344 reading an archive, it checks to make sure the label on the tape
12345 matches the one you gave.  @xref{label}.
12347 When @command{tar} writes an archive to tape, it creates a single
12348 tape file.  If multiple archives are written to the same tape, one
12349 after the other, they each get written as separate tape files.  When
12350 extracting, it is necessary to position the tape at the right place
12351 before running @command{tar}.  To do this, use the @command{mt} command.
12352 For more information on the @command{mt} command and on the organization
12353 of tapes into a sequence of tape files, see @ref{mt}.
12355 People seem to often do:
12357 @smallexample
12358 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
12359 @end smallexample
12361 or such, for pushing a common date in all volumes or an archive set.
12363 @node Tarcat
12364 @subsection Concatenate Volumes into a Single Archive
12366 @pindex tarcat
12367   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
12368 archive to a single @command{tar} archive.  Simply concatenating all
12369 volumes into one will not work, since each volume carries an additional
12370 information at the beginning.  @GNUTAR{} is shipped with the shell
12371 script @command{tarcat} designed for this purpose.
12373   The script takes a list of files comprising a multi-volume archive
12374 and creates the resulting archive at the standard output.  For example:
12376 @smallexample
12377 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
12378 @end smallexample
12380   The script implements a simple heuristics to determine the format of
12381 the first volume file and to decide how to process the rest of the
12382 files.  However, it makes no attempt to verify whether the files are
12383 given in order or even if they are valid @command{tar} archives.
12384 It uses @command{dd} and does not filter its standard error, so you
12385 will usually see lots of spurious messages.
12387 @FIXME{The script is not installed.  Should we install it?}
12389 @node label
12390 @section Including a Label in the Archive
12391 @cindex Labeling an archive
12392 @cindex Labels on the archive media
12393 @cindex Labeling multi-volume archives
12395 @opindex label
12396   To avoid problems caused by misplaced paper labels on the archive
12397 media, you can include a @dfn{label} entry --- an archive member which
12398 contains the name of the archive --- in the archive itself.  Use the
12399 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12400 option@footnote{Until version 1.10, that option was called
12401 @option{--volume}, but is not available under that name anymore.} in
12402 conjunction with the @option{--create} operation to include a label
12403 entry in the archive as it is being created.
12405 @table @option
12406 @item --label=@var{archive-label}
12407 @itemx -V @var{archive-label}
12408 Includes an @dfn{archive-label} at the beginning of the archive when
12409 the archive is being created, when used in conjunction with the
12410 @option{--create} operation.  Checks to make sure the archive label
12411 matches the one specified (when used in conjunction with any other
12412 operation).
12413 @end table
12415   If you create an archive using both
12416 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12417 and @option{--multi-volume} (@option{-M}), each volume of the archive
12418 will have an archive label of the form @samp{@var{archive-label}
12419 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
12420 next, and so on. @xref{Using Multiple Tapes}, for information on
12421 creating multiple volume archives.
12423 @cindex Volume label, listing
12424 @cindex Listing volume label
12425   The volume label will be displayed by @option{--list} along with
12426 the file contents.  If verbose display is requested, it will also be
12427 explicitly marked as in the example below:
12429 @smallexample
12430 @group
12431 $ @kbd{tar --verbose --list --file=iamanarchive}
12432 V--------- 0/0               0 1992-03-07 12:01 iamalabel--Volume Header--
12433 -rw-r--r-- ringo/user       40 1990-05-21 13:30 iamafilename
12434 @end group
12435 @end smallexample
12437 @opindex test-label
12438 @anchor{--test-label option}
12439   However, @option{--list} option will cause listing entire
12440 contents of the archive, which may be undesirable (for example, if the
12441 archive is stored on a tape).  You can request checking only the volume
12442 label by specifying @option{--test-label} option.  This option reads only the
12443 first block of an archive, so it can be used with slow storage
12444 devices.  For example:
12446 @smallexample
12447 @group
12448 $ @kbd{tar --test-label --file=iamanarchive}
12449 iamalabel
12450 @end group
12451 @end smallexample
12453   If @option{--test-label} is used with one or more command line
12454 arguments, @command{tar} compares the volume label with each
12455 argument.  It exits with code 0 if a match is found, and with code 1
12456 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
12457 mismatch with an exit code 2 and printed a spurious diagnostics on
12458 stderr.}.  No output is displayed, unless you also used the
12459 @option{--verbose} option.  For example:
12461 @smallexample
12462 @group
12463 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
12464 @result{} 0
12465 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
12466 @result{} 1
12467 @end group
12468 @end smallexample
12470   When used with the @option{--verbose} option, @command{tar}
12471 prints the actual volume label (if any), and a verbose diagnostics in
12472 case of a mismatch:
12474 @smallexample
12475 @group
12476 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
12477 iamalabel
12478 @result{} 0
12479 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
12480 iamalabel
12481 tar: Archive label mismatch
12482 @result{} 1
12483 @end group
12484 @end smallexample
12486   If you request any operation, other than @option{--create}, along
12487 with using @option{--label} option, @command{tar} will first check if
12488 the archive label matches the one specified and will refuse to proceed
12489 if it does not.  Use this as a safety precaution to avoid accidentally
12490 overwriting existing archives.  For example, if you wish to add files
12491 to @file{archive}, presumably labeled with string @samp{My volume},
12492 you will get:
12494 @smallexample
12495 @group
12496 $ @kbd{tar -rf archive --label 'My volume' .}
12497 tar: Archive not labeled to match 'My volume'
12498 @end group
12499 @end smallexample
12501 @noindent
12502 in case its label does not match.  This will work even if
12503 @file{archive} is not labeled at all.
12505   Similarly, @command{tar} will refuse to list or extract the
12506 archive if its label doesn't match the @var{archive-label}
12507 specified.  In those cases, @var{archive-label} argument is interpreted
12508 as a globbing-style pattern which must match the actual magnetic
12509 volume label.  @xref{exclude}, for a precise description of how match
12510 is attempted@footnote{Previous versions of @command{tar} used full
12511 regular expression matching, or before that, only exact string
12512 matching, instead of wildcard matchers.  We decided for the sake of
12513 simplicity to use a uniform matching device through
12514 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
12515 the volume label matcher will also suffix @var{archive-label} by
12516 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
12517 up.  Since the volume numbering is automatically added in labels at
12518 creation time, it sounded logical to equally help the user taking care
12519 of it when the archive is being read.
12521   You can also use @option{--label} to get a common information on
12522 all tapes of a series.  For having this information different in each
12523 series created through a single script used on a regular basis, just
12524 manage to get some date string as part of the label.  For example:
12526 @smallexample
12527 @group
12528 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
12529 $ @kbd{tar --create --file=/dev/tape --multi-volume \
12530      --label="Daily backup for `date +%Y-%m-%d`"}
12531 @end group
12532 @end smallexample
12534   Some more notes about volume labels:
12536 @itemize @bullet
12537 @item Each label has its own date and time, which corresponds
12538 to the time when @GNUTAR{} initially attempted to write it,
12539 often soon after the operator launches @command{tar} or types the
12540 carriage return telling that the next tape is ready.
12542 @item Comparing date labels to get an idea of tape throughput is
12543 unreliable.  It gives correct results only if the delays for rewinding
12544 tapes and the operator switching them were negligible, which is
12545 usually not the case.
12546 @end itemize
12548 @node verify
12549 @section Verifying Data as It is Stored
12550 @cindex Verifying a write operation
12551 @cindex Double-checking a write operation
12553 @table @option
12554 @item -W
12555 @itemx --verify
12556 @opindex verify, short description
12557 Attempt to verify the archive after writing.
12558 @end table
12560 This option causes @command{tar} to verify the archive after writing it.
12561 Each volume is checked after it is written, and any discrepancies
12562 are recorded on the standard error output.
12564 Verification requires that the archive be on a back-space-able medium.
12565 This means pipes, some cartridge tape drives, and some other devices
12566 cannot be verified.
12568 You can insure the accuracy of an archive by comparing files in the
12569 system with archive members.  @command{tar} can compare an archive to the
12570 file system as the archive is being written, to verify a write
12571 operation, or can compare a previously written archive, to insure that
12572 it is up to date.
12574 @xopindex{verify, using with @option{--create}}
12575 @xopindex{create, using with @option{--verify}}
12576 To check for discrepancies in an archive immediately after it is
12577 written, use the @option{--verify} (@option{-W}) option in conjunction with
12578 the @option{--create} operation.  When this option is
12579 specified, @command{tar} checks archive members against their counterparts
12580 in the file system, and reports discrepancies on the standard error.
12582 To verify an archive, you must be able to read it from before the end
12583 of the last written entry.  This option is useful for detecting data
12584 errors on some tapes.  Archives written to pipes, some cartridge tape
12585 drives, and some other devices cannot be verified.
12587 One can explicitly compare an already made archive with the file
12588 system by using the @option{--compare} (@option{--diff}, @option{-d})
12589 option, instead of using the more automatic @option{--verify} option.
12590 @xref{compare}.
12592 Note that these two options have a slightly different intent.  The
12593 @option{--compare} option checks how identical are the logical contents of some
12594 archive with what is on your disks, while the @option{--verify} option is
12595 really for checking if the physical contents agree and if the recording
12596 media itself is of dependable quality.  So, for the @option{--verify}
12597 operation, @command{tar} tries to defeat all in-memory cache pertaining to
12598 the archive, while it lets the speed optimization undisturbed for the
12599 @option{--compare} option.  If you nevertheless use @option{--compare} for
12600 media verification, you may have to defeat the in-memory cache yourself,
12601 maybe by opening and reclosing the door latch of your recording unit,
12602 forcing some doubt in your operating system about the fact this is really
12603 the same volume as the one just written or read.
12605 The @option{--verify} option would not be necessary if drivers were indeed
12606 able to detect dependably all write failures.  This sometimes require many
12607 magnetic heads, some able to read after the writes occurred.  One would
12608 not say that drivers unable to detect all cases are necessarily flawed,
12609 as long as programming is concerned.
12611 The @option{--verify} (@option{-W}) option will not work in
12612 conjunction with the @option{--multi-volume} (@option{-M}) option or
12613 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
12614 and @option{--delete} operations.  @xref{Operations}, for more
12615 information on these operations.
12617 Also, since @command{tar} normally strips leading @samp{/} from file
12618 names (@pxref{absolute}), a command like @samp{tar --verify -cf
12619 /tmp/foo.tar /etc} will work as desired only if the working directory is
12620 @file{/}, as @command{tar} uses the archive's relative member names
12621 (e.g., @file{etc/motd}) when verifying the archive.
12623 @node Write Protection
12624 @section Write Protection
12626 Almost all tapes and diskettes, and in a few rare cases, even disks can
12627 be @dfn{write protected}, to protect data on them from being changed.
12628 Once an archive is written, you should write protect the media to prevent
12629 the archive from being accidentally overwritten or deleted.  (This will
12630 protect the archive from being changed with a tape or floppy drive---it
12631 will not protect it from magnet fields or other physical hazards.)
12633 The write protection device itself is usually an integral part of the
12634 physical media, and can be a two position (write enabled/write
12635 disabled) switch, a notch which can be popped out or covered, a ring
12636 which can be removed from the center of a tape reel, or some other
12637 changeable feature.
12639 @node Reliability and security
12640 @chapter Reliability and Security
12642 The @command{tar} command reads and writes files as any other
12643 application does, and is subject to the usual caveats about
12644 reliability and security.  This section contains some commonsense
12645 advice on the topic.
12647 @menu
12648 * Reliability::
12649 * Security::
12650 @end menu
12652 @node Reliability
12653 @section Reliability
12655 Ideally, when @command{tar} is creating an archive, it reads from a
12656 file system that is not being modified, and encounters no errors or
12657 inconsistencies while reading and writing.  If this is the case, the
12658 archive should faithfully reflect what was read.  Similarly, when
12659 extracting from an archive, ideally @command{tar} ideally encounters
12660 no errors and the extracted files faithfully reflect what was in the
12661 archive.
12663 However, when reading or writing real-world file systems, several
12664 things can go wrong; these include permissions problems, corruption of
12665 data, and race conditions.
12667 @menu
12668 * Permissions problems::
12669 * Data corruption and repair::
12670 * Race conditions::
12671 @end menu
12673 @node Permissions problems
12674 @subsection Permissions Problems
12676 If @command{tar} encounters errors while reading or writing files, it
12677 normally reports an error and exits with nonzero status.  The work it
12678 does may therefore be incomplete.  For example, when creating an
12679 archive, if @command{tar} cannot read a file then it cannot copy the
12680 file into the archive.
12682 @node Data corruption and repair
12683 @subsection Data Corruption and Repair
12685 If an archive becomes corrupted by an I/O error, this may corrupt the
12686 data in an extracted file.  Worse, it may corrupt the file's metadata,
12687 which may cause later parts of the archive to become misinterpreted.
12688 An tar-format archive contains a checksum that most likely will detect
12689 errors in the metadata, but it will not detect errors in the data.
12691 If data corruption is a concern, you can compute and check your own
12692 checksums of an archive by using other programs, such as
12693 @command{cksum}.
12695 When attempting to recover from a read error or data corruption in an
12696 archive, you may need to skip past the questionable data and read the
12697 rest of the archive.  This requires some expertise in the archive
12698 format and in other software tools.
12700 @node Race conditions
12701 @subsection Race conditions
12703 If some other process is modifying the file system while @command{tar}
12704 is reading or writing files, the result may well be inconsistent due
12705 to race conditions.  For example, if another process creates some
12706 files in a directory while @command{tar} is creating an archive
12707 containing the directory's files, @command{tar} may see some of the
12708 files but not others, or it may see a file that is in the process of
12709 being created.  The resulting archive may not be a snapshot of the
12710 file system at any point in time.  If an application such as a
12711 database system depends on an accurate snapshot, restoring from the
12712 @command{tar} archive of a live file system may therefore break that
12713 consistency and may break the application.  The simplest way to avoid
12714 the consistency issues is to avoid making other changes to the file
12715 system while tar is reading it or writing it.
12717 When creating an archive, several options are available to avoid race
12718 conditions.  Some hosts have a way of snapshotting a file system, or
12719 of temporarily suspending all changes to a file system, by (say)
12720 suspending the only virtual machine that can modify a file system; if
12721 you use these facilities and have @command{tar -c} read from a
12722 snapshot when creating an archive, you can avoid inconsistency
12723 problems.  More drastically, before starting @command{tar} you could
12724 suspend or shut down all processes other than @command{tar} that have
12725 access to the file system, or you could unmount the file system and
12726 then mount it read-only.
12728 When extracting from an archive, one approach to avoid race conditions
12729 is to create a directory that no other process can write to, and
12730 extract into that.
12732 @node Security
12733 @section Security
12735 In some cases @command{tar} may be used in an adversarial situation,
12736 where an untrusted user is attempting to gain information about or
12737 modify otherwise-inaccessible files.  Dealing with untrusted data
12738 (that is, data generated by an untrusted user) typically requires
12739 extra care, because even the smallest mistake in the use of
12740 @command{tar} is more likely to be exploited by an adversary than by a
12741 race condition.
12743 @menu
12744 * Privacy::
12745 * Integrity::
12746 * Live untrusted data::
12747 * Security rules of thumb::
12748 @end menu
12750 @node Privacy
12751 @subsection Privacy
12753 Standard privacy concerns apply when using @command{tar}.  For
12754 example, suppose you are archiving your home directory into a file
12755 @file{/archive/myhome.tar}.  Any secret information in your home
12756 directory, such as your SSH secret keys, are copied faithfully into
12757 the archive.  Therefore, if your home directory contains any file that
12758 should not be read by some other user, the archive itself should be
12759 not be readable by that user.  And even if the archive's data are
12760 inaccessible to untrusted users, its metadata (such as size or
12761 last-modified date) may reveal some information about your home
12762 directory; if the metadata are intended to be private, the archive's
12763 parent directory should also be inaccessible to untrusted users.
12765 One precaution is to create @file{/archive} so that it is not
12766 accessible to any user, unless that user also has permission to access
12767 all the files in your home directory.
12769 Similarly, when extracting from an archive, take care that the
12770 permissions of the extracted files are not more generous than what you
12771 want.  Even if the archive itself is readable only to you, files
12772 extracted from it have their own permissions that may differ.
12774 @node Integrity
12775 @subsection Integrity
12777 When creating archives, take care that they are not writable by a
12778 untrusted user; otherwise, that user could modify the archive, and
12779 when you later extract from the archive you will get incorrect data.
12781 When @command{tar} extracts from an archive, by default it writes into
12782 files relative to the working directory.  If the archive was generated
12783 by an untrusted user, that user therefore can write into any file
12784 under the working directory.  If the working directory contains a
12785 symbolic link to another directory, the untrusted user can also write
12786 into any file under the referenced directory.  When extracting from an
12787 untrusted archive, it is therefore good practice to create an empty
12788 directory and run @command{tar} in that directory.
12790 When extracting from two or more untrusted archives, each one should
12791 be extracted independently, into different empty directories.
12792 Otherwise, the first archive could create a symbolic link into an area
12793 outside the working directory, and the second one could follow the
12794 link and overwrite data that is not under the working directory.  For
12795 example, when restoring from a series of incremental dumps, the
12796 archives should have been created by a trusted process, as otherwise
12797 the incremental restores might alter data outside the working
12798 directory.
12800 If you use the @option{--absolute-names} (@option{-P}) option when
12801 extracting, @command{tar} respects any file names in the archive, even
12802 file names that begin with @file{/} or contain @file{..}.  As this
12803 lets the archive overwrite any file in your system that you can write,
12804 the @option{--absolute-names} (@option{-P}) option should be used only
12805 for trusted archives.
12807 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12808 @option{--skip-old-files} options, @command{tar} refuses to replace
12809 existing files when extracting.  The difference between the two
12810 options is that the former treats existing files as errors whereas the
12811 latter just silently ignores them.
12813 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12814 refuses to replace the permissions or ownership of already-existing
12815 directories.  These options may help when extracting from untrusted
12816 archives.
12818 @node Live untrusted data
12819 @subsection Dealing with Live Untrusted Data
12821 Extra care is required when creating from or extracting into a file
12822 system that is accessible to untrusted users.  For example, superusers
12823 who invoke @command{tar} must be wary about its actions being hijacked
12824 by an adversary who is reading or writing the file system at the same
12825 time that @command{tar} is operating.
12827 When creating an archive from a live file system, @command{tar} is
12828 vulnerable to denial-of-service attacks.  For example, an adversarial
12829 user could create the illusion of an indefinitely-deep directory
12830 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12831 @command{tar}, or the illusion of an indefinitely-long file by
12832 creating a sparse file but arranging for blocks to be allocated just
12833 before @command{tar} reads them.  There is no easy way for
12834 @command{tar} to distinguish these scenarios from legitimate uses, so
12835 you may need to monitor @command{tar}, just as you'd need to monitor
12836 any other system service, to detect such attacks.
12838 While a superuser is extracting from an archive into a live file
12839 system, an untrusted user might replace a directory with a symbolic
12840 link, in hopes that @command{tar} will follow the symbolic link and
12841 extract data into files that the untrusted user does not have access
12842 to.  Even if the archive was generated by the superuser, it may
12843 contain a file such as @file{d/etc/passwd} that the untrusted user
12844 earlier created in order to break in; if the untrusted user replaces
12845 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12846 @command{tar} is running, @command{tar} will overwrite
12847 @file{/etc/passwd}.  This attack can be prevented by extracting into a
12848 directory that is inaccessible to untrusted users.
12850 Similar attacks via symbolic links are also possible when creating an
12851 archive, if the untrusted user can modify an ancestor of a top-level
12852 argument of @command{tar}.  For example, an untrusted user that can
12853 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12854 - /home/eve/Documents/yesterday} by replacing
12855 @file{/home/eve/Documents} with a symbolic link to some other
12856 location.  Attacks like these can be prevented by making sure that
12857 untrusted users cannot modify any files that are top-level arguments
12858 to @command{tar}, or any ancestor directories of these files.
12860 @node Security rules of thumb
12861 @subsection Security Rules of Thumb
12863 This section briefly summarizes rules of thumb for avoiding security
12864 pitfalls.
12866 @itemize @bullet
12868 @item
12869 Protect archives at least as much as you protect any of the files
12870 being archived.
12872 @item
12873 Extract from an untrusted archive only into an otherwise-empty
12874 directory.  This directory and its parent should be accessible only to
12875 trusted users.  For example:
12877 @example
12878 @group
12879 $ @kbd{chmod go-rwx .}
12880 $ @kbd{mkdir -m go-rwx dir}
12881 $ @kbd{cd dir}
12882 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12883 @end group
12884 @end example
12886 As a corollary, do not do an incremental restore from an untrusted archive.
12888 @item
12889 Do not let untrusted users access files extracted from untrusted
12890 archives without checking first for problems such as setuid programs.
12892 @item
12893 Do not let untrusted users modify directories that are ancestors of
12894 top-level arguments of @command{tar}.  For example, while you are
12895 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12896 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12898 @item
12899 Pay attention to the diagnostics and exit status of @command{tar}.
12901 @item
12902 When archiving live file systems, monitor running instances of
12903 @command{tar} to detect denial-of-service attacks.
12905 @item
12906 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12907 @option{--dereference} (@option{-h}), @option{--overwrite},
12908 @option{--recursive-unlink}, and @option{--remove-files} unless you
12909 understand their security implications.
12911 @end itemize
12913 @node Changes
12914 @appendix Changes
12916 This appendix lists some important user-visible changes between
12917 various versions of @GNUTAR{}. An up-to-date version of this document
12918 is available at
12919 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12920 @GNUTAR{} documentation page}.
12922 @table @asis
12923 @item Use of globbing patterns when listing and extracting.
12925 Previous versions of GNU tar assumed shell-style globbing when
12926 extracting from or listing an archive.  For example:
12928 @smallexample
12929 $ @kbd{tar xf foo.tar '*.c'}
12930 @end smallexample
12932 would extract all files whose names end in @samp{.c}.  This behavior
12933 was not documented and was incompatible with traditional tar
12934 implementations.  Therefore, starting from version 1.15.91, GNU tar
12935 no longer uses globbing by default.  For example, the above invocation
12936 is now interpreted as a request to extract from the archive the file
12937 named @file{*.c}.
12939 To facilitate transition to the new behavior for those users who got
12940 used to the previous incorrect one, @command{tar} will print a warning
12941 if it finds out that a requested member was not found in the archive
12942 and its name looks like a globbing pattern.  For example:
12944 @smallexample
12945 $ @kbd{tar xf foo.tar  '*.c'}
12946 tar: Pattern matching characters used in file names. Please,
12947 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12948 tar: suppress this warning.
12949 tar: *.c: Not found in archive
12950 tar: Error exit delayed from previous errors
12951 @end smallexample
12953 To treat member names as globbing patterns, use the @option{--wildcards} option.
12954 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12955 add this option to your @env{TAR_OPTIONS} variable.
12957 @xref{wildcards}, for the detailed discussion of the use of globbing
12958 patterns by @GNUTAR{}.
12960 @item Use of short option @option{-o}.
12962 Earlier versions of @GNUTAR{} understood @option{-o} command line
12963 option as a synonym for @option{--old-archive}.
12965 @GNUTAR{} starting from version 1.13.90 understands this option as
12966 a synonym for @option{--no-same-owner}.  This is compatible with
12967 UNIX98 @command{tar} implementations.
12969 However, to facilitate transition, @option{-o} option retains its
12970 old semantics when it is used with one of archive-creation commands.
12971 Users are encouraged to use @option{--format=oldgnu} instead.
12973 It is especially important, since versions of @acronym{GNU} Automake
12974 up to and including 1.8.4 invoke tar with this option to produce
12975 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
12976 of this issue and its implications.
12978 @xref{Options, tar-formats, Changing Automake's Behavior,
12979 automake, GNU Automake}, for a description on how to use various
12980 archive formats with @command{automake}.
12982 Future versions of @GNUTAR{} will understand @option{-o} only as a
12983 synonym for @option{--no-same-owner}.
12985 @item Use of short option @option{-l}
12987 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12988 synonym for @option{--one-file-system}.  Since such usage contradicted
12989 to UNIX98 specification and harmed compatibility with other
12990 implementations, it was declared deprecated in version 1.14.  However,
12991 to facilitate transition to its new semantics, it was supported by
12992 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
12993 variant of @option{--check-links} was introduced in version 1.15.91.
12995 @item Use of options @option{--portability} and @option{--old-archive}
12997 These options are deprecated.  Please use @option{--format=v7} instead.
12999 @item Use of option @option{--posix}
13001 This option is deprecated.  Please use @option{--format=posix} instead.
13002 @end table
13004 @node Recipes
13005 @appendix Recipes
13006 @include recipes.texi
13008 @node Configuring Help Summary
13009 @appendix Configuring Help Summary
13011 Running @kbd{tar --help} displays the short @command{tar} option
13012 summary (@pxref{help}). This summary is organized by @dfn{groups} of
13013 semantically close options. The options within each group are printed
13014 in the following order: a short option, eventually followed by a list
13015 of corresponding long option names, followed by a short description of
13016 the option. For example, here is an excerpt from the actual @kbd{tar
13017 --help} output:
13019 @verbatim
13020  Main operation mode:
13022   -A, --catenate, --concatenate   append tar files to an archive
13023   -c, --create               create a new archive
13024   -d, --diff, --compare      find differences between archive and
13025                              file system
13026       --delete               delete from the archive
13027 @end verbatim
13029 @vrindex ARGP_HELP_FMT, environment variable
13030 The exact visual representation of the help output is configurable via
13031 @env{ARGP_HELP_FMT} environment variable. The value of this variable
13032 is a comma-separated list of @dfn{format variable} assignments. There
13033 are two kinds of format variables. An @dfn{offset variable} keeps the
13034 offset of some part of help output text from the leftmost column on
13035 the screen. A @dfn{boolean} variable is a flag that toggles some
13036 output feature on or off. Depending on the type of the corresponding
13037 variable, there are two kinds of assignments:
13039 @table @asis
13040 @item Offset assignment
13042 The assignment to an offset variable has the following syntax:
13044 @smallexample
13045 @var{variable}=@var{value}
13046 @end smallexample
13048 @noindent
13049 where @var{variable} is the variable name, and @var{value} is a
13050 numeric value to be assigned to the variable.
13052 @item Boolean assignment
13054 To assign @code{true} value to a variable, simply put this variable name. To
13055 assign @code{false} value, prefix the variable name with @samp{no-}. For
13056 example:
13058 @smallexample
13059 @group
13060 # Assign @code{true} value:
13061 dup-args
13062 # Assign @code{false} value:
13063 no-dup-args
13064 @end group
13065 @end smallexample
13066 @end table
13068 Following variables are declared:
13070 @deftypevr {Help Output} boolean dup-args
13071 If true, arguments for an option are shown with both short and long
13072 options, even when a given option has both forms, for example:
13074 @smallexample
13075   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
13076 @end smallexample
13078 If false, then if an option has both short and long forms, the
13079 argument is only shown with the long one, for example:
13081 @smallexample
13082   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13083 @end smallexample
13085 @noindent
13086 and a message indicating that the argument is applicable to both
13087 forms is printed below the options. This message can be disabled
13088 using @code{dup-args-note} (see below).
13090 The default is false.
13091 @end deftypevr
13093 @deftypevr {Help Output} boolean dup-args-note
13094 If this variable is true, which is the default, the following notice
13095 is displayed at the end of the help output:
13097 @quotation
13098 Mandatory or optional arguments to long options are also mandatory or
13099 optional for any corresponding short options.
13100 @end quotation
13102 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
13103 variables @code{dup-args} or @code{dup-args-note} should be set.
13104 @end deftypevr
13106 @deftypevr {Help Output} offset short-opt-col
13107 Column in which short options start. Default is 2.
13109 @smallexample
13110 @group
13111 $ @kbd{tar --help|grep ARCHIVE}
13112   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13113 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
13114       -f, --file=ARCHIVE   use archive file or device ARCHIVE
13115 @end group
13116 @end smallexample
13117 @end deftypevr
13119 @deftypevr {Help Output} offset long-opt-col
13120 Column in which long options start. Default is 6. For example:
13122 @smallexample
13123 @group
13124 $ @kbd{tar --help|grep ARCHIVE}
13125   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13126 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
13127   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
13128 @end group
13129 @end smallexample
13130 @end deftypevr
13132 @deftypevr {Help Output} offset doc-opt-col
13133 Column in which @dfn{doc options} start.  A doc option isn't actually
13134 an option, but rather an arbitrary piece of documentation that is
13135 displayed in much the same manner as the options.  For example, in
13136 the description of @option{--format} option:
13138 @smallexample
13139 @group
13140   -H, --format=FORMAT        create archive of the given format.
13142  FORMAT is one of the following:
13144     gnu                      GNU tar 1.13.x format
13145     oldgnu                   GNU format as per tar <= 1.12
13146     pax                      POSIX 1003.1-2001 (pax) format
13147     posix                    same as pax
13148     ustar                    POSIX 1003.1-1988 (ustar) format
13149     v7                       old V7 tar format
13150 @end group
13151 @end smallexample
13153 @noindent
13154 the format names are doc options. Thus, if you set
13155 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
13156 will look as follows:
13158 @smallexample
13159 @group
13160   -H, --format=FORMAT        create archive of the given format.
13162  FORMAT is one of the following:
13164         gnu                      GNU tar 1.13.x format
13165         oldgnu                   GNU format as per tar <= 1.12
13166         pax                      POSIX 1003.1-2001 (pax) format
13167         posix                    same as pax
13168         ustar                    POSIX 1003.1-1988 (ustar) format
13169         v7                       old V7 tar format
13170 @end group
13171 @end smallexample
13172 @end deftypevr
13174 @deftypevr {Help Output} offset opt-doc-col
13175 Column in which option description starts. Default is 29.
13177 @smallexample
13178 @group
13179 $ @kbd{tar --help|grep ARCHIVE}
13180   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13181 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
13182   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13183 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
13184   -f, --file=ARCHIVE
13185            use archive file or device ARCHIVE
13186 @end group
13187 @end smallexample
13189 @noindent
13190 Notice, that the description starts on a separate line if
13191 @code{opt-doc-col} value is too small.
13192 @end deftypevr
13194 @deftypevr {Help Output} offset header-col
13195 Column in which @dfn{group headers} are printed.  A group header is a
13196 descriptive text preceding an option group.  For example, in the
13197 following text:
13199 @verbatim
13200  Main operation mode:
13202   -A, --catenate, --concatenate   append tar files to
13203                              an archive
13204   -c, --create               create a new archive
13205 @end verbatim
13206 @noindent
13207 @samp{Main operation mode:} is the group header.
13209 The default value is 1.
13210 @end deftypevr
13212 @deftypevr {Help Output} offset usage-indent
13213 Indentation of wrapped usage lines. Affects @option{--usage}
13214 output. Default is 12.
13215 @end deftypevr
13217 @deftypevr {Help Output} offset rmargin
13218 Right margin of the text output. Used for wrapping.
13219 @end deftypevr
13221 @node Fixing Snapshot Files
13222 @appendix Fixing Snapshot Files
13223 @include tar-snapshot-edit.texi
13225 @node Tar Internals
13226 @appendix Tar Internals
13227 @include intern.texi
13229 @node Genfile
13230 @appendix Genfile
13231 @include genfile.texi
13233 @node Free Software Needs Free Documentation
13234 @appendix Free Software Needs Free Documentation
13235 @include freemanuals.texi
13237 @node GNU Free Documentation License
13238 @appendix GNU Free Documentation License
13240 @include fdl.texi
13242 @node Index of Command Line Options
13243 @appendix Index of Command Line Options
13245 This appendix contains an index of all @GNUTAR{} long command line
13246 options. The options are listed without the preceding double-dash.
13247 For a cross-reference of short command line options, see
13248 @ref{Short Option Summary}.
13250 @printindex op
13252 @node Index
13253 @appendix Index
13255 @printindex cp
13257 @summarycontents
13258 @contents
13259 @bye
13261 @c Local variables:
13262 @c texinfo-column-for-description: 32
13263 @c End: