]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Changes for compatibility with Slackware installation scripts.
[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.
650 @FIXME{Be more specific, I'd like to make this node as detailed as
651 'Bug reporting' node in Emacs 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.
697 @FIXME{and what 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:: All @command{tar} Options.
1804 * help:: Where to Get Help.
1805 * defaults:: What are the Default Values.
1806 * verbose:: Checking @command{tar} progress.
1807 * checkpoints:: Checkpoints.
1808 * warnings:: Controlling Warning Messages.
1809 * interactive:: Asking for Confirmation During Operations.
1810 * external:: Running External Commands.
1811 @end menu
1812
1813 @node Synopsis
1814 @section General Synopsis of @command{tar}
1815
1816 The @GNUTAR{} program is invoked as either one of:
1817
1818 @smallexample
1819 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1820 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1821 @end smallexample
1822
1823 The second form is for when old options are being used.
1824
1825 You can use @command{tar} to store files in an archive, to extract them from
1826 an archive, and to do other types of archive manipulation. The primary
1827 argument to @command{tar}, which is called the @dfn{operation}, specifies
1828 which action to take. The other arguments to @command{tar} are either
1829 @dfn{options}, which change the way @command{tar} performs an operation,
1830 or file names or archive members, which specify the files or members
1831 @command{tar} is to act on.
1832
1833 You can actually type in arguments in any order, even if in this manual
1834 the options always precede the other arguments, to make examples easier
1835 to understand. Further, the option stating the main operation mode
1836 (the @command{tar} main command) is usually given first.
1837
1838 Each @var{name} in the synopsis above is interpreted as an archive member
1839 name when the main command is one of @option{--compare}
1840 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1841 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1842 @option{--update} (@option{-u}). When naming archive members, you
1843 must give the exact name of the member in the archive, as it is
1844 printed by @option{--list}. For @option{--append} (@option{-r}) and
1845 @option{--create} (@option{-c}), these @var{name} arguments specify
1846 the names of either files or directory hierarchies to place in the archive.
1847 These files or hierarchies should already exist in the file system,
1848 prior to the execution of the @command{tar} command.
1849
1850 @command{tar} interprets relative file names as being relative to the
1851 working directory. @command{tar} will make all file names relative
1852 (by removing leading slashes when archiving or restoring files),
1853 unless you specify otherwise (using the @option{--absolute-names}
1854 option). @xref{absolute}, for more information about
1855 @option{--absolute-names}.
1856
1857 If you give the name of a directory as either a file name or a member
1858 name, then @command{tar} acts recursively on all the files and directories
1859 beneath that directory. For example, the name @file{/} identifies all
1860 the files in the file system to @command{tar}.
1861
1862 The distinction between file names and archive member names is especially
1863 important when shell globbing is used, and sometimes a source of confusion
1864 for newcomers. @xref{wildcards}, for more information about globbing.
1865 The problem is that shells may only glob using existing files in the
1866 file system. Only @command{tar} itself may glob on archive members, so when
1867 needed, you must ensure that wildcard characters reach @command{tar} without
1868 being interpreted by the shell first. Using a backslash before @samp{*}
1869 or @samp{?}, or putting the whole argument between quotes, is usually
1870 sufficient for this.
1871
1872 Even if @var{name}s are often specified on the command line, they
1873 can also be read from a text file in the file system, using the
1874 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1875
1876 If you don't use any file name arguments, @option{--append} (@option{-r}),
1877 @option{--delete} and @option{--concatenate} (@option{--catenate},
1878 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1879 will usually yield a diagnostic and inhibit @command{tar} execution.
1880 The other operations of @command{tar} (@option{--list},
1881 @option{--extract}, @option{--compare}, and @option{--update})
1882 will act on the entire contents of the archive.
1883
1884 @anchor{exit status}
1885 @cindex exit status
1886 @cindex return status
1887 Besides successful exits, @GNUTAR{} may fail for
1888 many reasons. Some reasons correspond to bad usage, that is, when the
1889 @command{tar} command line is improperly written. Errors may be
1890 encountered later, while processing the archive or the files. Some
1891 errors are recoverable, in which case the failure is delayed until
1892 @command{tar} has completed all its work. Some errors are such that
1893 it would be not meaningful, or at least risky, to continue processing:
1894 @command{tar} then aborts processing immediately. All abnormal exits,
1895 whether immediate or delayed, should always be clearly diagnosed on
1896 @code{stderr}, after a line stating the nature of the error.
1897
1898 Possible exit codes of @GNUTAR{} are summarized in the following
1899 table:
1900
1901 @table @asis
1902 @item 0
1903 @samp{Successful termination}.
1904
1905 @item 1
1906 @samp{Some files differ}. If tar was invoked with @option{--compare}
1907 (@option{--diff}, @option{-d}) command line option, this means that
1908 some files in the archive differ from their disk counterparts
1909 (@pxref{compare}). If tar was given @option{--create},
1910 @option{--append} or @option{--update} option, this exit code means
1911 that some files were changed while being archived and so the resulting
1912 archive does not contain the exact copy of the file set.
1913
1914 @item 2
1915 @samp{Fatal error}. This means that some fatal, unrecoverable error
1916 occurred.
1917 @end table
1918
1919 If @command{tar} has invoked a subprocess and that subprocess exited with a
1920 nonzero exit code, @command{tar} exits with that code as well.
1921 This can happen, for example, if @command{tar} was given some
1922 compression option (@pxref{gzip}) and the external compressor program
1923 failed. Another example is @command{rmt} failure during backup to the
1924 remote device (@pxref{Remote Tape Server}).
1925
1926 @node using tar options
1927 @section Using @command{tar} Options
1928
1929 @GNUTAR{} has a total of eight operating modes which
1930 allow you to perform a variety of tasks. You are required to choose
1931 one operating mode each time you employ the @command{tar} program by
1932 specifying one, and only one operation as an argument to the
1933 @command{tar} command (the corresponding options may be found
1934 at @ref{frequent operations} and @ref{Operations}). Depending on
1935 circumstances, you may also wish to customize how the chosen operating
1936 mode behaves. For example, you may wish to change the way the output
1937 looks, or the format of the files that you wish to archive may require
1938 you to do something special in order to make the archive look right.
1939
1940 You can customize and control @command{tar}'s performance by running
1941 @command{tar} with one or more options (such as @option{--verbose}
1942 (@option{-v}), which we used in the tutorial). As we said in the
1943 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1944 their name suggests) optional. Depending on the operating mode, you
1945 may specify one or more options. Different options will have different
1946 effects, but in general they all change details of the operation, such
1947 as archive format, archive name, or level of user interaction. Some
1948 options make sense with all operating modes, while others are
1949 meaningful only with particular modes. You will likely use some
1950 options frequently, while you will only use others infrequently, or
1951 not at all. (A full list of options is available in @pxref{All Options}.)
1952
1953 @vrindex TAR_OPTIONS, environment variable
1954 @anchor{TAR_OPTIONS}
1955 The @env{TAR_OPTIONS} environment variable specifies default options to
1956 be placed in front of any explicit options. For example, if
1957 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1958 if the two options @option{-v} and @option{--unlink-first} had been
1959 specified before any explicit options. Option specifications are
1960 separated by whitespace. A backslash escapes the next character, so it
1961 can be used to specify an option containing whitespace or a backslash.
1962
1963 Note that @command{tar} options are case sensitive. For example, the
1964 options @option{-T} and @option{-t} are different; the first requires an
1965 argument for stating the name of a file providing a list of @var{name}s,
1966 while the second does not require an argument and is another way to
1967 write @option{--list} (@option{-t}).
1968
1969 In addition to the eight operations, there are many options to
1970 @command{tar}, and three different styles for writing both: long (mnemonic)
1971 form, short form, and old style. These styles are discussed below.
1972 Both the options and the operations can be written in any of these three
1973 styles.
1974
1975 @FIXME{menu at end of this node. need to think of an actual outline
1976 for this chapter; probably do that after stuff from chapter 4 is
1977 incorporated.}
1978
1979 @node Styles
1980 @section The Three Option Styles
1981
1982 There are three styles for writing operations and options to the command
1983 line invoking @command{tar}. The different styles were developed at
1984 different times during the history of @command{tar}. These styles will be
1985 presented below, from the most recent to the oldest.
1986
1987 Some options must take an argument@footnote{For example, @option{--file}
1988 (@option{-f}) takes the name of an archive file as an argument. If
1989 you do not supply an archive file name, @command{tar} will use a
1990 default, but this can be confusing; thus, we recommend that you always
1991 supply a specific archive file name.}. Where you @emph{place} the
1992 arguments generally depends on which style of options you choose. We
1993 will detail specific information relevant to each option style in the
1994 sections on the different option styles, below. The differences are
1995 subtle, yet can often be very important; incorrect option placement
1996 can cause you to overwrite a number of important files. We urge you
1997 to note these differences, and only use the option style(s) which
1998 makes the most sense to you until you feel comfortable with the others.
1999
2000 Some options @emph{may} take an argument. Such options may have at
2001 most long and short forms, they do not have old style equivalent. The
2002 rules for specifying an argument for such options are stricter than
2003 those for specifying mandatory arguments. Please, pay special
2004 attention to them.
2005
2006 @menu
2007 * Long Options:: Long Option Style
2008 * Short Options:: Short Option Style
2009 * Old Options:: Old Option Style
2010 * Mixing:: Mixing Option Styles
2011 @end menu
2012
2013 @node Long Options
2014 @subsection Long Option Style
2015
2016 @cindex long options
2017 @cindex options, long style
2018 @cindex options, GNU style
2019 @cindex options, mnemonic names
2020 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2021 dashes in a row, e.g., @option{--list}. The long names are more clear than
2022 their corresponding short or old names. It sometimes happens that a
2023 single long option has many different names which are
2024 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2025 long option names can be given unique abbreviations. For example,
2026 @option{--cre} can be used in place of @option{--create} because there is no
2027 other long option which begins with @samp{cre}. (One way to find
2028 this out is by trying it and seeing what happens; if a particular
2029 abbreviation could represent more than one option, @command{tar} will tell
2030 you that that abbreviation is ambiguous and you'll know that that
2031 abbreviation won't work. You may also choose to run @samp{tar --help}
2032 to see a list of options. Be aware that if you run @command{tar} with a
2033 unique abbreviation for the long name of an option you didn't want to
2034 use, you are stuck; @command{tar} will perform the command as ordered.)
2035
2036 Long options are meant to be obvious and easy to remember, and their
2037 meanings are generally easier to discern than those of their
2038 corresponding short options (see below). For example:
2039
2040 @smallexample
2041 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2042 @end smallexample
2043
2044 @noindent
2045 gives a fairly good set of hints about what the command does, even
2046 for those not fully acquainted with @command{tar}.
2047
2048 @cindex arguments to long options
2049 @cindex long options with mandatory arguments
2050 Long options which require arguments take those arguments
2051 immediately following the option name. There are two ways of
2052 specifying a mandatory argument. It can be separated from the
2053 option name either by an equal sign, or by any amount of
2054 white space characters. For example, the @option{--file} option (which
2055 tells the name of the @command{tar} archive) is given a file such as
2056 @file{archive.tar} as argument by using any of the following notations:
2057 @option{--file=archive.tar} or @option{--file archive.tar}.
2058
2059 @cindex optional arguments to long options
2060 @cindex long options with optional arguments
2061 In contrast, optional arguments must always be introduced using
2062 an equal sign. For example, the @option{--backup} option takes
2063 an optional argument specifying backup type. It must be used
2064 as @option{--backup=@var{backup-type}}.
2065
2066 @node Short Options
2067 @subsection Short Option Style
2068
2069 @cindex short options
2070 @cindex options, short style
2071 @cindex options, traditional
2072 Most options also have a @dfn{short option} name. Short options start with
2073 a single dash, and are followed by a single character, e.g., @option{-t}
2074 (which is equivalent to @option{--list}). The forms are absolutely
2075 identical in function; they are interchangeable.
2076
2077 The short option names are faster to type than long option names.
2078
2079 @cindex arguments to short options
2080 @cindex short options with mandatory arguments
2081 Short options which require arguments take their arguments immediately
2082 following the option, usually separated by white space. It is also
2083 possible to stick the argument right after the short option name, using
2084 no intervening space. For example, you might write @w{@option{-f
2085 archive.tar}} or @option{-farchive.tar} instead of using
2086 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2087 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2088 specific archive, here named @file{archive.tar}.
2089
2090 @cindex optional arguments to short options
2091 @cindex short options with optional arguments
2092 Short options which take optional arguments take their arguments
2093 immediately following the option letter, @emph{without any intervening
2094 white space characters}.
2095
2096 Short options' letters may be clumped together, but you are not
2097 required to do this (as compared to old options; see below). When
2098 short options are clumped as a set, use one (single) dash for them
2099 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2100 such a set is allowed to have an argument@footnote{Clustering many
2101 options, the last of which has an argument, is a rather opaque way to
2102 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2103 even be made helpful enough for considering such usages as invalid.}.
2104
2105 When the options are separated, the argument for each option which requires
2106 an argument directly follows that option, as is usual for Unix programs.
2107 For example:
2108
2109 @smallexample
2110 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2111 @end smallexample
2112
2113 If you reorder short options' locations, be sure to move any arguments
2114 that belong to them. If you do not move the arguments properly, you may
2115 end up overwriting files.
2116
2117 @node Old Options
2118 @subsection Old Option Style
2119 @cindex options, old style
2120 @cindex old option style
2121 @cindex option syntax, traditional
2122
2123 As far as we know, all @command{tar} programs, @acronym{GNU} and
2124 non-@acronym{GNU}, support @dfn{old options}: that is, if the first
2125 argument does not start with @samp{-}, it is assumed to specify option
2126 letters. @GNUTAR{} supports old options not only for historical
2127 reasons, but also because many people are used to them. If the first
2128 argument does not start with a dash, you are announcing the old option
2129 style instead of the short option style; old options are decoded
2130 differently.
2131
2132 Like short options, old options are single letters. However, old options
2133 must be written together as a single clumped set, without spaces separating
2134 them or dashes preceding them. This set
2135 of letters must be the first to appear on the command line, after the
2136 @command{tar} program name and some white space; old options cannot appear
2137 anywhere else. The letter of an old option is exactly the same letter as
2138 the corresponding short option. For example, the old option @samp{t} is
2139 the same as the short option @option{-t}, and consequently, the same as the
2140 long option @option{--list}. So for example, the command @w{@samp{tar
2141 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2142
2143 @cindex arguments to old options
2144 @cindex old options with mandatory arguments
2145 When options that need arguments are given together with the command,
2146 all the associated arguments follow, in the same order as the options.
2147 Thus, the example given previously could also be written in the old
2148 style as follows:
2149
2150 @smallexample
2151 $ @kbd{tar cvbf 20 /dev/rmt0}
2152 @end smallexample
2153
2154 @noindent
2155 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2156 the argument of @option{-f}.
2157
2158 The old style syntax can make it difficult to match
2159 option letters with their corresponding arguments, and is often
2160 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2161 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2162 argument for @option{-f}, and @option{-v} does not have a corresponding
2163 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2164 /dev/rmt0}} is clearer, putting all arguments next to the option they
2165 pertain to.
2166
2167 If you want to reorder the letters in the old option argument, be
2168 sure to reorder any corresponding argument appropriately.
2169
2170 This old way of writing @command{tar} options can surprise even experienced
2171 users. For example, the two commands:
2172
2173 @smallexample
2174 @kbd{tar cfz archive.tar.gz file}
2175 @kbd{tar -cfz archive.tar.gz file}
2176 @end smallexample
2177
2178 @noindent
2179 are quite different. The first example uses @file{archive.tar.gz} as
2180 the value for option @samp{f} and recognizes the option @samp{z}. The
2181 second example, however, uses @file{z} as the value for option
2182 @samp{f} --- probably not what was intended.
2183
2184 This second example could be corrected in many ways, among which the
2185 following are equivalent:
2186
2187 @smallexample
2188 @kbd{tar -czf archive.tar.gz file}
2189 @kbd{tar -cf archive.tar.gz -z file}
2190 @kbd{tar cf archive.tar.gz -z file}
2191 @end smallexample
2192
2193 @node Mixing
2194 @subsection Mixing Option Styles
2195
2196 @cindex options, mixing different styles
2197 All three styles may be intermixed in a single @command{tar} command,
2198 so long as the rules for each style are fully
2199 respected@footnote{Before @GNUTAR{} version 1.11.6,
2200 a bug prevented intermixing old style options with long options in
2201 some cases.}. Old style options and either of the modern styles of
2202 options may be mixed within a single @command{tar} command. However,
2203 old style options must be introduced as the first arguments only,
2204 following the rule for old options (old options must appear directly
2205 after the @command{tar} command and some white space). Modern options
2206 may be given only after all arguments to the old options have been
2207 collected. If this rule is not respected, a modern option might be
2208 falsely interpreted as the value of the argument to one of the old
2209 style options.
2210
2211 For example, all the following commands are wholly equivalent, and
2212 illustrate the many combinations and orderings of option styles.
2213
2214 @smallexample
2215 @kbd{tar --create --file=archive.tar}
2216 @kbd{tar --create -f archive.tar}
2217 @kbd{tar --create -farchive.tar}
2218 @kbd{tar --file=archive.tar --create}
2219 @kbd{tar --file=archive.tar -c}
2220 @kbd{tar -c --file=archive.tar}
2221 @kbd{tar -c -f archive.tar}
2222 @kbd{tar -c -farchive.tar}
2223 @kbd{tar -cf archive.tar}
2224 @kbd{tar -cfarchive.tar}
2225 @kbd{tar -f archive.tar --create}
2226 @kbd{tar -f archive.tar -c}
2227 @kbd{tar -farchive.tar --create}
2228 @kbd{tar -farchive.tar -c}
2229 @kbd{tar c --file=archive.tar}
2230 @kbd{tar c -f archive.tar}
2231 @kbd{tar c -farchive.tar}
2232 @kbd{tar cf archive.tar}
2233 @kbd{tar f archive.tar --create}
2234 @kbd{tar f archive.tar -c}
2235 @kbd{tar fc archive.tar}
2236 @end smallexample
2237
2238 On the other hand, the following commands are @emph{not} equivalent to
2239 the previous set:
2240
2241 @smallexample
2242 @kbd{tar -f -c archive.tar}
2243 @kbd{tar -fc archive.tar}
2244 @kbd{tar -fcarchive.tar}
2245 @kbd{tar -farchive.tarc}
2246 @kbd{tar cfarchive.tar}
2247 @end smallexample
2248
2249 @noindent
2250 These last examples mean something completely different from what the
2251 user intended (judging based on the example in the previous set which
2252 uses long options, whose intent is therefore very clear). The first
2253 four specify that the @command{tar} archive would be a file named
2254 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2255 respectively. The first two examples also specify a single non-option,
2256 @var{name} argument having the value @samp{archive.tar}. The last
2257 example contains only old style option letters (repeating option
2258 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2259 @samp{h}, or @samp{i}), with no argument value.
2260 @FIXME{not sure i liked
2261 the first sentence of this paragraph..}
2262
2263 @node All Options
2264 @section All @command{tar} Options
2265
2266 The coming manual sections contain an alphabetical listing of all
2267 @command{tar} operations and options, with brief descriptions and
2268 cross-references to more in-depth explanations in the body of the manual.
2269 They also contain an alphabetically arranged table of the short option
2270 forms with their corresponding long option. You can use this table as
2271 a reference for deciphering @command{tar} commands in scripts.
2272
2273 @menu
2274 * Operation Summary::
2275 * Option Summary::
2276 * Short Option Summary::
2277 @end menu
2278
2279 @node Operation Summary
2280 @subsection Operations
2281
2282 @table @option
2283
2284 @opsummary{append}
2285 @item --append
2286 @itemx -r
2287
2288 Appends files to the end of the archive. @xref{append}.
2289
2290 @opsummary{catenate}
2291 @item --catenate
2292 @itemx -A
2293
2294 Same as @option{--concatenate}. @xref{concatenate}.
2295
2296 @opsummary{compare}
2297 @item --compare
2298 @itemx -d
2299
2300 Compares archive members with their counterparts in the file
2301 system, and reports differences in file size, mode, owner,
2302 modification date and contents. @xref{compare}.
2303
2304 @opsummary{concatenate}
2305 @item --concatenate
2306 @itemx -A
2307
2308 Appends other @command{tar} archives to the end of the archive.
2309 @xref{concatenate}.
2310
2311 @opsummary{create}
2312 @item --create
2313 @itemx -c
2314
2315 Creates a new @command{tar} archive. @xref{create}.
2316
2317 @opsummary{delete}
2318 @item --delete
2319
2320 Deletes members from the archive. Don't try this on an archive on a
2321 tape! @xref{delete}.
2322
2323 @opsummary{diff}
2324 @item --diff
2325 @itemx -d
2326
2327 Same @option{--compare}. @xref{compare}.
2328
2329 @opsummary{extract}
2330 @item --extract
2331 @itemx -x
2332
2333 Extracts members from the archive into the file system. @xref{extract}.
2334
2335 @opsummary{get}
2336 @item --get
2337 @itemx -x
2338
2339 Same as @option{--extract}. @xref{extract}.
2340
2341 @opsummary{list}
2342 @item --list
2343 @itemx -t
2344
2345 Lists the members in an archive. @xref{list}.
2346
2347 @opsummary{update}
2348 @item --update
2349 @itemx -u
2350
2351 Adds files to the end of the archive, but only if they are newer than
2352 their counterparts already in the archive, or if they do not already
2353 exist in the archive. @xref{update}.
2354
2355 @end table
2356
2357 @node Option Summary
2358 @subsection @command{tar} Options
2359
2360 @table @option
2361
2362 @opsummary{absolute-names}
2363 @item --absolute-names
2364 @itemx -P
2365
2366 Normally when creating an archive, @command{tar} strips an initial
2367 @samp{/} from member names, and when extracting from an archive @command{tar}
2368 treats names specially if they have initial @samp{/} or internal
2369 @samp{..}. This option disables that behavior. @xref{absolute}.
2370
2371 @opsummary{after-date}
2372 @item --after-date
2373
2374 (See @option{--newer}, @pxref{after})
2375
2376 @opsummary{anchored}
2377 @item --anchored
2378 A pattern must match an initial subsequence of the name's components.
2379 @xref{controlling pattern-matching}.
2380
2381 @opsummary{atime-preserve}
2382 @item --atime-preserve
2383 @itemx --atime-preserve=replace
2384 @itemx --atime-preserve=system
2385
2386 Attempt to preserve the access time of files when reading them. This
2387 option currently is effective only on files that you own, unless you
2388 have superuser privileges.
2389
2390 @option{--atime-preserve=replace} remembers the access time of a file
2391 before reading it, and then restores the access time afterwards. This
2392 may cause problems if other programs are reading the file at the same
2393 time, as the times of their accesses will be lost. On most platforms
2394 restoring the access time also requires @command{tar} to restore the
2395 data modification time too, so this option may also cause problems if
2396 other programs are writing the file at the same time (@command{tar} attempts
2397 to detect this situation, but cannot do so reliably due to race
2398 conditions). Worse, on most platforms restoring the access time also
2399 updates the status change time, which means that this option is
2400 incompatible with incremental backups.
2401
2402 @option{--atime-preserve=system} avoids changing time stamps on files,
2403 without interfering with time stamp updates
2404 caused by other programs, so it works better with incremental backups.
2405 However, it requires a special @code{O_NOATIME} option from the
2406 underlying operating and file system implementation, and it also requires
2407 that searching directories does not update their access times. As of
2408 this writing (November 2005) this works only with Linux, and only with
2409 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2410 way to know whether this feature actually works. Sometimes
2411 @command{tar} knows that it does not work, and if you use
2412 @option{--atime-preserve=system} then @command{tar} complains and
2413 exits right away. But other times @command{tar} might think that the
2414 option works when it actually does not.
2415
2416 Currently @option{--atime-preserve} with no operand defaults to
2417 @option{--atime-preserve=replace}, but this may change in the future
2418 as support for @option{--atime-preserve=system} improves.
2419
2420 If your operating or file system does not support
2421 @option{--atime-preserve=@-system}, you might be able to preserve access
2422 times reliably by using the @command{mount} command. For example,
2423 you can mount the file system read-only, or access the file system via
2424 a read-only loopback mount, or use the @samp{noatime} mount option
2425 available on some systems. However, mounting typically requires
2426 superuser privileges and can be a pain to manage.
2427
2428 @opsummary{auto-compress}
2429 @item --auto-compress
2430 @itemx -a
2431
2432 During a @option{--create} operation, enables automatic compressed
2433 format recognition based on the archive suffix. The effect of this
2434 option is cancelled by @option{--no-auto-compress}. @xref{gzip}.
2435
2436 @opsummary{backup}
2437 @item --backup=@var{backup-type}
2438
2439 Rather than deleting files from the file system, @command{tar} will
2440 back them up using simple or numbered backups, depending upon
2441 @var{backup-type}. @xref{backup}.
2442
2443 @opsummary{block-number}
2444 @item --block-number
2445 @itemx -R
2446
2447 With this option present, @command{tar} prints error messages for read errors
2448 with the block number in the archive file. @xref{block-number}.
2449
2450 @opsummary{blocking-factor}
2451 @item --blocking-factor=@var{blocking}
2452 @itemx -b @var{blocking}
2453
2454 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2455 record. @xref{Blocking Factor}.
2456
2457 @opsummary{bzip2}
2458 @item --bzip2
2459 @itemx -j
2460
2461 This option tells @command{tar} to read or write archives through
2462 @code{bzip2}. @xref{gzip}.
2463
2464 @opsummary{check-device}
2465 @item --check-device
2466 Check device numbers when creating a list of modified files for
2467 incremental archiving. This is the default. @xref{device numbers},
2468 for a detailed description.
2469
2470 @opsummary{checkpoint}
2471 @item --checkpoint[=@var{number}]
2472
2473 This option directs @command{tar} to print periodic checkpoint
2474 messages as it reads through the archive. It is intended for when you
2475 want a visual indication that @command{tar} is still running, but
2476 don't want to see @option{--verbose} output. You can also instruct
2477 @command{tar} to execute a list of actions on each checkpoint, see
2478 @option{--checkpoint-action} below. For a detailed description, see
2479 @ref{checkpoints}.
2480
2481 @opsummary{checkpoint-action}
2482 @item --checkpoint-action=@var{action}
2483 Instruct @command{tar} to execute an action upon hitting a
2484 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2485 for a complete description.
2486
2487 The @var{action} argument can be one of the following:
2488
2489 @table @asis
2490 @item bell
2491 Produce an audible bell on the console.
2492
2493 @item dot
2494 @itemx .
2495 Print a single dot on the standard listing stream.
2496
2497 @item echo
2498 Display a textual message on the standard error, with the status and
2499 number of the checkpoint. This is the default.
2500
2501 @item echo=@var{string}
2502 Display @var{string} on the standard error. Before output, the string
2503 is subject to meta-character expansion.
2504
2505 @item exec=@var{command}
2506 Execute the given @var{command}.
2507
2508 @item sleep=@var{time}
2509 Wait for @var{time} seconds.
2510
2511 @item ttyout=@var{string}
2512 Output @var{string} on the current console (@file{/dev/tty}).
2513 @end table
2514
2515 Several @option{--checkpoint-action} options can be specified. The
2516 supplied actions will be executed in order of their appearance in the
2517 command line.
2518
2519 Using @option{--checkpoint-action} without @option{--checkpoint}
2520 assumes default checkpoint frequency of one checkpoint per 10 records.
2521
2522 @opsummary{check-links}
2523 @item --check-links
2524 @itemx -l
2525 If this option was given, @command{tar} will check the number of links
2526 dumped for each processed file. If this number does not match the
2527 total number of hard links for the file, a warning message will be
2528 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2529 synonym for @option{--one-file-system}. The current semantics, which
2530 complies to UNIX98, was introduced with version
2531 1.15.91. @xref{Changes}, for more information.}.
2532
2533 @xref{hard links}.
2534
2535 @opsummary{compress}
2536 @opsummary{uncompress}
2537 @item --compress
2538 @itemx --uncompress
2539 @itemx -Z
2540
2541 @command{tar} will use the @command{compress} program when reading or
2542 writing the archive. This allows you to directly act on archives
2543 while saving space. @xref{gzip}.
2544
2545 @opsummary{confirmation}
2546 @item --confirmation
2547
2548 (See @option{--interactive}.) @xref{interactive}.
2549
2550 @opsummary{delay-directory-restore}
2551 @item --delay-directory-restore
2552
2553 Delay setting modification times and permissions of extracted
2554 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2555
2556 @opsummary{dereference}
2557 @item --dereference
2558 @itemx -h
2559
2560 When reading or writing a file to be archived, @command{tar} accesses
2561 the file that a symbolic link points to, rather than the symlink
2562 itself. @xref{dereference}.
2563
2564 @opsummary{directory}
2565 @item --directory=@var{dir}
2566 @itemx -C @var{dir}
2567
2568 When this option is specified, @command{tar} will change its current directory
2569 to @var{dir} before performing any operations. When this option is used
2570 during archive creation, it is order sensitive. @xref{directory}.
2571
2572 @opsummary{exclude}
2573 @item --exclude=@var{pattern}
2574
2575 When performing operations, @command{tar} will skip files that match
2576 @var{pattern}. @xref{exclude}.
2577
2578 @opsummary{exclude-backups}
2579 @item --exclude-backups
2580 Exclude backup and lock files. @xref{exclude,, exclude-backups}.
2581
2582 @opsummary{exclude-from}
2583 @item --exclude-from=@var{file}
2584 @itemx -X @var{file}
2585
2586 Similar to @option{--exclude}, except @command{tar} will use the list of
2587 patterns in the file @var{file}. @xref{exclude}.
2588
2589 @opsummary{exclude-caches}
2590 @item --exclude-caches
2591
2592 Exclude from dump any directory containing a valid cache directory
2593 tag file, but still dump the directory node and the tag file itself.
2594
2595 @xref{exclude,, exclude-caches}.
2596
2597 @opsummary{exclude-caches-under}
2598 @item --exclude-caches-under
2599
2600 Exclude from dump any directory containing a valid cache directory
2601 tag file, but still dump the directory node itself.
2602
2603 @xref{exclude}.
2604
2605 @opsummary{exclude-caches-all}
2606 @item --exclude-caches-all
2607
2608 Exclude from dump any directory containing a valid cache directory
2609 tag file. @xref{exclude}.
2610
2611 @opsummary{exclude-tag}
2612 @item --exclude-tag=@var{file}
2613
2614 Exclude from dump any directory containing file named @var{file}, but
2615 dump the directory node and @var{file} itself. @xref{exclude,, exclude-tag}.
2616
2617 @opsummary{exclude-tag-under}
2618 @item --exclude-tag-under=@var{file}
2619
2620 Exclude from dump the contents of any directory containing file
2621 named @var{file}, but dump the directory node itself. @xref{exclude,,
2622 exclude-tag-under}.
2623
2624 @opsummary{exclude-tag-all}
2625 @item --exclude-tag-all=@var{file}
2626
2627 Exclude from dump any directory containing file named @var{file}.
2628 @xref{exclude,,exclude-tag-all}.
2629
2630 @opsummary{exclude-vcs}
2631 @item --exclude-vcs
2632
2633 Exclude from dump directories and files, that are internal for some
2634 widely used version control systems.
2635
2636 @xref{exclude,,exclude-vcs}.
2637
2638 @opsummary{file}
2639 @item --file=@var{archive}
2640 @itemx -f @var{archive}
2641
2642 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2643 performs operations on, rather than @command{tar}'s compilation dependent
2644 default. @xref{file tutorial}.
2645
2646 @opsummary{files-from}
2647 @item --files-from=@var{file}
2648 @itemx -T @var{file}
2649
2650 @command{tar} will use the contents of @var{file} as a list of archive members
2651 or files to operate on, in addition to those specified on the
2652 command-line. @xref{files}.
2653
2654 @opsummary{force-local}
2655 @item --force-local
2656
2657 Forces @command{tar} to interpret the file name given to @option{--file}
2658 as a local file, even if it looks like a remote tape drive name.
2659 @xref{local and remote archives}.
2660
2661 @opsummary{format}
2662 @item --format=@var{format}
2663 @itemx -H @var{format}
2664
2665 Selects output archive format. @var{Format} may be one of the
2666 following:
2667
2668 @table @samp
2669 @item v7
2670 Creates an archive that is compatible with Unix V7 @command{tar}.
2671
2672 @item oldgnu
2673 Creates an archive that is compatible with GNU @command{tar} version
2674 1.12 or earlier.
2675
2676 @item gnu
2677 Creates archive in GNU tar 1.13 format. Basically it is the same as
2678 @samp{oldgnu} with the only difference in the way it handles long
2679 numeric fields.
2680
2681 @item ustar
2682 Creates a @acronym{POSIX.1-1988} compatible archive.
2683
2684 @item posix
2685 Creates a @acronym{POSIX.1-2001 archive}.
2686
2687 @end table
2688
2689 @xref{Formats}, for a detailed discussion of these formats.
2690
2691 @opsummary{full-time}
2692 @item --full-time
2693 This option instructs @command{tar} to print file times to their full
2694 resolution. Usually this means 1-second resolution, but that depends
2695 on the underlying file system. The @option{--full-time} option takes
2696 effect only when detailed output (verbosity level 2 or higher) has
2697 been requested using the @option{--verbose} option, e.g., when listing
2698 or extracting archives:
2699
2700 @smallexample
2701 $ @kbd{tar -t -v --full-time -f archive.tar}
2702 @end smallexample
2703
2704 @noindent
2705 or, when creating an archive:
2706
2707 @smallexample
2708 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2709 @end smallexample
2710
2711 Notice, thar when creating the archive you need to specify
2712 @option{--verbose} twice to get a detailed output (@pxref{verbose
2713 tutorial}).
2714
2715 @opsummary{group}
2716 @item --group=@var{group}
2717
2718 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2719 rather than the group from the source file. @var{group} can specify a
2720 symbolic name, or a numeric @acronym{ID}, or both as
2721 @var{name}:@var{id}. @xref{override}.
2722
2723 Also see the comments for the @option{--owner=@var{user}} option.
2724
2725 @opsummary{gzip}
2726 @opsummary{gunzip}
2727 @opsummary{ungzip}
2728 @item --gzip
2729 @itemx --gunzip
2730 @itemx --ungzip
2731 @itemx -z
2732
2733 This option tells @command{tar} to read or write archives through
2734 @command{gzip}, allowing @command{tar} to directly operate on several
2735 kinds of compressed archives transparently. @xref{gzip}.
2736
2737 @opsummary{hard-dereference}
2738 @item --hard-dereference
2739 When creating an archive, dereference hard links and store the files
2740 they refer to, instead of creating usual hard link members.
2741
2742 @xref{hard links}.
2743
2744 @opsummary{help}
2745 @item --help
2746 @itemx -?
2747
2748 @command{tar} will print out a short message summarizing the operations and
2749 options to @command{tar} and exit. @xref{help}.
2750
2751 @opsummary{ignore-case}
2752 @item --ignore-case
2753 Ignore case when matching member or file names with
2754 patterns. @xref{controlling pattern-matching}.
2755
2756 @opsummary{ignore-command-error}
2757 @item --ignore-command-error
2758 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2759
2760 @opsummary{ignore-failed-read}
2761 @item --ignore-failed-read
2762
2763 Do not exit unsuccessfully merely because an unreadable file was encountered.
2764 @xref{Ignore Failed Read}.
2765
2766 @opsummary{ignore-zeros}
2767 @item --ignore-zeros
2768 @itemx -i
2769
2770 With this option, @command{tar} will ignore zeroed blocks in the
2771 archive, which normally signals EOF. @xref{Reading}.
2772
2773 @opsummary{incremental}
2774 @item --incremental
2775 @itemx -G
2776
2777 Informs @command{tar} that it is working with an old
2778 @acronym{GNU}-format incremental backup archive. It is intended
2779 primarily for backwards compatibility only. @xref{Incremental Dumps},
2780 for a detailed discussion of incremental archives.
2781
2782 @opsummary{index-file}
2783 @item --index-file=@var{file}
2784
2785 Send verbose output to @var{file} instead of to standard output.
2786
2787 @opsummary{info-script}
2788 @opsummary{new-volume-script}
2789 @item --info-script=@var{command}
2790 @itemx --new-volume-script=@var{command}
2791 @itemx -F @var{command}
2792
2793 When @command{tar} is performing multi-tape backups, @var{command} is run
2794 at the end of each tape. If it exits with nonzero status,
2795 @command{tar} fails immediately. @xref{info-script}, for a detailed
2796 discussion of this feature.
2797
2798 @opsummary{interactive}
2799 @item --interactive
2800 @itemx --confirmation
2801 @itemx -w
2802
2803 Specifies that @command{tar} should ask the user for confirmation before
2804 performing potentially destructive options, such as overwriting files.
2805 @xref{interactive}.
2806
2807 @opsummary{--keep-directory-symlink}
2808 @item --keep-directory-symlink
2809
2810 This option changes the behavior of tar when it encounters a symlink
2811 with the same name as the directory that it is about to extract. By
2812 default, in this case tar would first remove the symlink and then
2813 proceed extracting the directory.
2814
2815 The @option{--keep-directory-symlink} option disables this behavior
2816 and instructs tar to follow symlinks to directories when extracting
2817 from the archive.
2818
2819 It is mainly intended to provide compatibility with the Slackware
2820 installation scripts.
2821
2822 @opsummary{keep-newer-files}
2823 @item --keep-newer-files
2824
2825 Do not replace existing files that are newer than their archive copies
2826 when extracting files from an archive.
2827
2828 @opsummary{keep-old-files}
2829 @item --keep-old-files
2830 @itemx -k
2831
2832 Do not overwrite existing files when extracting files from an
2833 archive. Return error if such files exist. See also
2834 @ref{--skip-old-files}.
2835
2836 @xref{Keep Old Files}.
2837
2838 @opsummary{label}
2839 @item --label=@var{name}
2840 @itemx -V @var{name}
2841
2842 When creating an archive, instructs @command{tar} to write @var{name}
2843 as a name record in the archive. When extracting or listing archives,
2844 @command{tar} will only operate on archives that have a label matching
2845 the pattern specified in @var{name}. @xref{Tape Files}.
2846
2847 @opsummary{level}
2848 @item --level=@var{n}
2849 Force incremental backup of level @var{n}. As of @GNUTAR version
2850 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2851 file, thereby forcing the level 0 dump. Other values of @var{n} are
2852 effectively ignored. @xref{--level=0}, for details and examples.
2853
2854 The use of this option is valid only in conjunction with the
2855 @option{--listed-incremental} option. @xref{Incremental Dumps},
2856 for a detailed description.
2857
2858 @opsummary{listed-incremental}
2859 @item --listed-incremental=@var{snapshot-file}
2860 @itemx -g @var{snapshot-file}
2861
2862 During a @option{--create} operation, specifies that the archive that
2863 @command{tar} creates is a new @acronym{GNU}-format incremental
2864 backup, using @var{snapshot-file} to determine which files to backup.
2865 With other operations, informs @command{tar} that the archive is in
2866 incremental format. @xref{Incremental Dumps}.
2867
2868 @opsummary{lzip}
2869 @item --lzip
2870
2871 This option tells @command{tar} to read or write archives through
2872 @command{lzip}. @xref{gzip}.
2873
2874 @opsummary{lzma}
2875 @item --lzma
2876
2877 This option tells @command{tar} to read or write archives through
2878 @command{lzma}. @xref{gzip}.
2879
2880 @item --lzop
2881
2882 This option tells @command{tar} to read or write archives through
2883 @command{lzop}. @xref{gzip}.
2884
2885 @opsummary{mode}
2886 @item --mode=@var{permissions}
2887
2888 When adding files to an archive, @command{tar} will use
2889 @var{permissions} for the archive members, rather than the permissions
2890 from the files. @var{permissions} can be specified either as an octal
2891 number or as symbolic permissions, like with
2892 @command{chmod}. @xref{override}.
2893
2894 @opsummary{mtime}
2895 @item --mtime=@var{date}
2896
2897 When adding files to an archive, @command{tar} will use @var{date} as
2898 the modification time of members when creating archives, instead of
2899 their actual modification times. The value of @var{date} can be
2900 either a textual date representation (@pxref{Date input formats}) or a
2901 name of the existing file, starting with @samp{/} or @samp{.}. In the
2902 latter case, the modification time of that file is used. @xref{override}.
2903
2904 @opsummary{multi-volume}
2905 @item --multi-volume
2906 @itemx -M
2907
2908 Informs @command{tar} that it should create or otherwise operate on a
2909 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2910
2911 @opsummary{new-volume-script}
2912 @item --new-volume-script
2913
2914 (see @option{--info-script})
2915
2916 @opsummary{newer}
2917 @item --newer=@var{date}
2918 @itemx --after-date=@var{date}
2919 @itemx -N
2920
2921 When creating an archive, @command{tar} will only add files that have changed
2922 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2923 is taken to be the name of a file whose data modification time specifies
2924 the date. @xref{after}.
2925
2926 @opsummary{newer-mtime}
2927 @item --newer-mtime=@var{date}
2928
2929 Like @option{--newer}, but add only files whose
2930 contents have changed (as opposed to just @option{--newer}, which will
2931 also back up files for which any status information has
2932 changed). @xref{after}.
2933
2934 @opsummary{no-anchored}
2935 @item --no-anchored
2936 An exclude pattern can match any subsequence of the name's components.
2937 @xref{controlling pattern-matching}.
2938
2939 @opsummary{no-auto-compress}
2940 @item --no-auto-compress
2941
2942 Disables automatic compressed format recognition based on the archive
2943 suffix. @xref{--auto-compress}. @xref{gzip}.
2944
2945 @opsummary{no-check-device}
2946 @item --no-check-device
2947 Do not check device numbers when creating a list of modified files
2948 for incremental archiving. @xref{device numbers}, for
2949 a detailed description.
2950
2951 @opsummary{no-delay-directory-restore}
2952 @item --no-delay-directory-restore
2953
2954 Modification times and permissions of extracted
2955 directories are set when all files from this directory have been
2956 extracted. This is the default.
2957 @xref{Directory Modification Times and Permissions}.
2958
2959 @opsummary{no-ignore-case}
2960 @item --no-ignore-case
2961 Use case-sensitive matching.
2962 @xref{controlling pattern-matching}.
2963
2964 @opsummary{no-ignore-command-error}
2965 @item --no-ignore-command-error
2966 Print warnings about subprocesses that terminated with a nonzero exit
2967 code. @xref{Writing to an External Program}.
2968
2969 @opsummary{no-null}
2970 @item --no-null
2971
2972 If the @option{--null} option was given previously, this option
2973 cancels its effect, so that any following @option{--files-from}
2974 options will expect their file lists to be newline-terminated.
2975
2976 @opsummary{no-overwrite-dir}
2977 @item --no-overwrite-dir
2978
2979 Preserve metadata of existing directories when extracting files
2980 from an archive. @xref{Overwrite Old Files}.
2981
2982 @opsummary{no-quote-chars}
2983 @item --no-quote-chars=@var{string}
2984 Remove characters listed in @var{string} from the list of quoted
2985 characters set by the previous @option{--quote-chars} option
2986 (@pxref{quoting styles}).
2987
2988 @opsummary{no-recursion}
2989 @item --no-recursion
2990
2991 With this option, @command{tar} will not recurse into directories.
2992 @xref{recurse}.
2993
2994 @opsummary{no-same-owner}
2995 @item --no-same-owner
2996 @itemx -o
2997
2998 When extracting an archive, do not attempt to preserve the owner
2999 specified in the @command{tar} archive. This the default behavior
3000 for ordinary users.
3001
3002 @opsummary{no-same-permissions}
3003 @item --no-same-permissions
3004
3005 When extracting an archive, subtract the user's umask from files from
3006 the permissions specified in the archive. This is the default behavior
3007 for ordinary users.
3008
3009 @opsummary{no-seek}
3010 @item --no-seek
3011
3012 The archive media does not support seeks to arbitrary
3013 locations. Usually @command{tar} determines automatically whether
3014 the archive can be seeked or not. Use this option to disable this
3015 mechanism.
3016
3017 @opsummary{no-unquote}
3018 @item --no-unquote
3019 Treat all input file or member names literally, do not interpret
3020 escape sequences. @xref{input name quoting}.
3021
3022 @opsummary{no-wildcards}
3023 @item --no-wildcards
3024 Do not use wildcards.
3025 @xref{controlling pattern-matching}.
3026
3027 @opsummary{no-wildcards-match-slash}
3028 @item --no-wildcards-match-slash
3029 Wildcards do not match @samp{/}.
3030 @xref{controlling pattern-matching}.
3031
3032 @opsummary{null}
3033 @item --null
3034
3035 When @command{tar} is using the @option{--files-from} option, this option
3036 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
3037 @command{tar} can correctly work with file names that contain newlines.
3038 @xref{nul}.
3039
3040 @opsummary{numeric-owner}
3041 @item --numeric-owner
3042
3043 This option will notify @command{tar} that it should use numeric user
3044 and group IDs when creating a @command{tar} file, rather than names.
3045 @xref{Attributes}.
3046
3047 @item -o
3048 The function of this option depends on the action @command{tar} is
3049 performing. When extracting files, @option{-o} is a synonym for
3050 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3051 restoring ownership of files being extracted.
3052
3053 When creating an archive, it is a synonym for
3054 @option{--old-archive}. This behavior is for compatibility
3055 with previous versions of @GNUTAR{}, and will be
3056 removed in future releases.
3057
3058 @xref{Changes}, for more information.
3059
3060 @opsummary{occurrence}
3061 @item --occurrence[=@var{number}]
3062
3063 This option can be used in conjunction with one of the subcommands
3064 @option{--delete}, @option{--diff}, @option{--extract} or
3065 @option{--list} when a list of files is given either on the command
3066 line or via @option{-T} option.
3067
3068 This option instructs @command{tar} to process only the @var{number}th
3069 occurrence of each named file. @var{Number} defaults to 1, so
3070
3071 @smallexample
3072 tar -x -f archive.tar --occurrence filename
3073 @end smallexample
3074
3075 @noindent
3076 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3077 and will terminate without scanning to the end of the archive.
3078
3079 @opsummary{old-archive}
3080 @item --old-archive
3081 Synonym for @option{--format=v7}.
3082
3083 @opsummary{one-file-system}
3084 @item --one-file-system
3085 Used when creating an archive. Prevents @command{tar} from recursing into
3086 directories that are on different file systems from the current
3087 directory.
3088
3089 @opsummary{overwrite}
3090 @item --overwrite
3091
3092 Overwrite existing files and directory metadata when extracting files
3093 from an archive. @xref{Overwrite Old Files}.
3094
3095 @opsummary{overwrite-dir}
3096 @item --overwrite-dir
3097
3098 Overwrite the metadata of existing directories when extracting files
3099 from an archive. @xref{Overwrite Old Files}.
3100
3101 @opsummary{owner}
3102 @item --owner=@var{user}
3103
3104 Specifies that @command{tar} should use @var{user} as the owner of members
3105 when creating archives, instead of the user associated with the source
3106 file. @var{user} can specify a symbolic name, or a numeric
3107 @acronym{ID}, or both as @var{name}:@var{id}.
3108 @xref{override}.
3109
3110 This option does not affect extraction from archives.
3111
3112 @opsummary{pax-option}
3113 @item --pax-option=@var{keyword-list}
3114 This option enables creation of the archive in @acronym{POSIX.1-2001}
3115 format (@pxref{posix}) and modifies the way @command{tar} handles the
3116 extended header keywords. @var{Keyword-list} is a comma-separated
3117 list of keyword options. @xref{PAX keywords}, for a detailed
3118 discussion.
3119
3120 @opsummary{portability}
3121 @item --portability
3122 @itemx --old-archive
3123 Synonym for @option{--format=v7}.
3124
3125 @opsummary{posix}
3126 @item --posix
3127 Same as @option{--format=posix}.
3128
3129 @opsummary{preserve}
3130 @item --preserve
3131
3132 Synonymous with specifying both @option{--preserve-permissions} and
3133 @option{--same-order}. @xref{Setting Access Permissions}.
3134
3135 @opsummary{preserve-order}
3136 @item --preserve-order
3137
3138 (See @option{--same-order}; @pxref{Reading}.)
3139
3140 @opsummary{preserve-permissions}
3141 @opsummary{same-permissions}
3142 @item --preserve-permissions
3143 @itemx --same-permissions
3144 @itemx -p
3145
3146 When @command{tar} is extracting an archive, it normally subtracts the
3147 users' umask from the permissions specified in the archive and uses
3148 that number as the permissions to create the destination file.
3149 Specifying this option instructs @command{tar} that it should use the
3150 permissions directly from the archive. @xref{Setting Access Permissions}.
3151
3152 @opsummary{quote-chars}
3153 @item --quote-chars=@var{string}
3154 Always quote characters from @var{string}, even if the selected
3155 quoting style would not quote them (@pxref{quoting styles}).
3156
3157 @opsummary{quoting-style}
3158 @item --quoting-style=@var{style}
3159 Set quoting style to use when printing member and file names
3160 (@pxref{quoting styles}). Valid @var{style} values are:
3161 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3162 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3163 style is @code{escape}, unless overridden while configuring the
3164 package.
3165
3166 @opsummary{read-full-records}
3167 @item --read-full-records
3168 @itemx -B
3169
3170 Specifies that @command{tar} should reblock its input, for reading
3171 from pipes on systems with buggy implementations. @xref{Reading}.
3172
3173 @opsummary{record-size}
3174 @item --record-size=@var{size}[@var{suf}]
3175
3176 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3177 archive. The argument can be suffixed with a @dfn{size suffix}, e.g.
3178 @option{--record-size=10K} for 10 Kilobytes. @xref{size-suffixes},
3179 for a list of valid suffixes. @xref{Blocking Factor}, for a detailed
3180 description of this option.
3181
3182 @opsummary{recursion}
3183 @item --recursion
3184
3185 With this option, @command{tar} recurses into directories (default).
3186 @xref{recurse}.
3187
3188 @opsummary{recursive-unlink}
3189 @item --recursive-unlink
3190
3191 Remove existing
3192 directory hierarchies before extracting directories of the same name
3193 from the archive. @xref{Recursive Unlink}.
3194
3195 @opsummary{remove-files}
3196 @item --remove-files
3197
3198 Directs @command{tar} to remove the source file from the file system after
3199 appending it to an archive. @xref{remove files}.
3200
3201 @opsummary{restrict}
3202 @item --restrict
3203
3204 Disable use of some potentially harmful @command{tar} options.
3205 Currently this option disables shell invocation from multi-volume menu
3206 (@pxref{Using Multiple Tapes}).
3207
3208 @opsummary{rmt-command}
3209 @item --rmt-command=@var{cmd}
3210
3211 Notifies @command{tar} that it should use @var{cmd} instead of
3212 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3213
3214 @opsummary{rsh-command}
3215 @item --rsh-command=@var{cmd}
3216
3217 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3218 devices. @xref{Device}.
3219
3220 @opsummary{same-order}
3221 @item --same-order
3222 @itemx --preserve-order
3223 @itemx -s
3224
3225 This option is an optimization for @command{tar} when running on machines with
3226 small amounts of memory. It informs @command{tar} that the list of file
3227 arguments has already been sorted to match the order of files in the
3228 archive. @xref{Reading}.
3229
3230 @opsummary{same-owner}
3231 @item --same-owner
3232
3233 When extracting an archive, @command{tar} will attempt to preserve the owner
3234 specified in the @command{tar} archive with this option present.
3235 This is the default behavior for the superuser; this option has an
3236 effect only for ordinary users. @xref{Attributes}.
3237
3238 @opsummary{same-permissions}
3239 @item --same-permissions
3240
3241 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3242
3243 @opsummary{seek}
3244 @item --seek
3245 @itemx -n
3246
3247 Assume that the archive media supports seeks to arbitrary
3248 locations. Usually @command{tar} determines automatically whether
3249 the archive can be seeked or not. This option is intended for use
3250 in cases when such recognition fails. It takes effect only if the
3251 archive is open for reading (e.g. with @option{--list} or
3252 @option{--extract} options).
3253
3254 @opsummary{show-defaults}
3255 @item --show-defaults
3256
3257 Displays the default options used by @command{tar} and exits
3258 successfully. This option is intended for use in shell scripts.
3259 Here is an example of what you can see using this option:
3260
3261 @smallexample
3262 $ @kbd{tar --show-defaults}
3263 --format=gnu -f- -b20 --quoting-style=escape
3264 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3265 @end smallexample
3266
3267 @noindent
3268 Notice, that this option outputs only one line. The example output
3269 above has been split to fit page boundaries. @xref{defaults}.
3270
3271 @opsummary{show-omitted-dirs}
3272 @item --show-omitted-dirs
3273
3274 Instructs @command{tar} to mention the directories it is skipping when
3275 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3276
3277 @opsummary{show-snapshot-field-ranges}
3278 @item --show-snapshot-field-ranges
3279
3280 Displays the range of values allowed by this version of @command{tar}
3281 for each field in the snapshot file, then exits successfully.
3282 @xref{Snapshot Files}.
3283
3284 @opsummary{show-transformed-names}
3285 @opsummary{show-stored-names}
3286 @item --show-transformed-names
3287 @itemx --show-stored-names
3288
3289 Display file or member names after applying any transformations
3290 (@pxref{transform}). In particular, when used in conjunction with one of
3291 the archive creation operations it instructs @command{tar} to list the
3292 member names stored in the archive, as opposed to the actual file
3293 names. @xref{listing member and file names}.
3294
3295 @opsummary{skip-old-files}
3296 @item --skip-old-files
3297
3298 Do not overwrite existing files when extracting files from an
3299 archive. @xref{Keep Old Files}.
3300
3301 This option differs from @option{--keep-old-files} in that it does not
3302 treat such files as an error, instead it just silently avoids
3303 overwriting them.
3304
3305 The @option{--warning=existing-file} option can be used together with
3306 this option to produce warning messages about existing old files
3307 (@pxref{warnings}).
3308
3309 @opsummary{sparse}
3310 @item --sparse
3311 @itemx -S
3312
3313 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3314 sparse files efficiently. @xref{sparse}.
3315
3316 @opsummary{sparse-version}
3317 @item --sparse-version=@var{version}
3318
3319 Specifies the @dfn{format version} to use when archiving sparse
3320 files. Implies @option{--sparse}. @xref{sparse}. For the description
3321 of the supported sparse formats, @xref{Sparse Formats}.
3322
3323 @opsummary{starting-file}
3324 @item --starting-file=@var{name}
3325 @itemx -K @var{name}
3326
3327 This option affects extraction only; @command{tar} will skip extracting
3328 files in the archive until it finds one that matches @var{name}.
3329 @xref{Scarce}.
3330
3331 @opsummary{strip-components}
3332 @item --strip-components=@var{number}
3333 Strip given @var{number} of leading components from file names before
3334 extraction. For example, if archive @file{archive.tar} contained
3335 @file{/some/file/name}, then running
3336
3337 @smallexample
3338 tar --extract --file archive.tar --strip-components=2
3339 @end smallexample
3340
3341 @noindent
3342 would extract this file to file @file{name}.
3343
3344 @opsummary{suffix}
3345 @item --suffix=@var{suffix}
3346
3347 Alters the suffix @command{tar} uses when backing up files from the default
3348 @samp{~}. @xref{backup}.
3349
3350 @opsummary{tape-length}
3351 @item --tape-length=@var{num}[@var{suf}]
3352 @itemx -L @var{num}[@var{suf}]
3353
3354 Specifies the length of tapes that @command{tar} is writing as being
3355 @w{@var{num} x 1024} bytes long. If optional @var{suf} is given, it
3356 specifies a multiplicative factor to be used instead of 1024. For
3357 example, @samp{-L2M} means 2 megabytes. @xref{size-suffixes}, for a
3358 list of allowed suffixes. @xref{Using Multiple Tapes}, for a detailed
3359 discussion of this option.
3360
3361 @opsummary{test-label}
3362 @item --test-label
3363
3364 Reads the volume label. If an argument is specified, test whether it
3365 matches the volume label. @xref{--test-label option}.
3366
3367 @opsummary{to-command}
3368 @item --to-command=@var{command}
3369
3370 During extraction @command{tar} will pipe extracted files to the
3371 standard input of @var{command}. @xref{Writing to an External Program}.
3372
3373 @opsummary{to-stdout}
3374 @item --to-stdout
3375 @itemx -O
3376
3377 During extraction, @command{tar} will extract files to stdout rather
3378 than to the file system. @xref{Writing to Standard Output}.
3379
3380 @opsummary{totals}
3381 @item --totals[=@var{signo}]
3382
3383 Displays the total number of bytes transferred when processing an
3384 archive. If an argument is given, these data are displayed on
3385 request, when signal @var{signo} is delivered to @command{tar}.
3386 @xref{totals}.
3387
3388 @opsummary{touch}
3389 @item --touch
3390 @itemx -m
3391
3392 Sets the data modification time of extracted files to the extraction time,
3393 rather than the data modification time stored in the archive.
3394 @xref{Data Modification Times}.
3395
3396 @opsummary{transform}
3397 @opsummary{xform}
3398 @item --transform=@var{sed-expr}
3399 @itemx --xform=@var{sed-expr}
3400 Transform file or member names using @command{sed} replacement expression
3401 @var{sed-expr}. For example,
3402
3403 @smallexample
3404 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3405 @end smallexample
3406
3407 @noindent
3408 will add to @file{archive} files from the current working directory,
3409 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3410 discussion, @xref{transform}.
3411
3412 To see transformed member names in verbose listings, use
3413 @option{--show-transformed-names} option
3414 (@pxref{show-transformed-names}).
3415
3416 @opsummary{uncompress}
3417 @item --uncompress
3418
3419 (See @option{--compress}, @pxref{gzip})
3420
3421 @opsummary{ungzip}
3422 @item --ungzip
3423
3424 (See @option{--gzip}, @pxref{gzip})
3425
3426 @opsummary{unlink-first}
3427 @item --unlink-first
3428 @itemx -U
3429
3430 Directs @command{tar} to remove the corresponding file from the file
3431 system before extracting it from the archive. @xref{Unlink First}.
3432
3433 @opsummary{unquote}
3434 @item --unquote
3435 Enable unquoting input file or member names (default). @xref{input
3436 name quoting}.
3437
3438 @opsummary{use-compress-program}
3439 @item --use-compress-program=@var{prog}
3440 @itemx -I=@var{prog}
3441
3442 Instructs @command{tar} to access the archive through @var{prog}, which is
3443 presumed to be a compression program of some sort. @xref{gzip}.
3444
3445 @opsummary{utc}
3446 @item --utc
3447
3448 Display file modification dates in @acronym{UTC}. This option implies
3449 @option{--verbose}.
3450
3451 @opsummary{verbose}
3452 @item --verbose
3453 @itemx -v
3454
3455 Specifies that @command{tar} should be more verbose about the
3456 operations it is performing. This option can be specified multiple
3457 times for some operations to increase the amount of information displayed.
3458 @xref{verbose}.
3459
3460 @opsummary{verify}
3461 @item --verify
3462 @itemx -W
3463
3464 Verifies that the archive was correctly written when creating an
3465 archive. @xref{verify}.
3466
3467 @opsummary{version}
3468 @item --version
3469
3470 Print information about the program's name, version, origin and legal
3471 status, all on standard output, and then exit successfully.
3472 @xref{help}.
3473
3474 @opsummary{volno-file}
3475 @item --volno-file=@var{file}
3476
3477 Used in conjunction with @option{--multi-volume}. @command{tar} will
3478 keep track of which volume of a multi-volume archive it is working in
3479 @var{file}. @xref{volno-file}.
3480
3481 @opsummary{warning}
3482 @item --warning=@var{keyword}
3483
3484 Enable or disable warning messages identified by @var{keyword}. The
3485 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3486 @xref{warnings}.
3487
3488 @opsummary{wildcards}
3489 @item --wildcards
3490 Use wildcards when matching member names with patterns.
3491 @xref{controlling pattern-matching}.
3492
3493 @opsummary{wildcards-match-slash}
3494 @item --wildcards-match-slash
3495 Wildcards match @samp{/}.
3496 @xref{controlling pattern-matching}.
3497
3498 @opsummary{xz}
3499 @item --xz
3500 @itemx -J
3501 Use @command{xz} for compressing or decompressing the archives. @xref{gzip}.
3502
3503 @end table
3504
3505 @node Short Option Summary
3506 @subsection Short Options Cross Reference
3507
3508 Here is an alphabetized list of all of the short option forms, matching
3509 them with the equivalent long option.
3510
3511 @multitable @columnfractions 0.20 0.80
3512 @headitem Short Option @tab Reference
3513
3514 @item -A @tab @ref{--concatenate}.
3515
3516 @item -B @tab @ref{--read-full-records}.
3517
3518 @item -C @tab @ref{--directory}.
3519
3520 @item -F @tab @ref{--info-script}.
3521
3522 @item -G @tab @ref{--incremental}.
3523
3524 @item -J @tab @ref{--xz}.
3525
3526 @item -K @tab @ref{--starting-file}.
3527
3528 @item -L @tab @ref{--tape-length}.
3529
3530 @item -M @tab @ref{--multi-volume}.
3531
3532 @item -N @tab @ref{--newer}.
3533
3534 @item -O @tab @ref{--to-stdout}.
3535
3536 @item -P @tab @ref{--absolute-names}.
3537
3538 @item -R @tab @ref{--block-number}.
3539
3540 @item -S @tab @ref{--sparse}.
3541
3542 @item -T @tab @ref{--files-from}.
3543
3544 @item -U @tab @ref{--unlink-first}.
3545
3546 @item -V @tab @ref{--label}.
3547
3548 @item -W @tab @ref{--verify}.
3549
3550 @item -X @tab @ref{--exclude-from}.
3551
3552 @item -Z @tab @ref{--compress}.
3553
3554 @item -b @tab @ref{--blocking-factor}.
3555
3556 @item -c @tab @ref{--create}.
3557
3558 @item -d @tab @ref{--compare}.
3559
3560 @item -f @tab @ref{--file}.
3561
3562 @item -g @tab @ref{--listed-incremental}.
3563
3564 @item -h @tab @ref{--dereference}.
3565
3566 @item -i @tab @ref{--ignore-zeros}.
3567
3568 @item -j @tab @ref{--bzip2}.
3569
3570 @item -k @tab @ref{--keep-old-files}.
3571
3572 @item -l @tab @ref{--check-links}.
3573
3574 @item -m @tab @ref{--touch}.
3575
3576 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3577 @ref{--portability}.
3578
3579 The latter usage is deprecated. It is retained for compatibility with
3580 the earlier versions of @GNUTAR{}. In future releases
3581 @option{-o} will be equivalent to @option{--no-same-owner} only.
3582
3583 @item -p @tab @ref{--preserve-permissions}.
3584
3585 @item -r @tab @ref{--append}.
3586
3587 @item -s @tab @ref{--same-order}.
3588
3589 @item -t @tab @ref{--list}.
3590
3591 @item -u @tab @ref{--update}.
3592
3593 @item -v @tab @ref{--verbose}.
3594
3595 @item -w @tab @ref{--interactive}.
3596
3597 @item -x @tab @ref{--extract}.
3598
3599 @item -z @tab @ref{--gzip}.
3600
3601 @end multitable
3602
3603 @node help
3604 @section @GNUTAR{} documentation
3605
3606 @cindex Getting program version number
3607 @opindex version
3608 @cindex Version of the @command{tar} program
3609 Being careful, the first thing is really checking that you are using
3610 @GNUTAR{}, indeed. The @option{--version} option
3611 causes @command{tar} to print information about its name, version,
3612 origin and legal status, all on standard output, and then exit
3613 successfully. For example, @w{@samp{tar --version}} might print:
3614
3615 @smallexample
3616 tar (GNU tar) @value{VERSION}
3617 Copyright (C) 2013 Free Software Foundation, Inc.
3618 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3619 This is free software: you are free to change and redistribute it.
3620 There is NO WARRANTY, to the extent permitted by law.
3621
3622 Written by John Gilmore and Jay Fenlason.
3623 @end smallexample
3624
3625 @noindent
3626 The first occurrence of @samp{tar} in the result above is the program
3627 name in the package (for example, @command{rmt} is another program),
3628 while the second occurrence of @samp{tar} is the name of the package
3629 itself, containing possibly many programs. The package is currently
3630 named @samp{tar}, after the name of the main program it
3631 contains@footnote{There are plans to merge the @command{cpio} and
3632 @command{tar} packages into a single one which would be called
3633 @code{paxutils}. So, who knows if, one of this days, the
3634 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3635 paxutils) 3.2}}.}.
3636
3637 @cindex Obtaining help
3638 @cindex Listing all @command{tar} options
3639 @xopindex{help, introduction}
3640 Another thing you might want to do is checking the spelling or meaning
3641 of some particular @command{tar} option, without resorting to this
3642 manual, for once you have carefully read it. @GNUTAR{}
3643 has a short help feature, triggerable through the
3644 @option{--help} option. By using this option, @command{tar} will
3645 print a usage message listing all available options on standard
3646 output, then exit successfully, without doing anything else and
3647 ignoring all other options. Even if this is only a brief summary, it
3648 may be several screens long. So, if you are not using some kind of
3649 scrollable window, you might prefer to use something like:
3650
3651 @smallexample
3652 $ @kbd{tar --help | less}
3653 @end smallexample
3654
3655 @noindent
3656 presuming, here, that you like using @command{less} for a pager. Other
3657 popular pagers are @command{more} and @command{pg}. If you know about some
3658 @var{keyword} which interests you and do not want to read all the
3659 @option{--help} output, another common idiom is doing:
3660
3661 @smallexample
3662 tar --help | grep @var{keyword}
3663 @end smallexample
3664
3665 @noindent
3666 for getting only the pertinent lines. Notice, however, that some
3667 @command{tar} options have long description lines and the above
3668 command will list only the first of them.
3669
3670 The exact look of the option summary displayed by @kbd{tar --help} is
3671 configurable. @xref{Configuring Help Summary}, for a detailed description.
3672
3673 @opindex usage
3674 If you only wish to check the spelling of an option, running @kbd{tar
3675 --usage} may be a better choice. This will display a terse list of
3676 @command{tar} options without accompanying explanations.
3677
3678 The short help output is quite succinct, and you might have to get
3679 back to the full documentation for precise points. If you are reading
3680 this paragraph, you already have the @command{tar} manual in some
3681 form. This manual is available in a variety of forms from
3682 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3683 distribution, provided you have @TeX{} already installed somewhere,
3684 and a laser printer around. Just configure the distribution, execute
3685 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3686 usual way (contact your local guru to know how). If @GNUTAR{}
3687 has been conveniently installed at your place, this
3688 manual is also available in interactive, hypertextual form as an Info
3689 file. Just call @w{@samp{info tar}} or, if you do not have the
3690 @command{info} program handy, use the Info reader provided within
3691 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3692
3693 There is currently no @code{man} page for @GNUTAR{}.
3694 If you observe such a @code{man} page on the system you are running,
3695 either it does not belong to @GNUTAR{}, or it has not
3696 been produced by @acronym{GNU}. Some package maintainers convert
3697 @kbd{tar --help} output to a man page, using @command{help2man}. In
3698 any case, please bear in mind that the authoritative source of
3699 information about @GNUTAR{} is this Texinfo documentation.
3700
3701 @node defaults
3702 @section Obtaining @GNUTAR{} default values
3703
3704 @opindex show-defaults
3705 @GNUTAR{} has some predefined defaults that are used when you do not
3706 explicitly specify another values. To obtain a list of such
3707 defaults, use @option{--show-defaults} option. This will output the
3708 values in the form of @command{tar} command line options:
3709
3710 @smallexample
3711 @group
3712 $ @kbd{tar --show-defaults}
3713 --format=gnu -f- -b20 --quoting-style=escape
3714 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3715 @end group
3716 @end smallexample
3717
3718 @noindent
3719 Notice, that this option outputs only one line. The example output above
3720 has been split to fit page boundaries.
3721
3722 @noindent
3723 The above output shows that this version of @GNUTAR{} defaults to
3724 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3725 output as the archive, if no @option{--file} option has been given
3726 (@pxref{file tutorial}), the default blocking factor is 20
3727 (@pxref{Blocking Factor}). It also shows the default locations where
3728 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3729
3730 @node verbose
3731 @section Checking @command{tar} progress
3732
3733 Typically, @command{tar} performs most operations without reporting any
3734 information to the user except error messages. When using @command{tar}
3735 with many options, particularly ones with complicated or
3736 difficult-to-predict behavior, it is possible to make serious mistakes.
3737 @command{tar} provides several options that make observing @command{tar}
3738 easier. These options cause @command{tar} to print information as it
3739 progresses in its job, and you might want to use them just for being
3740 more careful about what is going on, or merely for entertaining
3741 yourself. If you have encountered a problem when operating on an
3742 archive, however, you may need more information than just an error
3743 message in order to solve the problem. The following options can be
3744 helpful diagnostic tools.
3745
3746 @cindex Verbose operation
3747 @opindex verbose
3748 Normally, the @option{--list} (@option{-t}) command to list an archive
3749 prints just the file names (one per line) and the other commands are
3750 silent. When used with most operations, the @option{--verbose}
3751 (@option{-v}) option causes @command{tar} to print the name of each
3752 file or archive member as it is processed. This and the other options
3753 which make @command{tar} print status information can be useful in
3754 monitoring @command{tar}.
3755
3756 With @option{--create} or @option{--extract}, @option{--verbose} used
3757 once just prints the names of the files or members as they are processed.
3758 Using it twice causes @command{tar} to print a longer listing
3759 (@xref{verbose member listing}, for the description) for each member.
3760 Since @option{--list} already prints the names of the members,
3761 @option{--verbose} used once with @option{--list} causes @command{tar}
3762 to print an @samp{ls -l} type listing of the files in the archive.
3763 The following examples both extract members with long list output:
3764
3765 @smallexample
3766 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3767 $ @kbd{tar xvvf archive.tar}
3768 @end smallexample
3769
3770 Verbose output appears on the standard output except when an archive is
3771 being written to the standard output, as with @samp{tar --create
3772 --file=- --verbose} (@samp{tar cvf -}, or even @samp{tar cv}---if the
3773 installer let standard output be the default archive). In that case
3774 @command{tar} writes verbose output to the standard error stream.
3775
3776 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3777 verbose output to @var{file} rather than to standard output or standard
3778 error.
3779
3780 @anchor{totals}
3781 @cindex Obtaining total status information
3782 @opindex totals
3783 The @option{--totals} option causes @command{tar} to print on the
3784 standard error the total amount of bytes transferred when processing
3785 an archive. When creating or appending to an archive, this option
3786 prints the number of bytes written to the archive and the average
3787 speed at which they have been written, e.g.:
3788
3789 @smallexample
3790 @group
3791 $ @kbd{tar -c -f archive.tar --totals /home}
3792 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3793 @end group
3794 @end smallexample
3795
3796 When reading an archive, this option displays the number of bytes
3797 read:
3798
3799 @smallexample
3800 @group
3801 $ @kbd{tar -x -f archive.tar --totals}
3802 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3803 @end group
3804 @end smallexample
3805
3806 Finally, when deleting from an archive, the @option{--totals} option
3807 displays both numbers plus number of bytes removed from the archive:
3808
3809 @smallexample
3810 @group
3811 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3812 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3813 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3814 Total bytes deleted: 1474048
3815 @end group
3816 @end smallexample
3817
3818 You can also obtain this information on request. When
3819 @option{--totals} is used with an argument, this argument is
3820 interpreted as a symbolic name of a signal, upon delivery of which the
3821 statistics is to be printed:
3822
3823 @table @option
3824 @item --totals=@var{signo}
3825 Print statistics upon delivery of signal @var{signo}. Valid arguments
3826 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3827 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3828 accepted.
3829 @end table
3830
3831 Both forms of @option{--totals} option can be used simultaneously.
3832 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3833 extract all members from its default archive and print statistics
3834 after finishing the extraction, as well as when receiving signal
3835 @code{SIGUSR1}.
3836
3837 @anchor{Progress information}
3838 @cindex Progress information
3839 The @option{--checkpoint} option prints an occasional message
3840 as @command{tar} reads or writes the archive. It is designed for
3841 those who don't need the more detailed (and voluminous) output of
3842 @option{--block-number} (@option{-R}), but do want visual confirmation
3843 that @command{tar} is actually making forward progress. By default it
3844 prints a message each 10 records read or written. This can be changed
3845 by giving it a numeric argument after an equal sign:
3846
3847 @smallexample
3848 $ @kbd{tar -c --checkpoint=1000} /var
3849 tar: Write checkpoint 1000
3850 tar: Write checkpoint 2000
3851 tar: Write checkpoint 3000
3852 @end smallexample
3853
3854 This example shows the default checkpoint message used by
3855 @command{tar}. If you place a dot immediately after the equal
3856 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3857 actually a shortcut for @option{--checkpoint=@var{n}
3858 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3859
3860 @smallexample
3861 $ @kbd{tar -c --checkpoint=.1000} /var
3862 ...
3863 @end smallexample
3864
3865 The @option{--checkpoint} option provides a flexible mechanism for
3866 executing arbitrary actions upon hitting checkpoints, see the next
3867 section (@pxref{checkpoints}), for more information on it.
3868
3869 @opindex show-omitted-dirs
3870 @anchor{show-omitted-dirs}
3871 The @option{--show-omitted-dirs} option, when reading an archive---with
3872 @option{--list} or @option{--extract}, for example---causes a message
3873 to be printed for each directory in the archive which is skipped.
3874 This happens regardless of the reason for skipping: the directory might
3875 not have been named on the command line (implicitly or explicitly),
3876 it might be excluded by the use of the
3877 @option{--exclude=@var{pattern}} option, or some other reason.
3878
3879 @opindex block-number
3880 @cindex Block number where error occurred
3881 @anchor{block-number}
3882 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3883 every message it would normally produce, the block number within the
3884 archive where the message was triggered. Also, supplementary messages
3885 are triggered when reading blocks full of NULs, or when hitting end of
3886 file on the archive. As of now, if the archive is properly terminated
3887 with a NUL block, the reading of the file may stop before end of file
3888 is met, so the position of end of file will not usually show when
3889 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3890 drains the archive before exiting when reading the
3891 archive from a pipe.
3892
3893 @cindex Error message, block number of
3894 This option is especially useful when reading damaged archives, since
3895 it helps pinpoint the damaged sections. It can also be used with
3896 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3897 choose among several backup tapes when retrieving a file later, in
3898 favor of the tape where the file appears earliest (closest to the
3899 front of the tape). @xref{backup}.
3900
3901 @node checkpoints
3902 @section Checkpoints
3903 @cindex checkpoints, defined
3904 @opindex checkpoint
3905 @opindex checkpoint-action
3906
3907 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3908 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3909 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3910 periodically execute arbitrary actions.
3911
3912 The checkpoint facility is enabled using the following option:
3913
3914 @table @option
3915 @xopindex{checkpoint, defined}
3916 @item --checkpoint[=@var{n}]
3917 Schedule checkpoints before writing or reading each @var{n}th record.
3918 The default value for @var{n} is 10.
3919 @end table
3920
3921 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3922 These actions include: pausing, displaying textual messages, and
3923 executing arbitrary external programs. Actions are defined using
3924 the @option{--checkpoint-action} option.
3925
3926 @table @option
3927 @xopindex{checkpoint-action, defined}
3928 @item --checkpoint-action=@var{action}
3929 Execute an @var{action} at each checkpoint.
3930 @end table
3931
3932 @cindex @code{echo}, checkpoint action
3933 The simplest value of @var{action} is @samp{echo}. It instructs
3934 @command{tar} to display the default message on the standard error
3935 stream upon arriving at each checkpoint. The default message is (in
3936 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3937 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3938 Here, @var{n} represents ordinal number of the checkpoint.
3939
3940 In another locales, translated versions of this message are used.
3941
3942 This is the default action, so running:
3943
3944 @smallexample
3945 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3946 @end smallexample
3947
3948 @noindent
3949 is equivalent to:
3950
3951 @smallexample
3952 $ @kbd{tar -c --checkpoint=1000} /var
3953 @end smallexample
3954
3955 The @samp{echo} action also allows to supply a customized message.
3956 You do so by placing an equals sign and the message right after it,
3957 e.g.:
3958
3959 @smallexample
3960 --checkpoint-action="echo=Hit %s checkpoint #%u"
3961 @end smallexample
3962
3963 The @samp{%s} and @samp{%u} in the above example are
3964 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3965 the @dfn{type} of the checkpoint: @samp{write} or
3966 @samp{read} (or a corresponding translated version in locales other
3967 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3968 the ordinal number of the checkpoint. Thus, the above example could
3969 produce the following output when used with the @option{--create}
3970 option:
3971
3972 @smallexample
3973 tar: Hit write checkpoint #10
3974 tar: Hit write checkpoint #20
3975 tar: Hit write checkpoint #30
3976 @end smallexample
3977
3978 Aside from meta-character expansion, the message string is subject to
3979 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3980 replaced with their corresponding @acronym{ASCII} characters
3981 (@pxref{escape sequences}). E.g. the following action will produce an
3982 audible bell and the message described above at each checkpoint:
3983
3984 @smallexample
3985 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3986 @end smallexample
3987
3988 @cindex @code{bell}, checkpoint action
3989 There is also a special action which produces an audible signal:
3990 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3991 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3992 whereas @samp{echo='\a'} sends it to the standard error.
3993
3994 @cindex @code{ttyout}, checkpoint action
3995 The @samp{ttyout=@var{string}} action outputs @var{string} to
3996 @file{/dev/tty}, so it can be used even if the standard output is
3997 redirected elsewhere. The @var{string} is subject to the same
3998 modifications as with @samp{echo} action. In contrast to the latter,
3999 @samp{ttyout} does not prepend @command{tar} executable name to the
4000 string, nor does it output a newline after it. For example, the
4001 following action will print the checkpoint message at the same screen
4002 line, overwriting any previous message:
4003
4004 @smallexample
4005 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
4006 @end smallexample
4007
4008 @cindex @code{dot}, checkpoint action
4009 Another available checkpoint action is @samp{dot} (or @samp{.}). It
4010 instructs @command{tar} to print a single dot on the standard listing
4011 stream, e.g.:
4012
4013 @smallexample
4014 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
4015 ...
4016 @end smallexample
4017
4018 For compatibility with previous @GNUTAR{} versions, this action can
4019 be abbreviated by placing a dot in front of the checkpoint frequency,
4020 as shown in the previous section.
4021
4022 @cindex @code{sleep}, checkpoint action
4023 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
4024 amount of seconds. The following example will stop for 30 seconds at each
4025 checkpoint:
4026
4027 @smallexample
4028 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
4029 @end smallexample
4030
4031 @anchor{checkpoint exec}
4032 @cindex @code{exec}, checkpoint action
4033 Finally, the @code{exec} action executes a given external command.
4034 For example:
4035
4036 @smallexample
4037 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4038 @end smallexample
4039
4040 The supplied command can be any valid command invocation, with or
4041 without additional command line arguments. If it does contain
4042 arguments, don't forget to quote it to prevent it from being split by
4043 the shell. @xref{external, Running External Commands}, for more detail.
4044
4045 The command gets a copy of @command{tar}'s environment plus the
4046 following variables:
4047
4048 @table @env
4049 @vrindex TAR_VERSION, checkpoint script environment
4050 @item TAR_VERSION
4051 @GNUTAR{} version number.
4052
4053 @vrindex TAR_ARCHIVE, checkpoint script environment
4054 @item TAR_ARCHIVE
4055 The name of the archive @command{tar} is processing.
4056
4057 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4058 @item TAR_BLOCKING_FACTOR
4059 Current blocking factor (@pxref{Blocking}).
4060
4061 @vrindex TAR_CHECKPOINT, checkpoint script environment
4062 @item TAR_CHECKPOINT
4063 Number of the checkpoint.
4064
4065 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4066 @item TAR_SUBCOMMAND
4067 A short option describing the operation @command{tar} is executing.
4068 @xref{Operations}, for a complete list of subcommand options.
4069
4070 @vrindex TAR_FORMAT, checkpoint script environment
4071 @item TAR_FORMAT
4072 Format of the archive being processed. @xref{Formats}, for a complete
4073 list of archive format names.
4074 @end table
4075
4076 These environment variables can also be passed as arguments to the
4077 command, provided that they are properly escaped, for example:
4078
4079 @smallexample
4080 @kbd{tar -c -f arc.tar \
4081 --checkpoint-action='exec=/sbin/cpoint $TAR_FILENAME'}
4082 @end smallexample
4083
4084 @noindent
4085 Notice single quotes to prevent variable names from being expanded by
4086 the shell when invoking @command{tar}.
4087
4088 Any number of actions can be defined, by supplying several
4089 @option{--checkpoint-action} options in the command line. For
4090 example, the command below displays two messages, pauses
4091 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4092
4093 @example
4094 @group
4095 $ @kbd{tar -c -f arc.tar \
4096 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4097 --checkpoint-action='echo=Sleeping for 30 seconds' \
4098 --checkpoint-action='sleep=30' \
4099 --checkpoint-action='exec=/sbin/cpoint'}
4100 @end group
4101 @end example
4102
4103 This example also illustrates the fact that
4104 @option{--checkpoint-action} can be used without
4105 @option{--checkpoint}. In this case, the default checkpoint frequency
4106 (at each 10th record) is assumed.
4107
4108 @node warnings
4109 @section Controlling Warning Messages
4110
4111 Sometimes, while performing the requested task, @GNUTAR{} notices
4112 some conditions that are not exactly errors, but which the user
4113 should be aware of. When this happens, @command{tar} issues a
4114 @dfn{warning message} describing the condition. Warning messages
4115 are output to the standard error and they do not affect the exit
4116 code of @command{tar} command.
4117
4118 @xopindex{warning, explained}
4119 @GNUTAR{} allows the user to suppress some or all of its warning
4120 messages:
4121
4122 @table @option
4123 @item --warning=@var{keyword}
4124 Control display of the warning messages identified by @var{keyword}.
4125 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4126 suppressed. Otherwise, they are enabled.
4127
4128 Multiple @option{--warning} messages accumulate.
4129
4130 The tables below list allowed values for @var{keyword} along with the
4131 warning messages they control.
4132 @end table
4133
4134 @subheading Keywords controlling @command{tar} operation
4135 @table @asis
4136 @kwindex all
4137 @item all
4138 Enable all warning messages. This is the default.
4139 @kwindex none
4140 @item none
4141 Disable all warning messages.
4142 @kwindex filename-with-nuls
4143 @cindex @samp{file name read contains nul character}, warning message
4144 @item filename-with-nuls
4145 @samp{%s: file name read contains nul character}
4146 @kwindex alone-zero-block
4147 @cindex @samp{A lone zero block at}, warning message
4148 @item alone-zero-block
4149 @samp{A lone zero block at %s}
4150 @end table
4151
4152 @subheading Keywords applicable for @command{tar --create}
4153 @table @asis
4154 @kwindex cachedir
4155 @cindex @samp{contains a cache directory tag}, warning message
4156 @item cachedir
4157 @samp{%s: contains a cache directory tag %s; %s}
4158 @kwindex file-shrank
4159 @cindex @samp{File shrank by %s bytes}, warning message
4160 @item file-shrank
4161 @samp{%s: File shrank by %s bytes; padding with zeros}
4162 @kwindex xdev
4163 @cindex @samp{file is on a different filesystem}, warning message
4164 @item xdev
4165 @samp{%s: file is on a different filesystem; not dumped}
4166 @kwindex file-ignored
4167 @cindex @samp{Unknown file type; file ignored}, warning message
4168 @cindex @samp{socket ignored}, warning message
4169 @cindex @samp{door ignored}, warning message
4170 @item file-ignored
4171 @samp{%s: Unknown file type; file ignored}
4172 @*@samp{%s: socket ignored}
4173 @*@samp{%s: door ignored}
4174 @kwindex file-unchanged
4175 @cindex @samp{file is unchanged; not dumped}, warning message
4176 @item file-unchanged
4177 @samp{%s: file is unchanged; not dumped}
4178 @kwindex ignore-archive
4179 @cindex @samp{file is the archive; not dumped}, warning message
4180 @kwindex ignore-archive
4181 @cindex @samp{file is the archive; not dumped}, warning message
4182 @item ignore-archive
4183 @samp{%s: file is the archive; not dumped}
4184 @kwindex file-removed
4185 @cindex @samp{File removed before we read it}, warning message
4186 @item file-removed
4187 @samp{%s: File removed before we read it}
4188 @kwindex file-changed
4189 @cindex @samp{file changed as we read it}, warning message
4190 @item file-changed
4191 @samp{%s: file changed as we read it}
4192 @end table
4193
4194 @subheading Keywords applicable for @command{tar --extract}
4195 @table @asis
4196 @kwindex timestamp
4197 @cindex @samp{implausibly old time stamp %s}, warning message
4198 @cindex @samp{time stamp %s is %s s in the future}, warning message
4199 @item timestamp
4200 @samp{%s: implausibly old time stamp %s}
4201 @*@samp{%s: time stamp %s is %s s in the future}
4202 @kwindex contiguous-cast
4203 @cindex @samp{Extracting contiguous files as regular files}, warning message
4204 @item contiguous-cast
4205 @samp{Extracting contiguous files as regular files}
4206 @kwindex symlink-cast
4207 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4208 @item symlink-cast
4209 @samp{Attempting extraction of symbolic links as hard links}
4210 @kwindex unknown-cast
4211 @cindex @samp{Unknown file type '%c', extracted as normal file}, warning message
4212 @item unknown-cast
4213 @samp{%s: Unknown file type '%c', extracted as normal file}
4214 @kwindex ignore-newer
4215 @cindex @samp{Current %s is newer or same age}, warning message
4216 @item ignore-newer
4217 @samp{Current %s is newer or same age}
4218 @kwindex unknown-keyword
4219 @cindex @samp{Ignoring unknown extended header keyword '%s'}, warning message
4220 @item unknown-keyword
4221 @samp{Ignoring unknown extended header keyword '%s'}
4222 @kwindex decompress-program
4223 @item decompress-program
4224 Controls verbose description of failures occurring when trying to run
4225 alternative decompressor programs (@pxref{alternative decompression
4226 programs}). This warning is disabled by default (unless
4227 @option{--verbose} is used). A common example of what you can get
4228 when using this warning is:
4229
4230 @smallexample
4231 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4232 tar (child): cannot run compress: No such file or directory
4233 tar (child): trying gzip
4234 @end smallexample
4235
4236 This means that @command{tar} first tried to decompress
4237 @file{archive.Z} using @command{compress}, and, when that
4238 failed, switched to @command{gzip}.
4239 @kwindex record-size
4240 @cindex @samp{Record size = %lu blocks}, warning message
4241 @item record-size
4242 @samp{Record size = %lu blocks}
4243 @end table
4244
4245 @subheading Keywords controlling incremental extraction:
4246 @table @asis
4247 @kwindex rename-directory
4248 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4249 @cindex @samp{%s: Directory has been renamed}, warning message
4250 @item rename-directory
4251 @samp{%s: Directory has been renamed from %s}
4252 @*@samp{%s: Directory has been renamed}
4253 @kwindex new-directory
4254 @cindex @samp{%s: Directory is new}, warning message
4255 @item new-directory
4256 @samp{%s: Directory is new}
4257 @kwindex xdev
4258 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4259 @item xdev
4260 @samp{%s: directory is on a different device: not purging}
4261 @kwindex bad-dumpdir
4262 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4263 @item bad-dumpdir
4264 @samp{Malformed dumpdir: 'X' never used}
4265 @end table
4266
4267 @node interactive
4268 @section Asking for Confirmation During Operations
4269 @cindex Interactive operation
4270
4271 Typically, @command{tar} carries out a command without stopping for
4272 further instructions. In some situations however, you may want to
4273 exclude some files and archive members from the operation (for instance
4274 if disk or storage space is tight). You can do this by excluding
4275 certain files automatically (@pxref{Choosing}), or by performing
4276 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4277 @command{tar} also accepts @option{--confirmation} for this option.
4278
4279 @opindex interactive
4280 When the @option{--interactive} (@option{-w}) option is specified, before
4281 reading, writing, or deleting files, @command{tar} first prints a message
4282 for each such file, telling what operation it intends to take, then asks
4283 for confirmation on the terminal. The actions which require
4284 confirmation include adding a file to the archive, extracting a file
4285 from the archive, deleting a file from the archive, and deleting a file
4286 from disk. To confirm the action, you must type a line of input
4287 beginning with @samp{y}. If your input line begins with anything other
4288 than @samp{y}, @command{tar} skips that file.
4289
4290 If @command{tar} is reading the archive from the standard input,
4291 @command{tar} opens the file @file{/dev/tty} to support the interactive
4292 communications.
4293
4294 Verbose output is normally sent to standard output, separate from
4295 other error messages. However, if the archive is produced directly
4296 on standard output, then verbose output is mixed with errors on
4297 @code{stderr}. Producing the archive on standard output may be used
4298 as a way to avoid using disk space, when the archive is soon to be
4299 consumed by another process reading it, say. Some people felt the need
4300 of producing an archive on stdout, still willing to segregate between
4301 verbose output and error output. A possible approach would be using a
4302 named pipe to receive the archive, and having the consumer process to
4303 read from that named pipe. This has the advantage of letting standard
4304 output free to receive verbose output, all separate from errors.
4305
4306 @node external
4307 @section Running External Commands
4308
4309 Certain @GNUTAR{} operations imply running external commands that you
4310 supply on the command line. One of such operations is checkpointing,
4311 described above (@pxref{checkpoint exec}). Another example of this
4312 feature is the @option{-I} option, which allows you to supply the
4313 program to use for compressing or decompressing the archive
4314 (@pxref{use-compress-program}).
4315
4316 Whenever such operation is requested, @command{tar} first splits the
4317 supplied command into words much like the shell does. It then treats
4318 the first word as the name of the program or the shell script to execute
4319 and the rest of words as its command line arguments. The program,
4320 unless given as an absolute file name, is searched in the shell's
4321 @env{PATH}.
4322
4323 Any additional information is normally supplied to external commands
4324 in environment variables, specific to each particular operation. For
4325 example, the @option{--checkpoint-action=exec} option, defines the
4326 @env{TAR_ARCHIVE} variable to the name of the archive being worked
4327 upon. You can, should the need be, use these variables in the
4328 command line of the external command. For example:
4329
4330 @smallexample
4331 $ @kbd{tar -x -f archive.tar \
4332 --checkpoint=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'}
4333 @end smallexample
4334
4335 @noindent
4336 This command prints for each checkpoint its number and the name of the
4337 archive, using the same output line on the screen.
4338
4339 Notice the use of single quotes to prevent variable names from being
4340 expanded by the shell when invoking @command{tar}.
4341
4342 @node operations
4343 @chapter @GNUTAR{} Operations
4344
4345 @menu
4346 * Basic tar::
4347 * Advanced tar::
4348 * create options::
4349 * extract options::
4350 * backup::
4351 * Applications::
4352 * looking ahead::
4353 @end menu
4354
4355 @node Basic tar
4356 @section Basic @GNUTAR{} Operations
4357
4358 The basic @command{tar} operations, @option{--create} (@option{-c}),
4359 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4360 @option{-x}), are currently presented and described in the tutorial
4361 chapter of this manual. This section provides some complementary notes
4362 for these operations.
4363
4364 @table @option
4365 @xopindex{create, complementary notes}
4366 @item --create
4367 @itemx -c
4368
4369 Creating an empty archive would have some kind of elegance. One can
4370 initialize an empty archive and later use @option{--append}
4371 (@option{-r}) for adding all members. Some applications would not
4372 welcome making an exception in the way of adding the first archive
4373 member. On the other hand, many people reported that it is
4374 dangerously too easy for @command{tar} to destroy a magnetic tape with
4375 an empty archive@footnote{This is well described in @cite{Unix-haters
4376 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4377 Books, ISBN 1-56884-203-1.}. The two most common errors are:
4378
4379 @enumerate
4380 @item
4381 Mistakingly using @code{create} instead of @code{extract}, when the
4382 intent was to extract the full contents of an archive. This error
4383 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4384 the QWERTY keyboard. Instead of being unpacked, the archive then
4385 gets wholly destroyed. When users speak about @dfn{exploding} an
4386 archive, they usually mean something else :-).
4387
4388 @item
4389 Forgetting the argument to @code{file}, when the intent was to create
4390 an archive with a single file in it. This error is likely because a
4391 tired user can easily add the @kbd{f} key to the cluster of option
4392 letters, by the mere force of habit, without realizing the full
4393 consequence of doing so. The usual consequence is that the single
4394 file, which was meant to be saved, is rather destroyed.
4395 @end enumerate
4396
4397 So, recognizing the likelihood and the catastrophic nature of these
4398 errors, @GNUTAR{} now takes some distance from elegance, and
4399 cowardly refuses to create an archive when @option{--create} option is
4400 given, there are no arguments besides options, and
4401 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4402 around the cautiousness of @GNUTAR{} and nevertheless create an
4403 archive with nothing in it, one may still use, as the value for the
4404 @option{--files-from} option, a file with no names in it, as shown in
4405 the following commands:
4406
4407 @smallexample
4408 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4409 @kbd{tar -cf empty-archive.tar -T /dev/null}
4410 @end smallexample
4411
4412 @xopindex{extract, complementary notes}
4413 @item --extract
4414 @itemx --get
4415 @itemx -x
4416
4417 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4418
4419 @item @option{--list} (@option{-t})
4420
4421 @GNUTAR{} now shows dates as @samp{1996-08-30},
4422 while it used to show them as @samp{Aug 30 1996}. Preferably,
4423 people should get used to ISO 8601 dates. Local American dates should
4424 be made available again with full date localization support, once
4425 ready. In the meantime, programs not being localizable for dates
4426 should prefer international dates, that's really the way to go.
4427
4428 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4429 are curious, it contains a detailed explanation of the ISO 8601 standard.
4430
4431 @end table
4432
4433 @node Advanced tar
4434 @section Advanced @GNUTAR{} Operations
4435
4436 Now that you have learned the basics of using @GNUTAR{}, you may want
4437 to learn about further ways in which @command{tar} can help you.
4438
4439 This chapter presents five, more advanced operations which you probably
4440 won't use on a daily basis, but which serve more specialized functions.
4441 We also explain the different styles of options and why you might want
4442 to use one or another, or a combination of them in your @command{tar}
4443 commands. Additionally, this chapter includes options which allow you to
4444 define the output from @command{tar} more carefully, and provide help and
4445 error correction in special circumstances.
4446
4447 @FIXME{check this after the chapter is actually revised to make sure
4448 it still introduces the info in the chapter correctly : ).}
4449
4450 @menu
4451 * Operations::
4452 * append::
4453 * update::
4454 * concatenate::
4455 * delete::
4456 * compare::
4457 @end menu
4458
4459 @node Operations
4460 @subsection The Five Advanced @command{tar} Operations
4461
4462 @cindex basic operations
4463 In the last chapter, you learned about the first three operations to
4464 @command{tar}. This chapter presents the remaining five operations to
4465 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4466 @option{--delete}, and @option{--compare}.
4467
4468 You are not likely to use these operations as frequently as those
4469 covered in the last chapter; however, since they perform specialized
4470 functions, they are quite useful when you do need to use them. We
4471 will give examples using the same directory and files that you created
4472 in the last chapter. As you may recall, the directory is called
4473 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4474 and the two archive files you created are
4475 @samp{collection.tar} and @samp{music.tar}.
4476
4477 We will also use the archive files @samp{afiles.tar} and
4478 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4479 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4480 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4481
4482 Unless we state otherwise, all practicing you do and examples you follow
4483 in this chapter will take place in the @file{practice} directory that
4484 you created in the previous chapter; see @ref{prepare for examples}.
4485 (Below in this section, we will remind you of the state of the examples
4486 where the last chapter left them.)
4487
4488 The five operations that we will cover in this chapter are:
4489
4490 @table @option
4491 @item --append
4492 @itemx -r
4493 Add new entries to an archive that already exists.
4494 @item --update
4495 @itemx -u
4496 Add more recent copies of archive members to the end of an archive, if
4497 they exist.
4498 @item --concatenate
4499 @itemx --catenate
4500 @itemx -A
4501 Add one or more pre-existing archives to the end of another archive.
4502 @item --delete
4503 Delete items from an archive (does not work on tapes).
4504 @item --compare
4505 @itemx --diff
4506 @itemx -d
4507 Compare archive members to their counterparts in the file system.
4508 @end table
4509
4510 @node append
4511 @subsection How to Add Files to Existing Archives: @option{--append}
4512
4513 @cindex appending files to existing archive
4514 @opindex append
4515 If you want to add files to an existing archive, you don't need to
4516 create a new archive; you can use @option{--append} (@option{-r}).
4517 The archive must already exist in order to use @option{--append}. (A
4518 related operation is the @option{--update} operation; you can use this
4519 to add newer versions of archive members to an existing archive. To learn how to
4520 do this with @option{--update}, @pxref{update}.)
4521
4522 If you use @option{--append} to add a file that has the same name as an
4523 archive member to an archive containing that archive member, then the
4524 old member is not deleted. What does happen, however, is somewhat
4525 complex. @command{tar} @emph{allows} you to have infinite number of files
4526 with the same name. Some operations treat these same-named members no
4527 differently than any other set of archive members: for example, if you
4528 view an archive with @option{--list} (@option{-t}), you will see all
4529 of those members listed, with their data modification times, owners, etc.
4530
4531 Other operations don't deal with these members as perfectly as you might
4532 prefer; if you were to use @option{--extract} to extract the archive,
4533 only the most recently added copy of a member with the same name as
4534 other members would end up in the working directory. This is because
4535 @option{--extract} extracts an archive in the order the members appeared
4536 in the archive; the most recently archived members will be extracted
4537 last. Additionally, an extracted member will @emph{replace} a file of
4538 the same name which existed in the directory already, and @command{tar}
4539 will not prompt you about this@footnote{Unless you give it
4540 @option{--keep-old-files} (or @option{--skip-old-files}) option, or
4541 the disk copy is newer than the one in the archive and you invoke
4542 @command{tar} with @option{--keep-newer-files} option.}. Thus, only
4543 the most recently archived member will end up being extracted, as it
4544 will replace the one extracted before it, and so on.
4545
4546 @cindex extracting @var{n}th copy of the file
4547 @xopindex{occurrence, described}
4548 There exists a special option that allows you to get around this
4549 behavior and extract (or list) only a particular copy of the file.
4550 This is @option{--occurrence} option. If you run @command{tar} with
4551 this option, it will extract only the first copy of the file. You
4552 may also give this option an argument specifying the number of
4553 copy to be extracted. Thus, for example if the archive
4554 @file{archive.tar} contained three copies of file @file{myfile}, then
4555 the command
4556
4557 @smallexample
4558 tar --extract --file archive.tar --occurrence=2 myfile
4559 @end smallexample
4560
4561 @noindent
4562 would extract only the second copy. @xref{Option
4563 Summary,---occurrence}, for the description of @option{--occurrence}
4564 option.
4565
4566 @FIXME{ hag -- you might want to incorporate some of the above into the
4567 MMwtSN node; not sure. i didn't know how to make it simpler...
4568
4569 There are a few ways to get around this. Xref to Multiple Members
4570 with the Same Name, maybe.}
4571
4572 @cindex Members, replacing with other members
4573 @cindex Replacing members with other members
4574 @xopindex{delete, using before --append}
4575 If you want to replace an archive member, use @option{--delete} to
4576 delete the member you want to remove from the archive, and then use
4577 @option{--append} to add the member you want to be in the archive. Note
4578 that you can not change the order of the archive; the most recently
4579 added member will still appear last. In this sense, you cannot truly
4580 ``replace'' one member with another. (Replacing one member with another
4581 will not work on certain types of media, such as tapes; see @ref{delete}
4582 and @ref{Media}, for more information.)
4583
4584 @menu
4585 * appending files:: Appending Files to an Archive
4586 * multiple::
4587 @end menu
4588
4589 @node appending files
4590 @subsubsection Appending Files to an Archive
4591 @cindex Adding files to an Archive
4592 @cindex Appending files to an Archive
4593 @cindex Archives, Appending files to
4594 @opindex append
4595
4596 The simplest way to add a file to an already existing archive is the
4597 @option{--append} (@option{-r}) operation, which writes specified
4598 files into the archive whether or not they are already among the
4599 archived files.
4600
4601 When you use @option{--append}, you @emph{must} specify file name
4602 arguments, as there is no default. If you specify a file that already
4603 exists in the archive, another copy of the file will be added to the
4604 end of the archive. As with other operations, the member names of the
4605 newly added files will be exactly the same as their names given on the
4606 command line. The @option{--verbose} (@option{-v}) option will print
4607 out the names of the files as they are written into the archive.
4608
4609 @option{--append} cannot be performed on some tape drives, unfortunately,
4610 due to deficiencies in the formats those tape drives use. The archive
4611 must be a valid @command{tar} archive, or else the results of using this
4612 operation will be unpredictable. @xref{Media}.
4613
4614 To demonstrate using @option{--append} to add a file to an archive,
4615 create a file called @file{rock} in the @file{practice} directory.
4616 Make sure you are in the @file{practice} directory. Then, run the
4617 following @command{tar} command to add @file{rock} to
4618 @file{collection.tar}:
4619
4620 @smallexample
4621 $ @kbd{tar --append --file=collection.tar rock}
4622 @end smallexample
4623
4624 @noindent
4625 If you now use the @option{--list} (@option{-t}) operation, you will see that
4626 @file{rock} has been added to the archive:
4627
4628 @smallexample
4629 $ @kbd{tar --list --file=collection.tar}
4630 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4631 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4632 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4633 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4634 @end smallexample
4635
4636 @node multiple
4637 @subsubsection Multiple Members with the Same Name
4638 @cindex members, multiple
4639 @cindex multiple members
4640
4641 You can use @option{--append} (@option{-r}) to add copies of files
4642 which have been updated since the archive was created. (However, we
4643 do not recommend doing this since there is another @command{tar}
4644 option called @option{--update}; @xref{update}, for more information.
4645 We describe this use of @option{--append} here for the sake of
4646 completeness.) When you extract the archive, the older version will
4647 be effectively lost. This works because files are extracted from an
4648 archive in the order in which they were archived. Thus, when the
4649 archive is extracted, a file archived later in time will replace a
4650 file of the same name which was archived earlier, even though the
4651 older version of the file will remain in the archive unless you delete
4652 all versions of the file.
4653
4654 Supposing you change the file @file{blues} and then append the changed
4655 version to @file{collection.tar}. As you saw above, the original
4656 @file{blues} is in the archive @file{collection.tar}. If you change the
4657 file and append the new version of the file to the archive, there will
4658 be two copies in the archive. When you extract the archive, the older
4659 version of the file will be extracted first, and then replaced by the
4660 newer version when it is extracted.
4661
4662 You can append the new, changed copy of the file @file{blues} to the
4663 archive in this way:
4664
4665 @smallexample
4666 $ @kbd{tar --append --verbose --file=collection.tar blues}
4667 blues
4668 @end smallexample
4669
4670 @noindent
4671 Because you specified the @option{--verbose} option, @command{tar} has
4672 printed the name of the file being appended as it was acted on. Now
4673 list the contents of the archive:
4674
4675 @smallexample
4676 $ @kbd{tar --list --verbose --file=collection.tar}
4677 -rw-r--r-- me/user 28 1996-10-18 16:31 jazz
4678 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4679 -rw-r--r-- me/user 20 1996-09-23 16:44 folk
4680 -rw-r--r-- me/user 20 1996-09-23 16:44 rock
4681 -rw-r--r-- me/user 58 1996-10-24 18:30 blues
4682 @end smallexample
4683
4684 @noindent
4685 The newest version of @file{blues} is now at the end of the archive
4686 (note the different creation dates and file sizes). If you extract
4687 the archive, the older version of the file @file{blues} will be
4688 replaced by the newer version. You can confirm this by extracting
4689 the archive and running @samp{ls} on the directory.
4690
4691 If you wish to extract the first occurrence of the file @file{blues}
4692 from the archive, use @option{--occurrence} option, as shown in
4693 the following example:
4694
4695 @smallexample
4696 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4697 -rw-r--r-- me/user 21 1996-09-23 16:44 blues
4698 @end smallexample
4699
4700 @xref{Writing}, for more information on @option{--extract} and
4701 see @ref{Option Summary, --occurrence}, for a description of
4702 @option{--occurrence} option.
4703
4704 @node update
4705 @subsection Updating an Archive
4706 @cindex Updating an archive
4707 @opindex update
4708
4709 In the previous section, you learned how to use @option{--append} to
4710 add a file to an existing archive. A related operation is
4711 @option{--update} (@option{-u}). The @option{--update} operation
4712 updates a @command{tar} archive by comparing the date of the specified
4713 archive members against the date of the file with the same name. If
4714 the file has been modified more recently than the archive member, then
4715 the newer version of the file is added to the archive (as with
4716 @option{--append}).
4717
4718 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4719 The operation will fail.
4720
4721 @FIXME{other examples of media on which --update will fail? need to ask
4722 charles and/or mib/thomas/dave shevett..}
4723
4724 Both @option{--update} and @option{--append} work by adding to the end
4725 of the archive. When you extract a file from the archive, only the
4726 version stored last will wind up in the file system, unless you use
4727 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4728
4729 @menu
4730 * how to update::
4731 @end menu
4732
4733 @node how to update
4734 @subsubsection How to Update an Archive Using @option{--update}
4735 @opindex update
4736
4737 You must use file name arguments with the @option{--update}
4738 (@option{-u}) operation. If you don't specify any files,
4739 @command{tar} won't act on any files and won't tell you that it didn't
4740 do anything (which may end up confusing you).
4741
4742 @c note: the above parenthetical added because in fact, this
4743 @c behavior just confused the author. :-)
4744
4745 To see the @option{--update} option at work, create a new file,
4746 @file{classical}, in your practice directory, and some extra text to the
4747 file @file{blues}, using any text editor. Then invoke @command{tar} with
4748 the @samp{update} operation and the @option{--verbose} (@option{-v})
4749 option specified, using the names of all the files in the @file{practice}
4750 directory as file name arguments:
4751
4752 @smallexample
4753 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4754 blues
4755 classical
4756 $
4757 @end smallexample
4758
4759 @noindent
4760 Because we have specified verbose mode, @command{tar} prints out the names
4761 of the files it is working on, which in this case are the names of the
4762 files that needed to be updated. If you run @samp{tar --list} and look
4763 at the archive, you will see @file{blues} and @file{classical} at its
4764 end. There will be a total of two versions of the member @samp{blues};
4765 the one at the end will be newer and larger, since you added text before
4766 updating it.
4767
4768 The reason @command{tar} does not overwrite the older file when updating
4769 it is because writing to the middle of a section of tape is a difficult
4770 process. Tapes are not designed to go backward. @xref{Media}, for more
4771 information about tapes.
4772
4773 @option{--update} (@option{-u}) is not suitable for performing backups for two
4774 reasons: it does not change directory content entries, and it
4775 lengthens the archive every time it is used. The @GNUTAR{}
4776 options intended specifically for backups are more
4777 efficient. If you need to run backups, please consult @ref{Backups}.
4778
4779 @node concatenate
4780 @subsection Combining Archives with @option{--concatenate}
4781
4782 @cindex Adding archives to an archive
4783 @cindex Concatenating Archives
4784 @opindex concatenate
4785 @opindex catenate
4786 @c @cindex @option{-A} described
4787 Sometimes it may be convenient to add a second archive onto the end of
4788 an archive rather than adding individual files to the archive. To add
4789 one or more archives to the end of another archive, you should use the
4790 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4791
4792 To use @option{--concatenate}, give the first archive with
4793 @option{--file} option and name the rest of archives to be
4794 concatenated on the command line. The members, and their member
4795 names, will be copied verbatim from those archives to the first
4796 one@footnote{This can cause multiple members to have the same name. For
4797 information on how this affects reading the archive, see @ref{multiple}.}.
4798 The new, concatenated archive will be called by the same name as the
4799 one given with the @option{--file} option. As usual, if you omit
4800 @option{--file}, @command{tar} will use the value of the environment
4801 variable @env{TAPE}, or, if this has not been set, the default archive name.
4802
4803 @FIXME{There is no way to specify a new name...}
4804
4805 To demonstrate how @option{--concatenate} works, create two small archives
4806 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4807 files from @file{practice}:
4808
4809 @smallexample
4810 $ @kbd{tar -cvf bluesrock.tar blues rock}
4811 blues
4812 rock
4813 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4814 folk
4815 jazz
4816 @end smallexample
4817
4818 @noindent
4819 If you like, You can run @samp{tar --list} to make sure the archives
4820 contain what they are supposed to:
4821
4822 @smallexample
4823 $ @kbd{tar -tvf bluesrock.tar}
4824 -rw-r--r-- melissa/user 105 1997-01-21 19:42 blues
4825 -rw-r--r-- melissa/user 33 1997-01-20 15:34 rock
4826 $ @kbd{tar -tvf jazzfolk.tar}
4827 -rw-r--r-- melissa/user 20 1996-09-23 16:44 folk
4828 -rw-r--r-- melissa/user 65 1997-01-30 14:15 jazz
4829 @end smallexample
4830
4831 We can concatenate these two archives with @command{tar}:
4832
4833 @smallexample
4834 $ @kbd{cd ..}
4835 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4836 @end smallexample
4837
4838 If you now list the contents of the @file{bluesrock.tar}, you will see
4839 that now it also contains the archive members of @file{jazzfolk.tar}:
4840
4841 @smallexample
4842 $ @kbd{tar --list --file=bluesrock.tar}
4843 blues
4844 rock
4845 folk
4846 jazz
4847 @end smallexample
4848
4849 When you use @option{--concatenate}, the source and target archives must
4850 already exist and must have been created using compatible format
4851 parameters. Notice, that @command{tar} does not check whether the
4852 archives it concatenates have compatible formats, it does not
4853 even check if the files are really tar archives.
4854
4855 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4856 tape drives, due to deficiencies in the formats those tape drives use.
4857
4858 @cindex @code{concatenate} vs @command{cat}
4859 @cindex @command{cat} vs @code{concatenate}
4860 It may seem more intuitive to you to want or try to use @command{cat} to
4861 concatenate two archives instead of using the @option{--concatenate}
4862 operation; after all, @command{cat} is the utility for combining files.
4863
4864 However, @command{tar} archives incorporate an end-of-file marker which
4865 must be removed if the concatenated archives are to be read properly as
4866 one archive. @option{--concatenate} removes the end-of-archive marker
4867 from the target archive before each new archive is appended. If you use
4868 @command{cat} to combine the archives, the result will not be a valid
4869 @command{tar} format archive. If you need to retrieve files from an
4870 archive that was added to using the @command{cat} utility, use the
4871 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4872 information on dealing with archives improperly combined using the
4873 @command{cat} shell utility.
4874
4875 @node delete
4876 @subsection Removing Archive Members Using @option{--delete}
4877 @cindex Deleting files from an archive
4878 @cindex Removing files from an archive
4879
4880 @opindex delete
4881 You can remove members from an archive by using the @option{--delete}
4882 option. Specify the name of the archive with @option{--file}
4883 (@option{-f}) and then specify the names of the members to be deleted;
4884 if you list no member names, nothing will be deleted. The
4885 @option{--verbose} option will cause @command{tar} to print the names
4886 of the members as they are deleted. As with @option{--extract}, you
4887 must give the exact member names when using @samp{tar --delete}.
4888 @option{--delete} will remove all versions of the named file from the
4889 archive. The @option{--delete} operation can run very slowly.
4890
4891 Unlike other operations, @option{--delete} has no short form.
4892
4893 @cindex Tapes, using @option{--delete} and
4894 @cindex Deleting from tape archives
4895 This operation will rewrite the archive. You can only use
4896 @option{--delete} on an archive if the archive device allows you to
4897 write to any point on the media, such as a disk; because of this, it
4898 does not work on magnetic tapes. Do not try to delete an archive member
4899 from a magnetic tape; the action will not succeed, and you will be
4900 likely to scramble the archive and damage your tape. There is no safe
4901 way (except by completely re-writing the archive) to delete files from
4902 most kinds of magnetic tape. @xref{Media}.
4903
4904 To delete all versions of the file @file{blues} from the archive
4905 @file{collection.tar} in the @file{practice} directory, make sure you
4906 are in that directory, and then,
4907
4908 @smallexample
4909 $ @kbd{tar --list --file=collection.tar}
4910 blues
4911 folk
4912 jazz
4913 rock
4914 $ @kbd{tar --delete --file=collection.tar blues}
4915 $ @kbd{tar --list --file=collection.tar}
4916 folk
4917 jazz
4918 rock
4919 @end smallexample
4920
4921 @FIXME{Check if the above listing is actually produced after running
4922 all the examples on collection.tar.}
4923
4924 The @option{--delete} option has been reported to work properly when
4925 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4926
4927 @node compare
4928 @subsection Comparing Archive Members with the File System
4929 @cindex Verifying the currency of an archive
4930
4931 @opindex compare
4932 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4933 specified archive members against files with the same names, and then
4934 reports differences in file size, mode, owner, modification date and
4935 contents. You should @emph{only} specify archive member names, not file
4936 names. If you do not name any members, then @command{tar} will compare the
4937 entire archive. If a file is represented in the archive but does not
4938 exist in the file system, @command{tar} reports a difference.
4939
4940 You have to specify the record size of the archive when modifying an
4941 archive with a non-default record size.
4942
4943 @command{tar} ignores files in the file system that do not have
4944 corresponding members in the archive.
4945
4946 The following example compares the archive members @file{rock},
4947 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4948 files of the same name in the file system. (Note that there is no file,
4949 @file{funk}; @command{tar} will report an error message.)
4950
4951 @smallexample
4952 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4953 rock
4954 blues
4955 tar: funk not found in archive
4956 @end smallexample
4957
4958 The spirit behind the @option{--compare} (@option{--diff},
4959 @option{-d}) option is to check whether the archive represents the
4960 current state of files on disk, more than validating the integrity of
4961 the archive media. For this latter goal, see @ref{verify}.
4962
4963 @node create options
4964 @section Options Used by @option{--create}
4965
4966 @xopindex{create, additional options}
4967 The previous chapter described the basics of how to use
4968 @option{--create} (@option{-c}) to create an archive from a set of files.
4969 @xref{create}. This section described advanced options to be used with
4970 @option{--create}.
4971
4972 @menu
4973 * override:: Overriding File Metadata.
4974 * Ignore Failed Read::
4975 @end menu
4976
4977 @node override
4978 @subsection Overriding File Metadata
4979
4980 As described above, a @command{tar} archive keeps, for each member it contains,
4981 its @dfn{metadata}, such as modification time, mode and ownership of
4982 the file. @GNUTAR{} allows to replace these data with other values
4983 when adding files to the archive. The options described in this
4984 section affect creation of archives of any type. For POSIX archives,
4985 see also @ref{PAX keywords}, for additional ways of controlling
4986 metadata, stored in the archive.
4987
4988 @table @option
4989 @opindex mode
4990 @item --mode=@var{permissions}
4991
4992 When adding files to an archive, @command{tar} will use
4993 @var{permissions} for the archive members, rather than the permissions
4994 from the files. @var{permissions} can be specified either as an octal
4995 number or as symbolic permissions, like with
4996 @command{chmod} (@xref{File permissions, Permissions, File
4997 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4998 also has useful information for those not being overly familiar with
4999 the UNIX permission system). Using latter syntax allows for
5000 more flexibility. For example, the value @samp{a+rw} adds read and write
5001 permissions for everybody, while retaining executable bits on directories
5002 or on any other file already marked as executable:
5003
5004 @smallexample
5005 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
5006 @end smallexample
5007
5008 @item --mtime=@var{date}
5009 @opindex mtime
5010
5011 When adding files to an archive, @command{tar} will use @var{date} as
5012 the modification time of members when creating archives, instead of
5013 their actual modification times. The argument @var{date} can be
5014 either a textual date representation in almost arbitrary format
5015 (@pxref{Date input formats}) or a name of an existing file, starting
5016 with @samp{/} or @samp{.}. In the latter case, the modification time
5017 of that file will be used.
5018
5019 The following example will set the modification date to 00:00:00,
5020 January 1, 1970:
5021
5022 @smallexample
5023 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
5024 @end smallexample
5025
5026 @noindent
5027 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
5028 will try to convert the specified date back to its textual
5029 representation and compare it with the one given with
5030 @option{--mtime} options. If the two dates differ, @command{tar} will
5031 print a warning saying what date it will use. This is to help user
5032 ensure he is using the right date.
5033
5034 For example:
5035
5036 @smallexample
5037 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
5038 tar: Option --mtime: Treating date 'yesterday' as 2006-06-20
5039 13:06:29.152478
5040 @dots{}
5041 @end smallexample
5042
5043 @item --owner=@var{user}
5044 @opindex owner
5045
5046 Specifies that @command{tar} should use @var{user} as the owner of members
5047 when creating archives, instead of the user associated with the source
5048 file.
5049
5050 If @var{user} contains a colon, it is taken to be of the form
5051 @var{name}:@var{id} where a nonempty @var{name} specifies the user
5052 name and a nonempty @var{id} specifies the decimal numeric user
5053 @acronym{ID}. If @var{user} does not contain a colon, it is taken to
5054 be a user number if it is one or more decimal digits; otherwise it is
5055 taken to be a user name.
5056
5057 If a name is given but no number, the number is inferred from the
5058 current host's user database if possible, and the file's user number
5059 is used otherwise. If a number is given but no name, the name is
5060 inferred from the number if possible, and an empty name is used
5061 otherwise. If both name and number are given, the user database is
5062 not consulted, and the name and number need not be valid on the
5063 current host.
5064
5065 There is no value indicating a missing number, and @samp{0} usually means
5066 @code{root}. Some people like to force @samp{0} as the value to offer in
5067 their distributions for the owner of files, because the @code{root} user is
5068 anonymous anyway, so that might as well be the owner of anonymous
5069 archives. For example:
5070
5071 @smallexample
5072 $ @kbd{tar -c -f archive.tar --owner=0 .}
5073 @end smallexample
5074
5075 @noindent
5076 or:
5077
5078 @smallexample
5079 $ @kbd{tar -c -f archive.tar --owner=root .}
5080 @end smallexample
5081
5082 @item --group=@var{group}
5083 @opindex group
5084
5085 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
5086 rather than the group from the source file. As with @option{--owner},
5087 the argument @var{group} can be an existing group symbolic name, or a
5088 decimal numeric group @acronym{ID}, or @var{name}:@var{id}.
5089 @end table
5090
5091 @node Ignore Failed Read
5092 @subsection Ignore Fail Read
5093
5094 @table @option
5095 @item --ignore-failed-read
5096 @opindex ignore-failed-read
5097 Do not exit with nonzero on unreadable files or directories.
5098 @end table
5099
5100 @node extract options
5101 @section Options Used by @option{--extract}
5102 @cindex options for use with @option{--extract}
5103
5104 @xopindex{extract, additional options}
5105 The previous chapter showed how to use @option{--extract} to extract
5106 an archive into the file system. Various options cause @command{tar} to
5107 extract more information than just file contents, such as the owner,
5108 the permissions, the modification date, and so forth. This section
5109 presents options to be used with @option{--extract} when certain special
5110 considerations arise. You may review the information presented in
5111 @ref{extract} for more basic information about the
5112 @option{--extract} operation.
5113
5114 @menu
5115 * Reading:: Options to Help Read Archives
5116 * Writing:: Changing How @command{tar} Writes Files
5117 * Scarce:: Coping with Scarce Resources
5118 @end menu
5119
5120 @node Reading
5121 @subsection Options to Help Read Archives
5122 @cindex Options when reading archives
5123
5124 @cindex Reading incomplete records
5125 @cindex Records, incomplete
5126 @opindex read-full-records
5127 Normally, @command{tar} will request data in full record increments from
5128 an archive storage device. If the device cannot return a full record,
5129 @command{tar} will report an error. However, some devices do not always
5130 return full records, or do not require the last record of an archive to
5131 be padded out to the next record boundary. To keep reading until you
5132 obtain a full record, or to accept an incomplete record if it contains
5133 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5134 in conjunction with the @option{--extract} or @option{--list} operations.
5135 @xref{Blocking}.
5136
5137 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5138 @command{tar} reads an archive from standard input, or from a remote
5139 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
5140 pipe returns however much happens to be in the pipe, even if it is
5141 less than was requested. If this option were not enabled, @command{tar}
5142 would fail as soon as it read an incomplete record from the pipe.
5143
5144 If you're not sure of the blocking factor of an archive, you can
5145 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5146 @option{--blocking-factor=@var{512-size}} (@option{-b
5147 @var{512-size}}), using a blocking factor larger than what the archive
5148 uses. This lets you avoid having to determine the blocking factor
5149 of an archive. @xref{Blocking Factor}.
5150
5151 @menu
5152 * read full records::
5153 * Ignore Zeros::
5154 @end menu
5155
5156 @node read full records
5157 @unnumberedsubsubsec Reading Full Records
5158
5159 @FIXME{need sentence or so of intro here}
5160
5161 @table @option
5162 @opindex read-full-records
5163 @item --read-full-records
5164 @item -B
5165 Use in conjunction with @option{--extract} (@option{--get},
5166 @option{-x}) to read an archive which contains incomplete records, or
5167 one which has a blocking factor less than the one specified.
5168 @end table
5169
5170 @node Ignore Zeros
5171 @unnumberedsubsubsec Ignoring Blocks of Zeros
5172
5173 @cindex End-of-archive blocks, ignoring
5174 @cindex Ignoring end-of-archive blocks
5175 @opindex ignore-zeros
5176 Normally, @command{tar} stops reading when it encounters a block of zeros
5177 between file entries (which usually indicates the end of the archive).
5178 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5179 completely read an archive which contains a block of zeros before the
5180 end (i.e., a damaged archive, or one that was created by concatenating
5181 several archives together).
5182
5183 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5184 versions of @command{tar} write garbage after the end-of-archive entry,
5185 since that part of the media is never supposed to be read. @GNUTAR{}
5186 does not write after the end of an archive, but seeks to
5187 maintain compatibility among archiving utilities.
5188
5189 @table @option
5190 @item --ignore-zeros
5191 @itemx -i
5192 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5193 encountered while reading an archive. Use in conjunction with
5194 @option{--extract} or @option{--list}.
5195 @end table
5196
5197 @node Writing
5198 @subsection Changing How @command{tar} Writes Files
5199 @UNREVISED
5200
5201 @FIXME{Introductory paragraph}
5202
5203 @menu
5204 * Dealing with Old Files::
5205 * Overwrite Old Files::
5206 * Keep Old Files::
5207 * Keep Newer Files::
5208 * Unlink First::
5209 * Recursive Unlink::
5210 * Data Modification Times::
5211 * Setting Access Permissions::
5212 * Directory Modification Times and Permissions::
5213 * Writing to Standard Output::
5214 * Writing to an External Program::
5215 * remove files::
5216 @end menu
5217
5218 @node Dealing with Old Files
5219 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5220
5221 @xopindex{overwrite-dir, introduced}
5222 When extracting files, if @command{tar} discovers that the extracted
5223 file already exists, it normally replaces the file by removing it before
5224 extracting it, to prevent confusion in the presence of hard or symbolic
5225 links. (If the existing file is a symbolic link, it is removed, not
5226 followed.) However, if a directory cannot be removed because it is
5227 nonempty, @command{tar} normally overwrites its metadata (ownership,
5228 permission, etc.). The @option{--overwrite-dir} option enables this
5229 default behavior. To be more cautious and preserve the metadata of
5230 such a directory, use the @option{--no-overwrite-dir} option.
5231
5232 @cindex Overwriting old files, prevention
5233 @xopindex{keep-old-files, introduced}
5234 To be even more cautious and prevent existing files from being replaced, use
5235 the @option{--keep-old-files} (@option{-k}) option. It causes
5236 @command{tar} to refuse to replace or update a file that already
5237 exists, i.e., a file with the same name as an archive member prevents
5238 extraction of that archive member. Instead, it reports an error. For
5239 example:
5240
5241 @example
5242 $ @kbd{ls}
5243 blues
5244 $ @kbd{tar -x -k -f archive.tar}
5245 tar: blues: Cannot open: File exists
5246 tar: Exiting with failure status due to previous errors
5247 @end example
5248
5249 @xopindex{skip-old-files, introduced}
5250 If you wish to preserve old files untouched, but don't want
5251 @command{tar} to treat them as errors, use the
5252 @option{--skip-old-files} option. This option causes @command{tar} to
5253 silently skip extracting over existing files.
5254
5255 @xopindex{overwrite, introduced}
5256 To be more aggressive about altering existing files, use the
5257 @option{--overwrite} option. It causes @command{tar} to overwrite
5258 existing files and to follow existing symbolic links when extracting.
5259
5260 @cindex Protecting old files
5261 Some people argue that @GNUTAR{} should not hesitate
5262 to overwrite files with other files when extracting. When extracting
5263 a @command{tar} archive, they expect to see a faithful copy of the
5264 state of the file system when the archive was created. It is debatable
5265 that this would always be a proper behavior. For example, suppose one
5266 has an archive in which @file{usr/local} is a link to
5267 @file{usr/local2}. Since then, maybe the site removed the link and
5268 renamed the whole hierarchy from @file{/usr/local2} to
5269 @file{/usr/local}. Such things happen all the time. I guess it would
5270 not be welcome at all that @GNUTAR{} removes the
5271 whole hierarchy just to make room for the link to be reinstated
5272 (unless it @emph{also} simultaneously restores the full
5273 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
5274 able to remove a whole hierarchy to reestablish a symbolic link, for
5275 example, but @emph{only if} @option{--recursive-unlink} is specified
5276 to allow this behavior. In any case, single files are silently
5277 removed.
5278
5279 @xopindex{unlink-first, introduced}
5280 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5281 some cases by causing @command{tar} to remove files unconditionally
5282 before extracting them.
5283
5284 @node Overwrite Old Files
5285 @unnumberedsubsubsec Overwrite Old Files
5286
5287 @table @option
5288 @opindex overwrite
5289 @item --overwrite
5290 Overwrite existing files and directory metadata when extracting files
5291 from an archive.
5292
5293 This causes @command{tar} to write extracted files into the file system without
5294 regard to the files already on the system; i.e., files with the same
5295 names as archive members are overwritten when the archive is extracted.
5296 It also causes @command{tar} to extract the ownership, permissions,
5297 and time stamps onto any preexisting files or directories.
5298 If the name of a corresponding file name is a symbolic link, the file
5299 pointed to by the symbolic link will be overwritten instead of the
5300 symbolic link itself (if this is possible). Moreover, special devices,
5301 empty directories and even symbolic links are automatically removed if
5302 they are in the way of extraction.
5303
5304 Be careful when using the @option{--overwrite} option, particularly when
5305 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5306 can change the contents, ownership or permissions of any file on your
5307 system. Also, many systems do not take kindly to overwriting files that
5308 are currently being executed.
5309
5310 @opindex overwrite-dir
5311 @item --overwrite-dir
5312 Overwrite the metadata of directories when extracting files from an
5313 archive, but remove other files before extracting.
5314 @end table
5315
5316 @node Keep Old Files
5317 @unnumberedsubsubsec Keep Old Files
5318
5319 @GNUTAR{} provides two options to control its actions in a situation
5320 when it is about to extract a file which already exists on disk.
5321
5322 @table @option
5323 @opindex keep-old-files
5324 @item --keep-old-files
5325 @itemx -k
5326 Do not replace existing files from archive. When such a file is
5327 encountered, @command{tar} issues an error message. Upon end of
5328 extraction, @command{tar} exits with code 2 (@pxref{exit status}).
5329
5330 @item --skip-old-files
5331 Do not replace existing files from archive, but do not treat that
5332 as error. Such files are silently skipped and do not affect
5333 @command{tar} exit status.
5334
5335 Additional verbosity can be obtained using @option{--warning=existing-file}
5336 together with that option (@pxref{warnings}).
5337 @end table
5338
5339 @node Keep Newer Files
5340 @unnumberedsubsubsec Keep Newer Files
5341
5342 @table @option
5343 @opindex keep-newer-files
5344 @item --keep-newer-files
5345 Do not replace existing files that are newer than their archive
5346 copies. This option is meaningless with @option{--list} (@option{-t}).
5347 @end table
5348
5349 @node Unlink First
5350 @unnumberedsubsubsec Unlink First
5351
5352 @table @option
5353 @opindex unlink-first
5354 @item --unlink-first
5355 @itemx -U
5356 Remove files before extracting over them.
5357 This can make @command{tar} run a bit faster if you know in advance
5358 that the extracted files all need to be removed. Normally this option
5359 slows @command{tar} down slightly, so it is disabled by default.
5360 @end table
5361
5362 @node Recursive Unlink
5363 @unnumberedsubsubsec Recursive Unlink
5364
5365 @table @option
5366 @opindex recursive-unlink
5367 @item --recursive-unlink
5368 When this option is specified, try removing files and directory hierarchies
5369 before extracting over them. @emph{This is a dangerous option!}
5370 @end table
5371
5372 If you specify the @option{--recursive-unlink} option,
5373 @command{tar} removes @emph{anything} that keeps you from extracting a file
5374 as far as current permissions will allow it. This could include removal
5375 of the contents of a full directory hierarchy.
5376
5377 @node Data Modification Times
5378 @unnumberedsubsubsec Setting Data Modification Times
5379
5380 @cindex Data modification times of extracted files
5381 @cindex Modification times of extracted files
5382 Normally, @command{tar} sets the data modification times of extracted
5383 files to the corresponding times recorded for the files in the archive, but
5384 limits the permissions of extracted files by the current @code{umask}
5385 setting.
5386
5387 To set the data modification times of extracted files to the time when
5388 the files were extracted, use the @option{--touch} (@option{-m}) option in
5389 conjunction with @option{--extract} (@option{--get}, @option{-x}).
5390
5391 @table @option
5392 @opindex touch
5393 @item --touch
5394 @itemx -m
5395 Sets the data modification time of extracted archive members to the time
5396 they were extracted, not the time recorded for them in the archive.
5397 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
5398 @end table
5399
5400 @node Setting Access Permissions
5401 @unnumberedsubsubsec Setting Access Permissions
5402
5403 @cindex Permissions of extracted files
5404 @cindex Modes of extracted files
5405 To set the modes (access permissions) of extracted files to those
5406 recorded for those files in the archive, use @option{--same-permissions}
5407 in conjunction with the @option{--extract} (@option{--get},
5408 @option{-x}) operation.
5409
5410 @table @option
5411 @opindex preserve-permissions
5412 @opindex same-permissions
5413 @item --preserve-permissions
5414 @itemx --same-permissions
5415 @c @itemx --ignore-umask
5416 @itemx -p
5417 Set modes of extracted archive members to those recorded in the
5418 archive, instead of current umask settings. Use in conjunction with
5419 @option{--extract} (@option{--get}, @option{-x}).
5420 @end table
5421
5422 @node Directory Modification Times and Permissions
5423 @unnumberedsubsubsec Directory Modification Times and Permissions
5424
5425 After successfully extracting a file member, @GNUTAR{} normally
5426 restores its permissions and modification times, as described in the
5427 previous sections. This cannot be done for directories, because
5428 after extracting a directory @command{tar} will almost certainly
5429 extract files into that directory and this will cause the directory
5430 modification time to be updated. Moreover, restoring that directory
5431 permissions may not permit file creation within it. Thus, restoring
5432 directory permissions and modification times must be delayed at least
5433 until all files have been extracted into that directory. @GNUTAR{}
5434 restores directories using the following approach.
5435
5436 The extracted directories are created with the mode specified in the
5437 archive, as modified by the umask of the user, which gives sufficient
5438 permissions to allow file creation. The meta-information about the
5439 directory is recorded in the temporary list of directories. When
5440 preparing to extract next archive member, @GNUTAR{} checks if the
5441 directory prefix of this file contains the remembered directory. If
5442 it does not, the program assumes that all files have been extracted
5443 into that directory, restores its modification time and permissions
5444 and removes its entry from the internal list. This approach allows
5445 to correctly restore directory meta-information in the majority of
5446 cases, while keeping memory requirements sufficiently small. It is
5447 based on the fact, that most @command{tar} archives use the predefined
5448 order of members: first the directory, then all the files and
5449 subdirectories in that directory.
5450
5451 However, this is not always true. The most important exception are
5452 incremental archives (@pxref{Incremental Dumps}). The member order in
5453 an incremental archive is reversed: first all directory members are
5454 stored, followed by other (non-directory) members. So, when extracting
5455 from incremental archives, @GNUTAR{} alters the above procedure. It
5456 remembers all restored directories, and restores their meta-data
5457 only after the entire archive has been processed. Notice, that you do
5458 not need to specify any special options for that, as @GNUTAR{}
5459 automatically detects archives in incremental format.
5460
5461 There may be cases, when such processing is required for normal archives
5462 too. Consider the following example:
5463
5464 @smallexample
5465 @group
5466 $ @kbd{tar --no-recursion -cvf archive \
5467 foo foo/file1 bar bar/file foo/file2}
5468 foo/
5469 foo/file1
5470 bar/
5471 bar/file
5472 foo/file2
5473 @end group
5474 @end smallexample
5475
5476 During the normal operation, after encountering @file{bar}
5477 @GNUTAR{} will assume that all files from the directory @file{foo}
5478 were already extracted and will therefore restore its timestamp and
5479 permission bits. However, after extracting @file{foo/file2} the
5480 directory timestamp will be offset again.
5481
5482 To correctly restore directory meta-information in such cases, use
5483 the @option{--delay-directory-restore} command line option:
5484
5485 @table @option
5486 @opindex delay-directory-restore
5487 @item --delay-directory-restore
5488 Delays restoring of the modification times and permissions of extracted
5489 directories until the end of extraction. This way, correct
5490 meta-information is restored even if the archive has unusual member
5491 ordering.
5492
5493 @opindex no-delay-directory-restore
5494 @item --no-delay-directory-restore
5495 Cancel the effect of the previous @option{--delay-directory-restore}.
5496 Use this option if you have used @option{--delay-directory-restore} in
5497 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5498 temporarily disable it.
5499 @end table
5500
5501 @node Writing to Standard Output
5502 @unnumberedsubsubsec Writing to Standard Output
5503
5504 @cindex Writing extracted files to standard output
5505 @cindex Standard output, writing extracted files to
5506 To write the extracted files to the standard output, instead of
5507 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5508 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5509 extracting files to send them through a pipe, and do not need to
5510 preserve them in the file system. If you extract multiple members,
5511 they appear on standard output concatenated, in the order they are
5512 found in the archive.
5513
5514 @table @option
5515 @opindex to-stdout
5516 @item --to-stdout
5517 @itemx -O
5518 Writes files to the standard output. Use only in conjunction with
5519 @option{--extract} (@option{--get}, @option{-x}). When this option is
5520 used, instead of creating the files specified, @command{tar} writes
5521 the contents of the files extracted to its standard output. This may
5522 be useful if you are only extracting the files in order to send them
5523 through a pipe. This option is meaningless with @option{--list}
5524 (@option{-t}).
5525 @end table
5526
5527 This can be useful, for example, if you have a tar archive containing
5528 a big file and don't want to store the file on disk before processing
5529 it. You can use a command like this:
5530
5531 @smallexample
5532 tar -xOzf foo.tgz bigfile | process
5533 @end smallexample
5534
5535 or even like this if you want to process the concatenation of the files:
5536
5537 @smallexample
5538 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5539 @end smallexample
5540
5541 However, @option{--to-command} may be more convenient for use with
5542 multiple files. See the next section.
5543
5544 @node Writing to an External Program
5545 @unnumberedsubsubsec Writing to an External Program
5546
5547 You can instruct @command{tar} to send the contents of each extracted
5548 file to the standard input of an external program:
5549
5550 @table @option
5551 @opindex to-command
5552 @item --to-command=@var{command}
5553 Extract files and pipe their contents to the standard input of
5554 @var{command}. When this option is used, instead of creating the
5555 files specified, @command{tar} invokes @var{command} and pipes the
5556 contents of the files to its standard output. The @var{command} may
5557 contain command line arguments (see @ref{external, Running External Commands},
5558 for more detail).
5559
5560 Notice, that @var{command} is executed once for each regular file
5561 extracted. Non-regular files (directories, etc.) are ignored when this
5562 option is used.
5563 @end table
5564
5565 The command can obtain the information about the file it processes
5566 from the following environment variables:
5567
5568 @table @env
5569 @vrindex TAR_FILETYPE, to-command environment
5570 @item TAR_FILETYPE
5571 Type of the file. It is a single letter with the following meaning:
5572
5573 @multitable @columnfractions 0.10 0.90
5574 @item f @tab Regular file
5575 @item d @tab Directory
5576 @item l @tab Symbolic link
5577 @item h @tab Hard link
5578 @item b @tab Block device
5579 @item c @tab Character device
5580 @end multitable
5581
5582 Currently only regular files are supported.
5583
5584 @vrindex TAR_MODE, to-command environment
5585 @item TAR_MODE
5586 File mode, an octal number.
5587
5588 @vrindex TAR_FILENAME, to-command environment
5589 @item TAR_FILENAME
5590 The name of the file.
5591
5592 @vrindex TAR_REALNAME, to-command environment
5593 @item TAR_REALNAME
5594 Name of the file as stored in the archive.
5595
5596 @vrindex TAR_UNAME, to-command environment
5597 @item TAR_UNAME
5598 Name of the file owner.
5599
5600 @vrindex TAR_GNAME, to-command environment
5601 @item TAR_GNAME
5602 Name of the file owner group.
5603
5604 @vrindex TAR_ATIME, to-command environment
5605 @item TAR_ATIME
5606 Time of last access. It is a decimal number, representing seconds
5607 since the Epoch. If the archive provides times with nanosecond
5608 precision, the nanoseconds are appended to the timestamp after a
5609 decimal point.
5610
5611 @vrindex TAR_MTIME, to-command environment
5612 @item TAR_MTIME
5613 Time of last modification.
5614
5615 @vrindex TAR_CTIME, to-command environment
5616 @item TAR_CTIME
5617 Time of last status change.
5618
5619 @vrindex TAR_SIZE, to-command environment
5620 @item TAR_SIZE
5621 Size of the file.
5622
5623 @vrindex TAR_UID, to-command environment
5624 @item TAR_UID
5625 UID of the file owner.
5626
5627 @vrindex TAR_GID, to-command environment
5628 @item TAR_GID
5629 GID of the file owner.
5630 @end table
5631
5632 Additionally, the following variables contain information about
5633 tar mode and the archive being processed:
5634
5635 @table @env
5636 @vrindex TAR_VERSION, to-command environment
5637 @item TAR_VERSION
5638 @GNUTAR{} version number.
5639
5640 @vrindex TAR_ARCHIVE, to-command environment
5641 @item TAR_ARCHIVE
5642 The name of the archive @command{tar} is processing.
5643
5644 @vrindex TAR_BLOCKING_FACTOR, to-command environment
5645 @item TAR_BLOCKING_FACTOR
5646 Current blocking factor (@pxref{Blocking}).
5647
5648 @vrindex TAR_VOLUME, to-command environment
5649 @item TAR_VOLUME
5650 Ordinal number of the volume @command{tar} is processing.
5651
5652 @vrindex TAR_FORMAT, to-command environment
5653 @item TAR_FORMAT
5654 Format of the archive being processed. @xref{Formats}, for a complete
5655 list of archive format names.
5656 @end table
5657
5658 These variables are defined prior to executing the command, so you can
5659 pass them as arguments, if you prefer. For example, if the command
5660 @var{proc} takes the member name and size as its arguments, then you
5661 could do:
5662
5663 @smallexample
5664 $ @kbd{tar -x -f archive.tar \
5665 --to-command='proc $TAR_FILENAME $TAR_SIZE'}
5666 @end smallexample
5667
5668 @noindent
5669 Notice single quotes to prevent variable names from being expanded by
5670 the shell when invoking @command{tar}.
5671
5672 If @var{command} exits with a non-0 status, @command{tar} will print
5673 an error message similar to the following:
5674
5675 @smallexample
5676 tar: 2345: Child returned status 1
5677 @end smallexample
5678
5679 Here, @samp{2345} is the PID of the finished process.
5680
5681 If this behavior is not wanted, use @option{--ignore-command-error}:
5682
5683 @table @option
5684 @opindex ignore-command-error
5685 @item --ignore-command-error
5686 Ignore exit codes of subprocesses. Notice that if the program
5687 exits on signal or otherwise terminates abnormally, the error message
5688 will be printed even if this option is used.
5689
5690 @opindex no-ignore-command-error
5691 @item --no-ignore-command-error
5692 Cancel the effect of any previous @option{--ignore-command-error}
5693 option. This option is useful if you have set
5694 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5695 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5696 @end table
5697
5698 @node remove files
5699 @unnumberedsubsubsec Removing Files
5700
5701 @FIXME{The section is too terse. Something more to add? An example,
5702 maybe?}
5703
5704 @table @option
5705 @opindex remove-files
5706 @item --remove-files
5707 Remove files after adding them to the archive.
5708 @end table
5709
5710 @node Scarce
5711 @subsection Coping with Scarce Resources
5712 @UNREVISED
5713
5714 @cindex Small memory
5715 @cindex Running out of space
5716
5717 @menu
5718 * Starting File::
5719 * Same Order::
5720 @end menu
5721
5722 @node Starting File
5723 @unnumberedsubsubsec Starting File
5724
5725 @table @option
5726 @opindex starting-file
5727 @item --starting-file=@var{name}
5728 @itemx -K @var{name}
5729 Starts an operation in the middle of an archive. Use in conjunction
5730 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5731 @end table
5732
5733 @cindex Middle of the archive, starting in the
5734 If a previous attempt to extract files failed due to lack of disk
5735 space, you can use @option{--starting-file=@var{name}} (@option{-K
5736 @var{name}}) to start extracting only after member @var{name} of the
5737 archive. This assumes, of course, that there is now free space, or
5738 that you are now extracting into a different file system. (You could
5739 also choose to suspend @command{tar}, remove unnecessary files from
5740 the file system, and then resume the same @command{tar} operation.
5741 In this case, @option{--starting-file} is not necessary.) See also
5742 @ref{interactive}, and @ref{exclude}.
5743
5744 @node Same Order
5745 @unnumberedsubsubsec Same Order
5746
5747 @table @option
5748 @cindex Large lists of file names on small machines
5749 @opindex same-order
5750 @opindex preserve-order
5751 @item --same-order
5752 @itemx --preserve-order
5753 @itemx -s
5754 To process large lists of file names on machines with small amounts of
5755 memory. Use in conjunction with @option{--compare} (@option{--diff},
5756 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5757 (@option{--get}, @option{-x}).
5758 @end table
5759
5760 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5761 names to be listed or extracted is sorted in the same order as the
5762 files in the archive. This allows a large list of names to be used,
5763 even on a small machine that would not otherwise be able to hold all
5764 the names in memory at the same time. Such a sorted list can easily be
5765 created by running @samp{tar -t} on the archive and editing its output.
5766
5767 This option is probably never needed on modern computer systems.
5768
5769 @node backup
5770 @section Backup options
5771
5772 @cindex backup options
5773
5774 @GNUTAR{} offers options for making backups of files
5775 before writing new versions. These options control the details of
5776 these backups. They may apply to the archive itself before it is
5777 created or rewritten, as well as individual extracted members. Other
5778 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5779 and @command{mv}, for example) offer similar options.
5780
5781 Backup options may prove unexpectedly useful when extracting archives
5782 containing many members having identical name, or when extracting archives
5783 on systems having file name limitations, making different members appear
5784 as having similar names through the side-effect of name truncation.
5785 @FIXME{This is true only if we have a good scheme for truncated backup names,
5786 which I'm not sure at all: I suspect work is needed in this area.}
5787 When any existing file is backed up before being overwritten by extraction,
5788 then clashing files are automatically be renamed to be unique, and the
5789 true name is kept for only the last file of a series of clashing files.
5790 By using verbose mode, users may track exactly what happens.
5791
5792 At the detail level, some decisions are still experimental, and may
5793 change in the future, we are waiting comments from our users. So, please
5794 do not learn to depend blindly on the details of the backup features.
5795 For example, currently, directories themselves are never renamed through
5796 using these options, so, extracting a file over a directory still has
5797 good chances to fail. Also, backup options apply to created archives,
5798 not only to extracted members. For created archives, backups will not
5799 be attempted when the archive is a block or character device, or when it
5800 refers to a remote file.
5801
5802 For the sake of simplicity and efficiency, backups are made by renaming old
5803 files prior to creation or extraction, and not by copying. The original
5804 name is restored if the file creation fails. If a failure occurs after a
5805 partial extraction of a file, both the backup and the partially extracted
5806 file are kept.
5807
5808 @table @samp
5809 @item --backup[=@var{method}]
5810 @opindex backup
5811 @vindex VERSION_CONTROL
5812 @cindex backups
5813 Back up files that are about to be overwritten or removed.
5814 Without this option, the original versions are destroyed.
5815
5816 Use @var{method} to determine the type of backups made.
5817 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5818 environment variable. And if @env{VERSION_CONTROL} is not set,
5819 use the @samp{existing} method.
5820
5821 @vindex version-control @r{Emacs variable}
5822 This option corresponds to the Emacs variable @samp{version-control};
5823 the same values for @var{method} are accepted as in Emacs. This option
5824 also allows more descriptive names. The valid @var{method}s are:
5825
5826 @table @samp
5827 @item t
5828 @itemx numbered
5829 @cindex numbered @r{backup method}
5830 Always make numbered backups.
5831
5832 @item nil
5833 @itemx existing
5834 @cindex existing @r{backup method}
5835 Make numbered backups of files that already have them, simple backups
5836 of the others.
5837
5838 @item never
5839 @itemx simple
5840 @cindex simple @r{backup method}
5841 Always make simple backups.
5842
5843 @end table
5844
5845 @item --suffix=@var{suffix}
5846 @opindex suffix
5847 @cindex backup suffix
5848 @vindex SIMPLE_BACKUP_SUFFIX
5849 Append @var{suffix} to each backup file made with @option{--backup}. If this
5850 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5851 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5852 set, the default is @samp{~}, just as in Emacs.
5853
5854 @end table
5855
5856 @node Applications
5857 @section Notable @command{tar} Usages
5858 @UNREVISED
5859
5860 @FIXME{Using Unix file linking capability to recreate directory
5861 structures---linking files into one subdirectory and then
5862 @command{tar}ring that directory.}
5863
5864 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5865
5866 @findex uuencode
5867 You can easily use archive files to transport a group of files from
5868 one system to another: put all relevant files into an archive on one
5869 computer system, transfer the archive to another system, and extract
5870 the contents there. The basic transfer medium might be magnetic tape,
5871 Internet FTP, or even electronic mail (though you must encode the
5872 archive with @command{uuencode} in order to transport it properly by
5873 mail). Both machines do not have to use the same operating system, as
5874 long as they both support the @command{tar} program.
5875
5876 For example, here is how you might copy a directory's contents from
5877 one disk to another, while preserving the dates, modes, owners and
5878 link-structure of all the files therein. In this case, the transfer
5879 medium is a @dfn{pipe}:
5880
5881 @smallexample
5882 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5883 @end smallexample
5884
5885 @noindent
5886 You can avoid subshells by using @option{-C} option:
5887
5888 @smallexample
5889 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5890 @end smallexample
5891
5892 @noindent
5893 The command also works using long option forms:
5894
5895 @smallexample
5896 @group
5897 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5898 | (cd targetdir; tar --extract --file=-)}
5899 @end group
5900 @end smallexample
5901
5902 @noindent
5903 or
5904
5905 @smallexample
5906 @group
5907 $ @kbd{tar --directory sourcedir --create --file=- . \
5908 | tar --directory targetdir --extract --file=-}
5909 @end group
5910 @end smallexample
5911
5912 @noindent
5913 This is one of the easiest methods to transfer a @command{tar} archive.
5914
5915 @node looking ahead
5916 @section Looking Ahead: The Rest of this Manual
5917
5918 You have now seen how to use all eight of the operations available to
5919 @command{tar}, and a number of the possible options. The next chapter
5920 explains how to choose and change file and archive names, how to use
5921 files to store names of other files which you can then call as
5922 arguments to @command{tar} (this can help you save time if you expect to
5923 archive the same list of files a number of times), and so forth.
5924 @FIXME{in case it's not obvious, i'm making this up in some sense
5925 based on my limited memory of what the next chapter *really* does. i
5926 just wanted to flesh out this final section a little bit so i'd
5927 remember to stick it in here. :-)}
5928
5929 If there are too many files to conveniently list on the command line,
5930 you can list the names in a file, and @command{tar} will read that file.
5931 @xref{files}.
5932
5933 There are various ways of causing @command{tar} to skip over some files,
5934 and not archive them. @xref{Choosing}.
5935
5936 @node Backups
5937 @chapter Performing Backups and Restoring Files
5938 @cindex backups
5939
5940 @GNUTAR{} is distributed along with the scripts for performing backups
5941 and restores. Even if there is a good chance those scripts may be
5942 satisfying to you, they are not the only scripts or methods available for doing
5943 backups and restore. You may well create your own, or use more
5944 sophisticated packages dedicated to that purpose.
5945
5946 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5947 Automatic Network Disk Archiver), a backup system developed by James
5948 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5949 This is free software, and it is available from @uref{http://www.amanda.org}.
5950
5951 @FIXME{
5952
5953 Here is a possible plan for a future documentation about the backuping
5954 scripts which are provided within the @GNUTAR{}
5955 distribution.
5956
5957 @itemize @bullet
5958 @item dumps
5959 @itemize @minus
5960 @item what are dumps
5961 @item different levels of dumps
5962 @itemize +
5963 @item full dump = dump everything
5964 @item level 1, level 2 dumps etc
5965 A level @var{n} dump dumps everything changed since the last level
5966 @var{n}-1 dump (?)
5967 @end itemize
5968 @item how to use scripts for dumps (ie, the concept)
5969 @itemize +
5970 @item scripts to run after editing backup specs (details)
5971 @end itemize
5972 @item Backup Specs, what is it.
5973 @itemize +
5974 @item how to customize
5975 @item actual text of script [/sp/dump/backup-specs]
5976 @end itemize
5977 @item Problems
5978 @itemize +
5979 @item rsh doesn't work
5980 @item rtape isn't installed
5981 @item (others?)
5982 @end itemize
5983 @item the @option{--incremental} option of tar
5984 @item tapes
5985 @itemize +
5986 @item write protection
5987 @item types of media, different sizes and types, useful for different things
5988 @item files and tape marks
5989 one tape mark between files, two at end.
5990 @item positioning the tape
5991 MT writes two at end of write,
5992 backspaces over one when writing again.
5993 @end itemize
5994 @end itemize
5995 @end itemize
5996 }
5997
5998 This chapter documents both the provided shell scripts and @command{tar}
5999 options which are more specific to usage as a backup tool.
6000
6001 To @dfn{back up} a file system means to create archives that contain
6002 all the files in that file system. Those archives can then be used to
6003 restore any or all of those files (for instance if a disk crashes or a
6004 file is accidentally deleted). File system @dfn{backups} are also
6005 called @dfn{dumps}.
6006
6007 @menu
6008 * Full Dumps:: Using @command{tar} to Perform Full Dumps
6009 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
6010 * Backup Levels:: Levels of Backups
6011 * Backup Parameters:: Setting Parameters for Backups and Restoration
6012 * Scripted Backups:: Using the Backup Scripts
6013 * Scripted Restoration:: Using the Restore Script
6014 @end menu
6015
6016 @node Full Dumps
6017 @section Using @command{tar} to Perform Full Dumps
6018 @UNREVISED
6019
6020 @cindex full dumps
6021 @cindex dumps, full
6022
6023 @cindex corrupted archives
6024 Full dumps should only be made when no other people or programs
6025 are modifying files in the file system. If files are modified while
6026 @command{tar} is making the backup, they may not be stored properly in
6027 the archive, in which case you won't be able to restore them if you
6028 have to. (Files not being modified are written with no trouble, and do
6029 not corrupt the entire archive.)
6030
6031 You will want to use the @option{--label=@var{archive-label}}
6032 (@option{-V @var{archive-label}}) option to give the archive a
6033 volume label, so you can tell what this archive is even if the label
6034 falls off the tape, or anything like that.
6035
6036 Unless the file system you are dumping is guaranteed to fit on
6037 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
6038 Make sure you have enough tapes on hand to complete the backup.
6039
6040 If you want to dump each file system separately you will need to use
6041 the @option{--one-file-system} option to prevent
6042 @command{tar} from crossing file system boundaries when storing
6043 (sub)directories.
6044
6045 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
6046 option is not needed, since this is a complete copy of everything in
6047 the file system, and a full restore from this backup would only be
6048 done onto a completely
6049 empty disk.
6050
6051 Unless you are in a hurry, and trust the @command{tar} program (and your
6052 tapes), it is a good idea to use the @option{--verify} (@option{-W})
6053 option, to make sure your files really made it onto the dump properly.
6054 This will also detect cases where the file was modified while (or just
6055 after) it was being archived. Not all media (notably cartridge tapes)
6056 are capable of being verified, unfortunately.
6057
6058 @node Incremental Dumps
6059 @section Using @command{tar} to Perform Incremental Dumps
6060
6061 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
6062 stores additional metadata so that exact state of the file system
6063 can be restored when extracting the archive.
6064
6065 @GNUTAR{} currently offers two options for handling incremental
6066 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
6067 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
6068
6069 @xopindex{listed-incremental, described}
6070 The option @option{--listed-incremental} instructs tar to operate on
6071 an incremental archive with additional metadata stored in a standalone
6072 file, called a @dfn{snapshot file}. The purpose of this file is to help
6073 determine which files have been changed, added or deleted since the
6074 last backup, so that the next incremental backup will contain only
6075 modified files. The name of the snapshot file is given as an argument
6076 to the option:
6077
6078 @table @option
6079 @item --listed-incremental=@var{file}
6080 @itemx -g @var{file}
6081 Handle incremental backups with snapshot data in @var{file}.
6082 @end table
6083
6084 To create an incremental backup, you would use
6085 @option{--listed-incremental} together with @option{--create}
6086 (@pxref{create}). For example:
6087
6088 @smallexample
6089 $ @kbd{tar --create \
6090 --file=archive.1.tar \
6091 --listed-incremental=/var/log/usr.snar \
6092 /usr}
6093 @end smallexample
6094
6095 This will create in @file{archive.1.tar} an incremental backup of
6096 the @file{/usr} file system, storing additional metadata in the file
6097 @file{/var/log/usr.snar}. If this file does not exist, it will be
6098 created. The created archive will then be a @dfn{level 0 backup};
6099 please see the next section for more on backup levels.
6100
6101 Otherwise, if the file @file{/var/log/usr.snar} exists, it
6102 determines which files are modified. In this case only these files will be
6103 stored in the archive. Suppose, for example, that after running the
6104 above command, you delete file @file{/usr/doc/old} and create
6105 directory @file{/usr/local/db} with the following contents:
6106
6107 @smallexample
6108 $ @kbd{ls /usr/local/db}
6109 /usr/local/db/data
6110 /usr/local/db/index
6111 @end smallexample
6112
6113 Some time later you create another incremental backup. You will
6114 then see:
6115
6116 @smallexample
6117 $ @kbd{tar --create \
6118 --file=archive.2.tar \
6119 --listed-incremental=/var/log/usr.snar \
6120 /usr}
6121 tar: usr/local/db: Directory is new
6122 usr/local/db/
6123 usr/local/db/data
6124 usr/local/db/index
6125 @end smallexample
6126
6127 @noindent
6128 The created archive @file{archive.2.tar} will contain only these
6129 three members. This archive is called a @dfn{level 1 backup}. Notice
6130 that @file{/var/log/usr.snar} will be updated with the new data, so if
6131 you plan to create more @samp{level 1} backups, it is necessary to
6132 create a working copy of the snapshot file before running
6133 @command{tar}. The above example will then be modified as follows:
6134
6135 @smallexample
6136 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
6137 $ @kbd{tar --create \
6138 --file=archive.2.tar \
6139 --listed-incremental=/var/log/usr.snar-1 \
6140 /usr}
6141 @end smallexample
6142
6143 @anchor{--level=0}
6144 @xopindex{level, described}
6145 You can force @samp{level 0} backups either by removing the snapshot
6146 file before running @command{tar}, or by supplying the
6147 @option{--level=0} option, e.g.:
6148
6149 @smallexample
6150 $ @kbd{tar --create \
6151 --file=archive.2.tar \
6152 --listed-incremental=/var/log/usr.snar-0 \
6153 --level=0 \
6154 /usr}
6155 @end smallexample
6156
6157 Incremental dumps depend crucially on time stamps, so the results are
6158 unreliable if you modify a file's time stamps during dumping (e.g.,
6159 with the @option{--atime-preserve=replace} option), or if you set the clock
6160 backwards.
6161
6162 @anchor{device numbers}
6163 @cindex Device numbers, using in incremental backups
6164 Metadata stored in snapshot files include device numbers, which,
6165 obviously are supposed to be non-volatile values. However, it turns
6166 out that @acronym{NFS} devices have undependable values when an automounter
6167 gets in the picture. This can lead to a great deal of spurious
6168 redumping in incremental dumps, so it is somewhat useless to compare
6169 two @acronym{NFS} devices numbers over time. The solution implemented
6170 currently is to consider all @acronym{NFS} devices as being equal
6171 when it comes to comparing directories; this is fairly gross, but
6172 there does not seem to be a better way to go.
6173
6174 Apart from using @acronym{NFS}, there are a number of cases where
6175 relying on device numbers can cause spurious redumping of unmodified
6176 files. For example, this occurs when archiving @acronym{LVM} snapshot
6177 volumes. To avoid this, use @option{--no-check-device} option:
6178
6179 @table @option
6180 @xopindex{no-check-device, described}
6181 @item --no-check-device
6182 Do not rely on device numbers when preparing a list of changed files
6183 for an incremental dump.
6184
6185 @xopindex{check-device, described}
6186 @item --check-device
6187 Use device numbers when preparing a list of changed files
6188 for an incremental dump. This is the default behavior. The purpose
6189 of this option is to undo the effect of the @option{--no-check-device}
6190 if it was given in @env{TAR_OPTIONS} environment variable
6191 (@pxref{TAR_OPTIONS}).
6192 @end table
6193
6194 There is also another way to cope with changing device numbers. It is
6195 described in detail in @ref{Fixing Snapshot Files}.
6196
6197 Note that incremental archives use @command{tar} extensions and may
6198 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6199
6200 @xopindex{listed-incremental, using with @option{--extract}}
6201 @xopindex{extract, using with @option{--listed-incremental}}
6202 To extract from the incremental dumps, use
6203 @option{--listed-incremental} together with @option{--extract}
6204 option (@pxref{extracting files}). In this case, @command{tar} does
6205 not need to access snapshot file, since all the data necessary for
6206 extraction are stored in the archive itself. So, when extracting, you
6207 can give whatever argument to @option{--listed-incremental}, the usual
6208 practice is to use @option{--listed-incremental=/dev/null}.
6209 Alternatively, you can use @option{--incremental}, which needs no
6210 arguments. In general, @option{--incremental} (@option{-G}) can be
6211 used as a shortcut for @option{--listed-incremental} when listing or
6212 extracting incremental backups (for more information regarding this
6213 option, @pxref{incremental-op}).
6214
6215 When extracting from the incremental backup @GNUTAR{} attempts to
6216 restore the exact state the file system had when the archive was
6217 created. In particular, it will @emph{delete} those files in the file
6218 system that did not exist in their directories when the archive was
6219 created. If you have created several levels of incremental files,
6220 then in order to restore the exact contents the file system had when
6221 the last level was created, you will need to restore from all backups
6222 in turn. Continuing our example, to restore the state of @file{/usr}
6223 file system, one would do@footnote{Notice, that since both archives
6224 were created without @option{-P} option (@pxref{absolute}), these
6225 commands should be run from the root file system.}:
6226
6227 @smallexample
6228 $ @kbd{tar --extract \
6229 --listed-incremental=/dev/null \
6230 --file archive.1.tar}
6231 $ @kbd{tar --extract \
6232 --listed-incremental=/dev/null \
6233 --file archive.2.tar}
6234 @end smallexample
6235
6236 To list the contents of an incremental archive, use @option{--list}
6237 (@pxref{list}), as usual. To obtain more information about the
6238 archive, use @option{--listed-incremental} or @option{--incremental}
6239 combined with two @option{--verbose} options@footnote{Two
6240 @option{--verbose} options were selected to avoid breaking usual
6241 verbose listing output (@option{--list --verbose}) when using in
6242 scripts.
6243
6244 @xopindex{incremental, using with @option{--list}}
6245 @xopindex{listed-incremental, using with @option{--list}}
6246 @xopindex{list, using with @option{--incremental}}
6247 @xopindex{list, using with @option{--listed-incremental}}
6248 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6249 contents of the DUMPDIR header (with terminating nulls) when
6250 @option{--incremental} or @option{--listed-incremental} option was
6251 given, no matter what the verbosity level. This behavior, and,
6252 especially, the binary output it produced were considered inconvenient
6253 and were changed in version 1.16.}:
6254
6255 @smallexample
6256 @kbd{tar --list --incremental --verbose --verbose archive.tar}
6257 @end smallexample
6258
6259 This command will print, for each directory in the archive, the list
6260 of files in that directory at the time the archive was created. This
6261 information is put out in a format which is both human-readable and
6262 unambiguous for a program: each file name is printed as
6263
6264 @smallexample
6265 @var{x} @var{file}
6266 @end smallexample
6267
6268 @noindent
6269 where @var{x} is a letter describing the status of the file: @samp{Y}
6270 if the file is present in the archive, @samp{N} if the file is not
6271 included in the archive, or a @samp{D} if the file is a directory (and
6272 is included in the archive). @xref{Dumpdir}, for the detailed
6273 description of dumpdirs and status codes. Each such
6274 line is terminated by a newline character. The last line is followed
6275 by an additional newline to indicate the end of the data.
6276
6277 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6278 gives the same behavior as @option{--listed-incremental} when used
6279 with @option{--list} and @option{--extract} options. When used with
6280 @option{--create} option, it creates an incremental archive without
6281 creating snapshot file. Thus, it is impossible to create several
6282 levels of incremental backups with @option{--incremental} option.
6283
6284 @node Backup Levels
6285 @section Levels of Backups
6286
6287 An archive containing all the files in the file system is called a
6288 @dfn{full backup} or @dfn{full dump}. You could insure your data by
6289 creating a full dump every day. This strategy, however, would waste a
6290 substantial amount of archive media and user time, as unchanged files
6291 are daily re-archived.
6292
6293 It is more efficient to do a full dump only occasionally. To back up
6294 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
6295 one} dump archives all the files that have changed since the last full
6296 dump.
6297
6298 A typical dump strategy would be to perform a full dump once a week,
6299 and a level one dump once a day. This means some versions of files
6300 will in fact be archived more than once, but this dump strategy makes
6301 it possible to restore a file system to within one day of accuracy by
6302 only extracting two archives---the last weekly (full) dump and the
6303 last daily (level one) dump. The only information lost would be in
6304 files changed or created since the last daily backup. (Doing dumps
6305 more than once a day is usually not worth the trouble.)
6306
6307 @GNUTAR{} comes with scripts you can use to do full
6308 and level-one (actually, even level-two and so on) dumps. Using
6309 scripts (shell programs) to perform backups and restoration is a
6310 convenient and reliable alternative to typing out file name lists
6311 and @command{tar} commands by hand.
6312
6313 Before you use these scripts, you need to edit the file
6314 @file{backup-specs}, which specifies parameters used by the backup
6315 scripts and by the restore script. This file is usually located
6316 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
6317 detailed description. Once the backup parameters are set, you can
6318 perform backups or restoration by running the appropriate script.
6319
6320 The name of the backup script is @code{backup}. The name of the
6321 restore script is @code{restore}. The following sections describe
6322 their use in detail.
6323
6324 @emph{Please Note:} The backup and restoration scripts are
6325 designed to be used together. While it is possible to restore files by
6326 hand from an archive which was created using a backup script, and to create
6327 an archive by hand which could then be extracted using the restore script,
6328 it is easier to use the scripts. @xref{Incremental Dumps}, before
6329 making such an attempt.
6330
6331 @node Backup Parameters
6332 @section Setting Parameters for Backups and Restoration
6333
6334 The file @file{backup-specs} specifies backup parameters for the
6335 backup and restoration scripts provided with @command{tar}. You must
6336 edit @file{backup-specs} to fit your system configuration and schedule
6337 before using these scripts.
6338
6339 Syntactically, @file{backup-specs} is a shell script, containing
6340 mainly variable assignments. However, any valid shell construct
6341 is allowed in this file. Particularly, you may wish to define
6342 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6343 For more information about shell script syntax, please refer to
6344 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6345 g_02, the definition of the Shell Command Language}. See also
6346 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6347
6348 The shell variables controlling behavior of @code{backup} and
6349 @code{restore} are described in the following subsections.
6350
6351 @menu
6352 * General-Purpose Variables::
6353 * Magnetic Tape Control::
6354 * User Hooks::
6355 * backup-specs example:: An Example Text of @file{Backup-specs}
6356 @end menu
6357
6358 @node General-Purpose Variables
6359 @subsection General-Purpose Variables
6360
6361 @defvr {Backup variable} ADMINISTRATOR
6362 The user name of the backup administrator. @code{Backup} scripts
6363 sends a backup report to this address.
6364 @end defvr
6365
6366 @defvr {Backup variable} BACKUP_HOUR
6367 The hour at which the backups are done. This can be a number from 0
6368 to 23, or the time specification in form @var{hours}:@var{minutes},
6369 or the string @samp{now}.
6370
6371 This variable is used by @code{backup}. Its value may be overridden
6372 using @option{--time} option (@pxref{Scripted Backups}).
6373 @end defvr
6374
6375 @defvr {Backup variable} TAPE_FILE
6376
6377 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
6378 is a remote archive (@pxref{remote-dev}), backup script will suppose
6379 that your @command{mt} is able to access remote devices. If @var{RSH}
6380 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6381 invocations of @command{mt}.
6382 @end defvr
6383
6384 @defvr {Backup variable} BLOCKING
6385
6386 The blocking factor @command{tar} will use when writing the dump archive.
6387 @xref{Blocking Factor}.
6388 @end defvr
6389
6390 @defvr {Backup variable} BACKUP_DIRS
6391
6392 A list of file systems to be dumped (for @code{backup}), or restored
6393 (for @code{restore}). You can include any directory
6394 name in the list --- subdirectories on that file system will be
6395 included, regardless of how they may look to other networked machines.
6396 Subdirectories on other file systems will be ignored.
6397
6398 The host name specifies which host to run @command{tar} on, and should
6399 normally be the host that actually contains the file system. However,
6400 the host machine must have @GNUTAR{} installed, and
6401 must be able to access the directory containing the backup scripts and
6402 their support files using the same file name that is used on the
6403 machine where the scripts are run (i.e., what @command{pwd} will print
6404 when in that directory on that machine). If the host that contains
6405 the file system does not have this capability, you can specify another
6406 host as long as it can access the file system through @acronym{NFS}.
6407
6408 If the list of file systems is very long you may wish to put it
6409 in a separate file. This file is usually named
6410 @file{/etc/backup/dirs}, but this name may be overridden in
6411 @file{backup-specs} using @code{DIRLIST} variable.
6412 @end defvr
6413
6414 @defvr {Backup variable} DIRLIST
6415
6416 The name of the file that contains a list of file systems to backup
6417 or restore. By default it is @file{/etc/backup/dirs}.
6418 @end defvr
6419
6420 @defvr {Backup variable} BACKUP_FILES
6421
6422 A list of individual files to be dumped (for @code{backup}), or restored
6423 (for @code{restore}). These should be accessible from the machine on
6424 which the backup script is run.
6425
6426 If the list of individual files is very long you may wish to store it
6427 in a separate file. This file is usually named
6428 @file{/etc/backup/files}, but this name may be overridden in
6429 @file{backup-specs} using @code{FILELIST} variable.
6430 @end defvr
6431
6432 @defvr {Backup variable} FILELIST
6433
6434 The name of the file that contains a list of individual files to backup
6435 or restore. By default it is @file{/etc/backup/files}.
6436 @end defvr
6437
6438 @defvr {Backup variable} MT
6439
6440 Full file name of @command{mt} binary.
6441 @end defvr
6442
6443 @defvr {Backup variable} RSH
6444 @anchor{RSH}
6445 Full file name of @command{rsh} binary or its equivalent. You may wish to
6446 set it to @code{ssh}, to improve security. In this case you will have
6447 to use public key authentication.
6448 @end defvr
6449
6450 @defvr {Backup variable} RSH_COMMAND
6451
6452 Full file name of @command{rsh} binary on remote machines. This will
6453 be passed via @option{--rsh-command} option to the remote invocation
6454 of @GNUTAR{}.
6455 @end defvr
6456
6457 @defvr {Backup variable} VOLNO_FILE
6458
6459 Name of temporary file to hold volume numbers. This needs to be accessible
6460 by all the machines which have file systems to be dumped.
6461 @end defvr
6462
6463 @defvr {Backup variable} XLIST
6464
6465 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
6466 located on the remote machine and containing the list of files to
6467 be excluded from the backup. Exclude file lists are searched in
6468 /etc/tar-backup directory. A common use for exclude file lists
6469 is to exclude files containing security-sensitive information
6470 (e.g., @file{/etc/shadow} from backups).
6471
6472 This variable affects only @code{backup}.
6473 @end defvr
6474
6475 @defvr {Backup variable} SLEEP_TIME
6476
6477 Time to sleep between dumps of any two successive file systems
6478
6479 This variable affects only @code{backup}.
6480 @end defvr
6481
6482 @defvr {Backup variable} DUMP_REMIND_SCRIPT
6483
6484 Script to be run when it's time to insert a new tape in for the next
6485 volume. Administrators may want to tailor this script for their site.
6486 If this variable isn't set, @GNUTAR{} will display its built-in
6487 prompt, and will expect confirmation from the console. For the
6488 description of the default prompt, see @ref{change volume prompt}.
6489
6490 @end defvr
6491
6492 @defvr {Backup variable} SLEEP_MESSAGE
6493
6494 Message to display on the terminal while waiting for dump time. Usually
6495 this will just be some literal text.
6496 @end defvr
6497
6498 @defvr {Backup variable} TAR
6499
6500 Full file name of the @GNUTAR{} executable. If this is not set, backup
6501 scripts will search @command{tar} in the current shell path.
6502 @end defvr
6503
6504 @node Magnetic Tape Control
6505 @subsection Magnetic Tape Control
6506
6507 Backup scripts access tape device using special @dfn{hook functions}.
6508 These functions take a single argument --- the name of the tape
6509 device. Their names are kept in the following variables:
6510
6511 @defvr {Backup variable} MT_BEGIN
6512 The name of @dfn{begin} function. This function is called before
6513 accessing the drive. By default it retensions the tape:
6514
6515 @smallexample
6516 MT_BEGIN=mt_begin
6517
6518 mt_begin() @{
6519 mt -f "$1" retension
6520 @}
6521 @end smallexample
6522 @end defvr
6523
6524 @defvr {Backup variable} MT_REWIND
6525 The name of @dfn{rewind} function. The default definition is as
6526 follows:
6527
6528 @smallexample
6529 MT_REWIND=mt_rewind
6530
6531 mt_rewind() @{
6532 mt -f "$1" rewind
6533 @}
6534 @end smallexample
6535
6536 @end defvr
6537
6538 @defvr {Backup variable} MT_OFFLINE
6539 The name of the function switching the tape off line. By default
6540 it is defined as follows:
6541
6542 @smallexample
6543 MT_OFFLINE=mt_offline
6544
6545 mt_offline() @{
6546 mt -f "$1" offl
6547 @}
6548 @end smallexample
6549 @end defvr
6550
6551 @defvr {Backup variable} MT_STATUS
6552 The name of the function used to obtain the status of the archive device,
6553 including error count. Default definition:
6554
6555 @smallexample
6556 MT_STATUS=mt_status
6557
6558 mt_status() @{
6559 mt -f "$1" status
6560 @}
6561 @end smallexample
6562 @end defvr
6563
6564 @node User Hooks
6565 @subsection User Hooks
6566
6567 @dfn{User hooks} are shell functions executed before and after
6568 each @command{tar} invocation. Thus, there are @dfn{backup
6569 hooks}, which are executed before and after dumping each file
6570 system, and @dfn{restore hooks}, executed before and
6571 after restoring a file system. Each user hook is a shell function
6572 taking four arguments:
6573
6574 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6575 Its arguments are:
6576
6577 @table @var
6578 @item level
6579 Current backup or restore level.
6580
6581 @item host
6582 Name or IP address of the host machine being dumped or restored.
6583
6584 @item fs
6585 Full file name of the file system being dumped or restored.
6586
6587 @item fsname
6588 File system name with directory separators replaced with colons. This
6589 is useful, e.g., for creating unique files.
6590 @end table
6591 @end deffn
6592
6593 Following variables keep the names of user hook functions:
6594
6595 @defvr {Backup variable} DUMP_BEGIN
6596 Dump begin function. It is executed before dumping the file system.
6597 @end defvr
6598
6599 @defvr {Backup variable} DUMP_END
6600 Executed after dumping the file system.
6601 @end defvr
6602
6603 @defvr {Backup variable} RESTORE_BEGIN
6604 Executed before restoring the file system.
6605 @end defvr
6606
6607 @defvr {Backup variable} RESTORE_END
6608 Executed after restoring the file system.
6609 @end defvr
6610
6611 @node backup-specs example
6612 @subsection An Example Text of @file{Backup-specs}
6613
6614 The following is an example of @file{backup-specs}:
6615
6616 @smallexample
6617 # site-specific parameters for file system backup.
6618
6619 ADMINISTRATOR=friedman
6620 BACKUP_HOUR=1
6621 TAPE_FILE=/dev/nrsmt0
6622
6623 # Use @code{ssh} instead of the less secure @code{rsh}
6624 RSH=/usr/bin/ssh
6625 RSH_COMMAND=/usr/bin/ssh
6626
6627 # Override MT_STATUS function:
6628 my_status() @{
6629 mts -t $TAPE_FILE
6630 @}
6631 MT_STATUS=my_status
6632
6633 # Disable MT_OFFLINE function
6634 MT_OFFLINE=:
6635
6636 BLOCKING=124
6637 BACKUP_DIRS="
6638 albert:/fs/fsf
6639 apple-gunkies:/gd
6640 albert:/fs/gd2
6641 albert:/fs/gp
6642 geech:/usr/jla
6643 churchy:/usr/roland
6644 albert:/
6645 albert:/usr
6646 apple-gunkies:/
6647 apple-gunkies:/usr
6648 gnu:/hack
6649 gnu:/u
6650 apple-gunkies:/com/mailer/gnu
6651 apple-gunkies:/com/archive/gnu"
6652
6653 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6654
6655 @end smallexample
6656
6657 @node Scripted Backups
6658 @section Using the Backup Scripts
6659
6660 The syntax for running a backup script is:
6661
6662 @smallexample
6663 backup --level=@var{level} --time=@var{time}
6664 @end smallexample
6665
6666 The @option{--level} option requests the dump level. Thus, to produce
6667 a full dump, specify @code{--level=0} (this is the default, so
6668 @option{--level} may be omitted if its value is
6669 @code{0})@footnote{For backward compatibility, the @code{backup} will also
6670 try to deduce the requested dump level from the name of the
6671 script itself. If the name consists of a string @samp{level-}
6672 followed by a single decimal digit, that digit is taken as
6673 the dump level number. Thus, you may create a link from @code{backup}
6674 to @code{level-1} and then run @code{level-1} whenever you need to
6675 create a level one dump.}.
6676
6677 The @option{--time} option determines when should the backup be
6678 run. @var{Time} may take three forms:
6679
6680 @table @asis
6681 @item @var{hh}:@var{mm}
6682
6683 The dump must be run at @var{hh} hours @var{mm} minutes.
6684
6685 @item @var{hh}
6686
6687 The dump must be run at @var{hh} hours.
6688
6689 @item now
6690
6691 The dump must be run immediately.
6692 @end table
6693
6694 You should start a script with a tape or disk mounted. Once you
6695 start a script, it prompts you for new tapes or disks as it
6696 needs them. Media volumes don't have to correspond to archive
6697 files --- a multi-volume archive can be started in the middle of a
6698 tape that already contains the end of another multi-volume archive.
6699 The @code{restore} script prompts for media by its archive volume,
6700 so to avoid an error message you should keep track of which tape
6701 (or disk) contains which volume of the archive (@pxref{Scripted
6702 Restoration}).
6703
6704 The backup scripts write two files on the file system. The first is a
6705 record file in @file{/etc/tar-backup/}, which is used by the scripts
6706 to store and retrieve information about which files were dumped. This
6707 file is not meant to be read by humans, and should not be deleted by
6708 them. @xref{Snapshot Files}, for a more detailed explanation of this
6709 file.
6710
6711 The second file is a log file containing the names of the file systems
6712 and files dumped, what time the backup was made, and any error
6713 messages that were generated, as well as how much space was left in
6714 the media volume after the last volume of the archive was written.
6715 You should check this log file after every backup. The file name is
6716 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6717 represents current date, and @var{n} represents current dump level number.
6718
6719 The script also prints the name of each system being dumped to the
6720 standard output.
6721
6722 Following is the full list of options accepted by @code{backup}
6723 script:
6724
6725 @table @option
6726 @item -l @var{level}
6727 @itemx --level=@var{level}
6728 Do backup level @var{level} (default 0).
6729
6730 @item -f
6731 @itemx --force
6732 Force backup even if today's log file already exists.
6733
6734 @item -v[@var{level}]
6735 @itemx --verbose[=@var{level}]
6736 Set verbosity level. The higher the level is, the more debugging
6737 information will be output during execution. Default @var{level}
6738 is 100, which means the highest debugging level.
6739
6740 @item -t @var{start-time}
6741 @itemx --time=@var{start-time}
6742 Wait till @var{time}, then do backup.
6743
6744 @item -h
6745 @itemx --help
6746 Display short help message and exit.
6747
6748 @item -V
6749 @itemx --version
6750 Display information about the program's name, version, origin and legal
6751 status, all on standard output, and then exit successfully.
6752 @end table
6753
6754
6755 @node Scripted Restoration
6756 @section Using the Restore Script
6757
6758 To restore files that were archived using a scripted backup, use the
6759 @code{restore} script. Its usage is quite straightforward. In the
6760 simplest form, invoke @code{restore --all}, it will
6761 then restore all the file systems and files specified in
6762 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6763
6764 You may select the file systems (and/or files) to restore by
6765 giving @code{restore} a list of @dfn{patterns} in its command
6766 line. For example, running
6767
6768 @smallexample
6769 restore 'albert:*'
6770 @end smallexample
6771
6772 @noindent
6773 will restore all file systems on the machine @samp{albert}. A more
6774 complicated example:
6775
6776 @smallexample
6777 restore 'albert:*' '*:/var'
6778 @end smallexample
6779
6780 @noindent
6781 This command will restore all file systems on the machine @samp{albert}
6782 as well as @file{/var} file system on all machines.
6783
6784 By default @code{restore} will start restoring files from the lowest
6785 available dump level (usually zero) and will continue through
6786 all available dump levels. There may be situations where such a
6787 thorough restore is not necessary. For example, you may wish to
6788 restore only files from the recent level one backup. To do so,
6789 use @option{--level} option, as shown in the example below:
6790
6791 @smallexample
6792 restore --level=1
6793 @end smallexample
6794
6795 The full list of options accepted by @code{restore} follows:
6796
6797 @table @option
6798 @item -a
6799 @itemx --all
6800 Restore all file systems and files specified in @file{backup-specs}.
6801
6802 @item -l @var{level}
6803 @itemx --level=@var{level}
6804 Start restoring from the given backup level, instead of the default 0.
6805
6806 @item -v[@var{level}]
6807 @itemx --verbose[=@var{level}]
6808 Set verbosity level. The higher the level is, the more debugging
6809 information will be output during execution. Default @var{level}
6810 is 100, which means the highest debugging level.
6811
6812 @item -h
6813 @itemx --help
6814 Display short help message and exit.
6815
6816 @item -V
6817 @itemx --version
6818 Display information about the program's name, version, origin and legal
6819 status, all on standard output, and then exit successfully.
6820 @end table
6821
6822 You should start the restore script with the media containing the
6823 first volume of the archive mounted. The script will prompt for other
6824 volumes as they are needed. If the archive is on tape, you don't need
6825 to rewind the tape to to its beginning---if the tape head is
6826 positioned past the beginning of the archive, the script will rewind
6827 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6828 positioning.
6829
6830 @quotation
6831 @strong{Warning:} The script will delete files from the active file
6832 system if they were not in the file system when the archive was made.
6833 @end quotation
6834
6835 @xref{Incremental Dumps}, for an explanation of how the script makes
6836 that determination.
6837
6838 @node Choosing
6839 @chapter Choosing Files and Names for @command{tar}
6840
6841 Certain options to @command{tar} enable you to specify a name for your
6842 archive. Other options let you decide which files to include or exclude
6843 from the archive, based on when or whether files were modified, whether
6844 the file names do or don't match specified patterns, or whether files
6845 are in specified directories.
6846
6847 This chapter discusses these options in detail.
6848
6849 @menu
6850 * file:: Choosing the Archive's Name
6851 * Selecting Archive Members::
6852 * files:: Reading Names from a File
6853 * exclude:: Excluding Some Files
6854 * wildcards:: Wildcards Patterns and Matching
6855 * quoting styles:: Ways of Quoting Special Characters in Names
6856 * transform:: Modifying File and Member Names
6857 * after:: Operating Only on New Files
6858 * recurse:: Descending into Directories
6859 * one:: Crossing File System Boundaries
6860 @end menu
6861
6862 @node file
6863 @section Choosing and Naming Archive Files
6864
6865 @cindex Naming an archive
6866 @cindex Archive Name
6867 @cindex Choosing an archive file
6868 @cindex Where is the archive?
6869 @opindex file
6870 By default, @command{tar} uses an archive file name that was compiled when
6871 it was built on the system; usually this name refers to some physical
6872 tape drive on the machine. However, the person who installed @command{tar}
6873 on the system may not have set the default to a meaningful value as far as
6874 most users are concerned. As a result, you will usually want to tell
6875 @command{tar} where to find (or create) the archive. The
6876 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6877 option allows you to either specify or name a file to use as the archive
6878 instead of the default archive file location.
6879
6880 @table @option
6881 @xopindex{file, short description}
6882 @item --file=@var{archive-name}
6883 @itemx -f @var{archive-name}
6884 Name the archive to create or operate on. Use in conjunction with
6885 any operation.
6886 @end table
6887
6888 For example, in this @command{tar} command,
6889
6890 @smallexample
6891 $ @kbd{tar -cvf collection.tar blues folk jazz}
6892 @end smallexample
6893
6894 @noindent
6895 @file{collection.tar} is the name of the archive. It must directly
6896 follow the @option{-f} option, since whatever directly follows @option{-f}
6897 @emph{will} end up naming the archive. If you neglect to specify an
6898 archive name, you may end up overwriting a file in the working directory
6899 with the archive you create since @command{tar} will use this file's name
6900 for the archive name.
6901
6902 An archive can be saved as a file in the file system, sent through a
6903 pipe or over a network, or written to an I/O device such as a tape,
6904 floppy disk, or CD write drive.
6905
6906 @cindex Writing new archives
6907 @cindex Archive creation
6908 If you do not name the archive, @command{tar} uses the value of the
6909 environment variable @env{TAPE} as the file name for the archive. If
6910 that is not available, @command{tar} uses a default, compiled-in archive
6911 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6912
6913 @cindex Standard input and output
6914 @cindex tar to standard input and output
6915 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6916 archive from standard input (when listing or extracting files), or
6917 writes it to standard output (when creating an archive). If you use
6918 @file{-} as an @var{archive-name} when modifying an archive,
6919 @command{tar} reads the original archive from its standard input and
6920 writes the entire new archive to its standard output.
6921
6922 The following example is a convenient way of copying directory
6923 hierarchy from @file{sourcedir} to @file{targetdir}.
6924
6925 @smallexample
6926 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6927 @end smallexample
6928
6929 The @option{-C} option allows to avoid using subshells:
6930
6931 @smallexample
6932 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6933 @end smallexample
6934
6935 In both examples above, the leftmost @command{tar} invocation archives
6936 the contents of @file{sourcedir} to the standard output, while the
6937 rightmost one reads this archive from its standard input and
6938 extracts it. The @option{-p} option tells it to restore permissions
6939 of the extracted files.
6940
6941 @cindex Remote devices
6942 @cindex tar to a remote device
6943 @anchor{remote-dev}
6944 To specify an archive file on a device attached to a remote machine,
6945 use the following:
6946
6947 @smallexample
6948 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6949 @end smallexample
6950
6951 @noindent
6952 @command{tar} will set up the remote connection, if possible, and
6953 prompt you for a username and password. If you use
6954 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6955 will attempt to set up the remote connection using your username
6956 as the username on the remote machine.
6957
6958 @cindex Local and remote archives
6959 @anchor{local and remote archives}
6960 If the archive file name includes a colon (@samp{:}), then it is assumed
6961 to be a file on another machine. If the archive file is
6962 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6963 host @var{host}. The remote host is accessed using the @command{rsh}
6964 program, with a username of @var{user}. If the username is omitted
6965 (along with the @samp{@@} sign), then your user name will be used.
6966 (This is the normal @command{rsh} behavior.) It is necessary for the
6967 remote machine, in addition to permitting your @command{rsh} access, to
6968 have the @file{rmt} program installed (this command is included in
6969 the @GNUTAR{} distribution and by default is installed under
6970 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
6971 installation prefix). If you need to use a file whose name includes a
6972 colon, then the remote tape drive behavior
6973 can be inhibited by using the @option{--force-local} option.
6974
6975 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6976 tries to minimize input and output operations. The Amanda backup
6977 system, when used with @GNUTAR{}, has an initial sizing pass which
6978 uses this feature.
6979
6980 @node Selecting Archive Members
6981 @section Selecting Archive Members
6982 @cindex Specifying files to act on
6983 @cindex Specifying archive members
6984
6985 @dfn{File Name arguments} specify which files in the file system
6986 @command{tar} operates on, when creating or adding to an archive, or which
6987 archive members @command{tar} operates on, when reading or deleting from
6988 an archive. @xref{Operations}.
6989
6990 To specify file names, you can include them as the last arguments on
6991 the command line, as follows:
6992 @smallexample
6993 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6994 @end smallexample
6995
6996 If a file name begins with dash (@samp{-}), precede it with
6997 @option{--add-file} option to prevent it from being treated as an
6998 option.
6999
7000 @anchor{input name quoting}
7001 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
7002 name, replacing @dfn{escape sequences} according to the following
7003 table:
7004
7005 @multitable @columnfractions 0.20 0.60
7006 @headitem Escape @tab Replaced with
7007 @item \a @tab Audible bell (@acronym{ASCII} 7)
7008 @item \b @tab Backspace (@acronym{ASCII} 8)
7009 @item \f @tab Form feed (@acronym{ASCII} 12)
7010 @item \n @tab New line (@acronym{ASCII} 10)
7011 @item \r @tab Carriage return (@acronym{ASCII} 13)
7012 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
7013 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
7014 @item \? @tab @acronym{ASCII} 127
7015 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
7016 of up to 3 digits)
7017 @end multitable
7018
7019 A backslash followed by any other symbol is retained.
7020
7021 This default behavior is controlled by the following command line
7022 option:
7023
7024 @table @option
7025 @opindex unquote
7026 @item --unquote
7027 Enable unquoting input file or member names (default).
7028
7029 @opindex no-unquote
7030 @item --no-unquote
7031 Disable unquoting input file or member names.
7032 @end table
7033
7034 If you specify a directory name as a file name argument, all the files
7035 in that directory are operated on by @command{tar}.
7036
7037 If you do not specify files, @command{tar} behavior differs depending
7038 on the operation mode as described below:
7039
7040 When @command{tar} is invoked with @option{--create} (@option{-c}),
7041 @command{tar} will stop immediately, reporting the following:
7042
7043 @smallexample
7044 @group
7045 $ @kbd{tar cf a.tar}
7046 tar: Cowardly refusing to create an empty archive
7047 Try 'tar --help' or 'tar --usage' for more information.
7048 @end group
7049 @end smallexample
7050
7051 If you specify either @option{--list} (@option{-t}) or
7052 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
7053 operates on all the archive members in the archive.
7054
7055 If run with @option{--diff} option, tar will compare the archive with
7056 the contents of the current working directory.
7057
7058 If you specify any other operation, @command{tar} does nothing.
7059
7060 By default, @command{tar} takes file names from the command line. However,
7061 there are other ways to specify file or member names, or to modify the
7062 manner in which @command{tar} selects the files or members upon which to
7063 operate. In general, these methods work both for specifying the names
7064 of files and archive members.
7065
7066 @node files
7067 @section Reading Names from a File
7068
7069 @cindex Reading file names from a file
7070 @cindex Lists of file names
7071 @cindex File Name arguments, alternatives
7072 @cindex @command{find}, using with @command{tar}
7073 Instead of giving the names of files or archive members on the command
7074 line, you can put the names into a file, and then use the
7075 @option{--files-from=@var{file-of-names}} (@option{-T
7076 @var{file-of-names}}) option to @command{tar}. Give the name of the
7077 file which contains the list of files to include as the argument to
7078 @option{--files-from}. In the list, the file names should be separated by
7079 newlines. You will frequently use this option when you have generated
7080 the list of files to archive with the @command{find} utility.
7081
7082 @table @option
7083 @opindex files-from
7084 @item --files-from=@var{file-name}
7085 @itemx -T @var{file-name}
7086 Get names to extract or create from file @var{file-name}.
7087 @end table
7088
7089 If you give a single dash as a file name for @option{--files-from}, (i.e.,
7090 you specify either @code{--files-from=-} or @code{-T -}), then the file
7091 names are read from standard input.
7092
7093 Unless you are running @command{tar} with @option{--create}, you can not use
7094 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
7095 command.
7096
7097 Any number of @option{-T} options can be given in the command line.
7098
7099 The following example shows how to use @command{find} to generate a list of
7100 files smaller than 400K in length and put that list into a file
7101 called @file{small-files}. You can then use the @option{-T} option to
7102 @command{tar} to specify the files from that file, @file{small-files}, to
7103 create the archive @file{little.tgz}. (The @option{-z} option to
7104 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
7105 more information.)
7106
7107 @smallexample
7108 $ @kbd{find . -size -400 -print > small-files}
7109 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
7110 @end smallexample
7111
7112 @noindent
7113 In the file list given by @option{-T} option, any file name beginning
7114 with @samp{-} character is considered a @command{tar} option and is
7115 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
7116 recognized only @option{-C} option in file lists, and only if the
7117 option and its argument occupied two consecutive lines.}. For example,
7118 the common use of this feature is to change to another directory by
7119 specifying @option{-C} option:
7120
7121 @smallexample
7122 @group
7123 $ @kbd{cat list}
7124 -C/etc
7125 passwd
7126 hosts
7127 -C/lib
7128 libc.a
7129 $ @kbd{tar -c -f foo.tar --files-from list}
7130 @end group
7131 @end smallexample
7132
7133 @noindent
7134 In this example, @command{tar} will first switch to @file{/etc}
7135 directory and add files @file{passwd} and @file{hosts} to the
7136 archive. Then it will change to @file{/lib} directory and will archive
7137 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
7138 contain:
7139
7140 @smallexample
7141 @group
7142 $ @kbd{tar tf foo.tar}
7143 passwd
7144 hosts
7145 libc.a
7146 @end group
7147 @end smallexample
7148
7149 @opindex add-file
7150 If you happen to have a file whose name starts with @samp{-},
7151 precede it with @option{--add-file} option to prevent it from
7152 being recognized as an option. For example: @code{--add-file=--my-file}.
7153
7154 @menu
7155 * nul::
7156 @end menu
7157
7158 @node nul
7159 @subsection @code{NUL}-Terminated File Names
7160
7161 @cindex File names, terminated by @code{NUL}
7162 @cindex @code{NUL}-terminated file names
7163 The @option{--null} option causes
7164 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7165 to read file names terminated by a @code{NUL} instead of a newline, so
7166 files whose names contain newlines can be archived using
7167 @option{--files-from}.
7168
7169 @table @option
7170 @xopindex{null, described}
7171 @item --null
7172 Only consider @code{NUL}-terminated file names, instead of files that
7173 terminate in a newline.
7174
7175 @xopindex{no-null, described}
7176 @item --no-null
7177 Undo the effect of any previous @option{--null} option.
7178 @end table
7179
7180 The @option{--null} option is just like the one in @acronym{GNU}
7181 @command{xargs} and @command{cpio}, and is useful with the
7182 @option{-print0} predicate of @acronym{GNU} @command{find}. In
7183 @command{tar}, @option{--null} also disables special handling for
7184 file names that begin with dash.
7185
7186 This example shows how to use @command{find} to generate a list of files
7187 larger than 800K in length and put that list into a file called
7188 @file{long-files}. The @option{-print0} option to @command{find} is just
7189 like @option{-print}, except that it separates files with a @code{NUL}
7190 rather than with a newline. You can then run @command{tar} with both the
7191 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7192 files from that file, @file{long-files}, to create the archive
7193 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
7194 @command{tar} to recognize the @code{NUL} separator between files.
7195
7196 @smallexample
7197 $ @kbd{find . -size +800 -print0 > long-files}
7198 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7199 @end smallexample
7200
7201 The @option{--no-null} option can be used if you need to read both
7202 @code{NUL}-terminated and newline-terminated files on the same command line.
7203 For example, if @file{flist} is a newline-terminated file, then the
7204 following command can be used to combine it with the above command:
7205
7206 @smallexample
7207 @group
7208 $ @kbd{find . -size +800 -print0 |
7209 tar -c -f big.tar --null -T - --no-null -T flist}
7210 @end group
7211 @end smallexample
7212
7213 This example uses short options for typographic reasons, to avoid
7214 very long lines.
7215
7216 @GNUTAR is tries to automatically detect @code{NUL}-terminated file
7217 lists, so in many cases it is safe to use them even without the
7218 @option{--null} option. In this case @command{tar} will print a
7219 warning and continue reading such a file as if @option{--null} were
7220 actually given:
7221
7222 @smallexample
7223 @group
7224 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7225 tar: -: file name read contains nul character
7226 @end group
7227 @end smallexample
7228
7229 The null terminator, however, remains in effect only for this
7230 particular file, any following @option{-T} options will assume
7231 newline termination. Of course, the null autodetection applies
7232 to these eventual surplus @option{-T} options as well.
7233
7234 @node exclude
7235 @section Excluding Some Files
7236
7237 @cindex File names, excluding files by
7238 @cindex Excluding files by name and pattern
7239 @cindex Excluding files by file system
7240 @opindex exclude
7241 @opindex exclude-from
7242 To avoid operating on files whose names match a particular pattern,
7243 use the @option{--exclude} or @option{--exclude-from} options.
7244
7245 @table @option
7246 @opindex exclude
7247 @item --exclude=@var{pattern}
7248 Causes @command{tar} to ignore files that match the @var{pattern}.
7249 @end table
7250
7251 @findex exclude
7252 The @option{--exclude=@var{pattern}} option prevents any file or
7253 member whose name matches the shell wildcard (@var{pattern}) from
7254 being operated on.
7255 For example, to create an archive with all the contents of the directory
7256 @file{src} except for files whose names end in @file{.o}, use the
7257 command @samp{tar -cf src.tar --exclude='*.o' src}.
7258
7259 You may give multiple @option{--exclude} options.
7260
7261 @table @option
7262 @opindex exclude-from
7263 @item --exclude-from=@var{file}
7264 @itemx -X @var{file}
7265 Causes @command{tar} to ignore files that match the patterns listed in
7266 @var{file}.
7267 @end table
7268
7269 @findex exclude-from
7270 Use the @option{--exclude-from} option to read a
7271 list of patterns, one per line, from @var{file}; @command{tar} will
7272 ignore files matching those patterns. Thus if @command{tar} is
7273 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7274 single line @file{*.o}, no files whose names end in @file{.o} will be
7275 added to the archive.
7276
7277 Notice, that lines from @var{file} are read verbatim. One of the
7278 frequent errors is leaving some extra whitespace after a file name,
7279 which is difficult to catch using text editors.
7280
7281 However, empty lines are OK.
7282
7283 @table @option
7284 @cindex version control system, excluding files
7285 @cindex VCS, excluding files
7286 @cindex SCCS, excluding files
7287 @cindex RCS, excluding files
7288 @cindex CVS, excluding files
7289 @cindex SVN, excluding files
7290 @cindex git, excluding files
7291 @cindex Bazaar, excluding files
7292 @cindex Arch, excluding files
7293 @cindex Mercurial, excluding files
7294 @cindex Darcs, excluding files
7295 @opindex exclude-vcs
7296 @item --exclude-vcs
7297 Exclude files and directories used by following version control
7298 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
7299 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
7300
7301 As of version @value{VERSION}, the following files are excluded:
7302
7303 @itemize @bullet
7304 @item @file{CVS/}, and everything under it
7305 @item @file{RCS/}, and everything under it
7306 @item @file{SCCS/}, and everything under it
7307 @item @file{.git/}, and everything under it
7308 @item @file{.gitignore}
7309 @item @file{.cvsignore}
7310 @item @file{.svn/}, and everything under it
7311 @item @file{.arch-ids/}, and everything under it
7312 @item @file{@{arch@}/}, and everything under it
7313 @item @file{=RELEASE-ID}
7314 @item @file{=meta-update}
7315 @item @file{=update}
7316 @item @file{.bzr}
7317 @item @file{.bzrignore}
7318 @item @file{.bzrtags}
7319 @item @file{.hg}
7320 @item @file{.hgignore}
7321 @item @file{.hgrags}
7322 @item @file{_darcs}
7323 @end itemize
7324
7325 @opindex exclude-backups
7326 @item --exclude-backups
7327 Exclude backup and lock files. This option causes exclusion of files
7328 that match the following shell globbing patterns:
7329
7330 @table @asis
7331 @item .#*
7332 @item *~
7333 @item #*#
7334 @end table
7335
7336 @end table
7337
7338 @findex exclude-caches
7339 When creating an archive, the @option{--exclude-caches} option family
7340 causes @command{tar} to exclude all directories that contain a @dfn{cache
7341 directory tag}. A cache directory tag is a short file with the
7342 well-known name @file{CACHEDIR.TAG} and having a standard header
7343 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
7344 Various applications write cache directory tags into directories they
7345 use to hold regenerable, non-precious data, so that such data can be
7346 more easily excluded from backups.
7347
7348 There are three @samp{exclude-caches} options, each providing a different
7349 exclusion semantics:
7350
7351 @table @option
7352 @opindex exclude-caches
7353 @item --exclude-caches
7354 Do not archive the contents of the directory, but archive the
7355 directory itself and the @file{CACHEDIR.TAG} file.
7356
7357 @opindex exclude-caches-under
7358 @item --exclude-caches-under
7359 Do not archive the contents of the directory, nor the
7360 @file{CACHEDIR.TAG} file, archive only the directory itself.
7361
7362 @opindex exclude-caches-all
7363 @item --exclude-caches-all
7364 Omit directories containing @file{CACHEDIR.TAG} file entirely.
7365 @end table
7366
7367 @findex exclude-tag
7368 Another option family, @option{--exclude-tag}, provides a generalization of
7369 this concept. It takes a single argument, a file name to look for.
7370 Any directory that contains this file will be excluded from the dump.
7371 Similarly to @samp{exclude-caches}, there are three options in this
7372 option family:
7373
7374 @table @option
7375 @opindex exclude-tag
7376 @item --exclude-tag=@var{file}
7377 Do not dump the contents of the directory, but dump the
7378 directory itself and the @var{file}.
7379
7380 @opindex exclude-tag-under
7381 @item --exclude-tag-under=@var{file}
7382 Do not dump the contents of the directory, nor the
7383 @var{file}, archive only the directory itself.
7384
7385 @opindex exclude-tag-all
7386 @item --exclude-tag-all=@var{file}
7387 Omit directories containing @var{file} file entirely.
7388 @end table
7389
7390 Multiple @option{--exclude-tag*} options can be given.
7391
7392 For example, given this directory:
7393
7394 @smallexample
7395 @group
7396 $ @kbd{find dir}
7397 dir
7398 dir/blues
7399 dir/jazz
7400 dir/folk
7401 dir/folk/tagfile
7402 dir/folk/sanjuan
7403 dir/folk/trote
7404 @end group
7405 @end smallexample
7406
7407 The @option{--exclude-tag} will produce the following:
7408
7409 @smallexample
7410 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
7411 dir/
7412 dir/blues
7413 dir/jazz
7414 dir/folk/
7415 tar: dir/folk/: contains a cache directory tag tagfile;
7416 contents not dumped
7417 dir/folk/tagfile
7418 @end smallexample
7419
7420 Both the @file{dir/folk} directory and its tagfile are preserved in
7421 the archive, however the rest of files in this directory are not.
7422
7423 Now, using the @option{--exclude-tag-under} option will exclude
7424 @file{tagfile} from the dump, while still preserving the directory
7425 itself, as shown in this example:
7426
7427 @smallexample
7428 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
7429 dir/
7430 dir/blues
7431 dir/jazz
7432 dir/folk/
7433 ./tar: dir/folk/: contains a cache directory tag tagfile;
7434 contents not dumped
7435 @end smallexample
7436
7437 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
7438 directory entirely:
7439
7440 @smallexample
7441 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
7442 dir/
7443 dir/blues
7444 dir/jazz
7445 ./tar: dir/folk/: contains a cache directory tag tagfile;
7446 directory not dumped
7447 @end smallexample
7448
7449 @menu
7450 * problems with exclude::
7451 @end menu
7452
7453 @node problems with exclude
7454 @unnumberedsubsec Problems with Using the @code{exclude} Options
7455
7456 @xopindex{exclude, potential problems with}
7457 Some users find @samp{exclude} options confusing. Here are some common
7458 pitfalls:
7459
7460 @itemize @bullet
7461 @item
7462 The main operating mode of @command{tar} does not act on a file name
7463 explicitly listed on the command line, if one of its file name
7464 components is excluded. In the example above, if
7465 you create an archive and exclude files that end with @samp{*.o}, but
7466 explicitly name the file @samp{dir.o/foo} after all the options have been
7467 listed, @samp{dir.o/foo} will be excluded from the archive.
7468
7469 @item
7470 You can sometimes confuse the meanings of @option{--exclude} and
7471 @option{--exclude-from}. Be careful: use @option{--exclude} when files
7472 to be excluded are given as a pattern on the command line. Use
7473 @option{--exclude-from} to introduce the name of a file which contains
7474 a list of patterns, one per line; each of these patterns can exclude
7475 zero, one, or many files.
7476
7477 @item
7478 When you use @option{--exclude=@var{pattern}}, be sure to quote the
7479 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
7480 like @samp{*}. If you do not do this, the shell might expand the
7481 @samp{*} itself using files at hand, so @command{tar} might receive a
7482 list of files instead of one pattern, or none at all, making the
7483 command somewhat illegal. This might not correspond to what you want.
7484
7485 For example, write:
7486
7487 @smallexample
7488 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
7489 @end smallexample
7490
7491 @noindent
7492 rather than:
7493
7494 @smallexample
7495 # @emph{Wrong!}
7496 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
7497 @end smallexample
7498
7499 @item
7500 You must use use shell syntax, or globbing, rather than @code{regexp}
7501 syntax, when using exclude options in @command{tar}. If you try to use
7502 @code{regexp} syntax to describe files to be excluded, your command
7503 might fail.
7504
7505 @item
7506 @FIXME{The change in semantics must have occurred before 1.11,
7507 so I doubt if it is worth mentioning at all. Anyway, should at
7508 least specify in which version the semantics changed.}
7509 In earlier versions of @command{tar}, what is now the
7510 @option{--exclude-from} option was called @option{--exclude} instead.
7511 Now, @option{--exclude} applies to patterns listed on the command
7512 line and @option{--exclude-from} applies to patterns listed in a
7513 file.
7514
7515 @end itemize
7516
7517 @node wildcards
7518 @section Wildcards Patterns and Matching
7519
7520 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
7521 @samp{*} or @samp{?} for example, are replaced and expanded into all
7522 existing files matching the given pattern. @GNUTAR{} can use wildcard
7523 patterns for matching (or globbing) archive members when extracting
7524 from or listing an archive. Wildcard patterns are also used for
7525 verifying volume labels of @command{tar} archives. This section has the
7526 purpose of explaining wildcard syntax for @command{tar}.
7527
7528 @FIXME{the next few paragraphs need work.}
7529
7530 A @var{pattern} should be written according to shell syntax, using wildcard
7531 characters to effect globbing. Most characters in the pattern stand
7532 for themselves in the matched string, and case is significant: @samp{a}
7533 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7534 pattern matches any single character in the matched string. The character
7535 @samp{*} in the pattern matches zero, one, or more single characters in
7536 the matched string. The character @samp{\} says to take the following
7537 character of the pattern @emph{literally}; it is useful when one needs to
7538 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7539
7540 The character @samp{[}, up to the matching @samp{]}, introduces a character
7541 class. A @dfn{character class} is a list of acceptable characters
7542 for the next single character of the matched string. For example,
7543 @samp{[abcde]} would match any of the first five letters of the alphabet.
7544 Note that within a character class, all of the ``special characters''
7545 listed above other than @samp{\} lose their special meaning; for example,
7546 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7547 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7548 the characters @samp{-} and @samp{]} must either come @emph{first} or
7549 @emph{last} in a character class.)
7550
7551 @cindex Excluding characters from a character class
7552 @cindex Character class, excluding characters from
7553 If the first character of the class after the opening @samp{[}
7554 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7555 Rather than listing character to match, it lists those characters which
7556 are @emph{forbidden} as the next single character of the matched string.
7557
7558 Other characters of the class stand for themselves. The special
7559 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7560 letters, is meant to represent all characters between @var{a} and
7561 @var{e}, inclusive.
7562
7563 @FIXME{need to add a sentence or so here to make this clear for those
7564 who don't have dan around.}
7565
7566 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7567 special for wildcard matches. However, if a pattern completely matches
7568 a directory prefix of a matched string, then it matches the full matched
7569 string: thus, excluding a directory also excludes all the files beneath it.
7570
7571 @menu
7572 * controlling pattern-matching::
7573 @end menu
7574
7575 @node controlling pattern-matching
7576 @unnumberedsubsec Controlling Pattern-Matching
7577
7578 For the purposes of this section, we call @dfn{exclusion members} all
7579 member names obtained while processing @option{--exclude} and
7580 @option{--exclude-from} options, and @dfn{inclusion members} those
7581 member names that were given in the command line or read from the file
7582 specified with @option{--files-from} option.
7583
7584 These two pairs of member lists are used in the following operations:
7585 @option{--diff}, @option{--extract}, @option{--list},
7586 @option{--update}.
7587
7588 There are no inclusion members in create mode (@option{--create} and
7589 @option{--append}), since in this mode the names obtained from the
7590 command line refer to @emph{files}, not archive members.
7591
7592 By default, inclusion members are compared with archive members
7593 literally @footnote{Notice that earlier @GNUTAR{} versions used
7594 globbing for inclusion members, which contradicted to UNIX98
7595 specification and was not documented. @xref{Changes}, for more
7596 information on this and other changes.} and exclusion members are
7597 treated as globbing patterns. For example:
7598
7599 @smallexample
7600 @group
7601 $ @kbd{tar tf foo.tar}
7602 a.c
7603 b.c
7604 a.txt
7605 [remarks]
7606 # @i{Member names are used verbatim:}
7607 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7608 [remarks]
7609 # @i{Exclude member names are globbed:}
7610 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7611 a.txt
7612 [remarks]
7613 @end group
7614 @end smallexample
7615
7616 This behavior can be altered by using the following options:
7617
7618 @table @option
7619 @opindex wildcards
7620 @item --wildcards
7621 Treat all member names as wildcards.
7622
7623 @opindex no-wildcards
7624 @item --no-wildcards
7625 Treat all member names as literal strings.
7626 @end table
7627
7628 Thus, to extract files whose names end in @samp{.c}, you can use:
7629
7630 @smallexample
7631 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7632 a.c
7633 b.c
7634 @end smallexample
7635
7636 @noindent
7637 Notice quoting of the pattern to prevent the shell from interpreting
7638 it.
7639
7640 The effect of @option{--wildcards} option is canceled by
7641 @option{--no-wildcards}. This can be used to pass part of
7642 the command line arguments verbatim and other part as globbing
7643 patterns. For example, the following invocation:
7644
7645 @smallexample
7646 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7647 @end smallexample
7648
7649 @noindent
7650 instructs @command{tar} to extract from @file{foo.tar} all files whose
7651 names end in @samp{.txt} and the file named @file{[remarks]}.
7652
7653 Normally, a pattern matches a name if an initial subsequence of the
7654 name's components matches the pattern, where @samp{*}, @samp{?}, and
7655 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7656 and wildcards can match @samp{/}.
7657
7658 Other than optionally stripping leading @samp{/} from names
7659 (@pxref{absolute}), patterns and names are used as-is. For
7660 example, trailing @samp{/} is not trimmed from a user-specified name
7661 before deciding whether to exclude it.
7662
7663 However, this matching procedure can be altered by the options listed
7664 below. These options accumulate. For example:
7665
7666 @smallexample
7667 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7668 @end smallexample
7669
7670 @noindent
7671 ignores case when excluding @samp{makefile}, but not when excluding
7672 @samp{readme}.
7673
7674 @table @option
7675 @opindex anchored
7676 @opindex no-anchored
7677 @item --anchored
7678 @itemx --no-anchored
7679 If anchored, a pattern must match an initial subsequence
7680 of the name's components. Otherwise, the pattern can match any
7681 subsequence. Default is @option{--no-anchored} for exclusion members
7682 and @option{--anchored} inclusion members.
7683
7684 @opindex ignore-case
7685 @opindex no-ignore-case
7686 @item --ignore-case
7687 @itemx --no-ignore-case
7688 When ignoring case, upper-case patterns match lower-case names and vice versa.
7689 When not ignoring case (the default), matching is case-sensitive.
7690
7691 @opindex wildcards-match-slash
7692 @opindex no-wildcards-match-slash
7693 @item --wildcards-match-slash
7694 @itemx --no-wildcards-match-slash
7695 When wildcards match slash (the default for exclusion members), a
7696 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7697 name. Otherwise, @samp{/} is matched only by @samp{/}.
7698
7699 @end table
7700
7701 The @option{--recursion} and @option{--no-recursion} options
7702 (@pxref{recurse}) also affect how member patterns are interpreted. If
7703 recursion is in effect, a pattern matches a name if it matches any of
7704 the name's parent directories.
7705
7706 The following table summarizes pattern-matching default values:
7707
7708 @multitable @columnfractions .3 .7
7709 @headitem Members @tab Default settings
7710 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7711 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7712 @end multitable
7713
7714 @node quoting styles
7715 @section Quoting Member Names
7716
7717 When displaying member names, @command{tar} takes care to avoid
7718 ambiguities caused by certain characters. This is called @dfn{name
7719 quoting}. The characters in question are:
7720
7721 @itemize @bullet
7722 @item Non-printable control characters:
7723 @anchor{escape sequences}
7724 @multitable @columnfractions 0.20 0.10 0.60
7725 @headitem Character @tab @acronym{ASCII} @tab Character name
7726 @item \a @tab 7 @tab Audible bell
7727 @item \b @tab 8 @tab Backspace
7728 @item \f @tab 12 @tab Form feed
7729 @item \n @tab 10 @tab New line
7730 @item \r @tab 13 @tab Carriage return
7731 @item \t @tab 9 @tab Horizontal tabulation
7732 @item \v @tab 11 @tab Vertical tabulation
7733 @end multitable
7734
7735 @item Space (@acronym{ASCII} 32)
7736
7737 @item Single and double quotes (@samp{'} and @samp{"})
7738
7739 @item Backslash (@samp{\})
7740 @end itemize
7741
7742 The exact way @command{tar} uses to quote these characters depends on
7743 the @dfn{quoting style}. The default quoting style, called
7744 @dfn{escape} (see below), uses backslash notation to represent control
7745 characters, space and backslash. Using this quoting style, control
7746 characters are represented as listed in column @samp{Character} in the
7747 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7748
7749 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7750 using @option{--quoting-style} option:
7751
7752 @table @option
7753 @item --quoting-style=@var{style}
7754 @opindex quoting-style
7755
7756 Sets quoting style. Valid values for @var{style} argument are:
7757 literal, shell, shell-always, c, escape, locale, clocale.
7758 @end table
7759
7760 These styles are described in detail below. To illustrate their
7761 effect, we will use an imaginary tar archive @file{arch.tar}
7762 containing the following members:
7763
7764 @smallexample
7765 @group
7766 # 1. Contains horizontal tabulation character.
7767 a tab
7768 # 2. Contains newline character
7769 a
7770 newline
7771 # 3. Contains a space
7772 a space
7773 # 4. Contains double quotes
7774 a"double"quote
7775 # 5. Contains single quotes
7776 a'single'quote
7777 # 6. Contains a backslash character:
7778 a\backslash
7779 @end group
7780 @end smallexample
7781
7782 Here is how usual @command{ls} command would have listed them, if they
7783 had existed in the current working directory:
7784
7785 @smallexample
7786 @group
7787 $ @kbd{ls}
7788 a\ttab
7789 a\nnewline
7790 a\ space
7791 a"double"quote
7792 a'single'quote
7793 a\\backslash
7794 @end group
7795 @end smallexample
7796
7797 Quoting styles:
7798
7799 @table @samp
7800 @item literal
7801 No quoting, display each character as is:
7802
7803 @smallexample
7804 @group
7805 $ @kbd{tar tf arch.tar --quoting-style=literal}
7806 ./
7807 ./a space
7808 ./a'single'quote
7809 ./a"double"quote
7810 ./a\backslash
7811 ./a tab
7812 ./a
7813 newline
7814 @end group
7815 @end smallexample
7816
7817 @item shell
7818 Display characters the same way Bourne shell does:
7819 control characters, except @samp{\t} and @samp{\n}, are printed using
7820 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7821 single quote is printed as @samp{\'}. If a name contains any quoted
7822 characters, it is enclosed in single quotes. In particular, if a name
7823 contains single quotes, it is printed as several single-quoted strings:
7824
7825 @smallexample
7826 @group
7827 $ @kbd{tar tf arch.tar --quoting-style=shell}
7828 ./
7829 './a space'
7830 './a'\''single'\''quote'
7831 './a"double"quote'
7832 './a\backslash'
7833 './a tab'
7834 './a
7835 newline'
7836 @end group
7837 @end smallexample
7838
7839 @item shell-always
7840 Same as @samp{shell}, but the names are always enclosed in single
7841 quotes:
7842
7843 @smallexample
7844 @group
7845 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7846 './'
7847 './a space'
7848 './a'\''single'\''quote'
7849 './a"double"quote'
7850 './a\backslash'
7851 './a tab'
7852 './a
7853 newline'
7854 @end group
7855 @end smallexample
7856
7857 @item c
7858 Use the notation of the C programming language. All names are
7859 enclosed in double quotes. Control characters are quoted using
7860 backslash notations, double quotes are represented as @samp{\"},
7861 backslash characters are represented as @samp{\\}. Single quotes and
7862 spaces are not quoted:
7863
7864 @smallexample
7865 @group
7866 $ @kbd{tar tf arch.tar --quoting-style=c}
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
7877 @item escape
7878 Control characters are printed using backslash notation, a space is
7879 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7880 default quoting style, unless it was changed when configured the
7881 package.
7882
7883 @smallexample
7884 @group
7885 $ @kbd{tar tf arch.tar --quoting-style=escape}
7886 ./
7887 ./a space
7888 ./a'single'quote
7889 ./a"double"quote
7890 ./a\\backslash
7891 ./a\ttab
7892 ./a\nnewline
7893 @end group
7894 @end smallexample
7895
7896 @item locale
7897 Control characters, single quote and backslash are printed using
7898 backslash notation. All names are quoted using left and right
7899 quotation marks, appropriate to the current locale. If it does not
7900 define quotation marks, use @samp{'} as left and as right
7901 quotation marks. Any occurrences of the right quotation mark in a
7902 name are escaped with @samp{\}, for example:
7903
7904 For example:
7905
7906 @smallexample
7907 @group
7908 $ @kbd{tar tf arch.tar --quoting-style=locale}
7909 './'
7910 './a space'
7911 './a\'single\'quote'
7912 './a"double"quote'
7913 './a\\backslash'
7914 './a\ttab'
7915 './a\nnewline'
7916 @end group
7917 @end smallexample
7918
7919 @item clocale
7920 Same as @samp{locale}, but @samp{"} is used for both left and right
7921 quotation marks, if not provided by the currently selected locale:
7922
7923 @smallexample
7924 @group
7925 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7926 "./"
7927 "./a space"
7928 "./a'single'quote"
7929 "./a\"double\"quote"
7930 "./a\\backslash"
7931 "./a\ttab"
7932 "./a\nnewline"
7933 @end group
7934 @end smallexample
7935 @end table
7936
7937 You can specify which characters should be quoted in addition to those
7938 implied by the current quoting style:
7939
7940 @table @option
7941 @item --quote-chars=@var{string}
7942 Always quote characters from @var{string}, even if the selected
7943 quoting style would not quote them.
7944 @end table
7945
7946 For example, using @samp{escape} quoting (compare with the usual
7947 escape listing above):
7948
7949 @smallexample
7950 @group
7951 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7952 ./
7953 ./a\ space
7954 ./a'single'quote
7955 ./a\"double\"quote
7956 ./a\\backslash
7957 ./a\ttab
7958 ./a\nnewline
7959 @end group
7960 @end smallexample
7961
7962 To disable quoting of such additional characters, use the following
7963 option:
7964
7965 @table @option
7966 @item --no-quote-chars=@var{string}
7967 Remove characters listed in @var{string} from the list of quoted
7968 characters set by the previous @option{--quote-chars} option.
7969 @end table
7970
7971 This option is particularly useful if you have added
7972 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7973 and wish to disable it for the current invocation.
7974
7975 Note, that @option{--no-quote-chars} does @emph{not} disable those
7976 characters that are quoted by default in the selected quoting style.
7977
7978 @node transform
7979 @section Modifying File and Member Names
7980
7981 @command{Tar} archives contain detailed information about files stored
7982 in them and full file names are part of that information. When
7983 storing a file to an archive, its file name is recorded in it,
7984 along with the actual file contents. When restoring from an archive,
7985 a file is created on disk with exactly the same name as that stored
7986 in the archive. In the majority of cases this is the desired behavior
7987 of a file archiver. However, there are some cases when it is not.
7988
7989 First of all, it is often unsafe to extract archive members with
7990 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7991 takes special precautions when extracting such names and provides a
7992 special option for handling them, which is described in
7993 @ref{absolute}.
7994
7995 Secondly, you may wish to extract file names without some leading
7996 directory components, or with otherwise modified names. In other
7997 cases it is desirable to store files under differing names in the
7998 archive.
7999
8000 @GNUTAR{} provides several options for these needs.
8001
8002 @table @option
8003 @opindex strip-components
8004 @item --strip-components=@var{number}
8005 Strip given @var{number} of leading components from file names before
8006 extraction.
8007 @end table
8008
8009 For example, suppose you have archived whole @file{/usr} hierarchy to
8010 a tar archive named @file{usr.tar}. Among other files, this archive
8011 contains @file{usr/include/stdlib.h}, which you wish to extract to
8012 the current working directory. To do so, you type:
8013
8014 @smallexample
8015 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
8016 @end smallexample
8017
8018 The option @option{--strip=2} instructs @command{tar} to strip the
8019 two leading components (@file{usr/} and @file{include/}) off the file
8020 name.
8021
8022 If you add the @option{--verbose} (@option{-v}) option to the invocation
8023 above, you will note that the verbose listing still contains the
8024 full file name, with the two removed components still in place. This
8025 can be inconvenient, so @command{tar} provides a special option for
8026 altering this behavior:
8027
8028 @anchor{show-transformed-names}
8029 @table @option
8030 @opindex show-transformed-names
8031 @item --show-transformed-names
8032 Display file or member names with all requested transformations
8033 applied.
8034 @end table
8035
8036 @noindent
8037 For example:
8038
8039 @smallexample
8040 @group
8041 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
8042 usr/include/stdlib.h
8043 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
8044 stdlib.h
8045 @end group
8046 @end smallexample
8047
8048 Notice that in both cases the file @file{stdlib.h} is extracted to the
8049 current working directory, @option{--show-transformed-names} affects
8050 only the way its name is displayed.
8051
8052 This option is especially useful for verifying whether the invocation
8053 will have the desired effect. Thus, before running
8054
8055 @smallexample
8056 $ @kbd{tar -x --strip=@var{n}}
8057 @end smallexample
8058
8059 @noindent
8060 it is often advisable to run
8061
8062 @smallexample
8063 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
8064 @end smallexample
8065
8066 @noindent
8067 to make sure the command will produce the intended results.
8068
8069 In case you need to apply more complex modifications to the file name,
8070 @GNUTAR{} provides a general-purpose transformation option:
8071
8072 @table @option
8073 @opindex transform
8074 @opindex xform
8075 @item --transform=@var{expression}
8076 @itemx --xform=@var{expression}
8077 Modify file names using supplied @var{expression}.
8078 @end table
8079
8080 @noindent
8081 The @var{expression} is a @command{sed}-like replace expression of the
8082 form:
8083
8084 @smallexample
8085 s/@var{regexp}/@var{replace}/[@var{flags}]
8086 @end smallexample
8087
8088 @noindent
8089 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
8090 replacement for each file name part that matches @var{regexp}. Both
8091 @var{regexp} and @var{replace} are described in detail in
8092 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
8093
8094 Any delimiter can be used in lieu of @samp{/}, the only requirement being
8095 that it be used consistently throughout the expression. For example,
8096 the following two expressions are equivalent:
8097
8098 @smallexample
8099 @group
8100 s/one/two/
8101 s,one,two,
8102 @end group
8103 @end smallexample
8104
8105 Changing delimiters is often useful when the @var{regex} contains
8106 slashes. For example, it is more convenient to write @code{s,/,-,} than
8107 @code{s/\//-/}.
8108
8109 As in @command{sed}, you can give several replace expressions,
8110 separated by a semicolon.
8111
8112 Supported @var{flags} are:
8113
8114 @table @samp
8115 @item g
8116 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8117 just the first.
8118
8119 @item i
8120 Use case-insensitive matching.
8121
8122 @item x
8123 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8124 regexps, Extended regular expressions, Extended regular expressions,
8125 sed, GNU sed}).
8126
8127 @item @var{number}
8128 Only replace the @var{number}th match of the @var{regexp}.
8129
8130 Note: the @acronym{POSIX} standard does not specify what should happen
8131 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
8132 follows the GNU @command{sed} implementation in this regard, so
8133 the interaction is defined to be: ignore matches before the
8134 @var{number}th, and then match and replace all matches from the
8135 @var{number}th on.
8136
8137 @end table
8138
8139 In addition, several @dfn{transformation scope} flags are supported,
8140 that control to what files transformations apply. These are:
8141
8142 @table @samp
8143 @item r
8144 Apply transformation to regular archive members.
8145
8146 @item R
8147 Do not apply transformation to regular archive members.
8148
8149 @item s
8150 Apply transformation to symbolic link targets.
8151
8152 @item S
8153 Do not apply transformation to symbolic link targets.
8154
8155 @item h
8156 Apply transformation to hard link targets.
8157
8158 @item H
8159 Do not apply transformation to hard link targets.
8160 @end table
8161
8162 Default is @samp{rsh}, which means to apply tranformations to both archive
8163 members and targets of symbolic and hard links.
8164
8165 Default scope flags can also be changed using @samp{flags=} statement
8166 in the transform expression. The flags set this way remain in force
8167 until next @samp{flags=} statement or end of expression, whichever
8168 occurs first. For example:
8169
8170 @smallexample
8171 --transform 'flags=S;s|^|/usr/local/|'
8172 @end smallexample
8173
8174 Here are several examples of @option{--transform} usage:
8175
8176 @enumerate
8177 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8178
8179 @smallexample
8180 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8181 @end smallexample
8182
8183 @item Strip two leading directory components (equivalent to
8184 @option{--strip-components=2}):
8185
8186 @smallexample
8187 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8188 @end smallexample
8189
8190 @item Convert each file name to lower case:
8191
8192 @smallexample
8193 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8194 @end smallexample
8195
8196 @item Prepend @file{/prefix/} to each file name:
8197
8198 @smallexample
8199 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8200 @end smallexample
8201
8202 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8203 to each archive member:
8204
8205 @smallexample
8206 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8207 @end smallexample
8208 @end enumerate
8209
8210 Notice the use of flags in the last example. The @file{/lib}
8211 directory often contains many symbolic links to files within it.
8212 It may look, for example, like this:
8213
8214 @smallexample
8215 $ @kbd{ls -l}
8216 drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
8217 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8218 lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8219 ...
8220 @end smallexample
8221
8222 Using the expression @samp{s,^,/usr/local/,} would mean adding
8223 @samp{/usr/local} to both regular archive members and to link
8224 targets. In this case, @file{/lib/libc.so.6} would become:
8225
8226 @smallexample
8227 /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8228 @end smallexample
8229
8230 This is definitely not desired. To avoid this, the @samp{S} flag
8231 is used, which excludes symbolic link targets from filename
8232 transformations. The result is:
8233
8234 @smallexample
8235 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8236 --show-transformed /lib}
8237 drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
8238 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8239 lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8240 -> libc-2.3.2.so
8241 @end smallexample
8242
8243 Unlike @option{--strip-components}, @option{--transform} can be used
8244 in any @GNUTAR{} operation mode. For example, the following command
8245 adds files to the archive while replacing the leading @file{usr/}
8246 component with @file{var/}:
8247
8248 @smallexample
8249 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8250 @end smallexample
8251
8252 To test @option{--transform} effect we suggest using
8253 @option{--show-transformed-names} option:
8254
8255 @smallexample
8256 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8257 --verbose --show-transformed-names /}
8258 @end smallexample
8259
8260 If both @option{--strip-components} and @option{--transform} are used
8261 together, then @option{--transform} is applied first, and the required
8262 number of components is then stripped from its result.
8263
8264 You can use as many @option{--transform} options in a single command
8265 line as you want. The specified expressions will then be applied in
8266 order of their appearance. For example, the following two invocations
8267 are equivalent:
8268
8269 @smallexample
8270 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8271 --transform='s,/usr/local,/usr/,'}
8272 $ @kbd{tar -cf arch.tar \
8273 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8274 @end smallexample
8275
8276 @node after
8277 @section Operating Only on New Files
8278
8279 @cindex Excluding file by age
8280 @cindex Data Modification time, excluding files by
8281 @cindex Modification time, excluding files by
8282 @cindex Age, excluding files by
8283 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
8284 @option{-N @var{date}}) option causes @command{tar} to only work on
8285 files whose data modification or status change times are newer than
8286 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
8287 it is taken to be a file name; the data modification time of that file
8288 is used as the date. If you use this option when creating or appending
8289 to an archive, the archive will only include new files. If you use
8290 @option{--after-date} when extracting an archive, @command{tar} will
8291 only extract files newer than the @var{date} you specify.
8292
8293 If you only want @command{tar} to make the date comparison based on
8294 modification of the file's data (rather than status
8295 changes), then use the @option{--newer-mtime=@var{date}} option.
8296
8297 @cindex --after-date and --update compared
8298 @cindex --newer-mtime and --update compared
8299 You may use these options with any operation. Note that these options
8300 differ from the @option{--update} (@option{-u}) operation in that they
8301 allow you to specify a particular date against which @command{tar} can
8302 compare when deciding whether or not to archive the files.
8303
8304 @table @option
8305 @opindex after-date
8306 @opindex newer
8307 @item --after-date=@var{date}
8308 @itemx --newer=@var{date}
8309 @itemx -N @var{date}
8310 Only store files newer than @var{date}.
8311
8312 Acts on files only if their data modification or status change times are
8313 later than @var{date}. Use in conjunction with any operation.
8314
8315 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
8316 name; the data modification time of that file is used as the date.
8317
8318 @opindex newer-mtime
8319 @item --newer-mtime=@var{date}
8320 Acts like @option{--after-date}, but only looks at data modification times.
8321 @end table
8322
8323 These options limit @command{tar} to operate only on files which have
8324 been modified after the date specified. A file's status is considered to have
8325 changed if its contents have been modified, or if its owner,
8326 permissions, and so forth, have been changed. (For more information on
8327 how to specify a date, see @ref{Date input formats}; remember that the
8328 entire date argument must be quoted if it contains any spaces.)
8329
8330 Gurus would say that @option{--after-date} tests both the data
8331 modification time (@code{mtime}, the time the contents of the file
8332 were last modified) and the status change time (@code{ctime}, the time
8333 the file's status was last changed: owner, permissions, etc.@:)
8334 fields, while @option{--newer-mtime} tests only the @code{mtime}
8335 field.
8336
8337 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
8338 @code{ctime} and processes the file if either one is more recent than
8339 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
8340 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
8341 contents of the file were looked at).
8342
8343 Date specifiers can have embedded spaces. Because of this, you may need
8344 to quote date arguments to keep the shell from parsing them as separate
8345 arguments. For example, the following command will add to the archive
8346 all the files modified less than two days ago:
8347
8348 @smallexample
8349 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
8350 @end smallexample
8351
8352 When any of these options is used with the option @option{--verbose}
8353 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
8354 date back to its textual representation and compare that with the
8355 one given with the option. If the two dates differ, @command{tar} will
8356 print a warning saying what date it will use. This is to help user
8357 ensure he is using the right date. For example:
8358
8359 @smallexample
8360 @group
8361 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
8362 tar: Option --after-date: Treating date '10 days ago' as 2006-06-11
8363 13:19:37.232434
8364 @end group
8365 @end smallexample
8366
8367 @quotation
8368 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
8369 should not be used for incremental backups. @xref{Incremental Dumps},
8370 for proper way of creating incremental backups.
8371 @end quotation
8372
8373 @node recurse
8374 @section Descending into Directories
8375 @cindex Avoiding recursion in directories
8376 @cindex Descending directories, avoiding
8377 @cindex Directories, avoiding recursion
8378 @cindex Recursion in directories, avoiding
8379
8380 Usually, @command{tar} will recursively explore all directories (either
8381 those given on the command line or through the @option{--files-from}
8382 option) for the various files they contain. However, you may not always
8383 want @command{tar} to act this way.
8384
8385 @opindex no-recursion
8386 @cindex @command{find}, using with @command{tar}
8387 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
8388 into specified directories. If you specify @option{--no-recursion}, you can
8389 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
8390 utility for hunting through levels of directories to
8391 construct a list of file names which you could then pass to @command{tar}.
8392 @command{find} allows you to be more selective when choosing which files to
8393 archive; see @ref{files}, for more information on using @command{find} with
8394 @command{tar}.
8395
8396 @table @option
8397 @item --no-recursion
8398 Prevents @command{tar} from recursively descending directories.
8399
8400 @opindex recursion
8401 @item --recursion
8402 Requires @command{tar} to recursively descend directories.
8403 This is the default.
8404 @end table
8405
8406 When you use @option{--no-recursion}, @GNUTAR{} grabs
8407 directory entries themselves, but does not descend on them
8408 recursively. Many people use @command{find} for locating files they
8409 want to back up, and since @command{tar} @emph{usually} recursively
8410 descends on directories, they have to use the @samp{@w{-not -type d}}
8411 test in their @command{find} invocation (@pxref{Type, Type, Type test,
8412 find, Finding Files}), as they usually do not want all the files in a
8413 directory. They then use the @option{--files-from} option to archive
8414 the files located via @command{find}.
8415
8416 The problem when restoring files archived in this manner is that the
8417 directories themselves are not in the archive; so the
8418 @option{--same-permissions} (@option{--preserve-permissions},
8419 @option{-p}) option does not affect them---while users might really
8420 like it to. Specifying @option{--no-recursion} is a way to tell
8421 @command{tar} to grab only the directory entries given to it, adding
8422 no new files on its own. To summarize, if you use @command{find} to
8423 create a list of files to be stored in an archive, use it as follows:
8424
8425 @smallexample
8426 @group
8427 $ @kbd{find @var{dir} @var{tests} | \
8428 tar -cf @var{archive} -T - --no-recursion}
8429 @end group
8430 @end smallexample
8431
8432 The @option{--no-recursion} option also applies when extracting: it
8433 causes @command{tar} to extract only the matched directory entries, not
8434 the files under those directories.
8435
8436 The @option{--no-recursion} option also affects how globbing patterns
8437 are interpreted (@pxref{controlling pattern-matching}).
8438
8439 The @option{--no-recursion} and @option{--recursion} options apply to
8440 later options and operands, and can be overridden by later occurrences
8441 of @option{--no-recursion} and @option{--recursion}. For example:
8442
8443 @smallexample
8444 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
8445 @end smallexample
8446
8447 @noindent
8448 creates an archive with one entry for @file{grape}, and the recursive
8449 contents of @file{grape/concord}, but no entries under @file{grape}
8450 other than @file{grape/concord}.
8451
8452 @node one
8453 @section Crossing File System Boundaries
8454 @cindex File system boundaries, not crossing
8455
8456 @command{tar} will normally automatically cross file system boundaries in
8457 order to archive files which are part of a directory tree. You can
8458 change this behavior by running @command{tar} and specifying
8459 @option{--one-file-system}. This option only affects files that are
8460 archived because they are in a directory that is being archived;
8461 @command{tar} will still archive files explicitly named on the command line
8462 or through @option{--files-from}, regardless of where they reside.
8463
8464 @table @option
8465 @opindex one-file-system
8466 @item --one-file-system
8467 Prevents @command{tar} from crossing file system boundaries when
8468 archiving. Use in conjunction with any write operation.
8469 @end table
8470
8471 The @option{--one-file-system} option causes @command{tar} to modify its
8472 normal behavior in archiving the contents of directories. If a file in
8473 a directory is not on the same file system as the directory itself, then
8474 @command{tar} will not archive that file. If the file is a directory
8475 itself, @command{tar} will not archive anything beneath it; in other words,
8476 @command{tar} will not cross mount points.
8477
8478 This option is useful for making full or incremental archival backups of
8479 a file system. If this option is used in conjunction with
8480 @option{--verbose} (@option{-v}), files that are excluded are
8481 mentioned by name on the standard error.
8482
8483 @menu
8484 * directory:: Changing Directory
8485 * absolute:: Absolute File Names
8486 @end menu
8487
8488 @node directory
8489 @subsection Changing the Working Directory
8490
8491 @FIXME{need to read over this node now for continuity; i've switched
8492 things around some.}
8493
8494 @cindex Changing directory mid-stream
8495 @cindex Directory, changing mid-stream
8496 @cindex Working directory, specifying
8497 To change the working directory in the middle of a list of file names,
8498 either on the command line or in a file specified using
8499 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
8500 This will change the working directory to the specified directory
8501 after that point in the list.
8502
8503 @table @option
8504 @opindex directory
8505 @item --directory=@var{directory}
8506 @itemx -C @var{directory}
8507 Changes the working directory in the middle of a command line.
8508 @end table
8509
8510 For example,
8511
8512 @smallexample
8513 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
8514 @end smallexample
8515
8516 @noindent
8517 will place the files @file{grape} and @file{prune} from the current
8518 directory into the archive @file{jams.tar}, followed by the file
8519 @file{cherry} from the directory @file{food}. This option is especially
8520 useful when you have several widely separated files that you want to
8521 store in the same archive.
8522
8523 Note that the file @file{cherry} is recorded in the archive under the
8524 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
8525 archive will contain three files that all appear to have come from the
8526 same directory; if the archive is extracted with plain @samp{tar
8527 --extract}, all three files will be written in the current directory.
8528
8529 Contrast this with the command,
8530
8531 @smallexample
8532 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
8533 @end smallexample
8534
8535 @noindent
8536 which records the third file in the archive under the name
8537 @file{red/cherry} so that, if the archive is extracted using
8538 @samp{tar --extract}, the third file will be written in a subdirectory
8539 named @file{red}.
8540
8541 You can use the @option{--directory} option to make the archive
8542 independent of the original name of the directory holding the files.
8543 The following command places the files @file{/etc/passwd},
8544 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
8545 @file{foo.tar}:
8546
8547 @smallexample
8548 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
8549 @end smallexample
8550
8551 @noindent
8552 However, the names of the archive members will be exactly what they were
8553 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
8554 They will not appear to be related by file name to the original
8555 directories where those files were located.
8556
8557 Note that @option{--directory} options are interpreted consecutively. If
8558 @option{--directory} specifies a relative file name, it is interpreted
8559 relative to the then current directory, which might not be the same as
8560 the original current working directory of @command{tar}, due to a previous
8561 @option{--directory} option.
8562
8563 When using @option{--files-from} (@pxref{files}), you can put various
8564 @command{tar} options (including @option{-C}) in the file list. Notice,
8565 however, that in this case the option and its argument may not be
8566 separated by whitespace. If you use short option, its argument must
8567 either follow the option letter immediately, without any intervening
8568 whitespace, or occupy the next line. Otherwise, if you use long
8569 option, separate its argument by an equal sign.
8570
8571 For instance, the file list for the above example will be:
8572
8573 @smallexample
8574 @group
8575 -C/etc
8576 passwd
8577 hosts
8578 --directory=/lib
8579 libc.a
8580 @end group
8581 @end smallexample
8582
8583 @noindent
8584 To use it, you would invoke @command{tar} as follows:
8585
8586 @smallexample
8587 $ @kbd{tar -c -f foo.tar --files-from list}
8588 @end smallexample
8589
8590 The interpretation of @option{--directory} is disabled by
8591 @option{--null} option.
8592
8593 @node absolute
8594 @subsection Absolute File Names
8595 @cindex absolute file names
8596 @cindex file names, absolute
8597
8598 By default, @GNUTAR{} drops a leading @samp{/} on
8599 input or output, and complains about file names containing a @file{..}
8600 component. There is an option that turns off this behavior:
8601
8602 @table @option
8603 @opindex absolute-names
8604 @item --absolute-names
8605 @itemx -P
8606 Do not strip leading slashes from file names, and permit file names
8607 containing a @file{..} file name component.
8608 @end table
8609
8610 When @command{tar} extracts archive members from an archive, it strips any
8611 leading slashes (@samp{/}) from the member name. This causes absolute
8612 member names in the archive to be treated as relative file names. This
8613 allows you to have such members extracted wherever you want, instead of
8614 being restricted to extracting the member in the exact directory named
8615 in the archive. For example, if the archive member has the name
8616 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8617 really @file{etc/passwd}.
8618
8619 File names containing @file{..} can cause problems when extracting, so
8620 @command{tar} normally warns you about such files when creating an
8621 archive, and rejects attempts to extracts such files.
8622
8623 Other @command{tar} programs do not do this. As a result, if you
8624 create an archive whose member names start with a slash, they will be
8625 difficult for other people with a non-@GNUTAR{}
8626 program to use. Therefore, @GNUTAR{} also strips
8627 leading slashes from member names when putting members into the
8628 archive. For example, if you ask @command{tar} to add the file
8629 @file{/bin/ls} to an archive, it will do so, but the member name will
8630 be @file{bin/ls}@footnote{A side effect of this is that when
8631 @option{--create} is used with @option{--verbose} the resulting output
8632 is not, generally speaking, the same as the one you'd get running
8633 @kbd{tar --list} command. This may be important if you use some
8634 scripts for comparing both outputs. @xref{listing member and file names},
8635 for the information on how to handle this case.}.
8636
8637 Symbolic links containing @file{..} or leading @samp{/} can also cause
8638 problems when extracting, so @command{tar} normally extracts them last;
8639 it may create empty files as placeholders during extraction.
8640
8641 If you use the @option{--absolute-names} (@option{-P}) option,
8642 @command{tar} will do none of these transformations.
8643
8644 To archive or extract files relative to the root directory, specify
8645 the @option{--absolute-names} (@option{-P}) option.
8646
8647 Normally, @command{tar} acts on files relative to the working
8648 directory---ignoring superior directory names when archiving, and
8649 ignoring leading slashes when extracting.
8650
8651 When you specify @option{--absolute-names} (@option{-P}),
8652 @command{tar} stores file names including all superior directory
8653 names, and preserves leading slashes. If you only invoked
8654 @command{tar} from the root directory you would never need the
8655 @option{--absolute-names} option, but using this option
8656 may be more convenient than switching to root.
8657
8658 @FIXME{Should be an example in the tutorial/wizardry section using this
8659 to transfer files between systems.}
8660
8661 @table @option
8662 @item --absolute-names
8663 Preserves full file names (including superior directory names) when
8664 archiving and extracting files.
8665
8666 @end table
8667
8668 @command{tar} prints out a message about removing the @samp{/} from
8669 file names. This message appears once per @GNUTAR{}
8670 invocation. It represents something which ought to be told; ignoring
8671 what it means can cause very serious surprises, later.
8672
8673 Some people, nevertheless, do not want to see this message. Wanting to
8674 play really dangerously, one may of course redirect @command{tar} standard
8675 error to the sink. For example, under @command{sh}:
8676
8677 @smallexample
8678 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8679 @end smallexample
8680
8681 @noindent
8682 Another solution, both nicer and simpler, would be to change to
8683 the @file{/} directory first, and then avoid absolute notation.
8684 For example:
8685
8686 @smallexample
8687 $ @kbd{tar -c -f archive.tar -C / home}
8688 @end smallexample
8689
8690 @xref{Integrity}, for some of the security-related implications
8691 of using this option.
8692
8693 @include parse-datetime.texi
8694
8695 @node Formats
8696 @chapter Controlling the Archive Format
8697
8698 @cindex Tar archive formats
8699 Due to historical reasons, there are several formats of tar archives.
8700 All of them are based on the same principles, but have some subtle
8701 differences that often make them incompatible with each other.
8702
8703 GNU tar is able to create and handle archives in a variety of formats.
8704 The most frequently used formats are (in alphabetical order):
8705
8706 @table @asis
8707 @item gnu
8708 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8709 from an early @acronym{POSIX} standard, adding some improvements such as
8710 sparse file handling and incremental archives. Unfortunately these
8711 features were implemented in a way incompatible with other archive
8712 formats.
8713
8714 Archives in @samp{gnu} format are able to hold file names of unlimited
8715 length.
8716
8717 @item oldgnu
8718 Format used by @GNUTAR{} of versions prior to 1.12.
8719
8720 @item v7
8721 Archive format, compatible with the V7 implementation of tar. This
8722 format imposes a number of limitations. The most important of them
8723 are:
8724
8725 @enumerate
8726 @item The maximum length of a file name is limited to 99 characters.
8727 @item The maximum length of a symbolic link is limited to 99 characters.
8728 @item It is impossible to store special files (block and character
8729 devices, fifos etc.)
8730 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8731 octal)
8732 @item V7 archives do not contain symbolic ownership information (user
8733 and group name of the file owner).
8734 @end enumerate
8735
8736 This format has traditionally been used by Automake when producing
8737 Makefiles. This practice will change in the future, in the meantime,
8738 however this means that projects containing file names more than 99
8739 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8740 Automake prior to 1.9.
8741
8742 @item ustar
8743 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8744 symbolic ownership information. It is also able to store
8745 special files. However, it imposes several restrictions as well:
8746
8747 @enumerate
8748 @item The maximum length of a file name is limited to 256 characters,
8749 provided that the file name can be split at a directory separator in
8750 two parts, first of them being at most 155 bytes long. So, in most
8751 cases the maximum file name length will be shorter than 256
8752 characters.
8753 @item The maximum length of a symbolic link name is limited to
8754 100 characters.
8755 @item Maximum size of a file the archive is able to accommodate
8756 is 8GB
8757 @item Maximum value of UID/GID is 2097151.
8758 @item Maximum number of bits in device major and minor numbers is 21.
8759 @end enumerate
8760
8761 @item star
8762 Format used by J@"org Schilling @command{star}
8763 implementation. @GNUTAR{} is able to read @samp{star} archives but
8764 currently does not produce them.
8765
8766 @item posix
8767 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8768 most flexible and feature-rich format. It does not impose any
8769 restrictions on file sizes or file name lengths. This format is quite
8770 recent, so not all tar implementations are able to handle it properly.
8771 However, this format is designed in such a way that any tar
8772 implementation able to read @samp{ustar} archives will be able to read
8773 most @samp{posix} archives as well, with the only exception that any
8774 additional information (such as long file names etc.) will in such
8775 case be extracted as plain text files along with the files it refers to.
8776
8777 This archive format will be the default format for future versions
8778 of @GNUTAR{}.
8779
8780 @end table
8781
8782 The following table summarizes the limitations of each of these
8783 formats:
8784
8785 @multitable @columnfractions .10 .20 .20 .20 .20
8786 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8787 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8788 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8789 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8790 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8791 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8792 @end multitable
8793
8794 The default format for @GNUTAR{} is defined at compilation
8795 time. You may check it by running @command{tar --help}, and examining
8796 the last lines of its output. Usually, @GNUTAR{} is configured
8797 to create archives in @samp{gnu} format, however, future version will
8798 switch to @samp{posix}.
8799
8800 @menu
8801 * Compression:: Using Less Space through Compression
8802 * Attributes:: Handling File Attributes
8803 * Portability:: Making @command{tar} Archives More Portable
8804 * cpio:: Comparison of @command{tar} and @command{cpio}
8805 @end menu
8806
8807 @node Compression
8808 @section Using Less Space through Compression
8809
8810 @menu
8811 * gzip:: Creating and Reading Compressed Archives
8812 * sparse:: Archiving Sparse Files
8813 @end menu
8814
8815 @node gzip
8816 @subsection Creating and Reading Compressed Archives
8817 @cindex Compressed archives
8818 @cindex Storing archives in compressed format
8819
8820 @cindex gzip
8821 @cindex bzip2
8822 @cindex lzip
8823 @cindex lzma
8824 @cindex lzop
8825 @cindex compress
8826 @GNUTAR{} is able to create and read compressed archives. It supports
8827 a wide variety of compression programs, namely: @command{gzip},
8828 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
8829 @command{xz} and traditional @command{compress}. The latter is
8830 supported mostly for backward compatibility, and we recommend
8831 against using it, because it is by far less effective than the other
8832 compression programs@footnote{It also had patent problems in the past.}.
8833
8834 Creating a compressed archive is simple: you just specify a
8835 @dfn{compression option} along with the usual archive creation
8836 commands. The compression option is @option{-z} (@option{--gzip}) to
8837 create a @command{gzip} compressed archive, @option{-j}
8838 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8839 @option{--lzip} to create an @asis{lzip} compressed archive,
8840 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
8841 @option{--lzma} to create an @asis{LZMA} compressed
8842 archive, @option{--lzop} to create an @asis{LSOP} archive, and
8843 @option{-Z} (@option{--compress}) to use @command{compress} program.
8844 For example:
8845
8846 @smallexample
8847 $ @kbd{tar czf archive.tar.gz .}
8848 @end smallexample
8849
8850 You can also let @GNUTAR{} select the compression program based on
8851 the suffix of the archive file name. This is done using
8852 @option{--auto-compress} (@option{-a}) command line option. For
8853 example, the following invocation will use @command{bzip2} for
8854 compression:
8855
8856 @smallexample
8857 $ @kbd{tar caf archive.tar.bz2 .}
8858 @end smallexample
8859
8860 @noindent
8861 whereas the following one will use @command{lzma}:
8862
8863 @smallexample
8864 $ @kbd{tar caf archive.tar.lzma .}
8865 @end smallexample
8866
8867 For a complete list of file name suffixes recognized by @GNUTAR{},
8868 see @ref{auto-compress}.
8869
8870 Reading compressed archive is even simpler: you don't need to specify
8871 any additional options as @GNUTAR{} recognizes its format
8872 automatically. Thus, the following commands will list and extract the
8873 archive created in previous example:
8874
8875 @smallexample
8876 # List the compressed archive
8877 $ @kbd{tar tf archive.tar.gz}
8878 # Extract the compressed archive
8879 $ @kbd{tar xf archive.tar.gz}
8880 @end smallexample
8881
8882 The format recognition algorithm is based on @dfn{signatures}, a
8883 special byte sequences in the beginning of file, that are specific for
8884 certain compression formats. If this approach fails, @command{tar}
8885 falls back to using archive name suffix to determine its format
8886 (@pxref{auto-compress}, for a list of recognized suffixes).
8887
8888 @anchor{alternative decompression programs}
8889 @cindex alternative decompression programs
8890 Some compression programs are able to handle different compression
8891 formats. @GNUTAR{} uses this, if the principal decompressor for the
8892 given format is not available. For example, if @command{compress} is
8893 not installed, @command{tar} will try to use @command{gzip}. As of
8894 version @value{VERSION} the following alternatives are
8895 tried@footnote{To verbosely trace the decompressor selection, use the
8896 @option{--warning=decompress-program} option
8897 (@pxref{warnings,decompress-program}).}:
8898
8899 @multitable @columnfractions 0.3 0.3 0.3
8900 @headitem Format @tab Main decompressor @tab Alternatives
8901 @item compress @tab compress @tab gzip
8902 @item lzma @tab lzma @tab xz
8903 @item bzip2 @tab bzip2 @tab lbzip2
8904 @end multitable
8905
8906 The only case when you have to specify a decompression option while
8907 reading the archive is when reading from a pipe or from a tape drive
8908 that does not support random access. However, in this case @GNUTAR{}
8909 will indicate which option you should use. For example:
8910
8911 @smallexample
8912 $ @kbd{cat archive.tar.gz | tar tf -}
8913 tar: Archive is compressed. Use -z option
8914 tar: Error is not recoverable: exiting now
8915 @end smallexample
8916
8917 If you see such diagnostics, just add the suggested option to the
8918 invocation of @GNUTAR{}:
8919
8920 @smallexample
8921 $ @kbd{cat archive.tar.gz | tar tzf -}
8922 @end smallexample
8923
8924 Notice also, that there are several restrictions on operations on
8925 compressed archives. First of all, compressed archives cannot be
8926 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
8927 them or delete (@option{--delete}) members from them or
8928 add (@option{--append}, alias @option{-r}) members to them. Likewise, you
8929 cannot append another @command{tar} archive to a compressed archive using
8930 @option{--concatenate} (@option{-A}). Secondly, multi-volume
8931 archives cannot be compressed.
8932
8933 The following options allow to select a particular compressor program:
8934
8935 @table @option
8936 @opindex gzip
8937 @opindex ungzip
8938 @item -z
8939 @itemx --gzip
8940 @itemx --ungzip
8941 Filter the archive through @command{gzip}.
8942
8943 @opindex xz
8944 @item -J
8945 @itemx --xz
8946 Filter the archive through @code{xz}.
8947
8948 @item -j
8949 @itemx --bzip2
8950 Filter the archive through @code{bzip2}.
8951
8952 @opindex lzip
8953 @item --lzip
8954 Filter the archive through @command{lzip}.
8955
8956 @opindex lzma
8957 @item --lzma
8958 Filter the archive through @command{lzma}.
8959
8960 @opindex lzop
8961 @item --lzop
8962 Filter the archive through @command{lzop}.
8963
8964 @opindex compress
8965 @opindex uncompress
8966 @item -Z
8967 @itemx --compress
8968 @itemx --uncompress
8969 Filter the archive through @command{compress}.
8970 @end table
8971
8972 When any of these options is given, @GNUTAR{} searches the compressor
8973 binary in the current path and invokes it. The name of the compressor
8974 program is specified at compilation time using a corresponding
8975 @option{--with-@var{compname}} option to @command{configure}, e.g.
8976 @option{--with-bzip2} to select a specific @command{bzip2} binary.
8977 @xref{lbzip2}, for a detailed discussion.
8978
8979 The output produced by @command{tar --help} shows the actual
8980 compressor names along with each of these options.
8981
8982 You can use any of these options on physical devices (tape drives,
8983 etc.) and remote files as well as on normal files; data to or from
8984 such devices or remote files is reblocked by another copy of the
8985 @command{tar} program to enforce the specified (or default) record
8986 size. The default compression parameters are used. Most compression
8987 programs let you override these by setting a program-specific
8988 environment variable. For example, with @command{gzip} you can set
8989 @env{GZIP}:
8990
8991 @smallexample
8992 $ @kbd{GZIP='-9 -n' tar czf archive.tar.gz subdir}
8993 @end smallexample
8994 Another way would be to use the @option{-I} option instead (see
8995 below), e.g.:
8996
8997 @smallexample
8998 $ @kbd{tar -cf archive.tar.gz -I 'gzip -9 -n' subdir}
8999 @end smallexample
9000
9001 @noindent
9002 Finally, the third, traditional, way to do this is to use a pipe:
9003
9004 @smallexample
9005 $ @kbd{tar cf - subdir | gzip -9 -n > archive.tar.gz}
9006 @end smallexample
9007
9008 @cindex corrupted archives
9009 Compressed archives are easily corrupted, because compressed files
9010 have little redundancy. The adaptive nature of the
9011 compression scheme means that the compression tables are implicitly
9012 spread all over the archive. If you lose a few blocks, the dynamic
9013 construction of the compression tables becomes unsynchronized, and there
9014 is little chance that you could recover later in the archive.
9015
9016 Other compression options provide better control over creating
9017 compressed archives. These are:
9018
9019 @table @option
9020 @anchor{auto-compress}
9021 @opindex auto-compress
9022 @item --auto-compress
9023 @itemx -a
9024 Select a compression program to use by the archive file name
9025 suffix. The following suffixes are recognized:
9026
9027 @multitable @columnfractions 0.3 0.6
9028 @headitem Suffix @tab Compression program
9029 @item @samp{.gz} @tab @command{gzip}
9030 @item @samp{.tgz} @tab @command{gzip}
9031 @item @samp{.taz} @tab @command{gzip}
9032 @item @samp{.Z} @tab @command{compress}
9033 @item @samp{.taZ} @tab @command{compress}
9034 @item @samp{.bz2} @tab @command{bzip2}
9035 @item @samp{.tz2} @tab @command{bzip2}
9036 @item @samp{.tbz2} @tab @command{bzip2}
9037 @item @samp{.tbz} @tab @command{bzip2}
9038 @item @samp{.lz} @tab @command{lzip}
9039 @item @samp{.lzma} @tab @command{lzma}
9040 @item @samp{.tlz} @tab @command{lzma}
9041 @item @samp{.lzo} @tab @command{lzop}
9042 @item @samp{.xz} @tab @command{xz}
9043 @end multitable
9044
9045 @anchor{use-compress-program}
9046 @opindex use-compress-program
9047 @item --use-compress-program=@var{command}
9048 @itemx -I=@var{command}
9049 Use external compression program @var{command}. Use this option if you
9050 are not happy with the compression program associated with the suffix
9051 at compile time or if you have a compression program that @GNUTAR{}
9052 does not support. The @var{command} argument is a valid command
9053 invocation, as you would type it at the command line prompt, with any
9054 additional options as needed. Enclose it in quotes if it contains
9055 white space (see @ref{external, Running External Commands}, for more detail).
9056
9057 The @var{command} should follow two conventions:
9058
9059 First, when invoked without additional options, it should read data
9060 from standard input, compress it and output it on standard output.
9061
9062 Secondly, if invoked with the additional @option{-d} option, it should
9063 do exactly the opposite, i.e., read the compressed data from the
9064 standard input and produce uncompressed data on the standard output.
9065
9066 The latter requirement means that you must not use the @option{-d}
9067 option as a part of the @var{command} itself.
9068 @end table
9069
9070 @cindex gpg, using with tar
9071 @cindex gnupg, using with tar
9072 @cindex Using encrypted archives
9073 The @option{--use-compress-program} option, in particular, lets you
9074 implement your own filters, not necessarily dealing with
9075 compression/decompression. For example, suppose you wish to implement
9076 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
9077 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
9078 Manual}). The following script does that:
9079
9080 @smallexample
9081 @group
9082 #! /bin/sh
9083 case $1 in
9084 -d) gpg --decrypt - | gzip -d -c;;
9085 '') gzip -c | gpg -s;;
9086 *) echo "Unknown option $1">&2; exit 1;;
9087 esac
9088 @end group
9089 @end smallexample
9090
9091 Suppose you name it @file{gpgz} and save it somewhere in your
9092 @env{PATH}. Then the following command will create a compressed
9093 archive signed with your private key:
9094
9095 @smallexample
9096 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
9097 @end smallexample
9098
9099 @noindent
9100 Likewise, the command below will list its contents:
9101
9102 @smallexample
9103 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
9104 @end smallexample
9105
9106 @ignore
9107 The above is based on the following discussion:
9108
9109 I have one question, or maybe it's a suggestion if there isn't a way
9110 to do it now. I would like to use @option{--gzip}, but I'd also like
9111 the output to be fed through a program like @acronym{GNU}
9112 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
9113 to use :-)), basically adding ECC protection on top of compression.
9114 It seems as if this should be quite easy to do, but I can't work out
9115 exactly how to go about it. Of course, I can pipe the standard output
9116 of @command{tar} through @command{ecc}, but then I lose (though I
9117 haven't started using it yet, I confess) the ability to have
9118 @command{tar} use @command{rmt} for it's I/O (I think).
9119
9120 I think the most straightforward thing would be to let me specify a
9121 general set of filters outboard of compression (preferably ordered,
9122 so the order can be automatically reversed on input operations, and
9123 with the options they require specifiable), but beggars shouldn't be
9124 choosers and anything you decide on would be fine with me.
9125
9126 By the way, I like @command{ecc} but if (as the comments say) it can't
9127 deal with loss of block sync, I'm tempted to throw some time at adding
9128 that capability. Supposing I were to actually do such a thing and
9129 get it (apparently) working, do you accept contributed changes to
9130 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9131
9132 Isn't that exactly the role of the
9133 @option{--use-compress-prog=@var{program}} option?
9134 I never tried it myself, but I suspect you may want to write a
9135 @var{prog} script or program able to filter stdin to stdout to
9136 way you want. It should recognize the @option{-d} option, for when
9137 extraction is needed rather than creation.
9138
9139 It has been reported that if one writes compressed data (through the
9140 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9141 the DLT compression mode, the data will actually get bigger and one will
9142 end up with less space on the tape.
9143 @end ignore
9144
9145 @menu
9146 * lbzip2:: Using lbzip2 with @GNUTAR{}.
9147 @end menu
9148
9149 @node lbzip2
9150 @subsubsection Using lbzip2 with @GNUTAR{}.
9151 @cindex lbzip2
9152 @cindex Laszlo Ersek
9153 @command{Lbzip2} is a multithreaded utility for handling
9154 @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
9155 multiple processors to speed up its operation and in general works
9156 considerably faster than @command{bzip2}. For a detailed description
9157 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9158 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9159 lbzip2: parallel bzip2 utility}.
9160
9161 Recent versions of @command{lbzip2} are mostly command line compatible
9162 with @command{bzip2}, which makes it possible to automatically invoke
9163 it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
9164 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9165 line option, like this:
9166
9167 @smallexample
9168 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9169 @end smallexample
9170
9171 Once configured and compiled this way, @command{tar --help} will show the
9172 following:
9173
9174 @smallexample
9175 @group
9176 $ @kbd{tar --help | grep -- --bzip2}
9177 -j, --bzip2 filter the archive through lbzip2
9178 @end group
9179 @end smallexample
9180
9181 @noindent
9182 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9183
9184 @node sparse
9185 @subsection Archiving Sparse Files
9186 @cindex Sparse Files
9187
9188 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
9189 in a file is a section of the file's contents which was never written.
9190 The contents of a hole reads as all zeros. On many operating systems,
9191 actual disk storage is not allocated for holes, but they are counted
9192 in the length of the file. If you archive such a file, @command{tar}
9193 could create an archive longer than the original. To have @command{tar}
9194 attempt to recognize the holes in a file, use @option{--sparse}
9195 (@option{-S}). When you use this option, then, for any file using
9196 less disk space than would be expected from its length, @command{tar}
9197 searches the file for consecutive stretches of zeros. It then records
9198 in the archive for the file where the consecutive stretches of zeros
9199 are, and only archives the ``real contents'' of the file. On
9200 extraction (using @option{--sparse} is not needed on extraction) any
9201 such files have holes created wherever the continuous stretches of zeros
9202 were found. Thus, if you use @option{--sparse}, @command{tar} archives
9203 won't take more space than the original.
9204
9205 @table @option
9206 @opindex sparse
9207 @item -S
9208 @itemx --sparse
9209 This option instructs @command{tar} to test each file for sparseness
9210 before attempting to archive it. If the file is found to be sparse it
9211 is treated specially, thus allowing to decrease the amount of space
9212 used by its image in the archive.
9213
9214 This option is meaningful only when creating or updating archives. It
9215 has no effect on extraction.
9216 @end table
9217
9218 Consider using @option{--sparse} when performing file system backups,
9219 to avoid archiving the expanded forms of files stored sparsely in the
9220 system.
9221
9222 Even if your system has no sparse files currently, some may be
9223 created in the future. If you use @option{--sparse} while making file
9224 system backups as a matter of course, you can be assured the archive
9225 will never take more space on the media than the files take on disk
9226 (otherwise, archiving a disk filled with sparse files might take
9227 hundreds of tapes). @xref{Incremental Dumps}.
9228
9229 However, be aware that @option{--sparse} option presents a serious
9230 drawback. Namely, in order to determine if the file is sparse
9231 @command{tar} has to read it before trying to archive it, so in total
9232 the file is read @strong{twice}. So, always bear in mind that the
9233 time needed to process all files with this option is roughly twice
9234 the time needed to archive them without it.
9235 @FIXME{A technical note:
9236
9237 Programs like @command{dump} do not have to read the entire file; by
9238 examining the file system directly, they can determine in advance
9239 exactly where the holes are and thus avoid reading through them. The
9240 only data it need read are the actual allocated data blocks.
9241 @GNUTAR{} uses a more portable and straightforward
9242 archiving approach, it would be fairly difficult that it does
9243 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
9244 1990-12-10:
9245
9246 @quotation
9247 What I did say is that you cannot tell the difference between a hole and an
9248 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
9249 best tells you how many holes there are; it doesn't tell you @emph{where}.
9250 Just as programs may, conceivably, care what @code{st_blocks} is (care
9251 to name one that does?), they may also care where the holes are (I have
9252 no examples of this one either, but it's equally imaginable).
9253
9254 I conclude from this that good archivers are not portable. One can
9255 arguably conclude that if you want a portable program, you can in good
9256 conscience restore files with as many holes as possible, since you can't
9257 get it right.
9258 @end quotation
9259 }
9260
9261 @cindex sparse formats, defined
9262 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9263 sparse files using in three distinct ways, called @dfn{sparse
9264 formats}. A sparse format is identified by its @dfn{number},
9265 consisting, as usual of two decimal numbers, delimited by a dot. By
9266 default, format @samp{1.0} is used. If, for some reason, you wish to
9267 use an earlier format, you can select it using
9268 @option{--sparse-version} option.
9269
9270 @table @option
9271 @opindex sparse-version
9272 @item --sparse-version=@var{version}
9273
9274 Select the format to store sparse files in. Valid @var{version} values
9275 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
9276 for a detailed description of each format.
9277 @end table
9278
9279 Using @option{--sparse-format} option implies @option{--sparse}.
9280
9281 @node Attributes
9282 @section Handling File Attributes
9283 @cindex atrributes, files
9284 @cindex file attributes
9285
9286 When @command{tar} reads files, it updates their access times. To
9287 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
9288 reset the access time retroactively or avoid changing it in the first
9289 place.
9290
9291 @table @option
9292 @opindex atime-preserve
9293 @item --atime-preserve
9294 @itemx --atime-preserve=replace
9295 @itemx --atime-preserve=system
9296 Preserve the access times of files that are read. This works only for
9297 files that you own, unless you have superuser privileges.
9298
9299 @option{--atime-preserve=replace} works on most systems, but it also
9300 restores the data modification time and updates the status change
9301 time. Hence it doesn't interact with incremental dumps nicely
9302 (@pxref{Incremental Dumps}), and it can set access or data modification times
9303 incorrectly if other programs access the file while @command{tar} is
9304 running.
9305
9306 @option{--atime-preserve=system} avoids changing the access time in
9307 the first place, if the operating system supports this.
9308 Unfortunately, this may or may not work on any given operating system
9309 or file system. If @command{tar} knows for sure it won't work, it
9310 complains right away.
9311
9312 Currently @option{--atime-preserve} with no operand defaults to
9313 @option{--atime-preserve=replace}, but this is intended to change to
9314 @option{--atime-preserve=system} when the latter is better-supported.
9315
9316 @opindex touch
9317 @item -m
9318 @itemx --touch
9319 Do not extract data modification time.
9320
9321 When this option is used, @command{tar} leaves the data modification times
9322 of the files it extracts as the times when the files were extracted,
9323 instead of setting it to the times recorded in the archive.
9324
9325 This option is meaningless with @option{--list} (@option{-t}).
9326
9327 @opindex same-owner
9328 @item --same-owner
9329 Create extracted files with the same ownership they have in the
9330 archive.
9331
9332 This is the default behavior for the superuser,
9333 so this option is meaningful only for non-root users, when @command{tar}
9334 is executed on those systems able to give files away. This is
9335 considered as a security flaw by many people, at least because it
9336 makes quite difficult to correctly account users for the disk space
9337 they occupy. Also, the @code{suid} or @code{sgid} attributes of
9338 files are easily and silently lost when files are given away.
9339
9340 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
9341 separately. If it can't find a user name (because the user @acronym{ID} is not
9342 in @file{/etc/passwd}), then it does not write one. When restoring,
9343 it tries to look the name (if one was written) up in
9344 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
9345 the archive instead.
9346
9347 @opindex no-same-owner
9348 @item --no-same-owner
9349 @itemx -o
9350 Do not attempt to restore ownership when extracting. This is the
9351 default behavior for ordinary users, so this option has an effect
9352 only for the superuser.
9353
9354 @opindex numeric-owner
9355 @item --numeric-owner
9356 The @option{--numeric-owner} option allows (ANSI) archives to be written
9357 without user/group name information or such information to be ignored
9358 when extracting. It effectively disables the generation and/or use
9359 of user/group name information. This option forces extraction using
9360 the numeric ids from the archive, ignoring the names.
9361
9362 This is useful in certain circumstances, when restoring a backup from
9363 an emergency floppy with different passwd/group files for example.
9364 It is otherwise impossible to extract files with the right ownerships
9365 if the password file in use during the extraction does not match the
9366 one belonging to the file system(s) being extracted. This occurs,
9367 for example, if you are restoring your files after a major crash and
9368 had booted from an emergency floppy with no password file or put your
9369 disk into another machine to do the restore.
9370
9371 The numeric ids are @emph{always} saved into @command{tar} archives.
9372 The identifying names are added at create time when provided by the
9373 system, unless @option{--format=oldgnu} is used. Numeric ids could be
9374 used when moving archives between a collection of machines using
9375 a centralized management for attribution of numeric ids to users
9376 and groups. This is often made through using the NIS capabilities.
9377
9378 When making a @command{tar} file for distribution to other sites, it
9379 is sometimes cleaner to use a single owner for all files in the
9380 distribution, and nicer to specify the write permission bits of the
9381 files as stored in the archive independently of their actual value on
9382 the file system. The way to prepare a clean distribution is usually
9383 to have some Makefile rule creating a directory, copying all needed
9384 files in that directory, then setting ownership and permissions as
9385 wanted (there are a lot of possible schemes), and only then making a
9386 @command{tar} archive out of this directory, before cleaning
9387 everything out. Of course, we could add a lot of options to
9388 @GNUTAR{} for fine tuning permissions and ownership.
9389 This is not the good way, I think. @GNUTAR{} is
9390 already crowded with options and moreover, the approach just explained
9391 gives you a great deal of control already.
9392
9393 @xopindex{same-permissions, short description}
9394 @xopindex{preserve-permissions, short description}
9395 @item -p
9396 @itemx --same-permissions
9397 @itemx --preserve-permissions
9398 Extract all protection information.
9399
9400 This option causes @command{tar} to set the modes (access permissions) of
9401 extracted files exactly as recorded in the archive. If this option
9402 is not used, the current @code{umask} setting limits the permissions
9403 on extracted files. This option is by default enabled when
9404 @command{tar} is executed by a superuser.
9405
9406
9407 This option is meaningless with @option{--list} (@option{-t}).
9408
9409 @opindex preserve
9410 @item --preserve
9411 Same as both @option{--same-permissions} and @option{--same-order}.
9412
9413 This option is deprecated, and will be removed in @GNUTAR{} version 1.23.
9414
9415 @end table
9416
9417 @node Portability
9418 @section Making @command{tar} Archives More Portable
9419
9420 Creating a @command{tar} archive on a particular system that is meant to be
9421 useful later on many other machines and with other versions of @command{tar}
9422 is more challenging than you might think. @command{tar} archive formats
9423 have been evolving since the first versions of Unix. Many such formats
9424 are around, and are not always compatible with each other. This section
9425 discusses a few problems, and gives some advice about making @command{tar}
9426 archives more portable.
9427
9428 One golden rule is simplicity. For example, limit your @command{tar}
9429 archives to contain only regular files and directories, avoiding
9430 other kind of special files. Do not attempt to save sparse files or
9431 contiguous files as such. Let's discuss a few more problems, in turn.
9432
9433 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
9434 archives and archive labels) in GNU and PAX formats.}
9435
9436 @menu
9437 * Portable Names:: Portable Names
9438 * dereference:: Symbolic Links
9439 * hard links:: Hard Links
9440 * old:: Old V7 Archives
9441 * ustar:: Ustar Archives
9442 * gnu:: GNU and old GNU format archives.
9443 * posix:: @acronym{POSIX} archives
9444 * Checksumming:: Checksumming Problems
9445 * Large or Negative Values:: Large files, negative time stamps, etc.
9446 * Other Tars:: How to Extract GNU-Specific Data Using
9447 Other @command{tar} Implementations
9448 @end menu
9449
9450 @node Portable Names
9451 @subsection Portable Names
9452
9453 Use portable file and member names. A name is portable if it contains
9454 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
9455 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
9456 contain @samp{/-}. Avoid deep directory nesting. For portability to
9457 old Unix hosts, limit your file name components to 14 characters or
9458 less.
9459
9460 If you intend to have your @command{tar} archives to be read under
9461 MSDOS, you should not rely on case distinction for file names, and you
9462 might use the @acronym{GNU} @command{doschk} program for helping you
9463 further diagnosing illegal MSDOS names, which are even more limited
9464 than System V's.
9465
9466 @node dereference
9467 @subsection Symbolic Links
9468 @cindex File names, using symbolic links
9469 @cindex Symbolic link as file name
9470
9471 @opindex dereference
9472 Normally, when @command{tar} archives a symbolic link, it writes a
9473 block to the archive naming the target of the link. In that way, the
9474 @command{tar} archive is a faithful record of the file system contents.
9475 When @option{--dereference} (@option{-h}) is used with
9476 @option{--create} (@option{-c}), @command{tar} archives the files
9477 symbolic links point to, instead of
9478 the links themselves.
9479
9480 When creating portable archives, use @option{--dereference}
9481 (@option{-h}): some systems do not support
9482 symbolic links, and moreover, your distribution might be unusable if
9483 it contains unresolved symbolic links.
9484
9485 When reading from an archive, the @option{--dereference} (@option{-h})
9486 option causes @command{tar} to follow an already-existing symbolic
9487 link when @command{tar} writes or reads a file named in the archive.
9488 Ordinarily, @command{tar} does not follow such a link, though it may
9489 remove the link before writing a new file. @xref{Dealing with Old
9490 Files}.
9491
9492 The @option{--dereference} option is unsafe if an untrusted user can
9493 modify directories while @command{tar} is running. @xref{Security}.
9494
9495 @node hard links
9496 @subsection Hard Links
9497 @cindex File names, using hard links
9498 @cindex hard links, dereferencing
9499 @cindex dereferencing hard links
9500
9501 Normally, when @command{tar} archives a hard link, it writes a
9502 block to the archive naming the target of the link (a @samp{1} type
9503 block). In that way, the actual file contents is stored in file only
9504 once. For example, consider the following two files:
9505
9506 @smallexample
9507 @group
9508 $ ls -l
9509 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
9510 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
9511 @end group
9512 @end smallexample
9513
9514 Here, @file{jeden} is a link to @file{one}. When archiving this
9515 directory with a verbose level 2, you will get an output similar to
9516 the following:
9517
9518 @smallexample
9519 $ tar cvvf ../archive.tar .
9520 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9521 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9522 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
9523 @end smallexample
9524
9525 The last line shows that, instead of storing two copies of the file,
9526 @command{tar} stored it only once, under the name @file{jeden}, and
9527 stored file @file{one} as a hard link to this file.
9528
9529 It may be important to know that all hard links to the given file are
9530 stored in the archive. For example, this may be necessary for exact
9531 reproduction of the file system. The following option does that:
9532
9533 @table @option
9534 @xopindex{check-links, described}
9535 @item --check-links
9536 @itemx -l
9537 Check the number of links dumped for each processed file. If this
9538 number does not match the total number of hard links for the file, print
9539 a warning message.
9540 @end table
9541
9542 For example, trying to archive only file @file{jeden} with this option
9543 produces the following diagnostics:
9544
9545 @smallexample
9546 $ tar -c -f ../archive.tar -l jeden
9547 tar: Missing links to 'jeden'.
9548 @end smallexample
9549
9550 Although creating special records for hard links helps keep a faithful
9551 record of the file system contents and makes archives more compact, it
9552 may present some difficulties when extracting individual members from
9553 the archive. For example, trying to extract file @file{one} from the
9554 archive created in previous examples produces, in the absense of file
9555 @file{jeden}:
9556
9557 @smallexample
9558 $ tar xf archive.tar ./one
9559 tar: ./one: Cannot hard link to './jeden': No such file or directory
9560 tar: Error exit delayed from previous errors
9561 @end smallexample
9562
9563 The reason for this behavior is that @command{tar} cannot seek back in
9564 the archive to the previous member (in this case, @file{one}), to
9565 extract it@footnote{There are plans to fix this in future releases.}.
9566 If you wish to avoid such problems at the cost of a bigger archive,
9567 use the following option:
9568
9569 @table @option
9570 @xopindex{hard-dereference, described}
9571 @item --hard-dereference
9572 Dereference hard links and store the files they refer to.
9573 @end table
9574
9575 For example, trying this option on our two sample files, we get two
9576 copies in the archive, each of which can then be extracted
9577 independently of the other:
9578
9579 @smallexample
9580 @group
9581 $ tar -c -vv -f ../archive.tar --hard-dereference .
9582 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9583 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9584 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
9585 @end group
9586 @end smallexample
9587
9588 @node old
9589 @subsection Old V7 Archives
9590 @cindex Format, old style
9591 @cindex Old style format
9592 @cindex Old style archives
9593 @cindex v7 archive format
9594
9595 Certain old versions of @command{tar} cannot handle additional
9596 information recorded by newer @command{tar} programs. To create an
9597 archive in V7 format (not ANSI), which can be read by these old
9598 versions, specify the @option{--format=v7} option in
9599 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
9600 accepts @option{--portability} or @option{--old-archive} for this
9601 option). When you specify it,
9602 @command{tar} leaves out information about directories, pipes, fifos,
9603 contiguous files, and device files, and specifies file ownership by
9604 group and user IDs instead of group and user names.
9605
9606 When updating an archive, do not use @option{--format=v7}
9607 unless the archive was created using this option.
9608
9609 In most cases, a @emph{new} format archive can be read by an @emph{old}
9610 @command{tar} program without serious trouble, so this option should
9611 seldom be needed. On the other hand, most modern @command{tar}s are
9612 able to read old format archives, so it might be safer for you to
9613 always use @option{--format=v7} for your distributions. Notice,
9614 however, that @samp{ustar} format is a better alternative, as it is
9615 free from many of @samp{v7}'s drawbacks.
9616
9617 @node ustar
9618 @subsection Ustar Archive Format
9619
9620 @cindex ustar archive format
9621 Archive format defined by @acronym{POSIX}.1-1988 specification is called
9622 @code{ustar}. Although it is more flexible than the V7 format, it
9623 still has many restrictions (@pxref{Formats,ustar}, for the detailed
9624 description of @code{ustar} format). Along with V7 format,
9625 @code{ustar} format is a good choice for archives intended to be read
9626 with other implementations of @command{tar}.
9627
9628 To create archive in @code{ustar} format, use @option{--format=ustar}
9629 option in conjunction with the @option{--create} (@option{-c}).
9630
9631 @node gnu
9632 @subsection @acronym{GNU} and old @GNUTAR{} format
9633
9634 @cindex GNU archive format
9635 @cindex Old GNU archive format
9636 @GNUTAR{} was based on an early draft of the
9637 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
9638 @command{tar}, such as the support for file names longer than 100
9639 characters, use portions of the @command{tar} header record which were
9640 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
9641 @acronym{POSIX} have allocated the same parts of the header record for
9642 other purposes. As a result, @GNUTAR{} format is
9643 incompatible with the current @acronym{POSIX} specification, and with
9644 @command{tar} programs that follow it.
9645
9646 In the majority of cases, @command{tar} will be configured to create
9647 this format by default. This will change in future releases, since
9648 we plan to make @samp{POSIX} format the default.
9649
9650 To force creation a @GNUTAR{} archive, use option
9651 @option{--format=gnu}.
9652
9653 @node posix
9654 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
9655
9656 @cindex POSIX archive format
9657 @cindex PAX archive format
9658 Starting from version 1.14 @GNUTAR{} features full support for
9659 @acronym{POSIX.1-2001} archives.
9660
9661 A @acronym{POSIX} conformant archive will be created if @command{tar}
9662 was given @option{--format=posix} (@option{--format=pax}) option. No
9663 special option is required to read and extract from a @acronym{POSIX}
9664 archive.
9665
9666 @menu
9667 * PAX keywords:: Controlling Extended Header Keywords.
9668 @end menu
9669
9670 @node PAX keywords
9671 @subsubsection Controlling Extended Header Keywords
9672
9673 @table @option
9674 @opindex pax-option
9675 @item --pax-option=@var{keyword-list}
9676 Handle keywords in @acronym{PAX} extended headers. This option is
9677 equivalent to @option{-o} option of the @command{pax} utility.
9678 @end table
9679
9680 @var{Keyword-list} is a comma-separated
9681 list of keyword options, each keyword option taking one of
9682 the following forms:
9683
9684 @table @code
9685 @item delete=@var{pattern}
9686 When used with one of archive-creation commands,
9687 this option instructs @command{tar} to omit from extended header records
9688 that it produces any keywords matching the string @var{pattern}.
9689
9690 When used in extract or list mode, this option instructs tar
9691 to ignore any keywords matching the given @var{pattern} in the extended
9692 header records. In both cases, matching is performed using the pattern
9693 matching notation described in @acronym{POSIX 1003.2}, 3.13
9694 (@pxref{wildcards}). For example:
9695
9696 @smallexample
9697 --pax-option delete=security.*
9698 @end smallexample
9699
9700 would suppress security-related information.
9701
9702 @item exthdr.name=@var{string}
9703
9704 This keyword allows user control over the name that is written into the
9705 ustar header blocks for the extended headers. The name is obtained
9706 from @var{string} after making the following substitutions:
9707
9708 @multitable @columnfractions .25 .55
9709 @headitem Meta-character @tab Replaced By
9710 @item %d @tab The directory name of the file, equivalent to the
9711 result of the @command{dirname} utility on the translated file name.
9712 @item %f @tab The name of the file with the directory information
9713 stripped, equivalent to the result of the @command{basename} utility
9714 on the translated file name.
9715 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9716 @item %% @tab A @samp{%} character.
9717 @end multitable
9718
9719 Any other @samp{%} characters in @var{string} produce undefined
9720 results.
9721
9722 If no option @samp{exthdr.name=string} is specified, @command{tar}
9723 will use the following default value:
9724
9725 @smallexample
9726 %d/PaxHeaders.%p/%f
9727 @end smallexample
9728
9729 @item exthdr.mtime=@var{value}
9730
9731 This keyword defines the value of the @samp{mtime} field that
9732 is written into the ustar header blocks for the extended headers.
9733 By default, the @samp{mtime} field is set to the modification time
9734 of the archive member described by that extended headers.
9735
9736 @item globexthdr.name=@var{string}
9737 This keyword allows user control over the name that is written into
9738 the ustar header blocks for global extended header records. The name
9739 is obtained from the contents of @var{string}, after making
9740 the following substitutions:
9741
9742 @multitable @columnfractions .25 .55
9743 @headitem Meta-character @tab Replaced By
9744 @item %n @tab An integer that represents the
9745 sequence number of the global extended header record in the archive,
9746 starting at 1.
9747 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9748 @item %% @tab A @samp{%} character.
9749 @end multitable
9750
9751 Any other @samp{%} characters in @var{string} produce undefined results.
9752
9753 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9754 will use the following default value:
9755
9756 @smallexample
9757 $TMPDIR/GlobalHead.%p.%n
9758 @end smallexample
9759
9760 @noindent
9761 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9762 environment variable. If @var{TMPDIR} is not set, @command{tar}
9763 uses @samp{/tmp}.
9764
9765 @item globexthdr.mtime=@var{value}
9766
9767 This keyword defines the value of the @samp{mtime} field that
9768 is written into the ustar header blocks for the global extended headers.
9769 By default, the @samp{mtime} field is set to the time when
9770 @command{tar} was invoked.
9771
9772 @item @var{keyword}=@var{value}
9773 When used with one of archive-creation commands, these keyword/value pairs
9774 will be included at the beginning of the archive in a global extended
9775 header record. When used with one of archive-reading commands,
9776 @command{tar} will behave as if it has encountered these keyword/value
9777 pairs at the beginning of the archive in a global extended header
9778 record.
9779
9780 @item @var{keyword}:=@var{value}
9781 When used with one of archive-creation commands, these keyword/value pairs
9782 will be included as records at the beginning of an extended header for
9783 each file. This is effectively equivalent to @var{keyword}=@var{value}
9784 form except that it creates no global extended header records.
9785
9786 When used with one of archive-reading commands, @command{tar} will
9787 behave as if these keyword/value pairs were included as records at the
9788 end of each extended header; thus, they will override any global or
9789 file-specific extended header record keywords of the same names.
9790 For example, in the command:
9791
9792 @smallexample
9793 tar --format=posix --create \
9794 --file archive --pax-option gname:=user .
9795 @end smallexample
9796
9797 the group name will be forced to a new value for all files
9798 stored in the archive.
9799 @end table
9800
9801 In any of the forms described above, the @var{value} may be
9802 a string enclosed in curly braces. In that case, the string
9803 between the braces is understood either as a textual time
9804 representation, as described in @ref{Date input formats}, or a name of
9805 the existing file, starting with @samp{/} or @samp{.}. In the latter
9806 case, the modification time of that file is used.
9807
9808 For example, to set all modification times to the current date, you
9809 use the following option:
9810
9811 @smallexample
9812 --pax-option='mtime:=@{now@}'
9813 @end smallexample
9814
9815 Note quoting of the option's argument.
9816
9817 @cindex archives, binary equivalent
9818 @cindex binary equivalent archives, creating
9819 As another example, here is the option that ensures that any two
9820 archives created using it, will be binary equivalent if they have the
9821 same contents:
9822
9823 @smallexample
9824 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
9825 @end smallexample
9826
9827 @node Checksumming
9828 @subsection Checksumming Problems
9829
9830 SunOS and HP-UX @command{tar} fail to accept archives created using
9831 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9832 is, file names having characters with the eight bit set, because they
9833 use signed checksums, while @GNUTAR{} uses unsigned
9834 checksums while creating archives, as per @acronym{POSIX} standards. On
9835 reading, @GNUTAR{} computes both checksums and
9836 accepts any. It is somewhat worrying that a lot of people may go
9837 around doing backup of their files using faulty (or at least
9838 non-standard) software, not learning about it until it's time to
9839 restore their missing files with an incompatible file extractor, or
9840 vice versa.
9841
9842 @GNUTAR{} computes checksums both ways, and accept
9843 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9844 wrong checksums. @GNUTAR{} produces the standard
9845 checksum, however, raising incompatibilities with Sun. That is to
9846 say, @GNUTAR{} has not been modified to
9847 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9848 I've been told that more recent Sun @command{tar} now read standard
9849 archives, so maybe Sun did a similar patch, after all?
9850
9851 The story seems to be that when Sun first imported @command{tar}
9852 sources on their system, they recompiled it without realizing that
9853 the checksums were computed differently, because of a change in
9854 the default signing of @code{char}'s in their compiler. So they
9855 started computing checksums wrongly. When they later realized their
9856 mistake, they merely decided to stay compatible with it, and with
9857 themselves afterwards. Presumably, but I do not really know, HP-UX
9858 has chosen that their @command{tar} archives to be compatible with Sun's.
9859 The current standards do not favor Sun @command{tar} format. In any
9860 case, it now falls on the shoulders of SunOS and HP-UX users to get
9861 a @command{tar} able to read the good archives they receive.
9862
9863 @node Large or Negative Values
9864 @subsection Large or Negative Values
9865 @cindex large values
9866 @cindex future time stamps
9867 @cindex negative time stamps
9868 @UNREVISED
9869
9870 The above sections suggest to use @samp{oldest possible} archive
9871 format if in doubt. However, sometimes it is not possible. If you
9872 attempt to archive a file whose metadata cannot be represented using
9873 required format, @GNUTAR{} will print error message and ignore such a
9874 file. You will than have to switch to a format that is able to
9875 handle such values. The format summary table (@pxref{Formats}) will
9876 help you to do so.
9877
9878 In particular, when trying to archive files larger than 8GB or with
9879 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9880 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9881 @acronym{POSIX} archive formats. When considering which format to
9882 choose, bear in mind that the @acronym{GNU} format uses
9883 two's-complement base-256 notation to store values that do not fit
9884 into standard @acronym{ustar} range. Such archives can generally be
9885 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9886 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9887 example, using two's complement representation for negative time
9888 stamps that assumes a signed 32-bit @code{time_t} generates archives
9889 that are not portable to hosts with differing @code{time_t}
9890 representations.
9891
9892 On the other hand, @acronym{POSIX} archives, generally speaking, can
9893 be extracted by any tar implementation that understands older
9894 @acronym{ustar} format. The only exception are files larger than 8GB.
9895
9896 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9897 POSIX-aware tars.}
9898
9899 @node Other Tars
9900 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9901
9902 In previous sections you became acquainted with various quirks
9903 necessary to make your archives portable. Sometimes you may need to
9904 extract archives containing GNU-specific members using some
9905 third-party @command{tar} implementation or an older version of
9906 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9907 but if it is for some reason impossible, this section will explain
9908 how to cope without it.
9909
9910 When we speak about @dfn{GNU-specific} members we mean two classes of
9911 them: members split between the volumes of a multi-volume archive and
9912 sparse members. You will be able to always recover such members if
9913 the archive is in PAX format. In addition split members can be
9914 recovered from archives in old GNU format. The following subsections
9915 describe the required procedures in detail.
9916
9917 @menu
9918 * Split Recovery:: Members Split Between Volumes
9919 * Sparse Recovery:: Sparse Members
9920 @end menu
9921
9922 @node Split Recovery
9923 @subsubsection Extracting Members Split Between Volumes
9924
9925 @cindex Mutli-volume archives, extracting using non-GNU tars
9926 If a member is split between several volumes of an old GNU format archive
9927 most third party @command{tar} implementation will fail to extract
9928 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9929 This program is available from
9930 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9931 home page}. It concatenates several archive volumes into a single
9932 valid archive. For example, if you have three volumes named from
9933 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9934 extract them using a third-party @command{tar}:
9935
9936 @smallexample
9937 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9938 @end smallexample
9939
9940 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9941 You could use this approach for most (although not all) PAX
9942 format archives as well. However, extracting split members from a PAX
9943 archive is a much easier task, because PAX volumes are constructed in
9944 such a way that each part of a split member is extracted to a
9945 different file by @command{tar} implementations that are not aware of
9946 GNU extensions. More specifically, the very first part retains its
9947 original name, and all subsequent parts are named using the pattern:
9948
9949 @smallexample
9950 %d/GNUFileParts.%p/%f.%n
9951 @end smallexample
9952
9953 @noindent
9954 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9955 have the following meaning:
9956
9957 @multitable @columnfractions .25 .55
9958 @headitem Meta-character @tab Replaced By
9959 @item %d @tab The directory name of the file, equivalent to the
9960 result of the @command{dirname} utility on its full name.
9961 @item %f @tab The file name of the file, equivalent to the result
9962 of the @command{basename} utility on its full name.
9963 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9964 created the archive.
9965 @item %n @tab Ordinal number of this particular part.
9966 @end multitable
9967
9968 For example, if the file @file{var/longfile} was split during archive
9969 creation between three volumes, and the creator @command{tar} process
9970 had process @acronym{ID} @samp{27962}, then the member names will be:
9971
9972 @smallexample
9973 var/longfile
9974 var/GNUFileParts.27962/longfile.1
9975 var/GNUFileParts.27962/longfile.2
9976 @end smallexample
9977
9978 When you extract your archive using a third-party @command{tar}, these
9979 files will be created on your disk, and the only thing you will need
9980 to do to restore your file in its original form is concatenate them in
9981 the proper order, for example:
9982
9983 @smallexample
9984 @group
9985 $ @kbd{cd var}
9986 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9987 GNUFileParts.27962/longfile.2 >> longfile}
9988 $ rm -f GNUFileParts.27962
9989 @end group
9990 @end smallexample
9991
9992 Notice, that if the @command{tar} implementation you use supports PAX
9993 format archives, it will probably emit warnings about unknown keywords
9994 during extraction. They will look like this:
9995
9996 @smallexample
9997 @group
9998 Tar file too small
9999 Unknown extended header keyword 'GNU.volume.filename' ignored.
10000 Unknown extended header keyword 'GNU.volume.size' ignored.
10001 Unknown extended header keyword 'GNU.volume.offset' ignored.
10002 @end group
10003 @end smallexample
10004
10005 @noindent
10006 You can safely ignore these warnings.
10007
10008 If your @command{tar} implementation is not PAX-aware, you will get
10009 more warnings and more files generated on your disk, e.g.:
10010
10011 @smallexample
10012 @group
10013 $ @kbd{tar xf vol-1.tar}
10014 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
10015 normal file
10016 Unexpected EOF in archive
10017 $ @kbd{tar xf vol-2.tar}
10018 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
10019 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
10020 'x', extracted as normal file
10021 @end group
10022 @end smallexample
10023
10024 Ignore these warnings. The @file{PaxHeaders.*} directories created
10025 will contain files with @dfn{extended header keywords} describing the
10026 extracted files. You can delete them, unless they describe sparse
10027 members. Read further to learn more about them.
10028
10029 @node Sparse Recovery
10030 @subsubsection Extracting Sparse Members
10031
10032 @cindex sparse files, extracting with non-GNU tars
10033 Any @command{tar} implementation will be able to extract sparse members from a
10034 PAX archive. However, the extracted files will be @dfn{condensed},
10035 i.e., any zero blocks will be removed from them. When we restore such
10036 a condensed file to its original form, by adding zero blocks (or
10037 @dfn{holes}) back to their original locations, we call this process
10038 @dfn{expanding} a compressed sparse file.
10039
10040 @pindex xsparse
10041 To expand a file, you will need a simple auxiliary program called
10042 @command{xsparse}. It is available in source form from
10043 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
10044 home page}.
10045
10046 @cindex sparse files v.1.0, extracting with non-GNU tars
10047 Let's begin with archive members in @dfn{sparse format
10048 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
10049 The condensed file will contain both file map and file data, so no
10050 additional data will be needed to restore it. If the original file
10051 name was @file{@var{dir}/@var{name}}, then the condensed file will be
10052 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
10053 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
10054 @dfn{process @acronym{ID}} of the @command{tar} process which created the
10055 archive (@pxref{PAX keywords}).}.
10056
10057 To expand a version 1.0 file, run @command{xsparse} as follows:
10058
10059 @smallexample
10060 $ @kbd{xsparse @file{cond-file}}
10061 @end smallexample
10062
10063 @noindent
10064 where @file{cond-file} is the name of the condensed file. The utility
10065 will deduce the name for the resulting expanded file using the
10066 following algorithm:
10067
10068 @enumerate 1
10069 @item If @file{cond-file} does not contain any directories,
10070 @file{../cond-file} will be used;
10071
10072 @item If @file{cond-file} has the form
10073 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
10074 are simple names, with no @samp{/} characters in them, the output file
10075 name will be @file{@var{dir}/@var{name}}.
10076
10077 @item Otherwise, if @file{cond-file} has the form
10078 @file{@var{dir}/@var{name}}, the output file name will be
10079 @file{@var{name}}.
10080 @end enumerate
10081
10082 In the unlikely case when this algorithm does not suit your needs,
10083 you can explicitly specify output file name as a second argument to
10084 the command:
10085
10086 @smallexample
10087 $ @kbd{xsparse @file{cond-file} @file{out-file}}
10088 @end smallexample
10089
10090 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
10091 first. In this mode, the command does not actually expand the file,
10092 but verbosely lists all actions it would be taking to do so. The dry
10093 run mode is enabled by @option{-n} command line argument:
10094
10095 @smallexample
10096 @group
10097 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
10098 Reading v.1.0 sparse map
10099 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10100 '/home/gray/sparsefile'
10101 Finished dry run
10102 @end group
10103 @end smallexample
10104
10105 To actually expand the file, you would run:
10106
10107 @smallexample
10108 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
10109 @end smallexample
10110
10111 @noindent
10112 The program behaves the same way all UNIX utilities do: it will keep
10113 quiet unless it has simething important to tell you (e.g. an error
10114 condition or something). If you wish it to produce verbose output,
10115 similar to that from the dry run mode, use @option{-v} option:
10116
10117 @smallexample
10118 @group
10119 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10120 Reading v.1.0 sparse map
10121 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10122 '/home/gray/sparsefile'
10123 Done
10124 @end group
10125 @end smallexample
10126
10127 Additionally, if your @command{tar} implementation has extracted the
10128 @dfn{extended headers} for this file, you can instruct @command{xstar}
10129 to use them in order to verify the integrity of the expanded file.
10130 The option @option{-x} sets the name of the extended header file to
10131 use. Continuing our example:
10132
10133 @smallexample
10134 @group
10135 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10136 /home/gray/GNUSparseFile.6058/sparsefile}
10137 Reading extended header file
10138 Found variable GNU.sparse.major = 1
10139 Found variable GNU.sparse.minor = 0
10140 Found variable GNU.sparse.name = sparsefile
10141 Found variable GNU.sparse.realsize = 217481216
10142 Reading v.1.0 sparse map
10143 Expanding file '/home/gray/GNUSparseFile.6058/sparsefile' to
10144 '/home/gray/sparsefile'
10145 Done
10146 @end group
10147 @end smallexample
10148
10149 @anchor{extracting sparse v.0.x}
10150 @cindex sparse files v.0.1, extracting with non-GNU tars
10151 @cindex sparse files v.0.0, extracting with non-GNU tars
10152 An @dfn{extended header} is a special @command{tar} archive header
10153 that precedes an archive member and contains a set of
10154 @dfn{variables}, describing the member properties that cannot be
10155 stored in the standard @code{ustar} header. While optional for
10156 expanding sparse version 1.0 members, the use of extended headers is
10157 mandatory when expanding sparse members in older sparse formats: v.0.0
10158 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10159 Formats}.) So, for these formats, the question is: how to obtain
10160 extended headers from the archive?
10161
10162 If you use a @command{tar} implementation that does not support PAX
10163 format, extended headers for each member will be extracted as a
10164 separate file. If we represent the member name as
10165 @file{@var{dir}/@var{name}}, then the extended header file will be
10166 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10167 @var{n} is an integer number.
10168
10169 Things become more difficult if your @command{tar} implementation
10170 does support PAX headers, because in this case you will have to
10171 manually extract the headers. We recommend the following algorithm:
10172
10173 @enumerate 1
10174 @item
10175 Consult the documentation of your @command{tar} implementation for an
10176 option that prints @dfn{block numbers} along with the archive
10177 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
10178 @command{star} has @option{-block-number}.
10179
10180 @item
10181 Obtain verbose listing using the @samp{block number} option, and
10182 find block numbers of the sparse member in question and the member
10183 immediately following it. For example, running @command{star} on our
10184 archive we obtain:
10185
10186 @smallexample
10187 @group
10188 $ @kbd{star -t -v -block-number -f arc.tar}
10189 @dots{}
10190 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10191 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10192 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10193 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10194 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10195 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
10196 @dots{}
10197 @end group
10198 @end smallexample
10199
10200 @noindent
10201 (as usual, ignore the warnings about unknown keywords.)
10202
10203 @item
10204 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10205 and @var{Bn} be the block number of the next member.
10206 Compute:
10207
10208 @smallexample
10209 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10210 @end smallexample
10211
10212 @noindent
10213 This number gives the size of the extended header part in tar @dfn{blocks}.
10214 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10215 = 7}.
10216
10217 @item
10218 Use @command{dd} to extract the headers:
10219
10220 @smallexample
10221 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10222 @end smallexample
10223
10224 @noindent
10225 where @var{archive} is the archive name, @var{hname} is a name of the
10226 file to store the extended header in, @var{Bs} and @var{N} are
10227 computed in previous steps.
10228
10229 In our example, this command will be
10230
10231 @smallexample
10232 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10233 @end smallexample
10234 @end enumerate
10235
10236 Finally, you can expand the condensed file, using the obtained header:
10237
10238 @smallexample
10239 @group
10240 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10241 Reading extended header file
10242 Found variable GNU.sparse.size = 217481216
10243 Found variable GNU.sparse.numblocks = 208
10244 Found variable GNU.sparse.name = sparsefile
10245 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10246 Expanding file 'GNUSparseFile.28124/sparsefile' to 'sparsefile'
10247 Done
10248 @end group
10249 @end smallexample
10250
10251 @node cpio
10252 @section Comparison of @command{tar} and @command{cpio}
10253 @UNREVISED
10254
10255 @FIXME{Reorganize the following material}
10256
10257 The @command{cpio} archive formats, like @command{tar}, do have maximum
10258 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
10259 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
10260 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
10261 with arbitrary file name lengths, but other @command{cpio} implementations
10262 may crash unexplainedly trying to read them.
10263
10264 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
10265 @command{cpio} doesn't handle symbolic links in the form in which it comes
10266 in System V prior to SVR4, and some vendors may have added symlinks
10267 to their system without enhancing @command{cpio} to know about them.
10268 Others may have enhanced it in a way other than the way I did it
10269 at Sun, and which was adopted by AT&T (and which is, I think, also
10270 present in the @command{cpio} that Berkeley picked up from AT&T and put
10271 into a later @acronym{BSD} release---I think I gave them my changes).
10272
10273 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
10274 can handle @command{tar} format input, and write it on output, and it
10275 probably handles symbolic links. They may not have bothered doing
10276 anything to enhance @command{tar} as a result.)
10277
10278 @command{cpio} handles special files; traditional @command{tar} doesn't.
10279
10280 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
10281 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
10282 (4.3-tahoe and later).
10283
10284 @command{tar}'s way of handling multiple hard links to a file can handle
10285 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
10286 @command{cpio}s way requires you to play some games (in its ``binary''
10287 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
10288 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
10289 field of the header to make sure that the file system @acronym{ID}/i-number pairs
10290 of different files were always different), and I don't know which
10291 @command{cpio}s, if any, play those games. Those that don't might get
10292 confused and think two files are the same file when they're not, and
10293 make hard links between them.
10294
10295 @command{tar}s way of handling multiple hard links to a file places only
10296 one copy of the link on the tape, but the name attached to that copy
10297 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
10298 way puts one copy for every link, but you can retrieve it using any
10299 of the names.
10300
10301 @quotation
10302 What type of check sum (if any) is used, and how is this calculated.
10303 @end quotation
10304
10305 See the attached manual pages for @command{tar} and @command{cpio} format.
10306 @command{tar} uses a checksum which is the sum of all the bytes in the
10307 @command{tar} header for a file; @command{cpio} uses no checksum.
10308
10309 @quotation
10310 If anyone knows why @command{cpio} was made when @command{tar} was present
10311 at the unix scene,
10312 @end quotation
10313
10314 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
10315 generally-available version of UNIX had @command{tar} at the time. I don't
10316 know whether any version that was generally available @emph{within AT&T}
10317 had @command{tar}, or, if so, whether the people within AT&T who did
10318 @command{cpio} knew about it.
10319
10320 On restore, if there is a corruption on a tape @command{tar} will stop at
10321 that point, while @command{cpio} will skip over it and try to restore the
10322 rest of the files.
10323
10324 The main difference is just in the command syntax and header format.
10325
10326 @command{tar} is a little more tape-oriented in that everything is blocked
10327 to start on a record boundary.
10328
10329 @quotation
10330 Is there any differences between the ability to recover crashed
10331 archives between the two of them. (Is there any chance of recovering
10332 crashed archives at all.)
10333 @end quotation
10334
10335 Theoretically it should be easier under @command{tar} since the blocking
10336 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
10337 However, modern @command{cpio}'s and variations have an option to just
10338 search for the next file header after an error with a reasonable chance
10339 of resyncing. However, lots of tape driver software won't allow you to
10340 continue past a media error which should be the only reason for getting
10341 out of sync unless a file changed sizes while you were writing the
10342 archive.
10343
10344 @quotation
10345 If anyone knows why @command{cpio} was made when @command{tar} was present
10346 at the unix scene, please tell me about this too.
10347 @end quotation
10348
10349 Probably because it is more media efficient (by not blocking everything
10350 and using only the space needed for the headers where @command{tar}
10351 always uses 512 bytes per file header) and it knows how to archive
10352 special files.
10353
10354 You might want to look at the freely available alternatives. The
10355 major ones are @command{afio}, @GNUTAR{}, and
10356 @command{pax}, each of which have their own extensions with some
10357 backwards compatibility.
10358
10359 Sparse files were @command{tar}red as sparse files (which you can
10360 easily test, because the resulting archive gets smaller, and
10361 @acronym{GNU} @command{cpio} can no longer read it).
10362
10363 @node Media
10364 @chapter Tapes and Other Archive Media
10365 @UNREVISED
10366
10367 A few special cases about tape handling warrant more detailed
10368 description. These special cases are discussed below.
10369
10370 Many complexities surround the use of @command{tar} on tape drives. Since
10371 the creation and manipulation of archives located on magnetic tape was
10372 the original purpose of @command{tar}, it contains many features making
10373 such manipulation easier.
10374
10375 Archives are usually written on dismountable media---tape cartridges,
10376 mag tapes, or floppy disks.
10377
10378 The amount of data a tape or disk holds depends not only on its size,
10379 but also on how it is formatted. A 2400 foot long reel of mag tape
10380 holds 40 megabytes of data when formatted at 1600 bits per inch. The
10381 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
10382
10383 Magnetic media are re-usable---once the archive on a tape is no longer
10384 needed, the archive can be erased and the tape or disk used over.
10385 Media quality does deteriorate with use, however. Most tapes or disks
10386 should be discarded when they begin to produce data errors. EXABYTE
10387 tape cartridges should be discarded when they generate an @dfn{error
10388 count} (number of non-usable bits) of more than 10k.
10389
10390 Magnetic media are written and erased using magnetic fields, and
10391 should be protected from such fields to avoid damage to stored data.
10392 Sticking a floppy disk to a filing cabinet using a magnet is probably
10393 not a good idea.
10394
10395 @menu
10396 * Device:: Device selection and switching
10397 * Remote Tape Server::
10398 * Common Problems and Solutions::
10399 * Blocking:: Blocking
10400 * Many:: Many archives on one tape
10401 * Using Multiple Tapes:: Using Multiple Tapes
10402 * label:: Including a Label in the Archive
10403 * verify::
10404 * Write Protection::
10405 @end menu
10406
10407 @node Device
10408 @section Device Selection and Switching
10409 @UNREVISED
10410
10411 @table @option
10412 @item -f [@var{hostname}:]@var{file}
10413 @itemx --file=[@var{hostname}:]@var{file}
10414 Use archive file or device @var{file} on @var{hostname}.
10415 @end table
10416
10417 This option is used to specify the file name of the archive @command{tar}
10418 works on.
10419
10420 If the file name is @samp{-}, @command{tar} reads the archive from standard
10421 input (when listing or extracting), or writes it to standard output
10422 (when creating). If the @samp{-} file name is given when updating an
10423 archive, @command{tar} will read the original archive from its standard
10424 input, and will write the entire new archive to its standard output.
10425
10426 If the file name contains a @samp{:}, it is interpreted as
10427 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
10428 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
10429 either case, @command{tar} will invoke the command @command{rsh} (or
10430 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
10431 machine. If you give an alternate login name, it will be given to the
10432 @command{rsh}.
10433 Naturally, the remote machine must have an executable
10434 @command{/usr/libexec/rmt}. This program is free software from the
10435 University of California, and a copy of the source code can be found
10436 with the sources for @command{tar}; it's compiled and installed by default.
10437 The exact path to this utility is determined when configuring the package.
10438 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
10439 your installation prefix. This location may also be overridden at
10440 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
10441 ---rmt-command}, for detailed description of this option. @xref{Remote
10442 Tape Server}, for the description of @command{rmt} command).
10443
10444 If this option is not given, but the environment variable @env{TAPE}
10445 is set, its value is used; otherwise, old versions of @command{tar}
10446 used a default archive name (which was picked when @command{tar} was
10447 compiled). The default is normally set up to be the @dfn{first} tape
10448 drive or other transportable I/O medium on the system.
10449
10450 Starting with version 1.11.5, @GNUTAR{} uses
10451 standard input and standard output as the default device, and I will
10452 not try anymore supporting automatic device detection at installation
10453 time. This was failing really in too many cases, it was hopeless.
10454 This is now completely left to the installer to override standard
10455 input and standard output for default device, if this seems
10456 preferable. Further, I think @emph{most} actual usages of
10457 @command{tar} are done with pipes or disks, not really tapes,
10458 cartridges or diskettes.
10459
10460 Some users think that using standard input and output is running
10461 after trouble. This could lead to a nasty surprise on your screen if
10462 you forget to specify an output file name---especially if you are going
10463 through a network or terminal server capable of buffering large amounts
10464 of output. We had so many bug reports in that area of configuring
10465 default tapes automatically, and so many contradicting requests, that
10466 we finally consider the problem to be portably intractable. We could
10467 of course use something like @samp{/dev/tape} as a default, but this
10468 is @emph{also} running after various kind of trouble, going from hung
10469 processes to accidental destruction of real tapes. After having seen
10470 all this mess, using standard input and output as a default really
10471 sounds like the only clean choice left, and a very useful one too.
10472
10473 @GNUTAR{} reads and writes archive in records, I
10474 suspect this is the main reason why block devices are preferred over
10475 character devices. Most probably, block devices are more efficient
10476 too. The installer could also check for @samp{DEFTAPE} in
10477 @file{<sys/mtio.h>}.
10478
10479 @table @option
10480 @xopindex{force-local, short description}
10481 @item --force-local
10482 Archive file is local even if it contains a colon.
10483
10484 @opindex rsh-command
10485 @item --rsh-command=@var{command}
10486 Use remote @var{command} instead of @command{rsh}. This option exists
10487 so that people who use something other than the standard @command{rsh}
10488 (e.g., a Kerberized @command{rsh}) can access a remote device.
10489
10490 When this command is not used, the shell command found when
10491 the @command{tar} program was installed is used instead. This is
10492 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
10493 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
10494 The installer may have overridden this by defining the environment
10495 variable @env{RSH} @emph{at installation time}.
10496
10497 @item -[0-7][lmh]
10498 Specify drive and density.
10499
10500 @xopindex{multi-volume, short description}
10501 @item -M
10502 @itemx --multi-volume
10503 Create/list/extract multi-volume archive.
10504
10505 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
10506 that may be larger than will fit on the medium used to hold it.
10507 @xref{Multi-Volume Archives}.
10508
10509 @xopindex{tape-length, short description}
10510 @item -L @var{num}
10511 @itemx --tape-length=@var{size}[@var{suf}]
10512 Change tape after writing @var{size} units of data. Unless @var{suf} is
10513 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
10514 1024} bytes. The following suffixes alter this behavior:
10515
10516 @float Table, size-suffixes
10517 @caption{Size Suffixes}
10518 @multitable @columnfractions 0.2 0.3 0.3
10519 @headitem Suffix @tab Units @tab Byte Equivalent
10520 @item b @tab Blocks @tab @var{size} x 512
10521 @item B @tab Kilobytes @tab @var{size} x 1024
10522 @item c @tab Bytes @tab @var{size}
10523 @item G @tab Gigabytes @tab @var{size} x 1024^3
10524 @item K @tab Kilobytes @tab @var{size} x 1024
10525 @item k @tab Kilobytes @tab @var{size} x 1024
10526 @item M @tab Megabytes @tab @var{size} x 1024^2
10527 @item P @tab Petabytes @tab @var{size} x 1024^5
10528 @item T @tab Terabytes @tab @var{size} x 1024^4
10529 @item w @tab Words @tab @var{size} x 2
10530 @end multitable
10531 @end float
10532
10533 This option might be useful when your tape drivers do not properly
10534 detect end of physical tapes. By being slightly conservative on the
10535 maximum tape length, you might avoid the problem entirely.
10536
10537 @xopindex{info-script, short description}
10538 @xopindex{new-volume-script, short description}
10539 @item -F @var{command}
10540 @itemx --info-script=@var{command}
10541 @itemx --new-volume-script=@var{command}
10542 Execute @var{command} at end of each tape. This implies
10543 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
10544 description of this option.
10545 @end table
10546
10547 @node Remote Tape Server
10548 @section Remote Tape Server
10549
10550 @cindex remote tape drive
10551 @pindex rmt
10552 In order to access the tape drive on a remote machine, @command{tar}
10553 uses the remote tape server written at the University of California at
10554 Berkeley. The remote tape server must be installed as
10555 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
10556 want to use. @command{tar} calls @command{rmt} by running an
10557 @command{rsh} or @command{remsh} to the remote machine, optionally
10558 using a different login name if one is supplied.
10559
10560 A copy of the source for the remote tape server is provided. Its
10561 source code can be freely distributed. It is compiled and
10562 installed by default.
10563
10564 @cindex absolute file names
10565 Unless you use the @option{--absolute-names} (@option{-P}) option,
10566 @GNUTAR{} will not allow you to create an archive that contains
10567 absolute file names (a file name beginning with @samp{/}.) If you try,
10568 @command{tar} will automatically remove the leading @samp{/} from the
10569 file names it stores in the archive. It will also type a warning
10570 message telling you what it is doing.
10571
10572 When reading an archive that was created with a different
10573 @command{tar} program, @GNUTAR{} automatically
10574 extracts entries in the archive which have absolute file names as if
10575 the file names were not absolute. This is an important feature. A
10576 visitor here once gave a @command{tar} tape to an operator to restore;
10577 the operator used Sun @command{tar} instead of @GNUTAR{},
10578 and the result was that it replaced large portions of
10579 our @file{/bin} and friends with versions from the tape; needless to
10580 say, we were unhappy about having to recover the file system from
10581 backup tapes.
10582
10583 For example, if the archive contained a file @file{/usr/bin/computoy},
10584 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
10585 relative to the current directory. If you want to extract the files in
10586 an archive to the same absolute names that they had when the archive
10587 was created, you should do a @samp{cd /} before extracting the files
10588 from the archive, or you should either use the @option{--absolute-names}
10589 option, or use the command @samp{tar -C / @dots{}}.
10590
10591 @cindex Ultrix 3.1 and write failure
10592 Some versions of Unix (Ultrix 3.1 is known to have this problem),
10593 can claim that a short write near the end of a tape succeeded,
10594 when it actually failed. This will result in the -M option not
10595 working correctly. The best workaround at the moment is to use a
10596 significantly larger blocking factor than the default 20.
10597
10598 In order to update an archive, @command{tar} must be able to backspace the
10599 archive in order to reread or rewrite a record that was just read (or
10600 written). This is currently possible only on two kinds of files: normal
10601 disk files (or any other file that can be backspaced with @samp{lseek}),
10602 and industry-standard 9-track magnetic tape (or any other kind of tape
10603 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
10604
10605 This means that the @option{--append}, @option{--concatenate}, and
10606 @option{--delete} commands will not work on any other kind of file.
10607 Some media simply cannot be backspaced, which means these commands and
10608 options will never be able to work on them. These non-backspacing
10609 media include pipes and cartridge tape drives.
10610
10611 Some other media can be backspaced, and @command{tar} will work on them
10612 once @command{tar} is modified to do so.
10613
10614 Archives created with the @option{--multi-volume}, @option{--label}, and
10615 @option{--incremental} (@option{-G}) options may not be readable by other version
10616 of @command{tar}. In particular, restoring a file that was split over
10617 a volume boundary will require some careful work with @command{dd}, if
10618 it can be done at all. Other versions of @command{tar} may also create
10619 an empty file whose name is that of the volume header. Some versions
10620 of @command{tar} may create normal files instead of directories archived
10621 with the @option{--incremental} (@option{-G}) option.
10622
10623 @node Common Problems and Solutions
10624 @section Some Common Problems and their Solutions
10625
10626 @ifclear PUBLISH
10627
10628 @format
10629 errors from system:
10630 permission denied
10631 no such file or directory
10632 not owner
10633
10634 errors from @command{tar}:
10635 directory checksum error
10636 header format error
10637
10638 errors from media/system:
10639 i/o error
10640 device busy
10641 @end format
10642
10643 @end ifclear
10644
10645 @node Blocking
10646 @section Blocking
10647 @cindex block
10648 @cindex record
10649
10650 @dfn{Block} and @dfn{record} terminology is rather confused, and it
10651 is also confusing to the expert reader. On the other hand, readers
10652 who are new to the field have a fresh mind, and they may safely skip
10653 the next two paragraphs, as the remainder of this manual uses those
10654 two terms in a quite consistent way.
10655
10656 John Gilmore, the writer of the public domain @command{tar} from which
10657 @GNUTAR{} was originally derived, wrote (June 1995):
10658
10659 @quotation
10660 The nomenclature of tape drives comes from IBM, where I believe
10661 they were invented for the IBM 650 or so. On IBM mainframes, what
10662 is recorded on tape are tape blocks. The logical organization of
10663 data is into records. There are various ways of putting records into
10664 blocks, including @code{F} (fixed sized records), @code{V} (variable
10665 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
10666 to a block), @code{VB} (variable size records, @var{n} to a block),
10667 @code{VSB} (variable spanned blocked: variable sized records that can
10668 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
10669 parameter specified this to the operating system.
10670
10671 The Unix man page on @command{tar} was totally confused about this.
10672 When I wrote @code{PD TAR}, I used the historically correct terminology
10673 (@command{tar} writes data records, which are grouped into blocks).
10674 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
10675 here), and now Fran@,{c}ois has migrated that terminology back
10676 into the source code too.
10677 @end quotation
10678
10679 The term @dfn{physical block} means the basic transfer chunk from or
10680 to a device, after which reading or writing may stop without anything
10681 being lost. In this manual, the term @dfn{block} usually refers to
10682 a disk physical block, @emph{assuming} that each disk block is 512
10683 bytes in length. It is true that some disk devices have different
10684 physical blocks, but @command{tar} ignore these differences in its own
10685 format, which is meant to be portable, so a @command{tar} block is always
10686 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
10687 The term @dfn{logical block} often represents the basic chunk of
10688 allocation of many disk blocks as a single entity, which the operating
10689 system treats somewhat atomically; this concept is only barely used
10690 in @GNUTAR{}.
10691
10692 The term @dfn{physical record} is another way to speak of a physical
10693 block, those two terms are somewhat interchangeable. In this manual,
10694 the term @dfn{record} usually refers to a tape physical block,
10695 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
10696 It is true that archives may be put on disk or used with pipes,
10697 but nevertheless, @command{tar} tries to read and write the archive one
10698 @dfn{record} at a time, whatever the medium in use. One record is made
10699 up of an integral number of blocks, and this operation of putting many
10700 disk blocks into a single tape block is called @dfn{reblocking}, or
10701 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
10702 the logical organization of many characters into something meaningful
10703 to the application. The term @dfn{unit record} describes a small set
10704 of characters which are transmitted whole to or by the application,
10705 and often refers to a line of text. Those two last terms are unrelated
10706 to what we call a @dfn{record} in @GNUTAR{}.
10707
10708 When writing to tapes, @command{tar} writes the contents of the archive
10709 in chunks known as @dfn{records}. To change the default blocking
10710 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
10711 @var{512-size}}) option. Each record will then be composed of
10712 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
10713 @xref{Standard}.) Each file written to the archive uses at least one
10714 full record. As a result, using a larger record size can result in
10715 more wasted space for small files. On the other hand, a larger record
10716 size can often be read and written much more efficiently.
10717
10718 Further complicating the problem is that some tape drives ignore the
10719 blocking entirely. For these, a larger record size can still improve
10720 performance (because the software layers above the tape drive still
10721 honor the blocking), but not as dramatically as on tape drives that
10722 honor blocking.
10723
10724 When reading an archive, @command{tar} can usually figure out the
10725 record size on itself. When this is the case, and a non-standard
10726 record size was used when the archive was created, @command{tar} will
10727 print a message about a non-standard blocking factor, and then operate
10728 normally@footnote{If this message is not needed, you can turn it off
10729 using the @option{--warning=no-record-size} option.}. On some tape
10730 devices, however, @command{tar} cannot figure out the record size
10731 itself. On most of those, you can specify a blocking factor (with
10732 @option{--blocking-factor}) larger than the actual blocking factor,
10733 and then use the @option{--read-full-records} (@option{-B}) option.
10734 (If you specify a blocking factor with @option{--blocking-factor} and
10735 don't use the @option{--read-full-records} option, then @command{tar}
10736 will not attempt to figure out the recording size itself.) On some
10737 devices, you must always specify the record size exactly with
10738 @option{--blocking-factor} when reading, because @command{tar} cannot
10739 figure it out. In any case, use @option{--list} (@option{-t}) before
10740 doing any extractions to see whether @command{tar} is reading the archive
10741 correctly.
10742
10743 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
10744 putting them into records is to put a whole number of them (one or
10745 more) into each record. @command{tar} records are all the same size;
10746 at the end of the file there's a block containing all zeros, which
10747 is how you tell that the remainder of the last record(s) are garbage.
10748
10749 In a standard @command{tar} file (no options), the block size is 512
10750 and the record size is 10240, for a blocking factor of 20. What the
10751 @option{--blocking-factor} option does is sets the blocking factor,
10752 changing the record size while leaving the block size at 512 bytes.
10753 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
10754 most tape drives these days prefer much bigger records in order to
10755 stream and not waste tape. When writing tapes for myself, some tend
10756 to use a factor of the order of 2048, say, giving a record size of
10757 around one megabyte.
10758
10759 If you use a blocking factor larger than 20, older @command{tar}
10760 programs might not be able to read the archive, so we recommend this
10761 as a limit to use in practice. @GNUTAR{}, however,
10762 will support arbitrarily large record sizes, limited only by the
10763 amount of virtual memory or the physical characteristics of the tape
10764 device.
10765
10766 @menu
10767 * Format Variations:: Format Variations
10768 * Blocking Factor:: The Blocking Factor of an Archive
10769 @end menu
10770
10771 @node Format Variations
10772 @subsection Format Variations
10773 @cindex Format Parameters
10774 @cindex Format Options
10775 @cindex Options, archive format specifying
10776 @cindex Options, format specifying
10777 @UNREVISED
10778
10779 Format parameters specify how an archive is written on the archive
10780 media. The best choice of format parameters will vary depending on
10781 the type and number of files being archived, and on the media used to
10782 store the archive.
10783
10784 To specify format parameters when accessing or creating an archive,
10785 you can use the options described in the following sections.
10786 If you do not specify any format parameters, @command{tar} uses
10787 default parameters. You cannot modify a compressed archive.
10788 If you create an archive with the @option{--blocking-factor} option
10789 specified (@pxref{Blocking Factor}), you must specify that
10790 blocking-factor when operating on the archive. @xref{Formats}, for other
10791 examples of format parameter considerations.
10792
10793 @node Blocking Factor
10794 @subsection The Blocking Factor of an Archive
10795 @cindex Blocking Factor
10796 @cindex Record Size
10797 @cindex Number of blocks per record
10798 @cindex Number of bytes per record
10799 @cindex Bytes per record
10800 @cindex Blocks per record
10801 @UNREVISED
10802
10803 @opindex blocking-factor
10804 The data in an archive is grouped into blocks, which are 512 bytes.
10805 Blocks are read and written in whole number multiples called
10806 @dfn{records}. The number of blocks in a record (i.e., the size of a
10807 record in units of 512 bytes) is called the @dfn{blocking factor}.
10808 The @option{--blocking-factor=@var{512-size}} (@option{-b
10809 @var{512-size}}) option specifies the blocking factor of an archive.
10810 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10811 can be specified at installation. To find out the blocking factor of
10812 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10813 This may not work on some devices.
10814
10815 Records are separated by gaps, which waste space on the archive media.
10816 If you are archiving on magnetic tape, using a larger blocking factor
10817 (and therefore larger records) provides faster throughput and allows you
10818 to fit more data on a tape (because there are fewer gaps). If you are
10819 archiving on cartridge, a very large blocking factor (say 126 or more)
10820 greatly increases performance. A smaller blocking factor, on the other
10821 hand, may be useful when archiving small files, to avoid archiving lots
10822 of nulls as @command{tar} fills out the archive to the end of the record.
10823 In general, the ideal record size depends on the size of the
10824 inter-record gaps on the tape you are using, and the average size of the
10825 files you are archiving. @xref{create}, for information on
10826 writing archives.
10827
10828 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10829
10830 Archives with blocking factors larger than 20 cannot be read
10831 by very old versions of @command{tar}, or by some newer versions
10832 of @command{tar} running on old machines with small address spaces.
10833 With @GNUTAR{}, the blocking factor of an archive is limited
10834 only by the maximum record size of the device containing the archive,
10835 or by the amount of available virtual memory.
10836
10837 Also, on some systems, not using adequate blocking factors, as sometimes
10838 imposed by the device drivers, may yield unexpected diagnostics. For
10839 example, this has been reported:
10840
10841 @smallexample
10842 Cannot write to /dev/dlt: Invalid argument
10843 @end smallexample
10844
10845 @noindent
10846 In such cases, it sometimes happen that the @command{tar} bundled by
10847 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10848 requires an explicit specification for the block size,
10849 which it cannot guess. This yields some people to consider
10850 @GNUTAR{} is misbehaving, because by comparison,
10851 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10852 for example, might resolve the problem.
10853
10854 If you use a non-default blocking factor when you create an archive, you
10855 must specify the same blocking factor when you modify that archive. Some
10856 archive devices will also require you to specify the blocking factor when
10857 reading that archive, however this is not typically the case. Usually, you
10858 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10859 reports a non-default record size and then lists the archive members as
10860 it would normally. To extract files from an archive with a non-standard
10861 blocking factor (particularly if you're not sure what the blocking factor
10862 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10863 specifying a blocking factor larger then the blocking factor of the archive
10864 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
10865 @xref{list}, for more information on the @option{--list} (@option{-t})
10866 operation. @xref{Reading}, for a more detailed explanation of that option.
10867
10868 @table @option
10869 @item --blocking-factor=@var{number}
10870 @itemx -b @var{number}
10871 Specifies the blocking factor of an archive. Can be used with any
10872 operation, but is usually not necessary with @option{--list} (@option{-t}).
10873 @end table
10874
10875 Device blocking
10876
10877 @table @option
10878 @item -b @var{blocks}
10879 @itemx --blocking-factor=@var{blocks}
10880 Set record size to @math{@var{blocks}*512} bytes.
10881
10882 This option is used to specify a @dfn{blocking factor} for the archive.
10883 When reading or writing the archive, @command{tar}, will do reads and writes
10884 of the archive in records of @math{@var{block}*512} bytes. This is true
10885 even when the archive is compressed. Some devices requires that all
10886 write operations be a multiple of a certain size, and so, @command{tar}
10887 pads the archive out to the next record boundary.
10888
10889 The default blocking factor is set when @command{tar} is compiled, and is
10890 typically 20. Blocking factors larger than 20 cannot be read by very
10891 old versions of @command{tar}, or by some newer versions of @command{tar}
10892 running on old machines with small address spaces.
10893
10894 With a magnetic tape, larger records give faster throughput and fit
10895 more data on a tape (because there are fewer inter-record gaps).
10896 If the archive is in a disk file or a pipe, you may want to specify
10897 a smaller blocking factor, since a large one will result in a large
10898 number of null bytes at the end of the archive.
10899
10900 When writing cartridge or other streaming tapes, a much larger
10901 blocking factor (say 126 or more) will greatly increase performance.
10902 However, you must specify the same blocking factor when reading or
10903 updating the archive.
10904
10905 Apparently, Exabyte drives have a physical block size of 8K bytes.
10906 If we choose our blocksize as a multiple of 8k bytes, then the problem
10907 seems to disappear. Id est, we are using block size of 112 right
10908 now, and we haven't had the problem since we switched@dots{}
10909
10910 With @GNUTAR{} the blocking factor is limited only
10911 by the maximum record size of the device containing the archive, or by
10912 the amount of available virtual memory.
10913
10914 However, deblocking or reblocking is virtually avoided in a special
10915 case which often occurs in practice, but which requires all the
10916 following conditions to be simultaneously true:
10917 @itemize @bullet
10918 @item
10919 the archive is subject to a compression option,
10920 @item
10921 the archive is not handled through standard input or output, nor
10922 redirected nor piped,
10923 @item
10924 the archive is directly handled to a local disk, instead of any special
10925 device,
10926 @item
10927 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10928 invocation.
10929 @end itemize
10930
10931 If the output goes directly to a local disk, and not through
10932 stdout, then the last write is not extended to a full record size.
10933 Otherwise, reblocking occurs. Here are a few other remarks on this
10934 topic:
10935
10936 @itemize @bullet
10937
10938 @item
10939 @command{gzip} will complain about trailing garbage if asked to
10940 uncompress a compressed archive on tape, there is an option to turn
10941 the message off, but it breaks the regularity of simply having to use
10942 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10943 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10944 Gailly, by sending a copy of this message to him.
10945
10946 @item
10947 @command{compress} does not show this problem, but as Jean-loup pointed
10948 out to Michael, @samp{compress -d} silently adds garbage after
10949 the result of decompression, which tar ignores because it already
10950 recognized its end-of-file indicator. So this bug may be safely
10951 ignored.
10952
10953 @item
10954 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10955 but will still return an exit status of 2 which tar reports in turn.
10956 @command{tar} might ignore the exit status returned, but I hate doing
10957 that, as it weakens the protection @command{tar} offers users against
10958 other possible problems at decompression time. If @command{gzip} was
10959 silently skipping trailing zeros @emph{and} also avoiding setting the
10960 exit status in this innocuous case, that would solve this situation.
10961
10962 @item
10963 @command{tar} should become more solid at not stopping to read a pipe at
10964 the first null block encountered. This inelegantly breaks the pipe.
10965 @command{tar} should rather drain the pipe out before exiting itself.
10966 @end itemize
10967
10968 @xopindex{ignore-zeros, short description}
10969 @item -i
10970 @itemx --ignore-zeros
10971 Ignore blocks of zeros in archive (means EOF).
10972
10973 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10974 of zeros in the archive. Normally a block of zeros indicates the
10975 end of the archive, but when reading a damaged archive, or one which
10976 was created by concatenating several archives together, this option
10977 allows @command{tar} to read the entire archive. This option is not on
10978 by default because many versions of @command{tar} write garbage after
10979 the zeroed blocks.
10980
10981 Note that this option causes @command{tar} to read to the end of the
10982 archive file, which may sometimes avoid problems when multiple files
10983 are stored on a single physical tape.
10984
10985 @xopindex{read-full-records, short description}
10986 @item -B
10987 @itemx --read-full-records
10988 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10989
10990 If @option{--read-full-records} is used, @command{tar}
10991 will not panic if an attempt to read a record from the archive does
10992 not return a full record. Instead, @command{tar} will keep reading
10993 until it has obtained a full
10994 record.
10995
10996 This option is turned on by default when @command{tar} is reading
10997 an archive from standard input, or from a remote machine. This is
10998 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10999 much happens to be in the pipe, even if it is less than @command{tar}
11000 requested. If this option was not used, @command{tar} would fail as
11001 soon as it read an incomplete record from the pipe.
11002
11003 This option is also useful with the commands for updating an archive.
11004
11005 @end table
11006
11007 Tape blocking
11008
11009 @FIXME{Appropriate options should be moved here from elsewhere.}
11010
11011 @cindex blocking factor
11012 @cindex tape blocking
11013
11014 When handling various tapes or cartridges, you have to take care of
11015 selecting a proper blocking, that is, the number of disk blocks you
11016 put together as a single tape block on the tape, without intervening
11017 tape gaps. A @dfn{tape gap} is a small landing area on the tape
11018 with no information on it, used for decelerating the tape to a
11019 full stop, and for later regaining the reading or writing speed.
11020 When the tape driver starts reading a record, the record has to
11021 be read whole without stopping, as a tape gap is needed to stop the
11022 tape motion without losing information.
11023
11024 @cindex Exabyte blocking
11025 @cindex DAT blocking
11026 Using higher blocking (putting more disk blocks per tape block) will use
11027 the tape more efficiently as there will be less tape gaps. But reading
11028 such tapes may be more difficult for the system, as more memory will be
11029 required to receive at once the whole record. Further, if there is a
11030 reading error on a huge record, this is less likely that the system will
11031 succeed in recovering the information. So, blocking should not be too
11032 low, nor it should be too high. @command{tar} uses by default a blocking of
11033 20 for historical reasons, and it does not really matter when reading or
11034 writing to disk. Current tape technology would easily accommodate higher
11035 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
11036 We were told that for some DLT drives, the blocking should be a multiple
11037 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
11038 Other manufacturers may use different recommendations for the same tapes.
11039 This might also depends of the buffering techniques used inside modern
11040 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
11041 Others request blocking to be some exponent of two.
11042
11043 So, there is no fixed rule for blocking. But blocking at read time
11044 should ideally be the same as blocking used at write time. At one place
11045 I know, with a wide variety of equipment, they found it best to use a
11046 blocking of 32 to guarantee that their tapes are fully interchangeable.
11047
11048 I was also told that, for recycled tapes, prior erasure (by the same
11049 drive unit that will be used to create the archives) sometimes lowers
11050 the error rates observed at rewriting time.
11051
11052 I might also use @option{--number-blocks} instead of
11053 @option{--block-number}, so @option{--block} will then expand to
11054 @option{--blocking-factor} unambiguously.
11055
11056 @node Many
11057 @section Many Archives on One Tape
11058
11059 @FIXME{Appropriate options should be moved here from elsewhere.}
11060
11061 @findex ntape @r{device}
11062 Most tape devices have two entries in the @file{/dev} directory, or
11063 entries that come in pairs, which differ only in the minor number for
11064 this device. Let's take for example @file{/dev/tape}, which often
11065 points to the only or usual tape device of a given system. There might
11066 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
11067 name is the @emph{rewinding} version of the device, while the name
11068 having @samp{nr} in it is the @emph{no rewinding} version of the same
11069 device.
11070
11071 A rewinding tape device will bring back the tape to its beginning point
11072 automatically when this device is opened or closed. Since @command{tar}
11073 opens the archive file before using it and closes it afterwards, this
11074 means that a simple:
11075
11076 @smallexample
11077 $ @kbd{tar cf /dev/tape @var{directory}}
11078 @end smallexample
11079
11080 @noindent
11081 will reposition the tape to its beginning both prior and after saving
11082 @var{directory} contents to it, thus erasing prior tape contents and
11083 making it so that any subsequent write operation will destroy what has
11084 just been saved.
11085
11086 @cindex tape positioning
11087 So, a rewinding device is normally meant to hold one and only one file.
11088 If you want to put more than one @command{tar} archive on a given tape, you
11089 will need to avoid using the rewinding version of the tape device. You
11090 will also have to pay special attention to tape positioning. Errors in
11091 positioning may overwrite the valuable data already on your tape. Many
11092 people, burnt by past experiences, will only use rewinding devices and
11093 limit themselves to one file per tape, precisely to avoid the risk of
11094 such errors. Be fully aware that writing at the wrong position on a
11095 tape loses all information past this point and most probably until the
11096 end of the tape, and this destroyed information @emph{cannot} be
11097 recovered.
11098
11099 To save @var{directory-1} as a first archive at the beginning of a
11100 tape, and leave that tape ready for a second archive, you should use:
11101
11102 @smallexample
11103 $ @kbd{mt -f /dev/nrtape rewind}
11104 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
11105 @end smallexample
11106
11107 @cindex tape marks
11108 @dfn{Tape marks} are special magnetic patterns written on the tape
11109 media, which are later recognizable by the reading hardware. These
11110 marks are used after each file, when there are many on a single tape.
11111 An empty file (that is to say, two tape marks in a row) signal the
11112 logical end of the tape, after which no file exist. Usually,
11113 non-rewinding tape device drivers will react to the close request issued
11114 by @command{tar} by first writing two tape marks after your archive, and by
11115 backspacing over one of these. So, if you remove the tape at that time
11116 from the tape drive, it is properly terminated. But if you write
11117 another file at the current position, the second tape mark will be
11118 erased by the new information, leaving only one tape mark between files.
11119
11120 So, you may now save @var{directory-2} as a second archive after the
11121 first on the same tape by issuing the command:
11122
11123 @smallexample
11124 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11125 @end smallexample
11126
11127 @noindent
11128 and so on for all the archives you want to put on the same tape.
11129
11130 Another usual case is that you do not write all the archives the same
11131 day, and you need to remove and store the tape between two archive
11132 sessions. In general, you must remember how many files are already
11133 saved on your tape. Suppose your tape already has 16 files on it, and
11134 that you are ready to write the 17th. You have to take care of skipping
11135 the first 16 tape marks before saving @var{directory-17}, say, by using
11136 these commands:
11137
11138 @smallexample
11139 $ @kbd{mt -f /dev/nrtape rewind}
11140 $ @kbd{mt -f /dev/nrtape fsf 16}
11141 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11142 @end smallexample
11143
11144 In all the previous examples, we put aside blocking considerations, but
11145 you should do the proper things for that as well. @xref{Blocking}.
11146
11147 @menu
11148 * Tape Positioning:: Tape Positions and Tape Marks
11149 * mt:: The @command{mt} Utility
11150 @end menu
11151
11152 @node Tape Positioning
11153 @subsection Tape Positions and Tape Marks
11154 @UNREVISED
11155
11156 Just as archives can store more than one file from the file system,
11157 tapes can store more than one archive file. To keep track of where
11158 archive files (or any other type of file stored on tape) begin and
11159 end, tape archive devices write magnetic @dfn{tape marks} on the
11160 archive media. Tape drives write one tape mark between files,
11161 two at the end of all the file entries.
11162
11163 If you think of data as a series of records "rrrr"'s, and tape marks as
11164 "*"'s, a tape might look like the following:
11165
11166 @smallexample
11167 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11168 @end smallexample
11169
11170 Tape devices read and write tapes using a read/write @dfn{tape
11171 head}---a physical part of the device which can only access one
11172 point on the tape at a time. When you use @command{tar} to read or
11173 write archive data from a tape device, the device will begin reading
11174 or writing from wherever on the tape the tape head happens to be,
11175 regardless of which archive or what part of the archive the tape
11176 head is on. Before writing an archive, you should make sure that no
11177 data on the tape will be overwritten (unless it is no longer needed).
11178 Before reading an archive, you should make sure the tape head is at
11179 the beginning of the archive you want to read. You can do it manually
11180 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
11181 that automatically (@pxref{Scripted Restoration}).
11182
11183 If you want to add new archive file entries to a tape, you should
11184 advance the tape to the end of the existing file entries, backspace
11185 over the last tape mark, and write the new archive file. If you were
11186 to add two archives to the example above, the tape might look like the
11187 following:
11188
11189 @smallexample
11190 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11191 @end smallexample
11192
11193 @node mt
11194 @subsection The @command{mt} Utility
11195 @UNREVISED
11196
11197 @FIXME{Is it true that this only works on non-block devices?
11198 should explain the difference, (fixed or variable).}
11199 @xref{Blocking Factor}.
11200
11201 You can use the @command{mt} utility to advance or rewind a tape past a
11202 specified number of archive files on the tape. This will allow you
11203 to move to the beginning of an archive before extracting or reading
11204 it, or to the end of all the archives before writing a new one.
11205 @FIXME{Why isn't there an "advance 'til you find two tape marks
11206 together"?}
11207
11208 The syntax of the @command{mt} command is:
11209
11210 @smallexample
11211 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11212 @end smallexample
11213
11214 where @var{tapename} is the name of the tape device, @var{number} is
11215 the number of times an operation is performed (with a default of one),
11216 and @var{operation} is one of the following:
11217
11218 @FIXME{is there any use for record operations?}
11219
11220 @table @option
11221 @item eof
11222 @itemx weof
11223 Writes @var{number} tape marks at the current position on the tape.
11224
11225 @item fsf
11226 Moves tape position forward @var{number} files.
11227
11228 @item bsf
11229 Moves tape position back @var{number} files.
11230
11231 @item rewind
11232 Rewinds the tape. (Ignores @var{number}.)
11233
11234 @item offline
11235 @itemx rewoff1
11236 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
11237
11238 @item status
11239 Prints status information about the tape unit.
11240
11241 @end table
11242
11243 If you don't specify a @var{tapename}, @command{mt} uses the environment
11244 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11245 the default device specified in your @file{sys/mtio.h} file
11246 (@code{DEFTAPE} variable). If this is not defined, the program will
11247 display a descriptive error message and exit with code 1.
11248
11249 @command{mt} returns a 0 exit status when the operation(s) were
11250 successful, 1 if the command was unrecognized, and 2 if an operation
11251 failed.
11252
11253 @node Using Multiple Tapes
11254 @section Using Multiple Tapes
11255
11256 Often you might want to write a large archive, one larger than will fit
11257 on the actual tape you are using. In such a case, you can run multiple
11258 @command{tar} commands, but this can be inconvenient, particularly if you
11259 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
11260 Therefore, @command{tar} provides a special mode for creating
11261 multi-volume archives.
11262
11263 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
11264 on several media volumes of fixed size. Although in this section we will
11265 often call @samp{volume} a @dfn{tape}, there is absolutely no
11266 requirement for multi-volume archives to be stored on tapes. Instead,
11267 they can use whatever media type the user finds convenient, they can
11268 even be located on files.
11269
11270 When creating a multi-volume archive, @GNUTAR{} continues to fill
11271 current volume until it runs out of space, then it switches to
11272 next volume (usually the operator is queried to replace the tape on
11273 this point), and continues working on the new volume. This operation
11274 continues until all requested files are dumped. If @GNUTAR{} detects
11275 end of media while dumping a file, such a file is archived in split
11276 form. Some very big files can even be split across several volumes.
11277
11278 Each volume is itself a valid @GNUTAR{} archive, so it can be read
11279 without any special options. Consequently any file member residing
11280 entirely on one volume can be extracted or otherwise operated upon
11281 without needing the other volume. Sure enough, to extract a split
11282 member you would need all volumes its parts reside on.
11283
11284 Multi-volume archives suffer from several limitations. In particular,
11285 they cannot be compressed.
11286
11287 @GNUTAR{} is able to create multi-volume archives of two formats
11288 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
11289
11290 @menu
11291 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
11292 * Tape Files:: Tape Files
11293 * Tarcat:: Concatenate Volumes into a Single Archive
11294
11295 @end menu
11296
11297 @node Multi-Volume Archives
11298 @subsection Archives Longer than One Tape or Disk
11299 @cindex Multi-volume archives
11300
11301 @opindex multi-volume
11302 To create an archive that is larger than will fit on a single unit of
11303 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
11304 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
11305 archive can be manipulated like any other archive (provided the
11306 @option{--multi-volume} option is specified), but is stored on more
11307 than one tape or file.
11308
11309 When you specify @option{--multi-volume}, @command{tar} does not report an
11310 error when it comes to the end of an archive volume (when reading), or
11311 the end of the media (when writing). Instead, it prompts you to load
11312 a new storage volume. If the archive is on a magnetic tape, you
11313 should change tapes when you see the prompt; if the archive is on a
11314 floppy disk, you should change disks; etc.
11315
11316 @table @option
11317 @item --multi-volume
11318 @itemx -M
11319 Creates a multi-volume archive, when used in conjunction with
11320 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
11321 archive, specify @option{--multi-volume} in conjunction with that
11322 operation.
11323 For example:
11324
11325 @smallexample
11326 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
11327 @end smallexample
11328 @end table
11329
11330 The method @command{tar} uses to detect end of tape is not perfect, and
11331 fails on some operating systems or on some devices. If @command{tar}
11332 cannot detect the end of the tape itself, you can use
11333 @option{--tape-length} option to inform it about the capacity of the
11334 tape:
11335
11336 @anchor{tape-length}
11337 @table @option
11338 @opindex tape-length
11339 @item --tape-length=@var{size}[@var{suf}]
11340 @itemx -L @var{size}[@var{suf}]
11341 Set maximum length of a volume. The @var{suf}, if given, specifies
11342 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
11343 megabytes (@pxref{size-suffixes}, for a list of allowed size
11344 suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
11345 assumed.
11346
11347 This option selects @option{--multi-volume} automatically. For example:
11348
11349 @smallexample
11350 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
11351 @end smallexample
11352
11353 @noindent
11354 or, which is equivalent:
11355
11356 @smallexample
11357 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
11358 @end smallexample
11359 @end table
11360
11361 @anchor{change volume prompt}
11362 When @GNUTAR{} comes to the end of a storage media, it asks you to
11363 change the volume. The built-in prompt for POSIX locale
11364 is@footnote{If you run @GNUTAR{} under a different locale, the
11365 translation to the locale's language will be used.}:
11366
11367 @smallexample
11368 Prepare volume #@var{n} for '@var{archive}' and hit return:
11369 @end smallexample
11370
11371 @noindent
11372 where @var{n} is the ordinal number of the volume to be created and
11373 @var{archive} is archive file or device name.
11374
11375 When prompting for a new tape, @command{tar} accepts any of the following
11376 responses:
11377
11378 @table @kbd
11379 @item ?
11380 Request @command{tar} to explain possible responses.
11381 @item q
11382 Request @command{tar} to exit immediately.
11383 @item n @var{file-name}
11384 Request @command{tar} to write the next volume on the file @var{file-name}.
11385 @item !
11386 Request @command{tar} to run a subshell. This option can be disabled
11387 by giving @option{--restrict} command line option to
11388 @command{tar}@footnote{@xref{--restrict}, for more information about
11389 this option.}.
11390 @item y
11391 Request @command{tar} to begin writing the next volume.
11392 @end table
11393
11394 (You should only type @samp{y} after you have changed the tape;
11395 otherwise @command{tar} will write over the volume it just finished.)
11396
11397 @cindex Volume number file
11398 @cindex volno file
11399 @anchor{volno-file}
11400 @opindex volno-file
11401 The volume number used by @command{tar} in its tape-changing prompt
11402 can be changed; if you give the
11403 @option{--volno-file=@var{file-of-number}} option, then
11404 @var{file-of-number} should be an non-existing file to be created, or
11405 else, a file already containing a decimal number. That number will be
11406 used as the volume number of the first volume written. When
11407 @command{tar} is finished, it will rewrite the file with the
11408 now-current volume number. (This does not change the volume number
11409 written on a tape label, as per @ref{label}, it @emph{only} affects
11410 the number used in the prompt.)
11411
11412 @cindex End-of-archive info script
11413 @cindex Info script
11414 @anchor{info-script}
11415 @opindex info-script
11416 @opindex new-volume-script
11417 If you want more elaborate behavior than this, you can write a special
11418 @dfn{new volume script}, that will be responsible for changing the
11419 volume, and instruct @command{tar} to use it instead of its normal
11420 prompting procedure:
11421
11422 @table @option
11423 @item --info-script=@var{command}
11424 @itemx --new-volume-script=@var{command}
11425 @itemx -F @var{command}
11426 Specify the command to invoke when switching volumes. The @var{command}
11427 can be used to eject cassettes, or to broadcast messages such as
11428 @samp{Someone please come change my tape} when performing unattended
11429 backups.
11430 @end table
11431
11432 The @var{command} can contain additional options, if such are needed.
11433 @xref{external, Running External Commands}, for a detailed discussion
11434 of the way @GNUTAR{} runs external commands. It inherits
11435 @command{tar}'s shell environment. Additional data is passed to it
11436 via the following environment variables:
11437
11438 @table @env
11439 @vrindex TAR_VERSION, info script environment variable
11440 @item TAR_VERSION
11441 @GNUTAR{} version number.
11442
11443 @vrindex TAR_ARCHIVE, info script environment variable
11444 @item TAR_ARCHIVE
11445 The name of the archive @command{tar} is processing.
11446
11447 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
11448 @item TAR_BLOCKING_FACTOR
11449 Current blocking factor (@pxref{Blocking}).
11450
11451 @vrindex TAR_VOLUME, info script environment variable
11452 @item TAR_VOLUME
11453 Ordinal number of the volume @command{tar} is about to start.
11454
11455 @vrindex TAR_SUBCOMMAND, info script environment variable
11456 @item TAR_SUBCOMMAND
11457 A short option describing the operation @command{tar} is executing.
11458 @xref{Operations}, for a complete list of subcommand options.
11459
11460 @vrindex TAR_FORMAT, info script environment variable
11461 @item TAR_FORMAT
11462 Format of the archive being processed. @xref{Formats}, for a complete
11463 list of archive format names.
11464
11465 @vrindex TAR_FD, info script environment variable
11466 @item TAR_FD
11467 File descriptor which can be used to communicate the new volume
11468 name to @command{tar}.
11469 @end table
11470
11471 These variables can be used in the @var{command} itself, provided that
11472 they are properly quoted to prevent them from being expanded by the
11473 shell that invokes @command{tar}.
11474
11475 The volume script can instruct @command{tar} to use new archive name,
11476 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
11477
11478 If the info script fails, @command{tar} exits; otherwise, it begins
11479 writing the next volume.
11480
11481 If you want @command{tar} to cycle through a series of files or tape
11482 drives, there are three approaches to choose from. First of all, you
11483 can give @command{tar} multiple @option{--file} options. In this case
11484 the specified files will be used, in sequence, as the successive
11485 volumes of the archive. Only when the first one in the sequence needs
11486 to be used again will @command{tar} prompt for a tape change (or run
11487 the info script). For example, suppose someone has two tape drives on
11488 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
11489 @GNUTAR{} to switch to the second drive when it needs to write the
11490 second tape, and then back to the first tape, etc., just do either of:
11491
11492 @smallexample
11493 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
11494 $ @kbd{tar -cM -f /dev/tape0 -f /dev/tape1 @var{files}}
11495 @end smallexample
11496
11497 The second method is to use the @samp{n} response to the tape-change
11498 prompt.
11499
11500 Finally, the most flexible approach is to use a volume script, that
11501 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
11502 following volume script will create a series of archive files, named
11503 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
11504 archive being created (as given by @option{--file} option) and
11505 @var{vol} is the ordinal number of the archive being created:
11506
11507 @smallexample
11508 @group
11509 #! /bin/bash
11510 # For this script it's advisable to use a shell, such as Bash,
11511 # that supports a TAR_FD value greater than 9.
11512
11513 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
11514
11515 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
11516 case $TAR_SUBCOMMAND in
11517 -c) ;;
11518 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
11519 ;;
11520 *) exit 1
11521 esac
11522
11523 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
11524 @end group
11525 @end smallexample
11526
11527 The same script can be used while listing, comparing or extracting
11528 from the created archive. For example:
11529
11530 @smallexample
11531 @group
11532 # @r{Create a multi-volume archive:}
11533 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
11534 # @r{Extract from the created archive:}
11535 $ @kbd{tar -x -f archive.tar -F new-volume .}
11536 @end group
11537 @end smallexample
11538
11539 @noindent
11540 Notice, that the first command had to use @option{-L} option, since
11541 otherwise @GNUTAR{} will end up writing everything to file
11542 @file{archive.tar}.
11543
11544 You can read each individual volume of a multi-volume archive as if it
11545 were an archive by itself. For example, to list the contents of one
11546 volume, use @option{--list}, without @option{--multi-volume} specified.
11547 To extract an archive member from one volume (assuming it is described
11548 that volume), use @option{--extract}, again without
11549 @option{--multi-volume}.
11550
11551 If an archive member is split across volumes (i.e., its entry begins on
11552 one volume of the media and ends on another), you need to specify
11553 @option{--multi-volume} to extract it successfully. In this case, you
11554 should load the volume where the archive member starts, and use
11555 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
11556 volumes as it needs them. @xref{extracting archives}, for more
11557 information about extracting archives.
11558
11559 Multi-volume archives can be modified like any other archive. To add
11560 files to a multi-volume archive, you need to only mount the last
11561 volume of the archive media (and new volumes, if needed). For all
11562 other operations, you need to use the entire archive.
11563
11564 If a multi-volume archive was labeled using
11565 @option{--label=@var{archive-label}} (@pxref{label}) when it was
11566 created, @command{tar} will not automatically label volumes which are
11567 added later. To label subsequent volumes, specify
11568 @option{--label=@var{archive-label}} again in conjunction with the
11569 @option{--append}, @option{--update} or @option{--concatenate} operation.
11570
11571 Notice that multi-volume support is a GNU extension and the archives
11572 created in this mode should be read only using @GNUTAR{}. If you
11573 absolutely have to process such archives using a third-party @command{tar}
11574 implementation, read @ref{Split Recovery}.
11575
11576 @node Tape Files
11577 @subsection Tape Files
11578 @cindex labeling archives
11579 @opindex label
11580 @UNREVISED
11581
11582 To give the archive a name which will be recorded in it, use the
11583 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
11584 option. This will write a special block identifying
11585 @var{volume-label} as the name of the archive to the front of the
11586 archive which will be displayed when the archive is listed with
11587 @option{--list}. If you are creating a multi-volume archive with
11588 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
11589 volume label will have @samp{Volume @var{nnn}} appended to the name
11590 you give, where @var{nnn} is the number of the volume of the archive.
11591 If you use the @option{--label=@var{volume-label}} option when
11592 reading an archive, it checks to make sure the label on the tape
11593 matches the one you gave. @xref{label}.
11594
11595 When @command{tar} writes an archive to tape, it creates a single
11596 tape file. If multiple archives are written to the same tape, one
11597 after the other, they each get written as separate tape files. When
11598 extracting, it is necessary to position the tape at the right place
11599 before running @command{tar}. To do this, use the @command{mt} command.
11600 For more information on the @command{mt} command and on the organization
11601 of tapes into a sequence of tape files, see @ref{mt}.
11602
11603 People seem to often do:
11604
11605 @smallexample
11606 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
11607 @end smallexample
11608
11609 or such, for pushing a common date in all volumes or an archive set.
11610
11611 @node Tarcat
11612 @subsection Concatenate Volumes into a Single Archive
11613
11614 @pindex tarcat
11615 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
11616 archive to a single @command{tar} archive. Simply concatenating all
11617 volumes into one will not work, since each volume carries an additional
11618 information at the beginning. @GNUTAR{} is shipped with the shell
11619 script @command{tarcat} designed for this purpose.
11620
11621 The script takes a list of files comprising a multi-volume archive
11622 and creates the resulting archive at the standard output. For example:
11623
11624 @smallexample
11625 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
11626 @end smallexample
11627
11628 The script implements a simple heuristics to determine the format of
11629 the first volume file and to decide how to process the rest of the
11630 files. However, it makes no attempt to verify whether the files are
11631 given in order or even if they are valid @command{tar} archives.
11632 It uses @command{dd} and does not filter its standard error, so you
11633 will usually see lots of spurious messages.
11634
11635 @FIXME{The script is not installed. Should we install it?}
11636
11637 @node label
11638 @section Including a Label in the Archive
11639 @cindex Labeling an archive
11640 @cindex Labels on the archive media
11641 @cindex Labeling multi-volume archives
11642
11643 @opindex label
11644 To avoid problems caused by misplaced paper labels on the archive
11645 media, you can include a @dfn{label} entry --- an archive member which
11646 contains the name of the archive --- in the archive itself. Use the
11647 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11648 option@footnote{Until version 1.10, that option was called
11649 @option{--volume}, but is not available under that name anymore.} in
11650 conjunction with the @option{--create} operation to include a label
11651 entry in the archive as it is being created.
11652
11653 @table @option
11654 @item --label=@var{archive-label}
11655 @itemx -V @var{archive-label}
11656 Includes an @dfn{archive-label} at the beginning of the archive when
11657 the archive is being created, when used in conjunction with the
11658 @option{--create} operation. Checks to make sure the archive label
11659 matches the one specified (when used in conjunction with any other
11660 operation).
11661 @end table
11662
11663 If you create an archive using both
11664 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11665 and @option{--multi-volume} (@option{-M}), each volume of the archive
11666 will have an archive label of the form @samp{@var{archive-label}
11667 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
11668 next, and so on. @xref{Using Multiple Tapes}, for information on
11669 creating multiple volume archives.
11670
11671 @cindex Volume label, listing
11672 @cindex Listing volume label
11673 The volume label will be displayed by @option{--list} along with
11674 the file contents. If verbose display is requested, it will also be
11675 explicitly marked as in the example below:
11676
11677 @smallexample
11678 @group
11679 $ @kbd{tar --verbose --list --file=iamanarchive}
11680 V--------- 0/0 0 1992-03-07 12:01 iamalabel--Volume Header--
11681 -rw-r--r-- ringo/user 40 1990-05-21 13:30 iamafilename
11682 @end group
11683 @end smallexample
11684
11685 @opindex test-label
11686 @anchor{--test-label option}
11687 However, @option{--list} option will cause listing entire
11688 contents of the archive, which may be undesirable (for example, if the
11689 archive is stored on a tape). You can request checking only the volume
11690 label by specifying @option{--test-label} option. This option reads only the
11691 first block of an archive, so it can be used with slow storage
11692 devices. For example:
11693
11694 @smallexample
11695 @group
11696 $ @kbd{tar --test-label --file=iamanarchive}
11697 iamalabel
11698 @end group
11699 @end smallexample
11700
11701 If @option{--test-label} is used with one or more command line
11702 arguments, @command{tar} compares the volume label with each
11703 argument. It exits with code 0 if a match is found, and with code 1
11704 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
11705 mismatch with an exit code 2 and printed a spurious diagnostics on
11706 stderr.}. No output is displayed, unless you also used the
11707 @option{--verbose} option. For example:
11708
11709 @smallexample
11710 @group
11711 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
11712 @result{} 0
11713 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
11714 @result{} 1
11715 @end group
11716 @end smallexample
11717
11718 When used with the @option{--verbose} option, @command{tar}
11719 prints the actual volume label (if any), and a verbose diagnostics in
11720 case of a mismatch:
11721
11722 @smallexample
11723 @group
11724 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
11725 iamalabel
11726 @result{} 0
11727 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
11728 iamalabel
11729 tar: Archive label mismatch
11730 @result{} 1
11731 @end group
11732 @end smallexample
11733
11734 If you request any operation, other than @option{--create}, along
11735 with using @option{--label} option, @command{tar} will first check if
11736 the archive label matches the one specified and will refuse to proceed
11737 if it does not. Use this as a safety precaution to avoid accidentally
11738 overwriting existing archives. For example, if you wish to add files
11739 to @file{archive}, presumably labeled with string @samp{My volume},
11740 you will get:
11741
11742 @smallexample
11743 @group
11744 $ @kbd{tar -rf archive --label 'My volume' .}
11745 tar: Archive not labeled to match 'My volume'
11746 @end group
11747 @end smallexample
11748
11749 @noindent
11750 in case its label does not match. This will work even if
11751 @file{archive} is not labeled at all.
11752
11753 Similarly, @command{tar} will refuse to list or extract the
11754 archive if its label doesn't match the @var{archive-label}
11755 specified. In those cases, @var{archive-label} argument is interpreted
11756 as a globbing-style pattern which must match the actual magnetic
11757 volume label. @xref{exclude}, for a precise description of how match
11758 is attempted@footnote{Previous versions of @command{tar} used full
11759 regular expression matching, or before that, only exact string
11760 matching, instead of wildcard matchers. We decided for the sake of
11761 simplicity to use a uniform matching device through
11762 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
11763 the volume label matcher will also suffix @var{archive-label} by
11764 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
11765 up. Since the volume numbering is automatically added in labels at
11766 creation time, it sounded logical to equally help the user taking care
11767 of it when the archive is being read.
11768
11769 You can also use @option{--label} to get a common information on
11770 all tapes of a series. For having this information different in each
11771 series created through a single script used on a regular basis, just
11772 manage to get some date string as part of the label. For example:
11773
11774 @smallexample
11775 @group
11776 $ @kbd{tar -cM -f /dev/tape -V "Daily backup for `date +%Y-%m-%d`"}
11777 $ @kbd{tar --create --file=/dev/tape --multi-volume \
11778 --label="Daily backup for `date +%Y-%m-%d`"}
11779 @end group
11780 @end smallexample
11781
11782 Some more notes about volume labels:
11783
11784 @itemize @bullet
11785 @item Each label has its own date and time, which corresponds
11786 to the time when @GNUTAR{} initially attempted to write it,
11787 often soon after the operator launches @command{tar} or types the
11788 carriage return telling that the next tape is ready.
11789
11790 @item Comparing date labels to get an idea of tape throughput is
11791 unreliable. It gives correct results only if the delays for rewinding
11792 tapes and the operator switching them were negligible, which is
11793 usually not the case.
11794 @end itemize
11795
11796 @node verify
11797 @section Verifying Data as It is Stored
11798 @cindex Verifying a write operation
11799 @cindex Double-checking a write operation
11800
11801 @table @option
11802 @item -W
11803 @itemx --verify
11804 @opindex verify, short description
11805 Attempt to verify the archive after writing.
11806 @end table
11807
11808 This option causes @command{tar} to verify the archive after writing it.
11809 Each volume is checked after it is written, and any discrepancies
11810 are recorded on the standard error output.
11811
11812 Verification requires that the archive be on a back-space-able medium.
11813 This means pipes, some cartridge tape drives, and some other devices
11814 cannot be verified.
11815
11816 You can insure the accuracy of an archive by comparing files in the
11817 system with archive members. @command{tar} can compare an archive to the
11818 file system as the archive is being written, to verify a write
11819 operation, or can compare a previously written archive, to insure that
11820 it is up to date.
11821
11822 @xopindex{verify, using with @option{--create}}
11823 @xopindex{create, using with @option{--verify}}
11824 To check for discrepancies in an archive immediately after it is
11825 written, use the @option{--verify} (@option{-W}) option in conjunction with
11826 the @option{--create} operation. When this option is
11827 specified, @command{tar} checks archive members against their counterparts
11828 in the file system, and reports discrepancies on the standard error.
11829
11830 To verify an archive, you must be able to read it from before the end
11831 of the last written entry. This option is useful for detecting data
11832 errors on some tapes. Archives written to pipes, some cartridge tape
11833 drives, and some other devices cannot be verified.
11834
11835 One can explicitly compare an already made archive with the file
11836 system by using the @option{--compare} (@option{--diff}, @option{-d})
11837 option, instead of using the more automatic @option{--verify} option.
11838 @xref{compare}.
11839
11840 Note that these two options have a slightly different intent. The
11841 @option{--compare} option checks how identical are the logical contents of some
11842 archive with what is on your disks, while the @option{--verify} option is
11843 really for checking if the physical contents agree and if the recording
11844 media itself is of dependable quality. So, for the @option{--verify}
11845 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11846 the archive, while it lets the speed optimization undisturbed for the
11847 @option{--compare} option. If you nevertheless use @option{--compare} for
11848 media verification, you may have to defeat the in-memory cache yourself,
11849 maybe by opening and reclosing the door latch of your recording unit,
11850 forcing some doubt in your operating system about the fact this is really
11851 the same volume as the one just written or read.
11852
11853 The @option{--verify} option would not be necessary if drivers were indeed
11854 able to detect dependably all write failures. This sometimes require many
11855 magnetic heads, some able to read after the writes occurred. One would
11856 not say that drivers unable to detect all cases are necessarily flawed,
11857 as long as programming is concerned.
11858
11859 The @option{--verify} (@option{-W}) option will not work in
11860 conjunction with the @option{--multi-volume} (@option{-M}) option or
11861 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11862 and @option{--delete} operations. @xref{Operations}, for more
11863 information on these operations.
11864
11865 Also, since @command{tar} normally strips leading @samp{/} from file
11866 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11867 /tmp/foo.tar /etc} will work as desired only if the working directory is
11868 @file{/}, as @command{tar} uses the archive's relative member names
11869 (e.g., @file{etc/motd}) when verifying the archive.
11870
11871 @node Write Protection
11872 @section Write Protection
11873
11874 Almost all tapes and diskettes, and in a few rare cases, even disks can
11875 be @dfn{write protected}, to protect data on them from being changed.
11876 Once an archive is written, you should write protect the media to prevent
11877 the archive from being accidentally overwritten or deleted. (This will
11878 protect the archive from being changed with a tape or floppy drive---it
11879 will not protect it from magnet fields or other physical hazards.)
11880
11881 The write protection device itself is usually an integral part of the
11882 physical media, and can be a two position (write enabled/write
11883 disabled) switch, a notch which can be popped out or covered, a ring
11884 which can be removed from the center of a tape reel, or some other
11885 changeable feature.
11886
11887 @node Reliability and security
11888 @chapter Reliability and Security
11889
11890 The @command{tar} command reads and writes files as any other
11891 application does, and is subject to the usual caveats about
11892 reliability and security. This section contains some commonsense
11893 advice on the topic.
11894
11895 @menu
11896 * Reliability::
11897 * Security::
11898 @end menu
11899
11900 @node Reliability
11901 @section Reliability
11902
11903 Ideally, when @command{tar} is creating an archive, it reads from a
11904 file system that is not being modified, and encounters no errors or
11905 inconsistencies while reading and writing. If this is the case, the
11906 archive should faithfully reflect what was read. Similarly, when
11907 extracting from an archive, ideally @command{tar} ideally encounters
11908 no errors and the extracted files faithfully reflect what was in the
11909 archive.
11910
11911 However, when reading or writing real-world file systems, several
11912 things can go wrong; these include permissions problems, corruption of
11913 data, and race conditions.
11914
11915 @menu
11916 * Permissions problems::
11917 * Data corruption and repair::
11918 * Race conditions::
11919 @end menu
11920
11921 @node Permissions problems
11922 @subsection Permissions Problems
11923
11924 If @command{tar} encounters errors while reading or writing files, it
11925 normally reports an error and exits with nonzero status. The work it
11926 does may therefore be incomplete. For example, when creating an
11927 archive, if @command{tar} cannot read a file then it cannot copy the
11928 file into the archive.
11929
11930 @node Data corruption and repair
11931 @subsection Data Corruption and Repair
11932
11933 If an archive becomes corrupted by an I/O error, this may corrupt the
11934 data in an extracted file. Worse, it may corrupt the file's metadata,
11935 which may cause later parts of the archive to become misinterpreted.
11936 An tar-format archive contains a checksum that most likely will detect
11937 errors in the metadata, but it will not detect errors in the data.
11938
11939 If data corruption is a concern, you can compute and check your own
11940 checksums of an archive by using other programs, such as
11941 @command{cksum}.
11942
11943 When attempting to recover from a read error or data corruption in an
11944 archive, you may need to skip past the questionable data and read the
11945 rest of the archive. This requires some expertise in the archive
11946 format and in other software tools.
11947
11948 @node Race conditions
11949 @subsection Race conditions
11950
11951 If some other process is modifying the file system while @command{tar}
11952 is reading or writing files, the result may well be inconsistent due
11953 to race conditions. For example, if another process creates some
11954 files in a directory while @command{tar} is creating an archive
11955 containing the directory's files, @command{tar} may see some of the
11956 files but not others, or it may see a file that is in the process of
11957 being created. The resulting archive may not be a snapshot of the
11958 file system at any point in time. If an application such as a
11959 database system depends on an accurate snapshot, restoring from the
11960 @command{tar} archive of a live file system may therefore break that
11961 consistency and may break the application. The simplest way to avoid
11962 the consistency issues is to avoid making other changes to the file
11963 system while tar is reading it or writing it.
11964
11965 When creating an archive, several options are available to avoid race
11966 conditions. Some hosts have a way of snapshotting a file system, or
11967 of temporarily suspending all changes to a file system, by (say)
11968 suspending the only virtual machine that can modify a file system; if
11969 you use these facilities and have @command{tar -c} read from a
11970 snapshot when creating an archive, you can avoid inconsistency
11971 problems. More drastically, before starting @command{tar} you could
11972 suspend or shut down all processes other than @command{tar} that have
11973 access to the file system, or you could unmount the file system and
11974 then mount it read-only.
11975
11976 When extracting from an archive, one approach to avoid race conditions
11977 is to create a directory that no other process can write to, and
11978 extract into that.
11979
11980 @node Security
11981 @section Security
11982
11983 In some cases @command{tar} may be used in an adversarial situation,
11984 where an untrusted user is attempting to gain information about or
11985 modify otherwise-inaccessible files. Dealing with untrusted data
11986 (that is, data generated by an untrusted user) typically requires
11987 extra care, because even the smallest mistake in the use of
11988 @command{tar} is more likely to be exploited by an adversary than by a
11989 race condition.
11990
11991 @menu
11992 * Privacy::
11993 * Integrity::
11994 * Live untrusted data::
11995 * Security rules of thumb::
11996 @end menu
11997
11998 @node Privacy
11999 @subsection Privacy
12000
12001 Standard privacy concerns apply when using @command{tar}. For
12002 example, suppose you are archiving your home directory into a file
12003 @file{/archive/myhome.tar}. Any secret information in your home
12004 directory, such as your SSH secret keys, are copied faithfully into
12005 the archive. Therefore, if your home directory contains any file that
12006 should not be read by some other user, the archive itself should be
12007 not be readable by that user. And even if the archive's data are
12008 inaccessible to untrusted users, its metadata (such as size or
12009 last-modified date) may reveal some information about your home
12010 directory; if the metadata are intended to be private, the archive's
12011 parent directory should also be inaccessible to untrusted users.
12012
12013 One precaution is to create @file{/archive} so that it is not
12014 accessible to any user, unless that user also has permission to access
12015 all the files in your home directory.
12016
12017 Similarly, when extracting from an archive, take care that the
12018 permissions of the extracted files are not more generous than what you
12019 want. Even if the archive itself is readable only to you, files
12020 extracted from it have their own permissions that may differ.
12021
12022 @node Integrity
12023 @subsection Integrity
12024
12025 When creating archives, take care that they are not writable by a
12026 untrusted user; otherwise, that user could modify the archive, and
12027 when you later extract from the archive you will get incorrect data.
12028
12029 When @command{tar} extracts from an archive, by default it writes into
12030 files relative to the working directory. If the archive was generated
12031 by an untrusted user, that user therefore can write into any file
12032 under the working directory. If the working directory contains a
12033 symbolic link to another directory, the untrusted user can also write
12034 into any file under the referenced directory. When extracting from an
12035 untrusted archive, it is therefore good practice to create an empty
12036 directory and run @command{tar} in that directory.
12037
12038 When extracting from two or more untrusted archives, each one should
12039 be extracted independently, into different empty directories.
12040 Otherwise, the first archive could create a symbolic link into an area
12041 outside the working directory, and the second one could follow the
12042 link and overwrite data that is not under the working directory. For
12043 example, when restoring from a series of incremental dumps, the
12044 archives should have been created by a trusted process, as otherwise
12045 the incremental restores might alter data outside the working
12046 directory.
12047
12048 If you use the @option{--absolute-names} (@option{-P}) option when
12049 extracting, @command{tar} respects any file names in the archive, even
12050 file names that begin with @file{/} or contain @file{..}. As this
12051 lets the archive overwrite any file in your system that you can write,
12052 the @option{--absolute-names} (@option{-P}) option should be used only
12053 for trusted archives.
12054
12055 Conversely, with the @option{--keep-old-files} (@option{-k}) and
12056 @option{--skip-old-files} options, @command{tar} refuses to replace
12057 existing files when extracting. The difference between the two
12058 options is that the former treats existing files as errors whereas the
12059 latter just silently ignores them.
12060
12061 Finally, with the @option{--no-overwrite-dir} option, @command{tar}
12062 refuses to replace the permissions or ownership of already-existing
12063 directories. These options may help when extracting from untrusted
12064 archives.
12065
12066 @node Live untrusted data
12067 @subsection Dealing with Live Untrusted Data
12068
12069 Extra care is required when creating from or extracting into a file
12070 system that is accessible to untrusted users. For example, superusers
12071 who invoke @command{tar} must be wary about its actions being hijacked
12072 by an adversary who is reading or writing the file system at the same
12073 time that @command{tar} is operating.
12074
12075 When creating an archive from a live file system, @command{tar} is
12076 vulnerable to denial-of-service attacks. For example, an adversarial
12077 user could create the illusion of an indefinitely-deep directory
12078 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
12079 @command{tar}, or the illusion of an indefinitely-long file by
12080 creating a sparse file but arranging for blocks to be allocated just
12081 before @command{tar} reads them. There is no easy way for
12082 @command{tar} to distinguish these scenarios from legitimate uses, so
12083 you may need to monitor @command{tar}, just as you'd need to monitor
12084 any other system service, to detect such attacks.
12085
12086 While a superuser is extracting from an archive into a live file
12087 system, an untrusted user might replace a directory with a symbolic
12088 link, in hopes that @command{tar} will follow the symbolic link and
12089 extract data into files that the untrusted user does not have access
12090 to. Even if the archive was generated by the superuser, it may
12091 contain a file such as @file{d/etc/passwd} that the untrusted user
12092 earlier created in order to break in; if the untrusted user replaces
12093 the directory @file{d/etc} with a symbolic link to @file{/etc} while
12094 @command{tar} is running, @command{tar} will overwrite
12095 @file{/etc/passwd}. This attack can be prevented by extracting into a
12096 directory that is inaccessible to untrusted users.
12097
12098 Similar attacks via symbolic links are also possible when creating an
12099 archive, if the untrusted user can modify an ancestor of a top-level
12100 argument of @command{tar}. For example, an untrusted user that can
12101 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
12102 - /home/eve/Documents/yesterday} by replacing
12103 @file{/home/eve/Documents} with a symbolic link to some other
12104 location. Attacks like these can be prevented by making sure that
12105 untrusted users cannot modify any files that are top-level arguments
12106 to @command{tar}, or any ancestor directories of these files.
12107
12108 @node Security rules of thumb
12109 @subsection Security Rules of Thumb
12110
12111 This section briefly summarizes rules of thumb for avoiding security
12112 pitfalls.
12113
12114 @itemize @bullet
12115
12116 @item
12117 Protect archives at least as much as you protect any of the files
12118 being archived.
12119
12120 @item
12121 Extract from an untrusted archive only into an otherwise-empty
12122 directory. This directory and its parent should be accessible only to
12123 trusted users. For example:
12124
12125 @example
12126 @group
12127 $ @kbd{chmod go-rwx .}
12128 $ @kbd{mkdir -m go-rwx dir}
12129 $ @kbd{cd dir}
12130 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12131 @end group
12132 @end example
12133
12134 As a corollary, do not do an incremental restore from an untrusted archive.
12135
12136 @item
12137 Do not let untrusted users access files extracted from untrusted
12138 archives without checking first for problems such as setuid programs.
12139
12140 @item
12141 Do not let untrusted users modify directories that are ancestors of
12142 top-level arguments of @command{tar}. For example, while you are
12143 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12144 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12145
12146 @item
12147 Pay attention to the diagnostics and exit status of @command{tar}.
12148
12149 @item
12150 When archiving live file systems, monitor running instances of
12151 @command{tar} to detect denial-of-service attacks.
12152
12153 @item
12154 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12155 @option{--dereference} (@option{-h}), @option{--overwrite},
12156 @option{--recursive-unlink}, and @option{--remove-files} unless you
12157 understand their security implications.
12158
12159 @end itemize
12160
12161 @node Changes
12162 @appendix Changes
12163
12164 This appendix lists some important user-visible changes between
12165 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12166 version of this document is available at
12167 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12168 @GNUTAR{} documentation page}.
12169
12170 @table @asis
12171 @item Use of globbing patterns when listing and extracting.
12172
12173 Previous versions of GNU tar assumed shell-style globbing when
12174 extracting from or listing an archive. For example:
12175
12176 @smallexample
12177 $ @kbd{tar xf foo.tar '*.c'}
12178 @end smallexample
12179
12180 would extract all files whose names end in @samp{.c}. This behavior
12181 was not documented and was incompatible with traditional tar
12182 implementations. Therefore, starting from version 1.15.91, GNU tar
12183 no longer uses globbing by default. For example, the above invocation
12184 is now interpreted as a request to extract from the archive the file
12185 named @file{*.c}.
12186
12187 To facilitate transition to the new behavior for those users who got
12188 used to the previous incorrect one, @command{tar} will print a warning
12189 if it finds out that a requested member was not found in the archive
12190 and its name looks like a globbing pattern. For example:
12191
12192 @smallexample
12193 $ @kbd{tar xf foo.tar '*.c'}
12194 tar: Pattern matching characters used in file names. Please,
12195 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12196 tar: suppress this warning.
12197 tar: *.c: Not found in archive
12198 tar: Error exit delayed from previous errors
12199 @end smallexample
12200
12201 To treat member names as globbing patterns, use the @option{--wildcards} option.
12202 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12203 add this option to your @env{TAR_OPTIONS} variable.
12204
12205 @xref{wildcards}, for the detailed discussion of the use of globbing
12206 patterns by @GNUTAR{}.
12207
12208 @item Use of short option @option{-o}.
12209
12210 Earlier versions of @GNUTAR{} understood @option{-o} command line
12211 option as a synonym for @option{--old-archive}.
12212
12213 @GNUTAR{} starting from version 1.13.90 understands this option as
12214 a synonym for @option{--no-same-owner}. This is compatible with
12215 UNIX98 @command{tar} implementations.
12216
12217 However, to facilitate transition, @option{-o} option retains its
12218 old semantics when it is used with one of archive-creation commands.
12219 Users are encouraged to use @option{--format=oldgnu} instead.
12220
12221 It is especially important, since versions of @acronym{GNU} Automake
12222 up to and including 1.8.4 invoke tar with this option to produce
12223 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
12224 of this issue and its implications.
12225
12226 @xref{Options, tar-formats, Changing Automake's Behavior,
12227 automake, GNU Automake}, for a description on how to use various
12228 archive formats with @command{automake}.
12229
12230 Future versions of @GNUTAR{} will understand @option{-o} only as a
12231 synonym for @option{--no-same-owner}.
12232
12233 @item Use of short option @option{-l}
12234
12235 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12236 synonym for @option{--one-file-system}. Since such usage contradicted
12237 to UNIX98 specification and harmed compatibility with other
12238 implementations, it was declared deprecated in version 1.14. However,
12239 to facilitate transition to its new semantics, it was supported by
12240 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
12241 variant of @option{--check-links} was introduced in version 1.15.91.
12242
12243 @item Use of options @option{--portability} and @option{--old-archive}
12244
12245 These options are deprecated. Please use @option{--format=v7} instead.
12246
12247 @item Use of option @option{--posix}
12248
12249 This option is deprecated. Please use @option{--format=posix} instead.
12250 @end table
12251
12252 @node Configuring Help Summary
12253 @appendix Configuring Help Summary
12254
12255 Running @kbd{tar --help} displays the short @command{tar} option
12256 summary (@pxref{help}). This summary is organized by @dfn{groups} of
12257 semantically close options. The options within each group are printed
12258 in the following order: a short option, eventually followed by a list
12259 of corresponding long option names, followed by a short description of
12260 the option. For example, here is an excerpt from the actual @kbd{tar
12261 --help} output:
12262
12263 @verbatim
12264 Main operation mode:
12265
12266 -A, --catenate, --concatenate append tar files to an archive
12267 -c, --create create a new archive
12268 -d, --diff, --compare find differences between archive and
12269 file system
12270 --delete delete from the archive
12271 @end verbatim
12272
12273 @vrindex ARGP_HELP_FMT, environment variable
12274 The exact visual representation of the help output is configurable via
12275 @env{ARGP_HELP_FMT} environment variable. The value of this variable
12276 is a comma-separated list of @dfn{format variable} assignments. There
12277 are two kinds of format variables. An @dfn{offset variable} keeps the
12278 offset of some part of help output text from the leftmost column on
12279 the screen. A @dfn{boolean} variable is a flag that toggles some
12280 output feature on or off. Depending on the type of the corresponding
12281 variable, there are two kinds of assignments:
12282
12283 @table @asis
12284 @item Offset assignment
12285
12286 The assignment to an offset variable has the following syntax:
12287
12288 @smallexample
12289 @var{variable}=@var{value}
12290 @end smallexample
12291
12292 @noindent
12293 where @var{variable} is the variable name, and @var{value} is a
12294 numeric value to be assigned to the variable.
12295
12296 @item Boolean assignment
12297
12298 To assign @code{true} value to a variable, simply put this variable name. To
12299 assign @code{false} value, prefix the variable name with @samp{no-}. For
12300 example:
12301
12302 @smallexample
12303 @group
12304 # Assign @code{true} value:
12305 dup-args
12306 # Assign @code{false} value:
12307 no-dup-args
12308 @end group
12309 @end smallexample
12310 @end table
12311
12312 Following variables are declared:
12313
12314 @deftypevr {Help Output} boolean dup-args
12315 If true, arguments for an option are shown with both short and long
12316 options, even when a given option has both forms, for example:
12317
12318 @smallexample
12319 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
12320 @end smallexample
12321
12322 If false, then if an option has both short and long forms, the
12323 argument is only shown with the long one, for example:
12324
12325 @smallexample
12326 -f, --file=ARCHIVE use archive file or device ARCHIVE
12327 @end smallexample
12328
12329 @noindent
12330 and a message indicating that the argument is applicable to both
12331 forms is printed below the options. This message can be disabled
12332 using @code{dup-args-note} (see below).
12333
12334 The default is false.
12335 @end deftypevr
12336
12337 @deftypevr {Help Output} boolean dup-args-note
12338 If this variable is true, which is the default, the following notice
12339 is displayed at the end of the help output:
12340
12341 @quotation
12342 Mandatory or optional arguments to long options are also mandatory or
12343 optional for any corresponding short options.
12344 @end quotation
12345
12346 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
12347 variables @code{dup-args} or @code{dup-args-note} should be set.
12348 @end deftypevr
12349
12350 @deftypevr {Help Output} offset short-opt-col
12351 Column in which short options start. Default is 2.
12352
12353 @smallexample
12354 @group
12355 $ @kbd{tar --help|grep ARCHIVE}
12356 -f, --file=ARCHIVE use archive file or device ARCHIVE
12357 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
12358 -f, --file=ARCHIVE use archive file or device ARCHIVE
12359 @end group
12360 @end smallexample
12361 @end deftypevr
12362
12363 @deftypevr {Help Output} offset long-opt-col
12364 Column in which long options start. Default is 6. For example:
12365
12366 @smallexample
12367 @group
12368 $ @kbd{tar --help|grep ARCHIVE}
12369 -f, --file=ARCHIVE use archive file or device ARCHIVE
12370 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
12371 -f, --file=ARCHIVE use archive file or device ARCHIVE
12372 @end group
12373 @end smallexample
12374 @end deftypevr
12375
12376 @deftypevr {Help Output} offset doc-opt-col
12377 Column in which @dfn{doc options} start. A doc option isn't actually
12378 an option, but rather an arbitrary piece of documentation that is
12379 displayed in much the same manner as the options. For example, in
12380 the description of @option{--format} option:
12381
12382 @smallexample
12383 @group
12384 -H, --format=FORMAT create archive of the given format.
12385
12386 FORMAT is one of the following:
12387
12388 gnu GNU tar 1.13.x format
12389 oldgnu GNU format as per tar <= 1.12
12390 pax POSIX 1003.1-2001 (pax) format
12391 posix same as pax
12392 ustar POSIX 1003.1-1988 (ustar) format
12393 v7 old V7 tar format
12394 @end group
12395 @end smallexample
12396
12397 @noindent
12398 the format names are doc options. Thus, if you set
12399 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
12400 will look as follows:
12401
12402 @smallexample
12403 @group
12404 -H, --format=FORMAT create archive of the given format.
12405
12406 FORMAT is one of the following:
12407
12408 gnu GNU tar 1.13.x format
12409 oldgnu GNU format as per tar <= 1.12
12410 pax POSIX 1003.1-2001 (pax) format
12411 posix same as pax
12412 ustar POSIX 1003.1-1988 (ustar) format
12413 v7 old V7 tar format
12414 @end group
12415 @end smallexample
12416 @end deftypevr
12417
12418 @deftypevr {Help Output} offset opt-doc-col
12419 Column in which option description starts. Default is 29.
12420
12421 @smallexample
12422 @group
12423 $ @kbd{tar --help|grep ARCHIVE}
12424 -f, --file=ARCHIVE use archive file or device ARCHIVE
12425 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
12426 -f, --file=ARCHIVE use archive file or device ARCHIVE
12427 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
12428 -f, --file=ARCHIVE
12429 use archive file or device ARCHIVE
12430 @end group
12431 @end smallexample
12432
12433 @noindent
12434 Notice, that the description starts on a separate line if
12435 @code{opt-doc-col} value is too small.
12436 @end deftypevr
12437
12438 @deftypevr {Help Output} offset header-col
12439 Column in which @dfn{group headers} are printed. A group header is a
12440 descriptive text preceding an option group. For example, in the
12441 following text:
12442
12443 @verbatim
12444 Main operation mode:
12445
12446 -A, --catenate, --concatenate append tar files to
12447 an archive
12448 -c, --create create a new archive
12449 @end verbatim
12450 @noindent
12451 @samp{Main operation mode:} is the group header.
12452
12453 The default value is 1.
12454 @end deftypevr
12455
12456 @deftypevr {Help Output} offset usage-indent
12457 Indentation of wrapped usage lines. Affects @option{--usage}
12458 output. Default is 12.
12459 @end deftypevr
12460
12461 @deftypevr {Help Output} offset rmargin
12462 Right margin of the text output. Used for wrapping.
12463 @end deftypevr
12464
12465 @node Fixing Snapshot Files
12466 @appendix Fixing Snapshot Files
12467 @include tar-snapshot-edit.texi
12468
12469 @node Tar Internals
12470 @appendix Tar Internals
12471 @include intern.texi
12472
12473 @node Genfile
12474 @appendix Genfile
12475 @include genfile.texi
12476
12477 @node Free Software Needs Free Documentation
12478 @appendix Free Software Needs Free Documentation
12479 @include freemanuals.texi
12480
12481 @node GNU Free Documentation License
12482 @appendix GNU Free Documentation License
12483
12484 @include fdl.texi
12485
12486 @node Index of Command Line Options
12487 @appendix Index of Command Line Options
12488
12489 This appendix contains an index of all @GNUTAR{} long command line
12490 options. The options are listed without the preceding double-dash.
12491 For a cross-reference of short command line options, see
12492 @ref{Short Option Summary}.
12493
12494 @printindex op
12495
12496 @node Index
12497 @appendix Index
12498
12499 @printindex cp
12500
12501 @summarycontents
12502 @contents
12503 @bye
12504
12505 @c Local variables:
12506 @c texinfo-column-for-description: 32
12507 @c End:
This page took 0.593019 seconds and 4 git commands to generate.