]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Document --hard-dereference and --checkpoint-action options. Improve documentation...
[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
25 @c Put everything in one index (arbitrarily chosen to be the concept index).
26 @syncodeindex fn cp
27 @syncodeindex ky cp
28 @syncodeindex pg cp
29 @syncodeindex vr cp
30
31 @copying
32
33 This manual is for @acronym{GNU} @command{tar} (version
34 @value{VERSION}, @value{UPDATED}), which creates and extracts files
35 from archives.
36
37 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
38 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
39
40 @quotation
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
47
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
51 @end quotation
52 @end copying
53
54 @dircategory Archiving
55 @direntry
56 * Tar: (tar). Making tape (or disk) archives.
57 @end direntry
58
59 @dircategory Individual utilities
60 @direntry
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
62 @end direntry
63
64 @shorttitlepage @acronym{GNU} @command{tar}
65
66 @titlepage
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
70
71 @page
72 @vskip 0pt plus 1filll
73 @insertcopying
74 @end titlepage
75
76 @ifnottex
77 @node Top
78 @top @acronym{GNU} tar: an archiver tool
79
80 @insertcopying
81
82 @cindex file archival
83 @cindex archiving files
84
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
87 @end ifnottex
88
89 @c The master menu goes here.
90 @c
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
94 @c
95 @c make master-menu
96
97 @menu
98 * Introduction::
99 * Tutorial::
100 * tar invocation::
101 * operations::
102 * Backups::
103 * Choosing::
104 * Date input formats::
105 * Formats::
106 * Media::
107
108 Appendices
109
110 * Changes::
111 * Configuring Help Summary::
112 * Fixing Snapshot Files::
113 * Tar Internals::
114 * Genfile::
115 * Free Software Needs Free Documentation::
116 * Copying This Manual::
117 * Index of Command Line Options::
118 * Index::
119
120 @detailmenu
121 --- The Detailed Node Listing ---
122
123 Introduction
124
125 * Book Contents:: What this Book Contains
126 * Definitions:: Some Definitions
127 * What tar Does:: What @command{tar} Does
128 * Naming tar Archives:: How @command{tar} Archives are Named
129 * Authors:: @GNUTAR{} Authors
130 * Reports:: Reporting bugs or suggestions
131
132 Tutorial Introduction to @command{tar}
133
134 * assumptions::
135 * stylistic conventions::
136 * basic tar options:: Basic @command{tar} Operations and Options
137 * frequent operations::
138 * Two Frequent Options::
139 * create:: How to Create Archives
140 * list:: How to List Archives
141 * extract:: How to Extract Members from an Archive
142 * going further::
143
144 Two Frequently Used Options
145
146 * file tutorial::
147 * verbose tutorial::
148 * help tutorial::
149
150 How to Create Archives
151
152 * prepare for examples::
153 * Creating the archive::
154 * create verbose::
155 * short create::
156 * create dir::
157
158 How to List Archives
159
160 * list dir::
161
162 How to Extract Members from an Archive
163
164 * extracting archives::
165 * extracting files::
166 * extract dir::
167 * extracting untrusted archives::
168 * failing commands::
169
170 Invoking @GNUTAR{}
171
172 * Synopsis::
173 * using tar options::
174 * Styles::
175 * All Options::
176 * help::
177 * defaults::
178 * verbose::
179 * checkpoints::
180 * interactive::
181
182 The Three Option Styles
183
184 * Long Options:: Long Option Style
185 * Short Options:: Short Option Style
186 * Old Options:: Old Option Style
187 * Mixing:: Mixing Option Styles
188
189 All @command{tar} Options
190
191 * Operation Summary::
192 * Option Summary::
193 * Short Option Summary::
194
195 @GNUTAR{} Operations
196
197 * Basic tar::
198 * Advanced tar::
199 * create options::
200 * extract options::
201 * backup::
202 * Applications::
203 * looking ahead::
204
205 Advanced @GNUTAR{} Operations
206
207 * Operations::
208 * append::
209 * update::
210 * concatenate::
211 * delete::
212 * compare::
213
214 How to Add Files to Existing Archives: @option{--append}
215
216 * appending files:: Appending Files to an Archive
217 * multiple::
218
219 Updating an Archive
220
221 * how to update::
222
223 Options Used by @option{--create}
224
225 * override:: Overriding File Metadata.
226 * Ignore Failed Read::
227
228 Options Used by @option{--extract}
229
230 * Reading:: Options to Help Read Archives
231 * Writing:: Changing How @command{tar} Writes Files
232 * Scarce:: Coping with Scarce Resources
233
234 Options to Help Read Archives
235
236 * read full records::
237 * Ignore Zeros::
238
239 Changing How @command{tar} Writes Files
240
241 * Dealing with Old Files::
242 * Overwrite Old Files::
243 * Keep Old Files::
244 * Keep Newer Files::
245 * Unlink First::
246 * Recursive Unlink::
247 * Data Modification Times::
248 * Setting Access Permissions::
249 * Directory Modification Times and Permissions::
250 * Writing to Standard Output::
251 * Writing to an External Program::
252 * remove files::
253
254 Coping with Scarce Resources
255
256 * Starting File::
257 * Same Order::
258
259 Performing Backups and Restoring Files
260
261 * Full Dumps:: Using @command{tar} to Perform Full Dumps
262 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
263 * Backup Levels:: Levels of Backups
264 * Backup Parameters:: Setting Parameters for Backups and Restoration
265 * Scripted Backups:: Using the Backup Scripts
266 * Scripted Restoration:: Using the Restore Script
267
268 Setting Parameters for Backups and Restoration
269
270 * General-Purpose Variables::
271 * Magnetic Tape Control::
272 * User Hooks::
273 * backup-specs example:: An Example Text of @file{Backup-specs}
274
275 Choosing Files and Names for @command{tar}
276
277 * file:: Choosing the Archive's Name
278 * Selecting Archive Members::
279 * files:: Reading Names from a File
280 * exclude:: Excluding Some Files
281 * wildcards:: Wildcards Patterns and Matching
282 * quoting styles:: Ways of Quoting Special Characters in Names
283 * transform:: Modifying File and Member Names
284 * after:: Operating Only on New Files
285 * recurse:: Descending into Directories
286 * one:: Crossing File System Boundaries
287
288 Reading Names from a File
289
290 * nul::
291
292 Excluding Some Files
293
294 * problems with exclude::
295
296 Wildcards Patterns and Matching
297
298 * controlling pattern-matching::
299
300 Crossing File System Boundaries
301
302 * directory:: Changing Directory
303 * absolute:: Absolute File Names
304
305 Date input formats
306
307 * General date syntax:: Common rules.
308 * Calendar date items:: 19 Dec 1994.
309 * Time of day items:: 9:20pm.
310 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
311 * Day of week items:: Monday and others.
312 * Relative items in date strings:: next tuesday, 2 years ago.
313 * Pure numbers in date strings:: 19931219, 1440.
314 * Seconds since the Epoch:: @@1078100502.
315 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
316 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
317
318 Controlling the Archive Format
319
320 * Compression:: Using Less Space through Compression
321 * Attributes:: Handling File Attributes
322 * Portability:: Making @command{tar} Archives More Portable
323 * cpio:: Comparison of @command{tar} and @command{cpio}
324
325 Using Less Space through Compression
326
327 * gzip:: Creating and Reading Compressed Archives
328 * sparse:: Archiving Sparse Files
329
330 Making @command{tar} Archives More Portable
331
332 * Portable Names:: Portable Names
333 * dereference:: Symbolic Links
334 * hard links:: Hard Links
335 * old:: Old V7 Archives
336 * ustar:: Ustar Archives
337 * gnu:: GNU and old GNU format archives.
338 * posix:: @acronym{POSIX} archives
339 * Checksumming:: Checksumming Problems
340 * Large or Negative Values:: Large files, negative time stamps, etc.
341 * Other Tars:: How to Extract GNU-Specific Data Using
342 Other @command{tar} Implementations
343
344 @GNUTAR{} and @acronym{POSIX} @command{tar}
345
346 * PAX keywords:: Controlling Extended Header Keywords.
347
348 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
349
350 * Split Recovery:: Members Split Between Volumes
351 * Sparse Recovery:: Sparse Members
352
353 Tapes and Other Archive Media
354
355 * Device:: Device selection and switching
356 * Remote Tape Server::
357 * Common Problems and Solutions::
358 * Blocking:: Blocking
359 * Many:: Many archives on one tape
360 * Using Multiple Tapes:: Using Multiple Tapes
361 * label:: Including a Label in the Archive
362 * verify::
363 * Write Protection::
364
365 Blocking
366
367 * Format Variations:: Format Variations
368 * Blocking Factor:: The Blocking Factor of an Archive
369
370 Many Archives on One Tape
371
372 * Tape Positioning:: Tape Positions and Tape Marks
373 * mt:: The @command{mt} Utility
374
375 Using Multiple Tapes
376
377 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
378 * Tape Files:: Tape Files
379 * Tarcat:: Concatenate Volumes into a Single Archive
380
381
382 Tar Internals
383
384 * Standard:: Basic Tar Format
385 * Extensions:: @acronym{GNU} Extensions to the Archive Format
386 * Sparse Formats:: Storing Sparse Files
387 * Snapshot Files::
388 * Dumpdir::
389
390 Storing Sparse Files
391
392 * Old GNU Format::
393 * PAX 0:: PAX Format, Versions 0.0 and 0.1
394 * PAX 1:: PAX Format, Version 1.0
395
396 Genfile
397
398 * Generate Mode:: File Generation Mode.
399 * Status Mode:: File Status Mode.
400 * Exec Mode:: Synchronous Execution mode.
401
402 Copying This Manual
403
404 * GNU Free Documentation License:: License for copying this manual
405
406 @end detailmenu
407 @end menu
408
409 @node Introduction
410 @chapter Introduction
411
412 @GNUTAR{} creates
413 and manipulates @dfn{archives} which are actually collections of
414 many other files; the program provides users with an organized and
415 systematic method for controlling a large amount of data.
416 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
417 archives need not (and these days, typically do not) reside on tapes.
418
419 @menu
420 * Book Contents:: What this Book Contains
421 * Definitions:: Some Definitions
422 * What tar Does:: What @command{tar} Does
423 * Naming tar Archives:: How @command{tar} Archives are Named
424 * Authors:: @GNUTAR{} Authors
425 * Reports:: Reporting bugs or suggestions
426 @end menu
427
428 @node Book Contents
429 @section What this Book Contains
430
431 The first part of this chapter introduces you to various terms that will
432 recur throughout the book. It also tells you who has worked on @GNUTAR{}
433 and its documentation, and where you should send bug reports
434 or comments.
435
436 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
437 gentle introduction for people who are new to using @command{tar}. It is
438 meant to be self contained, not requiring any reading from subsequent
439 chapters to make sense. It moves from topic to topic in a logical,
440 progressive order, building on information already explained.
441
442 Although the tutorial is paced and structured to allow beginners to
443 learn how to use @command{tar}, it is not intended solely for beginners.
444 The tutorial explains how to use the three most frequently used
445 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
446 two frequently used options (@samp{file} and @samp{verbose}). The other
447 chapters do not refer to the tutorial frequently; however, if a section
448 discusses something which is a complex variant of a basic concept, there
449 may be a cross reference to that basic concept. (The entire book,
450 including the tutorial, assumes that the reader understands some basic
451 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
452
453 The third chapter presents the remaining five operations, and
454 information about using @command{tar} options and option syntax.
455
456 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
457 than the reality. should think about whether this makes sense to say
458 here, or not.} The other chapters are meant to be used as a
459 reference. Each chapter presents everything that needs to be said
460 about a specific topic.
461
462 One of the chapters (@pxref{Date input formats}) exists in its
463 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
464 In addition, one section of this manual (@pxref{Standard}) contains a
465 big quote which is taken directly from @command{tar} sources.
466
467 In general, we give both long and short (abbreviated) option names
468 at least once in each section where the relevant option is covered, so
469 that novice readers will become familiar with both styles. (A few
470 options have no short versions, and the relevant sections will
471 indicate this.)
472
473 @node Definitions
474 @section Some Definitions
475
476 @cindex archive
477 @cindex tar archive
478 The @command{tar} program is used to create and manipulate @command{tar}
479 archives. An @dfn{archive} is a single file which contains the contents
480 of many files, while still identifying the names of the files, their
481 owner(s), and so forth. (In addition, archives record access
482 permissions, user and group, size in bytes, and data modification time.
483 Some archives also record the file names in each archived directory, as
484 well as other file and directory information.) You can use @command{tar}
485 to @dfn{create} a new archive in a specified directory.
486
487 @cindex member
488 @cindex archive member
489 @cindex file name
490 @cindex member name
491 The files inside an archive are called @dfn{members}. Within this
492 manual, we use the term @dfn{file} to refer only to files accessible in
493 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
494 @dfn{member} to refer only to the members of an archive. Similarly, a
495 @dfn{file name} is the name of a file, as it resides in the file system,
496 and a @dfn{member name} is the name of an archive member within the
497 archive.
498
499 @cindex extraction
500 @cindex unpacking
501 The term @dfn{extraction} refers to the process of copying an archive
502 member (or multiple members) into a file in the file system. Extracting
503 all the members of an archive is often called @dfn{extracting the
504 archive}. The term @dfn{unpack} can also be used to refer to the
505 extraction of many or all the members of an archive. Extracting an
506 archive does not destroy the archive's structure, just as creating an
507 archive does not destroy the copies of the files that exist outside of
508 the archive. You may also @dfn{list} the members in a given archive
509 (this is often thought of as ``printing'' them to the standard output,
510 or the command line), or @dfn{append} members to a pre-existing archive.
511 All of these operations can be performed using @command{tar}.
512
513 @node What tar Does
514 @section What @command{tar} Does
515
516 @cindex tar
517 The @command{tar} program provides the ability to create @command{tar}
518 archives, as well as various other kinds of manipulation. For example,
519 you can use @command{tar} on previously created archives to extract files,
520 to store additional files, or to update or list files which were already
521 stored.
522
523 Initially, @command{tar} archives were used to store files conveniently on
524 magnetic tape. The name @command{tar} comes from this use; it stands for
525 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
526 direct its output to available devices, files, or other programs (using
527 pipes). @command{tar} may even access remote devices or files (as archives).
528
529 You can use @command{tar} archives in many ways. We want to stress a few
530 of them: storage, backup, and transportation.
531
532 @FIXME{the following table entries need a bit of work.}
533 @table @asis
534 @item Storage
535 Often, @command{tar} archives are used to store related files for
536 convenient file transfer over a network. For example, the
537 @acronym{GNU} Project distributes its software bundled into
538 @command{tar} archives, so that all the files relating to a particular
539 program (or set of related programs) can be transferred as a single
540 unit.
541
542 A magnetic tape can store several files in sequence. However, the tape
543 has no names for these files; it only knows their relative position on
544 the tape. One way to store several files on one tape and retain their
545 names is by creating a @command{tar} archive. Even when the basic transfer
546 mechanism can keep track of names, as FTP can, the nuisance of handling
547 multiple files, directories, and multiple links makes @command{tar}
548 archives useful.
549
550 Archive files are also used for long-term storage. You can think of
551 this as transportation from the present into the future. (It is a
552 science-fiction idiom that you can move through time as well as in
553 space; the idea here is that @command{tar} can be used to move archives in
554 all dimensions, even time!)
555
556 @item Backup
557 Because the archive created by @command{tar} is capable of preserving
558 file information and directory structure, @command{tar} is commonly
559 used for performing full and incremental backups of disks. A backup
560 puts a collection of files (possibly pertaining to many users and
561 projects) together on a disk or a tape. This guards against
562 accidental destruction of the information in those files.
563 @GNUTAR{} has special features that allow it to be
564 used to make incremental and full dumps of all the files in a
565 file system.
566
567 @item Transportation
568 You can create an archive on one system, transfer it to another system,
569 and extract the contents there. This allows you to transport a group of
570 files from one system to another.
571 @end table
572
573 @node Naming tar Archives
574 @section How @command{tar} Archives are Named
575
576 Conventionally, @command{tar} archives are given names ending with
577 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
578 but this manual follows that convention in order to accustom readers to
579 it and to make examples more clear.
580
581 @cindex tar file
582 @cindex entry
583 @cindex tar entry
584 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
585 archive members as ``files'' or ``entries''. For people familiar with
586 the operation of @command{tar}, this causes no difficulty. However, in
587 this manual, we consistently refer to ``archives'' and ``archive
588 members'' to make learning to use @command{tar} easier for novice users.
589
590 @node Authors
591 @section @GNUTAR{} Authors
592
593 @GNUTAR{} was originally written by John Gilmore,
594 and modified by many people. The @acronym{GNU} enhancements were
595 written by Jay Fenlason, then Joy Kendall, and the whole package has
596 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
597 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
598 numerous and kind users.
599
600 We wish to stress that @command{tar} is a collective work, and owes much to
601 all those people who reported problems, offered solutions and other
602 insights, or shared their thoughts and suggestions. An impressive, yet
603 partial list of those contributors can be found in the @file{THANKS}
604 file from the @GNUTAR{} distribution.
605
606 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
607 sure i want to spell out the history in this detail, at least not for
608 the printed book. i'm just not sure it needs to be said this way.
609 i'll think about it.}
610
611 @FIXME{History is more important, and surely more interesting, than
612 actual names. Quoting names without history would be meaningless. FP}
613
614 Jay Fenlason put together a draft of a @GNUTAR{}
615 manual, borrowing notes from the original man page from John Gilmore.
616 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
617 Gorin worked on a tutorial and manual for @GNUTAR{}.
618 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
619 taking information from all these sources and merging them. Melissa
620 Weisshaus finally edited and redesigned the book to create version
621 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
622 by the current maintainer, Sergey Poznyakoff.
623
624 For version 1.12, Daniel Hagerty contributed a great deal of technical
625 consulting. In particular, he is the primary author of @ref{Backups}.
626
627 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
628 (see @url{http://savannah.gnu.org/projects/tar}), and
629 active development and maintenance work has started
630 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
631 Poznyakoff and Jeff Bailey.
632
633 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
634
635 @node Reports
636 @section Reporting bugs or suggestions
637
638 @cindex bug reports
639 @cindex reporting bugs
640 If you find problems or have suggestions about this program or manual,
641 please report them to @file{bug-tar@@gnu.org}.
642
643 When reporting a bug, please be sure to include as much detail as
644 possible, in order to reproduce it. @FIXME{Be more specific, I'd
645 like to make this node as detailed as 'Bug reporting' node in Emacs
646 manual}.
647
648 @node Tutorial
649 @chapter Tutorial Introduction to @command{tar}
650
651 This chapter guides you through some basic examples of three @command{tar}
652 operations: @option{--create}, @option{--list}, and @option{--extract}. If
653 you already know how to use some other version of @command{tar}, then you
654 may not need to read this chapter. This chapter omits most complicated
655 details about how @command{tar} works.
656
657 @menu
658 * assumptions::
659 * stylistic conventions::
660 * basic tar options:: Basic @command{tar} Operations and Options
661 * frequent operations::
662 * Two Frequent Options::
663 * create:: How to Create Archives
664 * list:: How to List Archives
665 * extract:: How to Extract Members from an Archive
666 * going further::
667 @end menu
668
669 @node assumptions
670 @section Assumptions this Tutorial Makes
671
672 This chapter is paced to allow beginners to learn about @command{tar}
673 slowly. At the same time, we will try to cover all the basic aspects of
674 these three operations. In order to accomplish both of these tasks, we
675 have made certain assumptions about your knowledge before reading this
676 manual, and the hardware you will be using:
677
678 @itemize @bullet
679 @item
680 Before you start to work through this tutorial, you should understand
681 what the terms ``archive'' and ``archive member'' mean
682 (@pxref{Definitions}). In addition, you should understand something
683 about how Unix-type operating systems work, and you should know how to
684 use some basic utilities. For example, you should know how to create,
685 list, copy, rename, edit, and delete files and directories; how to
686 change between directories; and how to figure out where you are in the
687 file system. You should have some basic understanding of directory
688 structure and how files are named according to which directory they are
689 in. You should understand concepts such as standard output and standard
690 input, what various definitions of the term ``argument'' mean, and the
691 differences between relative and absolute file names. @FIXME{and what
692 else?}
693
694 @item
695 This manual assumes that you are working from your own home directory
696 (unless we state otherwise). In this tutorial, you will create a
697 directory to practice @command{tar} commands in. When we show file names,
698 we will assume that those names are relative to your home directory.
699 For example, my home directory is @file{/home/fsf/melissa}. All of
700 my examples are in a subdirectory of the directory named by that file
701 name; the subdirectory is called @file{practice}.
702
703 @item
704 In general, we show examples of archives which exist on (or can be
705 written to, or worked with from) a directory on a hard disk. In most
706 cases, you could write those archives to, or work with them on any other
707 device, such as a tape drive. However, some of the later examples in
708 the tutorial and next chapter will not work on tape drives.
709 Additionally, working with tapes is much more complicated than working
710 with hard disks. For these reasons, the tutorial does not cover working
711 with tape drives. @xref{Media}, for complete information on using
712 @command{tar} archives with tape drives.
713
714 @FIXME{this is a cop out. need to add some simple tape drive info.}
715 @end itemize
716
717 @node stylistic conventions
718 @section Stylistic Conventions
719
720 In the examples, @samp{$} represents a typical shell prompt. It
721 precedes lines you should type; to make this more clear, those lines are
722 shown in @kbd{this font}, as opposed to lines which represent the
723 computer's response; those lines are shown in @code{this font}, or
724 sometimes @samp{like this}.
725
726 @c When we have lines which are too long to be
727 @c displayed in any other way, we will show them like this:
728
729 @node basic tar options
730 @section Basic @command{tar} Operations and Options
731
732 @command{tar} can take a wide variety of arguments which specify and define
733 the actions it will have on the particular set of files or the archive.
734 The main types of arguments to @command{tar} fall into one of two classes:
735 operations, and options.
736
737 Some arguments fall into a class called @dfn{operations}; exactly one of
738 these is both allowed and required for any instance of using @command{tar};
739 you may @emph{not} specify more than one. People sometimes speak of
740 @dfn{operating modes}. You are in a particular operating mode when you
741 have specified the operation which specifies it; there are eight
742 operations in total, and thus there are eight operating modes.
743
744 The other arguments fall into the class known as @dfn{options}. You are
745 not required to specify any options, and you are allowed to specify more
746 than one at a time (depending on the way you are using @command{tar} at
747 that time). Some options are used so frequently, and are so useful for
748 helping you type commands more carefully that they are effectively
749 ``required''. We will discuss them in this chapter.
750
751 You can write most of the @command{tar} operations and options in any
752 of three forms: long (mnemonic) form, short form, and old style. Some
753 of the operations and options have no short or ``old'' forms; however,
754 the operations and options which we will cover in this tutorial have
755 corresponding abbreviations. @FIXME{make sure this is still the case,
756 at the end}We will indicate those abbreviations appropriately to get
757 you used to seeing them. (Note that the ``old style'' option forms
758 exist in @GNUTAR{} for compatibility with Unix
759 @command{tar}. In this book we present a full discussion of this way
760 of writing options and operations (@pxref{Old Options}), and we discuss
761 the other two styles of writing options (@xref{Long Options}, and
762 @pxref{Short Options}).
763
764 In the examples and in the text of this tutorial, we usually use the
765 long forms of operations and options; but the ``short'' forms produce
766 the same result and can make typing long @command{tar} commands easier.
767 For example, instead of typing
768
769 @smallexample
770 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
771 @end smallexample
772
773 @noindent
774 you can type
775 @smallexample
776 @kbd{tar -c -v -f afiles.tar apple angst aspic}
777 @end smallexample
778
779 @noindent
780 or even
781 @smallexample
782 @kbd{tar -cvf afiles.tar apple angst aspic}
783 @end smallexample
784
785 @noindent
786 For more information on option syntax, see @ref{Advanced tar}. In
787 discussions in the text, when we name an option by its long form, we
788 also give the corresponding short option in parentheses.
789
790 The term, ``option'', can be confusing at times, since ``operations''
791 are often lumped in with the actual, @emph{optional} ``options'' in certain
792 general class statements. For example, we just talked about ``short and
793 long forms of options and operations''. However, experienced @command{tar}
794 users often refer to these by shorthand terms such as, ``short and long
795 options''. This term assumes that the ``operations'' are included, also.
796 Context will help you determine which definition of ``options'' to use.
797
798 Similarly, the term ``command'' can be confusing, as it is often used in
799 two different ways. People sometimes refer to @command{tar} ``commands''.
800 A @command{tar} @dfn{command} is the entire command line of user input
801 which tells @command{tar} what to do --- including the operation, options,
802 and any arguments (file names, pipes, other commands, etc.). However,
803 you will also sometimes hear the term ``the @command{tar} command''. When
804 the word ``command'' is used specifically like this, a person is usually
805 referring to the @command{tar} @emph{operation}, not the whole line.
806 Again, use context to figure out which of the meanings the speaker
807 intends.
808
809 @node frequent operations
810 @section The Three Most Frequently Used Operations
811
812 Here are the three most frequently used operations (both short and long
813 forms), as well as a brief description of their meanings. The rest of
814 this chapter will cover how to use these operations in detail. We will
815 present the rest of the operations in the next chapter.
816
817 @table @option
818 @item --create
819 @itemx -c
820 Create a new @command{tar} archive.
821 @item --list
822 @itemx -t
823 List the contents of an archive.
824 @item --extract
825 @itemx -x
826 Extract one or more members from an archive.
827 @end table
828
829 @node Two Frequent Options
830 @section Two Frequently Used Options
831
832 To understand how to run @command{tar} in the three operating modes listed
833 previously, you also need to understand how to use two of the options to
834 @command{tar}: @option{--file} (which takes an archive file as an argument)
835 and @option{--verbose}. (You are usually not @emph{required} to specify
836 either of these options when you run @command{tar}, but they can be very
837 useful in making things more clear and helping you avoid errors.)
838
839 @menu
840 * file tutorial::
841 * verbose tutorial::
842 * help tutorial::
843 @end menu
844
845 @node file tutorial
846 @unnumberedsubsec The @option{--file} Option
847
848 @table @option
849 @xopindex{file, tutorial}
850 @item --file=@var{archive-name}
851 @itemx -f @var{archive-name}
852 Specify the name of an archive file.
853 @end table
854
855 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
856 use @command{tar}; this option determines the name of the archive file
857 that @command{tar} will work on.
858
859 @vrindex TAPE
860 If you don't specify this argument, then @command{tar} will examine
861 the environment variable @env{TAPE}. If it is set, its value will be
862 used as the archive name. Otherwise, @command{tar} will use the
863 default archive, determined at the compile time. Usually it is
864 standard output or some physical tape drive attached to your machine
865 (you can verify what the default is by running @kbd{tar
866 --show-defaults}, @pxref{defaults}). If there is no tape drive
867 attached, or the default is not meaningful, then @command{tar} will
868 print an error message. The error message might look roughly like one
869 of the following:
870
871 @smallexample
872 tar: can't open /dev/rmt8 : No such device or address
873 tar: can't open /dev/rsmt0 : I/O error
874 @end smallexample
875
876 @noindent
877 To avoid confusion, we recommend that you always specify an archive file
878 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
879 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
880 @ref{file}.
881
882 @node verbose tutorial
883 @unnumberedsubsec The @option{--verbose} Option
884
885 @table @option
886 @xopindex{verbose, introduced}
887 @item --verbose
888 @itemx -v
889 Show the files being worked on as @command{tar} is running.
890 @end table
891
892 @option{--verbose} (@option{-v}) shows details about the results of running
893 @command{tar}. This can be especially useful when the results might not be
894 obvious. For example, if you want to see the progress of @command{tar} as
895 it writes files into the archive, you can use the @option{--verbose}
896 option. In the beginning, you may find it useful to use
897 @option{--verbose} at all times; when you are more accustomed to
898 @command{tar}, you will likely want to use it at certain times but not at
899 others. We will use @option{--verbose} at times to help make something
900 clear, and we will give many examples both using and not using
901 @option{--verbose} to show the differences.
902
903 Each instance of @option{--verbose} on the command line increases the
904 verbosity level by one, so if you need more details on the output,
905 specify it twice.
906
907 When reading archives (@option{--list}, @option{--extract},
908 @option{--diff}), @command{tar} by default prints only the names of
909 the members being extracted. Using @option{--verbose} will show a full,
910 @command{ls} style member listing.
911
912 In contrast, when writing archives (@option{--create}, @option{--append},
913 @option{--update}), @command{tar} does not print file names by
914 default. So, a single @option{--verbose} option shows the file names
915 being added to the archive, while two @option{--verbose} options
916 enable the full listing.
917
918 For example, to create an archive in verbose mode:
919
920 @smallexample
921 $ @kbd{tar -cvf afiles.tar apple angst aspic}
922 apple
923 angst
924 aspic
925 @end smallexample
926
927 @noindent
928 Creating the same archive with the verbosity level 2 could give:
929
930 @smallexample
931 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
932 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
933 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
934 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
935 @end smallexample
936
937 @noindent
938 This works equally well using short or long forms of options. Using
939 long forms, you would simply write out the mnemonic form of the option
940 twice, like this:
941
942 @smallexample
943 $ @kbd{tar --create --verbose --verbose @dots{}}
944 @end smallexample
945
946 @noindent
947 Note that you must double the hyphens properly each time.
948
949 Later in the tutorial, we will give examples using @w{@option{--verbose
950 --verbose}}.
951
952 @anchor{verbose member listing}
953 The full output consists of six fields:
954
955 @itemize @bullet
956 @item File type and permissions in symbolic form.
957 These are displayed in the same format as the first column of
958 @command{ls -l} output (@pxref{What information is listed,
959 format=verbose, Verbose listing, fileutils, GNU file utilities}).
960
961 @item Owner name and group separated by a slash character.
962 If these data are not available (for example, when listing a @samp{v7} format
963 archive), numeric @acronym{ID} values are printed instead.
964
965 @item Size of the file, in bytes.
966
967 @item File modification date in ISO 8601 format.
968
969 @item File modification time.
970
971 @item File name.
972 If the name contains any special characters (white space, newlines,
973 etc.) these are displayed in an unambiguous form using so called
974 @dfn{quoting style}. For the detailed discussion of available styles
975 and on how to use them, see @ref{quoting styles}.
976
977 Depending on the file type, the name can be followed by some
978 additional information, described in the following table:
979
980 @table @samp
981 @item -> @var{link-name}
982 The file or archive member is a @dfn{symbolic link} and
983 @var{link-name} is the name of file it links to.
984
985 @item link to @var{link-name}
986 The file or archive member is a @dfn{hard link} and @var{link-name} is
987 the name of file it links to.
988
989 @item --Long Link--
990 The archive member is an old GNU format long link. You will normally
991 not encounter this.
992
993 @item --Long Name--
994 The archive member is an old GNU format long name. You will normally
995 not encounter this.
996
997 @item --Volume Header--
998 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
999
1000 @item --Continued at byte @var{n}--
1001 Encountered only at the beginning of a multi-volume archive
1002 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1003 from the previous volume. The number @var{n} gives the offset where
1004 the original file was split.
1005
1006 @item unknown file type @var{c}
1007 An archive member of unknown type. @var{c} is the type character from
1008 the archive header. If you encounter such a message, it means that
1009 either your archive contains proprietary member types @GNUTAR{} is not
1010 able to handle, or the archive is corrupted.
1011 @end table
1012
1013 @end itemize
1014
1015 For example, here is an archive listing containing most of the special
1016 suffixes explained above:
1017
1018 @smallexample
1019 @group
1020 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1021 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1022 byte 32456--
1023 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1024 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1025 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1026 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1027 @end group
1028 @end smallexample
1029
1030 @smallexample
1031 @end smallexample
1032
1033 @node help tutorial
1034 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1035
1036 @table @option
1037 @opindex help
1038 @item --help
1039
1040 The @option{--help} option to @command{tar} prints out a very brief list of
1041 all operations and option available for the current version of
1042 @command{tar} available on your system.
1043 @end table
1044
1045 @node create
1046 @section How to Create Archives
1047 @UNREVISED
1048
1049 @cindex Creation of the archive
1050 @cindex Archive, creation of
1051 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1052 you use to create a @command{tar} archive. We will explain
1053 @option{--create} first because, in order to learn about the other
1054 operations, you will find it useful to have an archive available to
1055 practice on.
1056
1057 To make this easier, in this section you will first create a directory
1058 containing three files. Then, we will show you how to create an
1059 @emph{archive} (inside the new directory). Both the directory, and
1060 the archive are specifically for you to practice on. The rest of this
1061 chapter and the next chapter will show many examples using this
1062 directory and the files you will create: some of those files may be
1063 other directories and other archives.
1064
1065 The three files you will archive in this example are called
1066 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1067 @file{collection.tar}.
1068
1069 This section will proceed slowly, detailing how to use @option{--create}
1070 in @code{verbose} mode, and showing examples using both short and long
1071 forms. In the rest of the tutorial, and in the examples in the next
1072 chapter, we will proceed at a slightly quicker pace. This section
1073 moves more slowly to allow beginning users to understand how
1074 @command{tar} works.
1075
1076 @menu
1077 * prepare for examples::
1078 * Creating the archive::
1079 * create verbose::
1080 * short create::
1081 * create dir::
1082 @end menu
1083
1084 @node prepare for examples
1085 @subsection Preparing a Practice Directory for Examples
1086
1087 To follow along with this and future examples, create a new directory
1088 called @file{practice} containing files called @file{blues}, @file{folk}
1089 and @file{jazz}. The files can contain any information you like:
1090 ideally, they should contain information which relates to their names,
1091 and be of different lengths. Our examples assume that @file{practice}
1092 is a subdirectory of your home directory.
1093
1094 Now @command{cd} to the directory named @file{practice}; @file{practice}
1095 is now your @dfn{working directory}. (@emph{Please note}: Although
1096 the full file name of this directory is
1097 @file{/@var{homedir}/practice}, in our examples we will refer to
1098 this directory as @file{practice}; the @var{homedir} is presumed.
1099
1100 In general, you should check that the files to be archived exist where
1101 you think they do (in the working directory) by running @command{ls}.
1102 Because you just created the directory and the files and have changed to
1103 that directory, you probably don't need to do that this time.
1104
1105 It is very important to make sure there isn't already a file in the
1106 working directory with the archive name you intend to use (in this case,
1107 @samp{collection.tar}), or that you don't care about its contents.
1108 Whenever you use @samp{create}, @command{tar} will erase the current
1109 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1110 will not tell you if you are about to overwrite an archive unless you
1111 specify an option which does this (@pxref{backup}, for the
1112 information on how to do so). To add files to an existing archive,
1113 you need to use a different option, such as @option{--append} (@option{-r}); see
1114 @ref{append} for information on how to do this.
1115
1116 @node Creating the archive
1117 @subsection Creating the Archive
1118
1119 @xopindex{create, introduced}
1120 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1121 archive named @file{collection.tar}, use the following command:
1122
1123 @smallexample
1124 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1125 @end smallexample
1126
1127 The order of the arguments is not very important, @emph{when using long
1128 option forms}. You could also say:
1129
1130 @smallexample
1131 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1132 @end smallexample
1133
1134 @noindent
1135 However, you can see that this order is harder to understand; this is
1136 why we will list the arguments in the order that makes the commands
1137 easiest to understand (and we encourage you to do the same when you use
1138 @command{tar}, to avoid errors).
1139
1140 Note that the sequence
1141 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1142 If you substituted any other string of characters for
1143 @kbd{collection.tar}, then that string would become the name of the
1144 archive file you create.
1145
1146 The order of the options becomes more important when you begin to use
1147 short forms. With short forms, if you type commands in the wrong order
1148 (even if you type them correctly in all other ways), you may end up with
1149 results you don't expect. For this reason, it is a good idea to get
1150 into the habit of typing options in the order that makes inherent sense.
1151 @xref{short create}, for more information on this.
1152
1153 In this example, you type the command as shown above: @option{--create}
1154 is the operation which creates the new archive
1155 (@file{collection.tar}), and @option{--file} is the option which lets
1156 you give it the name you chose. The files, @file{blues}, @file{folk},
1157 and @file{jazz}, are now members of the archive, @file{collection.tar}
1158 (they are @dfn{file name arguments} to the @option{--create} operation.
1159 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1160 in the archive, they are called @emph{archive members}, not files.
1161 (@pxref{Definitions,members}).
1162
1163 When you create an archive, you @emph{must} specify which files you
1164 want placed in the archive. If you do not specify any archive
1165 members, @GNUTAR{} will complain.
1166
1167 If you now list the contents of the working directory (@command{ls}), you will
1168 find the archive file listed as well as the files you saw previously:
1169
1170 @smallexample
1171 blues folk jazz collection.tar
1172 @end smallexample
1173
1174 @noindent
1175 Creating the archive @samp{collection.tar} did not destroy the copies of
1176 the files in the directory.
1177
1178 Keep in mind that if you don't indicate an operation, @command{tar} will not
1179 run and will prompt you for one. If you don't name any files, @command{tar}
1180 will complain. You must have write access to the working directory,
1181 or else you will not be able to create an archive in that directory.
1182
1183 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1184 an existing archive; it will delete the archive and write a new one.
1185 Use @option{--append} (@option{-r}) instead. @xref{append}.
1186
1187 @node create verbose
1188 @subsection Running @option{--create} with @option{--verbose}
1189
1190 @xopindex{create, using with @option{--verbose}}
1191 @xopindex{verbose, using with @option{--create}}
1192 If you include the @option{--verbose} (@option{-v}) option on the command line,
1193 @command{tar} will list the files it is acting on as it is working. In
1194 verbose mode, the @code{create} example above would appear as:
1195
1196 @smallexample
1197 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1198 blues
1199 folk
1200 jazz
1201 @end smallexample
1202
1203 This example is just like the example we showed which did not use
1204 @option{--verbose}, except that @command{tar} generated the remaining lines
1205 @iftex
1206 (note the different font styles).
1207 @end iftex
1208 @ifinfo
1209 .
1210 @end ifinfo
1211
1212 In the rest of the examples in this chapter, we will frequently use
1213 @code{verbose} mode so we can show actions or @command{tar} responses that
1214 you would otherwise not see, and which are important for you to
1215 understand.
1216
1217 @node short create
1218 @subsection Short Forms with @samp{create}
1219
1220 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1221 basic uses of @command{tar}, and you will use it countless times.
1222 Eventually, you will probably want to use abbreviated (or ``short'')
1223 forms of options. A full discussion of the three different forms that
1224 options can take appears in @ref{Styles}; for now, here is what the
1225 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1226 using short option forms:
1227
1228 @smallexample
1229 $ @kbd{tar -cvf collection.tar blues folk jazz}
1230 blues
1231 folk
1232 jazz
1233 @end smallexample
1234
1235 @noindent
1236 As you can see, the system responds the same no matter whether you use
1237 long or short option forms.
1238
1239 @FIXME{i don't like how this is worded:} One difference between using
1240 short and long option forms is that, although the exact placement of
1241 arguments following options is no more specific when using short forms,
1242 it is easier to become confused and make a mistake when using short
1243 forms. For example, suppose you attempted the above example in the
1244 following way:
1245
1246 @smallexample
1247 $ @kbd{tar -cfv collection.tar blues folk jazz}
1248 @end smallexample
1249
1250 @noindent
1251 In this case, @command{tar} will make an archive file called @file{v},
1252 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1253 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1254 is thus taken to be the chosen archive file name. @command{tar} will try
1255 to add a file called @file{collection.tar} to the @file{v} archive file;
1256 if the file @file{collection.tar} did not already exist, @command{tar} will
1257 report an error indicating that this file does not exist. If the file
1258 @file{collection.tar} does already exist (e.g., from a previous command
1259 you may have run), then @command{tar} will add this file to the archive.
1260 Because the @option{-v} option did not get registered, @command{tar} will not
1261 run under @samp{verbose} mode, and will not report its progress.
1262
1263 The end result is that you may be quite confused about what happened,
1264 and possibly overwrite a file. To illustrate this further, we will show
1265 you how an example we showed previously would look using short forms.
1266
1267 This example,
1268
1269 @smallexample
1270 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1271 @end smallexample
1272
1273 @noindent
1274 is confusing as it is. When shown using short forms, however, it
1275 becomes much more so:
1276
1277 @smallexample
1278 $ @kbd{tar blues -c folk -f collection.tar jazz}
1279 @end smallexample
1280
1281 @noindent
1282 It would be very easy to put the wrong string of characters
1283 immediately following the @option{-f}, but doing that could sacrifice
1284 valuable data.
1285
1286 For this reason, we recommend that you pay very careful attention to
1287 the order of options and placement of file and archive names,
1288 especially when using short option forms. Not having the option name
1289 written out mnemonically can affect how well you remember which option
1290 does what, and therefore where different names have to be placed.
1291
1292 @node create dir
1293 @subsection Archiving Directories
1294
1295 @cindex Archiving Directories
1296 @cindex Directories, Archiving
1297 You can archive a directory by specifying its directory name as a
1298 file name argument to @command{tar}. The files in the directory will be
1299 archived relative to the working directory, and the directory will be
1300 re-created along with its contents when the archive is extracted.
1301
1302 To archive a directory, first move to its superior directory. If you
1303 have followed the previous instructions in this tutorial, you should
1304 type:
1305
1306 @smallexample
1307 $ @kbd{cd ..}
1308 $
1309 @end smallexample
1310
1311 @noindent
1312 This will put you into the directory which contains @file{practice},
1313 i.e., your home directory. Once in the superior directory, you can
1314 specify the subdirectory, @file{practice}, as a file name argument. To
1315 store @file{practice} in the new archive file @file{music.tar}, type:
1316
1317 @smallexample
1318 $ @kbd{tar --create --verbose --file=music.tar practice}
1319 @end smallexample
1320
1321 @noindent
1322 @command{tar} should output:
1323
1324 @smallexample
1325 practice/
1326 practice/blues
1327 practice/folk
1328 practice/jazz
1329 practice/collection.tar
1330 @end smallexample
1331
1332 Note that the archive thus created is not in the subdirectory
1333 @file{practice}, but rather in the current working directory---the
1334 directory from which @command{tar} was invoked. Before trying to archive a
1335 directory from its superior directory, you should make sure you have
1336 write access to the superior directory itself, not only the directory
1337 you are trying archive with @command{tar}. For example, you will probably
1338 not be able to store your home directory in an archive by invoking
1339 @command{tar} from the root directory; @xref{absolute}. (Note
1340 also that @file{collection.tar}, the original archive file, has itself
1341 been archived. @command{tar} will accept any file as a file to be
1342 archived, regardless of its content. When @file{music.tar} is
1343 extracted, the archive file @file{collection.tar} will be re-written
1344 into the file system).
1345
1346 If you give @command{tar} a command such as
1347
1348 @smallexample
1349 $ @kbd{tar --create --file=foo.tar .}
1350 @end smallexample
1351
1352 @noindent
1353 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1354 dumped}. This happens because @command{tar} creates the archive
1355 @file{foo.tar} in the current directory before putting any files into
1356 it. Then, when @command{tar} attempts to add all the files in the
1357 directory @file{.} to the archive, it notices that the file
1358 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1359 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1360 will continue in this case, and create the archive
1361 normally, except for the exclusion of that one file. (@emph{Please
1362 note:} Other implementations of @command{tar} may not be so clever;
1363 they will enter an infinite loop when this happens, so you should not
1364 depend on this behavior unless you are certain you are running
1365 @GNUTAR{}. In general, it is wise to always place the archive outside
1366 of the directory being dumped.
1367
1368 @node list
1369 @section How to List Archives
1370
1371 @opindex list
1372 Frequently, you will find yourself wanting to determine exactly what a
1373 particular archive contains. You can use the @option{--list}
1374 (@option{-t}) operation to get the member names as they currently
1375 appear in the archive, as well as various attributes of the files at
1376 the time they were archived. For example, you can examine the archive
1377 @file{collection.tar} that you created in the last section with the
1378 command,
1379
1380 @smallexample
1381 $ @kbd{tar --list --file=collection.tar}
1382 @end smallexample
1383
1384 @noindent
1385 The output of @command{tar} would then be:
1386
1387 @smallexample
1388 blues
1389 folk
1390 jazz
1391 @end smallexample
1392
1393 @noindent
1394 The archive @file{bfiles.tar} would list as follows:
1395
1396 @smallexample
1397 ./birds
1398 baboon
1399 ./box
1400 @end smallexample
1401
1402 @noindent
1403 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1404 @var{archive-name}}) option just as with @option{--create}
1405 (@option{-c}) to specify the name of the archive.
1406
1407 @xopindex{list, using with @option{--verbose}}
1408 @xopindex{verbose, using with @option{--list}}
1409 If you use the @option{--verbose} (@option{-v}) option with
1410 @option{--list}, then @command{tar} will print out a listing
1411 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1412 forth. This output is described in detail in @ref{verbose member listing}.
1413
1414 If you had used @option{--verbose} (@option{-v}) mode, the example
1415 above would look like:
1416
1417 @smallexample
1418 $ @kbd{tar --list --verbose --file=collection.tar folk}
1419 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1420 @end smallexample
1421
1422 @cindex listing member and file names
1423 @anchor{listing member and file names}
1424 It is important to notice that the output of @kbd{tar --list
1425 --verbose} does not necessarily match that produced by @kbd{tar
1426 --create --verbose} while creating the archive. It is because
1427 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1428 prefixes from file names before storing them in the archive
1429 (@xref{absolute}, for more information). In other
1430 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1431 an archive and @dfn{member names} when listing it. Consider this
1432 example:
1433
1434 @smallexample
1435 @group
1436 $ @kbd{tar cfv archive /etc/mail}
1437 tar: Removing leading `/' from member names
1438 /etc/mail/
1439 /etc/mail/sendmail.cf
1440 /etc/mail/aliases
1441 $ @kbd{tar tf archive}
1442 etc/mail/
1443 etc/mail/sendmail.cf
1444 etc/mail/aliases
1445 @end group
1446 @end smallexample
1447
1448 @opindex show-stored-names
1449 This default behavior can sometimes be inconvenient. You can force
1450 @GNUTAR{} show member names when creating archive by supplying
1451 @option{--show-stored-names} option.
1452
1453 @table @option
1454 @item --show-stored-names
1455 Print member (as opposed to @emph{file}) names when creating the archive.
1456 @end table
1457
1458 @cindex File name arguments, using @option{--list} with
1459 @xopindex{list, using with file name arguments}
1460 You can specify one or more individual member names as arguments when
1461 using @samp{list}. In this case, @command{tar} will only list the
1462 names of members you identify. For example, @w{@kbd{tar --list
1463 --file=afiles.tar apple}} would only print @file{apple}.
1464
1465 Because @command{tar} preserves file names, these must be specified as
1466 they appear in the archive (i.e., relative to the directory from which
1467 the archive was created). Therefore, it is essential when specifying
1468 member names to @command{tar} that you give the exact member names.
1469 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1470 error message something like @samp{tar: birds: Not found in archive},
1471 because there is no member named @file{birds}, only one named
1472 @file{./birds}. While the names @file{birds} and @file{./birds} name
1473 the same file, @emph{member} names by default are compared verbatim.
1474
1475 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1476 with @file{baboon}, because this exact member name is in the archive file
1477 @file{bfiles.tar}. If you are not sure of the exact file name,
1478 use @dfn{globbing patterns}, for example:
1479
1480 @smallexample
1481 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1482 @end smallexample
1483
1484 @noindent
1485 will list all members whose name contains @samp{b}. @xref{wildcards},
1486 for a detailed discussion of globbing patterns and related
1487 @command{tar} command line options.
1488
1489 @menu
1490 * list dir::
1491 @end menu
1492
1493 @node list dir
1494 @unnumberedsubsec Listing the Contents of a Stored Directory
1495
1496 To get information about the contents of an archived directory,
1497 use the directory name as a file name argument in conjunction with
1498 @option{--list} (@option{-t}). To find out file attributes, include the
1499 @option{--verbose} (@option{-v}) option.
1500
1501 For example, to find out about files in the directory @file{practice}, in
1502 the archive file @file{music.tar}, type:
1503
1504 @smallexample
1505 $ @kbd{tar --list --verbose --file=music.tar practice}
1506 @end smallexample
1507
1508 @command{tar} responds:
1509
1510 @smallexample
1511 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1512 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1513 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1514 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1515 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1516 @end smallexample
1517
1518 When you use a directory name as a file name argument, @command{tar} acts on
1519 all the files (including sub-directories) in that directory.
1520
1521 @node extract
1522 @section How to Extract Members from an Archive
1523 @UNREVISED
1524 @cindex Extraction
1525 @cindex Retrieving files from an archive
1526 @cindex Resurrecting files from an archive
1527
1528 @opindex extract
1529 Creating an archive is only half the job---there is no point in storing
1530 files in an archive if you can't retrieve them. The act of retrieving
1531 members from an archive so they can be used and manipulated as
1532 unarchived files again is called @dfn{extraction}. To extract files
1533 from an archive, use the @option{--extract} (@option{--get} or
1534 @option{-x}) operation. As with @option{--create}, specify the name
1535 of the archive with @option{--file} (@option{-f}) option. Extracting
1536 an archive does not modify the archive in any way; you can extract it
1537 multiple times if you want or need to.
1538
1539 Using @option{--extract}, you can extract an entire archive, or specific
1540 files. The files can be directories containing other files, or not. As
1541 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1542 long form of the operation without affecting the performance.
1543
1544 @menu
1545 * extracting archives::
1546 * extracting files::
1547 * extract dir::
1548 * extracting untrusted archives::
1549 * failing commands::
1550 @end menu
1551
1552 @node extracting archives
1553 @subsection Extracting an Entire Archive
1554
1555 To extract an entire archive, specify the archive file name only, with
1556 no individual file names as arguments. For example,
1557
1558 @smallexample
1559 $ @kbd{tar -xvf collection.tar}
1560 @end smallexample
1561
1562 @noindent
1563 produces this:
1564
1565 @smallexample
1566 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1567 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1568 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1569 @end smallexample
1570
1571 @node extracting files
1572 @subsection Extracting Specific Files
1573
1574 To extract specific archive members, give their exact member names as
1575 arguments, as printed by @option{--list} (@option{-t}). If you had
1576 mistakenly deleted one of the files you had placed in the archive
1577 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1578 from the archive without changing the archive's structure. Its
1579 contents will be identical to the original file @file{blues} that you
1580 deleted.
1581
1582 First, make sure you are in the @file{practice} directory, and list the
1583 files in the directory. Now, delete the file, @samp{blues}, and list
1584 the files in the directory again.
1585
1586 You can now extract the member @file{blues} from the archive file
1587 @file{collection.tar} like this:
1588
1589 @smallexample
1590 $ @kbd{tar --extract --file=collection.tar blues}
1591 @end smallexample
1592
1593 @noindent
1594 If you list the files in the directory again, you will see that the file
1595 @file{blues} has been restored, with its original permissions, data
1596 modification times, and owner.@footnote{This is only accidentally
1597 true, but not in general. Whereas modification times are always
1598 restored, in most cases, one has to be root for restoring the owner,
1599 and use a special option for restoring permissions. Here, it just
1600 happens that the restoring user is also the owner of the archived
1601 members, and that the current @code{umask} is compatible with original
1602 permissions.} (These parameters will be identical to those which
1603 the file had when you originally placed it in the archive; any changes
1604 you may have made before deleting the file from the file system,
1605 however, will @emph{not} have been made to the archive member.) The
1606 archive file, @samp{collection.tar}, is the same as it was before you
1607 extracted @samp{blues}. You can confirm this by running @command{tar} with
1608 @option{--list} (@option{-t}).
1609
1610 Remember that as with other operations, specifying the exact member
1611 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1612 will fail, because there is no member named @file{birds}. To extract
1613 the member named @file{./birds}, you must specify @w{@kbd{tar
1614 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1615 exact member names, use @option{--list} (@option{-t}) option
1616 (@pxref{list}). You can also extract those members that match a
1617 specific @dfn{globbing pattern}. For example, to extract from
1618 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1619 directory prefix, you could type:
1620
1621 @smallexample
1622 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1623 @end smallexample
1624
1625 @noindent
1626 Here, @option{--wildcards} instructs @command{tar} to treat
1627 command line arguments as globbing patterns and @option{--no-anchored}
1628 informs it that the patterns apply to member names after any @samp{/}
1629 delimiter. The use of globbing patterns is discussed in detail in
1630 @xref{wildcards}.
1631
1632 You can extract a file to standard output by combining the above options
1633 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1634 Output}).
1635
1636 If you give the @option{--verbose} option, then @option{--extract}
1637 will print the names of the archive members as it extracts them.
1638
1639 @node extract dir
1640 @subsection Extracting Files that are Directories
1641
1642 Extracting directories which are members of an archive is similar to
1643 extracting other files. The main difference to be aware of is that if
1644 the extracted directory has the same name as any directory already in
1645 the working directory, then files in the extracted directory will be
1646 placed into the directory of the same name. Likewise, if there are
1647 files in the pre-existing directory with the same names as the members
1648 which you extract, the files from the extracted archive will replace
1649 the files already in the working directory (and possible
1650 subdirectories). This will happen regardless of whether or not the
1651 files in the working directory were more recent than those extracted
1652 (there exist, however, special options that alter this behavior
1653 @pxref{Writing}).
1654
1655 However, if a file was stored with a directory name as part of its file
1656 name, and that directory does not exist under the working directory when
1657 the file is extracted, @command{tar} will create the directory.
1658
1659 We can demonstrate how to use @option{--extract} to extract a directory
1660 file with an example. Change to the @file{practice} directory if you
1661 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1662 go back to the parent directory and extract the archive
1663 @file{music.tar}. You may either extract the entire archive, or you may
1664 extract only the files you just deleted. To extract the entire archive,
1665 don't give any file names as arguments after the archive name
1666 @file{music.tar}. To extract only the files you deleted, use the
1667 following command:
1668
1669 @smallexample
1670 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1671 practice/folk
1672 practice/jazz
1673 @end smallexample
1674
1675 @noindent
1676 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1677 would have displayed more detail about the extracted files, as shown
1678 in the example below:
1679
1680 @smallexample
1681 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1682 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1683 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1684 @end smallexample
1685
1686 @noindent
1687 Because you created the directory with @file{practice} as part of the
1688 file names of each of the files by archiving the @file{practice}
1689 directory as @file{practice}, you must give @file{practice} as part
1690 of the file names when you extract those files from the archive.
1691
1692 @node extracting untrusted archives
1693 @subsection Extracting Archives from Untrusted Sources
1694
1695 Extracting files from archives can overwrite files that already exist.
1696 If you receive an archive from an untrusted source, you should make a
1697 new directory and extract into that directory, so that you don't have
1698 to worry about the extraction overwriting one of your existing files.
1699 For example, if @file{untrusted.tar} came from somewhere else on the
1700 Internet, and you don't necessarily trust its contents, you can
1701 extract it as follows:
1702
1703 @smallexample
1704 $ @kbd{mkdir newdir}
1705 $ @kbd{cd newdir}
1706 $ @kbd{tar -xvf ../untrusted.tar}
1707 @end smallexample
1708
1709 It is also a good practice to examine contents of the archive
1710 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1711 with @option{--verbose} (@option{-v}).
1712
1713 @node failing commands
1714 @subsection Commands That Will Fail
1715
1716 Here are some sample commands you might try which will not work, and why
1717 they won't work.
1718
1719 If you try to use this command,
1720
1721 @smallexample
1722 $ @kbd{tar -xvf music.tar folk jazz}
1723 @end smallexample
1724
1725 @noindent
1726 you will get the following response:
1727
1728 @smallexample
1729 tar: folk: Not found in archive
1730 tar: jazz: Not found in archive
1731 $
1732 @end smallexample
1733
1734 @noindent
1735 This is because these files were not originally @emph{in} the parent
1736 directory @file{..}, where the archive is located; they were in the
1737 @file{practice} directory, and their file names reflect this:
1738
1739 @smallexample
1740 $ @kbd{tar -tvf music.tar}
1741 practice/folk
1742 practice/jazz
1743 practice/rock
1744 @end smallexample
1745
1746 @FIXME{make sure the above works when going through the examples in
1747 order...}
1748
1749 @noindent
1750 Likewise, if you try to use this command,
1751
1752 @smallexample
1753 $ @kbd{tar -tvf music.tar folk jazz}
1754 @end smallexample
1755
1756 @noindent
1757 you would get a similar response. Members with those names are not in the
1758 archive. You must use the correct member names, or wildcards, in order
1759 to extract the files from the archive.
1760
1761 If you have forgotten the correct names of the files in the archive,
1762 use @w{@kbd{tar --list --verbose}} to list them correctly.
1763
1764 @FIXME{more examples, here? hag thinks it's a good idea.}
1765
1766 @node going further
1767 @section Going Further Ahead in this Manual
1768
1769 @FIXME{need to write up a node here about the things that are going to
1770 be in the rest of the manual.}
1771
1772 @node tar invocation
1773 @chapter Invoking @GNUTAR{}
1774 @UNREVISED
1775
1776 This chapter is about how one invokes the @GNUTAR{}
1777 command, from the command synopsis (@pxref{Synopsis}). There are
1778 numerous options, and many styles for writing them. One mandatory
1779 option specifies the operation @command{tar} should perform
1780 (@pxref{Operation Summary}), other options are meant to detail how
1781 this operation should be performed (@pxref{Option Summary}).
1782 Non-option arguments are not always interpreted the same way,
1783 depending on what the operation is.
1784
1785 You will find in this chapter everything about option styles and rules for
1786 writing them (@pxref{Styles}). On the other hand, operations and options
1787 are fully described elsewhere, in other chapters. Here, you will find
1788 only synthetic descriptions for operations and options, together with
1789 pointers to other parts of the @command{tar} manual.
1790
1791 Some options are so special they are fully described right in this
1792 chapter. They have the effect of inhibiting the normal operation of
1793 @command{tar} or else, they globally alter the amount of feedback the user
1794 receives about what is going on. These are the @option{--help} and
1795 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1796 and @option{--interactive} options (@pxref{interactive}).
1797
1798 @menu
1799 * Synopsis::
1800 * using tar options::
1801 * Styles::
1802 * All Options::
1803 * help::
1804 * defaults::
1805 * verbose::
1806 * checkpoints::
1807 * interactive::
1808 @end menu
1809
1810 @node Synopsis
1811 @section General Synopsis of @command{tar}
1812
1813 The @GNUTAR{} program is invoked as either one of:
1814
1815 @smallexample
1816 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1817 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1818 @end smallexample
1819
1820 The second form is for when old options are being used.
1821
1822 You can use @command{tar} to store files in an archive, to extract them from
1823 an archive, and to do other types of archive manipulation. The primary
1824 argument to @command{tar}, which is called the @dfn{operation}, specifies
1825 which action to take. The other arguments to @command{tar} are either
1826 @dfn{options}, which change the way @command{tar} performs an operation,
1827 or file names or archive members, which specify the files or members
1828 @command{tar} is to act on.
1829
1830 You can actually type in arguments in any order, even if in this manual
1831 the options always precede the other arguments, to make examples easier
1832 to understand. Further, the option stating the main operation mode
1833 (the @command{tar} main command) is usually given first.
1834
1835 Each @var{name} in the synopsis above is interpreted as an archive member
1836 name when the main command is one of @option{--compare}
1837 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1838 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1839 @option{--update} (@option{-u}). When naming archive members, you
1840 must give the exact name of the member in the archive, as it is
1841 printed by @option{--list}. For @option{--append} (@option{-r}) and
1842 @option{--create} (@option{-c}), these @var{name} arguments specify
1843 the names of either files or directory hierarchies to place in the archive.
1844 These files or hierarchies should already exist in the file system,
1845 prior to the execution of the @command{tar} command.
1846
1847 @command{tar} interprets relative file names as being relative to the
1848 working directory. @command{tar} will make all file names relative
1849 (by removing leading slashes when archiving or restoring files),
1850 unless you specify otherwise (using the @option{--absolute-names}
1851 option). @xref{absolute}, for more information about
1852 @option{--absolute-names}.
1853
1854 If you give the name of a directory as either a file name or a member
1855 name, then @command{tar} acts recursively on all the files and directories
1856 beneath that directory. For example, the name @file{/} identifies all
1857 the files in the file system to @command{tar}.
1858
1859 The distinction between file names and archive member names is especially
1860 important when shell globbing is used, and sometimes a source of confusion
1861 for newcomers. @xref{wildcards}, for more information about globbing.
1862 The problem is that shells may only glob using existing files in the
1863 file system. Only @command{tar} itself may glob on archive members, so when
1864 needed, you must ensure that wildcard characters reach @command{tar} without
1865 being interpreted by the shell first. Using a backslash before @samp{*}
1866 or @samp{?}, or putting the whole argument between quotes, is usually
1867 sufficient for this.
1868
1869 Even if @var{name}s are often specified on the command line, they
1870 can also be read from a text file in the file system, using the
1871 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1872
1873 If you don't use any file name arguments, @option{--append} (@option{-r}),
1874 @option{--delete} and @option{--concatenate} (@option{--catenate},
1875 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1876 will usually yield a diagnostic and inhibit @command{tar} execution.
1877 The other operations of @command{tar} (@option{--list},
1878 @option{--extract}, @option{--compare}, and @option{--update})
1879 will act on the entire contents of the archive.
1880
1881 @cindex exit status
1882 @cindex return status
1883 Besides successful exits, @GNUTAR{} may fail for
1884 many reasons. Some reasons correspond to bad usage, that is, when the
1885 @command{tar} command is improperly written. Errors may be
1886 encountered later, while encountering an error processing the archive
1887 or the files. Some errors are recoverable, in which case the failure
1888 is delayed until @command{tar} has completed all its work. Some
1889 errors are such that it would not meaningful, or at least risky, to
1890 continue processing: @command{tar} then aborts processing immediately.
1891 All abnormal exits, whether immediate or delayed, should always be
1892 clearly diagnosed on @code{stderr}, after a line stating the nature of
1893 the error.
1894
1895 Possible exit codes of @GNUTAR{} are summarized in the following
1896 table:
1897
1898 @table @asis
1899 @item 0
1900 @samp{Successful termination}.
1901
1902 @item 1
1903 @samp{Some files differ}. If tar was invoked with @option{--compare}
1904 (@option{--diff}, @option{-d}) command line option, this means that
1905 some files in the archive differ from their disk counterparts
1906 (@pxref{compare}). If tar was given @option{--create},
1907 @option{--append} or @option{--update} option, this exit code means
1908 that some files were changed while being archived and so the resulting
1909 archive does not contain the exact copy of the file set.
1910
1911 @item 2
1912 @samp{Fatal error}. This means that some fatal, unrecoverable error
1913 occurred.
1914 @end table
1915
1916 If @command{tar} has invoked a subprocess and that subprocess exited with a
1917 nonzero exit code, @command{tar} exits with that code as well.
1918 This can happen, for example, if @command{tar} was given some
1919 compression option (@pxref{gzip}) and the external compressor program
1920 failed. Another example is @command{rmt} failure during backup to the
1921 remote device (@pxref{Remote Tape Server}).
1922
1923 @node using tar options
1924 @section Using @command{tar} Options
1925
1926 @GNUTAR{} has a total of eight operating modes which
1927 allow you to perform a variety of tasks. You are required to choose
1928 one operating mode each time you employ the @command{tar} program by
1929 specifying one, and only one operation as an argument to the
1930 @command{tar} command (two lists of four operations each may be found
1931 at @ref{frequent operations} and @ref{Operations}). Depending on
1932 circumstances, you may also wish to customize how the chosen operating
1933 mode behaves. For example, you may wish to change the way the output
1934 looks, or the format of the files that you wish to archive may require
1935 you to do something special in order to make the archive look right.
1936
1937 You can customize and control @command{tar}'s performance by running
1938 @command{tar} with one or more options (such as @option{--verbose}
1939 (@option{-v}), which we used in the tutorial). As we said in the
1940 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1941 their name suggests) optional. Depending on the operating mode, you
1942 may specify one or more options. Different options will have different
1943 effects, but in general they all change details of the operation, such
1944 as archive format, archive name, or level of user interaction. Some
1945 options make sense with all operating modes, while others are
1946 meaningful only with particular modes. You will likely use some
1947 options frequently, while you will only use others infrequently, or
1948 not at all. (A full list of options is available in @pxref{All Options}.)
1949
1950 @vrindex TAR_OPTIONS, environment variable
1951 @anchor{TAR_OPTIONS}
1952 The @env{TAR_OPTIONS} environment variable specifies default options to
1953 be placed in front of any explicit options. For example, if
1954 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1955 if the two options @option{-v} and @option{--unlink-first} had been
1956 specified before any explicit options. Option specifications are
1957 separated by whitespace. A backslash escapes the next character, so it
1958 can be used to specify an option containing whitespace or a backslash.
1959
1960 Note that @command{tar} options are case sensitive. For example, the
1961 options @option{-T} and @option{-t} are different; the first requires an
1962 argument for stating the name of a file providing a list of @var{name}s,
1963 while the second does not require an argument and is another way to
1964 write @option{--list} (@option{-t}).
1965
1966 In addition to the eight operations, there are many options to
1967 @command{tar}, and three different styles for writing both: long (mnemonic)
1968 form, short form, and old style. These styles are discussed below.
1969 Both the options and the operations can be written in any of these three
1970 styles.
1971
1972 @FIXME{menu at end of this node. need to think of an actual outline
1973 for this chapter; probably do that after stuff from chapter 4 is
1974 incorporated.}
1975
1976 @node Styles
1977 @section The Three Option Styles
1978
1979 There are three styles for writing operations and options to the command
1980 line invoking @command{tar}. The different styles were developed at
1981 different times during the history of @command{tar}. These styles will be
1982 presented below, from the most recent to the oldest.
1983
1984 Some options must take an argument. (For example, @option{--file}
1985 (@option{-f})) takes the name of an archive file as an argument. If
1986 you do not supply an archive file name, @command{tar} will use a
1987 default, but this can be confusing; thus, we recommend that you always
1988 supply a specific archive file name.) Where you @emph{place} the
1989 arguments generally depends on which style of options you choose. We
1990 will detail specific information relevant to each option style in the
1991 sections on the different option styles, below. The differences are
1992 subtle, yet can often be very important; incorrect option placement
1993 can cause you to overwrite a number of important files. We urge you
1994 to note these differences, and only use the option style(s) which
1995 makes the most sense to you until you feel comfortable with the others.
1996
1997 Some options @emph{may} take an argument. Such options may have at
1998 most long and short forms, they do not have old style equivalent. The
1999 rules for specifying an argument for such options are stricter than
2000 those for specifying mandatory arguments. Please, pay special
2001 attention to them.
2002
2003 @menu
2004 * Long Options:: Long Option Style
2005 * Short Options:: Short Option Style
2006 * Old Options:: Old Option Style
2007 * Mixing:: Mixing Option Styles
2008 @end menu
2009
2010 @node Long Options
2011 @subsection Long Option Style
2012
2013 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2014 dashes in a row, e.g., @option{--list}. The long names are more clear than
2015 their corresponding short or old names. It sometimes happens that a
2016 single long option has many different names which are
2017 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2018 long option names can be given unique abbreviations. For example,
2019 @option{--cre} can be used in place of @option{--create} because there is no
2020 other long option which begins with @samp{cre}. (One way to find
2021 this out is by trying it and seeing what happens; if a particular
2022 abbreviation could represent more than one option, @command{tar} will tell
2023 you that that abbreviation is ambiguous and you'll know that that
2024 abbreviation won't work. You may also choose to run @samp{tar --help}
2025 to see a list of options. Be aware that if you run @command{tar} with a
2026 unique abbreviation for the long name of an option you didn't want to
2027 use, you are stuck; @command{tar} will perform the command as ordered.)
2028
2029 Long options are meant to be obvious and easy to remember, and their
2030 meanings are generally easier to discern than those of their
2031 corresponding short options (see below). For example:
2032
2033 @smallexample
2034 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2035 @end smallexample
2036
2037 @noindent
2038 gives a fairly good set of hints about what the command does, even
2039 for those not fully acquainted with @command{tar}.
2040
2041 Long options which require arguments take those arguments
2042 immediately following the option name. There are two ways of
2043 specifying a mandatory argument. It can be separated from the
2044 option name either by an equal sign, or by any amount of
2045 white space characters. For example, the @option{--file} option (which
2046 tells the name of the @command{tar} archive) is given a file such as
2047 @file{archive.tar} as argument by using any of the following notations:
2048 @option{--file=archive.tar} or @option{--file archive.tar}.
2049
2050 In contrast, optional arguments must always be introduced using
2051 an equal sign. For example, the @option{--backup} option takes
2052 an optional argument specifying backup type. It must be used
2053 as @option{--backup=@var{backup-type}}.
2054
2055 @node Short Options
2056 @subsection Short Option Style
2057
2058 Most options also have a @dfn{short option} name. Short options start with
2059 a single dash, and are followed by a single character, e.g., @option{-t}
2060 (which is equivalent to @option{--list}). The forms are absolutely
2061 identical in function; they are interchangeable.
2062
2063 The short option names are faster to type than long option names.
2064
2065 Short options which require arguments take their arguments immediately
2066 following the option, usually separated by white space. It is also
2067 possible to stick the argument right after the short option name, using
2068 no intervening space. For example, you might write @w{@option{-f
2069 archive.tar}} or @option{-farchive.tar} instead of using
2070 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2071 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2072 specific archive, here named @file{archive.tar}.
2073
2074 Short options which take optional arguments take their arguments
2075 immediately following the option letter, @emph{without any intervening
2076 white space characters}.
2077
2078 Short options' letters may be clumped together, but you are not
2079 required to do this (as compared to old options; see below). When
2080 short options are clumped as a set, use one (single) dash for them
2081 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2082 such a set is allowed to have an argument@footnote{Clustering many
2083 options, the last of which has an argument, is a rather opaque way to
2084 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2085 even be made helpful enough for considering such usages as invalid.}.
2086
2087 When the options are separated, the argument for each option which requires
2088 an argument directly follows that option, as is usual for Unix programs.
2089 For example:
2090
2091 @smallexample
2092 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2093 @end smallexample
2094
2095 If you reorder short options' locations, be sure to move any arguments
2096 that belong to them. If you do not move the arguments properly, you may
2097 end up overwriting files.
2098
2099 @node Old Options
2100 @subsection Old Option Style
2101 @UNREVISED
2102
2103 Like short options, @dfn{old options} are single letters. However, old options
2104 must be written together as a single clumped set, without spaces separating
2105 them or dashes preceding them@footnote{Beware that if you precede options
2106 with a dash, you are announcing the short option style instead of the
2107 old option style; short options are decoded differently.}. This set
2108 of letters must be the first to appear on the command line, after the
2109 @command{tar} program name and some white space; old options cannot appear
2110 anywhere else. The letter of an old option is exactly the same letter as
2111 the corresponding short option. For example, the old option @samp{t} is
2112 the same as the short option @option{-t}, and consequently, the same as the
2113 long option @option{--list}. So for example, the command @w{@samp{tar
2114 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2115
2116 When options that need arguments are given together with the command,
2117 all the associated arguments follow, in the same order as the options.
2118 Thus, the example given previously could also be written in the old
2119 style as follows:
2120
2121 @smallexample
2122 $ @kbd{tar cvbf 20 /dev/rmt0}
2123 @end smallexample
2124
2125 @noindent
2126 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2127 the argument of @option{-f}.
2128
2129 On the other hand, this old style syntax makes it difficult to match
2130 option letters with their corresponding arguments, and is often
2131 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2132 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2133 argument for @option{-f}, and @option{-v} does not have a corresponding
2134 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2135 /dev/rmt0}} is clearer, putting all arguments next to the option they
2136 pertain to.
2137
2138 If you want to reorder the letters in the old option argument, be
2139 sure to reorder any corresponding argument appropriately.
2140
2141 This old way of writing @command{tar} options can surprise even experienced
2142 users. For example, the two commands:
2143
2144 @smallexample
2145 @kbd{tar cfz archive.tar.gz file}
2146 @kbd{tar -cfz archive.tar.gz file}
2147 @end smallexample
2148
2149 @noindent
2150 are quite different. The first example uses @file{archive.tar.gz} as
2151 the value for option @samp{f} and recognizes the option @samp{z}. The
2152 second example, however, uses @file{z} as the value for option
2153 @samp{f} --- probably not what was intended.
2154
2155 Old options are kept for compatibility with old versions of @command{tar}.
2156
2157 This second example could be corrected in many ways, among which the
2158 following are equivalent:
2159
2160 @smallexample
2161 @kbd{tar -czf archive.tar.gz file}
2162 @kbd{tar -cf archive.tar.gz -z file}
2163 @kbd{tar cf archive.tar.gz -z file}
2164 @end smallexample
2165
2166 @cindex option syntax, traditional
2167 As far as we know, all @command{tar} programs, @acronym{GNU} and
2168 non-@acronym{GNU}, support old options. @GNUTAR{}
2169 supports them not only for historical reasons, but also because many
2170 people are used to them. For compatibility with Unix @command{tar},
2171 the first argument is always treated as containing command and option
2172 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2173 equivalent to @w{@samp{tar -c}:} both of them specify the
2174 @option{--create} (@option{-c}) command to create an archive.
2175
2176 @node Mixing
2177 @subsection Mixing Option Styles
2178
2179 All three styles may be intermixed in a single @command{tar} command,
2180 so long as the rules for each style are fully
2181 respected@footnote{Before @GNUTAR{} version 1.11.6,
2182 a bug prevented intermixing old style options with long options in
2183 some cases.}. Old style options and either of the modern styles of
2184 options may be mixed within a single @command{tar} command. However,
2185 old style options must be introduced as the first arguments only,
2186 following the rule for old options (old options must appear directly
2187 after the @command{tar} command and some white space). Modern options
2188 may be given only after all arguments to the old options have been
2189 collected. If this rule is not respected, a modern option might be
2190 falsely interpreted as the value of the argument to one of the old
2191 style options.
2192
2193 For example, all the following commands are wholly equivalent, and
2194 illustrate the many combinations and orderings of option styles.
2195
2196 @smallexample
2197 @kbd{tar --create --file=archive.tar}
2198 @kbd{tar --create -f archive.tar}
2199 @kbd{tar --create -farchive.tar}
2200 @kbd{tar --file=archive.tar --create}
2201 @kbd{tar --file=archive.tar -c}
2202 @kbd{tar -c --file=archive.tar}
2203 @kbd{tar -c -f archive.tar}
2204 @kbd{tar -c -farchive.tar}
2205 @kbd{tar -cf archive.tar}
2206 @kbd{tar -cfarchive.tar}
2207 @kbd{tar -f archive.tar --create}
2208 @kbd{tar -f archive.tar -c}
2209 @kbd{tar -farchive.tar --create}
2210 @kbd{tar -farchive.tar -c}
2211 @kbd{tar c --file=archive.tar}
2212 @kbd{tar c -f archive.tar}
2213 @kbd{tar c -farchive.tar}
2214 @kbd{tar cf archive.tar}
2215 @kbd{tar f archive.tar --create}
2216 @kbd{tar f archive.tar -c}
2217 @kbd{tar fc archive.tar}
2218 @end smallexample
2219
2220 On the other hand, the following commands are @emph{not} equivalent to
2221 the previous set:
2222
2223 @smallexample
2224 @kbd{tar -f -c archive.tar}
2225 @kbd{tar -fc archive.tar}
2226 @kbd{tar -fcarchive.tar}
2227 @kbd{tar -farchive.tarc}
2228 @kbd{tar cfarchive.tar}
2229 @end smallexample
2230
2231 @noindent
2232 These last examples mean something completely different from what the
2233 user intended (judging based on the example in the previous set which
2234 uses long options, whose intent is therefore very clear). The first
2235 four specify that the @command{tar} archive would be a file named
2236 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2237 respectively. The first two examples also specify a single non-option,
2238 @var{name} argument having the value @samp{archive.tar}. The last
2239 example contains only old style option letters (repeating option
2240 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2241 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2242 the first sentence of this paragraph..}
2243
2244 @node All Options
2245 @section All @command{tar} Options
2246
2247 The coming manual sections contain an alphabetical listing of all
2248 @command{tar} operations and options, with brief descriptions and cross
2249 references to more in-depth explanations in the body of the manual.
2250 They also contain an alphabetically arranged table of the short option
2251 forms with their corresponding long option. You can use this table as
2252 a reference for deciphering @command{tar} commands in scripts.
2253
2254 @menu
2255 * Operation Summary::
2256 * Option Summary::
2257 * Short Option Summary::
2258 @end menu
2259
2260 @node Operation Summary
2261 @subsection Operations
2262
2263 @table @option
2264
2265 @opsummary{append}
2266 @item --append
2267 @itemx -r
2268
2269 Appends files to the end of the archive. @xref{append}.
2270
2271 @opsummary{catenate}
2272 @item --catenate
2273 @itemx -A
2274
2275 Same as @option{--concatenate}. @xref{concatenate}.
2276
2277 @opsummary{compare}
2278 @item --compare
2279 @itemx -d
2280
2281 Compares archive members with their counterparts in the file
2282 system, and reports differences in file size, mode, owner,
2283 modification date and contents. @xref{compare}.
2284
2285 @opsummary{concatenate}
2286 @item --concatenate
2287 @itemx -A
2288
2289 Appends other @command{tar} archives to the end of the archive.
2290 @xref{concatenate}.
2291
2292 @opsummary{create}
2293 @item --create
2294 @itemx -c
2295
2296 Creates a new @command{tar} archive. @xref{create}.
2297
2298 @opsummary{delete}
2299 @item --delete
2300
2301 Deletes members from the archive. Don't try this on a archive on a
2302 tape! @xref{delete}.
2303
2304 @opsummary{diff}
2305 @item --diff
2306 @itemx -d
2307
2308 Same @option{--compare}. @xref{compare}.
2309
2310 @opsummary{extract}
2311 @item --extract
2312 @itemx -x
2313
2314 Extracts members from the archive into the file system. @xref{extract}.
2315
2316 @opsummary{get}
2317 @item --get
2318 @itemx -x
2319
2320 Same as @option{--extract}. @xref{extract}.
2321
2322 @opsummary{list}
2323 @item --list
2324 @itemx -t
2325
2326 Lists the members in an archive. @xref{list}.
2327
2328 @opsummary{update}
2329 @item --update
2330 @itemx -u
2331
2332 Adds files to the end of the archive, but only if they are newer than
2333 their counterparts already in the archive, or if they do not already
2334 exist in the archive. @xref{update}.
2335
2336 @end table
2337
2338 @node Option Summary
2339 @subsection @command{tar} Options
2340
2341 @table @option
2342
2343 @opsummary{absolute-names}
2344 @item --absolute-names
2345 @itemx -P
2346
2347 Normally when creating an archive, @command{tar} strips an initial
2348 @samp{/} from member names. This option disables that behavior.
2349 @xref{absolute}.
2350
2351 @opsummary{after-date}
2352 @item --after-date
2353
2354 (See @option{--newer}, @pxref{after})
2355
2356 @opsummary{anchored}
2357 @item --anchored
2358 A pattern must match an initial subsequence of the name's components.
2359 @xref{controlling pattern-matching}.
2360
2361 @opsummary{atime-preserve}
2362 @item --atime-preserve
2363 @itemx --atime-preserve=replace
2364 @itemx --atime-preserve=system
2365
2366 Attempt to preserve the access time of files when reading them. This
2367 option currently is effective only on files that you own, unless you
2368 have superuser privileges.
2369
2370 @option{--atime-preserve=replace} remembers the access time of a file
2371 before reading it, and then restores the access time afterwards. This
2372 may cause problems if other programs are reading the file at the same
2373 time, as the times of their accesses will be lost. On most platforms
2374 restoring the access time also requires @command{tar} to restore the
2375 data modification time too, so this option may also cause problems if
2376 other programs are writing the file at the same time. (Tar attempts
2377 to detect this situation, but cannot do so reliably due to race
2378 conditions.) Worse, on most platforms restoring the access time also
2379 updates the status change time, which means that this option is
2380 incompatible with incremental backups.
2381
2382 @option{--atime-preserve=system} avoids changing time stamps on files,
2383 without interfering with time stamp updates
2384 caused by other programs, so it works better with incremental backups.
2385 However, it requires a special @code{O_NOATIME} option from the
2386 underlying operating and file system implementation, and it also requires
2387 that searching directories does not update their access times. As of
2388 this writing (November 2005) this works only with Linux, and only with
2389 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2390 way to know whether this feature actually works. Sometimes
2391 @command{tar} knows that it does not work, and if you use
2392 @option{--atime-preserve=system} then @command{tar} complains and
2393 exits right away. But other times @command{tar} might think that the
2394 option works when it actually does not.
2395
2396 Currently @option{--atime-preserve} with no operand defaults to
2397 @option{--atime-preserve=replace}, but this may change in the future
2398 as support for @option{--atime-preserve=system} improves.
2399
2400 If your operating system does not support
2401 @option{--atime-preserve=@-system}, you might be able to preserve access
2402 times reliably by by using the @command{mount} command. For example,
2403 you can mount the file system read-only, or access the file system via
2404 a read-only loopback mount, or use the @samp{noatime} mount option
2405 available on some systems. However, mounting typically requires
2406 superuser privileges and can be a pain to manage.
2407
2408 @opsummary{auto-compress}
2409 @item --auto-compress
2410 @itemx -a
2411
2412 During a @option{--create} operation, enables automatic compressed
2413 format recognition based on the archive suffix. @xref{gzip}.
2414
2415 @opsummary{backup}
2416 @item --backup=@var{backup-type}
2417
2418 Rather than deleting files from the file system, @command{tar} will
2419 back them up using simple or numbered backups, depending upon
2420 @var{backup-type}. @xref{backup}.
2421
2422 @opsummary{block-number}
2423 @item --block-number
2424 @itemx -R
2425
2426 With this option present, @command{tar} prints error messages for read errors
2427 with the block number in the archive file. @xref{block-number}.
2428
2429 @opsummary{blocking-factor}
2430 @item --blocking-factor=@var{blocking}
2431 @itemx -b @var{blocking}
2432
2433 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2434 record. @xref{Blocking Factor}.
2435
2436 @opsummary{bzip2}
2437 @item --bzip2
2438 @itemx -j
2439
2440 This option tells @command{tar} to read or write archives through
2441 @code{bzip2}. @xref{gzip}.
2442
2443 @opsummary{checkpoint}
2444 @item --checkpoint[=@var{number}]
2445
2446 This option directs @command{tar} to print periodic checkpoint
2447 messages as it reads through the archive. It is intended for when you
2448 want a visual indication that @command{tar} is still running, but
2449 don't want to see @option{--verbose} output. You can also instruct
2450 @command{tar} to execute a list of actions on each checkpoint, see
2451 @option{--checklist-action} below. For a detailed description, see
2452 @ref{checkpoints}.
2453
2454 @opsummary{checkpoint-action}
2455 @item --checkpoint-action=@var{action}
2456 Instruct @command{tar} to execute an action upon hitting a
2457 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2458 for a complete description.
2459
2460 The @var{action} argument can be one of the following:
2461
2462 @table @asis
2463 @item echo
2464 Display a textual message on the standard error, with the status and
2465 number of the checkpoint. This is the default.
2466
2467 @item echo=@var{string}
2468 Display @var{string} on the standard error. Before output, the string
2469 is subject to meta-character expansion.
2470
2471 @item dot
2472 @itemx .
2473 Print a single dot on the standard listing stream.
2474
2475 @item sleep=@var{time}
2476 Wait for @var{time} seconds.
2477
2478 @item exec=@var{command}
2479 Execute the given @var{command}.
2480 @end table
2481
2482 Several @option{--checkpoint-action} options can be specified. The
2483 supplied actions will be executed in order of their appearance in the
2484 command line.
2485
2486 Using @option{--checkpoint-action} without @option{--checkpoint}
2487 assumes default checkpoint frequency of one checkpoint per 10 records.
2488
2489 @opsummary{check-links}
2490 @item --check-links
2491 @itemx -l
2492 If this option was given, @command{tar} will check the number of links
2493 dumped for each processed file. If this number does not match the
2494 total number of hard links for the file, a warning message will be
2495 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2496 synonym for @option{--one-file-system}. The current semantics, which
2497 complies to UNIX98, was introduced with version
2498 1.15.91. @xref{Changes}, for more information.}.
2499
2500 @xref{hard links}.
2501
2502 @opsummary{compress}
2503 @opsummary{uncompress}
2504 @item --compress
2505 @itemx --uncompress
2506 @itemx -Z
2507
2508 @command{tar} will use the @command{compress} program when reading or
2509 writing the archive. This allows you to directly act on archives
2510 while saving space. @xref{gzip}.
2511
2512 @opsummary{confirmation}
2513 @item --confirmation
2514
2515 (See @option{--interactive}.) @xref{interactive}.
2516
2517 @opsummary{delay-directory-restore}
2518 @item --delay-directory-restore
2519
2520 Delay setting modification times and permissions of extracted
2521 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2522
2523 @opsummary{dereference}
2524 @item --dereference
2525 @itemx -h
2526
2527 When creating a @command{tar} archive, @command{tar} will archive the
2528 file that a symbolic link points to, rather than archiving the
2529 symlink. @xref{dereference}.
2530
2531 @opsummary{directory}
2532 @item --directory=@var{dir}
2533 @itemx -C @var{dir}
2534
2535 When this option is specified, @command{tar} will change its current directory
2536 to @var{dir} before performing any operations. When this option is used
2537 during archive creation, it is order sensitive. @xref{directory}.
2538
2539 @opsummary{exclude}
2540 @item --exclude=@var{pattern}
2541
2542 When performing operations, @command{tar} will skip files that match
2543 @var{pattern}. @xref{exclude}.
2544
2545 @opsummary{exclude-from}
2546 @item --exclude-from=@var{file}
2547 @itemx -X @var{file}
2548
2549 Similar to @option{--exclude}, except @command{tar} will use the list of
2550 patterns in the file @var{file}. @xref{exclude}.
2551
2552 @opsummary{exclude-caches}
2553 @item --exclude-caches
2554
2555 Exclude from dump any directory containing a valid cache directory
2556 tag file, but still dump the directory node and the tag file itself.
2557
2558 @xref{exclude}.
2559
2560 @opsummary{exclude-caches-under}
2561 @item --exclude-caches-under
2562
2563 Exclude from dump any directory containing a valid cache directory
2564 tag file, but still dump the directory node itself.
2565
2566 @xref{exclude}.
2567
2568 @opsummary{exclude-caches-all}
2569 @item --exclude-caches-all
2570
2571 Exclude from dump any directory containing a valid cache directory
2572 tag file. @xref{exclude}.
2573
2574 @opsummary{exclude-tag}
2575 @item --exclude-tag=@var{file}
2576
2577 Exclude from dump any directory containing file named @var{file}, but
2578 dump the directory node and @var{file} itself. @xref{exclude}.
2579
2580 @opsummary{exclude-tag-under}
2581 @item --exclude-tag-under=@var{file}
2582
2583 Exclude from dump the contents of any directory containing file
2584 named @var{file}, but dump the directory node itself. @xref{exclude}.
2585
2586 @opsummary{exclude-tag-all}
2587 @item --exclude-tag-all=@var{file}
2588
2589 Exclude from dump any directory containing file named @var{file}.
2590 @xref{exclude}.
2591
2592 @opsummary{exclude-vcs}
2593 @item --exclude-vcs
2594
2595 Exclude from dump directories and files, that are internal for some
2596 widely used version control systems.
2597
2598 @xref{exclude}.
2599
2600 @opsummary{file}
2601 @item --file=@var{archive}
2602 @itemx -f @var{archive}
2603
2604 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2605 performs operations on, rather than @command{tar}'s compilation dependent
2606 default. @xref{file tutorial}.
2607
2608 @opsummary{files-from}
2609 @item --files-from=@var{file}
2610 @itemx -T @var{file}
2611
2612 @command{tar} will use the contents of @var{file} as a list of archive members
2613 or files to operate on, in addition to those specified on the
2614 command-line. @xref{files}.
2615
2616 @opsummary{force-local}
2617 @item --force-local
2618
2619 Forces @command{tar} to interpret the file name given to @option{--file}
2620 as a local file, even if it looks like a remote tape drive name.
2621 @xref{local and remote archives}.
2622
2623 @opsummary{format}
2624 @item --format=@var{format}
2625 @itemx -H @var{format}
2626
2627 Selects output archive format. @var{Format} may be one of the
2628 following:
2629
2630 @table @samp
2631 @item v7
2632 Creates an archive that is compatible with Unix V7 @command{tar}.
2633
2634 @item oldgnu
2635 Creates an archive that is compatible with GNU @command{tar} version
2636 1.12 or earlier.
2637
2638 @item gnu
2639 Creates archive in GNU tar 1.13 format. Basically it is the same as
2640 @samp{oldgnu} with the only difference in the way it handles long
2641 numeric fields.
2642
2643 @item ustar
2644 Creates a @acronym{POSIX.1-1988} compatible archive.
2645
2646 @item posix
2647 Creates a @acronym{POSIX.1-2001 archive}.
2648
2649 @end table
2650
2651 @xref{Formats}, for a detailed discussion of these formats.
2652
2653 @opsummary{group}
2654 @item --group=@var{group}
2655
2656 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2657 rather than the group from the source file. @var{group} is first decoded
2658 as a group symbolic name, but if this interpretation fails, it has to be
2659 a decimal numeric group @acronym{ID}. @xref{override}.
2660
2661 Also see the comments for the @option{--owner=@var{user}} option.
2662
2663 @opsummary{gzip}
2664 @opsummary{gunzip}
2665 @opsummary{ungzip}
2666 @item --gzip
2667 @itemx --gunzip
2668 @itemx --ungzip
2669 @itemx -z
2670
2671 This option tells @command{tar} to read or write archives through
2672 @command{gzip}, allowing @command{tar} to directly operate on several
2673 kinds of compressed archives transparently. @xref{gzip}.
2674
2675 @opsummary{hard-dereference}
2676 @item --hard-dereference
2677 When creating an archive, dereference hard links and store the files
2678 they refer to, instead of creating usual hard link members.
2679
2680 @xref{hard links}.
2681
2682 @opsummary{help}
2683 @item --help
2684 @itemx -?
2685
2686 @command{tar} will print out a short message summarizing the operations and
2687 options to @command{tar} and exit. @xref{help}.
2688
2689 @opsummary{ignore-case}
2690 @item --ignore-case
2691 Ignore case when matching member or file names with
2692 patterns. @xref{controlling pattern-matching}.
2693
2694 @opsummary{ignore-command-error}
2695 @item --ignore-command-error
2696 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2697
2698 @opsummary{ignore-failed-read}
2699 @item --ignore-failed-read
2700
2701 Do not exit unsuccessfully merely because an unreadable file was encountered.
2702 @xref{Reading}.
2703
2704 @opsummary{ignore-zeros}
2705 @item --ignore-zeros
2706 @itemx -i
2707
2708 With this option, @command{tar} will ignore zeroed blocks in the
2709 archive, which normally signals EOF. @xref{Reading}.
2710
2711 @opsummary{incremental}
2712 @item --incremental
2713 @itemx -G
2714
2715 Informs @command{tar} that it is working with an old
2716 @acronym{GNU}-format incremental backup archive. It is intended
2717 primarily for backwards compatibility only. @xref{Incremental Dumps},
2718 for a detailed discussion of incremental archives.
2719
2720 @opsummary{index-file}
2721 @item --index-file=@var{file}
2722
2723 Send verbose output to @var{file} instead of to standard output.
2724
2725 @opsummary{info-script}
2726 @opsummary{new-volume-script}
2727 @item --info-script=@var{script-file}
2728 @itemx --new-volume-script=@var{script-file}
2729 @itemx -F @var{script-file}
2730
2731 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2732 at the end of each tape. If @var{script-file} exits with nonzero status,
2733 @command{tar} fails immediately. @xref{info-script}, for a detailed
2734 discussion of @var{script-file}.
2735
2736 @opsummary{interactive}
2737 @item --interactive
2738 @itemx --confirmation
2739 @itemx -w
2740
2741 Specifies that @command{tar} should ask the user for confirmation before
2742 performing potentially destructive options, such as overwriting files.
2743 @xref{interactive}.
2744
2745 @opsummary{keep-newer-files}
2746 @item --keep-newer-files
2747
2748 Do not replace existing files that are newer than their archive copies
2749 when extracting files from an archive.
2750
2751 @opsummary{keep-old-files}
2752 @item --keep-old-files
2753 @itemx -k
2754
2755 Do not overwrite existing files when extracting files from an archive.
2756 @xref{Keep Old Files}.
2757
2758 @opsummary{label}
2759 @item --label=@var{name}
2760 @itemx -V @var{name}
2761
2762 When creating an archive, instructs @command{tar} to write @var{name}
2763 as a name record in the archive. When extracting or listing archives,
2764 @command{tar} will only operate on archives that have a label matching
2765 the pattern specified in @var{name}. @xref{Tape Files}.
2766
2767 @opsummary{listed-incremental}
2768 @item --listed-incremental=@var{snapshot-file}
2769 @itemx -g @var{snapshot-file}
2770
2771 During a @option{--create} operation, specifies that the archive that
2772 @command{tar} creates is a new @acronym{GNU}-format incremental
2773 backup, using @var{snapshot-file} to determine which files to backup.
2774 With other operations, informs @command{tar} that the archive is in
2775 incremental format. @xref{Incremental Dumps}.
2776
2777 @opsummary{lzma}
2778 @item --lzma
2779
2780 This option tells @command{tar} to read or write archives through
2781 @command{lzma}. @xref{gzip}.
2782
2783 @opsummary{mode}
2784 @item --mode=@var{permissions}
2785
2786 When adding files to an archive, @command{tar} will use
2787 @var{permissions} for the archive members, rather than the permissions
2788 from the files. @var{permissions} can be specified either as an octal
2789 number or as symbolic permissions, like with
2790 @command{chmod}. @xref{override}.
2791
2792 @opsummary{mtime}
2793 @item --mtime=@var{date}
2794
2795 When adding files to an archive, @command{tar} will use @var{date} as
2796 the modification time of members when creating archives, instead of
2797 their actual modification times. The value of @var{date} can be
2798 either a textual date representation (@pxref{Date input formats}) or a
2799 name of the existing file, starting with @samp{/} or @samp{.}. In the
2800 latter case, the modification time of that file is used. @xref{override}.
2801
2802 @opsummary{multi-volume}
2803 @item --multi-volume
2804 @itemx -M
2805
2806 Informs @command{tar} that it should create or otherwise operate on a
2807 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2808
2809 @opsummary{new-volume-script}
2810 @item --new-volume-script
2811
2812 (see --info-script)
2813
2814 @opsummary{newer}
2815 @item --newer=@var{date}
2816 @itemx --after-date=@var{date}
2817 @itemx -N
2818
2819 When creating an archive, @command{tar} will only add files that have changed
2820 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2821 is taken to be the name of a file whose data modification time specifies
2822 the date. @xref{after}.
2823
2824 @opsummary{newer-mtime}
2825 @item --newer-mtime=@var{date}
2826
2827 Like @option{--newer}, but add only files whose
2828 contents have changed (as opposed to just @option{--newer}, which will
2829 also back up files for which any status information has
2830 changed). @xref{after}.
2831
2832 @opsummary{no-anchored}
2833 @item --no-anchored
2834 An exclude pattern can match any subsequence of the name's components.
2835 @xref{controlling pattern-matching}.
2836
2837 @opsummary{no-delay-directory-restore}
2838 @item --no-delay-directory-restore
2839
2840 Modification times and permissions of extracted
2841 directories are set when all files from this directory have been
2842 extracted. This is the default.
2843 @xref{Directory Modification Times and Permissions}.
2844
2845 @opsummary{no-ignore-case}
2846 @item --no-ignore-case
2847 Use case-sensitive matching.
2848 @xref{controlling pattern-matching}.
2849
2850 @opsummary{no-ignore-command-error}
2851 @item --no-ignore-command-error
2852 Print warnings about subprocesses that terminated with a nonzero exit
2853 code. @xref{Writing to an External Program}.
2854
2855 @opsummary{no-overwrite-dir}
2856 @item --no-overwrite-dir
2857
2858 Preserve metadata of existing directories when extracting files
2859 from an archive. @xref{Overwrite Old Files}.
2860
2861 @opsummary{no-quote-chars}
2862 @item --no-quote-chars=@var{string}
2863 Remove characters listed in @var{string} from the list of quoted
2864 characters set by the previous @option{--quote-chars} option
2865 (@pxref{quoting styles}).
2866
2867 @opsummary{no-recursion}
2868 @item --no-recursion
2869
2870 With this option, @command{tar} will not recurse into directories.
2871 @xref{recurse}.
2872
2873 @opsummary{no-same-owner}
2874 @item --no-same-owner
2875 @itemx -o
2876
2877 When extracting an archive, do not attempt to preserve the owner
2878 specified in the @command{tar} archive. This the default behavior
2879 for ordinary users.
2880
2881 @opsummary{no-same-permissions}
2882 @item --no-same-permissions
2883
2884 When extracting an archive, subtract the user's umask from files from
2885 the permissions specified in the archive. This is the default behavior
2886 for ordinary users.
2887
2888 @opsummary{no-unquote}
2889 @item --no-unquote
2890 Treat all input file or member names literally, do not interpret
2891 escape sequences. @xref{input name quoting}.
2892
2893 @opsummary{no-wildcards}
2894 @item --no-wildcards
2895 Do not use wildcards.
2896 @xref{controlling pattern-matching}.
2897
2898 @opsummary{no-wildcards-match-slash}
2899 @item --no-wildcards-match-slash
2900 Wildcards do not match @samp{/}.
2901 @xref{controlling pattern-matching}.
2902
2903 @opsummary{null}
2904 @item --null
2905
2906 When @command{tar} is using the @option{--files-from} option, this option
2907 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
2908 @command{tar} can correctly work with file names that contain newlines.
2909 @xref{nul}.
2910
2911 @opsummary{numeric-owner}
2912 @item --numeric-owner
2913
2914 This option will notify @command{tar} that it should use numeric user
2915 and group IDs when creating a @command{tar} file, rather than names.
2916 @xref{Attributes}.
2917
2918 @item -o
2919 The function of this option depends on the action @command{tar} is
2920 performing. When extracting files, @option{-o} is a synonym for
2921 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2922 restoring ownership of files being extracted.
2923
2924 When creating an archive, it is a synonym for
2925 @option{--old-archive}. This behavior is for compatibility
2926 with previous versions of @GNUTAR{}, and will be
2927 removed in future releases.
2928
2929 @xref{Changes}, for more information.
2930
2931 @opsummary{occurrence}
2932 @item --occurrence[=@var{number}]
2933
2934 This option can be used in conjunction with one of the subcommands
2935 @option{--delete}, @option{--diff}, @option{--extract} or
2936 @option{--list} when a list of files is given either on the command
2937 line or via @option{-T} option.
2938
2939 This option instructs @command{tar} to process only the @var{number}th
2940 occurrence of each named file. @var{Number} defaults to 1, so
2941
2942 @smallexample
2943 tar -x -f archive.tar --occurrence filename
2944 @end smallexample
2945
2946 @noindent
2947 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2948 and will terminate without scanning to the end of the archive.
2949
2950 @opsummary{old-archive}
2951 @item --old-archive
2952 Synonym for @option{--format=v7}.
2953
2954 @opsummary{one-file-system}
2955 @item --one-file-system
2956 Used when creating an archive. Prevents @command{tar} from recursing into
2957 directories that are on different file systems from the current
2958 directory.
2959
2960 @opsummary{overwrite}
2961 @item --overwrite
2962
2963 Overwrite existing files and directory metadata when extracting files
2964 from an archive. @xref{Overwrite Old Files}.
2965
2966 @opsummary{overwrite-dir}
2967 @item --overwrite-dir
2968
2969 Overwrite the metadata of existing directories when extracting files
2970 from an archive. @xref{Overwrite Old Files}.
2971
2972 @opsummary{owner}
2973 @item --owner=@var{user}
2974
2975 Specifies that @command{tar} should use @var{user} as the owner of members
2976 when creating archives, instead of the user associated with the source
2977 file. @var{user} is first decoded as a user symbolic name, but if
2978 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
2979 @xref{override}.
2980
2981 This option does not affect extraction from archives.
2982
2983 @opsummary{pax-option}
2984 @item --pax-option=@var{keyword-list}
2985 This option is meaningful only with @acronym{POSIX.1-2001} archives
2986 (@pxref{posix}). It modifies the way @command{tar} handles the
2987 extended header keywords. @var{Keyword-list} is a comma-separated
2988 list of keyword options. @xref{PAX keywords}, for a detailed
2989 discussion.
2990
2991 @opsummary{portability}
2992 @item --portability
2993 @itemx --old-archive
2994 Synonym for @option{--format=v7}.
2995
2996 @opsummary{posix}
2997 @item --posix
2998 Same as @option{--format=posix}.
2999
3000 @opsummary{preserve}
3001 @item --preserve
3002
3003 Synonymous with specifying both @option{--preserve-permissions} and
3004 @option{--same-order}. @xref{Setting Access Permissions}.
3005
3006 @opsummary{preserve-order}
3007 @item --preserve-order
3008
3009 (See @option{--same-order}; @pxref{Reading}.)
3010
3011 @opsummary{preserve-permissions}
3012 @opsummary{same-permissions}
3013 @item --preserve-permissions
3014 @itemx --same-permissions
3015 @itemx -p
3016
3017 When @command{tar} is extracting an archive, it normally subtracts the
3018 users' umask from the permissions specified in the archive and uses
3019 that number as the permissions to create the destination file.
3020 Specifying this option instructs @command{tar} that it should use the
3021 permissions directly from the archive. @xref{Setting Access Permissions}.
3022
3023 @opsummary{quote-chars}
3024 @item --quote-chars=@var{string}
3025 Always quote characters from @var{string}, even if the selected
3026 quoting style would not quote them (@pxref{quoting styles}).
3027
3028 @opsummary{quoting-style}
3029 @item --quoting-style=@var{style}
3030 Set quoting style to use when printing member and file names
3031 (@pxref{quoting styles}). Valid @var{style} values are:
3032 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3033 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3034 style is @code{escape}, unless overridden while configuring the
3035 package.
3036
3037 @opsummary{read-full-records}
3038 @item --read-full-records
3039 @itemx -B
3040
3041 Specifies that @command{tar} should reblock its input, for reading
3042 from pipes on systems with buggy implementations. @xref{Reading}.
3043
3044 @opsummary{record-size}
3045 @item --record-size=@var{size}
3046
3047 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3048 archive. @xref{Blocking Factor}.
3049
3050 @opsummary{recursion}
3051 @item --recursion
3052
3053 With this option, @command{tar} recurses into directories (default).
3054 @xref{recurse}.
3055
3056 @opsummary{recursive-unlink}
3057 @item --recursive-unlink
3058
3059 Remove existing
3060 directory hierarchies before extracting directories of the same name
3061 from the archive. @xref{Recursive Unlink}.
3062
3063 @opsummary{remove-files}
3064 @item --remove-files
3065
3066 Directs @command{tar} to remove the source file from the file system after
3067 appending it to an archive. @xref{remove files}.
3068
3069 @opsummary{restrict}
3070 @item --restrict
3071
3072 Disable use of some potentially harmful @command{tar} options.
3073 Currently this option disables shell invocation from multi-volume menu
3074 (@pxref{Using Multiple Tapes}).
3075
3076 @opsummary{rmt-command}
3077 @item --rmt-command=@var{cmd}
3078
3079 Notifies @command{tar} that it should use @var{cmd} instead of
3080 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3081
3082 @opsummary{rsh-command}
3083 @item --rsh-command=@var{cmd}
3084
3085 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3086 devices. @xref{Device}.
3087
3088 @opsummary{same-order}
3089 @item --same-order
3090 @itemx --preserve-order
3091 @itemx -s
3092
3093 This option is an optimization for @command{tar} when running on machines with
3094 small amounts of memory. It informs @command{tar} that the list of file
3095 arguments has already been sorted to match the order of files in the
3096 archive. @xref{Reading}.
3097
3098 @opsummary{same-owner}
3099 @item --same-owner
3100
3101 When extracting an archive, @command{tar} will attempt to preserve the owner
3102 specified in the @command{tar} archive with this option present.
3103 This is the default behavior for the superuser; this option has an
3104 effect only for ordinary users. @xref{Attributes}.
3105
3106 @opsummary{same-permissions}
3107 @item --same-permissions
3108
3109 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3110
3111 @opsummary{seek}
3112 @item --seek
3113 @itemx -n
3114
3115 Assume that the archive media supports seeks to arbitrary
3116 locations. Usually @command{tar} determines automatically whether
3117 the archive can be seeked or not. This option is intended for use
3118 in cases when such recognition fails.
3119
3120 @opsummary{show-defaults}
3121 @item --show-defaults
3122
3123 Displays the default options used by @command{tar} and exits
3124 successfully. This option is intended for use in shell scripts.
3125 Here is an example of what you can see using this option:
3126
3127 @smallexample
3128 $ tar --show-defaults
3129 --format=gnu -f- -b20 --quoting-style=escape \
3130 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3131 @end smallexample
3132
3133 @opsummary{show-omitted-dirs}
3134 @item --show-omitted-dirs
3135
3136 Instructs @command{tar} to mention the directories it is skipping when
3137 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3138
3139 @opsummary{show-transformed-names}
3140 @opsummary{show-stored-names}
3141 @item --show-transformed-names
3142 @itemx --show-stored-names
3143
3144 Display file or member names after applying any transformations
3145 (@pxref{transform}). In particular, when used in conjunction with one of
3146 the archive creation operations it instructs @command{tar} to list the
3147 member names stored in the archive, as opposed to the actual file
3148 names. @xref{listing member and file names}.
3149
3150 @opsummary{sparse}
3151 @item --sparse
3152 @itemx -S
3153
3154 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3155 sparse files efficiently. @xref{sparse}.
3156
3157 @opsummary{sparse-version}
3158 @item --sparse-version=@var{version}
3159
3160 Specifies the @dfn{format version} to use when archiving sparse
3161 files. Implies @option{--sparse}. @xref{sparse}. For the description
3162 of the supported sparse formats, @xref{Sparse Formats}.
3163
3164 @opsummary{starting-file}
3165 @item --starting-file=@var{name}
3166 @itemx -K @var{name}
3167
3168 This option affects extraction only; @command{tar} will skip extracting
3169 files in the archive until it finds one that matches @var{name}.
3170 @xref{Scarce}.
3171
3172 @opsummary{strip-components}
3173 @item --strip-components=@var{number}
3174 Strip given @var{number} of leading components from file names before
3175 extraction. For example, if archive @file{archive.tar} contained
3176 @file{/some/file/name}, then running
3177
3178 @smallexample
3179 tar --extract --file archive.tar --strip-components=2
3180 @end smallexample
3181
3182 @noindent
3183 would extract this file to file @file{name}.
3184
3185 @opsummary{suffix}, summary
3186 @item --suffix=@var{suffix}
3187
3188 Alters the suffix @command{tar} uses when backing up files from the default
3189 @samp{~}. @xref{backup}.
3190
3191 @opsummary{tape-length}
3192 @item --tape-length=@var{num}
3193 @itemx -L @var{num}
3194
3195 Specifies the length of tapes that @command{tar} is writing as being
3196 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3197
3198 @opsummary{test-label}
3199 @item --test-label
3200
3201 Reads the volume label. If an argument is specified, test whether it
3202 matches the volume label. @xref{--test-label option}.
3203
3204 @opsummary{to-command}
3205 @item --to-command=@var{command}
3206
3207 During extraction @command{tar} will pipe extracted files to the
3208 standard input of @var{command}. @xref{Writing to an External Program}.
3209
3210 @opsummary{to-stdout}
3211 @item --to-stdout
3212 @itemx -O
3213
3214 During extraction, @command{tar} will extract files to stdout rather
3215 than to the file system. @xref{Writing to Standard Output}.
3216
3217 @opsummary{totals}
3218 @item --totals[=@var{signo}]
3219
3220 Displays the total number of bytes transferred when processing an
3221 archive. If an argument is given, these data are displayed on
3222 request, when signal @var{signo} is delivered to @command{tar}.
3223 @xref{totals}.
3224
3225 @opsummary{touch}
3226 @item --touch
3227 @itemx -m
3228
3229 Sets the data modification time of extracted files to the extraction time,
3230 rather than the data modification time stored in the archive.
3231 @xref{Data Modification Times}.
3232
3233 @opsummary{transform}
3234 @item --transform=@var{sed-expr}
3235
3236 Transform file or member names using @command{sed} replacement expression
3237 @var{sed-expr}. For example,
3238
3239 @smallexample
3240 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3241 @end smallexample
3242
3243 @noindent
3244 will add to @file{archive} files from the current working directory,
3245 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3246 discussion, @xref{transform}.
3247
3248 To see transformed member names in verbose listings, use
3249 @option{--show-transformed-names} option
3250 (@pxref{show-transformed-names}).
3251
3252 @opsummary{uncompress}
3253 @item --uncompress
3254
3255 (See @option{--compress}. @pxref{gzip})
3256
3257 @opsummary{ungzip}
3258 @item --ungzip
3259
3260 (See @option{--gzip}. @pxref{gzip})
3261
3262 @opsummary{unlink-first}
3263 @item --unlink-first
3264 @itemx -U
3265
3266 Directs @command{tar} to remove the corresponding file from the file
3267 system before extracting it from the archive. @xref{Unlink First}.
3268
3269 @opsummary{unquote}
3270 @item --unquote
3271 Enable unquoting input file or member names (default). @xref{input
3272 name quoting}.
3273
3274 @opsummary{use-compress-program}
3275 @item --use-compress-program=@var{prog}
3276
3277 Instructs @command{tar} to access the archive through @var{prog}, which is
3278 presumed to be a compression program of some sort. @xref{gzip}.
3279
3280 @opsummary{utc}
3281 @item --utc
3282
3283 Display file modification dates in @acronym{UTC}. This option implies
3284 @option{--verbose}.
3285
3286 @opsummary{verbose}
3287 @item --verbose
3288 @itemx -v
3289
3290 Specifies that @command{tar} should be more verbose about the
3291 operations it is performing. This option can be specified multiple
3292 times for some operations to increase the amount of information displayed.
3293 @xref{verbose}.
3294
3295 @opsummary{verify}
3296 @item --verify
3297 @itemx -W
3298
3299 Verifies that the archive was correctly written when creating an
3300 archive. @xref{verify}.
3301
3302 @opsummary{version}
3303 @item --version
3304
3305 Print information about the program's name, version, origin and legal
3306 status, all on standard output, and then exit successfully.
3307 @xref{help}.
3308
3309 @opsummary{volno-file}
3310 @item --volno-file=@var{file}
3311
3312 Used in conjunction with @option{--multi-volume}. @command{tar} will
3313 keep track of which volume of a multi-volume archive it is working in
3314 @var{file}. @xref{volno-file}.
3315
3316 @opsummary{wildcards}
3317 @item --wildcards
3318 Use wildcards when matching member names with patterns.
3319 @xref{controlling pattern-matching}.
3320
3321 @opsummary{wildcards-match-slash}
3322 @item --wildcards-match-slash
3323 Wildcards match @samp{/}.
3324 @xref{controlling pattern-matching}.
3325 @end table
3326
3327 @node Short Option Summary
3328 @subsection Short Options Cross Reference
3329
3330 Here is an alphabetized list of all of the short option forms, matching
3331 them with the equivalent long option.
3332
3333 @multitable @columnfractions 0.20 0.80
3334 @headitem Short Option @tab Reference
3335
3336 @item -A @tab @ref{--concatenate}.
3337
3338 @item -B @tab @ref{--read-full-records}.
3339
3340 @item -C @tab @ref{--directory}.
3341
3342 @item -F @tab @ref{--info-script}.
3343
3344 @item -G @tab @ref{--incremental}.
3345
3346 @item -K @tab @ref{--starting-file}.
3347
3348 @item -L @tab @ref{--tape-length}.
3349
3350 @item -M @tab @ref{--multi-volume}.
3351
3352 @item -N @tab @ref{--newer}.
3353
3354 @item -O @tab @ref{--to-stdout}.
3355
3356 @item -P @tab @ref{--absolute-names}.
3357
3358 @item -R @tab @ref{--block-number}.
3359
3360 @item -S @tab @ref{--sparse}.
3361
3362 @item -T @tab @ref{--files-from}.
3363
3364 @item -U @tab @ref{--unlink-first}.
3365
3366 @item -V @tab @ref{--label}.
3367
3368 @item -W @tab @ref{--verify}.
3369
3370 @item -X @tab @ref{--exclude-from}.
3371
3372 @item -Z @tab @ref{--compress}.
3373
3374 @item -b @tab @ref{--blocking-factor}.
3375
3376 @item -c @tab @ref{--create}.
3377
3378 @item -d @tab @ref{--compare}.
3379
3380 @item -f @tab @ref{--file}.
3381
3382 @item -g @tab @ref{--listed-incremental}.
3383
3384 @item -h @tab @ref{--dereference}.
3385
3386 @item -i @tab @ref{--ignore-zeros}.
3387
3388 @item -j @tab @ref{--bzip2}.
3389
3390 @item -k @tab @ref{--keep-old-files}.
3391
3392 @item -l @tab @ref{--check-links}.
3393
3394 @item -m @tab @ref{--touch}.
3395
3396 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3397 @ref{--portability}.
3398
3399 The later usage is deprecated. It is retained for compatibility with
3400 the earlier versions of @GNUTAR{}. In future releases
3401 @option{-o} will be equivalent to @option{--no-same-owner} only.
3402
3403 @item -p @tab @ref{--preserve-permissions}.
3404
3405 @item -r @tab @ref{--append}.
3406
3407 @item -s @tab @ref{--same-order}.
3408
3409 @item -t @tab @ref{--list}.
3410
3411 @item -u @tab @ref{--update}.
3412
3413 @item -v @tab @ref{--verbose}.
3414
3415 @item -w @tab @ref{--interactive}.
3416
3417 @item -x @tab @ref{--extract}.
3418
3419 @item -z @tab @ref{--gzip}.
3420
3421 @end multitable
3422
3423 @node help
3424 @section @GNUTAR{} documentation
3425
3426 @cindex Getting program version number
3427 @opindex version
3428 @cindex Version of the @command{tar} program
3429 Being careful, the first thing is really checking that you are using
3430 @GNUTAR{}, indeed. The @option{--version} option
3431 causes @command{tar} to print information about its name, version,
3432 origin and legal status, all on standard output, and then exit
3433 successfully. For example, @w{@samp{tar --version}} might print:
3434
3435 @smallexample
3436 tar (GNU tar) @value{VERSION}
3437 Copyright (C) 2006 Free Software Foundation, Inc.
3438 This is free software. You may redistribute copies of it under the terms
3439 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3440 There is NO WARRANTY, to the extent permitted by law.
3441
3442 Written by John Gilmore and Jay Fenlason.
3443 @end smallexample
3444
3445 @noindent
3446 The first occurrence of @samp{tar} in the result above is the program
3447 name in the package (for example, @command{rmt} is another program),
3448 while the second occurrence of @samp{tar} is the name of the package
3449 itself, containing possibly many programs. The package is currently
3450 named @samp{tar}, after the name of the main program it
3451 contains@footnote{There are plans to merge the @command{cpio} and
3452 @command{tar} packages into a single one which would be called
3453 @code{paxutils}. So, who knows if, one of this days, the
3454 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3455 paxutils) 3.2}}}.
3456
3457 @cindex Obtaining help
3458 @cindex Listing all @command{tar} options
3459 @xopindex{help, introduction}
3460 Another thing you might want to do is checking the spelling or meaning
3461 of some particular @command{tar} option, without resorting to this
3462 manual, for once you have carefully read it. @GNUTAR{}
3463 has a short help feature, triggerable through the
3464 @option{--help} option. By using this option, @command{tar} will
3465 print a usage message listing all available options on standard
3466 output, then exit successfully, without doing anything else and
3467 ignoring all other options. Even if this is only a brief summary, it
3468 may be several screens long. So, if you are not using some kind of
3469 scrollable window, you might prefer to use something like:
3470
3471 @smallexample
3472 $ @kbd{tar --help | less}
3473 @end smallexample
3474
3475 @noindent
3476 presuming, here, that you like using @command{less} for a pager. Other
3477 popular pagers are @command{more} and @command{pg}. If you know about some
3478 @var{keyword} which interests you and do not want to read all the
3479 @option{--help} output, another common idiom is doing:
3480
3481 @smallexample
3482 tar --help | grep @var{keyword}
3483 @end smallexample
3484
3485 @noindent
3486 for getting only the pertinent lines. Notice, however, that some
3487 @command{tar} options have long description lines and the above
3488 command will list only the first of them.
3489
3490 The exact look of the option summary displayed by @kbd{tar --help} is
3491 configurable. @xref{Configuring Help Summary}, for a detailed description.
3492
3493 @opindex usage
3494 If you only wish to check the spelling of an option, running @kbd{tar
3495 --usage} may be a better choice. This will display a terse list of
3496 @command{tar} option without accompanying explanations.
3497
3498 The short help output is quite succinct, and you might have to get
3499 back to the full documentation for precise points. If you are reading
3500 this paragraph, you already have the @command{tar} manual in some
3501 form. This manual is available in a variety of forms from
3502 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3503 distribution, provided you have @TeX{} already installed somewhere,
3504 and a laser printer around. Just configure the distribution, execute
3505 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3506 usual way (contact your local guru to know how). If @GNUTAR{}
3507 has been conveniently installed at your place, this
3508 manual is also available in interactive, hypertextual form as an Info
3509 file. Just call @w{@samp{info tar}} or, if you do not have the
3510 @command{info} program handy, use the Info reader provided within
3511 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3512
3513 There is currently no @code{man} page for @GNUTAR{}.
3514 If you observe such a @code{man} page on the system you are running,
3515 either it does not belong to @GNUTAR{}, or it has not
3516 been produced by @acronym{GNU}. Some package maintainers convert
3517 @kbd{tar --help} output to a man page, using @command{help2man}. In
3518 any case, please bear in mind that the authoritative source of
3519 information about @GNUTAR{} is this Texinfo documentation.
3520
3521 @node defaults
3522 @section Obtaining @GNUTAR{} default values
3523
3524 @opindex show-defaults
3525 @GNUTAR{} has some predefined defaults that are used when you do not
3526 explicitly specify another values. To obtain a list of such
3527 defaults, use @option{--show-defaults} option. This will output the
3528 values in the form of @command{tar} command line options:
3529
3530 @smallexample
3531 @group
3532 @kbd{tar --show-defaults}
3533 --format=gnu -f- -b20 --quoting-style=escape
3534 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3535 @end group
3536 @end smallexample
3537
3538 @noindent
3539 Notice, that this option outputs only one line. The example output above
3540 has been split to fit page boundaries.
3541
3542 @noindent
3543 The above output shows that this version of @GNUTAR{} defaults to
3544 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3545 output as the archive, if no @option{--file} option has been given
3546 (@pxref{file tutorial}), the default blocking factor is 20
3547 (@pxref{Blocking Factor}). It also shows the default locations where
3548 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3549
3550 @node verbose
3551 @section Checking @command{tar} progress
3552
3553 Typically, @command{tar} performs most operations without reporting any
3554 information to the user except error messages. When using @command{tar}
3555 with many options, particularly ones with complicated or
3556 difficult-to-predict behavior, it is possible to make serious mistakes.
3557 @command{tar} provides several options that make observing @command{tar}
3558 easier. These options cause @command{tar} to print information as it
3559 progresses in its job, and you might want to use them just for being
3560 more careful about what is going on, or merely for entertaining
3561 yourself. If you have encountered a problem when operating on an
3562 archive, however, you may need more information than just an error
3563 message in order to solve the problem. The following options can be
3564 helpful diagnostic tools.
3565
3566 @cindex Verbose operation
3567 @opindex verbose
3568 Normally, the @option{--list} (@option{-t}) command to list an archive
3569 prints just the file names (one per line) and the other commands are
3570 silent. When used with most operations, the @option{--verbose}
3571 (@option{-v}) option causes @command{tar} to print the name of each
3572 file or archive member as it is processed. This and the other options
3573 which make @command{tar} print status information can be useful in
3574 monitoring @command{tar}.
3575
3576 With @option{--create} or @option{--extract}, @option{--verbose} used
3577 once just prints the names of the files or members as they are processed.
3578 Using it twice causes @command{tar} to print a longer listing
3579 (@xref{verbose member listing}, for the description) for each member.
3580 Since @option{--list} already prints the names of the members,
3581 @option{--verbose} used once with @option{--list} causes @command{tar}
3582 to print an @samp{ls -l} type listing of the files in the archive.
3583 The following examples both extract members with long list output:
3584
3585 @smallexample
3586 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3587 $ @kbd{tar xvvf archive.tar}
3588 @end smallexample
3589
3590 Verbose output appears on the standard output except when an archive is
3591 being written to the standard output, as with @samp{tar --create
3592 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3593 installer let standard output be the default archive). In that case
3594 @command{tar} writes verbose output to the standard error stream.
3595
3596 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3597 verbose output to @var{file} rather than to standard output or standard
3598 error.
3599
3600 @anchor{totals}
3601 @cindex Obtaining total status information
3602 @opindex totals
3603 The @option{--totals} option causes @command{tar} to print on the
3604 standard error the total amount of bytes transferred when processing
3605 an archive. When creating or appending to an archive, this option
3606 prints the number of bytes written to the archive and the average
3607 speed at which they have been written, e.g.:
3608
3609 @smallexample
3610 @group
3611 $ @kbd{tar -c -f archive.tar --totals /home}
3612 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3613 @end group
3614 @end smallexample
3615
3616 When reading an archive, this option displays the number of bytes
3617 read:
3618
3619 @smallexample
3620 @group
3621 $ @kbd{tar -x -f archive.tar --totals}
3622 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3623 @end group
3624 @end smallexample
3625
3626 Finally, when deleting from an archive, the @option{--totals} option
3627 displays both numbers plus number of bytes removed from the archive:
3628
3629 @smallexample
3630 @group
3631 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3632 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3633 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3634 Total bytes deleted: 1474048
3635 @end group
3636 @end smallexample
3637
3638 You can also obtain this information on request. When
3639 @option{--totals} is used with an argument, this argument is
3640 interpreted as a symbolic name of a signal, upon delivery of which the
3641 statistics is to be printed:
3642
3643 @table @option
3644 @item --totals=@var{signo}
3645 Print statistics upon delivery of signal @var{signo}. Valid arguments
3646 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3647 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3648 accepted.
3649 @end table
3650
3651 Both forms of @option{--totals} option can be used simultaneously.
3652 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3653 extract all members from its default archive and print statistics
3654 after finishing the extraction, as well as when receiving signal
3655 @code{SIGUSR1}.
3656
3657 @anchor{Progress information}
3658 @cindex Progress information
3659 The @option{--checkpoint} option prints an occasional message
3660 as @command{tar} reads or writes the archive. It is designed for
3661 those who don't need the more detailed (and voluminous) output of
3662 @option{--block-number} (@option{-R}), but do want visual confirmation
3663 that @command{tar} is actually making forward progress. By default it
3664 prints a message each 10 records read or written. This can be changed
3665 by giving it a numeric argument after an equal sign:
3666
3667 @smallexample
3668 $ @kbd{tar -c --checkpoint=1000} /var
3669 tar: Write checkpoint 1000
3670 tar: Write checkpoint 2000
3671 tar: Write checkpoint 3000
3672 @end smallexample
3673
3674 This example shows the default checkpoint message used by
3675 @command{tar}. If you place a dot immediately after the equal
3676 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3677 actually a shortcut for @option{--checkpoint=@var{n}
3678 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3679
3680 @smallexample
3681 $ @kbd{tar -c --checkpoint=.1000} /var
3682 ...
3683 @end smallexample
3684
3685 The @option{--checkpoint} option provides a flexible mechanism for
3686 executing arbitrary actions upon hitting checkpoints, see the next
3687 section (@pxref{checkpoints}), for more information on it.
3688
3689 @opindex show-omitted-dirs
3690 @anchor{show-omitted-dirs}
3691 The @option{--show-omitted-dirs} option, when reading an archive---with
3692 @option{--list} or @option{--extract}, for example---causes a message
3693 to be printed for each directory in the archive which is skipped.
3694 This happens regardless of the reason for skipping: the directory might
3695 not have been named on the command line (implicitly or explicitly),
3696 it might be excluded by the use of the
3697 @option{--exclude=@var{pattern}} option, or some other reason.
3698
3699 @opindex block-number
3700 @cindex Block number where error occurred
3701 @anchor{block-number}
3702 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3703 every message it would normally produce, the block number within the
3704 archive where the message was triggered. Also, supplementary messages
3705 are triggered when reading blocks full of NULs, or when hitting end of
3706 file on the archive. As of now, if the archive if properly terminated
3707 with a NUL block, the reading of the file may stop before end of file
3708 is met, so the position of end of file will not usually show when
3709 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3710 drains the archive before exiting when reading the
3711 archive from a pipe.
3712
3713 @cindex Error message, block number of
3714 This option is especially useful when reading damaged archives, since
3715 it helps pinpoint the damaged sections. It can also be used with
3716 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3717 choose among several backup tapes when retrieving a file later, in
3718 favor of the tape where the file appears earliest (closest to the
3719 front of the tape). @xref{backup}.
3720
3721 @node checkpoints
3722 @section Checkpoints
3723 @cindex checkpoints, defined
3724 @opindex checkpoint
3725 @opindex checkpoint-action
3726
3727 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3728 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3729 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3730 periodically execute arbitrary actions.
3731
3732 The checkpoint facility is enabled using the following option:
3733
3734 @table @option
3735 @xopindex{checkpoint, defined}
3736 @item --checkpoint[=@var{n}]
3737 Schedule checkpoints before writing or reading each @var{n}th record.
3738 The default value for @var{n} is 10.
3739 @end table
3740
3741 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3742 These actions include: pausing, displaying textual messages, and
3743 executing arbitrary external programs. Actions are defined using
3744 the @option{--checkpoint-action} option.
3745
3746 @table @option
3747 @xopindex{checkpoint-action, defined}
3748 @item --checkpoint-action=@var{action}
3749 Execute an @var{action} at each checkpoint.
3750 @end table
3751
3752 @cindex @code{echo}, checkpoint action
3753 The simplest value of @var{action} is @samp{echo}. It instructs
3754 @command{tar} to display the default message on the standard error
3755 stream upon arriving at each checkpoint. The default message is (in
3756 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3757 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3758 Here, @var{n} represents ordinal number of the checkpoint.
3759
3760 In another locales, translated versions of this message are used.
3761
3762 This is the default action, so running:
3763
3764 @smallexample
3765 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3766 @end smallexample
3767
3768 @noindent
3769 is equivalent to:
3770
3771 @smallexample
3772 $ @kbd{tar -c --checkpoint=1000} /var
3773 @end smallexample
3774
3775 The @samp{echo} action also allows to supply a customized message.
3776 You do so by placing an equals sign and the message right after it,
3777 e.g.:
3778
3779 @smallexample
3780 --checkpoint-action="echo=Hit %s checkpoint #%u"
3781 @end smallexample
3782
3783 The @samp{%s} and @samp{%u} in the above example are
3784 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3785 the @dfn{type} of the checkpoint: @samp{write} or
3786 @samp{read} (or a corresponding translated version in locales other
3787 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3788 the ordinal number of the checkpoint. Thus, the above example could
3789 produce the following output when used with the @option{--create}
3790 option:
3791
3792 @smallexample
3793 tar: Hit write checkpoint #10
3794 tar: Hit write checkpoint #20
3795 tar: Hit write checkpoint #30
3796 @end smallexample
3797
3798 Aside from meta-character expansion, the message string is subject to
3799 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3800 replaced with their corresponding @acronym{ASCII} characters
3801 (@pxref{escape sequences}). E.g. the following action will produce an
3802 audible bell and the message described above at each checkpoint:
3803
3804 @smallexample
3805 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3806 @end smallexample
3807
3808 @cindex @code{dot}, checkpoint action
3809 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3810 instructs @command{tar} to print a single dot on the standard listing
3811 stream, e.g.:
3812
3813 @smallexample
3814 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3815 ...
3816 @end smallexample
3817
3818 For compatibility with previous @GNUTAR{} versions, this action can
3819 be abbreviated by placing a dot in front of the checkpoint frequency,
3820 as shown in the previous section.
3821
3822 @cindex @code{sleep}, checkpoint action
3823 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
3824 amount of seconds. The following example will stop for 30 seconds at each
3825 checkpoint:
3826
3827 @smallexample
3828 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
3829 @end smallexample
3830
3831 @cindex @code{exec}, checkpoint action
3832 Finally, the @code{exec} action executes a given external program.
3833 For example:
3834
3835 @smallexample
3836 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
3837 @end smallexample
3838
3839 This program is executed using @command{/bin/sh -c}, with no
3840 additional arguments. Its exit code is ignored. It gets a copy of
3841 @command{tar}'s environment plus the following variables:
3842
3843 @table @env
3844 @vrindex TAR_VERSION, checkpoint script environment
3845 @item TAR_VERSION
3846 @GNUTAR{} version number.
3847
3848 @vrindex TAR_ARCHIVE, checkpoint script environment
3849 @item TAR_ARCHIVE
3850 The name of the archive @command{tar} is processing.
3851
3852 @vrindex TAR_CHECKPOINT, checkpoint script environment
3853 @item TAR_CHECKPOINT
3854 The checkpoint number.
3855
3856 @vrindex TAR_SUBCOMMAND, checkpoint script environment
3857 @item TAR_SUBCOMMAND
3858 A short option describing the operation @command{tar} is executing
3859 @xref{Operations}, for a complete list of subcommand options.
3860
3861 @vrindex TAR_FORMAT, checkpoint script environment
3862 @item TAR_FORMAT
3863 Format of the archive being processed. @xref{Formats}, for a complete
3864 list of archive format names.
3865 @end table
3866
3867 Any number of actions can be defined, by supplying several
3868 @option{--checkpoint-action} options in the command line. For
3869 example, the command below displays two messages, pauses
3870 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
3871
3872 @example
3873 @group
3874 $ @kbd{tar -c -f arc.tar \
3875 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
3876 --checkpoint-action='echo=Sleeping for 30 seconds' \
3877 --checkpoint-action='sleep=30' \
3878 --checkpoint-action='exec=/sbin/cpoint'}
3879 @end group
3880 @end example
3881
3882 This example also illustrates the fact that
3883 @option{--checkpoint-action} can be used without
3884 @option{--checkpoint}. In this case, the default checkpoint frequency
3885 (at each 10th record) is assumed.
3886
3887 @node interactive
3888 @section Asking for Confirmation During Operations
3889 @cindex Interactive operation
3890
3891 Typically, @command{tar} carries out a command without stopping for
3892 further instructions. In some situations however, you may want to
3893 exclude some files and archive members from the operation (for instance
3894 if disk or storage space is tight). You can do this by excluding
3895 certain files automatically (@pxref{Choosing}), or by performing
3896 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3897 @command{tar} also accepts @option{--confirmation} for this option.
3898
3899 @opindex interactive
3900 When the @option{--interactive} (@option{-w}) option is specified, before
3901 reading, writing, or deleting files, @command{tar} first prints a message
3902 for each such file, telling what operation it intends to take, then asks
3903 for confirmation on the terminal. The actions which require
3904 confirmation include adding a file to the archive, extracting a file
3905 from the archive, deleting a file from the archive, and deleting a file
3906 from disk. To confirm the action, you must type a line of input
3907 beginning with @samp{y}. If your input line begins with anything other
3908 than @samp{y}, @command{tar} skips that file.
3909
3910 If @command{tar} is reading the archive from the standard input,
3911 @command{tar} opens the file @file{/dev/tty} to support the interactive
3912 communications.
3913
3914 Verbose output is normally sent to standard output, separate from
3915 other error messages. However, if the archive is produced directly
3916 on standard output, then verbose output is mixed with errors on
3917 @code{stderr}. Producing the archive on standard output may be used
3918 as a way to avoid using disk space, when the archive is soon to be
3919 consumed by another process reading it, say. Some people felt the need
3920 of producing an archive on stdout, still willing to segregate between
3921 verbose output and error output. A possible approach would be using a
3922 named pipe to receive the archive, and having the consumer process to
3923 read from that named pipe. This has the advantage of letting standard
3924 output free to receive verbose output, all separate from errors.
3925
3926 @node operations
3927 @chapter @GNUTAR{} Operations
3928
3929 @menu
3930 * Basic tar::
3931 * Advanced tar::
3932 * create options::
3933 * extract options::
3934 * backup::
3935 * Applications::
3936 * looking ahead::
3937 @end menu
3938
3939 @node Basic tar
3940 @section Basic @GNUTAR{} Operations
3941
3942 The basic @command{tar} operations, @option{--create} (@option{-c}),
3943 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3944 @option{-x}), are currently presented and described in the tutorial
3945 chapter of this manual. This section provides some complementary notes
3946 for these operations.
3947
3948 @table @option
3949 @xopindex{create, complementary notes}
3950 @item --create
3951 @itemx -c
3952
3953 Creating an empty archive would have some kind of elegance. One can
3954 initialize an empty archive and later use @option{--append}
3955 (@option{-r}) for adding all members. Some applications would not
3956 welcome making an exception in the way of adding the first archive
3957 member. On the other hand, many people reported that it is
3958 dangerously too easy for @command{tar} to destroy a magnetic tape with
3959 an empty archive@footnote{This is well described in @cite{Unix-haters
3960 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3961 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3962
3963 @enumerate
3964 @item
3965 Mistakingly using @code{create} instead of @code{extract}, when the
3966 intent was to extract the full contents of an archive. This error
3967 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3968 the QWERTY keyboard. Instead of being unpacked, the archive then
3969 gets wholly destroyed. When users speak about @dfn{exploding} an
3970 archive, they usually mean something else :-).
3971
3972 @item
3973 Forgetting the argument to @code{file}, when the intent was to create
3974 an archive with a single file in it. This error is likely because a
3975 tired user can easily add the @kbd{f} key to the cluster of option
3976 letters, by the mere force of habit, without realizing the full
3977 consequence of doing so. The usual consequence is that the single
3978 file, which was meant to be saved, is rather destroyed.
3979 @end enumerate
3980
3981 So, recognizing the likelihood and the catastrophic nature of these
3982 errors, @GNUTAR{} now takes some distance from elegance, and
3983 cowardly refuses to create an archive when @option{--create} option is
3984 given, there are no arguments besides options, and
3985 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3986 around the cautiousness of @GNUTAR{} and nevertheless create an
3987 archive with nothing in it, one may still use, as the value for the
3988 @option{--files-from} option, a file with no names in it, as shown in
3989 the following commands:
3990
3991 @smallexample
3992 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3993 @kbd{tar cfT empty-archive.tar /dev/null}
3994 @end smallexample
3995
3996 @xopindex{extract, complementary notes}
3997 @item --extract
3998 @itemx --get
3999 @itemx -x
4000
4001 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4002
4003 @item @option{--list} (@option{-t})
4004
4005 @GNUTAR{} now shows dates as @samp{1996-08-30},
4006 while it used to show them as @samp{Aug 30 1996}. Preferably,
4007 people should get used to ISO 8601 dates. Local American dates should
4008 be made available again with full date localization support, once
4009 ready. In the meantime, programs not being localizable for dates
4010 should prefer international dates, that's really the way to go.
4011
4012 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4013 are curious, it contains a detailed explanation of the ISO 8601 standard.
4014
4015 @end table
4016
4017 @node Advanced tar
4018 @section Advanced @GNUTAR{} Operations
4019
4020 Now that you have learned the basics of using @GNUTAR{}, you may want
4021 to learn about further ways in which @command{tar} can help you.
4022
4023 This chapter presents five, more advanced operations which you probably
4024 won't use on a daily basis, but which serve more specialized functions.
4025 We also explain the different styles of options and why you might want
4026 to use one or another, or a combination of them in your @command{tar}
4027 commands. Additionally, this chapter includes options which allow you to
4028 define the output from @command{tar} more carefully, and provide help and
4029 error correction in special circumstances.
4030
4031 @FIXME{check this after the chapter is actually revised to make sure
4032 it still introduces the info in the chapter correctly : ).}
4033
4034 @menu
4035 * Operations::
4036 * append::
4037 * update::
4038 * concatenate::
4039 * delete::
4040 * compare::
4041 @end menu
4042
4043 @node Operations
4044 @subsection The Five Advanced @command{tar} Operations
4045 @UNREVISED
4046
4047 In the last chapter, you learned about the first three operations to
4048 @command{tar}. This chapter presents the remaining five operations to
4049 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4050 @option{--delete}, and @option{--compare}.
4051
4052 You are not likely to use these operations as frequently as those
4053 covered in the last chapter; however, since they perform specialized
4054 functions, they are quite useful when you do need to use them. We
4055 will give examples using the same directory and files that you created
4056 in the last chapter. As you may recall, the directory is called
4057 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4058 @samp{rock}, and the two archive files you created are
4059 @samp{collection.tar} and @samp{music.tar}.
4060
4061 We will also use the archive files @samp{afiles.tar} and
4062 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4063 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4064 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4065
4066 Unless we state otherwise, all practicing you do and examples you follow
4067 in this chapter will take place in the @file{practice} directory that
4068 you created in the previous chapter; see @ref{prepare for examples}.
4069 (Below in this section, we will remind you of the state of the examples
4070 where the last chapter left them.)
4071
4072 The five operations that we will cover in this chapter are:
4073
4074 @table @option
4075 @item --append
4076 @itemx -r
4077 Add new entries to an archive that already exists.
4078 @item --update
4079 @itemx -r
4080 Add more recent copies of archive members to the end of an archive, if
4081 they exist.
4082 @item --concatenate
4083 @itemx --catenate
4084 @itemx -A
4085 Add one or more pre-existing archives to the end of another archive.
4086 @item --delete
4087 Delete items from an archive (does not work on tapes).
4088 @item --compare
4089 @itemx --diff
4090 @itemx -d
4091 Compare archive members to their counterparts in the file system.
4092 @end table
4093
4094 @node append
4095 @subsection How to Add Files to Existing Archives: @option{--append}
4096 @UNREVISED
4097
4098 @opindex append
4099 If you want to add files to an existing archive, you don't need to
4100 create a new archive; you can use @option{--append} (@option{-r}).
4101 The archive must already exist in order to use @option{--append}. (A
4102 related operation is the @option{--update} operation; you can use this
4103 to add newer versions of archive members to an existing archive. To learn how to
4104 do this with @option{--update}, @pxref{update}.)
4105
4106 If you use @option{--append} to add a file that has the same name as an
4107 archive member to an archive containing that archive member, then the
4108 old member is not deleted. What does happen, however, is somewhat
4109 complex. @command{tar} @emph{allows} you to have infinite number of files
4110 with the same name. Some operations treat these same-named members no
4111 differently than any other set of archive members: for example, if you
4112 view an archive with @option{--list} (@option{-t}), you will see all
4113 of those members listed, with their data modification times, owners, etc.
4114
4115 Other operations don't deal with these members as perfectly as you might
4116 prefer; if you were to use @option{--extract} to extract the archive,
4117 only the most recently added copy of a member with the same name as four
4118 other members would end up in the working directory. This is because
4119 @option{--extract} extracts an archive in the order the members appeared
4120 in the archive; the most recently archived members will be extracted
4121 last. Additionally, an extracted member will @emph{replace} a file of
4122 the same name which existed in the directory already, and @command{tar}
4123 will not prompt you about this@footnote{Unless you give it
4124 @option{--keep-old-files} option, or the disk copy is newer than the
4125 the one in the archive and you invoke @command{tar} with
4126 @option{--keep-newer-files} option}. Thus, only the most recently archived
4127 member will end up being extracted, as it will replace the one
4128 extracted before it, and so on.
4129
4130 There exists a special option that allows you to get around this
4131 behavior and extract (or list) only a particular copy of the file.
4132 This is @option{--occurrence} option. If you run @command{tar} with
4133 this option, it will extract only the first copy of the file. You
4134 may also give this option an argument specifying the number of
4135 copy to be extracted. Thus, for example if the archive
4136 @file{archive.tar} contained three copies of file @file{myfile}, then
4137 the command
4138
4139 @smallexample
4140 tar --extract --file archive.tar --occurrence=2 myfile
4141 @end smallexample
4142
4143 @noindent
4144 would extract only the second copy. @xref{Option
4145 Summary,---occurrence}, for the description of @option{--occurrence}
4146 option.
4147
4148 @FIXME{ hag -- you might want to incorporate some of the above into the
4149 MMwtSN node; not sure. i didn't know how to make it simpler...
4150
4151 There are a few ways to get around this. (maybe xref Multiple Members
4152 with the Same Name.}
4153
4154 @cindex Members, replacing with other members
4155 @cindex Replacing members with other members
4156 If you want to replace an archive member, use @option{--delete} to
4157 delete the member you want to remove from the archive, , and then use
4158 @option{--append} to add the member you want to be in the archive. Note
4159 that you can not change the order of the archive; the most recently
4160 added member will still appear last. In this sense, you cannot truly
4161 ``replace'' one member with another. (Replacing one member with another
4162 will not work on certain types of media, such as tapes; see @ref{delete}
4163 and @ref{Media}, for more information.)
4164
4165 @menu
4166 * appending files:: Appending Files to an Archive
4167 * multiple::
4168 @end menu
4169
4170 @node appending files
4171 @subsubsection Appending Files to an Archive
4172 @UNREVISED
4173 @cindex Adding files to an Archive
4174 @cindex Appending files to an Archive
4175 @cindex Archives, Appending files to
4176
4177 The simplest way to add a file to an already existing archive is the
4178 @option{--append} (@option{-r}) operation, which writes specified
4179 files into the archive whether or not they are already among the
4180 archived files.
4181
4182 When you use @option{--append}, you @emph{must} specify file name
4183 arguments, as there is no default. If you specify a file that already
4184 exists in the archive, another copy of the file will be added to the
4185 end of the archive. As with other operations, the member names of the
4186 newly added files will be exactly the same as their names given on the
4187 command line. The @option{--verbose} (@option{-v}) option will print
4188 out the names of the files as they are written into the archive.
4189
4190 @option{--append} cannot be performed on some tape drives, unfortunately,
4191 due to deficiencies in the formats those tape drives use. The archive
4192 must be a valid @command{tar} archive, or else the results of using this
4193 operation will be unpredictable. @xref{Media}.
4194
4195 To demonstrate using @option{--append} to add a file to an archive,
4196 create a file called @file{rock} in the @file{practice} directory.
4197 Make sure you are in the @file{practice} directory. Then, run the
4198 following @command{tar} command to add @file{rock} to
4199 @file{collection.tar}:
4200
4201 @smallexample
4202 $ @kbd{tar --append --file=collection.tar rock}
4203 @end smallexample
4204
4205 @noindent
4206 If you now use the @option{--list} (@option{-t}) operation, you will see that
4207 @file{rock} has been added to the archive:
4208
4209 @smallexample
4210 $ @kbd{tar --list --file=collection.tar}
4211 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4212 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4213 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4214 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4215 @end smallexample
4216
4217 @node multiple
4218 @subsubsection Multiple Members with the Same Name
4219
4220 You can use @option{--append} (@option{-r}) to add copies of files
4221 which have been updated since the archive was created. (However, we
4222 do not recommend doing this since there is another @command{tar}
4223 option called @option{--update}; @xref{update}, for more information.
4224 We describe this use of @option{--append} here for the sake of
4225 completeness.) When you extract the archive, the older version will
4226 be effectively lost. This works because files are extracted from an
4227 archive in the order in which they were archived. Thus, when the
4228 archive is extracted, a file archived later in time will replace a
4229 file of the same name which was archived earlier, even though the
4230 older version of the file will remain in the archive unless you delete
4231 all versions of the file.
4232
4233 Supposing you change the file @file{blues} and then append the changed
4234 version to @file{collection.tar}. As you saw above, the original
4235 @file{blues} is in the archive @file{collection.tar}. If you change the
4236 file and append the new version of the file to the archive, there will
4237 be two copies in the archive. When you extract the archive, the older
4238 version of the file will be extracted first, and then replaced by the
4239 newer version when it is extracted.
4240
4241 You can append the new, changed copy of the file @file{blues} to the
4242 archive in this way:
4243
4244 @smallexample
4245 $ @kbd{tar --append --verbose --file=collection.tar blues}
4246 blues
4247 @end smallexample
4248
4249 @noindent
4250 Because you specified the @option{--verbose} option, @command{tar} has
4251 printed the name of the file being appended as it was acted on. Now
4252 list the contents of the archive:
4253
4254 @smallexample
4255 $ @kbd{tar --list --verbose --file=collection.tar}
4256 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4257 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4258 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4259 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4260 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4261 @end smallexample
4262
4263 @noindent
4264 The newest version of @file{blues} is now at the end of the archive
4265 (note the different creation dates and file sizes). If you extract
4266 the archive, the older version of the file @file{blues} will be
4267 replaced by the newer version. You can confirm this by extracting
4268 the archive and running @samp{ls} on the directory.
4269
4270 If you wish to extract the first occurrence of the file @file{blues}
4271 from the archive, use @option{--occurrence} option, as shown in
4272 the following example:
4273
4274 @smallexample
4275 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4276 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4277 @end smallexample
4278
4279 @xref{Writing}, for more information on @option{--extract} and
4280 @xref{Option Summary, --occurrence}, for the description of
4281 @option{--occurrence} option.
4282
4283 @node update
4284 @subsection Updating an Archive
4285 @UNREVISED
4286 @cindex Updating an archive
4287
4288 @opindex update
4289 In the previous section, you learned how to use @option{--append} to
4290 add a file to an existing archive. A related operation is
4291 @option{--update} (@option{-u}). The @option{--update} operation
4292 updates a @command{tar} archive by comparing the date of the specified
4293 archive members against the date of the file with the same name. If
4294 the file has been modified more recently than the archive member, then
4295 the newer version of the file is added to the archive (as with
4296 @option{--append}).
4297
4298 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4299 The operation will fail.
4300
4301 @FIXME{other examples of media on which --update will fail? need to ask
4302 charles and/or mib/thomas/dave shevett..}
4303
4304 Both @option{--update} and @option{--append} work by adding to the end
4305 of the archive. When you extract a file from the archive, only the
4306 version stored last will wind up in the file system, unless you use
4307 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4308
4309 @menu
4310 * how to update::
4311 @end menu
4312
4313 @node how to update
4314 @subsubsection How to Update an Archive Using @option{--update}
4315
4316 You must use file name arguments with the @option{--update}
4317 (@option{-u}) operation. If you don't specify any files,
4318 @command{tar} won't act on any files and won't tell you that it didn't
4319 do anything (which may end up confusing you).
4320
4321 @c note: the above parenthetical added because in fact, this
4322 @c behavior just confused the author. :-)
4323
4324 To see the @option{--update} option at work, create a new file,
4325 @file{classical}, in your practice directory, and some extra text to the
4326 file @file{blues}, using any text editor. Then invoke @command{tar} with
4327 the @samp{update} operation and the @option{--verbose} (@option{-v})
4328 option specified, using the names of all the files in the practice
4329 directory as file name arguments:
4330
4331 @smallexample
4332 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4333 blues
4334 classical
4335 $
4336 @end smallexample
4337
4338 @noindent
4339 Because we have specified verbose mode, @command{tar} prints out the names
4340 of the files it is working on, which in this case are the names of the
4341 files that needed to be updated. If you run @samp{tar --list} and look
4342 at the archive, you will see @file{blues} and @file{classical} at its
4343 end. There will be a total of two versions of the member @samp{blues};
4344 the one at the end will be newer and larger, since you added text before
4345 updating it.
4346
4347 (The reason @command{tar} does not overwrite the older file when updating
4348 it is because writing to the middle of a section of tape is a difficult
4349 process. Tapes are not designed to go backward. @xref{Media}, for more
4350 information about tapes.
4351
4352 @option{--update} (@option{-u}) is not suitable for performing backups for two
4353 reasons: it does not change directory content entries, and it
4354 lengthens the archive every time it is used. The @GNUTAR{}
4355 options intended specifically for backups are more
4356 efficient. If you need to run backups, please consult @ref{Backups}.
4357
4358 @node concatenate
4359 @subsection Combining Archives with @option{--concatenate}
4360
4361 @cindex Adding archives to an archive
4362 @cindex Concatenating Archives
4363 @opindex concatenate
4364 @opindex catenate
4365 @c @cindex @option{-A} described
4366 Sometimes it may be convenient to add a second archive onto the end of
4367 an archive rather than adding individual files to the archive. To add
4368 one or more archives to the end of another archive, you should use the
4369 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4370
4371 To use @option{--concatenate}, give the first archive with
4372 @option{--file} option and name the rest of archives to be
4373 concatenated on the command line. The members, and their member
4374 names, will be copied verbatim from those archives to the first one.
4375 @footnote{This can cause multiple members to have the same name, for
4376 information on how this affects reading the archive, @ref{multiple}.}
4377 The new, concatenated archive will be called by the same name as the
4378 one given with the @option{--file} option. As usual, if you omit
4379 @option{--file}, @command{tar} will use the value of the environment
4380 variable @env{TAPE}, or, if this has not been set, the default archive name.
4381
4382 @FIXME{There is no way to specify a new name...}
4383
4384 To demonstrate how @option{--concatenate} works, create two small archives
4385 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4386 files from @file{practice}:
4387
4388 @smallexample
4389 $ @kbd{tar -cvf bluesrock.tar blues rock}
4390 blues
4391 rock
4392 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4393 folk
4394 jazz
4395 @end smallexample
4396
4397 @noindent
4398 If you like, You can run @samp{tar --list} to make sure the archives
4399 contain what they are supposed to:
4400
4401 @smallexample
4402 $ @kbd{tar -tvf bluesrock.tar}
4403 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4404 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4405 $ @kbd{tar -tvf jazzfolk.tar}
4406 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4407 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4408 @end smallexample
4409
4410 We can concatenate these two archives with @command{tar}:
4411
4412 @smallexample
4413 $ @kbd{cd ..}
4414 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4415 @end smallexample
4416
4417 If you now list the contents of the @file{bluesrock.tar}, you will see
4418 that now it also contains the archive members of @file{jazzfolk.tar}:
4419
4420 @smallexample
4421 $ @kbd{tar --list --file=bluesrock.tar}
4422 blues
4423 rock
4424 folk
4425 jazz
4426 @end smallexample
4427
4428 When you use @option{--concatenate}, the source and target archives must
4429 already exist and must have been created using compatible format
4430 parameters. Notice, that @command{tar} does not check whether the
4431 archives it concatenates have compatible formats, it does not
4432 even check if the files are really tar archives.
4433
4434 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4435 tape drives, due to deficiencies in the formats those tape drives use.
4436
4437 @cindex @code{concatenate} vs @command{cat}
4438 @cindex @command{cat} vs @code{concatenate}
4439 It may seem more intuitive to you to want or try to use @command{cat} to
4440 concatenate two archives instead of using the @option{--concatenate}
4441 operation; after all, @command{cat} is the utility for combining files.
4442
4443 However, @command{tar} archives incorporate an end-of-file marker which
4444 must be removed if the concatenated archives are to be read properly as
4445 one archive. @option{--concatenate} removes the end-of-archive marker
4446 from the target archive before each new archive is appended. If you use
4447 @command{cat} to combine the archives, the result will not be a valid
4448 @command{tar} format archive. If you need to retrieve files from an
4449 archive that was added to using the @command{cat} utility, use the
4450 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4451 information on dealing with archives improperly combined using the
4452 @command{cat} shell utility.
4453
4454 @node delete
4455 @subsection Removing Archive Members Using @option{--delete}
4456 @UNREVISED
4457 @cindex Deleting files from an archive
4458 @cindex Removing files from an archive
4459
4460 @opindex delete
4461 You can remove members from an archive by using the @option{--delete}
4462 option. Specify the name of the archive with @option{--file}
4463 (@option{-f}) and then specify the names of the members to be deleted;
4464 if you list no member names, nothing will be deleted. The
4465 @option{--verbose} option will cause @command{tar} to print the names
4466 of the members as they are deleted. As with @option{--extract}, you
4467 must give the exact member names when using @samp{tar --delete}.
4468 @option{--delete} will remove all versions of the named file from the
4469 archive. The @option{--delete} operation can run very slowly.
4470
4471 Unlike other operations, @option{--delete} has no short form.
4472
4473 @cindex Tapes, using @option{--delete} and
4474 @cindex Deleting from tape archives
4475 This operation will rewrite the archive. You can only use
4476 @option{--delete} on an archive if the archive device allows you to
4477 write to any point on the media, such as a disk; because of this, it
4478 does not work on magnetic tapes. Do not try to delete an archive member
4479 from a magnetic tape; the action will not succeed, and you will be
4480 likely to scramble the archive and damage your tape. There is no safe
4481 way (except by completely re-writing the archive) to delete files from
4482 most kinds of magnetic tape. @xref{Media}.
4483
4484 To delete all versions of the file @file{blues} from the archive
4485 @file{collection.tar} in the @file{practice} directory, make sure you
4486 are in that directory, and then,
4487
4488 @smallexample
4489 $ @kbd{tar --list --file=collection.tar}
4490 blues
4491 folk
4492 jazz
4493 rock
4494 $ @kbd{tar --delete --file=collection.tar blues}
4495 $ @kbd{tar --list --file=collection.tar}
4496 folk
4497 jazz
4498 rock
4499 $
4500 @end smallexample
4501
4502 @FIXME{Check if the above listing is actually produced after running
4503 all the examples on collection.tar.}
4504
4505 The @option{--delete} option has been reported to work properly when
4506 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4507
4508 @node compare
4509 @subsection Comparing Archive Members with the File System
4510 @cindex Verifying the currency of an archive
4511 @UNREVISED
4512
4513 @opindex compare
4514 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4515 specified archive members against files with the same names, and then
4516 reports differences in file size, mode, owner, modification date and
4517 contents. You should @emph{only} specify archive member names, not file
4518 names. If you do not name any members, then @command{tar} will compare the
4519 entire archive. If a file is represented in the archive but does not
4520 exist in the file system, @command{tar} reports a difference.
4521
4522 You have to specify the record size of the archive when modifying an
4523 archive with a non-default record size.
4524
4525 @command{tar} ignores files in the file system that do not have
4526 corresponding members in the archive.
4527
4528 The following example compares the archive members @file{rock},
4529 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4530 files of the same name in the file system. (Note that there is no file,
4531 @file{funk}; @command{tar} will report an error message.)
4532
4533 @smallexample
4534 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4535 rock
4536 blues
4537 tar: funk not found in archive
4538 @end smallexample
4539
4540 The spirit behind the @option{--compare} (@option{--diff},
4541 @option{-d}) option is to check whether the archive represents the
4542 current state of files on disk, more than validating the integrity of
4543 the archive media. For this later goal, @xref{verify}.
4544
4545 @node create options
4546 @section Options Used by @option{--create}
4547
4548 @xopindex{create, additional options}
4549 The previous chapter described the basics of how to use
4550 @option{--create} (@option{-c}) to create an archive from a set of files.
4551 @xref{create}. This section described advanced options to be used with
4552 @option{--create}.
4553
4554 @menu
4555 * override:: Overriding File Metadata.
4556 * Ignore Failed Read::
4557 @end menu
4558
4559 @node override
4560 @subsection Overriding File Metadata
4561
4562 As described above, a @command{tar} archive keeps, for each member it contains,
4563 its @dfn{metadata}, such as modification time, mode and ownership of
4564 the file. @GNUTAR{} allows to replace these data with other values
4565 when adding files to the archive. The options described in this
4566 section affect creation of archives of any type. For POSIX archives,
4567 see also @ref{PAX keywords}, for additional ways of controlling
4568 metadata, stored in the archive.
4569
4570 @table @option
4571 @opindex mode
4572 @item --mode=@var{permissions}
4573
4574 When adding files to an archive, @command{tar} will use
4575 @var{permissions} for the archive members, rather than the permissions
4576 from the files. @var{permissions} can be specified either as an octal
4577 number or as symbolic permissions, like with
4578 @command{chmod} (@xref{File permissions, Permissions, File
4579 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4580 also has useful information for those not being overly familiar with
4581 the UNIX permission system). Using latter syntax allows for
4582 more flexibility. For example, the value @samp{a+rw} adds read and write
4583 permissions for everybody, while retaining executable bits on directories
4584 or on any other file already marked as executable:
4585
4586 @smallexample
4587 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4588 @end smallexample
4589
4590 @item --mtime=@var{date}
4591 @opindex mtime
4592
4593 When adding files to an archive, @command{tar} will use @var{date} as
4594 the modification time of members when creating archives, instead of
4595 their actual modification times. The argument @var{date} can be
4596 either a textual date representation in almost arbitrary format
4597 (@pxref{Date input formats}) or a name of the existing file, starting
4598 with @samp{/} or @samp{.}. In the latter case, the modification time
4599 of that file will be used.
4600
4601 The following example will set the modification date to 00:00:00 UTC,
4602 January 1, 1970:
4603
4604 @smallexample
4605 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4606 @end smallexample
4607
4608 @noindent
4609 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4610 will try to convert the specified date back to its textual
4611 representation and compare it with the one given with
4612 @option{--mtime} options. If the two dates differ, @command{tar} will
4613 print a warning saying what date it will use. This is to help user
4614 ensure he is using the right date.
4615
4616 For example:
4617
4618 @smallexample
4619 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4620 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4621 13:06:29.152478
4622 @dots{}
4623 @end smallexample
4624
4625 @item --owner=@var{user}
4626 @opindex owner
4627
4628 Specifies that @command{tar} should use @var{user} as the owner of members
4629 when creating archives, instead of the user associated with the source
4630 file. The argument @var{user} can be either an existing user symbolic
4631 name, or a decimal numeric user @acronym{ID}.
4632
4633 There is no value indicating a missing number, and @samp{0} usually means
4634 @code{root}. Some people like to force @samp{0} as the value to offer in
4635 their distributions for the owner of files, because the @code{root} user is
4636 anonymous anyway, so that might as well be the owner of anonymous
4637 archives. For example:
4638
4639 @smallexample
4640 @group
4641 $ @kbd{tar -c -f archive.tar --owner=0 .}
4642 # @r{Or:}
4643 $ @kbd{tar -c -f archive.tar --owner=root .}
4644 @end group
4645 @end smallexample
4646
4647 @item --group=@var{group}
4648 @opindex group
4649
4650 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4651 rather than the group from the source file. The argument @var{group}
4652 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4653 @end table
4654
4655 @node Ignore Failed Read
4656 @subsection Ignore Fail Read
4657
4658 @table @option
4659 @item --ignore-failed-read
4660 @opindex ignore-failed-read
4661 Do not exit with nonzero on unreadable files or directories.
4662 @end table
4663
4664 @node extract options
4665 @section Options Used by @option{--extract}
4666 @UNREVISED
4667
4668 @xopindex{extract, additional options}
4669 The previous chapter showed how to use @option{--extract} to extract
4670 an archive into the file system. Various options cause @command{tar} to
4671 extract more information than just file contents, such as the owner,
4672 the permissions, the modification date, and so forth. This section
4673 presents options to be used with @option{--extract} when certain special
4674 considerations arise. You may review the information presented in
4675 @ref{extract} for more basic information about the
4676 @option{--extract} operation.
4677
4678 @menu
4679 * Reading:: Options to Help Read Archives
4680 * Writing:: Changing How @command{tar} Writes Files
4681 * Scarce:: Coping with Scarce Resources
4682 @end menu
4683
4684 @node Reading
4685 @subsection Options to Help Read Archives
4686 @cindex Options when reading archives
4687 @UNREVISED
4688
4689 @cindex Reading incomplete records
4690 @cindex Records, incomplete
4691 @opindex read-full-records
4692 Normally, @command{tar} will request data in full record increments from
4693 an archive storage device. If the device cannot return a full record,
4694 @command{tar} will report an error. However, some devices do not always
4695 return full records, or do not require the last record of an archive to
4696 be padded out to the next record boundary. To keep reading until you
4697 obtain a full record, or to accept an incomplete record if it contains
4698 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4699 in conjunction with the @option{--extract} or @option{--list} operations.
4700 @xref{Blocking}.
4701
4702 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4703 @command{tar} reads an archive from standard input, or from a remote
4704 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
4705 pipe returns however much happens to be in the pipe, even if it is
4706 less than was requested. If this option were not enabled, @command{tar}
4707 would fail as soon as it read an incomplete record from the pipe.
4708
4709 If you're not sure of the blocking factor of an archive, you can
4710 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4711 @option{--blocking-factor=@var{512-size}} (@option{-b
4712 @var{512-size}}), using a blocking factor larger than what the archive
4713 uses. This lets you avoid having to determine the blocking factor
4714 of an archive. @xref{Blocking Factor}.
4715
4716 @menu
4717 * read full records::
4718 * Ignore Zeros::
4719 @end menu
4720
4721 @node read full records
4722 @unnumberedsubsubsec Reading Full Records
4723
4724 @FIXME{need sentence or so of intro here}
4725
4726 @table @option
4727 @opindex read-full-records
4728 @item --read-full-records
4729 @item -B
4730 Use in conjunction with @option{--extract} (@option{--get},
4731 @option{-x}) to read an archive which contains incomplete records, or
4732 one which has a blocking factor less than the one specified.
4733 @end table
4734
4735 @node Ignore Zeros
4736 @unnumberedsubsubsec Ignoring Blocks of Zeros
4737
4738 @cindex End-of-archive blocks, ignoring
4739 @cindex Ignoring end-of-archive blocks
4740 @opindex ignore-zeros
4741 Normally, @command{tar} stops reading when it encounters a block of zeros
4742 between file entries (which usually indicates the end of the archive).
4743 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4744 completely read an archive which contains a block of zeros before the
4745 end (i.e., a damaged archive, or one that was created by concatenating
4746 several archives together).
4747
4748 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4749 versions of @command{tar} write garbage after the end-of-archive entry,
4750 since that part of the media is never supposed to be read. @GNUTAR{}
4751 does not write after the end of an archive, but seeks to
4752 maintain compatibility among archiving utilities.
4753
4754 @table @option
4755 @item --ignore-zeros
4756 @itemx -i
4757 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4758 encountered while reading an archive. Use in conjunction with
4759 @option{--extract} or @option{--list}.
4760 @end table
4761
4762 @node Writing
4763 @subsection Changing How @command{tar} Writes Files
4764 @UNREVISED
4765
4766 @FIXME{Introductory paragraph}
4767
4768 @menu
4769 * Dealing with Old Files::
4770 * Overwrite Old Files::
4771 * Keep Old Files::
4772 * Keep Newer Files::
4773 * Unlink First::
4774 * Recursive Unlink::
4775 * Data Modification Times::
4776 * Setting Access Permissions::
4777 * Directory Modification Times and Permissions::
4778 * Writing to Standard Output::
4779 * Writing to an External Program::
4780 * remove files::
4781 @end menu
4782
4783 @node Dealing with Old Files
4784 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4785
4786 @xopindex{overwrite-dir, introduced}
4787 When extracting files, if @command{tar} discovers that the extracted
4788 file already exists, it normally replaces the file by removing it before
4789 extracting it, to prevent confusion in the presence of hard or symbolic
4790 links. (If the existing file is a symbolic link, it is removed, not
4791 followed.) However, if a directory cannot be removed because it is
4792 nonempty, @command{tar} normally overwrites its metadata (ownership,
4793 permission, etc.). The @option{--overwrite-dir} option enables this
4794 default behavior. To be more cautious and preserve the metadata of
4795 such a directory, use the @option{--no-overwrite-dir} option.
4796
4797 @cindex Overwriting old files, prevention
4798 @xopindex{keep-old-files, introduced}
4799 To be even more cautious and prevent existing files from being replaced, use
4800 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4801 to replace or update a file that already exists, i.e., a file with the
4802 same name as an archive member prevents extraction of that archive
4803 member. Instead, it reports an error.
4804
4805 @xopindex{overwrite, introduced}
4806 To be more aggressive about altering existing files, use the
4807 @option{--overwrite} option. It causes @command{tar} to overwrite
4808 existing files and to follow existing symbolic links when extracting.
4809
4810 @cindex Protecting old files
4811 Some people argue that @GNUTAR{} should not hesitate
4812 to overwrite files with other files when extracting. When extracting
4813 a @command{tar} archive, they expect to see a faithful copy of the
4814 state of the file system when the archive was created. It is debatable
4815 that this would always be a proper behavior. For example, suppose one
4816 has an archive in which @file{usr/local} is a link to
4817 @file{usr/local2}. Since then, maybe the site removed the link and
4818 renamed the whole hierarchy from @file{/usr/local2} to
4819 @file{/usr/local}. Such things happen all the time. I guess it would
4820 not be welcome at all that @GNUTAR{} removes the
4821 whole hierarchy just to make room for the link to be reinstated
4822 (unless it @emph{also} simultaneously restores the full
4823 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4824 able to remove a whole hierarchy to reestablish a symbolic link, for
4825 example, but @emph{only if} @option{--recursive-unlink} is specified
4826 to allow this behavior. In any case, single files are silently
4827 removed.
4828
4829 @xopindex{unlink-first, introduced}
4830 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4831 some cases by causing @command{tar} to remove files unconditionally
4832 before extracting them.
4833
4834 @node Overwrite Old Files
4835 @unnumberedsubsubsec Overwrite Old Files
4836
4837 @table @option
4838 @opindex overwrite
4839 @item --overwrite
4840 Overwrite existing files and directory metadata when extracting files
4841 from an archive.
4842
4843 This causes @command{tar} to write extracted files into the file system without
4844 regard to the files already on the system; i.e., files with the same
4845 names as archive members are overwritten when the archive is extracted.
4846 It also causes @command{tar} to extract the ownership, permissions,
4847 and time stamps onto any preexisting files or directories.
4848 If the name of a corresponding file name is a symbolic link, the file
4849 pointed to by the symbolic link will be overwritten instead of the
4850 symbolic link itself (if this is possible). Moreover, special devices,
4851 empty directories and even symbolic links are automatically removed if
4852 they are in the way of extraction.
4853
4854 Be careful when using the @option{--overwrite} option, particularly when
4855 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4856 can change the contents, ownership or permissions of any file on your
4857 system. Also, many systems do not take kindly to overwriting files that
4858 are currently being executed.
4859
4860 @opindex overwrite-dir
4861 @item --overwrite-dir
4862 Overwrite the metadata of directories when extracting files from an
4863 archive, but remove other files before extracting.
4864 @end table
4865
4866 @node Keep Old Files
4867 @unnumberedsubsubsec Keep Old Files
4868
4869 @table @option
4870 @opindex keep-old-files
4871 @item --keep-old-files
4872 @itemx -k
4873 Do not replace existing files from archive. The
4874 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4875 from replacing existing files with files with the same name from the
4876 archive. The @option{--keep-old-files} option is meaningless with
4877 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4878 files in the file system during extraction.
4879 @end table
4880
4881 @node Keep Newer Files
4882 @unnumberedsubsubsec Keep Newer Files
4883
4884 @table @option
4885 @opindex keep-newer-files
4886 @item --keep-newer-files
4887 Do not replace existing files that are newer than their archive
4888 copies. This option is meaningless with @option{--list} (@option{-t}).
4889 @end table
4890
4891 @node Unlink First
4892 @unnumberedsubsubsec Unlink First
4893
4894 @table @option
4895 @opindex unlink-first
4896 @item --unlink-first
4897 @itemx -U
4898 Remove files before extracting over them.
4899 This can make @command{tar} run a bit faster if you know in advance
4900 that the extracted files all need to be removed. Normally this option
4901 slows @command{tar} down slightly, so it is disabled by default.
4902 @end table
4903
4904 @node Recursive Unlink
4905 @unnumberedsubsubsec Recursive Unlink
4906
4907 @table @option
4908 @opindex recursive-unlink
4909 @item --recursive-unlink
4910 When this option is specified, try removing files and directory hierarchies
4911 before extracting over them. @emph{This is a dangerous option!}
4912 @end table
4913
4914 If you specify the @option{--recursive-unlink} option,
4915 @command{tar} removes @emph{anything} that keeps you from extracting a file
4916 as far as current permissions will allow it. This could include removal
4917 of the contents of a full directory hierarchy.
4918
4919 @node Data Modification Times
4920 @unnumberedsubsubsec Setting Data Modification Times
4921
4922 @cindex Data modification times of extracted files
4923 @cindex Modification times of extracted files
4924 Normally, @command{tar} sets the data modification times of extracted
4925 files to the corresponding times recorded for the files in the archive, but
4926 limits the permissions of extracted files by the current @code{umask}
4927 setting.
4928
4929 To set the data modification times of extracted files to the time when
4930 the files were extracted, use the @option{--touch} (@option{-m}) option in
4931 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4932
4933 @table @option
4934 @opindex touch
4935 @item --touch
4936 @itemx -m
4937 Sets the data modification time of extracted archive members to the time
4938 they were extracted, not the time recorded for them in the archive.
4939 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4940 @end table
4941
4942 @node Setting Access Permissions
4943 @unnumberedsubsubsec Setting Access Permissions
4944
4945 @cindex Permissions of extracted files
4946 @cindex Modes of extracted files
4947 To set the modes (access permissions) of extracted files to those
4948 recorded for those files in the archive, use @option{--same-permissions}
4949 in conjunction with the @option{--extract} (@option{--get},
4950 @option{-x}) operation.
4951
4952 @table @option
4953 @opindex preserve-permissions
4954 @opindex same-permissions
4955 @item --preserve-permissions
4956 @itemx --same-permissions
4957 @c @itemx --ignore-umask
4958 @itemx -p
4959 Set modes of extracted archive members to those recorded in the
4960 archive, instead of current umask settings. Use in conjunction with
4961 @option{--extract} (@option{--get}, @option{-x}).
4962 @end table
4963
4964 @node Directory Modification Times and Permissions
4965 @unnumberedsubsubsec Directory Modification Times and Permissions
4966
4967 After successfully extracting a file member, @GNUTAR{} normally
4968 restores its permissions and modification times, as described in the
4969 previous sections. This cannot be done for directories, because
4970 after extracting a directory @command{tar} will almost certainly
4971 extract files into that directory and this will cause the directory
4972 modification time to be updated. Moreover, restoring that directory
4973 permissions may not permit file creation within it. Thus, restoring
4974 directory permissions and modification times must be delayed at least
4975 until all files have been extracted into that directory. @GNUTAR{}
4976 restores directories using the following approach.
4977
4978 The extracted directories are created with the mode specified in the
4979 archive, as modified by the umask of the user, which gives sufficient
4980 permissions to allow file creation. The meta-information about the
4981 directory is recorded in the temporary list of directories. When
4982 preparing to extract next archive member, @GNUTAR{} checks if the
4983 directory prefix of this file contains the remembered directory. If
4984 it does not, the program assumes that all files have been extracted
4985 into that directory, restores its modification time and permissions
4986 and removes its entry from the internal list. This approach allows
4987 to correctly restore directory meta-information in the majority of
4988 cases, while keeping memory requirements sufficiently small. It is
4989 based on the fact, that most @command{tar} archives use the predefined
4990 order of members: first the directory, then all the files and
4991 subdirectories in that directory.
4992
4993 However, this is not always true. The most important exception are
4994 incremental archives (@pxref{Incremental Dumps}). The member order in
4995 an incremental archive is reversed: first all directory members are
4996 stored, followed by other (non-directory) members. So, when extracting
4997 from incremental archives, @GNUTAR{} alters the above procedure. It
4998 remembers all restored directories, and restores their meta-data
4999 only after the entire archive has been processed. Notice, that you do
5000 not need to specify any special options for that, as @GNUTAR{}
5001 automatically detects archives in incremental format.
5002
5003 There may be cases, when such processing is required for normal archives
5004 too. Consider the following example:
5005
5006 @smallexample
5007 @group
5008 $ @kbd{tar --no-recursion -cvf archive \
5009 foo foo/file1 bar bar/file foo/file2}
5010 foo/
5011 foo/file1
5012 bar/
5013 bar/file
5014 foo/file2
5015 @end group
5016 @end smallexample
5017
5018 During the normal operation, after encountering @file{bar}
5019 @GNUTAR{} will assume that all files from the directory @file{foo}
5020 were already extracted and will therefore restore its timestamp and
5021 permission bits. However, after extracting @file{foo/file2} the
5022 directory timestamp will be offset again.
5023
5024 To correctly restore directory meta-information in such cases, use
5025 @option{delay-directory-restore} command line option:
5026
5027 @table @option
5028 @opindex delay-directory-restore
5029 @item --delay-directory-restore
5030 Delays restoring of the modification times and permissions of extracted
5031 directories until the end of extraction. This way, correct
5032 meta-information is restored even if the archive has unusual member
5033 ordering.
5034
5035 @opindex no-delay-directory-restore
5036 @item --no-delay-directory-restore
5037 Cancel the effect of the previous @option{--delay-directory-restore}.
5038 Use this option if you have used @option{--delay-directory-restore} in
5039 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5040 temporarily disable it.
5041 @end table
5042
5043 @node Writing to Standard Output
5044 @unnumberedsubsubsec Writing to Standard Output
5045
5046 @cindex Writing extracted files to standard output
5047 @cindex Standard output, writing extracted files to
5048 To write the extracted files to the standard output, instead of
5049 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5050 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5051 extracting files to send them through a pipe, and do not need to
5052 preserve them in the file system. If you extract multiple members,
5053 they appear on standard output concatenated, in the order they are
5054 found in the archive.
5055
5056 @table @option
5057 @opindex to-stdout
5058 @item --to-stdout
5059 @itemx -O
5060 Writes files to the standard output. Use only in conjunction with
5061 @option{--extract} (@option{--get}, @option{-x}). When this option is
5062 used, instead of creating the files specified, @command{tar} writes
5063 the contents of the files extracted to its standard output. This may
5064 be useful if you are only extracting the files in order to send them
5065 through a pipe. This option is meaningless with @option{--list}
5066 (@option{-t}).
5067 @end table
5068
5069 This can be useful, for example, if you have a tar archive containing
5070 a big file and don't want to store the file on disk before processing
5071 it. You can use a command like this:
5072
5073 @smallexample
5074 tar -xOzf foo.tgz bigfile | process
5075 @end smallexample
5076
5077 or even like this if you want to process the concatenation of the files:
5078
5079 @smallexample
5080 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5081 @end smallexample
5082
5083 However, @option{--to-command} may be more convenient for use with
5084 multiple files. See the next section.
5085
5086 @node Writing to an External Program
5087 @unnumberedsubsubsec Writing to an External Program
5088
5089 You can instruct @command{tar} to send the contents of each extracted
5090 file to the standard input of an external program:
5091
5092 @table @option
5093 @opindex to-command
5094 @item --to-command=@var{command}
5095 Extract files and pipe their contents to the standard input of
5096 @var{command}. When this option is used, instead of creating the
5097 files specified, @command{tar} invokes @var{command} and pipes the
5098 contents of the files to its standard output. @var{Command} may
5099 contain command line arguments. The program is executed via
5100 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5101 extracted. Non-regular files (directories, etc.) are ignored when this
5102 option is used.
5103 @end table
5104
5105 The command can obtain the information about the file it processes
5106 from the following environment variables:
5107
5108 @table @env
5109 @vrindex TAR_FILETYPE, to-command environment
5110 @item TAR_FILETYPE
5111 Type of the file. It is a single letter with the following meaning:
5112
5113 @multitable @columnfractions 0.10 0.90
5114 @item f @tab Regular file
5115 @item d @tab Directory
5116 @item l @tab Symbolic link
5117 @item h @tab Hard link
5118 @item b @tab Block device
5119 @item c @tab Character device
5120 @end multitable
5121
5122 Currently only regular files are supported.
5123
5124 @vrindex TAR_MODE, to-command environment
5125 @item TAR_MODE
5126 File mode, an octal number.
5127
5128 @vrindex TAR_FILENAME, to-command environment
5129 @item TAR_FILENAME
5130 The name of the file.
5131
5132 @vrindex TAR_REALNAME, to-command environment
5133 @item TAR_REALNAME
5134 Name of the file as stored in the archive.
5135
5136 @vrindex TAR_UNAME, to-command environment
5137 @item TAR_UNAME
5138 Name of the file owner.
5139
5140 @vrindex TAR_GNAME, to-command environment
5141 @item TAR_GNAME
5142 Name of the file owner group.
5143
5144 @vrindex TAR_ATIME, to-command environment
5145 @item TAR_ATIME
5146 Time of last access. It is a decimal number, representing seconds
5147 since the epoch. If the archive provides times with nanosecond
5148 precision, the nanoseconds are appended to the timestamp after a
5149 decimal point.
5150
5151 @vrindex TAR_MTIME, to-command environment
5152 @item TAR_MTIME
5153 Time of last modification.
5154
5155 @vrindex TAR_CTIME, to-command environment
5156 @item TAR_CTIME
5157 Time of last status change.
5158
5159 @vrindex TAR_SIZE, to-command environment
5160 @item TAR_SIZE
5161 Size of the file.
5162
5163 @vrindex TAR_UID, to-command environment
5164 @item TAR_UID
5165 UID of the file owner.
5166
5167 @vrindex TAR_GID, to-command environment
5168 @item TAR_GID
5169 GID of the file owner.
5170 @end table
5171
5172 In addition to these variables, @env{TAR_VERSION} contains the
5173 @GNUTAR{} version number.
5174
5175 If @var{command} exits with a non-0 status, @command{tar} will print
5176 an error message similar to the following:
5177
5178 @smallexample
5179 tar: 2345: Child returned status 1
5180 @end smallexample
5181
5182 Here, @samp{2345} is the PID of the finished process.
5183
5184 If this behavior is not wanted, use @option{--ignore-command-error}:
5185
5186 @table @option
5187 @opindex ignore-command-error
5188 @item --ignore-command-error
5189 Ignore exit codes of subprocesses. Notice that if the program
5190 exits on signal or otherwise terminates abnormally, the error message
5191 will be printed even if this option is used.
5192
5193 @opindex no-ignore-command-error
5194 @item --no-ignore-command-error
5195 Cancel the effect of any previous @option{--ignore-command-error}
5196 option. This option is useful if you have set
5197 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5198 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5199 @end table
5200
5201 @node remove files
5202 @unnumberedsubsubsec Removing Files
5203
5204 @FIXME{The section is too terse. Something more to add? An example,
5205 maybe?}
5206
5207 @table @option
5208 @opindex remove-files
5209 @item --remove-files
5210 Remove files after adding them to the archive.
5211 @end table
5212
5213 @node Scarce
5214 @subsection Coping with Scarce Resources
5215 @UNREVISED
5216
5217 @cindex Small memory
5218 @cindex Running out of space
5219
5220 @menu
5221 * Starting File::
5222 * Same Order::
5223 @end menu
5224
5225 @node Starting File
5226 @unnumberedsubsubsec Starting File
5227
5228 @table @option
5229 @opindex starting-file
5230 @item --starting-file=@var{name}
5231 @itemx -K @var{name}
5232 Starts an operation in the middle of an archive. Use in conjunction
5233 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5234 @end table
5235
5236 @cindex Middle of the archive, starting in the
5237 If a previous attempt to extract files failed due to lack of disk
5238 space, you can use @option{--starting-file=@var{name}} (@option{-K
5239 @var{name}}) to start extracting only after member @var{name} of the
5240 archive. This assumes, of course, that there is now free space, or
5241 that you are now extracting into a different file system. (You could
5242 also choose to suspend @command{tar}, remove unnecessary files from
5243 the file system, and then restart the same @command{tar} operation.
5244 In this case, @option{--starting-file} is not necessary.
5245 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
5246
5247 @node Same Order
5248 @unnumberedsubsubsec Same Order
5249
5250 @table @option
5251 @cindex Large lists of file names on small machines
5252 @opindex same-order
5253 @opindex preserve-order
5254 @item --same-order
5255 @itemx --preserve-order
5256 @itemx -s
5257 To process large lists of file names on machines with small amounts of
5258 memory. Use in conjunction with @option{--compare} (@option{--diff},
5259 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5260 (@option{--get}, @option{-x}).
5261 @end table
5262
5263 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5264 names to be listed or extracted is sorted in the same order as the
5265 files in the archive. This allows a large list of names to be used,
5266 even on a small machine that would not otherwise be able to hold all
5267 the names in memory at the same time. Such a sorted list can easily be
5268 created by running @samp{tar -t} on the archive and editing its output.
5269
5270 This option is probably never needed on modern computer systems.
5271
5272 @node backup
5273 @section Backup options
5274
5275 @cindex backup options
5276
5277 @GNUTAR{} offers options for making backups of files
5278 before writing new versions. These options control the details of
5279 these backups. They may apply to the archive itself before it is
5280 created or rewritten, as well as individual extracted members. Other
5281 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5282 and @command{mv}, for example) offer similar options.
5283
5284 Backup options may prove unexpectedly useful when extracting archives
5285 containing many members having identical name, or when extracting archives
5286 on systems having file name limitations, making different members appear
5287 has having similar names through the side-effect of name truncation.
5288 (This is true only if we have a good scheme for truncated backup names,
5289 which I'm not sure at all: I suspect work is needed in this area.)
5290 When any existing file is backed up before being overwritten by extraction,
5291 then clashing files are automatically be renamed to be unique, and the
5292 true name is kept for only the last file of a series of clashing files.
5293 By using verbose mode, users may track exactly what happens.
5294
5295 At the detail level, some decisions are still experimental, and may
5296 change in the future, we are waiting comments from our users. So, please
5297 do not learn to depend blindly on the details of the backup features.
5298 For example, currently, directories themselves are never renamed through
5299 using these options, so, extracting a file over a directory still has
5300 good chances to fail. Also, backup options apply to created archives,
5301 not only to extracted members. For created archives, backups will not
5302 be attempted when the archive is a block or character device, or when it
5303 refers to a remote file.
5304
5305 For the sake of simplicity and efficiency, backups are made by renaming old
5306 files prior to creation or extraction, and not by copying. The original
5307 name is restored if the file creation fails. If a failure occurs after a
5308 partial extraction of a file, both the backup and the partially extracted
5309 file are kept.
5310
5311 @table @samp
5312 @item --backup[=@var{method}]
5313 @opindex backup
5314 @vindex VERSION_CONTROL
5315 @cindex backups
5316 Back up files that are about to be overwritten or removed.
5317 Without this option, the original versions are destroyed.
5318
5319 Use @var{method} to determine the type of backups made.
5320 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5321 environment variable. And if @env{VERSION_CONTROL} is not set,
5322 use the @samp{existing} method.
5323
5324 @vindex version-control @r{Emacs variable}
5325 This option corresponds to the Emacs variable @samp{version-control};
5326 the same values for @var{method} are accepted as in Emacs. This option
5327 also allows more descriptive names. The valid @var{method}s are:
5328
5329 @table @samp
5330 @item t
5331 @itemx numbered
5332 @cindex numbered @r{backup method}
5333 Always make numbered backups.
5334
5335 @item nil
5336 @itemx existing
5337 @cindex existing @r{backup method}
5338 Make numbered backups of files that already have them, simple backups
5339 of the others.
5340
5341 @item never
5342 @itemx simple
5343 @cindex simple @r{backup method}
5344 Always make simple backups.
5345
5346 @end table
5347
5348 @item --suffix=@var{suffix}
5349 @opindex suffix
5350 @cindex backup suffix
5351 @vindex SIMPLE_BACKUP_SUFFIX
5352 Append @var{suffix} to each backup file made with @option{--backup}. If this
5353 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5354 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5355 set, the default is @samp{~}, just as in Emacs.
5356
5357 @end table
5358
5359 @node Applications
5360 @section Notable @command{tar} Usages
5361 @UNREVISED
5362
5363 @FIXME{Using Unix file linking capability to recreate directory
5364 structures---linking files into one subdirectory and then
5365 @command{tar}ring that directory.}
5366
5367 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5368
5369 @findex uuencode
5370 You can easily use archive files to transport a group of files from
5371 one system to another: put all relevant files into an archive on one
5372 computer system, transfer the archive to another system, and extract
5373 the contents there. The basic transfer medium might be magnetic tape,
5374 Internet FTP, or even electronic mail (though you must encode the
5375 archive with @command{uuencode} in order to transport it properly by
5376 mail). Both machines do not have to use the same operating system, as
5377 long as they both support the @command{tar} program.
5378
5379 For example, here is how you might copy a directory's contents from
5380 one disk to another, while preserving the dates, modes, owners and
5381 link-structure of all the files therein. In this case, the transfer
5382 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5383
5384 @smallexample
5385 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5386 @end smallexample
5387
5388 @noindent
5389 You can avoid subshells by using @option{-C} option:
5390
5391 @smallexample
5392 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5393 @end smallexample
5394
5395 @noindent
5396 The command also works using short option forms:
5397
5398 @smallexample
5399 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5400 | (cd targetdir; tar --extract --file=-)}
5401 # Or:
5402 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5403 | tar --directory targetdir --extract --file=-}
5404 @end smallexample
5405
5406 @noindent
5407 This is one of the easiest methods to transfer a @command{tar} archive.
5408
5409 @node looking ahead
5410 @section Looking Ahead: The Rest of this Manual
5411
5412 You have now seen how to use all eight of the operations available to
5413 @command{tar}, and a number of the possible options. The next chapter
5414 explains how to choose and change file and archive names, how to use
5415 files to store names of other files which you can then call as
5416 arguments to @command{tar} (this can help you save time if you expect to
5417 archive the same list of files a number of times), and so forth.
5418 @FIXME{in case it's not obvious, i'm making this up in some sense
5419 based on my limited memory of what the next chapter *really* does. i
5420 just wanted to flesh out this final section a little bit so i'd
5421 remember to stick it in here. :-)}
5422
5423 If there are too many files to conveniently list on the command line,
5424 you can list the names in a file, and @command{tar} will read that file.
5425 @xref{files}.
5426
5427 There are various ways of causing @command{tar} to skip over some files,
5428 and not archive them. @xref{Choosing}.
5429
5430 @node Backups
5431 @chapter Performing Backups and Restoring Files
5432 @UNREVISED
5433
5434 @GNUTAR{} is distributed along with the scripts
5435 which the Free Software Foundation uses for performing backups. There
5436 is no corresponding scripts available yet for doing restoration of
5437 files. Even if there is a good chance those scripts may be satisfying
5438 to you, they are not the only scripts or methods available for doing
5439 backups and restore. You may well create your own, or use more
5440 sophisticated packages dedicated to that purpose.
5441
5442 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5443 Automatic Network Disk Archiver), a backup system developed by James
5444 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5445 This is free software, and it is available at these places:
5446
5447 @smallexample
5448 http://www.cs.umd.edu/projects/amanda/amanda.html
5449 ftp://ftp.cs.umd.edu/pub/amanda
5450 @end smallexample
5451
5452 @FIXME{
5453
5454 Here is a possible plan for a future documentation about the backuping
5455 scripts which are provided within the @GNUTAR{}
5456 distribution.
5457
5458 @itemize @bullet
5459 @item dumps
5460 @itemize @minus
5461 @item what are dumps
5462 @item different levels of dumps
5463 @itemize +
5464 @item full dump = dump everything
5465 @item level 1, level 2 dumps etc
5466 A level @var{n} dump dumps everything changed since the last level
5467 @var{n}-1 dump (?)
5468 @end itemize
5469 @item how to use scripts for dumps (ie, the concept)
5470 @itemize +
5471 @item scripts to run after editing backup specs (details)
5472 @end itemize
5473 @item Backup Specs, what is it.
5474 @itemize +
5475 @item how to customize
5476 @item actual text of script [/sp/dump/backup-specs]
5477 @end itemize
5478 @item Problems
5479 @itemize +
5480 @item rsh doesn't work
5481 @item rtape isn't installed
5482 @item (others?)
5483 @end itemize
5484 @item the @option{--incremental} option of tar
5485 @item tapes
5486 @itemize +
5487 @item write protection
5488 @item types of media, different sizes and types, useful for different things
5489 @item files and tape marks
5490 one tape mark between files, two at end.
5491 @item positioning the tape
5492 MT writes two at end of write,
5493 backspaces over one when writing again.
5494 @end itemize
5495 @end itemize
5496 @end itemize
5497 }
5498
5499 This chapter documents both the provided shell scripts and @command{tar}
5500 options which are more specific to usage as a backup tool.
5501
5502 To @dfn{back up} a file system means to create archives that contain
5503 all the files in that file system. Those archives can then be used to
5504 restore any or all of those files (for instance if a disk crashes or a
5505 file is accidentally deleted). File system @dfn{backups} are also
5506 called @dfn{dumps}.
5507
5508 @menu
5509 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5510 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5511 * Backup Levels:: Levels of Backups
5512 * Backup Parameters:: Setting Parameters for Backups and Restoration
5513 * Scripted Backups:: Using the Backup Scripts
5514 * Scripted Restoration:: Using the Restore Script
5515 @end menu
5516
5517 @node Full Dumps
5518 @section Using @command{tar} to Perform Full Dumps
5519 @UNREVISED
5520
5521 @cindex full dumps
5522 @cindex dumps, full
5523
5524 @cindex corrupted archives
5525 Full dumps should only be made when no other people or programs
5526 are modifying files in the file system. If files are modified while
5527 @command{tar} is making the backup, they may not be stored properly in
5528 the archive, in which case you won't be able to restore them if you
5529 have to. (Files not being modified are written with no trouble, and do
5530 not corrupt the entire archive.)
5531
5532 You will want to use the @option{--label=@var{archive-label}}
5533 (@option{-V @var{archive-label}}) option to give the archive a
5534 volume label, so you can tell what this archive is even if the label
5535 falls off the tape, or anything like that.
5536
5537 Unless the file system you are dumping is guaranteed to fit on
5538 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5539 Make sure you have enough tapes on hand to complete the backup.
5540
5541 If you want to dump each file system separately you will need to use
5542 the @option{--one-file-system} option to prevent
5543 @command{tar} from crossing file system boundaries when storing
5544 (sub)directories.
5545
5546 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5547 option is not needed, since this is a complete copy of everything in
5548 the file system, and a full restore from this backup would only be
5549 done onto a completely
5550 empty disk.
5551
5552 Unless you are in a hurry, and trust the @command{tar} program (and your
5553 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5554 option, to make sure your files really made it onto the dump properly.
5555 This will also detect cases where the file was modified while (or just
5556 after) it was being archived. Not all media (notably cartridge tapes)
5557 are capable of being verified, unfortunately.
5558
5559 @node Incremental Dumps
5560 @section Using @command{tar} to Perform Incremental Dumps
5561
5562 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5563 stores additional metadata so that exact state of the file system
5564 can be restored when extracting the archive.
5565
5566 @GNUTAR{} currently offers two options for handling incremental
5567 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5568 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5569
5570 @opindex listed-incremental
5571 The option @option{--listed-incremental} instructs tar to operate on
5572 an incremental archive with additional metadata stored in a standalone
5573 file, called a @dfn{snapshot file}. The purpose of this file is to help
5574 determine which files have been changed, added or deleted since the
5575 last backup, so that the next incremental backup will contain only
5576 modified files. The name of the snapshot file is given as an argument
5577 to the option:
5578
5579 @table @option
5580 @item --listed-incremental=@var{file}
5581 @itemx -g @var{file}
5582 Handle incremental backups with snapshot data in @var{file}.
5583 @end table
5584
5585 To create an incremental backup, you would use
5586 @option{--listed-incremental} together with @option{--create}
5587 (@pxref{create}). For example:
5588
5589 @smallexample
5590 $ @kbd{tar --create \
5591 --file=archive.1.tar \
5592 --listed-incremental=/var/log/usr.snar \
5593 /usr}
5594 @end smallexample
5595
5596 This will create in @file{archive.1.tar} an incremental backup of
5597 the @file{/usr} file system, storing additional metadata in the file
5598 @file{/var/log/usr.snar}. If this file does not exist, it will be
5599 created. The created archive will then be a @dfn{level 0 backup};
5600 please see the next section for more on backup levels.
5601
5602 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5603 determines which files are modified. In this case only these files will be
5604 stored in the archive. Suppose, for example, that after running the
5605 above command, you delete file @file{/usr/doc/old} and create
5606 directory @file{/usr/local/db} with the following contents:
5607
5608 @smallexample
5609 $ @kbd{ls /usr/local/db}
5610 /usr/local/db/data
5611 /usr/local/db/index
5612 @end smallexample
5613
5614 Some time later you create another incremental backup. You will
5615 then see:
5616
5617 @smallexample
5618 $ @kbd{tar --create \
5619 --file=archive.2.tar \
5620 --listed-incremental=/var/log/usr.snar \
5621 /usr}
5622 tar: usr/local/db: Directory is new
5623 usr/local/db/
5624 usr/local/db/data
5625 usr/local/db/index
5626 @end smallexample
5627
5628 @noindent
5629 The created archive @file{archive.2.tar} will contain only these
5630 three members. This archive is called a @dfn{level 1 backup}. Notice
5631 that @file{/var/log/usr.snar} will be updated with the new data, so if
5632 you plan to create more @samp{level 1} backups, it is necessary to
5633 create a working copy of the snapshot file before running
5634 @command{tar}. The above example will then be modified as follows:
5635
5636 @smallexample
5637 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5638 $ @kbd{tar --create \
5639 --file=archive.2.tar \
5640 --listed-incremental=/var/log/usr.snar-1 \
5641 /usr}
5642 @end smallexample
5643
5644 Incremental dumps depend crucially on time stamps, so the results are
5645 unreliable if you modify a file's time stamps during dumping (e.g.,
5646 with the @option{--atime-preserve=replace} option), or if you set the clock
5647 backwards.
5648
5649 @cindex Device numbers, using in incremental backups
5650 Metadata stored in snapshot files include device numbers, which,
5651 obviously is supposed to be a non-volatile value. However, it turns
5652 out that NFS devices have undependable values when an automounter
5653 gets in the picture. This can lead to a great deal of spurious
5654 redumping in incremental dumps, so it is somewhat useless to compare
5655 two NFS devices numbers over time. The solution implemented currently
5656 is to considers all NFS devices as being equal when it comes to
5657 comparing directories; this is fairly gross, but there does not seem
5658 to be a better way to go.
5659
5660 If you are using the @i{Linux} kernel, the device numbers can also
5661 change when upgrading to some newer versions of the kernel. This can
5662 cause the next backup to be full backup on the affected filesystems.
5663 @xref{Fixing Snapshot Files}, for the information on how to handle this case.
5664
5665 Note that incremental archives use @command{tar} extensions and may
5666 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5667
5668 @xopindex{listed-incremental, using with @option{--extract}}
5669 @xopindex{extract, using with @option{--listed-incremental}}
5670 To extract from the incremental dumps, use
5671 @option{--listed-incremental} together with @option{--extract}
5672 option (@pxref{extracting files}). In this case, @command{tar} does
5673 not need to access snapshot file, since all the data necessary for
5674 extraction are stored in the archive itself. So, when extracting, you
5675 can give whatever argument to @option{--listed-incremental}, the usual
5676 practice is to use @option{--listed-incremental=/dev/null}.
5677 Alternatively, you can use @option{--incremental}, which needs no
5678 arguments. In general, @option{--incremental} (@option{-G}) can be
5679 used as a shortcut for @option{--listed-incremental} when listing or
5680 extracting incremental backups (for more information, regarding this
5681 option, @pxref{incremental-op}).
5682
5683 When extracting from the incremental backup @GNUTAR{} attempts to
5684 restore the exact state the file system had when the archive was
5685 created. In particular, it will @emph{delete} those files in the file
5686 system that did not exist in their directories when the archive was
5687 created. If you have created several levels of incremental files,
5688 then in order to restore the exact contents the file system had when
5689 the last level was created, you will need to restore from all backups
5690 in turn. Continuing our example, to restore the state of @file{/usr}
5691 file system, one would do@footnote{Notice, that since both archives
5692 were created without @option{-P} option (@pxref{absolute}), these
5693 commands should be run from the root file system.}:
5694
5695 @smallexample
5696 $ @kbd{tar --extract \
5697 --listed-incremental=/dev/null \
5698 --file archive.1.tar}
5699 $ @kbd{tar --extract \
5700 --listed-incremental=/dev/null \
5701 --file archive.2.tar}
5702 @end smallexample
5703
5704 To list the contents of an incremental archive, use @option{--list}
5705 (@pxref{list}), as usual. To obtain more information about the
5706 archive, use @option{--listed-incremental} or @option{--incremental}
5707 combined with two @option{--verbose} options@footnote{Two
5708 @option{--verbose} options were selected to avoid breaking usual
5709 verbose listing output (@option{--list --verbose}) when using in
5710 scripts.
5711
5712 @xopindex{incremental, using with @option{--list}}
5713 @xopindex{listed-incremental, using with @option{--list}}
5714 @xopindex{list, using with @option{--incremental}}
5715 @xopindex{list, using with @option{--listed-incremental}}
5716 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5717 contents of the DUMPDIR header (with terminating nulls) when
5718 @option{--incremental} or @option{--listed-incremental} option was
5719 given, no matter what the verbosity level. This behavior, and,
5720 especially, the binary output it produced were considered inconvenient
5721 and were changed in version 1.16}:
5722
5723 @smallexample
5724 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5725 @end smallexample
5726
5727 This command will print, for each directory in the archive, the list
5728 of files in that directory at the time the archive was created. This
5729 information is put out in a format which is both human-readable and
5730 unambiguous for a program: each file name is printed as
5731
5732 @smallexample
5733 @var{x} @var{file}
5734 @end smallexample
5735
5736 @noindent
5737 where @var{x} is a letter describing the status of the file: @samp{Y}
5738 if the file is present in the archive, @samp{N} if the file is not
5739 included in the archive, or a @samp{D} if the file is a directory (and
5740 is included in the archive). @xref{Dumpdir}, for the detailed
5741 description of dumpdirs and status codes. Each such
5742 line is terminated by a newline character. The last line is followed
5743 by an additional newline to indicate the end of the data.
5744
5745 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5746 gives the same behavior as @option{--listed-incremental} when used
5747 with @option{--list} and @option{--extract} options. When used with
5748 @option{--create} option, it creates an incremental archive without
5749 creating snapshot file. Thus, it is impossible to create several
5750 levels of incremental backups with @option{--incremental} option.
5751
5752 @node Backup Levels
5753 @section Levels of Backups
5754
5755 An archive containing all the files in the file system is called a
5756 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5757 creating a full dump every day. This strategy, however, would waste a
5758 substantial amount of archive media and user time, as unchanged files
5759 are daily re-archived.
5760
5761 It is more efficient to do a full dump only occasionally. To back up
5762 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5763 one} dump archives all the files that have changed since the last full
5764 dump.
5765
5766 A typical dump strategy would be to perform a full dump once a week,
5767 and a level one dump once a day. This means some versions of files
5768 will in fact be archived more than once, but this dump strategy makes
5769 it possible to restore a file system to within one day of accuracy by
5770 only extracting two archives---the last weekly (full) dump and the
5771 last daily (level one) dump. The only information lost would be in
5772 files changed or created since the last daily backup. (Doing dumps
5773 more than once a day is usually not worth the trouble).
5774
5775 @GNUTAR{} comes with scripts you can use to do full
5776 and level-one (actually, even level-two and so on) dumps. Using
5777 scripts (shell programs) to perform backups and restoration is a
5778 convenient and reliable alternative to typing out file name lists
5779 and @command{tar} commands by hand.
5780
5781 Before you use these scripts, you need to edit the file
5782 @file{backup-specs}, which specifies parameters used by the backup
5783 scripts and by the restore script. This file is usually located
5784 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5785 detailed description. Once the backup parameters are set, you can
5786 perform backups or restoration by running the appropriate script.
5787
5788 The name of the backup script is @code{backup}. The name of the
5789 restore script is @code{restore}. The following sections describe
5790 their use in detail.
5791
5792 @emph{Please Note:} The backup and restoration scripts are
5793 designed to be used together. While it is possible to restore files by
5794 hand from an archive which was created using a backup script, and to create
5795 an archive by hand which could then be extracted using the restore script,
5796 it is easier to use the scripts. @xref{Incremental Dumps}, before
5797 making such an attempt.
5798
5799 @node Backup Parameters
5800 @section Setting Parameters for Backups and Restoration
5801
5802 The file @file{backup-specs} specifies backup parameters for the
5803 backup and restoration scripts provided with @command{tar}. You must
5804 edit @file{backup-specs} to fit your system configuration and schedule
5805 before using these scripts.
5806
5807 Syntactically, @file{backup-specs} is a shell script, containing
5808 mainly variable assignments. However, any valid shell construct
5809 is allowed in this file. Particularly, you may wish to define
5810 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5811 For more information about shell script syntax, please refer to
5812 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5813 g_02, the definition of the Shell Command Language}. See also
5814 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5815
5816 The shell variables controlling behavior of @code{backup} and
5817 @code{restore} are described in the following subsections.
5818
5819 @menu
5820 * General-Purpose Variables::
5821 * Magnetic Tape Control::
5822 * User Hooks::
5823 * backup-specs example:: An Example Text of @file{Backup-specs}
5824 @end menu
5825
5826 @node General-Purpose Variables
5827 @subsection General-Purpose Variables
5828
5829 @defvr {Backup variable} ADMINISTRATOR
5830 The user name of the backup administrator. @code{Backup} scripts
5831 sends a backup report to this address.
5832 @end defvr
5833
5834 @defvr {Backup variable} BACKUP_HOUR
5835 The hour at which the backups are done. This can be a number from 0
5836 to 23, or the time specification in form @var{hours}:@var{minutes},
5837 or the string @samp{now}.
5838
5839 This variable is used by @code{backup}. Its value may be overridden
5840 using @option{--time} option (@pxref{Scripted Backups}).
5841 @end defvr
5842
5843 @defvr {Backup variable} TAPE_FILE
5844
5845 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5846 is a remote archive (@pxref{remote-dev}), backup script will suppose
5847 that your @command{mt} is able to access remote devices. If @var{RSH}
5848 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5849 invocations of @command{mt}.
5850 @end defvr
5851
5852 @defvr {Backup variable} BLOCKING
5853
5854 The blocking factor @command{tar} will use when writing the dump archive.
5855 @xref{Blocking Factor}.
5856 @end defvr
5857
5858 @defvr {Backup variable} BACKUP_DIRS
5859
5860 A list of file systems to be dumped (for @code{backup}), or restored
5861 (for @code{restore}). You can include any directory
5862 name in the list --- subdirectories on that file system will be
5863 included, regardless of how they may look to other networked machines.
5864 Subdirectories on other file systems will be ignored.
5865
5866 The host name specifies which host to run @command{tar} on, and should
5867 normally be the host that actually contains the file system. However,
5868 the host machine must have @GNUTAR{} installed, and
5869 must be able to access the directory containing the backup scripts and
5870 their support files using the same file name that is used on the
5871 machine where the scripts are run (i.e., what @command{pwd} will print
5872 when in that directory on that machine). If the host that contains
5873 the file system does not have this capability, you can specify another
5874 host as long as it can access the file system through NFS.
5875
5876 If the list of file systems is very long you may wish to put it
5877 in a separate file. This file is usually named
5878 @file{/etc/backup/dirs}, but this name may be overridden in
5879 @file{backup-specs} using @code{DIRLIST} variable.
5880 @end defvr
5881
5882 @defvr {Backup variable} DIRLIST
5883
5884 The name of the file that contains a list of file systems to backup
5885 or restore. By default it is @file{/etc/backup/dirs}.
5886 @end defvr
5887
5888 @defvr {Backup variable} BACKUP_FILES
5889
5890 A list of individual files to be dumped (for @code{backup}), or restored
5891 (for @code{restore}). These should be accessible from the machine on
5892 which the backup script is run.
5893
5894 If the list of file systems is very long you may wish to store it
5895 in a separate file. This file is usually named
5896 @file{/etc/backup/files}, but this name may be overridden in
5897 @file{backup-specs} using @code{FILELIST} variable.
5898 @end defvr
5899
5900 @defvr {Backup variable} FILELIST
5901
5902 The name of the file that contains a list of individual files to backup
5903 or restore. By default it is @file{/etc/backup/files}.
5904 @end defvr
5905
5906 @defvr {Backup variable} MT
5907
5908 Full file name of @command{mt} binary.
5909 @end defvr
5910
5911 @defvr {Backup variable} RSH
5912 @anchor{RSH}
5913 Full file name of @command{rsh} binary or its equivalent. You may wish to
5914 set it to @code{ssh}, to improve security. In this case you will have
5915 to use public key authentication.
5916 @end defvr
5917
5918 @defvr {Backup variable} RSH_COMMAND
5919
5920 Full file name of @command{rsh} binary on remote machines. This will
5921 be passed via @option{--rsh-command} option to the remote invocation
5922 of @GNUTAR{}.
5923 @end defvr
5924
5925 @defvr {Backup variable} VOLNO_FILE
5926
5927 Name of temporary file to hold volume numbers. This needs to be accessible
5928 by all the machines which have file systems to be dumped.
5929 @end defvr
5930
5931 @defvr {Backup variable} XLIST
5932
5933 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5934 located on the remote machine and containing the list of files to
5935 be excluded from the backup. Exclude file lists are searched in
5936 /etc/tar-backup directory. A common use for exclude file lists
5937 is to exclude files containing security-sensitive information
5938 (e.g., @file{/etc/shadow} from backups).
5939
5940 This variable affects only @code{backup}.
5941 @end defvr
5942
5943 @defvr {Backup variable} SLEEP_TIME
5944
5945 Time to sleep between dumps of any two successive file systems
5946
5947 This variable affects only @code{backup}.
5948 @end defvr
5949
5950 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5951
5952 Script to be run when it's time to insert a new tape in for the next
5953 volume. Administrators may want to tailor this script for their site.
5954 If this variable isn't set, @GNUTAR{} will display its built-in
5955 prompt, and will expect confirmation from the console. For the
5956 description of the default prompt, see @ref{change volume prompt}.
5957
5958 @end defvr
5959
5960 @defvr {Backup variable} SLEEP_MESSAGE
5961
5962 Message to display on the terminal while waiting for dump time. Usually
5963 this will just be some literal text.
5964 @end defvr
5965
5966 @defvr {Backup variable} TAR
5967
5968 Full file name of the @GNUTAR{} executable. If this is not set, backup
5969 scripts will search @command{tar} in the current shell path.
5970 @end defvr
5971
5972 @node Magnetic Tape Control
5973 @subsection Magnetic Tape Control
5974
5975 Backup scripts access tape device using special @dfn{hook functions}.
5976 These functions take a single argument -- the name of the tape
5977 device. Their names are kept in the following variables:
5978
5979 @defvr {Backup variable} MT_BEGIN
5980 The name of @dfn{begin} function. This function is called before
5981 accessing the drive. By default it retensions the tape:
5982
5983 @smallexample
5984 MT_BEGIN=mt_begin
5985
5986 mt_begin() @{
5987 mt -f "$1" retension
5988 @}
5989 @end smallexample
5990 @end defvr
5991
5992 @defvr {Backup variable} MT_REWIND
5993 The name of @dfn{rewind} function. The default definition is as
5994 follows:
5995
5996 @smallexample
5997 MT_REWIND=mt_rewind
5998
5999 mt_rewind() @{
6000 mt -f "$1" rewind
6001 @}
6002 @end smallexample
6003
6004 @end defvr
6005
6006 @defvr {Backup variable} MT_OFFLINE
6007 The name of the function switching the tape off line. By default
6008 it is defined as follows:
6009
6010 @smallexample
6011 MT_OFFLINE=mt_offline
6012
6013 mt_offline() @{
6014 mt -f "$1" offl
6015 @}
6016 @end smallexample
6017 @end defvr
6018
6019 @defvr {Backup variable} MT_STATUS
6020 The name of the function used to obtain the status of the archive device,
6021 including error count. Default definition:
6022
6023 @smallexample
6024 MT_STATUS=mt_status
6025
6026 mt_status() @{
6027 mt -f "$1" status
6028 @}
6029 @end smallexample
6030 @end defvr
6031
6032 @node User Hooks
6033 @subsection User Hooks
6034
6035 @dfn{User hooks} are shell functions executed before and after
6036 each @command{tar} invocation. Thus, there are @dfn{backup
6037 hooks}, which are executed before and after dumping each file
6038 system, and @dfn{restore hooks}, executed before and
6039 after restoring a file system. Each user hook is a shell function
6040 taking four arguments:
6041
6042 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6043 Its arguments are:
6044
6045 @table @var
6046 @item level
6047 Current backup or restore level.
6048
6049 @item host
6050 Name or IP address of the host machine being dumped or restored.
6051
6052 @item fs
6053 Full file name of the file system being dumped or restored.
6054
6055 @item fsname
6056 File system name with directory separators replaced with colons. This
6057 is useful, e.g., for creating unique files.
6058 @end table
6059 @end deffn
6060
6061 Following variables keep the names of user hook functions
6062
6063 @defvr {Backup variable} DUMP_BEGIN
6064 Dump begin function. It is executed before dumping the file system.
6065 @end defvr
6066
6067 @defvr {Backup variable} DUMP_END
6068 Executed after dumping the file system.
6069 @end defvr
6070
6071 @defvr {Backup variable} RESTORE_BEGIN
6072 Executed before restoring the file system.
6073 @end defvr
6074
6075 @defvr {Backup variable} RESTORE_END
6076 Executed after restoring the file system.
6077 @end defvr
6078
6079 @node backup-specs example
6080 @subsection An Example Text of @file{Backup-specs}
6081
6082 The following is an example of @file{backup-specs}:
6083
6084 @smallexample
6085 # site-specific parameters for file system backup.
6086
6087 ADMINISTRATOR=friedman
6088 BACKUP_HOUR=1
6089 TAPE_FILE=/dev/nrsmt0
6090
6091 # Use @code{ssh} instead of the less secure @code{rsh}
6092 RSH=/usr/bin/ssh
6093 RSH_COMMAND=/usr/bin/ssh
6094
6095 # Override MT_STATUS function:
6096 my_status() @{
6097 mts -t $TAPE_FILE
6098 @}
6099 MT_STATUS=my_status
6100
6101 # Disable MT_OFFLINE function
6102 MT_OFFLINE=:
6103
6104 BLOCKING=124
6105 BACKUP_DIRS="
6106 albert:/fs/fsf
6107 apple-gunkies:/gd
6108 albert:/fs/gd2
6109 albert:/fs/gp
6110 geech:/usr/jla
6111 churchy:/usr/roland
6112 albert:/
6113 albert:/usr
6114 apple-gunkies:/
6115 apple-gunkies:/usr
6116 gnu:/hack
6117 gnu:/u
6118 apple-gunkies:/com/mailer/gnu
6119 apple-gunkies:/com/archive/gnu"
6120
6121 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6122
6123 @end smallexample
6124
6125 @node Scripted Backups
6126 @section Using the Backup Scripts
6127
6128 The syntax for running a backup script is:
6129
6130 @smallexample
6131 backup --level=@var{level} --time=@var{time}
6132 @end smallexample
6133
6134 The @option{level} option requests the dump level. Thus, to produce
6135 a full dump, specify @code{--level=0} (this is the default, so
6136 @option{--level} may be omitted if its value is @code{0}).
6137 @footnote{For backward compatibility, the @code{backup} will also
6138 try to deduce the requested dump level from the name of the
6139 script itself. If the name consists of a string @samp{level-}
6140 followed by a single decimal digit, that digit is taken as
6141 the dump level number. Thus, you may create a link from @code{backup}
6142 to @code{level-1} and then run @code{level-1} whenever you need to
6143 create a level one dump.}
6144
6145 The @option{--time} option determines when should the backup be
6146 run. @var{Time} may take three forms:
6147
6148 @table @asis
6149 @item @var{hh}:@var{mm}
6150
6151 The dump must be run at @var{hh} hours @var{mm} minutes.
6152
6153 @item @var{hh}
6154
6155 The dump must be run at @var{hh} hours
6156
6157 @item now
6158
6159 The dump must be run immediately.
6160 @end table
6161
6162 You should start a script with a tape or disk mounted. Once you
6163 start a script, it prompts you for new tapes or disks as it
6164 needs them. Media volumes don't have to correspond to archive
6165 files --- a multi-volume archive can be started in the middle of a
6166 tape that already contains the end of another multi-volume archive.
6167 The @code{restore} script prompts for media by its archive volume,
6168 so to avoid an error message you should keep track of which tape
6169 (or disk) contains which volume of the archive (@pxref{Scripted
6170 Restoration}).
6171
6172 The backup scripts write two files on the file system. The first is a
6173 record file in @file{/etc/tar-backup/}, which is used by the scripts
6174 to store and retrieve information about which files were dumped. This
6175 file is not meant to be read by humans, and should not be deleted by
6176 them. @xref{Snapshot Files}, for a more detailed explanation of this
6177 file.
6178
6179 The second file is a log file containing the names of the file systems
6180 and files dumped, what time the backup was made, and any error
6181 messages that were generated, as well as how much space was left in
6182 the media volume after the last volume of the archive was written.
6183 You should check this log file after every backup. The file name is
6184 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6185 represents current date, and @var{n} represents current dump level number.
6186
6187 The script also prints the name of each system being dumped to the
6188 standard output.
6189
6190 Following is the full list of options accepted by @code{backup}
6191 script:
6192
6193 @table @option
6194 @item -l @var{level}
6195 @itemx --level=@var{level}
6196 Do backup level @var{level} (default 0).
6197
6198 @item -f
6199 @itemx --force
6200 Force backup even if today's log file already exists.
6201
6202 @item -v[@var{level}]
6203 @itemx --verbose[=@var{level}]
6204 Set verbosity level. The higher the level is, the more debugging
6205 information will be output during execution. Default @var{level}
6206 is 100, which means the highest debugging level.
6207
6208 @item -t @var{start-time}
6209 @itemx --time=@var{start-time}
6210 Wait till @var{time}, then do backup.
6211
6212 @item -h
6213 @itemx --help
6214 Display short help message and exit.
6215
6216 @item -V
6217 @itemx --version
6218 Display information about the program's name, version, origin and legal
6219 status, all on standard output, and then exit successfully.
6220 @end table
6221
6222
6223 @node Scripted Restoration
6224 @section Using the Restore Script
6225
6226 To restore files that were archived using a scripted backup, use the
6227 @code{restore} script. Its usage is quite straightforward. In the
6228 simplest form, invoke @code{restore --all}, it will
6229 then restore all the file systems and files specified in
6230 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6231
6232 You may select the file systems (and/or files) to restore by
6233 giving @code{restore} list of @dfn{patterns} in its command
6234 line. For example, running
6235
6236 @smallexample
6237 restore 'albert:*'
6238 @end smallexample
6239
6240 @noindent
6241 will restore all file systems on the machine @samp{albert}. A more
6242 complicated example:
6243
6244 @smallexample
6245 restore 'albert:*' '*:/var'
6246 @end smallexample
6247
6248 @noindent
6249 This command will restore all file systems on the machine @samp{albert}
6250 as well as @file{/var} file system on all machines.
6251
6252 By default @code{restore} will start restoring files from the lowest
6253 available dump level (usually zero) and will continue through
6254 all available dump levels. There may be situations where such a
6255 thorough restore is not necessary. For example, you may wish to
6256 restore only files from the recent level one backup. To do so,
6257 use @option{--level} option, as shown in the example below:
6258
6259 @smallexample
6260 restore --level=1
6261 @end smallexample
6262
6263 The full list of options accepted by @code{restore} follows:
6264
6265 @table @option
6266 @item -a
6267 @itemx --all
6268 Restore all file systems and files specified in @file{backup-specs}
6269
6270 @item -l @var{level}
6271 @itemx --level=@var{level}
6272 Start restoring from the given backup level, instead of the default 0.
6273
6274 @item -v[@var{level}]
6275 @itemx --verbose[=@var{level}]
6276 Set verbosity level. The higher the level is, the more debugging
6277 information will be output during execution. Default @var{level}
6278 is 100, which means the highest debugging level.
6279
6280 @item -h
6281 @itemx --help
6282 Display short help message and exit.
6283
6284 @item -V
6285 @itemx --version
6286 Display information about the program's name, version, origin and legal
6287 status, all on standard output, and then exit successfully.
6288 @end table
6289
6290 You should start the restore script with the media containing the
6291 first volume of the archive mounted. The script will prompt for other
6292 volumes as they are needed. If the archive is on tape, you don't need
6293 to rewind the tape to to its beginning---if the tape head is
6294 positioned past the beginning of the archive, the script will rewind
6295 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6296 positioning.
6297
6298 @quotation
6299 @strong{Warning:} The script will delete files from the active file
6300 system if they were not in the file system when the archive was made.
6301 @end quotation
6302
6303 @xref{Incremental Dumps}, for an explanation of how the script makes
6304 that determination.
6305
6306 @node Choosing
6307 @chapter Choosing Files and Names for @command{tar}
6308 @UNREVISED
6309
6310 Certain options to @command{tar} enable you to specify a name for your
6311 archive. Other options let you decide which files to include or exclude
6312 from the archive, based on when or whether files were modified, whether
6313 the file names do or don't match specified patterns, or whether files
6314 are in specified directories.
6315
6316 This chapter discusses these options in detail.
6317
6318 @menu
6319 * file:: Choosing the Archive's Name
6320 * Selecting Archive Members::
6321 * files:: Reading Names from a File
6322 * exclude:: Excluding Some Files
6323 * wildcards:: Wildcards Patterns and Matching
6324 * quoting styles:: Ways of Quoting Special Characters in Names
6325 * transform:: Modifying File and Member Names
6326 * after:: Operating Only on New Files
6327 * recurse:: Descending into Directories
6328 * one:: Crossing File System Boundaries
6329 @end menu
6330
6331 @node file
6332 @section Choosing and Naming Archive Files
6333 @UNREVISED
6334
6335 @cindex Naming an archive
6336 @cindex Archive Name
6337 @cindex Choosing an archive file
6338 @cindex Where is the archive?
6339 By default, @command{tar} uses an archive file name that was compiled when
6340 it was built on the system; usually this name refers to some physical
6341 tape drive on the machine. However, the person who installed @command{tar}
6342 on the system may not have set the default to a meaningful value as far as
6343 most users are concerned. As a result, you will usually want to tell
6344 @command{tar} where to find (or create) the archive. The
6345 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6346 option allows you to either specify or name a file to use as the archive
6347 instead of the default archive file location.
6348
6349 @table @option
6350 @xopindex{file, short description}
6351 @item --file=@var{archive-name}
6352 @itemx -f @var{archive-name}
6353 Name the archive to create or operate on. Use in conjunction with
6354 any operation.
6355 @end table
6356
6357 For example, in this @command{tar} command,
6358
6359 @smallexample
6360 $ @kbd{tar -cvf collection.tar blues folk jazz}
6361 @end smallexample
6362
6363 @noindent
6364 @file{collection.tar} is the name of the archive. It must directly
6365 follow the @option{-f} option, since whatever directly follows @option{-f}
6366 @emph{will} end up naming the archive. If you neglect to specify an
6367 archive name, you may end up overwriting a file in the working directory
6368 with the archive you create since @command{tar} will use this file's name
6369 for the archive name.
6370
6371 An archive can be saved as a file in the file system, sent through a
6372 pipe or over a network, or written to an I/O device such as a tape,
6373 floppy disk, or CD write drive.
6374
6375 @cindex Writing new archives
6376 @cindex Archive creation
6377 If you do not name the archive, @command{tar} uses the value of the
6378 environment variable @env{TAPE} as the file name for the archive. If
6379 that is not available, @command{tar} uses a default, compiled-in archive
6380 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6381
6382 @cindex Standard input and output
6383 @cindex tar to standard input and output
6384 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6385 archive from standard input (when listing or extracting files), or
6386 writes it to standard output (when creating an archive). If you use
6387 @file{-} as an @var{archive-name} when modifying an archive,
6388 @command{tar} reads the original archive from its standard input and
6389 writes the entire new archive to its standard output.
6390
6391 The following example is a convenient way of copying directory
6392 hierarchy from @file{sourcedir} to @file{targetdir}.
6393
6394 @smallexample
6395 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6396 @end smallexample
6397
6398 The @option{-C} option allows to avoid using subshells:
6399
6400 @smallexample
6401 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6402 @end smallexample
6403
6404 In both examples above, the leftmost @command{tar} invocation archives
6405 the contents of @file{sourcedir} to the standard output, while the
6406 rightmost one reads this archive from its standard input and
6407 extracts it. The @option{-p} option tells it to restore permissions
6408 of the extracted files.
6409
6410 @cindex Remote devices
6411 @cindex tar to a remote device
6412 @anchor{remote-dev}
6413 To specify an archive file on a device attached to a remote machine,
6414 use the following:
6415
6416 @smallexample
6417 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6418 @end smallexample
6419
6420 @noindent
6421 @command{tar} will complete the remote connection, if possible, and
6422 prompt you for a username and password. If you use
6423 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6424 will complete the remote connection, if possible, using your username
6425 as the username on the remote machine.
6426
6427 @cindex Local and remote archives
6428 @anchor{local and remote archives}
6429 If the archive file name includes a colon (@samp{:}), then it is assumed
6430 to be a file on another machine. If the archive file is
6431 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6432 host @var{host}. The remote host is accessed using the @command{rsh}
6433 program, with a username of @var{user}. If the username is omitted
6434 (along with the @samp{@@} sign), then your user name will be used.
6435 (This is the normal @command{rsh} behavior.) It is necessary for the
6436 remote machine, in addition to permitting your @command{rsh} access, to
6437 have the @file{rmt} program installed (This command is included in
6438 the @GNUTAR{} distribution and by default is installed under
6439 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6440 installation prefix). If you need to use a file whose name includes a
6441 colon, then the remote tape drive behavior
6442 can be inhibited by using the @option{--force-local} option.
6443
6444 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6445 tries to minimize input and output operations. The Amanda backup
6446 system, when used with @GNUTAR{}, has an initial sizing pass which
6447 uses this feature.
6448
6449 @node Selecting Archive Members
6450 @section Selecting Archive Members
6451 @cindex Specifying files to act on
6452 @cindex Specifying archive members
6453
6454 @dfn{File Name arguments} specify which files in the file system
6455 @command{tar} operates on, when creating or adding to an archive, or which
6456 archive members @command{tar} operates on, when reading or deleting from
6457 an archive. @xref{Operations}.
6458
6459 To specify file names, you can include them as the last arguments on
6460 the command line, as follows:
6461 @smallexample
6462 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6463 @end smallexample
6464
6465 If a file name begins with dash (@samp{-}), precede it with
6466 @option{--add-file} option to prevent it from being treated as an
6467 option.
6468
6469 @anchor{input name quoting}
6470 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6471 name, replacing @dfn{escape sequences} according to the following
6472 table:
6473
6474 @multitable @columnfractions 0.20 0.60
6475 @headitem Escape @tab Replaced with
6476 @item \a @tab Audible bell (@acronym{ASCII} 7)
6477 @item \b @tab Backspace (@acronym{ASCII} 8)
6478 @item \f @tab Form feed (@acronym{ASCII} 12)
6479 @item \n @tab New line (@acronym{ASCII} 10)
6480 @item \r @tab Carriage return (@acronym{ASCII} 13)
6481 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6482 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6483 @item \? @tab @acronym{ASCII} 127
6484 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6485 of up to 3 digits)
6486 @end multitable
6487
6488 A backslash followed by any other symbol is retained.
6489
6490 This default behavior is controlled by the following command line
6491 option:
6492
6493 @table @option
6494 @opindex unquote
6495 @item --unquote
6496 Enable unquoting input file or member names (default).
6497
6498 @opindex no-unquote
6499 @item --no-unquote
6500 Disable unquoting input file or member names.
6501 @end table
6502
6503 If you specify a directory name as a file name argument, all the files
6504 in that directory are operated on by @command{tar}.
6505
6506 If you do not specify files, @command{tar} behavior differs depending
6507 on the operation mode as described below:
6508
6509 When @command{tar} is invoked with @option{--create} (@option{-c}),
6510 @command{tar} will stop immediately, reporting the following:
6511
6512 @smallexample
6513 @group
6514 $ @kbd{tar cf a.tar}
6515 tar: Cowardly refusing to create an empty archive
6516 Try `tar --help' or `tar --usage' for more information.
6517 @end group
6518 @end smallexample
6519
6520 If you specify either @option{--list} (@option{-t}) or
6521 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6522 operates on all the archive members in the archive.
6523
6524 If run with @option{--diff} option, tar will compare the archive with
6525 the contents of the current working directory.
6526
6527 If you specify any other operation, @command{tar} does nothing.
6528
6529 By default, @command{tar} takes file names from the command line. However,
6530 there are other ways to specify file or member names, or to modify the
6531 manner in which @command{tar} selects the files or members upon which to
6532 operate. In general, these methods work both for specifying the names
6533 of files and archive members.
6534
6535 @node files
6536 @section Reading Names from a File
6537
6538 @cindex Reading file names from a file
6539 @cindex Lists of file names
6540 @cindex File Name arguments, alternatives
6541 Instead of giving the names of files or archive members on the command
6542 line, you can put the names into a file, and then use the
6543 @option{--files-from=@var{file-of-names}} (@option{-T
6544 @var{file-of-names}}) option to @command{tar}. Give the name of the
6545 file which contains the list of files to include as the argument to
6546 @option{--files-from}. In the list, the file names should be separated by
6547 newlines. You will frequently use this option when you have generated
6548 the list of files to archive with the @command{find} utility.
6549
6550 @table @option
6551 @opindex files-from
6552 @item --files-from=@var{file-name}
6553 @itemx -T @var{file-name}
6554 Get names to extract or create from file @var{file-name}.
6555 @end table
6556
6557 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6558 you specify either @code{--files-from=-} or @code{-T -}), then the file
6559 names are read from standard input.
6560
6561 Unless you are running @command{tar} with @option{--create}, you can not use
6562 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6563 command.
6564
6565 Any number of @option{-T} options can be given in the command line.
6566
6567 The following example shows how to use @command{find} to generate a list of
6568 files smaller than 400K in length and put that list into a file
6569 called @file{small-files}. You can then use the @option{-T} option to
6570 @command{tar} to specify the files from that file, @file{small-files}, to
6571 create the archive @file{little.tgz}. (The @option{-z} option to
6572 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6573 more information.)
6574
6575 @smallexample
6576 $ @kbd{find . -size -400 -print > small-files}
6577 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6578 @end smallexample
6579
6580 @noindent
6581 In the file list given by @option{-T} option, any file name beginning
6582 with @samp{-} character is considered a @command{tar} option and is
6583 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6584 recognized only @option{-C} option in file lists, and only if the
6585 option and its argument occupied two consecutive lines.} For example,
6586 the common use of this feature is to change to another directory by
6587 specifying @option{-C} option:
6588
6589 @smallexample
6590 @group
6591 $ @kbd{cat list}
6592 -C/etc
6593 passwd
6594 hosts
6595 -C/lib
6596 libc.a
6597 $ @kbd{tar -c -f foo.tar --files-from list}
6598 @end group
6599 @end smallexample
6600
6601 @noindent
6602 In this example, @command{tar} will first switch to @file{/etc}
6603 directory and add files @file{passwd} and @file{hosts} to the
6604 archive. Then it will change to @file{/lib} directory and will archive
6605 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6606 contain:
6607
6608 @smallexample
6609 @group
6610 $ @kbd{tar tf foo.tar}
6611 passwd
6612 hosts
6613 libc.a
6614 @end group
6615 @end smallexample
6616
6617 @noindent
6618 @xopindex{directory, using in @option{--files-from} argument}
6619 Notice that the option parsing algorithm used with @option{-T} is
6620 stricter than the one used by shell. Namely, when specifying option
6621 arguments, you should observe the following rules:
6622
6623 @itemize @bullet
6624 @item
6625 When using short (single-letter) option form, its argument must
6626 immediately follow the option letter, without any intervening
6627 whitespace. For example: @code{-Cdir}.
6628
6629 @item
6630 When using long option form, the option argument must be separated
6631 from the option by a single equal sign. No whitespace is allowed on
6632 any side of the equal sign. For example: @code{--directory=dir}.
6633
6634 @item
6635 For both short and long option forms, the option argument can be given
6636 on the next line after the option name, e.g.:
6637
6638 @smallexample
6639 @group
6640 --directory
6641 dir
6642 @end group
6643 @end smallexample
6644
6645 @noindent
6646 and
6647
6648 @smallexample
6649 @group
6650 -C
6651 dir
6652 @end group
6653 @end smallexample
6654 @end itemize
6655
6656 @opindex add-file
6657 If you happen to have a file whose name starts with @samp{-},
6658 precede it with @option{--add-file} option to prevent it from
6659 being recognized as an option. For example: @code{--add-file=--my-file}.
6660
6661 @menu
6662 * nul::
6663 @end menu
6664
6665 @node nul
6666 @subsection @code{NUL} Terminated File Names
6667
6668 @cindex File names, terminated by @code{NUL}
6669 @cindex @code{NUL} terminated file names
6670 The @option{--null} option causes
6671 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6672 to read file names terminated by a @code{NUL} instead of a newline, so
6673 files whose names contain newlines can be archived using
6674 @option{--files-from}.
6675
6676 @table @option
6677 @opindex null
6678 @item --null
6679 Only consider @code{NUL} terminated file names, instead of files that
6680 terminate in a newline.
6681 @end table
6682
6683 The @option{--null} option is just like the one in @acronym{GNU}
6684 @command{xargs} and @command{cpio}, and is useful with the
6685 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6686 @command{tar}, @option{--null} also disables special handling for
6687 file names that begin with dash.
6688
6689 This example shows how to use @command{find} to generate a list of files
6690 larger than 800K in length and put that list into a file called
6691 @file{long-files}. The @option{-print0} option to @command{find} is just
6692 like @option{-print}, except that it separates files with a @code{NUL}
6693 rather than with a newline. You can then run @command{tar} with both the
6694 @option{--null} and @option{-T} options to specify that @command{tar} get the
6695 files from that file, @file{long-files}, to create the archive
6696 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6697 @command{tar} to recognize the @code{NUL} separator between files.
6698
6699 @smallexample
6700 $ @kbd{find . -size +800 -print0 > long-files}
6701 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6702 @end smallexample
6703
6704 @FIXME{say anything else here to conclude the section?}
6705
6706 @node exclude
6707 @section Excluding Some Files
6708 @UNREVISED
6709
6710 @cindex File names, excluding files by
6711 @cindex Excluding files by name and pattern
6712 @cindex Excluding files by file system
6713 To avoid operating on files whose names match a particular pattern,
6714 use the @option{--exclude} or @option{--exclude-from} options.
6715
6716 @table @option
6717 @opindex exclude
6718 @item --exclude=@var{pattern}
6719 Causes @command{tar} to ignore files that match the @var{pattern}.
6720 @end table
6721
6722 @findex exclude
6723 The @option{--exclude=@var{pattern}} option prevents any file or
6724 member whose name matches the shell wildcard (@var{pattern}) from
6725 being operated on.
6726 For example, to create an archive with all the contents of the directory
6727 @file{src} except for files whose names end in @file{.o}, use the
6728 command @samp{tar -cf src.tar --exclude='*.o' src}.
6729
6730 You may give multiple @option{--exclude} options.
6731
6732 @table @option
6733 @opindex exclude-from
6734 @item --exclude-from=@var{file}
6735 @itemx -X @var{file}
6736 Causes @command{tar} to ignore files that match the patterns listed in
6737 @var{file}.
6738 @end table
6739
6740 @findex exclude-from
6741 Use the @option{--exclude-from} option to read a
6742 list of patterns, one per line, from @var{file}; @command{tar} will
6743 ignore files matching those patterns. Thus if @command{tar} is
6744 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6745 single line @file{*.o}, no files whose names end in @file{.o} will be
6746 added to the archive.
6747
6748 Notice, that lines from @var{file} are read verbatim. One of the
6749 frequent errors is leaving some extra whitespace after a file name,
6750 which is difficult to catch using text editors.
6751
6752 However, empty lines are OK.
6753
6754 @cindex version control system, excluding files
6755 @cindex VCS, excluding files
6756 @cindex SCCS, excluding files
6757 @cindex RCS, excluding files
6758 @cindex CVS, excluding files
6759 @cindex SVN, excluding files
6760 @cindex git, excluding files
6761 @table @option
6762 @opindex exclude-vcs
6763 @item --exclude-vcs
6764 Exclude files and directories used by some version control systems.
6765 @end table
6766
6767 As of version @value{VERSION}, the following files are excluded:
6768
6769 @itemize @bullet
6770 @item @file{CVS/}, and everything under it
6771 @item @file{RCS/}, and everything under it
6772 @item @file{SCCS/}, and everything under it
6773 @item @file{.git/}, and everything under it
6774 @item @file{.gitignore}
6775 @item @file{.cvsignore}
6776 @item @file{.svn/}, and everything under it
6777 @item @file{.arch-ids/}, and everything under it
6778 @item @file{@{arch@}/}, and everything under it
6779 @item @file{=RELEASE-ID}
6780 @item @file{=meta-update}
6781 @item @file{=update}
6782 @end itemize
6783
6784 @findex exclude-caches
6785 When creating an archive, the @option{--exclude-caches} option family
6786 causes @command{tar} to exclude all directories that contain a @dfn{cache
6787 directory tag}. A cache directory tag is a short file with the
6788 well-known name @file{CACHEDIR.TAG} and having a standard header
6789 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6790 Various applications write cache directory tags into directories they
6791 use to hold regenerable, non-precious data, so that such data can be
6792 more easily excluded from backups.
6793
6794 There are three @samp{exclude-caches} options, each providing a different
6795 exclusion semantics:
6796
6797 @table @option
6798 @opindex exclude-caches
6799 @item --exclude-caches
6800 Do not archive the contents of the directory, but archive the
6801 directory itself and the @file{CACHEDIR.TAG} file.
6802
6803 @opindex exclude-caches-under
6804 @item --exclude-caches-under
6805 Do not archive the contents of the directory, nor the
6806 @file{CACHEDIR.TAG} file, archive only the directory itself.
6807
6808 @opindex exclude-caches-all
6809 @item --exclude-caches-all
6810 Omit directories containing @file{CACHEDIR.TAG} file entirely.
6811 @end table
6812
6813 @findex exclude-tag
6814 Another option family, @option{--exclude-tag}, provides a generalization of
6815 this concept. It takes a single argument, a file name to look for.
6816 Any directory that contains this file will be excluded from the dump.
6817 Similarly to @samp{exclude-caches}, there are three options in this
6818 option family:
6819
6820 @table @option
6821 @opindex exclude-tag
6822 @item --exclude-tag=@var{file}
6823 Do not dump the contents of the directory, but dump the
6824 directory itself and the @var{file}.
6825
6826 @opindex exclude-tag-under
6827 @item --exclude-tag-under=@var{file}
6828 Do not dump the contents of the directory, nor the
6829 @var{file}, archive only the directory itself.
6830
6831 @opindex exclude-tag-all
6832 @item --exclude-tag-all=@var{file}
6833 Omit directories containing @var{file} file entirely.
6834 @end table
6835
6836 Multiple @option{--exclude-tag*} options can be given.
6837
6838 For example, given this directory:
6839
6840 @smallexample
6841 @group
6842 $ @kbd{find dir}
6843 dir
6844 dir/blues
6845 dir/jazz
6846 dir/folk
6847 dir/folk/tagfile
6848 dir/folk/sanjuan
6849 dir/folk/trote
6850 @end group
6851 @end smallexample
6852
6853 The @option{--exclude-tag} will produce the following:
6854
6855 @smallexample
6856 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
6857 dir/
6858 dir/blues
6859 dir/jazz
6860 dir/folk/
6861 tar: dir/folk/: contains a cache directory tag tagfile;
6862 contents not dumped
6863 dir/folk/tagfile
6864 @end smallexample
6865
6866 Both the @file{dir/folk} directory and its tagfile are preserved in
6867 the archive, however the rest of files in this directory are not.
6868
6869 Now, using the @option{--exclude-tag-under} option will exclude
6870 @file{tagfile} from the dump, while still preserving the directory
6871 itself, as shown in this example:
6872
6873 @smallexample
6874 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
6875 dir/
6876 dir/blues
6877 dir/jazz
6878 dir/folk/
6879 ./tar: dir/folk/: contains a cache directory tag tagfile;
6880 contents not dumped
6881 @end smallexample
6882
6883 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
6884 directory entirely:
6885
6886 @smallexample
6887 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
6888 dir/
6889 dir/blues
6890 dir/jazz
6891 ./tar: dir/folk/: contains a cache directory tag tagfile;
6892 directory not dumped
6893 @end smallexample
6894
6895 @menu
6896 * problems with exclude::
6897 @end menu
6898
6899 @node problems with exclude
6900 @unnumberedsubsec Problems with Using the @code{exclude} Options
6901
6902 @xopindex{exclude, potential problems with}
6903 Some users find @samp{exclude} options confusing. Here are some common
6904 pitfalls:
6905
6906 @itemize @bullet
6907 @item
6908 The main operating mode of @command{tar} does not act on a file name
6909 explicitly listed on the command line, if one of its file name
6910 components is excluded. In the example above, if
6911 you create an archive and exclude files that end with @samp{*.o}, but
6912 explicitly name the file @samp{dir.o/foo} after all the options have been
6913 listed, @samp{dir.o/foo} will be excluded from the archive.
6914
6915 @item
6916 You can sometimes confuse the meanings of @option{--exclude} and
6917 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6918 to be excluded are given as a pattern on the command line. Use
6919 @option{--exclude-from} to introduce the name of a file which contains
6920 a list of patterns, one per line; each of these patterns can exclude
6921 zero, one, or many files.
6922
6923 @item
6924 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6925 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6926 like @samp{*}. If you do not do this, the shell might expand the
6927 @samp{*} itself using files at hand, so @command{tar} might receive a
6928 list of files instead of one pattern, or none at all, making the
6929 command somewhat illegal. This might not correspond to what you want.
6930
6931 For example, write:
6932
6933 @smallexample
6934 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6935 @end smallexample
6936
6937 @noindent
6938 rather than:
6939
6940 @smallexample
6941 # @emph{Wrong!}
6942 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6943 @end smallexample
6944
6945 @item
6946 You must use use shell syntax, or globbing, rather than @code{regexp}
6947 syntax, when using exclude options in @command{tar}. If you try to use
6948 @code{regexp} syntax to describe files to be excluded, your command
6949 might fail.
6950
6951 @item
6952 @FIXME{The change in semantics must have occurred before 1.11,
6953 so I doubt if it is worth mentioning at all. Anyway, should at
6954 least specify in which version the semantics changed.}
6955 In earlier versions of @command{tar}, what is now the
6956 @option{--exclude-from} option was called @option{--exclude} instead.
6957 Now, @option{--exclude} applies to patterns listed on the command
6958 line and @option{--exclude-from} applies to patterns listed in a
6959 file.
6960
6961 @end itemize
6962
6963 @node wildcards
6964 @section Wildcards Patterns and Matching
6965
6966 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6967 @samp{*} or @samp{?} for example, are replaced and expanded into all
6968 existing files matching the given pattern. @GNUTAR{} can use wildcard
6969 patterns for matching (or globbing) archive members when extracting
6970 from or listing an archive. Wildcard patterns are also used for
6971 verifying volume labels of @command{tar} archives. This section has the
6972 purpose of explaining wildcard syntax for @command{tar}.
6973
6974 @FIXME{the next few paragraphs need work.}
6975
6976 A @var{pattern} should be written according to shell syntax, using wildcard
6977 characters to effect globbing. Most characters in the pattern stand
6978 for themselves in the matched string, and case is significant: @samp{a}
6979 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6980 pattern matches any single character in the matched string. The character
6981 @samp{*} in the pattern matches zero, one, or more single characters in
6982 the matched string. The character @samp{\} says to take the following
6983 character of the pattern @emph{literally}; it is useful when one needs to
6984 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6985
6986 The character @samp{[}, up to the matching @samp{]}, introduces a character
6987 class. A @dfn{character class} is a list of acceptable characters
6988 for the next single character of the matched string. For example,
6989 @samp{[abcde]} would match any of the first five letters of the alphabet.
6990 Note that within a character class, all of the ``special characters''
6991 listed above other than @samp{\} lose their special meaning; for example,
6992 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6993 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6994 the characters @samp{-} and @samp{]} must either come @emph{first} or
6995 @emph{last} in a character class.)
6996
6997 @cindex Excluding characters from a character class
6998 @cindex Character class, excluding characters from
6999 If the first character of the class after the opening @samp{[}
7000 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7001 Rather than listing character to match, it lists those characters which
7002 are @emph{forbidden} as the next single character of the matched string.
7003
7004 Other characters of the class stand for themselves. The special
7005 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7006 letters, is meant to represent all characters between @var{a} and
7007 @var{e}, inclusive.
7008
7009 @FIXME{need to add a sentence or so here to make this clear for those
7010 who don't have dan around.}
7011
7012 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7013 special for wildcard matches. However, if a pattern completely matches
7014 a directory prefix of a matched string, then it matches the full matched
7015 string: thus, excluding a directory also excludes all the files beneath it.
7016
7017 @menu
7018 * controlling pattern-matching::
7019 @end menu
7020
7021 @node controlling pattern-matching
7022 @unnumberedsubsec Controlling Pattern-Matching
7023
7024 For the purposes of this section, we call @dfn{exclusion members} all
7025 member names obtained while processing @option{--exclude} and
7026 @option{--exclude-from} options, and @dfn{inclusion members} those
7027 member names that were given in the command line or read from the file
7028 specified with @option{--files-from} option.
7029
7030 These two pairs of member lists are used in the following operations:
7031 @option{--diff}, @option{--extract}, @option{--list},
7032 @option{--update}.
7033
7034 There are no inclusion members in create mode (@option{--create} and
7035 @option{--append}), since in this mode the names obtained from the
7036 command line refer to @emph{files}, not archive members.
7037
7038 By default, inclusion members are compared with archive members
7039 literally @footnote{Notice that earlier @GNUTAR{} versions used
7040 globbing for inclusion members, which contradicted to UNIX98
7041 specification and was not documented. @xref{Changes}, for more
7042 information on this and other changes.} and exclusion members are
7043 treated as globbing patterns. For example:
7044
7045 @smallexample
7046 @group
7047 $ @kbd{tar tf foo.tar}
7048 a.c
7049 b.c
7050 a.txt
7051 [remarks]
7052 # @i{Member names are used verbatim:}
7053 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7054 [remarks]
7055 # @i{Exclude member names are globbed:}
7056 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7057 a.txt
7058 [remarks]
7059 @end group
7060 @end smallexample
7061
7062 This behavior can be altered by using the following options:
7063
7064 @table @option
7065 @opindex wildcards
7066 @item --wildcards
7067 Treat all member names as wildcards.
7068
7069 @opindex no-wildcards
7070 @item --no-wildcards
7071 Treat all member names as literal strings.
7072 @end table
7073
7074 Thus, to extract files whose names end in @samp{.c}, you can use:
7075
7076 @smallexample
7077 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7078 a.c
7079 b.c
7080 @end smallexample
7081
7082 @noindent
7083 Notice quoting of the pattern to prevent the shell from interpreting
7084 it.
7085
7086 The effect of @option{--wildcards} option is canceled by
7087 @option{--no-wildcards}. This can be used to pass part of
7088 the command line arguments verbatim and other part as globbing
7089 patterns. For example, the following invocation:
7090
7091 @smallexample
7092 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7093 @end smallexample
7094
7095 @noindent
7096 instructs @command{tar} to extract from @file{foo.tar} all files whose
7097 names end in @samp{.txt} and the file named @file{[remarks]}.
7098
7099 Normally, a pattern matches a name if an initial subsequence of the
7100 name's components matches the pattern, where @samp{*}, @samp{?}, and
7101 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7102 and wildcards can match @samp{/}.
7103
7104 Other than optionally stripping leading @samp{/} from names
7105 (@pxref{absolute}), patterns and names are used as-is. For
7106 example, trailing @samp{/} is not trimmed from a user-specified name
7107 before deciding whether to exclude it.
7108
7109 However, this matching procedure can be altered by the options listed
7110 below. These options accumulate. For example:
7111
7112 @smallexample
7113 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7114 @end smallexample
7115
7116 @noindent
7117 ignores case when excluding @samp{makefile}, but not when excluding
7118 @samp{readme}.
7119
7120 @table @option
7121 @opindex anchored
7122 @opindex no-anchored
7123 @item --anchored
7124 @itemx --no-anchored
7125 If anchored, a pattern must match an initial subsequence
7126 of the name's components. Otherwise, the pattern can match any
7127 subsequence. Default is @option{--no-anchored} for exclusion members
7128 and @option{--anchored} inclusion members.
7129
7130 @opindex ignore-case
7131 @opindex no-ignore-case
7132 @item --ignore-case
7133 @itemx --no-ignore-case
7134 When ignoring case, upper-case patterns match lower-case names and vice versa.
7135 When not ignoring case (the default), matching is case-sensitive.
7136
7137 @opindex wildcards-match-slash
7138 @opindex no-wildcards-match-slash
7139 @item --wildcards-match-slash
7140 @itemx --no-wildcards-match-slash
7141 When wildcards match slash (the default for exclusion members), a
7142 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7143 name. Otherwise, @samp{/} is matched only by @samp{/}.
7144
7145 @end table
7146
7147 The @option{--recursion} and @option{--no-recursion} options
7148 (@pxref{recurse}) also affect how member patterns are interpreted. If
7149 recursion is in effect, a pattern matches a name if it matches any of
7150 the name's parent directories.
7151
7152 The following table summarizes pattern-matching default values:
7153
7154 @multitable @columnfractions .3 .7
7155 @headitem Members @tab Default settings
7156 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7157 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7158 @end multitable
7159
7160 @node quoting styles
7161 @section Quoting Member Names
7162
7163 When displaying member names, @command{tar} takes care to avoid
7164 ambiguities caused by certain characters. This is called @dfn{name
7165 quoting}. The characters in question are:
7166
7167 @itemize @bullet
7168 @item Non-printable control characters:
7169 @anchor{escape sequences}
7170 @multitable @columnfractions 0.20 0.10 0.60
7171 @headitem Character @tab @acronym{ASCII} @tab Character name
7172 @item \a @tab 7 @tab Audible bell
7173 @item \b @tab 8 @tab Backspace
7174 @item \f @tab 12 @tab Form feed
7175 @item \n @tab 10 @tab New line
7176 @item \r @tab 13 @tab Carriage return
7177 @item \t @tab 9 @tab Horizontal tabulation
7178 @item \v @tab 11 @tab Vertical tabulation
7179 @end multitable
7180
7181 @item Space (@acronym{ASCII} 32)
7182
7183 @item Single and double quotes (@samp{'} and @samp{"})
7184
7185 @item Backslash (@samp{\})
7186 @end itemize
7187
7188 The exact way @command{tar} uses to quote these characters depends on
7189 the @dfn{quoting style}. The default quoting style, called
7190 @dfn{escape} (see below), uses backslash notation to represent control
7191 characters, space and backslash. Using this quoting style, control
7192 characters are represented as listed in column @samp{Character} in the
7193 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7194
7195 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7196 using @option{--quoting-style} option:
7197
7198 @table @option
7199 @item --quoting-style=@var{style}
7200 @opindex quoting-style
7201
7202 Sets quoting style. Valid values for @var{style} argument are:
7203 literal, shell, shell-always, c, escape, locale, clocale.
7204 @end table
7205
7206 These styles are described in detail below. To illustrate their
7207 effect, we will use an imaginary tar archive @file{arch.tar}
7208 containing the following members:
7209
7210 @smallexample
7211 @group
7212 # 1. Contains horizontal tabulation character.
7213 a tab
7214 # 2. Contains newline character
7215 a
7216 newline
7217 # 3. Contains a space
7218 a space
7219 # 4. Contains double quotes
7220 a"double"quote
7221 # 5. Contains single quotes
7222 a'single'quote
7223 # 6. Contains a backslash character:
7224 a\backslash
7225 @end group
7226 @end smallexample
7227
7228 Here is how usual @command{ls} command would have listed them, if they
7229 had existed in the current working directory:
7230
7231 @smallexample
7232 @group
7233 $ @kbd{ls}
7234 a\ttab
7235 a\nnewline
7236 a\ space
7237 a"double"quote
7238 a'single'quote
7239 a\\backslash
7240 @end group
7241 @end smallexample
7242
7243 Quoting styles:
7244
7245 @table @samp
7246 @item literal
7247 No quoting, display each character as is:
7248
7249 @smallexample
7250 @group
7251 $ @kbd{tar tf arch.tar --quoting-style=literal}
7252 ./
7253 ./a space
7254 ./a'single'quote
7255 ./a"double"quote
7256 ./a\backslash
7257 ./a tab
7258 ./a
7259 newline
7260 @end group
7261 @end smallexample
7262
7263 @item shell
7264 Display characters the same way Bourne shell does:
7265 control characters, except @samp{\t} and @samp{\n}, are printed using
7266 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7267 single quote is printed as @samp{\'}. If a name contains any quoted
7268 characters, it is enclosed in single quotes. In particular, if a name
7269 contains single quotes, it is printed as several single-quoted strings:
7270
7271 @smallexample
7272 @group
7273 $ @kbd{tar tf arch.tar --quoting-style=shell}
7274 ./
7275 './a space'
7276 './a'\''single'\''quote'
7277 './a"double"quote'
7278 './a\backslash'
7279 './a tab'
7280 './a
7281 newline'
7282 @end group
7283 @end smallexample
7284
7285 @item shell-always
7286 Same as @samp{shell}, but the names are always enclosed in single
7287 quotes:
7288
7289 @smallexample
7290 @group
7291 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7292 './'
7293 './a space'
7294 './a'\''single'\''quote'
7295 './a"double"quote'
7296 './a\backslash'
7297 './a tab'
7298 './a
7299 newline'
7300 @end group
7301 @end smallexample
7302
7303 @item c
7304 Use the notation of the C programming language. All names are
7305 enclosed in double quotes. Control characters are quoted using
7306 backslash notations, double quotes are represented as @samp{\"},
7307 backslash characters are represented as @samp{\\}. Single quotes and
7308 spaces are not quoted:
7309
7310 @smallexample
7311 @group
7312 $ @kbd{tar tf arch.tar --quoting-style=c}
7313 "./"
7314 "./a space"
7315 "./a'single'quote"
7316 "./a\"double\"quote"
7317 "./a\\backslash"
7318 "./a\ttab"
7319 "./a\nnewline"
7320 @end group
7321 @end smallexample
7322
7323 @item escape
7324 Control characters are printed using backslash notation, a space is
7325 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7326 default quoting style, unless it was changed when configured the
7327 package.
7328
7329 @smallexample
7330 @group
7331 $ @kbd{tar tf arch.tar --quoting-style=escape}
7332 ./
7333 ./a space
7334 ./a'single'quote
7335 ./a"double"quote
7336 ./a\\backslash
7337 ./a\ttab
7338 ./a\nnewline
7339 @end group
7340 @end smallexample
7341
7342 @item locale
7343 Control characters, single quote and backslash are printed using
7344 backslash notation. All names are quoted using left and right
7345 quotation marks, appropriate to the current locale. If it does not
7346 define quotation marks, use @samp{`} as left and @samp{'} as right
7347 quotation marks. Any occurrences of the right quotation mark in a
7348 name are escaped with @samp{\}, for example:
7349
7350 For example:
7351
7352 @smallexample
7353 @group
7354 $ @kbd{tar tf arch.tar --quoting-style=locale}
7355 `./'
7356 `./a space'
7357 `./a\'single\'quote'
7358 `./a"double"quote'
7359 `./a\\backslash'
7360 `./a\ttab'
7361 `./a\nnewline'
7362 @end group
7363 @end smallexample
7364
7365 @item clocale
7366 Same as @samp{locale}, but @samp{"} is used for both left and right
7367 quotation marks, if not provided by the currently selected locale:
7368
7369 @smallexample
7370 @group
7371 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7372 "./"
7373 "./a space"
7374 "./a'single'quote"
7375 "./a\"double\"quote"
7376 "./a\\backslash"
7377 "./a\ttab"
7378 "./a\nnewline"
7379 @end group
7380 @end smallexample
7381 @end table
7382
7383 You can specify which characters should be quoted in addition to those
7384 implied by the current quoting style:
7385
7386 @table @option
7387 @item --quote-chars=@var{string}
7388 Always quote characters from @var{string}, even if the selected
7389 quoting style would not quote them.
7390 @end table
7391
7392 For example, using @samp{escape} quoting (compare with the usual
7393 escape listing above):
7394
7395 @smallexample
7396 @group
7397 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7398 ./
7399 ./a\ space
7400 ./a'single'quote
7401 ./a\"double\"quote
7402 ./a\\backslash
7403 ./a\ttab
7404 ./a\nnewline
7405 @end group
7406 @end smallexample
7407
7408 To disable quoting of such additional characters, use the following
7409 option:
7410
7411 @table @option
7412 @item --no-quote-chars=@var{string}
7413 Remove characters listed in @var{string} from the list of quoted
7414 characters set by the previous @option{--quote-chars} option.
7415 @end table
7416
7417 This option is particularly useful if you have added
7418 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7419 and wish to disable it for the current invocation.
7420
7421 Note, that @option{--no-quote-chars} does @emph{not} disable those
7422 characters that are quoted by default in the selected quoting style.
7423
7424 @node transform
7425 @section Modifying File and Member Names
7426
7427 @command{Tar} archives contain detailed information about files stored
7428 in them and full file names are part of that information. When
7429 storing file to an archive, its file name is recorded in the archive
7430 along with the actual file contents. When restoring from an archive,
7431 a file is created on disk with exactly the same name as that stored
7432 in the archive. In the majority of cases this is the desired behavior
7433 of a file archiver. However, there are some cases when it is not.
7434
7435 First of all, it is often unsafe to extract archive members with
7436 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7437 takes special precautions when extracting such names and provides a
7438 special option for handling them, which is described in
7439 @ref{absolute}.
7440
7441 Secondly, you may wish to extract file names without some leading
7442 directory components, or with otherwise modified names. In other
7443 cases it is desirable to store files under differing names in the
7444 archive.
7445
7446 @GNUTAR{} provides two options for these needs.
7447
7448 @table @option
7449 @opindex strip-components
7450 @item --strip-components=@var{number}
7451 Strip given @var{number} of leading components from file names before
7452 extraction.
7453 @end table
7454
7455 For example, suppose you have archived whole @file{/usr} hierarchy to
7456 a tar archive named @file{usr.tar}. Among other files, this archive
7457 contains @file{usr/include/stdlib.h}, which you wish to extract to
7458 the current working directory. To do so, you type:
7459
7460 @smallexample
7461 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7462 @end smallexample
7463
7464 The option @option{--strip=2} instructs @command{tar} to strip the
7465 two leading components (@file{usr/} and @file{include/}) off the file
7466 name.
7467
7468 If you add to the above invocation @option{--verbose} (@option{-v})
7469 option, you will note that the verbose listing still contains the
7470 full file name, with the two removed components still in place. This
7471 can be inconvenient, so @command{tar} provides a special option for
7472 altering this behavior:
7473
7474 @anchor{show-transformed-names}
7475 @table @option
7476 @opindex show-transformed-names
7477 @item --show-transformed-names
7478 Display file or member names with all requested transformations
7479 applied.
7480 @end table
7481
7482 @noindent
7483 For example:
7484
7485 @smallexample
7486 @group
7487 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7488 usr/include/stdlib.h
7489 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7490 stdlib.h
7491 @end group
7492 @end smallexample
7493
7494 Notice that in both cases the file is @file{stdlib.h} extracted to the
7495 current working directory, @option{--show-transformed-names} affects
7496 only the way its name is displayed.
7497
7498 This option is especially useful for verifying whether the invocation
7499 will have the desired effect. Thus, before running
7500
7501 @smallexample
7502 $ @kbd{tar -x --strip=@var{n}}
7503 @end smallexample
7504
7505 @noindent
7506 it is often advisable to run
7507
7508 @smallexample
7509 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7510 @end smallexample
7511
7512 @noindent
7513 to make sure the command will produce the intended results.
7514
7515 In case you need to apply more complex modifications to the file name,
7516 @GNUTAR{} provides a general-purpose transformation option:
7517
7518 @table @option
7519 @opindex transform
7520 @item --transform=@var{expression}
7521 Modify file names using supplied @var{expression}.
7522 @end table
7523
7524 @noindent
7525 The @var{expression} is a @command{sed}-like replace expression of the
7526 form:
7527
7528 @smallexample
7529 s/@var{regexp}/@var{replace}/[@var{flags}]
7530 @end smallexample
7531
7532 @noindent
7533 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7534 replacement for each file name part that matches @var{regexp}. Both
7535 @var{regexp} and @var{replace} are described in detail in
7536 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7537
7538 Supported @var{flags} are:
7539
7540 @table @samp
7541 @item g
7542 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7543 just the first.
7544
7545 @item i
7546 Use case-insensitive matching
7547
7548 @item x
7549 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7550 regexps, Extended regular expressions, Extended regular expressions,
7551 sed, GNU sed}).
7552
7553 @item @var{number}
7554 Only replace the @var{number}th match of the @var{regexp}.
7555
7556 Note: the @var{posix} standard does not specify what should happen
7557 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7558 follows the GNU @command{sed} implementation in this regard, so
7559 the interaction is defined to be: ignore matches before the
7560 @var{number}th, and then match and replace all matches from the
7561 @var{number}th on.
7562
7563 @end table
7564
7565 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7566 that it be used consistently throughout the expression. For example,
7567 the following two expressions are equivalent:
7568
7569 @smallexample
7570 @group
7571 s/one/two/
7572 s,one,two,
7573 @end group
7574 @end smallexample
7575
7576 Changing delimiters is often useful when the @var{regex} contains
7577 slashes. For example, it is more convenient to write @code{s,/,-,} than
7578 @code{s/\//-/}.
7579
7580 Here are several examples of @option{--transform} usage:
7581
7582 @enumerate
7583 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7584
7585 @smallexample
7586 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7587 @end smallexample
7588
7589 @item Strip two leading directory components (equivalent to
7590 @option{--strip-components=2}):
7591
7592 @smallexample
7593 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7594 @end smallexample
7595
7596 @item Prepend @file{/prefix/} to each file name:
7597
7598 @smallexample
7599 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7600 @end smallexample
7601
7602 @item Convert each file name to lower case:
7603
7604 @smallexample
7605 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7606 @end smallexample
7607
7608 @end enumerate
7609
7610 Unlike @option{--strip-components}, @option{--transform} can be used
7611 in any @GNUTAR{} operation mode. For example, the following command
7612 adds files to the archive while replacing the leading @file{usr/}
7613 component with @file{var/}:
7614
7615 @smallexample
7616 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7617 @end smallexample
7618
7619 To test @option{--transform} effect we suggest using
7620 @option{--show-transformed-names} option:
7621
7622 @smallexample
7623 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7624 --verbose --show-transformed-names /}
7625 @end smallexample
7626
7627 If both @option{--strip-components} and @option{--transform} are used
7628 together, then @option{--transform} is applied first, and the required
7629 number of components is then stripped from its result.
7630
7631 @node after
7632 @section Operating Only on New Files
7633 @UNREVISED
7634
7635 @cindex Excluding file by age
7636 @cindex Data Modification time, excluding files by
7637 @cindex Modification time, excluding files by
7638 @cindex Age, excluding files by
7639 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7640 @option{-N @var{date}}) option causes @command{tar} to only work on
7641 files whose data modification or status change times are newer than
7642 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7643 it is taken to be a file name; the data modification time of that file
7644 is used as the date. If you use this option when creating or appending
7645 to an archive, the archive will only include new files. If you use
7646 @option{--after-date} when extracting an archive, @command{tar} will
7647 only extract files newer than the @var{date} you specify.
7648
7649 If you only want @command{tar} to make the date comparison based on
7650 modification of the file's data (rather than status
7651 changes), then use the @option{--newer-mtime=@var{date}} option.
7652
7653 You may use these options with any operation. Note that these options
7654 differ from the @option{--update} (@option{-u}) operation in that they
7655 allow you to specify a particular date against which @command{tar} can
7656 compare when deciding whether or not to archive the files.
7657
7658 @table @option
7659 @opindex after-date
7660 @opindex newer
7661 @item --after-date=@var{date}
7662 @itemx --newer=@var{date}
7663 @itemx -N @var{date}
7664 Only store files newer than @var{date}.
7665
7666 Acts on files only if their data modification or status change times are
7667 later than @var{date}. Use in conjunction with any operation.
7668
7669 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7670 name; the data modification time of that file is used as the date.
7671
7672 @opindex newer-mtime
7673 @item --newer-mtime=@var{date}
7674 Acts like @option{--after-date}, but only looks at data modification times.
7675 @end table
7676
7677 These options limit @command{tar} to operate only on files which have
7678 been modified after the date specified. A file's status is considered to have
7679 changed if its contents have been modified, or if its owner,
7680 permissions, and so forth, have been changed. (For more information on
7681 how to specify a date, see @ref{Date input formats}; remember that the
7682 entire date argument must be quoted if it contains any spaces.)
7683
7684 Gurus would say that @option{--after-date} tests both the data
7685 modification time (@code{mtime}, the time the contents of the file
7686 were last modified) and the status change time (@code{ctime}, the time
7687 the file's status was last changed: owner, permissions, etc.@:)
7688 fields, while @option{--newer-mtime} tests only the @code{mtime}
7689 field.
7690
7691 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7692 @code{ctime} and processes the file if either one is more recent than
7693 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7694 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7695 contents of the file were looked at).
7696
7697 Date specifiers can have embedded spaces. Because of this, you may need
7698 to quote date arguments to keep the shell from parsing them as separate
7699 arguments. For example, the following command will add to the archive
7700 all the files modified less than two days ago:
7701
7702 @smallexample
7703 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7704 @end smallexample
7705
7706 When any of these options is used with the option @option{--verbose}
7707 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7708 date back to its textual representation and compare that with the
7709 one given with the option. If the two dates differ, @command{tar} will
7710 print a warning saying what date it will use. This is to help user
7711 ensure he is using the right date. For example:
7712
7713 @smallexample
7714 @group
7715 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7716 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7717 13:19:37.232434
7718 @end group
7719 @end smallexample
7720
7721 @quotation
7722 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7723 should not be used for incremental backups. @xref{Incremental Dumps},
7724 for proper way of creating incremental backups.
7725 @end quotation
7726
7727 @node recurse
7728 @section Descending into Directories
7729 @UNREVISED
7730 @cindex Avoiding recursion in directories
7731 @cindex Descending directories, avoiding
7732 @cindex Directories, avoiding recursion
7733 @cindex Recursion in directories, avoiding
7734
7735 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7736
7737 Usually, @command{tar} will recursively explore all directories (either
7738 those given on the command line or through the @option{--files-from}
7739 option) for the various files they contain. However, you may not always
7740 want @command{tar} to act this way.
7741
7742 @opindex no-recursion
7743 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7744 into specified directories. If you specify @option{--no-recursion}, you can
7745 use the @command{find} utility for hunting through levels of directories to
7746 construct a list of file names which you could then pass to @command{tar}.
7747 @command{find} allows you to be more selective when choosing which files to
7748 archive; see @ref{files}, for more information on using @command{find} with
7749 @command{tar}, or look.
7750
7751 @table @option
7752 @item --no-recursion
7753 Prevents @command{tar} from recursively descending directories.
7754
7755 @opindex recursion
7756 @item --recursion
7757 Requires @command{tar} to recursively descend directories.
7758 This is the default.
7759 @end table
7760
7761 When you use @option{--no-recursion}, @GNUTAR{} grabs
7762 directory entries themselves, but does not descend on them
7763 recursively. Many people use @command{find} for locating files they
7764 want to back up, and since @command{tar} @emph{usually} recursively
7765 descends on directories, they have to use the @samp{@w{-not -type d}}
7766 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7767 find, Finding Files}), as they usually do not want all the files in a
7768 directory. They then use the @option{--files-from} option to archive
7769 the files located via @command{find}.
7770
7771 The problem when restoring files archived in this manner is that the
7772 directories themselves are not in the archive; so the
7773 @option{--same-permissions} (@option{--preserve-permissions},
7774 @option{-p}) option does not affect them---while users might really
7775 like it to. Specifying @option{--no-recursion} is a way to tell
7776 @command{tar} to grab only the directory entries given to it, adding
7777 no new files on its own. To summarize, if you use @command{find} to
7778 create a list of files to be stored in an archive, use it as follows:
7779
7780 @smallexample
7781 @group
7782 $ @kbd{find @var{dir} @var{tests} | \
7783 tar -cf @var{archive} -T - --no-recursion}
7784 @end group
7785 @end smallexample
7786
7787 The @option{--no-recursion} option also applies when extracting: it
7788 causes @command{tar} to extract only the matched directory entries, not
7789 the files under those directories.
7790
7791 The @option{--no-recursion} option also affects how globbing patterns
7792 are interpreted (@pxref{controlling pattern-matching}).
7793
7794 The @option{--no-recursion} and @option{--recursion} options apply to
7795 later options and operands, and can be overridden by later occurrences
7796 of @option{--no-recursion} and @option{--recursion}. For example:
7797
7798 @smallexample
7799 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7800 @end smallexample
7801
7802 @noindent
7803 creates an archive with one entry for @file{grape}, and the recursive
7804 contents of @file{grape/concord}, but no entries under @file{grape}
7805 other than @file{grape/concord}.
7806
7807 @node one
7808 @section Crossing File System Boundaries
7809 @cindex File system boundaries, not crossing
7810 @UNREVISED
7811
7812 @command{tar} will normally automatically cross file system boundaries in
7813 order to archive files which are part of a directory tree. You can
7814 change this behavior by running @command{tar} and specifying
7815 @option{--one-file-system}. This option only affects files that are
7816 archived because they are in a directory that is being archived;
7817 @command{tar} will still archive files explicitly named on the command line
7818 or through @option{--files-from}, regardless of where they reside.
7819
7820 @table @option
7821 @opindex one-file-system
7822 @item --one-file-system
7823 Prevents @command{tar} from crossing file system boundaries when
7824 archiving. Use in conjunction with any write operation.
7825 @end table
7826
7827 The @option{--one-file-system} option causes @command{tar} to modify its
7828 normal behavior in archiving the contents of directories. If a file in
7829 a directory is not on the same file system as the directory itself, then
7830 @command{tar} will not archive that file. If the file is a directory
7831 itself, @command{tar} will not archive anything beneath it; in other words,
7832 @command{tar} will not cross mount points.
7833
7834 This option is useful for making full or incremental archival backups of
7835 a file system. If this option is used in conjunction with
7836 @option{--verbose} (@option{-v}), files that are excluded are
7837 mentioned by name on the standard error.
7838
7839 @menu
7840 * directory:: Changing Directory
7841 * absolute:: Absolute File Names
7842 @end menu
7843
7844 @node directory
7845 @subsection Changing the Working Directory
7846
7847 @FIXME{need to read over this node now for continuity; i've switched
7848 things around some.}
7849
7850 @cindex Changing directory mid-stream
7851 @cindex Directory, changing mid-stream
7852 @cindex Working directory, specifying
7853 To change the working directory in the middle of a list of file names,
7854 either on the command line or in a file specified using
7855 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7856 This will change the working directory to the specified directory
7857 after that point in the list.
7858
7859 @table @option
7860 @opindex directory
7861 @item --directory=@var{directory}
7862 @itemx -C @var{directory}
7863 Changes the working directory in the middle of a command line.
7864 @end table
7865
7866 For example,
7867
7868 @smallexample
7869 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7870 @end smallexample
7871
7872 @noindent
7873 will place the files @file{grape} and @file{prune} from the current
7874 directory into the archive @file{jams.tar}, followed by the file
7875 @file{cherry} from the directory @file{food}. This option is especially
7876 useful when you have several widely separated files that you want to
7877 store in the same archive.
7878
7879 Note that the file @file{cherry} is recorded in the archive under the
7880 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7881 archive will contain three files that all appear to have come from the
7882 same directory; if the archive is extracted with plain @samp{tar
7883 --extract}, all three files will be written in the current directory.
7884
7885 Contrast this with the command,
7886
7887 @smallexample
7888 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7889 @end smallexample
7890
7891 @noindent
7892 which records the third file in the archive under the name
7893 @file{red/cherry} so that, if the archive is extracted using
7894 @samp{tar --extract}, the third file will be written in a subdirectory
7895 named @file{orange-colored}.
7896
7897 You can use the @option{--directory} option to make the archive
7898 independent of the original name of the directory holding the files.
7899 The following command places the files @file{/etc/passwd},
7900 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7901 @file{foo.tar}:
7902
7903 @smallexample
7904 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7905 @end smallexample
7906
7907 @noindent
7908 However, the names of the archive members will be exactly what they were
7909 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7910 They will not appear to be related by file name to the original
7911 directories where those files were located.
7912
7913 Note that @option{--directory} options are interpreted consecutively. If
7914 @option{--directory} specifies a relative file name, it is interpreted
7915 relative to the then current directory, which might not be the same as
7916 the original current working directory of @command{tar}, due to a previous
7917 @option{--directory} option.
7918
7919 When using @option{--files-from} (@pxref{files}), you can put various
7920 @command{tar} options (including @option{-C}) in the file list. Notice,
7921 however, that in this case the option and its argument may not be
7922 separated by whitespace. If you use short option, its argument must
7923 either follow the option letter immediately, without any intervening
7924 whitespace, or occupy the next line. Otherwise, if you use long
7925 option, separate its argument by an equal sign.
7926
7927 For instance, the file list for the above example will be:
7928
7929 @smallexample
7930 @group
7931 -C/etc
7932 passwd
7933 hosts
7934 --directory=/lib
7935 libc.a
7936 @end group
7937 @end smallexample
7938
7939 @noindent
7940 To use it, you would invoke @command{tar} as follows:
7941
7942 @smallexample
7943 $ @kbd{tar -c -f foo.tar --files-from list}
7944 @end smallexample
7945
7946 The interpretation of @option{--directory} is disabled by
7947 @option{--null} option.
7948
7949 @node absolute
7950 @subsection Absolute File Names
7951 @UNREVISED
7952
7953 @table @option
7954 @opindex absolute-names
7955 @item --absolute-names
7956 @itemx -P
7957 Do not strip leading slashes from file names, and permit file names
7958 containing a @file{..} file name component.
7959 @end table
7960
7961 By default, @GNUTAR{} drops a leading @samp{/} on
7962 input or output, and complains about file names containing a @file{..}
7963 component. This option turns off this behavior.
7964
7965 When @command{tar} extracts archive members from an archive, it strips any
7966 leading slashes (@samp{/}) from the member name. This causes absolute
7967 member names in the archive to be treated as relative file names. This
7968 allows you to have such members extracted wherever you want, instead of
7969 being restricted to extracting the member in the exact directory named
7970 in the archive. For example, if the archive member has the name
7971 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7972 really @file{etc/passwd}.
7973
7974 File names containing @file{..} can cause problems when extracting, so
7975 @command{tar} normally warns you about such files when creating an
7976 archive, and rejects attempts to extracts such files.
7977
7978 Other @command{tar} programs do not do this. As a result, if you
7979 create an archive whose member names start with a slash, they will be
7980 difficult for other people with a non-@GNUTAR{}
7981 program to use. Therefore, @GNUTAR{} also strips
7982 leading slashes from member names when putting members into the
7983 archive. For example, if you ask @command{tar} to add the file
7984 @file{/bin/ls} to an archive, it will do so, but the member name will
7985 be @file{bin/ls}.@footnote{A side effect of this is that when
7986 @option{--create} is used with @option{--verbose} the resulting output
7987 is not, generally speaking, the same as the one you'd get running
7988 @kbd{tar --list} command. This may be important if you use some
7989 scripts for comparing both outputs. @xref{listing member and file names},
7990 for the information on how to handle this case.}
7991
7992 If you use the @option{--absolute-names} (@option{-P}) option,
7993 @command{tar} will do none of these transformations.
7994
7995 To archive or extract files relative to the root directory, specify
7996 the @option{--absolute-names} (@option{-P}) option.
7997
7998 Normally, @command{tar} acts on files relative to the working
7999 directory---ignoring superior directory names when archiving, and
8000 ignoring leading slashes when extracting.
8001
8002 When you specify @option{--absolute-names} (@option{-P}),
8003 @command{tar} stores file names including all superior directory
8004 names, and preserves leading slashes. If you only invoked
8005 @command{tar} from the root directory you would never need the
8006 @option{--absolute-names} option, but using this option
8007 may be more convenient than switching to root.
8008
8009 @FIXME{Should be an example in the tutorial/wizardry section using this
8010 to transfer files between systems.}
8011
8012 @FIXME{Is write access an issue?}
8013
8014 @table @option
8015 @item --absolute-names
8016 Preserves full file names (including superior directory names) when
8017 archiving files. Preserves leading slash when extracting files.
8018
8019 @end table
8020
8021 @FIXME{this is still horrible; need to talk with dan on monday.}
8022
8023 @command{tar} prints out a message about removing the @samp{/} from
8024 file names. This message appears once per @GNUTAR{}
8025 invocation. It represents something which ought to be told; ignoring
8026 what it means can cause very serious surprises, later.
8027
8028 Some people, nevertheless, do not want to see this message. Wanting to
8029 play really dangerously, one may of course redirect @command{tar} standard
8030 error to the sink. For example, under @command{sh}:
8031
8032 @smallexample
8033 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8034 @end smallexample
8035
8036 @noindent
8037 Another solution, both nicer and simpler, would be to change to
8038 the @file{/} directory first, and then avoid absolute notation.
8039 For example:
8040
8041 @smallexample
8042 $ @kbd{(cd / && tar -c -f archive.tar home)}
8043 # @i{or}:
8044 $ @kbd{tar -c -f archive.tar -C / home}
8045 @end smallexample
8046
8047 @include getdate.texi
8048
8049 @node Formats
8050 @chapter Controlling the Archive Format
8051
8052 @cindex Tar archive formats
8053 Due to historical reasons, there are several formats of tar archives.
8054 All of them are based on the same principles, but have some subtle
8055 differences that often make them incompatible with each other.
8056
8057 GNU tar is able to create and handle archives in a variety of formats.
8058 The most frequently used formats are (in alphabetical order):
8059
8060 @table @asis
8061 @item gnu
8062 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8063 from an early @acronym{POSIX} standard, adding some improvements such as
8064 sparse file handling and incremental archives. Unfortunately these
8065 features were implemented in a way incompatible with other archive
8066 formats.
8067
8068 Archives in @samp{gnu} format are able to hold file names of unlimited
8069 length.
8070
8071 @item oldgnu
8072 Format used by @GNUTAR{} of versions prior to 1.12.
8073
8074 @item v7
8075 Archive format, compatible with the V7 implementation of tar. This
8076 format imposes a number of limitations. The most important of them
8077 are:
8078
8079 @enumerate
8080 @item The maximum length of a file name is limited to 99 characters.
8081 @item The maximum length of a symbolic link is limited to 99 characters.
8082 @item It is impossible to store special files (block and character
8083 devices, fifos etc.)
8084 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8085 octal)
8086 @item V7 archives do not contain symbolic ownership information (user
8087 and group name of the file owner).
8088 @end enumerate
8089
8090 This format has traditionally been used by Automake when producing
8091 Makefiles. This practice will change in the future, in the meantime,
8092 however this means that projects containing file names more than 99
8093 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8094 Automake prior to 1.9.
8095
8096 @item ustar
8097 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8098 symbolic ownership information. It is also able to store
8099 special files. However, it imposes several restrictions as well:
8100
8101 @enumerate
8102 @item The maximum length of a file name is limited to 256 characters,
8103 provided that the file name can be split at a directory separator in
8104 two parts, first of them being at most 155 bytes long. So, in most
8105 cases the maximum file name length will be shorter than 256
8106 characters.
8107 @item The maximum length of a symbolic link name is limited to
8108 100 characters.
8109 @item Maximum size of a file the archive is able to accommodate
8110 is 8GB
8111 @item Maximum value of UID/GID is 2097151.
8112 @item Maximum number of bits in device major and minor numbers is 21.
8113 @end enumerate
8114
8115 @item star
8116 Format used by J@"org Schilling @command{star}
8117 implementation. @GNUTAR{} is able to read @samp{star} archives but
8118 currently does not produce them.
8119
8120 @item posix
8121 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8122 most flexible and feature-rich format. It does not impose any
8123 restrictions on file sizes or file name lengths. This format is quite
8124 recent, so not all tar implementations are able to handle it properly.
8125 However, this format is designed in such a way that any tar
8126 implementation able to read @samp{ustar} archives will be able to read
8127 most @samp{posix} archives as well, with the only exception that any
8128 additional information (such as long file names etc.) will in such
8129 case be extracted as plain text files along with the files it refers to.
8130
8131 This archive format will be the default format for future versions
8132 of @GNUTAR{}.
8133
8134 @end table
8135
8136 The following table summarizes the limitations of each of these
8137 formats:
8138
8139 @multitable @columnfractions .10 .20 .20 .20 .20
8140 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8141 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8142 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8143 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8144 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8145 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8146 @end multitable
8147
8148 The default format for @GNUTAR{} is defined at compilation
8149 time. You may check it by running @command{tar --help}, and examining
8150 the last lines of its output. Usually, @GNUTAR{} is configured
8151 to create archives in @samp{gnu} format, however, future version will
8152 switch to @samp{posix}.
8153
8154 @menu
8155 * Compression:: Using Less Space through Compression
8156 * Attributes:: Handling File Attributes
8157 * Portability:: Making @command{tar} Archives More Portable
8158 * cpio:: Comparison of @command{tar} and @command{cpio}
8159 @end menu
8160
8161 @node Compression
8162 @section Using Less Space through Compression
8163
8164 @menu
8165 * gzip:: Creating and Reading Compressed Archives
8166 * sparse:: Archiving Sparse Files
8167 @end menu
8168
8169 @node gzip
8170 @subsection Creating and Reading Compressed Archives
8171 @cindex Compressed archives
8172 @cindex Storing archives in compressed format
8173
8174 @GNUTAR{} is able to create and read compressed archives. It supports
8175 @command{gzip}, @command{bzip2} and @command{lzma} compression
8176 programs. For backward compatibility, it also supports
8177 @command{compress} command, although we strongly recommend against
8178 using it, because it is by far less effective than other compression
8179 programs@footnote{It also had patent problems in the past.}.
8180
8181 Creating a compressed archive is simple: you just specify a
8182 @dfn{compression option} along with the usual archive creation
8183 commands. The compression option is @option{-z} (@option{--gzip}) to
8184 create a @command{gzip} compressed archive, @option{-j}
8185 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8186 @command{lzma} to create an @asis{LZMA} compressed archive and
8187 @option{-Z} (@option{--compress}) to use @command{compress} program.
8188 For example:
8189
8190 @smallexample
8191 $ @kbd{tar cfz archive.tar.gz .}
8192 @end smallexample
8193
8194 You can also let @GNUTAR{} select the compression program basing on
8195 the suffix of the archive file name. This is done using
8196 @option{--auto-compress} (@option{-a}) command line option. For
8197 example, the following invocation will use @command{bzip2} for
8198 compression:
8199
8200 @smallexample
8201 $ @kbd{tar cfa archive.tar.bz2 .}
8202 @end smallexample
8203
8204 @noindent
8205 whereas the following one will use @command{lzma}:
8206
8207 @smallexample
8208 $ @kbd{tar cfa archive.tar.lzma .}
8209 @end smallexample
8210
8211 For a complete list of file name suffixes recognized by @GNUTAR{},
8212 @ref{auto-compress}.
8213
8214 Reading compressed archive is even simpler: you don't need to specify
8215 any additional options as @GNUTAR{} recognizes its format
8216 automatically. Thus, the following commands will list and extract the
8217 archive created in previous example:
8218
8219 @smallexample
8220 # List the compressed archive
8221 $ @kbd{tar tf archive.tar.gz}
8222 # Extract the compressed archive
8223 $ @kbd{tar xf archive.tar.gz}
8224 @end smallexample
8225
8226 The only case when you have to specify a decompression option while
8227 reading the archive is when reading from a pipe or from a tape drive
8228 that does not support random access. However, in this case @GNUTAR{}
8229 will indicate which option you should use. For example:
8230
8231 @smallexample
8232 $ @kbd{cat archive.tar.gz | tar tf -}
8233 tar: Archive is compressed. Use -z option
8234 tar: Error is not recoverable: exiting now
8235 @end smallexample
8236
8237 If you see such diagnostics, just add the suggested option to the
8238 invocation of @GNUTAR{}:
8239
8240 @smallexample
8241 $ @kbd{cat archive.tar.gz | tar tfz -}
8242 @end smallexample
8243
8244 Notice also, that there are several restrictions on operations on
8245 compressed archives. First of all, compressed archives cannot be
8246 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8247 (@option{--delete}) members from them. Likewise, you cannot append
8248 another @command{tar} archive to a compressed archive using
8249 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8250 compressed.
8251
8252 The following table summarizes compression options used by @GNUTAR{}.
8253
8254 @table @option
8255 @anchor{auto-compress}
8256 @opindex auto-compress
8257 @item --auto-compress
8258 @itemx -a
8259 Select a compression program to use by the archive file name
8260 suffix. The following suffixes are recognized:
8261
8262 @multitable @columnfractions 0.3 0.6
8263 @headitem Suffix @tab Compression program
8264 @item @samp{.gz} @tab @command{gzip}
8265 @item @samp{.tgz} @tab @command{gzip}
8266 @item @samp{.taz} @tab @command{gzip}
8267 @item @samp{.Z} @tab @command{compress}
8268 @item @samp{.taZ} @tab @command{compress}
8269 @item @samp{.bz2} @tab @command{bzip2}
8270 @item @samp{.tz2} @tab @command{bzip2}
8271 @item @samp{.tbz2} @tab @command{bzip2}
8272 @item @samp{.tbz} @tab @command{bzip2}
8273 @item @samp{.lzma} @tab @command{lzma}
8274 @item @samp{.tlz} @tab @command{lzma}
8275 @end multitable
8276
8277 @opindex gzip
8278 @opindex ungzip
8279 @item -z
8280 @itemx --gzip
8281 @itemx --ungzip
8282 Filter the archive through @command{gzip}.
8283
8284 You can use @option{--gzip} and @option{--gunzip} on physical devices
8285 (tape drives, etc.) and remote files as well as on normal files; data
8286 to or from such devices or remote files is reblocked by another copy
8287 of the @command{tar} program to enforce the specified (or default) record
8288 size. The default compression parameters are used; if you need to
8289 override them, set @env{GZIP} environment variable, e.g.:
8290
8291 @smallexample
8292 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8293 @end smallexample
8294
8295 @noindent
8296 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8297 @command{gzip} explicitly:
8298
8299 @smallexample
8300 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8301 @end smallexample
8302
8303 @cindex corrupted archives
8304 About corrupted compressed archives: @command{gzip}'ed files have no
8305 redundancy, for maximum compression. The adaptive nature of the
8306 compression scheme means that the compression tables are implicitly
8307 spread all over the archive. If you lose a few blocks, the dynamic
8308 construction of the compression tables becomes unsynchronized, and there
8309 is little chance that you could recover later in the archive.
8310
8311 There are pending suggestions for having a per-volume or per-file
8312 compression in @GNUTAR{}. This would allow for viewing the
8313 contents without decompression, and for resynchronizing decompression at
8314 every volume or file, in case of corrupted archives. Doing so, we might
8315 lose some compressibility. But this would have make recovering easier.
8316 So, there are pros and cons. We'll see!
8317
8318 @opindex bzip2
8319 @item -j
8320 @itemx --bzip2
8321 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8322
8323 @opindex lzma
8324 @item --lzma
8325 Filter the archive through @command{lzma}. Otherwise like @option{--gzip}.
8326
8327 @opindex compress
8328 @opindex uncompress
8329 @item -Z
8330 @itemx --compress
8331 @itemx --uncompress
8332 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8333
8334 @opindex use-compress-program
8335 @item --use-compress-program=@var{prog}
8336 Use external compression program @var{prog}. Use this option if you
8337 have a compression program that @GNUTAR{} does not support. There
8338 are two requirements to which @var{prog} should comply:
8339
8340 First, when called without options, it should read data from standard
8341 input, compress it and output it on standard output.
8342
8343 Secondly, if called with @option{-d} argument, it should do exactly
8344 the opposite, i.e., read the compressed data from the standard input
8345 and produce uncompressed data on the standard output.
8346 @end table
8347
8348 @cindex gpg, using with tar
8349 @cindex gnupg, using with tar
8350 @cindex Using encrypted archives
8351 The @option{--use-compress-program} option, in particular, lets you
8352 implement your own filters, not necessarily dealing with
8353 compression/decompression. For example, suppose you wish to implement
8354 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8355 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8356 Manual}). The following script does that:
8357
8358 @smallexample
8359 @group
8360 #! /bin/sh
8361 case $1 in
8362 -d) gpg --decrypt - | gzip -d -c;;
8363 '') gzip -c | gpg -s ;;
8364 *) echo "Unknown option $1">&2; exit 1;;
8365 esac
8366 @end group
8367 @end smallexample
8368
8369 Suppose you name it @file{gpgz} and save it somewhere in your
8370 @env{PATH}. Then the following command will create a compressed
8371 archive signed with your private key:
8372
8373 @smallexample
8374 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8375 @end smallexample
8376
8377 @noindent
8378 Likewise, the following command will list its contents:
8379
8380 @smallexample
8381 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8382 @end smallexample
8383
8384 @ignore
8385 The above is based on the following discussion:
8386
8387 I have one question, or maybe it's a suggestion if there isn't a way
8388 to do it now. I would like to use @option{--gzip}, but I'd also like
8389 the output to be fed through a program like @acronym{GNU}
8390 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8391 to use :-)), basically adding ECC protection on top of compression.
8392 It seems as if this should be quite easy to do, but I can't work out
8393 exactly how to go about it. Of course, I can pipe the standard output
8394 of @command{tar} through @command{ecc}, but then I lose (though I
8395 haven't started using it yet, I confess) the ability to have
8396 @command{tar} use @command{rmt} for it's I/O (I think).
8397
8398 I think the most straightforward thing would be to let me specify a
8399 general set of filters outboard of compression (preferably ordered,
8400 so the order can be automatically reversed on input operations, and
8401 with the options they require specifiable), but beggars shouldn't be
8402 choosers and anything you decide on would be fine with me.
8403
8404 By the way, I like @command{ecc} but if (as the comments say) it can't
8405 deal with loss of block sync, I'm tempted to throw some time at adding
8406 that capability. Supposing I were to actually do such a thing and
8407 get it (apparently) working, do you accept contributed changes to
8408 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8409
8410 Isn't that exactly the role of the
8411 @option{--use-compress-prog=@var{program}} option?
8412 I never tried it myself, but I suspect you may want to write a
8413 @var{prog} script or program able to filter stdin to stdout to
8414 way you want. It should recognize the @option{-d} option, for when
8415 extraction is needed rather than creation.
8416
8417 It has been reported that if one writes compressed data (through the
8418 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8419 the DLT compression mode, the data will actually get bigger and one will
8420 end up with less space on the tape.
8421 @end ignore
8422
8423 @node sparse
8424 @subsection Archiving Sparse Files
8425 @cindex Sparse Files
8426
8427 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
8428 in a file is a section of the file's contents which was never written.
8429 The contents of a hole reads as all zeros. On many operating systems,
8430 actual disk storage is not allocated for holes, but they are counted
8431 in the length of the file. If you archive such a file, @command{tar}
8432 could create an archive longer than the original. To have @command{tar}
8433 attempt to recognize the holes in a file, use @option{--sparse}
8434 (@option{-S}). When you use this option, then, for any file using
8435 less disk space than would be expected from its length, @command{tar}
8436 searches the file for consecutive stretches of zeros. It then records
8437 in the archive for the file where the consecutive stretches of zeros
8438 are, and only archives the ``real contents'' of the file. On
8439 extraction (using @option{--sparse} is not needed on extraction) any
8440 such files have holes created wherever the continuous stretches of zeros
8441 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8442 won't take more space than the original.
8443
8444 @table @option
8445 @opindex sparse
8446 @item -S
8447 @itemx --sparse
8448 This option instructs @command{tar} to test each file for sparseness
8449 before attempting to archive it. If the file is found to be sparse it
8450 is treated specially, thus allowing to decrease the amount of space
8451 used by its image in the archive.
8452
8453 This option is meaningful only when creating or updating archives. It
8454 has no effect on extraction.
8455 @end table
8456
8457 Consider using @option{--sparse} when performing file system backups,
8458 to avoid archiving the expanded forms of files stored sparsely in the
8459 system.
8460
8461 Even if your system has no sparse files currently, some may be
8462 created in the future. If you use @option{--sparse} while making file
8463 system backups as a matter of course, you can be assured the archive
8464 will never take more space on the media than the files take on disk
8465 (otherwise, archiving a disk filled with sparse files might take
8466 hundreds of tapes). @xref{Incremental Dumps}.
8467
8468 However, be aware that @option{--sparse} option presents a serious
8469 drawback. Namely, in order to determine if the file is sparse
8470 @command{tar} has to read it before trying to archive it, so in total
8471 the file is read @strong{twice}. So, always bear in mind that the
8472 time needed to process all files with this option is roughly twice
8473 the time needed to archive them without it.
8474 @FIXME{A technical note:
8475
8476 Programs like @command{dump} do not have to read the entire file; by
8477 examining the file system directly, they can determine in advance
8478 exactly where the holes are and thus avoid reading through them. The
8479 only data it need read are the actual allocated data blocks.
8480 @GNUTAR{} uses a more portable and straightforward
8481 archiving approach, it would be fairly difficult that it does
8482 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8483 1990-12-10:
8484
8485 @quotation
8486 What I did say is that you cannot tell the difference between a hole and an
8487 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8488 best tells you how many holes there are; it doesn't tell you @emph{where}.
8489 Just as programs may, conceivably, care what @code{st_blocks} is (care
8490 to name one that does?), they may also care where the holes are (I have
8491 no examples of this one either, but it's equally imaginable).
8492
8493 I conclude from this that good archivers are not portable. One can
8494 arguably conclude that if you want a portable program, you can in good
8495 conscience restore files with as many holes as possible, since you can't
8496 get it right.
8497 @end quotation
8498 }
8499
8500 @cindex sparse formats, defined
8501 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8502 sparse files using in three distinct ways, called @dfn{sparse
8503 formats}. A sparse format is identified by its @dfn{number},
8504 consisting, as usual of two decimal numbers, delimited by a dot. By
8505 default, format @samp{1.0} is used. If, for some reason, you wish to
8506 use an earlier format, you can select it using
8507 @option{--sparse-version} option.
8508
8509 @table @option
8510 @opindex sparse-version
8511 @item --sparse-version=@var{version}
8512
8513 Select the format to store sparse files in. Valid @var{version} values
8514 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8515 for a detailed description of each format.
8516 @end table
8517
8518 Using @option{--sparse-format} option implies @option{--sparse}.
8519
8520 @node Attributes
8521 @section Handling File Attributes
8522 @UNREVISED
8523
8524 When @command{tar} reads files, it updates their access times. To
8525 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8526 reset the access time retroactively or avoid changing it in the first
8527 place.
8528
8529 Handling of file attributes
8530
8531 @table @option
8532 @opindex atime-preserve
8533 @item --atime-preserve
8534 @itemx --atime-preserve=replace
8535 @itemx --atime-preserve=system
8536 Preserve the access times of files that are read. This works only for
8537 files that you own, unless you have superuser privileges.
8538
8539 @option{--atime-preserve=replace} works on most systems, but it also
8540 restores the data modification time and updates the status change
8541 time. Hence it doesn't interact with incremental dumps nicely
8542 (@pxref{Incremental Dumps}), and it can set access or data modification times
8543 incorrectly if other programs access the file while @command{tar} is
8544 running.
8545
8546 @option{--atime-preserve=system} avoids changing the access time in
8547 the first place, if the operating system supports this.
8548 Unfortunately, this may or may not work on any given operating system
8549 or file system. If @command{tar} knows for sure it won't work, it
8550 complains right away.
8551
8552 Currently @option{--atime-preserve} with no operand defaults to
8553 @option{--atime-preserve=replace}, but this is intended to change to
8554 @option{--atime-preserve=system} when the latter is better-supported.
8555
8556 @opindex touch
8557 @item -m
8558 @itemx --touch
8559 Do not extract data modification time.
8560
8561 When this option is used, @command{tar} leaves the data modification times
8562 of the files it extracts as the times when the files were extracted,
8563 instead of setting it to the times recorded in the archive.
8564
8565 This option is meaningless with @option{--list} (@option{-t}).
8566
8567 @opindex same-owner
8568 @item --same-owner
8569 Create extracted files with the same ownership they have in the
8570 archive.
8571
8572 This is the default behavior for the superuser,
8573 so this option is meaningful only for non-root users, when @command{tar}
8574 is executed on those systems able to give files away. This is
8575 considered as a security flaw by many people, at least because it
8576 makes quite difficult to correctly account users for the disk space
8577 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8578 files are easily and silently lost when files are given away.
8579
8580 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
8581 separately. If it can't find a user name (because the user @acronym{ID} is not
8582 in @file{/etc/passwd}), then it does not write one. When restoring,
8583 it tries to look the name (if one was written) up in
8584 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
8585 the archive instead.
8586
8587 @opindex no-same-owner
8588 @item --no-same-owner
8589 @itemx -o
8590 Do not attempt to restore ownership when extracting. This is the
8591 default behavior for ordinary users, so this option has an effect
8592 only for the superuser.
8593
8594 @opindex numeric-owner
8595 @item --numeric-owner
8596 The @option{--numeric-owner} option allows (ANSI) archives to be written
8597 without user/group name information or such information to be ignored
8598 when extracting. It effectively disables the generation and/or use
8599 of user/group name information. This option forces extraction using
8600 the numeric ids from the archive, ignoring the names.
8601
8602 This is useful in certain circumstances, when restoring a backup from
8603 an emergency floppy with different passwd/group files for example.
8604 It is otherwise impossible to extract files with the right ownerships
8605 if the password file in use during the extraction does not match the
8606 one belonging to the file system(s) being extracted. This occurs,
8607 for example, if you are restoring your files after a major crash and
8608 had booted from an emergency floppy with no password file or put your
8609 disk into another machine to do the restore.
8610
8611 The numeric ids are @emph{always} saved into @command{tar} archives.
8612 The identifying names are added at create time when provided by the
8613 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8614 used when moving archives between a collection of machines using
8615 a centralized management for attribution of numeric ids to users
8616 and groups. This is often made through using the NIS capabilities.
8617
8618 When making a @command{tar} file for distribution to other sites, it
8619 is sometimes cleaner to use a single owner for all files in the
8620 distribution, and nicer to specify the write permission bits of the
8621 files as stored in the archive independently of their actual value on
8622 the file system. The way to prepare a clean distribution is usually
8623 to have some Makefile rule creating a directory, copying all needed
8624 files in that directory, then setting ownership and permissions as
8625 wanted (there are a lot of possible schemes), and only then making a
8626 @command{tar} archive out of this directory, before cleaning
8627 everything out. Of course, we could add a lot of options to
8628 @GNUTAR{} for fine tuning permissions and ownership.
8629 This is not the good way, I think. @GNUTAR{} is
8630 already crowded with options and moreover, the approach just explained
8631 gives you a great deal of control already.
8632
8633 @xopindex{same-permissions, short description}
8634 @xopindex{preserve-permissions, short description}
8635 @item -p
8636 @itemx --same-permissions
8637 @itemx --preserve-permissions
8638 Extract all protection information.
8639
8640 This option causes @command{tar} to set the modes (access permissions) of
8641 extracted files exactly as recorded in the archive. If this option
8642 is not used, the current @code{umask} setting limits the permissions
8643 on extracted files. This option is by default enabled when
8644 @command{tar} is executed by a superuser.
8645
8646
8647 This option is meaningless with @option{--list} (@option{-t}).
8648
8649 @opindex preserve
8650 @item --preserve
8651 Same as both @option{--same-permissions} and @option{--same-order}.
8652
8653 The @option{--preserve} option has no equivalent short option name.
8654 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8655
8656 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8657 Neither do I. --Sergey}
8658
8659 @end table
8660
8661 @node Portability
8662 @section Making @command{tar} Archives More Portable
8663
8664 Creating a @command{tar} archive on a particular system that is meant to be
8665 useful later on many other machines and with other versions of @command{tar}
8666 is more challenging than you might think. @command{tar} archive formats
8667 have been evolving since the first versions of Unix. Many such formats
8668 are around, and are not always compatible with each other. This section
8669 discusses a few problems, and gives some advice about making @command{tar}
8670 archives more portable.
8671
8672 One golden rule is simplicity. For example, limit your @command{tar}
8673 archives to contain only regular files and directories, avoiding
8674 other kind of special files. Do not attempt to save sparse files or
8675 contiguous files as such. Let's discuss a few more problems, in turn.
8676
8677 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8678 archives and archive labels) in GNU and PAX formats.}
8679
8680 @menu
8681 * Portable Names:: Portable Names
8682 * dereference:: Symbolic Links
8683 * hard links:: Hard Links
8684 * old:: Old V7 Archives
8685 * ustar:: Ustar Archives
8686 * gnu:: GNU and old GNU format archives.
8687 * posix:: @acronym{POSIX} archives
8688 * Checksumming:: Checksumming Problems
8689 * Large or Negative Values:: Large files, negative time stamps, etc.
8690 * Other Tars:: How to Extract GNU-Specific Data Using
8691 Other @command{tar} Implementations
8692 @end menu
8693
8694 @node Portable Names
8695 @subsection Portable Names
8696
8697 Use portable file and member names. A name is portable if it contains
8698 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8699 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8700 contain @samp{/-}. Avoid deep directory nesting. For portability to
8701 old Unix hosts, limit your file name components to 14 characters or
8702 less.
8703
8704 If you intend to have your @command{tar} archives to be read under
8705 MSDOS, you should not rely on case distinction for file names, and you
8706 might use the @acronym{GNU} @command{doschk} program for helping you
8707 further diagnosing illegal MSDOS names, which are even more limited
8708 than System V's.
8709
8710 @node dereference
8711 @subsection Symbolic Links
8712 @cindex File names, using symbolic links
8713 @cindex Symbolic link as file name
8714
8715 @opindex dereference
8716 Normally, when @command{tar} archives a symbolic link, it writes a
8717 block to the archive naming the target of the link. In that way, the
8718 @command{tar} archive is a faithful record of the file system contents.
8719 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8720 @command{tar} to archive the files symbolic links point to, instead of
8721 the links themselves. When this option is used, when @command{tar}
8722 encounters a symbolic link, it will archive the linked-to file,
8723 instead of simply recording the presence of a symbolic link.
8724
8725 The name under which the file is stored in the file system is not
8726 recorded in the archive. To record both the symbolic link name and
8727 the file name in the system, archive the file under both names. If
8728 all links were recorded automatically by @command{tar}, an extracted file
8729 might be linked to a file name that no longer exists in the file
8730 system.
8731
8732 If a linked-to file is encountered again by @command{tar} while creating
8733 the same archive, an entire second copy of it will be stored. (This
8734 @emph{might} be considered a bug.)
8735
8736 So, for portable archives, do not archive symbolic links as such,
8737 and use @option{--dereference} (@option{-h}): many systems do not support
8738 symbolic links, and moreover, your distribution might be unusable if
8739 it contains unresolved symbolic links.
8740
8741 @node hard links
8742 @subsection Hard Links
8743 @UNREVISED{}
8744 @cindex File names, using hard links
8745 @cindex hard links, dereferencing
8746 @cindex dereferencing hard links
8747
8748 Normally, when @command{tar} archives a hard link, it writes a
8749 block to the archive naming the target of the link (a @samp{1} type
8750 block). In that way, the actual file contents is stored in file only
8751 once. For example, consider the following two files:
8752
8753 @smallexample
8754 @group
8755 $ ls
8756 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
8757 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
8758 @end group
8759 @end smallexample
8760
8761 Here, @file{jeden} is a link to @file{one}. When archiving this
8762 directory with a verbose level 2, you will get an output similar to
8763 the following:
8764
8765 @smallexample
8766 $ tar cfvv ../archive.tar .
8767 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8768 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8769 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
8770 @end smallexample
8771
8772 The last line shows that, instead of storing two copies of the file,
8773 @command{tar} stored it only once, under the name @file{jeden}, and
8774 stored file @file{one} as a hard link to this file.
8775
8776 It may be important to know that all hard links to the given file are
8777 stored in the archive. For example, this may be necessary for exact
8778 reproduction of the file system. The following option does that:
8779
8780 @table @option
8781 @xopindex{check-links, described}
8782 @item --check-links
8783 @itemx -l
8784 Check the number of links dumped for each processed file. If this
8785 number does not match the total number of hard links for the file, print
8786 a warning message.
8787 @end table
8788
8789 For example, trying to archive only file @file{jeden} with this option
8790 produces the following diagnostics:
8791
8792 @smallexample
8793 $ tar -c -f ../archive.tar jeden
8794 tar: Missing links to `jeden'.
8795 @end smallexample
8796
8797 Although creating special records for hard links helps keep a faithful
8798 record of the file system contents and makes archives more compact, it
8799 may present some difficulties when extracting individual members from
8800 the archive. For example, trying to extract file @file{one} from the
8801 archive created in previous examples produces, in the absense of file
8802 @file{jeden}:
8803
8804 @smallexample
8805 $ tar xf archive.tar ./one
8806 tar: ./one: Cannot hard link to `./jeden': No such file or directory
8807 tar: Error exit delayed from previous errors
8808 @end smallexample
8809
8810 The reason for this behavior is that @command{tar} cannot seek back in
8811 the archive to the previous member (in this case, @file{one}), to
8812 extract it@footnote{There are plans to fix this in future releases.}.
8813 If you wish to avoid such problems at the cost of a bigger archive,
8814 use the following option:
8815
8816 @table @option
8817 @xopindex{hard-dereference, described}
8818 @item --hard-dereference
8819 Dereference hard links and store the files they refer to.
8820 @end table
8821
8822 For example, trying this option on our two sample files, we get two
8823 copies in the archive, each of which can then be extracted
8824 independently of the other:
8825
8826 @smallexample
8827 @group
8828 $ tar -c -vv -f ../archive.tar --hard-dereference .
8829 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8830 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8831 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
8832 @end group
8833 @end smallexample
8834
8835 @node old
8836 @subsection Old V7 Archives
8837 @cindex Format, old style
8838 @cindex Old style format
8839 @cindex Old style archives
8840 @cindex v7 archive format
8841
8842 Certain old versions of @command{tar} cannot handle additional
8843 information recorded by newer @command{tar} programs. To create an
8844 archive in V7 format (not ANSI), which can be read by these old
8845 versions, specify the @option{--format=v7} option in
8846 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8847 accepts @option{--portability} or @option{--old-archive} for this
8848 option). When you specify it,
8849 @command{tar} leaves out information about directories, pipes, fifos,
8850 contiguous files, and device files, and specifies file ownership by
8851 group and user IDs instead of group and user names.
8852
8853 When updating an archive, do not use @option{--format=v7}
8854 unless the archive was created using this option.
8855
8856 In most cases, a @emph{new} format archive can be read by an @emph{old}
8857 @command{tar} program without serious trouble, so this option should
8858 seldom be needed. On the other hand, most modern @command{tar}s are
8859 able to read old format archives, so it might be safer for you to
8860 always use @option{--format=v7} for your distributions. Notice,
8861 however, that @samp{ustar} format is a better alternative, as it is
8862 free from many of @samp{v7}'s drawbacks.
8863
8864 @node ustar
8865 @subsection Ustar Archive Format
8866
8867 @cindex ustar archive format
8868 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8869 @code{ustar}. Although it is more flexible than the V7 format, it
8870 still has many restrictions (@xref{Formats,ustar}, for the detailed
8871 description of @code{ustar} format). Along with V7 format,
8872 @code{ustar} format is a good choice for archives intended to be read
8873 with other implementations of @command{tar}.
8874
8875 To create archive in @code{ustar} format, use @option{--format=ustar}
8876 option in conjunction with the @option{--create} (@option{-c}).
8877
8878 @node gnu
8879 @subsection @acronym{GNU} and old @GNUTAR{} format
8880
8881 @cindex GNU archive format
8882 @cindex Old GNU archive format
8883 @GNUTAR{} was based on an early draft of the
8884 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8885 @command{tar}, such as the support for file names longer than 100
8886 characters, use portions of the @command{tar} header record which were
8887 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8888 @acronym{POSIX} have allocated the same parts of the header record for
8889 other purposes. As a result, @GNUTAR{} format is
8890 incompatible with the current @acronym{POSIX} specification, and with
8891 @command{tar} programs that follow it.
8892
8893 In the majority of cases, @command{tar} will be configured to create
8894 this format by default. This will change in future releases, since
8895 we plan to make @samp{POSIX} format the default.
8896
8897 To force creation a @GNUTAR{} archive, use option
8898 @option{--format=gnu}.
8899
8900 @node posix
8901 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8902
8903 @cindex POSIX archive format
8904 @cindex PAX archive format
8905 Starting from version 1.14 @GNUTAR{} features full support for
8906 @acronym{POSIX.1-2001} archives.
8907
8908 A @acronym{POSIX} conformant archive will be created if @command{tar}
8909 was given @option{--format=posix} (@option{--format=pax}) option. No
8910 special option is required to read and extract from a @acronym{POSIX}
8911 archive.
8912
8913 @menu
8914 * PAX keywords:: Controlling Extended Header Keywords.
8915 @end menu
8916
8917 @node PAX keywords
8918 @subsubsection Controlling Extended Header Keywords
8919
8920 @table @option
8921 @opindex pax-option
8922 @item --pax-option=@var{keyword-list}
8923 Handle keywords in @acronym{PAX} extended headers. This option is
8924 equivalent to @option{-o} option of the @command{pax} utility.
8925 @end table
8926
8927 @var{Keyword-list} is a comma-separated
8928 list of keyword options, each keyword option taking one of
8929 the following forms:
8930
8931 @table @code
8932 @item delete=@var{pattern}
8933 When used with one of archive-creation commands,
8934 this option instructs @command{tar} to omit from extended header records
8935 that it produces any keywords matching the string @var{pattern}.
8936
8937 When used in extract or list mode, this option instructs tar
8938 to ignore any keywords matching the given @var{pattern} in the extended
8939 header records. In both cases, matching is performed using the pattern
8940 matching notation described in @acronym{POSIX 1003.2}, 3.13
8941 (@pxref{wildcards}). For example:
8942
8943 @smallexample
8944 --pax-option delete=security.*
8945 @end smallexample
8946
8947 would suppress security-related information.
8948
8949 @item exthdr.name=@var{string}
8950
8951 This keyword allows user control over the name that is written into the
8952 ustar header blocks for the extended headers. The name is obtained
8953 from @var{string} after making the following substitutions:
8954
8955 @multitable @columnfractions .25 .55
8956 @headitem Meta-character @tab Replaced By
8957 @item %d @tab The directory name of the file, equivalent to the
8958 result of the @command{dirname} utility on the translated file name.
8959 @item %f @tab The name of the file with the directory information
8960 stripped, equivalent to the result of the @command{basename} utility
8961 on the translated file name.
8962 @item %p @tab The process @acronym{ID} of the @command{tar} process.
8963 @item %% @tab A @samp{%} character.
8964 @end multitable
8965
8966 Any other @samp{%} characters in @var{string} produce undefined
8967 results.
8968
8969 If no option @samp{exthdr.name=string} is specified, @command{tar}
8970 will use the following default value:
8971
8972 @smallexample
8973 %d/PaxHeaders.%p/%f
8974 @end smallexample
8975
8976 @item globexthdr.name=@var{string}
8977 This keyword allows user control over the name that is written into
8978 the ustar header blocks for global extended header records. The name
8979 is obtained from the contents of @var{string}, after making
8980 the following substitutions:
8981
8982 @multitable @columnfractions .25 .55
8983 @headitem Meta-character @tab Replaced By
8984 @item %n @tab An integer that represents the
8985 sequence number of the global extended header record in the archive,
8986 starting at 1.
8987 @item %p @tab The process @acronym{ID} of the @command{tar} process.
8988 @item %% @tab A @samp{%} character.
8989 @end multitable
8990
8991 Any other @samp{%} characters in @var{string} produce undefined results.
8992
8993 If no option @samp{globexthdr.name=string} is specified, @command{tar}
8994 will use the following default value:
8995
8996 @smallexample
8997 $TMPDIR/GlobalHead.%p.%n
8998 @end smallexample
8999
9000 @noindent
9001 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9002 environment variable. If @var{TMPDIR} is not set, @command{tar}
9003 uses @samp{/tmp}.
9004
9005 @item @var{keyword}=@var{value}
9006 When used with one of archive-creation commands, these keyword/value pairs
9007 will be included at the beginning of the archive in a global extended
9008 header record. When used with one of archive-reading commands,
9009 @command{tar} will behave as if it has encountered these keyword/value
9010 pairs at the beginning of the archive in a global extended header
9011 record.
9012
9013 @item @var{keyword}:=@var{value}
9014 When used with one of archive-creation commands, these keyword/value pairs
9015 will be included as records at the beginning of an extended header for
9016 each file. This is effectively equivalent to @var{keyword}=@var{value}
9017 form except that it creates no global extended header records.
9018
9019 When used with one of archive-reading commands, @command{tar} will
9020 behave as if these keyword/value pairs were included as records at the
9021 end of each extended header; thus, they will override any global or
9022 file-specific extended header record keywords of the same names.
9023 For example, in the command:
9024
9025 @smallexample
9026 tar --format=posix --create \
9027 --file archive --pax-option gname:=user .
9028 @end smallexample
9029
9030 the group name will be forced to a new value for all files
9031 stored in the archive.
9032 @end table
9033
9034 @node Checksumming
9035 @subsection Checksumming Problems
9036
9037 SunOS and HP-UX @command{tar} fail to accept archives created using
9038 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9039 is, file names having characters with the eight bit set, because they
9040 use signed checksums, while @GNUTAR{} uses unsigned
9041 checksums while creating archives, as per @acronym{POSIX} standards. On
9042 reading, @GNUTAR{} computes both checksums and
9043 accept any. It is somewhat worrying that a lot of people may go
9044 around doing backup of their files using faulty (or at least
9045 non-standard) software, not learning about it until it's time to
9046 restore their missing files with an incompatible file extractor, or
9047 vice versa.
9048
9049 @GNUTAR{} compute checksums both ways, and accept
9050 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9051 wrong checksums. @GNUTAR{} produces the standard
9052 checksum, however, raising incompatibilities with Sun. That is to
9053 say, @GNUTAR{} has not been modified to
9054 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9055 I've been told that more recent Sun @command{tar} now read standard
9056 archives, so maybe Sun did a similar patch, after all?
9057
9058 The story seems to be that when Sun first imported @command{tar}
9059 sources on their system, they recompiled it without realizing that
9060 the checksums were computed differently, because of a change in
9061 the default signing of @code{char}'s in their compiler. So they
9062 started computing checksums wrongly. When they later realized their
9063 mistake, they merely decided to stay compatible with it, and with
9064 themselves afterwards. Presumably, but I do not really know, HP-UX
9065 has chosen that their @command{tar} archives to be compatible with Sun's.
9066 The current standards do not favor Sun @command{tar} format. In any
9067 case, it now falls on the shoulders of SunOS and HP-UX users to get
9068 a @command{tar} able to read the good archives they receive.
9069
9070 @node Large or Negative Values
9071 @subsection Large or Negative Values
9072 @cindex large values
9073 @cindex future time stamps
9074 @cindex negative time stamps
9075 @UNREVISED{}
9076
9077 The above sections suggest to use @samp{oldest possible} archive
9078 format if in doubt. However, sometimes it is not possible. If you
9079 attempt to archive a file whose metadata cannot be represented using
9080 required format, @GNUTAR{} will print error message and ignore such a
9081 file. You will than have to switch to a format that is able to
9082 handle such values. The format summary table (@pxref{Formats}) will
9083 help you to do so.
9084
9085 In particular, when trying to archive files larger than 8GB or with
9086 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9087 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9088 @acronym{POSIX} archive formats. When considering which format to
9089 choose, bear in mind that the @acronym{GNU} format uses
9090 two's-complement base-256 notation to store values that do not fit
9091 into standard @acronym{ustar} range. Such archives can generally be
9092 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9093 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9094 example, using two's complement representation for negative time
9095 stamps that assumes a signed 32-bit @code{time_t} generates archives
9096 that are not portable to hosts with differing @code{time_t}
9097 representations.
9098
9099 On the other hand, @acronym{POSIX} archives, generally speaking, can
9100 be extracted by any tar implementation that understands older
9101 @acronym{ustar} format. The only exception are files larger than 8GB.
9102
9103 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9104 POSIX-aware tars.}
9105
9106 @node Other Tars
9107 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9108
9109 In previous sections you became acquainted with various quirks
9110 necessary to make your archives portable. Sometimes you may need to
9111 extract archives containing GNU-specific members using some
9112 third-party @command{tar} implementation or an older version of
9113 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9114 but if it is for some reason impossible, this section will explain
9115 how to cope without it.
9116
9117 When we speak about @dfn{GNU-specific} members we mean two classes of
9118 them: members split between the volumes of a multi-volume archive and
9119 sparse members. You will be able to always recover such members if
9120 the archive is in PAX format. In addition split members can be
9121 recovered from archives in old GNU format. The following subsections
9122 describe the required procedures in detail.
9123
9124 @menu
9125 * Split Recovery:: Members Split Between Volumes
9126 * Sparse Recovery:: Sparse Members
9127 @end menu
9128
9129 @node Split Recovery
9130 @subsubsection Extracting Members Split Between Volumes
9131
9132 @cindex Mutli-volume archives, extracting using non-GNU tars
9133 If a member is split between several volumes of an old GNU format archive
9134 most third party @command{tar} implementation will fail to extract
9135 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9136 This program is available from
9137 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9138 home page}. It concatenates several archive volumes into a single
9139 valid archive. For example, if you have three volumes named from
9140 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9141 extract them using a third-party @command{tar}:
9142
9143 @smallexample
9144 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9145 @end smallexample
9146
9147 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9148 You could use this approach for most (although not all) PAX
9149 format archives as well. However, extracting split members from a PAX
9150 archive is a much easier task, because PAX volumes are constructed in
9151 such a way that each part of a split member is extracted to a
9152 different file by @command{tar} implementations that are not aware of
9153 GNU extensions. More specifically, the very first part retains its
9154 original name, and all subsequent parts are named using the pattern:
9155
9156 @smallexample
9157 %d/GNUFileParts.%p/%f.%n
9158 @end smallexample
9159
9160 @noindent
9161 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9162 have the following meaning:
9163
9164 @multitable @columnfractions .25 .55
9165 @headitem Meta-character @tab Replaced By
9166 @item %d @tab The directory name of the file, equivalent to the
9167 result of the @command{dirname} utility on its full name.
9168 @item %f @tab The file name of the file, equivalent to the result
9169 of the @command{basename} utility on its full name.
9170 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9171 created the archive.
9172 @item %n @tab Ordinal number of this particular part.
9173 @end multitable
9174
9175 For example, if the file @file{var/longfile} was split during archive
9176 creation between three volumes, and the creator @command{tar} process
9177 had process @acronym{ID} @samp{27962}, then the member names will be:
9178
9179 @smallexample
9180 var/longfile
9181 var/GNUFileParts.27962/longfile.1
9182 var/GNUFileParts.27962/longfile.2
9183 @end smallexample
9184
9185 When you extract your archive using a third-party @command{tar}, these
9186 files will be created on your disk, and the only thing you will need
9187 to do to restore your file in its original form is concatenate them in
9188 the proper order, for example:
9189
9190 @smallexample
9191 @group
9192 $ @kbd{cd var}
9193 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9194 GNUFileParts.27962/longfile.2 >> longfile}
9195 $ rm -f GNUFileParts.27962
9196 @end group
9197 @end smallexample
9198
9199 Notice, that if the @command{tar} implementation you use supports PAX
9200 format archives, it will probably emit warnings about unknown keywords
9201 during extraction. They will look like this:
9202
9203 @smallexample
9204 @group
9205 Tar file too small
9206 Unknown extended header keyword 'GNU.volume.filename' ignored.
9207 Unknown extended header keyword 'GNU.volume.size' ignored.
9208 Unknown extended header keyword 'GNU.volume.offset' ignored.
9209 @end group
9210 @end smallexample
9211
9212 @noindent
9213 You can safely ignore these warnings.
9214
9215 If your @command{tar} implementation is not PAX-aware, you will get
9216 more warnings and more files generated on your disk, e.g.:
9217
9218 @smallexample
9219 @group
9220 $ @kbd{tar xf vol-1.tar}
9221 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9222 normal file
9223 Unexpected EOF in archive
9224 $ @kbd{tar xf vol-2.tar}
9225 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9226 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9227 'x', extracted as normal file
9228 @end group
9229 @end smallexample
9230
9231 Ignore these warnings. The @file{PaxHeaders.*} directories created
9232 will contain files with @dfn{extended header keywords} describing the
9233 extracted files. You can delete them, unless they describe sparse
9234 members. Read further to learn more about them.
9235
9236 @node Sparse Recovery
9237 @subsubsection Extracting Sparse Members
9238
9239 @cindex sparse files, extracting with non-GNU tars
9240 Any @command{tar} implementation will be able to extract sparse members from a
9241 PAX archive. However, the extracted files will be @dfn{condensed},
9242 i.e., any zero blocks will be removed from them. When we restore such
9243 a condensed file to its original form, by adding zero blocks (or
9244 @dfn{holes}) back to their original locations, we call this process
9245 @dfn{expanding} a compressed sparse file.
9246
9247 @pindex xsparse
9248 To expand a file, you will need a simple auxiliary program called
9249 @command{xsparse}. It is available in source form from
9250 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9251 home page}.
9252
9253 @cindex sparse files v.1.0, extracting with non-GNU tars
9254 Let's begin with archive members in @dfn{sparse format
9255 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9256 The condensed file will contain both file map and file data, so no
9257 additional data will be needed to restore it. If the original file
9258 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9259 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9260 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
9261 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9262 archive (@pxref{PAX keywords}).}.
9263
9264 To expand a version 1.0 file, run @command{xsparse} as follows:
9265
9266 @smallexample
9267 $ @kbd{xsparse @file{cond-file}}
9268 @end smallexample
9269
9270 @noindent
9271 where @file{cond-file} is the name of the condensed file. The utility
9272 will deduce the name for the resulting expanded file using the
9273 following algorithm:
9274
9275 @enumerate 1
9276 @item If @file{cond-file} does not contain any directories,
9277 @file{../cond-file} will be used;
9278
9279 @item If @file{cond-file} has the form
9280 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
9281 are simple names, with no @samp{/} characters in them, the output file
9282 name will be @file{@var{dir}/@var{name}}.
9283
9284 @item Otherwise, if @file{cond-file} has the form
9285 @file{@var{dir}/@var{name}}, the output file name will be
9286 @file{@var{name}}.
9287 @end enumerate
9288
9289 In the unlikely case when this algorithm does not suit your needs,
9290 you can explicitly specify output file name as a second argument to
9291 the command:
9292
9293 @smallexample
9294 $ @kbd{xsparse @file{cond-file} @file{out-file}}
9295 @end smallexample
9296
9297 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
9298 first. In this mode, the command does not actually expand the file,
9299 but verbosely lists all actions it would be taking to do so. The dry
9300 run mode is enabled by @option{-n} command line argument:
9301
9302 @smallexample
9303 @group
9304 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
9305 Reading v.1.0 sparse map
9306 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9307 `/home/gray/sparsefile'
9308 Finished dry run
9309 @end group
9310 @end smallexample
9311
9312 To actually expand the file, you would run:
9313
9314 @smallexample
9315 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9316 @end smallexample
9317
9318 @noindent
9319 The program behaves the same way all UNIX utilities do: it will keep
9320 quiet unless it has simething important to tell you (e.g. an error
9321 condition or something). If you wish it to produce verbose output,
9322 similar to that from the dry run mode, use @option{-v} option:
9323
9324 @smallexample
9325 @group
9326 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
9327 Reading v.1.0 sparse map
9328 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9329 `/home/gray/sparsefile'
9330 Done
9331 @end group
9332 @end smallexample
9333
9334 Additionally, if your @command{tar} implementation has extracted the
9335 @dfn{extended headers} for this file, you can instruct @command{xstar}
9336 to use them in order to verify the integrity of the expanded file.
9337 The option @option{-x} sets the name of the extended header file to
9338 use. Continuing our example:
9339
9340 @smallexample
9341 @group
9342 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
9343 /home/gray/GNUSparseFile.6058/sparsefile}
9344 Reading extended header file
9345 Found variable GNU.sparse.major = 1
9346 Found variable GNU.sparse.minor = 0
9347 Found variable GNU.sparse.name = sparsefile
9348 Found variable GNU.sparse.realsize = 217481216
9349 Reading v.1.0 sparse map
9350 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9351 `/home/gray/sparsefile'
9352 Done
9353 @end group
9354 @end smallexample
9355
9356 @anchor{extracting sparse v.0.x}
9357 @cindex sparse files v.0.1, extracting with non-GNU tars
9358 @cindex sparse files v.0.0, extracting with non-GNU tars
9359 An @dfn{extended header} is a special @command{tar} archive header
9360 that precedes an archive member and contains a set of
9361 @dfn{variables}, describing the member properties that cannot be
9362 stored in the standard @code{ustar} header. While optional for
9363 expanding sparse version 1.0 members, the use of extended headers is
9364 mandatory when expanding sparse members in older sparse formats: v.0.0
9365 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
9366 Formats}.) So, for these formats, the question is: how to obtain
9367 extended headers from the archive?
9368
9369 If you use a @command{tar} implementation that does not support PAX
9370 format, extended headers for each member will be extracted as a
9371 separate file. If we represent the member name as
9372 @file{@var{dir}/@var{name}}, then the extended header file will be
9373 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
9374 @var{n} is an integer number.
9375
9376 Things become more difficult if your @command{tar} implementation
9377 does support PAX headers, because in this case you will have to
9378 manually extract the headers. We recommend the following algorithm:
9379
9380 @enumerate 1
9381 @item
9382 Consult the documentation of your @command{tar} implementation for an
9383 option that prints @dfn{block numbers} along with the archive
9384 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
9385 @command{star} has @option{-block-number}.
9386
9387 @item
9388 Obtain verbose listing using the @samp{block number} option, and
9389 find block numbers of the sparse member in question and the member
9390 immediately following it. For example, running @command{star} on our
9391 archive we obtain:
9392
9393 @smallexample
9394 @group
9395 $ @kbd{star -t -v -block-number -f arc.tar}
9396 @dots{}
9397 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
9398 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
9399 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
9400 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
9401 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
9402 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
9403 @dots{}
9404 @end group
9405 @end smallexample
9406
9407 @noindent
9408 (as usual, ignore the warnings about unknown keywords.)
9409
9410 @item
9411 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
9412 and @var{Bn} be the block number of the next member.
9413 Compute:
9414
9415 @smallexample
9416 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
9417 @end smallexample
9418
9419 @noindent
9420 This number gives the size of the extended header part in tar @dfn{blocks}.
9421 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
9422 = 7}.
9423
9424 @item
9425 Use @command{dd} to extract the headers:
9426
9427 @smallexample
9428 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
9429 @end smallexample
9430
9431 @noindent
9432 where @var{archive} is the archive name, @var{hname} is a name of the
9433 file to store the extended header in, @var{Bs} and @var{N} are
9434 computed in previous steps.
9435
9436 In our example, this command will be
9437
9438 @smallexample
9439 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
9440 @end smallexample
9441 @end enumerate
9442
9443 Finally, you can expand the condensed file, using the obtained header:
9444
9445 @smallexample
9446 @group
9447 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
9448 Reading extended header file
9449 Found variable GNU.sparse.size = 217481216
9450 Found variable GNU.sparse.numblocks = 208
9451 Found variable GNU.sparse.name = sparsefile
9452 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
9453 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
9454 Done
9455 @end group
9456 @end smallexample
9457
9458 @node cpio
9459 @section Comparison of @command{tar} and @command{cpio}
9460 @UNREVISED
9461
9462 @FIXME{Reorganize the following material}
9463
9464 The @command{cpio} archive formats, like @command{tar}, do have maximum
9465 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
9466 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
9467 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
9468 with arbitrary file name lengths, but other @command{cpio} implementations
9469 may crash unexplainedly trying to read them.
9470
9471 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
9472 @command{cpio} doesn't handle symbolic links in the form in which it comes
9473 in System V prior to SVR4, and some vendors may have added symlinks
9474 to their system without enhancing @command{cpio} to know about them.
9475 Others may have enhanced it in a way other than the way I did it
9476 at Sun, and which was adopted by AT&T (and which is, I think, also
9477 present in the @command{cpio} that Berkeley picked up from AT&T and put
9478 into a later @acronym{BSD} release---I think I gave them my changes).
9479
9480 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
9481 can handle @command{tar} format input, and write it on output, and it
9482 probably handles symbolic links. They may not have bothered doing
9483 anything to enhance @command{tar} as a result.)
9484
9485 @command{cpio} handles special files; traditional @command{tar} doesn't.
9486
9487 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
9488 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
9489 (4.3-tahoe and later).
9490
9491 @command{tar}'s way of handling multiple hard links to a file can handle
9492 file systems that support 32-bit inumbers (e.g., the @acronym{BSD} file system);
9493 @command{cpio}s way requires you to play some games (in its ``binary''
9494 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
9495 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
9496 field of the header to make sure that the file system @acronym{ID}/i-number pairs
9497 of different files were always different), and I don't know which
9498 @command{cpio}s, if any, play those games. Those that don't might get
9499 confused and think two files are the same file when they're not, and
9500 make hard links between them.
9501
9502 @command{tar}s way of handling multiple hard links to a file places only
9503 one copy of the link on the tape, but the name attached to that copy
9504 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
9505 way puts one copy for every link, but you can retrieve it using any
9506 of the names.
9507
9508 @quotation
9509 What type of check sum (if any) is used, and how is this calculated.
9510 @end quotation
9511
9512 See the attached manual pages for @command{tar} and @command{cpio} format.
9513 @command{tar} uses a checksum which is the sum of all the bytes in the
9514 @command{tar} header for a file; @command{cpio} uses no checksum.
9515
9516 @quotation
9517 If anyone knows why @command{cpio} was made when @command{tar} was present
9518 at the unix scene,
9519 @end quotation
9520
9521 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
9522 generally-available version of UNIX had @command{tar} at the time. I don't
9523 know whether any version that was generally available @emph{within AT&T}
9524 had @command{tar}, or, if so, whether the people within AT&T who did
9525 @command{cpio} knew about it.
9526
9527 On restore, if there is a corruption on a tape @command{tar} will stop at
9528 that point, while @command{cpio} will skip over it and try to restore the
9529 rest of the files.
9530
9531 The main difference is just in the command syntax and header format.
9532
9533 @command{tar} is a little more tape-oriented in that everything is blocked
9534 to start on a record boundary.
9535
9536 @quotation
9537 Is there any differences between the ability to recover crashed
9538 archives between the two of them. (Is there any chance of recovering
9539 crashed archives at all.)
9540 @end quotation
9541
9542 Theoretically it should be easier under @command{tar} since the blocking
9543 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9544 However, modern @command{cpio}'s and variations have an option to just
9545 search for the next file header after an error with a reasonable chance
9546 of resyncing. However, lots of tape driver software won't allow you to
9547 continue past a media error which should be the only reason for getting
9548 out of sync unless a file changed sizes while you were writing the
9549 archive.
9550
9551 @quotation
9552 If anyone knows why @command{cpio} was made when @command{tar} was present
9553 at the unix scene, please tell me about this too.
9554 @end quotation
9555
9556 Probably because it is more media efficient (by not blocking everything
9557 and using only the space needed for the headers where @command{tar}
9558 always uses 512 bytes per file header) and it knows how to archive
9559 special files.
9560
9561 You might want to look at the freely available alternatives. The
9562 major ones are @command{afio}, @GNUTAR{}, and
9563 @command{pax}, each of which have their own extensions with some
9564 backwards compatibility.
9565
9566 Sparse files were @command{tar}red as sparse files (which you can
9567 easily test, because the resulting archive gets smaller, and
9568 @acronym{GNU} @command{cpio} can no longer read it).
9569
9570 @node Media
9571 @chapter Tapes and Other Archive Media
9572 @UNREVISED
9573
9574 A few special cases about tape handling warrant more detailed
9575 description. These special cases are discussed below.
9576
9577 Many complexities surround the use of @command{tar} on tape drives. Since
9578 the creation and manipulation of archives located on magnetic tape was
9579 the original purpose of @command{tar}, it contains many features making
9580 such manipulation easier.
9581
9582 Archives are usually written on dismountable media---tape cartridges,
9583 mag tapes, or floppy disks.
9584
9585 The amount of data a tape or disk holds depends not only on its size,
9586 but also on how it is formatted. A 2400 foot long reel of mag tape
9587 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9588 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9589
9590 Magnetic media are re-usable---once the archive on a tape is no longer
9591 needed, the archive can be erased and the tape or disk used over.
9592 Media quality does deteriorate with use, however. Most tapes or disks
9593 should be discarded when they begin to produce data errors. EXABYTE
9594 tape cartridges should be discarded when they generate an @dfn{error
9595 count} (number of non-usable bits) of more than 10k.
9596
9597 Magnetic media are written and erased using magnetic fields, and
9598 should be protected from such fields to avoid damage to stored data.
9599 Sticking a floppy disk to a filing cabinet using a magnet is probably
9600 not a good idea.
9601
9602 @menu
9603 * Device:: Device selection and switching
9604 * Remote Tape Server::
9605 * Common Problems and Solutions::
9606 * Blocking:: Blocking
9607 * Many:: Many archives on one tape
9608 * Using Multiple Tapes:: Using Multiple Tapes
9609 * label:: Including a Label in the Archive
9610 * verify::
9611 * Write Protection::
9612 @end menu
9613
9614 @node Device
9615 @section Device Selection and Switching
9616 @UNREVISED
9617
9618 @table @option
9619 @item -f [@var{hostname}:]@var{file}
9620 @itemx --file=[@var{hostname}:]@var{file}
9621 Use archive file or device @var{file} on @var{hostname}.
9622 @end table
9623
9624 This option is used to specify the file name of the archive @command{tar}
9625 works on.
9626
9627 If the file name is @samp{-}, @command{tar} reads the archive from standard
9628 input (when listing or extracting), or writes it to standard output
9629 (when creating). If the @samp{-} file name is given when updating an
9630 archive, @command{tar} will read the original archive from its standard
9631 input, and will write the entire new archive to its standard output.
9632
9633 If the file name contains a @samp{:}, it is interpreted as
9634 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9635 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9636 either case, @command{tar} will invoke the command @command{rsh} (or
9637 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9638 machine. If you give an alternate login name, it will be given to the
9639 @command{rsh}.
9640 Naturally, the remote machine must have an executable
9641 @command{/usr/libexec/rmt}. This program is free software from the
9642 University of California, and a copy of the source code can be found
9643 with the sources for @command{tar}; it's compiled and installed by default.
9644 The exact path to this utility is determined when configuring the package.
9645 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9646 your installation prefix. This location may also be overridden at
9647 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9648 ---rmt-command}, for detailed description of this option. @xref{Remote
9649 Tape Server}, for the description of @command{rmt} command).
9650
9651 If this option is not given, but the environment variable @env{TAPE}
9652 is set, its value is used; otherwise, old versions of @command{tar}
9653 used a default archive name (which was picked when @command{tar} was
9654 compiled). The default is normally set up to be the @dfn{first} tape
9655 drive or other transportable I/O medium on the system.
9656
9657 Starting with version 1.11.5, @GNUTAR{} uses
9658 standard input and standard output as the default device, and I will
9659 not try anymore supporting automatic device detection at installation
9660 time. This was failing really in too many cases, it was hopeless.
9661 This is now completely left to the installer to override standard
9662 input and standard output for default device, if this seems
9663 preferable. Further, I think @emph{most} actual usages of
9664 @command{tar} are done with pipes or disks, not really tapes,
9665 cartridges or diskettes.
9666
9667 Some users think that using standard input and output is running
9668 after trouble. This could lead to a nasty surprise on your screen if
9669 you forget to specify an output file name---especially if you are going
9670 through a network or terminal server capable of buffering large amounts
9671 of output. We had so many bug reports in that area of configuring
9672 default tapes automatically, and so many contradicting requests, that
9673 we finally consider the problem to be portably intractable. We could
9674 of course use something like @samp{/dev/tape} as a default, but this
9675 is @emph{also} running after various kind of trouble, going from hung
9676 processes to accidental destruction of real tapes. After having seen
9677 all this mess, using standard input and output as a default really
9678 sounds like the only clean choice left, and a very useful one too.
9679
9680 @GNUTAR{} reads and writes archive in records, I
9681 suspect this is the main reason why block devices are preferred over
9682 character devices. Most probably, block devices are more efficient
9683 too. The installer could also check for @samp{DEFTAPE} in
9684 @file{<sys/mtio.h>}.
9685
9686 @table @option
9687 @xopindex{force-local, short description}
9688 @item --force-local
9689 Archive file is local even if it contains a colon.
9690
9691 @opindex rsh-command
9692 @item --rsh-command=@var{command}
9693 Use remote @var{command} instead of @command{rsh}. This option exists
9694 so that people who use something other than the standard @command{rsh}
9695 (e.g., a Kerberized @command{rsh}) can access a remote device.
9696
9697 When this command is not used, the shell command found when
9698 the @command{tar} program was installed is used instead. This is
9699 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9700 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9701 The installer may have overridden this by defining the environment
9702 variable @env{RSH} @emph{at installation time}.
9703
9704 @item -[0-7][lmh]
9705 Specify drive and density.
9706
9707 @xopindex{multi-volume, short description}
9708 @item -M
9709 @itemx --multi-volume
9710 Create/list/extract multi-volume archive.
9711
9712 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9713 that may be larger than will fit on the medium used to hold it.
9714 @xref{Multi-Volume Archives}.
9715
9716 @xopindex{tape-length, short description}
9717 @item -L @var{num}
9718 @itemx --tape-length=@var{num}
9719 Change tape after writing @var{num} x 1024 bytes.
9720
9721 This option might be useful when your tape drivers do not properly
9722 detect end of physical tapes. By being slightly conservative on the
9723 maximum tape length, you might avoid the problem entirely.
9724
9725 @xopindex{info-script, short description}
9726 @xopindex{new-volume-script, short description}
9727 @item -F @var{file}
9728 @itemx --info-script=@var{file}
9729 @itemx --new-volume-script=@var{file}
9730 Execute @file{file} at end of each tape. This implies
9731 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9732 description of this option.
9733 @end table
9734
9735 @node Remote Tape Server
9736 @section The Remote Tape Server
9737
9738 @cindex remote tape drive
9739 @pindex rmt
9740 In order to access the tape drive on a remote machine, @command{tar}
9741 uses the remote tape server written at the University of California at
9742 Berkeley. The remote tape server must be installed as
9743 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9744 want to use. @command{tar} calls @command{rmt} by running an
9745 @command{rsh} or @command{remsh} to the remote machine, optionally
9746 using a different login name if one is supplied.
9747
9748 A copy of the source for the remote tape server is provided. It is
9749 Copyright @copyright{} 1983 by the Regents of the University of
9750 California, but can be freely distributed. It is compiled and
9751 installed by default.
9752
9753 @cindex absolute file names
9754 Unless you use the @option{--absolute-names} (@option{-P}) option,
9755 @GNUTAR{} will not allow you to create an archive that contains
9756 absolute file names (a file name beginning with @samp{/}.) If you try,
9757 @command{tar} will automatically remove the leading @samp{/} from the
9758 file names it stores in the archive. It will also type a warning
9759 message telling you what it is doing.
9760
9761 When reading an archive that was created with a different
9762 @command{tar} program, @GNUTAR{} automatically
9763 extracts entries in the archive which have absolute file names as if
9764 the file names were not absolute. This is an important feature. A
9765 visitor here once gave a @command{tar} tape to an operator to restore;
9766 the operator used Sun @command{tar} instead of @GNUTAR{},
9767 and the result was that it replaced large portions of
9768 our @file{/bin} and friends with versions from the tape; needless to
9769 say, we were unhappy about having to recover the file system from
9770 backup tapes.
9771
9772 For example, if the archive contained a file @file{/usr/bin/computoy},
9773 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9774 relative to the current directory. If you want to extract the files in
9775 an archive to the same absolute names that they had when the archive
9776 was created, you should do a @samp{cd /} before extracting the files
9777 from the archive, or you should either use the @option{--absolute-names}
9778 option, or use the command @samp{tar -C / @dots{}}.
9779
9780 @cindex Ultrix 3.1 and write failure
9781 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9782 can claim that a short write near the end of a tape succeeded,
9783 when it actually failed. This will result in the -M option not
9784 working correctly. The best workaround at the moment is to use a
9785 significantly larger blocking factor than the default 20.
9786
9787 In order to update an archive, @command{tar} must be able to backspace the
9788 archive in order to reread or rewrite a record that was just read (or
9789 written). This is currently possible only on two kinds of files: normal
9790 disk files (or any other file that can be backspaced with @samp{lseek}),
9791 and industry-standard 9-track magnetic tape (or any other kind of tape
9792 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9793
9794 This means that the @option{--append}, @option{--concatenate}, and
9795 @option{--delete} commands will not work on any other kind of file.
9796 Some media simply cannot be backspaced, which means these commands and
9797 options will never be able to work on them. These non-backspacing
9798 media include pipes and cartridge tape drives.
9799
9800 Some other media can be backspaced, and @command{tar} will work on them
9801 once @command{tar} is modified to do so.
9802
9803 Archives created with the @option{--multi-volume}, @option{--label}, and
9804 @option{--incremental} (@option{-G}) options may not be readable by other version
9805 of @command{tar}. In particular, restoring a file that was split over
9806 a volume boundary will require some careful work with @command{dd}, if
9807 it can be done at all. Other versions of @command{tar} may also create
9808 an empty file whose name is that of the volume header. Some versions
9809 of @command{tar} may create normal files instead of directories archived
9810 with the @option{--incremental} (@option{-G}) option.
9811
9812 @node Common Problems and Solutions
9813 @section Some Common Problems and their Solutions
9814
9815 @ifclear PUBLISH
9816
9817 @format
9818 errors from system:
9819 permission denied
9820 no such file or directory
9821 not owner
9822
9823 errors from @command{tar}:
9824 directory checksum error
9825 header format error
9826
9827 errors from media/system:
9828 i/o error
9829 device busy
9830 @end format
9831
9832 @end ifclear
9833
9834 @node Blocking
9835 @section Blocking
9836 @UNREVISED
9837
9838 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9839 is also confusing to the expert reader. On the other hand, readers
9840 who are new to the field have a fresh mind, and they may safely skip
9841 the next two paragraphs, as the remainder of this manual uses those
9842 two terms in a quite consistent way.
9843
9844 John Gilmore, the writer of the public domain @command{tar} from which
9845 @GNUTAR{} was originally derived, wrote (June 1995):
9846
9847 @quotation
9848 The nomenclature of tape drives comes from IBM, where I believe
9849 they were invented for the IBM 650 or so. On IBM mainframes, what
9850 is recorded on tape are tape blocks. The logical organization of
9851 data is into records. There are various ways of putting records into
9852 blocks, including @code{F} (fixed sized records), @code{V} (variable
9853 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9854 to a block), @code{VB} (variable size records, @var{n} to a block),
9855 @code{VSB} (variable spanned blocked: variable sized records that can
9856 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9857 parameter specified this to the operating system.
9858
9859 The Unix man page on @command{tar} was totally confused about this.
9860 When I wrote @code{PD TAR}, I used the historically correct terminology
9861 (@command{tar} writes data records, which are grouped into blocks).
9862 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9863 here), and now Fran@,{c}ois has migrated that terminology back
9864 into the source code too.
9865 @end quotation
9866
9867 The term @dfn{physical block} means the basic transfer chunk from or
9868 to a device, after which reading or writing may stop without anything
9869 being lost. In this manual, the term @dfn{block} usually refers to
9870 a disk physical block, @emph{assuming} that each disk block is 512
9871 bytes in length. It is true that some disk devices have different
9872 physical blocks, but @command{tar} ignore these differences in its own
9873 format, which is meant to be portable, so a @command{tar} block is always
9874 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9875 The term @dfn{logical block} often represents the basic chunk of
9876 allocation of many disk blocks as a single entity, which the operating
9877 system treats somewhat atomically; this concept is only barely used
9878 in @GNUTAR{}.
9879
9880 The term @dfn{physical record} is another way to speak of a physical
9881 block, those two terms are somewhat interchangeable. In this manual,
9882 the term @dfn{record} usually refers to a tape physical block,
9883 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9884 It is true that archives may be put on disk or used with pipes,
9885 but nevertheless, @command{tar} tries to read and write the archive one
9886 @dfn{record} at a time, whatever the medium in use. One record is made
9887 up of an integral number of blocks, and this operation of putting many
9888 disk blocks into a single tape block is called @dfn{reblocking}, or
9889 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9890 the logical organization of many characters into something meaningful
9891 to the application. The term @dfn{unit record} describes a small set
9892 of characters which are transmitted whole to or by the application,
9893 and often refers to a line of text. Those two last terms are unrelated
9894 to what we call a @dfn{record} in @GNUTAR{}.
9895
9896 When writing to tapes, @command{tar} writes the contents of the archive
9897 in chunks known as @dfn{records}. To change the default blocking
9898 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9899 @var{512-size}}) option. Each record will then be composed of
9900 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9901 @xref{Standard}.) Each file written to the archive uses at least one
9902 full record. As a result, using a larger record size can result in
9903 more wasted space for small files. On the other hand, a larger record
9904 size can often be read and written much more efficiently.
9905
9906 Further complicating the problem is that some tape drives ignore the
9907 blocking entirely. For these, a larger record size can still improve
9908 performance (because the software layers above the tape drive still
9909 honor the blocking), but not as dramatically as on tape drives that
9910 honor blocking.
9911
9912 When reading an archive, @command{tar} can usually figure out the
9913 record size on itself. When this is the case, and a non-standard
9914 record size was used when the archive was created, @command{tar} will
9915 print a message about a non-standard blocking factor, and then operate
9916 normally. On some tape devices, however, @command{tar} cannot figure
9917 out the record size itself. On most of those, you can specify a
9918 blocking factor (with @option{--blocking-factor}) larger than the
9919 actual blocking factor, and then use the @option{--read-full-records}
9920 (@option{-B}) option. (If you specify a blocking factor with
9921 @option{--blocking-factor} and don't use the
9922 @option{--read-full-records} option, then @command{tar} will not
9923 attempt to figure out the recording size itself.) On some devices,
9924 you must always specify the record size exactly with
9925 @option{--blocking-factor} when reading, because @command{tar} cannot
9926 figure it out. In any case, use @option{--list} (@option{-t}) before
9927 doing any extractions to see whether @command{tar} is reading the archive
9928 correctly.
9929
9930 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9931 putting them into records is to put a whole number of them (one or
9932 more) into each record. @command{tar} records are all the same size;
9933 at the end of the file there's a block containing all zeros, which
9934 is how you tell that the remainder of the last record(s) are garbage.
9935
9936 In a standard @command{tar} file (no options), the block size is 512
9937 and the record size is 10240, for a blocking factor of 20. What the
9938 @option{--blocking-factor} option does is sets the blocking factor,
9939 changing the record size while leaving the block size at 512 bytes.
9940 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9941 most tape drives these days prefer much bigger records in order to
9942 stream and not waste tape. When writing tapes for myself, some tend
9943 to use a factor of the order of 2048, say, giving a record size of
9944 around one megabyte.
9945
9946 If you use a blocking factor larger than 20, older @command{tar}
9947 programs might not be able to read the archive, so we recommend this
9948 as a limit to use in practice. @GNUTAR{}, however,
9949 will support arbitrarily large record sizes, limited only by the
9950 amount of virtual memory or the physical characteristics of the tape
9951 device.
9952
9953 @menu
9954 * Format Variations:: Format Variations
9955 * Blocking Factor:: The Blocking Factor of an Archive
9956 @end menu
9957
9958 @node Format Variations
9959 @subsection Format Variations
9960 @cindex Format Parameters
9961 @cindex Format Options
9962 @cindex Options, archive format specifying
9963 @cindex Options, format specifying
9964 @UNREVISED
9965
9966 Format parameters specify how an archive is written on the archive
9967 media. The best choice of format parameters will vary depending on
9968 the type and number of files being archived, and on the media used to
9969 store the archive.
9970
9971 To specify format parameters when accessing or creating an archive,
9972 you can use the options described in the following sections.
9973 If you do not specify any format parameters, @command{tar} uses
9974 default parameters. You cannot modify a compressed archive.
9975 If you create an archive with the @option{--blocking-factor} option
9976 specified (@pxref{Blocking Factor}), you must specify that
9977 blocking-factor when operating on the archive. @xref{Formats}, for other
9978 examples of format parameter considerations.
9979
9980 @node Blocking Factor
9981 @subsection The Blocking Factor of an Archive
9982 @cindex Blocking Factor
9983 @cindex Record Size
9984 @cindex Number of blocks per record
9985 @cindex Number of bytes per record
9986 @cindex Bytes per record
9987 @cindex Blocks per record
9988 @UNREVISED
9989
9990 @opindex blocking-factor
9991 The data in an archive is grouped into blocks, which are 512 bytes.
9992 Blocks are read and written in whole number multiples called
9993 @dfn{records}. The number of blocks in a record (i.e., the size of a
9994 record in units of 512 bytes) is called the @dfn{blocking factor}.
9995 The @option{--blocking-factor=@var{512-size}} (@option{-b
9996 @var{512-size}}) option specifies the blocking factor of an archive.
9997 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9998 can be specified at installation. To find out the blocking factor of
9999 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10000 This may not work on some devices.
10001
10002 Records are separated by gaps, which waste space on the archive media.
10003 If you are archiving on magnetic tape, using a larger blocking factor
10004 (and therefore larger records) provides faster throughput and allows you
10005 to fit more data on a tape (because there are fewer gaps). If you are
10006 archiving on cartridge, a very large blocking factor (say 126 or more)
10007 greatly increases performance. A smaller blocking factor, on the other
10008 hand, may be useful when archiving small files, to avoid archiving lots
10009 of nulls as @command{tar} fills out the archive to the end of the record.
10010 In general, the ideal record size depends on the size of the
10011 inter-record gaps on the tape you are using, and the average size of the
10012 files you are archiving. @xref{create}, for information on
10013 writing archives.
10014
10015 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10016
10017 Archives with blocking factors larger than 20 cannot be read
10018 by very old versions of @command{tar}, or by some newer versions
10019 of @command{tar} running on old machines with small address spaces.
10020 With @GNUTAR{}, the blocking factor of an archive is limited
10021 only by the maximum record size of the device containing the archive,
10022 or by the amount of available virtual memory.
10023
10024 Also, on some systems, not using adequate blocking factors, as sometimes
10025 imposed by the device drivers, may yield unexpected diagnostics. For
10026 example, this has been reported:
10027
10028 @smallexample
10029 Cannot write to /dev/dlt: Invalid argument
10030 @end smallexample
10031
10032 @noindent
10033 In such cases, it sometimes happen that the @command{tar} bundled by
10034 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10035 requires an explicit specification for the block size,
10036 which it cannot guess. This yields some people to consider
10037 @GNUTAR{} is misbehaving, because by comparison,
10038 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10039 for example, might resolve the problem.
10040
10041 If you use a non-default blocking factor when you create an archive, you
10042 must specify the same blocking factor when you modify that archive. Some
10043 archive devices will also require you to specify the blocking factor when
10044 reading that archive, however this is not typically the case. Usually, you
10045 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10046 reports a non-default record size and then lists the archive members as
10047 it would normally. To extract files from an archive with a non-standard
10048 blocking factor (particularly if you're not sure what the blocking factor
10049 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10050 specifying a blocking factor larger then the blocking factor of the archive
10051 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
10052 @xref{list}, for more information on the @option{--list} (@option{-t})
10053 operation. @xref{Reading}, for a more detailed explanation of that option.
10054
10055 @table @option
10056 @item --blocking-factor=@var{number}
10057 @itemx -b @var{number}
10058 Specifies the blocking factor of an archive. Can be used with any
10059 operation, but is usually not necessary with @option{--list} (@option{-t}).
10060 @end table
10061
10062 Device blocking
10063
10064 @table @option
10065 @item -b @var{blocks}
10066 @itemx --blocking-factor=@var{blocks}
10067 Set record size to @math{@var{blocks} * 512} bytes.
10068
10069 This option is used to specify a @dfn{blocking factor} for the archive.
10070 When reading or writing the archive, @command{tar}, will do reads and writes
10071 of the archive in records of @math{@var{block}*512} bytes. This is true
10072 even when the archive is compressed. Some devices requires that all
10073 write operations be a multiple of a certain size, and so, @command{tar}
10074 pads the archive out to the next record boundary.
10075
10076 The default blocking factor is set when @command{tar} is compiled, and is
10077 typically 20. Blocking factors larger than 20 cannot be read by very
10078 old versions of @command{tar}, or by some newer versions of @command{tar}
10079 running on old machines with small address spaces.
10080
10081 With a magnetic tape, larger records give faster throughput and fit
10082 more data on a tape (because there are fewer inter-record gaps).
10083 If the archive is in a disk file or a pipe, you may want to specify
10084 a smaller blocking factor, since a large one will result in a large
10085 number of null bytes at the end of the archive.
10086
10087 When writing cartridge or other streaming tapes, a much larger
10088 blocking factor (say 126 or more) will greatly increase performance.
10089 However, you must specify the same blocking factor when reading or
10090 updating the archive.
10091
10092 Apparently, Exabyte drives have a physical block size of 8K bytes.
10093 If we choose our blocksize as a multiple of 8k bytes, then the problem
10094 seems to disappear. Id est, we are using block size of 112 right
10095 now, and we haven't had the problem since we switched@dots{}
10096
10097 With @GNUTAR{} the blocking factor is limited only
10098 by the maximum record size of the device containing the archive, or by
10099 the amount of available virtual memory.
10100
10101 However, deblocking or reblocking is virtually avoided in a special
10102 case which often occurs in practice, but which requires all the
10103 following conditions to be simultaneously true:
10104 @itemize @bullet
10105 @item
10106 the archive is subject to a compression option,
10107 @item
10108 the archive is not handled through standard input or output, nor
10109 redirected nor piped,
10110 @item
10111 the archive is directly handled to a local disk, instead of any special
10112 device,
10113 @item
10114 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10115 invocation.
10116 @end itemize
10117
10118 If the output goes directly to a local disk, and not through
10119 stdout, then the last write is not extended to a full record size.
10120 Otherwise, reblocking occurs. Here are a few other remarks on this
10121 topic:
10122
10123 @itemize @bullet
10124
10125 @item
10126 @command{gzip} will complain about trailing garbage if asked to
10127 uncompress a compressed archive on tape, there is an option to turn
10128 the message off, but it breaks the regularity of simply having to use
10129 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10130 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10131 Gailly, by sending a copy of this message to him.
10132
10133 @item
10134 @command{compress} does not show this problem, but as Jean-loup pointed
10135 out to Michael, @samp{compress -d} silently adds garbage after
10136 the result of decompression, which tar ignores because it already
10137 recognized its end-of-file indicator. So this bug may be safely
10138 ignored.
10139
10140 @item
10141 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10142 but will still return an exit status of 2 which tar reports in turn.
10143 @command{tar} might ignore the exit status returned, but I hate doing
10144 that, as it weakens the protection @command{tar} offers users against
10145 other possible problems at decompression time. If @command{gzip} was
10146 silently skipping trailing zeros @emph{and} also avoiding setting the
10147 exit status in this innocuous case, that would solve this situation.
10148
10149 @item
10150 @command{tar} should become more solid at not stopping to read a pipe at
10151 the first null block encountered. This inelegantly breaks the pipe.
10152 @command{tar} should rather drain the pipe out before exiting itself.
10153 @end itemize
10154
10155 @xopindex{ignore-zeros, short description}
10156 @item -i
10157 @itemx --ignore-zeros
10158 Ignore blocks of zeros in archive (means EOF).
10159
10160 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10161 of zeros in the archive. Normally a block of zeros indicates the
10162 end of the archive, but when reading a damaged archive, or one which
10163 was created by concatenating several archives together, this option
10164 allows @command{tar} to read the entire archive. This option is not on
10165 by default because many versions of @command{tar} write garbage after
10166 the zeroed blocks.
10167
10168 Note that this option causes @command{tar} to read to the end of the
10169 archive file, which may sometimes avoid problems when multiple files
10170 are stored on a single physical tape.
10171
10172 @xopindex{read-full-records, short description}
10173 @item -B
10174 @itemx --read-full-records
10175 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10176
10177 If @option{--read-full-records} is used, @command{tar}
10178 will not panic if an attempt to read a record from the archive does
10179 not return a full record. Instead, @command{tar} will keep reading
10180 until it has obtained a full
10181 record.
10182
10183 This option is turned on by default when @command{tar} is reading
10184 an archive from standard input, or from a remote machine. This is
10185 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10186 much happens to be in the pipe, even if it is less than @command{tar}
10187 requested. If this option was not used, @command{tar} would fail as
10188 soon as it read an incomplete record from the pipe.
10189
10190 This option is also useful with the commands for updating an archive.
10191
10192 @end table
10193
10194 Tape blocking
10195
10196 @FIXME{Appropriate options should be moved here from elsewhere.}
10197
10198 @cindex blocking factor
10199 @cindex tape blocking
10200
10201 When handling various tapes or cartridges, you have to take care of
10202 selecting a proper blocking, that is, the number of disk blocks you
10203 put together as a single tape block on the tape, without intervening
10204 tape gaps. A @dfn{tape gap} is a small landing area on the tape
10205 with no information on it, used for decelerating the tape to a
10206 full stop, and for later regaining the reading or writing speed.
10207 When the tape driver starts reading a record, the record has to
10208 be read whole without stopping, as a tape gap is needed to stop the
10209 tape motion without loosing information.
10210
10211 @cindex Exabyte blocking
10212 @cindex DAT blocking
10213 Using higher blocking (putting more disk blocks per tape block) will use
10214 the tape more efficiently as there will be less tape gaps. But reading
10215 such tapes may be more difficult for the system, as more memory will be
10216 required to receive at once the whole record. Further, if there is a
10217 reading error on a huge record, this is less likely that the system will
10218 succeed in recovering the information. So, blocking should not be too
10219 low, nor it should be too high. @command{tar} uses by default a blocking of
10220 20 for historical reasons, and it does not really matter when reading or
10221 writing to disk. Current tape technology would easily accommodate higher
10222 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10223 We were told that for some DLT drives, the blocking should be a multiple
10224 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10225 Other manufacturers may use different recommendations for the same tapes.
10226 This might also depends of the buffering techniques used inside modern
10227 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
10228 Others request blocking to be some exponent of two.
10229
10230 So, there is no fixed rule for blocking. But blocking at read time
10231 should ideally be the same as blocking used at write time. At one place
10232 I know, with a wide variety of equipment, they found it best to use a
10233 blocking of 32 to guarantee that their tapes are fully interchangeable.
10234
10235 I was also told that, for recycled tapes, prior erasure (by the same
10236 drive unit that will be used to create the archives) sometimes lowers
10237 the error rates observed at rewriting time.
10238
10239 I might also use @option{--number-blocks} instead of
10240 @option{--block-number}, so @option{--block} will then expand to
10241 @option{--blocking-factor} unambiguously.
10242
10243 @node Many
10244 @section Many Archives on One Tape
10245
10246 @FIXME{Appropriate options should be moved here from elsewhere.}
10247
10248 @findex ntape @r{device}
10249 Most tape devices have two entries in the @file{/dev} directory, or
10250 entries that come in pairs, which differ only in the minor number for
10251 this device. Let's take for example @file{/dev/tape}, which often
10252 points to the only or usual tape device of a given system. There might
10253 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
10254 name is the @emph{rewinding} version of the device, while the name
10255 having @samp{nr} in it is the @emph{no rewinding} version of the same
10256 device.
10257
10258 A rewinding tape device will bring back the tape to its beginning point
10259 automatically when this device is opened or closed. Since @command{tar}
10260 opens the archive file before using it and closes it afterwards, this
10261 means that a simple:
10262
10263 @smallexample
10264 $ @kbd{tar cf /dev/tape @var{directory}}
10265 @end smallexample
10266
10267 @noindent
10268 will reposition the tape to its beginning both prior and after saving
10269 @var{directory} contents to it, thus erasing prior tape contents and
10270 making it so that any subsequent write operation will destroy what has
10271 just been saved.
10272
10273 @cindex tape positioning
10274 So, a rewinding device is normally meant to hold one and only one file.
10275 If you want to put more than one @command{tar} archive on a given tape, you
10276 will need to avoid using the rewinding version of the tape device. You
10277 will also have to pay special attention to tape positioning. Errors in
10278 positioning may overwrite the valuable data already on your tape. Many
10279 people, burnt by past experiences, will only use rewinding devices and
10280 limit themselves to one file per tape, precisely to avoid the risk of
10281 such errors. Be fully aware that writing at the wrong position on a
10282 tape loses all information past this point and most probably until the
10283 end of the tape, and this destroyed information @emph{cannot} be
10284 recovered.
10285
10286 To save @var{directory-1} as a first archive at the beginning of a
10287 tape, and leave that tape ready for a second archive, you should use:
10288
10289 @smallexample
10290 $ @kbd{mt -f /dev/nrtape rewind}
10291 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
10292 @end smallexample
10293
10294 @cindex tape marks
10295 @dfn{Tape marks} are special magnetic patterns written on the tape
10296 media, which are later recognizable by the reading hardware. These
10297 marks are used after each file, when there are many on a single tape.
10298 An empty file (that is to say, two tape marks in a row) signal the
10299 logical end of the tape, after which no file exist. Usually,
10300 non-rewinding tape device drivers will react to the close request issued
10301 by @command{tar} by first writing two tape marks after your archive, and by
10302 backspacing over one of these. So, if you remove the tape at that time
10303 from the tape drive, it is properly terminated. But if you write
10304 another file at the current position, the second tape mark will be
10305 erased by the new information, leaving only one tape mark between files.
10306
10307 So, you may now save @var{directory-2} as a second archive after the
10308 first on the same tape by issuing the command:
10309
10310 @smallexample
10311 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
10312 @end smallexample
10313
10314 @noindent
10315 and so on for all the archives you want to put on the same tape.
10316
10317 Another usual case is that you do not write all the archives the same
10318 day, and you need to remove and store the tape between two archive
10319 sessions. In general, you must remember how many files are already
10320 saved on your tape. Suppose your tape already has 16 files on it, and
10321 that you are ready to write the 17th. You have to take care of skipping
10322 the first 16 tape marks before saving @var{directory-17}, say, by using
10323 these commands:
10324
10325 @smallexample
10326 $ @kbd{mt -f /dev/nrtape rewind}
10327 $ @kbd{mt -f /dev/nrtape fsf 16}
10328 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
10329 @end smallexample
10330
10331 In all the previous examples, we put aside blocking considerations, but
10332 you should do the proper things for that as well. @xref{Blocking}.
10333
10334 @menu
10335 * Tape Positioning:: Tape Positions and Tape Marks
10336 * mt:: The @command{mt} Utility
10337 @end menu
10338
10339 @node Tape Positioning
10340 @subsection Tape Positions and Tape Marks
10341 @UNREVISED
10342
10343 Just as archives can store more than one file from the file system,
10344 tapes can store more than one archive file. To keep track of where
10345 archive files (or any other type of file stored on tape) begin and
10346 end, tape archive devices write magnetic @dfn{tape marks} on the
10347 archive media. Tape drives write one tape mark between files,
10348 two at the end of all the file entries.
10349
10350 If you think of data as a series of records "rrrr"'s, and tape marks as
10351 "*"'s, a tape might look like the following:
10352
10353 @smallexample
10354 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
10355 @end smallexample
10356
10357 Tape devices read and write tapes using a read/write @dfn{tape
10358 head}---a physical part of the device which can only access one
10359 point on the tape at a time. When you use @command{tar} to read or
10360 write archive data from a tape device, the device will begin reading
10361 or writing from wherever on the tape the tape head happens to be,
10362 regardless of which archive or what part of the archive the tape
10363 head is on. Before writing an archive, you should make sure that no
10364 data on the tape will be overwritten (unless it is no longer needed).
10365 Before reading an archive, you should make sure the tape head is at
10366 the beginning of the archive you want to read. You can do it manually
10367 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
10368 that automatically (@pxref{Scripted Restoration}).
10369
10370 If you want to add new archive file entries to a tape, you should
10371 advance the tape to the end of the existing file entries, backspace
10372 over the last tape mark, and write the new archive file. If you were
10373 to add two archives to the example above, the tape might look like the
10374 following:
10375
10376 @smallexample
10377 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
10378 @end smallexample
10379
10380 @node mt
10381 @subsection The @command{mt} Utility
10382 @UNREVISED
10383
10384 @FIXME{Is it true that this only works on non-block devices?
10385 should explain the difference, (fixed or variable).}
10386 @xref{Blocking Factor}.
10387
10388 You can use the @command{mt} utility to advance or rewind a tape past a
10389 specified number of archive files on the tape. This will allow you
10390 to move to the beginning of an archive before extracting or reading
10391 it, or to the end of all the archives before writing a new one.
10392 @FIXME{Why isn't there an "advance 'til you find two tape marks
10393 together"?}
10394
10395 The syntax of the @command{mt} command is:
10396
10397 @smallexample
10398 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
10399 @end smallexample
10400
10401 where @var{tapename} is the name of the tape device, @var{number} is
10402 the number of times an operation is performed (with a default of one),
10403 and @var{operation} is one of the following:
10404
10405 @FIXME{is there any use for record operations?}
10406
10407 @table @option
10408 @item eof
10409 @itemx weof
10410 Writes @var{number} tape marks at the current position on the tape.
10411
10412 @item fsf
10413 Moves tape position forward @var{number} files.
10414
10415 @item bsf
10416 Moves tape position back @var{number} files.
10417
10418 @item rewind
10419 Rewinds the tape. (Ignores @var{number}).
10420
10421 @item offline
10422 @itemx rewoff1
10423 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
10424
10425 @item status
10426 Prints status information about the tape unit.
10427
10428 @end table
10429
10430 @FIXME{Is there a better way to frob the spacing on the list?}
10431
10432 If you don't specify a @var{tapename}, @command{mt} uses the environment
10433 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
10434 the default device specified in your @file{sys/mtio.h} file
10435 (@code{DEFTAPE} variable). If this is not defined, the program will
10436 display a descriptive error message and exit with code 1.
10437
10438 @command{mt} returns a 0 exit status when the operation(s) were
10439 successful, 1 if the command was unrecognized, and 2 if an operation
10440 failed.
10441
10442 @node Using Multiple Tapes
10443 @section Using Multiple Tapes
10444
10445 Often you might want to write a large archive, one larger than will fit
10446 on the actual tape you are using. In such a case, you can run multiple
10447 @command{tar} commands, but this can be inconvenient, particularly if you
10448 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
10449 Therefore, @command{tar} provides a special mode for creating
10450 multi-volume archives.
10451
10452 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
10453 on several media volumes of fixed size. Although in this section we will
10454 often call @samp{volume} a @dfn{tape}, there is absolutely no
10455 requirement for multi-volume archives to be stored on tapes. Instead,
10456 they can use whatever media type the user finds convenient, they can
10457 even be located on files.
10458
10459 When creating a multi-volume archive, @GNUTAR{} continues to fill
10460 current volume until it runs out of space, then it switches to
10461 next volume (usually the operator is queried to replace the tape on
10462 this point), and continues working on the new volume. This operation
10463 continues until all requested files are dumped. If @GNUTAR{} detects
10464 end of media while dumping a file, such a file is archived in split
10465 form. Some very big files can even be split across several volumes.
10466
10467 Each volume is itself a valid @GNUTAR{} archive, so it can be read
10468 without any special options. Consequently any file member residing
10469 entirely on one volume can be extracted or otherwise operated upon
10470 without needing the other volume. Sure enough, to extract a split
10471 member you would need all volumes its parts reside on.
10472
10473 Multi-volume archives suffer from several limitations. In particular,
10474 they cannot be compressed.
10475
10476 @GNUTAR{} is able to create multi-volume archives of two formats
10477 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
10478
10479 @menu
10480 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
10481 * Tape Files:: Tape Files
10482 * Tarcat:: Concatenate Volumes into a Single Archive
10483
10484 @end menu
10485
10486 @node Multi-Volume Archives
10487 @subsection Archives Longer than One Tape or Disk
10488 @cindex Multi-volume archives
10489
10490 @opindex multi-volume
10491 To create an archive that is larger than will fit on a single unit of
10492 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
10493 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
10494 archive can be manipulated like any other archive (provided the
10495 @option{--multi-volume} option is specified), but is stored on more
10496 than one tape or disk.
10497
10498 When you specify @option{--multi-volume}, @command{tar} does not report an
10499 error when it comes to the end of an archive volume (when reading), or
10500 the end of the media (when writing). Instead, it prompts you to load
10501 a new storage volume. If the archive is on a magnetic tape, you
10502 should change tapes when you see the prompt; if the archive is on a
10503 floppy disk, you should change disks; etc.
10504
10505 @table @option
10506 @item --multi-volume
10507 @itemx -M
10508 Creates a multi-volume archive, when used in conjunction with
10509 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
10510 archive, specify @option{--multi-volume} in conjunction with that
10511 operation.
10512 For example:
10513
10514 @smallexample
10515 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
10516 @end smallexample
10517 @end table
10518
10519 The method @command{tar} uses to detect end of tape is not perfect, and
10520 fails on some operating systems or on some devices. If @command{tar}
10521 cannot detect the end of the tape itself, you can use
10522 @option{--tape-length} option to inform it about the capacity of the
10523 tape:
10524
10525 @anchor{tape-length}
10526 @table @option
10527 @opindex tape-length
10528 @item --tape-length=@var{size}
10529 @itemx -L @var{size}
10530 Set maximum length of a volume. The @var{size} argument should then
10531 be the usable size of the tape in units of 1024 bytes. This option
10532 selects @option{--multi-volume} automatically. For example:
10533
10534 @smallexample
10535 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
10536 @end smallexample
10537 @end table
10538
10539 @anchor{change volume prompt}
10540 When @GNUTAR{} comes to the end of a storage media, it asks you to
10541 change the volume. The built-in prompt for POSIX locale
10542 is@footnote{If you run @GNUTAR{} under a different locale, the
10543 translation to the locale's language will be used.}:
10544
10545 @smallexample
10546 Prepare volume #@var{n} for `@var{archive}' and hit return:
10547 @end smallexample
10548
10549 @noindent
10550 where @var{n} is the ordinal number of the volume to be created and
10551 @var{archive} is archive file or device name.
10552
10553 When prompting for a new tape, @command{tar} accepts any of the following
10554 responses:
10555
10556 @table @kbd
10557 @item ?
10558 Request @command{tar} to explain possible responses
10559 @item q
10560 Request @command{tar} to exit immediately.
10561 @item n @var{file-name}
10562 Request @command{tar} to write the next volume on the file @var{file-name}.
10563 @item !
10564 Request @command{tar} to run a subshell. This option can be disabled
10565 by giving @option{--restrict} command line option to
10566 @command{tar}@footnote{@xref{--restrict}, for more information about
10567 this option}.
10568 @item y
10569 Request @command{tar} to begin writing the next volume.
10570 @end table
10571
10572 (You should only type @samp{y} after you have changed the tape;
10573 otherwise @command{tar} will write over the volume it just finished.)
10574
10575 @cindex Volume number file
10576 @cindex volno file
10577 @anchor{volno-file}
10578 @opindex volno-file
10579 The volume number used by @command{tar} in its tape-changing prompt
10580 can be changed; if you give the
10581 @option{--volno-file=@var{file-of-number}} option, then
10582 @var{file-of-number} should be an non-existing file to be created, or
10583 else, a file already containing a decimal number. That number will be
10584 used as the volume number of the first volume written. When
10585 @command{tar} is finished, it will rewrite the file with the
10586 now-current volume number. (This does not change the volume number
10587 written on a tape label, as per @ref{label}, it @emph{only} affects
10588 the number used in the prompt.)
10589
10590 @cindex End-of-archive info script
10591 @cindex Info script
10592 @anchor{info-script}
10593 @opindex info-script
10594 @opindex new-volume-script
10595 If you want more elaborate behavior than this, you can write a special
10596 @dfn{new volume script}, that will be responsible for changing the
10597 volume, and instruct @command{tar} to use it instead of its normal
10598 prompting procedure:
10599
10600 @table @option
10601 @item --info-script=@var{script-name}
10602 @itemx --new-volume-script=@var{script-name}
10603 @itemx -F @var{script-name}
10604 Specify the full name of the volume script to use. The script can be
10605 used to eject cassettes, or to broadcast messages such as
10606 @samp{Someone please come change my tape} when performing unattended
10607 backups.
10608 @end table
10609
10610 The @var{script-name} is executed without any command line
10611 arguments. It inherits @command{tar}'s shell environment.
10612 Additional data is passed to it via the following
10613 environment variables:
10614
10615 @table @env
10616 @vrindex TAR_VERSION, info script environment variable
10617 @item TAR_VERSION
10618 @GNUTAR{} version number.
10619
10620 @vrindex TAR_ARCHIVE, info script environment variable
10621 @item TAR_ARCHIVE
10622 The name of the archive @command{tar} is processing.
10623
10624 @vrindex TAR_VOLUME, info script environment variable
10625 @item TAR_VOLUME
10626 Ordinal number of the volume @command{tar} is about to start.
10627
10628 @vrindex TAR_SUBCOMMAND, info script environment variable
10629 @item TAR_SUBCOMMAND
10630 A short option describing the operation @command{tar} is executing
10631 @xref{Operations}, for a complete list of subcommand options.
10632
10633 @vrindex TAR_FORMAT, info script environment variable
10634 @item TAR_FORMAT
10635 Format of the archive being processed. @xref{Formats}, for a complete
10636 list of archive format names.
10637
10638 @vrindex TAR_FD, info script environment variable
10639 @item TAR_FD
10640 File descriptor which can be used to communicate the new volume
10641 name to @command{tar}.
10642 @end table
10643
10644 The volume script can instruct @command{tar} to use new archive name,
10645 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
10646
10647 If the info script fails, @command{tar} exits; otherwise, it begins
10648 writing the next volume.
10649
10650 If you want @command{tar} to cycle through a series of files or tape
10651 drives, there are three approaches to choose from. First of all, you
10652 can give @command{tar} multiple @option{--file} options. In this case
10653 the specified files will be used, in sequence, as the successive
10654 volumes of the archive. Only when the first one in the sequence needs
10655 to be used again will @command{tar} prompt for a tape change (or run
10656 the info script). For example, suppose someone has two tape drives on
10657 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10658 @GNUTAR{} to switch to the second drive when it needs to write the
10659 second tape, and then back to the first tape, etc., just do either of:
10660
10661 @smallexample
10662 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10663 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10664 @end smallexample
10665
10666 The second method is to use the @samp{n} response to the tape-change
10667 prompt.
10668
10669 Finally, the most flexible approach is to use a volume script, that
10670 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
10671 following volume script will create a series of archive files, named
10672 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10673 archive being created (as given by @option{--file} option) and
10674 @var{vol} is the ordinal number of the archive being created:
10675
10676 @smallexample
10677 @group
10678 #! /bin/sh
10679 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10680
10681 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10682 case $TAR_SUBCOMMAND in
10683 -c) ;;
10684 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10685 ;;
10686 *) exit 1
10687 esac
10688
10689 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
10690 @end group
10691 @end smallexample
10692
10693 The same script can be used while listing, comparing or extracting
10694 from the created archive. For example:
10695
10696 @smallexample
10697 @group
10698 # @r{Create a multi-volume archive:}
10699 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10700 # @r{Extract from the created archive:}
10701 $ @kbd{tar -x -f archive.tar -F new-volume .}
10702 @end group
10703 @end smallexample
10704
10705 @noindent
10706 Notice, that the first command had to use @option{-L} option, since
10707 otherwise @GNUTAR{} will end up writing everything to file
10708 @file{archive.tar}.
10709
10710 You can read each individual volume of a multi-volume archive as if it
10711 were an archive by itself. For example, to list the contents of one
10712 volume, use @option{--list}, without @option{--multi-volume} specified.
10713 To extract an archive member from one volume (assuming it is described
10714 that volume), use @option{--extract}, again without
10715 @option{--multi-volume}.
10716
10717 If an archive member is split across volumes (i.e., its entry begins on
10718 one volume of the media and ends on another), you need to specify
10719 @option{--multi-volume} to extract it successfully. In this case, you
10720 should load the volume where the archive member starts, and use
10721 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10722 volumes as it needs them. @xref{extracting archives}, for more
10723 information about extracting archives.
10724
10725 Multi-volume archives can be modified like any other archive. To add
10726 files to a multi-volume archive, you need to only mount the last
10727 volume of the archive media (and new volumes, if needed). For all
10728 other operations, you need to use the entire archive.
10729
10730 If a multi-volume archive was labeled using
10731 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10732 created, @command{tar} will not automatically label volumes which are
10733 added later. To label subsequent volumes, specify
10734 @option{--label=@var{archive-label}} again in conjunction with the
10735 @option{--append}, @option{--update} or @option{--concatenate} operation.
10736
10737 Notice that multi-volume support is a GNU extension and the archives
10738 created in this mode should be read only using @GNUTAR{}. If you
10739 absolutely have to process such archives using a third-party @command{tar}
10740 implementation, read @ref{Split Recovery}.
10741
10742 @node Tape Files
10743 @subsection Tape Files
10744 @UNREVISED
10745
10746 To give the archive a name which will be recorded in it, use the
10747 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10748 option. This will write a special block identifying
10749 @var{volume-label} as the name of the archive to the front of the
10750 archive which will be displayed when the archive is listed with
10751 @option{--list}. If you are creating a multi-volume archive with
10752 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10753 volume label will have @samp{Volume @var{nnn}} appended to the name
10754 you give, where @var{nnn} is the number of the volume of the archive.
10755 (If you use the @option{--label=@var{volume-label}}) option when
10756 reading an archive, it checks to make sure the label on the tape
10757 matches the one you give. @xref{label}.
10758
10759 When @command{tar} writes an archive to tape, it creates a single
10760 tape file. If multiple archives are written to the same tape, one
10761 after the other, they each get written as separate tape files. When
10762 extracting, it is necessary to position the tape at the right place
10763 before running @command{tar}. To do this, use the @command{mt} command.
10764 For more information on the @command{mt} command and on the organization
10765 of tapes into a sequence of tape files, see @ref{mt}.
10766
10767 People seem to often do:
10768
10769 @smallexample
10770 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10771 @end smallexample
10772
10773 or such, for pushing a common date in all volumes or an archive set.
10774
10775 @node Tarcat
10776 @subsection Concatenate Volumes into a Single Archive
10777
10778 @pindex tarcat
10779 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10780 archive to a single @command{tar} archive. Simply concatenating all
10781 volumes into one will not work, since each volume carries an additional
10782 information at the beginning. @GNUTAR{} is shipped with the shell
10783 script @command{tarcat} designed for this purpose.
10784
10785 The script takes a list of files comprising a multi-volume archive
10786 and creates the resulting archive at the standard output. For example:
10787
10788 @smallexample
10789 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10790 @end smallexample
10791
10792 The script implements a simple heuristics to determine the format of
10793 the first volume file and to decide how to process the rest of the
10794 files. However, it makes no attempt to verify whether the files are
10795 given in order or even if they are valid @command{tar} archives.
10796 It uses @command{dd} and does not filter its standard error, so you
10797 will usually see lots of spurious messages.
10798
10799 @FIXME{The script is not installed. Should we install it?}
10800
10801 @node label
10802 @section Including a Label in the Archive
10803 @cindex Labeling an archive
10804 @cindex Labels on the archive media
10805 @cindex Labeling multi-volume archives
10806 @UNREVISED
10807
10808 @opindex label
10809 To avoid problems caused by misplaced paper labels on the archive
10810 media, you can include a @dfn{label} entry---an archive member which
10811 contains the name of the archive---in the archive itself. Use the
10812 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10813 option in conjunction with the @option{--create} operation to include
10814 a label entry in the archive as it is being created.
10815
10816 @table @option
10817 @item --label=@var{archive-label}
10818 @itemx -V @var{archive-label}
10819 Includes an @dfn{archive-label} at the beginning of the archive when
10820 the archive is being created, when used in conjunction with the
10821 @option{--create} operation. Checks to make sure the archive label
10822 matches the one specified (when used in conjunction with any other
10823 operation.
10824 @end table
10825
10826 If you create an archive using both
10827 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10828 and @option{--multi-volume} (@option{-M}), each volume of the archive
10829 will have an archive label of the form @samp{@var{archive-label}
10830 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10831 next, and so on. @xref{Using Multiple Tapes}, for information on
10832 creating multiple volume archives.
10833
10834 @cindex Volume label, listing
10835 @cindex Listing volume label
10836 The volume label will be displayed by @option{--list} along with
10837 the file contents. If verbose display is requested, it will also be
10838 explicitly marked as in the example below:
10839
10840 @smallexample
10841 @group
10842 $ @kbd{tar --verbose --list --file=iamanarchive}
10843 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10844 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10845 @end group
10846 @end smallexample
10847
10848 @opindex test-label
10849 @anchor{--test-label option}
10850 However, @option{--list} option will cause listing entire
10851 contents of the archive, which may be undesirable (for example, if the
10852 archive is stored on a tape). You can request checking only the volume
10853 by specifying @option{--test-label} option. This option reads only the
10854 first block of an archive, so it can be used with slow storage
10855 devices. For example:
10856
10857 @smallexample
10858 @group
10859 $ @kbd{tar --test-label --file=iamanarchive}
10860 iamalabel
10861 @end group
10862 @end smallexample
10863
10864 If @option{--test-label} is used with a single command line
10865 argument, @command{tar} compares the volume label with the
10866 argument. It exits with code 0 if the two strings match, and with code
10867 2 otherwise. In this case no output is displayed. For example:
10868
10869 @smallexample
10870 @group
10871 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10872 @result{} 0
10873 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10874 @result{} 1
10875 @end group
10876 @end smallexample
10877
10878 If you request any operation, other than @option{--create}, along
10879 with using @option{--label} option, @command{tar} will first check if
10880 the archive label matches the one specified and will refuse to proceed
10881 if it does not. Use this as a safety precaution to avoid accidentally
10882 overwriting existing archives. For example, if you wish to add files
10883 to @file{archive}, presumably labeled with string @samp{My volume},
10884 you will get:
10885
10886 @smallexample
10887 @group
10888 $ @kbd{tar -rf archive --label 'My volume' .}
10889 tar: Archive not labeled to match `My volume'
10890 @end group
10891 @end smallexample
10892
10893 @noindent
10894 in case its label does not match. This will work even if
10895 @file{archive} is not labeled at all.
10896
10897 Similarly, @command{tar} will refuse to list or extract the
10898 archive if its label doesn't match the @var{archive-label}
10899 specified. In those cases, @var{archive-label} argument is interpreted
10900 as a globbing-style pattern which must match the actual magnetic
10901 volume label. @xref{exclude}, for a precise description of how match
10902 is attempted@footnote{Previous versions of @command{tar} used full
10903 regular expression matching, or before that, only exact string
10904 matching, instead of wildcard matchers. We decided for the sake of
10905 simplicity to use a uniform matching device through
10906 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10907 the volume label matcher will also suffix @var{archive-label} by
10908 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10909 up. Since the volume numbering is automatically added in labels at
10910 creation time, it sounded logical to equally help the user taking care
10911 of it when the archive is being read.
10912
10913 The @option{--label} was once called @option{--volume}, but is not
10914 available under that name anymore.
10915
10916 You can also use @option{--label} to get a common information on
10917 all tapes of a series. For having this information different in each
10918 series created through a single script used on a regular basis, just
10919 manage to get some date string as part of the label. For example:
10920
10921 @smallexample
10922 @group
10923 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10924 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10925 --volume="Daily backup for `date +%Y-%m-%d`"}
10926 @end group
10927 @end smallexample
10928
10929 Also note that each label has its own date and time, which corresponds
10930 to when @GNUTAR{} initially attempted to write it,
10931 often soon after the operator launches @command{tar} or types the
10932 carriage return telling that the next tape is ready. Comparing date
10933 labels does give an idea of tape throughput only if the delays for
10934 rewinding tapes and the operator switching them were negligible, which
10935 is usually not the case.
10936
10937 @node verify
10938 @section Verifying Data as It is Stored
10939 @cindex Verifying a write operation
10940 @cindex Double-checking a write operation
10941
10942 @table @option
10943 @item -W
10944 @itemx --verify
10945 @opindex verify, short description
10946 Attempt to verify the archive after writing.
10947 @end table
10948
10949 This option causes @command{tar} to verify the archive after writing it.
10950 Each volume is checked after it is written, and any discrepancies
10951 are recorded on the standard error output.
10952
10953 Verification requires that the archive be on a back-space-able medium.
10954 This means pipes, some cartridge tape drives, and some other devices
10955 cannot be verified.
10956
10957 You can insure the accuracy of an archive by comparing files in the
10958 system with archive members. @command{tar} can compare an archive to the
10959 file system as the archive is being written, to verify a write
10960 operation, or can compare a previously written archive, to insure that
10961 it is up to date.
10962
10963 @xopindex{verify, using with @option{--create}}
10964 @xopindex{create, using with @option{--verify}}
10965 To check for discrepancies in an archive immediately after it is
10966 written, use the @option{--verify} (@option{-W}) option in conjunction with
10967 the @option{--create} operation. When this option is
10968 specified, @command{tar} checks archive members against their counterparts
10969 in the file system, and reports discrepancies on the standard error.
10970
10971 To verify an archive, you must be able to read it from before the end
10972 of the last written entry. This option is useful for detecting data
10973 errors on some tapes. Archives written to pipes, some cartridge tape
10974 drives, and some other devices cannot be verified.
10975
10976 One can explicitly compare an already made archive with the file
10977 system by using the @option{--compare} (@option{--diff}, @option{-d})
10978 option, instead of using the more automatic @option{--verify} option.
10979 @xref{compare}.
10980
10981 Note that these two options have a slightly different intent. The
10982 @option{--compare} option checks how identical are the logical contents of some
10983 archive with what is on your disks, while the @option{--verify} option is
10984 really for checking if the physical contents agree and if the recording
10985 media itself is of dependable quality. So, for the @option{--verify}
10986 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10987 the archive, while it lets the speed optimization undisturbed for the
10988 @option{--compare} option. If you nevertheless use @option{--compare} for
10989 media verification, you may have to defeat the in-memory cache yourself,
10990 maybe by opening and reclosing the door latch of your recording unit,
10991 forcing some doubt in your operating system about the fact this is really
10992 the same volume as the one just written or read.
10993
10994 The @option{--verify} option would not be necessary if drivers were indeed
10995 able to detect dependably all write failures. This sometimes require many
10996 magnetic heads, some able to read after the writes occurred. One would
10997 not say that drivers unable to detect all cases are necessarily flawed,
10998 as long as programming is concerned.
10999
11000 The @option{--verify} (@option{-W}) option will not work in
11001 conjunction with the @option{--multi-volume} (@option{-M}) option or
11002 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11003 and @option{--delete} operations. @xref{Operations}, for more
11004 information on these operations.
11005
11006 Also, since @command{tar} normally strips leading @samp{/} from file
11007 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11008 /tmp/foo.tar /etc} will work as desired only if the working directory is
11009 @file{/}, as @command{tar} uses the archive's relative member names
11010 (e.g., @file{etc/motd}) when verifying the archive.
11011
11012 @node Write Protection
11013 @section Write Protection
11014
11015 Almost all tapes and diskettes, and in a few rare cases, even disks can
11016 be @dfn{write protected}, to protect data on them from being changed.
11017 Once an archive is written, you should write protect the media to prevent
11018 the archive from being accidentally overwritten or deleted. (This will
11019 protect the archive from being changed with a tape or floppy drive---it
11020 will not protect it from magnet fields or other physical hazards).
11021
11022 The write protection device itself is usually an integral part of the
11023 physical media, and can be a two position (write enabled/write
11024 disabled) switch, a notch which can be popped out or covered, a ring
11025 which can be removed from the center of a tape reel, or some other
11026 changeable feature.
11027
11028 @node Changes
11029 @appendix Changes
11030
11031 This appendix lists some important user-visible changes between
11032 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
11033 version of this document is available at
11034 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
11035 @GNUTAR{} documentation page}.
11036
11037 @table @asis
11038 @item Use of globbing patterns when listing and extracting.
11039
11040 Previous versions of GNU tar assumed shell-style globbing when
11041 extracting from or listing an archive. For example:
11042
11043 @smallexample
11044 $ @kbd{tar xf foo.tar '*.c'}
11045 @end smallexample
11046
11047 would extract all files whose names end in @samp{.c}. This behavior
11048 was not documented and was incompatible with traditional tar
11049 implementations. Therefore, starting from version 1.15.91, GNU tar
11050 no longer uses globbing by default. For example, the above invocation
11051 is now interpreted as a request to extract from the archive the file
11052 named @file{*.c}.
11053
11054 To facilitate transition to the new behavior for those users who got
11055 used to the previous incorrect one, @command{tar} will print a warning
11056 if it finds out that a requested member was not found in the archive
11057 and its name looks like a globbing pattern. For example:
11058
11059 @smallexample
11060 $ @kbd{tar xf foo.tar '*.c'}
11061 tar: Pattern matching characters used in file names. Please,
11062 tar: use --wildcards to enable pattern matching, or --no-wildcards to
11063 tar: suppress this warning.
11064 tar: *.c: Not found in archive
11065 tar: Error exit delayed from previous errors
11066 @end smallexample
11067
11068 To treat member names as globbing patterns, use --wildcards option.
11069 If you want to tar to mimic the behavior of versions prior to 1.15.91,
11070 add this option to your @env{TAR_OPTIONS} variable.
11071
11072 @xref{wildcards}, for the detailed discussion of the use of globbing
11073 patterns by @GNUTAR{}.
11074
11075 @item Use of short option @option{-o}.
11076
11077 Earlier versions of @GNUTAR{} understood @option{-o} command line
11078 option as a synonym for @option{--old-archive}.
11079
11080 @GNUTAR{} starting from version 1.13.90 understands this option as
11081 a synonym for @option{--no-same-owner}. This is compatible with
11082 UNIX98 @command{tar} implementations.
11083
11084 However, to facilitate transition, @option{-o} option retains its
11085 old semantics when it is used with one of archive-creation commands.
11086 Users are encouraged to use @option{--format=oldgnu} instead.
11087
11088 It is especially important, since versions of @acronym{GNU} Automake
11089 up to and including 1.8.4 invoke tar with this option to produce
11090 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
11091 of this issue and its implications.
11092
11093 @FIXME{Change the first argument to tar-formats when the new Automake is
11094 out. The proposition to add @anchor{} to the appropriate place of its
11095 docs was accepted by Automake people --Sergey 2006-05-25}.
11096 @xref{Options, tar-v7, Changing Automake's Behavior,
11097 automake, GNU Automake}, for a description on how to use various
11098 archive formats with @command{automake}.
11099
11100 Future versions of @GNUTAR{} will understand @option{-o} only as a
11101 synonym for @option{--no-same-owner}.
11102
11103 @item Use of short option @option{-l}
11104
11105 Earlier versions of @GNUTAR{} understood @option{-l} option as a
11106 synonym for @option{--one-file-system}. Since such usage contradicted
11107 to UNIX98 specification and harmed compatibility with other
11108 implementation, it was declared deprecated in version 1.14. However,
11109 to facilitate transition to its new semantics, it was supported by
11110 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
11111 variant of @option{--check-links} was introduced in version 1.15.91.
11112
11113 @item Use of options @option{--portability} and @option{--old-archive}
11114
11115 These options are deprecated. Please use @option{--format=v7} instead.
11116
11117 @item Use of option @option{--posix}
11118
11119 This option is deprecated. Please use @option{--format=posix} instead.
11120 @end table
11121
11122 @node Configuring Help Summary
11123 @appendix Configuring Help Summary
11124
11125 Running @kbd{tar --help} displays the short @command{tar} option
11126 summary (@pxref{help}). This summary is organized by @dfn{groups} of
11127 semantically close options. The options within each group are printed
11128 in the following order: a short option, eventually followed by a list
11129 of corresponding long option names, followed by a short description of
11130 the option. For example, here is an excerpt from the actual @kbd{tar
11131 --help} output:
11132
11133 @verbatim
11134 Main operation mode:
11135
11136 -A, --catenate, --concatenate append tar files to an archive
11137 -c, --create create a new archive
11138 -d, --diff, --compare find differences between archive and
11139 file system
11140 --delete delete from the archive
11141 @end verbatim
11142
11143 @vrindex ARGP_HELP_FMT, environment variable
11144 The exact visual representation of the help output is configurable via
11145 @env{ARGP_HELP_FMT} environment variable. The value of this variable
11146 is a comma-separated list of @dfn{format variable} assignments. There
11147 are two kinds of format variables. An @dfn{offset variable} keeps the
11148 offset of some part of help output text from the leftmost column on
11149 the screen. A @dfn{boolean} variable is a flag that toggles some
11150 output feature on or off. Depending on the type of the corresponding
11151 variable, there are two kinds of assignments:
11152
11153 @table @asis
11154 @item Offset assignment
11155
11156 The assignment to an offset variable has the following syntax:
11157
11158 @smallexample
11159 @var{variable}=@var{value}
11160 @end smallexample
11161
11162 @noindent
11163 where @var{variable} is the variable name, and @var{value} is a
11164 numeric value to be assigned to the variable.
11165
11166 @item Boolean assignment
11167
11168 To assign @code{true} value to a variable, simply put this variable name. To
11169 assign @code{false} value, prefix the variable name with @samp{no-}. For
11170 example:
11171
11172 @smallexample
11173 @group
11174 # Assign @code{true} value:
11175 dup-args
11176 # Assign @code{false} value:
11177 no-dup-args
11178 @end group
11179 @end smallexample
11180 @end table
11181
11182 Following variables are declared:
11183
11184 @deftypevr {Help Output} boolean dup-args
11185 If true, arguments for an option are shown with both short and long
11186 options, even when a given option has both forms, for example:
11187
11188 @smallexample
11189 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
11190 @end smallexample
11191
11192 If false, then if an option has both short and long forms, the
11193 argument is only shown with the long one, for example:
11194
11195 @smallexample
11196 -f, --file=ARCHIVE use archive file or device ARCHIVE
11197 @end smallexample
11198
11199 @noindent
11200 and a message indicating that the argument is applicable to both
11201 forms is printed below the options. This message can be disabled
11202 using @code{dup-args-note} (see below).
11203
11204 The default is false.
11205 @end deftypevr
11206
11207 @deftypevr {Help Output} boolean dup-args-note
11208 If this variable is true, which is the default, the following notice
11209 is displayed at the end of the help output:
11210
11211 @quotation
11212 Mandatory or optional arguments to long options are also mandatory or
11213 optional for any corresponding short options.
11214 @end quotation
11215
11216 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
11217 variables @code{dup-args} or @code{dup-args-note} should be set.
11218 @end deftypevr
11219
11220 @deftypevr {Help Output} offset short-opt-col
11221 Column in which short options start. Default is 2.
11222
11223 @smallexample
11224 @group
11225 $ @kbd{tar --help|grep ARCHIVE}
11226 -f, --file=ARCHIVE use archive file or device ARCHIVE
11227 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
11228 -f, --file=ARCHIVE use archive file or device ARCHIVE
11229 @end group
11230 @end smallexample
11231 @end deftypevr
11232
11233 @deftypevr {Help Output} offset long-opt-col
11234 Column in which long options start. Default is 6. For example:
11235
11236 @smallexample
11237 @group
11238 $ @kbd{tar --help|grep ARCHIVE}
11239 -f, --file=ARCHIVE use archive file or device ARCHIVE
11240 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
11241 -f, --file=ARCHIVE use archive file or device ARCHIVE
11242 @end group
11243 @end smallexample
11244 @end deftypevr
11245
11246 @deftypevr {Help Output} offset doc-opt-col
11247 Column in which @dfn{doc options} start. A doc option isn't actually
11248 an option, but rather an arbitrary piece of documentation that is
11249 displayed in much the same manner as the options. For example, in
11250 the description of @option{--format} option:
11251
11252 @smallexample
11253 @group
11254 -H, --format=FORMAT create archive of the given format.
11255
11256 FORMAT is one of the following:
11257
11258 gnu GNU tar 1.13.x format
11259 oldgnu GNU format as per tar <= 1.12
11260 pax POSIX 1003.1-2001 (pax) format
11261 posix same as pax
11262 ustar POSIX 1003.1-1988 (ustar) format
11263 v7 old V7 tar format
11264 @end group
11265 @end smallexample
11266
11267 @noindent
11268 the format names are doc options. Thus, if you set
11269 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
11270 will look as follows:
11271
11272 @smallexample
11273 @group
11274 -H, --format=FORMAT create archive of the given format.
11275
11276 FORMAT is one of the following:
11277
11278 gnu GNU tar 1.13.x format
11279 oldgnu GNU format as per tar <= 1.12
11280 pax POSIX 1003.1-2001 (pax) format
11281 posix same as pax
11282 ustar POSIX 1003.1-1988 (ustar) format
11283 v7 old V7 tar format
11284 @end group
11285 @end smallexample
11286 @end deftypevr
11287
11288 @deftypevr {Help Output} offset opt-doc-col
11289 Column in which option description starts. Default is 29.
11290
11291 @smallexample
11292 @group
11293 $ @kbd{tar --help|grep ARCHIVE}
11294 -f, --file=ARCHIVE use archive file or device ARCHIVE
11295 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
11296 -f, --file=ARCHIVE use archive file or device ARCHIVE
11297 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
11298 -f, --file=ARCHIVE
11299 use archive file or device ARCHIVE
11300 @end group
11301 @end smallexample
11302
11303 @noindent
11304 Notice, that the description starts on a separate line if
11305 @code{opt-doc-col} value is too small.
11306 @end deftypevr
11307
11308 @deftypevr {Help Output} offset header-col
11309 Column in which @dfn{group headers} are printed. A group header is a
11310 descriptive text preceding an option group. For example, in the
11311 following text:
11312
11313 @verbatim
11314 Main operation mode:
11315
11316 -A, --catenate, --concatenate append tar files to
11317 an archive
11318 -c, --create create a new archive
11319 @end verbatim
11320 @noindent
11321 @samp{Main operation mode:} is the group header.
11322
11323 The default value is 1.
11324 @end deftypevr
11325
11326 @deftypevr {Help Output} offset usage-indent
11327 Indentation of wrapped usage lines. Affects @option{--usage}
11328 output. Default is 12.
11329 @end deftypevr
11330
11331 @deftypevr {Help Output} offset rmargin
11332 Right margin of the text output. Used for wrapping.
11333 @end deftypevr
11334
11335 @node Fixing Snapshot Files
11336 @appendix Fixing Snapshot Files
11337 @include tar-snapshot-edit.texi
11338
11339 @node Tar Internals
11340 @appendix Tar Internals
11341 @include intern.texi
11342
11343 @node Genfile
11344 @appendix Genfile
11345 @include genfile.texi
11346
11347 @node Free Software Needs Free Documentation
11348 @appendix Free Software Needs Free Documentation
11349 @include freemanuals.texi
11350
11351 @node Copying This Manual
11352 @appendix Copying This Manual
11353
11354 @menu
11355 * GNU Free Documentation License:: License for copying this manual
11356 @end menu
11357
11358 @include fdl.texi
11359
11360 @node Index of Command Line Options
11361 @appendix Index of Command Line Options
11362
11363 This appendix contains an index of all @GNUTAR{} long command line
11364 options. The options are listed without the preceding double-dash.
11365 For a cross-reference of short command line options, @ref{Short Option Summary}.
11366
11367 @printindex op
11368
11369 @node Index
11370 @appendix Index
11371
11372 @printindex cp
11373
11374 @summarycontents
11375 @contents
11376 @bye
11377
11378 @c Local variables:
11379 @c texinfo-column-for-description: 32
11380 @c End:
This page took 0.495393 seconds and 5 git commands to generate.