Make sure link counting works for file names supplied with -T
[tar.git] / doc / tar.texi
blob6d84c03636e1e8f7ee22274cd687ee938f32fdb0
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 * GNU Free Documentation License::
120 * Index of Command Line Options::
121 * Index::
123 @detailmenu
124  --- The Detailed Node Listing ---
126 Introduction
128 * Book Contents::               What this Book Contains
129 * Definitions::                 Some Definitions
130 * What tar Does::               What @command{tar} Does
131 * Naming tar Archives::         How @command{tar} Archives are Named
132 * Authors::                     @GNUTAR{} Authors
133 * Reports::                     Reporting bugs or suggestions
135 Tutorial Introduction to @command{tar}
137 * assumptions::
138 * stylistic conventions::
139 * basic tar options::           Basic @command{tar} Operations and Options
140 * frequent operations::
141 * Two Frequent Options::
142 * create::                      How to Create Archives
143 * list::                        How to List Archives
144 * extract::                     How to Extract Members from an Archive
145 * going further::
147 Two Frequently Used Options
149 * file tutorial::
150 * verbose tutorial::
151 * help tutorial::
153 How to Create Archives
155 * prepare for examples::
156 * Creating the archive::
157 * create verbose::
158 * short create::
159 * create dir::
161 How to List Archives
163 * list dir::
165 How to Extract Members from an Archive
167 * extracting archives::
168 * extracting files::
169 * extract dir::
170 * extracting untrusted archives::
171 * failing commands::
173 Invoking @GNUTAR{}
175 * Synopsis::
176 * using tar options::
177 * Styles::
178 * All Options::
179 * help::
180 * defaults::
181 * verbose::
182 * checkpoints::
183 * warnings::
184 * interactive::
186 The Three Option Styles
188 * Long Options::                Long Option Style
189 * Short Options::               Short Option Style
190 * Old Options::                 Old Option Style
191 * Mixing::                      Mixing Option Styles
193 All @command{tar} Options
195 * Operation Summary::
196 * Option Summary::
197 * Short Option Summary::
198 * Position-Sensitive Options::
200 @GNUTAR{} Operations
202 * Basic tar::
203 * Advanced tar::
204 * create options::
205 * extract options::
206 * backup::
207 * looking ahead::
209 Advanced @GNUTAR{} Operations
211 * Operations::
212 * append::
213 * update::
214 * concatenate::
215 * delete::
216 * compare::
218 How to Add Files to Existing Archives: @option{--append}
220 * appending files::             Appending Files to an Archive
221 * multiple::
223 Updating an Archive
225 * how to update::
227 Options Used by @option{--create}
229 * override::                  Overriding File Metadata.
230 * Extended File Attributes::
231 * Ignore Failed Read::
233 Options Used by @option{--extract}
235 * Reading::                     Options to Help Read Archives
236 * Writing::                     Changing How @command{tar} Writes Files
237 * Scarce::                      Coping with Scarce Resources
239 Options to Help Read Archives
241 * read full records::
242 * Ignore Zeros::
244 Changing How @command{tar} Writes Files
246 * Dealing with Old Files::
247 * Overwrite Old Files::
248 * Keep Old Files::
249 * Keep Newer Files::
250 * Unlink First::
251 * Recursive Unlink::
252 * Data Modification Times::
253 * Setting Access Permissions::
254 * Directory Modification Times and Permissions::
255 * Writing to Standard Output::
256 * Writing to an External Program::
257 * remove files::
259 Coping with Scarce Resources
261 * Starting File::
262 * Same Order::
264 Performing Backups and Restoring Files
266 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
267 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
268 * Backup Levels::               Levels of Backups
269 * Backup Parameters::           Setting Parameters for Backups and Restoration
270 * Scripted Backups::            Using the Backup Scripts
271 * Scripted Restoration::        Using the Restore Script
273 Setting Parameters for Backups and Restoration
275 * General-Purpose Variables::
276 * Magnetic Tape Control::
277 * User Hooks::
278 * backup-specs example::        An Example Text of @file{Backup-specs}
280 Choosing Files and Names for @command{tar}
282 * file::                        Choosing the Archive's Name
283 * Selecting Archive Members::
284 * files::                       Reading Names from a File
285 * exclude::                     Excluding Some Files
286 * wildcards::                   Wildcards Patterns and Matching
287 * quoting styles::              Ways of Quoting Special Characters in Names
288 * transform::                   Modifying File and Member Names
289 * after::                       Operating Only on New Files
290 * recurse::                     Descending into Directories
291 * one::                         Crossing File System Boundaries
293 Reading Names from a File
295 * nul::
297 Excluding Some Files
299 * problems with exclude::
301 Wildcards Patterns and Matching
303 * controlling pattern-matching::
305 Crossing File System Boundaries
307 * directory::                   Changing Directory
308 * absolute::                    Absolute File Names
310 Date input formats
312 * General date syntax::            Common rules.
313 * Calendar date items::            19 Dec 1994.
314 * Time of day items::              9:20pm.
315 * Time zone items::                @sc{est}, @sc{pdt}, @sc{gmt}.
316 * Day of week items::              Monday and others.
317 * Relative items in date strings:: next tuesday, 2 years ago.
318 * Pure numbers in date strings::   19931219, 1440.
319 * Seconds since the Epoch::        @@1078100502.
320 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
321 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
323 Controlling the Archive Format
325 * Compression::                 Using Less Space through Compression
326 * Attributes::                  Handling File Attributes
327 * Portability::                 Making @command{tar} Archives More Portable
328 * cpio::                        Comparison of @command{tar} and @command{cpio}
330 Using Less Space through Compression
332 * gzip::                        Creating and Reading Compressed Archives
333 * sparse::                      Archiving Sparse Files
335 Creating and Reading Compressed Archives
337 * lbzip2::  Using lbzip2 with @GNUTAR{}.
339 Making @command{tar} Archives More Portable
341 * Portable Names::              Portable Names
342 * dereference::                 Symbolic Links
343 * hard links::                  Hard Links
344 * old::                         Old V7 Archives
345 * ustar::                       Ustar Archives
346 * gnu::                         GNU and old GNU format archives.
347 * posix::                       @acronym{POSIX} archives
348 * Checksumming::                Checksumming Problems
349 * Large or Negative Values::    Large files, negative time stamps, etc.
350 * Other Tars::                  How to Extract GNU-Specific Data Using
351                                 Other @command{tar} Implementations
353 @GNUTAR{} and @acronym{POSIX} @command{tar}
355 * PAX keywords:: Controlling Extended Header Keywords.
357 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
359 * Split Recovery::       Members Split Between Volumes
360 * Sparse Recovery::      Sparse Members
362 Tapes and Other Archive Media
364 * Device::                      Device selection and switching
365 * Remote Tape Server::
366 * Common Problems and Solutions::
367 * Blocking::                    Blocking
368 * Many::                        Many archives on one tape
369 * Using Multiple Tapes::        Using Multiple Tapes
370 * label::                       Including a Label in the Archive
371 * verify::
372 * Write Protection::
374 Blocking
376 * Format Variations::           Format Variations
377 * Blocking Factor::             The Blocking Factor of an Archive
379 Many Archives on One Tape
381 * Tape Positioning::            Tape Positions and Tape Marks
382 * mt::                          The @command{mt} Utility
384 Using Multiple Tapes
386 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
387 * Tape Files::                  Tape Files
388 * Tarcat::                      Concatenate Volumes into a Single Archive
391 Tar Internals
393 * Standard::           Basic Tar Format
394 * Extensions::         @acronym{GNU} Extensions to the Archive Format
395 * Sparse Formats::     Storing Sparse Files
396 * Snapshot Files::
397 * Dumpdir::
399 Storing Sparse Files
401 * Old GNU Format::
402 * PAX 0::                PAX Format, Versions 0.0 and 0.1
403 * PAX 1::                PAX Format, Version 1.0
405 Genfile
407 * Generate Mode::     File Generation Mode.
408 * Status Mode::       File Status Mode.
409 * Exec Mode::         Synchronous Execution mode.
411 Copying This Manual
413 * GNU Free Documentation License::  License for copying this manual
415 @end detailmenu
416 @end menu
418 @node Introduction
419 @chapter Introduction
421 @GNUTAR{} creates
422 and manipulates @dfn{archives} which are actually collections of
423 many other files; the program provides users with an organized and
424 systematic method for controlling a large amount of data.
425 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
426 archives need not (and these days, typically do not) reside on tapes.
428 @menu
429 * Book Contents::               What this Book Contains
430 * Definitions::                 Some Definitions
431 * What tar Does::               What @command{tar} Does
432 * Naming tar Archives::         How @command{tar} Archives are Named
433 * Authors::                     @GNUTAR{} Authors
434 * Reports::                     Reporting bugs or suggestions
435 @end menu
437 @node Book Contents
438 @section What this Book Contains
440 The first part of this chapter introduces you to various terms that will
441 recur throughout the book.  It also tells you who has worked on @GNUTAR{}
442 and its documentation, and where you should send bug reports
443 or comments.
445 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
446 gentle introduction for people who are new to using @command{tar}.  It is
447 meant to be self-contained, not requiring any reading from subsequent
448 chapters to make sense.  It moves from topic to topic in a logical,
449 progressive order, building on information already explained.
451 Although the tutorial is paced and structured to allow beginners to
452 learn how to use @command{tar}, it is not intended solely for beginners.
453 The tutorial explains how to use the three most frequently used
454 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
455 two frequently used options (@samp{file} and @samp{verbose}).  The other
456 chapters do not refer to the tutorial frequently; however, if a section
457 discusses something which is a complex variant of a basic concept, there
458 may be a cross-reference to that basic concept.  (The entire book,
459 including the tutorial, assumes that the reader understands some basic
460 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
462 The third chapter presents the remaining five operations, and
463 information about using @command{tar} options and option syntax.
465 The other chapters are meant to be used as a reference.  Each chapter
466 presents everything that needs to be said about a specific topic.
468 One of the chapters (@pxref{Date input formats}) exists in its
469 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
470 In addition, one section of this manual (@pxref{Standard}) contains a
471 big quote which is taken directly from @command{tar} sources.
473 In general, we give both long and short (abbreviated) option names
474 at least once in each section where the relevant option is covered, so
475 that novice readers will become familiar with both styles.  (A few
476 options have no short versions, and the relevant sections will
477 indicate this.)
479 @node Definitions
480 @section Some Definitions
482 @cindex archive
483 @cindex tar archive
484 The @command{tar} program is used to create and manipulate @command{tar}
485 archives.  An @dfn{archive} is a single file which contains the contents
486 of many files, while still identifying the names of the files, their
487 owner(s), and so forth.  (In addition, archives record access
488 permissions, user and group, size in bytes, and data modification time.
489 Some archives also record the file names in each archived directory, as
490 well as other file and directory information.)  You can use @command{tar}
491 to @dfn{create} a new archive in a specified directory.
493 @cindex member
494 @cindex archive member
495 @cindex file name
496 @cindex member name
497 The files inside an archive are called @dfn{members}.  Within this
498 manual, we use the term @dfn{file} to refer only to files accessible in
499 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
500 @dfn{member} to refer only to the members of an archive.  Similarly, a
501 @dfn{file name} is the name of a file, as it resides in the file system,
502 and a @dfn{member name} is the name of an archive member within the
503 archive.
505 @cindex extraction
506 @cindex unpacking
507 The term @dfn{extraction} refers to the process of copying an archive
508 member (or multiple members) into a file in the file system.  Extracting
509 all the members of an archive is often called @dfn{extracting the
510 archive}.  The term @dfn{unpack} can also be used to refer to the
511 extraction of many or all the members of an archive.  Extracting an
512 archive does not destroy the archive's structure, just as creating an
513 archive does not destroy the copies of the files that exist outside of
514 the archive.  You may also @dfn{list} the members in a given archive
515 (this is often thought of as ``printing'' them to the standard output,
516 or the command line), or @dfn{append} members to a pre-existing archive.
517 All of these operations can be performed using @command{tar}.
519 @node What tar Does
520 @section What @command{tar} Does
522 @cindex tar
523 The @command{tar} program provides the ability to create @command{tar}
524 archives, as well as various other kinds of manipulation.  For example,
525 you can use @command{tar} on previously created archives to extract files,
526 to store additional files, or to update or list files which were already
527 stored.
529 Initially, @command{tar} archives were used to store files conveniently on
530 magnetic tape.  The name @command{tar} comes from this use; it stands for
531 @code{t}ape @code{ar}chiver.  Despite the utility's name, @command{tar} can
532 direct its output to available devices, files, or other programs (using
533 pipes).  @command{tar} may even access remote devices or files (as archives).
535 You can use @command{tar} archives in many ways.  We want to stress a few
536 of them: storage, backup, and transportation.
538 @FIXME{the following table entries need a bit of work.}
539 @table @asis
540 @item Storage
541 Often, @command{tar} archives are used to store related files for
542 convenient file transfer over a network.  For example, the
543 @acronym{GNU} Project distributes its software bundled into
544 @command{tar} archives, so that all the files relating to a particular
545 program (or set of related programs) can be transferred as a single
546 unit.
548 A magnetic tape can store several files in sequence.  However, the tape
549 has no names for these files; it only knows their relative position on
550 the tape.  One way to store several files on one tape and retain their
551 names is by creating a @command{tar} archive.  Even when the basic transfer
552 mechanism can keep track of names, as FTP can, the nuisance of handling
553 multiple files, directories, and multiple links makes @command{tar}
554 archives useful.
556 Archive files are also used for long-term storage.  You can think of
557 this as transportation from the present into the future.  (It is a
558 science-fiction idiom that you can move through time as well as in
559 space; the idea here is that @command{tar} can be used to move archives in
560 all dimensions, even time!)
562 @item Backup
563 Because the archive created by @command{tar} is capable of preserving
564 file information and directory structure, @command{tar} is commonly
565 used for performing full and incremental backups of disks.  A backup
566 puts a collection of files (possibly pertaining to many users and
567 projects) together on a disk or a tape.  This guards against
568 accidental destruction of the information in those files.
569 @GNUTAR{} has special features that allow it to be
570 used to make incremental and full dumps of all the files in a
571 file system.
573 @item Transportation
574 You can create an archive on one system, transfer it to another system,
575 and extract the contents there.  This allows you to transport a group of
576 files from one system to another.
577 @end table
579 @node Naming tar Archives
580 @section How @command{tar} Archives are Named
582 Conventionally, @command{tar} archives are given names ending with
583 @samp{.tar}.  This is not necessary for @command{tar} to operate properly,
584 but this manual follows that convention in order to accustom readers to
585 it and to make examples more clear.
587 @cindex tar file
588 @cindex entry
589 @cindex tar entry
590 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
591 archive members as ``files'' or ``entries''.  For people familiar with
592 the operation of @command{tar}, this causes no difficulty.  However, in
593 this manual, we consistently refer to ``archives'' and ``archive
594 members'' to make learning to use @command{tar} easier for novice users.
596 @node Authors
597 @section @GNUTAR{} Authors
599 @GNUTAR{} was originally written by John Gilmore,
600 and modified by many people.  The @acronym{GNU} enhancements were
601 written by Jay Fenlason, then Joy Kendall, and the whole package has
602 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
603 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
604 numerous and kind users.
606 We wish to stress that @command{tar} is a collective work, and owes much to
607 all those people who reported problems, offered solutions and other
608 insights, or shared their thoughts and suggestions.  An impressive, yet
609 partial list of those contributors can be found in the @file{THANKS}
610 file from the @GNUTAR{} distribution.
612 @FIXME{i want all of these names mentioned, Absolutely.  BUT, i'm not
613 sure i want to spell out the history in this detail, at least not for
614 the printed book.  i'm just not sure it needs to be said this way.
615 i'll think about it.}
617 @FIXME{History is more important, and surely more interesting, than
618 actual names.  Quoting names without history would be meaningless.  FP}
620 Jay Fenlason put together a draft of a @GNUTAR{}
621 manual, borrowing notes from the original man page from John Gilmore.
622 This was withdrawn in version 1.11.  Thomas Bushnell, n/BSG and Amy
623 Gorin worked on a tutorial and manual for @GNUTAR{}.
624 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
625 taking information from all these sources and merging them.  Melissa
626 Weisshaus finally edited and redesigned the book to create version
627 1.12.  The book for versions from 1.14 up to @value{VERSION} were edited
628 by the current maintainer, Sergey Poznyakoff.
630 For version 1.12, Daniel Hagerty contributed a great deal of technical
631 consulting.  In particular, he is the primary author of @ref{Backups}.
633 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
634 (see @url{http://savannah.gnu.org/projects/tar}), and
635 active development and maintenance work has started
636 again.  Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
637 Poznyakoff and Jeff Bailey.
639 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
641 @node Reports
642 @section Reporting bugs or suggestions
644 @cindex bug reports
645 @cindex reporting bugs
646 If you find problems or have suggestions about this program or manual,
647 please report them to @file{bug-tar@@gnu.org}.
649 When reporting a bug, please be sure to include as much detail as
650 possible, in order to reproduce it.
651 @FIXME{Be more specific, I'd like to make this node as detailed as
652 'Bug reporting' node in Emacs manual.}
654 @node Tutorial
655 @chapter Tutorial Introduction to @command{tar}
657 This chapter guides you through some basic examples of three @command{tar}
658 operations: @option{--create}, @option{--list}, and @option{--extract}.  If
659 you already know how to use some other version of @command{tar}, then you
660 may not need to read this chapter.  This chapter omits most complicated
661 details about how @command{tar} works.
663 @menu
664 * assumptions::
665 * stylistic conventions::
666 * basic tar options::           Basic @command{tar} Operations and Options
667 * frequent operations::
668 * Two Frequent Options::
669 * create::                      How to Create Archives
670 * list::                        How to List Archives
671 * extract::                     How to Extract Members from an Archive
672 * going further::
673 @end menu
675 @node assumptions
676 @section Assumptions this Tutorial Makes
678 This chapter is paced to allow beginners to learn about @command{tar}
679 slowly.  At the same time, we will try to cover all the basic aspects of
680 these three operations.  In order to accomplish both of these tasks, we
681 have made certain assumptions about your knowledge before reading this
682 manual, and the hardware you will be using:
684 @itemize @bullet
685 @item
686 Before you start to work through this tutorial, you should understand
687 what the terms ``archive'' and ``archive member'' mean
688 (@pxref{Definitions}).  In addition, you should understand something
689 about how Unix-type operating systems work, and you should know how to
690 use some basic utilities.  For example, you should know how to create,
691 list, copy, rename, edit, and delete files and directories; how to
692 change between directories; and how to figure out where you are in the
693 file system.  You should have some basic understanding of directory
694 structure and how files are named according to which directory they are
695 in.  You should understand concepts such as standard output and standard
696 input, what various definitions of the term @samp{argument} mean, and the
697 differences between relative and absolute file names.
698 @FIXME{and what else?}
700 @item
701 This manual assumes that you are working from your own home directory
702 (unless we state otherwise).  In this tutorial, you will create a
703 directory to practice @command{tar} commands in.  When we show file names,
704 we will assume that those names are relative to your home directory.
705 For example, my home directory is @file{/home/fsf/melissa}.  All of
706 my examples are in a subdirectory of the directory named by that file
707 name; the subdirectory is called @file{practice}.
709 @item
710 In general, we show examples of archives which exist on (or can be
711 written to, or worked with from) a directory on a hard disk.  In most
712 cases, you could write those archives to, or work with them on any other
713 device, such as a tape drive.  However, some of the later examples in
714 the tutorial and next chapter will not work on tape drives.
715 Additionally, working with tapes is much more complicated than working
716 with hard disks.  For these reasons, the tutorial does not cover working
717 with tape drives.  @xref{Media}, for complete information on using
718 @command{tar} archives with tape drives.
720 @FIXME{this is a cop out.  need to add some simple tape drive info.}
721 @end itemize
723 @node stylistic conventions
724 @section Stylistic Conventions
726 In the examples, @samp{$} represents a typical shell prompt.  It
727 precedes lines you should type; to make this more clear, those lines are
728 shown in @kbd{this font}, as opposed to lines which represent the
729 computer's response; those lines are shown in @code{this font}, or
730 sometimes @samp{like this}.
732 @c When we have lines which are too long to be
733 @c displayed in any other way, we will show them like this:
735 @node basic tar options
736 @section Basic @command{tar} Operations and Options
738 @command{tar} can take a wide variety of arguments which specify and define
739 the actions it will have on the particular set of files or the archive.
740 The main types of arguments to @command{tar} fall into one of two classes:
741 operations, and options.
743 Some arguments fall into a class called @dfn{operations}; exactly one of
744 these is both allowed and required for any instance of using @command{tar};
745 you may @emph{not} specify more than one.  People sometimes speak of
746 @dfn{operating modes}.  You are in a particular operating mode when you
747 have specified the operation which specifies it; there are eight
748 operations in total, and thus there are eight operating modes.
750 The other arguments fall into the class known as @dfn{options}.  You are
751 not required to specify any options, and you are allowed to specify more
752 than one at a time (depending on the way you are using @command{tar} at
753 that time).  Some options are used so frequently, and are so useful for
754 helping you type commands more carefully that they are effectively
755 ``required''.  We will discuss them in this chapter.
757 You can write most of the @command{tar} operations and options in any
758 of three forms: long (mnemonic) form, short form, and old style.  Some
759 of the operations and options have no short or ``old'' forms; however,
760 the operations and options which we will cover in this tutorial have
761 corresponding abbreviations.  We will indicate those abbreviations
762 appropriately to get you used to seeing them.  Note, that the ``old
763 style'' option forms exist in @GNUTAR{} for compatibility with Unix
764 @command{tar}.  In this book we present a full discussion of this way
765 of writing options and operations (@pxref{Old Options}), and we discuss
766 the other two styles of writing options (@xref{Long Options}, and
767 @pxref{Short Options}).
769 In the examples and in the text of this tutorial, we usually use the
770 long forms of operations and options; but the ``short'' forms produce
771 the same result and can make typing long @command{tar} commands easier.
772 For example, instead of typing
774 @smallexample
775 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
776 @end smallexample
778 @noindent
779 you can type
780 @smallexample
781 @kbd{tar -c -v -f afiles.tar apple angst aspic}
782 @end smallexample
784 @noindent
785 or even
786 @smallexample
787 @kbd{tar -cvf afiles.tar apple angst aspic}
788 @end smallexample
790 @noindent
791 For more information on option syntax, see @ref{Advanced tar}.  In
792 discussions in the text, when we name an option by its long form, we
793 also give the corresponding short option in parentheses.
795 The term, ``option'', can be confusing at times, since ``operations''
796 are often lumped in with the actual, @emph{optional} ``options'' in certain
797 general class statements.  For example, we just talked about ``short and
798 long forms of options and operations''.  However, experienced @command{tar}
799 users often refer to these by shorthand terms such as, ``short and long
800 options''.  This term assumes that the ``operations'' are included, also.
801 Context will help you determine which definition of ``options'' to use.
803 Similarly, the term ``command'' can be confusing, as it is often used in
804 two different ways.  People sometimes refer to @command{tar} ``commands''.
805 A @command{tar} @dfn{command} is the entire command line of user input
806 which tells @command{tar} what to do --- including the operation, options,
807 and any arguments (file names, pipes, other commands, etc.).  However,
808 you will also sometimes hear the term ``the @command{tar} command''.  When
809 the word ``command'' is used specifically like this, a person is usually
810 referring to the @command{tar} @emph{operation}, not the whole line.
811 Again, use context to figure out which of the meanings the speaker
812 intends.
814 @node frequent operations
815 @section The Three Most Frequently Used Operations
817 Here are the three most frequently used operations (both short and long
818 forms), as well as a brief description of their meanings.  The rest of
819 this chapter will cover how to use these operations in detail.  We will
820 present the rest of the operations in the next chapter.
822 @table @option
823 @item --create
824 @itemx -c
825 Create a new @command{tar} archive.
826 @item --list
827 @itemx -t
828 List the contents of an archive.
829 @item --extract
830 @itemx -x
831 Extract one or more members from an archive.
832 @end table
834 @node Two Frequent Options
835 @section Two Frequently Used Options
837 To understand how to run @command{tar} in the three operating modes listed
838 previously, you also need to understand how to use two of the options to
839 @command{tar}: @option{--file} (which takes an archive file as an argument)
840 and @option{--verbose}.  (You are usually not @emph{required} to specify
841 either of these options when you run @command{tar}, but they can be very
842 useful in making things more clear and helping you avoid errors.)
844 @menu
845 * file tutorial::
846 * verbose tutorial::
847 * help tutorial::
848 @end menu
850 @node file tutorial
851 @unnumberedsubsec The @option{--file} Option
853 @table @option
854 @xopindex{file, tutorial}
855 @item --file=@var{archive-name}
856 @itemx -f @var{archive-name}
857 Specify the name of an archive file.
858 @end table
860 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
861 use @command{tar}; this option determines the name of the archive file
862 that @command{tar} will work on.
864 @vrindex TAPE
865 If you don't specify this argument, then @command{tar} will examine
866 the environment variable @env{TAPE}.  If it is set, its value will be
867 used as the archive name.  Otherwise, @command{tar} will use the
868 default archive, determined at compile time. Usually it is
869 standard output or some physical tape drive attached to your machine
870 (you can verify what the default is by running @kbd{tar
871 --show-defaults}, @pxref{defaults}).  If there is no tape drive
872 attached, or the default is not meaningful, then @command{tar} will
873 print an error message.  The error message might look roughly like one
874 of the following:
876 @smallexample
877 tar: can't open /dev/rmt8 : No such device or address
878 tar: can't open /dev/rsmt0 : I/O error
879 @end smallexample
881 @noindent
882 To avoid confusion, we recommend that you always specify an archive file
883 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
884 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
885 @ref{file}.
887 @node verbose tutorial
888 @unnumberedsubsec The @option{--verbose} Option
890 @table @option
891 @xopindex{verbose, introduced}
892 @item --verbose
893 @itemx -v
894 Show the files being worked on as @command{tar} is running.
895 @end table
897 @option{--verbose} (@option{-v}) shows details about the results of running
898 @command{tar}.  This can be especially useful when the results might not be
899 obvious.  For example, if you want to see the progress of @command{tar} as
900 it writes files into the archive, you can use the @option{--verbose}
901 option.  In the beginning, you may find it useful to use
902 @option{--verbose} at all times; when you are more accustomed to
903 @command{tar}, you will likely want to use it at certain times but not at
904 others.  We will use @option{--verbose} at times to help make something
905 clear, and we will give many examples both using and not using
906 @option{--verbose} to show the differences.
908 Each instance of @option{--verbose} on the command line increases the
909 verbosity level by one, so if you need more details on the output,
910 specify it twice.
912 When reading archives (@option{--list}, @option{--extract},
913 @option{--diff}), @command{tar} by default prints only the names of
914 the members being extracted.  Using @option{--verbose} will show a full,
915 @command{ls} style member listing.
917 In contrast, when writing archives (@option{--create}, @option{--append},
918 @option{--update}), @command{tar} does not print file names by
919 default.  So, a single @option{--verbose} option shows the file names
920 being added to the archive, while two @option{--verbose} options
921 enable the full listing.
923 For example, to create an archive in verbose mode:
925 @smallexample
926 $ @kbd{tar -cvf afiles.tar apple angst aspic}
927 apple
928 angst
929 aspic
930 @end smallexample
932 @noindent
933 Creating the same archive with the verbosity level 2 could give:
935 @smallexample
936 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
937 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
938 -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
939 -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
940 @end smallexample
942 @noindent
943 This works equally well using short or long forms of options.  Using
944 long forms, you would simply write out the mnemonic form of the option
945 twice, like this:
947 @smallexample
948 $ @kbd{tar --create --verbose --verbose @dots{}}
949 @end smallexample
951 @noindent
952 Note that you must double the hyphens properly each time.
954 Later in the tutorial, we will give examples using @w{@option{--verbose
955 --verbose}}.
957 @anchor{verbose member listing}
958 The full output consists of six fields:
960 @itemize @bullet
961 @item File type and permissions in symbolic form.
962 These are displayed in the same format as the first column of
963 @command{ls -l} output (@pxref{What information is listed,
964 format=verbose, Verbose listing, fileutils, GNU file utilities}).
966 @item Owner name and group separated by a slash character.
967 If these data are not available (for example, when listing a @samp{v7} format
968 archive), numeric @acronym{ID} values are printed instead.
970 @item Size of the file, in bytes.
972 @item File modification date in ISO 8601 format.
974 @item File modification time.
976 @item File name.
977 If the name contains any special characters (white space, newlines,
978 etc.)@: these are displayed in an unambiguous form using so called
979 @dfn{quoting style}.  For the detailed discussion of available styles
980 and on how to use them, see @ref{quoting styles}.
982 Depending on the file type, the name can be followed by some
983 additional information, described in the following table:
985 @table @samp
986 @item -> @var{link-name}
987 The file or archive member is a @dfn{symbolic link} and
988 @var{link-name} is the name of file it links to.
990 @item link to @var{link-name}
991 The file or archive member is a @dfn{hard link} and @var{link-name} is
992 the name of file it links to.
994 @item --Long Link--
995 The archive member is an old GNU format long link.  You will normally
996 not encounter this.
998 @item --Long Name--
999 The archive member is an old GNU format long name.  You will normally
1000 not encounter this.
1002 @item --Volume Header--
1003 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1005 @item --Continued at byte @var{n}--
1006 Encountered only at the beginning of a multi-volume archive
1007 (@pxref{Using Multiple Tapes}).  This archive member is a continuation
1008 from the previous volume. The number @var{n} gives the offset where
1009 the original file was split.
1011 @item  unknown file type @var{c}
1012 An archive member of unknown type. @var{c} is the type character from
1013 the archive header.  If you encounter such a message, it means that
1014 either your archive contains proprietary member types @GNUTAR{} is not
1015 able to handle, or the archive is corrupted.
1016 @end table
1018 @end itemize
1020 For example, here is an archive listing containing most of the special
1021 suffixes explained above:
1023 @smallexample
1024 @group
1025 V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
1026 -rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1027 -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
1028 lrwxrwxrwx gray/staff        0 2006-06-09 13:01 angst -> apple
1029 -rw-r--r-- gray/staff    35793 2006-06-09 12:06 blues
1030 hrw-r--r-- gray/staff        0 2006-06-09 12:06 music link to blues
1031 @end group
1032 @end smallexample
1034 @smallexample
1035 @end smallexample
1037 @node help tutorial
1038 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1040 @table @option
1041 @opindex help
1042 @item --help
1044 The @option{--help} option to @command{tar} prints out a very brief list of
1045 all operations and option available for the current version of
1046 @command{tar} available on your system.
1047 @end table
1049 @node create
1050 @section How to Create Archives
1052 @cindex Creation of the archive
1053 @cindex Archive, creation of
1054 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1055 you use to create a @command{tar} archive.  We will explain
1056 @option{--create} first because, in order to learn about the other
1057 operations, you will find it useful to have an archive available to
1058 practice on.
1060 To make this easier, in this section you will first create a directory
1061 containing three files.  Then, we will show you how to create an
1062 @emph{archive} (inside the new directory).  Both the directory, and
1063 the archive are specifically for you to practice on.  The rest of this
1064 chapter and the next chapter will show many examples using this
1065 directory and the files you will create: some of those files may be
1066 other directories and other archives.
1068 The three files you will archive in this example are called
1069 @file{blues}, @file{folk}, and @file{jazz}.  The archive is called
1070 @file{collection.tar}.
1072 This section will proceed slowly, detailing how to use @option{--create}
1073 in @code{verbose} mode, and showing examples using both short and long
1074 forms.  In the rest of the tutorial, and in the examples in the next
1075 chapter, we will proceed at a slightly quicker pace.  This section
1076 moves more slowly to allow beginning users to understand how
1077 @command{tar} works.
1079 @menu
1080 * prepare for examples::
1081 * Creating the archive::
1082 * create verbose::
1083 * short create::
1084 * create dir::
1085 @end menu
1087 @node prepare for examples
1088 @subsection Preparing a Practice Directory for Examples
1090 To follow along with this and future examples, create a new directory
1091 called @file{practice} containing files called @file{blues}, @file{folk}
1092 and @file{jazz}.  The files can contain any information you like:
1093 ideally, they should contain information which relates to their names,
1094 and be of different lengths.  Our examples assume that @file{practice}
1095 is a subdirectory of your home directory.
1097 Now @command{cd} to the directory named @file{practice}; @file{practice}
1098 is now your @dfn{working directory}.  (@emph{Please note}: Although
1099 the full file name of this directory is
1100 @file{/@var{homedir}/practice}, in our examples we will refer to
1101 this directory as @file{practice}; the @var{homedir} is presumed.)
1103 In general, you should check that the files to be archived exist where
1104 you think they do (in the working directory) by running @command{ls}.
1105 Because you just created the directory and the files and have changed to
1106 that directory, you probably don't need to do that this time.
1108 It is very important to make sure there isn't already a file in the
1109 working directory with the archive name you intend to use (in this case,
1110 @samp{collection.tar}), or that you don't care about its contents.
1111 Whenever you use @samp{create}, @command{tar} will erase the current
1112 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists.  @command{tar}
1113 will not tell you if you are about to overwrite an archive unless you
1114 specify an option which does this (@pxref{backup}, for the
1115 information on how to do so).  To add files to an existing archive,
1116 you need to use a different option, such as @option{--append} (@option{-r}); see
1117 @ref{append} for information on how to do this.
1119 @node Creating the archive
1120 @subsection Creating the Archive
1122 @xopindex{create, introduced}
1123 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1124 archive named @file{collection.tar}, use the following command:
1126 @smallexample
1127 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1128 @end smallexample
1130 The order of the arguments is not very important, @emph{when using long
1131 option forms}, however you should always remember to use option as the
1132 first argument to tar.   For example, the following is wrong:
1134 @smallexample
1135 $ @kbd{tar blues -c folk -f collection.tar jazz}
1136 tar: -c: Invalid blocking factor
1137 Try 'tar --help' or 'tar --usage' for more information.
1138 @end smallexample
1140 The error message is produced because @command{tar} always treats its
1141 first argument as an option (or cluster of options), even if it does
1142 not start with dash.  This is @dfn{traditional} or @dfn{old option}
1143 style, called so because all implementations of @command{tar} have
1144 used it since the very inception of the tar archiver in 1970s.  This
1145 option style will be explained later (@pxref{Old Options}), for now
1146 just remember to always place option as the first argument.
1148 That being said, you could issue the following command:
1150 @smallexample
1151 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1152 @end smallexample
1154 @noindent
1155 However, you can see that this order is harder to understand; this is
1156 why we will list the arguments in the order that makes the commands
1157 easiest to understand (and we encourage you to do the same when you use
1158 @command{tar}, to avoid errors).
1160 Note that the sequence
1161 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1162 If you substituted any other string of characters for
1163 @kbd{collection.tar},  then that string would become the name of the
1164 archive file you create.
1166 The order of the options becomes more important when you begin to use
1167 short forms.  With short forms, if you type commands in the wrong order
1168 (even if you type them correctly in all other ways), you may end up with
1169 results you don't expect.  For this reason, it is a good idea to get
1170 into the habit of typing options in the order that makes inherent sense.
1171 @xref{short create}, for more information on this.
1173 In this example, you type the command as shown above: @option{--create}
1174 is the operation which creates the new archive
1175 (@file{collection.tar}), and @option{--file} is the option which lets
1176 you give it the name you chose.  The files, @file{blues}, @file{folk},
1177 and @file{jazz}, are now members of the archive, @file{collection.tar}
1178 (they are @dfn{file name arguments} to the @option{--create} operation.
1179 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1180 in the archive, they are called @emph{archive members}, not files.
1181 (@pxref{Definitions,members}).
1183 When you create an archive, you @emph{must} specify which files you
1184 want placed in the archive.  If you do not specify any archive
1185 members, @GNUTAR{} will complain.
1187 If you now list the contents of the working directory (@command{ls}), you will
1188 find the archive file listed as well as the files you saw previously:
1190 @smallexample
1191 blues   folk   jazz   collection.tar
1192 @end smallexample
1194 @noindent
1195 Creating the archive @samp{collection.tar} did not destroy the copies of
1196 the files in the directory.
1198 Keep in mind that if you don't indicate an operation, @command{tar} will not
1199 run and will prompt you for one.  If you don't name any files, @command{tar}
1200 will complain.  You must have write access to the working directory,
1201 or else you will not be able to create an archive in that directory.
1203 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1204 an existing archive; it will delete the archive and write a new one.
1205 Use @option{--append} (@option{-r}) instead.  @xref{append}.
1207 @node create verbose
1208 @subsection Running @option{--create} with @option{--verbose}
1210 @xopindex{create, using with @option{--verbose}}
1211 @xopindex{verbose, using with @option{--create}}
1212 If you include the @option{--verbose} (@option{-v}) option on the command line,
1213 @command{tar} will list the files it is acting on as it is working.  In
1214 verbose mode, the @code{create} example above would appear as:
1216 @smallexample
1217 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1218 blues
1219 folk
1220 jazz
1221 @end smallexample
1223 This example is just like the example we showed which did not use
1224 @option{--verbose}, except that @command{tar} generated the remaining
1225 @iftex
1226 lines (note the different font styles).
1227 @end iftex
1228 @ifinfo
1229 lines.
1230 @end ifinfo
1232 In the rest of the examples in this chapter, we will frequently use
1233 @code{verbose} mode so we can show actions or @command{tar} responses that
1234 you would otherwise not see, and which are important for you to
1235 understand.
1237 @node short create
1238 @subsection Short Forms with @samp{create}
1240 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1241 basic uses of @command{tar}, and you will use it countless times.
1242 Eventually, you will probably want to use abbreviated (or ``short'')
1243 forms of options.  A full discussion of the three different forms that
1244 options can take appears in @ref{Styles}; for now, here is what the
1245 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1246 using short option forms:
1248 @smallexample
1249 $ @kbd{tar -cvf collection.tar blues folk jazz}
1250 blues
1251 folk
1252 jazz
1253 @end smallexample
1255 @noindent
1256 As you can see, the system responds the same no matter whether you use
1257 long or short option forms.
1259 @FIXME{i don't like how this is worded:} One difference between using
1260 short and long option forms is that, although the exact placement of
1261 arguments following options is no more specific when using short forms,
1262 it is easier to become confused and make a mistake when using short
1263 forms.  For example, suppose you attempted the above example in the
1264 following way:
1266 @smallexample
1267 $ @kbd{tar -cfv collection.tar blues folk jazz}
1268 @end smallexample
1270 @noindent
1271 In this case, @command{tar} will make an archive file called @file{v},
1272 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1273 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1274 is thus taken to be the chosen archive file name.  @command{tar} will try
1275 to add a file called @file{collection.tar} to the @file{v} archive file;
1276 if the file @file{collection.tar} did not already exist, @command{tar} will
1277 report an error indicating that this file does not exist.  If the file
1278 @file{collection.tar} does already exist (e.g., from a previous command
1279 you may have run), then @command{tar} will add this file to the archive.
1280 Because the @option{-v} option did not get registered, @command{tar} will not
1281 run under @samp{verbose} mode, and will not report its progress.
1283 The end result is that you may be quite confused about what happened,
1284 and possibly overwrite a file.  To illustrate this further, we will show
1285 you how an example we showed previously would look using short forms.
1287 This example,
1289 @smallexample
1290 $ @kbd{tar --create folk blues --file=collection.tar jazz}
1291 @end smallexample
1293 @noindent
1294 is confusing as it is.  It becomes even more so when using short forms:
1296 @smallexample
1297 $ @kbd{tar -c folk blues -f collection.tar jazz}
1298 @end smallexample
1300 @noindent
1301 It would be very easy to put the wrong string of characters
1302 immediately following the @option{-f}, but doing that could sacrifice
1303 valuable data.
1305 For this reason, we recommend that you pay very careful attention to
1306 the order of options and placement of file and archive names,
1307 especially when using short option forms.  Not having the option name
1308 written out mnemonically can affect how well you remember which option
1309 does what, and therefore where different names have to be placed.
1311 @node create dir
1312 @subsection Archiving Directories
1314 @cindex Archiving Directories
1315 @cindex Directories, Archiving
1316 You can archive a directory by specifying its directory name as a
1317 file name argument to @command{tar}.  The files in the directory will be
1318 archived relative to the working directory, and the directory will be
1319 re-created along with its contents when the archive is extracted.
1321 To archive a directory, first move to its superior directory.  If you
1322 have followed the previous instructions in this tutorial, you should
1323 type:
1325 @smallexample
1326 $ @kbd{cd ..}
1328 @end smallexample
1330 @noindent
1331 This will put you into the directory which contains @file{practice},
1332 i.e., your home directory.  Once in the superior directory, you can
1333 specify the subdirectory, @file{practice}, as a file name argument.  To
1334 store @file{practice} in the new archive file @file{music.tar}, type:
1336 @smallexample
1337 $ @kbd{tar --create --verbose --file=music.tar practice}
1338 @end smallexample
1340 @noindent
1341 @command{tar} should output:
1343 @smallexample
1344 practice/
1345 practice/blues
1346 practice/folk
1347 practice/jazz
1348 practice/collection.tar
1349 @end smallexample
1351 Note that the archive thus created is not in the subdirectory
1352 @file{practice}, but rather in the current working directory---the
1353 directory from which @command{tar} was invoked.  Before trying to archive a
1354 directory from its superior directory, you should make sure you have
1355 write access to the superior directory itself, not only the directory
1356 you are trying archive with @command{tar}.  For example, you will probably
1357 not be able to store your home directory in an archive by invoking
1358 @command{tar} from the root directory; @xref{absolute}.  (Note
1359 also that @file{collection.tar}, the original archive file, has itself
1360 been archived.  @command{tar} will accept any file as a file to be
1361 archived, regardless of its content.  When @file{music.tar} is
1362 extracted, the archive file @file{collection.tar} will be re-written
1363 into the file system).
1365 If you give @command{tar} a command such as
1367 @smallexample
1368 $ @kbd{tar --create --file=foo.tar .}
1369 @end smallexample
1371 @noindent
1372 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1373 dumped}.  This happens because @command{tar} creates the archive
1374 @file{foo.tar} in the current directory before putting any files into
1375 it.  Then, when @command{tar} attempts to add all the files in the
1376 directory @file{.} to the archive, it notices that the file
1377 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1378 it.  (It makes no sense to put an archive into itself.)  @GNUTAR{}
1379 will continue in this case, and create the archive
1380 normally, except for the exclusion of that one file.  (@emph{Please
1381 note:} Other implementations of @command{tar} may not be so clever;
1382 they will enter an infinite loop when this happens, so you should not
1383 depend on this behavior unless you are certain you are running
1384 @GNUTAR{}.  In general, it is wise to always place the archive outside
1385 of the directory being dumped.)
1387 @node list
1388 @section How to List Archives
1390 @opindex list
1391 Frequently, you will find yourself wanting to determine exactly what a
1392 particular archive contains.  You can use the @option{--list}
1393 (@option{-t}) operation to get the member names as they currently
1394 appear in the archive, as well as various attributes of the files at
1395 the time they were archived.  For example, assuming @file{practice} is
1396 your working directory, you can examine the archive
1397 @file{collection.tar} that you created in the last section with the
1398 command,
1400 @smallexample
1401 $ @kbd{tar --list --file=collection.tar}
1402 @end smallexample
1404 @noindent
1405 The output of @command{tar} would then be:
1407 @smallexample
1408 blues
1409 folk
1410 jazz
1411 @end smallexample
1413 @noindent
1414 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1415 @var{archive-name}}) option just as with @option{--create}
1416 (@option{-c}) to specify the name of the archive.
1418 @cindex File name arguments, using @option{--list} with
1419 @xopindex{list, using with file name arguments}
1420 You can specify one or more individual member names as arguments when
1421 using @samp{list}.  In this case, @command{tar} will only list the
1422 names of members you identify.  For example, @w{@kbd{tar --list
1423 --file=collection.tar folk}} would only print @file{folk}:
1425 @smallexample
1426 $ @kbd{tar --list --file=collection.tar folk}
1427 folk
1428 @end smallexample
1430 @xopindex{list, using with @option{--verbose}}
1431 @xopindex{verbose, using with @option{--list}}
1432 If you use the @option{--verbose} (@option{-v}) option with
1433 @option{--list}, then @command{tar} will print out a listing
1434 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1435 forth.  This output is described in detail in @ref{verbose member listing}.
1437 If you had used @option{--verbose} (@option{-v}) mode, the example
1438 above would look like:
1440 @smallexample
1441 $ @kbd{tar --list --verbose --file=collection.tar folk}
1442 -rw-r--r-- myself/user      62 1990-05-23 10:55 folk
1443 @end smallexample
1445 @cindex listing member and file names
1446 @anchor{listing member and file names}
1447 It is important to notice that the output of @kbd{tar --list
1448 --verbose} does not necessarily match that produced by @kbd{tar
1449 --create --verbose} while creating the archive.  It is because
1450 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1451 prefixes from file names before storing them in the archive
1452 (@xref{absolute}, for more information).  In other
1453 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1454 an archive and @dfn{member names} when listing it.  Consider this
1455 example, run from your home directory:
1457 @smallexample
1458 @group
1459 $ @kbd{tar --create --verbose --file practice.tar ~/practice}
1460 tar: Removing leading '/' from member names
1461 /home/myself/practice/
1462 /home/myself/practice/blues
1463 /home/myself/practice/folk
1464 /home/myself/practice/jazz
1465 /home/myself/practice/collection.tar
1466 $ @kbd{tar --list --file practice.tar}
1467 home/myself/practice/
1468 home/myself/practice/blues
1469 home/myself/practice/folk
1470 home/myself/practice/jazz
1471 home/myself/practice/collection.tar
1472 @end group
1473 @end smallexample
1475 @opindex show-stored-names
1476   This default behavior can sometimes be inconvenient.  You can force
1477 @GNUTAR{} show member names when creating archive by supplying
1478 @option{--show-stored-names} option.
1480 @table @option
1481 @item --show-stored-names
1482 Print member (as opposed to @emph{file}) names when creating the archive.
1483 @end table
1485 With this option, both commands produce the same output:
1487 @smallexample
1488 @group
1489 $ @kbd{tar --create --verbose --show-stored-names \
1490            --file practice.tar ~/practice}
1491 tar: Removing leading '/' from member names
1492 home/myself/practice/
1493 home/myself/practice/blues
1494 home/myself/practice/folk
1495 home/myself/practice/jazz
1496 home/myself/practice/collection.tar
1497 $ @kbd{tar --list --file practice.tar}
1498 home/myself/practice/
1499 home/myself/practice/blues
1500 home/myself/practice/folk
1501 home/myself/practice/jazz
1502 home/myself/practice/collection.tar
1503 @end group
1504 @end smallexample
1506 Since @command{tar} preserves file names, those you wish to list must be
1507 specified as they appear in the archive (i.e., relative to the
1508 directory from which the archive was created).  Continuing the example
1509 above:
1511 @smallexample
1512 @group
1513 $ @kbd{tar --list --file=practice.tar folk}
1514 tar: folk: Not found in archive
1515 tar: Exiting with failure status due to previous errors
1516 @end group
1517 @end smallexample
1519 the error message is produced because there is no member named
1520 @file{folk}, only one named @file{home/myself/folk}.
1522 If you are not sure of the exact file name, use @dfn{globbing
1523 patterns}, for example:
1525 @smallexample
1526 $ @kbd{tar --list --file=practice.tar --wildcards '*/folk'}
1527 home/myself/practice/folk
1528 @end smallexample
1530 @noindent
1531 @xref{wildcards}, for a detailed discussion of globbing patterns and related
1532 @command{tar} command line options.
1534 @menu
1535 * list dir::
1536 @end menu
1538 @node list dir
1539 @unnumberedsubsec Listing the Contents of a Stored Directory
1541 To get information about the contents of an archived directory,
1542 use the directory name as a file name argument in conjunction with
1543 @option{--list} (@option{-t}).  To find out file attributes, include the
1544 @option{--verbose} (@option{-v}) option.
1546 For example, to find out about files in the directory @file{practice}, in
1547 the archive file @file{music.tar}, type:
1549 @smallexample
1550 $ @kbd{tar --list --verbose --file=music.tar practice}
1551 @end smallexample
1553 @command{tar} responds:
1555 @smallexample
1556 drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
1557 -rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
1558 -rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
1559 -rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
1560 -rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar
1561 @end smallexample
1563 When you use a directory name as a file name argument, @command{tar} acts on
1564 all the files (including sub-directories) in that directory.
1566 @node extract
1567 @section How to Extract Members from an Archive
1568 @cindex Extraction
1569 @cindex Retrieving files from an archive
1570 @cindex Resurrecting files from an archive
1572 @opindex extract
1573 Creating an archive is only half the job---there is no point in storing
1574 files in an archive if you can't retrieve them.  The act of retrieving
1575 members from an archive so they can be used and manipulated as
1576 unarchived files again is called @dfn{extraction}.  To extract files
1577 from an archive, use the @option{--extract} (@option{--get} or
1578 @option{-x}) operation.  As with @option{--create}, specify the name
1579 of the archive with @option{--file} (@option{-f}) option. Extracting
1580 an archive does not modify the archive in any way; you can extract it
1581 multiple times if you want or need to.
1583 Using @option{--extract}, you can extract an entire archive, or specific
1584 files.  The files can be directories containing other files, or not.  As
1585 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1586 long form of the operation without affecting the performance.
1588 @menu
1589 * extracting archives::
1590 * extracting files::
1591 * extract dir::
1592 * extracting untrusted archives::
1593 * failing commands::
1594 @end menu
1596 @node extracting archives
1597 @subsection Extracting an Entire Archive
1599 To extract an entire archive, specify the archive file name only, with
1600 no individual file names as arguments.  For example,
1602 @smallexample
1603 $ @kbd{tar -xvf collection.tar}
1604 @end smallexample
1606 @noindent
1607 produces this:
1609 @smallexample
1610 -rw-r--r-- myself/user      28 1996-10-18 16:31 jazz
1611 -rw-r--r-- myself/user      21 1996-09-23 16:44 blues
1612 -rw-r--r-- myself/user      20 1996-09-23 16:44 folk
1613 @end smallexample
1615 @node extracting files
1616 @subsection Extracting Specific Files
1618 To extract specific archive members, give their exact member names as
1619 arguments, as printed by @option{--list} (@option{-t}).  If you had
1620 mistakenly deleted one of the files you had placed in the archive
1621 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1622 from the archive without changing the archive's structure.  Its
1623 contents will be identical to the original file @file{blues} that you
1624 deleted.
1626 First, make sure you are in the @file{practice} directory, and list the
1627 files in the directory.  Now, delete the file, @samp{blues}, and list
1628 the files in the directory again.
1630 You can now extract the member @file{blues} from the archive file
1631 @file{collection.tar} like this:
1633 @smallexample
1634 $ @kbd{tar --extract --file=collection.tar blues}
1635 @end smallexample
1637 @noindent
1638 If you list the files in the directory again, you will see that the file
1639 @file{blues} has been restored, with its original permissions, data
1640 modification times, and owner.@footnote{This is only accidentally
1641 true, but not in general.  Whereas modification times are always
1642 restored, in most cases, one has to be root for restoring the owner,
1643 and use a special option for restoring permissions.  Here, it just
1644 happens that the restoring user is also the owner of the archived
1645 members, and that the current @code{umask} is compatible with original
1646 permissions.}  (These parameters will be identical to those which
1647 the file had when you originally placed it in the archive; any changes
1648 you may have made before deleting the file from the file system,
1649 however, will @emph{not} have been made to the archive member.)  The
1650 archive file, @samp{collection.tar}, is the same as it was before you
1651 extracted @samp{blues}.  You can confirm this by running @command{tar} with
1652 @option{--list} (@option{-t}).
1654 Remember that as with other operations, specifying the exact member
1655 name is important (@xref{failing commands}, for more examples).
1657 You can extract a file to standard output by combining the above options
1658 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1659 Output}).
1661 If you give the @option{--verbose} option, then @option{--extract}
1662 will print the names of the archive members as it extracts them.
1664 @node extract dir
1665 @subsection Extracting Files that are Directories
1667 Extracting directories which are members of an archive is similar to
1668 extracting other files.  The main difference to be aware of is that if
1669 the extracted directory has the same name as any directory already in
1670 the working directory, then files in the extracted directory will be
1671 placed into the directory of the same name.  Likewise, if there are
1672 files in the pre-existing directory with the same names as the members
1673 which you extract, the files from the extracted archive will replace
1674 the files already in the working directory (and possible
1675 subdirectories).  This will happen regardless of whether or not the
1676 files in the working directory were more recent than those extracted
1677 (there exist, however, special options that alter this behavior
1678 @pxref{Writing}).
1680 However, if a file was stored with a directory name as part of its file
1681 name, and that directory does not exist under the working directory when
1682 the file is extracted, @command{tar} will create the directory.
1684 We can demonstrate how to use @option{--extract} to extract a directory
1685 file with an example.  Change to the @file{practice} directory if you
1686 weren't there, and remove the files @file{folk} and @file{jazz}.  Then,
1687 go back to the parent directory and extract the archive
1688 @file{music.tar}.  You may either extract the entire archive, or you may
1689 extract only the files you just deleted.  To extract the entire archive,
1690 don't give any file names as arguments after the archive name
1691 @file{music.tar}.  To extract only the files you deleted, use the
1692 following command:
1694 @smallexample
1695 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1696 practice/folk
1697 practice/jazz
1698 @end smallexample
1700 @noindent
1701 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1702 would have displayed more detail about the extracted files, as shown
1703 in the example below:
1705 @smallexample
1706 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1707 -rw-r--r-- me/user          28 1996-10-18 16:31 practice/jazz
1708 -rw-r--r-- me/user          20 1996-09-23 16:44 practice/folk
1709 @end smallexample
1711 @noindent
1712 Because you created the directory with @file{practice} as part of the
1713 file names of each of the files by archiving the @file{practice}
1714 directory as @file{practice}, you must give @file{practice} as part
1715 of the file names when you extract those files from the archive.
1717 @node extracting untrusted archives
1718 @subsection Extracting Archives from Untrusted Sources
1720 Extracting files from archives can overwrite files that already exist.
1721 If you receive an archive from an untrusted source, you should make a
1722 new directory and extract into that directory, so that you don't have
1723 to worry about the extraction overwriting one of your existing files.
1724 For example, if @file{untrusted.tar} came from somewhere else on the
1725 Internet, and you don't necessarily trust its contents, you can
1726 extract it as follows:
1728 @smallexample
1729 $ @kbd{mkdir newdir}
1730 $ @kbd{cd newdir}
1731 $ @kbd{tar -xvf ../untrusted.tar}
1732 @end smallexample
1734 It is also a good practice to examine contents of the archive
1735 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1736 with @option{--verbose} (@option{-v}).
1738 @node failing commands
1739 @subsection Commands That Will Fail
1741 Here are some sample commands you might try which will not work, and why
1742 they won't work.
1744 If you try to use this command,
1746 @smallexample
1747 $ @kbd{tar -xvf music.tar folk jazz}
1748 @end smallexample
1750 @noindent
1751 you will get the following response:
1753 @smallexample
1754 tar: folk: Not found in archive
1755 tar: jazz: Not found in archive
1756 @end smallexample
1758 @noindent
1759 This is because these files were not originally @emph{in} the parent
1760 directory @file{..}, where the archive is located; they were in the
1761 @file{practice} directory, and their file names reflect this:
1763 @smallexample
1764 $ @kbd{tar -tvf music.tar}
1765 practice/blues
1766 practice/folk
1767 practice/jazz
1768 @end smallexample
1770 @noindent
1771 Likewise, if you try to use this command,
1773 @smallexample
1774 $ @kbd{tar -tvf music.tar folk jazz}
1775 @end smallexample
1777 @noindent
1778 you would get a similar response.  Members with those names are not in the
1779 archive.  You must use the correct member names, or wildcards, in order
1780 to extract the files from the archive.
1782 If you have forgotten the correct names of the files in the archive,
1783 use @w{@kbd{tar --list --verbose}} to list them correctly.
1785 To extract the member named @file{practice/folk}, you must specify
1787 @smallexample
1788 $ @kbd{tar --extract --file=music.tar practice/folk}
1789 @end smallexample
1791 @noindent
1792 Notice also, that as explained above, the @file{practice} directory
1793 will be created, if it didn't already exist.  There are options that
1794 allow you to strip away a certain number of leading directory
1795 components (@pxref{transform}).  For example,
1797 @smallexample
1798 $ @kbd{tar --extract --file=music.tar --strip-components=1 folk}
1799 @end smallexample
1801 @noindent
1802 will extract the file @file{folk} into the current working directory.
1804 @node going further
1805 @section Going Further Ahead in this Manual
1806 @UNREVISED
1808 @FIXME{need to write up a node here about the things that are going to
1809 be in the rest of the manual.}
1811 @node tar invocation
1812 @chapter Invoking @GNUTAR{}
1814 This chapter is about how one invokes the @GNUTAR{}
1815 command, from the command synopsis (@pxref{Synopsis}).  There are
1816 numerous options, and many styles for writing them.  One mandatory
1817 option specifies the operation @command{tar} should perform
1818 (@pxref{Operation Summary}), other options are meant to detail how
1819 this operation should be performed (@pxref{Option Summary}).
1820 Non-option arguments are not always interpreted the same way,
1821 depending on what the operation is.
1823 You will find in this chapter everything about option styles and rules for
1824 writing them (@pxref{Styles}).  On the other hand, operations and options
1825 are fully described elsewhere, in other chapters.  Here, you will find
1826 only synthetic descriptions for operations and options, together with
1827 pointers to other parts of the @command{tar} manual.
1829 Some options are so special they are fully described right in this
1830 chapter.  They have the effect of inhibiting the normal operation of
1831 @command{tar} or else, they globally alter the amount of feedback the user
1832 receives about what is going on.  These are the @option{--help} and
1833 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1834 and @option{--interactive} options (@pxref{interactive}).
1836 @menu
1837 * Synopsis::
1838 * using tar options::
1839 * Styles::
1840 * All Options::           All @command{tar} Options.
1841 * help::                  Where to Get Help.
1842 * defaults::              What are the Default Values.
1843 * verbose::               Checking @command{tar} progress.
1844 * checkpoints::           Checkpoints.
1845 * warnings::              Controlling Warning Messages.
1846 * interactive::           Asking for Confirmation During Operations.
1847 * external::              Running External Commands.
1848 @end menu
1850 @node Synopsis
1851 @section General Synopsis of @command{tar}
1853 The @GNUTAR{} program is invoked as either one of:
1855 @smallexample
1856 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1857 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1858 @end smallexample
1860 The second form is for when old options are being used.
1862 You can use @command{tar} to store files in an archive, to extract them from
1863 an archive, and to do other types of archive manipulation.  The primary
1864 argument to @command{tar}, which is called the @dfn{operation}, specifies
1865 which action to take.  The other arguments to @command{tar} are either
1866 @dfn{options}, which change the way @command{tar} performs an operation,
1867 or file names or archive members, which specify the files or members
1868 @command{tar} is to act on.
1870 You can actually type in arguments in any order, even if in this manual
1871 the options always precede the other arguments, to make examples easier
1872 to understand.  Further, the option stating the main operation mode
1873 (the @command{tar} main command) is usually given first.
1875 Each @var{name} in the synopsis above is interpreted as an archive member
1876 name when the main command is one of @option{--compare}
1877 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1878 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1879 @option{--update} (@option{-u}).  When naming archive members, you
1880 must give the exact name of the member in the archive, as it is
1881 printed by @option{--list}.  For @option{--append} (@option{-r}) and
1882 @option{--create} (@option{-c}), these @var{name} arguments specify
1883 the names of either files or directory hierarchies to place in the archive.
1884 These files or hierarchies should already exist in the file system,
1885 prior to the execution of the @command{tar} command.
1887 @command{tar} interprets relative file names as being relative to the
1888 working directory.  @command{tar} will make all file names relative
1889 (by removing leading slashes when archiving or restoring files),
1890 unless you specify otherwise (using the @option{--absolute-names}
1891 option).  @xref{absolute}, for more information about
1892 @option{--absolute-names}.
1894 If you give the name of a directory as either a file name or a member
1895 name, then @command{tar} acts recursively on all the files and directories
1896 beneath that directory.  For example, the name @file{/} identifies all
1897 the files in the file system to @command{tar}.
1899 The distinction between file names and archive member names is especially
1900 important when shell globbing is used, and sometimes a source of confusion
1901 for newcomers.  @xref{wildcards}, for more information about globbing.
1902 The problem is that shells may only glob using existing files in the
1903 file system.  Only @command{tar} itself may glob on archive members, so when
1904 needed, you must ensure that wildcard characters reach @command{tar} without
1905 being interpreted by the shell first.  Using a backslash before @samp{*}
1906 or @samp{?}, or putting the whole argument between quotes, is usually
1907 sufficient for this.
1909 Even if @var{name}s are often specified on the command line, they
1910 can also be read from a text file in the file system, using the
1911 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1913 If you don't use any file name arguments, @option{--append} (@option{-r}),
1914 @option{--delete} and @option{--concatenate} (@option{--catenate},
1915 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1916 will usually yield a diagnostic and inhibit @command{tar} execution.
1917 The other operations of @command{tar} (@option{--list},
1918 @option{--extract}, @option{--compare}, and @option{--update})
1919 will act on the entire contents of the archive.
1921 @anchor{exit status}
1922 @cindex exit status
1923 @cindex return status
1924 Besides successful exits, @GNUTAR{} may fail for
1925 many reasons.  Some reasons correspond to bad usage, that is, when the
1926 @command{tar} command line is improperly written.  Errors may be
1927 encountered later, while processing the archive or the files.  Some
1928 errors are recoverable, in which case the failure is delayed until
1929 @command{tar} has completed all its work.  Some errors are such that
1930 it would be not meaningful, or at least risky, to continue processing:
1931 @command{tar} then aborts processing immediately.  All abnormal exits,
1932 whether immediate or delayed, should always be clearly diagnosed on
1933 @code{stderr}, after a line stating the nature of the error.
1935 Possible exit codes of @GNUTAR{} are summarized in the following
1936 table:
1938 @table @asis
1939 @item 0
1940 @samp{Successful termination}.
1942 @item 1
1943 @samp{Some files differ}.  If tar was invoked with @option{--compare}
1944 (@option{--diff}, @option{-d}) command line option, this means that
1945 some files in the archive differ from their disk counterparts
1946 (@pxref{compare}).  If tar was given @option{--create},
1947 @option{--append} or @option{--update} option, this exit code means
1948 that some files were changed while being archived and so the resulting
1949 archive does not contain the exact copy of the file set.
1951 @item 2
1952 @samp{Fatal error}.  This means that some fatal, unrecoverable error
1953 occurred.
1954 @end table
1956 If @command{tar} has invoked a subprocess and that subprocess exited with a
1957 nonzero exit code, @command{tar} exits with that code as well.
1958 This can happen, for example, if @command{tar} was given some
1959 compression option (@pxref{gzip}) and the external compressor program
1960 failed.  Another example is @command{rmt} failure during backup to the
1961 remote device (@pxref{Remote Tape Server}).
1963 @node using tar options
1964 @section Using @command{tar} Options
1966 @GNUTAR{} has a total of eight operating modes which
1967 allow you to perform a variety of tasks.  You are required to choose
1968 one operating mode each time you employ the @command{tar} program by
1969 specifying one, and only one operation as an argument to the
1970 @command{tar} command (the corresponding options may be found
1971 at @ref{frequent operations} and @ref{Operations}).  Depending on
1972 circumstances, you may also wish to customize how the chosen operating
1973 mode behaves.  For example, you may wish to change the way the output
1974 looks, or the format of the files that you wish to archive may require
1975 you to do something special in order to make the archive look right.
1977 You can customize and control @command{tar}'s performance by running
1978 @command{tar} with one or more options (such as @option{--verbose}
1979 (@option{-v}), which we used in the tutorial).  As we said in the
1980 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1981 their name suggests) optional. Depending on the operating mode, you
1982 may specify one or more options. Different options will have different
1983 effects, but in general they all change details of the operation, such
1984 as archive format, archive name, or level of user interaction.  Some
1985 options make sense with all operating modes, while others are
1986 meaningful only with particular modes. You will likely use some
1987 options frequently, while you will only use others infrequently, or
1988 not at all.  (A full list of options is available in @pxref{All Options}.)
1990 @vrindex TAR_OPTIONS, environment variable
1991 @anchor{TAR_OPTIONS}
1992 The @env{TAR_OPTIONS} environment variable specifies default options to
1993 be placed in front of any explicit options.  For example, if
1994 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1995 if the two options @option{-v} and @option{--unlink-first} had been
1996 specified before any explicit options.  Option specifications are
1997 separated by whitespace.  A backslash escapes the next character, so it
1998 can be used to specify an option containing whitespace or a backslash.
2000 Note that @command{tar} options are case sensitive.  For example, the
2001 options @option{-T} and @option{-t} are different; the first requires an
2002 argument for stating the name of a file providing a list of @var{name}s,
2003 while the second does not require an argument and is another way to
2004 write @option{--list} (@option{-t}).
2006 In addition to the eight operations, there are many options to
2007 @command{tar}, and three different styles for writing both: long (mnemonic)
2008 form, short form, and old style.  These styles are discussed below.
2009 Both the options and the operations can be written in any of these three
2010 styles.
2012 @FIXME{menu at end of this node.  need to think of an actual outline
2013 for this chapter; probably do that after stuff from chapter 4 is
2014 incorporated.}
2016 @node Styles
2017 @section The Three Option Styles
2019 There are three styles for writing operations and options to the command
2020 line invoking @command{tar}.  The different styles were developed at
2021 different times during the history of @command{tar}.  These styles will be
2022 presented below, from the most recent to the oldest.
2024 Some options must take an argument@footnote{For example, @option{--file}
2025 (@option{-f}) takes the name of an archive file as an argument.  If
2026 you do not supply an archive file name, @command{tar} will use a
2027 default, but this can be confusing; thus, we recommend that you always
2028 supply a specific archive file name.}.  Where you @emph{place} the
2029 arguments generally depends on which style of options you choose.  We
2030 will detail specific information relevant to each option style in the
2031 sections on the different option styles, below.  The differences are
2032 subtle, yet can often be very important; incorrect option placement
2033 can cause you to overwrite a number of important files.  We urge you
2034 to note these differences, and only use the option style(s) which
2035 makes the most sense to you until you feel comfortable with the others.
2037 Some options @emph{may} take an argument.  Such options may have at
2038 most long and short forms, they do not have old style equivalent.  The
2039 rules for specifying an argument for such options are stricter than
2040 those for specifying mandatory arguments.  Please, pay special
2041 attention to them.
2043 @menu
2044 * Long Options::                Long Option Style
2045 * Short Options::               Short Option Style
2046 * Old Options::                 Old Option Style
2047 * Mixing::                      Mixing Option Styles
2048 @end menu
2050 @node Long Options
2051 @subsection Long Option Style
2053 @cindex long options
2054 @cindex options, long style
2055 @cindex options, GNU style
2056 @cindex options, mnemonic names
2057 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2058 dashes in a row, e.g., @option{--list}.  The long names are more clear than
2059 their corresponding short or old names.  It sometimes happens that a
2060 single long option has many different names which are
2061 synonymous, such as @option{--compare} and @option{--diff}.  In addition,
2062 long option names can be given unique abbreviations.  For example,
2063 @option{--cre} can be used in place of @option{--create} because there is no
2064 other long option which begins with @samp{cre}.  (One way to find
2065 this out is by trying it and seeing what happens; if a particular
2066 abbreviation could represent more than one option, @command{tar} will tell
2067 you that that abbreviation is ambiguous and you'll know that that
2068 abbreviation won't work.  You may also choose to run @samp{tar --help}
2069 to see a list of options.  Be aware that if you run @command{tar} with a
2070 unique abbreviation for the long name of an option you didn't want to
2071 use, you are stuck; @command{tar} will perform the command as ordered.)
2073 Long options are meant to be obvious and easy to remember, and their
2074 meanings are generally easier to discern than those of their
2075 corresponding short options (see below).  For example:
2077 @smallexample
2078 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2079 @end smallexample
2081 @noindent
2082 gives a fairly good set of hints about what the command does, even
2083 for those not fully acquainted with @command{tar}.
2085 @cindex arguments to long options
2086 @cindex long options with mandatory arguments
2087 Long options which require arguments take those arguments
2088 immediately following the option name.  There are two ways of
2089 specifying a mandatory argument.  It can be separated from the
2090 option name either by an equal sign, or by any amount of
2091 white space characters.  For example, the @option{--file} option (which
2092 tells the name of the @command{tar} archive) is given a file such as
2093 @file{archive.tar} as argument by using any of the following notations:
2094 @option{--file=archive.tar} or @option{--file archive.tar}.
2096 @cindex optional arguments to long options
2097 @cindex long options with optional arguments
2098 In contrast, optional arguments must always be introduced using
2099 an equal sign.  For example, the @option{--backup} option takes
2100 an optional argument specifying backup type.  It must be used
2101 as @option{--backup=@var{backup-type}}.
2103 @node Short Options
2104 @subsection Short Option Style
2106 @cindex short options
2107 @cindex options, short style
2108 @cindex options, traditional
2109 Most options also have a @dfn{short option} name.  Short options start with
2110 a single dash, and are followed by a single character, e.g., @option{-t}
2111 (which is equivalent to @option{--list}).  The forms are absolutely
2112 identical in function; they are interchangeable.
2114 The short option names are faster to type than long option names.
2116 @cindex arguments to short options
2117 @cindex short options with mandatory arguments
2118 Short options which require arguments take their arguments immediately
2119 following the option, usually separated by white space.  It is also
2120 possible to stick the argument right after the short option name, using
2121 no intervening space.  For example, you might write @w{@option{-f
2122 archive.tar}} or @option{-farchive.tar} instead of using
2123 @option{--file=archive.tar}.  Both @option{--file=@var{archive-name}} and
2124 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2125 specific archive, here named @file{archive.tar}.
2127 @cindex optional arguments to short options
2128 @cindex short options with optional arguments
2129 Short options which take optional arguments take their arguments
2130 immediately following the option letter, @emph{without any intervening
2131 white space characters}.
2133 Short options' letters may be clumped together, but you are not
2134 required to do this (as compared to old options; see below).  When
2135 short options are clumped as a set, use one (single) dash for them
2136 all, e.g., @w{@samp{@command{tar} -cvf}}.  Only the last option in
2137 such a set is allowed to have an argument@footnote{Clustering many
2138 options, the last of which has an argument, is a rather opaque way to
2139 write options.  Some wonder if @acronym{GNU} @code{getopt} should not
2140 even be made helpful enough for considering such usages as invalid.}.
2142 When the options are separated, the argument for each option which requires
2143 an argument directly follows that option, as is usual for Unix programs.
2144 For example:
2146 @smallexample
2147 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2148 @end smallexample
2150 If you reorder short options' locations, be sure to move any arguments
2151 that belong to them.  If you do not move the arguments properly, you may
2152 end up overwriting files.
2154 @node Old Options
2155 @subsection Old Option Style
2156 @cindex options, old style
2157 @cindex old option style
2158 @cindex option syntax, traditional
2160 As far as we know, all @command{tar} programs, @acronym{GNU} and
2161 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2162 argument does not start with @samp{-}, it is assumed to specify option
2163 letters.  @GNUTAR{} supports old options not only for historical
2164 reasons, but also because many people are used to them.  If the first
2165 argument does not start with a dash, you are announcing the old option
2166 style instead of the short option style; old options are decoded
2167 differently.
2169 Like short options, old options are single letters.  However, old options
2170 must be written together as a single clumped set, without spaces separating
2171 them or dashes preceding them.  This set
2172 of letters must be the first to appear on the command line, after the
2173 @command{tar} program name and some white space; old options cannot appear
2174 anywhere else.  The letter of an old option is exactly the same letter as
2175 the corresponding short option.  For example, the old option @samp{t} is
2176 the same as the short option @option{-t}, and consequently, the same as the
2177 long option @option{--list}.  So for example, the command @w{@samp{tar
2178 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2180 @cindex arguments to old options
2181 @cindex old options with mandatory arguments
2182 When options that need arguments are given together with the command,
2183 all the associated arguments follow, in the same order as the options.
2184 Thus, the example given previously could also be written in the old
2185 style as follows:
2187 @smallexample
2188 $ @kbd{tar cvbf 20 /dev/rmt0}
2189 @end smallexample
2191 @noindent
2192 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2193 the argument of @option{-f}.
2195 The old style syntax can make it difficult to match
2196 option letters with their corresponding arguments, and is often
2197 confusing.  In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2198 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2199 argument for @option{-f}, and @option{-v} does not have a corresponding
2200 argument.  Even using short options like in @w{@samp{tar -c -v -b 20 -f
2201 /dev/rmt0}} is clearer, putting all arguments next to the option they
2202 pertain to.
2204 If you want to reorder the letters in the old option argument, be
2205 sure to reorder any corresponding argument appropriately.
2207 This old way of writing @command{tar} options can surprise even experienced
2208 users.  For example, the two commands:
2210 @smallexample
2211 @kbd{tar cfz archive.tar.gz file}
2212 @kbd{tar -cfz archive.tar.gz file}
2213 @end smallexample
2215 @noindent
2216 are quite different.  The first example uses @file{archive.tar.gz} as
2217 the value for option @samp{f} and recognizes the option @samp{z}.  The
2218 second example, however, uses @file{z} as the value for option
2219 @samp{f} --- probably not what was intended.
2221 This second example could be corrected in many ways, among which the
2222 following are equivalent:
2224 @smallexample
2225 @kbd{tar -czf archive.tar.gz file}
2226 @kbd{tar -cf archive.tar.gz -z file}
2227 @kbd{tar cf archive.tar.gz -z file}
2228 @end smallexample
2230 @node Mixing
2231 @subsection Mixing Option Styles
2233 @cindex options, mixing different styles
2234 All three styles may be intermixed in a single @command{tar} command,
2235 so long as the rules for each style are fully
2236 respected@footnote{Before @GNUTAR{} version 1.11.6,
2237 a bug prevented intermixing old style options with long options in
2238 some cases.}.  Old style options and either of the modern styles of
2239 options may be mixed within a single @command{tar} command.  However,
2240 old style options must be introduced as the first arguments only,
2241 following the rule for old options (old options must appear directly
2242 after the @command{tar} command and some white space).  Modern options
2243 may be given only after all arguments to the old options have been
2244 collected.  If this rule is not respected, a modern option might be
2245 falsely interpreted as the value of the argument to one of the old
2246 style options.
2248 For example, all the following commands are wholly equivalent, and
2249 illustrate the many combinations and orderings of option styles.
2251 @smallexample
2252 @kbd{tar --create --file=archive.tar}
2253 @kbd{tar --create -f archive.tar}
2254 @kbd{tar --create -farchive.tar}
2255 @kbd{tar --file=archive.tar --create}
2256 @kbd{tar --file=archive.tar -c}
2257 @kbd{tar -c --file=archive.tar}
2258 @kbd{tar -c -f archive.tar}
2259 @kbd{tar -c -farchive.tar}
2260 @kbd{tar -cf archive.tar}
2261 @kbd{tar -cfarchive.tar}
2262 @kbd{tar -f archive.tar --create}
2263 @kbd{tar -f archive.tar -c}
2264 @kbd{tar -farchive.tar --create}
2265 @kbd{tar -farchive.tar -c}
2266 @kbd{tar c --file=archive.tar}
2267 @kbd{tar c -f archive.tar}
2268 @kbd{tar c -farchive.tar}
2269 @kbd{tar cf archive.tar}
2270 @kbd{tar f archive.tar --create}
2271 @kbd{tar f archive.tar -c}
2272 @kbd{tar fc archive.tar}
2273 @end smallexample
2275 On the other hand, the following commands are @emph{not} equivalent to
2276 the previous set:
2278 @smallexample
2279 @kbd{tar -f -c archive.tar}
2280 @kbd{tar -fc archive.tar}
2281 @kbd{tar -fcarchive.tar}
2282 @kbd{tar -farchive.tarc}
2283 @kbd{tar cfarchive.tar}
2284 @end smallexample
2286 @noindent
2287 These last examples mean something completely different from what the
2288 user intended (judging based on the example in the previous set which
2289 uses long options, whose intent is therefore very clear).  The first
2290 four specify that the @command{tar} archive would be a file named
2291 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2292 respectively.  The first two examples also specify a single non-option,
2293 @var{name} argument having the value @samp{archive.tar}.  The last
2294 example contains only old style option letters (repeating option
2295 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2296 @samp{h}, or @samp{i}), with no argument value.
2297 @FIXME{not sure i liked
2298 the first sentence of this paragraph..}
2300 @node All Options
2301 @section All @command{tar} Options
2303 The coming manual sections contain an alphabetical listing of all
2304 @command{tar} operations and options, with brief descriptions and
2305 cross-references to more in-depth explanations in the body of the manual.
2306 They also contain an alphabetically arranged table of the short option
2307 forms with their corresponding long option.  You can use this table as
2308 a reference for deciphering @command{tar} commands in scripts.
2310 @menu
2311 * Operation Summary::
2312 * Option Summary::
2313 * Short Option Summary::
2314 * Position-Sensitive Options::
2315 @end menu
2317 @node Operation Summary
2318 @subsection Operations
2320 @table @option
2322 @opsummary{append}
2323 @item --append
2324 @itemx -r
2326 Appends files to the end of the archive.  @xref{append}.
2328 @opsummary{catenate}
2329 @item --catenate
2330 @itemx -A
2332 Same as @option{--concatenate}.  @xref{concatenate}.
2334 @opsummary{compare}
2335 @item --compare
2336 @itemx -d
2338 Compares archive members with their counterparts in the file
2339 system, and reports differences in file size, mode, owner,
2340 modification date and contents.  @xref{compare}.
2342 @opsummary{concatenate}
2343 @item --concatenate
2344 @itemx -A
2346 Appends other @command{tar} archives to the end of the archive.
2347 @xref{concatenate}.
2349 @opsummary{create}
2350 @item --create
2351 @itemx -c
2353 Creates a new @command{tar} archive.  @xref{create}.
2355 @opsummary{delete}
2356 @item --delete
2358 Deletes members from the archive.  Don't try this on an archive on a
2359 tape!  @xref{delete}.
2361 @opsummary{diff}
2362 @item --diff
2363 @itemx -d
2365 Same @option{--compare}.  @xref{compare}.
2367 @opsummary{extract}
2368 @item --extract
2369 @itemx -x
2371 Extracts members from the archive into the file system.  @xref{extract}.
2373 @opsummary{get}
2374 @item --get
2375 @itemx -x
2377 Same as @option{--extract}.  @xref{extract}.
2379 @opsummary{list}
2380 @item --list
2381 @itemx -t
2383 Lists the members in an archive.  @xref{list}.
2385 @opsummary{update}
2386 @item --update
2387 @itemx -u
2389 Adds files to the end of the archive, but only if they are newer than
2390 their counterparts already in the archive, or if they do not already
2391 exist in the archive. @xref{update}.
2393 @end table
2395 @node Option Summary
2396 @subsection @command{tar} Options
2398 @table @option
2400 @opsummary{absolute-names}
2401 @item --absolute-names
2402 @itemx -P
2404 Normally when creating an archive, @command{tar} strips an initial
2405 @samp{/} from member names, and when extracting from an archive @command{tar}
2406 treats names specially if they have initial @samp{/} or internal
2407 @samp{..}.  This option disables that behavior.  @xref{absolute}.
2409 @opsummary{acls}
2410 @item --acls
2411 Enable POSIX ACLs support.  @xref{Extended File Attributes, acls}.
2413 @opsummary{after-date}
2414 @item --after-date
2416 (See @option{--newer}, @pxref{after})
2418 @opsummary{anchored}
2419 @item --anchored
2420 A pattern must match an initial subsequence of the name's components.
2421 @xref{controlling pattern-matching}.
2423 @opsummary{atime-preserve}
2424 @item --atime-preserve
2425 @itemx --atime-preserve=replace
2426 @itemx --atime-preserve=system
2428 Attempt to preserve the access time of files when reading them.  This
2429 option currently is effective only on files that you own, unless you
2430 have superuser privileges.
2432 @option{--atime-preserve=replace} remembers the access time of a file
2433 before reading it, and then restores the access time afterwards.  This
2434 may cause problems if other programs are reading the file at the same
2435 time, as the times of their accesses will be lost.  On most platforms
2436 restoring the access time also requires @command{tar} to restore the
2437 data modification time too, so this option may also cause problems if
2438 other programs are writing the file at the same time (@command{tar} attempts
2439 to detect this situation, but cannot do so reliably due to race
2440 conditions).  Worse, on most platforms restoring the access time also
2441 updates the status change time, which means that this option is
2442 incompatible with incremental backups.
2444 @option{--atime-preserve=system} avoids changing time stamps on files,
2445 without interfering with time stamp updates
2446 caused by other programs, so it works better with incremental backups.
2447 However, it requires a special @code{O_NOATIME} option from the
2448 underlying operating and file system implementation, and it also requires
2449 that searching directories does not update their access times.  As of
2450 this writing (November 2005) this works only with Linux, and only with
2451 Linux kernels 2.6.8 and later.  Worse, there is currently no reliable
2452 way to know whether this feature actually works.  Sometimes
2453 @command{tar} knows that it does not work, and if you use
2454 @option{--atime-preserve=system} then @command{tar} complains and
2455 exits right away.  But other times @command{tar} might think that the
2456 option works when it actually does not.
2458 Currently @option{--atime-preserve} with no operand defaults to
2459 @option{--atime-preserve=replace}, but this may change in the future
2460 as support for @option{--atime-preserve=system} improves.
2462 If your operating or file system does not support
2463 @option{--atime-preserve=@-system}, you might be able to preserve access
2464 times reliably by using the @command{mount} command.  For example,
2465 you can mount the file system read-only, or access the file system via
2466 a read-only loopback mount, or use the @samp{noatime} mount option
2467 available on some systems.  However, mounting typically requires
2468 superuser privileges and can be a pain to manage.
2470 @opsummary{auto-compress}
2471 @item --auto-compress
2472 @itemx -a
2474 During a @option{--create} operation, enables automatic compressed
2475 format recognition based on the archive suffix.  The effect of this
2476 option is cancelled by @option{--no-auto-compress}.  @xref{gzip}.
2478 @opsummary{backup}
2479 @item --backup=@var{backup-type}
2481 Rather than deleting files from the file system, @command{tar} will
2482 back them up using simple or numbered backups, depending upon
2483 @var{backup-type}.  @xref{backup}.
2485 @opsummary{block-number}
2486 @item --block-number
2487 @itemx -R
2489 With this option present, @command{tar} prints error messages for read errors
2490 with the block number in the archive file.  @xref{block-number}.
2492 @opsummary{blocking-factor}
2493 @item --blocking-factor=@var{blocking}
2494 @itemx -b @var{blocking}
2496 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2497 record.  @xref{Blocking Factor}.
2499 @opsummary{bzip2}
2500 @item --bzip2
2501 @itemx -j
2503 This option tells @command{tar} to read or write archives through
2504 @code{bzip2}.  @xref{gzip}.
2506 @opsummary{check-device}
2507 @item --check-device
2508 Check device numbers when creating a list of modified files for
2509 incremental archiving.  This is the default.  @xref{device numbers},
2510 for a detailed description.
2512 @opsummary{checkpoint}
2513 @item --checkpoint[=@var{number}]
2515 This option directs @command{tar} to print periodic checkpoint
2516 messages as it reads through the archive.  It is intended for when you
2517 want a visual indication that @command{tar} is still running, but
2518 don't want to see @option{--verbose} output.  You can also instruct
2519 @command{tar} to execute a list of actions on each checkpoint, see
2520 @option{--checkpoint-action} below.  For a detailed description, see
2521 @ref{checkpoints}.
2523 @opsummary{checkpoint-action}
2524 @item --checkpoint-action=@var{action}
2525 Instruct @command{tar} to execute an action upon hitting a
2526 breakpoint.  Here we give only a brief outline.  @xref{checkpoints},
2527 for a complete description.
2529 The @var{action} argument can be one of the following:
2531 @table @asis
2532 @item bell
2533 Produce an audible bell on the console.
2535 @item dot
2536 @itemx .
2537 Print a single dot on the standard listing stream.
2539 @item echo
2540 Display a textual message on the standard error, with the status and
2541 number of the checkpoint.  This is the default.
2543 @item echo=@var{string}
2544 Display @var{string} on the standard error.  Before output, the string
2545 is subject to meta-character expansion.
2547 @item exec=@var{command}
2548 Execute the given @var{command}.
2550 @item sleep=@var{time}
2551 Wait for @var{time} seconds.
2553 @item ttyout=@var{string}
2554 Output @var{string} on the current console (@file{/dev/tty}).
2556 @item totals
2557 Print statistics (see @pxref{totals}).
2559 @item wait=@var{signo}
2560 Wait for signal @var{signo}.
2561 @end table
2563 Several @option{--checkpoint-action} options can be specified.  The
2564 supplied actions will be executed in order of their appearance in the
2565 command line.
2567 Using @option{--checkpoint-action} without @option{--checkpoint}
2568 assumes default checkpoint frequency of one checkpoint per 10 records.
2570 @opsummary{check-links}
2571 @item --check-links
2572 @itemx -l
2573 If this option was given, @command{tar} will check the number of links
2574 dumped for each processed file.  If this number does not match the
2575 total number of hard links for the file, a warning message will be
2576 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2577 synonym for @option{--one-file-system}.  The current semantics, which
2578 complies to UNIX98, was introduced with version
2579 1.15.91. @xref{Changes}, for more information.}.
2581 @xref{hard links}.
2583 @opsummary{compress}
2584 @opsummary{uncompress}
2585 @item --compress
2586 @itemx --uncompress
2587 @itemx -Z
2589 @command{tar} will use the @command{compress} program when reading or
2590 writing the archive.  This allows you to directly act on archives
2591 while saving space.  @xref{gzip}.
2593 @opsummary{clamp-mtime}
2594 @item --clamp-mtime
2596 (See @option{--mtime}.)
2598 @opsummary{confirmation}
2599 @item --confirmation
2601 (See @option{--interactive}.)  @xref{interactive}.
2603 @opsummary{delay-directory-restore}
2604 @item --delay-directory-restore
2606 Delay setting modification times and permissions of extracted
2607 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2609 @opsummary{dereference}
2610 @item --dereference
2611 @itemx -h
2613 When reading or writing a file to be archived, @command{tar} accesses
2614 the file that a symbolic link points to, rather than the symlink
2615 itself.  @xref{dereference}.
2617 @opsummary{directory}
2618 @item --directory=@var{dir}
2619 @itemx -C @var{dir}
2621 When this option is specified, @command{tar} will change its current directory
2622 to @var{dir} before performing any operations.  When this option is used
2623 during archive creation, it is order sensitive.  @xref{directory}.
2625 @opsummary{exclude}
2626 @item --exclude=@var{pattern}
2628 When performing operations, @command{tar} will skip files that match
2629 @var{pattern}.  @xref{exclude}.
2631 @opsummary{exclude-backups}
2632 @item --exclude-backups
2633 Exclude backup and lock files.  @xref{exclude,, exclude-backups}.
2635 @opsummary{exclude-from}
2636 @item --exclude-from=@var{file}
2637 @itemx -X @var{file}
2639 Similar to @option{--exclude}, except @command{tar} will use the list of
2640 patterns in the file @var{file}.  @xref{exclude}.
2642 @opsummary{exclude-caches}
2643 @item --exclude-caches
2645 Exclude from dump any directory containing a valid cache directory
2646 tag file, but still dump the directory node and the tag file itself.
2648 @xref{exclude,, exclude-caches}.
2650 @opsummary{exclude-caches-under}
2651 @item --exclude-caches-under
2653 Exclude from dump any directory containing a valid cache directory
2654 tag file, but still dump the directory node itself.
2656 @xref{exclude}.
2658 @opsummary{exclude-caches-all}
2659 @item --exclude-caches-all
2661 Exclude from dump any directory containing a valid cache directory
2662 tag file.  @xref{exclude}.
2664 @opsummary{exclude-ignore}
2665 @item --exclude-ignore=@var{file}
2666 Before dumping a directory, @command{tar} checks if it contains
2667 @var{file}.  If so, exclusion patterns are read from this file.
2668 The patterns affect only the directory itself.  @xref{exclude}.
2670 @opsummary{exclude-ignore-recursive}
2671 @item --exclude-ignore-recursive=@var{file}
2672 Before dumping a directory, @command{tar} checks if it contains
2673 @var{file}.  If so, exclusion patterns are read from this file.
2674 The patterns affect the directory and all itssubdirectories.
2675 @xref{exclude}.
2677 @opsummary{exclude-tag}
2678 @item --exclude-tag=@var{file}
2680 Exclude from dump any directory containing file named @var{file}, but
2681 dump the directory node and @var{file} itself.  @xref{exclude,, exclude-tag}.
2683 @opsummary{exclude-tag-under}
2684 @item --exclude-tag-under=@var{file}
2686 Exclude from dump the contents of any directory containing file
2687 named @var{file}, but dump the directory node itself.  @xref{exclude,,
2688 exclude-tag-under}.
2690 @opsummary{exclude-tag-all}
2691 @item --exclude-tag-all=@var{file}
2693 Exclude from dump any directory containing file named @var{file}.
2694 @xref{exclude,,exclude-tag-all}.
2696 @opsummary{exclude-vcs}
2697 @item --exclude-vcs
2699 Exclude from dump directories and files, that are internal for some
2700 widely used version control systems.
2702 @xref{exclude-vcs}.
2704 @opsummary{exclude-vcs-ignores}
2705 @item --exclude-vcs-ignores
2706 Exclude files that match patterns read from VCS-specific ignore
2707 files.  Supported files are: @file{.cvsignore}, @file{.gitignore},
2708 @file{.bzrignore}, and @file{.hgignore}.  The semantics of each file
2709 is the same as for the corresponding VCS, e.g. patterns read from
2710 @file{.gitignore} affect the directory and all its subdirectories.
2711 @xref{exclude-vcs-ignores}.
2713 @opsummary{file}
2714 @item --file=@var{archive}
2715 @itemx -f @var{archive}
2717 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2718 performs operations on, rather than @command{tar}'s compilation dependent
2719 default.  @xref{file tutorial}.
2721 @opsummary{files-from}
2722 @item --files-from=@var{file}
2723 @itemx -T @var{file}
2725 @command{tar} will use the contents of @var{file} as a list of archive members
2726 or files to operate on, in addition to those specified on the
2727 command-line.  @xref{files}.
2729 @opsummary{force-local}
2730 @item --force-local
2732 Forces @command{tar} to interpret the file name given to @option{--file}
2733 as a local file, even if it looks like a remote tape drive name.
2734 @xref{local and remote archives}.
2736 @opsummary{format}
2737 @item --format=@var{format}
2738 @itemx -H @var{format}
2740 Selects output archive format.  @var{Format} may be one of the
2741 following:
2743 @table @samp
2744 @item v7
2745 Creates an archive that is compatible with Unix V7 @command{tar}.
2747 @item oldgnu
2748 Creates an archive that is compatible with GNU @command{tar} version
2749 1.12 or earlier.
2751 @item gnu
2752 Creates archive in GNU tar 1.13 format.  Basically it is the same as
2753 @samp{oldgnu} with the only difference in the way it handles long
2754 numeric fields.
2756 @item ustar
2757 Creates a @acronym{POSIX.1-1988} compatible archive.
2759 @item posix
2760 Creates a @acronym{POSIX.1-2001 archive}.
2762 @end table
2764 @xref{Formats}, for a detailed discussion of these formats.
2766 @opsummary{full-time}
2767 @item --full-time
2768 This option instructs @command{tar} to print file times to their full
2769 resolution.  Usually this means 1-second resolution, but that depends
2770 on the underlying file system.  The @option{--full-time} option takes
2771 effect only when detailed output (verbosity level 2 or higher) has
2772 been requested using the @option{--verbose} option, e.g., when listing
2773 or extracting archives:
2775 @smallexample
2776 $ @kbd{tar -t -v --full-time -f archive.tar}
2777 @end smallexample
2779 @noindent
2780 or, when creating an archive:
2782 @smallexample
2783 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2784 @end smallexample
2786 Notice, thar when creating the archive you need to specify
2787 @option{--verbose} twice to get a detailed output (@pxref{verbose
2788 tutorial}).
2790 @opsummary{group}
2791 @item --group=@var{group}
2793 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2794 rather than the group from the source file.  @var{group} can specify a
2795 symbolic name, or a numeric @acronym{ID}, or both as
2796 @var{name}:@var{id}.  @xref{override}.
2798 Also see the @option{--group-map} option and comments for the
2799 @option{--owner=@var{user}} option.
2801 @opsummary{group-map}
2802 @item --group-map=@var{file}
2804 Read owner group translation map from @var{file}.  This option allows to
2805 translate only certain group names and/or UIDs.  @xref{override}, for a
2806 detailed description.  When used together with @option{--group}
2807 option, the latter affects only those files whose owner group is not listed
2808 in the @var{file}.
2810 This option does not affect extraction from archives.
2812 @opsummary{gzip}
2813 @opsummary{gunzip}
2814 @opsummary{ungzip}
2815 @item --gzip
2816 @itemx --gunzip
2817 @itemx --ungzip
2818 @itemx -z
2820 This option tells @command{tar} to read or write archives through
2821 @command{gzip}, allowing @command{tar} to directly operate on several
2822 kinds of compressed archives transparently.  @xref{gzip}.
2824 @opsummary{hard-dereference}
2825 @item --hard-dereference
2826 When creating an archive, dereference hard links and store the files
2827 they refer to, instead of creating usual hard link members.
2829 @xref{hard links}.
2831 @opsummary{help}
2832 @item --help
2833 @itemx -?
2835 @command{tar} will print out a short message summarizing the operations and
2836 options to @command{tar} and exit. @xref{help}.
2838 @opsummary{hole-detection}
2839 @item --hole-detection=@var{method}
2840 Use @var{method} to detect holes in sparse files.  This option implies
2841 @option{--sparse}.  Valid methods are @samp{seek} and @samp{raw}.
2842 Default is @samp{seek} with fallback to @samp{raw} when not
2843 applicable. @xref{sparse}.
2845 @opsummary{ignore-case}
2846 @item --ignore-case
2847 Ignore case when matching member or file names with
2848 patterns. @xref{controlling pattern-matching}.
2850 @opsummary{ignore-command-error}
2851 @item --ignore-command-error
2852 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2854 @opsummary{ignore-failed-read}
2855 @item --ignore-failed-read
2857 Do not exit unsuccessfully merely because an unreadable file was encountered.
2858 @xref{Ignore Failed Read}.
2860 @opsummary{ignore-zeros}
2861 @item --ignore-zeros
2862 @itemx -i
2864 With this option, @command{tar} will ignore zeroed blocks in the
2865 archive, which normally signals EOF.  @xref{Reading}.
2867 @opsummary{incremental}
2868 @item --incremental
2869 @itemx -G
2871 Informs @command{tar} that it is working with an old
2872 @acronym{GNU}-format incremental backup archive.  It is intended
2873 primarily for backwards compatibility only.  @xref{Incremental Dumps},
2874 for a detailed discussion of incremental archives.
2876 @opsummary{index-file}
2877 @item --index-file=@var{file}
2879 Send verbose output to @var{file} instead of to standard output.
2881 @opsummary{info-script}
2882 @opsummary{new-volume-script}
2883 @item --info-script=@var{command}
2884 @itemx --new-volume-script=@var{command}
2885 @itemx -F @var{command}
2887 When @command{tar} is performing multi-tape backups, @var{command} is run
2888 at the end of each tape.  If it exits with nonzero status,
2889 @command{tar} fails immediately.  @xref{info-script}, for a detailed
2890 discussion of this feature.
2892 @opsummary{interactive}
2893 @item --interactive
2894 @itemx --confirmation
2895 @itemx -w
2897 Specifies that @command{tar} should ask the user for confirmation before
2898 performing potentially destructive options, such as overwriting files.
2899 @xref{interactive}.
2901 @opsummary{keep-directory-symlink}
2902 @item --keep-directory-symlink
2904 This option changes the behavior of tar when it encounters a symlink
2905 with the same name as the directory that it is about to extract.  By
2906 default, in this case tar would first remove the symlink and then
2907 proceed extracting the directory.
2909 The @option{--keep-directory-symlink} option disables this behavior
2910 and instructs tar to follow symlinks to directories when extracting
2911 from the archive.
2913 It is mainly intended to provide compatibility with the Slackware
2914 installation scripts.
2916 @opsummary{keep-newer-files}
2917 @item --keep-newer-files
2919 Do not replace existing files that are newer than their archive copies
2920 when extracting files from an archive.
2922 @opsummary{keep-old-files}
2923 @item --keep-old-files
2924 @itemx -k
2926 Do not overwrite existing files when extracting files from an
2927 archive.  Return error if such files exist.  See also
2928 @ref{--skip-old-files}.
2930 @xref{Keep Old Files}.
2932 @opsummary{label}
2933 @item --label=@var{name}
2934 @itemx -V @var{name}
2936 When creating an archive, instructs @command{tar} to write @var{name}
2937 as a name record in the archive.  When extracting or listing archives,
2938 @command{tar} will only operate on archives that have a label matching
2939 the pattern specified in @var{name}.  @xref{Tape Files}.
2941 @opsummary{level}
2942 @item --level=@var{n}
2943 Force incremental backup of level @var{n}.  As of @GNUTAR version
2944 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2945 file, thereby forcing the level 0 dump.  Other values of @var{n} are
2946 effectively ignored.  @xref{--level=0}, for details and examples.
2948 The use of this option is valid only in conjunction with the
2949 @option{--listed-incremental} option.  @xref{Incremental Dumps},
2950 for a detailed description.
2952 @opsummary{listed-incremental}
2953 @item --listed-incremental=@var{snapshot-file}
2954 @itemx -g @var{snapshot-file}
2956 During a @option{--create} operation, specifies that the archive that
2957 @command{tar} creates is a new @acronym{GNU}-format incremental
2958 backup, using @var{snapshot-file} to determine which files to backup.
2959 With other operations, informs @command{tar} that the archive is in
2960 incremental format.  @xref{Incremental Dumps}.
2962 @opsummary{lzip}
2963 @item --lzip
2965 This option tells @command{tar} to read or write archives through
2966 @command{lzip}.  @xref{gzip}.
2968 @opsummary{lzma}
2969 @item --lzma
2971 This option tells @command{tar} to read or write archives through
2972 @command{lzma}.  @xref{gzip}.
2974 @item --lzop
2976 This option tells @command{tar} to read or write archives through
2977 @command{lzop}.  @xref{gzip}.
2979 @opsummary{mode}
2980 @item --mode=@var{permissions}
2982 When adding files to an archive, @command{tar} will use
2983 @var{permissions} for the archive members, rather than the permissions
2984 from the files.  @var{permissions} can be specified either as an octal
2985 number or as symbolic permissions, like with
2986 @command{chmod}. @xref{override}.
2988 @opsummary{mtime}
2989 @item --mtime=@var{date}
2991 When adding files to an archive, @command{tar} will use @var{date} as
2992 the modification time of members when creating archives, instead of
2993 their actual modification times.  The value of @var{date} can be
2994 either a textual date representation (@pxref{Date input formats}) or a
2995 name of the existing file, starting with @samp{/} or @samp{.}.  In the
2996 latter case, the modification time of that file is used. @xref{override}.
2998 When @command{--clamp-mtime} is also specified, files with
2999 modification times earlier than @var{date} will retain their actual
3000 modification times, and @var{date} will only be used for files whose
3001 modification times are later than @var{date}.
3003 @opsummary{multi-volume}
3004 @item --multi-volume
3005 @itemx -M
3007 Informs @command{tar} that it should create or otherwise operate on a
3008 multi-volume @command{tar} archive.  @xref{Using Multiple Tapes}.
3010 @opsummary{new-volume-script}
3011 @item --new-volume-script
3013 (see @option{--info-script})
3015 @opsummary{newer}
3016 @item --newer=@var{date}
3017 @itemx --after-date=@var{date}
3018 @itemx -N
3020 When creating an archive, @command{tar} will only add files that have changed
3021 since @var{date}.  If @var{date} begins with @samp{/} or @samp{.}, it
3022 is taken to be the name of a file whose data modification time specifies
3023 the date.  @xref{after}.
3025 @opsummary{newer-mtime}
3026 @item --newer-mtime=@var{date}
3028 Like @option{--newer}, but add only files whose
3029 contents have changed (as opposed to just @option{--newer}, which will
3030 also back up files for which any status information has
3031 changed).  @xref{after}.
3033 @opsummary{no-acls}
3034 @item --no-acls
3035 Disable the POSIX ACLs support.  @xref{Extended File Attributes, acls}.
3037 @opsummary{no-anchored}
3038 @item --no-anchored
3039 An exclude pattern can match any subsequence of the name's components.
3040 @xref{controlling pattern-matching}.
3042 @opsummary{no-auto-compress}
3043 @item --no-auto-compress
3045 Disables automatic compressed format recognition based on the archive
3046 suffix.  @xref{--auto-compress}.  @xref{gzip}.
3048 @opsummary{no-check-device}
3049 @item --no-check-device
3050 Do not check device numbers when creating a list of modified files
3051 for incremental archiving.  @xref{device numbers}, for
3052 a detailed description.
3054 @opsummary{no-delay-directory-restore}
3055 @item --no-delay-directory-restore
3057 Modification times and permissions of extracted
3058 directories are set when all files from this directory have been
3059 extracted.  This is the default.
3060 @xref{Directory Modification Times and Permissions}.
3062 @opsummary{no-ignore-case}
3063 @item --no-ignore-case
3064 Use case-sensitive matching.
3065 @xref{controlling pattern-matching}.
3067 @opsummary{no-ignore-command-error}
3068 @item --no-ignore-command-error
3069 Print warnings about subprocesses that terminated with a nonzero exit
3070 code. @xref{Writing to an External Program}.
3072 @opsummary{no-null}
3073 @item --no-null
3075 If the @option{--null} option was given previously, this option
3076 cancels its effect, so that any following @option{--files-from}
3077 options will expect their file lists to be newline-terminated.
3079 @opsummary{no-overwrite-dir}
3080 @item --no-overwrite-dir
3082 Preserve metadata of existing directories when extracting files
3083 from an archive.  @xref{Overwrite Old Files}.
3085 @opsummary{no-quote-chars}
3086 @item --no-quote-chars=@var{string}
3087 Remove characters listed in @var{string} from the list of quoted
3088 characters set by the previous @option{--quote-chars} option
3089 (@pxref{quoting styles}).
3091 @opsummary{no-recursion}
3092 @item --no-recursion
3094 With this option, @command{tar} will not recurse into directories.
3095 @xref{recurse}.
3097 @opsummary{no-same-owner}
3098 @item --no-same-owner
3099 @itemx -o
3101 When extracting an archive, do not attempt to preserve the owner
3102 specified in the @command{tar} archive.  This the default behavior
3103 for ordinary users.
3105 @opsummary{no-same-permissions}
3106 @item --no-same-permissions
3108 When extracting an archive, subtract the user's umask from files from
3109 the permissions specified in the archive.  This is the default behavior
3110 for ordinary users.
3112 @opsummary{no-seek}
3113 @item --no-seek
3115 The archive media does not support seeks to arbitrary
3116 locations.  Usually @command{tar} determines automatically whether
3117 the archive can be seeked or not.  Use this option to disable this
3118 mechanism.
3120 @opsummary{no-selinux}
3121 @item --no-selinux
3122 Disable SELinux context support.  @xref{Extended File Attributes, SELinux}.
3124 @opsummary{no-unquote}
3125 @item --no-unquote
3126 Treat all input file or member names literally, do not interpret
3127 escape sequences.  @xref{input name quoting}.
3129 @opsummary{no-verbatim-files-from}
3130 @item --no-verbatim-files-from
3132 Instructs @GNUTAR{} to treat each line read from a file list as if it
3133 were supplied in the command line.  I.e., leading and trailing
3134 whitespace is removed and, if the result begins with a dash, it is
3135 treated as a @GNUTAR{} command line option.
3137 This is default behavior.  This option is provided as a way to restore
3138 it after @option{--verbatim-files-from} option.
3140 It is implied by the @option{--no-null} option.
3142 @xref{no-verbatim-files-from}.
3144 @opsummary{no-wildcards}
3145 @item --no-wildcards
3146 Do not use wildcards.
3147 @xref{controlling pattern-matching}.
3149 @opsummary{no-wildcards-match-slash}
3150 @item --no-wildcards-match-slash
3151 Wildcards do not match @samp{/}.
3152 @xref{controlling pattern-matching}.
3154 @opsummary{no-xattrs}
3155 @item --no-xattrs
3156 Disable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3158 @opsummary{null}
3159 @item --null
3161 When @command{tar} is using the @option{--files-from} option, this option
3162 instructs @command{tar} to expect file names terminated with
3163 @acronym{NUL}, and to process file names verbatim.
3165 This means that @command{tar} correctly works with file names that
3166 contain newlines or begin with a dash.
3168 @xref{nul}.
3170 See also @ref{verbatim-files-from}.
3172 @opsummary{numeric-owner}
3173 @item --numeric-owner
3175 This option will notify @command{tar} that it should use numeric user
3176 and group IDs when creating a @command{tar} file, rather than names.
3177 @xref{Attributes}.
3179 @item -o
3180 The function of this option depends on the action @command{tar} is
3181 performing.  When extracting files, @option{-o} is a synonym for
3182 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3183 restoring ownership of files being extracted.
3185 When creating an archive, it is a synonym for
3186 @option{--old-archive}.  This behavior is for compatibility
3187 with previous versions of @GNUTAR{}, and will be
3188 removed in future releases.
3190 @xref{Changes}, for more information.
3192 @opsummary{occurrence}
3193 @item --occurrence[=@var{number}]
3195 This option can be used in conjunction with one of the subcommands
3196 @option{--delete}, @option{--diff}, @option{--extract} or
3197 @option{--list} when a list of files is given either on the command
3198 line or via @option{-T} option.
3200 This option instructs @command{tar} to process only the @var{number}th
3201 occurrence of each named file.  @var{Number} defaults to 1, so
3203 @smallexample
3204 tar -x -f archive.tar --occurrence filename
3205 @end smallexample
3207 @noindent
3208 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3209 and will terminate without scanning to the end of the archive.
3211 @opsummary{old-archive}
3212 @item --old-archive
3213 Synonym for @option{--format=v7}.
3215 @opsummary{one-file-system}
3216 @item --one-file-system
3217 Used when creating an archive.  Prevents @command{tar} from recursing into
3218 directories that are on different file systems from the current
3219 directory.
3221 @opsummary{one-top-level}
3222 @item --one-top-level[=@var{dir}]
3223 Tells @command{tar} to create a new directory beneath the extraction directory
3224 (or the one passed to @option{-C}) and use it to guard against
3225 tarbombs.  In the absence of @var{dir} argument, the name of the new directory
3226 will be equal to the base name of the archive (file name minus the
3227 archive suffix, if recognized).  Any member names that do not begin
3228 with that directory name (after
3229 transformations from @option{--transform} and
3230 @option{--strip-components}) will be prefixed with it.  Recognized
3231 file name suffixes are @samp{.tar}, and any compression suffixes
3232 recognizable by @xref{--auto-compress}.
3234 @opsummary{overwrite}
3235 @item --overwrite
3237 Overwrite existing files and directory metadata when extracting files
3238 from an archive.  @xref{Overwrite Old Files}.
3240 @opsummary{overwrite-dir}
3241 @item --overwrite-dir
3243 Overwrite the metadata of existing directories when extracting files
3244 from an archive.  @xref{Overwrite Old Files}.
3246 @opsummary{owner}
3247 @item --owner=@var{user}
3249 Specifies that @command{tar} should use @var{user} as the owner of members
3250 when creating archives, instead of the user associated with the source
3251 file.  @var{user} can specify a symbolic name, or a numeric
3252 @acronym{ID}, or both as @var{name}:@var{id}.
3253 @xref{override}.
3255 This option does not affect extraction from archives.  See also
3256 @option{--owner-map}, below.
3258 @opsummary{owner-map}
3259 @item --owner-map=@var{file}
3261 Read owner translation map from @var{file}.  This option allows to
3262 translate only certain owner names or UIDs.  @xref{override}, for a
3263 detailed description.  When used together with @option{--owner}
3264 option, the latter affects only those files whose owner is not listed
3265 in the @var{file}.
3267 This option does not affect extraction from archives.
3269 @opsummary{pax-option}
3270 @item --pax-option=@var{keyword-list}
3271 This option enables creation of the archive in @acronym{POSIX.1-2001}
3272 format (@pxref{posix}) and modifies the way @command{tar} handles the
3273 extended header keywords.  @var{Keyword-list} is a comma-separated
3274 list of keyword options.  @xref{PAX keywords}, for a detailed
3275 discussion.
3277 @opsummary{portability}
3278 @item --portability
3279 @itemx --old-archive
3280 Synonym for @option{--format=v7}.
3282 @opsummary{posix}
3283 @item --posix
3284 Same as @option{--format=posix}.
3286 @opsummary{preserve-order}
3287 @item --preserve-order
3289 (See @option{--same-order}; @pxref{Reading}.)
3291 @opsummary{preserve-permissions}
3292 @opsummary{same-permissions}
3293 @item --preserve-permissions
3294 @itemx --same-permissions
3295 @itemx -p
3297 When @command{tar} is extracting an archive, it normally subtracts the
3298 users' umask from the permissions specified in the archive and uses
3299 that number as the permissions to create the destination file.
3300 Specifying this option instructs @command{tar} that it should use the
3301 permissions directly from the archive.  @xref{Setting Access Permissions}.
3303 @opsummary{quote-chars}
3304 @item --quote-chars=@var{string}
3305 Always quote characters from @var{string}, even if the selected
3306 quoting style would not quote them (@pxref{quoting styles}).
3308 @opsummary{quoting-style}
3309 @item --quoting-style=@var{style}
3310 Set quoting style to use when printing member and file names
3311 (@pxref{quoting styles}). Valid @var{style} values are:
3312 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3313 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3314 style is @code{escape}, unless overridden while configuring the
3315 package.
3317 @opsummary{read-full-records}
3318 @item --read-full-records
3319 @itemx -B
3321 Specifies that @command{tar} should reblock its input, for reading
3322 from pipes on systems with buggy implementations.  @xref{Reading}.
3324 @opsummary{record-size}
3325 @item --record-size=@var{size}[@var{suf}]
3327 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3328 archive.  The argument can be suffixed with a @dfn{size suffix}, e.g.
3329 @option{--record-size=10K} for 10 Kilobytes.  @xref{size-suffixes},
3330 for a list of valid suffixes.   @xref{Blocking Factor}, for a detailed
3331 description of this option.
3333 @opsummary{recursion}
3334 @item --recursion
3336 With this option, @command{tar} recurses into directories (default).
3337 @xref{recurse}.
3339 @opsummary{recursive-unlink}
3340 @item --recursive-unlink
3342 Remove existing
3343 directory hierarchies before extracting directories of the same name
3344 from the archive.  @xref{Recursive Unlink}.
3346 @opsummary{remove-files}
3347 @item --remove-files
3349 Directs @command{tar} to remove the source file from the file system after
3350 appending it to an archive.  @xref{remove files}.
3352 @opsummary{restrict}
3353 @item --restrict
3355 Disable use of some potentially harmful @command{tar} options.
3356 Currently this option disables shell invocation from multi-volume menu
3357 (@pxref{Using Multiple Tapes}).
3359 @opsummary{rmt-command}
3360 @item --rmt-command=@var{cmd}
3362 Notifies @command{tar} that it should use @var{cmd} instead of
3363 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3365 @opsummary{rsh-command}
3366 @item --rsh-command=@var{cmd}
3368 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3369 devices.  @xref{Device}.
3371 @opsummary{same-order}
3372 @item --same-order
3373 @itemx --preserve-order
3374 @itemx -s
3376 This option is an optimization for @command{tar} when running on machines with
3377 small amounts of memory.  It informs @command{tar} that the list of file
3378 arguments has already been sorted to match the order of files in the
3379 archive.  @xref{Reading}.
3381 @opsummary{same-owner}
3382 @item --same-owner
3384 When extracting an archive, @command{tar} will attempt to preserve the owner
3385 specified in the @command{tar} archive with this option present.
3386 This is the default behavior for the superuser; this option has an
3387 effect only for ordinary users.  @xref{Attributes}.
3389 @opsummary{same-permissions}
3390 @item --same-permissions
3392 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3394 @opsummary{seek}
3395 @item --seek
3396 @itemx -n
3398 Assume that the archive media supports seeks to arbitrary
3399 locations.  Usually @command{tar} determines automatically whether
3400 the archive can be seeked or not.  This option is intended for use
3401 in cases when such recognition fails.  It takes effect only if the
3402 archive is open for reading (e.g. with @option{--list} or
3403 @option{--extract} options).
3405 @opsummary{selinux}
3406 @item --selinux
3407 Enable the SELinux context support.
3408 @xref{Extended File Attributes, selinux}.
3410 @opsummary{show-defaults}
3411 @item --show-defaults
3413 Displays the default options used by @command{tar} and exits
3414 successfully.  This option is intended for use in shell scripts.
3415 Here is an example of what you can see using this option:
3417 @smallexample
3418 $ @kbd{tar --show-defaults}
3419 --format=gnu -f- -b20 --quoting-style=escape
3420 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3421 @end smallexample
3423 @noindent
3424 Notice, that this option outputs only one line.  The example output
3425 above has been split to fit page boundaries. @xref{defaults}.
3427 @opsummary{show-omitted-dirs}
3428 @item --show-omitted-dirs
3430 Instructs @command{tar} to mention the directories it is skipping when
3431 operating on a @command{tar} archive.  @xref{show-omitted-dirs}.
3433 @opsummary{show-snapshot-field-ranges}
3434 @item --show-snapshot-field-ranges
3436 Displays the range of values allowed by this version of @command{tar}
3437 for each field in the snapshot file, then exits successfully.
3438 @xref{Snapshot Files}.
3440 @opsummary{show-transformed-names}
3441 @opsummary{show-stored-names}
3442 @item --show-transformed-names
3443 @itemx --show-stored-names
3445 Display file or member names after applying any transformations
3446 (@pxref{transform}).  In particular, when used in conjunction with one of
3447 the archive creation operations it instructs @command{tar} to list the
3448 member names stored in the archive, as opposed to the actual file
3449 names.  @xref{listing member and file names}.
3451 @opsummary{skip-old-files}
3452 @item --skip-old-files
3454 Do not overwrite existing files when extracting files from an
3455 archive.  @xref{Keep Old Files}.
3457 This option differs from @option{--keep-old-files} in that it does not
3458 treat such files as an error, instead it just silently avoids
3459 overwriting them.
3461 The @option{--warning=existing-file} option can be used together with
3462 this option to produce warning messages about existing old files
3463 (@pxref{warnings}).
3465 @opsummary{sort}
3466 @item --sort=@var{order}
3467 Specify the directory sorting order when reading directories.
3468 @var{Order} may be one of the following:
3470 @table @samp
3471 @item none
3472 No directory sorting is performed. This is the default.
3474 @item name
3475 Sort the directory entries on name. The operating system may deliver
3476 directory entries in a more or less random order, and sorting them
3477 makes archive creation reproducible.
3479 @item inode
3480 Sort the directory entries on inode number. Sorting directories on
3481 inode number may reduce the amount of disk seek operations when
3482 creating an archive for some file systems.
3484 @end table
3486 @opsummary{sparse}
3487 @item --sparse
3488 @itemx -S
3490 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3491 sparse files efficiently.  @xref{sparse}.
3493 @opsummary{sparse-version}
3494 @item --sparse-version=@var{version}
3496 Specifies the @dfn{format version} to use when archiving sparse
3497 files.  Implies @option{--sparse}.  @xref{sparse}. For the description
3498 of the supported sparse formats, @xref{Sparse Formats}.
3500 @opsummary{starting-file}
3501 @item --starting-file=@var{name}
3502 @itemx -K @var{name}
3504 This option affects extraction only; @command{tar} will skip extracting
3505 files in the archive until it finds one that matches @var{name}.
3506 @xref{Scarce}.
3508 @opsummary{strip-components}
3509 @item --strip-components=@var{number}
3510 Strip given @var{number} of leading components from file names before
3511 extraction.  For example, if archive @file{archive.tar} contained
3512 @file{/some/file/name}, then running
3514 @smallexample
3515 tar --extract --file archive.tar --strip-components=2
3516 @end smallexample
3518 @noindent
3519 would extract this file to file @file{name}.
3521 @xref{transform}.
3523 @opsummary{suffix}
3524 @item --suffix=@var{suffix}
3526 Alters the suffix @command{tar} uses when backing up files from the default
3527 @samp{~}.  @xref{backup}.
3529 @opsummary{tape-length}
3530 @item --tape-length=@var{num}[@var{suf}]
3531 @itemx -L @var{num}[@var{suf}]
3533 Specifies the length of tapes that @command{tar} is writing as being
3534 @w{@var{num} x 1024} bytes long.  If optional @var{suf} is given, it
3535 specifies a multiplicative factor to be used instead of 1024.  For
3536 example, @samp{-L2M} means 2 megabytes.  @xref{size-suffixes}, for a
3537 list of allowed suffixes.  @xref{Using Multiple Tapes}, for a detailed
3538 discussion of this option.
3540 @opsummary{test-label}
3541 @item --test-label
3543 Reads the volume label.  If an argument is specified, test whether it
3544 matches the volume label.  @xref{--test-label option}.
3546 @opsummary{to-command}
3547 @item --to-command=@var{command}
3549 During extraction @command{tar} will pipe extracted files to the
3550 standard input of @var{command}.  @xref{Writing to an External Program}.
3552 @opsummary{to-stdout}
3553 @item --to-stdout
3554 @itemx -O
3556 During extraction, @command{tar} will extract files to stdout rather
3557 than to the file system.  @xref{Writing to Standard Output}.
3559 @opsummary{totals}
3560 @item --totals[=@var{signo}]
3562 Displays the total number of bytes transferred when processing an
3563 archive.  If an argument is given, these data are displayed on
3564 request, when signal @var{signo} is delivered to @command{tar}.
3565 @xref{totals}.
3567 @opsummary{touch}
3568 @item --touch
3569 @itemx -m
3571 Sets the data modification time of extracted files to the extraction time,
3572 rather than the data modification time stored in the archive.
3573 @xref{Data Modification Times}.
3575 @opsummary{transform}
3576 @opsummary{xform}
3577 @item --transform=@var{sed-expr}
3578 @itemx --xform=@var{sed-expr}
3579 Transform file or member names using @command{sed} replacement expression
3580 @var{sed-expr}.  For example,
3582 @smallexample
3583 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3584 @end smallexample
3586 @noindent
3587 will add to @file{archive} files from the current working directory,
3588 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3589 discussion, @xref{transform}.
3591 To see transformed member names in verbose listings, use
3592 @option{--show-transformed-names} option
3593 (@pxref{show-transformed-names}).
3595 @opsummary{uncompress}
3596 @item --uncompress
3598 (See @option{--compress}, @pxref{gzip})
3600 @opsummary{ungzip}
3601 @item --ungzip
3603 (See @option{--gzip}, @pxref{gzip})
3605 @opsummary{unlink-first}
3606 @item --unlink-first
3607 @itemx -U
3609 Directs @command{tar} to remove the corresponding file from the file
3610 system before extracting it from the archive.  @xref{Unlink First}.
3612 @opsummary{unquote}
3613 @item --unquote
3614 Enable unquoting input file or member names (default).  @xref{input
3615 name quoting}.
3617 @opsummary{use-compress-program}
3618 @item --use-compress-program=@var{prog}
3619 @itemx -I=@var{prog}
3621 Instructs @command{tar} to access the archive through @var{prog}, which is
3622 presumed to be a compression program of some sort.  @xref{gzip}.
3624 @opsummary{utc}
3625 @item --utc
3627 Display file modification dates in @acronym{UTC}.  This option implies
3628 @option{--verbose}.
3630 @opsummary{verbatim-files-from}
3631 @item --verbatim-files-from
3633 Instructs @GNUTAR{} to treat each line read from a file list as a file
3634 name, even if it starts with a dash.
3636 File lists are supplied with the @option{--files-from} (@option{-T})
3637 option.  By default, each line read from a file list is first trimmed
3638 off the leading and trailing whitespace and, if the result begins with
3639 a dash, it is treated as a @GNUTAR{} command line option.
3641 Use the @option{--verbatim-files-from} option to disable this special
3642 handling.  This facilitates the use of @command{tar} with file lists
3643 created by @command{file} command.
3645 This option affects all @option{--files-from} options that occur after
3646 it in the command line.  Its effect is reverted by the
3647 @option{--no-verbatim-files-from} option.
3649 This option is implied by the @option{--null} option.
3651 @xref{verbatim-files-from}.
3653 @opsummary{verbose}
3654 @item --verbose
3655 @itemx -v
3657 Specifies that @command{tar} should be more verbose about the
3658 operations it is performing.  This option can be specified multiple
3659 times for some operations to increase the amount of information displayed.
3660 @xref{verbose}.
3662 @opsummary{verify}
3663 @item --verify
3664 @itemx -W
3666 Verifies that the archive was correctly written when creating an
3667 archive.  @xref{verify}.
3669 @opsummary{version}
3670 @item --version
3672 Print information about the program's name, version, origin and legal
3673 status, all on standard output, and then exit successfully.
3674 @xref{help}.
3676 @opsummary{volno-file}
3677 @item --volno-file=@var{file}
3679 Used in conjunction with @option{--multi-volume}.  @command{tar} will
3680 keep track of which volume of a multi-volume archive it is working in
3681 @var{file}.  @xref{volno-file}.
3683 @opsummary{warning}
3684 @item --warning=@var{keyword}
3686 Enable or disable warning messages identified by @var{keyword}.  The
3687 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3688 @xref{warnings}.
3690 @opsummary{wildcards}
3691 @item --wildcards
3692 Use wildcards when matching member names with patterns.
3693 @xref{controlling pattern-matching}.
3695 @opsummary{wildcards-match-slash}
3696 @item --wildcards-match-slash
3697 Wildcards match @samp{/}.
3698 @xref{controlling pattern-matching}.
3700 @opsummary{xattrs}
3701 @item --xattrs
3702 Enable extended attributes support.  @xref{Extended File Attributes, xattrs}.
3704 @opsummary{xattrs-exclude}
3705 @item --xattrs-exclude=@var{pattern}
3706 Specify exclude pattern for xattr keys.
3707 @xref{Extended File Attributes, xattrs-exclude}.
3709 @opsummary{xattrs-include}
3710 @item --xattrs-include=@var{pattern}.
3711 Specify include pattern for xattr keys.  @var{pattern} is a globbing
3712 pattern, e.g. @samp{--xattrs-include='user.*'} to include
3713 only attributes from the user namespace.
3714 @xref{Extended File Attributes, xattrs-include}.
3716 @opsummary{xz}
3717 @item --xz
3718 @itemx -J
3719 Use @command{xz} for compressing or decompressing the archives.  @xref{gzip}.
3721 @item --zstd
3722 Use @command{zstd} for compressing or decompressing the archives.  @xref{gzip}.
3724 @end table
3726 @node Short Option Summary
3727 @subsection Short Options Cross Reference
3729 Here is an alphabetized list of all of the short option forms, matching
3730 them with the equivalent long option.
3732 @multitable @columnfractions 0.20 0.80
3733 @headitem Short Option  @tab Reference
3735 @item -A @tab @ref{--concatenate}.
3737 @item -B @tab @ref{--read-full-records}.
3739 @item -C @tab @ref{--directory}.
3741 @item -F @tab @ref{--info-script}.
3743 @item -G @tab @ref{--incremental}.
3745 @item -J @tab @ref{--xz}.
3747 @item -K @tab @ref{--starting-file}.
3749 @item -L @tab @ref{--tape-length}.
3751 @item -M @tab @ref{--multi-volume}.
3753 @item -N @tab @ref{--newer}.
3755 @item -O @tab @ref{--to-stdout}.
3757 @item -P @tab @ref{--absolute-names}.
3759 @item -R @tab @ref{--block-number}.
3761 @item -S @tab @ref{--sparse}.
3763 @item -T @tab @ref{--files-from}.
3765 @item -U @tab @ref{--unlink-first}.
3767 @item -V @tab @ref{--label}.
3769 @item -W @tab @ref{--verify}.
3771 @item -X @tab @ref{--exclude-from}.
3773 @item -Z @tab @ref{--compress}.
3775 @item -b @tab @ref{--blocking-factor}.
3777 @item -c @tab @ref{--create}.
3779 @item -d @tab @ref{--compare}.
3781 @item -f @tab @ref{--file}.
3783 @item -g @tab @ref{--listed-incremental}.
3785 @item -h @tab @ref{--dereference}.
3787 @item -i @tab @ref{--ignore-zeros}.
3789 @item -j @tab @ref{--bzip2}.
3791 @item -k @tab @ref{--keep-old-files}.
3793 @item -l @tab @ref{--check-links}.
3795 @item -m @tab @ref{--touch}.
3797 @item -o @tab When extracting, same as @ref{--no-same-owner}. When creating,
3798 -- @ref{--old-archive}.
3800 The latter usage is deprecated.  It is retained for compatibility with
3801 the earlier versions of @GNUTAR{}.  In future releases
3802 @option{-o} will be equivalent to @option{--no-same-owner} only.
3804 @item -p @tab @ref{--preserve-permissions}.
3806 @item -r @tab @ref{--append}.
3808 @item -s @tab @ref{--same-order}.
3810 @item -t @tab @ref{--list}.
3812 @item -u @tab @ref{--update}.
3814 @item -v @tab @ref{--verbose}.
3816 @item -w @tab @ref{--interactive}.
3818 @item -x @tab @ref{--extract}.
3820 @item -z @tab @ref{--gzip}.
3822 @end multitable
3824 @node Position-Sensitive Options
3825 @subsection Position-Sensitive Options
3827 Some @GNUTAR{} options can be used multiple times in the same
3828 invocation and affect all arguments that appear after them.  These are
3829 options that control how file names are selected and what kind of
3830 pattern matching is used.
3832 The most obvious example is the @option{-C} option.  It instructs @command{tar}
3833 to change to the directory given as its argument prior to processing
3834 the rest of command line (@pxref{directory}).  Thus, in the following
3835 command:
3837 @example
3838 @kbd{tar -c -f a.tar -C /etc passwd -C /var log spool}
3839 @end example
3841 @noindent
3842 the file @file{passwd} will be searched in the directory @file{/etc},
3843 and files @file{log} and @file{spool} -- in @file{/var}.
3845 These options can also be used in a file list supplied with the
3846 @option{--files-from} (@option{-T}) option (@pxref{files}).  In that
3847 case they affect all files (patterns) appearing in that file after
3848 them and remain in effect for any arguments processed after that file.
3849 For example, if the file @file{list.txt} contained:
3851 @example
3852 README
3853 -C src
3854 main.c
3855 @end example
3857 @noindent
3858 and @command{tar} were invoked as follows:
3860 @example
3861 @kbd{tar -c -f a.tar -T list.txt Makefile}
3862 @end example
3864 @noindent
3865 then the file @file{README} would be looked up in the current working
3866 directory, and files @file{main.c} and @file{Makefile} would be looked
3867 up in the directory @file{src}.
3869 Many options can be prefixed with @option{--no-} to cancel the effect
3870 of the original option.
3872 For example, the @option{--recursion} option controls whether to
3873 recurse in the subdirectories.  It's counterpart
3874 @option{--no-recursion} disables this.  Consider the command below.  It will
3875 store in the archive the directory @file{/usr} with all files and
3876 directories that are located in it as well as any files and
3877 directories in @file{/var}, without recursing into them@footnote{The @option{--recursion}
3878 option is the default and is used here for clarity.  The same example
3879 can be written as:
3881 @example
3882 tar -cf a.tar /usr --no-recursion /var/*
3883 @end example
3886 @example
3887 tar -cf a.tar --recursion /usr --no-recursion /var/*
3888 @end example
3890 During archive creation, @GNUTAR{} keeps track of positional options
3891 used and arguments affected by them.  If it finds out that any such
3892 options are used in an obviously erroneous way, the fact is reported
3893 and exit code is set to 2.  E.g.:
3895 @example
3896 @group
3897 $ @kbd{tar -cf a.tar . --exclude '*.o'}
3898 tar: The following options were used after any non-optional
3899 arguments in archive create or update mode.  These options are
3900 positional and affect only arguments that follow them.  Please,
3901 rearrange them properly.
3902 tar: --exclude '*.o' has no effect
3903 tar: Exiting with failure status due to previous errors
3904 @end group
3905 @end example
3907 The following table summarizes all position-sensitive options.
3909 @table @option
3910 @item --directory=@var{dir}
3911 @itemx -C @var{dir}
3912 @xref{directory}.
3914 @item --null
3915 @itemx --no-null
3916 @xref{nul}.
3918 @item --unquote
3919 @itemx --no-unquote
3920 @xref{input name quoting}.
3922 @item --verbatim-files-from
3923 @itemx --no-verbatim-files-from
3924 @xref{verbatim-files-from}.
3926 @item --recursion
3927 @itemx --no-recursion
3928 @xref{recurse}.
3930 @item --anchored
3931 @itemx --no-anchored
3932 @xref{anchored patterns}.
3934 @item --ignore-case
3935 @itemx --no-ignore-case
3936 @xref{case-insensitive matches}.
3938 @item --wildcards
3939 @itemx --no-wildcards
3940 @xref{controlling pattern-matching}.
3942 @item --wildcards-match-slash
3943 @itemx --no-wildcards-match-slash
3944 @xref{controlling pattern-matching}.
3946 @item --exclude
3947 @xref{exclude}.
3949 @item --exclude-from
3950 @itemx -X
3951 @itemx --exclude-caches
3952 @itemx --exclude-caches-under
3953 @itemx --exclude-caches-all
3954 @itemx --exclude-tag
3955 @itemx --exclude-ignore
3956 @itemx --exclude-ignore-recursive
3957 @itemx --exclude-tag-under
3958 @itemx --exclude-tag-all
3959 @itemx --exclude-vcs
3960 @itemx --exclude-vcs-ignores
3961 @itemx --exclude-backups
3962 @xref{exclude}.
3963 @end table
3965 @node help
3966 @section @GNUTAR{} documentation
3968 @cindex Getting program version number
3969 @opindex version
3970 @cindex Version of the @command{tar} program
3971 Being careful, the first thing is really checking that you are using
3972 @GNUTAR{}, indeed.  The @option{--version} option
3973 causes @command{tar} to print information about its name, version,
3974 origin and legal status, all on standard output, and then exit
3975 successfully.  For example, @w{@samp{tar --version}} might print:
3977 @smallexample
3978 tar (GNU tar) @value{VERSION}
3979 Copyright (C) 2013-2020 Free Software Foundation, Inc.
3980 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3981 This is free software: you are free to change and redistribute it.
3982 There is NO WARRANTY, to the extent permitted by law.
3984 Written by John Gilmore and Jay Fenlason.
3985 @end smallexample
3987 @noindent
3988 The first occurrence of @samp{tar} in the result above is the program
3989 name in the package (for example, @command{rmt} is another program),
3990 while the second occurrence of @samp{tar} is the name of the package
3991 itself, containing possibly many programs.  The package is currently
3992 named @samp{tar}, after the name of the main program it
3993 contains@footnote{There are plans to merge the @command{cpio} and
3994 @command{tar} packages into a single one which would be called
3995 @code{paxutils}.  So, who knows if, one of this days, the
3996 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3997 paxutils) 3.2}}.}.
3999 @cindex Obtaining help
4000 @cindex Listing all @command{tar} options
4001 @xopindex{help, introduction}
4002 Another thing you might want to do is checking the spelling or meaning
4003 of some particular @command{tar} option, without resorting to this
4004 manual, for once you have carefully read it.  @GNUTAR{}
4005 has a short help feature, triggerable through the
4006 @option{--help} option.  By using this option, @command{tar} will
4007 print a usage message listing all available options on standard
4008 output, then exit successfully, without doing anything else and
4009 ignoring all other options.  Even if this is only a brief summary, it
4010 may be several screens long.  So, if you are not using some kind of
4011 scrollable window, you might prefer to use something like:
4013 @smallexample
4014 $ @kbd{tar --help | less}
4015 @end smallexample
4017 @noindent
4018 presuming, here, that you like using @command{less} for a pager.  Other
4019 popular pagers are @command{more} and @command{pg}.  If you know about some
4020 @var{keyword} which interests you and do not want to read all the
4021 @option{--help} output, another common idiom is doing:
4023 @smallexample
4024 tar --help | grep @var{keyword}
4025 @end smallexample
4027 @noindent
4028 for getting only the pertinent lines.  Notice, however, that some
4029 @command{tar} options have long description lines and the above
4030 command will list only the first of them.
4032 The exact look of the option summary displayed by @kbd{tar --help} is
4033 configurable. @xref{Configuring Help Summary}, for a detailed description.
4035 @opindex usage
4036 If you only wish to check the spelling of an option, running @kbd{tar
4037 --usage} may be a better choice.  This will display a terse list of
4038 @command{tar} options without accompanying explanations.
4040 The short help output is quite succinct, and you might have to get
4041 back to the full documentation for precise points.  If you are reading
4042 this paragraph, you already have the @command{tar} manual in some
4043 form.  This manual is available in a variety of forms from
4044 @url{http://www.gnu.org/software/tar/manual}.  It may be printed out of the @GNUTAR{}
4045 distribution, provided you have @TeX{} already installed somewhere,
4046 and a laser printer around.  Just configure the distribution, execute
4047 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
4048 usual way (contact your local guru to know how).  If @GNUTAR{}
4049 has been conveniently installed at your place, this
4050 manual is also available in interactive, hypertextual form as an Info
4051 file.  Just call @w{@samp{info tar}} or, if you do not have the
4052 @command{info} program handy, use the Info reader provided within
4053 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
4055 There is currently no @code{man} page for @GNUTAR{}.
4056 If you observe such a @code{man} page on the system you are running,
4057 either it does not belong to @GNUTAR{}, or it has not
4058 been produced by @acronym{GNU}.  Some package maintainers convert
4059 @kbd{tar --help} output to a man page, using @command{help2man}.  In
4060 any case, please bear in mind that the authoritative source of
4061 information about @GNUTAR{} is this Texinfo documentation.
4063 @node defaults
4064 @section Obtaining @GNUTAR{} default values
4066 @opindex show-defaults
4067 @GNUTAR{} has some predefined defaults that are used when you do not
4068 explicitly specify another values.  To obtain a list of such
4069 defaults, use @option{--show-defaults} option.  This will output the
4070 values in the form of @command{tar} command line options:
4072 @smallexample
4073 @group
4074 $ @kbd{tar --show-defaults}
4075 --format=gnu -f- -b20 --quoting-style=escape
4076 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
4077 @end group
4078 @end smallexample
4080 @noindent
4081 Notice, that this option outputs only one line.  The example output above
4082 has been split to fit page boundaries.
4084 @noindent
4085 The above output shows that this version of @GNUTAR{} defaults to
4086 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
4087 output as the archive, if no @option{--file} option has been given
4088 (@pxref{file tutorial}), the default blocking factor is 20
4089 (@pxref{Blocking Factor}).  It also shows the default locations where
4090 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
4092 @node verbose
4093 @section Checking @command{tar} progress
4095 Typically, @command{tar} performs most operations without reporting any
4096 information to the user except error messages.  When using @command{tar}
4097 with many options, particularly ones with complicated or
4098 difficult-to-predict behavior, it is possible to make serious mistakes.
4099 @command{tar} provides several options that make observing @command{tar}
4100 easier.  These options cause @command{tar} to print information as it
4101 progresses in its job, and you might want to use them just for being
4102 more careful about what is going on, or merely for entertaining
4103 yourself.  If you have encountered a problem when operating on an
4104 archive, however, you may need more information than just an error
4105 message in order to solve the problem.  The following options can be
4106 helpful diagnostic tools.
4108 @cindex Verbose operation
4109 @opindex verbose
4110 Normally, the @option{--list} (@option{-t}) command to list an archive
4111 prints just the file names (one per line) and the other commands are
4112 silent. When used with most operations, the @option{--verbose}
4113 (@option{-v}) option causes @command{tar} to print the name of each
4114 file or archive member as it is processed.  This and the other options
4115 which make @command{tar} print status information can be useful in
4116 monitoring @command{tar}.
4118 With @option{--create} or @option{--extract}, @option{--verbose} used
4119 once just prints the names of the files or members as they are processed.
4120 Using it twice causes @command{tar} to print a longer listing
4121 (@xref{verbose member listing}, for the description) for each member.
4122 Since @option{--list} already prints  the names of the members,
4123 @option{--verbose} used once with @option{--list} causes @command{tar}
4124 to print an @samp{ls -l} type listing of the files in the archive.
4125 The following examples both extract members with long list output:
4127 @smallexample
4128 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
4129 $ @kbd{tar xvvf archive.tar}
4130 @end smallexample
4132 Verbose output appears on the standard output except when an archive is
4133 being written to the standard output, as with @samp{tar --create
4134 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
4135 installer let standard output be the default archive).  In that case
4136 @command{tar} writes verbose output to the standard error stream.
4138 If @option{--index-file=@var{file}} is specified, @command{tar} sends
4139 verbose output to @var{file} rather than to standard output or standard
4140 error.
4142 @anchor{totals}
4143 @cindex Obtaining total status information
4144 @opindex totals
4145 The @option{--totals} option causes @command{tar} to print on the
4146 standard error the total amount of bytes transferred when processing
4147 an archive.  When creating or appending to an archive, this option
4148 prints the number of bytes written to the archive and the average
4149 speed at which they have been written, e.g.:
4151 @smallexample
4152 @group
4153 $ @kbd{tar -c -f archive.tar --totals /home}
4154 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
4155 @end group
4156 @end smallexample
4158 When reading an archive, this option displays the number of bytes
4159 read:
4161 @smallexample
4162 @group
4163 $ @kbd{tar -x -f archive.tar --totals}
4164 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
4165 @end group
4166 @end smallexample
4168 Finally, when deleting from an archive, the @option{--totals} option
4169 displays both numbers plus number of bytes removed from the archive:
4171 @smallexample
4172 @group
4173 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
4174 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
4175 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
4176 Total bytes deleted: 1474048
4177 @end group
4178 @end smallexample
4180 You can also obtain this information on request.  When
4181 @option{--totals} is used with an argument, this argument is
4182 interpreted as a symbolic name of a signal, upon delivery of which the
4183 statistics is to be printed:
4185 @table @option
4186 @item --totals=@var{signo}
4187 Print statistics upon delivery of signal @var{signo}.  Valid arguments
4188 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4189 @code{SIGUSR2}.  Shortened names without @samp{SIG} prefix are also
4190 accepted.
4191 @end table
4193 Both forms of @option{--totals} option can be used simultaneously.
4194 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
4195 extract all members from its default archive and print statistics
4196 after finishing the extraction, as well as when receiving signal
4197 @code{SIGUSR1}.
4199 @anchor{Progress information}
4200 @cindex Progress information
4201 The @option{--checkpoint} option prints an occasional message
4202 as @command{tar} reads or writes the archive.  It is designed for
4203 those who don't need the more detailed (and voluminous) output of
4204 @option{--block-number} (@option{-R}), but do want visual confirmation
4205 that @command{tar} is actually making forward progress.  By default it
4206 prints a message each 10 records read or written.  This can be changed
4207 by giving it a numeric argument after an equal sign:
4209 @smallexample
4210 $ @kbd{tar -c --checkpoint=1000} /var
4211 tar: Write checkpoint 1000
4212 tar: Write checkpoint 2000
4213 tar: Write checkpoint 3000
4214 @end smallexample
4216 This example shows the default checkpoint message used by
4217 @command{tar}.  If you place a dot immediately after the equal
4218 sign, it will print a @samp{.} at each checkpoint@footnote{This is
4219 actually a shortcut for @option{--checkpoint=@var{n}
4220 --checkpoint-action=dot}.  @xref{checkpoints, dot}.}.  For example:
4222 @smallexample
4223 $ @kbd{tar -c --checkpoint=.1000} /var
4225 @end smallexample
4227 The @option{--checkpoint} option provides a flexible mechanism for
4228 executing arbitrary actions upon hitting checkpoints, see the next
4229 section (@pxref{checkpoints}), for more information on it.
4231 @opindex show-omitted-dirs
4232 @anchor{show-omitted-dirs}
4233 The @option{--show-omitted-dirs} option, when reading an archive---with
4234 @option{--list} or @option{--extract}, for example---causes a message
4235 to be printed for each directory in the archive which is skipped.
4236 This happens regardless of the reason for skipping: the directory might
4237 not have been named on the command line (implicitly or explicitly),
4238 it might be excluded by the use of the
4239 @option{--exclude=@var{pattern}} option, or some other reason.
4241 @opindex block-number
4242 @cindex Block number where error occurred
4243 @anchor{block-number}
4244 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
4245 every message it would normally produce, the block number within the
4246 archive where the message was triggered.  Also, supplementary messages
4247 are triggered when reading blocks full of NULs, or when hitting end of
4248 file on the archive.  As of now, if the archive is properly terminated
4249 with a NUL block, the reading of the file may stop before end of file
4250 is met, so the position of end of file will not usually show when
4251 @option{--block-number} (@option{-R}) is used.  Note that @GNUTAR{}
4252 drains the archive before exiting when reading the
4253 archive from a pipe.
4255 @cindex Error message, block number of
4256 This option is especially useful when reading damaged archives, since
4257 it helps pinpoint the damaged sections.  It can also be used with
4258 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
4259 choose among several backup tapes when retrieving a file later, in
4260 favor of the tape where the file appears earliest (closest to the
4261 front of the tape).  @xref{backup}.
4263 @node checkpoints
4264 @section Checkpoints
4265 @cindex checkpoints, defined
4266 @opindex checkpoint
4267 @opindex checkpoint-action
4269 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
4270 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
4271 from the archive (a @dfn{read checkpoint}).  Checkpoints allow to
4272 periodically execute arbitrary actions.
4274 The checkpoint facility is enabled using the following option:
4276 @table @option
4277 @xopindex{checkpoint, defined}
4278 @item --checkpoint[=@var{n}]
4279 Schedule checkpoints before writing or reading each @var{n}th record.
4280 The default value for @var{n} is 10.
4281 @end table
4283 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
4284 These actions include: pausing, displaying textual messages, and
4285 executing arbitrary external programs.  Actions are defined using
4286 the @option{--checkpoint-action} option.
4288 @table @option
4289 @xopindex{checkpoint-action, defined}
4290 @item --checkpoint-action=@var{action}
4291 Execute an @var{action} at each checkpoint.
4292 @end table
4294 @cindex @code{echo}, checkpoint action
4295 The simplest value of @var{action} is @samp{echo}.  It instructs
4296 @command{tar} to display the default message on the standard error
4297 stream upon arriving at each checkpoint.  The default message is (in
4298 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
4299 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
4300 Here, @var{n} represents ordinal number of the checkpoint.
4302 In another locales, translated versions of this message are used.
4304 This is the default action, so running:
4306 @smallexample
4307 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
4308 @end smallexample
4310 @noindent
4311 is equivalent to:
4313 @smallexample
4314 $ @kbd{tar -c --checkpoint=1000} /var
4315 @end smallexample
4317 The @samp{echo} action also allows to supply a customized message.
4318 You do so by placing an equals sign and the message right after it,
4319 e.g.:
4321 @smallexample
4322 --checkpoint-action="echo=Hit %s checkpoint #%u"
4323 @end smallexample
4325 The @samp{%s} and @samp{%u} in the above example are
4326 @dfn{format specifiers}.  The @samp{%s} specifier is replaced with
4327 the @dfn{type} of the checkpoint: @samp{write} or
4328 @samp{read} (or a corresponding translated version in locales other
4329 than @acronym{POSIX}).  The @samp{%u} specifier is replaced with
4330 the ordinal number of the checkpoint.  Thus, the above example could
4331 produce the following output when used with the @option{--create}
4332 option:
4334 @smallexample
4335 tar: Hit write checkpoint #10
4336 tar: Hit write checkpoint #20
4337 tar: Hit write checkpoint #30
4338 @end smallexample
4340 The complete list of available format specifiers follows.  Some of
4341 them can take optional arguments.  These arguments, if given, are
4342 supplied in curly braces between the percent sign and the specifier
4343 letter.
4345 @table @samp
4346 @item %s
4347 Print type of the checkpoint (@samp{write} or @samp{read}).
4349 @item %u
4350 Print number of the checkpoint.
4352 @item %@{r,w,d@}T
4353 Print number of bytes transferred so far and approximate transfer
4354 speed.  Optional arguments supply prefixes to be used before number
4355 of bytes read, written and deleted, correspondingly.  If absent,
4356 they default to @samp{R}. @samp{W}, @samp{D}.  Any or all of them can
4357 be omitted, so, that e.g. @samp{%@{@}T} means to print corresponding
4358 statistics without any prefixes.  Any surplus arguments, if present,
4359 are silently ignored.
4361 @example
4362 $ @kbd{tar --delete -f f.tar --checkpoint-action=echo="#%u: %T" main.c}
4363 tar: #1: R: 0 (0B, 0B/s),W: 0 (0B, 0B/s),D: 0
4364 tar: #2: R: 10240 (10KiB, 19MiB/s),W: 0 (0B, 0B/s),D: 10240
4365 @end example
4367 @noindent
4368 See also the @samp{totals} action, described below.
4370 @item %@{@var{fmt}@}t
4371 Output current local time using @var{fmt} as format for @command{strftime}
4372 (@pxref{strftime, strftime,,strftime(3), strftime(3) man page}).  The
4373 @samp{@{@var{fmt}@}} part is optional.  If not present, the default
4374 format is @samp{%c}, i.e. the preferred date and time representation
4375 for the current locale.
4377 @item %@{@var{n}@}*
4378 Pad output with spaces to the @var{n}th column.  If the
4379 @samp{@{@var{n}@}} part is omitted, the current screen width
4380 is assumed.
4382 @item %c
4383 This is a shortcut for @samp{%@{%Y-%m-%d %H:%M:%S@}t: %ds, %@{read,wrote@}T%*\r},
4384 intended mainly for use with @samp{ttyout} action (see below).
4385 @end table
4387 Aside from format expansion, the message string is subject to
4388 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
4389 replaced with their corresponding @acronym{ASCII} characters
4390 (@pxref{escape sequences}).  E.g. the following action will produce an
4391 audible bell and the message described above at each checkpoint:
4393 @smallexample
4394 --checkpoint-action='echo=\aHit %s checkpoint #%u'
4395 @end smallexample
4397 @cindex @code{bell}, checkpoint action
4398 There is also a special action which produces an audible signal:
4399 @samp{bell}.  It is not equivalent to @samp{echo='\a'}, because
4400 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
4401 whereas @samp{echo='\a'} sends it to the standard error.
4403 @cindex @code{ttyout}, checkpoint action
4404 The @samp{ttyout=@var{string}} action outputs @var{string} to
4405 @file{/dev/tty}, so it can be used even if the standard output is
4406 redirected elsewhere.  The @var{string} is subject to the same
4407 modifications as with @samp{echo} action.  In contrast to the latter,
4408 @samp{ttyout} does not prepend @command{tar} executable name to the
4409 string, nor does it output a newline after it.  For example, the
4410 following action will print the checkpoint message at the same screen
4411 line, overwriting any previous message:
4413 @smallexample
4414 --checkpoint-action="ttyout=Hit %s checkpoint #%u%*\r"
4415 @end smallexample
4417 @noindent
4418 Notice the use of @samp{%*} specifier to clear out any eventual
4419 remains of the prior output line.  As as more complex example,
4420 consider this:
4422 @smallexample
4423 --checkpoint-action=ttyout='%@{%Y-%m-%d %H:%M:%S@}t (%d sec): #%u, %T%*\r'
4424 @end smallexample
4426 @noindent
4427 This prints the current local time, number of seconds expired since
4428 tar was started, the checkpoint ordinal number, transferred bytes and
4429 average computed I/O speed.
4431 @cindex @code{dot}, checkpoint action
4432 Another available checkpoint action is @samp{dot} (or @samp{.}).  It
4433 instructs @command{tar} to print a single dot on the standard listing
4434 stream, e.g.:
4436 @smallexample
4437 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4439 @end smallexample
4441 For compatibility with previous @GNUTAR{} versions, this action can
4442 be abbreviated by placing a dot in front of the checkpoint frequency,
4443 as shown in the previous section.
4445 @cindex @code{totals}, checkpoint action
4446 The @samp{totals} action prints the total number of bytes transferred
4447 so far.  The format of the data is the same as for the
4448 @option{--totals} option (@pxref{totals}).  See also @samp{%T} format
4449 specifier of the @samp{echo} or @samp{ttyout} action.
4451 @cindex @code{sleep}, checkpoint action
4452 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4453 amount of seconds.  The following example will stop for 30 seconds at each
4454 checkpoint:
4456 @smallexample
4457 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4458 @end smallexample
4460 @anchor{checkpoint wait}
4461 @cindex @code{wait}, checkpoint action
4462 The @code{wait=@var{signo}} action stops further execution until the
4463 signal @var{signo} is delivered.  Valid values for @var{signo} are:
4464 @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
4465 @code{SIGUSR2}.  The @samp{SIG} prefix is optional.  For example:
4467 @example
4468 $ @kbd{tar -c -f arc --checkpoint=1000 --checkpoint-action wait=USR1 .}
4469 @end example
4471 In this example, @GNUTAR{} will stop archivation at each 1000th
4472 checkpoint. wait until the @samp{SIGUSR1} signal is delivered,
4473 and resume processing.
4475 This action is used by the @command{genfile} utility to perform
4476 modifications on the input files upon hitting certain checkpoints
4477 (@pxref{Exec Mode, genfile}).
4479 @anchor{checkpoint exec}
4480 @cindex @code{exec}, checkpoint action
4481 Finally, the @code{exec} action executes a given external command.
4482 For example:
4484 @smallexample
4485 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4486 @end smallexample
4488 The supplied command can be any valid command invocation, with or
4489 without additional command line arguments.  If it does contain
4490 arguments, don't forget to quote it to prevent it from being split by
4491 the shell.  @xref{external, Running External Commands}, for more detail.
4493 The command gets a copy of @command{tar}'s environment plus the
4494 following variables:
4496 @table @env
4497 @vrindex TAR_VERSION, checkpoint script environment
4498 @item TAR_VERSION
4499 @GNUTAR{} version number.
4501 @vrindex TAR_ARCHIVE, checkpoint script environment
4502 @item TAR_ARCHIVE
4503 The name of the archive @command{tar} is processing.
4505 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4506 @item TAR_BLOCKING_FACTOR
4507 Current blocking factor (@pxref{Blocking}).
4509 @vrindex TAR_CHECKPOINT, checkpoint script environment
4510 @item TAR_CHECKPOINT
4511 Number of the checkpoint.
4513 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4514 @item TAR_SUBCOMMAND
4515 A short option describing the operation @command{tar} is executing.
4516 @xref{Operations}, for a complete list of subcommand options.
4518 @vrindex TAR_FORMAT, checkpoint script environment
4519 @item TAR_FORMAT
4520 Format of the archive being processed. @xref{Formats}, for a complete
4521 list of archive format names.
4522 @end table
4524 These environment variables can also be passed as arguments to the
4525 command, provided that they are properly escaped, for example:
4527 @smallexample
4528 @kbd{tar -c -f arc.tar \
4529      --checkpoint-action='exec=/sbin/cpoint $TAR_CHECKPOINT'}
4530 @end smallexample
4532 @noindent
4533 Notice single quotes to prevent variable names from being expanded by
4534 the shell when invoking @command{tar}.
4536 Any number of actions can be defined, by supplying several
4537 @option{--checkpoint-action} options in the command line.  For
4538 example, the command below displays two messages, pauses
4539 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4541 @example
4542 @group
4543 $ @kbd{tar -c -f arc.tar \
4544        --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4545        --checkpoint-action='echo=Sleeping for 30 seconds' \
4546        --checkpoint-action='sleep=30' \
4547        --checkpoint-action='exec=/sbin/cpoint'}
4548 @end group
4549 @end example
4551 This example also illustrates the fact that
4552 @option{--checkpoint-action} can be used without
4553 @option{--checkpoint}.  In this case, the default checkpoint frequency
4554 (at each 10th record) is assumed.
4556 @node warnings
4557 @section Controlling Warning Messages
4559 Sometimes, while performing the requested task, @GNUTAR{} notices
4560 some conditions that are not exactly errors, but which the user
4561 should be aware of.  When this happens, @command{tar} issues a
4562 @dfn{warning message} describing the condition.  Warning messages
4563 are output to the standard error and they do not affect the exit
4564 code of @command{tar} command.
4566 @xopindex{warning, explained}
4567 @GNUTAR{} allows the user to suppress some or all of its warning
4568 messages:
4570 @table @option
4571 @item --warning=@var{keyword}
4572 Control display of the warning messages identified by @var{keyword}.
4573 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4574 suppressed.  Otherwise, they are enabled.
4576 Multiple @option{--warning} messages accumulate.
4578 The tables below list allowed values for @var{keyword} along with the
4579 warning messages they control.
4580 @end table
4582 @subheading Keywords controlling @command{tar} operation
4583 @table @asis
4584 @kwindex all
4585 @item all
4586 Enable all warning messages.  This is the default.
4587 @kwindex none
4588 @item none
4589 Disable all warning messages.
4590 @kwindex filename-with-nuls
4591 @cindex @samp{file name read contains nul character}, warning message
4592 @item filename-with-nuls
4593 @samp{%s: file name read contains nul character}
4594 @kwindex alone-zero-block
4595 @cindex @samp{A lone zero block at}, warning message
4596 @item alone-zero-block
4597 @samp{A lone zero block at %s}
4598 @end table
4600 @subheading Keywords applicable for @command{tar --create}
4601 @table @asis
4602 @kwindex cachedir
4603 @cindex @samp{contains a cache directory tag}, warning message
4604 @item cachedir
4605 @samp{%s: contains a cache directory tag %s; %s}
4606 @kwindex file-shrank
4607 @cindex @samp{File shrank by %s bytes}, warning message
4608 @item file-shrank
4609 @samp{%s: File shrank by %s bytes; padding with zeros}
4610 @kwindex xdev
4611 @cindex @samp{file is on a different filesystem}, warning message
4612 @item xdev
4613 @samp{%s: file is on a different filesystem; not dumped}
4614 @kwindex file-ignored
4615 @cindex @samp{Unknown file type; file ignored}, warning message
4616 @cindex @samp{socket ignored}, warning message
4617 @cindex @samp{door ignored}, warning message
4618 @item file-ignored
4619 @samp{%s: Unknown file type; file ignored}
4620 @*@samp{%s: socket ignored}
4621 @*@samp{%s: door ignored}
4622 @kwindex file-unchanged
4623 @cindex @samp{file is unchanged; not dumped}, warning message
4624 @item file-unchanged
4625 @samp{%s: file is unchanged; not dumped}
4626 @kwindex ignore-archive
4627 @cindex @samp{file is the archive; not dumped}, warning message
4628 @kwindex ignore-archive
4629 @cindex @samp{file is the archive; not dumped}, warning message
4630 @item ignore-archive
4631 @samp{%s: file is the archive; not dumped}
4632 @kwindex file-removed
4633 @cindex @samp{File removed before we read it}, warning message
4634 @item file-removed
4635 @samp{%s: File removed before we read it}
4636 @kwindex file-changed
4637 @cindex @samp{file changed as we read it}, warning message
4638 @item file-changed
4639 @samp{%s: file changed as we read it}
4640 @item failed-read
4641 Suppresses warnings about unreadable files or directories. This
4642 keyword applies only if used together with the @option{--ignore-failed-read}
4643 option. @xref{Ignore Failed Read}.
4644 @end table
4646 @subheading Keywords applicable for @command{tar --extract}
4647 @table @asis
4648 @kwindex existing-file
4649 @cindex @samp{%s: skipping existing file}, warning message
4650 @item existing-file
4651 @samp{%s: skipping existing file}
4652 @kwindex timestamp
4653 @cindex @samp{implausibly old time stamp %s}, warning message
4654 @cindex @samp{time stamp %s is %s s in the future}, warning message
4655 @item timestamp
4656 @samp{%s: implausibly old time stamp %s}
4657 @*@samp{%s: time stamp %s is %s s in the future}
4658 @kwindex contiguous-cast
4659 @cindex @samp{Extracting contiguous files as regular files}, warning message
4660 @item contiguous-cast
4661 @samp{Extracting contiguous files as regular files}
4662 @kwindex symlink-cast
4663 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4664 @item symlink-cast
4665 @samp{Attempting extraction of symbolic links as hard links}
4666 @kwindex unknown-cast
4667 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4668 @item unknown-cast
4669 @samp{%s: Unknown file type '%c', extracted as normal file}
4670 @kwindex ignore-newer
4671 @cindex @samp{Current %s is newer or same age}, warning message
4672 @item ignore-newer
4673 @samp{Current %s is newer or same age}
4674 @kwindex unknown-keyword
4675 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4676 @item unknown-keyword
4677 @samp{Ignoring unknown extended header keyword '%s'}
4678 @kwindex decompress-program
4679 @item decompress-program
4680 Controls verbose description of failures occurring when trying to run
4681 alternative decompressor programs (@pxref{alternative decompression
4682 programs}).  This warning is disabled by default (unless
4683 @option{--verbose} is used).  A common example of what you can get
4684 when using this warning is:
4686 @smallexample
4687 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4688 tar (child): cannot run compress: No such file or directory
4689 tar (child): trying gzip
4690 @end smallexample
4692 This means that @command{tar} first tried to decompress
4693 @file{archive.Z} using @command{compress}, and, when that
4694 failed, switched to @command{gzip}.
4695 @kwindex record-size
4696 @cindex @samp{Record size = %lu blocks}, warning message
4697 @item record-size
4698 @samp{Record size = %lu blocks}
4699 @end table
4701 @subheading Keywords controlling incremental extraction:
4702 @table @asis
4703 @kwindex rename-directory
4704 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4705 @cindex @samp{%s: Directory has been renamed}, warning message
4706 @item rename-directory
4707 @samp{%s: Directory has been renamed from %s}
4708 @*@samp{%s: Directory has been renamed}
4709 @kwindex new-directory
4710 @cindex @samp{%s: Directory is new}, warning message
4711 @item new-directory
4712 @samp{%s: Directory is new}
4713 @kwindex xdev
4714 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4715 @item xdev
4716 @samp{%s: directory is on a different device: not purging}
4717 @kwindex bad-dumpdir
4718 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4719 @item bad-dumpdir
4720 @samp{Malformed dumpdir: 'X' never used}
4721 @end table
4723 @node interactive
4724 @section Asking for Confirmation During Operations
4725 @cindex Interactive operation
4727 Typically, @command{tar} carries out a command without stopping for
4728 further instructions.  In some situations however, you may want to
4729 exclude some files and archive members from the operation (for instance
4730 if disk or storage space is tight).  You can do this by excluding
4731 certain files automatically (@pxref{Choosing}), or by performing
4732 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4733 @command{tar} also accepts @option{--confirmation} for this option.
4735 @opindex interactive
4736 When the @option{--interactive} (@option{-w}) option is specified, before
4737 reading, writing, or deleting files, @command{tar} first prints a message
4738 for each such file, telling what operation it intends to take, then asks
4739 for confirmation on the terminal.  The actions which require
4740 confirmation include adding a file to the archive, extracting a file
4741 from the archive, deleting a file from the archive, and deleting a file
4742 from disk.  To confirm the action, you must type a line of input
4743 beginning with @samp{y}.  If your input line begins with anything other
4744 than @samp{y}, @command{tar} skips that file.
4746 If @command{tar} is reading the archive from the standard input,
4747 @command{tar} opens the file @file{/dev/tty} to support the interactive
4748 communications.
4750 Verbose output is normally sent to standard output, separate from
4751 other error messages.  However, if the archive is produced directly
4752 on standard output, then verbose output is mixed with errors on
4753 @code{stderr}.  Producing the archive on standard output may be used
4754 as a way to avoid using disk space, when the archive is soon to be
4755 consumed by another process reading it, say.  Some people felt the need
4756 of producing an archive on stdout, still willing to segregate between
4757 verbose output and error output.  A possible approach would be using a
4758 named pipe to receive the archive, and having the consumer process to
4759 read from that named pipe.  This has the advantage of letting standard
4760 output free to receive verbose output, all separate from errors.
4762 @node external
4763 @section Running External Commands
4765 Certain @GNUTAR{} operations imply running external commands that you
4766 supply on the command line.  One of such operations is checkpointing,
4767 described above (@pxref{checkpoint exec}).  Another example of this
4768 feature is the @option{-I} option, which allows you to supply the
4769 program to use for compressing or decompressing the archive
4770 (@pxref{use-compress-program}).
4772 Whenever such operation is requested, @command{tar} first splits the
4773 supplied command into words much like the shell does.  It then treats
4774 the first word as the name of the program or the shell script to execute
4775 and the rest of words as its command line arguments.  The program,
4776 unless given as an absolute file name, is searched in the shell's
4777 @env{PATH}.
4779 Any additional information is normally supplied to external commands
4780 in environment variables, specific to each particular operation.  For
4781 example, the @option{--checkpoint-action=exec} option, defines the
4782 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4783 upon.  You can, should the need be, use these variables in the
4784 command line of the external command.  For example:
4786 @smallexample
4787 $ @kbd{tar -x -f archive.tar \
4788     --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4789 @end smallexample
4791 @noindent
4792 This command prints for each checkpoint its number and the name of the
4793 archive, using the same output line on the screen.
4795 Notice the use of single quotes to prevent variable names from being
4796 expanded by the shell when invoking @command{tar}.
4798 @node operations
4799 @chapter @GNUTAR{} Operations
4801 @menu
4802 * Basic tar::
4803 * Advanced tar::
4804 * create options::
4805 * extract options::
4806 * backup::
4807 * looking ahead::
4808 @end menu
4810 @node Basic tar
4811 @section Basic @GNUTAR{} Operations
4813 The basic @command{tar} operations, @option{--create} (@option{-c}),
4814 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4815 @option{-x}), are currently presented and described in the tutorial
4816 chapter of this manual.  This section provides some complementary notes
4817 for these operations.
4819 @table @option
4820 @xopindex{create, complementary notes}
4821 @item --create
4822 @itemx -c
4824 Creating an empty archive would have some kind of elegance.  One can
4825 initialize an empty archive and later use @option{--append}
4826 (@option{-r}) for adding all members.  Some applications would not
4827 welcome making an exception in the way of adding the first archive
4828 member.  On the other hand, many people reported that it is
4829 dangerously too easy for @command{tar} to destroy a magnetic tape with
4830 an empty archive@footnote{This is well described in @cite{Unix-haters
4831 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4832 Books, ISBN 1-56884-203-1.}.  The two most common errors are:
4834 @enumerate
4835 @item
4836 Mistakingly using @code{create} instead of @code{extract}, when the
4837 intent was to extract the full contents of an archive.  This error
4838 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4839 the QWERTY keyboard.  Instead of being unpacked, the archive then
4840 gets wholly destroyed.  When users speak about @dfn{exploding} an
4841 archive, they usually mean something else :-).
4843 @item
4844 Forgetting the argument to @code{file}, when the intent was to create
4845 an archive with a single file in it.  This error is likely because a
4846 tired user can easily add the @kbd{f} key to the cluster of option
4847 letters, by the mere force of habit, without realizing the full
4848 consequence of doing so.  The usual consequence is that the single
4849 file, which was meant to be saved, is rather destroyed.
4850 @end enumerate
4852 So, recognizing the likelihood and the catastrophic nature of these
4853 errors, @GNUTAR{} now takes some distance from elegance, and
4854 cowardly refuses to create an archive when @option{--create} option is
4855 given, there are no arguments besides options, and
4856 @option{--files-from} (@option{-T}) option is @emph{not} used.  To get
4857 around the cautiousness of @GNUTAR{} and nevertheless create an
4858 archive with nothing in it, one may still use, as the value for the
4859 @option{--files-from} option, a file with no names in it, as shown in
4860 the following commands:
4862 @smallexample
4863 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4864 @kbd{tar -cf empty-archive.tar -T /dev/null}
4865 @end smallexample
4867 @xopindex{extract, complementary notes}
4868 @item --extract
4869 @itemx --get
4870 @itemx -x
4872 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4874 @item @option{--list} (@option{-t})
4876 @GNUTAR{} now shows dates as @samp{1996-08-30},
4877 while it used to show them as @samp{Aug 30 1996}. Preferably,
4878 people should get used to ISO 8601 dates.  Local American dates should
4879 be made available again with full date localization support, once
4880 ready.  In the meantime, programs not being localizable for dates
4881 should prefer international dates, that's really the way to go.
4883 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4884 are curious, it contains a detailed explanation of the ISO 8601 standard.
4886 @end table
4888 @node Advanced tar
4889 @section Advanced @GNUTAR{} Operations
4891 Now that you have learned the basics of using @GNUTAR{}, you may want
4892 to learn about further ways in which @command{tar} can help you.
4894 This chapter presents five, more advanced operations which you probably
4895 won't use on a daily basis, but which serve more specialized functions.
4896 We also explain the different styles of options and why you might want
4897 to use one or another, or a combination of them in your @command{tar}
4898 commands.  Additionally, this chapter includes options which allow you to
4899 define the output from @command{tar} more carefully, and provide help and
4900 error correction in special circumstances.
4902 @FIXME{check this after the chapter is actually revised to make sure
4903 it still introduces the info in the chapter correctly : ).}
4905 @menu
4906 * Operations::
4907 * append::
4908 * update::
4909 * concatenate::
4910 * delete::
4911 * compare::
4912 @end menu
4914 @node Operations
4915 @subsection The Five Advanced @command{tar} Operations
4917 @cindex basic operations
4918 In the last chapter, you learned about the first three operations to
4919 @command{tar}.  This chapter presents the remaining five operations to
4920 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4921 @option{--delete}, and @option{--compare}.
4923 You are not likely to use these operations as frequently as those
4924 covered in the last chapter; however, since they perform specialized
4925 functions, they are quite useful when you do need to use them.  We
4926 will give examples using the same directory and files that you created
4927 in the last chapter.  As you may recall, the directory is called
4928 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4929 and the two archive files you created are
4930 @samp{collection.tar} and @samp{music.tar}.
4932 We will also use the archive files @samp{afiles.tar} and
4933 @samp{bfiles.tar}.  The archive @samp{afiles.tar} contains the members @samp{apple},
4934 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4935 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4937 Unless we state otherwise, all practicing you do and examples you follow
4938 in this chapter will take place in the @file{practice} directory that
4939 you created in the previous chapter; see @ref{prepare for examples}.
4940 (Below in this section, we will remind you of the state of the examples
4941 where the last chapter left them.)
4943 The five operations that we will cover in this chapter are:
4945 @table @option
4946 @item --append
4947 @itemx -r
4948 Add new entries to an archive that already exists.
4949 @item --update
4950 @itemx -u
4951 Add more recent copies of archive members to the end of an archive, if
4952 they exist.
4953 @item --concatenate
4954 @itemx --catenate
4955 @itemx -A
4956 Add one or more pre-existing archives to the end of another archive.
4957 @item --delete
4958 Delete items from an archive (does not work on tapes).
4959 @item --compare
4960 @itemx --diff
4961 @itemx -d
4962 Compare archive members to their counterparts in the file system.
4963 @end table
4965 @node append
4966 @subsection How to Add Files to Existing Archives: @option{--append}
4968 @cindex appending files to existing archive
4969 @opindex append
4970 If you want to add files to an existing archive, you don't need to
4971 create a new archive; you can use @option{--append} (@option{-r}).
4972 The archive must already exist in order to use @option{--append}.  (A
4973 related operation is the @option{--update} operation; you can use this
4974 to add newer versions of archive members to an existing archive.  To learn how to
4975 do this with @option{--update}, @pxref{update}.)
4977 If you use @option{--append} to add a file that has the same name as an
4978 archive member to an archive containing that archive member, then the
4979 old member is not deleted.  What does happen, however, is somewhat
4980 complex.  @command{tar} @emph{allows} you to have infinite number of files
4981 with the same name.  Some operations treat these same-named members no
4982 differently than any other set of archive members: for example, if you
4983 view an archive with @option{--list} (@option{-t}), you will see all
4984 of those members listed, with their data modification times, owners, etc.
4986 Other operations don't deal with these members as perfectly as you might
4987 prefer; if you were to use @option{--extract} to extract the archive,
4988 only the most recently added copy of a member with the same name as
4989 other members would end up in the working directory.  This is because
4990 @option{--extract} extracts an archive in the order the members appeared
4991 in the archive; the most recently archived members will be extracted
4992 last.  Additionally, an extracted member will @emph{replace} a file of
4993 the same name which existed in the directory already, and @command{tar}
4994 will not prompt you about this@footnote{Unless you give it
4995 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4996 the disk copy is newer than the one in the archive and you invoke
4997 @command{tar} with @option{--keep-newer-files} option.}.  Thus, only
4998 the most recently archived member will end up being extracted, as it
4999 will replace the one extracted before it, and so on.
5001 @cindex extracting @var{n}th copy of the file
5002 @xopindex{occurrence, described}
5003 There exists a special option that allows you to get around this
5004 behavior and extract (or list) only a particular copy of the file.
5005 This is @option{--occurrence} option.  If you run @command{tar} with
5006 this option, it will extract only the first copy of the file.  You
5007 may also give this option an argument specifying the number of
5008 copy to be extracted.  Thus, for example if the archive
5009 @file{archive.tar} contained three copies of file @file{myfile}, then
5010 the command
5012 @smallexample
5013 tar --extract --file archive.tar --occurrence=2 myfile
5014 @end smallexample
5016 @noindent
5017 would extract only the second copy.  @xref{Option
5018 Summary,---occurrence}, for the description of @option{--occurrence}
5019 option.
5021 @FIXME{ hag -- you might want to incorporate some of the above into the
5022 MMwtSN node; not sure.  i didn't know how to make it simpler...
5024 There are a few ways to get around this.  Xref to Multiple Members
5025 with the Same Name, maybe.}
5027 @cindex Members, replacing with other members
5028 @cindex Replacing members with other members
5029 @xopindex{delete, using before --append}
5030 If you want to replace an archive member, use @option{--delete} to
5031 delete the member you want to remove from the archive, and then use
5032 @option{--append} to add the member you want to be in the archive.  Note
5033 that you can not change the order of the archive; the most recently
5034 added member will still appear last.  In this sense, you cannot truly
5035 ``replace'' one member with another.  (Replacing one member with another
5036 will not work on certain types of media, such as tapes; see @ref{delete}
5037 and @ref{Media}, for more information.)
5039 @menu
5040 * appending files::             Appending Files to an Archive
5041 * multiple::
5042 @end menu
5044 @node appending files
5045 @subsubsection Appending Files to an Archive
5046 @cindex Adding files to an Archive
5047 @cindex Appending files to an Archive
5048 @cindex Archives, Appending files to
5049 @opindex append
5051 The simplest way to add a file to an already existing archive is the
5052 @option{--append} (@option{-r}) operation, which writes specified
5053 files into the archive whether or not they are already among the
5054 archived files.
5056 When you use @option{--append}, you @emph{must} specify file name
5057 arguments, as there is no default.  If you specify a file that already
5058 exists in the archive, another copy of the file will be added to the
5059 end of the archive.  As with other operations, the member names of the
5060 newly added files will be exactly the same as their names given on the
5061 command line.  The @option{--verbose} (@option{-v}) option will print
5062 out the names of the files as they are written into the archive.
5064 @option{--append} cannot be performed on some tape drives, unfortunately,
5065 due to deficiencies in the formats those tape drives use.  The archive
5066 must be a valid @command{tar} archive, or else the results of using this
5067 operation will be unpredictable.  @xref{Media}.
5069 To demonstrate using @option{--append} to add a file to an archive,
5070 create a file called @file{rock} in the @file{practice} directory.
5071 Make sure you are in the @file{practice} directory.  Then, run the
5072 following @command{tar} command to add @file{rock} to
5073 @file{collection.tar}:
5075 @smallexample
5076 $ @kbd{tar --append --file=collection.tar rock}
5077 @end smallexample
5079 @noindent
5080 If you now use the @option{--list} (@option{-t}) operation, you will see that
5081 @file{rock} has been added to the archive:
5083 @smallexample
5084 $ @kbd{tar --list --file=collection.tar}
5085 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5086 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5087 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5088 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5089 @end smallexample
5091 @node multiple
5092 @subsubsection Multiple Members with the Same Name
5093 @cindex members, multiple
5094 @cindex multiple members
5096 You can use @option{--append} (@option{-r}) to add copies of files
5097 which have been updated since the archive was created.  (However, we
5098 do not recommend doing this since there is another @command{tar}
5099 option called @option{--update}; @xref{update}, for more information.
5100 We describe this use of @option{--append} here for the sake of
5101 completeness.)  When you extract the archive, the older version will
5102 be effectively lost.  This works because files are extracted from an
5103 archive in the order in which they were archived.  Thus, when the
5104 archive is extracted, a file archived later in time will replace a
5105 file of the same name which was archived earlier, even though the
5106 older version of the file will remain in the archive unless you delete
5107 all versions of the file.
5109 Supposing you change the file @file{blues} and then append the changed
5110 version to @file{collection.tar}.  As you saw above, the original
5111 @file{blues} is in the archive @file{collection.tar}.  If you change the
5112 file and append the new version of the file to the archive, there will
5113 be two copies in the archive.  When you extract the archive, the older
5114 version of the file will be extracted first, and then replaced by the
5115 newer version when it is extracted.
5117 You can append the new, changed copy of the file @file{blues} to the
5118 archive in this way:
5120 @smallexample
5121 $ @kbd{tar --append --verbose --file=collection.tar blues}
5122 blues
5123 @end smallexample
5125 @noindent
5126 Because you specified the @option{--verbose} option, @command{tar} has
5127 printed the name of the file being appended as it was acted on.  Now
5128 list the contents of the archive:
5130 @smallexample
5131 $ @kbd{tar --list --verbose --file=collection.tar}
5132 -rw-r--r-- me/user          28 1996-10-18 16:31 jazz
5133 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5134 -rw-r--r-- me/user          20 1996-09-23 16:44 folk
5135 -rw-r--r-- me/user          20 1996-09-23 16:44 rock
5136 -rw-r--r-- me/user          58 1996-10-24 18:30 blues
5137 @end smallexample
5139 @noindent
5140 The newest version of @file{blues} is now at the end of the archive
5141 (note the different creation dates and file sizes).  If you extract
5142 the archive, the older version of the file @file{blues} will be
5143 replaced by the newer version.  You can confirm this by extracting
5144 the archive and running @samp{ls} on the directory.
5146 If you wish to extract the first occurrence of the file @file{blues}
5147 from the archive, use @option{--occurrence} option, as shown in
5148 the following example:
5150 @smallexample
5151 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
5152 -rw-r--r-- me/user          21 1996-09-23 16:44 blues
5153 @end smallexample
5155 @xref{Writing}, for more information on @option{--extract} and
5156 see @ref{Option Summary, --occurrence}, for a description of
5157 @option{--occurrence} option.
5159 @node update
5160 @subsection Updating an Archive
5161 @cindex Updating an archive
5162 @opindex update
5164 In the previous section, you learned how to use @option{--append} to
5165 add a file to an existing archive.  A related operation is
5166 @option{--update} (@option{-u}).  The @option{--update} operation
5167 updates a @command{tar} archive by comparing the date of the specified
5168 archive members against the date of the file with the same name.  If
5169 the file has been modified more recently than the archive member, then
5170 the newer version of the file is added to the archive (as with
5171 @option{--append}).
5173 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
5174 The operation will fail.
5176 @FIXME{other examples of media on which --update will fail?  need to ask
5177 charles and/or mib/thomas/dave shevett..}
5179 Both @option{--update} and @option{--append} work by adding to the end
5180 of the archive.  When you extract a file from the archive, only the
5181 version stored last will wind up in the file system, unless you use
5182 the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
5184 @menu
5185 * how to update::
5186 @end menu
5188 @node how to update
5189 @subsubsection How to Update an Archive Using @option{--update}
5190 @opindex update
5192 You must use file name arguments with the @option{--update}
5193 (@option{-u}) operation.  If you don't specify any files,
5194 @command{tar} won't act on any files and won't tell you that it didn't
5195 do anything (which may end up confusing you).
5197 @c note: the above parenthetical added because in fact, this
5198 @c behavior just confused the author. :-)
5200 To see the @option{--update} option at work, create a new file,
5201 @file{classical}, in your practice directory, and some extra text to the
5202 file @file{blues}, using any text editor.  Then invoke @command{tar} with
5203 the @samp{update} operation and the @option{--verbose} (@option{-v})
5204 option specified, using the names of all the files in the @file{practice}
5205 directory as file name arguments:
5207 @smallexample
5208 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
5209 blues
5210 classical
5212 @end smallexample
5214 @noindent
5215 Because we have specified verbose mode, @command{tar} prints out the names
5216 of the files it is working on, which in this case are the names of the
5217 files that needed to be updated.  If you run @samp{tar --list} and look
5218 at the archive, you will see @file{blues} and @file{classical} at its
5219 end.  There will be a total of two versions of the member @samp{blues};
5220 the one at the end will be newer and larger, since you added text before
5221 updating it.
5223 The reason @command{tar} does not overwrite the older file when updating
5224 it is that writing to the middle of a section of tape is a difficult
5225 process.  Tapes are not designed to go backward.  @xref{Media}, for more
5226 information about tapes.
5228 @option{--update} (@option{-u}) is not suitable for performing backups for two
5229 reasons: it does not change directory content entries, and it
5230 lengthens the archive every time it is used.  The @GNUTAR{}
5231 options intended specifically for backups are more
5232 efficient.  If you need to run backups, please consult @ref{Backups}.
5234 @node concatenate
5235 @subsection Combining Archives with @option{--concatenate}
5237 @cindex Adding archives to an archive
5238 @cindex Concatenating Archives
5239 @opindex concatenate
5240 @opindex catenate
5241 @c @cindex @option{-A} described
5242 Sometimes it may be convenient to add a second archive onto the end of
5243 an archive rather than adding individual files to the archive.  To add
5244 one or more archives to the end of another archive, you should use the
5245 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
5247 To use @option{--concatenate}, give the first archive with
5248 @option{--file} option and name the rest of archives to be
5249 concatenated on the command line.  The members, and their member
5250 names, will be copied verbatim from those archives to the first
5251 one@footnote{This can cause multiple members to have the same name.  For
5252 information on how this affects reading the archive, see @ref{multiple}.}.
5253 The new, concatenated archive will be called by the same name as the
5254 one given with the @option{--file} option.  As usual, if you omit
5255 @option{--file}, @command{tar} will use the value of the environment
5256 variable @env{TAPE}, or, if this has not been set, the default archive name.
5258 @FIXME{There is no way to specify a new name...}
5260 To demonstrate how @option{--concatenate} works, create two small archives
5261 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
5262 files from @file{practice}:
5264 @smallexample
5265 $ @kbd{tar -cvf bluesrock.tar blues rock}
5266 blues
5267 rock
5268 $ @kbd{tar -cvf folkjazz.tar folk jazz}
5269 folk
5270 jazz
5271 @end smallexample
5273 @noindent
5274 If you like, You can run @samp{tar --list} to make sure the archives
5275 contain what they are supposed to:
5277 @smallexample
5278 $ @kbd{tar -tvf bluesrock.tar}
5279 -rw-r--r-- melissa/user    105 1997-01-21 19:42 blues
5280 -rw-r--r-- melissa/user     33 1997-01-20 15:34 rock
5281 $ @kbd{tar -tvf jazzfolk.tar}
5282 -rw-r--r-- melissa/user     20 1996-09-23 16:44 folk
5283 -rw-r--r-- melissa/user     65 1997-01-30 14:15 jazz
5284 @end smallexample
5286 We can concatenate these two archives with @command{tar}:
5288 @smallexample
5289 $ @kbd{cd ..}
5290 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
5291 @end smallexample
5293 If you now list the contents of the @file{bluesrock.tar}, you will see
5294 that now it also contains the archive members of @file{jazzfolk.tar}:
5296 @smallexample
5297 $ @kbd{tar --list --file=bluesrock.tar}
5298 blues
5299 rock
5300 folk
5301 jazz
5302 @end smallexample
5304 When you use @option{--concatenate}, the source and target archives must
5305 already exist and must have been created using compatible format
5306 parameters.  Notice, that @command{tar} does not check whether the
5307 archives it concatenates have compatible formats, it does not
5308 even check if the files are really tar archives.
5310 Like @option{--append} (@option{-r}), this operation cannot be performed on some
5311 tape drives, due to deficiencies in the formats those tape drives use.
5313 @cindex @code{concatenate} vs @command{cat}
5314 @cindex @command{cat} vs @code{concatenate}
5315 It may seem more intuitive to you to want or try to use @command{cat} to
5316 concatenate two archives instead of using the @option{--concatenate}
5317 operation; after all, @command{cat} is the utility for combining files.
5319 However, @command{tar} archives incorporate an end-of-file marker which
5320 must be removed if the concatenated archives are to be read properly as
5321 one archive.  @option{--concatenate} removes the end-of-archive marker
5322 from the target archive before each new archive is appended.  If you use
5323 @command{cat} to combine the archives, the result will not be a valid
5324 @command{tar} format archive.  If you need to retrieve files from an
5325 archive that was added to using the @command{cat} utility, use the
5326 @option{--ignore-zeros} (@option{-i}) option.  @xref{Ignore Zeros}, for further
5327 information on dealing with archives improperly combined using the
5328 @command{cat} shell utility.
5330 @node delete
5331 @subsection Removing Archive Members Using @option{--delete}
5332 @cindex Deleting files from an archive
5333 @cindex Removing files from an archive
5335 @opindex delete
5336 You can remove members from an archive by using the @option{--delete}
5337 option.  Specify the name of the archive with @option{--file}
5338 (@option{-f}) and then specify the names of the members to be deleted;
5339 if you list no member names, nothing will be deleted.  The
5340 @option{--verbose} option will cause @command{tar} to print the names
5341 of the members as they are deleted. As with @option{--extract}, you
5342 must give the exact member names when using @samp{tar --delete}.
5343 @option{--delete} will remove all versions of the named file from the
5344 archive.  The @option{--delete} operation can run very slowly.
5346 Unlike other operations, @option{--delete} has no short form.
5348 @cindex Tapes, using @option{--delete} and
5349 @cindex Deleting from tape archives
5350 This operation will rewrite the archive.  You can only use
5351 @option{--delete} on an archive if the archive device allows you to
5352 write to any point on the media, such as a disk; because of this, it
5353 does not work on magnetic tapes.  Do not try to delete an archive member
5354 from a magnetic tape; the action will not succeed, and you will be
5355 likely to scramble the archive and damage your tape.  There is no safe
5356 way (except by completely re-writing the archive) to delete files from
5357 most kinds of magnetic tape.  @xref{Media}.
5359 To delete all versions of the file @file{blues} from the archive
5360 @file{collection.tar} in the @file{practice} directory, make sure you
5361 are in that directory, and then,
5363 @smallexample
5364 $ @kbd{tar --list --file=collection.tar}
5365 blues
5366 folk
5367 jazz
5368 rock
5369 $ @kbd{tar --delete --file=collection.tar blues}
5370 $ @kbd{tar --list --file=collection.tar}
5371 folk
5372 jazz
5373 rock
5374 @end smallexample
5376 @FIXME{Check if the above listing is actually produced after running
5377 all the examples on collection.tar.}
5379 The @option{--delete} option has been reported to work properly when
5380 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
5382 @node compare
5383 @subsection Comparing Archive Members with the File System
5384 @cindex Verifying the currency of an archive
5386 @opindex compare
5387 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
5388 specified archive members against files with the same names, and then
5389 reports differences in file size, mode, owner, modification date and
5390 contents.  You should @emph{only} specify archive member names, not file
5391 names.  If you do not name any members, then @command{tar} will compare the
5392 entire archive.  If a file is represented in the archive but does not
5393 exist in the file system, @command{tar} reports a difference.
5395 You have to specify the record size of the archive when modifying an
5396 archive with a non-default record size.
5398 @command{tar} ignores files in the file system that do not have
5399 corresponding members in the archive.
5401 The following example compares the archive members @file{rock},
5402 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
5403 files of the same name in the file system.  (Note that there is no file,
5404 @file{funk}; @command{tar} will report an error message.)
5406 @smallexample
5407 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
5408 rock
5409 blues
5410 tar: funk not found in archive
5411 @end smallexample
5413 The spirit behind the @option{--compare} (@option{--diff},
5414 @option{-d}) option is to check whether the archive represents the
5415 current state of files on disk, more than validating the integrity of
5416 the archive media.  For this latter goal, see @ref{verify}.
5418 @node create options
5419 @section Options Used by @option{--create}
5421 @xopindex{create, additional options}
5422 The previous chapter described the basics of how to use
5423 @option{--create} (@option{-c}) to create an archive from a set of files.
5424 @xref{create}.  This section described advanced options to be used with
5425 @option{--create}.
5427 @menu
5428 * override::                  Overriding File Metadata.
5429 * Extended File Attributes::
5430 * Ignore Failed Read::
5431 @end menu
5433 @node override
5434 @subsection Overriding File Metadata
5436 As described above, a @command{tar} archive keeps, for each member it contains,
5437 its @dfn{metadata}, such as modification time, mode and ownership of
5438 the file.  @GNUTAR{} allows to replace these data with other values
5439 when adding files to the archive.  The options described in this
5440 section affect creation of archives of any type.  For POSIX archives,
5441 see also @ref{PAX keywords}, for additional ways of controlling
5442 metadata, stored in the archive.
5444 @table @option
5445 @opindex mode
5446 @item --mode=@var{permissions}
5448 When adding files to an archive, @command{tar} will use
5449 @var{permissions} for the archive members, rather than the permissions
5450 from the files.  @var{permissions} can be specified either as an octal
5451 number or as symbolic permissions, like with
5452 @command{chmod} (@xref{File permissions, Permissions, File
5453 permissions, fileutils, @acronym{GNU} file utilities}.  This reference
5454 also has useful information for those not being overly familiar with
5455 the UNIX permission system).  Using latter syntax allows for
5456 more flexibility.  For example, the value @samp{a+rw} adds read and write
5457 permissions for everybody, while retaining executable bits on directories
5458 or on any other file already marked as executable:
5460 @smallexample
5461 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5462 @end smallexample
5464 @item --mtime=@var{date}
5465 @opindex mtime
5467 When adding files to an archive, @command{tar} will use @var{date} as
5468 the modification time of members when creating archives, instead of
5469 their actual modification times.  The argument @var{date} can be
5470 either a textual date representation in almost arbitrary format
5471 (@pxref{Date input formats}) or a name of an existing file, starting
5472 with @samp{/} or @samp{.}.  In the latter case, the modification time
5473 of that file will be used.
5475 The following example will set the modification date to 00:00:00,
5476 January 1, 1970:
5478 @smallexample
5479 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
5480 @end smallexample
5482 @noindent
5483 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5484 will try to convert the specified date back to its textual
5485 representation and compare it with the one given with
5486 @option{--mtime} options.  If the two dates differ, @command{tar} will
5487 print a warning saying what date it will use.  This is to help user
5488 ensure he is using the right date.
5490 For example:
5492 @smallexample
5493 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5494 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5495 13:06:29.152478
5496 @dots{}
5497 @end smallexample
5499 @noindent
5500 When used with @option{--clamp-mtime} @GNUTAR{} will only set the
5501 modification date to @var{date} on files whose actual modification
5502 date is later than @var{date}.  This is to make it easy to build
5503 reproducible archives given a common timestamp for generated files
5504 while still retaining the original timestamps of untouched files.
5506 @smallexample
5507 $ @kbd{tar -c -f archive.tar --clamp-mtime --mtime=@@$SOURCE_DATE_EPOCH .}
5508 @end smallexample
5510 @item --owner=@var{user}
5511 @opindex owner
5513 Specifies that @command{tar} should use @var{user} as the owner of members
5514 when creating archives, instead of the user associated with the source
5515 file.
5517 If @var{user} contains a colon, it is taken to be of the form
5518 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5519 name and a nonempty @var{id} specifies the decimal numeric user
5520 @acronym{ID}.  If @var{user} does not contain a colon, it is taken to
5521 be a user number if it is one or more decimal digits; otherwise it is
5522 taken to be a user name.
5524 If a name is given but no number, the number is inferred from the
5525 current host's user database if possible, and the file's user number
5526 is used otherwise.  If a number is given but no name, the name is
5527 inferred from the number if possible, and an empty name is used
5528 otherwise.  If both name and number are given, the user database is
5529 not consulted, and the name and number need not be valid on the
5530 current host.
5532 There is no value indicating a missing number, and @samp{0} usually means
5533 @code{root}.  Some people like to force @samp{0} as the value to offer in
5534 their distributions for the owner of files, because the @code{root} user is
5535 anonymous anyway, so that might as well be the owner of anonymous
5536 archives.  For example:
5538 @smallexample
5539 $ @kbd{tar -c -f archive.tar --owner=0 .}
5540 @end smallexample
5542 @noindent
5545 @smallexample
5546 $ @kbd{tar -c -f archive.tar --owner=root .}
5547 @end smallexample
5549 @item --group=@var{group}
5550 @opindex group
5552 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5553 rather than the group from the source file.  As with @option{--owner},
5554 the argument @var{group} can be an existing group symbolic name, or a
5555 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5556 @end table
5558 The @option{--owner} and @option{--group} options affect all files
5559 added to the archive.  @GNUTAR{} provides also two options that allow
5560 for more detailed control over owner translation:
5562 @table @option
5563 @item --owner-map=@var{file}
5564 Read UID translation map from @var{file}.
5566 When reading, empty lines are ignored.  The @samp{#} sign, unless
5567 quoted, introduces a comment, which extends to the end of the line.
5568 Each nonempty line defines mapping for a single UID.  It must consist
5569 of two fields separated by any amount of whitespace.  The first field
5570 defines original username and UID.  It can be a valid user name or
5571 a valid UID prefixed with a plus sign.  In both cases the
5572 corresponding UID or user name is inferred from the current host's
5573 user database.
5575 The second field defines the UID and username to map the original one
5576 to.  Its format can be the same as described above.  Otherwise, it can
5577 have the form @var{newname}:@var{newuid}, in which case neither
5578 @var{newname} nor @var{newuid} are required to be valid as per the
5579 user database.
5581 For example, consider the following file:
5583 @example
5584 +10     bin
5585 smith   root:0
5586 @end example
5588 @noindent
5589 Given this file, each input file that is owner by UID 10 will be
5590 stored in archive with owner name @samp{bin} and owner UID
5591 corresponding to @samp{bin}.  Each file owned by user @samp{smith}
5592 will be stored with owner name @samp{root} and owner ID 0.  Other
5593 files will remain unchanged.
5595 When used together with @option{--owner-map}, the @option{--owner}
5596 option affects only files whose owner is not listed in the map file.
5598 @item --group-map=@var{file}
5599 Read GID translation map from @var{file}.
5601 The format of @var{file} is the same as for @option{--owner-map}
5602 option:
5604 Each nonempty line defines mapping for a single GID.  It must consist
5605 of two fields separated by any amount of whitespace.  The first field
5606 defines original group name and GID.  It can be a valid group name or
5607 a valid GID prefixed with a plus sign.  In both cases the
5608 corresponding GID or user name is inferred from the current host's
5609 group database.
5611 The second field defines the GID and group name to map the original one
5612 to.  Its format can be the same as described above.  Otherwise, it can
5613 have the form @var{newname}:@var{newgid}, in which case neither
5614 @var{newname} nor @var{newgid} are required to be valid as per the
5615 group database.
5617 When used together with @option{--group-map}, the @option{--group}
5618 option affects only files whose owner group is not rewritten using the
5619 map file.
5620 @end table
5622 @node Extended File Attributes
5623 @subsection Extended File Attributes
5625 Extended file attributes are name-value pairs that can be
5626 associated with each node in a file system.  Despite the fact that
5627 POSIX.1e draft which proposed them has been withdrawn, the extended
5628 file attributes are supported by many file systems.  @GNUTAR{} can
5629 store extended file attributes along with the files.  This feature is
5630 controlled by the following command line arguments:
5632 @table @option
5633 @item --xattrs
5634 Enable extended attributes support.  When used with @option{--create},
5635 this option instructs @GNUTAR to store extended file attribute in the
5636 created archive.  This implies POSIX.1-2001 archive format
5637 (@option{--format=pax}).
5639 When used with @option{--extract}, this option tells @command{tar},
5640 for each file extracted, to read stored attributes from the archive
5641 and to apply them to the file.
5643 @item --no-xattrs
5644 Disable extended attributes support.  This is the default.
5645 @end table
5647 Attribute names are strings prefixed by a @dfn{namespace} name and a dot.
5648 Currently, four namespaces exist: @samp{user}, @samp{trusted},
5649 @samp{security} and @samp{system}.  By default, when @option{--xattr}
5650 is used, all names are stored in the archive (or extracted, if using
5651 @option{--extract}).  This can be controlled using the following
5652 options:
5654 @table @option
5655 @item --xattrs-exclude=@var{pattern}
5656 Specify exclude pattern for extended attributes.
5658 @item --xattrs-include=@var{pattern}
5659 Specify include pattern for extended attributes.
5660 @end table
5662 Here, the @var{pattern} is a globbing pattern.  For example, the
5663 following command:
5665 @example
5666 $ @kbd{tar --xattrs --xattrs-exclude='user.*' -c a.tar .}
5667 @end example
5669 will include in the archive @file{a.tar} all attributes, except those
5670 from the @samp{user} namespace.
5672 Any number of these options can be given, thereby creating lists of
5673 include and exclude patterns.
5675 When both options are used, first @option{--xattrs-include} is applied
5676 to select the set of attribute names to keep, and then
5677 @option{--xattrs-exclude} is applied to the resulting set.  In other
5678 words, only those attributes will be stored, whose names match one
5679 of the regexps in @option{--xattrs-include} and don't match any of
5680 the regexps from @option{--xattrs-exclude}.
5682 When listing the archive, if both @option{--xattrs} and
5683 @option{--verbose} options are given, files that have extended
5684 attributes are marked with an asterisk following their permission
5685 mask.  For example:
5687 @example
5688 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5689 @end example
5691 When two or more @option{--verbose} options are given, a detailed
5692 listing of extended attributes is printed after each file entry.  Each
5693 attribute is listed on a separate line, which begins with two spaces
5694 and the letter @samp{x} indicating extended attribute.  It is followed
5695 by a colon, length of the attribute and its name, e.g.:
5697 @example
5698 -rw-r--r--* smith/users      110 2016-03-16 16:07 file
5699   x:  7 user.mime_type
5700   x: 32 trusted.md5sum
5701 @end example
5703 File access control lists (@dfn{ACL}) are another actively used feature
5704 proposed by the POSIX.1e standard.  Each ACL consists of a set of ACL
5705 entries, each of which describes the access permissions on the file for
5706 an individual user or a group of users as a combination of read, write
5707 and search/execute permissions.
5709 Whether or not to use ACLs is controlled by the following two options:
5711 @table @option
5712 @item --acls
5713 Enable POSIX ACLs support.  When used with @option{--create},
5714 this option instructs @GNUTAR{} to store ACLs in the
5715 created archive.  This implies POSIX.1-2001 archive format
5716 (@option{--format=pax}).
5718 When used with @option{--extract}, this option tells @command{tar},
5719 to restore ACLs for each file extracted (provided they are present
5720 in the archive).
5722 @item --no-acls
5723 Disable POSIX ACLs support.  This is the default.
5724 @end table
5726 When listing the archive, if both @option{--acls} and
5727 @option{--verbose} options are given, files that have ACLs are marked
5728 with a plus sign following their permission mask.  For example:
5730 @example
5731 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5732 @end example
5734 When two or more @option{--verbose} options are given, a detailed
5735 listing of ACL is printed after each file entry:
5737 @example
5738 @group
5739 -rw-r--r--+ smith/users      110 2016-03-16 16:07 file
5740   a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r--
5741 @end group
5742 @end example
5744 @dfn{Security-Enhanced Linux} (@dfn{SELinux} for short) is a Linux
5745 kernel security module that provides a mechanism for supporting access
5746 control security policies, including so-called mandatory access
5747 controls (@dfn{MAC}).  Support for SELinux attributes is controlled by
5748 the following command line options:
5750 @table @option
5751 @item --selinux
5752 Enable the SELinux context support.
5754 @item --no-selinux
5755 Disable SELinux context support.
5756 @end table
5758 @node Ignore Failed Read
5759 @subsection Ignore Failed Read
5761 @table @option
5762 @item --ignore-failed-read
5763 @opindex ignore-failed-read
5764 Do not exit with nonzero on unreadable files or directories.
5765 @end table
5767 This option has effect only during creation.  It instructs tar to
5768 treat as mild conditions any missing or unreadable files (directories).
5769 Such failures don't affect the program exit code, and the
5770 corresponding diagnostic messages are marked as warnings, not errors.
5771 These warnings can be suppressed using the
5772 @option{--warning=failed-read} option (@pxref{warnings}).
5774 @node extract options
5775 @section Options Used by @option{--extract}
5776 @cindex options for use with @option{--extract}
5778 @xopindex{extract, additional options}
5779 The previous chapter showed how to use @option{--extract} to extract
5780 an archive into the file system.  Various options cause @command{tar} to
5781 extract more information than just file contents, such as the owner,
5782 the permissions, the modification date, and so forth.  This section
5783 presents options to be used with @option{--extract} when certain special
5784 considerations arise.  You may review the information presented in
5785 @ref{extract} for more basic information about the
5786 @option{--extract} operation.
5788 @menu
5789 * Reading::                     Options to Help Read Archives
5790 * Writing::                     Changing How @command{tar} Writes Files
5791 * Scarce::                      Coping with Scarce Resources
5792 @end menu
5794 @node Reading
5795 @subsection Options to Help Read Archives
5796 @cindex Options when reading archives
5798 @cindex Reading incomplete records
5799 @cindex Records, incomplete
5800 @opindex read-full-records
5801 Normally, @command{tar} will request data in full record increments from
5802 an archive storage device.  If the device cannot return a full record,
5803 @command{tar} will report an error.  However, some devices do not always
5804 return full records, or do not require the last record of an archive to
5805 be padded out to the next record boundary.  To keep reading until you
5806 obtain a full record, or to accept an incomplete record if it contains
5807 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5808 in conjunction with the @option{--extract} or @option{--list} operations.
5809 @xref{Blocking}.
5811 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5812 @command{tar} reads an archive from standard input, or from a remote
5813 machine.  This is because on @acronym{BSD} Unix systems, attempting to read a
5814 pipe returns however much happens to be in the pipe, even if it is
5815 less than was requested.  If this option were not enabled, @command{tar}
5816 would fail as soon as it read an incomplete record from the pipe.
5818 If you're not sure of the blocking factor of an archive, you can
5819 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5820 @option{--blocking-factor=@var{512-size}} (@option{-b
5821 @var{512-size}}), using a blocking factor larger than what the archive
5822 uses.  This lets you avoid having to determine the blocking factor
5823 of an archive.  @xref{Blocking Factor}.
5825 @menu
5826 * read full records::
5827 * Ignore Zeros::
5828 @end menu
5830 @node read full records
5831 @unnumberedsubsubsec Reading Full Records
5833 @FIXME{need sentence or so of intro here}
5835 @table @option
5836 @opindex read-full-records
5837 @item --read-full-records
5838 @item -B
5839 Use in conjunction with @option{--extract} (@option{--get},
5840 @option{-x}) to read an archive which contains incomplete records, or
5841 one which has a blocking factor less than the one specified.
5842 @end table
5844 @node Ignore Zeros
5845 @unnumberedsubsubsec Ignoring Blocks of Zeros
5847 @cindex End-of-archive blocks, ignoring
5848 @cindex Ignoring end-of-archive blocks
5849 @opindex ignore-zeros
5850 Normally, @command{tar} stops reading when it encounters a block of zeros
5851 between file entries (which usually indicates the end of the archive).
5852 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5853 completely read an archive which contains a block of zeros before the
5854 end (i.e., a damaged archive, or one that was created by concatenating
5855 several archives together).
5857 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5858 versions of @command{tar} write garbage after the end-of-archive entry,
5859 since that part of the media is never supposed to be read.  @GNUTAR{}
5860 does not write after the end of an archive, but seeks to
5861 maintain compatibility among archiving utilities.
5863 @table @option
5864 @item --ignore-zeros
5865 @itemx -i
5866 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5867 encountered while reading an archive.  Use in conjunction with
5868 @option{--extract} or @option{--list}.
5869 @end table
5871 @node Writing
5872 @subsection Changing How @command{tar} Writes Files
5873 @UNREVISED
5875 @FIXME{Introductory paragraph}
5877 @menu
5878 * Dealing with Old Files::
5879 * Overwrite Old Files::
5880 * Keep Old Files::
5881 * Keep Newer Files::
5882 * Unlink First::
5883 * Recursive Unlink::
5884 * Data Modification Times::
5885 * Setting Access Permissions::
5886 * Directory Modification Times and Permissions::
5887 * Writing to Standard Output::
5888 * Writing to an External Program::
5889 * remove files::
5890 @end menu
5892 @node Dealing with Old Files
5893 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5895 @xopindex{overwrite-dir, introduced}
5896 When extracting files, if @command{tar} discovers that the extracted
5897 file already exists, it normally replaces the file by removing it before
5898 extracting it, to prevent confusion in the presence of hard or symbolic
5899 links.  (If the existing file is a symbolic link, it is removed, not
5900 followed.)  However, if a directory cannot be removed because it is
5901 nonempty, @command{tar} normally overwrites its metadata (ownership,
5902 permission, etc.).  The @option{--overwrite-dir} option enables this
5903 default behavior.  To be more cautious and preserve the metadata of
5904 such a directory, use the @option{--no-overwrite-dir} option.
5906 @cindex Overwriting old files, prevention
5907 @xopindex{keep-old-files, introduced}
5908 To be even more cautious and prevent existing files from being replaced, use
5909 the @option{--keep-old-files} (@option{-k}) option.  It causes
5910 @command{tar} to refuse to replace or update a file that already
5911 exists, i.e., a file with the same name as an archive member prevents
5912 extraction of that archive member.  Instead, it reports an error.  For
5913 example:
5915 @example
5916 $ @kbd{ls}
5917 blues
5918 $ @kbd{tar -x -k -f archive.tar}
5919 tar: blues: Cannot open: File exists
5920 tar: Exiting with failure status due to previous errors
5921 @end example
5923 @xopindex{skip-old-files, introduced}
5924 If you wish to preserve old files untouched, but don't want
5925 @command{tar} to treat them as errors, use the
5926 @option{--skip-old-files} option.  This option causes @command{tar} to
5927 silently skip extracting over existing files.
5929 @xopindex{overwrite, introduced}
5930 To be more aggressive about altering existing files, use the
5931 @option{--overwrite} option.  It causes @command{tar} to overwrite
5932 existing files and to follow existing symbolic links when extracting.
5934 @cindex Protecting old files
5935 Some people argue that @GNUTAR{} should not hesitate
5936 to overwrite files with other files when extracting.  When extracting
5937 a @command{tar} archive, they expect to see a faithful copy of the
5938 state of the file system when the archive was created.  It is debatable
5939 that this would always be a proper behavior.  For example, suppose one
5940 has an archive in which @file{usr/local} is a link to
5941 @file{usr/local2}.  Since then, maybe the site removed the link and
5942 renamed the whole hierarchy from @file{/usr/local2} to
5943 @file{/usr/local}.  Such things happen all the time.  I guess it would
5944 not be welcome at all that @GNUTAR{} removes the
5945 whole hierarchy just to make room for the link to be reinstated
5946 (unless it @emph{also} simultaneously restores the full
5947 @file{/usr/local2}, of course!)  @GNUTAR{} is indeed
5948 able to remove a whole hierarchy to reestablish a symbolic link, for
5949 example, but @emph{only if} @option{--recursive-unlink} is specified
5950 to allow this behavior.  In any case, single files are silently
5951 removed.
5953 @xopindex{unlink-first, introduced}
5954 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5955 some cases by causing @command{tar} to remove files unconditionally
5956 before extracting them.
5958 @node Overwrite Old Files
5959 @unnumberedsubsubsec Overwrite Old Files
5961 @table @option
5962 @opindex overwrite
5963 @item --overwrite
5964 Overwrite existing files and directory metadata when extracting files
5965 from an archive.
5967 This causes @command{tar} to write extracted files into the file system without
5968 regard to the files already on the system; i.e., files with the same
5969 names as archive members are overwritten when the archive is extracted.
5970 It also causes @command{tar} to extract the ownership, permissions,
5971 and time stamps onto any preexisting files or directories.
5972 If the name of a corresponding file name is a symbolic link, the file
5973 pointed to by the symbolic link will be overwritten instead of the
5974 symbolic link itself (if this is possible).  Moreover, special devices,
5975 empty directories and even symbolic links are automatically removed if
5976 they are in the way of extraction.
5978 Be careful when using the @option{--overwrite} option, particularly when
5979 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5980 can change the contents, ownership or permissions of any file on your
5981 system.  Also, many systems do not take kindly to overwriting files that
5982 are currently being executed.
5984 @opindex overwrite-dir
5985 @item --overwrite-dir
5986 Overwrite the metadata of directories when extracting files from an
5987 archive, but remove other files before extracting.
5988 @end table
5990 @node Keep Old Files
5991 @unnumberedsubsubsec Keep Old Files
5993 @GNUTAR{} provides two options to control its actions in a situation
5994 when it is about to extract a file which already exists on disk.
5996 @table @option
5997 @opindex keep-old-files
5998 @item --keep-old-files
5999 @itemx -k
6000 Do not replace existing files from archive.  When such a file is
6001 encountered, @command{tar} issues an error message.  Upon end of
6002 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
6004 @item --skip-old-files
6005 Do not replace existing files from archive, but do not treat that
6006 as error.  Such files are silently skipped and do not affect
6007 @command{tar} exit status.
6009 Additional verbosity can be obtained using @option{--warning=existing-file}
6010 together with that option (@pxref{warnings}).
6011 @end table
6013 @node Keep Newer Files
6014 @unnumberedsubsubsec Keep Newer Files
6016 @table @option
6017 @opindex keep-newer-files
6018 @item --keep-newer-files
6019 Do not replace existing files that are newer than their archive
6020 copies.  This option is meaningless with @option{--list} (@option{-t}).
6021 @end table
6023 @node Unlink First
6024 @unnumberedsubsubsec Unlink First
6026 @table @option
6027 @opindex unlink-first
6028 @item --unlink-first
6029 @itemx -U
6030 Remove files before extracting over them.
6031 This can make @command{tar} run a bit faster if you know in advance
6032 that the extracted files all need to be removed.  Normally this option
6033 slows @command{tar} down slightly, so it is disabled by default.
6034 @end table
6036 @node Recursive Unlink
6037 @unnumberedsubsubsec Recursive Unlink
6039 @table @option
6040 @opindex recursive-unlink
6041 @item --recursive-unlink
6042 When this option is specified, try removing files and directory hierarchies
6043 before extracting over them.  @emph{This is a dangerous option!}
6044 @end table
6046 If you specify the @option{--recursive-unlink} option,
6047 @command{tar} removes @emph{anything} that keeps you from extracting a file
6048 as far as current permissions will allow it.  This could include removal
6049 of the contents of a full directory hierarchy.
6051 @node Data Modification Times
6052 @unnumberedsubsubsec Setting Data Modification Times
6054 @cindex Data modification times of extracted files
6055 @cindex Modification times of extracted files
6056 Normally, @command{tar} sets the data modification times of extracted
6057 files to the corresponding times recorded for the files in the archive, but
6058 limits the permissions of extracted files by the current @code{umask}
6059 setting.
6061 To set the data modification times of extracted files to the time when
6062 the files were extracted, use the @option{--touch} (@option{-m}) option in
6063 conjunction with @option{--extract} (@option{--get}, @option{-x}).
6065 @table @option
6066 @opindex touch
6067 @item --touch
6068 @itemx -m
6069 Sets the data modification time of extracted archive members to the time
6070 they were extracted, not the time recorded for them in the archive.
6071 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
6072 @end table
6074 @node Setting Access Permissions
6075 @unnumberedsubsubsec Setting Access Permissions
6077 @cindex Permissions of extracted files
6078 @cindex Modes of extracted files
6079 To set the modes (access permissions) of extracted files to those
6080 recorded for those files in the archive, use @option{--same-permissions}
6081 in conjunction with the @option{--extract} (@option{--get},
6082 @option{-x}) operation.
6084 @table @option
6085 @opindex preserve-permissions
6086 @opindex same-permissions
6087 @item --preserve-permissions
6088 @itemx --same-permissions
6089 @c @itemx --ignore-umask
6090 @itemx -p
6091 Set modes of extracted archive members to those recorded in the
6092 archive, instead of current umask settings.  Use in conjunction with
6093 @option{--extract} (@option{--get}, @option{-x}).
6094 @end table
6096 @node Directory Modification Times and Permissions
6097 @unnumberedsubsubsec Directory Modification Times and Permissions
6099 After successfully extracting a file member, @GNUTAR{} normally
6100 restores its permissions and modification times, as described in the
6101 previous sections.  This cannot be done for directories, because
6102 after extracting a directory @command{tar} will almost certainly
6103 extract files into that directory and this will cause the directory
6104 modification time to be updated.  Moreover, restoring that directory
6105 permissions may not permit file creation within it.  Thus, restoring
6106 directory permissions and modification times must be delayed at least
6107 until all files have been extracted into that directory.  @GNUTAR{}
6108 restores directories using the following approach.
6110 The extracted directories are created with the mode specified in the
6111 archive, as modified by the umask of the user, which gives sufficient
6112 permissions to allow file creation.  The meta-information about the
6113 directory is recorded in the temporary list of directories.  When
6114 preparing to extract next archive member, @GNUTAR{} checks if the
6115 directory prefix of this file contains the remembered directory.  If
6116 it does not, the program assumes that all files have been extracted
6117 into that directory, restores its modification time and permissions
6118 and removes its entry from the internal list.  This approach allows
6119 to correctly restore directory meta-information in the majority of
6120 cases, while keeping memory requirements sufficiently small.  It is
6121 based on the fact, that most @command{tar} archives use the predefined
6122 order of members: first the directory, then all the files and
6123 subdirectories in that directory.
6125 However, this is not always true.  The most important exception are
6126 incremental archives (@pxref{Incremental Dumps}).  The member order in
6127 an incremental archive is reversed: first all directory members are
6128 stored, followed by other (non-directory) members.  So, when extracting
6129 from incremental archives, @GNUTAR{} alters the above procedure.  It
6130 remembers all restored directories, and restores their meta-data
6131 only after the entire archive has been processed.  Notice, that you do
6132 not need to specify any special options for that, as @GNUTAR{}
6133 automatically detects archives in incremental format.
6135 There may be cases, when such processing is required for normal archives
6136 too.  Consider the following example:
6138 @smallexample
6139 @group
6140 $ @kbd{tar --no-recursion -cvf archive \
6141     foo foo/file1 bar bar/file foo/file2}
6142 foo/
6143 foo/file1
6144 bar/
6145 bar/file
6146 foo/file2
6147 @end group
6148 @end smallexample
6150 During the normal operation, after encountering @file{bar}
6151 @GNUTAR{} will assume that all files from the directory @file{foo}
6152 were already extracted and will therefore restore its timestamp and
6153 permission bits.  However, after extracting @file{foo/file2} the
6154 directory timestamp will be offset again.
6156 To correctly restore directory meta-information in such cases, use
6157 the @option{--delay-directory-restore} command line option:
6159 @table @option
6160 @opindex delay-directory-restore
6161 @item --delay-directory-restore
6162 Delays restoring of the modification times and permissions of extracted
6163 directories until the end of extraction.  This way, correct
6164 meta-information is restored even if the archive has unusual member
6165 ordering.
6167 @opindex no-delay-directory-restore
6168 @item --no-delay-directory-restore
6169 Cancel the effect of the previous @option{--delay-directory-restore}.
6170 Use this option if you have used @option{--delay-directory-restore} in
6171 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
6172 temporarily disable it.
6173 @end table
6175 @node Writing to Standard Output
6176 @unnumberedsubsubsec Writing to Standard Output
6178 @cindex Writing extracted files to standard output
6179 @cindex Standard output, writing extracted files to
6180 To write the extracted files to the standard output, instead of
6181 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
6182 conjunction with @option{--extract} (@option{--get}, @option{-x}).  This option is useful if you are
6183 extracting files to send them through a pipe, and do not need to
6184 preserve them in the file system.  If you extract multiple members,
6185 they appear on standard output concatenated, in the order they are
6186 found in the archive.
6188 @table @option
6189 @opindex to-stdout
6190 @item --to-stdout
6191 @itemx -O
6192 Writes files to the standard output.  Use only in conjunction with
6193 @option{--extract} (@option{--get}, @option{-x}).  When this option is
6194 used, instead of creating the files specified, @command{tar} writes
6195 the contents of the files extracted to its standard output.  This may
6196 be useful if you are only extracting the files in order to send them
6197 through a pipe.  This option is meaningless with @option{--list}
6198 (@option{-t}).
6199 @end table
6201 This can be useful, for example, if you have a tar archive containing
6202 a big file and don't want to store the file on disk before processing
6203 it.  You can use a command like this:
6205 @smallexample
6206 tar -xOzf foo.tgz bigfile | process
6207 @end smallexample
6209 or even like this if you want to process the concatenation of the files:
6211 @smallexample
6212 tar -xOzf foo.tgz bigfile1 bigfile2 | process
6213 @end smallexample
6215 However, @option{--to-command} may be more convenient for use with
6216 multiple files. See the next section.
6218 @node Writing to an External Program
6219 @unnumberedsubsubsec Writing to an External Program
6221 You can instruct @command{tar} to send the contents of each extracted
6222 file to the standard input of an external program:
6224 @table @option
6225 @opindex to-command
6226 @item --to-command=@var{command}
6227 Extract files and pipe their contents to the standard input of
6228 @var{command}.  When this option is used, instead of creating the
6229 files specified, @command{tar} invokes @var{command} and pipes the
6230 contents of the files to its standard output.  The @var{command} may
6231 contain command line arguments (see @ref{external, Running External Commands},
6232 for more detail).
6234 Notice, that @var{command} is executed once for each regular file
6235 extracted.  Non-regular files (directories, etc.)@: are ignored when this
6236 option is used.
6237 @end table
6239 The command can obtain the information about the file it processes
6240 from the following environment variables:
6242 @table @env
6243 @vrindex TAR_FILETYPE, to-command environment
6244 @item TAR_FILETYPE
6245 Type of the file. It is a single letter with the following meaning:
6247 @multitable @columnfractions 0.10 0.90
6248 @item f @tab Regular file
6249 @item d @tab Directory
6250 @item l @tab Symbolic link
6251 @item h @tab Hard link
6252 @item b @tab Block device
6253 @item c @tab Character device
6254 @end multitable
6256 Currently only regular files are supported.
6258 @vrindex TAR_MODE, to-command environment
6259 @item TAR_MODE
6260 File mode, an octal number.
6262 @vrindex TAR_FILENAME, to-command environment
6263 @item TAR_FILENAME
6264 The name of the file.
6266 @vrindex TAR_REALNAME, to-command environment
6267 @item TAR_REALNAME
6268 Name of the file as stored in the archive.
6270 @vrindex TAR_UNAME, to-command environment
6271 @item TAR_UNAME
6272 Name of the file owner.
6274 @vrindex TAR_GNAME, to-command environment
6275 @item TAR_GNAME
6276 Name of the file owner group.
6278 @vrindex TAR_ATIME, to-command environment
6279 @item TAR_ATIME
6280 Time of last access. It is a decimal number, representing seconds
6281 since the Epoch.  If the archive provides times with nanosecond
6282 precision, the nanoseconds are appended to the timestamp after a
6283 decimal point.
6285 @vrindex TAR_MTIME, to-command environment
6286 @item TAR_MTIME
6287 Time of last modification.
6289 @vrindex TAR_CTIME, to-command environment
6290 @item TAR_CTIME
6291 Time of last status change.
6293 @vrindex TAR_SIZE, to-command environment
6294 @item TAR_SIZE
6295 Size of the file.
6297 @vrindex TAR_UID, to-command environment
6298 @item TAR_UID
6299 UID of the file owner.
6301 @vrindex TAR_GID, to-command environment
6302 @item TAR_GID
6303 GID of the file owner.
6304 @end table
6306 Additionally, the following variables contain information about
6307 tar mode and the archive being processed:
6309 @table @env
6310 @vrindex TAR_VERSION, to-command environment
6311 @item TAR_VERSION
6312 @GNUTAR{} version number.
6314 @vrindex TAR_ARCHIVE, to-command environment
6315 @item TAR_ARCHIVE
6316 The name of the archive @command{tar} is processing.
6318 @vrindex TAR_BLOCKING_FACTOR, to-command environment
6319 @item TAR_BLOCKING_FACTOR
6320 Current blocking factor (@pxref{Blocking}).
6322 @vrindex TAR_VOLUME, to-command environment
6323 @item TAR_VOLUME
6324 Ordinal number of the volume @command{tar} is processing.
6326 @vrindex TAR_FORMAT, to-command environment
6327 @item TAR_FORMAT
6328 Format of the archive being processed. @xref{Formats}, for a complete
6329 list of archive format names.
6330 @end table
6332 These variables are defined prior to executing the command, so you can
6333 pass them as arguments, if you prefer.  For example, if the command
6334 @var{proc} takes the member name and size as its arguments, then you
6335 could do:
6337 @smallexample
6338 $ @kbd{tar -x -f archive.tar \
6339        --to-command='proc $TAR_FILENAME $TAR_SIZE'}
6340 @end smallexample
6342 @noindent
6343 Notice single quotes to prevent variable names from being expanded by
6344 the shell when invoking @command{tar}.
6346 If @var{command} exits with a non-0 status, @command{tar} will print
6347 an error message similar to the following:
6349 @smallexample
6350 tar: 2345: Child returned status 1
6351 @end smallexample
6353 Here, @samp{2345} is the PID of the finished process.
6355 If this behavior is not wanted, use @option{--ignore-command-error}:
6357 @table @option
6358 @opindex ignore-command-error
6359 @item --ignore-command-error
6360 Ignore exit codes of subprocesses.  Notice that if the program
6361 exits on signal or otherwise terminates abnormally, the error message
6362 will be printed even if this option is used.
6364 @opindex no-ignore-command-error
6365 @item --no-ignore-command-error
6366 Cancel the effect of any previous @option{--ignore-command-error}
6367 option. This option is useful if you have set
6368 @option{--ignore-command-error} in @env{TAR_OPTIONS}
6369 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
6370 @end table
6372 @node remove files
6373 @unnumberedsubsubsec Removing Files
6375 @FIXME{The section is too terse. Something more to add? An example,
6376 maybe?}
6378 @table @option
6379 @opindex remove-files
6380 @item --remove-files
6381 Remove files after adding them to the archive.
6382 @end table
6384 @node Scarce
6385 @subsection Coping with Scarce Resources
6386 @UNREVISED
6388 @cindex Small memory
6389 @cindex Running out of space
6391 @menu
6392 * Starting File::
6393 * Same Order::
6394 @end menu
6396 @node Starting File
6397 @unnumberedsubsubsec Starting File
6399 @table @option
6400 @opindex starting-file
6401 @item --starting-file=@var{name}
6402 @itemx -K @var{name}
6403 Starts an operation in the middle of an archive.  Use in conjunction
6404 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
6405 @end table
6407 @cindex Middle of the archive, starting in the
6408 If a previous attempt to extract files failed due to lack of disk
6409 space, you can use @option{--starting-file=@var{name}} (@option{-K
6410 @var{name}}) to start extracting only after member @var{name} of the
6411 archive.  This assumes, of course, that there is now free space, or
6412 that you are now extracting into a different file system.  (You could
6413 also choose to suspend @command{tar}, remove unnecessary files from
6414 the file system, and then resume the same @command{tar} operation.
6415 In this case, @option{--starting-file} is not necessary.)  See also
6416 @ref{interactive}, and @ref{exclude}.
6418 @node Same Order
6419 @unnumberedsubsubsec Same Order
6421 @table @option
6422 @cindex Large lists of file names on small machines
6423 @opindex same-order
6424 @opindex preserve-order
6425 @item --same-order
6426 @itemx --preserve-order
6427 @itemx -s
6428 To process large lists of file names on machines with small amounts of
6429 memory.  Use in conjunction with @option{--compare} (@option{--diff},
6430 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
6431 (@option{--get}, @option{-x}).
6432 @end table
6434 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
6435 names to be listed or extracted is sorted in the same order as the
6436 files in the archive.  This allows a large list of names to be used,
6437 even on a small machine that would not otherwise be able to hold all
6438 the names in memory at the same time.  Such a sorted list can easily be
6439 created by running @samp{tar -t} on the archive and editing its output.
6441 This option is probably never needed on modern computer systems.
6443 @node backup
6444 @section Backup options
6446 @cindex backup options
6448 @GNUTAR{} offers options for making backups of files
6449 before writing new versions.  These options control the details of
6450 these backups.  They may apply to the archive itself before it is
6451 created or rewritten, as well as individual extracted members.  Other
6452 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
6453 and @command{mv}, for example) offer similar options.
6455 Backup options may prove unexpectedly useful when extracting archives
6456 containing many members having identical name, or when extracting archives
6457 on systems having file name limitations, making different members appear
6458 as having similar names through the side-effect of name truncation.
6459 @FIXME{This is true only if we have a good scheme for truncated backup names,
6460 which I'm not sure at all: I suspect work is needed in this area.}
6461 When any existing file is backed up before being overwritten by extraction,
6462 then clashing files are automatically be renamed to be unique, and the
6463 true name is kept for only the last file of a series of clashing files.
6464 By using verbose mode, users may track exactly what happens.
6466 At the detail level, some decisions are still experimental, and may
6467 change in the future, we are waiting comments from our users.  So, please
6468 do not learn to depend blindly on the details of the backup features.
6469 For example, currently, directories themselves are never renamed through
6470 using these options, so, extracting a file over a directory still has
6471 good chances to fail.  Also, backup options apply to created archives,
6472 not only to extracted members.  For created archives, backups will not
6473 be attempted when the archive is a block or character device, or when it
6474 refers to a remote file.
6476 For the sake of simplicity and efficiency, backups are made by renaming old
6477 files prior to creation or extraction, and not by copying.  The original
6478 name is restored if the file creation fails.  If a failure occurs after a
6479 partial extraction of a file, both the backup and the partially extracted
6480 file are kept.
6482 @table @samp
6483 @item --backup[=@var{method}]
6484 @opindex backup
6485 @vindex VERSION_CONTROL
6486 @cindex backups
6487 Back up files that are about to be overwritten or removed.
6488 Without this option, the original versions are destroyed.
6490 Use @var{method} to determine the type of backups made.
6491 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
6492 environment variable.  And if @env{VERSION_CONTROL} is not set,
6493 use the @samp{existing} method.
6495 @vindex version-control @r{Emacs variable}
6496 This option corresponds to the Emacs variable @samp{version-control};
6497 the same values for @var{method} are accepted as in Emacs.  This option
6498 also allows more descriptive names.  The valid @var{method}s are:
6500 @table @samp
6501 @item t
6502 @itemx numbered
6503 @cindex numbered @r{backup method}
6504 Always make numbered backups.
6506 @item nil
6507 @itemx existing
6508 @cindex existing @r{backup method}
6509 Make numbered backups of files that already have them, simple backups
6510 of the others.
6512 @item never
6513 @itemx simple
6514 @cindex simple @r{backup method}
6515 Always make simple backups.
6517 @end table
6519 @item --suffix=@var{suffix}
6520 @opindex suffix
6521 @cindex backup suffix
6522 @vindex SIMPLE_BACKUP_SUFFIX
6523 Append @var{suffix} to each backup file made with @option{--backup}.  If this
6524 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
6525 environment variable is used.  And if @env{SIMPLE_BACKUP_SUFFIX} is not
6526 set, the default is @samp{~}, just as in Emacs.
6528 @end table
6530 @node looking ahead
6531 @section Looking Ahead: The Rest of this Manual
6533 You have now seen how to use all eight of the operations available to
6534 @command{tar}, and a number of the possible options.  The next chapter
6535 explains how to choose and change file and archive names, how to use
6536 files to store names of other files which you can then call as
6537 arguments to @command{tar} (this can help you save time if you expect to
6538 archive the same list of files a number of times), and so forth.
6539 @FIXME{in case it's not obvious, i'm making this up in some sense
6540 based on my limited memory of what the next chapter *really* does.  i
6541 just wanted to flesh out this final section a little bit so i'd
6542 remember to stick it in here. :-)}
6544 If there are too many files to conveniently list on the command line,
6545 you can list the names in a file, and @command{tar} will read that file.
6546 @xref{files}.
6548 There are various ways of causing @command{tar} to skip over some files,
6549 and not archive them.  @xref{Choosing}.
6551 @node Backups
6552 @chapter Performing Backups and Restoring Files
6553 @cindex backups
6555 @GNUTAR{} is distributed along with the scripts for performing backups
6556 and restores.  Even if there is a good chance those scripts may be
6557 satisfying to you, they are not the only scripts or methods available for doing
6558 backups and restore.  You may well create your own, or use more
6559 sophisticated packages dedicated to that purpose.
6561 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
6562 Automatic Network Disk Archiver), a backup system developed by James
6563 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
6564 This is free software, and it is available from @uref{http://www.amanda.org}.
6566 @FIXME{
6568 Here is a possible plan for a future documentation about the backuping
6569 scripts which are provided within the @GNUTAR{}
6570 distribution.
6572 @itemize @bullet
6573 @item dumps
6574  @itemize @minus
6575  @item what are dumps
6576  @item different levels of dumps
6577   @itemize +
6578   @item full dump = dump everything
6579   @item level 1, level 2 dumps etc
6580         A level @var{n} dump dumps everything changed since the last level
6581         @var{n}-1 dump (?)
6582   @end itemize
6583  @item how to use scripts for dumps  (ie, the concept)
6584   @itemize +
6585   @item scripts to run after editing backup specs (details)
6586   @end itemize
6587  @item Backup Specs, what is it.
6588   @itemize +
6589   @item how to customize
6590   @item actual text of script  [/sp/dump/backup-specs]
6591   @end itemize
6592  @item Problems
6593   @itemize +
6594    @item rsh doesn't work
6595    @item rtape isn't installed
6596    @item (others?)
6597   @end itemize
6598  @item the @option{--incremental} option of tar
6599  @item tapes
6600   @itemize +
6601   @item write protection
6602   @item types of media, different sizes and types, useful for different things
6603   @item files and tape marks
6604      one tape mark between files, two at end.
6605   @item positioning the tape
6606      MT writes two at end of write,
6607      backspaces over one when writing again.
6608   @end itemize
6609  @end itemize
6610 @end itemize
6613 This chapter documents both the provided shell scripts and @command{tar}
6614 options which are more specific to usage as a backup tool.
6616 To @dfn{back up} a file system means to create archives that contain
6617 all the files in that file system.  Those archives can then be used to
6618 restore any or all of those files (for instance if a disk crashes or a
6619 file is accidentally deleted).  File system @dfn{backups} are also
6620 called @dfn{dumps}.
6622 @menu
6623 * Full Dumps::                  Using @command{tar} to Perform Full Dumps
6624 * Incremental Dumps::           Using @command{tar} to Perform Incremental Dumps
6625 * Backup Levels::               Levels of Backups
6626 * Backup Parameters::           Setting Parameters for Backups and Restoration
6627 * Scripted Backups::            Using the Backup Scripts
6628 * Scripted Restoration::        Using the Restore Script
6629 @end menu
6631 @node Full Dumps
6632 @section Using @command{tar} to Perform Full Dumps
6633 @UNREVISED
6635 @cindex full dumps
6636 @cindex dumps, full
6638 @cindex corrupted archives
6639 Full dumps should only be made when no other people or programs
6640 are modifying files in the file system.  If files are modified while
6641 @command{tar} is making the backup, they may not be stored properly in
6642 the archive, in which case you won't be able to restore them if you
6643 have to.  (Files not being modified are written with no trouble, and do
6644 not corrupt the entire archive.)
6646 You will want to use the @option{--label=@var{archive-label}}
6647 (@option{-V @var{archive-label}}) option to give the archive a
6648 volume label, so you can tell what this archive is even if the label
6649 falls off the tape, or anything like that.
6651 Unless the file system you are dumping is guaranteed to fit on
6652 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6653 Make sure you have enough tapes on hand to complete the backup.
6655 If you want to dump each file system separately you will need to use
6656 the @option{--one-file-system} option to prevent
6657 @command{tar} from crossing file system boundaries when storing
6658 (sub)directories.
6660 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6661 option is not needed, since this is a complete copy of everything in
6662 the file system, and a full restore from this backup would only be
6663 done onto a completely
6664 empty disk.
6666 Unless you are in a hurry, and trust the @command{tar} program (and your
6667 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6668 option, to make sure your files really made it onto the dump properly.
6669 This will also detect cases where the file was modified while (or just
6670 after) it was being archived.  Not all media (notably cartridge tapes)
6671 are capable of being verified, unfortunately.
6673 @node Incremental Dumps
6674 @section Using @command{tar} to Perform Incremental Dumps
6676 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6677 stores additional metadata so that exact state of the file system
6678 can be restored when extracting the archive.
6680 @GNUTAR{} currently offers two options for handling incremental
6681 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6682 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6684 @xopindex{listed-incremental, described}
6685 The option @option{--listed-incremental} instructs tar to operate on
6686 an incremental archive with additional metadata stored in a standalone
6687 file, called a @dfn{snapshot file}.  The purpose of this file is to help
6688 determine which files have been changed, added or deleted since the
6689 last backup, so that the next incremental backup will contain only
6690 modified files.  The name of the snapshot file is given as an argument
6691 to the option:
6693 @table @option
6694 @item --listed-incremental=@var{file}
6695 @itemx -g @var{file}
6696   Handle incremental backups with snapshot data in @var{file}.
6697 @end table
6699 To create an incremental backup, you would use
6700 @option{--listed-incremental} together with @option{--create}
6701 (@pxref{create}).  For example:
6703 @smallexample
6704 $ @kbd{tar --create \
6705            --file=archive.1.tar \
6706            --listed-incremental=/var/log/usr.snar \
6707            /usr}
6708 @end smallexample
6710 This will create in @file{archive.1.tar} an incremental backup of
6711 the @file{/usr} file system, storing additional metadata in the file
6712 @file{/var/log/usr.snar}.  If this file does not exist, it will be
6713 created.  The created archive will then be a @dfn{level 0 backup};
6714 please see the next section for more on backup levels.
6716 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6717 determines which files are modified.  In this case only these files will be
6718 stored in the archive.  Suppose, for example, that after running the
6719 above command, you delete file @file{/usr/doc/old} and create
6720 directory @file{/usr/local/db} with the following contents:
6722 @smallexample
6723 $ @kbd{ls /usr/local/db}
6724 /usr/local/db/data
6725 /usr/local/db/index
6726 @end smallexample
6728 Some time later you create another incremental backup.  You will
6729 then see:
6731 @smallexample
6732 $ @kbd{tar --create \
6733            --file=archive.2.tar \
6734            --listed-incremental=/var/log/usr.snar \
6735            /usr}
6736 tar: usr/local/db: Directory is new
6737 usr/local/db/
6738 usr/local/db/data
6739 usr/local/db/index
6740 @end smallexample
6742 @noindent
6743 The created archive @file{archive.2.tar} will contain only these
6744 three members.  This archive is called a @dfn{level 1 backup}.  Notice
6745 that @file{/var/log/usr.snar} will be updated with the new data, so if
6746 you plan to create more @samp{level 1} backups, it is necessary to
6747 create a working copy of the snapshot file before running
6748 @command{tar}.  The above example will then be modified as follows:
6750 @smallexample
6751 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6752 $ @kbd{tar --create \
6753            --file=archive.2.tar \
6754            --listed-incremental=/var/log/usr.snar-1 \
6755            /usr}
6756 @end smallexample
6758 @anchor{--level=0}
6759 @xopindex{level, described}
6760 You can force @samp{level 0} backups either by removing the snapshot
6761 file before running @command{tar}, or by supplying the
6762 @option{--level=0} option, e.g.:
6764 @smallexample
6765 $ @kbd{tar --create \
6766            --file=archive.2.tar \
6767            --listed-incremental=/var/log/usr.snar-0 \
6768            --level=0 \
6769            /usr}
6770 @end smallexample
6772 Incremental dumps depend crucially on time stamps, so the results are
6773 unreliable if you modify a file's time stamps during dumping (e.g.,
6774 with the @option{--atime-preserve=replace} option), or if you set the clock
6775 backwards.
6777 @anchor{device numbers}
6778 @cindex Device numbers, using in incremental backups
6779 Metadata stored in snapshot files include device numbers, which,
6780 obviously are supposed to be non-volatile values.  However, it turns
6781 out that @acronym{NFS} devices have undependable values when an automounter
6782 gets in the picture.  This can lead to a great deal of spurious
6783 redumping in incremental dumps, so it is somewhat useless to compare
6784 two @acronym{NFS} devices numbers over time.  The solution implemented
6785 currently is to consider all @acronym{NFS} devices as being equal
6786 when it comes to comparing directories; this is fairly gross, but
6787 there does not seem to be a better way to go.
6789 Apart from using @acronym{NFS}, there are a number of cases where
6790 relying on device numbers can cause spurious redumping of unmodified
6791 files.  For example, this occurs when archiving @acronym{LVM} snapshot
6792 volumes.  To avoid this, use @option{--no-check-device} option:
6794 @table @option
6795 @xopindex{no-check-device, described}
6796 @item --no-check-device
6797 Do not rely on device numbers when preparing a list of changed files
6798 for an incremental dump.
6800 @xopindex{check-device, described}
6801 @item --check-device
6802 Use device numbers when preparing a list of changed files
6803 for an incremental dump.  This is the default behavior.  The purpose
6804 of this option is to undo the effect of the @option{--no-check-device}
6805 if it was given in @env{TAR_OPTIONS} environment variable
6806 (@pxref{TAR_OPTIONS}).
6807 @end table
6809 There is also another way to cope with changing device numbers.  It is
6810 described in detail in @ref{Fixing Snapshot Files}.
6812 Note that incremental archives use @command{tar} extensions and may
6813 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6815 @xopindex{listed-incremental, using with @option{--extract}}
6816 @xopindex{extract, using with @option{--listed-incremental}}
6817 To extract from the incremental dumps, use
6818 @option{--listed-incremental} together with @option{--extract}
6819 option (@pxref{extracting files}).  In this case, @command{tar} does
6820 not need to access snapshot file, since all the data necessary for
6821 extraction are stored in the archive itself.  So, when extracting, you
6822 can give whatever argument to @option{--listed-incremental}, the usual
6823 practice is to use @option{--listed-incremental=/dev/null}.
6824 Alternatively, you can use @option{--incremental}, which needs no
6825 arguments.  In general, @option{--incremental} (@option{-G}) can be
6826 used as a shortcut for @option{--listed-incremental} when listing or
6827 extracting incremental backups (for more information regarding this
6828 option, @pxref{incremental-op}).
6830 When extracting from the incremental backup @GNUTAR{} attempts to
6831 restore the exact state the file system had when the archive was
6832 created.  In particular, it will @emph{delete} those files in the file
6833 system that did not exist in their directories when the archive was
6834 created.  If you have created several levels of incremental files,
6835 then in order to restore the exact contents the file system  had when
6836 the last level was created, you will need to restore from all backups
6837 in turn.  Continuing our example, to restore the state of @file{/usr}
6838 file system, one would do@footnote{Notice, that since both archives
6839 were created without @option{-P} option (@pxref{absolute}), these
6840 commands should be run from the root file system.}:
6842 @smallexample
6843 $ @kbd{tar --extract \
6844            --listed-incremental=/dev/null \
6845            --file archive.1.tar}
6846 $ @kbd{tar --extract \
6847            --listed-incremental=/dev/null \
6848            --file archive.2.tar}
6849 @end smallexample
6851 To list the contents of an incremental archive, use @option{--list}
6852 (@pxref{list}), as usual.  To obtain more information about the
6853 archive, use @option{--listed-incremental} or @option{--incremental}
6854 combined with two @option{--verbose} options@footnote{Two
6855 @option{--verbose} options were selected to avoid breaking usual
6856 verbose listing output (@option{--list --verbose}) when using in
6857 scripts.
6859 @xopindex{incremental, using with @option{--list}}
6860 @xopindex{listed-incremental, using with @option{--list}}
6861 @xopindex{list, using with @option{--incremental}}
6862 @xopindex{list, using with @option{--listed-incremental}}
6863 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6864 contents of the DUMPDIR header (with terminating nulls) when
6865 @option{--incremental} or @option{--listed-incremental} option was
6866 given, no matter what the verbosity level.  This behavior, and,
6867 especially, the binary output it produced were considered inconvenient
6868 and were changed in version 1.16.}:
6870 @smallexample
6871 @kbd{tar --list --incremental --verbose --verbose --file archive.tar}
6872 @end smallexample
6874 This command will print, for each directory in the archive, the list
6875 of files in that directory at the time the archive was created.  This
6876 information is put out in a format which is both human-readable and
6877 unambiguous for a program: each file name is printed as
6879 @smallexample
6880 @var{x} @var{file}
6881 @end smallexample
6883 @noindent
6884 where @var{x} is a letter describing the status of the file: @samp{Y}
6885 if the file  is present in the archive, @samp{N} if the file is not
6886 included in the archive, or a @samp{D} if the file is a directory (and
6887 is included in the archive).  @xref{Dumpdir}, for the detailed
6888 description of dumpdirs and status codes.  Each such
6889 line is terminated by a newline character.  The last line is followed
6890 by an additional newline to indicate the end of the data.
6892 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6893 gives the same behavior as @option{--listed-incremental} when used
6894 with @option{--list} and @option{--extract} options.  When used with
6895 @option{--create} option, it creates an incremental archive without
6896 creating snapshot file.  Thus, it is impossible to create several
6897 levels of incremental backups with @option{--incremental} option.
6899 @node Backup Levels
6900 @section Levels of Backups
6902 An archive containing all the files in the file system is called a
6903 @dfn{full backup} or @dfn{full dump}.  You could insure your data by
6904 creating a full dump every day.  This strategy, however, would waste a
6905 substantial amount of archive media and user time, as unchanged files
6906 are daily re-archived.
6908 It is more efficient to do a full dump only occasionally.  To back up
6909 files between full dumps, you can use @dfn{incremental dumps}.  A @dfn{level
6910 one} dump archives all the files that have changed since the last full
6911 dump.
6913 A typical dump strategy would be to perform a full dump once a week,
6914 and a level one dump once a day.  This means some versions of files
6915 will in fact be archived more than once, but this dump strategy makes
6916 it possible to restore a file system to within one day of accuracy by
6917 only extracting two archives---the last weekly (full) dump and the
6918 last daily (level one) dump.  The only information lost would be in
6919 files changed or created since the last daily backup.  (Doing dumps
6920 more than once a day is usually not worth the trouble.)
6922 @GNUTAR{} comes with scripts you can use to do full
6923 and level-one (actually, even level-two and so on) dumps.  Using
6924 scripts (shell programs) to perform backups and restoration is a
6925 convenient and reliable alternative to typing out file name lists
6926 and @command{tar} commands by hand.
6928 Before you use these scripts, you need to edit the file
6929 @file{backup-specs}, which specifies parameters used by the backup
6930 scripts and by the restore script.  This file is usually located
6931 in @file{/etc/backup} directory.  @xref{Backup Parameters}, for its
6932 detailed description.  Once the backup parameters are set, you can
6933 perform backups or restoration by running the appropriate script.
6935 The name of the backup script is @code{backup}.  The name of the
6936 restore script is @code{restore}.  The following sections describe
6937 their use in detail.
6939 @emph{Please Note:} The backup and restoration scripts are
6940 designed to be used together.  While it is possible to restore files by
6941 hand from an archive which was created using a backup script, and to create
6942 an archive by hand which could then be extracted using the restore script,
6943 it is easier to use the scripts.  @xref{Incremental Dumps}, before
6944 making such an attempt.
6946 @node Backup Parameters
6947 @section Setting Parameters for Backups and Restoration
6949 The file @file{backup-specs} specifies backup parameters for the
6950 backup and restoration scripts provided with @command{tar}.  You must
6951 edit @file{backup-specs} to fit your system configuration and schedule
6952 before using these scripts.
6954 Syntactically, @file{backup-specs} is a shell script, containing
6955 mainly variable assignments.  However, any valid shell construct
6956 is allowed in this file.  Particularly, you may wish to define
6957 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6958 For more information about shell script syntax, please refer to
6959 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6960 g_02, the definition of the Shell Command Language}.  See also
6961 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6963 The shell variables controlling behavior of @code{backup} and
6964 @code{restore} are described in the following subsections.
6966 @menu
6967 * General-Purpose Variables::
6968 * Magnetic Tape Control::
6969 * User Hooks::
6970 * backup-specs example::        An Example Text of @file{Backup-specs}
6971 @end menu
6973 @node General-Purpose Variables
6974 @subsection General-Purpose Variables
6976 @defvr {Backup variable} ADMINISTRATOR
6977 The user name of the backup administrator.  @code{Backup} scripts
6978 sends a backup report to this address.
6979 @end defvr
6981 @defvr {Backup variable} BACKUP_HOUR
6982 The hour at which the backups are done.  This can be a number from 0
6983 to 23, or the time specification in form @var{hours}:@var{minutes},
6984 or the string @samp{now}.
6986 This variable is used by @code{backup}.  Its value may be overridden
6987 using @option{--time} option (@pxref{Scripted Backups}).
6988 @end defvr
6990 @defvr {Backup variable} TAPE_FILE
6992 The device @command{tar} writes the archive to.  If @var{TAPE_FILE}
6993 is a remote archive (@pxref{remote-dev}), backup script will suppose
6994 that your @command{mt} is able to access remote devices.  If @var{RSH}
6995 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6996 invocations of @command{mt}.
6997 @end defvr
6999 @defvr {Backup variable} BLOCKING
7001 The blocking factor @command{tar} will use when writing the dump archive.
7002 @xref{Blocking Factor}.
7003 @end defvr
7005 @defvr {Backup variable} BACKUP_DIRS
7007 A list of file systems to be dumped (for @code{backup}), or restored
7008 (for @code{restore}).  You can include any directory
7009 name in the list --- subdirectories on that file system will be
7010 included, regardless of how they may look to other networked machines.
7011 Subdirectories on other file systems will be ignored.
7013 The host name specifies which host to run @command{tar} on, and should
7014 normally be the host that actually contains the file system.  However,
7015 the host machine must have @GNUTAR{} installed, and
7016 must be able to access the directory containing the backup scripts and
7017 their support files using the same file name that is used on the
7018 machine where the scripts are run (i.e., what @command{pwd} will print
7019 when in that directory on that machine).  If the host that contains
7020 the file system does not have this capability, you can specify another
7021 host as long as it can access the file system through @acronym{NFS}.
7023 If the list of file systems is very long you may wish to put it
7024 in a separate file.  This file is usually named
7025 @file{/etc/backup/dirs}, but this name may be overridden in
7026 @file{backup-specs} using @code{DIRLIST} variable.
7027 @end defvr
7029 @defvr {Backup variable} DIRLIST
7031 The name of the file that contains a list of file systems to backup
7032 or restore.  By default it is @file{/etc/backup/dirs}.
7033 @end defvr
7035 @defvr {Backup variable} BACKUP_FILES
7037 A list of individual files to be dumped (for @code{backup}), or restored
7038 (for @code{restore}).  These should be accessible from the machine on
7039 which the backup script is run.
7041 If the list of individual files is very long you may wish to store it
7042 in a separate file.  This file is usually named
7043 @file{/etc/backup/files}, but this name may be overridden in
7044 @file{backup-specs} using @code{FILELIST} variable.
7045 @end defvr
7047 @defvr {Backup variable} FILELIST
7049 The name of the file that contains a list of individual files to backup
7050 or restore.  By default it is @file{/etc/backup/files}.
7051 @end defvr
7053 @defvr {Backup variable} MT
7055 Full file name of @command{mt} binary.
7056 @end defvr
7058 @defvr {Backup variable} RSH
7059 @anchor{RSH}
7060 Full file name of @command{rsh} binary or its equivalent.  You may wish to
7061 set it to @code{ssh}, to improve security.  In this case you will have
7062 to use public key authentication.
7063 @end defvr
7065 @defvr {Backup variable} RSH_COMMAND
7067 Full file name of @command{rsh} binary on remote machines.  This will
7068 be passed via @option{--rsh-command} option to the remote invocation
7069 of @GNUTAR{}.
7070 @end defvr
7072 @defvr {Backup variable} VOLNO_FILE
7074 Name of temporary file to hold volume numbers.  This needs to be accessible
7075 by all the machines which have file systems to be dumped.
7076 @end defvr
7078 @defvr {Backup variable} XLIST
7080 Name of @dfn{exclude file list}.  An @dfn{exclude file list} is a file
7081 located on the remote machine and containing the list of files to
7082 be excluded from the backup.  Exclude file lists are searched in
7083 /etc/tar-backup directory.  A common use for exclude file lists
7084 is to exclude files containing security-sensitive information
7085 (e.g., @file{/etc/shadow} from backups).
7087 This variable affects only @code{backup}.
7088 @end defvr
7090 @defvr {Backup variable} SLEEP_TIME
7092 Time to sleep between dumps of any two successive file systems
7094 This variable affects only @code{backup}.
7095 @end defvr
7097 @defvr {Backup variable} DUMP_REMIND_SCRIPT
7099 Script to be run when it's time to insert a new tape in for the next
7100 volume.  Administrators may want to tailor this script for their site.
7101 If this variable isn't set, @GNUTAR{} will display its built-in
7102 prompt, and will expect confirmation from the console.  For the
7103 description of the default prompt, see @ref{change volume prompt}.
7105 @end defvr
7107 @defvr {Backup variable} SLEEP_MESSAGE
7109 Message to display on the terminal while waiting for dump time.  Usually
7110 this will just be some literal text.
7111 @end defvr
7113 @defvr {Backup variable} TAR
7115 Full file name of the @GNUTAR{} executable.  If this is not set, backup
7116 scripts will search @command{tar} in the current shell path.
7117 @end defvr
7119 @node Magnetic Tape Control
7120 @subsection Magnetic Tape Control
7122 Backup scripts access tape device using special @dfn{hook functions}.
7123 These functions take a single argument --- the name of the tape
7124 device.  Their names are kept in the following variables:
7126 @defvr {Backup variable} MT_BEGIN
7127 The name of @dfn{begin} function.  This function is called before
7128 accessing the drive.  By default it retensions the tape:
7130 @smallexample
7131 MT_BEGIN=mt_begin
7133 mt_begin() @{
7134     mt -f "$1" retension
7136 @end smallexample
7137 @end defvr
7139 @defvr {Backup variable} MT_REWIND
7140 The name of @dfn{rewind} function.  The default definition is as
7141 follows:
7143 @smallexample
7144 MT_REWIND=mt_rewind
7146 mt_rewind() @{
7147     mt -f "$1" rewind
7149 @end smallexample
7151 @end defvr
7153 @defvr {Backup variable} MT_OFFLINE
7154 The name of the function switching the tape off line.  By default
7155 it is defined as follows:
7157 @smallexample
7158 MT_OFFLINE=mt_offline
7160 mt_offline() @{
7161     mt -f "$1" offl
7163 @end smallexample
7164 @end defvr
7166 @defvr {Backup variable} MT_STATUS
7167 The name of the function used to obtain the status of the archive device,
7168 including error count.  Default definition:
7170 @smallexample
7171 MT_STATUS=mt_status
7173 mt_status() @{
7174     mt -f "$1" status
7176 @end smallexample
7177 @end defvr
7179 @node User Hooks
7180 @subsection User Hooks
7182 @dfn{User hooks} are shell functions executed before and after
7183 each @command{tar} invocation.  Thus, there are @dfn{backup
7184 hooks}, which are executed before and after dumping each file
7185 system, and @dfn{restore hooks}, executed before and
7186 after restoring a file system.  Each user hook is a shell function
7187 taking four arguments:
7189 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
7190 Its arguments are:
7192 @table @var
7193 @item level
7194 Current backup or restore level.
7196 @item host
7197 Name or IP address of the host machine being dumped or restored.
7199 @item fs
7200 Full file name of the file system being dumped or restored.
7202 @item fsname
7203 File system name with directory separators replaced with colons.  This
7204 is useful, e.g., for creating unique files.
7205 @end table
7206 @end deffn
7208 Following variables keep the names of user hook functions:
7210 @defvr {Backup variable} DUMP_BEGIN
7211 Dump begin function.  It is executed before dumping the file system.
7212 @end defvr
7214 @defvr {Backup variable} DUMP_END
7215 Executed after dumping the file system.
7216 @end defvr
7218 @defvr {Backup variable} RESTORE_BEGIN
7219 Executed before restoring the file system.
7220 @end defvr
7222 @defvr {Backup variable} RESTORE_END
7223 Executed after restoring the file system.
7224 @end defvr
7226 @node backup-specs example
7227 @subsection An Example Text of @file{Backup-specs}
7229 The following is an example of @file{backup-specs}:
7231 @smallexample
7232 # site-specific parameters for file system backup.
7234 ADMINISTRATOR=friedman
7235 BACKUP_HOUR=1
7236 TAPE_FILE=/dev/nrsmt0
7238 # Use @code{ssh} instead of the less secure @code{rsh}
7239 RSH=/usr/bin/ssh
7240 RSH_COMMAND=/usr/bin/ssh
7242 # Override MT_STATUS function:
7243 my_status() @{
7244       mts -t $TAPE_FILE
7246 MT_STATUS=my_status
7248 # Disable MT_OFFLINE function
7249 MT_OFFLINE=:
7251 BLOCKING=124
7252 BACKUP_DIRS="
7253         albert:/fs/fsf
7254         apple-gunkies:/gd
7255         albert:/fs/gd2
7256         albert:/fs/gp
7257         geech:/usr/jla
7258         churchy:/usr/roland
7259         albert:/
7260         albert:/usr
7261         apple-gunkies:/
7262         apple-gunkies:/usr
7263         gnu:/hack
7264         gnu:/u
7265         apple-gunkies:/com/mailer/gnu
7266         apple-gunkies:/com/archive/gnu"
7268 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
7270 @end smallexample
7272 @node Scripted Backups
7273 @section Using the Backup Scripts
7275 The syntax for running a backup script is:
7277 @smallexample
7278 backup --level=@var{level} --time=@var{time}
7279 @end smallexample
7281 The @option{--level} option requests the dump level.  Thus, to produce
7282 a full dump, specify @code{--level=0} (this is the default, so
7283 @option{--level} may be omitted if its value is
7284 @code{0})@footnote{For backward compatibility, the @code{backup} will also
7285 try to deduce the requested dump level from the name of the
7286 script itself.  If the name consists of a string @samp{level-}
7287 followed by a single decimal digit, that digit is taken as
7288 the dump level number.  Thus, you may create a link from @code{backup}
7289 to @code{level-1} and then run @code{level-1} whenever you need to
7290 create a level one dump.}.
7292 The @option{--time} option determines when should the backup be
7293 run.  @var{Time} may take three forms:
7295 @table @asis
7296 @item @var{hh}:@var{mm}
7298 The dump must be run at @var{hh} hours @var{mm} minutes.
7300 @item @var{hh}
7302 The dump must be run at @var{hh} hours.
7304 @item now
7306 The dump must be run immediately.
7307 @end table
7309 You should start a script with a tape or disk mounted.  Once you
7310 start a script, it prompts you for new tapes or disks as it
7311 needs them.  Media volumes don't have to correspond to archive
7312 files --- a multi-volume archive can be started in the middle of a
7313 tape that already contains the end of another multi-volume archive.
7314 The @code{restore} script prompts for media by its archive volume,
7315 so to avoid an error message you should keep track of which tape
7316 (or disk) contains which volume of the archive (@pxref{Scripted
7317 Restoration}).
7319 The backup scripts write two files on the file system.  The first is a
7320 record file in @file{/etc/tar-backup/}, which is used by the scripts
7321 to store and retrieve information about which files were dumped.  This
7322 file is not meant to be read by humans, and should not be deleted by
7323 them.  @xref{Snapshot Files}, for a more detailed explanation of this
7324 file.
7326 The second file is a log file containing the names of the file systems
7327 and files dumped, what time the backup was made, and any error
7328 messages that were generated, as well as how much space was left in
7329 the media volume after the last volume of the archive was written.
7330 You should check this log file after every backup.  The file name is
7331 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
7332 represents current date, and @var{n} represents current dump level number.
7334 The script also prints the name of each system being dumped to the
7335 standard output.
7337 Following is the full list of options accepted by @code{backup}
7338 script:
7340 @table @option
7341 @item -l @var{level}
7342 @itemx --level=@var{level}
7343 Do backup level @var{level} (default 0).
7345 @item -f
7346 @itemx --force
7347 Force backup even if today's log file already exists.
7349 @item -v[@var{level}]
7350 @itemx --verbose[=@var{level}]
7351 Set verbosity level.  The higher the level is, the more debugging
7352 information will be output during execution.  Default @var{level}
7353 is 100, which means the highest debugging level.
7355 @item -t @var{start-time}
7356 @itemx --time=@var{start-time}
7357 Wait till @var{time}, then do backup.
7359 @item -h
7360 @itemx --help
7361 Display short help message and exit.
7363 @item -V
7364 @itemx --version
7365 Display information about the program's name, version, origin and legal
7366 status, all on standard output, and then exit successfully.
7367 @end table
7370 @node Scripted Restoration
7371 @section Using the Restore Script
7373 To restore files that were archived using a scripted backup, use the
7374 @code{restore} script.  Its usage is quite straightforward.  In the
7375 simplest form, invoke @code{restore --all}, it will
7376 then restore all the file systems and files specified in
7377 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
7379 You may select the file systems (and/or files) to restore by
7380 giving @code{restore} a list of @dfn{patterns} in its command
7381 line.  For example, running
7383 @smallexample
7384 restore 'albert:*'
7385 @end smallexample
7387 @noindent
7388 will restore all file systems on the machine @samp{albert}.  A more
7389 complicated example:
7391 @smallexample
7392 restore 'albert:*' '*:/var'
7393 @end smallexample
7395 @noindent
7396 This command will restore all file systems on the machine @samp{albert}
7397 as well as @file{/var} file system on all machines.
7399 By default @code{restore} will start restoring files from the lowest
7400 available dump level (usually zero) and will continue through
7401 all available dump levels.  There may be situations where such a
7402 thorough restore is not necessary.  For example, you may wish to
7403 restore only files from the recent level one backup.  To do so,
7404 use @option{--level} option, as shown in the example below:
7406 @smallexample
7407 restore --level=1
7408 @end smallexample
7410 The full list of options accepted by @code{restore} follows:
7412 @table @option
7413 @item -a
7414 @itemx --all
7415 Restore all file systems and files specified in @file{backup-specs}.
7417 @item -l @var{level}
7418 @itemx --level=@var{level}
7419 Start restoring from the given backup level, instead of the default 0.
7421 @item -v[@var{level}]
7422 @itemx --verbose[=@var{level}]
7423 Set verbosity level.  The higher the level is, the more debugging
7424 information will be output during execution.  Default @var{level}
7425 is 100, which means the highest debugging level.
7427 @item -h
7428 @itemx --help
7429 Display short help message and exit.
7431 @item -V
7432 @itemx --version
7433 Display information about the program's name, version, origin and legal
7434 status, all on standard output, and then exit successfully.
7435 @end table
7437 You should start the restore script with the media containing the
7438 first volume of the archive mounted.  The script will prompt for other
7439 volumes as they are needed.  If the archive is on tape, you don't need
7440 to rewind the tape to to its beginning---if the tape head is
7441 positioned past the beginning of the archive, the script will rewind
7442 the tape as needed.  @xref{Tape Positioning}, for a discussion of tape
7443 positioning.
7445 @quotation
7446 @strong{Warning:} The script will delete files from the active file
7447 system if they were not in the file system when the archive was made.
7448 @end quotation
7450 @xref{Incremental Dumps}, for an explanation of how the script makes
7451 that determination.
7453 @node Choosing
7454 @chapter Choosing Files and Names for @command{tar}
7456 Certain options to @command{tar} enable you to specify a name for your
7457 archive.  Other options let you decide which files to include or exclude
7458 from the archive, based on when or whether files were modified, whether
7459 the file names do or don't match specified patterns, or whether files
7460 are in specified directories.
7462 This chapter discusses these options in detail.
7464 @menu
7465 * file::                        Choosing the Archive's Name
7466 * Selecting Archive Members::
7467 * files::                       Reading Names from a File
7468 * exclude::                     Excluding Some Files
7469 * wildcards::                   Wildcards Patterns and Matching
7470 * quoting styles::              Ways of Quoting Special Characters in Names
7471 * transform::                   Modifying File and Member Names
7472 * after::                       Operating Only on New Files
7473 * recurse::                     Descending into Directories
7474 * one::                         Crossing File System Boundaries
7475 @end menu
7477 @node file
7478 @section Choosing and Naming Archive Files
7480 @cindex Naming an archive
7481 @cindex Archive Name
7482 @cindex Choosing an archive file
7483 @cindex Where is the archive?
7484 @opindex file
7485 By default, @command{tar} uses an archive file name that was compiled when
7486 it was built on the system; usually this name refers to some physical
7487 tape drive on the machine.  However, the person who installed @command{tar}
7488 on the system may not have set the default to a meaningful value as far as
7489 most users are concerned.  As a result, you will usually want to tell
7490 @command{tar} where to find (or create) the archive.  The
7491 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
7492 option allows you to either specify or name a file to use as the archive
7493 instead of the default archive file location.
7495 @table @option
7496 @xopindex{file, short description}
7497 @item --file=@var{archive-name}
7498 @itemx -f @var{archive-name}
7499 Name the archive to create or operate on.  Use in conjunction with
7500 any operation.
7501 @end table
7503 For example, in this @command{tar} command,
7505 @smallexample
7506 $ @kbd{tar -cvf collection.tar blues folk jazz}
7507 @end smallexample
7509 @noindent
7510 @file{collection.tar} is the name of the archive.  It must directly
7511 follow the @option{-f} option, since whatever directly follows @option{-f}
7512 @emph{will} end up naming the archive.  If you neglect to specify an
7513 archive name, you may end up overwriting a file in the working directory
7514 with the archive you create since @command{tar} will use this file's name
7515 for the archive name.
7517 An archive can be saved as a file in the file system, sent through a
7518 pipe or over a network, or written to an I/O device such as a tape,
7519 floppy disk, or CD write drive.
7521 @cindex Writing new archives
7522 @cindex Archive creation
7523 If you do not name the archive, @command{tar} uses the value of the
7524 environment variable @env{TAPE} as the file name for the archive.  If
7525 that is not available, @command{tar} uses a default, compiled-in archive
7526 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
7528 @cindex Standard input and output
7529 @cindex tar to standard input and output
7530 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
7531 archive from standard input (when listing or extracting files), or
7532 writes it to standard output (when creating an archive).  If you use
7533 @file{-} as an @var{archive-name} when modifying an archive,
7534 @command{tar} reads the original archive from its standard input and
7535 writes the entire new archive to its standard output.
7537 The following example is a convenient way of copying directory
7538 hierarchy from @file{sourcedir} to @file{targetdir}.
7540 @smallexample
7541 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
7542 @end smallexample
7544 The @option{-C} option allows to avoid using subshells:
7546 @smallexample
7547 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
7548 @end smallexample
7550 In both examples above, the leftmost @command{tar} invocation archives
7551 the contents of @file{sourcedir} to the standard output, while the
7552 rightmost one reads this archive from its standard input and
7553 extracts it.  The @option{-p} option tells it to restore permissions
7554 of the extracted files.
7556 @cindex Remote devices
7557 @cindex tar to a remote device
7558 @anchor{remote-dev}
7559 To specify an archive file on a device attached to a remote machine,
7560 use the following:
7562 @smallexample
7563 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
7564 @end smallexample
7566 @noindent
7567 @command{tar} will set up the remote connection, if possible, and
7568 prompt you for a username and password.  If you use
7569 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
7570 will attempt to set up the remote connection using your username
7571 as the username on the remote machine.
7573 @cindex Local and remote archives
7574 @anchor{local and remote archives}
7575 If the archive file name includes a colon (@samp{:}), then it is assumed
7576 to be a file on another machine.  If the archive file is
7577 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
7578 host @var{host}.  The remote host is accessed using the @command{rsh}
7579 program, with a username of @var{user}.  If the username is omitted
7580 (along with the @samp{@@} sign), then your user name will be used.
7581 (This is the normal @command{rsh} behavior.)  It is necessary for the
7582 remote machine, in addition to permitting your @command{rsh} access, to
7583 have the @file{rmt} program installed (this command is included in
7584 the @GNUTAR{} distribution and by default is installed under
7585 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
7586 installation prefix).  If you need to use a file whose name includes a
7587 colon, then the remote tape drive behavior
7588 can be inhibited by using the @option{--force-local} option.
7590 When the archive is being created to @file{/dev/null}, @GNUTAR{}
7591 tries to minimize input and output operations.  The Amanda backup
7592 system, when used with @GNUTAR{}, has an initial sizing pass which
7593 uses this feature.
7595 @node Selecting Archive Members
7596 @section Selecting Archive Members
7597 @cindex Specifying files to act on
7598 @cindex Specifying archive members
7600 @dfn{File Name arguments} specify which files in the file system
7601 @command{tar} operates on, when creating or adding to an archive, or which
7602 archive members @command{tar} operates on, when reading or deleting from
7603 an archive.  @xref{Operations}.
7605 To specify file names, you can include them as the last arguments on
7606 the command line, as follows:
7607 @smallexample
7608 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
7609 @end smallexample
7611 If a file name begins with dash (@samp{-}), precede it with
7612 @option{--add-file} option to prevent it from being treated as an
7613 option.
7615 @anchor{input name quoting}
7616 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7617 name, replacing @dfn{escape sequences} according to the following
7618 table:
7620 @multitable @columnfractions 0.20 0.60
7621 @headitem Escape @tab Replaced with
7622 @item \a         @tab Audible bell (@acronym{ASCII} 7)
7623 @item \b         @tab Backspace (@acronym{ASCII} 8)
7624 @item \f         @tab Form feed (@acronym{ASCII} 12)
7625 @item \n         @tab New line (@acronym{ASCII} 10)
7626 @item \r         @tab Carriage return (@acronym{ASCII} 13)
7627 @item \t         @tab Horizontal tabulation (@acronym{ASCII} 9)
7628 @item \v         @tab Vertical tabulation (@acronym{ASCII} 11)
7629 @item \?         @tab @acronym{ASCII} 127
7630 @item \@var{n}   @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7631                  of up to 3 digits)
7632 @end multitable
7634 A backslash followed by any other symbol is retained.
7636 This default behavior is controlled by the following command line
7637 option:
7639 @table @option
7640 @opindex unquote
7641 @item --unquote
7642 Enable unquoting input file or member names (default).
7644 @opindex no-unquote
7645 @item --no-unquote
7646 Disable unquoting input file or member names.
7647 @end table
7649 If you specify a directory name as a file name argument, all the files
7650 in that directory are operated on by @command{tar}.
7652 If you do not specify files, @command{tar} behavior differs depending
7653 on the operation mode as described below:
7655 When @command{tar} is invoked with @option{--create} (@option{-c}),
7656 @command{tar} will stop immediately, reporting the following:
7658 @smallexample
7659 @group
7660 $ @kbd{tar cf a.tar}
7661 tar: Cowardly refusing to create an empty archive
7662 Try 'tar --help' or 'tar --usage' for more information.
7663 @end group
7664 @end smallexample
7666 If you specify either @option{--list} (@option{-t}) or
7667 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7668 operates on all the archive members in the archive.
7670 If run with @option{--diff} option, tar will compare the archive with
7671 the contents of the current working directory.
7673 If you specify any other operation, @command{tar} does nothing.
7675 By default, @command{tar} takes file names from the command line.  However,
7676 there are other ways to specify file or member names, or to modify the
7677 manner in which @command{tar} selects the files or members upon which to
7678 operate.  In general, these methods work both for specifying the names
7679 of files and archive members.
7681 @node files
7682 @section Reading Names from a File
7684 @cindex Reading file names from a file
7685 @cindex Lists of file names
7686 @cindex File Name arguments, alternatives
7687 @cindex @command{find}, using with @command{tar}
7688 Instead of giving the names of files or archive members on the command
7689 line, you can put the names into a file, and then use the
7690 @option{--files-from=@var{file-of-names}} (@option{-T
7691 @var{file-of-names}}) option to @command{tar}.  Give the name of the
7692 file which contains the list of files to include as the argument to
7693 @option{--files-from}.  In the list, the file names should be separated by
7694 newlines.  You will frequently use this option when you have generated
7695 the list of files to archive with the @command{find} utility.
7697 @table @option
7698 @opindex files-from
7699 @item --files-from=@var{file-name}
7700 @itemx -T @var{file-name}
7701 Get names to extract or create from file @var{file-name}.
7702 @end table
7704 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7705 you specify either @code{--files-from=-} or @code{-T -}), then the file
7706 names are read from standard input.
7708 Unless you are running @command{tar} with @option{--create}, you cannot use
7709 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7710 command.
7712 Any number of @option{-T} options can be given in the command line.
7714 The following example shows how to use @command{find} to generate a list of
7715 files smaller than 400K in length and put that list into a file
7716 called @file{small-files}.  You can then use the @option{-T} option to
7717 @command{tar} to specify the files from that file, @file{small-files}, to
7718 create the archive @file{little.tgz}.  (The @option{-z} option to
7719 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7720 more information.)
7722 @smallexample
7723 $ @kbd{find . -size -400 -print > small-files}
7724 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7725 @end smallexample
7727 @noindent
7728 By default, each line read from the file list is first stripped off
7729 any leading and trailing whitespace.  If the resulting string begins
7730 with @samp{-} character, it is considered a @command{tar} option and is
7731 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7732 recognized only @option{-C} option in file lists, and only if the
7733 option and its argument occupied two consecutive lines.}. For example,
7734 the common use of this feature is to change to another directory by
7735 specifying @option{-C} option:
7737 @smallexample
7738 @group
7739 $ @kbd{cat list}
7740 -C/etc
7741 passwd
7742 hosts
7743 -C/lib
7744 libc.a
7745 $ @kbd{tar -c -f foo.tar --files-from list}
7746 @end group
7747 @end smallexample
7749 @noindent
7750 In this example, @command{tar} will first switch to @file{/etc}
7751 directory and add files @file{passwd} and @file{hosts} to the
7752 archive.  Then it will change to @file{/lib} directory and will archive
7753 the file @file{libc.a}.  Thus, the resulting archive @file{foo.tar} will
7754 contain:
7756 @smallexample
7757 @group
7758 $ @kbd{tar tf foo.tar}
7759 passwd
7760 hosts
7761 libc.a
7762 @end group
7763 @end smallexample
7765 Note, that any options used in the file list remain in effect for the
7766 rest of the command line.  For example, using the same @file{list}
7767 file as above, the following command
7769 @smallexample
7770 $ @kbd{tar -c -f foo.tar --files-from list libcurses.a}
7771 @end smallexample
7773 @noindent
7774 will look for file @file{libcurses.a} in the directory @file{/lib},
7775 because it was used with the last @option{-C} option
7776 (@pxref{Position-Sensitive Options}).
7778 @anchor{verbatim-files-from}
7779 @opindex verbatim-files-from
7780 If such option handling is undesirable, use the
7781 @option{--verbatim-files-from} option.  When this option is in effect,
7782 each line read from the file list is treated as a file name.  Notice,
7783 that this means, in particular, that no whitespace trimming is
7784 performed.
7786 @anchor{no-verbatim-files-from}
7787 @opindex no-verbatim-files-from
7788 The @option{--verbatim-files-from} affects all @option{-T} options
7789 that follow it in the command line.  The default behavior can be
7790 restored using @option{--no-verbatim-files-from} option.
7792 @opindex add-file
7793 To disable option handling for a single file name, use the
7794 @option{--add-file} option, e.g.: @code{--add-file=--my-file}.
7796 You can use any @GNUTAR{} command line options in the file list file,
7797 including @option{--files-from} option itself.  This allows for
7798 including contents of a file list into another file list file.
7799 Note however, that options that control file list processing, such as
7800 @option{--verbatim-files-from} or @option{--null} won't affect the
7801 file they appear in.  They will affect next @option{--files-from}
7802 option, if there is any.
7804 @menu
7805 * nul::
7806 @end menu
7808 @node nul
7809 @subsection @code{NUL}-Terminated File Names
7811 @cindex File names, terminated by @code{NUL}
7812 @cindex @code{NUL}-terminated file names
7813 The @option{--null} option causes
7814 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7815 to read file names terminated by a @code{NUL} instead of a newline, so
7816 files whose names contain newlines can be archived using
7817 @option{--files-from}.
7819 @table @option
7820 @xopindex{null, described}
7821 @item --null
7822 Only consider @code{NUL}-terminated file names, instead of files that
7823 terminate in a newline.
7825 @xopindex{no-null, described}
7826 @item --no-null
7827 Undo the effect of any previous @option{--null} option.
7828 @end table
7830 The @option{--null} option is just like the one in @acronym{GNU}
7831 @command{xargs} and @command{cpio}, and is useful with the
7832 @option{-print0} predicate of @acronym{GNU} @command{find}.  In
7833 @command{tar}, @option{--null} also disables special handling for
7834 file names that begin with dash (similar to
7835 @option{--verbatim-files-from} option).
7837 This example shows how to use @command{find} to generate a list of files
7838 larger than 800K in length and put that list into a file called
7839 @file{long-files}.  The @option{-print0} option to @command{find} is just
7840 like @option{-print}, except that it separates files with a @code{NUL}
7841 rather than with a newline.  You can then run @command{tar} with both the
7842 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7843 files from that file, @file{long-files}, to create the archive
7844 @file{big.tgz}.  The @option{--null} option to @command{tar} will cause
7845 @command{tar} to recognize the @code{NUL} separator between files.
7847 @smallexample
7848 $ @kbd{find . -size +800 -print0 > long-files}
7849 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7850 @end smallexample
7852 The @option{--no-null} option can be used if you need to read both
7853 @code{NUL}-terminated and newline-terminated files on the same command line.
7854 For example, if @file{flist} is a newline-terminated file, then the
7855 following command can be used to combine it with the above command:
7857 @smallexample
7858 @group
7859 $ @kbd{find . -size +800 -print0 |
7860   tar -c -f big.tar --null -T - --no-null -T flist}
7861 @end group
7862 @end smallexample
7864 This example uses short options for typographic reasons, to avoid
7865 very long lines.
7867 @GNUTAR is tries to automatically detect @code{NUL}-terminated file
7868 lists, so in many cases it is safe to use them even without the
7869 @option{--null} option.  In this case @command{tar} will print a
7870 warning and continue reading such a file as if @option{--null} were
7871 actually given:
7873 @smallexample
7874 @group
7875 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7876 tar: -: file name read contains nul character
7877 @end group
7878 @end smallexample
7880 The null terminator, however, remains in effect only for this
7881 particular file, any following @option{-T} options will assume
7882 newline termination.  Of course, the null autodetection applies
7883 to these eventual surplus @option{-T} options as well.
7885 @node exclude
7886 @section Excluding Some Files
7888 @cindex File names, excluding files by
7889 @cindex Excluding files by name and pattern
7890 @cindex Excluding files by file system
7891 @opindex exclude
7892 @opindex exclude-from
7893 To avoid operating on files whose names match a particular pattern,
7894 use the @option{--exclude} or @option{--exclude-from} options.
7896 @table @option
7897 @opindex exclude
7898 @item --exclude=@var{pattern}
7899 Causes @command{tar} to ignore files that match the @var{pattern}.
7900 @end table
7902 @findex exclude
7903 The @option{--exclude=@var{pattern}} option prevents any file or
7904 member whose name matches the shell wildcard (@var{pattern}) from
7905 being operated on.
7906 For example, to create an archive with all the contents of the directory
7907 @file{src} except for files whose names end in @file{.o}, use the
7908 command @samp{tar -cf src.tar --exclude='*.o' src}.
7910 You may give multiple @option{--exclude} options.
7912 @table @option
7913 @opindex exclude-from
7914 @item --exclude-from=@var{file}
7915 @itemx -X @var{file}
7916 Causes @command{tar} to ignore files that match the patterns listed in
7917 @var{file}.
7918 @end table
7920 @findex exclude-from
7921 Use the @option{--exclude-from} option to read a
7922 list of patterns, one per line, from @var{file}; @command{tar} will
7923 ignore files matching those patterns.  Thus if @command{tar} is
7924 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7925 single line @file{*.o}, no files whose names end in @file{.o} will be
7926 added to the archive.
7928 Notice, that lines from @var{file} are read verbatim. One of the
7929 frequent errors is leaving some extra whitespace after a file name,
7930 which is difficult to catch using text editors.
7932 However, empty lines are OK.
7934 @cindex VCS, excluding patterns from ignore files
7935 @cindex VCS, ignore files
7936 @cindex CVS, ignore files
7937 @cindex Git, ignore files
7938 @cindex Bazaar, ignore files
7939 @cindex Mercurial, ignore files
7940 When archiving directories that are under some version control system (VCS),
7941 it is often convenient to read exclusion patterns from this VCS'
7942 ignore files (e.g. @file{.cvsignore}, @file{.gitignore}, etc.)  The
7943 following options provide such possibility:
7945 @table @option
7946 @anchor{exclude-vcs-ignores}
7947 @opindex exclude-vcs-ignores
7948 @item --exclude-vcs-ignores
7949 Before archiving a directory, see if it contains any of the following
7950 files: @file{cvsignore}, @file{.gitignore}, @file{.bzrignore}, or
7951 @file{.hgignore}.  If so, read ignore patterns from these files.
7953 The patterns are treated much as the corresponding VCS would treat
7954 them, i.e.:
7956 @table @file
7957 @findex .cvsignore
7958 @item .cvsignore
7959 Contains shell-style globbing patterns that apply only to the
7960 directory where this file resides.  No comments are allowed in the
7961 file.  Empty lines are ignored.
7963 @findex .gitignore
7964 @item .gitignore
7965 Contains shell-style globbing patterns.  Applies to the directory
7966 where @file{.gitfile} is located and all its subdirectories.
7968 Any line beginning with a @samp{#} is a comment.  Backslash escapes
7969 the comment character.
7971 @findex .bzrignore
7972 @item .bzrignore
7973 Contains shell globbing-patterns and regular expressions (if prefixed
7974 with @samp{RE:}@footnote{According to the Bazaar docs,
7975 globbing-patterns are Korn-shell style and regular expressions are
7976 perl-style.  As of @GNUTAR{} version @value{VERSION}, these are
7977 treated as shell-style globs and posix extended regexps.  This will be
7978 fixed in future releases.}.  Patterns affect the directory and all its
7979 subdirectories.
7981 Any line beginning with a @samp{#} is a comment.
7983 @findex .hgignore
7984 @item .hgignore
7985 Contains posix regular expressions@footnote{Support for perl-style
7986 regexps will appear in future releases.}.  The line @samp{syntax:
7987 glob} switches to shell globbing patterns.  The line @samp{syntax:
7988 regexp} switches back.  Comments begin with a @samp{#}.  Patterns
7989 affect the directory and all its subdirectories.
7990 @end table
7992 @opindex exclude-ignore
7993 @item --exclude-ignore=@var{file}
7994 Before dumping a directory, @command{tar} checks if it contains
7995 @var{file}.  If so, exclusion patterns are read from this file.
7996 The patterns affect only the directory itself.
7998 @opindex exclude-ignore-recursive
7999 @item --exclude-ignore-recursive=@var{file}
8000 Same as @option{--exclude-ignore}, except that the patterns read
8001 affect both the directory where @var{file} resides and all its
8002 subdirectories.
8003 @end table
8005 @table @option
8006 @cindex version control system, excluding files
8007 @cindex VCS, excluding files
8008 @cindex SCCS, excluding files
8009 @cindex RCS, excluding files
8010 @cindex CVS, excluding files
8011 @cindex SVN, excluding files
8012 @cindex git, excluding files
8013 @cindex Bazaar, excluding files
8014 @cindex Arch, excluding files
8015 @cindex Mercurial, excluding files
8016 @cindex Darcs, excluding files
8017 @anchor{exclude-vcs}
8018 @opindex exclude-vcs
8019 @item --exclude-vcs
8020 Exclude files and directories used by following version control
8021 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
8022 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
8024 As of version @value{VERSION}, the following files are excluded:
8026 @itemize @bullet
8027 @item @file{CVS/}, and everything under it
8028 @item @file{RCS/}, and everything under it
8029 @item @file{SCCS/}, and everything under it
8030 @item @file{.git/}, and everything under it
8031 @item @file{.gitignore}
8032 @item @file{.gitmodules}
8033 @item @file{.gitattributes}
8034 @item @file{.cvsignore}
8035 @item @file{.svn/}, and everything under it
8036 @item @file{.arch-ids/}, and everything under it
8037 @item @file{@{arch@}/}, and everything under it
8038 @item @file{=RELEASE-ID}
8039 @item @file{=meta-update}
8040 @item @file{=update}
8041 @item @file{.bzr}
8042 @item @file{.bzrignore}
8043 @item @file{.bzrtags}
8044 @item @file{.hg}
8045 @item @file{.hgignore}
8046 @item @file{.hgrags}
8047 @item @file{_darcs}
8048 @end itemize
8050 @opindex exclude-backups
8051 @item --exclude-backups
8052 Exclude backup and lock files.  This option causes exclusion of files
8053 that match the following shell globbing patterns:
8055 @table @asis
8056 @item .#*
8057 @item *~
8058 @item #*#
8059 @end table
8061 @end table
8063 @findex exclude-caches
8064 When creating an archive, the @option{--exclude-caches} option family
8065 causes @command{tar} to exclude all directories that contain a @dfn{cache
8066 directory tag}. A cache directory tag is a short file with the
8067 well-known name @file{CACHEDIR.TAG} and having a standard header
8068 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
8069 Various applications write cache directory tags into directories they
8070 use to hold regenerable, non-precious data, so that such data can be
8071 more easily excluded from backups.
8073 There are three @samp{exclude-caches} options, each providing a different
8074 exclusion semantics:
8076 @table @option
8077 @opindex exclude-caches
8078 @item --exclude-caches
8079 Do not archive the contents of the directory, but archive the
8080 directory itself and the @file{CACHEDIR.TAG} file.
8082 @opindex exclude-caches-under
8083 @item --exclude-caches-under
8084 Do not archive the contents of the directory, nor the
8085 @file{CACHEDIR.TAG} file, archive only the directory itself.
8087 @opindex exclude-caches-all
8088 @item --exclude-caches-all
8089 Omit directories containing @file{CACHEDIR.TAG} file entirely.
8090 @end table
8092 @findex exclude-tag
8093 Another option family, @option{--exclude-tag}, provides a generalization of
8094 this concept.  It takes a single argument, a file name to look for.
8095 Any directory that contains this file will be excluded from the dump.
8096 Similarly to @samp{exclude-caches}, there are three options in this
8097 option family:
8099 @table @option
8100 @opindex exclude-tag
8101 @item --exclude-tag=@var{file}
8102 Do not dump the contents of the directory, but dump the
8103 directory itself and the @var{file}.
8105 @opindex exclude-tag-under
8106 @item --exclude-tag-under=@var{file}
8107 Do not dump the contents of the directory, nor the
8108 @var{file}, archive only the directory itself.
8110 @opindex exclude-tag-all
8111 @item --exclude-tag-all=@var{file}
8112 Omit directories containing @var{file} file entirely.
8113 @end table
8115 Multiple @option{--exclude-tag*} options can be given.
8117 For example, given this directory:
8119 @smallexample
8120 @group
8121 $ @kbd{find dir}
8123 dir/blues
8124 dir/jazz
8125 dir/folk
8126 dir/folk/tagfile
8127 dir/folk/sanjuan
8128 dir/folk/trote
8129 @end group
8130 @end smallexample
8132 The @option{--exclude-tag} will produce the following:
8134 @smallexample
8135 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
8136 dir/
8137 dir/blues
8138 dir/jazz
8139 dir/folk/
8140 tar: dir/folk/: contains a cache directory tag tagfile;
8141   contents not dumped
8142 dir/folk/tagfile
8143 @end smallexample
8145 Both the @file{dir/folk} directory and its tagfile are preserved in
8146 the archive, however the rest of files in this directory are not.
8148 Now, using the @option{--exclude-tag-under} option will exclude
8149 @file{tagfile} from the dump, while still preserving the directory
8150 itself, as shown in this example:
8152 @smallexample
8153 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
8154 dir/
8155 dir/blues
8156 dir/jazz
8157 dir/folk/
8158 ./tar: dir/folk/: contains a cache directory tag tagfile;
8159   contents not dumped
8160 @end smallexample
8162 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
8163 directory entirely:
8165 @smallexample
8166 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
8167 dir/
8168 dir/blues
8169 dir/jazz
8170 ./tar: dir/folk/: contains a cache directory tag tagfile;
8171   directory not dumped
8172 @end smallexample
8174 @menu
8175 * problems with exclude::
8176 @end menu
8178 @node problems with exclude
8179 @unnumberedsubsec Problems with Using the @code{exclude} Options
8181 @xopindex{exclude, potential problems with}
8182 Some users find @samp{exclude} options confusing.  Here are some common
8183 pitfalls:
8185 @itemize @bullet
8186 @item
8187 The main operating mode of @command{tar} does not act on a file name
8188 explicitly listed on the command line, if one of its file name
8189 components is excluded.  In the example above, if
8190 you create an archive and exclude files that end with @samp{*.o}, but
8191 explicitly name the file @samp{dir.o/foo} after all the options have been
8192 listed, @samp{dir.o/foo} will be excluded from the archive.
8194 @item
8195 You can sometimes confuse the meanings of @option{--exclude} and
8196 @option{--exclude-from}.  Be careful: use @option{--exclude} when files
8197 to be excluded are given as a pattern on the command line.  Use
8198 @option{--exclude-from} to introduce the name of a file which contains
8199 a list of patterns, one per line; each of these patterns can exclude
8200 zero, one, or many files.
8202 @item
8203 When you use @option{--exclude=@var{pattern}}, be sure to quote the
8204 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
8205 like @samp{*}.  If you do not do this, the shell might expand the
8206 @samp{*} itself using files at hand, so @command{tar} might receive a
8207 list of files instead of one pattern, or none at all, making the
8208 command somewhat illegal.  This might not correspond to what you want.
8210 For example, write:
8212 @smallexample
8213 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
8214 @end smallexample
8216 @noindent
8217 rather than:
8219 @smallexample
8220 # @emph{Wrong!}
8221 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
8222 @end smallexample
8224 @item
8225 You must use use shell syntax, or globbing, rather than @code{regexp}
8226 syntax, when using exclude options in @command{tar}.  If you try to use
8227 @code{regexp} syntax to describe files to be excluded, your command
8228 might fail.
8230 @item
8231 @FIXME{The change in semantics must have occurred before 1.11,
8232 so I doubt if it is worth mentioning at all. Anyway, should at
8233 least specify in which version the semantics changed.}
8234 In earlier versions of @command{tar}, what is now the
8235 @option{--exclude-from} option was called @option{--exclude} instead.
8236 Now, @option{--exclude} applies to patterns listed on the command
8237 line and @option{--exclude-from} applies to patterns listed in a
8238 file.
8240 @end itemize
8242 @node wildcards
8243 @section Wildcards Patterns and Matching
8245 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
8246 @samp{*} or @samp{?} for example, are replaced and expanded into all
8247 existing files matching the given pattern.  @GNUTAR{} can use wildcard
8248 patterns for matching (or globbing) archive members when extracting
8249 from or listing an archive.  Wildcard patterns are also used for
8250 verifying volume labels of @command{tar} archives.  This section has the
8251 purpose of explaining wildcard syntax for @command{tar}.
8253 @FIXME{the next few paragraphs need work.}
8255 A @var{pattern} should be written according to shell syntax, using wildcard
8256 characters to effect globbing.  Most characters in the pattern stand
8257 for themselves in the matched string, and case is significant: @samp{a}
8258 will match only @samp{a}, and not @samp{A}.  The character @samp{?} in the
8259 pattern matches any single character in the matched string.  The character
8260 @samp{*} in the pattern matches zero, one, or more single characters in
8261 the matched string.  The character @samp{\} says to take the following
8262 character of the pattern @emph{literally}; it is useful when one needs to
8263 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
8265 The character @samp{[}, up to the matching @samp{]}, introduces a character
8266 class.  A @dfn{character class} is a list of acceptable characters
8267 for the next single character of the matched string.  For example,
8268 @samp{[abcde]} would match any of the first five letters of the alphabet.
8269 Note that within a character class, all of the ``special characters''
8270 listed above other than @samp{\} lose their special meaning; for example,
8271 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
8272 @samp{[}, @samp{*}, @samp{?}, or @samp{]}.  (Due to parsing constraints,
8273 the characters @samp{-} and @samp{]} must either come @emph{first} or
8274 @emph{last} in a character class.)
8276 @cindex Excluding characters from a character class
8277 @cindex Character class, excluding characters from
8278 If the first character of the class after the opening @samp{[}
8279 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
8280 Rather than listing character to match, it lists those characters which
8281 are @emph{forbidden} as the next single character of the matched string.
8283 Other characters of the class stand for themselves.  The special
8284 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
8285 letters, is meant to represent all characters between @var{a} and
8286 @var{e}, inclusive.
8288 @FIXME{need to add a sentence or so here to make this clear for those
8289 who don't have dan around.}
8291 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
8292 special for wildcard matches.  However, if a pattern completely matches
8293 a directory prefix of a matched string, then it matches the full matched
8294 string: thus, excluding a directory also excludes all the files beneath it.
8296 @menu
8297 * controlling pattern-matching::
8298 @end menu
8300 @node controlling pattern-matching
8301 @unnumberedsubsec Controlling Pattern-Matching
8303 For the purposes of this section, we call @dfn{exclusion members} all
8304 member names obtained while processing @option{--exclude} and
8305 @option{--exclude-from} options, and @dfn{inclusion members} those
8306 member names that were given in the command line or read from the file
8307 specified with @option{--files-from} option.
8309 These two pairs of member lists are used in the following operations:
8310 @option{--diff}, @option{--extract}, @option{--list},
8311 @option{--update}.
8313 There are no inclusion members in create mode (@option{--create} and
8314 @option{--append}), since in this mode the names obtained from the
8315 command line refer to @emph{files}, not archive members.
8317 By default, inclusion members are compared with archive members
8318 literally @footnote{Notice that earlier @GNUTAR{} versions used
8319 globbing for inclusion members, which contradicted to UNIX98
8320 specification and was not documented. @xref{Changes}, for more
8321 information on this and other changes.} and exclusion members are
8322 treated as globbing patterns.  For example:
8324 @smallexample
8325 @group
8326 $ @kbd{tar tf foo.tar}
8329 a.txt
8330 [remarks]
8331 # @i{Member names are used verbatim:}
8332 $ @kbd{tar -xf foo.tar -v '[remarks]'}
8333 [remarks]
8334 # @i{Exclude member names are globbed:}
8335 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
8336 a.txt
8337 [remarks]
8338 @end group
8339 @end smallexample
8341 This behavior can be altered by using the following options:
8343 @table @option
8344 @opindex wildcards
8345 @item --wildcards
8346 Treat all member names as wildcards.
8348 @opindex no-wildcards
8349 @item --no-wildcards
8350 Treat all member names as literal strings.
8351 @end table
8353 Thus, to extract files whose names end in @samp{.c}, you can use:
8355 @smallexample
8356 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
8359 @end smallexample
8361 @noindent
8362 Notice quoting of the pattern to prevent the shell from interpreting
8365 The effect of @option{--wildcards} option is canceled by
8366 @option{--no-wildcards}.  This can be used to pass part of
8367 the command line arguments verbatim and other part as globbing
8368 patterns.  For example, the following invocation:
8370 @smallexample
8371 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
8372 @end smallexample
8374 @noindent
8375 instructs @command{tar} to extract from @file{foo.tar} all files whose
8376 names end in @samp{.txt} and the file named @file{[remarks]}.
8378 Normally, a pattern matches a name if an initial subsequence of the
8379 name's components matches the pattern, where @samp{*}, @samp{?}, and
8380 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
8381 and wildcards can match @samp{/}.
8383 Other than optionally stripping leading @samp{/} from names
8384 (@pxref{absolute}), patterns and names are used as-is.  For
8385 example, trailing @samp{/} is not trimmed from a user-specified name
8386 before deciding whether to exclude it.
8388 However, this matching procedure can be altered by the options listed
8389 below.  These options accumulate.  For example:
8391 @smallexample
8392 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
8393 @end smallexample
8395 @noindent
8396 ignores case when excluding @samp{makefile}, but not when excluding
8397 @samp{readme}.
8399 @table @option
8400 @anchor{anchored patterns}
8401 @opindex anchored
8402 @opindex no-anchored
8403 @item --anchored
8404 @itemx --no-anchored
8405 If anchored, a pattern must match an initial subsequence
8406 of the name's components.  Otherwise, the pattern can match any
8407 subsequence.  Default is @option{--no-anchored} for exclusion members
8408 and @option{--anchored} inclusion members.
8410 @anchor{case-insensitive matches}
8411 @opindex ignore-case
8412 @opindex no-ignore-case
8413 @item --ignore-case
8414 @itemx --no-ignore-case
8415 When ignoring case, upper-case patterns match lower-case names and vice versa.
8416 When not ignoring case (the default), matching is case-sensitive.
8418 @opindex wildcards-match-slash
8419 @opindex no-wildcards-match-slash
8420 @item --wildcards-match-slash
8421 @itemx --no-wildcards-match-slash
8422 When wildcards match slash (the default for exclusion members), a
8423 wildcard like @samp{*} in the pattern can match a @samp{/} in the
8424 name.  Otherwise, @samp{/} is matched only by @samp{/}.
8426 @end table
8428 The @option{--recursion} and @option{--no-recursion} options
8429 (@pxref{recurse}) also affect how member patterns are interpreted.  If
8430 recursion is in effect, a pattern matches a name if it matches any of
8431 the name's parent directories.
8433 The following table summarizes pattern-matching default values:
8435 @multitable @columnfractions .3 .7
8436 @headitem Members @tab Default settings
8437 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
8438 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
8439 @end multitable
8441 @node quoting styles
8442 @section Quoting Member Names
8444 When displaying member names, @command{tar} takes care to avoid
8445 ambiguities caused by certain characters.  This is called @dfn{name
8446 quoting}.  The characters in question are:
8448 @itemize @bullet
8449 @item Non-printable control characters:
8450 @anchor{escape sequences}
8451 @multitable @columnfractions 0.20 0.10 0.60
8452 @headitem Character @tab @acronym{ASCII} @tab Character name
8453 @item \a @tab 7  @tab Audible bell
8454 @item \b @tab 8  @tab Backspace
8455 @item \f @tab 12 @tab Form feed
8456 @item \n @tab 10 @tab New line
8457 @item \r @tab 13 @tab Carriage return
8458 @item \t @tab 9  @tab Horizontal tabulation
8459 @item \v @tab 11 @tab Vertical tabulation
8460 @end multitable
8462 @item Space (@acronym{ASCII} 32)
8464 @item Single and double quotes (@samp{'} and @samp{"})
8466 @item Backslash (@samp{\})
8467 @end itemize
8469 The exact way @command{tar} uses to quote these characters depends on
8470 the @dfn{quoting style}.  The default quoting style, called
8471 @dfn{escape} (see below), uses backslash notation to represent control
8472 characters and backslash.
8474 @GNUTAR{} offers seven distinct quoting styles, which can be selected
8475 using @option{--quoting-style} option:
8477 @table @option
8478 @item --quoting-style=@var{style}
8479 @opindex quoting-style
8481 Sets quoting style.  Valid values for @var{style} argument are:
8482 literal, shell, shell-always, c, escape, locale, clocale.
8483 @end table
8485 These styles are described in detail below.  To illustrate their
8486 effect, we will use an imaginary tar archive @file{arch.tar}
8487 containing the following members:
8489 @smallexample
8490 @group
8491 # 1. Contains horizontal tabulation character.
8492 a       tab
8493 # 2. Contains newline character
8495 newline
8496 # 3. Contains a space
8497 a space
8498 # 4. Contains double quotes
8499 a"double"quote
8500 # 5. Contains single quotes
8501 a'single'quote
8502 # 6. Contains a backslash character:
8503 a\backslash
8504 @end group
8505 @end smallexample
8507 Here is how usual @command{ls} command would have listed them, if they
8508 had existed in the current working directory:
8510 @smallexample
8511 @group
8512 $ @kbd{ls}
8513 a\ttab
8514 a\nnewline
8515 a\ space
8516 a"double"quote
8517 a'single'quote
8518 a\\backslash
8519 @end group
8520 @end smallexample
8522 Quoting styles:
8524 @table @samp
8525 @item literal
8526 No quoting, display each character as is:
8528 @smallexample
8529 @group
8530 $ @kbd{tar tf arch.tar --quoting-style=literal}
8532 ./a space
8533 ./a'single'quote
8534 ./a"double"quote
8535 ./a\backslash
8536 ./a     tab
8538 newline
8539 @end group
8540 @end smallexample
8542 @item shell
8543 Display characters the same way Bourne shell does:
8544 control characters, except @samp{\t} and @samp{\n}, are printed using
8545 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
8546 single quote is printed as @samp{\'}.  If a name contains any quoted
8547 characters, it is enclosed in single quotes.  In particular, if a name
8548 contains single quotes, it is printed as several single-quoted strings:
8550 @smallexample
8551 @group
8552 $ @kbd{tar tf arch.tar --quoting-style=shell}
8554 './a space'
8555 './a'\''single'\''quote'
8556 './a"double"quote'
8557 './a\backslash'
8558 './a    tab'
8559 './a
8560 newline'
8561 @end group
8562 @end smallexample
8564 @item shell-always
8565 Same as @samp{shell}, but the names are always enclosed in single
8566 quotes:
8568 @smallexample
8569 @group
8570 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
8571 './'
8572 './a space'
8573 './a'\''single'\''quote'
8574 './a"double"quote'
8575 './a\backslash'
8576 './a    tab'
8577 './a
8578 newline'
8579 @end group
8580 @end smallexample
8582 @item c
8583 Use the notation of the C programming language.  All names are
8584 enclosed in double quotes.  Control characters are quoted using
8585 backslash notations, double quotes are represented as @samp{\"},
8586 backslash characters are represented as @samp{\\}.  Single quotes and
8587 spaces are not quoted:
8589 @smallexample
8590 @group
8591 $ @kbd{tar tf arch.tar --quoting-style=c}
8592 "./"
8593 "./a space"
8594 "./a'single'quote"
8595 "./a\"double\"quote"
8596 "./a\\backslash"
8597 "./a\ttab"
8598 "./a\nnewline"
8599 @end group
8600 @end smallexample
8602 @item escape
8603 Control characters are printed using backslash notation, and a
8604 backslash as @samp{\\}.  This is the default quoting style, unless it
8605 was changed when configured the package.
8607 @smallexample
8608 @group
8609 $ @kbd{tar tf arch.tar --quoting-style=escape}
8611 ./a space
8612 ./a'single'quote
8613 ./a"double"quote
8614 ./a\\backslash
8615 ./a\ttab
8616 ./a\nnewline
8617 @end group
8618 @end smallexample
8620 @item locale
8621 Control characters, single quote and backslash are printed using
8622 backslash notation.  All names are quoted using left and right
8623 quotation marks, appropriate to the current locale.  If it does not
8624 define quotation marks, use @samp{'} as left and as right
8625 quotation marks.  Any occurrences of the right quotation mark in a
8626 name are escaped with @samp{\}, for example:
8628 For example:
8630 @smallexample
8631 @group
8632 $ @kbd{tar tf arch.tar --quoting-style=locale}
8633 './'
8634 './a space'
8635 './a\'single\'quote'
8636 './a"double"quote'
8637 './a\\backslash'
8638 './a\ttab'
8639 './a\nnewline'
8640 @end group
8641 @end smallexample
8643 @item clocale
8644 Same as @samp{locale}, but @samp{"} is used for both left and right
8645 quotation marks, if not provided by the currently selected locale:
8647 @smallexample
8648 @group
8649 $ @kbd{tar tf arch.tar --quoting-style=clocale}
8650 "./"
8651 "./a space"
8652 "./a'single'quote"
8653 "./a\"double\"quote"
8654 "./a\\backslash"
8655 "./a\ttab"
8656 "./a\nnewline"
8657 @end group
8658 @end smallexample
8659 @end table
8661 You can specify which characters should be quoted in addition to those
8662 implied by the current quoting style:
8664 @table @option
8665 @item --quote-chars=@var{string}
8666 Always quote characters from @var{string}, even if the selected
8667 quoting style would not quote them.
8668 @end table
8670 For example, using @samp{escape} quoting (compare with the usual
8671 escape listing above):
8673 @smallexample
8674 @group
8675 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
8677 ./a\ space
8678 ./a'single'quote
8679 ./a\"double\"quote
8680 ./a\\backslash
8681 ./a\ttab
8682 ./a\nnewline
8683 @end group
8684 @end smallexample
8686 To disable quoting of such additional characters, use the following
8687 option:
8689 @table @option
8690 @item --no-quote-chars=@var{string}
8691 Remove characters listed in @var{string} from the list of quoted
8692 characters set by the previous @option{--quote-chars} option.
8693 @end table
8695 This option is particularly useful if you have added
8696 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
8697 and wish to disable it for the current invocation.
8699 Note, that @option{--no-quote-chars} does @emph{not} disable those
8700 characters that are quoted by default in the selected quoting style.
8702 @node transform
8703 @section Modifying File and Member Names
8705 @command{Tar} archives contain detailed information about files stored
8706 in them and full file names are part of that information.  When
8707 storing a file to an archive, its file name is recorded in it,
8708 along with the actual file contents.  When restoring from an archive,
8709 a file is created on disk with exactly the same name as that stored
8710 in the archive.  In the majority of cases this is the desired behavior
8711 of a file archiver.  However, there are some cases when it is not.
8713 First of all, it is often unsafe to extract archive members with
8714 absolute file names or those that begin with a @file{../}.  @GNUTAR{}
8715 takes special precautions when extracting such names and provides a
8716 special option for handling them, which is described in
8717 @ref{absolute}.
8719 Secondly, you may wish to extract file names without some leading
8720 directory components, or with otherwise modified names.  In other
8721 cases it is desirable to store files under differing names in the
8722 archive.
8724 @GNUTAR{} provides several options for these needs.
8726 @table @option
8727 @opindex strip-components
8728 @item --strip-components=@var{number}
8729 Strip given @var{number} of leading components from file names before
8730 extraction.
8731 @end table
8733 For example, suppose you have archived whole @file{/usr} hierarchy to
8734 a tar archive named @file{usr.tar}.  Among other files, this archive
8735 contains @file{usr/include/stdlib.h}, which you wish to extract to
8736 the current working directory.  To do so, you type:
8738 @smallexample
8739 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8740 @end smallexample
8742 The option @option{--strip=2} instructs @command{tar} to strip the
8743 two leading components (@file{usr/} and @file{include/}) off the file
8744 name.
8746 If you add the @option{--verbose} (@option{-v}) option to the invocation
8747 above, you will note that the verbose listing still contains the
8748 full file name, with the two removed components still in place.  This
8749 can be inconvenient, so @command{tar} provides a special option for
8750 altering this behavior:
8752 @anchor{show-transformed-names}
8753 @table @option
8754 @opindex show-transformed-names
8755 @item --show-transformed-names
8756 Display file or member names with all requested transformations
8757 applied.
8758 @end table
8760 @noindent
8761 For example:
8763 @smallexample
8764 @group
8765 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8766 usr/include/stdlib.h
8767 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8768 stdlib.h
8769 @end group
8770 @end smallexample
8772 Notice that in both cases the file @file{stdlib.h} is extracted to the
8773 current working directory, @option{--show-transformed-names} affects
8774 only the way its name is displayed.
8776 This option is especially useful for verifying whether the invocation
8777 will have the desired effect.  Thus, before running
8779 @smallexample
8780 $ @kbd{tar -x --strip=@var{n}}
8781 @end smallexample
8783 @noindent
8784 it is often advisable to run
8786 @smallexample
8787 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8788 @end smallexample
8790 @noindent
8791 to make sure the command will produce the intended results.
8793 In case you need to apply more complex modifications to the file name,
8794 @GNUTAR{} provides a general-purpose transformation option:
8796 @table @option
8797 @opindex transform
8798 @opindex xform
8799 @item --transform=@var{expression}
8800 @itemx --xform=@var{expression}
8801 Modify file names using supplied @var{expression}.
8802 @end table
8804 @noindent
8805 The @var{expression} is a @command{sed}-like replace expression of the
8806 form:
8808 @smallexample
8809 s/@var{regexp}/@var{replace}/[@var{flags}]
8810 @end smallexample
8812 @noindent
8813 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8814 replacement for each file name part that matches @var{regexp}.  Both
8815 @var{regexp} and @var{replace} are described in detail in
8816 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8818 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8819 that it be used consistently throughout the expression. For example,
8820 the following two expressions are equivalent:
8822 @smallexample
8823 @group
8824 s/one/two/
8825 s,one,two,
8826 @end group
8827 @end smallexample
8829 Changing delimiters is often useful when the @var{regex} contains
8830 slashes.  For example, it is more convenient to write @code{s,/,-,} than
8831 @code{s/\//-/}.
8833 As in @command{sed}, you can give several replace expressions,
8834 separated by a semicolon.
8836 Supported @var{flags} are:
8838 @table @samp
8839 @item g
8840 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8841 just the first.
8843 @item i
8844 Use case-insensitive matching.
8846 @item x
8847 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8848 regexps, Extended regular expressions, Extended regular expressions,
8849 sed, GNU sed}).
8851 @item @var{number}
8852 Only replace the @var{number}th match of the @var{regexp}.
8854 Note: the @acronym{POSIX} standard does not specify what should happen
8855 when you mix the @samp{g} and @var{number} modifiers.  @GNUTAR{}
8856 follows the GNU @command{sed} implementation in this regard, so
8857 the interaction is defined to be: ignore matches before the
8858 @var{number}th, and then match and replace all matches from the
8859 @var{number}th on.
8861 @end table
8863 In addition, several @dfn{transformation scope} flags are supported,
8864 that control to what files transformations apply.  These are:
8866 @table @samp
8867 @item r
8868 Apply transformation to regular archive members.
8870 @item R
8871 Do not apply transformation to regular archive members.
8873 @item s
8874 Apply transformation to symbolic link targets.
8876 @item S
8877 Do not apply transformation to symbolic link targets.
8879 @item h
8880 Apply transformation to hard link targets.
8882 @item H
8883 Do not apply transformation to hard link targets.
8884 @end table
8886 Default is @samp{rsh}, which means to apply transformations to both archive
8887 members and targets of symbolic and hard links.
8889 Default scope flags can also be changed using @samp{flags=} statement
8890 in the transform expression.  The flags set this way remain in force
8891 until next @samp{flags=} statement or end of expression, whichever
8892 occurs first.  For example:
8894 @smallexample
8895   --transform 'flags=S;s|^|/usr/local/|'
8896 @end smallexample
8898 Here are several examples of @option{--transform} usage:
8900 @enumerate
8901 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8903 @smallexample
8904 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8905 @end smallexample
8907 @item Strip two leading directory components (equivalent to
8908 @option{--strip-components=2}):
8910 @smallexample
8911 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8912 @end smallexample
8914 @item Convert each file name to lower case:
8916 @smallexample
8917 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8918 @end smallexample
8920 @item Prepend @file{/prefix/}  to each file name:
8922 @smallexample
8923 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8924 @end smallexample
8926 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8927 to each archive member:
8929 @smallexample
8930 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8931 @end smallexample
8932 @end enumerate
8934 Notice the use of flags in the last example.  The @file{/lib}
8935 directory often contains many symbolic links to files within it.
8936 It may look, for example, like this:
8938 @smallexample
8939 $ @kbd{ls -l}
8940 drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
8941 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8942 lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8944 @end smallexample
8946 Using the expression @samp{s,^,/usr/local/,} would mean adding
8947 @samp{/usr/local} to both regular archive members and to link
8948 targets. In this case, @file{/lib/libc.so.6} would become:
8950 @smallexample
8951   /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8952 @end smallexample
8954 This is definitely not desired.  To avoid this, the @samp{S} flag
8955 is used, which excludes symbolic link targets from filename
8956 transformations.  The result is:
8958 @smallexample
8959 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -v -f arch.tar \
8960        --show-transformed /lib}
8961 drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
8962 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8963 lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8964  -> libc-2.3.2.so
8965 @end smallexample
8967 Unlike @option{--strip-components}, @option{--transform} can be used
8968 in any @GNUTAR{} operation mode.  For example, the following command
8969 adds files to the archive while replacing the leading @file{usr/}
8970 component with @file{var/}:
8972 @smallexample
8973 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8974 @end smallexample
8976 To test @option{--transform} effect we suggest using
8977 @option{--show-transformed-names} option:
8979 @smallexample
8980 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8981        --verbose --show-transformed-names /}
8982 @end smallexample
8984 If both @option{--strip-components} and @option{--transform} are used
8985 together, then @option{--transform} is applied first, and the required
8986 number of components is then stripped from its result.
8988 You can use as many @option{--transform} options in a single command
8989 line as you want.  The specified expressions will then be applied in
8990 order of their appearance.  For example, the following two invocations
8991 are equivalent:
8993 @smallexample
8994 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8995                         --transform='s,/usr/local,/usr/,'}
8996 $ @kbd{tar -cf arch.tar \
8997                --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8998 @end smallexample
9000 @node after
9001 @section Operating Only on New Files
9003 @cindex Excluding file by age
9004 @cindex Data Modification time, excluding files by
9005 @cindex Modification time, excluding files by
9006 @cindex Age, excluding files by
9007 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
9008 @option{-N @var{date}}) option causes @command{tar} to only work on
9009 files whose data modification or status change times are newer than
9010 the @var{date} given.  If @var{date} starts with @samp{/} or @samp{.},
9011 it is taken to be a file name; the data modification time of that file
9012 is used as the date. If you use this option when creating or appending
9013 to an archive, the archive will only include new files.  If you use
9014 @option{--after-date} when extracting an archive, @command{tar} will
9015 only extract files newer than the @var{date} you specify.
9017 If you only want @command{tar} to make the date comparison based on
9018 modification of the file's data (rather than status
9019 changes), then use the @option{--newer-mtime=@var{date}} option.
9021 @cindex --after-date and --update compared
9022 @cindex --newer-mtime and --update compared
9023 You may use these options with any operation.  Note that these options
9024 differ from the @option{--update} (@option{-u}) operation in that they
9025 allow you to specify a particular date against which @command{tar} can
9026 compare when deciding whether or not to archive the files.
9028 @table @option
9029 @opindex after-date
9030 @opindex newer
9031 @item --after-date=@var{date}
9032 @itemx --newer=@var{date}
9033 @itemx -N @var{date}
9034 Only store files newer than @var{date}.
9036 Acts on files only if their data modification or status change times are
9037 later than @var{date}.  Use in conjunction with any operation.
9039 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
9040 name; the data modification time of that file is used as the date.
9042 @opindex newer-mtime
9043 @item --newer-mtime=@var{date}
9044 Acts like @option{--after-date}, but only looks at data modification times.
9045 @end table
9047 These options limit @command{tar} to operate only on files which have
9048 been modified after the date specified.  A file's status is considered to have
9049 changed if its contents have been modified, or if its owner,
9050 permissions, and so forth, have been changed.  (For more information on
9051 how to specify a date, see @ref{Date input formats}; remember that the
9052 entire date argument must be quoted if it contains any spaces.)
9054 Gurus would say that @option{--after-date} tests both the data
9055 modification time (@code{mtime}, the time the contents of the file
9056 were last modified) and the status change time (@code{ctime}, the time
9057 the file's status was last changed: owner, permissions, etc.@:)
9058 fields, while @option{--newer-mtime} tests only the @code{mtime}
9059 field.
9061 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
9062 @code{ctime} and processes the file if either one is more recent than
9063 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
9064 disregards @code{ctime}.  Neither does it use @code{atime} (the last time the
9065 contents of the file were looked at).
9067 Date specifiers can have embedded spaces.  Because of this, you may need
9068 to quote date arguments to keep the shell from parsing them as separate
9069 arguments.  For example, the following command will add to the archive
9070 all the files modified less than two days ago:
9072 @smallexample
9073 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
9074 @end smallexample
9076 When any of these options is used with the option @option{--verbose}
9077 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
9078 date back to its textual representation and compare that with the
9079 one given with the option.  If the two dates differ, @command{tar} will
9080 print a warning saying what date it will use.  This is to help user
9081 ensure he is using the right date.  For example:
9083 @smallexample
9084 @group
9085 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
9086 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
9087 13:19:37.232434
9088 @end group
9089 @end smallexample
9091 @quotation
9092 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
9093 should not be used for incremental backups.  @xref{Incremental Dumps},
9094 for proper way of creating incremental backups.
9095 @end quotation
9097 @node recurse
9098 @section Descending into Directories
9099 @cindex Avoiding recursion in directories
9100 @cindex Descending directories, avoiding
9101 @cindex Directories, avoiding recursion
9102 @cindex Recursion in directories, avoiding
9104 Usually, @command{tar} will recursively explore all directories (either
9105 those given on the command line or through the @option{--files-from}
9106 option) for the various files they contain.  However, you may not always
9107 want @command{tar} to act this way.
9109 @opindex no-recursion
9110 @cindex @command{find}, using with @command{tar}
9111 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
9112 into specified directories.  If you specify @option{--no-recursion}, you can
9113 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
9114 utility for hunting through levels of directories to
9115 construct a list of file names which you could then pass to @command{tar}.
9116 @command{find} allows you to be more selective when choosing which files to
9117 archive; see @ref{files}, for more information on using @command{find} with
9118 @command{tar}.
9120 @table @option
9121 @item --no-recursion
9122 Prevents @command{tar} from recursively descending directories.
9124 @opindex recursion
9125 @item --recursion
9126 Requires @command{tar} to recursively descend directories.
9127 This is the default.
9128 @end table
9130 When you use @option{--no-recursion}, @GNUTAR{} grabs
9131 directory entries themselves, but does not descend on them
9132 recursively.  Many people use @command{find} for locating files they
9133 want to back up, and since @command{tar} @emph{usually} recursively
9134 descends on directories, they have to use the @samp{@w{-not -type d}}
9135 test in their @command{find} invocation (@pxref{Type, Type, Type test,
9136 find, Finding Files}), as they usually do not want all the files in a
9137 directory. They then use the @option{--files-from} option to archive
9138 the files located via @command{find}.
9140 The problem when restoring files archived in this manner is that the
9141 directories themselves are not in the archive; so the
9142 @option{--same-permissions} (@option{--preserve-permissions},
9143 @option{-p}) option does not affect them---while users might really
9144 like it to.  Specifying @option{--no-recursion} is a way to tell
9145 @command{tar} to grab only the directory entries given to it, adding
9146 no new files on its own.  To summarize, if you use @command{find} to
9147 create a list of files to be stored in an archive, use it as follows:
9149 @smallexample
9150 @group
9151 $ @kbd{find @var{dir} @var{tests} | \
9152   tar -cf @var{archive} --no-recursion -T -}
9153 @end group
9154 @end smallexample
9156 The @option{--no-recursion} option also applies when extracting: it
9157 causes @command{tar} to extract only the matched directory entries, not
9158 the files under those directories.
9160 The @option{--no-recursion} option also affects how globbing patterns
9161 are interpreted (@pxref{controlling pattern-matching}).
9163 The @option{--no-recursion} and @option{--recursion} options apply to
9164 later options and operands, and can be overridden by later occurrences
9165 of @option{--no-recursion} and @option{--recursion}.  For example:
9167 @smallexample
9168 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
9169 @end smallexample
9171 @noindent
9172 creates an archive with one entry for @file{grape}, and the recursive
9173 contents of @file{grape/concord}, but no entries under @file{grape}
9174 other than @file{grape/concord}.
9176 @node one
9177 @section Crossing File System Boundaries
9178 @cindex File system boundaries, not crossing
9180 @command{tar} will normally automatically cross file system boundaries in
9181 order to archive files which are part of a directory tree.  You can
9182 change this behavior by running @command{tar} and specifying
9183 @option{--one-file-system}.  This option only affects files that are
9184 archived because they are in a directory that is being archived;
9185 @command{tar} will still archive files explicitly named on the command line
9186 or through @option{--files-from}, regardless of where they reside.
9188 @table @option
9189 @opindex one-file-system
9190 @item --one-file-system
9191 Prevents @command{tar} from crossing file system boundaries when
9192 archiving.  Use in conjunction with any write operation.
9193 @end table
9195 The @option{--one-file-system} option causes @command{tar} to modify its
9196 normal behavior in archiving the contents of directories.  If a file in
9197 a directory is not on the same file system as the directory itself, then
9198 @command{tar} will not archive that file.  If the file is a directory
9199 itself, @command{tar} will not archive anything beneath it; in other words,
9200 @command{tar} will not cross mount points.
9202 This option is useful for making full or incremental archival backups of
9203 a file system.  If this option is used in conjunction with
9204 @option{--verbose} (@option{-v}), files that are excluded are
9205 mentioned by name on the standard error.
9207 @menu
9208 * directory::                   Changing Directory
9209 * absolute::                    Absolute File Names
9210 @end menu
9212 @node directory
9213 @subsection Changing the Working Directory
9215 @FIXME{need to read over this node now for continuity; i've switched
9216 things around some.}
9218 @cindex Changing directory mid-stream
9219 @cindex Directory, changing mid-stream
9220 @cindex Working directory, specifying
9221 To change the working directory in the middle of a list of file names,
9222 either on the command line or in a file specified using
9223 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
9224 This will change the working directory to the specified directory
9225 after that point in the list.
9227 @table @option
9228 @opindex directory
9229 @item --directory=@var{directory}
9230 @itemx -C @var{directory}
9231 Changes the working directory in the middle of a command line.
9232 @end table
9234 For example,
9236 @smallexample
9237 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
9238 @end smallexample
9240 @noindent
9241 will place the files @file{grape} and @file{prune} from the current
9242 directory into the archive @file{jams.tar}, followed by the file
9243 @file{cherry} from the directory @file{food}.  This option is especially
9244 useful when you have several widely separated files that you want to
9245 store in the same archive.
9247 Note that the file @file{cherry} is recorded in the archive under the
9248 precise name @file{cherry}, @emph{not} @file{food/cherry}.  Thus, the
9249 archive will contain three files that all appear to have come from the
9250 same directory; if the archive is extracted with plain @samp{tar
9251 --extract}, all three files will be written in the current directory.
9253 Contrast this with the command,
9255 @smallexample
9256 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
9257 @end smallexample
9259 @noindent
9260 which records the third file in the archive under the name
9261 @file{red/cherry} so that, if the archive is extracted using
9262 @samp{tar --extract}, the third file will be written in a subdirectory
9263 named @file{red}.
9265 You can use the @option{--directory} option to make the archive
9266 independent of the original name of the directory holding the files.
9267 The following command places the files @file{/etc/passwd},
9268 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
9269 @file{foo.tar}:
9271 @smallexample
9272 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
9273 @end smallexample
9275 @noindent
9276 However, the names of the archive members will be exactly what they were
9277 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
9278 They will not appear to be related by file name to the original
9279 directories where those files were located.
9281 Note that @option{--directory} options are interpreted consecutively.  If
9282 @option{--directory} specifies a relative file name, it is interpreted
9283 relative to the then current directory, which might not be the same as
9284 the original current working directory of @command{tar}, due to a previous
9285 @option{--directory} option.
9287 When using @option{--files-from} (@pxref{files}), you can put various
9288 @command{tar} options (including @option{-C}) in the file list.  Notice,
9289 however, that in this case the option and its argument may not be
9290 separated by whitespace.  If you use short option, its argument must
9291 either follow the option letter immediately, without any intervening
9292 whitespace, or occupy the next line.  Otherwise, if you use long
9293 option, separate its argument by an equal sign.
9295 For instance, the file list for the above example will be:
9297 @smallexample
9298 @group
9299 -C/etc
9300 passwd
9301 hosts
9302 --directory=/lib
9303 libc.a
9304 @end group
9305 @end smallexample
9307 @noindent
9308 To use it, you would invoke @command{tar} as follows:
9310 @smallexample
9311 $ @kbd{tar -c -f foo.tar --files-from list}
9312 @end smallexample
9314 The interpretation of options in file lists is disabled by
9315 @option{--verbatim-files-from} and @option{--null} options.
9317 @node absolute
9318 @subsection Absolute File Names
9319 @cindex absolute file names
9320 @cindex file names, absolute
9322 By default, @GNUTAR{} drops a leading @samp{/} on
9323 input or output, and complains about file names containing a @file{..}
9324 component.  There is an option that turns off this behavior:
9326 @table @option
9327 @opindex absolute-names
9328 @item --absolute-names
9329 @itemx -P
9330 Do not strip leading slashes from file names, and permit file names
9331 containing a @file{..} file name component.
9332 @end table
9334 When @command{tar} extracts archive members from an archive, it strips any
9335 leading slashes (@samp{/}) from the member name.  This causes absolute
9336 member names in the archive to be treated as relative file names.  This
9337 allows you to have such members extracted wherever you want, instead of
9338 being restricted to extracting the member in the exact directory named
9339 in the archive.  For example, if the archive member has the name
9340 @file{/etc/passwd}, @command{tar} will extract it as if the name were
9341 really @file{etc/passwd}.
9343 File names containing @file{..} can cause problems when extracting, so
9344 @command{tar} normally warns you about such files when creating an
9345 archive, and rejects attempts to extracts such files.
9347 Other @command{tar} programs do not do this.  As a result, if you
9348 create an archive whose member names start with a slash, they will be
9349 difficult for other people with a non-@GNUTAR{}
9350 program to use.  Therefore, @GNUTAR{} also strips
9351 leading slashes from member names when putting members into the
9352 archive.  For example, if you ask @command{tar} to add the file
9353 @file{/bin/ls} to an archive, it will do so, but the member name will
9354 be @file{bin/ls}@footnote{A side effect of this is that when
9355 @option{--create} is used with @option{--verbose} the resulting output
9356 is not, generally speaking, the same as the one you'd get running
9357 @kbd{tar --list} command.  This may be important if you use some
9358 scripts for comparing both outputs.  @xref{listing member and file names},
9359 for the information on how to handle this case.}.
9361 Symbolic links containing @file{..} or leading @samp{/} can also cause
9362 problems when extracting, so @command{tar} normally extracts them last;
9363 it may create empty files as placeholders during extraction.
9365 If you use the @option{--absolute-names} (@option{-P}) option,
9366 @command{tar} will do none of these transformations.
9368 To archive or extract files relative to the root directory, specify
9369 the @option{--absolute-names} (@option{-P}) option.
9371 Normally, @command{tar} acts on files relative to the working
9372 directory---ignoring superior directory names when archiving, and
9373 ignoring leading slashes when extracting.
9375 When you specify @option{--absolute-names} (@option{-P}),
9376 @command{tar} stores file names including all superior directory
9377 names, and preserves leading slashes.  If you only invoked
9378 @command{tar} from the root directory you would never need the
9379 @option{--absolute-names} option, but using this option
9380 may be more convenient than switching to root.
9382 @FIXME{Should be an example in the tutorial/wizardry section using this
9383 to transfer files between systems.}
9385 @table @option
9386 @item --absolute-names
9387 Preserves full file names (including superior directory names) when
9388 archiving and extracting files.
9390 @end table
9392 @command{tar} prints out a message about removing the @samp{/} from
9393 file names.  This message appears once per @GNUTAR{}
9394 invocation.  It represents something which ought to be told; ignoring
9395 what it means can cause very serious surprises, later.
9397 Some people, nevertheless, do not want to see this message.  Wanting to
9398 play really dangerously, one may of course redirect @command{tar} standard
9399 error to the sink.  For example, under @command{sh}:
9401 @smallexample
9402 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
9403 @end smallexample
9405 @noindent
9406 Another solution, both nicer and simpler, would be to change to
9407 the @file{/} directory first, and then avoid absolute notation.
9408 For example:
9410 @smallexample
9411 $ @kbd{tar -c -f archive.tar -C / home}
9412 @end smallexample
9414 @xref{Integrity}, for some of the security-related implications
9415 of using this option.
9417 @include parse-datetime.texi
9419 @node Formats
9420 @chapter Controlling the Archive Format
9422 @cindex Tar archive formats
9423 Due to historical reasons, there are several formats of tar archives.
9424 All of them are based on the same principles, but have some subtle
9425 differences that often make them incompatible with each other.
9427 GNU tar is able to create and handle archives in a variety of formats.
9428 The most frequently used formats are (in alphabetical order):
9430 @table @asis
9431 @item gnu
9432 Format used by @GNUTAR{} versions up to 1.13.25.  This format derived
9433 from an early @acronym{POSIX} standard, adding some improvements such as
9434 sparse file handling and incremental archives.  Unfortunately these
9435 features were implemented in a way incompatible with other archive
9436 formats.
9438 Archives in @samp{gnu} format are able to hold file names of unlimited
9439 length.
9441 @item oldgnu
9442 Format used by @GNUTAR{} of versions prior to 1.12.
9444 @item v7
9445 Archive format, compatible with the V7 implementation of tar.  This
9446 format imposes a number of limitations.  The most important of them
9447 are:
9449 @enumerate
9450 @item The maximum length of a file name is limited to 99 characters.
9451 @item The maximum length of a symbolic link is limited to 99 characters.
9452 @item It is impossible to store special files (block and character
9453 devices, fifos etc.)
9454 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
9455 octal)
9456 @item V7 archives do not contain symbolic ownership information (user
9457 and group name of the file owner).
9458 @end enumerate
9460 This format has traditionally been used by Automake when producing
9461 Makefiles.  This practice will change in the future, in the meantime,
9462 however this means that projects containing file names more than 99
9463 characters long will not be able to use @GNUTAR{} @value{VERSION} and
9464 Automake prior to 1.9.
9466 @item ustar
9467 Archive format defined by @acronym{POSIX.1-1988} specification.  It stores
9468 symbolic ownership information.  It is also able to store
9469 special files.  However, it imposes several restrictions as well:
9471 @enumerate
9472 @item The maximum length of a file name is limited to 256 characters,
9473 provided that the file name can be split at a directory separator in
9474 two parts, first of them being at most 155 bytes long.  So, in most
9475 cases the maximum file name length will be shorter than 256
9476 characters.
9477 @item The maximum length of a symbolic link name is limited to
9478 100 characters.
9479 @item Maximum size of a file the archive is able to accommodate
9480 is 8GB
9481 @item Maximum value of UID/GID is 2097151.
9482 @item Maximum number of bits in device major and minor numbers is 21.
9483 @end enumerate
9485 @item star
9486 Format used by J@"org Schilling @command{star}
9487 implementation.  @GNUTAR{} is able to read @samp{star} archives but
9488 currently does not produce them.
9490 @item posix
9491 Archive format defined by @acronym{POSIX.1-2001} specification.  This is the
9492 most flexible and feature-rich format.  It does not impose any
9493 restrictions on file sizes or file name lengths.  This format is quite
9494 recent, so not all tar implementations are able to handle it properly.
9495 However, this format is designed in such a way that any tar
9496 implementation able to read @samp{ustar} archives will be able to read
9497 most @samp{posix} archives as well, with the only exception that any
9498 additional information (such as long file names etc.)@: will in such
9499 case be extracted as plain text files along with the files it refers to.
9501 This archive format will be the default format for future versions
9502 of @GNUTAR{}.
9504 @end table
9506 The following table summarizes the limitations of each of these
9507 formats:
9509 @multitable @columnfractions .10 .20 .20 .20 .20
9510 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
9511 @item gnu    @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9512 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
9513 @item v7     @tab 2097151 @tab 8GB @tab 99 @tab n/a
9514 @item ustar  @tab 2097151 @tab 8GB @tab 256 @tab 21
9515 @item posix  @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
9516 @end multitable
9518 The default format for @GNUTAR{} is defined at compilation
9519 time.  You may check it by running @command{tar --help}, and examining
9520 the last lines of its output.  Usually, @GNUTAR{} is configured
9521 to create archives in @samp{gnu} format, however, future version will
9522 switch to @samp{posix}.
9524 @menu
9525 * Compression::                 Using Less Space through Compression
9526 * Attributes::                  Handling File Attributes
9527 * Portability::                 Making @command{tar} Archives More Portable
9528 * cpio::                        Comparison of @command{tar} and @command{cpio}
9529 @end menu
9531 @node Compression
9532 @section Using Less Space through Compression
9534 @menu
9535 * gzip::                        Creating and Reading Compressed Archives
9536 * sparse::                      Archiving Sparse Files
9537 @end menu
9539 @node gzip
9540 @subsection Creating and Reading Compressed Archives
9541 @cindex Compressed archives
9542 @cindex Storing archives in compressed format
9544 @cindex gzip
9545 @cindex bzip2
9546 @cindex lzip
9547 @cindex lzma
9548 @cindex lzop
9549 @cindex compress
9550 @cindex zstd
9551 @GNUTAR{} is able to create and read compressed archives.  It supports
9552 a wide variety of compression programs, namely: @command{gzip},
9553 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
9554 @command{zstd}, @command{xz} and traditional @command{compress}. The
9555 latter is supported mostly for backward compatibility, and we recommend
9556 against using it, because it is by far less effective than the other
9557 compression programs@footnote{It also had patent problems in the past.}.
9559 Creating a compressed archive is simple: you just specify a
9560 @dfn{compression option} along with the usual archive creation
9561 commands.  Available compression options are summarized in the
9562 table below:
9564 @multitable @columnfractions 0.4 0.2 0.4
9565 @headitem Long            @tab Short       @tab Archive format
9566 @item @option{--gzip}     @tab @option{-z} @tab @command{gzip}
9567 @item @option{--bzip2}    @tab @option{-j} @tab @command{bzip2}
9568 @item @option{--xz}       @tab @option{-J} @tab @command{xz}
9569 @item @option{--lzip}     @tab             @tab @command{lzip}
9570 @item @option{--lzma}     @tab             @tab @command{lzma}
9571 @item @option{--lzop}     @tab             @tab @command{lzop}
9572 @item @option{--zstd}     @tab             @tab @command{zstd}
9573 @item @option{--compress} @tab @option{-Z} @tab @command{compress}
9574 @end multitable
9576 For example:
9578 @smallexample
9579 $ @kbd{tar czf archive.tar.gz .}
9580 @end smallexample
9582 You can also let @GNUTAR{} select the compression program based on
9583 the suffix of the archive file name. This is done using
9584 @option{--auto-compress} (@option{-a}) command line option. For
9585 example, the following invocation will use @command{bzip2} for
9586 compression:
9588 @smallexample
9589 $ @kbd{tar caf archive.tar.bz2 .}
9590 @end smallexample
9592 @noindent
9593 whereas the following one will use @command{lzma}:
9595 @smallexample
9596 $ @kbd{tar caf archive.tar.lzma .}
9597 @end smallexample
9599 For a complete list of file name suffixes recognized by @GNUTAR{},
9600 see @ref{auto-compress}.
9602 Reading compressed archive is even simpler: you don't need to specify
9603 any additional options as @GNUTAR{} recognizes its format
9604 automatically.  Thus, the following commands will list and extract the
9605 archive created in previous example:
9607 @smallexample
9608 # List the compressed archive
9609 $ @kbd{tar tf archive.tar.gz}
9610 # Extract the compressed archive
9611 $ @kbd{tar xf archive.tar.gz}
9612 @end smallexample
9614 The format recognition algorithm is based on @dfn{signatures}, a
9615 special byte sequences in the beginning of file, that are specific for
9616 certain compression formats.  If this approach fails, @command{tar}
9617 falls back to using archive name suffix to determine its format
9618 (@pxref{auto-compress}, for a list of recognized suffixes).
9620 @anchor{alternative decompression programs}
9621 @cindex alternative decompression programs
9622 Some compression programs are able to handle different compression
9623 formats.  @GNUTAR{} uses this, if the principal decompressor for the
9624 given format is not available.  For example, if @command{compress} is
9625 not installed, @command{tar} will try to use @command{gzip}.  As of
9626 version @value{VERSION} the following alternatives are
9627 tried@footnote{To verbosely trace the decompressor selection, use the
9628 @option{--warning=decompress-program} option
9629 (@pxref{warnings,decompress-program}).}:
9631 @multitable @columnfractions 0.3 0.3 0.3
9632 @headitem Format @tab Main decompressor @tab Alternatives
9633 @item compress @tab compress @tab gzip
9634 @item lzma     @tab lzma     @tab xz
9635 @item bzip2    @tab bzip2    @tab lbzip2
9636 @end multitable
9638 The only case when you have to specify a decompression option while
9639 reading the archive is when reading from a pipe or from a tape drive
9640 that does not support random access.  However, in this case @GNUTAR{}
9641 will indicate which option you should use.  For example:
9643 @smallexample
9644 $ @kbd{cat archive.tar.gz | tar tf -}
9645 tar: Archive is compressed.  Use -z option
9646 tar: Error is not recoverable: exiting now
9647 @end smallexample
9649 If you see such diagnostics, just add the suggested option to the
9650 invocation of @GNUTAR{}:
9652 @smallexample
9653 $ @kbd{cat archive.tar.gz | tar tzf -}
9654 @end smallexample
9656 Notice also, that there are several restrictions on operations on
9657 compressed archives.  First of all, compressed archives cannot be
9658 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
9659 them or delete (@option{--delete}) members from them or
9660 add (@option{--append}, alias @option{-r}) members to them.  Likewise, you
9661 cannot append another @command{tar} archive to a compressed archive using
9662 @option{--concatenate} (@option{-A}).  Secondly, multi-volume
9663 archives cannot be compressed.
9665 The following options allow to select a particular compressor program:
9667 @table @option
9668 @opindex gzip
9669 @opindex ungzip
9670 @item -z
9671 @itemx --gzip
9672 @itemx --ungzip
9673 Filter the archive through @command{gzip}.
9675 @opindex xz
9676 @item -J
9677 @itemx --xz
9678 Filter the archive through @code{xz}.
9680 @item -j
9681 @itemx --bzip2
9682 Filter the archive through @code{bzip2}.
9684 @opindex lzip
9685 @item --lzip
9686 Filter the archive through @command{lzip}.
9688 @opindex lzma
9689 @item --lzma
9690 Filter the archive through @command{lzma}.
9692 @opindex lzop
9693 @item --lzop
9694 Filter the archive through @command{lzop}.
9696 @opindex zstd
9697 @item --zstd
9698 Filter the archive through @command{zstd}.
9700 @opindex compress
9701 @opindex uncompress
9702 @item -Z
9703 @itemx --compress
9704 @itemx --uncompress
9705 Filter the archive through @command{compress}.
9706 @end table
9708 When any of these options is given, @GNUTAR{} searches the compressor
9709 binary in the current path and invokes it.  The name of the compressor
9710 program is specified at compilation time using a corresponding
9711 @option{--with-@var{compname}} option to @command{configure}, e.g.
9712 @option{--with-bzip2} to select a specific @command{bzip2} binary.
9713 @xref{lbzip2}, for a detailed discussion.
9715 The output produced by @command{tar --help} shows the actual
9716 compressor names along with each of these options.
9718 You can use any of these options on physical devices (tape drives,
9719 etc.)@: and remote files as well as on normal files; data to or from
9720 such devices or remote files is reblocked by another copy of the
9721 @command{tar} program to enforce the specified (or default) record
9722 size.  The default compression parameters are used.
9723 You can override them by using the @option{-I} option (see
9724 below), e.g.:
9726 @smallexample
9727 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
9728 @end smallexample
9730 @noindent
9731 A more traditional way to do this is to use a pipe:
9733 @smallexample
9734 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9735 @end smallexample
9737 @cindex corrupted archives
9738 Compressed archives are easily corrupted, because compressed files
9739 have little redundancy.  The adaptive nature of the
9740 compression scheme means that the compression tables are implicitly
9741 spread all over the archive.  If you lose a few blocks, the dynamic
9742 construction of the compression tables becomes unsynchronized, and there
9743 is little chance that you could recover later in the archive.
9745 Other compression options provide better control over creating
9746 compressed archives.  These are:
9748 @table @option
9749 @anchor{auto-compress}
9750 @opindex auto-compress
9751 @item --auto-compress
9752 @itemx -a
9753 Select a compression program to use by the archive file name
9754 suffix.  The following suffixes are recognized:
9756 @multitable @columnfractions 0.3 0.6
9757 @headitem Suffix @tab Compression program
9758 @item @samp{.gz} @tab @command{gzip}
9759 @item @samp{.tgz} @tab @command{gzip}
9760 @item @samp{.taz} @tab @command{gzip}
9761 @item @samp{.Z} @tab @command{compress}
9762 @item @samp{.taZ} @tab @command{compress}
9763 @item @samp{.bz2} @tab @command{bzip2}
9764 @item @samp{.tz2} @tab @command{bzip2}
9765 @item @samp{.tbz2} @tab @command{bzip2}
9766 @item @samp{.tbz} @tab @command{bzip2}
9767 @item @samp{.lz} @tab @command{lzip}
9768 @item @samp{.lzma} @tab @command{lzma}
9769 @item @samp{.tlz} @tab @command{lzma}
9770 @item @samp{.lzo} @tab @command{lzop}
9771 @item @samp{.xz} @tab @command{xz}
9772 @item @samp{.zst} @tab @command{zstd}
9773 @item @samp{.tzst} @tab @command{zstd}
9774 @end multitable
9776 @anchor{use-compress-program}
9777 @opindex use-compress-program
9778 @item --use-compress-program=@var{command}
9779 @itemx -I=@var{command}
9780 Use external compression program @var{command}.  Use this option if you
9781 want to specify options for the compression program, or if you
9782 are not happy with the compression program associated with the suffix
9783 at compile time, or if you have a compression program that @GNUTAR{}
9784 does not support.  The @var{command} argument is a valid command
9785 invocation, as you would type it at the command line prompt, with any
9786 additional options as needed.  Enclose it in quotes if it contains
9787 white space (@pxref{external, Running External Commands}).
9789 The @var{command} should follow two conventions:
9791 First, when invoked without additional options, it should read data
9792 from standard input, compress it and output it on standard output.
9794 Secondly, if invoked with the additional @option{-d} option, it should
9795 do exactly the opposite, i.e., read the compressed data from the
9796 standard input and produce uncompressed data on the standard output.
9798 The latter requirement means that you must not use the @option{-d}
9799 option as a part of the @var{command} itself.
9800 @end table
9802 @cindex gpg, using with tar
9803 @cindex gnupg, using with tar
9804 @cindex Using encrypted archives
9805 The @option{--use-compress-program} option, in particular, lets you
9806 implement your own filters, not necessarily dealing with
9807 compression/decompression.  For example, suppose you wish to implement
9808 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9809 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9810 Manual}).  The following script does that:
9812 @smallexample
9813 @group
9814 #! /bin/sh
9815 case $1 in
9816 -d) gpg --decrypt - | gzip -d -c;;
9817 '') gzip -c | gpg -s;;
9818 *)  echo "Unknown option $1">&2; exit 1;;
9819 esac
9820 @end group
9821 @end smallexample
9823 Suppose you name it @file{gpgz} and save it somewhere in your
9824 @env{PATH}.  Then the following command will create a compressed
9825 archive signed with your private key:
9827 @smallexample
9828 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9829 @end smallexample
9831 @noindent
9832 Likewise, the command below will list its contents:
9834 @smallexample
9835 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9836 @end smallexample
9838 @ignore
9839 The above is based on the following discussion:
9841      I have one question, or maybe it's a suggestion if there isn't a way
9842      to do it now.  I would like to use @option{--gzip}, but I'd also like
9843      the output to be fed through a program like @acronym{GNU}
9844      @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9845      to use :-)), basically adding ECC protection on top of compression.
9846      It seems as if this should be quite easy to do, but I can't work out
9847      exactly how to go about it.  Of course, I can pipe the standard output
9848      of @command{tar} through @command{ecc}, but then I lose (though I
9849      haven't started using it yet, I confess) the ability to have
9850      @command{tar} use @command{rmt} for it's I/O (I think).
9852      I think the most straightforward thing would be to let me specify a
9853      general set of filters outboard of compression (preferably ordered,
9854      so the order can be automatically reversed on input operations, and
9855      with the options they require specifiable), but beggars shouldn't be
9856      choosers and anything you decide on would be fine with me.
9858      By the way, I like @command{ecc} but if (as the comments say) it can't
9859      deal with loss of block sync, I'm tempted to throw some time at adding
9860      that capability.  Supposing I were to actually do such a thing and
9861      get it (apparently) working, do you accept contributed changes to
9862      utilities like that?  (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9864   Isn't that exactly the role of the
9865   @option{--use-compress-prog=@var{program}} option?
9866   I never tried it myself, but I suspect you may want to write a
9867   @var{prog} script or program able to filter stdin to stdout to
9868   way you want.  It should recognize the @option{-d} option, for when
9869   extraction is needed rather than creation.
9871   It has been reported that if one writes compressed data (through the
9872   @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9873   the DLT compression mode, the data will actually get bigger and one will
9874   end up with less space on the tape.
9875 @end ignore
9877 @menu
9878 * lbzip2::  Using lbzip2 with @GNUTAR{}.
9879 @end menu
9881 @node lbzip2
9882 @subsubsection Using lbzip2 with @GNUTAR{}.
9883 @cindex lbzip2
9884 @cindex Laszlo Ersek
9885   @command{Lbzip2} is a multithreaded utility for handling
9886 @samp{bzip2} compression, written by Laszlo Ersek.  It makes use of
9887 multiple processors to speed up its operation and in general works
9888 considerably faster than @command{bzip2}.  For a detailed description
9889 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9890 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9891 lbzip2: parallel bzip2 utility}.
9893   Recent versions of @command{lbzip2} are mostly command line compatible
9894 with @command{bzip2}, which makes it possible to automatically invoke
9895 it via the @option{--bzip2} @GNUTAR{} command line option.  To do so,
9896 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9897 line option, like this:
9899 @smallexample
9900 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9901 @end smallexample
9903   Once configured and compiled this way, @command{tar --help} will show the
9904 following:
9906 @smallexample
9907 @group
9908 $ @kbd{tar --help | grep -- --bzip2}
9909   -j, --bzip2                filter the archive through lbzip2
9910 @end group
9911 @end smallexample
9913 @noindent
9914 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9916 @node sparse
9917 @subsection Archiving Sparse Files
9918 @cindex Sparse Files
9920 Files in the file system occasionally have @dfn{holes}.  A @dfn{hole}
9921 in a file is a section of the file's contents which was never written.
9922 The contents of a hole reads as all zeros.  On many operating systems,
9923 actual disk storage is not allocated for holes, but they are counted
9924 in the length of the file.  If you archive such a file, @command{tar}
9925 could create an archive longer than the original.  To have @command{tar}
9926 attempt to recognize the holes in a file, use @option{--sparse}
9927 (@option{-S}).  When you use this option, then, for any file using
9928 less disk space than would be expected from its length, @command{tar}
9929 searches the file for holes.  It then records in the archive for the file where
9930 the holes (consecutive stretches of zeros) are, and only archives the
9931 ``real contents'' of the file.  On extraction (using @option{--sparse} is not
9932 needed on extraction) any such files have also holes created wherever the holes
9933 were found.  Thus, if you use @option{--sparse}, @command{tar} archives won't
9934 take more space than the original.
9936 @GNUTAR{} uses two methods for detecting holes in sparse files.  These
9937 methods are described later in this subsection.
9939 @table @option
9940 @opindex sparse
9941 @item -S
9942 @itemx --sparse
9943 This option instructs @command{tar} to test each file for sparseness
9944 before attempting to archive it.  If the file is found to be sparse it
9945 is treated specially, thus allowing to decrease the amount of space
9946 used by its image in the archive.
9948 This option is meaningful only when creating or updating archives.  It
9949 has no effect on extraction.
9950 @end table
9952 Consider using @option{--sparse} when performing file system backups,
9953 to avoid archiving the expanded forms of files stored sparsely in the
9954 system.
9956 Even if your system has no sparse files currently, some may be
9957 created in the future.  If you use @option{--sparse} while making file
9958 system backups as a matter of course, you can be assured the archive
9959 will never take more space on the media than the files take on disk
9960 (otherwise, archiving a disk filled with sparse files might take
9961 hundreds of tapes).  @xref{Incremental Dumps}.
9963 However, be aware that @option{--sparse} option may present a serious
9964 drawback.  Namely, in order to determine the positions of holes in a file
9965 @command{tar} may have to read it before trying to archive it, so in total
9966 the file may be read @strong{twice}.  This may happen when your OS or your FS
9967 does not support @dfn{SEEK_HOLE/SEEK_DATA} feature in @dfn{lseek} (See
9968 @option{--hole-detection}, below).
9970 @cindex sparse formats, defined
9971 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9972 sparse files using in three distinct ways, called @dfn{sparse
9973 formats}.  A sparse format is identified by its @dfn{number},
9974 consisting, as usual of two decimal numbers, delimited by a dot.  By
9975 default, format @samp{1.0} is used.  If, for some reason, you wish to
9976 use an earlier format, you can select it using
9977 @option{--sparse-version} option.
9979 @table @option
9980 @opindex sparse-version
9981 @item --sparse-version=@var{version}
9982 Select the format to store sparse files in.  Valid @var{version} values
9983 are: @samp{0.0}, @samp{0.1} and @samp{1.0}.  @xref{Sparse Formats},
9984 for a detailed description of each format.
9985 @end table
9987 Using @option{--sparse-format} option implies @option{--sparse}.
9989 @table @option
9990 @opindex hole-detection
9991 @cindex hole detection
9992 @item --hole-detection=@var{method}
9993 Enforce concrete hole detection method.  Before the real contents of sparse
9994 file are stored, @command{tar} needs to gather knowledge about file
9995 sparseness.  This is because it needs to have the file's map of holes
9996 stored into tar header before it starts archiving the file contents.
9997 Currently, two methods of hole detection are implemented:
9999 @itemize @bullet
10000 @item @option{--hole-detection=seek}
10001 Seeking the file for data and holes.  It uses enhancement of the @code{lseek}
10002 system call (@code{SEEK_HOLE} and @code{SEEK_DATA}) which is able to
10003 reuse file system knowledge about sparse file contents - so the
10004 detection is usually very fast.  To use this feature, your file system
10005 and operating system must support it.  At the time of this writing
10006 (2015) this feature, in spite of not being accepted by POSIX, is
10007 fairly widely supported by different operating systems.
10009 @item @option{--hole-detection=raw}
10010 Reading byte-by-byte the whole sparse file before the archiving.  This
10011 method detects holes like consecutive stretches of zeroes.  Comparing to
10012 the previous method, it is usually much slower, although more
10013 portable.
10014 @end itemize
10015 @end table
10017 When no @option{--hole-detection} option is given, @command{tar} uses
10018 the @samp{seek}, if supported by the operating system.
10020 Using @option{--hole-detection} option implies @option{--sparse}.
10022 @node Attributes
10023 @section Handling File Attributes
10024 @cindex attributes, files
10025 @cindex file attributes
10027 When @command{tar} reads files, it updates their access times.  To
10028 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
10029 reset the access time retroactively or avoid changing it in the first
10030 place.
10032 @table @option
10033 @opindex atime-preserve
10034 @item --atime-preserve
10035 @itemx --atime-preserve=replace
10036 @itemx --atime-preserve=system
10037 Preserve the access times of files that are read.  This works only for
10038 files that you own, unless you have superuser privileges.
10040 @option{--atime-preserve=replace} works on most systems, but it also
10041 restores the data modification time and updates the status change
10042 time.  Hence it doesn't interact with incremental dumps nicely
10043 (@pxref{Incremental Dumps}), and it can set access or data modification times
10044 incorrectly if other programs access the file while @command{tar} is
10045 running.
10047 @option{--atime-preserve=system} avoids changing the access time in
10048 the first place, if the operating system supports this.
10049 Unfortunately, this may or may not work on any given operating system
10050 or file system.  If @command{tar} knows for sure it won't work, it
10051 complains right away.
10053 Currently @option{--atime-preserve} with no operand defaults to
10054 @option{--atime-preserve=replace}, but this is intended to change to
10055 @option{--atime-preserve=system} when the latter is better-supported.
10057 @opindex touch
10058 @item -m
10059 @itemx --touch
10060 Do not extract data modification time.
10062 When this option is used, @command{tar} leaves the data modification times
10063 of the files it extracts as the times when the files were extracted,
10064 instead of setting it to the times recorded in the archive.
10066 This option is meaningless with @option{--list} (@option{-t}).
10068 @opindex same-owner
10069 @item --same-owner
10070 Create extracted files with the same ownership they have in the
10071 archive.
10073 This is the default behavior for the superuser,
10074 so this option is meaningful only for non-root users, when @command{tar}
10075 is executed on those systems able to give files away.  This is
10076 considered as a security flaw by many people, at least because it
10077 makes quite difficult to correctly account users for the disk space
10078 they occupy.  Also, the @code{suid} or @code{sgid} attributes of
10079 files are easily and silently lost when files are given away.
10081 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
10082 separately.  If it can't find a user name (because the user @acronym{ID} is not
10083 in @file{/etc/passwd}), then it does not write one.  When restoring,
10084 it tries to look the name (if one was written) up in
10085 @file{/etc/passwd}.  If it fails, then it uses the user @acronym{ID} stored in
10086 the archive instead.
10088 @opindex no-same-owner
10089 @item --no-same-owner
10090 @itemx -o
10091 Do not attempt to restore ownership when extracting.  This is the
10092 default behavior for ordinary users, so this option has an effect
10093 only for the superuser.
10095 @opindex numeric-owner
10096 @item --numeric-owner
10097 The @option{--numeric-owner} option allows (ANSI) archives to be written
10098 without user/group name information or such information to be ignored
10099 when extracting.  It effectively disables the generation and/or use
10100 of user/group name information.  This option forces extraction using
10101 the numeric ids from the archive, ignoring the names.
10103 This is useful in certain circumstances, when restoring a backup from
10104 an emergency floppy with different passwd/group files for example.
10105 It is otherwise impossible to extract files with the right ownerships
10106 if the password file in use during the extraction does not match the
10107 one belonging to the file system(s) being extracted.  This occurs,
10108 for example, if you are restoring your files after a major crash and
10109 had booted from an emergency floppy with no password file or put your
10110 disk into another machine to do the restore.
10112 The numeric ids are @emph{always} saved into @command{tar} archives.
10113 The identifying names are added at create time when provided by the
10114 system, unless @option{--format=oldgnu} is used.  Numeric ids could be
10115 used when moving archives between a collection of machines using
10116 a centralized management for attribution of numeric ids to users
10117 and groups.  This is often made through using the NIS capabilities.
10119 When making a @command{tar} file for distribution to other sites, it
10120 is sometimes cleaner to use a single owner for all files in the
10121 distribution, and nicer to specify the write permission bits of the
10122 files as stored in the archive independently of their actual value on
10123 the file system.  The way to prepare a clean distribution is usually
10124 to have some Makefile rule creating a directory, copying all needed
10125 files in that directory, then setting ownership and permissions as
10126 wanted (there are a lot of possible schemes), and only then making a
10127 @command{tar} archive out of this directory, before cleaning
10128 everything out.  Of course, we could add a lot of options to
10129 @GNUTAR{} for fine tuning permissions and ownership.
10130 This is not the good way, I think.  @GNUTAR{} is
10131 already crowded with options and moreover, the approach just explained
10132 gives you a great deal of control already.
10134 @xopindex{same-permissions, short description}
10135 @xopindex{preserve-permissions, short description}
10136 @item -p
10137 @itemx --same-permissions
10138 @itemx --preserve-permissions
10139 Extract all protection information.
10141 This option causes @command{tar} to set the modes (access permissions) of
10142 extracted files exactly as recorded in the archive.  If this option
10143 is not used, the current @code{umask} setting limits the permissions
10144 on extracted files.  This option is by default enabled when
10145 @command{tar} is executed by a superuser.
10148 This option is meaningless with @option{--list} (@option{-t}).
10149 @end table
10151 @node Portability
10152 @section Making @command{tar} Archives More Portable
10154 Creating a @command{tar} archive on a particular system that is meant to be
10155 useful later on many other machines and with other versions of @command{tar}
10156 is more challenging than you might think.  @command{tar} archive formats
10157 have been evolving since the first versions of Unix.  Many such formats
10158 are around, and are not always compatible with each other.  This section
10159 discusses a few problems, and gives some advice about making @command{tar}
10160 archives more portable.
10162 One golden rule is simplicity.  For example, limit your @command{tar}
10163 archives to contain only regular files and directories, avoiding
10164 other kind of special files.  Do not attempt to save sparse files or
10165 contiguous files as such.  Let's discuss a few more problems, in turn.
10167 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
10168 archives and archive labels) in GNU and PAX formats.}
10170 @menu
10171 * Portable Names::              Portable Names
10172 * dereference::                 Symbolic Links
10173 * hard links::                  Hard Links
10174 * old::                         Old V7 Archives
10175 * ustar::                       Ustar Archives
10176 * gnu::                         GNU and old GNU format archives.
10177 * posix::                       @acronym{POSIX} archives
10178 * Checksumming::                Checksumming Problems
10179 * Large or Negative Values::    Large files, negative time stamps, etc.
10180 * Other Tars::                  How to Extract GNU-Specific Data Using
10181                                 Other @command{tar} Implementations
10182 @end menu
10184 @node Portable Names
10185 @subsection Portable Names
10187 Use portable file and member names.  A name is portable if it contains
10188 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
10189 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
10190 contain @samp{/-}.  Avoid deep directory nesting.  For portability to
10191 old Unix hosts, limit your file name components to 14 characters or
10192 less.
10194 If you intend to have your @command{tar} archives to be read under
10195 MSDOS, you should not rely on case distinction for file names, and you
10196 might use the @acronym{GNU} @command{doschk} program for helping you
10197 further diagnosing illegal MSDOS names, which are even more limited
10198 than System V's.
10200 @node dereference
10201 @subsection Symbolic Links
10202 @cindex File names, using symbolic links
10203 @cindex Symbolic link as file name
10205 @opindex dereference
10206 Normally, when @command{tar} archives a symbolic link, it writes a
10207 block to the archive naming the target of the link.  In that way, the
10208 @command{tar} archive is a faithful record of the file system contents.
10209 When @option{--dereference} (@option{-h}) is used with
10210 @option{--create} (@option{-c}), @command{tar} archives the files
10211 symbolic links point to, instead of
10212 the links themselves.
10214 When creating portable archives, use @option{--dereference}
10215 (@option{-h}): some systems do not support
10216 symbolic links, and moreover, your distribution might be unusable if
10217 it contains unresolved symbolic links.
10219 When reading from an archive, the @option{--dereference} (@option{-h})
10220 option causes @command{tar} to follow an already-existing symbolic
10221 link when @command{tar} writes or reads a file named in the archive.
10222 Ordinarily, @command{tar} does not follow such a link, though it may
10223 remove the link before writing a new file.  @xref{Dealing with Old
10224 Files}.
10226 The @option{--dereference} option is unsafe if an untrusted user can
10227 modify directories while @command{tar} is running.  @xref{Security}.
10229 @node hard links
10230 @subsection Hard Links
10231 @cindex File names, using hard links
10232 @cindex hard links, dereferencing
10233 @cindex dereferencing hard links
10235 Normally, when @command{tar} archives a hard link, it writes a
10236 block to the archive naming the target of the link (a @samp{1} type
10237 block).  In that way, the actual file contents is stored in file only
10238 once.  For example, consider the following two files:
10240 @smallexample
10241 @group
10242 $ ls -l
10243 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
10244 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
10245 @end group
10246 @end smallexample
10248 Here, @file{jeden} is a link to @file{one}.  When archiving this
10249 directory with a verbose level 2, you will get an output similar to
10250 the following:
10252 @smallexample
10253 $ tar cvvf ../archive.tar .
10254 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10255 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10256 hrw-r--r-- gray/staff        0 2007-10-30 15:11 ./one link to ./jeden
10257 @end smallexample
10259 The last line shows that, instead of storing two copies of the file,
10260 @command{tar} stored it only once, under the name @file{jeden}, and
10261 stored file @file{one} as a hard link to this file.
10263 It may be important to know that all hard links to the given file are
10264 stored in the archive.  For example, this may be necessary for exact
10265 reproduction of the file system.  The following option does that:
10267 @table @option
10268 @xopindex{check-links, described}
10269 @item --check-links
10270 @itemx -l
10271 Check the number of links dumped for each processed file.  If this
10272 number does not match the total number of hard links for the file, print
10273 a warning message.
10274 @end table
10276 For example, trying to archive only file @file{jeden} with this option
10277 produces the following diagnostics:
10279 @smallexample
10280 $ tar -c -f ../archive.tar -l jeden
10281 tar: Missing links to 'jeden'.
10282 @end smallexample
10284 Although creating special records for hard links helps keep a faithful
10285 record of the file system contents and makes archives more compact, it
10286 may present some difficulties when extracting individual members from
10287 the archive.  For example, trying to extract file @file{one} from the
10288 archive created in previous examples produces, in the absence of file
10289 @file{jeden}:
10291 @smallexample
10292 $ tar xf archive.tar ./one
10293 tar: ./one: Cannot hard link to './jeden': No such file or directory
10294 tar: Error exit delayed from previous errors
10295 @end smallexample
10297 The reason for this behavior is that @command{tar} cannot seek back in
10298 the archive to the previous member (in this case, @file{one}), to
10299 extract it@footnote{There are plans to fix this in future releases.}.
10300 If you wish to avoid such problems at the cost of a bigger archive,
10301 use the following option:
10303 @table @option
10304 @xopindex{hard-dereference, described}
10305 @item --hard-dereference
10306 Dereference hard links and store the files they refer to.
10307 @end table
10309 For example, trying this option on our two sample files, we get two
10310 copies in the archive, each of which can then be extracted
10311 independently of the other:
10313 @smallexample
10314 @group
10315 $ tar -c -vv -f ../archive.tar --hard-dereference .
10316 drwxr-xr-x gray/staff        0 2007-10-30 15:13 ./
10317 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./jeden
10318 -rw-r--r-- gray/staff        4 2007-10-30 15:11 ./one
10319 @end group
10320 @end smallexample
10322 @node old
10323 @subsection Old V7 Archives
10324 @cindex Format, old style
10325 @cindex Old style format
10326 @cindex Old style archives
10327 @cindex v7 archive format
10329 Certain old versions of @command{tar} cannot handle additional
10330 information recorded by newer @command{tar} programs.  To create an
10331 archive in V7 format (not ANSI), which can be read by these old
10332 versions, specify the @option{--format=v7} option in
10333 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
10334 accepts @option{--portability} or @option{--old-archive} for this
10335 option).  When you specify it,
10336 @command{tar} leaves out information about directories, pipes, fifos,
10337 contiguous files, and device files, and specifies file ownership by
10338 group and user IDs instead of group and user names.
10340 When updating an archive, do not use @option{--format=v7}
10341 unless the archive was created using this option.
10343 In most cases, a @emph{new} format archive can be read by an @emph{old}
10344 @command{tar} program without serious trouble, so this option should
10345 seldom be needed.  On the other hand, most modern @command{tar}s are
10346 able to read old format archives, so it might be safer for you to
10347 always use @option{--format=v7} for your distributions.  Notice,
10348 however, that @samp{ustar} format is a better alternative, as it is
10349 free from many of @samp{v7}'s drawbacks.
10351 @node ustar
10352 @subsection Ustar Archive Format
10354 @cindex ustar archive format
10355 The archive format defined by the @acronym{POSIX}.1-1988 specification is
10356 called @code{ustar}.  Although it is more flexible than the V7 format, it
10357 still has many restrictions (@pxref{Formats,ustar}, for the detailed
10358 description of @code{ustar} format).  Along with V7 format,
10359 @code{ustar} format is a good choice for archives intended to be read
10360 with other implementations of @command{tar}.
10362 To create an archive in @code{ustar} format, use the @option{--format=ustar}
10363 option in conjunction with @option{--create} (@option{-c}).
10365 @node gnu
10366 @subsection @acronym{GNU} and old @GNUTAR{} format
10368 @cindex GNU archive format
10369 @cindex Old GNU archive format
10370 @GNUTAR{} was based on an early draft of the
10371 @acronym{POSIX} 1003.1 @code{ustar} standard.  @acronym{GNU} extensions to
10372 @command{tar}, such as the support for file names longer than 100
10373 characters, use portions of the @command{tar} header record which were
10374 specified in that @acronym{POSIX} draft as unused.  Subsequent changes in
10375 @acronym{POSIX} have allocated the same parts of the header record for
10376 other purposes.  As a result, @GNUTAR{} format is
10377 incompatible with the current @acronym{POSIX} specification, and with
10378 @command{tar} programs that follow it.
10380 In the majority of cases, @command{tar} will be configured to create
10381 this format by default.  This will change in future releases, since
10382 we plan to make @samp{POSIX} format the default.
10384 To force creation a @GNUTAR{} archive, use option
10385 @option{--format=gnu}.
10387 @node posix
10388 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
10390 @cindex POSIX archive format
10391 @cindex PAX archive format
10392 Starting from version 1.14 @GNUTAR{} features full support for
10393 @acronym{POSIX.1-2001} archives.
10395 A @acronym{POSIX} conformant archive will be created if @command{tar}
10396 was given @option{--format=posix} (@option{--format=pax}) option.  No
10397 special option is required to read and extract from a @acronym{POSIX}
10398 archive.
10400 @menu
10401 * PAX keywords:: Controlling Extended Header Keywords.
10402 @end menu
10404 @node PAX keywords
10405 @subsubsection Controlling Extended Header Keywords
10407 @table @option
10408 @opindex pax-option
10409 @item --pax-option=@var{keyword-list}
10410 Handle keywords in @acronym{PAX} extended headers.  This option is
10411 equivalent to @option{-o} option of the @command{pax} utility.
10412 @end table
10414 @var{Keyword-list} is a comma-separated
10415 list of keyword options, each keyword option taking one of
10416 the following forms:
10418 @table @code
10419 @item delete=@var{pattern}
10420 When used with one of archive-creation commands,
10421 this option instructs @command{tar} to omit from extended header records
10422 that it produces any keywords matching the string @var{pattern}.
10424 When used in extract or list mode, this option instructs tar
10425 to ignore any keywords matching the given @var{pattern} in the extended
10426 header records.  In both cases, matching is performed using the pattern
10427 matching notation described in @acronym{POSIX 1003.2}, 3.13
10428 (@pxref{wildcards}).  For example:
10430 @smallexample
10431 --pax-option delete=security.*
10432 @end smallexample
10434 would suppress security-related information.
10436 @item exthdr.name=@var{string}
10438 This keyword allows user control over the name that is written into the
10439 ustar header blocks for the extended headers.  The name is obtained
10440 from @var{string} after making the following substitutions:
10442 @multitable @columnfractions .25 .55
10443 @headitem Meta-character @tab Replaced By
10444 @item %d @tab  The directory name of the file, equivalent to the
10445 result of the @command{dirname} utility on the translated file name.
10446 @item %f @tab  The name of the file with the directory information
10447 stripped, equivalent to the result of the @command{basename} utility
10448 on the translated file name.
10449 @item %p @tab  The process @acronym{ID} of the @command{tar} process.
10450 @item %% @tab  A @samp{%} character.
10451 @end multitable
10453 Any other @samp{%} characters in @var{string} produce undefined
10454 results.
10456 If no option @samp{exthdr.name=string} is specified, @command{tar}
10457 will use the following default value:
10459 @smallexample
10460 %d/PaxHeaders/%f
10461 @end smallexample
10463 This default is selected to ensure the reproducibility of the
10464 archive. @acronym{POSIX} standard recommends to use
10465 @samp{%d/PaxHeaders.%p/%f} instead, which means the two archives
10466 created with the same set of options and containing the same set
10467 of files will be byte-to-byte different. This default will be used
10468 if the environment variable @env{POSIXLY_CORRECT} is set.
10470 @item exthdr.mtime=@var{value}
10472 This keyword defines the value of the @samp{mtime} field that
10473 is written into the ustar header blocks for the extended headers.
10474 By default, the @samp{mtime} field is set to the modification time
10475 of the archive member described by that extended header (or to the
10476 value of the @option{--mtime} option, if supplied).
10478 @item globexthdr.name=@var{string}
10479 This keyword allows user control over the name that is written into
10480 the ustar header blocks for global extended header records.  The name
10481 is obtained from the contents of @var{string}, after making
10482 the following substitutions:
10484 @multitable @columnfractions .25 .55
10485 @headitem Meta-character @tab Replaced By
10486 @item %n @tab An integer that represents the
10487 sequence number of the global extended header record in the archive,
10488 starting at 1.
10489 @item %p @tab The process @acronym{ID} of the @command{tar} process.
10490 @item %% @tab A @samp{%} character.
10491 @end multitable
10493 Any other @samp{%} characters in @var{string} produce undefined results.
10495 If no option @samp{globexthdr.name=string} is specified, @command{tar}
10496 will use the following default value:
10498 @smallexample
10499 $TMPDIR/GlobalHead.%n
10500 @end smallexample
10502 If the environment variable @env{POSIXLY_CORRECT} is set, the
10503 following value is used instead:
10505 @smallexample
10506 $TMPDIR/GlobalHead.%p.%n
10507 @end smallexample
10509 In both cases, @samp{$TMPDIR} stands for the value of the @var{TMPDIR}
10510 environment variable.  If @var{TMPDIR} is not set, @command{tar}
10511 uses @samp{/tmp}.
10513 @item globexthdr.mtime=@var{value}
10515 This keyword defines the value of the @samp{mtime} field that
10516 is written into the ustar header blocks for the global extended headers.
10517 By default, the @samp{mtime} field is set to the time when
10518 @command{tar} was invoked.
10520 @item @var{keyword}=@var{value}
10521 When used with one of archive-creation commands, these keyword/value pairs
10522 will be included at the beginning of the archive in a global extended
10523 header record.  When used with one of archive-reading commands,
10524 @command{tar} will behave as if it has encountered these keyword/value
10525 pairs at the beginning of the archive in a global extended header
10526 record.
10528 @item @var{keyword}:=@var{value}
10529 When used with one of archive-creation commands, these keyword/value pairs
10530 will be included as records at the beginning of an extended header for
10531 each file.  This is effectively equivalent to @var{keyword}=@var{value}
10532 form except that it creates no global extended header records.
10534 When used with one of archive-reading commands, @command{tar} will
10535 behave as if these keyword/value pairs were included as records at the
10536 end of each extended header; thus, they will override any global or
10537 file-specific extended header record keywords of the same names.
10538 For example, in the command:
10540 @smallexample
10541 tar --format=posix --create \
10542     --file archive --pax-option gname:=user .
10543 @end smallexample
10545 the group name will be forced to a new value for all files
10546 stored in the archive.
10547 @end table
10549 In any of the forms described above, the @var{value} may be
10550 a string enclosed in curly braces.  In that case, the string
10551 between the braces is understood either as a textual time
10552 representation, as described in @ref{Date input formats}, or a name of
10553 the existing file, starting with @samp{/} or @samp{.}.  In the latter
10554 case, the modification time of that file is used.
10556 For example, to set all modification times to the current date, you
10557 use the following option:
10559 @smallexample
10560 --pax-option='mtime:=@{now@}'
10561 @end smallexample
10563 Note quoting of the option's argument.
10565 @cindex archives, binary equivalent
10566 @cindex binary equivalent archives, creating
10567 As another example, here is the option that ensures that any two
10568 archives created using it, will be binary equivalent if they have the
10569 same contents:
10571 @smallexample
10572 --pax-option=atime:=0
10573 @end smallexample
10575 @noindent
10576 If you extract files from such an archive and recreate the archive
10577 from them, you will also need to eliminate changes due to ctime, as
10578 shown in examples below:
10580 @smallexample
10581 --pax-option=atime:=0,ctime:=0
10582 @end smallexample
10584 @noindent
10587 @smallexample
10588 --pax-option=atime:=0,delete=ctime
10589 @end smallexample
10591 Notice, that if you create an archive in POSIX format (@pxref{posix})
10592 and the environment variable @env{POSIXLY_CORRECT} is set, then the
10593 two archives created using the same options on the same set of files
10594 will not be byte-to-byte equivalent even with the above option.  This
10595 is because the posix default for extended header names includes the
10596 PID of the tar process, which is different at each run. To produce
10597 byte-to-byte equivalent archives in this case, either unset
10598 @env{POSIXLY_CORRECT}, or use the following option:
10600 @smallexample
10601 ---pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0,ctime:=0
10602 @end smallexample
10604 @node Checksumming
10605 @subsection Checksumming Problems
10607 SunOS and HP-UX @command{tar} fail to accept archives created using
10608 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
10609 is, file names having characters with the eighth bit set, because they
10610 use signed checksums, while @GNUTAR{} uses unsigned
10611 checksums while creating archives, as per @acronym{POSIX} standards.  On
10612 reading, @GNUTAR{} computes both checksums and accepts either of them.
10613 It is somewhat worrying that a lot of people may go
10614 around doing backup of their files using faulty (or at least
10615 non-standard) software, not learning about it until it's time to
10616 restore their missing files with an incompatible file extractor, or
10617 vice versa.
10619 @GNUTAR{} computes checksums both ways, and accepts either of them
10620 on read, so @acronym{GNU} tar can read Sun tapes even with their
10621 wrong checksums.  @GNUTAR{} produces the standard
10622 checksum, however, raising incompatibilities with Sun.  That is to
10623 say, @GNUTAR{} has not been modified to
10624 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
10625 I've been told that more recent Sun @command{tar} now read standard
10626 archives, so maybe Sun did a similar patch, after all?
10628 The story seems to be that when Sun first imported @command{tar}
10629 sources on their system, they recompiled it without realizing that
10630 the checksums were computed differently, because of a change in
10631 the default signing of @code{char}'s in their compiler.  So they
10632 started computing checksums wrongly.  When they later realized their
10633 mistake, they merely decided to stay compatible with it, and with
10634 themselves afterwards.  Presumably, but I do not really know, HP-UX
10635 has chosen their @command{tar} archives to be compatible with Sun's.
10636 The current standards do not favor Sun @command{tar} format.  In any
10637 case, it now falls on the shoulders of SunOS and HP-UX users to get
10638 a @command{tar} able to read the good archives they receive.
10640 @node Large or Negative Values
10641 @subsection Large or Negative Values
10642 @cindex large values
10643 @cindex future time stamps
10644 @cindex negative time stamps
10645 @UNREVISED
10647 The above sections suggest to use @samp{oldest possible} archive
10648 format if in doubt.  However, sometimes it is not possible.  If you
10649 attempt to archive a file whose metadata cannot be represented using
10650 required format, @GNUTAR{} will print error message and ignore such a
10651 file.  You will than have to switch to a format that is able to
10652 handle such values.  The format summary table (@pxref{Formats}) will
10653 help you to do so.
10655 In particular, when trying to archive files larger than 8GB or with
10656 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
10657 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
10658 @acronym{POSIX} archive formats.  When considering which format to
10659 choose, bear in mind that the @acronym{GNU} format uses
10660 two's-complement base-256 notation to store values that do not fit
10661 into standard @acronym{ustar} range.  Such archives can generally be
10662 read only by a @GNUTAR{} implementation.  Moreover, they sometimes
10663 cannot be correctly restored on another hosts even by @GNUTAR{}.  For
10664 example, using two's complement representation for negative time
10665 stamps that assumes a signed 32-bit @code{time_t} generates archives
10666 that are not portable to hosts with differing @code{time_t}
10667 representations.
10669 On the other hand, @acronym{POSIX} archives, generally speaking, can
10670 be extracted by any tar implementation that understands older
10671 @acronym{ustar} format.  The only exception are files larger than 8GB.
10673 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
10674 POSIX-aware tars.}
10676 @node Other Tars
10677 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
10679 In previous sections you became acquainted with various quirks
10680 necessary to make your archives portable.  Sometimes you may need to
10681 extract archives containing GNU-specific members using some
10682 third-party @command{tar} implementation or an older version of
10683 @GNUTAR{}.  Of course your best bet is to have @GNUTAR{} installed,
10684 but if it is for some reason impossible, this section will explain
10685 how to cope without it.
10687 When we speak about @dfn{GNU-specific} members we mean two classes of
10688 them: members split between the volumes of a multi-volume archive and
10689 sparse members.  You will be able to always recover such members if
10690 the archive is in PAX format.  In addition split members can be
10691 recovered from archives in old GNU format.  The following subsections
10692 describe the required procedures in detail.
10694 @menu
10695 * Split Recovery::       Members Split Between Volumes
10696 * Sparse Recovery::      Sparse Members
10697 @end menu
10699 @node Split Recovery
10700 @subsubsection Extracting Members Split Between Volumes
10702 @cindex Multi-volume archives, extracting using non-GNU tars
10703 If a member is split between several volumes of an old GNU format archive
10704 most third party @command{tar} implementation will fail to extract
10705 it.  To extract it, use @command{tarcat} program (@pxref{Tarcat}).
10706 This program is available from
10707 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
10708 home page}.  It concatenates several archive volumes into a single
10709 valid archive.  For example, if you have three volumes named from
10710 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
10711 extract them using a third-party @command{tar}:
10713 @smallexample
10714 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
10715 @end smallexample
10717 @cindex Multi-volume archives in PAX format, extracting using non-GNU tars
10718 You could use this approach for most (although not all) PAX
10719 format archives as well.  However, extracting split members from a PAX
10720 archive is a much easier task, because PAX volumes are constructed in
10721 such a way that each part of a split member is extracted to a
10722 different file by @command{tar} implementations that are not aware of
10723 GNU extensions.  More specifically, the very first part retains its
10724 original name, and all subsequent parts are named using the pattern:
10726 @smallexample
10727 %d/GNUFileParts/%f.%n
10728 @end smallexample
10730 @noindent
10731 where symbols preceded by @samp{%} are @dfn{macro characters} that
10732 have the following meaning:
10734 @multitable @columnfractions .25 .55
10735 @headitem Meta-character @tab Replaced By
10736 @item %d @tab  The directory name of the file, equivalent to the
10737 result of the @command{dirname} utility on its full name.
10738 @item %f @tab  The file name of the file, equivalent to the result
10739 of the @command{basename} utility on its full name.
10740 @item %p @tab  The process @acronym{ID} of the @command{tar} process that
10741 created the archive.
10742 @item %n @tab  Ordinal number of this particular part.
10743 @end multitable
10745 For example, if the file @file{var/longfile} was split during archive
10746 creation between three volumes, then the member names will be:
10748 @smallexample
10749 var/longfile
10750 var/GNUFileParts/longfile.1
10751 var/GNUFileParts/longfile.2
10752 @end smallexample
10754 When you extract your archive using a third-party @command{tar}, these
10755 files will be created on your disk, and the only thing you will need
10756 to do to restore your file in its original form is concatenate them in
10757 the proper order, for example:
10759 @smallexample
10760 @group
10761 $ @kbd{cd var}
10762 $ @kbd{cat GNUFileParts/longfile.1 \
10763   GNUFileParts/longfile.2 >> longfile}
10764 $ rm -f GNUFileParts
10765 @end group
10766 @end smallexample
10768 Notice, that if the @command{tar} implementation you use supports PAX
10769 format archives, it will probably emit warnings about unknown keywords
10770 during extraction.  They will look like this:
10772 @smallexample
10773 @group
10774 Tar file too small
10775 Unknown extended header keyword 'GNU.volume.filename' ignored.
10776 Unknown extended header keyword 'GNU.volume.size' ignored.
10777 Unknown extended header keyword 'GNU.volume.offset' ignored.
10778 @end group
10779 @end smallexample
10781 @noindent
10782 You can safely ignore these warnings.
10784 If your @command{tar} implementation is not PAX-aware, you will get
10785 more warnings and more files generated on your disk, e.g.:
10787 @smallexample
10788 @group
10789 $ @kbd{tar xf vol-1.tar}
10790 var/PaxHeaders/longfile: Unknown file type 'x', extracted as
10791 normal file
10792 Unexpected EOF in archive
10793 $ @kbd{tar xf vol-2.tar}
10794 tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file
10795 GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type
10796 'x', extracted as normal file
10797 @end group
10798 @end smallexample
10800 Ignore these warnings.  The @file{PaxHeaders.*} directories created
10801 will contain files with @dfn{extended header keywords} describing the
10802 extracted files.  You can delete them, unless they describe sparse
10803 members.  Read further to learn more about them.
10805 @node Sparse Recovery
10806 @subsubsection Extracting Sparse Members
10808 @cindex sparse files, extracting with non-GNU tars
10809 Any @command{tar} implementation will be able to extract sparse members from a
10810 PAX archive.  However, the extracted files will be @dfn{condensed},
10811 i.e., any zero blocks will be removed from them.  When we restore such
10812 a condensed file to its original form, by adding zero blocks (or
10813 @dfn{holes}) back to their original locations, we call this process
10814 @dfn{expanding} a compressed sparse file.
10816 @pindex xsparse
10817 To expand a file, you will need a simple auxiliary program called
10818 @command{xsparse}.  It is available in source form from
10819 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10820 home page}.
10822 @cindex sparse files v.1.0, extracting with non-GNU tars
10823 Let's begin with archive members in @dfn{sparse format
10824 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10825 The condensed file will contain both file map and file data, so no
10826 additional data will be needed to restore it.  If the original file
10827 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10828 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10829 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10830 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10831 archive (@pxref{PAX keywords}).}.
10833 To expand a version 1.0 file, run @command{xsparse} as follows:
10835 @smallexample
10836 $ @kbd{xsparse @file{cond-file}}
10837 @end smallexample
10839 @noindent
10840 where @file{cond-file} is the name of the condensed file.  The utility
10841 will deduce the name for the resulting expanded file using the
10842 following algorithm:
10844 @enumerate 1
10845 @item If @file{cond-file} does not contain any directories,
10846 @file{../cond-file} will be used;
10848 @item If @file{cond-file} has the form
10849 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10850 are simple names, with no @samp{/} characters in them, the output file
10851 name will be @file{@var{dir}/@var{name}}.
10853 @item Otherwise, if @file{cond-file} has the form
10854 @file{@var{dir}/@var{name}}, the output file name will be
10855 @file{@var{name}}.
10856 @end enumerate
10858 In the unlikely case when this algorithm does not suit your needs,
10859 you can explicitly specify output file name as a second argument to
10860 the command:
10862 @smallexample
10863 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10864 @end smallexample
10866 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10867 first.  In this mode, the command does not actually expand the file,
10868 but verbosely lists all actions it would be taking to do so.  The dry
10869 run mode is enabled by @option{-n} command line argument:
10871 @smallexample
10872 @group
10873 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10874 Reading v.1.0 sparse map
10875 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10876 '/home/gray/sparsefile'
10877 Finished dry run
10878 @end group
10879 @end smallexample
10881 To actually expand the file, you would run:
10883 @smallexample
10884 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10885 @end smallexample
10887 @noindent
10888 The program behaves the same way all UNIX utilities do: it will keep
10889 quiet unless it has something important to tell you (e.g. an error
10890 condition or something).  If you wish it to produce verbose output,
10891 similar to that from the dry run mode, use @option{-v} option:
10893 @smallexample
10894 @group
10895 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10896 Reading v.1.0 sparse map
10897 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10898 '/home/gray/sparsefile'
10899 Done
10900 @end group
10901 @end smallexample
10903 Additionally, if your @command{tar} implementation has extracted the
10904 @dfn{extended headers} for this file, you can instruct @command{xstar}
10905 to use them in order to verify the integrity of the expanded file.
10906 The option @option{-x} sets the name of the extended header file to
10907 use.  Continuing our example:
10909 @smallexample
10910 @group
10911 $ @kbd{xsparse -v -x /home/gray/PaxHeaders/sparsefile \
10912   /home/gray/GNUSparseFile/sparsefile}
10913 Reading extended header file
10914 Found variable GNU.sparse.major = 1
10915 Found variable GNU.sparse.minor = 0
10916 Found variable GNU.sparse.name = sparsefile
10917 Found variable GNU.sparse.realsize = 217481216
10918 Reading v.1.0 sparse map
10919 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10920 '/home/gray/sparsefile'
10921 Done
10922 @end group
10923 @end smallexample
10925 @anchor{extracting sparse v0x}
10926 @cindex sparse files v.0.1, extracting with non-GNU tars
10927 @cindex sparse files v.0.0, extracting with non-GNU tars
10928 An @dfn{extended header} is a special @command{tar} archive header
10929 that precedes an archive member and contains a set of
10930 @dfn{variables}, describing the member properties that cannot be
10931 stored in the standard @code{ustar} header.  While optional for
10932 expanding sparse version 1.0 members, the use of extended headers is
10933 mandatory when expanding sparse members in older sparse formats: v.0.0
10934 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10935 Formats}.)  So, for these formats, the question is: how to obtain
10936 extended headers from the archive?
10938 If you use a @command{tar} implementation that does not support PAX
10939 format, extended headers for each member will be extracted as a
10940 separate file.  If we represent the member name as
10941 @file{@var{dir}/@var{name}}, then the extended header file will be
10942 named @file{@var{dir}/@/PaxHeaders/@/@var{name}}.
10944 Things become more difficult if your @command{tar} implementation
10945 does support PAX headers, because in this case you will have to
10946 manually extract the headers.  We recommend the following algorithm:
10948 @enumerate 1
10949 @item
10950 Consult the documentation of your @command{tar} implementation for an
10951 option that prints @dfn{block numbers} along with the archive
10952 listing (analogous to @GNUTAR{}'s @option{-R} option).  For example,
10953 @command{star} has @option{-block-number}.
10955 @item
10956 Obtain verbose listing using the @samp{block number} option, and
10957 find block numbers of the sparse member in question and the member
10958 immediately following it.  For example, running @command{star} on our
10959 archive we obtain:
10961 @smallexample
10962 @group
10963 $ @kbd{star -t -v -block-number -f arc.tar}
10964 @dots{}
10965 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10966 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10967 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10968 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10969 block        56:  425984 -rw-r--r--  gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10970 block       897:   65391 -rw-r--r--  gray/users Jun 24 20:06 2006 README
10971 @dots{}
10972 @end group
10973 @end smallexample
10975 @noindent
10976 (as usual, ignore the warnings about unknown keywords.)
10978 @item
10979 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10980 and @var{Bn} be the block number of the next member.
10981 Compute:
10983 @smallexample
10984 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10985 @end smallexample
10987 @noindent
10988 This number gives the size of the extended header part in tar @dfn{blocks}.
10989 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10990 = 7}.
10992 @item
10993 Use @command{dd} to extract the headers:
10995 @smallexample
10996 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10997 @end smallexample
10999 @noindent
11000 where @var{archive} is the archive name, @var{hname} is a name of the
11001 file to store the extended header in, @var{Bs} and @var{N} are
11002 computed in previous steps.
11004 In our example, this command will be
11006 @smallexample
11007 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
11008 @end smallexample
11009 @end enumerate
11011 Finally, you can expand the condensed file, using the obtained header:
11013 @smallexample
11014 @group
11015 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
11016 Reading extended header file
11017 Found variable GNU.sparse.size = 217481216
11018 Found variable GNU.sparse.numblocks = 208
11019 Found variable GNU.sparse.name = sparsefile
11020 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
11021 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
11022 Done
11023 @end group
11024 @end smallexample
11026 @node cpio
11027 @section Comparison of @command{tar} and @command{cpio}
11028 @UNREVISED
11030 @FIXME{Reorganize the following material}
11032 The @command{cpio} archive formats, like @command{tar}, do have maximum
11033 file name lengths.  The binary and old @acronym{ASCII} formats have a maximum file
11034 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
11035 file length of 1024.  @acronym{GNU} @command{cpio} can read and write archives
11036 with arbitrary file name lengths, but other @command{cpio} implementations
11037 may crash unexplainedly trying to read them.
11039 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
11040 @command{cpio} doesn't handle symbolic links in the form in which it comes
11041 in System V prior to SVR4, and some vendors may have added symlinks
11042 to their system without enhancing @command{cpio} to know about them.
11043 Others may have enhanced it in a way other than the way I did it
11044 at Sun, and which was adopted by AT&T (and which is, I think, also
11045 present in the @command{cpio} that Berkeley picked up from AT&T and put
11046 into a later @acronym{BSD} release---I think I gave them my changes).
11048 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
11049 can handle @command{tar} format input, and write it on output, and it
11050 probably handles symbolic links.  They may not have bothered doing
11051 anything to enhance @command{tar} as a result.)
11053 @command{cpio} handles special files; traditional @command{tar} doesn't.
11055 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
11056 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
11057 (4.3-tahoe and later).
11059 @command{tar}'s way of handling multiple hard links to a file can handle
11060 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
11061 @command{cpio}s way requires you to play some games (in its ``binary''
11062 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
11063 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
11064 field of the header to make sure that the file system @acronym{ID}/i-number pairs
11065 of different files were always different), and I don't know which
11066 @command{cpio}s, if any, play those games.  Those that don't might get
11067 confused and think two files are the same file when they're not, and
11068 make hard links between them.
11070 @command{tar}s way of handling multiple hard links to a file places only
11071 one copy of the link on the tape, but the name attached to that copy
11072 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
11073 way puts one copy for every link, but you can retrieve it using any
11074 of the names.
11076 @quotation
11077 What type of check sum (if any) is used, and how is this calculated.
11078 @end quotation
11080 See the attached manual pages for @command{tar} and @command{cpio} format.
11081 @command{tar} uses a checksum which is the sum of all the bytes in the
11082 @command{tar} header for a file; @command{cpio} uses no checksum.
11084 @quotation
11085 If anyone knows why @command{cpio} was made when @command{tar} was present
11086 at the unix scene,
11087 @end quotation
11089 It wasn't.  @command{cpio} first showed up in PWB/UNIX 1.0; no
11090 generally-available version of UNIX had @command{tar} at the time.  I don't
11091 know whether any version that was generally available @emph{within AT&T}
11092 had @command{tar}, or, if so, whether the people within AT&T who did
11093 @command{cpio} knew about it.
11095 On restore, if there is a corruption on a tape @command{tar} will stop at
11096 that point, while @command{cpio} will skip over it and try to restore the
11097 rest of the files.
11099 The main difference is just in the command syntax and header format.
11101 @command{tar} is a little more tape-oriented in that everything is blocked
11102 to start on a record boundary.
11104 @quotation
11105 Is there any differences between the ability to recover crashed
11106 archives between the two of them.  (Is there any chance of recovering
11107 crashed archives at all.)
11108 @end quotation
11110 Theoretically it should be easier under @command{tar} since the blocking
11111 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
11112 However, modern @command{cpio}'s and variations have an option to just
11113 search for the next file header after an error with a reasonable chance
11114 of resyncing.  However, lots of tape driver software won't allow you to
11115 continue past a media error which should be the only reason for getting
11116 out of sync unless a file changed sizes while you were writing the
11117 archive.
11119 @quotation
11120 If anyone knows why @command{cpio} was made when @command{tar} was present
11121 at the unix scene, please tell me about this too.
11122 @end quotation
11124 Probably because it is more media efficient (by not blocking everything
11125 and using only the space needed for the headers where @command{tar}
11126 always uses 512 bytes per file header) and it knows how to archive
11127 special files.
11129 You might want to look at the freely available alternatives.  The
11130 major ones are @command{afio}, @GNUTAR{}, and
11131 @command{pax}, each of which have their own extensions with some
11132 backwards compatibility.
11134 Sparse files were @command{tar}red as sparse files (which you can
11135 easily test, because the resulting archive gets smaller, and
11136 @acronym{GNU} @command{cpio} can no longer read it).
11138 @node Media
11139 @chapter Tapes and Other Archive Media
11140 @UNREVISED
11142 A few special cases about tape handling warrant more detailed
11143 description.  These special cases are discussed below.
11145 Many complexities surround the use of @command{tar} on tape drives.  Since
11146 the creation and manipulation of archives located on magnetic tape was
11147 the original purpose of @command{tar}, it contains many features making
11148 such manipulation easier.
11150 Archives are usually written on dismountable media---tape cartridges,
11151 mag tapes, or floppy disks.
11153 The amount of data a tape or disk holds depends not only on its size,
11154 but also on how it is formatted.  A 2400 foot long reel of mag tape
11155 holds 40 megabytes of data when formatted at 1600 bits per inch.  The
11156 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
11158 Magnetic media are re-usable---once the archive on a tape is no longer
11159 needed, the archive can be erased and the tape or disk used over.
11160 Media quality does deteriorate with use, however.  Most tapes or disks
11161 should be discarded when they begin to produce data errors.  EXABYTE
11162 tape cartridges should be discarded when they generate an @dfn{error
11163 count} (number of non-usable bits) of more than 10k.
11165 Magnetic media are written and erased using magnetic fields, and
11166 should be protected from such fields to avoid damage to stored data.
11167 Sticking a floppy disk to a filing cabinet using a magnet is probably
11168 not a good idea.
11170 @menu
11171 * Device::                      Device selection and switching
11172 * Remote Tape Server::
11173 * Common Problems and Solutions::
11174 * Blocking::                    Blocking
11175 * Many::                        Many archives on one tape
11176 * Using Multiple Tapes::        Using Multiple Tapes
11177 * label::                       Including a Label in the Archive
11178 * verify::
11179 * Write Protection::
11180 @end menu
11182 @node Device
11183 @section Device Selection and Switching
11184 @UNREVISED
11186 @table @option
11187 @item -f [@var{hostname}:]@var{file}
11188 @itemx --file=[@var{hostname}:]@var{file}
11189 Use archive file or device @var{file} on @var{hostname}.
11190 @end table
11192 This option is used to specify the file name of the archive @command{tar}
11193 works on.
11195 If the file name is @samp{-}, @command{tar} reads the archive from standard
11196 input (when listing or extracting), or writes it to standard output
11197 (when creating).  If the @samp{-} file name is given when updating an
11198 archive, @command{tar} will read the original archive from its standard
11199 input, and will write the entire new archive to its standard output.
11201 If the file name contains a @samp{:}, it is interpreted as
11202 @samp{hostname:file name}.  If the @var{hostname} contains an @dfn{at}
11203 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}.  In
11204 either case, @command{tar} will invoke the command @command{rsh} (or
11205 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
11206 machine.  If you give an alternate login name, it will be given to the
11207 @command{rsh}.
11208 Naturally, the remote machine must have an executable
11209 @command{/usr/libexec/rmt}.  This program is free software from the
11210 University of California, and a copy of the source code can be found
11211 with the sources for @command{tar}; it's compiled and installed by default.
11212 The exact path to this utility is determined when configuring the package.
11213 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
11214 your installation prefix.  This location may also be overridden at
11215 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
11216 ---rmt-command}, for detailed description of this option.  @xref{Remote
11217 Tape Server}, for the description of @command{rmt} command).
11219 If this option is not given, but the environment variable @env{TAPE}
11220 is set, its value is used; otherwise, old versions of @command{tar}
11221 used a default archive name (which was picked when @command{tar} was
11222 compiled).  The default is normally set up to be the @dfn{first} tape
11223 drive or other transportable I/O medium on the system.
11225 Starting with version 1.11.5, @GNUTAR{} uses
11226 standard input and standard output as the default device, and I will
11227 not try anymore supporting automatic device detection at installation
11228 time.  This was failing really in too many cases, it was hopeless.
11229 This is now completely left to the installer to override standard
11230 input and standard output for default device, if this seems
11231 preferable.  Further, I think @emph{most} actual usages of
11232 @command{tar} are done with pipes or disks, not really tapes,
11233 cartridges or diskettes.
11235 Some users think that using standard input and output is running
11236 after trouble.  This could lead to a nasty surprise on your screen if
11237 you forget to specify an output file name---especially if you are going
11238 through a network or terminal server capable of buffering large amounts
11239 of output.  We had so many bug reports in that area of configuring
11240 default tapes automatically, and so many contradicting requests, that
11241 we finally consider the problem to be portably intractable.  We could
11242 of course use something like @samp{/dev/tape} as a default, but this
11243 is @emph{also} running after various kind of trouble, going from hung
11244 processes to accidental destruction of real tapes.  After having seen
11245 all this mess, using standard input and output as a default really
11246 sounds like the only clean choice left, and a very useful one too.
11248 @GNUTAR{} reads and writes archive in records, I
11249 suspect this is the main reason why block devices are preferred over
11250 character devices.  Most probably, block devices are more efficient
11251 too.  The installer could also check for @samp{DEFTAPE} in
11252 @file{<sys/mtio.h>}.
11254 @table @option
11255 @xopindex{force-local, short description}
11256 @item --force-local
11257 Archive file is local even if it contains a colon.
11259 @opindex rsh-command
11260 @item --rsh-command=@var{command}
11261 Use remote @var{command} instead of @command{rsh}.  This option exists
11262 so that people who use something other than the standard @command{rsh}
11263 (e.g., a Kerberized @command{rsh}) can access a remote device.
11265 When this command is not used, the shell command found when
11266 the @command{tar} program was installed is used instead.  This is
11267 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
11268 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
11269 The installer may have overridden this by defining the environment
11270 variable @env{RSH} @emph{at installation time}.
11272 @item -[0-7][lmh]
11273 Specify drive and density.
11275 @xopindex{multi-volume, short description}
11276 @item -M
11277 @itemx --multi-volume
11278 Create/list/extract multi-volume archive.
11280 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
11281 that may be larger than will fit on the medium used to hold it.
11282 @xref{Multi-Volume Archives}.
11284 @xopindex{tape-length, short description}
11285 @item -L @var{num}
11286 @itemx --tape-length=@var{size}[@var{suf}]
11287 Change tape after writing @var{size} units of data.  Unless @var{suf} is
11288 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
11289 1024} bytes.  The following suffixes alter this behavior:
11291 @float Table, size-suffixes
11292 @caption{Size Suffixes}
11293 @multitable @columnfractions 0.2 0.3 0.3
11294 @headitem Suffix @tab Units            @tab Byte Equivalent
11295 @item b          @tab Blocks           @tab @var{size} x 512
11296 @item B          @tab Kilobytes        @tab @var{size} x 1024
11297 @item c          @tab Bytes            @tab @var{size}
11298 @item G          @tab Gigabytes        @tab @var{size} x 1024^3
11299 @item K          @tab Kilobytes        @tab @var{size} x 1024
11300 @item k          @tab Kilobytes        @tab @var{size} x 1024
11301 @item M          @tab Megabytes        @tab @var{size} x 1024^2
11302 @item P          @tab Petabytes        @tab @var{size} x 1024^5
11303 @item T          @tab Terabytes        @tab @var{size} x 1024^4
11304 @item w          @tab Words            @tab @var{size} x 2
11305 @end multitable
11306 @end float
11308 This option might be useful when your tape drivers do not properly
11309 detect end of physical tapes.  By being slightly conservative on the
11310 maximum tape length, you might avoid the problem entirely.
11312 @xopindex{info-script, short description}
11313 @xopindex{new-volume-script, short description}
11314 @item -F @var{command}
11315 @itemx --info-script=@var{command}
11316 @itemx --new-volume-script=@var{command}
11317 Execute @var{command} at end of each tape.  This implies
11318 @option{--multi-volume} (@option{-M}).  @xref{info-script}, for a detailed
11319 description of this option.
11320 @end table
11322 @node Remote Tape Server
11323 @section Remote Tape Server
11325 @cindex remote tape drive
11326 @pindex rmt
11327 In order to access the tape drive on a remote machine, @command{tar}
11328 uses the remote tape server written at the University of California at
11329 Berkeley.  The remote tape server must be installed as
11330 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
11331 want to use.  @command{tar} calls @command{rmt} by running an
11332 @command{rsh} or @command{remsh} to the remote machine, optionally
11333 using a different login name if one is supplied.
11335 A copy of the source for the remote tape server is provided.  Its
11336 source code can be freely distributed.  It is compiled and
11337 installed by default.
11339 @cindex absolute file names
11340 Unless you use the @option{--absolute-names} (@option{-P}) option,
11341 @GNUTAR{} will not allow you to create an archive that contains
11342 absolute file names (a file name beginning with @samp{/}).  If you try,
11343 @command{tar} will automatically remove the leading @samp{/} from the
11344 file names it stores in the archive.  It will also type a warning
11345 message telling you what it is doing.
11347 When reading an archive that was created with a different
11348 @command{tar} program, @GNUTAR{} automatically
11349 extracts entries in the archive which have absolute file names as if
11350 the file names were not absolute.  This is an important feature.  A
11351 visitor here once gave a @command{tar} tape to an operator to restore;
11352 the operator used Sun @command{tar} instead of @GNUTAR{},
11353 and the result was that it replaced large portions of
11354 our @file{/bin} and friends with versions from the tape; needless to
11355 say, we were unhappy about having to recover the file system from
11356 backup tapes.
11358 For example, if the archive contained a file @file{/usr/bin/computoy},
11359 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
11360 relative to the current directory.  If you want to extract the files in
11361 an archive to the same absolute names that they had when the archive
11362 was created, you should do a @samp{cd /} before extracting the files
11363 from the archive, or you should either use the @option{--absolute-names}
11364 option, or use the command @samp{tar -C / @dots{}}.
11366 @cindex Ultrix 3.1 and write failure
11367 Some versions of Unix (Ultrix 3.1 is known to have this problem),
11368 can claim that a short write near the end of a tape succeeded,
11369 when it actually failed.  This will result in the -M option not
11370 working correctly.  The best workaround at the moment is to use a
11371 significantly larger blocking factor than the default 20.
11373 In order to update an archive, @command{tar} must be able to backspace the
11374 archive in order to reread or rewrite a record that was just read (or
11375 written).  This is currently possible only on two kinds of files: normal
11376 disk files (or any other file that can be backspaced with @samp{lseek}),
11377 and industry-standard 9-track magnetic tape (or any other kind of tape
11378 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
11380 This means that the @option{--append}, @option{--concatenate}, and
11381 @option{--delete} commands will not work on any other kind of file.
11382 Some media simply cannot be backspaced, which means these commands and
11383 options will never be able to work on them.  These non-backspacing
11384 media include pipes and cartridge tape drives.
11386 Some other media can be backspaced, and @command{tar} will work on them
11387 once @command{tar} is modified to do so.
11389 Archives created with the @option{--multi-volume}, @option{--label}, and
11390 @option{--incremental} (@option{-G}) options may not be readable by other version
11391 of @command{tar}.  In particular, restoring a file that was split over
11392 a volume boundary will require some careful work with @command{dd}, if
11393 it can be done at all.  Other versions of @command{tar} may also create
11394 an empty file whose name is that of the volume header.  Some versions
11395 of @command{tar} may create normal files instead of directories archived
11396 with the @option{--incremental} (@option{-G}) option.
11398 @node Common Problems and Solutions
11399 @section Some Common Problems and their Solutions
11401 @ifclear PUBLISH
11403 @format
11404 errors from system:
11405 permission denied
11406 no such file or directory
11407 not owner
11409 errors from @command{tar}:
11410 directory checksum error
11411 header format error
11413 errors from media/system:
11414 i/o error
11415 device busy
11416 @end format
11418 @end ifclear
11420 @node Blocking
11421 @section Blocking
11422 @cindex block
11423 @cindex record
11425 @dfn{Block} and @dfn{record} terminology is rather confused, and it
11426 is also confusing to the expert reader.  On the other hand, readers
11427 who are new to the field have a fresh mind, and they may safely skip
11428 the next two paragraphs, as the remainder of this manual uses those
11429 two terms in a quite consistent way.
11431 John Gilmore, the writer of the public domain @command{tar} from which
11432 @GNUTAR{} was originally derived, wrote (June 1995):
11434 @quotation
11435 The nomenclature of tape drives comes from IBM, where I believe
11436 they were invented for the IBM 650 or so.  On IBM mainframes, what
11437 is recorded on tape are tape blocks.  The logical organization of
11438 data is into records.  There are various ways of putting records into
11439 blocks, including @code{F} (fixed sized records), @code{V} (variable
11440 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
11441 to a block), @code{VB} (variable size records, @var{n} to a block),
11442 @code{VSB} (variable spanned blocked: variable sized records that can
11443 occupy more than one block), etc.  The @code{JCL} @samp{DD RECFORM=}
11444 parameter specified this to the operating system.
11446 The Unix man page on @command{tar} was totally confused about this.
11447 When I wrote @code{PD TAR}, I used the historically correct terminology
11448 (@command{tar} writes data records, which are grouped into blocks).
11449 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
11450 here), and now Fran@,{c}ois has migrated that terminology back
11451 into the source code too.
11452 @end quotation
11454 The term @dfn{physical block} means the basic transfer chunk from or
11455 to a device, after which reading or writing may stop without anything
11456 being lost.  In this manual, the term @dfn{block} usually refers to
11457 a disk physical block, @emph{assuming} that each disk block is 512
11458 bytes in length.  It is true that some disk devices have different
11459 physical blocks, but @command{tar} ignore these differences in its own
11460 format, which is meant to be portable, so a @command{tar} block is always
11461 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
11462 The term @dfn{logical block} often represents the basic chunk of
11463 allocation of many disk blocks as a single entity, which the operating
11464 system treats somewhat atomically; this concept is only barely used
11465 in @GNUTAR{}.
11467 The term @dfn{physical record} is another way to speak of a physical
11468 block, those two terms are somewhat interchangeable.  In this manual,
11469 the term @dfn{record} usually refers to a tape physical block,
11470 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
11471 It is true that archives may be put on disk or used with pipes,
11472 but nevertheless, @command{tar} tries to read and write the archive one
11473 @dfn{record} at a time, whatever the medium in use.  One record is made
11474 up of an integral number of blocks, and this operation of putting many
11475 disk blocks into a single tape block is called @dfn{reblocking}, or
11476 more simply, @dfn{blocking}.  The term @dfn{logical record} refers to
11477 the logical organization of many characters into something meaningful
11478 to the application.  The term @dfn{unit record} describes a small set
11479 of characters which are transmitted whole to or by the application,
11480 and often refers to a line of text.  Those two last terms are unrelated
11481 to what we call a @dfn{record} in @GNUTAR{}.
11483 When writing to tapes, @command{tar} writes the contents of the archive
11484 in chunks known as @dfn{records}.  To change the default blocking
11485 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
11486 @var{512-size}}) option.  Each record will then be composed of
11487 @var{512-size} blocks.  (Each @command{tar} block is 512 bytes.
11488 @xref{Standard}.)  Each file written to the archive uses at least one
11489 full record.  As a result, using a larger record size can result in
11490 more wasted space for small files.  On the other hand, a larger record
11491 size can often be read and written much more efficiently.
11493 Further complicating the problem is that some tape drives ignore the
11494 blocking entirely.  For these, a larger record size can still improve
11495 performance (because the software layers above the tape drive still
11496 honor the blocking), but not as dramatically as on tape drives that
11497 honor blocking.
11499 When reading an archive, @command{tar} can usually figure out the
11500 record size on itself.  When this is the case, and a non-standard
11501 record size was used when the archive was created, @command{tar} will
11502 print a message about a non-standard blocking factor, and then operate
11503 normally@footnote{If this message is not needed, you can turn it off
11504 using the @option{--warning=no-record-size} option.}.  On some tape
11505 devices, however, @command{tar} cannot figure out the record size
11506 itself.  On most of those, you can specify a blocking factor (with
11507 @option{--blocking-factor}) larger than the actual blocking factor,
11508 and then use the @option{--read-full-records} (@option{-B}) option.
11509 (If you specify a blocking factor with @option{--blocking-factor} and
11510 don't use the @option{--read-full-records} option, then @command{tar}
11511 will not attempt to figure out the recording size itself.)  On some
11512 devices, you must always specify the record size exactly with
11513 @option{--blocking-factor} when reading, because @command{tar} cannot
11514 figure it out.  In any case, use @option{--list} (@option{-t}) before
11515 doing any extractions to see whether @command{tar} is reading the archive
11516 correctly.
11518 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
11519 putting them into records is to put a whole number of them (one or
11520 more) into each record.  @command{tar} records are all the same size;
11521 at the end of the file there's a block containing all zeros, which
11522 is how you tell that the remainder of the last record(s) are garbage.
11524 In a standard @command{tar} file (no options), the block size is 512
11525 and the record size is 10240, for a blocking factor of 20.  What the
11526 @option{--blocking-factor} option does is sets the blocking factor,
11527 changing the record size while leaving the block size at 512 bytes.
11528 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
11529 most tape drives these days prefer much bigger records in order to
11530 stream and not waste tape.  When writing tapes for myself, some tend
11531 to use a factor of the order of 2048, say, giving a record size of
11532 around one megabyte.
11534 If you use a blocking factor larger than 20, older @command{tar}
11535 programs might not be able to read the archive, so we recommend this
11536 as a limit to use in practice.  @GNUTAR{}, however,
11537 will support arbitrarily large record sizes, limited only by the
11538 amount of virtual memory or the physical characteristics of the tape
11539 device.
11541 @menu
11542 * Format Variations::           Format Variations
11543 * Blocking Factor::             The Blocking Factor of an Archive
11544 @end menu
11546 @node Format Variations
11547 @subsection Format Variations
11548 @cindex Format Parameters
11549 @cindex Format Options
11550 @cindex Options, archive format specifying
11551 @cindex Options, format specifying
11552 @UNREVISED
11554 Format parameters specify how an archive is written on the archive
11555 media.  The best choice of format parameters will vary depending on
11556 the type and number of files being archived, and on the media used to
11557 store the archive.
11559 To specify format parameters when accessing or creating an archive,
11560 you can use the options described in the following sections.
11561 If you do not specify any format parameters, @command{tar} uses
11562 default parameters.  You cannot modify a compressed archive.
11563 If you create an archive with the @option{--blocking-factor} option
11564 specified (@pxref{Blocking Factor}), you must specify that
11565 blocking-factor when operating on the archive.  @xref{Formats}, for other
11566 examples of format parameter considerations.
11568 @node Blocking Factor
11569 @subsection The Blocking Factor of an Archive
11570 @cindex Blocking Factor
11571 @cindex Record Size
11572 @cindex Number of blocks per record
11573 @cindex Number of bytes per record
11574 @cindex Bytes per record
11575 @cindex Blocks per record
11576 @UNREVISED
11578 @opindex blocking-factor
11579 The data in an archive is grouped into blocks, which are 512 bytes.
11580 Blocks are read and written in whole number multiples called
11581 @dfn{records}.  The number of blocks in a record (i.e., the size of a
11582 record in units of 512 bytes) is called the @dfn{blocking factor}.
11583 The @option{--blocking-factor=@var{512-size}} (@option{-b
11584 @var{512-size}}) option specifies the blocking factor of an archive.
11585 The default blocking factor is typically 20 (i.e., 10240 bytes), but
11586 can be specified at installation.  To find out the blocking factor of
11587 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
11588 This may not work on some devices.
11590 Records are separated by gaps, which waste space on the archive media.
11591 If you are archiving on magnetic tape, using a larger blocking factor
11592 (and therefore larger records) provides faster throughput and allows you
11593 to fit more data on a tape (because there are fewer gaps).  If you are
11594 archiving on cartridge, a very large blocking factor (say 126 or more)
11595 greatly increases performance.  A smaller blocking factor, on the other
11596 hand, may be useful when archiving small files, to avoid archiving lots
11597 of nulls as @command{tar} fills out the archive to the end of the record.
11598 In general, the ideal record size depends on the size of the
11599 inter-record gaps on the tape you are using, and the average size of the
11600 files you are archiving.  @xref{create}, for information on
11601 writing archives.
11603 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
11605 Archives with blocking factors larger than 20 cannot be read
11606 by very old versions of @command{tar}, or by some newer versions
11607 of @command{tar} running on old machines with small address spaces.
11608 With @GNUTAR{}, the blocking factor of an archive is limited
11609 only by the maximum record size of the device containing the archive,
11610 or by the amount of available virtual memory.
11612 Also, on some systems, not using adequate blocking factors, as sometimes
11613 imposed by the device drivers, may yield unexpected diagnostics.  For
11614 example, this has been reported:
11616 @smallexample
11617 Cannot write to /dev/dlt: Invalid argument
11618 @end smallexample
11620 @noindent
11621 In such cases, it sometimes happen that the @command{tar} bundled by
11622 the system is aware of block size idiosyncrasies, while @GNUTAR{}
11623 requires an explicit specification for the block size,
11624 which it cannot guess.  This yields some people to consider
11625 @GNUTAR{} is misbehaving, because by comparison,
11626 @cite{the bundle @command{tar} works OK}.  Adding @w{@kbd{-b 256}},
11627 for example, might resolve the problem.
11629 If you use a non-default blocking factor when you create an archive, you
11630 must specify the same blocking factor when you modify that archive.  Some
11631 archive devices will also require you to specify the blocking factor when
11632 reading that archive, however this is not typically the case.  Usually, you
11633 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
11634 reports a non-default record size and then lists the archive members as
11635 it would normally.  To extract files from an archive with a non-standard
11636 blocking factor (particularly if you're not sure what the blocking factor
11637 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
11638 specifying a blocking factor larger then the blocking factor of the archive
11639 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
11640 @xref{list}, for more information on the @option{--list} (@option{-t})
11641 operation.  @xref{Reading}, for a more detailed explanation of that option.
11643 @table @option
11644 @item --blocking-factor=@var{number}
11645 @itemx -b @var{number}
11646 Specifies the blocking factor of an archive.  Can be used with any
11647 operation, but is usually not necessary with @option{--list} (@option{-t}).
11648 @end table
11650 Device blocking
11652 @table @option
11653 @item -b @var{blocks}
11654 @itemx --blocking-factor=@var{blocks}
11655 Set record size to @math{@var{blocks}*512} bytes.
11657 This option is used to specify a @dfn{blocking factor} for the archive.
11658 When reading or writing the archive, @command{tar}, will do reads and writes
11659 of the archive in records of @math{@var{block}*512} bytes.  This is true
11660 even when the archive is compressed.  Some devices requires that all
11661 write operations be a multiple of a certain size, and so, @command{tar}
11662 pads the archive out to the next record boundary.
11664 The default blocking factor is set when @command{tar} is compiled, and is
11665 typically 20.  Blocking factors larger than 20 cannot be read by very
11666 old versions of @command{tar}, or by some newer versions of @command{tar}
11667 running on old machines with small address spaces.
11669 With a magnetic tape, larger records give faster throughput and fit
11670 more data on a tape (because there are fewer inter-record gaps).
11671 If the archive is in a disk file or a pipe, you may want to specify
11672 a smaller blocking factor, since a large one will result in a large
11673 number of null bytes at the end of the archive.
11675 When writing cartridge or other streaming tapes, a much larger
11676 blocking factor (say 126 or more) will greatly increase performance.
11677 However, you must specify the same blocking factor when reading or
11678 updating the archive.
11680 Apparently, Exabyte drives have a physical block size of 8K bytes.
11681 If we choose our blocksize as a multiple of 8k bytes, then the problem
11682 seems to disappear.  Id est, we are using block size of 112 right
11683 now, and we haven't had the problem since we switched@dots{}
11685 With @GNUTAR{} the blocking factor is limited only
11686 by the maximum record size of the device containing the archive, or by
11687 the amount of available virtual memory.
11689 However, deblocking or reblocking is virtually avoided in a special
11690 case which often occurs in practice, but which requires all the
11691 following conditions to be simultaneously true:
11692 @itemize @bullet
11693 @item
11694 the archive is subject to a compression option,
11695 @item
11696 the archive is not handled through standard input or output, nor
11697 redirected nor piped,
11698 @item
11699 the archive is directly handled to a local disk, instead of any special
11700 device,
11701 @item
11702 @option{--blocking-factor} is not explicitly specified on the @command{tar}
11703 invocation.
11704 @end itemize
11706 If the output goes directly to a local disk, and not through
11707 stdout, then the last write is not extended to a full record size.
11708 Otherwise, reblocking occurs.  Here are a few other remarks on this
11709 topic:
11711 @itemize @bullet
11713 @item
11714 @command{gzip} will complain about trailing garbage if asked to
11715 uncompress a compressed archive on tape, there is an option to turn
11716 the message off, but it breaks the regularity of simply having to use
11717 @samp{@var{prog} -d} for decompression.  It would be nice if gzip was
11718 silently ignoring any number of trailing zeros.  I'll ask Jean-loup
11719 Gailly, by sending a copy of this message to him.
11721 @item
11722 @command{compress} does not show this problem, but as Jean-loup pointed
11723 out to Michael, @samp{compress -d} silently adds garbage after
11724 the result of decompression, which tar ignores because it already
11725 recognized its end-of-file indicator.  So this bug may be safely
11726 ignored.
11728 @item
11729 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
11730 but will still return an exit status of 2 which tar reports in turn.
11731 @command{tar} might ignore the exit status returned, but I hate doing
11732 that, as it weakens the protection @command{tar} offers users against
11733 other possible problems at decompression time.  If @command{gzip} was
11734 silently skipping trailing zeros @emph{and} also avoiding setting the
11735 exit status in this innocuous case, that would solve this situation.
11737 @item
11738 @command{tar} should become more solid at not stopping to read a pipe at
11739 the first null block encountered.  This inelegantly breaks the pipe.
11740 @command{tar} should rather drain the pipe out before exiting itself.
11741 @end itemize
11743 @xopindex{ignore-zeros, short description}
11744 @item -i
11745 @itemx --ignore-zeros
11746 Ignore blocks of zeros in archive (means EOF).
11748 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
11749 of zeros in the archive.  Normally a block of zeros indicates the
11750 end of the archive, but when reading a damaged archive, or one which
11751 was created by concatenating several archives together, this option
11752 allows @command{tar} to read the entire archive.  This option is not on
11753 by default because many versions of @command{tar} write garbage after
11754 the zeroed blocks.
11756 Note that this option causes @command{tar} to read to the end of the
11757 archive file, which may sometimes avoid problems when multiple files
11758 are stored on a single physical tape.
11760 @xopindex{read-full-records, short description}
11761 @item -B
11762 @itemx --read-full-records
11763 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
11765 If @option{--read-full-records} is used, @command{tar}
11766 will not panic if an attempt to read a record from the archive does
11767 not return a full record.  Instead, @command{tar} will keep reading
11768 until it has obtained a full
11769 record.
11771 This option is turned on by default when @command{tar} is reading
11772 an archive from standard input, or from a remote machine.  This is
11773 because on @acronym{BSD} Unix systems, a read of a pipe will return however
11774 much happens to be in the pipe, even if it is less than @command{tar}
11775 requested.  If this option was not used, @command{tar} would fail as
11776 soon as it read an incomplete record from the pipe.
11778 This option is also useful with the commands for updating an archive.
11780 @end table
11782 Tape blocking
11784 @FIXME{Appropriate options should be moved here from elsewhere.}
11786 @cindex blocking factor
11787 @cindex tape blocking
11789 When handling various tapes or cartridges, you have to take care of
11790 selecting a proper blocking, that is, the number of disk blocks you
11791 put together as a single tape block on the tape, without intervening
11792 tape gaps.  A @dfn{tape gap} is a small landing area on the tape
11793 with no information on it, used for decelerating the tape to a
11794 full stop, and for later regaining the reading or writing speed.
11795 When the tape driver starts reading a record, the record has to
11796 be read whole without stopping, as a tape gap is needed to stop the
11797 tape motion without losing information.
11799 @cindex Exabyte blocking
11800 @cindex DAT blocking
11801 Using higher blocking (putting more disk blocks per tape block) will use
11802 the tape more efficiently as there will be less tape gaps.  But reading
11803 such tapes may be more difficult for the system, as more memory will be
11804 required to receive at once the whole record.  Further, if there is a
11805 reading error on a huge record, this is less likely that the system will
11806 succeed in recovering the information.  So, blocking should not be too
11807 low, nor it should be too high.  @command{tar} uses by default a blocking of
11808 20 for historical reasons, and it does not really matter when reading or
11809 writing to disk.  Current tape technology would easily accommodate higher
11810 blockings.  Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11811 We were told that for some DLT drives, the blocking should be a multiple
11812 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11813 Other manufacturers may use different recommendations for the same tapes.
11814 This might also depends of the buffering techniques used inside modern
11815 tape controllers.  Some imposes a minimum blocking, or a maximum blocking.
11816 Others request blocking to be some exponent of two.
11818 So, there is no fixed rule for blocking.  But blocking at read time
11819 should ideally be the same as blocking used at write time.  At one place
11820 I know, with a wide variety of equipment, they found it best to use a
11821 blocking of 32 to guarantee that their tapes are fully interchangeable.
11823 I was also told that, for recycled tapes, prior erasure (by the same
11824 drive unit that will be used to create the archives) sometimes lowers
11825 the error rates observed at rewriting time.
11827 I might also use @option{--number-blocks} instead of
11828 @option{--block-number}, so @option{--block} will then expand to
11829 @option{--blocking-factor} unambiguously.
11831 @node Many
11832 @section Many Archives on One Tape
11834 @FIXME{Appropriate options should be moved here from elsewhere.}
11836 @findex ntape @r{device}
11837 Most tape devices have two entries in the @file{/dev} directory, or
11838 entries that come in pairs, which differ only in the minor number for
11839 this device.  Let's take for example @file{/dev/tape}, which often
11840 points to the only or usual tape device of a given system.  There might
11841 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}.  The simpler
11842 name is the @emph{rewinding} version of the device, while the name
11843 having @samp{nr} in it is the @emph{no rewinding} version of the same
11844 device.
11846 A rewinding tape device will bring back the tape to its beginning point
11847 automatically when this device is opened or closed.  Since @command{tar}
11848 opens the archive file before using it and closes it afterwards, this
11849 means that a simple:
11851 @smallexample
11852 $ @kbd{tar cf /dev/tape @var{directory}}
11853 @end smallexample
11855 @noindent
11856 will reposition the tape to its beginning both prior and after saving
11857 @var{directory} contents to it, thus erasing prior tape contents and
11858 making it so that any subsequent write operation will destroy what has
11859 just been saved.
11861 @cindex tape positioning
11862 So, a rewinding device is normally meant to hold one and only one file.
11863 If you want to put more than one @command{tar} archive on a given tape, you
11864 will need to avoid using the rewinding version of the tape device.  You
11865 will also have to pay special attention to tape positioning.  Errors in
11866 positioning may overwrite the valuable data already on your tape.  Many
11867 people, burnt by past experiences, will only use rewinding devices and
11868 limit themselves to one file per tape, precisely to avoid the risk of
11869 such errors.  Be fully aware that writing at the wrong position on a
11870 tape loses all information past this point and most probably until the
11871 end of the tape, and this destroyed information @emph{cannot} be
11872 recovered.
11874 To save @var{directory-1} as a first archive at the beginning of a
11875 tape, and leave that tape ready for a second archive, you should use:
11877 @smallexample
11878 $ @kbd{mt -f /dev/nrtape rewind}
11879 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11880 @end smallexample
11882 @cindex tape marks
11883 @dfn{Tape marks} are special magnetic patterns written on the tape
11884 media, which are later recognizable by the reading hardware.  These
11885 marks are used after each file, when there are many on a single tape.
11886 An empty file (that is to say, two tape marks in a row) signal the
11887 logical end of the tape, after which no file exist.  Usually,
11888 non-rewinding tape device drivers will react to the close request issued
11889 by @command{tar} by first writing two tape marks after your archive, and by
11890 backspacing over one of these.  So, if you remove the tape at that time
11891 from the tape drive, it is properly terminated.  But if you write
11892 another file at the current position, the second tape mark will be
11893 erased by the new information, leaving only one tape mark between files.
11895 So, you may now save @var{directory-2} as a second archive after the
11896 first on the same tape by issuing the command:
11898 @smallexample
11899 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11900 @end smallexample
11902 @noindent
11903 and so on for all the archives you want to put on the same tape.
11905 Another usual case is that you do not write all the archives the same
11906 day, and you need to remove and store the tape between two archive
11907 sessions.  In general, you must remember how many files are already
11908 saved on your tape.  Suppose your tape already has 16 files on it, and
11909 that you are ready to write the 17th.  You have to take care of skipping
11910 the first 16 tape marks before saving @var{directory-17}, say, by using
11911 these commands:
11913 @smallexample
11914 $ @kbd{mt -f /dev/nrtape rewind}
11915 $ @kbd{mt -f /dev/nrtape fsf 16}
11916 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11917 @end smallexample
11919 In all the previous examples, we put aside blocking considerations, but
11920 you should do the proper things for that as well.  @xref{Blocking}.
11922 @menu
11923 * Tape Positioning::            Tape Positions and Tape Marks
11924 * mt::                          The @command{mt} Utility
11925 @end menu
11927 @node Tape Positioning
11928 @subsection Tape Positions and Tape Marks
11929 @UNREVISED
11931 Just as archives can store more than one file from the file system,
11932 tapes can store more than one archive file.  To keep track of where
11933 archive files (or any other type of file stored on tape) begin and
11934 end, tape archive devices write magnetic @dfn{tape marks} on the
11935 archive media.  Tape drives write one tape mark between files,
11936 two at the end of all the file entries.
11938 If you think of data as a series of records "rrrr"'s, and tape marks as
11939 "*"'s, a tape might look like the following:
11941 @smallexample
11942 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11943 @end smallexample
11945 Tape devices read and write tapes using a read/write @dfn{tape
11946 head}---a physical part of the device which can only access one
11947 point on the tape at a time.  When you use @command{tar} to read or
11948 write archive data from a tape device, the device will begin reading
11949 or writing from wherever on the tape the tape head happens to be,
11950 regardless of which archive or what part of the archive the tape
11951 head is on.  Before writing an archive, you should make sure that no
11952 data on the tape will be overwritten (unless it is no longer needed).
11953 Before reading an archive, you should make sure the tape head is at
11954 the beginning of the archive you want to read.  You can do it manually
11955 via @code{mt} utility (@pxref{mt}).  The @code{restore} script does
11956 that automatically (@pxref{Scripted Restoration}).
11958 If you want to add new archive file entries to a tape, you should
11959 advance the tape to the end of the existing file entries, backspace
11960 over the last tape mark, and write the new archive file.  If you were
11961 to add two archives to the example above, the tape might look like the
11962 following:
11964 @smallexample
11965 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11966 @end smallexample
11968 @node mt
11969 @subsection The @command{mt} Utility
11970 @UNREVISED
11972 @FIXME{Is it true that this only works on non-block devices?
11973 should explain the difference, (fixed or variable).}
11974 @xref{Blocking Factor}.
11976 You can use the @command{mt} utility to advance or rewind a tape past a
11977 specified number of archive files on the tape.  This will allow you
11978 to move to the beginning of an archive before extracting or reading
11979 it, or to the end of all the archives before writing a new one.
11980 @FIXME{Why isn't there an "advance 'til you find two tape marks
11981 together"?}
11983 The syntax of the @command{mt} command is:
11985 @smallexample
11986 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11987 @end smallexample
11989 where @var{tapename} is the name of the tape device, @var{number} is
11990 the number of times an operation is performed (with a default of one),
11991 and @var{operation} is one of the following:
11993 @FIXME{is there any use for record operations?}
11995 @table @option
11996 @item eof
11997 @itemx weof
11998 Writes @var{number} tape marks at the current position on the tape.
12000 @item fsf
12001 Moves tape position forward @var{number} files.
12003 @item bsf
12004 Moves tape position back @var{number} files.
12006 @item rewind
12007 Rewinds the tape.  (Ignores @var{number}.)
12009 @item offline
12010 @itemx rewoff1
12011 Rewinds the tape and takes the tape device off-line.  (Ignores @var{number}.)
12013 @item status
12014 Prints status information about the tape unit.
12016 @end table
12018 If you don't specify a @var{tapename}, @command{mt} uses the environment
12019 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
12020 the default device specified in your @file{sys/mtio.h} file
12021 (@code{DEFTAPE} variable).  If this is not defined, the program will
12022 display a descriptive error message and exit with code 1.
12024 @command{mt} returns a 0 exit status when the operation(s) were
12025 successful, 1 if the command was unrecognized, and 2 if an operation
12026 failed.
12028 @node Using Multiple Tapes
12029 @section Using Multiple Tapes
12031 Often you might want to write a large archive, one larger than will fit
12032 on the actual tape you are using.  In such a case, you can run multiple
12033 @command{tar} commands, but this can be inconvenient, particularly if you
12034 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
12035 Therefore, @command{tar} provides a special mode for creating
12036 multi-volume archives.
12038 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
12039 on several media volumes of fixed size.  Although in this section we will
12040 often call @samp{volume} a @dfn{tape}, there is absolutely no
12041 requirement for multi-volume archives to be stored on tapes.  Instead,
12042 they can use whatever media type the user finds convenient, they can
12043 even be located on files.
12045 When creating a multi-volume archive, @GNUTAR{} continues to fill
12046 current volume until it runs out of space, then it switches to
12047 next volume (usually the operator is queried to replace the tape on
12048 this point), and continues working on the new volume.  This operation
12049 continues until all requested files are dumped.  If @GNUTAR{} detects
12050 end of media while dumping a file, such a file is archived in split
12051 form.  Some very big files can even be split across several volumes.
12053 Each volume is itself a valid @GNUTAR{} archive, so it can be read
12054 without any special options.  Consequently any file member residing
12055 entirely on one volume can be extracted or otherwise operated upon
12056 without needing the other volume.  Sure enough, to extract a split
12057 member you would need all volumes its parts reside on.
12059 Multi-volume archives suffer from several limitations.  In particular,
12060 they cannot be compressed.
12062 @GNUTAR{} is able to create multi-volume archives of two formats
12063 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
12065 @menu
12066 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
12067 * Tape Files::                  Tape Files
12068 * Tarcat::                      Concatenate Volumes into a Single Archive
12070 @end menu
12072 @node Multi-Volume Archives
12073 @subsection Archives Longer than One Tape or Disk
12074 @cindex Multi-volume archives
12076 @opindex multi-volume
12077 To create an archive that is larger than will fit on a single unit of
12078 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
12079 the @option{--create} option (@pxref{create}).  A @dfn{multi-volume}
12080 archive can be manipulated like any other archive (provided the
12081 @option{--multi-volume} option is specified), but is stored on more
12082 than one tape or file.
12084 When you specify @option{--multi-volume}, @command{tar} does not report an
12085 error when it comes to the end of an archive volume (when reading), or
12086 the end of the media (when writing).  Instead, it prompts you to load
12087 a new storage volume.  If the archive is on a magnetic tape, you
12088 should change tapes when you see the prompt; if the archive is on a
12089 floppy disk, you should change disks; etc.
12091 @table @option
12092 @item --multi-volume
12093 @itemx -M
12094 Creates a multi-volume archive, when used in conjunction with
12095 @option{--create} (@option{-c}).  To perform any other operation on a multi-volume
12096 archive, specify @option{--multi-volume} in conjunction with that
12097 operation.
12098 For example:
12100 @smallexample
12101 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
12102 @end smallexample
12103 @end table
12105 The method @command{tar} uses to detect end of tape is not perfect, and
12106 fails on some operating systems or on some devices.  If @command{tar}
12107 cannot detect the end of the tape itself, you can use
12108 @option{--tape-length} option to inform it about the capacity of the
12109 tape:
12111 @anchor{tape-length}
12112 @table @option
12113 @opindex tape-length
12114 @item --tape-length=@var{size}[@var{suf}]
12115 @itemx -L @var{size}[@var{suf}]
12116 Set maximum length of a volume.  The @var{suf}, if given, specifies
12117 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
12118 megabytes (@pxref{size-suffixes}, for a list of allowed size
12119 suffixes).  Without @var{suf}, units of 1024 bytes (kilobyte) are
12120 assumed.
12122 This option selects @option{--multi-volume} automatically.  For example:
12124 @smallexample
12125 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
12126 @end smallexample
12128 @noindent
12129 or, which is equivalent:
12131 @smallexample
12132 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
12133 @end smallexample
12134 @end table
12136 @anchor{change volume prompt}
12137 When @GNUTAR{} comes to the end of a storage media, it asks you to
12138 change the volume.  The built-in prompt for POSIX locale
12139 is@footnote{If you run @GNUTAR{} under a different locale, the
12140 translation to the locale's language will be used.}:
12142 @smallexample
12143 Prepare volume #@var{n} for '@var{archive}' and hit return:
12144 @end smallexample
12146 @noindent
12147 where @var{n} is the ordinal number of the volume to be created and
12148 @var{archive} is archive file or device name.
12150 When prompting for a new tape, @command{tar} accepts any of the following
12151 responses:
12153 @table @kbd
12154 @item ?
12155 Request @command{tar} to explain possible responses.
12156 @item q
12157 Request @command{tar} to exit immediately.
12158 @item n @var{file-name}
12159 Request @command{tar} to write the next volume on the file @var{file-name}.
12160 @item !
12161 Request @command{tar} to run a subshell.  This option can be disabled
12162 by giving @option{--restrict} command line option to
12163 @command{tar}@footnote{@xref{--restrict}, for more information about
12164 this option.}.
12165 @item y
12166 Request @command{tar} to begin writing the next volume.
12167 @end table
12169 (You should only type @samp{y} after you have changed the tape;
12170 otherwise @command{tar} will write over the volume it just finished.)
12172 @cindex Volume number file
12173 @cindex volno file
12174 @anchor{volno-file}
12175 @opindex volno-file
12176 The volume number used by @command{tar} in its tape-changing prompt
12177 can be changed; if you give the
12178 @option{--volno-file=@var{file-of-number}} option, then
12179 @var{file-of-number} should be an non-existing file to be created, or
12180 else, a file already containing a decimal number.  That number will be
12181 used as the volume number of the first volume written.  When
12182 @command{tar} is finished, it will rewrite the file with the
12183 now-current volume number. (This does not change the volume number
12184 written on a tape label, as per @ref{label}, it @emph{only} affects
12185 the number used in the prompt.)
12187 @cindex End-of-archive info script
12188 @cindex Info script
12189 @anchor{info-script}
12190 @opindex info-script
12191 @opindex new-volume-script
12192 If you want more elaborate behavior than this, you can write a special
12193 @dfn{new volume script}, that will be responsible for changing the
12194 volume, and instruct @command{tar} to use it instead of its normal
12195 prompting procedure:
12197 @table @option
12198 @item --info-script=@var{command}
12199 @itemx --new-volume-script=@var{command}
12200 @itemx -F @var{command}
12201 Specify the command to invoke when switching volumes.  The @var{command}
12202 can be used to eject cassettes, or to broadcast messages such as
12203 @samp{Someone please come change my tape} when performing unattended
12204 backups.
12205 @end table
12207 The @var{command} can contain additional options, if such are needed.
12208 @xref{external, Running External Commands}, for a detailed discussion
12209 of the way @GNUTAR{} runs external commands.  It inherits
12210 @command{tar}'s shell environment.  Additional data is passed to it
12211 via the following environment variables:
12213 @table @env
12214 @vrindex TAR_VERSION, info script environment variable
12215 @item TAR_VERSION
12216 @GNUTAR{} version number.
12218 @vrindex TAR_ARCHIVE, info script environment variable
12219 @item TAR_ARCHIVE
12220 The name of the archive @command{tar} is processing.
12222 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
12223 @item TAR_BLOCKING_FACTOR
12224 Current blocking factor (@pxref{Blocking}).
12226 @vrindex TAR_VOLUME, info script environment variable
12227 @item TAR_VOLUME
12228 Ordinal number of the volume @command{tar} is about to start.
12230 @vrindex TAR_SUBCOMMAND, info script environment variable
12231 @item TAR_SUBCOMMAND
12232 A short option describing the operation @command{tar} is executing.
12233 @xref{Operations}, for a complete list of subcommand options.
12235 @vrindex TAR_FORMAT, info script environment variable
12236 @item TAR_FORMAT
12237 Format of the archive being processed. @xref{Formats}, for a complete
12238 list of archive format names.
12240 @vrindex TAR_FD, info script environment variable
12241 @item TAR_FD
12242 File descriptor which can be used to communicate the new volume
12243 name to @command{tar}.
12244 @end table
12246 These variables can be used in the @var{command} itself, provided that
12247 they are properly quoted to prevent them from being expanded by the
12248 shell that invokes @command{tar}.
12250 The volume script can instruct @command{tar} to use new archive name,
12251 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
12253 If the info script fails, @command{tar} exits; otherwise, it begins
12254 writing the next volume.
12256 If you want @command{tar} to cycle through a series of files or tape
12257 drives, there are three approaches to choose from.  First of all, you
12258 can give @command{tar} multiple @option{--file} options.  In this case
12259 the specified files will be used, in sequence, as the successive
12260 volumes of the archive.  Only when the first one in the sequence needs
12261 to be used again will @command{tar} prompt for a tape change (or run
12262 the info script).  For example, suppose someone has two tape drives on
12263 a system named @file{/dev/tape0} and @file{/dev/tape1}.  For having
12264 @GNUTAR{} to switch to the second drive when it needs to write the
12265 second tape, and then back to the first tape, etc., just do either of:
12267 @smallexample
12268 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
12269 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
12270 @end smallexample
12272 The second method is to use the @samp{n} response to the tape-change
12273 prompt.
12275 Finally, the most flexible approach is to use a volume script, that
12276 writes new archive name to the file descriptor @env{$TAR_FD}.  For example, the
12277 following volume script will create a series of archive files, named
12278 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
12279 archive being created (as given by @option{--file} option) and
12280 @var{vol} is the ordinal number of the archive being created:
12282 @smallexample
12283 @group
12284 #! /bin/bash
12285 # For this script it's advisable to use a shell, such as Bash,
12286 # that supports a TAR_FD value greater than 9.
12288 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
12290 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
12291 case $TAR_SUBCOMMAND in
12292 -c)       ;;
12293 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
12294           ;;
12295 *)        exit 1
12296 esac
12298 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
12299 @end group
12300 @end smallexample
12302 The same script can be used while listing, comparing or extracting
12303 from the created archive.  For example:
12305 @smallexample
12306 @group
12307 # @r{Create a multi-volume archive:}
12308 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
12309 # @r{Extract from the created archive:}
12310 $ @kbd{tar -x -f archive.tar -F new-volume .}
12311 @end group
12312 @end smallexample
12314 @noindent
12315 Notice, that the first command had to use @option{-L} option, since
12316 otherwise @GNUTAR{} will end up writing everything to file
12317 @file{archive.tar}.
12319 You can read each individual volume of a multi-volume archive as if it
12320 were an archive by itself.  For example, to list the contents of one
12321 volume, use @option{--list}, without @option{--multi-volume} specified.
12322 To extract an archive member from one volume (assuming it is described
12323 that volume), use @option{--extract}, again without
12324 @option{--multi-volume}.
12326 If an archive member is split across volumes (i.e., its entry begins on
12327 one volume of the media and ends on another), you need to specify
12328 @option{--multi-volume} to extract it successfully.  In this case, you
12329 should load the volume where the archive member starts, and use
12330 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
12331 volumes as it needs them.  @xref{extracting archives}, for more
12332 information about extracting archives.
12334 Multi-volume archives can be modified like any other archive.  To add
12335 files to a multi-volume archive, you need to only mount the last
12336 volume of the archive media (and new volumes, if needed).  For all
12337 other operations, you need to use the entire archive.
12339 If a multi-volume archive was labeled using
12340 @option{--label=@var{archive-label}} (@pxref{label}) when it was
12341 created, @command{tar} will not automatically label volumes which are
12342 added later.  To label subsequent volumes, specify
12343 @option{--label=@var{archive-label}} again in conjunction with the
12344 @option{--append}, @option{--update} or @option{--concatenate} operation.
12346 Notice that multi-volume support is a GNU extension and the archives
12347 created in this mode should be read only using @GNUTAR{}.  If you
12348 absolutely have to process such archives using a third-party @command{tar}
12349 implementation, read @ref{Split Recovery}.
12351 @node Tape Files
12352 @subsection Tape Files
12353 @cindex labeling archives
12354 @opindex label
12355 @UNREVISED
12357 To give the archive a name which will be recorded in it, use the
12358 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
12359 option.  This will write a special block identifying
12360 @var{volume-label} as the name of the archive to the front of the
12361 archive which will be displayed when the archive is listed with
12362 @option{--list}.  If you are creating a multi-volume archive with
12363 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
12364 volume label will have @samp{Volume @var{nnn}} appended to the name
12365 you give, where @var{nnn} is the number of the volume of the archive.
12366 If you use the @option{--label=@var{volume-label}} option when
12367 reading an archive, it checks to make sure the label on the tape
12368 matches the one you gave.  @xref{label}.
12370 When @command{tar} writes an archive to tape, it creates a single
12371 tape file.  If multiple archives are written to the same tape, one
12372 after the other, they each get written as separate tape files.  When
12373 extracting, it is necessary to position the tape at the right place
12374 before running @command{tar}.  To do this, use the @command{mt} command.
12375 For more information on the @command{mt} command and on the organization
12376 of tapes into a sequence of tape files, see @ref{mt}.
12378 People seem to often do:
12380 @smallexample
12381 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
12382 @end smallexample
12384 or such, for pushing a common date in all volumes or an archive set.
12386 @node Tarcat
12387 @subsection Concatenate Volumes into a Single Archive
12389 @pindex tarcat
12390   Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
12391 archive to a single @command{tar} archive.  Simply concatenating all
12392 volumes into one will not work, since each volume carries an additional
12393 information at the beginning.  @GNUTAR{} is shipped with the shell
12394 script @command{tarcat} designed for this purpose.
12396   The script takes a list of files comprising a multi-volume archive
12397 and creates the resulting archive at the standard output.  For example:
12399 @smallexample
12400 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
12401 @end smallexample
12403   The script implements a simple heuristics to determine the format of
12404 the first volume file and to decide how to process the rest of the
12405 files.  However, it makes no attempt to verify whether the files are
12406 given in order or even if they are valid @command{tar} archives.
12407 It uses @command{dd} and does not filter its standard error, so you
12408 will usually see lots of spurious messages.
12410 @FIXME{The script is not installed.  Should we install it?}
12412 @node label
12413 @section Including a Label in the Archive
12414 @cindex Labeling an archive
12415 @cindex Labels on the archive media
12416 @cindex Labeling multi-volume archives
12418 @opindex label
12419   To avoid problems caused by misplaced paper labels on the archive
12420 media, you can include a @dfn{label} entry --- an archive member which
12421 contains the name of the archive --- in the archive itself.  Use the
12422 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12423 option@footnote{Until version 1.10, that option was called
12424 @option{--volume}, but is not available under that name anymore.} in
12425 conjunction with the @option{--create} operation to include a label
12426 entry in the archive as it is being created.
12428 @table @option
12429 @item --label=@var{archive-label}
12430 @itemx -V @var{archive-label}
12431 Includes an @dfn{archive-label} at the beginning of the archive when
12432 the archive is being created, when used in conjunction with the
12433 @option{--create} operation.  Checks to make sure the archive label
12434 matches the one specified (when used in conjunction with any other
12435 operation).
12436 @end table
12438   If you create an archive using both
12439 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
12440 and @option{--multi-volume} (@option{-M}), each volume of the archive
12441 will have an archive label of the form @samp{@var{archive-label}
12442 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
12443 next, and so on. @xref{Using Multiple Tapes}, for information on
12444 creating multiple volume archives.
12446 @cindex Volume label, listing
12447 @cindex Listing volume label
12448   The volume label will be displayed by @option{--list} along with
12449 the file contents.  If verbose display is requested, it will also be
12450 explicitly marked as in the example below:
12452 @smallexample
12453 @group
12454 $ @kbd{tar --verbose --list --file=iamanarchive}
12455 V--------- 0/0               0 1992-03-07 12:01 iamalabel--Volume Header--
12456 -rw-r--r-- ringo/user       40 1990-05-21 13:30 iamafilename
12457 @end group
12458 @end smallexample
12460 @opindex test-label
12461 @anchor{--test-label option}
12462   However, @option{--list} option will cause listing entire
12463 contents of the archive, which may be undesirable (for example, if the
12464 archive is stored on a tape).  You can request checking only the volume
12465 label by specifying @option{--test-label} option.  This option reads only the
12466 first block of an archive, so it can be used with slow storage
12467 devices.  For example:
12469 @smallexample
12470 @group
12471 $ @kbd{tar --test-label --file=iamanarchive}
12472 iamalabel
12473 @end group
12474 @end smallexample
12476   If @option{--test-label} is used with one or more command line
12477 arguments, @command{tar} compares the volume label with each
12478 argument.  It exits with code 0 if a match is found, and with code 1
12479 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
12480 mismatch with an exit code 2 and printed a spurious diagnostics on
12481 stderr.}.  No output is displayed, unless you also used the
12482 @option{--verbose} option.  For example:
12484 @smallexample
12485 @group
12486 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
12487 @result{} 0
12488 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
12489 @result{} 1
12490 @end group
12491 @end smallexample
12493   When used with the @option{--verbose} option, @command{tar}
12494 prints the actual volume label (if any), and a verbose diagnostics in
12495 case of a mismatch:
12497 @smallexample
12498 @group
12499 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
12500 iamalabel
12501 @result{} 0
12502 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
12503 iamalabel
12504 tar: Archive label mismatch
12505 @result{} 1
12506 @end group
12507 @end smallexample
12509   If you request any operation, other than @option{--create}, along
12510 with using @option{--label} option, @command{tar} will first check if
12511 the archive label matches the one specified and will refuse to proceed
12512 if it does not.  Use this as a safety precaution to avoid accidentally
12513 overwriting existing archives.  For example, if you wish to add files
12514 to @file{archive}, presumably labeled with string @samp{My volume},
12515 you will get:
12517 @smallexample
12518 @group
12519 $ @kbd{tar -rf archive --label 'My volume' .}
12520 tar: Archive not labeled to match 'My volume'
12521 @end group
12522 @end smallexample
12524 @noindent
12525 in case its label does not match.  This will work even if
12526 @file{archive} is not labeled at all.
12528   Similarly, @command{tar} will refuse to list or extract the
12529 archive if its label doesn't match the @var{archive-label}
12530 specified.  In those cases, @var{archive-label} argument is interpreted
12531 as a globbing-style pattern which must match the actual magnetic
12532 volume label.  @xref{exclude}, for a precise description of how match
12533 is attempted@footnote{Previous versions of @command{tar} used full
12534 regular expression matching, or before that, only exact string
12535 matching, instead of wildcard matchers.  We decided for the sake of
12536 simplicity to use a uniform matching device through
12537 @command{tar}.}.  If the switch @option{--multi-volume} (@option{-M}) is being used,
12538 the volume label matcher will also suffix @var{archive-label} by
12539 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
12540 up.  Since the volume numbering is automatically added in labels at
12541 creation time, it sounded logical to equally help the user taking care
12542 of it when the archive is being read.
12544   You can also use @option{--label} to get a common information on
12545 all tapes of a series.  For having this information different in each
12546 series created through a single script used on a regular basis, just
12547 manage to get some date string as part of the label.  For example:
12549 @smallexample
12550 @group
12551 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
12552 $ @kbd{tar --create --file=/dev/tape --multi-volume \
12553      --label="Daily backup for `date +%Y-%m-%d`"}
12554 @end group
12555 @end smallexample
12557   Some more notes about volume labels:
12559 @itemize @bullet
12560 @item Each label has its own date and time, which corresponds
12561 to the time when @GNUTAR{} initially attempted to write it,
12562 often soon after the operator launches @command{tar} or types the
12563 carriage return telling that the next tape is ready.
12565 @item Comparing date labels to get an idea of tape throughput is
12566 unreliable.  It gives correct results only if the delays for rewinding
12567 tapes and the operator switching them were negligible, which is
12568 usually not the case.
12569 @end itemize
12571 @node verify
12572 @section Verifying Data as It is Stored
12573 @cindex Verifying a write operation
12574 @cindex Double-checking a write operation
12576 @table @option
12577 @item -W
12578 @itemx --verify
12579 @opindex verify, short description
12580 Attempt to verify the archive after writing.
12581 @end table
12583 This option causes @command{tar} to verify the archive after writing it.
12584 Each volume is checked after it is written, and any discrepancies
12585 are recorded on the standard error output.
12587 Verification requires that the archive be on a back-space-able medium.
12588 This means pipes, some cartridge tape drives, and some other devices
12589 cannot be verified.
12591 You can insure the accuracy of an archive by comparing files in the
12592 system with archive members.  @command{tar} can compare an archive to the
12593 file system as the archive is being written, to verify a write
12594 operation, or can compare a previously written archive, to insure that
12595 it is up to date.
12597 @xopindex{verify, using with @option{--create}}
12598 @xopindex{create, using with @option{--verify}}
12599 To check for discrepancies in an archive immediately after it is
12600 written, use the @option{--verify} (@option{-W}) option in conjunction with
12601 the @option{--create} operation.  When this option is
12602 specified, @command{tar} checks archive members against their counterparts
12603 in the file system, and reports discrepancies on the standard error.
12605 To verify an archive, you must be able to read it from before the end
12606 of the last written entry.  This option is useful for detecting data
12607 errors on some tapes.  Archives written to pipes, some cartridge tape
12608 drives, and some other devices cannot be verified.
12610 One can explicitly compare an already made archive with the file
12611 system by using the @option{--compare} (@option{--diff}, @option{-d})
12612 option, instead of using the more automatic @option{--verify} option.
12613 @xref{compare}.
12615 Note that these two options have a slightly different intent.  The
12616 @option{--compare} option checks how identical are the logical contents of some
12617 archive with what is on your disks, while the @option{--verify} option is
12618 really for checking if the physical contents agree and if the recording
12619 media itself is of dependable quality.  So, for the @option{--verify}
12620 operation, @command{tar} tries to defeat all in-memory cache pertaining to
12621 the archive, while it lets the speed optimization undisturbed for the
12622 @option{--compare} option.  If you nevertheless use @option{--compare} for
12623 media verification, you may have to defeat the in-memory cache yourself,
12624 maybe by opening and reclosing the door latch of your recording unit,
12625 forcing some doubt in your operating system about the fact this is really
12626 the same volume as the one just written or read.
12628 The @option{--verify} option would not be necessary if drivers were indeed
12629 able to detect dependably all write failures.  This sometimes require many
12630 magnetic heads, some able to read after the writes occurred.  One would
12631 not say that drivers unable to detect all cases are necessarily flawed,
12632 as long as programming is concerned.
12634 The @option{--verify} (@option{-W}) option will not work in
12635 conjunction with the @option{--multi-volume} (@option{-M}) option or
12636 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
12637 and @option{--delete} operations.  @xref{Operations}, for more
12638 information on these operations.
12640 Also, since @command{tar} normally strips leading @samp{/} from file
12641 names (@pxref{absolute}), a command like @samp{tar --verify -cf
12642 /tmp/foo.tar /etc} will work as desired only if the working directory is
12643 @file{/}, as @command{tar} uses the archive's relative member names
12644 (e.g., @file{etc/motd}) when verifying the archive.
12646 @node Write Protection
12647 @section Write Protection
12649 Almost all tapes and diskettes, and in a few rare cases, even disks can
12650 be @dfn{write protected}, to protect data on them from being changed.
12651 Once an archive is written, you should write protect the media to prevent
12652 the archive from being accidentally overwritten or deleted.  (This will
12653 protect the archive from being changed with a tape or floppy drive---it
12654 will not protect it from magnet fields or other physical hazards.)
12656 The write protection device itself is usually an integral part of the
12657 physical media, and can be a two position (write enabled/write
12658 disabled) switch, a notch which can be popped out or covered, a ring
12659 which can be removed from the center of a tape reel, or some other
12660 changeable feature.
12662 @node Reliability and security
12663 @chapter Reliability and Security
12665 The @command{tar} command reads and writes files as any other
12666 application does, and is subject to the usual caveats about
12667 reliability and security.  This section contains some commonsense
12668 advice on the topic.
12670 @menu
12671 * Reliability::
12672 * Security::
12673 @end menu
12675 @node Reliability
12676 @section Reliability
12678 Ideally, when @command{tar} is creating an archive, it reads from a
12679 file system that is not being modified, and encounters no errors or
12680 inconsistencies while reading and writing.  If this is the case, the
12681 archive should faithfully reflect what was read.  Similarly, when
12682 extracting from an archive, ideally @command{tar} ideally encounters
12683 no errors and the extracted files faithfully reflect what was in the
12684 archive.
12686 However, when reading or writing real-world file systems, several
12687 things can go wrong; these include permissions problems, corruption of
12688 data, and race conditions.
12690 @menu
12691 * Permissions problems::
12692 * Data corruption and repair::
12693 * Race conditions::
12694 @end menu
12696 @node Permissions problems
12697 @subsection Permissions Problems
12699 If @command{tar} encounters errors while reading or writing files, it
12700 normally reports an error and exits with nonzero status.  The work it
12701 does may therefore be incomplete.  For example, when creating an
12702 archive, if @command{tar} cannot read a file then it cannot copy the
12703 file into the archive.
12705 @node Data corruption and repair
12706 @subsection Data Corruption and Repair
12708 If an archive becomes corrupted by an I/O error, this may corrupt the
12709 data in an extracted file.  Worse, it may corrupt the file's metadata,
12710 which may cause later parts of the archive to become misinterpreted.
12711 An tar-format archive contains a checksum that most likely will detect
12712 errors in the metadata, but it will not detect errors in the data.
12714 If data corruption is a concern, you can compute and check your own
12715 checksums of an archive by using other programs, such as
12716 @command{cksum}.
12718 When attempting to recover from a read error or data corruption in an
12719 archive, you may need to skip past the questionable data and read the
12720 rest of the archive.  This requires some expertise in the archive
12721 format and in other software tools.
12723 @node Race conditions
12724 @subsection Race conditions
12726 If some other process is modifying the file system while @command{tar}
12727 is reading or writing files, the result may well be inconsistent due
12728 to race conditions.  For example, if another process creates some
12729 files in a directory while @command{tar} is creating an archive
12730 containing the directory's files, @command{tar} may see some of the
12731 files but not others, or it may see a file that is in the process of
12732 being created.  The resulting archive may not be a snapshot of the
12733 file system at any point in time.  If an application such as a
12734 database system depends on an accurate snapshot, restoring from the
12735 @command{tar} archive of a live file system may therefore break that
12736 consistency and may break the application.  The simplest way to avoid
12737 the consistency issues is to avoid making other changes to the file
12738 system while tar is reading it or writing it.
12740 When creating an archive, several options are available to avoid race
12741 conditions.  Some hosts have a way of snapshotting a file system, or
12742 of temporarily suspending all changes to a file system, by (say)
12743 suspending the only virtual machine that can modify a file system; if
12744 you use these facilities and have @command{tar -c} read from a
12745 snapshot when creating an archive, you can avoid inconsistency
12746 problems.  More drastically, before starting @command{tar} you could
12747 suspend or shut down all processes other than @command{tar} that have
12748 access to the file system, or you could unmount the file system and
12749 then mount it read-only.
12751 When extracting from an archive, one approach to avoid race conditions
12752 is to create a directory that no other process can write to, and
12753 extract into that.
12755 @node Security
12756 @section Security
12758 In some cases @command{tar} may be used in an adversarial situation,
12759 where an untrusted user is attempting to gain information about or
12760 modify otherwise-inaccessible files.  Dealing with untrusted data
12761 (that is, data generated by an untrusted user) typically requires
12762 extra care, because even the smallest mistake in the use of
12763 @command{tar} is more likely to be exploited by an adversary than by a
12764 race condition.
12766 @menu
12767 * Privacy::
12768 * Integrity::
12769 * Live untrusted data::
12770 * Security rules of thumb::
12771 @end menu
12773 @node Privacy
12774 @subsection Privacy
12776 Standard privacy concerns apply when using @command{tar}.  For
12777 example, suppose you are archiving your home directory into a file
12778 @file{/archive/myhome.tar}.  Any secret information in your home
12779 directory, such as your SSH secret keys, are copied faithfully into
12780 the archive.  Therefore, if your home directory contains any file that
12781 should not be read by some other user, the archive itself should be
12782 not be readable by that user.  And even if the archive's data are
12783 inaccessible to untrusted users, its metadata (such as size or
12784 last-modified date) may reveal some information about your home
12785 directory; if the metadata are intended to be private, the archive's
12786 parent directory should also be inaccessible to untrusted users.
12788 One precaution is to create @file{/archive} so that it is not
12789 accessible to any user, unless that user also has permission to access
12790 all the files in your home directory.
12792 Similarly, when extracting from an archive, take care that the
12793 permissions of the extracted files are not more generous than what you
12794 want.  Even if the archive itself is readable only to you, files
12795 extracted from it have their own permissions that may differ.
12797 @node Integrity
12798 @subsection Integrity
12800 When creating archives, take care that they are not writable by a
12801 untrusted user; otherwise, that user could modify the archive, and
12802 when you later extract from the archive you will get incorrect data.
12804 When @command{tar} extracts from an archive, by default it writes into
12805 files relative to the working directory.  If the archive was generated
12806 by an untrusted user, that user therefore can write into any file
12807 under the working directory.  If the working directory contains a
12808 symbolic link to another directory, the untrusted user can also write
12809 into any file under the referenced directory.  When extracting from an
12810 untrusted archive, it is therefore good practice to create an empty
12811 directory and run @command{tar} in that directory.
12813 When extracting from two or more untrusted archives, each one should
12814 be extracted independently, into different empty directories.
12815 Otherwise, the first archive could create a symbolic link into an area
12816 outside the working directory, and the second one could follow the
12817 link and overwrite data that is not under the working directory.  For
12818 example, when restoring from a series of incremental dumps, the
12819 archives should have been created by a trusted process, as otherwise
12820 the incremental restores might alter data outside the working
12821 directory.
12823 If you use the @option{--absolute-names} (@option{-P}) option when
12824 extracting, @command{tar} respects any file names in the archive, even
12825 file names that begin with @file{/} or contain @file{..}.  As this
12826 lets the archive overwrite any file in your system that you can write,
12827 the @option{--absolute-names} (@option{-P}) option should be used only
12828 for trusted archives.
12830 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12831 @option{--skip-old-files} options, @command{tar} refuses to replace
12832 existing files when extracting.  The difference between the two
12833 options is that the former treats existing files as errors whereas the
12834 latter just silently ignores them.
12836 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12837 refuses to replace the permissions or ownership of already-existing
12838 directories.  These options may help when extracting from untrusted
12839 archives.
12841 @node Live untrusted data
12842 @subsection Dealing with Live Untrusted Data
12844 Extra care is required when creating from or extracting into a file
12845 system that is accessible to untrusted users.  For example, superusers
12846 who invoke @command{tar} must be wary about its actions being hijacked
12847 by an adversary who is reading or writing the file system at the same
12848 time that @command{tar} is operating.
12850 When creating an archive from a live file system, @command{tar} is
12851 vulnerable to denial-of-service attacks.  For example, an adversarial
12852 user could create the illusion of an indefinitely-deep directory
12853 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12854 @command{tar}, or the illusion of an indefinitely-long file by
12855 creating a sparse file but arranging for blocks to be allocated just
12856 before @command{tar} reads them.  There is no easy way for
12857 @command{tar} to distinguish these scenarios from legitimate uses, so
12858 you may need to monitor @command{tar}, just as you'd need to monitor
12859 any other system service, to detect such attacks.
12861 While a superuser is extracting from an archive into a live file
12862 system, an untrusted user might replace a directory with a symbolic
12863 link, in hopes that @command{tar} will follow the symbolic link and
12864 extract data into files that the untrusted user does not have access
12865 to.  Even if the archive was generated by the superuser, it may
12866 contain a file such as @file{d/etc/passwd} that the untrusted user
12867 earlier created in order to break in; if the untrusted user replaces
12868 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12869 @command{tar} is running, @command{tar} will overwrite
12870 @file{/etc/passwd}.  This attack can be prevented by extracting into a
12871 directory that is inaccessible to untrusted users.
12873 Similar attacks via symbolic links are also possible when creating an
12874 archive, if the untrusted user can modify an ancestor of a top-level
12875 argument of @command{tar}.  For example, an untrusted user that can
12876 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12877 - /home/eve/Documents/yesterday} by replacing
12878 @file{/home/eve/Documents} with a symbolic link to some other
12879 location.  Attacks like these can be prevented by making sure that
12880 untrusted users cannot modify any files that are top-level arguments
12881 to @command{tar}, or any ancestor directories of these files.
12883 @node Security rules of thumb
12884 @subsection Security Rules of Thumb
12886 This section briefly summarizes rules of thumb for avoiding security
12887 pitfalls.
12889 @itemize @bullet
12891 @item
12892 Protect archives at least as much as you protect any of the files
12893 being archived.
12895 @item
12896 Extract from an untrusted archive only into an otherwise-empty
12897 directory.  This directory and its parent should be accessible only to
12898 trusted users.  For example:
12900 @example
12901 @group
12902 $ @kbd{chmod go-rwx .}
12903 $ @kbd{mkdir -m go-rwx dir}
12904 $ @kbd{cd dir}
12905 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12906 @end group
12907 @end example
12909 As a corollary, do not do an incremental restore from an untrusted archive.
12911 @item
12912 Do not let untrusted users access files extracted from untrusted
12913 archives without checking first for problems such as setuid programs.
12915 @item
12916 Do not let untrusted users modify directories that are ancestors of
12917 top-level arguments of @command{tar}.  For example, while you are
12918 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12919 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12921 @item
12922 Pay attention to the diagnostics and exit status of @command{tar}.
12924 @item
12925 When archiving live file systems, monitor running instances of
12926 @command{tar} to detect denial-of-service attacks.
12928 @item
12929 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12930 @option{--dereference} (@option{-h}), @option{--overwrite},
12931 @option{--recursive-unlink}, and @option{--remove-files} unless you
12932 understand their security implications.
12934 @end itemize
12936 @node Changes
12937 @appendix Changes
12939 This appendix lists some important user-visible changes between
12940 various versions of @GNUTAR{}. An up-to-date version of this document
12941 is available at
12942 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12943 @GNUTAR{} documentation page}.
12945 @table @asis
12946 @item Use of globbing patterns when listing and extracting.
12948 Previous versions of GNU tar assumed shell-style globbing when
12949 extracting from or listing an archive.  For example:
12951 @smallexample
12952 $ @kbd{tar xf foo.tar '*.c'}
12953 @end smallexample
12955 would extract all files whose names end in @samp{.c}.  This behavior
12956 was not documented and was incompatible with traditional tar
12957 implementations.  Therefore, starting from version 1.15.91, GNU tar
12958 no longer uses globbing by default.  For example, the above invocation
12959 is now interpreted as a request to extract from the archive the file
12960 named @file{*.c}.
12962 To facilitate transition to the new behavior for those users who got
12963 used to the previous incorrect one, @command{tar} will print a warning
12964 if it finds out that a requested member was not found in the archive
12965 and its name looks like a globbing pattern.  For example:
12967 @smallexample
12968 $ @kbd{tar xf foo.tar  '*.c'}
12969 tar: Pattern matching characters used in file names. Please,
12970 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12971 tar: suppress this warning.
12972 tar: *.c: Not found in archive
12973 tar: Error exit delayed from previous errors
12974 @end smallexample
12976 To treat member names as globbing patterns, use the @option{--wildcards} option.
12977 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12978 add this option to your @env{TAR_OPTIONS} variable.
12980 @xref{wildcards}, for the detailed discussion of the use of globbing
12981 patterns by @GNUTAR{}.
12983 @item Use of short option @option{-o}.
12985 Earlier versions of @GNUTAR{} understood @option{-o} command line
12986 option as a synonym for @option{--old-archive}.
12988 @GNUTAR{} starting from version 1.13.90 understands this option as
12989 a synonym for @option{--no-same-owner}.  This is compatible with
12990 UNIX98 @command{tar} implementations.
12992 However, to facilitate transition, @option{-o} option retains its
12993 old semantics when it is used with one of archive-creation commands.
12994 Users are encouraged to use @option{--format=oldgnu} instead.
12996 It is especially important, since versions of @acronym{GNU} Automake
12997 up to and including 1.8.4 invoke tar with this option to produce
12998 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
12999 of this issue and its implications.
13001 @xref{Options, tar-formats, Changing Automake's Behavior,
13002 automake, GNU Automake}, for a description on how to use various
13003 archive formats with @command{automake}.
13005 Future versions of @GNUTAR{} will understand @option{-o} only as a
13006 synonym for @option{--no-same-owner}.
13008 @item Use of short option @option{-l}
13010 Earlier versions of @GNUTAR{} understood @option{-l} option as a
13011 synonym for @option{--one-file-system}.  Since such usage contradicted
13012 to UNIX98 specification and harmed compatibility with other
13013 implementations, it was declared deprecated in version 1.14.  However,
13014 to facilitate transition to its new semantics, it was supported by
13015 versions 1.15 and 1.15.90.  The present use of @option{-l} as a short
13016 variant of @option{--check-links} was introduced in version 1.15.91.
13018 @item Use of options @option{--portability} and @option{--old-archive}
13020 These options are deprecated.  Please use @option{--format=v7} instead.
13022 @item Use of option @option{--posix}
13024 This option is deprecated.  Please use @option{--format=posix} instead.
13025 @end table
13027 @node Recipes
13028 @appendix Recipes
13029 @include recipes.texi
13031 @node Configuring Help Summary
13032 @appendix Configuring Help Summary
13034 Running @kbd{tar --help} displays the short @command{tar} option
13035 summary (@pxref{help}). This summary is organized by @dfn{groups} of
13036 semantically close options. The options within each group are printed
13037 in the following order: a short option, eventually followed by a list
13038 of corresponding long option names, followed by a short description of
13039 the option. For example, here is an excerpt from the actual @kbd{tar
13040 --help} output:
13042 @verbatim
13043  Main operation mode:
13045   -A, --catenate, --concatenate   append tar files to an archive
13046   -c, --create               create a new archive
13047   -d, --diff, --compare      find differences between archive and
13048                              file system
13049       --delete               delete from the archive
13050 @end verbatim
13052 @vrindex ARGP_HELP_FMT, environment variable
13053 The exact visual representation of the help output is configurable via
13054 @env{ARGP_HELP_FMT} environment variable. The value of this variable
13055 is a comma-separated list of @dfn{format variable} assignments. There
13056 are two kinds of format variables. An @dfn{offset variable} keeps the
13057 offset of some part of help output text from the leftmost column on
13058 the screen. A @dfn{boolean} variable is a flag that toggles some
13059 output feature on or off. Depending on the type of the corresponding
13060 variable, there are two kinds of assignments:
13062 @table @asis
13063 @item Offset assignment
13065 The assignment to an offset variable has the following syntax:
13067 @smallexample
13068 @var{variable}=@var{value}
13069 @end smallexample
13071 @noindent
13072 where @var{variable} is the variable name, and @var{value} is a
13073 numeric value to be assigned to the variable.
13075 @item Boolean assignment
13077 To assign @code{true} value to a variable, simply put this variable name. To
13078 assign @code{false} value, prefix the variable name with @samp{no-}. For
13079 example:
13081 @smallexample
13082 @group
13083 # Assign @code{true} value:
13084 dup-args
13085 # Assign @code{false} value:
13086 no-dup-args
13087 @end group
13088 @end smallexample
13089 @end table
13091 Following variables are declared:
13093 @deftypevr {Help Output} boolean dup-args
13094 If true, arguments for an option are shown with both short and long
13095 options, even when a given option has both forms, for example:
13097 @smallexample
13098   -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
13099 @end smallexample
13101 If false, then if an option has both short and long forms, the
13102 argument is only shown with the long one, for example:
13104 @smallexample
13105   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13106 @end smallexample
13108 @noindent
13109 and a message indicating that the argument is applicable to both
13110 forms is printed below the options. This message can be disabled
13111 using @code{dup-args-note} (see below).
13113 The default is false.
13114 @end deftypevr
13116 @deftypevr {Help Output} boolean dup-args-note
13117 If this variable is true, which is the default, the following notice
13118 is displayed at the end of the help output:
13120 @quotation
13121 Mandatory or optional arguments to long options are also mandatory or
13122 optional for any corresponding short options.
13123 @end quotation
13125 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
13126 variables @code{dup-args} or @code{dup-args-note} should be set.
13127 @end deftypevr
13129 @deftypevr {Help Output} offset short-opt-col
13130 Column in which short options start. Default is 2.
13132 @smallexample
13133 @group
13134 $ @kbd{tar --help|grep ARCHIVE}
13135   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13136 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
13137       -f, --file=ARCHIVE   use archive file or device ARCHIVE
13138 @end group
13139 @end smallexample
13140 @end deftypevr
13142 @deftypevr {Help Output} offset long-opt-col
13143 Column in which long options start. Default is 6. For example:
13145 @smallexample
13146 @group
13147 $ @kbd{tar --help|grep ARCHIVE}
13148   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13149 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
13150   -f,           --file=ARCHIVE   use archive file or device ARCHIVE
13151 @end group
13152 @end smallexample
13153 @end deftypevr
13155 @deftypevr {Help Output} offset doc-opt-col
13156 Column in which @dfn{doc options} start.  A doc option isn't actually
13157 an option, but rather an arbitrary piece of documentation that is
13158 displayed in much the same manner as the options.  For example, in
13159 the description of @option{--format} option:
13161 @smallexample
13162 @group
13163   -H, --format=FORMAT        create archive of the given format.
13165  FORMAT is one of the following:
13167     gnu                      GNU tar 1.13.x format
13168     oldgnu                   GNU format as per tar <= 1.12
13169     pax                      POSIX 1003.1-2001 (pax) format
13170     posix                    same as pax
13171     ustar                    POSIX 1003.1-1988 (ustar) format
13172     v7                       old V7 tar format
13173 @end group
13174 @end smallexample
13176 @noindent
13177 the format names are doc options. Thus, if you set
13178 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
13179 will look as follows:
13181 @smallexample
13182 @group
13183   -H, --format=FORMAT        create archive of the given format.
13185  FORMAT is one of the following:
13187         gnu                      GNU tar 1.13.x format
13188         oldgnu                   GNU format as per tar <= 1.12
13189         pax                      POSIX 1003.1-2001 (pax) format
13190         posix                    same as pax
13191         ustar                    POSIX 1003.1-1988 (ustar) format
13192         v7                       old V7 tar format
13193 @end group
13194 @end smallexample
13195 @end deftypevr
13197 @deftypevr {Help Output} offset opt-doc-col
13198 Column in which option description starts. Default is 29.
13200 @smallexample
13201 @group
13202 $ @kbd{tar --help|grep ARCHIVE}
13203   -f, --file=ARCHIVE         use archive file or device ARCHIVE
13204 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
13205   -f, --file=ARCHIVE   use archive file or device ARCHIVE
13206 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
13207   -f, --file=ARCHIVE
13208            use archive file or device ARCHIVE
13209 @end group
13210 @end smallexample
13212 @noindent
13213 Notice, that the description starts on a separate line if
13214 @code{opt-doc-col} value is too small.
13215 @end deftypevr
13217 @deftypevr {Help Output} offset header-col
13218 Column in which @dfn{group headers} are printed.  A group header is a
13219 descriptive text preceding an option group.  For example, in the
13220 following text:
13222 @verbatim
13223  Main operation mode:
13225   -A, --catenate, --concatenate   append tar files to
13226                              an archive
13227   -c, --create               create a new archive
13228 @end verbatim
13229 @noindent
13230 @samp{Main operation mode:} is the group header.
13232 The default value is 1.
13233 @end deftypevr
13235 @deftypevr {Help Output} offset usage-indent
13236 Indentation of wrapped usage lines. Affects @option{--usage}
13237 output. Default is 12.
13238 @end deftypevr
13240 @deftypevr {Help Output} offset rmargin
13241 Right margin of the text output. Used for wrapping.
13242 @end deftypevr
13244 @node Fixing Snapshot Files
13245 @appendix Fixing Snapshot Files
13246 @include tar-snapshot-edit.texi
13248 @node Tar Internals
13249 @appendix Tar Internals
13250 @include intern.texi
13252 @node Genfile
13253 @appendix Genfile
13254 @include genfile.texi
13256 @node GNU Free Documentation License
13257 @appendix GNU Free Documentation License
13259 @include fdl.texi
13261 @node Index of Command Line Options
13262 @appendix Index of Command Line Options
13264 This appendix contains an index of all @GNUTAR{} long command line
13265 options. The options are listed without the preceding double-dash.
13266 For a cross-reference of short command line options, see
13267 @ref{Short Option Summary}.
13269 @printindex op
13271 @node Index
13272 @appendix Index
13274 @printindex cp
13276 @summarycontents
13277 @contents
13278 @bye
13280 @c Local variables:
13281 @c texinfo-column-for-description: 32
13282 @c End: