]> Dogcows Code - chaz/tar/blob - doc/tar.texi
maint: update copyrights for 2013 and as per current GNU standards
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 2.1. Run 'make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.2. Run 'make master-menu' (see comment before the master menu).
19
20 @include rendition.texi
21 @include value.texi
22
23 @defcodeindex op
24 @defcodeindex kw
25
26 @c Put everything in one index (arbitrarily chosen to be the concept index).
27 @syncodeindex fn cp
28 @syncodeindex ky cp
29 @syncodeindex pg cp
30 @syncodeindex vr cp
31 @syncodeindex kw cp
32
33 @copying
34
35 This manual is for @acronym{GNU} @command{tar} (version
36 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 from archives.
38
39 Copyright @copyright{} 1992, 1994--1997, 1999--2001, 2003--2013 Free
40 Software Foundation, Inc.
41
42 @quotation
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with the
46 Invariant Sections being ``GNU General Public License'', with the
47 Front-Cover Texts being ``A GNU Manual'', and with the Back-Cover Texts
48 as in (a) below. A copy of the license is included in the section
49 entitled ``GNU Free Documentation License''.
50
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual.''
53 @end quotation
54 @end copying
55
56 @dircategory Archiving
57 @direntry
58 * Tar: (tar). Making tape (or disk) archives.
59 @end direntry
60
61 @dircategory Individual utilities
62 @direntry
63 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
64 @end direntry
65
66 @shorttitlepage @acronym{GNU} @command{tar}
67
68 @titlepage
69 @title @acronym{GNU} tar: an archiver tool
70 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
71 @author John Gilmore, Jay Fenlason et al.
72
73 @page
74 @vskip 0pt plus 1filll
75 @insertcopying
76 @end titlepage
77
78 @ifnottex
79 @node Top
80 @top @acronym{GNU} tar: an archiver tool
81
82 @insertcopying
83
84 @cindex file archival
85 @cindex archiving files
86
87 The first part of this master menu lists the major nodes in this Info
88 document. The rest of the menu lists all the lower level nodes.
89 @end ifnottex
90
91 @c The master menu goes here.
92 @c
93 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
94 @c loaded and run texinfo-master-menu.
95 @c To update it from the command line, run
96 @c
97 @c make master-menu
98
99 @menu
100 * Introduction::
101 * Tutorial::
102 * tar invocation::
103 * operations::
104 * Backups::
105 * Choosing::
106 * Date input formats::
107 * Formats::
108 * Media::
109 * Reliability and security::
110
111 Appendices
112
113 * Changes::
114 * Configuring Help Summary::
115 * Fixing Snapshot Files::
116 * Tar Internals::
117 * Genfile::
118 * Free Software Needs Free Documentation::
119 * GNU Free Documentation License::
120 * Index of Command Line Options::
121 * Index::
122
123 @detailmenu
124 --- The Detailed Node Listing ---
125
126 Introduction
127
128 * Book Contents:: What this Book Contains
129 * Definitions:: Some Definitions
130 * What tar Does:: What @command{tar} Does
131 * Naming tar Archives:: How @command{tar} Archives are Named
132 * Authors:: @GNUTAR{} Authors
133 * Reports:: Reporting bugs or suggestions
134
135 Tutorial Introduction to @command{tar}
136
137 * assumptions::
138 * stylistic conventions::
139 * basic tar options:: Basic @command{tar} Operations and Options
140 * frequent operations::
141 * Two Frequent Options::
142 * create:: How to Create Archives
143 * list:: How to List Archives
144 * extract:: How to Extract Members from an Archive
145 * going further::
146
147 Two Frequently Used Options
148
149 * file tutorial::
150 * verbose tutorial::
151 * help tutorial::
152
153 How to Create Archives
154
155 * prepare for examples::
156 * Creating the archive::
157 * create verbose::
158 * short create::
159 * create dir::
160
161 How to List Archives
162
163 * list dir::
164
165 How to Extract Members from an Archive
166
167 * extracting archives::
168 * extracting files::
169 * extract dir::
170 * extracting untrusted archives::
171 * failing commands::
172
173 Invoking @GNUTAR{}
174
175 * Synopsis::
176 * using tar options::
177 * Styles::
178 * All Options::
179 * help::
180 * defaults::
181 * verbose::
182 * checkpoints::
183 * warnings::
184 * interactive::
185
186 The Three Option Styles
187
188 * Long Options:: Long Option Style
189 * Short Options:: Short Option Style
190 * Old Options:: Old Option Style
191 * Mixing:: Mixing Option Styles
192
193 All @command{tar} Options
194
195 * Operation Summary::
196 * Option Summary::
197 * Short Option Summary::
198
199 @GNUTAR{} Operations
200
201 * Basic tar::
202 * Advanced tar::
203 * create options::
204 * extract options::
205 * backup::
206 * Applications::
207 * looking ahead::
208
209 Advanced @GNUTAR{} Operations
210
211 * Operations::
212 * append::
213 * update::
214 * concatenate::
215 * delete::
216 * compare::
217
218 How to Add Files to Existing Archives: @option{--append}
219
220 * appending files:: Appending Files to an Archive
221 * multiple::
222
223 Updating an Archive
224
225 * how to update::
226
227 Options Used by @option{--create}
228
229 * override:: Overriding File Metadata.
230 * Ignore Failed Read::
231
232 Options Used by @option{--extract}
233
234 * Reading:: Options to Help Read Archives
235 * Writing:: Changing How @command{tar} Writes Files
236 * Scarce:: Coping with Scarce Resources
237
238 Options to Help Read Archives
239
240 * read full records::
241 * Ignore Zeros::
242
243 Changing How @command{tar} Writes Files
244
245 * Dealing with Old Files::
246 * Overwrite Old Files::
247 * Keep Old Files::
248 * Keep Newer Files::
249 * Unlink First::
250 * Recursive Unlink::
251 * Data Modification Times::
252 * Setting Access Permissions::
253 * Directory Modification Times and Permissions::
254 * Writing to Standard Output::
255 * Writing to an External Program::
256 * remove files::
257
258 Coping with Scarce Resources
259
260 * Starting File::
261 * Same Order::
262
263 Performing Backups and Restoring Files
264
265 * Full Dumps:: Using @command{tar} to Perform Full Dumps
266 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
267 * Backup Levels:: Levels of Backups
268 * Backup Parameters:: Setting Parameters for Backups and Restoration
269 * Scripted Backups:: Using the Backup Scripts
270 * Scripted Restoration:: Using the Restore Script
271
272 Setting Parameters for Backups and Restoration
273
274 * General-Purpose Variables::
275 * Magnetic Tape Control::
276 * User Hooks::
277 * backup-specs example:: An Example Text of @file{Backup-specs}
278
279 Choosing Files and Names for @command{tar}
280
281 * file:: Choosing the Archive's Name
282 * Selecting Archive Members::
283 * files:: Reading Names from a File
284 * exclude:: Excluding Some Files
285 * wildcards:: Wildcards Patterns and Matching
286 * quoting styles:: Ways of Quoting Special Characters in Names
287 * transform:: Modifying File and Member Names
288 * after:: Operating Only on New Files
289 * recurse:: Descending into Directories
290 * one:: Crossing File System Boundaries
291
292 Reading Names from a File
293
294 * nul::
295
296 Excluding Some Files
297
298 * problems with exclude::
299
300 Wildcards Patterns and Matching
301
302 * controlling pattern-matching::
303
304 Crossing File System Boundaries
305
306 * directory:: Changing Directory
307 * absolute:: Absolute File Names
308
309 Date input formats
310
311 * General date syntax:: Common rules.
312 * Calendar date items:: 19 Dec 1994.
313 * Time of day items:: 9:20pm.
314 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
315 * Day of week items:: Monday and others.
316 * Relative items in date strings:: next tuesday, 2 years ago.
317 * Pure numbers in date strings:: 19931219, 1440.
318 * Seconds since the Epoch:: @@1078100502.
319 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
320 * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
321
322 Controlling the Archive Format
323
324 * Compression:: Using Less Space through Compression
325 * Attributes:: Handling File Attributes
326 * Portability:: Making @command{tar} Archives More Portable
327 * cpio:: Comparison of @command{tar} and @command{cpio}
328
329 Using Less Space through Compression
330
331 * gzip:: Creating and Reading Compressed Archives
332 * sparse:: Archiving Sparse Files
333
334 Creating and Reading Compressed Archives
335
336 * lbzip2:: Using lbzip2 with @GNUTAR{}.
337
338 Making @command{tar} Archives More Portable
339
340 * Portable Names:: Portable Names
341 * dereference:: Symbolic Links
342 * hard links:: Hard Links
343 * old:: Old V7 Archives
344 * ustar:: Ustar Archives
345 * gnu:: GNU and old GNU format archives.
346 * posix:: @acronym{POSIX} archives
347 * Checksumming:: Checksumming Problems
348 * Large or Negative Values:: Large files, negative time stamps, etc.
349 * Other Tars:: How to Extract GNU-Specific Data Using
350 Other @command{tar} Implementations
351
352 @GNUTAR{} and @acronym{POSIX} @command{tar}
353
354 * PAX keywords:: Controlling Extended Header Keywords.
355
356 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
357
358 * Split Recovery:: Members Split Between Volumes
359 * Sparse Recovery:: Sparse Members
360
361 Tapes and Other Archive Media
362
363 * Device:: Device selection and switching
364 * Remote Tape Server::
365 * Common Problems and Solutions::
366 * Blocking:: Blocking
367 * Many:: Many archives on one tape
368 * Using Multiple Tapes:: Using Multiple Tapes
369 * label:: Including a Label in the Archive
370 * verify::
371 * Write Protection::
372
373 Blocking
374
375 * Format Variations:: Format Variations
376 * Blocking Factor:: The Blocking Factor of an Archive
377
378 Many Archives on One Tape
379
380 * Tape Positioning:: Tape Positions and Tape Marks
381 * mt:: The @command{mt} Utility
382
383 Using Multiple Tapes
384
385 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
386 * Tape Files:: Tape Files
387 * Tarcat:: Concatenate Volumes into a Single Archive
388
389
390 Tar Internals
391
392 * Standard:: Basic Tar Format
393 * Extensions:: @acronym{GNU} Extensions to the Archive Format
394 * Sparse Formats:: Storing Sparse Files
395 * Snapshot Files::
396 * Dumpdir::
397
398 Storing Sparse Files
399
400 * Old GNU Format::
401 * PAX 0:: PAX Format, Versions 0.0 and 0.1
402 * PAX 1:: PAX Format, Version 1.0
403
404 Genfile
405
406 * Generate Mode:: File Generation Mode.
407 * Status Mode:: File Status Mode.
408 * Exec Mode:: Synchronous Execution mode.
409
410 Copying This Manual
411
412 * GNU Free Documentation License:: License for copying this manual
413
414 @end detailmenu
415 @end menu
416
417 @node Introduction
418 @chapter Introduction
419
420 @GNUTAR{} creates
421 and manipulates @dfn{archives} which are actually collections of
422 many other files; the program provides users with an organized and
423 systematic method for controlling a large amount of data.
424 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
425 archives need not (and these days, typically do not) reside on tapes.
426
427 @menu
428 * Book Contents:: What this Book Contains
429 * Definitions:: Some Definitions
430 * What tar Does:: What @command{tar} Does
431 * Naming tar Archives:: How @command{tar} Archives are Named
432 * Authors:: @GNUTAR{} Authors
433 * Reports:: Reporting bugs or suggestions
434 @end menu
435
436 @node Book Contents
437 @section What this Book Contains
438
439 The first part of this chapter introduces you to various terms that will
440 recur throughout the book. It also tells you who has worked on @GNUTAR{}
441 and its documentation, and where you should send bug reports
442 or comments.
443
444 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
445 gentle introduction for people who are new to using @command{tar}. It is
446 meant to be self-contained, not requiring any reading from subsequent
447 chapters to make sense. It moves from topic to topic in a logical,
448 progressive order, building on information already explained.
449
450 Although the tutorial is paced and structured to allow beginners to
451 learn how to use @command{tar}, it is not intended solely for beginners.
452 The tutorial explains how to use the three most frequently used
453 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
454 two frequently used options (@samp{file} and @samp{verbose}). The other
455 chapters do not refer to the tutorial frequently; however, if a section
456 discusses something which is a complex variant of a basic concept, there
457 may be a cross-reference to that basic concept. (The entire book,
458 including the tutorial, assumes that the reader understands some basic
459 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
460
461 The third chapter presents the remaining five operations, and
462 information about using @command{tar} options and option syntax.
463
464 The other chapters are meant to be used as a reference. Each chapter
465 presents everything that needs to be said about a specific topic.
466
467 One of the chapters (@pxref{Date input formats}) exists in its
468 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
469 In addition, one section of this manual (@pxref{Standard}) contains a
470 big quote which is taken directly from @command{tar} sources.
471
472 In general, we give both long and short (abbreviated) option names
473 at least once in each section where the relevant option is covered, so
474 that novice readers will become familiar with both styles. (A few
475 options have no short versions, and the relevant sections will
476 indicate this.)
477
478 @node Definitions
479 @section Some Definitions
480
481 @cindex archive
482 @cindex tar archive
483 The @command{tar} program is used to create and manipulate @command{tar}
484 archives. An @dfn{archive} is a single file which contains the contents
485 of many files, while still identifying the names of the files, their
486 owner(s), and so forth. (In addition, archives record access
487 permissions, user and group, size in bytes, and data modification time.
488 Some archives also record the file names in each archived directory, as
489 well as other file and directory information.) You can use @command{tar}
490 to @dfn{create} a new archive in a specified directory.
491
492 @cindex member
493 @cindex archive member
494 @cindex file name
495 @cindex member name
496 The files inside an archive are called @dfn{members}. Within this
497 manual, we use the term @dfn{file} to refer only to files accessible in
498 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
499 @dfn{member} to refer only to the members of an archive. Similarly, a
500 @dfn{file name} is the name of a file, as it resides in the file system,
501 and a @dfn{member name} is the name of an archive member within the
502 archive.
503
504 @cindex extraction
505 @cindex unpacking
506 The term @dfn{extraction} refers to the process of copying an archive
507 member (or multiple members) into a file in the file system. Extracting
508 all the members of an archive is often called @dfn{extracting the
509 archive}. The term @dfn{unpack} can also be used to refer to the
510 extraction of many or all the members of an archive. Extracting an
511 archive does not destroy the archive's structure, just as creating an
512 archive does not destroy the copies of the files that exist outside of
513 the archive. You may also @dfn{list} the members in a given archive
514 (this is often thought of as ``printing'' them to the standard output,
515 or the command line), or @dfn{append} members to a pre-existing archive.
516 All of these operations can be performed using @command{tar}.
517
518 @node What tar Does
519 @section What @command{tar} Does
520
521 @cindex tar
522 The @command{tar} program provides the ability to create @command{tar}
523 archives, as well as various other kinds of manipulation. For example,
524 you can use @command{tar} on previously created archives to extract files,
525 to store additional files, or to update or list files which were already
526 stored.
527
528 Initially, @command{tar} archives were used to store files conveniently on
529 magnetic tape. The name @command{tar} comes from this use; it stands for
530 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
531 direct its output to available devices, files, or other programs (using
532 pipes). @command{tar} may even access remote devices or files (as archives).
533
534 You can use @command{tar} archives in many ways. We want to stress a few
535 of them: storage, backup, and transportation.
536
537 @FIXME{the following table entries need a bit of work.}
538 @table @asis
539 @item Storage
540 Often, @command{tar} archives are used to store related files for
541 convenient file transfer over a network. For example, the
542 @acronym{GNU} Project distributes its software bundled into
543 @command{tar} archives, so that all the files relating to a particular
544 program (or set of related programs) can be transferred as a single
545 unit.
546
547 A magnetic tape can store several files in sequence. However, the tape
548 has no names for these files; it only knows their relative position on
549 the tape. One way to store several files on one tape and retain their
550 names is by creating a @command{tar} archive. Even when the basic transfer
551 mechanism can keep track of names, as FTP can, the nuisance of handling
552 multiple files, directories, and multiple links makes @command{tar}
553 archives useful.
554
555 Archive files are also used for long-term storage. You can think of
556 this as transportation from the present into the future. (It is a
557 science-fiction idiom that you can move through time as well as in
558 space; the idea here is that @command{tar} can be used to move archives in
559 all dimensions, even time!)
560
561 @item Backup
562 Because the archive created by @command{tar} is capable of preserving
563 file information and directory structure, @command{tar} is commonly
564 used for performing full and incremental backups of disks. A backup
565 puts a collection of files (possibly pertaining to many users and
566 projects) together on a disk or a tape. This guards against
567 accidental destruction of the information in those files.
568 @GNUTAR{} has special features that allow it to be
569 used to make incremental and full dumps of all the files in a
570 file system.
571
572 @item Transportation
573 You can create an archive on one system, transfer it to another system,
574 and extract the contents there. This allows you to transport a group of
575 files from one system to another.
576 @end table
577
578 @node Naming tar Archives
579 @section How @command{tar} Archives are Named
580
581 Conventionally, @command{tar} archives are given names ending with
582 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
583 but this manual follows that convention in order to accustom readers to
584 it and to make examples more clear.
585
586 @cindex tar file
587 @cindex entry
588 @cindex tar entry
589 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
590 archive members as ``files'' or ``entries''. For people familiar with
591 the operation of @command{tar}, this causes no difficulty. However, in
592 this manual, we consistently refer to ``archives'' and ``archive
593 members'' to make learning to use @command{tar} easier for novice users.
594
595 @node Authors
596 @section @GNUTAR{} Authors
597
598 @GNUTAR{} was originally written by John Gilmore,
599 and modified by many people. The @acronym{GNU} enhancements were
600 written by Jay Fenlason, then Joy Kendall, and the whole package has
601 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
602 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
603 numerous and kind users.
604
605 We wish to stress that @command{tar} is a collective work, and owes much to
606 all those people who reported problems, offered solutions and other
607 insights, or shared their thoughts and suggestions. An impressive, yet
608 partial list of those contributors can be found in the @file{THANKS}
609 file from the @GNUTAR{} distribution.
610
611 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
612 sure i want to spell out the history in this detail, at least not for
613 the printed book. i'm just not sure it needs to be said this way.
614 i'll think about it.}
615
616 @FIXME{History is more important, and surely more interesting, than
617 actual names. Quoting names without history would be meaningless. FP}
618
619 Jay Fenlason put together a draft of a @GNUTAR{}
620 manual, borrowing notes from the original man page from John Gilmore.
621 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
622 Gorin worked on a tutorial and manual for @GNUTAR{}.
623 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
624 taking information from all these sources and merging them. Melissa
625 Weisshaus finally edited and redesigned the book to create version
626 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
627 by the current maintainer, Sergey Poznyakoff.
628
629 For version 1.12, Daniel Hagerty contributed a great deal of technical
630 consulting. In particular, he is the primary author of @ref{Backups}.
631
632 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
633 (see @url{http://savannah.gnu.org/projects/tar}), and
634 active development and maintenance work has started
635 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
636 Poznyakoff and Jeff Bailey.
637
638 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
639
640 @node Reports
641 @section Reporting bugs or suggestions
642
643 @cindex bug reports
644 @cindex reporting bugs
645 If you find problems or have suggestions about this program or manual,
646 please report them to @file{bug-tar@@gnu.org}.
647
648 When reporting a bug, please be sure to include as much detail as
649 possible, in order to reproduce it. @FIXME{Be more specific, I'd
650 like to make this node as detailed as 'Bug reporting' node in Emacs
651 manual.}
652
653 @node Tutorial
654 @chapter Tutorial Introduction to @command{tar}
655
656 This chapter guides you through some basic examples of three @command{tar}
657 operations: @option{--create}, @option{--list}, and @option{--extract}. If
658 you already know how to use some other version of @command{tar}, then you
659 may not need to read this chapter. This chapter omits most complicated
660 details about how @command{tar} works.
661
662 @menu
663 * assumptions::
664 * stylistic conventions::
665 * basic tar options:: Basic @command{tar} Operations and Options
666 * frequent operations::
667 * Two Frequent Options::
668 * create:: How to Create Archives
669 * list:: How to List Archives
670 * extract:: How to Extract Members from an Archive
671 * going further::
672 @end menu
673
674 @node assumptions
675 @section Assumptions this Tutorial Makes
676
677 This chapter is paced to allow beginners to learn about @command{tar}
678 slowly. At the same time, we will try to cover all the basic aspects of
679 these three operations. In order to accomplish both of these tasks, we
680 have made certain assumptions about your knowledge before reading this
681 manual, and the hardware you will be using:
682
683 @itemize @bullet
684 @item
685 Before you start to work through this tutorial, you should understand
686 what the terms ``archive'' and ``archive member'' mean
687 (@pxref{Definitions}). In addition, you should understand something
688 about how Unix-type operating systems work, and you should know how to
689 use some basic utilities. For example, you should know how to create,
690 list, copy, rename, edit, and delete files and directories; how to
691 change between directories; and how to figure out where you are in the
692 file system. You should have some basic understanding of directory
693 structure and how files are named according to which directory they are
694 in. You should understand concepts such as standard output and standard
695 input, what various definitions of the term @samp{argument} mean, and the
696 differences between relative and absolute file names. @FIXME{and what
697 else?}
698
699 @item
700 This manual assumes that you are working from your own home directory
701 (unless we state otherwise). In this tutorial, you will create a
702 directory to practice @command{tar} commands in. When we show file names,
703 we will assume that those names are relative to your home directory.
704 For example, my home directory is @file{/home/fsf/melissa}. All of
705 my examples are in a subdirectory of the directory named by that file
706 name; the subdirectory is called @file{practice}.
707
708 @item
709 In general, we show examples of archives which exist on (or can be
710 written to, or worked with from) a directory on a hard disk. In most
711 cases, you could write those archives to, or work with them on any other
712 device, such as a tape drive. However, some of the later examples in
713 the tutorial and next chapter will not work on tape drives.
714 Additionally, working with tapes is much more complicated than working
715 with hard disks. For these reasons, the tutorial does not cover working
716 with tape drives. @xref{Media}, for complete information on using
717 @command{tar} archives with tape drives.
718
719 @FIXME{this is a cop out. need to add some simple tape drive info.}
720 @end itemize
721
722 @node stylistic conventions
723 @section Stylistic Conventions
724
725 In the examples, @samp{$} represents a typical shell prompt. It
726 precedes lines you should type; to make this more clear, those lines are
727 shown in @kbd{this font}, as opposed to lines which represent the
728 computer's response; those lines are shown in @code{this font}, or
729 sometimes @samp{like this}.
730
731 @c When we have lines which are too long to be
732 @c displayed in any other way, we will show them like this:
733
734 @node basic tar options
735 @section Basic @command{tar} Operations and Options
736
737 @command{tar} can take a wide variety of arguments which specify and define
738 the actions it will have on the particular set of files or the archive.
739 The main types of arguments to @command{tar} fall into one of two classes:
740 operations, and options.
741
742 Some arguments fall into a class called @dfn{operations}; exactly one of
743 these is both allowed and required for any instance of using @command{tar};
744 you may @emph{not} specify more than one. People sometimes speak of
745 @dfn{operating modes}. You are in a particular operating mode when you
746 have specified the operation which specifies it; there are eight
747 operations in total, and thus there are eight operating modes.
748
749 The other arguments fall into the class known as @dfn{options}. You are
750 not required to specify any options, and you are allowed to specify more
751 than one at a time (depending on the way you are using @command{tar} at
752 that time). Some options are used so frequently, and are so useful for
753 helping you type commands more carefully that they are effectively
754 ``required''. We will discuss them in this chapter.
755
756 You can write most of the @command{tar} operations and options in any
757 of three forms: long (mnemonic) form, short form, and old style. Some
758 of the operations and options have no short or ``old'' forms; however,
759 the operations and options which we will cover in this tutorial have
760 corresponding abbreviations. We will indicate those abbreviations
761 appropriately to get you used to seeing them. Note, that the ``old
762 style'' option forms exist in @GNUTAR{} for compatibility with Unix
763 @command{tar}. In this book we present a full discussion of this way
764 of writing options and operations (@pxref{Old Options}), and we discuss
765 the other two styles of writing options (@xref{Long Options}, and
766 @pxref{Short Options}).
767
768 In the examples and in the text of this tutorial, we usually use the
769 long forms of operations and options; but the ``short'' forms produce
770 the same result and can make typing long @command{tar} commands easier.
771 For example, instead of typing
772
773 @smallexample
774 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
775 @end smallexample
776
777 @noindent
778 you can type
779 @smallexample
780 @kbd{tar -c -v -f afiles.tar apple angst aspic}
781 @end smallexample
782
783 @noindent
784 or even
785 @smallexample
786 @kbd{tar -cvf afiles.tar apple angst aspic}
787 @end smallexample
788
789 @noindent
790 For more information on option syntax, see @ref{Advanced tar}. In
791 discussions in the text, when we name an option by its long form, we
792 also give the corresponding short option in parentheses.
793
794 The term, ``option'', can be confusing at times, since ``operations''
795 are often lumped in with the actual, @emph{optional} ``options'' in certain
796 general class statements. For example, we just talked about ``short and
797 long forms of options and operations''. However, experienced @command{tar}
798 users often refer to these by shorthand terms such as, ``short and long
799 options''. This term assumes that the ``operations'' are included, also.
800 Context will help you determine which definition of ``options'' to use.
801
802 Similarly, the term ``command'' can be confusing, as it is often used in
803 two different ways. People sometimes refer to @command{tar} ``commands''.
804 A @command{tar} @dfn{command} is the entire command line of user input
805 which tells @command{tar} what to do --- including the operation, options,
806 and any arguments (file names, pipes, other commands, etc.). However,
807 you will also sometimes hear the term ``the @command{tar} command''. When
808 the word ``command'' is used specifically like this, a person is usually
809 referring to the @command{tar} @emph{operation}, not the whole line.
810 Again, use context to figure out which of the meanings the speaker
811 intends.
812
813 @node frequent operations
814 @section The Three Most Frequently Used Operations
815
816 Here are the three most frequently used operations (both short and long
817 forms), as well as a brief description of their meanings. The rest of
818 this chapter will cover how to use these operations in detail. We will
819 present the rest of the operations in the next chapter.
820
821 @table @option
822 @item --create
823 @itemx -c
824 Create a new @command{tar} archive.
825 @item --list
826 @itemx -t
827 List the contents of an archive.
828 @item --extract
829 @itemx -x
830 Extract one or more members from an archive.
831 @end table
832
833 @node Two Frequent Options
834 @section Two Frequently Used Options
835
836 To understand how to run @command{tar} in the three operating modes listed
837 previously, you also need to understand how to use two of the options to
838 @command{tar}: @option{--file} (which takes an archive file as an argument)
839 and @option{--verbose}. (You are usually not @emph{required} to specify
840 either of these options when you run @command{tar}, but they can be very
841 useful in making things more clear and helping you avoid errors.)
842
843 @menu
844 * file tutorial::
845 * verbose tutorial::
846 * help tutorial::
847 @end menu
848
849 @node file tutorial
850 @unnumberedsubsec The @option{--file} Option
851
852 @table @option
853 @xopindex{file, tutorial}
854 @item --file=@var{archive-name}
855 @itemx -f @var{archive-name}
856 Specify the name of an archive file.
857 @end table
858
859 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
860 use @command{tar}; this option determines the name of the archive file
861 that @command{tar} will work on.
862
863 @vrindex TAPE
864 If you don't specify this argument, then @command{tar} will examine
865 the environment variable @env{TAPE}. If it is set, its value will be
866 used as the archive name. Otherwise, @command{tar} will use the
867 default archive, determined at compile time. Usually it is
868 standard output or some physical tape drive attached to your machine
869 (you can verify what the default is by running @kbd{tar
870 --show-defaults}, @pxref{defaults}). If there is no tape drive
871 attached, or the default is not meaningful, then @command{tar} will
872 print an error message. The error message might look roughly like one
873 of the following:
874
875 @smallexample
876 tar: can't open /dev/rmt8 : No such device or address
877 tar: can't open /dev/rsmt0 : I/O error
878 @end smallexample
879
880 @noindent
881 To avoid confusion, we recommend that you always specify an archive file
882 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
883 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
884 @ref{file}.
885
886 @node verbose tutorial
887 @unnumberedsubsec The @option{--verbose} Option
888
889 @table @option
890 @xopindex{verbose, introduced}
891 @item --verbose
892 @itemx -v
893 Show the files being worked on as @command{tar} is running.
894 @end table
895
896 @option{--verbose} (@option{-v}) shows details about the results of running
897 @command{tar}. This can be especially useful when the results might not be
898 obvious. For example, if you want to see the progress of @command{tar} as
899 it writes files into the archive, you can use the @option{--verbose}
900 option. In the beginning, you may find it useful to use
901 @option{--verbose} at all times; when you are more accustomed to
902 @command{tar}, you will likely want to use it at certain times but not at
903 others. We will use @option{--verbose} at times to help make something
904 clear, and we will give many examples both using and not using
905 @option{--verbose} to show the differences.
906
907 Each instance of @option{--verbose} on the command line increases the
908 verbosity level by one, so if you need more details on the output,
909 specify it twice.
910
911 When reading archives (@option{--list}, @option{--extract},
912 @option{--diff}), @command{tar} by default prints only the names of
913 the members being extracted. Using @option{--verbose} will show a full,
914 @command{ls} style member listing.
915
916 In contrast, when writing archives (@option{--create}, @option{--append},
917 @option{--update}), @command{tar} does not print file names by
918 default. So, a single @option{--verbose} option shows the file names
919 being added to the archive, while two @option{--verbose} options
920 enable the full listing.
921
922 For example, to create an archive in verbose mode:
923
924 @smallexample
925 $ @kbd{tar -cvf afiles.tar apple angst aspic}
926 apple
927 angst
928 aspic
929 @end smallexample
930
931 @noindent
932 Creating the same archive with the verbosity level 2 could give:
933
934 @smallexample
935 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
936 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
937 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
938 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
939 @end smallexample
940
941 @noindent
942 This works equally well using short or long forms of options. Using
943 long forms, you would simply write out the mnemonic form of the option
944 twice, like this:
945
946 @smallexample
947 $ @kbd{tar --create --verbose --verbose @dots{}}
948 @end smallexample
949
950 @noindent
951 Note that you must double the hyphens properly each time.
952
953 Later in the tutorial, we will give examples using @w{@option{--verbose
954 --verbose}}.
955
956 @anchor{verbose member listing}
957 The full output consists of six fields:
958
959 @itemize @bullet
960 @item File type and permissions in symbolic form.
961 These are displayed in the same format as the first column of
962 @command{ls -l} output (@pxref{What information is listed,
963 format=verbose, Verbose listing, fileutils, GNU file utilities}).
964
965 @item Owner name and group separated by a slash character.
966 If these data are not available (for example, when listing a @samp{v7} format
967 archive), numeric @acronym{ID} values are printed instead.
968
969 @item Size of the file, in bytes.
970
971 @item File modification date in ISO 8601 format.
972
973 @item File modification time.
974
975 @item File name.
976 If the name contains any special characters (white space, newlines,
977 etc.) these are displayed in an unambiguous form using so called
978 @dfn{quoting style}. For the detailed discussion of available styles
979 and on how to use them, see @ref{quoting styles}.
980
981 Depending on the file type, the name can be followed by some
982 additional information, described in the following table:
983
984 @table @samp
985 @item -> @var{link-name}
986 The file or archive member is a @dfn{symbolic link} and
987 @var{link-name} is the name of file it links to.
988
989 @item link to @var{link-name}
990 The file or archive member is a @dfn{hard link} and @var{link-name} is
991 the name of file it links to.
992
993 @item --Long Link--
994 The archive member is an old GNU format long link. You will normally
995 not encounter this.
996
997 @item --Long Name--
998 The archive member is an old GNU format long name. You will normally
999 not encounter this.
1000
1001 @item --Volume Header--
1002 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1003
1004 @item --Continued at byte @var{n}--
1005 Encountered only at the beginning of a multi-volume archive
1006 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1007 from the previous volume. The number @var{n} gives the offset where
1008 the original file was split.
1009
1010 @item unknown file type @var{c}
1011 An archive member of unknown type. @var{c} is the type character from
1012 the archive header. If you encounter such a message, it means that
1013 either your archive contains proprietary member types @GNUTAR{} is not
1014 able to handle, or the archive is corrupted.
1015 @end table
1016
1017 @end itemize
1018
1019 For example, here is an archive listing containing most of the special
1020 suffixes explained above:
1021
1022 @smallexample
1023 @group
1024 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1025 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at byte 32456--
1026 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1027 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1028 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1029 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1030 @end group
1031 @end smallexample
1032
1033 @smallexample
1034 @end smallexample
1035
1036 @node help tutorial
1037 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1038
1039 @table @option
1040 @opindex help
1041 @item --help
1042
1043 The @option{--help} option to @command{tar} prints out a very brief list of
1044 all operations and option available for the current version of
1045 @command{tar} available on your system.
1046 @end table
1047
1048 @node create
1049 @section How to Create Archives
1050 @UNREVISED
1051
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.
1059
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.
1067
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}.
1071
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.
1078
1079 @menu
1080 * prepare for examples::
1081 * Creating the archive::
1082 * create verbose::
1083 * short create::
1084 * create dir::
1085 @end menu
1086
1087 @node prepare for examples
1088 @subsection Preparing a Practice Directory for Examples
1089
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.
1096
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.)
1102
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.
1107
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.
1118
1119 @node Creating the archive
1120 @subsection Creating the Archive
1121
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:
1125
1126 @smallexample
1127 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1128 @end smallexample
1129
1130 The order of the arguments is not very important, @emph{when using long
1131 option forms}. You could also say:
1132
1133 @smallexample
1134 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1135 @end smallexample
1136
1137 @noindent
1138 However, you can see that this order is harder to understand; this is
1139 why we will list the arguments in the order that makes the commands
1140 easiest to understand (and we encourage you to do the same when you use
1141 @command{tar}, to avoid errors).
1142
1143 Note that the sequence
1144 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1145 If you substituted any other string of characters for
1146 @kbd{collection.tar}, then that string would become the name of the
1147 archive file you create.
1148
1149 The order of the options becomes more important when you begin to use
1150 short forms. With short forms, if you type commands in the wrong order
1151 (even if you type them correctly in all other ways), you may end up with
1152 results you don't expect. For this reason, it is a good idea to get
1153 into the habit of typing options in the order that makes inherent sense.
1154 @xref{short create}, for more information on this.
1155
1156 In this example, you type the command as shown above: @option{--create}
1157 is the operation which creates the new archive
1158 (@file{collection.tar}), and @option{--file} is the option which lets
1159 you give it the name you chose. The files, @file{blues}, @file{folk},
1160 and @file{jazz}, are now members of the archive, @file{collection.tar}
1161 (they are @dfn{file name arguments} to the @option{--create} operation.
1162 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1163 in the archive, they are called @emph{archive members}, not files.
1164 (@pxref{Definitions,members}).
1165
1166 When you create an archive, you @emph{must} specify which files you
1167 want placed in the archive. If you do not specify any archive
1168 members, @GNUTAR{} will complain.
1169
1170 If you now list the contents of the working directory (@command{ls}), you will
1171 find the archive file listed as well as the files you saw previously:
1172
1173 @smallexample
1174 blues folk jazz collection.tar
1175 @end smallexample
1176
1177 @noindent
1178 Creating the archive @samp{collection.tar} did not destroy the copies of
1179 the files in the directory.
1180
1181 Keep in mind that if you don't indicate an operation, @command{tar} will not
1182 run and will prompt you for one. If you don't name any files, @command{tar}
1183 will complain. You must have write access to the working directory,
1184 or else you will not be able to create an archive in that directory.
1185
1186 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1187 an existing archive; it will delete the archive and write a new one.
1188 Use @option{--append} (@option{-r}) instead. @xref{append}.
1189
1190 @node create verbose
1191 @subsection Running @option{--create} with @option{--verbose}
1192
1193 @xopindex{create, using with @option{--verbose}}
1194 @xopindex{verbose, using with @option{--create}}
1195 If you include the @option{--verbose} (@option{-v}) option on the command line,
1196 @command{tar} will list the files it is acting on as it is working. In
1197 verbose mode, the @code{create} example above would appear as:
1198
1199 @smallexample
1200 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1201 blues
1202 folk
1203 jazz
1204 @end smallexample
1205
1206 This example is just like the example we showed which did not use
1207 @option{--verbose}, except that @command{tar} generated the remaining
1208 @iftex
1209 lines (note the different font styles).
1210 @end iftex
1211 @ifinfo
1212 lines.
1213 @end ifinfo
1214
1215 In the rest of the examples in this chapter, we will frequently use
1216 @code{verbose} mode so we can show actions or @command{tar} responses that
1217 you would otherwise not see, and which are important for you to
1218 understand.
1219
1220 @node short create
1221 @subsection Short Forms with @samp{create}
1222
1223 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1224 basic uses of @command{tar}, and you will use it countless times.
1225 Eventually, you will probably want to use abbreviated (or ``short'')
1226 forms of options. A full discussion of the three different forms that
1227 options can take appears in @ref{Styles}; for now, here is what the
1228 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1229 using short option forms:
1230
1231 @smallexample
1232 $ @kbd{tar -cvf collection.tar blues folk jazz}
1233 blues
1234 folk
1235 jazz
1236 @end smallexample
1237
1238 @noindent
1239 As you can see, the system responds the same no matter whether you use
1240 long or short option forms.
1241
1242 @FIXME{i don't like how this is worded:} One difference between using
1243 short and long option forms is that, although the exact placement of
1244 arguments following options is no more specific when using short forms,
1245 it is easier to become confused and make a mistake when using short
1246 forms. For example, suppose you attempted the above example in the
1247 following way:
1248
1249 @smallexample
1250 $ @kbd{tar -cfv collection.tar blues folk jazz}
1251 @end smallexample
1252
1253 @noindent
1254 In this case, @command{tar} will make an archive file called @file{v},
1255 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1256 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1257 is thus taken to be the chosen archive file name. @command{tar} will try
1258 to add a file called @file{collection.tar} to the @file{v} archive file;
1259 if the file @file{collection.tar} did not already exist, @command{tar} will
1260 report an error indicating that this file does not exist. If the file
1261 @file{collection.tar} does already exist (e.g., from a previous command
1262 you may have run), then @command{tar} will add this file to the archive.
1263 Because the @option{-v} option did not get registered, @command{tar} will not
1264 run under @samp{verbose} mode, and will not report its progress.
1265
1266 The end result is that you may be quite confused about what happened,
1267 and possibly overwrite a file. To illustrate this further, we will show
1268 you how an example we showed previously would look using short forms.
1269
1270 This example,
1271
1272 @smallexample
1273 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1274 @end smallexample
1275
1276 @noindent
1277 is confusing as it is. When shown using short forms, however, it
1278 becomes much more so:
1279
1280 @smallexample
1281 $ @kbd{tar blues -c folk -f collection.tar jazz}
1282 @end smallexample
1283
1284 @noindent
1285 It would be very easy to put the wrong string of characters
1286 immediately following the @option{-f}, but doing that could sacrifice
1287 valuable data.
1288
1289 For this reason, we recommend that you pay very careful attention to
1290 the order of options and placement of file and archive names,
1291 especially when using short option forms. Not having the option name
1292 written out mnemonically can affect how well you remember which option
1293 does what, and therefore where different names have to be placed.
1294
1295 @node create dir
1296 @subsection Archiving Directories
1297
1298 @cindex Archiving Directories
1299 @cindex Directories, Archiving
1300 You can archive a directory by specifying its directory name as a
1301 file name argument to @command{tar}. The files in the directory will be
1302 archived relative to the working directory, and the directory will be
1303 re-created along with its contents when the archive is extracted.
1304
1305 To archive a directory, first move to its superior directory. If you
1306 have followed the previous instructions in this tutorial, you should
1307 type:
1308
1309 @smallexample
1310 $ @kbd{cd ..}
1311 $
1312 @end smallexample
1313
1314 @noindent
1315 This will put you into the directory which contains @file{practice},
1316 i.e., your home directory. Once in the superior directory, you can
1317 specify the subdirectory, @file{practice}, as a file name argument. To
1318 store @file{practice} in the new archive file @file{music.tar}, type:
1319
1320 @smallexample
1321 $ @kbd{tar --create --verbose --file=music.tar practice}
1322 @end smallexample
1323
1324 @noindent
1325 @command{tar} should output:
1326
1327 @smallexample
1328 practice/
1329 practice/blues
1330 practice/folk
1331 practice/jazz
1332 practice/collection.tar
1333 @end smallexample
1334
1335 Note that the archive thus created is not in the subdirectory
1336 @file{practice}, but rather in the current working directory---the
1337 directory from which @command{tar} was invoked. Before trying to archive a
1338 directory from its superior directory, you should make sure you have
1339 write access to the superior directory itself, not only the directory
1340 you are trying archive with @command{tar}. For example, you will probably
1341 not be able to store your home directory in an archive by invoking
1342 @command{tar} from the root directory; @xref{absolute}. (Note
1343 also that @file{collection.tar}, the original archive file, has itself
1344 been archived. @command{tar} will accept any file as a file to be
1345 archived, regardless of its content. When @file{music.tar} is
1346 extracted, the archive file @file{collection.tar} will be re-written
1347 into the file system).
1348
1349 If you give @command{tar} a command such as
1350
1351 @smallexample
1352 $ @kbd{tar --create --file=foo.tar .}
1353 @end smallexample
1354
1355 @noindent
1356 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1357 dumped}. This happens because @command{tar} creates the archive
1358 @file{foo.tar} in the current directory before putting any files into
1359 it. Then, when @command{tar} attempts to add all the files in the
1360 directory @file{.} to the archive, it notices that the file
1361 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1362 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1363 will continue in this case, and create the archive
1364 normally, except for the exclusion of that one file. (@emph{Please
1365 note:} Other implementations of @command{tar} may not be so clever;
1366 they will enter an infinite loop when this happens, so you should not
1367 depend on this behavior unless you are certain you are running
1368 @GNUTAR{}. In general, it is wise to always place the archive outside
1369 of the directory being dumped.)
1370
1371 @node list
1372 @section How to List Archives
1373
1374 @opindex list
1375 Frequently, you will find yourself wanting to determine exactly what a
1376 particular archive contains. You can use the @option{--list}
1377 (@option{-t}) operation to get the member names as they currently
1378 appear in the archive, as well as various attributes of the files at
1379 the time they were archived. For example, you can examine the archive
1380 @file{collection.tar} that you created in the last section with the
1381 command,
1382
1383 @smallexample
1384 $ @kbd{tar --list --file=collection.tar}
1385 @end smallexample
1386
1387 @noindent
1388 The output of @command{tar} would then be:
1389
1390 @smallexample
1391 blues
1392 folk
1393 jazz
1394 @end smallexample
1395
1396 @noindent
1397 The archive @file{bfiles.tar} would list as follows:
1398
1399 @smallexample
1400 ./birds
1401 baboon
1402 ./box
1403 @end smallexample
1404
1405 @noindent
1406 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1407 @var{archive-name}}) option just as with @option{--create}
1408 (@option{-c}) to specify the name of the archive.
1409
1410 @xopindex{list, using with @option{--verbose}}
1411 @xopindex{verbose, using with @option{--list}}
1412 If you use the @option{--verbose} (@option{-v}) option with
1413 @option{--list}, then @command{tar} will print out a listing
1414 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1415 forth. This output is described in detail in @ref{verbose member listing}.
1416
1417 If you had used @option{--verbose} (@option{-v}) mode, the example
1418 above would look like:
1419
1420 @smallexample
1421 $ @kbd{tar --list --verbose --file=collection.tar folk}
1422 -rw-r--r-- myself/user 62 1990-05-23 10:55 folk
1423 @end smallexample
1424
1425 @cindex listing member and file names
1426 @anchor{listing member and file names}
1427 It is important to notice that the output of @kbd{tar --list
1428 --verbose} does not necessarily match that produced by @kbd{tar
1429 --create --verbose} while creating the archive. It is because
1430 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1431 prefixes from file names before storing them in the archive
1432 (@xref{absolute}, for more information). In other
1433 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1434 an archive and @dfn{member names} when listing it. Consider this
1435 example:
1436
1437 @smallexample
1438 @group
1439 $ @kbd{tar --create --verbose --file archive /etc/mail}
1440 tar: Removing leading '/' from member names
1441 /etc/mail/
1442 /etc/mail/sendmail.cf
1443 /etc/mail/aliases
1444 $ @kbd{tar --test --file archive}
1445 etc/mail/
1446 etc/mail/sendmail.cf
1447 etc/mail/aliases
1448 @end group
1449 @end smallexample
1450
1451 @opindex show-stored-names
1452 This default behavior can sometimes be inconvenient. You can force
1453 @GNUTAR{} show member names when creating archive by supplying
1454 @option{--show-stored-names} option.
1455
1456 @table @option
1457 @item --show-stored-names
1458 Print member (as opposed to @emph{file}) names when creating the archive.
1459 @end table
1460
1461 @cindex File name arguments, using @option{--list} with
1462 @xopindex{list, using with file name arguments}
1463 You can specify one or more individual member names as arguments when
1464 using @samp{list}. In this case, @command{tar} will only list the
1465 names of members you identify. For example, @w{@kbd{tar --list
1466 --file=afiles.tar apple}} would only print @file{apple}.
1467
1468 Because @command{tar} preserves file names, these must be specified as
1469 they appear in the archive (i.e., relative to the directory from which
1470 the archive was created). Therefore, it is essential when specifying
1471 member names to @command{tar} that you give the exact member names.
1472 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1473 error message something like @samp{tar: birds: Not found in archive},
1474 because there is no member named @file{birds}, only one named
1475 @file{./birds}. While the names @file{birds} and @file{./birds} name
1476 the same file, @emph{member} names by default are compared verbatim.
1477
1478 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1479 with @file{baboon}, because this exact member name is in the archive file
1480 @file{bfiles.tar}. If you are not sure of the exact file name,
1481 use @dfn{globbing patterns}, for example:
1482
1483 @smallexample
1484 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1485 @end smallexample
1486
1487 @noindent
1488 will list all members whose name contains @samp{b}. @xref{wildcards},
1489 for a detailed discussion of globbing patterns and related
1490 @command{tar} command line options.
1491
1492 @menu
1493 * list dir::
1494 @end menu
1495
1496 @node list dir
1497 @unnumberedsubsec Listing the Contents of a Stored Directory
1498
1499 To get information about the contents of an archived directory,
1500 use the directory name as a file name argument in conjunction with
1501 @option{--list} (@option{-t}). To find out file attributes, include the
1502 @option{--verbose} (@option{-v}) option.
1503
1504 For example, to find out about files in the directory @file{practice}, in
1505 the archive file @file{music.tar}, type:
1506
1507 @smallexample
1508 $ @kbd{tar --list --verbose --file=music.tar practice}
1509 @end smallexample
1510
1511 @command{tar} responds:
1512
1513 @smallexample
1514 drwxrwxrwx myself/user 0 1990-05-31 21:49 practice/
1515 -rw-r--r-- myself/user 42 1990-05-21 13:29 practice/blues
1516 -rw-r--r-- myself/user 62 1990-05-23 10:55 practice/folk
1517 -rw-r--r-- myself/user 40 1990-05-21 13:30 practice/jazz
1518 -rw-r--r-- myself/user 10240 1990-05-31 21:49 practice/collection.tar
1519 @end smallexample
1520
1521 When you use a directory name as a file name argument, @command{tar} acts on
1522 all the files (including sub-directories) in that directory.
1523
1524 @node extract
1525 @section How to Extract Members from an Archive
1526 @cindex Extraction
1527 @cindex Retrieving files from an archive
1528 @cindex Resurrecting files from an archive
1529
1530 @opindex extract
1531 Creating an archive is only half the job---there is no point in storing
1532 files in an archive if you can't retrieve them. The act of retrieving
1533 members from an archive so they can be used and manipulated as
1534 unarchived files again is called @dfn{extraction}. To extract files
1535 from an archive, use the @option{--extract} (@option{--get} or
1536 @option{-x}) operation. As with @option{--create}, specify the name
1537 of the archive with @option{--file} (@option{-f}) option. Extracting
1538 an archive does not modify the archive in any way; you can extract it
1539 multiple times if you want or need to.
1540
1541 Using @option{--extract}, you can extract an entire archive, or specific
1542 files. The files can be directories containing other files, or not. As
1543 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1544 long form of the operation without affecting the performance.
1545
1546 @menu
1547 * extracting archives::
1548 * extracting files::
1549 * extract dir::
1550 * extracting untrusted archives::
1551 * failing commands::
1552 @end menu
1553
1554 @node extracting archives
1555 @subsection Extracting an Entire Archive
1556
1557 To extract an entire archive, specify the archive file name only, with
1558 no individual file names as arguments. For example,
1559
1560 @smallexample
1561 $ @kbd{tar -xvf collection.tar}
1562 @end smallexample
1563
1564 @noindent
1565 produces this:
1566
1567 @smallexample
1568 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
1569 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
1570 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
1571 @end smallexample
1572
1573 @node extracting files
1574 @subsection Extracting Specific Files
1575
1576 To extract specific archive members, give their exact member names as
1577 arguments, as printed by @option{--list} (@option{-t}). If you had
1578 mistakenly deleted one of the files you had placed in the archive
1579 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1580 from the archive without changing the archive's structure. Its
1581 contents will be identical to the original file @file{blues} that you
1582 deleted.
1583
1584 First, make sure you are in the @file{practice} directory, and list the
1585 files in the directory. Now, delete the file, @samp{blues}, and list
1586 the files in the directory again.
1587
1588 You can now extract the member @file{blues} from the archive file
1589 @file{collection.tar} like this:
1590
1591 @smallexample
1592 $ @kbd{tar --extract --file=collection.tar blues}
1593 @end smallexample
1594
1595 @noindent
1596 If you list the files in the directory again, you will see that the file
1597 @file{blues} has been restored, with its original permissions, data
1598 modification times, and owner.@footnote{This is only accidentally
1599 true, but not in general. Whereas modification times are always
1600 restored, in most cases, one has to be root for restoring the owner,
1601 and use a special option for restoring permissions. Here, it just
1602 happens that the restoring user is also the owner of the archived
1603 members, and that the current @code{umask} is compatible with original
1604 permissions.} (These parameters will be identical to those which
1605 the file had when you originally placed it in the archive; any changes
1606 you may have made before deleting the file from the file system,
1607 however, will @emph{not} have been made to the archive member.) The
1608 archive file, @samp{collection.tar}, is the same as it was before you
1609 extracted @samp{blues}. You can confirm this by running @command{tar} with
1610 @option{--list} (@option{-t}).
1611
1612 Remember that as with other operations, specifying the exact member
1613 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1614 will fail, because there is no member named @file{birds}. To extract
1615 the member named @file{./birds}, you must specify @w{@kbd{tar
1616 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1617 exact member names, use @option{--list} (@option{-t}) option
1618 (@pxref{list}). You can also extract those members that match a
1619 specific @dfn{globbing pattern}. For example, to extract from
1620 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1621 directory prefix, you could type:
1622
1623 @smallexample
1624 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1625 @end smallexample
1626
1627 @noindent
1628 Here, @option{--wildcards} instructs @command{tar} to treat
1629 command line arguments as globbing patterns and @option{--no-anchored}
1630 informs it that the patterns apply to member names after any @samp{/}
1631 delimiter. The use of globbing patterns is discussed in detail in
1632 @xref{wildcards}.
1633
1634 You can extract a file to standard output by combining the above options
1635 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1636 Output}).
1637
1638 If you give the @option{--verbose} option, then @option{--extract}
1639 will print the names of the archive members as it extracts them.
1640
1641 @node extract dir
1642 @subsection Extracting Files that are Directories
1643
1644 Extracting directories which are members of an archive is similar to
1645 extracting other files. The main difference to be aware of is that if
1646 the extracted directory has the same name as any directory already in
1647 the working directory, then files in the extracted directory will be
1648 placed into the directory of the same name. Likewise, if there are
1649 files in the pre-existing directory with the same names as the members
1650 which you extract, the files from the extracted archive will replace
1651 the files already in the working directory (and possible
1652 subdirectories). This will happen regardless of whether or not the
1653 files in the working directory were more recent than those extracted
1654 (there exist, however, special options that alter this behavior
1655 @pxref{Writing}).
1656
1657 However, if a file was stored with a directory name as part of its file
1658 name, and that directory does not exist under the working directory when
1659 the file is extracted, @command{tar} will create the directory.
1660
1661 We can demonstrate how to use @option{--extract} to extract a directory
1662 file with an example. Change to the @file{practice} directory if you
1663 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1664 go back to the parent directory and extract the archive
1665 @file{music.tar}. You may either extract the entire archive, or you may
1666 extract only the files you just deleted. To extract the entire archive,
1667 don't give any file names as arguments after the archive name
1668 @file{music.tar}. To extract only the files you deleted, use the
1669 following command:
1670
1671 @smallexample
1672 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1673 practice/folk
1674 practice/jazz
1675 @end smallexample
1676
1677 @noindent
1678 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1679 would have displayed more detail about the extracted files, as shown
1680 in the example below:
1681
1682 @smallexample
1683 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1684 -rw-r--r-- me/user 28 1996-10-18 16:31 practice/jazz
1685 -rw-r--r-- me/user 20 1996-09-23 16:44 practice/folk
1686 @end smallexample
1687
1688 @noindent
1689 Because you created the directory with @file{practice} as part of the
1690 file names of each of the files by archiving the @file{practice}
1691 directory as @file{practice}, you must give @file{practice} as part
1692 of the file names when you extract those files from the archive.
1693
1694 @node extracting untrusted archives
1695 @subsection Extracting Archives from Untrusted Sources
1696
1697 Extracting files from archives can overwrite files that already exist.
1698 If you receive an archive from an untrusted source, you should make a
1699 new directory and extract into that directory, so that you don't have
1700 to worry about the extraction overwriting one of your existing files.
1701 For example, if @file{untrusted.tar} came from somewhere else on the
1702 Internet, and you don't necessarily trust its contents, you can
1703 extract it as follows:
1704
1705 @smallexample
1706 $ @kbd{mkdir newdir}
1707 $ @kbd{cd newdir}
1708 $ @kbd{tar -xvf ../untrusted.tar}
1709 @end smallexample
1710
1711 It is also a good practice to examine contents of the archive
1712 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1713 with @option{--verbose} (@option{-v}).
1714
1715 @node failing commands
1716 @subsection Commands That Will Fail
1717
1718 Here are some sample commands you might try which will not work, and why
1719 they won't work.
1720
1721 If you try to use this command,
1722
1723 @smallexample
1724 $ @kbd{tar -xvf music.tar folk jazz}
1725 @end smallexample
1726
1727 @noindent
1728 you will get the following response:
1729
1730 @smallexample
1731 tar: folk: Not found in archive
1732 tar: jazz: Not found in archive
1733 @end smallexample
1734
1735 @noindent
1736 This is because these files were not originally @emph{in} the parent
1737 directory @file{..}, where the archive is located; they were in the
1738 @file{practice} directory, and their file names reflect this:
1739
1740 @smallexample
1741 $ @kbd{tar -tvf music.tar}
1742 practice/blues
1743 practice/folk
1744 practice/jazz
1745 @end smallexample
1746
1747 @FIXME{make sure the above works when going through the examples in
1748 order...}
1749
1750 @noindent
1751 Likewise, if you try to use this command,
1752
1753 @smallexample
1754 $ @kbd{tar -tvf music.tar folk jazz}
1755 @end smallexample
1756
1757 @noindent
1758 you would get a similar response. Members with those names are not in the
1759 archive. You must use the correct member names, or wildcards, in order
1760 to extract the files from the archive.
1761
1762 If you have forgotten the correct names of the files in the archive,
1763 use @w{@kbd{tar --list --verbose}} to list them correctly.
1764
1765 @FIXME{more examples, here? hag thinks it's a good idea.}
1766
1767 @node going further
1768 @section Going Further Ahead in this Manual
1769 @UNREVISED
1770
1771 @FIXME{need to write up a node here about the things that are going to
1772 be in the rest of the manual.}
1773
1774 @node tar invocation
1775 @chapter Invoking @GNUTAR{}
1776
1777 This chapter is about how one invokes the @GNUTAR{}
1778 command, from the command synopsis (@pxref{Synopsis}). There are
1779 numerous options, and many styles for writing them. One mandatory
1780 option specifies the operation @command{tar} should perform
1781 (@pxref{Operation Summary}), other options are meant to detail how
1782 this operation should be performed (@pxref{Option Summary}).
1783 Non-option arguments are not always interpreted the same way,
1784 depending on what the operation is.
1785
1786 You will find in this chapter everything about option styles and rules for
1787 writing them (@pxref{Styles}). On the other hand, operations and options
1788 are fully described elsewhere, in other chapters. Here, you will find
1789 only synthetic descriptions for operations and options, together with
1790 pointers to other parts of the @command{tar} manual.
1791
1792 Some options are so special they are fully described right in this
1793 chapter. They have the effect of inhibiting the normal operation of
1794 @command{tar} or else, they globally alter the amount of feedback the user
1795 receives about what is going on. These are the @option{--help} and
1796 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1797 and @option{--interactive} options (@pxref{interactive}).
1798
1799 @menu
1800 * Synopsis::
1801 * using tar options::
1802 * Styles::
1803 * All Options::
1804 * help::
1805 * defaults::
1806 * verbose::
1807 * checkpoints::
1808 * warnings::
1809 * interactive::
1810 @end menu
1811
1812 @node Synopsis
1813 @section General Synopsis of @command{tar}
1814
1815 The @GNUTAR{} program is invoked as either one of:
1816
1817 @smallexample
1818 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1819 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1820 @end smallexample
1821
1822 The second form is for when old options are being used.
1823
1824 You can use @command{tar} to store files in an archive, to extract them from
1825 an archive, and to do other types of archive manipulation. The primary
1826 argument to @command{tar}, which is called the @dfn{operation}, specifies
1827 which action to take. The other arguments to @command{tar} are either
1828 @dfn{options}, which change the way @command{tar} performs an operation,
1829 or file names or archive members, which specify the files or members
1830 @command{tar} is to act on.
1831
1832 You can actually type in arguments in any order, even if in this manual
1833 the options always precede the other arguments, to make examples easier
1834 to understand. Further, the option stating the main operation mode
1835 (the @command{tar} main command) is usually given first.
1836
1837 Each @var{name} in the synopsis above is interpreted as an archive member
1838 name when the main command is one of @option{--compare}
1839 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1840 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1841 @option{--update} (@option{-u}). When naming archive members, you
1842 must give the exact name of the member in the archive, as it is
1843 printed by @option{--list}. For @option{--append} (@option{-r}) and
1844 @option{--create} (@option{-c}), these @var{name} arguments specify
1845 the names of either files or directory hierarchies to place in the archive.
1846 These files or hierarchies should already exist in the file system,
1847 prior to the execution of the @command{tar} command.
1848
1849 @command{tar} interprets relative file names as being relative to the
1850 working directory. @command{tar} will make all file names relative
1851 (by removing leading slashes when archiving or restoring files),
1852 unless you specify otherwise (using the @option{--absolute-names}
1853 option). @xref{absolute}, for more information about
1854 @option{--absolute-names}.
1855
1856 If you give the name of a directory as either a file name or a member
1857 name, then @command{tar} acts recursively on all the files and directories
1858 beneath that directory. For example, the name @file{/} identifies all
1859 the files in the file system to @command{tar}.
1860
1861 The distinction between file names and archive member names is especially
1862 important when shell globbing is used, and sometimes a source of confusion
1863 for newcomers. @xref{wildcards}, for more information about globbing.
1864 The problem is that shells may only glob using existing files in the
1865 file system. Only @command{tar} itself may glob on archive members, so when
1866 needed, you must ensure that wildcard characters reach @command{tar} without
1867 being interpreted by the shell first. Using a backslash before @samp{*}
1868 or @samp{?}, or putting the whole argument between quotes, is usually
1869 sufficient for this.
1870
1871 Even if @var{name}s are often specified on the command line, they
1872 can also be read from a text file in the file system, using the
1873 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1874
1875 If you don't use any file name arguments, @option{--append} (@option{-r}),
1876 @option{--delete} and @option{--concatenate} (@option{--catenate},
1877 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1878 will usually yield a diagnostic and inhibit @command{tar} execution.
1879 The other operations of @command{tar} (@option{--list},
1880 @option{--extract}, @option{--compare}, and @option{--update})
1881 will act on the entire contents of the archive.
1882
1883 @anchor{exit status}
1884 @cindex exit status
1885 @cindex return status
1886 Besides successful exits, @GNUTAR{} may fail for
1887 many reasons. Some reasons correspond to bad usage, that is, when the
1888 @command{tar} command line is improperly written. Errors may be
1889 encountered later, while processing the archive or the files. Some
1890 errors are recoverable, in which case the failure is delayed until
1891 @command{tar} has completed all its work. Some errors are such that
1892 it would be not meaningful, or at least risky, to continue processing:
1893 @command{tar} then aborts processing immediately. All abnormal exits,
1894 whether immediate or delayed, should always be clearly diagnosed on
1895 @code{stderr}, after a line stating the nature of the error.
1896
1897 Possible exit codes of @GNUTAR{} are summarized in the following
1898 table:
1899
1900 @table @asis
1901 @item 0
1902 @samp{Successful termination}.
1903
1904 @item 1
1905 @samp{Some files differ}. If tar was invoked with @option{--compare}
1906 (@option{--diff}, @option{-d}) command line option, this means that
1907 some files in the archive differ from their disk counterparts
1908 (@pxref{compare}). If tar was given @option{--create},
1909 @option{--append} or @option{--update} option, this exit code means
1910 that some files were changed while being archived and so the resulting
1911 archive does not contain the exact copy of the file set.
1912
1913 @item 2
1914 @samp{Fatal error}. This means that some fatal, unrecoverable error
1915 occurred.
1916 @end table
1917
1918 If @command{tar} has invoked a subprocess and that subprocess exited with a
1919 nonzero exit code, @command{tar} exits with that code as well.
1920 This can happen, for example, if @command{tar} was given some
1921 compression option (@pxref{gzip}) and the external compressor program
1922 failed. Another example is @command{rmt} failure during backup to the
1923 remote device (@pxref{Remote Tape Server}).
1924
1925 @node using tar options
1926 @section Using @command{tar} Options
1927
1928 @GNUTAR{} has a total of eight operating modes which
1929 allow you to perform a variety of tasks. You are required to choose
1930 one operating mode each time you employ the @command{tar} program by
1931 specifying one, and only one operation as an argument to the
1932 @command{tar} command (the corresponding options may be found
1933 at @ref{frequent operations} and @ref{Operations}). Depending on
1934 circumstances, you may also wish to customize how the chosen operating
1935 mode behaves. For example, you may wish to change the way the output
1936 looks, or the format of the files that you wish to archive may require
1937 you to do something special in order to make the archive look right.
1938
1939 You can customize and control @command{tar}'s performance by running
1940 @command{tar} with one or more options (such as @option{--verbose}
1941 (@option{-v}), which we used in the tutorial). As we said in the
1942 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1943 their name suggests) optional. Depending on the operating mode, you
1944 may specify one or more options. Different options will have different
1945 effects, but in general they all change details of the operation, such
1946 as archive format, archive name, or level of user interaction. Some
1947 options make sense with all operating modes, while others are
1948 meaningful only with particular modes. You will likely use some
1949 options frequently, while you will only use others infrequently, or
1950 not at all. (A full list of options is available in @pxref{All Options}.)
1951
1952 @vrindex TAR_OPTIONS, environment variable
1953 @anchor{TAR_OPTIONS}
1954 The @env{TAR_OPTIONS} environment variable specifies default options to
1955 be placed in front of any explicit options. For example, if
1956 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1957 if the two options @option{-v} and @option{--unlink-first} had been
1958 specified before any explicit options. Option specifications are
1959 separated by whitespace. A backslash escapes the next character, so it
1960 can be used to specify an option containing whitespace or a backslash.
1961
1962 Note that @command{tar} options are case sensitive. For example, the
1963 options @option{-T} and @option{-t} are different; the first requires an
1964 argument for stating the name of a file providing a list of @var{name}s,
1965 while the second does not require an argument and is another way to
1966 write @option{--list} (@option{-t}).
1967
1968 In addition to the eight operations, there are many options to
1969 @command{tar}, and three different styles for writing both: long (mnemonic)
1970 form, short form, and old style. These styles are discussed below.
1971 Both the options and the operations can be written in any of these three
1972 styles.
1973
1974 @FIXME{menu at end of this node. need to think of an actual outline
1975 for this chapter; probably do that after stuff from chapter 4 is
1976 incorporated.}
1977
1978 @node Styles
1979 @section The Three Option Styles
1980
1981 There are three styles for writing operations and options to the command
1982 line invoking @command{tar}. The different styles were developed at
1983 different times during the history of @command{tar}. These styles will be
1984 presented below, from the most recent to the oldest.
1985
1986 Some options must take an argument@footnote{For example, @option{--file}
1987 (@option{-f}) takes the name of an archive file as an argument. If
1988 you do not supply an archive file name, @command{tar} will use a
1989 default, but this can be confusing; thus, we recommend that you always
1990 supply a specific archive file name.}. Where you @emph{place} the
1991 arguments generally depends on which style of options you choose. We
1992 will detail specific information relevant to each option style in the
1993 sections on the different option styles, below. The differences are
1994 subtle, yet can often be very important; incorrect option placement
1995 can cause you to overwrite a number of important files. We urge you
1996 to note these differences, and only use the option style(s) which
1997 makes the most sense to you until you feel comfortable with the others.
1998
1999 Some options @emph{may} take an argument. Such options may have at
2000 most long and short forms, they do not have old style equivalent. The
2001 rules for specifying an argument for such options are stricter than
2002 those for specifying mandatory arguments. Please, pay special
2003 attention to them.
2004
2005 @menu
2006 * Long Options:: Long Option Style
2007 * Short Options:: Short Option Style
2008 * Old Options:: Old Option Style
2009 * Mixing:: Mixing Option Styles
2010 @end menu
2011
2012 @node Long Options
2013 @subsection Long Option Style
2014
2015 @cindex long options
2016 @cindex options, long style
2017 @cindex options, GNU style
2018 @cindex options, mnemonic names
2019 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2020 dashes in a row, e.g., @option{--list}. The long names are more clear than
2021 their corresponding short or old names. It sometimes happens that a
2022 single long option has many different names which are
2023 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2024 long option names can be given unique abbreviations. For example,
2025 @option{--cre} can be used in place of @option{--create} because there is no
2026 other long option which begins with @samp{cre}. (One way to find
2027 this out is by trying it and seeing what happens; if a particular
2028 abbreviation could represent more than one option, @command{tar} will tell
2029 you that that abbreviation is ambiguous and you'll know that that
2030 abbreviation won't work. You may also choose to run @samp{tar --help}
2031 to see a list of options. Be aware that if you run @command{tar} with a
2032 unique abbreviation for the long name of an option you didn't want to
2033 use, you are stuck; @command{tar} will perform the command as ordered.)
2034
2035 Long options are meant to be obvious and easy to remember, and their
2036 meanings are generally easier to discern than those of their
2037 corresponding short options (see below). For example:
2038
2039 @smallexample
2040 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2041 @end smallexample
2042
2043 @noindent
2044 gives a fairly good set of hints about what the command does, even
2045 for those not fully acquainted with @command{tar}.
2046
2047 @cindex arguments to long options
2048 @cindex long options with mandatory arguments
2049 Long options which require arguments take those arguments
2050 immediately following the option name. There are two ways of
2051 specifying a mandatory argument. It can be separated from the
2052 option name either by an equal sign, or by any amount of
2053 white space characters. For example, the @option{--file} option (which
2054 tells the name of the @command{tar} archive) is given a file such as
2055 @file{archive.tar} as argument by using any of the following notations:
2056 @option{--file=archive.tar} or @option{--file archive.tar}.
2057
2058 @cindex optional arguments to long options
2059 @cindex long options with optional arguments
2060 In contrast, optional arguments must always be introduced using
2061 an equal sign. For example, the @option{--backup} option takes
2062 an optional argument specifying backup type. It must be used
2063 as @option{--backup=@var{backup-type}}.
2064
2065 @node Short Options
2066 @subsection Short Option Style
2067
2068 @cindex short options
2069 @cindex options, short style
2070 @cindex options, traditional
2071 Most options also have a @dfn{short option} name. Short options start with
2072 a single dash, and are followed by a single character, e.g., @option{-t}
2073 (which is equivalent to @option{--list}). The forms are absolutely
2074 identical in function; they are interchangeable.
2075
2076 The short option names are faster to type than long option names.
2077
2078 @cindex arguments to short options
2079 @cindex short options with mandatory arguments
2080 Short options which require arguments take their arguments immediately
2081 following the option, usually separated by white space. It is also
2082 possible to stick the argument right after the short option name, using
2083 no intervening space. For example, you might write @w{@option{-f
2084 archive.tar}} or @option{-farchive.tar} instead of using
2085 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2086 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2087 specific archive, here named @file{archive.tar}.
2088
2089 @cindex optional arguments to short options
2090 @cindex short options with optional arguments
2091 Short options which take optional arguments take their arguments
2092 immediately following the option letter, @emph{without any intervening
2093 white space characters}.
2094
2095 Short options' letters may be clumped together, but you are not
2096 required to do this (as compared to old options; see below). When
2097 short options are clumped as a set, use one (single) dash for them
2098 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2099 such a set is allowed to have an argument@footnote{Clustering many
2100 options, the last of which has an argument, is a rather opaque way to
2101 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2102 even be made helpful enough for considering such usages as invalid.}.
2103
2104 When the options are separated, the argument for each option which requires
2105 an argument directly follows that option, as is usual for Unix programs.
2106 For example:
2107
2108 @smallexample
2109 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2110 @end smallexample
2111
2112 If you reorder short options' locations, be sure to move any arguments
2113 that belong to them. If you do not move the arguments properly, you may
2114 end up overwriting files.
2115
2116 @node Old Options
2117 @subsection Old Option Style
2118 @cindex options, old style
2119 @cindex old option style
2120 @cindex option syntax, traditional
2121
2122 As far as we know, all @command{tar} programs, @acronym{GNU} and
2123 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2124 argument does not start with @samp{-}, it is assumed to specify option
2125 letters. @GNUTAR{} supports old options not only for historical
2126 reasons, but also because many people are used to them. If the first
2127 argument does not start with a dash, you are announcing the old option
2128 style instead of the short option style; old options are decoded
2129 differently.
2130
2131 Like short options, old options are single letters. However, old options
2132 must be written together as a single clumped set, without spaces separating
2133 them or dashes preceding them. This set
2134 of letters must be the first to appear on the command line, after the
2135 @command{tar} program name and some white space; old options cannot appear
2136 anywhere else. The letter of an old option is exactly the same letter as
2137 the corresponding short option. For example, the old option @samp{t} is
2138 the same as the short option @option{-t}, and consequently, the same as the
2139 long option @option{--list}. So for example, the command @w{@samp{tar
2140 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2141
2142 @cindex arguments to old options
2143 @cindex old options with mandatory arguments
2144 When options that need arguments are given together with the command,
2145 all the associated arguments follow, in the same order as the options.
2146 Thus, the example given previously could also be written in the old
2147 style as follows:
2148
2149 @smallexample
2150 $ @kbd{tar cvbf 20 /dev/rmt0}
2151 @end smallexample
2152
2153 @noindent
2154 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2155 the argument of @option{-f}.
2156
2157 The old style syntax can make it difficult to match
2158 option letters with their corresponding arguments, and is often
2159 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2160 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2161 argument for @option{-f}, and @option{-v} does not have a corresponding
2162 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2163 /dev/rmt0}} is clearer, putting all arguments next to the option they
2164 pertain to.
2165
2166 If you want to reorder the letters in the old option argument, be
2167 sure to reorder any corresponding argument appropriately.
2168
2169 This old way of writing @command{tar} options can surprise even experienced
2170 users. For example, the two commands:
2171
2172 @smallexample
2173 @kbd{tar cfz archive.tar.gz file}
2174 @kbd{tar -cfz archive.tar.gz file}
2175 @end smallexample
2176
2177 @noindent
2178 are quite different. The first example uses @file{archive.tar.gz} as
2179 the value for option @samp{f} and recognizes the option @samp{z}. The
2180 second example, however, uses @file{z} as the value for option
2181 @samp{f} --- probably not what was intended.
2182
2183 This second example could be corrected in many ways, among which the
2184 following are equivalent:
2185
2186 @smallexample
2187 @kbd{tar -czf archive.tar.gz file}
2188 @kbd{tar -cf archive.tar.gz -z file}
2189 @kbd{tar cf archive.tar.gz -z file}
2190 @end smallexample
2191
2192 @node Mixing
2193 @subsection Mixing Option Styles
2194
2195 @cindex options, mixing different styles
2196 All three styles may be intermixed in a single @command{tar} command,
2197 so long as the rules for each style are fully
2198 respected@footnote{Before @GNUTAR{} version 1.11.6,
2199 a bug prevented intermixing old style options with long options in
2200 some cases.}. Old style options and either of the modern styles of
2201 options may be mixed within a single @command{tar} command. However,
2202 old style options must be introduced as the first arguments only,
2203 following the rule for old options (old options must appear directly
2204 after the @command{tar} command and some white space). Modern options
2205 may be given only after all arguments to the old options have been
2206 collected. If this rule is not respected, a modern option might be
2207 falsely interpreted as the value of the argument to one of the old
2208 style options.
2209
2210 For example, all the following commands are wholly equivalent, and
2211 illustrate the many combinations and orderings of option styles.
2212
2213 @smallexample
2214 @kbd{tar --create --file=archive.tar}
2215 @kbd{tar --create -f archive.tar}
2216 @kbd{tar --create -farchive.tar}
2217 @kbd{tar --file=archive.tar --create}
2218 @kbd{tar --file=archive.tar -c}
2219 @kbd{tar -c --file=archive.tar}
2220 @kbd{tar -c -f archive.tar}
2221 @kbd{tar -c -farchive.tar}
2222 @kbd{tar -cf archive.tar}
2223 @kbd{tar -cfarchive.tar}
2224 @kbd{tar -f archive.tar --create}
2225 @kbd{tar -f archive.tar -c}
2226 @kbd{tar -farchive.tar --create}
2227 @kbd{tar -farchive.tar -c}
2228 @kbd{tar c --file=archive.tar}
2229 @kbd{tar c -f archive.tar}
2230 @kbd{tar c -farchive.tar}
2231 @kbd{tar cf archive.tar}
2232 @kbd{tar f archive.tar --create}
2233 @kbd{tar f archive.tar -c}
2234 @kbd{tar fc archive.tar}
2235 @end smallexample
2236
2237 On the other hand, the following commands are @emph{not} equivalent to
2238 the previous set:
2239
2240 @smallexample
2241 @kbd{tar -f -c archive.tar}
2242 @kbd{tar -fc archive.tar}
2243 @kbd{tar -fcarchive.tar}
2244 @kbd{tar -farchive.tarc}
2245 @kbd{tar cfarchive.tar}
2246 @end smallexample
2247
2248 @noindent
2249 These last examples mean something completely different from what the
2250 user intended (judging based on the example in the previous set which
2251 uses long options, whose intent is therefore very clear). The first
2252 four specify that the @command{tar} archive would be a file named
2253 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2254 respectively. The first two examples also specify a single non-option,
2255 @var{name} argument having the value @samp{archive.tar}. The last
2256 example contains only old style option letters (repeating option
2257 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2258 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2259 the first sentence of this paragraph..}
2260
2261 @node All Options
2262 @section All @command{tar} Options
2263
2264 The coming manual sections contain an alphabetical listing of all
2265 @command{tar} operations and options, with brief descriptions and
2266 cross-references to more in-depth explanations in the body of the manual.
2267 They also contain an alphabetically arranged table of the short option
2268 forms with their corresponding long option. You can use this table as
2269 a reference for deciphering @command{tar} commands in scripts.
2270
2271 @menu
2272 * Operation Summary::
2273 * Option Summary::
2274 * Short Option Summary::
2275 @end menu
2276
2277 @node Operation Summary
2278 @subsection Operations
2279
2280 @table @option
2281
2282 @opsummary{append}
2283 @item --append
2284 @itemx -r
2285
2286 Appends files to the end of the archive. @xref{append}.
2287
2288 @opsummary{catenate}
2289 @item --catenate
2290 @itemx -A
2291
2292 Same as @option{--concatenate}. @xref{concatenate}.
2293
2294 @opsummary{compare}
2295 @item --compare
2296 @itemx -d
2297
2298 Compares archive members with their counterparts in the file
2299 system, and reports differences in file size, mode, owner,
2300 modification date and contents. @xref{compare}.
2301
2302 @opsummary{concatenate}
2303 @item --concatenate
2304 @itemx -A
2305
2306 Appends other @command{tar} archives to the end of the archive.
2307 @xref{concatenate}.
2308
2309 @opsummary{create}
2310 @item --create
2311 @itemx -c
2312
2313 Creates a new @command{tar} archive. @xref{create}.
2314
2315 @opsummary{delete}
2316 @item --delete
2317
2318 Deletes members from the archive. Don't try this on an archive on a
2319 tape! @xref{delete}.
2320
2321 @opsummary{diff}
2322 @item --diff
2323 @itemx -d
2324
2325 Same @option{--compare}. @xref{compare}.
2326
2327 @opsummary{extract}
2328 @item --extract
2329 @itemx -x
2330
2331 Extracts members from the archive into the file system. @xref{extract}.
2332
2333 @opsummary{get}
2334 @item --get
2335 @itemx -x
2336
2337 Same as @option{--extract}. @xref{extract}.
2338
2339 @opsummary{list}
2340 @item --list
2341 @itemx -t
2342
2343 Lists the members in an archive. @xref{list}.
2344
2345 @opsummary{update}
2346 @item --update
2347 @itemx -u
2348
2349 Adds files to the end of the archive, but only if they are newer than
2350 their counterparts already in the archive, or if they do not already
2351 exist in the archive. @xref{update}.
2352
2353 @end table
2354
2355 @node Option Summary
2356 @subsection @command{tar} Options
2357
2358 @table @option
2359
2360 @opsummary{absolute-names}
2361 @item --absolute-names
2362 @itemx -P
2363
2364 Normally when creating an archive, @command{tar} strips an initial
2365 @samp{/} from member names, and when extracting from an archive @command{tar}
2366 treats names specially if they have initial @samp{/} or internal
2367 @samp{..}. This option disables that behavior. @xref{absolute}.
2368
2369 @opsummary{after-date}
2370 @item --after-date
2371
2372 (See @option{--newer}, @pxref{after})
2373
2374 @opsummary{anchored}
2375 @item --anchored
2376 A pattern must match an initial subsequence of the name's components.
2377 @xref{controlling pattern-matching}.
2378
2379 @opsummary{atime-preserve}
2380 @item --atime-preserve
2381 @itemx --atime-preserve=replace
2382 @itemx --atime-preserve=system
2383
2384 Attempt to preserve the access time of files when reading them. This
2385 option currently is effective only on files that you own, unless you
2386 have superuser privileges.
2387
2388 @option{--atime-preserve=replace} remembers the access time of a file
2389 before reading it, and then restores the access time afterwards. This
2390 may cause problems if other programs are reading the file at the same
2391 time, as the times of their accesses will be lost. On most platforms
2392 restoring the access time also requires @command{tar} to restore the
2393 data modification time too, so this option may also cause problems if
2394 other programs are writing the file at the same time (@command{tar} attempts
2395 to detect this situation, but cannot do so reliably due to race
2396 conditions). Worse, on most platforms restoring the access time also
2397 updates the status change time, which means that this option is
2398 incompatible with incremental backups.
2399
2400 @option{--atime-preserve=system} avoids changing time stamps on files,
2401 without interfering with time stamp updates
2402 caused by other programs, so it works better with incremental backups.
2403 However, it requires a special @code{O_NOATIME} option from the
2404 underlying operating and file system implementation, and it also requires
2405 that searching directories does not update their access times. As of
2406 this writing (November 2005) this works only with Linux, and only with
2407 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2408 way to know whether this feature actually works. Sometimes
2409 @command{tar} knows that it does not work, and if you use
2410 @option{--atime-preserve=system} then @command{tar} complains and
2411 exits right away. But other times @command{tar} might think that the
2412 option works when it actually does not.
2413
2414 Currently @option{--atime-preserve} with no operand defaults to
2415 @option{--atime-preserve=replace}, but this may change in the future
2416 as support for @option{--atime-preserve=system} improves.
2417
2418 If your operating or file system does not support
2419 @option{--atime-preserve=@-system}, you might be able to preserve access
2420 times reliably by using the @command{mount} command. For example,
2421 you can mount the file system read-only, or access the file system via
2422 a read-only loopback mount, or use the @samp{noatime} mount option
2423 available on some systems. However, mounting typically requires
2424 superuser privileges and can be a pain to manage.
2425
2426 @opsummary{auto-compress}
2427 @item --auto-compress
2428 @itemx -a
2429
2430 During a @option{--create} operation, enables automatic compressed
2431 format recognition based on the archive suffix. The effect of this
2432 option is cancelled by @option{--no-auto-compress}. @xref{gzip}.
2433
2434 @opsummary{backup}
2435 @item --backup=@var{backup-type}
2436
2437 Rather than deleting files from the file system, @command{tar} will
2438 back them up using simple or numbered backups, depending upon
2439 @var{backup-type}. @xref{backup}.
2440
2441 @opsummary{block-number}
2442 @item --block-number
2443 @itemx -R
2444
2445 With this option present, @command{tar} prints error messages for read errors
2446 with the block number in the archive file. @xref{block-number}.
2447
2448 @opsummary{blocking-factor}
2449 @item --blocking-factor=@var{blocking}
2450 @itemx -b @var{blocking}
2451
2452 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2453 record. @xref{Blocking Factor}.
2454
2455 @opsummary{bzip2}
2456 @item --bzip2
2457 @itemx -j
2458
2459 This option tells @command{tar} to read or write archives through
2460 @code{bzip2}. @xref{gzip}.
2461
2462 @opsummary{check-device}
2463 @item --check-device
2464 Check device numbers when creating a list of modified files for
2465 incremental archiving. This is the default. @xref{device numbers},
2466 for a detailed description.
2467
2468 @opsummary{checkpoint}
2469 @item --checkpoint[=@var{number}]
2470
2471 This option directs @command{tar} to print periodic checkpoint
2472 messages as it reads through the archive. It is intended for when you
2473 want a visual indication that @command{tar} is still running, but
2474 don't want to see @option{--verbose} output. You can also instruct
2475 @command{tar} to execute a list of actions on each checkpoint, see
2476 @option{--checkpoint-action} below. For a detailed description, see
2477 @ref{checkpoints}.
2478
2479 @opsummary{checkpoint-action}
2480 @item --checkpoint-action=@var{action}
2481 Instruct @command{tar} to execute an action upon hitting a
2482 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2483 for a complete description.
2484
2485 The @var{action} argument can be one of the following:
2486
2487 @table @asis
2488 @item bell
2489 Produce an audible bell on the console.
2490
2491 @item dot
2492 @itemx .
2493 Print a single dot on the standard listing stream.
2494
2495 @item echo
2496 Display a textual message on the standard error, with the status and
2497 number of the checkpoint. This is the default.
2498
2499 @item echo=@var{string}
2500 Display @var{string} on the standard error. Before output, the string
2501 is subject to meta-character expansion.
2502
2503 @item exec=@var{command}
2504 Execute the given @var{command}.
2505
2506 @item sleep=@var{time}
2507 Wait for @var{time} seconds.
2508
2509 @item ttyout=@var{string}
2510 Output @var{string} on the current console (@file{/dev/tty}).
2511 @end table
2512
2513 Several @option{--checkpoint-action} options can be specified. The
2514 supplied actions will be executed in order of their appearance in the
2515 command line.
2516
2517 Using @option{--checkpoint-action} without @option{--checkpoint}
2518 assumes default checkpoint frequency of one checkpoint per 10 records.
2519
2520 @opsummary{check-links}
2521 @item --check-links
2522 @itemx -l
2523 If this option was given, @command{tar} will check the number of links
2524 dumped for each processed file. If this number does not match the
2525 total number of hard links for the file, a warning message will be
2526 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2527 synonym for @option{--one-file-system}. The current semantics, which
2528 complies to UNIX98, was introduced with version
2529 1.15.91. @xref{Changes}, for more information.}.
2530
2531 @xref{hard links}.
2532
2533 @opsummary{compress}
2534 @opsummary{uncompress}
2535 @item --compress
2536 @itemx --uncompress
2537 @itemx -Z
2538
2539 @command{tar} will use the @command{compress} program when reading or
2540 writing the archive. This allows you to directly act on archives
2541 while saving space. @xref{gzip}.
2542
2543 @opsummary{confirmation}
2544 @item --confirmation
2545
2546 (See @option{--interactive}.) @xref{interactive}.
2547
2548 @opsummary{delay-directory-restore}
2549 @item --delay-directory-restore
2550
2551 Delay setting modification times and permissions of extracted
2552 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2553
2554 @opsummary{dereference}
2555 @item --dereference
2556 @itemx -h
2557
2558 When reading or writing a file to be archived, @command{tar} accesses
2559 the file that a symbolic link points to, rather than the symlink
2560 itself. @xref{dereference}.
2561
2562 @opsummary{directory}
2563 @item --directory=@var{dir}
2564 @itemx -C @var{dir}
2565
2566 When this option is specified, @command{tar} will change its current directory
2567 to @var{dir} before performing any operations. When this option is used
2568 during archive creation, it is order sensitive. @xref{directory}.
2569
2570 @opsummary{exclude}
2571 @item --exclude=@var{pattern}
2572
2573 When performing operations, @command{tar} will skip files that match
2574 @var{pattern}. @xref{exclude}.
2575
2576 @opsummary{exclude-backups}
2577 @item --exclude-backups
2578 Exclude backup and lock files. @xref{exclude,, exclude-backups}.
2579
2580 @opsummary{exclude-from}
2581 @item --exclude-from=@var{file}
2582 @itemx -X @var{file}
2583
2584 Similar to @option{--exclude}, except @command{tar} will use the list of
2585 patterns in the file @var{file}. @xref{exclude}.
2586
2587 @opsummary{exclude-caches}
2588 @item --exclude-caches
2589
2590 Exclude from dump any directory containing a valid cache directory
2591 tag file, but still dump the directory node and the tag file itself.
2592
2593 @xref{exclude,, exclude-caches}.
2594
2595 @opsummary{exclude-caches-under}
2596 @item --exclude-caches-under
2597
2598 Exclude from dump any directory containing a valid cache directory
2599 tag file, but still dump the directory node itself.
2600
2601 @xref{exclude}.
2602
2603 @opsummary{exclude-caches-all}
2604 @item --exclude-caches-all
2605
2606 Exclude from dump any directory containing a valid cache directory
2607 tag file. @xref{exclude}.
2608
2609 @opsummary{exclude-tag}
2610 @item --exclude-tag=@var{file}
2611
2612 Exclude from dump any directory containing file named @var{file}, but
2613 dump the directory node and @var{file} itself. @xref{exclude,, exclude-tag}.
2614
2615 @opsummary{exclude-tag-under}
2616 @item --exclude-tag-under=@var{file}
2617
2618 Exclude from dump the contents of any directory containing file
2619 named @var{file}, but dump the directory node itself. @xref{exclude,,
2620 exclude-tag-under}.
2621
2622 @opsummary{exclude-tag-all}
2623 @item --exclude-tag-all=@var{file}
2624
2625 Exclude from dump any directory containing file named @var{file}.
2626 @xref{exclude,,exclude-tag-all}.
2627
2628 @opsummary{exclude-vcs}
2629 @item --exclude-vcs
2630
2631 Exclude from dump directories and files, that are internal for some
2632 widely used version control systems.
2633
2634 @xref{exclude,,exclude-vcs}.
2635
2636 @opsummary{file}
2637 @item --file=@var{archive}
2638 @itemx -f @var{archive}
2639
2640 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2641 performs operations on, rather than @command{tar}'s compilation dependent
2642 default. @xref{file tutorial}.
2643
2644 @opsummary{files-from}
2645 @item --files-from=@var{file}
2646 @itemx -T @var{file}
2647
2648 @command{tar} will use the contents of @var{file} as a list of archive members
2649 or files to operate on, in addition to those specified on the
2650 command-line. @xref{files}.
2651
2652 @opsummary{force-local}
2653 @item --force-local
2654
2655 Forces @command{tar} to interpret the file name given to @option{--file}
2656 as a local file, even if it looks like a remote tape drive name.
2657 @xref{local and remote archives}.
2658
2659 @opsummary{format}
2660 @item --format=@var{format}
2661 @itemx -H @var{format}
2662
2663 Selects output archive format. @var{Format} may be one of the
2664 following:
2665
2666 @table @samp
2667 @item v7
2668 Creates an archive that is compatible with Unix V7 @command{tar}.
2669
2670 @item oldgnu
2671 Creates an archive that is compatible with GNU @command{tar} version
2672 1.12 or earlier.
2673
2674 @item gnu
2675 Creates archive in GNU tar 1.13 format. Basically it is the same as
2676 @samp{oldgnu} with the only difference in the way it handles long
2677 numeric fields.
2678
2679 @item ustar
2680 Creates a @acronym{POSIX.1-1988} compatible archive.
2681
2682 @item posix
2683 Creates a @acronym{POSIX.1-2001 archive}.
2684
2685 @end table
2686
2687 @xref{Formats}, for a detailed discussion of these formats.
2688
2689 @opsummary{full-time}
2690 @item --full-time
2691 This option instructs @command{tar} to print file times to their full
2692 resolution. Usually this means 1-second resolution, but that depends
2693 on the underlying file system. The @option{--full-time} option takes
2694 effect only when detailed output (verbosity level 2 or higher) has
2695 been requested using the @option{--verbose} option, e.g., when listing
2696 or extracting archives:
2697
2698 @smallexample
2699 $ @kbd{tar -t -v --full-time -f archive.tar}
2700 @end smallexample
2701
2702 @noindent
2703 or, when creating an archive:
2704
2705 @smallexample
2706 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2707 @end smallexample
2708
2709 Notice, thar when creating the archive you need to specify
2710 @option{--verbose} twice to get a detailed output (@pxref{verbose
2711 tutorial}).
2712
2713 @opsummary{group}
2714 @item --group=@var{group}
2715
2716 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2717 rather than the group from the source file. @var{group} can specify a
2718 symbolic name, or a numeric @acronym{ID}, or both as
2719 @var{name}:@var{id}. @xref{override}.
2720
2721 Also see the comments for the @option{--owner=@var{user}} option.
2722
2723 @opsummary{gzip}
2724 @opsummary{gunzip}
2725 @opsummary{ungzip}
2726 @item --gzip
2727 @itemx --gunzip
2728 @itemx --ungzip
2729 @itemx -z
2730
2731 This option tells @command{tar} to read or write archives through
2732 @command{gzip}, allowing @command{tar} to directly operate on several
2733 kinds of compressed archives transparently. @xref{gzip}.
2734
2735 @opsummary{hard-dereference}
2736 @item --hard-dereference
2737 When creating an archive, dereference hard links and store the files
2738 they refer to, instead of creating usual hard link members.
2739
2740 @xref{hard links}.
2741
2742 @opsummary{help}
2743 @item --help
2744 @itemx -?
2745
2746 @command{tar} will print out a short message summarizing the operations and
2747 options to @command{tar} and exit. @xref{help}.
2748
2749 @opsummary{ignore-case}
2750 @item --ignore-case
2751 Ignore case when matching member or file names with
2752 patterns. @xref{controlling pattern-matching}.
2753
2754 @opsummary{ignore-command-error}
2755 @item --ignore-command-error
2756 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2757
2758 @opsummary{ignore-failed-read}
2759 @item --ignore-failed-read
2760
2761 Do not exit unsuccessfully merely because an unreadable file was encountered.
2762 @xref{Ignore Failed Read}.
2763
2764 @opsummary{ignore-zeros}
2765 @item --ignore-zeros
2766 @itemx -i
2767
2768 With this option, @command{tar} will ignore zeroed blocks in the
2769 archive, which normally signals EOF. @xref{Reading}.
2770
2771 @opsummary{incremental}
2772 @item --incremental
2773 @itemx -G
2774
2775 Informs @command{tar} that it is working with an old
2776 @acronym{GNU}-format incremental backup archive. It is intended
2777 primarily for backwards compatibility only. @xref{Incremental Dumps},
2778 for a detailed discussion of incremental archives.
2779
2780 @opsummary{index-file}
2781 @item --index-file=@var{file}
2782
2783 Send verbose output to @var{file} instead of to standard output.
2784
2785 @opsummary{info-script}
2786 @opsummary{new-volume-script}
2787 @item --info-script=@var{script-file}
2788 @itemx --new-volume-script=@var{script-file}
2789 @itemx -F @var{script-file}
2790
2791 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2792 at the end of each tape. If @var{script-file} exits with nonzero status,
2793 @command{tar} fails immediately. @xref{info-script}, for a detailed
2794 discussion of @var{script-file}.
2795
2796 @opsummary{interactive}
2797 @item --interactive
2798 @itemx --confirmation
2799 @itemx -w
2800
2801 Specifies that @command{tar} should ask the user for confirmation before
2802 performing potentially destructive options, such as overwriting files.
2803 @xref{interactive}.
2804
2805 @opsummary{keep-newer-files}
2806 @item --keep-newer-files
2807
2808 Do not replace existing files that are newer than their archive copies
2809 when extracting files from an archive.
2810
2811 @opsummary{keep-old-files}
2812 @item --keep-old-files
2813 @itemx -k
2814
2815 Do not overwrite existing files when extracting files from an
2816 archive. Return error if such files exist. See also
2817 @ref{--skip-old-files}.
2818
2819 @xref{Keep Old Files}.
2820
2821 @opsummary{label}
2822 @item --label=@var{name}
2823 @itemx -V @var{name}
2824
2825 When creating an archive, instructs @command{tar} to write @var{name}
2826 as a name record in the archive. When extracting or listing archives,
2827 @command{tar} will only operate on archives that have a label matching
2828 the pattern specified in @var{name}. @xref{Tape Files}.
2829
2830 @opsummary{level}
2831 @item --level=@var{n}
2832 Force incremental backup of level @var{n}. As of @GNUTAR version
2833 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2834 file, thereby forcing the level 0 dump. Other values of @var{n} are
2835 effectively ignored. @xref{--level=0}, for details and examples.
2836
2837 The use of this option is valid only in conjunction with the
2838 @option{--listed-incremental} option. @xref{Incremental Dumps},
2839 for a detailed description.
2840
2841 @opsummary{listed-incremental}
2842 @item --listed-incremental=@var{snapshot-file}
2843 @itemx -g @var{snapshot-file}
2844
2845 During a @option{--create} operation, specifies that the archive that
2846 @command{tar} creates is a new @acronym{GNU}-format incremental
2847 backup, using @var{snapshot-file} to determine which files to backup.
2848 With other operations, informs @command{tar} that the archive is in
2849 incremental format. @xref{Incremental Dumps}.
2850
2851 @opsummary{lzip}
2852 @item --lzip
2853
2854 This option tells @command{tar} to read or write archives through
2855 @command{lzip}. @xref{gzip}.
2856
2857 @opsummary{lzma}
2858 @item --lzma
2859
2860 This option tells @command{tar} to read or write archives through
2861 @command{lzma}. @xref{gzip}.
2862
2863 @item --lzop
2864
2865 This option tells @command{tar} to read or write archives through
2866 @command{lzop}. @xref{gzip}.
2867
2868 @opsummary{mode}
2869 @item --mode=@var{permissions}
2870
2871 When adding files to an archive, @command{tar} will use
2872 @var{permissions} for the archive members, rather than the permissions
2873 from the files. @var{permissions} can be specified either as an octal
2874 number or as symbolic permissions, like with
2875 @command{chmod}. @xref{override}.
2876
2877 @opsummary{mtime}
2878 @item --mtime=@var{date}
2879
2880 When adding files to an archive, @command{tar} will use @var{date} as
2881 the modification time of members when creating archives, instead of
2882 their actual modification times. The value of @var{date} can be
2883 either a textual date representation (@pxref{Date input formats}) or a
2884 name of the existing file, starting with @samp{/} or @samp{.}. In the
2885 latter case, the modification time of that file is used. @xref{override}.
2886
2887 @opsummary{multi-volume}
2888 @item --multi-volume
2889 @itemx -M
2890
2891 Informs @command{tar} that it should create or otherwise operate on a
2892 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2893
2894 @opsummary{new-volume-script}
2895 @item --new-volume-script
2896
2897 (see @option{--info-script})
2898
2899 @opsummary{newer}
2900 @item --newer=@var{date}
2901 @itemx --after-date=@var{date}
2902 @itemx -N
2903
2904 When creating an archive, @command{tar} will only add files that have changed
2905 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2906 is taken to be the name of a file whose data modification time specifies
2907 the date. @xref{after}.
2908
2909 @opsummary{newer-mtime}
2910 @item --newer-mtime=@var{date}
2911
2912 Like @option{--newer}, but add only files whose
2913 contents have changed (as opposed to just @option{--newer}, which will
2914 also back up files for which any status information has
2915 changed). @xref{after}.
2916
2917 @opsummary{no-anchored}
2918 @item --no-anchored
2919 An exclude pattern can match any subsequence of the name's components.
2920 @xref{controlling pattern-matching}.
2921
2922 @opsummary{no-auto-compress}
2923 @item --no-auto-compress
2924
2925 Disables automatic compressed format recognition based on the archive
2926 suffix. @xref{--auto-compress}. @xref{gzip}.
2927
2928 @opsummary{no-check-device}
2929 @item --no-check-device
2930 Do not check device numbers when creating a list of modified files
2931 for incremental archiving. @xref{device numbers}, for
2932 a detailed description.
2933
2934 @opsummary{no-delay-directory-restore}
2935 @item --no-delay-directory-restore
2936
2937 Modification times and permissions of extracted
2938 directories are set when all files from this directory have been
2939 extracted. This is the default.
2940 @xref{Directory Modification Times and Permissions}.
2941
2942 @opsummary{no-ignore-case}
2943 @item --no-ignore-case
2944 Use case-sensitive matching.
2945 @xref{controlling pattern-matching}.
2946
2947 @opsummary{no-ignore-command-error}
2948 @item --no-ignore-command-error
2949 Print warnings about subprocesses that terminated with a nonzero exit
2950 code. @xref{Writing to an External Program}.
2951
2952 @opsummary{no-null}
2953 @item --no-null
2954
2955 If the @option{--null} option was given previously, this option
2956 cancels its effect, so that any following @option{--files-from}
2957 options will expect their file lists to be newline-terminated.
2958
2959 @opsummary{no-overwrite-dir}
2960 @item --no-overwrite-dir
2961
2962 Preserve metadata of existing directories when extracting files
2963 from an archive. @xref{Overwrite Old Files}.
2964
2965 @opsummary{no-quote-chars}
2966 @item --no-quote-chars=@var{string}
2967 Remove characters listed in @var{string} from the list of quoted
2968 characters set by the previous @option{--quote-chars} option
2969 (@pxref{quoting styles}).
2970
2971 @opsummary{no-recursion}
2972 @item --no-recursion
2973
2974 With this option, @command{tar} will not recurse into directories.
2975 @xref{recurse}.
2976
2977 @opsummary{no-same-owner}
2978 @item --no-same-owner
2979 @itemx -o
2980
2981 When extracting an archive, do not attempt to preserve the owner
2982 specified in the @command{tar} archive. This the default behavior
2983 for ordinary users.
2984
2985 @opsummary{no-same-permissions}
2986 @item --no-same-permissions
2987
2988 When extracting an archive, subtract the user's umask from files from
2989 the permissions specified in the archive. This is the default behavior
2990 for ordinary users.
2991
2992 @opsummary{no-seek}
2993 @item --no-seek
2994
2995 The archive media does not support seeks to arbitrary
2996 locations. Usually @command{tar} determines automatically whether
2997 the archive can be seeked or not. Use this option to disable this
2998 mechanism.
2999
3000 @opsummary{no-unquote}
3001 @item --no-unquote
3002 Treat all input file or member names literally, do not interpret
3003 escape sequences. @xref{input name quoting}.
3004
3005 @opsummary{no-wildcards}
3006 @item --no-wildcards
3007 Do not use wildcards.
3008 @xref{controlling pattern-matching}.
3009
3010 @opsummary{no-wildcards-match-slash}
3011 @item --no-wildcards-match-slash
3012 Wildcards do not match @samp{/}.
3013 @xref{controlling pattern-matching}.
3014
3015 @opsummary{null}
3016 @item --null
3017
3018 When @command{tar} is using the @option{--files-from} option, this option
3019 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
3020 @command{tar} can correctly work with file names that contain newlines.
3021 @xref{nul}.
3022
3023 @opsummary{numeric-owner}
3024 @item --numeric-owner
3025
3026 This option will notify @command{tar} that it should use numeric user
3027 and group IDs when creating a @command{tar} file, rather than names.
3028 @xref{Attributes}.
3029
3030 @item -o
3031 The function of this option depends on the action @command{tar} is
3032 performing. When extracting files, @option{-o} is a synonym for
3033 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3034 restoring ownership of files being extracted.
3035
3036 When creating an archive, it is a synonym for
3037 @option{--old-archive}. This behavior is for compatibility
3038 with previous versions of @GNUTAR{}, and will be
3039 removed in future releases.
3040
3041 @xref{Changes}, for more information.
3042
3043 @opsummary{occurrence}
3044 @item --occurrence[=@var{number}]
3045
3046 This option can be used in conjunction with one of the subcommands
3047 @option{--delete}, @option{--diff}, @option{--extract} or
3048 @option{--list} when a list of files is given either on the command
3049 line or via @option{-T} option.
3050
3051 This option instructs @command{tar} to process only the @var{number}th
3052 occurrence of each named file. @var{Number} defaults to 1, so
3053
3054 @smallexample
3055 tar -x -f archive.tar --occurrence filename
3056 @end smallexample
3057
3058 @noindent
3059 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3060 and will terminate without scanning to the end of the archive.
3061
3062 @opsummary{old-archive}
3063 @item --old-archive
3064 Synonym for @option{--format=v7}.
3065
3066 @opsummary{one-file-system}
3067 @item --one-file-system
3068 Used when creating an archive. Prevents @command{tar} from recursing into
3069 directories that are on different file systems from the current
3070 directory.
3071
3072 @opsummary{overwrite}
3073 @item --overwrite
3074
3075 Overwrite existing files and directory metadata when extracting files
3076 from an archive. @xref{Overwrite Old Files}.
3077
3078 @opsummary{overwrite-dir}
3079 @item --overwrite-dir
3080
3081 Overwrite the metadata of existing directories when extracting files
3082 from an archive. @xref{Overwrite Old Files}.
3083
3084 @opsummary{owner}
3085 @item --owner=@var{user}
3086
3087 Specifies that @command{tar} should use @var{user} as the owner of members
3088 when creating archives, instead of the user associated with the source
3089 file. @var{user} can specify a symbolic name, or a numeric
3090 @acronym{ID}, or both as @var{name}:@var{id}.
3091 @xref{override}.
3092
3093 This option does not affect extraction from archives.
3094
3095 @opsummary{pax-option}
3096 @item --pax-option=@var{keyword-list}
3097 This option enables creation of the archive in @acronym{POSIX.1-2001}
3098 format (@pxref{posix}) and modifies the way @command{tar} handles the
3099 extended header keywords. @var{Keyword-list} is a comma-separated
3100 list of keyword options. @xref{PAX keywords}, for a detailed
3101 discussion.
3102
3103 @opsummary{portability}
3104 @item --portability
3105 @itemx --old-archive
3106 Synonym for @option{--format=v7}.
3107
3108 @opsummary{posix}
3109 @item --posix
3110 Same as @option{--format=posix}.
3111
3112 @opsummary{preserve}
3113 @item --preserve
3114
3115 Synonymous with specifying both @option{--preserve-permissions} and
3116 @option{--same-order}. @xref{Setting Access Permissions}.
3117
3118 @opsummary{preserve-order}
3119 @item --preserve-order
3120
3121 (See @option{--same-order}; @pxref{Reading}.)
3122
3123 @opsummary{preserve-permissions}
3124 @opsummary{same-permissions}
3125 @item --preserve-permissions
3126 @itemx --same-permissions
3127 @itemx -p
3128
3129 When @command{tar} is extracting an archive, it normally subtracts the
3130 users' umask from the permissions specified in the archive and uses
3131 that number as the permissions to create the destination file.
3132 Specifying this option instructs @command{tar} that it should use the
3133 permissions directly from the archive. @xref{Setting Access Permissions}.
3134
3135 @opsummary{quote-chars}
3136 @item --quote-chars=@var{string}
3137 Always quote characters from @var{string}, even if the selected
3138 quoting style would not quote them (@pxref{quoting styles}).
3139
3140 @opsummary{quoting-style}
3141 @item --quoting-style=@var{style}
3142 Set quoting style to use when printing member and file names
3143 (@pxref{quoting styles}). Valid @var{style} values are:
3144 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3145 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3146 style is @code{escape}, unless overridden while configuring the
3147 package.
3148
3149 @opsummary{read-full-records}
3150 @item --read-full-records
3151 @itemx -B
3152
3153 Specifies that @command{tar} should reblock its input, for reading
3154 from pipes on systems with buggy implementations. @xref{Reading}.
3155
3156 @opsummary{record-size}
3157 @item --record-size=@var{size}[@var{suf}]
3158
3159 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3160 archive. The argument can be suffixed with a @dfn{size suffix}, e.g.
3161 @option{--record-size=10K} for 10 Kilobytes. @xref{size-suffixes},
3162 for a list of valid suffixes. @xref{Blocking Factor}, for a detailed
3163 description of this option.
3164
3165 @opsummary{recursion}
3166 @item --recursion
3167
3168 With this option, @command{tar} recurses into directories (default).
3169 @xref{recurse}.
3170
3171 @opsummary{recursive-unlink}
3172 @item --recursive-unlink
3173
3174 Remove existing
3175 directory hierarchies before extracting directories of the same name
3176 from the archive. @xref{Recursive Unlink}.
3177
3178 @opsummary{remove-files}
3179 @item --remove-files
3180
3181 Directs @command{tar} to remove the source file from the file system after
3182 appending it to an archive. @xref{remove files}.
3183
3184 @opsummary{restrict}
3185 @item --restrict
3186
3187 Disable use of some potentially harmful @command{tar} options.
3188 Currently this option disables shell invocation from multi-volume menu
3189 (@pxref{Using Multiple Tapes}).
3190
3191 @opsummary{rmt-command}
3192 @item --rmt-command=@var{cmd}
3193
3194 Notifies @command{tar} that it should use @var{cmd} instead of
3195 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3196
3197 @opsummary{rsh-command}
3198 @item --rsh-command=@var{cmd}
3199
3200 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3201 devices. @xref{Device}.
3202
3203 @opsummary{same-order}
3204 @item --same-order
3205 @itemx --preserve-order
3206 @itemx -s
3207
3208 This option is an optimization for @command{tar} when running on machines with
3209 small amounts of memory. It informs @command{tar} that the list of file
3210 arguments has already been sorted to match the order of files in the
3211 archive. @xref{Reading}.
3212
3213 @opsummary{same-owner}
3214 @item --same-owner
3215
3216 When extracting an archive, @command{tar} will attempt to preserve the owner
3217 specified in the @command{tar} archive with this option present.
3218 This is the default behavior for the superuser; this option has an
3219 effect only for ordinary users. @xref{Attributes}.
3220
3221 @opsummary{same-permissions}
3222 @item --same-permissions
3223
3224 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3225
3226 @opsummary{seek}
3227 @item --seek
3228 @itemx -n
3229
3230 Assume that the archive media supports seeks to arbitrary
3231 locations. Usually @command{tar} determines automatically whether
3232 the archive can be seeked or not. This option is intended for use
3233 in cases when such recognition fails. It takes effect only if the
3234 archive is open for reading (e.g. with @option{--list} or
3235 @option{--extract} options).
3236
3237 @opsummary{show-defaults}
3238 @item --show-defaults
3239
3240 Displays the default options used by @command{tar} and exits
3241 successfully. This option is intended for use in shell scripts.
3242 Here is an example of what you can see using this option:
3243
3244 @smallexample
3245 $ @kbd{tar --show-defaults}
3246 --format=gnu -f- -b20 --quoting-style=escape
3247 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3248 @end smallexample
3249
3250 @noindent
3251 Notice, that this option outputs only one line. The example output
3252 above has been split to fit page boundaries.
3253
3254 @opsummary{show-omitted-dirs}
3255 @item --show-omitted-dirs
3256
3257 Instructs @command{tar} to mention the directories it is skipping when
3258 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3259
3260 @opsummary{show-transformed-names}
3261 @opsummary{show-stored-names}
3262 @item --show-transformed-names
3263 @itemx --show-stored-names
3264
3265 Display file or member names after applying any transformations
3266 (@pxref{transform}). In particular, when used in conjunction with one of
3267 the archive creation operations it instructs @command{tar} to list the
3268 member names stored in the archive, as opposed to the actual file
3269 names. @xref{listing member and file names}.
3270
3271 @opsummary{skip-old-files}
3272 @item --skip-old-files
3273
3274 Do not overwrite existing files when extracting files from an
3275 archive. @xref{Keep Old Files}.
3276
3277 This option differs from @option{--keep-old-files} in that it does not
3278 treat such files as an error, instead it just silently avoids
3279 overwriting them.
3280
3281 The @option{--warning=existing-file} option can be used together with
3282 this option to produce warning messages about existing old files
3283 (@pxref{warnings}).
3284
3285 @opsummary{sparse}
3286 @item --sparse
3287 @itemx -S
3288
3289 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3290 sparse files efficiently. @xref{sparse}.
3291
3292 @opsummary{sparse-version}
3293 @item --sparse-version=@var{version}
3294
3295 Specifies the @dfn{format version} to use when archiving sparse
3296 files. Implies @option{--sparse}. @xref{sparse}. For the description
3297 of the supported sparse formats, @xref{Sparse Formats}.
3298
3299 @opsummary{starting-file}
3300 @item --starting-file=@var{name}
3301 @itemx -K @var{name}
3302
3303 This option affects extraction only; @command{tar} will skip extracting
3304 files in the archive until it finds one that matches @var{name}.
3305 @xref{Scarce}.
3306
3307 @opsummary{strip-components}
3308 @item --strip-components=@var{number}
3309 Strip given @var{number} of leading components from file names before
3310 extraction. For example, if archive @file{archive.tar} contained
3311 @file{/some/file/name}, then running
3312
3313 @smallexample
3314 tar --extract --file archive.tar --strip-components=2
3315 @end smallexample
3316
3317 @noindent
3318 would extract this file to file @file{name}.
3319
3320 @opsummary{suffix}
3321 @item --suffix=@var{suffix}
3322
3323 Alters the suffix @command{tar} uses when backing up files from the default
3324 @samp{~}. @xref{backup}.
3325
3326 @opsummary{tape-length}
3327 @item --tape-length=@var{num}[@var{suf}]
3328 @itemx -L @var{num}[@var{suf}]
3329
3330 Specifies the length of tapes that @command{tar} is writing as being
3331 @w{@var{num} x 1024} bytes long. If optional @var{suf} is given, it
3332 specifies a multiplicative factor to be used instead of 1024. For
3333 example, @samp{-L2M} means 2 megabytes. @xref{size-suffixes}, for a
3334 list of allowed suffixes. @xref{Using Multiple Tapes}, for a detailed
3335 discussion of this option.
3336
3337 @opsummary{test-label}
3338 @item --test-label
3339
3340 Reads the volume label. If an argument is specified, test whether it
3341 matches the volume label. @xref{--test-label option}.
3342
3343 @opsummary{to-command}
3344 @item --to-command=@var{command}
3345
3346 During extraction @command{tar} will pipe extracted files to the
3347 standard input of @var{command}. @xref{Writing to an External Program}.
3348
3349 @opsummary{to-stdout}
3350 @item --to-stdout
3351 @itemx -O
3352
3353 During extraction, @command{tar} will extract files to stdout rather
3354 than to the file system. @xref{Writing to Standard Output}.
3355
3356 @opsummary{totals}
3357 @item --totals[=@var{signo}]
3358
3359 Displays the total number of bytes transferred when processing an
3360 archive. If an argument is given, these data are displayed on
3361 request, when signal @var{signo} is delivered to @command{tar}.
3362 @xref{totals}.
3363
3364 @opsummary{touch}
3365 @item --touch
3366 @itemx -m
3367
3368 Sets the data modification time of extracted files to the extraction time,
3369 rather than the data modification time stored in the archive.
3370 @xref{Data Modification Times}.
3371
3372 @opsummary{transform}
3373 @opsummary{xform}
3374 @item --transform=@var{sed-expr}
3375 @itemx --xform=@var{sed-expr}
3376 Transform file or member names using @command{sed} replacement expression
3377 @var{sed-expr}. For example,
3378
3379 @smallexample
3380 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3381 @end smallexample
3382
3383 @noindent
3384 will add to @file{archive} files from the current working directory,
3385 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3386 discussion, @xref{transform}.
3387
3388 To see transformed member names in verbose listings, use
3389 @option{--show-transformed-names} option
3390 (@pxref{show-transformed-names}).
3391
3392 @opsummary{uncompress}
3393 @item --uncompress
3394
3395 (See @option{--compress}, @pxref{gzip})
3396
3397 @opsummary{ungzip}
3398 @item --ungzip
3399
3400 (See @option{--gzip}, @pxref{gzip})
3401
3402 @opsummary{unlink-first}
3403 @item --unlink-first
3404 @itemx -U
3405
3406 Directs @command{tar} to remove the corresponding file from the file
3407 system before extracting it from the archive. @xref{Unlink First}.
3408
3409 @opsummary{unquote}
3410 @item --unquote
3411 Enable unquoting input file or member names (default). @xref{input
3412 name quoting}.
3413
3414 @opsummary{use-compress-program}
3415 @item --use-compress-program=@var{prog}
3416 @itemx -I=@var{prog}
3417
3418 Instructs @command{tar} to access the archive through @var{prog}, which is
3419 presumed to be a compression program of some sort. @xref{gzip}.
3420
3421 @opsummary{utc}
3422 @item --utc
3423
3424 Display file modification dates in @acronym{UTC}. This option implies
3425 @option{--verbose}.
3426
3427 @opsummary{verbose}
3428 @item --verbose
3429 @itemx -v
3430
3431 Specifies that @command{tar} should be more verbose about the
3432 operations it is performing. This option can be specified multiple
3433 times for some operations to increase the amount of information displayed.
3434 @xref{verbose}.
3435
3436 @opsummary{verify}
3437 @item --verify
3438 @itemx -W
3439
3440 Verifies that the archive was correctly written when creating an
3441 archive. @xref{verify}.
3442
3443 @opsummary{version}
3444 @item --version
3445
3446 Print information about the program's name, version, origin and legal
3447 status, all on standard output, and then exit successfully.
3448 @xref{help}.
3449
3450 @opsummary{volno-file}
3451 @item --volno-file=@var{file}
3452
3453 Used in conjunction with @option{--multi-volume}. @command{tar} will
3454 keep track of which volume of a multi-volume archive it is working in
3455 @var{file}. @xref{volno-file}.
3456
3457 @opsummary{warning}
3458 @item --warning=@var{keyword}
3459
3460 Enable or disable warning messages identified by @var{keyword}. The
3461 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3462 @xref{warnings}.
3463
3464 @opsummary{wildcards}
3465 @item --wildcards
3466 Use wildcards when matching member names with patterns.
3467 @xref{controlling pattern-matching}.
3468
3469 @opsummary{wildcards-match-slash}
3470 @item --wildcards-match-slash
3471 Wildcards match @samp{/}.
3472 @xref{controlling pattern-matching}.
3473
3474 @opsummary{xz}
3475 @item --xz
3476 @itemx -J
3477 Use @command{xz} for compressing or decompressing the archives. @xref{gzip}.
3478
3479 @end table
3480
3481 @node Short Option Summary
3482 @subsection Short Options Cross Reference
3483
3484 Here is an alphabetized list of all of the short option forms, matching
3485 them with the equivalent long option.
3486
3487 @multitable @columnfractions 0.20 0.80
3488 @headitem Short Option @tab Reference
3489
3490 @item -A @tab @ref{--concatenate}.
3491
3492 @item -B @tab @ref{--read-full-records}.
3493
3494 @item -C @tab @ref{--directory}.
3495
3496 @item -F @tab @ref{--info-script}.
3497
3498 @item -G @tab @ref{--incremental}.
3499
3500 @item -J @tab @ref{--xz}.
3501
3502 @item -K @tab @ref{--starting-file}.
3503
3504 @item -L @tab @ref{--tape-length}.
3505
3506 @item -M @tab @ref{--multi-volume}.
3507
3508 @item -N @tab @ref{--newer}.
3509
3510 @item -O @tab @ref{--to-stdout}.
3511
3512 @item -P @tab @ref{--absolute-names}.
3513
3514 @item -R @tab @ref{--block-number}.
3515
3516 @item -S @tab @ref{--sparse}.
3517
3518 @item -T @tab @ref{--files-from}.
3519
3520 @item -U @tab @ref{--unlink-first}.
3521
3522 @item -V @tab @ref{--label}.
3523
3524 @item -W @tab @ref{--verify}.
3525
3526 @item -X @tab @ref{--exclude-from}.
3527
3528 @item -Z @tab @ref{--compress}.
3529
3530 @item -b @tab @ref{--blocking-factor}.
3531
3532 @item -c @tab @ref{--create}.
3533
3534 @item -d @tab @ref{--compare}.
3535
3536 @item -f @tab @ref{--file}.
3537
3538 @item -g @tab @ref{--listed-incremental}.
3539
3540 @item -h @tab @ref{--dereference}.
3541
3542 @item -i @tab @ref{--ignore-zeros}.
3543
3544 @item -j @tab @ref{--bzip2}.
3545
3546 @item -k @tab @ref{--keep-old-files}.
3547
3548 @item -l @tab @ref{--check-links}.
3549
3550 @item -m @tab @ref{--touch}.
3551
3552 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3553 @ref{--portability}.
3554
3555 The latter usage is deprecated. It is retained for compatibility with
3556 the earlier versions of @GNUTAR{}. In future releases
3557 @option{-o} will be equivalent to @option{--no-same-owner} only.
3558
3559 @item -p @tab @ref{--preserve-permissions}.
3560
3561 @item -r @tab @ref{--append}.
3562
3563 @item -s @tab @ref{--same-order}.
3564
3565 @item -t @tab @ref{--list}.
3566
3567 @item -u @tab @ref{--update}.
3568
3569 @item -v @tab @ref{--verbose}.
3570
3571 @item -w @tab @ref{--interactive}.
3572
3573 @item -x @tab @ref{--extract}.
3574
3575 @item -z @tab @ref{--gzip}.
3576
3577 @end multitable
3578
3579 @node help
3580 @section @GNUTAR{} documentation
3581
3582 @cindex Getting program version number
3583 @opindex version
3584 @cindex Version of the @command{tar} program
3585 Being careful, the first thing is really checking that you are using
3586 @GNUTAR{}, indeed. The @option{--version} option
3587 causes @command{tar} to print information about its name, version,
3588 origin and legal status, all on standard output, and then exit
3589 successfully. For example, @w{@samp{tar --version}} might print:
3590
3591 @smallexample
3592 tar (GNU tar) @value{VERSION}
3593 Copyright (C) 2013 Free Software Foundation, Inc.
3594 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3595 This is free software: you are free to change and redistribute it.
3596 There is NO WARRANTY, to the extent permitted by law.
3597
3598 Written by John Gilmore and Jay Fenlason.
3599 @end smallexample
3600
3601 @noindent
3602 The first occurrence of @samp{tar} in the result above is the program
3603 name in the package (for example, @command{rmt} is another program),
3604 while the second occurrence of @samp{tar} is the name of the package
3605 itself, containing possibly many programs. The package is currently
3606 named @samp{tar}, after the name of the main program it
3607 contains@footnote{There are plans to merge the @command{cpio} and
3608 @command{tar} packages into a single one which would be called
3609 @code{paxutils}. So, who knows if, one of this days, the
3610 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3611 paxutils) 3.2}}.}.
3612
3613 @cindex Obtaining help
3614 @cindex Listing all @command{tar} options
3615 @xopindex{help, introduction}
3616 Another thing you might want to do is checking the spelling or meaning
3617 of some particular @command{tar} option, without resorting to this
3618 manual, for once you have carefully read it. @GNUTAR{}
3619 has a short help feature, triggerable through the
3620 @option{--help} option. By using this option, @command{tar} will
3621 print a usage message listing all available options on standard
3622 output, then exit successfully, without doing anything else and
3623 ignoring all other options. Even if this is only a brief summary, it
3624 may be several screens long. So, if you are not using some kind of
3625 scrollable window, you might prefer to use something like:
3626
3627 @smallexample
3628 $ @kbd{tar --help | less}
3629 @end smallexample
3630
3631 @noindent
3632 presuming, here, that you like using @command{less} for a pager. Other
3633 popular pagers are @command{more} and @command{pg}. If you know about some
3634 @var{keyword} which interests you and do not want to read all the
3635 @option{--help} output, another common idiom is doing:
3636
3637 @smallexample
3638 tar --help | grep @var{keyword}
3639 @end smallexample
3640
3641 @noindent
3642 for getting only the pertinent lines. Notice, however, that some
3643 @command{tar} options have long description lines and the above
3644 command will list only the first of them.
3645
3646 The exact look of the option summary displayed by @kbd{tar --help} is
3647 configurable. @xref{Configuring Help Summary}, for a detailed description.
3648
3649 @opindex usage
3650 If you only wish to check the spelling of an option, running @kbd{tar
3651 --usage} may be a better choice. This will display a terse list of
3652 @command{tar} options without accompanying explanations.
3653
3654 The short help output is quite succinct, and you might have to get
3655 back to the full documentation for precise points. If you are reading
3656 this paragraph, you already have the @command{tar} manual in some
3657 form. This manual is available in a variety of forms from
3658 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3659 distribution, provided you have @TeX{} already installed somewhere,
3660 and a laser printer around. Just configure the distribution, execute
3661 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3662 usual way (contact your local guru to know how). If @GNUTAR{}
3663 has been conveniently installed at your place, this
3664 manual is also available in interactive, hypertextual form as an Info
3665 file. Just call @w{@samp{info tar}} or, if you do not have the
3666 @command{info} program handy, use the Info reader provided within
3667 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3668
3669 There is currently no @code{man} page for @GNUTAR{}.
3670 If you observe such a @code{man} page on the system you are running,
3671 either it does not belong to @GNUTAR{}, or it has not
3672 been produced by @acronym{GNU}. Some package maintainers convert
3673 @kbd{tar --help} output to a man page, using @command{help2man}. In
3674 any case, please bear in mind that the authoritative source of
3675 information about @GNUTAR{} is this Texinfo documentation.
3676
3677 @node defaults
3678 @section Obtaining @GNUTAR{} default values
3679
3680 @opindex show-defaults
3681 @GNUTAR{} has some predefined defaults that are used when you do not
3682 explicitly specify another values. To obtain a list of such
3683 defaults, use @option{--show-defaults} option. This will output the
3684 values in the form of @command{tar} command line options:
3685
3686 @smallexample
3687 @group
3688 $ @kbd{tar --show-defaults}
3689 --format=gnu -f- -b20 --quoting-style=escape
3690 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3691 @end group
3692 @end smallexample
3693
3694 @noindent
3695 Notice, that this option outputs only one line. The example output above
3696 has been split to fit page boundaries.
3697
3698 @noindent
3699 The above output shows that this version of @GNUTAR{} defaults to
3700 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3701 output as the archive, if no @option{--file} option has been given
3702 (@pxref{file tutorial}), the default blocking factor is 20
3703 (@pxref{Blocking Factor}). It also shows the default locations where
3704 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3705
3706 @node verbose
3707 @section Checking @command{tar} progress
3708
3709 Typically, @command{tar} performs most operations without reporting any
3710 information to the user except error messages. When using @command{tar}
3711 with many options, particularly ones with complicated or
3712 difficult-to-predict behavior, it is possible to make serious mistakes.
3713 @command{tar} provides several options that make observing @command{tar}
3714 easier. These options cause @command{tar} to print information as it
3715 progresses in its job, and you might want to use them just for being
3716 more careful about what is going on, or merely for entertaining
3717 yourself. If you have encountered a problem when operating on an
3718 archive, however, you may need more information than just an error
3719 message in order to solve the problem. The following options can be
3720 helpful diagnostic tools.
3721
3722 @cindex Verbose operation
3723 @opindex verbose
3724 Normally, the @option{--list} (@option{-t}) command to list an archive
3725 prints just the file names (one per line) and the other commands are
3726 silent. When used with most operations, the @option{--verbose}
3727 (@option{-v}) option causes @command{tar} to print the name of each
3728 file or archive member as it is processed. This and the other options
3729 which make @command{tar} print status information can be useful in
3730 monitoring @command{tar}.
3731
3732 With @option{--create} or @option{--extract}, @option{--verbose} used
3733 once just prints the names of the files or members as they are processed.
3734 Using it twice causes @command{tar} to print a longer listing
3735 (@xref{verbose member listing}, for the description) for each member.
3736 Since @option{--list} already prints the names of the members,
3737 @option{--verbose} used once with @option{--list} causes @command{tar}
3738 to print an @samp{ls -l} type listing of the files in the archive.
3739 The following examples both extract members with long list output:
3740
3741 @smallexample
3742 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3743 $ @kbd{tar xvvf archive.tar}
3744 @end smallexample
3745
3746 Verbose output appears on the standard output except when an archive is
3747 being written to the standard output, as with @samp{tar --create
3748 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
3749 installer let standard output be the default archive). In that case
3750 @command{tar} writes verbose output to the standard error stream.
3751
3752 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3753 verbose output to @var{file} rather than to standard output or standard
3754 error.
3755
3756 @anchor{totals}
3757 @cindex Obtaining total status information
3758 @opindex totals
3759 The @option{--totals} option causes @command{tar} to print on the
3760 standard error the total amount of bytes transferred when processing
3761 an archive. When creating or appending to an archive, this option
3762 prints the number of bytes written to the archive and the average
3763 speed at which they have been written, e.g.:
3764
3765 @smallexample
3766 @group
3767 $ @kbd{tar -c -f archive.tar --totals /home}
3768 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3769 @end group
3770 @end smallexample
3771
3772 When reading an archive, this option displays the number of bytes
3773 read:
3774
3775 @smallexample
3776 @group
3777 $ @kbd{tar -x -f archive.tar --totals}
3778 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3779 @end group
3780 @end smallexample
3781
3782 Finally, when deleting from an archive, the @option{--totals} option
3783 displays both numbers plus number of bytes removed from the archive:
3784
3785 @smallexample
3786 @group
3787 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3788 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3789 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3790 Total bytes deleted: 1474048
3791 @end group
3792 @end smallexample
3793
3794 You can also obtain this information on request. When
3795 @option{--totals} is used with an argument, this argument is
3796 interpreted as a symbolic name of a signal, upon delivery of which the
3797 statistics is to be printed:
3798
3799 @table @option
3800 @item --totals=@var{signo}
3801 Print statistics upon delivery of signal @var{signo}. Valid arguments
3802 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3803 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3804 accepted.
3805 @end table
3806
3807 Both forms of @option{--totals} option can be used simultaneously.
3808 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3809 extract all members from its default archive and print statistics
3810 after finishing the extraction, as well as when receiving signal
3811 @code{SIGUSR1}.
3812
3813 @anchor{Progress information}
3814 @cindex Progress information
3815 The @option{--checkpoint} option prints an occasional message
3816 as @command{tar} reads or writes the archive. It is designed for
3817 those who don't need the more detailed (and voluminous) output of
3818 @option{--block-number} (@option{-R}), but do want visual confirmation
3819 that @command{tar} is actually making forward progress. By default it
3820 prints a message each 10 records read or written. This can be changed
3821 by giving it a numeric argument after an equal sign:
3822
3823 @smallexample
3824 $ @kbd{tar -c --checkpoint=1000} /var
3825 tar: Write checkpoint 1000
3826 tar: Write checkpoint 2000
3827 tar: Write checkpoint 3000
3828 @end smallexample
3829
3830 This example shows the default checkpoint message used by
3831 @command{tar}. If you place a dot immediately after the equal
3832 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3833 actually a shortcut for @option{--checkpoint=@var{n}
3834 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3835
3836 @smallexample
3837 $ @kbd{tar -c --checkpoint=.1000} /var
3838 ...
3839 @end smallexample
3840
3841 The @option{--checkpoint} option provides a flexible mechanism for
3842 executing arbitrary actions upon hitting checkpoints, see the next
3843 section (@pxref{checkpoints}), for more information on it.
3844
3845 @opindex show-omitted-dirs
3846 @anchor{show-omitted-dirs}
3847 The @option{--show-omitted-dirs} option, when reading an archive---with
3848 @option{--list} or @option{--extract}, for example---causes a message
3849 to be printed for each directory in the archive which is skipped.
3850 This happens regardless of the reason for skipping: the directory might
3851 not have been named on the command line (implicitly or explicitly),
3852 it might be excluded by the use of the
3853 @option{--exclude=@var{pattern}} option, or some other reason.
3854
3855 @opindex block-number
3856 @cindex Block number where error occurred
3857 @anchor{block-number}
3858 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3859 every message it would normally produce, the block number within the
3860 archive where the message was triggered. Also, supplementary messages
3861 are triggered when reading blocks full of NULs, or when hitting end of
3862 file on the archive. As of now, if the archive is properly terminated
3863 with a NUL block, the reading of the file may stop before end of file
3864 is met, so the position of end of file will not usually show when
3865 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3866 drains the archive before exiting when reading the
3867 archive from a pipe.
3868
3869 @cindex Error message, block number of
3870 This option is especially useful when reading damaged archives, since
3871 it helps pinpoint the damaged sections. It can also be used with
3872 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3873 choose among several backup tapes when retrieving a file later, in
3874 favor of the tape where the file appears earliest (closest to the
3875 front of the tape). @xref{backup}.
3876
3877 @node checkpoints
3878 @section Checkpoints
3879 @cindex checkpoints, defined
3880 @opindex checkpoint
3881 @opindex checkpoint-action
3882
3883 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3884 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3885 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3886 periodically execute arbitrary actions.
3887
3888 The checkpoint facility is enabled using the following option:
3889
3890 @table @option
3891 @xopindex{checkpoint, defined}
3892 @item --checkpoint[=@var{n}]
3893 Schedule checkpoints before writing or reading each @var{n}th record.
3894 The default value for @var{n} is 10.
3895 @end table
3896
3897 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3898 These actions include: pausing, displaying textual messages, and
3899 executing arbitrary external programs. Actions are defined using
3900 the @option{--checkpoint-action} option.
3901
3902 @table @option
3903 @xopindex{checkpoint-action, defined}
3904 @item --checkpoint-action=@var{action}
3905 Execute an @var{action} at each checkpoint.
3906 @end table
3907
3908 @cindex @code{echo}, checkpoint action
3909 The simplest value of @var{action} is @samp{echo}. It instructs
3910 @command{tar} to display the default message on the standard error
3911 stream upon arriving at each checkpoint. The default message is (in
3912 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3913 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3914 Here, @var{n} represents ordinal number of the checkpoint.
3915
3916 In another locales, translated versions of this message are used.
3917
3918 This is the default action, so running:
3919
3920 @smallexample
3921 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3922 @end smallexample
3923
3924 @noindent
3925 is equivalent to:
3926
3927 @smallexample
3928 $ @kbd{tar -c --checkpoint=1000} /var
3929 @end smallexample
3930
3931 The @samp{echo} action also allows to supply a customized message.
3932 You do so by placing an equals sign and the message right after it,
3933 e.g.:
3934
3935 @smallexample
3936 --checkpoint-action="echo=Hit %s checkpoint #%u"
3937 @end smallexample
3938
3939 The @samp{%s} and @samp{%u} in the above example are
3940 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3941 the @dfn{type} of the checkpoint: @samp{write} or
3942 @samp{read} (or a corresponding translated version in locales other
3943 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3944 the ordinal number of the checkpoint. Thus, the above example could
3945 produce the following output when used with the @option{--create}
3946 option:
3947
3948 @smallexample
3949 tar: Hit write checkpoint #10
3950 tar: Hit write checkpoint #20
3951 tar: Hit write checkpoint #30
3952 @end smallexample
3953
3954 Aside from meta-character expansion, the message string is subject to
3955 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3956 replaced with their corresponding @acronym{ASCII} characters
3957 (@pxref{escape sequences}). E.g. the following action will produce an
3958 audible bell and the message described above at each checkpoint:
3959
3960 @smallexample
3961 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3962 @end smallexample
3963
3964 @cindex @code{bell}, checkpoint action
3965 There is also a special action which produces an audible signal:
3966 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3967 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3968 whereas @samp{echo='\a'} sends it to the standard error.
3969
3970 @cindex @code{ttyout}, checkpoint action
3971 The @samp{ttyout=@var{string}} action outputs @var{string} to
3972 @file{/dev/tty}, so it can be used even if the standard output is
3973 redirected elsewhere. The @var{string} is subject to the same
3974 modifications as with @samp{echo} action. In contrast to the latter,
3975 @samp{ttyout} does not prepend @command{tar} executable name to the
3976 string, nor does it output a newline after it. For example, the
3977 following action will print the checkpoint message at the same screen
3978 line, overwriting any previous message:
3979
3980 @smallexample
3981 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3982 @end smallexample
3983
3984 @cindex @code{dot}, checkpoint action
3985 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3986 instructs @command{tar} to print a single dot on the standard listing
3987 stream, e.g.:
3988
3989 @smallexample
3990 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3991 ...
3992 @end smallexample
3993
3994 For compatibility with previous @GNUTAR{} versions, this action can
3995 be abbreviated by placing a dot in front of the checkpoint frequency,
3996 as shown in the previous section.
3997
3998 @cindex @code{sleep}, checkpoint action
3999 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4000 amount of seconds. The following example will stop for 30 seconds at each
4001 checkpoint:
4002
4003 @smallexample
4004 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4005 @end smallexample
4006
4007 @cindex @code{exec}, checkpoint action
4008 Finally, the @code{exec} action executes a given external program.
4009 For example:
4010
4011 @smallexample
4012 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4013 @end smallexample
4014
4015 This program is executed using @command{/bin/sh -c}, with no
4016 additional arguments. Its exit code is ignored. It gets a copy of
4017 @command{tar}'s environment plus the following variables:
4018
4019 @table @env
4020 @vrindex TAR_VERSION, checkpoint script environment
4021 @item TAR_VERSION
4022 @GNUTAR{} version number.
4023
4024 @vrindex TAR_ARCHIVE, checkpoint script environment
4025 @item TAR_ARCHIVE
4026 The name of the archive @command{tar} is processing.
4027
4028 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4029 @item TAR_BLOCKING_FACTOR
4030 Current blocking factor (@pxref{Blocking}).
4031
4032 @vrindex TAR_CHECKPOINT, checkpoint script environment
4033 @item TAR_CHECKPOINT
4034 Number of the checkpoint.
4035
4036 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4037 @item TAR_SUBCOMMAND
4038 A short option describing the operation @command{tar} is executing.
4039 @xref{Operations}, for a complete list of subcommand options.
4040
4041 @vrindex TAR_FORMAT, checkpoint script environment
4042 @item TAR_FORMAT
4043 Format of the archive being processed. @xref{Formats}, for a complete
4044 list of archive format names.
4045 @end table
4046
4047 Any number of actions can be defined, by supplying several
4048 @option{--checkpoint-action} options in the command line. For
4049 example, the command below displays two messages, pauses
4050 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4051
4052 @example
4053 @group
4054 $ @kbd{tar -c -f arc.tar \
4055 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4056 --checkpoint-action='echo=Sleeping for 30 seconds' \
4057 --checkpoint-action='sleep=30' \
4058 --checkpoint-action='exec=/sbin/cpoint'}
4059 @end group
4060 @end example
4061
4062 This example also illustrates the fact that
4063 @option{--checkpoint-action} can be used without
4064 @option{--checkpoint}. In this case, the default checkpoint frequency
4065 (at each 10th record) is assumed.
4066
4067 @node warnings
4068 @section Controlling Warning Messages
4069
4070 Sometimes, while performing the requested task, @GNUTAR{} notices
4071 some conditions that are not exactly errors, but which the user
4072 should be aware of. When this happens, @command{tar} issues a
4073 @dfn{warning message} describing the condition. Warning messages
4074 are output to the standard error and they do not affect the exit
4075 code of @command{tar} command.
4076
4077 @xopindex{warning, explained}
4078 @GNUTAR{} allows the user to suppress some or all of its warning
4079 messages:
4080
4081 @table @option
4082 @item --warning=@var{keyword}
4083 Control display of the warning messages identified by @var{keyword}.
4084 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4085 suppressed. Otherwise, they are enabled.
4086
4087 Multiple @option{--warning} messages accumulate.
4088
4089 The tables below list allowed values for @var{keyword} along with the
4090 warning messages they control.
4091 @end table
4092
4093 @subheading Keywords controlling @command{tar} operation
4094 @table @asis
4095 @kwindex all
4096 @item all
4097 Enable all warning messages. This is the default.
4098 @kwindex none
4099 @item none
4100 Disable all warning messages.
4101 @kwindex filename-with-nuls
4102 @cindex @samp{file name read contains nul character}, warning message
4103 @item filename-with-nuls
4104 @samp{%s: file name read contains nul character}
4105 @kwindex alone-zero-block
4106 @cindex @samp{A lone zero block at}, warning message
4107 @item alone-zero-block
4108 @samp{A lone zero block at %s}
4109 @end table
4110
4111 @subheading Keywords applicable for @command{tar --create}
4112 @table @asis
4113 @kwindex cachedir
4114 @cindex @samp{contains a cache directory tag}, warning message
4115 @item cachedir
4116 @samp{%s: contains a cache directory tag %s; %s}
4117 @kwindex file-shrank
4118 @cindex @samp{File shrank by %s bytes}, warning message
4119 @item file-shrank
4120 @samp{%s: File shrank by %s bytes; padding with zeros}
4121 @kwindex xdev
4122 @cindex @samp{file is on a different filesystem}, warning message
4123 @item xdev
4124 @samp{%s: file is on a different filesystem; not dumped}
4125 @kwindex file-ignored
4126 @cindex @samp{Unknown file type; file ignored}, warning message
4127 @cindex @samp{socket ignored}, warning message
4128 @cindex @samp{door ignored}, warning message
4129 @item file-ignored
4130 @samp{%s: Unknown file type; file ignored}
4131 @*@samp{%s: socket ignored}
4132 @*@samp{%s: door ignored}
4133 @kwindex file-unchanged
4134 @cindex @samp{file is unchanged; not dumped}, warning message
4135 @item file-unchanged
4136 @samp{%s: file is unchanged; not dumped}
4137 @kwindex ignore-archive
4138 @cindex @samp{file is the archive; not dumped}, warning message
4139 @kwindex ignore-archive
4140 @cindex @samp{file is the archive; not dumped}, warning message
4141 @item ignore-archive
4142 @samp{%s: file is the archive; not dumped}
4143 @kwindex file-removed
4144 @cindex @samp{File removed before we read it}, warning message
4145 @item file-removed
4146 @samp{%s: File removed before we read it}
4147 @kwindex file-changed
4148 @cindex @samp{file changed as we read it}, warning message
4149 @item file-changed
4150 @samp{%s: file changed as we read it}
4151 @end table
4152
4153 @subheading Keywords applicable for @command{tar --extract}
4154 @table @asis
4155 @kwindex timestamp
4156 @cindex @samp{implausibly old time stamp %s}, warning message
4157 @cindex @samp{time stamp %s is %s s in the future}, warning message
4158 @item timestamp
4159 @samp{%s: implausibly old time stamp %s}
4160 @*@samp{%s: time stamp %s is %s s in the future}
4161 @kwindex contiguous-cast
4162 @cindex @samp{Extracting contiguous files as regular files}, warning message
4163 @item contiguous-cast
4164 @samp{Extracting contiguous files as regular files}
4165 @kwindex symlink-cast
4166 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4167 @item symlink-cast
4168 @samp{Attempting extraction of symbolic links as hard links}
4169 @kwindex unknown-cast
4170 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4171 @item unknown-cast
4172 @samp{%s: Unknown file type '%c', extracted as normal file}
4173 @kwindex ignore-newer
4174 @cindex @samp{Current %s is newer or same age}, warning message
4175 @item ignore-newer
4176 @samp{Current %s is newer or same age}
4177 @kwindex unknown-keyword
4178 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4179 @item unknown-keyword
4180 @samp{Ignoring unknown extended header keyword '%s'}
4181 @kwindex decompress-program
4182 @item decompress-program
4183 Controls verbose description of failures occurring when trying to run
4184 alternative decompressor programs (@pxref{alternative decompression
4185 programs}). This warning is disabled by default (unless
4186 @option{--verbose} is used). A common example of what you can get
4187 when using this warning is:
4188
4189 @smallexample
4190 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4191 tar (child): cannot run compress: No such file or directory
4192 tar (child): trying gzip
4193 @end smallexample
4194
4195 This means that @command{tar} first tried to decompress
4196 @file{archive.Z} using @command{compress}, and, when that
4197 failed, switched to @command{gzip}.
4198 @end table
4199
4200 @subheading Keywords controlling incremental extraction:
4201 @table @asis
4202 @kwindex rename-directory
4203 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4204 @cindex @samp{%s: Directory has been renamed}, warning message
4205 @item rename-directory
4206 @samp{%s: Directory has been renamed from %s}
4207 @*@samp{%s: Directory has been renamed}
4208 @kwindex new-directory
4209 @cindex @samp{%s: Directory is new}, warning message
4210 @item new-directory
4211 @samp{%s: Directory is new}
4212 @kwindex xdev
4213 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4214 @item xdev
4215 @samp{%s: directory is on a different device: not purging}
4216 @kwindex bad-dumpdir
4217 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4218 @item bad-dumpdir
4219 @samp{Malformed dumpdir: 'X' never used}
4220 @end table
4221
4222 @node interactive
4223 @section Asking for Confirmation During Operations
4224 @cindex Interactive operation
4225
4226 Typically, @command{tar} carries out a command without stopping for
4227 further instructions. In some situations however, you may want to
4228 exclude some files and archive members from the operation (for instance
4229 if disk or storage space is tight). You can do this by excluding
4230 certain files automatically (@pxref{Choosing}), or by performing
4231 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4232 @command{tar} also accepts @option{--confirmation} for this option.
4233
4234 @opindex interactive
4235 When the @option{--interactive} (@option{-w}) option is specified, before
4236 reading, writing, or deleting files, @command{tar} first prints a message
4237 for each such file, telling what operation it intends to take, then asks
4238 for confirmation on the terminal. The actions which require
4239 confirmation include adding a file to the archive, extracting a file
4240 from the archive, deleting a file from the archive, and deleting a file
4241 from disk. To confirm the action, you must type a line of input
4242 beginning with @samp{y}. If your input line begins with anything other
4243 than @samp{y}, @command{tar} skips that file.
4244
4245 If @command{tar} is reading the archive from the standard input,
4246 @command{tar} opens the file @file{/dev/tty} to support the interactive
4247 communications.
4248
4249 Verbose output is normally sent to standard output, separate from
4250 other error messages. However, if the archive is produced directly
4251 on standard output, then verbose output is mixed with errors on
4252 @code{stderr}. Producing the archive on standard output may be used
4253 as a way to avoid using disk space, when the archive is soon to be
4254 consumed by another process reading it, say. Some people felt the need
4255 of producing an archive on stdout, still willing to segregate between
4256 verbose output and error output. A possible approach would be using a
4257 named pipe to receive the archive, and having the consumer process to
4258 read from that named pipe. This has the advantage of letting standard
4259 output free to receive verbose output, all separate from errors.
4260
4261 @node operations
4262 @chapter @GNUTAR{} Operations
4263
4264 @menu
4265 * Basic tar::
4266 * Advanced tar::
4267 * create options::
4268 * extract options::
4269 * backup::
4270 * Applications::
4271 * looking ahead::
4272 @end menu
4273
4274 @node Basic tar
4275 @section Basic @GNUTAR{} Operations
4276
4277 The basic @command{tar} operations, @option{--create} (@option{-c}),
4278 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4279 @option{-x}), are currently presented and described in the tutorial
4280 chapter of this manual. This section provides some complementary notes
4281 for these operations.
4282
4283 @table @option
4284 @xopindex{create, complementary notes}
4285 @item --create
4286 @itemx -c
4287
4288 Creating an empty archive would have some kind of elegance. One can
4289 initialize an empty archive and later use @option{--append}
4290 (@option{-r}) for adding all members. Some applications would not
4291 welcome making an exception in the way of adding the first archive
4292 member. On the other hand, many people reported that it is
4293 dangerously too easy for @command{tar} to destroy a magnetic tape with
4294 an empty archive@footnote{This is well described in @cite{Unix-haters
4295 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4296 Books, ISBN 1-56884-203-1.}. The two most common errors are:
4297
4298 @enumerate
4299 @item
4300 Mistakingly using @code{create} instead of @code{extract}, when the
4301 intent was to extract the full contents of an archive. This error
4302 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4303 the QWERTY keyboard. Instead of being unpacked, the archive then
4304 gets wholly destroyed. When users speak about @dfn{exploding} an
4305 archive, they usually mean something else :-).
4306
4307 @item
4308 Forgetting the argument to @code{file}, when the intent was to create
4309 an archive with a single file in it. This error is likely because a
4310 tired user can easily add the @kbd{f} key to the cluster of option
4311 letters, by the mere force of habit, without realizing the full
4312 consequence of doing so. The usual consequence is that the single
4313 file, which was meant to be saved, is rather destroyed.
4314 @end enumerate
4315
4316 So, recognizing the likelihood and the catastrophic nature of these
4317 errors, @GNUTAR{} now takes some distance from elegance, and
4318 cowardly refuses to create an archive when @option{--create} option is
4319 given, there are no arguments besides options, and
4320 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4321 around the cautiousness of @GNUTAR{} and nevertheless create an
4322 archive with nothing in it, one may still use, as the value for the
4323 @option{--files-from} option, a file with no names in it, as shown in
4324 the following commands:
4325
4326 @smallexample
4327 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4328 @kbd{tar -cf empty-archive.tar -T /dev/null}
4329 @end smallexample
4330
4331 @xopindex{extract, complementary notes}
4332 @item --extract
4333 @itemx --get
4334 @itemx -x
4335
4336 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4337
4338 @item @option{--list} (@option{-t})
4339
4340 @GNUTAR{} now shows dates as @samp{1996-08-30},
4341 while it used to show them as @samp{Aug 30 1996}. Preferably,
4342 people should get used to ISO 8601 dates. Local American dates should
4343 be made available again with full date localization support, once
4344 ready. In the meantime, programs not being localizable for dates
4345 should prefer international dates, that's really the way to go.
4346
4347 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4348 are curious, it contains a detailed explanation of the ISO 8601 standard.
4349
4350 @end table
4351
4352 @node Advanced tar
4353 @section Advanced @GNUTAR{} Operations
4354
4355 Now that you have learned the basics of using @GNUTAR{}, you may want
4356 to learn about further ways in which @command{tar} can help you.
4357
4358 This chapter presents five, more advanced operations which you probably
4359 won't use on a daily basis, but which serve more specialized functions.
4360 We also explain the different styles of options and why you might want
4361 to use one or another, or a combination of them in your @command{tar}
4362 commands. Additionally, this chapter includes options which allow you to
4363 define the output from @command{tar} more carefully, and provide help and
4364 error correction in special circumstances.
4365
4366 @FIXME{check this after the chapter is actually revised to make sure
4367 it still introduces the info in the chapter correctly : ).}
4368
4369 @menu
4370 * Operations::
4371 * append::
4372 * update::
4373 * concatenate::
4374 * delete::
4375 * compare::
4376 @end menu
4377
4378 @node Operations
4379 @subsection The Five Advanced @command{tar} Operations
4380
4381 @cindex basic operations
4382 In the last chapter, you learned about the first three operations to
4383 @command{tar}. This chapter presents the remaining five operations to
4384 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4385 @option{--delete}, and @option{--compare}.
4386
4387 You are not likely to use these operations as frequently as those
4388 covered in the last chapter; however, since they perform specialized
4389 functions, they are quite useful when you do need to use them. We
4390 will give examples using the same directory and files that you created
4391 in the last chapter. As you may recall, the directory is called
4392 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4393 and the two archive files you created are
4394 @samp{collection.tar} and @samp{music.tar}.
4395
4396 We will also use the archive files @samp{afiles.tar} and
4397 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4398 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4399 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4400
4401 Unless we state otherwise, all practicing you do and examples you follow
4402 in this chapter will take place in the @file{practice} directory that
4403 you created in the previous chapter; see @ref{prepare for examples}.
4404 (Below in this section, we will remind you of the state of the examples
4405 where the last chapter left them.)
4406
4407 The five operations that we will cover in this chapter are:
4408
4409 @table @option
4410 @item --append
4411 @itemx -r
4412 Add new entries to an archive that already exists.
4413 @item --update
4414 @itemx -u
4415 Add more recent copies of archive members to the end of an archive, if
4416 they exist.
4417 @item --concatenate
4418 @itemx --catenate
4419 @itemx -A
4420 Add one or more pre-existing archives to the end of another archive.
4421 @item --delete
4422 Delete items from an archive (does not work on tapes).
4423 @item --compare
4424 @itemx --diff
4425 @itemx -d
4426 Compare archive members to their counterparts in the file system.
4427 @end table
4428
4429 @node append
4430 @subsection How to Add Files to Existing Archives: @option{--append}
4431
4432 @cindex appending files to existing archive
4433 @opindex append
4434 If you want to add files to an existing archive, you don't need to
4435 create a new archive; you can use @option{--append} (@option{-r}).
4436 The archive must already exist in order to use @option{--append}. (A
4437 related operation is the @option{--update} operation; you can use this
4438 to add newer versions of archive members to an existing archive. To learn how to
4439 do this with @option{--update}, @pxref{update}.)
4440
4441 If you use @option{--append} to add a file that has the same name as an
4442 archive member to an archive containing that archive member, then the
4443 old member is not deleted. What does happen, however, is somewhat
4444 complex. @command{tar} @emph{allows} you to have infinite number of files
4445 with the same name. Some operations treat these same-named members no
4446 differently than any other set of archive members: for example, if you
4447 view an archive with @option{--list} (@option{-t}), you will see all
4448 of those members listed, with their data modification times, owners, etc.
4449
4450 Other operations don't deal with these members as perfectly as you might
4451 prefer; if you were to use @option{--extract} to extract the archive,
4452 only the most recently added copy of a member with the same name as
4453 other members would end up in the working directory. This is because
4454 @option{--extract} extracts an archive in the order the members appeared
4455 in the archive; the most recently archived members will be extracted
4456 last. Additionally, an extracted member will @emph{replace} a file of
4457 the same name which existed in the directory already, and @command{tar}
4458 will not prompt you about this@footnote{Unless you give it
4459 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4460 the disk copy is newer than the one in the archive and you invoke
4461 @command{tar} with @option{--keep-newer-files} option.}. Thus, only
4462 the most recently archived member will end up being extracted, as it
4463 will replace the one extracted before it, and so on.
4464
4465 @cindex extracting @var{n}th copy of the file
4466 @xopindex{occurrence, described}
4467 There exists a special option that allows you to get around this
4468 behavior and extract (or list) only a particular copy of the file.
4469 This is @option{--occurrence} option. If you run @command{tar} with
4470 this option, it will extract only the first copy of the file. You
4471 may also give this option an argument specifying the number of
4472 copy to be extracted. Thus, for example if the archive
4473 @file{archive.tar} contained three copies of file @file{myfile}, then
4474 the command
4475
4476 @smallexample
4477 tar --extract --file archive.tar --occurrence=2 myfile
4478 @end smallexample
4479
4480 @noindent
4481 would extract only the second copy. @xref{Option
4482 Summary,---occurrence}, for the description of @option{--occurrence}
4483 option.
4484
4485 @FIXME{ hag -- you might want to incorporate some of the above into the
4486 MMwtSN node; not sure. i didn't know how to make it simpler...
4487
4488 There are a few ways to get around this. Xref to Multiple Members
4489 with the Same Name, maybe.}
4490
4491 @cindex Members, replacing with other members
4492 @cindex Replacing members with other members
4493 @xopindex{delete, using before --append}
4494 If you want to replace an archive member, use @option{--delete} to
4495 delete the member you want to remove from the archive, and then use
4496 @option{--append} to add the member you want to be in the archive. Note
4497 that you can not change the order of the archive; the most recently
4498 added member will still appear last. In this sense, you cannot truly
4499 ``replace'' one member with another. (Replacing one member with another
4500 will not work on certain types of media, such as tapes; see @ref{delete}
4501 and @ref{Media}, for more information.)
4502
4503 @menu
4504 * appending files:: Appending Files to an Archive
4505 * multiple::
4506 @end menu
4507
4508 @node appending files
4509 @subsubsection Appending Files to an Archive
4510 @cindex Adding files to an Archive
4511 @cindex Appending files to an Archive
4512 @cindex Archives, Appending files to
4513 @opindex append
4514
4515 The simplest way to add a file to an already existing archive is the
4516 @option{--append} (@option{-r}) operation, which writes specified
4517 files into the archive whether or not they are already among the
4518 archived files.
4519
4520 When you use @option{--append}, you @emph{must} specify file name
4521 arguments, as there is no default. If you specify a file that already
4522 exists in the archive, another copy of the file will be added to the
4523 end of the archive. As with other operations, the member names of the
4524 newly added files will be exactly the same as their names given on the
4525 command line. The @option{--verbose} (@option{-v}) option will print
4526 out the names of the files as they are written into the archive.
4527
4528 @option{--append} cannot be performed on some tape drives, unfortunately,
4529 due to deficiencies in the formats those tape drives use. The archive
4530 must be a valid @command{tar} archive, or else the results of using this
4531 operation will be unpredictable. @xref{Media}.
4532
4533 To demonstrate using @option{--append} to add a file to an archive,
4534 create a file called @file{rock} in the @file{practice} directory.
4535 Make sure you are in the @file{practice} directory. Then, run the
4536 following @command{tar} command to add @file{rock} to
4537 @file{collection.tar}:
4538
4539 @smallexample
4540 $ @kbd{tar --append --file=collection.tar rock}
4541 @end smallexample
4542
4543 @noindent
4544 If you now use the @option{--list} (@option{-t}) operation, you will see that
4545 @file{rock} has been added to the archive:
4546
4547 @smallexample
4548 $ @kbd{tar --list --file=collection.tar}
4549 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4550 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4551 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4552 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4553 @end smallexample
4554
4555 @node multiple
4556 @subsubsection Multiple Members with the Same Name
4557 @cindex members, multiple
4558 @cindex multiple members
4559
4560 You can use @option{--append} (@option{-r}) to add copies of files
4561 which have been updated since the archive was created. (However, we
4562 do not recommend doing this since there is another @command{tar}
4563 option called @option{--update}; @xref{update}, for more information.
4564 We describe this use of @option{--append} here for the sake of
4565 completeness.) When you extract the archive, the older version will
4566 be effectively lost. This works because files are extracted from an
4567 archive in the order in which they were archived. Thus, when the
4568 archive is extracted, a file archived later in time will replace a
4569 file of the same name which was archived earlier, even though the
4570 older version of the file will remain in the archive unless you delete
4571 all versions of the file.
4572
4573 Supposing you change the file @file{blues} and then append the changed
4574 version to @file{collection.tar}. As you saw above, the original
4575 @file{blues} is in the archive @file{collection.tar}. If you change the
4576 file and append the new version of the file to the archive, there will
4577 be two copies in the archive. When you extract the archive, the older
4578 version of the file will be extracted first, and then replaced by the
4579 newer version when it is extracted.
4580
4581 You can append the new, changed copy of the file @file{blues} to the
4582 archive in this way:
4583
4584 @smallexample
4585 $ @kbd{tar --append --verbose --file=collection.tar blues}
4586 blues
4587 @end smallexample
4588
4589 @noindent
4590 Because you specified the @option{--verbose} option, @command{tar} has
4591 printed the name of the file being appended as it was acted on. Now
4592 list the contents of the archive:
4593
4594 @smallexample
4595 $ @kbd{tar --list --verbose --file=collection.tar}
4596 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4597 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4598 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4599 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4600 -rw-r--r-- me/user 58 1996-10-24 18:30 blues
4601 @end smallexample
4602
4603 @noindent
4604 The newest version of @file{blues} is now at the end of the archive
4605 (note the different creation dates and file sizes). If you extract
4606 the archive, the older version of the file @file{blues} will be
4607 replaced by the newer version. You can confirm this by extracting
4608 the archive and running @samp{ls} on the directory.
4609
4610 If you wish to extract the first occurrence of the file @file{blues}
4611 from the archive, use @option{--occurrence} option, as shown in
4612 the following example:
4613
4614 @smallexample
4615 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4616 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4617 @end smallexample
4618
4619 @xref{Writing}, for more information on @option{--extract} and
4620 see @ref{Option Summary, --occurrence}, for a description of
4621 @option{--occurrence} option.
4622
4623 @node update
4624 @subsection Updating an Archive
4625 @cindex Updating an archive
4626 @opindex update
4627
4628 In the previous section, you learned how to use @option{--append} to
4629 add a file to an existing archive. A related operation is
4630 @option{--update} (@option{-u}). The @option{--update} operation
4631 updates a @command{tar} archive by comparing the date of the specified
4632 archive members against the date of the file with the same name. If
4633 the file has been modified more recently than the archive member, then
4634 the newer version of the file is added to the archive (as with
4635 @option{--append}).
4636
4637 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4638 The operation will fail.
4639
4640 @FIXME{other examples of media on which --update will fail? need to ask
4641 charles and/or mib/thomas/dave shevett..}
4642
4643 Both @option{--update} and @option{--append} work by adding to the end
4644 of the archive. When you extract a file from the archive, only the
4645 version stored last will wind up in the file system, unless you use
4646 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4647
4648 @menu
4649 * how to update::
4650 @end menu
4651
4652 @node how to update
4653 @subsubsection How to Update an Archive Using @option{--update}
4654 @opindex update
4655
4656 You must use file name arguments with the @option{--update}
4657 (@option{-u}) operation. If you don't specify any files,
4658 @command{tar} won't act on any files and won't tell you that it didn't
4659 do anything (which may end up confusing you).
4660
4661 @c note: the above parenthetical added because in fact, this
4662 @c behavior just confused the author. :-)
4663
4664 To see the @option{--update} option at work, create a new file,
4665 @file{classical}, in your practice directory, and some extra text to the
4666 file @file{blues}, using any text editor. Then invoke @command{tar} with
4667 the @samp{update} operation and the @option{--verbose} (@option{-v})
4668 option specified, using the names of all the files in the @file{practice}
4669 directory as file name arguments:
4670
4671 @smallexample
4672 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4673 blues
4674 classical
4675 $
4676 @end smallexample
4677
4678 @noindent
4679 Because we have specified verbose mode, @command{tar} prints out the names
4680 of the files it is working on, which in this case are the names of the
4681 files that needed to be updated. If you run @samp{tar --list} and look
4682 at the archive, you will see @file{blues} and @file{classical} at its
4683 end. There will be a total of two versions of the member @samp{blues};
4684 the one at the end will be newer and larger, since you added text before
4685 updating it.
4686
4687 The reason @command{tar} does not overwrite the older file when updating
4688 it is because writing to the middle of a section of tape is a difficult
4689 process. Tapes are not designed to go backward. @xref{Media}, for more
4690 information about tapes.
4691
4692 @option{--update} (@option{-u}) is not suitable for performing backups for two
4693 reasons: it does not change directory content entries, and it
4694 lengthens the archive every time it is used. The @GNUTAR{}
4695 options intended specifically for backups are more
4696 efficient. If you need to run backups, please consult @ref{Backups}.
4697
4698 @node concatenate
4699 @subsection Combining Archives with @option{--concatenate}
4700
4701 @cindex Adding archives to an archive
4702 @cindex Concatenating Archives
4703 @opindex concatenate
4704 @opindex catenate
4705 @c @cindex @option{-A} described
4706 Sometimes it may be convenient to add a second archive onto the end of
4707 an archive rather than adding individual files to the archive. To add
4708 one or more archives to the end of another archive, you should use the
4709 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4710
4711 To use @option{--concatenate}, give the first archive with
4712 @option{--file} option and name the rest of archives to be
4713 concatenated on the command line. The members, and their member
4714 names, will be copied verbatim from those archives to the first
4715 one@footnote{This can cause multiple members to have the same name. For
4716 information on how this affects reading the archive, see @ref{multiple}.}.
4717 The new, concatenated archive will be called by the same name as the
4718 one given with the @option{--file} option. As usual, if you omit
4719 @option{--file}, @command{tar} will use the value of the environment
4720 variable @env{TAPE}, or, if this has not been set, the default archive name.
4721
4722 @FIXME{There is no way to specify a new name...}
4723
4724 To demonstrate how @option{--concatenate} works, create two small archives
4725 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4726 files from @file{practice}:
4727
4728 @smallexample
4729 $ @kbd{tar -cvf bluesrock.tar blues rock}
4730 blues
4731 rock
4732 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4733 folk
4734 jazz
4735 @end smallexample
4736
4737 @noindent
4738 If you like, You can run @samp{tar --list} to make sure the archives
4739 contain what they are supposed to:
4740
4741 @smallexample
4742 $ @kbd{tar -tvf bluesrock.tar}
4743 -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
4744 -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
4745 $ @kbd{tar -tvf jazzfolk.tar}
4746 -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
4747 -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
4748 @end smallexample
4749
4750 We can concatenate these two archives with @command{tar}:
4751
4752 @smallexample
4753 $ @kbd{cd ..}
4754 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4755 @end smallexample
4756
4757 If you now list the contents of the @file{bluesrock.tar}, you will see
4758 that now it also contains the archive members of @file{jazzfolk.tar}:
4759
4760 @smallexample
4761 $ @kbd{tar --list --file=bluesrock.tar}
4762 blues
4763 rock
4764 folk
4765 jazz
4766 @end smallexample
4767
4768 When you use @option{--concatenate}, the source and target archives must
4769 already exist and must have been created using compatible format
4770 parameters. Notice, that @command{tar} does not check whether the
4771 archives it concatenates have compatible formats, it does not
4772 even check if the files are really tar archives.
4773
4774 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4775 tape drives, due to deficiencies in the formats those tape drives use.
4776
4777 @cindex @code{concatenate} vs @command{cat}
4778 @cindex @command{cat} vs @code{concatenate}
4779 It may seem more intuitive to you to want or try to use @command{cat} to
4780 concatenate two archives instead of using the @option{--concatenate}
4781 operation; after all, @command{cat} is the utility for combining files.
4782
4783 However, @command{tar} archives incorporate an end-of-file marker which
4784 must be removed if the concatenated archives are to be read properly as
4785 one archive. @option{--concatenate} removes the end-of-archive marker
4786 from the target archive before each new archive is appended. If you use
4787 @command{cat} to combine the archives, the result will not be a valid
4788 @command{tar} format archive. If you need to retrieve files from an
4789 archive that was added to using the @command{cat} utility, use the
4790 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4791 information on dealing with archives improperly combined using the
4792 @command{cat} shell utility.
4793
4794 @node delete
4795 @subsection Removing Archive Members Using @option{--delete}
4796 @cindex Deleting files from an archive
4797 @cindex Removing files from an archive
4798
4799 @opindex delete
4800 You can remove members from an archive by using the @option{--delete}
4801 option. Specify the name of the archive with @option{--file}
4802 (@option{-f}) and then specify the names of the members to be deleted;
4803 if you list no member names, nothing will be deleted. The
4804 @option{--verbose} option will cause @command{tar} to print the names
4805 of the members as they are deleted. As with @option{--extract}, you
4806 must give the exact member names when using @samp{tar --delete}.
4807 @option{--delete} will remove all versions of the named file from the
4808 archive. The @option{--delete} operation can run very slowly.
4809
4810 Unlike other operations, @option{--delete} has no short form.
4811
4812 @cindex Tapes, using @option{--delete} and
4813 @cindex Deleting from tape archives
4814 This operation will rewrite the archive. You can only use
4815 @option{--delete} on an archive if the archive device allows you to
4816 write to any point on the media, such as a disk; because of this, it
4817 does not work on magnetic tapes. Do not try to delete an archive member
4818 from a magnetic tape; the action will not succeed, and you will be
4819 likely to scramble the archive and damage your tape. There is no safe
4820 way (except by completely re-writing the archive) to delete files from
4821 most kinds of magnetic tape. @xref{Media}.
4822
4823 To delete all versions of the file @file{blues} from the archive
4824 @file{collection.tar} in the @file{practice} directory, make sure you
4825 are in that directory, and then,
4826
4827 @smallexample
4828 $ @kbd{tar --list --file=collection.tar}
4829 blues
4830 folk
4831 jazz
4832 rock
4833 $ @kbd{tar --delete --file=collection.tar blues}
4834 $ @kbd{tar --list --file=collection.tar}
4835 folk
4836 jazz
4837 rock
4838 @end smallexample
4839
4840 @FIXME{Check if the above listing is actually produced after running
4841 all the examples on collection.tar.}
4842
4843 The @option{--delete} option has been reported to work properly when
4844 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4845
4846 @node compare
4847 @subsection Comparing Archive Members with the File System
4848 @cindex Verifying the currency of an archive
4849
4850 @opindex compare
4851 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4852 specified archive members against files with the same names, and then
4853 reports differences in file size, mode, owner, modification date and
4854 contents. You should @emph{only} specify archive member names, not file
4855 names. If you do not name any members, then @command{tar} will compare the
4856 entire archive. If a file is represented in the archive but does not
4857 exist in the file system, @command{tar} reports a difference.
4858
4859 You have to specify the record size of the archive when modifying an
4860 archive with a non-default record size.
4861
4862 @command{tar} ignores files in the file system that do not have
4863 corresponding members in the archive.
4864
4865 The following example compares the archive members @file{rock},
4866 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4867 files of the same name in the file system. (Note that there is no file,
4868 @file{funk}; @command{tar} will report an error message.)
4869
4870 @smallexample
4871 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4872 rock
4873 blues
4874 tar: funk not found in archive
4875 @end smallexample
4876
4877 The spirit behind the @option{--compare} (@option{--diff},
4878 @option{-d}) option is to check whether the archive represents the
4879 current state of files on disk, more than validating the integrity of
4880 the archive media. For this latter goal, see @ref{verify}.
4881
4882 @node create options
4883 @section Options Used by @option{--create}
4884
4885 @xopindex{create, additional options}
4886 The previous chapter described the basics of how to use
4887 @option{--create} (@option{-c}) to create an archive from a set of files.
4888 @xref{create}. This section described advanced options to be used with
4889 @option{--create}.
4890
4891 @menu
4892 * override:: Overriding File Metadata.
4893 * Ignore Failed Read::
4894 @end menu
4895
4896 @node override
4897 @subsection Overriding File Metadata
4898
4899 As described above, a @command{tar} archive keeps, for each member it contains,
4900 its @dfn{metadata}, such as modification time, mode and ownership of
4901 the file. @GNUTAR{} allows to replace these data with other values
4902 when adding files to the archive. The options described in this
4903 section affect creation of archives of any type. For POSIX archives,
4904 see also @ref{PAX keywords}, for additional ways of controlling
4905 metadata, stored in the archive.
4906
4907 @table @option
4908 @opindex mode
4909 @item --mode=@var{permissions}
4910
4911 When adding files to an archive, @command{tar} will use
4912 @var{permissions} for the archive members, rather than the permissions
4913 from the files. @var{permissions} can be specified either as an octal
4914 number or as symbolic permissions, like with
4915 @command{chmod} (@xref{File permissions, Permissions, File
4916 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4917 also has useful information for those not being overly familiar with
4918 the UNIX permission system). Using latter syntax allows for
4919 more flexibility. For example, the value @samp{a+rw} adds read and write
4920 permissions for everybody, while retaining executable bits on directories
4921 or on any other file already marked as executable:
4922
4923 @smallexample
4924 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4925 @end smallexample
4926
4927 @item --mtime=@var{date}
4928 @opindex mtime
4929
4930 When adding files to an archive, @command{tar} will use @var{date} as
4931 the modification time of members when creating archives, instead of
4932 their actual modification times. The argument @var{date} can be
4933 either a textual date representation in almost arbitrary format
4934 (@pxref{Date input formats}) or a name of an existing file, starting
4935 with @samp{/} or @samp{.}. In the latter case, the modification time
4936 of that file will be used.
4937
4938 The following example will set the modification date to 00:00:00,
4939 January 1, 1970:
4940
4941 @smallexample
4942 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4943 @end smallexample
4944
4945 @noindent
4946 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4947 will try to convert the specified date back to its textual
4948 representation and compare it with the one given with
4949 @option{--mtime} options. If the two dates differ, @command{tar} will
4950 print a warning saying what date it will use. This is to help user
4951 ensure he is using the right date.
4952
4953 For example:
4954
4955 @smallexample
4956 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4957 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
4958 13:06:29.152478
4959 @dots{}
4960 @end smallexample
4961
4962 @item --owner=@var{user}
4963 @opindex owner
4964
4965 Specifies that @command{tar} should use @var{user} as the owner of members
4966 when creating archives, instead of the user associated with the source
4967 file.
4968
4969 If @var{user} contains a colon, it is taken to be of the form
4970 @var{name}:@var{id} where a nonempty @var{name} specifies the user
4971 name and a nonempty @var{id} specifies the decimal numeric user
4972 @acronym{ID}. If @var{user} does not contain a colon, it is taken to
4973 be a user number if it is one or more decimal digits; otherwise it is
4974 taken to be a user name.
4975
4976 If a name is given but no number, the number is inferred from the
4977 current host's user database if possible, and the file's user number
4978 is used otherwise. If a number is given but no name, the name is
4979 inferred from the number if possible, and an empty name is used
4980 otherwise. If both name and number are given, the user database is
4981 not consulted, and the name and number need not be valid on the
4982 current host.
4983
4984 There is no value indicating a missing number, and @samp{0} usually means
4985 @code{root}. Some people like to force @samp{0} as the value to offer in
4986 their distributions for the owner of files, because the @code{root} user is
4987 anonymous anyway, so that might as well be the owner of anonymous
4988 archives. For example:
4989
4990 @smallexample
4991 $ @kbd{tar -c -f archive.tar --owner=0 .}
4992 @end smallexample
4993
4994 @noindent
4995 or:
4996
4997 @smallexample
4998 $ @kbd{tar -c -f archive.tar --owner=root .}
4999 @end smallexample
5000
5001 @item --group=@var{group}
5002 @opindex group
5003
5004 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5005 rather than the group from the source file. As with @option{--owner},
5006 the argument @var{group} can be an existing group symbolic name, or a
5007 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5008 @end table
5009
5010 @node Ignore Failed Read
5011 @subsection Ignore Fail Read
5012
5013 @table @option
5014 @item --ignore-failed-read
5015 @opindex ignore-failed-read
5016 Do not exit with nonzero on unreadable files or directories.
5017 @end table
5018
5019 @node extract options
5020 @section Options Used by @option{--extract}
5021 @cindex options for use with @option{--extract}
5022
5023 @xopindex{extract, additional options}
5024 The previous chapter showed how to use @option{--extract} to extract
5025 an archive into the file system. Various options cause @command{tar} to
5026 extract more information than just file contents, such as the owner,
5027 the permissions, the modification date, and so forth. This section
5028 presents options to be used with @option{--extract} when certain special
5029 considerations arise. You may review the information presented in
5030 @ref{extract} for more basic information about the
5031 @option{--extract} operation.
5032
5033 @menu
5034 * Reading:: Options to Help Read Archives
5035 * Writing:: Changing How @command{tar} Writes Files
5036 * Scarce:: Coping with Scarce Resources
5037 @end menu
5038
5039 @node Reading
5040 @subsection Options to Help Read Archives
5041 @cindex Options when reading archives
5042
5043 @cindex Reading incomplete records
5044 @cindex Records, incomplete
5045 @opindex read-full-records
5046 Normally, @command{tar} will request data in full record increments from
5047 an archive storage device. If the device cannot return a full record,
5048 @command{tar} will report an error. However, some devices do not always
5049 return full records, or do not require the last record of an archive to
5050 be padded out to the next record boundary. To keep reading until you
5051 obtain a full record, or to accept an incomplete record if it contains
5052 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5053 in conjunction with the @option{--extract} or @option{--list} operations.
5054 @xref{Blocking}.
5055
5056 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5057 @command{tar} reads an archive from standard input, or from a remote
5058 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
5059 pipe returns however much happens to be in the pipe, even if it is
5060 less than was requested. If this option were not enabled, @command{tar}
5061 would fail as soon as it read an incomplete record from the pipe.
5062
5063 If you're not sure of the blocking factor of an archive, you can
5064 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5065 @option{--blocking-factor=@var{512-size}} (@option{-b
5066 @var{512-size}}), using a blocking factor larger than what the archive
5067 uses. This lets you avoid having to determine the blocking factor
5068 of an archive. @xref{Blocking Factor}.
5069
5070 @menu
5071 * read full records::
5072 * Ignore Zeros::
5073 @end menu
5074
5075 @node read full records
5076 @unnumberedsubsubsec Reading Full Records
5077
5078 @FIXME{need sentence or so of intro here}
5079
5080 @table @option
5081 @opindex read-full-records
5082 @item --read-full-records
5083 @item -B
5084 Use in conjunction with @option{--extract} (@option{--get},
5085 @option{-x}) to read an archive which contains incomplete records, or
5086 one which has a blocking factor less than the one specified.
5087 @end table
5088
5089 @node Ignore Zeros
5090 @unnumberedsubsubsec Ignoring Blocks of Zeros
5091
5092 @cindex End-of-archive blocks, ignoring
5093 @cindex Ignoring end-of-archive blocks
5094 @opindex ignore-zeros
5095 Normally, @command{tar} stops reading when it encounters a block of zeros
5096 between file entries (which usually indicates the end of the archive).
5097 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5098 completely read an archive which contains a block of zeros before the
5099 end (i.e., a damaged archive, or one that was created by concatenating
5100 several archives together).
5101
5102 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5103 versions of @command{tar} write garbage after the end-of-archive entry,
5104 since that part of the media is never supposed to be read. @GNUTAR{}
5105 does not write after the end of an archive, but seeks to
5106 maintain compatibility among archiving utilities.
5107
5108 @table @option
5109 @item --ignore-zeros
5110 @itemx -i
5111 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5112 encountered while reading an archive. Use in conjunction with
5113 @option{--extract} or @option{--list}.
5114 @end table
5115
5116 @node Writing
5117 @subsection Changing How @command{tar} Writes Files
5118 @UNREVISED
5119
5120 @FIXME{Introductory paragraph}
5121
5122 @menu
5123 * Dealing with Old Files::
5124 * Overwrite Old Files::
5125 * Keep Old Files::
5126 * Keep Newer Files::
5127 * Unlink First::
5128 * Recursive Unlink::
5129 * Data Modification Times::
5130 * Setting Access Permissions::
5131 * Directory Modification Times and Permissions::
5132 * Writing to Standard Output::
5133 * Writing to an External Program::
5134 * remove files::
5135 @end menu
5136
5137 @node Dealing with Old Files
5138 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5139
5140 @xopindex{overwrite-dir, introduced}
5141 When extracting files, if @command{tar} discovers that the extracted
5142 file already exists, it normally replaces the file by removing it before
5143 extracting it, to prevent confusion in the presence of hard or symbolic
5144 links. (If the existing file is a symbolic link, it is removed, not
5145 followed.) However, if a directory cannot be removed because it is
5146 nonempty, @command{tar} normally overwrites its metadata (ownership,
5147 permission, etc.). The @option{--overwrite-dir} option enables this
5148 default behavior. To be more cautious and preserve the metadata of
5149 such a directory, use the @option{--no-overwrite-dir} option.
5150
5151 @cindex Overwriting old files, prevention
5152 @xopindex{keep-old-files, introduced}
5153 To be even more cautious and prevent existing files from being replaced, use
5154 the @option{--keep-old-files} (@option{-k}) option. It causes
5155 @command{tar} to refuse to replace or update a file that already
5156 exists, i.e., a file with the same name as an archive member prevents
5157 extraction of that archive member. Instead, it reports an error. For
5158 example:
5159
5160 @example
5161 $ @kbd{ls}
5162 blues
5163 $ @kbd{tar -x -k -f archive.tar}
5164 tar: blues: Cannot open: File exists
5165 tar: Exiting with failure status due to previous errors
5166 @end example
5167
5168 @xopindex{skip-old-files, introduced}
5169 If you wish to preserve old files untouched, but don't want
5170 @command{tar} to treat them as errors, use the
5171 @option{--skip-old-files} option. This option causes @command{tar} to
5172 silently skip extracting over existing files.
5173
5174 @xopindex{overwrite, introduced}
5175 To be more aggressive about altering existing files, use the
5176 @option{--overwrite} option. It causes @command{tar} to overwrite
5177 existing files and to follow existing symbolic links when extracting.
5178
5179 @cindex Protecting old files
5180 Some people argue that @GNUTAR{} should not hesitate
5181 to overwrite files with other files when extracting. When extracting
5182 a @command{tar} archive, they expect to see a faithful copy of the
5183 state of the file system when the archive was created. It is debatable
5184 that this would always be a proper behavior. For example, suppose one
5185 has an archive in which @file{usr/local} is a link to
5186 @file{usr/local2}. Since then, maybe the site removed the link and
5187 renamed the whole hierarchy from @file{/usr/local2} to
5188 @file{/usr/local}. Such things happen all the time. I guess it would
5189 not be welcome at all that @GNUTAR{} removes the
5190 whole hierarchy just to make room for the link to be reinstated
5191 (unless it @emph{also} simultaneously restores the full
5192 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
5193 able to remove a whole hierarchy to reestablish a symbolic link, for
5194 example, but @emph{only if} @option{--recursive-unlink} is specified
5195 to allow this behavior. In any case, single files are silently
5196 removed.
5197
5198 @xopindex{unlink-first, introduced}
5199 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5200 some cases by causing @command{tar} to remove files unconditionally
5201 before extracting them.
5202
5203 @node Overwrite Old Files
5204 @unnumberedsubsubsec Overwrite Old Files
5205
5206 @table @option
5207 @opindex overwrite
5208 @item --overwrite
5209 Overwrite existing files and directory metadata when extracting files
5210 from an archive.
5211
5212 This causes @command{tar} to write extracted files into the file system without
5213 regard to the files already on the system; i.e., files with the same
5214 names as archive members are overwritten when the archive is extracted.
5215 It also causes @command{tar} to extract the ownership, permissions,
5216 and time stamps onto any preexisting files or directories.
5217 If the name of a corresponding file name is a symbolic link, the file
5218 pointed to by the symbolic link will be overwritten instead of the
5219 symbolic link itself (if this is possible). Moreover, special devices,
5220 empty directories and even symbolic links are automatically removed if
5221 they are in the way of extraction.
5222
5223 Be careful when using the @option{--overwrite} option, particularly when
5224 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5225 can change the contents, ownership or permissions of any file on your
5226 system. Also, many systems do not take kindly to overwriting files that
5227 are currently being executed.
5228
5229 @opindex overwrite-dir
5230 @item --overwrite-dir
5231 Overwrite the metadata of directories when extracting files from an
5232 archive, but remove other files before extracting.
5233 @end table
5234
5235 @node Keep Old Files
5236 @unnumberedsubsubsec Keep Old Files
5237
5238 @GNUTAR{} provides two options to control its actions in a situation
5239 when it is about to extract a file which already exists on disk.
5240
5241 @table @option
5242 @opindex keep-old-files
5243 @item --keep-old-files
5244 @itemx -k
5245 Do not replace existing files from archive. When such a file is
5246 encountered, @command{tar} issues an error message. Upon end of
5247 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
5248
5249 @item --skip-old-files
5250 Do not replace existing files from archive, but do not treat that
5251 as error. Such files are silently skipped and do not affect
5252 @command{tar} exit status.
5253
5254 Additional verbosity can be obtained using @option{--warning=existing-file}
5255 together with that option (@pxref{warnings}).
5256 @end table
5257
5258 @node Keep Newer Files
5259 @unnumberedsubsubsec Keep Newer Files
5260
5261 @table @option
5262 @opindex keep-newer-files
5263 @item --keep-newer-files
5264 Do not replace existing files that are newer than their archive
5265 copies. This option is meaningless with @option{--list} (@option{-t}).
5266 @end table
5267
5268 @node Unlink First
5269 @unnumberedsubsubsec Unlink First
5270
5271 @table @option
5272 @opindex unlink-first
5273 @item --unlink-first
5274 @itemx -U
5275 Remove files before extracting over them.
5276 This can make @command{tar} run a bit faster if you know in advance
5277 that the extracted files all need to be removed. Normally this option
5278 slows @command{tar} down slightly, so it is disabled by default.
5279 @end table
5280
5281 @node Recursive Unlink
5282 @unnumberedsubsubsec Recursive Unlink
5283
5284 @table @option
5285 @opindex recursive-unlink
5286 @item --recursive-unlink
5287 When this option is specified, try removing files and directory hierarchies
5288 before extracting over them. @emph{This is a dangerous option!}
5289 @end table
5290
5291 If you specify the @option{--recursive-unlink} option,
5292 @command{tar} removes @emph{anything} that keeps you from extracting a file
5293 as far as current permissions will allow it. This could include removal
5294 of the contents of a full directory hierarchy.
5295
5296 @node Data Modification Times
5297 @unnumberedsubsubsec Setting Data Modification Times
5298
5299 @cindex Data modification times of extracted files
5300 @cindex Modification times of extracted files
5301 Normally, @command{tar} sets the data modification times of extracted
5302 files to the corresponding times recorded for the files in the archive, but
5303 limits the permissions of extracted files by the current @code{umask}
5304 setting.
5305
5306 To set the data modification times of extracted files to the time when
5307 the files were extracted, use the @option{--touch} (@option{-m}) option in
5308 conjunction with @option{--extract} (@option{--get}, @option{-x}).
5309
5310 @table @option
5311 @opindex touch
5312 @item --touch
5313 @itemx -m
5314 Sets the data modification time of extracted archive members to the time
5315 they were extracted, not the time recorded for them in the archive.
5316 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
5317 @end table
5318
5319 @node Setting Access Permissions
5320 @unnumberedsubsubsec Setting Access Permissions
5321
5322 @cindex Permissions of extracted files
5323 @cindex Modes of extracted files
5324 To set the modes (access permissions) of extracted files to those
5325 recorded for those files in the archive, use @option{--same-permissions}
5326 in conjunction with the @option{--extract} (@option{--get},
5327 @option{-x}) operation.
5328
5329 @table @option
5330 @opindex preserve-permissions
5331 @opindex same-permissions
5332 @item --preserve-permissions
5333 @itemx --same-permissions
5334 @c @itemx --ignore-umask
5335 @itemx -p
5336 Set modes of extracted archive members to those recorded in the
5337 archive, instead of current umask settings. Use in conjunction with
5338 @option{--extract} (@option{--get}, @option{-x}).
5339 @end table
5340
5341 @node Directory Modification Times and Permissions
5342 @unnumberedsubsubsec Directory Modification Times and Permissions
5343
5344 After successfully extracting a file member, @GNUTAR{} normally
5345 restores its permissions and modification times, as described in the
5346 previous sections. This cannot be done for directories, because
5347 after extracting a directory @command{tar} will almost certainly
5348 extract files into that directory and this will cause the directory
5349 modification time to be updated. Moreover, restoring that directory
5350 permissions may not permit file creation within it. Thus, restoring
5351 directory permissions and modification times must be delayed at least
5352 until all files have been extracted into that directory. @GNUTAR{}
5353 restores directories using the following approach.
5354
5355 The extracted directories are created with the mode specified in the
5356 archive, as modified by the umask of the user, which gives sufficient
5357 permissions to allow file creation. The meta-information about the
5358 directory is recorded in the temporary list of directories. When
5359 preparing to extract next archive member, @GNUTAR{} checks if the
5360 directory prefix of this file contains the remembered directory. If
5361 it does not, the program assumes that all files have been extracted
5362 into that directory, restores its modification time and permissions
5363 and removes its entry from the internal list. This approach allows
5364 to correctly restore directory meta-information in the majority of
5365 cases, while keeping memory requirements sufficiently small. It is
5366 based on the fact, that most @command{tar} archives use the predefined
5367 order of members: first the directory, then all the files and
5368 subdirectories in that directory.
5369
5370 However, this is not always true. The most important exception are
5371 incremental archives (@pxref{Incremental Dumps}). The member order in
5372 an incremental archive is reversed: first all directory members are
5373 stored, followed by other (non-directory) members. So, when extracting
5374 from incremental archives, @GNUTAR{} alters the above procedure. It
5375 remembers all restored directories, and restores their meta-data
5376 only after the entire archive has been processed. Notice, that you do
5377 not need to specify any special options for that, as @GNUTAR{}
5378 automatically detects archives in incremental format.
5379
5380 There may be cases, when such processing is required for normal archives
5381 too. Consider the following example:
5382
5383 @smallexample
5384 @group
5385 $ @kbd{tar --no-recursion -cvf archive \
5386 foo foo/file1 bar bar/file foo/file2}
5387 foo/
5388 foo/file1
5389 bar/
5390 bar/file
5391 foo/file2
5392 @end group
5393 @end smallexample
5394
5395 During the normal operation, after encountering @file{bar}
5396 @GNUTAR{} will assume that all files from the directory @file{foo}
5397 were already extracted and will therefore restore its timestamp and
5398 permission bits. However, after extracting @file{foo/file2} the
5399 directory timestamp will be offset again.
5400
5401 To correctly restore directory meta-information in such cases, use
5402 the @option{--delay-directory-restore} command line option:
5403
5404 @table @option
5405 @opindex delay-directory-restore
5406 @item --delay-directory-restore
5407 Delays restoring of the modification times and permissions of extracted
5408 directories until the end of extraction. This way, correct
5409 meta-information is restored even if the archive has unusual member
5410 ordering.
5411
5412 @opindex no-delay-directory-restore
5413 @item --no-delay-directory-restore
5414 Cancel the effect of the previous @option{--delay-directory-restore}.
5415 Use this option if you have used @option{--delay-directory-restore} in
5416 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5417 temporarily disable it.
5418 @end table
5419
5420 @node Writing to Standard Output
5421 @unnumberedsubsubsec Writing to Standard Output
5422
5423 @cindex Writing extracted files to standard output
5424 @cindex Standard output, writing extracted files to
5425 To write the extracted files to the standard output, instead of
5426 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5427 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5428 extracting files to send them through a pipe, and do not need to
5429 preserve them in the file system. If you extract multiple members,
5430 they appear on standard output concatenated, in the order they are
5431 found in the archive.
5432
5433 @table @option
5434 @opindex to-stdout
5435 @item --to-stdout
5436 @itemx -O
5437 Writes files to the standard output. Use only in conjunction with
5438 @option{--extract} (@option{--get}, @option{-x}). When this option is
5439 used, instead of creating the files specified, @command{tar} writes
5440 the contents of the files extracted to its standard output. This may
5441 be useful if you are only extracting the files in order to send them
5442 through a pipe. This option is meaningless with @option{--list}
5443 (@option{-t}).
5444 @end table
5445
5446 This can be useful, for example, if you have a tar archive containing
5447 a big file and don't want to store the file on disk before processing
5448 it. You can use a command like this:
5449
5450 @smallexample
5451 tar -xOzf foo.tgz bigfile | process
5452 @end smallexample
5453
5454 or even like this if you want to process the concatenation of the files:
5455
5456 @smallexample
5457 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5458 @end smallexample
5459
5460 However, @option{--to-command} may be more convenient for use with
5461 multiple files. See the next section.
5462
5463 @node Writing to an External Program
5464 @unnumberedsubsubsec Writing to an External Program
5465
5466 You can instruct @command{tar} to send the contents of each extracted
5467 file to the standard input of an external program:
5468
5469 @table @option
5470 @opindex to-command
5471 @item --to-command=@var{command}
5472 Extract files and pipe their contents to the standard input of
5473 @var{command}. When this option is used, instead of creating the
5474 files specified, @command{tar} invokes @var{command} and pipes the
5475 contents of the files to its standard output. The @var{command} may
5476 contain command line arguments. The program is executed via
5477 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5478 extracted. Non-regular files (directories, etc.) are ignored when this
5479 option is used.
5480 @end table
5481
5482 The command can obtain the information about the file it processes
5483 from the following environment variables:
5484
5485 @table @env
5486 @vrindex TAR_FILETYPE, to-command environment
5487 @item TAR_FILETYPE
5488 Type of the file. It is a single letter with the following meaning:
5489
5490 @multitable @columnfractions 0.10 0.90
5491 @item f @tab Regular file
5492 @item d @tab Directory
5493 @item l @tab Symbolic link
5494 @item h @tab Hard link
5495 @item b @tab Block device
5496 @item c @tab Character device
5497 @end multitable
5498
5499 Currently only regular files are supported.
5500
5501 @vrindex TAR_MODE, to-command environment
5502 @item TAR_MODE
5503 File mode, an octal number.
5504
5505 @vrindex TAR_FILENAME, to-command environment
5506 @item TAR_FILENAME
5507 The name of the file.
5508
5509 @vrindex TAR_REALNAME, to-command environment
5510 @item TAR_REALNAME
5511 Name of the file as stored in the archive.
5512
5513 @vrindex TAR_UNAME, to-command environment
5514 @item TAR_UNAME
5515 Name of the file owner.
5516
5517 @vrindex TAR_GNAME, to-command environment
5518 @item TAR_GNAME
5519 Name of the file owner group.
5520
5521 @vrindex TAR_ATIME, to-command environment
5522 @item TAR_ATIME
5523 Time of last access. It is a decimal number, representing seconds
5524 since the Epoch. If the archive provides times with nanosecond
5525 precision, the nanoseconds are appended to the timestamp after a
5526 decimal point.
5527
5528 @vrindex TAR_MTIME, to-command environment
5529 @item TAR_MTIME
5530 Time of last modification.
5531
5532 @vrindex TAR_CTIME, to-command environment
5533 @item TAR_CTIME
5534 Time of last status change.
5535
5536 @vrindex TAR_SIZE, to-command environment
5537 @item TAR_SIZE
5538 Size of the file.
5539
5540 @vrindex TAR_UID, to-command environment
5541 @item TAR_UID
5542 UID of the file owner.
5543
5544 @vrindex TAR_GID, to-command environment
5545 @item TAR_GID
5546 GID of the file owner.
5547 @end table
5548
5549 Additionally, the following variables contain information about
5550 tar mode and the archive being processed:
5551
5552 @table @env
5553 @vrindex TAR_VERSION, to-command environment
5554 @item TAR_VERSION
5555 @GNUTAR{} version number.
5556
5557 @vrindex TAR_ARCHIVE, to-command environment
5558 @item TAR_ARCHIVE
5559 The name of the archive @command{tar} is processing.
5560
5561 @vrindex TAR_BLOCKING_FACTOR, to-command environment
5562 @item TAR_BLOCKING_FACTOR
5563 Current blocking factor (@pxref{Blocking}).
5564
5565 @vrindex TAR_VOLUME, to-command environment
5566 @item TAR_VOLUME
5567 Ordinal number of the volume @command{tar} is processing.
5568
5569 @vrindex TAR_FORMAT, to-command environment
5570 @item TAR_FORMAT
5571 Format of the archive being processed. @xref{Formats}, for a complete
5572 list of archive format names.
5573 @end table
5574
5575 If @var{command} exits with a non-0 status, @command{tar} will print
5576 an error message similar to the following:
5577
5578 @smallexample
5579 tar: 2345: Child returned status 1
5580 @end smallexample
5581
5582 Here, @samp{2345} is the PID of the finished process.
5583
5584 If this behavior is not wanted, use @option{--ignore-command-error}:
5585
5586 @table @option
5587 @opindex ignore-command-error
5588 @item --ignore-command-error
5589 Ignore exit codes of subprocesses. Notice that if the program
5590 exits on signal or otherwise terminates abnormally, the error message
5591 will be printed even if this option is used.
5592
5593 @opindex no-ignore-command-error
5594 @item --no-ignore-command-error
5595 Cancel the effect of any previous @option{--ignore-command-error}
5596 option. This option is useful if you have set
5597 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5598 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5599 @end table
5600
5601 @node remove files
5602 @unnumberedsubsubsec Removing Files
5603
5604 @FIXME{The section is too terse. Something more to add? An example,
5605 maybe?}
5606
5607 @table @option
5608 @opindex remove-files
5609 @item --remove-files
5610 Remove files after adding them to the archive.
5611 @end table
5612
5613 @node Scarce
5614 @subsection Coping with Scarce Resources
5615 @UNREVISED
5616
5617 @cindex Small memory
5618 @cindex Running out of space
5619
5620 @menu
5621 * Starting File::
5622 * Same Order::
5623 @end menu
5624
5625 @node Starting File
5626 @unnumberedsubsubsec Starting File
5627
5628 @table @option
5629 @opindex starting-file
5630 @item --starting-file=@var{name}
5631 @itemx -K @var{name}
5632 Starts an operation in the middle of an archive. Use in conjunction
5633 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5634 @end table
5635
5636 @cindex Middle of the archive, starting in the
5637 If a previous attempt to extract files failed due to lack of disk
5638 space, you can use @option{--starting-file=@var{name}} (@option{-K
5639 @var{name}}) to start extracting only after member @var{name} of the
5640 archive. This assumes, of course, that there is now free space, or
5641 that you are now extracting into a different file system. (You could
5642 also choose to suspend @command{tar}, remove unnecessary files from
5643 the file system, and then resume the same @command{tar} operation.
5644 In this case, @option{--starting-file} is not necessary.) See also
5645 @ref{interactive}, and @ref{exclude}.
5646
5647 @node Same Order
5648 @unnumberedsubsubsec Same Order
5649
5650 @table @option
5651 @cindex Large lists of file names on small machines
5652 @opindex same-order
5653 @opindex preserve-order
5654 @item --same-order
5655 @itemx --preserve-order
5656 @itemx -s
5657 To process large lists of file names on machines with small amounts of
5658 memory. Use in conjunction with @option{--compare} (@option{--diff},
5659 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5660 (@option{--get}, @option{-x}).
5661 @end table
5662
5663 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5664 names to be listed or extracted is sorted in the same order as the
5665 files in the archive. This allows a large list of names to be used,
5666 even on a small machine that would not otherwise be able to hold all
5667 the names in memory at the same time. Such a sorted list can easily be
5668 created by running @samp{tar -t} on the archive and editing its output.
5669
5670 This option is probably never needed on modern computer systems.
5671
5672 @node backup
5673 @section Backup options
5674
5675 @cindex backup options
5676
5677 @GNUTAR{} offers options for making backups of files
5678 before writing new versions. These options control the details of
5679 these backups. They may apply to the archive itself before it is
5680 created or rewritten, as well as individual extracted members. Other
5681 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5682 and @command{mv}, for example) offer similar options.
5683
5684 Backup options may prove unexpectedly useful when extracting archives
5685 containing many members having identical name, or when extracting archives
5686 on systems having file name limitations, making different members appear
5687 as having similar names through the side-effect of name truncation.
5688 @FIXME{This is true only if we have a good scheme for truncated backup names,
5689 which I'm not sure at all: I suspect work is needed in this area.}
5690 When any existing file is backed up before being overwritten by extraction,
5691 then clashing files are automatically be renamed to be unique, and the
5692 true name is kept for only the last file of a series of clashing files.
5693 By using verbose mode, users may track exactly what happens.
5694
5695 At the detail level, some decisions are still experimental, and may
5696 change in the future, we are waiting comments from our users. So, please
5697 do not learn to depend blindly on the details of the backup features.
5698 For example, currently, directories themselves are never renamed through
5699 using these options, so, extracting a file over a directory still has
5700 good chances to fail. Also, backup options apply to created archives,
5701 not only to extracted members. For created archives, backups will not
5702 be attempted when the archive is a block or character device, or when it
5703 refers to a remote file.
5704
5705 For the sake of simplicity and efficiency, backups are made by renaming old
5706 files prior to creation or extraction, and not by copying. The original
5707 name is restored if the file creation fails. If a failure occurs after a
5708 partial extraction of a file, both the backup and the partially extracted
5709 file are kept.
5710
5711 @table @samp
5712 @item --backup[=@var{method}]
5713 @opindex backup
5714 @vindex VERSION_CONTROL
5715 @cindex backups
5716 Back up files that are about to be overwritten or removed.
5717 Without this option, the original versions are destroyed.
5718
5719 Use @var{method} to determine the type of backups made.
5720 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5721 environment variable. And if @env{VERSION_CONTROL} is not set,
5722 use the @samp{existing} method.
5723
5724 @vindex version-control @r{Emacs variable}
5725 This option corresponds to the Emacs variable @samp{version-control};
5726 the same values for @var{method} are accepted as in Emacs. This option
5727 also allows more descriptive names. The valid @var{method}s are:
5728
5729 @table @samp
5730 @item t
5731 @itemx numbered
5732 @cindex numbered @r{backup method}
5733 Always make numbered backups.
5734
5735 @item nil
5736 @itemx existing
5737 @cindex existing @r{backup method}
5738 Make numbered backups of files that already have them, simple backups
5739 of the others.
5740
5741 @item never
5742 @itemx simple
5743 @cindex simple @r{backup method}
5744 Always make simple backups.
5745
5746 @end table
5747
5748 @item --suffix=@var{suffix}
5749 @opindex suffix
5750 @cindex backup suffix
5751 @vindex SIMPLE_BACKUP_SUFFIX
5752 Append @var{suffix} to each backup file made with @option{--backup}. If this
5753 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5754 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5755 set, the default is @samp{~}, just as in Emacs.
5756
5757 @end table
5758
5759 @node Applications
5760 @section Notable @command{tar} Usages
5761 @UNREVISED
5762
5763 @FIXME{Using Unix file linking capability to recreate directory
5764 structures---linking files into one subdirectory and then
5765 @command{tar}ring that directory.}
5766
5767 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5768
5769 @findex uuencode
5770 You can easily use archive files to transport a group of files from
5771 one system to another: put all relevant files into an archive on one
5772 computer system, transfer the archive to another system, and extract
5773 the contents there. The basic transfer medium might be magnetic tape,
5774 Internet FTP, or even electronic mail (though you must encode the
5775 archive with @command{uuencode} in order to transport it properly by
5776 mail). Both machines do not have to use the same operating system, as
5777 long as they both support the @command{tar} program.
5778
5779 For example, here is how you might copy a directory's contents from
5780 one disk to another, while preserving the dates, modes, owners and
5781 link-structure of all the files therein. In this case, the transfer
5782 medium is a @dfn{pipe}:
5783
5784 @smallexample
5785 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5786 @end smallexample
5787
5788 @noindent
5789 You can avoid subshells by using @option{-C} option:
5790
5791 @smallexample
5792 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5793 @end smallexample
5794
5795 @noindent
5796 The command also works using long option forms:
5797
5798 @smallexample
5799 @group
5800 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5801 | (cd targetdir; tar --extract --file=-)}
5802 @end group
5803 @end smallexample
5804
5805 @noindent
5806 or
5807
5808 @smallexample
5809 @group
5810 $ @kbd{tar --directory sourcedir --create --file=- . \
5811 | tar --directory targetdir --extract --file=-}
5812 @end group
5813 @end smallexample
5814
5815 @noindent
5816 This is one of the easiest methods to transfer a @command{tar} archive.
5817
5818 @node looking ahead
5819 @section Looking Ahead: The Rest of this Manual
5820
5821 You have now seen how to use all eight of the operations available to
5822 @command{tar}, and a number of the possible options. The next chapter
5823 explains how to choose and change file and archive names, how to use
5824 files to store names of other files which you can then call as
5825 arguments to @command{tar} (this can help you save time if you expect to
5826 archive the same list of files a number of times), and so forth.
5827 @FIXME{in case it's not obvious, i'm making this up in some sense
5828 based on my limited memory of what the next chapter *really* does. i
5829 just wanted to flesh out this final section a little bit so i'd
5830 remember to stick it in here. :-)}
5831
5832 If there are too many files to conveniently list on the command line,
5833 you can list the names in a file, and @command{tar} will read that file.
5834 @xref{files}.
5835
5836 There are various ways of causing @command{tar} to skip over some files,
5837 and not archive them. @xref{Choosing}.
5838
5839 @node Backups
5840 @chapter Performing Backups and Restoring Files
5841 @cindex backups
5842
5843 @GNUTAR{} is distributed along with the scripts for performing backups
5844 and restores. Even if there is a good chance those scripts may be
5845 satisfying to you, they are not the only scripts or methods available for doing
5846 backups and restore. You may well create your own, or use more
5847 sophisticated packages dedicated to that purpose.
5848
5849 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5850 Automatic Network Disk Archiver), a backup system developed by James
5851 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5852 This is free software, and it is available from @uref{http://www.amanda.org}.
5853
5854 @FIXME{
5855
5856 Here is a possible plan for a future documentation about the backuping
5857 scripts which are provided within the @GNUTAR{}
5858 distribution.
5859
5860 @itemize @bullet
5861 @item dumps
5862 @itemize @minus
5863 @item what are dumps
5864 @item different levels of dumps
5865 @itemize +
5866 @item full dump = dump everything
5867 @item level 1, level 2 dumps etc
5868 A level @var{n} dump dumps everything changed since the last level
5869 @var{n}-1 dump (?)
5870 @end itemize
5871 @item how to use scripts for dumps (ie, the concept)
5872 @itemize +
5873 @item scripts to run after editing backup specs (details)
5874 @end itemize
5875 @item Backup Specs, what is it.
5876 @itemize +
5877 @item how to customize
5878 @item actual text of script [/sp/dump/backup-specs]
5879 @end itemize
5880 @item Problems
5881 @itemize +
5882 @item rsh doesn't work
5883 @item rtape isn't installed
5884 @item (others?)
5885 @end itemize
5886 @item the @option{--incremental} option of tar
5887 @item tapes
5888 @itemize +
5889 @item write protection
5890 @item types of media, different sizes and types, useful for different things
5891 @item files and tape marks
5892 one tape mark between files, two at end.
5893 @item positioning the tape
5894 MT writes two at end of write,
5895 backspaces over one when writing again.
5896 @end itemize
5897 @end itemize
5898 @end itemize
5899 }
5900
5901 This chapter documents both the provided shell scripts and @command{tar}
5902 options which are more specific to usage as a backup tool.
5903
5904 To @dfn{back up} a file system means to create archives that contain
5905 all the files in that file system. Those archives can then be used to
5906 restore any or all of those files (for instance if a disk crashes or a
5907 file is accidentally deleted). File system @dfn{backups} are also
5908 called @dfn{dumps}.
5909
5910 @menu
5911 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5912 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5913 * Backup Levels:: Levels of Backups
5914 * Backup Parameters:: Setting Parameters for Backups and Restoration
5915 * Scripted Backups:: Using the Backup Scripts
5916 * Scripted Restoration:: Using the Restore Script
5917 @end menu
5918
5919 @node Full Dumps
5920 @section Using @command{tar} to Perform Full Dumps
5921 @UNREVISED
5922
5923 @cindex full dumps
5924 @cindex dumps, full
5925
5926 @cindex corrupted archives
5927 Full dumps should only be made when no other people or programs
5928 are modifying files in the file system. If files are modified while
5929 @command{tar} is making the backup, they may not be stored properly in
5930 the archive, in which case you won't be able to restore them if you
5931 have to. (Files not being modified are written with no trouble, and do
5932 not corrupt the entire archive.)
5933
5934 You will want to use the @option{--label=@var{archive-label}}
5935 (@option{-V @var{archive-label}}) option to give the archive a
5936 volume label, so you can tell what this archive is even if the label
5937 falls off the tape, or anything like that.
5938
5939 Unless the file system you are dumping is guaranteed to fit on
5940 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5941 Make sure you have enough tapes on hand to complete the backup.
5942
5943 If you want to dump each file system separately you will need to use
5944 the @option{--one-file-system} option to prevent
5945 @command{tar} from crossing file system boundaries when storing
5946 (sub)directories.
5947
5948 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5949 option is not needed, since this is a complete copy of everything in
5950 the file system, and a full restore from this backup would only be
5951 done onto a completely
5952 empty disk.
5953
5954 Unless you are in a hurry, and trust the @command{tar} program (and your
5955 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5956 option, to make sure your files really made it onto the dump properly.
5957 This will also detect cases where the file was modified while (or just
5958 after) it was being archived. Not all media (notably cartridge tapes)
5959 are capable of being verified, unfortunately.
5960
5961 @node Incremental Dumps
5962 @section Using @command{tar} to Perform Incremental Dumps
5963
5964 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5965 stores additional metadata so that exact state of the file system
5966 can be restored when extracting the archive.
5967
5968 @GNUTAR{} currently offers two options for handling incremental
5969 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5970 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5971
5972 @xopindex{listed-incremental, described}
5973 The option @option{--listed-incremental} instructs tar to operate on
5974 an incremental archive with additional metadata stored in a standalone
5975 file, called a @dfn{snapshot file}. The purpose of this file is to help
5976 determine which files have been changed, added or deleted since the
5977 last backup, so that the next incremental backup will contain only
5978 modified files. The name of the snapshot file is given as an argument
5979 to the option:
5980
5981 @table @option
5982 @item --listed-incremental=@var{file}
5983 @itemx -g @var{file}
5984 Handle incremental backups with snapshot data in @var{file}.
5985 @end table
5986
5987 To create an incremental backup, you would use
5988 @option{--listed-incremental} together with @option{--create}
5989 (@pxref{create}). For example:
5990
5991 @smallexample
5992 $ @kbd{tar --create \
5993 --file=archive.1.tar \
5994 --listed-incremental=/var/log/usr.snar \
5995 /usr}
5996 @end smallexample
5997
5998 This will create in @file{archive.1.tar} an incremental backup of
5999 the @file{/usr} file system, storing additional metadata in the file
6000 @file{/var/log/usr.snar}. If this file does not exist, it will be
6001 created. The created archive will then be a @dfn{level 0 backup};
6002 please see the next section for more on backup levels.
6003
6004 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6005 determines which files are modified. In this case only these files will be
6006 stored in the archive. Suppose, for example, that after running the
6007 above command, you delete file @file{/usr/doc/old} and create
6008 directory @file{/usr/local/db} with the following contents:
6009
6010 @smallexample
6011 $ @kbd{ls /usr/local/db}
6012 /usr/local/db/data
6013 /usr/local/db/index
6014 @end smallexample
6015
6016 Some time later you create another incremental backup. You will
6017 then see:
6018
6019 @smallexample
6020 $ @kbd{tar --create \
6021 --file=archive.2.tar \
6022 --listed-incremental=/var/log/usr.snar \
6023 /usr}
6024 tar: usr/local/db: Directory is new
6025 usr/local/db/
6026 usr/local/db/data
6027 usr/local/db/index
6028 @end smallexample
6029
6030 @noindent
6031 The created archive @file{archive.2.tar} will contain only these
6032 three members. This archive is called a @dfn{level 1 backup}. Notice
6033 that @file{/var/log/usr.snar} will be updated with the new data, so if
6034 you plan to create more @samp{level 1} backups, it is necessary to
6035 create a working copy of the snapshot file before running
6036 @command{tar}. The above example will then be modified as follows:
6037
6038 @smallexample
6039 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6040 $ @kbd{tar --create \
6041 --file=archive.2.tar \
6042 --listed-incremental=/var/log/usr.snar-1 \
6043 /usr}
6044 @end smallexample
6045
6046 @anchor{--level=0}
6047 @xopindex{level, described}
6048 You can force @samp{level 0} backups either by removing the snapshot
6049 file before running @command{tar}, or by supplying the
6050 @option{--level=0} option, e.g.:
6051
6052 @smallexample
6053 $ @kbd{tar --create \
6054 --file=archive.2.tar \
6055 --listed-incremental=/var/log/usr.snar-0 \
6056 --level=0 \
6057 /usr}
6058 @end smallexample
6059
6060 Incremental dumps depend crucially on time stamps, so the results are
6061 unreliable if you modify a file's time stamps during dumping (e.g.,
6062 with the @option{--atime-preserve=replace} option), or if you set the clock
6063 backwards.
6064
6065 @anchor{device numbers}
6066 @cindex Device numbers, using in incremental backups
6067 Metadata stored in snapshot files include device numbers, which,
6068 obviously are supposed to be non-volatile values. However, it turns
6069 out that @acronym{NFS} devices have undependable values when an automounter
6070 gets in the picture. This can lead to a great deal of spurious
6071 redumping in incremental dumps, so it is somewhat useless to compare
6072 two @acronym{NFS} devices numbers over time. The solution implemented
6073 currently is to consider all @acronym{NFS} devices as being equal
6074 when it comes to comparing directories; this is fairly gross, but
6075 there does not seem to be a better way to go.
6076
6077 Apart from using @acronym{NFS}, there are a number of cases where
6078 relying on device numbers can cause spurious redumping of unmodified
6079 files. For example, this occurs when archiving @acronym{LVM} snapshot
6080 volumes. To avoid this, use @option{--no-check-device} option:
6081
6082 @table @option
6083 @xopindex{no-check-device, described}
6084 @item --no-check-device
6085 Do not rely on device numbers when preparing a list of changed files
6086 for an incremental dump.
6087
6088 @xopindex{check-device, described}
6089 @item --check-device
6090 Use device numbers when preparing a list of changed files
6091 for an incremental dump. This is the default behavior. The purpose
6092 of this option is to undo the effect of the @option{--no-check-device}
6093 if it was given in @env{TAR_OPTIONS} environment variable
6094 (@pxref{TAR_OPTIONS}).
6095 @end table
6096
6097 There is also another way to cope with changing device numbers. It is
6098 described in detail in @ref{Fixing Snapshot Files}.
6099
6100 Note that incremental archives use @command{tar} extensions and may
6101 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6102
6103 @xopindex{listed-incremental, using with @option{--extract}}
6104 @xopindex{extract, using with @option{--listed-incremental}}
6105 To extract from the incremental dumps, use
6106 @option{--listed-incremental} together with @option{--extract}
6107 option (@pxref{extracting files}). In this case, @command{tar} does
6108 not need to access snapshot file, since all the data necessary for
6109 extraction are stored in the archive itself. So, when extracting, you
6110 can give whatever argument to @option{--listed-incremental}, the usual
6111 practice is to use @option{--listed-incremental=/dev/null}.
6112 Alternatively, you can use @option{--incremental}, which needs no
6113 arguments. In general, @option{--incremental} (@option{-G}) can be
6114 used as a shortcut for @option{--listed-incremental} when listing or
6115 extracting incremental backups (for more information regarding this
6116 option, @pxref{incremental-op}).
6117
6118 When extracting from the incremental backup @GNUTAR{} attempts to
6119 restore the exact state the file system had when the archive was
6120 created. In particular, it will @emph{delete} those files in the file
6121 system that did not exist in their directories when the archive was
6122 created. If you have created several levels of incremental files,
6123 then in order to restore the exact contents the file system had when
6124 the last level was created, you will need to restore from all backups
6125 in turn. Continuing our example, to restore the state of @file{/usr}
6126 file system, one would do@footnote{Notice, that since both archives
6127 were created without @option{-P} option (@pxref{absolute}), these
6128 commands should be run from the root file system.}:
6129
6130 @smallexample
6131 $ @kbd{tar --extract \
6132 --listed-incremental=/dev/null \
6133 --file archive.1.tar}
6134 $ @kbd{tar --extract \
6135 --listed-incremental=/dev/null \
6136 --file archive.2.tar}
6137 @end smallexample
6138
6139 To list the contents of an incremental archive, use @option{--list}
6140 (@pxref{list}), as usual. To obtain more information about the
6141 archive, use @option{--listed-incremental} or @option{--incremental}
6142 combined with two @option{--verbose} options@footnote{Two
6143 @option{--verbose} options were selected to avoid breaking usual
6144 verbose listing output (@option{--list --verbose}) when using in
6145 scripts.
6146
6147 @xopindex{incremental, using with @option{--list}}
6148 @xopindex{listed-incremental, using with @option{--list}}
6149 @xopindex{list, using with @option{--incremental}}
6150 @xopindex{list, using with @option{--listed-incremental}}
6151 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6152 contents of the DUMPDIR header (with terminating nulls) when
6153 @option{--incremental} or @option{--listed-incremental} option was
6154 given, no matter what the verbosity level. This behavior, and,
6155 especially, the binary output it produced were considered inconvenient
6156 and were changed in version 1.16.}:
6157
6158 @smallexample
6159 @kbd{tar --list --incremental --verbose --verbose archive.tar}
6160 @end smallexample
6161
6162 This command will print, for each directory in the archive, the list
6163 of files in that directory at the time the archive was created. This
6164 information is put out in a format which is both human-readable and
6165 unambiguous for a program: each file name is printed as
6166
6167 @smallexample
6168 @var{x} @var{file}
6169 @end smallexample
6170
6171 @noindent
6172 where @var{x} is a letter describing the status of the file: @samp{Y}
6173 if the file is present in the archive, @samp{N} if the file is not
6174 included in the archive, or a @samp{D} if the file is a directory (and
6175 is included in the archive). @xref{Dumpdir}, for the detailed
6176 description of dumpdirs and status codes. Each such
6177 line is terminated by a newline character. The last line is followed
6178 by an additional newline to indicate the end of the data.
6179
6180 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6181 gives the same behavior as @option{--listed-incremental} when used
6182 with @option{--list} and @option{--extract} options. When used with
6183 @option{--create} option, it creates an incremental archive without
6184 creating snapshot file. Thus, it is impossible to create several
6185 levels of incremental backups with @option{--incremental} option.
6186
6187 @node Backup Levels
6188 @section Levels of Backups
6189
6190 An archive containing all the files in the file system is called a
6191 @dfn{full backup} or @dfn{full dump}. You could insure your data by
6192 creating a full dump every day. This strategy, however, would waste a
6193 substantial amount of archive media and user time, as unchanged files
6194 are daily re-archived.
6195
6196 It is more efficient to do a full dump only occasionally. To back up
6197 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
6198 one} dump archives all the files that have changed since the last full
6199 dump.
6200
6201 A typical dump strategy would be to perform a full dump once a week,
6202 and a level one dump once a day. This means some versions of files
6203 will in fact be archived more than once, but this dump strategy makes
6204 it possible to restore a file system to within one day of accuracy by
6205 only extracting two archives---the last weekly (full) dump and the
6206 last daily (level one) dump. The only information lost would be in
6207 files changed or created since the last daily backup. (Doing dumps
6208 more than once a day is usually not worth the trouble.)
6209
6210 @GNUTAR{} comes with scripts you can use to do full
6211 and level-one (actually, even level-two and so on) dumps. Using
6212 scripts (shell programs) to perform backups and restoration is a
6213 convenient and reliable alternative to typing out file name lists
6214 and @command{tar} commands by hand.
6215
6216 Before you use these scripts, you need to edit the file
6217 @file{backup-specs}, which specifies parameters used by the backup
6218 scripts and by the restore script. This file is usually located
6219 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
6220 detailed description. Once the backup parameters are set, you can
6221 perform backups or restoration by running the appropriate script.
6222
6223 The name of the backup script is @code{backup}. The name of the
6224 restore script is @code{restore}. The following sections describe
6225 their use in detail.
6226
6227 @emph{Please Note:} The backup and restoration scripts are
6228 designed to be used together. While it is possible to restore files by
6229 hand from an archive which was created using a backup script, and to create
6230 an archive by hand which could then be extracted using the restore script,
6231 it is easier to use the scripts. @xref{Incremental Dumps}, before
6232 making such an attempt.
6233
6234 @node Backup Parameters
6235 @section Setting Parameters for Backups and Restoration
6236
6237 The file @file{backup-specs} specifies backup parameters for the
6238 backup and restoration scripts provided with @command{tar}. You must
6239 edit @file{backup-specs} to fit your system configuration and schedule
6240 before using these scripts.
6241
6242 Syntactically, @file{backup-specs} is a shell script, containing
6243 mainly variable assignments. However, any valid shell construct
6244 is allowed in this file. Particularly, you may wish to define
6245 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6246 For more information about shell script syntax, please refer to
6247 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6248 g_02, the definition of the Shell Command Language}. See also
6249 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6250
6251 The shell variables controlling behavior of @code{backup} and
6252 @code{restore} are described in the following subsections.
6253
6254 @menu
6255 * General-Purpose Variables::
6256 * Magnetic Tape Control::
6257 * User Hooks::
6258 * backup-specs example:: An Example Text of @file{Backup-specs}
6259 @end menu
6260
6261 @node General-Purpose Variables
6262 @subsection General-Purpose Variables
6263
6264 @defvr {Backup variable} ADMINISTRATOR
6265 The user name of the backup administrator. @code{Backup} scripts
6266 sends a backup report to this address.
6267 @end defvr
6268
6269 @defvr {Backup variable} BACKUP_HOUR
6270 The hour at which the backups are done. This can be a number from 0
6271 to 23, or the time specification in form @var{hours}:@var{minutes},
6272 or the string @samp{now}.
6273
6274 This variable is used by @code{backup}. Its value may be overridden
6275 using @option{--time} option (@pxref{Scripted Backups}).
6276 @end defvr
6277
6278 @defvr {Backup variable} TAPE_FILE
6279
6280 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
6281 is a remote archive (@pxref{remote-dev}), backup script will suppose
6282 that your @command{mt} is able to access remote devices. If @var{RSH}
6283 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6284 invocations of @command{mt}.
6285 @end defvr
6286
6287 @defvr {Backup variable} BLOCKING
6288
6289 The blocking factor @command{tar} will use when writing the dump archive.
6290 @xref{Blocking Factor}.
6291 @end defvr
6292
6293 @defvr {Backup variable} BACKUP_DIRS
6294
6295 A list of file systems to be dumped (for @code{backup}), or restored
6296 (for @code{restore}). You can include any directory
6297 name in the list --- subdirectories on that file system will be
6298 included, regardless of how they may look to other networked machines.
6299 Subdirectories on other file systems will be ignored.
6300
6301 The host name specifies which host to run @command{tar} on, and should
6302 normally be the host that actually contains the file system. However,
6303 the host machine must have @GNUTAR{} installed, and
6304 must be able to access the directory containing the backup scripts and
6305 their support files using the same file name that is used on the
6306 machine where the scripts are run (i.e., what @command{pwd} will print
6307 when in that directory on that machine). If the host that contains
6308 the file system does not have this capability, you can specify another
6309 host as long as it can access the file system through @acronym{NFS}.
6310
6311 If the list of file systems is very long you may wish to put it
6312 in a separate file. This file is usually named
6313 @file{/etc/backup/dirs}, but this name may be overridden in
6314 @file{backup-specs} using @code{DIRLIST} variable.
6315 @end defvr
6316
6317 @defvr {Backup variable} DIRLIST
6318
6319 The name of the file that contains a list of file systems to backup
6320 or restore. By default it is @file{/etc/backup/dirs}.
6321 @end defvr
6322
6323 @defvr {Backup variable} BACKUP_FILES
6324
6325 A list of individual files to be dumped (for @code{backup}), or restored
6326 (for @code{restore}). These should be accessible from the machine on
6327 which the backup script is run.
6328
6329 If the list of individual files is very long you may wish to store it
6330 in a separate file. This file is usually named
6331 @file{/etc/backup/files}, but this name may be overridden in
6332 @file{backup-specs} using @code{FILELIST} variable.
6333 @end defvr
6334
6335 @defvr {Backup variable} FILELIST
6336
6337 The name of the file that contains a list of individual files to backup
6338 or restore. By default it is @file{/etc/backup/files}.
6339 @end defvr
6340
6341 @defvr {Backup variable} MT
6342
6343 Full file name of @command{mt} binary.
6344 @end defvr
6345
6346 @defvr {Backup variable} RSH
6347 @anchor{RSH}
6348 Full file name of @command{rsh} binary or its equivalent. You may wish to
6349 set it to @code{ssh}, to improve security. In this case you will have
6350 to use public key authentication.
6351 @end defvr
6352
6353 @defvr {Backup variable} RSH_COMMAND
6354
6355 Full file name of @command{rsh} binary on remote machines. This will
6356 be passed via @option{--rsh-command} option to the remote invocation
6357 of @GNUTAR{}.
6358 @end defvr
6359
6360 @defvr {Backup variable} VOLNO_FILE
6361
6362 Name of temporary file to hold volume numbers. This needs to be accessible
6363 by all the machines which have file systems to be dumped.
6364 @end defvr
6365
6366 @defvr {Backup variable} XLIST
6367
6368 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
6369 located on the remote machine and containing the list of files to
6370 be excluded from the backup. Exclude file lists are searched in
6371 /etc/tar-backup directory. A common use for exclude file lists
6372 is to exclude files containing security-sensitive information
6373 (e.g., @file{/etc/shadow} from backups).
6374
6375 This variable affects only @code{backup}.
6376 @end defvr
6377
6378 @defvr {Backup variable} SLEEP_TIME
6379
6380 Time to sleep between dumps of any two successive file systems
6381
6382 This variable affects only @code{backup}.
6383 @end defvr
6384
6385 @defvr {Backup variable} DUMP_REMIND_SCRIPT
6386
6387 Script to be run when it's time to insert a new tape in for the next
6388 volume. Administrators may want to tailor this script for their site.
6389 If this variable isn't set, @GNUTAR{} will display its built-in
6390 prompt, and will expect confirmation from the console. For the
6391 description of the default prompt, see @ref{change volume prompt}.
6392
6393 @end defvr
6394
6395 @defvr {Backup variable} SLEEP_MESSAGE
6396
6397 Message to display on the terminal while waiting for dump time. Usually
6398 this will just be some literal text.
6399 @end defvr
6400
6401 @defvr {Backup variable} TAR
6402
6403 Full file name of the @GNUTAR{} executable. If this is not set, backup
6404 scripts will search @command{tar} in the current shell path.
6405 @end defvr
6406
6407 @node Magnetic Tape Control
6408 @subsection Magnetic Tape Control
6409
6410 Backup scripts access tape device using special @dfn{hook functions}.
6411 These functions take a single argument --- the name of the tape
6412 device. Their names are kept in the following variables:
6413
6414 @defvr {Backup variable} MT_BEGIN
6415 The name of @dfn{begin} function. This function is called before
6416 accessing the drive. By default it retensions the tape:
6417
6418 @smallexample
6419 MT_BEGIN=mt_begin
6420
6421 mt_begin() @{
6422 mt -f "$1" retension
6423 @}
6424 @end smallexample
6425 @end defvr
6426
6427 @defvr {Backup variable} MT_REWIND
6428 The name of @dfn{rewind} function. The default definition is as
6429 follows:
6430
6431 @smallexample
6432 MT_REWIND=mt_rewind
6433
6434 mt_rewind() @{
6435 mt -f "$1" rewind
6436 @}
6437 @end smallexample
6438
6439 @end defvr
6440
6441 @defvr {Backup variable} MT_OFFLINE
6442 The name of the function switching the tape off line. By default
6443 it is defined as follows:
6444
6445 @smallexample
6446 MT_OFFLINE=mt_offline
6447
6448 mt_offline() @{
6449 mt -f "$1" offl
6450 @}
6451 @end smallexample
6452 @end defvr
6453
6454 @defvr {Backup variable} MT_STATUS
6455 The name of the function used to obtain the status of the archive device,
6456 including error count. Default definition:
6457
6458 @smallexample
6459 MT_STATUS=mt_status
6460
6461 mt_status() @{
6462 mt -f "$1" status
6463 @}
6464 @end smallexample
6465 @end defvr
6466
6467 @node User Hooks
6468 @subsection User Hooks
6469
6470 @dfn{User hooks} are shell functions executed before and after
6471 each @command{tar} invocation. Thus, there are @dfn{backup
6472 hooks}, which are executed before and after dumping each file
6473 system, and @dfn{restore hooks}, executed before and
6474 after restoring a file system. Each user hook is a shell function
6475 taking four arguments:
6476
6477 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6478 Its arguments are:
6479
6480 @table @var
6481 @item level
6482 Current backup or restore level.
6483
6484 @item host
6485 Name or IP address of the host machine being dumped or restored.
6486
6487 @item fs
6488 Full file name of the file system being dumped or restored.
6489
6490 @item fsname
6491 File system name with directory separators replaced with colons. This
6492 is useful, e.g., for creating unique files.
6493 @end table
6494 @end deffn
6495
6496 Following variables keep the names of user hook functions:
6497
6498 @defvr {Backup variable} DUMP_BEGIN
6499 Dump begin function. It is executed before dumping the file system.
6500 @end defvr
6501
6502 @defvr {Backup variable} DUMP_END
6503 Executed after dumping the file system.
6504 @end defvr
6505
6506 @defvr {Backup variable} RESTORE_BEGIN
6507 Executed before restoring the file system.
6508 @end defvr
6509
6510 @defvr {Backup variable} RESTORE_END
6511 Executed after restoring the file system.
6512 @end defvr
6513
6514 @node backup-specs example
6515 @subsection An Example Text of @file{Backup-specs}
6516
6517 The following is an example of @file{backup-specs}:
6518
6519 @smallexample
6520 # site-specific parameters for file system backup.
6521
6522 ADMINISTRATOR=friedman
6523 BACKUP_HOUR=1
6524 TAPE_FILE=/dev/nrsmt0
6525
6526 # Use @code{ssh} instead of the less secure @code{rsh}
6527 RSH=/usr/bin/ssh
6528 RSH_COMMAND=/usr/bin/ssh
6529
6530 # Override MT_STATUS function:
6531 my_status() @{
6532 mts -t $TAPE_FILE
6533 @}
6534 MT_STATUS=my_status
6535
6536 # Disable MT_OFFLINE function
6537 MT_OFFLINE=:
6538
6539 BLOCKING=124
6540 BACKUP_DIRS="
6541 albert:/fs/fsf
6542 apple-gunkies:/gd
6543 albert:/fs/gd2
6544 albert:/fs/gp
6545 geech:/usr/jla
6546 churchy:/usr/roland
6547 albert:/
6548 albert:/usr
6549 apple-gunkies:/
6550 apple-gunkies:/usr
6551 gnu:/hack
6552 gnu:/u
6553 apple-gunkies:/com/mailer/gnu
6554 apple-gunkies:/com/archive/gnu"
6555
6556 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6557
6558 @end smallexample
6559
6560 @node Scripted Backups
6561 @section Using the Backup Scripts
6562
6563 The syntax for running a backup script is:
6564
6565 @smallexample
6566 backup --level=@var{level} --time=@var{time}
6567 @end smallexample
6568
6569 The @option{--level} option requests the dump level. Thus, to produce
6570 a full dump, specify @code{--level=0} (this is the default, so
6571 @option{--level} may be omitted if its value is
6572 @code{0})@footnote{For backward compatibility, the @code{backup} will also
6573 try to deduce the requested dump level from the name of the
6574 script itself. If the name consists of a string @samp{level-}
6575 followed by a single decimal digit, that digit is taken as
6576 the dump level number. Thus, you may create a link from @code{backup}
6577 to @code{level-1} and then run @code{level-1} whenever you need to
6578 create a level one dump.}.
6579
6580 The @option{--time} option determines when should the backup be
6581 run. @var{Time} may take three forms:
6582
6583 @table @asis
6584 @item @var{hh}:@var{mm}
6585
6586 The dump must be run at @var{hh} hours @var{mm} minutes.
6587
6588 @item @var{hh}
6589
6590 The dump must be run at @var{hh} hours.
6591
6592 @item now
6593
6594 The dump must be run immediately.
6595 @end table
6596
6597 You should start a script with a tape or disk mounted. Once you
6598 start a script, it prompts you for new tapes or disks as it
6599 needs them. Media volumes don't have to correspond to archive
6600 files --- a multi-volume archive can be started in the middle of a
6601 tape that already contains the end of another multi-volume archive.
6602 The @code{restore} script prompts for media by its archive volume,
6603 so to avoid an error message you should keep track of which tape
6604 (or disk) contains which volume of the archive (@pxref{Scripted
6605 Restoration}).
6606
6607 The backup scripts write two files on the file system. The first is a
6608 record file in @file{/etc/tar-backup/}, which is used by the scripts
6609 to store and retrieve information about which files were dumped. This
6610 file is not meant to be read by humans, and should not be deleted by
6611 them. @xref{Snapshot Files}, for a more detailed explanation of this
6612 file.
6613
6614 The second file is a log file containing the names of the file systems
6615 and files dumped, what time the backup was made, and any error
6616 messages that were generated, as well as how much space was left in
6617 the media volume after the last volume of the archive was written.
6618 You should check this log file after every backup. The file name is
6619 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6620 represents current date, and @var{n} represents current dump level number.
6621
6622 The script also prints the name of each system being dumped to the
6623 standard output.
6624
6625 Following is the full list of options accepted by @code{backup}
6626 script:
6627
6628 @table @option
6629 @item -l @var{level}
6630 @itemx --level=@var{level}
6631 Do backup level @var{level} (default 0).
6632
6633 @item -f
6634 @itemx --force
6635 Force backup even if today's log file already exists.
6636
6637 @item -v[@var{level}]
6638 @itemx --verbose[=@var{level}]
6639 Set verbosity level. The higher the level is, the more debugging
6640 information will be output during execution. Default @var{level}
6641 is 100, which means the highest debugging level.
6642
6643 @item -t @var{start-time}
6644 @itemx --time=@var{start-time}
6645 Wait till @var{time}, then do backup.
6646
6647 @item -h
6648 @itemx --help
6649 Display short help message and exit.
6650
6651 @item -V
6652 @itemx --version
6653 Display information about the program's name, version, origin and legal
6654 status, all on standard output, and then exit successfully.
6655 @end table
6656
6657
6658 @node Scripted Restoration
6659 @section Using the Restore Script
6660
6661 To restore files that were archived using a scripted backup, use the
6662 @code{restore} script. Its usage is quite straightforward. In the
6663 simplest form, invoke @code{restore --all}, it will
6664 then restore all the file systems and files specified in
6665 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6666
6667 You may select the file systems (and/or files) to restore by
6668 giving @code{restore} a list of @dfn{patterns} in its command
6669 line. For example, running
6670
6671 @smallexample
6672 restore 'albert:*'
6673 @end smallexample
6674
6675 @noindent
6676 will restore all file systems on the machine @samp{albert}. A more
6677 complicated example:
6678
6679 @smallexample
6680 restore 'albert:*' '*:/var'
6681 @end smallexample
6682
6683 @noindent
6684 This command will restore all file systems on the machine @samp{albert}
6685 as well as @file{/var} file system on all machines.
6686
6687 By default @code{restore} will start restoring files from the lowest
6688 available dump level (usually zero) and will continue through
6689 all available dump levels. There may be situations where such a
6690 thorough restore is not necessary. For example, you may wish to
6691 restore only files from the recent level one backup. To do so,
6692 use @option{--level} option, as shown in the example below:
6693
6694 @smallexample
6695 restore --level=1
6696 @end smallexample
6697
6698 The full list of options accepted by @code{restore} follows:
6699
6700 @table @option
6701 @item -a
6702 @itemx --all
6703 Restore all file systems and files specified in @file{backup-specs}.
6704
6705 @item -l @var{level}
6706 @itemx --level=@var{level}
6707 Start restoring from the given backup level, instead of the default 0.
6708
6709 @item -v[@var{level}]
6710 @itemx --verbose[=@var{level}]
6711 Set verbosity level. The higher the level is, the more debugging
6712 information will be output during execution. Default @var{level}
6713 is 100, which means the highest debugging level.
6714
6715 @item -h
6716 @itemx --help
6717 Display short help message and exit.
6718
6719 @item -V
6720 @itemx --version
6721 Display information about the program's name, version, origin and legal
6722 status, all on standard output, and then exit successfully.
6723 @end table
6724
6725 You should start the restore script with the media containing the
6726 first volume of the archive mounted. The script will prompt for other
6727 volumes as they are needed. If the archive is on tape, you don't need
6728 to rewind the tape to to its beginning---if the tape head is
6729 positioned past the beginning of the archive, the script will rewind
6730 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6731 positioning.
6732
6733 @quotation
6734 @strong{Warning:} The script will delete files from the active file
6735 system if they were not in the file system when the archive was made.
6736 @end quotation
6737
6738 @xref{Incremental Dumps}, for an explanation of how the script makes
6739 that determination.
6740
6741 @node Choosing
6742 @chapter Choosing Files and Names for @command{tar}
6743
6744 Certain options to @command{tar} enable you to specify a name for your
6745 archive. Other options let you decide which files to include or exclude
6746 from the archive, based on when or whether files were modified, whether
6747 the file names do or don't match specified patterns, or whether files
6748 are in specified directories.
6749
6750 This chapter discusses these options in detail.
6751
6752 @menu
6753 * file:: Choosing the Archive's Name
6754 * Selecting Archive Members::
6755 * files:: Reading Names from a File
6756 * exclude:: Excluding Some Files
6757 * wildcards:: Wildcards Patterns and Matching
6758 * quoting styles:: Ways of Quoting Special Characters in Names
6759 * transform:: Modifying File and Member Names
6760 * after:: Operating Only on New Files
6761 * recurse:: Descending into Directories
6762 * one:: Crossing File System Boundaries
6763 @end menu
6764
6765 @node file
6766 @section Choosing and Naming Archive Files
6767
6768 @cindex Naming an archive
6769 @cindex Archive Name
6770 @cindex Choosing an archive file
6771 @cindex Where is the archive?
6772 @opindex file
6773 By default, @command{tar} uses an archive file name that was compiled when
6774 it was built on the system; usually this name refers to some physical
6775 tape drive on the machine. However, the person who installed @command{tar}
6776 on the system may not have set the default to a meaningful value as far as
6777 most users are concerned. As a result, you will usually want to tell
6778 @command{tar} where to find (or create) the archive. The
6779 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6780 option allows you to either specify or name a file to use as the archive
6781 instead of the default archive file location.
6782
6783 @table @option
6784 @xopindex{file, short description}
6785 @item --file=@var{archive-name}
6786 @itemx -f @var{archive-name}
6787 Name the archive to create or operate on. Use in conjunction with
6788 any operation.
6789 @end table
6790
6791 For example, in this @command{tar} command,
6792
6793 @smallexample
6794 $ @kbd{tar -cvf collection.tar blues folk jazz}
6795 @end smallexample
6796
6797 @noindent
6798 @file{collection.tar} is the name of the archive. It must directly
6799 follow the @option{-f} option, since whatever directly follows @option{-f}
6800 @emph{will} end up naming the archive. If you neglect to specify an
6801 archive name, you may end up overwriting a file in the working directory
6802 with the archive you create since @command{tar} will use this file's name
6803 for the archive name.
6804
6805 An archive can be saved as a file in the file system, sent through a
6806 pipe or over a network, or written to an I/O device such as a tape,
6807 floppy disk, or CD write drive.
6808
6809 @cindex Writing new archives
6810 @cindex Archive creation
6811 If you do not name the archive, @command{tar} uses the value of the
6812 environment variable @env{TAPE} as the file name for the archive. If
6813 that is not available, @command{tar} uses a default, compiled-in archive
6814 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6815
6816 @cindex Standard input and output
6817 @cindex tar to standard input and output
6818 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6819 archive from standard input (when listing or extracting files), or
6820 writes it to standard output (when creating an archive). If you use
6821 @file{-} as an @var{archive-name} when modifying an archive,
6822 @command{tar} reads the original archive from its standard input and
6823 writes the entire new archive to its standard output.
6824
6825 The following example is a convenient way of copying directory
6826 hierarchy from @file{sourcedir} to @file{targetdir}.
6827
6828 @smallexample
6829 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6830 @end smallexample
6831
6832 The @option{-C} option allows to avoid using subshells:
6833
6834 @smallexample
6835 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6836 @end smallexample
6837
6838 In both examples above, the leftmost @command{tar} invocation archives
6839 the contents of @file{sourcedir} to the standard output, while the
6840 rightmost one reads this archive from its standard input and
6841 extracts it. The @option{-p} option tells it to restore permissions
6842 of the extracted files.
6843
6844 @cindex Remote devices
6845 @cindex tar to a remote device
6846 @anchor{remote-dev}
6847 To specify an archive file on a device attached to a remote machine,
6848 use the following:
6849
6850 @smallexample
6851 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6852 @end smallexample
6853
6854 @noindent
6855 @command{tar} will set up the remote connection, if possible, and
6856 prompt you for a username and password. If you use
6857 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6858 will attempt to set up the remote connection using your username
6859 as the username on the remote machine.
6860
6861 @cindex Local and remote archives
6862 @anchor{local and remote archives}
6863 If the archive file name includes a colon (@samp{:}), then it is assumed
6864 to be a file on another machine. If the archive file is
6865 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6866 host @var{host}. The remote host is accessed using the @command{rsh}
6867 program, with a username of @var{user}. If the username is omitted
6868 (along with the @samp{@@} sign), then your user name will be used.
6869 (This is the normal @command{rsh} behavior.) It is necessary for the
6870 remote machine, in addition to permitting your @command{rsh} access, to
6871 have the @file{rmt} program installed (this command is included in
6872 the @GNUTAR{} distribution and by default is installed under
6873 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
6874 installation prefix). If you need to use a file whose name includes a
6875 colon, then the remote tape drive behavior
6876 can be inhibited by using the @option{--force-local} option.
6877
6878 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6879 tries to minimize input and output operations. The Amanda backup
6880 system, when used with @GNUTAR{}, has an initial sizing pass which
6881 uses this feature.
6882
6883 @node Selecting Archive Members
6884 @section Selecting Archive Members
6885 @cindex Specifying files to act on
6886 @cindex Specifying archive members
6887
6888 @dfn{File Name arguments} specify which files in the file system
6889 @command{tar} operates on, when creating or adding to an archive, or which
6890 archive members @command{tar} operates on, when reading or deleting from
6891 an archive. @xref{Operations}.
6892
6893 To specify file names, you can include them as the last arguments on
6894 the command line, as follows:
6895 @smallexample
6896 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6897 @end smallexample
6898
6899 If a file name begins with dash (@samp{-}), precede it with
6900 @option{--add-file} option to prevent it from being treated as an
6901 option.
6902
6903 @anchor{input name quoting}
6904 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6905 name, replacing @dfn{escape sequences} according to the following
6906 table:
6907
6908 @multitable @columnfractions 0.20 0.60
6909 @headitem Escape @tab Replaced with
6910 @item \a @tab Audible bell (@acronym{ASCII} 7)
6911 @item \b @tab Backspace (@acronym{ASCII} 8)
6912 @item \f @tab Form feed (@acronym{ASCII} 12)
6913 @item \n @tab New line (@acronym{ASCII} 10)
6914 @item \r @tab Carriage return (@acronym{ASCII} 13)
6915 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6916 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6917 @item \? @tab @acronym{ASCII} 127
6918 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6919 of up to 3 digits)
6920 @end multitable
6921
6922 A backslash followed by any other symbol is retained.
6923
6924 This default behavior is controlled by the following command line
6925 option:
6926
6927 @table @option
6928 @opindex unquote
6929 @item --unquote
6930 Enable unquoting input file or member names (default).
6931
6932 @opindex no-unquote
6933 @item --no-unquote
6934 Disable unquoting input file or member names.
6935 @end table
6936
6937 If you specify a directory name as a file name argument, all the files
6938 in that directory are operated on by @command{tar}.
6939
6940 If you do not specify files, @command{tar} behavior differs depending
6941 on the operation mode as described below:
6942
6943 When @command{tar} is invoked with @option{--create} (@option{-c}),
6944 @command{tar} will stop immediately, reporting the following:
6945
6946 @smallexample
6947 @group
6948 $ @kbd{tar cf a.tar}
6949 tar: Cowardly refusing to create an empty archive
6950 Try 'tar --help' or 'tar --usage' for more information.
6951 @end group
6952 @end smallexample
6953
6954 If you specify either @option{--list} (@option{-t}) or
6955 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6956 operates on all the archive members in the archive.
6957
6958 If run with @option{--diff} option, tar will compare the archive with
6959 the contents of the current working directory.
6960
6961 If you specify any other operation, @command{tar} does nothing.
6962
6963 By default, @command{tar} takes file names from the command line. However,
6964 there are other ways to specify file or member names, or to modify the
6965 manner in which @command{tar} selects the files or members upon which to
6966 operate. In general, these methods work both for specifying the names
6967 of files and archive members.
6968
6969 @node files
6970 @section Reading Names from a File
6971
6972 @cindex Reading file names from a file
6973 @cindex Lists of file names
6974 @cindex File Name arguments, alternatives
6975 @cindex @command{find}, using with @command{tar}
6976 Instead of giving the names of files or archive members on the command
6977 line, you can put the names into a file, and then use the
6978 @option{--files-from=@var{file-of-names}} (@option{-T
6979 @var{file-of-names}}) option to @command{tar}. Give the name of the
6980 file which contains the list of files to include as the argument to
6981 @option{--files-from}. In the list, the file names should be separated by
6982 newlines. You will frequently use this option when you have generated
6983 the list of files to archive with the @command{find} utility.
6984
6985 @table @option
6986 @opindex files-from
6987 @item --files-from=@var{file-name}
6988 @itemx -T @var{file-name}
6989 Get names to extract or create from file @var{file-name}.
6990 @end table
6991
6992 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6993 you specify either @code{--files-from=-} or @code{-T -}), then the file
6994 names are read from standard input.
6995
6996 Unless you are running @command{tar} with @option{--create}, you can not use
6997 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6998 command.
6999
7000 Any number of @option{-T} options can be given in the command line.
7001
7002 The following example shows how to use @command{find} to generate a list of
7003 files smaller than 400K in length and put that list into a file
7004 called @file{small-files}. You can then use the @option{-T} option to
7005 @command{tar} to specify the files from that file, @file{small-files}, to
7006 create the archive @file{little.tgz}. (The @option{-z} option to
7007 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7008 more information.)
7009
7010 @smallexample
7011 $ @kbd{find . -size -400 -print > small-files}
7012 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7013 @end smallexample
7014
7015 @noindent
7016 In the file list given by @option{-T} option, any file name beginning
7017 with @samp{-} character is considered a @command{tar} option and is
7018 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7019 recognized only @option{-C} option in file lists, and only if the
7020 option and its argument occupied two consecutive lines.}. For example,
7021 the common use of this feature is to change to another directory by
7022 specifying @option{-C} option:
7023
7024 @smallexample
7025 @group
7026 $ @kbd{cat list}
7027 -C/etc
7028 passwd
7029 hosts
7030 -C/lib
7031 libc.a
7032 $ @kbd{tar -c -f foo.tar --files-from list}
7033 @end group
7034 @end smallexample
7035
7036 @noindent
7037 In this example, @command{tar} will first switch to @file{/etc}
7038 directory and add files @file{passwd} and @file{hosts} to the
7039 archive. Then it will change to @file{/lib} directory and will archive
7040 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
7041 contain:
7042
7043 @smallexample
7044 @group
7045 $ @kbd{tar tf foo.tar}
7046 passwd
7047 hosts
7048 libc.a
7049 @end group
7050 @end smallexample
7051
7052 @noindent
7053 @xopindex{directory, using in @option{--files-from} argument}
7054 Notice that the option parsing algorithm used with @option{-T} is
7055 stricter than the one used by shell. Namely, when specifying option
7056 arguments, you should observe the following rules:
7057
7058 @itemize @bullet
7059 @item
7060 When using short (single-letter) option form, its argument must
7061 immediately follow the option letter, without any intervening
7062 whitespace. For example: @code{-Cdir}.
7063
7064 @item
7065 When using long option form, the option argument must be separated
7066 from the option by a single equal sign. No whitespace is allowed on
7067 any side of the equal sign. For example: @code{--directory=dir}.
7068
7069 @item
7070 For both short and long option forms, the option argument can be given
7071 on the next line after the option name, e.g.:
7072
7073 @smallexample
7074 @group
7075 --directory
7076 dir
7077 @end group
7078 @end smallexample
7079
7080 @noindent
7081 and
7082
7083 @smallexample
7084 @group
7085 -C
7086 dir
7087 @end group
7088 @end smallexample
7089 @end itemize
7090
7091 @opindex add-file
7092 If you happen to have a file whose name starts with @samp{-},
7093 precede it with @option{--add-file} option to prevent it from
7094 being recognized as an option. For example: @code{--add-file=--my-file}.
7095
7096 @menu
7097 * nul::
7098 @end menu
7099
7100 @node nul
7101 @subsection @code{NUL}-Terminated File Names
7102
7103 @cindex File names, terminated by @code{NUL}
7104 @cindex @code{NUL}-terminated file names
7105 The @option{--null} option causes
7106 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7107 to read file names terminated by a @code{NUL} instead of a newline, so
7108 files whose names contain newlines can be archived using
7109 @option{--files-from}.
7110
7111 @table @option
7112 @xopindex{null, described}
7113 @item --null
7114 Only consider @code{NUL}-terminated file names, instead of files that
7115 terminate in a newline.
7116
7117 @xopindex{no-null, described}
7118 @item --no-null
7119 Undo the effect of any previous @option{--null} option.
7120 @end table
7121
7122 The @option{--null} option is just like the one in @acronym{GNU}
7123 @command{xargs} and @command{cpio}, and is useful with the
7124 @option{-print0} predicate of @acronym{GNU} @command{find}. In
7125 @command{tar}, @option{--null} also disables special handling for
7126 file names that begin with dash.
7127
7128 This example shows how to use @command{find} to generate a list of files
7129 larger than 800K in length and put that list into a file called
7130 @file{long-files}. The @option{-print0} option to @command{find} is just
7131 like @option{-print}, except that it separates files with a @code{NUL}
7132 rather than with a newline. You can then run @command{tar} with both the
7133 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7134 files from that file, @file{long-files}, to create the archive
7135 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
7136 @command{tar} to recognize the @code{NUL} separator between files.
7137
7138 @smallexample
7139 $ @kbd{find . -size +800 -print0 > long-files}
7140 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7141 @end smallexample
7142
7143 The @option{--no-null} option can be used if you need to read both
7144 @code{NUL}-terminated and newline-terminated files on the same command line.
7145 For example, if @file{flist} is a newline-terminated file, then the
7146 following command can be used to combine it with the above command:
7147
7148 @smallexample
7149 @group
7150 $ @kbd{find . -size +800 -print0 |
7151 tar -c -f big.tar --null -T - --no-null -T flist}
7152 @end group
7153 @end smallexample
7154
7155 This example uses short options for typographic reasons, to avoid
7156 very long lines.
7157
7158 @GNUTAR is able to automatically detect @code{NUL}-terminated file lists, so
7159 it is safe to use them even without the @option{--null} option. In
7160 this case @command{tar} will print a warning and continue reading such
7161 a file as if @option{--null} were actually given:
7162
7163 @smallexample
7164 @group
7165 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7166 tar: -: file name read contains nul character
7167 @end group
7168 @end smallexample
7169
7170 The null terminator, however, remains in effect only for this
7171 particular file, any following @option{-T} options will assume
7172 newline termination. Of course, the null autodetection applies
7173 to these eventual surplus @option{-T} options as well.
7174
7175 @node exclude
7176 @section Excluding Some Files
7177
7178 @cindex File names, excluding files by
7179 @cindex Excluding files by name and pattern
7180 @cindex Excluding files by file system
7181 @opindex exclude
7182 @opindex exclude-from
7183 To avoid operating on files whose names match a particular pattern,
7184 use the @option{--exclude} or @option{--exclude-from} options.
7185
7186 @table @option
7187 @opindex exclude
7188 @item --exclude=@var{pattern}
7189 Causes @command{tar} to ignore files that match the @var{pattern}.
7190 @end table
7191
7192 @findex exclude
7193 The @option{--exclude=@var{pattern}} option prevents any file or
7194 member whose name matches the shell wildcard (@var{pattern}) from
7195 being operated on.
7196 For example, to create an archive with all the contents of the directory
7197 @file{src} except for files whose names end in @file{.o}, use the
7198 command @samp{tar -cf src.tar --exclude='*.o' src}.
7199
7200 You may give multiple @option{--exclude} options.
7201
7202 @table @option
7203 @opindex exclude-from
7204 @item --exclude-from=@var{file}
7205 @itemx -X @var{file}
7206 Causes @command{tar} to ignore files that match the patterns listed in
7207 @var{file}.
7208 @end table
7209
7210 @findex exclude-from
7211 Use the @option{--exclude-from} option to read a
7212 list of patterns, one per line, from @var{file}; @command{tar} will
7213 ignore files matching those patterns. Thus if @command{tar} is
7214 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7215 single line @file{*.o}, no files whose names end in @file{.o} will be
7216 added to the archive.
7217
7218 Notice, that lines from @var{file} are read verbatim. One of the
7219 frequent errors is leaving some extra whitespace after a file name,
7220 which is difficult to catch using text editors.
7221
7222 However, empty lines are OK.
7223
7224 @table @option
7225 @cindex version control system, excluding files
7226 @cindex VCS, excluding files
7227 @cindex SCCS, excluding files
7228 @cindex RCS, excluding files
7229 @cindex CVS, excluding files
7230 @cindex SVN, excluding files
7231 @cindex git, excluding files
7232 @cindex Bazaar, excluding files
7233 @cindex Arch, excluding files
7234 @cindex Mercurial, excluding files
7235 @cindex Darcs, excluding files
7236 @opindex exclude-vcs
7237 @item --exclude-vcs
7238 Exclude files and directories used by following version control
7239 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
7240 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
7241
7242 As of version @value{VERSION}, the following files are excluded:
7243
7244 @itemize @bullet
7245 @item @file{CVS/}, and everything under it
7246 @item @file{RCS/}, and everything under it
7247 @item @file{SCCS/}, and everything under it
7248 @item @file{.git/}, and everything under it
7249 @item @file{.gitignore}
7250 @item @file{.cvsignore}
7251 @item @file{.svn/}, and everything under it
7252 @item @file{.arch-ids/}, and everything under it
7253 @item @file{@{arch@}/}, and everything under it
7254 @item @file{=RELEASE-ID}
7255 @item @file{=meta-update}
7256 @item @file{=update}
7257 @item @file{.bzr}
7258 @item @file{.bzrignore}
7259 @item @file{.bzrtags}
7260 @item @file{.hg}
7261 @item @file{.hgignore}
7262 @item @file{.hgrags}
7263 @item @file{_darcs}
7264 @end itemize
7265
7266 @opindex exclude-backups
7267 @item --exclude-backups
7268 Exclude backup and lock files. This option causes exclusion of files
7269 that match the following shell globbing patterns:
7270
7271 @table @asis
7272 @item .#*
7273 @item *~
7274 @item #*#
7275 @end table
7276
7277 @end table
7278
7279 @findex exclude-caches
7280 When creating an archive, the @option{--exclude-caches} option family
7281 causes @command{tar} to exclude all directories that contain a @dfn{cache
7282 directory tag}. A cache directory tag is a short file with the
7283 well-known name @file{CACHEDIR.TAG} and having a standard header
7284 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
7285 Various applications write cache directory tags into directories they
7286 use to hold regenerable, non-precious data, so that such data can be
7287 more easily excluded from backups.
7288
7289 There are three @samp{exclude-caches} options, each providing a different
7290 exclusion semantics:
7291
7292 @table @option
7293 @opindex exclude-caches
7294 @item --exclude-caches
7295 Do not archive the contents of the directory, but archive the
7296 directory itself and the @file{CACHEDIR.TAG} file.
7297
7298 @opindex exclude-caches-under
7299 @item --exclude-caches-under
7300 Do not archive the contents of the directory, nor the
7301 @file{CACHEDIR.TAG} file, archive only the directory itself.
7302
7303 @opindex exclude-caches-all
7304 @item --exclude-caches-all
7305 Omit directories containing @file{CACHEDIR.TAG} file entirely.
7306 @end table
7307
7308 @findex exclude-tag
7309 Another option family, @option{--exclude-tag}, provides a generalization of
7310 this concept. It takes a single argument, a file name to look for.
7311 Any directory that contains this file will be excluded from the dump.
7312 Similarly to @samp{exclude-caches}, there are three options in this
7313 option family:
7314
7315 @table @option
7316 @opindex exclude-tag
7317 @item --exclude-tag=@var{file}
7318 Do not dump the contents of the directory, but dump the
7319 directory itself and the @var{file}.
7320
7321 @opindex exclude-tag-under
7322 @item --exclude-tag-under=@var{file}
7323 Do not dump the contents of the directory, nor the
7324 @var{file}, archive only the directory itself.
7325
7326 @opindex exclude-tag-all
7327 @item --exclude-tag-all=@var{file}
7328 Omit directories containing @var{file} file entirely.
7329 @end table
7330
7331 Multiple @option{--exclude-tag*} options can be given.
7332
7333 For example, given this directory:
7334
7335 @smallexample
7336 @group
7337 $ @kbd{find dir}
7338 dir
7339 dir/blues
7340 dir/jazz
7341 dir/folk
7342 dir/folk/tagfile
7343 dir/folk/sanjuan
7344 dir/folk/trote
7345 @end group
7346 @end smallexample
7347
7348 The @option{--exclude-tag} will produce the following:
7349
7350 @smallexample
7351 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
7352 dir/
7353 dir/blues
7354 dir/jazz
7355 dir/folk/
7356 tar: dir/folk/: contains a cache directory tag tagfile;
7357 contents not dumped
7358 dir/folk/tagfile
7359 @end smallexample
7360
7361 Both the @file{dir/folk} directory and its tagfile are preserved in
7362 the archive, however the rest of files in this directory are not.
7363
7364 Now, using the @option{--exclude-tag-under} option will exclude
7365 @file{tagfile} from the dump, while still preserving the directory
7366 itself, as shown in this example:
7367
7368 @smallexample
7369 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
7370 dir/
7371 dir/blues
7372 dir/jazz
7373 dir/folk/
7374 ./tar: dir/folk/: contains a cache directory tag tagfile;
7375 contents not dumped
7376 @end smallexample
7377
7378 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
7379 directory entirely:
7380
7381 @smallexample
7382 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
7383 dir/
7384 dir/blues
7385 dir/jazz
7386 ./tar: dir/folk/: contains a cache directory tag tagfile;
7387 directory not dumped
7388 @end smallexample
7389
7390 @menu
7391 * problems with exclude::
7392 @end menu
7393
7394 @node problems with exclude
7395 @unnumberedsubsec Problems with Using the @code{exclude} Options
7396
7397 @xopindex{exclude, potential problems with}
7398 Some users find @samp{exclude} options confusing. Here are some common
7399 pitfalls:
7400
7401 @itemize @bullet
7402 @item
7403 The main operating mode of @command{tar} does not act on a file name
7404 explicitly listed on the command line, if one of its file name
7405 components is excluded. In the example above, if
7406 you create an archive and exclude files that end with @samp{*.o}, but
7407 explicitly name the file @samp{dir.o/foo} after all the options have been
7408 listed, @samp{dir.o/foo} will be excluded from the archive.
7409
7410 @item
7411 You can sometimes confuse the meanings of @option{--exclude} and
7412 @option{--exclude-from}. Be careful: use @option{--exclude} when files
7413 to be excluded are given as a pattern on the command line. Use
7414 @option{--exclude-from} to introduce the name of a file which contains
7415 a list of patterns, one per line; each of these patterns can exclude
7416 zero, one, or many files.
7417
7418 @item
7419 When you use @option{--exclude=@var{pattern}}, be sure to quote the
7420 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
7421 like @samp{*}. If you do not do this, the shell might expand the
7422 @samp{*} itself using files at hand, so @command{tar} might receive a
7423 list of files instead of one pattern, or none at all, making the
7424 command somewhat illegal. This might not correspond to what you want.
7425
7426 For example, write:
7427
7428 @smallexample
7429 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
7430 @end smallexample
7431
7432 @noindent
7433 rather than:
7434
7435 @smallexample
7436 # @emph{Wrong!}
7437 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
7438 @end smallexample
7439
7440 @item
7441 You must use use shell syntax, or globbing, rather than @code{regexp}
7442 syntax, when using exclude options in @command{tar}. If you try to use
7443 @code{regexp} syntax to describe files to be excluded, your command
7444 might fail.
7445
7446 @item
7447 @FIXME{The change in semantics must have occurred before 1.11,
7448 so I doubt if it is worth mentioning at all. Anyway, should at
7449 least specify in which version the semantics changed.}
7450 In earlier versions of @command{tar}, what is now the
7451 @option{--exclude-from} option was called @option{--exclude} instead.
7452 Now, @option{--exclude} applies to patterns listed on the command
7453 line and @option{--exclude-from} applies to patterns listed in a
7454 file.
7455
7456 @end itemize
7457
7458 @node wildcards
7459 @section Wildcards Patterns and Matching
7460
7461 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
7462 @samp{*} or @samp{?} for example, are replaced and expanded into all
7463 existing files matching the given pattern. @GNUTAR{} can use wildcard
7464 patterns for matching (or globbing) archive members when extracting
7465 from or listing an archive. Wildcard patterns are also used for
7466 verifying volume labels of @command{tar} archives. This section has the
7467 purpose of explaining wildcard syntax for @command{tar}.
7468
7469 @FIXME{the next few paragraphs need work.}
7470
7471 A @var{pattern} should be written according to shell syntax, using wildcard
7472 characters to effect globbing. Most characters in the pattern stand
7473 for themselves in the matched string, and case is significant: @samp{a}
7474 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7475 pattern matches any single character in the matched string. The character
7476 @samp{*} in the pattern matches zero, one, or more single characters in
7477 the matched string. The character @samp{\} says to take the following
7478 character of the pattern @emph{literally}; it is useful when one needs to
7479 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7480
7481 The character @samp{[}, up to the matching @samp{]}, introduces a character
7482 class. A @dfn{character class} is a list of acceptable characters
7483 for the next single character of the matched string. For example,
7484 @samp{[abcde]} would match any of the first five letters of the alphabet.
7485 Note that within a character class, all of the ``special characters''
7486 listed above other than @samp{\} lose their special meaning; for example,
7487 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7488 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7489 the characters @samp{-} and @samp{]} must either come @emph{first} or
7490 @emph{last} in a character class.)
7491
7492 @cindex Excluding characters from a character class
7493 @cindex Character class, excluding characters from
7494 If the first character of the class after the opening @samp{[}
7495 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7496 Rather than listing character to match, it lists those characters which
7497 are @emph{forbidden} as the next single character of the matched string.
7498
7499 Other characters of the class stand for themselves. The special
7500 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7501 letters, is meant to represent all characters between @var{a} and
7502 @var{e}, inclusive.
7503
7504 @FIXME{need to add a sentence or so here to make this clear for those
7505 who don't have dan around.}
7506
7507 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7508 special for wildcard matches. However, if a pattern completely matches
7509 a directory prefix of a matched string, then it matches the full matched
7510 string: thus, excluding a directory also excludes all the files beneath it.
7511
7512 @menu
7513 * controlling pattern-matching::
7514 @end menu
7515
7516 @node controlling pattern-matching
7517 @unnumberedsubsec Controlling Pattern-Matching
7518
7519 For the purposes of this section, we call @dfn{exclusion members} all
7520 member names obtained while processing @option{--exclude} and
7521 @option{--exclude-from} options, and @dfn{inclusion members} those
7522 member names that were given in the command line or read from the file
7523 specified with @option{--files-from} option.
7524
7525 These two pairs of member lists are used in the following operations:
7526 @option{--diff}, @option{--extract}, @option{--list},
7527 @option{--update}.
7528
7529 There are no inclusion members in create mode (@option{--create} and
7530 @option{--append}), since in this mode the names obtained from the
7531 command line refer to @emph{files}, not archive members.
7532
7533 By default, inclusion members are compared with archive members
7534 literally @footnote{Notice that earlier @GNUTAR{} versions used
7535 globbing for inclusion members, which contradicted to UNIX98
7536 specification and was not documented. @xref{Changes}, for more
7537 information on this and other changes.} and exclusion members are
7538 treated as globbing patterns. For example:
7539
7540 @smallexample
7541 @group
7542 $ @kbd{tar tf foo.tar}
7543 a.c
7544 b.c
7545 a.txt
7546 [remarks]
7547 # @i{Member names are used verbatim:}
7548 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7549 [remarks]
7550 # @i{Exclude member names are globbed:}
7551 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7552 a.txt
7553 [remarks]
7554 @end group
7555 @end smallexample
7556
7557 This behavior can be altered by using the following options:
7558
7559 @table @option
7560 @opindex wildcards
7561 @item --wildcards
7562 Treat all member names as wildcards.
7563
7564 @opindex no-wildcards
7565 @item --no-wildcards
7566 Treat all member names as literal strings.
7567 @end table
7568
7569 Thus, to extract files whose names end in @samp{.c}, you can use:
7570
7571 @smallexample
7572 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7573 a.c
7574 b.c
7575 @end smallexample
7576
7577 @noindent
7578 Notice quoting of the pattern to prevent the shell from interpreting
7579 it.
7580
7581 The effect of @option{--wildcards} option is canceled by
7582 @option{--no-wildcards}. This can be used to pass part of
7583 the command line arguments verbatim and other part as globbing
7584 patterns. For example, the following invocation:
7585
7586 @smallexample
7587 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7588 @end smallexample
7589
7590 @noindent
7591 instructs @command{tar} to extract from @file{foo.tar} all files whose
7592 names end in @samp{.txt} and the file named @file{[remarks]}.
7593
7594 Normally, a pattern matches a name if an initial subsequence of the
7595 name's components matches the pattern, where @samp{*}, @samp{?}, and
7596 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7597 and wildcards can match @samp{/}.
7598
7599 Other than optionally stripping leading @samp{/} from names
7600 (@pxref{absolute}), patterns and names are used as-is. For
7601 example, trailing @samp{/} is not trimmed from a user-specified name
7602 before deciding whether to exclude it.
7603
7604 However, this matching procedure can be altered by the options listed
7605 below. These options accumulate. For example:
7606
7607 @smallexample
7608 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7609 @end smallexample
7610
7611 @noindent
7612 ignores case when excluding @samp{makefile}, but not when excluding
7613 @samp{readme}.
7614
7615 @table @option
7616 @opindex anchored
7617 @opindex no-anchored
7618 @item --anchored
7619 @itemx --no-anchored
7620 If anchored, a pattern must match an initial subsequence
7621 of the name's components. Otherwise, the pattern can match any
7622 subsequence. Default is @option{--no-anchored} for exclusion members
7623 and @option{--anchored} inclusion members.
7624
7625 @opindex ignore-case
7626 @opindex no-ignore-case
7627 @item --ignore-case
7628 @itemx --no-ignore-case
7629 When ignoring case, upper-case patterns match lower-case names and vice versa.
7630 When not ignoring case (the default), matching is case-sensitive.
7631
7632 @opindex wildcards-match-slash
7633 @opindex no-wildcards-match-slash
7634 @item --wildcards-match-slash
7635 @itemx --no-wildcards-match-slash
7636 When wildcards match slash (the default for exclusion members), a
7637 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7638 name. Otherwise, @samp{/} is matched only by @samp{/}.
7639
7640 @end table
7641
7642 The @option{--recursion} and @option{--no-recursion} options
7643 (@pxref{recurse}) also affect how member patterns are interpreted. If
7644 recursion is in effect, a pattern matches a name if it matches any of
7645 the name's parent directories.
7646
7647 The following table summarizes pattern-matching default values:
7648
7649 @multitable @columnfractions .3 .7
7650 @headitem Members @tab Default settings
7651 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7652 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7653 @end multitable
7654
7655 @node quoting styles
7656 @section Quoting Member Names
7657
7658 When displaying member names, @command{tar} takes care to avoid
7659 ambiguities caused by certain characters. This is called @dfn{name
7660 quoting}. The characters in question are:
7661
7662 @itemize @bullet
7663 @item Non-printable control characters:
7664 @anchor{escape sequences}
7665 @multitable @columnfractions 0.20 0.10 0.60
7666 @headitem Character @tab @acronym{ASCII} @tab Character name
7667 @item \a @tab 7 @tab Audible bell
7668 @item \b @tab 8 @tab Backspace
7669 @item \f @tab 12 @tab Form feed
7670 @item \n @tab 10 @tab New line
7671 @item \r @tab 13 @tab Carriage return
7672 @item \t @tab 9 @tab Horizontal tabulation
7673 @item \v @tab 11 @tab Vertical tabulation
7674 @end multitable
7675
7676 @item Space (@acronym{ASCII} 32)
7677
7678 @item Single and double quotes (@samp{'} and @samp{"})
7679
7680 @item Backslash (@samp{\})
7681 @end itemize
7682
7683 The exact way @command{tar} uses to quote these characters depends on
7684 the @dfn{quoting style}. The default quoting style, called
7685 @dfn{escape} (see below), uses backslash notation to represent control
7686 characters, space and backslash. Using this quoting style, control
7687 characters are represented as listed in column @samp{Character} in the
7688 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7689
7690 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7691 using @option{--quoting-style} option:
7692
7693 @table @option
7694 @item --quoting-style=@var{style}
7695 @opindex quoting-style
7696
7697 Sets quoting style. Valid values for @var{style} argument are:
7698 literal, shell, shell-always, c, escape, locale, clocale.
7699 @end table
7700
7701 These styles are described in detail below. To illustrate their
7702 effect, we will use an imaginary tar archive @file{arch.tar}
7703 containing the following members:
7704
7705 @smallexample
7706 @group
7707 # 1. Contains horizontal tabulation character.
7708 a tab
7709 # 2. Contains newline character
7710 a
7711 newline
7712 # 3. Contains a space
7713 a space
7714 # 4. Contains double quotes
7715 a"double"quote
7716 # 5. Contains single quotes
7717 a'single'quote
7718 # 6. Contains a backslash character:
7719 a\backslash
7720 @end group
7721 @end smallexample
7722
7723 Here is how usual @command{ls} command would have listed them, if they
7724 had existed in the current working directory:
7725
7726 @smallexample
7727 @group
7728 $ @kbd{ls}
7729 a\ttab
7730 a\nnewline
7731 a\ space
7732 a"double"quote
7733 a'single'quote
7734 a\\backslash
7735 @end group
7736 @end smallexample
7737
7738 Quoting styles:
7739
7740 @table @samp
7741 @item literal
7742 No quoting, display each character as is:
7743
7744 @smallexample
7745 @group
7746 $ @kbd{tar tf arch.tar --quoting-style=literal}
7747 ./
7748 ./a space
7749 ./a'single'quote
7750 ./a"double"quote
7751 ./a\backslash
7752 ./a tab
7753 ./a
7754 newline
7755 @end group
7756 @end smallexample
7757
7758 @item shell
7759 Display characters the same way Bourne shell does:
7760 control characters, except @samp{\t} and @samp{\n}, are printed using
7761 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7762 single quote is printed as @samp{\'}. If a name contains any quoted
7763 characters, it is enclosed in single quotes. In particular, if a name
7764 contains single quotes, it is printed as several single-quoted strings:
7765
7766 @smallexample
7767 @group
7768 $ @kbd{tar tf arch.tar --quoting-style=shell}
7769 ./
7770 './a space'
7771 './a'\''single'\''quote'
7772 './a"double"quote'
7773 './a\backslash'
7774 './a tab'
7775 './a
7776 newline'
7777 @end group
7778 @end smallexample
7779
7780 @item shell-always
7781 Same as @samp{shell}, but the names are always enclosed in single
7782 quotes:
7783
7784 @smallexample
7785 @group
7786 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7787 './'
7788 './a space'
7789 './a'\''single'\''quote'
7790 './a"double"quote'
7791 './a\backslash'
7792 './a tab'
7793 './a
7794 newline'
7795 @end group
7796 @end smallexample
7797
7798 @item c
7799 Use the notation of the C programming language. All names are
7800 enclosed in double quotes. Control characters are quoted using
7801 backslash notations, double quotes are represented as @samp{\"},
7802 backslash characters are represented as @samp{\\}. Single quotes and
7803 spaces are not quoted:
7804
7805 @smallexample
7806 @group
7807 $ @kbd{tar tf arch.tar --quoting-style=c}
7808 "./"
7809 "./a space"
7810 "./a'single'quote"
7811 "./a\"double\"quote"
7812 "./a\\backslash"
7813 "./a\ttab"
7814 "./a\nnewline"
7815 @end group
7816 @end smallexample
7817
7818 @item escape
7819 Control characters are printed using backslash notation, a space is
7820 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7821 default quoting style, unless it was changed when configured the
7822 package.
7823
7824 @smallexample
7825 @group
7826 $ @kbd{tar tf arch.tar --quoting-style=escape}
7827 ./
7828 ./a space
7829 ./a'single'quote
7830 ./a"double"quote
7831 ./a\\backslash
7832 ./a\ttab
7833 ./a\nnewline
7834 @end group
7835 @end smallexample
7836
7837 @item locale
7838 Control characters, single quote and backslash are printed using
7839 backslash notation. All names are quoted using left and right
7840 quotation marks, appropriate to the current locale. If it does not
7841 define quotation marks, use @samp{'} as left and as right
7842 quotation marks. Any occurrences of the right quotation mark in a
7843 name are escaped with @samp{\}, for example:
7844
7845 For example:
7846
7847 @smallexample
7848 @group
7849 $ @kbd{tar tf arch.tar --quoting-style=locale}
7850 './'
7851 './a space'
7852 './a\'single\'quote'
7853 './a"double"quote'
7854 './a\\backslash'
7855 './a\ttab'
7856 './a\nnewline'
7857 @end group
7858 @end smallexample
7859
7860 @item clocale
7861 Same as @samp{locale}, but @samp{"} is used for both left and right
7862 quotation marks, if not provided by the currently selected locale:
7863
7864 @smallexample
7865 @group
7866 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7867 "./"
7868 "./a space"
7869 "./a'single'quote"
7870 "./a\"double\"quote"
7871 "./a\\backslash"
7872 "./a\ttab"
7873 "./a\nnewline"
7874 @end group
7875 @end smallexample
7876 @end table
7877
7878 You can specify which characters should be quoted in addition to those
7879 implied by the current quoting style:
7880
7881 @table @option
7882 @item --quote-chars=@var{string}
7883 Always quote characters from @var{string}, even if the selected
7884 quoting style would not quote them.
7885 @end table
7886
7887 For example, using @samp{escape} quoting (compare with the usual
7888 escape listing above):
7889
7890 @smallexample
7891 @group
7892 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7893 ./
7894 ./a\ space
7895 ./a'single'quote
7896 ./a\"double\"quote
7897 ./a\\backslash
7898 ./a\ttab
7899 ./a\nnewline
7900 @end group
7901 @end smallexample
7902
7903 To disable quoting of such additional characters, use the following
7904 option:
7905
7906 @table @option
7907 @item --no-quote-chars=@var{string}
7908 Remove characters listed in @var{string} from the list of quoted
7909 characters set by the previous @option{--quote-chars} option.
7910 @end table
7911
7912 This option is particularly useful if you have added
7913 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7914 and wish to disable it for the current invocation.
7915
7916 Note, that @option{--no-quote-chars} does @emph{not} disable those
7917 characters that are quoted by default in the selected quoting style.
7918
7919 @node transform
7920 @section Modifying File and Member Names
7921
7922 @command{Tar} archives contain detailed information about files stored
7923 in them and full file names are part of that information. When
7924 storing a file to an archive, its file name is recorded in it,
7925 along with the actual file contents. When restoring from an archive,
7926 a file is created on disk with exactly the same name as that stored
7927 in the archive. In the majority of cases this is the desired behavior
7928 of a file archiver. However, there are some cases when it is not.
7929
7930 First of all, it is often unsafe to extract archive members with
7931 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7932 takes special precautions when extracting such names and provides a
7933 special option for handling them, which is described in
7934 @ref{absolute}.
7935
7936 Secondly, you may wish to extract file names without some leading
7937 directory components, or with otherwise modified names. In other
7938 cases it is desirable to store files under differing names in the
7939 archive.
7940
7941 @GNUTAR{} provides several options for these needs.
7942
7943 @table @option
7944 @opindex strip-components
7945 @item --strip-components=@var{number}
7946 Strip given @var{number} of leading components from file names before
7947 extraction.
7948 @end table
7949
7950 For example, suppose you have archived whole @file{/usr} hierarchy to
7951 a tar archive named @file{usr.tar}. Among other files, this archive
7952 contains @file{usr/include/stdlib.h}, which you wish to extract to
7953 the current working directory. To do so, you type:
7954
7955 @smallexample
7956 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7957 @end smallexample
7958
7959 The option @option{--strip=2} instructs @command{tar} to strip the
7960 two leading components (@file{usr/} and @file{include/}) off the file
7961 name.
7962
7963 If you add the @option{--verbose} (@option{-v}) option to the invocation
7964 above, you will note that the verbose listing still contains the
7965 full file name, with the two removed components still in place. This
7966 can be inconvenient, so @command{tar} provides a special option for
7967 altering this behavior:
7968
7969 @anchor{show-transformed-names}
7970 @table @option
7971 @opindex show-transformed-names
7972 @item --show-transformed-names
7973 Display file or member names with all requested transformations
7974 applied.
7975 @end table
7976
7977 @noindent
7978 For example:
7979
7980 @smallexample
7981 @group
7982 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7983 usr/include/stdlib.h
7984 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7985 stdlib.h
7986 @end group
7987 @end smallexample
7988
7989 Notice that in both cases the file @file{stdlib.h} is extracted to the
7990 current working directory, @option{--show-transformed-names} affects
7991 only the way its name is displayed.
7992
7993 This option is especially useful for verifying whether the invocation
7994 will have the desired effect. Thus, before running
7995
7996 @smallexample
7997 $ @kbd{tar -x --strip=@var{n}}
7998 @end smallexample
7999
8000 @noindent
8001 it is often advisable to run
8002
8003 @smallexample
8004 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8005 @end smallexample
8006
8007 @noindent
8008 to make sure the command will produce the intended results.
8009
8010 In case you need to apply more complex modifications to the file name,
8011 @GNUTAR{} provides a general-purpose transformation option:
8012
8013 @table @option
8014 @opindex transform
8015 @opindex xform
8016 @item --transform=@var{expression}
8017 @itemx --xform=@var{expression}
8018 Modify file names using supplied @var{expression}.
8019 @end table
8020
8021 @noindent
8022 The @var{expression} is a @command{sed}-like replace expression of the
8023 form:
8024
8025 @smallexample
8026 s/@var{regexp}/@var{replace}/[@var{flags}]
8027 @end smallexample
8028
8029 @noindent
8030 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8031 replacement for each file name part that matches @var{regexp}. Both
8032 @var{regexp} and @var{replace} are described in detail in
8033 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8034
8035 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8036 that it be used consistently throughout the expression. For example,
8037 the following two expressions are equivalent:
8038
8039 @smallexample
8040 @group
8041 s/one/two/
8042 s,one,two,
8043 @end group
8044 @end smallexample
8045
8046 Changing delimiters is often useful when the @var{regex} contains
8047 slashes. For example, it is more convenient to write @code{s,/,-,} than
8048 @code{s/\//-/}.
8049
8050 As in @command{sed}, you can give several replace expressions,
8051 separated by a semicolon.
8052
8053 Supported @var{flags} are:
8054
8055 @table @samp
8056 @item g
8057 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8058 just the first.
8059
8060 @item i
8061 Use case-insensitive matching.
8062
8063 @item x
8064 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8065 regexps, Extended regular expressions, Extended regular expressions,
8066 sed, GNU sed}).
8067
8068 @item @var{number}
8069 Only replace the @var{number}th match of the @var{regexp}.
8070
8071 Note: the @acronym{POSIX} standard does not specify what should happen
8072 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
8073 follows the GNU @command{sed} implementation in this regard, so
8074 the interaction is defined to be: ignore matches before the
8075 @var{number}th, and then match and replace all matches from the
8076 @var{number}th on.
8077
8078 @end table
8079
8080 In addition, several @dfn{transformation scope} flags are supported,
8081 that control to what files transformations apply. These are:
8082
8083 @table @samp
8084 @item r
8085 Apply transformation to regular archive members.
8086
8087 @item R
8088 Do not apply transformation to regular archive members.
8089
8090 @item s
8091 Apply transformation to symbolic link targets.
8092
8093 @item S
8094 Do not apply transformation to symbolic link targets.
8095
8096 @item h
8097 Apply transformation to hard link targets.
8098
8099 @item H
8100 Do not apply transformation to hard link targets.
8101 @end table
8102
8103 Default is @samp{rsh}, which means to apply tranformations to both archive
8104 members and targets of symbolic and hard links.
8105
8106 Default scope flags can also be changed using @samp{flags=} statement
8107 in the transform expression. The flags set this way remain in force
8108 until next @samp{flags=} statement or end of expression, whichever
8109 occurs first. For example:
8110
8111 @smallexample
8112 --transform 'flags=S;s|^|/usr/local/|'
8113 @end smallexample
8114
8115 Here are several examples of @option{--transform} usage:
8116
8117 @enumerate
8118 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8119
8120 @smallexample
8121 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8122 @end smallexample
8123
8124 @item Strip two leading directory components (equivalent to
8125 @option{--strip-components=2}):
8126
8127 @smallexample
8128 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8129 @end smallexample
8130
8131 @item Convert each file name to lower case:
8132
8133 @smallexample
8134 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8135 @end smallexample
8136
8137 @item Prepend @file{/prefix/} to each file name:
8138
8139 @smallexample
8140 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8141 @end smallexample
8142
8143 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8144 to each archive member:
8145
8146 @smallexample
8147 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8148 @end smallexample
8149 @end enumerate
8150
8151 Notice the use of flags in the last example. The @file{/lib}
8152 directory often contains many symbolic links to files within it.
8153 It may look, for example, like this:
8154
8155 @smallexample
8156 $ @kbd{ls -l}
8157 drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
8158 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8159 lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8160 ...
8161 @end smallexample
8162
8163 Using the expression @samp{s,^,/usr/local/,} would mean adding
8164 @samp{/usr/local} to both regular archive members and to link
8165 targets. In this case, @file{/lib/libc.so.6} would become:
8166
8167 @smallexample
8168 /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8169 @end smallexample
8170
8171 This is definitely not desired. To avoid this, the @samp{S} flag
8172 is used, which excludes symbolic link targets from filename
8173 transformations. The result is:
8174
8175 @smallexample
8176 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8177 --show-transformed /lib}
8178 drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
8179 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8180 lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8181 -> libc-2.3.2.so
8182 @end smallexample
8183
8184 Unlike @option{--strip-components}, @option{--transform} can be used
8185 in any @GNUTAR{} operation mode. For example, the following command
8186 adds files to the archive while replacing the leading @file{usr/}
8187 component with @file{var/}:
8188
8189 @smallexample
8190 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8191 @end smallexample
8192
8193 To test @option{--transform} effect we suggest using
8194 @option{--show-transformed-names} option:
8195
8196 @smallexample
8197 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8198 --verbose --show-transformed-names /}
8199 @end smallexample
8200
8201 If both @option{--strip-components} and @option{--transform} are used
8202 together, then @option{--transform} is applied first, and the required
8203 number of components is then stripped from its result.
8204
8205 You can use as many @option{--transform} options in a single command
8206 line as you want. The specified expressions will then be applied in
8207 order of their appearance. For example, the following two invocations
8208 are equivalent:
8209
8210 @smallexample
8211 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8212 --transform='s,/usr/local,/usr/,'}
8213 $ @kbd{tar -cf arch.tar \
8214 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8215 @end smallexample
8216
8217 @node after
8218 @section Operating Only on New Files
8219
8220 @cindex Excluding file by age
8221 @cindex Data Modification time, excluding files by
8222 @cindex Modification time, excluding files by
8223 @cindex Age, excluding files by
8224 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
8225 @option{-N @var{date}}) option causes @command{tar} to only work on
8226 files whose data modification or status change times are newer than
8227 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
8228 it is taken to be a file name; the data modification time of that file
8229 is used as the date. If you use this option when creating or appending
8230 to an archive, the archive will only include new files. If you use
8231 @option{--after-date} when extracting an archive, @command{tar} will
8232 only extract files newer than the @var{date} you specify.
8233
8234 If you only want @command{tar} to make the date comparison based on
8235 modification of the file's data (rather than status
8236 changes), then use the @option{--newer-mtime=@var{date}} option.
8237
8238 @cindex --after-date and --update compared
8239 @cindex --newer-mtime and --update compared
8240 You may use these options with any operation. Note that these options
8241 differ from the @option{--update} (@option{-u}) operation in that they
8242 allow you to specify a particular date against which @command{tar} can
8243 compare when deciding whether or not to archive the files.
8244
8245 @table @option
8246 @opindex after-date
8247 @opindex newer
8248 @item --after-date=@var{date}
8249 @itemx --newer=@var{date}
8250 @itemx -N @var{date}
8251 Only store files newer than @var{date}.
8252
8253 Acts on files only if their data modification or status change times are
8254 later than @var{date}. Use in conjunction with any operation.
8255
8256 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
8257 name; the data modification time of that file is used as the date.
8258
8259 @opindex newer-mtime
8260 @item --newer-mtime=@var{date}
8261 Acts like @option{--after-date}, but only looks at data modification times.
8262 @end table
8263
8264 These options limit @command{tar} to operate only on files which have
8265 been modified after the date specified. A file's status is considered to have
8266 changed if its contents have been modified, or if its owner,
8267 permissions, and so forth, have been changed. (For more information on
8268 how to specify a date, see @ref{Date input formats}; remember that the
8269 entire date argument must be quoted if it contains any spaces.)
8270
8271 Gurus would say that @option{--after-date} tests both the data
8272 modification time (@code{mtime}, the time the contents of the file
8273 were last modified) and the status change time (@code{ctime}, the time
8274 the file's status was last changed: owner, permissions, etc.@:)
8275 fields, while @option{--newer-mtime} tests only the @code{mtime}
8276 field.
8277
8278 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
8279 @code{ctime} and processes the file if either one is more recent than
8280 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
8281 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
8282 contents of the file were looked at).
8283
8284 Date specifiers can have embedded spaces. Because of this, you may need
8285 to quote date arguments to keep the shell from parsing them as separate
8286 arguments. For example, the following command will add to the archive
8287 all the files modified less than two days ago:
8288
8289 @smallexample
8290 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
8291 @end smallexample
8292
8293 When any of these options is used with the option @option{--verbose}
8294 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
8295 date back to its textual representation and compare that with the
8296 one given with the option. If the two dates differ, @command{tar} will
8297 print a warning saying what date it will use. This is to help user
8298 ensure he is using the right date. For example:
8299
8300 @smallexample
8301 @group
8302 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
8303 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
8304 13:19:37.232434
8305 @end group
8306 @end smallexample
8307
8308 @quotation
8309 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
8310 should not be used for incremental backups. @xref{Incremental Dumps},
8311 for proper way of creating incremental backups.
8312 @end quotation
8313
8314 @node recurse
8315 @section Descending into Directories
8316 @cindex Avoiding recursion in directories
8317 @cindex Descending directories, avoiding
8318 @cindex Directories, avoiding recursion
8319 @cindex Recursion in directories, avoiding
8320
8321 Usually, @command{tar} will recursively explore all directories (either
8322 those given on the command line or through the @option{--files-from}
8323 option) for the various files they contain. However, you may not always
8324 want @command{tar} to act this way.
8325
8326 @opindex no-recursion
8327 @cindex @command{find}, using with @command{tar}
8328 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
8329 into specified directories. If you specify @option{--no-recursion}, you can
8330 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
8331 utility for hunting through levels of directories to
8332 construct a list of file names which you could then pass to @command{tar}.
8333 @command{find} allows you to be more selective when choosing which files to
8334 archive; see @ref{files}, for more information on using @command{find} with
8335 @command{tar}.
8336
8337 @table @option
8338 @item --no-recursion
8339 Prevents @command{tar} from recursively descending directories.
8340
8341 @opindex recursion
8342 @item --recursion
8343 Requires @command{tar} to recursively descend directories.
8344 This is the default.
8345 @end table
8346
8347 When you use @option{--no-recursion}, @GNUTAR{} grabs
8348 directory entries themselves, but does not descend on them
8349 recursively. Many people use @command{find} for locating files they
8350 want to back up, and since @command{tar} @emph{usually} recursively
8351 descends on directories, they have to use the @samp{@w{-not -type d}}
8352 test in their @command{find} invocation (@pxref{Type, Type, Type test,
8353 find, Finding Files}), as they usually do not want all the files in a
8354 directory. They then use the @option{--files-from} option to archive
8355 the files located via @command{find}.
8356
8357 The problem when restoring files archived in this manner is that the
8358 directories themselves are not in the archive; so the
8359 @option{--same-permissions} (@option{--preserve-permissions},
8360 @option{-p}) option does not affect them---while users might really
8361 like it to. Specifying @option{--no-recursion} is a way to tell
8362 @command{tar} to grab only the directory entries given to it, adding
8363 no new files on its own. To summarize, if you use @command{find} to
8364 create a list of files to be stored in an archive, use it as follows:
8365
8366 @smallexample
8367 @group
8368 $ @kbd{find @var{dir} @var{tests} | \
8369 tar -cf @var{archive} -T - --no-recursion}
8370 @end group
8371 @end smallexample
8372
8373 The @option{--no-recursion} option also applies when extracting: it
8374 causes @command{tar} to extract only the matched directory entries, not
8375 the files under those directories.
8376
8377 The @option{--no-recursion} option also affects how globbing patterns
8378 are interpreted (@pxref{controlling pattern-matching}).
8379
8380 The @option{--no-recursion} and @option{--recursion} options apply to
8381 later options and operands, and can be overridden by later occurrences
8382 of @option{--no-recursion} and @option{--recursion}. For example:
8383
8384 @smallexample
8385 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
8386 @end smallexample
8387
8388 @noindent
8389 creates an archive with one entry for @file{grape}, and the recursive
8390 contents of @file{grape/concord}, but no entries under @file{grape}
8391 other than @file{grape/concord}.
8392
8393 @node one
8394 @section Crossing File System Boundaries
8395 @cindex File system boundaries, not crossing
8396
8397 @command{tar} will normally automatically cross file system boundaries in
8398 order to archive files which are part of a directory tree. You can
8399 change this behavior by running @command{tar} and specifying
8400 @option{--one-file-system}. This option only affects files that are
8401 archived because they are in a directory that is being archived;
8402 @command{tar} will still archive files explicitly named on the command line
8403 or through @option{--files-from}, regardless of where they reside.
8404
8405 @table @option
8406 @opindex one-file-system
8407 @item --one-file-system
8408 Prevents @command{tar} from crossing file system boundaries when
8409 archiving. Use in conjunction with any write operation.
8410 @end table
8411
8412 The @option{--one-file-system} option causes @command{tar} to modify its
8413 normal behavior in archiving the contents of directories. If a file in
8414 a directory is not on the same file system as the directory itself, then
8415 @command{tar} will not archive that file. If the file is a directory
8416 itself, @command{tar} will not archive anything beneath it; in other words,
8417 @command{tar} will not cross mount points.
8418
8419 This option is useful for making full or incremental archival backups of
8420 a file system. If this option is used in conjunction with
8421 @option{--verbose} (@option{-v}), files that are excluded are
8422 mentioned by name on the standard error.
8423
8424 @menu
8425 * directory:: Changing Directory
8426 * absolute:: Absolute File Names
8427 @end menu
8428
8429 @node directory
8430 @subsection Changing the Working Directory
8431
8432 @FIXME{need to read over this node now for continuity; i've switched
8433 things around some.}
8434
8435 @cindex Changing directory mid-stream
8436 @cindex Directory, changing mid-stream
8437 @cindex Working directory, specifying
8438 To change the working directory in the middle of a list of file names,
8439 either on the command line or in a file specified using
8440 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
8441 This will change the working directory to the specified directory
8442 after that point in the list.
8443
8444 @table @option
8445 @opindex directory
8446 @item --directory=@var{directory}
8447 @itemx -C @var{directory}
8448 Changes the working directory in the middle of a command line.
8449 @end table
8450
8451 For example,
8452
8453 @smallexample
8454 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
8455 @end smallexample
8456
8457 @noindent
8458 will place the files @file{grape} and @file{prune} from the current
8459 directory into the archive @file{jams.tar}, followed by the file
8460 @file{cherry} from the directory @file{food}. This option is especially
8461 useful when you have several widely separated files that you want to
8462 store in the same archive.
8463
8464 Note that the file @file{cherry} is recorded in the archive under the
8465 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
8466 archive will contain three files that all appear to have come from the
8467 same directory; if the archive is extracted with plain @samp{tar
8468 --extract}, all three files will be written in the current directory.
8469
8470 Contrast this with the command,
8471
8472 @smallexample
8473 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
8474 @end smallexample
8475
8476 @noindent
8477 which records the third file in the archive under the name
8478 @file{red/cherry} so that, if the archive is extracted using
8479 @samp{tar --extract}, the third file will be written in a subdirectory
8480 named @file{red}.
8481
8482 You can use the @option{--directory} option to make the archive
8483 independent of the original name of the directory holding the files.
8484 The following command places the files @file{/etc/passwd},
8485 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
8486 @file{foo.tar}:
8487
8488 @smallexample
8489 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
8490 @end smallexample
8491
8492 @noindent
8493 However, the names of the archive members will be exactly what they were
8494 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
8495 They will not appear to be related by file name to the original
8496 directories where those files were located.
8497
8498 Note that @option{--directory} options are interpreted consecutively. If
8499 @option{--directory} specifies a relative file name, it is interpreted
8500 relative to the then current directory, which might not be the same as
8501 the original current working directory of @command{tar}, due to a previous
8502 @option{--directory} option.
8503
8504 When using @option{--files-from} (@pxref{files}), you can put various
8505 @command{tar} options (including @option{-C}) in the file list. Notice,
8506 however, that in this case the option and its argument may not be
8507 separated by whitespace. If you use short option, its argument must
8508 either follow the option letter immediately, without any intervening
8509 whitespace, or occupy the next line. Otherwise, if you use long
8510 option, separate its argument by an equal sign.
8511
8512 For instance, the file list for the above example will be:
8513
8514 @smallexample
8515 @group
8516 -C/etc
8517 passwd
8518 hosts
8519 --directory=/lib
8520 libc.a
8521 @end group
8522 @end smallexample
8523
8524 @noindent
8525 To use it, you would invoke @command{tar} as follows:
8526
8527 @smallexample
8528 $ @kbd{tar -c -f foo.tar --files-from list}
8529 @end smallexample
8530
8531 The interpretation of @option{--directory} is disabled by
8532 @option{--null} option.
8533
8534 @node absolute
8535 @subsection Absolute File Names
8536 @cindex absolute file names
8537 @cindex file names, absolute
8538
8539 By default, @GNUTAR{} drops a leading @samp{/} on
8540 input or output, and complains about file names containing a @file{..}
8541 component. There is an option that turns off this behavior:
8542
8543 @table @option
8544 @opindex absolute-names
8545 @item --absolute-names
8546 @itemx -P
8547 Do not strip leading slashes from file names, and permit file names
8548 containing a @file{..} file name component.
8549 @end table
8550
8551 When @command{tar} extracts archive members from an archive, it strips any
8552 leading slashes (@samp{/}) from the member name. This causes absolute
8553 member names in the archive to be treated as relative file names. This
8554 allows you to have such members extracted wherever you want, instead of
8555 being restricted to extracting the member in the exact directory named
8556 in the archive. For example, if the archive member has the name
8557 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8558 really @file{etc/passwd}.
8559
8560 File names containing @file{..} can cause problems when extracting, so
8561 @command{tar} normally warns you about such files when creating an
8562 archive, and rejects attempts to extracts such files.
8563
8564 Other @command{tar} programs do not do this. As a result, if you
8565 create an archive whose member names start with a slash, they will be
8566 difficult for other people with a non-@GNUTAR{}
8567 program to use. Therefore, @GNUTAR{} also strips
8568 leading slashes from member names when putting members into the
8569 archive. For example, if you ask @command{tar} to add the file
8570 @file{/bin/ls} to an archive, it will do so, but the member name will
8571 be @file{bin/ls}@footnote{A side effect of this is that when
8572 @option{--create} is used with @option{--verbose} the resulting output
8573 is not, generally speaking, the same as the one you'd get running
8574 @kbd{tar --list} command. This may be important if you use some
8575 scripts for comparing both outputs. @xref{listing member and file names},
8576 for the information on how to handle this case.}.
8577
8578 Symbolic links containing @file{..} or leading @samp{/} can also cause
8579 problems when extracting, so @command{tar} normally extracts them last;
8580 it may create empty files as placeholders during extraction.
8581
8582 If you use the @option{--absolute-names} (@option{-P}) option,
8583 @command{tar} will do none of these transformations.
8584
8585 To archive or extract files relative to the root directory, specify
8586 the @option{--absolute-names} (@option{-P}) option.
8587
8588 Normally, @command{tar} acts on files relative to the working
8589 directory---ignoring superior directory names when archiving, and
8590 ignoring leading slashes when extracting.
8591
8592 When you specify @option{--absolute-names} (@option{-P}),
8593 @command{tar} stores file names including all superior directory
8594 names, and preserves leading slashes. If you only invoked
8595 @command{tar} from the root directory you would never need the
8596 @option{--absolute-names} option, but using this option
8597 may be more convenient than switching to root.
8598
8599 @FIXME{Should be an example in the tutorial/wizardry section using this
8600 to transfer files between systems.}
8601
8602 @table @option
8603 @item --absolute-names
8604 Preserves full file names (including superior directory names) when
8605 archiving and extracting files.
8606
8607 @end table
8608
8609 @command{tar} prints out a message about removing the @samp{/} from
8610 file names. This message appears once per @GNUTAR{}
8611 invocation. It represents something which ought to be told; ignoring
8612 what it means can cause very serious surprises, later.
8613
8614 Some people, nevertheless, do not want to see this message. Wanting to
8615 play really dangerously, one may of course redirect @command{tar} standard
8616 error to the sink. For example, under @command{sh}:
8617
8618 @smallexample
8619 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8620 @end smallexample
8621
8622 @noindent
8623 Another solution, both nicer and simpler, would be to change to
8624 the @file{/} directory first, and then avoid absolute notation.
8625 For example:
8626
8627 @smallexample
8628 $ @kbd{tar -c -f archive.tar -C / home}
8629 @end smallexample
8630
8631 @xref{Integrity}, for some of the security-related implications
8632 of using this option.
8633
8634 @include parse-datetime.texi
8635
8636 @node Formats
8637 @chapter Controlling the Archive Format
8638
8639 @cindex Tar archive formats
8640 Due to historical reasons, there are several formats of tar archives.
8641 All of them are based on the same principles, but have some subtle
8642 differences that often make them incompatible with each other.
8643
8644 GNU tar is able to create and handle archives in a variety of formats.
8645 The most frequently used formats are (in alphabetical order):
8646
8647 @table @asis
8648 @item gnu
8649 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8650 from an early @acronym{POSIX} standard, adding some improvements such as
8651 sparse file handling and incremental archives. Unfortunately these
8652 features were implemented in a way incompatible with other archive
8653 formats.
8654
8655 Archives in @samp{gnu} format are able to hold file names of unlimited
8656 length.
8657
8658 @item oldgnu
8659 Format used by @GNUTAR{} of versions prior to 1.12.
8660
8661 @item v7
8662 Archive format, compatible with the V7 implementation of tar. This
8663 format imposes a number of limitations. The most important of them
8664 are:
8665
8666 @enumerate
8667 @item The maximum length of a file name is limited to 99 characters.
8668 @item The maximum length of a symbolic link is limited to 99 characters.
8669 @item It is impossible to store special files (block and character
8670 devices, fifos etc.)
8671 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8672 octal)
8673 @item V7 archives do not contain symbolic ownership information (user
8674 and group name of the file owner).
8675 @end enumerate
8676
8677 This format has traditionally been used by Automake when producing
8678 Makefiles. This practice will change in the future, in the meantime,
8679 however this means that projects containing file names more than 99
8680 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8681 Automake prior to 1.9.
8682
8683 @item ustar
8684 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8685 symbolic ownership information. It is also able to store
8686 special files. However, it imposes several restrictions as well:
8687
8688 @enumerate
8689 @item The maximum length of a file name is limited to 256 characters,
8690 provided that the file name can be split at a directory separator in
8691 two parts, first of them being at most 155 bytes long. So, in most
8692 cases the maximum file name length will be shorter than 256
8693 characters.
8694 @item The maximum length of a symbolic link name is limited to
8695 100 characters.
8696 @item Maximum size of a file the archive is able to accommodate
8697 is 8GB
8698 @item Maximum value of UID/GID is 2097151.
8699 @item Maximum number of bits in device major and minor numbers is 21.
8700 @end enumerate
8701
8702 @item star
8703 Format used by J@"org Schilling @command{star}
8704 implementation. @GNUTAR{} is able to read @samp{star} archives but
8705 currently does not produce them.
8706
8707 @item posix
8708 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8709 most flexible and feature-rich format. It does not impose any
8710 restrictions on file sizes or file name lengths. This format is quite
8711 recent, so not all tar implementations are able to handle it properly.
8712 However, this format is designed in such a way that any tar
8713 implementation able to read @samp{ustar} archives will be able to read
8714 most @samp{posix} archives as well, with the only exception that any
8715 additional information (such as long file names etc.) will in such
8716 case be extracted as plain text files along with the files it refers to.
8717
8718 This archive format will be the default format for future versions
8719 of @GNUTAR{}.
8720
8721 @end table
8722
8723 The following table summarizes the limitations of each of these
8724 formats:
8725
8726 @multitable @columnfractions .10 .20 .20 .20 .20
8727 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8728 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8729 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8730 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8731 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8732 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8733 @end multitable
8734
8735 The default format for @GNUTAR{} is defined at compilation
8736 time. You may check it by running @command{tar --help}, and examining
8737 the last lines of its output. Usually, @GNUTAR{} is configured
8738 to create archives in @samp{gnu} format, however, future version will
8739 switch to @samp{posix}.
8740
8741 @menu
8742 * Compression:: Using Less Space through Compression
8743 * Attributes:: Handling File Attributes
8744 * Portability:: Making @command{tar} Archives More Portable
8745 * cpio:: Comparison of @command{tar} and @command{cpio}
8746 @end menu
8747
8748 @node Compression
8749 @section Using Less Space through Compression
8750
8751 @menu
8752 * gzip:: Creating and Reading Compressed Archives
8753 * sparse:: Archiving Sparse Files
8754 @end menu
8755
8756 @node gzip
8757 @subsection Creating and Reading Compressed Archives
8758 @cindex Compressed archives
8759 @cindex Storing archives in compressed format
8760
8761 @cindex gzip
8762 @cindex bzip2
8763 @cindex lzip
8764 @cindex lzma
8765 @cindex lzop
8766 @cindex compress
8767 @GNUTAR{} is able to create and read compressed archives. It supports
8768 a wide variety of compression programs, namely: @command{gzip},
8769 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
8770 @command{xz} and traditional @command{compress}. The latter is
8771 supported mostly for backward compatibility, and we recommend
8772 against using it, because it is by far less effective than the other
8773 compression programs@footnote{It also had patent problems in the past.}.
8774
8775 Creating a compressed archive is simple: you just specify a
8776 @dfn{compression option} along with the usual archive creation
8777 commands. The compression option is @option{-z} (@option{--gzip}) to
8778 create a @command{gzip} compressed archive, @option{-j}
8779 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8780 @option{--lzip} to create an @asis{lzip} compressed archive,
8781 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
8782 @option{--lzma} to create an @asis{LZMA} compressed
8783 archive, @option{--lzop} to create an @asis{LSOP} archive, and
8784 @option{-Z} (@option{--compress}) to use @command{compress} program.
8785 For example:
8786
8787 @smallexample
8788 $ @kbd{tar czf archive.tar.gz .}
8789 @end smallexample
8790
8791 You can also let @GNUTAR{} select the compression program based on
8792 the suffix of the archive file name. This is done using
8793 @option{--auto-compress} (@option{-a}) command line option. For
8794 example, the following invocation will use @command{bzip2} for
8795 compression:
8796
8797 @smallexample
8798 $ @kbd{tar caf archive.tar.bz2 .}
8799 @end smallexample
8800
8801 @noindent
8802 whereas the following one will use @command{lzma}:
8803
8804 @smallexample
8805 $ @kbd{tar caf archive.tar.lzma .}
8806 @end smallexample
8807
8808 For a complete list of file name suffixes recognized by @GNUTAR{},
8809 see @ref{auto-compress}.
8810
8811 Reading compressed archive is even simpler: you don't need to specify
8812 any additional options as @GNUTAR{} recognizes its format
8813 automatically. Thus, the following commands will list and extract the
8814 archive created in previous example:
8815
8816 @smallexample
8817 # List the compressed archive
8818 $ @kbd{tar tf archive.tar.gz}
8819 # Extract the compressed archive
8820 $ @kbd{tar xf archive.tar.gz}
8821 @end smallexample
8822
8823 The format recognition algorithm is based on @dfn{signatures}, a
8824 special byte sequences in the beginning of file, that are specific for
8825 certain compression formats. If this approach fails, @command{tar}
8826 falls back to using archive name suffix to determine its format
8827 (@pxref{auto-compress}, for a list of recognized suffixes).
8828
8829 @anchor{alternative decompression programs}
8830 @cindex alternative decompression programs
8831 Some compression programs are able to handle different compression
8832 formats. @GNUTAR{} uses this, if the principal decompressor for the
8833 given format is not available. For example, if @command{compress} is
8834 not installed, @command{tar} will try to use @command{gzip}. As of
8835 version @value{VERSION} the following alternatives are
8836 tried@footnote{To verbosely trace the decompressor selection, use the
8837 @option{--warning=decompress-program} option
8838 (@pxref{warnings,decompress-program}).}:
8839
8840 @multitable @columnfractions 0.3 0.3 0.3
8841 @headitem Format @tab Main decompressor @tab Alternatives
8842 @item compress @tab compress @tab gzip
8843 @item lzma @tab lzma @tab xz
8844 @item bzip2 @tab bzip2 @tab lbzip2
8845 @end multitable
8846
8847 The only case when you have to specify a decompression option while
8848 reading the archive is when reading from a pipe or from a tape drive
8849 that does not support random access. However, in this case @GNUTAR{}
8850 will indicate which option you should use. For example:
8851
8852 @smallexample
8853 $ @kbd{cat archive.tar.gz | tar tf -}
8854 tar: Archive is compressed. Use -z option
8855 tar: Error is not recoverable: exiting now
8856 @end smallexample
8857
8858 If you see such diagnostics, just add the suggested option to the
8859 invocation of @GNUTAR{}:
8860
8861 @smallexample
8862 $ @kbd{cat archive.tar.gz | tar tzf -}
8863 @end smallexample
8864
8865 Notice also, that there are several restrictions on operations on
8866 compressed archives. First of all, compressed archives cannot be
8867 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
8868 them or delete (@option{--delete}) members from them or
8869 add (@option{--append}, alias @option{-r}) members to them. Likewise, you
8870 cannot append another @command{tar} archive to a compressed archive using
8871 @option{--concatenate} (@option{-A}). Secondly, multi-volume
8872 archives cannot be compressed.
8873
8874 The following options allow to select a particular compressor program:
8875
8876 @table @option
8877 @opindex gzip
8878 @opindex ungzip
8879 @item -z
8880 @itemx --gzip
8881 @itemx --ungzip
8882 Filter the archive through @command{gzip}.
8883
8884 @opindex xz
8885 @item -J
8886 @itemx --xz
8887 Filter the archive through @code{xz}.
8888
8889 @item -j
8890 @itemx --bzip2
8891 Filter the archive through @code{bzip2}.
8892
8893 @opindex lzip
8894 @item --lzip
8895 Filter the archive through @command{lzip}.
8896
8897 @opindex lzma
8898 @item --lzma
8899 Filter the archive through @command{lzma}.
8900
8901 @opindex lzop
8902 @item --lzop
8903 Filter the archive through @command{lzop}.
8904
8905 @opindex compress
8906 @opindex uncompress
8907 @item -Z
8908 @itemx --compress
8909 @itemx --uncompress
8910 Filter the archive through @command{compress}.
8911 @end table
8912
8913 When any of these options is given, @GNUTAR{} searches the compressor
8914 binary in the current path and invokes it. The name of the compressor
8915 program is specified at compilation time using a corresponding
8916 @option{--with-@var{compname}} option to @command{configure}, e.g.
8917 @option{--with-bzip2} to select a specific @command{bzip2} binary.
8918 @xref{lbzip2}, for a detailed discussion.
8919
8920 The output produced by @command{tar --help} shows the actual
8921 compressor names along with each of these options.
8922
8923 You can use any of these options on physical devices (tape drives,
8924 etc.) and remote files as well as on normal files; data to or from
8925 such devices or remote files is reblocked by another copy of the
8926 @command{tar} program to enforce the specified (or default) record
8927 size. The default compression parameters are used. Most compression
8928 programs let you override these by setting a program-specific
8929 environment variable. For example, with @command{gzip} you can set
8930 @env{GZIP}:
8931
8932 @smallexample
8933 $ @kbd{GZIP='-9 -n' tar czf archive.tar.gz subdir}
8934 @end smallexample
8935
8936 @noindent
8937 The traditional way to do this is to use a pipe:
8938
8939 @smallexample
8940 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
8941 @end smallexample
8942
8943 @cindex corrupted archives
8944 Compressed archives are easily corrupted, because compressed files
8945 have little redundancy. The adaptive nature of the
8946 compression scheme means that the compression tables are implicitly
8947 spread all over the archive. If you lose a few blocks, the dynamic
8948 construction of the compression tables becomes unsynchronized, and there
8949 is little chance that you could recover later in the archive.
8950
8951 Other compression options provide better control over creating
8952 compressed archives. These are:
8953
8954 @table @option
8955 @anchor{auto-compress}
8956 @opindex auto-compress
8957 @item --auto-compress
8958 @itemx -a
8959 Select a compression program to use by the archive file name
8960 suffix. The following suffixes are recognized:
8961
8962 @multitable @columnfractions 0.3 0.6
8963 @headitem Suffix @tab Compression program
8964 @item @samp{.gz} @tab @command{gzip}
8965 @item @samp{.tgz} @tab @command{gzip}
8966 @item @samp{.taz} @tab @command{gzip}
8967 @item @samp{.Z} @tab @command{compress}
8968 @item @samp{.taZ} @tab @command{compress}
8969 @item @samp{.bz2} @tab @command{bzip2}
8970 @item @samp{.tz2} @tab @command{bzip2}
8971 @item @samp{.tbz2} @tab @command{bzip2}
8972 @item @samp{.tbz} @tab @command{bzip2}
8973 @item @samp{.lz} @tab @command{lzip}
8974 @item @samp{.lzma} @tab @command{lzma}
8975 @item @samp{.tlz} @tab @command{lzma}
8976 @item @samp{.lzo} @tab @command{lzop}
8977 @item @samp{.xz} @tab @command{xz}
8978 @end multitable
8979
8980 @opindex use-compress-program
8981 @item --use-compress-program=@var{prog}
8982 @itemx -I=@var{prog}
8983 Use external compression program @var{prog}. Use this option if you
8984 are not happy with the compression program associated with the suffix
8985 at compile time or if you have a compression program that @GNUTAR{}
8986 does not support. The program should follow two conventions:
8987
8988 First, when invoked without options, it should read data from standard
8989 input, compress it and output it on standard output.
8990
8991 Secondly, if invoked with the @option{-d} option, it should do exactly
8992 the opposite, i.e., read the compressed data from the standard input
8993 and produce uncompressed data on the standard output.
8994 @end table
8995
8996 @cindex gpg, using with tar
8997 @cindex gnupg, using with tar
8998 @cindex Using encrypted archives
8999 The @option{--use-compress-program} option, in particular, lets you
9000 implement your own filters, not necessarily dealing with
9001 compression/decompression. For example, suppose you wish to implement
9002 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9003 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9004 Manual}). The following script does that:
9005
9006 @smallexample
9007 @group
9008 #! /bin/sh
9009 case $1 in
9010 -d) gpg --decrypt - | gzip -d -c;;
9011 '') gzip -c | gpg -s;;
9012 *) echo "Unknown option $1">&2; exit 1;;
9013 esac
9014 @end group
9015 @end smallexample
9016
9017 Suppose you name it @file{gpgz} and save it somewhere in your
9018 @env{PATH}. Then the following command will create a compressed
9019 archive signed with your private key:
9020
9021 @smallexample
9022 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9023 @end smallexample
9024
9025 @noindent
9026 Likewise, the command below will list its contents:
9027
9028 @smallexample
9029 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9030 @end smallexample
9031
9032 @ignore
9033 The above is based on the following discussion:
9034
9035 I have one question, or maybe it's a suggestion if there isn't a way
9036 to do it now. I would like to use @option{--gzip}, but I'd also like
9037 the output to be fed through a program like @acronym{GNU}
9038 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9039 to use :-)), basically adding ECC protection on top of compression.
9040 It seems as if this should be quite easy to do, but I can't work out
9041 exactly how to go about it. Of course, I can pipe the standard output
9042 of @command{tar} through @command{ecc}, but then I lose (though I
9043 haven't started using it yet, I confess) the ability to have
9044 @command{tar} use @command{rmt} for it's I/O (I think).
9045
9046 I think the most straightforward thing would be to let me specify a
9047 general set of filters outboard of compression (preferably ordered,
9048 so the order can be automatically reversed on input operations, and
9049 with the options they require specifiable), but beggars shouldn't be
9050 choosers and anything you decide on would be fine with me.
9051
9052 By the way, I like @command{ecc} but if (as the comments say) it can't
9053 deal with loss of block sync, I'm tempted to throw some time at adding
9054 that capability. Supposing I were to actually do such a thing and
9055 get it (apparently) working, do you accept contributed changes to
9056 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9057
9058 Isn't that exactly the role of the
9059 @option{--use-compress-prog=@var{program}} option?
9060 I never tried it myself, but I suspect you may want to write a
9061 @var{prog} script or program able to filter stdin to stdout to
9062 way you want. It should recognize the @option{-d} option, for when
9063 extraction is needed rather than creation.
9064
9065 It has been reported that if one writes compressed data (through the
9066 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9067 the DLT compression mode, the data will actually get bigger and one will
9068 end up with less space on the tape.
9069 @end ignore
9070
9071 @menu
9072 * lbzip2:: Using lbzip2 with @GNUTAR{}.
9073 @end menu
9074
9075 @node lbzip2
9076 @subsubsection Using lbzip2 with @GNUTAR{}.
9077 @cindex lbzip2
9078 @cindex Laszlo Ersek
9079 @command{Lbzip2} is a multithreaded utility for handling
9080 @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
9081 multiple processors to speed up its operation and in general works
9082 considerably faster than @command{bzip2}. For a detailed description
9083 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9084 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9085 lbzip2: parallel bzip2 utility}.
9086
9087 Recent versions of @command{lbzip2} are mostly command line compatible
9088 with @command{bzip2}, which makes it possible to automatically invoke
9089 it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
9090 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9091 line option, like this:
9092
9093 @smallexample
9094 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9095 @end smallexample
9096
9097 Once configured and compiled this way, @command{tar --help} will show the
9098 following:
9099
9100 @smallexample
9101 @group
9102 $ @kbd{tar --help | grep -- --bzip2}
9103 -j, --bzip2 filter the archive through lbzip2
9104 @end group
9105 @end smallexample
9106
9107 @noindent
9108 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9109
9110 @node sparse
9111 @subsection Archiving Sparse Files
9112 @cindex Sparse Files
9113
9114 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
9115 in a file is a section of the file's contents which was never written.
9116 The contents of a hole reads as all zeros. On many operating systems,
9117 actual disk storage is not allocated for holes, but they are counted
9118 in the length of the file. If you archive such a file, @command{tar}
9119 could create an archive longer than the original. To have @command{tar}
9120 attempt to recognize the holes in a file, use @option{--sparse}
9121 (@option{-S}). When you use this option, then, for any file using
9122 less disk space than would be expected from its length, @command{tar}
9123 searches the file for consecutive stretches of zeros. It then records
9124 in the archive for the file where the consecutive stretches of zeros
9125 are, and only archives the ``real contents'' of the file. On
9126 extraction (using @option{--sparse} is not needed on extraction) any
9127 such files have holes created wherever the continuous stretches of zeros
9128 were found. Thus, if you use @option{--sparse}, @command{tar} archives
9129 won't take more space than the original.
9130
9131 @table @option
9132 @opindex sparse
9133 @item -S
9134 @itemx --sparse
9135 This option instructs @command{tar} to test each file for sparseness
9136 before attempting to archive it. If the file is found to be sparse it
9137 is treated specially, thus allowing to decrease the amount of space
9138 used by its image in the archive.
9139
9140 This option is meaningful only when creating or updating archives. It
9141 has no effect on extraction.
9142 @end table
9143
9144 Consider using @option{--sparse} when performing file system backups,
9145 to avoid archiving the expanded forms of files stored sparsely in the
9146 system.
9147
9148 Even if your system has no sparse files currently, some may be
9149 created in the future. If you use @option{--sparse} while making file
9150 system backups as a matter of course, you can be assured the archive
9151 will never take more space on the media than the files take on disk
9152 (otherwise, archiving a disk filled with sparse files might take
9153 hundreds of tapes). @xref{Incremental Dumps}.
9154
9155 However, be aware that @option{--sparse} option presents a serious
9156 drawback. Namely, in order to determine if the file is sparse
9157 @command{tar} has to read it before trying to archive it, so in total
9158 the file is read @strong{twice}. So, always bear in mind that the
9159 time needed to process all files with this option is roughly twice
9160 the time needed to archive them without it.
9161 @FIXME{A technical note:
9162
9163 Programs like @command{dump} do not have to read the entire file; by
9164 examining the file system directly, they can determine in advance
9165 exactly where the holes are and thus avoid reading through them. The
9166 only data it need read are the actual allocated data blocks.
9167 @GNUTAR{} uses a more portable and straightforward
9168 archiving approach, it would be fairly difficult that it does
9169 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
9170 1990-12-10:
9171
9172 @quotation
9173 What I did say is that you cannot tell the difference between a hole and an
9174 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
9175 best tells you how many holes there are; it doesn't tell you @emph{where}.
9176 Just as programs may, conceivably, care what @code{st_blocks} is (care
9177 to name one that does?), they may also care where the holes are (I have
9178 no examples of this one either, but it's equally imaginable).
9179
9180 I conclude from this that good archivers are not portable. One can
9181 arguably conclude that if you want a portable program, you can in good
9182 conscience restore files with as many holes as possible, since you can't
9183 get it right.
9184 @end quotation
9185 }
9186
9187 @cindex sparse formats, defined
9188 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9189 sparse files using in three distinct ways, called @dfn{sparse
9190 formats}. A sparse format is identified by its @dfn{number},
9191 consisting, as usual of two decimal numbers, delimited by a dot. By
9192 default, format @samp{1.0} is used. If, for some reason, you wish to
9193 use an earlier format, you can select it using
9194 @option{--sparse-version} option.
9195
9196 @table @option
9197 @opindex sparse-version
9198 @item --sparse-version=@var{version}
9199
9200 Select the format to store sparse files in. Valid @var{version} values
9201 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
9202 for a detailed description of each format.
9203 @end table
9204
9205 Using @option{--sparse-format} option implies @option{--sparse}.
9206
9207 @node Attributes
9208 @section Handling File Attributes
9209 @cindex atrributes, files
9210 @cindex file attributes
9211
9212 When @command{tar} reads files, it updates their access times. To
9213 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
9214 reset the access time retroactively or avoid changing it in the first
9215 place.
9216
9217 @table @option
9218 @opindex atime-preserve
9219 @item --atime-preserve
9220 @itemx --atime-preserve=replace
9221 @itemx --atime-preserve=system
9222 Preserve the access times of files that are read. This works only for
9223 files that you own, unless you have superuser privileges.
9224
9225 @option{--atime-preserve=replace} works on most systems, but it also
9226 restores the data modification time and updates the status change
9227 time. Hence it doesn't interact with incremental dumps nicely
9228 (@pxref{Incremental Dumps}), and it can set access or data modification times
9229 incorrectly if other programs access the file while @command{tar} is
9230 running.
9231
9232 @option{--atime-preserve=system} avoids changing the access time in
9233 the first place, if the operating system supports this.
9234 Unfortunately, this may or may not work on any given operating system
9235 or file system. If @command{tar} knows for sure it won't work, it
9236 complains right away.
9237
9238 Currently @option{--atime-preserve} with no operand defaults to
9239 @option{--atime-preserve=replace}, but this is intended to change to
9240 @option{--atime-preserve=system} when the latter is better-supported.
9241
9242 @opindex touch
9243 @item -m
9244 @itemx --touch
9245 Do not extract data modification time.
9246
9247 When this option is used, @command{tar} leaves the data modification times
9248 of the files it extracts as the times when the files were extracted,
9249 instead of setting it to the times recorded in the archive.
9250
9251 This option is meaningless with @option{--list} (@option{-t}).
9252
9253 @opindex same-owner
9254 @item --same-owner
9255 Create extracted files with the same ownership they have in the
9256 archive.
9257
9258 This is the default behavior for the superuser,
9259 so this option is meaningful only for non-root users, when @command{tar}
9260 is executed on those systems able to give files away. This is
9261 considered as a security flaw by many people, at least because it
9262 makes quite difficult to correctly account users for the disk space
9263 they occupy. Also, the @code{suid} or @code{sgid} attributes of
9264 files are easily and silently lost when files are given away.
9265
9266 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
9267 separately. If it can't find a user name (because the user @acronym{ID} is not
9268 in @file{/etc/passwd}), then it does not write one. When restoring,
9269 it tries to look the name (if one was written) up in
9270 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
9271 the archive instead.
9272
9273 @opindex no-same-owner
9274 @item --no-same-owner
9275 @itemx -o
9276 Do not attempt to restore ownership when extracting. This is the
9277 default behavior for ordinary users, so this option has an effect
9278 only for the superuser.
9279
9280 @opindex numeric-owner
9281 @item --numeric-owner
9282 The @option{--numeric-owner} option allows (ANSI) archives to be written
9283 without user/group name information or such information to be ignored
9284 when extracting. It effectively disables the generation and/or use
9285 of user/group name information. This option forces extraction using
9286 the numeric ids from the archive, ignoring the names.
9287
9288 This is useful in certain circumstances, when restoring a backup from
9289 an emergency floppy with different passwd/group files for example.
9290 It is otherwise impossible to extract files with the right ownerships
9291 if the password file in use during the extraction does not match the
9292 one belonging to the file system(s) being extracted. This occurs,
9293 for example, if you are restoring your files after a major crash and
9294 had booted from an emergency floppy with no password file or put your
9295 disk into another machine to do the restore.
9296
9297 The numeric ids are @emph{always} saved into @command{tar} archives.
9298 The identifying names are added at create time when provided by the
9299 system, unless @option{--format=oldgnu} is used. Numeric ids could be
9300 used when moving archives between a collection of machines using
9301 a centralized management for attribution of numeric ids to users
9302 and groups. This is often made through using the NIS capabilities.
9303
9304 When making a @command{tar} file for distribution to other sites, it
9305 is sometimes cleaner to use a single owner for all files in the
9306 distribution, and nicer to specify the write permission bits of the
9307 files as stored in the archive independently of their actual value on
9308 the file system. The way to prepare a clean distribution is usually
9309 to have some Makefile rule creating a directory, copying all needed
9310 files in that directory, then setting ownership and permissions as
9311 wanted (there are a lot of possible schemes), and only then making a
9312 @command{tar} archive out of this directory, before cleaning
9313 everything out. Of course, we could add a lot of options to
9314 @GNUTAR{} for fine tuning permissions and ownership.
9315 This is not the good way, I think. @GNUTAR{} is
9316 already crowded with options and moreover, the approach just explained
9317 gives you a great deal of control already.
9318
9319 @xopindex{same-permissions, short description}
9320 @xopindex{preserve-permissions, short description}
9321 @item -p
9322 @itemx --same-permissions
9323 @itemx --preserve-permissions
9324 Extract all protection information.
9325
9326 This option causes @command{tar} to set the modes (access permissions) of
9327 extracted files exactly as recorded in the archive. If this option
9328 is not used, the current @code{umask} setting limits the permissions
9329 on extracted files. This option is by default enabled when
9330 @command{tar} is executed by a superuser.
9331
9332
9333 This option is meaningless with @option{--list} (@option{-t}).
9334
9335 @opindex preserve
9336 @item --preserve
9337 Same as both @option{--same-permissions} and @option{--same-order}.
9338
9339 This option is deprecated, and will be removed in @GNUTAR{} version 1.23.
9340
9341 @end table
9342
9343 @node Portability
9344 @section Making @command{tar} Archives More Portable
9345
9346 Creating a @command{tar} archive on a particular system that is meant to be
9347 useful later on many other machines and with other versions of @command{tar}
9348 is more challenging than you might think. @command{tar} archive formats
9349 have been evolving since the first versions of Unix. Many such formats
9350 are around, and are not always compatible with each other. This section
9351 discusses a few problems, and gives some advice about making @command{tar}
9352 archives more portable.
9353
9354 One golden rule is simplicity. For example, limit your @command{tar}
9355 archives to contain only regular files and directories, avoiding
9356 other kind of special files. Do not attempt to save sparse files or
9357 contiguous files as such. Let's discuss a few more problems, in turn.
9358
9359 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
9360 archives and archive labels) in GNU and PAX formats.}
9361
9362 @menu
9363 * Portable Names:: Portable Names
9364 * dereference:: Symbolic Links
9365 * hard links:: Hard Links
9366 * old:: Old V7 Archives
9367 * ustar:: Ustar Archives
9368 * gnu:: GNU and old GNU format archives.
9369 * posix:: @acronym{POSIX} archives
9370 * Checksumming:: Checksumming Problems
9371 * Large or Negative Values:: Large files, negative time stamps, etc.
9372 * Other Tars:: How to Extract GNU-Specific Data Using
9373 Other @command{tar} Implementations
9374 @end menu
9375
9376 @node Portable Names
9377 @subsection Portable Names
9378
9379 Use portable file and member names. A name is portable if it contains
9380 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
9381 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
9382 contain @samp{/-}. Avoid deep directory nesting. For portability to
9383 old Unix hosts, limit your file name components to 14 characters or
9384 less.
9385
9386 If you intend to have your @command{tar} archives to be read under
9387 MSDOS, you should not rely on case distinction for file names, and you
9388 might use the @acronym{GNU} @command{doschk} program for helping you
9389 further diagnosing illegal MSDOS names, which are even more limited
9390 than System V's.
9391
9392 @node dereference
9393 @subsection Symbolic Links
9394 @cindex File names, using symbolic links
9395 @cindex Symbolic link as file name
9396
9397 @opindex dereference
9398 Normally, when @command{tar} archives a symbolic link, it writes a
9399 block to the archive naming the target of the link. In that way, the
9400 @command{tar} archive is a faithful record of the file system contents.
9401 When @option{--dereference} (@option{-h}) is used with
9402 @option{--create} (@option{-c}), @command{tar} archives the files
9403 symbolic links point to, instead of
9404 the links themselves.
9405
9406 When creating portable archives, use @option{--dereference}
9407 (@option{-h}): some systems do not support
9408 symbolic links, and moreover, your distribution might be unusable if
9409 it contains unresolved symbolic links.
9410
9411 When reading from an archive, the @option{--dereference} (@option{-h})
9412 option causes @command{tar} to follow an already-existing symbolic
9413 link when @command{tar} writes or reads a file named in the archive.
9414 Ordinarily, @command{tar} does not follow such a link, though it may
9415 remove the link before writing a new file. @xref{Dealing with Old
9416 Files}.
9417
9418 The @option{--dereference} option is unsafe if an untrusted user can
9419 modify directories while @command{tar} is running. @xref{Security}.
9420
9421 @node hard links
9422 @subsection Hard Links
9423 @cindex File names, using hard links
9424 @cindex hard links, dereferencing
9425 @cindex dereferencing hard links
9426
9427 Normally, when @command{tar} archives a hard link, it writes a
9428 block to the archive naming the target of the link (a @samp{1} type
9429 block). In that way, the actual file contents is stored in file only
9430 once. For example, consider the following two files:
9431
9432 @smallexample
9433 @group
9434 $ ls -l
9435 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
9436 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
9437 @end group
9438 @end smallexample
9439
9440 Here, @file{jeden} is a link to @file{one}. When archiving this
9441 directory with a verbose level 2, you will get an output similar to
9442 the following:
9443
9444 @smallexample
9445 $ tar cvvf ../archive.tar .
9446 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9447 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9448 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
9449 @end smallexample
9450
9451 The last line shows that, instead of storing two copies of the file,
9452 @command{tar} stored it only once, under the name @file{jeden}, and
9453 stored file @file{one} as a hard link to this file.
9454
9455 It may be important to know that all hard links to the given file are
9456 stored in the archive. For example, this may be necessary for exact
9457 reproduction of the file system. The following option does that:
9458
9459 @table @option
9460 @xopindex{check-links, described}
9461 @item --check-links
9462 @itemx -l
9463 Check the number of links dumped for each processed file. If this
9464 number does not match the total number of hard links for the file, print
9465 a warning message.
9466 @end table
9467
9468 For example, trying to archive only file @file{jeden} with this option
9469 produces the following diagnostics:
9470
9471 @smallexample
9472 $ tar -c -f ../archive.tar -l jeden
9473 tar: Missing links to 'jeden'.
9474 @end smallexample
9475
9476 Although creating special records for hard links helps keep a faithful
9477 record of the file system contents and makes archives more compact, it
9478 may present some difficulties when extracting individual members from
9479 the archive. For example, trying to extract file @file{one} from the
9480 archive created in previous examples produces, in the absense of file
9481 @file{jeden}:
9482
9483 @smallexample
9484 $ tar xf archive.tar ./one
9485 tar: ./one: Cannot hard link to './jeden': No such file or directory
9486 tar: Error exit delayed from previous errors
9487 @end smallexample
9488
9489 The reason for this behavior is that @command{tar} cannot seek back in
9490 the archive to the previous member (in this case, @file{one}), to
9491 extract it@footnote{There are plans to fix this in future releases.}.
9492 If you wish to avoid such problems at the cost of a bigger archive,
9493 use the following option:
9494
9495 @table @option
9496 @xopindex{hard-dereference, described}
9497 @item --hard-dereference
9498 Dereference hard links and store the files they refer to.
9499 @end table
9500
9501 For example, trying this option on our two sample files, we get two
9502 copies in the archive, each of which can then be extracted
9503 independently of the other:
9504
9505 @smallexample
9506 @group
9507 $ tar -c -vv -f ../archive.tar --hard-dereference .
9508 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9509 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9510 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
9511 @end group
9512 @end smallexample
9513
9514 @node old
9515 @subsection Old V7 Archives
9516 @cindex Format, old style
9517 @cindex Old style format
9518 @cindex Old style archives
9519 @cindex v7 archive format
9520
9521 Certain old versions of @command{tar} cannot handle additional
9522 information recorded by newer @command{tar} programs. To create an
9523 archive in V7 format (not ANSI), which can be read by these old
9524 versions, specify the @option{--format=v7} option in
9525 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
9526 accepts @option{--portability} or @option{--old-archive} for this
9527 option). When you specify it,
9528 @command{tar} leaves out information about directories, pipes, fifos,
9529 contiguous files, and device files, and specifies file ownership by
9530 group and user IDs instead of group and user names.
9531
9532 When updating an archive, do not use @option{--format=v7}
9533 unless the archive was created using this option.
9534
9535 In most cases, a @emph{new} format archive can be read by an @emph{old}
9536 @command{tar} program without serious trouble, so this option should
9537 seldom be needed. On the other hand, most modern @command{tar}s are
9538 able to read old format archives, so it might be safer for you to
9539 always use @option{--format=v7} for your distributions. Notice,
9540 however, that @samp{ustar} format is a better alternative, as it is
9541 free from many of @samp{v7}'s drawbacks.
9542
9543 @node ustar
9544 @subsection Ustar Archive Format
9545
9546 @cindex ustar archive format
9547 Archive format defined by @acronym{POSIX}.1-1988 specification is called
9548 @code{ustar}. Although it is more flexible than the V7 format, it
9549 still has many restrictions (@pxref{Formats,ustar}, for the detailed
9550 description of @code{ustar} format). Along with V7 format,
9551 @code{ustar} format is a good choice for archives intended to be read
9552 with other implementations of @command{tar}.
9553
9554 To create archive in @code{ustar} format, use @option{--format=ustar}
9555 option in conjunction with the @option{--create} (@option{-c}).
9556
9557 @node gnu
9558 @subsection @acronym{GNU} and old @GNUTAR{} format
9559
9560 @cindex GNU archive format
9561 @cindex Old GNU archive format
9562 @GNUTAR{} was based on an early draft of the
9563 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
9564 @command{tar}, such as the support for file names longer than 100
9565 characters, use portions of the @command{tar} header record which were
9566 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
9567 @acronym{POSIX} have allocated the same parts of the header record for
9568 other purposes. As a result, @GNUTAR{} format is
9569 incompatible with the current @acronym{POSIX} specification, and with
9570 @command{tar} programs that follow it.
9571
9572 In the majority of cases, @command{tar} will be configured to create
9573 this format by default. This will change in future releases, since
9574 we plan to make @samp{POSIX} format the default.
9575
9576 To force creation a @GNUTAR{} archive, use option
9577 @option{--format=gnu}.
9578
9579 @node posix
9580 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
9581
9582 @cindex POSIX archive format
9583 @cindex PAX archive format
9584 Starting from version 1.14 @GNUTAR{} features full support for
9585 @acronym{POSIX.1-2001} archives.
9586
9587 A @acronym{POSIX} conformant archive will be created if @command{tar}
9588 was given @option{--format=posix} (@option{--format=pax}) option. No
9589 special option is required to read and extract from a @acronym{POSIX}
9590 archive.
9591
9592 @menu
9593 * PAX keywords:: Controlling Extended Header Keywords.
9594 @end menu
9595
9596 @node PAX keywords
9597 @subsubsection Controlling Extended Header Keywords
9598
9599 @table @option
9600 @opindex pax-option
9601 @item --pax-option=@var{keyword-list}
9602 Handle keywords in @acronym{PAX} extended headers. This option is
9603 equivalent to @option{-o} option of the @command{pax} utility.
9604 @end table
9605
9606 @var{Keyword-list} is a comma-separated
9607 list of keyword options, each keyword option taking one of
9608 the following forms:
9609
9610 @table @code
9611 @item delete=@var{pattern}
9612 When used with one of archive-creation commands,
9613 this option instructs @command{tar} to omit from extended header records
9614 that it produces any keywords matching the string @var{pattern}.
9615
9616 When used in extract or list mode, this option instructs tar
9617 to ignore any keywords matching the given @var{pattern} in the extended
9618 header records. In both cases, matching is performed using the pattern
9619 matching notation described in @acronym{POSIX 1003.2}, 3.13
9620 (@pxref{wildcards}). For example:
9621
9622 @smallexample
9623 --pax-option delete=security.*
9624 @end smallexample
9625
9626 would suppress security-related information.
9627
9628 @item exthdr.name=@var{string}
9629
9630 This keyword allows user control over the name that is written into the
9631 ustar header blocks for the extended headers. The name is obtained
9632 from @var{string} after making the following substitutions:
9633
9634 @multitable @columnfractions .25 .55
9635 @headitem Meta-character @tab Replaced By
9636 @item %d @tab The directory name of the file, equivalent to the
9637 result of the @command{dirname} utility on the translated file name.
9638 @item %f @tab The name of the file with the directory information
9639 stripped, equivalent to the result of the @command{basename} utility
9640 on the translated file name.
9641 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9642 @item %% @tab A @samp{%} character.
9643 @end multitable
9644
9645 Any other @samp{%} characters in @var{string} produce undefined
9646 results.
9647
9648 If no option @samp{exthdr.name=string} is specified, @command{tar}
9649 will use the following default value:
9650
9651 @smallexample
9652 %d/PaxHeaders.%p/%f
9653 @end smallexample
9654
9655 @item exthdr.mtime=@var{value}
9656
9657 This keyword defines the value of the @samp{mtime} field that
9658 is written into the ustar header blocks for the extended headers.
9659 By default, the @samp{mtime} field is set to the modification time
9660 of the archive member described by that extended headers.
9661
9662 @item globexthdr.name=@var{string}
9663 This keyword allows user control over the name that is written into
9664 the ustar header blocks for global extended header records. The name
9665 is obtained from the contents of @var{string}, after making
9666 the following substitutions:
9667
9668 @multitable @columnfractions .25 .55
9669 @headitem Meta-character @tab Replaced By
9670 @item %n @tab An integer that represents the
9671 sequence number of the global extended header record in the archive,
9672 starting at 1.
9673 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9674 @item %% @tab A @samp{%} character.
9675 @end multitable
9676
9677 Any other @samp{%} characters in @var{string} produce undefined results.
9678
9679 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9680 will use the following default value:
9681
9682 @smallexample
9683 $TMPDIR/GlobalHead.%p.%n
9684 @end smallexample
9685
9686 @noindent
9687 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9688 environment variable. If @var{TMPDIR} is not set, @command{tar}
9689 uses @samp{/tmp}.
9690
9691 @item globexthdr.mtime=@var{value}
9692
9693 This keyword defines the value of the @samp{mtime} field that
9694 is written into the ustar header blocks for the global extended headers.
9695 By default, the @samp{mtime} field is set to the time when
9696 @command{tar} was invoked.
9697
9698 @item @var{keyword}=@var{value}
9699 When used with one of archive-creation commands, these keyword/value pairs
9700 will be included at the beginning of the archive in a global extended
9701 header record. When used with one of archive-reading commands,
9702 @command{tar} will behave as if it has encountered these keyword/value
9703 pairs at the beginning of the archive in a global extended header
9704 record.
9705
9706 @item @var{keyword}:=@var{value}
9707 When used with one of archive-creation commands, these keyword/value pairs
9708 will be included as records at the beginning of an extended header for
9709 each file. This is effectively equivalent to @var{keyword}=@var{value}
9710 form except that it creates no global extended header records.
9711
9712 When used with one of archive-reading commands, @command{tar} will
9713 behave as if these keyword/value pairs were included as records at the
9714 end of each extended header; thus, they will override any global or
9715 file-specific extended header record keywords of the same names.
9716 For example, in the command:
9717
9718 @smallexample
9719 tar --format=posix --create \
9720 --file archive --pax-option gname:=user .
9721 @end smallexample
9722
9723 the group name will be forced to a new value for all files
9724 stored in the archive.
9725 @end table
9726
9727 In any of the forms described above, the @var{value} may be
9728 a string enclosed in curly braces. In that case, the string
9729 between the braces is understood either as a textual time
9730 representation, as described in @ref{Date input formats}, or a name of
9731 the existing file, starting with @samp{/} or @samp{.}. In the latter
9732 case, the modification time of that file is used.
9733
9734 For example, to set all modification times to the current date, you
9735 use the following option:
9736
9737 @smallexample
9738 --pax-option='mtime:=@{now@}'
9739 @end smallexample
9740
9741 Note quoting of the option's argument.
9742
9743 @cindex archives, binary equivalent
9744 @cindex binary equivalent archives, creating
9745 As another example, here is the option that ensures that any two
9746 archives created using it, will be binary equivalent if they have the
9747 same contents:
9748
9749 @smallexample
9750 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
9751 @end smallexample
9752
9753 @node Checksumming
9754 @subsection Checksumming Problems
9755
9756 SunOS and HP-UX @command{tar} fail to accept archives created using
9757 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9758 is, file names having characters with the eight bit set, because they
9759 use signed checksums, while @GNUTAR{} uses unsigned
9760 checksums while creating archives, as per @acronym{POSIX} standards. On
9761 reading, @GNUTAR{} computes both checksums and
9762 accepts any. It is somewhat worrying that a lot of people may go
9763 around doing backup of their files using faulty (or at least
9764 non-standard) software, not learning about it until it's time to
9765 restore their missing files with an incompatible file extractor, or
9766 vice versa.
9767
9768 @GNUTAR{} computes checksums both ways, and accept
9769 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9770 wrong checksums. @GNUTAR{} produces the standard
9771 checksum, however, raising incompatibilities with Sun. That is to
9772 say, @GNUTAR{} has not been modified to
9773 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9774 I've been told that more recent Sun @command{tar} now read standard
9775 archives, so maybe Sun did a similar patch, after all?
9776
9777 The story seems to be that when Sun first imported @command{tar}
9778 sources on their system, they recompiled it without realizing that
9779 the checksums were computed differently, because of a change in
9780 the default signing of @code{char}'s in their compiler. So they
9781 started computing checksums wrongly. When they later realized their
9782 mistake, they merely decided to stay compatible with it, and with
9783 themselves afterwards. Presumably, but I do not really know, HP-UX
9784 has chosen that their @command{tar} archives to be compatible with Sun's.
9785 The current standards do not favor Sun @command{tar} format. In any
9786 case, it now falls on the shoulders of SunOS and HP-UX users to get
9787 a @command{tar} able to read the good archives they receive.
9788
9789 @node Large or Negative Values
9790 @subsection Large or Negative Values
9791 @cindex large values
9792 @cindex future time stamps
9793 @cindex negative time stamps
9794 @UNREVISED
9795
9796 The above sections suggest to use @samp{oldest possible} archive
9797 format if in doubt. However, sometimes it is not possible. If you
9798 attempt to archive a file whose metadata cannot be represented using
9799 required format, @GNUTAR{} will print error message and ignore such a
9800 file. You will than have to switch to a format that is able to
9801 handle such values. The format summary table (@pxref{Formats}) will
9802 help you to do so.
9803
9804 In particular, when trying to archive files larger than 8GB or with
9805 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9806 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9807 @acronym{POSIX} archive formats. When considering which format to
9808 choose, bear in mind that the @acronym{GNU} format uses
9809 two's-complement base-256 notation to store values that do not fit
9810 into standard @acronym{ustar} range. Such archives can generally be
9811 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9812 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9813 example, using two's complement representation for negative time
9814 stamps that assumes a signed 32-bit @code{time_t} generates archives
9815 that are not portable to hosts with differing @code{time_t}
9816 representations.
9817
9818 On the other hand, @acronym{POSIX} archives, generally speaking, can
9819 be extracted by any tar implementation that understands older
9820 @acronym{ustar} format. The only exception are files larger than 8GB.
9821
9822 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9823 POSIX-aware tars.}
9824
9825 @node Other Tars
9826 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9827
9828 In previous sections you became acquainted with various quirks
9829 necessary to make your archives portable. Sometimes you may need to
9830 extract archives containing GNU-specific members using some
9831 third-party @command{tar} implementation or an older version of
9832 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9833 but if it is for some reason impossible, this section will explain
9834 how to cope without it.
9835
9836 When we speak about @dfn{GNU-specific} members we mean two classes of
9837 them: members split between the volumes of a multi-volume archive and
9838 sparse members. You will be able to always recover such members if
9839 the archive is in PAX format. In addition split members can be
9840 recovered from archives in old GNU format. The following subsections
9841 describe the required procedures in detail.
9842
9843 @menu
9844 * Split Recovery:: Members Split Between Volumes
9845 * Sparse Recovery:: Sparse Members
9846 @end menu
9847
9848 @node Split Recovery
9849 @subsubsection Extracting Members Split Between Volumes
9850
9851 @cindex Mutli-volume archives, extracting using non-GNU tars
9852 If a member is split between several volumes of an old GNU format archive
9853 most third party @command{tar} implementation will fail to extract
9854 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9855 This program is available from
9856 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9857 home page}. It concatenates several archive volumes into a single
9858 valid archive. For example, if you have three volumes named from
9859 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9860 extract them using a third-party @command{tar}:
9861
9862 @smallexample
9863 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9864 @end smallexample
9865
9866 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9867 You could use this approach for most (although not all) PAX
9868 format archives as well. However, extracting split members from a PAX
9869 archive is a much easier task, because PAX volumes are constructed in
9870 such a way that each part of a split member is extracted to a
9871 different file by @command{tar} implementations that are not aware of
9872 GNU extensions. More specifically, the very first part retains its
9873 original name, and all subsequent parts are named using the pattern:
9874
9875 @smallexample
9876 %d/GNUFileParts.%p/%f.%n
9877 @end smallexample
9878
9879 @noindent
9880 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9881 have the following meaning:
9882
9883 @multitable @columnfractions .25 .55
9884 @headitem Meta-character @tab Replaced By
9885 @item %d @tab The directory name of the file, equivalent to the
9886 result of the @command{dirname} utility on its full name.
9887 @item %f @tab The file name of the file, equivalent to the result
9888 of the @command{basename} utility on its full name.
9889 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9890 created the archive.
9891 @item %n @tab Ordinal number of this particular part.
9892 @end multitable
9893
9894 For example, if the file @file{var/longfile} was split during archive
9895 creation between three volumes, and the creator @command{tar} process
9896 had process @acronym{ID} @samp{27962}, then the member names will be:
9897
9898 @smallexample
9899 var/longfile
9900 var/GNUFileParts.27962/longfile.1
9901 var/GNUFileParts.27962/longfile.2
9902 @end smallexample
9903
9904 When you extract your archive using a third-party @command{tar}, these
9905 files will be created on your disk, and the only thing you will need
9906 to do to restore your file in its original form is concatenate them in
9907 the proper order, for example:
9908
9909 @smallexample
9910 @group
9911 $ @kbd{cd var}
9912 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9913 GNUFileParts.27962/longfile.2 >> longfile}
9914 $ rm -f GNUFileParts.27962
9915 @end group
9916 @end smallexample
9917
9918 Notice, that if the @command{tar} implementation you use supports PAX
9919 format archives, it will probably emit warnings about unknown keywords
9920 during extraction. They will look like this:
9921
9922 @smallexample
9923 @group
9924 Tar file too small
9925 Unknown extended header keyword 'GNU.volume.filename' ignored.
9926 Unknown extended header keyword 'GNU.volume.size' ignored.
9927 Unknown extended header keyword 'GNU.volume.offset' ignored.
9928 @end group
9929 @end smallexample
9930
9931 @noindent
9932 You can safely ignore these warnings.
9933
9934 If your @command{tar} implementation is not PAX-aware, you will get
9935 more warnings and more files generated on your disk, e.g.:
9936
9937 @smallexample
9938 @group
9939 $ @kbd{tar xf vol-1.tar}
9940 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9941 normal file
9942 Unexpected EOF in archive
9943 $ @kbd{tar xf vol-2.tar}
9944 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9945 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9946 'x', extracted as normal file
9947 @end group
9948 @end smallexample
9949
9950 Ignore these warnings. The @file{PaxHeaders.*} directories created
9951 will contain files with @dfn{extended header keywords} describing the
9952 extracted files. You can delete them, unless they describe sparse
9953 members. Read further to learn more about them.
9954
9955 @node Sparse Recovery
9956 @subsubsection Extracting Sparse Members
9957
9958 @cindex sparse files, extracting with non-GNU tars
9959 Any @command{tar} implementation will be able to extract sparse members from a
9960 PAX archive. However, the extracted files will be @dfn{condensed},
9961 i.e., any zero blocks will be removed from them. When we restore such
9962 a condensed file to its original form, by adding zero blocks (or
9963 @dfn{holes}) back to their original locations, we call this process
9964 @dfn{expanding} a compressed sparse file.
9965
9966 @pindex xsparse
9967 To expand a file, you will need a simple auxiliary program called
9968 @command{xsparse}. It is available in source form from
9969 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9970 home page}.
9971
9972 @cindex sparse files v.1.0, extracting with non-GNU tars
9973 Let's begin with archive members in @dfn{sparse format
9974 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9975 The condensed file will contain both file map and file data, so no
9976 additional data will be needed to restore it. If the original file
9977 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9978 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9979 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
9980 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9981 archive (@pxref{PAX keywords}).}.
9982
9983 To expand a version 1.0 file, run @command{xsparse} as follows:
9984
9985 @smallexample
9986 $ @kbd{xsparse @file{cond-file}}
9987 @end smallexample
9988
9989 @noindent
9990 where @file{cond-file} is the name of the condensed file. The utility
9991 will deduce the name for the resulting expanded file using the
9992 following algorithm:
9993
9994 @enumerate 1
9995 @item If @file{cond-file} does not contain any directories,
9996 @file{../cond-file} will be used;
9997
9998 @item If @file{cond-file} has the form
9999 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10000 are simple names, with no @samp{/} characters in them, the output file
10001 name will be @file{@var{dir}/@var{name}}.
10002
10003 @item Otherwise, if @file{cond-file} has the form
10004 @file{@var{dir}/@var{name}}, the output file name will be
10005 @file{@var{name}}.
10006 @end enumerate
10007
10008 In the unlikely case when this algorithm does not suit your needs,
10009 you can explicitly specify output file name as a second argument to
10010 the command:
10011
10012 @smallexample
10013 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10014 @end smallexample
10015
10016 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10017 first. In this mode, the command does not actually expand the file,
10018 but verbosely lists all actions it would be taking to do so. The dry
10019 run mode is enabled by @option{-n} command line argument:
10020
10021 @smallexample
10022 @group
10023 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10024 Reading v.1.0 sparse map
10025 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10026 '/home/gray/sparsefile'
10027 Finished dry run
10028 @end group
10029 @end smallexample
10030
10031 To actually expand the file, you would run:
10032
10033 @smallexample
10034 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10035 @end smallexample
10036
10037 @noindent
10038 The program behaves the same way all UNIX utilities do: it will keep
10039 quiet unless it has simething important to tell you (e.g. an error
10040 condition or something). If you wish it to produce verbose output,
10041 similar to that from the dry run mode, use @option{-v} option:
10042
10043 @smallexample
10044 @group
10045 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10046 Reading v.1.0 sparse map
10047 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10048 '/home/gray/sparsefile'
10049 Done
10050 @end group
10051 @end smallexample
10052
10053 Additionally, if your @command{tar} implementation has extracted the
10054 @dfn{extended headers} for this file, you can instruct @command{xstar}
10055 to use them in order to verify the integrity of the expanded file.
10056 The option @option{-x} sets the name of the extended header file to
10057 use. Continuing our example:
10058
10059 @smallexample
10060 @group
10061 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10062 /home/gray/GNUSparseFile.6058/sparsefile}
10063 Reading extended header file
10064 Found variable GNU.sparse.major = 1
10065 Found variable GNU.sparse.minor = 0
10066 Found variable GNU.sparse.name = sparsefile
10067 Found variable GNU.sparse.realsize = 217481216
10068 Reading v.1.0 sparse map
10069 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10070 '/home/gray/sparsefile'
10071 Done
10072 @end group
10073 @end smallexample
10074
10075 @anchor{extracting sparse v.0.x}
10076 @cindex sparse files v.0.1, extracting with non-GNU tars
10077 @cindex sparse files v.0.0, extracting with non-GNU tars
10078 An @dfn{extended header} is a special @command{tar} archive header
10079 that precedes an archive member and contains a set of
10080 @dfn{variables}, describing the member properties that cannot be
10081 stored in the standard @code{ustar} header. While optional for
10082 expanding sparse version 1.0 members, the use of extended headers is
10083 mandatory when expanding sparse members in older sparse formats: v.0.0
10084 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10085 Formats}.) So, for these formats, the question is: how to obtain
10086 extended headers from the archive?
10087
10088 If you use a @command{tar} implementation that does not support PAX
10089 format, extended headers for each member will be extracted as a
10090 separate file. If we represent the member name as
10091 @file{@var{dir}/@var{name}}, then the extended header file will be
10092 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10093 @var{n} is an integer number.
10094
10095 Things become more difficult if your @command{tar} implementation
10096 does support PAX headers, because in this case you will have to
10097 manually extract the headers. We recommend the following algorithm:
10098
10099 @enumerate 1
10100 @item
10101 Consult the documentation of your @command{tar} implementation for an
10102 option that prints @dfn{block numbers} along with the archive
10103 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
10104 @command{star} has @option{-block-number}.
10105
10106 @item
10107 Obtain verbose listing using the @samp{block number} option, and
10108 find block numbers of the sparse member in question and the member
10109 immediately following it. For example, running @command{star} on our
10110 archive we obtain:
10111
10112 @smallexample
10113 @group
10114 $ @kbd{star -t -v -block-number -f arc.tar}
10115 @dots{}
10116 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10117 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10118 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10119 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10120 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10121 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
10122 @dots{}
10123 @end group
10124 @end smallexample
10125
10126 @noindent
10127 (as usual, ignore the warnings about unknown keywords.)
10128
10129 @item
10130 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10131 and @var{Bn} be the block number of the next member.
10132 Compute:
10133
10134 @smallexample
10135 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10136 @end smallexample
10137
10138 @noindent
10139 This number gives the size of the extended header part in tar @dfn{blocks}.
10140 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10141 = 7}.
10142
10143 @item
10144 Use @command{dd} to extract the headers:
10145
10146 @smallexample
10147 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10148 @end smallexample
10149
10150 @noindent
10151 where @var{archive} is the archive name, @var{hname} is a name of the
10152 file to store the extended header in, @var{Bs} and @var{N} are
10153 computed in previous steps.
10154
10155 In our example, this command will be
10156
10157 @smallexample
10158 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10159 @end smallexample
10160 @end enumerate
10161
10162 Finally, you can expand the condensed file, using the obtained header:
10163
10164 @smallexample
10165 @group
10166 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10167 Reading extended header file
10168 Found variable GNU.sparse.size = 217481216
10169 Found variable GNU.sparse.numblocks = 208
10170 Found variable GNU.sparse.name = sparsefile
10171 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10172 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
10173 Done
10174 @end group
10175 @end smallexample
10176
10177 @node cpio
10178 @section Comparison of @command{tar} and @command{cpio}
10179 @UNREVISED
10180
10181 @FIXME{Reorganize the following material}
10182
10183 The @command{cpio} archive formats, like @command{tar}, do have maximum
10184 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
10185 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
10186 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
10187 with arbitrary file name lengths, but other @command{cpio} implementations
10188 may crash unexplainedly trying to read them.
10189
10190 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
10191 @command{cpio} doesn't handle symbolic links in the form in which it comes
10192 in System V prior to SVR4, and some vendors may have added symlinks
10193 to their system without enhancing @command{cpio} to know about them.
10194 Others may have enhanced it in a way other than the way I did it
10195 at Sun, and which was adopted by AT&T (and which is, I think, also
10196 present in the @command{cpio} that Berkeley picked up from AT&T and put
10197 into a later @acronym{BSD} release---I think I gave them my changes).
10198
10199 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
10200 can handle @command{tar} format input, and write it on output, and it
10201 probably handles symbolic links. They may not have bothered doing
10202 anything to enhance @command{tar} as a result.)
10203
10204 @command{cpio} handles special files; traditional @command{tar} doesn't.
10205
10206 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
10207 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
10208 (4.3-tahoe and later).
10209
10210 @command{tar}'s way of handling multiple hard links to a file can handle
10211 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
10212 @command{cpio}s way requires you to play some games (in its ``binary''
10213 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
10214 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
10215 field of the header to make sure that the file system @acronym{ID}/i-number pairs
10216 of different files were always different), and I don't know which
10217 @command{cpio}s, if any, play those games. Those that don't might get
10218 confused and think two files are the same file when they're not, and
10219 make hard links between them.
10220
10221 @command{tar}s way of handling multiple hard links to a file places only
10222 one copy of the link on the tape, but the name attached to that copy
10223 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
10224 way puts one copy for every link, but you can retrieve it using any
10225 of the names.
10226
10227 @quotation
10228 What type of check sum (if any) is used, and how is this calculated.
10229 @end quotation
10230
10231 See the attached manual pages for @command{tar} and @command{cpio} format.
10232 @command{tar} uses a checksum which is the sum of all the bytes in the
10233 @command{tar} header for a file; @command{cpio} uses no checksum.
10234
10235 @quotation
10236 If anyone knows why @command{cpio} was made when @command{tar} was present
10237 at the unix scene,
10238 @end quotation
10239
10240 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
10241 generally-available version of UNIX had @command{tar} at the time. I don't
10242 know whether any version that was generally available @emph{within AT&T}
10243 had @command{tar}, or, if so, whether the people within AT&T who did
10244 @command{cpio} knew about it.
10245
10246 On restore, if there is a corruption on a tape @command{tar} will stop at
10247 that point, while @command{cpio} will skip over it and try to restore the
10248 rest of the files.
10249
10250 The main difference is just in the command syntax and header format.
10251
10252 @command{tar} is a little more tape-oriented in that everything is blocked
10253 to start on a record boundary.
10254
10255 @quotation
10256 Is there any differences between the ability to recover crashed
10257 archives between the two of them. (Is there any chance of recovering
10258 crashed archives at all.)
10259 @end quotation
10260
10261 Theoretically it should be easier under @command{tar} since the blocking
10262 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
10263 However, modern @command{cpio}'s and variations have an option to just
10264 search for the next file header after an error with a reasonable chance
10265 of resyncing. However, lots of tape driver software won't allow you to
10266 continue past a media error which should be the only reason for getting
10267 out of sync unless a file changed sizes while you were writing the
10268 archive.
10269
10270 @quotation
10271 If anyone knows why @command{cpio} was made when @command{tar} was present
10272 at the unix scene, please tell me about this too.
10273 @end quotation
10274
10275 Probably because it is more media efficient (by not blocking everything
10276 and using only the space needed for the headers where @command{tar}
10277 always uses 512 bytes per file header) and it knows how to archive
10278 special files.
10279
10280 You might want to look at the freely available alternatives. The
10281 major ones are @command{afio}, @GNUTAR{}, and
10282 @command{pax}, each of which have their own extensions with some
10283 backwards compatibility.
10284
10285 Sparse files were @command{tar}red as sparse files (which you can
10286 easily test, because the resulting archive gets smaller, and
10287 @acronym{GNU} @command{cpio} can no longer read it).
10288
10289 @node Media
10290 @chapter Tapes and Other Archive Media
10291 @UNREVISED
10292
10293 A few special cases about tape handling warrant more detailed
10294 description. These special cases are discussed below.
10295
10296 Many complexities surround the use of @command{tar} on tape drives. Since
10297 the creation and manipulation of archives located on magnetic tape was
10298 the original purpose of @command{tar}, it contains many features making
10299 such manipulation easier.
10300
10301 Archives are usually written on dismountable media---tape cartridges,
10302 mag tapes, or floppy disks.
10303
10304 The amount of data a tape or disk holds depends not only on its size,
10305 but also on how it is formatted. A 2400 foot long reel of mag tape
10306 holds 40 megabytes of data when formatted at 1600 bits per inch. The
10307 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
10308
10309 Magnetic media are re-usable---once the archive on a tape is no longer
10310 needed, the archive can be erased and the tape or disk used over.
10311 Media quality does deteriorate with use, however. Most tapes or disks
10312 should be discarded when they begin to produce data errors. EXABYTE
10313 tape cartridges should be discarded when they generate an @dfn{error
10314 count} (number of non-usable bits) of more than 10k.
10315
10316 Magnetic media are written and erased using magnetic fields, and
10317 should be protected from such fields to avoid damage to stored data.
10318 Sticking a floppy disk to a filing cabinet using a magnet is probably
10319 not a good idea.
10320
10321 @menu
10322 * Device:: Device selection and switching
10323 * Remote Tape Server::
10324 * Common Problems and Solutions::
10325 * Blocking:: Blocking
10326 * Many:: Many archives on one tape
10327 * Using Multiple Tapes:: Using Multiple Tapes
10328 * label:: Including a Label in the Archive
10329 * verify::
10330 * Write Protection::
10331 @end menu
10332
10333 @node Device
10334 @section Device Selection and Switching
10335 @UNREVISED
10336
10337 @table @option
10338 @item -f [@var{hostname}:]@var{file}
10339 @itemx --file=[@var{hostname}:]@var{file}
10340 Use archive file or device @var{file} on @var{hostname}.
10341 @end table
10342
10343 This option is used to specify the file name of the archive @command{tar}
10344 works on.
10345
10346 If the file name is @samp{-}, @command{tar} reads the archive from standard
10347 input (when listing or extracting), or writes it to standard output
10348 (when creating). If the @samp{-} file name is given when updating an
10349 archive, @command{tar} will read the original archive from its standard
10350 input, and will write the entire new archive to its standard output.
10351
10352 If the file name contains a @samp{:}, it is interpreted as
10353 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
10354 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
10355 either case, @command{tar} will invoke the command @command{rsh} (or
10356 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
10357 machine. If you give an alternate login name, it will be given to the
10358 @command{rsh}.
10359 Naturally, the remote machine must have an executable
10360 @command{/usr/libexec/rmt}. This program is free software from the
10361 University of California, and a copy of the source code can be found
10362 with the sources for @command{tar}; it's compiled and installed by default.
10363 The exact path to this utility is determined when configuring the package.
10364 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
10365 your installation prefix. This location may also be overridden at
10366 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
10367 ---rmt-command}, for detailed description of this option. @xref{Remote
10368 Tape Server}, for the description of @command{rmt} command).
10369
10370 If this option is not given, but the environment variable @env{TAPE}
10371 is set, its value is used; otherwise, old versions of @command{tar}
10372 used a default archive name (which was picked when @command{tar} was
10373 compiled). The default is normally set up to be the @dfn{first} tape
10374 drive or other transportable I/O medium on the system.
10375
10376 Starting with version 1.11.5, @GNUTAR{} uses
10377 standard input and standard output as the default device, and I will
10378 not try anymore supporting automatic device detection at installation
10379 time. This was failing really in too many cases, it was hopeless.
10380 This is now completely left to the installer to override standard
10381 input and standard output for default device, if this seems
10382 preferable. Further, I think @emph{most} actual usages of
10383 @command{tar} are done with pipes or disks, not really tapes,
10384 cartridges or diskettes.
10385
10386 Some users think that using standard input and output is running
10387 after trouble. This could lead to a nasty surprise on your screen if
10388 you forget to specify an output file name---especially if you are going
10389 through a network or terminal server capable of buffering large amounts
10390 of output. We had so many bug reports in that area of configuring
10391 default tapes automatically, and so many contradicting requests, that
10392 we finally consider the problem to be portably intractable. We could
10393 of course use something like @samp{/dev/tape} as a default, but this
10394 is @emph{also} running after various kind of trouble, going from hung
10395 processes to accidental destruction of real tapes. After having seen
10396 all this mess, using standard input and output as a default really
10397 sounds like the only clean choice left, and a very useful one too.
10398
10399 @GNUTAR{} reads and writes archive in records, I
10400 suspect this is the main reason why block devices are preferred over
10401 character devices. Most probably, block devices are more efficient
10402 too. The installer could also check for @samp{DEFTAPE} in
10403 @file{<sys/mtio.h>}.
10404
10405 @table @option
10406 @xopindex{force-local, short description}
10407 @item --force-local
10408 Archive file is local even if it contains a colon.
10409
10410 @opindex rsh-command
10411 @item --rsh-command=@var{command}
10412 Use remote @var{command} instead of @command{rsh}. This option exists
10413 so that people who use something other than the standard @command{rsh}
10414 (e.g., a Kerberized @command{rsh}) can access a remote device.
10415
10416 When this command is not used, the shell command found when
10417 the @command{tar} program was installed is used instead. This is
10418 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
10419 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
10420 The installer may have overridden this by defining the environment
10421 variable @env{RSH} @emph{at installation time}.
10422
10423 @item -[0-7][lmh]
10424 Specify drive and density.
10425
10426 @xopindex{multi-volume, short description}
10427 @item -M
10428 @itemx --multi-volume
10429 Create/list/extract multi-volume archive.
10430
10431 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
10432 that may be larger than will fit on the medium used to hold it.
10433 @xref{Multi-Volume Archives}.
10434
10435 @xopindex{tape-length, short description}
10436 @item -L @var{num}
10437 @itemx --tape-length=@var{size}[@var{suf}]
10438 Change tape after writing @var{size} units of data. Unless @var{suf} is
10439 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
10440 1024} bytes. The following suffixes alter this behavior:
10441
10442 @float Table, size-suffixes
10443 @caption{Size Suffixes}
10444 @multitable @columnfractions 0.2 0.3 0.3
10445 @headitem Suffix @tab Units @tab Byte Equivalent
10446 @item b @tab Blocks @tab @var{size} x 512
10447 @item B @tab Kilobytes @tab @var{size} x 1024
10448 @item c @tab Bytes @tab @var{size}
10449 @item G @tab Gigabytes @tab @var{size} x 1024^3
10450 @item K @tab Kilobytes @tab @var{size} x 1024
10451 @item k @tab Kilobytes @tab @var{size} x 1024
10452 @item M @tab Megabytes @tab @var{size} x 1024^2
10453 @item P @tab Petabytes @tab @var{size} x 1024^5
10454 @item T @tab Terabytes @tab @var{size} x 1024^4
10455 @item w @tab Words @tab @var{size} x 2
10456 @end multitable
10457 @end float
10458
10459 This option might be useful when your tape drivers do not properly
10460 detect end of physical tapes. By being slightly conservative on the
10461 maximum tape length, you might avoid the problem entirely.
10462
10463 @xopindex{info-script, short description}
10464 @xopindex{new-volume-script, short description}
10465 @item -F @var{file}
10466 @itemx --info-script=@var{file}
10467 @itemx --new-volume-script=@var{file}
10468 Execute @file{file} at end of each tape. This implies
10469 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
10470 description of this option.
10471 @end table
10472
10473 @node Remote Tape Server
10474 @section Remote Tape Server
10475
10476 @cindex remote tape drive
10477 @pindex rmt
10478 In order to access the tape drive on a remote machine, @command{tar}
10479 uses the remote tape server written at the University of California at
10480 Berkeley. The remote tape server must be installed as
10481 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
10482 want to use. @command{tar} calls @command{rmt} by running an
10483 @command{rsh} or @command{remsh} to the remote machine, optionally
10484 using a different login name if one is supplied.
10485
10486 A copy of the source for the remote tape server is provided. Its
10487 source code can be freely distributed. It is compiled and
10488 installed by default.
10489
10490 @cindex absolute file names
10491 Unless you use the @option{--absolute-names} (@option{-P}) option,
10492 @GNUTAR{} will not allow you to create an archive that contains
10493 absolute file names (a file name beginning with @samp{/}.) If you try,
10494 @command{tar} will automatically remove the leading @samp{/} from the
10495 file names it stores in the archive. It will also type a warning
10496 message telling you what it is doing.
10497
10498 When reading an archive that was created with a different
10499 @command{tar} program, @GNUTAR{} automatically
10500 extracts entries in the archive which have absolute file names as if
10501 the file names were not absolute. This is an important feature. A
10502 visitor here once gave a @command{tar} tape to an operator to restore;
10503 the operator used Sun @command{tar} instead of @GNUTAR{},
10504 and the result was that it replaced large portions of
10505 our @file{/bin} and friends with versions from the tape; needless to
10506 say, we were unhappy about having to recover the file system from
10507 backup tapes.
10508
10509 For example, if the archive contained a file @file{/usr/bin/computoy},
10510 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
10511 relative to the current directory. If you want to extract the files in
10512 an archive to the same absolute names that they had when the archive
10513 was created, you should do a @samp{cd /} before extracting the files
10514 from the archive, or you should either use the @option{--absolute-names}
10515 option, or use the command @samp{tar -C / @dots{}}.
10516
10517 @cindex Ultrix 3.1 and write failure
10518 Some versions of Unix (Ultrix 3.1 is known to have this problem),
10519 can claim that a short write near the end of a tape succeeded,
10520 when it actually failed. This will result in the -M option not
10521 working correctly. The best workaround at the moment is to use a
10522 significantly larger blocking factor than the default 20.
10523
10524 In order to update an archive, @command{tar} must be able to backspace the
10525 archive in order to reread or rewrite a record that was just read (or
10526 written). This is currently possible only on two kinds of files: normal
10527 disk files (or any other file that can be backspaced with @samp{lseek}),
10528 and industry-standard 9-track magnetic tape (or any other kind of tape
10529 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
10530
10531 This means that the @option{--append}, @option{--concatenate}, and
10532 @option{--delete} commands will not work on any other kind of file.
10533 Some media simply cannot be backspaced, which means these commands and
10534 options will never be able to work on them. These non-backspacing
10535 media include pipes and cartridge tape drives.
10536
10537 Some other media can be backspaced, and @command{tar} will work on them
10538 once @command{tar} is modified to do so.
10539
10540 Archives created with the @option{--multi-volume}, @option{--label}, and
10541 @option{--incremental} (@option{-G}) options may not be readable by other version
10542 of @command{tar}. In particular, restoring a file that was split over
10543 a volume boundary will require some careful work with @command{dd}, if
10544 it can be done at all. Other versions of @command{tar} may also create
10545 an empty file whose name is that of the volume header. Some versions
10546 of @command{tar} may create normal files instead of directories archived
10547 with the @option{--incremental} (@option{-G}) option.
10548
10549 @node Common Problems and Solutions
10550 @section Some Common Problems and their Solutions
10551
10552 @ifclear PUBLISH
10553
10554 @format
10555 errors from system:
10556 permission denied
10557 no such file or directory
10558 not owner
10559
10560 errors from @command{tar}:
10561 directory checksum error
10562 header format error
10563
10564 errors from media/system:
10565 i/o error
10566 device busy
10567 @end format
10568
10569 @end ifclear
10570
10571 @node Blocking
10572 @section Blocking
10573 @cindex block
10574 @cindex record
10575
10576 @dfn{Block} and @dfn{record} terminology is rather confused, and it
10577 is also confusing to the expert reader. On the other hand, readers
10578 who are new to the field have a fresh mind, and they may safely skip
10579 the next two paragraphs, as the remainder of this manual uses those
10580 two terms in a quite consistent way.
10581
10582 John Gilmore, the writer of the public domain @command{tar} from which
10583 @GNUTAR{} was originally derived, wrote (June 1995):
10584
10585 @quotation
10586 The nomenclature of tape drives comes from IBM, where I believe
10587 they were invented for the IBM 650 or so. On IBM mainframes, what
10588 is recorded on tape are tape blocks. The logical organization of
10589 data is into records. There are various ways of putting records into
10590 blocks, including @code{F} (fixed sized records), @code{V} (variable
10591 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
10592 to a block), @code{VB} (variable size records, @var{n} to a block),
10593 @code{VSB} (variable spanned blocked: variable sized records that can
10594 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
10595 parameter specified this to the operating system.
10596
10597 The Unix man page on @command{tar} was totally confused about this.
10598 When I wrote @code{PD TAR}, I used the historically correct terminology
10599 (@command{tar} writes data records, which are grouped into blocks).
10600 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
10601 here), and now Fran@,{c}ois has migrated that terminology back
10602 into the source code too.
10603 @end quotation
10604
10605 The term @dfn{physical block} means the basic transfer chunk from or
10606 to a device, after which reading or writing may stop without anything
10607 being lost. In this manual, the term @dfn{block} usually refers to
10608 a disk physical block, @emph{assuming} that each disk block is 512
10609 bytes in length. It is true that some disk devices have different
10610 physical blocks, but @command{tar} ignore these differences in its own
10611 format, which is meant to be portable, so a @command{tar} block is always
10612 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
10613 The term @dfn{logical block} often represents the basic chunk of
10614 allocation of many disk blocks as a single entity, which the operating
10615 system treats somewhat atomically; this concept is only barely used
10616 in @GNUTAR{}.
10617
10618 The term @dfn{physical record} is another way to speak of a physical
10619 block, those two terms are somewhat interchangeable. In this manual,
10620 the term @dfn{record} usually refers to a tape physical block,
10621 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
10622 It is true that archives may be put on disk or used with pipes,
10623 but nevertheless, @command{tar} tries to read and write the archive one
10624 @dfn{record} at a time, whatever the medium in use. One record is made
10625 up of an integral number of blocks, and this operation of putting many
10626 disk blocks into a single tape block is called @dfn{reblocking}, or
10627 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
10628 the logical organization of many characters into something meaningful
10629 to the application. The term @dfn{unit record} describes a small set
10630 of characters which are transmitted whole to or by the application,
10631 and often refers to a line of text. Those two last terms are unrelated
10632 to what we call a @dfn{record} in @GNUTAR{}.
10633
10634 When writing to tapes, @command{tar} writes the contents of the archive
10635 in chunks known as @dfn{records}. To change the default blocking
10636 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
10637 @var{512-size}}) option. Each record will then be composed of
10638 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
10639 @xref{Standard}.) Each file written to the archive uses at least one
10640 full record. As a result, using a larger record size can result in
10641 more wasted space for small files. On the other hand, a larger record
10642 size can often be read and written much more efficiently.
10643
10644 Further complicating the problem is that some tape drives ignore the
10645 blocking entirely. For these, a larger record size can still improve
10646 performance (because the software layers above the tape drive still
10647 honor the blocking), but not as dramatically as on tape drives that
10648 honor blocking.
10649
10650 When reading an archive, @command{tar} can usually figure out the
10651 record size on itself. When this is the case, and a non-standard
10652 record size was used when the archive was created, @command{tar} will
10653 print a message about a non-standard blocking factor, and then operate
10654 normally. On some tape devices, however, @command{tar} cannot figure
10655 out the record size itself. On most of those, you can specify a
10656 blocking factor (with @option{--blocking-factor}) larger than the
10657 actual blocking factor, and then use the @option{--read-full-records}
10658 (@option{-B}) option. (If you specify a blocking factor with
10659 @option{--blocking-factor} and don't use the
10660 @option{--read-full-records} option, then @command{tar} will not
10661 attempt to figure out the recording size itself.) On some devices,
10662 you must always specify the record size exactly with
10663 @option{--blocking-factor} when reading, because @command{tar} cannot
10664 figure it out. In any case, use @option{--list} (@option{-t}) before
10665 doing any extractions to see whether @command{tar} is reading the archive
10666 correctly.
10667
10668 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
10669 putting them into records is to put a whole number of them (one or
10670 more) into each record. @command{tar} records are all the same size;
10671 at the end of the file there's a block containing all zeros, which
10672 is how you tell that the remainder of the last record(s) are garbage.
10673
10674 In a standard @command{tar} file (no options), the block size is 512
10675 and the record size is 10240, for a blocking factor of 20. What the
10676 @option{--blocking-factor} option does is sets the blocking factor,
10677 changing the record size while leaving the block size at 512 bytes.
10678 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
10679 most tape drives these days prefer much bigger records in order to
10680 stream and not waste tape. When writing tapes for myself, some tend
10681 to use a factor of the order of 2048, say, giving a record size of
10682 around one megabyte.
10683
10684 If you use a blocking factor larger than 20, older @command{tar}
10685 programs might not be able to read the archive, so we recommend this
10686 as a limit to use in practice. @GNUTAR{}, however,
10687 will support arbitrarily large record sizes, limited only by the
10688 amount of virtual memory or the physical characteristics of the tape
10689 device.
10690
10691 @menu
10692 * Format Variations:: Format Variations
10693 * Blocking Factor:: The Blocking Factor of an Archive
10694 @end menu
10695
10696 @node Format Variations
10697 @subsection Format Variations
10698 @cindex Format Parameters
10699 @cindex Format Options
10700 @cindex Options, archive format specifying
10701 @cindex Options, format specifying
10702 @UNREVISED
10703
10704 Format parameters specify how an archive is written on the archive
10705 media. The best choice of format parameters will vary depending on
10706 the type and number of files being archived, and on the media used to
10707 store the archive.
10708
10709 To specify format parameters when accessing or creating an archive,
10710 you can use the options described in the following sections.
10711 If you do not specify any format parameters, @command{tar} uses
10712 default parameters. You cannot modify a compressed archive.
10713 If you create an archive with the @option{--blocking-factor} option
10714 specified (@pxref{Blocking Factor}), you must specify that
10715 blocking-factor when operating on the archive. @xref{Formats}, for other
10716 examples of format parameter considerations.
10717
10718 @node Blocking Factor
10719 @subsection The Blocking Factor of an Archive
10720 @cindex Blocking Factor
10721 @cindex Record Size
10722 @cindex Number of blocks per record
10723 @cindex Number of bytes per record
10724 @cindex Bytes per record
10725 @cindex Blocks per record
10726 @UNREVISED
10727
10728 @opindex blocking-factor
10729 The data in an archive is grouped into blocks, which are 512 bytes.
10730 Blocks are read and written in whole number multiples called
10731 @dfn{records}. The number of blocks in a record (i.e., the size of a
10732 record in units of 512 bytes) is called the @dfn{blocking factor}.
10733 The @option{--blocking-factor=@var{512-size}} (@option{-b
10734 @var{512-size}}) option specifies the blocking factor of an archive.
10735 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10736 can be specified at installation. To find out the blocking factor of
10737 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10738 This may not work on some devices.
10739
10740 Records are separated by gaps, which waste space on the archive media.
10741 If you are archiving on magnetic tape, using a larger blocking factor
10742 (and therefore larger records) provides faster throughput and allows you
10743 to fit more data on a tape (because there are fewer gaps). If you are
10744 archiving on cartridge, a very large blocking factor (say 126 or more)
10745 greatly increases performance. A smaller blocking factor, on the other
10746 hand, may be useful when archiving small files, to avoid archiving lots
10747 of nulls as @command{tar} fills out the archive to the end of the record.
10748 In general, the ideal record size depends on the size of the
10749 inter-record gaps on the tape you are using, and the average size of the
10750 files you are archiving. @xref{create}, for information on
10751 writing archives.
10752
10753 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10754
10755 Archives with blocking factors larger than 20 cannot be read
10756 by very old versions of @command{tar}, or by some newer versions
10757 of @command{tar} running on old machines with small address spaces.
10758 With @GNUTAR{}, the blocking factor of an archive is limited
10759 only by the maximum record size of the device containing the archive,
10760 or by the amount of available virtual memory.
10761
10762 Also, on some systems, not using adequate blocking factors, as sometimes
10763 imposed by the device drivers, may yield unexpected diagnostics. For
10764 example, this has been reported:
10765
10766 @smallexample
10767 Cannot write to /dev/dlt: Invalid argument
10768 @end smallexample
10769
10770 @noindent
10771 In such cases, it sometimes happen that the @command{tar} bundled by
10772 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10773 requires an explicit specification for the block size,
10774 which it cannot guess. This yields some people to consider
10775 @GNUTAR{} is misbehaving, because by comparison,
10776 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10777 for example, might resolve the problem.
10778
10779 If you use a non-default blocking factor when you create an archive, you
10780 must specify the same blocking factor when you modify that archive. Some
10781 archive devices will also require you to specify the blocking factor when
10782 reading that archive, however this is not typically the case. Usually, you
10783 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10784 reports a non-default record size and then lists the archive members as
10785 it would normally. To extract files from an archive with a non-standard
10786 blocking factor (particularly if you're not sure what the blocking factor
10787 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10788 specifying a blocking factor larger then the blocking factor of the archive
10789 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
10790 @xref{list}, for more information on the @option{--list} (@option{-t})
10791 operation. @xref{Reading}, for a more detailed explanation of that option.
10792
10793 @table @option
10794 @item --blocking-factor=@var{number}
10795 @itemx -b @var{number}
10796 Specifies the blocking factor of an archive. Can be used with any
10797 operation, but is usually not necessary with @option{--list} (@option{-t}).
10798 @end table
10799
10800 Device blocking
10801
10802 @table @option
10803 @item -b @var{blocks}
10804 @itemx --blocking-factor=@var{blocks}
10805 Set record size to @math{@var{blocks}*512} bytes.
10806
10807 This option is used to specify a @dfn{blocking factor} for the archive.
10808 When reading or writing the archive, @command{tar}, will do reads and writes
10809 of the archive in records of @math{@var{block}*512} bytes. This is true
10810 even when the archive is compressed. Some devices requires that all
10811 write operations be a multiple of a certain size, and so, @command{tar}
10812 pads the archive out to the next record boundary.
10813
10814 The default blocking factor is set when @command{tar} is compiled, and is
10815 typically 20. Blocking factors larger than 20 cannot be read by very
10816 old versions of @command{tar}, or by some newer versions of @command{tar}
10817 running on old machines with small address spaces.
10818
10819 With a magnetic tape, larger records give faster throughput and fit
10820 more data on a tape (because there are fewer inter-record gaps).
10821 If the archive is in a disk file or a pipe, you may want to specify
10822 a smaller blocking factor, since a large one will result in a large
10823 number of null bytes at the end of the archive.
10824
10825 When writing cartridge or other streaming tapes, a much larger
10826 blocking factor (say 126 or more) will greatly increase performance.
10827 However, you must specify the same blocking factor when reading or
10828 updating the archive.
10829
10830 Apparently, Exabyte drives have a physical block size of 8K bytes.
10831 If we choose our blocksize as a multiple of 8k bytes, then the problem
10832 seems to disappear. Id est, we are using block size of 112 right
10833 now, and we haven't had the problem since we switched@dots{}
10834
10835 With @GNUTAR{} the blocking factor is limited only
10836 by the maximum record size of the device containing the archive, or by
10837 the amount of available virtual memory.
10838
10839 However, deblocking or reblocking is virtually avoided in a special
10840 case which often occurs in practice, but which requires all the
10841 following conditions to be simultaneously true:
10842 @itemize @bullet
10843 @item
10844 the archive is subject to a compression option,
10845 @item
10846 the archive is not handled through standard input or output, nor
10847 redirected nor piped,
10848 @item
10849 the archive is directly handled to a local disk, instead of any special
10850 device,
10851 @item
10852 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10853 invocation.
10854 @end itemize
10855
10856 If the output goes directly to a local disk, and not through
10857 stdout, then the last write is not extended to a full record size.
10858 Otherwise, reblocking occurs. Here are a few other remarks on this
10859 topic:
10860
10861 @itemize @bullet
10862
10863 @item
10864 @command{gzip} will complain about trailing garbage if asked to
10865 uncompress a compressed archive on tape, there is an option to turn
10866 the message off, but it breaks the regularity of simply having to use
10867 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10868 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10869 Gailly, by sending a copy of this message to him.
10870
10871 @item
10872 @command{compress} does not show this problem, but as Jean-loup pointed
10873 out to Michael, @samp{compress -d} silently adds garbage after
10874 the result of decompression, which tar ignores because it already
10875 recognized its end-of-file indicator. So this bug may be safely
10876 ignored.
10877
10878 @item
10879 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10880 but will still return an exit status of 2 which tar reports in turn.
10881 @command{tar} might ignore the exit status returned, but I hate doing
10882 that, as it weakens the protection @command{tar} offers users against
10883 other possible problems at decompression time. If @command{gzip} was
10884 silently skipping trailing zeros @emph{and} also avoiding setting the
10885 exit status in this innocuous case, that would solve this situation.
10886
10887 @item
10888 @command{tar} should become more solid at not stopping to read a pipe at
10889 the first null block encountered. This inelegantly breaks the pipe.
10890 @command{tar} should rather drain the pipe out before exiting itself.
10891 @end itemize
10892
10893 @xopindex{ignore-zeros, short description}
10894 @item -i
10895 @itemx --ignore-zeros
10896 Ignore blocks of zeros in archive (means EOF).
10897
10898 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10899 of zeros in the archive. Normally a block of zeros indicates the
10900 end of the archive, but when reading a damaged archive, or one which
10901 was created by concatenating several archives together, this option
10902 allows @command{tar} to read the entire archive. This option is not on
10903 by default because many versions of @command{tar} write garbage after
10904 the zeroed blocks.
10905
10906 Note that this option causes @command{tar} to read to the end of the
10907 archive file, which may sometimes avoid problems when multiple files
10908 are stored on a single physical tape.
10909
10910 @xopindex{read-full-records, short description}
10911 @item -B
10912 @itemx --read-full-records
10913 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10914
10915 If @option{--read-full-records} is used, @command{tar}
10916 will not panic if an attempt to read a record from the archive does
10917 not return a full record. Instead, @command{tar} will keep reading
10918 until it has obtained a full
10919 record.
10920
10921 This option is turned on by default when @command{tar} is reading
10922 an archive from standard input, or from a remote machine. This is
10923 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10924 much happens to be in the pipe, even if it is less than @command{tar}
10925 requested. If this option was not used, @command{tar} would fail as
10926 soon as it read an incomplete record from the pipe.
10927
10928 This option is also useful with the commands for updating an archive.
10929
10930 @end table
10931
10932 Tape blocking
10933
10934 @FIXME{Appropriate options should be moved here from elsewhere.}
10935
10936 @cindex blocking factor
10937 @cindex tape blocking
10938
10939 When handling various tapes or cartridges, you have to take care of
10940 selecting a proper blocking, that is, the number of disk blocks you
10941 put together as a single tape block on the tape, without intervening
10942 tape gaps. A @dfn{tape gap} is a small landing area on the tape
10943 with no information on it, used for decelerating the tape to a
10944 full stop, and for later regaining the reading or writing speed.
10945 When the tape driver starts reading a record, the record has to
10946 be read whole without stopping, as a tape gap is needed to stop the
10947 tape motion without losing information.
10948
10949 @cindex Exabyte blocking
10950 @cindex DAT blocking
10951 Using higher blocking (putting more disk blocks per tape block) will use
10952 the tape more efficiently as there will be less tape gaps. But reading
10953 such tapes may be more difficult for the system, as more memory will be
10954 required to receive at once the whole record. Further, if there is a
10955 reading error on a huge record, this is less likely that the system will
10956 succeed in recovering the information. So, blocking should not be too
10957 low, nor it should be too high. @command{tar} uses by default a blocking of
10958 20 for historical reasons, and it does not really matter when reading or
10959 writing to disk. Current tape technology would easily accommodate higher
10960 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10961 We were told that for some DLT drives, the blocking should be a multiple
10962 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10963 Other manufacturers may use different recommendations for the same tapes.
10964 This might also depends of the buffering techniques used inside modern
10965 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
10966 Others request blocking to be some exponent of two.
10967
10968 So, there is no fixed rule for blocking. But blocking at read time
10969 should ideally be the same as blocking used at write time. At one place
10970 I know, with a wide variety of equipment, they found it best to use a
10971 blocking of 32 to guarantee that their tapes are fully interchangeable.
10972
10973 I was also told that, for recycled tapes, prior erasure (by the same
10974 drive unit that will be used to create the archives) sometimes lowers
10975 the error rates observed at rewriting time.
10976
10977 I might also use @option{--number-blocks} instead of
10978 @option{--block-number}, so @option{--block} will then expand to
10979 @option{--blocking-factor} unambiguously.
10980
10981 @node Many
10982 @section Many Archives on One Tape
10983
10984 @FIXME{Appropriate options should be moved here from elsewhere.}
10985
10986 @findex ntape @r{device}
10987 Most tape devices have two entries in the @file{/dev} directory, or
10988 entries that come in pairs, which differ only in the minor number for
10989 this device. Let's take for example @file{/dev/tape}, which often
10990 points to the only or usual tape device of a given system. There might
10991 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
10992 name is the @emph{rewinding} version of the device, while the name
10993 having @samp{nr} in it is the @emph{no rewinding} version of the same
10994 device.
10995
10996 A rewinding tape device will bring back the tape to its beginning point
10997 automatically when this device is opened or closed. Since @command{tar}
10998 opens the archive file before using it and closes it afterwards, this
10999 means that a simple:
11000
11001 @smallexample
11002 $ @kbd{tar cf /dev/tape @var{directory}}
11003 @end smallexample
11004
11005 @noindent
11006 will reposition the tape to its beginning both prior and after saving
11007 @var{directory} contents to it, thus erasing prior tape contents and
11008 making it so that any subsequent write operation will destroy what has
11009 just been saved.
11010
11011 @cindex tape positioning
11012 So, a rewinding device is normally meant to hold one and only one file.
11013 If you want to put more than one @command{tar} archive on a given tape, you
11014 will need to avoid using the rewinding version of the tape device. You
11015 will also have to pay special attention to tape positioning. Errors in
11016 positioning may overwrite the valuable data already on your tape. Many
11017 people, burnt by past experiences, will only use rewinding devices and
11018 limit themselves to one file per tape, precisely to avoid the risk of
11019 such errors. Be fully aware that writing at the wrong position on a
11020 tape loses all information past this point and most probably until the
11021 end of the tape, and this destroyed information @emph{cannot} be
11022 recovered.
11023
11024 To save @var{directory-1} as a first archive at the beginning of a
11025 tape, and leave that tape ready for a second archive, you should use:
11026
11027 @smallexample
11028 $ @kbd{mt -f /dev/nrtape rewind}
11029 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11030 @end smallexample
11031
11032 @cindex tape marks
11033 @dfn{Tape marks} are special magnetic patterns written on the tape
11034 media, which are later recognizable by the reading hardware. These
11035 marks are used after each file, when there are many on a single tape.
11036 An empty file (that is to say, two tape marks in a row) signal the
11037 logical end of the tape, after which no file exist. Usually,
11038 non-rewinding tape device drivers will react to the close request issued
11039 by @command{tar} by first writing two tape marks after your archive, and by
11040 backspacing over one of these. So, if you remove the tape at that time
11041 from the tape drive, it is properly terminated. But if you write
11042 another file at the current position, the second tape mark will be
11043 erased by the new information, leaving only one tape mark between files.
11044
11045 So, you may now save @var{directory-2} as a second archive after the
11046 first on the same tape by issuing the command:
11047
11048 @smallexample
11049 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11050 @end smallexample
11051
11052 @noindent
11053 and so on for all the archives you want to put on the same tape.
11054
11055 Another usual case is that you do not write all the archives the same
11056 day, and you need to remove and store the tape between two archive
11057 sessions. In general, you must remember how many files are already
11058 saved on your tape. Suppose your tape already has 16 files on it, and
11059 that you are ready to write the 17th. You have to take care of skipping
11060 the first 16 tape marks before saving @var{directory-17}, say, by using
11061 these commands:
11062
11063 @smallexample
11064 $ @kbd{mt -f /dev/nrtape rewind}
11065 $ @kbd{mt -f /dev/nrtape fsf 16}
11066 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11067 @end smallexample
11068
11069 In all the previous examples, we put aside blocking considerations, but
11070 you should do the proper things for that as well. @xref{Blocking}.
11071
11072 @menu
11073 * Tape Positioning:: Tape Positions and Tape Marks
11074 * mt:: The @command{mt} Utility
11075 @end menu
11076
11077 @node Tape Positioning
11078 @subsection Tape Positions and Tape Marks
11079 @UNREVISED
11080
11081 Just as archives can store more than one file from the file system,
11082 tapes can store more than one archive file. To keep track of where
11083 archive files (or any other type of file stored on tape) begin and
11084 end, tape archive devices write magnetic @dfn{tape marks} on the
11085 archive media. Tape drives write one tape mark between files,
11086 two at the end of all the file entries.
11087
11088 If you think of data as a series of records "rrrr"'s, and tape marks as
11089 "*"'s, a tape might look like the following:
11090
11091 @smallexample
11092 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11093 @end smallexample
11094
11095 Tape devices read and write tapes using a read/write @dfn{tape
11096 head}---a physical part of the device which can only access one
11097 point on the tape at a time. When you use @command{tar} to read or
11098 write archive data from a tape device, the device will begin reading
11099 or writing from wherever on the tape the tape head happens to be,
11100 regardless of which archive or what part of the archive the tape
11101 head is on. Before writing an archive, you should make sure that no
11102 data on the tape will be overwritten (unless it is no longer needed).
11103 Before reading an archive, you should make sure the tape head is at
11104 the beginning of the archive you want to read. You can do it manually
11105 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
11106 that automatically (@pxref{Scripted Restoration}).
11107
11108 If you want to add new archive file entries to a tape, you should
11109 advance the tape to the end of the existing file entries, backspace
11110 over the last tape mark, and write the new archive file. If you were
11111 to add two archives to the example above, the tape might look like the
11112 following:
11113
11114 @smallexample
11115 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11116 @end smallexample
11117
11118 @node mt
11119 @subsection The @command{mt} Utility
11120 @UNREVISED
11121
11122 @FIXME{Is it true that this only works on non-block devices?
11123 should explain the difference, (fixed or variable).}
11124 @xref{Blocking Factor}.
11125
11126 You can use the @command{mt} utility to advance or rewind a tape past a
11127 specified number of archive files on the tape. This will allow you
11128 to move to the beginning of an archive before extracting or reading
11129 it, or to the end of all the archives before writing a new one.
11130 @FIXME{Why isn't there an "advance 'til you find two tape marks
11131 together"?}
11132
11133 The syntax of the @command{mt} command is:
11134
11135 @smallexample
11136 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11137 @end smallexample
11138
11139 where @var{tapename} is the name of the tape device, @var{number} is
11140 the number of times an operation is performed (with a default of one),
11141 and @var{operation} is one of the following:
11142
11143 @FIXME{is there any use for record operations?}
11144
11145 @table @option
11146 @item eof
11147 @itemx weof
11148 Writes @var{number} tape marks at the current position on the tape.
11149
11150 @item fsf
11151 Moves tape position forward @var{number} files.
11152
11153 @item bsf
11154 Moves tape position back @var{number} files.
11155
11156 @item rewind
11157 Rewinds the tape. (Ignores @var{number}.)
11158
11159 @item offline
11160 @itemx rewoff1
11161 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
11162
11163 @item status
11164 Prints status information about the tape unit.
11165
11166 @end table
11167
11168 If you don't specify a @var{tapename}, @command{mt} uses the environment
11169 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11170 the default device specified in your @file{sys/mtio.h} file
11171 (@code{DEFTAPE} variable). If this is not defined, the program will
11172 display a descriptive error message and exit with code 1.
11173
11174 @command{mt} returns a 0 exit status when the operation(s) were
11175 successful, 1 if the command was unrecognized, and 2 if an operation
11176 failed.
11177
11178 @node Using Multiple Tapes
11179 @section Using Multiple Tapes
11180
11181 Often you might want to write a large archive, one larger than will fit
11182 on the actual tape you are using. In such a case, you can run multiple
11183 @command{tar} commands, but this can be inconvenient, particularly if you
11184 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
11185 Therefore, @command{tar} provides a special mode for creating
11186 multi-volume archives.
11187
11188 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
11189 on several media volumes of fixed size. Although in this section we will
11190 often call @samp{volume} a @dfn{tape}, there is absolutely no
11191 requirement for multi-volume archives to be stored on tapes. Instead,
11192 they can use whatever media type the user finds convenient, they can
11193 even be located on files.
11194
11195 When creating a multi-volume archive, @GNUTAR{} continues to fill
11196 current volume until it runs out of space, then it switches to
11197 next volume (usually the operator is queried to replace the tape on
11198 this point), and continues working on the new volume. This operation
11199 continues until all requested files are dumped. If @GNUTAR{} detects
11200 end of media while dumping a file, such a file is archived in split
11201 form. Some very big files can even be split across several volumes.
11202
11203 Each volume is itself a valid @GNUTAR{} archive, so it can be read
11204 without any special options. Consequently any file member residing
11205 entirely on one volume can be extracted or otherwise operated upon
11206 without needing the other volume. Sure enough, to extract a split
11207 member you would need all volumes its parts reside on.
11208
11209 Multi-volume archives suffer from several limitations. In particular,
11210 they cannot be compressed.
11211
11212 @GNUTAR{} is able to create multi-volume archives of two formats
11213 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
11214
11215 @menu
11216 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
11217 * Tape Files:: Tape Files
11218 * Tarcat:: Concatenate Volumes into a Single Archive
11219
11220 @end menu
11221
11222 @node Multi-Volume Archives
11223 @subsection Archives Longer than One Tape or Disk
11224 @cindex Multi-volume archives
11225
11226 @opindex multi-volume
11227 To create an archive that is larger than will fit on a single unit of
11228 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
11229 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
11230 archive can be manipulated like any other archive (provided the
11231 @option{--multi-volume} option is specified), but is stored on more
11232 than one tape or file.
11233
11234 When you specify @option{--multi-volume}, @command{tar} does not report an
11235 error when it comes to the end of an archive volume (when reading), or
11236 the end of the media (when writing). Instead, it prompts you to load
11237 a new storage volume. If the archive is on a magnetic tape, you
11238 should change tapes when you see the prompt; if the archive is on a
11239 floppy disk, you should change disks; etc.
11240
11241 @table @option
11242 @item --multi-volume
11243 @itemx -M
11244 Creates a multi-volume archive, when used in conjunction with
11245 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
11246 archive, specify @option{--multi-volume} in conjunction with that
11247 operation.
11248 For example:
11249
11250 @smallexample
11251 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
11252 @end smallexample
11253 @end table
11254
11255 The method @command{tar} uses to detect end of tape is not perfect, and
11256 fails on some operating systems or on some devices. If @command{tar}
11257 cannot detect the end of the tape itself, you can use
11258 @option{--tape-length} option to inform it about the capacity of the
11259 tape:
11260
11261 @anchor{tape-length}
11262 @table @option
11263 @opindex tape-length
11264 @item --tape-length=@var{size}[@var{suf}]
11265 @itemx -L @var{size}[@var{suf}]
11266 Set maximum length of a volume. The @var{suf}, if given, specifies
11267 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
11268 megabytes (@pxref{size-suffixes}, for a list of allowed size
11269 suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
11270 assumed.
11271
11272 This option selects @option{--multi-volume} automatically. For example:
11273
11274 @smallexample
11275 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
11276 @end smallexample
11277
11278 @noindent
11279 or, which is equivalent:
11280
11281 @smallexample
11282 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
11283 @end smallexample
11284 @end table
11285
11286 @anchor{change volume prompt}
11287 When @GNUTAR{} comes to the end of a storage media, it asks you to
11288 change the volume. The built-in prompt for POSIX locale
11289 is@footnote{If you run @GNUTAR{} under a different locale, the
11290 translation to the locale's language will be used.}:
11291
11292 @smallexample
11293 Prepare volume #@var{n} for '@var{archive}' and hit return:
11294 @end smallexample
11295
11296 @noindent
11297 where @var{n} is the ordinal number of the volume to be created and
11298 @var{archive} is archive file or device name.
11299
11300 When prompting for a new tape, @command{tar} accepts any of the following
11301 responses:
11302
11303 @table @kbd
11304 @item ?
11305 Request @command{tar} to explain possible responses.
11306 @item q
11307 Request @command{tar} to exit immediately.
11308 @item n @var{file-name}
11309 Request @command{tar} to write the next volume on the file @var{file-name}.
11310 @item !
11311 Request @command{tar} to run a subshell. This option can be disabled
11312 by giving @option{--restrict} command line option to
11313 @command{tar}@footnote{@xref{--restrict}, for more information about
11314 this option.}.
11315 @item y
11316 Request @command{tar} to begin writing the next volume.
11317 @end table
11318
11319 (You should only type @samp{y} after you have changed the tape;
11320 otherwise @command{tar} will write over the volume it just finished.)
11321
11322 @cindex Volume number file
11323 @cindex volno file
11324 @anchor{volno-file}
11325 @opindex volno-file
11326 The volume number used by @command{tar} in its tape-changing prompt
11327 can be changed; if you give the
11328 @option{--volno-file=@var{file-of-number}} option, then
11329 @var{file-of-number} should be an non-existing file to be created, or
11330 else, a file already containing a decimal number. That number will be
11331 used as the volume number of the first volume written. When
11332 @command{tar} is finished, it will rewrite the file with the
11333 now-current volume number. (This does not change the volume number
11334 written on a tape label, as per @ref{label}, it @emph{only} affects
11335 the number used in the prompt.)
11336
11337 @cindex End-of-archive info script
11338 @cindex Info script
11339 @anchor{info-script}
11340 @opindex info-script
11341 @opindex new-volume-script
11342 If you want more elaborate behavior than this, you can write a special
11343 @dfn{new volume script}, that will be responsible for changing the
11344 volume, and instruct @command{tar} to use it instead of its normal
11345 prompting procedure:
11346
11347 @table @option
11348 @item --info-script=@var{script-name}
11349 @itemx --new-volume-script=@var{script-name}
11350 @itemx -F @var{script-name}
11351 Specify the full name of the volume script to use. The script can be
11352 used to eject cassettes, or to broadcast messages such as
11353 @samp{Someone please come change my tape} when performing unattended
11354 backups.
11355 @end table
11356
11357 The @var{script-name} is executed without any command line
11358 arguments. It inherits @command{tar}'s shell environment.
11359 Additional data is passed to it via the following
11360 environment variables:
11361
11362 @table @env
11363 @vrindex TAR_VERSION, info script environment variable
11364 @item TAR_VERSION
11365 @GNUTAR{} version number.
11366
11367 @vrindex TAR_ARCHIVE, info script environment variable
11368 @item TAR_ARCHIVE
11369 The name of the archive @command{tar} is processing.
11370
11371 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
11372 @item TAR_BLOCKING_FACTOR
11373 Current blocking factor (@pxref{Blocking}).
11374
11375 @vrindex TAR_VOLUME, info script environment variable
11376 @item TAR_VOLUME
11377 Ordinal number of the volume @command{tar} is about to start.
11378
11379 @vrindex TAR_SUBCOMMAND, info script environment variable
11380 @item TAR_SUBCOMMAND
11381 A short option describing the operation @command{tar} is executing.
11382 @xref{Operations}, for a complete list of subcommand options.
11383
11384 @vrindex TAR_FORMAT, info script environment variable
11385 @item TAR_FORMAT
11386 Format of the archive being processed. @xref{Formats}, for a complete
11387 list of archive format names.
11388
11389 @vrindex TAR_FD, info script environment variable
11390 @item TAR_FD
11391 File descriptor which can be used to communicate the new volume
11392 name to @command{tar}.
11393 @end table
11394
11395 The volume script can instruct @command{tar} to use new archive name,
11396 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
11397
11398 If the info script fails, @command{tar} exits; otherwise, it begins
11399 writing the next volume.
11400
11401 If you want @command{tar} to cycle through a series of files or tape
11402 drives, there are three approaches to choose from. First of all, you
11403 can give @command{tar} multiple @option{--file} options. In this case
11404 the specified files will be used, in sequence, as the successive
11405 volumes of the archive. Only when the first one in the sequence needs
11406 to be used again will @command{tar} prompt for a tape change (or run
11407 the info script). For example, suppose someone has two tape drives on
11408 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
11409 @GNUTAR{} to switch to the second drive when it needs to write the
11410 second tape, and then back to the first tape, etc., just do either of:
11411
11412 @smallexample
11413 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
11414 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
11415 @end smallexample
11416
11417 The second method is to use the @samp{n} response to the tape-change
11418 prompt.
11419
11420 Finally, the most flexible approach is to use a volume script, that
11421 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
11422 following volume script will create a series of archive files, named
11423 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
11424 archive being created (as given by @option{--file} option) and
11425 @var{vol} is the ordinal number of the archive being created:
11426
11427 @smallexample
11428 @group
11429 #! /bin/bash
11430 # For this script it's advisable to use a shell, such as Bash,
11431 # that supports a TAR_FD value greater than 9.
11432
11433 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
11434
11435 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
11436 case $TAR_SUBCOMMAND in
11437 -c) ;;
11438 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
11439 ;;
11440 *) exit 1
11441 esac
11442
11443 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
11444 @end group
11445 @end smallexample
11446
11447 The same script can be used while listing, comparing or extracting
11448 from the created archive. For example:
11449
11450 @smallexample
11451 @group
11452 # @r{Create a multi-volume archive:}
11453 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
11454 # @r{Extract from the created archive:}
11455 $ @kbd{tar -x -f archive.tar -F new-volume .}
11456 @end group
11457 @end smallexample
11458
11459 @noindent
11460 Notice, that the first command had to use @option{-L} option, since
11461 otherwise @GNUTAR{} will end up writing everything to file
11462 @file{archive.tar}.
11463
11464 You can read each individual volume of a multi-volume archive as if it
11465 were an archive by itself. For example, to list the contents of one
11466 volume, use @option{--list}, without @option{--multi-volume} specified.
11467 To extract an archive member from one volume (assuming it is described
11468 that volume), use @option{--extract}, again without
11469 @option{--multi-volume}.
11470
11471 If an archive member is split across volumes (i.e., its entry begins on
11472 one volume of the media and ends on another), you need to specify
11473 @option{--multi-volume} to extract it successfully. In this case, you
11474 should load the volume where the archive member starts, and use
11475 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
11476 volumes as it needs them. @xref{extracting archives}, for more
11477 information about extracting archives.
11478
11479 Multi-volume archives can be modified like any other archive. To add
11480 files to a multi-volume archive, you need to only mount the last
11481 volume of the archive media (and new volumes, if needed). For all
11482 other operations, you need to use the entire archive.
11483
11484 If a multi-volume archive was labeled using
11485 @option{--label=@var{archive-label}} (@pxref{label}) when it was
11486 created, @command{tar} will not automatically label volumes which are
11487 added later. To label subsequent volumes, specify
11488 @option{--label=@var{archive-label}} again in conjunction with the
11489 @option{--append}, @option{--update} or @option{--concatenate} operation.
11490
11491 Notice that multi-volume support is a GNU extension and the archives
11492 created in this mode should be read only using @GNUTAR{}. If you
11493 absolutely have to process such archives using a third-party @command{tar}
11494 implementation, read @ref{Split Recovery}.
11495
11496 @node Tape Files
11497 @subsection Tape Files
11498 @cindex labeling archives
11499 @opindex label
11500 @UNREVISED
11501
11502 To give the archive a name which will be recorded in it, use the
11503 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
11504 option. This will write a special block identifying
11505 @var{volume-label} as the name of the archive to the front of the
11506 archive which will be displayed when the archive is listed with
11507 @option{--list}. If you are creating a multi-volume archive with
11508 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
11509 volume label will have @samp{Volume @var{nnn}} appended to the name
11510 you give, where @var{nnn} is the number of the volume of the archive.
11511 If you use the @option{--label=@var{volume-label}} option when
11512 reading an archive, it checks to make sure the label on the tape
11513 matches the one you gave. @xref{label}.
11514
11515 When @command{tar} writes an archive to tape, it creates a single
11516 tape file. If multiple archives are written to the same tape, one
11517 after the other, they each get written as separate tape files. When
11518 extracting, it is necessary to position the tape at the right place
11519 before running @command{tar}. To do this, use the @command{mt} command.
11520 For more information on the @command{mt} command and on the organization
11521 of tapes into a sequence of tape files, see @ref{mt}.
11522
11523 People seem to often do:
11524
11525 @smallexample
11526 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
11527 @end smallexample
11528
11529 or such, for pushing a common date in all volumes or an archive set.
11530
11531 @node Tarcat
11532 @subsection Concatenate Volumes into a Single Archive
11533
11534 @pindex tarcat
11535 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
11536 archive to a single @command{tar} archive. Simply concatenating all
11537 volumes into one will not work, since each volume carries an additional
11538 information at the beginning. @GNUTAR{} is shipped with the shell
11539 script @command{tarcat} designed for this purpose.
11540
11541 The script takes a list of files comprising a multi-volume archive
11542 and creates the resulting archive at the standard output. For example:
11543
11544 @smallexample
11545 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
11546 @end smallexample
11547
11548 The script implements a simple heuristics to determine the format of
11549 the first volume file and to decide how to process the rest of the
11550 files. However, it makes no attempt to verify whether the files are
11551 given in order or even if they are valid @command{tar} archives.
11552 It uses @command{dd} and does not filter its standard error, so you
11553 will usually see lots of spurious messages.
11554
11555 @FIXME{The script is not installed. Should we install it?}
11556
11557 @node label
11558 @section Including a Label in the Archive
11559 @cindex Labeling an archive
11560 @cindex Labels on the archive media
11561 @cindex Labeling multi-volume archives
11562
11563 @opindex label
11564 To avoid problems caused by misplaced paper labels on the archive
11565 media, you can include a @dfn{label} entry --- an archive member which
11566 contains the name of the archive --- in the archive itself. Use the
11567 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11568 option@footnote{Until version 1.10, that option was called
11569 @option{--volume}, but is not available under that name anymore.} in
11570 conjunction with the @option{--create} operation to include a label
11571 entry in the archive as it is being created.
11572
11573 @table @option
11574 @item --label=@var{archive-label}
11575 @itemx -V @var{archive-label}
11576 Includes an @dfn{archive-label} at the beginning of the archive when
11577 the archive is being created, when used in conjunction with the
11578 @option{--create} operation. Checks to make sure the archive label
11579 matches the one specified (when used in conjunction with any other
11580 operation).
11581 @end table
11582
11583 If you create an archive using both
11584 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11585 and @option{--multi-volume} (@option{-M}), each volume of the archive
11586 will have an archive label of the form @samp{@var{archive-label}
11587 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
11588 next, and so on. @xref{Using Multiple Tapes}, for information on
11589 creating multiple volume archives.
11590
11591 @cindex Volume label, listing
11592 @cindex Listing volume label
11593 The volume label will be displayed by @option{--list} along with
11594 the file contents. If verbose display is requested, it will also be
11595 explicitly marked as in the example below:
11596
11597 @smallexample
11598 @group
11599 $ @kbd{tar --verbose --list --file=iamanarchive}
11600 V--------- 0/0 0 1992-03-07 12:01 iamalabel--Volume Header--
11601 -rw-r--r-- ringo/user 40 1990-05-21 13:30 iamafilename
11602 @end group
11603 @end smallexample
11604
11605 @opindex test-label
11606 @anchor{--test-label option}
11607 However, @option{--list} option will cause listing entire
11608 contents of the archive, which may be undesirable (for example, if the
11609 archive is stored on a tape). You can request checking only the volume
11610 label by specifying @option{--test-label} option. This option reads only the
11611 first block of an archive, so it can be used with slow storage
11612 devices. For example:
11613
11614 @smallexample
11615 @group
11616 $ @kbd{tar --test-label --file=iamanarchive}
11617 iamalabel
11618 @end group
11619 @end smallexample
11620
11621 If @option{--test-label} is used with one or more command line
11622 arguments, @command{tar} compares the volume label with each
11623 argument. It exits with code 0 if a match is found, and with code 1
11624 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
11625 mismatch with an exit code 2 and printed a spurious diagnostics on
11626 stderr.}. No output is displayed, unless you also used the
11627 @option{--verbose} option. For example:
11628
11629 @smallexample
11630 @group
11631 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
11632 @result{} 0
11633 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
11634 @result{} 1
11635 @end group
11636 @end smallexample
11637
11638 When used with the @option{--verbose} option, @command{tar}
11639 prints the actual volume label (if any), and a verbose diagnostics in
11640 case of a mismatch:
11641
11642 @smallexample
11643 @group
11644 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
11645 iamalabel
11646 @result{} 0
11647 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
11648 iamalabel
11649 tar: Archive label mismatch
11650 @result{} 1
11651 @end group
11652 @end smallexample
11653
11654 If you request any operation, other than @option{--create}, along
11655 with using @option{--label} option, @command{tar} will first check if
11656 the archive label matches the one specified and will refuse to proceed
11657 if it does not. Use this as a safety precaution to avoid accidentally
11658 overwriting existing archives. For example, if you wish to add files
11659 to @file{archive}, presumably labeled with string @samp{My volume},
11660 you will get:
11661
11662 @smallexample
11663 @group
11664 $ @kbd{tar -rf archive --label 'My volume' .}
11665 tar: Archive not labeled to match 'My volume'
11666 @end group
11667 @end smallexample
11668
11669 @noindent
11670 in case its label does not match. This will work even if
11671 @file{archive} is not labeled at all.
11672
11673 Similarly, @command{tar} will refuse to list or extract the
11674 archive if its label doesn't match the @var{archive-label}
11675 specified. In those cases, @var{archive-label} argument is interpreted
11676 as a globbing-style pattern which must match the actual magnetic
11677 volume label. @xref{exclude}, for a precise description of how match
11678 is attempted@footnote{Previous versions of @command{tar} used full
11679 regular expression matching, or before that, only exact string
11680 matching, instead of wildcard matchers. We decided for the sake of
11681 simplicity to use a uniform matching device through
11682 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
11683 the volume label matcher will also suffix @var{archive-label} by
11684 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
11685 up. Since the volume numbering is automatically added in labels at
11686 creation time, it sounded logical to equally help the user taking care
11687 of it when the archive is being read.
11688
11689 You can also use @option{--label} to get a common information on
11690 all tapes of a series. For having this information different in each
11691 series created through a single script used on a regular basis, just
11692 manage to get some date string as part of the label. For example:
11693
11694 @smallexample
11695 @group
11696 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
11697 $ @kbd{tar --create --file=/dev/tape --multi-volume \
11698 --label="Daily backup for `date +%Y-%m-%d`"}
11699 @end group
11700 @end smallexample
11701
11702 Some more notes about volume labels:
11703
11704 @itemize @bullet
11705 @item Each label has its own date and time, which corresponds
11706 to the time when @GNUTAR{} initially attempted to write it,
11707 often soon after the operator launches @command{tar} or types the
11708 carriage return telling that the next tape is ready.
11709
11710 @item Comparing date labels to get an idea of tape throughput is
11711 unreliable. It gives correct results only if the delays for rewinding
11712 tapes and the operator switching them were negligible, which is
11713 usually not the case.
11714 @end itemize
11715
11716 @node verify
11717 @section Verifying Data as It is Stored
11718 @cindex Verifying a write operation
11719 @cindex Double-checking a write operation
11720
11721 @table @option
11722 @item -W
11723 @itemx --verify
11724 @opindex verify, short description
11725 Attempt to verify the archive after writing.
11726 @end table
11727
11728 This option causes @command{tar} to verify the archive after writing it.
11729 Each volume is checked after it is written, and any discrepancies
11730 are recorded on the standard error output.
11731
11732 Verification requires that the archive be on a back-space-able medium.
11733 This means pipes, some cartridge tape drives, and some other devices
11734 cannot be verified.
11735
11736 You can insure the accuracy of an archive by comparing files in the
11737 system with archive members. @command{tar} can compare an archive to the
11738 file system as the archive is being written, to verify a write
11739 operation, or can compare a previously written archive, to insure that
11740 it is up to date.
11741
11742 @xopindex{verify, using with @option{--create}}
11743 @xopindex{create, using with @option{--verify}}
11744 To check for discrepancies in an archive immediately after it is
11745 written, use the @option{--verify} (@option{-W}) option in conjunction with
11746 the @option{--create} operation. When this option is
11747 specified, @command{tar} checks archive members against their counterparts
11748 in the file system, and reports discrepancies on the standard error.
11749
11750 To verify an archive, you must be able to read it from before the end
11751 of the last written entry. This option is useful for detecting data
11752 errors on some tapes. Archives written to pipes, some cartridge tape
11753 drives, and some other devices cannot be verified.
11754
11755 One can explicitly compare an already made archive with the file
11756 system by using the @option{--compare} (@option{--diff}, @option{-d})
11757 option, instead of using the more automatic @option{--verify} option.
11758 @xref{compare}.
11759
11760 Note that these two options have a slightly different intent. The
11761 @option{--compare} option checks how identical are the logical contents of some
11762 archive with what is on your disks, while the @option{--verify} option is
11763 really for checking if the physical contents agree and if the recording
11764 media itself is of dependable quality. So, for the @option{--verify}
11765 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11766 the archive, while it lets the speed optimization undisturbed for the
11767 @option{--compare} option. If you nevertheless use @option{--compare} for
11768 media verification, you may have to defeat the in-memory cache yourself,
11769 maybe by opening and reclosing the door latch of your recording unit,
11770 forcing some doubt in your operating system about the fact this is really
11771 the same volume as the one just written or read.
11772
11773 The @option{--verify} option would not be necessary if drivers were indeed
11774 able to detect dependably all write failures. This sometimes require many
11775 magnetic heads, some able to read after the writes occurred. One would
11776 not say that drivers unable to detect all cases are necessarily flawed,
11777 as long as programming is concerned.
11778
11779 The @option{--verify} (@option{-W}) option will not work in
11780 conjunction with the @option{--multi-volume} (@option{-M}) option or
11781 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11782 and @option{--delete} operations. @xref{Operations}, for more
11783 information on these operations.
11784
11785 Also, since @command{tar} normally strips leading @samp{/} from file
11786 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11787 /tmp/foo.tar /etc} will work as desired only if the working directory is
11788 @file{/}, as @command{tar} uses the archive's relative member names
11789 (e.g., @file{etc/motd}) when verifying the archive.
11790
11791 @node Write Protection
11792 @section Write Protection
11793
11794 Almost all tapes and diskettes, and in a few rare cases, even disks can
11795 be @dfn{write protected}, to protect data on them from being changed.
11796 Once an archive is written, you should write protect the media to prevent
11797 the archive from being accidentally overwritten or deleted. (This will
11798 protect the archive from being changed with a tape or floppy drive---it
11799 will not protect it from magnet fields or other physical hazards.)
11800
11801 The write protection device itself is usually an integral part of the
11802 physical media, and can be a two position (write enabled/write
11803 disabled) switch, a notch which can be popped out or covered, a ring
11804 which can be removed from the center of a tape reel, or some other
11805 changeable feature.
11806
11807 @node Reliability and security
11808 @chapter Reliability and Security
11809
11810 The @command{tar} command reads and writes files as any other
11811 application does, and is subject to the usual caveats about
11812 reliability and security. This section contains some commonsense
11813 advice on the topic.
11814
11815 @menu
11816 * Reliability::
11817 * Security::
11818 @end menu
11819
11820 @node Reliability
11821 @section Reliability
11822
11823 Ideally, when @command{tar} is creating an archive, it reads from a
11824 file system that is not being modified, and encounters no errors or
11825 inconsistencies while reading and writing. If this is the case, the
11826 archive should faithfully reflect what was read. Similarly, when
11827 extracting from an archive, ideally @command{tar} ideally encounters
11828 no errors and the extracted files faithfully reflect what was in the
11829 archive.
11830
11831 However, when reading or writing real-world file systems, several
11832 things can go wrong; these include permissions problems, corruption of
11833 data, and race conditions.
11834
11835 @menu
11836 * Permissions problems::
11837 * Data corruption and repair::
11838 * Race conditions::
11839 @end menu
11840
11841 @node Permissions problems
11842 @subsection Permissions Problems
11843
11844 If @command{tar} encounters errors while reading or writing files, it
11845 normally reports an error and exits with nonzero status. The work it
11846 does may therefore be incomplete. For example, when creating an
11847 archive, if @command{tar} cannot read a file then it cannot copy the
11848 file into the archive.
11849
11850 @node Data corruption and repair
11851 @subsection Data Corruption and Repair
11852
11853 If an archive becomes corrupted by an I/O error, this may corrupt the
11854 data in an extracted file. Worse, it may corrupt the file's metadata,
11855 which may cause later parts of the archive to become misinterpreted.
11856 An tar-format archive contains a checksum that most likely will detect
11857 errors in the metadata, but it will not detect errors in the data.
11858
11859 If data corruption is a concern, you can compute and check your own
11860 checksums of an archive by using other programs, such as
11861 @command{cksum}.
11862
11863 When attempting to recover from a read error or data corruption in an
11864 archive, you may need to skip past the questionable data and read the
11865 rest of the archive. This requires some expertise in the archive
11866 format and in other software tools.
11867
11868 @node Race conditions
11869 @subsection Race conditions
11870
11871 If some other process is modifying the file system while @command{tar}
11872 is reading or writing files, the result may well be inconsistent due
11873 to race conditions. For example, if another process creates some
11874 files in a directory while @command{tar} is creating an archive
11875 containing the directory's files, @command{tar} may see some of the
11876 files but not others, or it may see a file that is in the process of
11877 being created. The resulting archive may not be a snapshot of the
11878 file system at any point in time. If an application such as a
11879 database system depends on an accurate snapshot, restoring from the
11880 @command{tar} archive of a live file system may therefore break that
11881 consistency and may break the application. The simplest way to avoid
11882 the consistency issues is to avoid making other changes to the file
11883 system while tar is reading it or writing it.
11884
11885 When creating an archive, several options are available to avoid race
11886 conditions. Some hosts have a way of snapshotting a file system, or
11887 of temporarily suspending all changes to a file system, by (say)
11888 suspending the only virtual machine that can modify a file system; if
11889 you use these facilities and have @command{tar -c} read from a
11890 snapshot when creating an archive, you can avoid inconsistency
11891 problems. More drastically, before starting @command{tar} you could
11892 suspend or shut down all processes other than @command{tar} that have
11893 access to the file system, or you could unmount the file system and
11894 then mount it read-only.
11895
11896 When extracting from an archive, one approach to avoid race conditions
11897 is to create a directory that no other process can write to, and
11898 extract into that.
11899
11900 @node Security
11901 @section Security
11902
11903 In some cases @command{tar} may be used in an adversarial situation,
11904 where an untrusted user is attempting to gain information about or
11905 modify otherwise-inaccessible files. Dealing with untrusted data
11906 (that is, data generated by an untrusted user) typically requires
11907 extra care, because even the smallest mistake in the use of
11908 @command{tar} is more likely to be exploited by an adversary than by a
11909 race condition.
11910
11911 @menu
11912 * Privacy::
11913 * Integrity::
11914 * Live untrusted data::
11915 * Security rules of thumb::
11916 @end menu
11917
11918 @node Privacy
11919 @subsection Privacy
11920
11921 Standard privacy concerns apply when using @command{tar}. For
11922 example, suppose you are archiving your home directory into a file
11923 @file{/archive/myhome.tar}. Any secret information in your home
11924 directory, such as your SSH secret keys, are copied faithfully into
11925 the archive. Therefore, if your home directory contains any file that
11926 should not be read by some other user, the archive itself should be
11927 not be readable by that user. And even if the archive's data are
11928 inaccessible to untrusted users, its metadata (such as size or
11929 last-modified date) may reveal some information about your home
11930 directory; if the metadata are intended to be private, the archive's
11931 parent directory should also be inaccessible to untrusted users.
11932
11933 One precaution is to create @file{/archive} so that it is not
11934 accessible to any user, unless that user also has permission to access
11935 all the files in your home directory.
11936
11937 Similarly, when extracting from an archive, take care that the
11938 permissions of the extracted files are not more generous than what you
11939 want. Even if the archive itself is readable only to you, files
11940 extracted from it have their own permissions that may differ.
11941
11942 @node Integrity
11943 @subsection Integrity
11944
11945 When creating archives, take care that they are not writable by a
11946 untrusted user; otherwise, that user could modify the archive, and
11947 when you later extract from the archive you will get incorrect data.
11948
11949 When @command{tar} extracts from an archive, by default it writes into
11950 files relative to the working directory. If the archive was generated
11951 by an untrusted user, that user therefore can write into any file
11952 under the working directory. If the working directory contains a
11953 symbolic link to another directory, the untrusted user can also write
11954 into any file under the referenced directory. When extracting from an
11955 untrusted archive, it is therefore good practice to create an empty
11956 directory and run @command{tar} in that directory.
11957
11958 When extracting from two or more untrusted archives, each one should
11959 be extracted independently, into different empty directories.
11960 Otherwise, the first archive could create a symbolic link into an area
11961 outside the working directory, and the second one could follow the
11962 link and overwrite data that is not under the working directory. For
11963 example, when restoring from a series of incremental dumps, the
11964 archives should have been created by a trusted process, as otherwise
11965 the incremental restores might alter data outside the working
11966 directory.
11967
11968 If you use the @option{--absolute-names} (@option{-P}) option when
11969 extracting, @command{tar} respects any file names in the archive, even
11970 file names that begin with @file{/} or contain @file{..}. As this
11971 lets the archive overwrite any file in your system that you can write,
11972 the @option{--absolute-names} (@option{-P}) option should be used only
11973 for trusted archives.
11974
11975 Conversely, with the @option{--keep-old-files} (@option{-k}) and
11976 @option{--skip-old-files} options, @command{tar} refuses to replace
11977 existing files when extracting. The difference between the two
11978 options is that the former treats existing files as errors whereas the
11979 latter just silently ignores them.
11980
11981 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
11982 refuses to replace the permissions or ownership of already-existing
11983 directories. These options may help when extracting from untrusted
11984 archives.
11985
11986 @node Live untrusted data
11987 @subsection Dealing with Live Untrusted Data
11988
11989 Extra care is required when creating from or extracting into a file
11990 system that is accessible to untrusted users. For example, superusers
11991 who invoke @command{tar} must be wary about its actions being hijacked
11992 by an adversary who is reading or writing the file system at the same
11993 time that @command{tar} is operating.
11994
11995 When creating an archive from a live file system, @command{tar} is
11996 vulnerable to denial-of-service attacks. For example, an adversarial
11997 user could create the illusion of an indefinitely-deep directory
11998 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
11999 @command{tar}, or the illusion of an indefinitely-long file by
12000 creating a sparse file but arranging for blocks to be allocated just
12001 before @command{tar} reads them. There is no easy way for
12002 @command{tar} to distinguish these scenarios from legitimate uses, so
12003 you may need to monitor @command{tar}, just as you'd need to monitor
12004 any other system service, to detect such attacks.
12005
12006 While a superuser is extracting from an archive into a live file
12007 system, an untrusted user might replace a directory with a symbolic
12008 link, in hopes that @command{tar} will follow the symbolic link and
12009 extract data into files that the untrusted user does not have access
12010 to. Even if the archive was generated by the superuser, it may
12011 contain a file such as @file{d/etc/passwd} that the untrusted user
12012 earlier created in order to break in; if the untrusted user replaces
12013 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12014 @command{tar} is running, @command{tar} will overwrite
12015 @file{/etc/passwd}. This attack can be prevented by extracting into a
12016 directory that is inaccessible to untrusted users.
12017
12018 Similar attacks via symbolic links are also possible when creating an
12019 archive, if the untrusted user can modify an ancestor of a top-level
12020 argument of @command{tar}. For example, an untrusted user that can
12021 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12022 - /home/eve/Documents/yesterday} by replacing
12023 @file{/home/eve/Documents} with a symbolic link to some other
12024 location. Attacks like these can be prevented by making sure that
12025 untrusted users cannot modify any files that are top-level arguments
12026 to @command{tar}, or any ancestor directories of these files.
12027
12028 @node Security rules of thumb
12029 @subsection Security Rules of Thumb
12030
12031 This section briefly summarizes rules of thumb for avoiding security
12032 pitfalls.
12033
12034 @itemize @bullet
12035
12036 @item
12037 Protect archives at least as much as you protect any of the files
12038 being archived.
12039
12040 @item
12041 Extract from an untrusted archive only into an otherwise-empty
12042 directory. This directory and its parent should be accessible only to
12043 trusted users. For example:
12044
12045 @example
12046 @group
12047 $ @kbd{chmod go-rwx .}
12048 $ @kbd{mkdir -m go-rwx dir}
12049 $ @kbd{cd dir}
12050 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12051 @end group
12052 @end example
12053
12054 As a corollary, do not do an incremental restore from an untrusted archive.
12055
12056 @item
12057 Do not let untrusted users access files extracted from untrusted
12058 archives without checking first for problems such as setuid programs.
12059
12060 @item
12061 Do not let untrusted users modify directories that are ancestors of
12062 top-level arguments of @command{tar}. For example, while you are
12063 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12064 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12065
12066 @item
12067 Pay attention to the diagnostics and exit status of @command{tar}.
12068
12069 @item
12070 When archiving live file systems, monitor running instances of
12071 @command{tar} to detect denial-of-service attacks.
12072
12073 @item
12074 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12075 @option{--dereference} (@option{-h}), @option{--overwrite},
12076 @option{--recursive-unlink}, and @option{--remove-files} unless you
12077 understand their security implications.
12078
12079 @end itemize
12080
12081 @node Changes
12082 @appendix Changes
12083
12084 This appendix lists some important user-visible changes between
12085 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12086 version of this document is available at
12087 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12088 @GNUTAR{} documentation page}.
12089
12090 @table @asis
12091 @item Use of globbing patterns when listing and extracting.
12092
12093 Previous versions of GNU tar assumed shell-style globbing when
12094 extracting from or listing an archive. For example:
12095
12096 @smallexample
12097 $ @kbd{tar xf foo.tar '*.c'}
12098 @end smallexample
12099
12100 would extract all files whose names end in @samp{.c}. This behavior
12101 was not documented and was incompatible with traditional tar
12102 implementations. Therefore, starting from version 1.15.91, GNU tar
12103 no longer uses globbing by default. For example, the above invocation
12104 is now interpreted as a request to extract from the archive the file
12105 named @file{*.c}.
12106
12107 To facilitate transition to the new behavior for those users who got
12108 used to the previous incorrect one, @command{tar} will print a warning
12109 if it finds out that a requested member was not found in the archive
12110 and its name looks like a globbing pattern. For example:
12111
12112 @smallexample
12113 $ @kbd{tar xf foo.tar '*.c'}
12114 tar: Pattern matching characters used in file names. Please,
12115 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12116 tar: suppress this warning.
12117 tar: *.c: Not found in archive
12118 tar: Error exit delayed from previous errors
12119 @end smallexample
12120
12121 To treat member names as globbing patterns, use the @option{--wildcards} option.
12122 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12123 add this option to your @env{TAR_OPTIONS} variable.
12124
12125 @xref{wildcards}, for the detailed discussion of the use of globbing
12126 patterns by @GNUTAR{}.
12127
12128 @item Use of short option @option{-o}.
12129
12130 Earlier versions of @GNUTAR{} understood @option{-o} command line
12131 option as a synonym for @option{--old-archive}.
12132
12133 @GNUTAR{} starting from version 1.13.90 understands this option as
12134 a synonym for @option{--no-same-owner}. This is compatible with
12135 UNIX98 @command{tar} implementations.
12136
12137 However, to facilitate transition, @option{-o} option retains its
12138 old semantics when it is used with one of archive-creation commands.
12139 Users are encouraged to use @option{--format=oldgnu} instead.
12140
12141 It is especially important, since versions of @acronym{GNU} Automake
12142 up to and including 1.8.4 invoke tar with this option to produce
12143 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
12144 of this issue and its implications.
12145
12146 @xref{Options, tar-formats, Changing Automake's Behavior,
12147 automake, GNU Automake}, for a description on how to use various
12148 archive formats with @command{automake}.
12149
12150 Future versions of @GNUTAR{} will understand @option{-o} only as a
12151 synonym for @option{--no-same-owner}.
12152
12153 @item Use of short option @option{-l}
12154
12155 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12156 synonym for @option{--one-file-system}. Since such usage contradicted
12157 to UNIX98 specification and harmed compatibility with other
12158 implementations, it was declared deprecated in version 1.14. However,
12159 to facilitate transition to its new semantics, it was supported by
12160 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
12161 variant of @option{--check-links} was introduced in version 1.15.91.
12162
12163 @item Use of options @option{--portability} and @option{--old-archive}
12164
12165 These options are deprecated. Please use @option{--format=v7} instead.
12166
12167 @item Use of option @option{--posix}
12168
12169 This option is deprecated. Please use @option{--format=posix} instead.
12170 @end table
12171
12172 @node Configuring Help Summary
12173 @appendix Configuring Help Summary
12174
12175 Running @kbd{tar --help} displays the short @command{tar} option
12176 summary (@pxref{help}). This summary is organized by @dfn{groups} of
12177 semantically close options. The options within each group are printed
12178 in the following order: a short option, eventually followed by a list
12179 of corresponding long option names, followed by a short description of
12180 the option. For example, here is an excerpt from the actual @kbd{tar
12181 --help} output:
12182
12183 @verbatim
12184 Main operation mode:
12185
12186 -A, --catenate, --concatenate append tar files to an archive
12187 -c, --create create a new archive
12188 -d, --diff, --compare find differences between archive and
12189 file system
12190 --delete delete from the archive
12191 @end verbatim
12192
12193 @vrindex ARGP_HELP_FMT, environment variable
12194 The exact visual representation of the help output is configurable via
12195 @env{ARGP_HELP_FMT} environment variable. The value of this variable
12196 is a comma-separated list of @dfn{format variable} assignments. There
12197 are two kinds of format variables. An @dfn{offset variable} keeps the
12198 offset of some part of help output text from the leftmost column on
12199 the screen. A @dfn{boolean} variable is a flag that toggles some
12200 output feature on or off. Depending on the type of the corresponding
12201 variable, there are two kinds of assignments:
12202
12203 @table @asis
12204 @item Offset assignment
12205
12206 The assignment to an offset variable has the following syntax:
12207
12208 @smallexample
12209 @var{variable}=@var{value}
12210 @end smallexample
12211
12212 @noindent
12213 where @var{variable} is the variable name, and @var{value} is a
12214 numeric value to be assigned to the variable.
12215
12216 @item Boolean assignment
12217
12218 To assign @code{true} value to a variable, simply put this variable name. To
12219 assign @code{false} value, prefix the variable name with @samp{no-}. For
12220 example:
12221
12222 @smallexample
12223 @group
12224 # Assign @code{true} value:
12225 dup-args
12226 # Assign @code{false} value:
12227 no-dup-args
12228 @end group
12229 @end smallexample
12230 @end table
12231
12232 Following variables are declared:
12233
12234 @deftypevr {Help Output} boolean dup-args
12235 If true, arguments for an option are shown with both short and long
12236 options, even when a given option has both forms, for example:
12237
12238 @smallexample
12239 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
12240 @end smallexample
12241
12242 If false, then if an option has both short and long forms, the
12243 argument is only shown with the long one, for example:
12244
12245 @smallexample
12246 -f, --file=ARCHIVE use archive file or device ARCHIVE
12247 @end smallexample
12248
12249 @noindent
12250 and a message indicating that the argument is applicable to both
12251 forms is printed below the options. This message can be disabled
12252 using @code{dup-args-note} (see below).
12253
12254 The default is false.
12255 @end deftypevr
12256
12257 @deftypevr {Help Output} boolean dup-args-note
12258 If this variable is true, which is the default, the following notice
12259 is displayed at the end of the help output:
12260
12261 @quotation
12262 Mandatory or optional arguments to long options are also mandatory or
12263 optional for any corresponding short options.
12264 @end quotation
12265
12266 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
12267 variables @code{dup-args} or @code{dup-args-note} should be set.
12268 @end deftypevr
12269
12270 @deftypevr {Help Output} offset short-opt-col
12271 Column in which short options start. Default is 2.
12272
12273 @smallexample
12274 @group
12275 $ @kbd{tar --help|grep ARCHIVE}
12276 -f, --file=ARCHIVE use archive file or device ARCHIVE
12277 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
12278 -f, --file=ARCHIVE use archive file or device ARCHIVE
12279 @end group
12280 @end smallexample
12281 @end deftypevr
12282
12283 @deftypevr {Help Output} offset long-opt-col
12284 Column in which long options start. Default is 6. For example:
12285
12286 @smallexample
12287 @group
12288 $ @kbd{tar --help|grep ARCHIVE}
12289 -f, --file=ARCHIVE use archive file or device ARCHIVE
12290 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
12291 -f, --file=ARCHIVE use archive file or device ARCHIVE
12292 @end group
12293 @end smallexample
12294 @end deftypevr
12295
12296 @deftypevr {Help Output} offset doc-opt-col
12297 Column in which @dfn{doc options} start. A doc option isn't actually
12298 an option, but rather an arbitrary piece of documentation that is
12299 displayed in much the same manner as the options. For example, in
12300 the description of @option{--format} option:
12301
12302 @smallexample
12303 @group
12304 -H, --format=FORMAT create archive of the given format.
12305
12306 FORMAT is one of the following:
12307
12308 gnu GNU tar 1.13.x format
12309 oldgnu GNU format as per tar <= 1.12
12310 pax POSIX 1003.1-2001 (pax) format
12311 posix same as pax
12312 ustar POSIX 1003.1-1988 (ustar) format
12313 v7 old V7 tar format
12314 @end group
12315 @end smallexample
12316
12317 @noindent
12318 the format names are doc options. Thus, if you set
12319 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
12320 will look as follows:
12321
12322 @smallexample
12323 @group
12324 -H, --format=FORMAT create archive of the given format.
12325
12326 FORMAT is one of the following:
12327
12328 gnu GNU tar 1.13.x format
12329 oldgnu GNU format as per tar <= 1.12
12330 pax POSIX 1003.1-2001 (pax) format
12331 posix same as pax
12332 ustar POSIX 1003.1-1988 (ustar) format
12333 v7 old V7 tar format
12334 @end group
12335 @end smallexample
12336 @end deftypevr
12337
12338 @deftypevr {Help Output} offset opt-doc-col
12339 Column in which option description starts. Default is 29.
12340
12341 @smallexample
12342 @group
12343 $ @kbd{tar --help|grep ARCHIVE}
12344 -f, --file=ARCHIVE use archive file or device ARCHIVE
12345 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
12346 -f, --file=ARCHIVE use archive file or device ARCHIVE
12347 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
12348 -f, --file=ARCHIVE
12349 use archive file or device ARCHIVE
12350 @end group
12351 @end smallexample
12352
12353 @noindent
12354 Notice, that the description starts on a separate line if
12355 @code{opt-doc-col} value is too small.
12356 @end deftypevr
12357
12358 @deftypevr {Help Output} offset header-col
12359 Column in which @dfn{group headers} are printed. A group header is a
12360 descriptive text preceding an option group. For example, in the
12361 following text:
12362
12363 @verbatim
12364 Main operation mode:
12365
12366 -A, --catenate, --concatenate append tar files to
12367 an archive
12368 -c, --create create a new archive
12369 @end verbatim
12370 @noindent
12371 @samp{Main operation mode:} is the group header.
12372
12373 The default value is 1.
12374 @end deftypevr
12375
12376 @deftypevr {Help Output} offset usage-indent
12377 Indentation of wrapped usage lines. Affects @option{--usage}
12378 output. Default is 12.
12379 @end deftypevr
12380
12381 @deftypevr {Help Output} offset rmargin
12382 Right margin of the text output. Used for wrapping.
12383 @end deftypevr
12384
12385 @node Fixing Snapshot Files
12386 @appendix Fixing Snapshot Files
12387 @include tar-snapshot-edit.texi
12388
12389 @node Tar Internals
12390 @appendix Tar Internals
12391 @include intern.texi
12392
12393 @node Genfile
12394 @appendix Genfile
12395 @include genfile.texi
12396
12397 @node Free Software Needs Free Documentation
12398 @appendix Free Software Needs Free Documentation
12399 @include freemanuals.texi
12400
12401 @node GNU Free Documentation License
12402 @appendix GNU Free Documentation License
12403
12404 @include fdl.texi
12405
12406 @node Index of Command Line Options
12407 @appendix Index of Command Line Options
12408
12409 This appendix contains an index of all @GNUTAR{} long command line
12410 options. The options are listed without the preceding double-dash.
12411 For a cross-reference of short command line options, see
12412 @ref{Short Option Summary}.
12413
12414 @printindex op
12415
12416 @node Index
12417 @appendix Index
12418
12419 @printindex cp
12420
12421 @summarycontents
12422 @contents
12423 @bye
12424
12425 @c Local variables:
12426 @c texinfo-column-for-description: 32
12427 @c End:
This page took 0.593536 seconds and 5 git commands to generate.