]> Dogcows Code - chaz/tar/blob - doc/tar.texi
(Using Multiple Tapes,Multi-Volume Archives): Rewritten
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 1.1. Run `make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.1. Run `make master-menu' (see comment before the master menu).
19
20 @include rendition.texi
21 @include value.texi
22
23 @defcodeindex op
24
25 @c Put everything in one index (arbitrarily chosen to be the concept index).
26 @syncodeindex fn cp
27 @syncodeindex ky cp
28 @syncodeindex pg cp
29 @syncodeindex vr cp
30
31 @copying
32
33 This manual is for @acronym{GNU} @command{tar} (version
34 @value{VERSION}, @value{UPDATED}), which creates and extracts files
35 from archives.
36
37 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
38 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
39
40 @quotation
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
47
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
51 @end quotation
52 @end copying
53
54 @dircategory Archiving
55 @direntry
56 * Tar: (tar). Making tape (or disk) archives.
57 @end direntry
58
59 @dircategory Individual utilities
60 @direntry
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
62 @end direntry
63
64 @shorttitlepage @acronym{GNU} @command{tar}
65
66 @titlepage
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
70
71 @page
72 @vskip 0pt plus 1filll
73 @insertcopying
74 @end titlepage
75
76 @ifnottex
77 @node Top
78 @top @acronym{GNU} tar: an archiver tool
79
80 @insertcopying
81
82 @cindex file archival
83 @cindex archiving files
84
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
87 @end ifnottex
88
89 @c The master menu goes here.
90 @c
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
94 @c
95 @c make master-menu
96
97 @menu
98 * Introduction::
99 * Tutorial::
100 * tar invocation::
101 * operations::
102 * Backups::
103 * Choosing::
104 * Date input formats::
105 * Formats::
106 * Media::
107
108 Appendices
109
110 * Changes::
111 * Configuring Help Summary::
112 * Genfile::
113 * Tar Internals::
114 * Free Software Needs Free Documentation::
115 * Copying This Manual::
116 * Index of Command Line Options::
117 * Index::
118
119 @detailmenu
120 --- The Detailed Node Listing ---
121
122 Introduction
123
124 * Book Contents:: What this Book Contains
125 * Definitions:: Some Definitions
126 * What tar Does:: What @command{tar} Does
127 * Naming tar Archives:: How @command{tar} Archives are Named
128 * Authors:: @GNUTAR{} Authors
129 * Reports:: Reporting bugs or suggestions
130
131 Tutorial Introduction to @command{tar}
132
133 * assumptions::
134 * stylistic conventions::
135 * basic tar options:: Basic @command{tar} Operations and Options
136 * frequent operations::
137 * Two Frequent Options::
138 * create:: How to Create Archives
139 * list:: How to List Archives
140 * extract:: How to Extract Members from an Archive
141 * going further::
142
143 Two Frequently Used Options
144
145 * file tutorial::
146 * verbose tutorial::
147 * help tutorial::
148
149 How to Create Archives
150
151 * prepare for examples::
152 * Creating the archive::
153 * create verbose::
154 * short create::
155 * create dir::
156
157 How to List Archives
158
159 * list dir::
160
161 How to Extract Members from an Archive
162
163 * extracting archives::
164 * extracting files::
165 * extract dir::
166 * extracting untrusted archives::
167 * failing commands::
168
169 Invoking @GNUTAR{}
170
171 * Synopsis::
172 * using tar options::
173 * Styles::
174 * All Options::
175 * help::
176 * defaults::
177 * verbose::
178 * interactive::
179
180 The Three Option Styles
181
182 * Long Options:: Long Option Style
183 * Short Options:: Short Option Style
184 * Old Options:: Old Option Style
185 * Mixing:: Mixing Option Styles
186
187 All @command{tar} Options
188
189 * Operation Summary::
190 * Option Summary::
191 * Short Option Summary::
192
193 @GNUTAR{} Operations
194
195 * Basic tar::
196 * Advanced tar::
197 * create options::
198 * extract options::
199 * backup::
200 * Applications::
201 * looking ahead::
202
203 Advanced @GNUTAR{} Operations
204
205 * Operations::
206 * append::
207 * update::
208 * concatenate::
209 * delete::
210 * compare::
211
212 How to Add Files to Existing Archives: @option{--append}
213
214 * appending files:: Appending Files to an Archive
215 * multiple::
216
217 Updating an Archive
218
219 * how to update::
220
221 Options Used by @option{--create}
222
223 * Ignore Failed Read::
224
225 Options Used by @option{--extract}
226
227 * Reading:: Options to Help Read Archives
228 * Writing:: Changing How @command{tar} Writes Files
229 * Scarce:: Coping with Scarce Resources
230
231 Options to Help Read Archives
232
233 * read full records::
234 * Ignore Zeros::
235
236 Changing How @command{tar} Writes Files
237
238 * Dealing with Old Files::
239 * Overwrite Old Files::
240 * Keep Old Files::
241 * Keep Newer Files::
242 * Unlink First::
243 * Recursive Unlink::
244 * Data Modification Times::
245 * Setting Access Permissions::
246 * Directory Modification Times and Permissions::
247 * Writing to Standard Output::
248 * Writing to an External Program::
249 * remove files::
250
251 Coping with Scarce Resources
252
253 * Starting File::
254 * Same Order::
255
256 Performing Backups and Restoring Files
257
258 * Full Dumps:: Using @command{tar} to Perform Full Dumps
259 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
260 * Backup Levels:: Levels of Backups
261 * Backup Parameters:: Setting Parameters for Backups and Restoration
262 * Scripted Backups:: Using the Backup Scripts
263 * Scripted Restoration:: Using the Restore Script
264
265 Setting Parameters for Backups and Restoration
266
267 * General-Purpose Variables::
268 * Magnetic Tape Control::
269 * User Hooks::
270 * backup-specs example:: An Example Text of @file{Backup-specs}
271
272 Choosing Files and Names for @command{tar}
273
274 * file:: Choosing the Archive's Name
275 * Selecting Archive Members::
276 * files:: Reading Names from a File
277 * exclude:: Excluding Some Files
278 * wildcards:: Wildcards Patterns and Matching
279 * quoting styles:: Ways of Quoting Special Characters in Names
280 * transform:: Modifying File and Member Names
281 * after:: Operating Only on New Files
282 * recurse:: Descending into Directories
283 * one:: Crossing File System Boundaries
284
285 Reading Names from a File
286
287 * nul::
288
289 Excluding Some Files
290
291 * problems with exclude::
292
293 Wildcards Patterns and Matching
294
295 * controlling pattern-matching::
296
297 Crossing File System Boundaries
298
299 * directory:: Changing Directory
300 * absolute:: Absolute File Names
301
302 Date input formats
303
304 * General date syntax:: Common rules.
305 * Calendar date items:: 19 Dec 1994.
306 * Time of day items:: 9:20pm.
307 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
308 * Day of week items:: Monday and others.
309 * Relative items in date strings:: next tuesday, 2 years ago.
310 * Pure numbers in date strings:: 19931219, 1440.
311 * Seconds since the Epoch:: @@1078100502.
312 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
313 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
314
315 Controlling the Archive Format
316
317 * Portability:: Making @command{tar} Archives More Portable
318 * Compression:: Using Less Space through Compression
319 * Attributes:: Handling File Attributes
320 * cpio:: Comparison of @command{tar} and @command{cpio}
321
322 Making @command{tar} Archives More Portable
323
324 * Portable Names:: Portable Names
325 * dereference:: Symbolic Links
326 * old:: Old V7 Archives
327 * ustar:: Ustar Archives
328 * gnu:: GNU and old GNU format archives.
329 * posix:: @acronym{POSIX} archives
330 * Checksumming:: Checksumming Problems
331 * Large or Negative Values:: Large files, negative time stamps, etc.
332
333 @GNUTAR{} and @acronym{POSIX} @command{tar}
334
335 * PAX keywords:: Controlling Extended Header Keywords.
336
337 Using Less Space through Compression
338
339 * gzip:: Creating and Reading Compressed Archives
340 * sparse:: Archiving Sparse Files
341
342 Tapes and Other Archive Media
343
344 * Device:: Device selection and switching
345 * Remote Tape Server::
346 * Common Problems and Solutions::
347 * Blocking:: Blocking
348 * Many:: Many archives on one tape
349 * Using Multiple Tapes:: Using Multiple Tapes
350 * label:: Including a Label in the Archive
351 * verify::
352 * Write Protection::
353
354 Blocking
355
356 * Format Variations:: Format Variations
357 * Blocking Factor:: The Blocking Factor of an Archive
358
359 Many Archives on One Tape
360
361 * Tape Positioning:: Tape Positions and Tape Marks
362 * mt:: The @command{mt} Utility
363
364 Using Multiple Tapes
365
366 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
367 * Tape Files:: Tape Files
368 * Tarcat:: Concatenate Volumes into a Single Archive
369
370
371 Genfile
372
373 * Generate Mode:: File Generation Mode.
374 * Status Mode:: File Status Mode.
375 * Exec Mode:: Synchronous Execution mode.
376
377 Tar Internals
378
379 * Standard:: Basic Tar Format
380 * Extensions:: @acronym{GNU} Extensions to the Archive Format
381 * Snapshot Files::
382 * Dumpdir::
383
384 Copying This Manual
385
386 * GNU Free Documentation License:: License for copying this manual
387
388 @end detailmenu
389 @end menu
390
391 @node Introduction
392 @chapter Introduction
393
394 @GNUTAR{} creates
395 and manipulates @dfn{archives} which are actually collections of
396 many other files; the program provides users with an organized and
397 systematic method for controlling a large amount of data.
398 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
399 archives need not (and these days, typically do not) reside on tapes.
400
401 @menu
402 * Book Contents:: What this Book Contains
403 * Definitions:: Some Definitions
404 * What tar Does:: What @command{tar} Does
405 * Naming tar Archives:: How @command{tar} Archives are Named
406 * Authors:: @GNUTAR{} Authors
407 * Reports:: Reporting bugs or suggestions
408 @end menu
409
410 @node Book Contents
411 @section What this Book Contains
412
413 The first part of this chapter introduces you to various terms that will
414 recur throughout the book. It also tells you who has worked on @GNUTAR{}
415 and its documentation, and where you should send bug reports
416 or comments.
417
418 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
419 gentle introduction for people who are new to using @command{tar}. It is
420 meant to be self contained, not requiring any reading from subsequent
421 chapters to make sense. It moves from topic to topic in a logical,
422 progressive order, building on information already explained.
423
424 Although the tutorial is paced and structured to allow beginners to
425 learn how to use @command{tar}, it is not intended solely for beginners.
426 The tutorial explains how to use the three most frequently used
427 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
428 two frequently used options (@samp{file} and @samp{verbose}). The other
429 chapters do not refer to the tutorial frequently; however, if a section
430 discusses something which is a complex variant of a basic concept, there
431 may be a cross reference to that basic concept. (The entire book,
432 including the tutorial, assumes that the reader understands some basic
433 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
434
435 The third chapter presents the remaining five operations, and
436 information about using @command{tar} options and option syntax.
437
438 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
439 than the reality. should think about whether this makes sense to say
440 here, or not.} The other chapters are meant to be used as a
441 reference. Each chapter presents everything that needs to be said
442 about a specific topic.
443
444 One of the chapters (@pxref{Date input formats}) exists in its
445 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
446 In addition, one section of this manual (@pxref{Standard}) contains a
447 big quote which is taken directly from @command{tar} sources.
448
449 In general, we give both long and short (abbreviated) option names
450 at least once in each section where the relevant option is covered, so
451 that novice readers will become familiar with both styles. (A few
452 options have no short versions, and the relevant sections will
453 indicate this.)
454
455 @node Definitions
456 @section Some Definitions
457
458 @cindex archive
459 @cindex tar archive
460 The @command{tar} program is used to create and manipulate @command{tar}
461 archives. An @dfn{archive} is a single file which contains the contents
462 of many files, while still identifying the names of the files, their
463 owner(s), and so forth. (In addition, archives record access
464 permissions, user and group, size in bytes, and data modification time.
465 Some archives also record the file names in each archived directory, as
466 well as other file and directory information.) You can use @command{tar}
467 to @dfn{create} a new archive in a specified directory.
468
469 @cindex member
470 @cindex archive member
471 @cindex file name
472 @cindex member name
473 The files inside an archive are called @dfn{members}. Within this
474 manual, we use the term @dfn{file} to refer only to files accessible in
475 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
476 @dfn{member} to refer only to the members of an archive. Similarly, a
477 @dfn{file name} is the name of a file, as it resides in the file system,
478 and a @dfn{member name} is the name of an archive member within the
479 archive.
480
481 @cindex extraction
482 @cindex unpacking
483 The term @dfn{extraction} refers to the process of copying an archive
484 member (or multiple members) into a file in the file system. Extracting
485 all the members of an archive is often called @dfn{extracting the
486 archive}. The term @dfn{unpack} can also be used to refer to the
487 extraction of many or all the members of an archive. Extracting an
488 archive does not destroy the archive's structure, just as creating an
489 archive does not destroy the copies of the files that exist outside of
490 the archive. You may also @dfn{list} the members in a given archive
491 (this is often thought of as ``printing'' them to the standard output,
492 or the command line), or @dfn{append} members to a pre-existing archive.
493 All of these operations can be performed using @command{tar}.
494
495 @node What tar Does
496 @section What @command{tar} Does
497
498 @cindex tar
499 The @command{tar} program provides the ability to create @command{tar}
500 archives, as well as various other kinds of manipulation. For example,
501 you can use @command{tar} on previously created archives to extract files,
502 to store additional files, or to update or list files which were already
503 stored.
504
505 Initially, @command{tar} archives were used to store files conveniently on
506 magnetic tape. The name @command{tar} comes from this use; it stands for
507 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
508 direct its output to available devices, files, or other programs (using
509 pipes). @command{tar} may even access remote devices or files (as archives).
510
511 You can use @command{tar} archives in many ways. We want to stress a few
512 of them: storage, backup, and transportation.
513
514 @FIXME{the following table entries need a bit of work..}
515 @table @asis
516 @item Storage
517 Often, @command{tar} archives are used to store related files for
518 convenient file transfer over a network. For example, the
519 @acronym{GNU} Project distributes its software bundled into
520 @command{tar} archives, so that all the files relating to a particular
521 program (or set of related programs) can be transferred as a single
522 unit.
523
524 A magnetic tape can store several files in sequence. However, the tape
525 has no names for these files; it only knows their relative position on
526 the tape. One way to store several files on one tape and retain their
527 names is by creating a @command{tar} archive. Even when the basic transfer
528 mechanism can keep track of names, as FTP can, the nuisance of handling
529 multiple files, directories, and multiple links makes @command{tar}
530 archives useful.
531
532 Archive files are also used for long-term storage. You can think of
533 this as transportation from the present into the future. (It is a
534 science-fiction idiom that you can move through time as well as in
535 space; the idea here is that @command{tar} can be used to move archives in
536 all dimensions, even time!)
537
538 @item Backup
539 Because the archive created by @command{tar} is capable of preserving
540 file information and directory structure, @command{tar} is commonly
541 used for performing full and incremental backups of disks. A backup
542 puts a collection of files (possibly pertaining to many users and
543 projects) together on a disk or a tape. This guards against
544 accidental destruction of the information in those files.
545 @GNUTAR{} has special features that allow it to be
546 used to make incremental and full dumps of all the files in a
547 file system.
548
549 @item Transportation
550 You can create an archive on one system, transfer it to another system,
551 and extract the contents there. This allows you to transport a group of
552 files from one system to another.
553 @end table
554
555 @node Naming tar Archives
556 @section How @command{tar} Archives are Named
557
558 Conventionally, @command{tar} archives are given names ending with
559 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
560 but this manual follows that convention in order to accustom readers to
561 it and to make examples more clear.
562
563 @cindex tar file
564 @cindex entry
565 @cindex tar entry
566 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
567 archive members as ``files'' or ``entries''. For people familiar with
568 the operation of @command{tar}, this causes no difficulty. However, in
569 this manual, we consistently refer to ``archives'' and ``archive
570 members'' to make learning to use @command{tar} easier for novice users.
571
572 @node Authors
573 @section @GNUTAR{} Authors
574
575 @GNUTAR{} was originally written by John Gilmore,
576 and modified by many people. The @acronym{GNU} enhancements were
577 written by Jay Fenlason, then Joy Kendall, and the whole package has
578 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
579 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
580 numerous and kind users.
581
582 We wish to stress that @command{tar} is a collective work, and owes much to
583 all those people who reported problems, offered solutions and other
584 insights, or shared their thoughts and suggestions. An impressive, yet
585 partial list of those contributors can be found in the @file{THANKS}
586 file from the @GNUTAR{} distribution.
587
588 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
589 sure i want to spell out the history in this detail, at least not for
590 the printed book. i'm just not sure it needs to be said this way.
591 i'll think about it.}
592
593 @FIXME{History is more important, and surely more interesting, than
594 actual names. Quoting names without history would be meaningless. FP}
595
596 Jay Fenlason put together a draft of a @GNUTAR{}
597 manual, borrowing notes from the original man page from John Gilmore.
598 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
599 Gorin worked on a tutorial and manual for @GNUTAR{}.
600 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
601 taking information from all these sources and merging them. Melissa
602 Weisshaus finally edited and redesigned the book to create version
603 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
604 by the current maintainer, Sergey Poznyakoff.
605
606 For version 1.12, Daniel Hagerty contributed a great deal of technical
607 consulting. In particular, he is the primary author of @ref{Backups}.
608
609 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
610 (see @url{http://savannah.gnu.org/projects/tar}), and
611 active development and maintenance work has started
612 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
613 Poznyakoff and Jeff Bailey.
614
615 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
616
617 @node Reports
618 @section Reporting bugs or suggestions
619
620 @cindex bug reports
621 @cindex reporting bugs
622 If you find problems or have suggestions about this program or manual,
623 please report them to @file{bug-tar@@gnu.org}.
624
625 When reporting a bug, please be sure to include as much detail as
626 possible, in order to reproduce it. @FIXME{Be more specific, I'd
627 like to make this node as detailed as 'Bug reporting' node in Emacs
628 manual}.
629
630 @node Tutorial
631 @chapter Tutorial Introduction to @command{tar}
632
633 This chapter guides you through some basic examples of three @command{tar}
634 operations: @option{--create}, @option{--list}, and @option{--extract}. If
635 you already know how to use some other version of @command{tar}, then you
636 may not need to read this chapter. This chapter omits most complicated
637 details about how @command{tar} works.
638
639 @menu
640 * assumptions::
641 * stylistic conventions::
642 * basic tar options:: Basic @command{tar} Operations and Options
643 * frequent operations::
644 * Two Frequent Options::
645 * create:: How to Create Archives
646 * list:: How to List Archives
647 * extract:: How to Extract Members from an Archive
648 * going further::
649 @end menu
650
651 @node assumptions
652 @section Assumptions this Tutorial Makes
653
654 This chapter is paced to allow beginners to learn about @command{tar}
655 slowly. At the same time, we will try to cover all the basic aspects of
656 these three operations. In order to accomplish both of these tasks, we
657 have made certain assumptions about your knowledge before reading this
658 manual, and the hardware you will be using:
659
660 @itemize @bullet
661 @item
662 Before you start to work through this tutorial, you should understand
663 what the terms ``archive'' and ``archive member'' mean
664 (@pxref{Definitions}). In addition, you should understand something
665 about how Unix-type operating systems work, and you should know how to
666 use some basic utilities. For example, you should know how to create,
667 list, copy, rename, edit, and delete files and directories; how to
668 change between directories; and how to figure out where you are in the
669 file system. You should have some basic understanding of directory
670 structure and how files are named according to which directory they are
671 in. You should understand concepts such as standard output and standard
672 input, what various definitions of the term ``argument'' mean, and the
673 differences between relative and absolute path names. @FIXME{and what
674 else?}
675
676 @item
677 This manual assumes that you are working from your own home directory
678 (unless we state otherwise). In this tutorial, you will create a
679 directory to practice @command{tar} commands in. When we show path names,
680 we will assume that those paths are relative to your home directory.
681 For example, my home directory path is @file{/home/fsf/melissa}. All of
682 my examples are in a subdirectory of the directory named by that path
683 name; the subdirectory is called @file{practice}.
684
685 @item
686 In general, we show examples of archives which exist on (or can be
687 written to, or worked with from) a directory on a hard disk. In most
688 cases, you could write those archives to, or work with them on any other
689 device, such as a tape drive. However, some of the later examples in
690 the tutorial and next chapter will not work on tape drives.
691 Additionally, working with tapes is much more complicated than working
692 with hard disks. For these reasons, the tutorial does not cover working
693 with tape drives. @xref{Media}, for complete information on using
694 @command{tar} archives with tape drives.
695
696 @FIXME{this is a cop out. need to add some simple tape drive info.}
697 @end itemize
698
699 @node stylistic conventions
700 @section Stylistic Conventions
701
702 In the examples, @samp{$} represents a typical shell prompt. It
703 precedes lines you should type; to make this more clear, those lines are
704 shown in @kbd{this font}, as opposed to lines which represent the
705 computer's response; those lines are shown in @code{this font}, or
706 sometimes @samp{like this}.
707
708 @c When we have lines which are too long to be
709 @c displayed in any other way, we will show them like this:
710
711 @node basic tar options
712 @section Basic @command{tar} Operations and Options
713
714 @command{tar} can take a wide variety of arguments which specify and define
715 the actions it will have on the particular set of files or the archive.
716 The main types of arguments to @command{tar} fall into one of two classes:
717 operations, and options.
718
719 Some arguments fall into a class called @dfn{operations}; exactly one of
720 these is both allowed and required for any instance of using @command{tar};
721 you may @emph{not} specify more than one. People sometimes speak of
722 @dfn{operating modes}. You are in a particular operating mode when you
723 have specified the operation which specifies it; there are eight
724 operations in total, and thus there are eight operating modes.
725
726 The other arguments fall into the class known as @dfn{options}. You are
727 not required to specify any options, and you are allowed to specify more
728 than one at a time (depending on the way you are using @command{tar} at
729 that time). Some options are used so frequently, and are so useful for
730 helping you type commands more carefully that they are effectively
731 ``required''. We will discuss them in this chapter.
732
733 You can write most of the @command{tar} operations and options in any
734 of three forms: long (mnemonic) form, short form, and old style. Some
735 of the operations and options have no short or ``old'' forms; however,
736 the operations and options which we will cover in this tutorial have
737 corresponding abbreviations. @FIXME{make sure this is still the case,
738 at the end}We will indicate those abbreviations appropriately to get
739 you used to seeing them. (Note that the ``old style'' option forms
740 exist in @GNUTAR{} for compatibility with Unix
741 @command{tar}. In this book we present a full discussion of this way
742 of writing options and operations (@pxref{Old Options}), and we discuss
743 the other two styles of writing options (@xref{Long Options}, and
744 @pxref{Short Options}).
745
746 In the examples and in the text of this tutorial, we usually use the
747 long forms of operations and options; but the ``short'' forms produce
748 the same result and can make typing long @command{tar} commands easier.
749 For example, instead of typing
750
751 @smallexample
752 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
753 @end smallexample
754
755 @noindent
756 you can type
757 @smallexample
758 @kbd{tar -c -v -f afiles.tar apple angst aspic}
759 @end smallexample
760
761 @noindent
762 or even
763 @smallexample
764 @kbd{tar -cvf afiles.tar apple angst aspic}
765 @end smallexample
766
767 @noindent
768 For more information on option syntax, see @ref{Advanced tar}. In
769 discussions in the text, when we name an option by its long form, we
770 also give the corresponding short option in parentheses.
771
772 The term, ``option'', can be confusing at times, since ``operations''
773 are often lumped in with the actual, @emph{optional} ``options'' in certain
774 general class statements. For example, we just talked about ``short and
775 long forms of options and operations''. However, experienced @command{tar}
776 users often refer to these by shorthand terms such as, ``short and long
777 options''. This term assumes that the ``operations'' are included, also.
778 Context will help you determine which definition of ``options'' to use.
779
780 Similarly, the term ``command'' can be confusing, as it is often used in
781 two different ways. People sometimes refer to @command{tar} ``commands''.
782 A @command{tar} @dfn{command} is the entire command line of user input
783 which tells @command{tar} what to do --- including the operation, options,
784 and any arguments (file names, pipes, other commands, etc). However,
785 you will also sometimes hear the term ``the @command{tar} command''. When
786 the word ``command'' is used specifically like this, a person is usually
787 referring to the @command{tar} @emph{operation}, not the whole line.
788 Again, use context to figure out which of the meanings the speaker
789 intends.
790
791 @node frequent operations
792 @section The Three Most Frequently Used Operations
793
794 Here are the three most frequently used operations (both short and long
795 forms), as well as a brief description of their meanings. The rest of
796 this chapter will cover how to use these operations in detail. We will
797 present the rest of the operations in the next chapter.
798
799 @table @option
800 @item --create
801 @itemx -c
802 Create a new @command{tar} archive.
803 @item --list
804 @itemx -t
805 List the contents of an archive.
806 @item --extract
807 @itemx -x
808 Extract one or more members from an archive.
809 @end table
810
811 @node Two Frequent Options
812 @section Two Frequently Used Options
813
814 To understand how to run @command{tar} in the three operating modes listed
815 previously, you also need to understand how to use two of the options to
816 @command{tar}: @option{--file} (which takes an archive file as an argument)
817 and @option{--verbose}. (You are usually not @emph{required} to specify
818 either of these options when you run @command{tar}, but they can be very
819 useful in making things more clear and helping you avoid errors.)
820
821 @menu
822 * file tutorial::
823 * verbose tutorial::
824 * help tutorial::
825 @end menu
826
827 @node file tutorial
828 @unnumberedsubsec The @option{--file} Option
829
830 @table @option
831 @xopindex{file, tutorial}
832 @item --file=@var{archive-name}
833 @itemx -f @var{archive-name}
834 Specify the name of an archive file.
835 @end table
836
837 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
838 use @command{tar}; this option determines the name of the archive file
839 that @command{tar} will work on.
840
841 @vrindex TAPE
842 If you don't specify this argument, then @command{tar} will examine
843 the environment variable @env{TAPE}. If it is set, its value will be
844 used as the archive name. Otherwise, @command{tar} will use the
845 default archive, determined at the compile time. Usually it is
846 standard output or some physical tape drive attached to your machine
847 (you can verify what the default is by running @kbd{tar
848 --show-defaults}, @pxref{defaults}). If there is no tape drive
849 attached, or the default is not meaningful, then @command{tar} will
850 print an error message. The error message might look roughly like one
851 of the following:
852
853 @smallexample
854 tar: can't open /dev/rmt8 : No such device or address
855 tar: can't open /dev/rsmt0 : I/O error
856 @end smallexample
857
858 @noindent
859 To avoid confusion, we recommend that you always specify an archive file
860 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
861 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
862 @ref{file}.
863
864 @node verbose tutorial
865 @unnumberedsubsec The @option{--verbose} Option
866
867 @table @option
868 @xopindex{verbose, introduced}
869 @item --verbose
870 @itemx -v
871 Show the files being worked on as @command{tar} is running.
872 @end table
873
874 @option{--verbose} (@option{-v}) shows details about the results of running
875 @command{tar}. This can be especially useful when the results might not be
876 obvious. For example, if you want to see the progress of @command{tar} as
877 it writes files into the archive, you can use the @option{--verbose}
878 option. In the beginning, you may find it useful to use
879 @option{--verbose} at all times; when you are more accustomed to
880 @command{tar}, you will likely want to use it at certain times but not at
881 others. We will use @option{--verbose} at times to help make something
882 clear, and we will give many examples both using and not using
883 @option{--verbose} to show the differences.
884
885 Each instance of @option{--verbose} on the command line increases the
886 verbosity level by one, so if you need more details on the output,
887 specify it twice.
888
889 When reading archives (@option{--list}, @option{--extract},
890 @option{--diff}), @command{tar} by default prints only the names of
891 the members being extracted. Using @option{--verbose} will show a full,
892 @command{ls} style member listing.
893
894 In contrast, when writing archives (@option{--create}, @option{--append},
895 @option{--update}), @command{tar} does not print file names by
896 default. So, a single @option{--verbose} option shows the file names
897 being added to the archive, while two @option{--verbose} options
898 enable the full listing.
899
900 For example, to create an archive in verbose mode:
901
902 @smallexample
903 $ @kbd{tar -cvf afiles.tar apple angst aspic}
904 apple
905 angst
906 aspic
907 @end smallexample
908
909 @noindent
910 Creating the same archive with the verbosity level 2 could give:
911
912 @smallexample
913 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
914 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
915 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
916 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
917 @end smallexample
918
919 @noindent
920 This works equally well using short or long forms of options. Using
921 long forms, you would simply write out the mnemonic form of the option
922 twice, like this:
923
924 @smallexample
925 $ @kbd{tar --create --verbose --verbose @dots{}}
926 @end smallexample
927
928 @noindent
929 Note that you must double the hyphens properly each time.
930
931 Later in the tutorial, we will give examples using @w{@option{--verbose
932 --verbose}}.
933
934 @anchor{verbose member listing}
935 The full output consists of six fields:
936
937 @itemize @bullet
938 @item File type and permissions in symbolic form.
939 These are displayed in the same format as the first column of
940 @command{ls -l} output (@pxref{What information is listed,
941 format=verbose, Verbose listing, fileutils, GNU file utilities}).
942
943 @item Owner name and group separated by a slash character.
944 If these data are not available (for example, when listing a @samp{v7} format
945 archive), numeric ID values are printed instead.
946
947 @item Size of the file, in bytes.
948
949 @item File modification date in ISO 8601 format.
950
951 @item File modification time.
952
953 @item File name.
954 If the name contains any special characters (white space, newlines,
955 etc.) these are displayed in an unambiguous form using so called
956 @dfn{quoting style}. For the detailed discussion of available styles
957 and on how to use them, see @ref{quoting styles}.
958
959 Depending on the file type, the name can be followed by some
960 additional information, described in the following table:
961
962 @table @samp
963 @item -> @var{link-name}
964 The file or archive member is a @dfn{symbolic link} and
965 @var{link-name} is the name of file it links to.
966
967 @item link to @var{link-name}
968 The file or archive member is a @dfn{hard link} and @var{link-name} is
969 the name of file it links to.
970
971 @item --Long Link--
972 The archive member is an old GNU format long link. You will normally
973 not encounter this.
974
975 @item --Long Name--
976 The archive member is an old GNU format long name. You will normally
977 not encounter this.
978
979 @item --Volume Header--
980 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
981
982 @item --Continued at byte @var{n}--
983 Encountered only at the beginning of a multy-volume archive
984 (@pxref{Using Multiple Tapes}). This archive member is a continuation
985 from the previous volume. The number @var{n} gives the offset where
986 the original file was split.
987
988 @item --Mangled file names--
989 This archive member contains @dfn{mangled file names} declarations,
990 a special member type that was used by early versions of @GNUTAR{}.
991 You probably will never encounter this, unless you are reading a very
992 old archive.
993
994 @item unknown file type @var{c}
995 An archive member of unknown type. @var{c} is the type character from
996 the archive header. If you encounter such a message, it means that
997 either your archive contains proprietary member types @GNUTAR{} is not
998 able to handle, or the archive is corrupted.
999 @end table
1000
1001 @end itemize
1002
1003 For example, here is an archive listing containing most of the special
1004 suffixes explained above:
1005
1006 @smallexample
1007 @group
1008 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1009 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1010 byte 32456--
1011 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1012 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1013 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1014 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1015 @end group
1016 @end smallexample
1017
1018 @smallexample
1019 @end smallexample
1020
1021 @node help tutorial
1022 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1023
1024 @table @option
1025 @opindex help
1026 @item --help
1027
1028 The @option{--help} option to @command{tar} prints out a very brief list of
1029 all operations and option available for the current version of
1030 @command{tar} available on your system.
1031 @end table
1032
1033 @node create
1034 @section How to Create Archives
1035 @UNREVISED
1036
1037 @cindex Creation of the archive
1038 @cindex Archive, creation of
1039 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1040 you use to create a @command{tar} archive. We will explain
1041 @option{--create} first because, in order to learn about the other
1042 operations, you will find it useful to have an archive available to
1043 practice on.
1044
1045 To make this easier, in this section you will first create a directory
1046 containing three files. Then, we will show you how to create an
1047 @emph{archive} (inside the new directory). Both the directory, and
1048 the archive are specifically for you to practice on. The rest of this
1049 chapter and the next chapter will show many examples using this
1050 directory and the files you will create: some of those files may be
1051 other directories and other archives.
1052
1053 The three files you will archive in this example are called
1054 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1055 @file{collection.tar}.
1056
1057 This section will proceed slowly, detailing how to use @option{--create}
1058 in @code{verbose} mode, and showing examples using both short and long
1059 forms. In the rest of the tutorial, and in the examples in the next
1060 chapter, we will proceed at a slightly quicker pace. This section
1061 moves more slowly to allow beginning users to understand how
1062 @command{tar} works.
1063
1064 @menu
1065 * prepare for examples::
1066 * Creating the archive::
1067 * create verbose::
1068 * short create::
1069 * create dir::
1070 @end menu
1071
1072 @node prepare for examples
1073 @subsection Preparing a Practice Directory for Examples
1074
1075 To follow along with this and future examples, create a new directory
1076 called @file{practice} containing files called @file{blues}, @file{folk}
1077 and @file{jazz}. The files can contain any information you like:
1078 ideally, they should contain information which relates to their names,
1079 and be of different lengths. Our examples assume that @file{practice}
1080 is a subdirectory of your home directory.
1081
1082 Now @command{cd} to the directory named @file{practice}; @file{practice}
1083 is now your @dfn{working directory}. (@emph{Please note}: Although
1084 the full path name of this directory is
1085 @file{/@var{homedir}/practice}, in our examples we will refer to
1086 this directory as @file{practice}; the @var{homedir} is presumed.
1087
1088 In general, you should check that the files to be archived exist where
1089 you think they do (in the working directory) by running @command{ls}.
1090 Because you just created the directory and the files and have changed to
1091 that directory, you probably don't need to do that this time.
1092
1093 It is very important to make sure there isn't already a file in the
1094 working directory with the archive name you intend to use (in this case,
1095 @samp{collection.tar}), or that you don't care about its contents.
1096 Whenever you use @samp{create}, @command{tar} will erase the current
1097 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1098 will not tell you if you are about to overwrite an archive unless you
1099 specify an option which does this (@pxref{backup}, for the
1100 information on how to do so). To add files to an existing archive,
1101 you need to use a different option, such as @option{--append} (@option{-r}); see
1102 @ref{append} for information on how to do this.
1103
1104 @node Creating the archive
1105 @subsection Creating the Archive
1106
1107 @xopindex{create, introduced}
1108 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1109 archive named @file{collection.tar}, use the following command:
1110
1111 @smallexample
1112 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1113 @end smallexample
1114
1115 The order of the arguments is not very important, @emph{when using long
1116 option forms}. You could also say:
1117
1118 @smallexample
1119 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1120 @end smallexample
1121
1122 @noindent
1123 However, you can see that this order is harder to understand; this is
1124 why we will list the arguments in the order that makes the commands
1125 easiest to understand (and we encourage you to do the same when you use
1126 @command{tar}, to avoid errors).
1127
1128 Note that the part of the command which says,
1129 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1130 If you substituted any other string of characters for
1131 @kbd{collection.tar}, then that string would become the name of the
1132 archive file you create.
1133
1134 The order of the options becomes more important when you begin to use
1135 short forms. With short forms, if you type commands in the wrong order
1136 (even if you type them correctly in all other ways), you may end up with
1137 results you don't expect. For this reason, it is a good idea to get
1138 into the habit of typing options in the order that makes inherent sense.
1139 @xref{short create}, for more information on this.
1140
1141 In this example, you type the command as shown above: @option{--create}
1142 is the operation which creates the new archive
1143 (@file{collection.tar}), and @option{--file} is the option which lets
1144 you give it the name you chose. The files, @file{blues}, @file{folk},
1145 and @file{jazz}, are now members of the archive, @file{collection.tar}
1146 (they are @dfn{file name arguments} to the @option{--create} operation.
1147 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1148 in the archive, they are called @emph{archive members}, not files.
1149 (@pxref{Definitions,members}).
1150
1151 When you create an archive, you @emph{must} specify which files you
1152 want placed in the archive. If you do not specify any archive
1153 members, @GNUTAR{} will complain.
1154
1155 If you now list the contents of the working directory (@command{ls}), you will
1156 find the archive file listed as well as the files you saw previously:
1157
1158 @smallexample
1159 blues folk jazz collection.tar
1160 @end smallexample
1161
1162 @noindent
1163 Creating the archive @samp{collection.tar} did not destroy the copies of
1164 the files in the directory.
1165
1166 Keep in mind that if you don't indicate an operation, @command{tar} will not
1167 run and will prompt you for one. If you don't name any files, @command{tar}
1168 will complain. You must have write access to the working directory,
1169 or else you will not be able to create an archive in that directory.
1170
1171 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1172 an existing archive; it will delete the archive and write a new one.
1173 Use @option{--append} (@option{-r}) instead. @xref{append}.
1174
1175 @node create verbose
1176 @subsection Running @option{--create} with @option{--verbose}
1177
1178 @xopindex{create, using with @option{--verbose}}
1179 @xopindex{verbose, using with @option{--create}}
1180 If you include the @option{--verbose} (@option{-v}) option on the command line,
1181 @command{tar} will list the files it is acting on as it is working. In
1182 verbose mode, the @code{create} example above would appear as:
1183
1184 @smallexample
1185 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1186 blues
1187 folk
1188 jazz
1189 @end smallexample
1190
1191 This example is just like the example we showed which did not use
1192 @option{--verbose}, except that @command{tar} generated the remaining lines
1193 @iftex
1194 (note the different font styles).
1195 @end iftex
1196 @ifinfo
1197 .
1198 @end ifinfo
1199
1200 In the rest of the examples in this chapter, we will frequently use
1201 @code{verbose} mode so we can show actions or @command{tar} responses that
1202 you would otherwise not see, and which are important for you to
1203 understand.
1204
1205 @node short create
1206 @subsection Short Forms with @samp{create}
1207
1208 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1209 basic uses of @command{tar}, and you will use it countless times.
1210 Eventually, you will probably want to use abbreviated (or ``short'')
1211 forms of options. A full discussion of the three different forms that
1212 options can take appears in @ref{Styles}; for now, here is what the
1213 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1214 using short option forms:
1215
1216 @smallexample
1217 $ @kbd{tar -cvf collection.tar blues folk jazz}
1218 blues
1219 folk
1220 jazz
1221 @end smallexample
1222
1223 @noindent
1224 As you can see, the system responds the same no matter whether you use
1225 long or short option forms.
1226
1227 @FIXME{i don't like how this is worded:} One difference between using
1228 short and long option forms is that, although the exact placement of
1229 arguments following options is no more specific when using short forms,
1230 it is easier to become confused and make a mistake when using short
1231 forms. For example, suppose you attempted the above example in the
1232 following way:
1233
1234 @smallexample
1235 $ @kbd{tar -cfv collection.tar blues folk jazz}
1236 @end smallexample
1237
1238 @noindent
1239 In this case, @command{tar} will make an archive file called @file{v},
1240 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1241 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1242 is thus taken to be the chosen archive file name. @command{tar} will try
1243 to add a file called @file{collection.tar} to the @file{v} archive file;
1244 if the file @file{collection.tar} did not already exist, @command{tar} will
1245 report an error indicating that this file does not exist. If the file
1246 @file{collection.tar} does already exist (e.g., from a previous command
1247 you may have run), then @command{tar} will add this file to the archive.
1248 Because the @option{-v} option did not get registered, @command{tar} will not
1249 run under @samp{verbose} mode, and will not report its progress.
1250
1251 The end result is that you may be quite confused about what happened,
1252 and possibly overwrite a file. To illustrate this further, we will show
1253 you how an example we showed previously would look using short forms.
1254
1255 This example,
1256
1257 @smallexample
1258 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1259 @end smallexample
1260
1261 @noindent
1262 is confusing as it is. When shown using short forms, however, it
1263 becomes much more so:
1264
1265 @smallexample
1266 $ @kbd{tar blues -c folk -f collection.tar jazz}
1267 @end smallexample
1268
1269 @noindent
1270 It would be very easy to put the wrong string of characters
1271 immediately following the @option{-f}, but doing that could sacrifice
1272 valuable data.
1273
1274 For this reason, we recommend that you pay very careful attention to
1275 the order of options and placement of file and archive names,
1276 especially when using short option forms. Not having the option name
1277 written out mnemonically can affect how well you remember which option
1278 does what, and therefore where different names have to be placed.
1279
1280 @node create dir
1281 @subsection Archiving Directories
1282
1283 @cindex Archiving Directories
1284 @cindex Directories, Archiving
1285 You can archive a directory by specifying its directory name as a
1286 file name argument to @command{tar}. The files in the directory will be
1287 archived relative to the working directory, and the directory will be
1288 re-created along with its contents when the archive is extracted.
1289
1290 To archive a directory, first move to its superior directory. If you
1291 have followed the previous instructions in this tutorial, you should
1292 type:
1293
1294 @smallexample
1295 $ @kbd{cd ..}
1296 $
1297 @end smallexample
1298
1299 @noindent
1300 This will put you into the directory which contains @file{practice},
1301 i.e., your home directory. Once in the superior directory, you can
1302 specify the subdirectory, @file{practice}, as a file name argument. To
1303 store @file{practice} in the new archive file @file{music.tar}, type:
1304
1305 @smallexample
1306 $ @kbd{tar --create --verbose --file=music.tar practice}
1307 @end smallexample
1308
1309 @noindent
1310 @command{tar} should output:
1311
1312 @smallexample
1313 practice/
1314 practice/blues
1315 practice/folk
1316 practice/jazz
1317 practice/collection.tar
1318 @end smallexample
1319
1320 Note that the archive thus created is not in the subdirectory
1321 @file{practice}, but rather in the current working directory---the
1322 directory from which @command{tar} was invoked. Before trying to archive a
1323 directory from its superior directory, you should make sure you have
1324 write access to the superior directory itself, not only the directory
1325 you are trying archive with @command{tar}. For example, you will probably
1326 not be able to store your home directory in an archive by invoking
1327 @command{tar} from the root directory; @xref{absolute}. (Note
1328 also that @file{collection.tar}, the original archive file, has itself
1329 been archived. @command{tar} will accept any file as a file to be
1330 archived, regardless of its content. When @file{music.tar} is
1331 extracted, the archive file @file{collection.tar} will be re-written
1332 into the file system).
1333
1334 If you give @command{tar} a command such as
1335
1336 @smallexample
1337 $ @kbd{tar --create --file=foo.tar .}
1338 @end smallexample
1339
1340 @noindent
1341 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1342 dumped}. This happens because @command{tar} creates the archive
1343 @file{foo.tar} in the current directory before putting any files into
1344 it. Then, when @command{tar} attempts to add all the files in the
1345 directory @file{.} to the archive, it notices that the file
1346 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1347 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1348 will continue in this case, and create the archive
1349 normally, except for the exclusion of that one file. (@emph{Please
1350 note:} Other implementations of @command{tar} may not be so clever;
1351 they will enter an infinite loop when this happens, so you should not
1352 depend on this behavior unless you are certain you are running
1353 @GNUTAR{}. In general, it is wise to always place the archive outside
1354 of the directory being dumped.
1355
1356 @node list
1357 @section How to List Archives
1358
1359 @opindex list
1360 Frequently, you will find yourself wanting to determine exactly what a
1361 particular archive contains. You can use the @option{--list}
1362 (@option{-t}) operation to get the member names as they currently
1363 appear in the archive, as well as various attributes of the files at
1364 the time they were archived. For example, you can examine the archive
1365 @file{collection.tar} that you created in the last section with the
1366 command,
1367
1368 @smallexample
1369 $ @kbd{tar --list --file=collection.tar}
1370 @end smallexample
1371
1372 @noindent
1373 The output of @command{tar} would then be:
1374
1375 @smallexample
1376 blues
1377 folk
1378 jazz
1379 @end smallexample
1380
1381 @noindent
1382 The archive @file{bfiles.tar} would list as follows:
1383
1384 @smallexample
1385 ./birds
1386 baboon
1387 ./box
1388 @end smallexample
1389
1390 @noindent
1391 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1392 @var{archive-name}}) option just as with @option{--create}
1393 (@option{-c}) to specify the name of the archive.
1394
1395 @xopindex{list, using with @option{--verbose}}
1396 @xopindex{verbose, using with @option{--list}}
1397 If you use the @option{--verbose} (@option{-v}) option with
1398 @option{--list}, then @command{tar} will print out a listing
1399 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1400 forth. This output is described in detail in @ref{verbose member listing}.
1401
1402 If you had used @option{--verbose} (@option{-v}) mode, the example
1403 above would look like:
1404
1405 @smallexample
1406 $ @kbd{tar --list --verbose --file=collection.tar folk}
1407 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1408 @end smallexample
1409
1410 @cindex listing member and file names
1411 @anchor{listing member and file names}
1412 It is important to notice that the output of @kbd{tar --list
1413 --verbose} does not necessarily match that produced by @kbd{tar
1414 --create --verbose} while creating the archive. It is because
1415 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1416 prefixes from file names before storing them in the archive
1417 (@xref{absolute}, for more information). In other
1418 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1419 an archive and @dfn{member names} when listing it. Consider this
1420 example:
1421
1422 @smallexample
1423 @group
1424 $ @kbd{tar cfv archive /etc/mail}
1425 tar: Removing leading `/' from member names
1426 /etc/mail/
1427 /etc/mail/sendmail.cf
1428 /etc/mail/aliases
1429 $ @kbd{tar tf archive}
1430 etc/mail/
1431 etc/mail/sendmail.cf
1432 etc/mail/aliases
1433 @end group
1434 @end smallexample
1435
1436 @opindex show-stored-names
1437 This default behavior can sometimes be inconvenient. You can force
1438 @GNUTAR{} show member names when creating archive by supplying
1439 @option{--show-stored-names} option.
1440
1441 @table @option
1442 @item --show-stored-names
1443 Print member (as opposed to @emph{file}) names when creating the archive.
1444 @end table
1445
1446 @cindex File name arguments, using @option{--list} with
1447 @xopindex{list, using with file name arguments}
1448 You can specify one or more individual member names as arguments when
1449 using @samp{list}. In this case, @command{tar} will only list the
1450 names of members you identify. For example, @w{@kbd{tar --list
1451 --file=afiles.tar apple}} would only print @file{apple}.
1452
1453 Because @command{tar} preserves paths, file names must be specified as
1454 they appear in the archive (i.e., relative to the directory from which
1455 the archive was created). Therefore, it is essential when specifying
1456 member names to @command{tar} that you give the exact member names.
1457 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1458 error message something like @samp{tar: birds: Not found in archive},
1459 because there is no member named @file{birds}, only one named
1460 @file{./birds}. While the names @file{birds} and @file{./birds} name
1461 the same file, @emph{member} names by default are compared verbatim.
1462
1463 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1464 with @file{baboon}, because this exact member name is in the archive file
1465 @file{bfiles.tar}. If you are not sure of the exact file name,
1466 use @dfn{globbing patterns}, for example:
1467
1468 @smallexample
1469 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1470 @end smallexample
1471
1472 @noindent
1473 will list all members whose name contains @samp{b}. @xref{wildcards},
1474 for a detailed discussion of globbing patterns and related
1475 @command{tar} command line options.
1476
1477 @menu
1478 * list dir::
1479 @end menu
1480
1481 @node list dir
1482 @unnumberedsubsec Listing the Contents of a Stored Directory
1483
1484 To get information about the contents of an archived directory,
1485 use the directory name as a file name argument in conjunction with
1486 @option{--list} (@option{-t}). To find out file attributes, include the
1487 @option{--verbose} (@option{-v}) option.
1488
1489 For example, to find out about files in the directory @file{practice}, in
1490 the archive file @file{music.tar}, type:
1491
1492 @smallexample
1493 $ @kbd{tar --list --verbose --file=music.tar practice}
1494 @end smallexample
1495
1496 @command{tar} responds:
1497
1498 @smallexample
1499 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1500 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1501 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1502 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1503 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1504 @end smallexample
1505
1506 When you use a directory name as a file name argument, @command{tar} acts on
1507 all the files (including sub-directories) in that directory.
1508
1509 @node extract
1510 @section How to Extract Members from an Archive
1511 @UNREVISED
1512 @cindex Extraction
1513 @cindex Retrieving files from an archive
1514 @cindex Resurrecting files from an archive
1515
1516 @opindex extract
1517 Creating an archive is only half the job---there is no point in storing
1518 files in an archive if you can't retrieve them. The act of retrieving
1519 members from an archive so they can be used and manipulated as
1520 unarchived files again is called @dfn{extraction}. To extract files
1521 from an archive, use the @option{--extract} (@option{--get} or
1522 @option{-x}) operation. As with @option{--create}, specify the name
1523 of the archive with @option{--file} (@option{-f}) option. Extracting
1524 an archive does not modify the archive in any way; you can extract it
1525 multiple times if you want or need to.
1526
1527 Using @option{--extract}, you can extract an entire archive, or specific
1528 files. The files can be directories containing other files, or not. As
1529 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1530 long form of the operation without affecting the performance.
1531
1532 @menu
1533 * extracting archives::
1534 * extracting files::
1535 * extract dir::
1536 * extracting untrusted archives::
1537 * failing commands::
1538 @end menu
1539
1540 @node extracting archives
1541 @subsection Extracting an Entire Archive
1542
1543 To extract an entire archive, specify the archive file name only, with
1544 no individual file names as arguments. For example,
1545
1546 @smallexample
1547 $ @kbd{tar -xvf collection.tar}
1548 @end smallexample
1549
1550 @noindent
1551 produces this:
1552
1553 @smallexample
1554 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1555 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1556 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1557 @end smallexample
1558
1559 @node extracting files
1560 @subsection Extracting Specific Files
1561
1562 To extract specific archive members, give their exact member names as
1563 arguments, as printed by @option{--list} (@option{-t}). If you had
1564 mistakenly deleted one of the files you had placed in the archive
1565 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1566 from the archive without changing the archive's structure. Its
1567 contents will be identical to the original file @file{blues} that you
1568 deleted.
1569
1570 First, make sure you are in the @file{practice} directory, and list the
1571 files in the directory. Now, delete the file, @samp{blues}, and list
1572 the files in the directory again.
1573
1574 You can now extract the member @file{blues} from the archive file
1575 @file{collection.tar} like this:
1576
1577 @smallexample
1578 $ @kbd{tar --extract --file=collection.tar blues}
1579 @end smallexample
1580
1581 @noindent
1582 If you list the files in the directory again, you will see that the file
1583 @file{blues} has been restored, with its original permissions, data
1584 modification times, and owner.@footnote{This is only accidentally
1585 true, but not in general. Whereas modification times are always
1586 restored, in most cases, one has to be root for restoring the owner,
1587 and use a special option for restoring permissions. Here, it just
1588 happens that the restoring user is also the owner of the archived
1589 members, and that the current @code{umask} is compatible with original
1590 permissions.} (These parameters will be identical to those which
1591 the file had when you originally placed it in the archive; any changes
1592 you may have made before deleting the file from the file system,
1593 however, will @emph{not} have been made to the archive member.) The
1594 archive file, @samp{collection.tar}, is the same as it was before you
1595 extracted @samp{blues}. You can confirm this by running @command{tar} with
1596 @option{--list} (@option{-t}).
1597
1598 Remember that as with other operations, specifying the exact member
1599 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1600 will fail, because there is no member named @file{birds}. To extract
1601 the member named @file{./birds}, you must specify @w{@kbd{tar
1602 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1603 exact member names, use @option{--list} (@option{-t}) option
1604 (@pxref{list}). You can also extract those members that match a
1605 specific @dfn{globbing pattern}. For example, to extract from
1606 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1607 directory prefix, you could type:
1608
1609 @smallexample
1610 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1611 @end smallexample
1612
1613 @noindent
1614 Here, @option{--wildcards} instructs @command{tar} to treat
1615 command line arguments as globbing patterns and @option{--no-anchored}
1616 informs it that the patterns apply to member names after any @samp{/}
1617 delimiter. The use of globbing patterns is discussed in detail in
1618 @xref{wildcards}.
1619
1620 You can extract a file to standard output by combining the above options
1621 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1622 Output}).
1623
1624 If you give the @option{--verbose} option, then @option{--extract}
1625 will print the names of the archive members as it extracts them.
1626
1627 @node extract dir
1628 @subsection Extracting Files that are Directories
1629
1630 Extracting directories which are members of an archive is similar to
1631 extracting other files. The main difference to be aware of is that if
1632 the extracted directory has the same name as any directory already in
1633 the working directory, then files in the extracted directory will be
1634 placed into the directory of the same name. Likewise, if there are
1635 files in the pre-existing directory with the same names as the members
1636 which you extract, the files from the extracted archive will replace
1637 the files already in the working directory (and possible
1638 subdirectories). This will happen regardless of whether or not the
1639 files in the working directory were more recent than those extracted
1640 (there exist, however, special options that alter this behavior
1641 @pxref{Writing}).
1642
1643 However, if a file was stored with a directory name as part of its file
1644 name, and that directory does not exist under the working directory when
1645 the file is extracted, @command{tar} will create the directory.
1646
1647 We can demonstrate how to use @option{--extract} to extract a directory
1648 file with an example. Change to the @file{practice} directory if you
1649 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1650 go back to the parent directory and extract the archive
1651 @file{music.tar}. You may either extract the entire archive, or you may
1652 extract only the files you just deleted. To extract the entire archive,
1653 don't give any file names as arguments after the archive name
1654 @file{music.tar}. To extract only the files you deleted, use the
1655 following command:
1656
1657 @smallexample
1658 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1659 practice/folk
1660 practice/jazz
1661 @end smallexample
1662
1663 @noindent
1664 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1665 would have displayed more detail about the extracted files, as shown
1666 in the example below:
1667
1668 @smallexample
1669 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1670 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1671 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1672 @end smallexample
1673
1674 @noindent
1675 Because you created the directory with @file{practice} as part of the
1676 file names of each of the files by archiving the @file{practice}
1677 directory as @file{practice}, you must give @file{practice} as part
1678 of the file names when you extract those files from the archive.
1679
1680 @node extracting untrusted archives
1681 @subsection Extracting Archives from Untrusted Sources
1682
1683 Extracting files from archives can overwrite files that already exist.
1684 If you receive an archive from an untrusted source, you should make a
1685 new directory and extract into that directory, so that you don't have
1686 to worry about the extraction overwriting one of your existing files.
1687 For example, if @file{untrusted.tar} came from somewhere else on the
1688 Internet, and you don't necessarily trust its contents, you can
1689 extract it as follows:
1690
1691 @smallexample
1692 $ @kbd{mkdir newdir}
1693 $ @kbd{cd newdir}
1694 $ @kbd{tar -xvf ../untrusted.tar}
1695 @end smallexample
1696
1697 It is also a good practice to examine contents of the archive
1698 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1699 with @option{--verbose} (@option{-v}).
1700
1701 @node failing commands
1702 @subsection Commands That Will Fail
1703
1704 Here are some sample commands you might try which will not work, and why
1705 they won't work.
1706
1707 If you try to use this command,
1708
1709 @smallexample
1710 $ @kbd{tar -xvf music.tar folk jazz}
1711 @end smallexample
1712
1713 @noindent
1714 you will get the following response:
1715
1716 @smallexample
1717 tar: folk: Not found in archive
1718 tar: jazz: Not found in archive
1719 $
1720 @end smallexample
1721
1722 @noindent
1723 This is because these files were not originally @emph{in} the parent
1724 directory @file{..}, where the archive is located; they were in the
1725 @file{practice} directory, and their file names reflect this:
1726
1727 @smallexample
1728 $ @kbd{tar -tvf music.tar}
1729 practice/folk
1730 practice/jazz
1731 practice/rock
1732 @end smallexample
1733
1734 @FIXME{make sure the above works when going through the examples in
1735 order...}
1736
1737 @noindent
1738 Likewise, if you try to use this command,
1739
1740 @smallexample
1741 $ @kbd{tar -tvf music.tar folk jazz}
1742 @end smallexample
1743
1744 @noindent
1745 you would get a similar response. Members with those names are not in the
1746 archive. You must use the correct member names, or wildcards, in order
1747 to extract the files from the archive.
1748
1749 If you have forgotten the correct names of the files in the archive,
1750 use @w{@kbd{tar --list --verbose}} to list them correctly.
1751
1752 @FIXME{more examples, here? hag thinks it's a good idea.}
1753
1754 @node going further
1755 @section Going Further Ahead in this Manual
1756
1757 @FIXME{need to write up a node here about the things that are going to
1758 be in the rest of the manual.}
1759
1760 @node tar invocation
1761 @chapter Invoking @GNUTAR{}
1762 @UNREVISED
1763
1764 This chapter is about how one invokes the @GNUTAR{}
1765 command, from the command synopsis (@pxref{Synopsis}). There are
1766 numerous options, and many styles for writing them. One mandatory
1767 option specifies the operation @command{tar} should perform
1768 (@pxref{Operation Summary}), other options are meant to detail how
1769 this operation should be performed (@pxref{Option Summary}).
1770 Non-option arguments are not always interpreted the same way,
1771 depending on what the operation is.
1772
1773 You will find in this chapter everything about option styles and rules for
1774 writing them (@pxref{Styles}). On the other hand, operations and options
1775 are fully described elsewhere, in other chapters. Here, you will find
1776 only synthetic descriptions for operations and options, together with
1777 pointers to other parts of the @command{tar} manual.
1778
1779 Some options are so special they are fully described right in this
1780 chapter. They have the effect of inhibiting the normal operation of
1781 @command{tar} or else, they globally alter the amount of feedback the user
1782 receives about what is going on. These are the @option{--help} and
1783 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1784 and @option{--interactive} options (@pxref{interactive}).
1785
1786 @menu
1787 * Synopsis::
1788 * using tar options::
1789 * Styles::
1790 * All Options::
1791 * help::
1792 * defaults::
1793 * verbose::
1794 * interactive::
1795 @end menu
1796
1797 @node Synopsis
1798 @section General Synopsis of @command{tar}
1799
1800 The @GNUTAR{} program is invoked as either one of:
1801
1802 @smallexample
1803 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1804 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1805 @end smallexample
1806
1807 The second form is for when old options are being used.
1808
1809 You can use @command{tar} to store files in an archive, to extract them from
1810 an archive, and to do other types of archive manipulation. The primary
1811 argument to @command{tar}, which is called the @dfn{operation}, specifies
1812 which action to take. The other arguments to @command{tar} are either
1813 @dfn{options}, which change the way @command{tar} performs an operation,
1814 or file names or archive members, which specify the files or members
1815 @command{tar} is to act on.
1816
1817 You can actually type in arguments in any order, even if in this manual
1818 the options always precede the other arguments, to make examples easier
1819 to understand. Further, the option stating the main operation mode
1820 (the @command{tar} main command) is usually given first.
1821
1822 Each @var{name} in the synopsis above is interpreted as an archive member
1823 name when the main command is one of @option{--compare}
1824 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1825 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1826 @option{--update} (@option{-u}). When naming archive members, you
1827 must give the exact name of the member in the archive, as it is
1828 printed by @option{--list}. For @option{--append} (@option{-r}) and
1829 @option{--create} (@option{-c}), these @var{name} arguments specify
1830 the names of either files or directory hierarchies to place in the archive.
1831 These files or hierarchies should already exist in the file system,
1832 prior to the execution of the @command{tar} command.
1833
1834 @command{tar} interprets relative file names as being relative to the
1835 working directory. @command{tar} will make all file names relative
1836 (by removing leading slashes when archiving or restoring files),
1837 unless you specify otherwise (using the @option{--absolute-names}
1838 option). @xref{absolute}, for more information about
1839 @option{--absolute-names}.
1840
1841 If you give the name of a directory as either a file name or a member
1842 name, then @command{tar} acts recursively on all the files and directories
1843 beneath that directory. For example, the name @file{/} identifies all
1844 the files in the file system to @command{tar}.
1845
1846 The distinction between file names and archive member names is especially
1847 important when shell globbing is used, and sometimes a source of confusion
1848 for newcomers. @xref{wildcards}, for more information about globbing.
1849 The problem is that shells may only glob using existing files in the
1850 file system. Only @command{tar} itself may glob on archive members, so when
1851 needed, you must ensure that wildcard characters reach @command{tar} without
1852 being interpreted by the shell first. Using a backslash before @samp{*}
1853 or @samp{?}, or putting the whole argument between quotes, is usually
1854 sufficient for this.
1855
1856 Even if @var{name}s are often specified on the command line, they
1857 can also be read from a text file in the file system, using the
1858 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1859
1860 If you don't use any file name arguments, @option{--append} (@option{-r}),
1861 @option{--delete} and @option{--concatenate} (@option{--catenate},
1862 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1863 will usually yield a diagnostic and inhibit @command{tar} execution.
1864 The other operations of @command{tar} (@option{--list},
1865 @option{--extract}, @option{--compare}, and @option{--update})
1866 will act on the entire contents of the archive.
1867
1868 @cindex exit status
1869 @cindex return status
1870 Besides successful exits, @GNUTAR{} may fail for
1871 many reasons. Some reasons correspond to bad usage, that is, when the
1872 @command{tar} command is improperly written. Errors may be
1873 encountered later, while encountering an error processing the archive
1874 or the files. Some errors are recoverable, in which case the failure
1875 is delayed until @command{tar} has completed all its work. Some
1876 errors are such that it would not meaningful, or at least risky, to
1877 continue processing: @command{tar} then aborts processing immediately.
1878 All abnormal exits, whether immediate or delayed, should always be
1879 clearly diagnosed on @code{stderr}, after a line stating the nature of
1880 the error.
1881
1882 @GNUTAR{} returns only a few exit statuses. I'm really
1883 aiming simplicity in that area, for now. If you are not using the
1884 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1885 that everything went well, besides maybe innocuous warnings. Nonzero
1886 means that something went wrong. Right now, as of today, ``nonzero''
1887 is almost always 2, except for remote operations, where it may be
1888 128.
1889
1890 @node using tar options
1891 @section Using @command{tar} Options
1892
1893 @GNUTAR{} has a total of eight operating modes which
1894 allow you to perform a variety of tasks. You are required to choose
1895 one operating mode each time you employ the @command{tar} program by
1896 specifying one, and only one operation as an argument to the
1897 @command{tar} command (two lists of four operations each may be found
1898 at @ref{frequent operations} and @ref{Operations}). Depending on
1899 circumstances, you may also wish to customize how the chosen operating
1900 mode behaves. For example, you may wish to change the way the output
1901 looks, or the format of the files that you wish to archive may require
1902 you to do something special in order to make the archive look right.
1903
1904 You can customize and control @command{tar}'s performance by running
1905 @command{tar} with one or more options (such as @option{--verbose}
1906 (@option{-v}), which we used in the tutorial). As we said in the
1907 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1908 their name suggests) optional. Depending on the operating mode, you
1909 may specify one or more options. Different options will have different
1910 effects, but in general they all change details of the operation, such
1911 as archive format, archive name, or level of user interaction. Some
1912 options make sense with all operating modes, while others are
1913 meaningful only with particular modes. You will likely use some
1914 options frequently, while you will only use others infrequently, or
1915 not at all. (A full list of options is available in @pxref{All Options}.)
1916
1917 @vrindex TAR_OPTIONS, environment variable
1918 @anchor{TAR_OPTIONS}
1919 The @env{TAR_OPTIONS} environment variable specifies default options to
1920 be placed in front of any explicit options. For example, if
1921 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1922 if the two options @option{-v} and @option{--unlink-first} had been
1923 specified before any explicit options. Option specifications are
1924 separated by whitespace. A backslash escapes the next character, so it
1925 can be used to specify an option containing whitespace or a backslash.
1926
1927 Note that @command{tar} options are case sensitive. For example, the
1928 options @option{-T} and @option{-t} are different; the first requires an
1929 argument for stating the name of a file providing a list of @var{name}s,
1930 while the second does not require an argument and is another way to
1931 write @option{--list} (@option{-t}).
1932
1933 In addition to the eight operations, there are many options to
1934 @command{tar}, and three different styles for writing both: long (mnemonic)
1935 form, short form, and old style. These styles are discussed below.
1936 Both the options and the operations can be written in any of these three
1937 styles.
1938
1939 @FIXME{menu at end of this node. need to think of an actual outline
1940 for this chapter; probably do that after stuff from chapter 4 is
1941 incorporated.}
1942
1943 @node Styles
1944 @section The Three Option Styles
1945
1946 There are three styles for writing operations and options to the command
1947 line invoking @command{tar}. The different styles were developed at
1948 different times during the history of @command{tar}. These styles will be
1949 presented below, from the most recent to the oldest.
1950
1951 Some options must take an argument. (For example, @option{--file}
1952 (@option{-f})) takes the name of an archive file as an argument. If
1953 you do not supply an archive file name, @command{tar} will use a
1954 default, but this can be confusing; thus, we recommend that you always
1955 supply a specific archive file name.) Where you @emph{place} the
1956 arguments generally depends on which style of options you choose. We
1957 will detail specific information relevant to each option style in the
1958 sections on the different option styles, below. The differences are
1959 subtle, yet can often be very important; incorrect option placement
1960 can cause you to overwrite a number of important files. We urge you
1961 to note these differences, and only use the option style(s) which
1962 makes the most sense to you until you feel comfortable with the others.
1963
1964 Some options @emph{may} take an argument (currently, there are
1965 two such options: @option{--backup} and @option{--occurrence}). Such
1966 options may have at most long and short forms, they do not have old style
1967 equivalent. The rules for specifying an argument for such options
1968 are stricter than those for specifying mandatory arguments. Please,
1969 pay special attention to them.
1970
1971 @menu
1972 * Long Options:: Long Option Style
1973 * Short Options:: Short Option Style
1974 * Old Options:: Old Option Style
1975 * Mixing:: Mixing Option Styles
1976 @end menu
1977
1978 @node Long Options
1979 @subsection Long Option Style
1980
1981 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
1982 dashes in a row, e.g., @option{--list}. The long names are more clear than
1983 their corresponding short or old names. It sometimes happens that a
1984 single long option has many different different names which are
1985 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1986 long option names can be given unique abbreviations. For example,
1987 @option{--cre} can be used in place of @option{--create} because there is no
1988 other long option which begins with @samp{cre}. (One way to find
1989 this out is by trying it and seeing what happens; if a particular
1990 abbreviation could represent more than one option, @command{tar} will tell
1991 you that that abbreviation is ambiguous and you'll know that that
1992 abbreviation won't work. You may also choose to run @samp{tar --help}
1993 to see a list of options. Be aware that if you run @command{tar} with a
1994 unique abbreviation for the long name of an option you didn't want to
1995 use, you are stuck; @command{tar} will perform the command as ordered.)
1996
1997 Long options are meant to be obvious and easy to remember, and their
1998 meanings are generally easier to discern than those of their
1999 corresponding short options (see below). For example:
2000
2001 @smallexample
2002 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2003 @end smallexample
2004
2005 @noindent
2006 gives a fairly good set of hints about what the command does, even
2007 for those not fully acquainted with @command{tar}.
2008
2009 Long options which require arguments take those arguments
2010 immediately following the option name. There are two ways of
2011 specifying a mandatory argument. It can be separated from the
2012 option name either by an equal sign, or by any amount of
2013 white space characters. For example, the @option{--file} option (which
2014 tells the name of the @command{tar} archive) is given a file such as
2015 @file{archive.tar} as argument by using any of the following notations:
2016 @option{--file=archive.tar} or @option{--file archive.tar}.
2017
2018 In contrast, optional arguments must always be introduced using
2019 an equal sign. For example, the @option{--backup} option takes
2020 an optional argument specifying backup type. It must be used
2021 as @option{--backup=@var{backup-type}}.
2022
2023 @node Short Options
2024 @subsection Short Option Style
2025
2026 Most options also have a @dfn{short option} name. Short options start with
2027 a single dash, and are followed by a single character, e.g., @option{-t}
2028 (which is equivalent to @option{--list}). The forms are absolutely
2029 identical in function; they are interchangeable.
2030
2031 The short option names are faster to type than long option names.
2032
2033 Short options which require arguments take their arguments immediately
2034 following the option, usually separated by white space. It is also
2035 possible to stick the argument right after the short option name, using
2036 no intervening space. For example, you might write @w{@option{-f
2037 archive.tar}} or @option{-farchive.tar} instead of using
2038 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2039 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2040 specific archive, here named @file{archive.tar}.
2041
2042 Short options which take optional arguments take their arguments
2043 immediately following the option letter, @emph{without any intervening
2044 white space characters}.
2045
2046 Short options' letters may be clumped together, but you are not
2047 required to do this (as compared to old options; see below). When
2048 short options are clumped as a set, use one (single) dash for them
2049 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2050 such a set is allowed to have an argument@footnote{Clustering many
2051 options, the last of which has an argument, is a rather opaque way to
2052 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2053 even be made helpful enough for considering such usages as invalid.}.
2054
2055 When the options are separated, the argument for each option which requires
2056 an argument directly follows that option, as is usual for Unix programs.
2057 For example:
2058
2059 @smallexample
2060 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2061 @end smallexample
2062
2063 If you reorder short options' locations, be sure to move any arguments
2064 that belong to them. If you do not move the arguments properly, you may
2065 end up overwriting files.
2066
2067 @node Old Options
2068 @subsection Old Option Style
2069 @UNREVISED
2070
2071 Like short options, @dfn{old options} are single letters. However, old options
2072 must be written together as a single clumped set, without spaces separating
2073 them or dashes preceding them@footnote{Beware that if you precede options
2074 with a dash, you are announcing the short option style instead of the
2075 old option style; short options are decoded differently.}. This set
2076 of letters must be the first to appear on the command line, after the
2077 @command{tar} program name and some white space; old options cannot appear
2078 anywhere else. The letter of an old option is exactly the same letter as
2079 the corresponding short option. For example, the old option @samp{t} is
2080 the same as the short option @option{-t}, and consequently, the same as the
2081 long option @option{--list}. So for example, the command @w{@samp{tar
2082 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2083
2084 When options that need arguments are given together with the command,
2085 all the associated arguments follow, in the same order as the options.
2086 Thus, the example given previously could also be written in the old
2087 style as follows:
2088
2089 @smallexample
2090 $ @kbd{tar cvbf 20 /dev/rmt0}
2091 @end smallexample
2092
2093 @noindent
2094 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2095 the argument of @option{-f}.
2096
2097 On the other hand, this old style syntax makes it difficult to match
2098 option letters with their corresponding arguments, and is often
2099 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2100 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2101 argument for @option{-f}, and @option{-v} does not have a corresponding
2102 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2103 /dev/rmt0}} is clearer, putting all arguments next to the option they
2104 pertain to.
2105
2106 If you want to reorder the letters in the old option argument, be
2107 sure to reorder any corresponding argument appropriately.
2108
2109 This old way of writing @command{tar} options can surprise even experienced
2110 users. For example, the two commands:
2111
2112 @smallexample
2113 @kbd{tar cfz archive.tar.gz file}
2114 @kbd{tar -cfz archive.tar.gz file}
2115 @end smallexample
2116
2117 @noindent
2118 are quite different. The first example uses @file{archive.tar.gz} as
2119 the value for option @samp{f} and recognizes the option @samp{z}. The
2120 second example, however, uses @file{z} as the value for option
2121 @samp{f} --- probably not what was intended.
2122
2123 Old options are kept for compatibility with old versions of @command{tar}.
2124
2125 This second example could be corrected in many ways, among which the
2126 following are equivalent:
2127
2128 @smallexample
2129 @kbd{tar -czf archive.tar.gz file}
2130 @kbd{tar -cf archive.tar.gz -z file}
2131 @kbd{tar cf archive.tar.gz -z file}
2132 @end smallexample
2133
2134 @cindex option syntax, traditional
2135 As far as we know, all @command{tar} programs, @acronym{GNU} and
2136 non-@acronym{GNU}, support old options. @GNUTAR{}
2137 supports them not only for historical reasons, but also because many
2138 people are used to them. For compatibility with Unix @command{tar},
2139 the first argument is always treated as containing command and option
2140 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2141 equivalent to @w{@samp{tar -c}:} both of them specify the
2142 @option{--create} (@option{-c}) command to create an archive.
2143
2144 @node Mixing
2145 @subsection Mixing Option Styles
2146
2147 All three styles may be intermixed in a single @command{tar} command,
2148 so long as the rules for each style are fully
2149 respected@footnote{Before @GNUTAR{} version 1.11.6,
2150 a bug prevented intermixing old style options with long options in
2151 some cases.}. Old style options and either of the modern styles of
2152 options may be mixed within a single @command{tar} command. However,
2153 old style options must be introduced as the first arguments only,
2154 following the rule for old options (old options must appear directly
2155 after the @command{tar} command and some white space). Modern options
2156 may be given only after all arguments to the old options have been
2157 collected. If this rule is not respected, a modern option might be
2158 falsely interpreted as the value of the argument to one of the old
2159 style options.
2160
2161 For example, all the following commands are wholly equivalent, and
2162 illustrate the many combinations and orderings of option styles.
2163
2164 @smallexample
2165 @kbd{tar --create --file=archive.tar}
2166 @kbd{tar --create -f archive.tar}
2167 @kbd{tar --create -farchive.tar}
2168 @kbd{tar --file=archive.tar --create}
2169 @kbd{tar --file=archive.tar -c}
2170 @kbd{tar -c --file=archive.tar}
2171 @kbd{tar -c -f archive.tar}
2172 @kbd{tar -c -farchive.tar}
2173 @kbd{tar -cf archive.tar}
2174 @kbd{tar -cfarchive.tar}
2175 @kbd{tar -f archive.tar --create}
2176 @kbd{tar -f archive.tar -c}
2177 @kbd{tar -farchive.tar --create}
2178 @kbd{tar -farchive.tar -c}
2179 @kbd{tar c --file=archive.tar}
2180 @kbd{tar c -f archive.tar}
2181 @kbd{tar c -farchive.tar}
2182 @kbd{tar cf archive.tar}
2183 @kbd{tar f archive.tar --create}
2184 @kbd{tar f archive.tar -c}
2185 @kbd{tar fc archive.tar}
2186 @end smallexample
2187
2188 On the other hand, the following commands are @emph{not} equivalent to
2189 the previous set:
2190
2191 @smallexample
2192 @kbd{tar -f -c archive.tar}
2193 @kbd{tar -fc archive.tar}
2194 @kbd{tar -fcarchive.tar}
2195 @kbd{tar -farchive.tarc}
2196 @kbd{tar cfarchive.tar}
2197 @end smallexample
2198
2199 @noindent
2200 These last examples mean something completely different from what the
2201 user intended (judging based on the example in the previous set which
2202 uses long options, whose intent is therefore very clear). The first
2203 four specify that the @command{tar} archive would be a file named
2204 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2205 respectively. The first two examples also specify a single non-option,
2206 @var{name} argument having the value @samp{archive.tar}. The last
2207 example contains only old style option letters (repeating option
2208 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2209 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2210 the first sentence of this paragraph..}
2211
2212 @node All Options
2213 @section All @command{tar} Options
2214
2215 The coming manual sections contain an alphabetical listing of all
2216 @command{tar} operations and options, with brief descriptions and cross
2217 references to more in-depth explanations in the body of the manual.
2218 They also contain an alphabetically arranged table of the short option
2219 forms with their corresponding long option. You can use this table as
2220 a reference for deciphering @command{tar} commands in scripts.
2221
2222 @menu
2223 * Operation Summary::
2224 * Option Summary::
2225 * Short Option Summary::
2226 @end menu
2227
2228 @node Operation Summary
2229 @subsection Operations
2230
2231 @table @option
2232
2233 @opsummary{append}
2234 @item --append
2235 @itemx -r
2236
2237 Appends files to the end of the archive. @xref{append}.
2238
2239 @opsummary{catenate}
2240 @item --catenate
2241 @itemx -A
2242
2243 Same as @option{--concatenate}. @xref{concatenate}.
2244
2245 @opsummary{compare}
2246 @item --compare
2247 @itemx -d
2248
2249 Compares archive members with their counterparts in the file
2250 system, and reports differences in file size, mode, owner,
2251 modification date and contents. @xref{compare}.
2252
2253 @opsummary{concatenate}
2254 @item --concatenate
2255 @itemx -A
2256
2257 Appends other @command{tar} archives to the end of the archive.
2258 @xref{concatenate}.
2259
2260 @opsummary{create}
2261 @item --create
2262 @itemx -c
2263
2264 Creates a new @command{tar} archive. @xref{create}.
2265
2266 @opsummary{delete}
2267 @item --delete
2268
2269 Deletes members from the archive. Don't try this on a archive on a
2270 tape! @xref{delete}.
2271
2272 @opsummary{diff}
2273 @item --diff
2274 @itemx -d
2275
2276 Same @option{--compare}. @xref{compare}.
2277
2278 @opsummary{extract}
2279 @item --extract
2280 @itemx -x
2281
2282 Extracts members from the archive into the file system. @xref{extract}.
2283
2284 @opsummary{get}
2285 @item --get
2286 @itemx -x
2287
2288 Same as @option{--extract}. @xref{extract}.
2289
2290 @opsummary{list}
2291 @item --list
2292 @itemx -t
2293
2294 Lists the members in an archive. @xref{list}.
2295
2296 @opsummary{update}
2297 @item --update
2298 @itemx -u
2299
2300 Adds files to the end of the archive, but only if they are newer than
2301 their counterparts already in the archive, or if they do not already
2302 exist in the archive. @xref{update}.
2303
2304 @end table
2305
2306 @node Option Summary
2307 @subsection @command{tar} Options
2308
2309 @table @option
2310
2311 @opsummary{absolute-names}
2312 @item --absolute-names
2313 @itemx -P
2314
2315 Normally when creating an archive, @command{tar} strips an initial
2316 @samp{/} from member names. This option disables that behavior.
2317 @xref{absolute}.
2318
2319 @opsummary{after-date}
2320 @item --after-date
2321
2322 (See @option{--newer}, @pxref{after})
2323
2324 @opsummary{anchored}
2325 @item --anchored
2326 A pattern must match an initial subsequence of the name's components.
2327 @xref{controlling pattern-matching}.
2328
2329 @opsummary{atime-preserve}
2330 @item --atime-preserve
2331 @itemx --atime-preserve=replace
2332 @itemx --atime-preserve=system
2333
2334 Attempt to preserve the access time of files when reading them. This
2335 option currently is effective only on files that you own, unless you
2336 have superuser privileges.
2337
2338 @option{--atime-preserve=replace} remembers the access time of a file
2339 before reading it, and then restores the access time afterwards. This
2340 may cause problems if other programs are reading the file at the same
2341 time, as the times of their accesses will be lost. On most platforms
2342 restoring the access time also requires @command{tar} to restore the
2343 data modification time too, so this option may also cause problems if
2344 other programs are writing the file at the same time. (Tar attempts
2345 to detect this situation, but cannot do so reliably due to race
2346 conditions.) Worse, on most platforms restoring the access time also
2347 updates the status change time, which means that this option is
2348 incompatible with incremental backups.
2349
2350 @option{--atime-preserve=system} avoids changing time stamps on files,
2351 without interfering with time stamp updates
2352 caused by other programs, so it works better with incremental backups.
2353 However, it requires a special @code{O_NOATIME} option from the
2354 underlying operating and file system implementation, and it also requires
2355 that searching directories does not update their access times. As of
2356 this writing (November 2005) this works only with Linux, and only with
2357 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2358 way to know whether this feature actually works. Sometimes
2359 @command{tar} knows that it does not work, and if you use
2360 @option{--atime-preserve=system} then @command{tar} complains and
2361 exits right away. But other times @command{tar} might think that the
2362 option works when it actually does not.
2363
2364 Currently @option{--atime-preserve} with no operand defaults to
2365 @option{--atime-preserve=replace}, but this may change in the future
2366 as support for @option{--atime-preserve=system} improves.
2367
2368 If your operating system does not support
2369 @option{--atime-preserve=@-system}, you might be able to preserve access
2370 times reliably by by using the @command{mount} command. For example,
2371 you can mount the file system read-only, or access the file system via
2372 a read-only loopback mount, or use the @samp{noatime} mount option
2373 available on some systems. However, mounting typically requires
2374 superuser privileges and can be a pain to manage.
2375
2376 @opsummary{backup}
2377 @item --backup=@var{backup-type}
2378
2379 Rather than deleting files from the file system, @command{tar} will
2380 back them up using simple or numbered backups, depending upon
2381 @var{backup-type}. @xref{backup}.
2382
2383 @opsummary{block-number}
2384 @item --block-number
2385 @itemx -R
2386
2387 With this option present, @command{tar} prints error messages for read errors
2388 with the block number in the archive file. @xref{block-number}.
2389
2390 @opsummary{blocking-factor}
2391 @item --blocking-factor=@var{blocking}
2392 @itemx -b @var{blocking}
2393
2394 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2395 record. @xref{Blocking Factor}.
2396
2397 @opsummary{bzip2}
2398 @item --bzip2
2399 @itemx -j
2400
2401 This option tells @command{tar} to read or write archives through
2402 @code{bzip2}. @xref{gzip}.
2403
2404 @opsummary{checkpoint}
2405 @item --checkpoint[=@var{number}]
2406
2407 This option directs @command{tar} to print periodic checkpoint
2408 messages as it reads through the archive. It is intended for when you
2409 want a visual indication that @command{tar} is still running, but
2410 don't want to see @option{--verbose} output. For a detailed
2411 description, see @ref{Progress information}.
2412
2413 @opsummary{check-links}
2414 @item --check-links
2415 @itemx -l
2416 If this option was given, @command{tar} will check the number of links
2417 dumped for each processed file. If this number does not match the
2418 total number of hard links for the file, a warning message will be
2419 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2420 synonym for @option{--one-file-system}. The current semantics, which
2421 complies to UNIX98, was introduced with version
2422 1.15.91. @xref{Changes}, for more information.}.
2423
2424 @opsummary{compress}
2425 @opsummary{uncompress}
2426 @item --compress
2427 @itemx --uncompress
2428 @itemx -Z
2429
2430 @command{tar} will use the @command{compress} program when reading or
2431 writing the archive. This allows you to directly act on archives
2432 while saving space. @xref{gzip}.
2433
2434 @opsummary{confirmation}
2435 @item --confirmation
2436
2437 (See @option{--interactive}.) @xref{interactive}.
2438
2439 @opsummary{delay-directory-restore}
2440 @item --delay-directory-restore
2441
2442 Delay setting modification times and permissions of extracted
2443 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2444
2445 @opsummary{dereference}
2446 @item --dereference
2447 @itemx -h
2448
2449 When creating a @command{tar} archive, @command{tar} will archive the
2450 file that a symbolic link points to, rather than archiving the
2451 symlink. @xref{dereference}.
2452
2453 @opsummary{directory}
2454 @item --directory=@var{dir}
2455 @itemx -C @var{dir}
2456
2457 When this option is specified, @command{tar} will change its current directory
2458 to @var{dir} before performing any operations. When this option is used
2459 during archive creation, it is order sensitive. @xref{directory}.
2460
2461 @opsummary{exclude}
2462 @item --exclude=@var{pattern}
2463
2464 When performing operations, @command{tar} will skip files that match
2465 @var{pattern}. @xref{exclude}.
2466
2467 @opsummary{exclude-from}
2468 @item --exclude-from=@var{file}
2469 @itemx -X @var{file}
2470
2471 Similar to @option{--exclude}, except @command{tar} will use the list of
2472 patterns in the file @var{file}. @xref{exclude}.
2473
2474 @opsummary{exclude-caches}
2475 @item --exclude-caches
2476
2477 Automatically excludes all directories
2478 containing a cache directory tag. @xref{exclude}.
2479
2480 @opsummary{file}
2481 @item --file=@var{archive}
2482 @itemx -f @var{archive}
2483
2484 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2485 performs operations on, rather than @command{tar}'s compilation dependent
2486 default. @xref{file tutorial}.
2487
2488 @opsummary{files-from}
2489 @item --files-from=@var{file}
2490 @itemx -T @var{file}
2491
2492 @command{tar} will use the contents of @var{file} as a list of archive members
2493 or files to operate on, in addition to those specified on the
2494 command-line. @xref{files}.
2495
2496 @opsummary{force-local}
2497 @item --force-local
2498
2499 Forces @command{tar} to interpret the filename given to @option{--file}
2500 as a local file, even if it looks like a remote tape drive name.
2501 @xref{local and remote archives}.
2502
2503 @opsummary{format}
2504 @item --format=@var{format}
2505 @itemx -H @var{format}
2506
2507 Selects output archive format. @var{Format} may be one of the
2508 following:
2509
2510 @table @samp
2511 @item v7
2512 Creates an archive that is compatible with Unix V7 @command{tar}.
2513
2514 @item oldgnu
2515 Creates an archive that is compatible with GNU @command{tar} version
2516 1.12 or earlier.
2517
2518 @item gnu
2519 Creates archive in GNU tar 1.13 format. Basically it is the same as
2520 @samp{oldgnu} with the only difference in the way it handles long
2521 numeric fields.
2522
2523 @item ustar
2524 Creates a @acronym{POSIX.1-1988} compatible archive.
2525
2526 @item posix
2527 Creates a @acronym{POSIX.1-2001 archive}.
2528
2529 @end table
2530
2531 @xref{Formats}, for a detailed discussion of these formats.
2532
2533 @opsummary{group}
2534 @item --group=@var{group}
2535
2536 Files added to the @command{tar} archive will have a group id of @var{group},
2537 rather than the group from the source file. @var{group} is first decoded
2538 as a group symbolic name, but if this interpretation fails, it has to be
2539 a decimal numeric group ID. @FIXME-xref{}
2540
2541 Also see the comments for the @option{--owner=@var{user}} option.
2542
2543 @opsummary{gzip}
2544 @opsummary{gunzip}
2545 @opsummary{ungzip}
2546 @item --gzip
2547 @itemx --gunzip
2548 @itemx --ungzip
2549 @itemx -z
2550
2551 This option tells @command{tar} to read or write archives through
2552 @command{gzip}, allowing @command{tar} to directly operate on several
2553 kinds of compressed archives transparently. @xref{gzip}.
2554
2555 @opsummary{help}
2556 @item --help
2557 @itemx -?
2558
2559 @command{tar} will print out a short message summarizing the operations and
2560 options to @command{tar} and exit. @xref{help}.
2561
2562 @opsummary{ignore-case}
2563 @item --ignore-case
2564 Ignore case when matching member or file names with
2565 patterns. @xref{controlling pattern-matching}.
2566
2567 @opsummary{ignore-command-error}
2568 @item --ignore-command-error
2569 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2570
2571 @opsummary{ignore-failed-read}
2572 @item --ignore-failed-read
2573
2574 Do not exit unsuccessfully merely because an unreadable file was encountered.
2575 @xref{Reading}.
2576
2577 @opsummary{ignore-zeros}
2578 @item --ignore-zeros
2579 @itemx -i
2580
2581 With this option, @command{tar} will ignore zeroed blocks in the
2582 archive, which normally signals EOF. @xref{Reading}.
2583
2584 @opsummary{incremental}
2585 @item --incremental
2586 @itemx -G
2587
2588 Used to inform @command{tar} that it is working with an old
2589 @acronym{GNU}-format incremental backup archive. It is intended
2590 primarily for backwards compatibility only. @xref{Incremental Dumps},
2591 for a detailed discussion of incremental archives.
2592
2593 @opsummary{index-file}
2594 @item --index-file=@var{file}
2595
2596 Send verbose output to @var{file} instead of to standard output.
2597
2598 @opsummary{info-script}
2599 @opsummary{new-volume-script}
2600 @item --info-script=@var{script-file}
2601 @itemx --new-volume-script=@var{script-file}
2602 @itemx -F @var{script-file}
2603
2604 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2605 at the end of each tape. If @var{script-file} exits with nonzero status,
2606 @command{tar} fails immediately. @xref{info-script}, for a detailed
2607 discussion of @var{script-file}.
2608
2609 @opsummary{interactive}
2610 @item --interactive
2611 @itemx --confirmation
2612 @itemx -w
2613
2614 Specifies that @command{tar} should ask the user for confirmation before
2615 performing potentially destructive options, such as overwriting files.
2616 @xref{interactive}.
2617
2618 @opsummary{keep-newer-files}
2619 @item --keep-newer-files
2620
2621 Do not replace existing files that are newer than their archive copies
2622 when extracting files from an archive.
2623
2624 @opsummary{keep-old-files}
2625 @item --keep-old-files
2626 @itemx -k
2627
2628 Do not overwrite existing files when extracting files from an archive.
2629 @xref{Keep Old Files}.
2630
2631 @opsummary{label}
2632 @item --label=@var{name}
2633 @itemx -V @var{name}
2634
2635 When creating an archive, instructs @command{tar} to write @var{name}
2636 as a name record in the archive. When extracting or listing archives,
2637 @command{tar} will only operate on archives that have a label matching
2638 the pattern specified in @var{name}. @xref{Tape Files}.
2639
2640 @opsummary{listed-incremental}
2641 @item --listed-incremental=@var{snapshot-file}
2642 @itemx -g @var{snapshot-file}
2643
2644 During a @option{--create} operation, specifies that the archive that
2645 @command{tar} creates is a new @acronym{GNU}-format incremental
2646 backup, using @var{snapshot-file} to determine which files to backup.
2647 With other operations, informs @command{tar} that the archive is in
2648 incremental format. @xref{Incremental Dumps}.
2649
2650 @opsummary{mode}
2651 @item --mode=@var{permissions}
2652
2653 When adding files to an archive, @command{tar} will use
2654 @var{permissions} for the archive members, rather than the permissions
2655 from the files. The program @command{chmod} and this @command{tar}
2656 option share the same syntax for what @var{permissions} might be.
2657 @xref{File permissions, Permissions, File permissions, fileutils,
2658 @acronym{GNU} file utilities}. This reference also has useful
2659 information for those not being overly familiar with the Unix
2660 permission system.
2661
2662 Of course, @var{permissions} might be plainly specified as an octal number.
2663 However, by using generic symbolic modifications to mode bits, this allows
2664 more flexibility. For example, the value @samp{a+rw} adds read and write
2665 permissions for everybody, while retaining executable bits on directories
2666 or on any other file already marked as executable.
2667
2668 @opsummary{multi-volume}
2669 @item --multi-volume
2670 @itemx -M
2671
2672 Informs @command{tar} that it should create or otherwise operate on a
2673 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2674
2675 @opsummary{new-volume-script}
2676 @item --new-volume-script
2677
2678 (see --info-script)
2679
2680 @opsummary{seek}
2681 @item --seek
2682 @itemx -n
2683
2684 Assume that the archive media supports seeks to arbitrary
2685 locations. Usually @command{tar} determines automatically whether
2686 the archive can be seeked or not. This option is intended for use
2687 in cases when such recognition fails.
2688
2689 @opsummary{newer}
2690 @item --newer=@var{date}
2691 @itemx --after-date=@var{date}
2692 @itemx -N
2693
2694 When creating an archive, @command{tar} will only add files that have changed
2695 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2696 is taken to be the name of a file whose data modification time specifies
2697 the date. @xref{after}.
2698
2699 @opsummary{newer-mtime}
2700 @item --newer-mtime=@var{date}
2701
2702 Like @option{--newer}, but add only files whose
2703 contents have changed (as opposed to just @option{--newer}, which will
2704 also back up files for which any status information has changed).
2705
2706 @opsummary{no-anchored}
2707 @item --no-anchored
2708 An exclude pattern can match any subsequence of the name's components.
2709 @xref{controlling pattern-matching}.
2710
2711 @opsummary{no-delay-directory-restore}
2712 @item --no-delay-directory-restore
2713
2714 Setting modification times and permissions of extracted
2715 directories when all files from this directory has been
2716 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2717
2718 @opsummary{no-ignore-case}
2719 @item --no-ignore-case
2720 Use case-sensitive matching.
2721 @xref{controlling pattern-matching}.
2722
2723 @opsummary{no-ignore-command-error}
2724 @item --no-ignore-command-error
2725 Print warnings about subprocesses terminated with a non-zero exit
2726 code. @xref{Writing to an External Program}.
2727
2728 @opsummary{no-overwrite-dir}
2729 @item --no-overwrite-dir
2730
2731 Preserve metadata of existing directories when extracting files
2732 from an archive. @xref{Overwrite Old Files}.
2733
2734 @opsummary{no-quote-chars}
2735 @item --no-quote-chars=@var{string}
2736 Remove characters listed in @var{string} from the list of quoted
2737 characters set by the previous @option{--quote-chars} option
2738 (@pxref{quoting styles}).
2739
2740 @opsummary{no-recursion}
2741 @item --no-recursion
2742
2743 With this option, @command{tar} will not recurse into directories.
2744 @xref{recurse}.
2745
2746 @opsummary{no-same-owner}
2747 @item --no-same-owner
2748 @itemx -o
2749
2750 When extracting an archive, do not attempt to preserve the owner
2751 specified in the @command{tar} archive. This the default behavior
2752 for ordinary users.
2753
2754 @opsummary{no-same-permissions}
2755 @item --no-same-permissions
2756
2757 When extracting an archive, subtract the user's umask from files from
2758 the permissions specified in the archive. This is the default behavior
2759 for ordinary users.
2760
2761 @opsummary{no-unquote}
2762 @item --no-unquote
2763 Treat all input file or member names literally, do not interpret
2764 escape sequences. @xref{input name quoting}.
2765
2766 @opsummary{no-wildcards}
2767 @item --no-wildcards
2768 Do not use wildcards.
2769 @xref{controlling pattern-matching}.
2770
2771 @opsummary{no-wildcards-match-slash}
2772 @item --no-wildcards-match-slash
2773 Wildcards do not match @samp{/}.
2774 @xref{controlling pattern-matching}.
2775
2776 @opsummary{null}
2777 @item --null
2778
2779 When @command{tar} is using the @option{--files-from} option, this option
2780 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2781 @command{tar} can correctly work with file names that contain newlines.
2782 @xref{nul}.
2783
2784 @opsummary{numeric-owner}
2785 @item --numeric-owner
2786
2787 This option will notify @command{tar} that it should use numeric user
2788 and group IDs when creating a @command{tar} file, rather than names.
2789 @xref{Attributes}.
2790
2791 @item -o
2792 When extracting files, this option is a synonym for
2793 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2794 restoring ownership of files being extracted.
2795
2796 When creating an archive, @option{-o} is a synonym for
2797 @option{--old-archive}. This behavior is for compatibility
2798 with previous versions of @GNUTAR{}, and will be
2799 removed in the future releases.
2800
2801 @xref{Changes}, for more information.
2802
2803 @opsummary{occurrence}
2804 @item --occurrence[=@var{number}]
2805
2806 This option can be used in conjunction with one of the subcommands
2807 @option{--delete}, @option{--diff}, @option{--extract} or
2808 @option{--list} when a list of files is given either on the command
2809 line or via @option{-T} option.
2810
2811 This option instructs @command{tar} to process only the @var{number}th
2812 occurrence of each named file. @var{Number} defaults to 1, so
2813
2814 @smallexample
2815 tar -x -f archive.tar --occurrence filename
2816 @end smallexample
2817
2818 @noindent
2819 will extract the first occurrence of @file{filename} from @file{archive.tar}
2820 and will terminate without scanning to the end of the archive.
2821
2822 @opsummary{old-archive}
2823 @item --old-archive
2824 Synonym for @option{--format=v7}.
2825
2826 @opsummary{one-file-system}
2827 @item --one-file-system
2828 Used when creating an archive. Prevents @command{tar} from recursing into
2829 directories that are on different file systems from the current
2830 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2831 synonym for @option{--one-file-system}. This has changed in version
2832 1.15.91. @xref{Changes}, for more information.}.
2833
2834 @opsummary{overwrite}
2835 @item --overwrite
2836
2837 Overwrite existing files and directory metadata when extracting files
2838 from an archive. @xref{Overwrite Old Files}.
2839
2840 @opsummary{overwrite-dir}
2841 @item --overwrite-dir
2842
2843 Overwrite the metadata of existing directories when extracting files
2844 from an archive. @xref{Overwrite Old Files}.
2845
2846 @opsummary{owner}
2847 @item --owner=@var{user}
2848
2849 Specifies that @command{tar} should use @var{user} as the owner of members
2850 when creating archives, instead of the user associated with the source
2851 file. @var{user} is first decoded as a user symbolic name, but if
2852 this interpretation fails, it has to be a decimal numeric user ID.
2853 @FIXME-xref{}
2854
2855 There is no value indicating a missing number, and @samp{0} usually means
2856 @code{root}. Some people like to force @samp{0} as the value to offer in
2857 their distributions for the owner of files, because the @code{root} user is
2858 anonymous anyway, so that might as well be the owner of anonymous archives.
2859
2860 This option does not affect extraction from archives.
2861
2862 @opsummary{transform}
2863 @item --transform=@var{sed-expr}
2864
2865 Transform file or member names using @command{sed} replacement expression
2866 @var{sed-expr}. For example,
2867
2868 @smallexample
2869 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2870 @end smallexample
2871
2872 @noindent
2873 will add to @file{archive} files from the current working directory,
2874 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2875 discussion, @xref{transform}.
2876
2877 To see transformed member names in verbose listings, use
2878 @option{--show-transformed-names} option
2879 (@pxref{show-transformed-names}).
2880
2881 @opsummary{quote-chars}
2882 @item --quote-chars=@var{string}
2883 Always quote characters from @var{string}, even if the selected
2884 quoting style would not quote them (@pxref{quoting styles}).
2885
2886 @opsummary{quoting-style}
2887 @item --quoting-style=@var{style}
2888 Set quoting style to use when printing member and file names
2889 (@pxref{quoting styles}). Valid @var{style} values are:
2890 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2891 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2892 style is @code{escape}, unless overridden while configuring the
2893 package.
2894
2895 @opsummary{pax-option}
2896 @item --pax-option=@var{keyword-list}
2897 This option is meaningful only with @acronym{POSIX.1-2001} archives
2898 (@pxref{posix}). It modifies the way @command{tar} handles the
2899 extended header keywords. @var{Keyword-list} is a comma-separated
2900 list of keyword options. @xref{PAX keywords}, for a detailed
2901 discussion.
2902
2903 @opsummary{portability}
2904 @item --portability
2905 @itemx --old-archive
2906 Synonym for @option{--format=v7}.
2907
2908 @opsummary{posix}
2909 @item --posix
2910 Same as @option{--format=posix}.
2911
2912 @opsummary{preserve}
2913 @item --preserve
2914
2915 Synonymous with specifying both @option{--preserve-permissions} and
2916 @option{--same-order}. @xref{Setting Access Permissions}.
2917
2918 @opsummary{preserve-order}
2919 @item --preserve-order
2920
2921 (See @option{--same-order}; @pxref{Reading}.)
2922
2923 @opsummary{preserve-permissions}
2924 @opsummary{same-permissions}
2925 @item --preserve-permissions
2926 @itemx --same-permissions
2927 @itemx -p
2928
2929 When @command{tar} is extracting an archive, it normally subtracts the
2930 users' umask from the permissions specified in the archive and uses
2931 that number as the permissions to create the destination file.
2932 Specifying this option instructs @command{tar} that it should use the
2933 permissions directly from the archive. @xref{Setting Access Permissions}.
2934
2935 @opsummary{read-full-records}
2936 @item --read-full-records
2937 @itemx -B
2938
2939 Specifies that @command{tar} should reblock its input, for reading
2940 from pipes on systems with buggy implementations. @xref{Reading}.
2941
2942 @opsummary{record-size}
2943 @item --record-size=@var{size}
2944
2945 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2946 archive. @xref{Blocking Factor}.
2947
2948 @opsummary{recursion}
2949 @item --recursion
2950
2951 With this option, @command{tar} recurses into directories.
2952 @xref{recurse}.
2953
2954 @opsummary{recursive-unlink}
2955 @item --recursive-unlink
2956
2957 Remove existing
2958 directory hierarchies before extracting directories of the same name
2959 from the archive. @xref{Recursive Unlink}.
2960
2961 @opsummary{remove-files}
2962 @item --remove-files
2963
2964 Directs @command{tar} to remove the source file from the file system after
2965 appending it to an archive. @xref{remove files}.
2966
2967 @opsummary{restrict}
2968 @item --restrict
2969
2970 Disable use of some potentially harmful @command{tar} options.
2971 Currently this option disables shell invocaton from multi-volume menu
2972 (@pxref{Using Multiple Tapes}).
2973
2974 @opsummary{rmt-command}
2975 @item --rmt-command=@var{cmd}
2976
2977 Notifies @command{tar} that it should use @var{cmd} instead of
2978 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2979
2980 @opsummary{rsh-command}
2981 @item --rsh-command=@var{cmd}
2982
2983 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2984 devices. @xref{Device}.
2985
2986 @opsummary{same-order}
2987 @item --same-order
2988 @itemx --preserve-order
2989 @itemx -s
2990
2991 This option is an optimization for @command{tar} when running on machines with
2992 small amounts of memory. It informs @command{tar} that the list of file
2993 arguments has already been sorted to match the order of files in the
2994 archive. @xref{Reading}.
2995
2996 @opsummary{same-owner}
2997 @item --same-owner
2998
2999 When extracting an archive, @command{tar} will attempt to preserve the owner
3000 specified in the @command{tar} archive with this option present.
3001 This is the default behavior for the superuser; this option has an
3002 effect only for ordinary users. @xref{Attributes}.
3003
3004 @opsummary{same-permissions}
3005 @item --same-permissions
3006
3007 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3008
3009 @opsummary{show-defaults}
3010 @item --show-defaults
3011
3012 Displays the default options used by @command{tar} and exits
3013 successfully. This option is intended for use in shell scripts.
3014 Here is an example of what you can see using this option:
3015
3016 @smallexample
3017 $ tar --show-defaults
3018 --format=gnu -f- -b20 --quoting-style=escape \
3019 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3020 @end smallexample
3021
3022 @opsummary{show-omitted-dirs}
3023 @item --show-omitted-dirs
3024
3025 Instructs @command{tar} to mention directories its skipping over when
3026 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3027
3028 @opsummary{show-transformed-names}
3029 @opsummary{show-stored-names}
3030 @item --show-transformed-names
3031 @itemx --show-stored-names
3032
3033 Display file or member names after applying any transformations
3034 (@pxref{transform}). In particular, when used in conjunction with one of
3035 archive creation operations it instructs tar to list the member names
3036 stored in the archive, as opposed to the actual file
3037 names. @xref{listing member and file names}.
3038
3039 @opsummary{sparse}
3040 @item --sparse
3041 @itemx -S
3042
3043 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3044 sparse files efficiently. @xref{sparse}.
3045
3046 @opsummary{starting-file}
3047 @item --starting-file=@var{name}
3048 @itemx -K @var{name}
3049
3050 This option affects extraction only; @command{tar} will skip extracting
3051 files in the archive until it finds one that matches @var{name}.
3052 @xref{Scarce}.
3053
3054 @opsummary{strip-components}
3055 @item --strip-components=@var{number}
3056 Strip given @var{number} of leading components from file names before
3057 extraction.@footnote{This option was called @option{--strip-path} in
3058 version 1.14.} For example, if archive @file{archive.tar} contained
3059 @file{/some/file/name}, then running
3060
3061 @smallexample
3062 tar --extract --file archive.tar --strip-components=2
3063 @end smallexample
3064
3065 @noindent
3066 would extract this file to file @file{name}.
3067
3068 @opsummary{suffix}, summary
3069 @item --suffix=@var{suffix}
3070
3071 Alters the suffix @command{tar} uses when backing up files from the default
3072 @samp{~}. @xref{backup}.
3073
3074 @opsummary{tape-length}
3075 @item --tape-length=@var{num}
3076 @itemx -L @var{num}
3077
3078 Specifies the length of tapes that @command{tar} is writing as being
3079 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3080
3081 @opsummary{test-label}
3082 @item --test-label
3083
3084 Reads the volume label. If an argument is specified, test whether it
3085 matches the volume label. @xref{--test-label option}.
3086
3087 @opsummary{to-command}
3088 @item --to-command=@var{command}
3089
3090 During extraction @command{tar} will pipe extracted files to the
3091 standard input of @var{command}. @xref{Writing to an External Program}.
3092
3093 @opsummary{to-stdout}
3094 @item --to-stdout
3095 @itemx -O
3096
3097 During extraction, @command{tar} will extract files to stdout rather
3098 than to the file system. @xref{Writing to Standard Output}.
3099
3100 @opsummary{totals}
3101 @item --totals[=@var{signo}]
3102
3103 Displays the total number of bytes transferred when processing an
3104 archive. If an argument is given, these data are displayed on
3105 request, when signal @var{signo} is delivered to @command{tar}.
3106 @xref{totals}.
3107
3108 @opsummary{touch}
3109 @item --touch
3110 @itemx -m
3111
3112 Sets the data modification time of extracted files to the extraction time,
3113 rather than the data modification time stored in the archive.
3114 @xref{Data Modification Times}.
3115
3116 @opsummary{uncompress}
3117 @item --uncompress
3118
3119 (See @option{--compress}. @pxref{gzip})
3120
3121 @opsummary{ungzip}
3122 @item --ungzip
3123
3124 (See @option{--gzip}. @pxref{gzip})
3125
3126 @opsummary{unlink-first}
3127 @item --unlink-first
3128 @itemx -U
3129
3130 Directs @command{tar} to remove the corresponding file from the file
3131 system before extracting it from the archive. @xref{Unlink First}.
3132
3133 @opsummary{unquote}
3134 @item --unquote
3135 Enable unquoting input file or member names (default). @xref{input
3136 name quoting}.
3137
3138 @opsummary{use-compress-program}
3139 @item --use-compress-program=@var{prog}
3140
3141 Instructs @command{tar} to access the archive through @var{prog}, which is
3142 presumed to be a compression program of some sort. @xref{gzip}.
3143
3144 @opsummary{utc}
3145 @item --utc
3146
3147 Display file modification dates in @acronym{UTC}. This option implies
3148 @option{--verbose}.
3149
3150 @opsummary{verbose}
3151 @item --verbose
3152 @itemx -v
3153
3154 Specifies that @command{tar} should be more verbose about the operations its
3155 performing. This option can be specified multiple times for some
3156 operations to increase the amount of information displayed.
3157 @xref{verbose}.
3158
3159 @opsummary{verify}
3160 @item --verify
3161 @itemx -W
3162
3163 Verifies that the archive was correctly written when creating an
3164 archive. @xref{verify}.
3165
3166 @opsummary{version}
3167 @item --version
3168
3169 Print information about the program's name, version, origin and legal
3170 status, all on standard output, and then exit successfully.
3171 @xref{help}.
3172
3173 @opsummary{volno-file}
3174 @item --volno-file=@var{file}
3175
3176 Used in conjunction with @option{--multi-volume}. @command{tar} will
3177 keep track of which volume of a multi-volume archive its working in
3178 @var{file}. @xref{volno-file}.
3179
3180 @opsummary{wildcards}
3181 @item --wildcards
3182 Use wildcards when matching member names with patterns.
3183 @xref{controlling pattern-matching}.
3184
3185 @opsummary{wildcards-match-slash}
3186 @item --wildcards-match-slash
3187 Wildcards match @samp{/}.
3188 @xref{controlling pattern-matching}.
3189 @end table
3190
3191 @node Short Option Summary
3192 @subsection Short Options Cross Reference
3193
3194 Here is an alphabetized list of all of the short option forms, matching
3195 them with the equivalent long option.
3196
3197 @multitable @columnfractions 0.20 0.80
3198 @headitem Short Option @tab Reference
3199
3200 @item -A @tab @ref{--concatenate}.
3201
3202 @item -B @tab @ref{--read-full-records}.
3203
3204 @item -C @tab @ref{--directory}.
3205
3206 @item -F @tab @ref{--info-script}.
3207
3208 @item -G @tab @ref{--incremental}.
3209
3210 @item -K @tab @ref{--starting-file}.
3211
3212 @item -L @tab @ref{--tape-length}.
3213
3214 @item -M @tab @ref{--multi-volume}.
3215
3216 @item -N @tab @ref{--newer}.
3217
3218 @item -O @tab @ref{--to-stdout}.
3219
3220 @item -P @tab @ref{--absolute-names}.
3221
3222 @item -R @tab @ref{--block-number}.
3223
3224 @item -S @tab @ref{--sparse}.
3225
3226 @item -T @tab @ref{--files-from}.
3227
3228 @item -U @tab @ref{--unlink-first}.
3229
3230 @item -V @tab @ref{--label}.
3231
3232 @item -W @tab @ref{--verify}.
3233
3234 @item -X @tab @ref{--exclude-from}.
3235
3236 @item -Z @tab @ref{--compress}.
3237
3238 @item -b @tab @ref{--blocking-factor}.
3239
3240 @item -c @tab @ref{--create}.
3241
3242 @item -d @tab @ref{--compare}.
3243
3244 @item -f @tab @ref{--file}.
3245
3246 @item -g @tab @ref{--listed-incremental}.
3247
3248 @item -h @tab @ref{--dereference}.
3249
3250 @item -i @tab @ref{--ignore-zeros}.
3251
3252 @item -j @tab @ref{--bzip2}.
3253
3254 @item -k @tab @ref{--keep-old-files}.
3255
3256 @item -l @tab @ref{--check-links}.
3257
3258 @item -m @tab @ref{--touch}.
3259
3260 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3261 @ref{--portability}.
3262
3263 The later usage is deprecated. It is retained for compatibility with
3264 the earlier versions of @GNUTAR{}. In the future releases
3265 @option{-o} will be equivalent to @option{--no-same-owner} only.
3266
3267 @item -p @tab @ref{--preserve-permissions}.
3268
3269 @item -r @tab @ref{--append}.
3270
3271 @item -s @tab @ref{--same-order}.
3272
3273 @item -t @tab @ref{--list}.
3274
3275 @item -u @tab @ref{--update}.
3276
3277 @item -v @tab @ref{--verbose}.
3278
3279 @item -w @tab @ref{--interactive}.
3280
3281 @item -x @tab @ref{--extract}.
3282
3283 @item -z @tab @ref{--gzip}.
3284
3285 @end multitable
3286
3287 @node help
3288 @section @GNUTAR{} documentation
3289
3290 @cindex Getting program version number
3291 @opindex version
3292 @cindex Version of the @command{tar} program
3293 Being careful, the first thing is really checking that you are using
3294 @GNUTAR{}, indeed. The @option{--version} option
3295 causes @command{tar} to print information about its name, version,
3296 origin and legal status, all on standard output, and then exit
3297 successfully. For example, @w{@samp{tar --version}} might print:
3298
3299 @smallexample
3300 tar (GNU tar) @value{VERSION}
3301 Copyright (C) 2006 Free Software Foundation, Inc.
3302 This is free software. You may redistribute copies of it under the terms of
3303 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3304 There is NO WARRANTY, to the extent permitted by law.
3305
3306 Written by John Gilmore and Jay Fenlason.
3307 @end smallexample
3308
3309 @noindent
3310 The first occurrence of @samp{tar} in the result above is the program
3311 name in the package (for example, @command{rmt} is another program),
3312 while the second occurrence of @samp{tar} is the name of the package
3313 itself, containing possibly many programs. The package is currently
3314 named @samp{tar}, after the name of the main program it
3315 contains@footnote{There are plans to merge the @command{cpio} and
3316 @command{tar} packages into a single one which would be called
3317 @code{paxutils}. So, who knows if, one of this days, the
3318 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3319 paxutils) 3.2}}}.
3320
3321 @cindex Obtaining help
3322 @cindex Listing all @command{tar} options
3323 @xopindex{help, introduction}
3324 Another thing you might want to do is checking the spelling or meaning
3325 of some particular @command{tar} option, without resorting to this
3326 manual, for once you have carefully read it. @GNUTAR{}
3327 has a short help feature, triggerable through the
3328 @option{--help} option. By using this option, @command{tar} will
3329 print a usage message listing all available options on standard
3330 output, then exit successfully, without doing anything else and
3331 ignoring all other options. Even if this is only a brief summary, it
3332 may be several screens long. So, if you are not using some kind of
3333 scrollable window, you might prefer to use something like:
3334
3335 @smallexample
3336 $ @kbd{tar --help | less}
3337 @end smallexample
3338
3339 @noindent
3340 presuming, here, that you like using @command{less} for a pager. Other
3341 popular pagers are @command{more} and @command{pg}. If you know about some
3342 @var{keyword} which interests you and do not want to read all the
3343 @option{--help} output, another common idiom is doing:
3344
3345 @smallexample
3346 tar --help | grep @var{keyword}
3347 @end smallexample
3348
3349 @noindent
3350 for getting only the pertinent lines. Notice, however, that some
3351 @command{tar} options have long description lines and the above
3352 command will list only the first of them.
3353
3354 The exact look of the option summary displayed by @kbd{tar --help} is
3355 configurable. @xref{Configuring Help Summary}, for a detailed description.
3356
3357 @opindex usage
3358 If you only wish to check the spelling of an option, running @kbd{tar
3359 --usage} may be a better choice. This will display a terse list of
3360 @command{tar} option without accompanying explanations.
3361
3362 The short help output is quite succinct, and you might have to get
3363 back to the full documentation for precise points. If you are reading
3364 this paragraph, you already have the @command{tar} manual in some
3365 form. This manual is available in a variety of forms from
3366 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3367 distribution, provided you have @TeX{} already installed somewhere,
3368 and a laser printer around. Just configure the distribution, execute
3369 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3370 usual way (contact your local guru to know how). If @GNUTAR{}
3371 has been conveniently installed at your place, this
3372 manual is also available in interactive, hypertextual form as an Info
3373 file. Just call @w{@samp{info tar}} or, if you do not have the
3374 @command{info} program handy, use the Info reader provided within
3375 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3376
3377 There is currently no @code{man} page for @GNUTAR{}.
3378 If you observe such a @code{man} page on the system you are running,
3379 either it does not belong to @GNUTAR{}, or it has not
3380 been produced by @acronym{GNU}. Some package maintainers convert
3381 @kbd{tar --help} output to a man page, using @command{help2man}. In
3382 any case, please bear in mind that the authoritative source of
3383 information about @GNUTAR{} is this Texinfo documentation.
3384
3385 @node defaults
3386 @section Obtaining @GNUTAR{} default values
3387
3388 @opindex show-defaults
3389 @GNUTAR{} has some predefined defaults that are used when you do not
3390 explicitely specify another values. To obtain a list of such
3391 defaults, use @option{--show-defaults} option. This will output the
3392 values in the form of @command{tar} command line options:
3393
3394 @smallexample
3395 @group
3396 @kbd{tar --show-defaults}
3397 --format=gnu -f- -b20 --quoting-style=escape
3398 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3399 @end group
3400 @end smallexample
3401
3402 @noindent
3403 Notice, that this option outputs only one line. The example output above
3404 has been split to fit page boundaries.
3405
3406 @noindent
3407 The above output shows that this version of @GNUTAR{} defaults to
3408 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3409 output as the archive, if no @option{--file} option has been given
3410 (@pxref{file tutorial}), the default blocking factor is 20
3411 (@pxref{Blocking Factor}). It also shows the default locations where
3412 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3413
3414 @node verbose
3415 @section Checking @command{tar} progress
3416
3417 Typically, @command{tar} performs most operations without reporting any
3418 information to the user except error messages. When using @command{tar}
3419 with many options, particularly ones with complicated or
3420 difficult-to-predict behavior, it is possible to make serious mistakes.
3421 @command{tar} provides several options that make observing @command{tar}
3422 easier. These options cause @command{tar} to print information as it
3423 progresses in its job, and you might want to use them just for being
3424 more careful about what is going on, or merely for entertaining
3425 yourself. If you have encountered a problem when operating on an
3426 archive, however, you may need more information than just an error
3427 message in order to solve the problem. The following options can be
3428 helpful diagnostic tools.
3429
3430 @cindex Verbose operation
3431 @opindex verbose
3432 Normally, the @option{--list} (@option{-t}) command to list an archive
3433 prints just the file names (one per line) and the other commands are
3434 silent. When used with most operations, the @option{--verbose}
3435 (@option{-v}) option causes @command{tar} to print the name of each
3436 file or archive member as it is processed. This and the other options
3437 which make @command{tar} print status information can be useful in
3438 monitoring @command{tar}.
3439
3440 With @option{--create} or @option{--extract}, @option{--verbose} used
3441 once just prints the names of the files or members as they are processed.
3442 Using it twice causes @command{tar} to print a longer listing
3443 (@xref{verbose member listing}, for the description) for each member.
3444 Since @option{--list} already prints the names of the members,
3445 @option{--verbose} used once with @option{--list} causes @command{tar}
3446 to print an @samp{ls -l} type listing of the files in the archive.
3447 The following examples both extract members with long list output:
3448
3449 @smallexample
3450 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3451 $ @kbd{tar xvvf archive.tar}
3452 @end smallexample
3453
3454 Verbose output appears on the standard output except when an archive is
3455 being written to the standard output, as with @samp{tar --create
3456 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3457 installer let standard output be the default archive). In that case
3458 @command{tar} writes verbose output to the standard error stream.
3459
3460 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3461 verbose output to @var{file} rather than to standard output or standard
3462 error.
3463
3464 @anchor{totals}
3465 @cindex Obtaining total status information
3466 @opindex totals
3467 The @option{--totals} option causes @command{tar} to print on the
3468 standard error the total amount of bytes transferred when processing
3469 an archive. When creating or appending to an archive, this option
3470 prints the number of bytes written to the archive and the average
3471 speed at which they have been written, e.g.:
3472
3473 @smallexample
3474 @group
3475 $ @kbd{tar -c -f archive.tar --totals /home}
3476 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3477 @end group
3478 @end smallexample
3479
3480 When reading an archive, this option displays the number of bytes
3481 read:
3482
3483 @smallexample
3484 @group
3485 $ @kbd{tar -x -f archive.tar --totals}
3486 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3487 @end group
3488 @end smallexample
3489
3490 Finally, when deleting from an archive, the @option{--totals} option
3491 displays both numbers plus number of bytes removed from the archive:
3492
3493 @smallexample
3494 @group
3495 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3496 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3497 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3498 Total bytes deleted: 1474048
3499 @end group
3500 @end smallexample
3501
3502 You can also obtain this information on request. When
3503 @option{--totals} is used with an argument, this argument is
3504 interpreted as a symbolic name of a signal, upon delivery of which the
3505 statistics is to be printed:
3506
3507 @table @option
3508 @item --totals=@var{signo}
3509 Print statistics upon delivery of signal @var{signo}. Valid arguments
3510 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3511 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3512 accepted.
3513 @end table
3514
3515 Both forms of @option{--totals} option can be used simultaneously.
3516 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3517 extract all members from its default archive and print statistics
3518 after finishing the extraction, as well as when receiving signal
3519 @code{SIGUSR1}.
3520
3521 @anchor{Progress information}
3522 @cindex Progress information
3523 @opindex checkpoint
3524 The @option{--checkpoint} option prints an occasional message
3525 as @command{tar} reads or writes the archive. It is designed for
3526 those who don't need the more detailed (and voluminous) output of
3527 @option{--block-number} (@option{-R}), but do want visual confirmation
3528 that @command{tar} is actually making forward progress. By default it
3529 prints a message each 10 records read or written. This can be changed
3530 by giving it a numeric argument after an equal sign:
3531
3532 @smallexample
3533 $ @kbd{tar -c --checkpoint=1000} /var
3534 tar: Write checkpoint 1000
3535 tar: Write checkpoint 2000
3536 tar: Write checkpoint 3000
3537 @end smallexample
3538
3539 This example shows the default checkpoint message used by
3540 @command{tar}. If you place a dot immediately after the equal
3541 sign, it will print a @samp{.} at each checkpoint. For example:
3542
3543 @smallexample
3544 $ @kbd{tar -c --checkpoint=.1000} /var
3545 ...
3546 @end smallexample
3547
3548 @opindex show-omitted-dirs
3549 @anchor{show-omitted-dirs}
3550 The @option{--show-omitted-dirs} option, when reading an archive---with
3551 @option{--list} or @option{--extract}, for example---causes a message
3552 to be printed for each directory in the archive which is skipped.
3553 This happens regardless of the reason for skipping: the directory might
3554 not have been named on the command line (implicitly or explicitly),
3555 it might be excluded by the use of the
3556 @option{--exclude=@var{pattern}} option, or some other reason.
3557
3558 @opindex block-number
3559 @cindex Block number where error occurred
3560 @anchor{block-number}
3561 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3562 every message it would normally produce, the block number within the
3563 archive where the message was triggered. Also, supplementary messages
3564 are triggered when reading blocks full of NULs, or when hitting end of
3565 file on the archive. As of now, if the archive if properly terminated
3566 with a NUL block, the reading of the file may stop before end of file
3567 is met, so the position of end of file will not usually show when
3568 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3569 drains the archive before exiting when reading the
3570 archive from a pipe.
3571
3572 @cindex Error message, block number of
3573 This option is especially useful when reading damaged archives, since
3574 it helps pinpoint the damaged sections. It can also be used with
3575 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3576 choose among several backup tapes when retrieving a file later, in
3577 favor of the tape where the file appears earliest (closest to the
3578 front of the tape). @xref{backup}.
3579
3580 @node interactive
3581 @section Asking for Confirmation During Operations
3582 @cindex Interactive operation
3583
3584 Typically, @command{tar} carries out a command without stopping for
3585 further instructions. In some situations however, you may want to
3586 exclude some files and archive members from the operation (for instance
3587 if disk or storage space is tight). You can do this by excluding
3588 certain files automatically (@pxref{Choosing}), or by performing
3589 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3590 @command{tar} also accepts @option{--confirmation} for this option.
3591
3592 @opindex interactive
3593 When the @option{--interactive} (@option{-w}) option is specified, before
3594 reading, writing, or deleting files, @command{tar} first prints a message
3595 for each such file, telling what operation it intends to take, then asks
3596 for confirmation on the terminal. The actions which require
3597 confirmation include adding a file to the archive, extracting a file
3598 from the archive, deleting a file from the archive, and deleting a file
3599 from disk. To confirm the action, you must type a line of input
3600 beginning with @samp{y}. If your input line begins with anything other
3601 than @samp{y}, @command{tar} skips that file.
3602
3603 If @command{tar} is reading the archive from the standard input,
3604 @command{tar} opens the file @file{/dev/tty} to support the interactive
3605 communications.
3606
3607 Verbose output is normally sent to standard output, separate from
3608 other error messages. However, if the archive is produced directly
3609 on standard output, then verbose output is mixed with errors on
3610 @code{stderr}. Producing the archive on standard output may be used
3611 as a way to avoid using disk space, when the archive is soon to be
3612 consumed by another process reading it, say. Some people felt the need
3613 of producing an archive on stdout, still willing to segregate between
3614 verbose output and error output. A possible approach would be using a
3615 named pipe to receive the archive, and having the consumer process to
3616 read from that named pipe. This has the advantage of letting standard
3617 output free to receive verbose output, all separate from errors.
3618
3619 @node operations
3620 @chapter @GNUTAR{} Operations
3621
3622 @menu
3623 * Basic tar::
3624 * Advanced tar::
3625 * create options::
3626 * extract options::
3627 * backup::
3628 * Applications::
3629 * looking ahead::
3630 @end menu
3631
3632 @node Basic tar
3633 @section Basic @GNUTAR{} Operations
3634
3635 The basic @command{tar} operations, @option{--create} (@option{-c}),
3636 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3637 @option{-x}), are currently presented and described in the tutorial
3638 chapter of this manual. This section provides some complementary notes
3639 for these operations.
3640
3641 @table @option
3642 @xopindex{create, complementary notes}
3643 @item --create
3644 @itemx -c
3645
3646 Creating an empty archive would have some kind of elegance. One can
3647 initialize an empty archive and later use @option{--append}
3648 (@option{-r}) for adding all members. Some applications would not
3649 welcome making an exception in the way of adding the first archive
3650 member. On the other hand, many people reported that it is
3651 dangerously too easy for @command{tar} to destroy a magnetic tape with
3652 an empty archive@footnote{This is well described in @cite{Unix-haters
3653 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3654 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3655
3656 @enumerate
3657 @item
3658 Mistakingly using @code{create} instead of @code{extract}, when the
3659 intent was to extract the full contents of an archive. This error
3660 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3661 the QWERTY keyboard. Instead of being unpacked, the archive then
3662 gets wholly destroyed. When users speak about @dfn{exploding} an
3663 archive, they usually mean something else :-).
3664
3665 @item
3666 Forgetting the argument to @code{file}, when the intent was to create
3667 an archive with a single file in it. This error is likely because a
3668 tired user can easily add the @kbd{f} key to the cluster of option
3669 letters, by the mere force of habit, without realizing the full
3670 consequence of doing so. The usual consequence is that the single
3671 file, which was meant to be saved, is rather destroyed.
3672 @end enumerate
3673
3674 So, recognizing the likelihood and the catastrophical nature of these
3675 errors, @GNUTAR{} now takes some distance from elegance, and
3676 cowardly refuses to create an archive when @option{--create} option is
3677 given, there are no arguments besides options, and
3678 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3679 around the cautiousness of @GNUTAR{} and nevertheless create an
3680 archive with nothing in it, one may still use, as the value for the
3681 @option{--files-from} option, a file with no names in it, as shown in
3682 the following commands:
3683
3684 @smallexample
3685 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3686 @kbd{tar cfT empty-archive.tar /dev/null}
3687 @end smallexample
3688
3689 @xopindex{extract, complementary notes}
3690 @item --extract
3691 @itemx --get
3692 @itemx -x
3693
3694 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3695
3696 @item @option{--list} (@option{-t})
3697
3698 @GNUTAR{} now shows dates as @samp{1996-08-30},
3699 while it used to show them as @samp{Aug 30 1996}. Preferably,
3700 people should get used to ISO 8601 dates. Local American dates should
3701 be made available again with full date localization support, once
3702 ready. In the meantime, programs not being localizable for dates
3703 should prefer international dates, that's really the way to go.
3704
3705 Look up @url{http://www.ft.uni-erlangen.de/@/~mskuhn/@/iso-time.html} if you
3706 are curious, it contains a detailed explanation of the ISO 8601 standard.
3707
3708 @end table
3709
3710 @node Advanced tar
3711 @section Advanced @GNUTAR{} Operations
3712
3713 Now that you have learned the basics of using @GNUTAR{}, you may want
3714 to learn about further ways in which @command{tar} can help you.
3715
3716 This chapter presents five, more advanced operations which you probably
3717 won't use on a daily basis, but which serve more specialized functions.
3718 We also explain the different styles of options and why you might want
3719 to use one or another, or a combination of them in your @command{tar}
3720 commands. Additionally, this chapter includes options which allow you to
3721 define the output from @command{tar} more carefully, and provide help and
3722 error correction in special circumstances.
3723
3724 @FIXME{check this after the chapter is actually revised to make sure
3725 it still introduces the info in the chapter correctly : ).}
3726
3727 @menu
3728 * Operations::
3729 * append::
3730 * update::
3731 * concatenate::
3732 * delete::
3733 * compare::
3734 @end menu
3735
3736 @node Operations
3737 @subsection The Five Advanced @command{tar} Operations
3738 @UNREVISED
3739
3740 In the last chapter, you learned about the first three operations to
3741 @command{tar}. This chapter presents the remaining five operations to
3742 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3743 @option{--delete}, and @option{--compare}.
3744
3745 You are not likely to use these operations as frequently as those
3746 covered in the last chapter; however, since they perform specialized
3747 functions, they are quite useful when you do need to use them. We
3748 will give examples using the same directory and files that you created
3749 in the last chapter. As you may recall, the directory is called
3750 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3751 @samp{rock}, and the two archive files you created are
3752 @samp{collection.tar} and @samp{music.tar}.
3753
3754 We will also use the archive files @samp{afiles.tar} and
3755 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3756 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3757 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3758
3759 Unless we state otherwise, all practicing you do and examples you follow
3760 in this chapter will take place in the @file{practice} directory that
3761 you created in the previous chapter; see @ref{prepare for examples}.
3762 (Below in this section, we will remind you of the state of the examples
3763 where the last chapter left them.)
3764
3765 The five operations that we will cover in this chapter are:
3766
3767 @table @option
3768 @item --append
3769 @itemx -r
3770 Add new entries to an archive that already exists.
3771 @item --update
3772 @itemx -r
3773 Add more recent copies of archive members to the end of an archive, if
3774 they exist.
3775 @item --concatenate
3776 @itemx --catenate
3777 @itemx -A
3778 Add one or more pre-existing archives to the end of another archive.
3779 @item --delete
3780 Delete items from an archive (does not work on tapes).
3781 @item --compare
3782 @itemx --diff
3783 @itemx -d
3784 Compare archive members to their counterparts in the file system.
3785 @end table
3786
3787 @node append
3788 @subsection How to Add Files to Existing Archives: @option{--append}
3789 @UNREVISED
3790
3791 @opindex append
3792 If you want to add files to an existing archive, you don't need to
3793 create a new archive; you can use @option{--append} (@option{-r}).
3794 The archive must already exist in order to use @option{--append}. (A
3795 related operation is the @option{--update} operation; you can use this
3796 to add newer versions of archive members to an existing archive. To learn how to
3797 do this with @option{--update}, @pxref{update}.)
3798
3799 If you use @option{--append} to add a file that has the same name as an
3800 archive member to an archive containing that archive member, then the
3801 old member is not deleted. What does happen, however, is somewhat
3802 complex. @command{tar} @emph{allows} you to have infinite number of files
3803 with the same name. Some operations treat these same-named members no
3804 differently than any other set of archive members: for example, if you
3805 view an archive with @option{--list} (@option{-t}), you will see all
3806 of those members listed, with their data modification times, owners, etc.
3807
3808 Other operations don't deal with these members as perfectly as you might
3809 prefer; if you were to use @option{--extract} to extract the archive,
3810 only the most recently added copy of a member with the same name as four
3811 other members would end up in the working directory. This is because
3812 @option{--extract} extracts an archive in the order the members appeared
3813 in the archive; the most recently archived members will be extracted
3814 last. Additionally, an extracted member will @emph{replace} a file of
3815 the same name which existed in the directory already, and @command{tar}
3816 will not prompt you about this@footnote{Unless you give it
3817 @option{--keep-old-files} option, or the disk copy is newer than the
3818 the one in the archive and you invoke @command{tar} with
3819 @option{--keep-newer-files} option}. Thus, only the most recently archived
3820 member will end up being extracted, as it will replace the one
3821 extracted before it, and so on.
3822
3823 There exists a special option that allows you to get around this
3824 behavior and extract (or list) only a particular copy of the file.
3825 This is @option{--occurrence} option. If you run @command{tar} with
3826 this option, it will extract only the first copy of the file. You
3827 may also give this option an argument specifying the number of
3828 copy to be extracted. Thus, for example if the archive
3829 @file{archive.tar} contained three copies of file @file{myfile}, then
3830 the command
3831
3832 @smallexample
3833 tar --extract --file archive.tar --occurrence=2 myfile
3834 @end smallexample
3835
3836 @noindent
3837 would extract only the second copy. @xref{Option
3838 Summary,---occurrence}, for the description of @option{--occurrence}
3839 option.
3840
3841 @FIXME{ hag -- you might want to incorporate some of the above into the
3842 MMwtSN node; not sure. i didn't know how to make it simpler...
3843
3844 There are a few ways to get around this. (maybe xref Multiple Members
3845 with the Same Name.}
3846
3847 @cindex Members, replacing with other members
3848 @cindex Replacing members with other members
3849 If you want to replace an archive member, use @option{--delete} to
3850 delete the member you want to remove from the archive, , and then use
3851 @option{--append} to add the member you want to be in the archive. Note
3852 that you can not change the order of the archive; the most recently
3853 added member will still appear last. In this sense, you cannot truly
3854 ``replace'' one member with another. (Replacing one member with another
3855 will not work on certain types of media, such as tapes; see @ref{delete}
3856 and @ref{Media}, for more information.)
3857
3858 @menu
3859 * appending files:: Appending Files to an Archive
3860 * multiple::
3861 @end menu
3862
3863 @node appending files
3864 @subsubsection Appending Files to an Archive
3865 @UNREVISED
3866 @cindex Adding files to an Archive
3867 @cindex Appending files to an Archive
3868 @cindex Archives, Appending files to
3869
3870 The simplest way to add a file to an already existing archive is the
3871 @option{--append} (@option{-r}) operation, which writes specified
3872 files into the archive whether or not they are already among the
3873 archived files.
3874
3875 When you use @option{--append}, you @emph{must} specify file name
3876 arguments, as there is no default. If you specify a file that already
3877 exists in the archive, another copy of the file will be added to the
3878 end of the archive. As with other operations, the member names of the
3879 newly added files will be exactly the same as their names given on the
3880 command line. The @option{--verbose} (@option{-v}) option will print
3881 out the names of the files as they are written into the archive.
3882
3883 @option{--append} cannot be performed on some tape drives, unfortunately,
3884 due to deficiencies in the formats those tape drives use. The archive
3885 must be a valid @command{tar} archive, or else the results of using this
3886 operation will be unpredictable. @xref{Media}.
3887
3888 To demonstrate using @option{--append} to add a file to an archive,
3889 create a file called @file{rock} in the @file{practice} directory.
3890 Make sure you are in the @file{practice} directory. Then, run the
3891 following @command{tar} command to add @file{rock} to
3892 @file{collection.tar}:
3893
3894 @smallexample
3895 $ @kbd{tar --append --file=collection.tar rock}
3896 @end smallexample
3897
3898 @noindent
3899 If you now use the @option{--list} (@option{-t}) operation, you will see that
3900 @file{rock} has been added to the archive:
3901
3902 @smallexample
3903 $ @kbd{tar --list --file=collection.tar}
3904 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3905 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3906 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3907 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3908 @end smallexample
3909
3910 @node multiple
3911 @subsubsection Multiple Members with the Same Name
3912
3913 You can use @option{--append} (@option{-r}) to add copies of files
3914 which have been updated since the archive was created. (However, we
3915 do not recommend doing this since there is another @command{tar}
3916 option called @option{--update}; @xref{update}, for more information.
3917 We describe this use of @option{--append} here for the sake of
3918 completeness.) When you extract the archive, the older version will
3919 be effectively lost. This works because files are extracted from an
3920 archive in the order in which they were archived. Thus, when the
3921 archive is extracted, a file archived later in time will replace a
3922 file of the same name which was archived earlier, even though the
3923 older version of the file will remain in the archive unless you delete
3924 all versions of the file.
3925
3926 Supposing you change the file @file{blues} and then append the changed
3927 version to @file{collection.tar}. As you saw above, the original
3928 @file{blues} is in the archive @file{collection.tar}. If you change the
3929 file and append the new version of the file to the archive, there will
3930 be two copies in the archive. When you extract the archive, the older
3931 version of the file will be extracted first, and then replaced by the
3932 newer version when it is extracted.
3933
3934 You can append the new, changed copy of the file @file{blues} to the
3935 archive in this way:
3936
3937 @smallexample
3938 $ @kbd{tar --append --verbose --file=collection.tar blues}
3939 blues
3940 @end smallexample
3941
3942 @noindent
3943 Because you specified the @option{--verbose} option, @command{tar} has
3944 printed the name of the file being appended as it was acted on. Now
3945 list the contents of the archive:
3946
3947 @smallexample
3948 $ @kbd{tar --list --verbose --file=collection.tar}
3949 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3950 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3951 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3952 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3953 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3954 @end smallexample
3955
3956 @noindent
3957 The newest version of @file{blues} is now at the end of the archive
3958 (note the different creation dates and file sizes). If you extract
3959 the archive, the older version of the file @file{blues} will be
3960 replaced by the newer version. You can confirm this by extracting
3961 the archive and running @samp{ls} on the directory.
3962
3963 If you wish to extract the first occurrence of the file @file{blues}
3964 from the archive, use @option{--occurrence} option, as shown in
3965 the following example:
3966
3967 @smallexample
3968 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3969 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3970 @end smallexample
3971
3972 @xref{Writing}, for more information on @option{--extract} and
3973 @xref{Option Summary, --occurrence}, for the description of
3974 @option{--occurrence} option.
3975
3976 @node update
3977 @subsection Updating an Archive
3978 @UNREVISED
3979 @cindex Updating an archive
3980
3981 @opindex update
3982 In the previous section, you learned how to use @option{--append} to
3983 add a file to an existing archive. A related operation is
3984 @option{--update} (@option{-u}). The @option{--update} operation
3985 updates a @command{tar} archive by comparing the date of the specified
3986 archive members against the date of the file with the same name. If
3987 the file has been modified more recently than the archive member, then
3988 the newer version of the file is added to the archive (as with
3989 @option{--append}).
3990
3991 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3992 The operation will fail.
3993
3994 @FIXME{other examples of media on which --update will fail? need to ask
3995 charles and/or mib/thomas/dave shevett..}
3996
3997 Both @option{--update} and @option{--append} work by adding to the end
3998 of the archive. When you extract a file from the archive, only the
3999 version stored last will wind up in the file system, unless you use
4000 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4001
4002 @menu
4003 * how to update::
4004 @end menu
4005
4006 @node how to update
4007 @subsubsection How to Update an Archive Using @option{--update}
4008
4009 You must use file name arguments with the @option{--update}
4010 (@option{-u}) operation. If you don't specify any files,
4011 @command{tar} won't act on any files and won't tell you that it didn't
4012 do anything (which may end up confusing you).
4013
4014 @c note: the above parenthetical added because in fact, this
4015 @c behavior just confused the author. :-)
4016
4017 To see the @option{--update} option at work, create a new file,
4018 @file{classical}, in your practice directory, and some extra text to the
4019 file @file{blues}, using any text editor. Then invoke @command{tar} with
4020 the @samp{update} operation and the @option{--verbose} (@option{-v})
4021 option specified, using the names of all the files in the practice
4022 directory as file name arguments:
4023
4024 @smallexample
4025 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4026 blues
4027 classical
4028 $
4029 @end smallexample
4030
4031 @noindent
4032 Because we have specified verbose mode, @command{tar} prints out the names
4033 of the files it is working on, which in this case are the names of the
4034 files that needed to be updated. If you run @samp{tar --list} and look
4035 at the archive, you will see @file{blues} and @file{classical} at its
4036 end. There will be a total of two versions of the member @samp{blues};
4037 the one at the end will be newer and larger, since you added text before
4038 updating it.
4039
4040 (The reason @command{tar} does not overwrite the older file when updating
4041 it is because writing to the middle of a section of tape is a difficult
4042 process. Tapes are not designed to go backward. @xref{Media}, for more
4043 information about tapes.
4044
4045 @option{--update} (@option{-u}) is not suitable for performing backups for two
4046 reasons: it does not change directory content entries, and it
4047 lengthens the archive every time it is used. The @GNUTAR{}
4048 options intended specifically for backups are more
4049 efficient. If you need to run backups, please consult @ref{Backups}.
4050
4051 @node concatenate
4052 @subsection Combining Archives with @option{--concatenate}
4053
4054 @cindex Adding archives to an archive
4055 @cindex Concatenating Archives
4056 @opindex concatenate
4057 @opindex catenate
4058 @c @cindex @option{-A} described
4059 Sometimes it may be convenient to add a second archive onto the end of
4060 an archive rather than adding individual files to the archive. To add
4061 one or more archives to the end of another archive, you should use the
4062 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4063
4064 To use @option{--concatenate}, give the first archive with
4065 @option{--file} option and name the rest of archives to be
4066 concatenated on the command line. The members, and their member
4067 names, will be copied verbatim from those archives to the first one.
4068 @footnote{This can cause multiple members to have the same name, for
4069 information on how this affects reading the archive, @ref{multiple}.}
4070 The new, concatenated archive will be called by the same name as the
4071 one given with the @option{--file} option. As usual, if you omit
4072 @option{--file}, @command{tar} will use the value of the environment
4073 variable @env{TAPE}, or, if this has not been set, the default archive name.
4074
4075 @FIXME{There is no way to specify a new name...}
4076
4077 To demonstrate how @option{--concatenate} works, create two small archives
4078 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4079 files from @file{practice}:
4080
4081 @smallexample
4082 $ @kbd{tar -cvf bluesrock.tar blues rock}
4083 blues
4084 rock
4085 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4086 folk
4087 jazz
4088 @end smallexample
4089
4090 @noindent
4091 If you like, You can run @samp{tar --list} to make sure the archives
4092 contain what they are supposed to:
4093
4094 @smallexample
4095 $ @kbd{tar -tvf bluesrock.tar}
4096 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4097 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4098 $ @kbd{tar -tvf jazzfolk.tar}
4099 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4100 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4101 @end smallexample
4102
4103 We can concatenate these two archives with @command{tar}:
4104
4105 @smallexample
4106 $ @kbd{cd ..}
4107 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4108 @end smallexample
4109
4110 If you now list the contents of the @file{bluesrock.tar}, you will see
4111 that now it also contains the archive members of @file{jazzfolk.tar}:
4112
4113 @smallexample
4114 $ @kbd{tar --list --file=bluesrock.tar}
4115 blues
4116 rock
4117 folk
4118 jazz
4119 @end smallexample
4120
4121 When you use @option{--concatenate}, the source and target archives must
4122 already exist and must have been created using compatible format
4123 parameters. Notice, that @command{tar} does not check whether the
4124 archives it concatenates have compatible formats, it does not
4125 even check if the files are really tar archives.
4126
4127 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4128 tape drives, due to deficiencies in the formats those tape drives use.
4129
4130 @cindex @code{concatenate} vs @command{cat}
4131 @cindex @command{cat} vs @code{concatenate}
4132 It may seem more intuitive to you to want or try to use @command{cat} to
4133 concatenate two archives instead of using the @option{--concatenate}
4134 operation; after all, @command{cat} is the utility for combining files.
4135
4136 However, @command{tar} archives incorporate an end-of-file marker which
4137 must be removed if the concatenated archives are to be read properly as
4138 one archive. @option{--concatenate} removes the end-of-archive marker
4139 from the target archive before each new archive is appended. If you use
4140 @command{cat} to combine the archives, the result will not be a valid
4141 @command{tar} format archive. If you need to retrieve files from an
4142 archive that was added to using the @command{cat} utility, use the
4143 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4144 information on dealing with archives improperly combined using the
4145 @command{cat} shell utility.
4146
4147 @node delete
4148 @subsection Removing Archive Members Using @option{--delete}
4149 @UNREVISED
4150 @cindex Deleting files from an archive
4151 @cindex Removing files from an archive
4152
4153 @opindex delete
4154 You can remove members from an archive by using the @option{--delete}
4155 option. Specify the name of the archive with @option{--file}
4156 (@option{-f}) and then specify the names of the members to be deleted;
4157 if you list no member names, nothing will be deleted. The
4158 @option{--verbose} option will cause @command{tar} to print the names
4159 of the members as they are deleted. As with @option{--extract}, you
4160 must give the exact member names when using @samp{tar --delete}.
4161 @option{--delete} will remove all versions of the named file from the
4162 archive. The @option{--delete} operation can run very slowly.
4163
4164 Unlike other operations, @option{--delete} has no short form.
4165
4166 @cindex Tapes, using @option{--delete} and
4167 @cindex Deleting from tape archives
4168 This operation will rewrite the archive. You can only use
4169 @option{--delete} on an archive if the archive device allows you to
4170 write to any point on the media, such as a disk; because of this, it
4171 does not work on magnetic tapes. Do not try to delete an archive member
4172 from a magnetic tape; the action will not succeed, and you will be
4173 likely to scramble the archive and damage your tape. There is no safe
4174 way (except by completely re-writing the archive) to delete files from
4175 most kinds of magnetic tape. @xref{Media}.
4176
4177 To delete all versions of the file @file{blues} from the archive
4178 @file{collection.tar} in the @file{practice} directory, make sure you
4179 are in that directory, and then,
4180
4181 @smallexample
4182 $ @kbd{tar --list --file=collection.tar}
4183 blues
4184 folk
4185 jazz
4186 rock
4187 $ @kbd{tar --delete --file=collection.tar blues}
4188 $ @kbd{tar --list --file=collection.tar}
4189 folk
4190 jazz
4191 rock
4192 $
4193 @end smallexample
4194
4195 @FIXME{Check if the above listing is actually produced after running
4196 all the examples on collection.tar.}
4197
4198 The @option{--delete} option has been reported to work properly when
4199 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4200
4201 @node compare
4202 @subsection Comparing Archive Members with the File System
4203 @cindex Verifying the currency of an archive
4204 @UNREVISED
4205
4206 @opindex compare
4207 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4208 specified archive members against files with the same names, and then
4209 reports differences in file size, mode, owner, modification date and
4210 contents. You should @emph{only} specify archive member names, not file
4211 names. If you do not name any members, then @command{tar} will compare the
4212 entire archive. If a file is represented in the archive but does not
4213 exist in the file system, @command{tar} reports a difference.
4214
4215 You have to specify the record size of the archive when modifying an
4216 archive with a non-default record size.
4217
4218 @command{tar} ignores files in the file system that do not have
4219 corresponding members in the archive.
4220
4221 The following example compares the archive members @file{rock},
4222 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4223 files of the same name in the file system. (Note that there is no file,
4224 @file{funk}; @command{tar} will report an error message.)
4225
4226 @smallexample
4227 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4228 rock
4229 blues
4230 tar: funk not found in archive
4231 @end smallexample
4232
4233 The spirit behind the @option{--compare} (@option{--diff},
4234 @option{-d}) option is to check whether the archive represents the
4235 current state of files on disk, more than validating the integrity of
4236 the archive media. For this later goal, @xref{verify}.
4237
4238 @node create options
4239 @section Options Used by @option{--create}
4240
4241 @xopindex{create, additional options}
4242 The previous chapter described the basics of how to use
4243 @option{--create} (@option{-c}) to create an archive from a set of files.
4244 @xref{create}. This section described advanced options to be used with
4245 @option{--create}.
4246
4247 @menu
4248 * Ignore Failed Read::
4249 @end menu
4250
4251 @node Ignore Failed Read
4252 @subsection Ignore Fail Read
4253
4254 @table @option
4255 @item --ignore-failed-read
4256 Do not exit with nonzero on unreadable files or directories.
4257 @end table
4258
4259 @node extract options
4260 @section Options Used by @option{--extract}
4261 @UNREVISED
4262
4263 @xopindex{extract, additional options}
4264 The previous chapter showed how to use @option{--extract} to extract
4265 an archive into the file system. Various options cause @command{tar} to
4266 extract more information than just file contents, such as the owner,
4267 the permissions, the modification date, and so forth. This section
4268 presents options to be used with @option{--extract} when certain special
4269 considerations arise. You may review the information presented in
4270 @ref{extract} for more basic information about the
4271 @option{--extract} operation.
4272
4273 @menu
4274 * Reading:: Options to Help Read Archives
4275 * Writing:: Changing How @command{tar} Writes Files
4276 * Scarce:: Coping with Scarce Resources
4277 @end menu
4278
4279 @node Reading
4280 @subsection Options to Help Read Archives
4281 @cindex Options when reading archives
4282 @UNREVISED
4283
4284 @cindex Reading incomplete records
4285 @cindex Records, incomplete
4286 @opindex read-full-records
4287 Normally, @command{tar} will request data in full record increments from
4288 an archive storage device. If the device cannot return a full record,
4289 @command{tar} will report an error. However, some devices do not always
4290 return full records, or do not require the last record of an archive to
4291 be padded out to the next record boundary. To keep reading until you
4292 obtain a full record, or to accept an incomplete record if it contains
4293 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4294 in conjunction with the @option{--extract} or @option{--list} operations.
4295 @xref{Blocking}.
4296
4297 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4298 @command{tar} reads an archive from standard input, or from a remote
4299 machine. This is because on BSD Unix systems, attempting to read a
4300 pipe returns however much happens to be in the pipe, even if it is
4301 less than was requested. If this option were not enabled, @command{tar}
4302 would fail as soon as it read an incomplete record from the pipe.
4303
4304 If you're not sure of the blocking factor of an archive, you can
4305 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4306 @option{--blocking-factor=@var{512-size}} (@option{-b
4307 @var{512-size}}), using a blocking factor larger than what the archive
4308 uses. This lets you avoid having to determine the blocking factor
4309 of an archive. @xref{Blocking Factor}.
4310
4311 @menu
4312 * read full records::
4313 * Ignore Zeros::
4314 @end menu
4315
4316 @node read full records
4317 @unnumberedsubsubsec Reading Full Records
4318
4319 @FIXME{need sentence or so of intro here}
4320
4321 @table @option
4322 @opindex read-full-records
4323 @item --read-full-records
4324 @item -B
4325 Use in conjunction with @option{--extract} (@option{--get},
4326 @option{-x}) to read an archive which contains incomplete records, or
4327 one which has a blocking factor less than the one specified.
4328 @end table
4329
4330 @node Ignore Zeros
4331 @unnumberedsubsubsec Ignoring Blocks of Zeros
4332
4333 @cindex End-of-archive blocks, ignoring
4334 @cindex Ignoring end-of-archive blocks
4335 @opindex ignore-zeros
4336 Normally, @command{tar} stops reading when it encounters a block of zeros
4337 between file entries (which usually indicates the end of the archive).
4338 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4339 completely read an archive which contains a block of zeros before the
4340 end (i.e., a damaged archive, or one that was created by concatenating
4341 several archives together).
4342
4343 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4344 versions of @command{tar} write garbage after the end-of-archive entry,
4345 since that part of the media is never supposed to be read. @GNUTAR{}
4346 does not write after the end of an archive, but seeks to
4347 maintain compatiblity among archiving utilities.
4348
4349 @table @option
4350 @item --ignore-zeros
4351 @itemx -i
4352 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4353 encountered while reading an archive. Use in conjunction with
4354 @option{--extract} or @option{--list}.
4355 @end table
4356
4357 @node Writing
4358 @subsection Changing How @command{tar} Writes Files
4359 @UNREVISED
4360
4361 @FIXME{Introductory paragraph}
4362
4363 @menu
4364 * Dealing with Old Files::
4365 * Overwrite Old Files::
4366 * Keep Old Files::
4367 * Keep Newer Files::
4368 * Unlink First::
4369 * Recursive Unlink::
4370 * Data Modification Times::
4371 * Setting Access Permissions::
4372 * Directory Modification Times and Permissions::
4373 * Writing to Standard Output::
4374 * Writing to an External Program::
4375 * remove files::
4376 @end menu
4377
4378 @node Dealing with Old Files
4379 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4380
4381 @xopindex{overwrite-dir, introduced}
4382 When extracting files, if @command{tar} discovers that the extracted
4383 file already exists, it normally replaces the file by removing it before
4384 extracting it, to prevent confusion in the presence of hard or symbolic
4385 links. (If the existing file is a symbolic link, it is removed, not
4386 followed.) However, if a directory cannot be removed because it is
4387 nonempty, @command{tar} normally overwrites its metadata (ownership,
4388 permission, etc.). The @option{--overwrite-dir} option enables this
4389 default behavior. To be more cautious and preserve the metadata of
4390 such a directory, use the @option{--no-overwrite-dir} option.
4391
4392 @cindex Overwriting old files, prevention
4393 @xopindex{keep-old-files, introduced}
4394 To be even more cautious and prevent existing files from being replaced, use
4395 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4396 to replace or update a file that already exists, i.e., a file with the
4397 same name as an archive member prevents extraction of that archive
4398 member. Instead, it reports an error.
4399
4400 @xopindex{overwrite, introduced}
4401 To be more aggressive about altering existing files, use the
4402 @option{--overwrite} option. It causes @command{tar} to overwrite
4403 existing files and to follow existing symbolic links when extracting.
4404
4405 @cindex Protecting old files
4406 Some people argue that @GNUTAR{} should not hesitate
4407 to overwrite files with other files when extracting. When extracting
4408 a @command{tar} archive, they expect to see a faithful copy of the
4409 state of the file system when the archive was created. It is debatable
4410 that this would always be a proper behavior. For example, suppose one
4411 has an archive in which @file{usr/local} is a link to
4412 @file{usr/local2}. Since then, maybe the site removed the link and
4413 renamed the whole hierarchy from @file{/usr/local2} to
4414 @file{/usr/local}. Such things happen all the time. I guess it would
4415 not be welcome at all that @GNUTAR{} removes the
4416 whole hierarchy just to make room for the link to be reinstated
4417 (unless it @emph{also} simultaneously restores the full
4418 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4419 able to remove a whole hierarchy to reestablish a symbolic link, for
4420 example, but @emph{only if} @option{--recursive-unlink} is specified
4421 to allow this behavior. In any case, single files are silently
4422 removed.
4423
4424 @xopindex{unlink-first, introduced}
4425 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4426 some cases by causing @command{tar} to remove files unconditionally
4427 before extracting them.
4428
4429 @node Overwrite Old Files
4430 @unnumberedsubsubsec Overwrite Old Files
4431
4432 @table @option
4433 @opindex overwrite
4434 @item --overwrite
4435 Overwrite existing files and directory metadata when extracting files
4436 from an archive.
4437
4438 This causes @command{tar} to write extracted files into the file system without
4439 regard to the files already on the system; i.e., files with the same
4440 names as archive members are overwritten when the archive is extracted.
4441 It also causes @command{tar} to extract the ownership, permissions,
4442 and time stamps onto any preexisting files or directories.
4443 If the name of a corresponding file name is a symbolic link, the file
4444 pointed to by the symbolic link will be overwritten instead of the
4445 symbolic link itself (if this is possible). Moreover, special devices,
4446 empty directories and even symbolic links are automatically removed if
4447 they are in the way of extraction.
4448
4449 Be careful when using the @option{--overwrite} option, particularly when
4450 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4451 can change the contents, ownership or permissions of any file on your
4452 system. Also, many systems do not take kindly to overwriting files that
4453 are currently being executed.
4454
4455 @opindex overwrite-dir
4456 @item --overwrite-dir
4457 Overwrite the metadata of directories when extracting files from an
4458 archive, but remove other files before extracting.
4459 @end table
4460
4461 @node Keep Old Files
4462 @unnumberedsubsubsec Keep Old Files
4463
4464 @table @option
4465 @opindex keep-old-files
4466 @item --keep-old-files
4467 @itemx -k
4468 Do not replace existing files from archive. The
4469 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4470 from replacing existing files with files with the same name from the
4471 archive. The @option{--keep-old-files} option is meaningless with
4472 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4473 files in the file system during extraction.
4474 @end table
4475
4476 @node Keep Newer Files
4477 @unnumberedsubsubsec Keep Newer Files
4478
4479 @table @option
4480 @opindex keep-newer-files
4481 @item --keep-newer-files
4482 Do not replace existing files that are newer than their archive
4483 copies. This option is meaningless with @option{--list} (@option{-t}).
4484 @end table
4485
4486 @node Unlink First
4487 @unnumberedsubsubsec Unlink First
4488
4489 @table @option
4490 @opindex unlink-first
4491 @item --unlink-first
4492 @itemx -U
4493 Remove files before extracting over them.
4494 This can make @command{tar} run a bit faster if you know in advance
4495 that the extracted files all need to be removed. Normally this option
4496 slows @command{tar} down slightly, so it is disabled by default.
4497 @end table
4498
4499 @node Recursive Unlink
4500 @unnumberedsubsubsec Recursive Unlink
4501
4502 @table @option
4503 @opindex recursive-unlink
4504 @item --recursive-unlink
4505 When this option is specified, try removing files and directory hierarchies
4506 before extracting over them. @emph{This is a dangerous option!}
4507 @end table
4508
4509 If you specify the @option{--recursive-unlink} option,
4510 @command{tar} removes @emph{anything} that keeps you from extracting a file
4511 as far as current permissions will allow it. This could include removal
4512 of the contents of a full directory hierarchy.
4513
4514 @node Data Modification Times
4515 @unnumberedsubsubsec Setting Data Modification Times
4516
4517 @cindex Data modification times of extracted files
4518 @cindex Modification times of extracted files
4519 Normally, @command{tar} sets the data modification times of extracted
4520 files to the corresponding times recorded for the files in the archive, but
4521 limits the permissions of extracted files by the current @code{umask}
4522 setting.
4523
4524 To set the data modification times of extracted files to the time when
4525 the files were extracted, use the @option{--touch} (@option{-m}) option in
4526 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4527
4528 @table @option
4529 @opindex touch
4530 @item --touch
4531 @itemx -m
4532 Sets the data modification time of extracted archive members to the time
4533 they were extracted, not the time recorded for them in the archive.
4534 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4535 @end table
4536
4537 @node Setting Access Permissions
4538 @unnumberedsubsubsec Setting Access Permissions
4539
4540 @cindex Permissions of extracted files
4541 @cindex Modes of extracted files
4542 To set the modes (access permissions) of extracted files to those
4543 recorded for those files in the archive, use @option{--same-permissions}
4544 in conjunction with the @option{--extract} (@option{--get},
4545 @option{-x}) operation.
4546
4547 @table @option
4548 @opindex preserve-permissions
4549 @opindex same-permissions
4550 @item --preserve-permissions
4551 @itemx --same-permissions
4552 @c @itemx --ignore-umask
4553 @itemx -p
4554 Set modes of extracted archive members to those recorded in the
4555 archive, instead of current umask settings. Use in conjunction with
4556 @option{--extract} (@option{--get}, @option{-x}).
4557 @end table
4558
4559 @node Directory Modification Times and Permissions
4560 @unnumberedsubsubsec Directory Modification Times and Permissions
4561
4562 After sucessfully extracting a file member, @GNUTAR{} normally
4563 restores its permissions and modification times, as described in the
4564 previous sections. This cannot be done for directories, because
4565 after extracting a directory @command{tar} will almost certainly
4566 extract files into that directory and this will cause the directory
4567 modification time to be updated. Moreover, restoring that directory
4568 permissions may not permit file creation within it. Thus, restoring
4569 directory permissions and modification times must be delayed at least
4570 until all files have been extracted into that directory. @GNUTAR{}
4571 restores directories using the following approach.
4572
4573 The extracted directories are created with the mode specified in the
4574 archive, as modified by the umask of the user, which gives sufficient
4575 permissions to allow file creation. The meta-information about the
4576 directory is recorded in the temporary list of directories. When
4577 preparing to extract next archive member, @GNUTAR{} checks if the
4578 directory prefix of this file contains the remembered directory. If
4579 it does not, the program assumes that all files have been extracted
4580 into that directory, restores its modification time and permissions
4581 and removes its entry from the internal list. This approach allows
4582 to correctly restore directory meta-information in the majority of
4583 cases, while keeping memory requirements sufficiently small. It is
4584 based on the fact, that most @command{tar} archives use the predefined
4585 order of members: first the directory, then all the files and
4586 subdirectories in that directory.
4587
4588 However, this is not always true. The most important exception are
4589 incremental archives (@pxref{Incremental Dumps}). The member order in
4590 an incremental archive is reversed: first all directory members are
4591 stored, followed by other (non-directory) members. So, when extracting
4592 from incremental archives, @GNUTAR{} alters the above procedure. It
4593 remebers all restored directories, and restores their meta-data
4594 only after the entire archive has been processed. Notice, that you do
4595 not need to specity any special options for that, as @GNUTAR{}
4596 automatically detects archives in incremental format.
4597
4598 There may be cases, when such processing is required for normal archives
4599 too. Consider the following example:
4600
4601 @smallexample
4602 @group
4603 $ @kbd{tar --no-recursion -cvf archive \
4604 foo foo/file1 bar bar/file foo/file2}
4605 foo/
4606 foo/file1
4607 bar/
4608 bar/file
4609 foo/file2
4610 @end group
4611 @end smallexample
4612
4613 During the normal operation, after encountering @file{bar}
4614 @GNUTAR{} will assume that all files from the directory @file{foo}
4615 were already extracted and will therefore restore its timestamp and
4616 permission bits. However, after extracting @file{foo/file2} the
4617 directory timestamp will be offset again.
4618
4619 To correctly restore directory meta-information in such cases, use
4620 @option{delay-directory-restore} command line option:
4621
4622 @table @option
4623 @opindex delay-directory-restore
4624 @item --delay-directory-restore
4625 Delays restoring of the modification times and permissions of extracted
4626 directories until the end of extraction. This way, correct
4627 meta-information is restored even if the archive has unusual member
4628 ordering.
4629
4630 @opindex no-delay-directory-restore
4631 @item --no-delay-directory-restore
4632 Cancel the effect of the previous @option{--delay-directory-restore}.
4633 Use this option if you have used @option{--delay-directory-restore} in
4634 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4635 temporarily disable it.
4636 @end table
4637
4638 @node Writing to Standard Output
4639 @unnumberedsubsubsec Writing to Standard Output
4640
4641 @cindex Writing extracted files to standard output
4642 @cindex Standard output, writing extracted files to
4643 To write the extracted files to the standard output, instead of
4644 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4645 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4646 extracting files to send them through a pipe, and do not need to
4647 preserve them in the file system. If you extract multiple members,
4648 they appear on standard output concatenated, in the order they are
4649 found in the archive.
4650
4651 @table @option
4652 @opindex to-stdout
4653 @item --to-stdout
4654 @itemx -O
4655 Writes files to the standard output. Use only in conjunction with
4656 @option{--extract} (@option{--get}, @option{-x}). When this option is
4657 used, instead of creating the files specified, @command{tar} writes
4658 the contents of the files extracted to its standard output. This may
4659 be useful if you are only extracting the files in order to send them
4660 through a pipe. This option is meaningless with @option{--list}
4661 (@option{-t}).
4662 @end table
4663
4664 This can be useful, for example, if you have a tar archive containing
4665 a big file and don't want to store the file on disk before processing
4666 it. You can use a command like this:
4667
4668 @smallexample
4669 tar -xOzf foo.tgz bigfile | process
4670 @end smallexample
4671
4672 or even like this if you want to process the concatenation of the files:
4673
4674 @smallexample
4675 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4676 @end smallexample
4677
4678 Hovewer, @option{--to-command} may be more convenient for use with
4679 multiple files. See the next section.
4680
4681 @node Writing to an External Program
4682 @unnumberedsubsubsec Writing to an External Program
4683
4684 You can instruct @command{tar} to send the contents of each extracted
4685 file to the standard input of an external program:
4686
4687 @table @option
4688 @opindex to-command
4689 @item --to-command=@var{command}
4690 Extract files and pipe their contents to the standard input of
4691 @var{command}. When this option is used, instead of creating the
4692 files specified, @command{tar} invokes @var{command} and pipes the
4693 contents of the files to its standard output. @var{Command} may
4694 contain command line arguments. The program is executed via
4695 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4696 extracted. Non-regular files (directories, etc.) are ignored when this
4697 option is used.
4698 @end table
4699
4700 The command can obtain the information about the file it processes
4701 from the following environment variables:
4702
4703 @table @var
4704 @vrindex TAR_FILETYPE, to-command environment
4705 @item TAR_FILETYPE
4706 Type of the file. It is a single letter with the following meaning:
4707
4708 @multitable @columnfractions 0.10 0.90
4709 @item f @tab Regular file
4710 @item d @tab Directory
4711 @item l @tab Symbolic link
4712 @item h @tab Hard link
4713 @item b @tab Block device
4714 @item c @tab Character device
4715 @end multitable
4716
4717 Currently only regular files are supported.
4718
4719 @vrindex TAR_MODE, to-command environment
4720 @item TAR_MODE
4721 File mode, an octal number.
4722
4723 @vrindex TAR_FILENAME, to-command environment
4724 @item TAR_FILENAME
4725 The name of the file.
4726
4727 @vrindex TAR_REALNAME, to-command environment
4728 @item TAR_REALNAME
4729 Name of the file as stored in the archive.
4730
4731 @vrindex TAR_UNAME, to-command environment
4732 @item TAR_UNAME
4733 Name of the file owner.
4734
4735 @vrindex TAR_GNAME, to-command environment
4736 @item TAR_GNAME
4737 Name of the file owner group.
4738
4739 @vrindex TAR_ATIME, to-command environment
4740 @item TAR_ATIME
4741 Time of last access. It is a decimal number, representing seconds
4742 since the epoch. If the archive provides times with nanosecond
4743 precision, the nanoseconds are appended to the timestamp after a
4744 decimal point.
4745
4746 @vrindex TAR_MTIME, to-command environment
4747 @item TAR_MTIME
4748 Time of last modification.
4749
4750 @vrindex TAR_CTIME, to-command environment
4751 @item TAR_CTIME
4752 Time of last status change.
4753
4754 @vrindex TAR_SIZE, to-command environment
4755 @item TAR_SIZE
4756 Size of the file.
4757
4758 @vrindex TAR_UID, to-command environment
4759 @item TAR_UID
4760 UID of the file owner.
4761
4762 @vrindex TAR_GID, to-command environment
4763 @item TAR_GID
4764 GID of the file owner.
4765 @end table
4766
4767 In addition to these variables, @env{TAR_VERSION} contains the
4768 @GNUTAR{} version number.
4769
4770 If @var{command} exits with a non-0 status, @command{tar} will print
4771 an error message similar to the following:
4772
4773 @smallexample
4774 tar: 2345: Child returned status 1
4775 @end smallexample
4776
4777 Here, @samp{2345} is the PID of the finished process.
4778
4779 If this behavior is not wanted, use @option{--ignore-command-error}:
4780
4781 @table @option
4782 @opindex ignore-command-error
4783 @item --ignore-command-error
4784 Ignore exit codes of subprocesses. Notice that if the program
4785 exits on signal or otherwise terminates abnormally, the error message
4786 will be printed even if this option is used.
4787
4788 @opindex no-ignore-command-error
4789 @item --no-ignore-command-error
4790 Cancel the effect of any previous @option{--ignore-command-error}
4791 option. This option is useful if you have set
4792 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4793 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4794 @end table
4795
4796 @node remove files
4797 @unnumberedsubsubsec Removing Files
4798
4799 @FIXME{The section is too terse. Something more to add? An example,
4800 maybe?}
4801
4802 @table @option
4803 @opindex remove-files
4804 @item --remove-files
4805 Remove files after adding them to the archive.
4806 @end table
4807
4808 @node Scarce
4809 @subsection Coping with Scarce Resources
4810 @UNREVISED
4811
4812 @cindex Small memory
4813 @cindex Running out of space
4814
4815 @menu
4816 * Starting File::
4817 * Same Order::
4818 @end menu
4819
4820 @node Starting File
4821 @unnumberedsubsubsec Starting File
4822
4823 @table @option
4824 @opindex starting-file
4825 @item --starting-file=@var{name}
4826 @itemx -K @var{name}
4827 Starts an operation in the middle of an archive. Use in conjunction
4828 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4829 @end table
4830
4831 @cindex Middle of the archive, starting in the
4832 If a previous attempt to extract files failed due to lack of disk
4833 space, you can use @option{--starting-file=@var{name}} (@option{-K
4834 @var{name}}) to start extracting only after member @var{name} of the
4835 archive. This assumes, of course, that there is now free space, or
4836 that you are now extracting into a different file system. (You could
4837 also choose to suspend @command{tar}, remove unnecessary files from
4838 the file system, and then restart the same @command{tar} operation.
4839 In this case, @option{--starting-file} is not necessary.
4840 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4841
4842 @node Same Order
4843 @unnumberedsubsubsec Same Order
4844
4845 @table @option
4846 @cindex Large lists of file names on small machines
4847 @opindex same-order
4848 @opindex preserve-order
4849 @item --same-order
4850 @itemx --preserve-order
4851 @itemx -s
4852 To process large lists of file names on machines with small amounts of
4853 memory. Use in conjunction with @option{--compare} (@option{--diff},
4854 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4855 (@option{--get}, @option{-x}).
4856 @end table
4857
4858 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4859 names to be listed or extracted is sorted in the same order as the
4860 files in the archive. This allows a large list of names to be used,
4861 even on a small machine that would not otherwise be able to hold all
4862 the names in memory at the same time. Such a sorted list can easily be
4863 created by running @samp{tar -t} on the archive and editing its output.
4864
4865 This option is probably never needed on modern computer systems.
4866
4867 @node backup
4868 @section Backup options
4869
4870 @cindex backup options
4871
4872 @GNUTAR{} offers options for making backups of files
4873 before writing new versions. These options control the details of
4874 these backups. They may apply to the archive itself before it is
4875 created or rewritten, as well as individual extracted members. Other
4876 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4877 and @command{mv}, for example) offer similar options.
4878
4879 Backup options may prove unexpectedly useful when extracting archives
4880 containing many members having identical name, or when extracting archives
4881 on systems having file name limitations, making different members appear
4882 has having similar names through the side-effect of name truncation.
4883 (This is true only if we have a good scheme for truncated backup names,
4884 which I'm not sure at all: I suspect work is needed in this area.)
4885 When any existing file is backed up before being overwritten by extraction,
4886 then clashing files are automatically be renamed to be unique, and the
4887 true name is kept for only the last file of a series of clashing files.
4888 By using verbose mode, users may track exactly what happens.
4889
4890 At the detail level, some decisions are still experimental, and may
4891 change in the future, we are waiting comments from our users. So, please
4892 do not learn to depend blindly on the details of the backup features.
4893 For example, currently, directories themselves are never renamed through
4894 using these options, so, extracting a file over a directory still has
4895 good chances to fail. Also, backup options apply to created archives,
4896 not only to extracted members. For created archives, backups will not
4897 be attempted when the archive is a block or character device, or when it
4898 refers to a remote file.
4899
4900 For the sake of simplicity and efficiency, backups are made by renaming old
4901 files prior to creation or extraction, and not by copying. The original
4902 name is restored if the file creation fails. If a failure occurs after a
4903 partial extraction of a file, both the backup and the partially extracted
4904 file are kept.
4905
4906 @table @samp
4907 @item --backup[=@var{method}]
4908 @opindex backup
4909 @vindex VERSION_CONTROL
4910 @cindex backups
4911 Back up files that are about to be overwritten or removed.
4912 Without this option, the original versions are destroyed.
4913
4914 Use @var{method} to determine the type of backups made.
4915 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
4916 environment variable. And if @env{VERSION_CONTROL} is not set,
4917 use the @samp{existing} method.
4918
4919 @vindex version-control @r{Emacs variable}
4920 This option corresponds to the Emacs variable @samp{version-control};
4921 the same values for @var{method} are accepted as in Emacs. This option
4922 also allows more descriptive names. The valid @var{method}s are:
4923
4924 @table @samp
4925 @item t
4926 @itemx numbered
4927 @cindex numbered @r{backup method}
4928 Always make numbered backups.
4929
4930 @item nil
4931 @itemx existing
4932 @cindex existing @r{backup method}
4933 Make numbered backups of files that already have them, simple backups
4934 of the others.
4935
4936 @item never
4937 @itemx simple
4938 @cindex simple @r{backup method}
4939 Always make simple backups.
4940
4941 @end table
4942
4943 @item --suffix=@var{suffix}
4944 @opindex suffix
4945 @cindex backup suffix
4946 @vindex SIMPLE_BACKUP_SUFFIX
4947 Append @var{suffix} to each backup file made with @option{--backup}. If this
4948 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
4949 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
4950 set, the default is @samp{~}, just as in Emacs.
4951
4952 @end table
4953
4954 @node Applications
4955 @section Notable @command{tar} Usages
4956 @UNREVISED
4957
4958 @FIXME{Using Unix file linking capability to recreate directory
4959 structures---linking files into one subdirectory and then
4960 @command{tar}ring that directory.}
4961
4962 @FIXME{Nice hairy example using absolute-names, newer, etc.}
4963
4964 @findex uuencode
4965 You can easily use archive files to transport a group of files from
4966 one system to another: put all relevant files into an archive on one
4967 computer system, transfer the archive to another system, and extract
4968 the contents there. The basic transfer medium might be magnetic tape,
4969 Internet FTP, or even electronic mail (though you must encode the
4970 archive with @command{uuencode} in order to transport it properly by
4971 mail). Both machines do not have to use the same operating system, as
4972 long as they both support the @command{tar} program.
4973
4974 For example, here is how you might copy a directory's contents from
4975 one disk to another, while preserving the dates, modes, owners and
4976 link-structure of all the files therein. In this case, the transfer
4977 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
4978
4979 @smallexample
4980 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
4981 @end smallexample
4982
4983 @noindent
4984 You can avoid subshells by using @option{-C} option:
4985
4986 @smallexample
4987 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
4988 @end smallexample
4989
4990 @noindent
4991 The command also works using short option forms:
4992
4993 @smallexample
4994 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
4995 | (cd targetdir; tar --extract --file=-)}
4996 # Or:
4997 $ @kbd{tar --directory sourcedir --create --file=- . ) \
4998 | tar --directory targetdir --extract --file=-}
4999 @end smallexample
5000
5001 @noindent
5002 This is one of the easiest methods to transfer a @command{tar} archive.
5003
5004 @node looking ahead
5005 @section Looking Ahead: The Rest of this Manual
5006
5007 You have now seen how to use all eight of the operations available to
5008 @command{tar}, and a number of the possible options. The next chapter
5009 explains how to choose and change file and archive names, how to use
5010 files to store names of other files which you can then call as
5011 arguments to @command{tar} (this can help you save time if you expect to
5012 archive the same list of files a number of times), and so forth.
5013 @FIXME{in case it's not obvious, i'm making this up in some sense
5014 based on my limited memory of what the next chapter *really* does. i
5015 just wanted to flesh out this final section a little bit so i'd
5016 remember to stick it in here. :-)}
5017
5018 If there are too many files to conveniently list on the command line,
5019 you can list the names in a file, and @command{tar} will read that file.
5020 @xref{files}.
5021
5022 There are various ways of causing @command{tar} to skip over some files,
5023 and not archive them. @xref{Choosing}.
5024
5025 @node Backups
5026 @chapter Performing Backups and Restoring Files
5027 @UNREVISED
5028
5029 @GNUTAR{} is distributed along with the scripts
5030 which the Free Software Foundation uses for performing backups. There
5031 is no corresponding scripts available yet for doing restoration of
5032 files. Even if there is a good chance those scripts may be satisfying
5033 to you, they are not the only scripts or methods available for doing
5034 backups and restore. You may well create your own, or use more
5035 sophisticated packages dedicated to that purpose.
5036
5037 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5038 Automatic Network Disk Archiver), a backup system developed by James
5039 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5040 This is free software, and it is available at these places:
5041
5042 @smallexample
5043 http://www.cs.umd.edu/projects/amanda/amanda.html
5044 ftp://ftp.cs.umd.edu/pub/amanda
5045 @end smallexample
5046
5047 @FIXME{
5048
5049 Here is a possible plan for a future documentation about the backuping
5050 scripts which are provided within the @GNUTAR{}
5051 distribution.
5052
5053 @itemize @bullet
5054 @item dumps
5055 @itemize @minus
5056 @item what are dumps
5057 @item different levels of dumps
5058 @itemize +
5059 @item full dump = dump everything
5060 @item level 1, level 2 dumps etc
5061 A level @var{n} dump dumps everything changed since the last level
5062 @var{n}-1 dump (?)
5063 @end itemize
5064 @item how to use scripts for dumps (ie, the concept)
5065 @itemize +
5066 @item scripts to run after editing backup specs (details)
5067 @end itemize
5068 @item Backup Specs, what is it.
5069 @itemize +
5070 @item how to customize
5071 @item actual text of script [/sp/dump/backup-specs]
5072 @end itemize
5073 @item Problems
5074 @itemize +
5075 @item rsh doesn't work
5076 @item rtape isn't installed
5077 @item (others?)
5078 @end itemize
5079 @item the @option{--incremental} option of tar
5080 @item tapes
5081 @itemize +
5082 @item write protection
5083 @item types of media, different sizes and types, useful for different things
5084 @item files and tape marks
5085 one tape mark between files, two at end.
5086 @item positioning the tape
5087 MT writes two at end of write,
5088 backspaces over one when writing again.
5089 @end itemize
5090 @end itemize
5091 @end itemize
5092 }
5093
5094 This chapter documents both the provided shell scripts and @command{tar}
5095 options which are more specific to usage as a backup tool.
5096
5097 To @dfn{back up} a file system means to create archives that contain
5098 all the files in that file system. Those archives can then be used to
5099 restore any or all of those files (for instance if a disk crashes or a
5100 file is accidentally deleted). File system @dfn{backups} are also
5101 called @dfn{dumps}.
5102
5103 @menu
5104 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5105 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5106 * Backup Levels:: Levels of Backups
5107 * Backup Parameters:: Setting Parameters for Backups and Restoration
5108 * Scripted Backups:: Using the Backup Scripts
5109 * Scripted Restoration:: Using the Restore Script
5110 @end menu
5111
5112 @node Full Dumps
5113 @section Using @command{tar} to Perform Full Dumps
5114 @UNREVISED
5115
5116 @cindex full dumps
5117 @cindex dumps, full
5118
5119 @cindex corrupted archives
5120 Full dumps should only be made when no other people or programs
5121 are modifying files in the file system. If files are modified while
5122 @command{tar} is making the backup, they may not be stored properly in
5123 the archive, in which case you won't be able to restore them if you
5124 have to. (Files not being modified are written with no trouble, and do
5125 not corrupt the entire archive.)
5126
5127 You will want to use the @option{--label=@var{archive-label}}
5128 (@option{-V @var{archive-label}}) option to give the archive a
5129 volume label, so you can tell what this archive is even if the label
5130 falls off the tape, or anything like that.
5131
5132 Unless the file system you are dumping is guaranteed to fit on
5133 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5134 Make sure you have enough tapes on hand to complete the backup.
5135
5136 If you want to dump each file system separately you will need to use
5137 the @option{--one-file-system} option to prevent
5138 @command{tar} from crossing file system boundaries when storing
5139 (sub)directories.
5140
5141 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5142 option is not needed, since this is a complete copy of everything in
5143 the file system, and a full restore from this backup would only be
5144 done onto a completely
5145 empty disk.
5146
5147 Unless you are in a hurry, and trust the @command{tar} program (and your
5148 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5149 option, to make sure your files really made it onto the dump properly.
5150 This will also detect cases where the file was modified while (or just
5151 after) it was being archived. Not all media (notably cartridge tapes)
5152 are capable of being verified, unfortunately.
5153
5154 @node Incremental Dumps
5155 @section Using @command{tar} to Perform Incremental Dumps
5156
5157 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5158 stores additional metadata so that exact state of the file system
5159 can be restored when extracting the archive.
5160
5161 @GNUTAR{} currently offers two options for handling incremental
5162 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5163 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5164
5165 @opindex listed-incremental
5166 The option @option{--listed-incremental} instructs tar to operate on
5167 an incremental archive with additional metadata stored in a standalone
5168 file, called a @dfn{snapshot file}. The purpose of this file is to help
5169 determine which files have been changed, added or deleted since the
5170 last backup, so that the next incremental backup will contain only
5171 modified files. The name of the snapshot file is given as an argument
5172 to the option:
5173
5174 @table @option
5175 @item --listed-incremental=@var{file}
5176 @itemx -g @var{file}
5177 Handle incremental backups with snapshot data in @var{file}.
5178 @end table
5179
5180 To create an incremental backup, you would use
5181 @option{--listed-incremental} together with @option{--create}
5182 (@pxref{create}). For example:
5183
5184 @smallexample
5185 $ @kbd{tar --create \
5186 --file=archive.1.tar \
5187 --listed-incremental=/var/log/usr.snar \
5188 /usr}
5189 @end smallexample
5190
5191 This will create in @file{archive.1.tar} an incremental backup of
5192 the @file{/usr} file system, storing additional metadata in the file
5193 @file{/var/log/usr.snar}. If this file does not exist, it will be
5194 created. The created archive will then be a @dfn{level 0 backup};
5195 please see the next section for more on backup levels.
5196
5197 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5198 determines which files are modified. In this case only these files will be
5199 stored in the archive. Suppose, for example, that after running the
5200 above command, you delete file @file{/usr/doc/old} and create
5201 directory @file{/usr/local/db} with the following contents:
5202
5203 @smallexample
5204 $ @kbd{ls /usr/local/db}
5205 /usr/local/db/data
5206 /usr/local/db/index
5207 @end smallexample
5208
5209 Some time later you create another incremental backup. You will
5210 then see:
5211
5212 @smallexample
5213 $ @kbd{tar --create \
5214 --file=archive.2.tar \
5215 --listed-incremental=/var/log/usr.snar \
5216 /usr}
5217 tar: usr/local/db: Directory is new
5218 usr/local/db/
5219 usr/local/db/data
5220 usr/local/db/index
5221 @end smallexample
5222
5223 @noindent
5224 The created archive @file{archive.2.tar} will contain only these
5225 three members. This archive is called a @dfn{level 1 backup}. Notice
5226 that @file{/var/log/usr.snar} will be updated with the new data, so if
5227 you plan to create more @samp{level 1} backups, it is necessary to
5228 create a working copy of the snapshot file before running
5229 @command{tar}. The above example will then be modified as follows:
5230
5231 @smallexample
5232 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5233 $ @kbd{tar --create \
5234 --file=archive.2.tar \
5235 --listed-incremental=/var/log/usr.snar-1 \
5236 /usr}
5237 @end smallexample
5238
5239 Incremental dumps depend crucially on time stamps, so the results are
5240 unreliable if you modify a file's time stamps during dumping (e.g.,
5241 with the @option{--atime-preserve=replace} option), or if you set the clock
5242 backwards.
5243
5244 Metadata stored in snapshot files include device numbers, which,
5245 obviously is supposed to be a non-volatile value. However, it turns
5246 out that NFS devices have undependable values when an automounter
5247 gets in the picture. This can lead to a great deal of spurious
5248 redumping in incremental dumps, so it is somewhat useless to compare
5249 two NFS devices numbers over time. The solution implemented currently
5250 is to considers all NFS devices as being equal when it comes to
5251 comparing directories; this is fairly gross, but there does not seem
5252 to be a better way to go.
5253
5254 Note that incremental archives use @command{tar} extensions and may
5255 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5256
5257 @xopindex{listed-incremental, using with @option{--extract}}
5258 @xopindex{extract, using with @option{--listed-incremental}}
5259 To extract from the incremental dumps, use
5260 @option{--listed-incremental} together with @option{--extract}
5261 option (@pxref{extracting files}). In this case, @command{tar} does
5262 not need to access snapshot file, since all the data necessary for
5263 extraction are stored in the archive itself. So, when extracting, you
5264 can give whatever argument to @option{--listed-incremental}, the usual
5265 practice is to use @option{--listed-incremental=/dev/null}.
5266 Alternatively, you can use @option{--incremental}, which needs no
5267 arguments. In general, @option{--incremental} (@option{-G}) can be
5268 used as a shortcut for @option{--listed-incremental} when listing or
5269 extracting incremental backups (for more information, regarding this
5270 option, @pxref{incremental-op}).
5271
5272 When extracting from the incremental backup @GNUTAR{} attempts to
5273 restore the exact state the file system had when the archive was
5274 created. In particular, it will @emph{delete} those files in the file
5275 system that did not exist in their directories when the archive was
5276 created. If you have created several levels of incremental files,
5277 then in order to restore the exact contents the file system had when
5278 the last level was created, you will need to restore from all backups
5279 in turn. Continuing our example, to restore the state of @file{/usr}
5280 file system, one would do@footnote{Notice, that since both archives
5281 were created withouth @option{-P} option (@pxref{absolute}), these
5282 commands should be run from the root file system.}:
5283
5284 @smallexample
5285 $ @kbd{tar --extract \
5286 --listed-incremental=/dev/null \
5287 --file archive.1.tar}
5288 $ @kbd{tar --extract \
5289 --listed-incremental=/dev/null \
5290 --file archive.2.tar}
5291 @end smallexample
5292
5293 To list the contents of an incremental archive, use @option{--list}
5294 (@pxref{list}), as usual. To obtain more information about the
5295 archive, use @option{--listed-incremental} or @option{--incremental}
5296 combined with two @option{--verbose} options@footnote{Two
5297 @option{--verbose} options were selected to avoid breaking usual
5298 verbose listing output (@option{--list --verbose}) when using in
5299 scripts.
5300
5301 @xopindex{incremental, using with @option{--list}}
5302 @xopindex{listed-incremental, using with @option{--list}}
5303 @xopindex{list, using with @option{--incremental}}
5304 @xopindex{list, using with @option{--listed-incremental}}
5305 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5306 contents of the DUMPDIR header (with terminating nulls) when
5307 @option{--incremental} or @option{--listed-incremental} option was
5308 given, no matter what the verbosity level. This behavior, and,
5309 especially, the binary output it produced were considered incovenient
5310 and were changed in version 1.16}:
5311
5312 @smallexample
5313 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5314 @end smallexample
5315
5316 This command will print, for each directory in the archive, the list
5317 of files in that directory at the time the archive was created. This
5318 information is put out in a format which is both human-readable and
5319 unambiguous for a program: each file name is printed as
5320
5321 @smallexample
5322 @var{x} @var{file}
5323 @end smallexample
5324
5325 @noindent
5326 where @var{x} is a letter describing the status of the file: @samp{Y}
5327 if the file is present in the archive, @samp{N} if the file is not
5328 included in the archive, or a @samp{D} if the file is a directory (and
5329 is included in the archive). @xref{Dumpdir}, for the detailed
5330 description of dumpdirs and status codes. Each such
5331 line is terminated by a newline character. The last line is followed
5332 by an additional newline to indicate the end of the data.
5333
5334 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5335 gives the same behavior as @option{--listed-incremental} when used
5336 with @option{--list} and @option{--extract} options. When used with
5337 @option{--create} option, it creates an incremental archive without
5338 creating snapshot file. Thus, it is impossible to create several
5339 levels of incremental backups with @option{--incremental} option.
5340
5341 @node Backup Levels
5342 @section Levels of Backups
5343
5344 An archive containing all the files in the file system is called a
5345 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5346 creating a full dump every day. This strategy, however, would waste a
5347 substantial amount of archive media and user time, as unchanged files
5348 are daily re-archived.
5349
5350 It is more efficient to do a full dump only occasionally. To back up
5351 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5352 one} dump archives all the files that have changed since the last full
5353 dump.
5354
5355 A typical dump strategy would be to perform a full dump once a week,
5356 and a level one dump once a day. This means some versions of files
5357 will in fact be archived more than once, but this dump strategy makes
5358 it possible to restore a file system to within one day of accuracy by
5359 only extracting two archives---the last weekly (full) dump and the
5360 last daily (level one) dump. The only information lost would be in
5361 files changed or created since the last daily backup. (Doing dumps
5362 more than once a day is usually not worth the trouble).
5363
5364 @GNUTAR{} comes with scripts you can use to do full
5365 and level-one (actually, even level-two and so on) dumps. Using
5366 scripts (shell programs) to perform backups and restoration is a
5367 convenient and reliable alternative to typing out file name lists
5368 and @command{tar} commands by hand.
5369
5370 Before you use these scripts, you need to edit the file
5371 @file{backup-specs}, which specifies parameters used by the backup
5372 scripts and by the restore script. This file is usually located
5373 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5374 detailed description. Once the backup parameters are set, you can
5375 perform backups or restoration by running the appropriate script.
5376
5377 The name of the backup script is @code{backup}. The name of the
5378 restore script is @code{restore}. The following sections describe
5379 their use in detail.
5380
5381 @emph{Please Note:} The backup and restoration scripts are
5382 designed to be used together. While it is possible to restore files by
5383 hand from an archive which was created using a backup script, and to create
5384 an archive by hand which could then be extracted using the restore script,
5385 it is easier to use the scripts. @xref{Incremental Dumps}, before
5386 making such an attempt.
5387
5388 @node Backup Parameters
5389 @section Setting Parameters for Backups and Restoration
5390
5391 The file @file{backup-specs} specifies backup parameters for the
5392 backup and restoration scripts provided with @command{tar}. You must
5393 edit @file{backup-specs} to fit your system configuration and schedule
5394 before using these scripts.
5395
5396 Syntactically, @file{backup-specs} is a shell script, containing
5397 mainly variable assignments. However, any valid shell construct
5398 is allowed in this file. Particularly, you may wish to define
5399 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5400 For more information about shell script syntax, please refer to
5401 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5402 g_02, the definition of the Shell Command Language}. See also
5403 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5404
5405 The shell variables controlling behavior of @code{backup} and
5406 @code{restore} are described in the following subsections.
5407
5408 @menu
5409 * General-Purpose Variables::
5410 * Magnetic Tape Control::
5411 * User Hooks::
5412 * backup-specs example:: An Example Text of @file{Backup-specs}
5413 @end menu
5414
5415 @node General-Purpose Variables
5416 @subsection General-Purpose Variables
5417
5418 @defvr {Backup variable} ADMINISTRATOR
5419 The user name of the backup administrator. @code{Backup} scripts
5420 sends a backup report to this address.
5421 @end defvr
5422
5423 @defvr {Backup variable} BACKUP_HOUR
5424 The hour at which the backups are done. This can be a number from 0
5425 to 23, or the time specification in form @var{hours}:@var{minutes},
5426 or the string @samp{now}.
5427
5428 This variable is used by @code{backup}. Its value may be overridden
5429 using @option{--time} option (@pxref{Scripted Backups}).
5430 @end defvr
5431
5432 @defvr {Backup variable} TAPE_FILE
5433
5434 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5435 is a remote archive (@pxref{remote-dev}), backup script will suppose
5436 that your @command{mt} is able to access remote devices. If @var{RSH}
5437 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5438 invocations of @command{mt}.
5439 @end defvr
5440
5441 @defvr {Backup variable} BLOCKING
5442
5443 The blocking factor @command{tar} will use when writing the dump archive.
5444 @xref{Blocking Factor}.
5445 @end defvr
5446
5447 @defvr {Backup variable} BACKUP_DIRS
5448
5449 A list of file systems to be dumped (for @code{backup}), or restored
5450 (for @code{restore}). You can include any directory
5451 name in the list --- subdirectories on that file system will be
5452 included, regardless of how they may look to other networked machines.
5453 Subdirectories on other file systems will be ignored.
5454
5455 The host name specifies which host to run @command{tar} on, and should
5456 normally be the host that actually contains the file system. However,
5457 the host machine must have @GNUTAR{} installed, and
5458 must be able to access the directory containing the backup scripts and
5459 their support files using the same file name that is used on the
5460 machine where the scripts are run (i.e. what @command{pwd} will print
5461 when in that directory on that machine). If the host that contains
5462 the file system does not have this capability, you can specify another
5463 host as long as it can access the file system through NFS.
5464
5465 If the list of file systems is very long you may wish to put it
5466 in a separate file. This file is usually named
5467 @file{/etc/backup/dirs}, but this name may be overridden in
5468 @file{backup-specs} using @code{DIRLIST} variable.
5469 @end defvr
5470
5471 @defvr {Backup variable} DIRLIST
5472
5473 A path to the file containing the list of the file systems to backup
5474 or restore. By default it is @file{/etc/backup/dirs}.
5475 @end defvr
5476
5477 @defvr {Backup variable} BACKUP_FILES
5478
5479 A list of individual files to be dumped (for @code{backup}), or restored
5480 (for @code{restore}). These should be accessible from the machine on
5481 which the backup script is run.
5482
5483 If the list of file systems is very long you may wish to store it
5484 in a separate file. This file is usually named
5485 @file{/etc/backup/files}, but this name may be overridden in
5486 @file{backup-specs} using @code{FILELIST} variable.
5487 @end defvr
5488
5489 @defvr {Backup variable} FILELIST
5490
5491 A path to the file containing the list of the individual files to backup
5492 or restore. By default it is @file{/etc/backup/files}.
5493 @end defvr
5494
5495 @defvr {Backup variable} MT
5496
5497 Full file name of @command{mt} binary.
5498 @end defvr
5499
5500 @defvr {Backup variable} RSH
5501 @anchor{RSH}
5502 Full file name of @command{rsh} binary or its equivalent. You may wish to
5503 set it to @code{ssh}, to improve security. In this case you will have
5504 to use public key authentication.
5505 @end defvr
5506
5507 @defvr {Backup variable} RSH_COMMAND
5508
5509 Full file name of @command{rsh} binary on remote mashines. This will
5510 be passed via @option{--rsh-command} option to the remote invocation
5511 of @GNUTAR{}.
5512 @end defvr
5513
5514 @defvr {Backup variable} VOLNO_FILE
5515
5516 Name of temporary file to hold volume numbers. This needs to be accessible
5517 by all the machines which have file systems to be dumped.
5518 @end defvr
5519
5520 @defvr {Backup variable} XLIST
5521
5522 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5523 located on the remote machine and containing the list of files to
5524 be excluded from the backup. Exclude file lists are searched in
5525 /etc/tar-backup directory. A common use for exclude file lists
5526 is to exclude files containing security-sensitive information
5527 (e.g., @file{/etc/shadow} from backups).
5528
5529 This variable affects only @code{backup}.
5530 @end defvr
5531
5532 @defvr {Backup variable} SLEEP_TIME
5533
5534 Time to sleep between dumps of any two successive file systems
5535
5536 This variable affects only @code{backup}.
5537 @end defvr
5538
5539 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5540
5541 Script to be run when it's time to insert a new tape in for the next
5542 volume. Administrators may want to tailor this script for their site.
5543 If this variable isn't set, @GNUTAR{} will display its built-in
5544 prompt, and will expect confirmation from the console. For the
5545 description of the default prompt, see @ref{change volume prompt}.
5546
5547 @end defvr
5548
5549 @defvr {Backup variable} SLEEP_MESSAGE
5550
5551 Message to display on the terminal while waiting for dump time. Usually
5552 this will just be some literal text.
5553 @end defvr
5554
5555 @defvr {Backup variable} TAR
5556
5557 Full file name of the @GNUTAR{} executable. If this is not set, backup
5558 scripts will search @command{tar} in the current shell path.
5559 @end defvr
5560
5561 @node Magnetic Tape Control
5562 @subsection Magnetic Tape Control
5563
5564 Backup scripts access tape device using special @dfn{hook functions}.
5565 These functions take a single argument -- the name of the tape
5566 device. Their names are kept in the following variables:
5567
5568 @defvr {Backup variable} MT_BEGIN
5569 The name of @dfn{begin} function. This function is called before
5570 accessing the drive. By default it retensions the tape:
5571
5572 @smallexample
5573 MT_BEGIN=mt_begin
5574
5575 mt_begin() @{
5576 mt -f "$1" retension
5577 @}
5578 @end smallexample
5579 @end defvr
5580
5581 @defvr {Backup variable} MT_REWIND
5582 The name of @dfn{rewind} function. The default definition is as
5583 follows:
5584
5585 @smallexample
5586 MT_REWIND=mt_rewind
5587
5588 mt_rewind() @{
5589 mt -f "$1" rewind
5590 @}
5591 @end smallexample
5592
5593 @end defvr
5594
5595 @defvr {Backup variable} MT_OFFLINE
5596 The name of the function switching the tape off line. By default
5597 it is defined as follows:
5598
5599 @smallexample
5600 MT_OFFLINE=mt_offline
5601
5602 mt_offline() @{
5603 mt -f "$1" offl
5604 @}
5605 @end smallexample
5606 @end defvr
5607
5608 @defvr {Backup variable} MT_STATUS
5609 The name of the function used to obtain the status of the archive device,
5610 including error count. Default definition:
5611
5612 @smallexample
5613 MT_STATUS=mt_status
5614
5615 mt_status() @{
5616 mt -f "$1" status
5617 @}
5618 @end smallexample
5619 @end defvr
5620
5621 @node User Hooks
5622 @subsection User Hooks
5623
5624 @dfn{User hooks} are shell functions executed before and after
5625 each @command{tar} invocation. Thus, there are @dfn{backup
5626 hooks}, which are executed before and after dumping each file
5627 system, and @dfn{restore hooks}, executed before and
5628 after restoring a file system. Each user hook is a shell function
5629 taking four arguments:
5630
5631 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5632 Its arguments are:
5633
5634 @table @var
5635 @item level
5636 Current backup or restore level.
5637
5638 @item host
5639 Name or IP address of the host machine being dumped or restored.
5640
5641 @item fs
5642 Full path name to the file system being dumped or restored.
5643
5644 @item fsname
5645 File system name with directory separators replaced with colons. This
5646 is useful, e.g., for creating unique files.
5647 @end table
5648 @end deffn
5649
5650 Following variables keep the names of user hook functions
5651
5652 @defvr {Backup variable} DUMP_BEGIN
5653 Dump begin function. It is executed before dumping the file system.
5654 @end defvr
5655
5656 @defvr {Backup variable} DUMP_END
5657 Executed after dumping the file system.
5658 @end defvr
5659
5660 @defvr {Backup variable} RESTORE_BEGIN
5661 Executed before restoring the file system.
5662 @end defvr
5663
5664 @defvr {Backup variable} RESTORE_END
5665 Executed after restoring the file system.
5666 @end defvr
5667
5668 @node backup-specs example
5669 @subsection An Example Text of @file{Backup-specs}
5670
5671 The following is an example of @file{backup-specs}:
5672
5673 @smallexample
5674 # site-specific parameters for file system backup.
5675
5676 ADMINISTRATOR=friedman
5677 BACKUP_HOUR=1
5678 TAPE_FILE=/dev/nrsmt0
5679
5680 # Use @code{ssh} instead of the less secure @code{rsh}
5681 RSH=/usr/bin/ssh
5682 RSH_COMMAND=/usr/bin/ssh
5683
5684 # Override MT_STATUS function:
5685 my_status() @{
5686 mts -t $TAPE_FILE
5687 @}
5688 MT_STATUS=my_status
5689
5690 # Disable MT_OFFLINE function
5691 MT_OFFLINE=:
5692
5693 BLOCKING=124
5694 BACKUP_DIRS="
5695 albert:/fs/fsf
5696 apple-gunkies:/gd
5697 albert:/fs/gd2
5698 albert:/fs/gp
5699 geech:/usr/jla
5700 churchy:/usr/roland
5701 albert:/
5702 albert:/usr
5703 apple-gunkies:/
5704 apple-gunkies:/usr
5705 gnu:/hack
5706 gnu:/u
5707 apple-gunkies:/com/mailer/gnu
5708 apple-gunkies:/com/archive/gnu"
5709
5710 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5711
5712 @end smallexample
5713
5714 @node Scripted Backups
5715 @section Using the Backup Scripts
5716
5717 The syntax for running a backup script is:
5718
5719 @smallexample
5720 backup --level=@var{level} --time=@var{time}
5721 @end smallexample
5722
5723 The @option{level} option requests the dump level. Thus, to produce
5724 a full dump, specify @code{--level=0} (this is the default, so
5725 @option{--level} may be omitted if its value is @code{0}).
5726 @footnote{For backward compatibility, the @code{backup} will also
5727 try to deduce the requested dump level from the name of the
5728 script itself. If the name consists of a string @samp{level-}
5729 followed by a single decimal digit, that digit is taken as
5730 the dump level number. Thus, you may create a link from @code{backup}
5731 to @code{level-1} and then run @code{level-1} whenever you need to
5732 create a level one dump.}
5733
5734 The @option{--time} option determines when should the backup be
5735 run. @var{Time} may take three forms:
5736
5737 @table @asis
5738 @item @var{hh}:@var{mm}
5739
5740 The dump must be run at @var{hh} hours @var{mm} minutes.
5741
5742 @item @var{hh}
5743
5744 The dump must be run at @var{hh} hours
5745
5746 @item now
5747
5748 The dump must be run immediately.
5749 @end table
5750
5751 You should start a script with a tape or disk mounted. Once you
5752 start a script, it prompts you for new tapes or disks as it
5753 needs them. Media volumes don't have to correspond to archive
5754 files --- a multi-volume archive can be started in the middle of a
5755 tape that already contains the end of another multi-volume archive.
5756 The @code{restore} script prompts for media by its archive volume,
5757 so to avoid an error message you should keep track of which tape
5758 (or disk) contains which volume of the archive (@pxref{Scripted
5759 Restoration}).
5760
5761 The backup scripts write two files on the file system. The first is a
5762 record file in @file{/etc/tar-backup/}, which is used by the scripts
5763 to store and retrieve information about which files were dumped. This
5764 file is not meant to be read by humans, and should not be deleted by
5765 them. @xref{Snapshot Files}, for a more detailed explanation of this
5766 file.
5767
5768 The second file is a log file containing the names of the file systems
5769 and files dumped, what time the backup was made, and any error
5770 messages that were generated, as well as how much space was left in
5771 the media volume after the last volume of the archive was written.
5772 You should check this log file after every backup. The file name is
5773 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5774 represents current date, and @var{n} represents current dump level number.
5775
5776 The script also prints the name of each system being dumped to the
5777 standard output.
5778
5779 Following is the full list of options accepted by @code{backup}
5780 script:
5781
5782 @table @option
5783 @item -l @var{level}
5784 @itemx --level=@var{level}
5785 Do backup level @var{level} (default 0).
5786
5787 @item -f
5788 @itemx --force
5789 Force backup even if today's log file already exists.
5790
5791 @item -v[@var{level}]
5792 @itemx --verbose[=@var{level}]
5793 Set verbosity level. The higher the level is, the more debugging
5794 information will be output during execution. Devault @var{level}
5795 is 100, which means the highest debugging level.
5796
5797 @item -t @var{start-time}
5798 @itemx --time=@var{start-time}
5799 Wait till @var{time}, then do backup.
5800
5801 @item -h
5802 @itemx --help
5803 Display short help message and exit.
5804
5805 @item -V
5806 @itemx --version
5807 Display information about the program's name, version, origin and legal
5808 status, all on standard output, and then exit successfully.
5809 @end table
5810
5811
5812 @node Scripted Restoration
5813 @section Using the Restore Script
5814
5815 To restore files that were archived using a scripted backup, use the
5816 @code{restore} script. Its usage is quite straightforward. In the
5817 simplest form, invoke @code{restore --all}, it will
5818 then restore all the file systems and files specified in
5819 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5820
5821 You may select the file systems (and/or files) to restore by
5822 giving @code{restore} list of @dfn{patterns} in its command
5823 line. For example, running
5824
5825 @smallexample
5826 restore 'albert:*'
5827 @end smallexample
5828
5829 @noindent
5830 will restore all file systems on the machine @samp{albert}. A more
5831 complicated example:
5832
5833 @smallexample
5834 restore 'albert:*' '*:/var'
5835 @end smallexample
5836
5837 @noindent
5838 This command will restore all file systems on the machine @samp{albert}
5839 as well as @file{/var} file system on all machines.
5840
5841 By default @code{restore} will start restoring files from the lowest
5842 available dump level (usually zero) and will continue through
5843 all available dump levels. There may be situations where such a
5844 thorough restore is not necessary. For example, you may wish to
5845 restore only files from the recent level one backup. To do so,
5846 use @option{--level} option, as shown in the example below:
5847
5848 @smallexample
5849 restore --level=1
5850 @end smallexample
5851
5852 The full list of options accepted by @code{restore} follows:
5853
5854 @table @option
5855 @item -a
5856 @itemx --all
5857 Restore all file systems and files specified in @file{backup-specs}
5858
5859 @item -l @var{level}
5860 @itemx --level=@var{level}
5861 Start restoring from the given backup level, instead of the default 0.
5862
5863 @item -v[@var{level}]
5864 @itemx --verbose[=@var{level}]
5865 Set verbosity level. The higher the level is, the more debugging
5866 information will be output during execution. Devault @var{level}
5867 is 100, which means the highest debugging level.
5868
5869 @item -h
5870 @itemx --help
5871 Display short help message and exit.
5872
5873 @item -V
5874 @itemx --version
5875 Display information about the program's name, version, origin and legal
5876 status, all on standard output, and then exit successfully.
5877 @end table
5878
5879 You should start the restore script with the media containing the
5880 first volume of the archive mounted. The script will prompt for other
5881 volumes as they are needed. If the archive is on tape, you don't need
5882 to rewind the tape to to its beginning---if the tape head is
5883 positioned past the beginning of the archive, the script will rewind
5884 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
5885 positioning.
5886
5887 @quotation
5888 @strong{Warning:} The script will delete files from the active file
5889 system if they were not in the file system when the archive was made.
5890 @end quotation
5891
5892 @xref{Incremental Dumps}, for an explanation of how the script makes
5893 that determination.
5894
5895 @node Choosing
5896 @chapter Choosing Files and Names for @command{tar}
5897 @UNREVISED
5898
5899 Certain options to @command{tar} enable you to specify a name for your
5900 archive. Other options let you decide which files to include or exclude
5901 from the archive, based on when or whether files were modified, whether
5902 the file names do or don't match specified patterns, or whether files
5903 are in specified directories.
5904
5905 This chapter discusses these options in detail.
5906
5907 @menu
5908 * file:: Choosing the Archive's Name
5909 * Selecting Archive Members::
5910 * files:: Reading Names from a File
5911 * exclude:: Excluding Some Files
5912 * wildcards:: Wildcards Patterns and Matching
5913 * quoting styles:: Ways of Quoting Special Characters in Names
5914 * transform:: Modifying File and Member Names
5915 * after:: Operating Only on New Files
5916 * recurse:: Descending into Directories
5917 * one:: Crossing File System Boundaries
5918 @end menu
5919
5920 @node file
5921 @section Choosing and Naming Archive Files
5922 @UNREVISED
5923
5924 @cindex Naming an archive
5925 @cindex Archive Name
5926 @cindex Choosing an archive file
5927 @cindex Where is the archive?
5928 By default, @command{tar} uses an archive file name that was compiled when
5929 it was built on the system; usually this name refers to some physical
5930 tape drive on the machine. However, the person who installed @command{tar}
5931 on the system may not have set the default to a meaningful value as far as
5932 most users are concerned. As a result, you will usually want to tell
5933 @command{tar} where to find (or create) the archive. The
5934 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
5935 option allows you to either specify or name a file to use as the archive
5936 instead of the default archive file location.
5937
5938 @table @option
5939 @xopindex{file, short description}
5940 @item --file=@var{archive-name}
5941 @itemx -f @var{archive-name}
5942 Name the archive to create or operate on. Use in conjunction with
5943 any operation.
5944 @end table
5945
5946 For example, in this @command{tar} command,
5947
5948 @smallexample
5949 $ @kbd{tar -cvf collection.tar blues folk jazz}
5950 @end smallexample
5951
5952 @noindent
5953 @file{collection.tar} is the name of the archive. It must directly
5954 follow the @option{-f} option, since whatever directly follows @option{-f}
5955 @emph{will} end up naming the archive. If you neglect to specify an
5956 archive name, you may end up overwriting a file in the working directory
5957 with the archive you create since @command{tar} will use this file's name
5958 for the archive name.
5959
5960 An archive can be saved as a file in the file system, sent through a
5961 pipe or over a network, or written to an I/O device such as a tape,
5962 floppy disk, or CD write drive.
5963
5964 @cindex Writing new archives
5965 @cindex Archive creation
5966 If you do not name the archive, @command{tar} uses the value of the
5967 environment variable @env{TAPE} as the file name for the archive. If
5968 that is not available, @command{tar} uses a default, compiled-in archive
5969 name, usually that for tape unit zero (i.e. @file{/dev/tu00}).
5970
5971 @cindex Standard input and output
5972 @cindex tar to standard input and output
5973 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
5974 archive from standard input (when listing or extracting files), or
5975 writes it to standard output (when creating an archive). If you use
5976 @file{-} as an @var{archive-name} when modifying an archive,
5977 @command{tar} reads the original archive from its standard input and
5978 writes the entire new archive to its standard output.
5979
5980 The following example is a convenient way of copying directory
5981 hierarchy from @file{sourcedir} to @file{targetdir}.
5982
5983 @smallexample
5984 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
5985 @end smallexample
5986
5987 The @option{-C} option allows to avoid using subshells:
5988
5989 @smallexample
5990 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
5991 @end smallexample
5992
5993 In both examples above, the leftmost @command{tar} invocation archives
5994 the contents of @file{sourcedir} to the standard output, while the
5995 rightmost one reads this archive from its standard input and
5996 extracts it. The @option{-p} option tells it to restore permissions
5997 of the extracted files.
5998
5999 @cindex Remote devices
6000 @cindex tar to a remote device
6001 @anchor{remote-dev}
6002 To specify an archive file on a device attached to a remote machine,
6003 use the following:
6004
6005 @smallexample
6006 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6007 @end smallexample
6008
6009 @noindent
6010 @command{tar} will complete the remote connection, if possible, and
6011 prompt you for a username and password. If you use
6012 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6013 will complete the remote connection, if possible, using your username
6014 as the username on the remote machine.
6015
6016 @cindex Local and remote archives
6017 @anchor{local and remote archives}
6018 If the archive file name includes a colon (@samp{:}), then it is assumed
6019 to be a file on another machine. If the archive file is
6020 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6021 host @var{host}. The remote host is accessed using the @command{rsh}
6022 program, with a username of @var{user}. If the username is omitted
6023 (along with the @samp{@@} sign), then your user name will be used.
6024 (This is the normal @command{rsh} behavior.) It is necessary for the
6025 remote machine, in addition to permitting your @command{rsh} access, to
6026 have the @file{rmt} program installed (This command is included in
6027 the @GNUTAR{} distribution and by default is installed under
6028 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6029 installation prefix). If you need to use a file whose name includes a
6030 colon, then the remote tape drive behavior
6031 can be inhibited by using the @option{--force-local} option.
6032
6033 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6034 tries to minimize input and output operations. The Amanda backup
6035 system, when used with @GNUTAR{}, has an initial sizing pass which
6036 uses this feature.
6037
6038 @node Selecting Archive Members
6039 @section Selecting Archive Members
6040 @cindex Specifying files to act on
6041 @cindex Specifying archive members
6042
6043 @dfn{File Name arguments} specify which files in the file system
6044 @command{tar} operates on, when creating or adding to an archive, or which
6045 archive members @command{tar} operates on, when reading or deleting from
6046 an archive. @xref{Operations}.
6047
6048 To specify file names, you can include them as the last arguments on
6049 the command line, as follows:
6050 @smallexample
6051 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6052 @end smallexample
6053
6054 If a file name begins with dash (@samp{-}), precede it with
6055 @option{--add-file} option to prevent it from being treated as an
6056 option.
6057
6058 @anchor{input name quoting}
6059 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6060 name, replacing @dfn{escape sequences} according to the following
6061 table:
6062
6063 @multitable @columnfractions 0.20 0.60
6064 @headitem Escape @tab Replaced with
6065 @item \a @tab Audible bell (ASCII 7)
6066 @item \b @tab Backspace (ASCII 8)
6067 @item \f @tab Form feed (ASCII 12)
6068 @item \n @tab New line (ASCII 10)
6069 @item \r @tab Carriage return (ASCII 13)
6070 @item \t @tab Horizontal tabulation (ASCII 9)
6071 @item \v @tab Vertical tabulation (ASCII 11)
6072 @item \? @tab ASCII 127
6073 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6074 of up to 3 digits)
6075 @end multitable
6076
6077 A backslash followed by any other symbol is retained.
6078
6079 This default behavior is controlled by the following command line
6080 option:
6081
6082 @table @option
6083 @opindex unquote
6084 @item --unquote
6085 Enable unquoting input file or member names (default).
6086
6087 @opindex no-unquote
6088 @item --no-unquote
6089 Disable unquoting input file or member names.
6090 @end table
6091
6092 If you specify a directory name as a file name argument, all the files
6093 in that directory are operated on by @command{tar}.
6094
6095 If you do not specify files, @command{tar} behavior differs depending
6096 on the operation mode as described below:
6097
6098 When @command{tar} is invoked with @option{--create} (@option{-c}),
6099 @command{tar} will stop immediately, reporting the following:
6100
6101 @smallexample
6102 @group
6103 $ @kbd{tar cf a.tar}
6104 tar: Cowardly refusing to create an empty archive
6105 Try `tar --help' or `tar --usage' for more information.
6106 @end group
6107 @end smallexample
6108
6109 If you specify either @option{--list} (@option{-t}) or
6110 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6111 operates on all the archive members in the archive.
6112
6113 If run with @option{--diff} option, tar will compare the archive with
6114 the contents of the current working directory.
6115
6116 If you specify any other operation, @command{tar} does nothing.
6117
6118 By default, @command{tar} takes file names from the command line. However,
6119 there are other ways to specify file or member names, or to modify the
6120 manner in which @command{tar} selects the files or members upon which to
6121 operate. In general, these methods work both for specifying the names
6122 of files and archive members.
6123
6124 @node files
6125 @section Reading Names from a File
6126
6127 @cindex Reading file names from a file
6128 @cindex Lists of file names
6129 @cindex File Name arguments, alternatives
6130 Instead of giving the names of files or archive members on the command
6131 line, you can put the names into a file, and then use the
6132 @option{--files-from=@var{file-of-names}} (@option{-T
6133 @var{file-of-names}}) option to @command{tar}. Give the name of the
6134 file which contains the list of files to include as the argument to
6135 @option{--files-from}. In the list, the file names should be separated by
6136 newlines. You will frequently use this option when you have generated
6137 the list of files to archive with the @command{find} utility.
6138
6139 @table @option
6140 @opindex files-from
6141 @item --files-from=@var{file-name}
6142 @itemx -T @var{file-name}
6143 Get names to extract or create from file @var{file-name}.
6144 @end table
6145
6146 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6147 you specify either @code{--files-from=-} or @code{-T -}), then the file
6148 names are read from standard input.
6149
6150 Unless you are running @command{tar} with @option{--create}, you can not use
6151 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6152 command.
6153
6154 Any number of @option{-T} options can be given in the command line.
6155
6156 The following example shows how to use @command{find} to generate a list of
6157 files smaller than 400K in length and put that list into a file
6158 called @file{small-files}. You can then use the @option{-T} option to
6159 @command{tar} to specify the files from that file, @file{small-files}, to
6160 create the archive @file{little.tgz}. (The @option{-z} option to
6161 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6162 more information.)
6163
6164 @smallexample
6165 $ @kbd{find . -size -400 -print > small-files}
6166 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6167 @end smallexample
6168
6169 @noindent
6170 In the file list given by @option{-T} option, any file name beginning
6171 with @samp{-} character is considered a @command{tar} option and is
6172 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6173 recognized only @option{-C} option in file lists, and only if the
6174 option and its argument occupied two consecutive lines.} For example,
6175 the common use of this feature is to change to another directory by
6176 specifying @option{-C} option:
6177
6178 @smallexample
6179 @group
6180 $ @kbd{cat list}
6181 -C/etc
6182 passwd
6183 hosts
6184 -C/lib
6185 libc.a
6186 $ @kbd{tar -c -f foo.tar --files-from list}
6187 @end group
6188 @end smallexample
6189
6190 @noindent
6191 In this example, @command{tar} will first switch to @file{/etc}
6192 directory and add files @file{passwd} and @file{hosts} to the
6193 archive. Then it will change to @file{/lib} directory and will archive
6194 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6195 contain:
6196
6197 @smallexample
6198 @group
6199 $ @kbd{tar tf foo.tar}
6200 passwd
6201 hosts
6202 libc.a
6203 @end group
6204 @end smallexample
6205
6206 @noindent
6207 @xopindex{directory, using in @option{--files-from} argument}
6208 Notice that the option parsing algorithm used with @option{-T} is
6209 stricter than the one used by shell. Namely, when specifying option
6210 arguments, you should observe the following rules:
6211
6212 @itemize @bullet
6213 @item
6214 When using short (single-letter) option form, its argument must
6215 immediately follow the option letter, without any intervening
6216 whitespace. For example: @code{-Cdir}.
6217
6218 @item
6219 When using long option form, the option argument must be separated
6220 from the option by a single equal sign. No whitespace is allowed on
6221 any side of the equal sign. For example: @code{--directory=dir}.
6222
6223 @item
6224 For both short and long option forms, the option argument can be given
6225 on the next line after the option name, e.g.:
6226
6227 @smallexample
6228 @group
6229 --directory
6230 dir
6231 @end group
6232 @end smallexample
6233
6234 @noindent
6235 and
6236
6237 @smallexample
6238 @group
6239 -C
6240 dir
6241 @end group
6242 @end smallexample
6243 @end itemize
6244
6245 @opindex add-file
6246 If you happen to have a file whose name starts with @samp{-},
6247 precede it with @option{--add-file} option to prevent it from
6248 being recognized as an option. For example: @code{--add-file=--my-file}.
6249
6250 @menu
6251 * nul::
6252 @end menu
6253
6254 @node nul
6255 @subsection @code{NUL} Terminated File Names
6256
6257 @cindex File names, terminated by @code{NUL}
6258 @cindex @code{NUL} terminated file names
6259 The @option{--null} option causes
6260 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6261 to read file names terminated by a @code{NUL} instead of a newline, so
6262 files whose names contain newlines can be archived using
6263 @option{--files-from}.
6264
6265 @table @option
6266 @opindex null
6267 @item --null
6268 Only consider @code{NUL} terminated file names, instead of files that
6269 terminate in a newline.
6270 @end table
6271
6272 The @option{--null} option is just like the one in @acronym{GNU}
6273 @command{xargs} and @command{cpio}, and is useful with the
6274 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6275 @command{tar}, @option{--null} also disables special handling for
6276 file names that begin with dash.
6277
6278 This example shows how to use @command{find} to generate a list of files
6279 larger than 800K in length and put that list into a file called
6280 @file{long-files}. The @option{-print0} option to @command{find} is just
6281 like @option{-print}, except that it separates files with a @code{NUL}
6282 rather than with a newline. You can then run @command{tar} with both the
6283 @option{--null} and @option{-T} options to specify that @command{tar} get the
6284 files from that file, @file{long-files}, to create the archive
6285 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6286 @command{tar} to recognize the @code{NUL} separator between files.
6287
6288 @smallexample
6289 $ @kbd{find . -size +800 -print0 > long-files}
6290 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6291 @end smallexample
6292
6293 @FIXME{say anything else here to conclude the section?}
6294
6295 @node exclude
6296 @section Excluding Some Files
6297 @UNREVISED
6298
6299 @cindex File names, excluding files by
6300 @cindex Excluding files by name and pattern
6301 @cindex Excluding files by file system
6302 To avoid operating on files whose names match a particular pattern,
6303 use the @option{--exclude} or @option{--exclude-from} options.
6304
6305 @table @option
6306 @opindex exclude
6307 @item --exclude=@var{pattern}
6308 Causes @command{tar} to ignore files that match the @var{pattern}.
6309 @end table
6310
6311 @findex exclude
6312 The @option{--exclude=@var{pattern}} option prevents any file or
6313 member whose name matches the shell wildcard (@var{pattern}) from
6314 being operated on.
6315 For example, to create an archive with all the contents of the directory
6316 @file{src} except for files whose names end in @file{.o}, use the
6317 command @samp{tar -cf src.tar --exclude='*.o' src}.
6318
6319 You may give multiple @option{--exclude} options.
6320
6321 @table @option
6322 @opindex exclude-from
6323 @item --exclude-from=@var{file}
6324 @itemx -X @var{file}
6325 Causes @command{tar} to ignore files that match the patterns listed in
6326 @var{file}.
6327 @end table
6328
6329 @findex exclude-from
6330 Use the @option{--exclude-from} option to read a
6331 list of patterns, one per line, from @var{file}; @command{tar} will
6332 ignore files matching those patterns. Thus if @command{tar} is
6333 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6334 single line @file{*.o}, no files whose names end in @file{.o} will be
6335 added to the archive.
6336
6337 @table @option
6338 @opindex exclude-caches
6339 @item --exclude-caches
6340 Causes @command{tar} to ignore directories containing a cache directory tag.
6341 @end table
6342
6343 @findex exclude-caches
6344 When creating an archive, the @option{--exclude-caches} option causes
6345 @command{tar} to exclude all directories that contain a @dfn{cache
6346 directory tag}. A cache directory tag is a short file with the
6347 well-known name @file{CACHEDIR.TAG} and having a standard header
6348 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6349 Various applications write cache directory tags into directories they
6350 use to hold regenerable, non-precious data, so that such data can be
6351 more easily excluded from backups.
6352
6353 @menu
6354 * problems with exclude::
6355 @end menu
6356
6357 @node problems with exclude
6358 @unnumberedsubsec Problems with Using the @code{exclude} Options
6359
6360 @xopindex{exclude, potential problems with}
6361 Some users find @samp{exclude} options confusing. Here are some common
6362 pitfalls:
6363
6364 @itemize @bullet
6365 @item
6366 The main operating mode of @command{tar} does not act on a path name
6367 explicitly listed on the command line if one of its file name
6368 components is excluded. In the example above, if
6369 you create an archive and exclude files that end with @samp{*.o}, but
6370 explicitly name the file @samp{dir.o/foo} after all the options have been
6371 listed, @samp{dir.o/foo} will be excluded from the archive.
6372
6373 @item
6374 You can sometimes confuse the meanings of @option{--exclude} and
6375 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6376 to be excluded are given as a pattern on the command line. Use
6377 @option{--exclude-from} to introduce the name of a file which contains
6378 a list of patterns, one per line; each of these patterns can exclude
6379 zero, one, or many files.
6380
6381 @item
6382 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6383 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6384 like @samp{*}. If you do not do this, the shell might expand the
6385 @samp{*} itself using files at hand, so @command{tar} might receive a
6386 list of files instead of one pattern, or none at all, making the
6387 command somewhat illegal. This might not correspond to what you want.
6388
6389 For example, write:
6390
6391 @smallexample
6392 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6393 @end smallexample
6394
6395 @noindent
6396 rather than:
6397
6398 @smallexample
6399 # @emph{Wrong!}
6400 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6401 @end smallexample
6402
6403 @item
6404 You must use use shell syntax, or globbing, rather than @code{regexp}
6405 syntax, when using exclude options in @command{tar}. If you try to use
6406 @code{regexp} syntax to describe files to be excluded, your command
6407 might fail.
6408
6409 @item
6410 @FIXME{The change in semantics must have occurred before 1.11,
6411 so I doubt if it is worth mentioning at all. Anyway, should at
6412 least specify in which version the semantics changed.}
6413 In earlier versions of @command{tar}, what is now the
6414 @option{--exclude-from} option was called @option{--exclude} instead.
6415 Now, @option{--exclude} applies to patterns listed on the command
6416 line and @option{--exclude-from} applies to patterns listed in a
6417 file.
6418
6419 @end itemize
6420
6421 @node wildcards
6422 @section Wildcards Patterns and Matching
6423
6424 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6425 @samp{*} or @samp{?} for example, are replaced and expanded into all
6426 existing files matching the given pattern. @GNUTAR{} can use wildcard
6427 patterns for matching (or globbing) archive members when extracting
6428 from or listing an archive. Wildcard patterns are also used for
6429 verifying volume labels of @command{tar} archives. This section has the
6430 purpose of explaining wildcard syntax for @command{tar}.
6431
6432 @FIXME{the next few paragraphs need work.}
6433
6434 A @var{pattern} should be written according to shell syntax, using wildcard
6435 characters to effect globbing. Most characters in the pattern stand
6436 for themselves in the matched string, and case is significant: @samp{a}
6437 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6438 pattern matches any single character in the matched string. The character
6439 @samp{*} in the pattern matches zero, one, or more single characters in
6440 the matched string. The character @samp{\} says to take the following
6441 character of the pattern @emph{literally}; it is useful when one needs to
6442 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6443
6444 The character @samp{[}, up to the matching @samp{]}, introduces a character
6445 class. A @dfn{character class} is a list of acceptable characters
6446 for the next single character of the matched string. For example,
6447 @samp{[abcde]} would match any of the first five letters of the alphabet.
6448 Note that within a character class, all of the ``special characters''
6449 listed above other than @samp{\} lose their special meaning; for example,
6450 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6451 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6452 the characters @samp{-} and @samp{]} must either come @emph{first} or
6453 @emph{last} in a character class.)
6454
6455 @cindex Excluding characters from a character class
6456 @cindex Character class, excluding characters from
6457 If the first character of the class after the opening @samp{[}
6458 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6459 Rather than listing character to match, it lists those characters which
6460 are @emph{forbidden} as the next single character of the matched string.
6461
6462 Other characters of the class stand for themselves. The special
6463 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6464 letters, is meant to represent all characters between @var{a} and
6465 @var{e}, inclusive.
6466
6467 @FIXME{need to add a sentence or so here to make this clear for those
6468 who don't have dan around.}
6469
6470 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6471 special for wildcard matches. However, if a pattern completely matches
6472 a directory prefix of a matched string, then it matches the full matched
6473 string: thus, excluding a directory also excludes all the files beneath it.
6474
6475 @menu
6476 * controlling pattern-matching::
6477 @end menu
6478
6479 @node controlling pattern-matching
6480 @unnumberedsubsec Controlling Pattern-Matching
6481
6482 For the purposes of this section, we call @dfn{exclusion members} all
6483 member names obtained while processing @option{--exclude} and
6484 @option{--exclude-from} options, and @dfn{inclusion members} those
6485 member names that were given in the command line or read from the file
6486 specified with @option{--files-from} option.
6487
6488 These two pairs of member lists are used in the following operations:
6489 @option{--diff}, @option{--extract}, @option{--list},
6490 @option{--update}.
6491
6492 There are no inclusion members in create mode (@option{--create} and
6493 @option{--append}), since in this mode the names obtained from the
6494 command line refer to @emph{files}, not archive members.
6495
6496 By default, inclusion members are compared with archive members
6497 literally @footnote{Notice that earlier @GNUTAR{} versions used
6498 globbing for inclusion members, which contradicted to UNIX98
6499 specification and was not documented. @xref{Changes}, for more
6500 information on this and other changes.} and exclusion members are
6501 treated as globbing patterns. For example:
6502
6503 @smallexample
6504 @group
6505 $ @kbd{tar tf foo.tar}
6506 a.c
6507 b.c
6508 a.txt
6509 [remarks]
6510 # @i{Member names are used verbatim:}
6511 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6512 [remarks]
6513 # @i{Exclude member names are globbed:}
6514 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6515 a.txt
6516 [remarks]
6517 @end group
6518 @end smallexample
6519
6520 This behavior can be altered by using the following options:
6521
6522 @table @option
6523 @opindex wildcards
6524 @item --wildcards
6525 Treat all member names as wildcards.
6526
6527 @opindex no-wildcards
6528 @item --no-wildcards
6529 Treat all member names as literal strings.
6530 @end table
6531
6532 Thus, to extract files whose names end in @samp{.c}, you can use:
6533
6534 @smallexample
6535 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6536 a.c
6537 b.c
6538 @end smallexample
6539
6540 @noindent
6541 Notice quoting of the pattern to prevent the shell from interpreting
6542 it.
6543
6544 The effect of @option{--wildcards} option is cancelled by
6545 @option{--no-wildcards}. This can be used to pass part of
6546 the command line arguments verbatim and other part as globbing
6547 patterns. For example, the following invocation:
6548
6549 @smallexample
6550 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6551 @end smallexample
6552
6553 @noindent
6554 instructs @command{tar} to extract from @file{foo.tar} all files whose
6555 names end in @samp{.txt} and the file named @file{[remarks]}.
6556
6557 Normally, a pattern matches a name if an initial subsequence of the
6558 name's components matches the pattern, where @samp{*}, @samp{?}, and
6559 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6560 and wildcards can match @samp{/}.
6561
6562 Other than optionally stripping leading @samp{/} from names
6563 (@pxref{absolute}), patterns and names are used as-is. For
6564 example, trailing @samp{/} is not trimmed from a user-specified name
6565 before deciding whether to exclude it.
6566
6567 However, this matching procedure can be altered by the options listed
6568 below. These options accumulate. For example:
6569
6570 @smallexample
6571 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6572 @end smallexample
6573
6574 @noindent
6575 ignores case when excluding @samp{makefile}, but not when excluding
6576 @samp{readme}.
6577
6578 @table @option
6579 @opindex anchored
6580 @opindex no-anchored
6581 @item --anchored
6582 @itemx --no-anchored
6583 If anchored, a pattern must match an initial subsequence
6584 of the name's components. Otherwise, the pattern can match any
6585 subsequence. Default is @option{--no-anchored} for exclusion members
6586 and @option{--anchored} inclusion members.
6587
6588 @opindex ignore-case
6589 @opindex no-ignore-case
6590 @item --ignore-case
6591 @itemx --no-ignore-case
6592 When ignoring case, upper-case patterns match lower-case names and vice versa.
6593 When not ignoring case (the default), matching is case-sensitive.
6594
6595 @opindex wildcards-match-slash
6596 @opindex no-wildcards-match-slash
6597 @item --wildcards-match-slash
6598 @itemx --no-wildcards-match-slash
6599 When wildcards match slash (the default for exclusion members), a
6600 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6601 name. Otherwise, @samp{/} is matched only by @samp{/}.
6602
6603 @end table
6604
6605 The @option{--recursion} and @option{--no-recursion} options
6606 (@pxref{recurse}) also affect how member patterns are interpreted. If
6607 recursion is in effect, a pattern matches a name if it matches any of
6608 the name's parent directories.
6609
6610 The following table summarizes pattern-matching default values:
6611
6612 @multitable @columnfractions .3 .7
6613 @headitem Members @tab Default settings
6614 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6615 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6616 @end multitable
6617
6618 @node quoting styles
6619 @section Quoting Member Names
6620
6621 When displaying member names, @command{tar} takes care to avoid
6622 ambiguities caused by certain characters. This is called @dfn{name
6623 quoting}. The characters in question are:
6624
6625 @itemize @bullet
6626 @item Non-printable control characters:
6627
6628 @multitable @columnfractions 0.20 0.10 0.60
6629 @headitem Character @tab ASCII @tab Character name
6630 @item \a @tab 7 @tab Audible bell
6631 @item \b @tab 8 @tab Backspace
6632 @item \f @tab 12 @tab Form feed
6633 @item \n @tab 10 @tab New line
6634 @item \r @tab 13 @tab Carriage return
6635 @item \t @tab 9 @tab Horizontal tabulation
6636 @item \v @tab 11 @tab Vertical tabulation
6637 @end multitable
6638
6639 @item Space (ASCII 32)
6640
6641 @item Single and double quotes (@samp{'} and @samp{"})
6642
6643 @item Backslash (@samp{\})
6644 @end itemize
6645
6646 The exact way @command{tar} uses to quote these characters depends on
6647 the @dfn{quoting style}. The default quoting style, called
6648 @dfn{escape} (see below), uses backslash notation to represent control
6649 characters, space and backslash. Using this quoting style, control
6650 characters are represented as listed in column @samp{Character} in the
6651 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6652
6653 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6654 using @option{--quoting-style} option:
6655
6656 @table @option
6657 @item --quoting-style=@var{style}
6658 @opindex quoting-style
6659
6660 Sets quoting style. Valid values for @var{style} argument are:
6661 literal, shell, shell-always, c, escape, locale, clocale.
6662 @end table
6663
6664 These styles are described in detail below. To illustrate their
6665 effect, we will use an imaginary tar archive @file{arch.tar}
6666 containing the following members:
6667
6668 @smallexample
6669 @group
6670 # 1. Contains horizontal tabulation character.
6671 a tab
6672 # 2. Contains newline character
6673 a
6674 newline
6675 # 3. Contains a space
6676 a space
6677 # 4. Contains double quotes
6678 a"double"quote
6679 # 5. Contains single quotes
6680 a'single'quote
6681 # 6. Contains a backslash character:
6682 a\backslash
6683 @end group
6684 @end smallexample
6685
6686 Here is how usual @command{ls} command would have listed them, if they
6687 had existed in the current working directory:
6688
6689 @smallexample
6690 @group
6691 $ @kbd{ls}
6692 a\ttab
6693 a\nnewline
6694 a\ space
6695 a"double"quote
6696 a'single'quote
6697 a\\backslash
6698 @end group
6699 @end smallexample
6700
6701 Quoting styles:
6702
6703 @table @samp
6704 @item literal
6705 No quoting, display each character as is:
6706
6707 @smallexample
6708 @group
6709 $ @kbd{tar tf arch.tar --quoting-style=literal}
6710 ./
6711 ./a space
6712 ./a'single'quote
6713 ./a"double"quote
6714 ./a\backslash
6715 ./a tab
6716 ./a
6717 newline
6718 @end group
6719 @end smallexample
6720
6721 @item shell
6722 Display characters the same way Bourne shell does:
6723 control characters, except @samp{\t} and @samp{\n}, are printed using
6724 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6725 single quote is printed as @samp{\'}. If a name contains any quoted
6726 characters, it is enclosed in single quotes. In particular, if a name
6727 contains single quotes, it is printed as several single-quoted strings:
6728
6729 @smallexample
6730 @group
6731 $ @kbd{tar tf arch.tar --quoting-style=shell}
6732 ./
6733 './a space'
6734 './a'\''single'\''quote'
6735 './a"double"quote'
6736 './a\backslash'
6737 './a tab'
6738 './a
6739 newline'
6740 @end group
6741 @end smallexample
6742
6743 @item shell-always
6744 Same as @samp{shell}, but the names are always enclosed in single
6745 quotes:
6746
6747 @smallexample
6748 @group
6749 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6750 './'
6751 './a space'
6752 './a'\''single'\''quote'
6753 './a"double"quote'
6754 './a\backslash'
6755 './a tab'
6756 './a
6757 newline'
6758 @end group
6759 @end smallexample
6760
6761 @item c
6762 Use the notation of the C programming language. All names are
6763 enclosed in double quotes. Control characters are quoted using
6764 backslash notations, double quotes are represented as @samp{\"},
6765 backslash characters are represented as @samp{\\}. Single quotes and
6766 spaces are not quoted:
6767
6768 @smallexample
6769 @group
6770 $ @kbd{tar tf arch.tar --quoting-style=c}
6771 "./"
6772 "./a space"
6773 "./a'single'quote"
6774 "./a\"double\"quote"
6775 "./a\\backslash"
6776 "./a\ttab"
6777 "./a\nnewline"
6778 @end group
6779 @end smallexample
6780
6781 @item escape
6782 Control characters are printed using backslash notation, a space is
6783 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6784 default quoting style, unless it was changed when configured the
6785 package.
6786
6787 @smallexample
6788 @group
6789 $ @kbd{tar tf arch.tar --quoting-style=escape}
6790 ./
6791 ./a space
6792 ./a'single'quote
6793 ./a"double"quote
6794 ./a\\backslash
6795 ./a\ttab
6796 ./a\nnewline
6797 @end group
6798 @end smallexample
6799
6800 @item locale
6801 Control characters, single quote and backslash are printed using
6802 backslash notation. All names are quoted using left and right
6803 quotation marks, appropriate to the current locale. If it does not
6804 define quotation marks, use @samp{`} as left and @samp{'} as right
6805 quotation marks. Any occurrences of the right quotation mark in a
6806 name are escaped with @samp{\}, for example:
6807
6808 For example:
6809
6810 @smallexample
6811 @group
6812 $ @kbd{tar tf arch.tar --quoting-style=locale}
6813 `./'
6814 `./a space'
6815 `./a\'single\'quote'
6816 `./a"double"quote'
6817 `./a\\backslash'
6818 `./a\ttab'
6819 `./a\nnewline'
6820 @end group
6821 @end smallexample
6822
6823 @item clocale
6824 Same as @samp{locale}, but @samp{"} is used for both left and right
6825 quotation marks, if not provided by the currently selected locale:
6826
6827 @smallexample
6828 @group
6829 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6830 "./"
6831 "./a space"
6832 "./a'single'quote"
6833 "./a\"double\"quote"
6834 "./a\\backslash"
6835 "./a\ttab"
6836 "./a\nnewline"
6837 @end group
6838 @end smallexample
6839 @end table
6840
6841 You can specify which characters should be quoted in addition to those
6842 implied by the current quoting style:
6843
6844 @table @option
6845 @item --quote-chars=@var{string}
6846 Always quote characters from @var{string}, even if the selected
6847 quoting style would not quote them.
6848 @end table
6849
6850 For example, using @samp{escape} quoting (compare with the usual
6851 escape listing above):
6852
6853 @smallexample
6854 @group
6855 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6856 ./
6857 ./a\ space
6858 ./a'single'quote
6859 ./a\"double\"quote
6860 ./a\\backslash
6861 ./a\ttab
6862 ./a\nnewline
6863 @end group
6864 @end smallexample
6865
6866 To disable quoting of such additional characters, use the following
6867 option:
6868
6869 @table @option
6870 @item --no-quote-chars=@var{string}
6871 Remove characters listed in @var{string} from the list of quoted
6872 characters set by the previous @option{--quote-chars} option.
6873 @end table
6874
6875 This option is particularly useful if you have added
6876 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6877 and wish to disable it for the current invocation.
6878
6879 Note, that @option{--no-quote-chars} does @emph{not} disable those
6880 characters that are quoted by default in the selected quoting style.
6881
6882 @node transform
6883 @section Modifying File and Member Names
6884
6885 @command{Tar} archives contain detailed information about files stored
6886 in them and full file names are part of that information. When
6887 storing file to an archive, its file name is recorded in the archive
6888 along with the actual file contents. When restoring from an archive,
6889 a file is created on disk with exactly the same name as that stored
6890 in the archive. In the majority of cases this is the desired behavior
6891 of a file archiver. However, there are some cases when it is not.
6892
6893 First of all, it is often unsafe to extract archive members with
6894 absolute file names or those that begin with a @file{../}. @GNUTAR{}
6895 takes special precautions when extracting such names and provides a
6896 special option for handling them, which is described in
6897 @ref{absolute}.
6898
6899 Secondly, you may wish to extract file names without some leading
6900 directory components, or with otherwise modified names. In other
6901 cases it is desirable to store files under differing names in the
6902 archive.
6903
6904 @GNUTAR{} provides two options for these needs.
6905
6906 @table @option
6907 @opindex strip-components
6908 @item --strip-components=@var{number}
6909 Strip given @var{number} of leading components from file names before
6910 extraction.
6911 @end table
6912
6913 For example, suppose you have archived whole @file{/usr} hierarchy to
6914 a tar archive named @file{usr.tar}. Among other files, this archive
6915 contains @file{usr/include/stdlib.h}, which you wish to extract to
6916 the current working directory. To do so, you type:
6917
6918 @smallexample
6919 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
6920 @end smallexample
6921
6922 The option @option{--strip=2} instructs @command{tar} to strip the
6923 two leading components (@file{usr/} and @file{include/}) off the file
6924 name.
6925
6926 If you add to the above invocation @option{--verbose} (@option{-v})
6927 option, you will note that the verbose listing still contains the
6928 full file name, with the two removed components still in place. This
6929 can be inconvenient, so @command{tar} provides a special option for
6930 altering this behavior:
6931
6932 @anchor{show-transformed-names}
6933 @table @option
6934 @opindex show-transformed-names
6935 @item --show-transformed-names
6936 Display file or member names with all requested transformations
6937 applied.
6938 @end table
6939
6940 @noindent
6941 For example:
6942
6943 @smallexample
6944 @group
6945 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
6946 usr/include/stdlib.h
6947 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
6948 stdlib.h
6949 @end group
6950 @end smallexample
6951
6952 Notice that in both cases the file is @file{stdlib.h} extracted to the
6953 current working directory, @option{--show-transformed-names} affects
6954 only the way its name is displayed.
6955
6956 This option is especially useful for verifying whether the invocation
6957 will have the desired effect. Thus, before running
6958
6959 @smallexample
6960 $ @kbd{tar -x --strip=@var{n}}
6961 @end smallexample
6962
6963 @noindent
6964 it is often advisable to run
6965
6966 @smallexample
6967 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
6968 @end smallexample
6969
6970 @noindent
6971 to make sure the command will produce the intended results.
6972
6973 In case you need to apply more complex modifications to the file name,
6974 @GNUTAR{} provides a general-purpose transformation option:
6975
6976 @table @option
6977 @opindex transform
6978 @item --transform=@var{expression}
6979 Modify file names using supplied @var{expression}.
6980 @end table
6981
6982 @noindent
6983 The @var{expression} is a @command{sed}-like replace expression of the
6984 form:
6985
6986 @smallexample
6987 s/@var{regexp}/@var{replace}/[@var{flags}]
6988 @end smallexample
6989
6990 @noindent
6991 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
6992 replacement for each file name part that matches @var{regexp}. Both
6993 @var{regexp} and @var{replace} are described in detail in
6994 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
6995
6996 Supported @var{flags} are:
6997
6998 @table @samp
6999 @item g
7000 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7001 just the first.
7002
7003 @item i
7004 Use case-insensitive matching
7005
7006 @item x
7007 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7008 regexps, Extended regular expressions, Extended regular expressions,
7009 sed, GNU sed}).
7010
7011 @item @var{number}
7012 Only replace the @var{number}th match of the @var{regexp}.
7013
7014 Note: the @var{posix} standard does not specify what should happen
7015 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7016 follows the GNU @command{sed} implementation in this regard, so
7017 the the interaction is defined to be: ignore matches before the
7018 @var{number}th, and then match and replace all matches from the
7019 @var{number}th on.
7020
7021 @end table
7022
7023 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7024 that it be used consistently throughout the expression. For example,
7025 the following two expressions are equivalent:
7026
7027 @smallexample
7028 @group
7029 s/one/two/
7030 s,one,two,
7031 @end group
7032 @end smallexample
7033
7034 Changing delimiters is often useful when the @var{regex} contains
7035 slashes. For example, it is more convenient to write @code{s,/,-,} than
7036 @code{s/\//-/}.
7037
7038 Here are several examples of @option{--transform} usage:
7039
7040 @enumerate
7041 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7042
7043 @smallexample
7044 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7045 @end smallexample
7046
7047 @item Strip two leading directory components (equivalent to
7048 @option{--strip-components=2}):
7049
7050 @smallexample
7051 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7052 @end smallexample
7053
7054 @item Prepend @file{/prefix/} to each file name:
7055
7056 @smallexample
7057 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7058 @end smallexample
7059
7060 @item Convert each file name to lower case:
7061
7062 @smallexample
7063 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7064 @end smallexample
7065
7066 @end enumerate
7067
7068 Unlike @option{--strip-components}, @option{--transform} can be used
7069 in any @GNUTAR{} operation mode. For example, the following command
7070 adds files to the archive while replacing the leading @file{usr/}
7071 component with @file{var/}:
7072
7073 @smallexample
7074 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7075 @end smallexample
7076
7077 To test @option{--transform} effect we suggest using
7078 @option{--show-transformed-names} option:
7079
7080 @smallexample
7081 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7082 --verbose --show-transformed-names /}
7083 @end smallexample
7084
7085 If both @option{--strip-components} and @option{--transform} are used
7086 together, then @option{--transform} is applied first, and the required
7087 number of components is then stripped from its result.
7088
7089 @node after
7090 @section Operating Only on New Files
7091 @UNREVISED
7092
7093 @cindex Excluding file by age
7094 @cindex Data Modification time, excluding files by
7095 @cindex Modification time, excluding files by
7096 @cindex Age, excluding files by
7097 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7098 @option{-N @var{date}}) option causes @command{tar} to only work on
7099 files whose data modification or status change times are newer than
7100 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7101 it is taken to be a file name; the data modification time of that file
7102 is used as the date. If you use this option when creating or appending
7103 to an archive, the archive will only include new files. If you use
7104 @option{--after-date} when extracting an archive, @command{tar} will
7105 only extract files newer than the @var{date} you specify.
7106
7107 If you only want @command{tar} to make the date comparison based on
7108 modification of the file's data (rather than status
7109 changes), then use the @option{--newer-mtime=@var{date}} option.
7110
7111 You may use these options with any operation. Note that these options
7112 differ from the @option{--update} (@option{-u}) operation in that they
7113 allow you to specify a particular date against which @command{tar} can
7114 compare when deciding whether or not to archive the files.
7115
7116 @table @option
7117 @opindex after-date
7118 @opindex newer
7119 @item --after-date=@var{date}
7120 @itemx --newer=@var{date}
7121 @itemx -N @var{date}
7122 Only store files newer than @var{date}.
7123
7124 Acts on files only if their data modification or status change times are
7125 later than @var{date}. Use in conjunction with any operation.
7126
7127 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7128 name; the data modification time of that file is used as the date.
7129
7130 @opindex newer-mtime
7131 @item --newer-mtime=@var{date}
7132 Acts like @option{--after-date}, but only looks at data modification times.
7133 @end table
7134
7135 These options limit @command{tar} to operate only on files which have
7136 been modified after the date specified. A file's status is considered to have
7137 changed if its contents have been modified, or if its owner,
7138 permissions, and so forth, have been changed. (For more information on
7139 how to specify a date, see @ref{Date input formats}; remember that the
7140 entire date argument must be quoted if it contains any spaces.)
7141
7142 Gurus would say that @option{--after-date} tests both the data
7143 modification time (@code{mtime}, the time the contents of the file
7144 were last modified) and the status change time (@code{ctime}, the time
7145 the file's status was last changed: owner, permissions, etc.@:)
7146 fields, while @option{--newer-mtime} tests only the @code{mtime}
7147 field.
7148
7149 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7150 @code{ctime} and processes the file if either one is more recent than
7151 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7152 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7153 contents of the file were looked at).
7154
7155 Date specifiers can have embedded spaces. Because of this, you may need
7156 to quote date arguments to keep the shell from parsing them as separate
7157 arguments. For example, the following command will add to the archive
7158 all the files modified less than two days ago:
7159
7160 @smallexample
7161 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7162 @end smallexample
7163
7164 @quotation
7165 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7166 should not be used for incremental backups. @xref{Incremental Dumps},
7167 for proper way of creating incremental backups.
7168 @end quotation
7169
7170 @node recurse
7171 @section Descending into Directories
7172 @UNREVISED
7173 @cindex Avoiding recursion in directories
7174 @cindex Descending directories, avoiding
7175 @cindex Directories, avoiding recursion
7176 @cindex Recursion in directories, avoiding
7177
7178 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7179
7180 Usually, @command{tar} will recursively explore all directories (either
7181 those given on the command line or through the @option{--files-from}
7182 option) for the various files they contain. However, you may not always
7183 want @command{tar} to act this way.
7184
7185 @opindex no-recursion
7186 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7187 into specified directories. If you specify @option{--no-recursion}, you can
7188 use the @command{find} utility for hunting through levels of directories to
7189 construct a list of file names which you could then pass to @command{tar}.
7190 @command{find} allows you to be more selective when choosing which files to
7191 archive; see @ref{files}, for more information on using @command{find} with
7192 @command{tar}, or look.
7193
7194 @table @option
7195 @item --no-recursion
7196 Prevents @command{tar} from recursively descending directories.
7197
7198 @opindex recursion
7199 @item --recursion
7200 Requires @command{tar} to recursively descend directories.
7201 This is the default.
7202 @end table
7203
7204 When you use @option{--no-recursion}, @GNUTAR{} grabs
7205 directory entries themselves, but does not descend on them
7206 recursively. Many people use @command{find} for locating files they
7207 want to back up, and since @command{tar} @emph{usually} recursively
7208 descends on directories, they have to use the @samp{@w{-not -type d}}
7209 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7210 find, Finding Files}), as they usually do not want all the files in a
7211 directory. They then use the @option{--files-from} option to archive
7212 the files located via @command{find}.
7213
7214 The problem when restoring files archived in this manner is that the
7215 directories themselves are not in the archive; so the
7216 @option{--same-permissions} (@option{--preserve-permissions},
7217 @option{-p}) option does not affect them---while users might really
7218 like it to. Specifying @option{--no-recursion} is a way to tell
7219 @command{tar} to grab only the directory entries given to it, adding
7220 no new files on its own. To summarize, if you use @command{find} to
7221 create a list of files to be stored in an archive, use it as follows:
7222
7223 @smallexample
7224 @group
7225 $ @kbd{find @var{dir} @var{tests} | \
7226 tar -cf @var{archive} -T - --no-recursion}
7227 @end group
7228 @end smallexample
7229
7230 The @option{--no-recursion} option also applies when extracting: it
7231 causes @command{tar} to extract only the matched directory entries, not
7232 the files under those directories.
7233
7234 The @option{--no-recursion} option also affects how globbing patterns
7235 are interpreted (@pxref{controlling pattern-matching}).
7236
7237 The @option{--no-recursion} and @option{--recursion} options apply to
7238 later options and operands, and can be overridden by later occurrences
7239 of @option{--no-recursion} and @option{--recursion}. For example:
7240
7241 @smallexample
7242 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7243 @end smallexample
7244
7245 @noindent
7246 creates an archive with one entry for @file{grape}, and the recursive
7247 contents of @file{grape/concord}, but no entries under @file{grape}
7248 other than @file{grape/concord}.
7249
7250 @node one
7251 @section Crossing File System Boundaries
7252 @cindex File system boundaries, not crossing
7253 @UNREVISED
7254
7255 @command{tar} will normally automatically cross file system boundaries in
7256 order to archive files which are part of a directory tree. You can
7257 change this behavior by running @command{tar} and specifying
7258 @option{--one-file-system}. This option only affects files that are
7259 archived because they are in a directory that is being archived;
7260 @command{tar} will still archive files explicitly named on the command line
7261 or through @option{--files-from}, regardless of where they reside.
7262
7263 @table @option
7264 @opindex one-file-system
7265 @item --one-file-system
7266 Prevents @command{tar} from crossing file system boundaries when
7267 archiving. Use in conjunction with any write operation.
7268 @end table
7269
7270 The @option{--one-file-system} option causes @command{tar} to modify its
7271 normal behavior in archiving the contents of directories. If a file in
7272 a directory is not on the same file system as the directory itself, then
7273 @command{tar} will not archive that file. If the file is a directory
7274 itself, @command{tar} will not archive anything beneath it; in other words,
7275 @command{tar} will not cross mount points.
7276
7277 This option is useful for making full or incremental archival backups of
7278 a file system. If this option is used in conjunction with
7279 @option{--verbose} (@option{-v}), files that are excluded are
7280 mentioned by name on the standard error.
7281
7282 @menu
7283 * directory:: Changing Directory
7284 * absolute:: Absolute File Names
7285 @end menu
7286
7287 @node directory
7288 @subsection Changing the Working Directory
7289 @UNREVISED
7290
7291 @FIXME{need to read over this node now for continuity; i've switched
7292 things around some.}
7293
7294 @cindex Changing directory mid-stream
7295 @cindex Directory, changing mid-stream
7296 @cindex Working directory, specifying
7297 To change the working directory in the middle of a list of file names,
7298 either on the command line or in a file specified using
7299 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7300 This will change the working directory to the specified directory
7301 after that point in the list.
7302
7303 @table @option
7304 @opindex directory
7305 @item --directory=@var{directory}
7306 @itemx -C @var{directory}
7307 Changes the working directory in the middle of a command line.
7308 @end table
7309
7310 For example,
7311
7312 @smallexample
7313 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7314 @end smallexample
7315
7316 @noindent
7317 will place the files @file{grape} and @file{prune} from the current
7318 directory into the archive @file{jams.tar}, followed by the file
7319 @file{cherry} from the directory @file{food}. This option is especially
7320 useful when you have several widely separated files that you want to
7321 store in the same archive.
7322
7323 Note that the file @file{cherry} is recorded in the archive under the
7324 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7325 archive will contain three files that all appear to have come from the
7326 same directory; if the archive is extracted with plain @samp{tar
7327 --extract}, all three files will be written in the current directory.
7328
7329 Contrast this with the command,
7330
7331 @smallexample
7332 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7333 @end smallexample
7334
7335 @noindent
7336 which records the third file in the archive under the name
7337 @file{red/cherry} so that, if the archive is extracted using
7338 @samp{tar --extract}, the third file will be written in a subdirectory
7339 named @file{orange-colored}.
7340
7341 You can use the @option{--directory} option to make the archive
7342 independent of the original name of the directory holding the files.
7343 The following command places the files @file{/etc/passwd},
7344 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7345 @file{foo.tar}:
7346
7347 @smallexample
7348 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7349 @end smallexample
7350
7351 @noindent
7352 However, the names of the archive members will be exactly what they were
7353 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7354 They will not appear to be related by file name to the original
7355 directories where those files were located.
7356
7357 Note that @option{--directory} options are interpreted consecutively. If
7358 @option{--directory} specifies a relative file name, it is interpreted
7359 relative to the then current directory, which might not be the same as
7360 the original current working directory of @command{tar}, due to a previous
7361 @option{--directory} option.
7362
7363 When using @option{--files-from} (@pxref{files}), you can put various
7364 @command{tar} options (including @option{-C}) in the file list. Notice,
7365 however, that in this case the option and its argument may not be
7366 separated by whitespace. If you use short option, its argument must
7367 either follow the option letter immediately, without any intervening
7368 whitespace, or occupy the next line. Otherwise, if you use long
7369 option, separate its argument by an equal sign.
7370
7371 For instance, the file list for the above example will be:
7372
7373 @smallexample
7374 @group
7375 -C
7376 /etc
7377 passwd
7378 hosts
7379 -C
7380 /lib
7381 libc.a
7382 @end group
7383 @end smallexample
7384
7385 @noindent
7386 To use it, you would invoke @command{tar} as follows:
7387
7388 @smallexample
7389 $ @kbd{tar -c -f foo.tar --files-from list}
7390 @end smallexample
7391
7392 Notice also that you can only use the short option variant in the file
7393 list, i.e., always use @option{-C}, not @option{--directory}.
7394
7395 The interpretation of @option{--directory} is disabled by
7396 @option{--null} option.
7397
7398 @node absolute
7399 @subsection Absolute File Names
7400 @UNREVISED
7401
7402 @table @option
7403 @opindex absolute-names
7404 @item --absolute-names
7405 @itemx -P
7406 Do not strip leading slashes from file names, and permit file names
7407 containing a @file{..} file name component.
7408 @end table
7409
7410 By default, @GNUTAR{} drops a leading @samp{/} on
7411 input or output, and complains about file names containing a @file{..}
7412 component. This option turns off this behavior.
7413
7414 When @command{tar} extracts archive members from an archive, it strips any
7415 leading slashes (@samp{/}) from the member name. This causes absolute
7416 member names in the archive to be treated as relative file names. This
7417 allows you to have such members extracted wherever you want, instead of
7418 being restricted to extracting the member in the exact directory named
7419 in the archive. For example, if the archive member has the name
7420 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7421 really @file{etc/passwd}.
7422
7423 File names containing @file{..} can cause problems when extracting, so
7424 @command{tar} normally warns you about such files when creating an
7425 archive, and rejects attempts to extracts such files.
7426
7427 Other @command{tar} programs do not do this. As a result, if you
7428 create an archive whose member names start with a slash, they will be
7429 difficult for other people with a non-@GNUTAR{}
7430 program to use. Therefore, @GNUTAR{} also strips
7431 leading slashes from member names when putting members into the
7432 archive. For example, if you ask @command{tar} to add the file
7433 @file{/bin/ls} to an archive, it will do so, but the member name will
7434 be @file{bin/ls}.@footnote{A side effect of this is that when
7435 @option{--create} is used with @option{--verbose} the resulting output
7436 is not, generally speaking, the same as the one you'd get running
7437 @kbd{tar --list} command. This may be important if you use some
7438 scripts for comparing both outputs. @xref{listing member and file names},
7439 for the information on how to handle this case.}
7440
7441 If you use the @option{--absolute-names} (@option{-P}) option,
7442 @command{tar} will do none of these transformations.
7443
7444 To archive or extract files relative to the root directory, specify
7445 the @option{--absolute-names} (@option{-P}) option.
7446
7447 Normally, @command{tar} acts on files relative to the working
7448 directory---ignoring superior directory names when archiving, and
7449 ignoring leading slashes when extracting.
7450
7451 When you specify @option{--absolute-names} (@option{-P}),
7452 @command{tar} stores file names including all superior directory
7453 names, and preserves leading slashes. If you only invoked
7454 @command{tar} from the root directory you would never need the
7455 @option{--absolute-names} option, but using this option
7456 may be more convenient than switching to root.
7457
7458 @FIXME{Should be an example in the tutorial/wizardry section using this
7459 to transfer files between systems.}
7460
7461 @FIXME{Is write access an issue?}
7462
7463 @table @option
7464 @item --absolute-names
7465 Preserves full file names (including superior directory names) when
7466 archiving files. Preserves leading slash when extracting files.
7467
7468 @end table
7469
7470 @FIXME{this is still horrible; need to talk with dan on monday.}
7471
7472 @command{tar} prints out a message about removing the @samp{/} from
7473 file names. This message appears once per @GNUTAR{}
7474 invocation. It represents something which ought to be told; ignoring
7475 what it means can cause very serious surprises, later.
7476
7477 Some people, nevertheless, do not want to see this message. Wanting to
7478 play really dangerously, one may of course redirect @command{tar} standard
7479 error to the sink. For example, under @command{sh}:
7480
7481 @smallexample
7482 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7483 @end smallexample
7484
7485 @noindent
7486 Another solution, both nicer and simpler, would be to change to
7487 the @file{/} directory first, and then avoid absolute notation.
7488 For example:
7489
7490 @smallexample
7491 $ @kbd{(cd / && tar -c -f archive.tar home)}
7492 # @i{or}:
7493 $ @kbd{tar -c -f archive.tar -C / home}
7494 @end smallexample
7495
7496 @include getdate.texi
7497
7498 @node Formats
7499 @chapter Controlling the Archive Format
7500
7501 @cindex Tar archive formats
7502 Due to historical reasons, there are several formats of tar archives.
7503 All of them are based on the same principles, but have some subtle
7504 differences that often make them incompatible with each other.
7505
7506 GNU tar is able to create and handle archives in a variety of formats.
7507 The most frequently used formats are (in alphabetical order):
7508
7509 @table @asis
7510 @item gnu
7511 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7512 from an early @acronym{POSIX} standard, adding some improvements such as
7513 sparse file handling and incremental archives. Unfortunately these
7514 features were implemented in a way incompatible with other archive
7515 formats.
7516
7517 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7518 length.
7519
7520 @item oldgnu
7521 Format used by @GNUTAR{} of versions prior to 1.12.
7522
7523 @item v7
7524 Archive format, compatible with the V7 implementation of tar. This
7525 format imposes a number of limitations. The most important of them
7526 are:
7527
7528 @enumerate
7529 @item The maximum length of a file name is limited to 99 characters.
7530 @item The maximum length of a symbolic link is limited to 99 characters.
7531 @item It is impossible to store special files (block and character
7532 devices, fifos etc.)
7533 @item Maximum value of user or group ID is limited to 2097151 (7777777
7534 octal)
7535 @item V7 archives do not contain symbolic ownership information (user
7536 and group name of the file owner).
7537 @end enumerate
7538
7539 This format has traditionally been used by Automake when producing
7540 Makefiles. This practice will change in the future, in the meantime,
7541 however this means that projects containing filenames more than 99
7542 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7543 Automake prior to 1.9.
7544
7545 @item ustar
7546 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7547 symbolic ownership information. It is also able to store
7548 special files. However, it imposes several restrictions as well:
7549
7550 @enumerate
7551 @item The maximum length of a file name is limited to 256 characters,
7552 provided that the filename can be split at directory separator in
7553 two parts, first of them being at most 155 bytes long. So, in most
7554 cases the maximum file name length will be shorter than 256
7555 characters.
7556 @item The maximum length of a symbolic link name is limited to
7557 100 characters.
7558 @item Maximum size of a file the archive is able to accomodate
7559 is 8GB
7560 @item Maximum value of UID/GID is 2097151.
7561 @item Maximum number of bits in device major and minor numbers is 21.
7562 @end enumerate
7563
7564 @item star
7565 Format used by J@"org Schilling @command{star}
7566 implementation. @GNUTAR{} is able to read @samp{star} archives but
7567 currently does not produce them.
7568
7569 @item posix
7570 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7571 most flexible and feature-rich format. It does not impose any
7572 restrictions on file sizes or filename lengths. This format is quite
7573 recent, so not all tar implementations are able to handle it properly.
7574 However, this format is designed in such a way that any tar
7575 implementation able to read @samp{ustar} archives will be able to read
7576 most @samp{posix} archives as well, with the only exception that any
7577 additional information (such as long file names etc.) will in such
7578 case be extracted as plain text files along with the files it refers to.
7579
7580 This archive format will be the default format for future versions
7581 of @GNUTAR{}.
7582
7583 @end table
7584
7585 The following table summarizes the limitations of each of these
7586 formats:
7587
7588 @multitable @columnfractions .10 .20 .20 .20 .20
7589 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7590 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7591 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7592 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7593 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7594 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7595 @end multitable
7596
7597 The default format for @GNUTAR{} is defined at compilation
7598 time. You may check it by running @command{tar --help}, and examining
7599 the last lines of its output. Usually, @GNUTAR{} is configured
7600 to create archives in @samp{gnu} format, however, future version will
7601 switch to @samp{posix}.
7602
7603 @menu
7604 * Portability:: Making @command{tar} Archives More Portable
7605 * Compression:: Using Less Space through Compression
7606 * Attributes:: Handling File Attributes
7607 * cpio:: Comparison of @command{tar} and @command{cpio}
7608 @end menu
7609
7610 @node Portability
7611 @section Making @command{tar} Archives More Portable
7612
7613 Creating a @command{tar} archive on a particular system that is meant to be
7614 useful later on many other machines and with other versions of @command{tar}
7615 is more challenging than you might think. @command{tar} archive formats
7616 have been evolving since the first versions of Unix. Many such formats
7617 are around, and are not always compatible with each other. This section
7618 discusses a few problems, and gives some advice about making @command{tar}
7619 archives more portable.
7620
7621 One golden rule is simplicity. For example, limit your @command{tar}
7622 archives to contain only regular files and directories, avoiding
7623 other kind of special files. Do not attempt to save sparse files or
7624 contiguous files as such. Let's discuss a few more problems, in turn.
7625
7626 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7627 archives and archive labels) in GNU and PAX formats.}
7628
7629 @menu
7630 * Portable Names:: Portable Names
7631 * dereference:: Symbolic Links
7632 * old:: Old V7 Archives
7633 * ustar:: Ustar Archives
7634 * gnu:: GNU and old GNU format archives.
7635 * posix:: @acronym{POSIX} archives
7636 * Checksumming:: Checksumming Problems
7637 * Large or Negative Values:: Large files, negative time stamps, etc.
7638 @end menu
7639
7640 @node Portable Names
7641 @subsection Portable Names
7642
7643 Use portable file and member names. A name is portable if it contains
7644 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7645 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7646 contain @samp{/-}. Avoid deep directory nesting. For portability to
7647 old Unix hosts, limit your file name components to 14 characters or
7648 less.
7649
7650 If you intend to have your @command{tar} archives to be read under
7651 MSDOS, you should not rely on case distinction for file names, and you
7652 might use the @acronym{GNU} @command{doschk} program for helping you
7653 further diagnosing illegal MSDOS names, which are even more limited
7654 than System V's.
7655
7656 @node dereference
7657 @subsection Symbolic Links
7658 @cindex File names, using symbolic links
7659 @cindex Symbolic link as file name
7660
7661 @opindex dereference
7662 Normally, when @command{tar} archives a symbolic link, it writes a
7663 block to the archive naming the target of the link. In that way, the
7664 @command{tar} archive is a faithful record of the file system contents.
7665 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7666 @command{tar} to archive the files symbolic links point to, instead of
7667 the links themselves. When this option is used, when @command{tar}
7668 encounters a symbolic link, it will archive the linked-to file,
7669 instead of simply recording the presence of a symbolic link.
7670
7671 The name under which the file is stored in the file system is not
7672 recorded in the archive. To record both the symbolic link name and
7673 the file name in the system, archive the file under both names. If
7674 all links were recorded automatically by @command{tar}, an extracted file
7675 might be linked to a file name that no longer exists in the file
7676 system.
7677
7678 If a linked-to file is encountered again by @command{tar} while creating
7679 the same archive, an entire second copy of it will be stored. (This
7680 @emph{might} be considered a bug.)
7681
7682 So, for portable archives, do not archive symbolic links as such,
7683 and use @option{--dereference} (@option{-h}): many systems do not support
7684 symbolic links, and moreover, your distribution might be unusable if
7685 it contains unresolved symbolic links.
7686
7687 @node old
7688 @subsection Old V7 Archives
7689 @cindex Format, old style
7690 @cindex Old style format
7691 @cindex Old style archives
7692 @cindex v7 archive format
7693
7694 Certain old versions of @command{tar} cannot handle additional
7695 information recorded by newer @command{tar} programs. To create an
7696 archive in V7 format (not ANSI), which can be read by these old
7697 versions, specify the @option{--format=v7} option in
7698 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7699 accepts @option{--portability} or @samp{op-old-archive} for this
7700 option). When you specify it,
7701 @command{tar} leaves out information about directories, pipes, fifos,
7702 contiguous files, and device files, and specifies file ownership by
7703 group and user IDs instead of group and user names.
7704
7705 When updating an archive, do not use @option{--format=v7}
7706 unless the archive was created using this option.
7707
7708 In most cases, a @emph{new} format archive can be read by an @emph{old}
7709 @command{tar} program without serious trouble, so this option should
7710 seldom be needed. On the other hand, most modern @command{tar}s are
7711 able to read old format archives, so it might be safer for you to
7712 always use @option{--format=v7} for your distributions.
7713
7714 @node ustar
7715 @subsection Ustar Archive Format
7716
7717 @cindex ustar archive format
7718 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7719 @code{ustar}. Although it is more flexible than the V7 format, it
7720 still has many restrictions (@xref{Formats,ustar}, for the detailed
7721 description of @code{ustar} format). Along with V7 format,
7722 @code{ustar} format is a good choice for archives intended to be read
7723 with other implementations of @command{tar}.
7724
7725 To create archive in @code{ustar} format, use @option{--format=ustar}
7726 option in conjunction with the @option{--create} (@option{-c}).
7727
7728 @node gnu
7729 @subsection @acronym{GNU} and old @GNUTAR{} format
7730
7731 @cindex GNU archive format
7732 @cindex Old GNU archive format
7733 @GNUTAR{} was based on an early draft of the
7734 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7735 @command{tar}, such as the support for file names longer than 100
7736 characters, use portions of the @command{tar} header record which were
7737 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7738 @acronym{POSIX} have allocated the same parts of the header record for
7739 other purposes. As a result, @GNUTAR{} format is
7740 incompatible with the current @acronym{POSIX} specification, and with
7741 @command{tar} programs that follow it.
7742
7743 In the majority of cases, @command{tar} will be configured to create
7744 this format by default. This will change in the future releases, since
7745 we plan to make @samp{posix} format the default.
7746
7747 To force creation a @GNUTAR{} archive, use option
7748 @option{--format=gnu}.
7749
7750 @node posix
7751 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7752
7753 @cindex POSIX archive format
7754 @cindex PAX archive format
7755 Starting from version 1.14 @GNUTAR{} features full support for
7756 @acronym{POSIX.1-2001} archives.
7757
7758 A @acronym{POSIX} conformant archive will be created if @command{tar}
7759 was given @option{--format=posix} (@option{--format=pax}) option. No
7760 special option is required to read and extract from a @acronym{POSIX}
7761 archive.
7762
7763 @menu
7764 * PAX keywords:: Controlling Extended Header Keywords.
7765 @end menu
7766
7767 @node PAX keywords
7768 @subsubsection Controlling Extended Header Keywords
7769
7770 @table @option
7771 @opindex pax-option
7772 @item --pax-option=@var{keyword-list}
7773 Handle keywords in @acronym{PAX} extended headers. This option is
7774 equivalent to @option{-o} option of the @command{pax} utility.
7775 @end table
7776
7777 @var{Keyword-list} is a comma-separated
7778 list of keyword options, each keyword option taking one of
7779 the following forms:
7780
7781 @table @code
7782 @item delete=@var{pattern}
7783 When used with one of archive-creation commands,
7784 this option instructs @command{tar} to omit from extended header records
7785 that it produces any keywords matching the string @var{pattern}.
7786
7787 When used in extract or list mode, this option instructs tar
7788 to ignore any keywords matching the given @var{pattern} in the extended
7789 header records. In both cases, matching is performed using the pattern
7790 matching notation described in @acronym{POSIX 1003.2}, 3.13
7791 (@pxref{wildcards}). For example:
7792
7793 @smallexample
7794 --pax-option delete=security.*
7795 @end smallexample
7796
7797 would suppress security-related information.
7798
7799 @item exthdr.name=@var{string}
7800
7801 This keyword allows user control over the name that is written into the
7802 ustar header blocks for the extended headers. The name is obtained
7803 from @var{string} after making the following substitutions:
7804
7805 @multitable @columnfractions .25 .55
7806 @headitem Meta-character @tab Replaced By
7807 @item %d @tab The directory name of the file, equivalent to the
7808 result of the @command{dirname} utility on the translated pathname.
7809 @item %f @tab The filename of the file, equivalent to the result
7810 of the @command{basename} utility on the translated pathname.
7811 @item %p @tab The process ID of the @command{tar} process.
7812 @item %% @tab A @samp{%} character.
7813 @end multitable
7814
7815 Any other @samp{%} characters in @var{string} produce undefined
7816 results.
7817
7818 If no option @samp{exthdr.name=string} is specified, @command{tar}
7819 will use the following default value:
7820
7821 @smallexample
7822 %d/PaxHeaders.%p/%f
7823 @end smallexample
7824
7825 @item globexthdr.name=@var{string}
7826 This keyword allows user control over the name that is written into
7827 the ustar header blocks for global extended header records. The name
7828 is obtained from the contents of @var{string}, after making
7829 the following substitutions:
7830
7831 @multitable @columnfractions .25 .55
7832 @headitem Meta-character @tab Replaced By
7833 @item %n @tab An integer that represents the
7834 sequence number of the global extended header record in the archive,
7835 starting at 1.
7836 @item %p @tab The process ID of the @command{tar} process.
7837 @item %% @tab A @samp{%} character.
7838 @end multitable
7839
7840 Any other @samp{%} characters in @var{string} produce undefined results.
7841
7842 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7843 will use the following default value:
7844
7845 @smallexample
7846 $TMPDIR/GlobalHead.%p.%n
7847 @end smallexample
7848
7849 @noindent
7850 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7851 environment variable. If @var{TMPDIR} is not set, @command{tar}
7852 uses @samp{/tmp}.
7853
7854 @item @var{keyword}=@var{value}
7855 When used with one of archive-creation commands, these keyword/value pairs
7856 will be included at the beginning of the archive in a global extended
7857 header record. When used with one of archive-reading commands,
7858 @command{tar} will behave as if it has encountered these keyword/value
7859 pairs at the beginning of the archive in a global extended header
7860 record.
7861
7862 @item @var{keyword}:=@var{value}
7863 When used with one of archive-creation commands, these keyword/value pairs
7864 will be included as records at the beginning of an extended header for
7865 each file. This is effectively equivalent to @var{keyword}=@var{value}
7866 form except that it creates no global extended header records.
7867
7868 When used with one of archive-reading commands, @command{tar} will
7869 behave as if these keyword/value pairs were included as records at the
7870 end of each extended header; thus, they will override any global or
7871 file-specific extended header record keywords of the same names.
7872 For example, in the command:
7873
7874 @smallexample
7875 tar --format=posix --create \
7876 --file archive --pax-option gname:=user .
7877 @end smallexample
7878
7879 the group name will be forced to a new value for all files
7880 stored in the archive.
7881 @end table
7882
7883 @node Checksumming
7884 @subsection Checksumming Problems
7885
7886 SunOS and HP-UX @command{tar} fail to accept archives created using
7887 @GNUTAR{} and containing non-ASCII file names, that
7888 is, file names having characters with the eight bit set, because they
7889 use signed checksums, while @GNUTAR{} uses unsigned
7890 checksums while creating archives, as per @acronym{POSIX} standards. On
7891 reading, @GNUTAR{} computes both checksums and
7892 accept any. It is somewhat worrying that a lot of people may go
7893 around doing backup of their files using faulty (or at least
7894 non-standard) software, not learning about it until it's time to
7895 restore their missing files with an incompatible file extractor, or
7896 vice versa.
7897
7898 @GNUTAR{} compute checksums both ways, and accept
7899 any on read, so @acronym{GNU} tar can read Sun tapes even with their
7900 wrong checksums. @GNUTAR{} produces the standard
7901 checksum, however, raising incompatibilities with Sun. That is to
7902 say, @GNUTAR{} has not been modified to
7903 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
7904 I've been told that more recent Sun @command{tar} now read standard
7905 archives, so maybe Sun did a similar patch, after all?
7906
7907 The story seems to be that when Sun first imported @command{tar}
7908 sources on their system, they recompiled it without realizing that
7909 the checksums were computed differently, because of a change in
7910 the default signing of @code{char}'s in their compiler. So they
7911 started computing checksums wrongly. When they later realized their
7912 mistake, they merely decided to stay compatible with it, and with
7913 themselves afterwards. Presumably, but I do not really know, HP-UX
7914 has chosen that their @command{tar} archives to be compatible with Sun's.
7915 The current standards do not favor Sun @command{tar} format. In any
7916 case, it now falls on the shoulders of SunOS and HP-UX users to get
7917 a @command{tar} able to read the good archives they receive.
7918
7919 @node Large or Negative Values
7920 @subsection Large or Negative Values
7921 @cindex large values
7922 @cindex future time stamps
7923 @cindex negative time stamps
7924 @UNREVISED{}
7925
7926 The above sections suggest to use @samp{oldest possible} archive
7927 format if in doubt. However, sometimes it is not possible. If you
7928 attempt to archive a file whose metadata cannot be represented using
7929 required format, @GNUTAR{} will print error message and ignore such a
7930 file. You will than have to switch to a format that is able to
7931 handle such values. The format summary table (@pxref{Formats}) will
7932 help you to do so.
7933
7934 In particular, when trying to archive files larger than 8GB or with
7935 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
7936 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
7937 @acronym{POSIX} archive formats. When considering which format to
7938 choose, bear in mind that the @acronym{GNU} format uses
7939 two's-complement base-256 notation to store values that do not fit
7940 into standard @acronym{ustar} range. Such archives can generally be
7941 read only by a @GNUTAR{} implementation. Moreover, they sometimes
7942 cannot be correctly restored on another hosts even by @GNUTAR{}. For
7943 example, using two's complement representation for negative time
7944 stamps that assumes a signed 32-bit @code{time_t} generates archives
7945 that are not portable to hosts with differing @code{time_t}
7946 representations.
7947
7948 On the other hand, @acronym{POSIX} archives, generally speaking, can
7949 be extracted by any tar implementation that understands older
7950 @acronym{ustar} format. The only exception are files larger than 8GB.
7951
7952 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
7953 POSIX-aware tars.}
7954
7955 @node Compression
7956 @section Using Less Space through Compression
7957
7958 @menu
7959 * gzip:: Creating and Reading Compressed Archives
7960 * sparse:: Archiving Sparse Files
7961 @end menu
7962
7963 @node gzip
7964 @subsection Creating and Reading Compressed Archives
7965 @cindex Compressed archives
7966 @cindex Storing archives in compressed format
7967
7968 @GNUTAR{} is able to create and read compressed archives. It supports
7969 @command{gzip} and @command{bzip2} compression programs. For backward
7970 compatibilty, it also supports @command{compress} command, although
7971 we strongly recommend against using it, since there is a patent
7972 covering the algorithm it uses and you could be sued for patent
7973 infringement merely by running @command{compress}! Besides, it is less
7974 effective than @command{gzip} and @command{bzip2}.
7975
7976 Creating a compressed archive is simple: you just specify a
7977 @dfn{compression option} along with the usual archive creation
7978 commands. The compression option is @option{-z} (@option{--gzip}) to
7979 create a @command{gzip} compressed archive, @option{-j}
7980 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7981 @option{-Z} (@option{--compress}) to use @command{compress} program.
7982 For example:
7983
7984 @smallexample
7985 $ @kbd{tar cfz archive.tar.gz .}
7986 @end smallexample
7987
7988 Reading compressed archive is even simpler: you don't need to specify
7989 any additional options as @GNUTAR{} recognizes its format
7990 automatically. Thus, the following commands will list and extract the
7991 archive created in previous example:
7992
7993 @smallexample
7994 # List the compressed archive
7995 $ @kbd{tar tf archive.tar.gz}
7996 # Extract the compressed archive
7997 $ @kbd{tar xf archive.tar.gz}
7998 @end smallexample
7999
8000 The only case when you have to specify a decompression option while
8001 reading the archive is when reading from a pipe or from a tape drive
8002 that does not support random access. However, in this case @GNUTAR{}
8003 will indicate which option you should use. For example:
8004
8005 @smallexample
8006 $ @kbd{cat archive.tar.gz | tar tf -}
8007 tar: Archive is compressed. Use -z option
8008 tar: Error is not recoverable: exiting now
8009 @end smallexample
8010
8011 If you see such diagnostics, just add the suggested option to the
8012 invocation of @GNUTAR{}:
8013
8014 @smallexample
8015 $ @kbd{cat archive.tar.gz | tar tfz -}
8016 @end smallexample
8017
8018 Notice also, that there are several restrictions on operations on
8019 compressed archives. First of all, compressed archives cannot be
8020 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8021 (@option{--delete}) members from them. Likewise, you cannot append
8022 another @command{tar} archive to a compressed archive using
8023 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8024 compressed.
8025
8026 The following table summarizes compression options used by @GNUTAR{}.
8027
8028 @table @option
8029 @opindex gzip
8030 @opindex ungzip
8031 @item -z
8032 @itemx --gzip
8033 @itemx --ungzip
8034 Filter the archive through @command{gzip}.
8035
8036 You can use @option{--gzip} and @option{--gunzip} on physical devices
8037 (tape drives, etc.) and remote files as well as on normal files; data
8038 to or from such devices or remote files is reblocked by another copy
8039 of the @command{tar} program to enforce the specified (or default) record
8040 size. The default compression parameters are used; if you need to
8041 override them, set @env{GZIP} environment variable, e.g.:
8042
8043 @smallexample
8044 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8045 @end smallexample
8046
8047 @noindent
8048 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8049 @command{gzip} explicitly:
8050
8051 @smallexample
8052 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8053 @end smallexample
8054
8055 @cindex corrupted archives
8056 About corrupted compressed archives: @command{gzip}'ed files have no
8057 redundancy, for maximum compression. The adaptive nature of the
8058 compression scheme means that the compression tables are implicitly
8059 spread all over the archive. If you lose a few blocks, the dynamic
8060 construction of the compression tables becomes unsynchronized, and there
8061 is little chance that you could recover later in the archive.
8062
8063 There are pending suggestions for having a per-volume or per-file
8064 compression in @GNUTAR{}. This would allow for viewing the
8065 contents without decompression, and for resynchronizing decompression at
8066 every volume or file, in case of corrupted archives. Doing so, we might
8067 lose some compressibility. But this would have make recovering easier.
8068 So, there are pros and cons. We'll see!
8069
8070 @opindex bzip2
8071 @item -j
8072 @itemx --bzip2
8073 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8074
8075 @opindex compress
8076 @opindex uncompress
8077 @item -Z
8078 @itemx --compress
8079 @itemx --uncompress
8080 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8081
8082 The @acronym{GNU} Project recommends you not use
8083 @command{compress}, because there is a patent covering the algorithm it
8084 uses. You could be sued for patent infringement merely by running
8085 @command{compress}.
8086
8087 @opindex use-compress-program
8088 @item --use-compress-program=@var{prog}
8089 Use external compression program @var{prog}. Use this option if you
8090 have a compression program that @GNUTAR{} does not support. There
8091 are two requirements to which @var{prog} should comply:
8092
8093 First, when called without options, it should read data from standard
8094 input, compress it and output it on standard output.
8095
8096 Secondly, if called with @option{-d} argument, it should do exactly
8097 the opposite, i.e., read the compressed data from the standard input
8098 and produce uncompressed data on the standard output.
8099 @end table
8100
8101 @cindex gpg, using with tar
8102 @cindex gnupg, using with tar
8103 @cindex Using encrypted archives
8104 The @option{--use-compress-program} option, in particular, lets you
8105 implement your own filters, not necessarily dealing with
8106 compression/decomression. For example, suppose you wish to implement
8107 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8108 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8109 Manual}). The following script does that:
8110
8111 @smallexample
8112 @group
8113 #! /bin/sh
8114 case $1 in
8115 -d) gpg --decrypt - | gzip -d -c;;
8116 '') gzip -c | gpg -s ;;
8117 *) echo "Unknown option $1">&2; exit 1;;
8118 esac
8119 @end group
8120 @end smallexample
8121
8122 Suppose you name it @file{gpgz} and save it somewhere in your
8123 @env{PATH}. Then the following command will create a commpressed
8124 archive signed with your private key:
8125
8126 @smallexample
8127 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8128 @end smallexample
8129
8130 @noindent
8131 Likewise, the following command will list its contents:
8132
8133 @smallexample
8134 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8135 @end smallexample
8136
8137 @ignore
8138 The above is based on the following discussion:
8139
8140 I have one question, or maybe it's a suggestion if there isn't a way
8141 to do it now. I would like to use @option{--gzip}, but I'd also like
8142 the output to be fed through a program like @acronym{GNU}
8143 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8144 to use :-)), basically adding ECC protection on top of compression.
8145 It seems as if this should be quite easy to do, but I can't work out
8146 exactly how to go about it. Of course, I can pipe the standard output
8147 of @command{tar} through @command{ecc}, but then I lose (though I
8148 haven't started using it yet, I confess) the ability to have
8149 @command{tar} use @command{rmt} for it's I/O (I think).
8150
8151 I think the most straightforward thing would be to let me specify a
8152 general set of filters outboard of compression (preferably ordered,
8153 so the order can be automatically reversed on input operations, and
8154 with the options they require specifiable), but beggars shouldn't be
8155 choosers and anything you decide on would be fine with me.
8156
8157 By the way, I like @command{ecc} but if (as the comments say) it can't
8158 deal with loss of block sync, I'm tempted to throw some time at adding
8159 that capability. Supposing I were to actually do such a thing and
8160 get it (apparently) working, do you accept contributed changes to
8161 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8162
8163 Isn't that exactly the role of the
8164 @option{--use-compress-prog=@var{program}} option?
8165 I never tried it myself, but I suspect you may want to write a
8166 @var{prog} script or program able to filter stdin to stdout to
8167 way you want. It should recognize the @option{-d} option, for when
8168 extraction is needed rather than creation.
8169
8170 It has been reported that if one writes compressed data (through the
8171 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8172 the DLT compression mode, the data will actually get bigger and one will
8173 end up with less space on the tape.
8174 @end ignore
8175
8176 @node sparse
8177 @subsection Archiving Sparse Files
8178 @cindex Sparse Files
8179 @UNREVISED
8180
8181 @table @option
8182 @opindex sparse
8183 @item -S
8184 @itemx --sparse
8185 Handle sparse files efficiently.
8186 @end table
8187
8188 This option causes all files to be put in the archive to be tested for
8189 sparseness, and handled specially if they are. The @option{--sparse}
8190 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8191 backed up. Using this option dramatically decreases the amount of
8192 space needed to store such a file.
8193
8194 In later versions, this option may be removed, and the testing and
8195 treatment of sparse files may be done automatically with any special
8196 @acronym{GNU} options. For now, it is an option needing to be specified on
8197 the command line with the creation or updating of an archive.
8198
8199 Files in the file system occasionally have ``holes.'' A hole in a file
8200 is a section of the file's contents which was never written. The
8201 contents of a hole read as all zeros. On many operating systems,
8202 actual disk storage is not allocated for holes, but they are counted
8203 in the length of the file. If you archive such a file, @command{tar}
8204 could create an archive longer than the original. To have @command{tar}
8205 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8206 you use this option, then, for any file using less disk space than
8207 would be expected from its length, @command{tar} searches the file for
8208 consecutive stretches of zeros. It then records in the archive for
8209 the file where the consecutive stretches of zeros are, and only
8210 archives the ``real contents'' of the file. On extraction (using
8211 @option{--sparse} is not needed on extraction) any such
8212 files have holes created wherever the continuous stretches of zeros
8213 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8214 won't take more space than the original.
8215
8216 A file is sparse if it contains blocks of zeros whose existence is
8217 recorded, but that have no space allocated on disk. When you specify
8218 the @option{--sparse} option in conjunction with the @option{--create}
8219 (@option{-c}) operation, @command{tar} tests all files for sparseness
8220 while archiving. If @command{tar} finds a file to be sparse, it uses a
8221 sparse representation of the file in the archive. @xref{create}, for
8222 more information about creating archives.
8223
8224 @option{--sparse} is useful when archiving files, such as dbm files,
8225 likely to contain many nulls. This option dramatically
8226 decreases the amount of space needed to store such an archive.
8227
8228 @quotation
8229 @strong{Please Note:} Always use @option{--sparse} when performing file
8230 system backups, to avoid archiving the expanded forms of files stored
8231 sparsely in the system.
8232
8233 Even if your system has no sparse files currently, some may be
8234 created in the future. If you use @option{--sparse} while making file
8235 system backups as a matter of course, you can be assured the archive
8236 will never take more space on the media than the files take on disk
8237 (otherwise, archiving a disk filled with sparse files might take
8238 hundreds of tapes). @xref{Incremental Dumps}.
8239 @end quotation
8240
8241 @command{tar} ignores the @option{--sparse} option when reading an archive.
8242
8243 @table @option
8244 @item --sparse
8245 @itemx -S
8246 Files stored sparsely in the file system are represented sparsely in
8247 the archive. Use in conjunction with write operations.
8248 @end table
8249
8250 However, users should be well aware that at archive creation time,
8251 @GNUTAR{} still has to read whole disk file to
8252 locate the @dfn{holes}, and so, even if sparse files use little space
8253 on disk and in the archive, they may sometimes require inordinate
8254 amount of time for reading and examining all-zero blocks of a file.
8255 Although it works, it's painfully slow for a large (sparse) file, even
8256 though the resulting tar archive may be small. (One user reports that
8257 dumping a @file{core} file of over 400 megabytes, but with only about
8258 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8259 ELC, with full CPU utilization.)
8260
8261 This reading is required in all cases and is not related to the fact
8262 the @option{--sparse} option is used or not, so by merely @emph{not}
8263 using the option, you are not saving time@footnote{Well! We should say
8264 the whole truth, here. When @option{--sparse} is selected while creating
8265 an archive, the current @command{tar} algorithm requires sparse files to be
8266 read twice, not once. We hope to develop a new archive format for saving
8267 sparse files in which one pass will be sufficient.}.
8268
8269 Programs like @command{dump} do not have to read the entire file; by
8270 examining the file system directly, they can determine in advance
8271 exactly where the holes are and thus avoid reading through them. The
8272 only data it need read are the actual allocated data blocks.
8273 @GNUTAR{} uses a more portable and straightforward
8274 archiving approach, it would be fairly difficult that it does
8275 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8276 1990-12-10:
8277
8278 @quotation
8279 What I did say is that you cannot tell the difference between a hole and an
8280 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8281 best tells you how many holes there are; it doesn't tell you @emph{where}.
8282 Just as programs may, conceivably, care what @code{st_blocks} is (care
8283 to name one that does?), they may also care where the holes are (I have
8284 no examples of this one either, but it's equally imaginable).
8285
8286 I conclude from this that good archivers are not portable. One can
8287 arguably conclude that if you want a portable program, you can in good
8288 conscience restore files with as many holes as possible, since you can't
8289 get it right.
8290 @end quotation
8291
8292 @node Attributes
8293 @section Handling File Attributes
8294 @UNREVISED
8295
8296 When @command{tar} reads files, it updates their access times. To
8297 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8298 reset the access time retroactively or avoid changing it in the first
8299 place.
8300
8301 Handling of file attributes
8302
8303 @table @option
8304 @opindex atime-preserve
8305 @item --atime-preserve
8306 @itemx --atime-preserve=replace
8307 @itemx --atime-preserve=system
8308 Preserve the access times of files that are read. This works only for
8309 files that you own, unless you have superuser privileges.
8310
8311 @option{--atime-preserve=replace} works on most systems, but it also
8312 restores the data modification time and updates the status change
8313 time. Hence it doesn't interact with incremental dumps nicely
8314 (@pxref{Backups}), and it can set access or data modification times
8315 incorrectly if other programs access the file while @command{tar} is
8316 running.
8317
8318 @option{--atime-preserve=system} avoids changing the access time in
8319 the first place, if the operating system supports this.
8320 Unfortunately, this may or may not work on any given operating system
8321 or file system. If @command{tar} knows for sure it won't work, it
8322 complains right away.
8323
8324 Currently @option{--atime-preserve} with no operand defaults to
8325 @option{--atime-preserve=replace}, but this is intended to change to
8326 @option{--atime-preserve=system} when the latter is better-supported.
8327
8328 @opindex touch
8329 @item -m
8330 @itemx --touch
8331 Do not extract data modification time.
8332
8333 When this option is used, @command{tar} leaves the data modification times
8334 of the files it extracts as the times when the files were extracted,
8335 instead of setting it to the times recorded in the archive.
8336
8337 This option is meaningless with @option{--list} (@option{-t}).
8338
8339 @opindex same-owner
8340 @item --same-owner
8341 Create extracted files with the same ownership they have in the
8342 archive.
8343
8344 This is the default behavior for the superuser,
8345 so this option is meaningful only for non-root users, when @command{tar}
8346 is executed on those systems able to give files away. This is
8347 considered as a security flaw by many people, at least because it
8348 makes quite difficult to correctly account users for the disk space
8349 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8350 files are easily and silently lost when files are given away.
8351
8352 When writing an archive, @command{tar} writes the user id and user name
8353 separately. If it can't find a user name (because the user id is not
8354 in @file{/etc/passwd}), then it does not write one. When restoring,
8355 it tries to look the name (if one was written) up in
8356 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8357 the archive instead.
8358
8359 @opindex no-same-owner
8360 @item --no-same-owner
8361 @itemx -o
8362 Do not attempt to restore ownership when extracting. This is the
8363 default behavior for ordinary users, so this option has an effect
8364 only for the superuser.
8365
8366 @opindex numeric-owner
8367 @item --numeric-owner
8368 The @option{--numeric-owner} option allows (ANSI) archives to be written
8369 without user/group name information or such information to be ignored
8370 when extracting. It effectively disables the generation and/or use
8371 of user/group name information. This option forces extraction using
8372 the numeric ids from the archive, ignoring the names.
8373
8374 This is useful in certain circumstances, when restoring a backup from
8375 an emergency floppy with different passwd/group files for example.
8376 It is otherwise impossible to extract files with the right ownerships
8377 if the password file in use during the extraction does not match the
8378 one belonging to the file system(s) being extracted. This occurs,
8379 for example, if you are restoring your files after a major crash and
8380 had booted from an emergency floppy with no password file or put your
8381 disk into another machine to do the restore.
8382
8383 The numeric ids are @emph{always} saved into @command{tar} archives.
8384 The identifying names are added at create time when provided by the
8385 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8386 used when moving archives between a collection of machines using
8387 a centralized management for attribution of numeric ids to users
8388 and groups. This is often made through using the NIS capabilities.
8389
8390 When making a @command{tar} file for distribution to other sites, it
8391 is sometimes cleaner to use a single owner for all files in the
8392 distribution, and nicer to specify the write permission bits of the
8393 files as stored in the archive independently of their actual value on
8394 the file system. The way to prepare a clean distribution is usually
8395 to have some Makefile rule creating a directory, copying all needed
8396 files in that directory, then setting ownership and permissions as
8397 wanted (there are a lot of possible schemes), and only then making a
8398 @command{tar} archive out of this directory, before cleaning
8399 everything out. Of course, we could add a lot of options to
8400 @GNUTAR{} for fine tuning permissions and ownership.
8401 This is not the good way, I think. @GNUTAR{} is
8402 already crowded with options and moreover, the approach just explained
8403 gives you a great deal of control already.
8404
8405 @xopindex{same-permissions, short description}
8406 @xopindex{preserve-permissions, short description}
8407 @item -p
8408 @itemx --same-permissions
8409 @itemx --preserve-permissions
8410 Extract all protection information.
8411
8412 This option causes @command{tar} to set the modes (access permissions) of
8413 extracted files exactly as recorded in the archive. If this option
8414 is not used, the current @code{umask} setting limits the permissions
8415 on extracted files. This option is by default enabled when
8416 @command{tar} is executed by a superuser.
8417
8418
8419 This option is meaningless with @option{--list} (@option{-t}).
8420
8421 @opindex preserve
8422 @item --preserve
8423 Same as both @option{--same-permissions} and @option{--same-order}.
8424
8425 The @option{--preserve} option has no equivalent short option name.
8426 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8427
8428 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8429 Neither do I. --Sergey}
8430
8431 @end table
8432
8433 @node cpio
8434 @section Comparison of @command{tar} and @command{cpio}
8435 @UNREVISED
8436
8437 @FIXME{Reorganize the following material}
8438
8439 The @command{cpio} archive formats, like @command{tar}, do have maximum
8440 pathname lengths. The binary and old ASCII formats have a max path
8441 length of 256, and the new ASCII and CRC ASCII formats have a max
8442 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8443 with arbitrary pathname lengths, but other @command{cpio} implementations
8444 may crash unexplainedly trying to read them.
8445
8446 @command{tar} handles symbolic links in the form in which it comes in BSD;
8447 @command{cpio} doesn't handle symbolic links in the form in which it comes
8448 in System V prior to SVR4, and some vendors may have added symlinks
8449 to their system without enhancing @command{cpio} to know about them.
8450 Others may have enhanced it in a way other than the way I did it
8451 at Sun, and which was adopted by AT&T (and which is, I think, also
8452 present in the @command{cpio} that Berkeley picked up from AT&T and put
8453 into a later BSD release---I think I gave them my changes).
8454
8455 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8456 can handle @command{tar} format input, and write it on output, and it
8457 probably handles symbolic links. They may not have bothered doing
8458 anything to enhance @command{tar} as a result.)
8459
8460 @command{cpio} handles special files; traditional @command{tar} doesn't.
8461
8462 @command{tar} comes with V7, System III, System V, and BSD source;
8463 @command{cpio} comes only with System III, System V, and later BSD
8464 (4.3-tahoe and later).
8465
8466 @command{tar}'s way of handling multiple hard links to a file can handle
8467 file systems that support 32-bit inumbers (e.g., the BSD file system);
8468 @command{cpio}s way requires you to play some games (in its "binary"
8469 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8470 they're 18 bits---it would have to play games with the "file system ID"
8471 field of the header to make sure that the file system ID/i-number pairs
8472 of different files were always different), and I don't know which
8473 @command{cpio}s, if any, play those games. Those that don't might get
8474 confused and think two files are the same file when they're not, and
8475 make hard links between them.
8476
8477 @command{tar}s way of handling multiple hard links to a file places only
8478 one copy of the link on the tape, but the name attached to that copy
8479 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8480 way puts one copy for every link, but you can retrieve it using any
8481 of the names.
8482
8483 @quotation
8484 What type of check sum (if any) is used, and how is this calculated.
8485 @end quotation
8486
8487 See the attached manual pages for @command{tar} and @command{cpio} format.
8488 @command{tar} uses a checksum which is the sum of all the bytes in the
8489 @command{tar} header for a file; @command{cpio} uses no checksum.
8490
8491 @quotation
8492 If anyone knows why @command{cpio} was made when @command{tar} was present
8493 at the unix scene,
8494 @end quotation
8495
8496 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8497 generally-available version of UNIX had @command{tar} at the time. I don't
8498 know whether any version that was generally available @emph{within AT&T}
8499 had @command{tar}, or, if so, whether the people within AT&T who did
8500 @command{cpio} knew about it.
8501
8502 On restore, if there is a corruption on a tape @command{tar} will stop at
8503 that point, while @command{cpio} will skip over it and try to restore the
8504 rest of the files.
8505
8506 The main difference is just in the command syntax and header format.
8507
8508 @command{tar} is a little more tape-oriented in that everything is blocked
8509 to start on a record boundary.
8510
8511 @quotation
8512 Is there any differences between the ability to recover crashed
8513 archives between the two of them. (Is there any chance of recovering
8514 crashed archives at all.)
8515 @end quotation
8516
8517 Theoretically it should be easier under @command{tar} since the blocking
8518 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8519 However, modern @command{cpio}'s and variations have an option to just
8520 search for the next file header after an error with a reasonable chance
8521 of resyncing. However, lots of tape driver software won't allow you to
8522 continue past a media error which should be the only reason for getting
8523 out of sync unless a file changed sizes while you were writing the
8524 archive.
8525
8526 @quotation
8527 If anyone knows why @command{cpio} was made when @command{tar} was present
8528 at the unix scene, please tell me about this too.
8529 @end quotation
8530
8531 Probably because it is more media efficient (by not blocking everything
8532 and using only the space needed for the headers where @command{tar}
8533 always uses 512 bytes per file header) and it knows how to archive
8534 special files.
8535
8536 You might want to look at the freely available alternatives. The
8537 major ones are @command{afio}, @GNUTAR{}, and
8538 @command{pax}, each of which have their own extensions with some
8539 backwards compatibility.
8540
8541 Sparse files were @command{tar}red as sparse files (which you can
8542 easily test, because the resulting archive gets smaller, and
8543 @acronym{GNU} @command{cpio} can no longer read it).
8544
8545 @node Media
8546 @chapter Tapes and Other Archive Media
8547 @UNREVISED
8548
8549 A few special cases about tape handling warrant more detailed
8550 description. These special cases are discussed below.
8551
8552 Many complexities surround the use of @command{tar} on tape drives. Since
8553 the creation and manipulation of archives located on magnetic tape was
8554 the original purpose of @command{tar}, it contains many features making
8555 such manipulation easier.
8556
8557 Archives are usually written on dismountable media---tape cartridges,
8558 mag tapes, or floppy disks.
8559
8560 The amount of data a tape or disk holds depends not only on its size,
8561 but also on how it is formatted. A 2400 foot long reel of mag tape
8562 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8563 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8564
8565 Magnetic media are re-usable---once the archive on a tape is no longer
8566 needed, the archive can be erased and the tape or disk used over.
8567 Media quality does deteriorate with use, however. Most tapes or disks
8568 should be discarded when they begin to produce data errors. EXABYTE
8569 tape cartridges should be discarded when they generate an @dfn{error
8570 count} (number of non-usable bits) of more than 10k.
8571
8572 Magnetic media are written and erased using magnetic fields, and
8573 should be protected from such fields to avoid damage to stored data.
8574 Sticking a floppy disk to a filing cabinet using a magnet is probably
8575 not a good idea.
8576
8577 @menu
8578 * Device:: Device selection and switching
8579 * Remote Tape Server::
8580 * Common Problems and Solutions::
8581 * Blocking:: Blocking
8582 * Many:: Many archives on one tape
8583 * Using Multiple Tapes:: Using Multiple Tapes
8584 * label:: Including a Label in the Archive
8585 * verify::
8586 * Write Protection::
8587 @end menu
8588
8589 @node Device
8590 @section Device Selection and Switching
8591 @UNREVISED
8592
8593 @table @option
8594 @item -f [@var{hostname}:]@var{file}
8595 @itemx --file=[@var{hostname}:]@var{file}
8596 Use archive file or device @var{file} on @var{hostname}.
8597 @end table
8598
8599 This option is used to specify the file name of the archive @command{tar}
8600 works on.
8601
8602 If the file name is @samp{-}, @command{tar} reads the archive from standard
8603 input (when listing or extracting), or writes it to standard output
8604 (when creating). If the @samp{-} file name is given when updating an
8605 archive, @command{tar} will read the original archive from its standard
8606 input, and will write the entire new archive to its standard output.
8607
8608 If the file name contains a @samp{:}, it is interpreted as
8609 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8610 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8611 either case, @command{tar} will invoke the command @command{rsh} (or
8612 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8613 machine. If you give an alternate login name, it will be given to the
8614 @command{rsh}.
8615 Naturally, the remote machine must have an executable
8616 @command{/usr/libexec/rmt}. This program is free software from the
8617 University of California, and a copy of the source code can be found
8618 with the sources for @command{tar}; it's compiled and installed by default.
8619 The exact path to this utility is determined when configuring the package.
8620 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8621 your installation prefix. This location may also be overridden at
8622 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8623 ---rmt-command}, for detailed description of this option. @xref{Remote
8624 Tape Server}, for the description of @command{rmt} command).
8625
8626 If this option is not given, but the environment variable @env{TAPE}
8627 is set, its value is used; otherwise, old versions of @command{tar}
8628 used a default archive name (which was picked when @command{tar} was
8629 compiled). The default is normally set up to be the @dfn{first} tape
8630 drive or other transportable I/O medium on the system.
8631
8632 Starting with version 1.11.5, @GNUTAR{} uses
8633 standard input and standard output as the default device, and I will
8634 not try anymore supporting automatic device detection at installation
8635 time. This was failing really in too many cases, it was hopeless.
8636 This is now completely left to the installer to override standard
8637 input and standard output for default device, if this seems
8638 preferable. Further, I think @emph{most} actual usages of
8639 @command{tar} are done with pipes or disks, not really tapes,
8640 cartridges or diskettes.
8641
8642 Some users think that using standard input and output is running
8643 after trouble. This could lead to a nasty surprise on your screen if
8644 you forget to specify an output file name---especially if you are going
8645 through a network or terminal server capable of buffering large amounts
8646 of output. We had so many bug reports in that area of configuring
8647 default tapes automatically, and so many contradicting requests, that
8648 we finally consider the problem to be portably intractable. We could
8649 of course use something like @samp{/dev/tape} as a default, but this
8650 is @emph{also} running after various kind of trouble, going from hung
8651 processes to accidental destruction of real tapes. After having seen
8652 all this mess, using standard input and output as a default really
8653 sounds like the only clean choice left, and a very useful one too.
8654
8655 @GNUTAR{} reads and writes archive in records, I
8656 suspect this is the main reason why block devices are preferred over
8657 character devices. Most probably, block devices are more efficient
8658 too. The installer could also check for @samp{DEFTAPE} in
8659 @file{<sys/mtio.h>}.
8660
8661 @table @option
8662 @xopindex{force-local, short description}
8663 @item --force-local
8664 Archive file is local even if it contains a colon.
8665
8666 @opindex rsh-command
8667 @item --rsh-command=@var{command}
8668 Use remote @var{command} instead of @command{rsh}. This option exists
8669 so that people who use something other than the standard @command{rsh}
8670 (e.g., a Kerberized @command{rsh}) can access a remote device.
8671
8672 When this command is not used, the shell command found when
8673 the @command{tar} program was installed is used instead. This is
8674 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8675 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8676 The installer may have overridden this by defining the environment
8677 variable @env{RSH} @emph{at installation time}.
8678
8679 @item -[0-7][lmh]
8680 Specify drive and density.
8681
8682 @xopindex{multi-volume, short description}
8683 @item -M
8684 @itemx --multi-volume
8685 Create/list/extract multi-volume archive.
8686
8687 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8688 that may be larger than will fit on the medium used to hold it.
8689 @xref{Multi-Volume Archives}.
8690
8691 @xopindex{tape-length, short description}
8692 @item -L @var{num}
8693 @itemx --tape-length=@var{num}
8694 Change tape after writing @var{num} x 1024 bytes.
8695
8696 This option might be useful when your tape drivers do not properly
8697 detect end of physical tapes. By being slightly conservative on the
8698 maximum tape length, you might avoid the problem entirely.
8699
8700 @xopindex{info-script, short description}
8701 @xopindex{new-volume-script, short description}
8702 @item -F @var{file}
8703 @itemx --info-script=@var{file}
8704 @itemx --new-volume-script=@var{file}
8705 Execute @file{file} at end of each tape. This implies
8706 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8707 description of this option.
8708 @end table
8709
8710 @node Remote Tape Server
8711 @section The Remote Tape Server
8712
8713 @cindex remote tape drive
8714 @pindex rmt
8715 In order to access the tape drive on a remote machine, @command{tar}
8716 uses the remote tape server written at the University of California at
8717 Berkeley. The remote tape server must be installed as
8718 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8719 want to use. @command{tar} calls @command{rmt} by running an
8720 @command{rsh} or @command{remsh} to the remote machine, optionally
8721 using a different login name if one is supplied.
8722
8723 A copy of the source for the remote tape server is provided. It is
8724 Copyright @copyright{} 1983 by the Regents of the University of
8725 California, but can be freely distributed. It is compiled and
8726 installed by default.
8727
8728 @cindex absolute file names
8729 Unless you use the @option{--absolute-names} (@option{-P}) option,
8730 @GNUTAR{} will not allow you to create an archive that contains
8731 absolute file names (a file name beginning with @samp{/}.) If you try,
8732 @command{tar} will automatically remove the leading @samp{/} from the
8733 file names it stores in the archive. It will also type a warning
8734 message telling you what it is doing.
8735
8736 When reading an archive that was created with a different
8737 @command{tar} program, @GNUTAR{} automatically
8738 extracts entries in the archive which have absolute file names as if
8739 the file names were not absolute. This is an important feature. A
8740 visitor here once gave a @command{tar} tape to an operator to restore;
8741 the operator used Sun @command{tar} instead of @GNUTAR{},
8742 and the result was that it replaced large portions of
8743 our @file{/bin} and friends with versions from the tape; needless to
8744 say, we were unhappy about having to recover the file system from
8745 backup tapes.
8746
8747 For example, if the archive contained a file @file{/usr/bin/computoy},
8748 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8749 relative to the current directory. If you want to extract the files in
8750 an archive to the same absolute names that they had when the archive
8751 was created, you should do a @samp{cd /} before extracting the files
8752 from the archive, or you should either use the @option{--absolute-names}
8753 option, or use the command @samp{tar -C / @dots{}}.
8754
8755 @cindex Ultrix 3.1 and write failure
8756 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8757 can claim that a short write near the end of a tape succeeded,
8758 when it actually failed. This will result in the -M option not
8759 working correctly. The best workaround at the moment is to use a
8760 significantly larger blocking factor than the default 20.
8761
8762 In order to update an archive, @command{tar} must be able to backspace the
8763 archive in order to reread or rewrite a record that was just read (or
8764 written). This is currently possible only on two kinds of files: normal
8765 disk files (or any other file that can be backspaced with @samp{lseek}),
8766 and industry-standard 9-track magnetic tape (or any other kind of tape
8767 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8768
8769 This means that the @option{--append}, @option{--concatenate}, and
8770 @option{--delete} commands will not work on any other kind of file.
8771 Some media simply cannot be backspaced, which means these commands and
8772 options will never be able to work on them. These non-backspacing
8773 media include pipes and cartridge tape drives.
8774
8775 Some other media can be backspaced, and @command{tar} will work on them
8776 once @command{tar} is modified to do so.
8777
8778 Archives created with the @option{--multi-volume}, @option{--label}, and
8779 @option{--incremental} (@option{-G}) options may not be readable by other version
8780 of @command{tar}. In particular, restoring a file that was split over
8781 a volume boundary will require some careful work with @command{dd}, if
8782 it can be done at all. Other versions of @command{tar} may also create
8783 an empty file whose name is that of the volume header. Some versions
8784 of @command{tar} may create normal files instead of directories archived
8785 with the @option{--incremental} (@option{-G}) option.
8786
8787 @node Common Problems and Solutions
8788 @section Some Common Problems and their Solutions
8789
8790 @ifclear PUBLISH
8791
8792 @format
8793 errors from system:
8794 permission denied
8795 no such file or directory
8796 not owner
8797
8798 errors from @command{tar}:
8799 directory checksum error
8800 header format error
8801
8802 errors from media/system:
8803 i/o error
8804 device busy
8805 @end format
8806
8807 @end ifclear
8808
8809 @node Blocking
8810 @section Blocking
8811 @UNREVISED
8812
8813 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8814 is also confusing to the expert reader. On the other hand, readers
8815 who are new to the field have a fresh mind, and they may safely skip
8816 the next two paragraphs, as the remainder of this manual uses those
8817 two terms in a quite consistent way.
8818
8819 John Gilmore, the writer of the public domain @command{tar} from which
8820 @GNUTAR{} was originally derived, wrote (June 1995):
8821
8822 @quotation
8823 The nomenclature of tape drives comes from IBM, where I believe
8824 they were invented for the IBM 650 or so. On IBM mainframes, what
8825 is recorded on tape are tape blocks. The logical organization of
8826 data is into records. There are various ways of putting records into
8827 blocks, including @code{F} (fixed sized records), @code{V} (variable
8828 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8829 to a block), @code{VB} (variable size records, @var{n} to a block),
8830 @code{VSB} (variable spanned blocked: variable sized records that can
8831 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8832 parameter specified this to the operating system.
8833
8834 The Unix man page on @command{tar} was totally confused about this.
8835 When I wrote @code{PD TAR}, I used the historically correct terminology
8836 (@command{tar} writes data records, which are grouped into blocks).
8837 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8838 here), and now Fran@,{c}ois has migrated that terminology back
8839 into the source code too.
8840 @end quotation
8841
8842 The term @dfn{physical block} means the basic transfer chunk from or
8843 to a device, after which reading or writing may stop without anything
8844 being lost. In this manual, the term @dfn{block} usually refers to
8845 a disk physical block, @emph{assuming} that each disk block is 512
8846 bytes in length. It is true that some disk devices have different
8847 physical blocks, but @command{tar} ignore these differences in its own
8848 format, which is meant to be portable, so a @command{tar} block is always
8849 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8850 The term @dfn{logical block} often represents the basic chunk of
8851 allocation of many disk blocks as a single entity, which the operating
8852 system treats somewhat atomically; this concept is only barely used
8853 in @GNUTAR{}.
8854
8855 The term @dfn{physical record} is another way to speak of a physical
8856 block, those two terms are somewhat interchangeable. In this manual,
8857 the term @dfn{record} usually refers to a tape physical block,
8858 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8859 It is true that archives may be put on disk or used with pipes,
8860 but nevertheless, @command{tar} tries to read and write the archive one
8861 @dfn{record} at a time, whatever the medium in use. One record is made
8862 up of an integral number of blocks, and this operation of putting many
8863 disk blocks into a single tape block is called @dfn{reblocking}, or
8864 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8865 the logical organization of many characters into something meaningful
8866 to the application. The term @dfn{unit record} describes a small set
8867 of characters which are transmitted whole to or by the application,
8868 and often refers to a line of text. Those two last terms are unrelated
8869 to what we call a @dfn{record} in @GNUTAR{}.
8870
8871 When writing to tapes, @command{tar} writes the contents of the archive
8872 in chunks known as @dfn{records}. To change the default blocking
8873 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8874 @var{512-size}}) option. Each record will then be composed of
8875 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8876 @xref{Standard}.) Each file written to the archive uses at least one
8877 full record. As a result, using a larger record size can result in
8878 more wasted space for small files. On the other hand, a larger record
8879 size can often be read and written much more efficiently.
8880
8881 Further complicating the problem is that some tape drives ignore the
8882 blocking entirely. For these, a larger record size can still improve
8883 performance (because the software layers above the tape drive still
8884 honor the blocking), but not as dramatically as on tape drives that
8885 honor blocking.
8886
8887 When reading an archive, @command{tar} can usually figure out the
8888 record size on itself. When this is the case, and a non-standard
8889 record size was used when the archive was created, @command{tar} will
8890 print a message about a non-standard blocking factor, and then operate
8891 normally. On some tape devices, however, @command{tar} cannot figure
8892 out the record size itself. On most of those, you can specify a
8893 blocking factor (with @option{--blocking-factor}) larger than the
8894 actual blocking factor, and then use the @option{--read-full-records}
8895 (@option{-B}) option. (If you specify a blocking factor with
8896 @option{--blocking-factor} and don't use the
8897 @option{--read-full-records} option, then @command{tar} will not
8898 attempt to figure out the recording size itself.) On some devices,
8899 you must always specify the record size exactly with
8900 @option{--blocking-factor} when reading, because @command{tar} cannot
8901 figure it out. In any case, use @option{--list} (@option{-t}) before
8902 doing any extractions to see whether @command{tar} is reading the archive
8903 correctly.
8904
8905 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8906 putting them into records is to put a whole number of them (one or
8907 more) into each record. @command{tar} records are all the same size;
8908 at the end of the file there's a block containing all zeros, which
8909 is how you tell that the remainder of the last record(s) are garbage.
8910
8911 In a standard @command{tar} file (no options), the block size is 512
8912 and the record size is 10240, for a blocking factor of 20. What the
8913 @option{--blocking-factor} option does is sets the blocking factor,
8914 changing the record size while leaving the block size at 512 bytes.
8915 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8916 most tape drives these days prefer much bigger records in order to
8917 stream and not waste tape. When writing tapes for myself, some tend
8918 to use a factor of the order of 2048, say, giving a record size of
8919 around one megabyte.
8920
8921 If you use a blocking factor larger than 20, older @command{tar}
8922 programs might not be able to read the archive, so we recommend this
8923 as a limit to use in practice. @GNUTAR{}, however,
8924 will support arbitrarily large record sizes, limited only by the
8925 amount of virtual memory or the physical characteristics of the tape
8926 device.
8927
8928 @menu
8929 * Format Variations:: Format Variations
8930 * Blocking Factor:: The Blocking Factor of an Archive
8931 @end menu
8932
8933 @node Format Variations
8934 @subsection Format Variations
8935 @cindex Format Parameters
8936 @cindex Format Options
8937 @cindex Options, archive format specifying
8938 @cindex Options, format specifying
8939 @UNREVISED
8940
8941 Format parameters specify how an archive is written on the archive
8942 media. The best choice of format parameters will vary depending on
8943 the type and number of files being archived, and on the media used to
8944 store the archive.
8945
8946 To specify format parameters when accessing or creating an archive,
8947 you can use the options described in the following sections.
8948 If you do not specify any format parameters, @command{tar} uses
8949 default parameters. You cannot modify a compressed archive.
8950 If you create an archive with the @option{--blocking-factor} option
8951 specified (@pxref{Blocking Factor}), you must specify that
8952 blocking-factor when operating on the archive. @xref{Formats}, for other
8953 examples of format parameter considerations.
8954
8955 @node Blocking Factor
8956 @subsection The Blocking Factor of an Archive
8957 @cindex Blocking Factor
8958 @cindex Record Size
8959 @cindex Number of blocks per record
8960 @cindex Number of bytes per record
8961 @cindex Bytes per record
8962 @cindex Blocks per record
8963 @UNREVISED
8964
8965 @opindex blocking-factor
8966 The data in an archive is grouped into blocks, which are 512 bytes.
8967 Blocks are read and written in whole number multiples called
8968 @dfn{records}. The number of blocks in a record (i.e. the size of a
8969 record in units of 512 bytes) is called the @dfn{blocking factor}.
8970 The @option{--blocking-factor=@var{512-size}} (@option{-b
8971 @var{512-size}}) option specifies the blocking factor of an archive.
8972 The default blocking factor is typically 20 (i.e., 10240 bytes), but
8973 can be specified at installation. To find out the blocking factor of
8974 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
8975 This may not work on some devices.
8976
8977 Records are separated by gaps, which waste space on the archive media.
8978 If you are archiving on magnetic tape, using a larger blocking factor
8979 (and therefore larger records) provides faster throughput and allows you
8980 to fit more data on a tape (because there are fewer gaps). If you are
8981 archiving on cartridge, a very large blocking factor (say 126 or more)
8982 greatly increases performance. A smaller blocking factor, on the other
8983 hand, may be useful when archiving small files, to avoid archiving lots
8984 of nulls as @command{tar} fills out the archive to the end of the record.
8985 In general, the ideal record size depends on the size of the
8986 inter-record gaps on the tape you are using, and the average size of the
8987 files you are archiving. @xref{create}, for information on
8988 writing archives.
8989
8990 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
8991
8992 Archives with blocking factors larger than 20 cannot be read
8993 by very old versions of @command{tar}, or by some newer versions
8994 of @command{tar} running on old machines with small address spaces.
8995 With @GNUTAR{}, the blocking factor of an archive is limited
8996 only by the maximum record size of the device containing the archive,
8997 or by the amount of available virtual memory.
8998
8999 Also, on some systems, not using adequate blocking factors, as sometimes
9000 imposed by the device drivers, may yield unexpected diagnostics. For
9001 example, this has been reported:
9002
9003 @smallexample
9004 Cannot write to /dev/dlt: Invalid argument
9005 @end smallexample
9006
9007 @noindent
9008 In such cases, it sometimes happen that the @command{tar} bundled by
9009 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9010 requires an explicit specification for the block size,
9011 which it cannot guess. This yields some people to consider
9012 @GNUTAR{} is misbehaving, because by comparison,
9013 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9014 for example, might resolve the problem.
9015
9016 If you use a non-default blocking factor when you create an archive, you
9017 must specify the same blocking factor when you modify that archive. Some
9018 archive devices will also require you to specify the blocking factor when
9019 reading that archive, however this is not typically the case. Usually, you
9020 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9021 reports a non-default record size and then lists the archive members as
9022 it would normally. To extract files from an archive with a non-standard
9023 blocking factor (particularly if you're not sure what the blocking factor
9024 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9025 specifying a blocking factor larger then the blocking factor of the archive
9026 (i.e. @samp{tar --extract --read-full-records --blocking-factor=300}.
9027 @xref{list}, for more information on the @option{--list} (@option{-t})
9028 operation. @xref{Reading}, for a more detailed explanation of that option.
9029
9030 @table @option
9031 @item --blocking-factor=@var{number}
9032 @itemx -b @var{number}
9033 Specifies the blocking factor of an archive. Can be used with any
9034 operation, but is usually not necessary with @option{--list} (@option{-t}).
9035 @end table
9036
9037 Device blocking
9038
9039 @table @option
9040 @item -b @var{blocks}
9041 @itemx --blocking-factor=@var{blocks}
9042 Set record size to @math{@var{blocks} * 512} bytes.
9043
9044 This option is used to specify a @dfn{blocking factor} for the archive.
9045 When reading or writing the archive, @command{tar}, will do reads and writes
9046 of the archive in records of @math{@var{block}*512} bytes. This is true
9047 even when the archive is compressed. Some devices requires that all
9048 write operations be a multiple of a certain size, and so, @command{tar}
9049 pads the archive out to the next record boundary.
9050
9051 The default blocking factor is set when @command{tar} is compiled, and is
9052 typically 20. Blocking factors larger than 20 cannot be read by very
9053 old versions of @command{tar}, or by some newer versions of @command{tar}
9054 running on old machines with small address spaces.
9055
9056 With a magnetic tape, larger records give faster throughput and fit
9057 more data on a tape (because there are fewer inter-record gaps).
9058 If the archive is in a disk file or a pipe, you may want to specify
9059 a smaller blocking factor, since a large one will result in a large
9060 number of null bytes at the end of the archive.
9061
9062 When writing cartridge or other streaming tapes, a much larger
9063 blocking factor (say 126 or more) will greatly increase performance.
9064 However, you must specify the same blocking factor when reading or
9065 updating the archive.
9066
9067 Apparently, Exabyte drives have a physical block size of 8K bytes.
9068 If we choose our blocksize as a multiple of 8k bytes, then the problem
9069 seems to disappear. Id est, we are using block size of 112 right
9070 now, and we haven't had the problem since we switched@dots{}
9071
9072 With @GNUTAR{} the blocking factor is limited only
9073 by the maximum record size of the device containing the archive, or by
9074 the amount of available virtual memory.
9075
9076 However, deblocking or reblocking is virtually avoided in a special
9077 case which often occurs in practice, but which requires all the
9078 following conditions to be simultaneously true:
9079 @itemize @bullet
9080 @item
9081 the archive is subject to a compression option,
9082 @item
9083 the archive is not handled through standard input or output, nor
9084 redirected nor piped,
9085 @item
9086 the archive is directly handled to a local disk, instead of any special
9087 device,
9088 @item
9089 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9090 invocation.
9091 @end itemize
9092
9093 If the output goes directly to a local disk, and not through
9094 stdout, then the last write is not extended to a full record size.
9095 Otherwise, reblocking occurs. Here are a few other remarks on this
9096 topic:
9097
9098 @itemize @bullet
9099
9100 @item
9101 @command{gzip} will complain about trailing garbage if asked to
9102 uncompress a compressed archive on tape, there is an option to turn
9103 the message off, but it breaks the regularity of simply having to use
9104 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9105 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9106 Gailly, by sending a copy of this message to him.
9107
9108 @item
9109 @command{compress} does not show this problem, but as Jean-loup pointed
9110 out to Michael, @samp{compress -d} silently adds garbage after
9111 the result of decompression, which tar ignores because it already
9112 recognized its end-of-file indicator. So this bug may be safely
9113 ignored.
9114
9115 @item
9116 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9117 but will still return an exit status of 2 which tar reports in turn.
9118 @command{tar} might ignore the exit status returned, but I hate doing
9119 that, as it weakens the protection @command{tar} offers users against
9120 other possible problems at decompression time. If @command{gzip} was
9121 silently skipping trailing zeros @emph{and} also avoiding setting the
9122 exit status in this innocuous case, that would solve this situation.
9123
9124 @item
9125 @command{tar} should become more solid at not stopping to read a pipe at
9126 the first null block encountered. This inelegantly breaks the pipe.
9127 @command{tar} should rather drain the pipe out before exiting itself.
9128 @end itemize
9129
9130 @xopindex{ignore-zeros, short description}
9131 @item -i
9132 @itemx --ignore-zeros
9133 Ignore blocks of zeros in archive (means EOF).
9134
9135 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9136 of zeros in the archive. Normally a block of zeros indicates the
9137 end of the archive, but when reading a damaged archive, or one which
9138 was created by concatenating several archives together, this option
9139 allows @command{tar} to read the entire archive. This option is not on
9140 by default because many versions of @command{tar} write garbage after
9141 the zeroed blocks.
9142
9143 Note that this option causes @command{tar} to read to the end of the
9144 archive file, which may sometimes avoid problems when multiple files
9145 are stored on a single physical tape.
9146
9147 @xopindex{read-full-records, short description}
9148 @item -B
9149 @itemx --read-full-records
9150 Reblock as we read (for reading 4.2BSD pipes).
9151
9152 If @option{--read-full-records} is used, @command{tar}
9153 will not panic if an attempt to read a record from the archive does
9154 not return a full record. Instead, @command{tar} will keep reading
9155 until it has obtained a full
9156 record.
9157
9158 This option is turned on by default when @command{tar} is reading
9159 an archive from standard input, or from a remote machine. This is
9160 because on BSD Unix systems, a read of a pipe will return however
9161 much happens to be in the pipe, even if it is less than @command{tar}
9162 requested. If this option was not used, @command{tar} would fail as
9163 soon as it read an incomplete record from the pipe.
9164
9165 This option is also useful with the commands for updating an archive.
9166
9167 @end table
9168
9169 Tape blocking
9170
9171 @FIXME{Appropriate options should be moved here from elsewhere.}
9172
9173 @cindex blocking factor
9174 @cindex tape blocking
9175
9176 When handling various tapes or cartridges, you have to take care of
9177 selecting a proper blocking, that is, the number of disk blocks you
9178 put together as a single tape block on the tape, without intervening
9179 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9180 with no information on it, used for decelerating the tape to a
9181 full stop, and for later regaining the reading or writing speed.
9182 When the tape driver starts reading a record, the record has to
9183 be read whole without stopping, as a tape gap is needed to stop the
9184 tape motion without loosing information.
9185
9186 @cindex Exabyte blocking
9187 @cindex DAT blocking
9188 Using higher blocking (putting more disk blocks per tape block) will use
9189 the tape more efficiently as there will be less tape gaps. But reading
9190 such tapes may be more difficult for the system, as more memory will be
9191 required to receive at once the whole record. Further, if there is a
9192 reading error on a huge record, this is less likely that the system will
9193 succeed in recovering the information. So, blocking should not be too
9194 low, nor it should be too high. @command{tar} uses by default a blocking of
9195 20 for historical reasons, and it does not really matter when reading or
9196 writing to disk. Current tape technology would easily accommodate higher
9197 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9198 We were told that for some DLT drives, the blocking should be a multiple
9199 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9200 Other manufacturers may use different recommendations for the same tapes.
9201 This might also depends of the buffering techniques used inside modern
9202 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9203 Others request blocking to be some exponent of two.
9204
9205 So, there is no fixed rule for blocking. But blocking at read time
9206 should ideally be the same as blocking used at write time. At one place
9207 I know, with a wide variety of equipment, they found it best to use a
9208 blocking of 32 to guarantee that their tapes are fully interchangeable.
9209
9210 I was also told that, for recycled tapes, prior erasure (by the same
9211 drive unit that will be used to create the archives) sometimes lowers
9212 the error rates observed at rewriting time.
9213
9214 I might also use @option{--number-blocks} instead of
9215 @option{--block-number}, so @option{--block} will then expand to
9216 @option{--blocking-factor} unambiguously.
9217
9218 @node Many
9219 @section Many Archives on One Tape
9220
9221 @FIXME{Appropriate options should be moved here from elsewhere.}
9222
9223 @findex ntape @r{device}
9224 Most tape devices have two entries in the @file{/dev} directory, or
9225 entries that come in pairs, which differ only in the minor number for
9226 this device. Let's take for example @file{/dev/tape}, which often
9227 points to the only or usual tape device of a given system. There might
9228 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9229 name is the @emph{rewinding} version of the device, while the name
9230 having @samp{nr} in it is the @emph{no rewinding} version of the same
9231 device.
9232
9233 A rewinding tape device will bring back the tape to its beginning point
9234 automatically when this device is opened or closed. Since @command{tar}
9235 opens the archive file before using it and closes it afterwards, this
9236 means that a simple:
9237
9238 @smallexample
9239 $ @kbd{tar cf /dev/tape @var{directory}}
9240 @end smallexample
9241
9242 @noindent
9243 will reposition the tape to its beginning both prior and after saving
9244 @var{directory} contents to it, thus erasing prior tape contents and
9245 making it so that any subsequent write operation will destroy what has
9246 just been saved.
9247
9248 @cindex tape positioning
9249 So, a rewinding device is normally meant to hold one and only one file.
9250 If you want to put more than one @command{tar} archive on a given tape, you
9251 will need to avoid using the rewinding version of the tape device. You
9252 will also have to pay special attention to tape positioning. Errors in
9253 positioning may overwrite the valuable data already on your tape. Many
9254 people, burnt by past experiences, will only use rewinding devices and
9255 limit themselves to one file per tape, precisely to avoid the risk of
9256 such errors. Be fully aware that writing at the wrong position on a
9257 tape loses all information past this point and most probably until the
9258 end of the tape, and this destroyed information @emph{cannot} be
9259 recovered.
9260
9261 To save @var{directory-1} as a first archive at the beginning of a
9262 tape, and leave that tape ready for a second archive, you should use:
9263
9264 @smallexample
9265 $ @kbd{mt -f /dev/nrtape rewind}
9266 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9267 @end smallexample
9268
9269 @cindex tape marks
9270 @dfn{Tape marks} are special magnetic patterns written on the tape
9271 media, which are later recognizable by the reading hardware. These
9272 marks are used after each file, when there are many on a single tape.
9273 An empty file (that is to say, two tape marks in a row) signal the
9274 logical end of the tape, after which no file exist. Usually,
9275 non-rewinding tape device drivers will react to the close request issued
9276 by @command{tar} by first writing two tape marks after your archive, and by
9277 backspacing over one of these. So, if you remove the tape at that time
9278 from the tape drive, it is properly terminated. But if you write
9279 another file at the current position, the second tape mark will be
9280 erased by the new information, leaving only one tape mark between files.
9281
9282 So, you may now save @var{directory-2} as a second archive after the
9283 first on the same tape by issuing the command:
9284
9285 @smallexample
9286 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9287 @end smallexample
9288
9289 @noindent
9290 and so on for all the archives you want to put on the same tape.
9291
9292 Another usual case is that you do not write all the archives the same
9293 day, and you need to remove and store the tape between two archive
9294 sessions. In general, you must remember how many files are already
9295 saved on your tape. Suppose your tape already has 16 files on it, and
9296 that you are ready to write the 17th. You have to take care of skipping
9297 the first 16 tape marks before saving @var{directory-17}, say, by using
9298 these commands:
9299
9300 @smallexample
9301 $ @kbd{mt -f /dev/nrtape rewind}
9302 $ @kbd{mt -f /dev/nrtape fsf 16}
9303 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9304 @end smallexample
9305
9306 In all the previous examples, we put aside blocking considerations, but
9307 you should do the proper things for that as well. @xref{Blocking}.
9308
9309 @menu
9310 * Tape Positioning:: Tape Positions and Tape Marks
9311 * mt:: The @command{mt} Utility
9312 @end menu
9313
9314 @node Tape Positioning
9315 @subsection Tape Positions and Tape Marks
9316 @UNREVISED
9317
9318 Just as archives can store more than one file from the file system,
9319 tapes can store more than one archive file. To keep track of where
9320 archive files (or any other type of file stored on tape) begin and
9321 end, tape archive devices write magnetic @dfn{tape marks} on the
9322 archive media. Tape drives write one tape mark between files,
9323 two at the end of all the file entries.
9324
9325 If you think of data as a series of records "rrrr"'s, and tape marks as
9326 "*"'s, a tape might look like the following:
9327
9328 @smallexample
9329 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9330 @end smallexample
9331
9332 Tape devices read and write tapes using a read/write @dfn{tape
9333 head}---a physical part of the device which can only access one
9334 point on the tape at a time. When you use @command{tar} to read or
9335 write archive data from a tape device, the device will begin reading
9336 or writing from wherever on the tape the tape head happens to be,
9337 regardless of which archive or what part of the archive the tape
9338 head is on. Before writing an archive, you should make sure that no
9339 data on the tape will be overwritten (unless it is no longer needed).
9340 Before reading an archive, you should make sure the tape head is at
9341 the beginning of the archive you want to read. You can do it manually
9342 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9343 that automatically (@pxref{Scripted Restoration}).
9344
9345 If you want to add new archive file entries to a tape, you should
9346 advance the tape to the end of the existing file entries, backspace
9347 over the last tape mark, and write the new archive file. If you were
9348 to add two archives to the example above, the tape might look like the
9349 following:
9350
9351 @smallexample
9352 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9353 @end smallexample
9354
9355 @node mt
9356 @subsection The @command{mt} Utility
9357 @UNREVISED
9358
9359 @FIXME{Is it true that this only works on non-block devices?
9360 should explain the difference, (fixed or variable).}
9361 @xref{Blocking Factor}.
9362
9363 You can use the @command{mt} utility to advance or rewind a tape past a
9364 specified number of archive files on the tape. This will allow you
9365 to move to the beginning of an archive before extracting or reading
9366 it, or to the end of all the archives before writing a new one.
9367 @FIXME{Why isn't there an "advance 'til you find two tape marks
9368 together"?}
9369
9370 The syntax of the @command{mt} command is:
9371
9372 @smallexample
9373 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9374 @end smallexample
9375
9376 where @var{tapename} is the name of the tape device, @var{number} is
9377 the number of times an operation is performed (with a default of one),
9378 and @var{operation} is one of the following:
9379
9380 @FIXME{is there any use for record operations?}
9381
9382 @table @option
9383 @item eof
9384 @itemx weof
9385 Writes @var{number} tape marks at the current position on the tape.
9386
9387 @item fsf
9388 Moves tape position forward @var{number} files.
9389
9390 @item bsf
9391 Moves tape position back @var{number} files.
9392
9393 @item rewind
9394 Rewinds the tape. (Ignores @var{number}).
9395
9396 @item offline
9397 @itemx rewoff1
9398 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9399
9400 @item status
9401 Prints status information about the tape unit.
9402
9403 @end table
9404
9405 @FIXME{Is there a better way to frob the spacing on the list?}
9406
9407 If you don't specify a @var{tapename}, @command{mt} uses the environment
9408 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9409 the default device specified in your @file{sys/mtio.h} file
9410 (@code{DEFTAPE} variable). If this is not defined, the program will
9411 display a descriptive error message and exit with code 1.
9412
9413 @command{mt} returns a 0 exit status when the operation(s) were
9414 successful, 1 if the command was unrecognized, and 2 if an operation
9415 failed.
9416
9417 @node Using Multiple Tapes
9418 @section Using Multiple Tapes
9419
9420 Often you might want to write a large archive, one larger than will fit
9421 on the actual tape you are using. In such a case, you can run multiple
9422 @command{tar} commands, but this can be inconvenient, particularly if you
9423 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9424 Therefore, @command{tar} provides a special mode for creating
9425 multi-volume archives.
9426
9427 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9428 on several media volumes of fixed size. Although in this section we will
9429 often call @samp{volume} a @dfn{tape}, there is absolutely no
9430 requirement for multi-volume archives to be stored on tapes. Instead,
9431 they can use whatever media type the user finds convenient, they can
9432 even be located on files.
9433
9434 When creating a multi-volume arvhive, @GNUTAR{} continues to fill
9435 current volume until it runs out of space, then it switches to
9436 next volume (usually the operator is queried to replace the tape on
9437 this point), and continues working on the new volume. This operation
9438 continues untill all requested files are dumped. If @GNUTAR{} detects
9439 end of media while dumping a file, such a file is archived in split
9440 form. Some very big files can even be split across several volumes.
9441
9442 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9443 without any special options. Consequently any file member residing
9444 entirely on one volume can be extracted or otherwise operated upon
9445 without needing the other volume. Sure enough, to extract a split
9446 member you would need all volumes its parts reside on.
9447
9448 Multi-volume archives suffer from several limitations. In particular,
9449 they cannot be compressed.
9450
9451 @GNUTAR{} is able to create multi-volume archives of two formats
9452 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9453
9454 @menu
9455 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9456 * Tape Files:: Tape Files
9457 * Tarcat:: Concatenate Volumes into a Single Archive
9458
9459 @end menu
9460
9461 @node Multi-Volume Archives
9462 @subsection Archives Longer than One Tape or Disk
9463 @cindex Multi-volume archives
9464
9465 @opindex multi-volume
9466 To create an archive that is larger than will fit on a single unit of
9467 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9468 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9469 archive can be manipulated like any other archive (provided the
9470 @option{--multi-volume} option is specified), but is stored on more
9471 than one tape or disk.
9472
9473 When you specify @option{--multi-volume}, @command{tar} does not report an
9474 error when it comes to the end of an archive volume (when reading), or
9475 the end of the media (when writing). Instead, it prompts you to load
9476 a new storage volume. If the archive is on a magnetic tape, you
9477 should change tapes when you see the prompt; if the archive is on a
9478 floppy disk, you should change disks; etc.
9479
9480 @table @option
9481 @item --multi-volume
9482 @itemx -M
9483 Creates a multi-volume archive, when used in conjunction with
9484 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9485 archive, specify @option{--multi-volume} in conjunction with that
9486 operation.
9487 For example:
9488
9489 @smallexample
9490 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9491 @end smallexample
9492 @end table
9493
9494 The method @command{tar} uses to detect end of tape is not perfect, and
9495 fails on some operating systems or on some devices. If @command{tar}
9496 cannot detect the end of the tape itself, you can use
9497 @option{--tape-length} option to inform it about the capacity of the
9498 tape:
9499
9500 @anchor{tape-length}
9501 @table @option
9502 @opindex tape-length
9503 @item --tape-length=@var{size}
9504 @itemx -L @var{size}
9505 Set maximum length of a volume. The @var{size} argument should then
9506 be the usable size of the tape in units of 1024 bytes. This option
9507 selects @option{--multi-volume} automatically. For example:
9508
9509 @smallexample
9510 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9511 @end smallexample
9512 @end table
9513
9514 @anchor{change volume prompt}
9515 When @GNUTAR{} comes to the end of a storage media, it asks you to
9516 change the volume. The built-in prompt for POSIX locale
9517 is@footnote{If you run @GNUTAR{} under a different locale, the
9518 translation to the locale's language will be used.}:
9519
9520 @smallexample
9521 Prepare volume #@var{n} for `@var{archive}' and hit return:
9522 @end smallexample
9523
9524 @noindent
9525 where @var{n} is the ordinal number of the volume to be created and
9526 @var{archive} is archive file or device name.
9527
9528 When prompting for a new tape, @command{tar} accepts any of the following
9529 responses:
9530
9531 @table @kbd
9532 @item ?
9533 Request @command{tar} to explain possible responses
9534 @item q
9535 Request @command{tar} to exit immediately.
9536 @item n @var{file-name}
9537 Request @command{tar} to write the next volume on the file @var{file-name}.
9538 @item !
9539 Request @command{tar} to run a subshell. This option can be disabled
9540 by giving @option{--restrict} command line option to
9541 @command{tar}@footnote{@xref{--restrict}, for more information about
9542 this option}.
9543 @item y
9544 Request @command{tar} to begin writing the next volume.
9545 @end table
9546
9547 (You should only type @samp{y} after you have changed the tape;
9548 otherwise @command{tar} will write over the volume it just finished.)
9549
9550 @cindex Volume number file
9551 @cindex volno file
9552 @anchor{volno-file}
9553 @opindex volno-file
9554 The volume number used by @command{tar} in its tape-changing prompt
9555 can be changed; if you give the
9556 @option{--volno-file=@var{file-of-number}} option, then
9557 @var{file-of-number} should be an unexisting file to be created, or
9558 else, a file already containing a decimal number. That number will be
9559 used as the volume number of the first volume written. When
9560 @command{tar} is finished, it will rewrite the file with the
9561 now-current volume number. (This does not change the volume number
9562 written on a tape label, as per @ref{label}, it @emph{only} affects
9563 the number used in the prompt.)
9564
9565 @cindex End-of-archive info script
9566 @cindex Info script
9567 @anchor{info-script}
9568 @opindex info-script
9569 @opindex new-volume-script
9570 If you want more elaborate behavior than this, you can write a special
9571 @dfn{new volume script}, that will be responsible for changing the
9572 volume, and instruct @command{tar} to use it instead of its normal
9573 prompting procedure:
9574
9575 @table @option
9576 @item --info-script=@var{script-name}
9577 @itemx --new-volume-script=@var{script-name}
9578 @itemx -F @var{script-name}
9579 Specify the full name of the volume script to use. The script can be
9580 used to eject cassettes, or to broadcast messages such as
9581 @samp{Someone please come change my tape} when performing unattended
9582 backups.
9583 @end table
9584
9585 The @var{script-name} is executed without any command line
9586 arguments. It inherits @command{tar}'s shell environment.
9587 Additional data is passed to it via the following
9588 environment variables:
9589
9590 @table @env
9591 @vrindex TAR_VERSION, info script environment variable
9592 @item TAR_VERSION
9593 @GNUTAR{} version number.
9594
9595 @vrindex TAR_ARCHIVE, info script environment variable
9596 @item TAR_ARCHIVE
9597 The name of the archive @command{tar} is processing.
9598
9599 @vrindex TAR_VOLUME, info script environment variable
9600 @item TAR_VOLUME
9601 Ordinal number of the volume @command{tar} is about to start.
9602
9603 @vrindex TAR_SUBCOMMAND, info script environment variable
9604 @item TAR_SUBCOMMAND
9605 Short option describing the operation @command{tar} is executing
9606 @xref{Operations}, for a complete list of subcommand options.
9607
9608 @vrindex TAR_FORMAT, info script environment variable
9609 @item TAR_FORMAT
9610 Format of the archive being processed. @xref{Formats}, for a complete
9611 list of archive format names.
9612 @end table
9613
9614 The volume script can instruct @command{tar} to use new archive name,
9615 by writing in to file descriptor 3 (see below for an example).
9616
9617 If the info script fails, @command{tar} exits; otherwise, it begins
9618 writing the next volume.
9619
9620 If you want @command{tar} to cycle through a series of files or tape
9621 drives, there are three approaches to choose from. First of all, you
9622 can give @command{tar} multiple @option{--file} options. In this case
9623 the specified files will be used, in sequence, as the successive
9624 volumes of the archive. Only when the first one in the sequence needs
9625 to be used again will @command{tar} prompt for a tape change (or run
9626 the info script). For example, suppose someone has two tape drives on
9627 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
9628 @GNUTAR{} to switch to the second drive when it needs to write the
9629 second tape, and then back to the first tape, etc., just do either of:
9630
9631 @smallexample
9632 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9633 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9634 @end smallexample
9635
9636 The second method is to use the @samp{n} response to the tape-change
9637 prompt.
9638
9639 Finally, the most flexible approach is to use a volume script, that
9640 writes new archive name to the file descriptor #3. For example, the
9641 following volume script will create a series of archive files, named
9642 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
9643 archive being created (as given by @option{--file} option) and
9644 @var{vol} is the ordinal number of the archive being created:
9645
9646 @smallexample
9647 @group
9648 #! /bin/sh
9649 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9650
9651 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9652 case $TAR_SUBCOMMAND in
9653 -c) ;;
9654 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9655 ;;
9656 *) exit 1
9657 esac
9658
9659 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9660 @end group
9661 @end smallexample
9662
9663 The same script cant be used while listing, comparing or extracting
9664 from the created archive. For example:
9665
9666 @smallexample
9667 @group
9668 # @r{Create a multi-volume archive:}
9669 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
9670 # @r{Extract from the created archive:}
9671 $ @kbd{tar -x -f archive.tar -F new-volume .}
9672 @end group
9673 @end smallexample
9674
9675 @noindent
9676 Notice, that the first command had to use @option{-L} option, since
9677 otherwise @GNUTAR{} will end up writing everything to file
9678 @file{archive.tar}.
9679
9680 You can read each individual volume of a multi-volume archive as if it
9681 were an archive by itself. For example, to list the contents of one
9682 volume, use @option{--list}, without @option{--multi-volume} specified.
9683 To extract an archive member from one volume (assuming it is described
9684 that volume), use @option{--extract}, again without
9685 @option{--multi-volume}.
9686
9687 If an archive member is split across volumes (i.e. its entry begins on
9688 one volume of the media and ends on another), you need to specify
9689 @option{--multi-volume} to extract it successfully. In this case, you
9690 should load the volume where the archive member starts, and use
9691 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9692 volumes as it needs them. @xref{extracting archives}, for more
9693 information about extracting archives.
9694
9695 Multi-volume archives can be modified like any other archive. To add
9696 files to a multi-volume archive, you need to only mount the last
9697 volume of the archive media (and new volumes, if needed). For all
9698 other operations, you need to use the entire archive.
9699
9700 If a multi-volume archive was labeled using
9701 @option{--label=@var{archive-label}} (@pxref{label}) when it was
9702 created, @command{tar} will not automatically label volumes which are
9703 added later. To label subsequent volumes, specify
9704 @option{--label=@var{archive-label}} again in conjunction with the
9705 @option{--append}, @option{--update} or @option{--concatenate} operation.
9706
9707 @FIXME{This is no longer true: Multivolume archives in @samp{POSIX}
9708 format can be extracted using any posix-compliant tar
9709 implementation. The split members can then be recreated from parts
9710 using a simple shell script. Provide more information about it:}
9711 Beware that there is @emph{no} real standard about the proper way, for
9712 a @command{tar} archive, to span volume boundaries. If you have a
9713 multi-volume created by some vendor's @command{tar}, there is almost
9714 no chance you could read all the volumes with @GNUTAR{}.
9715 The converse is also true: you may not expect
9716 multi-volume archives created by @GNUTAR{} to be
9717 fully recovered by vendor's @command{tar}. Since there is little
9718 chance that, in mixed system configurations, some vendor's
9719 @command{tar} will work on another vendor's machine, and there is a
9720 great chance that @GNUTAR{} will work on most of
9721 them, your best bet is to install @GNUTAR{} on all
9722 machines between which you know exchange of files is possible.
9723
9724 @node Tape Files
9725 @subsection Tape Files
9726 @UNREVISED
9727
9728 To give the archive a name which will be recorded in it, use the
9729 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9730 option. This will write a special block identifying
9731 @var{volume-label} as the name of the archive to the front of the
9732 archive which will be displayed when the archive is listed with
9733 @option{--list}. If you are creating a multi-volume archive with
9734 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9735 volume label will have @samp{Volume @var{nnn}} appended to the name
9736 you give, where @var{nnn} is the number of the volume of the archive.
9737 (If you use the @option{--label=@var{volume-label}}) option when
9738 reading an archive, it checks to make sure the label on the tape
9739 matches the one you give. @xref{label}.
9740
9741 When @command{tar} writes an archive to tape, it creates a single
9742 tape file. If multiple archives are written to the same tape, one
9743 after the other, they each get written as separate tape files. When
9744 extracting, it is necessary to position the tape at the right place
9745 before running @command{tar}. To do this, use the @command{mt} command.
9746 For more information on the @command{mt} command and on the organization
9747 of tapes into a sequence of tape files, see @ref{mt}.
9748
9749 People seem to often do:
9750
9751 @smallexample
9752 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9753 @end smallexample
9754
9755 or such, for pushing a common date in all volumes or an archive set.
9756
9757 @node Tarcat
9758 @subsection Concatenate Volumes into a Single Archive
9759
9760 @pindex tarcat
9761 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9762 archive to a single @command{tar} archive. Simply concatenating all
9763 volumes into one will not work, since each volume carries an additional
9764 information at the beginning. @GNUTAR{} is shipped with the shell
9765 script @command{tarcat} designed for this purpose.
9766
9767 The script takes a list of files comprising a multi-volume archive
9768 and creates the resulting archive at the standard output. For example:
9769
9770 @smallexample
9771 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9772 @end smallexample
9773
9774 The script implements a simple heuristics to determine the format of
9775 the first volume file and to decide how to process the rest of the
9776 files. However, it makes no attempt to verify whether the files are
9777 given in order or even if they are valid @command{tar} archives.
9778 It uses @command{dd} and does not filter its standard error, so you
9779 will usually see lots of spurious messages.
9780
9781 @FIXME{The script is not installed. Should we install it?}
9782
9783 @node label
9784 @section Including a Label in the Archive
9785 @cindex Labeling an archive
9786 @cindex Labels on the archive media
9787 @cindex Labeling multi-volume archives
9788 @UNREVISED
9789
9790 @opindex label
9791 To avoid problems caused by misplaced paper labels on the archive
9792 media, you can include a @dfn{label} entry---an archive member which
9793 contains the name of the archive---in the archive itself. Use the
9794 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9795 option in conjunction with the @option{--create} operation to include
9796 a label entry in the archive as it is being created.
9797
9798 @table @option
9799 @item --label=@var{archive-label}
9800 @itemx -V @var{archive-label}
9801 Includes an @dfn{archive-label} at the beginning of the archive when
9802 the archive is being created, when used in conjunction with the
9803 @option{--create} operation. Checks to make sure the archive label
9804 matches the one specified (when used in conjunction with any other
9805 operation.
9806 @end table
9807
9808 If you create an archive using both
9809 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9810 and @option{--multi-volume} (@option{-M}), each volume of the archive
9811 will have an archive label of the form @samp{@var{archive-label}
9812 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9813 next, and so on. @xref{Using Multiple Tapes}, for information on
9814 creating multiple volume archives.
9815
9816 @cindex Volume label, listing
9817 @cindex Listing volume label
9818 The volume label will be displayed by @option{--list} along with
9819 the file contents. If verbose display is requested, it will also be
9820 explicitely marked as in the example below:
9821
9822 @smallexample
9823 @group
9824 $ @kbd{tar --verbose --list --file=iamanarchive}
9825 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9826 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9827 @end group
9828 @end smallexample
9829
9830 @opindex test-label
9831 @anchor{--test-label option}
9832 However, @option{--list} option will cause listing entire
9833 contents of the archive, which may be undesirable (for example, if the
9834 archive is stored on a tape). You can request checking only the volume
9835 by specifying @option{--test-label} option. This option reads only the
9836 first block of an archive, so it can be used with slow storage
9837 devices. For example:
9838
9839 @smallexample
9840 @group
9841 $ @kbd{tar --test-label --file=iamanarchive}
9842 iamalabel
9843 @end group
9844 @end smallexample
9845
9846 If @option{--test-label} is used with a single command line
9847 argument, @command{tar} compares the volume label with the
9848 argument. It exits with code 0 if the two strings match, and with code
9849 2 otherwise. In this case no output is displayed. For example:
9850
9851 @smallexample
9852 @group
9853 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9854 @result{} 0
9855 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9856 @result{} 1
9857 @end group
9858 @end smallexample
9859
9860 If you request any operation, other than @option{--create}, along
9861 with using @option{--label} option, @command{tar} will first check if
9862 the archive label matches the one specified and will refuse to proceed
9863 if it does not. Use this as a safety precaution to avoid accidentally
9864 overwriting existing archives. For example, if you wish to add files
9865 to @file{archive}, presumably labelled with string @samp{My volume},
9866 you will get:
9867
9868 @smallexample
9869 @group
9870 $ @kbd{tar -rf archive --label 'My volume' .}
9871 tar: Archive not labeled to match `My volume'
9872 @end group
9873 @end smallexample
9874
9875 @noindent
9876 in case its label does not match. This will work even if
9877 @file{archive} is not labelled at all.
9878
9879 Similarly, @command{tar} will refuse to list or extract the
9880 archive if its label doesn't match the @var{archive-label}
9881 specified. In those cases, @var{archive-label} argument is interpreted
9882 as a globbing-style pattern which must match the actual magnetic
9883 volume label. @xref{exclude}, for a precise description of how match
9884 is attempted@footnote{Previous versions of @command{tar} used full
9885 regular expression matching, or before that, only exact string
9886 matching, instead of wildcard matchers. We decided for the sake of
9887 simplicity to use a uniform matching device through
9888 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
9889 the volume label matcher will also suffix @var{archive-label} by
9890 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
9891 up. Since the volume numbering is automatically added in labels at
9892 creation time, it sounded logical to equally help the user taking care
9893 of it when the archive is being read.
9894
9895 The @option{--label} was once called @option{--volume}, but is not
9896 available under that name anymore.
9897
9898 You can also use @option{--label} to get a common information on
9899 all tapes of a series. For having this information different in each
9900 series created through a single script used on a regular basis, just
9901 manage to get some date string as part of the label. For example:
9902
9903 @smallexample
9904 @group
9905 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9906 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9907 --volume="Daily backup for `date +%Y-%m-%d`"}
9908 @end group
9909 @end smallexample
9910
9911 Also note that each label has its own date and time, which corresponds
9912 to when @GNUTAR{} initially attempted to write it,
9913 often soon after the operator launches @command{tar} or types the
9914 carriage return telling that the next tape is ready. Comparing date
9915 labels does give an idea of tape throughput only if the delays for
9916 rewinding tapes and the operator switching them were negligible, which
9917 is usually not the case.
9918
9919 @node verify
9920 @section Verifying Data as It is Stored
9921 @cindex Verifying a write operation
9922 @cindex Double-checking a write operation
9923
9924 @table @option
9925 @item -W
9926 @itemx --verify
9927 @opindex verify, short description
9928 Attempt to verify the archive after writing.
9929 @end table
9930
9931 This option causes @command{tar} to verify the archive after writing it.
9932 Each volume is checked after it is written, and any discrepancies
9933 are recorded on the standard error output.
9934
9935 Verification requires that the archive be on a back-space-able medium.
9936 This means pipes, some cartridge tape drives, and some other devices
9937 cannot be verified.
9938
9939 You can insure the accuracy of an archive by comparing files in the
9940 system with archive members. @command{tar} can compare an archive to the
9941 file system as the archive is being written, to verify a write
9942 operation, or can compare a previously written archive, to insure that
9943 it is up to date.
9944
9945 @xopindex{verify, using with @option{--create}}
9946 @xopindex{create, using with @option{--verify}}
9947 To check for discrepancies in an archive immediately after it is
9948 written, use the @option{--verify} (@option{-W}) option in conjunction with
9949 the @option{--create} operation. When this option is
9950 specified, @command{tar} checks archive members against their counterparts
9951 in the file system, and reports discrepancies on the standard error.
9952
9953 To verify an archive, you must be able to read it from before the end
9954 of the last written entry. This option is useful for detecting data
9955 errors on some tapes. Archives written to pipes, some cartridge tape
9956 drives, and some other devices cannot be verified.
9957
9958 One can explicitly compare an already made archive with the file
9959 system by using the @option{--compare} (@option{--diff}, @option{-d})
9960 option, instead of using the more automatic @option{--verify} option.
9961 @xref{compare}.
9962
9963 Note that these two options have a slightly different intent. The
9964 @option{--compare} option checks how identical are the logical contents of some
9965 archive with what is on your disks, while the @option{--verify} option is
9966 really for checking if the physical contents agree and if the recording
9967 media itself is of dependable quality. So, for the @option{--verify}
9968 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9969 the archive, while it lets the speed optimization undisturbed for the
9970 @option{--compare} option. If you nevertheless use @option{--compare} for
9971 media verification, you may have to defeat the in-memory cache yourself,
9972 maybe by opening and reclosing the door latch of your recording unit,
9973 forcing some doubt in your operating system about the fact this is really
9974 the same volume as the one just written or read.
9975
9976 The @option{--verify} option would not be necessary if drivers were indeed
9977 able to detect dependably all write failures. This sometimes require many
9978 magnetic heads, some able to read after the writes occurred. One would
9979 not say that drivers unable to detect all cases are necessarily flawed,
9980 as long as programming is concerned.
9981
9982 The @option{--verify} (@option{-W}) option will not work in
9983 conjunction with the @option{--multi-volume} (@option{-M}) option or
9984 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
9985 and @option{--delete} operations. @xref{Operations}, for more
9986 information on these operations.
9987
9988 Also, since @command{tar} normally strips leading @samp{/} from file
9989 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9990 /tmp/foo.tar /etc} will work as desired only if the working directory is
9991 @file{/}, as @command{tar} uses the archive's relative member names
9992 (e.g., @file{etc/motd}) when verifying the archive.
9993
9994 @node Write Protection
9995 @section Write Protection
9996
9997 Almost all tapes and diskettes, and in a few rare cases, even disks can
9998 be @dfn{write protected}, to protect data on them from being changed.
9999 Once an archive is written, you should write protect the media to prevent
10000 the archive from being accidentally overwritten or deleted. (This will
10001 protect the archive from being changed with a tape or floppy drive---it
10002 will not protect it from magnet fields or other physical hazards).
10003
10004 The write protection device itself is usually an integral part of the
10005 physical media, and can be a two position (write enabled/write
10006 disabled) switch, a notch which can be popped out or covered, a ring
10007 which can be removed from the center of a tape reel, or some other
10008 changeable feature.
10009
10010 @node Changes
10011 @appendix Changes
10012
10013 This appendix lists some important user-visible changes between
10014 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10015 version of this document is available at
10016 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10017 @GNUTAR{} documentation page}.
10018
10019 @table @asis
10020 @item Use of globbing patterns when listing and extracting.
10021
10022 Previous versions of GNU tar assumed shell-style globbing when
10023 extracting from or listing an archive. For example:
10024
10025 @smallexample
10026 $ @kbd{tar xf foo.tar '*.c'}
10027 @end smallexample
10028
10029 would extract all files whose names end in @samp{.c}. This behavior
10030 was not documented and was incompatible with traditional tar
10031 implementations. Therefore, starting from version 1.15.91, GNU tar
10032 no longer uses globbing by default. For example, the above invocation
10033 is now interpreted as a request to extract from the archive the file
10034 named @file{*.c}.
10035
10036 To facilitate transition to the new behavior for those users who got
10037 used to the previous incorrect one, @command{tar} will print a warning
10038 if it finds out that a requested member was not found in the archive
10039 and its name looks like a globbing pattern. For example:
10040
10041 @smallexample
10042 $ @kbd{tar xf foo.tar '*.c'}
10043 tar: Pattern matching characters used in file names. Please,
10044 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10045 tar: suppress this warning.
10046 tar: *.c: Not found in archive
10047 tar: Error exit delayed from previous errors
10048 @end smallexample
10049
10050 To treat member names as globbing patterns, use --wildcards option.
10051 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10052 add this option to your @env{TAR_OPTIONS} variable.
10053
10054 @xref{wildcards}, for the detailed discussion of the use of globbing
10055 patterns by @GNUTAR{}.
10056
10057 @item Use of short option @option{-o}.
10058
10059 Earlier versions of @GNUTAR{} understood @option{-o} command line
10060 option as a synonym for @option{--old-archive}.
10061
10062 @GNUTAR{} starting from version 1.13.90 understands this option as
10063 a synonym for @option{--no-same-owner}. This is compatible with
10064 UNIX98 @command{tar} implementations.
10065
10066 However, to facilitate transition, @option{-o} option retains its
10067 old semantics when it is used with one of archive-creation commands.
10068 Users are encouraged to use @option{--format=oldgnu} instead.
10069
10070 It is especially important, since versions of @acronym{GNU} Automake
10071 up to and including 1.8.4 invoke tar with this option to produce
10072 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10073 of this issue and its implications.
10074
10075 @FIXME{Change the first argument to tar-formats when the new Automake is
10076 out. The proposition to add @anchor{} to the appropriate place of its
10077 docs was accepted by Automake people --Sergey 2006-05-25}.
10078 @xref{Options, tar-v7, Changing Automake's Behavior,
10079 automake, GNU Automake}, for a description on how to use various
10080 archive formats with @command{automake}.
10081
10082 Future versions of @GNUTAR{} will understand @option{-o} only as a
10083 synonym for @option{--no-same-owner}.
10084
10085 @item Use of short option @option{-l}
10086
10087 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10088 synonym for @option{--one-file-system}. Since such usage contradicted
10089 to UNIX98 specification and harmed compatibility with other
10090 implementation, it was declared deprecated in version 1.14. However,
10091 to facilitate transition to its new semantics, it was supported by
10092 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10093 variant of @option{--check-links} was introduced in version 1.15.91.
10094
10095 @item Use of options @option{--portability} and @option{--old-archive}
10096
10097 These options are deprecated. Please use @option{--format=v7} instead.
10098
10099 @item Use of option @option{--posix}
10100
10101 This option is deprecated. Please use @option{--format=posix} instead.
10102 @end table
10103
10104 @node Configuring Help Summary
10105 @appendix Configuring Help Summary
10106
10107 Running @kbd{tar --help} displays the short @command{tar} option
10108 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10109 semantically close options. The options within each group are printed
10110 in the following order: a short option, eventually followed by a list
10111 of corresponding long option names, followed by a short description of
10112 the option. For example, here is an excerpt from the actual @kbd{tar
10113 --help} output:
10114
10115 @verbatim
10116 Main operation mode:
10117
10118 -A, --catenate, --concatenate append tar files to an archive
10119 -c, --create create a new archive
10120 -d, --diff, --compare find differences between archive and
10121 file system
10122 --delete delete from the archive
10123 @end verbatim
10124
10125 @vrindex ARGP_HELP_FMT, environment variable
10126 The exact visual representation of the help output is configurable via
10127 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10128 is a comma-separated list of @dfn{format variable} assignments. There
10129 are two kinds of format variables. An @dfn{offset variable} keeps the
10130 offset of some part of help output text from the leftmost column on
10131 the screen. A @dfn{boolean} variable is a flag that toggles some
10132 output feature on or off. Depending on the type of the corresponding
10133 variable, there are two kinds of assignments:
10134
10135 @table @asis
10136 @item Offset assignment
10137
10138 The assignment to an offset variable has the following syntax:
10139
10140 @smallexample
10141 @var{variable}=@var{value}
10142 @end smallexample
10143
10144 @noindent
10145 where @var{variable} is the variable name, and @var{value} is a
10146 numeric value to be assigned to the variable.
10147
10148 @item Boolean assignment
10149
10150 To assign @code{true} value to a variable, simply put this variable name. To
10151 assign @code{false} value, prefix the variable name with @samp{no-}. For
10152 example:
10153
10154 @smallexample
10155 @group
10156 # Assign @code{true} value:
10157 dup-args
10158 # Assign @code{false} value:
10159 no-dup-args
10160 @end group
10161 @end smallexample
10162 @end table
10163
10164 Following variables are declared:
10165
10166 @deftypevr {Help Output} boolean dup-args
10167 If true, arguments for an option are shown with both short and long
10168 options, even when a given option has both forms, for example:
10169
10170 @smallexample
10171 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10172 @end smallexample
10173
10174 If false, then if an option has both short and long forms, the
10175 argument is only shown with the long one, for example:
10176
10177 @smallexample
10178 -f, --file=ARCHIVE use archive file or device ARCHIVE
10179 @end smallexample
10180
10181 @noindent
10182 and a message indicating that the argument is applicable to both
10183 forms is printed below the options. This message can be disabled
10184 using @code{dup-args-note} (see below).
10185
10186 The default is false.
10187 @end deftypevr
10188
10189 @deftypevr {Help Output} boolean dup-args-note
10190 If this variable is true, which is the default, the following notice
10191 is displayed at the end of the help output:
10192
10193 @quotation
10194 Mandatory or optional arguments to long options are also mandatory or
10195 optional for any corresponding short options.
10196 @end quotation
10197
10198 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10199 variables @code{dup-args} or @code{dup-args-note} should be set.
10200 @end deftypevr
10201
10202 @deftypevr {Help Output} offset short-opt-col
10203 Column in which short options start. Default is 2.
10204
10205 @smallexample
10206 @group
10207 $ @kbd{tar --help|grep ARCHIVE}
10208 -f, --file=ARCHIVE use archive file or device ARCHIVE
10209 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10210 -f, --file=ARCHIVE use archive file or device ARCHIVE
10211 @end group
10212 @end smallexample
10213 @end deftypevr
10214
10215 @deftypevr {Help Output} offset long-opt-col
10216 Column in which long options start. Default is 6. For example:
10217
10218 @smallexample
10219 @group
10220 $ @kbd{tar --help|grep ARCHIVE}
10221 -f, --file=ARCHIVE use archive file or device ARCHIVE
10222 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10223 -f, --file=ARCHIVE use archive file or device ARCHIVE
10224 @end group
10225 @end smallexample
10226 @end deftypevr
10227
10228 @deftypevr {Help Output} offset doc-opt-col
10229 Column in which @dfn{doc options} start. A doc option isn't actually
10230 an option, but rather an arbitrary piece of documentation that is
10231 displayed in much the same manner as the options. For example, in
10232 the description of @option{--format} option:
10233
10234 @smallexample
10235 @group
10236 -H, --format=FORMAT create archive of the given format.
10237
10238 FORMAT is one of the following:
10239
10240 gnu GNU tar 1.13.x format
10241 oldgnu GNU format as per tar <= 1.12
10242 pax POSIX 1003.1-2001 (pax) format
10243 posix same as pax
10244 ustar POSIX 1003.1-1988 (ustar) format
10245 v7 old V7 tar format
10246 @end group
10247 @end smallexample
10248
10249 @noindent
10250 the format names are doc options. Thus, if you set
10251 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10252 will look as follows:
10253
10254 @smallexample
10255 @group
10256 -H, --format=FORMAT create archive of the given format.
10257
10258 FORMAT is one of the following:
10259
10260 gnu GNU tar 1.13.x format
10261 oldgnu GNU format as per tar <= 1.12
10262 pax POSIX 1003.1-2001 (pax) format
10263 posix same as pax
10264 ustar POSIX 1003.1-1988 (ustar) format
10265 v7 old V7 tar format
10266 @end group
10267 @end smallexample
10268 @end deftypevr
10269
10270 @deftypevr {Help Output} offset opt-doc-col
10271 Column in which option description starts. Default is 29.
10272
10273 @smallexample
10274 @group
10275 $ @kbd{tar --help|grep ARCHIVE}
10276 -f, --file=ARCHIVE use archive file or device ARCHIVE
10277 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10278 -f, --file=ARCHIVE use archive file or device ARCHIVE
10279 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10280 -f, --file=ARCHIVE
10281 use archive file or device ARCHIVE
10282 @end group
10283 @end smallexample
10284
10285 @noindent
10286 Notice, that the description starts on a separate line if
10287 @code{opt-doc-col} value is too small.
10288 @end deftypevr
10289
10290 @deftypevr {Help Output} offset header-col
10291 Column in which @dfn{group headers} are printed. A group header is a
10292 descriptive text preceding an option group. For example, in the
10293 following text:
10294
10295 @verbatim
10296 Main operation mode:
10297
10298 -A, --catenate, --concatenate append tar files to
10299 an archive
10300 -c, --create create a new archive
10301 @end verbatim
10302 @noindent
10303 @samp{Main operation mode:} is the group header.
10304
10305 The default value is 1.
10306 @end deftypevr
10307
10308 @deftypevr {Help Output} offset usage-indent
10309 Indentation of wrapped usage lines. Affects @option{--usage}
10310 output. Default is 12.
10311 @end deftypevr
10312
10313 @deftypevr {Help Output} offset rmargin
10314 Right margin of the text output. Used for wrapping.
10315 @end deftypevr
10316
10317 @node Genfile
10318 @appendix Genfile
10319 @include genfile.texi
10320
10321 @node Tar Internals
10322 @appendix Tar Internals
10323 @include intern.texi
10324
10325 @node Free Software Needs Free Documentation
10326 @appendix Free Software Needs Free Documentation
10327 @include freemanuals.texi
10328
10329 @node Copying This Manual
10330 @appendix Copying This Manual
10331
10332 @menu
10333 * GNU Free Documentation License:: License for copying this manual
10334 @end menu
10335
10336 @include fdl.texi
10337
10338 @node Index of Command Line Options
10339 @appendix Index of Command Line Options
10340
10341 This appendix contains an index of all @GNUTAR{} long command line
10342 options. The options are listed without the preceeding double-dash.
10343 For a cross-reference of short command line options, @ref{Short Option Summary}.
10344
10345 @printindex op
10346
10347 @node Index
10348 @appendix Index
10349
10350 @printindex cp
10351
10352 @summarycontents
10353 @contents
10354 @bye
10355
10356 @c Local variables:
10357 @c texinfo-column-for-description: 32
10358 @c End:
This page took 0.472079 seconds and 5 git commands to generate.