]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Update
[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 bell
2464 Produce an audible bell on the console.
2465
2466 @item dot
2467 @itemx .
2468 Print a single dot on the standard listing stream.
2469
2470 @item echo
2471 Display a textual message on the standard error, with the status and
2472 number of the checkpoint. This is the default.
2473
2474 @item echo=@var{string}
2475 Display @var{string} on the standard error. Before output, the string
2476 is subject to meta-character expansion.
2477
2478 @item exec=@var{command}
2479 Execute the given @var{command}.
2480
2481 @item sleep=@var{time}
2482 Wait for @var{time} seconds.
2483
2484 @item ttyout=@var{string}
2485 Output @var{string} on the current console (@file{/dev/tty}).
2486 @end table
2487
2488 Several @option{--checkpoint-action} options can be specified. The
2489 supplied actions will be executed in order of their appearance in the
2490 command line.
2491
2492 Using @option{--checkpoint-action} without @option{--checkpoint}
2493 assumes default checkpoint frequency of one checkpoint per 10 records.
2494
2495 @opsummary{check-links}
2496 @item --check-links
2497 @itemx -l
2498 If this option was given, @command{tar} will check the number of links
2499 dumped for each processed file. If this number does not match the
2500 total number of hard links for the file, a warning message will be
2501 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2502 synonym for @option{--one-file-system}. The current semantics, which
2503 complies to UNIX98, was introduced with version
2504 1.15.91. @xref{Changes}, for more information.}.
2505
2506 @xref{hard links}.
2507
2508 @opsummary{compress}
2509 @opsummary{uncompress}
2510 @item --compress
2511 @itemx --uncompress
2512 @itemx -Z
2513
2514 @command{tar} will use the @command{compress} program when reading or
2515 writing the archive. This allows you to directly act on archives
2516 while saving space. @xref{gzip}.
2517
2518 @opsummary{confirmation}
2519 @item --confirmation
2520
2521 (See @option{--interactive}.) @xref{interactive}.
2522
2523 @opsummary{delay-directory-restore}
2524 @item --delay-directory-restore
2525
2526 Delay setting modification times and permissions of extracted
2527 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2528
2529 @opsummary{dereference}
2530 @item --dereference
2531 @itemx -h
2532
2533 When creating a @command{tar} archive, @command{tar} will archive the
2534 file that a symbolic link points to, rather than archiving the
2535 symlink. @xref{dereference}.
2536
2537 @opsummary{directory}
2538 @item --directory=@var{dir}
2539 @itemx -C @var{dir}
2540
2541 When this option is specified, @command{tar} will change its current directory
2542 to @var{dir} before performing any operations. When this option is used
2543 during archive creation, it is order sensitive. @xref{directory}.
2544
2545 @opsummary{exclude}
2546 @item --exclude=@var{pattern}
2547
2548 When performing operations, @command{tar} will skip files that match
2549 @var{pattern}. @xref{exclude}.
2550
2551 @opsummary{exclude-from}
2552 @item --exclude-from=@var{file}
2553 @itemx -X @var{file}
2554
2555 Similar to @option{--exclude}, except @command{tar} will use the list of
2556 patterns in the file @var{file}. @xref{exclude}.
2557
2558 @opsummary{exclude-caches}
2559 @item --exclude-caches
2560
2561 Exclude from dump any directory containing a valid cache directory
2562 tag file, but still dump the directory node and the tag file itself.
2563
2564 @xref{exclude}.
2565
2566 @opsummary{exclude-caches-under}
2567 @item --exclude-caches-under
2568
2569 Exclude from dump any directory containing a valid cache directory
2570 tag file, but still dump the directory node itself.
2571
2572 @xref{exclude}.
2573
2574 @opsummary{exclude-caches-all}
2575 @item --exclude-caches-all
2576
2577 Exclude from dump any directory containing a valid cache directory
2578 tag file. @xref{exclude}.
2579
2580 @opsummary{exclude-tag}
2581 @item --exclude-tag=@var{file}
2582
2583 Exclude from dump any directory containing file named @var{file}, but
2584 dump the directory node and @var{file} itself. @xref{exclude}.
2585
2586 @opsummary{exclude-tag-under}
2587 @item --exclude-tag-under=@var{file}
2588
2589 Exclude from dump the contents of any directory containing file
2590 named @var{file}, but dump the directory node itself. @xref{exclude}.
2591
2592 @opsummary{exclude-tag-all}
2593 @item --exclude-tag-all=@var{file}
2594
2595 Exclude from dump any directory containing file named @var{file}.
2596 @xref{exclude}.
2597
2598 @opsummary{exclude-vcs}
2599 @item --exclude-vcs
2600
2601 Exclude from dump directories and files, that are internal for some
2602 widely used version control systems.
2603
2604 @xref{exclude}.
2605
2606 @opsummary{file}
2607 @item --file=@var{archive}
2608 @itemx -f @var{archive}
2609
2610 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2611 performs operations on, rather than @command{tar}'s compilation dependent
2612 default. @xref{file tutorial}.
2613
2614 @opsummary{files-from}
2615 @item --files-from=@var{file}
2616 @itemx -T @var{file}
2617
2618 @command{tar} will use the contents of @var{file} as a list of archive members
2619 or files to operate on, in addition to those specified on the
2620 command-line. @xref{files}.
2621
2622 @opsummary{force-local}
2623 @item --force-local
2624
2625 Forces @command{tar} to interpret the file name given to @option{--file}
2626 as a local file, even if it looks like a remote tape drive name.
2627 @xref{local and remote archives}.
2628
2629 @opsummary{format}
2630 @item --format=@var{format}
2631 @itemx -H @var{format}
2632
2633 Selects output archive format. @var{Format} may be one of the
2634 following:
2635
2636 @table @samp
2637 @item v7
2638 Creates an archive that is compatible with Unix V7 @command{tar}.
2639
2640 @item oldgnu
2641 Creates an archive that is compatible with GNU @command{tar} version
2642 1.12 or earlier.
2643
2644 @item gnu
2645 Creates archive in GNU tar 1.13 format. Basically it is the same as
2646 @samp{oldgnu} with the only difference in the way it handles long
2647 numeric fields.
2648
2649 @item ustar
2650 Creates a @acronym{POSIX.1-1988} compatible archive.
2651
2652 @item posix
2653 Creates a @acronym{POSIX.1-2001 archive}.
2654
2655 @end table
2656
2657 @xref{Formats}, for a detailed discussion of these formats.
2658
2659 @opsummary{group}
2660 @item --group=@var{group}
2661
2662 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2663 rather than the group from the source file. @var{group} is first decoded
2664 as a group symbolic name, but if this interpretation fails, it has to be
2665 a decimal numeric group @acronym{ID}. @xref{override}.
2666
2667 Also see the comments for the @option{--owner=@var{user}} option.
2668
2669 @opsummary{gzip}
2670 @opsummary{gunzip}
2671 @opsummary{ungzip}
2672 @item --gzip
2673 @itemx --gunzip
2674 @itemx --ungzip
2675 @itemx -z
2676
2677 This option tells @command{tar} to read or write archives through
2678 @command{gzip}, allowing @command{tar} to directly operate on several
2679 kinds of compressed archives transparently. @xref{gzip}.
2680
2681 @opsummary{hard-dereference}
2682 @item --hard-dereference
2683 When creating an archive, dereference hard links and store the files
2684 they refer to, instead of creating usual hard link members.
2685
2686 @xref{hard links}.
2687
2688 @opsummary{help}
2689 @item --help
2690 @itemx -?
2691
2692 @command{tar} will print out a short message summarizing the operations and
2693 options to @command{tar} and exit. @xref{help}.
2694
2695 @opsummary{ignore-case}
2696 @item --ignore-case
2697 Ignore case when matching member or file names with
2698 patterns. @xref{controlling pattern-matching}.
2699
2700 @opsummary{ignore-command-error}
2701 @item --ignore-command-error
2702 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2703
2704 @opsummary{ignore-failed-read}
2705 @item --ignore-failed-read
2706
2707 Do not exit unsuccessfully merely because an unreadable file was encountered.
2708 @xref{Reading}.
2709
2710 @opsummary{ignore-zeros}
2711 @item --ignore-zeros
2712 @itemx -i
2713
2714 With this option, @command{tar} will ignore zeroed blocks in the
2715 archive, which normally signals EOF. @xref{Reading}.
2716
2717 @opsummary{incremental}
2718 @item --incremental
2719 @itemx -G
2720
2721 Informs @command{tar} that it is working with an old
2722 @acronym{GNU}-format incremental backup archive. It is intended
2723 primarily for backwards compatibility only. @xref{Incremental Dumps},
2724 for a detailed discussion of incremental archives.
2725
2726 @opsummary{index-file}
2727 @item --index-file=@var{file}
2728
2729 Send verbose output to @var{file} instead of to standard output.
2730
2731 @opsummary{info-script}
2732 @opsummary{new-volume-script}
2733 @item --info-script=@var{script-file}
2734 @itemx --new-volume-script=@var{script-file}
2735 @itemx -F @var{script-file}
2736
2737 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2738 at the end of each tape. If @var{script-file} exits with nonzero status,
2739 @command{tar} fails immediately. @xref{info-script}, for a detailed
2740 discussion of @var{script-file}.
2741
2742 @opsummary{interactive}
2743 @item --interactive
2744 @itemx --confirmation
2745 @itemx -w
2746
2747 Specifies that @command{tar} should ask the user for confirmation before
2748 performing potentially destructive options, such as overwriting files.
2749 @xref{interactive}.
2750
2751 @opsummary{keep-newer-files}
2752 @item --keep-newer-files
2753
2754 Do not replace existing files that are newer than their archive copies
2755 when extracting files from an archive.
2756
2757 @opsummary{keep-old-files}
2758 @item --keep-old-files
2759 @itemx -k
2760
2761 Do not overwrite existing files when extracting files from an archive.
2762 @xref{Keep Old Files}.
2763
2764 @opsummary{label}
2765 @item --label=@var{name}
2766 @itemx -V @var{name}
2767
2768 When creating an archive, instructs @command{tar} to write @var{name}
2769 as a name record in the archive. When extracting or listing archives,
2770 @command{tar} will only operate on archives that have a label matching
2771 the pattern specified in @var{name}. @xref{Tape Files}.
2772
2773 @opsummary{listed-incremental}
2774 @item --listed-incremental=@var{snapshot-file}
2775 @itemx -g @var{snapshot-file}
2776
2777 During a @option{--create} operation, specifies that the archive that
2778 @command{tar} creates is a new @acronym{GNU}-format incremental
2779 backup, using @var{snapshot-file} to determine which files to backup.
2780 With other operations, informs @command{tar} that the archive is in
2781 incremental format. @xref{Incremental Dumps}.
2782
2783 @opsummary{lzma}
2784 @item --lzma
2785
2786 This option tells @command{tar} to read or write archives through
2787 @command{lzma}. @xref{gzip}.
2788
2789 @opsummary{mode}
2790 @item --mode=@var{permissions}
2791
2792 When adding files to an archive, @command{tar} will use
2793 @var{permissions} for the archive members, rather than the permissions
2794 from the files. @var{permissions} can be specified either as an octal
2795 number or as symbolic permissions, like with
2796 @command{chmod}. @xref{override}.
2797
2798 @opsummary{mtime}
2799 @item --mtime=@var{date}
2800
2801 When adding files to an archive, @command{tar} will use @var{date} as
2802 the modification time of members when creating archives, instead of
2803 their actual modification times. The value of @var{date} can be
2804 either a textual date representation (@pxref{Date input formats}) or a
2805 name of the existing file, starting with @samp{/} or @samp{.}. In the
2806 latter case, the modification time of that file is used. @xref{override}.
2807
2808 @opsummary{multi-volume}
2809 @item --multi-volume
2810 @itemx -M
2811
2812 Informs @command{tar} that it should create or otherwise operate on a
2813 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2814
2815 @opsummary{new-volume-script}
2816 @item --new-volume-script
2817
2818 (see --info-script)
2819
2820 @opsummary{newer}
2821 @item --newer=@var{date}
2822 @itemx --after-date=@var{date}
2823 @itemx -N
2824
2825 When creating an archive, @command{tar} will only add files that have changed
2826 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2827 is taken to be the name of a file whose data modification time specifies
2828 the date. @xref{after}.
2829
2830 @opsummary{newer-mtime}
2831 @item --newer-mtime=@var{date}
2832
2833 Like @option{--newer}, but add only files whose
2834 contents have changed (as opposed to just @option{--newer}, which will
2835 also back up files for which any status information has
2836 changed). @xref{after}.
2837
2838 @opsummary{no-anchored}
2839 @item --no-anchored
2840 An exclude pattern can match any subsequence of the name's components.
2841 @xref{controlling pattern-matching}.
2842
2843 @opsummary{no-delay-directory-restore}
2844 @item --no-delay-directory-restore
2845
2846 Modification times and permissions of extracted
2847 directories are set when all files from this directory have been
2848 extracted. This is the default.
2849 @xref{Directory Modification Times and Permissions}.
2850
2851 @opsummary{no-ignore-case}
2852 @item --no-ignore-case
2853 Use case-sensitive matching.
2854 @xref{controlling pattern-matching}.
2855
2856 @opsummary{no-ignore-command-error}
2857 @item --no-ignore-command-error
2858 Print warnings about subprocesses that terminated with a nonzero exit
2859 code. @xref{Writing to an External Program}.
2860
2861 @opsummary{no-overwrite-dir}
2862 @item --no-overwrite-dir
2863
2864 Preserve metadata of existing directories when extracting files
2865 from an archive. @xref{Overwrite Old Files}.
2866
2867 @opsummary{no-quote-chars}
2868 @item --no-quote-chars=@var{string}
2869 Remove characters listed in @var{string} from the list of quoted
2870 characters set by the previous @option{--quote-chars} option
2871 (@pxref{quoting styles}).
2872
2873 @opsummary{no-recursion}
2874 @item --no-recursion
2875
2876 With this option, @command{tar} will not recurse into directories.
2877 @xref{recurse}.
2878
2879 @opsummary{no-same-owner}
2880 @item --no-same-owner
2881 @itemx -o
2882
2883 When extracting an archive, do not attempt to preserve the owner
2884 specified in the @command{tar} archive. This the default behavior
2885 for ordinary users.
2886
2887 @opsummary{no-same-permissions}
2888 @item --no-same-permissions
2889
2890 When extracting an archive, subtract the user's umask from files from
2891 the permissions specified in the archive. This is the default behavior
2892 for ordinary users.
2893
2894 @opsummary{no-unquote}
2895 @item --no-unquote
2896 Treat all input file or member names literally, do not interpret
2897 escape sequences. @xref{input name quoting}.
2898
2899 @opsummary{no-wildcards}
2900 @item --no-wildcards
2901 Do not use wildcards.
2902 @xref{controlling pattern-matching}.
2903
2904 @opsummary{no-wildcards-match-slash}
2905 @item --no-wildcards-match-slash
2906 Wildcards do not match @samp{/}.
2907 @xref{controlling pattern-matching}.
2908
2909 @opsummary{null}
2910 @item --null
2911
2912 When @command{tar} is using the @option{--files-from} option, this option
2913 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
2914 @command{tar} can correctly work with file names that contain newlines.
2915 @xref{nul}.
2916
2917 @opsummary{numeric-owner}
2918 @item --numeric-owner
2919
2920 This option will notify @command{tar} that it should use numeric user
2921 and group IDs when creating a @command{tar} file, rather than names.
2922 @xref{Attributes}.
2923
2924 @item -o
2925 The function of this option depends on the action @command{tar} is
2926 performing. When extracting files, @option{-o} is a synonym for
2927 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2928 restoring ownership of files being extracted.
2929
2930 When creating an archive, it is a synonym for
2931 @option{--old-archive}. This behavior is for compatibility
2932 with previous versions of @GNUTAR{}, and will be
2933 removed in future releases.
2934
2935 @xref{Changes}, for more information.
2936
2937 @opsummary{occurrence}
2938 @item --occurrence[=@var{number}]
2939
2940 This option can be used in conjunction with one of the subcommands
2941 @option{--delete}, @option{--diff}, @option{--extract} or
2942 @option{--list} when a list of files is given either on the command
2943 line or via @option{-T} option.
2944
2945 This option instructs @command{tar} to process only the @var{number}th
2946 occurrence of each named file. @var{Number} defaults to 1, so
2947
2948 @smallexample
2949 tar -x -f archive.tar --occurrence filename
2950 @end smallexample
2951
2952 @noindent
2953 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2954 and will terminate without scanning to the end of the archive.
2955
2956 @opsummary{old-archive}
2957 @item --old-archive
2958 Synonym for @option{--format=v7}.
2959
2960 @opsummary{one-file-system}
2961 @item --one-file-system
2962 Used when creating an archive. Prevents @command{tar} from recursing into
2963 directories that are on different file systems from the current
2964 directory.
2965
2966 @opsummary{overwrite}
2967 @item --overwrite
2968
2969 Overwrite existing files and directory metadata when extracting files
2970 from an archive. @xref{Overwrite Old Files}.
2971
2972 @opsummary{overwrite-dir}
2973 @item --overwrite-dir
2974
2975 Overwrite the metadata of existing directories when extracting files
2976 from an archive. @xref{Overwrite Old Files}.
2977
2978 @opsummary{owner}
2979 @item --owner=@var{user}
2980
2981 Specifies that @command{tar} should use @var{user} as the owner of members
2982 when creating archives, instead of the user associated with the source
2983 file. @var{user} is first decoded as a user symbolic name, but if
2984 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
2985 @xref{override}.
2986
2987 This option does not affect extraction from archives.
2988
2989 @opsummary{pax-option}
2990 @item --pax-option=@var{keyword-list}
2991 This option is meaningful only with @acronym{POSIX.1-2001} archives
2992 (@pxref{posix}). It modifies the way @command{tar} handles the
2993 extended header keywords. @var{Keyword-list} is a comma-separated
2994 list of keyword options. @xref{PAX keywords}, for a detailed
2995 discussion.
2996
2997 @opsummary{portability}
2998 @item --portability
2999 @itemx --old-archive
3000 Synonym for @option{--format=v7}.
3001
3002 @opsummary{posix}
3003 @item --posix
3004 Same as @option{--format=posix}.
3005
3006 @opsummary{preserve}
3007 @item --preserve
3008
3009 Synonymous with specifying both @option{--preserve-permissions} and
3010 @option{--same-order}. @xref{Setting Access Permissions}.
3011
3012 @opsummary{preserve-order}
3013 @item --preserve-order
3014
3015 (See @option{--same-order}; @pxref{Reading}.)
3016
3017 @opsummary{preserve-permissions}
3018 @opsummary{same-permissions}
3019 @item --preserve-permissions
3020 @itemx --same-permissions
3021 @itemx -p
3022
3023 When @command{tar} is extracting an archive, it normally subtracts the
3024 users' umask from the permissions specified in the archive and uses
3025 that number as the permissions to create the destination file.
3026 Specifying this option instructs @command{tar} that it should use the
3027 permissions directly from the archive. @xref{Setting Access Permissions}.
3028
3029 @opsummary{quote-chars}
3030 @item --quote-chars=@var{string}
3031 Always quote characters from @var{string}, even if the selected
3032 quoting style would not quote them (@pxref{quoting styles}).
3033
3034 @opsummary{quoting-style}
3035 @item --quoting-style=@var{style}
3036 Set quoting style to use when printing member and file names
3037 (@pxref{quoting styles}). Valid @var{style} values are:
3038 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3039 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3040 style is @code{escape}, unless overridden while configuring the
3041 package.
3042
3043 @opsummary{read-full-records}
3044 @item --read-full-records
3045 @itemx -B
3046
3047 Specifies that @command{tar} should reblock its input, for reading
3048 from pipes on systems with buggy implementations. @xref{Reading}.
3049
3050 @opsummary{record-size}
3051 @item --record-size=@var{size}
3052
3053 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3054 archive. @xref{Blocking Factor}.
3055
3056 @opsummary{recursion}
3057 @item --recursion
3058
3059 With this option, @command{tar} recurses into directories (default).
3060 @xref{recurse}.
3061
3062 @opsummary{recursive-unlink}
3063 @item --recursive-unlink
3064
3065 Remove existing
3066 directory hierarchies before extracting directories of the same name
3067 from the archive. @xref{Recursive Unlink}.
3068
3069 @opsummary{remove-files}
3070 @item --remove-files
3071
3072 Directs @command{tar} to remove the source file from the file system after
3073 appending it to an archive. @xref{remove files}.
3074
3075 @opsummary{restrict}
3076 @item --restrict
3077
3078 Disable use of some potentially harmful @command{tar} options.
3079 Currently this option disables shell invocation from multi-volume menu
3080 (@pxref{Using Multiple Tapes}).
3081
3082 @opsummary{rmt-command}
3083 @item --rmt-command=@var{cmd}
3084
3085 Notifies @command{tar} that it should use @var{cmd} instead of
3086 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3087
3088 @opsummary{rsh-command}
3089 @item --rsh-command=@var{cmd}
3090
3091 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3092 devices. @xref{Device}.
3093
3094 @opsummary{same-order}
3095 @item --same-order
3096 @itemx --preserve-order
3097 @itemx -s
3098
3099 This option is an optimization for @command{tar} when running on machines with
3100 small amounts of memory. It informs @command{tar} that the list of file
3101 arguments has already been sorted to match the order of files in the
3102 archive. @xref{Reading}.
3103
3104 @opsummary{same-owner}
3105 @item --same-owner
3106
3107 When extracting an archive, @command{tar} will attempt to preserve the owner
3108 specified in the @command{tar} archive with this option present.
3109 This is the default behavior for the superuser; this option has an
3110 effect only for ordinary users. @xref{Attributes}.
3111
3112 @opsummary{same-permissions}
3113 @item --same-permissions
3114
3115 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3116
3117 @opsummary{seek}
3118 @item --seek
3119 @itemx -n
3120
3121 Assume that the archive media supports seeks to arbitrary
3122 locations. Usually @command{tar} determines automatically whether
3123 the archive can be seeked or not. This option is intended for use
3124 in cases when such recognition fails.
3125
3126 @opsummary{show-defaults}
3127 @item --show-defaults
3128
3129 Displays the default options used by @command{tar} and exits
3130 successfully. This option is intended for use in shell scripts.
3131 Here is an example of what you can see using this option:
3132
3133 @smallexample
3134 $ tar --show-defaults
3135 --format=gnu -f- -b20 --quoting-style=escape \
3136 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3137 @end smallexample
3138
3139 @opsummary{show-omitted-dirs}
3140 @item --show-omitted-dirs
3141
3142 Instructs @command{tar} to mention the directories it is skipping when
3143 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3144
3145 @opsummary{show-transformed-names}
3146 @opsummary{show-stored-names}
3147 @item --show-transformed-names
3148 @itemx --show-stored-names
3149
3150 Display file or member names after applying any transformations
3151 (@pxref{transform}). In particular, when used in conjunction with one of
3152 the archive creation operations it instructs @command{tar} to list the
3153 member names stored in the archive, as opposed to the actual file
3154 names. @xref{listing member and file names}.
3155
3156 @opsummary{sparse}
3157 @item --sparse
3158 @itemx -S
3159
3160 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3161 sparse files efficiently. @xref{sparse}.
3162
3163 @opsummary{sparse-version}
3164 @item --sparse-version=@var{version}
3165
3166 Specifies the @dfn{format version} to use when archiving sparse
3167 files. Implies @option{--sparse}. @xref{sparse}. For the description
3168 of the supported sparse formats, @xref{Sparse Formats}.
3169
3170 @opsummary{starting-file}
3171 @item --starting-file=@var{name}
3172 @itemx -K @var{name}
3173
3174 This option affects extraction only; @command{tar} will skip extracting
3175 files in the archive until it finds one that matches @var{name}.
3176 @xref{Scarce}.
3177
3178 @opsummary{strip-components}
3179 @item --strip-components=@var{number}
3180 Strip given @var{number} of leading components from file names before
3181 extraction. For example, if archive @file{archive.tar} contained
3182 @file{/some/file/name}, then running
3183
3184 @smallexample
3185 tar --extract --file archive.tar --strip-components=2
3186 @end smallexample
3187
3188 @noindent
3189 would extract this file to file @file{name}.
3190
3191 @opsummary{suffix}, summary
3192 @item --suffix=@var{suffix}
3193
3194 Alters the suffix @command{tar} uses when backing up files from the default
3195 @samp{~}. @xref{backup}.
3196
3197 @opsummary{tape-length}
3198 @item --tape-length=@var{num}
3199 @itemx -L @var{num}
3200
3201 Specifies the length of tapes that @command{tar} is writing as being
3202 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3203
3204 @opsummary{test-label}
3205 @item --test-label
3206
3207 Reads the volume label. If an argument is specified, test whether it
3208 matches the volume label. @xref{--test-label option}.
3209
3210 @opsummary{to-command}
3211 @item --to-command=@var{command}
3212
3213 During extraction @command{tar} will pipe extracted files to the
3214 standard input of @var{command}. @xref{Writing to an External Program}.
3215
3216 @opsummary{to-stdout}
3217 @item --to-stdout
3218 @itemx -O
3219
3220 During extraction, @command{tar} will extract files to stdout rather
3221 than to the file system. @xref{Writing to Standard Output}.
3222
3223 @opsummary{totals}
3224 @item --totals[=@var{signo}]
3225
3226 Displays the total number of bytes transferred when processing an
3227 archive. If an argument is given, these data are displayed on
3228 request, when signal @var{signo} is delivered to @command{tar}.
3229 @xref{totals}.
3230
3231 @opsummary{touch}
3232 @item --touch
3233 @itemx -m
3234
3235 Sets the data modification time of extracted files to the extraction time,
3236 rather than the data modification time stored in the archive.
3237 @xref{Data Modification Times}.
3238
3239 @opsummary{transform}
3240 @item --transform=@var{sed-expr}
3241
3242 Transform file or member names using @command{sed} replacement expression
3243 @var{sed-expr}. For example,
3244
3245 @smallexample
3246 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3247 @end smallexample
3248
3249 @noindent
3250 will add to @file{archive} files from the current working directory,
3251 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3252 discussion, @xref{transform}.
3253
3254 To see transformed member names in verbose listings, use
3255 @option{--show-transformed-names} option
3256 (@pxref{show-transformed-names}).
3257
3258 @opsummary{uncompress}
3259 @item --uncompress
3260
3261 (See @option{--compress}. @pxref{gzip})
3262
3263 @opsummary{ungzip}
3264 @item --ungzip
3265
3266 (See @option{--gzip}. @pxref{gzip})
3267
3268 @opsummary{unlink-first}
3269 @item --unlink-first
3270 @itemx -U
3271
3272 Directs @command{tar} to remove the corresponding file from the file
3273 system before extracting it from the archive. @xref{Unlink First}.
3274
3275 @opsummary{unquote}
3276 @item --unquote
3277 Enable unquoting input file or member names (default). @xref{input
3278 name quoting}.
3279
3280 @opsummary{use-compress-program}
3281 @item --use-compress-program=@var{prog}
3282
3283 Instructs @command{tar} to access the archive through @var{prog}, which is
3284 presumed to be a compression program of some sort. @xref{gzip}.
3285
3286 @opsummary{utc}
3287 @item --utc
3288
3289 Display file modification dates in @acronym{UTC}. This option implies
3290 @option{--verbose}.
3291
3292 @opsummary{verbose}
3293 @item --verbose
3294 @itemx -v
3295
3296 Specifies that @command{tar} should be more verbose about the
3297 operations it is performing. This option can be specified multiple
3298 times for some operations to increase the amount of information displayed.
3299 @xref{verbose}.
3300
3301 @opsummary{verify}
3302 @item --verify
3303 @itemx -W
3304
3305 Verifies that the archive was correctly written when creating an
3306 archive. @xref{verify}.
3307
3308 @opsummary{version}
3309 @item --version
3310
3311 Print information about the program's name, version, origin and legal
3312 status, all on standard output, and then exit successfully.
3313 @xref{help}.
3314
3315 @opsummary{volno-file}
3316 @item --volno-file=@var{file}
3317
3318 Used in conjunction with @option{--multi-volume}. @command{tar} will
3319 keep track of which volume of a multi-volume archive it is working in
3320 @var{file}. @xref{volno-file}.
3321
3322 @opsummary{wildcards}
3323 @item --wildcards
3324 Use wildcards when matching member names with patterns.
3325 @xref{controlling pattern-matching}.
3326
3327 @opsummary{wildcards-match-slash}
3328 @item --wildcards-match-slash
3329 Wildcards match @samp{/}.
3330 @xref{controlling pattern-matching}.
3331 @end table
3332
3333 @node Short Option Summary
3334 @subsection Short Options Cross Reference
3335
3336 Here is an alphabetized list of all of the short option forms, matching
3337 them with the equivalent long option.
3338
3339 @multitable @columnfractions 0.20 0.80
3340 @headitem Short Option @tab Reference
3341
3342 @item -A @tab @ref{--concatenate}.
3343
3344 @item -B @tab @ref{--read-full-records}.
3345
3346 @item -C @tab @ref{--directory}.
3347
3348 @item -F @tab @ref{--info-script}.
3349
3350 @item -G @tab @ref{--incremental}.
3351
3352 @item -K @tab @ref{--starting-file}.
3353
3354 @item -L @tab @ref{--tape-length}.
3355
3356 @item -M @tab @ref{--multi-volume}.
3357
3358 @item -N @tab @ref{--newer}.
3359
3360 @item -O @tab @ref{--to-stdout}.
3361
3362 @item -P @tab @ref{--absolute-names}.
3363
3364 @item -R @tab @ref{--block-number}.
3365
3366 @item -S @tab @ref{--sparse}.
3367
3368 @item -T @tab @ref{--files-from}.
3369
3370 @item -U @tab @ref{--unlink-first}.
3371
3372 @item -V @tab @ref{--label}.
3373
3374 @item -W @tab @ref{--verify}.
3375
3376 @item -X @tab @ref{--exclude-from}.
3377
3378 @item -Z @tab @ref{--compress}.
3379
3380 @item -b @tab @ref{--blocking-factor}.
3381
3382 @item -c @tab @ref{--create}.
3383
3384 @item -d @tab @ref{--compare}.
3385
3386 @item -f @tab @ref{--file}.
3387
3388 @item -g @tab @ref{--listed-incremental}.
3389
3390 @item -h @tab @ref{--dereference}.
3391
3392 @item -i @tab @ref{--ignore-zeros}.
3393
3394 @item -j @tab @ref{--bzip2}.
3395
3396 @item -k @tab @ref{--keep-old-files}.
3397
3398 @item -l @tab @ref{--check-links}.
3399
3400 @item -m @tab @ref{--touch}.
3401
3402 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3403 @ref{--portability}.
3404
3405 The later usage is deprecated. It is retained for compatibility with
3406 the earlier versions of @GNUTAR{}. In future releases
3407 @option{-o} will be equivalent to @option{--no-same-owner} only.
3408
3409 @item -p @tab @ref{--preserve-permissions}.
3410
3411 @item -r @tab @ref{--append}.
3412
3413 @item -s @tab @ref{--same-order}.
3414
3415 @item -t @tab @ref{--list}.
3416
3417 @item -u @tab @ref{--update}.
3418
3419 @item -v @tab @ref{--verbose}.
3420
3421 @item -w @tab @ref{--interactive}.
3422
3423 @item -x @tab @ref{--extract}.
3424
3425 @item -z @tab @ref{--gzip}.
3426
3427 @end multitable
3428
3429 @node help
3430 @section @GNUTAR{} documentation
3431
3432 @cindex Getting program version number
3433 @opindex version
3434 @cindex Version of the @command{tar} program
3435 Being careful, the first thing is really checking that you are using
3436 @GNUTAR{}, indeed. The @option{--version} option
3437 causes @command{tar} to print information about its name, version,
3438 origin and legal status, all on standard output, and then exit
3439 successfully. For example, @w{@samp{tar --version}} might print:
3440
3441 @smallexample
3442 tar (GNU tar) @value{VERSION}
3443 Copyright (C) 2006 Free Software Foundation, Inc.
3444 This is free software. You may redistribute copies of it under the terms
3445 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3446 There is NO WARRANTY, to the extent permitted by law.
3447
3448 Written by John Gilmore and Jay Fenlason.
3449 @end smallexample
3450
3451 @noindent
3452 The first occurrence of @samp{tar} in the result above is the program
3453 name in the package (for example, @command{rmt} is another program),
3454 while the second occurrence of @samp{tar} is the name of the package
3455 itself, containing possibly many programs. The package is currently
3456 named @samp{tar}, after the name of the main program it
3457 contains@footnote{There are plans to merge the @command{cpio} and
3458 @command{tar} packages into a single one which would be called
3459 @code{paxutils}. So, who knows if, one of this days, the
3460 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3461 paxutils) 3.2}}}.
3462
3463 @cindex Obtaining help
3464 @cindex Listing all @command{tar} options
3465 @xopindex{help, introduction}
3466 Another thing you might want to do is checking the spelling or meaning
3467 of some particular @command{tar} option, without resorting to this
3468 manual, for once you have carefully read it. @GNUTAR{}
3469 has a short help feature, triggerable through the
3470 @option{--help} option. By using this option, @command{tar} will
3471 print a usage message listing all available options on standard
3472 output, then exit successfully, without doing anything else and
3473 ignoring all other options. Even if this is only a brief summary, it
3474 may be several screens long. So, if you are not using some kind of
3475 scrollable window, you might prefer to use something like:
3476
3477 @smallexample
3478 $ @kbd{tar --help | less}
3479 @end smallexample
3480
3481 @noindent
3482 presuming, here, that you like using @command{less} for a pager. Other
3483 popular pagers are @command{more} and @command{pg}. If you know about some
3484 @var{keyword} which interests you and do not want to read all the
3485 @option{--help} output, another common idiom is doing:
3486
3487 @smallexample
3488 tar --help | grep @var{keyword}
3489 @end smallexample
3490
3491 @noindent
3492 for getting only the pertinent lines. Notice, however, that some
3493 @command{tar} options have long description lines and the above
3494 command will list only the first of them.
3495
3496 The exact look of the option summary displayed by @kbd{tar --help} is
3497 configurable. @xref{Configuring Help Summary}, for a detailed description.
3498
3499 @opindex usage
3500 If you only wish to check the spelling of an option, running @kbd{tar
3501 --usage} may be a better choice. This will display a terse list of
3502 @command{tar} option without accompanying explanations.
3503
3504 The short help output is quite succinct, and you might have to get
3505 back to the full documentation for precise points. If you are reading
3506 this paragraph, you already have the @command{tar} manual in some
3507 form. This manual is available in a variety of forms from
3508 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3509 distribution, provided you have @TeX{} already installed somewhere,
3510 and a laser printer around. Just configure the distribution, execute
3511 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3512 usual way (contact your local guru to know how). If @GNUTAR{}
3513 has been conveniently installed at your place, this
3514 manual is also available in interactive, hypertextual form as an Info
3515 file. Just call @w{@samp{info tar}} or, if you do not have the
3516 @command{info} program handy, use the Info reader provided within
3517 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3518
3519 There is currently no @code{man} page for @GNUTAR{}.
3520 If you observe such a @code{man} page on the system you are running,
3521 either it does not belong to @GNUTAR{}, or it has not
3522 been produced by @acronym{GNU}. Some package maintainers convert
3523 @kbd{tar --help} output to a man page, using @command{help2man}. In
3524 any case, please bear in mind that the authoritative source of
3525 information about @GNUTAR{} is this Texinfo documentation.
3526
3527 @node defaults
3528 @section Obtaining @GNUTAR{} default values
3529
3530 @opindex show-defaults
3531 @GNUTAR{} has some predefined defaults that are used when you do not
3532 explicitly specify another values. To obtain a list of such
3533 defaults, use @option{--show-defaults} option. This will output the
3534 values in the form of @command{tar} command line options:
3535
3536 @smallexample
3537 @group
3538 @kbd{tar --show-defaults}
3539 --format=gnu -f- -b20 --quoting-style=escape
3540 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3541 @end group
3542 @end smallexample
3543
3544 @noindent
3545 Notice, that this option outputs only one line. The example output above
3546 has been split to fit page boundaries.
3547
3548 @noindent
3549 The above output shows that this version of @GNUTAR{} defaults to
3550 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3551 output as the archive, if no @option{--file} option has been given
3552 (@pxref{file tutorial}), the default blocking factor is 20
3553 (@pxref{Blocking Factor}). It also shows the default locations where
3554 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3555
3556 @node verbose
3557 @section Checking @command{tar} progress
3558
3559 Typically, @command{tar} performs most operations without reporting any
3560 information to the user except error messages. When using @command{tar}
3561 with many options, particularly ones with complicated or
3562 difficult-to-predict behavior, it is possible to make serious mistakes.
3563 @command{tar} provides several options that make observing @command{tar}
3564 easier. These options cause @command{tar} to print information as it
3565 progresses in its job, and you might want to use them just for being
3566 more careful about what is going on, or merely for entertaining
3567 yourself. If you have encountered a problem when operating on an
3568 archive, however, you may need more information than just an error
3569 message in order to solve the problem. The following options can be
3570 helpful diagnostic tools.
3571
3572 @cindex Verbose operation
3573 @opindex verbose
3574 Normally, the @option{--list} (@option{-t}) command to list an archive
3575 prints just the file names (one per line) and the other commands are
3576 silent. When used with most operations, the @option{--verbose}
3577 (@option{-v}) option causes @command{tar} to print the name of each
3578 file or archive member as it is processed. This and the other options
3579 which make @command{tar} print status information can be useful in
3580 monitoring @command{tar}.
3581
3582 With @option{--create} or @option{--extract}, @option{--verbose} used
3583 once just prints the names of the files or members as they are processed.
3584 Using it twice causes @command{tar} to print a longer listing
3585 (@xref{verbose member listing}, for the description) for each member.
3586 Since @option{--list} already prints the names of the members,
3587 @option{--verbose} used once with @option{--list} causes @command{tar}
3588 to print an @samp{ls -l} type listing of the files in the archive.
3589 The following examples both extract members with long list output:
3590
3591 @smallexample
3592 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3593 $ @kbd{tar xvvf archive.tar}
3594 @end smallexample
3595
3596 Verbose output appears on the standard output except when an archive is
3597 being written to the standard output, as with @samp{tar --create
3598 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3599 installer let standard output be the default archive). In that case
3600 @command{tar} writes verbose output to the standard error stream.
3601
3602 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3603 verbose output to @var{file} rather than to standard output or standard
3604 error.
3605
3606 @anchor{totals}
3607 @cindex Obtaining total status information
3608 @opindex totals
3609 The @option{--totals} option causes @command{tar} to print on the
3610 standard error the total amount of bytes transferred when processing
3611 an archive. When creating or appending to an archive, this option
3612 prints the number of bytes written to the archive and the average
3613 speed at which they have been written, e.g.:
3614
3615 @smallexample
3616 @group
3617 $ @kbd{tar -c -f archive.tar --totals /home}
3618 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3619 @end group
3620 @end smallexample
3621
3622 When reading an archive, this option displays the number of bytes
3623 read:
3624
3625 @smallexample
3626 @group
3627 $ @kbd{tar -x -f archive.tar --totals}
3628 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3629 @end group
3630 @end smallexample
3631
3632 Finally, when deleting from an archive, the @option{--totals} option
3633 displays both numbers plus number of bytes removed from the archive:
3634
3635 @smallexample
3636 @group
3637 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3638 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3639 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3640 Total bytes deleted: 1474048
3641 @end group
3642 @end smallexample
3643
3644 You can also obtain this information on request. When
3645 @option{--totals} is used with an argument, this argument is
3646 interpreted as a symbolic name of a signal, upon delivery of which the
3647 statistics is to be printed:
3648
3649 @table @option
3650 @item --totals=@var{signo}
3651 Print statistics upon delivery of signal @var{signo}. Valid arguments
3652 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3653 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3654 accepted.
3655 @end table
3656
3657 Both forms of @option{--totals} option can be used simultaneously.
3658 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3659 extract all members from its default archive and print statistics
3660 after finishing the extraction, as well as when receiving signal
3661 @code{SIGUSR1}.
3662
3663 @anchor{Progress information}
3664 @cindex Progress information
3665 The @option{--checkpoint} option prints an occasional message
3666 as @command{tar} reads or writes the archive. It is designed for
3667 those who don't need the more detailed (and voluminous) output of
3668 @option{--block-number} (@option{-R}), but do want visual confirmation
3669 that @command{tar} is actually making forward progress. By default it
3670 prints a message each 10 records read or written. This can be changed
3671 by giving it a numeric argument after an equal sign:
3672
3673 @smallexample
3674 $ @kbd{tar -c --checkpoint=1000} /var
3675 tar: Write checkpoint 1000
3676 tar: Write checkpoint 2000
3677 tar: Write checkpoint 3000
3678 @end smallexample
3679
3680 This example shows the default checkpoint message used by
3681 @command{tar}. If you place a dot immediately after the equal
3682 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3683 actually a shortcut for @option{--checkpoint=@var{n}
3684 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3685
3686 @smallexample
3687 $ @kbd{tar -c --checkpoint=.1000} /var
3688 ...
3689 @end smallexample
3690
3691 The @option{--checkpoint} option provides a flexible mechanism for
3692 executing arbitrary actions upon hitting checkpoints, see the next
3693 section (@pxref{checkpoints}), for more information on it.
3694
3695 @opindex show-omitted-dirs
3696 @anchor{show-omitted-dirs}
3697 The @option{--show-omitted-dirs} option, when reading an archive---with
3698 @option{--list} or @option{--extract}, for example---causes a message
3699 to be printed for each directory in the archive which is skipped.
3700 This happens regardless of the reason for skipping: the directory might
3701 not have been named on the command line (implicitly or explicitly),
3702 it might be excluded by the use of the
3703 @option{--exclude=@var{pattern}} option, or some other reason.
3704
3705 @opindex block-number
3706 @cindex Block number where error occurred
3707 @anchor{block-number}
3708 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3709 every message it would normally produce, the block number within the
3710 archive where the message was triggered. Also, supplementary messages
3711 are triggered when reading blocks full of NULs, or when hitting end of
3712 file on the archive. As of now, if the archive if properly terminated
3713 with a NUL block, the reading of the file may stop before end of file
3714 is met, so the position of end of file will not usually show when
3715 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3716 drains the archive before exiting when reading the
3717 archive from a pipe.
3718
3719 @cindex Error message, block number of
3720 This option is especially useful when reading damaged archives, since
3721 it helps pinpoint the damaged sections. It can also be used with
3722 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3723 choose among several backup tapes when retrieving a file later, in
3724 favor of the tape where the file appears earliest (closest to the
3725 front of the tape). @xref{backup}.
3726
3727 @node checkpoints
3728 @section Checkpoints
3729 @cindex checkpoints, defined
3730 @opindex checkpoint
3731 @opindex checkpoint-action
3732
3733 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3734 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3735 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3736 periodically execute arbitrary actions.
3737
3738 The checkpoint facility is enabled using the following option:
3739
3740 @table @option
3741 @xopindex{checkpoint, defined}
3742 @item --checkpoint[=@var{n}]
3743 Schedule checkpoints before writing or reading each @var{n}th record.
3744 The default value for @var{n} is 10.
3745 @end table
3746
3747 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3748 These actions include: pausing, displaying textual messages, and
3749 executing arbitrary external programs. Actions are defined using
3750 the @option{--checkpoint-action} option.
3751
3752 @table @option
3753 @xopindex{checkpoint-action, defined}
3754 @item --checkpoint-action=@var{action}
3755 Execute an @var{action} at each checkpoint.
3756 @end table
3757
3758 @cindex @code{echo}, checkpoint action
3759 The simplest value of @var{action} is @samp{echo}. It instructs
3760 @command{tar} to display the default message on the standard error
3761 stream upon arriving at each checkpoint. The default message is (in
3762 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3763 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3764 Here, @var{n} represents ordinal number of the checkpoint.
3765
3766 In another locales, translated versions of this message are used.
3767
3768 This is the default action, so running:
3769
3770 @smallexample
3771 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3772 @end smallexample
3773
3774 @noindent
3775 is equivalent to:
3776
3777 @smallexample
3778 $ @kbd{tar -c --checkpoint=1000} /var
3779 @end smallexample
3780
3781 The @samp{echo} action also allows to supply a customized message.
3782 You do so by placing an equals sign and the message right after it,
3783 e.g.:
3784
3785 @smallexample
3786 --checkpoint-action="echo=Hit %s checkpoint #%u"
3787 @end smallexample
3788
3789 The @samp{%s} and @samp{%u} in the above example are
3790 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3791 the @dfn{type} of the checkpoint: @samp{write} or
3792 @samp{read} (or a corresponding translated version in locales other
3793 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3794 the ordinal number of the checkpoint. Thus, the above example could
3795 produce the following output when used with the @option{--create}
3796 option:
3797
3798 @smallexample
3799 tar: Hit write checkpoint #10
3800 tar: Hit write checkpoint #20
3801 tar: Hit write checkpoint #30
3802 @end smallexample
3803
3804 Aside from meta-character expansion, the message string is subject to
3805 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3806 replaced with their corresponding @acronym{ASCII} characters
3807 (@pxref{escape sequences}). E.g. the following action will produce an
3808 audible bell and the message described above at each checkpoint:
3809
3810 @smallexample
3811 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3812 @end smallexample
3813
3814 @cindex @code{bell}, checkpoint action
3815 There is also a special action which produces an audible signal:
3816 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3817 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3818 whereas @samp{echo='\a'} sends it to the standard error.
3819
3820 @cindex @code{ttyout}, checkpoint action
3821 The @samp{ttyout=@var{string}} action outputs @var{string} to
3822 @file{/dev/tty}, so it can be used even if the standard output is
3823 redirected elsewhere. The @var{string} is subject to the same
3824 modifications as with @samp{echo} action. In contrast to the latter,
3825 @samp{ttyout} does not prepend @command{tar} executable name to the
3826 string, nor does it output a newline after it. For example, the
3827 following action will print the checkpoint message at the same screen
3828 line, overwriting any previous message:
3829
3830 @smallexample
3831 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3832 @end smallexample
3833
3834 @cindex @code{dot}, checkpoint action
3835 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3836 instructs @command{tar} to print a single dot on the standard listing
3837 stream, e.g.:
3838
3839 @smallexample
3840 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3841 ...
3842 @end smallexample
3843
3844 For compatibility with previous @GNUTAR{} versions, this action can
3845 be abbreviated by placing a dot in front of the checkpoint frequency,
3846 as shown in the previous section.
3847
3848 @cindex @code{sleep}, checkpoint action
3849 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
3850 amount of seconds. The following example will stop for 30 seconds at each
3851 checkpoint:
3852
3853 @smallexample
3854 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
3855 @end smallexample
3856
3857 @cindex @code{exec}, checkpoint action
3858 Finally, the @code{exec} action executes a given external program.
3859 For example:
3860
3861 @smallexample
3862 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
3863 @end smallexample
3864
3865 This program is executed using @command{/bin/sh -c}, with no
3866 additional arguments. Its exit code is ignored. It gets a copy of
3867 @command{tar}'s environment plus the following variables:
3868
3869 @table @env
3870 @vrindex TAR_VERSION, checkpoint script environment
3871 @item TAR_VERSION
3872 @GNUTAR{} version number.
3873
3874 @vrindex TAR_ARCHIVE, checkpoint script environment
3875 @item TAR_ARCHIVE
3876 The name of the archive @command{tar} is processing.
3877
3878 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
3879 @item TAR_BLOCKING_FACTOR
3880 Current blocking factor (@pxref{Blocking}.
3881
3882 @vrindex TAR_CHECKPOINT, checkpoint script environment
3883 @item TAR_CHECKPOINT
3884 The checkpoint number.
3885
3886 @vrindex TAR_SUBCOMMAND, checkpoint script environment
3887 @item TAR_SUBCOMMAND
3888 A short option describing the operation @command{tar} is executing
3889 @xref{Operations}, for a complete list of subcommand options.
3890
3891 @vrindex TAR_FORMAT, checkpoint script environment
3892 @item TAR_FORMAT
3893 Format of the archive being processed. @xref{Formats}, for a complete
3894 list of archive format names.
3895 @end table
3896
3897 Any number of actions can be defined, by supplying several
3898 @option{--checkpoint-action} options in the command line. For
3899 example, the command below displays two messages, pauses
3900 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
3901
3902 @example
3903 @group
3904 $ @kbd{tar -c -f arc.tar \
3905 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
3906 --checkpoint-action='echo=Sleeping for 30 seconds' \
3907 --checkpoint-action='sleep=30' \
3908 --checkpoint-action='exec=/sbin/cpoint'}
3909 @end group
3910 @end example
3911
3912 This example also illustrates the fact that
3913 @option{--checkpoint-action} can be used without
3914 @option{--checkpoint}. In this case, the default checkpoint frequency
3915 (at each 10th record) is assumed.
3916
3917 @node interactive
3918 @section Asking for Confirmation During Operations
3919 @cindex Interactive operation
3920
3921 Typically, @command{tar} carries out a command without stopping for
3922 further instructions. In some situations however, you may want to
3923 exclude some files and archive members from the operation (for instance
3924 if disk or storage space is tight). You can do this by excluding
3925 certain files automatically (@pxref{Choosing}), or by performing
3926 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3927 @command{tar} also accepts @option{--confirmation} for this option.
3928
3929 @opindex interactive
3930 When the @option{--interactive} (@option{-w}) option is specified, before
3931 reading, writing, or deleting files, @command{tar} first prints a message
3932 for each such file, telling what operation it intends to take, then asks
3933 for confirmation on the terminal. The actions which require
3934 confirmation include adding a file to the archive, extracting a file
3935 from the archive, deleting a file from the archive, and deleting a file
3936 from disk. To confirm the action, you must type a line of input
3937 beginning with @samp{y}. If your input line begins with anything other
3938 than @samp{y}, @command{tar} skips that file.
3939
3940 If @command{tar} is reading the archive from the standard input,
3941 @command{tar} opens the file @file{/dev/tty} to support the interactive
3942 communications.
3943
3944 Verbose output is normally sent to standard output, separate from
3945 other error messages. However, if the archive is produced directly
3946 on standard output, then verbose output is mixed with errors on
3947 @code{stderr}. Producing the archive on standard output may be used
3948 as a way to avoid using disk space, when the archive is soon to be
3949 consumed by another process reading it, say. Some people felt the need
3950 of producing an archive on stdout, still willing to segregate between
3951 verbose output and error output. A possible approach would be using a
3952 named pipe to receive the archive, and having the consumer process to
3953 read from that named pipe. This has the advantage of letting standard
3954 output free to receive verbose output, all separate from errors.
3955
3956 @node operations
3957 @chapter @GNUTAR{} Operations
3958
3959 @menu
3960 * Basic tar::
3961 * Advanced tar::
3962 * create options::
3963 * extract options::
3964 * backup::
3965 * Applications::
3966 * looking ahead::
3967 @end menu
3968
3969 @node Basic tar
3970 @section Basic @GNUTAR{} Operations
3971
3972 The basic @command{tar} operations, @option{--create} (@option{-c}),
3973 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3974 @option{-x}), are currently presented and described in the tutorial
3975 chapter of this manual. This section provides some complementary notes
3976 for these operations.
3977
3978 @table @option
3979 @xopindex{create, complementary notes}
3980 @item --create
3981 @itemx -c
3982
3983 Creating an empty archive would have some kind of elegance. One can
3984 initialize an empty archive and later use @option{--append}
3985 (@option{-r}) for adding all members. Some applications would not
3986 welcome making an exception in the way of adding the first archive
3987 member. On the other hand, many people reported that it is
3988 dangerously too easy for @command{tar} to destroy a magnetic tape with
3989 an empty archive@footnote{This is well described in @cite{Unix-haters
3990 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3991 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3992
3993 @enumerate
3994 @item
3995 Mistakingly using @code{create} instead of @code{extract}, when the
3996 intent was to extract the full contents of an archive. This error
3997 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3998 the QWERTY keyboard. Instead of being unpacked, the archive then
3999 gets wholly destroyed. When users speak about @dfn{exploding} an
4000 archive, they usually mean something else :-).
4001
4002 @item
4003 Forgetting the argument to @code{file}, when the intent was to create
4004 an archive with a single file in it. This error is likely because a
4005 tired user can easily add the @kbd{f} key to the cluster of option
4006 letters, by the mere force of habit, without realizing the full
4007 consequence of doing so. The usual consequence is that the single
4008 file, which was meant to be saved, is rather destroyed.
4009 @end enumerate
4010
4011 So, recognizing the likelihood and the catastrophic nature of these
4012 errors, @GNUTAR{} now takes some distance from elegance, and
4013 cowardly refuses to create an archive when @option{--create} option is
4014 given, there are no arguments besides options, and
4015 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4016 around the cautiousness of @GNUTAR{} and nevertheless create an
4017 archive with nothing in it, one may still use, as the value for the
4018 @option{--files-from} option, a file with no names in it, as shown in
4019 the following commands:
4020
4021 @smallexample
4022 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4023 @kbd{tar cfT empty-archive.tar /dev/null}
4024 @end smallexample
4025
4026 @xopindex{extract, complementary notes}
4027 @item --extract
4028 @itemx --get
4029 @itemx -x
4030
4031 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4032
4033 @item @option{--list} (@option{-t})
4034
4035 @GNUTAR{} now shows dates as @samp{1996-08-30},
4036 while it used to show them as @samp{Aug 30 1996}. Preferably,
4037 people should get used to ISO 8601 dates. Local American dates should
4038 be made available again with full date localization support, once
4039 ready. In the meantime, programs not being localizable for dates
4040 should prefer international dates, that's really the way to go.
4041
4042 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4043 are curious, it contains a detailed explanation of the ISO 8601 standard.
4044
4045 @end table
4046
4047 @node Advanced tar
4048 @section Advanced @GNUTAR{} Operations
4049
4050 Now that you have learned the basics of using @GNUTAR{}, you may want
4051 to learn about further ways in which @command{tar} can help you.
4052
4053 This chapter presents five, more advanced operations which you probably
4054 won't use on a daily basis, but which serve more specialized functions.
4055 We also explain the different styles of options and why you might want
4056 to use one or another, or a combination of them in your @command{tar}
4057 commands. Additionally, this chapter includes options which allow you to
4058 define the output from @command{tar} more carefully, and provide help and
4059 error correction in special circumstances.
4060
4061 @FIXME{check this after the chapter is actually revised to make sure
4062 it still introduces the info in the chapter correctly : ).}
4063
4064 @menu
4065 * Operations::
4066 * append::
4067 * update::
4068 * concatenate::
4069 * delete::
4070 * compare::
4071 @end menu
4072
4073 @node Operations
4074 @subsection The Five Advanced @command{tar} Operations
4075 @UNREVISED
4076
4077 In the last chapter, you learned about the first three operations to
4078 @command{tar}. This chapter presents the remaining five operations to
4079 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4080 @option{--delete}, and @option{--compare}.
4081
4082 You are not likely to use these operations as frequently as those
4083 covered in the last chapter; however, since they perform specialized
4084 functions, they are quite useful when you do need to use them. We
4085 will give examples using the same directory and files that you created
4086 in the last chapter. As you may recall, the directory is called
4087 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4088 @samp{rock}, and the two archive files you created are
4089 @samp{collection.tar} and @samp{music.tar}.
4090
4091 We will also use the archive files @samp{afiles.tar} and
4092 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4093 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4094 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4095
4096 Unless we state otherwise, all practicing you do and examples you follow
4097 in this chapter will take place in the @file{practice} directory that
4098 you created in the previous chapter; see @ref{prepare for examples}.
4099 (Below in this section, we will remind you of the state of the examples
4100 where the last chapter left them.)
4101
4102 The five operations that we will cover in this chapter are:
4103
4104 @table @option
4105 @item --append
4106 @itemx -r
4107 Add new entries to an archive that already exists.
4108 @item --update
4109 @itemx -r
4110 Add more recent copies of archive members to the end of an archive, if
4111 they exist.
4112 @item --concatenate
4113 @itemx --catenate
4114 @itemx -A
4115 Add one or more pre-existing archives to the end of another archive.
4116 @item --delete
4117 Delete items from an archive (does not work on tapes).
4118 @item --compare
4119 @itemx --diff
4120 @itemx -d
4121 Compare archive members to their counterparts in the file system.
4122 @end table
4123
4124 @node append
4125 @subsection How to Add Files to Existing Archives: @option{--append}
4126 @UNREVISED
4127
4128 @opindex append
4129 If you want to add files to an existing archive, you don't need to
4130 create a new archive; you can use @option{--append} (@option{-r}).
4131 The archive must already exist in order to use @option{--append}. (A
4132 related operation is the @option{--update} operation; you can use this
4133 to add newer versions of archive members to an existing archive. To learn how to
4134 do this with @option{--update}, @pxref{update}.)
4135
4136 If you use @option{--append} to add a file that has the same name as an
4137 archive member to an archive containing that archive member, then the
4138 old member is not deleted. What does happen, however, is somewhat
4139 complex. @command{tar} @emph{allows} you to have infinite number of files
4140 with the same name. Some operations treat these same-named members no
4141 differently than any other set of archive members: for example, if you
4142 view an archive with @option{--list} (@option{-t}), you will see all
4143 of those members listed, with their data modification times, owners, etc.
4144
4145 Other operations don't deal with these members as perfectly as you might
4146 prefer; if you were to use @option{--extract} to extract the archive,
4147 only the most recently added copy of a member with the same name as four
4148 other members would end up in the working directory. This is because
4149 @option{--extract} extracts an archive in the order the members appeared
4150 in the archive; the most recently archived members will be extracted
4151 last. Additionally, an extracted member will @emph{replace} a file of
4152 the same name which existed in the directory already, and @command{tar}
4153 will not prompt you about this@footnote{Unless you give it
4154 @option{--keep-old-files} option, or the disk copy is newer than the
4155 the one in the archive and you invoke @command{tar} with
4156 @option{--keep-newer-files} option}. Thus, only the most recently archived
4157 member will end up being extracted, as it will replace the one
4158 extracted before it, and so on.
4159
4160 There exists a special option that allows you to get around this
4161 behavior and extract (or list) only a particular copy of the file.
4162 This is @option{--occurrence} option. If you run @command{tar} with
4163 this option, it will extract only the first copy of the file. You
4164 may also give this option an argument specifying the number of
4165 copy to be extracted. Thus, for example if the archive
4166 @file{archive.tar} contained three copies of file @file{myfile}, then
4167 the command
4168
4169 @smallexample
4170 tar --extract --file archive.tar --occurrence=2 myfile
4171 @end smallexample
4172
4173 @noindent
4174 would extract only the second copy. @xref{Option
4175 Summary,---occurrence}, for the description of @option{--occurrence}
4176 option.
4177
4178 @FIXME{ hag -- you might want to incorporate some of the above into the
4179 MMwtSN node; not sure. i didn't know how to make it simpler...
4180
4181 There are a few ways to get around this. (maybe xref Multiple Members
4182 with the Same Name.}
4183
4184 @cindex Members, replacing with other members
4185 @cindex Replacing members with other members
4186 If you want to replace an archive member, use @option{--delete} to
4187 delete the member you want to remove from the archive, , and then use
4188 @option{--append} to add the member you want to be in the archive. Note
4189 that you can not change the order of the archive; the most recently
4190 added member will still appear last. In this sense, you cannot truly
4191 ``replace'' one member with another. (Replacing one member with another
4192 will not work on certain types of media, such as tapes; see @ref{delete}
4193 and @ref{Media}, for more information.)
4194
4195 @menu
4196 * appending files:: Appending Files to an Archive
4197 * multiple::
4198 @end menu
4199
4200 @node appending files
4201 @subsubsection Appending Files to an Archive
4202 @UNREVISED
4203 @cindex Adding files to an Archive
4204 @cindex Appending files to an Archive
4205 @cindex Archives, Appending files to
4206
4207 The simplest way to add a file to an already existing archive is the
4208 @option{--append} (@option{-r}) operation, which writes specified
4209 files into the archive whether or not they are already among the
4210 archived files.
4211
4212 When you use @option{--append}, you @emph{must} specify file name
4213 arguments, as there is no default. If you specify a file that already
4214 exists in the archive, another copy of the file will be added to the
4215 end of the archive. As with other operations, the member names of the
4216 newly added files will be exactly the same as their names given on the
4217 command line. The @option{--verbose} (@option{-v}) option will print
4218 out the names of the files as they are written into the archive.
4219
4220 @option{--append} cannot be performed on some tape drives, unfortunately,
4221 due to deficiencies in the formats those tape drives use. The archive
4222 must be a valid @command{tar} archive, or else the results of using this
4223 operation will be unpredictable. @xref{Media}.
4224
4225 To demonstrate using @option{--append} to add a file to an archive,
4226 create a file called @file{rock} in the @file{practice} directory.
4227 Make sure you are in the @file{practice} directory. Then, run the
4228 following @command{tar} command to add @file{rock} to
4229 @file{collection.tar}:
4230
4231 @smallexample
4232 $ @kbd{tar --append --file=collection.tar rock}
4233 @end smallexample
4234
4235 @noindent
4236 If you now use the @option{--list} (@option{-t}) operation, you will see that
4237 @file{rock} has been added to the archive:
4238
4239 @smallexample
4240 $ @kbd{tar --list --file=collection.tar}
4241 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4242 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4243 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4244 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4245 @end smallexample
4246
4247 @node multiple
4248 @subsubsection Multiple Members with the Same Name
4249
4250 You can use @option{--append} (@option{-r}) to add copies of files
4251 which have been updated since the archive was created. (However, we
4252 do not recommend doing this since there is another @command{tar}
4253 option called @option{--update}; @xref{update}, for more information.
4254 We describe this use of @option{--append} here for the sake of
4255 completeness.) When you extract the archive, the older version will
4256 be effectively lost. This works because files are extracted from an
4257 archive in the order in which they were archived. Thus, when the
4258 archive is extracted, a file archived later in time will replace a
4259 file of the same name which was archived earlier, even though the
4260 older version of the file will remain in the archive unless you delete
4261 all versions of the file.
4262
4263 Supposing you change the file @file{blues} and then append the changed
4264 version to @file{collection.tar}. As you saw above, the original
4265 @file{blues} is in the archive @file{collection.tar}. If you change the
4266 file and append the new version of the file to the archive, there will
4267 be two copies in the archive. When you extract the archive, the older
4268 version of the file will be extracted first, and then replaced by the
4269 newer version when it is extracted.
4270
4271 You can append the new, changed copy of the file @file{blues} to the
4272 archive in this way:
4273
4274 @smallexample
4275 $ @kbd{tar --append --verbose --file=collection.tar blues}
4276 blues
4277 @end smallexample
4278
4279 @noindent
4280 Because you specified the @option{--verbose} option, @command{tar} has
4281 printed the name of the file being appended as it was acted on. Now
4282 list the contents of the archive:
4283
4284 @smallexample
4285 $ @kbd{tar --list --verbose --file=collection.tar}
4286 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4287 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4288 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4289 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4290 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4291 @end smallexample
4292
4293 @noindent
4294 The newest version of @file{blues} is now at the end of the archive
4295 (note the different creation dates and file sizes). If you extract
4296 the archive, the older version of the file @file{blues} will be
4297 replaced by the newer version. You can confirm this by extracting
4298 the archive and running @samp{ls} on the directory.
4299
4300 If you wish to extract the first occurrence of the file @file{blues}
4301 from the archive, use @option{--occurrence} option, as shown in
4302 the following example:
4303
4304 @smallexample
4305 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4306 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4307 @end smallexample
4308
4309 @xref{Writing}, for more information on @option{--extract} and
4310 @xref{Option Summary, --occurrence}, for the description of
4311 @option{--occurrence} option.
4312
4313 @node update
4314 @subsection Updating an Archive
4315 @UNREVISED
4316 @cindex Updating an archive
4317
4318 @opindex update
4319 In the previous section, you learned how to use @option{--append} to
4320 add a file to an existing archive. A related operation is
4321 @option{--update} (@option{-u}). The @option{--update} operation
4322 updates a @command{tar} archive by comparing the date of the specified
4323 archive members against the date of the file with the same name. If
4324 the file has been modified more recently than the archive member, then
4325 the newer version of the file is added to the archive (as with
4326 @option{--append}).
4327
4328 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4329 The operation will fail.
4330
4331 @FIXME{other examples of media on which --update will fail? need to ask
4332 charles and/or mib/thomas/dave shevett..}
4333
4334 Both @option{--update} and @option{--append} work by adding to the end
4335 of the archive. When you extract a file from the archive, only the
4336 version stored last will wind up in the file system, unless you use
4337 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4338
4339 @menu
4340 * how to update::
4341 @end menu
4342
4343 @node how to update
4344 @subsubsection How to Update an Archive Using @option{--update}
4345
4346 You must use file name arguments with the @option{--update}
4347 (@option{-u}) operation. If you don't specify any files,
4348 @command{tar} won't act on any files and won't tell you that it didn't
4349 do anything (which may end up confusing you).
4350
4351 @c note: the above parenthetical added because in fact, this
4352 @c behavior just confused the author. :-)
4353
4354 To see the @option{--update} option at work, create a new file,
4355 @file{classical}, in your practice directory, and some extra text to the
4356 file @file{blues}, using any text editor. Then invoke @command{tar} with
4357 the @samp{update} operation and the @option{--verbose} (@option{-v})
4358 option specified, using the names of all the files in the practice
4359 directory as file name arguments:
4360
4361 @smallexample
4362 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4363 blues
4364 classical
4365 $
4366 @end smallexample
4367
4368 @noindent
4369 Because we have specified verbose mode, @command{tar} prints out the names
4370 of the files it is working on, which in this case are the names of the
4371 files that needed to be updated. If you run @samp{tar --list} and look
4372 at the archive, you will see @file{blues} and @file{classical} at its
4373 end. There will be a total of two versions of the member @samp{blues};
4374 the one at the end will be newer and larger, since you added text before
4375 updating it.
4376
4377 (The reason @command{tar} does not overwrite the older file when updating
4378 it is because writing to the middle of a section of tape is a difficult
4379 process. Tapes are not designed to go backward. @xref{Media}, for more
4380 information about tapes.
4381
4382 @option{--update} (@option{-u}) is not suitable for performing backups for two
4383 reasons: it does not change directory content entries, and it
4384 lengthens the archive every time it is used. The @GNUTAR{}
4385 options intended specifically for backups are more
4386 efficient. If you need to run backups, please consult @ref{Backups}.
4387
4388 @node concatenate
4389 @subsection Combining Archives with @option{--concatenate}
4390
4391 @cindex Adding archives to an archive
4392 @cindex Concatenating Archives
4393 @opindex concatenate
4394 @opindex catenate
4395 @c @cindex @option{-A} described
4396 Sometimes it may be convenient to add a second archive onto the end of
4397 an archive rather than adding individual files to the archive. To add
4398 one or more archives to the end of another archive, you should use the
4399 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4400
4401 To use @option{--concatenate}, give the first archive with
4402 @option{--file} option and name the rest of archives to be
4403 concatenated on the command line. The members, and their member
4404 names, will be copied verbatim from those archives to the first one.
4405 @footnote{This can cause multiple members to have the same name, for
4406 information on how this affects reading the archive, @ref{multiple}.}
4407 The new, concatenated archive will be called by the same name as the
4408 one given with the @option{--file} option. As usual, if you omit
4409 @option{--file}, @command{tar} will use the value of the environment
4410 variable @env{TAPE}, or, if this has not been set, the default archive name.
4411
4412 @FIXME{There is no way to specify a new name...}
4413
4414 To demonstrate how @option{--concatenate} works, create two small archives
4415 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4416 files from @file{practice}:
4417
4418 @smallexample
4419 $ @kbd{tar -cvf bluesrock.tar blues rock}
4420 blues
4421 rock
4422 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4423 folk
4424 jazz
4425 @end smallexample
4426
4427 @noindent
4428 If you like, You can run @samp{tar --list} to make sure the archives
4429 contain what they are supposed to:
4430
4431 @smallexample
4432 $ @kbd{tar -tvf bluesrock.tar}
4433 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4434 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4435 $ @kbd{tar -tvf jazzfolk.tar}
4436 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4437 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4438 @end smallexample
4439
4440 We can concatenate these two archives with @command{tar}:
4441
4442 @smallexample
4443 $ @kbd{cd ..}
4444 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4445 @end smallexample
4446
4447 If you now list the contents of the @file{bluesrock.tar}, you will see
4448 that now it also contains the archive members of @file{jazzfolk.tar}:
4449
4450 @smallexample
4451 $ @kbd{tar --list --file=bluesrock.tar}
4452 blues
4453 rock
4454 folk
4455 jazz
4456 @end smallexample
4457
4458 When you use @option{--concatenate}, the source and target archives must
4459 already exist and must have been created using compatible format
4460 parameters. Notice, that @command{tar} does not check whether the
4461 archives it concatenates have compatible formats, it does not
4462 even check if the files are really tar archives.
4463
4464 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4465 tape drives, due to deficiencies in the formats those tape drives use.
4466
4467 @cindex @code{concatenate} vs @command{cat}
4468 @cindex @command{cat} vs @code{concatenate}
4469 It may seem more intuitive to you to want or try to use @command{cat} to
4470 concatenate two archives instead of using the @option{--concatenate}
4471 operation; after all, @command{cat} is the utility for combining files.
4472
4473 However, @command{tar} archives incorporate an end-of-file marker which
4474 must be removed if the concatenated archives are to be read properly as
4475 one archive. @option{--concatenate} removes the end-of-archive marker
4476 from the target archive before each new archive is appended. If you use
4477 @command{cat} to combine the archives, the result will not be a valid
4478 @command{tar} format archive. If you need to retrieve files from an
4479 archive that was added to using the @command{cat} utility, use the
4480 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4481 information on dealing with archives improperly combined using the
4482 @command{cat} shell utility.
4483
4484 @node delete
4485 @subsection Removing Archive Members Using @option{--delete}
4486 @UNREVISED
4487 @cindex Deleting files from an archive
4488 @cindex Removing files from an archive
4489
4490 @opindex delete
4491 You can remove members from an archive by using the @option{--delete}
4492 option. Specify the name of the archive with @option{--file}
4493 (@option{-f}) and then specify the names of the members to be deleted;
4494 if you list no member names, nothing will be deleted. The
4495 @option{--verbose} option will cause @command{tar} to print the names
4496 of the members as they are deleted. As with @option{--extract}, you
4497 must give the exact member names when using @samp{tar --delete}.
4498 @option{--delete} will remove all versions of the named file from the
4499 archive. The @option{--delete} operation can run very slowly.
4500
4501 Unlike other operations, @option{--delete} has no short form.
4502
4503 @cindex Tapes, using @option{--delete} and
4504 @cindex Deleting from tape archives
4505 This operation will rewrite the archive. You can only use
4506 @option{--delete} on an archive if the archive device allows you to
4507 write to any point on the media, such as a disk; because of this, it
4508 does not work on magnetic tapes. Do not try to delete an archive member
4509 from a magnetic tape; the action will not succeed, and you will be
4510 likely to scramble the archive and damage your tape. There is no safe
4511 way (except by completely re-writing the archive) to delete files from
4512 most kinds of magnetic tape. @xref{Media}.
4513
4514 To delete all versions of the file @file{blues} from the archive
4515 @file{collection.tar} in the @file{practice} directory, make sure you
4516 are in that directory, and then,
4517
4518 @smallexample
4519 $ @kbd{tar --list --file=collection.tar}
4520 blues
4521 folk
4522 jazz
4523 rock
4524 $ @kbd{tar --delete --file=collection.tar blues}
4525 $ @kbd{tar --list --file=collection.tar}
4526 folk
4527 jazz
4528 rock
4529 $
4530 @end smallexample
4531
4532 @FIXME{Check if the above listing is actually produced after running
4533 all the examples on collection.tar.}
4534
4535 The @option{--delete} option has been reported to work properly when
4536 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4537
4538 @node compare
4539 @subsection Comparing Archive Members with the File System
4540 @cindex Verifying the currency of an archive
4541 @UNREVISED
4542
4543 @opindex compare
4544 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4545 specified archive members against files with the same names, and then
4546 reports differences in file size, mode, owner, modification date and
4547 contents. You should @emph{only} specify archive member names, not file
4548 names. If you do not name any members, then @command{tar} will compare the
4549 entire archive. If a file is represented in the archive but does not
4550 exist in the file system, @command{tar} reports a difference.
4551
4552 You have to specify the record size of the archive when modifying an
4553 archive with a non-default record size.
4554
4555 @command{tar} ignores files in the file system that do not have
4556 corresponding members in the archive.
4557
4558 The following example compares the archive members @file{rock},
4559 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4560 files of the same name in the file system. (Note that there is no file,
4561 @file{funk}; @command{tar} will report an error message.)
4562
4563 @smallexample
4564 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4565 rock
4566 blues
4567 tar: funk not found in archive
4568 @end smallexample
4569
4570 The spirit behind the @option{--compare} (@option{--diff},
4571 @option{-d}) option is to check whether the archive represents the
4572 current state of files on disk, more than validating the integrity of
4573 the archive media. For this later goal, @xref{verify}.
4574
4575 @node create options
4576 @section Options Used by @option{--create}
4577
4578 @xopindex{create, additional options}
4579 The previous chapter described the basics of how to use
4580 @option{--create} (@option{-c}) to create an archive from a set of files.
4581 @xref{create}. This section described advanced options to be used with
4582 @option{--create}.
4583
4584 @menu
4585 * override:: Overriding File Metadata.
4586 * Ignore Failed Read::
4587 @end menu
4588
4589 @node override
4590 @subsection Overriding File Metadata
4591
4592 As described above, a @command{tar} archive keeps, for each member it contains,
4593 its @dfn{metadata}, such as modification time, mode and ownership of
4594 the file. @GNUTAR{} allows to replace these data with other values
4595 when adding files to the archive. The options described in this
4596 section affect creation of archives of any type. For POSIX archives,
4597 see also @ref{PAX keywords}, for additional ways of controlling
4598 metadata, stored in the archive.
4599
4600 @table @option
4601 @opindex mode
4602 @item --mode=@var{permissions}
4603
4604 When adding files to an archive, @command{tar} will use
4605 @var{permissions} for the archive members, rather than the permissions
4606 from the files. @var{permissions} can be specified either as an octal
4607 number or as symbolic permissions, like with
4608 @command{chmod} (@xref{File permissions, Permissions, File
4609 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4610 also has useful information for those not being overly familiar with
4611 the UNIX permission system). Using latter syntax allows for
4612 more flexibility. For example, the value @samp{a+rw} adds read and write
4613 permissions for everybody, while retaining executable bits on directories
4614 or on any other file already marked as executable:
4615
4616 @smallexample
4617 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4618 @end smallexample
4619
4620 @item --mtime=@var{date}
4621 @opindex mtime
4622
4623 When adding files to an archive, @command{tar} will use @var{date} as
4624 the modification time of members when creating archives, instead of
4625 their actual modification times. The argument @var{date} can be
4626 either a textual date representation in almost arbitrary format
4627 (@pxref{Date input formats}) or a name of the existing file, starting
4628 with @samp{/} or @samp{.}. In the latter case, the modification time
4629 of that file will be used.
4630
4631 The following example will set the modification date to 00:00:00 UTC,
4632 January 1, 1970:
4633
4634 @smallexample
4635 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4636 @end smallexample
4637
4638 @noindent
4639 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4640 will try to convert the specified date back to its textual
4641 representation and compare it with the one given with
4642 @option{--mtime} options. If the two dates differ, @command{tar} will
4643 print a warning saying what date it will use. This is to help user
4644 ensure he is using the right date.
4645
4646 For example:
4647
4648 @smallexample
4649 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4650 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4651 13:06:29.152478
4652 @dots{}
4653 @end smallexample
4654
4655 @item --owner=@var{user}
4656 @opindex owner
4657
4658 Specifies that @command{tar} should use @var{user} as the owner of members
4659 when creating archives, instead of the user associated with the source
4660 file. The argument @var{user} can be either an existing user symbolic
4661 name, or a decimal numeric user @acronym{ID}.
4662
4663 There is no value indicating a missing number, and @samp{0} usually means
4664 @code{root}. Some people like to force @samp{0} as the value to offer in
4665 their distributions for the owner of files, because the @code{root} user is
4666 anonymous anyway, so that might as well be the owner of anonymous
4667 archives. For example:
4668
4669 @smallexample
4670 @group
4671 $ @kbd{tar -c -f archive.tar --owner=0 .}
4672 # @r{Or:}
4673 $ @kbd{tar -c -f archive.tar --owner=root .}
4674 @end group
4675 @end smallexample
4676
4677 @item --group=@var{group}
4678 @opindex group
4679
4680 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4681 rather than the group from the source file. The argument @var{group}
4682 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4683 @end table
4684
4685 @node Ignore Failed Read
4686 @subsection Ignore Fail Read
4687
4688 @table @option
4689 @item --ignore-failed-read
4690 @opindex ignore-failed-read
4691 Do not exit with nonzero on unreadable files or directories.
4692 @end table
4693
4694 @node extract options
4695 @section Options Used by @option{--extract}
4696 @UNREVISED
4697
4698 @xopindex{extract, additional options}
4699 The previous chapter showed how to use @option{--extract} to extract
4700 an archive into the file system. Various options cause @command{tar} to
4701 extract more information than just file contents, such as the owner,
4702 the permissions, the modification date, and so forth. This section
4703 presents options to be used with @option{--extract} when certain special
4704 considerations arise. You may review the information presented in
4705 @ref{extract} for more basic information about the
4706 @option{--extract} operation.
4707
4708 @menu
4709 * Reading:: Options to Help Read Archives
4710 * Writing:: Changing How @command{tar} Writes Files
4711 * Scarce:: Coping with Scarce Resources
4712 @end menu
4713
4714 @node Reading
4715 @subsection Options to Help Read Archives
4716 @cindex Options when reading archives
4717 @UNREVISED
4718
4719 @cindex Reading incomplete records
4720 @cindex Records, incomplete
4721 @opindex read-full-records
4722 Normally, @command{tar} will request data in full record increments from
4723 an archive storage device. If the device cannot return a full record,
4724 @command{tar} will report an error. However, some devices do not always
4725 return full records, or do not require the last record of an archive to
4726 be padded out to the next record boundary. To keep reading until you
4727 obtain a full record, or to accept an incomplete record if it contains
4728 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4729 in conjunction with the @option{--extract} or @option{--list} operations.
4730 @xref{Blocking}.
4731
4732 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4733 @command{tar} reads an archive from standard input, or from a remote
4734 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
4735 pipe returns however much happens to be in the pipe, even if it is
4736 less than was requested. If this option were not enabled, @command{tar}
4737 would fail as soon as it read an incomplete record from the pipe.
4738
4739 If you're not sure of the blocking factor of an archive, you can
4740 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4741 @option{--blocking-factor=@var{512-size}} (@option{-b
4742 @var{512-size}}), using a blocking factor larger than what the archive
4743 uses. This lets you avoid having to determine the blocking factor
4744 of an archive. @xref{Blocking Factor}.
4745
4746 @menu
4747 * read full records::
4748 * Ignore Zeros::
4749 @end menu
4750
4751 @node read full records
4752 @unnumberedsubsubsec Reading Full Records
4753
4754 @FIXME{need sentence or so of intro here}
4755
4756 @table @option
4757 @opindex read-full-records
4758 @item --read-full-records
4759 @item -B
4760 Use in conjunction with @option{--extract} (@option{--get},
4761 @option{-x}) to read an archive which contains incomplete records, or
4762 one which has a blocking factor less than the one specified.
4763 @end table
4764
4765 @node Ignore Zeros
4766 @unnumberedsubsubsec Ignoring Blocks of Zeros
4767
4768 @cindex End-of-archive blocks, ignoring
4769 @cindex Ignoring end-of-archive blocks
4770 @opindex ignore-zeros
4771 Normally, @command{tar} stops reading when it encounters a block of zeros
4772 between file entries (which usually indicates the end of the archive).
4773 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4774 completely read an archive which contains a block of zeros before the
4775 end (i.e., a damaged archive, or one that was created by concatenating
4776 several archives together).
4777
4778 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4779 versions of @command{tar} write garbage after the end-of-archive entry,
4780 since that part of the media is never supposed to be read. @GNUTAR{}
4781 does not write after the end of an archive, but seeks to
4782 maintain compatibility among archiving utilities.
4783
4784 @table @option
4785 @item --ignore-zeros
4786 @itemx -i
4787 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4788 encountered while reading an archive. Use in conjunction with
4789 @option{--extract} or @option{--list}.
4790 @end table
4791
4792 @node Writing
4793 @subsection Changing How @command{tar} Writes Files
4794 @UNREVISED
4795
4796 @FIXME{Introductory paragraph}
4797
4798 @menu
4799 * Dealing with Old Files::
4800 * Overwrite Old Files::
4801 * Keep Old Files::
4802 * Keep Newer Files::
4803 * Unlink First::
4804 * Recursive Unlink::
4805 * Data Modification Times::
4806 * Setting Access Permissions::
4807 * Directory Modification Times and Permissions::
4808 * Writing to Standard Output::
4809 * Writing to an External Program::
4810 * remove files::
4811 @end menu
4812
4813 @node Dealing with Old Files
4814 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4815
4816 @xopindex{overwrite-dir, introduced}
4817 When extracting files, if @command{tar} discovers that the extracted
4818 file already exists, it normally replaces the file by removing it before
4819 extracting it, to prevent confusion in the presence of hard or symbolic
4820 links. (If the existing file is a symbolic link, it is removed, not
4821 followed.) However, if a directory cannot be removed because it is
4822 nonempty, @command{tar} normally overwrites its metadata (ownership,
4823 permission, etc.). The @option{--overwrite-dir} option enables this
4824 default behavior. To be more cautious and preserve the metadata of
4825 such a directory, use the @option{--no-overwrite-dir} option.
4826
4827 @cindex Overwriting old files, prevention
4828 @xopindex{keep-old-files, introduced}
4829 To be even more cautious and prevent existing files from being replaced, use
4830 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4831 to replace or update a file that already exists, i.e., a file with the
4832 same name as an archive member prevents extraction of that archive
4833 member. Instead, it reports an error.
4834
4835 @xopindex{overwrite, introduced}
4836 To be more aggressive about altering existing files, use the
4837 @option{--overwrite} option. It causes @command{tar} to overwrite
4838 existing files and to follow existing symbolic links when extracting.
4839
4840 @cindex Protecting old files
4841 Some people argue that @GNUTAR{} should not hesitate
4842 to overwrite files with other files when extracting. When extracting
4843 a @command{tar} archive, they expect to see a faithful copy of the
4844 state of the file system when the archive was created. It is debatable
4845 that this would always be a proper behavior. For example, suppose one
4846 has an archive in which @file{usr/local} is a link to
4847 @file{usr/local2}. Since then, maybe the site removed the link and
4848 renamed the whole hierarchy from @file{/usr/local2} to
4849 @file{/usr/local}. Such things happen all the time. I guess it would
4850 not be welcome at all that @GNUTAR{} removes the
4851 whole hierarchy just to make room for the link to be reinstated
4852 (unless it @emph{also} simultaneously restores the full
4853 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4854 able to remove a whole hierarchy to reestablish a symbolic link, for
4855 example, but @emph{only if} @option{--recursive-unlink} is specified
4856 to allow this behavior. In any case, single files are silently
4857 removed.
4858
4859 @xopindex{unlink-first, introduced}
4860 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4861 some cases by causing @command{tar} to remove files unconditionally
4862 before extracting them.
4863
4864 @node Overwrite Old Files
4865 @unnumberedsubsubsec Overwrite Old Files
4866
4867 @table @option
4868 @opindex overwrite
4869 @item --overwrite
4870 Overwrite existing files and directory metadata when extracting files
4871 from an archive.
4872
4873 This causes @command{tar} to write extracted files into the file system without
4874 regard to the files already on the system; i.e., files with the same
4875 names as archive members are overwritten when the archive is extracted.
4876 It also causes @command{tar} to extract the ownership, permissions,
4877 and time stamps onto any preexisting files or directories.
4878 If the name of a corresponding file name is a symbolic link, the file
4879 pointed to by the symbolic link will be overwritten instead of the
4880 symbolic link itself (if this is possible). Moreover, special devices,
4881 empty directories and even symbolic links are automatically removed if
4882 they are in the way of extraction.
4883
4884 Be careful when using the @option{--overwrite} option, particularly when
4885 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4886 can change the contents, ownership or permissions of any file on your
4887 system. Also, many systems do not take kindly to overwriting files that
4888 are currently being executed.
4889
4890 @opindex overwrite-dir
4891 @item --overwrite-dir
4892 Overwrite the metadata of directories when extracting files from an
4893 archive, but remove other files before extracting.
4894 @end table
4895
4896 @node Keep Old Files
4897 @unnumberedsubsubsec Keep Old Files
4898
4899 @table @option
4900 @opindex keep-old-files
4901 @item --keep-old-files
4902 @itemx -k
4903 Do not replace existing files from archive. The
4904 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4905 from replacing existing files with files with the same name from the
4906 archive. The @option{--keep-old-files} option is meaningless with
4907 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4908 files in the file system during extraction.
4909 @end table
4910
4911 @node Keep Newer Files
4912 @unnumberedsubsubsec Keep Newer Files
4913
4914 @table @option
4915 @opindex keep-newer-files
4916 @item --keep-newer-files
4917 Do not replace existing files that are newer than their archive
4918 copies. This option is meaningless with @option{--list} (@option{-t}).
4919 @end table
4920
4921 @node Unlink First
4922 @unnumberedsubsubsec Unlink First
4923
4924 @table @option
4925 @opindex unlink-first
4926 @item --unlink-first
4927 @itemx -U
4928 Remove files before extracting over them.
4929 This can make @command{tar} run a bit faster if you know in advance
4930 that the extracted files all need to be removed. Normally this option
4931 slows @command{tar} down slightly, so it is disabled by default.
4932 @end table
4933
4934 @node Recursive Unlink
4935 @unnumberedsubsubsec Recursive Unlink
4936
4937 @table @option
4938 @opindex recursive-unlink
4939 @item --recursive-unlink
4940 When this option is specified, try removing files and directory hierarchies
4941 before extracting over them. @emph{This is a dangerous option!}
4942 @end table
4943
4944 If you specify the @option{--recursive-unlink} option,
4945 @command{tar} removes @emph{anything} that keeps you from extracting a file
4946 as far as current permissions will allow it. This could include removal
4947 of the contents of a full directory hierarchy.
4948
4949 @node Data Modification Times
4950 @unnumberedsubsubsec Setting Data Modification Times
4951
4952 @cindex Data modification times of extracted files
4953 @cindex Modification times of extracted files
4954 Normally, @command{tar} sets the data modification times of extracted
4955 files to the corresponding times recorded for the files in the archive, but
4956 limits the permissions of extracted files by the current @code{umask}
4957 setting.
4958
4959 To set the data modification times of extracted files to the time when
4960 the files were extracted, use the @option{--touch} (@option{-m}) option in
4961 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4962
4963 @table @option
4964 @opindex touch
4965 @item --touch
4966 @itemx -m
4967 Sets the data modification time of extracted archive members to the time
4968 they were extracted, not the time recorded for them in the archive.
4969 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4970 @end table
4971
4972 @node Setting Access Permissions
4973 @unnumberedsubsubsec Setting Access Permissions
4974
4975 @cindex Permissions of extracted files
4976 @cindex Modes of extracted files
4977 To set the modes (access permissions) of extracted files to those
4978 recorded for those files in the archive, use @option{--same-permissions}
4979 in conjunction with the @option{--extract} (@option{--get},
4980 @option{-x}) operation.
4981
4982 @table @option
4983 @opindex preserve-permissions
4984 @opindex same-permissions
4985 @item --preserve-permissions
4986 @itemx --same-permissions
4987 @c @itemx --ignore-umask
4988 @itemx -p
4989 Set modes of extracted archive members to those recorded in the
4990 archive, instead of current umask settings. Use in conjunction with
4991 @option{--extract} (@option{--get}, @option{-x}).
4992 @end table
4993
4994 @node Directory Modification Times and Permissions
4995 @unnumberedsubsubsec Directory Modification Times and Permissions
4996
4997 After successfully extracting a file member, @GNUTAR{} normally
4998 restores its permissions and modification times, as described in the
4999 previous sections. This cannot be done for directories, because
5000 after extracting a directory @command{tar} will almost certainly
5001 extract files into that directory and this will cause the directory
5002 modification time to be updated. Moreover, restoring that directory
5003 permissions may not permit file creation within it. Thus, restoring
5004 directory permissions and modification times must be delayed at least
5005 until all files have been extracted into that directory. @GNUTAR{}
5006 restores directories using the following approach.
5007
5008 The extracted directories are created with the mode specified in the
5009 archive, as modified by the umask of the user, which gives sufficient
5010 permissions to allow file creation. The meta-information about the
5011 directory is recorded in the temporary list of directories. When
5012 preparing to extract next archive member, @GNUTAR{} checks if the
5013 directory prefix of this file contains the remembered directory. If
5014 it does not, the program assumes that all files have been extracted
5015 into that directory, restores its modification time and permissions
5016 and removes its entry from the internal list. This approach allows
5017 to correctly restore directory meta-information in the majority of
5018 cases, while keeping memory requirements sufficiently small. It is
5019 based on the fact, that most @command{tar} archives use the predefined
5020 order of members: first the directory, then all the files and
5021 subdirectories in that directory.
5022
5023 However, this is not always true. The most important exception are
5024 incremental archives (@pxref{Incremental Dumps}). The member order in
5025 an incremental archive is reversed: first all directory members are
5026 stored, followed by other (non-directory) members. So, when extracting
5027 from incremental archives, @GNUTAR{} alters the above procedure. It
5028 remembers all restored directories, and restores their meta-data
5029 only after the entire archive has been processed. Notice, that you do
5030 not need to specify any special options for that, as @GNUTAR{}
5031 automatically detects archives in incremental format.
5032
5033 There may be cases, when such processing is required for normal archives
5034 too. Consider the following example:
5035
5036 @smallexample
5037 @group
5038 $ @kbd{tar --no-recursion -cvf archive \
5039 foo foo/file1 bar bar/file foo/file2}
5040 foo/
5041 foo/file1
5042 bar/
5043 bar/file
5044 foo/file2
5045 @end group
5046 @end smallexample
5047
5048 During the normal operation, after encountering @file{bar}
5049 @GNUTAR{} will assume that all files from the directory @file{foo}
5050 were already extracted and will therefore restore its timestamp and
5051 permission bits. However, after extracting @file{foo/file2} the
5052 directory timestamp will be offset again.
5053
5054 To correctly restore directory meta-information in such cases, use
5055 @option{delay-directory-restore} command line option:
5056
5057 @table @option
5058 @opindex delay-directory-restore
5059 @item --delay-directory-restore
5060 Delays restoring of the modification times and permissions of extracted
5061 directories until the end of extraction. This way, correct
5062 meta-information is restored even if the archive has unusual member
5063 ordering.
5064
5065 @opindex no-delay-directory-restore
5066 @item --no-delay-directory-restore
5067 Cancel the effect of the previous @option{--delay-directory-restore}.
5068 Use this option if you have used @option{--delay-directory-restore} in
5069 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5070 temporarily disable it.
5071 @end table
5072
5073 @node Writing to Standard Output
5074 @unnumberedsubsubsec Writing to Standard Output
5075
5076 @cindex Writing extracted files to standard output
5077 @cindex Standard output, writing extracted files to
5078 To write the extracted files to the standard output, instead of
5079 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5080 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5081 extracting files to send them through a pipe, and do not need to
5082 preserve them in the file system. If you extract multiple members,
5083 they appear on standard output concatenated, in the order they are
5084 found in the archive.
5085
5086 @table @option
5087 @opindex to-stdout
5088 @item --to-stdout
5089 @itemx -O
5090 Writes files to the standard output. Use only in conjunction with
5091 @option{--extract} (@option{--get}, @option{-x}). When this option is
5092 used, instead of creating the files specified, @command{tar} writes
5093 the contents of the files extracted to its standard output. This may
5094 be useful if you are only extracting the files in order to send them
5095 through a pipe. This option is meaningless with @option{--list}
5096 (@option{-t}).
5097 @end table
5098
5099 This can be useful, for example, if you have a tar archive containing
5100 a big file and don't want to store the file on disk before processing
5101 it. You can use a command like this:
5102
5103 @smallexample
5104 tar -xOzf foo.tgz bigfile | process
5105 @end smallexample
5106
5107 or even like this if you want to process the concatenation of the files:
5108
5109 @smallexample
5110 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5111 @end smallexample
5112
5113 However, @option{--to-command} may be more convenient for use with
5114 multiple files. See the next section.
5115
5116 @node Writing to an External Program
5117 @unnumberedsubsubsec Writing to an External Program
5118
5119 You can instruct @command{tar} to send the contents of each extracted
5120 file to the standard input of an external program:
5121
5122 @table @option
5123 @opindex to-command
5124 @item --to-command=@var{command}
5125 Extract files and pipe their contents to the standard input of
5126 @var{command}. When this option is used, instead of creating the
5127 files specified, @command{tar} invokes @var{command} and pipes the
5128 contents of the files to its standard output. @var{Command} may
5129 contain command line arguments. The program is executed via
5130 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5131 extracted. Non-regular files (directories, etc.) are ignored when this
5132 option is used.
5133 @end table
5134
5135 The command can obtain the information about the file it processes
5136 from the following environment variables:
5137
5138 @table @env
5139 @vrindex TAR_FILETYPE, to-command environment
5140 @item TAR_FILETYPE
5141 Type of the file. It is a single letter with the following meaning:
5142
5143 @multitable @columnfractions 0.10 0.90
5144 @item f @tab Regular file
5145 @item d @tab Directory
5146 @item l @tab Symbolic link
5147 @item h @tab Hard link
5148 @item b @tab Block device
5149 @item c @tab Character device
5150 @end multitable
5151
5152 Currently only regular files are supported.
5153
5154 @vrindex TAR_MODE, to-command environment
5155 @item TAR_MODE
5156 File mode, an octal number.
5157
5158 @vrindex TAR_FILENAME, to-command environment
5159 @item TAR_FILENAME
5160 The name of the file.
5161
5162 @vrindex TAR_REALNAME, to-command environment
5163 @item TAR_REALNAME
5164 Name of the file as stored in the archive.
5165
5166 @vrindex TAR_UNAME, to-command environment
5167 @item TAR_UNAME
5168 Name of the file owner.
5169
5170 @vrindex TAR_GNAME, to-command environment
5171 @item TAR_GNAME
5172 Name of the file owner group.
5173
5174 @vrindex TAR_ATIME, to-command environment
5175 @item TAR_ATIME
5176 Time of last access. It is a decimal number, representing seconds
5177 since the epoch. If the archive provides times with nanosecond
5178 precision, the nanoseconds are appended to the timestamp after a
5179 decimal point.
5180
5181 @vrindex TAR_MTIME, to-command environment
5182 @item TAR_MTIME
5183 Time of last modification.
5184
5185 @vrindex TAR_CTIME, to-command environment
5186 @item TAR_CTIME
5187 Time of last status change.
5188
5189 @vrindex TAR_SIZE, to-command environment
5190 @item TAR_SIZE
5191 Size of the file.
5192
5193 @vrindex TAR_UID, to-command environment
5194 @item TAR_UID
5195 UID of the file owner.
5196
5197 @vrindex TAR_GID, to-command environment
5198 @item TAR_GID
5199 GID of the file owner.
5200 @end table
5201
5202 In addition to these variables, @env{TAR_VERSION} contains the
5203 @GNUTAR{} version number.
5204
5205 If @var{command} exits with a non-0 status, @command{tar} will print
5206 an error message similar to the following:
5207
5208 @smallexample
5209 tar: 2345: Child returned status 1
5210 @end smallexample
5211
5212 Here, @samp{2345} is the PID of the finished process.
5213
5214 If this behavior is not wanted, use @option{--ignore-command-error}:
5215
5216 @table @option
5217 @opindex ignore-command-error
5218 @item --ignore-command-error
5219 Ignore exit codes of subprocesses. Notice that if the program
5220 exits on signal or otherwise terminates abnormally, the error message
5221 will be printed even if this option is used.
5222
5223 @opindex no-ignore-command-error
5224 @item --no-ignore-command-error
5225 Cancel the effect of any previous @option{--ignore-command-error}
5226 option. This option is useful if you have set
5227 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5228 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5229 @end table
5230
5231 @node remove files
5232 @unnumberedsubsubsec Removing Files
5233
5234 @FIXME{The section is too terse. Something more to add? An example,
5235 maybe?}
5236
5237 @table @option
5238 @opindex remove-files
5239 @item --remove-files
5240 Remove files after adding them to the archive.
5241 @end table
5242
5243 @node Scarce
5244 @subsection Coping with Scarce Resources
5245 @UNREVISED
5246
5247 @cindex Small memory
5248 @cindex Running out of space
5249
5250 @menu
5251 * Starting File::
5252 * Same Order::
5253 @end menu
5254
5255 @node Starting File
5256 @unnumberedsubsubsec Starting File
5257
5258 @table @option
5259 @opindex starting-file
5260 @item --starting-file=@var{name}
5261 @itemx -K @var{name}
5262 Starts an operation in the middle of an archive. Use in conjunction
5263 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5264 @end table
5265
5266 @cindex Middle of the archive, starting in the
5267 If a previous attempt to extract files failed due to lack of disk
5268 space, you can use @option{--starting-file=@var{name}} (@option{-K
5269 @var{name}}) to start extracting only after member @var{name} of the
5270 archive. This assumes, of course, that there is now free space, or
5271 that you are now extracting into a different file system. (You could
5272 also choose to suspend @command{tar}, remove unnecessary files from
5273 the file system, and then restart the same @command{tar} operation.
5274 In this case, @option{--starting-file} is not necessary.
5275 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
5276
5277 @node Same Order
5278 @unnumberedsubsubsec Same Order
5279
5280 @table @option
5281 @cindex Large lists of file names on small machines
5282 @opindex same-order
5283 @opindex preserve-order
5284 @item --same-order
5285 @itemx --preserve-order
5286 @itemx -s
5287 To process large lists of file names on machines with small amounts of
5288 memory. Use in conjunction with @option{--compare} (@option{--diff},
5289 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5290 (@option{--get}, @option{-x}).
5291 @end table
5292
5293 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5294 names to be listed or extracted is sorted in the same order as the
5295 files in the archive. This allows a large list of names to be used,
5296 even on a small machine that would not otherwise be able to hold all
5297 the names in memory at the same time. Such a sorted list can easily be
5298 created by running @samp{tar -t} on the archive and editing its output.
5299
5300 This option is probably never needed on modern computer systems.
5301
5302 @node backup
5303 @section Backup options
5304
5305 @cindex backup options
5306
5307 @GNUTAR{} offers options for making backups of files
5308 before writing new versions. These options control the details of
5309 these backups. They may apply to the archive itself before it is
5310 created or rewritten, as well as individual extracted members. Other
5311 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5312 and @command{mv}, for example) offer similar options.
5313
5314 Backup options may prove unexpectedly useful when extracting archives
5315 containing many members having identical name, or when extracting archives
5316 on systems having file name limitations, making different members appear
5317 has having similar names through the side-effect of name truncation.
5318 (This is true only if we have a good scheme for truncated backup names,
5319 which I'm not sure at all: I suspect work is needed in this area.)
5320 When any existing file is backed up before being overwritten by extraction,
5321 then clashing files are automatically be renamed to be unique, and the
5322 true name is kept for only the last file of a series of clashing files.
5323 By using verbose mode, users may track exactly what happens.
5324
5325 At the detail level, some decisions are still experimental, and may
5326 change in the future, we are waiting comments from our users. So, please
5327 do not learn to depend blindly on the details of the backup features.
5328 For example, currently, directories themselves are never renamed through
5329 using these options, so, extracting a file over a directory still has
5330 good chances to fail. Also, backup options apply to created archives,
5331 not only to extracted members. For created archives, backups will not
5332 be attempted when the archive is a block or character device, or when it
5333 refers to a remote file.
5334
5335 For the sake of simplicity and efficiency, backups are made by renaming old
5336 files prior to creation or extraction, and not by copying. The original
5337 name is restored if the file creation fails. If a failure occurs after a
5338 partial extraction of a file, both the backup and the partially extracted
5339 file are kept.
5340
5341 @table @samp
5342 @item --backup[=@var{method}]
5343 @opindex backup
5344 @vindex VERSION_CONTROL
5345 @cindex backups
5346 Back up files that are about to be overwritten or removed.
5347 Without this option, the original versions are destroyed.
5348
5349 Use @var{method} to determine the type of backups made.
5350 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5351 environment variable. And if @env{VERSION_CONTROL} is not set,
5352 use the @samp{existing} method.
5353
5354 @vindex version-control @r{Emacs variable}
5355 This option corresponds to the Emacs variable @samp{version-control};
5356 the same values for @var{method} are accepted as in Emacs. This option
5357 also allows more descriptive names. The valid @var{method}s are:
5358
5359 @table @samp
5360 @item t
5361 @itemx numbered
5362 @cindex numbered @r{backup method}
5363 Always make numbered backups.
5364
5365 @item nil
5366 @itemx existing
5367 @cindex existing @r{backup method}
5368 Make numbered backups of files that already have them, simple backups
5369 of the others.
5370
5371 @item never
5372 @itemx simple
5373 @cindex simple @r{backup method}
5374 Always make simple backups.
5375
5376 @end table
5377
5378 @item --suffix=@var{suffix}
5379 @opindex suffix
5380 @cindex backup suffix
5381 @vindex SIMPLE_BACKUP_SUFFIX
5382 Append @var{suffix} to each backup file made with @option{--backup}. If this
5383 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5384 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5385 set, the default is @samp{~}, just as in Emacs.
5386
5387 @end table
5388
5389 @node Applications
5390 @section Notable @command{tar} Usages
5391 @UNREVISED
5392
5393 @FIXME{Using Unix file linking capability to recreate directory
5394 structures---linking files into one subdirectory and then
5395 @command{tar}ring that directory.}
5396
5397 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5398
5399 @findex uuencode
5400 You can easily use archive files to transport a group of files from
5401 one system to another: put all relevant files into an archive on one
5402 computer system, transfer the archive to another system, and extract
5403 the contents there. The basic transfer medium might be magnetic tape,
5404 Internet FTP, or even electronic mail (though you must encode the
5405 archive with @command{uuencode} in order to transport it properly by
5406 mail). Both machines do not have to use the same operating system, as
5407 long as they both support the @command{tar} program.
5408
5409 For example, here is how you might copy a directory's contents from
5410 one disk to another, while preserving the dates, modes, owners and
5411 link-structure of all the files therein. In this case, the transfer
5412 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5413
5414 @smallexample
5415 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5416 @end smallexample
5417
5418 @noindent
5419 You can avoid subshells by using @option{-C} option:
5420
5421 @smallexample
5422 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5423 @end smallexample
5424
5425 @noindent
5426 The command also works using short option forms:
5427
5428 @smallexample
5429 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5430 | (cd targetdir; tar --extract --file=-)}
5431 # Or:
5432 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5433 | tar --directory targetdir --extract --file=-}
5434 @end smallexample
5435
5436 @noindent
5437 This is one of the easiest methods to transfer a @command{tar} archive.
5438
5439 @node looking ahead
5440 @section Looking Ahead: The Rest of this Manual
5441
5442 You have now seen how to use all eight of the operations available to
5443 @command{tar}, and a number of the possible options. The next chapter
5444 explains how to choose and change file and archive names, how to use
5445 files to store names of other files which you can then call as
5446 arguments to @command{tar} (this can help you save time if you expect to
5447 archive the same list of files a number of times), and so forth.
5448 @FIXME{in case it's not obvious, i'm making this up in some sense
5449 based on my limited memory of what the next chapter *really* does. i
5450 just wanted to flesh out this final section a little bit so i'd
5451 remember to stick it in here. :-)}
5452
5453 If there are too many files to conveniently list on the command line,
5454 you can list the names in a file, and @command{tar} will read that file.
5455 @xref{files}.
5456
5457 There are various ways of causing @command{tar} to skip over some files,
5458 and not archive them. @xref{Choosing}.
5459
5460 @node Backups
5461 @chapter Performing Backups and Restoring Files
5462 @UNREVISED
5463
5464 @GNUTAR{} is distributed along with the scripts
5465 which the Free Software Foundation uses for performing backups. There
5466 is no corresponding scripts available yet for doing restoration of
5467 files. Even if there is a good chance those scripts may be satisfying
5468 to you, they are not the only scripts or methods available for doing
5469 backups and restore. You may well create your own, or use more
5470 sophisticated packages dedicated to that purpose.
5471
5472 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5473 Automatic Network Disk Archiver), a backup system developed by James
5474 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5475 This is free software, and it is available at these places:
5476
5477 @smallexample
5478 http://www.cs.umd.edu/projects/amanda/amanda.html
5479 ftp://ftp.cs.umd.edu/pub/amanda
5480 @end smallexample
5481
5482 @FIXME{
5483
5484 Here is a possible plan for a future documentation about the backuping
5485 scripts which are provided within the @GNUTAR{}
5486 distribution.
5487
5488 @itemize @bullet
5489 @item dumps
5490 @itemize @minus
5491 @item what are dumps
5492 @item different levels of dumps
5493 @itemize +
5494 @item full dump = dump everything
5495 @item level 1, level 2 dumps etc
5496 A level @var{n} dump dumps everything changed since the last level
5497 @var{n}-1 dump (?)
5498 @end itemize
5499 @item how to use scripts for dumps (ie, the concept)
5500 @itemize +
5501 @item scripts to run after editing backup specs (details)
5502 @end itemize
5503 @item Backup Specs, what is it.
5504 @itemize +
5505 @item how to customize
5506 @item actual text of script [/sp/dump/backup-specs]
5507 @end itemize
5508 @item Problems
5509 @itemize +
5510 @item rsh doesn't work
5511 @item rtape isn't installed
5512 @item (others?)
5513 @end itemize
5514 @item the @option{--incremental} option of tar
5515 @item tapes
5516 @itemize +
5517 @item write protection
5518 @item types of media, different sizes and types, useful for different things
5519 @item files and tape marks
5520 one tape mark between files, two at end.
5521 @item positioning the tape
5522 MT writes two at end of write,
5523 backspaces over one when writing again.
5524 @end itemize
5525 @end itemize
5526 @end itemize
5527 }
5528
5529 This chapter documents both the provided shell scripts and @command{tar}
5530 options which are more specific to usage as a backup tool.
5531
5532 To @dfn{back up} a file system means to create archives that contain
5533 all the files in that file system. Those archives can then be used to
5534 restore any or all of those files (for instance if a disk crashes or a
5535 file is accidentally deleted). File system @dfn{backups} are also
5536 called @dfn{dumps}.
5537
5538 @menu
5539 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5540 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5541 * Backup Levels:: Levels of Backups
5542 * Backup Parameters:: Setting Parameters for Backups and Restoration
5543 * Scripted Backups:: Using the Backup Scripts
5544 * Scripted Restoration:: Using the Restore Script
5545 @end menu
5546
5547 @node Full Dumps
5548 @section Using @command{tar} to Perform Full Dumps
5549 @UNREVISED
5550
5551 @cindex full dumps
5552 @cindex dumps, full
5553
5554 @cindex corrupted archives
5555 Full dumps should only be made when no other people or programs
5556 are modifying files in the file system. If files are modified while
5557 @command{tar} is making the backup, they may not be stored properly in
5558 the archive, in which case you won't be able to restore them if you
5559 have to. (Files not being modified are written with no trouble, and do
5560 not corrupt the entire archive.)
5561
5562 You will want to use the @option{--label=@var{archive-label}}
5563 (@option{-V @var{archive-label}}) option to give the archive a
5564 volume label, so you can tell what this archive is even if the label
5565 falls off the tape, or anything like that.
5566
5567 Unless the file system you are dumping is guaranteed to fit on
5568 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5569 Make sure you have enough tapes on hand to complete the backup.
5570
5571 If you want to dump each file system separately you will need to use
5572 the @option{--one-file-system} option to prevent
5573 @command{tar} from crossing file system boundaries when storing
5574 (sub)directories.
5575
5576 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5577 option is not needed, since this is a complete copy of everything in
5578 the file system, and a full restore from this backup would only be
5579 done onto a completely
5580 empty disk.
5581
5582 Unless you are in a hurry, and trust the @command{tar} program (and your
5583 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5584 option, to make sure your files really made it onto the dump properly.
5585 This will also detect cases where the file was modified while (or just
5586 after) it was being archived. Not all media (notably cartridge tapes)
5587 are capable of being verified, unfortunately.
5588
5589 @node Incremental Dumps
5590 @section Using @command{tar} to Perform Incremental Dumps
5591
5592 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5593 stores additional metadata so that exact state of the file system
5594 can be restored when extracting the archive.
5595
5596 @GNUTAR{} currently offers two options for handling incremental
5597 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5598 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5599
5600 @opindex listed-incremental
5601 The option @option{--listed-incremental} instructs tar to operate on
5602 an incremental archive with additional metadata stored in a standalone
5603 file, called a @dfn{snapshot file}. The purpose of this file is to help
5604 determine which files have been changed, added or deleted since the
5605 last backup, so that the next incremental backup will contain only
5606 modified files. The name of the snapshot file is given as an argument
5607 to the option:
5608
5609 @table @option
5610 @item --listed-incremental=@var{file}
5611 @itemx -g @var{file}
5612 Handle incremental backups with snapshot data in @var{file}.
5613 @end table
5614
5615 To create an incremental backup, you would use
5616 @option{--listed-incremental} together with @option{--create}
5617 (@pxref{create}). For example:
5618
5619 @smallexample
5620 $ @kbd{tar --create \
5621 --file=archive.1.tar \
5622 --listed-incremental=/var/log/usr.snar \
5623 /usr}
5624 @end smallexample
5625
5626 This will create in @file{archive.1.tar} an incremental backup of
5627 the @file{/usr} file system, storing additional metadata in the file
5628 @file{/var/log/usr.snar}. If this file does not exist, it will be
5629 created. The created archive will then be a @dfn{level 0 backup};
5630 please see the next section for more on backup levels.
5631
5632 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5633 determines which files are modified. In this case only these files will be
5634 stored in the archive. Suppose, for example, that after running the
5635 above command, you delete file @file{/usr/doc/old} and create
5636 directory @file{/usr/local/db} with the following contents:
5637
5638 @smallexample
5639 $ @kbd{ls /usr/local/db}
5640 /usr/local/db/data
5641 /usr/local/db/index
5642 @end smallexample
5643
5644 Some time later you create another incremental backup. You will
5645 then see:
5646
5647 @smallexample
5648 $ @kbd{tar --create \
5649 --file=archive.2.tar \
5650 --listed-incremental=/var/log/usr.snar \
5651 /usr}
5652 tar: usr/local/db: Directory is new
5653 usr/local/db/
5654 usr/local/db/data
5655 usr/local/db/index
5656 @end smallexample
5657
5658 @noindent
5659 The created archive @file{archive.2.tar} will contain only these
5660 three members. This archive is called a @dfn{level 1 backup}. Notice
5661 that @file{/var/log/usr.snar} will be updated with the new data, so if
5662 you plan to create more @samp{level 1} backups, it is necessary to
5663 create a working copy of the snapshot file before running
5664 @command{tar}. The above example will then be modified as follows:
5665
5666 @smallexample
5667 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5668 $ @kbd{tar --create \
5669 --file=archive.2.tar \
5670 --listed-incremental=/var/log/usr.snar-1 \
5671 /usr}
5672 @end smallexample
5673
5674 Incremental dumps depend crucially on time stamps, so the results are
5675 unreliable if you modify a file's time stamps during dumping (e.g.,
5676 with the @option{--atime-preserve=replace} option), or if you set the clock
5677 backwards.
5678
5679 @cindex Device numbers, using in incremental backups
5680 Metadata stored in snapshot files include device numbers, which,
5681 obviously is supposed to be a non-volatile value. However, it turns
5682 out that NFS devices have undependable values when an automounter
5683 gets in the picture. This can lead to a great deal of spurious
5684 redumping in incremental dumps, so it is somewhat useless to compare
5685 two NFS devices numbers over time. The solution implemented currently
5686 is to considers all NFS devices as being equal when it comes to
5687 comparing directories; this is fairly gross, but there does not seem
5688 to be a better way to go.
5689
5690 If you are using the @i{Linux} kernel, the device numbers can also
5691 change when upgrading to some newer versions of the kernel. This can
5692 cause the next backup to be full backup on the affected filesystems.
5693 @xref{Fixing Snapshot Files}, for the information on how to handle this case.
5694
5695 Note that incremental archives use @command{tar} extensions and may
5696 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5697
5698 @xopindex{listed-incremental, using with @option{--extract}}
5699 @xopindex{extract, using with @option{--listed-incremental}}
5700 To extract from the incremental dumps, use
5701 @option{--listed-incremental} together with @option{--extract}
5702 option (@pxref{extracting files}). In this case, @command{tar} does
5703 not need to access snapshot file, since all the data necessary for
5704 extraction are stored in the archive itself. So, when extracting, you
5705 can give whatever argument to @option{--listed-incremental}, the usual
5706 practice is to use @option{--listed-incremental=/dev/null}.
5707 Alternatively, you can use @option{--incremental}, which needs no
5708 arguments. In general, @option{--incremental} (@option{-G}) can be
5709 used as a shortcut for @option{--listed-incremental} when listing or
5710 extracting incremental backups (for more information, regarding this
5711 option, @pxref{incremental-op}).
5712
5713 When extracting from the incremental backup @GNUTAR{} attempts to
5714 restore the exact state the file system had when the archive was
5715 created. In particular, it will @emph{delete} those files in the file
5716 system that did not exist in their directories when the archive was
5717 created. If you have created several levels of incremental files,
5718 then in order to restore the exact contents the file system had when
5719 the last level was created, you will need to restore from all backups
5720 in turn. Continuing our example, to restore the state of @file{/usr}
5721 file system, one would do@footnote{Notice, that since both archives
5722 were created without @option{-P} option (@pxref{absolute}), these
5723 commands should be run from the root file system.}:
5724
5725 @smallexample
5726 $ @kbd{tar --extract \
5727 --listed-incremental=/dev/null \
5728 --file archive.1.tar}
5729 $ @kbd{tar --extract \
5730 --listed-incremental=/dev/null \
5731 --file archive.2.tar}
5732 @end smallexample
5733
5734 To list the contents of an incremental archive, use @option{--list}
5735 (@pxref{list}), as usual. To obtain more information about the
5736 archive, use @option{--listed-incremental} or @option{--incremental}
5737 combined with two @option{--verbose} options@footnote{Two
5738 @option{--verbose} options were selected to avoid breaking usual
5739 verbose listing output (@option{--list --verbose}) when using in
5740 scripts.
5741
5742 @xopindex{incremental, using with @option{--list}}
5743 @xopindex{listed-incremental, using with @option{--list}}
5744 @xopindex{list, using with @option{--incremental}}
5745 @xopindex{list, using with @option{--listed-incremental}}
5746 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5747 contents of the DUMPDIR header (with terminating nulls) when
5748 @option{--incremental} or @option{--listed-incremental} option was
5749 given, no matter what the verbosity level. This behavior, and,
5750 especially, the binary output it produced were considered inconvenient
5751 and were changed in version 1.16}:
5752
5753 @smallexample
5754 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5755 @end smallexample
5756
5757 This command will print, for each directory in the archive, the list
5758 of files in that directory at the time the archive was created. This
5759 information is put out in a format which is both human-readable and
5760 unambiguous for a program: each file name is printed as
5761
5762 @smallexample
5763 @var{x} @var{file}
5764 @end smallexample
5765
5766 @noindent
5767 where @var{x} is a letter describing the status of the file: @samp{Y}
5768 if the file is present in the archive, @samp{N} if the file is not
5769 included in the archive, or a @samp{D} if the file is a directory (and
5770 is included in the archive). @xref{Dumpdir}, for the detailed
5771 description of dumpdirs and status codes. Each such
5772 line is terminated by a newline character. The last line is followed
5773 by an additional newline to indicate the end of the data.
5774
5775 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5776 gives the same behavior as @option{--listed-incremental} when used
5777 with @option{--list} and @option{--extract} options. When used with
5778 @option{--create} option, it creates an incremental archive without
5779 creating snapshot file. Thus, it is impossible to create several
5780 levels of incremental backups with @option{--incremental} option.
5781
5782 @node Backup Levels
5783 @section Levels of Backups
5784
5785 An archive containing all the files in the file system is called a
5786 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5787 creating a full dump every day. This strategy, however, would waste a
5788 substantial amount of archive media and user time, as unchanged files
5789 are daily re-archived.
5790
5791 It is more efficient to do a full dump only occasionally. To back up
5792 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5793 one} dump archives all the files that have changed since the last full
5794 dump.
5795
5796 A typical dump strategy would be to perform a full dump once a week,
5797 and a level one dump once a day. This means some versions of files
5798 will in fact be archived more than once, but this dump strategy makes
5799 it possible to restore a file system to within one day of accuracy by
5800 only extracting two archives---the last weekly (full) dump and the
5801 last daily (level one) dump. The only information lost would be in
5802 files changed or created since the last daily backup. (Doing dumps
5803 more than once a day is usually not worth the trouble).
5804
5805 @GNUTAR{} comes with scripts you can use to do full
5806 and level-one (actually, even level-two and so on) dumps. Using
5807 scripts (shell programs) to perform backups and restoration is a
5808 convenient and reliable alternative to typing out file name lists
5809 and @command{tar} commands by hand.
5810
5811 Before you use these scripts, you need to edit the file
5812 @file{backup-specs}, which specifies parameters used by the backup
5813 scripts and by the restore script. This file is usually located
5814 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5815 detailed description. Once the backup parameters are set, you can
5816 perform backups or restoration by running the appropriate script.
5817
5818 The name of the backup script is @code{backup}. The name of the
5819 restore script is @code{restore}. The following sections describe
5820 their use in detail.
5821
5822 @emph{Please Note:} The backup and restoration scripts are
5823 designed to be used together. While it is possible to restore files by
5824 hand from an archive which was created using a backup script, and to create
5825 an archive by hand which could then be extracted using the restore script,
5826 it is easier to use the scripts. @xref{Incremental Dumps}, before
5827 making such an attempt.
5828
5829 @node Backup Parameters
5830 @section Setting Parameters for Backups and Restoration
5831
5832 The file @file{backup-specs} specifies backup parameters for the
5833 backup and restoration scripts provided with @command{tar}. You must
5834 edit @file{backup-specs} to fit your system configuration and schedule
5835 before using these scripts.
5836
5837 Syntactically, @file{backup-specs} is a shell script, containing
5838 mainly variable assignments. However, any valid shell construct
5839 is allowed in this file. Particularly, you may wish to define
5840 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5841 For more information about shell script syntax, please refer to
5842 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5843 g_02, the definition of the Shell Command Language}. See also
5844 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5845
5846 The shell variables controlling behavior of @code{backup} and
5847 @code{restore} are described in the following subsections.
5848
5849 @menu
5850 * General-Purpose Variables::
5851 * Magnetic Tape Control::
5852 * User Hooks::
5853 * backup-specs example:: An Example Text of @file{Backup-specs}
5854 @end menu
5855
5856 @node General-Purpose Variables
5857 @subsection General-Purpose Variables
5858
5859 @defvr {Backup variable} ADMINISTRATOR
5860 The user name of the backup administrator. @code{Backup} scripts
5861 sends a backup report to this address.
5862 @end defvr
5863
5864 @defvr {Backup variable} BACKUP_HOUR
5865 The hour at which the backups are done. This can be a number from 0
5866 to 23, or the time specification in form @var{hours}:@var{minutes},
5867 or the string @samp{now}.
5868
5869 This variable is used by @code{backup}. Its value may be overridden
5870 using @option{--time} option (@pxref{Scripted Backups}).
5871 @end defvr
5872
5873 @defvr {Backup variable} TAPE_FILE
5874
5875 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5876 is a remote archive (@pxref{remote-dev}), backup script will suppose
5877 that your @command{mt} is able to access remote devices. If @var{RSH}
5878 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5879 invocations of @command{mt}.
5880 @end defvr
5881
5882 @defvr {Backup variable} BLOCKING
5883
5884 The blocking factor @command{tar} will use when writing the dump archive.
5885 @xref{Blocking Factor}.
5886 @end defvr
5887
5888 @defvr {Backup variable} BACKUP_DIRS
5889
5890 A list of file systems to be dumped (for @code{backup}), or restored
5891 (for @code{restore}). You can include any directory
5892 name in the list --- subdirectories on that file system will be
5893 included, regardless of how they may look to other networked machines.
5894 Subdirectories on other file systems will be ignored.
5895
5896 The host name specifies which host to run @command{tar} on, and should
5897 normally be the host that actually contains the file system. However,
5898 the host machine must have @GNUTAR{} installed, and
5899 must be able to access the directory containing the backup scripts and
5900 their support files using the same file name that is used on the
5901 machine where the scripts are run (i.e., what @command{pwd} will print
5902 when in that directory on that machine). If the host that contains
5903 the file system does not have this capability, you can specify another
5904 host as long as it can access the file system through NFS.
5905
5906 If the list of file systems is very long you may wish to put it
5907 in a separate file. This file is usually named
5908 @file{/etc/backup/dirs}, but this name may be overridden in
5909 @file{backup-specs} using @code{DIRLIST} variable.
5910 @end defvr
5911
5912 @defvr {Backup variable} DIRLIST
5913
5914 The name of the file that contains a list of file systems to backup
5915 or restore. By default it is @file{/etc/backup/dirs}.
5916 @end defvr
5917
5918 @defvr {Backup variable} BACKUP_FILES
5919
5920 A list of individual files to be dumped (for @code{backup}), or restored
5921 (for @code{restore}). These should be accessible from the machine on
5922 which the backup script is run.
5923
5924 If the list of file systems is very long you may wish to store it
5925 in a separate file. This file is usually named
5926 @file{/etc/backup/files}, but this name may be overridden in
5927 @file{backup-specs} using @code{FILELIST} variable.
5928 @end defvr
5929
5930 @defvr {Backup variable} FILELIST
5931
5932 The name of the file that contains a list of individual files to backup
5933 or restore. By default it is @file{/etc/backup/files}.
5934 @end defvr
5935
5936 @defvr {Backup variable} MT
5937
5938 Full file name of @command{mt} binary.
5939 @end defvr
5940
5941 @defvr {Backup variable} RSH
5942 @anchor{RSH}
5943 Full file name of @command{rsh} binary or its equivalent. You may wish to
5944 set it to @code{ssh}, to improve security. In this case you will have
5945 to use public key authentication.
5946 @end defvr
5947
5948 @defvr {Backup variable} RSH_COMMAND
5949
5950 Full file name of @command{rsh} binary on remote machines. This will
5951 be passed via @option{--rsh-command} option to the remote invocation
5952 of @GNUTAR{}.
5953 @end defvr
5954
5955 @defvr {Backup variable} VOLNO_FILE
5956
5957 Name of temporary file to hold volume numbers. This needs to be accessible
5958 by all the machines which have file systems to be dumped.
5959 @end defvr
5960
5961 @defvr {Backup variable} XLIST
5962
5963 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5964 located on the remote machine and containing the list of files to
5965 be excluded from the backup. Exclude file lists are searched in
5966 /etc/tar-backup directory. A common use for exclude file lists
5967 is to exclude files containing security-sensitive information
5968 (e.g., @file{/etc/shadow} from backups).
5969
5970 This variable affects only @code{backup}.
5971 @end defvr
5972
5973 @defvr {Backup variable} SLEEP_TIME
5974
5975 Time to sleep between dumps of any two successive file systems
5976
5977 This variable affects only @code{backup}.
5978 @end defvr
5979
5980 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5981
5982 Script to be run when it's time to insert a new tape in for the next
5983 volume. Administrators may want to tailor this script for their site.
5984 If this variable isn't set, @GNUTAR{} will display its built-in
5985 prompt, and will expect confirmation from the console. For the
5986 description of the default prompt, see @ref{change volume prompt}.
5987
5988 @end defvr
5989
5990 @defvr {Backup variable} SLEEP_MESSAGE
5991
5992 Message to display on the terminal while waiting for dump time. Usually
5993 this will just be some literal text.
5994 @end defvr
5995
5996 @defvr {Backup variable} TAR
5997
5998 Full file name of the @GNUTAR{} executable. If this is not set, backup
5999 scripts will search @command{tar} in the current shell path.
6000 @end defvr
6001
6002 @node Magnetic Tape Control
6003 @subsection Magnetic Tape Control
6004
6005 Backup scripts access tape device using special @dfn{hook functions}.
6006 These functions take a single argument -- the name of the tape
6007 device. Their names are kept in the following variables:
6008
6009 @defvr {Backup variable} MT_BEGIN
6010 The name of @dfn{begin} function. This function is called before
6011 accessing the drive. By default it retensions the tape:
6012
6013 @smallexample
6014 MT_BEGIN=mt_begin
6015
6016 mt_begin() @{
6017 mt -f "$1" retension
6018 @}
6019 @end smallexample
6020 @end defvr
6021
6022 @defvr {Backup variable} MT_REWIND
6023 The name of @dfn{rewind} function. The default definition is as
6024 follows:
6025
6026 @smallexample
6027 MT_REWIND=mt_rewind
6028
6029 mt_rewind() @{
6030 mt -f "$1" rewind
6031 @}
6032 @end smallexample
6033
6034 @end defvr
6035
6036 @defvr {Backup variable} MT_OFFLINE
6037 The name of the function switching the tape off line. By default
6038 it is defined as follows:
6039
6040 @smallexample
6041 MT_OFFLINE=mt_offline
6042
6043 mt_offline() @{
6044 mt -f "$1" offl
6045 @}
6046 @end smallexample
6047 @end defvr
6048
6049 @defvr {Backup variable} MT_STATUS
6050 The name of the function used to obtain the status of the archive device,
6051 including error count. Default definition:
6052
6053 @smallexample
6054 MT_STATUS=mt_status
6055
6056 mt_status() @{
6057 mt -f "$1" status
6058 @}
6059 @end smallexample
6060 @end defvr
6061
6062 @node User Hooks
6063 @subsection User Hooks
6064
6065 @dfn{User hooks} are shell functions executed before and after
6066 each @command{tar} invocation. Thus, there are @dfn{backup
6067 hooks}, which are executed before and after dumping each file
6068 system, and @dfn{restore hooks}, executed before and
6069 after restoring a file system. Each user hook is a shell function
6070 taking four arguments:
6071
6072 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6073 Its arguments are:
6074
6075 @table @var
6076 @item level
6077 Current backup or restore level.
6078
6079 @item host
6080 Name or IP address of the host machine being dumped or restored.
6081
6082 @item fs
6083 Full file name of the file system being dumped or restored.
6084
6085 @item fsname
6086 File system name with directory separators replaced with colons. This
6087 is useful, e.g., for creating unique files.
6088 @end table
6089 @end deffn
6090
6091 Following variables keep the names of user hook functions
6092
6093 @defvr {Backup variable} DUMP_BEGIN
6094 Dump begin function. It is executed before dumping the file system.
6095 @end defvr
6096
6097 @defvr {Backup variable} DUMP_END
6098 Executed after dumping the file system.
6099 @end defvr
6100
6101 @defvr {Backup variable} RESTORE_BEGIN
6102 Executed before restoring the file system.
6103 @end defvr
6104
6105 @defvr {Backup variable} RESTORE_END
6106 Executed after restoring the file system.
6107 @end defvr
6108
6109 @node backup-specs example
6110 @subsection An Example Text of @file{Backup-specs}
6111
6112 The following is an example of @file{backup-specs}:
6113
6114 @smallexample
6115 # site-specific parameters for file system backup.
6116
6117 ADMINISTRATOR=friedman
6118 BACKUP_HOUR=1
6119 TAPE_FILE=/dev/nrsmt0
6120
6121 # Use @code{ssh} instead of the less secure @code{rsh}
6122 RSH=/usr/bin/ssh
6123 RSH_COMMAND=/usr/bin/ssh
6124
6125 # Override MT_STATUS function:
6126 my_status() @{
6127 mts -t $TAPE_FILE
6128 @}
6129 MT_STATUS=my_status
6130
6131 # Disable MT_OFFLINE function
6132 MT_OFFLINE=:
6133
6134 BLOCKING=124
6135 BACKUP_DIRS="
6136 albert:/fs/fsf
6137 apple-gunkies:/gd
6138 albert:/fs/gd2
6139 albert:/fs/gp
6140 geech:/usr/jla
6141 churchy:/usr/roland
6142 albert:/
6143 albert:/usr
6144 apple-gunkies:/
6145 apple-gunkies:/usr
6146 gnu:/hack
6147 gnu:/u
6148 apple-gunkies:/com/mailer/gnu
6149 apple-gunkies:/com/archive/gnu"
6150
6151 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6152
6153 @end smallexample
6154
6155 @node Scripted Backups
6156 @section Using the Backup Scripts
6157
6158 The syntax for running a backup script is:
6159
6160 @smallexample
6161 backup --level=@var{level} --time=@var{time}
6162 @end smallexample
6163
6164 The @option{level} option requests the dump level. Thus, to produce
6165 a full dump, specify @code{--level=0} (this is the default, so
6166 @option{--level} may be omitted if its value is @code{0}).
6167 @footnote{For backward compatibility, the @code{backup} will also
6168 try to deduce the requested dump level from the name of the
6169 script itself. If the name consists of a string @samp{level-}
6170 followed by a single decimal digit, that digit is taken as
6171 the dump level number. Thus, you may create a link from @code{backup}
6172 to @code{level-1} and then run @code{level-1} whenever you need to
6173 create a level one dump.}
6174
6175 The @option{--time} option determines when should the backup be
6176 run. @var{Time} may take three forms:
6177
6178 @table @asis
6179 @item @var{hh}:@var{mm}
6180
6181 The dump must be run at @var{hh} hours @var{mm} minutes.
6182
6183 @item @var{hh}
6184
6185 The dump must be run at @var{hh} hours
6186
6187 @item now
6188
6189 The dump must be run immediately.
6190 @end table
6191
6192 You should start a script with a tape or disk mounted. Once you
6193 start a script, it prompts you for new tapes or disks as it
6194 needs them. Media volumes don't have to correspond to archive
6195 files --- a multi-volume archive can be started in the middle of a
6196 tape that already contains the end of another multi-volume archive.
6197 The @code{restore} script prompts for media by its archive volume,
6198 so to avoid an error message you should keep track of which tape
6199 (or disk) contains which volume of the archive (@pxref{Scripted
6200 Restoration}).
6201
6202 The backup scripts write two files on the file system. The first is a
6203 record file in @file{/etc/tar-backup/}, which is used by the scripts
6204 to store and retrieve information about which files were dumped. This
6205 file is not meant to be read by humans, and should not be deleted by
6206 them. @xref{Snapshot Files}, for a more detailed explanation of this
6207 file.
6208
6209 The second file is a log file containing the names of the file systems
6210 and files dumped, what time the backup was made, and any error
6211 messages that were generated, as well as how much space was left in
6212 the media volume after the last volume of the archive was written.
6213 You should check this log file after every backup. The file name is
6214 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6215 represents current date, and @var{n} represents current dump level number.
6216
6217 The script also prints the name of each system being dumped to the
6218 standard output.
6219
6220 Following is the full list of options accepted by @code{backup}
6221 script:
6222
6223 @table @option
6224 @item -l @var{level}
6225 @itemx --level=@var{level}
6226 Do backup level @var{level} (default 0).
6227
6228 @item -f
6229 @itemx --force
6230 Force backup even if today's log file already exists.
6231
6232 @item -v[@var{level}]
6233 @itemx --verbose[=@var{level}]
6234 Set verbosity level. The higher the level is, the more debugging
6235 information will be output during execution. Default @var{level}
6236 is 100, which means the highest debugging level.
6237
6238 @item -t @var{start-time}
6239 @itemx --time=@var{start-time}
6240 Wait till @var{time}, then do backup.
6241
6242 @item -h
6243 @itemx --help
6244 Display short help message and exit.
6245
6246 @item -V
6247 @itemx --version
6248 Display information about the program's name, version, origin and legal
6249 status, all on standard output, and then exit successfully.
6250 @end table
6251
6252
6253 @node Scripted Restoration
6254 @section Using the Restore Script
6255
6256 To restore files that were archived using a scripted backup, use the
6257 @code{restore} script. Its usage is quite straightforward. In the
6258 simplest form, invoke @code{restore --all}, it will
6259 then restore all the file systems and files specified in
6260 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6261
6262 You may select the file systems (and/or files) to restore by
6263 giving @code{restore} list of @dfn{patterns} in its command
6264 line. For example, running
6265
6266 @smallexample
6267 restore 'albert:*'
6268 @end smallexample
6269
6270 @noindent
6271 will restore all file systems on the machine @samp{albert}. A more
6272 complicated example:
6273
6274 @smallexample
6275 restore 'albert:*' '*:/var'
6276 @end smallexample
6277
6278 @noindent
6279 This command will restore all file systems on the machine @samp{albert}
6280 as well as @file{/var} file system on all machines.
6281
6282 By default @code{restore} will start restoring files from the lowest
6283 available dump level (usually zero) and will continue through
6284 all available dump levels. There may be situations where such a
6285 thorough restore is not necessary. For example, you may wish to
6286 restore only files from the recent level one backup. To do so,
6287 use @option{--level} option, as shown in the example below:
6288
6289 @smallexample
6290 restore --level=1
6291 @end smallexample
6292
6293 The full list of options accepted by @code{restore} follows:
6294
6295 @table @option
6296 @item -a
6297 @itemx --all
6298 Restore all file systems and files specified in @file{backup-specs}
6299
6300 @item -l @var{level}
6301 @itemx --level=@var{level}
6302 Start restoring from the given backup level, instead of the default 0.
6303
6304 @item -v[@var{level}]
6305 @itemx --verbose[=@var{level}]
6306 Set verbosity level. The higher the level is, the more debugging
6307 information will be output during execution. Default @var{level}
6308 is 100, which means the highest debugging level.
6309
6310 @item -h
6311 @itemx --help
6312 Display short help message and exit.
6313
6314 @item -V
6315 @itemx --version
6316 Display information about the program's name, version, origin and legal
6317 status, all on standard output, and then exit successfully.
6318 @end table
6319
6320 You should start the restore script with the media containing the
6321 first volume of the archive mounted. The script will prompt for other
6322 volumes as they are needed. If the archive is on tape, you don't need
6323 to rewind the tape to to its beginning---if the tape head is
6324 positioned past the beginning of the archive, the script will rewind
6325 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6326 positioning.
6327
6328 @quotation
6329 @strong{Warning:} The script will delete files from the active file
6330 system if they were not in the file system when the archive was made.
6331 @end quotation
6332
6333 @xref{Incremental Dumps}, for an explanation of how the script makes
6334 that determination.
6335
6336 @node Choosing
6337 @chapter Choosing Files and Names for @command{tar}
6338 @UNREVISED
6339
6340 Certain options to @command{tar} enable you to specify a name for your
6341 archive. Other options let you decide which files to include or exclude
6342 from the archive, based on when or whether files were modified, whether
6343 the file names do or don't match specified patterns, or whether files
6344 are in specified directories.
6345
6346 This chapter discusses these options in detail.
6347
6348 @menu
6349 * file:: Choosing the Archive's Name
6350 * Selecting Archive Members::
6351 * files:: Reading Names from a File
6352 * exclude:: Excluding Some Files
6353 * wildcards:: Wildcards Patterns and Matching
6354 * quoting styles:: Ways of Quoting Special Characters in Names
6355 * transform:: Modifying File and Member Names
6356 * after:: Operating Only on New Files
6357 * recurse:: Descending into Directories
6358 * one:: Crossing File System Boundaries
6359 @end menu
6360
6361 @node file
6362 @section Choosing and Naming Archive Files
6363 @UNREVISED
6364
6365 @cindex Naming an archive
6366 @cindex Archive Name
6367 @cindex Choosing an archive file
6368 @cindex Where is the archive?
6369 By default, @command{tar} uses an archive file name that was compiled when
6370 it was built on the system; usually this name refers to some physical
6371 tape drive on the machine. However, the person who installed @command{tar}
6372 on the system may not have set the default to a meaningful value as far as
6373 most users are concerned. As a result, you will usually want to tell
6374 @command{tar} where to find (or create) the archive. The
6375 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6376 option allows you to either specify or name a file to use as the archive
6377 instead of the default archive file location.
6378
6379 @table @option
6380 @xopindex{file, short description}
6381 @item --file=@var{archive-name}
6382 @itemx -f @var{archive-name}
6383 Name the archive to create or operate on. Use in conjunction with
6384 any operation.
6385 @end table
6386
6387 For example, in this @command{tar} command,
6388
6389 @smallexample
6390 $ @kbd{tar -cvf collection.tar blues folk jazz}
6391 @end smallexample
6392
6393 @noindent
6394 @file{collection.tar} is the name of the archive. It must directly
6395 follow the @option{-f} option, since whatever directly follows @option{-f}
6396 @emph{will} end up naming the archive. If you neglect to specify an
6397 archive name, you may end up overwriting a file in the working directory
6398 with the archive you create since @command{tar} will use this file's name
6399 for the archive name.
6400
6401 An archive can be saved as a file in the file system, sent through a
6402 pipe or over a network, or written to an I/O device such as a tape,
6403 floppy disk, or CD write drive.
6404
6405 @cindex Writing new archives
6406 @cindex Archive creation
6407 If you do not name the archive, @command{tar} uses the value of the
6408 environment variable @env{TAPE} as the file name for the archive. If
6409 that is not available, @command{tar} uses a default, compiled-in archive
6410 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6411
6412 @cindex Standard input and output
6413 @cindex tar to standard input and output
6414 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6415 archive from standard input (when listing or extracting files), or
6416 writes it to standard output (when creating an archive). If you use
6417 @file{-} as an @var{archive-name} when modifying an archive,
6418 @command{tar} reads the original archive from its standard input and
6419 writes the entire new archive to its standard output.
6420
6421 The following example is a convenient way of copying directory
6422 hierarchy from @file{sourcedir} to @file{targetdir}.
6423
6424 @smallexample
6425 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6426 @end smallexample
6427
6428 The @option{-C} option allows to avoid using subshells:
6429
6430 @smallexample
6431 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6432 @end smallexample
6433
6434 In both examples above, the leftmost @command{tar} invocation archives
6435 the contents of @file{sourcedir} to the standard output, while the
6436 rightmost one reads this archive from its standard input and
6437 extracts it. The @option{-p} option tells it to restore permissions
6438 of the extracted files.
6439
6440 @cindex Remote devices
6441 @cindex tar to a remote device
6442 @anchor{remote-dev}
6443 To specify an archive file on a device attached to a remote machine,
6444 use the following:
6445
6446 @smallexample
6447 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6448 @end smallexample
6449
6450 @noindent
6451 @command{tar} will complete the remote connection, if possible, and
6452 prompt you for a username and password. If you use
6453 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6454 will complete the remote connection, if possible, using your username
6455 as the username on the remote machine.
6456
6457 @cindex Local and remote archives
6458 @anchor{local and remote archives}
6459 If the archive file name includes a colon (@samp{:}), then it is assumed
6460 to be a file on another machine. If the archive file is
6461 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6462 host @var{host}. The remote host is accessed using the @command{rsh}
6463 program, with a username of @var{user}. If the username is omitted
6464 (along with the @samp{@@} sign), then your user name will be used.
6465 (This is the normal @command{rsh} behavior.) It is necessary for the
6466 remote machine, in addition to permitting your @command{rsh} access, to
6467 have the @file{rmt} program installed (This command is included in
6468 the @GNUTAR{} distribution and by default is installed under
6469 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6470 installation prefix). If you need to use a file whose name includes a
6471 colon, then the remote tape drive behavior
6472 can be inhibited by using the @option{--force-local} option.
6473
6474 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6475 tries to minimize input and output operations. The Amanda backup
6476 system, when used with @GNUTAR{}, has an initial sizing pass which
6477 uses this feature.
6478
6479 @node Selecting Archive Members
6480 @section Selecting Archive Members
6481 @cindex Specifying files to act on
6482 @cindex Specifying archive members
6483
6484 @dfn{File Name arguments} specify which files in the file system
6485 @command{tar} operates on, when creating or adding to an archive, or which
6486 archive members @command{tar} operates on, when reading or deleting from
6487 an archive. @xref{Operations}.
6488
6489 To specify file names, you can include them as the last arguments on
6490 the command line, as follows:
6491 @smallexample
6492 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6493 @end smallexample
6494
6495 If a file name begins with dash (@samp{-}), precede it with
6496 @option{--add-file} option to prevent it from being treated as an
6497 option.
6498
6499 @anchor{input name quoting}
6500 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6501 name, replacing @dfn{escape sequences} according to the following
6502 table:
6503
6504 @multitable @columnfractions 0.20 0.60
6505 @headitem Escape @tab Replaced with
6506 @item \a @tab Audible bell (@acronym{ASCII} 7)
6507 @item \b @tab Backspace (@acronym{ASCII} 8)
6508 @item \f @tab Form feed (@acronym{ASCII} 12)
6509 @item \n @tab New line (@acronym{ASCII} 10)
6510 @item \r @tab Carriage return (@acronym{ASCII} 13)
6511 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6512 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6513 @item \? @tab @acronym{ASCII} 127
6514 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6515 of up to 3 digits)
6516 @end multitable
6517
6518 A backslash followed by any other symbol is retained.
6519
6520 This default behavior is controlled by the following command line
6521 option:
6522
6523 @table @option
6524 @opindex unquote
6525 @item --unquote
6526 Enable unquoting input file or member names (default).
6527
6528 @opindex no-unquote
6529 @item --no-unquote
6530 Disable unquoting input file or member names.
6531 @end table
6532
6533 If you specify a directory name as a file name argument, all the files
6534 in that directory are operated on by @command{tar}.
6535
6536 If you do not specify files, @command{tar} behavior differs depending
6537 on the operation mode as described below:
6538
6539 When @command{tar} is invoked with @option{--create} (@option{-c}),
6540 @command{tar} will stop immediately, reporting the following:
6541
6542 @smallexample
6543 @group
6544 $ @kbd{tar cf a.tar}
6545 tar: Cowardly refusing to create an empty archive
6546 Try `tar --help' or `tar --usage' for more information.
6547 @end group
6548 @end smallexample
6549
6550 If you specify either @option{--list} (@option{-t}) or
6551 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6552 operates on all the archive members in the archive.
6553
6554 If run with @option{--diff} option, tar will compare the archive with
6555 the contents of the current working directory.
6556
6557 If you specify any other operation, @command{tar} does nothing.
6558
6559 By default, @command{tar} takes file names from the command line. However,
6560 there are other ways to specify file or member names, or to modify the
6561 manner in which @command{tar} selects the files or members upon which to
6562 operate. In general, these methods work both for specifying the names
6563 of files and archive members.
6564
6565 @node files
6566 @section Reading Names from a File
6567
6568 @cindex Reading file names from a file
6569 @cindex Lists of file names
6570 @cindex File Name arguments, alternatives
6571 Instead of giving the names of files or archive members on the command
6572 line, you can put the names into a file, and then use the
6573 @option{--files-from=@var{file-of-names}} (@option{-T
6574 @var{file-of-names}}) option to @command{tar}. Give the name of the
6575 file which contains the list of files to include as the argument to
6576 @option{--files-from}. In the list, the file names should be separated by
6577 newlines. You will frequently use this option when you have generated
6578 the list of files to archive with the @command{find} utility.
6579
6580 @table @option
6581 @opindex files-from
6582 @item --files-from=@var{file-name}
6583 @itemx -T @var{file-name}
6584 Get names to extract or create from file @var{file-name}.
6585 @end table
6586
6587 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6588 you specify either @code{--files-from=-} or @code{-T -}), then the file
6589 names are read from standard input.
6590
6591 Unless you are running @command{tar} with @option{--create}, you can not use
6592 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6593 command.
6594
6595 Any number of @option{-T} options can be given in the command line.
6596
6597 The following example shows how to use @command{find} to generate a list of
6598 files smaller than 400K in length and put that list into a file
6599 called @file{small-files}. You can then use the @option{-T} option to
6600 @command{tar} to specify the files from that file, @file{small-files}, to
6601 create the archive @file{little.tgz}. (The @option{-z} option to
6602 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6603 more information.)
6604
6605 @smallexample
6606 $ @kbd{find . -size -400 -print > small-files}
6607 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6608 @end smallexample
6609
6610 @noindent
6611 In the file list given by @option{-T} option, any file name beginning
6612 with @samp{-} character is considered a @command{tar} option and is
6613 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6614 recognized only @option{-C} option in file lists, and only if the
6615 option and its argument occupied two consecutive lines.} For example,
6616 the common use of this feature is to change to another directory by
6617 specifying @option{-C} option:
6618
6619 @smallexample
6620 @group
6621 $ @kbd{cat list}
6622 -C/etc
6623 passwd
6624 hosts
6625 -C/lib
6626 libc.a
6627 $ @kbd{tar -c -f foo.tar --files-from list}
6628 @end group
6629 @end smallexample
6630
6631 @noindent
6632 In this example, @command{tar} will first switch to @file{/etc}
6633 directory and add files @file{passwd} and @file{hosts} to the
6634 archive. Then it will change to @file{/lib} directory and will archive
6635 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6636 contain:
6637
6638 @smallexample
6639 @group
6640 $ @kbd{tar tf foo.tar}
6641 passwd
6642 hosts
6643 libc.a
6644 @end group
6645 @end smallexample
6646
6647 @noindent
6648 @xopindex{directory, using in @option{--files-from} argument}
6649 Notice that the option parsing algorithm used with @option{-T} is
6650 stricter than the one used by shell. Namely, when specifying option
6651 arguments, you should observe the following rules:
6652
6653 @itemize @bullet
6654 @item
6655 When using short (single-letter) option form, its argument must
6656 immediately follow the option letter, without any intervening
6657 whitespace. For example: @code{-Cdir}.
6658
6659 @item
6660 When using long option form, the option argument must be separated
6661 from the option by a single equal sign. No whitespace is allowed on
6662 any side of the equal sign. For example: @code{--directory=dir}.
6663
6664 @item
6665 For both short and long option forms, the option argument can be given
6666 on the next line after the option name, e.g.:
6667
6668 @smallexample
6669 @group
6670 --directory
6671 dir
6672 @end group
6673 @end smallexample
6674
6675 @noindent
6676 and
6677
6678 @smallexample
6679 @group
6680 -C
6681 dir
6682 @end group
6683 @end smallexample
6684 @end itemize
6685
6686 @opindex add-file
6687 If you happen to have a file whose name starts with @samp{-},
6688 precede it with @option{--add-file} option to prevent it from
6689 being recognized as an option. For example: @code{--add-file=--my-file}.
6690
6691 @menu
6692 * nul::
6693 @end menu
6694
6695 @node nul
6696 @subsection @code{NUL} Terminated File Names
6697
6698 @cindex File names, terminated by @code{NUL}
6699 @cindex @code{NUL} terminated file names
6700 The @option{--null} option causes
6701 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6702 to read file names terminated by a @code{NUL} instead of a newline, so
6703 files whose names contain newlines can be archived using
6704 @option{--files-from}.
6705
6706 @table @option
6707 @opindex null
6708 @item --null
6709 Only consider @code{NUL} terminated file names, instead of files that
6710 terminate in a newline.
6711 @end table
6712
6713 The @option{--null} option is just like the one in @acronym{GNU}
6714 @command{xargs} and @command{cpio}, and is useful with the
6715 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6716 @command{tar}, @option{--null} also disables special handling for
6717 file names that begin with dash.
6718
6719 This example shows how to use @command{find} to generate a list of files
6720 larger than 800K in length and put that list into a file called
6721 @file{long-files}. The @option{-print0} option to @command{find} is just
6722 like @option{-print}, except that it separates files with a @code{NUL}
6723 rather than with a newline. You can then run @command{tar} with both the
6724 @option{--null} and @option{-T} options to specify that @command{tar} get the
6725 files from that file, @file{long-files}, to create the archive
6726 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6727 @command{tar} to recognize the @code{NUL} separator between files.
6728
6729 @smallexample
6730 $ @kbd{find . -size +800 -print0 > long-files}
6731 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6732 @end smallexample
6733
6734 @FIXME{say anything else here to conclude the section?}
6735
6736 @node exclude
6737 @section Excluding Some Files
6738 @UNREVISED
6739
6740 @cindex File names, excluding files by
6741 @cindex Excluding files by name and pattern
6742 @cindex Excluding files by file system
6743 To avoid operating on files whose names match a particular pattern,
6744 use the @option{--exclude} or @option{--exclude-from} options.
6745
6746 @table @option
6747 @opindex exclude
6748 @item --exclude=@var{pattern}
6749 Causes @command{tar} to ignore files that match the @var{pattern}.
6750 @end table
6751
6752 @findex exclude
6753 The @option{--exclude=@var{pattern}} option prevents any file or
6754 member whose name matches the shell wildcard (@var{pattern}) from
6755 being operated on.
6756 For example, to create an archive with all the contents of the directory
6757 @file{src} except for files whose names end in @file{.o}, use the
6758 command @samp{tar -cf src.tar --exclude='*.o' src}.
6759
6760 You may give multiple @option{--exclude} options.
6761
6762 @table @option
6763 @opindex exclude-from
6764 @item --exclude-from=@var{file}
6765 @itemx -X @var{file}
6766 Causes @command{tar} to ignore files that match the patterns listed in
6767 @var{file}.
6768 @end table
6769
6770 @findex exclude-from
6771 Use the @option{--exclude-from} option to read a
6772 list of patterns, one per line, from @var{file}; @command{tar} will
6773 ignore files matching those patterns. Thus if @command{tar} is
6774 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6775 single line @file{*.o}, no files whose names end in @file{.o} will be
6776 added to the archive.
6777
6778 Notice, that lines from @var{file} are read verbatim. One of the
6779 frequent errors is leaving some extra whitespace after a file name,
6780 which is difficult to catch using text editors.
6781
6782 However, empty lines are OK.
6783
6784 @cindex version control system, excluding files
6785 @cindex VCS, excluding files
6786 @cindex SCCS, excluding files
6787 @cindex RCS, excluding files
6788 @cindex CVS, excluding files
6789 @cindex SVN, excluding files
6790 @cindex git, excluding files
6791 @table @option
6792 @opindex exclude-vcs
6793 @item --exclude-vcs
6794 Exclude files and directories used by some version control systems.
6795 @end table
6796
6797 As of version @value{VERSION}, the following files are excluded:
6798
6799 @itemize @bullet
6800 @item @file{CVS/}, and everything under it
6801 @item @file{RCS/}, and everything under it
6802 @item @file{SCCS/}, and everything under it
6803 @item @file{.git/}, and everything under it
6804 @item @file{.gitignore}
6805 @item @file{.cvsignore}
6806 @item @file{.svn/}, and everything under it
6807 @item @file{.arch-ids/}, and everything under it
6808 @item @file{@{arch@}/}, and everything under it
6809 @item @file{=RELEASE-ID}
6810 @item @file{=meta-update}
6811 @item @file{=update}
6812 @end itemize
6813
6814 @findex exclude-caches
6815 When creating an archive, the @option{--exclude-caches} option family
6816 causes @command{tar} to exclude all directories that contain a @dfn{cache
6817 directory tag}. A cache directory tag is a short file with the
6818 well-known name @file{CACHEDIR.TAG} and having a standard header
6819 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6820 Various applications write cache directory tags into directories they
6821 use to hold regenerable, non-precious data, so that such data can be
6822 more easily excluded from backups.
6823
6824 There are three @samp{exclude-caches} options, each providing a different
6825 exclusion semantics:
6826
6827 @table @option
6828 @opindex exclude-caches
6829 @item --exclude-caches
6830 Do not archive the contents of the directory, but archive the
6831 directory itself and the @file{CACHEDIR.TAG} file.
6832
6833 @opindex exclude-caches-under
6834 @item --exclude-caches-under
6835 Do not archive the contents of the directory, nor the
6836 @file{CACHEDIR.TAG} file, archive only the directory itself.
6837
6838 @opindex exclude-caches-all
6839 @item --exclude-caches-all
6840 Omit directories containing @file{CACHEDIR.TAG} file entirely.
6841 @end table
6842
6843 @findex exclude-tag
6844 Another option family, @option{--exclude-tag}, provides a generalization of
6845 this concept. It takes a single argument, a file name to look for.
6846 Any directory that contains this file will be excluded from the dump.
6847 Similarly to @samp{exclude-caches}, there are three options in this
6848 option family:
6849
6850 @table @option
6851 @opindex exclude-tag
6852 @item --exclude-tag=@var{file}
6853 Do not dump the contents of the directory, but dump the
6854 directory itself and the @var{file}.
6855
6856 @opindex exclude-tag-under
6857 @item --exclude-tag-under=@var{file}
6858 Do not dump the contents of the directory, nor the
6859 @var{file}, archive only the directory itself.
6860
6861 @opindex exclude-tag-all
6862 @item --exclude-tag-all=@var{file}
6863 Omit directories containing @var{file} file entirely.
6864 @end table
6865
6866 Multiple @option{--exclude-tag*} options can be given.
6867
6868 For example, given this directory:
6869
6870 @smallexample
6871 @group
6872 $ @kbd{find dir}
6873 dir
6874 dir/blues
6875 dir/jazz
6876 dir/folk
6877 dir/folk/tagfile
6878 dir/folk/sanjuan
6879 dir/folk/trote
6880 @end group
6881 @end smallexample
6882
6883 The @option{--exclude-tag} will produce the following:
6884
6885 @smallexample
6886 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
6887 dir/
6888 dir/blues
6889 dir/jazz
6890 dir/folk/
6891 tar: dir/folk/: contains a cache directory tag tagfile;
6892 contents not dumped
6893 dir/folk/tagfile
6894 @end smallexample
6895
6896 Both the @file{dir/folk} directory and its tagfile are preserved in
6897 the archive, however the rest of files in this directory are not.
6898
6899 Now, using the @option{--exclude-tag-under} option will exclude
6900 @file{tagfile} from the dump, while still preserving the directory
6901 itself, as shown in this example:
6902
6903 @smallexample
6904 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
6905 dir/
6906 dir/blues
6907 dir/jazz
6908 dir/folk/
6909 ./tar: dir/folk/: contains a cache directory tag tagfile;
6910 contents not dumped
6911 @end smallexample
6912
6913 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
6914 directory entirely:
6915
6916 @smallexample
6917 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
6918 dir/
6919 dir/blues
6920 dir/jazz
6921 ./tar: dir/folk/: contains a cache directory tag tagfile;
6922 directory not dumped
6923 @end smallexample
6924
6925 @menu
6926 * problems with exclude::
6927 @end menu
6928
6929 @node problems with exclude
6930 @unnumberedsubsec Problems with Using the @code{exclude} Options
6931
6932 @xopindex{exclude, potential problems with}
6933 Some users find @samp{exclude} options confusing. Here are some common
6934 pitfalls:
6935
6936 @itemize @bullet
6937 @item
6938 The main operating mode of @command{tar} does not act on a file name
6939 explicitly listed on the command line, if one of its file name
6940 components is excluded. In the example above, if
6941 you create an archive and exclude files that end with @samp{*.o}, but
6942 explicitly name the file @samp{dir.o/foo} after all the options have been
6943 listed, @samp{dir.o/foo} will be excluded from the archive.
6944
6945 @item
6946 You can sometimes confuse the meanings of @option{--exclude} and
6947 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6948 to be excluded are given as a pattern on the command line. Use
6949 @option{--exclude-from} to introduce the name of a file which contains
6950 a list of patterns, one per line; each of these patterns can exclude
6951 zero, one, or many files.
6952
6953 @item
6954 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6955 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6956 like @samp{*}. If you do not do this, the shell might expand the
6957 @samp{*} itself using files at hand, so @command{tar} might receive a
6958 list of files instead of one pattern, or none at all, making the
6959 command somewhat illegal. This might not correspond to what you want.
6960
6961 For example, write:
6962
6963 @smallexample
6964 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6965 @end smallexample
6966
6967 @noindent
6968 rather than:
6969
6970 @smallexample
6971 # @emph{Wrong!}
6972 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6973 @end smallexample
6974
6975 @item
6976 You must use use shell syntax, or globbing, rather than @code{regexp}
6977 syntax, when using exclude options in @command{tar}. If you try to use
6978 @code{regexp} syntax to describe files to be excluded, your command
6979 might fail.
6980
6981 @item
6982 @FIXME{The change in semantics must have occurred before 1.11,
6983 so I doubt if it is worth mentioning at all. Anyway, should at
6984 least specify in which version the semantics changed.}
6985 In earlier versions of @command{tar}, what is now the
6986 @option{--exclude-from} option was called @option{--exclude} instead.
6987 Now, @option{--exclude} applies to patterns listed on the command
6988 line and @option{--exclude-from} applies to patterns listed in a
6989 file.
6990
6991 @end itemize
6992
6993 @node wildcards
6994 @section Wildcards Patterns and Matching
6995
6996 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6997 @samp{*} or @samp{?} for example, are replaced and expanded into all
6998 existing files matching the given pattern. @GNUTAR{} can use wildcard
6999 patterns for matching (or globbing) archive members when extracting
7000 from or listing an archive. Wildcard patterns are also used for
7001 verifying volume labels of @command{tar} archives. This section has the
7002 purpose of explaining wildcard syntax for @command{tar}.
7003
7004 @FIXME{the next few paragraphs need work.}
7005
7006 A @var{pattern} should be written according to shell syntax, using wildcard
7007 characters to effect globbing. Most characters in the pattern stand
7008 for themselves in the matched string, and case is significant: @samp{a}
7009 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7010 pattern matches any single character in the matched string. The character
7011 @samp{*} in the pattern matches zero, one, or more single characters in
7012 the matched string. The character @samp{\} says to take the following
7013 character of the pattern @emph{literally}; it is useful when one needs to
7014 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7015
7016 The character @samp{[}, up to the matching @samp{]}, introduces a character
7017 class. A @dfn{character class} is a list of acceptable characters
7018 for the next single character of the matched string. For example,
7019 @samp{[abcde]} would match any of the first five letters of the alphabet.
7020 Note that within a character class, all of the ``special characters''
7021 listed above other than @samp{\} lose their special meaning; for example,
7022 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7023 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7024 the characters @samp{-} and @samp{]} must either come @emph{first} or
7025 @emph{last} in a character class.)
7026
7027 @cindex Excluding characters from a character class
7028 @cindex Character class, excluding characters from
7029 If the first character of the class after the opening @samp{[}
7030 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7031 Rather than listing character to match, it lists those characters which
7032 are @emph{forbidden} as the next single character of the matched string.
7033
7034 Other characters of the class stand for themselves. The special
7035 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7036 letters, is meant to represent all characters between @var{a} and
7037 @var{e}, inclusive.
7038
7039 @FIXME{need to add a sentence or so here to make this clear for those
7040 who don't have dan around.}
7041
7042 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7043 special for wildcard matches. However, if a pattern completely matches
7044 a directory prefix of a matched string, then it matches the full matched
7045 string: thus, excluding a directory also excludes all the files beneath it.
7046
7047 @menu
7048 * controlling pattern-matching::
7049 @end menu
7050
7051 @node controlling pattern-matching
7052 @unnumberedsubsec Controlling Pattern-Matching
7053
7054 For the purposes of this section, we call @dfn{exclusion members} all
7055 member names obtained while processing @option{--exclude} and
7056 @option{--exclude-from} options, and @dfn{inclusion members} those
7057 member names that were given in the command line or read from the file
7058 specified with @option{--files-from} option.
7059
7060 These two pairs of member lists are used in the following operations:
7061 @option{--diff}, @option{--extract}, @option{--list},
7062 @option{--update}.
7063
7064 There are no inclusion members in create mode (@option{--create} and
7065 @option{--append}), since in this mode the names obtained from the
7066 command line refer to @emph{files}, not archive members.
7067
7068 By default, inclusion members are compared with archive members
7069 literally @footnote{Notice that earlier @GNUTAR{} versions used
7070 globbing for inclusion members, which contradicted to UNIX98
7071 specification and was not documented. @xref{Changes}, for more
7072 information on this and other changes.} and exclusion members are
7073 treated as globbing patterns. For example:
7074
7075 @smallexample
7076 @group
7077 $ @kbd{tar tf foo.tar}
7078 a.c
7079 b.c
7080 a.txt
7081 [remarks]
7082 # @i{Member names are used verbatim:}
7083 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7084 [remarks]
7085 # @i{Exclude member names are globbed:}
7086 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7087 a.txt
7088 [remarks]
7089 @end group
7090 @end smallexample
7091
7092 This behavior can be altered by using the following options:
7093
7094 @table @option
7095 @opindex wildcards
7096 @item --wildcards
7097 Treat all member names as wildcards.
7098
7099 @opindex no-wildcards
7100 @item --no-wildcards
7101 Treat all member names as literal strings.
7102 @end table
7103
7104 Thus, to extract files whose names end in @samp{.c}, you can use:
7105
7106 @smallexample
7107 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7108 a.c
7109 b.c
7110 @end smallexample
7111
7112 @noindent
7113 Notice quoting of the pattern to prevent the shell from interpreting
7114 it.
7115
7116 The effect of @option{--wildcards} option is canceled by
7117 @option{--no-wildcards}. This can be used to pass part of
7118 the command line arguments verbatim and other part as globbing
7119 patterns. For example, the following invocation:
7120
7121 @smallexample
7122 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7123 @end smallexample
7124
7125 @noindent
7126 instructs @command{tar} to extract from @file{foo.tar} all files whose
7127 names end in @samp{.txt} and the file named @file{[remarks]}.
7128
7129 Normally, a pattern matches a name if an initial subsequence of the
7130 name's components matches the pattern, where @samp{*}, @samp{?}, and
7131 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7132 and wildcards can match @samp{/}.
7133
7134 Other than optionally stripping leading @samp{/} from names
7135 (@pxref{absolute}), patterns and names are used as-is. For
7136 example, trailing @samp{/} is not trimmed from a user-specified name
7137 before deciding whether to exclude it.
7138
7139 However, this matching procedure can be altered by the options listed
7140 below. These options accumulate. For example:
7141
7142 @smallexample
7143 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7144 @end smallexample
7145
7146 @noindent
7147 ignores case when excluding @samp{makefile}, but not when excluding
7148 @samp{readme}.
7149
7150 @table @option
7151 @opindex anchored
7152 @opindex no-anchored
7153 @item --anchored
7154 @itemx --no-anchored
7155 If anchored, a pattern must match an initial subsequence
7156 of the name's components. Otherwise, the pattern can match any
7157 subsequence. Default is @option{--no-anchored} for exclusion members
7158 and @option{--anchored} inclusion members.
7159
7160 @opindex ignore-case
7161 @opindex no-ignore-case
7162 @item --ignore-case
7163 @itemx --no-ignore-case
7164 When ignoring case, upper-case patterns match lower-case names and vice versa.
7165 When not ignoring case (the default), matching is case-sensitive.
7166
7167 @opindex wildcards-match-slash
7168 @opindex no-wildcards-match-slash
7169 @item --wildcards-match-slash
7170 @itemx --no-wildcards-match-slash
7171 When wildcards match slash (the default for exclusion members), a
7172 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7173 name. Otherwise, @samp{/} is matched only by @samp{/}.
7174
7175 @end table
7176
7177 The @option{--recursion} and @option{--no-recursion} options
7178 (@pxref{recurse}) also affect how member patterns are interpreted. If
7179 recursion is in effect, a pattern matches a name if it matches any of
7180 the name's parent directories.
7181
7182 The following table summarizes pattern-matching default values:
7183
7184 @multitable @columnfractions .3 .7
7185 @headitem Members @tab Default settings
7186 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7187 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7188 @end multitable
7189
7190 @node quoting styles
7191 @section Quoting Member Names
7192
7193 When displaying member names, @command{tar} takes care to avoid
7194 ambiguities caused by certain characters. This is called @dfn{name
7195 quoting}. The characters in question are:
7196
7197 @itemize @bullet
7198 @item Non-printable control characters:
7199 @anchor{escape sequences}
7200 @multitable @columnfractions 0.20 0.10 0.60
7201 @headitem Character @tab @acronym{ASCII} @tab Character name
7202 @item \a @tab 7 @tab Audible bell
7203 @item \b @tab 8 @tab Backspace
7204 @item \f @tab 12 @tab Form feed
7205 @item \n @tab 10 @tab New line
7206 @item \r @tab 13 @tab Carriage return
7207 @item \t @tab 9 @tab Horizontal tabulation
7208 @item \v @tab 11 @tab Vertical tabulation
7209 @end multitable
7210
7211 @item Space (@acronym{ASCII} 32)
7212
7213 @item Single and double quotes (@samp{'} and @samp{"})
7214
7215 @item Backslash (@samp{\})
7216 @end itemize
7217
7218 The exact way @command{tar} uses to quote these characters depends on
7219 the @dfn{quoting style}. The default quoting style, called
7220 @dfn{escape} (see below), uses backslash notation to represent control
7221 characters, space and backslash. Using this quoting style, control
7222 characters are represented as listed in column @samp{Character} in the
7223 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7224
7225 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7226 using @option{--quoting-style} option:
7227
7228 @table @option
7229 @item --quoting-style=@var{style}
7230 @opindex quoting-style
7231
7232 Sets quoting style. Valid values for @var{style} argument are:
7233 literal, shell, shell-always, c, escape, locale, clocale.
7234 @end table
7235
7236 These styles are described in detail below. To illustrate their
7237 effect, we will use an imaginary tar archive @file{arch.tar}
7238 containing the following members:
7239
7240 @smallexample
7241 @group
7242 # 1. Contains horizontal tabulation character.
7243 a tab
7244 # 2. Contains newline character
7245 a
7246 newline
7247 # 3. Contains a space
7248 a space
7249 # 4. Contains double quotes
7250 a"double"quote
7251 # 5. Contains single quotes
7252 a'single'quote
7253 # 6. Contains a backslash character:
7254 a\backslash
7255 @end group
7256 @end smallexample
7257
7258 Here is how usual @command{ls} command would have listed them, if they
7259 had existed in the current working directory:
7260
7261 @smallexample
7262 @group
7263 $ @kbd{ls}
7264 a\ttab
7265 a\nnewline
7266 a\ space
7267 a"double"quote
7268 a'single'quote
7269 a\\backslash
7270 @end group
7271 @end smallexample
7272
7273 Quoting styles:
7274
7275 @table @samp
7276 @item literal
7277 No quoting, display each character as is:
7278
7279 @smallexample
7280 @group
7281 $ @kbd{tar tf arch.tar --quoting-style=literal}
7282 ./
7283 ./a space
7284 ./a'single'quote
7285 ./a"double"quote
7286 ./a\backslash
7287 ./a tab
7288 ./a
7289 newline
7290 @end group
7291 @end smallexample
7292
7293 @item shell
7294 Display characters the same way Bourne shell does:
7295 control characters, except @samp{\t} and @samp{\n}, are printed using
7296 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7297 single quote is printed as @samp{\'}. If a name contains any quoted
7298 characters, it is enclosed in single quotes. In particular, if a name
7299 contains single quotes, it is printed as several single-quoted strings:
7300
7301 @smallexample
7302 @group
7303 $ @kbd{tar tf arch.tar --quoting-style=shell}
7304 ./
7305 './a space'
7306 './a'\''single'\''quote'
7307 './a"double"quote'
7308 './a\backslash'
7309 './a tab'
7310 './a
7311 newline'
7312 @end group
7313 @end smallexample
7314
7315 @item shell-always
7316 Same as @samp{shell}, but the names are always enclosed in single
7317 quotes:
7318
7319 @smallexample
7320 @group
7321 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7322 './'
7323 './a space'
7324 './a'\''single'\''quote'
7325 './a"double"quote'
7326 './a\backslash'
7327 './a tab'
7328 './a
7329 newline'
7330 @end group
7331 @end smallexample
7332
7333 @item c
7334 Use the notation of the C programming language. All names are
7335 enclosed in double quotes. Control characters are quoted using
7336 backslash notations, double quotes are represented as @samp{\"},
7337 backslash characters are represented as @samp{\\}. Single quotes and
7338 spaces are not quoted:
7339
7340 @smallexample
7341 @group
7342 $ @kbd{tar tf arch.tar --quoting-style=c}
7343 "./"
7344 "./a space"
7345 "./a'single'quote"
7346 "./a\"double\"quote"
7347 "./a\\backslash"
7348 "./a\ttab"
7349 "./a\nnewline"
7350 @end group
7351 @end smallexample
7352
7353 @item escape
7354 Control characters are printed using backslash notation, a space is
7355 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7356 default quoting style, unless it was changed when configured the
7357 package.
7358
7359 @smallexample
7360 @group
7361 $ @kbd{tar tf arch.tar --quoting-style=escape}
7362 ./
7363 ./a space
7364 ./a'single'quote
7365 ./a"double"quote
7366 ./a\\backslash
7367 ./a\ttab
7368 ./a\nnewline
7369 @end group
7370 @end smallexample
7371
7372 @item locale
7373 Control characters, single quote and backslash are printed using
7374 backslash notation. All names are quoted using left and right
7375 quotation marks, appropriate to the current locale. If it does not
7376 define quotation marks, use @samp{`} as left and @samp{'} as right
7377 quotation marks. Any occurrences of the right quotation mark in a
7378 name are escaped with @samp{\}, for example:
7379
7380 For example:
7381
7382 @smallexample
7383 @group
7384 $ @kbd{tar tf arch.tar --quoting-style=locale}
7385 `./'
7386 `./a space'
7387 `./a\'single\'quote'
7388 `./a"double"quote'
7389 `./a\\backslash'
7390 `./a\ttab'
7391 `./a\nnewline'
7392 @end group
7393 @end smallexample
7394
7395 @item clocale
7396 Same as @samp{locale}, but @samp{"} is used for both left and right
7397 quotation marks, if not provided by the currently selected locale:
7398
7399 @smallexample
7400 @group
7401 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7402 "./"
7403 "./a space"
7404 "./a'single'quote"
7405 "./a\"double\"quote"
7406 "./a\\backslash"
7407 "./a\ttab"
7408 "./a\nnewline"
7409 @end group
7410 @end smallexample
7411 @end table
7412
7413 You can specify which characters should be quoted in addition to those
7414 implied by the current quoting style:
7415
7416 @table @option
7417 @item --quote-chars=@var{string}
7418 Always quote characters from @var{string}, even if the selected
7419 quoting style would not quote them.
7420 @end table
7421
7422 For example, using @samp{escape} quoting (compare with the usual
7423 escape listing above):
7424
7425 @smallexample
7426 @group
7427 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7428 ./
7429 ./a\ space
7430 ./a'single'quote
7431 ./a\"double\"quote
7432 ./a\\backslash
7433 ./a\ttab
7434 ./a\nnewline
7435 @end group
7436 @end smallexample
7437
7438 To disable quoting of such additional characters, use the following
7439 option:
7440
7441 @table @option
7442 @item --no-quote-chars=@var{string}
7443 Remove characters listed in @var{string} from the list of quoted
7444 characters set by the previous @option{--quote-chars} option.
7445 @end table
7446
7447 This option is particularly useful if you have added
7448 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7449 and wish to disable it for the current invocation.
7450
7451 Note, that @option{--no-quote-chars} does @emph{not} disable those
7452 characters that are quoted by default in the selected quoting style.
7453
7454 @node transform
7455 @section Modifying File and Member Names
7456
7457 @command{Tar} archives contain detailed information about files stored
7458 in them and full file names are part of that information. When
7459 storing file to an archive, its file name is recorded in the archive
7460 along with the actual file contents. When restoring from an archive,
7461 a file is created on disk with exactly the same name as that stored
7462 in the archive. In the majority of cases this is the desired behavior
7463 of a file archiver. However, there are some cases when it is not.
7464
7465 First of all, it is often unsafe to extract archive members with
7466 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7467 takes special precautions when extracting such names and provides a
7468 special option for handling them, which is described in
7469 @ref{absolute}.
7470
7471 Secondly, you may wish to extract file names without some leading
7472 directory components, or with otherwise modified names. In other
7473 cases it is desirable to store files under differing names in the
7474 archive.
7475
7476 @GNUTAR{} provides two options for these needs.
7477
7478 @table @option
7479 @opindex strip-components
7480 @item --strip-components=@var{number}
7481 Strip given @var{number} of leading components from file names before
7482 extraction.
7483 @end table
7484
7485 For example, suppose you have archived whole @file{/usr} hierarchy to
7486 a tar archive named @file{usr.tar}. Among other files, this archive
7487 contains @file{usr/include/stdlib.h}, which you wish to extract to
7488 the current working directory. To do so, you type:
7489
7490 @smallexample
7491 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7492 @end smallexample
7493
7494 The option @option{--strip=2} instructs @command{tar} to strip the
7495 two leading components (@file{usr/} and @file{include/}) off the file
7496 name.
7497
7498 If you add to the above invocation @option{--verbose} (@option{-v})
7499 option, you will note that the verbose listing still contains the
7500 full file name, with the two removed components still in place. This
7501 can be inconvenient, so @command{tar} provides a special option for
7502 altering this behavior:
7503
7504 @anchor{show-transformed-names}
7505 @table @option
7506 @opindex show-transformed-names
7507 @item --show-transformed-names
7508 Display file or member names with all requested transformations
7509 applied.
7510 @end table
7511
7512 @noindent
7513 For example:
7514
7515 @smallexample
7516 @group
7517 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7518 usr/include/stdlib.h
7519 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7520 stdlib.h
7521 @end group
7522 @end smallexample
7523
7524 Notice that in both cases the file is @file{stdlib.h} extracted to the
7525 current working directory, @option{--show-transformed-names} affects
7526 only the way its name is displayed.
7527
7528 This option is especially useful for verifying whether the invocation
7529 will have the desired effect. Thus, before running
7530
7531 @smallexample
7532 $ @kbd{tar -x --strip=@var{n}}
7533 @end smallexample
7534
7535 @noindent
7536 it is often advisable to run
7537
7538 @smallexample
7539 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7540 @end smallexample
7541
7542 @noindent
7543 to make sure the command will produce the intended results.
7544
7545 In case you need to apply more complex modifications to the file name,
7546 @GNUTAR{} provides a general-purpose transformation option:
7547
7548 @table @option
7549 @opindex transform
7550 @item --transform=@var{expression}
7551 Modify file names using supplied @var{expression}.
7552 @end table
7553
7554 @noindent
7555 The @var{expression} is a @command{sed}-like replace expression of the
7556 form:
7557
7558 @smallexample
7559 s/@var{regexp}/@var{replace}/[@var{flags}]
7560 @end smallexample
7561
7562 @noindent
7563 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7564 replacement for each file name part that matches @var{regexp}. Both
7565 @var{regexp} and @var{replace} are described in detail in
7566 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7567
7568 Supported @var{flags} are:
7569
7570 @table @samp
7571 @item g
7572 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7573 just the first.
7574
7575 @item i
7576 Use case-insensitive matching
7577
7578 @item x
7579 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7580 regexps, Extended regular expressions, Extended regular expressions,
7581 sed, GNU sed}).
7582
7583 @item @var{number}
7584 Only replace the @var{number}th match of the @var{regexp}.
7585
7586 Note: the @var{posix} standard does not specify what should happen
7587 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7588 follows the GNU @command{sed} implementation in this regard, so
7589 the interaction is defined to be: ignore matches before the
7590 @var{number}th, and then match and replace all matches from the
7591 @var{number}th on.
7592
7593 @end table
7594
7595 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7596 that it be used consistently throughout the expression. For example,
7597 the following two expressions are equivalent:
7598
7599 @smallexample
7600 @group
7601 s/one/two/
7602 s,one,two,
7603 @end group
7604 @end smallexample
7605
7606 Changing delimiters is often useful when the @var{regex} contains
7607 slashes. For example, it is more convenient to write @code{s,/,-,} than
7608 @code{s/\//-/}.
7609
7610 Here are several examples of @option{--transform} usage:
7611
7612 @enumerate
7613 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7614
7615 @smallexample
7616 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7617 @end smallexample
7618
7619 @item Strip two leading directory components (equivalent to
7620 @option{--strip-components=2}):
7621
7622 @smallexample
7623 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7624 @end smallexample
7625
7626 @item Prepend @file{/prefix/} to each file name:
7627
7628 @smallexample
7629 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7630 @end smallexample
7631
7632 @item Convert each file name to lower case:
7633
7634 @smallexample
7635 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7636 @end smallexample
7637
7638 @end enumerate
7639
7640 Unlike @option{--strip-components}, @option{--transform} can be used
7641 in any @GNUTAR{} operation mode. For example, the following command
7642 adds files to the archive while replacing the leading @file{usr/}
7643 component with @file{var/}:
7644
7645 @smallexample
7646 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7647 @end smallexample
7648
7649 To test @option{--transform} effect we suggest using
7650 @option{--show-transformed-names} option:
7651
7652 @smallexample
7653 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7654 --verbose --show-transformed-names /}
7655 @end smallexample
7656
7657 If both @option{--strip-components} and @option{--transform} are used
7658 together, then @option{--transform} is applied first, and the required
7659 number of components is then stripped from its result.
7660
7661 @node after
7662 @section Operating Only on New Files
7663 @UNREVISED
7664
7665 @cindex Excluding file by age
7666 @cindex Data Modification time, excluding files by
7667 @cindex Modification time, excluding files by
7668 @cindex Age, excluding files by
7669 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7670 @option{-N @var{date}}) option causes @command{tar} to only work on
7671 files whose data modification or status change times are newer than
7672 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7673 it is taken to be a file name; the data modification time of that file
7674 is used as the date. If you use this option when creating or appending
7675 to an archive, the archive will only include new files. If you use
7676 @option{--after-date} when extracting an archive, @command{tar} will
7677 only extract files newer than the @var{date} you specify.
7678
7679 If you only want @command{tar} to make the date comparison based on
7680 modification of the file's data (rather than status
7681 changes), then use the @option{--newer-mtime=@var{date}} option.
7682
7683 You may use these options with any operation. Note that these options
7684 differ from the @option{--update} (@option{-u}) operation in that they
7685 allow you to specify a particular date against which @command{tar} can
7686 compare when deciding whether or not to archive the files.
7687
7688 @table @option
7689 @opindex after-date
7690 @opindex newer
7691 @item --after-date=@var{date}
7692 @itemx --newer=@var{date}
7693 @itemx -N @var{date}
7694 Only store files newer than @var{date}.
7695
7696 Acts on files only if their data modification or status change times are
7697 later than @var{date}. Use in conjunction with any operation.
7698
7699 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7700 name; the data modification time of that file is used as the date.
7701
7702 @opindex newer-mtime
7703 @item --newer-mtime=@var{date}
7704 Acts like @option{--after-date}, but only looks at data modification times.
7705 @end table
7706
7707 These options limit @command{tar} to operate only on files which have
7708 been modified after the date specified. A file's status is considered to have
7709 changed if its contents have been modified, or if its owner,
7710 permissions, and so forth, have been changed. (For more information on
7711 how to specify a date, see @ref{Date input formats}; remember that the
7712 entire date argument must be quoted if it contains any spaces.)
7713
7714 Gurus would say that @option{--after-date} tests both the data
7715 modification time (@code{mtime}, the time the contents of the file
7716 were last modified) and the status change time (@code{ctime}, the time
7717 the file's status was last changed: owner, permissions, etc.@:)
7718 fields, while @option{--newer-mtime} tests only the @code{mtime}
7719 field.
7720
7721 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7722 @code{ctime} and processes the file if either one is more recent than
7723 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7724 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7725 contents of the file were looked at).
7726
7727 Date specifiers can have embedded spaces. Because of this, you may need
7728 to quote date arguments to keep the shell from parsing them as separate
7729 arguments. For example, the following command will add to the archive
7730 all the files modified less than two days ago:
7731
7732 @smallexample
7733 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7734 @end smallexample
7735
7736 When any of these options is used with the option @option{--verbose}
7737 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7738 date back to its textual representation and compare that with the
7739 one given with the option. If the two dates differ, @command{tar} will
7740 print a warning saying what date it will use. This is to help user
7741 ensure he is using the right date. For example:
7742
7743 @smallexample
7744 @group
7745 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7746 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7747 13:19:37.232434
7748 @end group
7749 @end smallexample
7750
7751 @quotation
7752 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7753 should not be used for incremental backups. @xref{Incremental Dumps},
7754 for proper way of creating incremental backups.
7755 @end quotation
7756
7757 @node recurse
7758 @section Descending into Directories
7759 @UNREVISED
7760 @cindex Avoiding recursion in directories
7761 @cindex Descending directories, avoiding
7762 @cindex Directories, avoiding recursion
7763 @cindex Recursion in directories, avoiding
7764
7765 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7766
7767 Usually, @command{tar} will recursively explore all directories (either
7768 those given on the command line or through the @option{--files-from}
7769 option) for the various files they contain. However, you may not always
7770 want @command{tar} to act this way.
7771
7772 @opindex no-recursion
7773 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7774 into specified directories. If you specify @option{--no-recursion}, you can
7775 use the @command{find} utility for hunting through levels of directories to
7776 construct a list of file names which you could then pass to @command{tar}.
7777 @command{find} allows you to be more selective when choosing which files to
7778 archive; see @ref{files}, for more information on using @command{find} with
7779 @command{tar}, or look.
7780
7781 @table @option
7782 @item --no-recursion
7783 Prevents @command{tar} from recursively descending directories.
7784
7785 @opindex recursion
7786 @item --recursion
7787 Requires @command{tar} to recursively descend directories.
7788 This is the default.
7789 @end table
7790
7791 When you use @option{--no-recursion}, @GNUTAR{} grabs
7792 directory entries themselves, but does not descend on them
7793 recursively. Many people use @command{find} for locating files they
7794 want to back up, and since @command{tar} @emph{usually} recursively
7795 descends on directories, they have to use the @samp{@w{-not -type d}}
7796 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7797 find, Finding Files}), as they usually do not want all the files in a
7798 directory. They then use the @option{--files-from} option to archive
7799 the files located via @command{find}.
7800
7801 The problem when restoring files archived in this manner is that the
7802 directories themselves are not in the archive; so the
7803 @option{--same-permissions} (@option{--preserve-permissions},
7804 @option{-p}) option does not affect them---while users might really
7805 like it to. Specifying @option{--no-recursion} is a way to tell
7806 @command{tar} to grab only the directory entries given to it, adding
7807 no new files on its own. To summarize, if you use @command{find} to
7808 create a list of files to be stored in an archive, use it as follows:
7809
7810 @smallexample
7811 @group
7812 $ @kbd{find @var{dir} @var{tests} | \
7813 tar -cf @var{archive} -T - --no-recursion}
7814 @end group
7815 @end smallexample
7816
7817 The @option{--no-recursion} option also applies when extracting: it
7818 causes @command{tar} to extract only the matched directory entries, not
7819 the files under those directories.
7820
7821 The @option{--no-recursion} option also affects how globbing patterns
7822 are interpreted (@pxref{controlling pattern-matching}).
7823
7824 The @option{--no-recursion} and @option{--recursion} options apply to
7825 later options and operands, and can be overridden by later occurrences
7826 of @option{--no-recursion} and @option{--recursion}. For example:
7827
7828 @smallexample
7829 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7830 @end smallexample
7831
7832 @noindent
7833 creates an archive with one entry for @file{grape}, and the recursive
7834 contents of @file{grape/concord}, but no entries under @file{grape}
7835 other than @file{grape/concord}.
7836
7837 @node one
7838 @section Crossing File System Boundaries
7839 @cindex File system boundaries, not crossing
7840 @UNREVISED
7841
7842 @command{tar} will normally automatically cross file system boundaries in
7843 order to archive files which are part of a directory tree. You can
7844 change this behavior by running @command{tar} and specifying
7845 @option{--one-file-system}. This option only affects files that are
7846 archived because they are in a directory that is being archived;
7847 @command{tar} will still archive files explicitly named on the command line
7848 or through @option{--files-from}, regardless of where they reside.
7849
7850 @table @option
7851 @opindex one-file-system
7852 @item --one-file-system
7853 Prevents @command{tar} from crossing file system boundaries when
7854 archiving. Use in conjunction with any write operation.
7855 @end table
7856
7857 The @option{--one-file-system} option causes @command{tar} to modify its
7858 normal behavior in archiving the contents of directories. If a file in
7859 a directory is not on the same file system as the directory itself, then
7860 @command{tar} will not archive that file. If the file is a directory
7861 itself, @command{tar} will not archive anything beneath it; in other words,
7862 @command{tar} will not cross mount points.
7863
7864 This option is useful for making full or incremental archival backups of
7865 a file system. If this option is used in conjunction with
7866 @option{--verbose} (@option{-v}), files that are excluded are
7867 mentioned by name on the standard error.
7868
7869 @menu
7870 * directory:: Changing Directory
7871 * absolute:: Absolute File Names
7872 @end menu
7873
7874 @node directory
7875 @subsection Changing the Working Directory
7876
7877 @FIXME{need to read over this node now for continuity; i've switched
7878 things around some.}
7879
7880 @cindex Changing directory mid-stream
7881 @cindex Directory, changing mid-stream
7882 @cindex Working directory, specifying
7883 To change the working directory in the middle of a list of file names,
7884 either on the command line or in a file specified using
7885 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7886 This will change the working directory to the specified directory
7887 after that point in the list.
7888
7889 @table @option
7890 @opindex directory
7891 @item --directory=@var{directory}
7892 @itemx -C @var{directory}
7893 Changes the working directory in the middle of a command line.
7894 @end table
7895
7896 For example,
7897
7898 @smallexample
7899 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7900 @end smallexample
7901
7902 @noindent
7903 will place the files @file{grape} and @file{prune} from the current
7904 directory into the archive @file{jams.tar}, followed by the file
7905 @file{cherry} from the directory @file{food}. This option is especially
7906 useful when you have several widely separated files that you want to
7907 store in the same archive.
7908
7909 Note that the file @file{cherry} is recorded in the archive under the
7910 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7911 archive will contain three files that all appear to have come from the
7912 same directory; if the archive is extracted with plain @samp{tar
7913 --extract}, all three files will be written in the current directory.
7914
7915 Contrast this with the command,
7916
7917 @smallexample
7918 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7919 @end smallexample
7920
7921 @noindent
7922 which records the third file in the archive under the name
7923 @file{red/cherry} so that, if the archive is extracted using
7924 @samp{tar --extract}, the third file will be written in a subdirectory
7925 named @file{orange-colored}.
7926
7927 You can use the @option{--directory} option to make the archive
7928 independent of the original name of the directory holding the files.
7929 The following command places the files @file{/etc/passwd},
7930 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7931 @file{foo.tar}:
7932
7933 @smallexample
7934 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7935 @end smallexample
7936
7937 @noindent
7938 However, the names of the archive members will be exactly what they were
7939 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7940 They will not appear to be related by file name to the original
7941 directories where those files were located.
7942
7943 Note that @option{--directory} options are interpreted consecutively. If
7944 @option{--directory} specifies a relative file name, it is interpreted
7945 relative to the then current directory, which might not be the same as
7946 the original current working directory of @command{tar}, due to a previous
7947 @option{--directory} option.
7948
7949 When using @option{--files-from} (@pxref{files}), you can put various
7950 @command{tar} options (including @option{-C}) in the file list. Notice,
7951 however, that in this case the option and its argument may not be
7952 separated by whitespace. If you use short option, its argument must
7953 either follow the option letter immediately, without any intervening
7954 whitespace, or occupy the next line. Otherwise, if you use long
7955 option, separate its argument by an equal sign.
7956
7957 For instance, the file list for the above example will be:
7958
7959 @smallexample
7960 @group
7961 -C/etc
7962 passwd
7963 hosts
7964 --directory=/lib
7965 libc.a
7966 @end group
7967 @end smallexample
7968
7969 @noindent
7970 To use it, you would invoke @command{tar} as follows:
7971
7972 @smallexample
7973 $ @kbd{tar -c -f foo.tar --files-from list}
7974 @end smallexample
7975
7976 The interpretation of @option{--directory} is disabled by
7977 @option{--null} option.
7978
7979 @node absolute
7980 @subsection Absolute File Names
7981 @UNREVISED
7982
7983 @table @option
7984 @opindex absolute-names
7985 @item --absolute-names
7986 @itemx -P
7987 Do not strip leading slashes from file names, and permit file names
7988 containing a @file{..} file name component.
7989 @end table
7990
7991 By default, @GNUTAR{} drops a leading @samp{/} on
7992 input or output, and complains about file names containing a @file{..}
7993 component. This option turns off this behavior.
7994
7995 When @command{tar} extracts archive members from an archive, it strips any
7996 leading slashes (@samp{/}) from the member name. This causes absolute
7997 member names in the archive to be treated as relative file names. This
7998 allows you to have such members extracted wherever you want, instead of
7999 being restricted to extracting the member in the exact directory named
8000 in the archive. For example, if the archive member has the name
8001 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8002 really @file{etc/passwd}.
8003
8004 File names containing @file{..} can cause problems when extracting, so
8005 @command{tar} normally warns you about such files when creating an
8006 archive, and rejects attempts to extracts such files.
8007
8008 Other @command{tar} programs do not do this. As a result, if you
8009 create an archive whose member names start with a slash, they will be
8010 difficult for other people with a non-@GNUTAR{}
8011 program to use. Therefore, @GNUTAR{} also strips
8012 leading slashes from member names when putting members into the
8013 archive. For example, if you ask @command{tar} to add the file
8014 @file{/bin/ls} to an archive, it will do so, but the member name will
8015 be @file{bin/ls}.@footnote{A side effect of this is that when
8016 @option{--create} is used with @option{--verbose} the resulting output
8017 is not, generally speaking, the same as the one you'd get running
8018 @kbd{tar --list} command. This may be important if you use some
8019 scripts for comparing both outputs. @xref{listing member and file names},
8020 for the information on how to handle this case.}
8021
8022 If you use the @option{--absolute-names} (@option{-P}) option,
8023 @command{tar} will do none of these transformations.
8024
8025 To archive or extract files relative to the root directory, specify
8026 the @option{--absolute-names} (@option{-P}) option.
8027
8028 Normally, @command{tar} acts on files relative to the working
8029 directory---ignoring superior directory names when archiving, and
8030 ignoring leading slashes when extracting.
8031
8032 When you specify @option{--absolute-names} (@option{-P}),
8033 @command{tar} stores file names including all superior directory
8034 names, and preserves leading slashes. If you only invoked
8035 @command{tar} from the root directory you would never need the
8036 @option{--absolute-names} option, but using this option
8037 may be more convenient than switching to root.
8038
8039 @FIXME{Should be an example in the tutorial/wizardry section using this
8040 to transfer files between systems.}
8041
8042 @FIXME{Is write access an issue?}
8043
8044 @table @option
8045 @item --absolute-names
8046 Preserves full file names (including superior directory names) when
8047 archiving files. Preserves leading slash when extracting files.
8048
8049 @end table
8050
8051 @FIXME{this is still horrible; need to talk with dan on monday.}
8052
8053 @command{tar} prints out a message about removing the @samp{/} from
8054 file names. This message appears once per @GNUTAR{}
8055 invocation. It represents something which ought to be told; ignoring
8056 what it means can cause very serious surprises, later.
8057
8058 Some people, nevertheless, do not want to see this message. Wanting to
8059 play really dangerously, one may of course redirect @command{tar} standard
8060 error to the sink. For example, under @command{sh}:
8061
8062 @smallexample
8063 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8064 @end smallexample
8065
8066 @noindent
8067 Another solution, both nicer and simpler, would be to change to
8068 the @file{/} directory first, and then avoid absolute notation.
8069 For example:
8070
8071 @smallexample
8072 $ @kbd{(cd / && tar -c -f archive.tar home)}
8073 # @i{or}:
8074 $ @kbd{tar -c -f archive.tar -C / home}
8075 @end smallexample
8076
8077 @include getdate.texi
8078
8079 @node Formats
8080 @chapter Controlling the Archive Format
8081
8082 @cindex Tar archive formats
8083 Due to historical reasons, there are several formats of tar archives.
8084 All of them are based on the same principles, but have some subtle
8085 differences that often make them incompatible with each other.
8086
8087 GNU tar is able to create and handle archives in a variety of formats.
8088 The most frequently used formats are (in alphabetical order):
8089
8090 @table @asis
8091 @item gnu
8092 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8093 from an early @acronym{POSIX} standard, adding some improvements such as
8094 sparse file handling and incremental archives. Unfortunately these
8095 features were implemented in a way incompatible with other archive
8096 formats.
8097
8098 Archives in @samp{gnu} format are able to hold file names of unlimited
8099 length.
8100
8101 @item oldgnu
8102 Format used by @GNUTAR{} of versions prior to 1.12.
8103
8104 @item v7
8105 Archive format, compatible with the V7 implementation of tar. This
8106 format imposes a number of limitations. The most important of them
8107 are:
8108
8109 @enumerate
8110 @item The maximum length of a file name is limited to 99 characters.
8111 @item The maximum length of a symbolic link is limited to 99 characters.
8112 @item It is impossible to store special files (block and character
8113 devices, fifos etc.)
8114 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8115 octal)
8116 @item V7 archives do not contain symbolic ownership information (user
8117 and group name of the file owner).
8118 @end enumerate
8119
8120 This format has traditionally been used by Automake when producing
8121 Makefiles. This practice will change in the future, in the meantime,
8122 however this means that projects containing file names more than 99
8123 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8124 Automake prior to 1.9.
8125
8126 @item ustar
8127 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8128 symbolic ownership information. It is also able to store
8129 special files. However, it imposes several restrictions as well:
8130
8131 @enumerate
8132 @item The maximum length of a file name is limited to 256 characters,
8133 provided that the file name can be split at a directory separator in
8134 two parts, first of them being at most 155 bytes long. So, in most
8135 cases the maximum file name length will be shorter than 256
8136 characters.
8137 @item The maximum length of a symbolic link name is limited to
8138 100 characters.
8139 @item Maximum size of a file the archive is able to accommodate
8140 is 8GB
8141 @item Maximum value of UID/GID is 2097151.
8142 @item Maximum number of bits in device major and minor numbers is 21.
8143 @end enumerate
8144
8145 @item star
8146 Format used by J@"org Schilling @command{star}
8147 implementation. @GNUTAR{} is able to read @samp{star} archives but
8148 currently does not produce them.
8149
8150 @item posix
8151 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8152 most flexible and feature-rich format. It does not impose any
8153 restrictions on file sizes or file name lengths. This format is quite
8154 recent, so not all tar implementations are able to handle it properly.
8155 However, this format is designed in such a way that any tar
8156 implementation able to read @samp{ustar} archives will be able to read
8157 most @samp{posix} archives as well, with the only exception that any
8158 additional information (such as long file names etc.) will in such
8159 case be extracted as plain text files along with the files it refers to.
8160
8161 This archive format will be the default format for future versions
8162 of @GNUTAR{}.
8163
8164 @end table
8165
8166 The following table summarizes the limitations of each of these
8167 formats:
8168
8169 @multitable @columnfractions .10 .20 .20 .20 .20
8170 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8171 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8172 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8173 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8174 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8175 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8176 @end multitable
8177
8178 The default format for @GNUTAR{} is defined at compilation
8179 time. You may check it by running @command{tar --help}, and examining
8180 the last lines of its output. Usually, @GNUTAR{} is configured
8181 to create archives in @samp{gnu} format, however, future version will
8182 switch to @samp{posix}.
8183
8184 @menu
8185 * Compression:: Using Less Space through Compression
8186 * Attributes:: Handling File Attributes
8187 * Portability:: Making @command{tar} Archives More Portable
8188 * cpio:: Comparison of @command{tar} and @command{cpio}
8189 @end menu
8190
8191 @node Compression
8192 @section Using Less Space through Compression
8193
8194 @menu
8195 * gzip:: Creating and Reading Compressed Archives
8196 * sparse:: Archiving Sparse Files
8197 @end menu
8198
8199 @node gzip
8200 @subsection Creating and Reading Compressed Archives
8201 @cindex Compressed archives
8202 @cindex Storing archives in compressed format
8203
8204 @GNUTAR{} is able to create and read compressed archives. It supports
8205 @command{gzip}, @command{bzip2} and @command{lzma} compression
8206 programs. For backward compatibility, it also supports
8207 @command{compress} command, although we strongly recommend against
8208 using it, because it is by far less effective than other compression
8209 programs@footnote{It also had patent problems in the past.}.
8210
8211 Creating a compressed archive is simple: you just specify a
8212 @dfn{compression option} along with the usual archive creation
8213 commands. The compression option is @option{-z} (@option{--gzip}) to
8214 create a @command{gzip} compressed archive, @option{-j}
8215 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8216 @command{lzma} to create an @asis{LZMA} compressed archive and
8217 @option{-Z} (@option{--compress}) to use @command{compress} program.
8218 For example:
8219
8220 @smallexample
8221 $ @kbd{tar cfz archive.tar.gz .}
8222 @end smallexample
8223
8224 You can also let @GNUTAR{} select the compression program basing on
8225 the suffix of the archive file name. This is done using
8226 @option{--auto-compress} (@option{-a}) command line option. For
8227 example, the following invocation will use @command{bzip2} for
8228 compression:
8229
8230 @smallexample
8231 $ @kbd{tar cfa archive.tar.bz2 .}
8232 @end smallexample
8233
8234 @noindent
8235 whereas the following one will use @command{lzma}:
8236
8237 @smallexample
8238 $ @kbd{tar cfa archive.tar.lzma .}
8239 @end smallexample
8240
8241 For a complete list of file name suffixes recognized by @GNUTAR{},
8242 @ref{auto-compress}.
8243
8244 Reading compressed archive is even simpler: you don't need to specify
8245 any additional options as @GNUTAR{} recognizes its format
8246 automatically. Thus, the following commands will list and extract the
8247 archive created in previous example:
8248
8249 @smallexample
8250 # List the compressed archive
8251 $ @kbd{tar tf archive.tar.gz}
8252 # Extract the compressed archive
8253 $ @kbd{tar xf archive.tar.gz}
8254 @end smallexample
8255
8256 The only case when you have to specify a decompression option while
8257 reading the archive is when reading from a pipe or from a tape drive
8258 that does not support random access. However, in this case @GNUTAR{}
8259 will indicate which option you should use. For example:
8260
8261 @smallexample
8262 $ @kbd{cat archive.tar.gz | tar tf -}
8263 tar: Archive is compressed. Use -z option
8264 tar: Error is not recoverable: exiting now
8265 @end smallexample
8266
8267 If you see such diagnostics, just add the suggested option to the
8268 invocation of @GNUTAR{}:
8269
8270 @smallexample
8271 $ @kbd{cat archive.tar.gz | tar tfz -}
8272 @end smallexample
8273
8274 Notice also, that there are several restrictions on operations on
8275 compressed archives. First of all, compressed archives cannot be
8276 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8277 (@option{--delete}) members from them. Likewise, you cannot append
8278 another @command{tar} archive to a compressed archive using
8279 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8280 compressed.
8281
8282 The following table summarizes compression options used by @GNUTAR{}.
8283
8284 @table @option
8285 @anchor{auto-compress}
8286 @opindex auto-compress
8287 @item --auto-compress
8288 @itemx -a
8289 Select a compression program to use by the archive file name
8290 suffix. The following suffixes are recognized:
8291
8292 @multitable @columnfractions 0.3 0.6
8293 @headitem Suffix @tab Compression program
8294 @item @samp{.gz} @tab @command{gzip}
8295 @item @samp{.tgz} @tab @command{gzip}
8296 @item @samp{.taz} @tab @command{gzip}
8297 @item @samp{.Z} @tab @command{compress}
8298 @item @samp{.taZ} @tab @command{compress}
8299 @item @samp{.bz2} @tab @command{bzip2}
8300 @item @samp{.tz2} @tab @command{bzip2}
8301 @item @samp{.tbz2} @tab @command{bzip2}
8302 @item @samp{.tbz} @tab @command{bzip2}
8303 @item @samp{.lzma} @tab @command{lzma}
8304 @item @samp{.tlz} @tab @command{lzma}
8305 @end multitable
8306
8307 @opindex gzip
8308 @opindex ungzip
8309 @item -z
8310 @itemx --gzip
8311 @itemx --ungzip
8312 Filter the archive through @command{gzip}.
8313
8314 You can use @option{--gzip} and @option{--gunzip} on physical devices
8315 (tape drives, etc.) and remote files as well as on normal files; data
8316 to or from such devices or remote files is reblocked by another copy
8317 of the @command{tar} program to enforce the specified (or default) record
8318 size. The default compression parameters are used; if you need to
8319 override them, set @env{GZIP} environment variable, e.g.:
8320
8321 @smallexample
8322 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8323 @end smallexample
8324
8325 @noindent
8326 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8327 @command{gzip} explicitly:
8328
8329 @smallexample
8330 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8331 @end smallexample
8332
8333 @cindex corrupted archives
8334 About corrupted compressed archives: @command{gzip}'ed files have no
8335 redundancy, for maximum compression. The adaptive nature of the
8336 compression scheme means that the compression tables are implicitly
8337 spread all over the archive. If you lose a few blocks, the dynamic
8338 construction of the compression tables becomes unsynchronized, and there
8339 is little chance that you could recover later in the archive.
8340
8341 There are pending suggestions for having a per-volume or per-file
8342 compression in @GNUTAR{}. This would allow for viewing the
8343 contents without decompression, and for resynchronizing decompression at
8344 every volume or file, in case of corrupted archives. Doing so, we might
8345 lose some compressibility. But this would have make recovering easier.
8346 So, there are pros and cons. We'll see!
8347
8348 @opindex bzip2
8349 @item -j
8350 @itemx --bzip2
8351 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8352
8353 @opindex lzma
8354 @item --lzma
8355 Filter the archive through @command{lzma}. Otherwise like @option{--gzip}.
8356
8357 @opindex compress
8358 @opindex uncompress
8359 @item -Z
8360 @itemx --compress
8361 @itemx --uncompress
8362 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8363
8364 @opindex use-compress-program
8365 @item --use-compress-program=@var{prog}
8366 Use external compression program @var{prog}. Use this option if you
8367 have a compression program that @GNUTAR{} does not support. There
8368 are two requirements to which @var{prog} should comply:
8369
8370 First, when called without options, it should read data from standard
8371 input, compress it and output it on standard output.
8372
8373 Secondly, if called with @option{-d} argument, it should do exactly
8374 the opposite, i.e., read the compressed data from the standard input
8375 and produce uncompressed data on the standard output.
8376 @end table
8377
8378 @cindex gpg, using with tar
8379 @cindex gnupg, using with tar
8380 @cindex Using encrypted archives
8381 The @option{--use-compress-program} option, in particular, lets you
8382 implement your own filters, not necessarily dealing with
8383 compression/decompression. For example, suppose you wish to implement
8384 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8385 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8386 Manual}). The following script does that:
8387
8388 @smallexample
8389 @group
8390 #! /bin/sh
8391 case $1 in
8392 -d) gpg --decrypt - | gzip -d -c;;
8393 '') gzip -c | gpg -s ;;
8394 *) echo "Unknown option $1">&2; exit 1;;
8395 esac
8396 @end group
8397 @end smallexample
8398
8399 Suppose you name it @file{gpgz} and save it somewhere in your
8400 @env{PATH}. Then the following command will create a compressed
8401 archive signed with your private key:
8402
8403 @smallexample
8404 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8405 @end smallexample
8406
8407 @noindent
8408 Likewise, the following command will list its contents:
8409
8410 @smallexample
8411 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8412 @end smallexample
8413
8414 @ignore
8415 The above is based on the following discussion:
8416
8417 I have one question, or maybe it's a suggestion if there isn't a way
8418 to do it now. I would like to use @option{--gzip}, but I'd also like
8419 the output to be fed through a program like @acronym{GNU}
8420 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8421 to use :-)), basically adding ECC protection on top of compression.
8422 It seems as if this should be quite easy to do, but I can't work out
8423 exactly how to go about it. Of course, I can pipe the standard output
8424 of @command{tar} through @command{ecc}, but then I lose (though I
8425 haven't started using it yet, I confess) the ability to have
8426 @command{tar} use @command{rmt} for it's I/O (I think).
8427
8428 I think the most straightforward thing would be to let me specify a
8429 general set of filters outboard of compression (preferably ordered,
8430 so the order can be automatically reversed on input operations, and
8431 with the options they require specifiable), but beggars shouldn't be
8432 choosers and anything you decide on would be fine with me.
8433
8434 By the way, I like @command{ecc} but if (as the comments say) it can't
8435 deal with loss of block sync, I'm tempted to throw some time at adding
8436 that capability. Supposing I were to actually do such a thing and
8437 get it (apparently) working, do you accept contributed changes to
8438 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8439
8440 Isn't that exactly the role of the
8441 @option{--use-compress-prog=@var{program}} option?
8442 I never tried it myself, but I suspect you may want to write a
8443 @var{prog} script or program able to filter stdin to stdout to
8444 way you want. It should recognize the @option{-d} option, for when
8445 extraction is needed rather than creation.
8446
8447 It has been reported that if one writes compressed data (through the
8448 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8449 the DLT compression mode, the data will actually get bigger and one will
8450 end up with less space on the tape.
8451 @end ignore
8452
8453 @node sparse
8454 @subsection Archiving Sparse Files
8455 @cindex Sparse Files
8456
8457 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
8458 in a file is a section of the file's contents which was never written.
8459 The contents of a hole reads as all zeros. On many operating systems,
8460 actual disk storage is not allocated for holes, but they are counted
8461 in the length of the file. If you archive such a file, @command{tar}
8462 could create an archive longer than the original. To have @command{tar}
8463 attempt to recognize the holes in a file, use @option{--sparse}
8464 (@option{-S}). When you use this option, then, for any file using
8465 less disk space than would be expected from its length, @command{tar}
8466 searches the file for consecutive stretches of zeros. It then records
8467 in the archive for the file where the consecutive stretches of zeros
8468 are, and only archives the ``real contents'' of the file. On
8469 extraction (using @option{--sparse} is not needed on extraction) any
8470 such files have holes created wherever the continuous stretches of zeros
8471 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8472 won't take more space than the original.
8473
8474 @table @option
8475 @opindex sparse
8476 @item -S
8477 @itemx --sparse
8478 This option instructs @command{tar} to test each file for sparseness
8479 before attempting to archive it. If the file is found to be sparse it
8480 is treated specially, thus allowing to decrease the amount of space
8481 used by its image in the archive.
8482
8483 This option is meaningful only when creating or updating archives. It
8484 has no effect on extraction.
8485 @end table
8486
8487 Consider using @option{--sparse} when performing file system backups,
8488 to avoid archiving the expanded forms of files stored sparsely in the
8489 system.
8490
8491 Even if your system has no sparse files currently, some may be
8492 created in the future. If you use @option{--sparse} while making file
8493 system backups as a matter of course, you can be assured the archive
8494 will never take more space on the media than the files take on disk
8495 (otherwise, archiving a disk filled with sparse files might take
8496 hundreds of tapes). @xref{Incremental Dumps}.
8497
8498 However, be aware that @option{--sparse} option presents a serious
8499 drawback. Namely, in order to determine if the file is sparse
8500 @command{tar} has to read it before trying to archive it, so in total
8501 the file is read @strong{twice}. So, always bear in mind that the
8502 time needed to process all files with this option is roughly twice
8503 the time needed to archive them without it.
8504 @FIXME{A technical note:
8505
8506 Programs like @command{dump} do not have to read the entire file; by
8507 examining the file system directly, they can determine in advance
8508 exactly where the holes are and thus avoid reading through them. The
8509 only data it need read are the actual allocated data blocks.
8510 @GNUTAR{} uses a more portable and straightforward
8511 archiving approach, it would be fairly difficult that it does
8512 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8513 1990-12-10:
8514
8515 @quotation
8516 What I did say is that you cannot tell the difference between a hole and an
8517 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8518 best tells you how many holes there are; it doesn't tell you @emph{where}.
8519 Just as programs may, conceivably, care what @code{st_blocks} is (care
8520 to name one that does?), they may also care where the holes are (I have
8521 no examples of this one either, but it's equally imaginable).
8522
8523 I conclude from this that good archivers are not portable. One can
8524 arguably conclude that if you want a portable program, you can in good
8525 conscience restore files with as many holes as possible, since you can't
8526 get it right.
8527 @end quotation
8528 }
8529
8530 @cindex sparse formats, defined
8531 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8532 sparse files using in three distinct ways, called @dfn{sparse
8533 formats}. A sparse format is identified by its @dfn{number},
8534 consisting, as usual of two decimal numbers, delimited by a dot. By
8535 default, format @samp{1.0} is used. If, for some reason, you wish to
8536 use an earlier format, you can select it using
8537 @option{--sparse-version} option.
8538
8539 @table @option
8540 @opindex sparse-version
8541 @item --sparse-version=@var{version}
8542
8543 Select the format to store sparse files in. Valid @var{version} values
8544 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8545 for a detailed description of each format.
8546 @end table
8547
8548 Using @option{--sparse-format} option implies @option{--sparse}.
8549
8550 @node Attributes
8551 @section Handling File Attributes
8552 @UNREVISED
8553
8554 When @command{tar} reads files, it updates their access times. To
8555 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8556 reset the access time retroactively or avoid changing it in the first
8557 place.
8558
8559 Handling of file attributes
8560
8561 @table @option
8562 @opindex atime-preserve
8563 @item --atime-preserve
8564 @itemx --atime-preserve=replace
8565 @itemx --atime-preserve=system
8566 Preserve the access times of files that are read. This works only for
8567 files that you own, unless you have superuser privileges.
8568
8569 @option{--atime-preserve=replace} works on most systems, but it also
8570 restores the data modification time and updates the status change
8571 time. Hence it doesn't interact with incremental dumps nicely
8572 (@pxref{Incremental Dumps}), and it can set access or data modification times
8573 incorrectly if other programs access the file while @command{tar} is
8574 running.
8575
8576 @option{--atime-preserve=system} avoids changing the access time in
8577 the first place, if the operating system supports this.
8578 Unfortunately, this may or may not work on any given operating system
8579 or file system. If @command{tar} knows for sure it won't work, it
8580 complains right away.
8581
8582 Currently @option{--atime-preserve} with no operand defaults to
8583 @option{--atime-preserve=replace}, but this is intended to change to
8584 @option{--atime-preserve=system} when the latter is better-supported.
8585
8586 @opindex touch
8587 @item -m
8588 @itemx --touch
8589 Do not extract data modification time.
8590
8591 When this option is used, @command{tar} leaves the data modification times
8592 of the files it extracts as the times when the files were extracted,
8593 instead of setting it to the times recorded in the archive.
8594
8595 This option is meaningless with @option{--list} (@option{-t}).
8596
8597 @opindex same-owner
8598 @item --same-owner
8599 Create extracted files with the same ownership they have in the
8600 archive.
8601
8602 This is the default behavior for the superuser,
8603 so this option is meaningful only for non-root users, when @command{tar}
8604 is executed on those systems able to give files away. This is
8605 considered as a security flaw by many people, at least because it
8606 makes quite difficult to correctly account users for the disk space
8607 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8608 files are easily and silently lost when files are given away.
8609
8610 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
8611 separately. If it can't find a user name (because the user @acronym{ID} is not
8612 in @file{/etc/passwd}), then it does not write one. When restoring,
8613 it tries to look the name (if one was written) up in
8614 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
8615 the archive instead.
8616
8617 @opindex no-same-owner
8618 @item --no-same-owner
8619 @itemx -o
8620 Do not attempt to restore ownership when extracting. This is the
8621 default behavior for ordinary users, so this option has an effect
8622 only for the superuser.
8623
8624 @opindex numeric-owner
8625 @item --numeric-owner
8626 The @option{--numeric-owner} option allows (ANSI) archives to be written
8627 without user/group name information or such information to be ignored
8628 when extracting. It effectively disables the generation and/or use
8629 of user/group name information. This option forces extraction using
8630 the numeric ids from the archive, ignoring the names.
8631
8632 This is useful in certain circumstances, when restoring a backup from
8633 an emergency floppy with different passwd/group files for example.
8634 It is otherwise impossible to extract files with the right ownerships
8635 if the password file in use during the extraction does not match the
8636 one belonging to the file system(s) being extracted. This occurs,
8637 for example, if you are restoring your files after a major crash and
8638 had booted from an emergency floppy with no password file or put your
8639 disk into another machine to do the restore.
8640
8641 The numeric ids are @emph{always} saved into @command{tar} archives.
8642 The identifying names are added at create time when provided by the
8643 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8644 used when moving archives between a collection of machines using
8645 a centralized management for attribution of numeric ids to users
8646 and groups. This is often made through using the NIS capabilities.
8647
8648 When making a @command{tar} file for distribution to other sites, it
8649 is sometimes cleaner to use a single owner for all files in the
8650 distribution, and nicer to specify the write permission bits of the
8651 files as stored in the archive independently of their actual value on
8652 the file system. The way to prepare a clean distribution is usually
8653 to have some Makefile rule creating a directory, copying all needed
8654 files in that directory, then setting ownership and permissions as
8655 wanted (there are a lot of possible schemes), and only then making a
8656 @command{tar} archive out of this directory, before cleaning
8657 everything out. Of course, we could add a lot of options to
8658 @GNUTAR{} for fine tuning permissions and ownership.
8659 This is not the good way, I think. @GNUTAR{} is
8660 already crowded with options and moreover, the approach just explained
8661 gives you a great deal of control already.
8662
8663 @xopindex{same-permissions, short description}
8664 @xopindex{preserve-permissions, short description}
8665 @item -p
8666 @itemx --same-permissions
8667 @itemx --preserve-permissions
8668 Extract all protection information.
8669
8670 This option causes @command{tar} to set the modes (access permissions) of
8671 extracted files exactly as recorded in the archive. If this option
8672 is not used, the current @code{umask} setting limits the permissions
8673 on extracted files. This option is by default enabled when
8674 @command{tar} is executed by a superuser.
8675
8676
8677 This option is meaningless with @option{--list} (@option{-t}).
8678
8679 @opindex preserve
8680 @item --preserve
8681 Same as both @option{--same-permissions} and @option{--same-order}.
8682
8683 The @option{--preserve} option has no equivalent short option name.
8684 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8685
8686 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8687 Neither do I. --Sergey}
8688
8689 @end table
8690
8691 @node Portability
8692 @section Making @command{tar} Archives More Portable
8693
8694 Creating a @command{tar} archive on a particular system that is meant to be
8695 useful later on many other machines and with other versions of @command{tar}
8696 is more challenging than you might think. @command{tar} archive formats
8697 have been evolving since the first versions of Unix. Many such formats
8698 are around, and are not always compatible with each other. This section
8699 discusses a few problems, and gives some advice about making @command{tar}
8700 archives more portable.
8701
8702 One golden rule is simplicity. For example, limit your @command{tar}
8703 archives to contain only regular files and directories, avoiding
8704 other kind of special files. Do not attempt to save sparse files or
8705 contiguous files as such. Let's discuss a few more problems, in turn.
8706
8707 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8708 archives and archive labels) in GNU and PAX formats.}
8709
8710 @menu
8711 * Portable Names:: Portable Names
8712 * dereference:: Symbolic Links
8713 * hard links:: Hard Links
8714 * old:: Old V7 Archives
8715 * ustar:: Ustar Archives
8716 * gnu:: GNU and old GNU format archives.
8717 * posix:: @acronym{POSIX} archives
8718 * Checksumming:: Checksumming Problems
8719 * Large or Negative Values:: Large files, negative time stamps, etc.
8720 * Other Tars:: How to Extract GNU-Specific Data Using
8721 Other @command{tar} Implementations
8722 @end menu
8723
8724 @node Portable Names
8725 @subsection Portable Names
8726
8727 Use portable file and member names. A name is portable if it contains
8728 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8729 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8730 contain @samp{/-}. Avoid deep directory nesting. For portability to
8731 old Unix hosts, limit your file name components to 14 characters or
8732 less.
8733
8734 If you intend to have your @command{tar} archives to be read under
8735 MSDOS, you should not rely on case distinction for file names, and you
8736 might use the @acronym{GNU} @command{doschk} program for helping you
8737 further diagnosing illegal MSDOS names, which are even more limited
8738 than System V's.
8739
8740 @node dereference
8741 @subsection Symbolic Links
8742 @cindex File names, using symbolic links
8743 @cindex Symbolic link as file name
8744
8745 @opindex dereference
8746 Normally, when @command{tar} archives a symbolic link, it writes a
8747 block to the archive naming the target of the link. In that way, the
8748 @command{tar} archive is a faithful record of the file system contents.
8749 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8750 @command{tar} to archive the files symbolic links point to, instead of
8751 the links themselves. When this option is used, when @command{tar}
8752 encounters a symbolic link, it will archive the linked-to file,
8753 instead of simply recording the presence of a symbolic link.
8754
8755 The name under which the file is stored in the file system is not
8756 recorded in the archive. To record both the symbolic link name and
8757 the file name in the system, archive the file under both names. If
8758 all links were recorded automatically by @command{tar}, an extracted file
8759 might be linked to a file name that no longer exists in the file
8760 system.
8761
8762 If a linked-to file is encountered again by @command{tar} while creating
8763 the same archive, an entire second copy of it will be stored. (This
8764 @emph{might} be considered a bug.)
8765
8766 So, for portable archives, do not archive symbolic links as such,
8767 and use @option{--dereference} (@option{-h}): many systems do not support
8768 symbolic links, and moreover, your distribution might be unusable if
8769 it contains unresolved symbolic links.
8770
8771 @node hard links
8772 @subsection Hard Links
8773 @UNREVISED{}
8774 @cindex File names, using hard links
8775 @cindex hard links, dereferencing
8776 @cindex dereferencing hard links
8777
8778 Normally, when @command{tar} archives a hard link, it writes a
8779 block to the archive naming the target of the link (a @samp{1} type
8780 block). In that way, the actual file contents is stored in file only
8781 once. For example, consider the following two files:
8782
8783 @smallexample
8784 @group
8785 $ ls
8786 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
8787 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
8788 @end group
8789 @end smallexample
8790
8791 Here, @file{jeden} is a link to @file{one}. When archiving this
8792 directory with a verbose level 2, you will get an output similar to
8793 the following:
8794
8795 @smallexample
8796 $ tar cfvv ../archive.tar .
8797 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8798 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8799 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
8800 @end smallexample
8801
8802 The last line shows that, instead of storing two copies of the file,
8803 @command{tar} stored it only once, under the name @file{jeden}, and
8804 stored file @file{one} as a hard link to this file.
8805
8806 It may be important to know that all hard links to the given file are
8807 stored in the archive. For example, this may be necessary for exact
8808 reproduction of the file system. The following option does that:
8809
8810 @table @option
8811 @xopindex{check-links, described}
8812 @item --check-links
8813 @itemx -l
8814 Check the number of links dumped for each processed file. If this
8815 number does not match the total number of hard links for the file, print
8816 a warning message.
8817 @end table
8818
8819 For example, trying to archive only file @file{jeden} with this option
8820 produces the following diagnostics:
8821
8822 @smallexample
8823 $ tar -c -f ../archive.tar jeden
8824 tar: Missing links to `jeden'.
8825 @end smallexample
8826
8827 Although creating special records for hard links helps keep a faithful
8828 record of the file system contents and makes archives more compact, it
8829 may present some difficulties when extracting individual members from
8830 the archive. For example, trying to extract file @file{one} from the
8831 archive created in previous examples produces, in the absense of file
8832 @file{jeden}:
8833
8834 @smallexample
8835 $ tar xf archive.tar ./one
8836 tar: ./one: Cannot hard link to `./jeden': No such file or directory
8837 tar: Error exit delayed from previous errors
8838 @end smallexample
8839
8840 The reason for this behavior is that @command{tar} cannot seek back in
8841 the archive to the previous member (in this case, @file{one}), to
8842 extract it@footnote{There are plans to fix this in future releases.}.
8843 If you wish to avoid such problems at the cost of a bigger archive,
8844 use the following option:
8845
8846 @table @option
8847 @xopindex{hard-dereference, described}
8848 @item --hard-dereference
8849 Dereference hard links and store the files they refer to.
8850 @end table
8851
8852 For example, trying this option on our two sample files, we get two
8853 copies in the archive, each of which can then be extracted
8854 independently of the other:
8855
8856 @smallexample
8857 @group
8858 $ tar -c -vv -f ../archive.tar --hard-dereference .
8859 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8860 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8861 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
8862 @end group
8863 @end smallexample
8864
8865 @node old
8866 @subsection Old V7 Archives
8867 @cindex Format, old style
8868 @cindex Old style format
8869 @cindex Old style archives
8870 @cindex v7 archive format
8871
8872 Certain old versions of @command{tar} cannot handle additional
8873 information recorded by newer @command{tar} programs. To create an
8874 archive in V7 format (not ANSI), which can be read by these old
8875 versions, specify the @option{--format=v7} option in
8876 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8877 accepts @option{--portability} or @option{--old-archive} for this
8878 option). When you specify it,
8879 @command{tar} leaves out information about directories, pipes, fifos,
8880 contiguous files, and device files, and specifies file ownership by
8881 group and user IDs instead of group and user names.
8882
8883 When updating an archive, do not use @option{--format=v7}
8884 unless the archive was created using this option.
8885
8886 In most cases, a @emph{new} format archive can be read by an @emph{old}
8887 @command{tar} program without serious trouble, so this option should
8888 seldom be needed. On the other hand, most modern @command{tar}s are
8889 able to read old format archives, so it might be safer for you to
8890 always use @option{--format=v7} for your distributions. Notice,
8891 however, that @samp{ustar} format is a better alternative, as it is
8892 free from many of @samp{v7}'s drawbacks.
8893
8894 @node ustar
8895 @subsection Ustar Archive Format
8896
8897 @cindex ustar archive format
8898 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8899 @code{ustar}. Although it is more flexible than the V7 format, it
8900 still has many restrictions (@xref{Formats,ustar}, for the detailed
8901 description of @code{ustar} format). Along with V7 format,
8902 @code{ustar} format is a good choice for archives intended to be read
8903 with other implementations of @command{tar}.
8904
8905 To create archive in @code{ustar} format, use @option{--format=ustar}
8906 option in conjunction with the @option{--create} (@option{-c}).
8907
8908 @node gnu
8909 @subsection @acronym{GNU} and old @GNUTAR{} format
8910
8911 @cindex GNU archive format
8912 @cindex Old GNU archive format
8913 @GNUTAR{} was based on an early draft of the
8914 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8915 @command{tar}, such as the support for file names longer than 100
8916 characters, use portions of the @command{tar} header record which were
8917 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8918 @acronym{POSIX} have allocated the same parts of the header record for
8919 other purposes. As a result, @GNUTAR{} format is
8920 incompatible with the current @acronym{POSIX} specification, and with
8921 @command{tar} programs that follow it.
8922
8923 In the majority of cases, @command{tar} will be configured to create
8924 this format by default. This will change in future releases, since
8925 we plan to make @samp{POSIX} format the default.
8926
8927 To force creation a @GNUTAR{} archive, use option
8928 @option{--format=gnu}.
8929
8930 @node posix
8931 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8932
8933 @cindex POSIX archive format
8934 @cindex PAX archive format
8935 Starting from version 1.14 @GNUTAR{} features full support for
8936 @acronym{POSIX.1-2001} archives.
8937
8938 A @acronym{POSIX} conformant archive will be created if @command{tar}
8939 was given @option{--format=posix} (@option{--format=pax}) option. No
8940 special option is required to read and extract from a @acronym{POSIX}
8941 archive.
8942
8943 @menu
8944 * PAX keywords:: Controlling Extended Header Keywords.
8945 @end menu
8946
8947 @node PAX keywords
8948 @subsubsection Controlling Extended Header Keywords
8949
8950 @table @option
8951 @opindex pax-option
8952 @item --pax-option=@var{keyword-list}
8953 Handle keywords in @acronym{PAX} extended headers. This option is
8954 equivalent to @option{-o} option of the @command{pax} utility.
8955 @end table
8956
8957 @var{Keyword-list} is a comma-separated
8958 list of keyword options, each keyword option taking one of
8959 the following forms:
8960
8961 @table @code
8962 @item delete=@var{pattern}
8963 When used with one of archive-creation commands,
8964 this option instructs @command{tar} to omit from extended header records
8965 that it produces any keywords matching the string @var{pattern}.
8966
8967 When used in extract or list mode, this option instructs tar
8968 to ignore any keywords matching the given @var{pattern} in the extended
8969 header records. In both cases, matching is performed using the pattern
8970 matching notation described in @acronym{POSIX 1003.2}, 3.13
8971 (@pxref{wildcards}). For example:
8972
8973 @smallexample
8974 --pax-option delete=security.*
8975 @end smallexample
8976
8977 would suppress security-related information.
8978
8979 @item exthdr.name=@var{string}
8980
8981 This keyword allows user control over the name that is written into the
8982 ustar header blocks for the extended headers. The name is obtained
8983 from @var{string} after making the following substitutions:
8984
8985 @multitable @columnfractions .25 .55
8986 @headitem Meta-character @tab Replaced By
8987 @item %d @tab The directory name of the file, equivalent to the
8988 result of the @command{dirname} utility on the translated file name.
8989 @item %f @tab The name of the file with the directory information
8990 stripped, equivalent to the result of the @command{basename} utility
8991 on the translated file name.
8992 @item %p @tab The process @acronym{ID} of the @command{tar} process.
8993 @item %% @tab A @samp{%} character.
8994 @end multitable
8995
8996 Any other @samp{%} characters in @var{string} produce undefined
8997 results.
8998
8999 If no option @samp{exthdr.name=string} is specified, @command{tar}
9000 will use the following default value:
9001
9002 @smallexample
9003 %d/PaxHeaders.%p/%f
9004 @end smallexample
9005
9006 @item globexthdr.name=@var{string}
9007 This keyword allows user control over the name that is written into
9008 the ustar header blocks for global extended header records. The name
9009 is obtained from the contents of @var{string}, after making
9010 the following substitutions:
9011
9012 @multitable @columnfractions .25 .55
9013 @headitem Meta-character @tab Replaced By
9014 @item %n @tab An integer that represents the
9015 sequence number of the global extended header record in the archive,
9016 starting at 1.
9017 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9018 @item %% @tab A @samp{%} character.
9019 @end multitable
9020
9021 Any other @samp{%} characters in @var{string} produce undefined results.
9022
9023 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9024 will use the following default value:
9025
9026 @smallexample
9027 $TMPDIR/GlobalHead.%p.%n
9028 @end smallexample
9029
9030 @noindent
9031 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9032 environment variable. If @var{TMPDIR} is not set, @command{tar}
9033 uses @samp{/tmp}.
9034
9035 @item @var{keyword}=@var{value}
9036 When used with one of archive-creation commands, these keyword/value pairs
9037 will be included at the beginning of the archive in a global extended
9038 header record. When used with one of archive-reading commands,
9039 @command{tar} will behave as if it has encountered these keyword/value
9040 pairs at the beginning of the archive in a global extended header
9041 record.
9042
9043 @item @var{keyword}:=@var{value}
9044 When used with one of archive-creation commands, these keyword/value pairs
9045 will be included as records at the beginning of an extended header for
9046 each file. This is effectively equivalent to @var{keyword}=@var{value}
9047 form except that it creates no global extended header records.
9048
9049 When used with one of archive-reading commands, @command{tar} will
9050 behave as if these keyword/value pairs were included as records at the
9051 end of each extended header; thus, they will override any global or
9052 file-specific extended header record keywords of the same names.
9053 For example, in the command:
9054
9055 @smallexample
9056 tar --format=posix --create \
9057 --file archive --pax-option gname:=user .
9058 @end smallexample
9059
9060 the group name will be forced to a new value for all files
9061 stored in the archive.
9062 @end table
9063
9064 @node Checksumming
9065 @subsection Checksumming Problems
9066
9067 SunOS and HP-UX @command{tar} fail to accept archives created using
9068 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9069 is, file names having characters with the eight bit set, because they
9070 use signed checksums, while @GNUTAR{} uses unsigned
9071 checksums while creating archives, as per @acronym{POSIX} standards. On
9072 reading, @GNUTAR{} computes both checksums and
9073 accept any. It is somewhat worrying that a lot of people may go
9074 around doing backup of their files using faulty (or at least
9075 non-standard) software, not learning about it until it's time to
9076 restore their missing files with an incompatible file extractor, or
9077 vice versa.
9078
9079 @GNUTAR{} compute checksums both ways, and accept
9080 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9081 wrong checksums. @GNUTAR{} produces the standard
9082 checksum, however, raising incompatibilities with Sun. That is to
9083 say, @GNUTAR{} has not been modified to
9084 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9085 I've been told that more recent Sun @command{tar} now read standard
9086 archives, so maybe Sun did a similar patch, after all?
9087
9088 The story seems to be that when Sun first imported @command{tar}
9089 sources on their system, they recompiled it without realizing that
9090 the checksums were computed differently, because of a change in
9091 the default signing of @code{char}'s in their compiler. So they
9092 started computing checksums wrongly. When they later realized their
9093 mistake, they merely decided to stay compatible with it, and with
9094 themselves afterwards. Presumably, but I do not really know, HP-UX
9095 has chosen that their @command{tar} archives to be compatible with Sun's.
9096 The current standards do not favor Sun @command{tar} format. In any
9097 case, it now falls on the shoulders of SunOS and HP-UX users to get
9098 a @command{tar} able to read the good archives they receive.
9099
9100 @node Large or Negative Values
9101 @subsection Large or Negative Values
9102 @cindex large values
9103 @cindex future time stamps
9104 @cindex negative time stamps
9105 @UNREVISED{}
9106
9107 The above sections suggest to use @samp{oldest possible} archive
9108 format if in doubt. However, sometimes it is not possible. If you
9109 attempt to archive a file whose metadata cannot be represented using
9110 required format, @GNUTAR{} will print error message and ignore such a
9111 file. You will than have to switch to a format that is able to
9112 handle such values. The format summary table (@pxref{Formats}) will
9113 help you to do so.
9114
9115 In particular, when trying to archive files larger than 8GB or with
9116 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9117 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9118 @acronym{POSIX} archive formats. When considering which format to
9119 choose, bear in mind that the @acronym{GNU} format uses
9120 two's-complement base-256 notation to store values that do not fit
9121 into standard @acronym{ustar} range. Such archives can generally be
9122 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9123 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9124 example, using two's complement representation for negative time
9125 stamps that assumes a signed 32-bit @code{time_t} generates archives
9126 that are not portable to hosts with differing @code{time_t}
9127 representations.
9128
9129 On the other hand, @acronym{POSIX} archives, generally speaking, can
9130 be extracted by any tar implementation that understands older
9131 @acronym{ustar} format. The only exception are files larger than 8GB.
9132
9133 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9134 POSIX-aware tars.}
9135
9136 @node Other Tars
9137 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9138
9139 In previous sections you became acquainted with various quirks
9140 necessary to make your archives portable. Sometimes you may need to
9141 extract archives containing GNU-specific members using some
9142 third-party @command{tar} implementation or an older version of
9143 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9144 but if it is for some reason impossible, this section will explain
9145 how to cope without it.
9146
9147 When we speak about @dfn{GNU-specific} members we mean two classes of
9148 them: members split between the volumes of a multi-volume archive and
9149 sparse members. You will be able to always recover such members if
9150 the archive is in PAX format. In addition split members can be
9151 recovered from archives in old GNU format. The following subsections
9152 describe the required procedures in detail.
9153
9154 @menu
9155 * Split Recovery:: Members Split Between Volumes
9156 * Sparse Recovery:: Sparse Members
9157 @end menu
9158
9159 @node Split Recovery
9160 @subsubsection Extracting Members Split Between Volumes
9161
9162 @cindex Mutli-volume archives, extracting using non-GNU tars
9163 If a member is split between several volumes of an old GNU format archive
9164 most third party @command{tar} implementation will fail to extract
9165 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9166 This program is available from
9167 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9168 home page}. It concatenates several archive volumes into a single
9169 valid archive. For example, if you have three volumes named from
9170 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9171 extract them using a third-party @command{tar}:
9172
9173 @smallexample
9174 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9175 @end smallexample
9176
9177 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9178 You could use this approach for most (although not all) PAX
9179 format archives as well. However, extracting split members from a PAX
9180 archive is a much easier task, because PAX volumes are constructed in
9181 such a way that each part of a split member is extracted to a
9182 different file by @command{tar} implementations that are not aware of
9183 GNU extensions. More specifically, the very first part retains its
9184 original name, and all subsequent parts are named using the pattern:
9185
9186 @smallexample
9187 %d/GNUFileParts.%p/%f.%n
9188 @end smallexample
9189
9190 @noindent
9191 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9192 have the following meaning:
9193
9194 @multitable @columnfractions .25 .55
9195 @headitem Meta-character @tab Replaced By
9196 @item %d @tab The directory name of the file, equivalent to the
9197 result of the @command{dirname} utility on its full name.
9198 @item %f @tab The file name of the file, equivalent to the result
9199 of the @command{basename} utility on its full name.
9200 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9201 created the archive.
9202 @item %n @tab Ordinal number of this particular part.
9203 @end multitable
9204
9205 For example, if the file @file{var/longfile} was split during archive
9206 creation between three volumes, and the creator @command{tar} process
9207 had process @acronym{ID} @samp{27962}, then the member names will be:
9208
9209 @smallexample
9210 var/longfile
9211 var/GNUFileParts.27962/longfile.1
9212 var/GNUFileParts.27962/longfile.2
9213 @end smallexample
9214
9215 When you extract your archive using a third-party @command{tar}, these
9216 files will be created on your disk, and the only thing you will need
9217 to do to restore your file in its original form is concatenate them in
9218 the proper order, for example:
9219
9220 @smallexample
9221 @group
9222 $ @kbd{cd var}
9223 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9224 GNUFileParts.27962/longfile.2 >> longfile}
9225 $ rm -f GNUFileParts.27962
9226 @end group
9227 @end smallexample
9228
9229 Notice, that if the @command{tar} implementation you use supports PAX
9230 format archives, it will probably emit warnings about unknown keywords
9231 during extraction. They will look like this:
9232
9233 @smallexample
9234 @group
9235 Tar file too small
9236 Unknown extended header keyword 'GNU.volume.filename' ignored.
9237 Unknown extended header keyword 'GNU.volume.size' ignored.
9238 Unknown extended header keyword 'GNU.volume.offset' ignored.
9239 @end group
9240 @end smallexample
9241
9242 @noindent
9243 You can safely ignore these warnings.
9244
9245 If your @command{tar} implementation is not PAX-aware, you will get
9246 more warnings and more files generated on your disk, e.g.:
9247
9248 @smallexample
9249 @group
9250 $ @kbd{tar xf vol-1.tar}
9251 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9252 normal file
9253 Unexpected EOF in archive
9254 $ @kbd{tar xf vol-2.tar}
9255 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9256 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9257 'x', extracted as normal file
9258 @end group
9259 @end smallexample
9260
9261 Ignore these warnings. The @file{PaxHeaders.*} directories created
9262 will contain files with @dfn{extended header keywords} describing the
9263 extracted files. You can delete them, unless they describe sparse
9264 members. Read further to learn more about them.
9265
9266 @node Sparse Recovery
9267 @subsubsection Extracting Sparse Members
9268
9269 @cindex sparse files, extracting with non-GNU tars
9270 Any @command{tar} implementation will be able to extract sparse members from a
9271 PAX archive. However, the extracted files will be @dfn{condensed},
9272 i.e., any zero blocks will be removed from them. When we restore such
9273 a condensed file to its original form, by adding zero blocks (or
9274 @dfn{holes}) back to their original locations, we call this process
9275 @dfn{expanding} a compressed sparse file.
9276
9277 @pindex xsparse
9278 To expand a file, you will need a simple auxiliary program called
9279 @command{xsparse}. It is available in source form from
9280 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9281 home page}.
9282
9283 @cindex sparse files v.1.0, extracting with non-GNU tars
9284 Let's begin with archive members in @dfn{sparse format
9285 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9286 The condensed file will contain both file map and file data, so no
9287 additional data will be needed to restore it. If the original file
9288 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9289 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9290 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
9291 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9292 archive (@pxref{PAX keywords}).}.
9293
9294 To expand a version 1.0 file, run @command{xsparse} as follows:
9295
9296 @smallexample
9297 $ @kbd{xsparse @file{cond-file}}
9298 @end smallexample
9299
9300 @noindent
9301 where @file{cond-file} is the name of the condensed file. The utility
9302 will deduce the name for the resulting expanded file using the
9303 following algorithm:
9304
9305 @enumerate 1
9306 @item If @file{cond-file} does not contain any directories,
9307 @file{../cond-file} will be used;
9308
9309 @item If @file{cond-file} has the form
9310 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
9311 are simple names, with no @samp{/} characters in them, the output file
9312 name will be @file{@var{dir}/@var{name}}.
9313
9314 @item Otherwise, if @file{cond-file} has the form
9315 @file{@var{dir}/@var{name}}, the output file name will be
9316 @file{@var{name}}.
9317 @end enumerate
9318
9319 In the unlikely case when this algorithm does not suit your needs,
9320 you can explicitly specify output file name as a second argument to
9321 the command:
9322
9323 @smallexample
9324 $ @kbd{xsparse @file{cond-file} @file{out-file}}
9325 @end smallexample
9326
9327 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
9328 first. In this mode, the command does not actually expand the file,
9329 but verbosely lists all actions it would be taking to do so. The dry
9330 run mode is enabled by @option{-n} command line argument:
9331
9332 @smallexample
9333 @group
9334 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
9335 Reading v.1.0 sparse map
9336 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9337 `/home/gray/sparsefile'
9338 Finished dry run
9339 @end group
9340 @end smallexample
9341
9342 To actually expand the file, you would run:
9343
9344 @smallexample
9345 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9346 @end smallexample
9347
9348 @noindent
9349 The program behaves the same way all UNIX utilities do: it will keep
9350 quiet unless it has simething important to tell you (e.g. an error
9351 condition or something). If you wish it to produce verbose output,
9352 similar to that from the dry run mode, use @option{-v} option:
9353
9354 @smallexample
9355 @group
9356 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
9357 Reading v.1.0 sparse map
9358 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9359 `/home/gray/sparsefile'
9360 Done
9361 @end group
9362 @end smallexample
9363
9364 Additionally, if your @command{tar} implementation has extracted the
9365 @dfn{extended headers} for this file, you can instruct @command{xstar}
9366 to use them in order to verify the integrity of the expanded file.
9367 The option @option{-x} sets the name of the extended header file to
9368 use. Continuing our example:
9369
9370 @smallexample
9371 @group
9372 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
9373 /home/gray/GNUSparseFile.6058/sparsefile}
9374 Reading extended header file
9375 Found variable GNU.sparse.major = 1
9376 Found variable GNU.sparse.minor = 0
9377 Found variable GNU.sparse.name = sparsefile
9378 Found variable GNU.sparse.realsize = 217481216
9379 Reading v.1.0 sparse map
9380 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9381 `/home/gray/sparsefile'
9382 Done
9383 @end group
9384 @end smallexample
9385
9386 @anchor{extracting sparse v.0.x}
9387 @cindex sparse files v.0.1, extracting with non-GNU tars
9388 @cindex sparse files v.0.0, extracting with non-GNU tars
9389 An @dfn{extended header} is a special @command{tar} archive header
9390 that precedes an archive member and contains a set of
9391 @dfn{variables}, describing the member properties that cannot be
9392 stored in the standard @code{ustar} header. While optional for
9393 expanding sparse version 1.0 members, the use of extended headers is
9394 mandatory when expanding sparse members in older sparse formats: v.0.0
9395 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
9396 Formats}.) So, for these formats, the question is: how to obtain
9397 extended headers from the archive?
9398
9399 If you use a @command{tar} implementation that does not support PAX
9400 format, extended headers for each member will be extracted as a
9401 separate file. If we represent the member name as
9402 @file{@var{dir}/@var{name}}, then the extended header file will be
9403 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
9404 @var{n} is an integer number.
9405
9406 Things become more difficult if your @command{tar} implementation
9407 does support PAX headers, because in this case you will have to
9408 manually extract the headers. We recommend the following algorithm:
9409
9410 @enumerate 1
9411 @item
9412 Consult the documentation of your @command{tar} implementation for an
9413 option that prints @dfn{block numbers} along with the archive
9414 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
9415 @command{star} has @option{-block-number}.
9416
9417 @item
9418 Obtain verbose listing using the @samp{block number} option, and
9419 find block numbers of the sparse member in question and the member
9420 immediately following it. For example, running @command{star} on our
9421 archive we obtain:
9422
9423 @smallexample
9424 @group
9425 $ @kbd{star -t -v -block-number -f arc.tar}
9426 @dots{}
9427 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
9428 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
9429 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
9430 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
9431 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
9432 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
9433 @dots{}
9434 @end group
9435 @end smallexample
9436
9437 @noindent
9438 (as usual, ignore the warnings about unknown keywords.)
9439
9440 @item
9441 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
9442 and @var{Bn} be the block number of the next member.
9443 Compute:
9444
9445 @smallexample
9446 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
9447 @end smallexample
9448
9449 @noindent
9450 This number gives the size of the extended header part in tar @dfn{blocks}.
9451 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
9452 = 7}.
9453
9454 @item
9455 Use @command{dd} to extract the headers:
9456
9457 @smallexample
9458 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
9459 @end smallexample
9460
9461 @noindent
9462 where @var{archive} is the archive name, @var{hname} is a name of the
9463 file to store the extended header in, @var{Bs} and @var{N} are
9464 computed in previous steps.
9465
9466 In our example, this command will be
9467
9468 @smallexample
9469 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
9470 @end smallexample
9471 @end enumerate
9472
9473 Finally, you can expand the condensed file, using the obtained header:
9474
9475 @smallexample
9476 @group
9477 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
9478 Reading extended header file
9479 Found variable GNU.sparse.size = 217481216
9480 Found variable GNU.sparse.numblocks = 208
9481 Found variable GNU.sparse.name = sparsefile
9482 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
9483 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
9484 Done
9485 @end group
9486 @end smallexample
9487
9488 @node cpio
9489 @section Comparison of @command{tar} and @command{cpio}
9490 @UNREVISED
9491
9492 @FIXME{Reorganize the following material}
9493
9494 The @command{cpio} archive formats, like @command{tar}, do have maximum
9495 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
9496 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
9497 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
9498 with arbitrary file name lengths, but other @command{cpio} implementations
9499 may crash unexplainedly trying to read them.
9500
9501 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
9502 @command{cpio} doesn't handle symbolic links in the form in which it comes
9503 in System V prior to SVR4, and some vendors may have added symlinks
9504 to their system without enhancing @command{cpio} to know about them.
9505 Others may have enhanced it in a way other than the way I did it
9506 at Sun, and which was adopted by AT&T (and which is, I think, also
9507 present in the @command{cpio} that Berkeley picked up from AT&T and put
9508 into a later @acronym{BSD} release---I think I gave them my changes).
9509
9510 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
9511 can handle @command{tar} format input, and write it on output, and it
9512 probably handles symbolic links. They may not have bothered doing
9513 anything to enhance @command{tar} as a result.)
9514
9515 @command{cpio} handles special files; traditional @command{tar} doesn't.
9516
9517 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
9518 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
9519 (4.3-tahoe and later).
9520
9521 @command{tar}'s way of handling multiple hard links to a file can handle
9522 file systems that support 32-bit inumbers (e.g., the @acronym{BSD} file system);
9523 @command{cpio}s way requires you to play some games (in its ``binary''
9524 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
9525 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
9526 field of the header to make sure that the file system @acronym{ID}/i-number pairs
9527 of different files were always different), and I don't know which
9528 @command{cpio}s, if any, play those games. Those that don't might get
9529 confused and think two files are the same file when they're not, and
9530 make hard links between them.
9531
9532 @command{tar}s way of handling multiple hard links to a file places only
9533 one copy of the link on the tape, but the name attached to that copy
9534 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
9535 way puts one copy for every link, but you can retrieve it using any
9536 of the names.
9537
9538 @quotation
9539 What type of check sum (if any) is used, and how is this calculated.
9540 @end quotation
9541
9542 See the attached manual pages for @command{tar} and @command{cpio} format.
9543 @command{tar} uses a checksum which is the sum of all the bytes in the
9544 @command{tar} header for a file; @command{cpio} uses no checksum.
9545
9546 @quotation
9547 If anyone knows why @command{cpio} was made when @command{tar} was present
9548 at the unix scene,
9549 @end quotation
9550
9551 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
9552 generally-available version of UNIX had @command{tar} at the time. I don't
9553 know whether any version that was generally available @emph{within AT&T}
9554 had @command{tar}, or, if so, whether the people within AT&T who did
9555 @command{cpio} knew about it.
9556
9557 On restore, if there is a corruption on a tape @command{tar} will stop at
9558 that point, while @command{cpio} will skip over it and try to restore the
9559 rest of the files.
9560
9561 The main difference is just in the command syntax and header format.
9562
9563 @command{tar} is a little more tape-oriented in that everything is blocked
9564 to start on a record boundary.
9565
9566 @quotation
9567 Is there any differences between the ability to recover crashed
9568 archives between the two of them. (Is there any chance of recovering
9569 crashed archives at all.)
9570 @end quotation
9571
9572 Theoretically it should be easier under @command{tar} since the blocking
9573 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9574 However, modern @command{cpio}'s and variations have an option to just
9575 search for the next file header after an error with a reasonable chance
9576 of resyncing. However, lots of tape driver software won't allow you to
9577 continue past a media error which should be the only reason for getting
9578 out of sync unless a file changed sizes while you were writing the
9579 archive.
9580
9581 @quotation
9582 If anyone knows why @command{cpio} was made when @command{tar} was present
9583 at the unix scene, please tell me about this too.
9584 @end quotation
9585
9586 Probably because it is more media efficient (by not blocking everything
9587 and using only the space needed for the headers where @command{tar}
9588 always uses 512 bytes per file header) and it knows how to archive
9589 special files.
9590
9591 You might want to look at the freely available alternatives. The
9592 major ones are @command{afio}, @GNUTAR{}, and
9593 @command{pax}, each of which have their own extensions with some
9594 backwards compatibility.
9595
9596 Sparse files were @command{tar}red as sparse files (which you can
9597 easily test, because the resulting archive gets smaller, and
9598 @acronym{GNU} @command{cpio} can no longer read it).
9599
9600 @node Media
9601 @chapter Tapes and Other Archive Media
9602 @UNREVISED
9603
9604 A few special cases about tape handling warrant more detailed
9605 description. These special cases are discussed below.
9606
9607 Many complexities surround the use of @command{tar} on tape drives. Since
9608 the creation and manipulation of archives located on magnetic tape was
9609 the original purpose of @command{tar}, it contains many features making
9610 such manipulation easier.
9611
9612 Archives are usually written on dismountable media---tape cartridges,
9613 mag tapes, or floppy disks.
9614
9615 The amount of data a tape or disk holds depends not only on its size,
9616 but also on how it is formatted. A 2400 foot long reel of mag tape
9617 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9618 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9619
9620 Magnetic media are re-usable---once the archive on a tape is no longer
9621 needed, the archive can be erased and the tape or disk used over.
9622 Media quality does deteriorate with use, however. Most tapes or disks
9623 should be discarded when they begin to produce data errors. EXABYTE
9624 tape cartridges should be discarded when they generate an @dfn{error
9625 count} (number of non-usable bits) of more than 10k.
9626
9627 Magnetic media are written and erased using magnetic fields, and
9628 should be protected from such fields to avoid damage to stored data.
9629 Sticking a floppy disk to a filing cabinet using a magnet is probably
9630 not a good idea.
9631
9632 @menu
9633 * Device:: Device selection and switching
9634 * Remote Tape Server::
9635 * Common Problems and Solutions::
9636 * Blocking:: Blocking
9637 * Many:: Many archives on one tape
9638 * Using Multiple Tapes:: Using Multiple Tapes
9639 * label:: Including a Label in the Archive
9640 * verify::
9641 * Write Protection::
9642 @end menu
9643
9644 @node Device
9645 @section Device Selection and Switching
9646 @UNREVISED
9647
9648 @table @option
9649 @item -f [@var{hostname}:]@var{file}
9650 @itemx --file=[@var{hostname}:]@var{file}
9651 Use archive file or device @var{file} on @var{hostname}.
9652 @end table
9653
9654 This option is used to specify the file name of the archive @command{tar}
9655 works on.
9656
9657 If the file name is @samp{-}, @command{tar} reads the archive from standard
9658 input (when listing or extracting), or writes it to standard output
9659 (when creating). If the @samp{-} file name is given when updating an
9660 archive, @command{tar} will read the original archive from its standard
9661 input, and will write the entire new archive to its standard output.
9662
9663 If the file name contains a @samp{:}, it is interpreted as
9664 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9665 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9666 either case, @command{tar} will invoke the command @command{rsh} (or
9667 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9668 machine. If you give an alternate login name, it will be given to the
9669 @command{rsh}.
9670 Naturally, the remote machine must have an executable
9671 @command{/usr/libexec/rmt}. This program is free software from the
9672 University of California, and a copy of the source code can be found
9673 with the sources for @command{tar}; it's compiled and installed by default.
9674 The exact path to this utility is determined when configuring the package.
9675 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9676 your installation prefix. This location may also be overridden at
9677 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9678 ---rmt-command}, for detailed description of this option. @xref{Remote
9679 Tape Server}, for the description of @command{rmt} command).
9680
9681 If this option is not given, but the environment variable @env{TAPE}
9682 is set, its value is used; otherwise, old versions of @command{tar}
9683 used a default archive name (which was picked when @command{tar} was
9684 compiled). The default is normally set up to be the @dfn{first} tape
9685 drive or other transportable I/O medium on the system.
9686
9687 Starting with version 1.11.5, @GNUTAR{} uses
9688 standard input and standard output as the default device, and I will
9689 not try anymore supporting automatic device detection at installation
9690 time. This was failing really in too many cases, it was hopeless.
9691 This is now completely left to the installer to override standard
9692 input and standard output for default device, if this seems
9693 preferable. Further, I think @emph{most} actual usages of
9694 @command{tar} are done with pipes or disks, not really tapes,
9695 cartridges or diskettes.
9696
9697 Some users think that using standard input and output is running
9698 after trouble. This could lead to a nasty surprise on your screen if
9699 you forget to specify an output file name---especially if you are going
9700 through a network or terminal server capable of buffering large amounts
9701 of output. We had so many bug reports in that area of configuring
9702 default tapes automatically, and so many contradicting requests, that
9703 we finally consider the problem to be portably intractable. We could
9704 of course use something like @samp{/dev/tape} as a default, but this
9705 is @emph{also} running after various kind of trouble, going from hung
9706 processes to accidental destruction of real tapes. After having seen
9707 all this mess, using standard input and output as a default really
9708 sounds like the only clean choice left, and a very useful one too.
9709
9710 @GNUTAR{} reads and writes archive in records, I
9711 suspect this is the main reason why block devices are preferred over
9712 character devices. Most probably, block devices are more efficient
9713 too. The installer could also check for @samp{DEFTAPE} in
9714 @file{<sys/mtio.h>}.
9715
9716 @table @option
9717 @xopindex{force-local, short description}
9718 @item --force-local
9719 Archive file is local even if it contains a colon.
9720
9721 @opindex rsh-command
9722 @item --rsh-command=@var{command}
9723 Use remote @var{command} instead of @command{rsh}. This option exists
9724 so that people who use something other than the standard @command{rsh}
9725 (e.g., a Kerberized @command{rsh}) can access a remote device.
9726
9727 When this command is not used, the shell command found when
9728 the @command{tar} program was installed is used instead. This is
9729 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9730 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9731 The installer may have overridden this by defining the environment
9732 variable @env{RSH} @emph{at installation time}.
9733
9734 @item -[0-7][lmh]
9735 Specify drive and density.
9736
9737 @xopindex{multi-volume, short description}
9738 @item -M
9739 @itemx --multi-volume
9740 Create/list/extract multi-volume archive.
9741
9742 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9743 that may be larger than will fit on the medium used to hold it.
9744 @xref{Multi-Volume Archives}.
9745
9746 @xopindex{tape-length, short description}
9747 @item -L @var{num}
9748 @itemx --tape-length=@var{num}
9749 Change tape after writing @var{num} x 1024 bytes.
9750
9751 This option might be useful when your tape drivers do not properly
9752 detect end of physical tapes. By being slightly conservative on the
9753 maximum tape length, you might avoid the problem entirely.
9754
9755 @xopindex{info-script, short description}
9756 @xopindex{new-volume-script, short description}
9757 @item -F @var{file}
9758 @itemx --info-script=@var{file}
9759 @itemx --new-volume-script=@var{file}
9760 Execute @file{file} at end of each tape. This implies
9761 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9762 description of this option.
9763 @end table
9764
9765 @node Remote Tape Server
9766 @section The Remote Tape Server
9767
9768 @cindex remote tape drive
9769 @pindex rmt
9770 In order to access the tape drive on a remote machine, @command{tar}
9771 uses the remote tape server written at the University of California at
9772 Berkeley. The remote tape server must be installed as
9773 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9774 want to use. @command{tar} calls @command{rmt} by running an
9775 @command{rsh} or @command{remsh} to the remote machine, optionally
9776 using a different login name if one is supplied.
9777
9778 A copy of the source for the remote tape server is provided. It is
9779 Copyright @copyright{} 1983 by the Regents of the University of
9780 California, but can be freely distributed. It is compiled and
9781 installed by default.
9782
9783 @cindex absolute file names
9784 Unless you use the @option{--absolute-names} (@option{-P}) option,
9785 @GNUTAR{} will not allow you to create an archive that contains
9786 absolute file names (a file name beginning with @samp{/}.) If you try,
9787 @command{tar} will automatically remove the leading @samp{/} from the
9788 file names it stores in the archive. It will also type a warning
9789 message telling you what it is doing.
9790
9791 When reading an archive that was created with a different
9792 @command{tar} program, @GNUTAR{} automatically
9793 extracts entries in the archive which have absolute file names as if
9794 the file names were not absolute. This is an important feature. A
9795 visitor here once gave a @command{tar} tape to an operator to restore;
9796 the operator used Sun @command{tar} instead of @GNUTAR{},
9797 and the result was that it replaced large portions of
9798 our @file{/bin} and friends with versions from the tape; needless to
9799 say, we were unhappy about having to recover the file system from
9800 backup tapes.
9801
9802 For example, if the archive contained a file @file{/usr/bin/computoy},
9803 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9804 relative to the current directory. If you want to extract the files in
9805 an archive to the same absolute names that they had when the archive
9806 was created, you should do a @samp{cd /} before extracting the files
9807 from the archive, or you should either use the @option{--absolute-names}
9808 option, or use the command @samp{tar -C / @dots{}}.
9809
9810 @cindex Ultrix 3.1 and write failure
9811 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9812 can claim that a short write near the end of a tape succeeded,
9813 when it actually failed. This will result in the -M option not
9814 working correctly. The best workaround at the moment is to use a
9815 significantly larger blocking factor than the default 20.
9816
9817 In order to update an archive, @command{tar} must be able to backspace the
9818 archive in order to reread or rewrite a record that was just read (or
9819 written). This is currently possible only on two kinds of files: normal
9820 disk files (or any other file that can be backspaced with @samp{lseek}),
9821 and industry-standard 9-track magnetic tape (or any other kind of tape
9822 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9823
9824 This means that the @option{--append}, @option{--concatenate}, and
9825 @option{--delete} commands will not work on any other kind of file.
9826 Some media simply cannot be backspaced, which means these commands and
9827 options will never be able to work on them. These non-backspacing
9828 media include pipes and cartridge tape drives.
9829
9830 Some other media can be backspaced, and @command{tar} will work on them
9831 once @command{tar} is modified to do so.
9832
9833 Archives created with the @option{--multi-volume}, @option{--label}, and
9834 @option{--incremental} (@option{-G}) options may not be readable by other version
9835 of @command{tar}. In particular, restoring a file that was split over
9836 a volume boundary will require some careful work with @command{dd}, if
9837 it can be done at all. Other versions of @command{tar} may also create
9838 an empty file whose name is that of the volume header. Some versions
9839 of @command{tar} may create normal files instead of directories archived
9840 with the @option{--incremental} (@option{-G}) option.
9841
9842 @node Common Problems and Solutions
9843 @section Some Common Problems and their Solutions
9844
9845 @ifclear PUBLISH
9846
9847 @format
9848 errors from system:
9849 permission denied
9850 no such file or directory
9851 not owner
9852
9853 errors from @command{tar}:
9854 directory checksum error
9855 header format error
9856
9857 errors from media/system:
9858 i/o error
9859 device busy
9860 @end format
9861
9862 @end ifclear
9863
9864 @node Blocking
9865 @section Blocking
9866 @UNREVISED
9867
9868 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9869 is also confusing to the expert reader. On the other hand, readers
9870 who are new to the field have a fresh mind, and they may safely skip
9871 the next two paragraphs, as the remainder of this manual uses those
9872 two terms in a quite consistent way.
9873
9874 John Gilmore, the writer of the public domain @command{tar} from which
9875 @GNUTAR{} was originally derived, wrote (June 1995):
9876
9877 @quotation
9878 The nomenclature of tape drives comes from IBM, where I believe
9879 they were invented for the IBM 650 or so. On IBM mainframes, what
9880 is recorded on tape are tape blocks. The logical organization of
9881 data is into records. There are various ways of putting records into
9882 blocks, including @code{F} (fixed sized records), @code{V} (variable
9883 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9884 to a block), @code{VB} (variable size records, @var{n} to a block),
9885 @code{VSB} (variable spanned blocked: variable sized records that can
9886 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9887 parameter specified this to the operating system.
9888
9889 The Unix man page on @command{tar} was totally confused about this.
9890 When I wrote @code{PD TAR}, I used the historically correct terminology
9891 (@command{tar} writes data records, which are grouped into blocks).
9892 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9893 here), and now Fran@,{c}ois has migrated that terminology back
9894 into the source code too.
9895 @end quotation
9896
9897 The term @dfn{physical block} means the basic transfer chunk from or
9898 to a device, after which reading or writing may stop without anything
9899 being lost. In this manual, the term @dfn{block} usually refers to
9900 a disk physical block, @emph{assuming} that each disk block is 512
9901 bytes in length. It is true that some disk devices have different
9902 physical blocks, but @command{tar} ignore these differences in its own
9903 format, which is meant to be portable, so a @command{tar} block is always
9904 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9905 The term @dfn{logical block} often represents the basic chunk of
9906 allocation of many disk blocks as a single entity, which the operating
9907 system treats somewhat atomically; this concept is only barely used
9908 in @GNUTAR{}.
9909
9910 The term @dfn{physical record} is another way to speak of a physical
9911 block, those two terms are somewhat interchangeable. In this manual,
9912 the term @dfn{record} usually refers to a tape physical block,
9913 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9914 It is true that archives may be put on disk or used with pipes,
9915 but nevertheless, @command{tar} tries to read and write the archive one
9916 @dfn{record} at a time, whatever the medium in use. One record is made
9917 up of an integral number of blocks, and this operation of putting many
9918 disk blocks into a single tape block is called @dfn{reblocking}, or
9919 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9920 the logical organization of many characters into something meaningful
9921 to the application. The term @dfn{unit record} describes a small set
9922 of characters which are transmitted whole to or by the application,
9923 and often refers to a line of text. Those two last terms are unrelated
9924 to what we call a @dfn{record} in @GNUTAR{}.
9925
9926 When writing to tapes, @command{tar} writes the contents of the archive
9927 in chunks known as @dfn{records}. To change the default blocking
9928 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9929 @var{512-size}}) option. Each record will then be composed of
9930 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9931 @xref{Standard}.) Each file written to the archive uses at least one
9932 full record. As a result, using a larger record size can result in
9933 more wasted space for small files. On the other hand, a larger record
9934 size can often be read and written much more efficiently.
9935
9936 Further complicating the problem is that some tape drives ignore the
9937 blocking entirely. For these, a larger record size can still improve
9938 performance (because the software layers above the tape drive still
9939 honor the blocking), but not as dramatically as on tape drives that
9940 honor blocking.
9941
9942 When reading an archive, @command{tar} can usually figure out the
9943 record size on itself. When this is the case, and a non-standard
9944 record size was used when the archive was created, @command{tar} will
9945 print a message about a non-standard blocking factor, and then operate
9946 normally. On some tape devices, however, @command{tar} cannot figure
9947 out the record size itself. On most of those, you can specify a
9948 blocking factor (with @option{--blocking-factor}) larger than the
9949 actual blocking factor, and then use the @option{--read-full-records}
9950 (@option{-B}) option. (If you specify a blocking factor with
9951 @option{--blocking-factor} and don't use the
9952 @option{--read-full-records} option, then @command{tar} will not
9953 attempt to figure out the recording size itself.) On some devices,
9954 you must always specify the record size exactly with
9955 @option{--blocking-factor} when reading, because @command{tar} cannot
9956 figure it out. In any case, use @option{--list} (@option{-t}) before
9957 doing any extractions to see whether @command{tar} is reading the archive
9958 correctly.
9959
9960 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9961 putting them into records is to put a whole number of them (one or
9962 more) into each record. @command{tar} records are all the same size;
9963 at the end of the file there's a block containing all zeros, which
9964 is how you tell that the remainder of the last record(s) are garbage.
9965
9966 In a standard @command{tar} file (no options), the block size is 512
9967 and the record size is 10240, for a blocking factor of 20. What the
9968 @option{--blocking-factor} option does is sets the blocking factor,
9969 changing the record size while leaving the block size at 512 bytes.
9970 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9971 most tape drives these days prefer much bigger records in order to
9972 stream and not waste tape. When writing tapes for myself, some tend
9973 to use a factor of the order of 2048, say, giving a record size of
9974 around one megabyte.
9975
9976 If you use a blocking factor larger than 20, older @command{tar}
9977 programs might not be able to read the archive, so we recommend this
9978 as a limit to use in practice. @GNUTAR{}, however,
9979 will support arbitrarily large record sizes, limited only by the
9980 amount of virtual memory or the physical characteristics of the tape
9981 device.
9982
9983 @menu
9984 * Format Variations:: Format Variations
9985 * Blocking Factor:: The Blocking Factor of an Archive
9986 @end menu
9987
9988 @node Format Variations
9989 @subsection Format Variations
9990 @cindex Format Parameters
9991 @cindex Format Options
9992 @cindex Options, archive format specifying
9993 @cindex Options, format specifying
9994 @UNREVISED
9995
9996 Format parameters specify how an archive is written on the archive
9997 media. The best choice of format parameters will vary depending on
9998 the type and number of files being archived, and on the media used to
9999 store the archive.
10000
10001 To specify format parameters when accessing or creating an archive,
10002 you can use the options described in the following sections.
10003 If you do not specify any format parameters, @command{tar} uses
10004 default parameters. You cannot modify a compressed archive.
10005 If you create an archive with the @option{--blocking-factor} option
10006 specified (@pxref{Blocking Factor}), you must specify that
10007 blocking-factor when operating on the archive. @xref{Formats}, for other
10008 examples of format parameter considerations.
10009
10010 @node Blocking Factor
10011 @subsection The Blocking Factor of an Archive
10012 @cindex Blocking Factor
10013 @cindex Record Size
10014 @cindex Number of blocks per record
10015 @cindex Number of bytes per record
10016 @cindex Bytes per record
10017 @cindex Blocks per record
10018 @UNREVISED
10019
10020 @opindex blocking-factor
10021 The data in an archive is grouped into blocks, which are 512 bytes.
10022 Blocks are read and written in whole number multiples called
10023 @dfn{records}. The number of blocks in a record (i.e., the size of a
10024 record in units of 512 bytes) is called the @dfn{blocking factor}.
10025 The @option{--blocking-factor=@var{512-size}} (@option{-b
10026 @var{512-size}}) option specifies the blocking factor of an archive.
10027 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10028 can be specified at installation. To find out the blocking factor of
10029 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10030 This may not work on some devices.
10031
10032 Records are separated by gaps, which waste space on the archive media.
10033 If you are archiving on magnetic tape, using a larger blocking factor
10034 (and therefore larger records) provides faster throughput and allows you
10035 to fit more data on a tape (because there are fewer gaps). If you are
10036 archiving on cartridge, a very large blocking factor (say 126 or more)
10037 greatly increases performance. A smaller blocking factor, on the other
10038 hand, may be useful when archiving small files, to avoid archiving lots
10039 of nulls as @command{tar} fills out the archive to the end of the record.
10040 In general, the ideal record size depends on the size of the
10041 inter-record gaps on the tape you are using, and the average size of the
10042 files you are archiving. @xref{create}, for information on
10043 writing archives.
10044
10045 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10046
10047 Archives with blocking factors larger than 20 cannot be read
10048 by very old versions of @command{tar}, or by some newer versions
10049 of @command{tar} running on old machines with small address spaces.
10050 With @GNUTAR{}, the blocking factor of an archive is limited
10051 only by the maximum record size of the device containing the archive,
10052 or by the amount of available virtual memory.
10053
10054 Also, on some systems, not using adequate blocking factors, as sometimes
10055 imposed by the device drivers, may yield unexpected diagnostics. For
10056 example, this has been reported:
10057
10058 @smallexample
10059 Cannot write to /dev/dlt: Invalid argument
10060 @end smallexample
10061
10062 @noindent
10063 In such cases, it sometimes happen that the @command{tar} bundled by
10064 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10065 requires an explicit specification for the block size,
10066 which it cannot guess. This yields some people to consider
10067 @GNUTAR{} is misbehaving, because by comparison,
10068 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10069 for example, might resolve the problem.
10070
10071 If you use a non-default blocking factor when you create an archive, you
10072 must specify the same blocking factor when you modify that archive. Some
10073 archive devices will also require you to specify the blocking factor when
10074 reading that archive, however this is not typically the case. Usually, you
10075 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10076 reports a non-default record size and then lists the archive members as
10077 it would normally. To extract files from an archive with a non-standard
10078 blocking factor (particularly if you're not sure what the blocking factor
10079 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10080 specifying a blocking factor larger then the blocking factor of the archive
10081 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
10082 @xref{list}, for more information on the @option{--list} (@option{-t})
10083 operation. @xref{Reading}, for a more detailed explanation of that option.
10084
10085 @table @option
10086 @item --blocking-factor=@var{number}
10087 @itemx -b @var{number}
10088 Specifies the blocking factor of an archive. Can be used with any
10089 operation, but is usually not necessary with @option{--list} (@option{-t}).
10090 @end table
10091
10092 Device blocking
10093
10094 @table @option
10095 @item -b @var{blocks}
10096 @itemx --blocking-factor=@var{blocks}
10097 Set record size to @math{@var{blocks} * 512} bytes.
10098
10099 This option is used to specify a @dfn{blocking factor} for the archive.
10100 When reading or writing the archive, @command{tar}, will do reads and writes
10101 of the archive in records of @math{@var{block}*512} bytes. This is true
10102 even when the archive is compressed. Some devices requires that all
10103 write operations be a multiple of a certain size, and so, @command{tar}
10104 pads the archive out to the next record boundary.
10105
10106 The default blocking factor is set when @command{tar} is compiled, and is
10107 typically 20. Blocking factors larger than 20 cannot be read by very
10108 old versions of @command{tar}, or by some newer versions of @command{tar}
10109 running on old machines with small address spaces.
10110
10111 With a magnetic tape, larger records give faster throughput and fit
10112 more data on a tape (because there are fewer inter-record gaps).
10113 If the archive is in a disk file or a pipe, you may want to specify
10114 a smaller blocking factor, since a large one will result in a large
10115 number of null bytes at the end of the archive.
10116
10117 When writing cartridge or other streaming tapes, a much larger
10118 blocking factor (say 126 or more) will greatly increase performance.
10119 However, you must specify the same blocking factor when reading or
10120 updating the archive.
10121
10122 Apparently, Exabyte drives have a physical block size of 8K bytes.
10123 If we choose our blocksize as a multiple of 8k bytes, then the problem
10124 seems to disappear. Id est, we are using block size of 112 right
10125 now, and we haven't had the problem since we switched@dots{}
10126
10127 With @GNUTAR{} the blocking factor is limited only
10128 by the maximum record size of the device containing the archive, or by
10129 the amount of available virtual memory.
10130
10131 However, deblocking or reblocking is virtually avoided in a special
10132 case which often occurs in practice, but which requires all the
10133 following conditions to be simultaneously true:
10134 @itemize @bullet
10135 @item
10136 the archive is subject to a compression option,
10137 @item
10138 the archive is not handled through standard input or output, nor
10139 redirected nor piped,
10140 @item
10141 the archive is directly handled to a local disk, instead of any special
10142 device,
10143 @item
10144 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10145 invocation.
10146 @end itemize
10147
10148 If the output goes directly to a local disk, and not through
10149 stdout, then the last write is not extended to a full record size.
10150 Otherwise, reblocking occurs. Here are a few other remarks on this
10151 topic:
10152
10153 @itemize @bullet
10154
10155 @item
10156 @command{gzip} will complain about trailing garbage if asked to
10157 uncompress a compressed archive on tape, there is an option to turn
10158 the message off, but it breaks the regularity of simply having to use
10159 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10160 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10161 Gailly, by sending a copy of this message to him.
10162
10163 @item
10164 @command{compress} does not show this problem, but as Jean-loup pointed
10165 out to Michael, @samp{compress -d} silently adds garbage after
10166 the result of decompression, which tar ignores because it already
10167 recognized its end-of-file indicator. So this bug may be safely
10168 ignored.
10169
10170 @item
10171 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10172 but will still return an exit status of 2 which tar reports in turn.
10173 @command{tar} might ignore the exit status returned, but I hate doing
10174 that, as it weakens the protection @command{tar} offers users against
10175 other possible problems at decompression time. If @command{gzip} was
10176 silently skipping trailing zeros @emph{and} also avoiding setting the
10177 exit status in this innocuous case, that would solve this situation.
10178
10179 @item
10180 @command{tar} should become more solid at not stopping to read a pipe at
10181 the first null block encountered. This inelegantly breaks the pipe.
10182 @command{tar} should rather drain the pipe out before exiting itself.
10183 @end itemize
10184
10185 @xopindex{ignore-zeros, short description}
10186 @item -i
10187 @itemx --ignore-zeros
10188 Ignore blocks of zeros in archive (means EOF).
10189
10190 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10191 of zeros in the archive. Normally a block of zeros indicates the
10192 end of the archive, but when reading a damaged archive, or one which
10193 was created by concatenating several archives together, this option
10194 allows @command{tar} to read the entire archive. This option is not on
10195 by default because many versions of @command{tar} write garbage after
10196 the zeroed blocks.
10197
10198 Note that this option causes @command{tar} to read to the end of the
10199 archive file, which may sometimes avoid problems when multiple files
10200 are stored on a single physical tape.
10201
10202 @xopindex{read-full-records, short description}
10203 @item -B
10204 @itemx --read-full-records
10205 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10206
10207 If @option{--read-full-records} is used, @command{tar}
10208 will not panic if an attempt to read a record from the archive does
10209 not return a full record. Instead, @command{tar} will keep reading
10210 until it has obtained a full
10211 record.
10212
10213 This option is turned on by default when @command{tar} is reading
10214 an archive from standard input, or from a remote machine. This is
10215 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10216 much happens to be in the pipe, even if it is less than @command{tar}
10217 requested. If this option was not used, @command{tar} would fail as
10218 soon as it read an incomplete record from the pipe.
10219
10220 This option is also useful with the commands for updating an archive.
10221
10222 @end table
10223
10224 Tape blocking
10225
10226 @FIXME{Appropriate options should be moved here from elsewhere.}
10227
10228 @cindex blocking factor
10229 @cindex tape blocking
10230
10231 When handling various tapes or cartridges, you have to take care of
10232 selecting a proper blocking, that is, the number of disk blocks you
10233 put together as a single tape block on the tape, without intervening
10234 tape gaps. A @dfn{tape gap} is a small landing area on the tape
10235 with no information on it, used for decelerating the tape to a
10236 full stop, and for later regaining the reading or writing speed.
10237 When the tape driver starts reading a record, the record has to
10238 be read whole without stopping, as a tape gap is needed to stop the
10239 tape motion without loosing information.
10240
10241 @cindex Exabyte blocking
10242 @cindex DAT blocking
10243 Using higher blocking (putting more disk blocks per tape block) will use
10244 the tape more efficiently as there will be less tape gaps. But reading
10245 such tapes may be more difficult for the system, as more memory will be
10246 required to receive at once the whole record. Further, if there is a
10247 reading error on a huge record, this is less likely that the system will
10248 succeed in recovering the information. So, blocking should not be too
10249 low, nor it should be too high. @command{tar} uses by default a blocking of
10250 20 for historical reasons, and it does not really matter when reading or
10251 writing to disk. Current tape technology would easily accommodate higher
10252 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10253 We were told that for some DLT drives, the blocking should be a multiple
10254 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10255 Other manufacturers may use different recommendations for the same tapes.
10256 This might also depends of the buffering techniques used inside modern
10257 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
10258 Others request blocking to be some exponent of two.
10259
10260 So, there is no fixed rule for blocking. But blocking at read time
10261 should ideally be the same as blocking used at write time. At one place
10262 I know, with a wide variety of equipment, they found it best to use a
10263 blocking of 32 to guarantee that their tapes are fully interchangeable.
10264
10265 I was also told that, for recycled tapes, prior erasure (by the same
10266 drive unit that will be used to create the archives) sometimes lowers
10267 the error rates observed at rewriting time.
10268
10269 I might also use @option{--number-blocks} instead of
10270 @option{--block-number}, so @option{--block} will then expand to
10271 @option{--blocking-factor} unambiguously.
10272
10273 @node Many
10274 @section Many Archives on One Tape
10275
10276 @FIXME{Appropriate options should be moved here from elsewhere.}
10277
10278 @findex ntape @r{device}
10279 Most tape devices have two entries in the @file{/dev} directory, or
10280 entries that come in pairs, which differ only in the minor number for
10281 this device. Let's take for example @file{/dev/tape}, which often
10282 points to the only or usual tape device of a given system. There might
10283 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
10284 name is the @emph{rewinding} version of the device, while the name
10285 having @samp{nr} in it is the @emph{no rewinding} version of the same
10286 device.
10287
10288 A rewinding tape device will bring back the tape to its beginning point
10289 automatically when this device is opened or closed. Since @command{tar}
10290 opens the archive file before using it and closes it afterwards, this
10291 means that a simple:
10292
10293 @smallexample
10294 $ @kbd{tar cf /dev/tape @var{directory}}
10295 @end smallexample
10296
10297 @noindent
10298 will reposition the tape to its beginning both prior and after saving
10299 @var{directory} contents to it, thus erasing prior tape contents and
10300 making it so that any subsequent write operation will destroy what has
10301 just been saved.
10302
10303 @cindex tape positioning
10304 So, a rewinding device is normally meant to hold one and only one file.
10305 If you want to put more than one @command{tar} archive on a given tape, you
10306 will need to avoid using the rewinding version of the tape device. You
10307 will also have to pay special attention to tape positioning. Errors in
10308 positioning may overwrite the valuable data already on your tape. Many
10309 people, burnt by past experiences, will only use rewinding devices and
10310 limit themselves to one file per tape, precisely to avoid the risk of
10311 such errors. Be fully aware that writing at the wrong position on a
10312 tape loses all information past this point and most probably until the
10313 end of the tape, and this destroyed information @emph{cannot} be
10314 recovered.
10315
10316 To save @var{directory-1} as a first archive at the beginning of a
10317 tape, and leave that tape ready for a second archive, you should use:
10318
10319 @smallexample
10320 $ @kbd{mt -f /dev/nrtape rewind}
10321 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
10322 @end smallexample
10323
10324 @cindex tape marks
10325 @dfn{Tape marks} are special magnetic patterns written on the tape
10326 media, which are later recognizable by the reading hardware. These
10327 marks are used after each file, when there are many on a single tape.
10328 An empty file (that is to say, two tape marks in a row) signal the
10329 logical end of the tape, after which no file exist. Usually,
10330 non-rewinding tape device drivers will react to the close request issued
10331 by @command{tar} by first writing two tape marks after your archive, and by
10332 backspacing over one of these. So, if you remove the tape at that time
10333 from the tape drive, it is properly terminated. But if you write
10334 another file at the current position, the second tape mark will be
10335 erased by the new information, leaving only one tape mark between files.
10336
10337 So, you may now save @var{directory-2} as a second archive after the
10338 first on the same tape by issuing the command:
10339
10340 @smallexample
10341 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
10342 @end smallexample
10343
10344 @noindent
10345 and so on for all the archives you want to put on the same tape.
10346
10347 Another usual case is that you do not write all the archives the same
10348 day, and you need to remove and store the tape between two archive
10349 sessions. In general, you must remember how many files are already
10350 saved on your tape. Suppose your tape already has 16 files on it, and
10351 that you are ready to write the 17th. You have to take care of skipping
10352 the first 16 tape marks before saving @var{directory-17}, say, by using
10353 these commands:
10354
10355 @smallexample
10356 $ @kbd{mt -f /dev/nrtape rewind}
10357 $ @kbd{mt -f /dev/nrtape fsf 16}
10358 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
10359 @end smallexample
10360
10361 In all the previous examples, we put aside blocking considerations, but
10362 you should do the proper things for that as well. @xref{Blocking}.
10363
10364 @menu
10365 * Tape Positioning:: Tape Positions and Tape Marks
10366 * mt:: The @command{mt} Utility
10367 @end menu
10368
10369 @node Tape Positioning
10370 @subsection Tape Positions and Tape Marks
10371 @UNREVISED
10372
10373 Just as archives can store more than one file from the file system,
10374 tapes can store more than one archive file. To keep track of where
10375 archive files (or any other type of file stored on tape) begin and
10376 end, tape archive devices write magnetic @dfn{tape marks} on the
10377 archive media. Tape drives write one tape mark between files,
10378 two at the end of all the file entries.
10379
10380 If you think of data as a series of records "rrrr"'s, and tape marks as
10381 "*"'s, a tape might look like the following:
10382
10383 @smallexample
10384 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
10385 @end smallexample
10386
10387 Tape devices read and write tapes using a read/write @dfn{tape
10388 head}---a physical part of the device which can only access one
10389 point on the tape at a time. When you use @command{tar} to read or
10390 write archive data from a tape device, the device will begin reading
10391 or writing from wherever on the tape the tape head happens to be,
10392 regardless of which archive or what part of the archive the tape
10393 head is on. Before writing an archive, you should make sure that no
10394 data on the tape will be overwritten (unless it is no longer needed).
10395 Before reading an archive, you should make sure the tape head is at
10396 the beginning of the archive you want to read. You can do it manually
10397 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
10398 that automatically (@pxref{Scripted Restoration}).
10399
10400 If you want to add new archive file entries to a tape, you should
10401 advance the tape to the end of the existing file entries, backspace
10402 over the last tape mark, and write the new archive file. If you were
10403 to add two archives to the example above, the tape might look like the
10404 following:
10405
10406 @smallexample
10407 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
10408 @end smallexample
10409
10410 @node mt
10411 @subsection The @command{mt} Utility
10412 @UNREVISED
10413
10414 @FIXME{Is it true that this only works on non-block devices?
10415 should explain the difference, (fixed or variable).}
10416 @xref{Blocking Factor}.
10417
10418 You can use the @command{mt} utility to advance or rewind a tape past a
10419 specified number of archive files on the tape. This will allow you
10420 to move to the beginning of an archive before extracting or reading
10421 it, or to the end of all the archives before writing a new one.
10422 @FIXME{Why isn't there an "advance 'til you find two tape marks
10423 together"?}
10424
10425 The syntax of the @command{mt} command is:
10426
10427 @smallexample
10428 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
10429 @end smallexample
10430
10431 where @var{tapename} is the name of the tape device, @var{number} is
10432 the number of times an operation is performed (with a default of one),
10433 and @var{operation} is one of the following:
10434
10435 @FIXME{is there any use for record operations?}
10436
10437 @table @option
10438 @item eof
10439 @itemx weof
10440 Writes @var{number} tape marks at the current position on the tape.
10441
10442 @item fsf
10443 Moves tape position forward @var{number} files.
10444
10445 @item bsf
10446 Moves tape position back @var{number} files.
10447
10448 @item rewind
10449 Rewinds the tape. (Ignores @var{number}).
10450
10451 @item offline
10452 @itemx rewoff1
10453 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
10454
10455 @item status
10456 Prints status information about the tape unit.
10457
10458 @end table
10459
10460 @FIXME{Is there a better way to frob the spacing on the list?}
10461
10462 If you don't specify a @var{tapename}, @command{mt} uses the environment
10463 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
10464 the default device specified in your @file{sys/mtio.h} file
10465 (@code{DEFTAPE} variable). If this is not defined, the program will
10466 display a descriptive error message and exit with code 1.
10467
10468 @command{mt} returns a 0 exit status when the operation(s) were
10469 successful, 1 if the command was unrecognized, and 2 if an operation
10470 failed.
10471
10472 @node Using Multiple Tapes
10473 @section Using Multiple Tapes
10474
10475 Often you might want to write a large archive, one larger than will fit
10476 on the actual tape you are using. In such a case, you can run multiple
10477 @command{tar} commands, but this can be inconvenient, particularly if you
10478 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
10479 Therefore, @command{tar} provides a special mode for creating
10480 multi-volume archives.
10481
10482 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
10483 on several media volumes of fixed size. Although in this section we will
10484 often call @samp{volume} a @dfn{tape}, there is absolutely no
10485 requirement for multi-volume archives to be stored on tapes. Instead,
10486 they can use whatever media type the user finds convenient, they can
10487 even be located on files.
10488
10489 When creating a multi-volume archive, @GNUTAR{} continues to fill
10490 current volume until it runs out of space, then it switches to
10491 next volume (usually the operator is queried to replace the tape on
10492 this point), and continues working on the new volume. This operation
10493 continues until all requested files are dumped. If @GNUTAR{} detects
10494 end of media while dumping a file, such a file is archived in split
10495 form. Some very big files can even be split across several volumes.
10496
10497 Each volume is itself a valid @GNUTAR{} archive, so it can be read
10498 without any special options. Consequently any file member residing
10499 entirely on one volume can be extracted or otherwise operated upon
10500 without needing the other volume. Sure enough, to extract a split
10501 member you would need all volumes its parts reside on.
10502
10503 Multi-volume archives suffer from several limitations. In particular,
10504 they cannot be compressed.
10505
10506 @GNUTAR{} is able to create multi-volume archives of two formats
10507 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
10508
10509 @menu
10510 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
10511 * Tape Files:: Tape Files
10512 * Tarcat:: Concatenate Volumes into a Single Archive
10513
10514 @end menu
10515
10516 @node Multi-Volume Archives
10517 @subsection Archives Longer than One Tape or Disk
10518 @cindex Multi-volume archives
10519
10520 @opindex multi-volume
10521 To create an archive that is larger than will fit on a single unit of
10522 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
10523 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
10524 archive can be manipulated like any other archive (provided the
10525 @option{--multi-volume} option is specified), but is stored on more
10526 than one tape or disk.
10527
10528 When you specify @option{--multi-volume}, @command{tar} does not report an
10529 error when it comes to the end of an archive volume (when reading), or
10530 the end of the media (when writing). Instead, it prompts you to load
10531 a new storage volume. If the archive is on a magnetic tape, you
10532 should change tapes when you see the prompt; if the archive is on a
10533 floppy disk, you should change disks; etc.
10534
10535 @table @option
10536 @item --multi-volume
10537 @itemx -M
10538 Creates a multi-volume archive, when used in conjunction with
10539 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
10540 archive, specify @option{--multi-volume} in conjunction with that
10541 operation.
10542 For example:
10543
10544 @smallexample
10545 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
10546 @end smallexample
10547 @end table
10548
10549 The method @command{tar} uses to detect end of tape is not perfect, and
10550 fails on some operating systems or on some devices. If @command{tar}
10551 cannot detect the end of the tape itself, you can use
10552 @option{--tape-length} option to inform it about the capacity of the
10553 tape:
10554
10555 @anchor{tape-length}
10556 @table @option
10557 @opindex tape-length
10558 @item --tape-length=@var{size}
10559 @itemx -L @var{size}
10560 Set maximum length of a volume. The @var{size} argument should then
10561 be the usable size of the tape in units of 1024 bytes. This option
10562 selects @option{--multi-volume} automatically. For example:
10563
10564 @smallexample
10565 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
10566 @end smallexample
10567 @end table
10568
10569 @anchor{change volume prompt}
10570 When @GNUTAR{} comes to the end of a storage media, it asks you to
10571 change the volume. The built-in prompt for POSIX locale
10572 is@footnote{If you run @GNUTAR{} under a different locale, the
10573 translation to the locale's language will be used.}:
10574
10575 @smallexample
10576 Prepare volume #@var{n} for `@var{archive}' and hit return:
10577 @end smallexample
10578
10579 @noindent
10580 where @var{n} is the ordinal number of the volume to be created and
10581 @var{archive} is archive file or device name.
10582
10583 When prompting for a new tape, @command{tar} accepts any of the following
10584 responses:
10585
10586 @table @kbd
10587 @item ?
10588 Request @command{tar} to explain possible responses
10589 @item q
10590 Request @command{tar} to exit immediately.
10591 @item n @var{file-name}
10592 Request @command{tar} to write the next volume on the file @var{file-name}.
10593 @item !
10594 Request @command{tar} to run a subshell. This option can be disabled
10595 by giving @option{--restrict} command line option to
10596 @command{tar}@footnote{@xref{--restrict}, for more information about
10597 this option}.
10598 @item y
10599 Request @command{tar} to begin writing the next volume.
10600 @end table
10601
10602 (You should only type @samp{y} after you have changed the tape;
10603 otherwise @command{tar} will write over the volume it just finished.)
10604
10605 @cindex Volume number file
10606 @cindex volno file
10607 @anchor{volno-file}
10608 @opindex volno-file
10609 The volume number used by @command{tar} in its tape-changing prompt
10610 can be changed; if you give the
10611 @option{--volno-file=@var{file-of-number}} option, then
10612 @var{file-of-number} should be an non-existing file to be created, or
10613 else, a file already containing a decimal number. That number will be
10614 used as the volume number of the first volume written. When
10615 @command{tar} is finished, it will rewrite the file with the
10616 now-current volume number. (This does not change the volume number
10617 written on a tape label, as per @ref{label}, it @emph{only} affects
10618 the number used in the prompt.)
10619
10620 @cindex End-of-archive info script
10621 @cindex Info script
10622 @anchor{info-script}
10623 @opindex info-script
10624 @opindex new-volume-script
10625 If you want more elaborate behavior than this, you can write a special
10626 @dfn{new volume script}, that will be responsible for changing the
10627 volume, and instruct @command{tar} to use it instead of its normal
10628 prompting procedure:
10629
10630 @table @option
10631 @item --info-script=@var{script-name}
10632 @itemx --new-volume-script=@var{script-name}
10633 @itemx -F @var{script-name}
10634 Specify the full name of the volume script to use. The script can be
10635 used to eject cassettes, or to broadcast messages such as
10636 @samp{Someone please come change my tape} when performing unattended
10637 backups.
10638 @end table
10639
10640 The @var{script-name} is executed without any command line
10641 arguments. It inherits @command{tar}'s shell environment.
10642 Additional data is passed to it via the following
10643 environment variables:
10644
10645 @table @env
10646 @vrindex TAR_VERSION, info script environment variable
10647 @item TAR_VERSION
10648 @GNUTAR{} version number.
10649
10650 @vrindex TAR_ARCHIVE, info script environment variable
10651 @item TAR_ARCHIVE
10652 The name of the archive @command{tar} is processing.
10653
10654 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
10655 @item TAR_BLOCKING_FACTOR
10656 Current blocking factor (@pxref{Blocking}.
10657
10658 @vrindex TAR_VOLUME, info script environment variable
10659 @item TAR_VOLUME
10660 Ordinal number of the volume @command{tar} is about to start.
10661
10662 @vrindex TAR_SUBCOMMAND, info script environment variable
10663 @item TAR_SUBCOMMAND
10664 A short option describing the operation @command{tar} is executing
10665 @xref{Operations}, for a complete list of subcommand options.
10666
10667 @vrindex TAR_FORMAT, info script environment variable
10668 @item TAR_FORMAT
10669 Format of the archive being processed. @xref{Formats}, for a complete
10670 list of archive format names.
10671
10672 @vrindex TAR_FD, info script environment variable
10673 @item TAR_FD
10674 File descriptor which can be used to communicate the new volume
10675 name to @command{tar}.
10676 @end table
10677
10678 The volume script can instruct @command{tar} to use new archive name,
10679 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
10680
10681 If the info script fails, @command{tar} exits; otherwise, it begins
10682 writing the next volume.
10683
10684 If you want @command{tar} to cycle through a series of files or tape
10685 drives, there are three approaches to choose from. First of all, you
10686 can give @command{tar} multiple @option{--file} options. In this case
10687 the specified files will be used, in sequence, as the successive
10688 volumes of the archive. Only when the first one in the sequence needs
10689 to be used again will @command{tar} prompt for a tape change (or run
10690 the info script). For example, suppose someone has two tape drives on
10691 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10692 @GNUTAR{} to switch to the second drive when it needs to write the
10693 second tape, and then back to the first tape, etc., just do either of:
10694
10695 @smallexample
10696 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10697 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10698 @end smallexample
10699
10700 The second method is to use the @samp{n} response to the tape-change
10701 prompt.
10702
10703 Finally, the most flexible approach is to use a volume script, that
10704 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
10705 following volume script will create a series of archive files, named
10706 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10707 archive being created (as given by @option{--file} option) and
10708 @var{vol} is the ordinal number of the archive being created:
10709
10710 @smallexample
10711 @group
10712 #! /bin/sh
10713 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10714
10715 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10716 case $TAR_SUBCOMMAND in
10717 -c) ;;
10718 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10719 ;;
10720 *) exit 1
10721 esac
10722
10723 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
10724 @end group
10725 @end smallexample
10726
10727 The same script can be used while listing, comparing or extracting
10728 from the created archive. For example:
10729
10730 @smallexample
10731 @group
10732 # @r{Create a multi-volume archive:}
10733 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10734 # @r{Extract from the created archive:}
10735 $ @kbd{tar -x -f archive.tar -F new-volume .}
10736 @end group
10737 @end smallexample
10738
10739 @noindent
10740 Notice, that the first command had to use @option{-L} option, since
10741 otherwise @GNUTAR{} will end up writing everything to file
10742 @file{archive.tar}.
10743
10744 You can read each individual volume of a multi-volume archive as if it
10745 were an archive by itself. For example, to list the contents of one
10746 volume, use @option{--list}, without @option{--multi-volume} specified.
10747 To extract an archive member from one volume (assuming it is described
10748 that volume), use @option{--extract}, again without
10749 @option{--multi-volume}.
10750
10751 If an archive member is split across volumes (i.e., its entry begins on
10752 one volume of the media and ends on another), you need to specify
10753 @option{--multi-volume} to extract it successfully. In this case, you
10754 should load the volume where the archive member starts, and use
10755 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10756 volumes as it needs them. @xref{extracting archives}, for more
10757 information about extracting archives.
10758
10759 Multi-volume archives can be modified like any other archive. To add
10760 files to a multi-volume archive, you need to only mount the last
10761 volume of the archive media (and new volumes, if needed). For all
10762 other operations, you need to use the entire archive.
10763
10764 If a multi-volume archive was labeled using
10765 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10766 created, @command{tar} will not automatically label volumes which are
10767 added later. To label subsequent volumes, specify
10768 @option{--label=@var{archive-label}} again in conjunction with the
10769 @option{--append}, @option{--update} or @option{--concatenate} operation.
10770
10771 Notice that multi-volume support is a GNU extension and the archives
10772 created in this mode should be read only using @GNUTAR{}. If you
10773 absolutely have to process such archives using a third-party @command{tar}
10774 implementation, read @ref{Split Recovery}.
10775
10776 @node Tape Files
10777 @subsection Tape Files
10778 @UNREVISED
10779
10780 To give the archive a name which will be recorded in it, use the
10781 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10782 option. This will write a special block identifying
10783 @var{volume-label} as the name of the archive to the front of the
10784 archive which will be displayed when the archive is listed with
10785 @option{--list}. If you are creating a multi-volume archive with
10786 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10787 volume label will have @samp{Volume @var{nnn}} appended to the name
10788 you give, where @var{nnn} is the number of the volume of the archive.
10789 (If you use the @option{--label=@var{volume-label}}) option when
10790 reading an archive, it checks to make sure the label on the tape
10791 matches the one you give. @xref{label}.
10792
10793 When @command{tar} writes an archive to tape, it creates a single
10794 tape file. If multiple archives are written to the same tape, one
10795 after the other, they each get written as separate tape files. When
10796 extracting, it is necessary to position the tape at the right place
10797 before running @command{tar}. To do this, use the @command{mt} command.
10798 For more information on the @command{mt} command and on the organization
10799 of tapes into a sequence of tape files, see @ref{mt}.
10800
10801 People seem to often do:
10802
10803 @smallexample
10804 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10805 @end smallexample
10806
10807 or such, for pushing a common date in all volumes or an archive set.
10808
10809 @node Tarcat
10810 @subsection Concatenate Volumes into a Single Archive
10811
10812 @pindex tarcat
10813 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10814 archive to a single @command{tar} archive. Simply concatenating all
10815 volumes into one will not work, since each volume carries an additional
10816 information at the beginning. @GNUTAR{} is shipped with the shell
10817 script @command{tarcat} designed for this purpose.
10818
10819 The script takes a list of files comprising a multi-volume archive
10820 and creates the resulting archive at the standard output. For example:
10821
10822 @smallexample
10823 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10824 @end smallexample
10825
10826 The script implements a simple heuristics to determine the format of
10827 the first volume file and to decide how to process the rest of the
10828 files. However, it makes no attempt to verify whether the files are
10829 given in order or even if they are valid @command{tar} archives.
10830 It uses @command{dd} and does not filter its standard error, so you
10831 will usually see lots of spurious messages.
10832
10833 @FIXME{The script is not installed. Should we install it?}
10834
10835 @node label
10836 @section Including a Label in the Archive
10837 @cindex Labeling an archive
10838 @cindex Labels on the archive media
10839 @cindex Labeling multi-volume archives
10840 @UNREVISED
10841
10842 @opindex label
10843 To avoid problems caused by misplaced paper labels on the archive
10844 media, you can include a @dfn{label} entry---an archive member which
10845 contains the name of the archive---in the archive itself. Use the
10846 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10847 option in conjunction with the @option{--create} operation to include
10848 a label entry in the archive as it is being created.
10849
10850 @table @option
10851 @item --label=@var{archive-label}
10852 @itemx -V @var{archive-label}
10853 Includes an @dfn{archive-label} at the beginning of the archive when
10854 the archive is being created, when used in conjunction with the
10855 @option{--create} operation. Checks to make sure the archive label
10856 matches the one specified (when used in conjunction with any other
10857 operation.
10858 @end table
10859
10860 If you create an archive using both
10861 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10862 and @option{--multi-volume} (@option{-M}), each volume of the archive
10863 will have an archive label of the form @samp{@var{archive-label}
10864 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10865 next, and so on. @xref{Using Multiple Tapes}, for information on
10866 creating multiple volume archives.
10867
10868 @cindex Volume label, listing
10869 @cindex Listing volume label
10870 The volume label will be displayed by @option{--list} along with
10871 the file contents. If verbose display is requested, it will also be
10872 explicitly marked as in the example below:
10873
10874 @smallexample
10875 @group
10876 $ @kbd{tar --verbose --list --file=iamanarchive}
10877 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10878 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10879 @end group
10880 @end smallexample
10881
10882 @opindex test-label
10883 @anchor{--test-label option}
10884 However, @option{--list} option will cause listing entire
10885 contents of the archive, which may be undesirable (for example, if the
10886 archive is stored on a tape). You can request checking only the volume
10887 by specifying @option{--test-label} option. This option reads only the
10888 first block of an archive, so it can be used with slow storage
10889 devices. For example:
10890
10891 @smallexample
10892 @group
10893 $ @kbd{tar --test-label --file=iamanarchive}
10894 iamalabel
10895 @end group
10896 @end smallexample
10897
10898 If @option{--test-label} is used with a single command line
10899 argument, @command{tar} compares the volume label with the
10900 argument. It exits with code 0 if the two strings match, and with code
10901 2 otherwise. In this case no output is displayed. For example:
10902
10903 @smallexample
10904 @group
10905 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10906 @result{} 0
10907 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10908 @result{} 1
10909 @end group
10910 @end smallexample
10911
10912 If you request any operation, other than @option{--create}, along
10913 with using @option{--label} option, @command{tar} will first check if
10914 the archive label matches the one specified and will refuse to proceed
10915 if it does not. Use this as a safety precaution to avoid accidentally
10916 overwriting existing archives. For example, if you wish to add files
10917 to @file{archive}, presumably labeled with string @samp{My volume},
10918 you will get:
10919
10920 @smallexample
10921 @group
10922 $ @kbd{tar -rf archive --label 'My volume' .}
10923 tar: Archive not labeled to match `My volume'
10924 @end group
10925 @end smallexample
10926
10927 @noindent
10928 in case its label does not match. This will work even if
10929 @file{archive} is not labeled at all.
10930
10931 Similarly, @command{tar} will refuse to list or extract the
10932 archive if its label doesn't match the @var{archive-label}
10933 specified. In those cases, @var{archive-label} argument is interpreted
10934 as a globbing-style pattern which must match the actual magnetic
10935 volume label. @xref{exclude}, for a precise description of how match
10936 is attempted@footnote{Previous versions of @command{tar} used full
10937 regular expression matching, or before that, only exact string
10938 matching, instead of wildcard matchers. We decided for the sake of
10939 simplicity to use a uniform matching device through
10940 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10941 the volume label matcher will also suffix @var{archive-label} by
10942 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10943 up. Since the volume numbering is automatically added in labels at
10944 creation time, it sounded logical to equally help the user taking care
10945 of it when the archive is being read.
10946
10947 The @option{--label} was once called @option{--volume}, but is not
10948 available under that name anymore.
10949
10950 You can also use @option{--label} to get a common information on
10951 all tapes of a series. For having this information different in each
10952 series created through a single script used on a regular basis, just
10953 manage to get some date string as part of the label. For example:
10954
10955 @smallexample
10956 @group
10957 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10958 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10959 --volume="Daily backup for `date +%Y-%m-%d`"}
10960 @end group
10961 @end smallexample
10962
10963 Also note that each label has its own date and time, which corresponds
10964 to when @GNUTAR{} initially attempted to write it,
10965 often soon after the operator launches @command{tar} or types the
10966 carriage return telling that the next tape is ready. Comparing date
10967 labels does give an idea of tape throughput only if the delays for
10968 rewinding tapes and the operator switching them were negligible, which
10969 is usually not the case.
10970
10971 @node verify
10972 @section Verifying Data as It is Stored
10973 @cindex Verifying a write operation
10974 @cindex Double-checking a write operation
10975
10976 @table @option
10977 @item -W
10978 @itemx --verify
10979 @opindex verify, short description
10980 Attempt to verify the archive after writing.
10981 @end table
10982
10983 This option causes @command{tar} to verify the archive after writing it.
10984 Each volume is checked after it is written, and any discrepancies
10985 are recorded on the standard error output.
10986
10987 Verification requires that the archive be on a back-space-able medium.
10988 This means pipes, some cartridge tape drives, and some other devices
10989 cannot be verified.
10990
10991 You can insure the accuracy of an archive by comparing files in the
10992 system with archive members. @command{tar} can compare an archive to the
10993 file system as the archive is being written, to verify a write
10994 operation, or can compare a previously written archive, to insure that
10995 it is up to date.
10996
10997 @xopindex{verify, using with @option{--create}}
10998 @xopindex{create, using with @option{--verify}}
10999 To check for discrepancies in an archive immediately after it is
11000 written, use the @option{--verify} (@option{-W}) option in conjunction with
11001 the @option{--create} operation. When this option is
11002 specified, @command{tar} checks archive members against their counterparts
11003 in the file system, and reports discrepancies on the standard error.
11004
11005 To verify an archive, you must be able to read it from before the end
11006 of the last written entry. This option is useful for detecting data
11007 errors on some tapes. Archives written to pipes, some cartridge tape
11008 drives, and some other devices cannot be verified.
11009
11010 One can explicitly compare an already made archive with the file
11011 system by using the @option{--compare} (@option{--diff}, @option{-d})
11012 option, instead of using the more automatic @option{--verify} option.
11013 @xref{compare}.
11014
11015 Note that these two options have a slightly different intent. The
11016 @option{--compare} option checks how identical are the logical contents of some
11017 archive with what is on your disks, while the @option{--verify} option is
11018 really for checking if the physical contents agree and if the recording
11019 media itself is of dependable quality. So, for the @option{--verify}
11020 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11021 the archive, while it lets the speed optimization undisturbed for the
11022 @option{--compare} option. If you nevertheless use @option{--compare} for
11023 media verification, you may have to defeat the in-memory cache yourself,
11024 maybe by opening and reclosing the door latch of your recording unit,
11025 forcing some doubt in your operating system about the fact this is really
11026 the same volume as the one just written or read.
11027
11028 The @option{--verify} option would not be necessary if drivers were indeed
11029 able to detect dependably all write failures. This sometimes require many
11030 magnetic heads, some able to read after the writes occurred. One would
11031 not say that drivers unable to detect all cases are necessarily flawed,
11032 as long as programming is concerned.
11033
11034 The @option{--verify} (@option{-W}) option will not work in
11035 conjunction with the @option{--multi-volume} (@option{-M}) option or
11036 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11037 and @option{--delete} operations. @xref{Operations}, for more
11038 information on these operations.
11039
11040 Also, since @command{tar} normally strips leading @samp{/} from file
11041 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11042 /tmp/foo.tar /etc} will work as desired only if the working directory is
11043 @file{/}, as @command{tar} uses the archive's relative member names
11044 (e.g., @file{etc/motd}) when verifying the archive.
11045
11046 @node Write Protection
11047 @section Write Protection
11048
11049 Almost all tapes and diskettes, and in a few rare cases, even disks can
11050 be @dfn{write protected}, to protect data on them from being changed.
11051 Once an archive is written, you should write protect the media to prevent
11052 the archive from being accidentally overwritten or deleted. (This will
11053 protect the archive from being changed with a tape or floppy drive---it
11054 will not protect it from magnet fields or other physical hazards).
11055
11056 The write protection device itself is usually an integral part of the
11057 physical media, and can be a two position (write enabled/write
11058 disabled) switch, a notch which can be popped out or covered, a ring
11059 which can be removed from the center of a tape reel, or some other
11060 changeable feature.
11061
11062 @node Changes
11063 @appendix Changes
11064
11065 This appendix lists some important user-visible changes between
11066 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
11067 version of this document is available at
11068 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
11069 @GNUTAR{} documentation page}.
11070
11071 @table @asis
11072 @item Use of globbing patterns when listing and extracting.
11073
11074 Previous versions of GNU tar assumed shell-style globbing when
11075 extracting from or listing an archive. For example:
11076
11077 @smallexample
11078 $ @kbd{tar xf foo.tar '*.c'}
11079 @end smallexample
11080
11081 would extract all files whose names end in @samp{.c}. This behavior
11082 was not documented and was incompatible with traditional tar
11083 implementations. Therefore, starting from version 1.15.91, GNU tar
11084 no longer uses globbing by default. For example, the above invocation
11085 is now interpreted as a request to extract from the archive the file
11086 named @file{*.c}.
11087
11088 To facilitate transition to the new behavior for those users who got
11089 used to the previous incorrect one, @command{tar} will print a warning
11090 if it finds out that a requested member was not found in the archive
11091 and its name looks like a globbing pattern. For example:
11092
11093 @smallexample
11094 $ @kbd{tar xf foo.tar '*.c'}
11095 tar: Pattern matching characters used in file names. Please,
11096 tar: use --wildcards to enable pattern matching, or --no-wildcards to
11097 tar: suppress this warning.
11098 tar: *.c: Not found in archive
11099 tar: Error exit delayed from previous errors
11100 @end smallexample
11101
11102 To treat member names as globbing patterns, use --wildcards option.
11103 If you want to tar to mimic the behavior of versions prior to 1.15.91,
11104 add this option to your @env{TAR_OPTIONS} variable.
11105
11106 @xref{wildcards}, for the detailed discussion of the use of globbing
11107 patterns by @GNUTAR{}.
11108
11109 @item Use of short option @option{-o}.
11110
11111 Earlier versions of @GNUTAR{} understood @option{-o} command line
11112 option as a synonym for @option{--old-archive}.
11113
11114 @GNUTAR{} starting from version 1.13.90 understands this option as
11115 a synonym for @option{--no-same-owner}. This is compatible with
11116 UNIX98 @command{tar} implementations.
11117
11118 However, to facilitate transition, @option{-o} option retains its
11119 old semantics when it is used with one of archive-creation commands.
11120 Users are encouraged to use @option{--format=oldgnu} instead.
11121
11122 It is especially important, since versions of @acronym{GNU} Automake
11123 up to and including 1.8.4 invoke tar with this option to produce
11124 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
11125 of this issue and its implications.
11126
11127 @FIXME{Change the first argument to tar-formats when the new Automake is
11128 out. The proposition to add @anchor{} to the appropriate place of its
11129 docs was accepted by Automake people --Sergey 2006-05-25}.
11130 @xref{Options, tar-v7, Changing Automake's Behavior,
11131 automake, GNU Automake}, for a description on how to use various
11132 archive formats with @command{automake}.
11133
11134 Future versions of @GNUTAR{} will understand @option{-o} only as a
11135 synonym for @option{--no-same-owner}.
11136
11137 @item Use of short option @option{-l}
11138
11139 Earlier versions of @GNUTAR{} understood @option{-l} option as a
11140 synonym for @option{--one-file-system}. Since such usage contradicted
11141 to UNIX98 specification and harmed compatibility with other
11142 implementation, it was declared deprecated in version 1.14. However,
11143 to facilitate transition to its new semantics, it was supported by
11144 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
11145 variant of @option{--check-links} was introduced in version 1.15.91.
11146
11147 @item Use of options @option{--portability} and @option{--old-archive}
11148
11149 These options are deprecated. Please use @option{--format=v7} instead.
11150
11151 @item Use of option @option{--posix}
11152
11153 This option is deprecated. Please use @option{--format=posix} instead.
11154 @end table
11155
11156 @node Configuring Help Summary
11157 @appendix Configuring Help Summary
11158
11159 Running @kbd{tar --help} displays the short @command{tar} option
11160 summary (@pxref{help}). This summary is organized by @dfn{groups} of
11161 semantically close options. The options within each group are printed
11162 in the following order: a short option, eventually followed by a list
11163 of corresponding long option names, followed by a short description of
11164 the option. For example, here is an excerpt from the actual @kbd{tar
11165 --help} output:
11166
11167 @verbatim
11168 Main operation mode:
11169
11170 -A, --catenate, --concatenate append tar files to an archive
11171 -c, --create create a new archive
11172 -d, --diff, --compare find differences between archive and
11173 file system
11174 --delete delete from the archive
11175 @end verbatim
11176
11177 @vrindex ARGP_HELP_FMT, environment variable
11178 The exact visual representation of the help output is configurable via
11179 @env{ARGP_HELP_FMT} environment variable. The value of this variable
11180 is a comma-separated list of @dfn{format variable} assignments. There
11181 are two kinds of format variables. An @dfn{offset variable} keeps the
11182 offset of some part of help output text from the leftmost column on
11183 the screen. A @dfn{boolean} variable is a flag that toggles some
11184 output feature on or off. Depending on the type of the corresponding
11185 variable, there are two kinds of assignments:
11186
11187 @table @asis
11188 @item Offset assignment
11189
11190 The assignment to an offset variable has the following syntax:
11191
11192 @smallexample
11193 @var{variable}=@var{value}
11194 @end smallexample
11195
11196 @noindent
11197 where @var{variable} is the variable name, and @var{value} is a
11198 numeric value to be assigned to the variable.
11199
11200 @item Boolean assignment
11201
11202 To assign @code{true} value to a variable, simply put this variable name. To
11203 assign @code{false} value, prefix the variable name with @samp{no-}. For
11204 example:
11205
11206 @smallexample
11207 @group
11208 # Assign @code{true} value:
11209 dup-args
11210 # Assign @code{false} value:
11211 no-dup-args
11212 @end group
11213 @end smallexample
11214 @end table
11215
11216 Following variables are declared:
11217
11218 @deftypevr {Help Output} boolean dup-args
11219 If true, arguments for an option are shown with both short and long
11220 options, even when a given option has both forms, for example:
11221
11222 @smallexample
11223 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
11224 @end smallexample
11225
11226 If false, then if an option has both short and long forms, the
11227 argument is only shown with the long one, for example:
11228
11229 @smallexample
11230 -f, --file=ARCHIVE use archive file or device ARCHIVE
11231 @end smallexample
11232
11233 @noindent
11234 and a message indicating that the argument is applicable to both
11235 forms is printed below the options. This message can be disabled
11236 using @code{dup-args-note} (see below).
11237
11238 The default is false.
11239 @end deftypevr
11240
11241 @deftypevr {Help Output} boolean dup-args-note
11242 If this variable is true, which is the default, the following notice
11243 is displayed at the end of the help output:
11244
11245 @quotation
11246 Mandatory or optional arguments to long options are also mandatory or
11247 optional for any corresponding short options.
11248 @end quotation
11249
11250 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
11251 variables @code{dup-args} or @code{dup-args-note} should be set.
11252 @end deftypevr
11253
11254 @deftypevr {Help Output} offset short-opt-col
11255 Column in which short options start. Default is 2.
11256
11257 @smallexample
11258 @group
11259 $ @kbd{tar --help|grep ARCHIVE}
11260 -f, --file=ARCHIVE use archive file or device ARCHIVE
11261 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
11262 -f, --file=ARCHIVE use archive file or device ARCHIVE
11263 @end group
11264 @end smallexample
11265 @end deftypevr
11266
11267 @deftypevr {Help Output} offset long-opt-col
11268 Column in which long options start. Default is 6. For example:
11269
11270 @smallexample
11271 @group
11272 $ @kbd{tar --help|grep ARCHIVE}
11273 -f, --file=ARCHIVE use archive file or device ARCHIVE
11274 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
11275 -f, --file=ARCHIVE use archive file or device ARCHIVE
11276 @end group
11277 @end smallexample
11278 @end deftypevr
11279
11280 @deftypevr {Help Output} offset doc-opt-col
11281 Column in which @dfn{doc options} start. A doc option isn't actually
11282 an option, but rather an arbitrary piece of documentation that is
11283 displayed in much the same manner as the options. For example, in
11284 the description of @option{--format} option:
11285
11286 @smallexample
11287 @group
11288 -H, --format=FORMAT create archive of the given format.
11289
11290 FORMAT is one of the following:
11291
11292 gnu GNU tar 1.13.x format
11293 oldgnu GNU format as per tar <= 1.12
11294 pax POSIX 1003.1-2001 (pax) format
11295 posix same as pax
11296 ustar POSIX 1003.1-1988 (ustar) format
11297 v7 old V7 tar format
11298 @end group
11299 @end smallexample
11300
11301 @noindent
11302 the format names are doc options. Thus, if you set
11303 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
11304 will look as follows:
11305
11306 @smallexample
11307 @group
11308 -H, --format=FORMAT create archive of the given format.
11309
11310 FORMAT is one of the following:
11311
11312 gnu GNU tar 1.13.x format
11313 oldgnu GNU format as per tar <= 1.12
11314 pax POSIX 1003.1-2001 (pax) format
11315 posix same as pax
11316 ustar POSIX 1003.1-1988 (ustar) format
11317 v7 old V7 tar format
11318 @end group
11319 @end smallexample
11320 @end deftypevr
11321
11322 @deftypevr {Help Output} offset opt-doc-col
11323 Column in which option description starts. Default is 29.
11324
11325 @smallexample
11326 @group
11327 $ @kbd{tar --help|grep ARCHIVE}
11328 -f, --file=ARCHIVE use archive file or device ARCHIVE
11329 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
11330 -f, --file=ARCHIVE use archive file or device ARCHIVE
11331 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
11332 -f, --file=ARCHIVE
11333 use archive file or device ARCHIVE
11334 @end group
11335 @end smallexample
11336
11337 @noindent
11338 Notice, that the description starts on a separate line if
11339 @code{opt-doc-col} value is too small.
11340 @end deftypevr
11341
11342 @deftypevr {Help Output} offset header-col
11343 Column in which @dfn{group headers} are printed. A group header is a
11344 descriptive text preceding an option group. For example, in the
11345 following text:
11346
11347 @verbatim
11348 Main operation mode:
11349
11350 -A, --catenate, --concatenate append tar files to
11351 an archive
11352 -c, --create create a new archive
11353 @end verbatim
11354 @noindent
11355 @samp{Main operation mode:} is the group header.
11356
11357 The default value is 1.
11358 @end deftypevr
11359
11360 @deftypevr {Help Output} offset usage-indent
11361 Indentation of wrapped usage lines. Affects @option{--usage}
11362 output. Default is 12.
11363 @end deftypevr
11364
11365 @deftypevr {Help Output} offset rmargin
11366 Right margin of the text output. Used for wrapping.
11367 @end deftypevr
11368
11369 @node Fixing Snapshot Files
11370 @appendix Fixing Snapshot Files
11371 @include tar-snapshot-edit.texi
11372
11373 @node Tar Internals
11374 @appendix Tar Internals
11375 @include intern.texi
11376
11377 @node Genfile
11378 @appendix Genfile
11379 @include genfile.texi
11380
11381 @node Free Software Needs Free Documentation
11382 @appendix Free Software Needs Free Documentation
11383 @include freemanuals.texi
11384
11385 @node Copying This Manual
11386 @appendix Copying This Manual
11387
11388 @menu
11389 * GNU Free Documentation License:: License for copying this manual
11390 @end menu
11391
11392 @include fdl.texi
11393
11394 @node Index of Command Line Options
11395 @appendix Index of Command Line Options
11396
11397 This appendix contains an index of all @GNUTAR{} long command line
11398 options. The options are listed without the preceding double-dash.
11399 For a cross-reference of short command line options, @ref{Short Option Summary}.
11400
11401 @printindex op
11402
11403 @node Index
11404 @appendix Index
11405
11406 @printindex cp
11407
11408 @summarycontents
11409 @contents
11410 @bye
11411
11412 @c Local variables:
11413 @c texinfo-column-for-description: 32
11414 @c End:
This page took 0.544952 seconds and 5 git commands to generate.