]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Update master menu
[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 @include rendition.texi
14 @include value.texi
15
16 @c Put everything in one index (arbitrarily chosen to be the concept index).
17 @syncodeindex fn cp
18 @syncodeindex ky cp
19 @syncodeindex pg cp
20 @syncodeindex vr cp
21
22 @defindex op
23
24 @copying
25
26 This manual is for @acronym{GNU} @command{tar} (version
27 @value{VERSION}, @value{UPDATED}), which creates and extracts files
28 from archives.
29
30 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
31 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
32
33 @quotation
34 Permission is granted to copy, distribute and/or modify this document
35 under the terms of the GNU Free Documentation License, Version 1.1 or
36 any later version published by the Free Software Foundation; with no
37 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
38 and with the Back-Cover Texts as in (a) below. A copy of the license
39 is included in the section entitled "GNU Free Documentation License".
40
41 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
42 this GNU Manual. Buying copies from GNU Press supports the FSF in
43 developing GNU and promoting software freedom.''
44 @end quotation
45 @end copying
46
47 @dircategory Archiving
48 @direntry
49 * Tar: (tar). Making tape (or disk) archives.
50 @end direntry
51
52 @dircategory Individual utilities
53 @direntry
54 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
55 @end direntry
56
57 @shorttitlepage @acronym{GNU} @command{tar}
58
59 @titlepage
60 @title @acronym{GNU} tar: an archiver tool
61 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
62 @author John Gilmore, Jay Fenlason et al.
63
64 @page
65 @vskip 0pt plus 1filll
66 @insertcopying
67 @end titlepage
68
69 @ifnottex
70 @node Top
71 @top @acronym{GNU} tar: an archiver tool
72
73 @insertcopying
74
75 @cindex file archival
76 @cindex archiving files
77
78 The first part of this master menu lists the major nodes in this Info
79 document. The rest of the menu lists all the lower level nodes.
80 @end ifnottex
81
82 @c The master menu goes here.
83 @c
84 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
85 @c loaded and run texinfo-master-menu.
86 @c To update it from the command line, run
87 @c
88 @c make master-menu
89
90 @menu
91 * Introduction::
92 * Tutorial::
93 * tar invocation::
94 * operations::
95 * Backups::
96 * Choosing::
97 * Date input formats::
98 * Formats::
99 * Media::
100
101 Appendices
102
103 * Changes::
104 * Configuring Help Summary::
105 * Genfile::
106 * Tar Internals::
107 * Free Software Needs Free Documentation::
108 * Copying This Manual::
109 * Index of Command Line Options::
110 * Index::
111
112 @detailmenu
113 --- The Detailed Node Listing ---
114
115 Introduction
116
117 * Book Contents:: What this Book Contains
118 * Definitions:: Some Definitions
119 * What tar Does:: What @command{tar} Does
120 * Naming tar Archives:: How @command{tar} Archives are Named
121 * Authors:: @GNUTAR{} Authors
122 * Reports:: Reporting bugs or suggestions
123
124 Tutorial Introduction to @command{tar}
125
126 * assumptions::
127 * stylistic conventions::
128 * basic tar options:: Basic @command{tar} Operations and Options
129 * frequent operations::
130 * Two Frequent Options::
131 * create:: How to Create Archives
132 * list:: How to List Archives
133 * extract:: How to Extract Members from an Archive
134 * going further::
135
136 Two Frequently Used Options
137
138 * file tutorial::
139 * verbose tutorial::
140 * help tutorial::
141
142 How to Create Archives
143
144 * prepare for examples::
145 * Creating the archive::
146 * create verbose::
147 * short create::
148 * create dir::
149
150 How to List Archives
151
152 * list dir::
153
154 How to Extract Members from an Archive
155
156 * extracting archives::
157 * extracting files::
158 * extract dir::
159 * extracting untrusted archives::
160 * failing commands::
161
162 Invoking @GNUTAR{}
163
164 * Synopsis::
165 * using tar options::
166 * Styles::
167 * All Options::
168 * help::
169 * defaults::
170 * verbose::
171 * interactive::
172
173 The Three Option Styles
174
175 * Mnemonic Options:: Mnemonic Option Style
176 * Short Options:: Short Option Style
177 * Old Options:: Old Option Style
178 * Mixing:: Mixing Option Styles
179
180 All @command{tar} Options
181
182 * Operation Summary::
183 * Option Summary::
184 * Short Option Summary::
185
186 @GNUTAR{} Operations
187
188 * Basic tar::
189 * Advanced tar::
190 * create options::
191 * extract options::
192 * backup::
193 * Applications::
194 * looking ahead::
195
196 Advanced @GNUTAR{} Operations
197
198 * Operations::
199 * append::
200 * update::
201 * concatenate::
202 * delete::
203 * compare::
204
205 How to Add Files to Existing Archives: @option{--append}
206
207 * appending files:: Appending Files to an Archive
208 * multiple::
209
210 Updating an Archive
211
212 * how to update::
213
214 Options Used by @option{--create}
215
216 * Ignore Failed Read::
217
218 Options Used by @option{--extract}
219
220 * Reading:: Options to Help Read Archives
221 * Writing:: Changing How @command{tar} Writes Files
222 * Scarce:: Coping with Scarce Resources
223
224 Options to Help Read Archives
225
226 * read full records::
227 * Ignore Zeros::
228
229 Changing How @command{tar} Writes Files
230
231 * Dealing with Old Files::
232 * Overwrite Old Files::
233 * Keep Old Files::
234 * Keep Newer Files::
235 * Unlink First::
236 * Recursive Unlink::
237 * Data Modification Times::
238 * Setting Access Permissions::
239 * Directory Modification Times and Permissions::
240 * Writing to Standard Output::
241 * Writing to an External Program::
242 * remove files::
243
244 Coping with Scarce Resources
245
246 * Starting File::
247 * Same Order::
248
249 Performing Backups and Restoring Files
250
251 * Full Dumps:: Using @command{tar} to Perform Full Dumps
252 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
253 * Backup Levels:: Levels of Backups
254 * Backup Parameters:: Setting Parameters for Backups and Restoration
255 * Scripted Backups:: Using the Backup Scripts
256 * Scripted Restoration:: Using the Restore Script
257
258 Setting Parameters for Backups and Restoration
259
260 * General-Purpose Variables::
261 * Magnetic Tape Control::
262 * User Hooks::
263 * backup-specs example:: An Example Text of @file{Backup-specs}
264
265 Choosing Files and Names for @command{tar}
266
267 * file:: Choosing the Archive's Name
268 * Selecting Archive Members::
269 * files:: Reading Names from a File
270 * exclude:: Excluding Some Files
271 * wildcards:: Wildcards Patterns and Matching
272 * quoting styles:: Ways of Quoting Special Characters in Names
273 * transform:: Modifying File and Member Names
274 * after:: Operating Only on New Files
275 * recurse:: Descending into Directories
276 * one:: Crossing File System Boundaries
277
278 Reading Names from a File
279
280 * nul::
281
282 Excluding Some Files
283
284 * problems with exclude::
285
286 Wildcards Patterns and Matching
287
288 * controlling pattern-matching::
289
290 Crossing File System Boundaries
291
292 * directory:: Changing Directory
293 * absolute:: Absolute File Names
294
295 Date input formats
296
297 * General date syntax:: Common rules.
298 * Calendar date items:: 19 Dec 1994.
299 * Time of day items:: 9:20pm.
300 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
301 * Day of week items:: Monday and others.
302 * Relative items in date strings:: next tuesday, 2 years ago.
303 * Pure numbers in date strings:: 19931219, 1440.
304 * Seconds since the Epoch:: @@1078100502.
305 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
306 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
307
308 Controlling the Archive Format
309
310 * Portability:: Making @command{tar} Archives More Portable
311 * Compression:: Using Less Space through Compression
312 * Attributes:: Handling File Attributes
313 * cpio:: Comparison of @command{tar} and @command{cpio}
314
315 Making @command{tar} Archives More Portable
316
317 * Portable Names:: Portable Names
318 * dereference:: Symbolic Links
319 * old:: Old V7 Archives
320 * ustar:: Ustar Archives
321 * gnu:: GNU and old GNU format archives.
322 * posix:: @acronym{POSIX} archives
323 * Checksumming:: Checksumming Problems
324 * Large or Negative Values:: Large files, negative time stamps, etc.
325
326 @GNUTAR{} and @acronym{POSIX} @command{tar}
327
328 * PAX keywords:: Controlling Extended Header Keywords.
329
330 Using Less Space through Compression
331
332 * gzip:: Creating and Reading Compressed Archives
333 * sparse:: Archiving Sparse Files
334
335 Tapes and Other Archive Media
336
337 * Device:: Device selection and switching
338 * Remote Tape Server::
339 * Common Problems and Solutions::
340 * Blocking:: Blocking
341 * Many:: Many archives on one tape
342 * Using Multiple Tapes:: Using Multiple Tapes
343 * label:: Including a Label in the Archive
344 * verify::
345 * Write Protection::
346
347 Blocking
348
349 * Format Variations:: Format Variations
350 * Blocking Factor:: The Blocking Factor of an Archive
351
352 Many Archives on One Tape
353
354 * Tape Positioning:: Tape Positions and Tape Marks
355 * mt:: The @command{mt} Utility
356
357 Using Multiple Tapes
358
359 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
360 * Tape Files:: Tape Files
361 * Tarcat:: Concatenate Volumes into a Single Archive
362
363
364 Genfile
365
366 * Generate Mode:: File Generation Mode.
367 * Status Mode:: File Status Mode.
368 * Exec Mode:: Synchronous Execution mode.
369
370 Tar Internals
371
372 * Standard:: Basic Tar Format
373 * Extensions:: @acronym{GNU} Extensions to the Archive Format
374 * Snapshot Files::
375 * Dumpdir::
376
377 Copying This Manual
378
379 * GNU Free Documentation License:: License for copying this manual
380
381 @end detailmenu
382 @end menu
383
384 @node Introduction
385 @chapter Introduction
386
387 @GNUTAR{} creates
388 and manipulates @dfn{archives} which are actually collections of
389 many other files; the program provides users with an organized and
390 systematic method for controlling a large amount of data.
391 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
392 archives need not (and these days, typically do not) reside on tapes.
393
394 @menu
395 * Book Contents:: What this Book Contains
396 * Definitions:: Some Definitions
397 * What tar Does:: What @command{tar} Does
398 * Naming tar Archives:: How @command{tar} Archives are Named
399 * Authors:: @GNUTAR{} Authors
400 * Reports:: Reporting bugs or suggestions
401 @end menu
402
403 @node Book Contents
404 @section What this Book Contains
405
406 The first part of this chapter introduces you to various terms that will
407 recur throughout the book. It also tells you who has worked on @GNUTAR{}
408 and its documentation, and where you should send bug reports
409 or comments.
410
411 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
412 gentle introduction for people who are new to using @command{tar}. It is
413 meant to be self contained, not requiring any reading from subsequent
414 chapters to make sense. It moves from topic to topic in a logical,
415 progressive order, building on information already explained.
416
417 Although the tutorial is paced and structured to allow beginners to
418 learn how to use @command{tar}, it is not intended solely for beginners.
419 The tutorial explains how to use the three most frequently used
420 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
421 two frequently used options (@samp{file} and @samp{verbose}). The other
422 chapters do not refer to the tutorial frequently; however, if a section
423 discusses something which is a complex variant of a basic concept, there
424 may be a cross reference to that basic concept. (The entire book,
425 including the tutorial, assumes that the reader understands some basic
426 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
427
428 The third chapter presents the remaining five operations, and
429 information about using @command{tar} options and option syntax.
430
431 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
432 than the reality. should think about whether this makes sense to say
433 here, or not.} The other chapters are meant to be used as a
434 reference. Each chapter presents everything that needs to be said
435 about a specific topic.
436
437 One of the chapters (@pxref{Date input formats}) exists in its
438 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
439 In addition, one section of this manual (@pxref{Standard}) contains a
440 big quote which is taken directly from @command{tar} sources.
441
442 In general, we give both long and short (abbreviated) option names
443 at least once in each section where the relevant option is covered, so
444 that novice readers will become familiar with both styles. (A few
445 options have no short versions, and the relevant sections will
446 indicate this.)
447
448 @node Definitions
449 @section Some Definitions
450
451 @cindex archive
452 @cindex tar archive
453 The @command{tar} program is used to create and manipulate @command{tar}
454 archives. An @dfn{archive} is a single file which contains the contents
455 of many files, while still identifying the names of the files, their
456 owner(s), and so forth. (In addition, archives record access
457 permissions, user and group, size in bytes, and data modification time.
458 Some archives also record the file names in each archived directory, as
459 well as other file and directory information.) You can use @command{tar}
460 to @dfn{create} a new archive in a specified directory.
461
462 @cindex member
463 @cindex archive member
464 @cindex file name
465 @cindex member name
466 The files inside an archive are called @dfn{members}. Within this
467 manual, we use the term @dfn{file} to refer only to files accessible in
468 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
469 @dfn{member} to refer only to the members of an archive. Similarly, a
470 @dfn{file name} is the name of a file, as it resides in the file system,
471 and a @dfn{member name} is the name of an archive member within the
472 archive.
473
474 @cindex extraction
475 @cindex unpacking
476 The term @dfn{extraction} refers to the process of copying an archive
477 member (or multiple members) into a file in the file system. Extracting
478 all the members of an archive is often called @dfn{extracting the
479 archive}. The term @dfn{unpack} can also be used to refer to the
480 extraction of many or all the members of an archive. Extracting an
481 archive does not destroy the archive's structure, just as creating an
482 archive does not destroy the copies of the files that exist outside of
483 the archive. You may also @dfn{list} the members in a given archive
484 (this is often thought of as ``printing'' them to the standard output,
485 or the command line), or @dfn{append} members to a pre-existing archive.
486 All of these operations can be performed using @command{tar}.
487
488 @node What tar Does
489 @section What @command{tar} Does
490
491 @cindex tar
492 The @command{tar} program provides the ability to create @command{tar}
493 archives, as well as various other kinds of manipulation. For example,
494 you can use @command{tar} on previously created archives to extract files,
495 to store additional files, or to update or list files which were already
496 stored.
497
498 Initially, @command{tar} archives were used to store files conveniently on
499 magnetic tape. The name @command{tar} comes from this use; it stands for
500 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
501 direct its output to available devices, files, or other programs (using
502 pipes). @command{tar} may even access remote devices or files (as archives).
503
504 You can use @command{tar} archives in many ways. We want to stress a few
505 of them: storage, backup, and transportation.
506
507 @FIXME{the following table entries need a bit of work..}
508 @table @asis
509 @item Storage
510 Often, @command{tar} archives are used to store related files for
511 convenient file transfer over a network. For example, the
512 @acronym{GNU} Project distributes its software bundled into
513 @command{tar} archives, so that all the files relating to a particular
514 program (or set of related programs) can be transferred as a single
515 unit.
516
517 A magnetic tape can store several files in sequence. However, the tape
518 has no names for these files; it only knows their relative position on
519 the tape. One way to store several files on one tape and retain their
520 names is by creating a @command{tar} archive. Even when the basic transfer
521 mechanism can keep track of names, as FTP can, the nuisance of handling
522 multiple files, directories, and multiple links makes @command{tar}
523 archives useful.
524
525 Archive files are also used for long-term storage. You can think of
526 this as transportation from the present into the future. (It is a
527 science-fiction idiom that you can move through time as well as in
528 space; the idea here is that @command{tar} can be used to move archives in
529 all dimensions, even time!)
530
531 @item Backup
532 Because the archive created by @command{tar} is capable of preserving
533 file information and directory structure, @command{tar} is commonly
534 used for performing full and incremental backups of disks. A backup
535 puts a collection of files (possibly pertaining to many users and
536 projects) together on a disk or a tape. This guards against
537 accidental destruction of the information in those files.
538 @GNUTAR{} has special features that allow it to be
539 used to make incremental and full dumps of all the files in a
540 file system.
541
542 @item Transportation
543 You can create an archive on one system, transfer it to another system,
544 and extract the contents there. This allows you to transport a group of
545 files from one system to another.
546 @end table
547
548 @node Naming tar Archives
549 @section How @command{tar} Archives are Named
550
551 Conventionally, @command{tar} archives are given names ending with
552 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
553 but this manual follows that convention in order to accustom readers to
554 it and to make examples more clear.
555
556 @cindex tar file
557 @cindex entry
558 @cindex tar entry
559 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
560 archive members as ``files'' or ``entries''. For people familiar with
561 the operation of @command{tar}, this causes no difficulty. However, in
562 this manual, we consistently refer to ``archives'' and ``archive
563 members'' to make learning to use @command{tar} easier for novice users.
564
565 @node Authors
566 @section @GNUTAR{} Authors
567
568 @GNUTAR{} was originally written by John Gilmore,
569 and modified by many people. The @acronym{GNU} enhancements were
570 written by Jay Fenlason, then Joy Kendall, and the whole package has
571 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
572 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
573 numerous and kind users.
574
575 We wish to stress that @command{tar} is a collective work, and owes much to
576 all those people who reported problems, offered solutions and other
577 insights, or shared their thoughts and suggestions. An impressive, yet
578 partial list of those contributors can be found in the @file{THANKS}
579 file from the @GNUTAR{} distribution.
580
581 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
582 sure i want to spell out the history in this detail, at least not for
583 the printed book. i'm just not sure it needs to be said this way.
584 i'll think about it.}
585
586 @FIXME{History is more important, and surely more interesting, than
587 actual names. Quoting names without history would be meaningless. FP}
588
589 Jay Fenlason put together a draft of a @GNUTAR{}
590 manual, borrowing notes from the original man page from John Gilmore.
591 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
592 Gorin worked on a tutorial and manual for @GNUTAR{}.
593 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
594 taking information from all these sources and merging them. Melissa
595 Weisshaus finally edited and redesigned the book to create version
596 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
597 by the current maintainer, Sergey Poznyakoff.
598
599 For version 1.12, Daniel Hagerty contributed a great deal of technical
600 consulting. In particular, he is the primary author of @ref{Backups}.
601
602 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
603 (see @url{http://savannah.gnu.org/projects/tar}), and
604 active development and maintenance work has started
605 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
606 Poznyakoff and Jeff Bailey.
607
608 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
609
610 @node Reports
611 @section Reporting bugs or suggestions
612
613 @cindex bug reports
614 @cindex reporting bugs
615 If you find problems or have suggestions about this program or manual,
616 please report them to @file{bug-tar@@gnu.org}.
617
618 When reporting a bug, please be sure to include as much detail as
619 possible, in order to reproduce it. @FIXME{Be more specific, I'd
620 like to make this node as detailed as 'Bug reporting' node in Emacs
621 manual}.
622
623 @node Tutorial
624 @chapter Tutorial Introduction to @command{tar}
625
626 This chapter guides you through some basic examples of three @command{tar}
627 operations: @option{--create}, @option{--list}, and @option{--extract}. If
628 you already know how to use some other version of @command{tar}, then you
629 may not need to read this chapter. This chapter omits most complicated
630 details about how @command{tar} works.
631
632 @menu
633 * assumptions::
634 * stylistic conventions::
635 * basic tar options:: Basic @command{tar} Operations and Options
636 * frequent operations::
637 * Two Frequent Options::
638 * create:: How to Create Archives
639 * list:: How to List Archives
640 * extract:: How to Extract Members from an Archive
641 * going further::
642 @end menu
643
644 @node assumptions
645 @section Assumptions this Tutorial Makes
646
647 This chapter is paced to allow beginners to learn about @command{tar}
648 slowly. At the same time, we will try to cover all the basic aspects of
649 these three operations. In order to accomplish both of these tasks, we
650 have made certain assumptions about your knowledge before reading this
651 manual, and the hardware you will be using:
652
653 @itemize @bullet
654 @item
655 Before you start to work through this tutorial, you should understand
656 what the terms ``archive'' and ``archive member'' mean
657 (@pxref{Definitions}). In addition, you should understand something
658 about how Unix-type operating systems work, and you should know how to
659 use some basic utilities. For example, you should know how to create,
660 list, copy, rename, edit, and delete files and directories; how to
661 change between directories; and how to figure out where you are in the
662 file system. You should have some basic understanding of directory
663 structure and how files are named according to which directory they are
664 in. You should understand concepts such as standard output and standard
665 input, what various definitions of the term ``argument'' mean, and the
666 differences between relative and absolute path names. @FIXME{and what
667 else?}
668
669 @item
670 This manual assumes that you are working from your own home directory
671 (unless we state otherwise). In this tutorial, you will create a
672 directory to practice @command{tar} commands in. When we show path names,
673 we will assume that those paths are relative to your home directory.
674 For example, my home directory path is @file{/home/fsf/melissa}. All of
675 my examples are in a subdirectory of the directory named by that path
676 name; the subdirectory is called @file{practice}.
677
678 @item
679 In general, we show examples of archives which exist on (or can be
680 written to, or worked with from) a directory on a hard disk. In most
681 cases, you could write those archives to, or work with them on any other
682 device, such as a tape drive. However, some of the later examples in
683 the tutorial and next chapter will not work on tape drives.
684 Additionally, working with tapes is much more complicated than working
685 with hard disks. For these reasons, the tutorial does not cover working
686 with tape drives. @xref{Media}, for complete information on using
687 @command{tar} archives with tape drives.
688
689 @FIXME{this is a cop out. need to add some simple tape drive info.}
690 @end itemize
691
692 @node stylistic conventions
693 @section Stylistic Conventions
694
695 In the examples, @samp{$} represents a typical shell prompt. It
696 precedes lines you should type; to make this more clear, those lines are
697 shown in @kbd{this font}, as opposed to lines which represent the
698 computer's response; those lines are shown in @code{this font}, or
699 sometimes @samp{like this}.
700
701 @c When we have lines which are too long to be
702 @c displayed in any other way, we will show them like this:
703
704 @node basic tar options
705 @section Basic @command{tar} Operations and Options
706
707 @command{tar} can take a wide variety of arguments which specify and define
708 the actions it will have on the particular set of files or the archive.
709 The main types of arguments to @command{tar} fall into one of two classes:
710 operations, and options.
711
712 Some arguments fall into a class called @dfn{operations}; exactly one of
713 these is both allowed and required for any instance of using @command{tar};
714 you may @emph{not} specify more than one. People sometimes speak of
715 @dfn{operating modes}. You are in a particular operating mode when you
716 have specified the operation which specifies it; there are eight
717 operations in total, and thus there are eight operating modes.
718
719 The other arguments fall into the class known as @dfn{options}. You are
720 not required to specify any options, and you are allowed to specify more
721 than one at a time (depending on the way you are using @command{tar} at
722 that time). Some options are used so frequently, and are so useful for
723 helping you type commands more carefully that they are effectively
724 ``required''. We will discuss them in this chapter.
725
726 You can write most of the @command{tar} operations and options in any
727 of three forms: long (mnemonic) form, short form, and old style. Some
728 of the operations and options have no short or ``old'' forms; however,
729 the operations and options which we will cover in this tutorial have
730 corresponding abbreviations. @FIXME{make sure this is still the case,
731 at the end}We will indicate those abbreviations appropriately to get
732 you used to seeing them. (Note that the ``old style'' option forms
733 exist in @GNUTAR{} for compatibility with Unix
734 @command{tar}. In this book we present a full discussion of this way
735 of writing options and operations (@pxref{Old Options}), and we discuss
736 the other two styles of writing options (@xref{Mnemonic Options}, and
737 @pxref{Short Options}).
738
739 In the examples and in the text of this tutorial, we usually use the
740 long forms of operations and options; but the ``short'' forms produce
741 the same result and can make typing long @command{tar} commands easier.
742 For example, instead of typing
743
744 @smallexample
745 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
746 @end smallexample
747
748 @noindent
749 you can type
750 @smallexample
751 @kbd{tar -c -v -f afiles.tar apple angst aspic}
752 @end smallexample
753
754 @noindent
755 or even
756 @smallexample
757 @kbd{tar -cvf afiles.tar apple angst aspic}
758 @end smallexample
759
760 @noindent
761 For more information on option syntax, see @ref{Advanced tar}. In
762 discussions in the text, when we name an option by its long form, we
763 also give the corresponding short option in parentheses.
764
765 The term, ``option'', can be confusing at times, since ``operations''
766 are often lumped in with the actual, @emph{optional} ``options'' in certain
767 general class statements. For example, we just talked about ``short and
768 long forms of options and operations''. However, experienced @command{tar}
769 users often refer to these by shorthand terms such as, ``short and long
770 options''. This term assumes that the ``operations'' are included, also.
771 Context will help you determine which definition of ``options'' to use.
772
773 Similarly, the term ``command'' can be confusing, as it is often used in
774 two different ways. People sometimes refer to @command{tar} ``commands''.
775 A @command{tar} @dfn{command} is the entire command line of user input
776 which tells @command{tar} what to do --- including the operation, options,
777 and any arguments (file names, pipes, other commands, etc). However,
778 you will also sometimes hear the term ``the @command{tar} command''. When
779 the word ``command'' is used specifically like this, a person is usually
780 referring to the @command{tar} @emph{operation}, not the whole line.
781 Again, use context to figure out which of the meanings the speaker
782 intends.
783
784 @node frequent operations
785 @section The Three Most Frequently Used Operations
786
787 Here are the three most frequently used operations (both short and long
788 forms), as well as a brief description of their meanings. The rest of
789 this chapter will cover how to use these operations in detail. We will
790 present the rest of the operations in the next chapter.
791
792 @table @option
793 @item --create
794 @itemx -c
795 Create a new @command{tar} archive.
796 @item --list
797 @itemx -t
798 List the contents of an archive.
799 @item --extract
800 @itemx -x
801 Extract one or more members from an archive.
802 @end table
803
804 @node Two Frequent Options
805 @section Two Frequently Used Options
806
807 To understand how to run @command{tar} in the three operating modes listed
808 previously, you also need to understand how to use two of the options to
809 @command{tar}: @option{--file} (which takes an archive file as an argument)
810 and @option{--verbose}. (You are usually not @emph{required} to specify
811 either of these options when you run @command{tar}, but they can be very
812 useful in making things more clear and helping you avoid errors.)
813
814 @menu
815 * file tutorial::
816 * verbose tutorial::
817 * help tutorial::
818 @end menu
819
820 @node file tutorial
821 @unnumberedsubsec The @option{--file} Option
822
823 @table @option
824 @opindex file, tutorial
825 @item --file=@var{archive-name}
826 @itemx -f @var{archive-name}
827 Specify the name of an archive file.
828 @end table
829
830 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
831 use @command{tar}; this option determines the name of the archive file
832 that @command{tar} will work on.
833
834 @vrindex TAPE
835 If you don't specify this argument, then @command{tar} will examine
836 the environment variable @env{TAPE}. If it is set, its value will be
837 used as the archive name. Otherwise, @command{tar} will use the
838 default archive, determined at the compile time. Usually it is
839 standard output or some physical tape drive attached to your machine
840 (you can verify what the default is by running @kbd{tar
841 --show-defaults}, @pxref{defaults}). If there is no tape drive
842 attached, or the default is not meaningful, then @command{tar} will
843 print an error message. The error message might look roughly like one
844 of the following:
845
846 @smallexample
847 tar: can't open /dev/rmt8 : No such device or address
848 tar: can't open /dev/rsmt0 : I/O error
849 @end smallexample
850
851 @noindent
852 To avoid confusion, we recommend that you always specify an archive file
853 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
854 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
855 @ref{file}.
856
857 @node verbose tutorial
858 @unnumberedsubsec The @option{--verbose} Option
859
860 @table @option
861 @opindex verbose, introduced
862 @item --verbose
863 @itemx -v
864 Show the files being worked on as @command{tar} is running.
865 @end table
866
867 @option{--verbose} (@option{-v}) shows details about the results of running
868 @command{tar}. This can be especially useful when the results might not be
869 obvious. For example, if you want to see the progress of @command{tar} as
870 it writes files into the archive, you can use the @option{--verbose}
871 option. In the beginning, you may find it useful to use
872 @option{--verbose} at all times; when you are more accustomed to
873 @command{tar}, you will likely want to use it at certain times but not at
874 others. We will use @option{--verbose} at times to help make something
875 clear, and we will give many examples both using and not using
876 @option{--verbose} to show the differences.
877
878 Each instance of @option{--verbose} on the command line increases the
879 verbosity level by one, so if you need more details on the output,
880 specify it twice.
881
882 When reading archives (@option{--list}, @option{--extract},
883 @option{--diff}), @command{tar} by default prints only the names of
884 the members being extracted. Using @option{--verbose} will show a full,
885 @command{ls} style member listing.
886
887 In contrast, when writing archives (@option{--create}, @option{--append},
888 @option{--update}), @command{tar} does not print file names by
889 default. So, a single @option{--verbose} option shows the file names
890 being added to the archive, while two @option{--verbose} options
891 enable the full listing.
892
893 For example, to create an archive in verbose mode:
894
895 @smallexample
896 $ @kbd{tar -cvf afiles.tar apple angst aspic}
897 apple
898 angst
899 aspic
900 @end smallexample
901
902 @noindent
903 Creating the same archive with the verbosity level 2 could give:
904
905 @smallexample
906 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
907 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
908 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
909 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
910 @end smallexample
911
912 @noindent
913 This works equally well using short or long forms of options. Using
914 long forms, you would simply write out the mnemonic form of the option
915 twice, like this:
916
917 @smallexample
918 $ @kbd{tar --create --verbose --verbose @dots{}}
919 @end smallexample
920
921 @noindent
922 Note that you must double the hyphens properly each time.
923
924 Later in the tutorial, we will give examples using @w{@option{--verbose
925 --verbose}}.
926
927 The full output consists of six fields:
928
929 @itemize @bullet
930 @item File type and permissions in symbolic form.
931 These are displayed in the same format as the first column of
932 @command{ls -l} output (@pxref{What information is listed,
933 format=verbose, Verbose listing, fileutils, GNU file utilities}).
934
935 @item Owner name and group separated by a slash character.
936 If these data are not available (for example, when listing a @samp{v7} format
937 archive), numeric ID values are printed instead.
938
939 @item Size of the file, in bytes.
940
941 @item File modification date in ISO 8601 format.
942
943 @item File modification time.
944
945 @item File name.
946 If the name contains any special characters (white space, newlines,
947 etc.) these are displayed in an unambiguous form using so called
948 @dfn{quoting style}. For the detailed discussion of available styles
949 and on how to use them, see @ref{quoting styles}.
950
951 Depending on the file type, the name can be followed by some
952 additional information, described in the following table:
953
954 @table @samp
955 @item -> @var{link-name}
956 The file or archive member is a @dfn{symbolic link} and
957 @var{link-name} is the name of file it links to.
958
959 @item link to @var{link-name}
960 The file or archive member is a @dfn{hard link} and @var{link-name} is
961 the name of file it links to.
962
963 @item --Long Link--
964 The archive member is an old GNU format long link. You will normally
965 not encounter this.
966
967 @item --Long Name--
968 The archive member is an old GNU format long name. You will normally
969 not encounter this.
970
971 @item --Volume Header--
972 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
973
974 @item --Continued at byte @var{n}--
975 Encountered only at the beginning of a multy-volume archive
976 (@pxref{Using Multiple Tapes}). This archive member is a continuation
977 from the previous volume. The number @var{n} gives the offset where
978 the original file was split.
979
980 @item --Mangled file names--
981 This archive member contains @dfn{mangled file names} declarations,
982 a special member type that was used by early versions of @GNUTAR{}.
983 You probably will never encounter this, unless you are reading a very
984 old archive.
985
986 @item unknown file type @var{c}
987 An archive member of unknown type. @var{c} is the type character from
988 the archive header. If you encounter such a message, it means that
989 either your archive contains proprietary member types @GNUTAR{} is not
990 able to handle, or the archive is corrupted.
991 @end table
992
993 @end itemize
994
995 For example, here is an archive listing containing most of the special
996 suffixes explained above:
997
998 @smallexample
999 @group
1000 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1001 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1002 byte 32456--
1003 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1004 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1005 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1006 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1007 @end group
1008 @end smallexample
1009
1010 @smallexample
1011 @end smallexample
1012
1013 @node help tutorial
1014 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1015
1016 @table @option
1017 @opindex help
1018 @item --help
1019
1020 The @option{--help} option to @command{tar} prints out a very brief list of
1021 all operations and option available for the current version of
1022 @command{tar} available on your system.
1023 @end table
1024
1025 @node create
1026 @section How to Create Archives
1027 @UNREVISED
1028
1029 @cindex Creation of the archive
1030 @cindex Archive, creation of
1031 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1032 you use to create a @command{tar} archive. We will explain
1033 @option{--create} first because, in order to learn about the other
1034 operations, you will find it useful to have an archive available to
1035 practice on.
1036
1037 To make this easier, in this section you will first create a directory
1038 containing three files. Then, we will show you how to create an
1039 @emph{archive} (inside the new directory). Both the directory, and
1040 the archive are specifically for you to practice on. The rest of this
1041 chapter and the next chapter will show many examples using this
1042 directory and the files you will create: some of those files may be
1043 other directories and other archives.
1044
1045 The three files you will archive in this example are called
1046 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1047 @file{collection.tar}.
1048
1049 This section will proceed slowly, detailing how to use @option{--create}
1050 in @code{verbose} mode, and showing examples using both short and long
1051 forms. In the rest of the tutorial, and in the examples in the next
1052 chapter, we will proceed at a slightly quicker pace. This section
1053 moves more slowly to allow beginning users to understand how
1054 @command{tar} works.
1055
1056 @menu
1057 * prepare for examples::
1058 * Creating the archive::
1059 * create verbose::
1060 * short create::
1061 * create dir::
1062 @end menu
1063
1064 @node prepare for examples
1065 @subsection Preparing a Practice Directory for Examples
1066
1067 To follow along with this and future examples, create a new directory
1068 called @file{practice} containing files called @file{blues}, @file{folk}
1069 and @file{jazz}. The files can contain any information you like:
1070 ideally, they should contain information which relates to their names,
1071 and be of different lengths. Our examples assume that @file{practice}
1072 is a subdirectory of your home directory.
1073
1074 Now @command{cd} to the directory named @file{practice}; @file{practice}
1075 is now your @dfn{working directory}. (@emph{Please note}: Although
1076 the full path name of this directory is
1077 @file{/@var{homedir}/practice}, in our examples we will refer to
1078 this directory as @file{practice}; the @var{homedir} is presumed.
1079
1080 In general, you should check that the files to be archived exist where
1081 you think they do (in the working directory) by running @command{ls}.
1082 Because you just created the directory and the files and have changed to
1083 that directory, you probably don't need to do that this time.
1084
1085 It is very important to make sure there isn't already a file in the
1086 working directory with the archive name you intend to use (in this case,
1087 @samp{collection.tar}), or that you don't care about its contents.
1088 Whenever you use @samp{create}, @command{tar} will erase the current
1089 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1090 will not tell you if you are about to overwrite an archive unless you
1091 specify an option which does this (@pxref{backup}, for the
1092 information on how to do so). To add files to an existing archive,
1093 you need to use a different option, such as @option{--append} (@option{-r}); see
1094 @ref{append} for information on how to do this.
1095
1096 @node Creating the archive
1097 @subsection Creating the Archive
1098
1099 @opindex create, introduced
1100 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1101 archive named @file{collection.tar}, use the following command:
1102
1103 @smallexample
1104 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1105 @end smallexample
1106
1107 The order of the arguments is not very important, @emph{when using long
1108 option forms}. You could also say:
1109
1110 @smallexample
1111 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1112 @end smallexample
1113
1114 @noindent
1115 However, you can see that this order is harder to understand; this is
1116 why we will list the arguments in the order that makes the commands
1117 easiest to understand (and we encourage you to do the same when you use
1118 @command{tar}, to avoid errors).
1119
1120 Note that the part of the command which says,
1121 @w{@option{--file=collection.tar}} is considered to be @emph{one} argument.
1122 If you substituted any other string of characters for
1123 @kbd{collection.tar}, then that string would become the name of the
1124 archive file you create.
1125
1126 The order of the options becomes more important when you begin to use
1127 short forms. With short forms, if you type commands in the wrong order
1128 (even if you type them correctly in all other ways), you may end up with
1129 results you don't expect. For this reason, it is a good idea to get
1130 into the habit of typing options in the order that makes inherent sense.
1131 @xref{short create}, for more information on this.
1132
1133 In this example, you type the command as shown above: @option{--create}
1134 is the operation which creates the new archive
1135 (@file{collection.tar}), and @option{--file} is the option which lets
1136 you give it the name you chose. The files, @file{blues}, @file{folk},
1137 and @file{jazz}, are now members of the archive, @file{collection.tar}
1138 (they are @dfn{file name arguments} to the @option{--create} operation.
1139 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1140 in the archive, they are called @emph{archive members}, not files.
1141 (@pxref{Definitions,members}).
1142
1143 When you create an archive, you @emph{must} specify which files you
1144 want placed in the archive. If you do not specify any archive
1145 members, @GNUTAR{} will complain.
1146
1147 If you now list the contents of the working directory (@command{ls}), you will
1148 find the archive file listed as well as the files you saw previously:
1149
1150 @smallexample
1151 blues folk jazz collection.tar
1152 @end smallexample
1153
1154 @noindent
1155 Creating the archive @samp{collection.tar} did not destroy the copies of
1156 the files in the directory.
1157
1158 Keep in mind that if you don't indicate an operation, @command{tar} will not
1159 run and will prompt you for one. If you don't name any files, @command{tar}
1160 will complain. You must have write access to the working directory,
1161 or else you will not be able to create an archive in that directory.
1162
1163 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1164 an existing archive; it will delete the archive and write a new one.
1165 Use @option{--append} (@option{-r}) instead. @xref{append}.
1166
1167 @node create verbose
1168 @subsection Running @option{--create} with @option{--verbose}
1169
1170 @opindex create, using with @option{--verbose}
1171 @opindex verbose, using with @option{--create}
1172 If you include the @option{--verbose} (@option{-v}) option on the command line,
1173 @command{tar} will list the files it is acting on as it is working. In
1174 verbose mode, the @code{create} example above would appear as:
1175
1176 @smallexample
1177 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1178 blues
1179 folk
1180 jazz
1181 @end smallexample
1182
1183 This example is just like the example we showed which did not use
1184 @option{--verbose}, except that @command{tar} generated the remaining lines
1185 @iftex
1186 (note the different font styles).
1187 @end iftex
1188 @ifinfo
1189 .
1190 @end ifinfo
1191
1192 In the rest of the examples in this chapter, we will frequently use
1193 @code{verbose} mode so we can show actions or @command{tar} responses that
1194 you would otherwise not see, and which are important for you to
1195 understand.
1196
1197 @node short create
1198 @subsection Short Forms with @samp{create}
1199
1200 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1201 basic uses of @command{tar}, and you will use it countless times.
1202 Eventually, you will probably want to use abbreviated (or ``short'')
1203 forms of options. A full discussion of the three different forms that
1204 options can take appears in @ref{Styles}; for now, here is what the
1205 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1206 using short option forms:
1207
1208 @smallexample
1209 $ @kbd{tar -cvf collection.tar blues folk jazz}
1210 blues
1211 folk
1212 jazz
1213 @end smallexample
1214
1215 @noindent
1216 As you can see, the system responds the same no matter whether you use
1217 long or short option forms.
1218
1219 @FIXME{i don't like how this is worded:} One difference between using
1220 short and long option forms is that, although the exact placement of
1221 arguments following options is no more specific when using short forms,
1222 it is easier to become confused and make a mistake when using short
1223 forms. For example, suppose you attempted the above example in the
1224 following way:
1225
1226 @smallexample
1227 $ @kbd{tar -cfv collection.tar blues folk jazz}
1228 @end smallexample
1229
1230 @noindent
1231 In this case, @command{tar} will make an archive file called @file{v},
1232 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1233 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1234 is thus taken to be the chosen archive file name. @command{tar} will try
1235 to add a file called @file{collection.tar} to the @file{v} archive file;
1236 if the file @file{collection.tar} did not already exist, @command{tar} will
1237 report an error indicating that this file does not exist. If the file
1238 @file{collection.tar} does already exist (e.g., from a previous command
1239 you may have run), then @command{tar} will add this file to the archive.
1240 Because the @option{-v} option did not get registered, @command{tar} will not
1241 run under @samp{verbose} mode, and will not report its progress.
1242
1243 The end result is that you may be quite confused about what happened,
1244 and possibly overwrite a file. To illustrate this further, we will show
1245 you how an example we showed previously would look using short forms.
1246
1247 This example,
1248
1249 @smallexample
1250 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1251 @end smallexample
1252
1253 @noindent
1254 is confusing as it is. When shown using short forms, however, it
1255 becomes much more so:
1256
1257 @smallexample
1258 $ @kbd{tar blues -c folk -f collection.tar jazz}
1259 @end smallexample
1260
1261 @noindent
1262 It would be very easy to put the wrong string of characters
1263 immediately following the @option{-f}, but doing that could sacrifice
1264 valuable data.
1265
1266 For this reason, we recommend that you pay very careful attention to
1267 the order of options and placement of file and archive names,
1268 especially when using short option forms. Not having the option name
1269 written out mnemonically can affect how well you remember which option
1270 does what, and therefore where different names have to be placed.
1271
1272 @node create dir
1273 @subsection Archiving Directories
1274
1275 @cindex Archiving Directories
1276 @cindex Directories, Archiving
1277 You can archive a directory by specifying its directory name as a
1278 file name argument to @command{tar}. The files in the directory will be
1279 archived relative to the working directory, and the directory will be
1280 re-created along with its contents when the archive is extracted.
1281
1282 To archive a directory, first move to its superior directory. If you
1283 have followed the previous instructions in this tutorial, you should
1284 type:
1285
1286 @smallexample
1287 $ @kbd{cd ..}
1288 $
1289 @end smallexample
1290
1291 @noindent
1292 This will put you into the directory which contains @file{practice},
1293 i.e., your home directory. Once in the superior directory, you can
1294 specify the subdirectory, @file{practice}, as a file name argument. To
1295 store @file{practice} in the new archive file @file{music.tar}, type:
1296
1297 @smallexample
1298 $ @kbd{tar --create --verbose --file=music.tar practice}
1299 @end smallexample
1300
1301 @noindent
1302 @command{tar} should output:
1303
1304 @smallexample
1305 practice/
1306 practice/blues
1307 practice/folk
1308 practice/jazz
1309 practice/collection.tar
1310 @end smallexample
1311
1312 Note that the archive thus created is not in the subdirectory
1313 @file{practice}, but rather in the current working directory---the
1314 directory from which @command{tar} was invoked. Before trying to archive a
1315 directory from its superior directory, you should make sure you have
1316 write access to the superior directory itself, not only the directory
1317 you are trying archive with @command{tar}. For example, you will probably
1318 not be able to store your home directory in an archive by invoking
1319 @command{tar} from the root directory; @xref{absolute}. (Note
1320 also that @file{collection.tar}, the original archive file, has itself
1321 been archived. @command{tar} will accept any file as a file to be
1322 archived, regardless of its content. When @file{music.tar} is
1323 extracted, the archive file @file{collection.tar} will be re-written
1324 into the file system).
1325
1326 If you give @command{tar} a command such as
1327
1328 @smallexample
1329 $ @kbd{tar --create --file=foo.tar .}
1330 @end smallexample
1331
1332 @noindent
1333 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1334 dumped}. This happens because @command{tar} creates the archive
1335 @file{foo.tar} in the current directory before putting any files into
1336 it. Then, when @command{tar} attempts to add all the files in the
1337 directory @file{.} to the archive, it notices that the file
1338 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1339 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1340 will continue in this case, and create the archive
1341 normally, except for the exclusion of that one file. (@emph{Please
1342 note:} Other implementations of @command{tar} may not be so clever;
1343 they will enter an infinite loop when this happens, so you should not
1344 depend on this behavior unless you are certain you are running
1345 @GNUTAR{}. In general, it is wise to always place the archive outside
1346 of the directory being dumped.
1347
1348 @node list
1349 @section How to List Archives
1350
1351 @opindex list
1352 Frequently, you will find yourself wanting to determine exactly what a
1353 particular archive contains. You can use the @option{--list} (@option{-t}) operation
1354 to get the member names as they currently appear in the archive, as well
1355 as various attributes of the files at the time they were archived. For
1356 example, you can examine the archive @file{collection.tar} that you
1357 created in the last section with the command,
1358
1359 @smallexample
1360 $ @kbd{tar --list --file=collection.tar}
1361 @end smallexample
1362
1363 @noindent
1364 The output of @command{tar} would then be:
1365
1366 @smallexample
1367 blues
1368 folk
1369 jazz
1370 @end smallexample
1371
1372 @noindent
1373 The archive @file{bfiles.tar} would list as follows:
1374
1375 @smallexample
1376 ./birds
1377 baboon
1378 ./box
1379 @end smallexample
1380
1381 @noindent
1382 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1383 @var{archive-name}}) option just as with @option{--create}
1384 (@option{-c}) to specify the name of the archive.
1385
1386 @opindex list, using with @option{--verbose}
1387 @opindex verbose, using with @option{--list}
1388 If you use the @option{--verbose} (@option{-v}) option with
1389 @option{--list}, then @command{tar} will print out a listing
1390 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so forth.
1391
1392 If you had used @option{--verbose} (@option{-v}) mode, the example
1393 above would look like:
1394
1395 @smallexample
1396 $ @kbd{tar --list --verbose --file=collection.tar folk}
1397 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1398 @end smallexample
1399
1400 @cindex listing member and file names
1401 @anchor{listing member and file names}
1402 It is important to notice that the output of @kbd{tar --list
1403 --verbose} does not necessarily match that produced by @kbd{tar
1404 --create --verbose} while creating the archive. It is because
1405 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1406 prefixes from file names before storing them in the archive
1407 (@xref{absolute}, for more information). In other
1408 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1409 an archive and @dfn{member names} when listing it. Consider this
1410 example:
1411
1412 @smallexample
1413 @group
1414 $ @kbd{tar cfv archive /etc/mail}
1415 tar: Removing leading `/' from member names
1416 /etc/mail/
1417 /etc/mail/sendmail.cf
1418 /etc/mail/aliases
1419 $ @kbd{tar tf archive}
1420 etc/mail/
1421 etc/mail/sendmail.cf
1422 etc/mail/aliases
1423 @end group
1424 @end smallexample
1425
1426 @opindex show-stored-names
1427 This default behavior can sometimes be inconvenient. You can force
1428 @GNUTAR{} show member names when creating archive by supplying
1429 @option{--show-stored-names} option.
1430
1431 @table @option
1432 @item --show-stored-names
1433 Print member (as opposed to @emph{file}) names when creating the archive.
1434 @end table
1435
1436 @cindex File name arguments, using @option{--list} with
1437 @opindex list, using with file name arguments
1438 You can specify one or more individual member names as arguments when
1439 using @samp{list}. In this case, @command{tar} will only list the
1440 names of members you identify. For example, @w{@kbd{tar --list
1441 --file=afiles.tar apple}} would only print @file{apple}.
1442
1443 Because @command{tar} preserves paths, file names must be specified as
1444 they appear in the archive (ie., relative to the directory from which
1445 the archive was created). Therefore, it is essential when specifying
1446 member names to @command{tar} that you give the exact member names.
1447 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1448 error message something like @samp{tar: birds: Not found in archive},
1449 because there is no member named @file{birds}, only one named
1450 @file{./birds}. While the names @file{birds} and @file{./birds} name
1451 the same file, @emph{member} names by default are compared verbatim.
1452
1453 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1454 with @file{baboon}, because this exact member name is in the archive file
1455 @file{bfiles.tar}. If you are not sure of the exact file name,
1456 use @dfn{globbing patterns}, for example:
1457
1458 @smallexample
1459 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1460 @end smallexample
1461
1462 @noindent
1463 will list all members whose name contains @samp{b}. @xref{wildcards},
1464 for a detailed discussion of globbing patterns and related
1465 @command{tar} command line options.
1466
1467 @menu
1468 * list dir::
1469 @end menu
1470
1471 @node list dir
1472 @unnumberedsubsec Listing the Contents of a Stored Directory
1473
1474 To get information about the contents of an archived directory,
1475 use the directory name as a file name argument in conjunction with
1476 @option{--list} (@option{-t}). To find out file attributes, include the
1477 @option{--verbose} (@option{-v}) option.
1478
1479 For example, to find out about files in the directory @file{practice}, in
1480 the archive file @file{music.tar}, type:
1481
1482 @smallexample
1483 $ @kbd{tar --list --verbose --file=music.tar practice}
1484 @end smallexample
1485
1486 @command{tar} responds:
1487
1488 @smallexample
1489 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1490 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1491 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1492 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1493 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1494 @end smallexample
1495
1496 When you use a directory name as a file name argument, @command{tar} acts on
1497 all the files (including sub-directories) in that directory.
1498
1499 @node extract
1500 @section How to Extract Members from an Archive
1501 @UNREVISED
1502 @cindex Extraction
1503 @cindex Retrieving files from an archive
1504 @cindex Resurrecting files from an archive
1505
1506 @opindex extract
1507 Creating an archive is only half the job---there is no point in storing
1508 files in an archive if you can't retrieve them. The act of retrieving
1509 members from an archive so they can be used and manipulated as
1510 unarchived files again is called @dfn{extraction}. To extract files
1511 from an archive, use the @option{--extract} (@option{--get} or
1512 @option{-x}) operation. As with @option{--create}, specify the name
1513 of the archive with @option{--file} (@option{-f}) option. Extracting
1514 an archive does not modify the archive in any way; you can extract it
1515 multiple times if you want or need to.
1516
1517 Using @option{--extract}, you can extract an entire archive, or specific
1518 files. The files can be directories containing other files, or not. As
1519 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1520 long form of the operation without affecting the performance.
1521
1522 @menu
1523 * extracting archives::
1524 * extracting files::
1525 * extract dir::
1526 * extracting untrusted archives::
1527 * failing commands::
1528 @end menu
1529
1530 @node extracting archives
1531 @subsection Extracting an Entire Archive
1532
1533 To extract an entire archive, specify the archive file name only, with
1534 no individual file names as arguments. For example,
1535
1536 @smallexample
1537 $ @kbd{tar -xvf collection.tar}
1538 @end smallexample
1539
1540 @noindent
1541 produces this:
1542
1543 @smallexample
1544 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1545 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1546 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1547 @end smallexample
1548
1549 @node extracting files
1550 @subsection Extracting Specific Files
1551
1552 To extract specific archive members, give their exact member names as
1553 arguments, as printed by @option{--list} (@option{-t}). If you had
1554 mistakenly deleted one of the files you had placed in the archive
1555 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1556 from the archive without changing the archive's structure. Its
1557 contents will be identical to the original file @file{blues} that you
1558 deleted.
1559
1560 First, make sure you are in the @file{practice} directory, and list the
1561 files in the directory. Now, delete the file, @samp{blues}, and list
1562 the files in the directory again.
1563
1564 You can now extract the member @file{blues} from the archive file
1565 @file{collection.tar} like this:
1566
1567 @smallexample
1568 $ @kbd{tar --extract --file=collection.tar blues}
1569 @end smallexample
1570
1571 @noindent
1572 If you list the files in the directory again, you will see that the file
1573 @file{blues} has been restored, with its original permissions, data
1574 modification times, and owner.@footnote{This is only accidentally
1575 true, but not in general. Whereas modification times are always
1576 restored, in most cases, one has to be root for restoring the owner,
1577 and use a special option for restoring permissions. Here, it just
1578 happens that the restoring user is also the owner of the archived
1579 members, and that the current @code{umask} is compatible with original
1580 permissions.} (These parameters will be identical to those which
1581 the file had when you originally placed it in the archive; any changes
1582 you may have made before deleting the file from the file system,
1583 however, will @emph{not} have been made to the archive member.) The
1584 archive file, @samp{collection.tar}, is the same as it was before you
1585 extracted @samp{blues}. You can confirm this by running @command{tar} with
1586 @option{--list} (@option{-t}).
1587
1588 Remember that as with other operations, specifying the exact member
1589 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1590 will fail, because there is no member named @file{birds}. To extract
1591 the member named @file{./birds}, you must specify @w{@kbd{tar
1592 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1593 exact member names, use @option{--list} (@option{-t}) option
1594 (@pxref{list}). You can also extract those members that match a
1595 specific @dfn{globbing pattern}. For example, to extract from
1596 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1597 directory prefix, you could type:
1598
1599 @smallexample
1600 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1601 @end smallexample
1602
1603 @noindent
1604 Here, @option{--wildcards} instructs @command{tar} to treat
1605 command line arguments as globbing patterns and @option{--no-anchored}
1606 informs it that the patterns apply to member names after any @samp{/}
1607 delimiter. The use of globbing patterns is discussed in detail in
1608 @xref{wildcards}.
1609
1610 You can extract a file to standard output by combining the above options
1611 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1612 Output}).
1613
1614 If you give the @option{--verbose} option, then @option{--extract}
1615 will print the names of the archive members as it extracts them.
1616
1617 @node extract dir
1618 @subsection Extracting Files that are Directories
1619
1620 Extracting directories which are members of an archive is similar to
1621 extracting other files. The main difference to be aware of is that if
1622 the extracted directory has the same name as any directory already in
1623 the working directory, then files in the extracted directory will be
1624 placed into the directory of the same name. Likewise, if there are
1625 files in the pre-existing directory with the same names as the members
1626 which you extract, the files from the extracted archive will replace
1627 the files already in the working directory (and possible
1628 subdirectories). This will happen regardless of whether or not the
1629 files in the working directory were more recent than those extracted
1630 (there exist, however, special options that alter this behavior
1631 @pxref{Writing}).
1632
1633 However, if a file was stored with a directory name as part of its file
1634 name, and that directory does not exist under the working directory when
1635 the file is extracted, @command{tar} will create the directory.
1636
1637 We can demonstrate how to use @option{--extract} to extract a directory
1638 file with an example. Change to the @file{practice} directory if you
1639 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1640 go back to the parent directory and extract the archive
1641 @file{music.tar}. You may either extract the entire archive, or you may
1642 extract only the files you just deleted. To extract the entire archive,
1643 don't give any file names as arguments after the archive name
1644 @file{music.tar}. To extract only the files you deleted, use the
1645 following command:
1646
1647 @smallexample
1648 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1649 practice/folk
1650 practice/jazz
1651 @end smallexample
1652
1653 @noindent
1654 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1655 would have displayed more detail about the extracted files, as shown
1656 in the example below:
1657
1658 @smallexample
1659 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1660 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1661 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1662 @end smallexample
1663
1664 @noindent
1665 Because you created the directory with @file{practice} as part of the
1666 file names of each of the files by archiving the @file{practice}
1667 directory as @file{practice}, you must give @file{practice} as part
1668 of the file names when you extract those files from the archive.
1669
1670 @node extracting untrusted archives
1671 @subsection Extracting Archives from Untrusted Sources
1672
1673 Extracting files from archives can overwrite files that already exist.
1674 If you receive an archive from an untrusted source, you should make a
1675 new directory and extract into that directory, so that you don't have
1676 to worry about the extraction overwriting one of your existing files.
1677 For example, if @file{untrusted.tar} came from somewhere else on the
1678 Internet, and you don't necessarily trust its contents, you can
1679 extract it as follows:
1680
1681 @smallexample
1682 $ @kbd{mkdir newdir}
1683 $ @kbd{cd newdir}
1684 $ @kbd{tar -xvf ../untrusted.tar}
1685 @end smallexample
1686
1687 It is also a good practice to examine contents of the archive
1688 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1689 with @option{--verbose} (@option{-v}).
1690
1691 @node failing commands
1692 @subsection Commands That Will Fail
1693
1694 Here are some sample commands you might try which will not work, and why
1695 they won't work.
1696
1697 If you try to use this command,
1698
1699 @smallexample
1700 $ @kbd{tar -xvf music.tar folk jazz}
1701 @end smallexample
1702
1703 @noindent
1704 you will get the following response:
1705
1706 @smallexample
1707 tar: folk: Not found in archive
1708 tar: jazz: Not found in archive
1709 $
1710 @end smallexample
1711
1712 @noindent
1713 This is because these files were not originally @emph{in} the parent
1714 directory @file{..}, where the archive is located; they were in the
1715 @file{practice} directory, and their file names reflect this:
1716
1717 @smallexample
1718 $ @kbd{tar -tvf music.tar}
1719 practice/folk
1720 practice/jazz
1721 practice/rock
1722 @end smallexample
1723
1724 @FIXME{make sure the above works when going through the examples in
1725 order...}
1726
1727 @noindent
1728 Likewise, if you try to use this command,
1729
1730 @smallexample
1731 $ @kbd{tar -tvf music.tar folk jazz}
1732 @end smallexample
1733
1734 @noindent
1735 you would get a similar response. Members with those names are not in the
1736 archive. You must use the correct member names, or wildcards, in order
1737 to extract the files from the archive.
1738
1739 If you have forgotten the correct names of the files in the archive,
1740 use @w{@kbd{tar --list --verbose}} to list them correctly.
1741
1742 @FIXME{more examples, here? hag thinks it's a good idea.}
1743
1744 @node going further
1745 @section Going Further Ahead in this Manual
1746
1747 @FIXME{need to write up a node here about the things that are going to
1748 be in the rest of the manual.}
1749
1750 @node tar invocation
1751 @chapter Invoking @GNUTAR{}
1752 @UNREVISED
1753
1754 This chapter is about how one invokes the @GNUTAR{}
1755 command, from the command synopsis (@pxref{Synopsis}). There are
1756 numerous options, and many styles for writing them. One mandatory
1757 option specifies the operation @command{tar} should perform
1758 (@pxref{Operation Summary}), other options are meant to detail how
1759 this operation should be performed (@pxref{Option Summary}).
1760 Non-option arguments are not always interpreted the same way,
1761 depending on what the operation is.
1762
1763 You will find in this chapter everything about option styles and rules for
1764 writing them (@pxref{Styles}). On the other hand, operations and options
1765 are fully described elsewhere, in other chapters. Here, you will find
1766 only synthetic descriptions for operations and options, together with
1767 pointers to other parts of the @command{tar} manual.
1768
1769 Some options are so special they are fully described right in this
1770 chapter. They have the effect of inhibiting the normal operation of
1771 @command{tar} or else, they globally alter the amount of feedback the user
1772 receives about what is going on. These are the @option{--help} and
1773 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1774 and @option{--interactive} options (@pxref{interactive}).
1775
1776 @menu
1777 * Synopsis::
1778 * using tar options::
1779 * Styles::
1780 * All Options::
1781 * help::
1782 * defaults::
1783 * verbose::
1784 * interactive::
1785 @end menu
1786
1787 @node Synopsis
1788 @section General Synopsis of @command{tar}
1789
1790 The @GNUTAR{} program is invoked as either one of:
1791
1792 @smallexample
1793 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1794 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1795 @end smallexample
1796
1797 The second form is for when old options are being used.
1798
1799 You can use @command{tar} to store files in an archive, to extract them from
1800 an archive, and to do other types of archive manipulation. The primary
1801 argument to @command{tar}, which is called the @dfn{operation}, specifies
1802 which action to take. The other arguments to @command{tar} are either
1803 @dfn{options}, which change the way @command{tar} performs an operation,
1804 or file names or archive members, which specify the files or members
1805 @command{tar} is to act on.
1806
1807 You can actually type in arguments in any order, even if in this manual
1808 the options always precede the other arguments, to make examples easier
1809 to understand. Further, the option stating the main operation mode
1810 (the @command{tar} main command) is usually given first.
1811
1812 Each @var{name} in the synopsis above is interpreted as an archive member
1813 name when the main command is one of @option{--compare}
1814 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1815 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1816 @option{--update} (@option{-u}). When naming archive members, you
1817 must give the exact name of the member in the archive, as it is
1818 printed by @option{--list}. For @option{--append} (@option{-r}) and
1819 @option{--create} (@option{-c}), these @var{name} arguments specify
1820 the names of either files or directory hierarchies to place in the archive.
1821 These files or hierarchies should already exist in the file system,
1822 prior to the execution of the @command{tar} command.
1823
1824 @command{tar} interprets relative file names as being relative to the
1825 working directory. @command{tar} will make all file names relative
1826 (by removing leading slashes when archiving or restoring files),
1827 unless you specify otherwise (using the @option{--absolute-names}
1828 option). @xref{absolute}, for more information about
1829 @option{--absolute-names}.
1830
1831 If you give the name of a directory as either a file name or a member
1832 name, then @command{tar} acts recursively on all the files and directories
1833 beneath that directory. For example, the name @file{/} identifies all
1834 the files in the file system to @command{tar}.
1835
1836 The distinction between file names and archive member names is especially
1837 important when shell globbing is used, and sometimes a source of confusion
1838 for newcomers. @xref{wildcards}, for more information about globbing.
1839 The problem is that shells may only glob using existing files in the
1840 file system. Only @command{tar} itself may glob on archive members, so when
1841 needed, you must ensure that wildcard characters reach @command{tar} without
1842 being interpreted by the shell first. Using a backslash before @samp{*}
1843 or @samp{?}, or putting the whole argument between quotes, is usually
1844 sufficient for this.
1845
1846 Even if @var{name}s are often specified on the command line, they
1847 can also be read from a text file in the file system, using the
1848 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1849
1850 If you don't use any file name arguments, @option{--append} (@option{-r}),
1851 @option{--delete} and @option{--concatenate} (@option{--catenate},
1852 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1853 will usually yield a diagnostic and inhibit @command{tar} execution.
1854 The other operations of @command{tar} (@option{--list},
1855 @option{--extract}, @option{--compare}, and @option{--update})
1856 will act on the entire contents of the archive.
1857
1858 @cindex exit status
1859 @cindex return status
1860 Besides successful exits, @GNUTAR{} may fail for
1861 many reasons. Some reasons correspond to bad usage, that is, when the
1862 @command{tar} command is improperly written. Errors may be
1863 encountered later, while encountering an error processing the archive
1864 or the files. Some errors are recoverable, in which case the failure
1865 is delayed until @command{tar} has completed all its work. Some
1866 errors are such that it would not meaningful, or at least risky, to
1867 continue processing: @command{tar} then aborts processing immediately.
1868 All abnormal exits, whether immediate or delayed, should always be
1869 clearly diagnosed on @code{stderr}, after a line stating the nature of
1870 the error.
1871
1872 @GNUTAR{} returns only a few exit statuses. I'm really
1873 aiming simplicity in that area, for now. If you are not using the
1874 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1875 that everything went well, besides maybe innocuous warnings. Nonzero
1876 means that something went wrong. Right now, as of today, ``nonzero''
1877 is almost always 2, except for remote operations, where it may be
1878 128.
1879
1880 @node using tar options
1881 @section Using @command{tar} Options
1882
1883 @GNUTAR{} has a total of eight operating modes which
1884 allow you to perform a variety of tasks. You are required to choose
1885 one operating mode each time you employ the @command{tar} program by
1886 specifying one, and only one operation as an argument to the
1887 @command{tar} command (two lists of four operations each may be found
1888 at @ref{frequent operations} and @ref{Operations}). Depending on
1889 circumstances, you may also wish to customize how the chosen operating
1890 mode behaves. For example, you may wish to change the way the output
1891 looks, or the format of the files that you wish to archive may require
1892 you to do something special in order to make the archive look right.
1893
1894 You can customize and control @command{tar}'s performance by running
1895 @command{tar} with one or more options (such as @option{--verbose}
1896 (@option{-v}), which we used in the tutorial). As we said in the
1897 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1898 their name suggests) optional. Depending on the operating mode, you
1899 may specify one or more options. Different options will have different
1900 effects, but in general they all change details of the operation, such
1901 as archive format, archive name, or level of user interaction. Some
1902 options make sense with all operating modes, while others are
1903 meaningful only with particular modes. You will likely use some
1904 options frequently, while you will only use others infrequently, or
1905 not at all. (A full list of options is available in @pxref{All Options}.)
1906
1907 @vrindex TAR_OPTIONS, environment variable
1908 @anchor{TAR_OPTIONS}
1909 The @env{TAR_OPTIONS} environment variable specifies default options to
1910 be placed in front of any explicit options. For example, if
1911 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1912 if the two options @option{-v} and @option{--unlink-first} had been
1913 specified before any explicit options. Option specifications are
1914 separated by whitespace. A backslash escapes the next character, so it
1915 can be used to specify an option containing whitespace or a backslash.
1916
1917 Note that @command{tar} options are case sensitive. For example, the
1918 options @option{-T} and @option{-t} are different; the first requires an
1919 argument for stating the name of a file providing a list of @var{name}s,
1920 while the second does not require an argument and is another way to
1921 write @option{--list} (@option{-t}).
1922
1923 In addition to the eight operations, there are many options to
1924 @command{tar}, and three different styles for writing both: long (mnemonic)
1925 form, short form, and old style. These styles are discussed below.
1926 Both the options and the operations can be written in any of these three
1927 styles.
1928
1929 @FIXME{menu at end of this node. need to think of an actual outline
1930 for this chapter; probably do that after stuff from chapter 4 is
1931 incorporated.}
1932
1933 @node Styles
1934 @section The Three Option Styles
1935
1936 There are three styles for writing operations and options to the command
1937 line invoking @command{tar}. The different styles were developed at
1938 different times during the history of @command{tar}. These styles will be
1939 presented below, from the most recent to the oldest.
1940
1941 Some options must take an argument. (For example, @option{--file}
1942 (@option{-f})) takes the name of an archive file as an argument. If
1943 you do not supply an archive file name, @command{tar} will use a
1944 default, but this can be confusing; thus, we recommend that you always
1945 supply a specific archive file name.) Where you @emph{place} the
1946 arguments generally depends on which style of options you choose. We
1947 will detail specific information relevant to each option style in the
1948 sections on the different option styles, below. The differences are
1949 subtle, yet can often be very important; incorrect option placement
1950 can cause you to overwrite a number of important files. We urge you
1951 to note these differences, and only use the option style(s) which
1952 makes the most sense to you until you feel comfortable with the others.
1953
1954 Some options @emph{may} take an argument (currently, there are
1955 two such options: @option{--backup} and @option{--occurrence}). Such
1956 options may have at most long and short forms, they do not have old style
1957 equivalent. The rules for specifying an argument for such options
1958 are stricter than those for specifying mandatory arguments. Please,
1959 pay special attention to them.
1960
1961 @menu
1962 * Mnemonic Options:: Mnemonic Option Style
1963 * Short Options:: Short Option Style
1964 * Old Options:: Old Option Style
1965 * Mixing:: Mixing Option Styles
1966 @end menu
1967
1968 @node Mnemonic Options
1969 @subsection Mnemonic Option Style
1970
1971 @FIXME{have to decide whether or not to replace other occurrences of
1972 "mnemonic" with "long", or *ugh* vice versa.}
1973
1974 Each option has at least one long (or mnemonic) name starting with two
1975 dashes in a row, e.g., @option{--list}. The long names are more clear than
1976 their corresponding short or old names. It sometimes happens that a
1977 single mnemonic option has many different different names which are
1978 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1979 long option names can be given unique abbreviations. For example,
1980 @option{--cre} can be used in place of @option{--create} because there is no
1981 other mnemonic option which begins with @samp{cre}. (One way to find
1982 this out is by trying it and seeing what happens; if a particular
1983 abbreviation could represent more than one option, @command{tar} will tell
1984 you that that abbreviation is ambiguous and you'll know that that
1985 abbreviation won't work. You may also choose to run @samp{tar --help}
1986 to see a list of options. Be aware that if you run @command{tar} with a
1987 unique abbreviation for the long name of an option you didn't want to
1988 use, you are stuck; @command{tar} will perform the command as ordered.)
1989
1990 Mnemonic options are meant to be obvious and easy to remember, and their
1991 meanings are generally easier to discern than those of their
1992 corresponding short options (see below). For example:
1993
1994 @smallexample
1995 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
1996 @end smallexample
1997
1998 @noindent
1999 gives a fairly good set of hints about what the command does, even
2000 for those not fully acquainted with @command{tar}.
2001
2002 Mnemonic options which require arguments take those arguments
2003 immediately following the option name. There are two ways of
2004 specifying a mandatory argument. It can be separated from the
2005 option name either by an equal sign, or by any amount of
2006 white space characters. For example, the @option{--file} option (which
2007 tells the name of the @command{tar} archive) is given a file such as
2008 @file{archive.tar} as argument by using any of the following notations:
2009 @option{--file=archive.tar} or @option{--file archive.tar}.
2010
2011 In contrast, optional arguments must always be introduced using
2012 an equal sign. For example, the @option{--backup} option takes
2013 an optional argument specifying backup type. It must be used
2014 as @option{--backup=@var{backup-type}}.
2015
2016 @node Short Options
2017 @subsection Short Option Style
2018
2019 Most options also have a short option name. Short options start with
2020 a single dash, and are followed by a single character, e.g., @option{-t}
2021 (which is equivalent to @option{--list}). The forms are absolutely
2022 identical in function; they are interchangeable.
2023
2024 The short option names are faster to type than long option names.
2025
2026 Short options which require arguments take their arguments immediately
2027 following the option, usually separated by white space. It is also
2028 possible to stick the argument right after the short option name, using
2029 no intervening space. For example, you might write @w{@option{-f
2030 archive.tar}} or @option{-farchive.tar} instead of using
2031 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2032 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2033 specific archive, here named @file{archive.tar}.
2034
2035 Short options which take optional arguments take their arguments
2036 immediately following the option letter, @emph{without any intervening
2037 white space characters}.
2038
2039 Short options' letters may be clumped together, but you are not
2040 required to do this (as compared to old options; see below). When
2041 short options are clumped as a set, use one (single) dash for them
2042 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2043 such a set is allowed to have an argument@footnote{Clustering many
2044 options, the last of which has an argument, is a rather opaque way to
2045 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2046 even be made helpful enough for considering such usages as invalid.}.
2047
2048 When the options are separated, the argument for each option which requires
2049 an argument directly follows that option, as is usual for Unix programs.
2050 For example:
2051
2052 @smallexample
2053 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2054 @end smallexample
2055
2056 If you reorder short options' locations, be sure to move any arguments
2057 that belong to them. If you do not move the arguments properly, you may
2058 end up overwriting files.
2059
2060 @node Old Options
2061 @subsection Old Option Style
2062 @UNREVISED
2063
2064 Like short options, old options are single letters. However, old options
2065 must be written together as a single clumped set, without spaces separating
2066 them or dashes preceding them@footnote{Beware that if you precede options
2067 with a dash, you are announcing the short option style instead of the
2068 old option style; short options are decoded differently.}. This set
2069 of letters must be the first to appear on the command line, after the
2070 @command{tar} program name and some white space; old options cannot appear
2071 anywhere else. The letter of an old option is exactly the same letter as
2072 the corresponding short option. For example, the old option @samp{t} is
2073 the same as the short option @option{-t}, and consequently, the same as the
2074 mnemonic option @option{--list}. So for example, the command @w{@samp{tar
2075 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2076
2077 When options that need arguments are given together with the command,
2078 all the associated arguments follow, in the same order as the options.
2079 Thus, the example given previously could also be written in the old
2080 style as follows:
2081
2082 @smallexample
2083 $ @kbd{tar cvbf 20 /dev/rmt0}
2084 @end smallexample
2085
2086 @noindent
2087 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2088 the argument of @option{-f}.
2089
2090 On the other hand, this old style syntax makes it difficult to match
2091 option letters with their corresponding arguments, and is often
2092 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2093 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2094 argument for @option{-f}, and @option{-v} does not have a corresponding
2095 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2096 /dev/rmt0}} is clearer, putting all arguments next to the option they
2097 pertain to.
2098
2099 If you want to reorder the letters in the old option argument, be
2100 sure to reorder any corresponding argument appropriately.
2101
2102 This old way of writing @command{tar} options can surprise even experienced
2103 users. For example, the two commands:
2104
2105 @smallexample
2106 @kbd{tar cfz archive.tar.gz file}
2107 @kbd{tar -cfz archive.tar.gz file}
2108 @end smallexample
2109
2110 @noindent
2111 are quite different. The first example uses @file{archive.tar.gz} as
2112 the value for option @samp{f} and recognizes the option @samp{z}. The
2113 second example, however, uses @file{z} as the value for option
2114 @samp{f} --- probably not what was intended.
2115
2116 Old options are kept for compatibility with old versions of @command{tar}.
2117
2118 This second example could be corrected in many ways, among which the
2119 following are equivalent:
2120
2121 @smallexample
2122 @kbd{tar -czf archive.tar.gz file}
2123 @kbd{tar -cf archive.tar.gz -z file}
2124 @kbd{tar cf archive.tar.gz -z file}
2125 @end smallexample
2126
2127 @cindex option syntax, traditional
2128 As far as we know, all @command{tar} programs, @acronym{GNU} and
2129 non-@acronym{GNU}, support old options. @GNUTAR{}
2130 supports them not only for historical reasons, but also because many
2131 people are used to them. For compatibility with Unix @command{tar},
2132 the first argument is always treated as containing command and option
2133 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2134 equivalent to @w{@samp{tar -c}:} both of them specify the
2135 @option{--create} (@option{-c}) command to create an archive.
2136
2137 @node Mixing
2138 @subsection Mixing Option Styles
2139
2140 All three styles may be intermixed in a single @command{tar} command,
2141 so long as the rules for each style are fully
2142 respected@footnote{Before @GNUTAR{} version 1.11.6,
2143 a bug prevented intermixing old style options with mnemonic options in
2144 some cases.}. Old style options and either of the modern styles of
2145 options may be mixed within a single @command{tar} command. However,
2146 old style options must be introduced as the first arguments only,
2147 following the rule for old options (old options must appear directly
2148 after the @command{tar} command and some white space). Modern options
2149 may be given only after all arguments to the old options have been
2150 collected. If this rule is not respected, a modern option might be
2151 falsely interpreted as the value of the argument to one of the old
2152 style options.
2153
2154 For example, all the following commands are wholly equivalent, and
2155 illustrate the many combinations and orderings of option styles.
2156
2157 @smallexample
2158 @kbd{tar --create --file=archive.tar}
2159 @kbd{tar --create -f archive.tar}
2160 @kbd{tar --create -farchive.tar}
2161 @kbd{tar --file=archive.tar --create}
2162 @kbd{tar --file=archive.tar -c}
2163 @kbd{tar -c --file=archive.tar}
2164 @kbd{tar -c -f archive.tar}
2165 @kbd{tar -c -farchive.tar}
2166 @kbd{tar -cf archive.tar}
2167 @kbd{tar -cfarchive.tar}
2168 @kbd{tar -f archive.tar --create}
2169 @kbd{tar -f archive.tar -c}
2170 @kbd{tar -farchive.tar --create}
2171 @kbd{tar -farchive.tar -c}
2172 @kbd{tar c --file=archive.tar}
2173 @kbd{tar c -f archive.tar}
2174 @kbd{tar c -farchive.tar}
2175 @kbd{tar cf archive.tar}
2176 @kbd{tar f archive.tar --create}
2177 @kbd{tar f archive.tar -c}
2178 @kbd{tar fc archive.tar}
2179 @end smallexample
2180
2181 On the other hand, the following commands are @emph{not} equivalent to
2182 the previous set:
2183
2184 @smallexample
2185 @kbd{tar -f -c archive.tar}
2186 @kbd{tar -fc archive.tar}
2187 @kbd{tar -fcarchive.tar}
2188 @kbd{tar -farchive.tarc}
2189 @kbd{tar cfarchive.tar}
2190 @end smallexample
2191
2192 @noindent
2193 These last examples mean something completely different from what the
2194 user intended (judging based on the example in the previous set which
2195 uses long options, whose intent is therefore very clear). The first
2196 four specify that the @command{tar} archive would be a file named
2197 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2198 respectively. The first two examples also specify a single non-option,
2199 @var{name} argument having the value @samp{archive.tar}. The last
2200 example contains only old style option letters (repeating option
2201 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2202 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2203 the first sentence of this paragraph..}
2204
2205 @node All Options
2206 @section All @command{tar} Options
2207
2208 The coming manual sections contain an alphabetical listing of all
2209 @command{tar} operations and options, with brief descriptions and cross
2210 references to more in-depth explanations in the body of the manual.
2211 They also contain an alphabetically arranged table of the short option
2212 forms with their corresponding long option. You can use this table as
2213 a reference for deciphering @command{tar} commands in scripts.
2214
2215 @menu
2216 * Operation Summary::
2217 * Option Summary::
2218 * Short Option Summary::
2219 @end menu
2220
2221 @node Operation Summary
2222 @subsection Operations
2223
2224 @table @option
2225
2226 @opindex append, summary
2227 @item --append
2228 @itemx -r
2229
2230 Appends files to the end of the archive. @xref{append}.
2231
2232 @opindex catenate, summary
2233 @item --catenate
2234 @itemx -A
2235
2236 Same as @option{--concatenate}. @xref{concatenate}.
2237
2238 @opindex compare, summary
2239 @item --compare
2240 @itemx -d
2241
2242 Compares archive members with their counterparts in the file
2243 system, and reports differences in file size, mode, owner,
2244 modification date and contents. @xref{compare}.
2245
2246 @opindex concatenate, summary
2247 @item --concatenate
2248 @itemx -A
2249
2250 Appends other @command{tar} archives to the end of the archive.
2251 @xref{concatenate}.
2252
2253 @opindex create, summary
2254 @item --create
2255 @itemx -c
2256
2257 Creates a new @command{tar} archive. @xref{create}.
2258
2259 @opindex delete, summary
2260 @item --delete
2261
2262 Deletes members from the archive. Don't try this on a archive on a
2263 tape! @xref{delete}.
2264
2265 @opindex diff, summary
2266 @item --diff
2267 @itemx -d
2268
2269 Same @option{--compare}. @xref{compare}.
2270
2271 @opindex extract, summary
2272 @item --extract
2273 @itemx -x
2274
2275 Extracts members from the archive into the file system. @xref{extract}.
2276
2277 @opindex get, summary
2278 @item --get
2279 @itemx -x
2280
2281 Same as @option{--extract}. @xref{extract}.
2282
2283 @opindex list, summary
2284 @item --list
2285 @itemx -t
2286
2287 Lists the members in an archive. @xref{list}.
2288
2289 @opindex update, summary
2290 @item --update
2291 @itemx -u
2292
2293 Adds files to the end of the archive, but only if they are newer than
2294 their counterparts already in the archive, or if they do not already
2295 exist in the archive. @xref{update}.
2296
2297 @end table
2298
2299 @node Option Summary
2300 @subsection @command{tar} Options
2301
2302 @table @option
2303
2304 @opindex absolute-names, summary
2305 @item --absolute-names
2306 @itemx -P
2307
2308 Normally when creating an archive, @command{tar} strips an initial
2309 @samp{/} from member names. This option disables that behavior.
2310 @xref{absolute}.
2311
2312 @opindex after-date, summary
2313 @item --after-date
2314
2315 (See @option{--newer}, @pxref{after})
2316
2317 @opindex anchored, summary
2318 @item --anchored
2319 A pattern must match an initial subsequence of the name's components.
2320 @xref{controlling pattern-matching}.
2321
2322 @opindex atime-preserve, summary
2323 @item --atime-preserve
2324 @itemx --atime-preserve=replace
2325 @itemx --atime-preserve=system
2326
2327 Attempt to preserve the access time of files when reading them. This
2328 option currently is effective only on files that you own, unless you
2329 have superuser privileges.
2330
2331 @option{--atime-preserve=replace} remembers the access time of a file
2332 before reading it, and then restores the access time afterwards. This
2333 may cause problems if other programs are reading the file at the same
2334 time, as the times of their accesses will be lost. On most platforms
2335 restoring the access time also requires @command{tar} to restore the
2336 data modification time too, so this option may also cause problems if
2337 other programs are writing the file at the same time. (Tar attempts
2338 to detect this situation, but cannot do so reliably due to race
2339 conditions.) Worse, on most platforms restoring the access time also
2340 updates the status change time, which means that this option is
2341 incompatible with incremental backups.
2342
2343 @option{--atime-preserve=system} avoids changing time stamps on files,
2344 without interfering with time stamp updates
2345 caused by other programs, so it works better with incremental backups.
2346 However, it requires a special @code{O_NOATIME} option from the
2347 underlying operating and file system implementation, and it also requires
2348 that searching directories does not update their access times. As of
2349 this writing (November 2005) this works only with Linux, and only with
2350 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2351 way to know whether this feature actually works. Sometimes
2352 @command{tar} knows that it does not work, and if you use
2353 @option{--atime-preserve=system} then @command{tar} complains and
2354 exits right away. But other times @command{tar} might think that the
2355 option works when it actually does not.
2356
2357 Currently @option{--atime-preserve} with no operand defaults to
2358 @option{--atime-preserve=replace}, but this may change in the future
2359 as support for @option{--atime-preserve=system} improves.
2360
2361 If your operating system does not support
2362 @option{--atime-preserve=system}, you might be able to preserve access
2363 times reliably by by using the @command{mount} command. For example,
2364 you can mount the file system read-only, or access the file system via
2365 a read-only loopback mount, or use the @samp{noatime} mount option
2366 available on some systems. However, mounting typically requires
2367 superuser privileges and can be a pain to manage.
2368
2369 @opindex backup, summary
2370 @item --backup=@var{backup-type}
2371
2372 Rather than deleting files from the file system, @command{tar} will
2373 back them up using simple or numbered backups, depending upon
2374 @var{backup-type}. @xref{backup}.
2375
2376 @opindex block-number, summary
2377 @item --block-number
2378 @itemx -R
2379
2380 With this option present, @command{tar} prints error messages for read errors
2381 with the block number in the archive file. @xref{block-number}.
2382
2383 @opindex blocking-factor, summary
2384 @item --blocking-factor=@var{blocking}
2385 @itemx -b @var{blocking}
2386
2387 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2388 record. @xref{Blocking Factor}.
2389
2390 @opindex bzip2, summary
2391 @item --bzip2
2392 @itemx -j
2393
2394 This option tells @command{tar} to read or write archives through
2395 @code{bzip2}. @xref{gzip}.
2396
2397 @opindex checkpoint, summary
2398 @item --checkpoint[=@var{number}]
2399
2400 This option directs @command{tar} to print periodic checkpoint
2401 messages as it reads through the archive. It is intended for when you
2402 want a visual indication that @command{tar} is still running, but
2403 don't want to see @option{--verbose} output. For a detailed
2404 description, see @ref{Progress information}.
2405
2406 @opindex check-links, summary
2407 @item --check-links
2408 @itemx -l
2409 If this option was given, @command{tar} will check the number of links
2410 dumped for each processed file. If this number does not match the
2411 total number of hard links for the file, a warning message will be
2412 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2413 synonym for @option{--one-file-system}. The current semantics, which
2414 complies to UNIX98, was introduced with version
2415 1.15.91. @xref{Changes}, for more information.}.
2416
2417 @opindex compress, summary
2418 @opindex uncompress, summary
2419 @item --compress
2420 @itemx --uncompress
2421 @itemx -Z
2422
2423 @command{tar} will use the @command{compress} program when reading or
2424 writing the archive. This allows you to directly act on archives
2425 while saving space. @xref{gzip}.
2426
2427 @opindex confirmation, summary
2428 @item --confirmation
2429
2430 (See @option{--interactive}.) @xref{interactive}.
2431
2432 @opindex delay-directory-restore, summary
2433 @item --delay-directory-restore
2434
2435 Delay setting modification times and permissions of extracted
2436 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2437
2438 @opindex dereference, summary
2439 @item --dereference
2440 @itemx -h
2441
2442 When creating a @command{tar} archive, @command{tar} will archive the
2443 file that a symbolic link points to, rather than archiving the
2444 symlink. @xref{dereference}.
2445
2446 @opindex directory, summary
2447 @item --directory=@var{dir}
2448 @itemx -C @var{dir}
2449
2450 When this option is specified, @command{tar} will change its current directory
2451 to @var{dir} before performing any operations. When this option is used
2452 during archive creation, it is order sensitive. @xref{directory}.
2453
2454 @opindex exclude, summary
2455 @item --exclude=@var{pattern}
2456
2457 When performing operations, @command{tar} will skip files that match
2458 @var{pattern}. @xref{exclude}.
2459
2460 @opindex exclude-from, summary
2461 @item --exclude-from=@var{file}
2462 @itemx -X @var{file}
2463
2464 Similar to @option{--exclude}, except @command{tar} will use the list of
2465 patterns in the file @var{file}. @xref{exclude}.
2466
2467 @opindex exclude-caches, summary
2468 @item --exclude-caches
2469
2470 Automatically excludes all directories
2471 containing a cache directory tag. @xref{exclude}.
2472
2473 @opindex file, summary
2474 @item --file=@var{archive}
2475 @itemx -f @var{archive}
2476
2477 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2478 performs operations on, rather than @command{tar}'s compilation dependent
2479 default. @xref{file tutorial}.
2480
2481 @opindex files-from, summary
2482 @item --files-from=@var{file}
2483 @itemx -T @var{file}
2484
2485 @command{tar} will use the contents of @var{file} as a list of archive members
2486 or files to operate on, in addition to those specified on the
2487 command-line. @xref{files}.
2488
2489 @opindex force-local, summary
2490 @item --force-local
2491
2492 Forces @command{tar} to interpret the filename given to @option{--file}
2493 as a local file, even if it looks like a remote tape drive name.
2494 @xref{local and remote archives}.
2495
2496 @opindex format, summary
2497 @item --format=@var{format}
2498
2499 Selects output archive format. @var{Format} may be one of the
2500 following:
2501
2502 @table @samp
2503 @item v7
2504 Creates an archive that is compatible with Unix V7 @command{tar}.
2505
2506 @item oldgnu
2507 Creates an archive that is compatible with GNU @command{tar} version
2508 1.12 or earlier.
2509
2510 @item gnu
2511 Creates archive in GNU tar 1.13 format. Basically it is the same as
2512 @samp{oldgnu} with the only difference in the way it handles long
2513 numeric fields.
2514
2515 @item ustar
2516 Creates a @acronym{POSIX.1-1988} compatible archive.
2517
2518 @item posix
2519 Creates a @acronym{POSIX.1-2001 archive}.
2520
2521 @end table
2522
2523 @xref{Formats}, for a detailed discussion of these formats.
2524
2525 @opindex group, summary
2526 @item --group=@var{group}
2527
2528 Files added to the @command{tar} archive will have a group id of @var{group},
2529 rather than the group from the source file. @var{group} is first decoded
2530 as a group symbolic name, but if this interpretation fails, it has to be
2531 a decimal numeric group ID. @FIXME-xref{}
2532
2533 Also see the comments for the @option{--owner=@var{user}} option.
2534
2535 @opindex gzip, summary
2536 @opindex gunzip, summary
2537 @opindex ungzip, summary
2538 @item --gzip
2539 @itemx --gunzip
2540 @itemx --ungzip
2541 @itemx -z
2542
2543 This option tells @command{tar} to read or write archives through
2544 @command{gzip}, allowing @command{tar} to directly operate on several
2545 kinds of compressed archives transparently. @xref{gzip}.
2546
2547 @opindex help, summary
2548 @item --help
2549
2550 @command{tar} will print out a short message summarizing the operations and
2551 options to @command{tar} and exit. @xref{help}.
2552
2553 @opindex ignore-case, summary
2554 @item --ignore-case
2555 Ignore case when matching member or file names with
2556 patterns. @xref{controlling pattern-matching}.
2557
2558 @opindex ignore-command-error, summary
2559 @item --ignore-command-error
2560 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2561
2562 @opindex ignore-failed-read, summary
2563 @item --ignore-failed-read
2564
2565 Do not exit unsuccessfully merely because an unreadable file was encountered.
2566 @xref{Reading}.
2567
2568 @opindex ignore-zeros, summary
2569 @item --ignore-zeros
2570 @itemx -i
2571
2572 With this option, @command{tar} will ignore zeroed blocks in the
2573 archive, which normally signals EOF. @xref{Reading}.
2574
2575 @opindex incremental, summary
2576 @item --incremental
2577 @itemx -G
2578
2579 Used to inform @command{tar} that it is working with an old
2580 @acronym{GNU}-format incremental backup archive. It is intended
2581 primarily for backwards compatibility only. @xref{Incremental Dumps},
2582 for a detailed discussion of incremental archives.
2583
2584 @opindex index-file, summary
2585 @item --index-file=@var{file}
2586
2587 Send verbose output to @var{file} instead of to standard output.
2588
2589 @opindex info-script, summary
2590 @opindex new-volume-script, summary
2591 @item --info-script=@var{script-file}
2592 @itemx --new-volume-script=@var{script-file}
2593 @itemx -F @var{script-file}
2594
2595 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2596 at the end of each tape. If @var{script-file} exits with nonzero status,
2597 @command{tar} fails immediately. @xref{info-script}, for a detailed
2598 discussion of @var{script-file}.
2599
2600 @opindex interactive, summary
2601 @item --interactive
2602 @itemx --confirmation
2603 @itemx -w
2604
2605 Specifies that @command{tar} should ask the user for confirmation before
2606 performing potentially destructive options, such as overwriting files.
2607 @xref{interactive}.
2608
2609 @opindex keep-newer-files, summary
2610 @item --keep-newer-files
2611
2612 Do not replace existing files that are newer than their archive copies
2613 when extracting files from an archive.
2614
2615 @opindex keep-old-files, summary
2616 @item --keep-old-files
2617 @itemx -k
2618
2619 Do not overwrite existing files when extracting files from an archive.
2620 @xref{Keep Old Files}.
2621
2622 @opindex label, summary
2623 @item --label=@var{name}
2624 @itemx -V @var{name}
2625
2626 When creating an archive, instructs @command{tar} to write @var{name}
2627 as a name record in the archive. When extracting or listing archives,
2628 @command{tar} will only operate on archives that have a label matching
2629 the pattern specified in @var{name}. @xref{Tape Files}.
2630
2631 @opindex listed-incremental, summary
2632 @item --listed-incremental=@var{snapshot-file}
2633 @itemx -g @var{snapshot-file}
2634
2635 During a @option{--create} operation, specifies that the archive that
2636 @command{tar} creates is a new @acronym{GNU}-format incremental
2637 backup, using @var{snapshot-file} to determine which files to backup.
2638 With other operations, informs @command{tar} that the archive is in
2639 incremental format. @xref{Incremental Dumps}.
2640
2641 @opindex mode, summary
2642 @item --mode=@var{permissions}
2643
2644 When adding files to an archive, @command{tar} will use
2645 @var{permissions} for the archive members, rather than the permissions
2646 from the files. The program @command{chmod} and this @command{tar}
2647 option share the same syntax for what @var{permissions} might be.
2648 @xref{File permissions, Permissions, File permissions, fileutils,
2649 @acronym{GNU} file utilities}. This reference also has useful
2650 information for those not being overly familiar with the Unix
2651 permission system.
2652
2653 Of course, @var{permissions} might be plainly specified as an octal number.
2654 However, by using generic symbolic modifications to mode bits, this allows
2655 more flexibility. For example, the value @samp{a+rw} adds read and write
2656 permissions for everybody, while retaining executable bits on directories
2657 or on any other file already marked as executable.
2658
2659 @opindex multi-volume, summary
2660 @item --multi-volume
2661 @itemx -M
2662
2663 Informs @command{tar} that it should create or otherwise operate on a
2664 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2665
2666 @opindex new-volume-script, summary
2667 @item --new-volume-script
2668
2669 (see --info-script)
2670
2671 @opindex seek, summary
2672 @item --seek
2673 @itemx -n
2674
2675 Assume that the archive media supports seeks to arbitrary
2676 locations. Usually @command{tar} determines automatically whether
2677 the archive can be seeked or not. This option is intended for use
2678 in cases when such recognition fails.
2679
2680 @opindex newer, summary
2681 @item --newer=@var{date}
2682 @itemx --after-date=@var{date}
2683 @itemx -N
2684
2685 When creating an archive, @command{tar} will only add files that have changed
2686 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2687 is taken to be the name of a file whose data modification time specifies
2688 the date. @xref{after}.
2689
2690 @opindex newer-mtime, summary
2691 @item --newer-mtime=@var{date}
2692
2693 Like @option{--newer}, but add only files whose
2694 contents have changed (as opposed to just @option{--newer}, which will
2695 also back up files for which any status information has changed).
2696
2697 @opindex no-anchored, summary
2698 @item --no-anchored
2699 An exclude pattern can match any subsequence of the name's components.
2700 @xref{controlling pattern-matching}.
2701
2702 @opindex no-delay-directory-restore, summary
2703 @item --no-delay-directory-restore
2704
2705 Setting modification times and permissions of extracted
2706 directories when all files from this directory has been
2707 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2708
2709 @opindex no-ignore-case, summary
2710 @item --no-ignore-case
2711 Use case-sensitive matching.
2712 @xref{controlling pattern-matching}.
2713
2714 @opindex no-ignore-command-error, summary
2715 @item --no-ignore-command-error
2716 Print warnings about subprocesses terminated with a non-zero exit
2717 code. @xref{Writing to an External Program}.
2718
2719 @opindex no-quote-chars, summary
2720 @item --no-quote-chars=@var{string}
2721 Remove characters listed in @var{string} from the list of quoted
2722 characters set by the previous @option{--quote-chars} option
2723 (@pxref{quoting styles}).
2724
2725 @opindex no-recursion, summary
2726 @item --no-recursion
2727
2728 With this option, @command{tar} will not recurse into directories.
2729 @xref{recurse}.
2730
2731 @opindex no-same-owner, summary
2732 @item --no-same-owner
2733 @itemx -o
2734
2735 When extracting an archive, do not attempt to preserve the owner
2736 specified in the @command{tar} archive. This the default behavior
2737 for ordinary users.
2738
2739 @opindex no-same-permissions, summary
2740 @item --no-same-permissions
2741
2742 When extracting an archive, subtract the user's umask from files from
2743 the permissions specified in the archive. This is the default behavior
2744 for ordinary users.
2745
2746 @opindex no-wildcards, summary
2747 @item --no-wildcards
2748 Do not use wildcards.
2749 @xref{controlling pattern-matching}.
2750
2751 @opindex no-wildcards-match-slash, summary
2752 @item --no-wildcards-match-slash
2753 Wildcards do not match @samp{/}.
2754 @xref{controlling pattern-matching}.
2755
2756 @opindex null, summary
2757 @item --null
2758
2759 When @command{tar} is using the @option{--files-from} option, this option
2760 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2761 @command{tar} can correctly work with file names that contain newlines.
2762 @xref{nul}.
2763
2764 @opindex numeric-owner, summary
2765 @item --numeric-owner
2766
2767 This option will notify @command{tar} that it should use numeric user
2768 and group IDs when creating a @command{tar} file, rather than names.
2769 @xref{Attributes}.
2770
2771 @item -o
2772 When extracting files, this option is a synonym for
2773 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2774 restoring ownership of files being extracted.
2775
2776 When creating an archive, @option{-o} is a synonym for
2777 @option{--old-archive}. This behavior is for compatibility
2778 with previous versions of @GNUTAR{}, and will be
2779 removed in the future releases.
2780
2781 @xref{Changes}, for more information.
2782
2783 @opindex occurrence, summary
2784 @item --occurrence[=@var{number}]
2785
2786 This option can be used in conjunction with one of the subcommands
2787 @option{--delete}, @option{--diff}, @option{--extract} or
2788 @option{--list} when a list of files is given either on the command
2789 line or via @option{-T} option.
2790
2791 This option instructs @command{tar} to process only the @var{number}th
2792 occurrence of each named file. @var{Number} defaults to 1, so
2793
2794 @smallexample
2795 tar -x -f archive.tar --occurrence filename
2796 @end smallexample
2797
2798 @noindent
2799 will extract the first occurrence of @file{filename} from @file{archive.tar}
2800 and will terminate without scanning to the end of the archive.
2801
2802 @opindex old-archive, summary
2803 @item --old-archive
2804 Synonym for @option{--format=v7}.
2805
2806 @opindex one-file-system, summary
2807 @item --one-file-system
2808 Used when creating an archive. Prevents @command{tar} from recursing into
2809 directories that are on different file systems from the current
2810 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2811 synonym for @option{--one-file-system}. This has changed in version
2812 1.15.91. @xref{Changes}, for more information.}.
2813
2814 @opindex overwrite, summary
2815 @item --overwrite
2816
2817 Overwrite existing files and directory metadata when extracting files
2818 from an archive. @xref{Overwrite Old Files}.
2819
2820 @opindex overwrite-dir, summary
2821 @item --overwrite-dir
2822
2823 Overwrite the metadata of existing directories when extracting files
2824 from an archive. @xref{Overwrite Old Files}.
2825
2826 @opindex owner, summary
2827 @item --owner=@var{user}
2828
2829 Specifies that @command{tar} should use @var{user} as the owner of members
2830 when creating archives, instead of the user associated with the source
2831 file. @var{user} is first decoded as a user symbolic name, but if
2832 this interpretation fails, it has to be a decimal numeric user ID.
2833 @FIXME-xref{}
2834
2835 There is no value indicating a missing number, and @samp{0} usually means
2836 @code{root}. Some people like to force @samp{0} as the value to offer in
2837 their distributions for the owner of files, because the @code{root} user is
2838 anonymous anyway, so that might as well be the owner of anonymous archives.
2839
2840 This option does not affect extraction from archives.
2841
2842 @opindex transform, summary
2843 @item --transform=@var{sed-expr}
2844
2845 Transform file or member names using @command{sed} replacement expression
2846 @var{sed-expr}. For example,
2847
2848 @smallexample
2849 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2850 @end smallexample
2851
2852 @noindent
2853 will add to @file{archive} files from the current working directory,
2854 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2855 discussion, @xref{transform}.
2856
2857 To see transformed member names in verbose listings, use
2858 @option{--show-transformed-names} option
2859 (@pxref{show-transformed-names}).
2860
2861 @opindex quote-chars, summary
2862 @item --quote-chars=@var{string}
2863 Always quote characters from @var{string}, even if the selected
2864 quoting style would not quote them (@pxref{quoting styles}).
2865
2866 @opindex quoting-style, summary
2867 @item --quoting-style=@var{style}
2868 Set quoting style to use when printing member and file names
2869 (@pxref{quoting styles}). Valid @var{style} values are:
2870 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2871 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2872 style is @code{escape}, unless overridden while configuring the
2873 package.
2874
2875 @opindex pax-option, summary
2876 @item --pax-option=@var{keyword-list}
2877 This option is meaningful only with @acronym{POSIX.1-2001} archives
2878 (@pxref{posix}). It modifies the way @command{tar} handles the
2879 extended header keywords. @var{Keyword-list} is a comma-separated
2880 list of keyword options. @xref{PAX keywords}, for a detailed
2881 discussion.
2882
2883 @opindex portability, summary
2884 @item --portability
2885 @itemx --old-archive
2886 Synonym for @option{--format=v7}.
2887
2888 @opindex posix, summary
2889 @item --posix
2890 Same as @option{--format=posix}.
2891
2892 @opindex preserve, summary
2893 @item --preserve
2894
2895 Synonymous with specifying both @option{--preserve-permissions} and
2896 @option{--same-order}. @xref{Setting Access Permissions}.
2897
2898 @opindex preserve-order, summary
2899 @item --preserve-order
2900
2901 (See @option{--same-order}; @pxref{Reading}.)
2902
2903 @opindex preserve-permissions, summary
2904 @opindex same-permissions, summary
2905 @item --preserve-permissions
2906 @itemx --same-permissions
2907 @itemx -p
2908
2909 When @command{tar} is extracting an archive, it normally subtracts the
2910 users' umask from the permissions specified in the archive and uses
2911 that number as the permissions to create the destination file.
2912 Specifying this option instructs @command{tar} that it should use the
2913 permissions directly from the archive. @xref{Setting Access Permissions}.
2914
2915 @opindex read-full-records, summary
2916 @item --read-full-records
2917 @itemx -B
2918
2919 Specifies that @command{tar} should reblock its input, for reading
2920 from pipes on systems with buggy implementations. @xref{Reading}.
2921
2922 @opindex record-size, summary
2923 @item --record-size=@var{size}
2924
2925 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2926 archive. @xref{Blocking Factor}.
2927
2928 @opindex recursion, summary
2929 @item --recursion
2930
2931 With this option, @command{tar} recurses into directories.
2932 @xref{recurse}.
2933
2934 @opindex recursive-unlink, summary
2935 @item --recursive-unlink
2936
2937 Remove existing
2938 directory hierarchies before extracting directories of the same name
2939 from the archive. @xref{Recursive Unlink}.
2940
2941 @opindex remove-files, summary
2942 @item --remove-files
2943
2944 Directs @command{tar} to remove the source file from the file system after
2945 appending it to an archive. @xref{remove files}.
2946
2947 @opindex restrict, summary
2948 @item --restrict
2949
2950 Disable use of some potentially harmful @command{tar} options.
2951 Currently this option disables shell invocaton from multi-volume menu
2952 (@pxref{Using Multiple Tapes}).
2953
2954 @opindex rmt-command, summary
2955 @item --rmt-command=@var{cmd}
2956
2957 Notifies @command{tar} that it should use @var{cmd} instead of
2958 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2959
2960 @opindex rsh-command, summary
2961 @item --rsh-command=@var{cmd}
2962
2963 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2964 devices. @xref{Device}.
2965
2966 @opindex same-order, summary
2967 @item --same-order
2968 @itemx --preserve-order
2969 @itemx -s
2970
2971 This option is an optimization for @command{tar} when running on machines with
2972 small amounts of memory. It informs @command{tar} that the list of file
2973 arguments has already been sorted to match the order of files in the
2974 archive. @xref{Reading}.
2975
2976 @opindex same-owner, summary
2977 @item --same-owner
2978
2979 When extracting an archive, @command{tar} will attempt to preserve the owner
2980 specified in the @command{tar} archive with this option present.
2981 This is the default behavior for the superuser; this option has an
2982 effect only for ordinary users. @xref{Attributes}.
2983
2984 @opindex same-permissions, summary
2985 @item --same-permissions
2986
2987 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
2988
2989 @opindex show-defaults, summary
2990 @item --show-defaults
2991
2992 Displays the default options used by @command{tar} and exits
2993 successfully. This option is intended for use in shell scripts.
2994 Here is an example of what you can see using this option:
2995
2996 @smallexample
2997 $ tar --show-defaults
2998 --format=gnu -f- -b20 --quoting-style=escape \
2999 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3000 @end smallexample
3001
3002 @opindex show-omitted-dirs, summary
3003 @item --show-omitted-dirs
3004
3005 Instructs @command{tar} to mention directories its skipping over when
3006 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3007
3008 @opindex show-transformed-names, summary
3009 @opindex show-stored-names, summary
3010 @item --show-transformed-names
3011 @itemx --show-stored-names
3012
3013 Display file or member names after applying any transformations
3014 (@pxref{transform}). In particular, when used in conjunction with one of
3015 archive creation operations it instructs tar to list the member names
3016 stored in the archive, as opposed to the actual file
3017 names. @xref{listing member and file names}.
3018
3019 @opindex sparse, summary
3020 @item --sparse
3021 @itemx -S
3022
3023 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3024 sparse files efficiently. @xref{sparse}.
3025
3026 @opindex starting-file, summary
3027 @item --starting-file=@var{name}
3028 @itemx -K @var{name}
3029
3030 This option affects extraction only; @command{tar} will skip extracting
3031 files in the archive until it finds one that matches @var{name}.
3032 @xref{Scarce}.
3033
3034 @opindex strip-components, summary
3035 @item --strip-components=@var{number}
3036 Strip given @var{number} of leading components from file names before
3037 extraction.@footnote{This option was called @option{--strip-path} in
3038 version 1.14.} For example, if archive @file{archive.tar} contained
3039 @file{/some/file/name}, then running
3040
3041 @smallexample
3042 tar --extract --file archive.tar --strip-components=2
3043 @end smallexample
3044
3045 @noindent
3046 would extract this file to file @file{name}.
3047
3048 @opindex suffix, summary
3049 @item --suffix=@var{suffix}
3050
3051 Alters the suffix @command{tar} uses when backing up files from the default
3052 @samp{~}. @xref{backup}.
3053
3054 @opindex tape-length, summary
3055 @item --tape-length=@var{num}
3056 @itemx -L @var{num}
3057
3058 Specifies the length of tapes that @command{tar} is writing as being
3059 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3060
3061 @opindex test-label, summary
3062 @item --test-label
3063
3064 Reads the volume label. If an argument is specified, test whether it
3065 matches the volume label. @xref{--test-label option}.
3066
3067 @opindex to-command, summary
3068 @item --to-command=@var{command}
3069
3070 During extraction @command{tar} will pipe extracted files to the
3071 standard input of @var{command}. @xref{Writing to an External Program}.
3072
3073 @opindex to-stdout, summary
3074 @item --to-stdout
3075 @itemx -O
3076
3077 During extraction, @command{tar} will extract files to stdout rather
3078 than to the file system. @xref{Writing to Standard Output}.
3079
3080 @opindex totals, summary
3081 @item --totals
3082
3083 Displays the total number of bytes written after creating an archive.
3084 @xref{verbose}.
3085
3086 @opindex touch, summary
3087 @item --touch
3088 @itemx -m
3089
3090 Sets the data modification time of extracted files to the extraction time,
3091 rather than the data modification time stored in the archive.
3092 @xref{Data Modification Times}.
3093
3094 @opindex uncompress, summary
3095 @item --uncompress
3096
3097 (See @option{--compress}. @pxref{gzip})
3098
3099 @opindex ungzip, summary
3100 @item --ungzip
3101
3102 (See @option{--gzip}. @pxref{gzip})
3103
3104 @opindex unlink-first, summary
3105 @item --unlink-first
3106 @itemx -U
3107
3108 Directs @command{tar} to remove the corresponding file from the file
3109 system before extracting it from the archive. @xref{Unlink First}.
3110
3111 @opindex use-compress-program, summary
3112 @item --use-compress-program=@var{prog}
3113
3114 Instructs @command{tar} to access the archive through @var{prog}, which is
3115 presumed to be a compression program of some sort. @xref{gzip}.
3116
3117 @opindex utc, summary
3118 @item --utc
3119
3120 Display file modification dates in @acronym{UTC}. This option implies
3121 @option{--verbose}.
3122
3123 @opindex verbose, summary
3124 @item --verbose
3125 @itemx -v
3126
3127 Specifies that @command{tar} should be more verbose about the operations its
3128 performing. This option can be specified multiple times for some
3129 operations to increase the amount of information displayed.
3130 @xref{verbose}.
3131
3132 @opindex verify, summary
3133 @item --verify
3134 @itemx -W
3135
3136 Verifies that the archive was correctly written when creating an
3137 archive. @xref{verify}.
3138
3139 @opindex version, summary
3140 @item --version
3141
3142 Print information about the program's name, version, origin and legal
3143 status, all on standard output, and then exit successfully.
3144 @xref{help}.
3145
3146 @opindex volno-file, summary
3147 @item --volno-file=@var{file}
3148
3149 Used in conjunction with @option{--multi-volume}. @command{tar} will keep track
3150 of which volume of a multi-volume archive its working in @var{file}.
3151 @xref{volno-file}.
3152
3153 @opindex wildcards, summary
3154 @item --wildcards
3155 Use wildcards when matching member names with patterns.
3156 @xref{controlling pattern-matching}.
3157
3158 @opindex wildcards-match-slash, summary
3159 @item --wildcards-match-slash
3160 Wildcards match @samp{/}.
3161 @xref{controlling pattern-matching}.
3162 @end table
3163
3164 @node Short Option Summary
3165 @subsection Short Options Cross Reference
3166
3167 Here is an alphabetized list of all of the short option forms, matching
3168 them with the equivalent long option.
3169
3170 @table @option
3171
3172 @item -A
3173
3174 @option{--concatenate}
3175
3176 @item -B
3177
3178 @option{--read-full-records}
3179
3180 @item -C
3181
3182 @option{--directory}
3183
3184 @item -F
3185
3186 @option{--info-script}
3187
3188 @item -G
3189
3190 @option{--incremental}
3191
3192 @item -K
3193
3194 @option{--starting-file}
3195
3196 @item -L
3197
3198 @option{--tape-length}
3199
3200 @item -M
3201
3202 @option{--multi-volume}
3203
3204 @item -N
3205
3206 @option{--newer}
3207
3208 @item -O
3209
3210 @option{--to-stdout}
3211
3212 @item -P
3213
3214 @option{--absolute-names}
3215
3216 @item -R
3217
3218 @option{--block-number}
3219
3220 @item -S
3221
3222 @option{--sparse}
3223
3224 @item -T
3225
3226 @option{--files-from}
3227
3228 @item -U
3229
3230 @option{--unlink-first}
3231
3232 @item -V
3233
3234 @option{--label}
3235
3236 @item -W
3237
3238 @option{--verify}
3239
3240 @item -X
3241
3242 @option{--exclude-from}
3243
3244 @item -Z
3245
3246 @option{--compress}
3247
3248 @item -b
3249
3250 @option{--blocking-factor}
3251
3252 @item -c
3253
3254 @option{--create}
3255
3256 @item -d
3257
3258 @option{--compare}
3259
3260 @item -f
3261
3262 @option{--file}
3263
3264 @item -g
3265
3266 @option{--listed-incremental}
3267
3268 @item -h
3269
3270 @option{--dereference}
3271
3272 @item -i
3273
3274 @option{--ignore-zeros}
3275
3276 @item -j
3277
3278 @option{--bzip2}
3279
3280 @item -k
3281
3282 @option{--keep-old-files}
3283
3284 @item -l
3285
3286 @option{--one-file-system}. Use of this short option is deprecated. It
3287 is retained for compatibility with the earlier versions of GNU
3288 @command{tar}, and will be changed in future releases.
3289
3290 @xref{Changes}, for more information.
3291
3292 @item -m
3293
3294 @option{--touch}
3295
3296 @item -o
3297
3298 When creating --- @option{--no-same-owner}, when extracting ---
3299 @option{--portability}.
3300
3301 The later usage is deprecated. It is retained for compatibility with
3302 the earlier versions of @GNUTAR{}. In the future releases
3303 @option{-o} will be equivalent to @option{--no-same-owner} only.
3304
3305 @item -p
3306
3307 @option{--preserve-permissions}
3308
3309 @item -r
3310
3311 @option{--append}
3312
3313 @item -s
3314
3315 @option{--same-order}
3316
3317 @item -t
3318
3319 @option{--list}
3320
3321 @item -u
3322
3323 @option{--update}
3324
3325 @item -v
3326
3327 @option{--verbose}
3328
3329 @item -w
3330
3331 @option{--interactive}
3332
3333 @item -x
3334
3335 @option{--extract}
3336
3337 @item -z
3338
3339 @option{--gzip}
3340
3341 @end table
3342
3343 @node help
3344 @section @GNUTAR{} documentation
3345
3346 @cindex Getting program version number
3347 @opindex version
3348 @cindex Version of the @command{tar} program
3349 Being careful, the first thing is really checking that you are using
3350 @GNUTAR{}, indeed. The @option{--version} option
3351 causes @command{tar} to print information about its name, version,
3352 origin and legal status, all on standard output, and then exit
3353 successfully. For example, @w{@samp{tar --version}} might print:
3354
3355 @smallexample
3356 tar (GNU tar) 1.15.2
3357 Copyright (C) 2006 Free Software Foundation, Inc.
3358 This is free software. You may redistribute copies of it under the terms of
3359 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3360 There is NO WARRANTY, to the extent permitted by law.
3361
3362 Written by John Gilmore and Jay Fenlason.
3363 @end smallexample
3364
3365 @noindent
3366 The first occurrence of @samp{tar} in the result above is the program
3367 name in the package (for example, @command{rmt} is another program),
3368 while the second occurrence of @samp{tar} is the name of the package
3369 itself, containing possibly many programs. The package is currently
3370 named @samp{tar}, after the name of the main program it
3371 contains@footnote{There are plans to merge the @command{cpio} and
3372 @command{tar} packages into a single one which would be called
3373 @code{paxutils}. So, who knows if, one of this days, the
3374 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3375 paxutils) 3.2}}}.
3376
3377 @cindex Obtaining help
3378 @cindex Listing all @command{tar} options
3379 @opindex help, introduction
3380 Another thing you might want to do is checking the spelling or meaning
3381 of some particular @command{tar} option, without resorting to this
3382 manual, for once you have carefully read it. @GNUTAR{}
3383 has a short help feature, triggerable through the
3384 @option{--help} option. By using this option, @command{tar} will
3385 print a usage message listing all available options on standard
3386 output, then exit successfully, without doing anything else and
3387 ignoring all other options. Even if this is only a brief summary, it
3388 may be several screens long. So, if you are not using some kind of
3389 scrollable window, you might prefer to use something like:
3390
3391 @smallexample
3392 $ @kbd{tar --help | less}
3393 @end smallexample
3394
3395 @noindent
3396 presuming, here, that you like using @command{less} for a pager. Other
3397 popular pagers are @command{more} and @command{pg}. If you know about some
3398 @var{keyword} which interests you and do not want to read all the
3399 @option{--help} output, another common idiom is doing:
3400
3401 @smallexample
3402 tar --help | grep @var{keyword}
3403 @end smallexample
3404
3405 @noindent
3406 for getting only the pertinent lines. Notice, however, that some
3407 @command{tar} options have long description lines and the above
3408 command will list only the first of them.
3409
3410 The exact look of the option summary displayed by @kbd{tar --help} is
3411 configurable. @xref{Configuring Help Summary}, for a detailed description.
3412
3413 @opindex usage
3414 If you only wish to check the spelling of an option, running @kbd{tar
3415 --usage} may be a better choice. This will display a terse list of
3416 @command{tar} option without accompanying explanations.
3417
3418 The short help output is quite succinct, and you might have to get
3419 back to the full documentation for precise points. If you are reading
3420 this paragraph, you already have the @command{tar} manual in some
3421 form. This manual is available in a variety of forms from
3422 @url{http://www.gnu.org/software/tar/manual}. It may printed out of the @GNUTAR{}
3423 distribution, provided you have @TeX{} already installed somewhere,
3424 and a laser printer around. Just configure the distribution, execute
3425 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3426 usual way (contact your local guru to know how). If @GNUTAR{}
3427 has been conveniently installed at your place, this
3428 manual is also available in interactive, hypertextual form as an Info
3429 file. Just call @w{@samp{info tar}} or, if you do not have the
3430 @command{info} program handy, use the Info reader provided within
3431 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3432
3433 There is currently no @code{man} page for @GNUTAR{}.
3434 If you observe such a @code{man} page on the system you are running,
3435 either it does not belong to @GNUTAR{}, or it has not
3436 been produced by @acronym{GNU}. Some package maintainers convert
3437 @kbd{tar --help} output to a man page, using @command{help2man}. In
3438 any case, please bear in mind that the authoritative source of
3439 information about @GNUTAR{} is this Texinfo documentation.
3440
3441 @node defaults
3442 @section Obtaining @GNUTAR{} default values
3443
3444 @opindex show-defaults
3445 @GNUTAR{} has some predefined defaults that are used when you do not
3446 explicitely specify another values. To obtain a list of such
3447 defaults, use @option{--show-defaults} option. This will output the
3448 values in the form of @command{tar} command line options:
3449
3450 @smallexample
3451 @group
3452 @kbd{tar --show-defaults}
3453 --format=gnu -f- -b20 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3454 @end group
3455 @end smallexample
3456
3457 @noindent
3458 The above output shows that this version of @GNUTAR{} defaults to
3459 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3460 output as the archive, if no @option{--file} option has been given
3461 (@pxref{file tutorial}), the default blocking factor is 20
3462 (@pxref{Blocking Factor}). It also shows the default locations where
3463 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3464
3465 @node verbose
3466 @section Checking @command{tar} progress
3467
3468 Typically, @command{tar} performs most operations without reporting any
3469 information to the user except error messages. When using @command{tar}
3470 with many options, particularly ones with complicated or
3471 difficult-to-predict behavior, it is possible to make serious mistakes.
3472 @command{tar} provides several options that make observing @command{tar}
3473 easier. These options cause @command{tar} to print information as it
3474 progresses in its job, and you might want to use them just for being
3475 more careful about what is going on, or merely for entertaining
3476 yourself. If you have encountered a problem when operating on an
3477 archive, however, you may need more information than just an error
3478 message in order to solve the problem. The following options can be
3479 helpful diagnostic tools.
3480
3481 @cindex Verbose operation
3482 @opindex verbose
3483 Normally, the @option{--list} (@option{-t}) command to list an archive
3484 prints just the file names (one per line) and the other commands are
3485 silent. When used with most operations, the @option{--verbose}
3486 (@option{-v}) option causes @command{tar} to print the name of each
3487 file or archive member as it is processed. This and the other options
3488 which make @command{tar} print status information can be useful in
3489 monitoring @command{tar}.
3490
3491 With @option{--create} or @option{--extract}, @option{--verbose} used
3492 once just prints the names of the files or members as they are processed.
3493 Using it twice causes @command{tar} to print a longer listing
3494 (reminiscent of @samp{ls -l}) for each member. Since @option{--list}
3495 already prints the names of the members, @option{--verbose} used once
3496 with @option{--list} causes @command{tar} to print an @samp{ls -l}
3497 type listing of the files in the archive. The following examples both
3498 extract members with long list output:
3499
3500 @smallexample
3501 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3502 $ @kbd{tar xvvf archive.tar}
3503 @end smallexample
3504
3505 Verbose output appears on the standard output except when an archive is
3506 being written to the standard output, as with @samp{tar --create
3507 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3508 installer let standard output be the default archive). In that case
3509 @command{tar} writes verbose output to the standard error stream.
3510
3511 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3512 verbose output to @var{file} rather than to standard output or standard
3513 error.
3514
3515 @cindex Obtaining total status information
3516 @opindex totals
3517 The @option{--totals} option---which is only meaningful when used with
3518 @option{--create} (@option{-c})---causes @command{tar} to print the total
3519 amount written to the archive, after it has been fully created.
3520
3521 @anchor{Progress information}
3522 @cindex Progress information
3523 @opindex checkpoint
3524 The @option{--checkpoint} option prints an occasional message
3525 as @command{tar} reads or writes the archive. It is designed for
3526 those who don't need the more detailed (and voluminous) output of
3527 @option{--block-number} (@option{-R}), but do want visual confirmation
3528 that @command{tar} is actually making forward progress. By default it
3529 prints a message each 10 records read or written. This can be changed
3530 by giving it a numeric argument after an equal sign:
3531
3532 @smallexample
3533 $ @kbd{tar -c --checkpoint=1000} /var
3534 tar: Write checkpoint 1000
3535 tar: Write checkpoint 2000
3536 tar: Write checkpoint 3000
3537 @end smallexample
3538
3539 This example shows the default checkpoint message used by
3540 @command{tar}. If you place a dot immediately after the equal
3541 sign, it will print a @samp{.} at each checkpoint. For example:
3542
3543 @smallexample
3544 $ @kbd{tar -c --checkpoint=.1000} /var
3545 ...
3546 @end smallexample
3547
3548 @opindex show-omitted-dirs
3549 @anchor{show-omitted-dirs}
3550 The @option{--show-omitted-dirs} option, when reading an archive---with
3551 @option{--list} or @option{--extract}, for example---causes a message
3552 to be printed for each directory in the archive which is skipped.
3553 This happens regardless of the reason for skipping: the directory might
3554 not have been named on the command line (implicitly or explicitly),
3555 it might be excluded by the use of the
3556 @option{--exclude=@var{pattern}} option, or some other reason.
3557
3558 @opindex block-number
3559 @cindex Block number where error occurred
3560 @anchor{block-number}
3561 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3562 every message it would normally produce, the block number within the
3563 archive where the message was triggered. Also, supplementary messages
3564 are triggered when reading blocks full of NULs, or when hitting end of
3565 file on the archive. As of now, if the archive if properly terminated
3566 with a NUL block, the reading of the file may stop before end of file
3567 is met, so the position of end of file will not usually show when
3568 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3569 drains the archive before exiting when reading the
3570 archive from a pipe.
3571
3572 @cindex Error message, block number of
3573 This option is especially useful when reading damaged archives, since
3574 it helps pinpoint the damaged sections. It can also be used with
3575 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3576 choose among several backup tapes when retrieving a file later, in
3577 favor of the tape where the file appears earliest (closest to the
3578 front of the tape). @xref{backup}.
3579
3580 @node interactive
3581 @section Asking for Confirmation During Operations
3582 @cindex Interactive operation
3583
3584 Typically, @command{tar} carries out a command without stopping for
3585 further instructions. In some situations however, you may want to
3586 exclude some files and archive members from the operation (for instance
3587 if disk or storage space is tight). You can do this by excluding
3588 certain files automatically (@pxref{Choosing}), or by performing
3589 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3590 @command{tar} also accepts @option{--confirmation} for this option.
3591
3592 @opindex interactive
3593 When the @option{--interactive} (@option{-w}) option is specified, before
3594 reading, writing, or deleting files, @command{tar} first prints a message
3595 for each such file, telling what operation it intends to take, then asks
3596 for confirmation on the terminal. The actions which require
3597 confirmation include adding a file to the archive, extracting a file
3598 from the archive, deleting a file from the archive, and deleting a file
3599 from disk. To confirm the action, you must type a line of input
3600 beginning with @samp{y}. If your input line begins with anything other
3601 than @samp{y}, @command{tar} skips that file.
3602
3603 If @command{tar} is reading the archive from the standard input,
3604 @command{tar} opens the file @file{/dev/tty} to support the interactive
3605 communications.
3606
3607 Verbose output is normally sent to standard output, separate from
3608 other error messages. However, if the archive is produced directly
3609 on standard output, then verbose output is mixed with errors on
3610 @code{stderr}. Producing the archive on standard output may be used
3611 as a way to avoid using disk space, when the archive is soon to be
3612 consumed by another process reading it, say. Some people felt the need
3613 of producing an archive on stdout, still willing to segregate between
3614 verbose output and error output. A possible approach would be using a
3615 named pipe to receive the archive, and having the consumer process to
3616 read from that named pipe. This has the advantage of letting standard
3617 output free to receive verbose output, all separate from errors.
3618
3619 @node operations
3620 @chapter @GNUTAR{} Operations
3621
3622 @menu
3623 * Basic tar::
3624 * Advanced tar::
3625 * create options::
3626 * extract options::
3627 * backup::
3628 * Applications::
3629 * looking ahead::
3630 @end menu
3631
3632 @node Basic tar
3633 @section Basic @GNUTAR{} Operations
3634
3635 The basic @command{tar} operations, @option{--create} (@option{-c}),
3636 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3637 @option{-x}), are currently presented and described in the tutorial
3638 chapter of this manual. This section provides some complementary notes
3639 for these operations.
3640
3641 @table @option
3642 @opindex create, complementary notes
3643 @item --create
3644 @itemx -c
3645
3646 Creating an empty archive would have some kind of elegance. One can
3647 initialize an empty archive and later use @option{--append}
3648 (@option{-r}) for adding all members. Some applications would not
3649 welcome making an exception in the way of adding the first archive
3650 member. On the other hand, many people reported that it is
3651 dangerously too easy for @command{tar} to destroy a magnetic tape with
3652 an empty archive@footnote{This is well described in @cite{Unix-haters
3653 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3654 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3655
3656 @enumerate
3657 @item
3658 Mistakingly using @code{create} instead of @code{extract}, when the
3659 intent was to extract the full contents of an archive. This error
3660 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3661 the QWERTY keyboard. Instead of being unpacked, the archive then
3662 gets wholly destroyed. When users speak about @dfn{exploding} an
3663 archive, they usually mean something else :-).
3664
3665 @item
3666 Forgetting the argument to @code{file}, when the intent was to create
3667 an archive with a single file in it. This error is likely because a
3668 tired user can easily add the @kbd{f} key to the cluster of option
3669 letters, by the mere force of habit, without realizing the full
3670 consequence of doing so. The usual consequence is that the single
3671 file, which was meant to be saved, is rather destroyed.
3672 @end enumerate
3673
3674 So, recognizing the likelihood and the catastrophical nature of these
3675 errors, @GNUTAR{} now takes some distance from elegance, and
3676 cowardly refuses to create an archive when @option{--create} option is
3677 given, there are no arguments besides options, and
3678 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3679 around the cautiousness of @GNUTAR{} and nevertheless create an
3680 archive with nothing in it, one may still use, as the value for the
3681 @option{--files-from} option, a file with no names in it, as shown in
3682 the following commands:
3683
3684 @smallexample
3685 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3686 @kbd{tar cfT empty-archive.tar /dev/null}
3687 @end smallexample
3688
3689 @opindex extract, complementary notes
3690 @item --extract
3691 @itemx --get
3692 @itemx -x
3693
3694 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3695
3696 @item @option{--list} (@option{-t})
3697
3698 @GNUTAR{} now shows dates as @samp{1996-08-30},
3699 while it used to show them as @samp{Aug 30 1996}. Preferably,
3700 people should get used to ISO 8601 dates. Local American dates should
3701 be made available again with full date localization support, once
3702 ready. In the meantime, programs not being localizable for dates
3703 should prefer international dates, that's really the way to go.
3704
3705 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3706 are curious, it contains a detailed explanation of the ISO 8601 standard.
3707
3708 @end table
3709
3710 @node Advanced tar
3711 @section Advanced @GNUTAR{} Operations
3712
3713 Now that you have learned the basics of using @GNUTAR{}, you may want
3714 to learn about further ways in which @command{tar} can help you.
3715
3716 This chapter presents five, more advanced operations which you probably
3717 won't use on a daily basis, but which serve more specialized functions.
3718 We also explain the different styles of options and why you might want
3719 to use one or another, or a combination of them in your @command{tar}
3720 commands. Additionally, this chapter includes options which allow you to
3721 define the output from @command{tar} more carefully, and provide help and
3722 error correction in special circumstances.
3723
3724 @FIXME{check this after the chapter is actually revised to make sure
3725 it still introduces the info in the chapter correctly : ).}
3726
3727 @menu
3728 * Operations::
3729 * append::
3730 * update::
3731 * concatenate::
3732 * delete::
3733 * compare::
3734 @end menu
3735
3736 @node Operations
3737 @subsection The Five Advanced @command{tar} Operations
3738 @UNREVISED
3739
3740 In the last chapter, you learned about the first three operations to
3741 @command{tar}. This chapter presents the remaining five operations to
3742 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3743 @option{--delete}, and @option{--compare}.
3744
3745 You are not likely to use these operations as frequently as those
3746 covered in the last chapter; however, since they perform specialized
3747 functions, they are quite useful when you do need to use them. We
3748 will give examples using the same directory and files that you created
3749 in the last chapter. As you may recall, the directory is called
3750 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3751 @samp{rock}, and the two archive files you created are
3752 @samp{collection.tar} and @samp{music.tar}.
3753
3754 We will also use the archive files @samp{afiles.tar} and
3755 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3756 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3757 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3758
3759 Unless we state otherwise, all practicing you do and examples you follow
3760 in this chapter will take place in the @file{practice} directory that
3761 you created in the previous chapter; see @ref{prepare for examples}.
3762 (Below in this section, we will remind you of the state of the examples
3763 where the last chapter left them.)
3764
3765 The five operations that we will cover in this chapter are:
3766
3767 @table @option
3768 @item --append
3769 @itemx -r
3770 Add new entries to an archive that already exists.
3771 @item --update
3772 @itemx -r
3773 Add more recent copies of archive members to the end of an archive, if
3774 they exist.
3775 @item --concatenate
3776 @itemx --catenate
3777 @itemx -A
3778 Add one or more pre-existing archives to the end of another archive.
3779 @item --delete
3780 Delete items from an archive (does not work on tapes).
3781 @item --compare
3782 @itemx --diff
3783 @itemx -d
3784 Compare archive members to their counterparts in the file system.
3785 @end table
3786
3787 @node append
3788 @subsection How to Add Files to Existing Archives: @option{--append}
3789 @UNREVISED
3790
3791 @opindex append
3792 If you want to add files to an existing archive, you don't need to
3793 create a new archive; you can use @option{--append} (@option{-r}).
3794 The archive must already exist in order to use @option{--append}. (A
3795 related operation is the @option{--update} operation; you can use this
3796 to add newer versions of archive members to an existing archive. To learn how to
3797 do this with @option{--update}, @pxref{update}.)
3798
3799 If you use @option{--append} to add a file that has the same name as an
3800 archive member to an archive containing that archive member, then the
3801 old member is not deleted. What does happen, however, is somewhat
3802 complex. @command{tar} @emph{allows} you to have infinite number of files
3803 with the same name. Some operations treat these same-named members no
3804 differently than any other set of archive members: for example, if you
3805 view an archive with @option{--list} (@option{-t}), you will see all
3806 of those members listed, with their data modification times, owners, etc.
3807
3808 Other operations don't deal with these members as perfectly as you might
3809 prefer; if you were to use @option{--extract} to extract the archive,
3810 only the most recently added copy of a member with the same name as four
3811 other members would end up in the working directory. This is because
3812 @option{--extract} extracts an archive in the order the members appeared
3813 in the archive; the most recently archived members will be extracted
3814 last. Additionally, an extracted member will @emph{replace} a file of
3815 the same name which existed in the directory already, and @command{tar}
3816 will not prompt you about this@footnote{Unless you give it
3817 @option{--keep-old-files} option, or the disk copy is newer than the
3818 the one in the archive and you invoke @command{tar} with
3819 @option{--keep-newer-files} option}. Thus, only the most recently archived
3820 member will end up being extracted, as it will replace the one
3821 extracted before it, and so on.
3822
3823 There exists a special option that allows you to get around this
3824 behavior and extract (or list) only a particular copy of the file.
3825 This is @option{--occurrence} option. If you run @command{tar} with
3826 this option, it will extract only the first copy of the file. You
3827 may also give this option an argument specifying the number of
3828 copy to be extracted. Thus, for example if the archive
3829 @file{archive.tar} contained three copies of file @file{myfile}, then
3830 the command
3831
3832 @smallexample
3833 tar --extract --file archive.tar --occurrence=2 myfile
3834 @end smallexample
3835
3836 @noindent
3837 would extract only the second copy. @xref{Option
3838 Summary,---occurrence}, for the description of @option{--occurrence}
3839 option.
3840
3841 @FIXME{ hag -- you might want to incorporate some of the above into the
3842 MMwtSN node; not sure. i didn't know how to make it simpler...
3843
3844 There are a few ways to get around this. (maybe xref Multiple Members
3845 with the Same Name.}
3846
3847 @cindex Members, replacing with other members
3848 @cindex Replacing members with other members
3849 If you want to replace an archive member, use @option{--delete} to
3850 delete the member you want to remove from the archive, , and then use
3851 @option{--append} to add the member you want to be in the archive. Note
3852 that you can not change the order of the archive; the most recently
3853 added member will still appear last. In this sense, you cannot truly
3854 ``replace'' one member with another. (Replacing one member with another
3855 will not work on certain types of media, such as tapes; see @ref{delete}
3856 and @ref{Media}, for more information.)
3857
3858 @menu
3859 * appending files:: Appending Files to an Archive
3860 * multiple::
3861 @end menu
3862
3863 @node appending files
3864 @subsubsection Appending Files to an Archive
3865 @UNREVISED
3866 @cindex Adding files to an Archive
3867 @cindex Appending files to an Archive
3868 @cindex Archives, Appending files to
3869
3870 The simplest way to add a file to an already existing archive is the
3871 @option{--append} (@option{-r}) operation, which writes specified
3872 files into the archive whether or not they are already among the
3873 archived files.
3874
3875 When you use @option{--append}, you @emph{must} specify file name
3876 arguments, as there is no default. If you specify a file that already
3877 exists in the archive, another copy of the file will be added to the
3878 end of the archive. As with other operations, the member names of the
3879 newly added files will be exactly the same as their names given on the
3880 command line. The @option{--verbose} (@option{-v}) option will print
3881 out the names of the files as they are written into the archive.
3882
3883 @option{--append} cannot be performed on some tape drives, unfortunately,
3884 due to deficiencies in the formats those tape drives use. The archive
3885 must be a valid @command{tar} archive, or else the results of using this
3886 operation will be unpredictable. @xref{Media}.
3887
3888 To demonstrate using @option{--append} to add a file to an archive,
3889 create a file called @file{rock} in the @file{practice} directory.
3890 Make sure you are in the @file{practice} directory. Then, run the
3891 following @command{tar} command to add @file{rock} to
3892 @file{collection.tar}:
3893
3894 @smallexample
3895 $ @kbd{tar --append --file=collection.tar rock}
3896 @end smallexample
3897
3898 @noindent
3899 If you now use the @option{--list} (@option{-t}) operation, you will see that
3900 @file{rock} has been added to the archive:
3901
3902 @smallexample
3903 $ @kbd{tar --list --file=collection.tar}
3904 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3905 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3906 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3907 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3908 @end smallexample
3909
3910 @node multiple
3911 @subsubsection Multiple Files with the Same Name
3912
3913 You can use @option{--append} (@option{-r}) to add copies of files
3914 which have been updated since the archive was created. (However, we
3915 do not recommend doing this since there is another @command{tar}
3916 option called @option{--update}; @xref{update}, for more information.
3917 We describe this use of @option{--append} here for the sake of
3918 completeness.) When you extract the archive, the older version will
3919 be effectively lost. This works because files are extracted from an
3920 archive in the order in which they were archived. Thus, when the
3921 archive is extracted, a file archived later in time will replace a
3922 file of the same name which was archived earlier, even though the
3923 older version of the file will remain in the archive unless you delete
3924 all versions of the file.
3925
3926 Supposing you change the file @file{blues} and then append the changed
3927 version to @file{collection.tar}. As you saw above, the original
3928 @file{blues} is in the archive @file{collection.tar}. If you change the
3929 file and append the new version of the file to the archive, there will
3930 be two copies in the archive. When you extract the archive, the older
3931 version of the file will be extracted first, and then replaced by the
3932 newer version when it is extracted.
3933
3934 You can append the new, changed copy of the file @file{blues} to the
3935 archive in this way:
3936
3937 @smallexample
3938 $ @kbd{tar --append --verbose --file=collection.tar blues}
3939 blues
3940 @end smallexample
3941
3942 @noindent
3943 Because you specified the @option{--verbose} option, @command{tar} has
3944 printed the name of the file being appended as it was acted on. Now
3945 list the contents of the archive:
3946
3947 @smallexample
3948 $ @kbd{tar --list --verbose --file=collection.tar}
3949 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3950 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3951 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3952 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3953 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3954 @end smallexample
3955
3956 @noindent
3957 The newest version of @file{blues} is now at the end of the archive
3958 (note the different creation dates and file sizes). If you extract
3959 the archive, the older version of the file @file{blues} will be
3960 replaced by the newer version. You can confirm this by extracting
3961 the archive and running @samp{ls} on the directory.
3962
3963 If you wish to extract the first occurrence of the file @file{blues}
3964 from the archive, use @option{--occurrence} option, as shown in
3965 the following example:
3966
3967 @smallexample
3968 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3969 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3970 @end smallexample
3971
3972 @xref{Writing}, for more information on @option{--extract} and
3973 @xref{Option Summary, --occurrence}, for the description of
3974 @option{--occurrence} option.
3975
3976 @node update
3977 @subsection Updating an Archive
3978 @UNREVISED
3979 @cindex Updating an archive
3980
3981 @opindex update
3982 In the previous section, you learned how to use @option{--append} to
3983 add a file to an existing archive. A related operation is
3984 @option{--update} (@option{-u}). The @option{--update} operation
3985 updates a @command{tar} archive by comparing the date of the specified
3986 archive members against the date of the file with the same name. If
3987 the file has been modified more recently than the archive member, then
3988 the newer version of the file is added to the archive (as with
3989 @option{--append}).
3990
3991 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3992 The operation will fail.
3993
3994 @FIXME{other examples of media on which --update will fail? need to ask
3995 charles and/or mib/thomas/dave shevett..}
3996
3997 Both @option{--update} and @option{--append} work by adding to the end
3998 of the archive. When you extract a file from the archive, only the
3999 version stored last will wind up in the file system, unless you use
4000 the @option{--backup} option. @FIXME-ref{Multiple Members with the
4001 Same Name}
4002
4003 @menu
4004 * how to update::
4005 @end menu
4006
4007 @node how to update
4008 @subsubsection How to Update an Archive Using @option{--update}
4009
4010 You must use file name arguments with the @option{--update}
4011 (@option{-u}) operation. If you don't specify any files,
4012 @command{tar} won't act on any files and won't tell you that it didn't
4013 do anything (which may end up confusing you).
4014
4015 @c note: the above parenthetical added because in fact, this
4016 @c behavior just confused the author. :-)
4017
4018 To see the @option{--update} option at work, create a new file,
4019 @file{classical}, in your practice directory, and some extra text to the
4020 file @file{blues}, using any text editor. Then invoke @command{tar} with
4021 the @samp{update} operation and the @option{--verbose} (@option{-v})
4022 option specified, using the names of all the files in the practice
4023 directory as file name arguments:
4024
4025 @smallexample
4026 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4027 blues
4028 classical
4029 $
4030 @end smallexample
4031
4032 @noindent
4033 Because we have specified verbose mode, @command{tar} prints out the names
4034 of the files it is working on, which in this case are the names of the
4035 files that needed to be updated. If you run @samp{tar --list} and look
4036 at the archive, you will see @file{blues} and @file{classical} at its
4037 end. There will be a total of two versions of the member @samp{blues};
4038 the one at the end will be newer and larger, since you added text before
4039 updating it.
4040
4041 (The reason @command{tar} does not overwrite the older file when updating
4042 it is because writing to the middle of a section of tape is a difficult
4043 process. Tapes are not designed to go backward. @xref{Media}, for more
4044 information about tapes.
4045
4046 @option{--update} (@option{-u}) is not suitable for performing backups for two
4047 reasons: it does not change directory content entries, and it
4048 lengthens the archive every time it is used. The @GNUTAR{}
4049 options intended specifically for backups are more
4050 efficient. If you need to run backups, please consult @ref{Backups}.
4051
4052 @node concatenate
4053 @subsection Combining Archives with @option{--concatenate}
4054
4055 @cindex Adding archives to an archive
4056 @cindex Concatenating Archives
4057 @opindex concatenate
4058 @opindex catenate
4059 @c @cindex @option{-A} described
4060 Sometimes it may be convenient to add a second archive onto the end of
4061 an archive rather than adding individual files to the archive. To add
4062 one or more archives to the end of another archive, you should use the
4063 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4064
4065 To use @option{--concatenate}, give the first archive with
4066 @option{--file} option and name the rest of archives to be
4067 concatenated on the command line. The members, and their member
4068 names, will be copied verbatim from those archives to the first one.
4069 @FIXME-ref{This can cause multiple members to have the same name, for
4070 information on how this affects reading the archive, Multiple
4071 Members with the Same Name.}
4072 The new, concatenated archive will be called by the same name as the
4073 one given with the @option{--file} option. As usual, if you omit
4074 @option{--file}, @command{tar} will use the value of the environment
4075 variable @env{TAPE}, or, if this has not been set, the default archive name.
4076
4077 @FIXME{There is no way to specify a new name...}
4078
4079 To demonstrate how @option{--concatenate} works, create two small archives
4080 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4081 files from @file{practice}:
4082
4083 @smallexample
4084 $ @kbd{tar -cvf bluesrock.tar blues rock}
4085 blues
4086 rock
4087 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4088 folk
4089 jazz
4090 @end smallexample
4091
4092 @noindent
4093 If you like, You can run @samp{tar --list} to make sure the archives
4094 contain what they are supposed to:
4095
4096 @smallexample
4097 $ @kbd{tar -tvf bluesrock.tar}
4098 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4099 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4100 $ @kbd{tar -tvf jazzfolk.tar}
4101 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4102 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4103 @end smallexample
4104
4105 We can concatenate these two archives with @command{tar}:
4106
4107 @smallexample
4108 $ @kbd{cd ..}
4109 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4110 @end smallexample
4111
4112 If you now list the contents of the @file{bluesrock.tar}, you will see
4113 that now it also contains the archive members of @file{jazzfolk.tar}:
4114
4115 @smallexample
4116 $ @kbd{tar --list --file=bluesrock.tar}
4117 blues
4118 rock
4119 folk
4120 jazz
4121 @end smallexample
4122
4123 When you use @option{--concatenate}, the source and target archives must
4124 already exist and must have been created using compatible format
4125 parameters. Notice, that @command{tar} does not check whether the
4126 archives it concatenates have compatible formats, it does not
4127 even check if the files are really tar archives.
4128
4129 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4130 tape drives, due to deficiencies in the formats those tape drives use.
4131
4132 @cindex @code{concatenate} vs @command{cat}
4133 @cindex @command{cat} vs @code{concatenate}
4134 It may seem more intuitive to you to want or try to use @command{cat} to
4135 concatenate two archives instead of using the @option{--concatenate}
4136 operation; after all, @command{cat} is the utility for combining files.
4137
4138 However, @command{tar} archives incorporate an end-of-file marker which
4139 must be removed if the concatenated archives are to be read properly as
4140 one archive. @option{--concatenate} removes the end-of-archive marker
4141 from the target archive before each new archive is appended. If you use
4142 @command{cat} to combine the archives, the result will not be a valid
4143 @command{tar} format archive. If you need to retrieve files from an
4144 archive that was added to using the @command{cat} utility, use the
4145 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4146 information on dealing with archives improperly combined using the
4147 @command{cat} shell utility.
4148
4149 @node delete
4150 @subsection Removing Archive Members Using @option{--delete}
4151 @UNREVISED
4152 @cindex Deleting files from an archive
4153 @cindex Removing files from an archive
4154
4155 @opindex delete
4156 You can remove members from an archive by using the @option{--delete}
4157 option. Specify the name of the archive with @option{--file}
4158 (@option{-f}) and then specify the names of the members to be deleted;
4159 if you list no member names, nothing will be deleted. The
4160 @option{--verbose} option will cause @command{tar} to print the names
4161 of the members as they are deleted. As with @option{--extract}, you
4162 must give the exact member names when using @samp{tar --delete}.
4163 @option{--delete} will remove all versions of the named file from the
4164 archive. The @option{--delete} operation can run very slowly.
4165
4166 Unlike other operations, @option{--delete} has no short form.
4167
4168 @cindex Tapes, using @option{--delete} and
4169 @cindex Deleting from tape archives
4170 This operation will rewrite the archive. You can only use
4171 @option{--delete} on an archive if the archive device allows you to
4172 write to any point on the media, such as a disk; because of this, it
4173 does not work on magnetic tapes. Do not try to delete an archive member
4174 from a magnetic tape; the action will not succeed, and you will be
4175 likely to scramble the archive and damage your tape. There is no safe
4176 way (except by completely re-writing the archive) to delete files from
4177 most kinds of magnetic tape. @xref{Media}.
4178
4179 To delete all versions of the file @file{blues} from the archive
4180 @file{collection.tar} in the @file{practice} directory, make sure you
4181 are in that directory, and then,
4182
4183 @smallexample
4184 $ @kbd{tar --list --file=collection.tar}
4185 blues
4186 folk
4187 jazz
4188 rock
4189 $ @kbd{tar --delete --file=collection.tar blues}
4190 $ @kbd{tar --list --file=collection.tar}
4191 folk
4192 jazz
4193 rock
4194 $
4195 @end smallexample
4196
4197 @FIXME{Check if the above listing is actually produced after running
4198 all the examples on collection.tar.}
4199
4200 The @option{--delete} option has been reported to work properly when
4201 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4202
4203 @node compare
4204 @subsection Comparing Archive Members with the File System
4205 @cindex Verifying the currency of an archive
4206 @UNREVISED
4207
4208 @opindex compare
4209 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4210 specified archive members against files with the same names, and then
4211 reports differences in file size, mode, owner, modification date and
4212 contents. You should @emph{only} specify archive member names, not file
4213 names. If you do not name any members, then @command{tar} will compare the
4214 entire archive. If a file is represented in the archive but does not
4215 exist in the file system, @command{tar} reports a difference.
4216
4217 You have to specify the record size of the archive when modifying an
4218 archive with a non-default record size.
4219
4220 @command{tar} ignores files in the file system that do not have
4221 corresponding members in the archive.
4222
4223 The following example compares the archive members @file{rock},
4224 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4225 files of the same name in the file system. (Note that there is no file,
4226 @file{funk}; @command{tar} will report an error message.)
4227
4228 @smallexample
4229 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4230 rock
4231 blues
4232 tar: funk not found in archive
4233 @end smallexample
4234
4235 The spirit behind the @option{--compare} (@option{--diff},
4236 @option{-d}) option is to check whether the archive represents the
4237 current state of files on disk, more than validating the integrity of
4238 the archive media. For this later goal, @xref{verify}.
4239
4240 @node create options
4241 @section Options Used by @option{--create}
4242
4243 @opindex create, additional options
4244 The previous chapter described the basics of how to use
4245 @option{--create} (@option{-c}) to create an archive from a set of files.
4246 @xref{create}. This section described advanced options to be used with
4247 @option{--create}.
4248
4249 @menu
4250 * Ignore Failed Read::
4251 @end menu
4252
4253 @node Ignore Failed Read
4254 @subsection Ignore Fail Read
4255
4256 @table @option
4257 @item --ignore-failed-read
4258 Do not exit with nonzero on unreadable files or directories.
4259 @end table
4260
4261 @node extract options
4262 @section Options Used by @option{--extract}
4263 @UNREVISED
4264
4265 @opindex extract, additional options
4266 The previous chapter showed how to use @option{--extract} to extract
4267 an archive into the file system. Various options cause @command{tar} to
4268 extract more information than just file contents, such as the owner,
4269 the permissions, the modification date, and so forth. This section
4270 presents options to be used with @option{--extract} when certain special
4271 considerations arise. You may review the information presented in
4272 @ref{extract} for more basic information about the
4273 @option{--extract} operation.
4274
4275 @menu
4276 * Reading:: Options to Help Read Archives
4277 * Writing:: Changing How @command{tar} Writes Files
4278 * Scarce:: Coping with Scarce Resources
4279 @end menu
4280
4281 @node Reading
4282 @subsection Options to Help Read Archives
4283 @cindex Options when reading archives
4284 @UNREVISED
4285
4286 @cindex Reading incomplete records
4287 @cindex Records, incomplete
4288 @opindex read-full-records
4289 Normally, @command{tar} will request data in full record increments from
4290 an archive storage device. If the device cannot return a full record,
4291 @command{tar} will report an error. However, some devices do not always
4292 return full records, or do not require the last record of an archive to
4293 be padded out to the next record boundary. To keep reading until you
4294 obtain a full record, or to accept an incomplete record if it contains
4295 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4296 in conjunction with the @option{--extract} or @option{--list} operations.
4297 @xref{Blocking}.
4298
4299 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4300 @command{tar} reads an archive from standard input, or from a remote
4301 machine. This is because on BSD Unix systems, attempting to read a
4302 pipe returns however much happens to be in the pipe, even if it is
4303 less than was requested. If this option were not enabled, @command{tar}
4304 would fail as soon as it read an incomplete record from the pipe.
4305
4306 If you're not sure of the blocking factor of an archive, you can
4307 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4308 @option{--blocking-factor=@var{512-size}} (@option{-b
4309 @var{512-size}}), using a blocking factor larger than what the archive
4310 uses. This lets you avoid having to determine the blocking factor
4311 of an archive. @xref{Blocking Factor}.
4312
4313 @menu
4314 * read full records::
4315 * Ignore Zeros::
4316 @end menu
4317
4318 @node read full records
4319 @unnumberedsubsubsec Reading Full Records
4320
4321 @FIXME{need sentence or so of intro here}
4322
4323 @table @option
4324 @opindex read-full-records
4325 @item --read-full-records
4326 @item -B
4327 Use in conjunction with @option{--extract} (@option{--get},
4328 @option{-x}) to read an archive which contains incomplete records, or
4329 one which has a blocking factor less than the one specified.
4330 @end table
4331
4332 @node Ignore Zeros
4333 @unnumberedsubsubsec Ignoring Blocks of Zeros
4334
4335 @cindex End-of-archive blocks, ignoring
4336 @cindex Ignoring end-of-archive blocks
4337 @opindex ignore-zeros
4338 Normally, @command{tar} stops reading when it encounters a block of zeros
4339 between file entries (which usually indicates the end of the archive).
4340 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4341 completely read an archive which contains a block of zeros before the
4342 end (i.e., a damaged archive, or one that was created by concatenating
4343 several archives together).
4344
4345 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4346 versions of @command{tar} write garbage after the end-of-archive entry,
4347 since that part of the media is never supposed to be read. @GNUTAR{}
4348 does not write after the end of an archive, but seeks to
4349 maintain compatiblity among archiving utilities.
4350
4351 @table @option
4352 @item --ignore-zeros
4353 @itemx -i
4354 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4355 encountered while reading an archive. Use in conjunction with
4356 @option{--extract} or @option{--list}.
4357 @end table
4358
4359 @node Writing
4360 @subsection Changing How @command{tar} Writes Files
4361 @UNREVISED
4362
4363 @FIXME{Introductory paragraph}
4364
4365 @menu
4366 * Dealing with Old Files::
4367 * Overwrite Old Files::
4368 * Keep Old Files::
4369 * Keep Newer Files::
4370 * Unlink First::
4371 * Recursive Unlink::
4372 * Data Modification Times::
4373 * Setting Access Permissions::
4374 * Directory Modification Times and Permissions::
4375 * Writing to Standard Output::
4376 * Writing to an External Program::
4377 * remove files::
4378 @end menu
4379
4380 @node Dealing with Old Files
4381 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4382
4383 @opindex overwrite-dir, introduced
4384 When extracting files, if @command{tar} discovers that the extracted
4385 file already exists, it normally replaces the file by removing it before
4386 extracting it, to prevent confusion in the presence of hard or symbolic
4387 links. (If the existing file is a symbolic link, it is removed, not
4388 followed.) However, if a directory cannot be removed because it is
4389 nonempty, @command{tar} normally overwrites its metadata (ownership,
4390 permission, etc.). The @option{--overwrite-dir} option enables this
4391 default behavior. To be more cautious and preserve the metadata of
4392 such a directory, use the @option{--no-overwrite-dir} option.
4393
4394 @cindex Overwriting old files, prevention
4395 @opindex keep-old-files, introduced
4396 To be even more cautious and prevent existing files from being replaced, use
4397 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4398 to replace or update a file that already exists, i.e., a file with the
4399 same name as an archive member prevents extraction of that archive
4400 member. Instead, it reports an error.
4401
4402 @opindex overwrite, introduced
4403 To be more aggressive about altering existing files, use the
4404 @option{--overwrite} option. It causes @command{tar} to overwrite
4405 existing files and to follow existing symbolic links when extracting.
4406
4407 @cindex Protecting old files
4408 Some people argue that @GNUTAR{} should not hesitate
4409 to overwrite files with other files when extracting. When extracting
4410 a @command{tar} archive, they expect to see a faithful copy of the
4411 state of the file system when the archive was created. It is debatable
4412 that this would always be a proper behavior. For example, suppose one
4413 has an archive in which @file{usr/local} is a link to
4414 @file{usr/local2}. Since then, maybe the site removed the link and
4415 renamed the whole hierarchy from @file{/usr/local2} to
4416 @file{/usr/local}. Such things happen all the time. I guess it would
4417 not be welcome at all that @GNUTAR{} removes the
4418 whole hierarchy just to make room for the link to be reinstated
4419 (unless it @emph{also} simultaneously restores the full
4420 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4421 able to remove a whole hierarchy to reestablish a symbolic link, for
4422 example, but @emph{only if} @option{--recursive-unlink} is specified
4423 to allow this behavior. In any case, single files are silently
4424 removed.
4425
4426 @opindex unlink-first, introduced
4427 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4428 some cases by causing @command{tar} to remove files unconditionally
4429 before extracting them.
4430
4431 @node Overwrite Old Files
4432 @unnumberedsubsubsec Overwrite Old Files
4433
4434 @table @option
4435 @opindex overwrite
4436 @item --overwrite
4437 Overwrite existing files and directory metadata when extracting files
4438 from an archive.
4439
4440 This causes @command{tar} to write extracted files into the file system without
4441 regard to the files already on the system; i.e., files with the same
4442 names as archive members are overwritten when the archive is extracted.
4443 It also causes @command{tar} to extract the ownership, permissions,
4444 and time stamps onto any preexisting files or directories.
4445 If the name of a corresponding file name is a symbolic link, the file
4446 pointed to by the symbolic link will be overwritten instead of the
4447 symbolic link itself (if this is possible). Moreover, special devices,
4448 empty directories and even symbolic links are automatically removed if
4449 they are in the way of extraction.
4450
4451 Be careful when using the @option{--overwrite} option, particularly when
4452 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4453 can change the contents, ownership or permissions of any file on your
4454 system. Also, many systems do not take kindly to overwriting files that
4455 are currently being executed.
4456
4457 @opindex overwrite-dir
4458 @item --overwrite-dir
4459 Overwrite the metadata of directories when extracting files from an
4460 archive, but remove other files before extracting.
4461 @end table
4462
4463 @node Keep Old Files
4464 @unnumberedsubsubsec Keep Old Files
4465
4466 @table @option
4467 @opindex keep-old-files
4468 @item --keep-old-files
4469 @itemx -k
4470 Do not replace existing files from archive. The
4471 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4472 from replacing existing files with files with the same name from the
4473 archive. The @option{--keep-old-files} option is meaningless with
4474 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4475 files in the file system during extraction.
4476 @end table
4477
4478 @node Keep Newer Files
4479 @unnumberedsubsubsec Keep Newer Files
4480
4481 @table @option
4482 @opindex keep-newer-files
4483 @item --keep-newer-files
4484 Do not replace existing files that are newer than their archive
4485 copies. This option is meaningless with @option{--list} (@option{-t}).
4486 @end table
4487
4488 @node Unlink First
4489 @unnumberedsubsubsec Unlink First
4490
4491 @table @option
4492 @opindex unlink-first
4493 @item --unlink-first
4494 @itemx -U
4495 Remove files before extracting over them.
4496 This can make @command{tar} run a bit faster if you know in advance
4497 that the extracted files all need to be removed. Normally this option
4498 slows @command{tar} down slightly, so it is disabled by default.
4499 @end table
4500
4501 @node Recursive Unlink
4502 @unnumberedsubsubsec Recursive Unlink
4503
4504 @table @option
4505 @opindex recursive-unlink
4506 @item --recursive-unlink
4507 When this option is specified, try removing files and directory hierarchies
4508 before extracting over them. @emph{This is a dangerous option!}
4509 @end table
4510
4511 If you specify the @option{--recursive-unlink} option,
4512 @command{tar} removes @emph{anything} that keeps you from extracting a file
4513 as far as current permissions will allow it. This could include removal
4514 of the contents of a full directory hierarchy.
4515
4516 @node Data Modification Times
4517 @unnumberedsubsubsec Setting Data Modification Times
4518
4519 @cindex Data modification times of extracted files
4520 @cindex Modification times of extracted files
4521 Normally, @command{tar} sets the data modification times of extracted
4522 files to the corresponding times recorded for the files in the archive, but
4523 limits the permissions of extracted files by the current @code{umask}
4524 setting.
4525
4526 To set the data modification times of extracted files to the time when
4527 the files were extracted, use the @option{--touch} (@option{-m}) option in
4528 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4529
4530 @table @option
4531 @opindex touch
4532 @item --touch
4533 @itemx -m
4534 Sets the data modification time of extracted archive members to the time
4535 they were extracted, not the time recorded for them in the archive.
4536 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4537 @end table
4538
4539 @node Setting Access Permissions
4540 @unnumberedsubsubsec Setting Access Permissions
4541
4542 @cindex Permissions of extracted files
4543 @cindex Modes of extracted files
4544 To set the modes (access permissions) of extracted files to those
4545 recorded for those files in the archive, use @option{--same-permissions}
4546 in conjunction with the @option{--extract} (@option{--get},
4547 @option{-x}) operation.
4548
4549 @table @option
4550 @opindex preserve-permission
4551 @opindex same-permission
4552 @item --preserve-permission
4553 @itemx --same-permission
4554 @c @itemx --ignore-umask
4555 @itemx -p
4556 Set modes of extracted archive members to those recorded in the
4557 archive, instead of current umask settings. Use in conjunction with
4558 @option{--extract} (@option{--get}, @option{-x}).
4559 @end table
4560
4561 @node Directory Modification Times and Permissions
4562 @unnumberedsubsubsec Directory Modification Times and Permissions
4563
4564 After sucessfully extracting a file member, @GNUTAR{} normally
4565 restores its permissions and modification times, as described in the
4566 previous sections. This cannot be done for directories, because
4567 after extracting a directory @command{tar} will almost certainly
4568 extract files into that directory and this will cause the directory
4569 modification time to be updated. Moreover, restoring that directory
4570 permissions may not permit file creation within it. Thus, restoring
4571 directory permissions and modification times must be delayed at least
4572 until all files have been extracted into that directory. @GNUTAR{}
4573 restores directories using the following approach.
4574
4575 The extracted directories are created with the mode specified in the
4576 archive, as modified by the umask of the user, which gives sufficient
4577 permissions to allow file creation. The meta-information about the
4578 directory is recorded in the temporary list of directories. When
4579 preparing to extract next archive member, @GNUTAR{} checks if the
4580 directory prefix of this file contains the remembered directory. If
4581 it does not, the program assumes that all files have been extracted
4582 into that directory, restores its modification time and permissions
4583 and removes its entry from the internal list. This approach allows
4584 to correctly restore directory meta-information in the majority of
4585 cases, while keeping memory requirements sufficiently small. It is
4586 based on the fact, that most @command{tar} archives use the predefined
4587 order of members: first the directory, then all the files and
4588 subdirectories in that directory.
4589
4590 However, this is not always true. The most important exception are
4591 incremental archives (@pxref{Incremental Dumps}). The member order in
4592 an incremental archive is reversed: first all directory members are
4593 stored, followed by other (non-directory) members. So, when extracting
4594 from incremental archives, @GNUTAR{} alters the above procedure. It
4595 remebers all restored directories, and restores their meta-data
4596 only after the entire archive has been processed. Notice, that you do
4597 not need to specity any special options for that, as @GNUTAR{}
4598 automatically detects archives in incremental format.
4599
4600 There may be cases, when such processing is required for normal archives
4601 too. Consider the following example:
4602
4603 @smallexample
4604 @group
4605 $ @kbd{tar --no-recursion -cvf archive \
4606 foo foo/file1 bar bar/file foo/file2}
4607 foo/
4608 foo/file1
4609 bar/
4610 bar/file
4611 foo/file2
4612 @end group
4613 @end smallexample
4614
4615 During the normal operation, after encountering @file{bar}
4616 @GNUTAR{} will assume that all files from the directory @file{foo}
4617 were already extracted and will therefore restore its timestamp and
4618 permission bits. However, after extracting @file{foo/file2} the
4619 directory timestamp will be offset again.
4620
4621 To correctly restore directory meta-information in such cases, use
4622 @option{delay-directory-restore} command line option:
4623
4624 @table @option
4625 @opindex delay-directory-restore
4626 @item --delay-directory-restore
4627 Delays restoring of the modification times and permissions of extracted
4628 directories until the end of extraction. This way, correct
4629 meta-information is restored even if the archive has unusual member
4630 ordering.
4631
4632 @opindex no-delay-directory-restore
4633 @item --no-delay-directory-restore
4634 Cancel the effect of the previous @option{--delay-directory-restore}.
4635 Use this option if you have used @option{--delay-directory-restore} in
4636 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4637 temporarily disable it.
4638 @end table
4639
4640 @node Writing to Standard Output
4641 @unnumberedsubsubsec Writing to Standard Output
4642
4643 @cindex Writing extracted files to standard output
4644 @cindex Standard output, writing extracted files to
4645 To write the extracted files to the standard output, instead of
4646 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4647 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4648 extracting files to send them through a pipe, and do not need to
4649 preserve them in the file system. If you extract multiple members,
4650 they appear on standard output concatenated, in the order they are
4651 found in the archive.
4652
4653 @table @option
4654 @opindex to-stdout
4655 @item --to-stdout
4656 @itemx -O
4657 Writes files to the standard output. Use only in conjunction with
4658 @option{--extract} (@option{--get}, @option{-x}). When this option is
4659 used, instead of creating the files specified, @command{tar} writes
4660 the contents of the files extracted to its standard output. This may
4661 be useful if you are only extracting the files in order to send them
4662 through a pipe. This option is meaningless with @option{--list}
4663 (@option{-t}).
4664 @end table
4665
4666 This can be useful, for example, if you have a tar archive containing
4667 a big file and don't want to store the file on disk before processing
4668 it. You can use a command like this:
4669
4670 @smallexample
4671 tar -xOzf foo.tgz bigfile | process
4672 @end smallexample
4673
4674 or even like this if you want to process the concatenation of the files:
4675
4676 @smallexample
4677 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4678 @end smallexample
4679
4680 Hovewer, @option{--to-command} may be more convenient for use with
4681 multiple files. See the next section.
4682
4683 @node Writing to an External Program
4684 @unnumberedsubsubsec Writing to an External Program
4685
4686 You can instruct @command{tar} to send the contents of each extracted
4687 file to the standard input of an external program:
4688
4689 @table @option
4690 @opindex to-command
4691 @item --to-command=@var{command}
4692 Extract files and pipe their contents to the standard input of
4693 @var{command}. When this option is used, instead of creating the
4694 files specified, @command{tar} invokes @var{command} and pipes the
4695 contents of the files to its standard output. @var{Command} may
4696 contain command line arguments. The program is executed via
4697 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4698 extracted. Non-regular files (directories, etc.) are ignored when this
4699 option is used.
4700 @end table
4701
4702 The command can obtain the information about the file it processes
4703 from the following environment variables:
4704
4705 @table @var
4706 @vrindex TAR_FILETYPE, to-command environment
4707 @item TAR_FILETYPE
4708 Type of the file. It is a single letter with the following meaning:
4709
4710 @multitable @columnfractions 0.10 0.90
4711 @item f @tab Regular file
4712 @item d @tab Directory
4713 @item l @tab Symbolic link
4714 @item h @tab Hard link
4715 @item b @tab Block device
4716 @item c @tab Character device
4717 @end multitable
4718
4719 Currently only regular files are supported.
4720
4721 @vrindex TAR_MODE, to-command environment
4722 @item TAR_MODE
4723 File mode, an octal number.
4724
4725 @vrindex TAR_FILENAME, to-command environment
4726 @item TAR_FILENAME
4727 The name of the file.
4728
4729 @vrindex TAR_REALNAME, to-command environment
4730 @item TAR_REALNAME
4731 Name of the file as stored in the archive.
4732
4733 @vrindex TAR_UNAME, to-command environment
4734 @item TAR_UNAME
4735 Name of the file owner.
4736
4737 @vrindex TAR_GNAME, to-command environment
4738 @item TAR_GNAME
4739 Name of the file owner group.
4740
4741 @vrindex TAR_ATIME, to-command environment
4742 @item TAR_ATIME
4743 Time of last access. It is a decimal number, representing seconds
4744 since the epoch. If the archive provides times with nanosecond
4745 precision, the nanoseconds are appended to the timestamp after a
4746 decimal point.
4747
4748 @vrindex TAR_MTIME, to-command environment
4749 @item TAR_MTIME
4750 Time of last modification.
4751
4752 @vrindex TAR_CTIME, to-command environment
4753 @item TAR_CTIME
4754 Time of last status change.
4755
4756 @vrindex TAR_SIZE, to-command environment
4757 @item TAR_SIZE
4758 Size of the file.
4759
4760 @vrindex TAR_UID, to-command environment
4761 @item TAR_UID
4762 UID of the file owner.
4763
4764 @vrindex TAR_GID, to-command environment
4765 @item TAR_GID
4766 GID of the file owner.
4767 @end table
4768
4769 In addition to these variables, @env{TAR_VERSION} contains the
4770 @GNUTAR{} version number.
4771
4772 If @var{command} exits with a non-0 status, @command{tar} will print
4773 an error message similar to the following:
4774
4775 @smallexample
4776 tar: 2345: Child returned status 1
4777 @end smallexample
4778
4779 Here, @samp{2345} is the PID of the finished process.
4780
4781 If this behavior is not wanted, use @option{--ignore-command-error}:
4782
4783 @table @option
4784 @opindex ignore-command-error
4785 @item --ignore-command-error
4786 Ignore exit codes of subprocesses. Notice that if the program
4787 exits on signal or otherwise terminates abnormally, the error message
4788 will be printed even if this option is used.
4789
4790 @opindex no-ignore-command-error
4791 @item --no-ignore-command-error
4792 Cancel the effect of any previous @option{--ignore-command-error}
4793 option. This option is useful if you have set
4794 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4795 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4796 @end table
4797
4798 @node remove files
4799 @unnumberedsubsubsec Removing Files
4800
4801 @FIXME{The section is too terse. Something more to add? An example,
4802 maybe?}
4803
4804 @table @option
4805 @opindex remove-files
4806 @item --remove-files
4807 Remove files after adding them to the archive.
4808 @end table
4809
4810 @node Scarce
4811 @subsection Coping with Scarce Resources
4812 @UNREVISED
4813
4814 @cindex Small memory
4815 @cindex Running out of space
4816
4817 @menu
4818 * Starting File::
4819 * Same Order::
4820 @end menu
4821
4822 @node Starting File
4823 @unnumberedsubsubsec Starting File
4824
4825 @table @option
4826 @opindex starting-file
4827 @item --starting-file=@var{name}
4828 @itemx -K @var{name}
4829 Starts an operation in the middle of an archive. Use in conjunction
4830 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4831 @end table
4832
4833 @cindex Middle of the archive, starting in the
4834 If a previous attempt to extract files failed due to lack of disk
4835 space, you can use @option{--starting-file=@var{name}} (@option{-K
4836 @var{name}}) to start extracting only after member @var{name} of the
4837 archive. This assumes, of course, that there is now free space, or
4838 that you are now extracting into a different file system. (You could
4839 also choose to suspend @command{tar}, remove unnecessary files from
4840 the file system, and then restart the same @command{tar} operation.
4841 In this case, @option{--starting-file} is not necessary.
4842 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4843
4844 @node Same Order
4845 @unnumberedsubsubsec Same Order
4846
4847 @table @option
4848 @cindex Large lists of file names on small machines
4849 @opindex same-order
4850 @opindex preserve-order
4851 @item --same-order
4852 @itemx --preserve-order
4853 @itemx -s
4854 To process large lists of file names on machines with small amounts of
4855 memory. Use in conjunction with @option{--compare} (@option{--diff},
4856 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4857 (@option{--get}, @option{-x}).
4858 @end table
4859
4860 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4861 names to be listed or extracted is sorted in the same order as the
4862 files in the archive. This allows a large list of names to be used,
4863 even on a small machine that would not otherwise be able to hold all
4864 the names in memory at the same time. Such a sorted list can easily be
4865 created by running @samp{tar -t} on the archive and editing its output.
4866
4867 This option is probably never needed on modern computer systems.
4868
4869 @node backup
4870 @section Backup options
4871
4872 @cindex backup options
4873
4874 @GNUTAR{} offers options for making backups of files
4875 before writing new versions. These options control the details of
4876 these backups. They may apply to the archive itself before it is
4877 created or rewritten, as well as individual extracted members. Other
4878 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4879 and @command{mv}, for example) offer similar options.
4880
4881 Backup options may prove unexpectedly useful when extracting archives
4882 containing many members having identical name, or when extracting archives
4883 on systems having file name limitations, making different members appear
4884 has having similar names through the side-effect of name truncation.
4885 (This is true only if we have a good scheme for truncated backup names,
4886 which I'm not sure at all: I suspect work is needed in this area.)
4887 When any existing file is backed up before being overwritten by extraction,
4888 then clashing files are automatically be renamed to be unique, and the
4889 true name is kept for only the last file of a series of clashing files.
4890 By using verbose mode, users may track exactly what happens.
4891
4892 At the detail level, some decisions are still experimental, and may
4893 change in the future, we are waiting comments from our users. So, please
4894 do not learn to depend blindly on the details of the backup features.
4895 For example, currently, directories themselves are never renamed through
4896 using these options, so, extracting a file over a directory still has
4897 good chances to fail. Also, backup options apply to created archives,
4898 not only to extracted members. For created archives, backups will not
4899 be attempted when the archive is a block or character device, or when it
4900 refers to a remote file.
4901
4902 For the sake of simplicity and efficiency, backups are made by renaming old
4903 files prior to creation or extraction, and not by copying. The original
4904 name is restored if the file creation fails. If a failure occurs after a
4905 partial extraction of a file, both the backup and the partially extracted
4906 file are kept.
4907
4908 @table @samp
4909 @item --backup[=@var{method}]
4910 @opindex backup
4911 @vindex VERSION_CONTROL
4912 @cindex backups
4913 Back up files that are about to be overwritten or removed.
4914 Without this option, the original versions are destroyed.
4915
4916 Use @var{method} to determine the type of backups made.
4917 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
4918 environment variable. And if @env{VERSION_CONTROL} is not set,
4919 use the @samp{existing} method.
4920
4921 @vindex version-control @r{Emacs variable}
4922 This option corresponds to the Emacs variable @samp{version-control};
4923 the same values for @var{method} are accepted as in Emacs. This option
4924 also allows more descriptive names. The valid @var{method}s are:
4925
4926 @table @samp
4927 @item t
4928 @itemx numbered
4929 @cindex numbered @r{backup method}
4930 Always make numbered backups.
4931
4932 @item nil
4933 @itemx existing
4934 @cindex existing @r{backup method}
4935 Make numbered backups of files that already have them, simple backups
4936 of the others.
4937
4938 @item never
4939 @itemx simple
4940 @cindex simple @r{backup method}
4941 Always make simple backups.
4942
4943 @end table
4944
4945 @item --suffix=@var{suffix}
4946 @opindex suffix
4947 @cindex backup suffix
4948 @vindex SIMPLE_BACKUP_SUFFIX
4949 Append @var{suffix} to each backup file made with @option{--backup}. If this
4950 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
4951 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
4952 set, the default is @samp{~}, just as in Emacs.
4953
4954 @end table
4955
4956 Some people express the desire to @emph{always} use the @option{--backup}
4957 option, by defining some kind of alias or script. This is not as easy
4958 as one may think, due to the fact that old style options should appear first
4959 and consume arguments a bit unpredictably for an alias or script. But,
4960 if you are ready to give up using old style options, you may resort to
4961 using something like (a Bourne shell function here):
4962
4963 @smallexample
4964 tar () @{ /usr/local/bin/tar --backup $*; @}
4965 @end smallexample
4966
4967 @node Applications
4968 @section Notable @command{tar} Usages
4969 @UNREVISED
4970
4971 @FIXME{Using Unix file linking capability to recreate directory
4972 structures---linking files into one subdirectory and then
4973 @command{tar}ring that directory.}
4974
4975 @FIXME{Nice hairy example using absolute-names, newer, etc.}
4976
4977 @findex uuencode
4978 You can easily use archive files to transport a group of files from
4979 one system to another: put all relevant files into an archive on one
4980 computer system, transfer the archive to another system, and extract
4981 the contents there. The basic transfer medium might be magnetic tape,
4982 Internet FTP, or even electronic mail (though you must encode the
4983 archive with @command{uuencode} in order to transport it properly by
4984 mail). Both machines do not have to use the same operating system, as
4985 long as they both support the @command{tar} program.
4986
4987 For example, here is how you might copy a directory's contents from
4988 one disk to another, while preserving the dates, modes, owners and
4989 link-structure of all the files therein. In this case, the transfer
4990 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
4991
4992 @smallexample
4993 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
4994 @end smallexample
4995
4996 @noindent
4997 You can avoid subshells by using @option{-C} option:
4998
4999 @smallexample
5000 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5001 @end smallexample
5002
5003 @noindent
5004 The command also works using short option forms:
5005
5006 @smallexample
5007 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5008 | (cd targetdir; tar --extract --file=-)}
5009 # Or:
5010 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5011 | tar --directory targetdir --extract --file=-}
5012 @end smallexample
5013
5014 @noindent
5015 This is one of the easiest methods to transfer a @command{tar} archive.
5016
5017 @node looking ahead
5018 @section Looking Ahead: The Rest of this Manual
5019
5020 You have now seen how to use all eight of the operations available to
5021 @command{tar}, and a number of the possible options. The next chapter
5022 explains how to choose and change file and archive names, how to use
5023 files to store names of other files which you can then call as
5024 arguments to @command{tar} (this can help you save time if you expect to
5025 archive the same list of files a number of times), and so forth.
5026 @FIXME{in case it's not obvious, i'm making this up in some sense
5027 based on my limited memory of what the next chapter *really* does. i
5028 just wanted to flesh out this final section a little bit so i'd
5029 remember to stick it in here. :-)}
5030
5031 If there are too many files to conveniently list on the command line,
5032 you can list the names in a file, and @command{tar} will read that file.
5033 @xref{files}.
5034
5035 There are various ways of causing @command{tar} to skip over some files,
5036 and not archive them. @xref{Choosing}.
5037
5038 @node Backups
5039 @chapter Performing Backups and Restoring Files
5040 @UNREVISED
5041
5042 @GNUTAR{} is distributed along with the scripts
5043 which the Free Software Foundation uses for performing backups. There
5044 is no corresponding scripts available yet for doing restoration of
5045 files. Even if there is a good chance those scripts may be satisfying
5046 to you, they are not the only scripts or methods available for doing
5047 backups and restore. You may well create your own, or use more
5048 sophisticated packages dedicated to that purpose.
5049
5050 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5051 Automatic Network Disk Archiver), a backup system developed by James
5052 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5053 This is free software, and it is available at these places:
5054
5055 @smallexample
5056 http://www.cs.umd.edu/projects/amanda/amanda.html
5057 ftp://ftp.cs.umd.edu/pub/amanda
5058 @end smallexample
5059
5060 @FIXME{
5061
5062 Here is a possible plan for a future documentation about the backuping
5063 scripts which are provided within the @GNUTAR{}
5064 distribution.
5065
5066 @itemize @bullet
5067 @item dumps
5068 @itemize @minus
5069 @item what are dumps
5070 @item different levels of dumps
5071 @itemize +
5072 @item full dump = dump everything
5073 @item level 1, level 2 dumps etc
5074 A level @var{n} dump dumps everything changed since the last level
5075 @var{n}-1 dump (?)
5076 @end itemize
5077 @item how to use scripts for dumps (ie, the concept)
5078 @itemize +
5079 @item scripts to run after editing backup specs (details)
5080 @end itemize
5081 @item Backup Specs, what is it.
5082 @itemize +
5083 @item how to customize
5084 @item actual text of script [/sp/dump/backup-specs]
5085 @end itemize
5086 @item Problems
5087 @itemize +
5088 @item rsh doesn't work
5089 @item rtape isn't installed
5090 @item (others?)
5091 @end itemize
5092 @item the @option{--incremental} option of tar
5093 @item tapes
5094 @itemize +
5095 @item write protection
5096 @item types of media, different sizes and types, useful for different things
5097 @item files and tape marks
5098 one tape mark between files, two at end.
5099 @item positioning the tape
5100 MT writes two at end of write,
5101 backspaces over one when writing again.
5102 @end itemize
5103 @end itemize
5104 @end itemize
5105 }
5106
5107 This chapter documents both the provided shell scripts and @command{tar}
5108 options which are more specific to usage as a backup tool.
5109
5110 To @dfn{back up} a file system means to create archives that contain
5111 all the files in that file system. Those archives can then be used to
5112 restore any or all of those files (for instance if a disk crashes or a
5113 file is accidentally deleted). File system @dfn{backups} are also
5114 called @dfn{dumps}.
5115
5116 @menu
5117 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5118 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5119 * Backup Levels:: Levels of Backups
5120 * Backup Parameters:: Setting Parameters for Backups and Restoration
5121 * Scripted Backups:: Using the Backup Scripts
5122 * Scripted Restoration:: Using the Restore Script
5123 @end menu
5124
5125 @node Full Dumps
5126 @section Using @command{tar} to Perform Full Dumps
5127 @UNREVISED
5128
5129 @cindex full dumps
5130 @cindex dumps, full
5131
5132 @cindex corrupted archives
5133 Full dumps should only be made when no other people or programs
5134 are modifying files in the file system. If files are modified while
5135 @command{tar} is making the backup, they may not be stored properly in
5136 the archive, in which case you won't be able to restore them if you
5137 have to. (Files not being modified are written with no trouble, and do
5138 not corrupt the entire archive.)
5139
5140 You will want to use the @option{--label=@var{archive-label}}
5141 (@option{-V @var{archive-label}}) option to give the archive a
5142 volume label, so you can tell what this archive is even if the label
5143 falls off the tape, or anything like that.
5144
5145 Unless the file system you are dumping is guaranteed to fit on
5146 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5147 Make sure you have enough tapes on hand to complete the backup.
5148
5149 If you want to dump each file system separately you will need to use
5150 the @option{--one-file-system} option to prevent
5151 @command{tar} from crossing file system boundaries when storing
5152 (sub)directories.
5153
5154 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5155 option is not needed, since this is a complete copy of everything in
5156 the file system, and a full restore from this backup would only be
5157 done onto a completely
5158 empty disk.
5159
5160 Unless you are in a hurry, and trust the @command{tar} program (and your
5161 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5162 option, to make sure your files really made it onto the dump properly.
5163 This will also detect cases where the file was modified while (or just
5164 after) it was being archived. Not all media (notably cartridge tapes)
5165 are capable of being verified, unfortunately.
5166
5167 @node Incremental Dumps
5168 @section Using @command{tar} to Perform Incremental Dumps
5169
5170 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5171 stores additional metadata so that exact state of the file system
5172 can be restored when extracting the archive.
5173
5174 @GNUTAR{} currently offers two options for handling incremental
5175 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5176 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5177
5178 @opindex listed-incremental
5179 The option @option{--listed-incremental} instructs tar to operate on
5180 an incremental archive with additional metadata stored in a standalone
5181 file, called a @dfn{snapshot file}. The purpose of this file is to help
5182 determine which files have been changed, added or deleted since the
5183 last backup, so that the next incremental backup will contain only
5184 modified files. The name of the snapshot file is given as an argument
5185 to the option:
5186
5187 @table @option
5188 @item --listed-incremental=@var{file}
5189 @itemx -g @var{file}
5190 Handle incremental backups with snapshot data in @var{file}.
5191 @end table
5192
5193 To create an incremental backup, you would use
5194 @option{--listed-incremental} together with @option{--create}
5195 (@pxref{create}). For example:
5196
5197 @smallexample
5198 $ @kbd{tar --create \
5199 --file=archive.1.tar \
5200 --listed-incremental=/var/log/usr.snar \
5201 /usr}
5202 @end smallexample
5203
5204 This will create in @file{archive.1.tar} an incremental backup of
5205 the @file{/usr} file system, storing additional metadata in the file
5206 @file{/var/log/usr.snar}. If this file does not exist, it will be
5207 created. The created archive will then be a @dfn{level 0 backup};
5208 please see the next section for more on backup levels.
5209
5210 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5211 determines which files are modified. In this case only these files will be
5212 stored in the archive. Suppose, for example, that after running the
5213 above command, you delete file @file{/usr/doc/old} and create
5214 directory @file{/usr/local/db} with the following contents:
5215
5216 @smallexample
5217 $ @kbd{ls /usr/local/db}
5218 /usr/local/db/data
5219 /usr/local/db/index
5220 @end smallexample
5221
5222 Some time later you create another incremental backup. You will
5223 then see:
5224
5225 @smallexample
5226 $ @kbd{tar --create \
5227 --file=archive.2.tar \
5228 --listed-incremental=/var/log/usr.snar \
5229 /usr}
5230 tar: usr/local/db: Directory is new
5231 usr/local/db/
5232 usr/local/db/data
5233 usr/local/db/index
5234 @end smallexample
5235
5236 @noindent
5237 The created archive @file{archive.2.tar} will contain only these
5238 three members. This archive is called a @dfn{level 1 backup}. Notice
5239 that @file{/var/log/usr.snar} will be updated with the new data, so if
5240 you plan to create more @samp{level 1} backups, it is necessary to
5241 create a working copy of the snapshot file before running
5242 @command{tar}. The above example will then be modified as follows:
5243
5244 @smallexample
5245 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5246 $ @kbd{tar --create \
5247 --file=archive.2.tar \
5248 --listed-incremental=/var/log/usr.snar-1 \
5249 /usr}
5250 @end smallexample
5251
5252 Incremental dumps depend crucially on time stamps, so the results are
5253 unreliable if you modify a file's time stamps during dumping (e.g.,
5254 with the @option{--atime-preserve=replace} option), or if you set the clock
5255 backwards.
5256
5257 Metadata stored in snapshot files include device numbers, which,
5258 obviously is supposed to be a non-volatile value. However, it turns
5259 out that NFS devices have undependable values when an automounter
5260 gets in the picture. This can lead to a great deal of spurious
5261 redumping in incremental dumps, so it is somewhat useless to compare
5262 two NFS devices numbers over time. The solution implemented currently
5263 is to considers all NFS devices as being equal when it comes to
5264 comparing directories; this is fairly gross, but there does not seem
5265 to be a better way to go.
5266
5267 Note that incremental archives use @command{tar} extensions and may
5268 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5269
5270 @opindex listed-incremental, using with @option{--extract}
5271 @opindex extract, using with @option{--listed-incremental}
5272 To extract from the incremental dumps, use
5273 @option{--listed-incremental} together with @option{--extract}
5274 option (@pxref{extracting files}). In this case, @command{tar} does
5275 not need to access snapshot file, since all the data necessary for
5276 extraction are stored in the archive itself. So, when extracting, you
5277 can give whatever argument to @option{--listed-incremental}, the usual
5278 practice is to use @option{--listed-incremental=/dev/null}.
5279 Alternatively, you can use @option{--incremental}, which needs no
5280 arguments. In general, @option{--incremental} (@option{-G}) can be
5281 used as a shortcut for @option{--listed-incremental} when listing or
5282 extracting incremental backups (for more information, regarding this
5283 option, @pxref{incremental-op}).
5284
5285 When extracting from the incremental backup @GNUTAR{} attempts to
5286 restore the exact state the file system had when the archive was
5287 created. In particular, it will @emph{delete} those files in the file
5288 system that did not exist in their directories when the archive was
5289 created. If you have created several levels of incremental files,
5290 then in order to restore the exact contents the file system had when
5291 the last level was created, you will need to restore from all backups
5292 in turn. Continuing our example, to restore the state of @file{/usr}
5293 file system, one would do@footnote{Notice, that since both archives
5294 were created withouth @option{-P} option (@pxref{absolute}), these
5295 commands should be run from the root file system.}:
5296
5297 @smallexample
5298 $ @kbd{tar --extract \
5299 --listed-incremental=/dev/null \
5300 --file archive.1.tar}
5301 $ @kbd{tar --extract \
5302 --listed-incremental=/dev/null \
5303 --file archive.2.tar}
5304 @end smallexample
5305
5306 To list the contents of an incremental archive, use @option{--list}
5307 (@pxref{list}), as usual. To obtain more information about the
5308 archive, use @option{--listed-incremental} or @option{--incremental}
5309 combined with two @option{--verbose} options@footnote{Two
5310 @option{--verbose} options were selected to avoid breaking usual
5311 verbose listing output (@option{--list --verbose}) when using in
5312 scripts.
5313
5314 @opindex incremental, using with @option{--list}
5315 @opindex listed-incremental, using with @option{--list}
5316 @opindex list, using with @option{--incremental}
5317 @opindex list, using with @option{--listed-incremental}
5318 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5319 contents of the DUMPDIR header (with terminating nulls) when
5320 @option{--incremental} or @option{--listed-incremental} option was
5321 given, no matter what the verbosity level. This behavior, and,
5322 especially, the binary output it produced were considered incovenient
5323 and were changed in version 1.16}:
5324
5325 @smallexample
5326 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5327 @end smallexample
5328
5329 This command will print, for each directory in the archive, the list
5330 of files in that directory at the time the archive was created. This
5331 information is put out in a format which is both human-readable and
5332 unambiguous for a program: each file name is printed as
5333
5334 @smallexample
5335 @var{x} @var{file}
5336 @end smallexample
5337
5338 @noindent
5339 where @var{x} is a letter describing the status of the file: @samp{Y}
5340 if the file is present in the archive, @samp{N} if the file is not
5341 included in the archive, or a @samp{D} if the file is a directory (and
5342 is included in the archive). @xref{Dumpdir}, for the detailed
5343 description of dumpdirs and status codes. Each such
5344 line is terminated by a newline character. The last line is followed
5345 by an additional newline to indicate the end of the data.
5346
5347 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5348 gives the same behavior as @option{--listed-incremental} when used
5349 with @option{--list} and @option{--extract} options. When used with
5350 @option{--create} option, it creates an incremental archive without
5351 creating snapshot file. Thus, it is impossible to create several
5352 levels of incremental backups with @option{--incremental} option.
5353
5354 @node Backup Levels
5355 @section Levels of Backups
5356
5357 An archive containing all the files in the file system is called a
5358 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5359 creating a full dump every day. This strategy, however, would waste a
5360 substantial amount of archive media and user time, as unchanged files
5361 are daily re-archived.
5362
5363 It is more efficient to do a full dump only occasionally. To back up
5364 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5365 one} dump archives all the files that have changed since the last full
5366 dump.
5367
5368 A typical dump strategy would be to perform a full dump once a week,
5369 and a level one dump once a day. This means some versions of files
5370 will in fact be archived more than once, but this dump strategy makes
5371 it possible to restore a file system to within one day of accuracy by
5372 only extracting two archives---the last weekly (full) dump and the
5373 last daily (level one) dump. The only information lost would be in
5374 files changed or created since the last daily backup. (Doing dumps
5375 more than once a day is usually not worth the trouble).
5376
5377 @GNUTAR{} comes with scripts you can use to do full
5378 and level-one (actually, even level-two and so on) dumps. Using
5379 scripts (shell programs) to perform backups and restoration is a
5380 convenient and reliable alternative to typing out file name lists
5381 and @command{tar} commands by hand.
5382
5383 Before you use these scripts, you need to edit the file
5384 @file{backup-specs}, which specifies parameters used by the backup
5385 scripts and by the restore script. This file is usually located
5386 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5387 detailed description. Once the backup parameters are set, you can
5388 perform backups or restoration by running the appropriate script.
5389
5390 The name of the backup script is @code{backup}. The name of the
5391 restore script is @code{restore}. The following sections describe
5392 their use in detail.
5393
5394 @emph{Please Note:} The backup and restoration scripts are
5395 designed to be used together. While it is possible to restore files by
5396 hand from an archive which was created using a backup script, and to create
5397 an archive by hand which could then be extracted using the restore script,
5398 it is easier to use the scripts. @xref{Incremental Dumps}, before
5399 making such an attempt.
5400
5401 @node Backup Parameters
5402 @section Setting Parameters for Backups and Restoration
5403
5404 The file @file{backup-specs} specifies backup parameters for the
5405 backup and restoration scripts provided with @command{tar}. You must
5406 edit @file{backup-specs} to fit your system configuration and schedule
5407 before using these scripts.
5408
5409 Syntactically, @file{backup-specs} is a shell script, containing
5410 mainly variable assignments. However, any valid shell construct
5411 is allowed in this file. Particularly, you may wish to define
5412 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5413 For more information about shell script syntax, please refer to
5414 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5415 g_02, the definition of the Shell Command Language}. See also
5416 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5417
5418 The shell variables controlling behavior of @code{backup} and
5419 @code{restore} are described in the following subsections.
5420
5421 @menu
5422 * General-Purpose Variables::
5423 * Magnetic Tape Control::
5424 * User Hooks::
5425 * backup-specs example:: An Example Text of @file{Backup-specs}
5426 @end menu
5427
5428 @node General-Purpose Variables
5429 @subsection General-Purpose Variables
5430
5431 @defvr {Backup variable} ADMINISTRATOR
5432 The user name of the backup administrator. @code{Backup} scripts
5433 sends a backup report to this address.
5434 @end defvr
5435
5436 @defvr {Backup variable} BACKUP_HOUR
5437 The hour at which the backups are done. This can be a number from 0
5438 to 23, or the time specification in form @var{hours}:@var{minutes},
5439 or the string @samp{now}.
5440
5441 This variable is used by @code{backup}. Its value may be overridden
5442 using @option{--time} option (@pxref{Scripted Backups}).
5443 @end defvr
5444
5445 @defvr {Backup variable} TAPE_FILE
5446
5447 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5448 is a remote archive (@pxref{remote-dev}), backup script will suppose
5449 that your @command{mt} is able to access remote devices. If @var{RSH}
5450 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5451 invocations of @command{mt}.
5452 @end defvr
5453
5454 @defvr {Backup variable} BLOCKING
5455
5456 The blocking factor @command{tar} will use when writing the dump archive.
5457 @xref{Blocking Factor}.
5458 @end defvr
5459
5460 @defvr {Backup variable} BACKUP_DIRS
5461
5462 A list of file systems to be dumped (for @code{backup}), or restored
5463 (for @code{restore}). You can include any directory
5464 name in the list --- subdirectories on that file system will be
5465 included, regardless of how they may look to other networked machines.
5466 Subdirectories on other file systems will be ignored.
5467
5468 The host name specifies which host to run @command{tar} on, and should
5469 normally be the host that actually contains the file system. However,
5470 the host machine must have @GNUTAR{} installed, and
5471 must be able to access the directory containing the backup scripts and
5472 their support files using the same file name that is used on the
5473 machine where the scripts are run (ie. what @command{pwd} will print
5474 when in that directory on that machine). If the host that contains
5475 the file system does not have this capability, you can specify another
5476 host as long as it can access the file system through NFS.
5477
5478 If the list of file systems is very long you may wish to put it
5479 in a separate file. This file is usually named
5480 @file{/etc/backup/dirs}, but this name may be overridden in
5481 @file{backup-specs} using @code{DIRLIST} variable.
5482 @end defvr
5483
5484 @defvr {Backup variable} DIRLIST
5485
5486 A path to the file containing the list of the file systems to backup
5487 or restore. By default it is @file{/etc/backup/dirs}.
5488 @end defvr
5489
5490 @defvr {Backup variable} BACKUP_FILES
5491
5492 A list of individual files to be dumped (for @code{backup}), or restored
5493 (for @code{restore}). These should be accessible from the machine on
5494 which the backup script is run.
5495
5496 If the list of file systems is very long you may wish to store it
5497 in a separate file. This file is usually named
5498 @file{/etc/backup/files}, but this name may be overridden in
5499 @file{backup-specs} using @code{FILELIST} variable.
5500 @end defvr
5501
5502 @defvr {Backup variable} FILELIST
5503
5504 A path to the file containing the list of the individual files to backup
5505 or restore. By default it is @file{/etc/backup/files}.
5506 @end defvr
5507
5508 @defvr {Backup variable} MT
5509
5510 Full file name of @command{mt} binary.
5511 @end defvr
5512
5513 @defvr {Backup variable} RSH
5514 @anchor{RSH}
5515 Full file name of @command{rsh} binary or its equivalent. You may wish to
5516 set it to @code{ssh}, to improve security. In this case you will have
5517 to use public key authentication.
5518 @end defvr
5519
5520 @defvr {Backup variable} RSH_COMMAND
5521
5522 Full file name of @command{rsh} binary on remote mashines. This will
5523 be passed via @option{--rsh-command} option to the remote invocation
5524 of @GNUTAR{}.
5525 @end defvr
5526
5527 @defvr {Backup variable} VOLNO_FILE
5528
5529 Name of temporary file to hold volume numbers. This needs to be accessible
5530 by all the machines which have file systems to be dumped.
5531 @end defvr
5532
5533 @defvr {Backup variable} XLIST
5534
5535 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5536 located on the remote machine and containing the list of files to
5537 be excluded from the backup. Exclude file lists are searched in
5538 /etc/tar-backup directory. A common use for exclude file lists
5539 is to exclude files containing security-sensitive information
5540 (e.g., @file{/etc/shadow} from backups).
5541
5542 This variable affects only @code{backup}.
5543 @end defvr
5544
5545 @defvr {Backup variable} SLEEP_TIME
5546
5547 Time to sleep between dumps of any two successive file systems
5548
5549 This variable affects only @code{backup}.
5550 @end defvr
5551
5552 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5553
5554 Script to be run when it's time to insert a new tape in for the next
5555 volume. Administrators may want to tailor this script for their site.
5556 If this variable isn't set, @GNUTAR{} will display its built-in
5557 prompt, and will expect confirmation from the console.
5558
5559 The built-in prompt for POSIX locale is:
5560
5561 @smallexample
5562 Prepare volume #@var{n} for `@var{archive}' and hit return:
5563 @end smallexample
5564
5565 @noindent
5566 where @var{n} is the ordinal number of the volume to be created and
5567 @var{archive} is archive file or device name.
5568
5569 If you run @GNUTAR{} under a different locale, the translation of
5570 the above prompt to the locale's language will be used.
5571
5572 @end defvr
5573
5574 @defvr {Backup variable} SLEEP_MESSAGE
5575
5576 Message to display on the terminal while waiting for dump time. Usually
5577 this will just be some literal text.
5578 @end defvr
5579
5580 @defvr {Backup variable} TAR
5581
5582 Full file name of the @GNUTAR{} executable. If this is not set, backup
5583 scripts will search @command{tar} in the current shell path.
5584 @end defvr
5585
5586 @node Magnetic Tape Control
5587 @subsection Magnetic Tape Control
5588
5589 Backup scripts access tape device using special @dfn{hook functions}.
5590 These functions take a single argument -- the name of the tape
5591 device. Their names are kept in the following variables:
5592
5593 @defvr {Backup variable} MT_BEGIN
5594 The name of @dfn{begin} function. This function is called before
5595 accessing the drive. By default it retensions the tape:
5596
5597 @smallexample
5598 MT_BEGIN=mt_begin
5599
5600 mt_begin() @{
5601 mt -f "$1" retension
5602 @}
5603 @end smallexample
5604 @end defvr
5605
5606 @defvr {Backup variable} MT_REWIND
5607 The name of @dfn{rewind} function. The default definition is as
5608 follows:
5609
5610 @smallexample
5611 MT_REWIND=mt_rewind
5612
5613 mt_rewind() @{
5614 mt -f "$1" rewind
5615 @}
5616 @end smallexample
5617
5618 @end defvr
5619
5620 @defvr {Backup variable} MT_OFFLINE
5621 The name of the function switching the tape off line. By default
5622 it is defined as follows:
5623
5624 @smallexample
5625 MT_OFFLINE=mt_offline
5626
5627 mt_offline() @{
5628 mt -f "$1" offl
5629 @}
5630 @end smallexample
5631 @end defvr
5632
5633 @defvr {Backup variable} MT_STATUS
5634 The name of the function used to obtain the status of the archive device,
5635 including error count. Default definition:
5636
5637 @smallexample
5638 MT_STATUS=mt_status
5639
5640 mt_status() @{
5641 mt -f "$1" status
5642 @}
5643 @end smallexample
5644 @end defvr
5645
5646 @node User Hooks
5647 @subsection User Hooks
5648
5649 @dfn{User hooks} are shell functions executed before and after
5650 each @command{tar} invocation. Thus, there are @dfn{backup
5651 hooks}, which are executed before and after dumping each file
5652 system, and @dfn{restore hooks}, executed before and
5653 after restoring a file system. Each user hook is a shell function
5654 taking four arguments:
5655
5656 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5657 Its arguments are:
5658
5659 @table @var
5660 @item level
5661 Current backup or restore level.
5662
5663 @item host
5664 Name or IP address of the host machine being dumped or restored.
5665
5666 @item fs
5667 Full path name to the file system being dumped or restored.
5668
5669 @item fsname
5670 File system name with directory separators replaced with colons. This
5671 is useful, e.g., for creating unique files.
5672 @end table
5673 @end deffn
5674
5675 Following variables keep the names of user hook functions
5676
5677 @defvr {Backup variable} DUMP_BEGIN
5678 Dump begin function. It is executed before dumping the file system.
5679 @end defvr
5680
5681 @defvr {Backup variable} DUMP_END
5682 Executed after dumping the file system.
5683 @end defvr
5684
5685 @defvr {Backup variable} RESTORE_BEGIN
5686 Executed before restoring the file system.
5687 @end defvr
5688
5689 @defvr {Backup variable} RESTORE_END
5690 Executed after restoring the file system.
5691 @end defvr
5692
5693 @node backup-specs example
5694 @subsection An Example Text of @file{Backup-specs}
5695
5696 The following is an example of @file{backup-specs}:
5697
5698 @smallexample
5699 # site-specific parameters for file system backup.
5700
5701 ADMINISTRATOR=friedman
5702 BACKUP_HOUR=1
5703 TAPE_FILE=/dev/nrsmt0
5704
5705 # Use @code{ssh} instead of the less secure @code{rsh}
5706 RSH=/usr/bin/ssh
5707 RSH_COMMAND=/usr/bin/ssh
5708
5709 # Override MT_STATUS function:
5710 my_status() @{
5711 mts -t $TAPE_FILE
5712 @}
5713 MT_STATUS=my_status
5714
5715 # Disable MT_OFFLINE function
5716 MT_OFFLINE=:
5717
5718 BLOCKING=124
5719 BACKUP_DIRS="
5720 albert:/fs/fsf
5721 apple-gunkies:/gd
5722 albert:/fs/gd2
5723 albert:/fs/gp
5724 geech:/usr/jla
5725 churchy:/usr/roland
5726 albert:/
5727 albert:/usr
5728 apple-gunkies:/
5729 apple-gunkies:/usr
5730 gnu:/hack
5731 gnu:/u
5732 apple-gunkies:/com/mailer/gnu
5733 apple-gunkies:/com/archive/gnu"
5734
5735 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5736
5737 @end smallexample
5738
5739 @node Scripted Backups
5740 @section Using the Backup Scripts
5741
5742 The syntax for running a backup script is:
5743
5744 @smallexample
5745 backup --level=@var{level} --time=@var{time}
5746 @end smallexample
5747
5748 The @option{level} option requests the dump level. Thus, to produce
5749 a full dump, specify @code{--level=0} (this is the default, so
5750 @option{--level} may be omitted if its value is @code{0}).
5751 @footnote{For backward compatibility, the @code{backup} will also
5752 try to deduce the requested dump level from the name of the
5753 script itself. If the name consists of a string @samp{level-}
5754 followed by a single decimal digit, that digit is taken as
5755 the dump level number. Thus, you may create a link from @code{backup}
5756 to @code{level-1} and then run @code{level-1} whenever you need to
5757 create a level one dump.}
5758
5759 The @option{--time} option determines when should the backup be
5760 run. @var{Time} may take three forms:
5761
5762 @table @asis
5763 @item @var{hh}:@var{mm}
5764
5765 The dump must be run at @var{hh} hours @var{mm} minutes.
5766
5767 @item @var{hh}
5768
5769 The dump must be run at @var{hh} hours
5770
5771 @item now
5772
5773 The dump must be run immediately.
5774 @end table
5775
5776 You should start a script with a tape or disk mounted. Once you
5777 start a script, it prompts you for new tapes or disks as it
5778 needs them. Media volumes don't have to correspond to archive
5779 files --- a multi-volume archive can be started in the middle of a
5780 tape that already contains the end of another multi-volume archive.
5781 The @code{restore} script prompts for media by its archive volume,
5782 so to avoid an error message you should keep track of which tape
5783 (or disk) contains which volume of the archive (@pxref{Scripted
5784 Restoration}).
5785
5786 The backup scripts write two files on the file system. The first is a
5787 record file in @file{/etc/tar-backup/}, which is used by the scripts
5788 to store and retrieve information about which files were dumped. This
5789 file is not meant to be read by humans, and should not be deleted by
5790 them. @xref{Snapshot Files}, for a more detailed explanation of this
5791 file.
5792
5793 The second file is a log file containing the names of the file systems
5794 and files dumped, what time the backup was made, and any error
5795 messages that were generated, as well as how much space was left in
5796 the media volume after the last volume of the archive was written.
5797 You should check this log file after every backup. The file name is
5798 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5799 represents current date, and @var{n} represents current dump level number.
5800
5801 The script also prints the name of each system being dumped to the
5802 standard output.
5803
5804 Following is the full list of options accepted by @code{backup}
5805 script:
5806
5807 @table @option
5808 @item -l @var{level}
5809 @itemx --level=@var{level}
5810 Do backup level @var{level} (default 0).
5811
5812 @item -f
5813 @itemx --force
5814 Force backup even if today's log file already exists.
5815
5816 @item -v[@var{level}]
5817 @itemx --verbose[=@var{level}]
5818 Set verbosity level. The higher the level is, the more debugging
5819 information will be output during execution. Devault @var{level}
5820 is 100, which means the highest debugging level.
5821
5822 @item -t @var{start-time}
5823 @itemx --time=@var{start-time}
5824 Wait till @var{time}, then do backup.
5825
5826 @item -h
5827 @itemx --help
5828 Display short help message and exit.
5829
5830 @item -V
5831 @itemx --version
5832 Display information about the program's name, version, origin and legal
5833 status, all on standard output, and then exit successfully.
5834 @end table
5835
5836
5837 @node Scripted Restoration
5838 @section Using the Restore Script
5839
5840 To restore files that were archived using a scripted backup, use the
5841 @code{restore} script. Its usage is quite straightforward. In the
5842 simplest form, invoke @code{restore --all}, it will
5843 then restore all the file systems and files specified in
5844 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5845
5846 You may select the file systems (and/or files) to restore by
5847 giving @code{restore} list of @dfn{patterns} in its command
5848 line. For example, running
5849
5850 @smallexample
5851 restore 'albert:*'
5852 @end smallexample
5853
5854 @noindent
5855 will restore all file systems on the machine @samp{albert}. A more
5856 complicated example:
5857
5858 @smallexample
5859 restore 'albert:*' '*:/var'
5860 @end smallexample
5861
5862 @noindent
5863 This command will restore all file systems on the machine @samp{albert}
5864 as well as @file{/var} file system on all machines.
5865
5866 By default @code{restore} will start restoring files from the lowest
5867 available dump level (usually zero) and will continue through
5868 all available dump levels. There may be situations where such a
5869 thorough restore is not necessary. For example, you may wish to
5870 restore only files from the recent level one backup. To do so,
5871 use @option{--level} option, as shown in the example below:
5872
5873 @smallexample
5874 restore --level=1
5875 @end smallexample
5876
5877 The full list of options accepted by @code{restore} follows:
5878
5879 @table @option
5880 @item -a
5881 @itemx --all
5882 Restore all file systems and files specified in @file{backup-specs}
5883
5884 @item -l @var{level}
5885 @itemx --level=@var{level}
5886 Start restoring from the given backup level, instead of the default 0.
5887
5888 @item -v[@var{level}]
5889 @itemx --verbose[=@var{level}]
5890 Set verbosity level. The higher the level is, the more debugging
5891 information will be output during execution. Devault @var{level}
5892 is 100, which means the highest debugging level.
5893
5894 @item -h
5895 @itemx --help
5896 Display short help message and exit.
5897
5898 @item -V
5899 @itemx --version
5900 Display information about the program's name, version, origin and legal
5901 status, all on standard output, and then exit successfully.
5902 @end table
5903
5904 You should start the restore script with the media containing the
5905 first volume of the archive mounted. The script will prompt for other
5906 volumes as they are needed. If the archive is on tape, you don't need
5907 to rewind the tape to to its beginning---if the tape head is
5908 positioned past the beginning of the archive, the script will rewind
5909 the tape as needed. @FIXME-xref{Media, for a discussion of tape
5910 positioning.}
5911
5912 @quotation
5913 @strong{Warning:} The script will delete files from the active file
5914 system if they were not in the file system when the archive was made.
5915 @end quotation
5916
5917 @xref{Incremental Dumps}, for an explanation of how the script makes
5918 that determination.
5919
5920 @node Choosing
5921 @chapter Choosing Files and Names for @command{tar}
5922 @UNREVISED
5923
5924 Certain options to @command{tar} enable you to specify a name for your
5925 archive. Other options let you decide which files to include or exclude
5926 from the archive, based on when or whether files were modified, whether
5927 the file names do or don't match specified patterns, or whether files
5928 are in specified directories.
5929
5930 This chapter discusses these options in detail.
5931
5932 @menu
5933 * file:: Choosing the Archive's Name
5934 * Selecting Archive Members::
5935 * files:: Reading Names from a File
5936 * exclude:: Excluding Some Files
5937 * wildcards:: Wildcards Patterns and Matching
5938 * quoting styles:: Ways of Quoting Special Characters in Names
5939 * transform:: Modifying File and Member Names
5940 * after:: Operating Only on New Files
5941 * recurse:: Descending into Directories
5942 * one:: Crossing File System Boundaries
5943 @end menu
5944
5945 @node file
5946 @section Choosing and Naming Archive Files
5947 @UNREVISED
5948
5949 @cindex Naming an archive
5950 @cindex Archive Name
5951 @cindex Choosing an archive file
5952 @cindex Where is the archive?
5953 By default, @command{tar} uses an archive file name that was compiled when
5954 it was built on the system; usually this name refers to some physical
5955 tape drive on the machine. However, the person who installed @command{tar}
5956 on the system may not have set the default to a meaningful value as far as
5957 most users are concerned. As a result, you will usually want to tell
5958 @command{tar} where to find (or create) the archive. The
5959 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
5960 option allows you to either specify or name a file to use as the archive
5961 instead of the default archive file location.
5962
5963 @table @option
5964 @opindex file, short description
5965 @item --file=@var{archive-name}
5966 @itemx -f @var{archive-name}
5967 Name the archive to create or operate on. Use in conjunction with
5968 any operation.
5969 @end table
5970
5971 For example, in this @command{tar} command,
5972
5973 @smallexample
5974 $ @kbd{tar -cvf collection.tar blues folk jazz}
5975 @end smallexample
5976
5977 @noindent
5978 @file{collection.tar} is the name of the archive. It must directly
5979 follow the @option{-f} option, since whatever directly follows @option{-f}
5980 @emph{will} end up naming the archive. If you neglect to specify an
5981 archive name, you may end up overwriting a file in the working directory
5982 with the archive you create since @command{tar} will use this file's name
5983 for the archive name.
5984
5985 An archive can be saved as a file in the file system, sent through a
5986 pipe or over a network, or written to an I/O device such as a tape,
5987 floppy disk, or CD write drive.
5988
5989 @cindex Writing new archives
5990 @cindex Archive creation
5991 If you do not name the archive, @command{tar} uses the value of the
5992 environment variable @env{TAPE} as the file name for the archive. If
5993 that is not available, @command{tar} uses a default, compiled-in archive
5994 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
5995
5996 @cindex Standard input and output
5997 @cindex tar to standard input and output
5998 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
5999 archive from standard input (when listing or extracting files), or
6000 writes it to standard output (when creating an archive). If you use
6001 @file{-} as an @var{archive-name} when modifying an archive,
6002 @command{tar} reads the original archive from its standard input and
6003 writes the entire new archive to its standard output.
6004
6005 The following example is a convenient way of copying directory
6006 hierarchy from @file{sourcedir} to @file{targetdir}.
6007
6008 @smallexample
6009 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6010 @end smallexample
6011
6012 The @option{-C} option allows to avoid using subshells:
6013
6014 @smallexample
6015 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6016 @end smallexample
6017
6018 In both examples above, the leftmost @command{tar} invocation archives
6019 the contents of @file{sourcedir} to the standard output, while the
6020 rightmost one reads this archive from its standard input and
6021 extracts it. The @option{-p} option tells it to restore permissions
6022 of the extracted files.
6023
6024 @cindex Remote devices
6025 @cindex tar to a remote device
6026 @anchor{remote-dev}
6027 To specify an archive file on a device attached to a remote machine,
6028 use the following:
6029
6030 @smallexample
6031 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6032 @end smallexample
6033
6034 @noindent
6035 @command{tar} will complete the remote connection, if possible, and
6036 prompt you for a username and password. If you use
6037 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6038 will complete the remote connection, if possible, using your username
6039 as the username on the remote machine.
6040
6041 @cindex Local and remote archives
6042 @anchor{local and remote archives}
6043 If the archive file name includes a colon (@samp{:}), then it is assumed
6044 to be a file on another machine. If the archive file is
6045 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6046 host @var{host}. The remote host is accessed using the @command{rsh}
6047 program, with a username of @var{user}. If the username is omitted
6048 (along with the @samp{@@} sign), then your user name will be used.
6049 (This is the normal @command{rsh} behavior.) It is necessary for the
6050 remote machine, in addition to permitting your @command{rsh} access, to
6051 have the @file{rmt} program installed (This command is included in
6052 the @GNUTAR{} distribution and by default is installed under
6053 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6054 installation prefix). If you need to use a file whose name includes a
6055 colon, then the remote tape drive behavior
6056 can be inhibited by using the @option{--force-local} option.
6057
6058 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6059 tries to minimize input and output operations. The Amanda backup
6060 system, when used with @GNUTAR{}, has an initial sizing pass which
6061 uses this feature.
6062
6063 @node Selecting Archive Members
6064 @section Selecting Archive Members
6065 @cindex Specifying files to act on
6066 @cindex Specifying archive members
6067
6068 @dfn{File Name arguments} specify which files in the file system
6069 @command{tar} operates on, when creating or adding to an archive, or which
6070 archive members @command{tar} operates on, when reading or deleting from
6071 an archive. @xref{Operations}.
6072
6073 To specify file names, you can include them as the last arguments on
6074 the command line, as follows:
6075 @smallexample
6076 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6077 @end smallexample
6078
6079 If a file name begins with dash (@samp{-}), precede it with
6080 @option{--add-file} option to prevent it from being treated as an
6081 option.
6082
6083 If you specify a directory name as a file name argument, all the files
6084 in that directory are operated on by @command{tar}.
6085
6086 If you do not specify files, @command{tar} behavior differs depending
6087 on the operation mode as described below:
6088
6089 When @command{tar} is invoked with @option{--create} (@option{-c}),
6090 @command{tar} will stop immediately, reporting the following:
6091
6092 @smallexample
6093 @group
6094 $ @kbd{tar cf a.tar}
6095 tar: Cowardly refusing to create an empty archive
6096 Try `tar --help' or `tar --usage' for more information.
6097 @end group
6098 @end smallexample
6099
6100 If you specify either @option{--list} (@option{-t}) or
6101 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6102 operates on all the archive members in the archive.
6103
6104 If run with @option{--diff} option, tar will compare the archive with
6105 the contents of the current working directory.
6106
6107 If you specify any other operation, @command{tar} does nothing.
6108
6109 By default, @command{tar} takes file names from the command line. However,
6110 there are other ways to specify file or member names, or to modify the
6111 manner in which @command{tar} selects the files or members upon which to
6112 operate. In general, these methods work both for specifying the names
6113 of files and archive members.
6114
6115 @node files
6116 @section Reading Names from a File
6117
6118 @cindex Reading file names from a file
6119 @cindex Lists of file names
6120 @cindex File Name arguments, alternatives
6121 Instead of giving the names of files or archive members on the command
6122 line, you can put the names into a file, and then use the
6123 @option{--files-from=@var{file-of-names}} (@option{-T
6124 @var{file-of-names}}) option to @command{tar}. Give the name of the
6125 file which contains the list of files to include as the argument to
6126 @option{--files-from}. In the list, the file names should be separated by
6127 newlines. You will frequently use this option when you have generated
6128 the list of files to archive with the @command{find} utility.
6129
6130 @table @option
6131 @opindex files-from
6132 @item --files-from=@var{file-name}
6133 @itemx -T @var{file-name}
6134 Get names to extract or create from file @var{file-name}.
6135 @end table
6136
6137 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6138 you specify either @code{--files-from=-} or @code{-T -}), then the file
6139 names are read from standard input.
6140
6141 Unless you are running @command{tar} with @option{--create}, you can not use
6142 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6143 command.
6144
6145 Any number of @option{-T} options can be given in the command line.
6146
6147 The following example shows how to use @command{find} to generate a list of
6148 files smaller than 400K in length and put that list into a file
6149 called @file{small-files}. You can then use the @option{-T} option to
6150 @command{tar} to specify the files from that file, @file{small-files}, to
6151 create the archive @file{little.tgz}. (The @option{-z} option to
6152 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6153 more information.)
6154
6155 @smallexample
6156 $ @kbd{find . -size -400 -print > small-files}
6157 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6158 @end smallexample
6159
6160 @noindent
6161 In the file list given by @option{-T} option, any file name beginning
6162 with @samp{-} character is considered a @command{tar} option and is
6163 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6164 recognized only @option{-C} option in file lists, and only if the
6165 option and its argument occupied two consecutive lines.} For example,
6166 the common use of this feature is to change to another directory by
6167 specifying @option{-C} option:
6168
6169 @smallexample
6170 @group
6171 $ @kbd{cat list}
6172 -C/etc
6173 passwd
6174 hosts
6175 -C/lib
6176 libc.a
6177 $ @kbd{tar -c -f foo.tar --files-from list}
6178 @end group
6179 @end smallexample
6180
6181 @noindent
6182 In this example, @command{tar} will first switch to @file{/etc}
6183 directory and add files @file{passwd} and @file{hosts} to the
6184 archive. Then it will change to @file{/lib} directory and will archive
6185 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6186 contain:
6187
6188 @smallexample
6189 @group
6190 $ @kbd{tar tf foo.tar}
6191 passwd
6192 hosts
6193 libc.a
6194 @end group
6195 @end smallexample
6196
6197 @noindent
6198 @opindex directory, using in @option{--files-from} argument
6199 Notice that the option parsing algorithm used with @option{-T} is
6200 stricter than the one used by shell. Namely, when specifying option
6201 arguments, you should observe the following rules:
6202
6203 @itemize @bullet
6204 @item
6205 When using short (single-letter) option form, its argument must
6206 immediately follow the option letter, without any intervening
6207 whitespace. For example: @code{-Cdir}.
6208
6209 @item
6210 When using long option form, the option argument must be separated
6211 from the option by a single equal sign. No whitespace is allowed on
6212 any side of the equal sign. For example: @code{--directory=dir}.
6213
6214 @item
6215 For both short and long option forms, the option argument can be given
6216 on the next line after the option name, e.g.:
6217
6218 @smallexample
6219 @group
6220 --directory
6221 dir
6222 @end group
6223 @end smallexample
6224
6225 @noindent
6226 and
6227
6228 @smallexample
6229 @group
6230 -C
6231 dir
6232 @end group
6233 @end smallexample
6234 @end itemize
6235
6236 @opindex add-file
6237 If you happen to have a file whose name starts with @samp{-},
6238 precede it with @option{--add-file} option to prevent it from
6239 being recognized as an option. For example: @code{--add-file=--my-file}.
6240
6241 @menu
6242 * nul::
6243 @end menu
6244
6245 @node nul
6246 @subsection @code{NUL} Terminated File Names
6247
6248 @cindex File names, terminated by @code{NUL}
6249 @cindex @code{NUL} terminated file names
6250 The @option{--null} option causes
6251 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6252 to read file names terminated by a @code{NUL} instead of a newline, so
6253 files whose names contain newlines can be archived using
6254 @option{--files-from}.
6255
6256 @table @option
6257 @opindex null
6258 @item --null
6259 Only consider @code{NUL} terminated file names, instead of files that
6260 terminate in a newline.
6261 @end table
6262
6263 The @option{--null} option is just like the one in @acronym{GNU}
6264 @command{xargs} and @command{cpio}, and is useful with the
6265 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6266 @command{tar}, @option{--null} also disables special handling for
6267 file names that begin with dash.
6268
6269 This example shows how to use @command{find} to generate a list of files
6270 larger than 800K in length and put that list into a file called
6271 @file{long-files}. The @option{-print0} option to @command{find} is just
6272 like @option{-print}, except that it separates files with a @code{NUL}
6273 rather than with a newline. You can then run @command{tar} with both the
6274 @option{--null} and @option{-T} options to specify that @command{tar} get the
6275 files from that file, @file{long-files}, to create the archive
6276 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6277 @command{tar} to recognize the @code{NUL} separator between files.
6278
6279 @smallexample
6280 $ @kbd{find . -size +800 -print0 > long-files}
6281 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6282 @end smallexample
6283
6284 @FIXME{say anything else here to conclude the section?}
6285
6286 @node exclude
6287 @section Excluding Some Files
6288 @UNREVISED
6289
6290 @cindex File names, excluding files by
6291 @cindex Excluding files by name and pattern
6292 @cindex Excluding files by file system
6293 To avoid operating on files whose names match a particular pattern,
6294 use the @option{--exclude} or @option{--exclude-from} options.
6295
6296 @table @option
6297 @opindex exclude
6298 @item --exclude=@var{pattern}
6299 Causes @command{tar} to ignore files that match the @var{pattern}.
6300 @end table
6301
6302 @findex exclude
6303 The @option{--exclude=@var{pattern}} option prevents any file or
6304 member whose name matches the shell wildcard (@var{pattern}) from
6305 being operated on.
6306 For example, to create an archive with all the contents of the directory
6307 @file{src} except for files whose names end in @file{.o}, use the
6308 command @samp{tar -cf src.tar --exclude='*.o' src}.
6309
6310 You may give multiple @option{--exclude} options.
6311
6312 @table @option
6313 @opindex exclude-from
6314 @item --exclude-from=@var{file}
6315 @itemx -X @var{file}
6316 Causes @command{tar} to ignore files that match the patterns listed in
6317 @var{file}.
6318 @end table
6319
6320 @findex exclude-from
6321 Use the @option{--exclude-from} option to read a
6322 list of patterns, one per line, from @var{file}; @command{tar} will
6323 ignore files matching those patterns. Thus if @command{tar} is
6324 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6325 single line @file{*.o}, no files whose names end in @file{.o} will be
6326 added to the archive.
6327
6328 @table @option
6329 @opindex exclude-caches
6330 @item --exclude-caches
6331 Causes @command{tar} to ignore directories containing a cache directory tag.
6332 @end table
6333
6334 @findex exclude-caches
6335 When creating an archive, the @option{--exclude-caches} option causes
6336 @command{tar} to exclude all directories that contain a @dfn{cache
6337 directory tag}. A cache directory tag is a short file with the
6338 well-known name @file{CACHEDIR.TAG} and having a standard header
6339 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6340 Various applications write cache directory tags into directories they
6341 use to hold regenerable, non-precious data, so that such data can be
6342 more easily excluded from backups.
6343
6344 @menu
6345 * problems with exclude::
6346 @end menu
6347
6348 @node problems with exclude
6349 @unnumberedsubsec Problems with Using the @code{exclude} Options
6350
6351 @opindex exclude, potential problems with
6352 Some users find @samp{exclude} options confusing. Here are some common
6353 pitfalls:
6354
6355 @itemize @bullet
6356 @item
6357 The main operating mode of @command{tar} does not act on a path name
6358 explicitly listed on the command line if one of its file name
6359 components is excluded. In the example above, if
6360 you create an archive and exclude files that end with @samp{*.o}, but
6361 explicitly name the file @samp{dir.o/foo} after all the options have been
6362 listed, @samp{dir.o/foo} will be excluded from the archive.
6363
6364 @item
6365 You can sometimes confuse the meanings of @option{--exclude} and
6366 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6367 to be excluded are given as a pattern on the command line. Use
6368 @option{--exclude-from} to introduce the name of a file which contains
6369 a list of patterns, one per line; each of these patterns can exclude
6370 zero, one, or many files.
6371
6372 @item
6373 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6374 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6375 like @samp{*}. If you do not do this, the shell might expand the
6376 @samp{*} itself using files at hand, so @command{tar} might receive a
6377 list of files instead of one pattern, or none at all, making the
6378 command somewhat illegal. This might not correspond to what you want.
6379
6380 For example, write:
6381
6382 @smallexample
6383 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6384 @end smallexample
6385
6386 @noindent
6387 rather than:
6388
6389 @smallexample
6390 # @emph{Wrong!}
6391 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6392 @end smallexample
6393
6394 @item
6395 You must use use shell syntax, or globbing, rather than @code{regexp}
6396 syntax, when using exclude options in @command{tar}. If you try to use
6397 @code{regexp} syntax to describe files to be excluded, your command
6398 might fail.
6399
6400 @item
6401 @FIXME{The change in semantics must have occurred before 1.11,
6402 so I doubt if it is worth mentioning at all. Anyway, should at
6403 least specify in which version the semantics changed.}
6404 In earlier versions of @command{tar}, what is now the
6405 @option{--exclude-from} option was called @option{--exclude} instead.
6406 Now, @option{--exclude} applies to patterns listed on the command
6407 line and @option{--exclude-from} applies to patterns listed in a
6408 file.
6409
6410 @end itemize
6411
6412 @node wildcards
6413 @section Wildcards Patterns and Matching
6414
6415 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6416 @samp{*} or @samp{?} for example, are replaced and expanded into all
6417 existing files matching the given pattern. @GNUTAR{} can use wildcard
6418 patterns for matching (or globbing) archive members when extracting
6419 from or listing an archive. Wildcard patterns are also used for
6420 verifying volume labels of @command{tar} archives. This section has the
6421 purpose of explaining wildcard syntax for @command{tar}.
6422
6423 @FIXME{the next few paragraphs need work.}
6424
6425 A @var{pattern} should be written according to shell syntax, using wildcard
6426 characters to effect globbing. Most characters in the pattern stand
6427 for themselves in the matched string, and case is significant: @samp{a}
6428 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6429 pattern matches any single character in the matched string. The character
6430 @samp{*} in the pattern matches zero, one, or more single characters in
6431 the matched string. The character @samp{\} says to take the following
6432 character of the pattern @emph{literally}; it is useful when one needs to
6433 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6434
6435 The character @samp{[}, up to the matching @samp{]}, introduces a character
6436 class. A @dfn{character class} is a list of acceptable characters
6437 for the next single character of the matched string. For example,
6438 @samp{[abcde]} would match any of the first five letters of the alphabet.
6439 Note that within a character class, all of the ``special characters''
6440 listed above other than @samp{\} lose their special meaning; for example,
6441 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6442 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6443 the characters @samp{-} and @samp{]} must either come @emph{first} or
6444 @emph{last} in a character class.)
6445
6446 @cindex Excluding characters from a character class
6447 @cindex Character class, excluding characters from
6448 If the first character of the class after the opening @samp{[}
6449 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6450 Rather than listing character to match, it lists those characters which
6451 are @emph{forbidden} as the next single character of the matched string.
6452
6453 Other characters of the class stand for themselves. The special
6454 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6455 letters, is meant to represent all characters between @var{a} and
6456 @var{e}, inclusive.
6457
6458 @FIXME{need to add a sentence or so here to make this clear for those
6459 who don't have dan around.}
6460
6461 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6462 special for wildcard matches. However, if a pattern completely matches
6463 a directory prefix of a matched string, then it matches the full matched
6464 string: thus, excluding a directory also excludes all the files beneath it.
6465
6466 @menu
6467 * controlling pattern-matching::
6468 @end menu
6469
6470 @node controlling pattern-matching
6471 @unnumberedsubsec Controlling Pattern-Matching
6472
6473 For the purposes of this section, we call @dfn{exclusion members} all
6474 member names obtained while processing @option{--exclude} and
6475 @option{--exclude-from} options, and @dfn{inclusion members} those
6476 member names that were given in the command line or read from the file
6477 specified with @option{--files-from} option.
6478
6479 These two pairs of member lists are used in the following operations:
6480 @option{--diff}, @option{--extract}, @option{--list},
6481 @option{--update}.
6482
6483 There are no inclusion members in create mode (@option{--create} and
6484 @option{--append}), since in this mode the names obtained from the
6485 command line refer to @emph{files}, not archive members.
6486
6487 By default, inclusion members are compared with archive members
6488 literally @footnote{Notice that earlier @GNUTAR{} versions used
6489 globbing for inclusion members, which contradicted to UNIX98
6490 specification and was not documented. @xref{Changes}, for more
6491 information on this and other changes.} and exclusion members are
6492 treated as globbing patterns. For example:
6493
6494 @smallexample
6495 @group
6496 $ @kbd{tar tf foo.tar}
6497 a.c
6498 b.c
6499 a.txt
6500 [remarks]
6501 # @i{Member names are used verbatim:}
6502 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6503 [remarks]
6504 # @i{Exclude member names are globbed:}
6505 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6506 a.txt
6507 [remarks]
6508 @end group
6509 @end smallexample
6510
6511 This behavior can be altered by using the following options:
6512
6513 @table @option
6514 @opindex wildcards
6515 @item --wildcards
6516 Treat all member names as wildcards.
6517
6518 @opindex no-wildcards
6519 @item --no-wildcards
6520 Treat all member names as literal strings.
6521 @end table
6522
6523 Thus, to extract files whose names end in @samp{.c}, you can use:
6524
6525 @smallexample
6526 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6527 a.c
6528 b.c
6529 @end smallexample
6530
6531 @noindent
6532 Notice quoting of the pattern to prevent the shell from interpreting
6533 it.
6534
6535 The effect of @option{--wildcards} option is cancelled by
6536 @option{--no-wildcards}. This can be used to pass part of
6537 the command line arguments verbatim and other part as globbing
6538 patterns. For example, the following invocation:
6539
6540 @smallexample
6541 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6542 @end smallexample
6543
6544 @noindent
6545 instructs @command{tar} to extract from @file{foo.tar} all files whose
6546 names end in @samp{.txt} and the file named @file{[remarks]}.
6547
6548 Normally, a pattern matches a name if an initial subsequence of the
6549 name's components matches the pattern, where @samp{*}, @samp{?}, and
6550 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6551 and wildcards can match @samp{/}.
6552
6553 Other than optionally stripping leading @samp{/} from names
6554 (@pxref{absolute}), patterns and names are used as-is. For
6555 example, trailing @samp{/} is not trimmed from a user-specified name
6556 before deciding whether to exclude it.
6557
6558 However, this matching procedure can be altered by the options listed
6559 below. These options accumulate. For example:
6560
6561 @smallexample
6562 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6563 @end smallexample
6564
6565 @noindent
6566 ignores case when excluding @samp{makefile}, but not when excluding
6567 @samp{readme}.
6568
6569 @table @option
6570 @opindex anchored
6571 @opindex no-anchored
6572 @item --anchored
6573 @itemx --no-anchored
6574 If anchored, a pattern must match an initial subsequence
6575 of the name's components. Otherwise, the pattern can match any
6576 subsequence. Default is @option{--no-anchored} for exclusion members
6577 and @option{--anchored} inclusion members.
6578
6579 @opindex ignore-case
6580 @opindex no-ignore-case
6581 @item --ignore-case
6582 @itemx --no-ignore-case
6583 When ignoring case, upper-case patterns match lower-case names and vice versa.
6584 When not ignoring case (the default), matching is case-sensitive.
6585
6586 @opindex wildcards-match-slash
6587 @opindex no-wildcards-match-slash
6588 @item --wildcards-match-slash
6589 @itemx --no-wildcards-match-slash
6590 When wildcards match slash (the default for exclusion members), a
6591 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6592 name. Otherwise, @samp{/} is matched only by @samp{/}.
6593
6594 @end table
6595
6596 The @option{--recursion} and @option{--no-recursion} options
6597 (@pxref{recurse}) also affect how member patterns are interpreted. If
6598 recursion is in effect, a pattern matches a name if it matches any of
6599 the name's parent directories.
6600
6601 The following table summarizes pattern-matching default values:
6602
6603 @multitable @columnfractions .3 .7
6604 @headitem Members @tab Default settings
6605 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6606 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6607 @end multitable
6608
6609 @node quoting styles
6610 @section Quoting Member Names
6611
6612 When displaying member names, @command{tar} takes care to avoid
6613 ambiguities caused by certain characters. This is called @dfn{name
6614 quoting}. The characters in question are:
6615
6616 @itemize @bullet
6617 @item Non-printable control characters:
6618
6619 @multitable @columnfractions 0.20 0.10 0.60
6620 @headitem Character @tab ASCII @tab Character name
6621 @item \a @tab 7 @tab Audible bell
6622 @item \b @tab 8 @tab Backspace
6623 @item \f @tab 12 @tab Form feed
6624 @item \n @tab 10 @tab New line
6625 @item \r @tab 13 @tab Carriage return
6626 @item \t @tab 9 @tab Horizontal tabulation
6627 @item \v @tab 11 @tab Vertical tabulation
6628 @end multitable
6629
6630 @item Space (ASCII 32)
6631
6632 @item Single and double quotes (@samp{'} and @samp{"})
6633
6634 @item Backslash (@samp{\})
6635 @end itemize
6636
6637 The exact way @command{tar} uses to quote these characters depends on
6638 the @dfn{quoting style}. The default quoting style, called
6639 @dfn{escape} (see below), uses backslash notation to represent control
6640 characters, space and backslash. Using this quoting style, control
6641 characters are represented as listed in column @samp{Character} in the
6642 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6643
6644 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6645 using @option{--quoting-style} option:
6646
6647 @table @option
6648 @item --quoting-style=@var{style}
6649 @opindex quoting-style
6650
6651 Sets quoting style. Valid values for @var{style} argument are:
6652 literal, shell, shell-always, c, escape, locale, clocale.
6653 @end table
6654
6655 These styles are described in detail below. To illustrate their
6656 effect, we will use an imaginary tar archive @file{arch.tar}
6657 containing the following members:
6658
6659 @smallexample
6660 @group
6661 # 1. Contains horizontal tabulation character.
6662 a tab
6663 # 2. Contains newline character
6664 a
6665 newline
6666 # 3. Contains a space
6667 a space
6668 # 4. Contains double quotes
6669 a"double"quote
6670 # 5. Contains single quotes
6671 a'single'quote
6672 # 6. Contains a backslash character:
6673 a\backslash
6674 @end group
6675 @end smallexample
6676
6677 Here is how usual @command{ls} command would have listed them, if they
6678 had existed in the current working directory:
6679
6680 @smallexample
6681 @group
6682 $ @kbd{ls}
6683 a\ttab
6684 a\nnewline
6685 a\ space
6686 a"double"quote
6687 a'single'quote
6688 a\\backslash
6689 @end group
6690 @end smallexample
6691
6692 Quoting styles:
6693
6694 @table @samp
6695 @item literal
6696 No quoting, display each character as is:
6697
6698 @smallexample
6699 @group
6700 $ @kbd{tar tf arch.tar --quoting-style=literal}
6701 ./
6702 ./a space
6703 ./a'single'quote
6704 ./a"double"quote
6705 ./a\backslash
6706 ./a tab
6707 ./a
6708 newline
6709 @end group
6710 @end smallexample
6711
6712 @item shell
6713 Display characters the same way Bourne shell does:
6714 control characters, except @samp{\t} and @samp{\n}, are printed using
6715 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6716 single quote is printed as @samp{\'}. If a name contains any quoted
6717 characters, it is enclosed in single quotes. In particular, if a name
6718 contains single quotes, it is printed as several single-quoted strings:
6719
6720 @smallexample
6721 @group
6722 $ @kbd{tar tf arch.tar --quoting-style=shell}
6723 ./
6724 './a space'
6725 './a'\''single'\''quote'
6726 './a"double"quote'
6727 './a\backslash'
6728 './a tab'
6729 './a
6730 newline'
6731 @end group
6732 @end smallexample
6733
6734 @item shell-always
6735 Same as @samp{shell}, but the names are always enclosed in single
6736 quotes:
6737
6738 @smallexample
6739 @group
6740 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6741 './'
6742 './a space'
6743 './a'\''single'\''quote'
6744 './a"double"quote'
6745 './a\backslash'
6746 './a tab'
6747 './a
6748 newline'
6749 @end group
6750 @end smallexample
6751
6752 @item c
6753 Use the notation of the C programming language. All names are
6754 enclosed in double quotes. Control characters are quoted using
6755 backslash notations, double quotes are represented as @samp{\"},
6756 backslash characters are represented as @samp{\\}. Single quotes and
6757 spaces are not quoted:
6758
6759 @smallexample
6760 @group
6761 $ @kbd{tar tf arch.tar --quoting-style=c}
6762 "./"
6763 "./a space"
6764 "./a'single'quote"
6765 "./a\"double\"quote"
6766 "./a\\backslash"
6767 "./a\ttab"
6768 "./a\nnewline"
6769 @end group
6770 @end smallexample
6771
6772 @item escape
6773 Control characters are printed using backslash notation, a space is
6774 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6775 default quoting style, unless it was changed when configured the
6776 package.
6777
6778 @smallexample
6779 @group
6780 $ @kbd{tar tf arch.tar --quoting-style=escape}
6781 ./
6782 ./a space
6783 ./a'single'quote
6784 ./a"double"quote
6785 ./a\\backslash
6786 ./a\ttab
6787 ./a\nnewline
6788 @end group
6789 @end smallexample
6790
6791 @item locale
6792 Control characters, single quote and backslash are printed using
6793 backslash notation. All names are quoted using left and right
6794 quotation marks, appropriate to the current locale. If it does not
6795 define quotation marks, use @samp{`} as left and @samp{'} as right
6796 quotation marks. Any occurrences of the right quotation mark in a
6797 name are escaped with @samp{\}, for example:
6798
6799 For example:
6800
6801 @smallexample
6802 @group
6803 $ @kbd{tar tf arch.tar --quoting-style=locale}
6804 `./'
6805 `./a space'
6806 `./a\'single\'quote'
6807 `./a"double"quote'
6808 `./a\\backslash'
6809 `./a\ttab'
6810 `./a\nnewline'
6811 @end group
6812 @end smallexample
6813
6814 @item clocale
6815 Same as @samp{locale}, but @samp{"} is used for both left and right
6816 quotation marks, if not provided by the currently selected locale:
6817
6818 @smallexample
6819 @group
6820 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6821 "./"
6822 "./a space"
6823 "./a'single'quote"
6824 "./a\"double\"quote"
6825 "./a\\backslash"
6826 "./a\ttab"
6827 "./a\nnewline"
6828 @end group
6829 @end smallexample
6830 @end table
6831
6832 You can specify which characters should be quoted in addition to those
6833 implied by the current quoting style:
6834
6835 @table @option
6836 @item --quote-chars=@var{string}
6837 Always quote characters from @var{string}, even if the selected
6838 quoting style would not quote them.
6839 @end table
6840
6841 For example, using @samp{escape} quoting (compare with the usual
6842 escape listing above):
6843
6844 @smallexample
6845 @group
6846 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6847 ./
6848 ./a\ space
6849 ./a'single'quote
6850 ./a\"double\"quote
6851 ./a\\backslash
6852 ./a\ttab
6853 ./a\nnewline
6854 @end group
6855 @end smallexample
6856
6857 To disable quoting of such additional characters, use the following
6858 option:
6859
6860 @table @option
6861 @item --no-quote-chars=@var{string}
6862 Remove characters listed in @var{string} from the list of quoted
6863 characters set by the previous @option{--quote-chars} option.
6864 @end table
6865
6866 This option is particularly useful if you have added
6867 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6868 and wish to disable it for the current invocation.
6869
6870 Note, that @option{--no-quote-chars} does @emph{not} disable those
6871 characters that are quoted by default in the selected quoting style.
6872
6873 @node transform
6874 @section Modifying File and Member Names
6875
6876 @command{Tar} archives contain detailed information about files stored
6877 in them and full file names are part of that information. When
6878 storing file to an archive, its file name is recorded in the archive
6879 along with the actual file contents. When restoring from an archive,
6880 a file is created on disk with exactly the same name as that stored
6881 in the archive. In the majority of cases this is the desired behavior
6882 of a file archiver. However, there are some cases when it is not.
6883
6884 First of all, it is often unsafe to extract archive members with
6885 absolute file names or those that begin with a @file{../}. @GNUTAR{}
6886 takes special precautions when extracting such names and provides a
6887 special option for handling them, which is described in
6888 @ref{absolute}.
6889
6890 Secondly, you may wish to extract file names without some leading
6891 directory components, or with otherwise modified names. In other
6892 cases it is desirable to store files under differing names in the
6893 archive.
6894
6895 @GNUTAR{} provides two options for these needs.
6896
6897 @table @option
6898 @opindex strip-components
6899 @item --strip-components=@var{number}
6900 Strip given @var{number} of leading components from file names before
6901 extraction.
6902 @end table
6903
6904 For example, suppose you have archived whole @file{/usr} hierarchy to
6905 a tar archive named @file{usr.tar}. Among other files, this archive
6906 contains @file{usr/include/stdlib.h}, which you wish to extract to
6907 the current working directory. To do so, you type:
6908
6909 @smallexample
6910 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
6911 @end smallexample
6912
6913 The option @option{--strip=2} instructs @command{tar} to strip the
6914 two leading components (@file{usr/} and @file{include/}) off the file
6915 name.
6916
6917 If you add to the above invocation @option{--verbose} (@option{-v})
6918 option, you will note that the verbose listing still contains the
6919 full file name, with the two removed components still in place. This
6920 can be inconvenient, so @command{tar} provides a special option for
6921 altering this behavior:
6922
6923 @anchor{show-transformed-names}
6924 @table @option
6925 @opindex --show-transformed-names
6926 @item --show-transformed-names
6927 Display file or member names with all requested transformations
6928 applied.
6929 @end table
6930
6931 @noindent
6932 For example:
6933
6934 @smallexample
6935 @group
6936 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
6937 usr/include/stdlib.h
6938 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
6939 stdlib.h
6940 @end group
6941 @end smallexample
6942
6943 Notice that in both cases the file is @file{stdlib.h} extracted to the
6944 current working directory, @option{--show-transformed-names} affects
6945 only the way its name is displayed.
6946
6947 This option is especially useful for verifying whether the invocation
6948 will have the desired effect. Thus, before running
6949
6950 @smallexample
6951 $ @kbd{tar -x --strip=@var{n}}
6952 @end smallexample
6953
6954 @noindent
6955 it is often advisable to run
6956
6957 @smallexample
6958 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
6959 @end smallexample
6960
6961 @noindent
6962 to make sure the command will produce the intended results.
6963
6964 In case you need to apply more complex modifications to the file name,
6965 @GNUTAR{} provides a general-purpose transformation option:
6966
6967 @table @option
6968 @opindex --transform
6969 @item --transform=@var{expression}
6970 Modify file names using supplied @var{expression}.
6971 @end table
6972
6973 @noindent
6974 The @var{expression} is a @command{sed}-like replace expression of the
6975 form:
6976
6977 @smallexample
6978 s/@var{regexp}/@var{replace}/[@var{flags}]
6979 @end smallexample
6980
6981 @noindent
6982 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
6983 replacement for each file name part that matches @var{regexp}. Both
6984 @var{regexp} and @var{replace} are described in detail in
6985 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
6986
6987 Supported @var{flags} are:
6988
6989 @table @samp
6990 @item g
6991 Apply the replacement to @emph{all} matches to the @var{regexp}, not
6992 just the first.
6993
6994 @item i
6995 Use case-insensitive matching
6996
6997 @item x
6998 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
6999 regexps, Extended regular expressions, Extended regular expressions,
7000 sed, GNU sed}).
7001
7002 @item @var{number}
7003 Only replace the @var{number}th match of the @var{regexp}.
7004
7005 Note: the @var{posix} standard does not specify what should happen
7006 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7007 follows the GNU @command{sed} implementation in this regard, so
7008 the the interaction is defined to be: ignore matches before the
7009 @var{number}th, and then match and replace all matches from the
7010 @var{number}th on.
7011
7012 @end table
7013
7014 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7015 that it be used consistently throughout the expression. For example,
7016 the following two expressions are equivalent:
7017
7018 @smallexample
7019 @group
7020 s/one/two/
7021 s,one,two,
7022 @end group
7023 @end smallexample
7024
7025 Changing delimiters is often useful when the @var{regex} contains
7026 slashes. For example, it is more convenient to write @code{s,/,-,} than
7027 @code{s/\//-/}.
7028
7029 Here are several examples of @option{--transform} usage:
7030
7031 @enumerate
7032 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7033
7034 @smallexample
7035 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7036 @end smallexample
7037
7038 @item Strip two leading directory components (equivalent to
7039 @option{--strip-components=2}):
7040
7041 @smallexample
7042 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7043 @end smallexample
7044
7045 @item Prepend @file{/prefix/} to each file name:
7046
7047 @smallexample
7048 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7049 @end smallexample
7050
7051 @item Convert each file name to lower case:
7052
7053 @smallexample
7054 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7055 @end smallexample
7056
7057 @end enumerate
7058
7059 Unlike @option{--strip-components}, @option{--transform} can be used
7060 in any @GNUTAR{} operation mode. For example, the following command
7061 adds files to the archive while replacing the leading @file{usr/}
7062 component with @file{var/}:
7063
7064 @smallexample
7065 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7066 @end smallexample
7067
7068 To test @option{--transform} effect we suggest using
7069 @option{--show-transformed-names} option:
7070
7071 @smallexample
7072 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7073 --verbose --show-transformed-names /}
7074 @end smallexample
7075
7076 If both @option{--strip-components} and @option{--transform} are used
7077 together, then @option{--transform} is applied first, and the required
7078 number of components is then stripped from its result.
7079
7080 @node after
7081 @section Operating Only on New Files
7082 @UNREVISED
7083
7084 @cindex Excluding file by age
7085 @cindex Data Modification time, excluding files by
7086 @cindex Modification time, excluding files by
7087 @cindex Age, excluding files by
7088 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7089 @option{-N @var{date}}) option causes @command{tar} to only work on
7090 files whose data modification or status change times are newer than
7091 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7092 it is taken to be a file name; the data modification time of that file
7093 is used as the date. If you use this option when creating or appending
7094 to an archive, the archive will only include new files. If you use
7095 @option{--after-date} when extracting an archive, @command{tar} will
7096 only extract files newer than the @var{date} you specify.
7097
7098 If you only want @command{tar} to make the date comparison based on
7099 modification of the file's data (rather than status
7100 changes), then use the @option{--newer-mtime=@var{date}} option.
7101
7102 You may use these options with any operation. Note that these options
7103 differ from the @option{--update} (@option{-u}) operation in that they
7104 allow you to specify a particular date against which @command{tar} can
7105 compare when deciding whether or not to archive the files.
7106
7107 @table @option
7108 @opindex after-date
7109 @opindex newer
7110 @item --after-date=@var{date}
7111 @itemx --newer=@var{date}
7112 @itemx -N @var{date}
7113 Only store files newer than @var{date}.
7114
7115 Acts on files only if their data modification or status change times are
7116 later than @var{date}. Use in conjunction with any operation.
7117
7118 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7119 name; the data modification time of that file is used as the date.
7120
7121 @opindex newer-mtime
7122 @item --newer-mtime=@var{date}
7123 Acts like @option{--after-date}, but only looks at data modification times.
7124 @end table
7125
7126 These options limit @command{tar} to operate only on files which have
7127 been modified after the date specified. A file's status is considered to have
7128 changed if its contents have been modified, or if its owner,
7129 permissions, and so forth, have been changed. (For more information on
7130 how to specify a date, see @ref{Date input formats}; remember that the
7131 entire date argument must be quoted if it contains any spaces.)
7132
7133 Gurus would say that @option{--after-date} tests both the data
7134 modification time (@code{mtime}, the time the contents of the file
7135 were last modified) and the status change time (@code{ctime}, the time
7136 the file's status was last changed: owner, permissions, etc.@:)
7137 fields, while @option{--newer-mtime} tests only the @code{mtime}
7138 field.
7139
7140 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7141 @code{ctime} and processes the file if either one is more recent than
7142 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7143 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7144 contents of the file were looked at).
7145
7146 Date specifiers can have embedded spaces. Because of this, you may need
7147 to quote date arguments to keep the shell from parsing them as separate
7148 arguments. For example, the following command will add to the archive
7149 all the files modified less than two days ago:
7150
7151 @smallexample
7152 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7153 @end smallexample
7154
7155 @quotation
7156 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7157 should not be used for incremental backups. @xref{Incremental Dumps},
7158 for proper way of creating incremental backups.
7159 @end quotation
7160
7161 @node recurse
7162 @section Descending into Directories
7163 @UNREVISED
7164 @cindex Avoiding recursion in directories
7165 @cindex Descending directories, avoiding
7166 @cindex Directories, avoiding recursion
7167 @cindex Recursion in directories, avoiding
7168
7169 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7170
7171 Usually, @command{tar} will recursively explore all directories (either
7172 those given on the command line or through the @option{--files-from}
7173 option) for the various files they contain. However, you may not always
7174 want @command{tar} to act this way.
7175
7176 @opindex no-recursion
7177 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7178 into specified directories. If you specify @option{--no-recursion}, you can
7179 use the @command{find} utility for hunting through levels of directories to
7180 construct a list of file names which you could then pass to @command{tar}.
7181 @command{find} allows you to be more selective when choosing which files to
7182 archive; see @ref{files}, for more information on using @command{find} with
7183 @command{tar}, or look.
7184
7185 @table @option
7186 @item --no-recursion
7187 Prevents @command{tar} from recursively descending directories.
7188
7189 @opindex recursion
7190 @item --recursion
7191 Requires @command{tar} to recursively descend directories.
7192 This is the default.
7193 @end table
7194
7195 When you use @option{--no-recursion}, @GNUTAR{} grabs
7196 directory entries themselves, but does not descend on them
7197 recursively. Many people use @command{find} for locating files they
7198 want to back up, and since @command{tar} @emph{usually} recursively
7199 descends on directories, they have to use the @samp{@w{-not -type d}}
7200 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7201 find, Finding Files}), as they usually do not want all the files in a
7202 directory. They then use the @option{--files-from} option to archive
7203 the files located via @command{find}.
7204
7205 The problem when restoring files archived in this manner is that the
7206 directories themselves are not in the archive; so the
7207 @option{--same-permissions} (@option{--preserve-permissions},
7208 @option{-p}) option does not affect them---while users might really
7209 like it to. Specifying @option{--no-recursion} is a way to tell
7210 @command{tar} to grab only the directory entries given to it, adding
7211 no new files on its own. To summarize, if you use @command{find} to
7212 create a list of files to be stored in an archive, use it as follows:
7213
7214 @smallexample
7215 @group
7216 $ @kbd{find @var{dir} @var{tests} | \
7217 tar -cf @var{archive} -T - --no-recursion}
7218 @end group
7219 @end smallexample
7220
7221 The @option{--no-recursion} option also applies when extracting: it
7222 causes @command{tar} to extract only the matched directory entries, not
7223 the files under those directories.
7224
7225 The @option{--no-recursion} option also affects how globbing patterns
7226 are interpreted (@pxref{controlling pattern-matching}).
7227
7228 The @option{--no-recursion} and @option{--recursion} options apply to
7229 later options and operands, and can be overridden by later occurrences
7230 of @option{--no-recursion} and @option{--recursion}. For example:
7231
7232 @smallexample
7233 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7234 @end smallexample
7235
7236 @noindent
7237 creates an archive with one entry for @file{grape}, and the recursive
7238 contents of @file{grape/concord}, but no entries under @file{grape}
7239 other than @file{grape/concord}.
7240
7241 @node one
7242 @section Crossing File System Boundaries
7243 @cindex File system boundaries, not crossing
7244 @UNREVISED
7245
7246 @command{tar} will normally automatically cross file system boundaries in
7247 order to archive files which are part of a directory tree. You can
7248 change this behavior by running @command{tar} and specifying
7249 @option{--one-file-system}. This option only affects files that are
7250 archived because they are in a directory that is being archived;
7251 @command{tar} will still archive files explicitly named on the command line
7252 or through @option{--files-from}, regardless of where they reside.
7253
7254 @table @option
7255 @opindex one-file-system
7256 @item --one-file-system
7257 Prevents @command{tar} from crossing file system boundaries when
7258 archiving. Use in conjunction with any write operation.
7259 @end table
7260
7261 The @option{--one-file-system} option causes @command{tar} to modify its
7262 normal behavior in archiving the contents of directories. If a file in
7263 a directory is not on the same file system as the directory itself, then
7264 @command{tar} will not archive that file. If the file is a directory
7265 itself, @command{tar} will not archive anything beneath it; in other words,
7266 @command{tar} will not cross mount points.
7267
7268 This option is useful for making full or incremental archival backups of
7269 a file system. If this option is used in conjunction with
7270 @option{--verbose} (@option{-v}), files that are excluded are
7271 mentioned by name on the standard error.
7272
7273 @menu
7274 * directory:: Changing Directory
7275 * absolute:: Absolute File Names
7276 @end menu
7277
7278 @node directory
7279 @subsection Changing the Working Directory
7280 @UNREVISED
7281
7282 @FIXME{need to read over this node now for continuity; i've switched
7283 things around some.}
7284
7285 @cindex Changing directory mid-stream
7286 @cindex Directory, changing mid-stream
7287 @cindex Working directory, specifying
7288 To change the working directory in the middle of a list of file names,
7289 either on the command line or in a file specified using
7290 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7291 This will change the working directory to the specified directory
7292 after that point in the list.
7293
7294 @table @option
7295 @opindex directory
7296 @item --directory=@var{directory}
7297 @itemx -C @var{directory}
7298 Changes the working directory in the middle of a command line.
7299 @end table
7300
7301 For example,
7302
7303 @smallexample
7304 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7305 @end smallexample
7306
7307 @noindent
7308 will place the files @file{grape} and @file{prune} from the current
7309 directory into the archive @file{jams.tar}, followed by the file
7310 @file{cherry} from the directory @file{food}. This option is especially
7311 useful when you have several widely separated files that you want to
7312 store in the same archive.
7313
7314 Note that the file @file{cherry} is recorded in the archive under the
7315 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7316 archive will contain three files that all appear to have come from the
7317 same directory; if the archive is extracted with plain @samp{tar
7318 --extract}, all three files will be written in the current directory.
7319
7320 Contrast this with the command,
7321
7322 @smallexample
7323 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7324 @end smallexample
7325
7326 @noindent
7327 which records the third file in the archive under the name
7328 @file{red/cherry} so that, if the archive is extracted using
7329 @samp{tar --extract}, the third file will be written in a subdirectory
7330 named @file{orange-colored}.
7331
7332 You can use the @option{--directory} option to make the archive
7333 independent of the original name of the directory holding the files.
7334 The following command places the files @file{/etc/passwd},
7335 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7336 @file{foo.tar}:
7337
7338 @smallexample
7339 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7340 @end smallexample
7341
7342 @noindent
7343 However, the names of the archive members will be exactly what they were
7344 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7345 They will not appear to be related by file name to the original
7346 directories where those files were located.
7347
7348 Note that @option{--directory} options are interpreted consecutively. If
7349 @option{--directory} specifies a relative file name, it is interpreted
7350 relative to the then current directory, which might not be the same as
7351 the original current working directory of @command{tar}, due to a previous
7352 @option{--directory} option.
7353
7354 When using @option{--files-from} (@pxref{files}), you can put various
7355 @command{tar} options (including @option{-C}) in the file list. Notice,
7356 however, that in this case the option and its argument may not be
7357 separated by whitespace. If you use short option, its argument must
7358 either follow the option letter immediately, without any intervening
7359 whitespace, or occupy the next line. Otherwise, if you use long
7360 option, separate its argument by an equal sign.
7361
7362 For instance, the file list for the above example will be:
7363
7364 @smallexample
7365 @group
7366 -C
7367 /etc
7368 passwd
7369 hosts
7370 -C
7371 /lib
7372 libc.a
7373 @end group
7374 @end smallexample
7375
7376 @noindent
7377 To use it, you would invoke @command{tar} as follows:
7378
7379 @smallexample
7380 $ @kbd{tar -c -f foo.tar --files-from list}
7381 @end smallexample
7382
7383 Notice also that you can only use the short option variant in the file
7384 list, i.e., always use @option{-C}, not @option{--directory}.
7385
7386 The interpretation of @option{--directory} is disabled by
7387 @option{--null} option.
7388
7389 @node absolute
7390 @subsection Absolute File Names
7391 @UNREVISED
7392
7393 @table @option
7394 @opindex absolute-names
7395 @item --absolute-names
7396 @itemx -P
7397 Do not strip leading slashes from file names, and permit file names
7398 containing a @file{..} file name component.
7399 @end table
7400
7401 By default, @GNUTAR{} drops a leading @samp{/} on
7402 input or output, and complains about file names containing a @file{..}
7403 component. This option turns off this behavior.
7404
7405 When @command{tar} extracts archive members from an archive, it strips any
7406 leading slashes (@samp{/}) from the member name. This causes absolute
7407 member names in the archive to be treated as relative file names. This
7408 allows you to have such members extracted wherever you want, instead of
7409 being restricted to extracting the member in the exact directory named
7410 in the archive. For example, if the archive member has the name
7411 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7412 really @file{etc/passwd}.
7413
7414 File names containing @file{..} can cause problems when extracting, so
7415 @command{tar} normally warns you about such files when creating an
7416 archive, and rejects attempts to extracts such files.
7417
7418 Other @command{tar} programs do not do this. As a result, if you
7419 create an archive whose member names start with a slash, they will be
7420 difficult for other people with a non-@GNUTAR{}
7421 program to use. Therefore, @GNUTAR{} also strips
7422 leading slashes from member names when putting members into the
7423 archive. For example, if you ask @command{tar} to add the file
7424 @file{/bin/ls} to an archive, it will do so, but the member name will
7425 be @file{bin/ls}.@footnote{A side effect of this is that when
7426 @option{--create} is used with @option{--verbose} the resulting output
7427 is not, generally speaking, the same as the one you'd get running
7428 @kbd{tar --list} command. This may be important if you use some
7429 scripts for comparing both outputs. @xref{listing member and file names},
7430 for the information on how to handle this case.}
7431
7432 If you use the @option{--absolute-names} (@option{-P}) option,
7433 @command{tar} will do none of these transformations.
7434
7435 To archive or extract files relative to the root directory, specify
7436 the @option{--absolute-names} (@option{-P}) option.
7437
7438 Normally, @command{tar} acts on files relative to the working
7439 directory---ignoring superior directory names when archiving, and
7440 ignoring leading slashes when extracting.
7441
7442 When you specify @option{--absolute-names} (@option{-P}),
7443 @command{tar} stores file names including all superior directory
7444 names, and preserves leading slashes. If you only invoked
7445 @command{tar} from the root directory you would never need the
7446 @option{--absolute-names} option, but using this option
7447 may be more convenient than switching to root.
7448
7449 @FIXME{Should be an example in the tutorial/wizardry section using this
7450 to transfer files between systems.}
7451
7452 @FIXME{Is write access an issue?}
7453
7454 @table @option
7455 @item --absolute-names
7456 Preserves full file names (including superior directory names) when
7457 archiving files. Preserves leading slash when extracting files.
7458
7459 @end table
7460
7461 @FIXME{this is still horrible; need to talk with dan on monday.}
7462
7463 @command{tar} prints out a message about removing the @samp{/} from
7464 file names. This message appears once per @GNUTAR{}
7465 invocation. It represents something which ought to be told; ignoring
7466 what it means can cause very serious surprises, later.
7467
7468 Some people, nevertheless, do not want to see this message. Wanting to
7469 play really dangerously, one may of course redirect @command{tar} standard
7470 error to the sink. For example, under @command{sh}:
7471
7472 @smallexample
7473 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7474 @end smallexample
7475
7476 @noindent
7477 Another solution, both nicer and simpler, would be to change to
7478 the @file{/} directory first, and then avoid absolute notation.
7479 For example:
7480
7481 @smallexample
7482 $ @kbd{(cd / && tar -c -f archive.tar home)}
7483 # @i{or}:
7484 $ @kbd{tar -c -f archive.tar -C / home}
7485 @end smallexample
7486
7487 @include getdate.texi
7488
7489 @node Formats
7490 @chapter Controlling the Archive Format
7491
7492 @cindex Tar archive formats
7493 Due to historical reasons, there are several formats of tar archives.
7494 All of them are based on the same principles, but have some subtle
7495 differences that often make them incompatible with each other.
7496
7497 GNU tar is able to create and handle archives in a variety of formats.
7498 The most frequently used formats are (in alphabetical order):
7499
7500 @table @asis
7501 @item gnu
7502 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7503 from an early @acronym{POSIX} standard, adding some improvements such as
7504 sparse file handling and incremental archives. Unfortunately these
7505 features were implemented in a way incompatible with other archive
7506 formats.
7507
7508 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7509 length.
7510
7511 @item oldgnu
7512 Format used by @GNUTAR{} of versions prior to 1.12.
7513
7514 @item v7
7515 Archive format, compatible with the V7 implementation of tar. This
7516 format imposes a number of limitations. The most important of them
7517 are:
7518
7519 @enumerate
7520 @item The maximum length of a file name is limited to 99 characters.
7521 @item The maximum length of a symbolic link is limited to 99 characters.
7522 @item It is impossible to store special files (block and character
7523 devices, fifos etc.)
7524 @item Maximum value of user or group ID is limited to 2097151 (7777777
7525 octal)
7526 @item V7 archives do not contain symbolic ownership information (user
7527 and group name of the file owner).
7528 @end enumerate
7529
7530 This format has traditionally been used by Automake when producing
7531 Makefiles. This practice will change in the future, in the meantime,
7532 however this means that projects containing filenames more than 99
7533 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7534 Automake prior to 1.9.
7535
7536 @item ustar
7537 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7538 symbolic ownership information. It is also able to store
7539 special files. However, it imposes several restrictions as well:
7540
7541 @enumerate
7542 @item The maximum length of a file name is limited to 256 characters,
7543 provided that the filename can be split at directory separator in
7544 two parts, first of them being at most 155 bytes long. So, in most
7545 cases the maximum file name length will be shorter than 256
7546 characters.
7547 @item The maximum length of a symbolic link name is limited to
7548 100 characters.
7549 @item Maximum size of a file the archive is able to accomodate
7550 is 8GB
7551 @item Maximum value of UID/GID is 2097151.
7552 @item Maximum number of bits in device major and minor numbers is 21.
7553 @end enumerate
7554
7555 @item star
7556 Format used by J@"org Schilling @command{star}
7557 implementation. @GNUTAR{} is able to read @samp{star} archives but
7558 currently does not produce them.
7559
7560 @item posix
7561 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7562 most flexible and feature-rich format. It does not impose any
7563 restrictions on file sizes or filename lengths. This format is quite
7564 recent, so not all tar implementations are able to handle it properly.
7565 However, this format is designed in such a way that any tar
7566 implementation able to read @samp{ustar} archives will be able to read
7567 most @samp{posix} archives as well, with the only exception that any
7568 additional information (such as long file names etc.) will in such
7569 case be extracted as plain text files along with the files it refers to.
7570
7571 This archive format will be the default format for future versions
7572 of @GNUTAR{}.
7573
7574 @end table
7575
7576 The following table summarizes the limitations of each of these
7577 formats:
7578
7579 @multitable @columnfractions .10 .20 .20 .20 .20
7580 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7581 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7582 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7583 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7584 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7585 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7586 @end multitable
7587
7588 The default format for @GNUTAR{} is defined at compilation
7589 time. You may check it by running @command{tar --help}, and examining
7590 the last lines of its output. Usually, @GNUTAR{} is configured
7591 to create archives in @samp{gnu} format, however, future version will
7592 switch to @samp{posix}.
7593
7594 @menu
7595 * Portability:: Making @command{tar} Archives More Portable
7596 * Compression:: Using Less Space through Compression
7597 * Attributes:: Handling File Attributes
7598 * cpio:: Comparison of @command{tar} and @command{cpio}
7599 @end menu
7600
7601 @node Portability
7602 @section Making @command{tar} Archives More Portable
7603
7604 Creating a @command{tar} archive on a particular system that is meant to be
7605 useful later on many other machines and with other versions of @command{tar}
7606 is more challenging than you might think. @command{tar} archive formats
7607 have been evolving since the first versions of Unix. Many such formats
7608 are around, and are not always compatible with each other. This section
7609 discusses a few problems, and gives some advice about making @command{tar}
7610 archives more portable.
7611
7612 One golden rule is simplicity. For example, limit your @command{tar}
7613 archives to contain only regular files and directories, avoiding
7614 other kind of special files. Do not attempt to save sparse files or
7615 contiguous files as such. Let's discuss a few more problems, in turn.
7616
7617 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7618 archives and archive labels) in GNU and PAX formats.}
7619
7620 @menu
7621 * Portable Names:: Portable Names
7622 * dereference:: Symbolic Links
7623 * old:: Old V7 Archives
7624 * ustar:: Ustar Archives
7625 * gnu:: GNU and old GNU format archives.
7626 * posix:: @acronym{POSIX} archives
7627 * Checksumming:: Checksumming Problems
7628 * Large or Negative Values:: Large files, negative time stamps, etc.
7629 @end menu
7630
7631 @node Portable Names
7632 @subsection Portable Names
7633
7634 Use portable file and member names. A name is portable if it contains
7635 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7636 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7637 contain @samp{/-}. Avoid deep directory nesting. For portability to
7638 old Unix hosts, limit your file name components to 14 characters or
7639 less.
7640
7641 If you intend to have your @command{tar} archives to be read under
7642 MSDOS, you should not rely on case distinction for file names, and you
7643 might use the @acronym{GNU} @command{doschk} program for helping you
7644 further diagnosing illegal MSDOS names, which are even more limited
7645 than System V's.
7646
7647 @node dereference
7648 @subsection Symbolic Links
7649 @cindex File names, using symbolic links
7650 @cindex Symbolic link as file name
7651
7652 @opindex dereference
7653 Normally, when @command{tar} archives a symbolic link, it writes a
7654 block to the archive naming the target of the link. In that way, the
7655 @command{tar} archive is a faithful record of the file system contents.
7656 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7657 @command{tar} to archive the files symbolic links point to, instead of
7658 the links themselves. When this option is used, when @command{tar}
7659 encounters a symbolic link, it will archive the linked-to file,
7660 instead of simply recording the presence of a symbolic link.
7661
7662 The name under which the file is stored in the file system is not
7663 recorded in the archive. To record both the symbolic link name and
7664 the file name in the system, archive the file under both names. If
7665 all links were recorded automatically by @command{tar}, an extracted file
7666 might be linked to a file name that no longer exists in the file
7667 system.
7668
7669 If a linked-to file is encountered again by @command{tar} while creating
7670 the same archive, an entire second copy of it will be stored. (This
7671 @emph{might} be considered a bug.)
7672
7673 So, for portable archives, do not archive symbolic links as such,
7674 and use @option{--dereference} (@option{-h}): many systems do not support
7675 symbolic links, and moreover, your distribution might be unusable if
7676 it contains unresolved symbolic links.
7677
7678 @node old
7679 @subsection Old V7 Archives
7680 @cindex Format, old style
7681 @cindex Old style format
7682 @cindex Old style archives
7683 @cindex v7 archive format
7684
7685 Certain old versions of @command{tar} cannot handle additional
7686 information recorded by newer @command{tar} programs. To create an
7687 archive in V7 format (not ANSI), which can be read by these old
7688 versions, specify the @option{--format=v7} option in
7689 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7690 accepts @option{--portability} or @samp{op-old-archive} for this
7691 option). When you specify it,
7692 @command{tar} leaves out information about directories, pipes, fifos,
7693 contiguous files, and device files, and specifies file ownership by
7694 group and user IDs instead of group and user names.
7695
7696 When updating an archive, do not use @option{--format=v7}
7697 unless the archive was created using this option.
7698
7699 In most cases, a @emph{new} format archive can be read by an @emph{old}
7700 @command{tar} program without serious trouble, so this option should
7701 seldom be needed. On the other hand, most modern @command{tar}s are
7702 able to read old format archives, so it might be safer for you to
7703 always use @option{--format=v7} for your distributions.
7704
7705 @node ustar
7706 @subsection Ustar Archive Format
7707
7708 @cindex ustar archive format
7709 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7710 @code{ustar}. Although it is more flexible than the V7 format, it
7711 still has many restrictions (@xref{Formats,ustar}, for the detailed
7712 description of @code{ustar} format). Along with V7 format,
7713 @code{ustar} format is a good choice for archives intended to be read
7714 with other implementations of @command{tar}.
7715
7716 To create archive in @code{ustar} format, use @option{--format=ustar}
7717 option in conjunction with the @option{--create} (@option{-c}).
7718
7719 @node gnu
7720 @subsection @acronym{GNU} and old @GNUTAR{} format
7721
7722 @cindex GNU archive format
7723 @cindex Old GNU archive format
7724 @GNUTAR{} was based on an early draft of the
7725 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7726 @command{tar}, such as the support for file names longer than 100
7727 characters, use portions of the @command{tar} header record which were
7728 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7729 @acronym{POSIX} have allocated the same parts of the header record for
7730 other purposes. As a result, @GNUTAR{} format is
7731 incompatible with the current @acronym{POSIX} specification, and with
7732 @command{tar} programs that follow it.
7733
7734 In the majority of cases, @command{tar} will be configured to create
7735 this format by default. This will change in the future releases, since
7736 we plan to make @samp{posix} format the default.
7737
7738 To force creation a @GNUTAR{} archive, use option
7739 @option{--format=gnu}.
7740
7741 @node posix
7742 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7743
7744 @cindex POSIX archive format
7745 @cindex PAX archive format
7746 Starting from version 1.14 @GNUTAR{} features full support for
7747 @acronym{POSIX.1-2001} archives.
7748
7749 A @acronym{POSIX} conformant archive will be created if @command{tar}
7750 was given @option{--format=posix} (@option{--format=pax}) option. No
7751 special option is required to read and extract from a @acronym{POSIX}
7752 archive.
7753
7754 @menu
7755 * PAX keywords:: Controlling Extended Header Keywords.
7756 @end menu
7757
7758 @node PAX keywords
7759 @subsubsection Controlling Extended Header Keywords
7760
7761 @table @option
7762 @opindex pax-option
7763 @item --pax-option=@var{keyword-list}
7764 Handle keywords in @acronym{PAX} extended headers. This option is
7765 equivalent to @option{-o} option of the @command{pax} utility.
7766 @end table
7767
7768 @var{Keyword-list} is a comma-separated
7769 list of keyword options, each keyword option taking one of
7770 the following forms:
7771
7772 @table @code
7773 @item delete=@var{pattern}
7774 When used with one of archive-creation commands,
7775 this option instructs @command{tar} to omit from extended header records
7776 that it produces any keywords matching the string @var{pattern}.
7777
7778 When used in extract or list mode, this option instructs tar
7779 to ignore any keywords matching the given @var{pattern} in the extended
7780 header records. In both cases, matching is performed using the pattern
7781 matching notation described in @acronym{POSIX 1003.2}, 3.13
7782 (@pxref{wildcards}). For example:
7783
7784 @smallexample
7785 --pax-option delete=security.*
7786 @end smallexample
7787
7788 would suppress security-related information.
7789
7790 @item exthdr.name=@var{string}
7791
7792 This keyword allows user control over the name that is written into the
7793 ustar header blocks for the extended headers. The name is obtained
7794 from @var{string} after making the following substitutions:
7795
7796 @multitable @columnfractions .25 .55
7797 @headitem Meta-character @tab Replaced By
7798 @item %d @tab The directory name of the file, equivalent to the
7799 result of the @command{dirname} utility on the translated pathname.
7800 @item %f @tab The filename of the file, equivalent to the result
7801 of the @command{basename} utility on the translated pathname.
7802 @item %p @tab The process ID of the @command{tar} process.
7803 @item %% @tab A @samp{%} character.
7804 @end multitable
7805
7806 Any other @samp{%} characters in @var{string} produce undefined
7807 results.
7808
7809 If no option @samp{exthdr.name=string} is specified, @command{tar}
7810 will use the following default value:
7811
7812 @smallexample
7813 %d/PaxHeaders.%p/%f
7814 @end smallexample
7815
7816 @item globexthdr.name=@var{string}
7817 This keyword allows user control over the name that is written into
7818 the ustar header blocks for global extended header records. The name
7819 is obtained from the contents of @var{string}, after making
7820 the following substitutions:
7821
7822 @multitable @columnfractions .25 .55
7823 @headitem Meta-character @tab Replaced By
7824 @item %n @tab An integer that represents the
7825 sequence number of the global extended header record in the archive,
7826 starting at 1.
7827 @item %p @tab The process ID of the @command{tar} process.
7828 @item %% @tab A @samp{%} character.
7829 @end multitable
7830
7831 Any other @samp{%} characters in @var{string} produce undefined results.
7832
7833 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7834 will use the following default value:
7835
7836 @smallexample
7837 $TMPDIR/GlobalHead.%p.%n
7838 @end smallexample
7839
7840 @noindent
7841 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7842 environment variable. If @var{TMPDIR} is not set, @command{tar}
7843 uses @samp{/tmp}.
7844
7845 @item @var{keyword}=@var{value}
7846 When used with one of archive-creation commands, these keyword/value pairs
7847 will be included at the beginning of the archive in a global extended
7848 header record. When used with one of archive-reading commands,
7849 @command{tar} will behave as if it has encountered these keyword/value
7850 pairs at the beginning of the archive in a global extended header
7851 record.
7852
7853 @item @var{keyword}:=@var{value}
7854 When used with one of archive-creation commands, these keyword/value pairs
7855 will be included as records at the beginning of an extended header for
7856 each file. This is effectively equivalent to @var{keyword}=@var{value}
7857 form except that it creates no global extended header records.
7858
7859 When used with one of archive-reading commands, @command{tar} will
7860 behave as if these keyword/value pairs were included as records at the
7861 end of each extended header; thus, they will override any global or
7862 file-specific extended header record keywords of the same names.
7863 For example, in the command:
7864
7865 @smallexample
7866 tar --format=posix --create \
7867 --file archive --pax-option gname:=user .
7868 @end smallexample
7869
7870 the group name will be forced to a new value for all files
7871 stored in the archive.
7872 @end table
7873
7874 @node Checksumming
7875 @subsection Checksumming Problems
7876
7877 SunOS and HP-UX @command{tar} fail to accept archives created using
7878 @GNUTAR{} and containing non-ASCII file names, that
7879 is, file names having characters with the eight bit set, because they
7880 use signed checksums, while @GNUTAR{} uses unsigned
7881 checksums while creating archives, as per @acronym{POSIX} standards. On
7882 reading, @GNUTAR{} computes both checksums and
7883 accept any. It is somewhat worrying that a lot of people may go
7884 around doing backup of their files using faulty (or at least
7885 non-standard) software, not learning about it until it's time to
7886 restore their missing files with an incompatible file extractor, or
7887 vice versa.
7888
7889 @GNUTAR{} compute checksums both ways, and accept
7890 any on read, so @acronym{GNU} tar can read Sun tapes even with their
7891 wrong checksums. @GNUTAR{} produces the standard
7892 checksum, however, raising incompatibilities with Sun. That is to
7893 say, @GNUTAR{} has not been modified to
7894 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
7895 I've been told that more recent Sun @command{tar} now read standard
7896 archives, so maybe Sun did a similar patch, after all?
7897
7898 The story seems to be that when Sun first imported @command{tar}
7899 sources on their system, they recompiled it without realizing that
7900 the checksums were computed differently, because of a change in
7901 the default signing of @code{char}'s in their compiler. So they
7902 started computing checksums wrongly. When they later realized their
7903 mistake, they merely decided to stay compatible with it, and with
7904 themselves afterwards. Presumably, but I do not really know, HP-UX
7905 has chosen that their @command{tar} archives to be compatible with Sun's.
7906 The current standards do not favor Sun @command{tar} format. In any
7907 case, it now falls on the shoulders of SunOS and HP-UX users to get
7908 a @command{tar} able to read the good archives they receive.
7909
7910 @node Large or Negative Values
7911 @subsection Large or Negative Values
7912 @cindex large values
7913 @cindex future time stamps
7914 @cindex negative time stamps
7915 @UNREVISED{}
7916
7917 The above sections suggest to use @samp{oldest possible} archive
7918 format if in doubt. However, sometimes it is not possible. If you
7919 attempt to archive a file whose metadata cannot be represented using
7920 required format, @GNUTAR{} will print error message and ignore such a
7921 file. You will than have to switch to a format that is able to
7922 handle such values. The format summary table (@pxref{Formats}) will
7923 help you to do so.
7924
7925 In particular, when trying to archive files larger than 8GB or with
7926 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
7927 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
7928 @acronym{POSIX} archive formats. When considering which format to
7929 choose, bear in mind that the @acronym{GNU} format uses
7930 two's-complement base-256 notation to store values that do not fit
7931 into standard @acronym{ustar} range. Such archives can generally be
7932 read only by a @GNUTAR{} implementation. Moreover, they sometimes
7933 cannot be correctly restored on another hosts even by @GNUTAR{}. For
7934 example, using two's complement representation for negative time
7935 stamps that assumes a signed 32-bit @code{time_t} generates archives
7936 that are not portable to hosts with differing @code{time_t}
7937 representations.
7938
7939 On the other hand, @acronym{POSIX} archives, generally speaking, can
7940 be extracted by any tar implementation that understands older
7941 @acronym{ustar} format. The only exception are files larger than 8GB.
7942
7943 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
7944 POSIX-aware tars.}
7945
7946 @node Compression
7947 @section Using Less Space through Compression
7948
7949 @menu
7950 * gzip:: Creating and Reading Compressed Archives
7951 * sparse:: Archiving Sparse Files
7952 @end menu
7953
7954 @node gzip
7955 @subsection Creating and Reading Compressed Archives
7956 @cindex Compressed archives
7957 @cindex Storing archives in compressed format
7958
7959 @GNUTAR{} is able to create and read compressed archives. It supports
7960 @command{gzip} and @command{bzip2} compression programs. For backward
7961 compatibilty, it also supports @command{compress} command, although
7962 we strongly recommend against using it, since there is a patent
7963 covering the algorithm it uses and you could be sued for patent
7964 infringement merely by running @command{compress}! Besides, it is less
7965 effective than @command{gzip} and @command{bzip2}.
7966
7967 Creating a compressed archive is simple: you just specify a
7968 @dfn{compression option} along with the usual archive creation
7969 commands. The compression option is @option{-z} (@option{--gzip}) to
7970 create a @command{gzip} compressed archive, @option{-j}
7971 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7972 @option{-Z} (@option{--compress}) to use @command{compress} program.
7973 For example:
7974
7975 @smallexample
7976 $ @kbd{tar cfz archive.tar.gz .}
7977 @end smallexample
7978
7979 Reading compressed archive is even simpler: you don't need to specify
7980 any additional options as @GNUTAR{} recognizes its format
7981 automatically. Thus, the following commands will list and extract the
7982 archive created in previous example:
7983
7984 @smallexample
7985 # List the compressed archive
7986 $ @kbd{tar tf archive.tar.gz}
7987 # Extract the compressed archive
7988 $ @kbd{tar xf archive.tar.gz}
7989 @end smallexample
7990
7991 The only case when you have to specify a decompression option while
7992 reading the archive is when reading from a pipe or from a tape drive
7993 that does not support random access. However, in this case @GNUTAR{}
7994 will indicate which option you should use. For example:
7995
7996 @smallexample
7997 $ @kbd{cat archive.tar.gz | tar tf -}
7998 tar: Archive is compressed. Use -z option
7999 tar: Error is not recoverable: exiting now
8000 @end smallexample
8001
8002 If you see such diagnostics, just add the suggested option to the
8003 invocation of @GNUTAR{}:
8004
8005 @smallexample
8006 $ @kbd{cat archive.tar.gz | tar tfz -}
8007 @end smallexample
8008
8009 Notice also, that there are several restrictions on operations on
8010 compressed archives. First of all, compressed archives cannot be
8011 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8012 (@option{--delete}) members from them. Likewise, you cannot append
8013 another @command{tar} archive to a compressed archive using
8014 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8015 compressed.
8016
8017 The following table summarizes compression options used by @GNUTAR{}.
8018
8019 @table @option
8020 @opindex gzip
8021 @opindex ungzip
8022 @item -z
8023 @itemx --gzip
8024 @itemx --ungzip
8025 Filter the archive through @command{gzip}.
8026
8027 You can use @option{--gzip} and @option{--gunzip} on physical devices
8028 (tape drives, etc.) and remote files as well as on normal files; data
8029 to or from such devices or remote files is reblocked by another copy
8030 of the @command{tar} program to enforce the specified (or default) record
8031 size. The default compression parameters are used; if you need to
8032 override them, set @env{GZIP} environment variable, e.g.:
8033
8034 @smallexample
8035 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8036 @end smallexample
8037
8038 @noindent
8039 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8040 @command{gzip} explicitly:
8041
8042 @smallexample
8043 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8044 @end smallexample
8045
8046 @cindex corrupted archives
8047 About corrupted compressed archives: @command{gzip}'ed files have no
8048 redundancy, for maximum compression. The adaptive nature of the
8049 compression scheme means that the compression tables are implicitly
8050 spread all over the archive. If you lose a few blocks, the dynamic
8051 construction of the compression tables becomes unsynchronized, and there
8052 is little chance that you could recover later in the archive.
8053
8054 There are pending suggestions for having a per-volume or per-file
8055 compression in @GNUTAR{}. This would allow for viewing the
8056 contents without decompression, and for resynchronizing decompression at
8057 every volume or file, in case of corrupted archives. Doing so, we might
8058 lose some compressibility. But this would have make recovering easier.
8059 So, there are pros and cons. We'll see!
8060
8061 @opindex bzip2
8062 @item -j
8063 @itemx --bzip2
8064 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8065
8066 @opindex compress
8067 @opindex uncompress
8068 @item -Z
8069 @itemx --compress
8070 @itemx --uncompress
8071 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8072
8073 The @acronym{GNU} Project recommends you not use
8074 @command{compress}, because there is a patent covering the algorithm it
8075 uses. You could be sued for patent infringement merely by running
8076 @command{compress}.
8077
8078 @opindex use-compress-program
8079 @item --use-compress-program=@var{prog}
8080 Use external compression program @var{prog}. Use this option if you
8081 have a compression program that @GNUTAR{} does not support. There
8082 are two requirements to which @var{prog} should comply:
8083
8084 First, when called without options, it should read data from standard
8085 input, compress it and output it on standard output.
8086
8087 Secondly, if called with @option{-d} argument, it should do exactly
8088 the opposite, i.e., read the compressed data from the standard input
8089 and produce uncompressed data on the standard output.
8090 @end table
8091
8092 @cindex gpg, using with tar
8093 @cindex gnupg, using with tar
8094 @cindex Using encrypted archives
8095 The @option{--use-compress-program} option, in particular, lets you
8096 implement your own filters, not necessarily dealing with
8097 compression/decomression. For example, suppose you wish to implement
8098 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8099 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8100 Manual}). The following script does that:
8101
8102 @smallexample
8103 @group
8104 #! /bin/sh
8105 case $1 in
8106 -d) gpg --decrypt - | gzip -d -c;;
8107 '') gzip -c | gpg -s ;;
8108 *) echo "Unknown option $1">&2; exit 1;;
8109 esac
8110 @end group
8111 @end smallexample
8112
8113 Suppose you name it @file{gpgz} and save it somewhere in your
8114 @env{PATH}. Then the following command will create a commpressed
8115 archive signed with your private key:
8116
8117 @smallexample
8118 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8119 @end smallexample
8120
8121 @noindent
8122 Likewise, the following command will list its contents:
8123
8124 @smallexample
8125 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8126 @end smallexample
8127
8128 @ignore
8129 The above is based on the following discussion:
8130
8131 I have one question, or maybe it's a suggestion if there isn't a way
8132 to do it now. I would like to use @option{--gzip}, but I'd also like
8133 the output to be fed through a program like @acronym{GNU}
8134 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8135 to use :-)), basically adding ECC protection on top of compression.
8136 It seems as if this should be quite easy to do, but I can't work out
8137 exactly how to go about it. Of course, I can pipe the standard output
8138 of @command{tar} through @command{ecc}, but then I lose (though I
8139 haven't started using it yet, I confess) the ability to have
8140 @command{tar} use @command{rmt} for it's I/O (I think).
8141
8142 I think the most straightforward thing would be to let me specify a
8143 general set of filters outboard of compression (preferably ordered,
8144 so the order can be automatically reversed on input operations, and
8145 with the options they require specifiable), but beggars shouldn't be
8146 choosers and anything you decide on would be fine with me.
8147
8148 By the way, I like @command{ecc} but if (as the comments say) it can't
8149 deal with loss of block sync, I'm tempted to throw some time at adding
8150 that capability. Supposing I were to actually do such a thing and
8151 get it (apparently) working, do you accept contributed changes to
8152 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8153
8154 Isn't that exactly the role of the
8155 @option{--use-compress-prog=@var{program}} option?
8156 I never tried it myself, but I suspect you may want to write a
8157 @var{prog} script or program able to filter stdin to stdout to
8158 way you want. It should recognize the @option{-d} option, for when
8159 extraction is needed rather than creation.
8160
8161 It has been reported that if one writes compressed data (through the
8162 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8163 the DLT compression mode, the data will actually get bigger and one will
8164 end up with less space on the tape.
8165 @end ignore
8166
8167 @node sparse
8168 @subsection Archiving Sparse Files
8169 @cindex Sparse Files
8170 @UNREVISED
8171
8172 @table @option
8173 @opindex sparse
8174 @item -S
8175 @itemx --sparse
8176 Handle sparse files efficiently.
8177 @end table
8178
8179 This option causes all files to be put in the archive to be tested for
8180 sparseness, and handled specially if they are. The @option{--sparse}
8181 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8182 backed up. Using this option dramatically decreases the amount of
8183 space needed to store such a file.
8184
8185 In later versions, this option may be removed, and the testing and
8186 treatment of sparse files may be done automatically with any special
8187 @acronym{GNU} options. For now, it is an option needing to be specified on
8188 the command line with the creation or updating of an archive.
8189
8190 Files in the file system occasionally have ``holes.'' A hole in a file
8191 is a section of the file's contents which was never written. The
8192 contents of a hole read as all zeros. On many operating systems,
8193 actual disk storage is not allocated for holes, but they are counted
8194 in the length of the file. If you archive such a file, @command{tar}
8195 could create an archive longer than the original. To have @command{tar}
8196 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8197 you use this option, then, for any file using less disk space than
8198 would be expected from its length, @command{tar} searches the file for
8199 consecutive stretches of zeros. It then records in the archive for
8200 the file where the consecutive stretches of zeros are, and only
8201 archives the ``real contents'' of the file. On extraction (using
8202 @option{--sparse} is not needed on extraction) any such
8203 files have holes created wherever the continuous stretches of zeros
8204 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8205 won't take more space than the original.
8206
8207 A file is sparse if it contains blocks of zeros whose existence is
8208 recorded, but that have no space allocated on disk. When you specify
8209 the @option{--sparse} option in conjunction with the @option{--create}
8210 (@option{-c}) operation, @command{tar} tests all files for sparseness
8211 while archiving. If @command{tar} finds a file to be sparse, it uses a
8212 sparse representation of the file in the archive. @xref{create}, for
8213 more information about creating archives.
8214
8215 @option{--sparse} is useful when archiving files, such as dbm files,
8216 likely to contain many nulls. This option dramatically
8217 decreases the amount of space needed to store such an archive.
8218
8219 @quotation
8220 @strong{Please Note:} Always use @option{--sparse} when performing file
8221 system backups, to avoid archiving the expanded forms of files stored
8222 sparsely in the system.
8223
8224 Even if your system has no sparse files currently, some may be
8225 created in the future. If you use @option{--sparse} while making file
8226 system backups as a matter of course, you can be assured the archive
8227 will never take more space on the media than the files take on disk
8228 (otherwise, archiving a disk filled with sparse files might take
8229 hundreds of tapes). @xref{Incremental Dumps}.
8230 @end quotation
8231
8232 @command{tar} ignores the @option{--sparse} option when reading an archive.
8233
8234 @table @option
8235 @item --sparse
8236 @itemx -S
8237 Files stored sparsely in the file system are represented sparsely in
8238 the archive. Use in conjunction with write operations.
8239 @end table
8240
8241 However, users should be well aware that at archive creation time,
8242 @GNUTAR{} still has to read whole disk file to
8243 locate the @dfn{holes}, and so, even if sparse files use little space
8244 on disk and in the archive, they may sometimes require inordinate
8245 amount of time for reading and examining all-zero blocks of a file.
8246 Although it works, it's painfully slow for a large (sparse) file, even
8247 though the resulting tar archive may be small. (One user reports that
8248 dumping a @file{core} file of over 400 megabytes, but with only about
8249 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8250 ELC, with full CPU utilization.)
8251
8252 This reading is required in all cases and is not related to the fact
8253 the @option{--sparse} option is used or not, so by merely @emph{not}
8254 using the option, you are not saving time@footnote{Well! We should say
8255 the whole truth, here. When @option{--sparse} is selected while creating
8256 an archive, the current @command{tar} algorithm requires sparse files to be
8257 read twice, not once. We hope to develop a new archive format for saving
8258 sparse files in which one pass will be sufficient.}.
8259
8260 Programs like @command{dump} do not have to read the entire file; by
8261 examining the file system directly, they can determine in advance
8262 exactly where the holes are and thus avoid reading through them. The
8263 only data it need read are the actual allocated data blocks.
8264 @GNUTAR{} uses a more portable and straightforward
8265 archiving approach, it would be fairly difficult that it does
8266 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8267 1990-12-10:
8268
8269 @quotation
8270 What I did say is that you cannot tell the difference between a hole and an
8271 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8272 best tells you how many holes there are; it doesn't tell you @emph{where}.
8273 Just as programs may, conceivably, care what @code{st_blocks} is (care
8274 to name one that does?), they may also care where the holes are (I have
8275 no examples of this one either, but it's equally imaginable).
8276
8277 I conclude from this that good archivers are not portable. One can
8278 arguably conclude that if you want a portable program, you can in good
8279 conscience restore files with as many holes as possible, since you can't
8280 get it right.
8281 @end quotation
8282
8283 @node Attributes
8284 @section Handling File Attributes
8285 @UNREVISED
8286
8287 When @command{tar} reads files, it updates their access times. To
8288 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8289 reset the access time retroactively or avoid changing it in the first
8290 place.
8291
8292 Handling of file attributes
8293
8294 @table @option
8295 @opindex atime-preserve
8296 @item --atime-preserve
8297 @itemx --atime-preserve=replace
8298 @itemx --atime-preserve=system
8299 Preserve the access times of files that are read. This works only for
8300 files that you own, unless you have superuser privileges.
8301
8302 @option{--atime-preserve=replace} works on most systems, but it also
8303 restores the data modification time and updates the status change
8304 time. Hence it doesn't interact with incremental dumps nicely
8305 (@pxref{Backups}), and it can set access or data modification times
8306 incorrectly if other programs access the file while @command{tar} is
8307 running.
8308
8309 @option{--atime-preserve=system} avoids changing the access time in
8310 the first place, if the operating system supports this.
8311 Unfortunately, this may or may not work on any given operating system
8312 or file system. If @command{tar} knows for sure it won't work, it
8313 complains right away.
8314
8315 Currently @option{--atime-preserve} with no operand defaults to
8316 @option{--atime-preserve=replace}, but this is intended to change to
8317 @option{--atime-preserve=system} when the latter is better-supported.
8318
8319 @opindex touch
8320 @item -m
8321 @itemx --touch
8322 Do not extract data modification time.
8323
8324 When this option is used, @command{tar} leaves the data modification times
8325 of the files it extracts as the times when the files were extracted,
8326 instead of setting it to the times recorded in the archive.
8327
8328 This option is meaningless with @option{--list} (@option{-t}).
8329
8330 @opindex same-owner
8331 @item --same-owner
8332 Create extracted files with the same ownership they have in the
8333 archive.
8334
8335 This is the default behavior for the superuser,
8336 so this option is meaningful only for non-root users, when @command{tar}
8337 is executed on those systems able to give files away. This is
8338 considered as a security flaw by many people, at least because it
8339 makes quite difficult to correctly account users for the disk space
8340 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8341 files are easily and silently lost when files are given away.
8342
8343 When writing an archive, @command{tar} writes the user id and user name
8344 separately. If it can't find a user name (because the user id is not
8345 in @file{/etc/passwd}), then it does not write one. When restoring,
8346 it tries to look the name (if one was written) up in
8347 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8348 the archive instead.
8349
8350 @opindex no-same-owner
8351 @item --no-same-owner
8352 @itemx -o
8353 Do not attempt to restore ownership when extracting. This is the
8354 default behavior for ordinary users, so this option has an effect
8355 only for the superuser.
8356
8357 @opindex numeric-owner
8358 @item --numeric-owner
8359 The @option{--numeric-owner} option allows (ANSI) archives to be written
8360 without user/group name information or such information to be ignored
8361 when extracting. It effectively disables the generation and/or use
8362 of user/group name information. This option forces extraction using
8363 the numeric ids from the archive, ignoring the names.
8364
8365 This is useful in certain circumstances, when restoring a backup from
8366 an emergency floppy with different passwd/group files for example.
8367 It is otherwise impossible to extract files with the right ownerships
8368 if the password file in use during the extraction does not match the
8369 one belonging to the file system(s) being extracted. This occurs,
8370 for example, if you are restoring your files after a major crash and
8371 had booted from an emergency floppy with no password file or put your
8372 disk into another machine to do the restore.
8373
8374 The numeric ids are @emph{always} saved into @command{tar} archives.
8375 The identifying names are added at create time when provided by the
8376 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8377 used when moving archives between a collection of machines using
8378 a centralized management for attribution of numeric ids to users
8379 and groups. This is often made through using the NIS capabilities.
8380
8381 When making a @command{tar} file for distribution to other sites, it
8382 is sometimes cleaner to use a single owner for all files in the
8383 distribution, and nicer to specify the write permission bits of the
8384 files as stored in the archive independently of their actual value on
8385 the file system. The way to prepare a clean distribution is usually
8386 to have some Makefile rule creating a directory, copying all needed
8387 files in that directory, then setting ownership and permissions as
8388 wanted (there are a lot of possible schemes), and only then making a
8389 @command{tar} archive out of this directory, before cleaning
8390 everything out. Of course, we could add a lot of options to
8391 @GNUTAR{} for fine tuning permissions and ownership.
8392 This is not the good way, I think. @GNUTAR{} is
8393 already crowded with options and moreover, the approach just explained
8394 gives you a great deal of control already.
8395
8396 @opindex same-permissions, short description
8397 @opindex preserve-permissions, short description
8398 @item -p
8399 @itemx --same-permissions
8400 @itemx --preserve-permissions
8401 Extract all protection information.
8402
8403 This option causes @command{tar} to set the modes (access permissions) of
8404 extracted files exactly as recorded in the archive. If this option
8405 is not used, the current @code{umask} setting limits the permissions
8406 on extracted files. This option is by default enabled when
8407 @command{tar} is executed by a superuser.
8408
8409
8410 This option is meaningless with @option{--list} (@option{-t}).
8411
8412 @opindex preserve
8413 @item --preserve
8414 Same as both @option{--same-permissions} and @option{--same-order}.
8415
8416 The @option{--preserve} option has no equivalent short option name.
8417 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8418
8419 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8420 Neither do I. --Sergey}
8421
8422 @end table
8423
8424 @node cpio
8425 @section Comparison of @command{tar} and @command{cpio}
8426 @UNREVISED
8427
8428 @FIXME{Reorganize the following material}
8429
8430 The @command{cpio} archive formats, like @command{tar}, do have maximum
8431 pathname lengths. The binary and old ASCII formats have a max path
8432 length of 256, and the new ASCII and CRC ASCII formats have a max
8433 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8434 with arbitrary pathname lengths, but other @command{cpio} implementations
8435 may crash unexplainedly trying to read them.
8436
8437 @command{tar} handles symbolic links in the form in which it comes in BSD;
8438 @command{cpio} doesn't handle symbolic links in the form in which it comes
8439 in System V prior to SVR4, and some vendors may have added symlinks
8440 to their system without enhancing @command{cpio} to know about them.
8441 Others may have enhanced it in a way other than the way I did it
8442 at Sun, and which was adopted by AT&T (and which is, I think, also
8443 present in the @command{cpio} that Berkeley picked up from AT&T and put
8444 into a later BSD release---I think I gave them my changes).
8445
8446 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8447 can handle @command{tar} format input, and write it on output, and it
8448 probably handles symbolic links. They may not have bothered doing
8449 anything to enhance @command{tar} as a result.)
8450
8451 @command{cpio} handles special files; traditional @command{tar} doesn't.
8452
8453 @command{tar} comes with V7, System III, System V, and BSD source;
8454 @command{cpio} comes only with System III, System V, and later BSD
8455 (4.3-tahoe and later).
8456
8457 @command{tar}'s way of handling multiple hard links to a file can handle
8458 file systems that support 32-bit inumbers (e.g., the BSD file system);
8459 @command{cpio}s way requires you to play some games (in its "binary"
8460 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8461 they're 18 bits---it would have to play games with the "file system ID"
8462 field of the header to make sure that the file system ID/i-number pairs
8463 of different files were always different), and I don't know which
8464 @command{cpio}s, if any, play those games. Those that don't might get
8465 confused and think two files are the same file when they're not, and
8466 make hard links between them.
8467
8468 @command{tar}s way of handling multiple hard links to a file places only
8469 one copy of the link on the tape, but the name attached to that copy
8470 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8471 way puts one copy for every link, but you can retrieve it using any
8472 of the names.
8473
8474 @quotation
8475 What type of check sum (if any) is used, and how is this calculated.
8476 @end quotation
8477
8478 See the attached manual pages for @command{tar} and @command{cpio} format.
8479 @command{tar} uses a checksum which is the sum of all the bytes in the
8480 @command{tar} header for a file; @command{cpio} uses no checksum.
8481
8482 @quotation
8483 If anyone knows why @command{cpio} was made when @command{tar} was present
8484 at the unix scene,
8485 @end quotation
8486
8487 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8488 generally-available version of UNIX had @command{tar} at the time. I don't
8489 know whether any version that was generally available @emph{within AT&T}
8490 had @command{tar}, or, if so, whether the people within AT&T who did
8491 @command{cpio} knew about it.
8492
8493 On restore, if there is a corruption on a tape @command{tar} will stop at
8494 that point, while @command{cpio} will skip over it and try to restore the
8495 rest of the files.
8496
8497 The main difference is just in the command syntax and header format.
8498
8499 @command{tar} is a little more tape-oriented in that everything is blocked
8500 to start on a record boundary.
8501
8502 @quotation
8503 Is there any differences between the ability to recover crashed
8504 archives between the two of them. (Is there any chance of recovering
8505 crashed archives at all.)
8506 @end quotation
8507
8508 Theoretically it should be easier under @command{tar} since the blocking
8509 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8510 However, modern @command{cpio}'s and variations have an option to just
8511 search for the next file header after an error with a reasonable chance
8512 of resyncing. However, lots of tape driver software won't allow you to
8513 continue past a media error which should be the only reason for getting
8514 out of sync unless a file changed sizes while you were writing the
8515 archive.
8516
8517 @quotation
8518 If anyone knows why @command{cpio} was made when @command{tar} was present
8519 at the unix scene, please tell me about this too.
8520 @end quotation
8521
8522 Probably because it is more media efficient (by not blocking everything
8523 and using only the space needed for the headers where @command{tar}
8524 always uses 512 bytes per file header) and it knows how to archive
8525 special files.
8526
8527 You might want to look at the freely available alternatives. The
8528 major ones are @command{afio}, @GNUTAR{}, and
8529 @command{pax}, each of which have their own extensions with some
8530 backwards compatibility.
8531
8532 Sparse files were @command{tar}red as sparse files (which you can
8533 easily test, because the resulting archive gets smaller, and
8534 @acronym{GNU} @command{cpio} can no longer read it).
8535
8536 @node Media
8537 @chapter Tapes and Other Archive Media
8538 @UNREVISED
8539
8540 A few special cases about tape handling warrant more detailed
8541 description. These special cases are discussed below.
8542
8543 Many complexities surround the use of @command{tar} on tape drives. Since
8544 the creation and manipulation of archives located on magnetic tape was
8545 the original purpose of @command{tar}, it contains many features making
8546 such manipulation easier.
8547
8548 Archives are usually written on dismountable media---tape cartridges,
8549 mag tapes, or floppy disks.
8550
8551 The amount of data a tape or disk holds depends not only on its size,
8552 but also on how it is formatted. A 2400 foot long reel of mag tape
8553 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8554 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8555
8556 Magnetic media are re-usable---once the archive on a tape is no longer
8557 needed, the archive can be erased and the tape or disk used over.
8558 Media quality does deteriorate with use, however. Most tapes or disks
8559 should be discarded when they begin to produce data errors. EXABYTE
8560 tape cartridges should be discarded when they generate an @dfn{error
8561 count} (number of non-usable bits) of more than 10k.
8562
8563 Magnetic media are written and erased using magnetic fields, and
8564 should be protected from such fields to avoid damage to stored data.
8565 Sticking a floppy disk to a filing cabinet using a magnet is probably
8566 not a good idea.
8567
8568 @menu
8569 * Device:: Device selection and switching
8570 * Remote Tape Server::
8571 * Common Problems and Solutions::
8572 * Blocking:: Blocking
8573 * Many:: Many archives on one tape
8574 * Using Multiple Tapes:: Using Multiple Tapes
8575 * label:: Including a Label in the Archive
8576 * verify::
8577 * Write Protection::
8578 @end menu
8579
8580 @node Device
8581 @section Device Selection and Switching
8582 @UNREVISED
8583
8584 @table @option
8585 @item -f [@var{hostname}:]@var{file}
8586 @itemx --file=[@var{hostname}:]@var{file}
8587 Use archive file or device @var{file} on @var{hostname}.
8588 @end table
8589
8590 This option is used to specify the file name of the archive @command{tar}
8591 works on.
8592
8593 If the file name is @samp{-}, @command{tar} reads the archive from standard
8594 input (when listing or extracting), or writes it to standard output
8595 (when creating). If the @samp{-} file name is given when updating an
8596 archive, @command{tar} will read the original archive from its standard
8597 input, and will write the entire new archive to its standard output.
8598
8599 If the file name contains a @samp{:}, it is interpreted as
8600 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8601 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8602 either case, @command{tar} will invoke the command @command{rsh} (or
8603 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8604 machine. If you give an alternate login name, it will be given to the
8605 @command{rsh}.
8606 Naturally, the remote machine must have an executable
8607 @command{/usr/libexec/rmt}. This program is free software from the
8608 University of California, and a copy of the source code can be found
8609 with the sources for @command{tar}; it's compiled and installed by default.
8610 The exact path to this utility is determined when configuring the package.
8611 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8612 your installation prefix. This location may also be overridden at
8613 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8614 ---rmt-command}, for detailed description of this option. @xref{Remote
8615 Tape Server}, for the description of @command{rmt} command).
8616
8617 If this option is not given, but the environment variable @env{TAPE}
8618 is set, its value is used; otherwise, old versions of @command{tar}
8619 used a default archive name (which was picked when @command{tar} was
8620 compiled). The default is normally set up to be the @dfn{first} tape
8621 drive or other transportable I/O medium on the system.
8622
8623 Starting with version 1.11.5, @GNUTAR{} uses
8624 standard input and standard output as the default device, and I will
8625 not try anymore supporting automatic device detection at installation
8626 time. This was failing really in too many cases, it was hopeless.
8627 This is now completely left to the installer to override standard
8628 input and standard output for default device, if this seems
8629 preferable. Further, I think @emph{most} actual usages of
8630 @command{tar} are done with pipes or disks, not really tapes,
8631 cartridges or diskettes.
8632
8633 Some users think that using standard input and output is running
8634 after trouble. This could lead to a nasty surprise on your screen if
8635 you forget to specify an output file name---especially if you are going
8636 through a network or terminal server capable of buffering large amounts
8637 of output. We had so many bug reports in that area of configuring
8638 default tapes automatically, and so many contradicting requests, that
8639 we finally consider the problem to be portably intractable. We could
8640 of course use something like @samp{/dev/tape} as a default, but this
8641 is @emph{also} running after various kind of trouble, going from hung
8642 processes to accidental destruction of real tapes. After having seen
8643 all this mess, using standard input and output as a default really
8644 sounds like the only clean choice left, and a very useful one too.
8645
8646 @GNUTAR{} reads and writes archive in records, I
8647 suspect this is the main reason why block devices are preferred over
8648 character devices. Most probably, block devices are more efficient
8649 too. The installer could also check for @samp{DEFTAPE} in
8650 @file{<sys/mtio.h>}.
8651
8652 @table @option
8653 @opindex force-local, short description
8654 @item --force-local
8655 Archive file is local even if it contains a colon.
8656
8657 @opindex rsh-command
8658 @item --rsh-command=@var{command}
8659 Use remote @var{command} instead of @command{rsh}. This option exists
8660 so that people who use something other than the standard @command{rsh}
8661 (e.g., a Kerberized @command{rsh}) can access a remote device.
8662
8663 When this command is not used, the shell command found when
8664 the @command{tar} program was installed is used instead. This is
8665 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8666 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8667 The installer may have overridden this by defining the environment
8668 variable @env{RSH} @emph{at installation time}.
8669
8670 @item -[0-7][lmh]
8671 Specify drive and density.
8672
8673 @opindex multi-volume, short description
8674 @item -M
8675 @itemx --multi-volume
8676 Create/list/extract multi-volume archive.
8677
8678 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8679 that may be larger than will fit on the medium used to hold it.
8680 @xref{Multi-Volume Archives}.
8681
8682 @opindex tape-length, short description
8683 @item -L @var{num}
8684 @itemx --tape-length=@var{num}
8685 Change tape after writing @var{num} x 1024 bytes.
8686
8687 This option might be useful when your tape drivers do not properly
8688 detect end of physical tapes. By being slightly conservative on the
8689 maximum tape length, you might avoid the problem entirely.
8690
8691 @opindex info-script, short description
8692 @opindex new-volume-script, short description
8693 @item -F @var{file}
8694 @itemx --info-script=@var{file}
8695 @itemx --new-volume-script=@var{file}
8696 Execute @file{file} at end of each tape. This implies
8697 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8698 description of this option.
8699 @end table
8700
8701 @node Remote Tape Server
8702 @section The Remote Tape Server
8703
8704 @cindex remote tape drive
8705 @pindex rmt
8706 In order to access the tape drive on a remote machine, @command{tar}
8707 uses the remote tape server written at the University of California at
8708 Berkeley. The remote tape server must be installed as
8709 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8710 want to use. @command{tar} calls @command{rmt} by running an
8711 @command{rsh} or @command{remsh} to the remote machine, optionally
8712 using a different login name if one is supplied.
8713
8714 A copy of the source for the remote tape server is provided. It is
8715 Copyright @copyright{} 1983 by the Regents of the University of
8716 California, but can be freely distributed. It is compiled and
8717 installed by default.
8718
8719 @cindex absolute file names
8720 Unless you use the @option{--absolute-names} (@option{-P}) option,
8721 @GNUTAR{} will not allow you to create an archive that contains
8722 absolute file names (a file name beginning with @samp{/}.) If you try,
8723 @command{tar} will automatically remove the leading @samp{/} from the
8724 file names it stores in the archive. It will also type a warning
8725 message telling you what it is doing.
8726
8727 When reading an archive that was created with a different
8728 @command{tar} program, @GNUTAR{} automatically
8729 extracts entries in the archive which have absolute file names as if
8730 the file names were not absolute. This is an important feature. A
8731 visitor here once gave a @command{tar} tape to an operator to restore;
8732 the operator used Sun @command{tar} instead of @GNUTAR{},
8733 and the result was that it replaced large portions of
8734 our @file{/bin} and friends with versions from the tape; needless to
8735 say, we were unhappy about having to recover the file system from
8736 backup tapes.
8737
8738 For example, if the archive contained a file @file{/usr/bin/computoy},
8739 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8740 relative to the current directory. If you want to extract the files in
8741 an archive to the same absolute names that they had when the archive
8742 was created, you should do a @samp{cd /} before extracting the files
8743 from the archive, or you should either use the @option{--absolute-names}
8744 option, or use the command @samp{tar -C / @dots{}}.
8745
8746 @cindex Ultrix 3.1 and write failure
8747 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8748 can claim that a short write near the end of a tape succeeded,
8749 when it actually failed. This will result in the -M option not
8750 working correctly. The best workaround at the moment is to use a
8751 significantly larger blocking factor than the default 20.
8752
8753 In order to update an archive, @command{tar} must be able to backspace the
8754 archive in order to reread or rewrite a record that was just read (or
8755 written). This is currently possible only on two kinds of files: normal
8756 disk files (or any other file that can be backspaced with @samp{lseek}),
8757 and industry-standard 9-track magnetic tape (or any other kind of tape
8758 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8759
8760 This means that the @option{--append}, @option{--concatenate}, and
8761 @option{--delete} commands will not work on any other kind of file.
8762 Some media simply cannot be backspaced, which means these commands and
8763 options will never be able to work on them. These non-backspacing
8764 media include pipes and cartridge tape drives.
8765
8766 Some other media can be backspaced, and @command{tar} will work on them
8767 once @command{tar} is modified to do so.
8768
8769 Archives created with the @option{--multi-volume}, @option{--label}, and
8770 @option{--incremental} (@option{-G}) options may not be readable by other version
8771 of @command{tar}. In particular, restoring a file that was split over
8772 a volume boundary will require some careful work with @command{dd}, if
8773 it can be done at all. Other versions of @command{tar} may also create
8774 an empty file whose name is that of the volume header. Some versions
8775 of @command{tar} may create normal files instead of directories archived
8776 with the @option{--incremental} (@option{-G}) option.
8777
8778 @node Common Problems and Solutions
8779 @section Some Common Problems and their Solutions
8780
8781 @ifclear PUBLISH
8782
8783 @format
8784 errors from system:
8785 permission denied
8786 no such file or directory
8787 not owner
8788
8789 errors from @command{tar}:
8790 directory checksum error
8791 header format error
8792
8793 errors from media/system:
8794 i/o error
8795 device busy
8796 @end format
8797
8798 @end ifclear
8799
8800 @node Blocking
8801 @section Blocking
8802 @UNREVISED
8803
8804 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8805 is also confusing to the expert reader. On the other hand, readers
8806 who are new to the field have a fresh mind, and they may safely skip
8807 the next two paragraphs, as the remainder of this manual uses those
8808 two terms in a quite consistent way.
8809
8810 John Gilmore, the writer of the public domain @command{tar} from which
8811 @GNUTAR{} was originally derived, wrote (June 1995):
8812
8813 @quotation
8814 The nomenclature of tape drives comes from IBM, where I believe
8815 they were invented for the IBM 650 or so. On IBM mainframes, what
8816 is recorded on tape are tape blocks. The logical organization of
8817 data is into records. There are various ways of putting records into
8818 blocks, including @code{F} (fixed sized records), @code{V} (variable
8819 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8820 to a block), @code{VB} (variable size records, @var{n} to a block),
8821 @code{VSB} (variable spanned blocked: variable sized records that can
8822 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8823 parameter specified this to the operating system.
8824
8825 The Unix man page on @command{tar} was totally confused about this.
8826 When I wrote @code{PD TAR}, I used the historically correct terminology
8827 (@command{tar} writes data records, which are grouped into blocks).
8828 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8829 here), and now Fran@,{c}ois has migrated that terminology back
8830 into the source code too.
8831 @end quotation
8832
8833 The term @dfn{physical block} means the basic transfer chunk from or
8834 to a device, after which reading or writing may stop without anything
8835 being lost. In this manual, the term @dfn{block} usually refers to
8836 a disk physical block, @emph{assuming} that each disk block is 512
8837 bytes in length. It is true that some disk devices have different
8838 physical blocks, but @command{tar} ignore these differences in its own
8839 format, which is meant to be portable, so a @command{tar} block is always
8840 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8841 The term @dfn{logical block} often represents the basic chunk of
8842 allocation of many disk blocks as a single entity, which the operating
8843 system treats somewhat atomically; this concept is only barely used
8844 in @GNUTAR{}.
8845
8846 The term @dfn{physical record} is another way to speak of a physical
8847 block, those two terms are somewhat interchangeable. In this manual,
8848 the term @dfn{record} usually refers to a tape physical block,
8849 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8850 It is true that archives may be put on disk or used with pipes,
8851 but nevertheless, @command{tar} tries to read and write the archive one
8852 @dfn{record} at a time, whatever the medium in use. One record is made
8853 up of an integral number of blocks, and this operation of putting many
8854 disk blocks into a single tape block is called @dfn{reblocking}, or
8855 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8856 the logical organization of many characters into something meaningful
8857 to the application. The term @dfn{unit record} describes a small set
8858 of characters which are transmitted whole to or by the application,
8859 and often refers to a line of text. Those two last terms are unrelated
8860 to what we call a @dfn{record} in @GNUTAR{}.
8861
8862 When writing to tapes, @command{tar} writes the contents of the archive
8863 in chunks known as @dfn{records}. To change the default blocking
8864 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8865 @var{512-size}}) option. Each record will then be composed of
8866 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8867 @xref{Standard}.) Each file written to the archive uses at least one
8868 full record. As a result, using a larger record size can result in
8869 more wasted space for small files. On the other hand, a larger record
8870 size can often be read and written much more efficiently.
8871
8872 Further complicating the problem is that some tape drives ignore the
8873 blocking entirely. For these, a larger record size can still improve
8874 performance (because the software layers above the tape drive still
8875 honor the blocking), but not as dramatically as on tape drives that
8876 honor blocking.
8877
8878 When reading an archive, @command{tar} can usually figure out the
8879 record size on itself. When this is the case, and a non-standard
8880 record size was used when the archive was created, @command{tar} will
8881 print a message about a non-standard blocking factor, and then operate
8882 normally. On some tape devices, however, @command{tar} cannot figure
8883 out the record size itself. On most of those, you can specify a
8884 blocking factor (with @option{--blocking-factor}) larger than the
8885 actual blocking factor, and then use the @option{--read-full-records}
8886 (@option{-B}) option. (If you specify a blocking factor with
8887 @option{--blocking-factor} and don't use the
8888 @option{--read-full-records} option, then @command{tar} will not
8889 attempt to figure out the recording size itself.) On some devices,
8890 you must always specify the record size exactly with
8891 @option{--blocking-factor} when reading, because @command{tar} cannot
8892 figure it out. In any case, use @option{--list} (@option{-t}) before
8893 doing any extractions to see whether @command{tar} is reading the archive
8894 correctly.
8895
8896 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8897 putting them into records is to put a whole number of them (one or
8898 more) into each record. @command{tar} records are all the same size;
8899 at the end of the file there's a block containing all zeros, which
8900 is how you tell that the remainder of the last record(s) are garbage.
8901
8902 In a standard @command{tar} file (no options), the block size is 512
8903 and the record size is 10240, for a blocking factor of 20. What the
8904 @option{--blocking-factor} option does is sets the blocking factor,
8905 changing the record size while leaving the block size at 512 bytes.
8906 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8907 most tape drives these days prefer much bigger records in order to
8908 stream and not waste tape. When writing tapes for myself, some tend
8909 to use a factor of the order of 2048, say, giving a record size of
8910 around one megabyte.
8911
8912 If you use a blocking factor larger than 20, older @command{tar}
8913 programs might not be able to read the archive, so we recommend this
8914 as a limit to use in practice. @GNUTAR{}, however,
8915 will support arbitrarily large record sizes, limited only by the
8916 amount of virtual memory or the physical characteristics of the tape
8917 device.
8918
8919 @menu
8920 * Format Variations:: Format Variations
8921 * Blocking Factor:: The Blocking Factor of an Archive
8922 @end menu
8923
8924 @node Format Variations
8925 @subsection Format Variations
8926 @cindex Format Parameters
8927 @cindex Format Options
8928 @cindex Options, archive format specifying
8929 @cindex Options, format specifying
8930 @UNREVISED
8931
8932 Format parameters specify how an archive is written on the archive
8933 media. The best choice of format parameters will vary depending on
8934 the type and number of files being archived, and on the media used to
8935 store the archive.
8936
8937 To specify format parameters when accessing or creating an archive,
8938 you can use the options described in the following sections.
8939 If you do not specify any format parameters, @command{tar} uses
8940 default parameters. You cannot modify a compressed archive.
8941 If you create an archive with the @option{--blocking-factor} option
8942 specified (@pxref{Blocking Factor}), you must specify that
8943 blocking-factor when operating on the archive. @xref{Formats}, for other
8944 examples of format parameter considerations.
8945
8946 @node Blocking Factor
8947 @subsection The Blocking Factor of an Archive
8948 @cindex Blocking Factor
8949 @cindex Record Size
8950 @cindex Number of blocks per record
8951 @cindex Number of bytes per record
8952 @cindex Bytes per record
8953 @cindex Blocks per record
8954 @UNREVISED
8955
8956 @opindex blocking-factor
8957 The data in an archive is grouped into blocks, which are 512 bytes.
8958 Blocks are read and written in whole number multiples called
8959 @dfn{records}. The number of blocks in a record (ie. the size of a
8960 record in units of 512 bytes) is called the @dfn{blocking factor}.
8961 The @option{--blocking-factor=@var{512-size}} (@option{-b
8962 @var{512-size}}) option specifies the blocking factor of an archive.
8963 The default blocking factor is typically 20 (i.e., 10240 bytes), but
8964 can be specified at installation. To find out the blocking factor of
8965 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
8966 This may not work on some devices.
8967
8968 Records are separated by gaps, which waste space on the archive media.
8969 If you are archiving on magnetic tape, using a larger blocking factor
8970 (and therefore larger records) provides faster throughput and allows you
8971 to fit more data on a tape (because there are fewer gaps). If you are
8972 archiving on cartridge, a very large blocking factor (say 126 or more)
8973 greatly increases performance. A smaller blocking factor, on the other
8974 hand, may be useful when archiving small files, to avoid archiving lots
8975 of nulls as @command{tar} fills out the archive to the end of the record.
8976 In general, the ideal record size depends on the size of the
8977 inter-record gaps on the tape you are using, and the average size of the
8978 files you are archiving. @xref{create}, for information on
8979 writing archives.
8980
8981 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
8982
8983 Archives with blocking factors larger than 20 cannot be read
8984 by very old versions of @command{tar}, or by some newer versions
8985 of @command{tar} running on old machines with small address spaces.
8986 With @GNUTAR{}, the blocking factor of an archive is limited
8987 only by the maximum record size of the device containing the archive,
8988 or by the amount of available virtual memory.
8989
8990 Also, on some systems, not using adequate blocking factors, as sometimes
8991 imposed by the device drivers, may yield unexpected diagnostics. For
8992 example, this has been reported:
8993
8994 @smallexample
8995 Cannot write to /dev/dlt: Invalid argument
8996 @end smallexample
8997
8998 @noindent
8999 In such cases, it sometimes happen that the @command{tar} bundled by
9000 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9001 requires an explicit specification for the block size,
9002 which it cannot guess. This yields some people to consider
9003 @GNUTAR{} is misbehaving, because by comparison,
9004 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9005 for example, might resolve the problem.
9006
9007 If you use a non-default blocking factor when you create an archive, you
9008 must specify the same blocking factor when you modify that archive. Some
9009 archive devices will also require you to specify the blocking factor when
9010 reading that archive, however this is not typically the case. Usually, you
9011 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9012 reports a non-default record size and then lists the archive members as
9013 it would normally. To extract files from an archive with a non-standard
9014 blocking factor (particularly if you're not sure what the blocking factor
9015 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9016 specifying a blocking factor larger then the blocking factor of the archive
9017 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
9018 @xref{list}, for more information on the @option{--list} (@option{-t})
9019 operation. @xref{Reading}, for a more detailed explanation of that option.
9020
9021 @table @option
9022 @item --blocking-factor=@var{number}
9023 @itemx -b @var{number}
9024 Specifies the blocking factor of an archive. Can be used with any
9025 operation, but is usually not necessary with @option{--list} (@option{-t}).
9026 @end table
9027
9028 Device blocking
9029
9030 @table @option
9031 @item -b @var{blocks}
9032 @itemx --blocking-factor=@var{blocks}
9033 Set record size to @math{@var{blocks} * 512} bytes.
9034
9035 This option is used to specify a @dfn{blocking factor} for the archive.
9036 When reading or writing the archive, @command{tar}, will do reads and writes
9037 of the archive in records of @math{@var{block}*512} bytes. This is true
9038 even when the archive is compressed. Some devices requires that all
9039 write operations be a multiple of a certain size, and so, @command{tar}
9040 pads the archive out to the next record boundary.
9041
9042 The default blocking factor is set when @command{tar} is compiled, and is
9043 typically 20. Blocking factors larger than 20 cannot be read by very
9044 old versions of @command{tar}, or by some newer versions of @command{tar}
9045 running on old machines with small address spaces.
9046
9047 With a magnetic tape, larger records give faster throughput and fit
9048 more data on a tape (because there are fewer inter-record gaps).
9049 If the archive is in a disk file or a pipe, you may want to specify
9050 a smaller blocking factor, since a large one will result in a large
9051 number of null bytes at the end of the archive.
9052
9053 When writing cartridge or other streaming tapes, a much larger
9054 blocking factor (say 126 or more) will greatly increase performance.
9055 However, you must specify the same blocking factor when reading or
9056 updating the archive.
9057
9058 Apparently, Exabyte drives have a physical block size of 8K bytes.
9059 If we choose our blocksize as a multiple of 8k bytes, then the problem
9060 seems to disappear. Id est, we are using block size of 112 right
9061 now, and we haven't had the problem since we switched@dots{}
9062
9063 With @GNUTAR{} the blocking factor is limited only
9064 by the maximum record size of the device containing the archive, or by
9065 the amount of available virtual memory.
9066
9067 However, deblocking or reblocking is virtually avoided in a special
9068 case which often occurs in practice, but which requires all the
9069 following conditions to be simultaneously true:
9070 @itemize @bullet
9071 @item
9072 the archive is subject to a compression option,
9073 @item
9074 the archive is not handled through standard input or output, nor
9075 redirected nor piped,
9076 @item
9077 the archive is directly handled to a local disk, instead of any special
9078 device,
9079 @item
9080 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9081 invocation.
9082 @end itemize
9083
9084 If the output goes directly to a local disk, and not through
9085 stdout, then the last write is not extended to a full record size.
9086 Otherwise, reblocking occurs. Here are a few other remarks on this
9087 topic:
9088
9089 @itemize @bullet
9090
9091 @item
9092 @command{gzip} will complain about trailing garbage if asked to
9093 uncompress a compressed archive on tape, there is an option to turn
9094 the message off, but it breaks the regularity of simply having to use
9095 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9096 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9097 Gailly, by sending a copy of this message to him.
9098
9099 @item
9100 @command{compress} does not show this problem, but as Jean-loup pointed
9101 out to Michael, @samp{compress -d} silently adds garbage after
9102 the result of decompression, which tar ignores because it already
9103 recognized its end-of-file indicator. So this bug may be safely
9104 ignored.
9105
9106 @item
9107 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9108 but will still return an exit status of 2 which tar reports in turn.
9109 @command{tar} might ignore the exit status returned, but I hate doing
9110 that, as it weakens the protection @command{tar} offers users against
9111 other possible problems at decompression time. If @command{gzip} was
9112 silently skipping trailing zeros @emph{and} also avoiding setting the
9113 exit status in this innocuous case, that would solve this situation.
9114
9115 @item
9116 @command{tar} should become more solid at not stopping to read a pipe at
9117 the first null block encountered. This inelegantly breaks the pipe.
9118 @command{tar} should rather drain the pipe out before exiting itself.
9119 @end itemize
9120
9121 @opindex ignore-zeros, short description
9122 @item -i
9123 @itemx --ignore-zeros
9124 Ignore blocks of zeros in archive (means EOF).
9125
9126 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9127 of zeros in the archive. Normally a block of zeros indicates the
9128 end of the archive, but when reading a damaged archive, or one which
9129 was created by concatenating several archives together, this option
9130 allows @command{tar} to read the entire archive. This option is not on
9131 by default because many versions of @command{tar} write garbage after
9132 the zeroed blocks.
9133
9134 Note that this option causes @command{tar} to read to the end of the
9135 archive file, which may sometimes avoid problems when multiple files
9136 are stored on a single physical tape.
9137
9138 @opindex read-full-records, short description
9139 @item -B
9140 @itemx --read-full-records
9141 Reblock as we read (for reading 4.2BSD pipes).
9142
9143 If @option{--read-full-records} is used, @command{tar}
9144 will not panic if an attempt to read a record from the archive does
9145 not return a full record. Instead, @command{tar} will keep reading
9146 until it has obtained a full
9147 record.
9148
9149 This option is turned on by default when @command{tar} is reading
9150 an archive from standard input, or from a remote machine. This is
9151 because on BSD Unix systems, a read of a pipe will return however
9152 much happens to be in the pipe, even if it is less than @command{tar}
9153 requested. If this option was not used, @command{tar} would fail as
9154 soon as it read an incomplete record from the pipe.
9155
9156 This option is also useful with the commands for updating an archive.
9157
9158 @end table
9159
9160 Tape blocking
9161
9162 @FIXME{Appropriate options should be moved here from elsewhere.}
9163
9164 @cindex blocking factor
9165 @cindex tape blocking
9166
9167 When handling various tapes or cartridges, you have to take care of
9168 selecting a proper blocking, that is, the number of disk blocks you
9169 put together as a single tape block on the tape, without intervening
9170 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9171 with no information on it, used for decelerating the tape to a
9172 full stop, and for later regaining the reading or writing speed.
9173 When the tape driver starts reading a record, the record has to
9174 be read whole without stopping, as a tape gap is needed to stop the
9175 tape motion without loosing information.
9176
9177 @cindex Exabyte blocking
9178 @cindex DAT blocking
9179 Using higher blocking (putting more disk blocks per tape block) will use
9180 the tape more efficiently as there will be less tape gaps. But reading
9181 such tapes may be more difficult for the system, as more memory will be
9182 required to receive at once the whole record. Further, if there is a
9183 reading error on a huge record, this is less likely that the system will
9184 succeed in recovering the information. So, blocking should not be too
9185 low, nor it should be too high. @command{tar} uses by default a blocking of
9186 20 for historical reasons, and it does not really matter when reading or
9187 writing to disk. Current tape technology would easily accommodate higher
9188 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9189 We were told that for some DLT drives, the blocking should be a multiple
9190 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9191 Other manufacturers may use different recommendations for the same tapes.
9192 This might also depends of the buffering techniques used inside modern
9193 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9194 Others request blocking to be some exponent of two.
9195
9196 So, there is no fixed rule for blocking. But blocking at read time
9197 should ideally be the same as blocking used at write time. At one place
9198 I know, with a wide variety of equipment, they found it best to use a
9199 blocking of 32 to guarantee that their tapes are fully interchangeable.
9200
9201 I was also told that, for recycled tapes, prior erasure (by the same
9202 drive unit that will be used to create the archives) sometimes lowers
9203 the error rates observed at rewriting time.
9204
9205 I might also use @option{--number-blocks} instead of
9206 @option{--block-number}, so @option{--block} will then expand to
9207 @option{--blocking-factor} unambiguously.
9208
9209 @node Many
9210 @section Many Archives on One Tape
9211
9212 @FIXME{Appropriate options should be moved here from elsewhere.}
9213
9214 @findex ntape @r{device}
9215 Most tape devices have two entries in the @file{/dev} directory, or
9216 entries that come in pairs, which differ only in the minor number for
9217 this device. Let's take for example @file{/dev/tape}, which often
9218 points to the only or usual tape device of a given system. There might
9219 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9220 name is the @emph{rewinding} version of the device, while the name
9221 having @samp{nr} in it is the @emph{no rewinding} version of the same
9222 device.
9223
9224 A rewinding tape device will bring back the tape to its beginning point
9225 automatically when this device is opened or closed. Since @command{tar}
9226 opens the archive file before using it and closes it afterwards, this
9227 means that a simple:
9228
9229 @smallexample
9230 $ @kbd{tar cf /dev/tape @var{directory}}
9231 @end smallexample
9232
9233 @noindent
9234 will reposition the tape to its beginning both prior and after saving
9235 @var{directory} contents to it, thus erasing prior tape contents and
9236 making it so that any subsequent write operation will destroy what has
9237 just been saved.
9238
9239 @cindex tape positioning
9240 So, a rewinding device is normally meant to hold one and only one file.
9241 If you want to put more than one @command{tar} archive on a given tape, you
9242 will need to avoid using the rewinding version of the tape device. You
9243 will also have to pay special attention to tape positioning. Errors in
9244 positioning may overwrite the valuable data already on your tape. Many
9245 people, burnt by past experiences, will only use rewinding devices and
9246 limit themselves to one file per tape, precisely to avoid the risk of
9247 such errors. Be fully aware that writing at the wrong position on a
9248 tape loses all information past this point and most probably until the
9249 end of the tape, and this destroyed information @emph{cannot} be
9250 recovered.
9251
9252 To save @var{directory-1} as a first archive at the beginning of a
9253 tape, and leave that tape ready for a second archive, you should use:
9254
9255 @smallexample
9256 $ @kbd{mt -f /dev/nrtape rewind}
9257 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9258 @end smallexample
9259
9260 @cindex tape marks
9261 @dfn{Tape marks} are special magnetic patterns written on the tape
9262 media, which are later recognizable by the reading hardware. These
9263 marks are used after each file, when there are many on a single tape.
9264 An empty file (that is to say, two tape marks in a row) signal the
9265 logical end of the tape, after which no file exist. Usually,
9266 non-rewinding tape device drivers will react to the close request issued
9267 by @command{tar} by first writing two tape marks after your archive, and by
9268 backspacing over one of these. So, if you remove the tape at that time
9269 from the tape drive, it is properly terminated. But if you write
9270 another file at the current position, the second tape mark will be
9271 erased by the new information, leaving only one tape mark between files.
9272
9273 So, you may now save @var{directory-2} as a second archive after the
9274 first on the same tape by issuing the command:
9275
9276 @smallexample
9277 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9278 @end smallexample
9279
9280 @noindent
9281 and so on for all the archives you want to put on the same tape.
9282
9283 Another usual case is that you do not write all the archives the same
9284 day, and you need to remove and store the tape between two archive
9285 sessions. In general, you must remember how many files are already
9286 saved on your tape. Suppose your tape already has 16 files on it, and
9287 that you are ready to write the 17th. You have to take care of skipping
9288 the first 16 tape marks before saving @var{directory-17}, say, by using
9289 these commands:
9290
9291 @smallexample
9292 $ @kbd{mt -f /dev/nrtape rewind}
9293 $ @kbd{mt -f /dev/nrtape fsf 16}
9294 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9295 @end smallexample
9296
9297 In all the previous examples, we put aside blocking considerations, but
9298 you should do the proper things for that as well. @xref{Blocking}.
9299
9300 @menu
9301 * Tape Positioning:: Tape Positions and Tape Marks
9302 * mt:: The @command{mt} Utility
9303 @end menu
9304
9305 @node Tape Positioning
9306 @subsection Tape Positions and Tape Marks
9307 @UNREVISED
9308
9309 Just as archives can store more than one file from the file system,
9310 tapes can store more than one archive file. To keep track of where
9311 archive files (or any other type of file stored on tape) begin and
9312 end, tape archive devices write magnetic @dfn{tape marks} on the
9313 archive media. Tape drives write one tape mark between files,
9314 two at the end of all the file entries.
9315
9316 If you think of data as a series of records "rrrr"'s, and tape marks as
9317 "*"'s, a tape might look like the following:
9318
9319 @smallexample
9320 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9321 @end smallexample
9322
9323 Tape devices read and write tapes using a read/write @dfn{tape
9324 head}---a physical part of the device which can only access one
9325 point on the tape at a time. When you use @command{tar} to read or
9326 write archive data from a tape device, the device will begin reading
9327 or writing from wherever on the tape the tape head happens to be,
9328 regardless of which archive or what part of the archive the tape
9329 head is on. Before writing an archive, you should make sure that no
9330 data on the tape will be overwritten (unless it is no longer needed).
9331 Before reading an archive, you should make sure the tape head is at
9332 the beginning of the archive you want to read. You can do it manually
9333 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9334 that automatically (@pxref{Scripted Restoration}).
9335
9336 If you want to add new archive file entries to a tape, you should
9337 advance the tape to the end of the existing file entries, backspace
9338 over the last tape mark, and write the new archive file. If you were
9339 to add two archives to the example above, the tape might look like the
9340 following:
9341
9342 @smallexample
9343 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9344 @end smallexample
9345
9346 @node mt
9347 @subsection The @command{mt} Utility
9348 @UNREVISED
9349
9350 @FIXME{Is it true that this only works on non-block devices?
9351 should explain the difference, (fixed or variable).}
9352 @xref{Blocking Factor}.
9353
9354 You can use the @command{mt} utility to advance or rewind a tape past a
9355 specified number of archive files on the tape. This will allow you
9356 to move to the beginning of an archive before extracting or reading
9357 it, or to the end of all the archives before writing a new one.
9358 @FIXME{Why isn't there an "advance 'til you find two tape marks
9359 together"?}
9360
9361 The syntax of the @command{mt} command is:
9362
9363 @smallexample
9364 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9365 @end smallexample
9366
9367 where @var{tapename} is the name of the tape device, @var{number} is
9368 the number of times an operation is performed (with a default of one),
9369 and @var{operation} is one of the following:
9370
9371 @FIXME{is there any use for record operations?}
9372
9373 @table @option
9374 @item eof
9375 @itemx weof
9376 Writes @var{number} tape marks at the current position on the tape.
9377
9378 @item fsf
9379 Moves tape position forward @var{number} files.
9380
9381 @item bsf
9382 Moves tape position back @var{number} files.
9383
9384 @item rewind
9385 Rewinds the tape. (Ignores @var{number}).
9386
9387 @item offline
9388 @itemx rewoff1
9389 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9390
9391 @item status
9392 Prints status information about the tape unit.
9393
9394 @end table
9395
9396 @FIXME{Is there a better way to frob the spacing on the list?}
9397
9398 If you don't specify a @var{tapename}, @command{mt} uses the environment
9399 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9400 the default device specified in your @file{sys/mtio.h} file
9401 (@code{DEFTAPE} variable). If this is not defined, the program will
9402 display a descriptive error message and exit with code 1.
9403
9404 @command{mt} returns a 0 exit status when the operation(s) were
9405 successful, 1 if the command was unrecognized, and 2 if an operation
9406 failed.
9407
9408 @node Using Multiple Tapes
9409 @section Using Multiple Tapes
9410 @UNREVISED
9411
9412 Often you might want to write a large archive, one larger than will fit
9413 on the actual tape you are using. In such a case, you can run multiple
9414 @command{tar} commands, but this can be inconvenient, particularly if you
9415 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9416 Therefore, @command{tar} supports multiple tapes automatically.
9417
9418 Use @option{--multi-volume} (@option{-M}) on the command line, and
9419 then @command{tar} will, when it reaches the end of the tape, prompt
9420 for another tape, and continue the archive. Each tape will have an
9421 independent archive, and can be read without needing the other. (As
9422 an exception to this, the file that @command{tar} was archiving when
9423 it ran out of tape will usually be split between the two archives; in
9424 this case you need to extract from the first archive, using
9425 @option{--multi-volume}, and then put in the second tape when
9426 prompted, so @command{tar} can restore both halves of the file.)
9427
9428 @GNUTAR{} multi-volume archives do not use a truly portable format.
9429 You need @GNUTAR{} at both ends to process them properly.
9430
9431 When prompting for a new tape, @command{tar} accepts any of the following
9432 responses:
9433
9434 @table @kbd
9435 @item ?
9436 Request @command{tar} to explain possible responses
9437 @item q
9438 Request @command{tar} to exit immediately.
9439 @item n @var{file-name}
9440 Request @command{tar} to write the next volume on the file @var{file-name}.
9441 @item !
9442 Request @command{tar} to run a subshell. This option can be disabled
9443 by giving @option{--restrict} command line option to @command{tar}.
9444 @item y
9445 Request @command{tar} to begin writing the next volume.
9446 @end table
9447
9448 (You should only type @samp{y} after you have changed the tape;
9449 otherwise @command{tar} will write over the volume it just finished.)
9450
9451 @cindex End-of-archive info script
9452 @cindex Info script
9453 @anchor{info-script}
9454 @opindex info-script
9455 @opindex new-volume-script
9456 If you want more elaborate behavior than this, give @command{tar} the
9457 @option{--info-script=@var{script-name}}
9458 (@option{--new-volume-script=@var{script-name}}, @option{-F
9459 @var{script-name}}) option. The file @var{script-name} is expected to
9460 be a program (or shell script) to be run instead of the normal
9461 prompting procedure. It is executed without any command line
9462 arguments. Additional data is passed to it via the following
9463 environment variables:
9464
9465 @table @env
9466 @vrindex TAR_VERSION, info script environment variable
9467 @item TAR_VERSION
9468 @GNUTAR{} version number.
9469
9470 @vrindex TAR_ARCHIVE, info script environment variable
9471 @item TAR_ARCHIVE
9472 The name of the archive @command{tar} is processing.
9473
9474 @vrindex TAR_VOLUME, info script environment variable
9475 @item TAR_VOLUME
9476 Ordinal number of the volume @command{tar} is about to start.
9477
9478 @vrindex TAR_SUBCOMMAND, info script environment variable
9479 @item TAR_SUBCOMMAND
9480 Short option describing the operation @command{tar} is executing
9481 @xref{Operations}, for a complete list of subcommand options.
9482
9483 @vrindex TAR_FORMAT, info script environment variable
9484 @item TAR_FORMAT
9485 Format of the archive being processed. @xref{Formats}, for a complete
9486 list of archive format names.
9487 @end table
9488
9489 The info script can instruct @command{tar} to use new archive name,
9490 by writing in to file descriptor 3 (see below for an
9491 example).
9492
9493 If the info script fails, @command{tar} exits; otherwise, it begins
9494 writing the next volume.
9495
9496 The method @command{tar} uses to detect end of tape is not perfect, and
9497 fails on some operating systems or on some devices. You can use the
9498 @option{--tape-length=@var{size}} (@option{-L @var{size}}) option if
9499 @command{tar} can't detect the end of the tape itself. This option
9500 selects @option{--multi-volume} (@option{-M}) automatically. The
9501 @var{size} argument should then be the usable size of the tape in
9502 units of 1024 bytes. But for many devices, and floppy disks in
9503 particular, this option is never required for real, as far as we know.
9504
9505 @cindex Volume number file
9506 @cindex volno file
9507 @anchor{volno-file}
9508 @opindex volno-file
9509 The volume number used by @command{tar} in its tape-change prompt
9510 can be changed; if you give the
9511 @option{--volno-file=@var{file-of-number}} option, then
9512 @var{file-of-number} should be an unexisting file to be created, or
9513 else, a file already containing a decimal number. That number will be
9514 used as the volume number of the first volume written. When
9515 @command{tar} is finished, it will rewrite the file with the
9516 now-current volume number. (This does not change the volume number
9517 written on a tape label, as per @ref{label}, it @emph{only} affects
9518 the number used in the prompt.)
9519
9520 If you want @command{tar} to cycle through a series of files or tape
9521 drives, there are three approaches to choose from. First of all, you
9522 can give @command{tar} multiple @option{--file} options. In this case
9523 the specified files will be used, in sequence, as the successive
9524 volumes of the archive. Only when the first one in the sequence needs
9525 to be used again will @command{tar} prompt for a tape change (or run
9526 the info script). Secondly, you can use the @samp{n} response to the
9527 tape-change prompt, and, finally, you can use an info script, that
9528 writes new archive name to file descriptor. The following example
9529 illustrates this approach:
9530
9531 @smallexample
9532 @group
9533 #! /bin/sh
9534 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9535
9536 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9537 case $TAR_SUBCOMMAND in
9538 -c) ;;
9539 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9540 ;;
9541 *) exit 1
9542 esac
9543
9544 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9545 @end group
9546 @end smallexample
9547
9548 Each volume of a multi-volume archive is an independent @command{tar}
9549 archive, complete in itself. For example, you can list or extract any
9550 volume alone; just don't specify @option{--multi-volume}
9551 (@option{-M}). However, if one file in the archive is split across
9552 volumes, the only way to extract it successfully is with a
9553 multi-volume extract command @option{--extract --multi-volume}
9554 (@option{-xM}) starting on or before the volume where the file begins.
9555
9556 For example, let's presume someone has two tape drives on a system
9557 named @file{/dev/tape0} and @file{/dev/tape1}. For having @GNUTAR{}
9558 to switch to the second drive when it needs to write the
9559 second tape, and then back to the first tape, etc., just do either of:
9560
9561 @smallexample
9562 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9563 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9564 @end smallexample
9565
9566 @menu
9567 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9568 * Tape Files:: Tape Files
9569 * Tarcat:: Concatenate Volumes into a Single Archive
9570
9571 @end menu
9572
9573 @node Multi-Volume Archives
9574 @subsection Archives Longer than One Tape or Disk
9575 @cindex Multi-volume archives
9576 @UNREVISED
9577
9578 @opindex multi-volume
9579 To create an archive that is larger than will fit on a single unit of
9580 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9581 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9582 archive can be manipulated like any other archive (provided the
9583 @option{--multi-volume} option is specified), but is stored on more
9584 than one tape or disk.
9585
9586 When you specify @option{--multi-volume}, @command{tar} does not report an
9587 error when it comes to the end of an archive volume (when reading), or
9588 the end of the media (when writing). Instead, it prompts you to load
9589 a new storage volume. If the archive is on a magnetic tape, you
9590 should change tapes when you see the prompt; if the archive is on a
9591 floppy disk, you should change disks; etc.
9592
9593 You can read each individual volume of a multi-volume archive as if it
9594 were an archive by itself. For example, to list the contents of one
9595 volume, use @option{--list}, without @option{--multi-volume} specified.
9596 To extract an archive member from one volume (assuming it is described
9597 that volume), use @option{--extract}, again without
9598 @option{--multi-volume}.
9599
9600 If an archive member is split across volumes (ie. its entry begins on
9601 one volume of the media and ends on another), you need to specify
9602 @option{--multi-volume} to extract it successfully. In this case, you
9603 should load the volume where the archive member starts, and use
9604 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9605 volumes as it needs them. @xref{extracting archives}, for more
9606 information about extracting archives.
9607
9608 @option{--info-script=@var{script-name}}
9609 (@option{--new-volume-script=@var{script-name}}, @option{-F
9610 @var{script-name}}) (@pxref{info-script}) is like
9611 @option{--multi-volume} (@option{-M}), except that @command{tar} does
9612 not prompt you directly to change media volumes when a volume is
9613 full---instead, @command{tar} runs commands you have stored in
9614 @var{script-name}. For example, this option can be used to eject
9615 cassettes, or to broadcast messages such as @samp{Someone please come
9616 change my tape} when performing unattended backups. When
9617 @var{script-name} is done, @command{tar} will assume that the media
9618 has been changed.
9619
9620 Multi-volume archives can be modified like any other archive. To add
9621 files to a multi-volume archive, you need to only mount the last
9622 volume of the archive media (and new volumes, if needed). For all
9623 other operations, you need to use the entire archive.
9624
9625 If a multi-volume archive was labeled using
9626 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9627 (@pxref{label}) when it was created, @command{tar} will not
9628 automatically label volumes which are added later. To label
9629 subsequent volumes, specify @option{--label=@var{archive-label}} again
9630 in conjunction with the @option{--append}, @option{--update} or
9631 @option{--concatenate} operation.
9632
9633 @cindex Labeling multi-volume archives
9634 @FIXME{example}
9635
9636 @FIXME{There should be a sample program here, including an exit
9637 before end. Is the exit status even checked in tar? :-(}
9638
9639 @table @option
9640 @item --multi-volume
9641 @itemx -M
9642 Creates a multi-volume archive, when used in conjunction with
9643 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9644 archive, specify @option{--multi-volume} in conjunction with that
9645 operation.
9646
9647 @item --info-script=@var{program-file}
9648 @itemx --new-volume-script=@var{program-file}
9649 @itemx -F @var{program-file}
9650 Creates a multi-volume archive via a script. Used in conjunction with
9651 @option{--create} (@option{-c}). @xref{info-script}, dor a detailed discussion.
9652 @end table
9653
9654 Beware that there is @emph{no} real standard about the proper way, for
9655 a @command{tar} archive, to span volume boundaries. If you have a
9656 multi-volume created by some vendor's @command{tar}, there is almost
9657 no chance you could read all the volumes with @GNUTAR{}.
9658 The converse is also true: you may not expect
9659 multi-volume archives created by @GNUTAR{} to be
9660 fully recovered by vendor's @command{tar}. Since there is little
9661 chance that, in mixed system configurations, some vendor's
9662 @command{tar} will work on another vendor's machine, and there is a
9663 great chance that @GNUTAR{} will work on most of
9664 them, your best bet is to install @GNUTAR{} on all
9665 machines between which you know exchange of files is possible.
9666
9667 @node Tape Files
9668 @subsection Tape Files
9669 @UNREVISED
9670
9671 To give the archive a name which will be recorded in it, use the
9672 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9673 option. This will write a special block identifying
9674 @var{volume-label} as the name of the archive to the front of the
9675 archive which will be displayed when the archive is listed with
9676 @option{--list}. If you are creating a multi-volume archive with
9677 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9678 volume label will have @samp{Volume @var{nnn}} appended to the name
9679 you give, where @var{nnn} is the number of the volume of the archive.
9680 (If you use the @option{--label=@var{volume-label}}) option when
9681 reading an archive, it checks to make sure the label on the tape
9682 matches the one you give. @xref{label}.
9683
9684 When @command{tar} writes an archive to tape, it creates a single
9685 tape file. If multiple archives are written to the same tape, one
9686 after the other, they each get written as separate tape files. When
9687 extracting, it is necessary to position the tape at the right place
9688 before running @command{tar}. To do this, use the @command{mt} command.
9689 For more information on the @command{mt} command and on the organization
9690 of tapes into a sequence of tape files, see @ref{mt}.
9691
9692 People seem to often do:
9693
9694 @smallexample
9695 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9696 @end smallexample
9697
9698 or such, for pushing a common date in all volumes or an archive set.
9699
9700 @node Tarcat
9701 @subsection Concatenate Volumes into a Single Archive
9702
9703 @pindex tarcat
9704 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9705 archive to a single @command{tar} archive. Simply concatenating all
9706 volumes into one will not work, since each volume carries an additional
9707 information at the beginning. @GNUTAR{} is shipped with the shell
9708 script @command{tarcat} designed for this purpose.
9709
9710 The script takes a list of files comprising a multi-volume archive
9711 and creates the resulting archive at the standard output. For example:
9712
9713 @smallexample
9714 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9715 @end smallexample
9716
9717 The script implements a simple heuristics to determine the format of
9718 the first volume file and to decide how to process the rest of the
9719 files. However, it makes no attempt to verify whether the files are
9720 given in order or even if they are valid @command{tar} archives.
9721 It uses @command{dd} and does not filter its standard error, so you
9722 will usually see lots of spurious messages.
9723
9724 @FIXME{The script is not installed. Should we install it?}
9725
9726 @node label
9727 @section Including a Label in the Archive
9728 @cindex Labeling an archive
9729 @cindex Labels on the archive media
9730 @UNREVISED
9731
9732 @opindex label
9733 To avoid problems caused by misplaced paper labels on the archive
9734 media, you can include a @dfn{label} entry---an archive member which
9735 contains the name of the archive---in the archive itself. Use the
9736 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9737 option in conjunction with the @option{--create} operation to include
9738 a label entry in the archive as it is being created.
9739
9740 @table @option
9741 @item --label=@var{archive-label}
9742 @itemx -V @var{archive-label}
9743 Includes an @dfn{archive-label} at the beginning of the archive when
9744 the archive is being created, when used in conjunction with the
9745 @option{--create} operation. Checks to make sure the archive label
9746 matches the one specified (when used in conjunction with any other
9747 operation.
9748 @end table
9749
9750 If you create an archive using both
9751 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9752 and @option{--multi-volume} (@option{-M}), each volume of the archive
9753 will have an archive label of the form @samp{@var{archive-label}
9754 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9755 next, and so on. @xref{Using Multiple Tapes}, for information on
9756 creating multiple volume archives.
9757
9758 @cindex Volume label, listing
9759 @cindex Listing volume label
9760 The volume label will be displayed by @option{--list} along with
9761 the file contents. If verbose display is requested, it will also be
9762 explicitely marked as in the example below:
9763
9764 @smallexample
9765 @group
9766 $ @kbd{tar --verbose --list --file=iamanarchive}
9767 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9768 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9769 @end group
9770 @end smallexample
9771
9772 @opindex test-label
9773 @anchor{--test-label option}
9774 However, @option{--list} option will cause listing entire
9775 contents of the archive, which may be undesirable (for example, if the
9776 archive is stored on a tape). You can request checking only the volume
9777 by specifying @option{--test-label} option. This option reads only the
9778 first block of an archive, so it can be used with slow storage
9779 devices. For example:
9780
9781 @smallexample
9782 @group
9783 $ @kbd{tar --test-label --file=iamanarchive}
9784 iamalabel
9785 @end group
9786 @end smallexample
9787
9788 If @option{--test-label} is used with a single command line
9789 argument, @command{tar} compares the volume label with the
9790 argument. It exits with code 0 if the two strings match, and with code
9791 2 otherwise. In this case no output is displayed. For example:
9792
9793 @smallexample
9794 @group
9795 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9796 @result{} 0
9797 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9798 @result{} 1
9799 @end group
9800 @end smallexample
9801
9802 If you request any operation, other than @option{--create}, along
9803 with using @option{--label} option, @command{tar} will first check if
9804 the archive label matches the one specified and will refuse to proceed
9805 if it does not. Use this as a safety precaution to avoid accidentally
9806 overwriting existing archives. For example, if you wish to add files
9807 to @file{archive}, presumably labelled with string @samp{My volume},
9808 you will get:
9809
9810 @smallexample
9811 @group
9812 $ @kbd{tar -rf archive --label 'My volume' .}
9813 tar: Archive not labeled to match `My volume'
9814 @end group
9815 @end smallexample
9816
9817 @noindent
9818 in case its label does not match. This will work even if
9819 @file{archive} is not labelled at all.
9820
9821 Similarly, @command{tar} will refuse to list or extract the
9822 archive if its label doesn't match the @var{archive-label}
9823 specified. In those cases, @var{archive-label} argument is interpreted
9824 as a globbing-style pattern which must match the actual magnetic
9825 volume label. @xref{exclude}, for a precise description of how match
9826 is attempted@footnote{Previous versions of @command{tar} used full
9827 regular expression matching, or before that, only exact string
9828 matching, instead of wildcard matchers. We decided for the sake of
9829 simplicity to use a uniform matching device through
9830 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
9831 the volume label matcher will also suffix @var{archive-label} by
9832 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
9833 up. Since the volume numbering is automatically added in labels at
9834 creation time, it sounded logical to equally help the user taking care
9835 of it when the archive is being read.
9836
9837 The @option{--label} was once called @option{--volume}, but is not
9838 available under that name anymore.
9839
9840 You can also use @option{--label} to get a common information on
9841 all tapes of a series. For having this information different in each
9842 series created through a single script used on a regular basis, just
9843 manage to get some date string as part of the label. For example:
9844
9845 @smallexample
9846 @group
9847 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9848 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9849 --volume="Daily backup for `date +%Y-%m-%d`"}
9850 @end group
9851 @end smallexample
9852
9853 Also note that each label has its own date and time, which corresponds
9854 to when @GNUTAR{} initially attempted to write it,
9855 often soon after the operator launches @command{tar} or types the
9856 carriage return telling that the next tape is ready. Comparing date
9857 labels does give an idea of tape throughput only if the delays for
9858 rewinding tapes and the operator switching them were negligible, which
9859 is usually not the case.
9860
9861 @node verify
9862 @section Verifying Data as It is Stored
9863 @cindex Verifying a write operation
9864 @cindex Double-checking a write operation
9865
9866 @table @option
9867 @item -W
9868 @itemx --verify
9869 @opindex verify, short description
9870 Attempt to verify the archive after writing.
9871 @end table
9872
9873 This option causes @command{tar} to verify the archive after writing it.
9874 Each volume is checked after it is written, and any discrepancies
9875 are recorded on the standard error output.
9876
9877 Verification requires that the archive be on a back-space-able medium.
9878 This means pipes, some cartridge tape drives, and some other devices
9879 cannot be verified.
9880
9881 You can insure the accuracy of an archive by comparing files in the
9882 system with archive members. @command{tar} can compare an archive to the
9883 file system as the archive is being written, to verify a write
9884 operation, or can compare a previously written archive, to insure that
9885 it is up to date.
9886
9887 @opindex verify, using with @option{--create}
9888 @opindex create, using with @option{--verify}
9889 To check for discrepancies in an archive immediately after it is
9890 written, use the @option{--verify} (@option{-W}) option in conjunction with
9891 the @option{--create} operation. When this option is
9892 specified, @command{tar} checks archive members against their counterparts
9893 in the file system, and reports discrepancies on the standard error.
9894
9895 To verify an archive, you must be able to read it from before the end
9896 of the last written entry. This option is useful for detecting data
9897 errors on some tapes. Archives written to pipes, some cartridge tape
9898 drives, and some other devices cannot be verified.
9899
9900 One can explicitly compare an already made archive with the file
9901 system by using the @option{--compare} (@option{--diff}, @option{-d})
9902 option, instead of using the more automatic @option{--verify} option.
9903 @xref{compare}.
9904
9905 Note that these two options have a slightly different intent. The
9906 @option{--compare} option checks how identical are the logical contents of some
9907 archive with what is on your disks, while the @option{--verify} option is
9908 really for checking if the physical contents agree and if the recording
9909 media itself is of dependable quality. So, for the @option{--verify}
9910 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9911 the archive, while it lets the speed optimization undisturbed for the
9912 @option{--compare} option. If you nevertheless use @option{--compare} for
9913 media verification, you may have to defeat the in-memory cache yourself,
9914 maybe by opening and reclosing the door latch of your recording unit,
9915 forcing some doubt in your operating system about the fact this is really
9916 the same volume as the one just written or read.
9917
9918 The @option{--verify} option would not be necessary if drivers were indeed
9919 able to detect dependably all write failures. This sometimes require many
9920 magnetic heads, some able to read after the writes occurred. One would
9921 not say that drivers unable to detect all cases are necessarily flawed,
9922 as long as programming is concerned.
9923
9924 The @option{--verify} (@option{-W}) option will not work in
9925 conjunction with the @option{--multi-volume} (@option{-M}) option or
9926 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
9927 and @option{--delete} operations. @xref{Operations}, for more
9928 information on these operations.
9929
9930 Also, since @command{tar} normally strips leading @samp{/} from file
9931 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9932 /tmp/foo.tar /etc} will work as desired only if the working directory is
9933 @file{/}, as @command{tar} uses the archive's relative member names
9934 (e.g., @file{etc/motd}) when verifying the archive.
9935
9936 @node Write Protection
9937 @section Write Protection
9938
9939 Almost all tapes and diskettes, and in a few rare cases, even disks can
9940 be @dfn{write protected}, to protect data on them from being changed.
9941 Once an archive is written, you should write protect the media to prevent
9942 the archive from being accidentally overwritten or deleted. (This will
9943 protect the archive from being changed with a tape or floppy drive---it
9944 will not protect it from magnet fields or other physical hazards).
9945
9946 The write protection device itself is usually an integral part of the
9947 physical media, and can be a two position (write enabled/write
9948 disabled) switch, a notch which can be popped out or covered, a ring
9949 which can be removed from the center of a tape reel, or some other
9950 changeable feature.
9951
9952 @node Changes
9953 @appendix Changes
9954
9955 This appendix lists some important user-visible changes between
9956 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
9957 version of this document is available at
9958 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
9959 @GNUTAR{} documentation page}.
9960
9961 @table @asis
9962 @item Use of globbing patterns when listing and extracting.
9963
9964 Previous versions of GNU tar assumed shell-style globbing when
9965 extracting from or listing an archive. For example:
9966
9967 @smallexample
9968 $ @kbd{tar xf foo.tar '*.c'}
9969 @end smallexample
9970
9971 would extract all files whose names end in @samp{.c}. This behavior
9972 was not documented and was incompatible with traditional tar
9973 implementations. Therefore, starting from version 1.15.91, GNU tar
9974 no longer uses globbing by default. For example, the above invocation
9975 is now interpreted as a request to extract from the archive the file
9976 named @file{*.c}.
9977
9978 To facilitate transition to the new behavior for those users who got
9979 used to the previous incorrect one, @command{tar} will print a warning
9980 if it finds out that a requested member was not found in the archive
9981 and its name looks like a globbing pattern. For example:
9982
9983 @smallexample
9984 $ @kbd{tar xf foo.tar '*.c'}
9985 tar: Pattern matching characters used in file names. Please,
9986 tar: use --wildcards to enable pattern matching, or --no-wildcards to
9987 tar: suppress this warning.
9988 tar: *.c: Not found in archive
9989 tar: Error exit delayed from previous errors
9990 @end smallexample
9991
9992 To treat member names as globbing patterns, use --wildcards option.
9993 If you want to tar to mimic the behavior of versions prior to 1.15.91,
9994 add this option to your @env{TAR_OPTIONS} variable.
9995
9996 @xref{wildcards}, for the detailed discussion of the use of globbing
9997 patterns by @GNUTAR{}.
9998
9999 @item Use of short option @option{-o}.
10000
10001 Earlier versions of @GNUTAR{} understood @option{-o} command line
10002 option as a synonym for @option{--old-archive}.
10003
10004 @GNUTAR{} starting from version 1.13.90 understands this option as
10005 a synonym for @option{--no-same-owner}. This is compatible with
10006 UNIX98 @command{tar} implementations.
10007
10008 However, to facilitate transition, @option{-o} option retains its
10009 old semantics when it is used with one of archive-creation commands.
10010 Users are encouraged to use @option{--format=oldgnu} instead.
10011
10012 It is especially important, since versions of @acronym{GNU} Automake
10013 up to and including 1.8.4 invoke tar with this option to produce
10014 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10015 of this issue and its implications.
10016
10017 @FIXME{Change the first argument to tar-formats when the new Automake is
10018 out. The proposition to add @anchor{} to the appropriate place of its
10019 docs was accepted by Automake people --Sergey 2006-05-25}.
10020 @xref{Options, tar-v7, Changing Automake's Behavior,
10021 automake, GNU Automake}, for a description on how to use various
10022 archive formats with @command{automake}.
10023
10024 Future versions of @GNUTAR{} will understand @option{-o} only as a
10025 synonym for @option{--no-same-owner}.
10026
10027 @item Use of short option @option{-l}
10028
10029 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10030 synonym for @option{--one-file-system}. Since such usage contradicted
10031 to UNIX98 specification and harmed compatibility with other
10032 implementation, it was declared deprecated in version 1.14. However,
10033 to facilitate transition to its new semantics, it was supported by
10034 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10035 variant of @option{--check-links} was introduced in version 1.15.91.
10036
10037 @item Use of options @option{--portability} and @option{--old-archive}
10038
10039 These options are deprecated. Please use @option{--format=v7} instead.
10040
10041 @item Use of option @option{--posix}
10042
10043 This option is deprecated. Please use @option{--format=posix} instead.
10044 @end table
10045
10046 @node Configuring Help Summary
10047 @appendix Configuring Help Summary
10048
10049 Running @kbd{tar --help} displays the short @command{tar} option
10050 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10051 semantically close options. The options within each group are printed
10052 in the following order: a short option, eventually followed by a list
10053 of corresponding long option names, followed by a short description of
10054 the option. For example, here is an excerpt from the actual @kbd{tar
10055 --help} output:
10056
10057 @verbatim
10058 Main operation mode:
10059
10060 -A, --catenate, --concatenate append tar files to an archive
10061 -c, --create create a new archive
10062 -d, --diff, --compare find differences between archive and
10063 file system
10064 --delete delete from the archive
10065 @end verbatim
10066
10067 @vrindex ARGP_HELP_FMT, environment variable
10068 The exact visual representation of the help output is configurable via
10069 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10070 is a comma-separated list of @dfn{format variable} assignments. There
10071 are two kinds of format variables. An @dfn{offset variable} keeps the
10072 offset of some part of help output text from the leftmost column on
10073 the screen. A @dfn{boolean} variable is a flag that toggles some
10074 output feature on or off. Depending on the type of the corresponding
10075 variable, there are two kinds of assignments:
10076
10077 @table @asis
10078 @item Offset assignment
10079
10080 The assignment to an offset variable has the following syntax:
10081
10082 @smallexample
10083 @var{variable}=@var{value}
10084 @end smallexample
10085
10086 @noindent
10087 where @var{variable} is the variable name, and @var{value} is a
10088 numeric value to be assigned to the variable.
10089
10090 @item Boolean assignment
10091
10092 To assign @code{true} value to a variable, simply put this variable name. To
10093 assign @code{false} value, prefix the variable name with @samp{no-}. For
10094 example:
10095
10096 @smallexample
10097 @group
10098 # Assign @code{true} value:
10099 dup-args
10100 # Assign @code{false} value:
10101 no-dup-args
10102 @end group
10103 @end smallexample
10104 @end table
10105
10106 Following variables are declared:
10107
10108 @deftypevr {Help Output} boolean dup-args
10109 If true, arguments for an option are shown with both short and long
10110 options, even when a given option has both forms, for example:
10111
10112 @smallexample
10113 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10114 @end smallexample
10115
10116 If false, then if an option has both short and long forms, the
10117 argument is only shown with the long one, for example:
10118
10119 @smallexample
10120 -f, --file=ARCHIVE use archive file or device ARCHIVE
10121 @end smallexample
10122
10123 @noindent
10124 and a message indicating that the argument is applicable to both
10125 forms is printed below the options. This message can be disabled
10126 using @code{dup-args-note} (see below).
10127
10128 The default is false.
10129 @end deftypevr
10130
10131 @deftypevr {Help Output} boolean dup-args-note
10132 If this variable is true, which is the default, the following notice
10133 is displayed at the end of the help output:
10134
10135 @quotation
10136 Mandatory or optional arguments to long options are also mandatory or
10137 optional for any corresponding short options.
10138 @end quotation
10139
10140 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10141 variables @code{dup-args} or @code{dup-args-note} should be set.
10142 @end deftypevr
10143
10144 @deftypevr {Help Output} offset short-opt-col
10145 Column in which short options start. Default is 2.
10146
10147 @smallexample
10148 @group
10149 $ @kbd{tar --help|grep ARCHIVE}
10150 -f, --file=ARCHIVE use archive file or device ARCHIVE
10151 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10152 -f, --file=ARCHIVE use archive file or device ARCHIVE
10153 @end group
10154 @end smallexample
10155 @end deftypevr
10156
10157 @deftypevr {Help Output} offset long-opt-col
10158 Column in which long options start. Default is 6. For example:
10159
10160 @smallexample
10161 @group
10162 $ @kbd{tar --help|grep ARCHIVE}
10163 -f, --file=ARCHIVE use archive file or device ARCHIVE
10164 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10165 -f, --file=ARCHIVE use archive file or device ARCHIVE
10166 @end group
10167 @end smallexample
10168 @end deftypevr
10169
10170 @deftypevr {Help Output} offset doc-opt-col
10171 Column in which @dfn{doc options} start. A doc option isn't actually
10172 an option, but rather an arbitrary piece of documentation that is
10173 displayed in much the same manner as the options. For example, in
10174 the description of @option{--format} option:
10175
10176 @smallexample
10177 @group
10178 -H, --format=FORMAT create archive of the given format.
10179
10180 FORMAT is one of the following:
10181
10182 gnu GNU tar 1.13.x format
10183 oldgnu GNU format as per tar <= 1.12
10184 pax POSIX 1003.1-2001 (pax) format
10185 posix same as pax
10186 ustar POSIX 1003.1-1988 (ustar) format
10187 v7 old V7 tar format
10188 @end group
10189 @end smallexample
10190
10191 @noindent
10192 the format names are doc options. Thus, if you set
10193 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10194 will look as follows:
10195
10196 @smallexample
10197 @group
10198 -H, --format=FORMAT create archive of the given format.
10199
10200 FORMAT is one of the following:
10201
10202 gnu GNU tar 1.13.x format
10203 oldgnu GNU format as per tar <= 1.12
10204 pax POSIX 1003.1-2001 (pax) format
10205 posix same as pax
10206 ustar POSIX 1003.1-1988 (ustar) format
10207 v7 old V7 tar format
10208 @end group
10209 @end smallexample
10210 @end deftypevr
10211
10212 @deftypevr {Help Output} offset opt-doc-col
10213 Column in which option description starts. Default is 29.
10214
10215 @smallexample
10216 @group
10217 $ @kbd{tar --help|grep ARCHIVE}
10218 -f, --file=ARCHIVE use archive file or device ARCHIVE
10219 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10220 -f, --file=ARCHIVE use archive file or device ARCHIVE
10221 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10222 -f, --file=ARCHIVE
10223 use archive file or device ARCHIVE
10224 @end group
10225 @end smallexample
10226
10227 @noindent
10228 Notice, that the description starts on a separate line if
10229 @code{opt-doc-col} value is too small.
10230 @end deftypevr
10231
10232 @deftypevr {Help Output} offset header-col
10233 Column in which @dfn{group headers} are printed. A group header is a
10234 descriptive text preceding an option group. For example, in the
10235 following text:
10236
10237 @verbatim
10238 Main operation mode:
10239
10240 -A, --catenate, --concatenate append tar files to
10241 an archive
10242 -c, --create create a new archive
10243 @end verbatim
10244 @noindent
10245 @samp{Main operation mode:} is the group header.
10246
10247 The default value is 1.
10248 @end deftypevr
10249
10250 @deftypevr {Help Output} offset usage-indent
10251 Indentation of wrapped usage lines. Affects @option{--usage}
10252 output. Default is 12.
10253 @end deftypevr
10254
10255 @deftypevr {Help Output} offset rmargin
10256 Right margin of the text output. Used for wrapping.
10257 @end deftypevr
10258
10259 @node Genfile
10260 @appendix Genfile
10261 @include genfile.texi
10262
10263 @node Tar Internals
10264 @appendix Tar Internals
10265 @include intern.texi
10266
10267 @node Free Software Needs Free Documentation
10268 @appendix Free Software Needs Free Documentation
10269 @include freemanuals.texi
10270
10271 @node Copying This Manual
10272 @appendix Copying This Manual
10273
10274 @menu
10275 * GNU Free Documentation License:: License for copying this manual
10276 @end menu
10277
10278 @include fdl.texi
10279
10280 @node Index of Command Line Options
10281 @appendix Index of Command Line Options
10282
10283 This appendix contains an index of all @GNUTAR{} long command line
10284 options. The options are listed without the preceeding double-dash.
10285
10286 @FIXME{@itemize
10287 @item Make sure @emph{all} options are indexed.
10288 @item Provide an index of short options
10289 @end itemize}
10290
10291 @printindex op
10292
10293 @node Index
10294 @appendix Index
10295
10296 @printindex cp
10297
10298 @summarycontents
10299 @contents
10300 @bye
10301
10302 @c Local variables:
10303 @c texinfo-column-for-description: 32
10304 @c End:
This page took 0.449735 seconds and 5 git commands to generate.