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