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