]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Document better the --totals option.
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @include rendition.texi
14 @include value.texi
15
16 @c Put everything in one index (arbitrarily chosen to be the concept index).
17 @syncodeindex fn cp
18 @syncodeindex ky cp
19 @syncodeindex pg cp
20 @syncodeindex vr cp
21
22 @defindex op
23
24 @copying
25
26 This manual is for @acronym{GNU} @command{tar} (version
27 @value{VERSION}, @value{UPDATED}), which creates and extracts files
28 from archives.
29
30 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
31 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
32
33 @quotation
34 Permission is granted to copy, distribute and/or modify this document
35 under the terms of the GNU Free Documentation License, Version 1.1 or
36 any later version published by the Free Software Foundation; with no
37 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
38 and with the Back-Cover Texts as in (a) below. A copy of the license
39 is included in the section entitled "GNU Free Documentation License".
40
41 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
42 this GNU Manual. Buying copies from GNU Press supports the FSF in
43 developing GNU and promoting software freedom.''
44 @end quotation
45 @end copying
46
47 @dircategory Archiving
48 @direntry
49 * Tar: (tar). Making tape (or disk) archives.
50 @end direntry
51
52 @dircategory Individual utilities
53 @direntry
54 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
55 @end direntry
56
57 @shorttitlepage @acronym{GNU} @command{tar}
58
59 @titlepage
60 @title @acronym{GNU} tar: an archiver tool
61 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
62 @author John Gilmore, Jay Fenlason et al.
63
64 @page
65 @vskip 0pt plus 1filll
66 @insertcopying
67 @end titlepage
68
69 @ifnottex
70 @node Top
71 @top @acronym{GNU} tar: an archiver tool
72
73 @insertcopying
74
75 @cindex file archival
76 @cindex archiving files
77
78 The first part of this master menu lists the major nodes in this Info
79 document. The rest of the menu lists all the lower level nodes.
80 @end ifnottex
81
82 @c The master menu goes here.
83 @c
84 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
85 @c loaded and run texinfo-master-menu.
86 @c To update it from the command line, run
87 @c
88 @c make master-menu
89
90 @menu
91 * Introduction::
92 * Tutorial::
93 * tar invocation::
94 * operations::
95 * Backups::
96 * Choosing::
97 * Date input formats::
98 * Formats::
99 * Media::
100
101 Appendices
102
103 * Changes::
104 * Configuring Help Summary::
105 * Genfile::
106 * Tar Internals::
107 * Free Software Needs Free Documentation::
108 * Copying This Manual::
109 * Index of Command Line Options::
110 * Index::
111
112 @detailmenu
113 --- The Detailed Node Listing ---
114
115 Introduction
116
117 * Book Contents:: What this Book Contains
118 * Definitions:: Some Definitions
119 * What tar Does:: What @command{tar} Does
120 * Naming tar Archives:: How @command{tar} Archives are Named
121 * Authors:: @GNUTAR{} Authors
122 * Reports:: Reporting bugs or suggestions
123
124 Tutorial Introduction to @command{tar}
125
126 * assumptions::
127 * stylistic conventions::
128 * basic tar options:: Basic @command{tar} Operations and Options
129 * frequent operations::
130 * Two Frequent Options::
131 * create:: How to Create Archives
132 * list:: How to List Archives
133 * extract:: How to Extract Members from an Archive
134 * going further::
135
136 Two Frequently Used Options
137
138 * file tutorial::
139 * verbose tutorial::
140 * help tutorial::
141
142 How to Create Archives
143
144 * prepare for examples::
145 * Creating the archive::
146 * create verbose::
147 * short create::
148 * create dir::
149
150 How to List Archives
151
152 * list dir::
153
154 How to Extract Members from an Archive
155
156 * extracting archives::
157 * extracting files::
158 * extract dir::
159 * extracting untrusted archives::
160 * failing commands::
161
162 Invoking @GNUTAR{}
163
164 * Synopsis::
165 * using tar options::
166 * Styles::
167 * All Options::
168 * help::
169 * defaults::
170 * verbose::
171 * interactive::
172
173 The Three Option Styles
174
175 * Mnemonic Options:: Mnemonic Option Style
176 * Short Options:: Short Option Style
177 * Old Options:: Old Option Style
178 * Mixing:: Mixing Option Styles
179
180 All @command{tar} Options
181
182 * Operation Summary::
183 * Option Summary::
184 * Short Option Summary::
185
186 @GNUTAR{} Operations
187
188 * Basic tar::
189 * Advanced tar::
190 * create options::
191 * extract options::
192 * backup::
193 * Applications::
194 * looking ahead::
195
196 Advanced @GNUTAR{} Operations
197
198 * Operations::
199 * append::
200 * update::
201 * concatenate::
202 * delete::
203 * compare::
204
205 How to Add Files to Existing Archives: @option{--append}
206
207 * appending files:: Appending Files to an Archive
208 * multiple::
209
210 Updating an Archive
211
212 * how to update::
213
214 Options Used by @option{--create}
215
216 * Ignore Failed Read::
217
218 Options Used by @option{--extract}
219
220 * Reading:: Options to Help Read Archives
221 * Writing:: Changing How @command{tar} Writes Files
222 * Scarce:: Coping with Scarce Resources
223
224 Options to Help Read Archives
225
226 * read full records::
227 * Ignore Zeros::
228
229 Changing How @command{tar} Writes Files
230
231 * Dealing with Old Files::
232 * Overwrite Old Files::
233 * Keep Old Files::
234 * Keep Newer Files::
235 * Unlink First::
236 * Recursive Unlink::
237 * Data Modification Times::
238 * Setting Access Permissions::
239 * Directory Modification Times and Permissions::
240 * Writing to Standard Output::
241 * Writing to an External Program::
242 * remove files::
243
244 Coping with Scarce Resources
245
246 * Starting File::
247 * Same Order::
248
249 Performing Backups and Restoring Files
250
251 * Full Dumps:: Using @command{tar} to Perform Full Dumps
252 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
253 * Backup Levels:: Levels of Backups
254 * Backup Parameters:: Setting Parameters for Backups and Restoration
255 * Scripted Backups:: Using the Backup Scripts
256 * Scripted Restoration:: Using the Restore Script
257
258 Setting Parameters for Backups and Restoration
259
260 * General-Purpose Variables::
261 * Magnetic Tape Control::
262 * User Hooks::
263 * backup-specs example:: An Example Text of @file{Backup-specs}
264
265 Choosing Files and Names for @command{tar}
266
267 * file:: Choosing the Archive's Name
268 * Selecting Archive Members::
269 * files:: Reading Names from a File
270 * exclude:: Excluding Some Files
271 * wildcards:: Wildcards Patterns and Matching
272 * quoting styles:: Ways of Quoting Special Characters in Names
273 * transform:: Modifying File and Member Names
274 * after:: Operating Only on New Files
275 * recurse:: Descending into Directories
276 * one:: Crossing File System Boundaries
277
278 Reading Names from a File
279
280 * nul::
281
282 Excluding Some Files
283
284 * problems with exclude::
285
286 Wildcards Patterns and Matching
287
288 * controlling pattern-matching::
289
290 Crossing File System Boundaries
291
292 * directory:: Changing Directory
293 * absolute:: Absolute File Names
294
295 Date input formats
296
297 * General date syntax:: Common rules.
298 * Calendar date items:: 19 Dec 1994.
299 * Time of day items:: 9:20pm.
300 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
301 * Day of week items:: Monday and others.
302 * Relative items in date strings:: next tuesday, 2 years ago.
303 * Pure numbers in date strings:: 19931219, 1440.
304 * Seconds since the Epoch:: @@1078100502.
305 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
306 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
307
308 Controlling the Archive Format
309
310 * Portability:: Making @command{tar} Archives More Portable
311 * Compression:: Using Less Space through Compression
312 * Attributes:: Handling File Attributes
313 * cpio:: Comparison of @command{tar} and @command{cpio}
314
315 Making @command{tar} Archives More Portable
316
317 * Portable Names:: Portable Names
318 * dereference:: Symbolic Links
319 * old:: Old V7 Archives
320 * ustar:: Ustar Archives
321 * gnu:: GNU and old GNU format archives.
322 * posix:: @acronym{POSIX} archives
323 * Checksumming:: Checksumming Problems
324 * Large or Negative Values:: Large files, negative time stamps, etc.
325
326 @GNUTAR{} and @acronym{POSIX} @command{tar}
327
328 * PAX keywords:: Controlling Extended Header Keywords.
329
330 Using Less Space through Compression
331
332 * gzip:: Creating and Reading Compressed Archives
333 * sparse:: Archiving Sparse Files
334
335 Tapes and Other Archive Media
336
337 * Device:: Device selection and switching
338 * Remote Tape Server::
339 * Common Problems and Solutions::
340 * Blocking:: Blocking
341 * Many:: Many archives on one tape
342 * Using Multiple Tapes:: Using Multiple Tapes
343 * label:: Including a Label in the Archive
344 * verify::
345 * Write Protection::
346
347 Blocking
348
349 * Format Variations:: Format Variations
350 * Blocking Factor:: The Blocking Factor of an Archive
351
352 Many Archives on One Tape
353
354 * Tape Positioning:: Tape Positions and Tape Marks
355 * mt:: The @command{mt} Utility
356
357 Using Multiple Tapes
358
359 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
360 * Tape Files:: Tape Files
361 * Tarcat:: Concatenate Volumes into a Single Archive
362
363
364 Genfile
365
366 * Generate Mode:: File Generation Mode.
367 * Status Mode:: File Status Mode.
368 * Exec Mode:: Synchronous Execution mode.
369
370 Tar Internals
371
372 * Standard:: Basic Tar Format
373 * Extensions:: @acronym{GNU} Extensions to the Archive Format
374 * Snapshot Files::
375 * Dumpdir::
376
377 Copying This Manual
378
379 * GNU Free Documentation License:: License for copying this manual
380
381 @end detailmenu
382 @end menu
383
384 @node Introduction
385 @chapter Introduction
386
387 @GNUTAR{} creates
388 and manipulates @dfn{archives} which are actually collections of
389 many other files; the program provides users with an organized and
390 systematic method for controlling a large amount of data.
391 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
392 archives need not (and these days, typically do not) reside on tapes.
393
394 @menu
395 * Book Contents:: What this Book Contains
396 * Definitions:: Some Definitions
397 * What tar Does:: What @command{tar} Does
398 * Naming tar Archives:: How @command{tar} Archives are Named
399 * Authors:: @GNUTAR{} Authors
400 * Reports:: Reporting bugs or suggestions
401 @end menu
402
403 @node Book Contents
404 @section What this Book Contains
405
406 The first part of this chapter introduces you to various terms that will
407 recur throughout the book. It also tells you who has worked on @GNUTAR{}
408 and its documentation, and where you should send bug reports
409 or comments.
410
411 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
412 gentle introduction for people who are new to using @command{tar}. It is
413 meant to be self contained, not requiring any reading from subsequent
414 chapters to make sense. It moves from topic to topic in a logical,
415 progressive order, building on information already explained.
416
417 Although the tutorial is paced and structured to allow beginners to
418 learn how to use @command{tar}, it is not intended solely for beginners.
419 The tutorial explains how to use the three most frequently used
420 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
421 two frequently used options (@samp{file} and @samp{verbose}). The other
422 chapters do not refer to the tutorial frequently; however, if a section
423 discusses something which is a complex variant of a basic concept, there
424 may be a cross reference to that basic concept. (The entire book,
425 including the tutorial, assumes that the reader understands some basic
426 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
427
428 The third chapter presents the remaining five operations, and
429 information about using @command{tar} options and option syntax.
430
431 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
432 than the reality. should think about whether this makes sense to say
433 here, or not.} The other chapters are meant to be used as a
434 reference. Each chapter presents everything that needs to be said
435 about a specific topic.
436
437 One of the chapters (@pxref{Date input formats}) exists in its
438 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
439 In addition, one section of this manual (@pxref{Standard}) contains a
440 big quote which is taken directly from @command{tar} sources.
441
442 In general, we give both long and short (abbreviated) option names
443 at least once in each section where the relevant option is covered, so
444 that novice readers will become familiar with both styles. (A few
445 options have no short versions, and the relevant sections will
446 indicate this.)
447
448 @node Definitions
449 @section Some Definitions
450
451 @cindex archive
452 @cindex tar archive
453 The @command{tar} program is used to create and manipulate @command{tar}
454 archives. An @dfn{archive} is a single file which contains the contents
455 of many files, while still identifying the names of the files, their
456 owner(s), and so forth. (In addition, archives record access
457 permissions, user and group, size in bytes, and data modification time.
458 Some archives also record the file names in each archived directory, as
459 well as other file and directory information.) You can use @command{tar}
460 to @dfn{create} a new archive in a specified directory.
461
462 @cindex member
463 @cindex archive member
464 @cindex file name
465 @cindex member name
466 The files inside an archive are called @dfn{members}. Within this
467 manual, we use the term @dfn{file} to refer only to files accessible in
468 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
469 @dfn{member} to refer only to the members of an archive. Similarly, a
470 @dfn{file name} is the name of a file, as it resides in the file system,
471 and a @dfn{member name} is the name of an archive member within the
472 archive.
473
474 @cindex extraction
475 @cindex unpacking
476 The term @dfn{extraction} refers to the process of copying an archive
477 member (or multiple members) into a file in the file system. Extracting
478 all the members of an archive is often called @dfn{extracting the
479 archive}. The term @dfn{unpack} can also be used to refer to the
480 extraction of many or all the members of an archive. Extracting an
481 archive does not destroy the archive's structure, just as creating an
482 archive does not destroy the copies of the files that exist outside of
483 the archive. You may also @dfn{list} the members in a given archive
484 (this is often thought of as ``printing'' them to the standard output,
485 or the command line), or @dfn{append} members to a pre-existing archive.
486 All of these operations can be performed using @command{tar}.
487
488 @node What tar Does
489 @section What @command{tar} Does
490
491 @cindex tar
492 The @command{tar} program provides the ability to create @command{tar}
493 archives, as well as various other kinds of manipulation. For example,
494 you can use @command{tar} on previously created archives to extract files,
495 to store additional files, or to update or list files which were already
496 stored.
497
498 Initially, @command{tar} archives were used to store files conveniently on
499 magnetic tape. The name @command{tar} comes from this use; it stands for
500 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
501 direct its output to available devices, files, or other programs (using
502 pipes). @command{tar} may even access remote devices or files (as archives).
503
504 You can use @command{tar} archives in many ways. We want to stress a few
505 of them: storage, backup, and transportation.
506
507 @FIXME{the following table entries need a bit of work..}
508 @table @asis
509 @item Storage
510 Often, @command{tar} archives are used to store related files for
511 convenient file transfer over a network. For example, the
512 @acronym{GNU} Project distributes its software bundled into
513 @command{tar} archives, so that all the files relating to a particular
514 program (or set of related programs) can be transferred as a single
515 unit.
516
517 A magnetic tape can store several files in sequence. However, the tape
518 has no names for these files; it only knows their relative position on
519 the tape. One way to store several files on one tape and retain their
520 names is by creating a @command{tar} archive. Even when the basic transfer
521 mechanism can keep track of names, as FTP can, the nuisance of handling
522 multiple files, directories, and multiple links makes @command{tar}
523 archives useful.
524
525 Archive files are also used for long-term storage. You can think of
526 this as transportation from the present into the future. (It is a
527 science-fiction idiom that you can move through time as well as in
528 space; the idea here is that @command{tar} can be used to move archives in
529 all dimensions, even time!)
530
531 @item Backup
532 Because the archive created by @command{tar} is capable of preserving
533 file information and directory structure, @command{tar} is commonly
534 used for performing full and incremental backups of disks. A backup
535 puts a collection of files (possibly pertaining to many users and
536 projects) together on a disk or a tape. This guards against
537 accidental destruction of the information in those files.
538 @GNUTAR{} has special features that allow it to be
539 used to make incremental and full dumps of all the files in a
540 file system.
541
542 @item Transportation
543 You can create an archive on one system, transfer it to another system,
544 and extract the contents there. This allows you to transport a group of
545 files from one system to another.
546 @end table
547
548 @node Naming tar Archives
549 @section How @command{tar} Archives are Named
550
551 Conventionally, @command{tar} archives are given names ending with
552 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
553 but this manual follows that convention in order to accustom readers to
554 it and to make examples more clear.
555
556 @cindex tar file
557 @cindex entry
558 @cindex tar entry
559 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
560 archive members as ``files'' or ``entries''. For people familiar with
561 the operation of @command{tar}, this causes no difficulty. However, in
562 this manual, we consistently refer to ``archives'' and ``archive
563 members'' to make learning to use @command{tar} easier for novice users.
564
565 @node Authors
566 @section @GNUTAR{} Authors
567
568 @GNUTAR{} was originally written by John Gilmore,
569 and modified by many people. The @acronym{GNU} enhancements were
570 written by Jay Fenlason, then Joy Kendall, and the whole package has
571 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
572 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
573 numerous and kind users.
574
575 We wish to stress that @command{tar} is a collective work, and owes much to
576 all those people who reported problems, offered solutions and other
577 insights, or shared their thoughts and suggestions. An impressive, yet
578 partial list of those contributors can be found in the @file{THANKS}
579 file from the @GNUTAR{} distribution.
580
581 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
582 sure i want to spell out the history in this detail, at least not for
583 the printed book. i'm just not sure it needs to be said this way.
584 i'll think about it.}
585
586 @FIXME{History is more important, and surely more interesting, than
587 actual names. Quoting names without history would be meaningless. FP}
588
589 Jay Fenlason put together a draft of a @GNUTAR{}
590 manual, borrowing notes from the original man page from John Gilmore.
591 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
592 Gorin worked on a tutorial and manual for @GNUTAR{}.
593 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
594 taking information from all these sources and merging them. Melissa
595 Weisshaus finally edited and redesigned the book to create version
596 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
597 by the current maintainer, Sergey Poznyakoff.
598
599 For version 1.12, Daniel Hagerty contributed a great deal of technical
600 consulting. In particular, he is the primary author of @ref{Backups}.
601
602 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
603 (see @url{http://savannah.gnu.org/projects/tar}), and
604 active development and maintenance work has started
605 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
606 Poznyakoff and Jeff Bailey.
607
608 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
609
610 @node Reports
611 @section Reporting bugs or suggestions
612
613 @cindex bug reports
614 @cindex reporting bugs
615 If you find problems or have suggestions about this program or manual,
616 please report them to @file{bug-tar@@gnu.org}.
617
618 When reporting a bug, please be sure to include as much detail as
619 possible, in order to reproduce it. @FIXME{Be more specific, I'd
620 like to make this node as detailed as 'Bug reporting' node in Emacs
621 manual}.
622
623 @node Tutorial
624 @chapter Tutorial Introduction to @command{tar}
625
626 This chapter guides you through some basic examples of three @command{tar}
627 operations: @option{--create}, @option{--list}, and @option{--extract}. If
628 you already know how to use some other version of @command{tar}, then you
629 may not need to read this chapter. This chapter omits most complicated
630 details about how @command{tar} works.
631
632 @menu
633 * assumptions::
634 * stylistic conventions::
635 * basic tar options:: Basic @command{tar} Operations and Options
636 * frequent operations::
637 * Two Frequent Options::
638 * create:: How to Create Archives
639 * list:: How to List Archives
640 * extract:: How to Extract Members from an Archive
641 * going further::
642 @end menu
643
644 @node assumptions
645 @section Assumptions this Tutorial Makes
646
647 This chapter is paced to allow beginners to learn about @command{tar}
648 slowly. At the same time, we will try to cover all the basic aspects of
649 these three operations. In order to accomplish both of these tasks, we
650 have made certain assumptions about your knowledge before reading this
651 manual, and the hardware you will be using:
652
653 @itemize @bullet
654 @item
655 Before you start to work through this tutorial, you should understand
656 what the terms ``archive'' and ``archive member'' mean
657 (@pxref{Definitions}). In addition, you should understand something
658 about how Unix-type operating systems work, and you should know how to
659 use some basic utilities. For example, you should know how to create,
660 list, copy, rename, edit, and delete files and directories; how to
661 change between directories; and how to figure out where you are in the
662 file system. You should have some basic understanding of directory
663 structure and how files are named according to which directory they are
664 in. You should understand concepts such as standard output and standard
665 input, what various definitions of the term ``argument'' mean, and the
666 differences between relative and absolute path names. @FIXME{and what
667 else?}
668
669 @item
670 This manual assumes that you are working from your own home directory
671 (unless we state otherwise). In this tutorial, you will create a
672 directory to practice @command{tar} commands in. When we show path names,
673 we will assume that those paths are relative to your home directory.
674 For example, my home directory path is @file{/home/fsf/melissa}. All of
675 my examples are in a subdirectory of the directory named by that path
676 name; the subdirectory is called @file{practice}.
677
678 @item
679 In general, we show examples of archives which exist on (or can be
680 written to, or worked with from) a directory on a hard disk. In most
681 cases, you could write those archives to, or work with them on any other
682 device, such as a tape drive. However, some of the later examples in
683 the tutorial and next chapter will not work on tape drives.
684 Additionally, working with tapes is much more complicated than working
685 with hard disks. For these reasons, the tutorial does not cover working
686 with tape drives. @xref{Media}, for complete information on using
687 @command{tar} archives with tape drives.
688
689 @FIXME{this is a cop out. need to add some simple tape drive info.}
690 @end itemize
691
692 @node stylistic conventions
693 @section Stylistic Conventions
694
695 In the examples, @samp{$} represents a typical shell prompt. It
696 precedes lines you should type; to make this more clear, those lines are
697 shown in @kbd{this font}, as opposed to lines which represent the
698 computer's response; those lines are shown in @code{this font}, or
699 sometimes @samp{like this}.
700
701 @c When we have lines which are too long to be
702 @c displayed in any other way, we will show them like this:
703
704 @node basic tar options
705 @section Basic @command{tar} Operations and Options
706
707 @command{tar} can take a wide variety of arguments which specify and define
708 the actions it will have on the particular set of files or the archive.
709 The main types of arguments to @command{tar} fall into one of two classes:
710 operations, and options.
711
712 Some arguments fall into a class called @dfn{operations}; exactly one of
713 these is both allowed and required for any instance of using @command{tar};
714 you may @emph{not} specify more than one. People sometimes speak of
715 @dfn{operating modes}. You are in a particular operating mode when you
716 have specified the operation which specifies it; there are eight
717 operations in total, and thus there are eight operating modes.
718
719 The other arguments fall into the class known as @dfn{options}. You are
720 not required to specify any options, and you are allowed to specify more
721 than one at a time (depending on the way you are using @command{tar} at
722 that time). Some options are used so frequently, and are so useful for
723 helping you type commands more carefully that they are effectively
724 ``required''. We will discuss them in this chapter.
725
726 You can write most of the @command{tar} operations and options in any
727 of three forms: long (mnemonic) form, short form, and old style. Some
728 of the operations and options have no short or ``old'' forms; however,
729 the operations and options which we will cover in this tutorial have
730 corresponding abbreviations. @FIXME{make sure this is still the case,
731 at the end}We will indicate those abbreviations appropriately to get
732 you used to seeing them. (Note that the ``old style'' option forms
733 exist in @GNUTAR{} for compatibility with Unix
734 @command{tar}. In this book we present a full discussion of this way
735 of writing options and operations (@pxref{Old Options}), and we discuss
736 the other two styles of writing options (@xref{Mnemonic Options}, and
737 @pxref{Short Options}).
738
739 In the examples and in the text of this tutorial, we usually use the
740 long forms of operations and options; but the ``short'' forms produce
741 the same result and can make typing long @command{tar} commands easier.
742 For example, instead of typing
743
744 @smallexample
745 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
746 @end smallexample
747
748 @noindent
749 you can type
750 @smallexample
751 @kbd{tar -c -v -f afiles.tar apple angst aspic}
752 @end smallexample
753
754 @noindent
755 or even
756 @smallexample
757 @kbd{tar -cvf afiles.tar apple angst aspic}
758 @end smallexample
759
760 @noindent
761 For more information on option syntax, see @ref{Advanced tar}. In
762 discussions in the text, when we name an option by its long form, we
763 also give the corresponding short option in parentheses.
764
765 The term, ``option'', can be confusing at times, since ``operations''
766 are often lumped in with the actual, @emph{optional} ``options'' in certain
767 general class statements. For example, we just talked about ``short and
768 long forms of options and operations''. However, experienced @command{tar}
769 users often refer to these by shorthand terms such as, ``short and long
770 options''. This term assumes that the ``operations'' are included, also.
771 Context will help you determine which definition of ``options'' to use.
772
773 Similarly, the term ``command'' can be confusing, as it is often used in
774 two different ways. People sometimes refer to @command{tar} ``commands''.
775 A @command{tar} @dfn{command} is the entire command line of user input
776 which tells @command{tar} what to do --- including the operation, options,
777 and any arguments (file names, pipes, other commands, etc). However,
778 you will also sometimes hear the term ``the @command{tar} command''. When
779 the word ``command'' is used specifically like this, a person is usually
780 referring to the @command{tar} @emph{operation}, not the whole line.
781 Again, use context to figure out which of the meanings the speaker
782 intends.
783
784 @node frequent operations
785 @section The Three Most Frequently Used Operations
786
787 Here are the three most frequently used operations (both short and long
788 forms), as well as a brief description of their meanings. The rest of
789 this chapter will cover how to use these operations in detail. We will
790 present the rest of the operations in the next chapter.
791
792 @table @option
793 @item --create
794 @itemx -c
795 Create a new @command{tar} archive.
796 @item --list
797 @itemx -t
798 List the contents of an archive.
799 @item --extract
800 @itemx -x
801 Extract one or more members from an archive.
802 @end table
803
804 @node Two Frequent Options
805 @section Two Frequently Used Options
806
807 To understand how to run @command{tar} in the three operating modes listed
808 previously, you also need to understand how to use two of the options to
809 @command{tar}: @option{--file} (which takes an archive file as an argument)
810 and @option{--verbose}. (You are usually not @emph{required} to specify
811 either of these options when you run @command{tar}, but they can be very
812 useful in making things more clear and helping you avoid errors.)
813
814 @menu
815 * file tutorial::
816 * verbose tutorial::
817 * help tutorial::
818 @end menu
819
820 @node file tutorial
821 @unnumberedsubsec The @option{--file} Option
822
823 @table @option
824 @opindex file, tutorial
825 @item --file=@var{archive-name}
826 @itemx -f @var{archive-name}
827 Specify the name of an archive file.
828 @end table
829
830 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
831 use @command{tar}; this option determines the name of the archive file
832 that @command{tar} will work on.
833
834 @vrindex TAPE
835 If you don't specify this argument, then @command{tar} will examine
836 the environment variable @env{TAPE}. If it is set, its value will be
837 used as the archive name. Otherwise, @command{tar} will use the
838 default archive, determined at the compile time. Usually it is
839 standard output or some physical tape drive attached to your machine
840 (you can verify what the default is by running @kbd{tar
841 --show-defaults}, @pxref{defaults}). If there is no tape drive
842 attached, or the default is not meaningful, then @command{tar} will
843 print an error message. The error message might look roughly like one
844 of the following:
845
846 @smallexample
847 tar: can't open /dev/rmt8 : No such device or address
848 tar: can't open /dev/rsmt0 : I/O error
849 @end smallexample
850
851 @noindent
852 To avoid confusion, we recommend that you always specify an archive file
853 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
854 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
855 @ref{file}.
856
857 @node verbose tutorial
858 @unnumberedsubsec The @option{--verbose} Option
859
860 @table @option
861 @opindex verbose, introduced
862 @item --verbose
863 @itemx -v
864 Show the files being worked on as @command{tar} is running.
865 @end table
866
867 @option{--verbose} (@option{-v}) shows details about the results of running
868 @command{tar}. This can be especially useful when the results might not be
869 obvious. For example, if you want to see the progress of @command{tar} as
870 it writes files into the archive, you can use the @option{--verbose}
871 option. In the beginning, you may find it useful to use
872 @option{--verbose} at all times; when you are more accustomed to
873 @command{tar}, you will likely want to use it at certain times but not at
874 others. We will use @option{--verbose} at times to help make something
875 clear, and we will give many examples both using and not using
876 @option{--verbose} to show the differences.
877
878 Each instance of @option{--verbose} on the command line increases the
879 verbosity level by one, so if you need more details on the output,
880 specify it twice.
881
882 When reading archives (@option{--list}, @option{--extract},
883 @option{--diff}), @command{tar} by default prints only the names of
884 the members being extracted. Using @option{--verbose} will show a full,
885 @command{ls} style member listing.
886
887 In contrast, when writing archives (@option{--create}, @option{--append},
888 @option{--update}), @command{tar} does not print file names by
889 default. So, a single @option{--verbose} option shows the file names
890 being added to the archive, while two @option{--verbose} options
891 enable the full listing.
892
893 For example, to create an archive in verbose mode:
894
895 @smallexample
896 $ @kbd{tar -cvf afiles.tar apple angst aspic}
897 apple
898 angst
899 aspic
900 @end smallexample
901
902 @noindent
903 Creating the same archive with the verbosity level 2 could give:
904
905 @smallexample
906 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
907 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
908 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
909 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
910 @end smallexample
911
912 @noindent
913 This works equally well using short or long forms of options. Using
914 long forms, you would simply write out the mnemonic form of the option
915 twice, like this:
916
917 @smallexample
918 $ @kbd{tar --create --verbose --verbose @dots{}}
919 @end smallexample
920
921 @noindent
922 Note that you must double the hyphens properly each time.
923
924 Later in the tutorial, we will give examples using @w{@option{--verbose
925 --verbose}}.
926
927 The full output consists of six fields:
928
929 @itemize @bullet
930 @item File type and permissions in symbolic form.
931 These are displayed in the same format as the first column of
932 @command{ls -l} output (@pxref{What information is listed,
933 format=verbose, Verbose listing, fileutils, GNU file utilities}).
934
935 @item Owner name and group separated by a slash character.
936 If these data are not available (for example, when listing a @samp{v7} format
937 archive), numeric ID values are printed instead.
938
939 @item Size of the file, in bytes.
940
941 @item File modification date in ISO 8601 format.
942
943 @item File modification time.
944
945 @item File name.
946 If the name contains any special characters (white space, newlines,
947 etc.) these are displayed in an unambiguous form using so called
948 @dfn{quoting style}. For the detailed discussion of available styles
949 and on how to use them, see @ref{quoting styles}.
950
951 Depending on the file type, the name can be followed by some
952 additional information, described in the following table:
953
954 @table @samp
955 @item -> @var{link-name}
956 The file or archive member is a @dfn{symbolic link} and
957 @var{link-name} is the name of file it links to.
958
959 @item link to @var{link-name}
960 The file or archive member is a @dfn{hard link} and @var{link-name} is
961 the name of file it links to.
962
963 @item --Long Link--
964 The archive member is an old GNU format long link. You will normally
965 not encounter this.
966
967 @item --Long Name--
968 The archive member is an old GNU format long name. You will normally
969 not encounter this.
970
971 @item --Volume Header--
972 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
973
974 @item --Continued at byte @var{n}--
975 Encountered only at the beginning of a multy-volume archive
976 (@pxref{Using Multiple Tapes}). This archive member is a continuation
977 from the previous volume. The number @var{n} gives the offset where
978 the original file was split.
979
980 @item --Mangled file names--
981 This archive member contains @dfn{mangled file names} declarations,
982 a special member type that was used by early versions of @GNUTAR{}.
983 You probably will never encounter this, unless you are reading a very
984 old archive.
985
986 @item unknown file type @var{c}
987 An archive member of unknown type. @var{c} is the type character from
988 the archive header. If you encounter such a message, it means that
989 either your archive contains proprietary member types @GNUTAR{} is not
990 able to handle, or the archive is corrupted.
991 @end table
992
993 @end itemize
994
995 For example, here is an archive listing containing most of the special
996 suffixes explained above:
997
998 @smallexample
999 @group
1000 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1001 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1002 byte 32456--
1003 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1004 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1005 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1006 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1007 @end group
1008 @end smallexample
1009
1010 @smallexample
1011 @end smallexample
1012
1013 @node help tutorial
1014 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1015
1016 @table @option
1017 @opindex help
1018 @item --help
1019
1020 The @option{--help} option to @command{tar} prints out a very brief list of
1021 all operations and option available for the current version of
1022 @command{tar} available on your system.
1023 @end table
1024
1025 @node create
1026 @section How to Create Archives
1027 @UNREVISED
1028
1029 @cindex Creation of the archive
1030 @cindex Archive, creation of
1031 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1032 you use to create a @command{tar} archive. We will explain
1033 @option{--create} first because, in order to learn about the other
1034 operations, you will find it useful to have an archive available to
1035 practice on.
1036
1037 To make this easier, in this section you will first create a directory
1038 containing three files. Then, we will show you how to create an
1039 @emph{archive} (inside the new directory). Both the directory, and
1040 the archive are specifically for you to practice on. The rest of this
1041 chapter and the next chapter will show many examples using this
1042 directory and the files you will create: some of those files may be
1043 other directories and other archives.
1044
1045 The three files you will archive in this example are called
1046 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1047 @file{collection.tar}.
1048
1049 This section will proceed slowly, detailing how to use @option{--create}
1050 in @code{verbose} mode, and showing examples using both short and long
1051 forms. In the rest of the tutorial, and in the examples in the next
1052 chapter, we will proceed at a slightly quicker pace. This section
1053 moves more slowly to allow beginning users to understand how
1054 @command{tar} works.
1055
1056 @menu
1057 * prepare for examples::
1058 * Creating the archive::
1059 * create verbose::
1060 * short create::
1061 * create dir::
1062 @end menu
1063
1064 @node prepare for examples
1065 @subsection Preparing a Practice Directory for Examples
1066
1067 To follow along with this and future examples, create a new directory
1068 called @file{practice} containing files called @file{blues}, @file{folk}
1069 and @file{jazz}. The files can contain any information you like:
1070 ideally, they should contain information which relates to their names,
1071 and be of different lengths. Our examples assume that @file{practice}
1072 is a subdirectory of your home directory.
1073
1074 Now @command{cd} to the directory named @file{practice}; @file{practice}
1075 is now your @dfn{working directory}. (@emph{Please note}: Although
1076 the full path name of this directory is
1077 @file{/@var{homedir}/practice}, in our examples we will refer to
1078 this directory as @file{practice}; the @var{homedir} is presumed.
1079
1080 In general, you should check that the files to be archived exist where
1081 you think they do (in the working directory) by running @command{ls}.
1082 Because you just created the directory and the files and have changed to
1083 that directory, you probably don't need to do that this time.
1084
1085 It is very important to make sure there isn't already a file in the
1086 working directory with the archive name you intend to use (in this case,
1087 @samp{collection.tar}), or that you don't care about its contents.
1088 Whenever you use @samp{create}, @command{tar} will erase the current
1089 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1090 will not tell you if you are about to overwrite an archive unless you
1091 specify an option which does this (@pxref{backup}, for the
1092 information on how to do so). To add files to an existing archive,
1093 you need to use a different option, such as @option{--append} (@option{-r}); see
1094 @ref{append} for information on how to do this.
1095
1096 @node Creating the archive
1097 @subsection Creating the Archive
1098
1099 @opindex create, introduced
1100 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1101 archive named @file{collection.tar}, use the following command:
1102
1103 @smallexample
1104 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1105 @end smallexample
1106
1107 The order of the arguments is not very important, @emph{when using long
1108 option forms}. You could also say:
1109
1110 @smallexample
1111 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1112 @end smallexample
1113
1114 @noindent
1115 However, you can see that this order is harder to understand; this is
1116 why we will list the arguments in the order that makes the commands
1117 easiest to understand (and we encourage you to do the same when you use
1118 @command{tar}, to avoid errors).
1119
1120 Note that the part of the command which says,
1121 @w{@option{--file=collection.tar}} is considered to be @emph{one} argument.
1122 If you substituted any other string of characters for
1123 @kbd{collection.tar}, then that string would become the name of the
1124 archive file you create.
1125
1126 The order of the options becomes more important when you begin to use
1127 short forms. With short forms, if you type commands in the wrong order
1128 (even if you type them correctly in all other ways), you may end up with
1129 results you don't expect. For this reason, it is a good idea to get
1130 into the habit of typing options in the order that makes inherent sense.
1131 @xref{short create}, for more information on this.
1132
1133 In this example, you type the command as shown above: @option{--create}
1134 is the operation which creates the new archive
1135 (@file{collection.tar}), and @option{--file} is the option which lets
1136 you give it the name you chose. The files, @file{blues}, @file{folk},
1137 and @file{jazz}, are now members of the archive, @file{collection.tar}
1138 (they are @dfn{file name arguments} to the @option{--create} operation.
1139 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1140 in the archive, they are called @emph{archive members}, not files.
1141 (@pxref{Definitions,members}).
1142
1143 When you create an archive, you @emph{must} specify which files you
1144 want placed in the archive. If you do not specify any archive
1145 members, @GNUTAR{} will complain.
1146
1147 If you now list the contents of the working directory (@command{ls}), you will
1148 find the archive file listed as well as the files you saw previously:
1149
1150 @smallexample
1151 blues folk jazz collection.tar
1152 @end smallexample
1153
1154 @noindent
1155 Creating the archive @samp{collection.tar} did not destroy the copies of
1156 the files in the directory.
1157
1158 Keep in mind that if you don't indicate an operation, @command{tar} will not
1159 run and will prompt you for one. If you don't name any files, @command{tar}
1160 will complain. You must have write access to the working directory,
1161 or else you will not be able to create an archive in that directory.
1162
1163 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1164 an existing archive; it will delete the archive and write a new one.
1165 Use @option{--append} (@option{-r}) instead. @xref{append}.
1166
1167 @node create verbose
1168 @subsection Running @option{--create} with @option{--verbose}
1169
1170 @opindex create, using with @option{--verbose}
1171 @opindex verbose, using with @option{--create}
1172 If you include the @option{--verbose} (@option{-v}) option on the command line,
1173 @command{tar} will list the files it is acting on as it is working. In
1174 verbose mode, the @code{create} example above would appear as:
1175
1176 @smallexample
1177 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1178 blues
1179 folk
1180 jazz
1181 @end smallexample
1182
1183 This example is just like the example we showed which did not use
1184 @option{--verbose}, except that @command{tar} generated the remaining lines
1185 @iftex
1186 (note the different font styles).
1187 @end iftex
1188 @ifinfo
1189 .
1190 @end ifinfo
1191
1192 In the rest of the examples in this chapter, we will frequently use
1193 @code{verbose} mode so we can show actions or @command{tar} responses that
1194 you would otherwise not see, and which are important for you to
1195 understand.
1196
1197 @node short create
1198 @subsection Short Forms with @samp{create}
1199
1200 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1201 basic uses of @command{tar}, and you will use it countless times.
1202 Eventually, you will probably want to use abbreviated (or ``short'')
1203 forms of options. A full discussion of the three different forms that
1204 options can take appears in @ref{Styles}; for now, here is what the
1205 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1206 using short option forms:
1207
1208 @smallexample
1209 $ @kbd{tar -cvf collection.tar blues folk jazz}
1210 blues
1211 folk
1212 jazz
1213 @end smallexample
1214
1215 @noindent
1216 As you can see, the system responds the same no matter whether you use
1217 long or short option forms.
1218
1219 @FIXME{i don't like how this is worded:} One difference between using
1220 short and long option forms is that, although the exact placement of
1221 arguments following options is no more specific when using short forms,
1222 it is easier to become confused and make a mistake when using short
1223 forms. For example, suppose you attempted the above example in the
1224 following way:
1225
1226 @smallexample
1227 $ @kbd{tar -cfv collection.tar blues folk jazz}
1228 @end smallexample
1229
1230 @noindent
1231 In this case, @command{tar} will make an archive file called @file{v},
1232 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1233 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1234 is thus taken to be the chosen archive file name. @command{tar} will try
1235 to add a file called @file{collection.tar} to the @file{v} archive file;
1236 if the file @file{collection.tar} did not already exist, @command{tar} will
1237 report an error indicating that this file does not exist. If the file
1238 @file{collection.tar} does already exist (e.g., from a previous command
1239 you may have run), then @command{tar} will add this file to the archive.
1240 Because the @option{-v} option did not get registered, @command{tar} will not
1241 run under @samp{verbose} mode, and will not report its progress.
1242
1243 The end result is that you may be quite confused about what happened,
1244 and possibly overwrite a file. To illustrate this further, we will show
1245 you how an example we showed previously would look using short forms.
1246
1247 This example,
1248
1249 @smallexample
1250 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1251 @end smallexample
1252
1253 @noindent
1254 is confusing as it is. When shown using short forms, however, it
1255 becomes much more so:
1256
1257 @smallexample
1258 $ @kbd{tar blues -c folk -f collection.tar jazz}
1259 @end smallexample
1260
1261 @noindent
1262 It would be very easy to put the wrong string of characters
1263 immediately following the @option{-f}, but doing that could sacrifice
1264 valuable data.
1265
1266 For this reason, we recommend that you pay very careful attention to
1267 the order of options and placement of file and archive names,
1268 especially when using short option forms. Not having the option name
1269 written out mnemonically can affect how well you remember which option
1270 does what, and therefore where different names have to be placed.
1271
1272 @node create dir
1273 @subsection Archiving Directories
1274
1275 @cindex Archiving Directories
1276 @cindex Directories, Archiving
1277 You can archive a directory by specifying its directory name as a
1278 file name argument to @command{tar}. The files in the directory will be
1279 archived relative to the working directory, and the directory will be
1280 re-created along with its contents when the archive is extracted.
1281
1282 To archive a directory, first move to its superior directory. If you
1283 have followed the previous instructions in this tutorial, you should
1284 type:
1285
1286 @smallexample
1287 $ @kbd{cd ..}
1288 $
1289 @end smallexample
1290
1291 @noindent
1292 This will put you into the directory which contains @file{practice},
1293 i.e., your home directory. Once in the superior directory, you can
1294 specify the subdirectory, @file{practice}, as a file name argument. To
1295 store @file{practice} in the new archive file @file{music.tar}, type:
1296
1297 @smallexample
1298 $ @kbd{tar --create --verbose --file=music.tar practice}
1299 @end smallexample
1300
1301 @noindent
1302 @command{tar} should output:
1303
1304 @smallexample
1305 practice/
1306 practice/blues
1307 practice/folk
1308 practice/jazz
1309 practice/collection.tar
1310 @end smallexample
1311
1312 Note that the archive thus created is not in the subdirectory
1313 @file{practice}, but rather in the current working directory---the
1314 directory from which @command{tar} was invoked. Before trying to archive a
1315 directory from its superior directory, you should make sure you have
1316 write access to the superior directory itself, not only the directory
1317 you are trying archive with @command{tar}. For example, you will probably
1318 not be able to store your home directory in an archive by invoking
1319 @command{tar} from the root directory; @xref{absolute}. (Note
1320 also that @file{collection.tar}, the original archive file, has itself
1321 been archived. @command{tar} will accept any file as a file to be
1322 archived, regardless of its content. When @file{music.tar} is
1323 extracted, the archive file @file{collection.tar} will be re-written
1324 into the file system).
1325
1326 If you give @command{tar} a command such as
1327
1328 @smallexample
1329 $ @kbd{tar --create --file=foo.tar .}
1330 @end smallexample
1331
1332 @noindent
1333 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1334 dumped}. This happens because @command{tar} creates the archive
1335 @file{foo.tar} in the current directory before putting any files into
1336 it. Then, when @command{tar} attempts to add all the files in the
1337 directory @file{.} to the archive, it notices that the file
1338 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1339 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1340 will continue in this case, and create the archive
1341 normally, except for the exclusion of that one file. (@emph{Please
1342 note:} Other implementations of @command{tar} may not be so clever;
1343 they will enter an infinite loop when this happens, so you should not
1344 depend on this behavior unless you are certain you are running
1345 @GNUTAR{}. In general, it is wise to always place the archive outside
1346 of the directory being dumped.
1347
1348 @node list
1349 @section How to List Archives
1350
1351 @opindex list
1352 Frequently, you will find yourself wanting to determine exactly what a
1353 particular archive contains. You can use the @option{--list} (@option{-t}) operation
1354 to get the member names as they currently appear in the archive, as well
1355 as various attributes of the files at the time they were archived. For
1356 example, you can examine the archive @file{collection.tar} that you
1357 created in the last section with the command,
1358
1359 @smallexample
1360 $ @kbd{tar --list --file=collection.tar}
1361 @end smallexample
1362
1363 @noindent
1364 The output of @command{tar} would then be:
1365
1366 @smallexample
1367 blues
1368 folk
1369 jazz
1370 @end smallexample
1371
1372 @noindent
1373 The archive @file{bfiles.tar} would list as follows:
1374
1375 @smallexample
1376 ./birds
1377 baboon
1378 ./box
1379 @end smallexample
1380
1381 @noindent
1382 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1383 @var{archive-name}}) option just as with @option{--create}
1384 (@option{-c}) to specify the name of the archive.
1385
1386 @opindex list, using with @option{--verbose}
1387 @opindex verbose, using with @option{--list}
1388 If you use the @option{--verbose} (@option{-v}) option with
1389 @option{--list}, then @command{tar} will print out a listing
1390 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so forth.
1391
1392 If you had used @option{--verbose} (@option{-v}) mode, the example
1393 above would look like:
1394
1395 @smallexample
1396 $ @kbd{tar --list --verbose --file=collection.tar folk}
1397 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1398 @end smallexample
1399
1400 @cindex listing member and file names
1401 @anchor{listing member and file names}
1402 It is important to notice that the output of @kbd{tar --list
1403 --verbose} does not necessarily match that produced by @kbd{tar
1404 --create --verbose} while creating the archive. It is because
1405 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1406 prefixes from file names before storing them in the archive
1407 (@xref{absolute}, for more information). In other
1408 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1409 an archive and @dfn{member names} when listing it. Consider this
1410 example:
1411
1412 @smallexample
1413 @group
1414 $ @kbd{tar cfv archive /etc/mail}
1415 tar: Removing leading `/' from member names
1416 /etc/mail/
1417 /etc/mail/sendmail.cf
1418 /etc/mail/aliases
1419 $ @kbd{tar tf archive}
1420 etc/mail/
1421 etc/mail/sendmail.cf
1422 etc/mail/aliases
1423 @end group
1424 @end smallexample
1425
1426 @opindex show-stored-names
1427 This default behavior can sometimes be inconvenient. You can force
1428 @GNUTAR{} show member names when creating archive by supplying
1429 @option{--show-stored-names} option.
1430
1431 @table @option
1432 @item --show-stored-names
1433 Print member (as opposed to @emph{file}) names when creating the archive.
1434 @end table
1435
1436 @cindex File name arguments, using @option{--list} with
1437 @opindex list, using with file name arguments
1438 You can specify one or more individual member names as arguments when
1439 using @samp{list}. In this case, @command{tar} will only list the
1440 names of members you identify. For example, @w{@kbd{tar --list
1441 --file=afiles.tar apple}} would only print @file{apple}.
1442
1443 Because @command{tar} preserves paths, file names must be specified as
1444 they appear in the archive (ie., relative to the directory from which
1445 the archive was created). Therefore, it is essential when specifying
1446 member names to @command{tar} that you give the exact member names.
1447 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1448 error message something like @samp{tar: birds: Not found in archive},
1449 because there is no member named @file{birds}, only one named
1450 @file{./birds}. While the names @file{birds} and @file{./birds} name
1451 the same file, @emph{member} names by default are compared verbatim.
1452
1453 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1454 with @file{baboon}, because this exact member name is in the archive file
1455 @file{bfiles.tar}. If you are not sure of the exact file name,
1456 use @dfn{globbing patterns}, for example:
1457
1458 @smallexample
1459 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1460 @end smallexample
1461
1462 @noindent
1463 will list all members whose name contains @samp{b}. @xref{wildcards},
1464 for a detailed discussion of globbing patterns and related
1465 @command{tar} command line options.
1466
1467 @menu
1468 * list dir::
1469 @end menu
1470
1471 @node list dir
1472 @unnumberedsubsec Listing the Contents of a Stored Directory
1473
1474 To get information about the contents of an archived directory,
1475 use the directory name as a file name argument in conjunction with
1476 @option{--list} (@option{-t}). To find out file attributes, include the
1477 @option{--verbose} (@option{-v}) option.
1478
1479 For example, to find out about files in the directory @file{practice}, in
1480 the archive file @file{music.tar}, type:
1481
1482 @smallexample
1483 $ @kbd{tar --list --verbose --file=music.tar practice}
1484 @end smallexample
1485
1486 @command{tar} responds:
1487
1488 @smallexample
1489 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1490 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1491 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1492 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1493 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1494 @end smallexample
1495
1496 When you use a directory name as a file name argument, @command{tar} acts on
1497 all the files (including sub-directories) in that directory.
1498
1499 @node extract
1500 @section How to Extract Members from an Archive
1501 @UNREVISED
1502 @cindex Extraction
1503 @cindex Retrieving files from an archive
1504 @cindex Resurrecting files from an archive
1505
1506 @opindex extract
1507 Creating an archive is only half the job---there is no point in storing
1508 files in an archive if you can't retrieve them. The act of retrieving
1509 members from an archive so they can be used and manipulated as
1510 unarchived files again is called @dfn{extraction}. To extract files
1511 from an archive, use the @option{--extract} (@option{--get} or
1512 @option{-x}) operation. As with @option{--create}, specify the name
1513 of the archive with @option{--file} (@option{-f}) option. Extracting
1514 an archive does not modify the archive in any way; you can extract it
1515 multiple times if you want or need to.
1516
1517 Using @option{--extract}, you can extract an entire archive, or specific
1518 files. The files can be directories containing other files, or not. As
1519 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1520 long form of the operation without affecting the performance.
1521
1522 @menu
1523 * extracting archives::
1524 * extracting files::
1525 * extract dir::
1526 * extracting untrusted archives::
1527 * failing commands::
1528 @end menu
1529
1530 @node extracting archives
1531 @subsection Extracting an Entire Archive
1532
1533 To extract an entire archive, specify the archive file name only, with
1534 no individual file names as arguments. For example,
1535
1536 @smallexample
1537 $ @kbd{tar -xvf collection.tar}
1538 @end smallexample
1539
1540 @noindent
1541 produces this:
1542
1543 @smallexample
1544 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1545 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1546 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1547 @end smallexample
1548
1549 @node extracting files
1550 @subsection Extracting Specific Files
1551
1552 To extract specific archive members, give their exact member names as
1553 arguments, as printed by @option{--list} (@option{-t}). If you had
1554 mistakenly deleted one of the files you had placed in the archive
1555 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1556 from the archive without changing the archive's structure. Its
1557 contents will be identical to the original file @file{blues} that you
1558 deleted.
1559
1560 First, make sure you are in the @file{practice} directory, and list the
1561 files in the directory. Now, delete the file, @samp{blues}, and list
1562 the files in the directory again.
1563
1564 You can now extract the member @file{blues} from the archive file
1565 @file{collection.tar} like this:
1566
1567 @smallexample
1568 $ @kbd{tar --extract --file=collection.tar blues}
1569 @end smallexample
1570
1571 @noindent
1572 If you list the files in the directory again, you will see that the file
1573 @file{blues} has been restored, with its original permissions, data
1574 modification times, and owner.@footnote{This is only accidentally
1575 true, but not in general. Whereas modification times are always
1576 restored, in most cases, one has to be root for restoring the owner,
1577 and use a special option for restoring permissions. Here, it just
1578 happens that the restoring user is also the owner of the archived
1579 members, and that the current @code{umask} is compatible with original
1580 permissions.} (These parameters will be identical to those which
1581 the file had when you originally placed it in the archive; any changes
1582 you may have made before deleting the file from the file system,
1583 however, will @emph{not} have been made to the archive member.) The
1584 archive file, @samp{collection.tar}, is the same as it was before you
1585 extracted @samp{blues}. You can confirm this by running @command{tar} with
1586 @option{--list} (@option{-t}).
1587
1588 Remember that as with other operations, specifying the exact member
1589 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1590 will fail, because there is no member named @file{birds}. To extract
1591 the member named @file{./birds}, you must specify @w{@kbd{tar
1592 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1593 exact member names, use @option{--list} (@option{-t}) option
1594 (@pxref{list}). You can also extract those members that match a
1595 specific @dfn{globbing pattern}. For example, to extract from
1596 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1597 directory prefix, you could type:
1598
1599 @smallexample
1600 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1601 @end smallexample
1602
1603 @noindent
1604 Here, @option{--wildcards} instructs @command{tar} to treat
1605 command line arguments as globbing patterns and @option{--no-anchored}
1606 informs it that the patterns apply to member names after any @samp{/}
1607 delimiter. The use of globbing patterns is discussed in detail in
1608 @xref{wildcards}.
1609
1610 You can extract a file to standard output by combining the above options
1611 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1612 Output}).
1613
1614 If you give the @option{--verbose} option, then @option{--extract}
1615 will print the names of the archive members as it extracts them.
1616
1617 @node extract dir
1618 @subsection Extracting Files that are Directories
1619
1620 Extracting directories which are members of an archive is similar to
1621 extracting other files. The main difference to be aware of is that if
1622 the extracted directory has the same name as any directory already in
1623 the working directory, then files in the extracted directory will be
1624 placed into the directory of the same name. Likewise, if there are
1625 files in the pre-existing directory with the same names as the members
1626 which you extract, the files from the extracted archive will replace
1627 the files already in the working directory (and possible
1628 subdirectories). This will happen regardless of whether or not the
1629 files in the working directory were more recent than those extracted
1630 (there exist, however, special options that alter this behavior
1631 @pxref{Writing}).
1632
1633 However, if a file was stored with a directory name as part of its file
1634 name, and that directory does not exist under the working directory when
1635 the file is extracted, @command{tar} will create the directory.
1636
1637 We can demonstrate how to use @option{--extract} to extract a directory
1638 file with an example. Change to the @file{practice} directory if you
1639 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1640 go back to the parent directory and extract the archive
1641 @file{music.tar}. You may either extract the entire archive, or you may
1642 extract only the files you just deleted. To extract the entire archive,
1643 don't give any file names as arguments after the archive name
1644 @file{music.tar}. To extract only the files you deleted, use the
1645 following command:
1646
1647 @smallexample
1648 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1649 practice/folk
1650 practice/jazz
1651 @end smallexample
1652
1653 @noindent
1654 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1655 would have displayed more detail about the extracted files, as shown
1656 in the example below:
1657
1658 @smallexample
1659 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1660 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1661 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1662 @end smallexample
1663
1664 @noindent
1665 Because you created the directory with @file{practice} as part of the
1666 file names of each of the files by archiving the @file{practice}
1667 directory as @file{practice}, you must give @file{practice} as part
1668 of the file names when you extract those files from the archive.
1669
1670 @node extracting untrusted archives
1671 @subsection Extracting Archives from Untrusted Sources
1672
1673 Extracting files from archives can overwrite files that already exist.
1674 If you receive an archive from an untrusted source, you should make a
1675 new directory and extract into that directory, so that you don't have
1676 to worry about the extraction overwriting one of your existing files.
1677 For example, if @file{untrusted.tar} came from somewhere else on the
1678 Internet, and you don't necessarily trust its contents, you can
1679 extract it as follows:
1680
1681 @smallexample
1682 $ @kbd{mkdir newdir}
1683 $ @kbd{cd newdir}
1684 $ @kbd{tar -xvf ../untrusted.tar}
1685 @end smallexample
1686
1687 It is also a good practice to examine contents of the archive
1688 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1689 with @option{--verbose} (@option{-v}).
1690
1691 @node failing commands
1692 @subsection Commands That Will Fail
1693
1694 Here are some sample commands you might try which will not work, and why
1695 they won't work.
1696
1697 If you try to use this command,
1698
1699 @smallexample
1700 $ @kbd{tar -xvf music.tar folk jazz}
1701 @end smallexample
1702
1703 @noindent
1704 you will get the following response:
1705
1706 @smallexample
1707 tar: folk: Not found in archive
1708 tar: jazz: Not found in archive
1709 $
1710 @end smallexample
1711
1712 @noindent
1713 This is because these files were not originally @emph{in} the parent
1714 directory @file{..}, where the archive is located; they were in the
1715 @file{practice} directory, and their file names reflect this:
1716
1717 @smallexample
1718 $ @kbd{tar -tvf music.tar}
1719 practice/folk
1720 practice/jazz
1721 practice/rock
1722 @end smallexample
1723
1724 @FIXME{make sure the above works when going through the examples in
1725 order...}
1726
1727 @noindent
1728 Likewise, if you try to use this command,
1729
1730 @smallexample
1731 $ @kbd{tar -tvf music.tar folk jazz}
1732 @end smallexample
1733
1734 @noindent
1735 you would get a similar response. Members with those names are not in the
1736 archive. You must use the correct member names, or wildcards, in order
1737 to extract the files from the archive.
1738
1739 If you have forgotten the correct names of the files in the archive,
1740 use @w{@kbd{tar --list --verbose}} to list them correctly.
1741
1742 @FIXME{more examples, here? hag thinks it's a good idea.}
1743
1744 @node going further
1745 @section Going Further Ahead in this Manual
1746
1747 @FIXME{need to write up a node here about the things that are going to
1748 be in the rest of the manual.}
1749
1750 @node tar invocation
1751 @chapter Invoking @GNUTAR{}
1752 @UNREVISED
1753
1754 This chapter is about how one invokes the @GNUTAR{}
1755 command, from the command synopsis (@pxref{Synopsis}). There are
1756 numerous options, and many styles for writing them. One mandatory
1757 option specifies the operation @command{tar} should perform
1758 (@pxref{Operation Summary}), other options are meant to detail how
1759 this operation should be performed (@pxref{Option Summary}).
1760 Non-option arguments are not always interpreted the same way,
1761 depending on what the operation is.
1762
1763 You will find in this chapter everything about option styles and rules for
1764 writing them (@pxref{Styles}). On the other hand, operations and options
1765 are fully described elsewhere, in other chapters. Here, you will find
1766 only synthetic descriptions for operations and options, together with
1767 pointers to other parts of the @command{tar} manual.
1768
1769 Some options are so special they are fully described right in this
1770 chapter. They have the effect of inhibiting the normal operation of
1771 @command{tar} or else, they globally alter the amount of feedback the user
1772 receives about what is going on. These are the @option{--help} and
1773 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1774 and @option{--interactive} options (@pxref{interactive}).
1775
1776 @menu
1777 * Synopsis::
1778 * using tar options::
1779 * Styles::
1780 * All Options::
1781 * help::
1782 * defaults::
1783 * verbose::
1784 * interactive::
1785 @end menu
1786
1787 @node Synopsis
1788 @section General Synopsis of @command{tar}
1789
1790 The @GNUTAR{} program is invoked as either one of:
1791
1792 @smallexample
1793 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1794 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1795 @end smallexample
1796
1797 The second form is for when old options are being used.
1798
1799 You can use @command{tar} to store files in an archive, to extract them from
1800 an archive, and to do other types of archive manipulation. The primary
1801 argument to @command{tar}, which is called the @dfn{operation}, specifies
1802 which action to take. The other arguments to @command{tar} are either
1803 @dfn{options}, which change the way @command{tar} performs an operation,
1804 or file names or archive members, which specify the files or members
1805 @command{tar} is to act on.
1806
1807 You can actually type in arguments in any order, even if in this manual
1808 the options always precede the other arguments, to make examples easier
1809 to understand. Further, the option stating the main operation mode
1810 (the @command{tar} main command) is usually given first.
1811
1812 Each @var{name} in the synopsis above is interpreted as an archive member
1813 name when the main command is one of @option{--compare}
1814 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1815 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1816 @option{--update} (@option{-u}). When naming archive members, you
1817 must give the exact name of the member in the archive, as it is
1818 printed by @option{--list}. For @option{--append} (@option{-r}) and
1819 @option{--create} (@option{-c}), these @var{name} arguments specify
1820 the names of either files or directory hierarchies to place in the archive.
1821 These files or hierarchies should already exist in the file system,
1822 prior to the execution of the @command{tar} command.
1823
1824 @command{tar} interprets relative file names as being relative to the
1825 working directory. @command{tar} will make all file names relative
1826 (by removing leading slashes when archiving or restoring files),
1827 unless you specify otherwise (using the @option{--absolute-names}
1828 option). @xref{absolute}, for more information about
1829 @option{--absolute-names}.
1830
1831 If you give the name of a directory as either a file name or a member
1832 name, then @command{tar} acts recursively on all the files and directories
1833 beneath that directory. For example, the name @file{/} identifies all
1834 the files in the file system to @command{tar}.
1835
1836 The distinction between file names and archive member names is especially
1837 important when shell globbing is used, and sometimes a source of confusion
1838 for newcomers. @xref{wildcards}, for more information about globbing.
1839 The problem is that shells may only glob using existing files in the
1840 file system. Only @command{tar} itself may glob on archive members, so when
1841 needed, you must ensure that wildcard characters reach @command{tar} without
1842 being interpreted by the shell first. Using a backslash before @samp{*}
1843 or @samp{?}, or putting the whole argument between quotes, is usually
1844 sufficient for this.
1845
1846 Even if @var{name}s are often specified on the command line, they
1847 can also be read from a text file in the file system, using the
1848 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1849
1850 If you don't use any file name arguments, @option{--append} (@option{-r}),
1851 @option{--delete} and @option{--concatenate} (@option{--catenate},
1852 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1853 will usually yield a diagnostic and inhibit @command{tar} execution.
1854 The other operations of @command{tar} (@option{--list},
1855 @option{--extract}, @option{--compare}, and @option{--update})
1856 will act on the entire contents of the archive.
1857
1858 @cindex exit status
1859 @cindex return status
1860 Besides successful exits, @GNUTAR{} may fail for
1861 many reasons. Some reasons correspond to bad usage, that is, when the
1862 @command{tar} command is improperly written. Errors may be
1863 encountered later, while encountering an error processing the archive
1864 or the files. Some errors are recoverable, in which case the failure
1865 is delayed until @command{tar} has completed all its work. Some
1866 errors are such that it would not meaningful, or at least risky, to
1867 continue processing: @command{tar} then aborts processing immediately.
1868 All abnormal exits, whether immediate or delayed, should always be
1869 clearly diagnosed on @code{stderr}, after a line stating the nature of
1870 the error.
1871
1872 @GNUTAR{} returns only a few exit statuses. I'm really
1873 aiming simplicity in that area, for now. If you are not using the
1874 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1875 that everything went well, besides maybe innocuous warnings. Nonzero
1876 means that something went wrong. Right now, as of today, ``nonzero''
1877 is almost always 2, except for remote operations, where it may be
1878 128.
1879
1880 @node using tar options
1881 @section Using @command{tar} Options
1882
1883 @GNUTAR{} has a total of eight operating modes which
1884 allow you to perform a variety of tasks. You are required to choose
1885 one operating mode each time you employ the @command{tar} program by
1886 specifying one, and only one operation as an argument to the
1887 @command{tar} command (two lists of four operations each may be found
1888 at @ref{frequent operations} and @ref{Operations}). Depending on
1889 circumstances, you may also wish to customize how the chosen operating
1890 mode behaves. For example, you may wish to change the way the output
1891 looks, or the format of the files that you wish to archive may require
1892 you to do something special in order to make the archive look right.
1893
1894 You can customize and control @command{tar}'s performance by running
1895 @command{tar} with one or more options (such as @option{--verbose}
1896 (@option{-v}), which we used in the tutorial). As we said in the
1897 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1898 their name suggests) optional. Depending on the operating mode, you
1899 may specify one or more options. Different options will have different
1900 effects, but in general they all change details of the operation, such
1901 as archive format, archive name, or level of user interaction. Some
1902 options make sense with all operating modes, while others are
1903 meaningful only with particular modes. You will likely use some
1904 options frequently, while you will only use others infrequently, or
1905 not at all. (A full list of options is available in @pxref{All Options}.)
1906
1907 @vrindex TAR_OPTIONS, environment variable
1908 @anchor{TAR_OPTIONS}
1909 The @env{TAR_OPTIONS} environment variable specifies default options to
1910 be placed in front of any explicit options. For example, if
1911 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1912 if the two options @option{-v} and @option{--unlink-first} had been
1913 specified before any explicit options. Option specifications are
1914 separated by whitespace. A backslash escapes the next character, so it
1915 can be used to specify an option containing whitespace or a backslash.
1916
1917 Note that @command{tar} options are case sensitive. For example, the
1918 options @option{-T} and @option{-t} are different; the first requires an
1919 argument for stating the name of a file providing a list of @var{name}s,
1920 while the second does not require an argument and is another way to
1921 write @option{--list} (@option{-t}).
1922
1923 In addition to the eight operations, there are many options to
1924 @command{tar}, and three different styles for writing both: long (mnemonic)
1925 form, short form, and old style. These styles are discussed below.
1926 Both the options and the operations can be written in any of these three
1927 styles.
1928
1929 @FIXME{menu at end of this node. need to think of an actual outline
1930 for this chapter; probably do that after stuff from chapter 4 is
1931 incorporated.}
1932
1933 @node Styles
1934 @section The Three Option Styles
1935
1936 There are three styles for writing operations and options to the command
1937 line invoking @command{tar}. The different styles were developed at
1938 different times during the history of @command{tar}. These styles will be
1939 presented below, from the most recent to the oldest.
1940
1941 Some options must take an argument. (For example, @option{--file}
1942 (@option{-f})) takes the name of an archive file as an argument. If
1943 you do not supply an archive file name, @command{tar} will use a
1944 default, but this can be confusing; thus, we recommend that you always
1945 supply a specific archive file name.) Where you @emph{place} the
1946 arguments generally depends on which style of options you choose. We
1947 will detail specific information relevant to each option style in the
1948 sections on the different option styles, below. The differences are
1949 subtle, yet can often be very important; incorrect option placement
1950 can cause you to overwrite a number of important files. We urge you
1951 to note these differences, and only use the option style(s) which
1952 makes the most sense to you until you feel comfortable with the others.
1953
1954 Some options @emph{may} take an argument (currently, there are
1955 two such options: @option{--backup} and @option{--occurrence}). Such
1956 options may have at most long and short forms, they do not have old style
1957 equivalent. The rules for specifying an argument for such options
1958 are stricter than those for specifying mandatory arguments. Please,
1959 pay special attention to them.
1960
1961 @menu
1962 * Mnemonic Options:: Mnemonic Option Style
1963 * Short Options:: Short Option Style
1964 * Old Options:: Old Option Style
1965 * Mixing:: Mixing Option Styles
1966 @end menu
1967
1968 @node Mnemonic Options
1969 @subsection Mnemonic Option Style
1970
1971 @FIXME{have to decide whether or not to replace other occurrences of
1972 "mnemonic" with "long", or *ugh* vice versa.}
1973
1974 Each option has at least one long (or mnemonic) name starting with two
1975 dashes in a row, e.g., @option{--list}. The long names are more clear than
1976 their corresponding short or old names. It sometimes happens that a
1977 single mnemonic option has many different different names which are
1978 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1979 long option names can be given unique abbreviations. For example,
1980 @option{--cre} can be used in place of @option{--create} because there is no
1981 other mnemonic option which begins with @samp{cre}. (One way to find
1982 this out is by trying it and seeing what happens; if a particular
1983 abbreviation could represent more than one option, @command{tar} will tell
1984 you that that abbreviation is ambiguous and you'll know that that
1985 abbreviation won't work. You may also choose to run @samp{tar --help}
1986 to see a list of options. Be aware that if you run @command{tar} with a
1987 unique abbreviation for the long name of an option you didn't want to
1988 use, you are stuck; @command{tar} will perform the command as ordered.)
1989
1990 Mnemonic options are meant to be obvious and easy to remember, and their
1991 meanings are generally easier to discern than those of their
1992 corresponding short options (see below). For example:
1993
1994 @smallexample
1995 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
1996 @end smallexample
1997
1998 @noindent
1999 gives a fairly good set of hints about what the command does, even
2000 for those not fully acquainted with @command{tar}.
2001
2002 Mnemonic options which require arguments take those arguments
2003 immediately following the option name. There are two ways of
2004 specifying a mandatory argument. It can be separated from the
2005 option name either by an equal sign, or by any amount of
2006 white space characters. For example, the @option{--file} option (which
2007 tells the name of the @command{tar} archive) is given a file such as
2008 @file{archive.tar} as argument by using any of the following notations:
2009 @option{--file=archive.tar} or @option{--file archive.tar}.
2010
2011 In contrast, optional arguments must always be introduced using
2012 an equal sign. For example, the @option{--backup} option takes
2013 an optional argument specifying backup type. It must be used
2014 as @option{--backup=@var{backup-type}}.
2015
2016 @node Short Options
2017 @subsection Short Option Style
2018
2019 Most options also have a short option name. Short options start with
2020 a single dash, and are followed by a single character, e.g., @option{-t}
2021 (which is equivalent to @option{--list}). The forms are absolutely
2022 identical in function; they are interchangeable.
2023
2024 The short option names are faster to type than long option names.
2025
2026 Short options which require arguments take their arguments immediately
2027 following the option, usually separated by white space. It is also
2028 possible to stick the argument right after the short option name, using
2029 no intervening space. For example, you might write @w{@option{-f
2030 archive.tar}} or @option{-farchive.tar} instead of using
2031 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2032 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2033 specific archive, here named @file{archive.tar}.
2034
2035 Short options which take optional arguments take their arguments
2036 immediately following the option letter, @emph{without any intervening
2037 white space characters}.
2038
2039 Short options' letters may be clumped together, but you are not
2040 required to do this (as compared to old options; see below). When
2041 short options are clumped as a set, use one (single) dash for them
2042 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2043 such a set is allowed to have an argument@footnote{Clustering many
2044 options, the last of which has an argument, is a rather opaque way to
2045 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2046 even be made helpful enough for considering such usages as invalid.}.
2047
2048 When the options are separated, the argument for each option which requires
2049 an argument directly follows that option, as is usual for Unix programs.
2050 For example:
2051
2052 @smallexample
2053 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2054 @end smallexample
2055
2056 If you reorder short options' locations, be sure to move any arguments
2057 that belong to them. If you do not move the arguments properly, you may
2058 end up overwriting files.
2059
2060 @node Old Options
2061 @subsection Old Option Style
2062 @UNREVISED
2063
2064 Like short options, old options are single letters. However, old options
2065 must be written together as a single clumped set, without spaces separating
2066 them or dashes preceding them@footnote{Beware that if you precede options
2067 with a dash, you are announcing the short option style instead of the
2068 old option style; short options are decoded differently.}. This set
2069 of letters must be the first to appear on the command line, after the
2070 @command{tar} program name and some white space; old options cannot appear
2071 anywhere else. The letter of an old option is exactly the same letter as
2072 the corresponding short option. For example, the old option @samp{t} is
2073 the same as the short option @option{-t}, and consequently, the same as the
2074 mnemonic option @option{--list}. So for example, the command @w{@samp{tar
2075 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2076
2077 When options that need arguments are given together with the command,
2078 all the associated arguments follow, in the same order as the options.
2079 Thus, the example given previously could also be written in the old
2080 style as follows:
2081
2082 @smallexample
2083 $ @kbd{tar cvbf 20 /dev/rmt0}
2084 @end smallexample
2085
2086 @noindent
2087 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2088 the argument of @option{-f}.
2089
2090 On the other hand, this old style syntax makes it difficult to match
2091 option letters with their corresponding arguments, and is often
2092 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2093 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2094 argument for @option{-f}, and @option{-v} does not have a corresponding
2095 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2096 /dev/rmt0}} is clearer, putting all arguments next to the option they
2097 pertain to.
2098
2099 If you want to reorder the letters in the old option argument, be
2100 sure to reorder any corresponding argument appropriately.
2101
2102 This old way of writing @command{tar} options can surprise even experienced
2103 users. For example, the two commands:
2104
2105 @smallexample
2106 @kbd{tar cfz archive.tar.gz file}
2107 @kbd{tar -cfz archive.tar.gz file}
2108 @end smallexample
2109
2110 @noindent
2111 are quite different. The first example uses @file{archive.tar.gz} as
2112 the value for option @samp{f} and recognizes the option @samp{z}. The
2113 second example, however, uses @file{z} as the value for option
2114 @samp{f} --- probably not what was intended.
2115
2116 Old options are kept for compatibility with old versions of @command{tar}.
2117
2118 This second example could be corrected in many ways, among which the
2119 following are equivalent:
2120
2121 @smallexample
2122 @kbd{tar -czf archive.tar.gz file}
2123 @kbd{tar -cf archive.tar.gz -z file}
2124 @kbd{tar cf archive.tar.gz -z file}
2125 @end smallexample
2126
2127 @cindex option syntax, traditional
2128 As far as we know, all @command{tar} programs, @acronym{GNU} and
2129 non-@acronym{GNU}, support old options. @GNUTAR{}
2130 supports them not only for historical reasons, but also because many
2131 people are used to them. For compatibility with Unix @command{tar},
2132 the first argument is always treated as containing command and option
2133 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2134 equivalent to @w{@samp{tar -c}:} both of them specify the
2135 @option{--create} (@option{-c}) command to create an archive.
2136
2137 @node Mixing
2138 @subsection Mixing Option Styles
2139
2140 All three styles may be intermixed in a single @command{tar} command,
2141 so long as the rules for each style are fully
2142 respected@footnote{Before @GNUTAR{} version 1.11.6,
2143 a bug prevented intermixing old style options with mnemonic options in
2144 some cases.}. Old style options and either of the modern styles of
2145 options may be mixed within a single @command{tar} command. However,
2146 old style options must be introduced as the first arguments only,
2147 following the rule for old options (old options must appear directly
2148 after the @command{tar} command and some white space). Modern options
2149 may be given only after all arguments to the old options have been
2150 collected. If this rule is not respected, a modern option might be
2151 falsely interpreted as the value of the argument to one of the old
2152 style options.
2153
2154 For example, all the following commands are wholly equivalent, and
2155 illustrate the many combinations and orderings of option styles.
2156
2157 @smallexample
2158 @kbd{tar --create --file=archive.tar}
2159 @kbd{tar --create -f archive.tar}
2160 @kbd{tar --create -farchive.tar}
2161 @kbd{tar --file=archive.tar --create}
2162 @kbd{tar --file=archive.tar -c}
2163 @kbd{tar -c --file=archive.tar}
2164 @kbd{tar -c -f archive.tar}
2165 @kbd{tar -c -farchive.tar}
2166 @kbd{tar -cf archive.tar}
2167 @kbd{tar -cfarchive.tar}
2168 @kbd{tar -f archive.tar --create}
2169 @kbd{tar -f archive.tar -c}
2170 @kbd{tar -farchive.tar --create}
2171 @kbd{tar -farchive.tar -c}
2172 @kbd{tar c --file=archive.tar}
2173 @kbd{tar c -f archive.tar}
2174 @kbd{tar c -farchive.tar}
2175 @kbd{tar cf archive.tar}
2176 @kbd{tar f archive.tar --create}
2177 @kbd{tar f archive.tar -c}
2178 @kbd{tar fc archive.tar}
2179 @end smallexample
2180
2181 On the other hand, the following commands are @emph{not} equivalent to
2182 the previous set:
2183
2184 @smallexample
2185 @kbd{tar -f -c archive.tar}
2186 @kbd{tar -fc archive.tar}
2187 @kbd{tar -fcarchive.tar}
2188 @kbd{tar -farchive.tarc}
2189 @kbd{tar cfarchive.tar}
2190 @end smallexample
2191
2192 @noindent
2193 These last examples mean something completely different from what the
2194 user intended (judging based on the example in the previous set which
2195 uses long options, whose intent is therefore very clear). The first
2196 four specify that the @command{tar} archive would be a file named
2197 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2198 respectively. The first two examples also specify a single non-option,
2199 @var{name} argument having the value @samp{archive.tar}. The last
2200 example contains only old style option letters (repeating option
2201 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2202 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2203 the first sentence of this paragraph..}
2204
2205 @node All Options
2206 @section All @command{tar} Options
2207
2208 The coming manual sections contain an alphabetical listing of all
2209 @command{tar} operations and options, with brief descriptions and cross
2210 references to more in-depth explanations in the body of the manual.
2211 They also contain an alphabetically arranged table of the short option
2212 forms with their corresponding long option. You can use this table as
2213 a reference for deciphering @command{tar} commands in scripts.
2214
2215 @menu
2216 * Operation Summary::
2217 * Option Summary::
2218 * Short Option Summary::
2219 @end menu
2220
2221 @node Operation Summary
2222 @subsection Operations
2223
2224 @table @option
2225
2226 @opindex append, summary
2227 @item --append
2228 @itemx -r
2229
2230 Appends files to the end of the archive. @xref{append}.
2231
2232 @opindex catenate, summary
2233 @item --catenate
2234 @itemx -A
2235
2236 Same as @option{--concatenate}. @xref{concatenate}.
2237
2238 @opindex compare, summary
2239 @item --compare
2240 @itemx -d
2241
2242 Compares archive members with their counterparts in the file
2243 system, and reports differences in file size, mode, owner,
2244 modification date and contents. @xref{compare}.
2245
2246 @opindex concatenate, summary
2247 @item --concatenate
2248 @itemx -A
2249
2250 Appends other @command{tar} archives to the end of the archive.
2251 @xref{concatenate}.
2252
2253 @opindex create, summary
2254 @item --create
2255 @itemx -c
2256
2257 Creates a new @command{tar} archive. @xref{create}.
2258
2259 @opindex delete, summary
2260 @item --delete
2261
2262 Deletes members from the archive. Don't try this on a archive on a
2263 tape! @xref{delete}.
2264
2265 @opindex diff, summary
2266 @item --diff
2267 @itemx -d
2268
2269 Same @option{--compare}. @xref{compare}.
2270
2271 @opindex extract, summary
2272 @item --extract
2273 @itemx -x
2274
2275 Extracts members from the archive into the file system. @xref{extract}.
2276
2277 @opindex get, summary
2278 @item --get
2279 @itemx -x
2280
2281 Same as @option{--extract}. @xref{extract}.
2282
2283 @opindex list, summary
2284 @item --list
2285 @itemx -t
2286
2287 Lists the members in an archive. @xref{list}.
2288
2289 @opindex update, summary
2290 @item --update
2291 @itemx -u
2292
2293 Adds files to the end of the archive, but only if they are newer than
2294 their counterparts already in the archive, or if they do not already
2295 exist in the archive. @xref{update}.
2296
2297 @end table
2298
2299 @node Option Summary
2300 @subsection @command{tar} Options
2301
2302 @table @option
2303
2304 @opindex absolute-names, summary
2305 @item --absolute-names
2306 @itemx -P
2307
2308 Normally when creating an archive, @command{tar} strips an initial
2309 @samp{/} from member names. This option disables that behavior.
2310 @xref{absolute}.
2311
2312 @opindex after-date, summary
2313 @item --after-date
2314
2315 (See @option{--newer}, @pxref{after})
2316
2317 @opindex anchored, summary
2318 @item --anchored
2319 A pattern must match an initial subsequence of the name's components.
2320 @xref{controlling pattern-matching}.
2321
2322 @opindex atime-preserve, summary
2323 @item --atime-preserve
2324 @itemx --atime-preserve=replace
2325 @itemx --atime-preserve=system
2326
2327 Attempt to preserve the access time of files when reading them. This
2328 option currently is effective only on files that you own, unless you
2329 have superuser privileges.
2330
2331 @option{--atime-preserve=replace} remembers the access time of a file
2332 before reading it, and then restores the access time afterwards. This
2333 may cause problems if other programs are reading the file at the same
2334 time, as the times of their accesses will be lost. On most platforms
2335 restoring the access time also requires @command{tar} to restore the
2336 data modification time too, so this option may also cause problems if
2337 other programs are writing the file at the same time. (Tar attempts
2338 to detect this situation, but cannot do so reliably due to race
2339 conditions.) Worse, on most platforms restoring the access time also
2340 updates the status change time, which means that this option is
2341 incompatible with incremental backups.
2342
2343 @option{--atime-preserve=system} avoids changing time stamps on files,
2344 without interfering with time stamp updates
2345 caused by other programs, so it works better with incremental backups.
2346 However, it requires a special @code{O_NOATIME} option from the
2347 underlying operating and file system implementation, and it also requires
2348 that searching directories does not update their access times. As of
2349 this writing (November 2005) this works only with Linux, and only with
2350 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2351 way to know whether this feature actually works. Sometimes
2352 @command{tar} knows that it does not work, and if you use
2353 @option{--atime-preserve=system} then @command{tar} complains and
2354 exits right away. But other times @command{tar} might think that the
2355 option works when it actually does not.
2356
2357 Currently @option{--atime-preserve} with no operand defaults to
2358 @option{--atime-preserve=replace}, but this may change in the future
2359 as support for @option{--atime-preserve=system} improves.
2360
2361 If your operating system does not support
2362 @option{--atime-preserve=system}, you might be able to preserve access
2363 times reliably by by using the @command{mount} command. For example,
2364 you can mount the file system read-only, or access the file system via
2365 a read-only loopback mount, or use the @samp{noatime} mount option
2366 available on some systems. However, mounting typically requires
2367 superuser privileges and can be a pain to manage.
2368
2369 @opindex backup, summary
2370 @item --backup=@var{backup-type}
2371
2372 Rather than deleting files from the file system, @command{tar} will
2373 back them up using simple or numbered backups, depending upon
2374 @var{backup-type}. @xref{backup}.
2375
2376 @opindex block-number, summary
2377 @item --block-number
2378 @itemx -R
2379
2380 With this option present, @command{tar} prints error messages for read errors
2381 with the block number in the archive file. @xref{block-number}.
2382
2383 @opindex blocking-factor, summary
2384 @item --blocking-factor=@var{blocking}
2385 @itemx -b @var{blocking}
2386
2387 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2388 record. @xref{Blocking Factor}.
2389
2390 @opindex bzip2, summary
2391 @item --bzip2
2392 @itemx -j
2393
2394 This option tells @command{tar} to read or write archives through
2395 @code{bzip2}. @xref{gzip}.
2396
2397 @opindex checkpoint, summary
2398 @item --checkpoint[=@var{number}]
2399
2400 This option directs @command{tar} to print periodic checkpoint
2401 messages as it reads through the archive. It is intended for when you
2402 want a visual indication that @command{tar} is still running, but
2403 don't want to see @option{--verbose} output. For a detailed
2404 description, see @ref{Progress information}.
2405
2406 @opindex check-links, summary
2407 @item --check-links
2408 @itemx -l
2409 If this option was given, @command{tar} will check the number of links
2410 dumped for each processed file. If this number does not match the
2411 total number of hard links for the file, a warning message will be
2412 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2413 synonym for @option{--one-file-system}. The current semantics, which
2414 complies to UNIX98, was introduced with version
2415 1.15.91. @xref{Changes}, for more information.}.
2416
2417 @opindex compress, summary
2418 @opindex uncompress, summary
2419 @item --compress
2420 @itemx --uncompress
2421 @itemx -Z
2422
2423 @command{tar} will use the @command{compress} program when reading or
2424 writing the archive. This allows you to directly act on archives
2425 while saving space. @xref{gzip}.
2426
2427 @opindex confirmation, summary
2428 @item --confirmation
2429
2430 (See @option{--interactive}.) @xref{interactive}.
2431
2432 @opindex delay-directory-restore, summary
2433 @item --delay-directory-restore
2434
2435 Delay setting modification times and permissions of extracted
2436 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2437
2438 @opindex dereference, summary
2439 @item --dereference
2440 @itemx -h
2441
2442 When creating a @command{tar} archive, @command{tar} will archive the
2443 file that a symbolic link points to, rather than archiving the
2444 symlink. @xref{dereference}.
2445
2446 @opindex directory, summary
2447 @item --directory=@var{dir}
2448 @itemx -C @var{dir}
2449
2450 When this option is specified, @command{tar} will change its current directory
2451 to @var{dir} before performing any operations. When this option is used
2452 during archive creation, it is order sensitive. @xref{directory}.
2453
2454 @opindex exclude, summary
2455 @item --exclude=@var{pattern}
2456
2457 When performing operations, @command{tar} will skip files that match
2458 @var{pattern}. @xref{exclude}.
2459
2460 @opindex exclude-from, summary
2461 @item --exclude-from=@var{file}
2462 @itemx -X @var{file}
2463
2464 Similar to @option{--exclude}, except @command{tar} will use the list of
2465 patterns in the file @var{file}. @xref{exclude}.
2466
2467 @opindex exclude-caches, summary
2468 @item --exclude-caches
2469
2470 Automatically excludes all directories
2471 containing a cache directory tag. @xref{exclude}.
2472
2473 @opindex file, summary
2474 @item --file=@var{archive}
2475 @itemx -f @var{archive}
2476
2477 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2478 performs operations on, rather than @command{tar}'s compilation dependent
2479 default. @xref{file tutorial}.
2480
2481 @opindex files-from, summary
2482 @item --files-from=@var{file}
2483 @itemx -T @var{file}
2484
2485 @command{tar} will use the contents of @var{file} as a list of archive members
2486 or files to operate on, in addition to those specified on the
2487 command-line. @xref{files}.
2488
2489 @opindex force-local, summary
2490 @item --force-local
2491
2492 Forces @command{tar} to interpret the filename given to @option{--file}
2493 as a local file, even if it looks like a remote tape drive name.
2494 @xref{local and remote archives}.
2495
2496 @opindex format, summary
2497 @item --format=@var{format}
2498
2499 Selects output archive format. @var{Format} may be one of the
2500 following:
2501
2502 @table @samp
2503 @item v7
2504 Creates an archive that is compatible with Unix V7 @command{tar}.
2505
2506 @item oldgnu
2507 Creates an archive that is compatible with GNU @command{tar} version
2508 1.12 or earlier.
2509
2510 @item gnu
2511 Creates archive in GNU tar 1.13 format. Basically it is the same as
2512 @samp{oldgnu} with the only difference in the way it handles long
2513 numeric fields.
2514
2515 @item ustar
2516 Creates a @acronym{POSIX.1-1988} compatible archive.
2517
2518 @item posix
2519 Creates a @acronym{POSIX.1-2001 archive}.
2520
2521 @end table
2522
2523 @xref{Formats}, for a detailed discussion of these formats.
2524
2525 @opindex group, summary
2526 @item --group=@var{group}
2527
2528 Files added to the @command{tar} archive will have a group id of @var{group},
2529 rather than the group from the source file. @var{group} is first decoded
2530 as a group symbolic name, but if this interpretation fails, it has to be
2531 a decimal numeric group ID. @FIXME-xref{}
2532
2533 Also see the comments for the @option{--owner=@var{user}} option.
2534
2535 @opindex gzip, summary
2536 @opindex gunzip, summary
2537 @opindex ungzip, summary
2538 @item --gzip
2539 @itemx --gunzip
2540 @itemx --ungzip
2541 @itemx -z
2542
2543 This option tells @command{tar} to read or write archives through
2544 @command{gzip}, allowing @command{tar} to directly operate on several
2545 kinds of compressed archives transparently. @xref{gzip}.
2546
2547 @opindex help, summary
2548 @item --help
2549
2550 @command{tar} will print out a short message summarizing the operations and
2551 options to @command{tar} and exit. @xref{help}.
2552
2553 @opindex ignore-case, summary
2554 @item --ignore-case
2555 Ignore case when matching member or file names with
2556 patterns. @xref{controlling pattern-matching}.
2557
2558 @opindex ignore-command-error, summary
2559 @item --ignore-command-error
2560 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2561
2562 @opindex ignore-failed-read, summary
2563 @item --ignore-failed-read
2564
2565 Do not exit unsuccessfully merely because an unreadable file was encountered.
2566 @xref{Reading}.
2567
2568 @opindex ignore-zeros, summary
2569 @item --ignore-zeros
2570 @itemx -i
2571
2572 With this option, @command{tar} will ignore zeroed blocks in the
2573 archive, which normally signals EOF. @xref{Reading}.
2574
2575 @opindex incremental, summary
2576 @item --incremental
2577 @itemx -G
2578
2579 Used to inform @command{tar} that it is working with an old
2580 @acronym{GNU}-format incremental backup archive. It is intended
2581 primarily for backwards compatibility only. @xref{Incremental Dumps},
2582 for a detailed discussion of incremental archives.
2583
2584 @opindex index-file, summary
2585 @item --index-file=@var{file}
2586
2587 Send verbose output to @var{file} instead of to standard output.
2588
2589 @opindex info-script, summary
2590 @opindex new-volume-script, summary
2591 @item --info-script=@var{script-file}
2592 @itemx --new-volume-script=@var{script-file}
2593 @itemx -F @var{script-file}
2594
2595 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2596 at the end of each tape. If @var{script-file} exits with nonzero status,
2597 @command{tar} fails immediately. @xref{info-script}, for a detailed
2598 discussion of @var{script-file}.
2599
2600 @opindex interactive, summary
2601 @item --interactive
2602 @itemx --confirmation
2603 @itemx -w
2604
2605 Specifies that @command{tar} should ask the user for confirmation before
2606 performing potentially destructive options, such as overwriting files.
2607 @xref{interactive}.
2608
2609 @opindex keep-newer-files, summary
2610 @item --keep-newer-files
2611
2612 Do not replace existing files that are newer than their archive copies
2613 when extracting files from an archive.
2614
2615 @opindex keep-old-files, summary
2616 @item --keep-old-files
2617 @itemx -k
2618
2619 Do not overwrite existing files when extracting files from an archive.
2620 @xref{Keep Old Files}.
2621
2622 @opindex label, summary
2623 @item --label=@var{name}
2624 @itemx -V @var{name}
2625
2626 When creating an archive, instructs @command{tar} to write @var{name}
2627 as a name record in the archive. When extracting or listing archives,
2628 @command{tar} will only operate on archives that have a label matching
2629 the pattern specified in @var{name}. @xref{Tape Files}.
2630
2631 @opindex listed-incremental, summary
2632 @item --listed-incremental=@var{snapshot-file}
2633 @itemx -g @var{snapshot-file}
2634
2635 During a @option{--create} operation, specifies that the archive that
2636 @command{tar} creates is a new @acronym{GNU}-format incremental
2637 backup, using @var{snapshot-file} to determine which files to backup.
2638 With other operations, informs @command{tar} that the archive is in
2639 incremental format. @xref{Incremental Dumps}.
2640
2641 @opindex mode, summary
2642 @item --mode=@var{permissions}
2643
2644 When adding files to an archive, @command{tar} will use
2645 @var{permissions} for the archive members, rather than the permissions
2646 from the files. The program @command{chmod} and this @command{tar}
2647 option share the same syntax for what @var{permissions} might be.
2648 @xref{File permissions, Permissions, File permissions, fileutils,
2649 @acronym{GNU} file utilities}. This reference also has useful
2650 information for those not being overly familiar with the Unix
2651 permission system.
2652
2653 Of course, @var{permissions} might be plainly specified as an octal number.
2654 However, by using generic symbolic modifications to mode bits, this allows
2655 more flexibility. For example, the value @samp{a+rw} adds read and write
2656 permissions for everybody, while retaining executable bits on directories
2657 or on any other file already marked as executable.
2658
2659 @opindex multi-volume, summary
2660 @item --multi-volume
2661 @itemx -M
2662
2663 Informs @command{tar} that it should create or otherwise operate on a
2664 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2665
2666 @opindex new-volume-script, summary
2667 @item --new-volume-script
2668
2669 (see --info-script)
2670
2671 @opindex seek, summary
2672 @item --seek
2673 @itemx -n
2674
2675 Assume that the archive media supports seeks to arbitrary
2676 locations. Usually @command{tar} determines automatically whether
2677 the archive can be seeked or not. This option is intended for use
2678 in cases when such recognition fails.
2679
2680 @opindex newer, summary
2681 @item --newer=@var{date}
2682 @itemx --after-date=@var{date}
2683 @itemx -N
2684
2685 When creating an archive, @command{tar} will only add files that have changed
2686 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2687 is taken to be the name of a file whose data modification time specifies
2688 the date. @xref{after}.
2689
2690 @opindex newer-mtime, summary
2691 @item --newer-mtime=@var{date}
2692
2693 Like @option{--newer}, but add only files whose
2694 contents have changed (as opposed to just @option{--newer}, which will
2695 also back up files for which any status information has changed).
2696
2697 @opindex no-anchored, summary
2698 @item --no-anchored
2699 An exclude pattern can match any subsequence of the name's components.
2700 @xref{controlling pattern-matching}.
2701
2702 @opindex no-delay-directory-restore, summary
2703 @item --no-delay-directory-restore
2704
2705 Setting modification times and permissions of extracted
2706 directories when all files from this directory has been
2707 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2708
2709 @opindex no-ignore-case, summary
2710 @item --no-ignore-case
2711 Use case-sensitive matching.
2712 @xref{controlling pattern-matching}.
2713
2714 @opindex no-ignore-command-error, summary
2715 @item --no-ignore-command-error
2716 Print warnings about subprocesses terminated with a non-zero exit
2717 code. @xref{Writing to an External Program}.
2718
2719 @opindex no-quote-chars, summary
2720 @item --no-quote-chars=@var{string}
2721 Remove characters listed in @var{string} from the list of quoted
2722 characters set by the previous @option{--quote-chars} option
2723 (@pxref{quoting styles}).
2724
2725 @opindex no-recursion, summary
2726 @item --no-recursion
2727
2728 With this option, @command{tar} will not recurse into directories.
2729 @xref{recurse}.
2730
2731 @opindex no-same-owner, summary
2732 @item --no-same-owner
2733 @itemx -o
2734
2735 When extracting an archive, do not attempt to preserve the owner
2736 specified in the @command{tar} archive. This the default behavior
2737 for ordinary users.
2738
2739 @opindex no-same-permissions, summary
2740 @item --no-same-permissions
2741
2742 When extracting an archive, subtract the user's umask from files from
2743 the permissions specified in the archive. This is the default behavior
2744 for ordinary users.
2745
2746 @opindex no-wildcards, summary
2747 @item --no-wildcards
2748 Do not use wildcards.
2749 @xref{controlling pattern-matching}.
2750
2751 @opindex no-wildcards-match-slash, summary
2752 @item --no-wildcards-match-slash
2753 Wildcards do not match @samp{/}.
2754 @xref{controlling pattern-matching}.
2755
2756 @opindex null, summary
2757 @item --null
2758
2759 When @command{tar} is using the @option{--files-from} option, this option
2760 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2761 @command{tar} can correctly work with file names that contain newlines.
2762 @xref{nul}.
2763
2764 @opindex numeric-owner, summary
2765 @item --numeric-owner
2766
2767 This option will notify @command{tar} that it should use numeric user
2768 and group IDs when creating a @command{tar} file, rather than names.
2769 @xref{Attributes}.
2770
2771 @item -o
2772 When extracting files, this option is a synonym for
2773 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2774 restoring ownership of files being extracted.
2775
2776 When creating an archive, @option{-o} is a synonym for
2777 @option{--old-archive}. This behavior is for compatibility
2778 with previous versions of @GNUTAR{}, and will be
2779 removed in the future releases.
2780
2781 @xref{Changes}, for more information.
2782
2783 @opindex occurrence, summary
2784 @item --occurrence[=@var{number}]
2785
2786 This option can be used in conjunction with one of the subcommands
2787 @option{--delete}, @option{--diff}, @option{--extract} or
2788 @option{--list} when a list of files is given either on the command
2789 line or via @option{-T} option.
2790
2791 This option instructs @command{tar} to process only the @var{number}th
2792 occurrence of each named file. @var{Number} defaults to 1, so
2793
2794 @smallexample
2795 tar -x -f archive.tar --occurrence filename
2796 @end smallexample
2797
2798 @noindent
2799 will extract the first occurrence of @file{filename} from @file{archive.tar}
2800 and will terminate without scanning to the end of the archive.
2801
2802 @opindex old-archive, summary
2803 @item --old-archive
2804 Synonym for @option{--format=v7}.
2805
2806 @opindex one-file-system, summary
2807 @item --one-file-system
2808 Used when creating an archive. Prevents @command{tar} from recursing into
2809 directories that are on different file systems from the current
2810 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2811 synonym for @option{--one-file-system}. This has changed in version
2812 1.15.91. @xref{Changes}, for more information.}.
2813
2814 @opindex overwrite, summary
2815 @item --overwrite
2816
2817 Overwrite existing files and directory metadata when extracting files
2818 from an archive. @xref{Overwrite Old Files}.
2819
2820 @opindex overwrite-dir, summary
2821 @item --overwrite-dir
2822
2823 Overwrite the metadata of existing directories when extracting files
2824 from an archive. @xref{Overwrite Old Files}.
2825
2826 @opindex owner, summary
2827 @item --owner=@var{user}
2828
2829 Specifies that @command{tar} should use @var{user} as the owner of members
2830 when creating archives, instead of the user associated with the source
2831 file. @var{user} is first decoded as a user symbolic name, but if
2832 this interpretation fails, it has to be a decimal numeric user ID.
2833 @FIXME-xref{}
2834
2835 There is no value indicating a missing number, and @samp{0} usually means
2836 @code{root}. Some people like to force @samp{0} as the value to offer in
2837 their distributions for the owner of files, because the @code{root} user is
2838 anonymous anyway, so that might as well be the owner of anonymous archives.
2839
2840 This option does not affect extraction from archives.
2841
2842 @opindex transform, summary
2843 @item --transform=@var{sed-expr}
2844
2845 Transform file or member names using @command{sed} replacement expression
2846 @var{sed-expr}. For example,
2847
2848 @smallexample
2849 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2850 @end smallexample
2851
2852 @noindent
2853 will add to @file{archive} files from the current working directory,
2854 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2855 discussion, @xref{transform}.
2856
2857 To see transformed member names in verbose listings, use
2858 @option{--show-transformed-names} option
2859 (@pxref{show-transformed-names}).
2860
2861 @opindex quote-chars, summary
2862 @item --quote-chars=@var{string}
2863 Always quote characters from @var{string}, even if the selected
2864 quoting style would not quote them (@pxref{quoting styles}).
2865
2866 @opindex quoting-style, summary
2867 @item --quoting-style=@var{style}
2868 Set quoting style to use when printing member and file names
2869 (@pxref{quoting styles}). Valid @var{style} values are:
2870 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2871 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2872 style is @code{escape}, unless overridden while configuring the
2873 package.
2874
2875 @opindex pax-option, summary
2876 @item --pax-option=@var{keyword-list}
2877 This option is meaningful only with @acronym{POSIX.1-2001} archives
2878 (@pxref{posix}). It modifies the way @command{tar} handles the
2879 extended header keywords. @var{Keyword-list} is a comma-separated
2880 list of keyword options. @xref{PAX keywords}, for a detailed
2881 discussion.
2882
2883 @opindex portability, summary
2884 @item --portability
2885 @itemx --old-archive
2886 Synonym for @option{--format=v7}.
2887
2888 @opindex posix, summary
2889 @item --posix
2890 Same as @option{--format=posix}.
2891
2892 @opindex preserve, summary
2893 @item --preserve
2894
2895 Synonymous with specifying both @option{--preserve-permissions} and
2896 @option{--same-order}. @xref{Setting Access Permissions}.
2897
2898 @opindex preserve-order, summary
2899 @item --preserve-order
2900
2901 (See @option{--same-order}; @pxref{Reading}.)
2902
2903 @opindex preserve-permissions, summary
2904 @opindex same-permissions, summary
2905 @item --preserve-permissions
2906 @itemx --same-permissions
2907 @itemx -p
2908
2909 When @command{tar} is extracting an archive, it normally subtracts the
2910 users' umask from the permissions specified in the archive and uses
2911 that number as the permissions to create the destination file.
2912 Specifying this option instructs @command{tar} that it should use the
2913 permissions directly from the archive. @xref{Setting Access Permissions}.
2914
2915 @opindex read-full-records, summary
2916 @item --read-full-records
2917 @itemx -B
2918
2919 Specifies that @command{tar} should reblock its input, for reading
2920 from pipes on systems with buggy implementations. @xref{Reading}.
2921
2922 @opindex record-size, summary
2923 @item --record-size=@var{size}
2924
2925 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2926 archive. @xref{Blocking Factor}.
2927
2928 @opindex recursion, summary
2929 @item --recursion
2930
2931 With this option, @command{tar} recurses into directories.
2932 @xref{recurse}.
2933
2934 @opindex recursive-unlink, summary
2935 @item --recursive-unlink
2936
2937 Remove existing
2938 directory hierarchies before extracting directories of the same name
2939 from the archive. @xref{Recursive Unlink}.
2940
2941 @opindex remove-files, summary
2942 @item --remove-files
2943
2944 Directs @command{tar} to remove the source file from the file system after
2945 appending it to an archive. @xref{remove files}.
2946
2947 @opindex restrict, summary
2948 @item --restrict
2949
2950 Disable use of some potentially harmful @command{tar} options.
2951 Currently this option disables shell invocaton from multi-volume menu
2952 (@pxref{Using Multiple Tapes}).
2953
2954 @opindex rmt-command, summary
2955 @item --rmt-command=@var{cmd}
2956
2957 Notifies @command{tar} that it should use @var{cmd} instead of
2958 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2959
2960 @opindex rsh-command, summary
2961 @item --rsh-command=@var{cmd}
2962
2963 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2964 devices. @xref{Device}.
2965
2966 @opindex same-order, summary
2967 @item --same-order
2968 @itemx --preserve-order
2969 @itemx -s
2970
2971 This option is an optimization for @command{tar} when running on machines with
2972 small amounts of memory. It informs @command{tar} that the list of file
2973 arguments has already been sorted to match the order of files in the
2974 archive. @xref{Reading}.
2975
2976 @opindex same-owner, summary
2977 @item --same-owner
2978
2979 When extracting an archive, @command{tar} will attempt to preserve the owner
2980 specified in the @command{tar} archive with this option present.
2981 This is the default behavior for the superuser; this option has an
2982 effect only for ordinary users. @xref{Attributes}.
2983
2984 @opindex same-permissions, summary
2985 @item --same-permissions
2986
2987 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
2988
2989 @opindex show-defaults, summary
2990 @item --show-defaults
2991
2992 Displays the default options used by @command{tar} and exits
2993 successfully. This option is intended for use in shell scripts.
2994 Here is an example of what you can see using this option:
2995
2996 @smallexample
2997 $ tar --show-defaults
2998 --format=gnu -f- -b20 --quoting-style=escape \
2999 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3000 @end smallexample
3001
3002 @opindex show-omitted-dirs, summary
3003 @item --show-omitted-dirs
3004
3005 Instructs @command{tar} to mention directories its skipping over when
3006 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3007
3008 @opindex show-transformed-names, summary
3009 @opindex show-stored-names, summary
3010 @item --show-transformed-names
3011 @itemx --show-stored-names
3012
3013 Display file or member names after applying any transformations
3014 (@pxref{transform}). In particular, when used in conjunction with one of
3015 archive creation operations it instructs tar to list the member names
3016 stored in the archive, as opposed to the actual file
3017 names. @xref{listing member and file names}.
3018
3019 @opindex sparse, summary
3020 @item --sparse
3021 @itemx -S
3022
3023 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3024 sparse files efficiently. @xref{sparse}.
3025
3026 @opindex starting-file, summary
3027 @item --starting-file=@var{name}
3028 @itemx -K @var{name}
3029
3030 This option affects extraction only; @command{tar} will skip extracting
3031 files in the archive until it finds one that matches @var{name}.
3032 @xref{Scarce}.
3033
3034 @opindex strip-components, summary
3035 @item --strip-components=@var{number}
3036 Strip given @var{number} of leading components from file names before
3037 extraction.@footnote{This option was called @option{--strip-path} in
3038 version 1.14.} For example, if archive @file{archive.tar} contained
3039 @file{/some/file/name}, then running
3040
3041 @smallexample
3042 tar --extract --file archive.tar --strip-components=2
3043 @end smallexample
3044
3045 @noindent
3046 would extract this file to file @file{name}.
3047
3048 @opindex suffix, summary
3049 @item --suffix=@var{suffix}
3050
3051 Alters the suffix @command{tar} uses when backing up files from the default
3052 @samp{~}. @xref{backup}.
3053
3054 @opindex tape-length, summary
3055 @item --tape-length=@var{num}
3056 @itemx -L @var{num}
3057
3058 Specifies the length of tapes that @command{tar} is writing as being
3059 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3060
3061 @opindex test-label, summary
3062 @item --test-label
3063
3064 Reads the volume label. If an argument is specified, test whether it
3065 matches the volume label. @xref{--test-label option}.
3066
3067 @opindex to-command, summary
3068 @item --to-command=@var{command}
3069
3070 During extraction @command{tar} will pipe extracted files to the
3071 standard input of @var{command}. @xref{Writing to an External Program}.
3072
3073 @opindex to-stdout, summary
3074 @item --to-stdout
3075 @itemx -O
3076
3077 During extraction, @command{tar} will extract files to stdout rather
3078 than to the file system. @xref{Writing to Standard Output}.
3079
3080 @opindex totals, summary
3081 @item --totals[=@var{signo}]
3082
3083 Displays the total number of bytes transferred when processing an
3084 archive. If an argument is given, these data are displayed on
3085 request, when signal @var{signo} is delivered to @command{tar}.
3086 @xref{totals}.
3087
3088 @opindex touch, summary
3089 @item --touch
3090 @itemx -m
3091
3092 Sets the data modification time of extracted files to the extraction time,
3093 rather than the data modification time stored in the archive.
3094 @xref{Data Modification Times}.
3095
3096 @opindex uncompress, summary
3097 @item --uncompress
3098
3099 (See @option{--compress}. @pxref{gzip})
3100
3101 @opindex ungzip, summary
3102 @item --ungzip
3103
3104 (See @option{--gzip}. @pxref{gzip})
3105
3106 @opindex unlink-first, summary
3107 @item --unlink-first
3108 @itemx -U
3109
3110 Directs @command{tar} to remove the corresponding file from the file
3111 system before extracting it from the archive. @xref{Unlink First}.
3112
3113 @opindex use-compress-program, summary
3114 @item --use-compress-program=@var{prog}
3115
3116 Instructs @command{tar} to access the archive through @var{prog}, which is
3117 presumed to be a compression program of some sort. @xref{gzip}.
3118
3119 @opindex utc, summary
3120 @item --utc
3121
3122 Display file modification dates in @acronym{UTC}. This option implies
3123 @option{--verbose}.
3124
3125 @opindex verbose, summary
3126 @item --verbose
3127 @itemx -v
3128
3129 Specifies that @command{tar} should be more verbose about the operations its
3130 performing. This option can be specified multiple times for some
3131 operations to increase the amount of information displayed.
3132 @xref{verbose}.
3133
3134 @opindex verify, summary
3135 @item --verify
3136 @itemx -W
3137
3138 Verifies that the archive was correctly written when creating an
3139 archive. @xref{verify}.
3140
3141 @opindex version, summary
3142 @item --version
3143
3144 Print information about the program's name, version, origin and legal
3145 status, all on standard output, and then exit successfully.
3146 @xref{help}.
3147
3148 @opindex volno-file, summary
3149 @item --volno-file=@var{file}
3150
3151 Used in conjunction with @option{--multi-volume}. @command{tar} will keep track
3152 of which volume of a multi-volume archive its working in @var{file}.
3153 @xref{volno-file}.
3154
3155 @opindex wildcards, summary
3156 @item --wildcards
3157 Use wildcards when matching member names with patterns.
3158 @xref{controlling pattern-matching}.
3159
3160 @opindex wildcards-match-slash, summary
3161 @item --wildcards-match-slash
3162 Wildcards match @samp{/}.
3163 @xref{controlling pattern-matching}.
3164 @end table
3165
3166 @node Short Option Summary
3167 @subsection Short Options Cross Reference
3168
3169 Here is an alphabetized list of all of the short option forms, matching
3170 them with the equivalent long option.
3171
3172 @table @option
3173
3174 @item -A
3175
3176 @option{--concatenate}
3177
3178 @item -B
3179
3180 @option{--read-full-records}
3181
3182 @item -C
3183
3184 @option{--directory}
3185
3186 @item -F
3187
3188 @option{--info-script}
3189
3190 @item -G
3191
3192 @option{--incremental}
3193
3194 @item -K
3195
3196 @option{--starting-file}
3197
3198 @item -L
3199
3200 @option{--tape-length}
3201
3202 @item -M
3203
3204 @option{--multi-volume}
3205
3206 @item -N
3207
3208 @option{--newer}
3209
3210 @item -O
3211
3212 @option{--to-stdout}
3213
3214 @item -P
3215
3216 @option{--absolute-names}
3217
3218 @item -R
3219
3220 @option{--block-number}
3221
3222 @item -S
3223
3224 @option{--sparse}
3225
3226 @item -T
3227
3228 @option{--files-from}
3229
3230 @item -U
3231
3232 @option{--unlink-first}
3233
3234 @item -V
3235
3236 @option{--label}
3237
3238 @item -W
3239
3240 @option{--verify}
3241
3242 @item -X
3243
3244 @option{--exclude-from}
3245
3246 @item -Z
3247
3248 @option{--compress}
3249
3250 @item -b
3251
3252 @option{--blocking-factor}
3253
3254 @item -c
3255
3256 @option{--create}
3257
3258 @item -d
3259
3260 @option{--compare}
3261
3262 @item -f
3263
3264 @option{--file}
3265
3266 @item -g
3267
3268 @option{--listed-incremental}
3269
3270 @item -h
3271
3272 @option{--dereference}
3273
3274 @item -i
3275
3276 @option{--ignore-zeros}
3277
3278 @item -j
3279
3280 @option{--bzip2}
3281
3282 @item -k
3283
3284 @option{--keep-old-files}
3285
3286 @item -l
3287
3288 @option{--one-file-system}. Use of this short option is deprecated. It
3289 is retained for compatibility with the earlier versions of GNU
3290 @command{tar}, and will be changed in future releases.
3291
3292 @xref{Changes}, for more information.
3293
3294 @item -m
3295
3296 @option{--touch}
3297
3298 @item -o
3299
3300 When creating --- @option{--no-same-owner}, when extracting ---
3301 @option{--portability}.
3302
3303 The later usage is deprecated. It is retained for compatibility with
3304 the earlier versions of @GNUTAR{}. In the future releases
3305 @option{-o} will be equivalent to @option{--no-same-owner} only.
3306
3307 @item -p
3308
3309 @option{--preserve-permissions}
3310
3311 @item -r
3312
3313 @option{--append}
3314
3315 @item -s
3316
3317 @option{--same-order}
3318
3319 @item -t
3320
3321 @option{--list}
3322
3323 @item -u
3324
3325 @option{--update}
3326
3327 @item -v
3328
3329 @option{--verbose}
3330
3331 @item -w
3332
3333 @option{--interactive}
3334
3335 @item -x
3336
3337 @option{--extract}
3338
3339 @item -z
3340
3341 @option{--gzip}
3342
3343 @end table
3344
3345 @node help
3346 @section @GNUTAR{} documentation
3347
3348 @cindex Getting program version number
3349 @opindex version
3350 @cindex Version of the @command{tar} program
3351 Being careful, the first thing is really checking that you are using
3352 @GNUTAR{}, indeed. The @option{--version} option
3353 causes @command{tar} to print information about its name, version,
3354 origin and legal status, all on standard output, and then exit
3355 successfully. For example, @w{@samp{tar --version}} might print:
3356
3357 @smallexample
3358 tar (GNU tar) 1.15.2
3359 Copyright (C) 2006 Free Software Foundation, Inc.
3360 This is free software. You may redistribute copies of it under the terms of
3361 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3362 There is NO WARRANTY, to the extent permitted by law.
3363
3364 Written by John Gilmore and Jay Fenlason.
3365 @end smallexample
3366
3367 @noindent
3368 The first occurrence of @samp{tar} in the result above is the program
3369 name in the package (for example, @command{rmt} is another program),
3370 while the second occurrence of @samp{tar} is the name of the package
3371 itself, containing possibly many programs. The package is currently
3372 named @samp{tar}, after the name of the main program it
3373 contains@footnote{There are plans to merge the @command{cpio} and
3374 @command{tar} packages into a single one which would be called
3375 @code{paxutils}. So, who knows if, one of this days, the
3376 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3377 paxutils) 3.2}}}.
3378
3379 @cindex Obtaining help
3380 @cindex Listing all @command{tar} options
3381 @opindex help, introduction
3382 Another thing you might want to do is checking the spelling or meaning
3383 of some particular @command{tar} option, without resorting to this
3384 manual, for once you have carefully read it. @GNUTAR{}
3385 has a short help feature, triggerable through the
3386 @option{--help} option. By using this option, @command{tar} will
3387 print a usage message listing all available options on standard
3388 output, then exit successfully, without doing anything else and
3389 ignoring all other options. Even if this is only a brief summary, it
3390 may be several screens long. So, if you are not using some kind of
3391 scrollable window, you might prefer to use something like:
3392
3393 @smallexample
3394 $ @kbd{tar --help | less}
3395 @end smallexample
3396
3397 @noindent
3398 presuming, here, that you like using @command{less} for a pager. Other
3399 popular pagers are @command{more} and @command{pg}. If you know about some
3400 @var{keyword} which interests you and do not want to read all the
3401 @option{--help} output, another common idiom is doing:
3402
3403 @smallexample
3404 tar --help | grep @var{keyword}
3405 @end smallexample
3406
3407 @noindent
3408 for getting only the pertinent lines. Notice, however, that some
3409 @command{tar} options have long description lines and the above
3410 command will list only the first of them.
3411
3412 The exact look of the option summary displayed by @kbd{tar --help} is
3413 configurable. @xref{Configuring Help Summary}, for a detailed description.
3414
3415 @opindex usage
3416 If you only wish to check the spelling of an option, running @kbd{tar
3417 --usage} may be a better choice. This will display a terse list of
3418 @command{tar} option without accompanying explanations.
3419
3420 The short help output is quite succinct, and you might have to get
3421 back to the full documentation for precise points. If you are reading
3422 this paragraph, you already have the @command{tar} manual in some
3423 form. This manual is available in a variety of forms from
3424 @url{http://www.gnu.org/software/tar/manual}. It may printed out of the @GNUTAR{}
3425 distribution, provided you have @TeX{} already installed somewhere,
3426 and a laser printer around. Just configure the distribution, execute
3427 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3428 usual way (contact your local guru to know how). If @GNUTAR{}
3429 has been conveniently installed at your place, this
3430 manual is also available in interactive, hypertextual form as an Info
3431 file. Just call @w{@samp{info tar}} or, if you do not have the
3432 @command{info} program handy, use the Info reader provided within
3433 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3434
3435 There is currently no @code{man} page for @GNUTAR{}.
3436 If you observe such a @code{man} page on the system you are running,
3437 either it does not belong to @GNUTAR{}, or it has not
3438 been produced by @acronym{GNU}. Some package maintainers convert
3439 @kbd{tar --help} output to a man page, using @command{help2man}. In
3440 any case, please bear in mind that the authoritative source of
3441 information about @GNUTAR{} is this Texinfo documentation.
3442
3443 @node defaults
3444 @section Obtaining @GNUTAR{} default values
3445
3446 @opindex show-defaults
3447 @GNUTAR{} has some predefined defaults that are used when you do not
3448 explicitely specify another values. To obtain a list of such
3449 defaults, use @option{--show-defaults} option. This will output the
3450 values in the form of @command{tar} command line options:
3451
3452 @smallexample
3453 @group
3454 @kbd{tar --show-defaults}
3455 --format=gnu -f- -b20 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3456 @end group
3457 @end smallexample
3458
3459 @noindent
3460 The above output shows that this version of @GNUTAR{} defaults to
3461 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3462 output as the archive, if no @option{--file} option has been given
3463 (@pxref{file tutorial}), the default blocking factor is 20
3464 (@pxref{Blocking Factor}). It also shows the default locations where
3465 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3466
3467 @node verbose
3468 @section Checking @command{tar} progress
3469
3470 Typically, @command{tar} performs most operations without reporting any
3471 information to the user except error messages. When using @command{tar}
3472 with many options, particularly ones with complicated or
3473 difficult-to-predict behavior, it is possible to make serious mistakes.
3474 @command{tar} provides several options that make observing @command{tar}
3475 easier. These options cause @command{tar} to print information as it
3476 progresses in its job, and you might want to use them just for being
3477 more careful about what is going on, or merely for entertaining
3478 yourself. If you have encountered a problem when operating on an
3479 archive, however, you may need more information than just an error
3480 message in order to solve the problem. The following options can be
3481 helpful diagnostic tools.
3482
3483 @cindex Verbose operation
3484 @opindex verbose
3485 Normally, the @option{--list} (@option{-t}) command to list an archive
3486 prints just the file names (one per line) and the other commands are
3487 silent. When used with most operations, the @option{--verbose}
3488 (@option{-v}) option causes @command{tar} to print the name of each
3489 file or archive member as it is processed. This and the other options
3490 which make @command{tar} print status information can be useful in
3491 monitoring @command{tar}.
3492
3493 With @option{--create} or @option{--extract}, @option{--verbose} used
3494 once just prints the names of the files or members as they are processed.
3495 Using it twice causes @command{tar} to print a longer listing
3496 (reminiscent of @samp{ls -l}) for each member. Since @option{--list}
3497 already prints the names of the members, @option{--verbose} used once
3498 with @option{--list} causes @command{tar} to print an @samp{ls -l}
3499 type listing of the files in the archive. The following examples both
3500 extract members with long list output:
3501
3502 @smallexample
3503 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3504 $ @kbd{tar xvvf archive.tar}
3505 @end smallexample
3506
3507 Verbose output appears on the standard output except when an archive is
3508 being written to the standard output, as with @samp{tar --create
3509 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3510 installer let standard output be the default archive). In that case
3511 @command{tar} writes verbose output to the standard error stream.
3512
3513 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3514 verbose output to @var{file} rather than to standard output or standard
3515 error.
3516
3517 @anchor{totals}
3518 @cindex Obtaining total status information
3519 @opindex totals
3520 The @option{--totals} option causes @command{tar} to print on the
3521 standard error the total amount of bytes transferred when processing
3522 an archive. When creating or appending to an archive, this option
3523 prints the number of bytes written to the archive and the average
3524 speed at which they have been written, e.g.:
3525
3526 @smallexample
3527 @group
3528 $ @kbd{tar -c -f archive.tar --totals /home}
3529 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3530 @end group
3531 @end smallexample
3532
3533 When reading an archive, this option displays the number of bytes
3534 read:
3535
3536 @smallexample
3537 @group
3538 $ @kbd{tar -x -f archive.tar --totals}
3539 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3540 @end group
3541 @end smallexample
3542
3543 Finally, when deleting from an archive, the @option{--totals} option
3544 displays both numbers plus number of bytes removed from the archive:
3545
3546 @smallexample
3547 @group
3548 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3549 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3550 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3551 Total bytes deleted: 1474048
3552 @end group
3553 @end smallexample
3554
3555 You can also obtain this information on request. When
3556 @option{--totals} is used with an argument, this argument is
3557 interpreted as a symbolic name of a signal, upon delivery of which the
3558 statistics is to be printed:
3559
3560 @table @option
3561 @item --totals=@var{signo}
3562 Print statistics upon delivery of signal @var{signo}. Valid arguments
3563 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3564 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3565 accepted.
3566 @end table
3567
3568 Both forms of @option{--totals} option can be used simultaneously.
3569 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3570 extract all members from its default archive and print statistics
3571 after finishing the extraction, as well as when receiving signal
3572 @code{SIGUSR1}.
3573
3574 @anchor{Progress information}
3575 @cindex Progress information
3576 @opindex checkpoint
3577 The @option{--checkpoint} option prints an occasional message
3578 as @command{tar} reads or writes the archive. It is designed for
3579 those who don't need the more detailed (and voluminous) output of
3580 @option{--block-number} (@option{-R}), but do want visual confirmation
3581 that @command{tar} is actually making forward progress. By default it
3582 prints a message each 10 records read or written. This can be changed
3583 by giving it a numeric argument after an equal sign:
3584
3585 @smallexample
3586 $ @kbd{tar -c --checkpoint=1000} /var
3587 tar: Write checkpoint 1000
3588 tar: Write checkpoint 2000
3589 tar: Write checkpoint 3000
3590 @end smallexample
3591
3592 This example shows the default checkpoint message used by
3593 @command{tar}. If you place a dot immediately after the equal
3594 sign, it will print a @samp{.} at each checkpoint. For example:
3595
3596 @smallexample
3597 $ @kbd{tar -c --checkpoint=.1000} /var
3598 ...
3599 @end smallexample
3600
3601 @opindex show-omitted-dirs
3602 @anchor{show-omitted-dirs}
3603 The @option{--show-omitted-dirs} option, when reading an archive---with
3604 @option{--list} or @option{--extract}, for example---causes a message
3605 to be printed for each directory in the archive which is skipped.
3606 This happens regardless of the reason for skipping: the directory might
3607 not have been named on the command line (implicitly or explicitly),
3608 it might be excluded by the use of the
3609 @option{--exclude=@var{pattern}} option, or some other reason.
3610
3611 @opindex block-number
3612 @cindex Block number where error occurred
3613 @anchor{block-number}
3614 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3615 every message it would normally produce, the block number within the
3616 archive where the message was triggered. Also, supplementary messages
3617 are triggered when reading blocks full of NULs, or when hitting end of
3618 file on the archive. As of now, if the archive if properly terminated
3619 with a NUL block, the reading of the file may stop before end of file
3620 is met, so the position of end of file will not usually show when
3621 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3622 drains the archive before exiting when reading the
3623 archive from a pipe.
3624
3625 @cindex Error message, block number of
3626 This option is especially useful when reading damaged archives, since
3627 it helps pinpoint the damaged sections. It can also be used with
3628 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3629 choose among several backup tapes when retrieving a file later, in
3630 favor of the tape where the file appears earliest (closest to the
3631 front of the tape). @xref{backup}.
3632
3633 @node interactive
3634 @section Asking for Confirmation During Operations
3635 @cindex Interactive operation
3636
3637 Typically, @command{tar} carries out a command without stopping for
3638 further instructions. In some situations however, you may want to
3639 exclude some files and archive members from the operation (for instance
3640 if disk or storage space is tight). You can do this by excluding
3641 certain files automatically (@pxref{Choosing}), or by performing
3642 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3643 @command{tar} also accepts @option{--confirmation} for this option.
3644
3645 @opindex interactive
3646 When the @option{--interactive} (@option{-w}) option is specified, before
3647 reading, writing, or deleting files, @command{tar} first prints a message
3648 for each such file, telling what operation it intends to take, then asks
3649 for confirmation on the terminal. The actions which require
3650 confirmation include adding a file to the archive, extracting a file
3651 from the archive, deleting a file from the archive, and deleting a file
3652 from disk. To confirm the action, you must type a line of input
3653 beginning with @samp{y}. If your input line begins with anything other
3654 than @samp{y}, @command{tar} skips that file.
3655
3656 If @command{tar} is reading the archive from the standard input,
3657 @command{tar} opens the file @file{/dev/tty} to support the interactive
3658 communications.
3659
3660 Verbose output is normally sent to standard output, separate from
3661 other error messages. However, if the archive is produced directly
3662 on standard output, then verbose output is mixed with errors on
3663 @code{stderr}. Producing the archive on standard output may be used
3664 as a way to avoid using disk space, when the archive is soon to be
3665 consumed by another process reading it, say. Some people felt the need
3666 of producing an archive on stdout, still willing to segregate between
3667 verbose output and error output. A possible approach would be using a
3668 named pipe to receive the archive, and having the consumer process to
3669 read from that named pipe. This has the advantage of letting standard
3670 output free to receive verbose output, all separate from errors.
3671
3672 @node operations
3673 @chapter @GNUTAR{} Operations
3674
3675 @menu
3676 * Basic tar::
3677 * Advanced tar::
3678 * create options::
3679 * extract options::
3680 * backup::
3681 * Applications::
3682 * looking ahead::
3683 @end menu
3684
3685 @node Basic tar
3686 @section Basic @GNUTAR{} Operations
3687
3688 The basic @command{tar} operations, @option{--create} (@option{-c}),
3689 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3690 @option{-x}), are currently presented and described in the tutorial
3691 chapter of this manual. This section provides some complementary notes
3692 for these operations.
3693
3694 @table @option
3695 @opindex create, complementary notes
3696 @item --create
3697 @itemx -c
3698
3699 Creating an empty archive would have some kind of elegance. One can
3700 initialize an empty archive and later use @option{--append}
3701 (@option{-r}) for adding all members. Some applications would not
3702 welcome making an exception in the way of adding the first archive
3703 member. On the other hand, many people reported that it is
3704 dangerously too easy for @command{tar} to destroy a magnetic tape with
3705 an empty archive@footnote{This is well described in @cite{Unix-haters
3706 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3707 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3708
3709 @enumerate
3710 @item
3711 Mistakingly using @code{create} instead of @code{extract}, when the
3712 intent was to extract the full contents of an archive. This error
3713 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3714 the QWERTY keyboard. Instead of being unpacked, the archive then
3715 gets wholly destroyed. When users speak about @dfn{exploding} an
3716 archive, they usually mean something else :-).
3717
3718 @item
3719 Forgetting the argument to @code{file}, when the intent was to create
3720 an archive with a single file in it. This error is likely because a
3721 tired user can easily add the @kbd{f} key to the cluster of option
3722 letters, by the mere force of habit, without realizing the full
3723 consequence of doing so. The usual consequence is that the single
3724 file, which was meant to be saved, is rather destroyed.
3725 @end enumerate
3726
3727 So, recognizing the likelihood and the catastrophical nature of these
3728 errors, @GNUTAR{} now takes some distance from elegance, and
3729 cowardly refuses to create an archive when @option{--create} option is
3730 given, there are no arguments besides options, and
3731 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3732 around the cautiousness of @GNUTAR{} and nevertheless create an
3733 archive with nothing in it, one may still use, as the value for the
3734 @option{--files-from} option, a file with no names in it, as shown in
3735 the following commands:
3736
3737 @smallexample
3738 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3739 @kbd{tar cfT empty-archive.tar /dev/null}
3740 @end smallexample
3741
3742 @opindex extract, complementary notes
3743 @item --extract
3744 @itemx --get
3745 @itemx -x
3746
3747 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3748
3749 @item @option{--list} (@option{-t})
3750
3751 @GNUTAR{} now shows dates as @samp{1996-08-30},
3752 while it used to show them as @samp{Aug 30 1996}. Preferably,
3753 people should get used to ISO 8601 dates. Local American dates should
3754 be made available again with full date localization support, once
3755 ready. In the meantime, programs not being localizable for dates
3756 should prefer international dates, that's really the way to go.
3757
3758 Look up @url{http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html} if you
3759 are curious, it contains a detailed explanation of the ISO 8601 standard.
3760
3761 @end table
3762
3763 @node Advanced tar
3764 @section Advanced @GNUTAR{} Operations
3765
3766 Now that you have learned the basics of using @GNUTAR{}, you may want
3767 to learn about further ways in which @command{tar} can help you.
3768
3769 This chapter presents five, more advanced operations which you probably
3770 won't use on a daily basis, but which serve more specialized functions.
3771 We also explain the different styles of options and why you might want
3772 to use one or another, or a combination of them in your @command{tar}
3773 commands. Additionally, this chapter includes options which allow you to
3774 define the output from @command{tar} more carefully, and provide help and
3775 error correction in special circumstances.
3776
3777 @FIXME{check this after the chapter is actually revised to make sure
3778 it still introduces the info in the chapter correctly : ).}
3779
3780 @menu
3781 * Operations::
3782 * append::
3783 * update::
3784 * concatenate::
3785 * delete::
3786 * compare::
3787 @end menu
3788
3789 @node Operations
3790 @subsection The Five Advanced @command{tar} Operations
3791 @UNREVISED
3792
3793 In the last chapter, you learned about the first three operations to
3794 @command{tar}. This chapter presents the remaining five operations to
3795 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3796 @option{--delete}, and @option{--compare}.
3797
3798 You are not likely to use these operations as frequently as those
3799 covered in the last chapter; however, since they perform specialized
3800 functions, they are quite useful when you do need to use them. We
3801 will give examples using the same directory and files that you created
3802 in the last chapter. As you may recall, the directory is called
3803 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3804 @samp{rock}, and the two archive files you created are
3805 @samp{collection.tar} and @samp{music.tar}.
3806
3807 We will also use the archive files @samp{afiles.tar} and
3808 @samp{bfiles.tar}. @samp{afiles.tar} contains the members @samp{apple},
3809 @samp{angst}, and @samp{aspic}. @samp{bfiles.tar} contains the members
3810 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3811
3812 Unless we state otherwise, all practicing you do and examples you follow
3813 in this chapter will take place in the @file{practice} directory that
3814 you created in the previous chapter; see @ref{prepare for examples}.
3815 (Below in this section, we will remind you of the state of the examples
3816 where the last chapter left them.)
3817
3818 The five operations that we will cover in this chapter are:
3819
3820 @table @option
3821 @item --append
3822 @itemx -r
3823 Add new entries to an archive that already exists.
3824 @item --update
3825 @itemx -r
3826 Add more recent copies of archive members to the end of an archive, if
3827 they exist.
3828 @item --concatenate
3829 @itemx --catenate
3830 @itemx -A
3831 Add one or more pre-existing archives to the end of another archive.
3832 @item --delete
3833 Delete items from an archive (does not work on tapes).
3834 @item --compare
3835 @itemx --diff
3836 @itemx -d
3837 Compare archive members to their counterparts in the file system.
3838 @end table
3839
3840 @node append
3841 @subsection How to Add Files to Existing Archives: @option{--append}
3842 @UNREVISED
3843
3844 @opindex append
3845 If you want to add files to an existing archive, you don't need to
3846 create a new archive; you can use @option{--append} (@option{-r}).
3847 The archive must already exist in order to use @option{--append}. (A
3848 related operation is the @option{--update} operation; you can use this
3849 to add newer versions of archive members to an existing archive. To learn how to
3850 do this with @option{--update}, @pxref{update}.)
3851
3852 If you use @option{--append} to add a file that has the same name as an
3853 archive member to an archive containing that archive member, then the
3854 old member is not deleted. What does happen, however, is somewhat
3855 complex. @command{tar} @emph{allows} you to have infinite number of files
3856 with the same name. Some operations treat these same-named members no
3857 differently than any other set of archive members: for example, if you
3858 view an archive with @option{--list} (@option{-t}), you will see all
3859 of those members listed, with their data modification times, owners, etc.
3860
3861 Other operations don't deal with these members as perfectly as you might
3862 prefer; if you were to use @option{--extract} to extract the archive,
3863 only the most recently added copy of a member with the same name as four
3864 other members would end up in the working directory. This is because
3865 @option{--extract} extracts an archive in the order the members appeared
3866 in the archive; the most recently archived members will be extracted
3867 last. Additionally, an extracted member will @emph{replace} a file of
3868 the same name which existed in the directory already, and @command{tar}
3869 will not prompt you about this@footnote{Unless you give it
3870 @option{--keep-old-files} option, or the disk copy is newer than the
3871 the one in the archive and you invoke @command{tar} with
3872 @option{--keep-newer-files} option}. Thus, only the most recently archived
3873 member will end up being extracted, as it will replace the one
3874 extracted before it, and so on.
3875
3876 There exists a special option that allows you to get around this
3877 behavior and extract (or list) only a particular copy of the file.
3878 This is @option{--occurrence} option. If you run @command{tar} with
3879 this option, it will extract only the first copy of the file. You
3880 may also give this option an argument specifying the number of
3881 copy to be extracted. Thus, for example if the archive
3882 @file{archive.tar} contained three copies of file @file{myfile}, then
3883 the command
3884
3885 @smallexample
3886 tar --extract --file archive.tar --occurrence=2 myfile
3887 @end smallexample
3888
3889 @noindent
3890 would extract only the second copy. @xref{Option
3891 Summary,---occurrence}, for the description of @option{--occurrence}
3892 option.
3893
3894 @FIXME{ hag -- you might want to incorporate some of the above into the
3895 MMwtSN node; not sure. i didn't know how to make it simpler...
3896
3897 There are a few ways to get around this. (maybe xref Multiple Members
3898 with the Same Name.}
3899
3900 @cindex Members, replacing with other members
3901 @cindex Replacing members with other members
3902 If you want to replace an archive member, use @option{--delete} to
3903 delete the member you want to remove from the archive, , and then use
3904 @option{--append} to add the member you want to be in the archive. Note
3905 that you can not change the order of the archive; the most recently
3906 added member will still appear last. In this sense, you cannot truly
3907 ``replace'' one member with another. (Replacing one member with another
3908 will not work on certain types of media, such as tapes; see @ref{delete}
3909 and @ref{Media}, for more information.)
3910
3911 @menu
3912 * appending files:: Appending Files to an Archive
3913 * multiple::
3914 @end menu
3915
3916 @node appending files
3917 @subsubsection Appending Files to an Archive
3918 @UNREVISED
3919 @cindex Adding files to an Archive
3920 @cindex Appending files to an Archive
3921 @cindex Archives, Appending files to
3922
3923 The simplest way to add a file to an already existing archive is the
3924 @option{--append} (@option{-r}) operation, which writes specified
3925 files into the archive whether or not they are already among the
3926 archived files.
3927
3928 When you use @option{--append}, you @emph{must} specify file name
3929 arguments, as there is no default. If you specify a file that already
3930 exists in the archive, another copy of the file will be added to the
3931 end of the archive. As with other operations, the member names of the
3932 newly added files will be exactly the same as their names given on the
3933 command line. The @option{--verbose} (@option{-v}) option will print
3934 out the names of the files as they are written into the archive.
3935
3936 @option{--append} cannot be performed on some tape drives, unfortunately,
3937 due to deficiencies in the formats those tape drives use. The archive
3938 must be a valid @command{tar} archive, or else the results of using this
3939 operation will be unpredictable. @xref{Media}.
3940
3941 To demonstrate using @option{--append} to add a file to an archive,
3942 create a file called @file{rock} in the @file{practice} directory.
3943 Make sure you are in the @file{practice} directory. Then, run the
3944 following @command{tar} command to add @file{rock} to
3945 @file{collection.tar}:
3946
3947 @smallexample
3948 $ @kbd{tar --append --file=collection.tar rock}
3949 @end smallexample
3950
3951 @noindent
3952 If you now use the @option{--list} (@option{-t}) operation, you will see that
3953 @file{rock} has been added to the archive:
3954
3955 @smallexample
3956 $ @kbd{tar --list --file=collection.tar}
3957 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3958 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3959 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3960 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3961 @end smallexample
3962
3963 @node multiple
3964 @subsubsection Multiple Files with the Same Name
3965
3966 You can use @option{--append} (@option{-r}) to add copies of files
3967 which have been updated since the archive was created. (However, we
3968 do not recommend doing this since there is another @command{tar}
3969 option called @option{--update}; @xref{update}, for more information.
3970 We describe this use of @option{--append} here for the sake of
3971 completeness.) When you extract the archive, the older version will
3972 be effectively lost. This works because files are extracted from an
3973 archive in the order in which they were archived. Thus, when the
3974 archive is extracted, a file archived later in time will replace a
3975 file of the same name which was archived earlier, even though the
3976 older version of the file will remain in the archive unless you delete
3977 all versions of the file.
3978
3979 Supposing you change the file @file{blues} and then append the changed
3980 version to @file{collection.tar}. As you saw above, the original
3981 @file{blues} is in the archive @file{collection.tar}. If you change the
3982 file and append the new version of the file to the archive, there will
3983 be two copies in the archive. When you extract the archive, the older
3984 version of the file will be extracted first, and then replaced by the
3985 newer version when it is extracted.
3986
3987 You can append the new, changed copy of the file @file{blues} to the
3988 archive in this way:
3989
3990 @smallexample
3991 $ @kbd{tar --append --verbose --file=collection.tar blues}
3992 blues
3993 @end smallexample
3994
3995 @noindent
3996 Because you specified the @option{--verbose} option, @command{tar} has
3997 printed the name of the file being appended as it was acted on. Now
3998 list the contents of the archive:
3999
4000 @smallexample
4001 $ @kbd{tar --list --verbose --file=collection.tar}
4002 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4003 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4004 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4005 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4006 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4007 @end smallexample
4008
4009 @noindent
4010 The newest version of @file{blues} is now at the end of the archive
4011 (note the different creation dates and file sizes). If you extract
4012 the archive, the older version of the file @file{blues} will be
4013 replaced by the newer version. You can confirm this by extracting
4014 the archive and running @samp{ls} on the directory.
4015
4016 If you wish to extract the first occurrence of the file @file{blues}
4017 from the archive, use @option{--occurrence} option, as shown in
4018 the following example:
4019
4020 @smallexample
4021 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4022 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4023 @end smallexample
4024
4025 @xref{Writing}, for more information on @option{--extract} and
4026 @xref{Option Summary, --occurrence}, for the description of
4027 @option{--occurrence} option.
4028
4029 @node update
4030 @subsection Updating an Archive
4031 @UNREVISED
4032 @cindex Updating an archive
4033
4034 @opindex update
4035 In the previous section, you learned how to use @option{--append} to
4036 add a file to an existing archive. A related operation is
4037 @option{--update} (@option{-u}). The @option{--update} operation
4038 updates a @command{tar} archive by comparing the date of the specified
4039 archive members against the date of the file with the same name. If
4040 the file has been modified more recently than the archive member, then
4041 the newer version of the file is added to the archive (as with
4042 @option{--append}).
4043
4044 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4045 The operation will fail.
4046
4047 @FIXME{other examples of media on which --update will fail? need to ask
4048 charles and/or mib/thomas/dave shevett..}
4049
4050 Both @option{--update} and @option{--append} work by adding to the end
4051 of the archive. When you extract a file from the archive, only the
4052 version stored last will wind up in the file system, unless you use
4053 the @option{--backup} option. @FIXME-ref{Multiple Members with the
4054 Same Name}
4055
4056 @menu
4057 * how to update::
4058 @end menu
4059
4060 @node how to update
4061 @subsubsection How to Update an Archive Using @option{--update}
4062
4063 You must use file name arguments with the @option{--update}
4064 (@option{-u}) operation. If you don't specify any files,
4065 @command{tar} won't act on any files and won't tell you that it didn't
4066 do anything (which may end up confusing you).
4067
4068 @c note: the above parenthetical added because in fact, this
4069 @c behavior just confused the author. :-)
4070
4071 To see the @option{--update} option at work, create a new file,
4072 @file{classical}, in your practice directory, and some extra text to the
4073 file @file{blues}, using any text editor. Then invoke @command{tar} with
4074 the @samp{update} operation and the @option{--verbose} (@option{-v})
4075 option specified, using the names of all the files in the practice
4076 directory as file name arguments:
4077
4078 @smallexample
4079 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4080 blues
4081 classical
4082 $
4083 @end smallexample
4084
4085 @noindent
4086 Because we have specified verbose mode, @command{tar} prints out the names
4087 of the files it is working on, which in this case are the names of the
4088 files that needed to be updated. If you run @samp{tar --list} and look
4089 at the archive, you will see @file{blues} and @file{classical} at its
4090 end. There will be a total of two versions of the member @samp{blues};
4091 the one at the end will be newer and larger, since you added text before
4092 updating it.
4093
4094 (The reason @command{tar} does not overwrite the older file when updating
4095 it is because writing to the middle of a section of tape is a difficult
4096 process. Tapes are not designed to go backward. @xref{Media}, for more
4097 information about tapes.
4098
4099 @option{--update} (@option{-u}) is not suitable for performing backups for two
4100 reasons: it does not change directory content entries, and it
4101 lengthens the archive every time it is used. The @GNUTAR{}
4102 options intended specifically for backups are more
4103 efficient. If you need to run backups, please consult @ref{Backups}.
4104
4105 @node concatenate
4106 @subsection Combining Archives with @option{--concatenate}
4107
4108 @cindex Adding archives to an archive
4109 @cindex Concatenating Archives
4110 @opindex concatenate
4111 @opindex catenate
4112 @c @cindex @option{-A} described
4113 Sometimes it may be convenient to add a second archive onto the end of
4114 an archive rather than adding individual files to the archive. To add
4115 one or more archives to the end of another archive, you should use the
4116 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4117
4118 To use @option{--concatenate}, give the first archive with
4119 @option{--file} option and name the rest of archives to be
4120 concatenated on the command line. The members, and their member
4121 names, will be copied verbatim from those archives to the first one.
4122 @FIXME-ref{This can cause multiple members to have the same name, for
4123 information on how this affects reading the archive, Multiple
4124 Members with the Same Name.}
4125 The new, concatenated archive will be called by the same name as the
4126 one given with the @option{--file} option. As usual, if you omit
4127 @option{--file}, @command{tar} will use the value of the environment
4128 variable @env{TAPE}, or, if this has not been set, the default archive name.
4129
4130 @FIXME{There is no way to specify a new name...}
4131
4132 To demonstrate how @option{--concatenate} works, create two small archives
4133 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4134 files from @file{practice}:
4135
4136 @smallexample
4137 $ @kbd{tar -cvf bluesrock.tar blues rock}
4138 blues
4139 rock
4140 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4141 folk
4142 jazz
4143 @end smallexample
4144
4145 @noindent
4146 If you like, You can run @samp{tar --list} to make sure the archives
4147 contain what they are supposed to:
4148
4149 @smallexample
4150 $ @kbd{tar -tvf bluesrock.tar}
4151 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4152 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4153 $ @kbd{tar -tvf jazzfolk.tar}
4154 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4155 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4156 @end smallexample
4157
4158 We can concatenate these two archives with @command{tar}:
4159
4160 @smallexample
4161 $ @kbd{cd ..}
4162 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4163 @end smallexample
4164
4165 If you now list the contents of the @file{bluesrock.tar}, you will see
4166 that now it also contains the archive members of @file{jazzfolk.tar}:
4167
4168 @smallexample
4169 $ @kbd{tar --list --file=bluesrock.tar}
4170 blues
4171 rock
4172 folk
4173 jazz
4174 @end smallexample
4175
4176 When you use @option{--concatenate}, the source and target archives must
4177 already exist and must have been created using compatible format
4178 parameters. Notice, that @command{tar} does not check whether the
4179 archives it concatenates have compatible formats, it does not
4180 even check if the files are really tar archives.
4181
4182 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4183 tape drives, due to deficiencies in the formats those tape drives use.
4184
4185 @cindex @code{concatenate} vs @command{cat}
4186 @cindex @command{cat} vs @code{concatenate}
4187 It may seem more intuitive to you to want or try to use @command{cat} to
4188 concatenate two archives instead of using the @option{--concatenate}
4189 operation; after all, @command{cat} is the utility for combining files.
4190
4191 However, @command{tar} archives incorporate an end-of-file marker which
4192 must be removed if the concatenated archives are to be read properly as
4193 one archive. @option{--concatenate} removes the end-of-archive marker
4194 from the target archive before each new archive is appended. If you use
4195 @command{cat} to combine the archives, the result will not be a valid
4196 @command{tar} format archive. If you need to retrieve files from an
4197 archive that was added to using the @command{cat} utility, use the
4198 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4199 information on dealing with archives improperly combined using the
4200 @command{cat} shell utility.
4201
4202 @node delete
4203 @subsection Removing Archive Members Using @option{--delete}
4204 @UNREVISED
4205 @cindex Deleting files from an archive
4206 @cindex Removing files from an archive
4207
4208 @opindex delete
4209 You can remove members from an archive by using the @option{--delete}
4210 option. Specify the name of the archive with @option{--file}
4211 (@option{-f}) and then specify the names of the members to be deleted;
4212 if you list no member names, nothing will be deleted. The
4213 @option{--verbose} option will cause @command{tar} to print the names
4214 of the members as they are deleted. As with @option{--extract}, you
4215 must give the exact member names when using @samp{tar --delete}.
4216 @option{--delete} will remove all versions of the named file from the
4217 archive. The @option{--delete} operation can run very slowly.
4218
4219 Unlike other operations, @option{--delete} has no short form.
4220
4221 @cindex Tapes, using @option{--delete} and
4222 @cindex Deleting from tape archives
4223 This operation will rewrite the archive. You can only use
4224 @option{--delete} on an archive if the archive device allows you to
4225 write to any point on the media, such as a disk; because of this, it
4226 does not work on magnetic tapes. Do not try to delete an archive member
4227 from a magnetic tape; the action will not succeed, and you will be
4228 likely to scramble the archive and damage your tape. There is no safe
4229 way (except by completely re-writing the archive) to delete files from
4230 most kinds of magnetic tape. @xref{Media}.
4231
4232 To delete all versions of the file @file{blues} from the archive
4233 @file{collection.tar} in the @file{practice} directory, make sure you
4234 are in that directory, and then,
4235
4236 @smallexample
4237 $ @kbd{tar --list --file=collection.tar}
4238 blues
4239 folk
4240 jazz
4241 rock
4242 $ @kbd{tar --delete --file=collection.tar blues}
4243 $ @kbd{tar --list --file=collection.tar}
4244 folk
4245 jazz
4246 rock
4247 $
4248 @end smallexample
4249
4250 @FIXME{Check if the above listing is actually produced after running
4251 all the examples on collection.tar.}
4252
4253 The @option{--delete} option has been reported to work properly when
4254 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4255
4256 @node compare
4257 @subsection Comparing Archive Members with the File System
4258 @cindex Verifying the currency of an archive
4259 @UNREVISED
4260
4261 @opindex compare
4262 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4263 specified archive members against files with the same names, and then
4264 reports differences in file size, mode, owner, modification date and
4265 contents. You should @emph{only} specify archive member names, not file
4266 names. If you do not name any members, then @command{tar} will compare the
4267 entire archive. If a file is represented in the archive but does not
4268 exist in the file system, @command{tar} reports a difference.
4269
4270 You have to specify the record size of the archive when modifying an
4271 archive with a non-default record size.
4272
4273 @command{tar} ignores files in the file system that do not have
4274 corresponding members in the archive.
4275
4276 The following example compares the archive members @file{rock},
4277 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4278 files of the same name in the file system. (Note that there is no file,
4279 @file{funk}; @command{tar} will report an error message.)
4280
4281 @smallexample
4282 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4283 rock
4284 blues
4285 tar: funk not found in archive
4286 @end smallexample
4287
4288 The spirit behind the @option{--compare} (@option{--diff},
4289 @option{-d}) option is to check whether the archive represents the
4290 current state of files on disk, more than validating the integrity of
4291 the archive media. For this later goal, @xref{verify}.
4292
4293 @node create options
4294 @section Options Used by @option{--create}
4295
4296 @opindex create, additional options
4297 The previous chapter described the basics of how to use
4298 @option{--create} (@option{-c}) to create an archive from a set of files.
4299 @xref{create}. This section described advanced options to be used with
4300 @option{--create}.
4301
4302 @menu
4303 * Ignore Failed Read::
4304 @end menu
4305
4306 @node Ignore Failed Read
4307 @subsection Ignore Fail Read
4308
4309 @table @option
4310 @item --ignore-failed-read
4311 Do not exit with nonzero on unreadable files or directories.
4312 @end table
4313
4314 @node extract options
4315 @section Options Used by @option{--extract}
4316 @UNREVISED
4317
4318 @opindex extract, additional options
4319 The previous chapter showed how to use @option{--extract} to extract
4320 an archive into the file system. Various options cause @command{tar} to
4321 extract more information than just file contents, such as the owner,
4322 the permissions, the modification date, and so forth. This section
4323 presents options to be used with @option{--extract} when certain special
4324 considerations arise. You may review the information presented in
4325 @ref{extract} for more basic information about the
4326 @option{--extract} operation.
4327
4328 @menu
4329 * Reading:: Options to Help Read Archives
4330 * Writing:: Changing How @command{tar} Writes Files
4331 * Scarce:: Coping with Scarce Resources
4332 @end menu
4333
4334 @node Reading
4335 @subsection Options to Help Read Archives
4336 @cindex Options when reading archives
4337 @UNREVISED
4338
4339 @cindex Reading incomplete records
4340 @cindex Records, incomplete
4341 @opindex read-full-records
4342 Normally, @command{tar} will request data in full record increments from
4343 an archive storage device. If the device cannot return a full record,
4344 @command{tar} will report an error. However, some devices do not always
4345 return full records, or do not require the last record of an archive to
4346 be padded out to the next record boundary. To keep reading until you
4347 obtain a full record, or to accept an incomplete record if it contains
4348 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4349 in conjunction with the @option{--extract} or @option{--list} operations.
4350 @xref{Blocking}.
4351
4352 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4353 @command{tar} reads an archive from standard input, or from a remote
4354 machine. This is because on BSD Unix systems, attempting to read a
4355 pipe returns however much happens to be in the pipe, even if it is
4356 less than was requested. If this option were not enabled, @command{tar}
4357 would fail as soon as it read an incomplete record from the pipe.
4358
4359 If you're not sure of the blocking factor of an archive, you can
4360 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4361 @option{--blocking-factor=@var{512-size}} (@option{-b
4362 @var{512-size}}), using a blocking factor larger than what the archive
4363 uses. This lets you avoid having to determine the blocking factor
4364 of an archive. @xref{Blocking Factor}.
4365
4366 @menu
4367 * read full records::
4368 * Ignore Zeros::
4369 @end menu
4370
4371 @node read full records
4372 @unnumberedsubsubsec Reading Full Records
4373
4374 @FIXME{need sentence or so of intro here}
4375
4376 @table @option
4377 @opindex read-full-records
4378 @item --read-full-records
4379 @item -B
4380 Use in conjunction with @option{--extract} (@option{--get},
4381 @option{-x}) to read an archive which contains incomplete records, or
4382 one which has a blocking factor less than the one specified.
4383 @end table
4384
4385 @node Ignore Zeros
4386 @unnumberedsubsubsec Ignoring Blocks of Zeros
4387
4388 @cindex End-of-archive blocks, ignoring
4389 @cindex Ignoring end-of-archive blocks
4390 @opindex ignore-zeros
4391 Normally, @command{tar} stops reading when it encounters a block of zeros
4392 between file entries (which usually indicates the end of the archive).
4393 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4394 completely read an archive which contains a block of zeros before the
4395 end (i.e., a damaged archive, or one that was created by concatenating
4396 several archives together).
4397
4398 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4399 versions of @command{tar} write garbage after the end-of-archive entry,
4400 since that part of the media is never supposed to be read. @GNUTAR{}
4401 does not write after the end of an archive, but seeks to
4402 maintain compatiblity among archiving utilities.
4403
4404 @table @option
4405 @item --ignore-zeros
4406 @itemx -i
4407 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4408 encountered while reading an archive. Use in conjunction with
4409 @option{--extract} or @option{--list}.
4410 @end table
4411
4412 @node Writing
4413 @subsection Changing How @command{tar} Writes Files
4414 @UNREVISED
4415
4416 @FIXME{Introductory paragraph}
4417
4418 @menu
4419 * Dealing with Old Files::
4420 * Overwrite Old Files::
4421 * Keep Old Files::
4422 * Keep Newer Files::
4423 * Unlink First::
4424 * Recursive Unlink::
4425 * Data Modification Times::
4426 * Setting Access Permissions::
4427 * Directory Modification Times and Permissions::
4428 * Writing to Standard Output::
4429 * Writing to an External Program::
4430 * remove files::
4431 @end menu
4432
4433 @node Dealing with Old Files
4434 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4435
4436 @opindex overwrite-dir, introduced
4437 When extracting files, if @command{tar} discovers that the extracted
4438 file already exists, it normally replaces the file by removing it before
4439 extracting it, to prevent confusion in the presence of hard or symbolic
4440 links. (If the existing file is a symbolic link, it is removed, not
4441 followed.) However, if a directory cannot be removed because it is
4442 nonempty, @command{tar} normally overwrites its metadata (ownership,
4443 permission, etc.). The @option{--overwrite-dir} option enables this
4444 default behavior. To be more cautious and preserve the metadata of
4445 such a directory, use the @option{--no-overwrite-dir} option.
4446
4447 @cindex Overwriting old files, prevention
4448 @opindex keep-old-files, introduced
4449 To be even more cautious and prevent existing files from being replaced, use
4450 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4451 to replace or update a file that already exists, i.e., a file with the
4452 same name as an archive member prevents extraction of that archive
4453 member. Instead, it reports an error.
4454
4455 @opindex overwrite, introduced
4456 To be more aggressive about altering existing files, use the
4457 @option{--overwrite} option. It causes @command{tar} to overwrite
4458 existing files and to follow existing symbolic links when extracting.
4459
4460 @cindex Protecting old files
4461 Some people argue that @GNUTAR{} should not hesitate
4462 to overwrite files with other files when extracting. When extracting
4463 a @command{tar} archive, they expect to see a faithful copy of the
4464 state of the file system when the archive was created. It is debatable
4465 that this would always be a proper behavior. For example, suppose one
4466 has an archive in which @file{usr/local} is a link to
4467 @file{usr/local2}. Since then, maybe the site removed the link and
4468 renamed the whole hierarchy from @file{/usr/local2} to
4469 @file{/usr/local}. Such things happen all the time. I guess it would
4470 not be welcome at all that @GNUTAR{} removes the
4471 whole hierarchy just to make room for the link to be reinstated
4472 (unless it @emph{also} simultaneously restores the full
4473 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4474 able to remove a whole hierarchy to reestablish a symbolic link, for
4475 example, but @emph{only if} @option{--recursive-unlink} is specified
4476 to allow this behavior. In any case, single files are silently
4477 removed.
4478
4479 @opindex unlink-first, introduced
4480 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4481 some cases by causing @command{tar} to remove files unconditionally
4482 before extracting them.
4483
4484 @node Overwrite Old Files
4485 @unnumberedsubsubsec Overwrite Old Files
4486
4487 @table @option
4488 @opindex overwrite
4489 @item --overwrite
4490 Overwrite existing files and directory metadata when extracting files
4491 from an archive.
4492
4493 This causes @command{tar} to write extracted files into the file system without
4494 regard to the files already on the system; i.e., files with the same
4495 names as archive members are overwritten when the archive is extracted.
4496 It also causes @command{tar} to extract the ownership, permissions,
4497 and time stamps onto any preexisting files or directories.
4498 If the name of a corresponding file name is a symbolic link, the file
4499 pointed to by the symbolic link will be overwritten instead of the
4500 symbolic link itself (if this is possible). Moreover, special devices,
4501 empty directories and even symbolic links are automatically removed if
4502 they are in the way of extraction.
4503
4504 Be careful when using the @option{--overwrite} option, particularly when
4505 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4506 can change the contents, ownership or permissions of any file on your
4507 system. Also, many systems do not take kindly to overwriting files that
4508 are currently being executed.
4509
4510 @opindex overwrite-dir
4511 @item --overwrite-dir
4512 Overwrite the metadata of directories when extracting files from an
4513 archive, but remove other files before extracting.
4514 @end table
4515
4516 @node Keep Old Files
4517 @unnumberedsubsubsec Keep Old Files
4518
4519 @table @option
4520 @opindex keep-old-files
4521 @item --keep-old-files
4522 @itemx -k
4523 Do not replace existing files from archive. The
4524 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4525 from replacing existing files with files with the same name from the
4526 archive. The @option{--keep-old-files} option is meaningless with
4527 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4528 files in the file system during extraction.
4529 @end table
4530
4531 @node Keep Newer Files
4532 @unnumberedsubsubsec Keep Newer Files
4533
4534 @table @option
4535 @opindex keep-newer-files
4536 @item --keep-newer-files
4537 Do not replace existing files that are newer than their archive
4538 copies. This option is meaningless with @option{--list} (@option{-t}).
4539 @end table
4540
4541 @node Unlink First
4542 @unnumberedsubsubsec Unlink First
4543
4544 @table @option
4545 @opindex unlink-first
4546 @item --unlink-first
4547 @itemx -U
4548 Remove files before extracting over them.
4549 This can make @command{tar} run a bit faster if you know in advance
4550 that the extracted files all need to be removed. Normally this option
4551 slows @command{tar} down slightly, so it is disabled by default.
4552 @end table
4553
4554 @node Recursive Unlink
4555 @unnumberedsubsubsec Recursive Unlink
4556
4557 @table @option
4558 @opindex recursive-unlink
4559 @item --recursive-unlink
4560 When this option is specified, try removing files and directory hierarchies
4561 before extracting over them. @emph{This is a dangerous option!}
4562 @end table
4563
4564 If you specify the @option{--recursive-unlink} option,
4565 @command{tar} removes @emph{anything} that keeps you from extracting a file
4566 as far as current permissions will allow it. This could include removal
4567 of the contents of a full directory hierarchy.
4568
4569 @node Data Modification Times
4570 @unnumberedsubsubsec Setting Data Modification Times
4571
4572 @cindex Data modification times of extracted files
4573 @cindex Modification times of extracted files
4574 Normally, @command{tar} sets the data modification times of extracted
4575 files to the corresponding times recorded for the files in the archive, but
4576 limits the permissions of extracted files by the current @code{umask}
4577 setting.
4578
4579 To set the data modification times of extracted files to the time when
4580 the files were extracted, use the @option{--touch} (@option{-m}) option in
4581 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4582
4583 @table @option
4584 @opindex touch
4585 @item --touch
4586 @itemx -m
4587 Sets the data modification time of extracted archive members to the time
4588 they were extracted, not the time recorded for them in the archive.
4589 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4590 @end table
4591
4592 @node Setting Access Permissions
4593 @unnumberedsubsubsec Setting Access Permissions
4594
4595 @cindex Permissions of extracted files
4596 @cindex Modes of extracted files
4597 To set the modes (access permissions) of extracted files to those
4598 recorded for those files in the archive, use @option{--same-permissions}
4599 in conjunction with the @option{--extract} (@option{--get},
4600 @option{-x}) operation.
4601
4602 @table @option
4603 @opindex preserve-permission
4604 @opindex same-permission
4605 @item --preserve-permission
4606 @itemx --same-permission
4607 @c @itemx --ignore-umask
4608 @itemx -p
4609 Set modes of extracted archive members to those recorded in the
4610 archive, instead of current umask settings. Use in conjunction with
4611 @option{--extract} (@option{--get}, @option{-x}).
4612 @end table
4613
4614 @node Directory Modification Times and Permissions
4615 @unnumberedsubsubsec Directory Modification Times and Permissions
4616
4617 After sucessfully extracting a file member, @GNUTAR{} normally
4618 restores its permissions and modification times, as described in the
4619 previous sections. This cannot be done for directories, because
4620 after extracting a directory @command{tar} will almost certainly
4621 extract files into that directory and this will cause the directory
4622 modification time to be updated. Moreover, restoring that directory
4623 permissions may not permit file creation within it. Thus, restoring
4624 directory permissions and modification times must be delayed at least
4625 until all files have been extracted into that directory. @GNUTAR{}
4626 restores directories using the following approach.
4627
4628 The extracted directories are created with the mode specified in the
4629 archive, as modified by the umask of the user, which gives sufficient
4630 permissions to allow file creation. The meta-information about the
4631 directory is recorded in the temporary list of directories. When
4632 preparing to extract next archive member, @GNUTAR{} checks if the
4633 directory prefix of this file contains the remembered directory. If
4634 it does not, the program assumes that all files have been extracted
4635 into that directory, restores its modification time and permissions
4636 and removes its entry from the internal list. This approach allows
4637 to correctly restore directory meta-information in the majority of
4638 cases, while keeping memory requirements sufficiently small. It is
4639 based on the fact, that most @command{tar} archives use the predefined
4640 order of members: first the directory, then all the files and
4641 subdirectories in that directory.
4642
4643 However, this is not always true. The most important exception are
4644 incremental archives (@pxref{Incremental Dumps}). The member order in
4645 an incremental archive is reversed: first all directory members are
4646 stored, followed by other (non-directory) members. So, when extracting
4647 from incremental archives, @GNUTAR{} alters the above procedure. It
4648 remebers all restored directories, and restores their meta-data
4649 only after the entire archive has been processed. Notice, that you do
4650 not need to specity any special options for that, as @GNUTAR{}
4651 automatically detects archives in incremental format.
4652
4653 There may be cases, when such processing is required for normal archives
4654 too. Consider the following example:
4655
4656 @smallexample
4657 @group
4658 $ @kbd{tar --no-recursion -cvf archive \
4659 foo foo/file1 bar bar/file foo/file2}
4660 foo/
4661 foo/file1
4662 bar/
4663 bar/file
4664 foo/file2
4665 @end group
4666 @end smallexample
4667
4668 During the normal operation, after encountering @file{bar}
4669 @GNUTAR{} will assume that all files from the directory @file{foo}
4670 were already extracted and will therefore restore its timestamp and
4671 permission bits. However, after extracting @file{foo/file2} the
4672 directory timestamp will be offset again.
4673
4674 To correctly restore directory meta-information in such cases, use
4675 @option{delay-directory-restore} command line option:
4676
4677 @table @option
4678 @opindex delay-directory-restore
4679 @item --delay-directory-restore
4680 Delays restoring of the modification times and permissions of extracted
4681 directories until the end of extraction. This way, correct
4682 meta-information is restored even if the archive has unusual member
4683 ordering.
4684
4685 @opindex no-delay-directory-restore
4686 @item --no-delay-directory-restore
4687 Cancel the effect of the previous @option{--delay-directory-restore}.
4688 Use this option if you have used @option{--delay-directory-restore} in
4689 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4690 temporarily disable it.
4691 @end table
4692
4693 @node Writing to Standard Output
4694 @unnumberedsubsubsec Writing to Standard Output
4695
4696 @cindex Writing extracted files to standard output
4697 @cindex Standard output, writing extracted files to
4698 To write the extracted files to the standard output, instead of
4699 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4700 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4701 extracting files to send them through a pipe, and do not need to
4702 preserve them in the file system. If you extract multiple members,
4703 they appear on standard output concatenated, in the order they are
4704 found in the archive.
4705
4706 @table @option
4707 @opindex to-stdout
4708 @item --to-stdout
4709 @itemx -O
4710 Writes files to the standard output. Use only in conjunction with
4711 @option{--extract} (@option{--get}, @option{-x}). When this option is
4712 used, instead of creating the files specified, @command{tar} writes
4713 the contents of the files extracted to its standard output. This may
4714 be useful if you are only extracting the files in order to send them
4715 through a pipe. This option is meaningless with @option{--list}
4716 (@option{-t}).
4717 @end table
4718
4719 This can be useful, for example, if you have a tar archive containing
4720 a big file and don't want to store the file on disk before processing
4721 it. You can use a command like this:
4722
4723 @smallexample
4724 tar -xOzf foo.tgz bigfile | process
4725 @end smallexample
4726
4727 or even like this if you want to process the concatenation of the files:
4728
4729 @smallexample
4730 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4731 @end smallexample
4732
4733 Hovewer, @option{--to-command} may be more convenient for use with
4734 multiple files. See the next section.
4735
4736 @node Writing to an External Program
4737 @unnumberedsubsubsec Writing to an External Program
4738
4739 You can instruct @command{tar} to send the contents of each extracted
4740 file to the standard input of an external program:
4741
4742 @table @option
4743 @opindex to-command
4744 @item --to-command=@var{command}
4745 Extract files and pipe their contents to the standard input of
4746 @var{command}. When this option is used, instead of creating the
4747 files specified, @command{tar} invokes @var{command} and pipes the
4748 contents of the files to its standard output. @var{Command} may
4749 contain command line arguments. The program is executed via
4750 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4751 extracted. Non-regular files (directories, etc.) are ignored when this
4752 option is used.
4753 @end table
4754
4755 The command can obtain the information about the file it processes
4756 from the following environment variables:
4757
4758 @table @var
4759 @vrindex TAR_FILETYPE, to-command environment
4760 @item TAR_FILETYPE
4761 Type of the file. It is a single letter with the following meaning:
4762
4763 @multitable @columnfractions 0.10 0.90
4764 @item f @tab Regular file
4765 @item d @tab Directory
4766 @item l @tab Symbolic link
4767 @item h @tab Hard link
4768 @item b @tab Block device
4769 @item c @tab Character device
4770 @end multitable
4771
4772 Currently only regular files are supported.
4773
4774 @vrindex TAR_MODE, to-command environment
4775 @item TAR_MODE
4776 File mode, an octal number.
4777
4778 @vrindex TAR_FILENAME, to-command environment
4779 @item TAR_FILENAME
4780 The name of the file.
4781
4782 @vrindex TAR_REALNAME, to-command environment
4783 @item TAR_REALNAME
4784 Name of the file as stored in the archive.
4785
4786 @vrindex TAR_UNAME, to-command environment
4787 @item TAR_UNAME
4788 Name of the file owner.
4789
4790 @vrindex TAR_GNAME, to-command environment
4791 @item TAR_GNAME
4792 Name of the file owner group.
4793
4794 @vrindex TAR_ATIME, to-command environment
4795 @item TAR_ATIME
4796 Time of last access. It is a decimal number, representing seconds
4797 since the epoch. If the archive provides times with nanosecond
4798 precision, the nanoseconds are appended to the timestamp after a
4799 decimal point.
4800
4801 @vrindex TAR_MTIME, to-command environment
4802 @item TAR_MTIME
4803 Time of last modification.
4804
4805 @vrindex TAR_CTIME, to-command environment
4806 @item TAR_CTIME
4807 Time of last status change.
4808
4809 @vrindex TAR_SIZE, to-command environment
4810 @item TAR_SIZE
4811 Size of the file.
4812
4813 @vrindex TAR_UID, to-command environment
4814 @item TAR_UID
4815 UID of the file owner.
4816
4817 @vrindex TAR_GID, to-command environment
4818 @item TAR_GID
4819 GID of the file owner.
4820 @end table
4821
4822 In addition to these variables, @env{TAR_VERSION} contains the
4823 @GNUTAR{} version number.
4824
4825 If @var{command} exits with a non-0 status, @command{tar} will print
4826 an error message similar to the following:
4827
4828 @smallexample
4829 tar: 2345: Child returned status 1
4830 @end smallexample
4831
4832 Here, @samp{2345} is the PID of the finished process.
4833
4834 If this behavior is not wanted, use @option{--ignore-command-error}:
4835
4836 @table @option
4837 @opindex ignore-command-error
4838 @item --ignore-command-error
4839 Ignore exit codes of subprocesses. Notice that if the program
4840 exits on signal or otherwise terminates abnormally, the error message
4841 will be printed even if this option is used.
4842
4843 @opindex no-ignore-command-error
4844 @item --no-ignore-command-error
4845 Cancel the effect of any previous @option{--ignore-command-error}
4846 option. This option is useful if you have set
4847 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4848 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4849 @end table
4850
4851 @node remove files
4852 @unnumberedsubsubsec Removing Files
4853
4854 @FIXME{The section is too terse. Something more to add? An example,
4855 maybe?}
4856
4857 @table @option
4858 @opindex remove-files
4859 @item --remove-files
4860 Remove files after adding them to the archive.
4861 @end table
4862
4863 @node Scarce
4864 @subsection Coping with Scarce Resources
4865 @UNREVISED
4866
4867 @cindex Small memory
4868 @cindex Running out of space
4869
4870 @menu
4871 * Starting File::
4872 * Same Order::
4873 @end menu
4874
4875 @node Starting File
4876 @unnumberedsubsubsec Starting File
4877
4878 @table @option
4879 @opindex starting-file
4880 @item --starting-file=@var{name}
4881 @itemx -K @var{name}
4882 Starts an operation in the middle of an archive. Use in conjunction
4883 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4884 @end table
4885
4886 @cindex Middle of the archive, starting in the
4887 If a previous attempt to extract files failed due to lack of disk
4888 space, you can use @option{--starting-file=@var{name}} (@option{-K
4889 @var{name}}) to start extracting only after member @var{name} of the
4890 archive. This assumes, of course, that there is now free space, or
4891 that you are now extracting into a different file system. (You could
4892 also choose to suspend @command{tar}, remove unnecessary files from
4893 the file system, and then restart the same @command{tar} operation.
4894 In this case, @option{--starting-file} is not necessary.
4895 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4896
4897 @node Same Order
4898 @unnumberedsubsubsec Same Order
4899
4900 @table @option
4901 @cindex Large lists of file names on small machines
4902 @opindex same-order
4903 @opindex preserve-order
4904 @item --same-order
4905 @itemx --preserve-order
4906 @itemx -s
4907 To process large lists of file names on machines with small amounts of
4908 memory. Use in conjunction with @option{--compare} (@option{--diff},
4909 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4910 (@option{--get}, @option{-x}).
4911 @end table
4912
4913 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4914 names to be listed or extracted is sorted in the same order as the
4915 files in the archive. This allows a large list of names to be used,
4916 even on a small machine that would not otherwise be able to hold all
4917 the names in memory at the same time. Such a sorted list can easily be
4918 created by running @samp{tar -t} on the archive and editing its output.
4919
4920 This option is probably never needed on modern computer systems.
4921
4922 @node backup
4923 @section Backup options
4924
4925 @cindex backup options
4926
4927 @GNUTAR{} offers options for making backups of files
4928 before writing new versions. These options control the details of
4929 these backups. They may apply to the archive itself before it is
4930 created or rewritten, as well as individual extracted members. Other
4931 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4932 and @command{mv}, for example) offer similar options.
4933
4934 Backup options may prove unexpectedly useful when extracting archives
4935 containing many members having identical name, or when extracting archives
4936 on systems having file name limitations, making different members appear
4937 has having similar names through the side-effect of name truncation.
4938 (This is true only if we have a good scheme for truncated backup names,
4939 which I'm not sure at all: I suspect work is needed in this area.)
4940 When any existing file is backed up before being overwritten by extraction,
4941 then clashing files are automatically be renamed to be unique, and the
4942 true name is kept for only the last file of a series of clashing files.
4943 By using verbose mode, users may track exactly what happens.
4944
4945 At the detail level, some decisions are still experimental, and may
4946 change in the future, we are waiting comments from our users. So, please
4947 do not learn to depend blindly on the details of the backup features.
4948 For example, currently, directories themselves are never renamed through
4949 using these options, so, extracting a file over a directory still has
4950 good chances to fail. Also, backup options apply to created archives,
4951 not only to extracted members. For created archives, backups will not
4952 be attempted when the archive is a block or character device, or when it
4953 refers to a remote file.
4954
4955 For the sake of simplicity and efficiency, backups are made by renaming old
4956 files prior to creation or extraction, and not by copying. The original
4957 name is restored if the file creation fails. If a failure occurs after a
4958 partial extraction of a file, both the backup and the partially extracted
4959 file are kept.
4960
4961 @table @samp
4962 @item --backup[=@var{method}]
4963 @opindex backup
4964 @vindex VERSION_CONTROL
4965 @cindex backups
4966 Back up files that are about to be overwritten or removed.
4967 Without this option, the original versions are destroyed.
4968
4969 Use @var{method} to determine the type of backups made.
4970 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
4971 environment variable. And if @env{VERSION_CONTROL} is not set,
4972 use the @samp{existing} method.
4973
4974 @vindex version-control @r{Emacs variable}
4975 This option corresponds to the Emacs variable @samp{version-control};
4976 the same values for @var{method} are accepted as in Emacs. This option
4977 also allows more descriptive names. The valid @var{method}s are:
4978
4979 @table @samp
4980 @item t
4981 @itemx numbered
4982 @cindex numbered @r{backup method}
4983 Always make numbered backups.
4984
4985 @item nil
4986 @itemx existing
4987 @cindex existing @r{backup method}
4988 Make numbered backups of files that already have them, simple backups
4989 of the others.
4990
4991 @item never
4992 @itemx simple
4993 @cindex simple @r{backup method}
4994 Always make simple backups.
4995
4996 @end table
4997
4998 @item --suffix=@var{suffix}
4999 @opindex suffix
5000 @cindex backup suffix
5001 @vindex SIMPLE_BACKUP_SUFFIX
5002 Append @var{suffix} to each backup file made with @option{--backup}. If this
5003 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5004 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5005 set, the default is @samp{~}, just as in Emacs.
5006
5007 @end table
5008
5009 Some people express the desire to @emph{always} use the @option{--backup}
5010 option, by defining some kind of alias or script. This is not as easy
5011 as one may think, due to the fact that old style options should appear first
5012 and consume arguments a bit unpredictably for an alias or script. But,
5013 if you are ready to give up using old style options, you may resort to
5014 using something like (a Bourne shell function here):
5015
5016 @smallexample
5017 tar () @{ /usr/local/bin/tar --backup $*; @}
5018 @end smallexample
5019
5020 @node Applications
5021 @section Notable @command{tar} Usages
5022 @UNREVISED
5023
5024 @FIXME{Using Unix file linking capability to recreate directory
5025 structures---linking files into one subdirectory and then
5026 @command{tar}ring that directory.}
5027
5028 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5029
5030 @findex uuencode
5031 You can easily use archive files to transport a group of files from
5032 one system to another: put all relevant files into an archive on one
5033 computer system, transfer the archive to another system, and extract
5034 the contents there. The basic transfer medium might be magnetic tape,
5035 Internet FTP, or even electronic mail (though you must encode the
5036 archive with @command{uuencode} in order to transport it properly by
5037 mail). Both machines do not have to use the same operating system, as
5038 long as they both support the @command{tar} program.
5039
5040 For example, here is how you might copy a directory's contents from
5041 one disk to another, while preserving the dates, modes, owners and
5042 link-structure of all the files therein. In this case, the transfer
5043 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5044
5045 @smallexample
5046 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5047 @end smallexample
5048
5049 @noindent
5050 You can avoid subshells by using @option{-C} option:
5051
5052 @smallexample
5053 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5054 @end smallexample
5055
5056 @noindent
5057 The command also works using short option forms:
5058
5059 @smallexample
5060 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5061 | (cd targetdir; tar --extract --file=-)}
5062 # Or:
5063 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5064 | tar --directory targetdir --extract --file=-}
5065 @end smallexample
5066
5067 @noindent
5068 This is one of the easiest methods to transfer a @command{tar} archive.
5069
5070 @node looking ahead
5071 @section Looking Ahead: The Rest of this Manual
5072
5073 You have now seen how to use all eight of the operations available to
5074 @command{tar}, and a number of the possible options. The next chapter
5075 explains how to choose and change file and archive names, how to use
5076 files to store names of other files which you can then call as
5077 arguments to @command{tar} (this can help you save time if you expect to
5078 archive the same list of files a number of times), and so forth.
5079 @FIXME{in case it's not obvious, i'm making this up in some sense
5080 based on my limited memory of what the next chapter *really* does. i
5081 just wanted to flesh out this final section a little bit so i'd
5082 remember to stick it in here. :-)}
5083
5084 If there are too many files to conveniently list on the command line,
5085 you can list the names in a file, and @command{tar} will read that file.
5086 @xref{files}.
5087
5088 There are various ways of causing @command{tar} to skip over some files,
5089 and not archive them. @xref{Choosing}.
5090
5091 @node Backups
5092 @chapter Performing Backups and Restoring Files
5093 @UNREVISED
5094
5095 @GNUTAR{} is distributed along with the scripts
5096 which the Free Software Foundation uses for performing backups. There
5097 is no corresponding scripts available yet for doing restoration of
5098 files. Even if there is a good chance those scripts may be satisfying
5099 to you, they are not the only scripts or methods available for doing
5100 backups and restore. You may well create your own, or use more
5101 sophisticated packages dedicated to that purpose.
5102
5103 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5104 Automatic Network Disk Archiver), a backup system developed by James
5105 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5106 This is free software, and it is available at these places:
5107
5108 @smallexample
5109 http://www.cs.umd.edu/projects/amanda/amanda.html
5110 ftp://ftp.cs.umd.edu/pub/amanda
5111 @end smallexample
5112
5113 @FIXME{
5114
5115 Here is a possible plan for a future documentation about the backuping
5116 scripts which are provided within the @GNUTAR{}
5117 distribution.
5118
5119 @itemize @bullet
5120 @item dumps
5121 @itemize @minus
5122 @item what are dumps
5123 @item different levels of dumps
5124 @itemize +
5125 @item full dump = dump everything
5126 @item level 1, level 2 dumps etc
5127 A level @var{n} dump dumps everything changed since the last level
5128 @var{n}-1 dump (?)
5129 @end itemize
5130 @item how to use scripts for dumps (ie, the concept)
5131 @itemize +
5132 @item scripts to run after editing backup specs (details)
5133 @end itemize
5134 @item Backup Specs, what is it.
5135 @itemize +
5136 @item how to customize
5137 @item actual text of script [/sp/dump/backup-specs]
5138 @end itemize
5139 @item Problems
5140 @itemize +
5141 @item rsh doesn't work
5142 @item rtape isn't installed
5143 @item (others?)
5144 @end itemize
5145 @item the @option{--incremental} option of tar
5146 @item tapes
5147 @itemize +
5148 @item write protection
5149 @item types of media, different sizes and types, useful for different things
5150 @item files and tape marks
5151 one tape mark between files, two at end.
5152 @item positioning the tape
5153 MT writes two at end of write,
5154 backspaces over one when writing again.
5155 @end itemize
5156 @end itemize
5157 @end itemize
5158 }
5159
5160 This chapter documents both the provided shell scripts and @command{tar}
5161 options which are more specific to usage as a backup tool.
5162
5163 To @dfn{back up} a file system means to create archives that contain
5164 all the files in that file system. Those archives can then be used to
5165 restore any or all of those files (for instance if a disk crashes or a
5166 file is accidentally deleted). File system @dfn{backups} are also
5167 called @dfn{dumps}.
5168
5169 @menu
5170 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5171 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5172 * Backup Levels:: Levels of Backups
5173 * Backup Parameters:: Setting Parameters for Backups and Restoration
5174 * Scripted Backups:: Using the Backup Scripts
5175 * Scripted Restoration:: Using the Restore Script
5176 @end menu
5177
5178 @node Full Dumps
5179 @section Using @command{tar} to Perform Full Dumps
5180 @UNREVISED
5181
5182 @cindex full dumps
5183 @cindex dumps, full
5184
5185 @cindex corrupted archives
5186 Full dumps should only be made when no other people or programs
5187 are modifying files in the file system. If files are modified while
5188 @command{tar} is making the backup, they may not be stored properly in
5189 the archive, in which case you won't be able to restore them if you
5190 have to. (Files not being modified are written with no trouble, and do
5191 not corrupt the entire archive.)
5192
5193 You will want to use the @option{--label=@var{archive-label}}
5194 (@option{-V @var{archive-label}}) option to give the archive a
5195 volume label, so you can tell what this archive is even if the label
5196 falls off the tape, or anything like that.
5197
5198 Unless the file system you are dumping is guaranteed to fit on
5199 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5200 Make sure you have enough tapes on hand to complete the backup.
5201
5202 If you want to dump each file system separately you will need to use
5203 the @option{--one-file-system} option to prevent
5204 @command{tar} from crossing file system boundaries when storing
5205 (sub)directories.
5206
5207 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5208 option is not needed, since this is a complete copy of everything in
5209 the file system, and a full restore from this backup would only be
5210 done onto a completely
5211 empty disk.
5212
5213 Unless you are in a hurry, and trust the @command{tar} program (and your
5214 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5215 option, to make sure your files really made it onto the dump properly.
5216 This will also detect cases where the file was modified while (or just
5217 after) it was being archived. Not all media (notably cartridge tapes)
5218 are capable of being verified, unfortunately.
5219
5220 @node Incremental Dumps
5221 @section Using @command{tar} to Perform Incremental Dumps
5222
5223 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5224 stores additional metadata so that exact state of the file system
5225 can be restored when extracting the archive.
5226
5227 @GNUTAR{} currently offers two options for handling incremental
5228 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5229 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5230
5231 @opindex listed-incremental
5232 The option @option{--listed-incremental} instructs tar to operate on
5233 an incremental archive with additional metadata stored in a standalone
5234 file, called a @dfn{snapshot file}. The purpose of this file is to help
5235 determine which files have been changed, added or deleted since the
5236 last backup, so that the next incremental backup will contain only
5237 modified files. The name of the snapshot file is given as an argument
5238 to the option:
5239
5240 @table @option
5241 @item --listed-incremental=@var{file}
5242 @itemx -g @var{file}
5243 Handle incremental backups with snapshot data in @var{file}.
5244 @end table
5245
5246 To create an incremental backup, you would use
5247 @option{--listed-incremental} together with @option{--create}
5248 (@pxref{create}). For example:
5249
5250 @smallexample
5251 $ @kbd{tar --create \
5252 --file=archive.1.tar \
5253 --listed-incremental=/var/log/usr.snar \
5254 /usr}
5255 @end smallexample
5256
5257 This will create in @file{archive.1.tar} an incremental backup of
5258 the @file{/usr} file system, storing additional metadata in the file
5259 @file{/var/log/usr.snar}. If this file does not exist, it will be
5260 created. The created archive will then be a @dfn{level 0 backup};
5261 please see the next section for more on backup levels.
5262
5263 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5264 determines which files are modified. In this case only these files will be
5265 stored in the archive. Suppose, for example, that after running the
5266 above command, you delete file @file{/usr/doc/old} and create
5267 directory @file{/usr/local/db} with the following contents:
5268
5269 @smallexample
5270 $ @kbd{ls /usr/local/db}
5271 /usr/local/db/data
5272 /usr/local/db/index
5273 @end smallexample
5274
5275 Some time later you create another incremental backup. You will
5276 then see:
5277
5278 @smallexample
5279 $ @kbd{tar --create \
5280 --file=archive.2.tar \
5281 --listed-incremental=/var/log/usr.snar \
5282 /usr}
5283 tar: usr/local/db: Directory is new
5284 usr/local/db/
5285 usr/local/db/data
5286 usr/local/db/index
5287 @end smallexample
5288
5289 @noindent
5290 The created archive @file{archive.2.tar} will contain only these
5291 three members. This archive is called a @dfn{level 1 backup}. Notice
5292 that @file{/var/log/usr.snar} will be updated with the new data, so if
5293 you plan to create more @samp{level 1} backups, it is necessary to
5294 create a working copy of the snapshot file before running
5295 @command{tar}. The above example will then be modified as follows:
5296
5297 @smallexample
5298 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5299 $ @kbd{tar --create \
5300 --file=archive.2.tar \
5301 --listed-incremental=/var/log/usr.snar-1 \
5302 /usr}
5303 @end smallexample
5304
5305 Incremental dumps depend crucially on time stamps, so the results are
5306 unreliable if you modify a file's time stamps during dumping (e.g.,
5307 with the @option{--atime-preserve=replace} option), or if you set the clock
5308 backwards.
5309
5310 Metadata stored in snapshot files include device numbers, which,
5311 obviously is supposed to be a non-volatile value. However, it turns
5312 out that NFS devices have undependable values when an automounter
5313 gets in the picture. This can lead to a great deal of spurious
5314 redumping in incremental dumps, so it is somewhat useless to compare
5315 two NFS devices numbers over time. The solution implemented currently
5316 is to considers all NFS devices as being equal when it comes to
5317 comparing directories; this is fairly gross, but there does not seem
5318 to be a better way to go.
5319
5320 Note that incremental archives use @command{tar} extensions and may
5321 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5322
5323 @opindex listed-incremental, using with @option{--extract}
5324 @opindex extract, using with @option{--listed-incremental}
5325 To extract from the incremental dumps, use
5326 @option{--listed-incremental} together with @option{--extract}
5327 option (@pxref{extracting files}). In this case, @command{tar} does
5328 not need to access snapshot file, since all the data necessary for
5329 extraction are stored in the archive itself. So, when extracting, you
5330 can give whatever argument to @option{--listed-incremental}, the usual
5331 practice is to use @option{--listed-incremental=/dev/null}.
5332 Alternatively, you can use @option{--incremental}, which needs no
5333 arguments. In general, @option{--incremental} (@option{-G}) can be
5334 used as a shortcut for @option{--listed-incremental} when listing or
5335 extracting incremental backups (for more information, regarding this
5336 option, @pxref{incremental-op}).
5337
5338 When extracting from the incremental backup @GNUTAR{} attempts to
5339 restore the exact state the file system had when the archive was
5340 created. In particular, it will @emph{delete} those files in the file
5341 system that did not exist in their directories when the archive was
5342 created. If you have created several levels of incremental files,
5343 then in order to restore the exact contents the file system had when
5344 the last level was created, you will need to restore from all backups
5345 in turn. Continuing our example, to restore the state of @file{/usr}
5346 file system, one would do@footnote{Notice, that since both archives
5347 were created withouth @option{-P} option (@pxref{absolute}), these
5348 commands should be run from the root file system.}:
5349
5350 @smallexample
5351 $ @kbd{tar --extract \
5352 --listed-incremental=/dev/null \
5353 --file archive.1.tar}
5354 $ @kbd{tar --extract \
5355 --listed-incremental=/dev/null \
5356 --file archive.2.tar}
5357 @end smallexample
5358
5359 To list the contents of an incremental archive, use @option{--list}
5360 (@pxref{list}), as usual. To obtain more information about the
5361 archive, use @option{--listed-incremental} or @option{--incremental}
5362 combined with two @option{--verbose} options@footnote{Two
5363 @option{--verbose} options were selected to avoid breaking usual
5364 verbose listing output (@option{--list --verbose}) when using in
5365 scripts.
5366
5367 @opindex incremental, using with @option{--list}
5368 @opindex listed-incremental, using with @option{--list}
5369 @opindex list, using with @option{--incremental}
5370 @opindex list, using with @option{--listed-incremental}
5371 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5372 contents of the DUMPDIR header (with terminating nulls) when
5373 @option{--incremental} or @option{--listed-incremental} option was
5374 given, no matter what the verbosity level. This behavior, and,
5375 especially, the binary output it produced were considered incovenient
5376 and were changed in version 1.16}:
5377
5378 @smallexample
5379 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5380 @end smallexample
5381
5382 This command will print, for each directory in the archive, the list
5383 of files in that directory at the time the archive was created. This
5384 information is put out in a format which is both human-readable and
5385 unambiguous for a program: each file name is printed as
5386
5387 @smallexample
5388 @var{x} @var{file}
5389 @end smallexample
5390
5391 @noindent
5392 where @var{x} is a letter describing the status of the file: @samp{Y}
5393 if the file is present in the archive, @samp{N} if the file is not
5394 included in the archive, or a @samp{D} if the file is a directory (and
5395 is included in the archive). @xref{Dumpdir}, for the detailed
5396 description of dumpdirs and status codes. Each such
5397 line is terminated by a newline character. The last line is followed
5398 by an additional newline to indicate the end of the data.
5399
5400 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5401 gives the same behavior as @option{--listed-incremental} when used
5402 with @option{--list} and @option{--extract} options. When used with
5403 @option{--create} option, it creates an incremental archive without
5404 creating snapshot file. Thus, it is impossible to create several
5405 levels of incremental backups with @option{--incremental} option.
5406
5407 @node Backup Levels
5408 @section Levels of Backups
5409
5410 An archive containing all the files in the file system is called a
5411 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5412 creating a full dump every day. This strategy, however, would waste a
5413 substantial amount of archive media and user time, as unchanged files
5414 are daily re-archived.
5415
5416 It is more efficient to do a full dump only occasionally. To back up
5417 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5418 one} dump archives all the files that have changed since the last full
5419 dump.
5420
5421 A typical dump strategy would be to perform a full dump once a week,
5422 and a level one dump once a day. This means some versions of files
5423 will in fact be archived more than once, but this dump strategy makes
5424 it possible to restore a file system to within one day of accuracy by
5425 only extracting two archives---the last weekly (full) dump and the
5426 last daily (level one) dump. The only information lost would be in
5427 files changed or created since the last daily backup. (Doing dumps
5428 more than once a day is usually not worth the trouble).
5429
5430 @GNUTAR{} comes with scripts you can use to do full
5431 and level-one (actually, even level-two and so on) dumps. Using
5432 scripts (shell programs) to perform backups and restoration is a
5433 convenient and reliable alternative to typing out file name lists
5434 and @command{tar} commands by hand.
5435
5436 Before you use these scripts, you need to edit the file
5437 @file{backup-specs}, which specifies parameters used by the backup
5438 scripts and by the restore script. This file is usually located
5439 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5440 detailed description. Once the backup parameters are set, you can
5441 perform backups or restoration by running the appropriate script.
5442
5443 The name of the backup script is @code{backup}. The name of the
5444 restore script is @code{restore}. The following sections describe
5445 their use in detail.
5446
5447 @emph{Please Note:} The backup and restoration scripts are
5448 designed to be used together. While it is possible to restore files by
5449 hand from an archive which was created using a backup script, and to create
5450 an archive by hand which could then be extracted using the restore script,
5451 it is easier to use the scripts. @xref{Incremental Dumps}, before
5452 making such an attempt.
5453
5454 @node Backup Parameters
5455 @section Setting Parameters for Backups and Restoration
5456
5457 The file @file{backup-specs} specifies backup parameters for the
5458 backup and restoration scripts provided with @command{tar}. You must
5459 edit @file{backup-specs} to fit your system configuration and schedule
5460 before using these scripts.
5461
5462 Syntactically, @file{backup-specs} is a shell script, containing
5463 mainly variable assignments. However, any valid shell construct
5464 is allowed in this file. Particularly, you may wish to define
5465 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5466 For more information about shell script syntax, please refer to
5467 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5468 g_02, the definition of the Shell Command Language}. See also
5469 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5470
5471 The shell variables controlling behavior of @code{backup} and
5472 @code{restore} are described in the following subsections.
5473
5474 @menu
5475 * General-Purpose Variables::
5476 * Magnetic Tape Control::
5477 * User Hooks::
5478 * backup-specs example:: An Example Text of @file{Backup-specs}
5479 @end menu
5480
5481 @node General-Purpose Variables
5482 @subsection General-Purpose Variables
5483
5484 @defvr {Backup variable} ADMINISTRATOR
5485 The user name of the backup administrator. @code{Backup} scripts
5486 sends a backup report to this address.
5487 @end defvr
5488
5489 @defvr {Backup variable} BACKUP_HOUR
5490 The hour at which the backups are done. This can be a number from 0
5491 to 23, or the time specification in form @var{hours}:@var{minutes},
5492 or the string @samp{now}.
5493
5494 This variable is used by @code{backup}. Its value may be overridden
5495 using @option{--time} option (@pxref{Scripted Backups}).
5496 @end defvr
5497
5498 @defvr {Backup variable} TAPE_FILE
5499
5500 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5501 is a remote archive (@pxref{remote-dev}), backup script will suppose
5502 that your @command{mt} is able to access remote devices. If @var{RSH}
5503 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5504 invocations of @command{mt}.
5505 @end defvr
5506
5507 @defvr {Backup variable} BLOCKING
5508
5509 The blocking factor @command{tar} will use when writing the dump archive.
5510 @xref{Blocking Factor}.
5511 @end defvr
5512
5513 @defvr {Backup variable} BACKUP_DIRS
5514
5515 A list of file systems to be dumped (for @code{backup}), or restored
5516 (for @code{restore}). You can include any directory
5517 name in the list --- subdirectories on that file system will be
5518 included, regardless of how they may look to other networked machines.
5519 Subdirectories on other file systems will be ignored.
5520
5521 The host name specifies which host to run @command{tar} on, and should
5522 normally be the host that actually contains the file system. However,
5523 the host machine must have @GNUTAR{} installed, and
5524 must be able to access the directory containing the backup scripts and
5525 their support files using the same file name that is used on the
5526 machine where the scripts are run (ie. what @command{pwd} will print
5527 when in that directory on that machine). If the host that contains
5528 the file system does not have this capability, you can specify another
5529 host as long as it can access the file system through NFS.
5530
5531 If the list of file systems is very long you may wish to put it
5532 in a separate file. This file is usually named
5533 @file{/etc/backup/dirs}, but this name may be overridden in
5534 @file{backup-specs} using @code{DIRLIST} variable.
5535 @end defvr
5536
5537 @defvr {Backup variable} DIRLIST
5538
5539 A path to the file containing the list of the file systems to backup
5540 or restore. By default it is @file{/etc/backup/dirs}.
5541 @end defvr
5542
5543 @defvr {Backup variable} BACKUP_FILES
5544
5545 A list of individual files to be dumped (for @code{backup}), or restored
5546 (for @code{restore}). These should be accessible from the machine on
5547 which the backup script is run.
5548
5549 If the list of file systems is very long you may wish to store it
5550 in a separate file. This file is usually named
5551 @file{/etc/backup/files}, but this name may be overridden in
5552 @file{backup-specs} using @code{FILELIST} variable.
5553 @end defvr
5554
5555 @defvr {Backup variable} FILELIST
5556
5557 A path to the file containing the list of the individual files to backup
5558 or restore. By default it is @file{/etc/backup/files}.
5559 @end defvr
5560
5561 @defvr {Backup variable} MT
5562
5563 Full file name of @command{mt} binary.
5564 @end defvr
5565
5566 @defvr {Backup variable} RSH
5567 @anchor{RSH}
5568 Full file name of @command{rsh} binary or its equivalent. You may wish to
5569 set it to @code{ssh}, to improve security. In this case you will have
5570 to use public key authentication.
5571 @end defvr
5572
5573 @defvr {Backup variable} RSH_COMMAND
5574
5575 Full file name of @command{rsh} binary on remote mashines. This will
5576 be passed via @option{--rsh-command} option to the remote invocation
5577 of @GNUTAR{}.
5578 @end defvr
5579
5580 @defvr {Backup variable} VOLNO_FILE
5581
5582 Name of temporary file to hold volume numbers. This needs to be accessible
5583 by all the machines which have file systems to be dumped.
5584 @end defvr
5585
5586 @defvr {Backup variable} XLIST
5587
5588 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5589 located on the remote machine and containing the list of files to
5590 be excluded from the backup. Exclude file lists are searched in
5591 /etc/tar-backup directory. A common use for exclude file lists
5592 is to exclude files containing security-sensitive information
5593 (e.g., @file{/etc/shadow} from backups).
5594
5595 This variable affects only @code{backup}.
5596 @end defvr
5597
5598 @defvr {Backup variable} SLEEP_TIME
5599
5600 Time to sleep between dumps of any two successive file systems
5601
5602 This variable affects only @code{backup}.
5603 @end defvr
5604
5605 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5606
5607 Script to be run when it's time to insert a new tape in for the next
5608 volume. Administrators may want to tailor this script for their site.
5609 If this variable isn't set, @GNUTAR{} will display its built-in
5610 prompt, and will expect confirmation from the console.
5611
5612 The built-in prompt for POSIX locale is:
5613
5614 @smallexample
5615 Prepare volume #@var{n} for `@var{archive}' and hit return:
5616 @end smallexample
5617
5618 @noindent
5619 where @var{n} is the ordinal number of the volume to be created and
5620 @var{archive} is archive file or device name.
5621
5622 If you run @GNUTAR{} under a different locale, the translation of
5623 the above prompt to the locale's language will be used.
5624
5625 @end defvr
5626
5627 @defvr {Backup variable} SLEEP_MESSAGE
5628
5629 Message to display on the terminal while waiting for dump time. Usually
5630 this will just be some literal text.
5631 @end defvr
5632
5633 @defvr {Backup variable} TAR
5634
5635 Full file name of the @GNUTAR{} executable. If this is not set, backup
5636 scripts will search @command{tar} in the current shell path.
5637 @end defvr
5638
5639 @node Magnetic Tape Control
5640 @subsection Magnetic Tape Control
5641
5642 Backup scripts access tape device using special @dfn{hook functions}.
5643 These functions take a single argument -- the name of the tape
5644 device. Their names are kept in the following variables:
5645
5646 @defvr {Backup variable} MT_BEGIN
5647 The name of @dfn{begin} function. This function is called before
5648 accessing the drive. By default it retensions the tape:
5649
5650 @smallexample
5651 MT_BEGIN=mt_begin
5652
5653 mt_begin() @{
5654 mt -f "$1" retension
5655 @}
5656 @end smallexample
5657 @end defvr
5658
5659 @defvr {Backup variable} MT_REWIND
5660 The name of @dfn{rewind} function. The default definition is as
5661 follows:
5662
5663 @smallexample
5664 MT_REWIND=mt_rewind
5665
5666 mt_rewind() @{
5667 mt -f "$1" rewind
5668 @}
5669 @end smallexample
5670
5671 @end defvr
5672
5673 @defvr {Backup variable} MT_OFFLINE
5674 The name of the function switching the tape off line. By default
5675 it is defined as follows:
5676
5677 @smallexample
5678 MT_OFFLINE=mt_offline
5679
5680 mt_offline() @{
5681 mt -f "$1" offl
5682 @}
5683 @end smallexample
5684 @end defvr
5685
5686 @defvr {Backup variable} MT_STATUS
5687 The name of the function used to obtain the status of the archive device,
5688 including error count. Default definition:
5689
5690 @smallexample
5691 MT_STATUS=mt_status
5692
5693 mt_status() @{
5694 mt -f "$1" status
5695 @}
5696 @end smallexample
5697 @end defvr
5698
5699 @node User Hooks
5700 @subsection User Hooks
5701
5702 @dfn{User hooks} are shell functions executed before and after
5703 each @command{tar} invocation. Thus, there are @dfn{backup
5704 hooks}, which are executed before and after dumping each file
5705 system, and @dfn{restore hooks}, executed before and
5706 after restoring a file system. Each user hook is a shell function
5707 taking four arguments:
5708
5709 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5710 Its arguments are:
5711
5712 @table @var
5713 @item level
5714 Current backup or restore level.
5715
5716 @item host
5717 Name or IP address of the host machine being dumped or restored.
5718
5719 @item fs
5720 Full path name to the file system being dumped or restored.
5721
5722 @item fsname
5723 File system name with directory separators replaced with colons. This
5724 is useful, e.g., for creating unique files.
5725 @end table
5726 @end deffn
5727
5728 Following variables keep the names of user hook functions
5729
5730 @defvr {Backup variable} DUMP_BEGIN
5731 Dump begin function. It is executed before dumping the file system.
5732 @end defvr
5733
5734 @defvr {Backup variable} DUMP_END
5735 Executed after dumping the file system.
5736 @end defvr
5737
5738 @defvr {Backup variable} RESTORE_BEGIN
5739 Executed before restoring the file system.
5740 @end defvr
5741
5742 @defvr {Backup variable} RESTORE_END
5743 Executed after restoring the file system.
5744 @end defvr
5745
5746 @node backup-specs example
5747 @subsection An Example Text of @file{Backup-specs}
5748
5749 The following is an example of @file{backup-specs}:
5750
5751 @smallexample
5752 # site-specific parameters for file system backup.
5753
5754 ADMINISTRATOR=friedman
5755 BACKUP_HOUR=1
5756 TAPE_FILE=/dev/nrsmt0
5757
5758 # Use @code{ssh} instead of the less secure @code{rsh}
5759 RSH=/usr/bin/ssh
5760 RSH_COMMAND=/usr/bin/ssh
5761
5762 # Override MT_STATUS function:
5763 my_status() @{
5764 mts -t $TAPE_FILE
5765 @}
5766 MT_STATUS=my_status
5767
5768 # Disable MT_OFFLINE function
5769 MT_OFFLINE=:
5770
5771 BLOCKING=124
5772 BACKUP_DIRS="
5773 albert:/fs/fsf
5774 apple-gunkies:/gd
5775 albert:/fs/gd2
5776 albert:/fs/gp
5777 geech:/usr/jla
5778 churchy:/usr/roland
5779 albert:/
5780 albert:/usr
5781 apple-gunkies:/
5782 apple-gunkies:/usr
5783 gnu:/hack
5784 gnu:/u
5785 apple-gunkies:/com/mailer/gnu
5786 apple-gunkies:/com/archive/gnu"
5787
5788 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5789
5790 @end smallexample
5791
5792 @node Scripted Backups
5793 @section Using the Backup Scripts
5794
5795 The syntax for running a backup script is:
5796
5797 @smallexample
5798 backup --level=@var{level} --time=@var{time}
5799 @end smallexample
5800
5801 The @option{level} option requests the dump level. Thus, to produce
5802 a full dump, specify @code{--level=0} (this is the default, so
5803 @option{--level} may be omitted if its value is @code{0}).
5804 @footnote{For backward compatibility, the @code{backup} will also
5805 try to deduce the requested dump level from the name of the
5806 script itself. If the name consists of a string @samp{level-}
5807 followed by a single decimal digit, that digit is taken as
5808 the dump level number. Thus, you may create a link from @code{backup}
5809 to @code{level-1} and then run @code{level-1} whenever you need to
5810 create a level one dump.}
5811
5812 The @option{--time} option determines when should the backup be
5813 run. @var{Time} may take three forms:
5814
5815 @table @asis
5816 @item @var{hh}:@var{mm}
5817
5818 The dump must be run at @var{hh} hours @var{mm} minutes.
5819
5820 @item @var{hh}
5821
5822 The dump must be run at @var{hh} hours
5823
5824 @item now
5825
5826 The dump must be run immediately.
5827 @end table
5828
5829 You should start a script with a tape or disk mounted. Once you
5830 start a script, it prompts you for new tapes or disks as it
5831 needs them. Media volumes don't have to correspond to archive
5832 files --- a multi-volume archive can be started in the middle of a
5833 tape that already contains the end of another multi-volume archive.
5834 The @code{restore} script prompts for media by its archive volume,
5835 so to avoid an error message you should keep track of which tape
5836 (or disk) contains which volume of the archive (@pxref{Scripted
5837 Restoration}).
5838
5839 The backup scripts write two files on the file system. The first is a
5840 record file in @file{/etc/tar-backup/}, which is used by the scripts
5841 to store and retrieve information about which files were dumped. This
5842 file is not meant to be read by humans, and should not be deleted by
5843 them. @xref{Snapshot Files}, for a more detailed explanation of this
5844 file.
5845
5846 The second file is a log file containing the names of the file systems
5847 and files dumped, what time the backup was made, and any error
5848 messages that were generated, as well as how much space was left in
5849 the media volume after the last volume of the archive was written.
5850 You should check this log file after every backup. The file name is
5851 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5852 represents current date, and @var{n} represents current dump level number.
5853
5854 The script also prints the name of each system being dumped to the
5855 standard output.
5856
5857 Following is the full list of options accepted by @code{backup}
5858 script:
5859
5860 @table @option
5861 @item -l @var{level}
5862 @itemx --level=@var{level}
5863 Do backup level @var{level} (default 0).
5864
5865 @item -f
5866 @itemx --force
5867 Force backup even if today's log file already exists.
5868
5869 @item -v[@var{level}]
5870 @itemx --verbose[=@var{level}]
5871 Set verbosity level. The higher the level is, the more debugging
5872 information will be output during execution. Devault @var{level}
5873 is 100, which means the highest debugging level.
5874
5875 @item -t @var{start-time}
5876 @itemx --time=@var{start-time}
5877 Wait till @var{time}, then do backup.
5878
5879 @item -h
5880 @itemx --help
5881 Display short help message and exit.
5882
5883 @item -V
5884 @itemx --version
5885 Display information about the program's name, version, origin and legal
5886 status, all on standard output, and then exit successfully.
5887 @end table
5888
5889
5890 @node Scripted Restoration
5891 @section Using the Restore Script
5892
5893 To restore files that were archived using a scripted backup, use the
5894 @code{restore} script. Its usage is quite straightforward. In the
5895 simplest form, invoke @code{restore --all}, it will
5896 then restore all the file systems and files specified in
5897 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5898
5899 You may select the file systems (and/or files) to restore by
5900 giving @code{restore} list of @dfn{patterns} in its command
5901 line. For example, running
5902
5903 @smallexample
5904 restore 'albert:*'
5905 @end smallexample
5906
5907 @noindent
5908 will restore all file systems on the machine @samp{albert}. A more
5909 complicated example:
5910
5911 @smallexample
5912 restore 'albert:*' '*:/var'
5913 @end smallexample
5914
5915 @noindent
5916 This command will restore all file systems on the machine @samp{albert}
5917 as well as @file{/var} file system on all machines.
5918
5919 By default @code{restore} will start restoring files from the lowest
5920 available dump level (usually zero) and will continue through
5921 all available dump levels. There may be situations where such a
5922 thorough restore is not necessary. For example, you may wish to
5923 restore only files from the recent level one backup. To do so,
5924 use @option{--level} option, as shown in the example below:
5925
5926 @smallexample
5927 restore --level=1
5928 @end smallexample
5929
5930 The full list of options accepted by @code{restore} follows:
5931
5932 @table @option
5933 @item -a
5934 @itemx --all
5935 Restore all file systems and files specified in @file{backup-specs}
5936
5937 @item -l @var{level}
5938 @itemx --level=@var{level}
5939 Start restoring from the given backup level, instead of the default 0.
5940
5941 @item -v[@var{level}]
5942 @itemx --verbose[=@var{level}]
5943 Set verbosity level. The higher the level is, the more debugging
5944 information will be output during execution. Devault @var{level}
5945 is 100, which means the highest debugging level.
5946
5947 @item -h
5948 @itemx --help
5949 Display short help message and exit.
5950
5951 @item -V
5952 @itemx --version
5953 Display information about the program's name, version, origin and legal
5954 status, all on standard output, and then exit successfully.
5955 @end table
5956
5957 You should start the restore script with the media containing the
5958 first volume of the archive mounted. The script will prompt for other
5959 volumes as they are needed. If the archive is on tape, you don't need
5960 to rewind the tape to to its beginning---if the tape head is
5961 positioned past the beginning of the archive, the script will rewind
5962 the tape as needed. @FIXME-xref{Media, for a discussion of tape
5963 positioning.}
5964
5965 @quotation
5966 @strong{Warning:} The script will delete files from the active file
5967 system if they were not in the file system when the archive was made.
5968 @end quotation
5969
5970 @xref{Incremental Dumps}, for an explanation of how the script makes
5971 that determination.
5972
5973 @node Choosing
5974 @chapter Choosing Files and Names for @command{tar}
5975 @UNREVISED
5976
5977 Certain options to @command{tar} enable you to specify a name for your
5978 archive. Other options let you decide which files to include or exclude
5979 from the archive, based on when or whether files were modified, whether
5980 the file names do or don't match specified patterns, or whether files
5981 are in specified directories.
5982
5983 This chapter discusses these options in detail.
5984
5985 @menu
5986 * file:: Choosing the Archive's Name
5987 * Selecting Archive Members::
5988 * files:: Reading Names from a File
5989 * exclude:: Excluding Some Files
5990 * wildcards:: Wildcards Patterns and Matching
5991 * quoting styles:: Ways of Quoting Special Characters in Names
5992 * transform:: Modifying File and Member Names
5993 * after:: Operating Only on New Files
5994 * recurse:: Descending into Directories
5995 * one:: Crossing File System Boundaries
5996 @end menu
5997
5998 @node file
5999 @section Choosing and Naming Archive Files
6000 @UNREVISED
6001
6002 @cindex Naming an archive
6003 @cindex Archive Name
6004 @cindex Choosing an archive file
6005 @cindex Where is the archive?
6006 By default, @command{tar} uses an archive file name that was compiled when
6007 it was built on the system; usually this name refers to some physical
6008 tape drive on the machine. However, the person who installed @command{tar}
6009 on the system may not have set the default to a meaningful value as far as
6010 most users are concerned. As a result, you will usually want to tell
6011 @command{tar} where to find (or create) the archive. The
6012 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6013 option allows you to either specify or name a file to use as the archive
6014 instead of the default archive file location.
6015
6016 @table @option
6017 @opindex file, short description
6018 @item --file=@var{archive-name}
6019 @itemx -f @var{archive-name}
6020 Name the archive to create or operate on. Use in conjunction with
6021 any operation.
6022 @end table
6023
6024 For example, in this @command{tar} command,
6025
6026 @smallexample
6027 $ @kbd{tar -cvf collection.tar blues folk jazz}
6028 @end smallexample
6029
6030 @noindent
6031 @file{collection.tar} is the name of the archive. It must directly
6032 follow the @option{-f} option, since whatever directly follows @option{-f}
6033 @emph{will} end up naming the archive. If you neglect to specify an
6034 archive name, you may end up overwriting a file in the working directory
6035 with the archive you create since @command{tar} will use this file's name
6036 for the archive name.
6037
6038 An archive can be saved as a file in the file system, sent through a
6039 pipe or over a network, or written to an I/O device such as a tape,
6040 floppy disk, or CD write drive.
6041
6042 @cindex Writing new archives
6043 @cindex Archive creation
6044 If you do not name the archive, @command{tar} uses the value of the
6045 environment variable @env{TAPE} as the file name for the archive. If
6046 that is not available, @command{tar} uses a default, compiled-in archive
6047 name, usually that for tape unit zero (ie. @file{/dev/tu00}).
6048
6049 @cindex Standard input and output
6050 @cindex tar to standard input and output
6051 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6052 archive from standard input (when listing or extracting files), or
6053 writes it to standard output (when creating an archive). If you use
6054 @file{-} as an @var{archive-name} when modifying an archive,
6055 @command{tar} reads the original archive from its standard input and
6056 writes the entire new archive to its standard output.
6057
6058 The following example is a convenient way of copying directory
6059 hierarchy from @file{sourcedir} to @file{targetdir}.
6060
6061 @smallexample
6062 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6063 @end smallexample
6064
6065 The @option{-C} option allows to avoid using subshells:
6066
6067 @smallexample
6068 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6069 @end smallexample
6070
6071 In both examples above, the leftmost @command{tar} invocation archives
6072 the contents of @file{sourcedir} to the standard output, while the
6073 rightmost one reads this archive from its standard input and
6074 extracts it. The @option{-p} option tells it to restore permissions
6075 of the extracted files.
6076
6077 @cindex Remote devices
6078 @cindex tar to a remote device
6079 @anchor{remote-dev}
6080 To specify an archive file on a device attached to a remote machine,
6081 use the following:
6082
6083 @smallexample
6084 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6085 @end smallexample
6086
6087 @noindent
6088 @command{tar} will complete the remote connection, if possible, and
6089 prompt you for a username and password. If you use
6090 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6091 will complete the remote connection, if possible, using your username
6092 as the username on the remote machine.
6093
6094 @cindex Local and remote archives
6095 @anchor{local and remote archives}
6096 If the archive file name includes a colon (@samp{:}), then it is assumed
6097 to be a file on another machine. If the archive file is
6098 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6099 host @var{host}. The remote host is accessed using the @command{rsh}
6100 program, with a username of @var{user}. If the username is omitted
6101 (along with the @samp{@@} sign), then your user name will be used.
6102 (This is the normal @command{rsh} behavior.) It is necessary for the
6103 remote machine, in addition to permitting your @command{rsh} access, to
6104 have the @file{rmt} program installed (This command is included in
6105 the @GNUTAR{} distribution and by default is installed under
6106 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6107 installation prefix). If you need to use a file whose name includes a
6108 colon, then the remote tape drive behavior
6109 can be inhibited by using the @option{--force-local} option.
6110
6111 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6112 tries to minimize input and output operations. The Amanda backup
6113 system, when used with @GNUTAR{}, has an initial sizing pass which
6114 uses this feature.
6115
6116 @node Selecting Archive Members
6117 @section Selecting Archive Members
6118 @cindex Specifying files to act on
6119 @cindex Specifying archive members
6120
6121 @dfn{File Name arguments} specify which files in the file system
6122 @command{tar} operates on, when creating or adding to an archive, or which
6123 archive members @command{tar} operates on, when reading or deleting from
6124 an archive. @xref{Operations}.
6125
6126 To specify file names, you can include them as the last arguments on
6127 the command line, as follows:
6128 @smallexample
6129 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6130 @end smallexample
6131
6132 If a file name begins with dash (@samp{-}), precede it with
6133 @option{--add-file} option to prevent it from being treated as an
6134 option.
6135
6136 If you specify a directory name as a file name argument, all the files
6137 in that directory are operated on by @command{tar}.
6138
6139 If you do not specify files, @command{tar} behavior differs depending
6140 on the operation mode as described below:
6141
6142 When @command{tar} is invoked with @option{--create} (@option{-c}),
6143 @command{tar} will stop immediately, reporting the following:
6144
6145 @smallexample
6146 @group
6147 $ @kbd{tar cf a.tar}
6148 tar: Cowardly refusing to create an empty archive
6149 Try `tar --help' or `tar --usage' for more information.
6150 @end group
6151 @end smallexample
6152
6153 If you specify either @option{--list} (@option{-t}) or
6154 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6155 operates on all the archive members in the archive.
6156
6157 If run with @option{--diff} option, tar will compare the archive with
6158 the contents of the current working directory.
6159
6160 If you specify any other operation, @command{tar} does nothing.
6161
6162 By default, @command{tar} takes file names from the command line. However,
6163 there are other ways to specify file or member names, or to modify the
6164 manner in which @command{tar} selects the files or members upon which to
6165 operate. In general, these methods work both for specifying the names
6166 of files and archive members.
6167
6168 @node files
6169 @section Reading Names from a File
6170
6171 @cindex Reading file names from a file
6172 @cindex Lists of file names
6173 @cindex File Name arguments, alternatives
6174 Instead of giving the names of files or archive members on the command
6175 line, you can put the names into a file, and then use the
6176 @option{--files-from=@var{file-of-names}} (@option{-T
6177 @var{file-of-names}}) option to @command{tar}. Give the name of the
6178 file which contains the list of files to include as the argument to
6179 @option{--files-from}. In the list, the file names should be separated by
6180 newlines. You will frequently use this option when you have generated
6181 the list of files to archive with the @command{find} utility.
6182
6183 @table @option
6184 @opindex files-from
6185 @item --files-from=@var{file-name}
6186 @itemx -T @var{file-name}
6187 Get names to extract or create from file @var{file-name}.
6188 @end table
6189
6190 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6191 you specify either @code{--files-from=-} or @code{-T -}), then the file
6192 names are read from standard input.
6193
6194 Unless you are running @command{tar} with @option{--create}, you can not use
6195 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6196 command.
6197
6198 Any number of @option{-T} options can be given in the command line.
6199
6200 The following example shows how to use @command{find} to generate a list of
6201 files smaller than 400K in length and put that list into a file
6202 called @file{small-files}. You can then use the @option{-T} option to
6203 @command{tar} to specify the files from that file, @file{small-files}, to
6204 create the archive @file{little.tgz}. (The @option{-z} option to
6205 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6206 more information.)
6207
6208 @smallexample
6209 $ @kbd{find . -size -400 -print > small-files}
6210 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6211 @end smallexample
6212
6213 @noindent
6214 In the file list given by @option{-T} option, any file name beginning
6215 with @samp{-} character is considered a @command{tar} option and is
6216 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6217 recognized only @option{-C} option in file lists, and only if the
6218 option and its argument occupied two consecutive lines.} For example,
6219 the common use of this feature is to change to another directory by
6220 specifying @option{-C} option:
6221
6222 @smallexample
6223 @group
6224 $ @kbd{cat list}
6225 -C/etc
6226 passwd
6227 hosts
6228 -C/lib
6229 libc.a
6230 $ @kbd{tar -c -f foo.tar --files-from list}
6231 @end group
6232 @end smallexample
6233
6234 @noindent
6235 In this example, @command{tar} will first switch to @file{/etc}
6236 directory and add files @file{passwd} and @file{hosts} to the
6237 archive. Then it will change to @file{/lib} directory and will archive
6238 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6239 contain:
6240
6241 @smallexample
6242 @group
6243 $ @kbd{tar tf foo.tar}
6244 passwd
6245 hosts
6246 libc.a
6247 @end group
6248 @end smallexample
6249
6250 @noindent
6251 @opindex directory, using in @option{--files-from} argument
6252 Notice that the option parsing algorithm used with @option{-T} is
6253 stricter than the one used by shell. Namely, when specifying option
6254 arguments, you should observe the following rules:
6255
6256 @itemize @bullet
6257 @item
6258 When using short (single-letter) option form, its argument must
6259 immediately follow the option letter, without any intervening
6260 whitespace. For example: @code{-Cdir}.
6261
6262 @item
6263 When using long option form, the option argument must be separated
6264 from the option by a single equal sign. No whitespace is allowed on
6265 any side of the equal sign. For example: @code{--directory=dir}.
6266
6267 @item
6268 For both short and long option forms, the option argument can be given
6269 on the next line after the option name, e.g.:
6270
6271 @smallexample
6272 @group
6273 --directory
6274 dir
6275 @end group
6276 @end smallexample
6277
6278 @noindent
6279 and
6280
6281 @smallexample
6282 @group
6283 -C
6284 dir
6285 @end group
6286 @end smallexample
6287 @end itemize
6288
6289 @opindex add-file
6290 If you happen to have a file whose name starts with @samp{-},
6291 precede it with @option{--add-file} option to prevent it from
6292 being recognized as an option. For example: @code{--add-file=--my-file}.
6293
6294 @menu
6295 * nul::
6296 @end menu
6297
6298 @node nul
6299 @subsection @code{NUL} Terminated File Names
6300
6301 @cindex File names, terminated by @code{NUL}
6302 @cindex @code{NUL} terminated file names
6303 The @option{--null} option causes
6304 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6305 to read file names terminated by a @code{NUL} instead of a newline, so
6306 files whose names contain newlines can be archived using
6307 @option{--files-from}.
6308
6309 @table @option
6310 @opindex null
6311 @item --null
6312 Only consider @code{NUL} terminated file names, instead of files that
6313 terminate in a newline.
6314 @end table
6315
6316 The @option{--null} option is just like the one in @acronym{GNU}
6317 @command{xargs} and @command{cpio}, and is useful with the
6318 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6319 @command{tar}, @option{--null} also disables special handling for
6320 file names that begin with dash.
6321
6322 This example shows how to use @command{find} to generate a list of files
6323 larger than 800K in length and put that list into a file called
6324 @file{long-files}. The @option{-print0} option to @command{find} is just
6325 like @option{-print}, except that it separates files with a @code{NUL}
6326 rather than with a newline. You can then run @command{tar} with both the
6327 @option{--null} and @option{-T} options to specify that @command{tar} get the
6328 files from that file, @file{long-files}, to create the archive
6329 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6330 @command{tar} to recognize the @code{NUL} separator between files.
6331
6332 @smallexample
6333 $ @kbd{find . -size +800 -print0 > long-files}
6334 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6335 @end smallexample
6336
6337 @FIXME{say anything else here to conclude the section?}
6338
6339 @node exclude
6340 @section Excluding Some Files
6341 @UNREVISED
6342
6343 @cindex File names, excluding files by
6344 @cindex Excluding files by name and pattern
6345 @cindex Excluding files by file system
6346 To avoid operating on files whose names match a particular pattern,
6347 use the @option{--exclude} or @option{--exclude-from} options.
6348
6349 @table @option
6350 @opindex exclude
6351 @item --exclude=@var{pattern}
6352 Causes @command{tar} to ignore files that match the @var{pattern}.
6353 @end table
6354
6355 @findex exclude
6356 The @option{--exclude=@var{pattern}} option prevents any file or
6357 member whose name matches the shell wildcard (@var{pattern}) from
6358 being operated on.
6359 For example, to create an archive with all the contents of the directory
6360 @file{src} except for files whose names end in @file{.o}, use the
6361 command @samp{tar -cf src.tar --exclude='*.o' src}.
6362
6363 You may give multiple @option{--exclude} options.
6364
6365 @table @option
6366 @opindex exclude-from
6367 @item --exclude-from=@var{file}
6368 @itemx -X @var{file}
6369 Causes @command{tar} to ignore files that match the patterns listed in
6370 @var{file}.
6371 @end table
6372
6373 @findex exclude-from
6374 Use the @option{--exclude-from} option to read a
6375 list of patterns, one per line, from @var{file}; @command{tar} will
6376 ignore files matching those patterns. Thus if @command{tar} is
6377 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6378 single line @file{*.o}, no files whose names end in @file{.o} will be
6379 added to the archive.
6380
6381 @table @option
6382 @opindex exclude-caches
6383 @item --exclude-caches
6384 Causes @command{tar} to ignore directories containing a cache directory tag.
6385 @end table
6386
6387 @findex exclude-caches
6388 When creating an archive, the @option{--exclude-caches} option causes
6389 @command{tar} to exclude all directories that contain a @dfn{cache
6390 directory tag}. A cache directory tag is a short file with the
6391 well-known name @file{CACHEDIR.TAG} and having a standard header
6392 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6393 Various applications write cache directory tags into directories they
6394 use to hold regenerable, non-precious data, so that such data can be
6395 more easily excluded from backups.
6396
6397 @menu
6398 * problems with exclude::
6399 @end menu
6400
6401 @node problems with exclude
6402 @unnumberedsubsec Problems with Using the @code{exclude} Options
6403
6404 @opindex exclude, potential problems with
6405 Some users find @samp{exclude} options confusing. Here are some common
6406 pitfalls:
6407
6408 @itemize @bullet
6409 @item
6410 The main operating mode of @command{tar} does not act on a path name
6411 explicitly listed on the command line if one of its file name
6412 components is excluded. In the example above, if
6413 you create an archive and exclude files that end with @samp{*.o}, but
6414 explicitly name the file @samp{dir.o/foo} after all the options have been
6415 listed, @samp{dir.o/foo} will be excluded from the archive.
6416
6417 @item
6418 You can sometimes confuse the meanings of @option{--exclude} and
6419 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6420 to be excluded are given as a pattern on the command line. Use
6421 @option{--exclude-from} to introduce the name of a file which contains
6422 a list of patterns, one per line; each of these patterns can exclude
6423 zero, one, or many files.
6424
6425 @item
6426 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6427 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6428 like @samp{*}. If you do not do this, the shell might expand the
6429 @samp{*} itself using files at hand, so @command{tar} might receive a
6430 list of files instead of one pattern, or none at all, making the
6431 command somewhat illegal. This might not correspond to what you want.
6432
6433 For example, write:
6434
6435 @smallexample
6436 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6437 @end smallexample
6438
6439 @noindent
6440 rather than:
6441
6442 @smallexample
6443 # @emph{Wrong!}
6444 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6445 @end smallexample
6446
6447 @item
6448 You must use use shell syntax, or globbing, rather than @code{regexp}
6449 syntax, when using exclude options in @command{tar}. If you try to use
6450 @code{regexp} syntax to describe files to be excluded, your command
6451 might fail.
6452
6453 @item
6454 @FIXME{The change in semantics must have occurred before 1.11,
6455 so I doubt if it is worth mentioning at all. Anyway, should at
6456 least specify in which version the semantics changed.}
6457 In earlier versions of @command{tar}, what is now the
6458 @option{--exclude-from} option was called @option{--exclude} instead.
6459 Now, @option{--exclude} applies to patterns listed on the command
6460 line and @option{--exclude-from} applies to patterns listed in a
6461 file.
6462
6463 @end itemize
6464
6465 @node wildcards
6466 @section Wildcards Patterns and Matching
6467
6468 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6469 @samp{*} or @samp{?} for example, are replaced and expanded into all
6470 existing files matching the given pattern. @GNUTAR{} can use wildcard
6471 patterns for matching (or globbing) archive members when extracting
6472 from or listing an archive. Wildcard patterns are also used for
6473 verifying volume labels of @command{tar} archives. This section has the
6474 purpose of explaining wildcard syntax for @command{tar}.
6475
6476 @FIXME{the next few paragraphs need work.}
6477
6478 A @var{pattern} should be written according to shell syntax, using wildcard
6479 characters to effect globbing. Most characters in the pattern stand
6480 for themselves in the matched string, and case is significant: @samp{a}
6481 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6482 pattern matches any single character in the matched string. The character
6483 @samp{*} in the pattern matches zero, one, or more single characters in
6484 the matched string. The character @samp{\} says to take the following
6485 character of the pattern @emph{literally}; it is useful when one needs to
6486 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6487
6488 The character @samp{[}, up to the matching @samp{]}, introduces a character
6489 class. A @dfn{character class} is a list of acceptable characters
6490 for the next single character of the matched string. For example,
6491 @samp{[abcde]} would match any of the first five letters of the alphabet.
6492 Note that within a character class, all of the ``special characters''
6493 listed above other than @samp{\} lose their special meaning; for example,
6494 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6495 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6496 the characters @samp{-} and @samp{]} must either come @emph{first} or
6497 @emph{last} in a character class.)
6498
6499 @cindex Excluding characters from a character class
6500 @cindex Character class, excluding characters from
6501 If the first character of the class after the opening @samp{[}
6502 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6503 Rather than listing character to match, it lists those characters which
6504 are @emph{forbidden} as the next single character of the matched string.
6505
6506 Other characters of the class stand for themselves. The special
6507 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6508 letters, is meant to represent all characters between @var{a} and
6509 @var{e}, inclusive.
6510
6511 @FIXME{need to add a sentence or so here to make this clear for those
6512 who don't have dan around.}
6513
6514 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6515 special for wildcard matches. However, if a pattern completely matches
6516 a directory prefix of a matched string, then it matches the full matched
6517 string: thus, excluding a directory also excludes all the files beneath it.
6518
6519 @menu
6520 * controlling pattern-matching::
6521 @end menu
6522
6523 @node controlling pattern-matching
6524 @unnumberedsubsec Controlling Pattern-Matching
6525
6526 For the purposes of this section, we call @dfn{exclusion members} all
6527 member names obtained while processing @option{--exclude} and
6528 @option{--exclude-from} options, and @dfn{inclusion members} those
6529 member names that were given in the command line or read from the file
6530 specified with @option{--files-from} option.
6531
6532 These two pairs of member lists are used in the following operations:
6533 @option{--diff}, @option{--extract}, @option{--list},
6534 @option{--update}.
6535
6536 There are no inclusion members in create mode (@option{--create} and
6537 @option{--append}), since in this mode the names obtained from the
6538 command line refer to @emph{files}, not archive members.
6539
6540 By default, inclusion members are compared with archive members
6541 literally @footnote{Notice that earlier @GNUTAR{} versions used
6542 globbing for inclusion members, which contradicted to UNIX98
6543 specification and was not documented. @xref{Changes}, for more
6544 information on this and other changes.} and exclusion members are
6545 treated as globbing patterns. For example:
6546
6547 @smallexample
6548 @group
6549 $ @kbd{tar tf foo.tar}
6550 a.c
6551 b.c
6552 a.txt
6553 [remarks]
6554 # @i{Member names are used verbatim:}
6555 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6556 [remarks]
6557 # @i{Exclude member names are globbed:}
6558 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6559 a.txt
6560 [remarks]
6561 @end group
6562 @end smallexample
6563
6564 This behavior can be altered by using the following options:
6565
6566 @table @option
6567 @opindex wildcards
6568 @item --wildcards
6569 Treat all member names as wildcards.
6570
6571 @opindex no-wildcards
6572 @item --no-wildcards
6573 Treat all member names as literal strings.
6574 @end table
6575
6576 Thus, to extract files whose names end in @samp{.c}, you can use:
6577
6578 @smallexample
6579 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6580 a.c
6581 b.c
6582 @end smallexample
6583
6584 @noindent
6585 Notice quoting of the pattern to prevent the shell from interpreting
6586 it.
6587
6588 The effect of @option{--wildcards} option is cancelled by
6589 @option{--no-wildcards}. This can be used to pass part of
6590 the command line arguments verbatim and other part as globbing
6591 patterns. For example, the following invocation:
6592
6593 @smallexample
6594 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6595 @end smallexample
6596
6597 @noindent
6598 instructs @command{tar} to extract from @file{foo.tar} all files whose
6599 names end in @samp{.txt} and the file named @file{[remarks]}.
6600
6601 Normally, a pattern matches a name if an initial subsequence of the
6602 name's components matches the pattern, where @samp{*}, @samp{?}, and
6603 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6604 and wildcards can match @samp{/}.
6605
6606 Other than optionally stripping leading @samp{/} from names
6607 (@pxref{absolute}), patterns and names are used as-is. For
6608 example, trailing @samp{/} is not trimmed from a user-specified name
6609 before deciding whether to exclude it.
6610
6611 However, this matching procedure can be altered by the options listed
6612 below. These options accumulate. For example:
6613
6614 @smallexample
6615 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6616 @end smallexample
6617
6618 @noindent
6619 ignores case when excluding @samp{makefile}, but not when excluding
6620 @samp{readme}.
6621
6622 @table @option
6623 @opindex anchored
6624 @opindex no-anchored
6625 @item --anchored
6626 @itemx --no-anchored
6627 If anchored, a pattern must match an initial subsequence
6628 of the name's components. Otherwise, the pattern can match any
6629 subsequence. Default is @option{--no-anchored} for exclusion members
6630 and @option{--anchored} inclusion members.
6631
6632 @opindex ignore-case
6633 @opindex no-ignore-case
6634 @item --ignore-case
6635 @itemx --no-ignore-case
6636 When ignoring case, upper-case patterns match lower-case names and vice versa.
6637 When not ignoring case (the default), matching is case-sensitive.
6638
6639 @opindex wildcards-match-slash
6640 @opindex no-wildcards-match-slash
6641 @item --wildcards-match-slash
6642 @itemx --no-wildcards-match-slash
6643 When wildcards match slash (the default for exclusion members), a
6644 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6645 name. Otherwise, @samp{/} is matched only by @samp{/}.
6646
6647 @end table
6648
6649 The @option{--recursion} and @option{--no-recursion} options
6650 (@pxref{recurse}) also affect how member patterns are interpreted. If
6651 recursion is in effect, a pattern matches a name if it matches any of
6652 the name's parent directories.
6653
6654 The following table summarizes pattern-matching default values:
6655
6656 @multitable @columnfractions .3 .7
6657 @headitem Members @tab Default settings
6658 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6659 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6660 @end multitable
6661
6662 @node quoting styles
6663 @section Quoting Member Names
6664
6665 When displaying member names, @command{tar} takes care to avoid
6666 ambiguities caused by certain characters. This is called @dfn{name
6667 quoting}. The characters in question are:
6668
6669 @itemize @bullet
6670 @item Non-printable control characters:
6671
6672 @multitable @columnfractions 0.20 0.10 0.60
6673 @headitem Character @tab ASCII @tab Character name
6674 @item \a @tab 7 @tab Audible bell
6675 @item \b @tab 8 @tab Backspace
6676 @item \f @tab 12 @tab Form feed
6677 @item \n @tab 10 @tab New line
6678 @item \r @tab 13 @tab Carriage return
6679 @item \t @tab 9 @tab Horizontal tabulation
6680 @item \v @tab 11 @tab Vertical tabulation
6681 @end multitable
6682
6683 @item Space (ASCII 32)
6684
6685 @item Single and double quotes (@samp{'} and @samp{"})
6686
6687 @item Backslash (@samp{\})
6688 @end itemize
6689
6690 The exact way @command{tar} uses to quote these characters depends on
6691 the @dfn{quoting style}. The default quoting style, called
6692 @dfn{escape} (see below), uses backslash notation to represent control
6693 characters, space and backslash. Using this quoting style, control
6694 characters are represented as listed in column @samp{Character} in the
6695 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6696
6697 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6698 using @option{--quoting-style} option:
6699
6700 @table @option
6701 @item --quoting-style=@var{style}
6702 @opindex quoting-style
6703
6704 Sets quoting style. Valid values for @var{style} argument are:
6705 literal, shell, shell-always, c, escape, locale, clocale.
6706 @end table
6707
6708 These styles are described in detail below. To illustrate their
6709 effect, we will use an imaginary tar archive @file{arch.tar}
6710 containing the following members:
6711
6712 @smallexample
6713 @group
6714 # 1. Contains horizontal tabulation character.
6715 a tab
6716 # 2. Contains newline character
6717 a
6718 newline
6719 # 3. Contains a space
6720 a space
6721 # 4. Contains double quotes
6722 a"double"quote
6723 # 5. Contains single quotes
6724 a'single'quote
6725 # 6. Contains a backslash character:
6726 a\backslash
6727 @end group
6728 @end smallexample
6729
6730 Here is how usual @command{ls} command would have listed them, if they
6731 had existed in the current working directory:
6732
6733 @smallexample
6734 @group
6735 $ @kbd{ls}
6736 a\ttab
6737 a\nnewline
6738 a\ space
6739 a"double"quote
6740 a'single'quote
6741 a\\backslash
6742 @end group
6743 @end smallexample
6744
6745 Quoting styles:
6746
6747 @table @samp
6748 @item literal
6749 No quoting, display each character as is:
6750
6751 @smallexample
6752 @group
6753 $ @kbd{tar tf arch.tar --quoting-style=literal}
6754 ./
6755 ./a space
6756 ./a'single'quote
6757 ./a"double"quote
6758 ./a\backslash
6759 ./a tab
6760 ./a
6761 newline
6762 @end group
6763 @end smallexample
6764
6765 @item shell
6766 Display characters the same way Bourne shell does:
6767 control characters, except @samp{\t} and @samp{\n}, are printed using
6768 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6769 single quote is printed as @samp{\'}. If a name contains any quoted
6770 characters, it is enclosed in single quotes. In particular, if a name
6771 contains single quotes, it is printed as several single-quoted strings:
6772
6773 @smallexample
6774 @group
6775 $ @kbd{tar tf arch.tar --quoting-style=shell}
6776 ./
6777 './a space'
6778 './a'\''single'\''quote'
6779 './a"double"quote'
6780 './a\backslash'
6781 './a tab'
6782 './a
6783 newline'
6784 @end group
6785 @end smallexample
6786
6787 @item shell-always
6788 Same as @samp{shell}, but the names are always enclosed in single
6789 quotes:
6790
6791 @smallexample
6792 @group
6793 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6794 './'
6795 './a space'
6796 './a'\''single'\''quote'
6797 './a"double"quote'
6798 './a\backslash'
6799 './a tab'
6800 './a
6801 newline'
6802 @end group
6803 @end smallexample
6804
6805 @item c
6806 Use the notation of the C programming language. All names are
6807 enclosed in double quotes. Control characters are quoted using
6808 backslash notations, double quotes are represented as @samp{\"},
6809 backslash characters are represented as @samp{\\}. Single quotes and
6810 spaces are not quoted:
6811
6812 @smallexample
6813 @group
6814 $ @kbd{tar tf arch.tar --quoting-style=c}
6815 "./"
6816 "./a space"
6817 "./a'single'quote"
6818 "./a\"double\"quote"
6819 "./a\\backslash"
6820 "./a\ttab"
6821 "./a\nnewline"
6822 @end group
6823 @end smallexample
6824
6825 @item escape
6826 Control characters are printed using backslash notation, a space is
6827 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6828 default quoting style, unless it was changed when configured the
6829 package.
6830
6831 @smallexample
6832 @group
6833 $ @kbd{tar tf arch.tar --quoting-style=escape}
6834 ./
6835 ./a space
6836 ./a'single'quote
6837 ./a"double"quote
6838 ./a\\backslash
6839 ./a\ttab
6840 ./a\nnewline
6841 @end group
6842 @end smallexample
6843
6844 @item locale
6845 Control characters, single quote and backslash are printed using
6846 backslash notation. All names are quoted using left and right
6847 quotation marks, appropriate to the current locale. If it does not
6848 define quotation marks, use @samp{`} as left and @samp{'} as right
6849 quotation marks. Any occurrences of the right quotation mark in a
6850 name are escaped with @samp{\}, for example:
6851
6852 For example:
6853
6854 @smallexample
6855 @group
6856 $ @kbd{tar tf arch.tar --quoting-style=locale}
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 @item clocale
6868 Same as @samp{locale}, but @samp{"} is used for both left and right
6869 quotation marks, if not provided by the currently selected locale:
6870
6871 @smallexample
6872 @group
6873 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6874 "./"
6875 "./a space"
6876 "./a'single'quote"
6877 "./a\"double\"quote"
6878 "./a\\backslash"
6879 "./a\ttab"
6880 "./a\nnewline"
6881 @end group
6882 @end smallexample
6883 @end table
6884
6885 You can specify which characters should be quoted in addition to those
6886 implied by the current quoting style:
6887
6888 @table @option
6889 @item --quote-chars=@var{string}
6890 Always quote characters from @var{string}, even if the selected
6891 quoting style would not quote them.
6892 @end table
6893
6894 For example, using @samp{escape} quoting (compare with the usual
6895 escape listing above):
6896
6897 @smallexample
6898 @group
6899 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6900 ./
6901 ./a\ space
6902 ./a'single'quote
6903 ./a\"double\"quote
6904 ./a\\backslash
6905 ./a\ttab
6906 ./a\nnewline
6907 @end group
6908 @end smallexample
6909
6910 To disable quoting of such additional characters, use the following
6911 option:
6912
6913 @table @option
6914 @item --no-quote-chars=@var{string}
6915 Remove characters listed in @var{string} from the list of quoted
6916 characters set by the previous @option{--quote-chars} option.
6917 @end table
6918
6919 This option is particularly useful if you have added
6920 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6921 and wish to disable it for the current invocation.
6922
6923 Note, that @option{--no-quote-chars} does @emph{not} disable those
6924 characters that are quoted by default in the selected quoting style.
6925
6926 @node transform
6927 @section Modifying File and Member Names
6928
6929 @command{Tar} archives contain detailed information about files stored
6930 in them and full file names are part of that information. When
6931 storing file to an archive, its file name is recorded in the archive
6932 along with the actual file contents. When restoring from an archive,
6933 a file is created on disk with exactly the same name as that stored
6934 in the archive. In the majority of cases this is the desired behavior
6935 of a file archiver. However, there are some cases when it is not.
6936
6937 First of all, it is often unsafe to extract archive members with
6938 absolute file names or those that begin with a @file{../}. @GNUTAR{}
6939 takes special precautions when extracting such names and provides a
6940 special option for handling them, which is described in
6941 @ref{absolute}.
6942
6943 Secondly, you may wish to extract file names without some leading
6944 directory components, or with otherwise modified names. In other
6945 cases it is desirable to store files under differing names in the
6946 archive.
6947
6948 @GNUTAR{} provides two options for these needs.
6949
6950 @table @option
6951 @opindex strip-components
6952 @item --strip-components=@var{number}
6953 Strip given @var{number} of leading components from file names before
6954 extraction.
6955 @end table
6956
6957 For example, suppose you have archived whole @file{/usr} hierarchy to
6958 a tar archive named @file{usr.tar}. Among other files, this archive
6959 contains @file{usr/include/stdlib.h}, which you wish to extract to
6960 the current working directory. To do so, you type:
6961
6962 @smallexample
6963 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
6964 @end smallexample
6965
6966 The option @option{--strip=2} instructs @command{tar} to strip the
6967 two leading components (@file{usr/} and @file{include/}) off the file
6968 name.
6969
6970 If you add to the above invocation @option{--verbose} (@option{-v})
6971 option, you will note that the verbose listing still contains the
6972 full file name, with the two removed components still in place. This
6973 can be inconvenient, so @command{tar} provides a special option for
6974 altering this behavior:
6975
6976 @anchor{show-transformed-names}
6977 @table @option
6978 @opindex --show-transformed-names
6979 @item --show-transformed-names
6980 Display file or member names with all requested transformations
6981 applied.
6982 @end table
6983
6984 @noindent
6985 For example:
6986
6987 @smallexample
6988 @group
6989 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
6990 usr/include/stdlib.h
6991 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
6992 stdlib.h
6993 @end group
6994 @end smallexample
6995
6996 Notice that in both cases the file is @file{stdlib.h} extracted to the
6997 current working directory, @option{--show-transformed-names} affects
6998 only the way its name is displayed.
6999
7000 This option is especially useful for verifying whether the invocation
7001 will have the desired effect. Thus, before running
7002
7003 @smallexample
7004 $ @kbd{tar -x --strip=@var{n}}
7005 @end smallexample
7006
7007 @noindent
7008 it is often advisable to run
7009
7010 @smallexample
7011 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7012 @end smallexample
7013
7014 @noindent
7015 to make sure the command will produce the intended results.
7016
7017 In case you need to apply more complex modifications to the file name,
7018 @GNUTAR{} provides a general-purpose transformation option:
7019
7020 @table @option
7021 @opindex --transform
7022 @item --transform=@var{expression}
7023 Modify file names using supplied @var{expression}.
7024 @end table
7025
7026 @noindent
7027 The @var{expression} is a @command{sed}-like replace expression of the
7028 form:
7029
7030 @smallexample
7031 s/@var{regexp}/@var{replace}/[@var{flags}]
7032 @end smallexample
7033
7034 @noindent
7035 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7036 replacement for each file name part that matches @var{regexp}. Both
7037 @var{regexp} and @var{replace} are described in detail in
7038 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7039
7040 Supported @var{flags} are:
7041
7042 @table @samp
7043 @item g
7044 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7045 just the first.
7046
7047 @item i
7048 Use case-insensitive matching
7049
7050 @item x
7051 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7052 regexps, Extended regular expressions, Extended regular expressions,
7053 sed, GNU sed}).
7054
7055 @item @var{number}
7056 Only replace the @var{number}th match of the @var{regexp}.
7057
7058 Note: the @var{posix} standard does not specify what should happen
7059 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7060 follows the GNU @command{sed} implementation in this regard, so
7061 the the interaction is defined to be: ignore matches before the
7062 @var{number}th, and then match and replace all matches from the
7063 @var{number}th on.
7064
7065 @end table
7066
7067 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7068 that it be used consistently throughout the expression. For example,
7069 the following two expressions are equivalent:
7070
7071 @smallexample
7072 @group
7073 s/one/two/
7074 s,one,two,
7075 @end group
7076 @end smallexample
7077
7078 Changing delimiters is often useful when the @var{regex} contains
7079 slashes. For example, it is more convenient to write @code{s,/,-,} than
7080 @code{s/\//-/}.
7081
7082 Here are several examples of @option{--transform} usage:
7083
7084 @enumerate
7085 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7086
7087 @smallexample
7088 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7089 @end smallexample
7090
7091 @item Strip two leading directory components (equivalent to
7092 @option{--strip-components=2}):
7093
7094 @smallexample
7095 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7096 @end smallexample
7097
7098 @item Prepend @file{/prefix/} to each file name:
7099
7100 @smallexample
7101 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7102 @end smallexample
7103
7104 @item Convert each file name to lower case:
7105
7106 @smallexample
7107 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7108 @end smallexample
7109
7110 @end enumerate
7111
7112 Unlike @option{--strip-components}, @option{--transform} can be used
7113 in any @GNUTAR{} operation mode. For example, the following command
7114 adds files to the archive while replacing the leading @file{usr/}
7115 component with @file{var/}:
7116
7117 @smallexample
7118 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7119 @end smallexample
7120
7121 To test @option{--transform} effect we suggest using
7122 @option{--show-transformed-names} option:
7123
7124 @smallexample
7125 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7126 --verbose --show-transformed-names /}
7127 @end smallexample
7128
7129 If both @option{--strip-components} and @option{--transform} are used
7130 together, then @option{--transform} is applied first, and the required
7131 number of components is then stripped from its result.
7132
7133 @node after
7134 @section Operating Only on New Files
7135 @UNREVISED
7136
7137 @cindex Excluding file by age
7138 @cindex Data Modification time, excluding files by
7139 @cindex Modification time, excluding files by
7140 @cindex Age, excluding files by
7141 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7142 @option{-N @var{date}}) option causes @command{tar} to only work on
7143 files whose data modification or status change times are newer than
7144 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7145 it is taken to be a file name; the data modification time of that file
7146 is used as the date. If you use this option when creating or appending
7147 to an archive, the archive will only include new files. If you use
7148 @option{--after-date} when extracting an archive, @command{tar} will
7149 only extract files newer than the @var{date} you specify.
7150
7151 If you only want @command{tar} to make the date comparison based on
7152 modification of the file's data (rather than status
7153 changes), then use the @option{--newer-mtime=@var{date}} option.
7154
7155 You may use these options with any operation. Note that these options
7156 differ from the @option{--update} (@option{-u}) operation in that they
7157 allow you to specify a particular date against which @command{tar} can
7158 compare when deciding whether or not to archive the files.
7159
7160 @table @option
7161 @opindex after-date
7162 @opindex newer
7163 @item --after-date=@var{date}
7164 @itemx --newer=@var{date}
7165 @itemx -N @var{date}
7166 Only store files newer than @var{date}.
7167
7168 Acts on files only if their data modification or status change times are
7169 later than @var{date}. Use in conjunction with any operation.
7170
7171 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7172 name; the data modification time of that file is used as the date.
7173
7174 @opindex newer-mtime
7175 @item --newer-mtime=@var{date}
7176 Acts like @option{--after-date}, but only looks at data modification times.
7177 @end table
7178
7179 These options limit @command{tar} to operate only on files which have
7180 been modified after the date specified. A file's status is considered to have
7181 changed if its contents have been modified, or if its owner,
7182 permissions, and so forth, have been changed. (For more information on
7183 how to specify a date, see @ref{Date input formats}; remember that the
7184 entire date argument must be quoted if it contains any spaces.)
7185
7186 Gurus would say that @option{--after-date} tests both the data
7187 modification time (@code{mtime}, the time the contents of the file
7188 were last modified) and the status change time (@code{ctime}, the time
7189 the file's status was last changed: owner, permissions, etc.@:)
7190 fields, while @option{--newer-mtime} tests only the @code{mtime}
7191 field.
7192
7193 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7194 @code{ctime} and processes the file if either one is more recent than
7195 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7196 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7197 contents of the file were looked at).
7198
7199 Date specifiers can have embedded spaces. Because of this, you may need
7200 to quote date arguments to keep the shell from parsing them as separate
7201 arguments. For example, the following command will add to the archive
7202 all the files modified less than two days ago:
7203
7204 @smallexample
7205 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7206 @end smallexample
7207
7208 @quotation
7209 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7210 should not be used for incremental backups. @xref{Incremental Dumps},
7211 for proper way of creating incremental backups.
7212 @end quotation
7213
7214 @node recurse
7215 @section Descending into Directories
7216 @UNREVISED
7217 @cindex Avoiding recursion in directories
7218 @cindex Descending directories, avoiding
7219 @cindex Directories, avoiding recursion
7220 @cindex Recursion in directories, avoiding
7221
7222 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7223
7224 Usually, @command{tar} will recursively explore all directories (either
7225 those given on the command line or through the @option{--files-from}
7226 option) for the various files they contain. However, you may not always
7227 want @command{tar} to act this way.
7228
7229 @opindex no-recursion
7230 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7231 into specified directories. If you specify @option{--no-recursion}, you can
7232 use the @command{find} utility for hunting through levels of directories to
7233 construct a list of file names which you could then pass to @command{tar}.
7234 @command{find} allows you to be more selective when choosing which files to
7235 archive; see @ref{files}, for more information on using @command{find} with
7236 @command{tar}, or look.
7237
7238 @table @option
7239 @item --no-recursion
7240 Prevents @command{tar} from recursively descending directories.
7241
7242 @opindex recursion
7243 @item --recursion
7244 Requires @command{tar} to recursively descend directories.
7245 This is the default.
7246 @end table
7247
7248 When you use @option{--no-recursion}, @GNUTAR{} grabs
7249 directory entries themselves, but does not descend on them
7250 recursively. Many people use @command{find} for locating files they
7251 want to back up, and since @command{tar} @emph{usually} recursively
7252 descends on directories, they have to use the @samp{@w{-not -type d}}
7253 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7254 find, Finding Files}), as they usually do not want all the files in a
7255 directory. They then use the @option{--files-from} option to archive
7256 the files located via @command{find}.
7257
7258 The problem when restoring files archived in this manner is that the
7259 directories themselves are not in the archive; so the
7260 @option{--same-permissions} (@option{--preserve-permissions},
7261 @option{-p}) option does not affect them---while users might really
7262 like it to. Specifying @option{--no-recursion} is a way to tell
7263 @command{tar} to grab only the directory entries given to it, adding
7264 no new files on its own. To summarize, if you use @command{find} to
7265 create a list of files to be stored in an archive, use it as follows:
7266
7267 @smallexample
7268 @group
7269 $ @kbd{find @var{dir} @var{tests} | \
7270 tar -cf @var{archive} -T - --no-recursion}
7271 @end group
7272 @end smallexample
7273
7274 The @option{--no-recursion} option also applies when extracting: it
7275 causes @command{tar} to extract only the matched directory entries, not
7276 the files under those directories.
7277
7278 The @option{--no-recursion} option also affects how globbing patterns
7279 are interpreted (@pxref{controlling pattern-matching}).
7280
7281 The @option{--no-recursion} and @option{--recursion} options apply to
7282 later options and operands, and can be overridden by later occurrences
7283 of @option{--no-recursion} and @option{--recursion}. For example:
7284
7285 @smallexample
7286 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7287 @end smallexample
7288
7289 @noindent
7290 creates an archive with one entry for @file{grape}, and the recursive
7291 contents of @file{grape/concord}, but no entries under @file{grape}
7292 other than @file{grape/concord}.
7293
7294 @node one
7295 @section Crossing File System Boundaries
7296 @cindex File system boundaries, not crossing
7297 @UNREVISED
7298
7299 @command{tar} will normally automatically cross file system boundaries in
7300 order to archive files which are part of a directory tree. You can
7301 change this behavior by running @command{tar} and specifying
7302 @option{--one-file-system}. This option only affects files that are
7303 archived because they are in a directory that is being archived;
7304 @command{tar} will still archive files explicitly named on the command line
7305 or through @option{--files-from}, regardless of where they reside.
7306
7307 @table @option
7308 @opindex one-file-system
7309 @item --one-file-system
7310 Prevents @command{tar} from crossing file system boundaries when
7311 archiving. Use in conjunction with any write operation.
7312 @end table
7313
7314 The @option{--one-file-system} option causes @command{tar} to modify its
7315 normal behavior in archiving the contents of directories. If a file in
7316 a directory is not on the same file system as the directory itself, then
7317 @command{tar} will not archive that file. If the file is a directory
7318 itself, @command{tar} will not archive anything beneath it; in other words,
7319 @command{tar} will not cross mount points.
7320
7321 This option is useful for making full or incremental archival backups of
7322 a file system. If this option is used in conjunction with
7323 @option{--verbose} (@option{-v}), files that are excluded are
7324 mentioned by name on the standard error.
7325
7326 @menu
7327 * directory:: Changing Directory
7328 * absolute:: Absolute File Names
7329 @end menu
7330
7331 @node directory
7332 @subsection Changing the Working Directory
7333 @UNREVISED
7334
7335 @FIXME{need to read over this node now for continuity; i've switched
7336 things around some.}
7337
7338 @cindex Changing directory mid-stream
7339 @cindex Directory, changing mid-stream
7340 @cindex Working directory, specifying
7341 To change the working directory in the middle of a list of file names,
7342 either on the command line or in a file specified using
7343 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7344 This will change the working directory to the specified directory
7345 after that point in the list.
7346
7347 @table @option
7348 @opindex directory
7349 @item --directory=@var{directory}
7350 @itemx -C @var{directory}
7351 Changes the working directory in the middle of a command line.
7352 @end table
7353
7354 For example,
7355
7356 @smallexample
7357 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7358 @end smallexample
7359
7360 @noindent
7361 will place the files @file{grape} and @file{prune} from the current
7362 directory into the archive @file{jams.tar}, followed by the file
7363 @file{cherry} from the directory @file{food}. This option is especially
7364 useful when you have several widely separated files that you want to
7365 store in the same archive.
7366
7367 Note that the file @file{cherry} is recorded in the archive under the
7368 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7369 archive will contain three files that all appear to have come from the
7370 same directory; if the archive is extracted with plain @samp{tar
7371 --extract}, all three files will be written in the current directory.
7372
7373 Contrast this with the command,
7374
7375 @smallexample
7376 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7377 @end smallexample
7378
7379 @noindent
7380 which records the third file in the archive under the name
7381 @file{red/cherry} so that, if the archive is extracted using
7382 @samp{tar --extract}, the third file will be written in a subdirectory
7383 named @file{orange-colored}.
7384
7385 You can use the @option{--directory} option to make the archive
7386 independent of the original name of the directory holding the files.
7387 The following command places the files @file{/etc/passwd},
7388 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7389 @file{foo.tar}:
7390
7391 @smallexample
7392 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7393 @end smallexample
7394
7395 @noindent
7396 However, the names of the archive members will be exactly what they were
7397 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7398 They will not appear to be related by file name to the original
7399 directories where those files were located.
7400
7401 Note that @option{--directory} options are interpreted consecutively. If
7402 @option{--directory} specifies a relative file name, it is interpreted
7403 relative to the then current directory, which might not be the same as
7404 the original current working directory of @command{tar}, due to a previous
7405 @option{--directory} option.
7406
7407 When using @option{--files-from} (@pxref{files}), you can put various
7408 @command{tar} options (including @option{-C}) in the file list. Notice,
7409 however, that in this case the option and its argument may not be
7410 separated by whitespace. If you use short option, its argument must
7411 either follow the option letter immediately, without any intervening
7412 whitespace, or occupy the next line. Otherwise, if you use long
7413 option, separate its argument by an equal sign.
7414
7415 For instance, the file list for the above example will be:
7416
7417 @smallexample
7418 @group
7419 -C
7420 /etc
7421 passwd
7422 hosts
7423 -C
7424 /lib
7425 libc.a
7426 @end group
7427 @end smallexample
7428
7429 @noindent
7430 To use it, you would invoke @command{tar} as follows:
7431
7432 @smallexample
7433 $ @kbd{tar -c -f foo.tar --files-from list}
7434 @end smallexample
7435
7436 Notice also that you can only use the short option variant in the file
7437 list, i.e., always use @option{-C}, not @option{--directory}.
7438
7439 The interpretation of @option{--directory} is disabled by
7440 @option{--null} option.
7441
7442 @node absolute
7443 @subsection Absolute File Names
7444 @UNREVISED
7445
7446 @table @option
7447 @opindex absolute-names
7448 @item --absolute-names
7449 @itemx -P
7450 Do not strip leading slashes from file names, and permit file names
7451 containing a @file{..} file name component.
7452 @end table
7453
7454 By default, @GNUTAR{} drops a leading @samp{/} on
7455 input or output, and complains about file names containing a @file{..}
7456 component. This option turns off this behavior.
7457
7458 When @command{tar} extracts archive members from an archive, it strips any
7459 leading slashes (@samp{/}) from the member name. This causes absolute
7460 member names in the archive to be treated as relative file names. This
7461 allows you to have such members extracted wherever you want, instead of
7462 being restricted to extracting the member in the exact directory named
7463 in the archive. For example, if the archive member has the name
7464 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7465 really @file{etc/passwd}.
7466
7467 File names containing @file{..} can cause problems when extracting, so
7468 @command{tar} normally warns you about such files when creating an
7469 archive, and rejects attempts to extracts such files.
7470
7471 Other @command{tar} programs do not do this. As a result, if you
7472 create an archive whose member names start with a slash, they will be
7473 difficult for other people with a non-@GNUTAR{}
7474 program to use. Therefore, @GNUTAR{} also strips
7475 leading slashes from member names when putting members into the
7476 archive. For example, if you ask @command{tar} to add the file
7477 @file{/bin/ls} to an archive, it will do so, but the member name will
7478 be @file{bin/ls}.@footnote{A side effect of this is that when
7479 @option{--create} is used with @option{--verbose} the resulting output
7480 is not, generally speaking, the same as the one you'd get running
7481 @kbd{tar --list} command. This may be important if you use some
7482 scripts for comparing both outputs. @xref{listing member and file names},
7483 for the information on how to handle this case.}
7484
7485 If you use the @option{--absolute-names} (@option{-P}) option,
7486 @command{tar} will do none of these transformations.
7487
7488 To archive or extract files relative to the root directory, specify
7489 the @option{--absolute-names} (@option{-P}) option.
7490
7491 Normally, @command{tar} acts on files relative to the working
7492 directory---ignoring superior directory names when archiving, and
7493 ignoring leading slashes when extracting.
7494
7495 When you specify @option{--absolute-names} (@option{-P}),
7496 @command{tar} stores file names including all superior directory
7497 names, and preserves leading slashes. If you only invoked
7498 @command{tar} from the root directory you would never need the
7499 @option{--absolute-names} option, but using this option
7500 may be more convenient than switching to root.
7501
7502 @FIXME{Should be an example in the tutorial/wizardry section using this
7503 to transfer files between systems.}
7504
7505 @FIXME{Is write access an issue?}
7506
7507 @table @option
7508 @item --absolute-names
7509 Preserves full file names (including superior directory names) when
7510 archiving files. Preserves leading slash when extracting files.
7511
7512 @end table
7513
7514 @FIXME{this is still horrible; need to talk with dan on monday.}
7515
7516 @command{tar} prints out a message about removing the @samp{/} from
7517 file names. This message appears once per @GNUTAR{}
7518 invocation. It represents something which ought to be told; ignoring
7519 what it means can cause very serious surprises, later.
7520
7521 Some people, nevertheless, do not want to see this message. Wanting to
7522 play really dangerously, one may of course redirect @command{tar} standard
7523 error to the sink. For example, under @command{sh}:
7524
7525 @smallexample
7526 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7527 @end smallexample
7528
7529 @noindent
7530 Another solution, both nicer and simpler, would be to change to
7531 the @file{/} directory first, and then avoid absolute notation.
7532 For example:
7533
7534 @smallexample
7535 $ @kbd{(cd / && tar -c -f archive.tar home)}
7536 # @i{or}:
7537 $ @kbd{tar -c -f archive.tar -C / home}
7538 @end smallexample
7539
7540 @include getdate.texi
7541
7542 @node Formats
7543 @chapter Controlling the Archive Format
7544
7545 @cindex Tar archive formats
7546 Due to historical reasons, there are several formats of tar archives.
7547 All of them are based on the same principles, but have some subtle
7548 differences that often make them incompatible with each other.
7549
7550 GNU tar is able to create and handle archives in a variety of formats.
7551 The most frequently used formats are (in alphabetical order):
7552
7553 @table @asis
7554 @item gnu
7555 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7556 from an early @acronym{POSIX} standard, adding some improvements such as
7557 sparse file handling and incremental archives. Unfortunately these
7558 features were implemented in a way incompatible with other archive
7559 formats.
7560
7561 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7562 length.
7563
7564 @item oldgnu
7565 Format used by @GNUTAR{} of versions prior to 1.12.
7566
7567 @item v7
7568 Archive format, compatible with the V7 implementation of tar. This
7569 format imposes a number of limitations. The most important of them
7570 are:
7571
7572 @enumerate
7573 @item The maximum length of a file name is limited to 99 characters.
7574 @item The maximum length of a symbolic link is limited to 99 characters.
7575 @item It is impossible to store special files (block and character
7576 devices, fifos etc.)
7577 @item Maximum value of user or group ID is limited to 2097151 (7777777
7578 octal)
7579 @item V7 archives do not contain symbolic ownership information (user
7580 and group name of the file owner).
7581 @end enumerate
7582
7583 This format has traditionally been used by Automake when producing
7584 Makefiles. This practice will change in the future, in the meantime,
7585 however this means that projects containing filenames more than 99
7586 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7587 Automake prior to 1.9.
7588
7589 @item ustar
7590 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7591 symbolic ownership information. It is also able to store
7592 special files. However, it imposes several restrictions as well:
7593
7594 @enumerate
7595 @item The maximum length of a file name is limited to 256 characters,
7596 provided that the filename can be split at directory separator in
7597 two parts, first of them being at most 155 bytes long. So, in most
7598 cases the maximum file name length will be shorter than 256
7599 characters.
7600 @item The maximum length of a symbolic link name is limited to
7601 100 characters.
7602 @item Maximum size of a file the archive is able to accomodate
7603 is 8GB
7604 @item Maximum value of UID/GID is 2097151.
7605 @item Maximum number of bits in device major and minor numbers is 21.
7606 @end enumerate
7607
7608 @item star
7609 Format used by J@"org Schilling @command{star}
7610 implementation. @GNUTAR{} is able to read @samp{star} archives but
7611 currently does not produce them.
7612
7613 @item posix
7614 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7615 most flexible and feature-rich format. It does not impose any
7616 restrictions on file sizes or filename lengths. This format is quite
7617 recent, so not all tar implementations are able to handle it properly.
7618 However, this format is designed in such a way that any tar
7619 implementation able to read @samp{ustar} archives will be able to read
7620 most @samp{posix} archives as well, with the only exception that any
7621 additional information (such as long file names etc.) will in such
7622 case be extracted as plain text files along with the files it refers to.
7623
7624 This archive format will be the default format for future versions
7625 of @GNUTAR{}.
7626
7627 @end table
7628
7629 The following table summarizes the limitations of each of these
7630 formats:
7631
7632 @multitable @columnfractions .10 .20 .20 .20 .20
7633 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7634 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7635 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7636 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7637 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7638 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7639 @end multitable
7640
7641 The default format for @GNUTAR{} is defined at compilation
7642 time. You may check it by running @command{tar --help}, and examining
7643 the last lines of its output. Usually, @GNUTAR{} is configured
7644 to create archives in @samp{gnu} format, however, future version will
7645 switch to @samp{posix}.
7646
7647 @menu
7648 * Portability:: Making @command{tar} Archives More Portable
7649 * Compression:: Using Less Space through Compression
7650 * Attributes:: Handling File Attributes
7651 * cpio:: Comparison of @command{tar} and @command{cpio}
7652 @end menu
7653
7654 @node Portability
7655 @section Making @command{tar} Archives More Portable
7656
7657 Creating a @command{tar} archive on a particular system that is meant to be
7658 useful later on many other machines and with other versions of @command{tar}
7659 is more challenging than you might think. @command{tar} archive formats
7660 have been evolving since the first versions of Unix. Many such formats
7661 are around, and are not always compatible with each other. This section
7662 discusses a few problems, and gives some advice about making @command{tar}
7663 archives more portable.
7664
7665 One golden rule is simplicity. For example, limit your @command{tar}
7666 archives to contain only regular files and directories, avoiding
7667 other kind of special files. Do not attempt to save sparse files or
7668 contiguous files as such. Let's discuss a few more problems, in turn.
7669
7670 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7671 archives and archive labels) in GNU and PAX formats.}
7672
7673 @menu
7674 * Portable Names:: Portable Names
7675 * dereference:: Symbolic Links
7676 * old:: Old V7 Archives
7677 * ustar:: Ustar Archives
7678 * gnu:: GNU and old GNU format archives.
7679 * posix:: @acronym{POSIX} archives
7680 * Checksumming:: Checksumming Problems
7681 * Large or Negative Values:: Large files, negative time stamps, etc.
7682 @end menu
7683
7684 @node Portable Names
7685 @subsection Portable Names
7686
7687 Use portable file and member names. A name is portable if it contains
7688 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7689 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7690 contain @samp{/-}. Avoid deep directory nesting. For portability to
7691 old Unix hosts, limit your file name components to 14 characters or
7692 less.
7693
7694 If you intend to have your @command{tar} archives to be read under
7695 MSDOS, you should not rely on case distinction for file names, and you
7696 might use the @acronym{GNU} @command{doschk} program for helping you
7697 further diagnosing illegal MSDOS names, which are even more limited
7698 than System V's.
7699
7700 @node dereference
7701 @subsection Symbolic Links
7702 @cindex File names, using symbolic links
7703 @cindex Symbolic link as file name
7704
7705 @opindex dereference
7706 Normally, when @command{tar} archives a symbolic link, it writes a
7707 block to the archive naming the target of the link. In that way, the
7708 @command{tar} archive is a faithful record of the file system contents.
7709 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7710 @command{tar} to archive the files symbolic links point to, instead of
7711 the links themselves. When this option is used, when @command{tar}
7712 encounters a symbolic link, it will archive the linked-to file,
7713 instead of simply recording the presence of a symbolic link.
7714
7715 The name under which the file is stored in the file system is not
7716 recorded in the archive. To record both the symbolic link name and
7717 the file name in the system, archive the file under both names. If
7718 all links were recorded automatically by @command{tar}, an extracted file
7719 might be linked to a file name that no longer exists in the file
7720 system.
7721
7722 If a linked-to file is encountered again by @command{tar} while creating
7723 the same archive, an entire second copy of it will be stored. (This
7724 @emph{might} be considered a bug.)
7725
7726 So, for portable archives, do not archive symbolic links as such,
7727 and use @option{--dereference} (@option{-h}): many systems do not support
7728 symbolic links, and moreover, your distribution might be unusable if
7729 it contains unresolved symbolic links.
7730
7731 @node old
7732 @subsection Old V7 Archives
7733 @cindex Format, old style
7734 @cindex Old style format
7735 @cindex Old style archives
7736 @cindex v7 archive format
7737
7738 Certain old versions of @command{tar} cannot handle additional
7739 information recorded by newer @command{tar} programs. To create an
7740 archive in V7 format (not ANSI), which can be read by these old
7741 versions, specify the @option{--format=v7} option in
7742 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7743 accepts @option{--portability} or @samp{op-old-archive} for this
7744 option). When you specify it,
7745 @command{tar} leaves out information about directories, pipes, fifos,
7746 contiguous files, and device files, and specifies file ownership by
7747 group and user IDs instead of group and user names.
7748
7749 When updating an archive, do not use @option{--format=v7}
7750 unless the archive was created using this option.
7751
7752 In most cases, a @emph{new} format archive can be read by an @emph{old}
7753 @command{tar} program without serious trouble, so this option should
7754 seldom be needed. On the other hand, most modern @command{tar}s are
7755 able to read old format archives, so it might be safer for you to
7756 always use @option{--format=v7} for your distributions.
7757
7758 @node ustar
7759 @subsection Ustar Archive Format
7760
7761 @cindex ustar archive format
7762 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7763 @code{ustar}. Although it is more flexible than the V7 format, it
7764 still has many restrictions (@xref{Formats,ustar}, for the detailed
7765 description of @code{ustar} format). Along with V7 format,
7766 @code{ustar} format is a good choice for archives intended to be read
7767 with other implementations of @command{tar}.
7768
7769 To create archive in @code{ustar} format, use @option{--format=ustar}
7770 option in conjunction with the @option{--create} (@option{-c}).
7771
7772 @node gnu
7773 @subsection @acronym{GNU} and old @GNUTAR{} format
7774
7775 @cindex GNU archive format
7776 @cindex Old GNU archive format
7777 @GNUTAR{} was based on an early draft of the
7778 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7779 @command{tar}, such as the support for file names longer than 100
7780 characters, use portions of the @command{tar} header record which were
7781 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7782 @acronym{POSIX} have allocated the same parts of the header record for
7783 other purposes. As a result, @GNUTAR{} format is
7784 incompatible with the current @acronym{POSIX} specification, and with
7785 @command{tar} programs that follow it.
7786
7787 In the majority of cases, @command{tar} will be configured to create
7788 this format by default. This will change in the future releases, since
7789 we plan to make @samp{posix} format the default.
7790
7791 To force creation a @GNUTAR{} archive, use option
7792 @option{--format=gnu}.
7793
7794 @node posix
7795 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7796
7797 @cindex POSIX archive format
7798 @cindex PAX archive format
7799 Starting from version 1.14 @GNUTAR{} features full support for
7800 @acronym{POSIX.1-2001} archives.
7801
7802 A @acronym{POSIX} conformant archive will be created if @command{tar}
7803 was given @option{--format=posix} (@option{--format=pax}) option. No
7804 special option is required to read and extract from a @acronym{POSIX}
7805 archive.
7806
7807 @menu
7808 * PAX keywords:: Controlling Extended Header Keywords.
7809 @end menu
7810
7811 @node PAX keywords
7812 @subsubsection Controlling Extended Header Keywords
7813
7814 @table @option
7815 @opindex pax-option
7816 @item --pax-option=@var{keyword-list}
7817 Handle keywords in @acronym{PAX} extended headers. This option is
7818 equivalent to @option{-o} option of the @command{pax} utility.
7819 @end table
7820
7821 @var{Keyword-list} is a comma-separated
7822 list of keyword options, each keyword option taking one of
7823 the following forms:
7824
7825 @table @code
7826 @item delete=@var{pattern}
7827 When used with one of archive-creation commands,
7828 this option instructs @command{tar} to omit from extended header records
7829 that it produces any keywords matching the string @var{pattern}.
7830
7831 When used in extract or list mode, this option instructs tar
7832 to ignore any keywords matching the given @var{pattern} in the extended
7833 header records. In both cases, matching is performed using the pattern
7834 matching notation described in @acronym{POSIX 1003.2}, 3.13
7835 (@pxref{wildcards}). For example:
7836
7837 @smallexample
7838 --pax-option delete=security.*
7839 @end smallexample
7840
7841 would suppress security-related information.
7842
7843 @item exthdr.name=@var{string}
7844
7845 This keyword allows user control over the name that is written into the
7846 ustar header blocks for the extended headers. The name is obtained
7847 from @var{string} after making the following substitutions:
7848
7849 @multitable @columnfractions .25 .55
7850 @headitem Meta-character @tab Replaced By
7851 @item %d @tab The directory name of the file, equivalent to the
7852 result of the @command{dirname} utility on the translated pathname.
7853 @item %f @tab The filename of the file, equivalent to the result
7854 of the @command{basename} utility on the translated pathname.
7855 @item %p @tab The process ID of the @command{tar} process.
7856 @item %% @tab A @samp{%} character.
7857 @end multitable
7858
7859 Any other @samp{%} characters in @var{string} produce undefined
7860 results.
7861
7862 If no option @samp{exthdr.name=string} is specified, @command{tar}
7863 will use the following default value:
7864
7865 @smallexample
7866 %d/PaxHeaders.%p/%f
7867 @end smallexample
7868
7869 @item globexthdr.name=@var{string}
7870 This keyword allows user control over the name that is written into
7871 the ustar header blocks for global extended header records. The name
7872 is obtained from the contents of @var{string}, after making
7873 the following substitutions:
7874
7875 @multitable @columnfractions .25 .55
7876 @headitem Meta-character @tab Replaced By
7877 @item %n @tab An integer that represents the
7878 sequence number of the global extended header record in the archive,
7879 starting at 1.
7880 @item %p @tab The process ID of the @command{tar} process.
7881 @item %% @tab A @samp{%} character.
7882 @end multitable
7883
7884 Any other @samp{%} characters in @var{string} produce undefined results.
7885
7886 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7887 will use the following default value:
7888
7889 @smallexample
7890 $TMPDIR/GlobalHead.%p.%n
7891 @end smallexample
7892
7893 @noindent
7894 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7895 environment variable. If @var{TMPDIR} is not set, @command{tar}
7896 uses @samp{/tmp}.
7897
7898 @item @var{keyword}=@var{value}
7899 When used with one of archive-creation commands, these keyword/value pairs
7900 will be included at the beginning of the archive in a global extended
7901 header record. When used with one of archive-reading commands,
7902 @command{tar} will behave as if it has encountered these keyword/value
7903 pairs at the beginning of the archive in a global extended header
7904 record.
7905
7906 @item @var{keyword}:=@var{value}
7907 When used with one of archive-creation commands, these keyword/value pairs
7908 will be included as records at the beginning of an extended header for
7909 each file. This is effectively equivalent to @var{keyword}=@var{value}
7910 form except that it creates no global extended header records.
7911
7912 When used with one of archive-reading commands, @command{tar} will
7913 behave as if these keyword/value pairs were included as records at the
7914 end of each extended header; thus, they will override any global or
7915 file-specific extended header record keywords of the same names.
7916 For example, in the command:
7917
7918 @smallexample
7919 tar --format=posix --create \
7920 --file archive --pax-option gname:=user .
7921 @end smallexample
7922
7923 the group name will be forced to a new value for all files
7924 stored in the archive.
7925 @end table
7926
7927 @node Checksumming
7928 @subsection Checksumming Problems
7929
7930 SunOS and HP-UX @command{tar} fail to accept archives created using
7931 @GNUTAR{} and containing non-ASCII file names, that
7932 is, file names having characters with the eight bit set, because they
7933 use signed checksums, while @GNUTAR{} uses unsigned
7934 checksums while creating archives, as per @acronym{POSIX} standards. On
7935 reading, @GNUTAR{} computes both checksums and
7936 accept any. It is somewhat worrying that a lot of people may go
7937 around doing backup of their files using faulty (or at least
7938 non-standard) software, not learning about it until it's time to
7939 restore their missing files with an incompatible file extractor, or
7940 vice versa.
7941
7942 @GNUTAR{} compute checksums both ways, and accept
7943 any on read, so @acronym{GNU} tar can read Sun tapes even with their
7944 wrong checksums. @GNUTAR{} produces the standard
7945 checksum, however, raising incompatibilities with Sun. That is to
7946 say, @GNUTAR{} has not been modified to
7947 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
7948 I've been told that more recent Sun @command{tar} now read standard
7949 archives, so maybe Sun did a similar patch, after all?
7950
7951 The story seems to be that when Sun first imported @command{tar}
7952 sources on their system, they recompiled it without realizing that
7953 the checksums were computed differently, because of a change in
7954 the default signing of @code{char}'s in their compiler. So they
7955 started computing checksums wrongly. When they later realized their
7956 mistake, they merely decided to stay compatible with it, and with
7957 themselves afterwards. Presumably, but I do not really know, HP-UX
7958 has chosen that their @command{tar} archives to be compatible with Sun's.
7959 The current standards do not favor Sun @command{tar} format. In any
7960 case, it now falls on the shoulders of SunOS and HP-UX users to get
7961 a @command{tar} able to read the good archives they receive.
7962
7963 @node Large or Negative Values
7964 @subsection Large or Negative Values
7965 @cindex large values
7966 @cindex future time stamps
7967 @cindex negative time stamps
7968 @UNREVISED{}
7969
7970 The above sections suggest to use @samp{oldest possible} archive
7971 format if in doubt. However, sometimes it is not possible. If you
7972 attempt to archive a file whose metadata cannot be represented using
7973 required format, @GNUTAR{} will print error message and ignore such a
7974 file. You will than have to switch to a format that is able to
7975 handle such values. The format summary table (@pxref{Formats}) will
7976 help you to do so.
7977
7978 In particular, when trying to archive files larger than 8GB or with
7979 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
7980 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
7981 @acronym{POSIX} archive formats. When considering which format to
7982 choose, bear in mind that the @acronym{GNU} format uses
7983 two's-complement base-256 notation to store values that do not fit
7984 into standard @acronym{ustar} range. Such archives can generally be
7985 read only by a @GNUTAR{} implementation. Moreover, they sometimes
7986 cannot be correctly restored on another hosts even by @GNUTAR{}. For
7987 example, using two's complement representation for negative time
7988 stamps that assumes a signed 32-bit @code{time_t} generates archives
7989 that are not portable to hosts with differing @code{time_t}
7990 representations.
7991
7992 On the other hand, @acronym{POSIX} archives, generally speaking, can
7993 be extracted by any tar implementation that understands older
7994 @acronym{ustar} format. The only exception are files larger than 8GB.
7995
7996 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
7997 POSIX-aware tars.}
7998
7999 @node Compression
8000 @section Using Less Space through Compression
8001
8002 @menu
8003 * gzip:: Creating and Reading Compressed Archives
8004 * sparse:: Archiving Sparse Files
8005 @end menu
8006
8007 @node gzip
8008 @subsection Creating and Reading Compressed Archives
8009 @cindex Compressed archives
8010 @cindex Storing archives in compressed format
8011
8012 @GNUTAR{} is able to create and read compressed archives. It supports
8013 @command{gzip} and @command{bzip2} compression programs. For backward
8014 compatibilty, it also supports @command{compress} command, although
8015 we strongly recommend against using it, since there is a patent
8016 covering the algorithm it uses and you could be sued for patent
8017 infringement merely by running @command{compress}! Besides, it is less
8018 effective than @command{gzip} and @command{bzip2}.
8019
8020 Creating a compressed archive is simple: you just specify a
8021 @dfn{compression option} along with the usual archive creation
8022 commands. The compression option is @option{-z} (@option{--gzip}) to
8023 create a @command{gzip} compressed archive, @option{-j}
8024 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
8025 @option{-Z} (@option{--compress}) to use @command{compress} program.
8026 For example:
8027
8028 @smallexample
8029 $ @kbd{tar cfz archive.tar.gz .}
8030 @end smallexample
8031
8032 Reading compressed archive is even simpler: you don't need to specify
8033 any additional options as @GNUTAR{} recognizes its format
8034 automatically. Thus, the following commands will list and extract the
8035 archive created in previous example:
8036
8037 @smallexample
8038 # List the compressed archive
8039 $ @kbd{tar tf archive.tar.gz}
8040 # Extract the compressed archive
8041 $ @kbd{tar xf archive.tar.gz}
8042 @end smallexample
8043
8044 The only case when you have to specify a decompression option while
8045 reading the archive is when reading from a pipe or from a tape drive
8046 that does not support random access. However, in this case @GNUTAR{}
8047 will indicate which option you should use. For example:
8048
8049 @smallexample
8050 $ @kbd{cat archive.tar.gz | tar tf -}
8051 tar: Archive is compressed. Use -z option
8052 tar: Error is not recoverable: exiting now
8053 @end smallexample
8054
8055 If you see such diagnostics, just add the suggested option to the
8056 invocation of @GNUTAR{}:
8057
8058 @smallexample
8059 $ @kbd{cat archive.tar.gz | tar tfz -}
8060 @end smallexample
8061
8062 Notice also, that there are several restrictions on operations on
8063 compressed archives. First of all, compressed archives cannot be
8064 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8065 (@option{--delete}) members from them. Likewise, you cannot append
8066 another @command{tar} archive to a compressed archive using
8067 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8068 compressed.
8069
8070 The following table summarizes compression options used by @GNUTAR{}.
8071
8072 @table @option
8073 @opindex gzip
8074 @opindex ungzip
8075 @item -z
8076 @itemx --gzip
8077 @itemx --ungzip
8078 Filter the archive through @command{gzip}.
8079
8080 You can use @option{--gzip} and @option{--gunzip} on physical devices
8081 (tape drives, etc.) and remote files as well as on normal files; data
8082 to or from such devices or remote files is reblocked by another copy
8083 of the @command{tar} program to enforce the specified (or default) record
8084 size. The default compression parameters are used; if you need to
8085 override them, set @env{GZIP} environment variable, e.g.:
8086
8087 @smallexample
8088 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8089 @end smallexample
8090
8091 @noindent
8092 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8093 @command{gzip} explicitly:
8094
8095 @smallexample
8096 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8097 @end smallexample
8098
8099 @cindex corrupted archives
8100 About corrupted compressed archives: @command{gzip}'ed files have no
8101 redundancy, for maximum compression. The adaptive nature of the
8102 compression scheme means that the compression tables are implicitly
8103 spread all over the archive. If you lose a few blocks, the dynamic
8104 construction of the compression tables becomes unsynchronized, and there
8105 is little chance that you could recover later in the archive.
8106
8107 There are pending suggestions for having a per-volume or per-file
8108 compression in @GNUTAR{}. This would allow for viewing the
8109 contents without decompression, and for resynchronizing decompression at
8110 every volume or file, in case of corrupted archives. Doing so, we might
8111 lose some compressibility. But this would have make recovering easier.
8112 So, there are pros and cons. We'll see!
8113
8114 @opindex bzip2
8115 @item -j
8116 @itemx --bzip2
8117 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8118
8119 @opindex compress
8120 @opindex uncompress
8121 @item -Z
8122 @itemx --compress
8123 @itemx --uncompress
8124 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8125
8126 The @acronym{GNU} Project recommends you not use
8127 @command{compress}, because there is a patent covering the algorithm it
8128 uses. You could be sued for patent infringement merely by running
8129 @command{compress}.
8130
8131 @opindex use-compress-program
8132 @item --use-compress-program=@var{prog}
8133 Use external compression program @var{prog}. Use this option if you
8134 have a compression program that @GNUTAR{} does not support. There
8135 are two requirements to which @var{prog} should comply:
8136
8137 First, when called without options, it should read data from standard
8138 input, compress it and output it on standard output.
8139
8140 Secondly, if called with @option{-d} argument, it should do exactly
8141 the opposite, i.e., read the compressed data from the standard input
8142 and produce uncompressed data on the standard output.
8143 @end table
8144
8145 @cindex gpg, using with tar
8146 @cindex gnupg, using with tar
8147 @cindex Using encrypted archives
8148 The @option{--use-compress-program} option, in particular, lets you
8149 implement your own filters, not necessarily dealing with
8150 compression/decomression. For example, suppose you wish to implement
8151 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8152 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8153 Manual}). The following script does that:
8154
8155 @smallexample
8156 @group
8157 #! /bin/sh
8158 case $1 in
8159 -d) gpg --decrypt - | gzip -d -c;;
8160 '') gzip -c | gpg -s ;;
8161 *) echo "Unknown option $1">&2; exit 1;;
8162 esac
8163 @end group
8164 @end smallexample
8165
8166 Suppose you name it @file{gpgz} and save it somewhere in your
8167 @env{PATH}. Then the following command will create a commpressed
8168 archive signed with your private key:
8169
8170 @smallexample
8171 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8172 @end smallexample
8173
8174 @noindent
8175 Likewise, the following command will list its contents:
8176
8177 @smallexample
8178 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8179 @end smallexample
8180
8181 @ignore
8182 The above is based on the following discussion:
8183
8184 I have one question, or maybe it's a suggestion if there isn't a way
8185 to do it now. I would like to use @option{--gzip}, but I'd also like
8186 the output to be fed through a program like @acronym{GNU}
8187 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8188 to use :-)), basically adding ECC protection on top of compression.
8189 It seems as if this should be quite easy to do, but I can't work out
8190 exactly how to go about it. Of course, I can pipe the standard output
8191 of @command{tar} through @command{ecc}, but then I lose (though I
8192 haven't started using it yet, I confess) the ability to have
8193 @command{tar} use @command{rmt} for it's I/O (I think).
8194
8195 I think the most straightforward thing would be to let me specify a
8196 general set of filters outboard of compression (preferably ordered,
8197 so the order can be automatically reversed on input operations, and
8198 with the options they require specifiable), but beggars shouldn't be
8199 choosers and anything you decide on would be fine with me.
8200
8201 By the way, I like @command{ecc} but if (as the comments say) it can't
8202 deal with loss of block sync, I'm tempted to throw some time at adding
8203 that capability. Supposing I were to actually do such a thing and
8204 get it (apparently) working, do you accept contributed changes to
8205 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8206
8207 Isn't that exactly the role of the
8208 @option{--use-compress-prog=@var{program}} option?
8209 I never tried it myself, but I suspect you may want to write a
8210 @var{prog} script or program able to filter stdin to stdout to
8211 way you want. It should recognize the @option{-d} option, for when
8212 extraction is needed rather than creation.
8213
8214 It has been reported that if one writes compressed data (through the
8215 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8216 the DLT compression mode, the data will actually get bigger and one will
8217 end up with less space on the tape.
8218 @end ignore
8219
8220 @node sparse
8221 @subsection Archiving Sparse Files
8222 @cindex Sparse Files
8223 @UNREVISED
8224
8225 @table @option
8226 @opindex sparse
8227 @item -S
8228 @itemx --sparse
8229 Handle sparse files efficiently.
8230 @end table
8231
8232 This option causes all files to be put in the archive to be tested for
8233 sparseness, and handled specially if they are. The @option{--sparse}
8234 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8235 backed up. Using this option dramatically decreases the amount of
8236 space needed to store such a file.
8237
8238 In later versions, this option may be removed, and the testing and
8239 treatment of sparse files may be done automatically with any special
8240 @acronym{GNU} options. For now, it is an option needing to be specified on
8241 the command line with the creation or updating of an archive.
8242
8243 Files in the file system occasionally have ``holes.'' A hole in a file
8244 is a section of the file's contents which was never written. The
8245 contents of a hole read as all zeros. On many operating systems,
8246 actual disk storage is not allocated for holes, but they are counted
8247 in the length of the file. If you archive such a file, @command{tar}
8248 could create an archive longer than the original. To have @command{tar}
8249 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8250 you use this option, then, for any file using less disk space than
8251 would be expected from its length, @command{tar} searches the file for
8252 consecutive stretches of zeros. It then records in the archive for
8253 the file where the consecutive stretches of zeros are, and only
8254 archives the ``real contents'' of the file. On extraction (using
8255 @option{--sparse} is not needed on extraction) any such
8256 files have holes created wherever the continuous stretches of zeros
8257 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8258 won't take more space than the original.
8259
8260 A file is sparse if it contains blocks of zeros whose existence is
8261 recorded, but that have no space allocated on disk. When you specify
8262 the @option{--sparse} option in conjunction with the @option{--create}
8263 (@option{-c}) operation, @command{tar} tests all files for sparseness
8264 while archiving. If @command{tar} finds a file to be sparse, it uses a
8265 sparse representation of the file in the archive. @xref{create}, for
8266 more information about creating archives.
8267
8268 @option{--sparse} is useful when archiving files, such as dbm files,
8269 likely to contain many nulls. This option dramatically
8270 decreases the amount of space needed to store such an archive.
8271
8272 @quotation
8273 @strong{Please Note:} Always use @option{--sparse} when performing file
8274 system backups, to avoid archiving the expanded forms of files stored
8275 sparsely in the system.
8276
8277 Even if your system has no sparse files currently, some may be
8278 created in the future. If you use @option{--sparse} while making file
8279 system backups as a matter of course, you can be assured the archive
8280 will never take more space on the media than the files take on disk
8281 (otherwise, archiving a disk filled with sparse files might take
8282 hundreds of tapes). @xref{Incremental Dumps}.
8283 @end quotation
8284
8285 @command{tar} ignores the @option{--sparse} option when reading an archive.
8286
8287 @table @option
8288 @item --sparse
8289 @itemx -S
8290 Files stored sparsely in the file system are represented sparsely in
8291 the archive. Use in conjunction with write operations.
8292 @end table
8293
8294 However, users should be well aware that at archive creation time,
8295 @GNUTAR{} still has to read whole disk file to
8296 locate the @dfn{holes}, and so, even if sparse files use little space
8297 on disk and in the archive, they may sometimes require inordinate
8298 amount of time for reading and examining all-zero blocks of a file.
8299 Although it works, it's painfully slow for a large (sparse) file, even
8300 though the resulting tar archive may be small. (One user reports that
8301 dumping a @file{core} file of over 400 megabytes, but with only about
8302 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8303 ELC, with full CPU utilization.)
8304
8305 This reading is required in all cases and is not related to the fact
8306 the @option{--sparse} option is used or not, so by merely @emph{not}
8307 using the option, you are not saving time@footnote{Well! We should say
8308 the whole truth, here. When @option{--sparse} is selected while creating
8309 an archive, the current @command{tar} algorithm requires sparse files to be
8310 read twice, not once. We hope to develop a new archive format for saving
8311 sparse files in which one pass will be sufficient.}.
8312
8313 Programs like @command{dump} do not have to read the entire file; by
8314 examining the file system directly, they can determine in advance
8315 exactly where the holes are and thus avoid reading through them. The
8316 only data it need read are the actual allocated data blocks.
8317 @GNUTAR{} uses a more portable and straightforward
8318 archiving approach, it would be fairly difficult that it does
8319 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8320 1990-12-10:
8321
8322 @quotation
8323 What I did say is that you cannot tell the difference between a hole and an
8324 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8325 best tells you how many holes there are; it doesn't tell you @emph{where}.
8326 Just as programs may, conceivably, care what @code{st_blocks} is (care
8327 to name one that does?), they may also care where the holes are (I have
8328 no examples of this one either, but it's equally imaginable).
8329
8330 I conclude from this that good archivers are not portable. One can
8331 arguably conclude that if you want a portable program, you can in good
8332 conscience restore files with as many holes as possible, since you can't
8333 get it right.
8334 @end quotation
8335
8336 @node Attributes
8337 @section Handling File Attributes
8338 @UNREVISED
8339
8340 When @command{tar} reads files, it updates their access times. To
8341 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8342 reset the access time retroactively or avoid changing it in the first
8343 place.
8344
8345 Handling of file attributes
8346
8347 @table @option
8348 @opindex atime-preserve
8349 @item --atime-preserve
8350 @itemx --atime-preserve=replace
8351 @itemx --atime-preserve=system
8352 Preserve the access times of files that are read. This works only for
8353 files that you own, unless you have superuser privileges.
8354
8355 @option{--atime-preserve=replace} works on most systems, but it also
8356 restores the data modification time and updates the status change
8357 time. Hence it doesn't interact with incremental dumps nicely
8358 (@pxref{Backups}), and it can set access or data modification times
8359 incorrectly if other programs access the file while @command{tar} is
8360 running.
8361
8362 @option{--atime-preserve=system} avoids changing the access time in
8363 the first place, if the operating system supports this.
8364 Unfortunately, this may or may not work on any given operating system
8365 or file system. If @command{tar} knows for sure it won't work, it
8366 complains right away.
8367
8368 Currently @option{--atime-preserve} with no operand defaults to
8369 @option{--atime-preserve=replace}, but this is intended to change to
8370 @option{--atime-preserve=system} when the latter is better-supported.
8371
8372 @opindex touch
8373 @item -m
8374 @itemx --touch
8375 Do not extract data modification time.
8376
8377 When this option is used, @command{tar} leaves the data modification times
8378 of the files it extracts as the times when the files were extracted,
8379 instead of setting it to the times recorded in the archive.
8380
8381 This option is meaningless with @option{--list} (@option{-t}).
8382
8383 @opindex same-owner
8384 @item --same-owner
8385 Create extracted files with the same ownership they have in the
8386 archive.
8387
8388 This is the default behavior for the superuser,
8389 so this option is meaningful only for non-root users, when @command{tar}
8390 is executed on those systems able to give files away. This is
8391 considered as a security flaw by many people, at least because it
8392 makes quite difficult to correctly account users for the disk space
8393 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8394 files are easily and silently lost when files are given away.
8395
8396 When writing an archive, @command{tar} writes the user id and user name
8397 separately. If it can't find a user name (because the user id is not
8398 in @file{/etc/passwd}), then it does not write one. When restoring,
8399 it tries to look the name (if one was written) up in
8400 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8401 the archive instead.
8402
8403 @opindex no-same-owner
8404 @item --no-same-owner
8405 @itemx -o
8406 Do not attempt to restore ownership when extracting. This is the
8407 default behavior for ordinary users, so this option has an effect
8408 only for the superuser.
8409
8410 @opindex numeric-owner
8411 @item --numeric-owner
8412 The @option{--numeric-owner} option allows (ANSI) archives to be written
8413 without user/group name information or such information to be ignored
8414 when extracting. It effectively disables the generation and/or use
8415 of user/group name information. This option forces extraction using
8416 the numeric ids from the archive, ignoring the names.
8417
8418 This is useful in certain circumstances, when restoring a backup from
8419 an emergency floppy with different passwd/group files for example.
8420 It is otherwise impossible to extract files with the right ownerships
8421 if the password file in use during the extraction does not match the
8422 one belonging to the file system(s) being extracted. This occurs,
8423 for example, if you are restoring your files after a major crash and
8424 had booted from an emergency floppy with no password file or put your
8425 disk into another machine to do the restore.
8426
8427 The numeric ids are @emph{always} saved into @command{tar} archives.
8428 The identifying names are added at create time when provided by the
8429 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8430 used when moving archives between a collection of machines using
8431 a centralized management for attribution of numeric ids to users
8432 and groups. This is often made through using the NIS capabilities.
8433
8434 When making a @command{tar} file for distribution to other sites, it
8435 is sometimes cleaner to use a single owner for all files in the
8436 distribution, and nicer to specify the write permission bits of the
8437 files as stored in the archive independently of their actual value on
8438 the file system. The way to prepare a clean distribution is usually
8439 to have some Makefile rule creating a directory, copying all needed
8440 files in that directory, then setting ownership and permissions as
8441 wanted (there are a lot of possible schemes), and only then making a
8442 @command{tar} archive out of this directory, before cleaning
8443 everything out. Of course, we could add a lot of options to
8444 @GNUTAR{} for fine tuning permissions and ownership.
8445 This is not the good way, I think. @GNUTAR{} is
8446 already crowded with options and moreover, the approach just explained
8447 gives you a great deal of control already.
8448
8449 @opindex same-permissions, short description
8450 @opindex preserve-permissions, short description
8451 @item -p
8452 @itemx --same-permissions
8453 @itemx --preserve-permissions
8454 Extract all protection information.
8455
8456 This option causes @command{tar} to set the modes (access permissions) of
8457 extracted files exactly as recorded in the archive. If this option
8458 is not used, the current @code{umask} setting limits the permissions
8459 on extracted files. This option is by default enabled when
8460 @command{tar} is executed by a superuser.
8461
8462
8463 This option is meaningless with @option{--list} (@option{-t}).
8464
8465 @opindex preserve
8466 @item --preserve
8467 Same as both @option{--same-permissions} and @option{--same-order}.
8468
8469 The @option{--preserve} option has no equivalent short option name.
8470 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8471
8472 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8473 Neither do I. --Sergey}
8474
8475 @end table
8476
8477 @node cpio
8478 @section Comparison of @command{tar} and @command{cpio}
8479 @UNREVISED
8480
8481 @FIXME{Reorganize the following material}
8482
8483 The @command{cpio} archive formats, like @command{tar}, do have maximum
8484 pathname lengths. The binary and old ASCII formats have a max path
8485 length of 256, and the new ASCII and CRC ASCII formats have a max
8486 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8487 with arbitrary pathname lengths, but other @command{cpio} implementations
8488 may crash unexplainedly trying to read them.
8489
8490 @command{tar} handles symbolic links in the form in which it comes in BSD;
8491 @command{cpio} doesn't handle symbolic links in the form in which it comes
8492 in System V prior to SVR4, and some vendors may have added symlinks
8493 to their system without enhancing @command{cpio} to know about them.
8494 Others may have enhanced it in a way other than the way I did it
8495 at Sun, and which was adopted by AT&T (and which is, I think, also
8496 present in the @command{cpio} that Berkeley picked up from AT&T and put
8497 into a later BSD release---I think I gave them my changes).
8498
8499 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8500 can handle @command{tar} format input, and write it on output, and it
8501 probably handles symbolic links. They may not have bothered doing
8502 anything to enhance @command{tar} as a result.)
8503
8504 @command{cpio} handles special files; traditional @command{tar} doesn't.
8505
8506 @command{tar} comes with V7, System III, System V, and BSD source;
8507 @command{cpio} comes only with System III, System V, and later BSD
8508 (4.3-tahoe and later).
8509
8510 @command{tar}'s way of handling multiple hard links to a file can handle
8511 file systems that support 32-bit inumbers (e.g., the BSD file system);
8512 @command{cpio}s way requires you to play some games (in its "binary"
8513 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8514 they're 18 bits---it would have to play games with the "file system ID"
8515 field of the header to make sure that the file system ID/i-number pairs
8516 of different files were always different), and I don't know which
8517 @command{cpio}s, if any, play those games. Those that don't might get
8518 confused and think two files are the same file when they're not, and
8519 make hard links between them.
8520
8521 @command{tar}s way of handling multiple hard links to a file places only
8522 one copy of the link on the tape, but the name attached to that copy
8523 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8524 way puts one copy for every link, but you can retrieve it using any
8525 of the names.
8526
8527 @quotation
8528 What type of check sum (if any) is used, and how is this calculated.
8529 @end quotation
8530
8531 See the attached manual pages for @command{tar} and @command{cpio} format.
8532 @command{tar} uses a checksum which is the sum of all the bytes in the
8533 @command{tar} header for a file; @command{cpio} uses no checksum.
8534
8535 @quotation
8536 If anyone knows why @command{cpio} was made when @command{tar} was present
8537 at the unix scene,
8538 @end quotation
8539
8540 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8541 generally-available version of UNIX had @command{tar} at the time. I don't
8542 know whether any version that was generally available @emph{within AT&T}
8543 had @command{tar}, or, if so, whether the people within AT&T who did
8544 @command{cpio} knew about it.
8545
8546 On restore, if there is a corruption on a tape @command{tar} will stop at
8547 that point, while @command{cpio} will skip over it and try to restore the
8548 rest of the files.
8549
8550 The main difference is just in the command syntax and header format.
8551
8552 @command{tar} is a little more tape-oriented in that everything is blocked
8553 to start on a record boundary.
8554
8555 @quotation
8556 Is there any differences between the ability to recover crashed
8557 archives between the two of them. (Is there any chance of recovering
8558 crashed archives at all.)
8559 @end quotation
8560
8561 Theoretically it should be easier under @command{tar} since the blocking
8562 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8563 However, modern @command{cpio}'s and variations have an option to just
8564 search for the next file header after an error with a reasonable chance
8565 of resyncing. However, lots of tape driver software won't allow you to
8566 continue past a media error which should be the only reason for getting
8567 out of sync unless a file changed sizes while you were writing the
8568 archive.
8569
8570 @quotation
8571 If anyone knows why @command{cpio} was made when @command{tar} was present
8572 at the unix scene, please tell me about this too.
8573 @end quotation
8574
8575 Probably because it is more media efficient (by not blocking everything
8576 and using only the space needed for the headers where @command{tar}
8577 always uses 512 bytes per file header) and it knows how to archive
8578 special files.
8579
8580 You might want to look at the freely available alternatives. The
8581 major ones are @command{afio}, @GNUTAR{}, and
8582 @command{pax}, each of which have their own extensions with some
8583 backwards compatibility.
8584
8585 Sparse files were @command{tar}red as sparse files (which you can
8586 easily test, because the resulting archive gets smaller, and
8587 @acronym{GNU} @command{cpio} can no longer read it).
8588
8589 @node Media
8590 @chapter Tapes and Other Archive Media
8591 @UNREVISED
8592
8593 A few special cases about tape handling warrant more detailed
8594 description. These special cases are discussed below.
8595
8596 Many complexities surround the use of @command{tar} on tape drives. Since
8597 the creation and manipulation of archives located on magnetic tape was
8598 the original purpose of @command{tar}, it contains many features making
8599 such manipulation easier.
8600
8601 Archives are usually written on dismountable media---tape cartridges,
8602 mag tapes, or floppy disks.
8603
8604 The amount of data a tape or disk holds depends not only on its size,
8605 but also on how it is formatted. A 2400 foot long reel of mag tape
8606 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8607 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8608
8609 Magnetic media are re-usable---once the archive on a tape is no longer
8610 needed, the archive can be erased and the tape or disk used over.
8611 Media quality does deteriorate with use, however. Most tapes or disks
8612 should be discarded when they begin to produce data errors. EXABYTE
8613 tape cartridges should be discarded when they generate an @dfn{error
8614 count} (number of non-usable bits) of more than 10k.
8615
8616 Magnetic media are written and erased using magnetic fields, and
8617 should be protected from such fields to avoid damage to stored data.
8618 Sticking a floppy disk to a filing cabinet using a magnet is probably
8619 not a good idea.
8620
8621 @menu
8622 * Device:: Device selection and switching
8623 * Remote Tape Server::
8624 * Common Problems and Solutions::
8625 * Blocking:: Blocking
8626 * Many:: Many archives on one tape
8627 * Using Multiple Tapes:: Using Multiple Tapes
8628 * label:: Including a Label in the Archive
8629 * verify::
8630 * Write Protection::
8631 @end menu
8632
8633 @node Device
8634 @section Device Selection and Switching
8635 @UNREVISED
8636
8637 @table @option
8638 @item -f [@var{hostname}:]@var{file}
8639 @itemx --file=[@var{hostname}:]@var{file}
8640 Use archive file or device @var{file} on @var{hostname}.
8641 @end table
8642
8643 This option is used to specify the file name of the archive @command{tar}
8644 works on.
8645
8646 If the file name is @samp{-}, @command{tar} reads the archive from standard
8647 input (when listing or extracting), or writes it to standard output
8648 (when creating). If the @samp{-} file name is given when updating an
8649 archive, @command{tar} will read the original archive from its standard
8650 input, and will write the entire new archive to its standard output.
8651
8652 If the file name contains a @samp{:}, it is interpreted as
8653 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8654 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8655 either case, @command{tar} will invoke the command @command{rsh} (or
8656 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8657 machine. If you give an alternate login name, it will be given to the
8658 @command{rsh}.
8659 Naturally, the remote machine must have an executable
8660 @command{/usr/libexec/rmt}. This program is free software from the
8661 University of California, and a copy of the source code can be found
8662 with the sources for @command{tar}; it's compiled and installed by default.
8663 The exact path to this utility is determined when configuring the package.
8664 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8665 your installation prefix. This location may also be overridden at
8666 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8667 ---rmt-command}, for detailed description of this option. @xref{Remote
8668 Tape Server}, for the description of @command{rmt} command).
8669
8670 If this option is not given, but the environment variable @env{TAPE}
8671 is set, its value is used; otherwise, old versions of @command{tar}
8672 used a default archive name (which was picked when @command{tar} was
8673 compiled). The default is normally set up to be the @dfn{first} tape
8674 drive or other transportable I/O medium on the system.
8675
8676 Starting with version 1.11.5, @GNUTAR{} uses
8677 standard input and standard output as the default device, and I will
8678 not try anymore supporting automatic device detection at installation
8679 time. This was failing really in too many cases, it was hopeless.
8680 This is now completely left to the installer to override standard
8681 input and standard output for default device, if this seems
8682 preferable. Further, I think @emph{most} actual usages of
8683 @command{tar} are done with pipes or disks, not really tapes,
8684 cartridges or diskettes.
8685
8686 Some users think that using standard input and output is running
8687 after trouble. This could lead to a nasty surprise on your screen if
8688 you forget to specify an output file name---especially if you are going
8689 through a network or terminal server capable of buffering large amounts
8690 of output. We had so many bug reports in that area of configuring
8691 default tapes automatically, and so many contradicting requests, that
8692 we finally consider the problem to be portably intractable. We could
8693 of course use something like @samp{/dev/tape} as a default, but this
8694 is @emph{also} running after various kind of trouble, going from hung
8695 processes to accidental destruction of real tapes. After having seen
8696 all this mess, using standard input and output as a default really
8697 sounds like the only clean choice left, and a very useful one too.
8698
8699 @GNUTAR{} reads and writes archive in records, I
8700 suspect this is the main reason why block devices are preferred over
8701 character devices. Most probably, block devices are more efficient
8702 too. The installer could also check for @samp{DEFTAPE} in
8703 @file{<sys/mtio.h>}.
8704
8705 @table @option
8706 @opindex force-local, short description
8707 @item --force-local
8708 Archive file is local even if it contains a colon.
8709
8710 @opindex rsh-command
8711 @item --rsh-command=@var{command}
8712 Use remote @var{command} instead of @command{rsh}. This option exists
8713 so that people who use something other than the standard @command{rsh}
8714 (e.g., a Kerberized @command{rsh}) can access a remote device.
8715
8716 When this command is not used, the shell command found when
8717 the @command{tar} program was installed is used instead. This is
8718 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8719 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8720 The installer may have overridden this by defining the environment
8721 variable @env{RSH} @emph{at installation time}.
8722
8723 @item -[0-7][lmh]
8724 Specify drive and density.
8725
8726 @opindex multi-volume, short description
8727 @item -M
8728 @itemx --multi-volume
8729 Create/list/extract multi-volume archive.
8730
8731 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8732 that may be larger than will fit on the medium used to hold it.
8733 @xref{Multi-Volume Archives}.
8734
8735 @opindex tape-length, short description
8736 @item -L @var{num}
8737 @itemx --tape-length=@var{num}
8738 Change tape after writing @var{num} x 1024 bytes.
8739
8740 This option might be useful when your tape drivers do not properly
8741 detect end of physical tapes. By being slightly conservative on the
8742 maximum tape length, you might avoid the problem entirely.
8743
8744 @opindex info-script, short description
8745 @opindex new-volume-script, short description
8746 @item -F @var{file}
8747 @itemx --info-script=@var{file}
8748 @itemx --new-volume-script=@var{file}
8749 Execute @file{file} at end of each tape. This implies
8750 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8751 description of this option.
8752 @end table
8753
8754 @node Remote Tape Server
8755 @section The Remote Tape Server
8756
8757 @cindex remote tape drive
8758 @pindex rmt
8759 In order to access the tape drive on a remote machine, @command{tar}
8760 uses the remote tape server written at the University of California at
8761 Berkeley. The remote tape server must be installed as
8762 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8763 want to use. @command{tar} calls @command{rmt} by running an
8764 @command{rsh} or @command{remsh} to the remote machine, optionally
8765 using a different login name if one is supplied.
8766
8767 A copy of the source for the remote tape server is provided. It is
8768 Copyright @copyright{} 1983 by the Regents of the University of
8769 California, but can be freely distributed. It is compiled and
8770 installed by default.
8771
8772 @cindex absolute file names
8773 Unless you use the @option{--absolute-names} (@option{-P}) option,
8774 @GNUTAR{} will not allow you to create an archive that contains
8775 absolute file names (a file name beginning with @samp{/}.) If you try,
8776 @command{tar} will automatically remove the leading @samp{/} from the
8777 file names it stores in the archive. It will also type a warning
8778 message telling you what it is doing.
8779
8780 When reading an archive that was created with a different
8781 @command{tar} program, @GNUTAR{} automatically
8782 extracts entries in the archive which have absolute file names as if
8783 the file names were not absolute. This is an important feature. A
8784 visitor here once gave a @command{tar} tape to an operator to restore;
8785 the operator used Sun @command{tar} instead of @GNUTAR{},
8786 and the result was that it replaced large portions of
8787 our @file{/bin} and friends with versions from the tape; needless to
8788 say, we were unhappy about having to recover the file system from
8789 backup tapes.
8790
8791 For example, if the archive contained a file @file{/usr/bin/computoy},
8792 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8793 relative to the current directory. If you want to extract the files in
8794 an archive to the same absolute names that they had when the archive
8795 was created, you should do a @samp{cd /} before extracting the files
8796 from the archive, or you should either use the @option{--absolute-names}
8797 option, or use the command @samp{tar -C / @dots{}}.
8798
8799 @cindex Ultrix 3.1 and write failure
8800 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8801 can claim that a short write near the end of a tape succeeded,
8802 when it actually failed. This will result in the -M option not
8803 working correctly. The best workaround at the moment is to use a
8804 significantly larger blocking factor than the default 20.
8805
8806 In order to update an archive, @command{tar} must be able to backspace the
8807 archive in order to reread or rewrite a record that was just read (or
8808 written). This is currently possible only on two kinds of files: normal
8809 disk files (or any other file that can be backspaced with @samp{lseek}),
8810 and industry-standard 9-track magnetic tape (or any other kind of tape
8811 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8812
8813 This means that the @option{--append}, @option{--concatenate}, and
8814 @option{--delete} commands will not work on any other kind of file.
8815 Some media simply cannot be backspaced, which means these commands and
8816 options will never be able to work on them. These non-backspacing
8817 media include pipes and cartridge tape drives.
8818
8819 Some other media can be backspaced, and @command{tar} will work on them
8820 once @command{tar} is modified to do so.
8821
8822 Archives created with the @option{--multi-volume}, @option{--label}, and
8823 @option{--incremental} (@option{-G}) options may not be readable by other version
8824 of @command{tar}. In particular, restoring a file that was split over
8825 a volume boundary will require some careful work with @command{dd}, if
8826 it can be done at all. Other versions of @command{tar} may also create
8827 an empty file whose name is that of the volume header. Some versions
8828 of @command{tar} may create normal files instead of directories archived
8829 with the @option{--incremental} (@option{-G}) option.
8830
8831 @node Common Problems and Solutions
8832 @section Some Common Problems and their Solutions
8833
8834 @ifclear PUBLISH
8835
8836 @format
8837 errors from system:
8838 permission denied
8839 no such file or directory
8840 not owner
8841
8842 errors from @command{tar}:
8843 directory checksum error
8844 header format error
8845
8846 errors from media/system:
8847 i/o error
8848 device busy
8849 @end format
8850
8851 @end ifclear
8852
8853 @node Blocking
8854 @section Blocking
8855 @UNREVISED
8856
8857 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8858 is also confusing to the expert reader. On the other hand, readers
8859 who are new to the field have a fresh mind, and they may safely skip
8860 the next two paragraphs, as the remainder of this manual uses those
8861 two terms in a quite consistent way.
8862
8863 John Gilmore, the writer of the public domain @command{tar} from which
8864 @GNUTAR{} was originally derived, wrote (June 1995):
8865
8866 @quotation
8867 The nomenclature of tape drives comes from IBM, where I believe
8868 they were invented for the IBM 650 or so. On IBM mainframes, what
8869 is recorded on tape are tape blocks. The logical organization of
8870 data is into records. There are various ways of putting records into
8871 blocks, including @code{F} (fixed sized records), @code{V} (variable
8872 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8873 to a block), @code{VB} (variable size records, @var{n} to a block),
8874 @code{VSB} (variable spanned blocked: variable sized records that can
8875 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8876 parameter specified this to the operating system.
8877
8878 The Unix man page on @command{tar} was totally confused about this.
8879 When I wrote @code{PD TAR}, I used the historically correct terminology
8880 (@command{tar} writes data records, which are grouped into blocks).
8881 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8882 here), and now Fran@,{c}ois has migrated that terminology back
8883 into the source code too.
8884 @end quotation
8885
8886 The term @dfn{physical block} means the basic transfer chunk from or
8887 to a device, after which reading or writing may stop without anything
8888 being lost. In this manual, the term @dfn{block} usually refers to
8889 a disk physical block, @emph{assuming} that each disk block is 512
8890 bytes in length. It is true that some disk devices have different
8891 physical blocks, but @command{tar} ignore these differences in its own
8892 format, which is meant to be portable, so a @command{tar} block is always
8893 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8894 The term @dfn{logical block} often represents the basic chunk of
8895 allocation of many disk blocks as a single entity, which the operating
8896 system treats somewhat atomically; this concept is only barely used
8897 in @GNUTAR{}.
8898
8899 The term @dfn{physical record} is another way to speak of a physical
8900 block, those two terms are somewhat interchangeable. In this manual,
8901 the term @dfn{record} usually refers to a tape physical block,
8902 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8903 It is true that archives may be put on disk or used with pipes,
8904 but nevertheless, @command{tar} tries to read and write the archive one
8905 @dfn{record} at a time, whatever the medium in use. One record is made
8906 up of an integral number of blocks, and this operation of putting many
8907 disk blocks into a single tape block is called @dfn{reblocking}, or
8908 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8909 the logical organization of many characters into something meaningful
8910 to the application. The term @dfn{unit record} describes a small set
8911 of characters which are transmitted whole to or by the application,
8912 and often refers to a line of text. Those two last terms are unrelated
8913 to what we call a @dfn{record} in @GNUTAR{}.
8914
8915 When writing to tapes, @command{tar} writes the contents of the archive
8916 in chunks known as @dfn{records}. To change the default blocking
8917 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8918 @var{512-size}}) option. Each record will then be composed of
8919 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8920 @xref{Standard}.) Each file written to the archive uses at least one
8921 full record. As a result, using a larger record size can result in
8922 more wasted space for small files. On the other hand, a larger record
8923 size can often be read and written much more efficiently.
8924
8925 Further complicating the problem is that some tape drives ignore the
8926 blocking entirely. For these, a larger record size can still improve
8927 performance (because the software layers above the tape drive still
8928 honor the blocking), but not as dramatically as on tape drives that
8929 honor blocking.
8930
8931 When reading an archive, @command{tar} can usually figure out the
8932 record size on itself. When this is the case, and a non-standard
8933 record size was used when the archive was created, @command{tar} will
8934 print a message about a non-standard blocking factor, and then operate
8935 normally. On some tape devices, however, @command{tar} cannot figure
8936 out the record size itself. On most of those, you can specify a
8937 blocking factor (with @option{--blocking-factor}) larger than the
8938 actual blocking factor, and then use the @option{--read-full-records}
8939 (@option{-B}) option. (If you specify a blocking factor with
8940 @option{--blocking-factor} and don't use the
8941 @option{--read-full-records} option, then @command{tar} will not
8942 attempt to figure out the recording size itself.) On some devices,
8943 you must always specify the record size exactly with
8944 @option{--blocking-factor} when reading, because @command{tar} cannot
8945 figure it out. In any case, use @option{--list} (@option{-t}) before
8946 doing any extractions to see whether @command{tar} is reading the archive
8947 correctly.
8948
8949 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
8950 putting them into records is to put a whole number of them (one or
8951 more) into each record. @command{tar} records are all the same size;
8952 at the end of the file there's a block containing all zeros, which
8953 is how you tell that the remainder of the last record(s) are garbage.
8954
8955 In a standard @command{tar} file (no options), the block size is 512
8956 and the record size is 10240, for a blocking factor of 20. What the
8957 @option{--blocking-factor} option does is sets the blocking factor,
8958 changing the record size while leaving the block size at 512 bytes.
8959 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
8960 most tape drives these days prefer much bigger records in order to
8961 stream and not waste tape. When writing tapes for myself, some tend
8962 to use a factor of the order of 2048, say, giving a record size of
8963 around one megabyte.
8964
8965 If you use a blocking factor larger than 20, older @command{tar}
8966 programs might not be able to read the archive, so we recommend this
8967 as a limit to use in practice. @GNUTAR{}, however,
8968 will support arbitrarily large record sizes, limited only by the
8969 amount of virtual memory or the physical characteristics of the tape
8970 device.
8971
8972 @menu
8973 * Format Variations:: Format Variations
8974 * Blocking Factor:: The Blocking Factor of an Archive
8975 @end menu
8976
8977 @node Format Variations
8978 @subsection Format Variations
8979 @cindex Format Parameters
8980 @cindex Format Options
8981 @cindex Options, archive format specifying
8982 @cindex Options, format specifying
8983 @UNREVISED
8984
8985 Format parameters specify how an archive is written on the archive
8986 media. The best choice of format parameters will vary depending on
8987 the type and number of files being archived, and on the media used to
8988 store the archive.
8989
8990 To specify format parameters when accessing or creating an archive,
8991 you can use the options described in the following sections.
8992 If you do not specify any format parameters, @command{tar} uses
8993 default parameters. You cannot modify a compressed archive.
8994 If you create an archive with the @option{--blocking-factor} option
8995 specified (@pxref{Blocking Factor}), you must specify that
8996 blocking-factor when operating on the archive. @xref{Formats}, for other
8997 examples of format parameter considerations.
8998
8999 @node Blocking Factor
9000 @subsection The Blocking Factor of an Archive
9001 @cindex Blocking Factor
9002 @cindex Record Size
9003 @cindex Number of blocks per record
9004 @cindex Number of bytes per record
9005 @cindex Bytes per record
9006 @cindex Blocks per record
9007 @UNREVISED
9008
9009 @opindex blocking-factor
9010 The data in an archive is grouped into blocks, which are 512 bytes.
9011 Blocks are read and written in whole number multiples called
9012 @dfn{records}. The number of blocks in a record (ie. the size of a
9013 record in units of 512 bytes) is called the @dfn{blocking factor}.
9014 The @option{--blocking-factor=@var{512-size}} (@option{-b
9015 @var{512-size}}) option specifies the blocking factor of an archive.
9016 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9017 can be specified at installation. To find out the blocking factor of
9018 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9019 This may not work on some devices.
9020
9021 Records are separated by gaps, which waste space on the archive media.
9022 If you are archiving on magnetic tape, using a larger blocking factor
9023 (and therefore larger records) provides faster throughput and allows you
9024 to fit more data on a tape (because there are fewer gaps). If you are
9025 archiving on cartridge, a very large blocking factor (say 126 or more)
9026 greatly increases performance. A smaller blocking factor, on the other
9027 hand, may be useful when archiving small files, to avoid archiving lots
9028 of nulls as @command{tar} fills out the archive to the end of the record.
9029 In general, the ideal record size depends on the size of the
9030 inter-record gaps on the tape you are using, and the average size of the
9031 files you are archiving. @xref{create}, for information on
9032 writing archives.
9033
9034 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9035
9036 Archives with blocking factors larger than 20 cannot be read
9037 by very old versions of @command{tar}, or by some newer versions
9038 of @command{tar} running on old machines with small address spaces.
9039 With @GNUTAR{}, the blocking factor of an archive is limited
9040 only by the maximum record size of the device containing the archive,
9041 or by the amount of available virtual memory.
9042
9043 Also, on some systems, not using adequate blocking factors, as sometimes
9044 imposed by the device drivers, may yield unexpected diagnostics. For
9045 example, this has been reported:
9046
9047 @smallexample
9048 Cannot write to /dev/dlt: Invalid argument
9049 @end smallexample
9050
9051 @noindent
9052 In such cases, it sometimes happen that the @command{tar} bundled by
9053 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9054 requires an explicit specification for the block size,
9055 which it cannot guess. This yields some people to consider
9056 @GNUTAR{} is misbehaving, because by comparison,
9057 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9058 for example, might resolve the problem.
9059
9060 If you use a non-default blocking factor when you create an archive, you
9061 must specify the same blocking factor when you modify that archive. Some
9062 archive devices will also require you to specify the blocking factor when
9063 reading that archive, however this is not typically the case. Usually, you
9064 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9065 reports a non-default record size and then lists the archive members as
9066 it would normally. To extract files from an archive with a non-standard
9067 blocking factor (particularly if you're not sure what the blocking factor
9068 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9069 specifying a blocking factor larger then the blocking factor of the archive
9070 (ie. @samp{tar --extract --read-full-records --blocking-factor=300}.
9071 @xref{list}, for more information on the @option{--list} (@option{-t})
9072 operation. @xref{Reading}, for a more detailed explanation of that option.
9073
9074 @table @option
9075 @item --blocking-factor=@var{number}
9076 @itemx -b @var{number}
9077 Specifies the blocking factor of an archive. Can be used with any
9078 operation, but is usually not necessary with @option{--list} (@option{-t}).
9079 @end table
9080
9081 Device blocking
9082
9083 @table @option
9084 @item -b @var{blocks}
9085 @itemx --blocking-factor=@var{blocks}
9086 Set record size to @math{@var{blocks} * 512} bytes.
9087
9088 This option is used to specify a @dfn{blocking factor} for the archive.
9089 When reading or writing the archive, @command{tar}, will do reads and writes
9090 of the archive in records of @math{@var{block}*512} bytes. This is true
9091 even when the archive is compressed. Some devices requires that all
9092 write operations be a multiple of a certain size, and so, @command{tar}
9093 pads the archive out to the next record boundary.
9094
9095 The default blocking factor is set when @command{tar} is compiled, and is
9096 typically 20. Blocking factors larger than 20 cannot be read by very
9097 old versions of @command{tar}, or by some newer versions of @command{tar}
9098 running on old machines with small address spaces.
9099
9100 With a magnetic tape, larger records give faster throughput and fit
9101 more data on a tape (because there are fewer inter-record gaps).
9102 If the archive is in a disk file or a pipe, you may want to specify
9103 a smaller blocking factor, since a large one will result in a large
9104 number of null bytes at the end of the archive.
9105
9106 When writing cartridge or other streaming tapes, a much larger
9107 blocking factor (say 126 or more) will greatly increase performance.
9108 However, you must specify the same blocking factor when reading or
9109 updating the archive.
9110
9111 Apparently, Exabyte drives have a physical block size of 8K bytes.
9112 If we choose our blocksize as a multiple of 8k bytes, then the problem
9113 seems to disappear. Id est, we are using block size of 112 right
9114 now, and we haven't had the problem since we switched@dots{}
9115
9116 With @GNUTAR{} the blocking factor is limited only
9117 by the maximum record size of the device containing the archive, or by
9118 the amount of available virtual memory.
9119
9120 However, deblocking or reblocking is virtually avoided in a special
9121 case which often occurs in practice, but which requires all the
9122 following conditions to be simultaneously true:
9123 @itemize @bullet
9124 @item
9125 the archive is subject to a compression option,
9126 @item
9127 the archive is not handled through standard input or output, nor
9128 redirected nor piped,
9129 @item
9130 the archive is directly handled to a local disk, instead of any special
9131 device,
9132 @item
9133 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9134 invocation.
9135 @end itemize
9136
9137 If the output goes directly to a local disk, and not through
9138 stdout, then the last write is not extended to a full record size.
9139 Otherwise, reblocking occurs. Here are a few other remarks on this
9140 topic:
9141
9142 @itemize @bullet
9143
9144 @item
9145 @command{gzip} will complain about trailing garbage if asked to
9146 uncompress a compressed archive on tape, there is an option to turn
9147 the message off, but it breaks the regularity of simply having to use
9148 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9149 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9150 Gailly, by sending a copy of this message to him.
9151
9152 @item
9153 @command{compress} does not show this problem, but as Jean-loup pointed
9154 out to Michael, @samp{compress -d} silently adds garbage after
9155 the result of decompression, which tar ignores because it already
9156 recognized its end-of-file indicator. So this bug may be safely
9157 ignored.
9158
9159 @item
9160 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9161 but will still return an exit status of 2 which tar reports in turn.
9162 @command{tar} might ignore the exit status returned, but I hate doing
9163 that, as it weakens the protection @command{tar} offers users against
9164 other possible problems at decompression time. If @command{gzip} was
9165 silently skipping trailing zeros @emph{and} also avoiding setting the
9166 exit status in this innocuous case, that would solve this situation.
9167
9168 @item
9169 @command{tar} should become more solid at not stopping to read a pipe at
9170 the first null block encountered. This inelegantly breaks the pipe.
9171 @command{tar} should rather drain the pipe out before exiting itself.
9172 @end itemize
9173
9174 @opindex ignore-zeros, short description
9175 @item -i
9176 @itemx --ignore-zeros
9177 Ignore blocks of zeros in archive (means EOF).
9178
9179 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9180 of zeros in the archive. Normally a block of zeros indicates the
9181 end of the archive, but when reading a damaged archive, or one which
9182 was created by concatenating several archives together, this option
9183 allows @command{tar} to read the entire archive. This option is not on
9184 by default because many versions of @command{tar} write garbage after
9185 the zeroed blocks.
9186
9187 Note that this option causes @command{tar} to read to the end of the
9188 archive file, which may sometimes avoid problems when multiple files
9189 are stored on a single physical tape.
9190
9191 @opindex read-full-records, short description
9192 @item -B
9193 @itemx --read-full-records
9194 Reblock as we read (for reading 4.2BSD pipes).
9195
9196 If @option{--read-full-records} is used, @command{tar}
9197 will not panic if an attempt to read a record from the archive does
9198 not return a full record. Instead, @command{tar} will keep reading
9199 until it has obtained a full
9200 record.
9201
9202 This option is turned on by default when @command{tar} is reading
9203 an archive from standard input, or from a remote machine. This is
9204 because on BSD Unix systems, a read of a pipe will return however
9205 much happens to be in the pipe, even if it is less than @command{tar}
9206 requested. If this option was not used, @command{tar} would fail as
9207 soon as it read an incomplete record from the pipe.
9208
9209 This option is also useful with the commands for updating an archive.
9210
9211 @end table
9212
9213 Tape blocking
9214
9215 @FIXME{Appropriate options should be moved here from elsewhere.}
9216
9217 @cindex blocking factor
9218 @cindex tape blocking
9219
9220 When handling various tapes or cartridges, you have to take care of
9221 selecting a proper blocking, that is, the number of disk blocks you
9222 put together as a single tape block on the tape, without intervening
9223 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9224 with no information on it, used for decelerating the tape to a
9225 full stop, and for later regaining the reading or writing speed.
9226 When the tape driver starts reading a record, the record has to
9227 be read whole without stopping, as a tape gap is needed to stop the
9228 tape motion without loosing information.
9229
9230 @cindex Exabyte blocking
9231 @cindex DAT blocking
9232 Using higher blocking (putting more disk blocks per tape block) will use
9233 the tape more efficiently as there will be less tape gaps. But reading
9234 such tapes may be more difficult for the system, as more memory will be
9235 required to receive at once the whole record. Further, if there is a
9236 reading error on a huge record, this is less likely that the system will
9237 succeed in recovering the information. So, blocking should not be too
9238 low, nor it should be too high. @command{tar} uses by default a blocking of
9239 20 for historical reasons, and it does not really matter when reading or
9240 writing to disk. Current tape technology would easily accommodate higher
9241 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9242 We were told that for some DLT drives, the blocking should be a multiple
9243 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9244 Other manufacturers may use different recommendations for the same tapes.
9245 This might also depends of the buffering techniques used inside modern
9246 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9247 Others request blocking to be some exponent of two.
9248
9249 So, there is no fixed rule for blocking. But blocking at read time
9250 should ideally be the same as blocking used at write time. At one place
9251 I know, with a wide variety of equipment, they found it best to use a
9252 blocking of 32 to guarantee that their tapes are fully interchangeable.
9253
9254 I was also told that, for recycled tapes, prior erasure (by the same
9255 drive unit that will be used to create the archives) sometimes lowers
9256 the error rates observed at rewriting time.
9257
9258 I might also use @option{--number-blocks} instead of
9259 @option{--block-number}, so @option{--block} will then expand to
9260 @option{--blocking-factor} unambiguously.
9261
9262 @node Many
9263 @section Many Archives on One Tape
9264
9265 @FIXME{Appropriate options should be moved here from elsewhere.}
9266
9267 @findex ntape @r{device}
9268 Most tape devices have two entries in the @file{/dev} directory, or
9269 entries that come in pairs, which differ only in the minor number for
9270 this device. Let's take for example @file{/dev/tape}, which often
9271 points to the only or usual tape device of a given system. There might
9272 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9273 name is the @emph{rewinding} version of the device, while the name
9274 having @samp{nr} in it is the @emph{no rewinding} version of the same
9275 device.
9276
9277 A rewinding tape device will bring back the tape to its beginning point
9278 automatically when this device is opened or closed. Since @command{tar}
9279 opens the archive file before using it and closes it afterwards, this
9280 means that a simple:
9281
9282 @smallexample
9283 $ @kbd{tar cf /dev/tape @var{directory}}
9284 @end smallexample
9285
9286 @noindent
9287 will reposition the tape to its beginning both prior and after saving
9288 @var{directory} contents to it, thus erasing prior tape contents and
9289 making it so that any subsequent write operation will destroy what has
9290 just been saved.
9291
9292 @cindex tape positioning
9293 So, a rewinding device is normally meant to hold one and only one file.
9294 If you want to put more than one @command{tar} archive on a given tape, you
9295 will need to avoid using the rewinding version of the tape device. You
9296 will also have to pay special attention to tape positioning. Errors in
9297 positioning may overwrite the valuable data already on your tape. Many
9298 people, burnt by past experiences, will only use rewinding devices and
9299 limit themselves to one file per tape, precisely to avoid the risk of
9300 such errors. Be fully aware that writing at the wrong position on a
9301 tape loses all information past this point and most probably until the
9302 end of the tape, and this destroyed information @emph{cannot} be
9303 recovered.
9304
9305 To save @var{directory-1} as a first archive at the beginning of a
9306 tape, and leave that tape ready for a second archive, you should use:
9307
9308 @smallexample
9309 $ @kbd{mt -f /dev/nrtape rewind}
9310 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9311 @end smallexample
9312
9313 @cindex tape marks
9314 @dfn{Tape marks} are special magnetic patterns written on the tape
9315 media, which are later recognizable by the reading hardware. These
9316 marks are used after each file, when there are many on a single tape.
9317 An empty file (that is to say, two tape marks in a row) signal the
9318 logical end of the tape, after which no file exist. Usually,
9319 non-rewinding tape device drivers will react to the close request issued
9320 by @command{tar} by first writing two tape marks after your archive, and by
9321 backspacing over one of these. So, if you remove the tape at that time
9322 from the tape drive, it is properly terminated. But if you write
9323 another file at the current position, the second tape mark will be
9324 erased by the new information, leaving only one tape mark between files.
9325
9326 So, you may now save @var{directory-2} as a second archive after the
9327 first on the same tape by issuing the command:
9328
9329 @smallexample
9330 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9331 @end smallexample
9332
9333 @noindent
9334 and so on for all the archives you want to put on the same tape.
9335
9336 Another usual case is that you do not write all the archives the same
9337 day, and you need to remove and store the tape between two archive
9338 sessions. In general, you must remember how many files are already
9339 saved on your tape. Suppose your tape already has 16 files on it, and
9340 that you are ready to write the 17th. You have to take care of skipping
9341 the first 16 tape marks before saving @var{directory-17}, say, by using
9342 these commands:
9343
9344 @smallexample
9345 $ @kbd{mt -f /dev/nrtape rewind}
9346 $ @kbd{mt -f /dev/nrtape fsf 16}
9347 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9348 @end smallexample
9349
9350 In all the previous examples, we put aside blocking considerations, but
9351 you should do the proper things for that as well. @xref{Blocking}.
9352
9353 @menu
9354 * Tape Positioning:: Tape Positions and Tape Marks
9355 * mt:: The @command{mt} Utility
9356 @end menu
9357
9358 @node Tape Positioning
9359 @subsection Tape Positions and Tape Marks
9360 @UNREVISED
9361
9362 Just as archives can store more than one file from the file system,
9363 tapes can store more than one archive file. To keep track of where
9364 archive files (or any other type of file stored on tape) begin and
9365 end, tape archive devices write magnetic @dfn{tape marks} on the
9366 archive media. Tape drives write one tape mark between files,
9367 two at the end of all the file entries.
9368
9369 If you think of data as a series of records "rrrr"'s, and tape marks as
9370 "*"'s, a tape might look like the following:
9371
9372 @smallexample
9373 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9374 @end smallexample
9375
9376 Tape devices read and write tapes using a read/write @dfn{tape
9377 head}---a physical part of the device which can only access one
9378 point on the tape at a time. When you use @command{tar} to read or
9379 write archive data from a tape device, the device will begin reading
9380 or writing from wherever on the tape the tape head happens to be,
9381 regardless of which archive or what part of the archive the tape
9382 head is on. Before writing an archive, you should make sure that no
9383 data on the tape will be overwritten (unless it is no longer needed).
9384 Before reading an archive, you should make sure the tape head is at
9385 the beginning of the archive you want to read. You can do it manually
9386 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9387 that automatically (@pxref{Scripted Restoration}).
9388
9389 If you want to add new archive file entries to a tape, you should
9390 advance the tape to the end of the existing file entries, backspace
9391 over the last tape mark, and write the new archive file. If you were
9392 to add two archives to the example above, the tape might look like the
9393 following:
9394
9395 @smallexample
9396 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9397 @end smallexample
9398
9399 @node mt
9400 @subsection The @command{mt} Utility
9401 @UNREVISED
9402
9403 @FIXME{Is it true that this only works on non-block devices?
9404 should explain the difference, (fixed or variable).}
9405 @xref{Blocking Factor}.
9406
9407 You can use the @command{mt} utility to advance or rewind a tape past a
9408 specified number of archive files on the tape. This will allow you
9409 to move to the beginning of an archive before extracting or reading
9410 it, or to the end of all the archives before writing a new one.
9411 @FIXME{Why isn't there an "advance 'til you find two tape marks
9412 together"?}
9413
9414 The syntax of the @command{mt} command is:
9415
9416 @smallexample
9417 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9418 @end smallexample
9419
9420 where @var{tapename} is the name of the tape device, @var{number} is
9421 the number of times an operation is performed (with a default of one),
9422 and @var{operation} is one of the following:
9423
9424 @FIXME{is there any use for record operations?}
9425
9426 @table @option
9427 @item eof
9428 @itemx weof
9429 Writes @var{number} tape marks at the current position on the tape.
9430
9431 @item fsf
9432 Moves tape position forward @var{number} files.
9433
9434 @item bsf
9435 Moves tape position back @var{number} files.
9436
9437 @item rewind
9438 Rewinds the tape. (Ignores @var{number}).
9439
9440 @item offline
9441 @itemx rewoff1
9442 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9443
9444 @item status
9445 Prints status information about the tape unit.
9446
9447 @end table
9448
9449 @FIXME{Is there a better way to frob the spacing on the list?}
9450
9451 If you don't specify a @var{tapename}, @command{mt} uses the environment
9452 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9453 the default device specified in your @file{sys/mtio.h} file
9454 (@code{DEFTAPE} variable). If this is not defined, the program will
9455 display a descriptive error message and exit with code 1.
9456
9457 @command{mt} returns a 0 exit status when the operation(s) were
9458 successful, 1 if the command was unrecognized, and 2 if an operation
9459 failed.
9460
9461 @node Using Multiple Tapes
9462 @section Using Multiple Tapes
9463 @UNREVISED
9464
9465 Often you might want to write a large archive, one larger than will fit
9466 on the actual tape you are using. In such a case, you can run multiple
9467 @command{tar} commands, but this can be inconvenient, particularly if you
9468 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9469 Therefore, @command{tar} supports multiple tapes automatically.
9470
9471 Use @option{--multi-volume} (@option{-M}) on the command line, and
9472 then @command{tar} will, when it reaches the end of the tape, prompt
9473 for another tape, and continue the archive. Each tape will have an
9474 independent archive, and can be read without needing the other. (As
9475 an exception to this, the file that @command{tar} was archiving when
9476 it ran out of tape will usually be split between the two archives; in
9477 this case you need to extract from the first archive, using
9478 @option{--multi-volume}, and then put in the second tape when
9479 prompted, so @command{tar} can restore both halves of the file.)
9480
9481 @GNUTAR{} multi-volume archives do not use a truly portable format.
9482 You need @GNUTAR{} at both ends to process them properly.
9483
9484 When prompting for a new tape, @command{tar} accepts any of the following
9485 responses:
9486
9487 @table @kbd
9488 @item ?
9489 Request @command{tar} to explain possible responses
9490 @item q
9491 Request @command{tar} to exit immediately.
9492 @item n @var{file-name}
9493 Request @command{tar} to write the next volume on the file @var{file-name}.
9494 @item !
9495 Request @command{tar} to run a subshell. This option can be disabled
9496 by giving @option{--restrict} command line option to @command{tar}.
9497 @item y
9498 Request @command{tar} to begin writing the next volume.
9499 @end table
9500
9501 (You should only type @samp{y} after you have changed the tape;
9502 otherwise @command{tar} will write over the volume it just finished.)
9503
9504 @cindex End-of-archive info script
9505 @cindex Info script
9506 @anchor{info-script}
9507 @opindex info-script
9508 @opindex new-volume-script
9509 If you want more elaborate behavior than this, give @command{tar} the
9510 @option{--info-script=@var{script-name}}
9511 (@option{--new-volume-script=@var{script-name}}, @option{-F
9512 @var{script-name}}) option. The file @var{script-name} is expected to
9513 be a program (or shell script) to be run instead of the normal
9514 prompting procedure. It is executed without any command line
9515 arguments. Additional data is passed to it via the following
9516 environment variables:
9517
9518 @table @env
9519 @vrindex TAR_VERSION, info script environment variable
9520 @item TAR_VERSION
9521 @GNUTAR{} version number.
9522
9523 @vrindex TAR_ARCHIVE, info script environment variable
9524 @item TAR_ARCHIVE
9525 The name of the archive @command{tar} is processing.
9526
9527 @vrindex TAR_VOLUME, info script environment variable
9528 @item TAR_VOLUME
9529 Ordinal number of the volume @command{tar} is about to start.
9530
9531 @vrindex TAR_SUBCOMMAND, info script environment variable
9532 @item TAR_SUBCOMMAND
9533 Short option describing the operation @command{tar} is executing
9534 @xref{Operations}, for a complete list of subcommand options.
9535
9536 @vrindex TAR_FORMAT, info script environment variable
9537 @item TAR_FORMAT
9538 Format of the archive being processed. @xref{Formats}, for a complete
9539 list of archive format names.
9540 @end table
9541
9542 The info script can instruct @command{tar} to use new archive name,
9543 by writing in to file descriptor 3 (see below for an
9544 example).
9545
9546 If the info script fails, @command{tar} exits; otherwise, it begins
9547 writing the next volume.
9548
9549 The method @command{tar} uses to detect end of tape is not perfect, and
9550 fails on some operating systems or on some devices. You can use the
9551 @option{--tape-length=@var{size}} (@option{-L @var{size}}) option if
9552 @command{tar} can't detect the end of the tape itself. This option
9553 selects @option{--multi-volume} (@option{-M}) automatically. The
9554 @var{size} argument should then be the usable size of the tape in
9555 units of 1024 bytes. But for many devices, and floppy disks in
9556 particular, this option is never required for real, as far as we know.
9557
9558 @cindex Volume number file
9559 @cindex volno file
9560 @anchor{volno-file}
9561 @opindex volno-file
9562 The volume number used by @command{tar} in its tape-change prompt
9563 can be changed; if you give the
9564 @option{--volno-file=@var{file-of-number}} option, then
9565 @var{file-of-number} should be an unexisting file to be created, or
9566 else, a file already containing a decimal number. That number will be
9567 used as the volume number of the first volume written. When
9568 @command{tar} is finished, it will rewrite the file with the
9569 now-current volume number. (This does not change the volume number
9570 written on a tape label, as per @ref{label}, it @emph{only} affects
9571 the number used in the prompt.)
9572
9573 If you want @command{tar} to cycle through a series of files or tape
9574 drives, there are three approaches to choose from. First of all, you
9575 can give @command{tar} multiple @option{--file} options. In this case
9576 the specified files will be used, in sequence, as the successive
9577 volumes of the archive. Only when the first one in the sequence needs
9578 to be used again will @command{tar} prompt for a tape change (or run
9579 the info script). Secondly, you can use the @samp{n} response to the
9580 tape-change prompt, and, finally, you can use an info script, that
9581 writes new archive name to file descriptor. The following example
9582 illustrates this approach:
9583
9584 @smallexample
9585 @group
9586 #! /bin/sh
9587 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9588
9589 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9590 case $TAR_SUBCOMMAND in
9591 -c) ;;
9592 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9593 ;;
9594 *) exit 1
9595 esac
9596
9597 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9598 @end group
9599 @end smallexample
9600
9601 Each volume of a multi-volume archive is an independent @command{tar}
9602 archive, complete in itself. For example, you can list or extract any
9603 volume alone; just don't specify @option{--multi-volume}
9604 (@option{-M}). However, if one file in the archive is split across
9605 volumes, the only way to extract it successfully is with a
9606 multi-volume extract command @option{--extract --multi-volume}
9607 (@option{-xM}) starting on or before the volume where the file begins.
9608
9609 For example, let's presume someone has two tape drives on a system
9610 named @file{/dev/tape0} and @file{/dev/tape1}. For having @GNUTAR{}
9611 to switch to the second drive when it needs to write the
9612 second tape, and then back to the first tape, etc., just do either of:
9613
9614 @smallexample
9615 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9616 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9617 @end smallexample
9618
9619 @menu
9620 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9621 * Tape Files:: Tape Files
9622 * Tarcat:: Concatenate Volumes into a Single Archive
9623
9624 @end menu
9625
9626 @node Multi-Volume Archives
9627 @subsection Archives Longer than One Tape or Disk
9628 @cindex Multi-volume archives
9629 @UNREVISED
9630
9631 @opindex multi-volume
9632 To create an archive that is larger than will fit on a single unit of
9633 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9634 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9635 archive can be manipulated like any other archive (provided the
9636 @option{--multi-volume} option is specified), but is stored on more
9637 than one tape or disk.
9638
9639 When you specify @option{--multi-volume}, @command{tar} does not report an
9640 error when it comes to the end of an archive volume (when reading), or
9641 the end of the media (when writing). Instead, it prompts you to load
9642 a new storage volume. If the archive is on a magnetic tape, you
9643 should change tapes when you see the prompt; if the archive is on a
9644 floppy disk, you should change disks; etc.
9645
9646 You can read each individual volume of a multi-volume archive as if it
9647 were an archive by itself. For example, to list the contents of one
9648 volume, use @option{--list}, without @option{--multi-volume} specified.
9649 To extract an archive member from one volume (assuming it is described
9650 that volume), use @option{--extract}, again without
9651 @option{--multi-volume}.
9652
9653 If an archive member is split across volumes (ie. its entry begins on
9654 one volume of the media and ends on another), you need to specify
9655 @option{--multi-volume} to extract it successfully. In this case, you
9656 should load the volume where the archive member starts, and use
9657 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9658 volumes as it needs them. @xref{extracting archives}, for more
9659 information about extracting archives.
9660
9661 @option{--info-script=@var{script-name}}
9662 (@option{--new-volume-script=@var{script-name}}, @option{-F
9663 @var{script-name}}) (@pxref{info-script}) is like
9664 @option{--multi-volume} (@option{-M}), except that @command{tar} does
9665 not prompt you directly to change media volumes when a volume is
9666 full---instead, @command{tar} runs commands you have stored in
9667 @var{script-name}. For example, this option can be used to eject
9668 cassettes, or to broadcast messages such as @samp{Someone please come
9669 change my tape} when performing unattended backups. When
9670 @var{script-name} is done, @command{tar} will assume that the media
9671 has been changed.
9672
9673 Multi-volume archives can be modified like any other archive. To add
9674 files to a multi-volume archive, you need to only mount the last
9675 volume of the archive media (and new volumes, if needed). For all
9676 other operations, you need to use the entire archive.
9677
9678 If a multi-volume archive was labeled using
9679 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9680 (@pxref{label}) when it was created, @command{tar} will not
9681 automatically label volumes which are added later. To label
9682 subsequent volumes, specify @option{--label=@var{archive-label}} again
9683 in conjunction with the @option{--append}, @option{--update} or
9684 @option{--concatenate} operation.
9685
9686 @cindex Labeling multi-volume archives
9687 @FIXME{example}
9688
9689 @FIXME{There should be a sample program here, including an exit
9690 before end. Is the exit status even checked in tar? :-(}
9691
9692 @table @option
9693 @item --multi-volume
9694 @itemx -M
9695 Creates a multi-volume archive, when used in conjunction with
9696 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9697 archive, specify @option{--multi-volume} in conjunction with that
9698 operation.
9699
9700 @item --info-script=@var{program-file}
9701 @itemx --new-volume-script=@var{program-file}
9702 @itemx -F @var{program-file}
9703 Creates a multi-volume archive via a script. Used in conjunction with
9704 @option{--create} (@option{-c}). @xref{info-script}, dor a detailed discussion.
9705 @end table
9706
9707 Beware that there is @emph{no} real standard about the proper way, for
9708 a @command{tar} archive, to span volume boundaries. If you have a
9709 multi-volume created by some vendor's @command{tar}, there is almost
9710 no chance you could read all the volumes with @GNUTAR{}.
9711 The converse is also true: you may not expect
9712 multi-volume archives created by @GNUTAR{} to be
9713 fully recovered by vendor's @command{tar}. Since there is little
9714 chance that, in mixed system configurations, some vendor's
9715 @command{tar} will work on another vendor's machine, and there is a
9716 great chance that @GNUTAR{} will work on most of
9717 them, your best bet is to install @GNUTAR{} on all
9718 machines between which you know exchange of files is possible.
9719
9720 @node Tape Files
9721 @subsection Tape Files
9722 @UNREVISED
9723
9724 To give the archive a name which will be recorded in it, use the
9725 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9726 option. This will write a special block identifying
9727 @var{volume-label} as the name of the archive to the front of the
9728 archive which will be displayed when the archive is listed with
9729 @option{--list}. If you are creating a multi-volume archive with
9730 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9731 volume label will have @samp{Volume @var{nnn}} appended to the name
9732 you give, where @var{nnn} is the number of the volume of the archive.
9733 (If you use the @option{--label=@var{volume-label}}) option when
9734 reading an archive, it checks to make sure the label on the tape
9735 matches the one you give. @xref{label}.
9736
9737 When @command{tar} writes an archive to tape, it creates a single
9738 tape file. If multiple archives are written to the same tape, one
9739 after the other, they each get written as separate tape files. When
9740 extracting, it is necessary to position the tape at the right place
9741 before running @command{tar}. To do this, use the @command{mt} command.
9742 For more information on the @command{mt} command and on the organization
9743 of tapes into a sequence of tape files, see @ref{mt}.
9744
9745 People seem to often do:
9746
9747 @smallexample
9748 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9749 @end smallexample
9750
9751 or such, for pushing a common date in all volumes or an archive set.
9752
9753 @node Tarcat
9754 @subsection Concatenate Volumes into a Single Archive
9755
9756 @pindex tarcat
9757 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9758 archive to a single @command{tar} archive. Simply concatenating all
9759 volumes into one will not work, since each volume carries an additional
9760 information at the beginning. @GNUTAR{} is shipped with the shell
9761 script @command{tarcat} designed for this purpose.
9762
9763 The script takes a list of files comprising a multi-volume archive
9764 and creates the resulting archive at the standard output. For example:
9765
9766 @smallexample
9767 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9768 @end smallexample
9769
9770 The script implements a simple heuristics to determine the format of
9771 the first volume file and to decide how to process the rest of the
9772 files. However, it makes no attempt to verify whether the files are
9773 given in order or even if they are valid @command{tar} archives.
9774 It uses @command{dd} and does not filter its standard error, so you
9775 will usually see lots of spurious messages.
9776
9777 @FIXME{The script is not installed. Should we install it?}
9778
9779 @node label
9780 @section Including a Label in the Archive
9781 @cindex Labeling an archive
9782 @cindex Labels on the archive media
9783 @UNREVISED
9784
9785 @opindex label
9786 To avoid problems caused by misplaced paper labels on the archive
9787 media, you can include a @dfn{label} entry---an archive member which
9788 contains the name of the archive---in the archive itself. Use the
9789 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9790 option in conjunction with the @option{--create} operation to include
9791 a label entry in the archive as it is being created.
9792
9793 @table @option
9794 @item --label=@var{archive-label}
9795 @itemx -V @var{archive-label}
9796 Includes an @dfn{archive-label} at the beginning of the archive when
9797 the archive is being created, when used in conjunction with the
9798 @option{--create} operation. Checks to make sure the archive label
9799 matches the one specified (when used in conjunction with any other
9800 operation.
9801 @end table
9802
9803 If you create an archive using both
9804 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9805 and @option{--multi-volume} (@option{-M}), each volume of the archive
9806 will have an archive label of the form @samp{@var{archive-label}
9807 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9808 next, and so on. @xref{Using Multiple Tapes}, for information on
9809 creating multiple volume archives.
9810
9811 @cindex Volume label, listing
9812 @cindex Listing volume label
9813 The volume label will be displayed by @option{--list} along with
9814 the file contents. If verbose display is requested, it will also be
9815 explicitely marked as in the example below:
9816
9817 @smallexample
9818 @group
9819 $ @kbd{tar --verbose --list --file=iamanarchive}
9820 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9821 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9822 @end group
9823 @end smallexample
9824
9825 @opindex test-label
9826 @anchor{--test-label option}
9827 However, @option{--list} option will cause listing entire
9828 contents of the archive, which may be undesirable (for example, if the
9829 archive is stored on a tape). You can request checking only the volume
9830 by specifying @option{--test-label} option. This option reads only the
9831 first block of an archive, so it can be used with slow storage
9832 devices. For example:
9833
9834 @smallexample
9835 @group
9836 $ @kbd{tar --test-label --file=iamanarchive}
9837 iamalabel
9838 @end group
9839 @end smallexample
9840
9841 If @option{--test-label} is used with a single command line
9842 argument, @command{tar} compares the volume label with the
9843 argument. It exits with code 0 if the two strings match, and with code
9844 2 otherwise. In this case no output is displayed. For example:
9845
9846 @smallexample
9847 @group
9848 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9849 @result{} 0
9850 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9851 @result{} 1
9852 @end group
9853 @end smallexample
9854
9855 If you request any operation, other than @option{--create}, along
9856 with using @option{--label} option, @command{tar} will first check if
9857 the archive label matches the one specified and will refuse to proceed
9858 if it does not. Use this as a safety precaution to avoid accidentally
9859 overwriting existing archives. For example, if you wish to add files
9860 to @file{archive}, presumably labelled with string @samp{My volume},
9861 you will get:
9862
9863 @smallexample
9864 @group
9865 $ @kbd{tar -rf archive --label 'My volume' .}
9866 tar: Archive not labeled to match `My volume'
9867 @end group
9868 @end smallexample
9869
9870 @noindent
9871 in case its label does not match. This will work even if
9872 @file{archive} is not labelled at all.
9873
9874 Similarly, @command{tar} will refuse to list or extract the
9875 archive if its label doesn't match the @var{archive-label}
9876 specified. In those cases, @var{archive-label} argument is interpreted
9877 as a globbing-style pattern which must match the actual magnetic
9878 volume label. @xref{exclude}, for a precise description of how match
9879 is attempted@footnote{Previous versions of @command{tar} used full
9880 regular expression matching, or before that, only exact string
9881 matching, instead of wildcard matchers. We decided for the sake of
9882 simplicity to use a uniform matching device through
9883 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
9884 the volume label matcher will also suffix @var{archive-label} by
9885 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
9886 up. Since the volume numbering is automatically added in labels at
9887 creation time, it sounded logical to equally help the user taking care
9888 of it when the archive is being read.
9889
9890 The @option{--label} was once called @option{--volume}, but is not
9891 available under that name anymore.
9892
9893 You can also use @option{--label} to get a common information on
9894 all tapes of a series. For having this information different in each
9895 series created through a single script used on a regular basis, just
9896 manage to get some date string as part of the label. For example:
9897
9898 @smallexample
9899 @group
9900 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
9901 $ @kbd{tar --create --file=/dev/tape --multi-volume \
9902 --volume="Daily backup for `date +%Y-%m-%d`"}
9903 @end group
9904 @end smallexample
9905
9906 Also note that each label has its own date and time, which corresponds
9907 to when @GNUTAR{} initially attempted to write it,
9908 often soon after the operator launches @command{tar} or types the
9909 carriage return telling that the next tape is ready. Comparing date
9910 labels does give an idea of tape throughput only if the delays for
9911 rewinding tapes and the operator switching them were negligible, which
9912 is usually not the case.
9913
9914 @node verify
9915 @section Verifying Data as It is Stored
9916 @cindex Verifying a write operation
9917 @cindex Double-checking a write operation
9918
9919 @table @option
9920 @item -W
9921 @itemx --verify
9922 @opindex verify, short description
9923 Attempt to verify the archive after writing.
9924 @end table
9925
9926 This option causes @command{tar} to verify the archive after writing it.
9927 Each volume is checked after it is written, and any discrepancies
9928 are recorded on the standard error output.
9929
9930 Verification requires that the archive be on a back-space-able medium.
9931 This means pipes, some cartridge tape drives, and some other devices
9932 cannot be verified.
9933
9934 You can insure the accuracy of an archive by comparing files in the
9935 system with archive members. @command{tar} can compare an archive to the
9936 file system as the archive is being written, to verify a write
9937 operation, or can compare a previously written archive, to insure that
9938 it is up to date.
9939
9940 @opindex verify, using with @option{--create}
9941 @opindex create, using with @option{--verify}
9942 To check for discrepancies in an archive immediately after it is
9943 written, use the @option{--verify} (@option{-W}) option in conjunction with
9944 the @option{--create} operation. When this option is
9945 specified, @command{tar} checks archive members against their counterparts
9946 in the file system, and reports discrepancies on the standard error.
9947
9948 To verify an archive, you must be able to read it from before the end
9949 of the last written entry. This option is useful for detecting data
9950 errors on some tapes. Archives written to pipes, some cartridge tape
9951 drives, and some other devices cannot be verified.
9952
9953 One can explicitly compare an already made archive with the file
9954 system by using the @option{--compare} (@option{--diff}, @option{-d})
9955 option, instead of using the more automatic @option{--verify} option.
9956 @xref{compare}.
9957
9958 Note that these two options have a slightly different intent. The
9959 @option{--compare} option checks how identical are the logical contents of some
9960 archive with what is on your disks, while the @option{--verify} option is
9961 really for checking if the physical contents agree and if the recording
9962 media itself is of dependable quality. So, for the @option{--verify}
9963 operation, @command{tar} tries to defeat all in-memory cache pertaining to
9964 the archive, while it lets the speed optimization undisturbed for the
9965 @option{--compare} option. If you nevertheless use @option{--compare} for
9966 media verification, you may have to defeat the in-memory cache yourself,
9967 maybe by opening and reclosing the door latch of your recording unit,
9968 forcing some doubt in your operating system about the fact this is really
9969 the same volume as the one just written or read.
9970
9971 The @option{--verify} option would not be necessary if drivers were indeed
9972 able to detect dependably all write failures. This sometimes require many
9973 magnetic heads, some able to read after the writes occurred. One would
9974 not say that drivers unable to detect all cases are necessarily flawed,
9975 as long as programming is concerned.
9976
9977 The @option{--verify} (@option{-W}) option will not work in
9978 conjunction with the @option{--multi-volume} (@option{-M}) option or
9979 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
9980 and @option{--delete} operations. @xref{Operations}, for more
9981 information on these operations.
9982
9983 Also, since @command{tar} normally strips leading @samp{/} from file
9984 names (@pxref{absolute}), a command like @samp{tar --verify -cf
9985 /tmp/foo.tar /etc} will work as desired only if the working directory is
9986 @file{/}, as @command{tar} uses the archive's relative member names
9987 (e.g., @file{etc/motd}) when verifying the archive.
9988
9989 @node Write Protection
9990 @section Write Protection
9991
9992 Almost all tapes and diskettes, and in a few rare cases, even disks can
9993 be @dfn{write protected}, to protect data on them from being changed.
9994 Once an archive is written, you should write protect the media to prevent
9995 the archive from being accidentally overwritten or deleted. (This will
9996 protect the archive from being changed with a tape or floppy drive---it
9997 will not protect it from magnet fields or other physical hazards).
9998
9999 The write protection device itself is usually an integral part of the
10000 physical media, and can be a two position (write enabled/write
10001 disabled) switch, a notch which can be popped out or covered, a ring
10002 which can be removed from the center of a tape reel, or some other
10003 changeable feature.
10004
10005 @node Changes
10006 @appendix Changes
10007
10008 This appendix lists some important user-visible changes between
10009 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10010 version of this document is available at
10011 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10012 @GNUTAR{} documentation page}.
10013
10014 @table @asis
10015 @item Use of globbing patterns when listing and extracting.
10016
10017 Previous versions of GNU tar assumed shell-style globbing when
10018 extracting from or listing an archive. For example:
10019
10020 @smallexample
10021 $ @kbd{tar xf foo.tar '*.c'}
10022 @end smallexample
10023
10024 would extract all files whose names end in @samp{.c}. This behavior
10025 was not documented and was incompatible with traditional tar
10026 implementations. Therefore, starting from version 1.15.91, GNU tar
10027 no longer uses globbing by default. For example, the above invocation
10028 is now interpreted as a request to extract from the archive the file
10029 named @file{*.c}.
10030
10031 To facilitate transition to the new behavior for those users who got
10032 used to the previous incorrect one, @command{tar} will print a warning
10033 if it finds out that a requested member was not found in the archive
10034 and its name looks like a globbing pattern. For example:
10035
10036 @smallexample
10037 $ @kbd{tar xf foo.tar '*.c'}
10038 tar: Pattern matching characters used in file names. Please,
10039 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10040 tar: suppress this warning.
10041 tar: *.c: Not found in archive
10042 tar: Error exit delayed from previous errors
10043 @end smallexample
10044
10045 To treat member names as globbing patterns, use --wildcards option.
10046 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10047 add this option to your @env{TAR_OPTIONS} variable.
10048
10049 @xref{wildcards}, for the detailed discussion of the use of globbing
10050 patterns by @GNUTAR{}.
10051
10052 @item Use of short option @option{-o}.
10053
10054 Earlier versions of @GNUTAR{} understood @option{-o} command line
10055 option as a synonym for @option{--old-archive}.
10056
10057 @GNUTAR{} starting from version 1.13.90 understands this option as
10058 a synonym for @option{--no-same-owner}. This is compatible with
10059 UNIX98 @command{tar} implementations.
10060
10061 However, to facilitate transition, @option{-o} option retains its
10062 old semantics when it is used with one of archive-creation commands.
10063 Users are encouraged to use @option{--format=oldgnu} instead.
10064
10065 It is especially important, since versions of @acronym{GNU} Automake
10066 up to and including 1.8.4 invoke tar with this option to produce
10067 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10068 of this issue and its implications.
10069
10070 @FIXME{Change the first argument to tar-formats when the new Automake is
10071 out. The proposition to add @anchor{} to the appropriate place of its
10072 docs was accepted by Automake people --Sergey 2006-05-25}.
10073 @xref{Options, tar-v7, Changing Automake's Behavior,
10074 automake, GNU Automake}, for a description on how to use various
10075 archive formats with @command{automake}.
10076
10077 Future versions of @GNUTAR{} will understand @option{-o} only as a
10078 synonym for @option{--no-same-owner}.
10079
10080 @item Use of short option @option{-l}
10081
10082 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10083 synonym for @option{--one-file-system}. Since such usage contradicted
10084 to UNIX98 specification and harmed compatibility with other
10085 implementation, it was declared deprecated in version 1.14. However,
10086 to facilitate transition to its new semantics, it was supported by
10087 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10088 variant of @option{--check-links} was introduced in version 1.15.91.
10089
10090 @item Use of options @option{--portability} and @option{--old-archive}
10091
10092 These options are deprecated. Please use @option{--format=v7} instead.
10093
10094 @item Use of option @option{--posix}
10095
10096 This option is deprecated. Please use @option{--format=posix} instead.
10097 @end table
10098
10099 @node Configuring Help Summary
10100 @appendix Configuring Help Summary
10101
10102 Running @kbd{tar --help} displays the short @command{tar} option
10103 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10104 semantically close options. The options within each group are printed
10105 in the following order: a short option, eventually followed by a list
10106 of corresponding long option names, followed by a short description of
10107 the option. For example, here is an excerpt from the actual @kbd{tar
10108 --help} output:
10109
10110 @verbatim
10111 Main operation mode:
10112
10113 -A, --catenate, --concatenate append tar files to an archive
10114 -c, --create create a new archive
10115 -d, --diff, --compare find differences between archive and
10116 file system
10117 --delete delete from the archive
10118 @end verbatim
10119
10120 @vrindex ARGP_HELP_FMT, environment variable
10121 The exact visual representation of the help output is configurable via
10122 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10123 is a comma-separated list of @dfn{format variable} assignments. There
10124 are two kinds of format variables. An @dfn{offset variable} keeps the
10125 offset of some part of help output text from the leftmost column on
10126 the screen. A @dfn{boolean} variable is a flag that toggles some
10127 output feature on or off. Depending on the type of the corresponding
10128 variable, there are two kinds of assignments:
10129
10130 @table @asis
10131 @item Offset assignment
10132
10133 The assignment to an offset variable has the following syntax:
10134
10135 @smallexample
10136 @var{variable}=@var{value}
10137 @end smallexample
10138
10139 @noindent
10140 where @var{variable} is the variable name, and @var{value} is a
10141 numeric value to be assigned to the variable.
10142
10143 @item Boolean assignment
10144
10145 To assign @code{true} value to a variable, simply put this variable name. To
10146 assign @code{false} value, prefix the variable name with @samp{no-}. For
10147 example:
10148
10149 @smallexample
10150 @group
10151 # Assign @code{true} value:
10152 dup-args
10153 # Assign @code{false} value:
10154 no-dup-args
10155 @end group
10156 @end smallexample
10157 @end table
10158
10159 Following variables are declared:
10160
10161 @deftypevr {Help Output} boolean dup-args
10162 If true, arguments for an option are shown with both short and long
10163 options, even when a given option has both forms, for example:
10164
10165 @smallexample
10166 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10167 @end smallexample
10168
10169 If false, then if an option has both short and long forms, the
10170 argument is only shown with the long one, for example:
10171
10172 @smallexample
10173 -f, --file=ARCHIVE use archive file or device ARCHIVE
10174 @end smallexample
10175
10176 @noindent
10177 and a message indicating that the argument is applicable to both
10178 forms is printed below the options. This message can be disabled
10179 using @code{dup-args-note} (see below).
10180
10181 The default is false.
10182 @end deftypevr
10183
10184 @deftypevr {Help Output} boolean dup-args-note
10185 If this variable is true, which is the default, the following notice
10186 is displayed at the end of the help output:
10187
10188 @quotation
10189 Mandatory or optional arguments to long options are also mandatory or
10190 optional for any corresponding short options.
10191 @end quotation
10192
10193 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10194 variables @code{dup-args} or @code{dup-args-note} should be set.
10195 @end deftypevr
10196
10197 @deftypevr {Help Output} offset short-opt-col
10198 Column in which short options start. Default is 2.
10199
10200 @smallexample
10201 @group
10202 $ @kbd{tar --help|grep ARCHIVE}
10203 -f, --file=ARCHIVE use archive file or device ARCHIVE
10204 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10205 -f, --file=ARCHIVE use archive file or device ARCHIVE
10206 @end group
10207 @end smallexample
10208 @end deftypevr
10209
10210 @deftypevr {Help Output} offset long-opt-col
10211 Column in which long options start. Default is 6. For example:
10212
10213 @smallexample
10214 @group
10215 $ @kbd{tar --help|grep ARCHIVE}
10216 -f, --file=ARCHIVE use archive file or device ARCHIVE
10217 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10218 -f, --file=ARCHIVE use archive file or device ARCHIVE
10219 @end group
10220 @end smallexample
10221 @end deftypevr
10222
10223 @deftypevr {Help Output} offset doc-opt-col
10224 Column in which @dfn{doc options} start. A doc option isn't actually
10225 an option, but rather an arbitrary piece of documentation that is
10226 displayed in much the same manner as the options. For example, in
10227 the description of @option{--format} option:
10228
10229 @smallexample
10230 @group
10231 -H, --format=FORMAT create archive of the given format.
10232
10233 FORMAT is one of the following:
10234
10235 gnu GNU tar 1.13.x format
10236 oldgnu GNU format as per tar <= 1.12
10237 pax POSIX 1003.1-2001 (pax) format
10238 posix same as pax
10239 ustar POSIX 1003.1-1988 (ustar) format
10240 v7 old V7 tar format
10241 @end group
10242 @end smallexample
10243
10244 @noindent
10245 the format names are doc options. Thus, if you set
10246 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10247 will look as follows:
10248
10249 @smallexample
10250 @group
10251 -H, --format=FORMAT create archive of the given format.
10252
10253 FORMAT is one of the following:
10254
10255 gnu GNU tar 1.13.x format
10256 oldgnu GNU format as per tar <= 1.12
10257 pax POSIX 1003.1-2001 (pax) format
10258 posix same as pax
10259 ustar POSIX 1003.1-1988 (ustar) format
10260 v7 old V7 tar format
10261 @end group
10262 @end smallexample
10263 @end deftypevr
10264
10265 @deftypevr {Help Output} offset opt-doc-col
10266 Column in which option description starts. Default is 29.
10267
10268 @smallexample
10269 @group
10270 $ @kbd{tar --help|grep ARCHIVE}
10271 -f, --file=ARCHIVE use archive file or device ARCHIVE
10272 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10273 -f, --file=ARCHIVE use archive file or device ARCHIVE
10274 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10275 -f, --file=ARCHIVE
10276 use archive file or device ARCHIVE
10277 @end group
10278 @end smallexample
10279
10280 @noindent
10281 Notice, that the description starts on a separate line if
10282 @code{opt-doc-col} value is too small.
10283 @end deftypevr
10284
10285 @deftypevr {Help Output} offset header-col
10286 Column in which @dfn{group headers} are printed. A group header is a
10287 descriptive text preceding an option group. For example, in the
10288 following text:
10289
10290 @verbatim
10291 Main operation mode:
10292
10293 -A, --catenate, --concatenate append tar files to
10294 an archive
10295 -c, --create create a new archive
10296 @end verbatim
10297 @noindent
10298 @samp{Main operation mode:} is the group header.
10299
10300 The default value is 1.
10301 @end deftypevr
10302
10303 @deftypevr {Help Output} offset usage-indent
10304 Indentation of wrapped usage lines. Affects @option{--usage}
10305 output. Default is 12.
10306 @end deftypevr
10307
10308 @deftypevr {Help Output} offset rmargin
10309 Right margin of the text output. Used for wrapping.
10310 @end deftypevr
10311
10312 @node Genfile
10313 @appendix Genfile
10314 @include genfile.texi
10315
10316 @node Tar Internals
10317 @appendix Tar Internals
10318 @include intern.texi
10319
10320 @node Free Software Needs Free Documentation
10321 @appendix Free Software Needs Free Documentation
10322 @include freemanuals.texi
10323
10324 @node Copying This Manual
10325 @appendix Copying This Manual
10326
10327 @menu
10328 * GNU Free Documentation License:: License for copying this manual
10329 @end menu
10330
10331 @include fdl.texi
10332
10333 @node Index of Command Line Options
10334 @appendix Index of Command Line Options
10335
10336 This appendix contains an index of all @GNUTAR{} long command line
10337 options. The options are listed without the preceeding double-dash.
10338
10339 @FIXME{@itemize
10340 @item Make sure @emph{all} options are indexed.
10341 @item Provide an index of short options
10342 @end itemize}
10343
10344 @printindex op
10345
10346 @node Index
10347 @appendix Index
10348
10349 @printindex cp
10350
10351 @summarycontents
10352 @contents
10353 @bye
10354
10355 @c Local variables:
10356 @c texinfo-column-for-description: 32
10357 @c End:
This page took 0.508453 seconds and 5 git commands to generate.