]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Updated
[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, created with texinfo-master-menu, goes here.
83 @c (However, getdate.texi's menu is interpolated by hand.)
84
85 @menu
86 * Introduction::
87 * Tutorial::
88 * tar invocation::
89 * operations::
90 * Backups::
91 * Choosing::
92 * Date input formats::
93 * Formats::
94 * Media::
95
96 Appendices
97
98 * Changes::
99 * Configuring Help Summary::
100 * Genfile::
101 * Snapshot Files::
102 * Free Software Needs Free Documentation::
103 * Copying This Manual::
104 * Index of Command Line Options::
105 * Index::
106
107 @detailmenu
108 --- The Detailed Node Listing ---
109
110 Introduction
111
112 * Book Contents:: What this Book Contains
113 * Definitions:: Some Definitions
114 * What tar Does:: What @command{tar} Does
115 * Naming tar Archives:: How @command{tar} Archives are Named
116 * Authors:: @GNUTAR{} Authors
117 * Reports:: Reporting bugs or suggestions
118
119 Tutorial Introduction to @command{tar}
120
121 * assumptions::
122 * stylistic conventions::
123 * basic tar options:: Basic @command{tar} Operations and Options
124 * frequent operations::
125 * Two Frequent Options::
126 * create:: How to Create Archives
127 * list:: How to List Archives
128 * extract:: How to Extract Members from an Archive
129 * going further::
130
131 Two Frequently Used Options
132
133 * file tutorial::
134 * verbose tutorial::
135 * help tutorial::
136
137 How to Create Archives
138
139 * prepare for examples::
140 * Creating the archive::
141 * create verbose::
142 * short create::
143 * create dir::
144
145 How to List Archives
146
147 * list dir::
148
149 How to Extract Members from an Archive
150
151 * extracting archives::
152 * extracting files::
153 * extract dir::
154 * failing commands::
155
156 Invoking @GNUTAR{}
157
158 * Synopsis::
159 * using tar options::
160 * Styles::
161 * All Options::
162 * help::
163 * defaults::
164 * verbose::
165 * interactive::
166
167 The Three Option Styles
168
169 * Mnemonic Options:: Mnemonic Option Style
170 * Short Options:: Short Option Style
171 * Old Options:: Old Option Style
172 * Mixing:: Mixing Option Styles
173
174 All @command{tar} Options
175
176 * Operation Summary::
177 * Option Summary::
178 * Short Option Summary::
179
180 @GNUTAR{} Operations
181
182 * Basic tar::
183 * Advanced tar::
184 * create options::
185 * extract options::
186 * backup::
187 * Applications::
188 * looking ahead::
189
190 Advanced @GNUTAR{} Operations
191
192 * Operations::
193 * append::
194 * update::
195 * concatenate::
196 * delete::
197 * compare::
198
199 How to Add Files to Existing Archives: @option{--append}
200
201 * appending files:: Appending Files to an Archive
202 * multiple::
203
204 Updating an Archive
205
206 * how to update::
207
208 Options Used by @option{--create}
209
210 * Ignore Failed Read::
211
212 Options Used by @option{--extract}
213
214 * Reading:: Options to Help Read Archives
215 * Writing:: Changing How @command{tar} Writes Files
216 * Scarce:: Coping with Scarce Resources
217
218 Options to Help Read Archives
219
220 * read full records::
221 * Ignore Zeros::
222
223 Changing How @command{tar} Writes Files
224
225 * Dealing with Old Files::
226 * Overwrite Old Files::
227 * Keep Old Files::
228 * Keep Newer Files::
229 * Unlink First::
230 * Recursive Unlink::
231 * Data Modification Times::
232 * Setting Access Permissions::
233 * Writing to Standard Output::
234 * remove files::
235
236 Coping with Scarce Resources
237
238 * Starting File::
239 * Same Order::
240
241 Performing Backups and Restoring Files
242
243 * Full Dumps:: Using @command{tar} to Perform Full Dumps
244 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
245 * Backup Levels:: Levels of Backups
246 * Backup Parameters:: Setting Parameters for Backups and Restoration
247 * Scripted Backups:: Using the Backup Scripts
248 * Scripted Restoration:: Using the Restore Script
249
250 Setting Parameters for Backups and Restoration
251
252 * General-Purpose Variables::
253 * Magnetic Tape Control::
254 * User Hooks::
255 * backup-specs example:: An Example Text of @file{Backup-specs}
256
257 Choosing Files and Names for @command{tar}
258
259 * file:: Choosing the Archive's Name
260 * Selecting Archive Members::
261 * files:: Reading Names from a File
262 * exclude:: Excluding Some Files
263 * Wildcards:: Wildcards Patterns and Matching
264 * after:: Operating Only on New Files
265 * recurse:: Descending into Directories
266 * one:: Crossing File System Boundaries
267
268 Reading Names from a File
269
270 * nul::
271
272 Excluding Some Files
273
274 * problems with exclude::
275
276 Crossing File System Boundaries
277
278 * directory:: Changing Directory
279 * absolute:: Absolute File Names
280
281 Date input formats
282
283 * General date syntax:: Common rules.
284 * Calendar date items:: 19 Dec 1994.
285 * Time of day items:: 9:20pm.
286 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}, ...
287 * Day of week items:: Monday and others.
288 * Relative items in date strings:: next tuesday, 2 years ago.
289 * Pure numbers in date strings:: 19931219, 1440.
290 * Seconds since the Epoch:: @@1078100502.
291 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
292
293 Controlling the Archive Format
294
295 * Portability:: Making @command{tar} Archives More Portable
296 * Compression:: Using Less Space through Compression
297 * Attributes:: Handling File Attributes
298 * Standard:: The Standard Format
299 * Extensions:: @acronym{GNU} Extensions to the Archive Format
300 * cpio:: Comparison of @command{tar} and @command{cpio}
301
302 Making @command{tar} Archives More Portable
303
304 * Portable Names:: Portable Names
305 * dereference:: Symbolic Links
306 * old:: Old V7 Archives
307 * posix:: @acronym{POSIX} archives
308 * Checksumming:: Checksumming Problems
309 * Large or Negative Values:: Large files, negative time stamps, etc.
310
311 Using Less Space through Compression
312
313 * gzip:: Creating and Reading Compressed Archives
314 * sparse:: Archiving Sparse Files
315
316 Tapes and Other Archive Media
317
318 * Device:: Device selection and switching
319 * Remote Tape Server::
320 * Common Problems and Solutions::
321 * Blocking:: Blocking
322 * Many:: Many archives on one tape
323 * Using Multiple Tapes:: Using Multiple Tapes
324 * label:: Including a Label in the Archive
325 * verify::
326 * Write Protection::
327
328 Blocking
329
330 * Format Variations:: Format Variations
331 * Blocking Factor:: The Blocking Factor of an Archive
332
333 Many Archives on One Tape
334
335 * Tape Positioning:: Tape Positions and Tape Marks
336 * mt:: The @command{mt} Utility
337
338 Using Multiple Tapes
339
340 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
341 * Tape Files:: Tape Files
342 * Tarcat:: Concatenate Volumes into a Single Archive
343
344 GNU tar internals and development
345
346 * Genfile::
347 * Snapshot Files::
348
349 Copying This Manual
350
351 * Free Software Needs Free Documentation::
352 * GNU Free Documentation License:: License for copying this manual
353
354 @end detailmenu
355 @end menu
356
357 @node Introduction
358 @chapter Introduction
359
360 @GNUTAR{} creates
361 and manipulates @dfn{archives} which are actually collections of
362 many other files; the program provides users with an organized and
363 systematic method for controlling a large amount of data.
364 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
365 archives need not (and these days, typically do not) reside on tapes.
366
367 @menu
368 * Book Contents:: What this Book Contains
369 * Definitions:: Some Definitions
370 * What tar Does:: What @command{tar} Does
371 * Naming tar Archives:: How @command{tar} Archives are Named
372 * Authors:: @GNUTAR{} Authors
373 * Reports:: Reporting bugs or suggestions
374 @end menu
375
376 @node Book Contents
377 @section What this Book Contains
378
379 The first part of this chapter introduces you to various terms that will
380 recur throughout the book. It also tells you who has worked on @GNUTAR{}
381 and its documentation, and where you should send bug reports
382 or comments.
383
384 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
385 gentle introduction for people who are new to using @command{tar}. It is
386 meant to be self contained, not requiring any reading from subsequent
387 chapters to make sense. It moves from topic to topic in a logical,
388 progressive order, building on information already explained.
389
390 Although the tutorial is paced and structured to allow beginners to
391 learn how to use @command{tar}, it is not intended solely for beginners.
392 The tutorial explains how to use the three most frequently used
393 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
394 two frequently used options (@samp{file} and @samp{verbose}). The other
395 chapters do not refer to the tutorial frequently; however, if a section
396 discusses something which is a complex variant of a basic concept, there
397 may be a cross reference to that basic concept. (The entire book,
398 including the tutorial, assumes that the reader understands some basic
399 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
400
401 The third chapter presents the remaining five operations, and
402 information about using @command{tar} options and option syntax.
403
404 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
405 than the reality. should think about whether this makes sense to say
406 here, or not.} The other chapters are meant to be used as a
407 reference. Each chapter presents everything that needs to be said
408 about a specific topic.
409
410 One of the chapters (@pxref{Date input formats}) exists in its
411 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
412 In addition, one section of this manual (@pxref{Standard}) contains a
413 big quote which is taken directly from @command{tar} sources.
414
415 In general, we give both long and short (abbreviated) option names
416 at least once in each section where the relevant option is covered, so
417 that novice readers will become familiar with both styles. (A few
418 options have no short versions, and the relevant sections will
419 indicate this.)
420
421 @node Definitions
422 @section Some Definitions
423
424 @cindex archive
425 @cindex tar archive
426 The @command{tar} program is used to create and manipulate @command{tar}
427 archives. An @dfn{archive} is a single file which contains the contents
428 of many files, while still identifying the names of the files, their
429 owner(s), and so forth. (In addition, archives record access
430 permissions, user and group, size in bytes, and data modification time.
431 Some archives also record the file names in each archived directory, as
432 well as other file and directory information.) You can use @command{tar}
433 to @dfn{create} a new archive in a specified directory.
434
435 @cindex member
436 @cindex archive member
437 @cindex file name
438 @cindex member name
439 The files inside an archive are called @dfn{members}. Within this
440 manual, we use the term @dfn{file} to refer only to files accessible in
441 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
442 @dfn{member} to refer only to the members of an archive. Similarly, a
443 @dfn{file name} is the name of a file, as it resides in the file system,
444 and a @dfn{member name} is the name of an archive member within the
445 archive.
446
447 @cindex extraction
448 @cindex unpacking
449 The term @dfn{extraction} refers to the process of copying an archive
450 member (or multiple members) into a file in the file system. Extracting
451 all the members of an archive is often called @dfn{extracting the
452 archive}. The term @dfn{unpack} can also be used to refer to the
453 extraction of many or all the members of an archive. Extracting an
454 archive does not destroy the archive's structure, just as creating an
455 archive does not destroy the copies of the files that exist outside of
456 the archive. You may also @dfn{list} the members in a given archive
457 (this is often thought of as ``printing'' them to the standard output,
458 or the command line), or @dfn{append} members to a pre-existing archive.
459 All of these operations can be performed using @command{tar}.
460
461 @node What tar Does
462 @section What @command{tar} Does
463
464 @cindex tar
465 The @command{tar} program provides the ability to create @command{tar}
466 archives, as well as various other kinds of manipulation. For example,
467 you can use @command{tar} on previously created archives to extract files,
468 to store additional files, or to update or list files which were already
469 stored.
470
471 Initially, @command{tar} archives were used to store files conveniently on
472 magnetic tape. The name @command{tar} comes from this use; it stands for
473 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
474 direct its output to available devices, files, or other programs (using
475 pipes). @command{tar} may even access remote devices or files (as archives).
476
477 You can use @command{tar} archives in many ways. We want to stress a few
478 of them: storage, backup, and transportation.
479
480 @FIXME{the following table entries need a bit of work..}
481 @table @asis
482 @item Storage
483 Often, @command{tar} archives are used to store related files for
484 convenient file transfer over a network. For example, the
485 @acronym{GNU} Project distributes its software bundled into
486 @command{tar} archives, so that all the files relating to a particular
487 program (or set of related programs) can be transferred as a single
488 unit.
489
490 A magnetic tape can store several files in sequence. However, the tape
491 has no names for these files; it only knows their relative position on
492 the tape. One way to store several files on one tape and retain their
493 names is by creating a @command{tar} archive. Even when the basic transfer
494 mechanism can keep track of names, as FTP can, the nuisance of handling
495 multiple files, directories, and multiple links makes @command{tar}
496 archives useful.
497
498 Archive files are also used for long-term storage. You can think of
499 this as transportation from the present into the future. (It is a
500 science-fiction idiom that you can move through time as well as in
501 space; the idea here is that @command{tar} can be used to move archives in
502 all dimensions, even time!)
503
504 @item Backup
505 Because the archive created by @command{tar} is capable of preserving
506 file information and directory structure, @command{tar} is commonly
507 used for performing full and incremental backups of disks. A backup
508 puts a collection of files (possibly pertaining to many users and
509 projects) together on a disk or a tape. This guards against
510 accidental destruction of the information in those files.
511 @GNUTAR{} has special features that allow it to be
512 used to make incremental and full dumps of all the files in a
513 file system.
514
515 @item Transportation
516 You can create an archive on one system, transfer it to another system,
517 and extract the contents there. This allows you to transport a group of
518 files from one system to another.
519 @end table
520
521 @node Naming tar Archives
522 @section How @command{tar} Archives are Named
523
524 Conventionally, @command{tar} archives are given names ending with
525 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
526 but this manual follows that convention in order to accustom readers to
527 it and to make examples more clear.
528
529 @cindex tar file
530 @cindex entry
531 @cindex tar entry
532 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
533 archive members as ``files'' or ``entries''. For people familiar with
534 the operation of @command{tar}, this causes no difficulty. However, in
535 this manual, we consistently refer to ``archives'' and ``archive
536 members'' to make learning to use @command{tar} easier for novice users.
537
538 @node Authors
539 @section @GNUTAR{} Authors
540
541 @GNUTAR{} was originally written by John Gilmore,
542 and modified by many people. The @acronym{GNU} enhancements were
543 written by Jay Fenlason, then Joy Kendall, and the whole package has
544 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
545 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
546 numerous and kind users.
547
548 We wish to stress that @command{tar} is a collective work, and owes much to
549 all those people who reported problems, offered solutions and other
550 insights, or shared their thoughts and suggestions. An impressive, yet
551 partial list of those contributors can be found in the @file{THANKS}
552 file from the @GNUTAR{} distribution.
553
554 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
555 sure i want to spell out the history in this detail, at least not for
556 the printed book. i'm just not sure it needs to be said this way.
557 i'll think about it.}
558
559 @FIXME{History is more important, and surely more interesting, than
560 actual names. Quoting names without history would be meaningless. FP}
561
562 Jay Fenlason put together a draft of a @GNUTAR{}
563 manual, borrowing notes from the original man page from John Gilmore.
564 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
565 Gorin worked on a tutorial and manual for @GNUTAR{}.
566 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
567 taking information from all these sources and merging them. Melissa
568 Weisshaus finally edited and redesigned the book to create version
569 1.12. @FIXME{update version number as necessary; i'm being
570 optimistic!} @FIXME{Someone [maybe karl berry? maybe bob chassell?
571 maybe melissa? maybe julie sussman?] needs to properly index the
572 thing.}
573
574 For version 1.12, Daniel Hagerty contributed a great deal of technical
575 consulting. In particular, he is the primary author of @ref{Backups}.
576
577 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
578 (see @url{http://savannah.gnu.org/projects/tar}), and
579 active development and maintenance work has started
580 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
581 Poznyakoff and Jeff Bailey.
582
583 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
584
585 @node Reports
586 @section Reporting bugs or suggestions
587
588 @cindex bug reports
589 @cindex reporting bugs
590 If you find problems or have suggestions about this program or manual,
591 please report them to @file{bug-tar@@gnu.org}.
592
593 When reporting a bug, please be sure to include as much detail as
594 possible, in order to reproduce it. @FIXME{Be more specific, I'd
595 like to make this node as detailed as 'Bug reporting' node in Emacs
596 manual}.
597
598 @node Tutorial
599 @chapter Tutorial Introduction to @command{tar}
600
601 This chapter guides you through some basic examples of three @command{tar}
602 operations: @option{--create}, @option{--list}, and @option{--extract}. If
603 you already know how to use some other version of @command{tar}, then you
604 may not need to read this chapter. This chapter omits most complicated
605 details about how @command{tar} works.
606
607 @menu
608 * assumptions::
609 * stylistic conventions::
610 * basic tar options:: Basic @command{tar} Operations and Options
611 * frequent operations::
612 * Two Frequent Options::
613 * create:: How to Create Archives
614 * list:: How to List Archives
615 * extract:: How to Extract Members from an Archive
616 * going further::
617 @end menu
618
619 @node assumptions
620 @section Assumptions this Tutorial Makes
621
622 This chapter is paced to allow beginners to learn about @command{tar}
623 slowly. At the same time, we will try to cover all the basic aspects of
624 these three operations. In order to accomplish both of these tasks, we
625 have made certain assumptions about your knowledge before reading this
626 manual, and the hardware you will be using:
627
628 @itemize @bullet
629 @item
630 Before you start to work through this tutorial, you should understand
631 what the terms ``archive'' and ``archive member'' mean
632 (@pxref{Definitions}). In addition, you should understand something
633 about how Unix-type operating systems work, and you should know how to
634 use some basic utilities. For example, you should know how to create,
635 list, copy, rename, edit, and delete files and directories; how to
636 change between directories; and how to figure out where you are in the
637 file system. You should have some basic understanding of directory
638 structure and how files are named according to which directory they are
639 in. You should understand concepts such as standard output and standard
640 input, what various definitions of the term ``argument'' mean, and the
641 differences between relative and absolute path names. @FIXME{and what
642 else?}
643
644 @item
645 This manual assumes that you are working from your own home directory
646 (unless we state otherwise). In this tutorial, you will create a
647 directory to practice @command{tar} commands in. When we show path names,
648 we will assume that those paths are relative to your home directory.
649 For example, my home directory path is @file{/home/fsf/melissa}. All of
650 my examples are in a subdirectory of the directory named by that path
651 name; the subdirectory is called @file{practice}.
652
653 @item
654 In general, we show examples of archives which exist on (or can be
655 written to, or worked with from) a directory on a hard disk. In most
656 cases, you could write those archives to, or work with them on any other
657 device, such as a tape drive. However, some of the later examples in
658 the tutorial and next chapter will not work on tape drives.
659 Additionally, working with tapes is much more complicated than working
660 with hard disks. For these reasons, the tutorial does not cover working
661 with tape drives. @xref{Media}, for complete information on using
662 @command{tar} archives with tape drives.
663
664 @FIXME{this is a cop out. need to add some simple tape drive info.}
665 @end itemize
666
667 @node stylistic conventions
668 @section Stylistic Conventions
669
670 In the examples, @samp{$} represents a typical shell prompt. It
671 precedes lines you should type; to make this more clear, those lines are
672 shown in @kbd{this font}, as opposed to lines which represent the
673 computer's response; those lines are shown in @code{this font}, or
674 sometimes @samp{like this}.
675
676 @c When we have lines which are too long to be
677 @c displayed in any other way, we will show them like this:
678
679 @node basic tar options
680 @section Basic @command{tar} Operations and Options
681
682 @command{tar} can take a wide variety of arguments which specify and define
683 the actions it will have on the particular set of files or the archive.
684 The main types of arguments to @command{tar} fall into one of two classes:
685 operations, and options.
686
687 Some arguments fall into a class called @dfn{operations}; exactly one of
688 these is both allowed and required for any instance of using @command{tar};
689 you may @emph{not} specify more than one. People sometimes speak of
690 @dfn{operating modes}. You are in a particular operating mode when you
691 have specified the operation which specifies it; there are eight
692 operations in total, and thus there are eight operating modes.
693
694 The other arguments fall into the class known as @dfn{options}. You are
695 not required to specify any options, and you are allowed to specify more
696 than one at a time (depending on the way you are using @command{tar} at
697 that time). Some options are used so frequently, and are so useful for
698 helping you type commands more carefully that they are effectively
699 ``required''. We will discuss them in this chapter.
700
701 You can write most of the @command{tar} operations and options in any
702 of three forms: long (mnemonic) form, short form, and old style. Some
703 of the operations and options have no short or ``old'' forms; however,
704 the operations and options which we will cover in this tutorial have
705 corresponding abbreviations. @FIXME{make sure this is still the case,
706 at the end}We will indicate those abbreviations appropriately to get
707 you used to seeing them. (Note that the ``old style'' option forms
708 exist in @GNUTAR{} for compatibility with Unix
709 @command{tar}. In this book we present a full discussion of this way
710 of writing options and operations (@pxref{Old Options}), and we discuss
711 the other two styles of writing options (@xref{Mnemonic Options}, and
712 @pxref{Short Options}).
713
714 In the examples and in the text of this tutorial, we usually use the
715 long forms of operations and options; but the ``short'' forms produce
716 the same result and can make typing long @command{tar} commands easier.
717 For example, instead of typing
718
719 @smallexample
720 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
721 @end smallexample
722
723 @noindent
724 you can type
725 @smallexample
726 @kbd{tar -c -v -f afiles.tar apple angst aspic}
727 @end smallexample
728
729 @noindent
730 or even
731 @smallexample
732 @kbd{tar -cvf afiles.tar apple angst aspic}
733 @end smallexample
734
735 @noindent
736 For more information on option syntax, see @ref{Advanced tar}. In
737 discussions in the text, when we name an option by its long form, we
738 also give the corresponding short option in parentheses.
739
740 The term, ``option'', can be confusing at times, since ``operations''
741 are often lumped in with the actual, @emph{optional} ``options'' in certain
742 general class statements. For example, we just talked about ``short and
743 long forms of options and operations''. However, experienced @command{tar}
744 users often refer to these by shorthand terms such as, ``short and long
745 options''. This term assumes that the ``operations'' are included, also.
746 Context will help you determine which definition of ``options'' to use.
747
748 Similarly, the term ``command'' can be confusing, as it is often used in
749 two different ways. People sometimes refer to @command{tar} ``commands''.
750 A @command{tar} @dfn{command} is the entire command line of user input
751 which tells @command{tar} what to do --- including the operation, options,
752 and any arguments (file names, pipes, other commands, etc). However,
753 you will also sometimes hear the term ``the @command{tar} command''. When
754 the word ``command'' is used specifically like this, a person is usually
755 referring to the @command{tar} @emph{operation}, not the whole line.
756 Again, use context to figure out which of the meanings the speaker
757 intends.
758
759 @node frequent operations
760 @section The Three Most Frequently Used Operations
761
762 Here are the three most frequently used operations (both short and long
763 forms), as well as a brief description of their meanings. The rest of
764 this chapter will cover how to use these operations in detail. We will
765 present the rest of the operations in the next chapter.
766
767 @table @option
768 @item --create
769 @itemx -c
770 Create a new @command{tar} archive.
771 @item --list
772 @itemx -t
773 List the contents of an archive.
774 @item --extract
775 @itemx -x
776 Extract one or more members from an archive.
777 @end table
778
779 @node Two Frequent Options
780 @section Two Frequently Used Options
781
782 To understand how to run @command{tar} in the three operating modes listed
783 previously, you also need to understand how to use two of the options to
784 @command{tar}: @option{--file} (which takes an archive file as an argument)
785 and @option{--verbose}. (You are usually not @emph{required} to specify
786 either of these options when you run @command{tar}, but they can be very
787 useful in making things more clear and helping you avoid errors.)
788
789 @menu
790 * file tutorial::
791 * verbose tutorial::
792 * help tutorial::
793 @end menu
794
795 @node file tutorial
796 @unnumberedsubsec The @option{--file} Option
797
798 @table @option
799 @opindex file, tutorial
800 @item --file=@var{archive-name}
801 @itemx -f @var{archive-name}
802 Specify the name of an archive file.
803 @end table
804
805 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
806 use @command{tar}; this option determines the name of the archive file
807 that @command{tar} will work on.
808
809 @vrindex TAPE
810 If you don't specify this argument, then @command{tar} will examine
811 the environment variable @env{TAPE}. If it is set, its value will be
812 used as the archive name. Otherwise, @command{tar} will use the
813 default archive, determined at the compile time. Usually it is
814 standard output or some physical tape drive attached to your machine
815 (you can verify what the default is by running @kbd{tar
816 --show-defaults}, @pxref{defaults}). If there is no tape drive
817 attached, or the default is not meaningful, then @command{tar} will
818 print an error message. The error message might look roughly like one
819 of the following:
820
821 @smallexample
822 tar: can't open /dev/rmt8 : No such device or address
823 tar: can't open /dev/rsmt0 : I/O error
824 @end smallexample
825
826 @noindent
827 To avoid confusion, we recommend that you always specify an archive file
828 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
829 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
830 @ref{file}.
831
832 @node verbose tutorial
833 @unnumberedsubsec The @option{--verbose} Option
834
835 @table @option
836 @opindex verbose, introduced
837 @item --verbose
838 @itemx -v
839 Show the files being worked on as @command{tar} is running.
840 @end table
841
842 @option{--verbose} (@option{-v}) shows details about the results of running
843 @command{tar}. This can be especially useful when the results might not be
844 obvious. For example, if you want to see the progress of @command{tar} as
845 it writes files into the archive, you can use the @option{--verbose}
846 option. In the beginning, you may find it useful to use
847 @option{--verbose} at all times; when you are more accustomed to
848 @command{tar}, you will likely want to use it at certain times but not at
849 others. We will use @option{--verbose} at times to help make something
850 clear, and we will give many examples both using and not using
851 @option{--verbose} to show the differences.
852
853 Sometimes, a single instance of @option{--verbose} on the command line
854 will show a full, @samp{ls} style listing of an archive or files,
855 giving sizes, owners, and similar information. @FIXME{Describe the
856 exact output format, e.g., how hard links are displayed.}
857 Other times, @option{--verbose} will only show files or members that the particular
858 operation is operating on at the time. In the latter case, you can
859 use @option{--verbose} twice in a command to get a listing such as that
860 in the former case. For example, instead of saying
861
862 @smallexample
863 @kbd{tar -cvf afiles.tar apple angst aspic}
864 @end smallexample
865
866 @noindent
867 above, you might say
868
869 @smallexample
870 @kbd{tar -cvvf afiles.tar apple angst aspic}
871 @end smallexample
872
873 @noindent
874 This works equally well using short or long forms of options. Using
875 long forms, you would simply write out the mnemonic form of the option
876 twice, like this:
877
878 @smallexample
879 $ @kbd{tar --create --verbose --verbose @dots{}}
880 @end smallexample
881
882 @noindent
883 Note that you must double the hyphens properly each time.
884
885 Later in the tutorial, we will give examples using @w{@option{--verbose
886 --verbose}}.
887
888 @node help tutorial
889 @unnumberedsubsec Getting Help: Using the @option{--help} Option
890
891 @table @option
892 @opindex help
893 @item --help
894
895 The @option{--help} option to @command{tar} prints out a very brief list of
896 all operations and option available for the current version of
897 @command{tar} available on your system.
898 @end table
899
900 @node create
901 @section How to Create Archives
902 @UNREVISED
903
904 @cindex Creation of the archive
905 @cindex Archive, creation of
906 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
907 you use to create a @command{tar} archive. We will explain
908 @option{--create} first because, in order to learn about the other
909 operations, you will find it useful to have an archive available to
910 practice on.
911
912 To make this easier, in this section you will first create a directory
913 containing three files. Then, we will show you how to create an
914 @emph{archive} (inside the new directory). Both the directory, and
915 the archive are specifically for you to practice on. The rest of this
916 chapter and the next chapter will show many examples using this
917 directory and the files you will create: some of those files may be
918 other directories and other archives.
919
920 The three files you will archive in this example are called
921 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
922 @file{collection.tar}.
923
924 This section will proceed slowly, detailing how to use @option{--create}
925 in @code{verbose} mode, and showing examples using both short and long
926 forms. In the rest of the tutorial, and in the examples in the next
927 chapter, we will proceed at a slightly quicker pace. This section
928 moves more slowly to allow beginning users to understand how
929 @command{tar} works.
930
931 @menu
932 * prepare for examples::
933 * Creating the archive::
934 * create verbose::
935 * short create::
936 * create dir::
937 @end menu
938
939 @node prepare for examples
940 @subsection Preparing a Practice Directory for Examples
941
942 To follow along with this and future examples, create a new directory
943 called @file{practice} containing files called @file{blues}, @file{folk}
944 and @file{jazz}. The files can contain any information you like:
945 ideally, they should contain information which relates to their names,
946 and be of different lengths. Our examples assume that @file{practice}
947 is a subdirectory of your home directory.
948
949 Now @command{cd} to the directory named @file{practice}; @file{practice}
950 is now your @dfn{working directory}. (@emph{Please note}: Although
951 the full path name of this directory is
952 @file{/@var{homedir}/practice}, in our examples we will refer to
953 this directory as @file{practice}; the @var{homedir} is presumed.
954
955 In general, you should check that the files to be archived exist where
956 you think they do (in the working directory) by running @command{ls}.
957 Because you just created the directory and the files and have changed to
958 that directory, you probably don't need to do that this time.
959
960 It is very important to make sure there isn't already a file in the
961 working directory with the archive name you intend to use (in this case,
962 @samp{collection.tar}), or that you don't care about its contents.
963 Whenever you use @samp{create}, @command{tar} will erase the current
964 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
965 will not tell you if you are about to overwrite an archive unless you
966 specify an option which does this (@pxref{backup}, for the
967 information on how to do so). To add files to an existing archive,
968 you need to use a different option, such as @option{--append} (@option{-r}); see
969 @ref{append} for information on how to do this.
970
971 @node Creating the archive
972 @subsection Creating the Archive
973
974 @opindex create, introduced
975 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
976 archive named @file{collection.tar}, use the following command:
977
978 @smallexample
979 $ @kbd{tar --create --file=collection.tar blues folk jazz}
980 @end smallexample
981
982 The order of the arguments is not very important, @emph{when using long
983 option forms}. You could also say:
984
985 @smallexample
986 $ @kbd{tar blues --create folk --file=collection.tar jazz}
987 @end smallexample
988
989 @noindent
990 However, you can see that this order is harder to understand; this is
991 why we will list the arguments in the order that makes the commands
992 easiest to understand (and we encourage you to do the same when you use
993 @command{tar}, to avoid errors).
994
995 Note that the part of the command which says,
996 @w{@option{--file=collection.tar}} is considered to be @emph{one} argument.
997 If you substituted any other string of characters for
998 @kbd{collection.tar}, then that string would become the name of the
999 archive file you create.
1000
1001 The order of the options becomes more important when you begin to use
1002 short forms. With short forms, if you type commands in the wrong order
1003 (even if you type them correctly in all other ways), you may end up with
1004 results you don't expect. For this reason, it is a good idea to get
1005 into the habit of typing options in the order that makes inherent sense.
1006 @xref{short create}, for more information on this.
1007
1008 In this example, you type the command as shown above: @option{--create}
1009 is the operation which creates the new archive
1010 (@file{collection.tar}), and @option{--file} is the option which lets
1011 you give it the name you chose. The files, @file{blues}, @file{folk},
1012 and @file{jazz}, are now members of the archive, @file{collection.tar}
1013 (they are @dfn{file name arguments} to the @option{--create} operation).
1014 @FIXME{xref here to the discussion of file name args?}Now that they are
1015 in the archive, they are called @emph{archive members}, not files.
1016 (@pxref{Definitions,members}).
1017
1018 When you create an archive, you @emph{must} specify which files you
1019 want placed in the archive. If you do not specify any archive
1020 members, @GNUTAR{} will complain.
1021
1022 If you now list the contents of the working directory (@command{ls}), you will
1023 find the archive file listed as well as the files you saw previously:
1024
1025 @smallexample
1026 blues folk jazz collection.tar
1027 @end smallexample
1028
1029 @noindent
1030 Creating the archive @samp{collection.tar} did not destroy the copies of
1031 the files in the directory.
1032
1033 Keep in mind that if you don't indicate an operation, @command{tar} will not
1034 run and will prompt you for one. If you don't name any files, @command{tar}
1035 will complain. You must have write access to the working directory,
1036 or else you will not be able to create an archive in that directory.
1037
1038 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1039 an existing archive; it will delete the archive and write a new one.
1040 Use @option{--append} (@option{-r}) instead. @xref{append}.
1041
1042 @node create verbose
1043 @subsection Running @option{--create} with @option{--verbose}
1044
1045 @opindex create, using with @option{--verbose}
1046 @opindex verbose, using with @option{--create}
1047 If you include the @option{--verbose} (@option{-v}) option on the command line,
1048 @command{tar} will list the files it is acting on as it is working. In
1049 verbose mode, the @code{create} example above would appear as:
1050
1051 @smallexample
1052 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1053 blues
1054 folk
1055 jazz
1056 @end smallexample
1057
1058 This example is just like the example we showed which did not use
1059 @option{--verbose}, except that @command{tar} generated the remaining lines
1060 @iftex
1061 (note the different font styles).
1062 @end iftex
1063 @ifinfo
1064 .
1065 @end ifinfo
1066
1067 In the rest of the examples in this chapter, we will frequently use
1068 @code{verbose} mode so we can show actions or @command{tar} responses that
1069 you would otherwise not see, and which are important for you to
1070 understand.
1071
1072 @node short create
1073 @subsection Short Forms with @samp{create}
1074
1075 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1076 basic uses of @command{tar}, and you will use it countless times.
1077 Eventually, you will probably want to use abbreviated (or ``short'')
1078 forms of options. A full discussion of the three different forms that
1079 options can take appears in @ref{Styles}; for now, here is what the
1080 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1081 using short option forms:
1082
1083 @smallexample
1084 $ @kbd{tar -cvf collection.tar blues folk jazz}
1085 blues
1086 folk
1087 jazz
1088 @end smallexample
1089
1090 @noindent
1091 As you can see, the system responds the same no matter whether you use
1092 long or short option forms.
1093
1094 @FIXME{i don't like how this is worded:} One difference between using
1095 short and long option forms is that, although the exact placement of
1096 arguments following options is no more specific when using short forms,
1097 it is easier to become confused and make a mistake when using short
1098 forms. For example, suppose you attempted the above example in the
1099 following way:
1100
1101 @smallexample
1102 $ @kbd{tar -cfv collection.tar blues folk jazz}
1103 @end smallexample
1104
1105 @noindent
1106 In this case, @command{tar} will make an archive file called @file{v},
1107 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1108 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1109 is thus taken to be the chosen archive file name. @command{tar} will try
1110 to add a file called @file{collection.tar} to the @file{v} archive file;
1111 if the file @file{collection.tar} did not already exist, @command{tar} will
1112 report an error indicating that this file does not exist. If the file
1113 @file{collection.tar} does already exist (e.g., from a previous command
1114 you may have run), then @command{tar} will add this file to the archive.
1115 Because the @option{-v} option did not get registered, @command{tar} will not
1116 run under @samp{verbose} mode, and will not report its progress.
1117
1118 The end result is that you may be quite confused about what happened,
1119 and possibly overwrite a file. To illustrate this further, we will show
1120 you how an example we showed previously would look using short forms.
1121
1122 This example,
1123
1124 @smallexample
1125 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1126 @end smallexample
1127
1128 @noindent
1129 is confusing as it is. When shown using short forms, however, it
1130 becomes much more so:
1131
1132 @smallexample
1133 $ @kbd{tar blues -c folk -f collection.tar jazz}
1134 @end smallexample
1135
1136 @noindent
1137 It would be very easy to put the wrong string of characters
1138 immediately following the @option{-f}, but doing that could sacrifice
1139 valuable data.
1140
1141 For this reason, we recommend that you pay very careful attention to
1142 the order of options and placement of file and archive names,
1143 especially when using short option forms. Not having the option name
1144 written out mnemonically can affect how well you remember which option
1145 does what, and therefore where different names have to be placed.
1146
1147 @node create dir
1148 @subsection Archiving Directories
1149
1150 @cindex Archiving Directories
1151 @cindex Directories, Archiving
1152 You can archive a directory by specifying its directory name as a
1153 file name argument to @command{tar}. The files in the directory will be
1154 archived relative to the working directory, and the directory will be
1155 re-created along with its contents when the archive is extracted.
1156
1157 To archive a directory, first move to its superior directory. If you
1158 have followed the previous instructions in this tutorial, you should
1159 type:
1160
1161 @smallexample
1162 $ @kbd{cd ..}
1163 $
1164 @end smallexample
1165
1166 @noindent
1167 This will put you into the directory which contains @file{practice},
1168 i.e., your home directory. Once in the superior directory, you can
1169 specify the subdirectory, @file{practice}, as a file name argument. To
1170 store @file{practice} in the new archive file @file{music.tar}, type:
1171
1172 @smallexample
1173 $ @kbd{tar --create --verbose --file=music.tar practice}
1174 @end smallexample
1175
1176 @noindent
1177 @command{tar} should output:
1178
1179 @smallexample
1180 practice/
1181 practice/blues
1182 practice/folk
1183 practice/jazz
1184 practice/collection.tar
1185 @end smallexample
1186
1187 Note that the archive thus created is not in the subdirectory
1188 @file{practice}, but rather in the current working directory---the
1189 directory from which @command{tar} was invoked. Before trying to archive a
1190 directory from its superior directory, you should make sure you have
1191 write access to the superior directory itself, not only the directory
1192 you are trying archive with @command{tar}. For example, you will probably
1193 not be able to store your home directory in an archive by invoking
1194 @command{tar} from the root directory; @xref{absolute}. (Note
1195 also that @file{collection.tar}, the original archive file, has itself
1196 been archived. @command{tar} will accept any file as a file to be
1197 archived, regardless of its content. When @file{music.tar} is
1198 extracted, the archive file @file{collection.tar} will be re-written
1199 into the file system).
1200
1201 If you give @command{tar} a command such as
1202
1203 @smallexample
1204 $ @kbd{tar --create --file=foo.tar .}
1205 @end smallexample
1206
1207 @noindent
1208 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1209 dumped}. This happens because @command{tar} creates the archive
1210 @file{foo.tar} in the current directory before putting any files into
1211 it. Then, when @command{tar} attempts to add all the files in the
1212 directory @file{.} to the archive, it notices that the file
1213 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1214 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1215 will continue in this case, and create the archive
1216 normally, except for the exclusion of that one file. (@emph{Please
1217 note:} Other implementations of @command{tar} may not be so clever;
1218 they will enter an infinite loop when this happens, so you should not
1219 depend on this behavior unless you are certain you are running
1220 @GNUTAR{}. In general, it is wise to always place the archive outside
1221 of the directory being dumped.
1222
1223 @node list
1224 @section How to List Archives
1225
1226 @opindex list
1227 Frequently, you will find yourself wanting to determine exactly what a
1228 particular archive contains. You can use the @option{--list} (@option{-t}) operation
1229 to get the member names as they currently appear in the archive, as well
1230 as various attributes of the files at the time they were archived. For
1231 example, you can examine the archive @file{collection.tar} that you
1232 created in the last section with the command,
1233
1234 @smallexample
1235 $ @kbd{tar --list --file=collection.tar}
1236 @end smallexample
1237
1238 @noindent
1239 The output of @command{tar} would then be:
1240
1241 @smallexample
1242 blues
1243 folk
1244 jazz
1245 @end smallexample
1246
1247 @noindent
1248 The archive @file{bfiles.tar} would list as follows:
1249
1250 @smallexample
1251 ./birds
1252 baboon
1253 ./box
1254 @end smallexample
1255
1256 @noindent
1257 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1258 @var{archive-name}}) option just as with @option{--create}
1259 (@option{-c}) to specify the name of the archive.
1260
1261 @opindex list, using with @option{--verbose}
1262 @opindex verbose, using with @option{--list}
1263 If you use the @option{--verbose} (@option{-v}) option with
1264 @option{--list}, then @command{tar} will print out a listing
1265 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so forth.
1266
1267 If you had used @option{--verbose} (@option{-v}) mode, the example
1268 above would look like:
1269
1270 @smallexample
1271 $ @kbd{tar --list --verbose --file=collection.tar folk}
1272 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1273 @end smallexample
1274
1275 @cindex listing member and file names
1276 @anchor{listing member and file names}
1277 It is important to notice that the output of @kbd{tar --list
1278 --verbose} does not necessarily match that produced by @kbd{tar
1279 --create --verbose} while creating the archive. It is because
1280 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1281 prefixes from file names before storing them in the archive
1282 (@xref{absolute}, for more information). In other
1283 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1284 an archive and @dfn{member names} when listing it. Consider this
1285 example:
1286
1287 @smallexample
1288 @group
1289 $ @kbd{tar cfv archive /etc/mail}
1290 tar: Removing leading `/' from member names
1291 /etc/mail/
1292 /etc/mail/sendmail.cf
1293 /etc/mail/aliases
1294 $ @kbd{tar tf archive}
1295 etc/mail/
1296 etc/mail/sendmail.cf
1297 etc/mail/aliases
1298 @end group
1299 @end smallexample
1300
1301 @opindex show-stored-names
1302 This default behavior can sometimes be inconvenient. You can force
1303 @GNUTAR{} show member names when creating archive by supplying
1304 @option{--show-stored-names} option.
1305
1306 @table @option
1307 @item --show-stored-names
1308 Print member (as opposed to @emph{file}) names when creating the archive.
1309 @end table
1310
1311 @cindex File name arguments, using @option{--list} with
1312 @opindex list, using with file name arguments
1313 You can specify one or more individual member names as arguments when
1314 using @samp{list}. In this case, @command{tar} will only list the
1315 names of members you identify. For example, @w{@kbd{tar --list
1316 --file=afiles.tar apple}} would only print @file{apple}.
1317
1318 Because @command{tar} preserves paths, file names must be specified as
1319 they appear in the archive (ie., relative to the directory from which
1320 the archive was created). Therefore, it is essential when specifying
1321 member names to @command{tar} that you give the exact member names.
1322 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1323 error message something like @samp{tar: birds: Not found in archive},
1324 because there is no member named @file{birds}, only one named
1325 @file{./birds}. While the names @file{birds} and @file{./birds} name
1326 the same file, @emph{member} names by default are compared verbatim.
1327
1328 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1329 with @file{baboon}, because this exact member name is in the archive file
1330 @file{bfiles.tar}. If you are not sure of the exact file name,
1331 use @dfn{globbing patterns}, for example:
1332
1333 @smallexample
1334 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1335 @end smallexample
1336
1337 @noindent
1338 will list all members whose name contains @samp{b}. @xref{Wildcards},
1339 for a detailed discussion of globbing patterns and related
1340 @command{tar} command line options.
1341
1342 @menu
1343 * list dir::
1344 @end menu
1345
1346 @node list dir
1347 @unnumberedsubsec Listing the Contents of a Stored Directory
1348
1349 To get information about the contents of an archived directory,
1350 use the directory name as a file name argument in conjunction with
1351 @option{--list} (@option{-t}). To find out file attributes, include the
1352 @option{--verbose} (@option{-v}) option.
1353
1354 For example, to find out about files in the directory @file{practice}, in
1355 the archive file @file{music.tar}, type:
1356
1357 @smallexample
1358 $ @kbd{tar --list --verbose --file=music.tar practice}
1359 @end smallexample
1360
1361 @command{tar} responds:
1362
1363 @smallexample
1364 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1365 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1366 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1367 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1368 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1369 @end smallexample
1370
1371 When you use a directory name as a file name argument, @command{tar} acts on
1372 all the files (including sub-directories) in that directory.
1373
1374 @node extract
1375 @section How to Extract Members from an Archive
1376 @UNREVISED
1377 @cindex Extraction
1378 @cindex Retrieving files from an archive
1379 @cindex Resurrecting files from an archive
1380
1381 @opindex extract
1382 Creating an archive is only half the job---there is no point in storing
1383 files in an archive if you can't retrieve them. The act of retrieving
1384 members from an archive so they can be used and manipulated as
1385 unarchived files again is called @dfn{extraction}. To extract files
1386 from an archive, use the @option{--extract} (@option{--get} or
1387 @option{-x}) operation. As with @option{--create}, specify the name
1388 of the archive with @option{--file} (@option{-f}) option. Extracting
1389 an archive does not modify the archive in any way; you can extract it
1390 multiple times if you want or need to.
1391
1392 Using @option{--extract}, you can extract an entire archive, or specific
1393 files. The files can be directories containing other files, or not. As
1394 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1395 long form of the operation without affecting the performance.
1396
1397 @menu
1398 * extracting archives::
1399 * extracting files::
1400 * extract dir::
1401 * extracting untrusted archives::
1402 * failing commands::
1403 @end menu
1404
1405 @node extracting archives
1406 @subsection Extracting an Entire Archive
1407
1408 To extract an entire archive, specify the archive file name only, with
1409 no individual file names as arguments. For example,
1410
1411 @smallexample
1412 $ @kbd{tar -xvf collection.tar}
1413 @end smallexample
1414
1415 @noindent
1416 produces this:
1417
1418 @smallexample
1419 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1420 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1421 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1422 @end smallexample
1423
1424 @node extracting files
1425 @subsection Extracting Specific Files
1426
1427 To extract specific archive members, give their exact member names as
1428 arguments, as printed by @option{--list} (@option{-t}). If you had
1429 mistakenly deleted one of the files you had placed in the archive
1430 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1431 from the archive without changing the archive's structure. Its
1432 contents will be identical to the original file @file{blues} that you
1433 deleted.
1434
1435 First, make sure you are in the @file{practice} directory, and list the
1436 files in the directory. Now, delete the file, @samp{blues}, and list
1437 the files in the directory again.
1438
1439 You can now extract the member @file{blues} from the archive file
1440 @file{collection.tar} like this:
1441
1442 @smallexample
1443 $ @kbd{tar --extract --file=collection.tar blues}
1444 @end smallexample
1445
1446 @noindent
1447 If you list the files in the directory again, you will see that the file
1448 @file{blues} has been restored, with its original permissions, data
1449 modification times, and owner.@footnote{This is only accidentally
1450 true, but not in general. Whereas modification times are always
1451 restored, in most cases, one has to be root for restoring the owner,
1452 and use a special option for restoring permissions. Here, it just
1453 happens that the restoring user is also the owner of the archived
1454 members, and that the current @code{umask} is compatible with original
1455 permissions.} (These parameters will be identical to those which
1456 the file had when you originally placed it in the archive; any changes
1457 you may have made before deleting the file from the file system,
1458 however, will @emph{not} have been made to the archive member.) The
1459 archive file, @samp{collection.tar}, is the same as it was before you
1460 extracted @samp{blues}. You can confirm this by running @command{tar} with
1461 @option{--list} (@option{-t}).
1462
1463 Remember that as with other operations, specifying the exact member
1464 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1465 will fail, because there is no member named @file{birds}. To extract
1466 the member named @file{./birds}, you must specify @w{@kbd{tar
1467 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1468 exact member names, use @option{--list} (@option{-t}) option
1469 (@pxref{list}). You can also extract those members that match a
1470 specific @dfn{globbing pattern}. For example, to extract from
1471 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1472 directory prefix, you could type:
1473
1474 @smallexample
1475 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1476 @end smallexample
1477
1478 @noindent
1479 Here, @option{--wildcards} instructs @command{tar} to treat
1480 command line arguments as globbing patterns and @option{--no-anchored}
1481 informs it that the patterns apply to member names after any @samp{/}
1482 delimiter. The use of globbing patterns is discussed in detail in
1483 @xref{Wildcards}.
1484
1485 You can extract a file to standard output by combining the above options
1486 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1487 Output}).
1488
1489 If you give the @option{--verbose} option, then @option{--extract}
1490 will print the names of the archive members as it extracts them.
1491
1492 @node extract dir
1493 @subsection Extracting Files that are Directories
1494
1495 Extracting directories which are members of an archive is similar to
1496 extracting other files. The main difference to be aware of is that if
1497 the extracted directory has the same name as any directory already in
1498 the working directory, then files in the extracted directory will be
1499 placed into the directory of the same name. Likewise, if there are
1500 files in the pre-existing directory with the same names as the members
1501 which you extract, the files from the extracted archive will replace
1502 the files already in the working directory (and possible
1503 subdirectories). This will happen regardless of whether or not the
1504 files in the working directory were more recent than those extracted
1505 (there exist, however, special options that alter this behavior
1506 @pxref{Writing}).
1507
1508 However, if a file was stored with a directory name as part of its file
1509 name, and that directory does not exist under the working directory when
1510 the file is extracted, @command{tar} will create the directory.
1511
1512 We can demonstrate how to use @option{--extract} to extract a directory
1513 file with an example. Change to the @file{practice} directory if you
1514 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1515 go back to the parent directory and extract the archive
1516 @file{music.tar}. You may either extract the entire archive, or you may
1517 extract only the files you just deleted. To extract the entire archive,
1518 don't give any file names as arguments after the archive name
1519 @file{music.tar}. To extract only the files you deleted, use the
1520 following command:
1521
1522 @smallexample
1523 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1524 practice/folk
1525 practice/jazz
1526 @end smallexample
1527
1528 @noindent
1529 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1530 would have displayed more detail about the extracted files, as shown
1531 in the example below:
1532
1533 @smallexample
1534 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1535 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1536 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1537 @end smallexample
1538
1539 @noindent
1540 Because you created the directory with @file{practice} as part of the
1541 file names of each of the files by archiving the @file{practice}
1542 directory as @file{practice}, you must give @file{practice} as part
1543 of the file names when you extract those files from the archive.
1544
1545 @node extracting untrusted archives
1546 @subsection Extracting Archives from Untrusted Sources
1547
1548 Extracting files from archives can overwrite files that already exist.
1549 If you receive an archive from an untrusted source, you should make a
1550 new directory and extract into that directory, so that you don't have
1551 to worry about the extraction overwriting one of your existing files.
1552 For example, if @file{untrusted.tar} came from somewhere else on the
1553 Internet, and you don't necessarily trust its contents, you can
1554 extract it as follows:
1555
1556 @smallexample
1557 $ @kbd{mkdir newdir}
1558 $ @kbd{cd newdir}
1559 $ @kbd{tar -xvf ../untrusted.tar}
1560 @end smallexample
1561
1562 It is also a good practice to examine contents of the archive
1563 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1564 with @option{--verbose} (@option{-v}).
1565
1566 @node failing commands
1567 @subsection Commands That Will Fail
1568
1569 Here are some sample commands you might try which will not work, and why
1570 they won't work.
1571
1572 If you try to use this command,
1573
1574 @smallexample
1575 $ @kbd{tar -xvf music.tar folk jazz}
1576 @end smallexample
1577
1578 @noindent
1579 you will get the following response:
1580
1581 @smallexample
1582 tar: folk: Not found in archive
1583 tar: jazz: Not found in archive
1584 $
1585 @end smallexample
1586
1587 @noindent
1588 This is because these files were not originally @emph{in} the parent
1589 directory @file{..}, where the archive is located; they were in the
1590 @file{practice} directory, and their file names reflect this:
1591
1592 @smallexample
1593 $ @kbd{tar -tvf music.tar}
1594 practice/folk
1595 practice/jazz
1596 practice/rock
1597 @end smallexample
1598
1599 @FIXME{make sure the above works when going through the examples in
1600 order...}
1601
1602 @noindent
1603 Likewise, if you try to use this command,
1604
1605 @smallexample
1606 $ @kbd{tar -tvf music.tar folk jazz}
1607 @end smallexample
1608
1609 @noindent
1610 you would get a similar response. Members with those names are not in the
1611 archive. You must use the correct member names, or wildcards, in order
1612 to extract the files from the archive.
1613
1614 If you have forgotten the correct names of the files in the archive,
1615 use @w{@kbd{tar --list --verbose}} to list them correctly.
1616
1617 @FIXME{more examples, here? hag thinks it's a good idea.}
1618
1619 @node going further
1620 @section Going Further Ahead in this Manual
1621
1622 @FIXME{need to write up a node here about the things that are going to
1623 be in the rest of the manual.}
1624
1625 @node tar invocation
1626 @chapter Invoking @GNUTAR{}
1627 @UNREVISED
1628
1629 This chapter is about how one invokes the @GNUTAR{}
1630 command, from the command synopsis (@pxref{Synopsis}). There are
1631 numerous options, and many styles for writing them. One mandatory
1632 option specifies the operation @command{tar} should perform
1633 (@pxref{Operation Summary}), other options are meant to detail how
1634 this operation should be performed (@pxref{Option Summary}).
1635 Non-option arguments are not always interpreted the same way,
1636 depending on what the operation is.
1637
1638 You will find in this chapter everything about option styles and rules for
1639 writing them (@pxref{Styles}). On the other hand, operations and options
1640 are fully described elsewhere, in other chapters. Here, you will find
1641 only synthetic descriptions for operations and options, together with
1642 pointers to other parts of the @command{tar} manual.
1643
1644 Some options are so special they are fully described right in this
1645 chapter. They have the effect of inhibiting the normal operation of
1646 @command{tar} or else, they globally alter the amount of feedback the user
1647 receives about what is going on. These are the @option{--help} and
1648 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1649 and @option{--interactive} options (@pxref{interactive}).
1650
1651 @menu
1652 * Synopsis::
1653 * using tar options::
1654 * Styles::
1655 * All Options::
1656 * help::
1657 * defaults::
1658 * verbose::
1659 * interactive::
1660 @end menu
1661
1662 @node Synopsis
1663 @section General Synopsis of @command{tar}
1664
1665 The @GNUTAR{} program is invoked as either one of:
1666
1667 @smallexample
1668 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1669 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1670 @end smallexample
1671
1672 The second form is for when old options are being used.
1673
1674 You can use @command{tar} to store files in an archive, to extract them from
1675 an archive, and to do other types of archive manipulation. The primary
1676 argument to @command{tar}, which is called the @dfn{operation}, specifies
1677 which action to take. The other arguments to @command{tar} are either
1678 @dfn{options}, which change the way @command{tar} performs an operation,
1679 or file names or archive members, which specify the files or members
1680 @command{tar} is to act on.
1681
1682 You can actually type in arguments in any order, even if in this manual
1683 the options always precede the other arguments, to make examples easier
1684 to understand. Further, the option stating the main operation mode
1685 (the @command{tar} main command) is usually given first.
1686
1687 Each @var{name} in the synopsis above is interpreted as an archive member
1688 name when the main command is one of @option{--compare}
1689 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1690 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1691 @option{--update} (@option{-u}). When naming archive members, you
1692 must give the exact name of the member in the archive, as it is
1693 printed by @option{--list}. For @option{--append} (@option{-r}) and
1694 @option{--create} (@option{-c}), these @var{name} arguments specify
1695 the names of either files or directory hierarchies to place in the archive.
1696 These files or hierarchies should already exist in the file system,
1697 prior to the execution of the @command{tar} command.
1698
1699 @command{tar} interprets relative file names as being relative to the
1700 working directory. @command{tar} will make all file names relative
1701 (by removing leading slashes when archiving or restoring files),
1702 unless you specify otherwise (using the @option{--absolute-names}
1703 option). @xref{absolute}, for more information about
1704 @option{--absolute-names}.
1705
1706 If you give the name of a directory as either a file name or a member
1707 name, then @command{tar} acts recursively on all the files and directories
1708 beneath that directory. For example, the name @file{/} identifies all
1709 the files in the file system to @command{tar}.
1710
1711 The distinction between file names and archive member names is especially
1712 important when shell globbing is used, and sometimes a source of confusion
1713 for newcomers. @xref{Wildcards}, for more information about globbing.
1714 The problem is that shells may only glob using existing files in the
1715 file system. Only @command{tar} itself may glob on archive members, so when
1716 needed, you must ensure that wildcard characters reach @command{tar} without
1717 being interpreted by the shell first. Using a backslash before @samp{*}
1718 or @samp{?}, or putting the whole argument between quotes, is usually
1719 sufficient for this.
1720
1721 Even if @var{name}s are often specified on the command line, they
1722 can also be read from a text file in the file system, using the
1723 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1724
1725 If you don't use any file name arguments, @option{--append} (@option{-r}),
1726 @option{--delete} and @option{--concatenate} (@option{--catenate},
1727 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1728 will usually yield a diagnostic and inhibit @command{tar} execution.
1729 The other operations of @command{tar} (@option{--list},
1730 @option{--extract}, @option{--compare}, and @option{--update})
1731 will act on the entire contents of the archive.
1732
1733 @cindex exit status
1734 @cindex return status
1735 Besides successful exits, @GNUTAR{} may fail for
1736 many reasons. Some reasons correspond to bad usage, that is, when the
1737 @command{tar} command is improperly written. Errors may be
1738 encountered later, while encountering an error processing the archive
1739 or the files. Some errors are recoverable, in which case the failure
1740 is delayed until @command{tar} has completed all its work. Some
1741 errors are such that it would not meaningful, or at least risky, to
1742 continue processing: @command{tar} then aborts processing immediately.
1743 All abnormal exits, whether immediate or delayed, should always be
1744 clearly diagnosed on @code{stderr}, after a line stating the nature of
1745 the error.
1746
1747 @GNUTAR{} returns only a few exit statuses. I'm really
1748 aiming simplicity in that area, for now. If you are not using the
1749 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1750 that everything went well, besides maybe innocuous warnings. Nonzero
1751 means that something went wrong. Right now, as of today, ``nonzero''
1752 is almost always 2, except for remote operations, where it may be
1753 128.
1754
1755 @node using tar options
1756 @section Using @command{tar} Options
1757
1758 @GNUTAR{} has a total of eight operating modes which
1759 allow you to perform a variety of tasks. You are required to choose
1760 one operating mode each time you employ the @command{tar} program by
1761 specifying one, and only one operation as an argument to the
1762 @command{tar} command (two lists of four operations each may be found
1763 at @ref{frequent operations} and @ref{Operations}). Depending on
1764 circumstances, you may also wish to customize how the chosen operating
1765 mode behaves. For example, you may wish to change the way the output
1766 looks, or the format of the files that you wish to archive may require
1767 you to do something special in order to make the archive look right.
1768
1769 You can customize and control @command{tar}'s performance by running
1770 @command{tar} with one or more options (such as @option{--verbose}
1771 (@option{-v}), which we used in the tutorial). As we said in the
1772 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1773 their name suggests) optional. Depending on the operating mode, you
1774 may specify one or more options. Different options will have different
1775 effects, but in general they all change details of the operation, such
1776 as archive format, archive name, or level of user interaction. Some
1777 options make sense with all operating modes, while others are
1778 meaningful only with particular modes. You will likely use some
1779 options frequently, while you will only use others infrequently, or
1780 not at all. (A full list of options is available in @pxref{All Options}.)
1781
1782 @vrindex TAR_OPTIONS, environment variable
1783 @anchor{TAR_OPTIONS}
1784 The @env{TAR_OPTIONS} environment variable specifies default options to
1785 be placed in front of any explicit options. For example, if
1786 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1787 if the two options @option{-v} and @option{--unlink-first} had been
1788 specified before any explicit options. Option specifications are
1789 separated by whitespace. A backslash escapes the next character, so it
1790 can be used to specify an option containing whitespace or a backslash.
1791
1792 Note that @command{tar} options are case sensitive. For example, the
1793 options @option{-T} and @option{-t} are different; the first requires an
1794 argument for stating the name of a file providing a list of @var{name}s,
1795 while the second does not require an argument and is another way to
1796 write @option{--list} (@option{-t}).
1797
1798 In addition to the eight operations, there are many options to
1799 @command{tar}, and three different styles for writing both: long (mnemonic)
1800 form, short form, and old style. These styles are discussed below.
1801 Both the options and the operations can be written in any of these three
1802 styles.
1803
1804 @FIXME{menu at end of this node. need to think of an actual outline
1805 for this chapter; probably do that after stuff from chapter 4 is
1806 incorporated.}
1807
1808 @node Styles
1809 @section The Three Option Styles
1810
1811 There are three styles for writing operations and options to the command
1812 line invoking @command{tar}. The different styles were developed at
1813 different times during the history of @command{tar}. These styles will be
1814 presented below, from the most recent to the oldest.
1815
1816 Some options must take an argument. (For example, @option{--file}
1817 (@option{-f})) takes the name of an archive file as an argument. If
1818 you do not supply an archive file name, @command{tar} will use a
1819 default, but this can be confusing; thus, we recommend that you always
1820 supply a specific archive file name.) Where you @emph{place} the
1821 arguments generally depends on which style of options you choose. We
1822 will detail specific information relevant to each option style in the
1823 sections on the different option styles, below. The differences are
1824 subtle, yet can often be very important; incorrect option placement
1825 can cause you to overwrite a number of important files. We urge you
1826 to note these differences, and only use the option style(s) which
1827 makes the most sense to you until you feel comfortable with the others.
1828
1829 Some options @emph{may} take an argument (currently, there are
1830 two such options: @option{--backup} and @option{--occurrence}). Such
1831 options may have at most long and short forms, they do not have old style
1832 equivalent. The rules for specifying an argument for such options
1833 are stricter than those for specifying mandatory arguments. Please,
1834 pay special attention to them.
1835
1836 @menu
1837 * Mnemonic Options:: Mnemonic Option Style
1838 * Short Options:: Short Option Style
1839 * Old Options:: Old Option Style
1840 * Mixing:: Mixing Option Styles
1841 @end menu
1842
1843 @node Mnemonic Options
1844 @subsection Mnemonic Option Style
1845
1846 @FIXME{have to decide whether or not to replace other occurrences of
1847 "mnemonic" with "long", or *ugh* vice versa.}
1848
1849 Each option has at least one long (or mnemonic) name starting with two
1850 dashes in a row, e.g., @option{--list}. The long names are more clear than
1851 their corresponding short or old names. It sometimes happens that a
1852 single mnemonic option has many different different names which are
1853 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1854 long option names can be given unique abbreviations. For example,
1855 @option{--cre} can be used in place of @option{--create} because there is no
1856 other mnemonic option which begins with @samp{cre}. (One way to find
1857 this out is by trying it and seeing what happens; if a particular
1858 abbreviation could represent more than one option, @command{tar} will tell
1859 you that that abbreviation is ambiguous and you'll know that that
1860 abbreviation won't work. You may also choose to run @samp{tar --help}
1861 to see a list of options. Be aware that if you run @command{tar} with a
1862 unique abbreviation for the long name of an option you didn't want to
1863 use, you are stuck; @command{tar} will perform the command as ordered.)
1864
1865 Mnemonic options are meant to be obvious and easy to remember, and their
1866 meanings are generally easier to discern than those of their
1867 corresponding short options (see below). For example:
1868
1869 @smallexample
1870 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
1871 @end smallexample
1872
1873 @noindent
1874 gives a fairly good set of hints about what the command does, even
1875 for those not fully acquainted with @command{tar}.
1876
1877 Mnemonic options which require arguments take those arguments
1878 immediately following the option name. There are two ways of
1879 specifying a mandatory argument. It can be separated from the
1880 option name either by an equal sign, or by any amount of
1881 white space characters. For example, the @option{--file} option (which
1882 tells the name of the @command{tar} archive) is given a file such as
1883 @file{archive.tar} as argument by using any of the following notations:
1884 @option{--file=archive.tar} or @option{--file archive.tar}.
1885
1886 In contrast, optional arguments must always be introduced using
1887 an equal sign. For example, the @option{--backup} option takes
1888 an optional argument specifying backup type. It must be used
1889 as @option{--backup=@var{backup-type}}.
1890
1891 @node Short Options
1892 @subsection Short Option Style
1893
1894 Most options also have a short option name. Short options start with
1895 a single dash, and are followed by a single character, e.g., @option{-t}
1896 (which is equivalent to @option{--list}). The forms are absolutely
1897 identical in function; they are interchangeable.
1898
1899 The short option names are faster to type than long option names.
1900
1901 Short options which require arguments take their arguments immediately
1902 following the option, usually separated by white space. It is also
1903 possible to stick the argument right after the short option name, using
1904 no intervening space. For example, you might write @w{@option{-f
1905 archive.tar}} or @option{-farchive.tar} instead of using
1906 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
1907 @w{@option{-f @var{archive-name}}} denote the option which indicates a
1908 specific archive, here named @file{archive.tar}.
1909
1910 Short options which take optional arguments take their arguments
1911 immediately following the option letter, @emph{without any intervening
1912 white space characters}.
1913
1914 Short options' letters may be clumped together, but you are not
1915 required to do this (as compared to old options; see below). When
1916 short options are clumped as a set, use one (single) dash for them
1917 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
1918 such a set is allowed to have an argument@footnote{Clustering many
1919 options, the last of which has an argument, is a rather opaque way to
1920 write options. Some wonder if @acronym{GNU} @code{getopt} should not
1921 even be made helpful enough for considering such usages as invalid.}.
1922
1923 When the options are separated, the argument for each option which requires
1924 an argument directly follows that option, as is usual for Unix programs.
1925 For example:
1926
1927 @smallexample
1928 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
1929 @end smallexample
1930
1931 If you reorder short options' locations, be sure to move any arguments
1932 that belong to them. If you do not move the arguments properly, you may
1933 end up overwriting files.
1934
1935 @node Old Options
1936 @subsection Old Option Style
1937 @UNREVISED
1938
1939 Like short options, old options are single letters. However, old options
1940 must be written together as a single clumped set, without spaces separating
1941 them or dashes preceding them@footnote{Beware that if you precede options
1942 with a dash, you are announcing the short option style instead of the
1943 old option style; short options are decoded differently.}. This set
1944 of letters must be the first to appear on the command line, after the
1945 @command{tar} program name and some white space; old options cannot appear
1946 anywhere else. The letter of an old option is exactly the same letter as
1947 the corresponding short option. For example, the old option @samp{t} is
1948 the same as the short option @option{-t}, and consequently, the same as the
1949 mnemonic option @option{--list}. So for example, the command @w{@samp{tar
1950 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
1951
1952 When options that need arguments are given together with the command,
1953 all the associated arguments follow, in the same order as the options.
1954 Thus, the example given previously could also be written in the old
1955 style as follows:
1956
1957 @smallexample
1958 $ @kbd{tar cvbf 20 /dev/rmt0}
1959 @end smallexample
1960
1961 @noindent
1962 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
1963 the argument of @option{-f}.
1964
1965 On the other hand, this old style syntax makes it difficult to match
1966 option letters with their corresponding arguments, and is often
1967 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
1968 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
1969 argument for @option{-f}, and @option{-v} does not have a corresponding
1970 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
1971 /dev/rmt0}} is clearer, putting all arguments next to the option they
1972 pertain to.
1973
1974 If you want to reorder the letters in the old option argument, be
1975 sure to reorder any corresponding argument appropriately.
1976
1977 This old way of writing @command{tar} options can surprise even experienced
1978 users. For example, the two commands:
1979
1980 @smallexample
1981 @kbd{tar cfz archive.tar.gz file}
1982 @kbd{tar -cfz archive.tar.gz file}
1983 @end smallexample
1984
1985 @noindent
1986 are quite different. The first example uses @file{archive.tar.gz} as
1987 the value for option @samp{f} and recognizes the option @samp{z}. The
1988 second example, however, uses @file{z} as the value for option
1989 @samp{f} --- probably not what was intended.
1990
1991 Old options are kept for compatibility with old versions of @command{tar}.
1992
1993 This second example could be corrected in many ways, among which the
1994 following are equivalent:
1995
1996 @smallexample
1997 @kbd{tar -czf archive.tar.gz file}
1998 @kbd{tar -cf archive.tar.gz -z file}
1999 @kbd{tar cf archive.tar.gz -z file}
2000 @end smallexample
2001
2002 @cindex option syntax, traditional
2003 As far as we know, all @command{tar} programs, @acronym{GNU} and
2004 non-@acronym{GNU}, support old options. @GNUTAR{}
2005 supports them not only for historical reasons, but also because many
2006 people are used to them. For compatibility with Unix @command{tar},
2007 the first argument is always treated as containing command and option
2008 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2009 equivalent to @w{@samp{tar -c}:} both of them specify the
2010 @option{--create} (@option{-c}) command to create an archive.
2011
2012 @node Mixing
2013 @subsection Mixing Option Styles
2014
2015 All three styles may be intermixed in a single @command{tar} command,
2016 so long as the rules for each style are fully
2017 respected@footnote{Before @GNUTAR{} version 1.11.6,
2018 a bug prevented intermixing old style options with mnemonic options in
2019 some cases.}. Old style options and either of the modern styles of
2020 options may be mixed within a single @command{tar} command. However,
2021 old style options must be introduced as the first arguments only,
2022 following the rule for old options (old options must appear directly
2023 after the @command{tar} command and some white space). Modern options
2024 may be given only after all arguments to the old options have been
2025 collected. If this rule is not respected, a modern option might be
2026 falsely interpreted as the value of the argument to one of the old
2027 style options.
2028
2029 For example, all the following commands are wholly equivalent, and
2030 illustrate the many combinations and orderings of option styles.
2031
2032 @smallexample
2033 @kbd{tar --create --file=archive.tar}
2034 @kbd{tar --create -f archive.tar}
2035 @kbd{tar --create -farchive.tar}
2036 @kbd{tar --file=archive.tar --create}
2037 @kbd{tar --file=archive.tar -c}
2038 @kbd{tar -c --file=archive.tar}
2039 @kbd{tar -c -f archive.tar}
2040 @kbd{tar -c -farchive.tar}
2041 @kbd{tar -cf archive.tar}
2042 @kbd{tar -cfarchive.tar}
2043 @kbd{tar -f archive.tar --create}
2044 @kbd{tar -f archive.tar -c}
2045 @kbd{tar -farchive.tar --create}
2046 @kbd{tar -farchive.tar -c}
2047 @kbd{tar c --file=archive.tar}
2048 @kbd{tar c -f archive.tar}
2049 @kbd{tar c -farchive.tar}
2050 @kbd{tar cf archive.tar}
2051 @kbd{tar f archive.tar --create}
2052 @kbd{tar f archive.tar -c}
2053 @kbd{tar fc archive.tar}
2054 @end smallexample
2055
2056 On the other hand, the following commands are @emph{not} equivalent to
2057 the previous set:
2058
2059 @smallexample
2060 @kbd{tar -f -c archive.tar}
2061 @kbd{tar -fc archive.tar}
2062 @kbd{tar -fcarchive.tar}
2063 @kbd{tar -farchive.tarc}
2064 @kbd{tar cfarchive.tar}
2065 @end smallexample
2066
2067 @noindent
2068 These last examples mean something completely different from what the
2069 user intended (judging based on the example in the previous set which
2070 uses long options, whose intent is therefore very clear). The first
2071 four specify that the @command{tar} archive would be a file named
2072 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2073 respectively. The first two examples also specify a single non-option,
2074 @var{name} argument having the value @samp{archive.tar}. The last
2075 example contains only old style option letters (repeating option
2076 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2077 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2078 the first sentence of this paragraph..}
2079
2080 @node All Options
2081 @section All @command{tar} Options
2082
2083 The coming manual sections contain an alphabetical listing of all
2084 @command{tar} operations and options, with brief descriptions and cross
2085 references to more in-depth explanations in the body of the manual.
2086 They also contain an alphabetically arranged table of the short option
2087 forms with their corresponding long option. You can use this table as
2088 a reference for deciphering @command{tar} commands in scripts.
2089
2090 @menu
2091 * Operation Summary::
2092 * Option Summary::
2093 * Short Option Summary::
2094 @end menu
2095
2096 @node Operation Summary
2097 @subsection Operations
2098
2099 @table @option
2100
2101 @opindex append, summary
2102 @item --append
2103 @itemx -r
2104
2105 Appends files to the end of the archive. @xref{append}.
2106
2107 @opindex catenate, summary
2108 @item --catenate
2109 @itemx -A
2110
2111 Same as @option{--concatenate}. @xref{concatenate}.
2112
2113 @opindex compare, summary
2114 @item --compare
2115 @itemx -d
2116
2117 Compares archive members with their counterparts in the file
2118 system, and reports differences in file size, mode, owner,
2119 modification date and contents. @xref{compare}.
2120
2121 @opindex concatenate, summary
2122 @item --concatenate
2123 @itemx -A
2124
2125 Appends other @command{tar} archives to the end of the archive.
2126 @xref{concatenate}.
2127
2128 @opindex create, summary
2129 @item --create
2130 @itemx -c
2131
2132 Creates a new @command{tar} archive. @xref{create}.
2133
2134 @opindex delete, summary
2135 @item --delete
2136
2137 Deletes members from the archive. Don't try this on a archive on a
2138 tape! @xref{delete}.
2139
2140 @opindex diff, summary
2141 @item --diff
2142 @itemx -d
2143
2144 Same @option{--compare}. @xref{compare}.
2145
2146 @opindex extract, summary
2147 @item --extract
2148 @itemx -x
2149
2150 Extracts members from the archive into the file system. @xref{extract}.
2151
2152 @opindex get, summary
2153 @item --get
2154 @itemx -x
2155
2156 Same as @option{--extract}. @xref{extract}.
2157
2158 @opindex list, summary
2159 @item --list
2160 @itemx -t
2161
2162 Lists the members in an archive. @xref{list}.
2163
2164 @opindex update, summary
2165 @item --update
2166 @itemx -u
2167
2168 Adds files to the end of the archive, but only if they are newer than
2169 their counterparts already in the archive, or if they do not already
2170 exist in the archive. @xref{update}.
2171
2172 @end table
2173
2174 @node Option Summary
2175 @subsection @command{tar} Options
2176
2177 @table @option
2178
2179 @opindex absolute-names, summary
2180 @item --absolute-names
2181 @itemx -P
2182
2183 Normally when creating an archive, @command{tar} strips an initial
2184 @samp{/} from member names. This option disables that behavior.
2185 @xref{absolute}.
2186
2187 @opindex after-date, summary
2188 @item --after-date
2189
2190 (See @option{--newer}, @pxref{after})
2191
2192 @opindex anchored, summary
2193 @item --anchored
2194 A pattern must match an initial subsequence of the name's components.
2195 @xref{controlling pattern-matching}.
2196
2197 @opindex atime-preserve, summary
2198 @item --atime-preserve
2199 @itemx --atime-preserve=replace
2200 @itemx --atime-preserve=system
2201
2202 Attempt to preserve the access time of files when reading them. This
2203 option currently is effective only on files that you own, unless you
2204 have superuser privileges.
2205
2206 @option{--atime-preserve=replace} remembers the access time of a file
2207 before reading it, and then restores the access time afterwards. This
2208 may cause problems if other programs are reading the file at the same
2209 time, as the times of their accesses will be lost. On most platforms
2210 restoring the access time also requires @command{tar} to restore the
2211 data modification time too, so this option may also cause problems if
2212 other programs are writing the file at the same time. (Tar attempts
2213 to detect this situation, but cannot do so reliably due to race
2214 conditions.) Worse, on most platforms restoring the access time also
2215 updates the status change time, which means that this option is
2216 incompatible with incremental backups.
2217
2218 @option{--atime-preserve=system} avoids changing time stamps on files,
2219 without interfering with time stamp updates
2220 caused by other programs, so it works better with incremental backups.
2221 However, it requires a special @code{O_NOATIME} option from the
2222 underlying operating and file system implementation, and it also requires
2223 that searching directories does not update their access times. As of
2224 this writing (November 2005) this works only with Linux, and only with
2225 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2226 way to know whether this feature actually works. Sometimes
2227 @command{tar} knows that it does not work, and if you use
2228 @option{--atime-preserve=system} then @command{tar} complains and
2229 exits right away. But other times @command{tar} might think that the
2230 option works when it actually does not.
2231
2232 Currently @option{--atime-preserve} with no operand defaults to
2233 @option{--atime-preserve=replace}, but this may change in the future
2234 as support for @option{--atime-preserve=system} improves.
2235
2236 If your operating system does not support
2237 @option{--atime-preserve=system}, you might be able to preserve access
2238 times reliably by by using the @command{mount} command. For example,
2239 you can mount the file system read-only, or access the file system via
2240 a read-only loopback mount, or use the @samp{noatime} mount option
2241 available on some systems. However, mounting typically requires
2242 superuser privileges and can be a pain to manage.
2243
2244 @opindex backup, summary
2245 @item --backup=@var{backup-type}
2246
2247 Rather than deleting files from the file system, @command{tar} will
2248 back them up using simple or numbered backups, depending upon
2249 @var{backup-type}. @xref{backup}.
2250
2251 @opindex block-number, summary
2252 @item --block-number
2253 @itemx -R
2254
2255 With this option present, @command{tar} prints error messages for read errors
2256 with the block number in the archive file. @xref{block-number}.
2257
2258 @opindex blocking-factor, summary
2259 @item --blocking-factor=@var{blocking}
2260 @itemx -b @var{blocking}
2261
2262 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2263 record. @xref{Blocking Factor}.
2264
2265 @opindex bzip2, summary
2266 @item --bzip2
2267 @itemx -j
2268
2269 This option tells @command{tar} to read or write archives through
2270 @code{bzip2}. @xref{gzip}.
2271
2272 @opindex checkpoint, summary
2273 @item --checkpoint
2274
2275 This option directs @command{tar} to print periodic checkpoint messages as it
2276 reads through the archive. It is intended for when you want a visual
2277 indication that @command{tar} is still running, but don't want to see
2278 @option{--verbose} output. @FIXME-xref{}
2279
2280 @opindex check-links, summary
2281 @item --check-links
2282 @itemx -l
2283 If this option was given, @command{tar} will check the number of links
2284 dumped for each processed file. If this number does not match the
2285 total number of hard links for the file, a warning message will be
2286 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2287 synonym for @option{--one-file-system}. The current semantics, wich
2288 complies to UNIX98, was introduced with version
2289 1.15.91. @xref{Changes}, for more information.}.
2290
2291 @opindex compress, summary
2292 @opindex uncompress, summary
2293 @item --compress
2294 @itemx --uncompress
2295 @itemx -Z
2296
2297 @command{tar} will use the @command{compress} program when reading or
2298 writing the archive. This allows you to directly act on archives
2299 while saving space. @xref{gzip}.
2300
2301 @opindex confirmation, summary
2302 @item --confirmation
2303
2304 (See @option{--interactive}.) @xref{interactive}.
2305
2306 @opindex delay-directory-restore, summary
2307 @item --delay-directory-restore
2308
2309 Delay setting modification times and permissions of extracted
2310 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2311
2312 @opindex dereference, summary
2313 @item --dereference
2314 @itemx -h
2315
2316 When creating a @command{tar} archive, @command{tar} will archive the
2317 file that a symbolic link points to, rather than archiving the
2318 symlink. @xref{dereference}.
2319
2320 @opindex directory, summary
2321 @item --directory=@var{dir}
2322 @itemx -C @var{dir}
2323
2324 When this option is specified, @command{tar} will change its current directory
2325 to @var{dir} before performing any operations. When this option is used
2326 during archive creation, it is order sensitive. @xref{directory}.
2327
2328 @opindex exclude, summary
2329 @item --exclude=@var{pattern}
2330
2331 When performing operations, @command{tar} will skip files that match
2332 @var{pattern}. @xref{exclude}.
2333
2334 @opindex exclude-from, summary
2335 @item --exclude-from=@var{file}
2336 @itemx -X @var{file}
2337
2338 Similar to @option{--exclude}, except @command{tar} will use the list of
2339 patterns in the file @var{file}. @xref{exclude}.
2340
2341 @opindex exclude-caches, summary
2342 @item --exclude-caches
2343
2344 Automatically excludes all directories
2345 containing a cache directory tag. @xref{exclude}.
2346
2347 @opindex file, summary
2348 @item --file=@var{archive}
2349 @itemx -f @var{archive}
2350
2351 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2352 performs operations on, rather than @command{tar}'s compilation dependent
2353 default. @xref{file tutorial}.
2354
2355 @opindex files-from, summary
2356 @item --files-from=@var{file}
2357 @itemx -T @var{file}
2358
2359 @command{tar} will use the contents of @var{file} as a list of archive members
2360 or files to operate on, in addition to those specified on the
2361 command-line. @xref{files}.
2362
2363 @opindex force-local, summary
2364 @item --force-local
2365
2366 Forces @command{tar} to interpret the filename given to @option{--file}
2367 as a local file, even if it looks like a remote tape drive name.
2368 @xref{local and remote archives}.
2369
2370 @opindex format, summary
2371 @item --format=@var{format}
2372
2373 Selects output archive format. @var{Format} may be one of the
2374 following:
2375
2376 @table @samp
2377 @item v7
2378 Creates an archive that is compatible with Unix V7 @command{tar}.
2379
2380 @item oldgnu
2381 Creates an archive that is compatible with GNU @command{tar} version
2382 1.12 or earlier.
2383
2384 @item gnu
2385 Creates archive in GNU tar 1.13 format. Basically it is the same as
2386 @samp{oldgnu} with the only difference in the way it handles long
2387 numeric fields.
2388
2389 @item ustar
2390 Creates a @acronym{POSIX.1-1988} compatible archive.
2391
2392 @item posix
2393 Creates a @acronym{POSIX.1-2001 archive}.
2394
2395 @end table
2396
2397 @xref{Formats}, for a detailed discussion of these formats.
2398
2399 @opindex group, summary
2400 @item --group=@var{group}
2401
2402 Files added to the @command{tar} archive will have a group id of @var{group},
2403 rather than the group from the source file. @var{group} is first decoded
2404 as a group symbolic name, but if this interpretation fails, it has to be
2405 a decimal numeric group ID. @FIXME-xref{}
2406
2407 Also see the comments for the @option{--owner=@var{user}} option.
2408
2409 @opindex gzip, summary
2410 @opindex gunzip, summary
2411 @opindex ungzip, summary
2412 @item --gzip
2413 @itemx --gunzip
2414 @itemx --ungzip
2415 @itemx -z
2416
2417 This option tells @command{tar} to read or write archives through
2418 @command{gzip}, allowing @command{tar} to directly operate on several
2419 kinds of compressed archives transparently. @xref{gzip}.
2420
2421 @opindex help, summary
2422 @item --help
2423
2424 @command{tar} will print out a short message summarizing the operations and
2425 options to @command{tar} and exit. @xref{help}.
2426
2427 @opindex ignore-case, summary
2428 @item --ignore-case
2429 Ignore case when matching member or file names with
2430 patterns. @xref{controlling pattern-matching}.
2431
2432 @opindex ignore-command-error, summary
2433 @item --ignore-command-error
2434 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2435
2436 @opindex ignore-failed-read, summary
2437 @item --ignore-failed-read
2438
2439 Do not exit unsuccessfully merely because an unreadable file was encountered.
2440 @xref{Reading}.
2441
2442 @opindex ignore-zeros, summary
2443 @item --ignore-zeros
2444 @itemx -i
2445
2446 With this option, @command{tar} will ignore zeroed blocks in the
2447 archive, which normally signals EOF. @xref{Reading}.
2448
2449 @opindex incremental, summary
2450 @item --incremental
2451 @itemx -G
2452
2453 Used to inform @command{tar} that it is working with an old
2454 @acronym{GNU}-format incremental backup archive. It is intended
2455 primarily for backwards compatibility only. @xref{Incremental Dumps},
2456 for a detailed discussion of incremental archives.
2457
2458 @opindex index-file, summary
2459 @item --index-file=@var{file}
2460
2461 Send verbose output to @var{file} instead of to standard output.
2462
2463 @opindex info-script, summary
2464 @opindex new-volume-script, summary
2465 @item --info-script=@var{script-file}
2466 @itemx --new-volume-script=@var{script-file}
2467 @itemx -F @var{script-file}
2468
2469 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2470 at the end of each tape. If @var{script-file} exits with nonzero status,
2471 @command{tar} fails immediately. @xref{info-script}, for a detailed
2472 discussion of @var{script-file}.
2473
2474 @opindex interactive, summary
2475 @item --interactive
2476 @itemx --confirmation
2477 @itemx -w
2478
2479 Specifies that @command{tar} should ask the user for confirmation before
2480 performing potentially destructive options, such as overwriting files.
2481 @xref{interactive}.
2482
2483 @opindex keep-newer-files, summary
2484 @item --keep-newer-files
2485
2486 Do not replace existing files that are newer than their archive copies
2487 when extracting files from an archive.
2488
2489 @opindex keep-old-files, summary
2490 @item --keep-old-files
2491 @itemx -k
2492
2493 Do not overwrite existing files when extracting files from an archive.
2494 @xref{Keep Old Files}.
2495
2496 @opindex label, summary
2497 @item --label=@var{name}
2498 @itemx -V @var{name}
2499
2500 When creating an archive, instructs @command{tar} to write @var{name}
2501 as a name record in the archive. When extracting or listing archives,
2502 @command{tar} will only operate on archives that have a label matching
2503 the pattern specified in @var{name}. @xref{Tape Files}.
2504
2505 @opindex listed-incremental, summary
2506 @item --listed-incremental=@var{snapshot-file}
2507 @itemx -g @var{snapshot-file}
2508
2509 During a @option{--create} operation, specifies that the archive that
2510 @command{tar} creates is a new @acronym{GNU}-format incremental
2511 backup, using @var{snapshot-file} to determine which files to backup.
2512 With other operations, informs @command{tar} that the archive is in
2513 incremental format. @xref{Incremental Dumps}.
2514
2515 @opindex mode, summary
2516 @item --mode=@var{permissions}
2517
2518 When adding files to an archive, @command{tar} will use
2519 @var{permissions} for the archive members, rather than the permissions
2520 from the files. The program @command{chmod} and this @command{tar}
2521 option share the same syntax for what @var{permissions} might be.
2522 @xref{File permissions, Permissions, File permissions, fileutils,
2523 @acronym{GNU} file utilities}. This reference also has useful
2524 information for those not being overly familiar with the Unix
2525 permission system.
2526
2527 Of course, @var{permissions} might be plainly specified as an octal number.
2528 However, by using generic symbolic modifications to mode bits, this allows
2529 more flexibility. For example, the value @samp{a+rw} adds read and write
2530 permissions for everybody, while retaining executable bits on directories
2531 or on any other file already marked as executable.
2532
2533 @opindex multi-volume, summary
2534 @item --multi-volume
2535 @itemx -M
2536
2537 Informs @command{tar} that it should create or otherwise operate on a
2538 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2539
2540 @opindex new-volume-script, summary
2541 @item --new-volume-script
2542
2543 (see --info-script)
2544
2545 @opindex seek, summary
2546 @item --seek
2547 @itemx -n
2548
2549 Assume that the archive media supports seeks to arbitrary
2550 locations. Usually @command{tar} determines automatically whether
2551 the archive can be seeked or not. This option is intended for use
2552 in cases when such recognition fails.
2553
2554 @opindex newer, summary
2555 @item --newer=@var{date}
2556 @itemx --after-date=@var{date}
2557 @itemx -N
2558
2559 When creating an archive, @command{tar} will only add files that have changed
2560 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2561 is taken to be the name of a file whose data modification time specifies
2562 the date. @xref{after}.
2563
2564 @opindex newer-mtime, summary
2565 @item --newer-mtime=@var{date}
2566
2567 Like @option{--newer}, but add only files whose
2568 contents have changed (as opposed to just @option{--newer}, which will
2569 also back up files for which any status information has changed).
2570
2571 @opindex no-anchored, summary
2572 @item --no-anchored
2573 An exclude pattern can match any subsequence of the name's components.
2574 @xref{controlling pattern-matching}.
2575
2576 @opindex no-delay-directory-restore, summary
2577 @item --no-delay-directory-restore
2578
2579 Setting modification times and permissions of extracted
2580 directories when all files from this directory has been
2581 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2582
2583 @opindex no-ignore-case, summary
2584 @item --no-ignore-case
2585 Use case-sensitive matching.
2586 @xref{controlling pattern-matching}.
2587
2588 @opindex no-ignore-command-error, summary
2589 @item --no-ignore-command-error
2590 Print warnings about subprocesses terminated with a non-zero exit
2591 code. @xref{Writing to an External Program}.
2592
2593 @opindex no-quote-chars, summary
2594 @item --no-quote-chars=@var{string}
2595 Do not quote characters from @var{string}, even if the selected
2596 quoting style implies they should be quoted (@FIXME-pxref{Quoting Styles}).
2597
2598 @opindex no-recursion, summary
2599 @item --no-recursion
2600
2601 With this option, @command{tar} will not recurse into directories.
2602 @xref{recurse}.
2603
2604 @opindex no-same-owner, summary
2605 @item --no-same-owner
2606 @itemx -o
2607
2608 When extracting an archive, do not attempt to preserve the owner
2609 specified in the @command{tar} archive. This the default behavior
2610 for ordinary users.
2611
2612 @opindex no-same-permissions, summary
2613 @item --no-same-permissions
2614
2615 When extracting an archive, subtract the user's umask from files from
2616 the permissions specified in the archive. This is the default behavior
2617 for ordinary users.
2618
2619 @opindex no-wildcards, summary
2620 @item --no-wildcards
2621 Do not use wildcards.
2622 @xref{controlling pattern-matching}.
2623
2624 @opindex no-wildcards-match-slash, summary
2625 @item --no-wildcards-match-slash
2626 Wildcards do not match @samp{/}.
2627 @xref{controlling pattern-matching}.
2628
2629 @opindex null, summary
2630 @item --null
2631
2632 When @command{tar} is using the @option{--files-from} option, this option
2633 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2634 @command{tar} can correctly work with file names that contain newlines.
2635 @xref{nul}.
2636
2637 @opindex numeric-owner, summary
2638 @item --numeric-owner
2639
2640 This option will notify @command{tar} that it should use numeric user
2641 and group IDs when creating a @command{tar} file, rather than names.
2642 @xref{Attributes}.
2643
2644 @item -o
2645 When extracting files, this option is a synonym for
2646 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2647 restoring ownership of files being extracted.
2648
2649 When creating an archive, @option{-o} is a synonym for
2650 @option{--old-archive}. This behavior is for compatibility
2651 with previous versions of @GNUTAR{}, and will be
2652 removed in the future releases.
2653
2654 @xref{Changes}, for more information.
2655
2656 @opindex occurrence, summary
2657 @item --occurrence[=@var{number}]
2658
2659 This option can be used in conjunction with one of the subcommands
2660 @option{--delete}, @option{--diff}, @option{--extract} or
2661 @option{--list} when a list of files is given either on the command
2662 line or via @option{-T} option.
2663
2664 This option instructs @command{tar} to process only the @var{number}th
2665 occurrence of each named file. @var{Number} defaults to 1, so
2666
2667 @smallexample
2668 tar -x -f archive.tar --occurrence filename
2669 @end smallexample
2670
2671 @noindent
2672 will extract the first occurrence of @file{filename} from @file{archive.tar}
2673 and will terminate without scanning to the end of the archive.
2674
2675 @opindex old-archive, summary
2676 @item --old-archive
2677 Synonym for @option{--format=v7}.
2678
2679 @opindex one-file-system, summary
2680 @item --one-file-system
2681 Used when creating an archive. Prevents @command{tar} from recursing into
2682 directories that are on different file systems from the current
2683 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2684 synonym for @option{--one-file-system}. This has changed in version
2685 1.15.91. @xref{Changes}, for more information.}.
2686
2687 @opindex overwrite, summary
2688 @item --overwrite
2689
2690 Overwrite existing files and directory metadata when extracting files
2691 from an archive. @xref{Overwrite Old Files}.
2692
2693 @opindex overwrite-dir, summary
2694 @item --overwrite-dir
2695
2696 Overwrite the metadata of existing directories when extracting files
2697 from an archive. @xref{Overwrite Old Files}.
2698
2699 @opindex owner, summary
2700 @item --owner=@var{user}
2701
2702 Specifies that @command{tar} should use @var{user} as the owner of members
2703 when creating archives, instead of the user associated with the source
2704 file. @var{user} is first decoded as a user symbolic name, but if
2705 this interpretation fails, it has to be a decimal numeric user ID.
2706 @FIXME-xref{}
2707
2708 There is no value indicating a missing number, and @samp{0} usually means
2709 @code{root}. Some people like to force @samp{0} as the value to offer in
2710 their distributions for the owner of files, because the @code{root} user is
2711 anonymous anyway, so that might as well be the owner of anonymous archives.
2712
2713 This option does not affect extraction from archives.
2714
2715 @opindex quote-chars, summary
2716 @item --quote-chars=@var{string}
2717 Always quote characters from @var{string}, even if the selected
2718 quoting style would not quote them (@FIXME-pxref{Quoting Styles}).
2719
2720 @opindex quoting-style, summary
2721 @item --quoting-style=@var{style}
2722 Set quoting style to use when printing member and file names
2723 (@FIXME-pxref{Quoting Styles}). Valid @var{style} values are:
2724 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2725 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2726 style is @code{escape}, unless overridden while configuring the
2727 package.
2728
2729 @opindex pax-option, summary
2730 @item --pax-option=@var{keyword-list}
2731 @FIXME{Such a detailed description does not belong there, move it elsewhere.}
2732 This option is meaningful only with @acronym{POSIX.1-2001} archives
2733 (@pxref{posix}). It modifies the way @command{tar} handles the
2734 extended header keywords. @var{Keyword-list} is a comma-separated
2735 list of keyword options, each keyword option taking one of
2736 the following forms:
2737
2738 @table @asis
2739 @item delete=@var{pattern}
2740 When used with one of archive-creation commands,
2741 this option instructs @command{tar} to omit from extended header records
2742 that it produces any keywords matching the string @var{pattern}.
2743
2744 When used in extract or list mode, this option instructs tar
2745 to ignore any keywords matching the given @var{pattern} in the extended
2746 header records. In both cases, matching is performed using the pattern
2747 matching notation described in @acronym{POSIX 1003.2}, 3.13
2748 (See @cite{glob(7)}). For example:
2749
2750 @smallexample
2751 --pax-option delete=security.*
2752 @end smallexample
2753
2754 would suppress security-related information.
2755
2756 @item exthdr.name=@var{string}
2757
2758 This keyword allows user control over the name that is written into the
2759 ustar header blocks for the extended headers. The name is obtained
2760 from @var{string} after making the following substitutions:
2761
2762 @multitable @columnfractions .30 .70
2763 @headitem Meta-character @tab Replaced By
2764 @item %d @tab The directory name of the file, equivalent to the
2765 result of the @command{dirname} utility on the translated pathname.
2766 @item %f @tab The filename of the file, equivalent to the result
2767 of the @command{basename} utility on the translated pathname.
2768 @item %p @tab The process ID of the @command{tar} process.
2769 @item %% @tab A @samp{%} character.
2770 @end multitable
2771
2772 Any other @samp{%} characters in @var{string} produce undefined
2773 results.
2774
2775 If no option @samp{exthdr.name=string} is specified, @command{tar}
2776 will use the following default value:
2777
2778 @smallexample
2779 %d/PaxHeaders.%p/%f
2780 @end smallexample
2781
2782 @item globexthdr.name=@var{string}
2783 This keyword allows user control over the name that is written into
2784 the ustar header blocks for global extended header records. The name
2785 is obtained from the contents of @var{string}, after making
2786 the following substitutions:
2787
2788 @multitable @columnfractions .30 .70
2789 @headitem Meta-character @tab Replaced By
2790 @item %n @tab An integer that represents the
2791 sequence number of the global extended header record in the archive,
2792 starting at 1.
2793 @item %p @tab The process ID of the @command{tar} process.
2794 @item %% @tab A @samp{%} character.
2795 @end multitable
2796
2797 Any other @samp{%} characters in @var{string} produce undefined results.
2798
2799 If no option @samp{globexthdr.name=string} is specified, @command{tar}
2800 will use the following default value:
2801
2802 @smallexample
2803 $TMPDIR/GlobalHead.%p.%n
2804 @end smallexample
2805
2806 @noindent
2807 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
2808 environment variable. If @var{TMPDIR} is not set, @command{tar}
2809 uses @samp{/tmp}.
2810
2811 @item @var{keyword}=@var{value}
2812 When used with one of archive-creation commands, these keyword/value pairs
2813 will be included at the beginning of the archive in a global extended
2814 header record. When used with one of archive-reading commands,
2815 @command{tar} will behave as if it has encountered these keyword/value
2816 pairs at the beginning of the archive in a global extended header
2817 record.
2818
2819 @item @var{keyword}:=@var{value}
2820 When used with one of archive-creation commands, these keyword/value pairs
2821 will be included as records at the beginning of an extended header for
2822 each file. This is effectively equivalent to @var{keyword}=@var{value}
2823 form except that it creates no global extended header records.
2824
2825 When used with one of archive-reading commands, @command{tar} will
2826 behave as if these keyword/value pairs were included as records at the
2827 end of each extended header; thus, they will override any global or
2828 file-specific extended header record keywords of the same names.
2829 For example, in the command:
2830
2831 @smallexample
2832 tar --format=posix --create \
2833 --file archive --pax-option gname:=user .
2834 @end smallexample
2835
2836 the group name will be forced to a new value for all files
2837 stored in the archive.
2838 @end table
2839
2840 @opindex portability, summary
2841 @item --portability
2842 @itemx --old-archive
2843 Synonym for @option{--format=v7}.
2844
2845 @opindex posix, summary
2846 @item --posix
2847 Same as @option{--format=posix}.
2848
2849 @opindex preserve, summary
2850 @item --preserve
2851
2852 Synonymous with specifying both @option{--preserve-permissions} and
2853 @option{--same-order}. @xref{Setting Access Permissions}.
2854
2855 @opindex preserve-order, summary
2856 @item --preserve-order
2857
2858 (See @option{--same-order}; @pxref{Reading}.)
2859
2860 @opindex preserve-permissions, summary
2861 @opindex same-permissions, summary
2862 @item --preserve-permissions
2863 @itemx --same-permissions
2864 @itemx -p
2865
2866 When @command{tar} is extracting an archive, it normally subtracts the
2867 users' umask from the permissions specified in the archive and uses
2868 that number as the permissions to create the destination file.
2869 Specifying this option instructs @command{tar} that it should use the
2870 permissions directly from the archive. @xref{Setting Access Permissions}.
2871
2872 @opindex read-full-records, summary
2873 @item --read-full-records
2874 @itemx -B
2875
2876 Specifies that @command{tar} should reblock its input, for reading
2877 from pipes on systems with buggy implementations. @xref{Reading}.
2878
2879 @opindex record-size, summary
2880 @item --record-size=@var{size}
2881
2882 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2883 archive. @xref{Blocking Factor}.
2884
2885 @opindex recursion, summary
2886 @item --recursion
2887
2888 With this option, @command{tar} recurses into directories.
2889 @xref{recurse}.
2890
2891 @opindex recursive-unlink, summary
2892 @item --recursive-unlink
2893
2894 Remove existing
2895 directory hierarchies before extracting directories of the same name
2896 from the archive. @xref{Recursive Unlink}.
2897
2898 @opindex remove-files, summary
2899 @item --remove-files
2900
2901 Directs @command{tar} to remove the source file from the file system after
2902 appending it to an archive. @xref{remove files}.
2903
2904 @opindex restrict, summary
2905 @item --restrict
2906
2907 Disable use of some potentially harmful @command{tar} options.
2908 Currently this option disables shell invocaton from multi-volume menu
2909 (@pxref{Using Multiple Tapes}).
2910
2911 @opindex rmt-command, summary
2912 @item --rmt-command=@var{cmd}
2913
2914 Notifies @command{tar} that it should use @var{cmd} instead of
2915 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2916
2917 @opindex rsh-command, summary
2918 @item --rsh-command=@var{cmd}
2919
2920 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2921 devices. @xref{Device}.
2922
2923 @opindex same-order, summary
2924 @item --same-order
2925 @itemx --preserve-order
2926 @itemx -s
2927
2928 This option is an optimization for @command{tar} when running on machines with
2929 small amounts of memory. It informs @command{tar} that the list of file
2930 arguments has already been sorted to match the order of files in the
2931 archive. @xref{Reading}.
2932
2933 @opindex same-owner, summary
2934 @item --same-owner
2935
2936 When extracting an archive, @command{tar} will attempt to preserve the owner
2937 specified in the @command{tar} archive with this option present.
2938 This is the default behavior for the superuser; this option has an
2939 effect only for ordinary users. @xref{Attributes}.
2940
2941 @opindex same-permissions, summary
2942 @item --same-permissions
2943
2944 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
2945
2946 @opindex show-defaults, summary
2947 @item --show-defaults
2948
2949 Displays the default options used by @command{tar} and exits
2950 successfully. This option is intended for use in shell scripts.
2951 Here is an example of what you can see using this option:
2952
2953 @smallexample
2954 $ tar --show-defaults
2955 --format=gnu -f- -b20 --quoting-style=escape \
2956 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
2957 @end smallexample
2958
2959 @opindex show-omitted-dirs, summary
2960 @item --show-omitted-dirs
2961
2962 Instructs @command{tar} to mention directories its skipping over when
2963 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
2964
2965 @opindex show-stored-names, summary
2966 @item --show-stored-names
2967
2968 This option has effect only when used in conjunction with one of
2969 archive creation operations. It instructs tar to list the member names
2970 stored in the archive, as opposed to the actual file
2971 names. @xref{listing member and file names}.
2972
2973 @opindex sparse, summary
2974 @item --sparse
2975 @itemx -S
2976
2977 Invokes a @acronym{GNU} extension when adding files to an archive that handles
2978 sparse files efficiently. @xref{sparse}.
2979
2980 @opindex starting-file, summary
2981 @item --starting-file=@var{name}
2982 @itemx -K @var{name}
2983
2984 This option affects extraction only; @command{tar} will skip extracting
2985 files in the archive until it finds one that matches @var{name}.
2986 @xref{Scarce}.
2987
2988 @opindex strip-components, summary
2989 @item --strip-components=@var{number}
2990 Strip given @var{number} of leading components from file names before
2991 extraction.@footnote{This option was called @option{--strip-path} in
2992 version 1.14.} For example, if archive @file{archive.tar} contained
2993 @file{/some/file/name}, then running
2994
2995 @smallexample
2996 tar --extract --file archive.tar --strip-components=2
2997 @end smallexample
2998
2999 @noindent
3000 would extracted this file to file @file{name}.
3001
3002 @opindex suffix, summary
3003 @item --suffix=@var{suffix}
3004
3005 Alters the suffix @command{tar} uses when backing up files from the default
3006 @samp{~}. @xref{backup}.
3007
3008 @opindex tape-length, summary
3009 @item --tape-length=@var{num}
3010 @itemx -L @var{num}
3011
3012 Specifies the length of tapes that @command{tar} is writing as being
3013 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3014
3015 @opindex test-label, summary
3016 @item --test-label
3017
3018 Reads the volume label. If an argument is specified, test whether it
3019 matches the volume label. @xref{--test-label option}.
3020
3021 @opindex to-command, summary
3022 @item --to-command=@var{command}
3023
3024 During extraction @command{tar} will pipe extracted files to the
3025 standard input of @var{command}. @xref{Writing to an External Program}.
3026
3027 @opindex to-stdout, summary
3028 @item --to-stdout
3029 @itemx -O
3030
3031 During extraction, @command{tar} will extract files to stdout rather
3032 than to the file system. @xref{Writing to Standard Output}.
3033
3034 @opindex totals, summary
3035 @item --totals
3036
3037 Displays the total number of bytes written after creating an archive.
3038 @xref{verbose}.
3039
3040 @opindex touch, summary
3041 @item --touch
3042 @itemx -m
3043
3044 Sets the data modification time of extracted files to the extraction time,
3045 rather than the data modification time stored in the archive.
3046 @xref{Data Modification Times}.
3047
3048 @opindex uncompress, summary
3049 @item --uncompress
3050
3051 (See @option{--compress}. @pxref{gzip})
3052
3053 @opindex ungzip, summary
3054 @item --ungzip
3055
3056 (See @option{--gzip}. @pxref{gzip})
3057
3058 @opindex unlink-first, summary
3059 @item --unlink-first
3060 @itemx -U
3061
3062 Directs @command{tar} to remove the corresponding file from the file
3063 system before extracting it from the archive. @xref{Unlink First}.
3064
3065 @opindex use-compress-program, summary
3066 @item --use-compress-program=@var{prog}
3067
3068 Instructs @command{tar} to access the archive through @var{prog}, which is
3069 presumed to be a compression program of some sort. @xref{gzip}.
3070
3071 @opindex utc, summary
3072 @item --utc
3073
3074 Display file modification dates in @acronym{UTC}. This option implies
3075 @option{--verbose}.
3076
3077 @opindex verbose, summary
3078 @item --verbose
3079 @itemx -v
3080
3081 Specifies that @command{tar} should be more verbose about the operations its
3082 performing. This option can be specified multiple times for some
3083 operations to increase the amount of information displayed.
3084 @xref{verbose}.
3085
3086 @opindex verify, summary
3087 @item --verify
3088 @itemx -W
3089
3090 Verifies that the archive was correctly written when creating an
3091 archive. @xref{verify}.
3092
3093 @opindex version, summary
3094 @item --version
3095
3096 Print information about the program's name, version, origin and legal
3097 status, all on standard output, and then exit successfully.
3098 @xref{help}.
3099
3100 @opindex volno-file, summary
3101 @item --volno-file=@var{file}
3102
3103 Used in conjunction with @option{--multi-volume}. @command{tar} will keep track
3104 of which volume of a multi-volume archive its working in @var{file}.
3105 @xref{volno-file}.
3106
3107 @opindex wildcards, summary
3108 @item --wildcards
3109 Use wildcards when matching member names with patterns.
3110 @xref{controlling pattern-matching}.
3111
3112 @opindex wildcards-match-slash, summary
3113 @item --wildcards-match-slash
3114 Wildcards match @samp{/}.
3115 @xref{controlling pattern-matching}.
3116 @end table
3117
3118 @node Short Option Summary
3119 @subsection Short Options Cross Reference
3120
3121 Here is an alphabetized list of all of the short option forms, matching
3122 them with the equivalent long option.
3123
3124 @table @option
3125
3126 @item -A
3127
3128 @option{--concatenate}
3129
3130 @item -B
3131
3132 @option{--read-full-records}
3133
3134 @item -C
3135
3136 @option{--directory}
3137
3138 @item -F
3139
3140 @option{--info-script}
3141
3142 @item -G
3143
3144 @option{--incremental}
3145
3146 @item -K
3147
3148 @option{--starting-file}
3149
3150 @item -L
3151
3152 @option{--tape-length}
3153
3154 @item -M
3155
3156 @option{--multi-volume}
3157
3158 @item -N
3159
3160 @option{--newer}
3161
3162 @item -O
3163
3164 @option{--to-stdout}
3165
3166 @item -P
3167
3168 @option{--absolute-names}
3169
3170 @item -R
3171
3172 @option{--block-number}
3173
3174 @item -S
3175
3176 @option{--sparse}
3177
3178 @item -T
3179
3180 @option{--files-from}
3181
3182 @item -U
3183
3184 @option{--unlink-first}
3185
3186 @item -V
3187
3188 @option{--label}
3189
3190 @item -W
3191
3192 @option{--verify}
3193
3194 @item -X
3195
3196 @option{--exclude-from}
3197
3198 @item -Z
3199
3200 @option{--compress}
3201
3202 @item -b
3203
3204 @option{--blocking-factor}
3205
3206 @item -c
3207
3208 @option{--create}
3209
3210 @item -d
3211
3212 @option{--compare}
3213
3214 @item -f
3215
3216 @option{--file}
3217
3218 @item -g
3219
3220 @option{--listed-incremental}
3221
3222 @item -h
3223
3224 @option{--dereference}
3225
3226 @item -i
3227
3228 @option{--ignore-zeros}
3229
3230 @item -j
3231
3232 @option{--bzip2}
3233
3234 @item -k
3235
3236 @option{--keep-old-files}
3237
3238 @item -l
3239
3240 @option{--one-file-system}. Use of this short option is deprecated. It
3241 is retained for compatibility with the earlier versions of GNU
3242 @command{tar}, and will be changed in future releases.
3243
3244 @xref{Changes}, for more information.
3245
3246 @item -m
3247
3248 @option{--touch}
3249
3250 @item -o
3251
3252 When creating --- @option{--no-same-owner}, when extracting ---
3253 @option{--portability}.
3254
3255 The later usage is deprecated. It is retained for compatibility with
3256 the earlier versions of @GNUTAR{}. In the future releases
3257 @option{-o} will be equivalent to @option{--no-same-owner} only.
3258
3259 @item -p
3260
3261 @option{--preserve-permissions}
3262
3263 @item -r
3264
3265 @option{--append}
3266
3267 @item -s
3268
3269 @option{--same-order}
3270
3271 @item -t
3272
3273 @option{--list}
3274
3275 @item -u
3276
3277 @option{--update}
3278
3279 @item -v
3280
3281 @option{--verbose}
3282
3283 @item -w
3284
3285 @option{--interactive}
3286
3287 @item -x
3288
3289 @option{--extract}
3290
3291 @item -z
3292
3293 @option{--gzip}
3294
3295 @end table
3296
3297 @node help
3298 @section @GNUTAR{} documentation
3299
3300 @cindex Getting program version number
3301 @opindex version
3302 @cindex Version of the @command{tar} program
3303 Being careful, the first thing is really checking that you are using
3304 @GNUTAR{}, indeed. The @option{--version} option
3305 causes @command{tar} to print information about its name, version,
3306 origin and legal status, all on standard output, and then exit
3307 successfully. For example, @w{@samp{tar --version}} might print:
3308
3309 @smallexample
3310 tar (GNU tar) 1.15.2
3311 Copyright (C) 2006 Free Software Foundation, Inc.
3312 This is free software. You may redistribute copies of it under the terms of
3313 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3314 There is NO WARRANTY, to the extent permitted by law.
3315
3316 Written by John Gilmore and Jay Fenlason.
3317 @end smallexample
3318
3319 @noindent
3320 The first occurrence of @samp{tar} in the result above is the program
3321 name in the package (for example, @command{rmt} is another program),
3322 while the second occurrence of @samp{tar} is the name of the package
3323 itself, containing possibly many programs. The package is currently
3324 named @samp{tar}, after the name of the main program it
3325 contains@footnote{There are plans to merge the @command{cpio} and
3326 @command{tar} packages into a single one which would be called
3327 @code{paxutils}. So, who knows if, one of this days, the
3328 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3329 paxutils) 3.2}}}.
3330
3331 @cindex Obtaining help
3332 @cindex Listing all @command{tar} options
3333 @opindex help, introduction
3334 Another thing you might want to do is checking the spelling or meaning
3335 of some particular @command{tar} option, without resorting to this
3336 manual, for once you have carefully read it. @GNUTAR{}
3337 has a short help feature, triggerable through the
3338 @option{--help} option. By using this option, @command{tar} will
3339 print a usage message listing all available options on standard
3340 output, then exit successfully, without doing anything else and
3341 ignoring all other options. Even if this is only a brief summary, it
3342 may be several screens long. So, if you are not using some kind of
3343 scrollable window, you might prefer to use something like:
3344
3345 @smallexample
3346 $ @kbd{tar --help | less}
3347 @end smallexample
3348
3349 @noindent
3350 presuming, here, that you like using @command{less} for a pager. Other
3351 popular pagers are @command{more} and @command{pg}. If you know about some
3352 @var{keyword} which interests you and do not want to read all the
3353 @option{--help} output, another common idiom is doing:
3354
3355 @smallexample
3356 tar --help | grep @var{keyword}
3357 @end smallexample
3358
3359 @noindent
3360 for getting only the pertinent lines. Notice, however, that some
3361 @command{tar} options have long description lines and the above
3362 command will list only the first of them.
3363
3364 The exact look of the option summary displayed by @kbd{tar --help} is
3365 configurable. @xref{Configuring Help Summary}, for a detailed description.
3366
3367 @opindex usage
3368 If you only wish to check the spelling of an option, running @kbd{tar
3369 --usage} may be a better choice. This will display a terse list of
3370 @command{tar} option without accompanying explanations.
3371
3372 The short help output is quite succinct, and you might have to get
3373 back to the full documentation for precise points. If you are reading
3374 this paragraph, you already have the @command{tar} manual in some
3375 form. This manual is available in a variety of forms from
3376 @url{http://www.gnu.org/software/tar/manual}. It may printed out of the @GNUTAR{}
3377 distribution, provided you have @TeX{} already installed somewhere,
3378 and a laser printer around. Just configure the distribution, execute
3379 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3380 usual way (contact your local guru to know how). If @GNUTAR{}
3381 has been conveniently installed at your place, this
3382 manual is also available in interactive, hypertextual form as an Info
3383 file. Just call @w{@samp{info tar}} or, if you do not have the
3384 @command{info} program handy, use the Info reader provided within
3385 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3386
3387 There is currently no @code{man} page for @GNUTAR{}.
3388 If you observe such a @code{man} page on the system you are running,
3389 either it does not belong to @GNUTAR{}, or it has not
3390 been produced by @acronym{GNU}. Some package maintainers convert
3391 @kbd{tar --help} output to a man page, using @command{help2man}. In
3392 any case, please bear in mind that the authoritative source of
3393 information about @GNUTAR{} is this Texinfo documentation.
3394
3395 @node defaults
3396 @section Obtaining @GNUTAR{} default values
3397
3398 @opindex show-defaults
3399 @GNUTAR{} has some predefined defaults that are used when you do not
3400 explicitely specify another values. To obtain a list of such
3401 defaults, use @option{--show-defaults} option. This will output the
3402 values in the form of @command{tar} command line options:
3403
3404 @smallexample
3405 @group
3406 @kbd{tar --show-defaults}
3407 --format=gnu -f- -b20 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3408 @end group
3409 @end smallexample
3410
3411 @noindent
3412 The above output shows that this version of @GNUTAR{} defaults to
3413 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3414 output as the archive, if no @option{--file} option has been given
3415 (@pxref{file tutorial}), the default blocking factor is 20
3416 (@pxref{Blocking Factor}). It also shows the default locations where
3417 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3418
3419 @node verbose
3420 @section Checking @command{tar} progress
3421
3422 Typically, @command{tar} performs most operations without reporting any
3423 information to the user except error messages. When using @command{tar}
3424 with many options, particularly ones with complicated or
3425 difficult-to-predict behavior, it is possible to make serious mistakes.
3426 @command{tar} provides several options that make observing @command{tar}
3427 easier. These options cause @command{tar} to print information as it
3428 progresses in its job, and you might want to use them just for being
3429 more careful about what is going on, or merely for entertaining
3430 yourself. If you have encountered a problem when operating on an
3431 archive, however, you may need more information than just an error
3432 message in order to solve the problem. The following options can be
3433 helpful diagnostic tools.
3434
3435 @cindex Verbose operation
3436 @opindex verbose
3437 Normally, the @option{--list} (@option{-t}) command to list an archive
3438 prints just the file names (one per line) and the other commands are
3439 silent. When used with most operations, the @option{--verbose}
3440 (@option{-v}) option causes @command{tar} to print the name of each
3441 file or archive member as it is processed. This and the other options
3442 which make @command{tar} print status information can be useful in
3443 monitoring @command{tar}.
3444
3445 With @option{--create} or @option{--extract}, @option{--verbose} used
3446 once just prints the names of the files or members as they are processed.
3447 Using it twice causes @command{tar} to print a longer listing
3448 (reminiscent of @samp{ls -l}) for each member. Since @option{--list}
3449 already prints the names of the members, @option{--verbose} used once
3450 with @option{--list} causes @command{tar} to print an @samp{ls -l}
3451 type listing of the files in the archive. The following examples both
3452 extract members with long list output:
3453
3454 @smallexample
3455 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3456 $ @kbd{tar xvvf archive.tar}
3457 @end smallexample
3458
3459 Verbose output appears on the standard output except when an archive is
3460 being written to the standard output, as with @samp{tar --create
3461 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3462 installer let standard output be the default archive). In that case
3463 @command{tar} writes verbose output to the standard error stream.
3464
3465 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3466 verbose output to @var{file} rather than to standard output or standard
3467 error.
3468
3469 @cindex Obtaining total status information
3470 @opindex totals
3471 The @option{--totals} option---which is only meaningful when used with
3472 @option{--create} (@option{-c})---causes @command{tar} to print the total
3473 amount written to the archive, after it has been fully created.
3474
3475 @cindex Progress information
3476 @opindex checkpoint
3477 The @option{--checkpoint} option prints an occasional message
3478 as @command{tar} reads or writes the archive. In fact, it prints
3479 a message each 10 records read or written. It is designed for
3480 those who don't need the more detailed (and voluminous) output of
3481 @option{--block-number} (@option{-R}), but do want visual confirmation
3482 that @command{tar} is actually making forward progress.
3483
3484 @FIXME{There is some confusion here. It seems that -R once wrote a
3485 message at @samp{every} record read or written.}
3486
3487 @opindex show-omitted-dirs
3488 @anchor{show-omitted-dirs}
3489 The @option{--show-omitted-dirs} option, when reading an archive---with
3490 @option{--list} or @option{--extract}, for example---causes a message
3491 to be printed for each directory in the archive which is skipped.
3492 This happens regardless of the reason for skipping: the directory might
3493 not have been named on the command line (implicitly or explicitly),
3494 it might be excluded by the use of the @option{--exclude=@var{pattern}} option, or
3495 some other reason.
3496
3497 @opindex block-number
3498 @cindex Block number where error occurred
3499 @anchor{block-number}
3500 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3501 every message it would normally produce, the block number within the
3502 archive where the message was triggered. Also, supplementary messages
3503 are triggered when reading blocks full of NULs, or when hitting end of
3504 file on the archive. As of now, if the archive if properly terminated
3505 with a NUL block, the reading of the file may stop before end of file
3506 is met, so the position of end of file will not usually show when
3507 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3508 drains the archive before exiting when reading the
3509 archive from a pipe.
3510
3511 @cindex Error message, block number of
3512 This option is especially useful when reading damaged archives, since
3513 it helps pinpoint the damaged sections. It can also be used with
3514 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3515 choose among several backup tapes when retrieving a file later, in
3516 favor of the tape where the file appears earliest (closest to the
3517 front of the tape). @xref{backup}.
3518
3519 @node interactive
3520 @section Asking for Confirmation During Operations
3521 @cindex Interactive operation
3522
3523 Typically, @command{tar} carries out a command without stopping for
3524 further instructions. In some situations however, you may want to
3525 exclude some files and archive members from the operation (for instance
3526 if disk or storage space is tight). You can do this by excluding
3527 certain files automatically (@pxref{Choosing}), or by performing
3528 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3529 @command{tar} also accepts @option{--confirmation} for this option.
3530
3531 @opindex interactive
3532 When the @option{--interactive} (@option{-w}) option is specified, before
3533 reading, writing, or deleting files, @command{tar} first prints a message
3534 for each such file, telling what operation it intends to take, then asks
3535 for confirmation on the terminal. The actions which require
3536 confirmation include adding a file to the archive, extracting a file
3537 from the archive, deleting a file from the archive, and deleting a file
3538 from disk. To confirm the action, you must type a line of input
3539 beginning with @samp{y}. If your input line begins with anything other
3540 than @samp{y}, @command{tar} skips that file.
3541
3542 If @command{tar} is reading the archive from the standard input,
3543 @command{tar} opens the file @file{/dev/tty} to support the interactive
3544 communications.
3545
3546 Verbose output is normally sent to standard output, separate from
3547 other error messages. However, if the archive is produced directly
3548 on standard output, then verbose output is mixed with errors on
3549 @code{stderr}. Producing the archive on standard output may be used
3550 as a way to avoid using disk space, when the archive is soon to be
3551 consumed by another process reading it, say. Some people felt the need
3552 of producing an archive on stdout, still willing to segregate between
3553 verbose output and error output. A possible approach would be using a
3554 named pipe to receive the archive, and having the consumer process to
3555 read from that named pipe. This has the advantage of letting standard
3556 output free to receive verbose output, all separate from errors.
3557
3558 @node operations
3559 @chapter @GNUTAR{} Operations
3560
3561 @menu
3562 * Basic tar::
3563 * Advanced tar::
3564 * create options::
3565 * extract options::
3566 * backup::
3567 * Applications::
3568 * looking ahead::
3569 @end menu
3570
3571 @node Basic tar
3572 @section Basic @GNUTAR{} Operations
3573
3574 The basic @command{tar} operations, @option{--create} (@option{-c}),
3575 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3576 @option{-x}), are currently presented and described in the tutorial
3577 chapter of this manual. This section provides some complementary notes
3578 for these operations.
3579
3580 @table @option
3581 @opindex create, complementary notes
3582 @item --create
3583 @itemx -c
3584
3585 Creating an empty archive would have some kind of elegance. One can
3586 initialize an empty archive and later use @option{--append}
3587 (@option{-r}) for adding all members. Some applications would not
3588 welcome making an exception in the way of adding the first archive
3589 member. On the other hand, many people reported that it is
3590 dangerously too easy for @command{tar} to destroy a magnetic tape with
3591 an empty archive@footnote{This is well described in @cite{Unix-haters
3592 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3593 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3594
3595 @enumerate
3596 @item
3597 Mistakingly using @code{create} instead of @code{extract}, when the
3598 intent was to extract the full contents of an archive. This error
3599 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3600 the QWERTY keyboard. Instead of being unpacked, the archive then
3601 gets wholly destroyed. When users speak about @dfn{exploding} an
3602 archive, they usually mean something else :-).
3603
3604 @item
3605 Forgetting the argument to @code{file}, when the intent was to create
3606 an archive with a single file in it. This error is likely because a
3607 tired user can easily add the @kbd{f} key to the cluster of option
3608 letters, by the mere force of habit, without realizing the full
3609 consequence of doing so. The usual consequence is that the single
3610 file, which was meant to be saved, is rather destroyed.
3611 @end enumerate
3612
3613 So, recognizing the likelihood and the catastrophical nature of these
3614 errors, @GNUTAR{} now takes some distance from elegance, and
3615 cowardly refuses to create an archive when @option{--create} option is
3616 given, there are no arguments besides options, and
3617 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3618 around the cautiousness of @GNUTAR{} and nevertheless create an
3619 archive with nothing in it, one may still use, as the value for the
3620 @option{--files-from} option, a file with no names in it, as shown in
3621 the following commands:
3622
3623 @smallexample
3624 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3625 @kbd{tar cfT empty-archive.tar /dev/null}
3626 @end smallexample
3627
3628 @opindex extract, complementary notes
3629 @item --extract
3630 @itemx --get
3631 @itemx -x
3632
3633 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3634
3635 @item @option{--list} (@option{-t})
3636
3637 @GNUTAR{} now shows dates as @samp{1996-08-30},
3638 while it used to show them as @samp{Aug 30 1996}. Preferably,
3639 people should get used to ISO 8601 dates. Local American dates should
3640 be made available again with full date localization support, once
3641 ready. In the meantime, programs not being localizable for dates
3642 should prefer international dates, that's really the way to go.
3643
3644 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3645 are curious, it contains a detailed explanation of the ISO 8601 standard.
3646
3647 @end table
3648
3649 @node Advanced tar
3650 @section Advanced @GNUTAR{} Operations
3651
3652 Now that you have learned the basics of using @GNUTAR{}, you may want
3653 to learn about further ways in which @command{tar} can help you.
3654
3655 This chapter presents five, more advanced operations which you probably
3656 won't use on a daily basis, but which serve more specialized functions.
3657 We also explain the different styles of options and why you might want
3658 to use one or another, or a combination of them in your @command{tar}
3659 commands. Additionally, this chapter includes options which allow you to
3660 define the output from @command{tar} more carefully, and provide help and
3661 error correction in special circumstances.
3662
3663 @FIXME{check this after the chapter is actually revised to make sure
3664 it still introduces the info in the chapter correctly : ).}
3665
3666 @menu
3667 * Operations::
3668 * append::
3669 * update::
3670 * concatenate::
3671 * delete::
3672 * compare::
3673 @end menu
3674
3675 @node Operations
3676 @subsection The Five Advanced @command{tar} Operations
3677 @UNREVISED
3678
3679 In the last chapter, you learned about the first three operations to
3680 @command{tar}. This chapter presents the remaining five operations to
3681 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3682 @option{--delete}, and @option{--compare}.
3683
3684 You are not likely to use these operations as frequently as those
3685 covered in the last chapter; however, since they perform specialized
3686 functions, they are quite useful when you do need to use them. We
3687 will give examples using the same directory and files that you created
3688 in the last chapter. As you may recall, the directory is called
3689 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3690 @samp{rock}, and the two archive files you created are
3691 @samp{collection.tar} and @samp{music.tar}.
3692
3693 We will also use the archive files @samp{afiles.tar} and
3694 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3695 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3696 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3697
3698 Unless we state otherwise, all practicing you do and examples you follow
3699 in this chapter will take place in the @file{practice} directory that
3700 you created in the previous chapter; see @ref{prepare for examples}.
3701 (Below in this section, we will remind you of the state of the examples
3702 where the last chapter left them.)
3703
3704 The five operations that we will cover in this chapter are:
3705
3706 @table @option
3707 @item --append
3708 @itemx -r
3709 Add new entries to an archive that already exists.
3710 @item --update
3711 @itemx -r
3712 Add more recent copies of archive members to the end of an archive, if
3713 they exist.
3714 @item --concatenate
3715 @itemx --catenate
3716 @itemx -A
3717 Add one or more pre-existing archives to the end of another archive.
3718 @item --delete
3719 Delete items from an archive (does not work on tapes).
3720 @item --compare
3721 @itemx --diff
3722 @itemx -d
3723 Compare archive members to their counterparts in the file system.
3724 @end table
3725
3726 @node append
3727 @subsection How to Add Files to Existing Archives: @option{--append}
3728 @UNREVISED
3729
3730 @opindex append
3731 If you want to add files to an existing archive, you don't need to
3732 create a new archive; you can use @option{--append} (@option{-r}).
3733 The archive must already exist in order to use @option{--append}. (A
3734 related operation is the @option{--update} operation; you can use this
3735 to add newer versions of archive members to an existing archive. To learn how to
3736 do this with @option{--update}, @pxref{update}.)
3737
3738 If you use @option{--append} to add a file that has the same name as an
3739 archive member to an archive containing that archive member, then the
3740 old member is not deleted. What does happen, however, is somewhat
3741 complex. @command{tar} @emph{allows} you to have infinite number of files
3742 with the same name. Some operations treat these same-named members no
3743 differently than any other set of archive members: for example, if you
3744 view an archive with @option{--list} (@option{-t}), you will see all
3745 of those members listed, with their data modification times, owners, etc.
3746
3747 Other operations don't deal with these members as perfectly as you might
3748 prefer; if you were to use @option{--extract} to extract the archive,
3749 only the most recently added copy of a member with the same name as four
3750 other members would end up in the working directory. This is because
3751 @option{--extract} extracts an archive in the order the members appeared
3752 in the archive; the most recently archived members will be extracted
3753 last. Additionally, an extracted member will @emph{replace} a file of
3754 the same name which existed in the directory already, and @command{tar}
3755 will not prompt you about this@footnote{Unless you give it
3756 @option{--keep-old-files} option, or the disk copy is newer than the
3757 the one in the archive and you invoke @command{tar} with
3758 @option{--keep-newer-files} option}. Thus, only the most recently archived
3759 member will end up being extracted, as it will replace the one
3760 extracted before it, and so on.
3761
3762 There exists a special option that allows you to get around this
3763 behavior and extract (or list) only a particular copy of the file.
3764 This is @option{--occurrence} option. If you run @command{tar} with
3765 this option, it will extract only the first copy of the file. You
3766 may also give this option an argument specifying the number of
3767 copy to be extracted. Thus, for example if the archive
3768 @file{archive.tar} contained three copies of file @file{myfile}, then
3769 the command
3770
3771 @smallexample
3772 tar --extract --file archive.tar --occurrence=2 myfile
3773 @end smallexample
3774
3775 @noindent
3776 would extract only the second copy. @xref{Option
3777 Summary,---occurrence}, for the description of @option{--occurrence}
3778 option.
3779
3780 @FIXME{ hag -- you might want to incorporate some of the above into the
3781 MMwtSN node; not sure. i didn't know how to make it simpler...
3782
3783 There are a few ways to get around this. (maybe xref Multiple Members
3784 with the Same Name.}
3785
3786 @cindex Members, replacing with other members
3787 @cindex Replacing members with other members
3788 If you want to replace an archive member, use @option{--delete} to
3789 delete the member you want to remove from the archive, , and then use
3790 @option{--append} to add the member you want to be in the archive. Note
3791 that you can not change the order of the archive; the most recently
3792 added member will still appear last. In this sense, you cannot truly
3793 ``replace'' one member with another. (Replacing one member with another
3794 will not work on certain types of media, such as tapes; see @ref{delete}
3795 and @ref{Media}, for more information.)
3796
3797 @menu
3798 * appending files:: Appending Files to an Archive
3799 * multiple::
3800 @end menu
3801
3802 @node appending files
3803 @subsubsection Appending Files to an Archive
3804 @UNREVISED
3805 @cindex Adding files to an Archive
3806 @cindex Appending files to an Archive
3807 @cindex Archives, Appending files to
3808
3809 The simplest way to add a file to an already existing archive is the
3810 @option{--append} (@option{-r}) operation, which writes specified
3811 files into the archive whether or not they are already among the
3812 archived files.
3813
3814 When you use @option{--append}, you @emph{must} specify file name
3815 arguments, as there is no default. If you specify a file that already
3816 exists in the archive, another copy of the file will be added to the
3817 end of the archive. As with other operations, the member names of the
3818 newly added files will be exactly the same as their names given on the
3819 command line. The @option{--verbose} (@option{-v}) option will print
3820 out the names of the files as they are written into the archive.
3821
3822 @option{--append} cannot be performed on some tape drives, unfortunately,
3823 due to deficiencies in the formats those tape drives use. The archive
3824 must be a valid @command{tar} archive, or else the results of using this
3825 operation will be unpredictable. @xref{Media}.
3826
3827 To demonstrate using @option{--append} to add a file to an archive,
3828 create a file called @file{rock} in the @file{practice} directory.
3829 Make sure you are in the @file{practice} directory. Then, run the
3830 following @command{tar} command to add @file{rock} to
3831 @file{collection.tar}:
3832
3833 @smallexample
3834 $ @kbd{tar --append --file=collection.tar rock}
3835 @end smallexample
3836
3837 @noindent
3838 If you now use the @option{--list} (@option{-t}) operation, you will see that
3839 @file{rock} has been added to the archive:
3840
3841 @smallexample
3842 $ @kbd{tar --list --file=collection.tar}
3843 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3844 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3845 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3846 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3847 @end smallexample
3848
3849 @node multiple
3850 @subsubsection Multiple Files with the Same Name
3851
3852 You can use @option{--append} (@option{-r}) to add copies of files
3853 which have been updated since the archive was created. (However, we
3854 do not recommend doing this since there is another @command{tar}
3855 option called @option{--update}; @xref{update}, for more information.
3856 We describe this use of @option{--append} here for the sake of
3857 completeness.) When you extract the archive, the older version will
3858 be effectively lost. This works because files are extracted from an
3859 archive in the order in which they were archived. Thus, when the
3860 archive is extracted, a file archived later in time will replace a
3861 file of the same name which was archived earlier, even though the
3862 older version of the file will remain in the archive unless you delete
3863 all versions of the file.
3864
3865 Supposing you change the file @file{blues} and then append the changed
3866 version to @file{collection.tar}. As you saw above, the original
3867 @file{blues} is in the archive @file{collection.tar}. If you change the
3868 file and append the new version of the file to the archive, there will
3869 be two copies in the archive. When you extract the archive, the older
3870 version of the file will be extracted first, and then replaced by the
3871 newer version when it is extracted.
3872
3873 You can append the new, changed copy of the file @file{blues} to the
3874 archive in this way:
3875
3876 @smallexample
3877 $ @kbd{tar --append --verbose --file=collection.tar blues}
3878 blues
3879 @end smallexample
3880
3881 @noindent
3882 Because you specified the @option{--verbose} option, @command{tar} has
3883 printed the name of the file being appended as it was acted on. Now
3884 list the contents of the archive:
3885
3886 @smallexample
3887 $ @kbd{tar --list --verbose --file=collection.tar}
3888 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3889 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3890 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3891 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3892 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3893 @end smallexample
3894
3895 @noindent
3896 The newest version of @file{blues} is now at the end of the archive
3897 (note the different creation dates and file sizes). If you extract
3898 the archive, the older version of the file @file{blues} will be
3899 replaced by the newer version. You can confirm this by extracting
3900 the archive and running @samp{ls} on the directory.
3901
3902 If you wish to extract the first occurrence of the file @file{blues}
3903 from the archive, use @option{--occurrence} option, as shown in
3904 the following example:
3905
3906 @smallexample
3907 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3908 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3909 @end smallexample
3910
3911 @xref{Writing}, for more information on @option{--extract} and
3912 @xref{Option Summary, --occurrence}, for the description of
3913 @option{--occurrence} option.
3914
3915 @node update
3916 @subsection Updating an Archive
3917 @UNREVISED
3918 @cindex Updating an archive
3919
3920 @opindex update
3921 In the previous section, you learned how to use @option{--append} to
3922 add a file to an existing archive. A related operation is
3923 @option{--update} (@option{-u}). The @option{--update} operation
3924 updates a @command{tar} archive by comparing the date of the specified
3925 archive members against the date of the file with the same name. If
3926 the file has been modified more recently than the archive member, then
3927 the newer version of the file is added to the archive (as with
3928 @option{--append}).
3929
3930 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3931 The operation will fail.
3932
3933 @FIXME{other examples of media on which --update will fail? need to ask
3934 charles and/or mib/thomas/dave shevett..}
3935
3936 Both @option{--update} and @option{--append} work by adding to the end
3937 of the archive. When you extract a file from the archive, only the
3938 version stored last will wind up in the file system, unless you use
3939 the @option{--backup} option. @FIXME-ref{Multiple Members with the
3940 Same Name}
3941
3942 @menu
3943 * how to update::
3944 @end menu
3945
3946 @node how to update
3947 @subsubsection How to Update an Archive Using @option{--update}
3948
3949 You must use file name arguments with the @option{--update}
3950 (@option{-u}) operation. If you don't specify any files,
3951 @command{tar} won't act on any files and won't tell you that it didn't
3952 do anything (which may end up confusing you).
3953
3954 @c note: the above parenthetical added because in fact, this
3955 @c behavior just confused the author. :-)
3956
3957 To see the @option{--update} option at work, create a new file,
3958 @file{classical}, in your practice directory, and some extra text to the
3959 file @file{blues}, using any text editor. Then invoke @command{tar} with
3960 the @samp{update} operation and the @option{--verbose} (@option{-v})
3961 option specified, using the names of all the files in the practice
3962 directory as file name arguments:
3963
3964 @smallexample
3965 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
3966 blues
3967 classical
3968 $
3969 @end smallexample
3970
3971 @noindent
3972 Because we have specified verbose mode, @command{tar} prints out the names
3973 of the files it is working on, which in this case are the names of the
3974 files that needed to be updated. If you run @samp{tar --list} and look
3975 at the archive, you will see @file{blues} and @file{classical} at its
3976 end. There will be a total of two versions of the member @samp{blues};
3977 the one at the end will be newer and larger, since you added text before
3978 updating it.
3979
3980 (The reason @command{tar} does not overwrite the older file when updating
3981 it is because writing to the middle of a section of tape is a difficult
3982 process. Tapes are not designed to go backward. @xref{Media}, for more
3983 information about tapes.
3984
3985 @option{--update} (@option{-u}) is not suitable for performing backups for two
3986 reasons: it does not change directory content entries, and it
3987 lengthens the archive every time it is used. The @GNUTAR{}
3988 options intended specifically for backups are more
3989 efficient. If you need to run backups, please consult @ref{Backups}.
3990
3991 @node concatenate
3992 @subsection Combining Archives with @option{--concatenate}
3993
3994 @cindex Adding archives to an archive
3995 @cindex Concatenating Archives
3996 @opindex concatenate
3997 @opindex catenate
3998 @c @cindex @option{-A} described
3999 Sometimes it may be convenient to add a second archive onto the end of
4000 an archive rather than adding individual files to the archive. To add
4001 one or more archives to the end of another archive, you should use the
4002 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4003
4004 To use @option{--concatenate}, give the first archive with
4005 @option{--file} option and name the rest of archives to be
4006 concatenated on the command line. The members, and their member
4007 names, will be copied verbatim from those archives to the first one.
4008 @FIXME-ref{This can cause multiple members to have the same name, for
4009 information on how this affects reading the archive, Multiple
4010 Members with the Same Name.}
4011 The new, concatenated archive will be called by the same name as the
4012 one given with the @option{--file} option. As usual, if you omit
4013 @option{--file}, @command{tar} will use the value of the environment
4014 variable @env{TAPE}, or, if this has not been set, the default archive name.
4015
4016 @FIXME{There is no way to specify a new name...}
4017
4018 To demonstrate how @option{--concatenate} works, create two small archives
4019 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4020 files from @file{practice}:
4021
4022 @smallexample
4023 $ @kbd{tar -cvf bluesrock.tar blues rock}
4024 blues
4025 rock
4026 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4027 folk
4028 jazz
4029 @end smallexample
4030
4031 @noindent
4032 If you like, You can run @samp{tar --list} to make sure the archives
4033 contain what they are supposed to:
4034
4035 @smallexample
4036 $ @kbd{tar -tvf bluesrock.tar}
4037 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4038 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4039 $ @kbd{tar -tvf jazzfolk.tar}
4040 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4041 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4042 @end smallexample
4043
4044 We can concatenate these two archives with @command{tar}:
4045
4046 @smallexample
4047 $ @kbd{cd ..}
4048 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4049 @end smallexample
4050
4051 If you now list the contents of the @file{bluesrock.tar}, you will see
4052 that now it also contains the archive members of @file{jazzfolk.tar}:
4053
4054 @smallexample
4055 $ @kbd{tar --list --file=bluesrock.tar}
4056 blues
4057 rock
4058 folk
4059 jazz
4060 @end smallexample
4061
4062 When you use @option{--concatenate}, the source and target archives must
4063 already exist and must have been created using compatible format
4064 parameters. Notice, that @command{tar} does not check whether the
4065 archives it concatenates have compatible formats, it does not
4066 even check if the files are really tar archives.
4067
4068 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4069 tape drives, due to deficiencies in the formats those tape drives use.
4070
4071 @cindex @code{concatenate} vs @command{cat}
4072 @cindex @command{cat} vs @code{concatenate}
4073 It may seem more intuitive to you to want or try to use @command{cat} to
4074 concatenate two archives instead of using the @option{--concatenate}
4075 operation; after all, @command{cat} is the utility for combining files.
4076
4077 However, @command{tar} archives incorporate an end-of-file marker which
4078 must be removed if the concatenated archives are to be read properly as
4079 one archive. @option{--concatenate} removes the end-of-archive marker
4080 from the target archive before each new archive is appended. If you use
4081 @command{cat} to combine the archives, the result will not be a valid
4082 @command{tar} format archive. If you need to retrieve files from an
4083 archive that was added to using the @command{cat} utility, use the
4084 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4085 information on dealing with archives improperly combined using the
4086 @command{cat} shell utility.
4087
4088 @node delete
4089 @subsection Removing Archive Members Using @option{--delete}
4090 @UNREVISED
4091 @cindex Deleting files from an archive
4092 @cindex Removing files from an archive
4093
4094 @opindex delete
4095 You can remove members from an archive by using the @option{--delete}
4096 option. Specify the name of the archive with @option{--file}
4097 (@option{-f}) and then specify the names of the members to be deleted;
4098 if you list no member names, nothing will be deleted. The
4099 @option{--verbose} option will cause @command{tar} to print the names
4100 of the members as they are deleted. As with @option{--extract}, you
4101 must give the exact member names when using @samp{tar --delete}.
4102 @option{--delete} will remove all versions of the named file from the
4103 archive. The @option{--delete} operation can run very slowly.
4104
4105 Unlike other operations, @option{--delete} has no short form.
4106
4107 @cindex Tapes, using @option{--delete} and
4108 @cindex Deleting from tape archives
4109 This operation will rewrite the archive. You can only use
4110 @option{--delete} on an archive if the archive device allows you to
4111 write to any point on the media, such as a disk; because of this, it
4112 does not work on magnetic tapes. Do not try to delete an archive member
4113 from a magnetic tape; the action will not succeed, and you will be
4114 likely to scramble the archive and damage your tape. There is no safe
4115 way (except by completely re-writing the archive) to delete files from
4116 most kinds of magnetic tape. @xref{Media}.
4117
4118 To delete all versions of the file @file{blues} from the archive
4119 @file{collection.tar} in the @file{practice} directory, make sure you
4120 are in that directory, and then,
4121
4122 @smallexample
4123 $ @kbd{tar --list --file=collection.tar}
4124 blues
4125 folk
4126 jazz
4127 rock
4128 $ @kbd{tar --delete --file=collection.tar blues}
4129 $ @kbd{tar --list --file=collection.tar}
4130 folk
4131 jazz
4132 rock
4133 $
4134 @end smallexample
4135
4136 @FIXME{Check if the above listing is actually produced after running
4137 all the examples on collection.tar.}
4138
4139 The @option{--delete} option has been reported to work properly when
4140 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4141
4142 @node compare
4143 @subsection Comparing Archive Members with the File System
4144 @cindex Verifying the currency of an archive
4145 @UNREVISED
4146
4147 @opindex compare
4148 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4149 specified archive members against files with the same names, and then
4150 reports differences in file size, mode, owner, modification date and
4151 contents. You should @emph{only} specify archive member names, not file
4152 names. If you do not name any members, then @command{tar} will compare the
4153 entire archive. If a file is represented in the archive but does not
4154 exist in the file system, @command{tar} reports a difference.
4155
4156 You have to specify the record size of the archive when modifying an
4157 archive with a non-default record size.
4158
4159 @command{tar} ignores files in the file system that do not have
4160 corresponding members in the archive.
4161
4162 The following example compares the archive members @file{rock},
4163 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4164 files of the same name in the file system. (Note that there is no file,
4165 @file{funk}; @command{tar} will report an error message.)
4166
4167 @smallexample
4168 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4169 rock
4170 blues
4171 tar: funk not found in archive
4172 @end smallexample
4173
4174 The spirit behind the @option{--compare} (@option{--diff}, @option{-d}) option is to check whether the
4175 archive represents the current state of files on disk, more than validating
4176 the integrity of the archive media. For this later goal, @xref{verify}.
4177
4178 @node create options
4179 @section Options Used by @option{--create}
4180
4181 @opindex create, additional options
4182 The previous chapter described the basics of how to use
4183 @option{--create} (@option{-c}) to create an archive from a set of files.
4184 @xref{create}. This section described advanced options to be used with
4185 @option{--create}.
4186
4187 @menu
4188 * Ignore Failed Read::
4189 @end menu
4190
4191 @node Ignore Failed Read
4192 @subsection Ignore Fail Read
4193
4194 @table @option
4195 @item --ignore-failed-read
4196 Do not exit with nonzero on unreadable files or directories.
4197 @end table
4198
4199 @node extract options
4200 @section Options Used by @option{--extract}
4201 @UNREVISED
4202
4203 @opindex extract, additional options
4204 The previous chapter showed how to use @option{--extract} to extract
4205 an archive into the file system. Various options cause @command{tar} to
4206 extract more information than just file contents, such as the owner,
4207 the permissions, the modification date, and so forth. This section
4208 presents options to be used with @option{--extract} when certain special
4209 considerations arise. You may review the information presented in
4210 @ref{extract} for more basic information about the
4211 @option{--extract} operation.
4212
4213 @menu
4214 * Reading:: Options to Help Read Archives
4215 * Writing:: Changing How @command{tar} Writes Files
4216 * Scarce:: Coping with Scarce Resources
4217 @end menu
4218
4219 @node Reading
4220 @subsection Options to Help Read Archives
4221 @cindex Options when reading archives
4222 @UNREVISED
4223
4224 @cindex Reading incomplete records
4225 @cindex Records, incomplete
4226 @opindex read-full-records
4227 Normally, @command{tar} will request data in full record increments from
4228 an archive storage device. If the device cannot return a full record,
4229 @command{tar} will report an error. However, some devices do not always
4230 return full records, or do not require the last record of an archive to
4231 be padded out to the next record boundary. To keep reading until you
4232 obtain a full record, or to accept an incomplete record if it contains
4233 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4234 in conjunction with the @option{--extract} or @option{--list} operations.
4235 @xref{Blocking}.
4236
4237 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4238 @command{tar} reads an archive from standard input, or from a remote
4239 machine. This is because on BSD Unix systems, attempting to read a
4240 pipe returns however much happens to be in the pipe, even if it is
4241 less than was requested. If this option were not enabled, @command{tar}
4242 would fail as soon as it read an incomplete record from the pipe.
4243
4244 If you're not sure of the blocking factor of an archive, you can
4245 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4246 @option{--blocking-factor=@var{512-size}} (@option{-b
4247 @var{512-size}}), using a blocking factor larger than what the archive
4248 uses. This lets you avoid having to determine the blocking factor
4249 of an archive. @xref{Blocking Factor}.
4250
4251 @menu
4252 * read full records::
4253 * Ignore Zeros::
4254 @end menu
4255
4256 @node read full records
4257 @unnumberedsubsubsec Reading Full Records
4258
4259 @FIXME{need sentence or so of intro here}
4260
4261 @table @option
4262 @opindex read-full-records
4263 @item --read-full-records
4264 @item -B
4265 Use in conjunction with @option{--extract} (@option{--get},
4266 @option{-x}) to read an archive which contains incomplete records, or
4267 one which has a blocking factor less than the one specified.
4268 @end table
4269
4270 @node Ignore Zeros
4271 @unnumberedsubsubsec Ignoring Blocks of Zeros
4272
4273 @cindex End-of-archive blocks, ignoring
4274 @cindex Ignoring end-of-archive blocks
4275 @opindex ignore-zeros
4276 Normally, @command{tar} stops reading when it encounters a block of zeros
4277 between file entries (which usually indicates the end of the archive).
4278 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4279 completely read an archive which contains a block of zeros before the
4280 end (i.e., a damaged archive, or one that was created by concatenating
4281 several archives together).
4282
4283 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4284 versions of @command{tar} write garbage after the end-of-archive entry,
4285 since that part of the media is never supposed to be read. @GNUTAR{}
4286 does not write after the end of an archive, but seeks to
4287 maintain compatiblity among archiving utilities.
4288
4289 @table @option
4290 @item --ignore-zeros
4291 @itemx -i
4292 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4293 encountered while reading an archive. Use in conjunction with
4294 @option{--extract} or @option{--list}.
4295 @end table
4296
4297 @node Writing
4298 @subsection Changing How @command{tar} Writes Files
4299 @UNREVISED
4300
4301 @FIXME{Introductory paragraph}
4302
4303 @menu
4304 * Dealing with Old Files::
4305 * Overwrite Old Files::
4306 * Keep Old Files::
4307 * Keep Newer Files::
4308 * Unlink First::
4309 * Recursive Unlink::
4310 * Data Modification Times::
4311 * Setting Access Permissions::
4312 * Directory Modification Times and Permissions::
4313 * Writing to Standard Output::
4314 * Writing to an External Program::
4315 * remove files::
4316 @end menu
4317
4318 @node Dealing with Old Files
4319 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4320
4321 @opindex overwrite-dir, introduced
4322 When extracting files, if @command{tar} discovers that the extracted
4323 file already exists, it normally replaces the file by removing it before
4324 extracting it, to prevent confusion in the presence of hard or symbolic
4325 links. (If the existing file is a symbolic link, it is removed, not
4326 followed.) However, if a directory cannot be removed because it is
4327 nonempty, @command{tar} normally overwrites its metadata (ownership,
4328 permission, etc.). The @option{--overwrite-dir} option enables this
4329 default behavior. To be more cautious and preserve the metadata of
4330 such a directory, use the @option{--no-overwrite-dir} option.
4331
4332 @cindex Overwriting old files, prevention
4333 @opindex keep-old-files, introduced
4334 To be even more cautious and prevent existing files from being replaced, use
4335 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4336 to replace or update a file that already exists, i.e., a file with the
4337 same name as an archive member prevents extraction of that archive
4338 member. Instead, it reports an error.
4339
4340 @opindex overwrite, introduced
4341 To be more aggressive about altering existing files, use the
4342 @option{--overwrite} option. It causes @command{tar} to overwrite
4343 existing files and to follow existing symbolic links when extracting.
4344
4345 @cindex Protecting old files
4346 Some people argue that @GNUTAR{} should not hesitate
4347 to overwrite files with other files when extracting. When extracting
4348 a @command{tar} archive, they expect to see a faithful copy of the
4349 state of the file system when the archive was created. It is debatable
4350 that this would always be a proper behavior. For example, suppose one
4351 has an archive in which @file{usr/local} is a link to
4352 @file{usr/local2}. Since then, maybe the site removed the link and
4353 renamed the whole hierarchy from @file{/usr/local2} to
4354 @file{/usr/local}. Such things happen all the time. I guess it would
4355 not be welcome at all that @GNUTAR{} removes the
4356 whole hierarchy just to make room for the link to be reinstated
4357 (unless it @emph{also} simultaneously restores the full
4358 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4359 able to remove a whole hierarchy to reestablish a symbolic link, for
4360 example, but @emph{only if} @option{--recursive-unlink} is specified
4361 to allow this behavior. In any case, single files are silently
4362 removed.
4363
4364 @opindex unlink-first, introduced
4365 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4366 some cases by causing @command{tar} to remove files unconditionally
4367 before extracting them.
4368
4369 @node Overwrite Old Files
4370 @unnumberedsubsubsec Overwrite Old Files
4371
4372 @table @option
4373 @opindex overwrite
4374 @item --overwrite
4375 Overwrite existing files and directory metadata when extracting files
4376 from an archive.
4377
4378 This causes @command{tar} to write extracted files into the file system without
4379 regard to the files already on the system; i.e., files with the same
4380 names as archive members are overwritten when the archive is extracted.
4381 It also causes @command{tar} to extract the ownership, permissions,
4382 and time stamps onto any preexisting files or directories.
4383 If the name of a corresponding file name is a symbolic link, the file
4384 pointed to by the symbolic link will be overwritten instead of the
4385 symbolic link itself (if this is possible). Moreover, special devices,
4386 empty directories and even symbolic links are automatically removed if
4387 they are in the way of extraction.
4388
4389 Be careful when using the @option{--overwrite} option, particularly when
4390 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4391 can change the contents, ownership or permissions of any file on your
4392 system. Also, many systems do not take kindly to overwriting files that
4393 are currently being executed.
4394
4395 @opindex overwrite-dir
4396 @item --overwrite-dir
4397 Overwrite the metadata of directories when extracting files from an
4398 archive, but remove other files before extracting.
4399 @end table
4400
4401 @node Keep Old Files
4402 @unnumberedsubsubsec Keep Old Files
4403
4404 @table @option
4405 @opindex keep-old-files
4406 @item --keep-old-files
4407 @itemx -k
4408 Do not replace existing files from archive. The
4409 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4410 from replacing existing files with files with the same name from the
4411 archive. The @option{--keep-old-files} option is meaningless with
4412 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4413 files in the file system during extraction.
4414 @end table
4415
4416 @node Keep Newer Files
4417 @unnumberedsubsubsec Keep Newer Files
4418
4419 @table @option
4420 @opindex keep-newer-files
4421 @item --keep-newer-files
4422 Do not replace existing files that are newer than their archive
4423 copies. This option is meaningless with @option{--list} (@option{-t}).
4424 @end table
4425
4426 @node Unlink First
4427 @unnumberedsubsubsec Unlink First
4428
4429 @table @option
4430 @opindex unlink-first
4431 @item --unlink-first
4432 @itemx -U
4433 Remove files before extracting over them.
4434 This can make @command{tar} run a bit faster if you know in advance
4435 that the extracted files all need to be removed. Normally this option
4436 slows @command{tar} down slightly, so it is disabled by default.
4437 @end table
4438
4439 @node Recursive Unlink
4440 @unnumberedsubsubsec Recursive Unlink
4441
4442 @table @option
4443 @opindex recursive-unlink
4444 @item --recursive-unlink
4445 When this option is specified, try removing files and directory hierarchies
4446 before extracting over them. @emph{This is a dangerous option!}
4447 @end table
4448
4449 If you specify the @option{--recursive-unlink} option,
4450 @command{tar} removes @emph{anything} that keeps you from extracting a file
4451 as far as current permissions will allow it. This could include removal
4452 of the contents of a full directory hierarchy.
4453
4454 @node Data Modification Times
4455 @unnumberedsubsubsec Setting Data Modification Times
4456
4457 @cindex Data modification times of extracted files
4458 @cindex Modification times of extracted files
4459 Normally, @command{tar} sets the data modification times of extracted
4460 files to the corresponding times recorded for the files in the archive, but
4461 limits the permissions of extracted files by the current @code{umask}
4462 setting.
4463
4464 To set the data modification times of extracted files to the time when
4465 the files were extracted, use the @option{--touch} (@option{-m}) option in
4466 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4467
4468 @table @option
4469 @opindex touch
4470 @item --touch
4471 @itemx -m
4472 Sets the data modification time of extracted archive members to the time
4473 they were extracted, not the time recorded for them in the archive.
4474 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4475 @end table
4476
4477 @node Setting Access Permissions
4478 @unnumberedsubsubsec Setting Access Permissions
4479
4480 @cindex Permissions of extracted files
4481 @cindex Modes of extracted files
4482 To set the modes (access permissions) of extracted files to those
4483 recorded for those files in the archive, use @option{--same-permissions}
4484 in conjunction with the @option{--extract} (@option{--get},
4485 @option{-x}) operation.
4486
4487 @table @option
4488 @opindex preserve-permission
4489 @opindex same-permission
4490 @item --preserve-permission
4491 @itemx --same-permission
4492 @c @itemx --ignore-umask
4493 @itemx -p
4494 Set modes of extracted archive members to those recorded in the
4495 archive, instead of current umask settings. Use in conjunction with
4496 @option{--extract} (@option{--get}, @option{-x}).
4497 @end table
4498
4499 @node Directory Modification Times and Permissions
4500 @unnumberedsubsubsec Directory Modification Times and Permissions
4501
4502 After sucessfully extracting a file member, @GNUTAR{} normally
4503 restores its permissions and modification times, as described in the
4504 previous sections. This cannot be done for directories, because
4505 after extracting a directory @command{tar} will almost certainly
4506 extract files into that directory and this will cause the directory
4507 modification time to be updated. Moreover, restoring that directory
4508 permissions may not permit file creation within it. Thus, restoring
4509 directory permissions and modification times must be delayed at least
4510 until all files have been extracted into that directory. @GNUTAR{}
4511 restores directories using the following approach.
4512
4513 The extracted directories are created with the mode specified in the
4514 archive, as modified by the umask of the user, which gives sufficient
4515 permissions to allow file creation. The meta-information about the
4516 directory is recorded in the temporary list of directories. When
4517 preparing to extract next archive member, @GNUTAR{} checks if the
4518 directory prefix of this file contains the remembered directory. If
4519 it does not, the program assumes that all files have been extracted
4520 into that directory, restores its modification time and permissions
4521 and removes its entry from the internal list. This approach allows
4522 to correctly restore directory meta-information in the majority of
4523 cases, while keeping memory requirements sufficiently small. It is
4524 based on the fact, that most @command{tar} archives use the predefined
4525 order of members: first the directory, then all the files and
4526 subdirectories in that directory.
4527
4528 However, this is not always true. The most important exception are
4529 incremental archives (@pxref{Incremental Dumps}). The member order in
4530 an incremental archive is reversed: first all directory members are
4531 stored, followed by other (non-directory) members. So, when extracting
4532 from incremental archives, @GNUTAR{} alters the above procedure. It
4533 remebers all restored directories, and restores their meta-data
4534 only after the entire archive has been processed. Notice, that you do
4535 not need to specity any special options for that, as @GNUTAR{}
4536 automatically detects archives in incremental format.
4537
4538 There may be cases, when such processing is required for normal archives
4539 too. Consider the following example:
4540
4541 @smallexample
4542 @group
4543 $ @kbd{tar --no-recursion -cvf archive \
4544 foo foo/file1 bar bar/file foo/file2}
4545 foo/
4546 foo/file1
4547 bar/
4548 bar/file
4549 foo/file2
4550 @end group
4551 @end smallexample
4552
4553 During the normal operation, after encountering @file{bar}
4554 @GNUTAR{} will assume that all files from the directory @file{foo}
4555 were already extracted and will therefore restore its timestamp and
4556 permission bits. However, after extracting @file{foo/file2} the
4557 directory timestamp will be offset again.
4558
4559 To correctly restore directory meta-information in such cases, use
4560 @option{delay-directory-restore} command line option:
4561
4562 @table @option
4563 @opindex delay-directory-restore
4564 @item --delay-directory-restore
4565 Delays restoring of the modification times and permissions of extracted
4566 directories until the end of extraction. This way, correct
4567 meta-information is restored even if the archive has unusual member
4568 ordering.
4569
4570 @opindex no-delay-directory-restore
4571 @item --no-delay-directory-restore
4572 Cancel the effect of the previous @option{--delay-directory-restore}.
4573 Use this option if you have used @option{--delay-directory-restore} in
4574 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4575 temporarily disable it.
4576 @end table
4577
4578 @node Writing to Standard Output
4579 @unnumberedsubsubsec Writing to Standard Output
4580
4581 @cindex Writing extracted files to standard output
4582 @cindex Standard output, writing extracted files to
4583 To write the extracted files to the standard output, instead of
4584 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4585 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4586 extracting files to send them through a pipe, and do not need to
4587 preserve them in the file system. If you extract multiple members,
4588 they appear on standard output concatenated, in the order they are
4589 found in the archive.
4590
4591 @table @option
4592 @opindex to-stdout
4593 @item --to-stdout
4594 @itemx -O
4595 Writes files to the standard output. Use only in conjunction with
4596 @option{--extract} (@option{--get}, @option{-x}). When this option is
4597 used, instead of creating the files specified, @command{tar} writes
4598 the contents of the files extracted to its standard output. This may
4599 be useful if you are only extracting the files in order to send them
4600 through a pipe. This option is meaningless with @option{--list}
4601 (@option{-t}).
4602 @end table
4603
4604 This can be useful, for example, if you have a tar archive containing
4605 a big file and don't want to store the file on disk before processing
4606 it. You can use a command like this:
4607
4608 @smallexample
4609 tar -xOzf foo.tgz bigfile | process
4610 @end smallexample
4611
4612 or even like this if you want to process the concatenation of the files:
4613
4614 @smallexample
4615 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4616 @end smallexample
4617
4618 Hovewer, @option{--to-command} may be more convenient for use with
4619 multiple files. See the next section.
4620
4621 @node Writing to an External Program
4622 @unnumberedsubsubsec Writing to an External Program
4623
4624 You can instruct @command{tar} to send the contents of each extracted
4625 file to the standard input of an external program:
4626
4627 @table @option
4628 @opindex to-command
4629 @item --to-command=@var{command}
4630 Extract files and pipe their contents to the standard input of
4631 @var{command}. When this option is used, instead of creating the
4632 files specified, @command{tar} invokes @var{command} and pipes the
4633 contents of the files to its standard output. @var{Command} may
4634 contain command line arguments. The program is executed via
4635 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4636 extracted. Non-regular files (directories, etc.) are ignored when this
4637 option is used.
4638 @end table
4639
4640 The command can obtain the information about the file it processes
4641 from the following environment variables:
4642
4643 @table @var
4644 @vrindex TAR_FILETYPE, to-command environment
4645 @item TAR_FILETYPE
4646 Type of the file. It is a single letter with the following meaning:
4647
4648 @multitable @columnfractions 0.10 0.90
4649 @item f @tab Regular file
4650 @item d @tab Directory
4651 @item l @tab Symbolic link
4652 @item h @tab Hard link
4653 @item b @tab Block device
4654 @item c @tab Character device
4655 @end multitable
4656
4657 Currently only regular files are supported.
4658
4659 @vrindex TAR_MODE, to-command environment
4660 @item TAR_MODE
4661 File mode, an octal number.
4662
4663 @vrindex TAR_FILENAME, to-command environment
4664 @item TAR_FILENAME
4665 The name of the file.
4666
4667 @vrindex TAR_REALNAME, to-command environment
4668 @item TAR_REALNAME
4669 Name of the file as stored in the archive.
4670
4671 @vrindex TAR_UNAME, to-command environment
4672 @item TAR_UNAME
4673 Name of the file owner.
4674
4675 @vrindex TAR_GNAME, to-command environment
4676 @item TAR_GNAME
4677 Name of the file owner group.
4678
4679 @vrindex TAR_ATIME, to-command environment
4680 @item TAR_ATIME
4681 Time of last access. It is a decimal number, representing seconds
4682 since the epoch. If the archive provides times with nanosecond
4683 precision, the nanoseconds are appended to the timestamp after a
4684 decimal point.
4685
4686 @vrindex TAR_MTIME, to-command environment
4687 @item TAR_MTIME
4688 Time of last modification.
4689
4690 @vrindex TAR_CTIME, to-command environment
4691 @item TAR_CTIME
4692 Time of last status change.
4693
4694 @vrindex TAR_SIZE, to-command environment
4695 @item TAR_SIZE
4696 Size of the file.
4697
4698 @vrindex TAR_UID, to-command environment
4699 @item TAR_UID
4700 UID of the file owner.
4701
4702 @vrindex TAR_GID, to-command environment
4703 @item TAR_GID
4704 GID of the file owner.
4705 @end table
4706
4707 In addition to these variables, @env{TAR_VERSION} contains the
4708 @GNUTAR{} version number.
4709
4710 If @var{command} exits with a non-0 status, @command{tar} will print
4711 an error message similar to the following:
4712
4713 @smallexample
4714 tar: 2345: Child returned status 1
4715 @end smallexample
4716
4717 Here, @samp{2345} is the PID of the finished process.
4718
4719 If this behavior is not wanted, use @option{--ignore-command-error}:
4720
4721 @table @option
4722 @opindex ignore-command-error
4723 @item --ignore-command-error
4724 Ignore exit codes of subprocesses. Notice that if the program
4725 exits on signal or otherwise terminates abnormally, the error message
4726 will be printed even if this option is used.
4727
4728 @opindex no-ignore-command-error
4729 @item --no-ignore-command-error
4730 Cancel the effect of any previous @option{--ignore-command-error}
4731 option. This option is useful if you have set
4732 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4733 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4734 @end table
4735
4736 @node remove files
4737 @unnumberedsubsubsec Removing Files
4738
4739 @FIXME{The section is too terse. Something more to add? An example,
4740 maybe?}
4741
4742 @table @option
4743 @opindex remove-files
4744 @item --remove-files
4745 Remove files after adding them to the archive.
4746 @end table
4747
4748 @node Scarce
4749 @subsection Coping with Scarce Resources
4750 @UNREVISED
4751
4752 @cindex Small memory
4753 @cindex Running out of space
4754
4755 @menu
4756 * Starting File::
4757 * Same Order::
4758 @end menu
4759
4760 @node Starting File
4761 @unnumberedsubsubsec Starting File
4762
4763 @table @option
4764 @opindex starting-file
4765 @item --starting-file=@var{name}
4766 @itemx -K @var{name}
4767 Starts an operation in the middle of an archive. Use in conjunction
4768 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4769 @end table
4770
4771 @cindex Middle of the archive, starting in the
4772 If a previous attempt to extract files failed due to lack of disk
4773 space, you can use @option{--starting-file=@var{name}} (@option{-K
4774 @var{name}}) to start extracting only after member @var{name} of the
4775 archive. This assumes, of course, that there is now free space, or
4776 that you are now extracting into a different file system. (You could
4777 also choose to suspend @command{tar}, remove unnecessary files from
4778 the file system, and then restart the same @command{tar} operation.
4779 In this case, @option{--starting-file} is not necessary.
4780 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4781
4782 @node Same Order
4783 @unnumberedsubsubsec Same Order
4784
4785 @table @option
4786 @cindex Large lists of file names on small machines
4787 @opindex same-order
4788 @opindex preserve-order
4789 @item --same-order
4790 @itemx --preserve-order
4791 @itemx -s
4792 To process large lists of file names on machines with small amounts of
4793 memory. Use in conjunction with @option{--compare} (@option{--diff},
4794 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4795 (@option{--get}, @option{-x}).
4796 @end table
4797
4798 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4799 names to be listed or extracted is sorted in the same order as the
4800 files in the archive. This allows a large list of names to be used,
4801 even on a small machine that would not otherwise be able to hold all
4802 the names in memory at the same time. Such a sorted list can easily be
4803 created by running @samp{tar -t} on the archive and editing its output.
4804
4805 This option is probably never needed on modern computer systems.
4806
4807 @node backup
4808 @section Backup options
4809
4810 @cindex backup options
4811
4812 @GNUTAR{} offers options for making backups of files
4813 before writing new versions. These options control the details of
4814 these backups. They may apply to the archive itself before it is
4815 created or rewritten, as well as individual extracted members. Other
4816 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4817 and @command{mv}, for example) offer similar options.
4818
4819 Backup options may prove unexpectedly useful when extracting archives
4820 containing many members having identical name, or when extracting archives
4821 on systems having file name limitations, making different members appear
4822 has having similar names through the side-effect of name truncation.
4823 (This is true only if we have a good scheme for truncated backup names,
4824 which I'm not sure at all: I suspect work is needed in this area.)
4825 When any existing file is backed up before being overwritten by extraction,
4826 then clashing files are automatically be renamed to be unique, and the
4827 true name is kept for only the last file of a series of clashing files.
4828 By using verbose mode, users may track exactly what happens.
4829
4830 At the detail level, some decisions are still experimental, and may
4831 change in the future, we are waiting comments from our users. So, please
4832 do not learn to depend blindly on the details of the backup features.
4833 For example, currently, directories themselves are never renamed through
4834 using these options, so, extracting a file over a directory still has
4835 good chances to fail. Also, backup options apply to created archives,
4836 not only to extracted members. For created archives, backups will not
4837 be attempted when the archive is a block or character device, or when it
4838 refers to a remote file.
4839
4840 For the sake of simplicity and efficiency, backups are made by renaming old
4841 files prior to creation or extraction, and not by copying. The original
4842 name is restored if the file creation fails. If a failure occurs after a
4843 partial extraction of a file, both the backup and the partially extracted
4844 file are kept.
4845
4846 @table @samp
4847 @item --backup[=@var{method}]
4848 @opindex backup
4849 @vindex VERSION_CONTROL
4850 @cindex backups
4851 Back up files that are about to be overwritten or removed.
4852 Without this option, the original versions are destroyed.
4853
4854 Use @var{method} to determine the type of backups made.
4855 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
4856 environment variable. And if @env{VERSION_CONTROL} is not set,
4857 use the @samp{existing} method.
4858
4859 @vindex version-control @r{Emacs variable}
4860 This option corresponds to the Emacs variable @samp{version-control};
4861 the same values for @var{method} are accepted as in Emacs. This option
4862 also allows more descriptive names. The valid @var{method}s are:
4863
4864 @table @samp
4865 @item t
4866 @itemx numbered
4867 @cindex numbered @r{backup method}
4868 Always make numbered backups.
4869
4870 @item nil
4871 @itemx existing
4872 @cindex existing @r{backup method}
4873 Make numbered backups of files that already have them, simple backups
4874 of the others.
4875
4876 @item never
4877 @itemx simple
4878 @cindex simple @r{backup method}
4879 Always make simple backups.
4880
4881 @end table
4882
4883 @item --suffix=@var{suffix}
4884 @opindex suffix
4885 @cindex backup suffix
4886 @vindex SIMPLE_BACKUP_SUFFIX
4887 Append @var{suffix} to each backup file made with @option{--backup}. If this
4888 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
4889 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
4890 set, the default is @samp{~}, just as in Emacs.
4891
4892 @end table
4893
4894 Some people express the desire to @emph{always} use the @option{--backup}
4895 option, by defining some kind of alias or script. This is not as easy
4896 as one may think, due to the fact that old style options should appear first
4897 and consume arguments a bit unpredictably for an alias or script. But,
4898 if you are ready to give up using old style options, you may resort to
4899 using something like (a Bourne shell function here):
4900
4901 @smallexample
4902 tar () @{ /usr/local/bin/tar --backup $*; @}
4903 @end smallexample
4904
4905 @node Applications
4906 @section Notable @command{tar} Usages
4907 @UNREVISED
4908
4909 @FIXME{Using Unix file linking capability to recreate directory
4910 structures---linking files into one subdirectory and then
4911 @command{tar}ring that directory.}
4912
4913 @FIXME{Nice hairy example using absolute-names, newer, etc.}
4914
4915 @findex uuencode
4916 You can easily use archive files to transport a group of files from
4917 one system to another: put all relevant files into an archive on one
4918 computer system, transfer the archive to another system, and extract
4919 the contents there. The basic transfer medium might be magnetic tape,
4920 Internet FTP, or even electronic mail (though you must encode the
4921 archive with @command{uuencode} in order to transport it properly by
4922 mail). Both machines do not have to use the same operating system, as
4923 long as they both support the @command{tar} program.
4924
4925 For example, here is how you might copy a directory's contents from
4926 one disk to another, while preserving the dates, modes, owners and
4927 link-structure of all the files therein. In this case, the transfer
4928 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
4929
4930 @smallexample
4931 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
4932 @end smallexample
4933
4934 @noindent
4935 You can avoid subshells by using @option{-C} option:
4936
4937 @smallexample
4938 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
4939 @end smallexample
4940
4941 @noindent
4942 The command also works using short option forms:
4943
4944 @smallexample
4945 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
4946 | (cd targetdir; tar --extract --file=-)}
4947 # Or:
4948 $ @kbd{tar --directory sourcedir --create --file=- . ) \
4949 | tar --directory targetdir --extract --file=-}
4950 @end smallexample
4951
4952 @noindent
4953 This is one of the easiest methods to transfer a @command{tar} archive.
4954
4955 @node looking ahead
4956 @section Looking Ahead: The Rest of this Manual
4957
4958 You have now seen how to use all eight of the operations available to
4959 @command{tar}, and a number of the possible options. The next chapter
4960 explains how to choose and change file and archive names, how to use
4961 files to store names of other files which you can then call as
4962 arguments to @command{tar} (this can help you save time if you expect to
4963 archive the same list of files a number of times), and so forth.
4964 @FIXME{in case it's not obvious, i'm making this up in some sense
4965 based on my limited memory of what the next chapter *really* does. i
4966 just wanted to flesh out this final section a little bit so i'd
4967 remember to stick it in here. :-)}
4968
4969 If there are too many files to conveniently list on the command line,
4970 you can list the names in a file, and @command{tar} will read that file.
4971 @xref{files}.
4972
4973 There are various ways of causing @command{tar} to skip over some files,
4974 and not archive them. @xref{Choosing}.
4975
4976 @node Backups
4977 @chapter Performing Backups and Restoring Files
4978 @UNREVISED
4979
4980 @GNUTAR{} is distributed along with the scripts
4981 which the Free Software Foundation uses for performing backups. There
4982 is no corresponding scripts available yet for doing restoration of
4983 files. Even if there is a good chance those scripts may be satisfying
4984 to you, they are not the only scripts or methods available for doing
4985 backups and restore. You may well create your own, or use more
4986 sophisticated packages dedicated to that purpose.
4987
4988 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
4989 Automatic Network Disk Archiver), a backup system developed by James
4990 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
4991 This is free software, and it is available at these places:
4992
4993 @smallexample
4994 http://www.cs.umd.edu/projects/amanda/amanda.html
4995 ftp://ftp.cs.umd.edu/pub/amanda
4996 @end smallexample
4997
4998 @FIXME{
4999
5000 Here is a possible plan for a future documentation about the backuping
5001 scripts which are provided within the @GNUTAR{}
5002 distribution.
5003
5004 @itemize @bullet
5005 @item dumps
5006 @itemize @minus
5007 @item what are dumps
5008 @item different levels of dumps
5009 @itemize +
5010 @item full dump = dump everything
5011 @item level 1, level 2 dumps etc
5012 A level @var{n} dump dumps everything changed since the last level
5013 @var{n}-1 dump (?)
5014 @end itemize
5015 @item how to use scripts for dumps (ie, the concept)
5016 @itemize +
5017 @item scripts to run after editing backup specs (details)
5018 @end itemize
5019 @item Backup Specs, what is it.
5020 @itemize +
5021 @item how to customize
5022 @item actual text of script [/sp/dump/backup-specs]
5023 @end itemize
5024 @item Problems
5025 @itemize +
5026 @item rsh doesn't work
5027 @item rtape isn't installed
5028 @item (others?)
5029 @end itemize
5030 @item the @option{--incremental} option of tar
5031 @item tapes
5032 @itemize +
5033 @item write protection
5034 @item types of media, different sizes and types, useful for different things
5035 @item files and tape marks
5036 one tape mark between files, two at end.
5037 @item positioning the tape
5038 MT writes two at end of write,
5039 backspaces over one when writing again.
5040 @end itemize
5041 @end itemize
5042 @end itemize
5043 }
5044
5045 This chapter documents both the provided shell scripts and @command{tar}
5046 options which are more specific to usage as a backup tool.
5047
5048 To @dfn{back up} a file system means to create archives that contain
5049 all the files in that file system. Those archives can then be used to
5050 restore any or all of those files (for instance if a disk crashes or a
5051 file is accidentally deleted). File system @dfn{backups} are also
5052 called @dfn{dumps}.
5053
5054 @menu
5055 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5056 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5057 * Backup Levels:: Levels of Backups
5058 * Backup Parameters:: Setting Parameters for Backups and Restoration
5059 * Scripted Backups:: Using the Backup Scripts
5060 * Scripted Restoration:: Using the Restore Script
5061 @end menu
5062
5063 @node Full Dumps
5064 @section Using @command{tar} to Perform Full Dumps
5065 @UNREVISED
5066
5067 @cindex full dumps
5068 @cindex dumps, full
5069
5070 @cindex corrupted archives
5071 Full dumps should only be made when no other people or programs
5072 are modifying files in the file system. If files are modified while
5073 @command{tar} is making the backup, they may not be stored properly in
5074 the archive, in which case you won't be able to restore them if you
5075 have to. (Files not being modified are written with no trouble, and do
5076 not corrupt the entire archive.)
5077
5078 You will want to use the @option{--label=@var{archive-label}}
5079 (@option{-V @var{archive-label}}) option to give the archive a
5080 volume label, so you can tell what this archive is even if the label
5081 falls off the tape, or anything like that.
5082
5083 Unless the file system you are dumping is guaranteed to fit on
5084 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5085 Make sure you have enough tapes on hand to complete the backup.
5086
5087 If you want to dump each file system separately you will need to use
5088 the @option{--one-file-system} option to prevent
5089 @command{tar} from crossing file system boundaries when storing
5090 (sub)directories.
5091
5092 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5093 option is not needed, since this is a complete copy of everything in
5094 the file system, and a full restore from this backup would only be
5095 done onto a completely
5096 empty disk.
5097
5098 Unless you are in a hurry, and trust the @command{tar} program (and your
5099 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5100 option, to make sure your files really made it onto the dump properly.
5101 This will also detect cases where the file was modified while (or just
5102 after) it was being archived. Not all media (notably cartridge tapes)
5103 are capable of being verified, unfortunately.
5104
5105 @node Incremental Dumps
5106 @section Using @command{tar} to Perform Incremental Dumps
5107
5108 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5109 stores additional metadata so that exact state of the file system
5110 can be restored when extracting the archive.
5111
5112 @GNUTAR{} currently offers two options for handling incremental
5113 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5114 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5115
5116 @opindex listed-incremental
5117 The option @option{--listed-incremental} instructs tar to operate on
5118 an incremental archive with additional metadata stored in a standalone
5119 file, called a @dfn{snapshot file}. The purpose of this file is to help
5120 determine which files have been changed, added or deleted since the
5121 last backup, so that the next incremental backup will contain only
5122 modified files. The name of the snapshot file is given as an argument
5123 to the option:
5124
5125 @table @option
5126 @item --listed-incremental=@var{file}
5127 @itemx -g @var{file}
5128 Handle incremental backups with snapshot data in @var{file}.
5129 @end table
5130
5131 To create an incremental backup, you would use
5132 @option{--listed-incremental} together with @option{--create}
5133 (@pxref{create}). For example:
5134
5135 @smallexample
5136 $ @kbd{tar --create \
5137 --file=archive.1.tar \
5138 --listed-incremental=/var/log/usr.snar \
5139 /usr}
5140 @end smallexample
5141
5142 This will create in @file{archive.1.tar} an incremental backup of
5143 the @file{/usr} file system, storing additional metadata in the file
5144 @file{/var/log/usr.snar}. If this file does not exist, it will be
5145 created. The created archive will then be a @dfn{level 0 backup};
5146 please see the next section for more on backup levels.
5147
5148 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5149 determines which files are modified. In this case only these files will be
5150 stored in the archive. Suppose, for example, that after running the
5151 above command, you delete file @file{/usr/doc/old} and create
5152 directory @file{/usr/local/db} with the following contents:
5153
5154 @smallexample
5155 $ @kbd{ls /usr/local/db}
5156 /usr/local/db/data
5157 /usr/local/db/index
5158 @end smallexample
5159
5160 Some time later you create another incremental backup. You will
5161 then see:
5162
5163 @smallexample
5164 $ @kbd{tar --create \
5165 --file=archive.2.tar \
5166 --listed-incremental=/var/log/usr.snar \
5167 /usr}
5168 tar: usr/local/db: Directory is new
5169 usr/local/db/
5170 usr/local/db/data
5171 usr/local/db/index
5172 @end smallexample
5173
5174 @noindent
5175 The created archive @file{archive.2.tar} will contain only these
5176 three members. This archive is called a @dfn{level 1 backup}. Notice
5177 that @file{/var/log/usr.snar} will be updated with the new data, so if
5178 you plan to create more @samp{level 1} backups, it is necessary to
5179 create a working copy of the snapshot file before running
5180 @command{tar}. The above example will then be modified as follows:
5181
5182 @smallexample
5183 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5184 $ @kbd{tar --create \
5185 --file=archive.2.tar \
5186 --listed-incremental=/var/log/usr.snar-1 \
5187 /usr}
5188 @end smallexample
5189
5190 Incremental dumps depend crucially on time stamps, so the results are
5191 unreliable if you modify a file's time stamps during dumping (e.g.,
5192 with the @option{--atime-preserve=replace} option), or if you set the clock
5193 backwards.
5194
5195 Metadata stored in snapshot files include device numbers, which,
5196 obviously is supposed to be a non-volatile value. However, it turns
5197 out that NFS devices have undependable values when an automounter
5198 gets in the picture. This can lead to a great deal of spurious
5199 redumping in incremental dumps, so it is somewhat useless to compare
5200 two NFS devices numbers over time. The solution implemented currently
5201 is to considers all NFS devices as being equal when it comes to
5202 comparing directories; this is fairly gross, but there does not seem
5203 to be a better way to go.
5204
5205 Note that incremental archives use @command{tar} extensions and may
5206 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5207
5208 @opindex listed-incremental, using with @option{--extract}
5209 @opindex extract, using with @option{--listed-incremental}
5210 To extract from the incremental dumps, use
5211 @option{--listed-incremental} together with @option{--extract}
5212 option (@pxref{extracting files}). In this case, @command{tar} does
5213 not need to access snapshot file, since all the data necessary for
5214 extraction are stored in the archive itself. So, when extracting, you
5215 can give whatever argument to @option{--listed-incremental}, the usual
5216 practice is to use @option{--listed-incremental=/dev/null}.
5217 Alternatively, you can use @option{--incremental}, which needs no
5218 arguments. In general, @option{--incremental} (@option{-G}) can be
5219 used as a shortcut for @option{--listed-incremental} when listing or
5220 extracting incremental backups (for more information, regarding this
5221 option, @pxref{incremental-op}).
5222
5223 When extracting from the incremental backup @GNUTAR{} attempts to
5224 restore the exact state the file system had when the archive was
5225 created. In particular, it will @emph{delete} those files in the file
5226 system that did not exist in their directories when the archive was
5227 created. If you have created several levels of incremental files,
5228 then in order to restore the exact contents the file system had when
5229 the last level was created, you will need to restore from all backups
5230 in turn. Continuing our example, to restore the state of @file{/usr}
5231 file system, one would do@footnote{Notice, that since both archives
5232 were created withouth @option{-P} option (@pxref{absolute}), these
5233 commands should be run from the root file system.}:
5234
5235 @smallexample
5236 $ @kbd{tar --extract \
5237 --listed-incremental=/dev/null \
5238 --file archive.1.tar}
5239 $ @kbd{tar --extract \
5240 --listed-incremental=/dev/null \
5241 --file archive.2.tar}
5242 @end smallexample
5243
5244 To list the contents of an incremental archive, use @option{--list}
5245 (@pxref{list}), as usual. To obtain more information about the
5246 archive, use @option{--listed-incremental} or @option{--incremental}
5247 combined with two @option{--verbose} options@footnote{Two
5248 @option{--verbose} options were selected to avoid breaking usual
5249 verbose listing output (@option{--list --verbose}) when using in
5250 scripts.
5251
5252 @opindex incremental, using with @option{--list}
5253 @opindex listed-incremental, using with @option{--list}
5254 @opindex list, using with @option{--incremental}
5255 @opindex list, using with @option{--listed-incremental}
5256 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5257 contents of the DUMPDIR header (with terminating nulls) when
5258 @option{--incremental} or @option{--listed-incremental} option was
5259 given, no matter what the verbosity level. This behavior, and,
5260 especially, the binary output it produced were considered incovenient
5261 and were changed in version 1.16}:
5262
5263 @smallexample
5264 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5265 @end smallexample
5266
5267 This command will print, for each directory in the archive, the list
5268 of files in that directory at the time the archive was created. This
5269 information is put out in a format which is both human-readable and
5270 unambiguous for a program: each file name is printed as
5271
5272 @smallexample
5273 @var{x} @var{file}
5274 @end smallexample
5275
5276 @noindent
5277 where @var{x} is a letter describing the status of the file: @samp{Y}
5278 if the file is present in the archive, @samp{N} if the file is not
5279 included in the archive, or a @samp{D} if the file is a directory (and
5280 is included in the archive).@FIXME-xref{dumpdir format}. Each such
5281 line is terminated by a newline character. The last line is followed
5282 by an additional newline to indicate the end of the data.
5283
5284 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5285 gives the same behavior as @option{--listed-incremental} when used
5286 with @option{--list} and @option{--extract} options. When used with
5287 @option{--create} option, it creates an incremental archive without
5288 creating snapshot file. Thus, it is impossible to create several
5289 levels of incremental backups with @option{--incremental} option.
5290
5291 @node Backup Levels
5292 @section Levels of Backups
5293
5294 An archive containing all the files in the file system is called a
5295 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5296 creating a full dump every day. This strategy, however, would waste a
5297 substantial amount of archive media and user time, as unchanged files
5298 are daily re-archived.
5299
5300 It is more efficient to do a full dump only occasionally. To back up
5301 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5302 one} dump archives all the files that have changed since the last full
5303 dump.
5304
5305 A typical dump strategy would be to perform a full dump once a week,
5306 and a level one dump once a day. This means some versions of files
5307 will in fact be archived more than once, but this dump strategy makes
5308 it possible to restore a file system to within one day of accuracy by
5309 only extracting two archives---the last weekly (full) dump and the
5310 last daily (level one) dump. The only information lost would be in
5311 files changed or created since the last daily backup. (Doing dumps
5312 more than once a day is usually not worth the trouble).
5313
5314 @GNUTAR{} comes with scripts you can use to do full
5315 and level-one (actually, even level-two and so on) dumps. Using
5316 scripts (shell programs) to perform backups and restoration is a
5317 convenient and reliable alternative to typing out file name lists
5318 and @command{tar} commands by hand.
5319
5320 Before you use these scripts, you need to edit the file
5321 @file{backup-specs}, which specifies parameters used by the backup
5322 scripts and by the restore script. This file is usually located
5323 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5324 detailed description. Once the backup parameters are set, you can
5325 perform backups or restoration by running the appropriate script.
5326
5327 The name of the backup script is @code{backup}. The name of the
5328 restore script is @code{restore}. The following sections describe
5329 their use in detail.
5330
5331 @emph{Please Note:} The backup and restoration scripts are
5332 designed to be used together. While it is possible to restore files by
5333 hand from an archive which was created using a backup script, and to create
5334 an archive by hand which could then be extracted using the restore script,
5335 it is easier to use the scripts. @xref{Incremental Dumps}, before
5336 making such an attempt.
5337
5338 @node Backup Parameters
5339 @section Setting Parameters for Backups and Restoration
5340
5341 The file @file{backup-specs} specifies backup parameters for the
5342 backup and restoration scripts provided with @command{tar}. You must
5343 edit @file{backup-specs} to fit your system configuration and schedule
5344 before using these scripts.
5345
5346 Syntactically, @file{backup-specs} is a shell script, containing
5347 mainly variable assignments. However, any valid shell construct
5348 is allowed in this file. Particularly, you may wish to define
5349 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5350 For more information about shell script syntax, please refer to
5351 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5352 g_02, the definition of the Shell Command Language}. See also
5353 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5354
5355 The shell variables controlling behavior of @code{backup} and
5356 @code{restore} are described in the following subsections.
5357
5358 @menu
5359 * General-Purpose Variables::
5360 * Magnetic Tape Control::
5361 * User Hooks::
5362 * backup-specs example:: An Example Text of @file{Backup-specs}
5363 @end menu
5364
5365 @node General-Purpose Variables
5366 @subsection General-Purpose Variables
5367
5368 @defvr {Backup variable} ADMINISTRATOR
5369 The user name of the backup administrator. @code{Backup} scripts
5370 sends a backup report to this address.
5371 @end defvr
5372
5373 @defvr {Backup variable} BACKUP_HOUR
5374 The hour at which the backups are done. This can be a number from 0
5375 to 23, or the time specification in form @var{hours}:@var{minutes},
5376 or the string @samp{now}.
5377
5378 This variable is used by @code{backup}. Its value may be overridden
5379 using @option{--time} option (@pxref{Scripted Backups}).
5380 @end defvr
5381
5382 @defvr {Backup variable} TAPE_FILE
5383
5384 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5385 is a remote archive (@pxref{remote-dev}), backup script will suppose
5386 that your @command{mt} is able to access remote devices. If @var{RSH}
5387 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5388 invocations of @command{mt}.
5389 @end defvr
5390
5391 @defvr {Backup variable} BLOCKING
5392
5393 The blocking factor @command{tar} will use when writing the dump archive.
5394 @xref{Blocking Factor}.
5395 @end defvr
5396
5397 @defvr {Backup variable} BACKUP_DIRS
5398
5399 A list of file systems to be dumped (for @code{backup}), or restored
5400 (for @code{restore}). You can include any directory
5401 name in the list --- subdirectories on that file system will be
5402 included, regardless of how they may look to other networked machines.
5403 Subdirectories on other file systems will be ignored.
5404
5405 The host name specifies which host to run @command{tar} on, and should
5406 normally be the host that actually contains the file system. However,
5407 the host machine must have @GNUTAR{} installed, and
5408 must be able to access the directory containing the backup scripts and
5409 their support files using the same file name that is used on the
5410 machine where the scripts are run (ie. what @command{pwd} will print
5411 when in that directory on that machine). If the host that contains
5412 the file system does not have this capability, you can specify another
5413 host as long as it can access the file system through NFS.
5414
5415 If the list of file systems is very long you may wish to put it
5416 in a separate file. This file is usually named
5417 @file{/etc/backup/dirs}, but this name may be overridden in
5418 @file{backup-specs} using @code{DIRLIST} variable.
5419 @end defvr
5420
5421 @defvr {Backup variable} DIRLIST
5422
5423 A path to the file containing the list of the file systems to backup
5424 or restore. By default it is @file{/etc/backup/dirs}.
5425 @end defvr
5426
5427 @defvr {Backup variable} BACKUP_FILES
5428
5429 A list of individual files to be dumped (for @code{backup}), or restored
5430 (for @code{restore}). These should be accessible from the machine on
5431 which the backup script is run.
5432
5433 If the list of file systems is very long you may wish to store it
5434 in a separate file. This file is usually named
5435 @file{/etc/backup/files}, but this name may be overridden in
5436 @file{backup-specs} using @code{FILELIST} variable.
5437 @end defvr
5438
5439 @defvr {Backup variable} FILELIST
5440
5441 A path to the file containing the list of the individual files to backup
5442 or restore. By default it is @file{/etc/backup/files}.
5443 @end defvr
5444
5445 @defvr {Backup variable} MT
5446
5447 Full file name of @command{mt} binary.
5448 @end defvr
5449
5450 @defvr {Backup variable} RSH
5451 @anchor{RSH}
5452 Full file name of @command{rsh} binary or its equivalent. You may wish to
5453 set it to @code{ssh}, to improve security. In this case you will have
5454 to use public key authentication.
5455 @end defvr
5456
5457 @defvr {Backup variable} RSH_COMMAND
5458
5459 Full file name of @command{rsh} binary on remote mashines. This will
5460 be passed via @option{--rsh-command} option to the remote invocation
5461 of @GNUTAR{}.
5462 @end defvr
5463
5464 @defvr {Backup variable} VOLNO_FILE
5465
5466 Name of temporary file to hold volume numbers. This needs to be accessible
5467 by all the machines which have file systems to be dumped.
5468 @end defvr
5469
5470 @defvr {Backup variable} XLIST
5471
5472 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5473 located on the remote machine and containing the list of files to
5474 be excluded from the backup. Exclude file lists are searched in
5475 /etc/tar-backup directory. A common use for exclude file lists
5476 is to exclude files containing security-sensitive information
5477 (e.g., @file{/etc/shadow} from backups).
5478
5479 This variable affects only @code{backup}.
5480 @end defvr
5481
5482 @defvr {Backup variable} SLEEP_TIME
5483
5484 Time to sleep between dumps of any two successive file systems
5485
5486 This variable affects only @code{backup}.
5487 @end defvr
5488
5489 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5490
5491 Script to be run when it's time to insert a new tape in for the next
5492 volume. Administrators may want to tailor this script for their site.
5493 If this variable isn't set, @GNUTAR{} will display its built-in prompt
5494 @FIXME-xref{describe it somewhere!}, and will expect confirmation from
5495 the console.
5496 @end defvr
5497
5498 @defvr {Backup variable} SLEEP_MESSAGE
5499
5500 Message to display on the terminal while waiting for dump time. Usually
5501 this will just be some literal text.
5502 @end defvr
5503
5504 @defvr {Backup variable} TAR
5505
5506 Full file name of the @GNUTAR{} executable. If this is not set, backup
5507 scripts will search @command{tar} in the current shell path.
5508 @end defvr
5509
5510 @node Magnetic Tape Control
5511 @subsection Magnetic Tape Control
5512
5513 Backup scripts access tape device using special @dfn{hook functions}.
5514 These functions take a single argument -- the name of the tape
5515 device. Their names are kept in the following variables:
5516
5517 @defvr {Backup variable} MT_BEGIN
5518 The name of @dfn{begin} function. This function is called before
5519 accessing the drive. By default it retensions the tape:
5520
5521 @smallexample
5522 MT_BEGIN=mt_begin
5523
5524 mt_begin() @{
5525 mt -f "$1" retension
5526 @}
5527 @end smallexample
5528 @end defvr
5529
5530 @defvr {Backup variable} MT_REWIND
5531 The name of @dfn{rewind} function. The default definition is as
5532 follows:
5533
5534 @smallexample
5535 MT_REWIND=mt_rewind
5536
5537 mt_rewind() @{
5538 mt -f "$1" rewind
5539 @}
5540 @end smallexample
5541
5542 @end defvr
5543
5544 @defvr {Backup variable} MT_OFFLINE
5545 The name of the function switching the tape off line. By default
5546 it is defined as follows:
5547
5548 @smallexample
5549 MT_OFFLINE=mt_offline
5550
5551 mt_offline() @{
5552 mt -f "$1" offl
5553 @}
5554 @end smallexample
5555 @end defvr
5556
5557 @defvr {Backup variable} MT_STATUS
5558 The name of the function used to obtain the status of the archive device,
5559 including error count. Default definition:
5560
5561 @smallexample
5562 MT_STATUS=mt_status
5563
5564 mt_status() @{
5565 mt -f "$1" status
5566 @}
5567 @end smallexample
5568 @end defvr
5569
5570 @node User Hooks
5571 @subsection User Hooks
5572
5573 @dfn{User hooks} are shell functions executed before and after
5574 each @command{tar} invocation. Thus, there are @dfn{backup
5575 hooks}, which are executed before and after dumping each file
5576 system, and @dfn{restore hooks}, executed before and
5577 after restoring a file system. Each user hook is a shell function
5578 taking four arguments:
5579
5580 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5581 Its arguments are:
5582
5583 @table @var
5584 @item level
5585 Current backup or restore level.
5586
5587 @item host
5588 Name or IP address of the host machine being dumped or restored.
5589
5590 @item fs
5591 Full path name to the file system being dumped or restored.
5592
5593 @item fsname
5594 File system name with directory separators replaced with colons. This
5595 is useful, e.g., for creating unique files.
5596 @end table
5597 @end deffn
5598
5599 Following variables keep the names of user hook functions
5600
5601 @defvr {Backup variable} DUMP_BEGIN
5602 Dump begin function. It is executed before dumping the file system.
5603 @end defvr
5604
5605 @defvr {Backup variable} DUMP_END
5606 Executed after dumping the file system.
5607 @end defvr
5608
5609 @defvr {Backup variable} RESTORE_BEGIN
5610 Executed before restoring the file system.
5611 @end defvr
5612
5613 @defvr {Backup variable} RESTORE_END
5614 Executed after restoring the file system.
5615 @end defvr
5616
5617 @node backup-specs example
5618 @subsection An Example Text of @file{Backup-specs}
5619
5620 The following is an example of @file{backup-specs}:
5621
5622 @smallexample
5623 # site-specific parameters for file system backup.
5624
5625 ADMINISTRATOR=friedman
5626 BACKUP_HOUR=1
5627 TAPE_FILE=/dev/nrsmt0
5628
5629 # Use @code{ssh} instead of the less secure @code{rsh}
5630 RSH=/usr/bin/ssh
5631 RSH_COMMAND=/usr/bin/ssh
5632
5633 # Override MT_STATUS function:
5634 my_status() @{
5635 mts -t $TAPE_FILE
5636 @}
5637 MT_STATUS=my_status
5638
5639 # Disable MT_OFFLINE function
5640 MT_OFFLINE=:
5641
5642 BLOCKING=124
5643 BACKUP_DIRS="
5644 albert:/fs/fsf
5645 apple-gunkies:/gd
5646 albert:/fs/gd2
5647 albert:/fs/gp
5648 geech:/usr/jla
5649 churchy:/usr/roland
5650 albert:/
5651 albert:/usr
5652 apple-gunkies:/
5653 apple-gunkies:/usr
5654 gnu:/hack
5655 gnu:/u
5656 apple-gunkies:/com/mailer/gnu
5657 apple-gunkies:/com/archive/gnu"
5658
5659 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5660
5661 @end smallexample
5662
5663 @node Scripted Backups
5664 @section Using the Backup Scripts
5665
5666 The syntax for running a backup script is:
5667
5668 @smallexample
5669 backup --level=@var{level} --time=@var{time}
5670 @end smallexample
5671
5672 The @option{level} option requests the dump level. Thus, to produce
5673 a full dump, specify @code{--level=0} (this is the default, so
5674 @option{--level} may be omitted if its value is @code{0}).
5675 @footnote{For backward compatibility, the @code{backup} will also
5676 try to deduce the requested dump level from the name of the
5677 script itself. If the name consists of a string @samp{level-}
5678 followed by a single decimal digit, that digit is taken as
5679 the dump level number. Thus, you may create a link from @code{backup}
5680 to @code{level-1} and then run @code{level-1} whenever you need to
5681 create a level one dump.}
5682
5683 The @option{--time} option determines when should the backup be
5684 run. @var{Time} may take three forms:
5685
5686 @table @asis
5687 @item @var{hh}:@var{mm}
5688
5689 The dump must be run at @var{hh} hours @var{mm} minutes.
5690
5691 @item @var{hh}
5692
5693 The dump must be run at @var{hh} hours
5694
5695 @item now
5696
5697 The dump must be run immediately.
5698 @end table
5699
5700 You should start a script with a tape or disk mounted. Once you
5701 start a script, it prompts you for new tapes or disks as it
5702 needs them. Media volumes don't have to correspond to archive
5703 files --- a multi-volume archive can be started in the middle of a
5704 tape that already contains the end of another multi-volume archive.
5705 The @code{restore} script prompts for media by its archive volume,
5706 so to avoid an error message you should keep track of which tape
5707 (or disk) contains which volume of the archive (@pxref{Scripted
5708 Restoration}).
5709
5710 The backup scripts write two files on the file system. The first is a
5711 record file in @file{/etc/tar-backup/}, which is used by the scripts
5712 to store and retrieve information about which files were dumped. This
5713 file is not meant to be read by humans, and should not be deleted by
5714 them. @xref{Snapshot Files}, for a more detailed explanation of this
5715 file.
5716
5717 The second file is a log file containing the names of the file systems
5718 and files dumped, what time the backup was made, and any error
5719 messages that were generated, as well as how much space was left in
5720 the media volume after the last volume of the archive was written.
5721 You should check this log file after every backup. The file name is
5722 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5723 represents current date, and @var{n} represents current dump level number.
5724
5725 The script also prints the name of each system being dumped to the
5726 standard output.
5727
5728 Following is the full list of options accepted by @code{backup}
5729 script:
5730
5731 @table @option
5732 @item -l @var{level}
5733 @itemx --level=@var{level}
5734 Do backup level @var{level} (default 0).
5735
5736 @item -f
5737 @itemx --force
5738 Force backup even if today's log file already exists.
5739
5740 @item -v[@var{level}]
5741 @itemx --verbose[=@var{level}]
5742 Set verbosity level. The higher the level is, the more debugging
5743 information will be output during execution. Devault @var{level}
5744 is 100, which means the highest debugging level.
5745
5746 @item -t @var{start-time}
5747 @itemx --time=@var{start-time}
5748 Wait till @var{time}, then do backup.
5749
5750 @item -h
5751 @itemx --help
5752 Display short help message and exit.
5753
5754 @item -V
5755 @itemx --version
5756 Display information about the program's name, version, origin and legal
5757 status, all on standard output, and then exit successfully.
5758 @end table
5759
5760
5761 @node Scripted Restoration
5762 @section Using the Restore Script
5763
5764 To restore files that were archived using a scripted backup, use the
5765 @code{restore} script. Its usage is quite straightforward. In the
5766 simplest form, invoke @code{restore --all}, it will
5767 then restore all the file systems and files specified in
5768 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5769
5770 You may select the file systems (and/or files) to restore by
5771 giving @code{restore} list of @dfn{patterns} in its command
5772 line. For example, running
5773
5774 @smallexample
5775 restore 'albert:*'
5776 @end smallexample
5777
5778 @noindent
5779 will restore all file systems on the machine @samp{albert}. A more
5780 complicated example:
5781
5782 @smallexample
5783 restore 'albert:*' '*:/var'
5784 @end smallexample
5785
5786 @noindent
5787 This command will restore all file systems on the machine @samp{albert}
5788 as well as @file{/var} file system on all machines.
5789
5790 By default @code{restore} will start restoring files from the lowest
5791 available dump level (usually zero) and will continue through
5792 all available dump levels. There may be situations where such a
5793 thorough restore is not necessary. For example, you may wish to
5794 restore only files from the recent level one backup. To do so,
5795 use @option{--level} option, as shown in the example below:
5796
5797 @smallexample
5798 restore --level=1
5799 @end smallexample
5800
5801 The full list of options accepted by @code{restore} follows:
5802
5803 @table @option
5804 @item -a
5805 @itemx --all
5806 Restore all file systems and files specified in @file{backup-specs}
5807
5808 @item -l @var{level}
5809 @itemx --level=@var{level}
5810 Start restoring from the given backup level, instead of the default 0.
5811
5812 @item -v[@var{level}]
5813 @itemx --verbose[=@var{level}]
5814 Set verbosity level. The higher the level is, the more debugging
5815 information will be output during execution. Devault @var{level}
5816 is 100, which means the highest debugging level.
5817
5818 @item -h
5819 @itemx --help
5820 Display short help message and exit.
5821
5822 @item -V
5823 @itemx --version
5824 Display information about the program's name, version, origin and legal
5825 status, all on standard output, and then exit successfully.
5826 @end table
5827
5828 You should start the restore script with the media containing the
5829 first volume of the archive mounted. The script will prompt for other
5830 volumes as they are needed. If the archive is on tape, you don't need
5831 to rewind the tape to to its beginning---if the tape head is
5832 positioned past the beginning of the archive, the script will rewind
5833 the tape as needed. @FIXME-xref{Media, for a discussion of tape
5834 positioning.}
5835
5836 @quotation
5837 @strong{Warning:} The script will delete files from the active file
5838 system if they were not in the file system when the archive was made.
5839 @end quotation
5840
5841 @xref{Incremental Dumps}, for an explanation of how the script makes
5842 that determination.
5843
5844 @node Choosing
5845 @chapter Choosing Files and Names for @command{tar}
5846 @UNREVISED
5847
5848 Certain options to @command{tar} enable you to specify a name for your
5849 archive. Other options let you decide which files to include or exclude
5850 from the archive, based on when or whether files were modified, whether
5851 the file names do or don't match specified patterns, or whether files
5852 are in specified directories.
5853
5854 This chapter discusses these options in detail.
5855
5856 @menu
5857 * file:: Choosing the Archive's Name
5858 * Selecting Archive Members::
5859 * files:: Reading Names from a File
5860 * exclude:: Excluding Some Files
5861 * Wildcards:: Wildcards Patterns and Matching
5862 * after:: Operating Only on New Files
5863 * recurse:: Descending into Directories
5864 * one:: Crossing File System Boundaries
5865 @end menu
5866
5867 @node file
5868 @section Choosing and Naming Archive Files
5869 @UNREVISED
5870
5871 @cindex Naming an archive
5872 @cindex Archive Name
5873 @cindex Choosing an archive file
5874 @cindex Where is the archive?
5875 By default, @command{tar} uses an archive file name that was compiled when
5876 it was built on the system; usually this name refers to some physical
5877 tape drive on the machine. However, the person who installed @command{tar}
5878 on the system may not have set the default to a meaningful value as far as
5879 most users are concerned. As a result, you will usually want to tell
5880 @command{tar} where to find (or create) the archive. The
5881 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
5882 option allows you to either specify or name a file to use as the archive
5883 instead of the default archive file location.
5884
5885 @table @option
5886 @opindex file, short description
5887 @item --file=@var{archive-name}
5888 @itemx -f @var{archive-name}
5889 Name the archive to create or operate on. Use in conjunction with
5890 any operation.
5891 @end table
5892
5893 For example, in this @command{tar} command,
5894
5895 @smallexample
5896 $ @kbd{tar -cvf collection.tar blues folk jazz}
5897 @end smallexample
5898
5899 @noindent
5900 @file{collection.tar} is the name of the archive. It must directly
5901 follow the @option{-f} option, since whatever directly follows @option{-f}
5902 @emph{will} end up naming the archive. If you neglect to specify an
5903 archive name, you may end up overwriting a file in the working directory
5904 with the archive you create since @command{tar} will use this file's name
5905 for the archive name.
5906
5907 An archive can be saved as a file in the file system, sent through a
5908 pipe or over a network, or written to an I/O device such as a tape,
5909 floppy disk, or CD write drive.
5910
5911 @cindex Writing new archives
5912 @cindex Archive creation
5913 If you do not name the archive, @command{tar} uses the value of the
5914 environment variable @env{TAPE} as the file name for the archive. If
5915 that is not available, @command{tar} uses a default, compiled-in archive
5916 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
5917
5918 @cindex Standard input and output
5919 @cindex tar to standard input and output
5920 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
5921 archive from standard input (when listing or extracting files), or
5922 writes it to standard output (when creating an archive). If you use
5923 @file{-} as an @var{archive-name} when modifying an archive,
5924 @command{tar} reads the original archive from its standard input and
5925 writes the entire new archive to its standard output.
5926
5927 The following example is a convenient way of copying directory
5928 hierarchy from @file{sourcedir} to @file{targetdir}.
5929
5930 @smallexample
5931 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
5932 @end smallexample
5933
5934 The @option{-C} option allows to avoid using subshells:
5935
5936 @smallexample
5937 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
5938 @end smallexample
5939
5940 In both examples above, the leftmost @command{tar} invocation archives
5941 the contents of @file{sourcedir} to the standard output, while the
5942 rightmost one reads this archive from its standard input and
5943 extracts it. The @option{-p} option tells it to restore permissions
5944 of the extracted files.
5945
5946 @cindex Remote devices
5947 @cindex tar to a remote device
5948 @anchor{remote-dev}
5949 To specify an archive file on a device attached to a remote machine,
5950 use the following:
5951
5952 @smallexample
5953 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
5954 @end smallexample
5955
5956 @noindent
5957 @command{tar} will complete the remote connection, if possible, and
5958 prompt you for a username and password. If you use
5959 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
5960 will complete the remote connection, if possible, using your username
5961 as the username on the remote machine.
5962
5963 @cindex Local and remote archives
5964 @anchor{local and remote archives}
5965 If the archive file name includes a colon (@samp{:}), then it is assumed
5966 to be a file on another machine. If the archive file is
5967 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
5968 host @var{host}. The remote host is accessed using the @command{rsh}
5969 program, with a username of @var{user}. If the username is omitted
5970 (along with the @samp{@@} sign), then your user name will be used.
5971 (This is the normal @command{rsh} behavior.) It is necessary for the
5972 remote machine, in addition to permitting your @command{rsh} access, to
5973 have the @file{rmt} program installed (This command is included in
5974 the @GNUTAR{} distribution and by default is installed under
5975 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
5976 installation prefix). If you need to use a file whose name includes a
5977 colon, then the remote tape drive behavior
5978 can be inhibited by using the @option{--force-local} option.
5979
5980 When the archive is being created to @file{/dev/null}, @GNUTAR{}
5981 tries to minimize input and output operations. The Amanda backup
5982 system, when used with @GNUTAR{}, has an initial sizing pass which
5983 uses this feature.
5984
5985 @node Selecting Archive Members
5986 @section Selecting Archive Members
5987 @cindex Specifying files to act on
5988 @cindex Specifying archive members
5989
5990 @dfn{File Name arguments} specify which files in the file system
5991 @command{tar} operates on, when creating or adding to an archive, or which
5992 archive members @command{tar} operates on, when reading or deleting from
5993 an archive. @xref{Operations}.
5994
5995 To specify file names, you can include them as the last arguments on
5996 the command line, as follows:
5997 @smallexample
5998 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
5999 @end smallexample
6000
6001 If a file name begins with dash (@samp{-}), precede it with
6002 @option{--add-file} option to prevent it from being treated as an
6003 option.
6004
6005 If you specify a directory name as a file name argument, all the files
6006 in that directory are operated on by @command{tar}.
6007
6008 If you do not specify files, @command{tar} behavior differs depending
6009 on the operation mode as described below:
6010
6011 When @command{tar} is invoked with @option{--create} (@option{-c}),
6012 @command{tar} will stop immediately, reporting the following:
6013
6014 @smallexample
6015 @group
6016 $ @kbd{tar cf a.tar}
6017 tar: Cowardly refusing to create an empty archive
6018 Try `tar --help' or `tar --usage' for more information.
6019 @end group
6020 @end smallexample
6021
6022 If you specify either @option{--list} (@option{-t}) or
6023 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6024 operates on all the archive members in the archive.
6025
6026 If run with @option{--diff} option, tar will compare the archive with
6027 the contents of the current working directory.
6028
6029 If you specify any other operation, @command{tar} does nothing.
6030
6031 By default, @command{tar} takes file names from the command line. However,
6032 there are other ways to specify file or member names, or to modify the
6033 manner in which @command{tar} selects the files or members upon which to
6034 operate. In general, these methods work both for specifying the names
6035 of files and archive members.
6036
6037 @node files
6038 @section Reading Names from a File
6039
6040 @cindex Reading file names from a file
6041 @cindex Lists of file names
6042 @cindex File Name arguments, alternatives
6043 Instead of giving the names of files or archive members on the command
6044 line, you can put the names into a file, and then use the
6045 @option{--files-from=@var{file-of-names}} (@option{-T
6046 @var{file-of-names}}) option to @command{tar}. Give the name of the
6047 file which contains the list of files to include as the argument to
6048 @option{--files-from}. In the list, the file names should be separated by
6049 newlines. You will frequently use this option when you have generated
6050 the list of files to archive with the @command{find} utility.
6051
6052 @table @option
6053 @opindex files-from
6054 @item --files-from=@var{file-name}
6055 @itemx -T @var{file-name}
6056 Get names to extract or create from file @var{file-name}.
6057 @end table
6058
6059 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6060 you specify either @code{--files-from=-} or @code{-T -}), then the file
6061 names are read from standard input.
6062
6063 Unless you are running @command{tar} with @option{--create}, you can not use
6064 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6065 command.
6066
6067 Any number of @option{-T} options can be given in the command line.
6068
6069 The following example shows how to use @command{find} to generate a list of
6070 files smaller than 400K in length and put that list into a file
6071 called @file{small-files}. You can then use the @option{-T} option to
6072 @command{tar} to specify the files from that file, @file{small-files}, to
6073 create the archive @file{little.tgz}. (The @option{-z} option to
6074 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6075 more information.)
6076
6077 @smallexample
6078 $ @kbd{find . -size -400 -print > small-files}
6079 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6080 @end smallexample
6081
6082 @noindent
6083 In the file list given by @option{-T} option, any file name beginning
6084 with @samp{-} character is considered a @command{tar} option and is
6085 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6086 recognized only @option{-C} option in file lists, and only if the
6087 option and its argument occupied two consecutive lines.} For example,
6088 the common use of this feature is to change to another directory by
6089 specifying @option{-C} option:
6090
6091 @smallexample
6092 @group
6093 $ @kbd{cat list}
6094 -C/etc
6095 passwd
6096 hosts
6097 -C/lib
6098 libc.a
6099 $ @kbd{tar -c -f foo.tar --files-from list}
6100 @end group
6101 @end smallexample
6102
6103 @noindent
6104 In this example, @command{tar} will first switch to @file{/etc}
6105 directory and add files @file{passwd} and @file{hosts} to the
6106 archive. Then it will change to @file{/lib} directory and will archive
6107 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6108 contain:
6109
6110 @smallexample
6111 @group
6112 $ @kbd{tar tf foo.tar}
6113 passwd
6114 hosts
6115 libc.a
6116 @end group
6117 @end smallexample
6118
6119 @noindent
6120 @opindex directory, using in @option{--files-from} argument
6121 Notice that the option parsing algorithm used with @option{-T} is
6122 stricter than the one used by shell. Namely, when specifying option
6123 arguments, you should observe the following rules:
6124
6125 @itemize @bullet
6126 @item
6127 When using short (single-letter) option form, its argument must
6128 immediately follow the option letter, without any intervening
6129 whitespace. For example: @code{-Cdir}.
6130
6131 @item
6132 When using long option form, the option argument must be separated
6133 from the option by a single equal sign. No whitespace is allowed on
6134 any side of the equal sign. For example: @code{--directory=dir}.
6135
6136 @item
6137 For both short and long option forms, the option argument can be given
6138 on the next line after the option name, e.g.:
6139
6140 @smallexample
6141 @group
6142 --directory
6143 dir
6144 @end group
6145 @end smallexample
6146
6147 @noindent
6148 and
6149
6150 @smallexample
6151 @group
6152 -C
6153 dir
6154 @end group
6155 @end smallexample
6156 @end itemize
6157
6158 @opindex add-file
6159 If you happen to have a file whose name starts with @samp{-},
6160 precede it with @option{--add-file} option to prevent it from
6161 being recognized as an option. For example: @code{--add-file=--my-file}.
6162
6163 @menu
6164 * nul::
6165 @end menu
6166
6167 @node nul
6168 @subsection @code{NUL} Terminated File Names
6169
6170 @cindex File names, terminated by @code{NUL}
6171 @cindex @code{NUL} terminated file names
6172 The @option{--null} option causes
6173 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6174 to read file names terminated by a @code{NUL} instead of a newline, so
6175 files whose names contain newlines can be archived using
6176 @option{--files-from}.
6177
6178 @table @option
6179 @opindex null
6180 @item --null
6181 Only consider @code{NUL} terminated file names, instead of files that
6182 terminate in a newline.
6183 @end table
6184
6185 The @option{--null} option is just like the one in @acronym{GNU}
6186 @command{xargs} and @command{cpio}, and is useful with the
6187 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6188 @command{tar}, @option{--null} also disables special handling for
6189 file names that begin with dash.
6190
6191 This example shows how to use @command{find} to generate a list of files
6192 larger than 800K in length and put that list into a file called
6193 @file{long-files}. The @option{-print0} option to @command{find} is just
6194 like @option{-print}, except that it separates files with a @code{NUL}
6195 rather than with a newline. You can then run @command{tar} with both the
6196 @option{--null} and @option{-T} options to specify that @command{tar} get the
6197 files from that file, @file{long-files}, to create the archive
6198 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6199 @command{tar} to recognize the @code{NUL} separator between files.
6200
6201 @smallexample
6202 $ @kbd{find . -size +800 -print0 > long-files}
6203 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6204 @end smallexample
6205
6206 @FIXME{say anything else here to conclude the section?}
6207
6208 @node exclude
6209 @section Excluding Some Files
6210 @UNREVISED
6211
6212 @cindex File names, excluding files by
6213 @cindex Excluding files by name and pattern
6214 @cindex Excluding files by file system
6215 To avoid operating on files whose names match a particular pattern,
6216 use the @option{--exclude} or @option{--exclude-from} options.
6217
6218 @table @option
6219 @opindex exclude
6220 @item --exclude=@var{pattern}
6221 Causes @command{tar} to ignore files that match the @var{pattern}.
6222 @end table
6223
6224 @findex exclude
6225 The @option{--exclude=@var{pattern}} option prevents any file or
6226 member whose name matches the shell wildcard (@var{pattern}) from
6227 being operated on.
6228 For example, to create an archive with all the contents of the directory
6229 @file{src} except for files whose names end in @file{.o}, use the
6230 command @samp{tar -cf src.tar --exclude='*.o' src}.
6231
6232 You may give multiple @option{--exclude} options.
6233
6234 @table @option
6235 @opindex exclude-from
6236 @item --exclude-from=@var{file}
6237 @itemx -X @var{file}
6238 Causes @command{tar} to ignore files that match the patterns listed in
6239 @var{file}.
6240 @end table
6241
6242 @findex exclude-from
6243 Use the @option{--exclude-from} option to read a
6244 list of patterns, one per line, from @var{file}; @command{tar} will
6245 ignore files matching those patterns. Thus if @command{tar} is
6246 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6247 single line @file{*.o}, no files whose names end in @file{.o} will be
6248 added to the archive.
6249
6250 @table @option
6251 @opindex exclude-caches
6252 @item --exclude-caches
6253 Causes @command{tar} to ignore directories containing a cache directory tag.
6254 @end table
6255
6256 @findex exclude-caches
6257 When creating an archive, the @option{--exclude-caches} option causes
6258 @command{tar} to exclude all directories that contain a @dfn{cache
6259 directory tag}. A cache directory tag is a short file with the
6260 well-known name @file{CACHEDIR.TAG} and having a standard header
6261 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6262 Various applications write cache directory tags into directories they
6263 use to hold regenerable, non-precious data, so that such data can be
6264 more easily excluded from backups.
6265
6266 @menu
6267 * problems with exclude::
6268 @end menu
6269
6270 @node problems with exclude
6271 @unnumberedsubsec Problems with Using the @code{exclude} Options
6272
6273 @opindex exclude, potential problems with
6274 Some users find @samp{exclude} options confusing. Here are some common
6275 pitfalls:
6276
6277 @itemize @bullet
6278 @item
6279 The main operating mode of @command{tar} does not act on a path name
6280 explicitly listed on the command line if one of its file name
6281 components is excluded. In the example above, if
6282 you create an archive and exclude files that end with @samp{*.o}, but
6283 explicitly name the file @samp{dir.o/foo} after all the options have been
6284 listed, @samp{dir.o/foo} will be excluded from the archive.
6285
6286 @item
6287 You can sometimes confuse the meanings of @option{--exclude} and
6288 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6289 to be excluded are given as a pattern on the command line. Use
6290 @option{--exclude-from} to introduce the name of a file which contains
6291 a list of patterns, one per line; each of these patterns can exclude
6292 zero, one, or many files.
6293
6294 @item
6295 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6296 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6297 like @samp{*}. If you do not do this, the shell might expand the
6298 @samp{*} itself using files at hand, so @command{tar} might receive a
6299 list of files instead of one pattern, or none at all, making the
6300 command somewhat illegal. This might not correspond to what you want.
6301
6302 For example, write:
6303
6304 @smallexample
6305 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6306 @end smallexample
6307
6308 @noindent
6309 rather than:
6310
6311 @smallexample
6312 # @emph{Wrong!}
6313 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6314 @end smallexample
6315
6316 @item
6317 You must use use shell syntax, or globbing, rather than @code{regexp}
6318 syntax, when using exclude options in @command{tar}. If you try to use
6319 @code{regexp} syntax to describe files to be excluded, your command
6320 might fail.
6321
6322 @item
6323 @FIXME{The change in semantics must have occurred before 1.11,
6324 so I doubt if it is worth mentioning at all. Anyway, should at
6325 least specify in which version the semantics changed.}
6326 In earlier versions of @command{tar}, what is now the
6327 @option{--exclude-from} option was called @option{--exclude} instead.
6328 Now, @option{--exclude} applies to patterns listed on the command
6329 line and @option{--exclude-from} applies to patterns listed in a
6330 file.
6331
6332 @end itemize
6333
6334 @node Wildcards
6335 @section Wildcards Patterns and Matching
6336
6337 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6338 @samp{*} or @samp{?} for example, are replaced and expanded into all
6339 existing files matching the given pattern. @GNUTAR{} can use wildcard
6340 patterns for matching (or globbing) archive members when extracting
6341 from or listing an archive. Wildcard patterns are also used for
6342 verifying volume labels of @command{tar} archives. This section has the
6343 purpose of explaining wildcard syntax for @command{tar}.
6344
6345 @FIXME{the next few paragraphs need work.}
6346
6347 A @var{pattern} should be written according to shell syntax, using wildcard
6348 characters to effect globbing. Most characters in the pattern stand
6349 for themselves in the matched string, and case is significant: @samp{a}
6350 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6351 pattern matches any single character in the matched string. The character
6352 @samp{*} in the pattern matches zero, one, or more single characters in
6353 the matched string. The character @samp{\} says to take the following
6354 character of the pattern @emph{literally}; it is useful when one needs to
6355 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6356
6357 The character @samp{[}, up to the matching @samp{]}, introduces a character
6358 class. A @dfn{character class} is a list of acceptable characters
6359 for the next single character of the matched string. For example,
6360 @samp{[abcde]} would match any of the first five letters of the alphabet.
6361 Note that within a character class, all of the ``special characters''
6362 listed above other than @samp{\} lose their special meaning; for example,
6363 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6364 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6365 the characters @samp{-} and @samp{]} must either come @emph{first} or
6366 @emph{last} in a character class.)
6367
6368 @cindex Excluding characters from a character class
6369 @cindex Character class, excluding characters from
6370 If the first character of the class after the opening @samp{[}
6371 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6372 Rather than listing character to match, it lists those characters which
6373 are @emph{forbidden} as the next single character of the matched string.
6374
6375 Other characters of the class stand for themselves. The special
6376 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6377 letters, is meant to represent all characters between @var{a} and
6378 @var{e}, inclusive.
6379
6380 @FIXME{need to add a sentence or so here to make this clear for those
6381 who don't have dan around.}
6382
6383 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6384 special for wildcard matches. However, if a pattern completely matches
6385 a directory prefix of a matched string, then it matches the full matched
6386 string: thus, excluding a directory also excludes all the files beneath it.
6387
6388 @menu
6389 * controlling pattern-matching::
6390 @end menu
6391
6392 @node controlling pattern-matching
6393 @unnumberedsubsec Controlling Pattern-Matching
6394
6395 For the purposes of this section, we call @dfn{exclusion members} all
6396 member names obtained while processing @option{--exclude} and
6397 @option{--exclude-from} options, and @dfn{inclusion members} those
6398 member names that were given in the command line or read from the file
6399 specified with @option{--files-from} option.
6400
6401 These two pairs of member lists are used in the following operations:
6402 @option{--diff}, @option{--extract}, @option{--list},
6403 @option{--update}.
6404
6405 There are no inclusion members in create mode (@option{--create} and
6406 @option{--append}), since in this mode the names obtained from the
6407 command line refer to @emph{files}, not archive members.
6408
6409 By default, inclusion members are compared with archive members
6410 literally @footnote{Notice that earlier @GNUTAR{} versions used
6411 globbing for inclusion members, which contradicted to UNIX98
6412 specification and was not documented. @xref{Changes}, for more
6413 information on this and other changes} and exclusion members are
6414 treated as globbing patterns. For example:
6415
6416 @smallexample
6417 @group
6418 $ @kbd{tar tf foo.tar}
6419 a.c
6420 b.c
6421 a.txt
6422 [remarks]
6423 # @i{Member names are used verbatim:}
6424 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6425 [remarks]
6426 # @i{Exclude member names are globbed:}
6427 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6428 a.txt
6429 [remarks]
6430 @end group
6431 @end smallexample
6432
6433 This behavior can be altered by using the following options:
6434
6435 @table @option
6436 @opindex wildcards
6437 @item --wildcards
6438 Treat all member names as wildcards.
6439
6440 @opindex no-wildcards
6441 @item --no-wildcards
6442 Treat all member names as literal strings.
6443 @end table
6444
6445 Thus, to extract files whose names end in @samp{.c}, you can use:
6446
6447 @smallexample
6448 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6449 a.c
6450 b.c
6451 @end smallexample
6452
6453 @noindent
6454 Notice quoting of the pattern to prevent the shell from interpreting
6455 it.
6456
6457 The effect of @option{--wildcards} option is cancelled by
6458 @option{--no-wildcards}. This can be used to pass part of
6459 the command line arguments verbatim and other part as globbing
6460 patterns. For example, the following invocation:
6461
6462 @smallexample
6463 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6464 @end smallexample
6465
6466 @noindent
6467 instructs @command{tar} to extract from @file{foo.tar} all files whose
6468 names end in @samp{.txt} and the file named @file{[remarks]}.
6469
6470 Normally, a pattern matches a name if an initial subsequence of the
6471 name's components matches the pattern, where @samp{*}, @samp{?}, and
6472 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6473 and wildcards can match @samp{/}.
6474
6475 Other than optionally stripping leading @samp{/} from names
6476 (@pxref{absolute}), patterns and names are used as-is. For
6477 example, trailing @samp{/} is not trimmed from a user-specified name
6478 before deciding whether to exclude it.
6479
6480 However, this matching procedure can be altered by the options listed
6481 below. These options accumulate. For example:
6482
6483 @smallexample
6484 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6485 @end smallexample
6486
6487 ignores case when excluding @samp{makefile}, but not when excluding
6488 @samp{readme}.
6489
6490 @table @option
6491 @opindex anchored
6492 @opindex no-anchored
6493 @item --anchored
6494 @itemx --no-anchored
6495 If anchored, a pattern must match an initial subsequence
6496 of the name's components. Otherwise, the pattern can match any
6497 subsequence. Default is @option{--no-anchored} for exclusion members
6498 and @option{--anchored} inclusion members.
6499
6500 @opindex ignore-case
6501 @opindex no-ignore-case
6502 @item --ignore-case
6503 @itemx --no-ignore-case
6504 When ignoring case, upper-case patterns match lower-case names and vice versa.
6505 When not ignoring case (the default), matching is case-sensitive.
6506
6507 @opindex wildcards-match-slash
6508 @opindex no-wildcards-match-slash
6509 @item --wildcards-match-slash
6510 @itemx --no-wildcards-match-slash
6511 When wildcards match slash (the default for exclusion members), a
6512 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6513 name. Otherwise, @samp{/} is matched only by @samp{/}.
6514
6515 @end table
6516
6517 The @option{--recursion} and @option{--no-recursion} options
6518 (@pxref{recurse}) also affect how member patterns are interpreted. If
6519 recursion is in effect, a pattern matches a name if it matches any of
6520 the name's parent directories.
6521
6522 The following table summarizes pattern-matching default values:
6523
6524 @multitable @columnfractions .3 .7
6525 @headitem Members @tab Default settings
6526 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6527 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6528 @end multitable
6529
6530 @node after
6531 @section Operating Only on New Files
6532 @UNREVISED
6533
6534 @cindex Excluding file by age
6535 @cindex Data Modification time, excluding files by
6536 @cindex Modification time, excluding files by
6537 @cindex Age, excluding files by
6538 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
6539 @option{-N @var{date}}) option causes @command{tar} to only work on
6540 files whose data modification or status change times are newer than
6541 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
6542 it is taken to be a file name; the data modification time of that file
6543 is used as the date. If you use this option when creating or appending
6544 to an archive, the archive will only include new files. If you use
6545 @option{--after-date} when extracting an archive, @command{tar} will
6546 only extract files newer than the @var{date} you specify.
6547
6548 If you only want @command{tar} to make the date comparison based on
6549 modification of the file's data (rather than status
6550 changes), then use the @option{--newer-mtime=@var{date}} option.
6551
6552 You may use these options with any operation. Note that these options
6553 differ from the @option{--update} (@option{-u}) operation in that they
6554 allow you to specify a particular date against which @command{tar} can
6555 compare when deciding whether or not to archive the files.
6556
6557 @table @option
6558 @opindex after-date
6559 @opindex newer
6560 @item --after-date=@var{date}
6561 @itemx --newer=@var{date}
6562 @itemx -N @var{date}
6563 Only store files newer than @var{date}.
6564
6565 Acts on files only if their data modification or status change times are
6566 later than @var{date}. Use in conjunction with any operation.
6567
6568 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
6569 name; the data modification time of that file is used as the date.
6570
6571 @opindex newer-mtime
6572 @item --newer-mtime=@var{date}
6573 Acts like @option{--after-date}, but only looks at data modification times.
6574 @end table
6575
6576 These options limit @command{tar} to operate only on files which have
6577 been modified after the date specified. A file's status is considered to have
6578 changed if its contents have been modified, or if its owner,
6579 permissions, and so forth, have been changed. (For more information on
6580 how to specify a date, see @ref{Date input formats}; remember that the
6581 entire date argument must be quoted if it contains any spaces.)
6582
6583 Gurus would say that @option{--after-date} tests both the data
6584 modification time (@code{mtime}, the time the contents of the file
6585 were last modified) and the status change time (@code{ctime}, the time
6586 the file's status was last changed: owner, permissions, etc.@:)
6587 fields, while @option{--newer-mtime} tests only the @code{mtime}
6588 field.
6589
6590 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
6591 @code{ctime} and processes the file if either one is more recent than
6592 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
6593 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
6594 contents of the file were looked at).
6595
6596 Date specifiers can have embedded spaces. Because of this, you may need
6597 to quote date arguments to keep the shell from parsing them as separate
6598 arguments. For example, the following command will add to the archive
6599 all the files modified less than two days ago:
6600
6601 @smallexample
6602 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
6603 @end smallexample
6604
6605 @quotation
6606 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
6607 should not be used for incremental backups. @xref{Incremental Dumps},
6608 for proper way of creating incremental backups.
6609 @end quotation
6610
6611 @node recurse
6612 @section Descending into Directories
6613 @UNREVISED
6614 @cindex Avoiding recursion in directories
6615 @cindex Descending directories, avoiding
6616 @cindex Directories, avoiding recursion
6617 @cindex Recursion in directories, avoiding
6618
6619 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
6620
6621 Usually, @command{tar} will recursively explore all directories (either
6622 those given on the command line or through the @option{--files-from}
6623 option) for the various files they contain. However, you may not always
6624 want @command{tar} to act this way.
6625
6626 @opindex no-recursion
6627 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
6628 into specified directories. If you specify @option{--no-recursion}, you can
6629 use the @command{find} utility for hunting through levels of directories to
6630 construct a list of file names which you could then pass to @command{tar}.
6631 @command{find} allows you to be more selective when choosing which files to
6632 archive; see @ref{files}, for more information on using @command{find} with
6633 @command{tar}, or look.
6634
6635 @table @option
6636 @item --no-recursion
6637 Prevents @command{tar} from recursively descending directories.
6638
6639 @opindex recursion
6640 @item --recursion
6641 Requires @command{tar} to recursively descend directories.
6642 This is the default.
6643 @end table
6644
6645 When you use @option{--no-recursion}, @GNUTAR{} grabs
6646 directory entries themselves, but does not descend on them
6647 recursively. Many people use @command{find} for locating files they
6648 want to back up, and since @command{tar} @emph{usually} recursively
6649 descends on directories, they have to use the @samp{@w{-not -type d}}
6650 test in their @command{find} invocation (@pxref{Type, Type, Type test,
6651 find, Finding Files}), as they usually do not want all the files in a
6652 directory. They then use the @option{--files-from} option to archive
6653 the files located via @command{find}.
6654
6655 The problem when restoring files archived in this manner is that the
6656 directories themselves are not in the archive; so the
6657 @option{--same-permissions} (@option{--preserve-permissions},
6658 @option{-p}) option does not affect them---while users might really
6659 like it to. Specifying @option{--no-recursion} is a way to tell
6660 @command{tar} to grab only the directory entries given to it, adding
6661 no new files on its own. To summarize, if you use @command{find} to
6662 create a list of files to be stored in an archive, use it as follows:
6663
6664 @smallexample
6665 @group
6666 $ @kbd{find @var{dir} @var{tests} | \
6667 tar -cf @var{archive} -T - --no-recursion}
6668 @end group
6669 @end smallexample
6670
6671 The @option{--no-recursion} option also applies when extracting: it
6672 causes @command{tar} to extract only the matched directory entries, not
6673 the files under those directories.
6674
6675 The @option{--no-recursion} option also affects how globbing patterns
6676 are interpreted (@pxref{controlling pattern-matching}).
6677
6678 The @option{--no-recursion} and @option{--recursion} options apply to
6679 later options and operands, and can be overridden by later occurrences
6680 of @option{--no-recursion} and @option{--recursion}. For example:
6681
6682 @smallexample
6683 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
6684 @end smallexample
6685
6686 @noindent
6687 creates an archive with one entry for @file{grape}, and the recursive
6688 contents of @file{grape/concord}, but no entries under @file{grape}
6689 other than @file{grape/concord}.
6690
6691 @node one
6692 @section Crossing File System Boundaries
6693 @cindex File system boundaries, not crossing
6694 @UNREVISED
6695
6696 @command{tar} will normally automatically cross file system boundaries in
6697 order to archive files which are part of a directory tree. You can
6698 change this behavior by running @command{tar} and specifying
6699 @option{--one-file-system}. This option only affects files that are
6700 archived because they are in a directory that is being archived;
6701 @command{tar} will still archive files explicitly named on the command line
6702 or through @option{--files-from}, regardless of where they reside.
6703
6704 @table @option
6705 @opindex one-file-system
6706 @item --one-file-system
6707 Prevents @command{tar} from crossing file system boundaries when
6708 archiving. Use in conjunction with any write operation.
6709 @end table
6710
6711 The @option{--one-file-system} option causes @command{tar} to modify its
6712 normal behavior in archiving the contents of directories. If a file in
6713 a directory is not on the same file system as the directory itself, then
6714 @command{tar} will not archive that file. If the file is a directory
6715 itself, @command{tar} will not archive anything beneath it; in other words,
6716 @command{tar} will not cross mount points.
6717
6718 This option is useful for making full or incremental archival backups of
6719 a file system. If this option is used in conjunction with
6720 @option{--verbose} (@option{-v}), files that are excluded are
6721 mentioned by name on the standard error.
6722
6723 @menu
6724 * directory:: Changing Directory
6725 * absolute:: Absolute File Names
6726 @end menu
6727
6728 @node directory
6729 @subsection Changing the Working Directory
6730 @UNREVISED
6731
6732 @FIXME{need to read over this node now for continuity; i've switched
6733 things around some.}
6734
6735 @cindex Changing directory mid-stream
6736 @cindex Directory, changing mid-stream
6737 @cindex Working directory, specifying
6738 To change the working directory in the middle of a list of file names,
6739 either on the command line or in a file specified using
6740 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
6741 This will change the working directory to the specified directory
6742 after that point in the list.
6743
6744 @table @option
6745 @opindex directory
6746 @item --directory=@var{directory}
6747 @itemx -C @var{directory}
6748 Changes the working directory in the middle of a command line.
6749 @end table
6750
6751 For example,
6752
6753 @smallexample
6754 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
6755 @end smallexample
6756
6757 @noindent
6758 will place the files @file{grape} and @file{prune} from the current
6759 directory into the archive @file{jams.tar}, followed by the file
6760 @file{cherry} from the directory @file{food}. This option is especially
6761 useful when you have several widely separated files that you want to
6762 store in the same archive.
6763
6764 Note that the file @file{cherry} is recorded in the archive under the
6765 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
6766 archive will contain three files that all appear to have come from the
6767 same directory; if the archive is extracted with plain @samp{tar
6768 --extract}, all three files will be written in the current directory.
6769
6770 Contrast this with the command,
6771
6772 @smallexample
6773 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
6774 @end smallexample
6775
6776 @noindent
6777 which records the third file in the archive under the name
6778 @file{red/cherry} so that, if the archive is extracted using
6779 @samp{tar --extract}, the third file will be written in a subdirectory
6780 named @file{orange-colored}.
6781
6782 You can use the @option{--directory} option to make the archive
6783 independent of the original name of the directory holding the files.
6784 The following command places the files @file{/etc/passwd},
6785 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
6786 @file{foo.tar}:
6787
6788 @smallexample
6789 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
6790 @end smallexample
6791
6792 @noindent
6793 However, the names of the archive members will be exactly what they were
6794 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
6795 They will not appear to be related by file name to the original
6796 directories where those files were located.
6797
6798 Note that @option{--directory} options are interpreted consecutively. If
6799 @option{--directory} specifies a relative file name, it is interpreted
6800 relative to the then current directory, which might not be the same as
6801 the original current working directory of @command{tar}, due to a previous
6802 @option{--directory} option.
6803
6804 When using @option{--files-from} (@pxref{files}), you can put various
6805 @command{tar} options (including @option{-C}) in the file list. Notice,
6806 however, that in this case the option and its argument may not be
6807 separated by whitespace. If you use short option, its argument must
6808 either follow the option letter immediately, without any intervening
6809 whitespace, or occupy the next line. Otherwise, if you use long
6810 option, separate its argument by an equal sign.
6811
6812 For instance, the file list for the above example will be:
6813
6814 @smallexample
6815 @group
6816 -C
6817 /etc
6818 passwd
6819 hosts
6820 -C
6821 /lib
6822 libc.a
6823 @end group
6824 @end smallexample
6825
6826 @noindent
6827 To use it, you would invoke @command{tar} as follows:
6828
6829 @smallexample
6830 $ @kbd{tar -c -f foo.tar --files-from list}
6831 @end smallexample
6832
6833 Notice also that you can only use the short option variant in the file
6834 list, i.e., always use @option{-C}, not @option{--directory}.
6835
6836 The interpretation of @option{--directory} is disabled by
6837 @option{--null} option.
6838
6839 @node absolute
6840 @subsection Absolute File Names
6841 @UNREVISED
6842
6843 @table @option
6844 @opindex absolute-names
6845 @item --absolute-names
6846 @itemx -P
6847 Do not strip leading slashes from file names, and permit file names
6848 containing a @file{..} file name component.
6849 @end table
6850
6851 By default, @GNUTAR{} drops a leading @samp{/} on
6852 input or output, and complains about file names containing a @file{..}
6853 component. This option turns off this behavior.
6854
6855 When @command{tar} extracts archive members from an archive, it strips any
6856 leading slashes (@samp{/}) from the member name. This causes absolute
6857 member names in the archive to be treated as relative file names. This
6858 allows you to have such members extracted wherever you want, instead of
6859 being restricted to extracting the member in the exact directory named
6860 in the archive. For example, if the archive member has the name
6861 @file{/etc/passwd}, @command{tar} will extract it as if the name were
6862 really @file{etc/passwd}.
6863
6864 File names containing @file{..} can cause problems when extracting, so
6865 @command{tar} normally warns you about such files when creating an
6866 archive, and rejects attempts to extracts such files.
6867
6868 Other @command{tar} programs do not do this. As a result, if you
6869 create an archive whose member names start with a slash, they will be
6870 difficult for other people with a non-@GNUTAR{}
6871 program to use. Therefore, @GNUTAR{} also strips
6872 leading slashes from member names when putting members into the
6873 archive. For example, if you ask @command{tar} to add the file
6874 @file{/bin/ls} to an archive, it will do so, but the member name will
6875 be @file{bin/ls}.@footnote{A side effect of this is that when
6876 @option{--create} is used with @option{--verbose} the resulting output
6877 is not, generally speaking, the same as the one you'd get running
6878 @kbd{tar --list} command. This may be important if you use some
6879 scripts for comparing both outputs. @xref{listing member and file names},
6880 for the information on how to handle this case.}
6881
6882 If you use the @option{--absolute-names} (@option{-P}) option,
6883 @command{tar} will do none of these transformations.
6884
6885 To archive or extract files relative to the root directory, specify
6886 the @option{--absolute-names} (@option{-P}) option.
6887
6888 Normally, @command{tar} acts on files relative to the working
6889 directory---ignoring superior directory names when archiving, and
6890 ignoring leading slashes when extracting.
6891
6892 When you specify @option{--absolute-names} (@option{-P}),
6893 @command{tar} stores file names including all superior directory
6894 names, and preserves leading slashes. If you only invoked
6895 @command{tar} from the root directory you would never need the
6896 @option{--absolute-names} option, but using this option
6897 may be more convenient than switching to root.
6898
6899 @FIXME{Should be an example in the tutorial/wizardry section using this
6900 to transfer files between systems.}
6901
6902 @FIXME{Is write access an issue?}
6903
6904 @table @option
6905 @item --absolute-names
6906 Preserves full file names (including superior directory names) when
6907 archiving files. Preserves leading slash when extracting files.
6908
6909 @end table
6910
6911 @FIXME{this is still horrible; need to talk with dan on monday.}
6912
6913 @command{tar} prints out a message about removing the @samp{/} from
6914 file names. This message appears once per @GNUTAR{}
6915 invocation. It represents something which ought to be told; ignoring
6916 what it means can cause very serious surprises, later.
6917
6918 Some people, nevertheless, do not want to see this message. Wanting to
6919 play really dangerously, one may of course redirect @command{tar} standard
6920 error to the sink. For example, under @command{sh}:
6921
6922 @smallexample
6923 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
6924 @end smallexample
6925
6926 @noindent
6927 Another solution, both nicer and simpler, would be to change to
6928 the @file{/} directory first, and then avoid absolute notation.
6929 For example:
6930
6931 @smallexample
6932 $ @kbd{(cd / && tar -c -f archive.tar home)}
6933 # @i{or}:
6934 $ @kbd{tar -c -f archive.tar -C / home}
6935 @end smallexample
6936
6937 @include getdate.texi
6938
6939 @node Formats
6940 @chapter Controlling the Archive Format
6941
6942 @cindex Tar archive formats
6943 Due to historical reasons, there are several formats of tar archives.
6944 All of them are based on the same principles, but have some subtle
6945 differences that often make them incompatible with each other.
6946
6947 GNU tar is able to create and handle archives in a variety of formats.
6948 The most frequently used formats are (in alphabetical order):
6949
6950 @table @asis
6951 @item gnu
6952 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
6953 from an early @acronym{POSIX} standard, adding some improvements such as
6954 sparse file handling and incremental archives. Unfortunately these
6955 features were implemented in a way incompatible with other archive
6956 formats.
6957
6958 Archives in @samp{gnu} format are able to hold pathnames of unlimited
6959 length.
6960
6961 @item oldgnu
6962 Format used by @GNUTAR{} of versions prior to 1.12.
6963
6964 @item v7
6965 Archive format, compatible with the V7 implementation of tar. This
6966 format imposes a number of limitations. The most important of them
6967 are:
6968
6969 @enumerate
6970 @item The maximum length of a file name is limited to 99 characters.
6971 @item The maximum length of a symbolic link is limited to 99 characters.
6972 @item It is impossible to store special files (block and character
6973 devices, fifos etc.)
6974 @item Maximum value of user or group ID is limited to 2097151 (7777777
6975 octal)
6976 @item V7 archives do not contain symbolic ownership information (user
6977 and group name of the file owner).
6978 @end enumerate
6979
6980 This format has traditionally been used by Automake when producing
6981 Makefiles. This practice will change in the future, in the meantime,
6982 however this means that projects containing filenames more than 99
6983 characters long will not be able to use @GNUTAR{} @value{VERSION} and
6984 Automake prior to 1.9.
6985
6986 @item ustar
6987 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
6988 symbolic ownership information. It is also able to store
6989 special files. However, it imposes several restrictions as well:
6990
6991 @enumerate
6992 @item The maximum length of a file name is limited to 256 characters,
6993 provided that the filename can be split at directory separator in
6994 two parts, first of them being at most 155 bytes long. So, in most
6995 cases the maximum file name length will be shorter than 256
6996 characters.
6997 @item The maximum length of a symbolic link name is limited to
6998 100 characters.
6999 @item Maximum size of a file the archive is able to accomodate
7000 is 8GB
7001 @item Maximum value of UID/GID is 2097151.
7002 @item Maximum number of bits in device major and minor numbers is 21.
7003 @end enumerate
7004
7005 @item star
7006 Format used by J@"org Schilling @command{star}
7007 implementation. @GNUTAR{} is able to read @samp{star} archives but
7008 currently does not produce them.
7009
7010 @item posix
7011 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7012 most flexible and feature-rich format. It does not impose any
7013 restrictions on file sizes or filename lengths. This format is quite
7014 recent, so not all tar implementations are able to handle it properly.
7015 However, this format is designed in such a way that any tar
7016 implementation able to read @samp{ustar} archives will be able to read
7017 most @samp{posix} archives as well, with the only exception that any
7018 additional information (such as long file names etc.) will in such
7019 case be extracted as plain text files along with the files it refers to.
7020
7021 This archive format will be the default format for future versions
7022 of @GNUTAR{}.
7023
7024 @end table
7025
7026 The following table summarizes the limitations of each of these
7027 formats:
7028
7029 @multitable @columnfractions .10 .20 .20 .20 .20
7030 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7031 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7032 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7033 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7034 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7035 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7036 @end multitable
7037
7038 The default format for @GNUTAR{} is defined at compilation
7039 time. You may check it by running @command{tar --help}, and examining
7040 the last lines of its output. Usually, @GNUTAR{} is configured
7041 to create archives in @samp{gnu} format, however, future version will
7042 switch to @samp{posix}.
7043
7044 @menu
7045 * Portability:: Making @command{tar} Archives More Portable
7046 * Compression:: Using Less Space through Compression
7047 * Attributes:: Handling File Attributes
7048 * Standard:: The Standard Format
7049 * Extensions:: @acronym{GNU} Extensions to the Archive Format
7050 * cpio:: Comparison of @command{tar} and @command{cpio}
7051 @end menu
7052
7053 @node Portability
7054 @section Making @command{tar} Archives More Portable
7055
7056 Creating a @command{tar} archive on a particular system that is meant to be
7057 useful later on many other machines and with other versions of @command{tar}
7058 is more challenging than you might think. @command{tar} archive formats
7059 have been evolving since the first versions of Unix. Many such formats
7060 are around, and are not always compatible with each other. This section
7061 discusses a few problems, and gives some advice about making @command{tar}
7062 archives more portable.
7063
7064 One golden rule is simplicity. For example, limit your @command{tar}
7065 archives to contain only regular files and directories, avoiding
7066 other kind of special files. Do not attempt to save sparse files or
7067 contiguous files as such. Let's discuss a few more problems, in turn.
7068
7069 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7070 archives and archive labels) in GNU and PAX formats.}
7071
7072 @menu
7073 * Portable Names:: Portable Names
7074 * dereference:: Symbolic Links
7075 * old:: Old V7 Archives
7076 * ustar:: Ustar Archives
7077 * gnu:: GNU and old GNU format archives.
7078 * posix:: @acronym{POSIX} archives
7079 * Checksumming:: Checksumming Problems
7080 * Large or Negative Values:: Large files, negative time stamps, etc.
7081 @end menu
7082
7083 @node Portable Names
7084 @subsection Portable Names
7085
7086 Use portable file and member names. A name is portable if it contains
7087 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7088 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7089 contain @samp{/-}. Avoid deep directory nesting. For portability to
7090 old Unix hosts, limit your file name components to 14 characters or
7091 less.
7092
7093 If you intend to have your @command{tar} archives to be read under
7094 MSDOS, you should not rely on case distinction for file names, and you
7095 might use the @acronym{GNU} @command{doschk} program for helping you
7096 further diagnosing illegal MSDOS names, which are even more limited
7097 than System V's.
7098
7099 @node dereference
7100 @subsection Symbolic Links
7101 @cindex File names, using symbolic links
7102 @cindex Symbolic link as file name
7103
7104 @opindex dereference
7105 Normally, when @command{tar} archives a symbolic link, it writes a
7106 block to the archive naming the target of the link. In that way, the
7107 @command{tar} archive is a faithful record of the file system contents.
7108 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7109 @command{tar} to archive the files symbolic links point to, instead of
7110 the links themselves. When this option is used, when @command{tar}
7111 encounters a symbolic link, it will archive the linked-to file,
7112 instead of simply recording the presence of a symbolic link.
7113
7114 The name under which the file is stored in the file system is not
7115 recorded in the archive. To record both the symbolic link name and
7116 the file name in the system, archive the file under both names. If
7117 all links were recorded automatically by @command{tar}, an extracted file
7118 might be linked to a file name that no longer exists in the file
7119 system.
7120
7121 If a linked-to file is encountered again by @command{tar} while creating
7122 the same archive, an entire second copy of it will be stored. (This
7123 @emph{might} be considered a bug.)
7124
7125 So, for portable archives, do not archive symbolic links as such,
7126 and use @option{--dereference} (@option{-h}): many systems do not support
7127 symbolic links, and moreover, your distribution might be unusable if
7128 it contains unresolved symbolic links.
7129
7130 @node old
7131 @subsection Old V7 Archives
7132 @cindex Format, old style
7133 @cindex Old style format
7134 @cindex Old style archives
7135 @cindex v7 archive format
7136
7137 Certain old versions of @command{tar} cannot handle additional
7138 information recorded by newer @command{tar} programs. To create an
7139 archive in V7 format (not ANSI), which can be read by these old
7140 versions, specify the @option{--format=v7} option in
7141 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7142 accepts @option{--portability} or @samp{op-old-archive} for this
7143 option). When you specify it,
7144 @command{tar} leaves out information about directories, pipes, fifos,
7145 contiguous files, and device files, and specifies file ownership by
7146 group and user IDs instead of group and user names.
7147
7148 When updating an archive, do not use @option{--format=v7}
7149 unless the archive was created using this option.
7150
7151 In most cases, a @emph{new} format archive can be read by an @emph{old}
7152 @command{tar} program without serious trouble, so this option should
7153 seldom be needed. On the other hand, most modern @command{tar}s are
7154 able to read old format archives, so it might be safer for you to
7155 always use @option{--format=v7} for your distributions.
7156
7157 @node ustar
7158 @subsection Ustar Archive Format
7159
7160 @cindex ustar archive format
7161 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7162 @code{ustar}. Although it is more flexible than the V7 format, it
7163 still has many restrictions (@xref{Formats,ustar}, for the detailed
7164 description of @code{ustar} format). Along with V7 format,
7165 @code{ustar} format is a good choice for archives intended to be read
7166 with other implementations of @command{tar}.
7167
7168 To create archive in @code{ustar} format, use @option{--format=ustar}
7169 option in conjunction with the @option{--create} (@option{-c}).
7170
7171 @node gnu
7172 @subsection @acronym{GNU} and old @GNUTAR{} format
7173
7174 @cindex GNU archive format
7175 @cindex Old GNU archive format
7176 @GNUTAR{} was based on an early draft of the
7177 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7178 @command{tar}, such as the support for file names longer than 100
7179 characters, use portions of the @command{tar} header record which were
7180 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7181 @acronym{POSIX} have allocated the same parts of the header record for
7182 other purposes. As a result, @GNUTAR{} format is
7183 incompatible with the current @acronym{POSIX} specification, and with
7184 @command{tar} programs that follow it.
7185
7186 In the majority of cases, @command{tar} will be configured to create
7187 this format by default. This will change in the future releases, since
7188 we plan to make @samp{posix} format the default.
7189
7190 To force creation a @GNUTAR{} archive, use option
7191 @option{--format=gnu}.
7192
7193 @node posix
7194 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7195
7196 @cindex POSIX archive format
7197 @cindex PAX archive format
7198 The version @value{VERSION} of @GNUTAR{} is able
7199 to read and create archives conforming to @acronym{POSIX.1-2001} standard.
7200
7201 A @acronym{POSIX} conformant archive will be created if @command{tar}
7202 was given @option{--format=posix} option.
7203
7204 @node Checksumming
7205 @subsection Checksumming Problems
7206
7207 SunOS and HP-UX @command{tar} fail to accept archives created using
7208 @GNUTAR{} and containing non-ASCII file names, that
7209 is, file names having characters with the eight bit set, because they
7210 use signed checksums, while @GNUTAR{} uses unsigned
7211 checksums while creating archives, as per @acronym{POSIX} standards. On
7212 reading, @GNUTAR{} computes both checksums and
7213 accept any. It is somewhat worrying that a lot of people may go
7214 around doing backup of their files using faulty (or at least
7215 non-standard) software, not learning about it until it's time to
7216 restore their missing files with an incompatible file extractor, or
7217 vice versa.
7218
7219 @GNUTAR{} compute checksums both ways, and accept
7220 any on read, so @acronym{GNU} tar can read Sun tapes even with their
7221 wrong checksums. @GNUTAR{} produces the standard
7222 checksum, however, raising incompatibilities with Sun. That is to
7223 say, @GNUTAR{} has not been modified to
7224 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
7225 I've been told that more recent Sun @command{tar} now read standard
7226 archives, so maybe Sun did a similar patch, after all?
7227
7228 The story seems to be that when Sun first imported @command{tar}
7229 sources on their system, they recompiled it without realizing that
7230 the checksums were computed differently, because of a change in
7231 the default signing of @code{char}'s in their compiler. So they
7232 started computing checksums wrongly. When they later realized their
7233 mistake, they merely decided to stay compatible with it, and with
7234 themselves afterwards. Presumably, but I do not really know, HP-UX
7235 has chosen that their @command{tar} archives to be compatible with Sun's.
7236 The current standards do not favor Sun @command{tar} format. In any
7237 case, it now falls on the shoulders of SunOS and HP-UX users to get
7238 a @command{tar} able to read the good archives they receive.
7239
7240 @node Large or Negative Values
7241 @subsection Large or Negative Values
7242 @cindex large values
7243 @cindex future time stamps
7244 @cindex negative time stamps
7245 @UNREVISED{}
7246
7247 The above sections suggest to use @samp{oldest possible} archive
7248 format if in doubt. However, sometimes it is not possible. If you
7249 attempt to archive a file whose metadata cannot be represented using
7250 required format, @GNUTAR{} will print error message and ignore such a
7251 file. You will than have to switch to a format that is able to
7252 handle such values. The format summary table (@pxref{Formats}) will
7253 help you to do so.
7254
7255 In particular, when trying to archive files larger than 8GB or with
7256 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
7257 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
7258 @acronym{POSIX} archive formats. When considering which format to
7259 choose, bear in mind that the @acronym{GNU} format uses
7260 two's-complement base-256 notation to store values that do not fit
7261 into standard @acronym{ustar} range. Such archives can generally be
7262 read only by a @GNUTAR{} implementation. Moreover, they sometimes
7263 cannot be correctly restored on another hosts even by @GNUTAR{}. For
7264 example, using two's complement representation for negative time
7265 stamps that assumes a signed 32-bit @code{time_t} generates archives
7266 that are not portable to hosts with differing @code{time_t}
7267 representations.
7268
7269 On the other hand, @acronym{POSIX} archives, generally speaking, can
7270 be extracted by any tar implementation that understands older
7271 @acronym{ustar} format. The only exception are files larger than 8GB.
7272
7273 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
7274 POSIX-aware tars.}
7275
7276 @node Compression
7277 @section Using Less Space through Compression
7278
7279 @menu
7280 * gzip:: Creating and Reading Compressed Archives
7281 * sparse:: Archiving Sparse Files
7282 @end menu
7283
7284 @node gzip
7285 @subsection Creating and Reading Compressed Archives
7286 @cindex Compressed archives
7287 @cindex Storing archives in compressed format
7288
7289 @GNUTAR{} is able to create and read compressed archives. It supports
7290 @command{gzip} and @command{bzip2} compression programs. For backward
7291 compatibilty, it also supports @command{compress} command, although
7292 we strongly recommend against using it, since there is a patent
7293 covering the algorithm it uses and you could be sued for patent
7294 infringement merely by running @command{compress}! Besides, it is less
7295 effective than @command{gzip} and @command{bzip2}.
7296
7297 Creating a compressed archive is simple: you just specify a
7298 @dfn{compression option} along with the usual archive creation
7299 commands. The compression option is @option{-z} (@option{--gzip}) to
7300 create a @command{gzip} compressed archive, @option{-j}
7301 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7302 @option{-Z} (@option{--compress}) to use @command{compress} program.
7303 For example:
7304
7305 @smallexample
7306 $ @kbd{tar cfz archive.tar.gz .}
7307 @end smallexample
7308
7309 Reading compressed archive is even simpler: you don't need to specify
7310 any additional options as @GNUTAR{} recognizes its format
7311 automatically. Thus, the following commands will list and extract the
7312 archive created in previous example:
7313
7314 @smallexample
7315 # List the compressed archive
7316 $ @kbd{tar tf archive.tar.gz}
7317 # Extract the compressed archive
7318 $ @kbd{tar xf archive.tar.gz}
7319 @end smallexample
7320
7321 The only case when you have to specify a decompression option while
7322 reading the archive is when reading from a pipe or from a tape drive
7323 that does not support random access. However, in this case @GNUTAR{}
7324 will indicate which option you should use. For example:
7325
7326 @smallexample
7327 $ @kbd{cat archive.tar.gz | tar tf -}
7328 tar: Archive is compressed. Use -z option
7329 tar: Error is not recoverable: exiting now
7330 @end smallexample
7331
7332 If you see such diagnostics, just add the suggested option to the
7333 invocation of @GNUTAR{}:
7334
7335 @smallexample
7336 $ @kbd{cat archive.tar.gz | tar tfz -}
7337 @end smallexample
7338
7339 Notice also, that there are several restrictions on operations on
7340 compressed archives. First of all, compressed archives cannot be
7341 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
7342 (@option{--delete}) members from them. Likewise, you cannot append
7343 another @command{tar} archive to a compressed archive using
7344 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
7345 compressed.
7346
7347 The following table summarizes compression options used by @GNUTAR{}.
7348
7349 @table @option
7350 @opindex gzip
7351 @opindex ungzip
7352 @item -z
7353 @itemx --gzip
7354 @itemx --ungzip
7355 Filter the archive through @command{gzip}.
7356
7357 You can use @option{--gzip} and @option{--gunzip} on physical devices
7358 (tape drives, etc.) and remote files as well as on normal files; data
7359 to or from such devices or remote files is reblocked by another copy
7360 of the @command{tar} program to enforce the specified (or default) record
7361 size. The default compression parameters are used; if you need to
7362 override them, set @env{GZIP} environment variable, e.g.:
7363
7364 @smallexample
7365 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
7366 @end smallexample
7367
7368 @noindent
7369 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
7370 @command{gzip} explicitly:
7371
7372 @smallexample
7373 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
7374 @end smallexample
7375
7376 @cindex corrupted archives
7377 About corrupted compressed archives: @command{gzip}'ed files have no
7378 redundancy, for maximum compression. The adaptive nature of the
7379 compression scheme means that the compression tables are implicitly
7380 spread all over the archive. If you lose a few blocks, the dynamic
7381 construction of the compression tables becomes unsynchronized, and there
7382 is little chance that you could recover later in the archive.
7383
7384 There are pending suggestions for having a per-volume or per-file
7385 compression in @GNUTAR{}. This would allow for viewing the
7386 contents without decompression, and for resynchronizing decompression at
7387 every volume or file, in case of corrupted archives. Doing so, we might
7388 lose some compressibility. But this would have make recovering easier.
7389 So, there are pros and cons. We'll see!
7390
7391 @opindex bzip2
7392 @item -j
7393 @itemx --bzip2
7394 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
7395
7396 @opindex compress
7397 @opindex uncompress
7398 @item -Z
7399 @itemx --compress
7400 @itemx --uncompress
7401 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
7402
7403 The @acronym{GNU} Project recommends you not use
7404 @command{compress}, because there is a patent covering the algorithm it
7405 uses. You could be sued for patent infringement merely by running
7406 @command{compress}.
7407
7408 @opindex use-compress-program
7409 @item --use-compress-program=@var{prog}
7410 Use external compression program @var{prog}. Use this option if you
7411 have a compression program that @GNUTAR{} does not support. There
7412 are two requirements to which @var{prog} should comply:
7413
7414 First, when called without options, it should read data from standard
7415 input, compress it and output it on standard output.
7416
7417 Secondly, if called with @option{-d} argument, it should do exactly
7418 the opposite, i.e., read the compressed data from the standard input
7419 and produce uncompressed data on the standard output.
7420 @end table
7421
7422 @cindex gpg, using with tar
7423 @cindex gnupg, using with tar
7424 @cindex Using encrypted archives
7425 The @option{--use-compress-program} option, in particular, lets you
7426 implement your own filters, not necessarily dealing with
7427 compression/decomression. For example, suppose you wish to implement
7428 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
7429 gpg, gpg ---- encryption and signing tool, gpg}). The following
7430 script does that:
7431
7432 @smallexample
7433 @group
7434 #! /bin/sh
7435 case $1 in
7436 -d) gpg --decrypt - | gzip -d -c;;
7437 '') gzip -c | gpg -s ;;
7438 *) echo "Unknown option $1">&2; exit 1;;
7439 esac
7440 @end group
7441 @end smallexample
7442
7443 Suppose you name it @file{gpgz} and save it somewhere in your
7444 @env{PATH}. Then the following command will create a commpressed
7445 archive signed with your private key:
7446
7447 @smallexample
7448 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
7449 @end smallexample
7450
7451 @noindent
7452 Likewise, the following command will list its contents:
7453
7454 @smallexample
7455 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
7456 @end smallexample
7457
7458 @ignore
7459 The above is based on the following discussion:
7460
7461 I have one question, or maybe it's a suggestion if there isn't a way
7462 to do it now. I would like to use @option{--gzip}, but I'd also like
7463 the output to be fed through a program like @acronym{GNU}
7464 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7465 to use :-)), basically adding ECC protection on top of compression.
7466 It seems as if this should be quite easy to do, but I can't work out
7467 exactly how to go about it. Of course, I can pipe the standard output
7468 of @command{tar} through @command{ecc}, but then I lose (though I
7469 haven't started using it yet, I confess) the ability to have
7470 @command{tar} use @command{rmt} for it's I/O (I think).
7471
7472 I think the most straightforward thing would be to let me specify a
7473 general set of filters outboard of compression (preferably ordered,
7474 so the order can be automatically reversed on input operations, and
7475 with the options they require specifiable), but beggars shouldn't be
7476 choosers and anything you decide on would be fine with me.
7477
7478 By the way, I like @command{ecc} but if (as the comments say) it can't
7479 deal with loss of block sync, I'm tempted to throw some time at adding
7480 that capability. Supposing I were to actually do such a thing and
7481 get it (apparently) working, do you accept contributed changes to
7482 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7483
7484 Isn't that exactly the role of the
7485 @option{--use-compress-prog=@var{program}} option?
7486 I never tried it myself, but I suspect you may want to write a
7487 @var{prog} script or program able to filter stdin to stdout to
7488 way you want. It should recognize the @option{-d} option, for when
7489 extraction is needed rather than creation.
7490
7491 It has been reported that if one writes compressed data (through the
7492 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
7493 the DLT compression mode, the data will actually get bigger and one will
7494 end up with less space on the tape.
7495 @end ignore
7496
7497 @node sparse
7498 @subsection Archiving Sparse Files
7499 @cindex Sparse Files
7500 @UNREVISED
7501
7502 @table @option
7503 @opindex sparse
7504 @item -S
7505 @itemx --sparse
7506 Handle sparse files efficiently.
7507 @end table
7508
7509 This option causes all files to be put in the archive to be tested for
7510 sparseness, and handled specially if they are. The @option{--sparse}
7511 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
7512 backed up. Using this option dramatically decreases the amount of
7513 space needed to store such a file.
7514
7515 In later versions, this option may be removed, and the testing and
7516 treatment of sparse files may be done automatically with any special
7517 @acronym{GNU} options. For now, it is an option needing to be specified on
7518 the command line with the creation or updating of an archive.
7519
7520 Files in the file system occasionally have ``holes.'' A hole in a file
7521 is a section of the file's contents which was never written. The
7522 contents of a hole read as all zeros. On many operating systems,
7523 actual disk storage is not allocated for holes, but they are counted
7524 in the length of the file. If you archive such a file, @command{tar}
7525 could create an archive longer than the original. To have @command{tar}
7526 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
7527 you use this option, then, for any file using less disk space than
7528 would be expected from its length, @command{tar} searches the file for
7529 consecutive stretches of zeros. It then records in the archive for
7530 the file where the consecutive stretches of zeros are, and only
7531 archives the ``real contents'' of the file. On extraction (using
7532 @option{--sparse} is not needed on extraction) any such
7533 files have holes created wherever the continuous stretches of zeros
7534 were found. Thus, if you use @option{--sparse}, @command{tar} archives
7535 won't take more space than the original.
7536
7537 A file is sparse if it contains blocks of zeros whose existence is
7538 recorded, but that have no space allocated on disk. When you specify
7539 the @option{--sparse} option in conjunction with the @option{--create}
7540 (@option{-c}) operation, @command{tar} tests all files for sparseness
7541 while archiving. If @command{tar} finds a file to be sparse, it uses a
7542 sparse representation of the file in the archive. @xref{create}, for
7543 more information about creating archives.
7544
7545 @option{--sparse} is useful when archiving files, such as dbm files,
7546 likely to contain many nulls. This option dramatically
7547 decreases the amount of space needed to store such an archive.
7548
7549 @quotation
7550 @strong{Please Note:} Always use @option{--sparse} when performing file
7551 system backups, to avoid archiving the expanded forms of files stored
7552 sparsely in the system.
7553
7554 Even if your system has no sparse files currently, some may be
7555 created in the future. If you use @option{--sparse} while making file
7556 system backups as a matter of course, you can be assured the archive
7557 will never take more space on the media than the files take on disk
7558 (otherwise, archiving a disk filled with sparse files might take
7559 hundreds of tapes). @xref{Incremental Dumps}.
7560 @end quotation
7561
7562 @command{tar} ignores the @option{--sparse} option when reading an archive.
7563
7564 @table @option
7565 @item --sparse
7566 @itemx -S
7567 Files stored sparsely in the file system are represented sparsely in
7568 the archive. Use in conjunction with write operations.
7569 @end table
7570
7571 However, users should be well aware that at archive creation time,
7572 @GNUTAR{} still has to read whole disk file to
7573 locate the @dfn{holes}, and so, even if sparse files use little space
7574 on disk and in the archive, they may sometimes require inordinate
7575 amount of time for reading and examining all-zero blocks of a file.
7576 Although it works, it's painfully slow for a large (sparse) file, even
7577 though the resulting tar archive may be small. (One user reports that
7578 dumping a @file{core} file of over 400 megabytes, but with only about
7579 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
7580 ELC, with full CPU utilization.)
7581
7582 This reading is required in all cases and is not related to the fact
7583 the @option{--sparse} option is used or not, so by merely @emph{not}
7584 using the option, you are not saving time@footnote{Well! We should say
7585 the whole truth, here. When @option{--sparse} is selected while creating
7586 an archive, the current @command{tar} algorithm requires sparse files to be
7587 read twice, not once. We hope to develop a new archive format for saving
7588 sparse files in which one pass will be sufficient.}.
7589
7590 Programs like @command{dump} do not have to read the entire file; by
7591 examining the file system directly, they can determine in advance
7592 exactly where the holes are and thus avoid reading through them. The
7593 only data it need read are the actual allocated data blocks.
7594 @GNUTAR{} uses a more portable and straightforward
7595 archiving approach, it would be fairly difficult that it does
7596 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
7597 1990-12-10:
7598
7599 @quotation
7600 What I did say is that you cannot tell the difference between a hole and an
7601 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
7602 best tells you how many holes there are; it doesn't tell you @emph{where}.
7603 Just as programs may, conceivably, care what @code{st_blocks} is (care
7604 to name one that does?), they may also care where the holes are (I have
7605 no examples of this one either, but it's equally imaginable).
7606
7607 I conclude from this that good archivers are not portable. One can
7608 arguably conclude that if you want a portable program, you can in good
7609 conscience restore files with as many holes as possible, since you can't
7610 get it right.
7611 @end quotation
7612
7613 @node Attributes
7614 @section Handling File Attributes
7615 @UNREVISED
7616
7617 When @command{tar} reads files, it updates their access times. To
7618 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
7619 reset the access time retroactively or avoid changing it in the first
7620 place.
7621
7622 Handling of file attributes
7623
7624 @table @option
7625 @opindex atime-preserve
7626 @item --atime-preserve
7627 @itemx --atime-preserve=replace
7628 @itemx --atime-preserve=system
7629 Preserve the access times of files that are read. This works only for
7630 files that you own, unless you have superuser privileges.
7631
7632 @option{--atime-preserve=replace} works on most systems, but it also
7633 restores the data modification time and updates the status change
7634 time. Hence it doesn't interact with incremental dumps nicely
7635 (@pxref{Backups}), and it can set access or data modification times
7636 incorrectly if other programs access the file while @command{tar} is
7637 running.
7638
7639 @option{--atime-preserve=system} avoids changing the access time in
7640 the first place, if the operating system supports this.
7641 Unfortunately, this may or may not work on any given operating system
7642 or file system. If @command{tar} knows for sure it won't work, it
7643 complains right away.
7644
7645 Currently @option{--atime-preserve} with no operand defaults to
7646 @option{--atime-preserve=replace}, but this is intended to change to
7647 @option{--atime-preserve=system} when the latter is better-supported.
7648
7649 @opindex touch
7650 @item -m
7651 @itemx --touch
7652 Do not extract data modification time.
7653
7654 When this option is used, @command{tar} leaves the data modification times
7655 of the files it extracts as the times when the files were extracted,
7656 instead of setting it to the times recorded in the archive.
7657
7658 This option is meaningless with @option{--list} (@option{-t}).
7659
7660 @opindex same-owner
7661 @item --same-owner
7662 Create extracted files with the same ownership they have in the
7663 archive.
7664
7665 This is the default behavior for the superuser,
7666 so this option is meaningful only for non-root users, when @command{tar}
7667 is executed on those systems able to give files away. This is
7668 considered as a security flaw by many people, at least because it
7669 makes quite difficult to correctly account users for the disk space
7670 they occupy. Also, the @code{suid} or @code{sgid} attributes of
7671 files are easily and silently lost when files are given away.
7672
7673 When writing an archive, @command{tar} writes the user id and user name
7674 separately. If it can't find a user name (because the user id is not
7675 in @file{/etc/passwd}), then it does not write one. When restoring,
7676 it tries to look the name (if one was written) up in
7677 @file{/etc/passwd}. If it fails, then it uses the user id stored in
7678 the archive instead.
7679
7680 @opindex no-same-owner
7681 @item --no-same-owner
7682 @itemx -o
7683 Do not attempt to restore ownership when extracting. This is the
7684 default behavior for ordinary users, so this option has an effect
7685 only for the superuser.
7686
7687 @opindex numeric-owner
7688 @item --numeric-owner
7689 The @option{--numeric-owner} option allows (ANSI) archives to be written
7690 without user/group name information or such information to be ignored
7691 when extracting. It effectively disables the generation and/or use
7692 of user/group name information. This option forces extraction using
7693 the numeric ids from the archive, ignoring the names.
7694
7695 This is useful in certain circumstances, when restoring a backup from
7696 an emergency floppy with different passwd/group files for example.
7697 It is otherwise impossible to extract files with the right ownerships
7698 if the password file in use during the extraction does not match the
7699 one belonging to the file system(s) being extracted. This occurs,
7700 for example, if you are restoring your files after a major crash and
7701 had booted from an emergency floppy with no password file or put your
7702 disk into another machine to do the restore.
7703
7704 The numeric ids are @emph{always} saved into @command{tar} archives.
7705 The identifying names are added at create time when provided by the
7706 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
7707 used when moving archives between a collection of machines using
7708 a centralized management for attribution of numeric ids to users
7709 and groups. This is often made through using the NIS capabilities.
7710
7711 When making a @command{tar} file for distribution to other sites, it
7712 is sometimes cleaner to use a single owner for all files in the
7713 distribution, and nicer to specify the write permission bits of the
7714 files as stored in the archive independently of their actual value on
7715 the file system. The way to prepare a clean distribution is usually
7716 to have some Makefile rule creating a directory, copying all needed
7717 files in that directory, then setting ownership and permissions as
7718 wanted (there are a lot of possible schemes), and only then making a
7719 @command{tar} archive out of this directory, before cleaning
7720 everything out. Of course, we could add a lot of options to
7721 @GNUTAR{} for fine tuning permissions and ownership.
7722 This is not the good way, I think. @GNUTAR{} is
7723 already crowded with options and moreover, the approach just explained
7724 gives you a great deal of control already.
7725
7726 @opindex same-permissions, short description
7727 @opindex preserve-permissions, short description
7728 @item -p
7729 @itemx --same-permissions
7730 @itemx --preserve-permissions
7731 Extract all protection information.
7732
7733 This option causes @command{tar} to set the modes (access permissions) of
7734 extracted files exactly as recorded in the archive. If this option
7735 is not used, the current @code{umask} setting limits the permissions
7736 on extracted files. This option is by default enabled when
7737 @command{tar} is executed by a superuser.
7738
7739
7740 This option is meaningless with @option{--list} (@option{-t}).
7741
7742 @opindex preserve
7743 @item --preserve
7744 Same as both @option{--same-permissions} and @option{--same-order}.
7745
7746 The @option{--preserve} option has no equivalent short option name.
7747 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
7748
7749 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
7750 Neither do I. --Sergey}
7751
7752 @end table
7753
7754 @node Standard
7755 @section Basic Tar Format
7756 @UNREVISED
7757
7758 While an archive may contain many files, the archive itself is a
7759 single ordinary file. Like any other file, an archive file can be
7760 written to a storage device such as a tape or disk, sent through a
7761 pipe or over a network, saved on the active file system, or even
7762 stored in another archive. An archive file is not easy to read or
7763 manipulate without using the @command{tar} utility or Tar mode in
7764 @acronym{GNU} Emacs.
7765
7766 Physically, an archive consists of a series of file entries terminated
7767 by an end-of-archive entry, which consists of two 512 blocks of zero
7768 bytes. A file
7769 entry usually describes one of the files in the archive (an
7770 @dfn{archive member}), and consists of a file header and the contents
7771 of the file. File headers contain file names and statistics, checksum
7772 information which @command{tar} uses to detect file corruption, and
7773 information about file types.
7774
7775 Archives are permitted to have more than one member with the same
7776 member name. One way this situation can occur is if more than one
7777 version of a file has been stored in the archive. For information
7778 about adding new versions of a file to an archive, see @ref{update}.
7779 @FIXME-xref{To learn more about having more than one archive member with the
7780 same name, see -backup node, when it's written.}
7781
7782 In addition to entries describing archive members, an archive may
7783 contain entries which @command{tar} itself uses to store information.
7784 @xref{label}, for an example of such an archive entry.
7785
7786 A @command{tar} archive file contains a series of blocks. Each block
7787 contains @code{BLOCKSIZE} bytes. Although this format may be thought
7788 of as being on magnetic tape, other media are often used.
7789
7790 Each file archived is represented by a header block which describes
7791 the file, followed by zero or more blocks which give the contents
7792 of the file. At the end of the archive file there are two 512-byte blocks
7793 filled with binary zeros as an end-of-file marker. A reasonable system
7794 should write such end-of-file marker at the end of an archive, but
7795 must not assume that such a block exists when reading an archive. In
7796 particular @GNUTAR{} always issues a warning if it does not encounter it.
7797
7798 The blocks may be @dfn{blocked} for physical I/O operations.
7799 Each record of @var{n} blocks (where @var{n} is set by the
7800 @option{--blocking-factor=@var{512-size}} (@option{-b @var{512-size}}) option to @command{tar}) is written with a single
7801 @w{@samp{write ()}} operation. On magnetic tapes, the result of
7802 such a write is a single record. When writing an archive,
7803 the last record of blocks should be written at the full size, with
7804 blocks after the zero block containing all zeros. When reading
7805 an archive, a reasonable system should properly handle an archive
7806 whose last record is shorter than the rest, or which contains garbage
7807 records after a zero block.
7808
7809 The header block is defined in C as follows. In the @GNUTAR{}
7810 distribution, this is part of file @file{src/tar.h}:
7811
7812 @smallexample
7813 @include header.texi
7814 @end smallexample
7815
7816 All characters in header blocks are represented by using 8-bit
7817 characters in the local variant of ASCII. Each field within the
7818 structure is contiguous; that is, there is no padding used within
7819 the structure. Each character on the archive medium is stored
7820 contiguously.
7821
7822 Bytes representing the contents of files (after the header block
7823 of each file) are not translated in any way and are not constrained
7824 to represent characters in any character set. The @command{tar} format
7825 does not distinguish text files from binary files, and no translation
7826 of file contents is performed.
7827
7828 The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
7829 @code{gname} are null-terminated character strings. All other fields
7830 are zero-filled octal numbers in ASCII. Each numeric field of width
7831 @var{w} contains @var{w} minus 1 digits, and a null.
7832
7833 The @code{name} field is the file name of the file, with directory names
7834 (if any) preceding the file name, separated by slashes.
7835
7836 @FIXME{how big a name before field overflows?}
7837
7838 The @code{mode} field provides nine bits specifying file permissions
7839 and three bits to specify the Set UID, Set GID, and Save Text
7840 (@dfn{sticky}) modes. Values for these bits are defined above.
7841 When special permissions are required to create a file with a given
7842 mode, and the user restoring files from the archive does not hold such
7843 permissions, the mode bit(s) specifying those special permissions
7844 are ignored. Modes which are not supported by the operating system
7845 restoring files from the archive will be ignored. Unsupported modes
7846 should be faked up when creating or updating an archive; e.g., the
7847 group permission could be copied from the @emph{other} permission.
7848
7849 The @code{uid} and @code{gid} fields are the numeric user and group
7850 ID of the file owners, respectively. If the operating system does
7851 not support numeric user or group IDs, these fields should be ignored.
7852
7853 The @code{size} field is the size of the file in bytes; linked files
7854 are archived with this field specified as zero. @FIXME-xref{Modifiers, in
7855 particular the @option{--incremental} (@option{-G}) option.}
7856
7857 The @code{mtime} field is the data modification time of the file at
7858 the time it was archived. It is the ASCII representation of the octal
7859 value of the last time the file's contents were modified, represented
7860 as an integer number of
7861 seconds since January 1, 1970, 00:00 Coordinated Universal Time.
7862
7863 The @code{chksum} field is the ASCII representation of the octal value
7864 of the simple sum of all bytes in the header block. Each 8-bit
7865 byte in the header is added to an unsigned integer, initialized to
7866 zero, the precision of which shall be no less than seventeen bits.
7867 When calculating the checksum, the @code{chksum} field is treated as
7868 if it were all blanks.
7869
7870 The @code{typeflag} field specifies the type of file archived. If a
7871 particular implementation does not recognize or permit the specified
7872 type, the file will be extracted as if it were a regular file. As this
7873 action occurs, @command{tar} issues a warning to the standard error.
7874
7875 The @code{atime} and @code{ctime} fields are used in making incremental
7876 backups; they store, respectively, the particular file's access and
7877 status change times.
7878
7879 The @code{offset} is used by the @option{--multi-volume} (@option{-M}) option, when
7880 making a multi-volume archive. The offset is number of bytes into
7881 the file that we need to restart at to continue the file on the next
7882 tape, i.e., where we store the location that a continued file is
7883 continued at.
7884
7885 The following fields were added to deal with sparse files. A file
7886 is @dfn{sparse} if it takes in unallocated blocks which end up being
7887 represented as zeros, i.e., no useful data. A test to see if a file
7888 is sparse is to look at the number blocks allocated for it versus the
7889 number of characters in the file; if there are fewer blocks allocated
7890 for the file than would normally be allocated for a file of that
7891 size, then the file is sparse. This is the method @command{tar} uses to
7892 detect a sparse file, and once such a file is detected, it is treated
7893 differently from non-sparse files.
7894
7895 Sparse files are often @code{dbm} files, or other database-type files
7896 which have data at some points and emptiness in the greater part of
7897 the file. Such files can appear to be very large when an @samp{ls
7898 -l} is done on them, when in truth, there may be a very small amount
7899 of important data contained in the file. It is thus undesirable
7900 to have @command{tar} think that it must back up this entire file, as
7901 great quantities of room are wasted on empty blocks, which can lead
7902 to running out of room on a tape far earlier than is necessary.
7903 Thus, sparse files are dealt with so that these empty blocks are
7904 not written to the tape. Instead, what is written to the tape is a
7905 description, of sorts, of the sparse file: where the holes are, how
7906 big the holes are, and how much data is found at the end of the hole.
7907 This way, the file takes up potentially far less room on the tape,
7908 and when the file is extracted later on, it will look exactly the way
7909 it looked beforehand. The following is a description of the fields
7910 used to handle a sparse file:
7911
7912 The @code{sp} is an array of @code{struct sparse}. Each @code{struct
7913 sparse} contains two 12-character strings which represent an offset
7914 into the file and a number of bytes to be written at that offset.
7915 The offset is absolute, and not relative to the offset in preceding
7916 array element.
7917
7918 The header can hold four of these @code{struct sparse} at the moment;
7919 if more are needed, they are not stored in the header.
7920
7921 The @code{isextended} flag is set when an @code{extended_header}
7922 is needed to deal with a file. Note that this means that this flag
7923 can only be set when dealing with a sparse file, and it is only set
7924 in the event that the description of the file will not fit in the
7925 allotted room for sparse structures in the header. In other words,
7926 an extended_header is needed.
7927
7928 The @code{extended_header} structure is used for sparse files which
7929 need more sparse structures than can fit in the header. The header can
7930 fit 4 such structures; if more are needed, the flag @code{isextended}
7931 gets set and the next block is an @code{extended_header}.
7932
7933 Each @code{extended_header} structure contains an array of 21
7934 sparse structures, along with a similar @code{isextended} flag
7935 that the header had. There can be an indeterminate number of such
7936 @code{extended_header}s to describe a sparse file.
7937
7938 @table @asis
7939
7940 @item @code{REGTYPE}
7941 @itemx @code{AREGTYPE}
7942 These flags represent a regular file. In order to be compatible
7943 with older versions of @command{tar}, a @code{typeflag} value of
7944 @code{AREGTYPE} should be silently recognized as a regular file.
7945 New archives should be created using @code{REGTYPE}. Also, for
7946 backward compatibility, @command{tar} treats a regular file whose name
7947 ends with a slash as a directory.
7948
7949 @item @code{LNKTYPE}
7950 This flag represents a file linked to another file, of any type,
7951 previously archived. Such files are identified in Unix by each
7952 file having the same device and inode number. The linked-to name is
7953 specified in the @code{linkname} field with a trailing null.
7954
7955 @item @code{SYMTYPE}
7956 This represents a symbolic link to another file. The linked-to name
7957 is specified in the @code{linkname} field with a trailing null.
7958
7959 @item @code{CHRTYPE}
7960 @itemx @code{BLKTYPE}
7961 These represent character special files and block special files
7962 respectively. In this case the @code{devmajor} and @code{devminor}
7963 fields will contain the major and minor device numbers respectively.
7964 Operating systems may map the device specifications to their own
7965 local specification, or may ignore the entry.
7966
7967 @item @code{DIRTYPE}
7968 This flag specifies a directory or sub-directory. The directory
7969 name in the @code{name} field should end with a slash. On systems where
7970 disk allocation is performed on a directory basis, the @code{size} field
7971 will contain the maximum number of bytes (which may be rounded to
7972 the nearest disk block allocation unit) which the directory may
7973 hold. A @code{size} field of zero indicates no such limiting. Systems
7974 which do not support limiting in this manner should ignore the
7975 @code{size} field.
7976
7977 @item @code{FIFOTYPE}
7978 This specifies a FIFO special file. Note that the archiving of a
7979 FIFO file archives the existence of this file and not its contents.
7980
7981 @item @code{CONTTYPE}
7982 This specifies a contiguous file, which is the same as a normal
7983 file except that, in operating systems which support it, all its
7984 space is allocated contiguously on the disk. Operating systems
7985 which do not allow contiguous allocation should silently treat this
7986 type as a normal file.
7987
7988 @item @code{A} @dots{} @code{Z}
7989 These are reserved for custom implementations. Some of these are
7990 used in the @acronym{GNU} modified format, as described below.
7991
7992 @end table
7993
7994 Other values are reserved for specification in future revisions of
7995 the P1003 standard, and should not be used by any @command{tar} program.
7996
7997 The @code{magic} field indicates that this archive was output in
7998 the P1003 archive format. If this field contains @code{TMAGIC},
7999 the @code{uname} and @code{gname} fields will contain the ASCII
8000 representation of the owner and group of the file respectively.
8001 If found, the user and group IDs are used rather than the values in
8002 the @code{uid} and @code{gid} fields.
8003
8004 For references, see ISO/IEC 9945-1:1990 or IEEE Std 1003.1-1990, pages
8005 169-173 (section 10.1) for @cite{Archive/Interchange File Format}; and
8006 IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
8007 (section E.4.48) for @cite{pax - Portable archive interchange}.
8008
8009 @node Extensions
8010 @section @acronym{GNU} Extensions to the Archive Format
8011 @UNREVISED
8012
8013 The @acronym{GNU} format uses additional file types to describe new types of
8014 files in an archive. These are listed below.
8015
8016 @table @code
8017 @item GNUTYPE_DUMPDIR
8018 @itemx 'D'
8019 This represents a directory and a list of files created by the
8020 @option{--incremental} (@option{-G}) option. The @code{size} field gives the total
8021 size of the associated list of files. Each file name is preceded by
8022 either a @samp{Y} (the file should be in this archive) or an @samp{N}.
8023 (The file is a directory, or is not stored in the archive.) Each file
8024 name is terminated by a null. There is an additional null after the
8025 last file name.
8026
8027 @item GNUTYPE_MULTIVOL
8028 @itemx 'M'
8029 This represents a file continued from another volume of a multi-volume
8030 archive created with the @option{--multi-volume} (@option{-M}) option. The original
8031 type of the file is not given here. The @code{size} field gives the
8032 maximum size of this piece of the file (assuming the volume does
8033 not end before the file is written out). The @code{offset} field
8034 gives the offset from the beginning of the file where this part of
8035 the file begins. Thus @code{size} plus @code{offset} should equal
8036 the original size of the file.
8037
8038 @item GNUTYPE_SPARSE
8039 @itemx 'S'
8040 This flag indicates that we are dealing with a sparse file. Note
8041 that archiving a sparse file requires special operations to find
8042 holes in the file, which mark the positions of these holes, along
8043 with the number of bytes of data to be found after the hole.
8044
8045 @item GNUTYPE_VOLHDR
8046 @itemx 'V'
8047 This file type is used to mark the volume header that was given with
8048 the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option when the archive was created. The @code{name}
8049 field contains the @code{name} given after the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option.
8050 The @code{size} field is zero. Only the first file in each volume
8051 of an archive should have this type.
8052
8053 @end table
8054
8055 You may have trouble reading a @acronym{GNU} format archive on a
8056 non-@acronym{GNU} system if the options @option{--incremental} (@option{-G}),
8057 @option{--multi-volume} (@option{-M}), @option{--sparse} (@option{-S}), or @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) were
8058 used when writing the archive. In general, if @command{tar} does not
8059 use the @acronym{GNU}-added fields of the header, other versions of
8060 @command{tar} should be able to read the archive. Otherwise, the
8061 @command{tar} program will give an error, the most likely one being a
8062 checksum error.
8063
8064 @node cpio
8065 @section Comparison of @command{tar} and @command{cpio}
8066 @UNREVISED
8067
8068 @FIXME{Reorganize the following material}
8069
8070 The @command{cpio} archive formats, like @command{tar}, do have maximum
8071 pathname lengths. The binary and old ASCII formats have a max path
8072 length of 256, and the new ASCII and CRC ASCII formats have a max
8073 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8074 with arbitrary pathname lengths, but other @command{cpio} implementations
8075 may crash unexplainedly trying to read them.
8076
8077 @command{tar} handles symbolic links in the form in which it comes in BSD;
8078 @command{cpio} doesn't handle symbolic links in the form in which it comes
8079 in System V prior to SVR4, and some vendors may have added symlinks
8080 to their system without enhancing @command{cpio} to know about them.
8081 Others may have enhanced it in a way other than the way I did it
8082 at Sun, and which was adopted by AT&T (and which is, I think, also
8083 present in the @command{cpio} that Berkeley picked up from AT&T and put
8084 into a later BSD release---I think I gave them my changes).
8085
8086 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8087 can handle @command{tar} format input, and write it on output, and it
8088 probably handles symbolic links. They may not have bothered doing
8089 anything to enhance @command{tar} as a result.)
8090
8091 @command{cpio} handles special files; traditional @command{tar} doesn't.
8092
8093 @command{tar} comes with V7, System III, System V, and BSD source;
8094 @command{cpio} comes only with System III, System V, and later BSD
8095 (4.3-tahoe and later).
8096
8097 @command{tar}'s way of handling multiple hard links to a file can handle
8098 file systems that support 32-bit inumbers (e.g., the BSD file system);
8099 @command{cpio}s way requires you to play some games (in its "binary"
8100 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8101 they're 18 bits---it would have to play games with the "file system ID"
8102 field of the header to make sure that the file system ID/i-number pairs
8103 of different files were always different), and I don't know which
8104 @command{cpio}s, if any, play those games. Those that don't might get
8105 confused and think two files are the same file when they're not, and
8106 make hard links between them.
8107
8108 @command{tar}s way of handling multiple hard links to a file places only
8109 one copy of the link on the tape, but the name attached to that copy
8110 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8111 way puts one copy for every link, but you can retrieve it using any
8112 of the names.
8113
8114 @quotation
8115 What type of check sum (if any) is used, and how is this calculated.
8116 @end quotation
8117
8118 See the attached manual pages for @command{tar} and @command{cpio} format.
8119 @command{tar} uses a checksum which is the sum of all the bytes in the
8120 @command{tar} header for a file; @command{cpio} uses no checksum.
8121
8122 @quotation
8123 If anyone knows why @command{cpio} was made when @command{tar} was present
8124 at the unix scene,
8125 @end quotation
8126
8127 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8128 generally-available version of UNIX had @command{tar} at the time. I don't
8129 know whether any version that was generally available @emph{within AT&T}
8130 had @command{tar}, or, if so, whether the people within AT&T who did
8131 @command{cpio} knew about it.
8132
8133 On restore, if there is a corruption on a tape @command{tar} will stop at
8134 that point, while @command{cpio} will skip over it and try to restore the
8135 rest of the files.
8136
8137 The main difference is just in the command syntax and header format.
8138
8139 @command{tar} is a little more tape-oriented in that everything is blocked
8140 to start on a record boundary.
8141
8142 @quotation
8143 Is there any differences between the ability to recover crashed
8144 archives between the two of them. (Is there any chance of recovering
8145 crashed archives at all.)
8146 @end quotation
8147
8148 Theoretically it should be easier under @command{tar} since the blocking
8149 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8150 However, modern @command{cpio}'s and variations have an option to just
8151 search for the next file header after an error with a reasonable chance
8152 of resyncing. However, lots of tape driver software won't allow you to
8153 continue past a media error which should be the only reason for getting
8154 out of sync unless a file changed sizes while you were writing the
8155 archive.
8156
8157 @quotation
8158 If anyone knows why @command{cpio} was made when @command{tar} was present
8159 at the unix scene, please tell me about this too.
8160 @end quotation
8161
8162 Probably because it is more media efficient (by not blocking everything
8163 and using only the space needed for the headers where @command{tar}
8164 always uses 512 bytes per file header) and it knows how to archive
8165 special files.
8166
8167 You might want to look at the freely available alternatives. The
8168 major ones are @command{afio}, @GNUTAR{}, and
8169 @command{pax}, each of which have their own extensions with some
8170 backwards compatibility.
8171
8172 Sparse files were @command{tar}red as sparse files (which you can
8173 easily test, because the resulting archive gets smaller, and
8174 @acronym{GNU} @command{cpio} can no longer read it).
8175
8176 @node Media
8177 @chapter Tapes and Other Archive Media
8178 @UNREVISED
8179
8180 A few special cases about tape handling warrant more detailed
8181 description. These special cases are discussed below.
8182
8183 Many complexities surround the use of @command{tar} on tape drives. Since
8184 the creation and manipulation of archives located on magnetic tape was
8185 the original purpose of @command{tar}, it contains many features making
8186 such manipulation easier.
8187
8188 Archives are usually written on dismountable media---tape cartridges,
8189 mag tapes, or floppy disks.
8190
8191 The amount of data a tape or disk holds depends not only on its size,
8192 but also on how it is formatted. A 2400 foot long reel of mag tape
8193 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8194 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8195
8196 Magnetic media are re-usable---once the archive on a tape is no longer
8197 needed, the archive can be erased and the tape or disk used over.
8198 Media quality does deteriorate with use, however. Most tapes or disks
8199 should be discarded when they begin to produce data errors. EXABYTE
8200 tape cartridges should be discarded when they generate an @dfn{error
8201 count} (number of non-usable bits) of more than 10k.
8202
8203 Magnetic media are written and erased using magnetic fields, and
8204 should be protected from such fields to avoid damage to stored data.
8205 Sticking a floppy disk to a filing cabinet using a magnet is probably
8206 not a good idea.
8207
8208 @menu
8209 * Device:: Device selection and switching
8210 * Remote Tape Server::
8211 * Common Problems and Solutions::
8212 * Blocking:: Blocking
8213 * Many:: Many archives on one tape
8214 * Using Multiple Tapes:: Using Multiple Tapes
8215 * label:: Including a Label in the Archive
8216 * verify::
8217 * Write Protection::
8218 @end menu
8219
8220 @node Device
8221 @section Device Selection and Switching
8222 @UNREVISED
8223
8224 @table @option
8225 @item -f [@var{hostname}:]@var{file}
8226 @itemx --file=[@var{hostname}:]@var{file}
8227 Use archive file or device @var{file} on @var{hostname}.
8228 @end table
8229
8230 This option is used to specify the file name of the archive @command{tar}
8231 works on.
8232
8233 If the file name is @samp{-}, @command{tar} reads the archive from standard
8234 input (when listing or extracting), or writes it to standard output
8235 (when creating). If the @samp{-} file name is given when updating an
8236 archive, @command{tar} will read the original archive from its standard
8237 input, and will write the entire new archive to its standard output.
8238
8239 If the file name contains a @samp{:}, it is interpreted as
8240 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8241 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8242 either case, @command{tar} will invoke the command @command{rsh} (or
8243 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8244 machine. If you give an alternate login name, it will be given to the
8245 @command{rsh}.
8246 Naturally, the remote machine must have an executable
8247 @command{/usr/libexec/rmt}. This program is free software from the
8248 University of California, and a copy of the source code can be found
8249 with the sources for @command{tar}; it's compiled and installed by default.
8250 The exact path to this utility is determined when configuring the package.
8251 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8252 your installation prefix. This location may also be overridden at
8253 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8254 ---rmt-command}, for detailed description of this option. @xref{Remote
8255 Tape Server}, for the description of @command{rmt} command).
8256
8257 If this option is not given, but the environment variable @env{TAPE}
8258 is set, its value is used; otherwise, old versions of @command{tar}
8259 used a default archive name (which was picked when @command{tar} was
8260 compiled). The default is normally set up to be the @dfn{first} tape
8261 drive or other transportable I/O medium on the system.
8262
8263 Starting with version 1.11.5, @GNUTAR{} uses
8264 standard input and standard output as the default device, and I will
8265 not try anymore supporting automatic device detection at installation
8266 time. This was failing really in too many cases, it was hopeless.
8267 This is now completely left to the installer to override standard
8268 input and standard output for default device, if this seems
8269 preferable. Further, I think @emph{most} actual usages of
8270 @command{tar} are done with pipes or disks, not really tapes,
8271 cartridges or diskettes.
8272
8273 Some users think that using standard input and output is running
8274 after trouble. This could lead to a nasty surprise on your screen if
8275 you forget to specify an output file name---especially if you are going
8276 through a network or terminal server capable of buffering large amounts
8277 of output. We had so many bug reports in that area of configuring
8278 default tapes automatically, and so many contradicting requests, that
8279 we finally consider the problem to be portably intractable. We could
8280 of course use something like @samp{/dev/tape} as a default, but this
8281 is @emph{also} running after various kind of trouble, going from hung
8282 processes to accidental destruction of real tapes. After having seen
8283 all this mess, using standard input and output as a default really
8284 sounds like the only clean choice left, and a very useful one too.
8285
8286 @GNUTAR{} reads and writes archive in records, I
8287 suspect this is the main reason why block devices are preferred over
8288 character devices. Most probably, block devices are more efficient
8289 too. The installer could also check for @samp{DEFTAPE} in
8290 @file{<sys/mtio.h>}.
8291
8292 @table @option
8293 @opindex force-local, short description
8294 @item --force-local
8295 Archive file is local even if it contains a colon.
8296
8297 @opindex rsh-command
8298 @item --rsh-command=@var{command}
8299 Use remote @var{command} instead of @command{rsh}. This option exists
8300 so that people who use something other than the standard @command{rsh}
8301 (e.g., a Kerberized @command{rsh}) can access a remote device.
8302
8303 When this command is not used, the shell command found when
8304 the @command{tar} program was installed is used instead. This is
8305 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8306 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8307 The installer may have overridden this by defining the environment
8308 variable @env{RSH} @emph{at installation time}.
8309
8310 @item -[0-7][lmh]
8311 Specify drive and density.
8312
8313 @opindex multi-volume, short description
8314 @item -M
8315 @itemx --multi-volume
8316 Create/list/extract multi-volume archive.
8317
8318 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8319 that may be larger than will fit on the medium used to hold it.
8320 @xref{Multi-Volume Archives}.
8321
8322 @opindex tape-length, short description
8323 @item -L @var{num}
8324 @itemx --tape-length=@var{num}
8325 Change tape after writing @var{num} x 1024 bytes.
8326
8327 This option might be useful when your tape drivers do not properly
8328 detect end of physical tapes. By being slightly conservative on the
8329 maximum tape length, you might avoid the problem entirely.
8330
8331 @opindex info-script, short description
8332 @opindex new-volume-script, short description
8333 @item -F @var{file}
8334 @itemx --info-script=@var{file}
8335 @itemx --new-volume-script=@var{file}
8336 Execute @file{file} at end of each tape. This implies
8337 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8338 description of this option.
8339 @end table
8340
8341 @node Remote Tape Server
8342 @section The Remote Tape Server
8343
8344 @cindex remote tape drive
8345 @pindex rmt
8346 In order to access the tape drive on a remote machine, @command{tar}
8347 uses the remote tape server written at the University of California at
8348 Berkeley. The remote tape server must be installed as
8349 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8350 want to use. @command{tar} calls @command{rmt} by running an
8351 @command{rsh} or @command{remsh} to the remote machine, optionally
8352 using a different login name if one is supplied.
8353
8354 A copy of the source for the remote tape server is provided. It is
8355 Copyright @copyright{} 1983 by the Regents of the University of
8356 California, but can be freely distributed. It is compiled and
8357 installed by default.
8358
8359 @cindex absolute file names
8360 Unless you use the @option{--absolute-names} (@option{-P}) option,
8361 @GNUTAR{} will not allow you to create an archive that contains
8362 absolute file names (a file name beginning with @samp{/}.) If you try,
8363 @command{tar} will automatically remove the leading @samp{/} from the
8364 file names it stores in the archive. It will also type a warning
8365 message telling you what it is doing.
8366
8367 When reading an archive that was created with a different
8368 @command{tar} program, @GNUTAR{} automatically
8369 extracts entries in the archive which have absolute file names as if
8370 the file names were not absolute. This is an important feature. A
8371 visitor here once gave a @command{tar} tape to an operator to restore;
8372 the operator used Sun @command{tar} instead of @GNUTAR{},
8373 and the result was that it replaced large portions of
8374 our @file{/bin} and friends with versions from the tape; needless to
8375 say, we were unhappy about having to recover the file system from
8376 backup tapes.
8377
8378 For example, if the archive contained a file @file{/usr/bin/computoy},
8379 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8380 relative to the current directory. If you want to extract the files in
8381 an archive to the same absolute names that they had when the archive
8382 was created, you should do a @samp{cd /} before extracting the files
8383 from the archive, or you should either use the @option{--absolute-names}
8384 option, or use the command @samp{tar -C / @dots{}}.
8385
8386 @cindex Ultrix 3.1 and write failure
8387 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8388 can claim that a short write near the end of a tape succeeded,
8389 when it actually failed. This will result in the -M option not
8390 working correctly. The best workaround at the moment is to use a
8391 significantly larger blocking factor than the default 20.
8392
8393 In order to update an archive, @command{tar} must be able to backspace the
8394 archive in order to reread or rewrite a record that was just read (or
8395 written). This is currently possible only on two kinds of files: normal
8396 disk files (or any other file that can be backspaced with @samp{lseek}),
8397 and industry-standard 9-track magnetic tape (or any other kind of tape
8398 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8399
8400 This means that the @option{--append}, @option{--concatenate}, and
8401 @option{--delete} commands will not work on any other kind of file.
8402 Some media simply cannot be backspaced, which means these commands and
8403 options will never be able to work on them. These non-backspacing
8404 media include pipes and cartridge tape drives.
8405
8406 Some other media can be backspaced, and @command{tar} will work on them
8407 once @command{tar} is modified to do so.
8408
8409 Archives created with the @option{--multi-volume}, @option{--label}, and
8410 @option{--incremental} (@option{-G}) options may not be readable by other version
8411 of @command{tar}. In particular, restoring a file that was split over
8412 a volume boundary will require some careful work with @command{dd}, if
8413 it can be done at all. Other versions of @command{tar} may also create
8414 an empty file whose name is that of the volume header. Some versions
8415 of @command{tar} may create normal files instead of directories archived
8416 with the @option{--incremental} (@option{-G}) option.
8417
8418 @node Common Problems and Solutions
8419 @section Some Common Problems and their Solutions
8420
8421 @ifclear PUBLISH
8422
8423 @format
8424 errors from system:
8425 permission denied
8426 no such file or directory
8427 not owner
8428
8429 errors from @command{tar}:
8430 directory checksum error
8431 header format error
8432
8433 errors from media/system:
8434 i/o error
8435 device busy
8436 @end format
8437
8438 @end ifclear
8439
8440 @node Blocking
8441 @section Blocking
8442 @UNREVISED
8443
8444 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8445 is also confusing to the expert reader. On the other hand, readers
8446 who are new to the field have a fresh mind, and they may safely skip
8447 the next two paragraphs, as the remainder of this manual uses those
8448 two terms in a quite consistent way.
8449
8450 John Gilmore, the writer of the public domain @command{tar} from which
8451 @GNUTAR{} was originally derived, wrote (June 1995):
8452
8453 @quotation
8454 The nomenclature of tape drives comes from IBM, where I believe
8455 they were invented for the IBM 650 or so. On IBM mainframes, what
8456 is recorded on tape are tape blocks. The logical organization of
8457 data is into records. There are various ways of putting records into
8458 blocks, including @code{F} (fixed sized records), @code{V} (variable
8459 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8460 to a block), @code{VB} (variable size records, @var{n} to a block),
8461 @code{VSB} (variable spanned blocked: variable sized records that can
8462 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8463 parameter specified this to the operating system.
8464
8465 The Unix man page on @command{tar} was totally confused about this.
8466 When I wrote @code{PD TAR}, I used the historically correct terminology
8467 (@command{tar} writes data records, which are grouped into blocks).
8468 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8469 here), and now Fran@,{c}ois has migrated that terminology back
8470 into the source code too.
8471 @end quotation
8472
8473 The term @dfn{physical block} means the basic transfer chunk from or
8474 to a device, after which reading or writing may stop without anything
8475 being lost. In this manual, the term @dfn{block} usually refers to
8476 a disk physical block, @emph{assuming} that each disk block is 512
8477 bytes in length. It is true that some disk devices have different
8478 physical blocks, but @command{tar} ignore these differences in its own
8479 format, which is meant to be portable, so a @command{tar} block is always
8480 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8481 The term @dfn{logical block} often represents the basic chunk of
8482 allocation of many disk blocks as a single entity, which the operating
8483 system treats somewhat atomically; this concept is only barely used
8484 in @GNUTAR{}.
8485
8486 The term @dfn{physical record} is another way to speak of a physical
8487 block, those two terms are somewhat interchangeable. In this manual,
8488 the term @dfn{record} usually refers to a tape physical block,
8489 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8490 It is true that archives may be put on disk or used with pipes,
8491 but nevertheless, @command{tar} tries to read and write the archive one
8492 @dfn{record} at a time, whatever the medium in use. One record is made
8493 up of an integral number of blocks, and this operation of putting many
8494 disk blocks into a single tape block is called @dfn{reblocking}, or
8495 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8496 the logical organization of many characters into something meaningful
8497 to the application. The term @dfn{unit record} describes a small set
8498 of characters which are transmitted whole to or by the application,
8499 and often refers to a line of text. Those two last terms are unrelated
8500 to what we call a @dfn{record} in @GNUTAR{}.
8501
8502 When writing to tapes, @command{tar} writes the contents of the archive
8503 in chunks known as @dfn{records}. To change the default blocking
8504 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8505 @var{512-size}}) option. Each record will then be composed of
8506 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8507 @xref{Standard}.) Each file written to the archive uses at least one
8508 full record. As a result, using a larger record size can result in
8509 more wasted space for small files. On the other hand, a larger record
8510 size can often be read and written much more efficiently.
8511
8512 Further complicating the problem is that some tape drives ignore the
8513 blocking entirely. For these, a larger record size can still improve
8514 performance (because the software layers above the tape drive still
8515 honor the blocking), but not as dramatically as on tape drives that
8516 honor blocking.
8517
8518 When reading an archive, @command{tar} can usually figure out the
8519 record size on itself. When this is the case, and a non-standard
8520 record size was used when the archive was created, @command{tar} will
8521 print a message about a non-standard blocking factor, and then operate
8522 normally. On some tape devices, however, @command{tar} cannot figure
8523 out the record size itself. On most of those, you can specify a
8524 blocking factor (with @option{--blocking-factor}) larger than the
8525 actual blocking factor, and then use the @option{--read-full-records}
8526 (@option{-B}) option. (If you specify a blocking factor with
8527 @option{--blocking-factor} and don't use the
8528 @option{--read-full-records} option, then @command{tar} will not
8529 attempt to figure out the recording size itself.) On some devices,
8530 you must always specify the record size exactly with
8531 @option{--blocking-factor} when reading, because @command{tar} cannot
8532 figure it out. In any case, use @option{--list} (@option{-t}) before
8533 doing any extractions to see whether @command{tar} is reading the archive
8534 correctly.
8535
8536 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8537 putting them into records is to put a whole number of them (one or
8538 more) into each record. @command{tar} records are all the same size;
8539 at the end of the file there's a block containing all zeros, which
8540 is how you tell that the remainder of the last record(s) are garbage.
8541
8542 In a standard @command{tar} file (no options), the block size is 512
8543 and the record size is 10240, for a blocking factor of 20. What the
8544 @option{--blocking-factor} option does is sets the blocking factor,
8545 changing the record size while leaving the block size at 512 bytes.
8546 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8547 most tape drives these days prefer much bigger records in order to
8548 stream and not waste tape. When writing tapes for myself, some tend
8549 to use a factor of the order of 2048, say, giving a record size of
8550 around one megabyte.
8551
8552 If you use a blocking factor larger than 20, older @command{tar}
8553 programs might not be able to read the archive, so we recommend this
8554 as a limit to use in practice. @GNUTAR{}, however,
8555 will support arbitrarily large record sizes, limited only by the
8556 amount of virtual memory or the physical characteristics of the tape
8557 device.
8558
8559 @menu
8560 * Format Variations:: Format Variations
8561 * Blocking Factor:: The Blocking Factor of an Archive
8562 @end menu
8563
8564 @node Format Variations
8565 @subsection Format Variations
8566 @cindex Format Parameters
8567 @cindex Format Options
8568 @cindex Options, archive format specifying
8569 @cindex Options, format specifying
8570 @UNREVISED
8571
8572 Format parameters specify how an archive is written on the archive
8573 media. The best choice of format parameters will vary depending on
8574 the type and number of files being archived, and on the media used to
8575 store the archive.
8576
8577 To specify format parameters when accessing or creating an archive,
8578 you can use the options described in the following sections.
8579 If you do not specify any format parameters, @command{tar} uses
8580 default parameters. You cannot modify a compressed archive.
8581 If you create an archive with the @option{--blocking-factor} option
8582 specified (@pxref{Blocking Factor}), you must specify that
8583 blocking-factor when operating on the archive. @xref{Formats}, for other
8584 examples of format parameter considerations.
8585
8586 @node Blocking Factor
8587 @subsection The Blocking Factor of an Archive
8588 @cindex Blocking Factor
8589 @cindex Record Size
8590 @cindex Number of blocks per record
8591 @cindex Number of bytes per record
8592 @cindex Bytes per record
8593 @cindex Blocks per record
8594 @UNREVISED
8595
8596 @opindex blocking-factor
8597 The data in an archive is grouped into blocks, which are 512 bytes.
8598 Blocks are read and written in whole number multiples called
8599 @dfn{records}. The number of blocks in a record (ie. the size of a
8600 record in units of 512 bytes) is called the @dfn{blocking factor}.
8601 The @option{--blocking-factor=@var{512-size}} (@option{-b
8602 @var{512-size}}) option specifies the blocking factor of an archive.
8603 The default blocking factor is typically 20 (i.e., 10240 bytes), but
8604 can be specified at installation. To find out the blocking factor of
8605 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
8606 This may not work on some devices.
8607
8608 Records are separated by gaps, which waste space on the archive media.
8609 If you are archiving on magnetic tape, using a larger blocking factor
8610 (and therefore larger records) provides faster throughput and allows you
8611 to fit more data on a tape (because there are fewer gaps). If you are
8612 archiving on cartridge, a very large blocking factor (say 126 or more)
8613 greatly increases performance. A smaller blocking factor, on the other
8614 hand, may be useful when archiving small files, to avoid archiving lots
8615 of nulls as @command{tar} fills out the archive to the end of the record.
8616 In general, the ideal record size depends on the size of the
8617 inter-record gaps on the tape you are using, and the average size of the
8618 files you are archiving. @xref{create}, for information on
8619 writing archives.
8620
8621 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
8622
8623 Archives with blocking factors larger than 20 cannot be read
8624 by very old versions of @command{tar}, or by some newer versions
8625 of @command{tar} running on old machines with small address spaces.
8626 With @GNUTAR{}, the blocking factor of an archive is limited
8627 only by the maximum record size of the device containing the archive,
8628 or by the amount of available virtual memory.
8629
8630 Also, on some systems, not using adequate blocking factors, as sometimes
8631 imposed by the device drivers, may yield unexpected diagnostics. For
8632 example, this has been reported:
8633
8634 @smallexample
8635 Cannot write to /dev/dlt: Invalid argument
8636 @end smallexample
8637
8638 @noindent
8639 In such cases, it sometimes happen that the @command{tar} bundled by
8640 the system is aware of block size idiosyncrasies, while @GNUTAR{}
8641 requires an explicit specification for the block size,
8642 which it cannot guess. This yields some people to consider
8643 @GNUTAR{} is misbehaving, because by comparison,
8644 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
8645 for example, might resolve the problem.
8646
8647 If you use a non-default blocking factor when you create an archive, you
8648 must specify the same blocking factor when you modify that archive. Some
8649 archive devices will also require you to specify the blocking factor when
8650 reading that archive, however this is not typically the case. Usually, you
8651 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
8652 reports a non-default record size and then lists the archive members as
8653 it would normally. To extract files from an archive with a non-standard
8654 blocking factor (particularly if you're not sure what the blocking factor
8655 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
8656 specifying a blocking factor larger then the blocking factor of the archive
8657 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
8658 @xref{list}, for more information on the @option{--list} (@option{-t})
8659 operation. @xref{Reading}, for a more detailed explanation of that option.
8660
8661 @table @option
8662 @item --blocking-factor=@var{number}
8663 @itemx -b @var{number}
8664 Specifies the blocking factor of an archive. Can be used with any
8665 operation, but is usually not necessary with @option{--list} (@option{-t}).
8666 @end table
8667
8668 Device blocking
8669
8670 @table @option
8671 @item -b @var{blocks}
8672 @itemx --blocking-factor=@var{blocks}
8673 Set record size to @math{@var{blocks} * 512} bytes.
8674
8675 This option is used to specify a @dfn{blocking factor} for the archive.
8676 When reading or writing the archive, @command{tar}, will do reads and writes
8677 of the archive in records of @math{@var{block}*512} bytes. This is true
8678 even when the archive is compressed. Some devices requires that all
8679 write operations be a multiple of a certain size, and so, @command{tar}
8680 pads the archive out to the next record boundary.
8681
8682 The default blocking factor is set when @command{tar} is compiled, and is
8683 typically 20. Blocking factors larger than 20 cannot be read by very
8684 old versions of @command{tar}, or by some newer versions of @command{tar}
8685 running on old machines with small address spaces.
8686
8687 With a magnetic tape, larger records give faster throughput and fit
8688 more data on a tape (because there are fewer inter-record gaps).
8689 If the archive is in a disk file or a pipe, you may want to specify
8690 a smaller blocking factor, since a large one will result in a large
8691 number of null bytes at the end of the archive.
8692
8693 When writing cartridge or other streaming tapes, a much larger
8694 blocking factor (say 126 or more) will greatly increase performance.
8695 However, you must specify the same blocking factor when reading or
8696 updating the archive.
8697
8698 Apparently, Exabyte drives have a physical block size of 8K bytes.
8699 If we choose our blocksize as a multiple of 8k bytes, then the problem
8700 seems to disappear. Id est, we are using block size of 112 right
8701 now, and we haven't had the problem since we switched@dots{}
8702
8703 With @GNUTAR{} the blocking factor is limited only
8704 by the maximum record size of the device containing the archive, or by
8705 the amount of available virtual memory.
8706
8707 However, deblocking or reblocking is virtually avoided in a special
8708 case which often occurs in practice, but which requires all the
8709 following conditions to be simultaneously true:
8710 @itemize @bullet
8711 @item
8712 the archive is subject to a compression option,
8713 @item
8714 the archive is not handled through standard input or output, nor
8715 redirected nor piped,
8716 @item
8717 the archive is directly handled to a local disk, instead of any special
8718 device,
8719 @item
8720 @option{--blocking-factor} is not explicitly specified on the @command{tar}
8721 invocation.
8722 @end itemize
8723
8724 If the output goes directly to a local disk, and not through
8725 stdout, then the last write is not extended to a full record size.
8726 Otherwise, reblocking occurs. Here are a few other remarks on this
8727 topic:
8728
8729 @itemize @bullet
8730
8731 @item
8732 @command{gzip} will complain about trailing garbage if asked to
8733 uncompress a compressed archive on tape, there is an option to turn
8734 the message off, but it breaks the regularity of simply having to use
8735 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
8736 silently ignoring any number of trailing zeros. I'll ask Jean-loup
8737 Gailly, by sending a copy of this message to him.
8738
8739 @item
8740 @command{compress} does not show this problem, but as Jean-loup pointed
8741 out to Michael, @samp{compress -d} silently adds garbage after
8742 the result of decompression, which tar ignores because it already
8743 recognized its end-of-file indicator. So this bug may be safely
8744 ignored.
8745
8746 @item
8747 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
8748 but will still return an exit status of 2 which tar reports in turn.
8749 @command{tar} might ignore the exit status returned, but I hate doing
8750 that, as it weakens the protection @command{tar} offers users against
8751 other possible problems at decompression time. If @command{gzip} was
8752 silently skipping trailing zeros @emph{and} also avoiding setting the
8753 exit status in this innocuous case, that would solve this situation.
8754
8755 @item
8756 @command{tar} should become more solid at not stopping to read a pipe at
8757 the first null block encountered. This inelegantly breaks the pipe.
8758 @command{tar} should rather drain the pipe out before exiting itself.
8759 @end itemize
8760
8761 @opindex ignore-zeros, short description
8762 @item -i
8763 @itemx --ignore-zeros
8764 Ignore blocks of zeros in archive (means EOF).
8765
8766 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
8767 of zeros in the archive. Normally a block of zeros indicates the
8768 end of the archive, but when reading a damaged archive, or one which
8769 was created by concatenating several archives together, this option
8770 allows @command{tar} to read the entire archive. This option is not on
8771 by default because many versions of @command{tar} write garbage after
8772 the zeroed blocks.
8773
8774 Note that this option causes @command{tar} to read to the end of the
8775 archive file, which may sometimes avoid problems when multiple files
8776 are stored on a single physical tape.
8777
8778 @opindex read-full-records, short description
8779 @item -B
8780 @itemx --read-full-records
8781 Reblock as we read (for reading 4.2BSD pipes).
8782
8783 If @option{--read-full-records} is used, @command{tar}
8784 will not panic if an attempt to read a record from the archive does
8785 not return a full record. Instead, @command{tar} will keep reading
8786 until it has obtained a full
8787 record.
8788
8789 This option is turned on by default when @command{tar} is reading
8790 an archive from standard input, or from a remote machine. This is
8791 because on BSD Unix systems, a read of a pipe will return however
8792 much happens to be in the pipe, even if it is less than @command{tar}
8793 requested. If this option was not used, @command{tar} would fail as
8794 soon as it read an incomplete record from the pipe.
8795
8796 This option is also useful with the commands for updating an archive.
8797
8798 @end table
8799
8800 Tape blocking
8801
8802 @FIXME{Appropriate options should be moved here from elsewhere.}
8803
8804 @cindex blocking factor
8805 @cindex tape blocking
8806
8807 When handling various tapes or cartridges, you have to take care of
8808 selecting a proper blocking, that is, the number of disk blocks you
8809 put together as a single tape block on the tape, without intervening
8810 tape gaps. A @dfn{tape gap} is a small landing area on the tape
8811 with no information on it, used for decelerating the tape to a
8812 full stop, and for later regaining the reading or writing speed.
8813 When the tape driver starts reading a record, the record has to
8814 be read whole without stopping, as a tape gap is needed to stop the
8815 tape motion without loosing information.
8816
8817 @cindex Exabyte blocking
8818 @cindex DAT blocking
8819 Using higher blocking (putting more disk blocks per tape block) will use
8820 the tape more efficiently as there will be less tape gaps. But reading
8821 such tapes may be more difficult for the system, as more memory will be
8822 required to receive at once the whole record. Further, if there is a
8823 reading error on a huge record, this is less likely that the system will
8824 succeed in recovering the information. So, blocking should not be too
8825 low, nor it should be too high. @command{tar} uses by default a blocking of
8826 20 for historical reasons, and it does not really matter when reading or
8827 writing to disk. Current tape technology would easily accommodate higher
8828 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
8829 We were told that for some DLT drives, the blocking should be a multiple
8830 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
8831 Other manufacturers may use different recommendations for the same tapes.
8832 This might also depends of the buffering techniques used inside modern
8833 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
8834 Others request blocking to be some exponent of two.
8835
8836 So, there is no fixed rule for blocking. But blocking at read time
8837 should ideally be the same as blocking used at write time. At one place
8838 I know, with a wide variety of equipment, they found it best to use a
8839 blocking of 32 to guarantee that their tapes are fully interchangeable.
8840
8841 I was also told that, for recycled tapes, prior erasure (by the same
8842 drive unit that will be used to create the archives) sometimes lowers
8843 the error rates observed at rewriting time.
8844
8845 I might also use @option{--number-blocks} instead of
8846 @option{--block-number}, so @option{--block} will then expand to
8847 @option{--blocking-factor} unambiguously.
8848
8849 @node Many
8850 @section Many Archives on One Tape
8851
8852 @FIXME{Appropriate options should be moved here from elsewhere.}
8853
8854 @findex ntape @r{device}
8855 Most tape devices have two entries in the @file{/dev} directory, or
8856 entries that come in pairs, which differ only in the minor number for
8857 this device. Let's take for example @file{/dev/tape}, which often
8858 points to the only or usual tape device of a given system. There might
8859 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
8860 name is the @emph{rewinding} version of the device, while the name
8861 having @samp{nr} in it is the @emph{no rewinding} version of the same
8862 device.
8863
8864 A rewinding tape device will bring back the tape to its beginning point
8865 automatically when this device is opened or closed. Since @command{tar}
8866 opens the archive file before using it and closes it afterwards, this
8867 means that a simple:
8868
8869 @smallexample
8870 $ @kbd{tar cf /dev/tape @var{directory}}
8871 @end smallexample
8872
8873 @noindent
8874 will reposition the tape to its beginning both prior and after saving
8875 @var{directory} contents to it, thus erasing prior tape contents and
8876 making it so that any subsequent write operation will destroy what has
8877 just been saved.
8878
8879 @cindex tape positioning
8880 So, a rewinding device is normally meant to hold one and only one file.
8881 If you want to put more than one @command{tar} archive on a given tape, you
8882 will need to avoid using the rewinding version of the tape device. You
8883 will also have to pay special attention to tape positioning. Errors in
8884 positioning may overwrite the valuable data already on your tape. Many
8885 people, burnt by past experiences, will only use rewinding devices and
8886 limit themselves to one file per tape, precisely to avoid the risk of
8887 such errors. Be fully aware that writing at the wrong position on a
8888 tape loses all information past this point and most probably until the
8889 end of the tape, and this destroyed information @emph{cannot} be
8890 recovered.
8891
8892 To save @var{directory-1} as a first archive at the beginning of a
8893 tape, and leave that tape ready for a second archive, you should use:
8894
8895 @smallexample
8896 $ @kbd{mt -f /dev/nrtape rewind}
8897 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
8898 @end smallexample
8899
8900 @cindex tape marks
8901 @dfn{Tape marks} are special magnetic patterns written on the tape
8902 media, which are later recognizable by the reading hardware. These
8903 marks are used after each file, when there are many on a single tape.
8904 An empty file (that is to say, two tape marks in a row) signal the
8905 logical end of the tape, after which no file exist. Usually,
8906 non-rewinding tape device drivers will react to the close request issued
8907 by @command{tar} by first writing two tape marks after your archive, and by
8908 backspacing over one of these. So, if you remove the tape at that time
8909 from the tape drive, it is properly terminated. But if you write
8910 another file at the current position, the second tape mark will be
8911 erased by the new information, leaving only one tape mark between files.
8912
8913 So, you may now save @var{directory-2} as a second archive after the
8914 first on the same tape by issuing the command:
8915
8916 @smallexample
8917 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
8918 @end smallexample
8919
8920 @noindent
8921 and so on for all the archives you want to put on the same tape.
8922
8923 Another usual case is that you do not write all the archives the same
8924 day, and you need to remove and store the tape between two archive
8925 sessions. In general, you must remember how many files are already
8926 saved on your tape. Suppose your tape already has 16 files on it, and
8927 that you are ready to write the 17th. You have to take care of skipping
8928 the first 16 tape marks before saving @var{directory-17}, say, by using
8929 these commands:
8930
8931 @smallexample
8932 $ @kbd{mt -f /dev/nrtape rewind}
8933 $ @kbd{mt -f /dev/nrtape fsf 16}
8934 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
8935 @end smallexample
8936
8937 In all the previous examples, we put aside blocking considerations, but
8938 you should do the proper things for that as well. @xref{Blocking}.
8939
8940 @menu
8941 * Tape Positioning:: Tape Positions and Tape Marks
8942 * mt:: The @command{mt} Utility
8943 @end menu
8944
8945 @node Tape Positioning
8946 @subsection Tape Positions and Tape Marks
8947 @UNREVISED
8948
8949 Just as archives can store more than one file from the file system,
8950 tapes can store more than one archive file. To keep track of where
8951 archive files (or any other type of file stored on tape) begin and
8952 end, tape archive devices write magnetic @dfn{tape marks} on the
8953 archive media. Tape drives write one tape mark between files,
8954 two at the end of all the file entries.
8955
8956 If you think of data as a series of records "rrrr"'s, and tape marks as
8957 "*"'s, a tape might look like the following:
8958
8959 @smallexample
8960 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
8961 @end smallexample
8962
8963 Tape devices read and write tapes using a read/write @dfn{tape
8964 head}---a physical part of the device which can only access one
8965 point on the tape at a time. When you use @command{tar} to read or
8966 write archive data from a tape device, the device will begin reading
8967 or writing from wherever on the tape the tape head happens to be,
8968 regardless of which archive or what part of the archive the tape
8969 head is on. Before writing an archive, you should make sure that no
8970 data on the tape will be overwritten (unless it is no longer needed).
8971 Before reading an archive, you should make sure the tape head is at
8972 the beginning of the archive you want to read. You can do it manually
8973 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
8974 that automatically (@pxref{Scripted Restoration}).
8975
8976 If you want to add new archive file entries to a tape, you should
8977 advance the tape to the end of the existing file entries, backspace
8978 over the last tape mark, and write the new archive file. If you were
8979 to add two archives to the example above, the tape might look like the
8980 following:
8981
8982 @smallexample
8983 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
8984 @end smallexample
8985
8986 @node mt
8987 @subsection The @command{mt} Utility
8988 @UNREVISED
8989
8990 @FIXME{Is it true that this only works on non-block devices?
8991 should explain the difference, (fixed or variable).}
8992 @xref{Blocking Factor}.
8993
8994 You can use the @command{mt} utility to advance or rewind a tape past a
8995 specified number of archive files on the tape. This will allow you
8996 to move to the beginning of an archive before extracting or reading
8997 it, or to the end of all the archives before writing a new one.
8998 @FIXME{Why isn't there an "advance 'til you find two tape marks
8999 together"?}
9000
9001 The syntax of the @command{mt} command is:
9002
9003 @smallexample
9004 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9005 @end smallexample
9006
9007 where @var{tapename} is the name of the tape device, @var{number} is
9008 the number of times an operation is performed (with a default of one),
9009 and @var{operation} is one of the following:
9010
9011 @FIXME{is there any use for record operations?}
9012
9013 @table @option
9014 @item eof
9015 @itemx weof
9016 Writes @var{number} tape marks at the current position on the tape.
9017
9018 @item fsf
9019 Moves tape position forward @var{number} files.
9020
9021 @item bsf
9022 Moves tape position back @var{number} files.
9023
9024 @item rewind
9025 Rewinds the tape. (Ignores @var{number}).
9026
9027 @item offline
9028 @itemx rewoff1
9029 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9030
9031 @item status
9032 Prints status information about the tape unit.
9033
9034 @end table
9035
9036 @FIXME{Is there a better way to frob the spacing on the list?}
9037
9038 If you don't specify a @var{tapename}, @command{mt} uses the environment
9039 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} uses the device
9040 @file{/dev/rmt12}.
9041
9042 @command{mt} returns a 0 exit status when the operation(s) were
9043 successful, 1 if the command was unrecognized, and 2 if an operation
9044 failed.
9045
9046 @node Using Multiple Tapes
9047 @section Using Multiple Tapes
9048 @UNREVISED
9049
9050 Often you might want to write a large archive, one larger than will fit
9051 on the actual tape you are using. In such a case, you can run multiple
9052 @command{tar} commands, but this can be inconvenient, particularly if you
9053 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9054 Therefore, @command{tar} supports multiple tapes automatically.
9055
9056 Use @option{--multi-volume} (@option{-M}) on the command line, and
9057 then @command{tar} will, when it reaches the end of the tape, prompt
9058 for another tape, and continue the archive. Each tape will have an
9059 independent archive, and can be read without needing the other. (As
9060 an exception to this, the file that @command{tar} was archiving when
9061 it ran out of tape will usually be split between the two archives; in
9062 this case you need to extract from the first archive, using
9063 @option{--multi-volume}, and then put in the second tape when
9064 prompted, so @command{tar} can restore both halves of the file.)
9065
9066 @GNUTAR{} multi-volume archives do not use a truly portable format.
9067 You need @GNUTAR{} at both ends to process them properly.
9068
9069 When prompting for a new tape, @command{tar} accepts any of the following
9070 responses:
9071
9072 @table @kbd
9073 @item ?
9074 Request @command{tar} to explain possible responses
9075 @item q
9076 Request @command{tar} to exit immediately.
9077 @item n @var{file-name}
9078 Request @command{tar} to write the next volume on the file @var{file-name}.
9079 @item !
9080 Request @command{tar} to run a subshell. This option can be disabled
9081 by giving @option{--restrict} command line option to @command{tar}.
9082 @item y
9083 Request @command{tar} to begin writing the next volume.
9084 @end table
9085
9086 (You should only type @samp{y} after you have changed the tape;
9087 otherwise @command{tar} will write over the volume it just finished.)
9088
9089 @cindex End-of-archive info script
9090 @cindex Info script
9091 @anchor{info-script}
9092 @opindex info-script
9093 @opindex new-volume-script
9094 If you want more elaborate behavior than this, give @command{tar} the
9095 @option{--info-script=@var{script-name}}
9096 (@option{--new-volume-script=@var{script-name}}, @option{-F
9097 @var{script-name}}) option. The file @var{script-name} is expected to
9098 be a program (or shell script) to be run instead of the normal
9099 prompting procedure. It is executed without any command line
9100 arguments. Additional data is passed to it via the following
9101 environment variables:
9102
9103 @table @env
9104 @vrindex TAR_VERSION, info script environment variable
9105 @item TAR_VERSION
9106 @GNUTAR{} version number.
9107
9108 @vrindex TAR_ARCHIVE, info script environment variable
9109 @item TAR_ARCHIVE
9110 The name of the archive @command{tar} is processing.
9111
9112 @vrindex TAR_VOLUME, info script environment variable
9113 @item TAR_VOLUME
9114 Ordinal number of the volume @command{tar} is about to start.
9115
9116 @vrindex TAR_SUBCOMMAND, info script environment variable
9117 @item TAR_SUBCOMMAND
9118 Short option describing the operation @command{tar} is executed.
9119 @xref{Operations}, for a complete list of subcommand options.
9120
9121 @vrindex TAR_FORMAT, info script environment variable
9122 @item TAR_FORMAT
9123 Format of the archive being processed. @xref{Formats}, for a complete
9124 list of archive format names.
9125 @end table
9126
9127 The info script can instruct @command{tar} to use new archive name,
9128 by writing in to file descriptor 3 (see below for an
9129 example).
9130
9131 If the info script fails, @command{tar} exits; otherwise, it begins
9132 writing the next volume.
9133
9134 The method @command{tar} uses to detect end of tape is not perfect, and
9135 fails on some operating systems or on some devices. You can use the
9136 @option{--tape-length=@var{size}} (@option{-L @var{size}}) option if
9137 @command{tar} can't detect the end of the tape itself. This option
9138 selects @option{--multi-volume} (@option{-M}) automatically. The
9139 @var{size} argument should then be the usable size of the tape in
9140 units of 1024 bytes. But for many devices, and floppy disks in
9141 particular, this option is never required for real, as far as we know.
9142
9143 @cindex Volume number file
9144 @cindex volno file
9145 @anchor{volno-file}
9146 @opindex volno-file
9147 The volume number used by @command{tar} in its tape-change prompt
9148 can be changed; if you give the
9149 @option{--volno-file=@var{file-of-number}} option, then
9150 @var{file-of-number} should be an unexisting file to be created, or
9151 else, a file already containing a decimal number. That number will be
9152 used as the volume number of the first volume written. When
9153 @command{tar} is finished, it will rewrite the file with the
9154 now-current volume number. (This does not change the volume number
9155 written on a tape label, as per @ref{label}, it @emph{only} affects
9156 the number used in the prompt.)
9157
9158 If you want @command{tar} to cycle through a series of files or tape
9159 drives, there are three approaches to choose from. First of all, you
9160 can give @command{tar} multiple @option{--file} options. In this case
9161 the specified files will be used, in sequence, as the successive
9162 volumes of the archive. Only when the first one in the sequence needs
9163 to be used again will @command{tar} prompt for a tape change (or run
9164 the info script). Secondly, you can use the @samp{n} response to the
9165 tape-change prompt, and, finally, you can use an info script, that
9166 writes new archive name to file descriptor. The following example
9167 illustrates this approach:
9168
9169 @smallexample
9170 @group
9171 #! /bin/sh
9172 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9173
9174 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9175 case $TAR_SUBCOMMAND in
9176 -c) ;;
9177 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9178 ;;
9179 *) exit 1
9180 esac
9181
9182 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9183 @end group
9184 @end smallexample
9185
9186 Each volume of a multi-volume archive is an independent @command{tar}
9187 archive, complete in itself. For example, you can list or extract any
9188 volume alone; just don't specify @option{--multi-volume}
9189 (@option{-M}). However, if one file in the archive is split across
9190 volumes, the only way to extract it successfully is with a
9191 multi-volume extract command @option{--extract --multi-volume}
9192 (@option{-xM}) starting on or before the volume where the file begins.
9193
9194 For example, let's presume someone has two tape drives on a system
9195 named @file{/dev/tape0} and @file{/dev/tape1}. For having @GNUTAR{}
9196 to switch to the second drive when it needs to write the
9197 second tape, and then back to the first tape, etc., just do either of:
9198
9199 @smallexample
9200 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9201 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9202 @end smallexample
9203
9204 @menu
9205 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9206 * Tape Files:: Tape Files
9207 * Tarcat:: Concatenate Volumes into a Single Archive
9208
9209 @end menu
9210
9211 @node Multi-Volume Archives
9212 @subsection Archives Longer than One Tape or Disk
9213 @cindex Multi-volume archives
9214 @UNREVISED
9215
9216 @opindex multi-volume
9217 To create an archive that is larger than will fit on a single unit of
9218 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9219 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9220 archive can be manipulated like any other archive (provided the
9221 @option{--multi-volume} option is specified), but is stored on more
9222 than one tape or disk.
9223
9224 When you specify @option{--multi-volume}, @command{tar} does not report an
9225 error when it comes to the end of an archive volume (when reading), or
9226 the end of the media (when writing). Instead, it prompts you to load
9227 a new storage volume. If the archive is on a magnetic tape, you
9228 should change tapes when you see the prompt; if the archive is on a
9229 floppy disk, you should change disks; etc.
9230
9231 You can read each individual volume of a multi-volume archive as if it
9232 were an archive by itself. For example, to list the contents of one
9233 volume, use @option{--list}, without @option{--multi-volume} specified.
9234 To extract an archive member from one volume (assuming it is described
9235 that volume), use @option{--extract}, again without
9236 @option{--multi-volume}.
9237
9238 If an archive member is split across volumes (ie. its entry begins on
9239 one volume of the media and ends on another), you need to specify
9240 @option{--multi-volume} to extract it successfully. In this case, you
9241 should load the volume where the archive member starts, and use
9242 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9243 volumes as it needs them. @xref{extracting archives}, for more
9244 information about extracting archives.
9245
9246 @option{--info-script=@var{script-name}}
9247 (@option{--new-volume-script=@var{script-name}}, @option{-F
9248 @var{script-name}}) (@pxref{info-script}) is like
9249 @option{--multi-volume} (@option{-M}), except that @command{tar} does
9250 not prompt you directly to change media volumes when a volume is
9251 full---instead, @command{tar} runs commands you have stored in
9252 @var{script-name}. For example, this option can be used to eject
9253 cassettes, or to broadcast messages such as @samp{Someone please come
9254 change my tape} when performing unattended backups. When
9255 @var{script-name} is done, @command{tar} will assume that the media
9256 has been changed.
9257
9258 Multi-volume archives can be modified like any other archive. To add
9259 files to a multi-volume archive, you need to only mount the last
9260 volume of the archive media (and new volumes, if needed). For all
9261 other operations, you need to use the entire archive.
9262
9263 If a multi-volume archive was labeled using
9264 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9265 (@pxref{label}) when it was created, @command{tar} will not
9266 automatically label volumes which are added later. To label
9267 subsequent volumes, specify @option{--label=@var{archive-label}} again
9268 in conjunction with the @option{--append}, @option{--update} or
9269 @option{--concatenate} operation.
9270
9271 @cindex Labeling multi-volume archives
9272 @FIXME{example}
9273
9274 @FIXME{There should be a sample program here, including an exit
9275 before end. Is the exit status even checked in tar? :-(}
9276
9277 @table @option
9278 @item --multi-volume
9279 @itemx -M
9280 Creates a multi-volume archive, when used in conjunction with
9281 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9282 archive, specify @option{--multi-volume} in conjunction with that
9283 operation.
9284
9285 @item --info-script=@var{program-file}
9286 @itemx --new-volume-script=@var{program-file}
9287 @itemx -F @var{program-file}
9288 Creates a multi-volume archive via a script. Used in conjunction with
9289 @option{--create} (@option{-c}). @xref{info-script}, dor a detailed discussion.
9290 @end table
9291
9292 Beware that there is @emph{no} real standard about the proper way, for
9293 a @command{tar} archive, to span volume boundaries. If you have a
9294 multi-volume created by some vendor's @command{tar}, there is almost
9295 no chance you could read all the volumes with @GNUTAR{}.
9296 The converse is also true: you may not expect
9297 multi-volume archives created by @GNUTAR{} to be
9298 fully recovered by vendor's @command{tar}. Since there is little
9299 chance that, in mixed system configurations, some vendor's
9300 @command{tar} will work on another vendor's machine, and there is a
9301 great chance that @GNUTAR{} will work on most of
9302 them, your best bet is to install @GNUTAR{} on all
9303 machines between which you know exchange of files is possible.
9304
9305 @node Tape Files
9306 @subsection Tape Files
9307 @UNREVISED
9308
9309 To give the archive a name which will be recorded in it, use the
9310 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9311 option. This will write a special block identifying
9312 @var{volume-label} as the name of the archive to the front of the
9313 archive which will be displayed when the archive is listed with
9314 @option{--list}. If you are creating a multi-volume archive with
9315 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9316 volume label will have @samp{Volume @var{nnn}} appended to the name
9317 you give, where @var{nnn} is the number of the volume of the archive.
9318 (If you use the @option{--label=@var{volume-label}}) option when
9319 reading an archive, it checks to make sure the label on the tape
9320 matches the one you give. @xref{label}.
9321
9322 When @command{tar} writes an archive to tape, it creates a single
9323 tape file. If multiple archives are written to the same tape, one
9324 after the other, they each get written as separate tape files. When
9325 extracting, it is necessary to position the tape at the right place
9326 before running @command{tar}. To do this, use the @command{mt} command.
9327 For more information on the @command{mt} command and on the organization
9328 of tapes into a sequence of tape files, see @ref{mt}.
9329
9330 People seem to often do:
9331
9332 @smallexample
9333 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9334 @end smallexample
9335
9336 or such, for pushing a common date in all volumes or an archive set.
9337
9338 @node Tarcat
9339 @subsection Concatenate Volumes into a Single Archive
9340
9341 @pindex tarcat
9342 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9343 archive to a single @command{tar} archive. Simply concatenating all
9344 volumes into one will not work, since each volume carries an additional
9345 information at the beginning. @GNUTAR{} is shipped with the shell
9346 script @command{tarcat} designed for this purpose.
9347
9348 The script takes a list of files comprising a multi-volume archive
9349 and creates the resulting archive at the standard output. For example:
9350
9351 @smallexample
9352 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9353 @end smallexample
9354
9355 The script implements a simple heuristics to determine the format of
9356 the first volume file and to decide how to process the rest of the
9357 files. However, it makes no attempt to verify whether the files are
9358 given in order or even if they are valid @command{tar} archives.
9359 It uses @command{dd} and does not filter its standard error, so you
9360 will usually see lots of spurious messages.
9361
9362 @FIXME{The script is not installed. Should we install it?}
9363
9364 @node label
9365 @section Including a Label in the Archive
9366 @cindex Labeling an archive
9367 @cindex Labels on the archive media
9368 @UNREVISED
9369
9370 @opindex label
9371 To avoid problems caused by misplaced paper labels on the archive
9372 media, you can include a @dfn{label} entry---an archive member which
9373 contains the name of the archive---in the archive itself. Use the
9374 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9375 option in conjunction with the @option{--create} operation to include
9376 a label entry in the archive as it is being created.
9377
9378 @table @option
9379 @item --label=@var{archive-label}
9380 @itemx -V @var{archive-label}
9381 Includes an @dfn{archive-label} at the beginning of the archive when
9382 the archive is being created, when used in conjunction with the
9383 @option{--create} operation. Checks to make sure the archive label
9384 matches the one specified (when used in conjunction with any other
9385 operation.
9386 @end table
9387
9388 If you create an archive using both
9389 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9390 and @option{--multi-volume} (@option{-M}), each volume of the archive
9391 will have an archive label of the form @samp{@var{archive-label}
9392 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9393 next, and so on. @xref{Using Multiple Tapes}, for information on
9394 creating multiple volume archives.
9395
9396 @cindex Volume label, listing
9397 @cindex Listing volume label
9398 The volume label will be displayed by @option{--list} along with
9399 the file contents. If verbose display is requested, it will also be
9400 explicitely marked as in the example below:
9401
9402 @smallexample
9403 @group
9404 $ @kbd{tar --verbose --list --file=iamanarchive}
9405 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9406 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9407 @end group
9408 @end smallexample
9409
9410 @opindex test-label
9411 @anchor{--test-label option}
9412 However, @option{--list} option will cause listing entire
9413 contents of the archive, which may be undesirable (for example, if the
9414 archive is stored on a tape). You can request checking only the volume
9415 by specifying @option{--test-label} option. This option reads only the
9416 first block of an archive, so it can be used with slow storage
9417 devices. For example:
9418
9419 @smallexample
9420 @group
9421 $ @kbd{tar --test-label --file=iamanarchive}
9422 iamalabel
9423 @end group
9424 @end smallexample
9425
9426 If @option{--test-label} is used with a single command line
9427 argument, @command{tar} compares the volume label with the
9428 argument. It exits with code 0 if the two strings match, and with code
9429 2 otherwise. In this case no output is displayed. For example:
9430
9431 @smallexample
9432 @group
9433 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9434 @result{} 0
9435 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9436 @result{} 1
9437 @end group
9438 @end smallexample
9439
9440 If you request any operation, other than @option{--create}, along
9441 with using @option{--label} option, @command{tar} will first check if
9442 the archive label matches the one specified and will refuse to proceed
9443 if it does not. Use this as a safety precaution to avoid accidentally
9444 overwriting existing archives. For example, if you wish to add files
9445 to @file{archive}, presumably labelled with string @samp{My volume},
9446 you will get:
9447
9448 @smallexample
9449 @group
9450 $ @kbd{tar -rf archive --label 'My volume' .}
9451 tar: Archive not labeled to match `My volume'
9452 @end group
9453 @end smallexample
9454
9455 @noindent
9456 in case its label does not match. This will work even if
9457 @file{archive} is not labelled at all.
9458
9459 Similarly, @command{tar} will refuse to list or extract the
9460 archive if its label doesn't match the @var{archive-label}
9461 specified. In those cases, @var{archive-label} argument is interpreted
9462 as a globbing-style pattern which must match the actual magnetic
9463 volume label. @xref{exclude}, for a precise description of how match
9464 is attempted@footnote{Previous versions of @command{tar} used full
9465 regular expression matching, or before that, only exact string
9466 matching, instead of wildcard matchers. We decided for the sake of
9467 simplicity to use a uniform matching device through
9468 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
9469 the volume label matcher will also suffix @var{archive-label} by
9470 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
9471 up. Since the volume numbering is automatically added in labels at
9472 creation time, it sounded logical to equally help the user taking care
9473 of it when the archive is being read.
9474
9475 The @option{--label} was once called @option{--volume}, but is not
9476 available under that name anymore.
9477
9478 You can also use @option{--label} to get a common information on
9479 all tapes of a series. For having this information different in each
9480 series created through a single script used on a regular basis, just
9481 manage to get some date string as part of the label. For example:
9482
9483 @smallexample
9484 @group
9485 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9486 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9487 --volume="Daily backup for `date +%Y-%m-%d`"}
9488 @end group
9489 @end smallexample
9490
9491 Also note that each label has its own date and time, which corresponds
9492 to when @GNUTAR{} initially attempted to write it,
9493 often soon after the operator launches @command{tar} or types the
9494 carriage return telling that the next tape is ready. Comparing date
9495 labels does give an idea of tape throughput only if the delays for
9496 rewinding tapes and the operator switching them were negligible, which
9497 is usually not the case.
9498
9499 @node verify
9500 @section Verifying Data as It is Stored
9501 @cindex Verifying a write operation
9502 @cindex Double-checking a write operation
9503
9504 @table @option
9505 @item -W
9506 @itemx --verify
9507 @opindex verify, short description
9508 Attempt to verify the archive after writing.
9509 @end table
9510
9511 This option causes @command{tar} to verify the archive after writing it.
9512 Each volume is checked after it is written, and any discrepancies
9513 are recorded on the standard error output.
9514
9515 Verification requires that the archive be on a back-space-able medium.
9516 This means pipes, some cartridge tape drives, and some other devices
9517 cannot be verified.
9518
9519 You can insure the accuracy of an archive by comparing files in the
9520 system with archive members. @command{tar} can compare an archive to the
9521 file system as the archive is being written, to verify a write
9522 operation, or can compare a previously written archive, to insure that
9523 it is up to date.
9524
9525 @opindex verify, using with @option{--create}
9526 @opindex create, using with @option{--verify}
9527 To check for discrepancies in an archive immediately after it is
9528 written, use the @option{--verify} (@option{-W}) option in conjunction with
9529 the @option{--create} operation. When this option is
9530 specified, @command{tar} checks archive members against their counterparts
9531 in the file system, and reports discrepancies on the standard error.
9532
9533 To verify an archive, you must be able to read it from before the end
9534 of the last written entry. This option is useful for detecting data
9535 errors on some tapes. Archives written to pipes, some cartridge tape
9536 drives, and some other devices cannot be verified.
9537
9538 One can explicitly compare an already made archive with the file
9539 system by using the @option{--compare} (@option{--diff}, @option{-d})
9540 option, instead of using the more automatic @option{--verify} option.
9541 @xref{compare}.
9542
9543 Note that these two options have a slightly different intent. The
9544 @option{--compare} option checks how identical are the logical contents of some
9545 archive with what is on your disks, while the @option{--verify} option is
9546 really for checking if the physical contents agree and if the recording
9547 media itself is of dependable quality. So, for the @option{--verify}
9548 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9549 the archive, while it lets the speed optimization undisturbed for the
9550 @option{--compare} option. If you nevertheless use @option{--compare} for
9551 media verification, you may have to defeat the in-memory cache yourself,
9552 maybe by opening and reclosing the door latch of your recording unit,
9553 forcing some doubt in your operating system about the fact this is really
9554 the same volume as the one just written or read.
9555
9556 The @option{--verify} option would not be necessary if drivers were indeed
9557 able to detect dependably all write failures. This sometimes require many
9558 magnetic heads, some able to read after the writes occurred. One would
9559 not say that drivers unable to detect all cases are necessarily flawed,
9560 as long as programming is concerned.
9561
9562 The @option{--verify} (@option{-W}) option will not work in
9563 conjunction with the @option{--multi-volume} (@option{-M}) option or
9564 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
9565 and @option{--delete} operations. @xref{Operations}, for more
9566 information on these operations.
9567
9568 Also, since @command{tar} normally strips leading @samp{/} from file
9569 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9570 /tmp/foo.tar /etc} will work as desired only if the working directory is
9571 @file{/}, as @command{tar} uses the archive's relative member names
9572 (e.g., @file{etc/motd}) when verifying the archive.
9573
9574 @node Write Protection
9575 @section Write Protection
9576
9577 Almost all tapes and diskettes, and in a few rare cases, even disks can
9578 be @dfn{write protected}, to protect data on them from being changed.
9579 Once an archive is written, you should write protect the media to prevent
9580 the archive from being accidentally overwritten or deleted. (This will
9581 protect the archive from being changed with a tape or floppy drive---it
9582 will not protect it from magnet fields or other physical hazards).
9583
9584 The write protection device itself is usually an integral part of the
9585 physical media, and can be a two position (write enabled/write
9586 disabled) switch, a notch which can be popped out or covered, a ring
9587 which can be removed from the center of a tape reel, or some other
9588 changeable feature.
9589
9590 @node Changes
9591 @appendix Changes
9592
9593 This appendix lists some important user-visible changes between
9594 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
9595 version of this document is available at
9596 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
9597 @GNUTAR{} documentation page}.
9598
9599 @table @asis
9600 @item Use of globbing patterns when listing and extracting.
9601
9602 Previous versions of GNU tar assumed shell-style globbing when
9603 extracting from or listing an archive. For example:
9604
9605 @smallexample
9606 $ @kbd{tar xf foo.tar '*.c'}
9607 @end smallexample
9608
9609 would extract all files whose names end in @samp{.c}. This behavior
9610 was not documented and was incompatible with traditional tar
9611 implementations. Therefore, starting from version 1.15.91, GNU tar
9612 no longer uses globbing by default. For example, the above invocation
9613 is now interpreted as a request to extract from the archive the file
9614 named @file{*.c}.
9615
9616 To facilitate transition to the new behavior for those users who got
9617 used to the previous incorrect one, @command{tar} will print a warning
9618 if it finds out that a requested member was not found in the archive
9619 and its name looks like a globbing pattern. For example:
9620
9621 @smallexample
9622 $ @kbd{tar xf foo.tar '*.c'}
9623 tar: Pattern matching characters used in file names. Please,
9624 tar: use --wildcards to enable pattern matching, or --no-wildcards to
9625 tar: suppress this warning.
9626 tar: *.c: Not found in archive
9627 tar: Error exit delayed from previous errors
9628 @end smallexample
9629
9630 To treat member names as globbing patterns, use --wildcards option.
9631 If you want to tar to mimic the behavior of versions prior to 1.15.91,
9632 add this option to your @env{TAR_OPTIONS} variable.
9633
9634 @xref{Wildcards}, for the detailed discussion of the use of globbing
9635 patterns by @GNUTAR{}.
9636
9637 @item Use of short option @option{-o}.
9638
9639 Earlier versions of @GNUTAR{} understood @option{-o} command line
9640 option as a synonym for @option{--old-archive}.
9641
9642 @GNUTAR{} starting from version 1.13.90 understands this option as
9643 a synonym for @option{--no-same-owner}. This is compatible with
9644 UNIX98 @command{tar} implementations.
9645
9646 However, to facilitate transition, @option{-o} option retains its
9647 old semantics when it is used with one of archive-creation commands.
9648 Users are encouraged to use @option{--format=oldgnu} instead.
9649
9650 It is especially important, since versions of @acronym{GNU} Automake
9651 up to and including 1.8.4 invoke tar with this option to produce
9652 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
9653 of this issue and its implications.
9654
9655 @FIXME{Change the first argument to tar-formats if and when Automake
9656 people accept my patch to the documentation, and the new Automake is
9657 out --Sergey 2006-05-25}.
9658 @xref{Options, tar-v7, Changing Automake's Behavior,
9659 automake, GNU Automake}, for a description on how to use various
9660 archive formats with @command{automake}.
9661
9662 Future versions of @GNUTAR{} will understand @option{-o} only as a
9663 synonym for @option{--no-same-owner}.
9664
9665 @item Use of short option @option{-l}
9666
9667 Earlier versions of @GNUTAR{} understood @option{-l} option as a
9668 synonym for @option{--one-file-system}. Since such usage contradicted
9669 to UNIX98 specification and harmed compatibility with other
9670 implementation, it was declared deprecated in version 1.14. However,
9671 to facilitate transition to its new semantics, it was supported by
9672 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
9673 variant of @option{--check-links} was introduced in version 1.15.91.
9674
9675 @item Use of options @option{--portability} and @option{--old-archive}
9676
9677 These options are deprecated. Please use @option{--format=v7} instead.
9678
9679 @item Use of option @option{--posix}
9680
9681 This option is deprecated. Please use @option{--format=posix} instead.
9682 @end table
9683
9684 @node Configuring Help Summary
9685 @appendix Configuring Help Summary
9686
9687 Running @kbd{tar --help} displays the short @command{tar} option
9688 summary (@pxref{help}). This summary is organised by @dfn{groups} of
9689 semantically close options. The options within each group are printed
9690 in the following order: a short option, eventually followed by a list
9691 of corresponding long option names, followed by a short description of
9692 the option. For example, here is an excerpt from the actual @kbd{tar
9693 --help} output:
9694
9695 @verbatim
9696 Main operation mode:
9697
9698 -A, --catenate, --concatenate append tar files to an archive
9699 -c, --create create a new archive
9700 -d, --diff, --compare find differences between archive and
9701 file system
9702 --delete delete from the archive
9703 @end verbatim
9704
9705 @vrindex ARGP_HELP_FMT, environment variable
9706 The exact visual representation of the help output is configurable via
9707 @env{ARGP_HELP_FMT} environment variable. The value of this variable
9708 is a comma-separated list of @dfn{format variable} assignments. There
9709 are two kinds of format variables. An @dfn{offset variable} keeps the
9710 offset of some part of help output text from the leftmost column on
9711 the screen. A @dfn{boolean} variable is a flag that toggles some
9712 output feature on or off. Depending on the type of the corresponding
9713 variable, there are two kinds of assignments:
9714
9715 @table @asis
9716 @item Offset assignment
9717
9718 The assignment to an offset variable has the following syntax:
9719
9720 @smallexample
9721 @var{variable}=@var{value}
9722 @end smallexample
9723
9724 @noindent
9725 where @var{variable} is the variable name, and @var{value} is a
9726 numeric value to be assigned to the variable.
9727
9728 @item Boolean assignment
9729
9730 To assign @code{true} value to a variable, simply put this variable name. To
9731 assign @code{false} value, prefix the variable name with @samp{no-}. For
9732 example:
9733
9734 @smallexample
9735 @group
9736 # Assign @code{true} value:
9737 dup-args
9738 # Assign @code{false} value:
9739 no-dup-args
9740 @end group
9741 @end smallexample
9742 @end table
9743
9744 Following variables are declared:
9745
9746 @deftypevr {Help Output} boolean dup-args
9747 If true, arguments for an option are shown with both short and long
9748 options, even when a given option has both forms, for example:
9749
9750 @smallexample
9751 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
9752 @end smallexample
9753
9754 If false, then if an option has both short and long forms, the
9755 argument is only shown with the long one, for example:
9756
9757 @smallexample
9758 -f, --file=ARCHIVE use archive file or device ARCHIVE
9759 @end smallexample
9760
9761 @noindent
9762 and a message indicating that the argument is applicable to both
9763 forms is printed below the options. This message can be disabled
9764 using @code{dup-args-note} (see below).
9765
9766 The default is false.
9767 @end deftypevr
9768
9769 @deftypevr {Help Output} boolean dup-args-note
9770 If this variable is true, which is the default, the following notice
9771 is displayed at the end of the help output:
9772
9773 @quotation
9774 Mandatory or optional arguments to long options are also mandatory or
9775 optional for any corresponding short options.
9776 @end quotation
9777
9778 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
9779 variables @code{dup-args} or @code{dup-args-note} should be set.
9780 @end deftypevr
9781
9782 @deftypevr {Help Output} offset short-opt-col
9783 Column in which short options start. Default is 2.
9784
9785 @smallexample
9786 @group
9787 $ @kbd{tar --help|grep ARCHIVE}
9788 -f, --file=ARCHIVE use archive file or device ARCHIVE
9789 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
9790 -f, --file=ARCHIVE use archive file or device ARCHIVE
9791 @end group
9792 @end smallexample
9793 @end deftypevr
9794
9795 @deftypevr {Help Output} offset long-opt-col
9796 Column in which long options start. Default is 6. For example:
9797
9798 @smallexample
9799 @group
9800 $ @kbd{tar --help|grep ARCHIVE}
9801 -f, --file=ARCHIVE use archive file or device ARCHIVE
9802 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
9803 -f, --file=ARCHIVE use archive file or device ARCHIVE
9804 @end group
9805 @end smallexample
9806 @end deftypevr
9807
9808 @deftypevr {Help Output} offset doc-opt-col
9809 Column in which @dfn{doc options} start. A doc option isn't actually
9810 an option, but rather an arbitrary piece of documentation that is
9811 displayed in much the same manner as the options. For example, in
9812 the description of @option{--format} option:
9813
9814 @smallexample
9815 @group
9816 -H, --format=FORMAT create archive of the given format.
9817
9818 FORMAT is one of the following:
9819
9820 gnu GNU tar 1.13.x format
9821 oldgnu GNU format as per tar <= 1.12
9822 pax POSIX 1003.1-2001 (pax) format
9823 posix same as pax
9824 ustar POSIX 1003.1-1988 (ustar) format
9825 v7 old V7 tar format
9826 @end group
9827 @end smallexample
9828
9829 @noindent
9830 the format names are doc options. Thus, if you set
9831 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
9832 will look as follows:
9833
9834 @smallexample
9835 @group
9836 -H, --format=FORMAT create archive of the given format.
9837
9838 FORMAT is one of the following:
9839
9840 gnu GNU tar 1.13.x format
9841 oldgnu GNU format as per tar <= 1.12
9842 pax POSIX 1003.1-2001 (pax) format
9843 posix same as pax
9844 ustar POSIX 1003.1-1988 (ustar) format
9845 v7 old V7 tar format
9846 @end group
9847 @end smallexample
9848 @end deftypevr
9849
9850 @deftypevr {Help Output} offset opt-doc-col
9851 Column in which option description starts. Default is 29.
9852
9853 @smallexample
9854 @group
9855 $ @kbd{tar --help|grep ARCHIVE}
9856 -f, --file=ARCHIVE use archive file or device ARCHIVE
9857 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
9858 -f, --file=ARCHIVE use archive file or device ARCHIVE
9859 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
9860 -f, --file=ARCHIVE
9861 use archive file or device ARCHIVE
9862 @end group
9863 @end smallexample
9864
9865 @noindent
9866 Notice, that the description starts on a separate line if
9867 @code{opt-doc-col} value is too small.
9868 @end deftypevr
9869
9870 @deftypevr {Help Output} offset header-col
9871 Column in which @dfn{group headers} are printed. A group header is a
9872 descriptive text preceding an option group. For example, in the
9873 following text:
9874
9875 @verbatim
9876 Main operation mode:
9877
9878 -A, --catenate, --concatenate append tar files to
9879 an archive
9880 -c, --create create a new archive
9881 @end verbatim
9882 @noindent
9883 @samp{Main operation mode:} is the group header.
9884
9885 The default value is 1.
9886 @end deftypevr
9887
9888 @deftypevr {Help Output} offset usage-indent
9889 Indentation of wrapped usage lines. Affects @option{--usage}
9890 output. Default is 12.
9891 @end deftypevr
9892
9893 @deftypevr {Help Output} offset rmargin
9894 Right margin of the text output. Used for wrapping.
9895 @end deftypevr
9896
9897 @node Genfile
9898 @appendix Genfile
9899 @include genfile.texi
9900
9901 @node Snapshot Files
9902 @appendix Format of the Incremental Snapshot Files
9903 @include snapshot.texi
9904
9905 @node Free Software Needs Free Documentation
9906 @appendix Free Software Needs Free Documentation
9907 @include freemanuals.texi
9908
9909 @node Copying This Manual
9910 @appendix Copying This Manual
9911
9912 @menu
9913 * GNU Free Documentation License:: License for copying this manual
9914 @end menu
9915
9916 @include fdl.texi
9917
9918 @node Index of Command Line Options
9919 @appendix Index of Command Line Options
9920
9921 This appendix contains an index of all @GNUTAR{} long command line
9922 options. The options are listed without the preceeding double-dash.
9923
9924 @FIXME{@itemize
9925 @item Make sure @emph{all} options are indexed.
9926 @item Provide an index of short options
9927 @end itemize}
9928
9929 @printindex op
9930
9931 @node Index
9932 @appendix Index
9933
9934 @printindex cp
9935
9936 @summarycontents
9937 @contents
9938 @bye
9939
9940 @c Local variables:
9941 @c texinfo-column-for-description: 32
9942 @c End:
This page took 0.475508 seconds and 5 git commands to generate.