]> Dogcows Code - chaz/tar/blob - doc/tar.texi
(Overriding File Metadata): New node
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 1.1. Run `make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.1. Run `make master-menu' (see comment before the master menu).
19
20 @include rendition.texi
21 @include value.texi
22
23 @defcodeindex op
24
25 @c Put everything in one index (arbitrarily chosen to be the concept index).
26 @syncodeindex fn cp
27 @syncodeindex ky cp
28 @syncodeindex pg cp
29 @syncodeindex vr cp
30
31 @copying
32
33 This manual is for @acronym{GNU} @command{tar} (version
34 @value{VERSION}, @value{UPDATED}), which creates and extracts files
35 from archives.
36
37 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
38 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
39
40 @quotation
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
47
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
51 @end quotation
52 @end copying
53
54 @dircategory Archiving
55 @direntry
56 * Tar: (tar). Making tape (or disk) archives.
57 @end direntry
58
59 @dircategory Individual utilities
60 @direntry
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
62 @end direntry
63
64 @shorttitlepage @acronym{GNU} @command{tar}
65
66 @titlepage
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
70
71 @page
72 @vskip 0pt plus 1filll
73 @insertcopying
74 @end titlepage
75
76 @ifnottex
77 @node Top
78 @top @acronym{GNU} tar: an archiver tool
79
80 @insertcopying
81
82 @cindex file archival
83 @cindex archiving files
84
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
87 @end ifnottex
88
89 @c The master menu goes here.
90 @c
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
94 @c
95 @c make master-menu
96
97 @menu
98 * Introduction::
99 * Tutorial::
100 * tar invocation::
101 * operations::
102 * Backups::
103 * Choosing::
104 * Date input formats::
105 * Formats::
106 * Media::
107
108 Appendices
109
110 * Changes::
111 * Configuring Help Summary::
112 * Genfile::
113 * Tar Internals::
114 * Free Software Needs Free Documentation::
115 * Copying This Manual::
116 * Index of Command Line Options::
117 * Index::
118
119 @detailmenu
120 --- The Detailed Node Listing ---
121
122 Introduction
123
124 * Book Contents:: What this Book Contains
125 * Definitions:: Some Definitions
126 * What tar Does:: What @command{tar} Does
127 * Naming tar Archives:: How @command{tar} Archives are Named
128 * Authors:: @GNUTAR{} Authors
129 * Reports:: Reporting bugs or suggestions
130
131 Tutorial Introduction to @command{tar}
132
133 * assumptions::
134 * stylistic conventions::
135 * basic tar options:: Basic @command{tar} Operations and Options
136 * frequent operations::
137 * Two Frequent Options::
138 * create:: How to Create Archives
139 * list:: How to List Archives
140 * extract:: How to Extract Members from an Archive
141 * going further::
142
143 Two Frequently Used Options
144
145 * file tutorial::
146 * verbose tutorial::
147 * help tutorial::
148
149 How to Create Archives
150
151 * prepare for examples::
152 * Creating the archive::
153 * create verbose::
154 * short create::
155 * create dir::
156
157 How to List Archives
158
159 * list dir::
160
161 How to Extract Members from an Archive
162
163 * extracting archives::
164 * extracting files::
165 * extract dir::
166 * extracting untrusted archives::
167 * failing commands::
168
169 Invoking @GNUTAR{}
170
171 * Synopsis::
172 * using tar options::
173 * Styles::
174 * All Options::
175 * help::
176 * defaults::
177 * verbose::
178 * interactive::
179
180 The Three Option Styles
181
182 * Long Options:: Long Option Style
183 * Short Options:: Short Option Style
184 * Old Options:: Old Option Style
185 * Mixing:: Mixing Option Styles
186
187 All @command{tar} Options
188
189 * Operation Summary::
190 * Option Summary::
191 * Short Option Summary::
192
193 @GNUTAR{} Operations
194
195 * Basic tar::
196 * Advanced tar::
197 * create options::
198 * extract options::
199 * backup::
200 * Applications::
201 * looking ahead::
202
203 Advanced @GNUTAR{} Operations
204
205 * Operations::
206 * append::
207 * update::
208 * concatenate::
209 * delete::
210 * compare::
211
212 How to Add Files to Existing Archives: @option{--append}
213
214 * appending files:: Appending Files to an Archive
215 * multiple::
216
217 Updating an Archive
218
219 * how to update::
220
221 Options Used by @option{--create}
222
223 * override:: Overriding File Metadata.
224 * Ignore Failed Read::
225
226 Options Used by @option{--extract}
227
228 * Reading:: Options to Help Read Archives
229 * Writing:: Changing How @command{tar} Writes Files
230 * Scarce:: Coping with Scarce Resources
231
232 Options to Help Read Archives
233
234 * read full records::
235 * Ignore Zeros::
236
237 Changing How @command{tar} Writes Files
238
239 * Dealing with Old Files::
240 * Overwrite Old Files::
241 * Keep Old Files::
242 * Keep Newer Files::
243 * Unlink First::
244 * Recursive Unlink::
245 * Data Modification Times::
246 * Setting Access Permissions::
247 * Directory Modification Times and Permissions::
248 * Writing to Standard Output::
249 * Writing to an External Program::
250 * remove files::
251
252 Coping with Scarce Resources
253
254 * Starting File::
255 * Same Order::
256
257 Performing Backups and Restoring Files
258
259 * Full Dumps:: Using @command{tar} to Perform Full Dumps
260 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
261 * Backup Levels:: Levels of Backups
262 * Backup Parameters:: Setting Parameters for Backups and Restoration
263 * Scripted Backups:: Using the Backup Scripts
264 * Scripted Restoration:: Using the Restore Script
265
266 Setting Parameters for Backups and Restoration
267
268 * General-Purpose Variables::
269 * Magnetic Tape Control::
270 * User Hooks::
271 * backup-specs example:: An Example Text of @file{Backup-specs}
272
273 Choosing Files and Names for @command{tar}
274
275 * file:: Choosing the Archive's Name
276 * Selecting Archive Members::
277 * files:: Reading Names from a File
278 * exclude:: Excluding Some Files
279 * wildcards:: Wildcards Patterns and Matching
280 * quoting styles:: Ways of Quoting Special Characters in Names
281 * transform:: Modifying File and Member Names
282 * after:: Operating Only on New Files
283 * recurse:: Descending into Directories
284 * one:: Crossing File System Boundaries
285
286 Reading Names from a File
287
288 * nul::
289
290 Excluding Some Files
291
292 * problems with exclude::
293
294 Wildcards Patterns and Matching
295
296 * controlling pattern-matching::
297
298 Crossing File System Boundaries
299
300 * directory:: Changing Directory
301 * absolute:: Absolute File Names
302
303 Date input formats
304
305 * General date syntax:: Common rules.
306 * Calendar date items:: 19 Dec 1994.
307 * Time of day items:: 9:20pm.
308 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
309 * Day of week items:: Monday and others.
310 * Relative items in date strings:: next tuesday, 2 years ago.
311 * Pure numbers in date strings:: 19931219, 1440.
312 * Seconds since the Epoch:: @@1078100502.
313 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
314 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
315
316 Controlling the Archive Format
317
318 * Portability:: Making @command{tar} Archives More Portable
319 * Compression:: Using Less Space through Compression
320 * Attributes:: Handling File Attributes
321 * cpio:: Comparison of @command{tar} and @command{cpio}
322
323 Making @command{tar} Archives More Portable
324
325 * Portable Names:: Portable Names
326 * dereference:: Symbolic Links
327 * old:: Old V7 Archives
328 * ustar:: Ustar Archives
329 * gnu:: GNU and old GNU format archives.
330 * posix:: @acronym{POSIX} archives
331 * Checksumming:: Checksumming Problems
332 * Large or Negative Values:: Large files, negative time stamps, etc.
333
334 @GNUTAR{} and @acronym{POSIX} @command{tar}
335
336 * PAX keywords:: Controlling Extended Header Keywords.
337
338 Using Less Space through Compression
339
340 * gzip:: Creating and Reading Compressed Archives
341 * sparse:: Archiving Sparse Files
342
343 Tapes and Other Archive Media
344
345 * Device:: Device selection and switching
346 * Remote Tape Server::
347 * Common Problems and Solutions::
348 * Blocking:: Blocking
349 * Many:: Many archives on one tape
350 * Using Multiple Tapes:: Using Multiple Tapes
351 * label:: Including a Label in the Archive
352 * verify::
353 * Write Protection::
354
355 Blocking
356
357 * Format Variations:: Format Variations
358 * Blocking Factor:: The Blocking Factor of an Archive
359
360 Many Archives on One Tape
361
362 * Tape Positioning:: Tape Positions and Tape Marks
363 * mt:: The @command{mt} Utility
364
365 Using Multiple Tapes
366
367 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
368 * Tape Files:: Tape Files
369 * Tarcat:: Concatenate Volumes into a Single Archive
370
371
372 Genfile
373
374 * Generate Mode:: File Generation Mode.
375 * Status Mode:: File Status Mode.
376 * Exec Mode:: Synchronous Execution mode.
377
378 Tar Internals
379
380 * Standard:: Basic Tar Format
381 * Extensions:: @acronym{GNU} Extensions to the Archive Format
382 * Snapshot Files::
383 * Dumpdir::
384
385 Copying This Manual
386
387 * GNU Free Documentation License:: License for copying this manual
388
389 @end detailmenu
390 @end menu
391
392 @node Introduction
393 @chapter Introduction
394
395 @GNUTAR{} creates
396 and manipulates @dfn{archives} which are actually collections of
397 many other files; the program provides users with an organized and
398 systematic method for controlling a large amount of data.
399 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
400 archives need not (and these days, typically do not) reside on tapes.
401
402 @menu
403 * Book Contents:: What this Book Contains
404 * Definitions:: Some Definitions
405 * What tar Does:: What @command{tar} Does
406 * Naming tar Archives:: How @command{tar} Archives are Named
407 * Authors:: @GNUTAR{} Authors
408 * Reports:: Reporting bugs or suggestions
409 @end menu
410
411 @node Book Contents
412 @section What this Book Contains
413
414 The first part of this chapter introduces you to various terms that will
415 recur throughout the book. It also tells you who has worked on @GNUTAR{}
416 and its documentation, and where you should send bug reports
417 or comments.
418
419 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
420 gentle introduction for people who are new to using @command{tar}. It is
421 meant to be self contained, not requiring any reading from subsequent
422 chapters to make sense. It moves from topic to topic in a logical,
423 progressive order, building on information already explained.
424
425 Although the tutorial is paced and structured to allow beginners to
426 learn how to use @command{tar}, it is not intended solely for beginners.
427 The tutorial explains how to use the three most frequently used
428 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
429 two frequently used options (@samp{file} and @samp{verbose}). The other
430 chapters do not refer to the tutorial frequently; however, if a section
431 discusses something which is a complex variant of a basic concept, there
432 may be a cross reference to that basic concept. (The entire book,
433 including the tutorial, assumes that the reader understands some basic
434 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
435
436 The third chapter presents the remaining five operations, and
437 information about using @command{tar} options and option syntax.
438
439 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
440 than the reality. should think about whether this makes sense to say
441 here, or not.} The other chapters are meant to be used as a
442 reference. Each chapter presents everything that needs to be said
443 about a specific topic.
444
445 One of the chapters (@pxref{Date input formats}) exists in its
446 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
447 In addition, one section of this manual (@pxref{Standard}) contains a
448 big quote which is taken directly from @command{tar} sources.
449
450 In general, we give both long and short (abbreviated) option names
451 at least once in each section where the relevant option is covered, so
452 that novice readers will become familiar with both styles. (A few
453 options have no short versions, and the relevant sections will
454 indicate this.)
455
456 @node Definitions
457 @section Some Definitions
458
459 @cindex archive
460 @cindex tar archive
461 The @command{tar} program is used to create and manipulate @command{tar}
462 archives. An @dfn{archive} is a single file which contains the contents
463 of many files, while still identifying the names of the files, their
464 owner(s), and so forth. (In addition, archives record access
465 permissions, user and group, size in bytes, and data modification time.
466 Some archives also record the file names in each archived directory, as
467 well as other file and directory information.) You can use @command{tar}
468 to @dfn{create} a new archive in a specified directory.
469
470 @cindex member
471 @cindex archive member
472 @cindex file name
473 @cindex member name
474 The files inside an archive are called @dfn{members}. Within this
475 manual, we use the term @dfn{file} to refer only to files accessible in
476 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
477 @dfn{member} to refer only to the members of an archive. Similarly, a
478 @dfn{file name} is the name of a file, as it resides in the file system,
479 and a @dfn{member name} is the name of an archive member within the
480 archive.
481
482 @cindex extraction
483 @cindex unpacking
484 The term @dfn{extraction} refers to the process of copying an archive
485 member (or multiple members) into a file in the file system. Extracting
486 all the members of an archive is often called @dfn{extracting the
487 archive}. The term @dfn{unpack} can also be used to refer to the
488 extraction of many or all the members of an archive. Extracting an
489 archive does not destroy the archive's structure, just as creating an
490 archive does not destroy the copies of the files that exist outside of
491 the archive. You may also @dfn{list} the members in a given archive
492 (this is often thought of as ``printing'' them to the standard output,
493 or the command line), or @dfn{append} members to a pre-existing archive.
494 All of these operations can be performed using @command{tar}.
495
496 @node What tar Does
497 @section What @command{tar} Does
498
499 @cindex tar
500 The @command{tar} program provides the ability to create @command{tar}
501 archives, as well as various other kinds of manipulation. For example,
502 you can use @command{tar} on previously created archives to extract files,
503 to store additional files, or to update or list files which were already
504 stored.
505
506 Initially, @command{tar} archives were used to store files conveniently on
507 magnetic tape. The name @command{tar} comes from this use; it stands for
508 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
509 direct its output to available devices, files, or other programs (using
510 pipes). @command{tar} may even access remote devices or files (as archives).
511
512 You can use @command{tar} archives in many ways. We want to stress a few
513 of them: storage, backup, and transportation.
514
515 @FIXME{the following table entries need a bit of work..}
516 @table @asis
517 @item Storage
518 Often, @command{tar} archives are used to store related files for
519 convenient file transfer over a network. For example, the
520 @acronym{GNU} Project distributes its software bundled into
521 @command{tar} archives, so that all the files relating to a particular
522 program (or set of related programs) can be transferred as a single
523 unit.
524
525 A magnetic tape can store several files in sequence. However, the tape
526 has no names for these files; it only knows their relative position on
527 the tape. One way to store several files on one tape and retain their
528 names is by creating a @command{tar} archive. Even when the basic transfer
529 mechanism can keep track of names, as FTP can, the nuisance of handling
530 multiple files, directories, and multiple links makes @command{tar}
531 archives useful.
532
533 Archive files are also used for long-term storage. You can think of
534 this as transportation from the present into the future. (It is a
535 science-fiction idiom that you can move through time as well as in
536 space; the idea here is that @command{tar} can be used to move archives in
537 all dimensions, even time!)
538
539 @item Backup
540 Because the archive created by @command{tar} is capable of preserving
541 file information and directory structure, @command{tar} is commonly
542 used for performing full and incremental backups of disks. A backup
543 puts a collection of files (possibly pertaining to many users and
544 projects) together on a disk or a tape. This guards against
545 accidental destruction of the information in those files.
546 @GNUTAR{} has special features that allow it to be
547 used to make incremental and full dumps of all the files in a
548 file system.
549
550 @item Transportation
551 You can create an archive on one system, transfer it to another system,
552 and extract the contents there. This allows you to transport a group of
553 files from one system to another.
554 @end table
555
556 @node Naming tar Archives
557 @section How @command{tar} Archives are Named
558
559 Conventionally, @command{tar} archives are given names ending with
560 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
561 but this manual follows that convention in order to accustom readers to
562 it and to make examples more clear.
563
564 @cindex tar file
565 @cindex entry
566 @cindex tar entry
567 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
568 archive members as ``files'' or ``entries''. For people familiar with
569 the operation of @command{tar}, this causes no difficulty. However, in
570 this manual, we consistently refer to ``archives'' and ``archive
571 members'' to make learning to use @command{tar} easier for novice users.
572
573 @node Authors
574 @section @GNUTAR{} Authors
575
576 @GNUTAR{} was originally written by John Gilmore,
577 and modified by many people. The @acronym{GNU} enhancements were
578 written by Jay Fenlason, then Joy Kendall, and the whole package has
579 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
580 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
581 numerous and kind users.
582
583 We wish to stress that @command{tar} is a collective work, and owes much to
584 all those people who reported problems, offered solutions and other
585 insights, or shared their thoughts and suggestions. An impressive, yet
586 partial list of those contributors can be found in the @file{THANKS}
587 file from the @GNUTAR{} distribution.
588
589 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
590 sure i want to spell out the history in this detail, at least not for
591 the printed book. i'm just not sure it needs to be said this way.
592 i'll think about it.}
593
594 @FIXME{History is more important, and surely more interesting, than
595 actual names. Quoting names without history would be meaningless. FP}
596
597 Jay Fenlason put together a draft of a @GNUTAR{}
598 manual, borrowing notes from the original man page from John Gilmore.
599 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
600 Gorin worked on a tutorial and manual for @GNUTAR{}.
601 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
602 taking information from all these sources and merging them. Melissa
603 Weisshaus finally edited and redesigned the book to create version
604 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
605 by the current maintainer, Sergey Poznyakoff.
606
607 For version 1.12, Daniel Hagerty contributed a great deal of technical
608 consulting. In particular, he is the primary author of @ref{Backups}.
609
610 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
611 (see @url{http://savannah.gnu.org/projects/tar}), and
612 active development and maintenance work has started
613 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
614 Poznyakoff and Jeff Bailey.
615
616 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
617
618 @node Reports
619 @section Reporting bugs or suggestions
620
621 @cindex bug reports
622 @cindex reporting bugs
623 If you find problems or have suggestions about this program or manual,
624 please report them to @file{bug-tar@@gnu.org}.
625
626 When reporting a bug, please be sure to include as much detail as
627 possible, in order to reproduce it. @FIXME{Be more specific, I'd
628 like to make this node as detailed as 'Bug reporting' node in Emacs
629 manual}.
630
631 @node Tutorial
632 @chapter Tutorial Introduction to @command{tar}
633
634 This chapter guides you through some basic examples of three @command{tar}
635 operations: @option{--create}, @option{--list}, and @option{--extract}. If
636 you already know how to use some other version of @command{tar}, then you
637 may not need to read this chapter. This chapter omits most complicated
638 details about how @command{tar} works.
639
640 @menu
641 * assumptions::
642 * stylistic conventions::
643 * basic tar options:: Basic @command{tar} Operations and Options
644 * frequent operations::
645 * Two Frequent Options::
646 * create:: How to Create Archives
647 * list:: How to List Archives
648 * extract:: How to Extract Members from an Archive
649 * going further::
650 @end menu
651
652 @node assumptions
653 @section Assumptions this Tutorial Makes
654
655 This chapter is paced to allow beginners to learn about @command{tar}
656 slowly. At the same time, we will try to cover all the basic aspects of
657 these three operations. In order to accomplish both of these tasks, we
658 have made certain assumptions about your knowledge before reading this
659 manual, and the hardware you will be using:
660
661 @itemize @bullet
662 @item
663 Before you start to work through this tutorial, you should understand
664 what the terms ``archive'' and ``archive member'' mean
665 (@pxref{Definitions}). In addition, you should understand something
666 about how Unix-type operating systems work, and you should know how to
667 use some basic utilities. For example, you should know how to create,
668 list, copy, rename, edit, and delete files and directories; how to
669 change between directories; and how to figure out where you are in the
670 file system. You should have some basic understanding of directory
671 structure and how files are named according to which directory they are
672 in. You should understand concepts such as standard output and standard
673 input, what various definitions of the term ``argument'' mean, and the
674 differences between relative and absolute path names. @FIXME{and what
675 else?}
676
677 @item
678 This manual assumes that you are working from your own home directory
679 (unless we state otherwise). In this tutorial, you will create a
680 directory to practice @command{tar} commands in. When we show path names,
681 we will assume that those paths are relative to your home directory.
682 For example, my home directory path is @file{/home/fsf/melissa}. All of
683 my examples are in a subdirectory of the directory named by that path
684 name; the subdirectory is called @file{practice}.
685
686 @item
687 In general, we show examples of archives which exist on (or can be
688 written to, or worked with from) a directory on a hard disk. In most
689 cases, you could write those archives to, or work with them on any other
690 device, such as a tape drive. However, some of the later examples in
691 the tutorial and next chapter will not work on tape drives.
692 Additionally, working with tapes is much more complicated than working
693 with hard disks. For these reasons, the tutorial does not cover working
694 with tape drives. @xref{Media}, for complete information on using
695 @command{tar} archives with tape drives.
696
697 @FIXME{this is a cop out. need to add some simple tape drive info.}
698 @end itemize
699
700 @node stylistic conventions
701 @section Stylistic Conventions
702
703 In the examples, @samp{$} represents a typical shell prompt. It
704 precedes lines you should type; to make this more clear, those lines are
705 shown in @kbd{this font}, as opposed to lines which represent the
706 computer's response; those lines are shown in @code{this font}, or
707 sometimes @samp{like this}.
708
709 @c When we have lines which are too long to be
710 @c displayed in any other way, we will show them like this:
711
712 @node basic tar options
713 @section Basic @command{tar} Operations and Options
714
715 @command{tar} can take a wide variety of arguments which specify and define
716 the actions it will have on the particular set of files or the archive.
717 The main types of arguments to @command{tar} fall into one of two classes:
718 operations, and options.
719
720 Some arguments fall into a class called @dfn{operations}; exactly one of
721 these is both allowed and required for any instance of using @command{tar};
722 you may @emph{not} specify more than one. People sometimes speak of
723 @dfn{operating modes}. You are in a particular operating mode when you
724 have specified the operation which specifies it; there are eight
725 operations in total, and thus there are eight operating modes.
726
727 The other arguments fall into the class known as @dfn{options}. You are
728 not required to specify any options, and you are allowed to specify more
729 than one at a time (depending on the way you are using @command{tar} at
730 that time). Some options are used so frequently, and are so useful for
731 helping you type commands more carefully that they are effectively
732 ``required''. We will discuss them in this chapter.
733
734 You can write most of the @command{tar} operations and options in any
735 of three forms: long (mnemonic) form, short form, and old style. Some
736 of the operations and options have no short or ``old'' forms; however,
737 the operations and options which we will cover in this tutorial have
738 corresponding abbreviations. @FIXME{make sure this is still the case,
739 at the end}We will indicate those abbreviations appropriately to get
740 you used to seeing them. (Note that the ``old style'' option forms
741 exist in @GNUTAR{} for compatibility with Unix
742 @command{tar}. In this book we present a full discussion of this way
743 of writing options and operations (@pxref{Old Options}), and we discuss
744 the other two styles of writing options (@xref{Long Options}, and
745 @pxref{Short Options}).
746
747 In the examples and in the text of this tutorial, we usually use the
748 long forms of operations and options; but the ``short'' forms produce
749 the same result and can make typing long @command{tar} commands easier.
750 For example, instead of typing
751
752 @smallexample
753 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
754 @end smallexample
755
756 @noindent
757 you can type
758 @smallexample
759 @kbd{tar -c -v -f afiles.tar apple angst aspic}
760 @end smallexample
761
762 @noindent
763 or even
764 @smallexample
765 @kbd{tar -cvf afiles.tar apple angst aspic}
766 @end smallexample
767
768 @noindent
769 For more information on option syntax, see @ref{Advanced tar}. In
770 discussions in the text, when we name an option by its long form, we
771 also give the corresponding short option in parentheses.
772
773 The term, ``option'', can be confusing at times, since ``operations''
774 are often lumped in with the actual, @emph{optional} ``options'' in certain
775 general class statements. For example, we just talked about ``short and
776 long forms of options and operations''. However, experienced @command{tar}
777 users often refer to these by shorthand terms such as, ``short and long
778 options''. This term assumes that the ``operations'' are included, also.
779 Context will help you determine which definition of ``options'' to use.
780
781 Similarly, the term ``command'' can be confusing, as it is often used in
782 two different ways. People sometimes refer to @command{tar} ``commands''.
783 A @command{tar} @dfn{command} is the entire command line of user input
784 which tells @command{tar} what to do --- including the operation, options,
785 and any arguments (file names, pipes, other commands, etc). However,
786 you will also sometimes hear the term ``the @command{tar} command''. When
787 the word ``command'' is used specifically like this, a person is usually
788 referring to the @command{tar} @emph{operation}, not the whole line.
789 Again, use context to figure out which of the meanings the speaker
790 intends.
791
792 @node frequent operations
793 @section The Three Most Frequently Used Operations
794
795 Here are the three most frequently used operations (both short and long
796 forms), as well as a brief description of their meanings. The rest of
797 this chapter will cover how to use these operations in detail. We will
798 present the rest of the operations in the next chapter.
799
800 @table @option
801 @item --create
802 @itemx -c
803 Create a new @command{tar} archive.
804 @item --list
805 @itemx -t
806 List the contents of an archive.
807 @item --extract
808 @itemx -x
809 Extract one or more members from an archive.
810 @end table
811
812 @node Two Frequent Options
813 @section Two Frequently Used Options
814
815 To understand how to run @command{tar} in the three operating modes listed
816 previously, you also need to understand how to use two of the options to
817 @command{tar}: @option{--file} (which takes an archive file as an argument)
818 and @option{--verbose}. (You are usually not @emph{required} to specify
819 either of these options when you run @command{tar}, but they can be very
820 useful in making things more clear and helping you avoid errors.)
821
822 @menu
823 * file tutorial::
824 * verbose tutorial::
825 * help tutorial::
826 @end menu
827
828 @node file tutorial
829 @unnumberedsubsec The @option{--file} Option
830
831 @table @option
832 @xopindex{file, tutorial}
833 @item --file=@var{archive-name}
834 @itemx -f @var{archive-name}
835 Specify the name of an archive file.
836 @end table
837
838 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
839 use @command{tar}; this option determines the name of the archive file
840 that @command{tar} will work on.
841
842 @vrindex TAPE
843 If you don't specify this argument, then @command{tar} will examine
844 the environment variable @env{TAPE}. If it is set, its value will be
845 used as the archive name. Otherwise, @command{tar} will use the
846 default archive, determined at the compile time. Usually it is
847 standard output or some physical tape drive attached to your machine
848 (you can verify what the default is by running @kbd{tar
849 --show-defaults}, @pxref{defaults}). If there is no tape drive
850 attached, or the default is not meaningful, then @command{tar} will
851 print an error message. The error message might look roughly like one
852 of the following:
853
854 @smallexample
855 tar: can't open /dev/rmt8 : No such device or address
856 tar: can't open /dev/rsmt0 : I/O error
857 @end smallexample
858
859 @noindent
860 To avoid confusion, we recommend that you always specify an archive file
861 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
862 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
863 @ref{file}.
864
865 @node verbose tutorial
866 @unnumberedsubsec The @option{--verbose} Option
867
868 @table @option
869 @xopindex{verbose, introduced}
870 @item --verbose
871 @itemx -v
872 Show the files being worked on as @command{tar} is running.
873 @end table
874
875 @option{--verbose} (@option{-v}) shows details about the results of running
876 @command{tar}. This can be especially useful when the results might not be
877 obvious. For example, if you want to see the progress of @command{tar} as
878 it writes files into the archive, you can use the @option{--verbose}
879 option. In the beginning, you may find it useful to use
880 @option{--verbose} at all times; when you are more accustomed to
881 @command{tar}, you will likely want to use it at certain times but not at
882 others. We will use @option{--verbose} at times to help make something
883 clear, and we will give many examples both using and not using
884 @option{--verbose} to show the differences.
885
886 Each instance of @option{--verbose} on the command line increases the
887 verbosity level by one, so if you need more details on the output,
888 specify it twice.
889
890 When reading archives (@option{--list}, @option{--extract},
891 @option{--diff}), @command{tar} by default prints only the names of
892 the members being extracted. Using @option{--verbose} will show a full,
893 @command{ls} style member listing.
894
895 In contrast, when writing archives (@option{--create}, @option{--append},
896 @option{--update}), @command{tar} does not print file names by
897 default. So, a single @option{--verbose} option shows the file names
898 being added to the archive, while two @option{--verbose} options
899 enable the full listing.
900
901 For example, to create an archive in verbose mode:
902
903 @smallexample
904 $ @kbd{tar -cvf afiles.tar apple angst aspic}
905 apple
906 angst
907 aspic
908 @end smallexample
909
910 @noindent
911 Creating the same archive with the verbosity level 2 could give:
912
913 @smallexample
914 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
915 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
916 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
917 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
918 @end smallexample
919
920 @noindent
921 This works equally well using short or long forms of options. Using
922 long forms, you would simply write out the mnemonic form of the option
923 twice, like this:
924
925 @smallexample
926 $ @kbd{tar --create --verbose --verbose @dots{}}
927 @end smallexample
928
929 @noindent
930 Note that you must double the hyphens properly each time.
931
932 Later in the tutorial, we will give examples using @w{@option{--verbose
933 --verbose}}.
934
935 @anchor{verbose member listing}
936 The full output consists of six fields:
937
938 @itemize @bullet
939 @item File type and permissions in symbolic form.
940 These are displayed in the same format as the first column of
941 @command{ls -l} output (@pxref{What information is listed,
942 format=verbose, Verbose listing, fileutils, GNU file utilities}).
943
944 @item Owner name and group separated by a slash character.
945 If these data are not available (for example, when listing a @samp{v7} format
946 archive), numeric ID values are printed instead.
947
948 @item Size of the file, in bytes.
949
950 @item File modification date in ISO 8601 format.
951
952 @item File modification time.
953
954 @item File name.
955 If the name contains any special characters (white space, newlines,
956 etc.) these are displayed in an unambiguous form using so called
957 @dfn{quoting style}. For the detailed discussion of available styles
958 and on how to use them, see @ref{quoting styles}.
959
960 Depending on the file type, the name can be followed by some
961 additional information, described in the following table:
962
963 @table @samp
964 @item -> @var{link-name}
965 The file or archive member is a @dfn{symbolic link} and
966 @var{link-name} is the name of file it links to.
967
968 @item link to @var{link-name}
969 The file or archive member is a @dfn{hard link} and @var{link-name} is
970 the name of file it links to.
971
972 @item --Long Link--
973 The archive member is an old GNU format long link. You will normally
974 not encounter this.
975
976 @item --Long Name--
977 The archive member is an old GNU format long name. You will normally
978 not encounter this.
979
980 @item --Volume Header--
981 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
982
983 @item --Continued at byte @var{n}--
984 Encountered only at the beginning of a multy-volume archive
985 (@pxref{Using Multiple Tapes}). This archive member is a continuation
986 from the previous volume. The number @var{n} gives the offset where
987 the original file was split.
988
989 @item --Mangled file names--
990 This archive member contains @dfn{mangled file names} declarations,
991 a special member type that was used by early versions of @GNUTAR{}.
992 You probably will never encounter this, unless you are reading a very
993 old archive.
994
995 @item unknown file type @var{c}
996 An archive member of unknown type. @var{c} is the type character from
997 the archive header. If you encounter such a message, it means that
998 either your archive contains proprietary member types @GNUTAR{} is not
999 able to handle, or the archive is corrupted.
1000 @end table
1001
1002 @end itemize
1003
1004 For example, here is an archive listing containing most of the special
1005 suffixes explained above:
1006
1007 @smallexample
1008 @group
1009 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1010 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1011 byte 32456--
1012 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1013 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1014 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1015 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1016 @end group
1017 @end smallexample
1018
1019 @smallexample
1020 @end smallexample
1021
1022 @node help tutorial
1023 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1024
1025 @table @option
1026 @opindex help
1027 @item --help
1028
1029 The @option{--help} option to @command{tar} prints out a very brief list of
1030 all operations and option available for the current version of
1031 @command{tar} available on your system.
1032 @end table
1033
1034 @node create
1035 @section How to Create Archives
1036 @UNREVISED
1037
1038 @cindex Creation of the archive
1039 @cindex Archive, creation of
1040 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1041 you use to create a @command{tar} archive. We will explain
1042 @option{--create} first because, in order to learn about the other
1043 operations, you will find it useful to have an archive available to
1044 practice on.
1045
1046 To make this easier, in this section you will first create a directory
1047 containing three files. Then, we will show you how to create an
1048 @emph{archive} (inside the new directory). Both the directory, and
1049 the archive are specifically for you to practice on. The rest of this
1050 chapter and the next chapter will show many examples using this
1051 directory and the files you will create: some of those files may be
1052 other directories and other archives.
1053
1054 The three files you will archive in this example are called
1055 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1056 @file{collection.tar}.
1057
1058 This section will proceed slowly, detailing how to use @option{--create}
1059 in @code{verbose} mode, and showing examples using both short and long
1060 forms. In the rest of the tutorial, and in the examples in the next
1061 chapter, we will proceed at a slightly quicker pace. This section
1062 moves more slowly to allow beginning users to understand how
1063 @command{tar} works.
1064
1065 @menu
1066 * prepare for examples::
1067 * Creating the archive::
1068 * create verbose::
1069 * short create::
1070 * create dir::
1071 @end menu
1072
1073 @node prepare for examples
1074 @subsection Preparing a Practice Directory for Examples
1075
1076 To follow along with this and future examples, create a new directory
1077 called @file{practice} containing files called @file{blues}, @file{folk}
1078 and @file{jazz}. The files can contain any information you like:
1079 ideally, they should contain information which relates to their names,
1080 and be of different lengths. Our examples assume that @file{practice}
1081 is a subdirectory of your home directory.
1082
1083 Now @command{cd} to the directory named @file{practice}; @file{practice}
1084 is now your @dfn{working directory}. (@emph{Please note}: Although
1085 the full path name of this directory is
1086 @file{/@var{homedir}/practice}, in our examples we will refer to
1087 this directory as @file{practice}; the @var{homedir} is presumed.
1088
1089 In general, you should check that the files to be archived exist where
1090 you think they do (in the working directory) by running @command{ls}.
1091 Because you just created the directory and the files and have changed to
1092 that directory, you probably don't need to do that this time.
1093
1094 It is very important to make sure there isn't already a file in the
1095 working directory with the archive name you intend to use (in this case,
1096 @samp{collection.tar}), or that you don't care about its contents.
1097 Whenever you use @samp{create}, @command{tar} will erase the current
1098 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1099 will not tell you if you are about to overwrite an archive unless you
1100 specify an option which does this (@pxref{backup}, for the
1101 information on how to do so). To add files to an existing archive,
1102 you need to use a different option, such as @option{--append} (@option{-r}); see
1103 @ref{append} for information on how to do this.
1104
1105 @node Creating the archive
1106 @subsection Creating the Archive
1107
1108 @xopindex{create, introduced}
1109 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1110 archive named @file{collection.tar}, use the following command:
1111
1112 @smallexample
1113 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1114 @end smallexample
1115
1116 The order of the arguments is not very important, @emph{when using long
1117 option forms}. You could also say:
1118
1119 @smallexample
1120 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1121 @end smallexample
1122
1123 @noindent
1124 However, you can see that this order is harder to understand; this is
1125 why we will list the arguments in the order that makes the commands
1126 easiest to understand (and we encourage you to do the same when you use
1127 @command{tar}, to avoid errors).
1128
1129 Note that the sequence
1130 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1131 If you substituted any other string of characters for
1132 @kbd{collection.tar}, then that string would become the name of the
1133 archive file you create.
1134
1135 The order of the options becomes more important when you begin to use
1136 short forms. With short forms, if you type commands in the wrong order
1137 (even if you type them correctly in all other ways), you may end up with
1138 results you don't expect. For this reason, it is a good idea to get
1139 into the habit of typing options in the order that makes inherent sense.
1140 @xref{short create}, for more information on this.
1141
1142 In this example, you type the command as shown above: @option{--create}
1143 is the operation which creates the new archive
1144 (@file{collection.tar}), and @option{--file} is the option which lets
1145 you give it the name you chose. The files, @file{blues}, @file{folk},
1146 and @file{jazz}, are now members of the archive, @file{collection.tar}
1147 (they are @dfn{file name arguments} to the @option{--create} operation.
1148 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1149 in the archive, they are called @emph{archive members}, not files.
1150 (@pxref{Definitions,members}).
1151
1152 When you create an archive, you @emph{must} specify which files you
1153 want placed in the archive. If you do not specify any archive
1154 members, @GNUTAR{} will complain.
1155
1156 If you now list the contents of the working directory (@command{ls}), you will
1157 find the archive file listed as well as the files you saw previously:
1158
1159 @smallexample
1160 blues folk jazz collection.tar
1161 @end smallexample
1162
1163 @noindent
1164 Creating the archive @samp{collection.tar} did not destroy the copies of
1165 the files in the directory.
1166
1167 Keep in mind that if you don't indicate an operation, @command{tar} will not
1168 run and will prompt you for one. If you don't name any files, @command{tar}
1169 will complain. You must have write access to the working directory,
1170 or else you will not be able to create an archive in that directory.
1171
1172 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1173 an existing archive; it will delete the archive and write a new one.
1174 Use @option{--append} (@option{-r}) instead. @xref{append}.
1175
1176 @node create verbose
1177 @subsection Running @option{--create} with @option{--verbose}
1178
1179 @xopindex{create, using with @option{--verbose}}
1180 @xopindex{verbose, using with @option{--create}}
1181 If you include the @option{--verbose} (@option{-v}) option on the command line,
1182 @command{tar} will list the files it is acting on as it is working. In
1183 verbose mode, the @code{create} example above would appear as:
1184
1185 @smallexample
1186 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1187 blues
1188 folk
1189 jazz
1190 @end smallexample
1191
1192 This example is just like the example we showed which did not use
1193 @option{--verbose}, except that @command{tar} generated the remaining lines
1194 @iftex
1195 (note the different font styles).
1196 @end iftex
1197 @ifinfo
1198 .
1199 @end ifinfo
1200
1201 In the rest of the examples in this chapter, we will frequently use
1202 @code{verbose} mode so we can show actions or @command{tar} responses that
1203 you would otherwise not see, and which are important for you to
1204 understand.
1205
1206 @node short create
1207 @subsection Short Forms with @samp{create}
1208
1209 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1210 basic uses of @command{tar}, and you will use it countless times.
1211 Eventually, you will probably want to use abbreviated (or ``short'')
1212 forms of options. A full discussion of the three different forms that
1213 options can take appears in @ref{Styles}; for now, here is what the
1214 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1215 using short option forms:
1216
1217 @smallexample
1218 $ @kbd{tar -cvf collection.tar blues folk jazz}
1219 blues
1220 folk
1221 jazz
1222 @end smallexample
1223
1224 @noindent
1225 As you can see, the system responds the same no matter whether you use
1226 long or short option forms.
1227
1228 @FIXME{i don't like how this is worded:} One difference between using
1229 short and long option forms is that, although the exact placement of
1230 arguments following options is no more specific when using short forms,
1231 it is easier to become confused and make a mistake when using short
1232 forms. For example, suppose you attempted the above example in the
1233 following way:
1234
1235 @smallexample
1236 $ @kbd{tar -cfv collection.tar blues folk jazz}
1237 @end smallexample
1238
1239 @noindent
1240 In this case, @command{tar} will make an archive file called @file{v},
1241 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1242 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1243 is thus taken to be the chosen archive file name. @command{tar} will try
1244 to add a file called @file{collection.tar} to the @file{v} archive file;
1245 if the file @file{collection.tar} did not already exist, @command{tar} will
1246 report an error indicating that this file does not exist. If the file
1247 @file{collection.tar} does already exist (e.g., from a previous command
1248 you may have run), then @command{tar} will add this file to the archive.
1249 Because the @option{-v} option did not get registered, @command{tar} will not
1250 run under @samp{verbose} mode, and will not report its progress.
1251
1252 The end result is that you may be quite confused about what happened,
1253 and possibly overwrite a file. To illustrate this further, we will show
1254 you how an example we showed previously would look using short forms.
1255
1256 This example,
1257
1258 @smallexample
1259 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1260 @end smallexample
1261
1262 @noindent
1263 is confusing as it is. When shown using short forms, however, it
1264 becomes much more so:
1265
1266 @smallexample
1267 $ @kbd{tar blues -c folk -f collection.tar jazz}
1268 @end smallexample
1269
1270 @noindent
1271 It would be very easy to put the wrong string of characters
1272 immediately following the @option{-f}, but doing that could sacrifice
1273 valuable data.
1274
1275 For this reason, we recommend that you pay very careful attention to
1276 the order of options and placement of file and archive names,
1277 especially when using short option forms. Not having the option name
1278 written out mnemonically can affect how well you remember which option
1279 does what, and therefore where different names have to be placed.
1280
1281 @node create dir
1282 @subsection Archiving Directories
1283
1284 @cindex Archiving Directories
1285 @cindex Directories, Archiving
1286 You can archive a directory by specifying its directory name as a
1287 file name argument to @command{tar}. The files in the directory will be
1288 archived relative to the working directory, and the directory will be
1289 re-created along with its contents when the archive is extracted.
1290
1291 To archive a directory, first move to its superior directory. If you
1292 have followed the previous instructions in this tutorial, you should
1293 type:
1294
1295 @smallexample
1296 $ @kbd{cd ..}
1297 $
1298 @end smallexample
1299
1300 @noindent
1301 This will put you into the directory which contains @file{practice},
1302 i.e., your home directory. Once in the superior directory, you can
1303 specify the subdirectory, @file{practice}, as a file name argument. To
1304 store @file{practice} in the new archive file @file{music.tar}, type:
1305
1306 @smallexample
1307 $ @kbd{tar --create --verbose --file=music.tar practice}
1308 @end smallexample
1309
1310 @noindent
1311 @command{tar} should output:
1312
1313 @smallexample
1314 practice/
1315 practice/blues
1316 practice/folk
1317 practice/jazz
1318 practice/collection.tar
1319 @end smallexample
1320
1321 Note that the archive thus created is not in the subdirectory
1322 @file{practice}, but rather in the current working directory---the
1323 directory from which @command{tar} was invoked. Before trying to archive a
1324 directory from its superior directory, you should make sure you have
1325 write access to the superior directory itself, not only the directory
1326 you are trying archive with @command{tar}. For example, you will probably
1327 not be able to store your home directory in an archive by invoking
1328 @command{tar} from the root directory; @xref{absolute}. (Note
1329 also that @file{collection.tar}, the original archive file, has itself
1330 been archived. @command{tar} will accept any file as a file to be
1331 archived, regardless of its content. When @file{music.tar} is
1332 extracted, the archive file @file{collection.tar} will be re-written
1333 into the file system).
1334
1335 If you give @command{tar} a command such as
1336
1337 @smallexample
1338 $ @kbd{tar --create --file=foo.tar .}
1339 @end smallexample
1340
1341 @noindent
1342 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1343 dumped}. This happens because @command{tar} creates the archive
1344 @file{foo.tar} in the current directory before putting any files into
1345 it. Then, when @command{tar} attempts to add all the files in the
1346 directory @file{.} to the archive, it notices that the file
1347 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1348 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1349 will continue in this case, and create the archive
1350 normally, except for the exclusion of that one file. (@emph{Please
1351 note:} Other implementations of @command{tar} may not be so clever;
1352 they will enter an infinite loop when this happens, so you should not
1353 depend on this behavior unless you are certain you are running
1354 @GNUTAR{}. In general, it is wise to always place the archive outside
1355 of the directory being dumped.
1356
1357 @node list
1358 @section How to List Archives
1359
1360 @opindex list
1361 Frequently, you will find yourself wanting to determine exactly what a
1362 particular archive contains. You can use the @option{--list}
1363 (@option{-t}) operation to get the member names as they currently
1364 appear in the archive, as well as various attributes of the files at
1365 the time they were archived. For example, you can examine the archive
1366 @file{collection.tar} that you created in the last section with the
1367 command,
1368
1369 @smallexample
1370 $ @kbd{tar --list --file=collection.tar}
1371 @end smallexample
1372
1373 @noindent
1374 The output of @command{tar} would then be:
1375
1376 @smallexample
1377 blues
1378 folk
1379 jazz
1380 @end smallexample
1381
1382 @noindent
1383 The archive @file{bfiles.tar} would list as follows:
1384
1385 @smallexample
1386 ./birds
1387 baboon
1388 ./box
1389 @end smallexample
1390
1391 @noindent
1392 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1393 @var{archive-name}}) option just as with @option{--create}
1394 (@option{-c}) to specify the name of the archive.
1395
1396 @xopindex{list, using with @option{--verbose}}
1397 @xopindex{verbose, using with @option{--list}}
1398 If you use the @option{--verbose} (@option{-v}) option with
1399 @option{--list}, then @command{tar} will print out a listing
1400 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1401 forth. This output is described in detail in @ref{verbose member listing}.
1402
1403 If you had used @option{--verbose} (@option{-v}) mode, the example
1404 above would look like:
1405
1406 @smallexample
1407 $ @kbd{tar --list --verbose --file=collection.tar folk}
1408 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1409 @end smallexample
1410
1411 @cindex listing member and file names
1412 @anchor{listing member and file names}
1413 It is important to notice that the output of @kbd{tar --list
1414 --verbose} does not necessarily match that produced by @kbd{tar
1415 --create --verbose} while creating the archive. It is because
1416 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1417 prefixes from file names before storing them in the archive
1418 (@xref{absolute}, for more information). In other
1419 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1420 an archive and @dfn{member names} when listing it. Consider this
1421 example:
1422
1423 @smallexample
1424 @group
1425 $ @kbd{tar cfv archive /etc/mail}
1426 tar: Removing leading `/' from member names
1427 /etc/mail/
1428 /etc/mail/sendmail.cf
1429 /etc/mail/aliases
1430 $ @kbd{tar tf archive}
1431 etc/mail/
1432 etc/mail/sendmail.cf
1433 etc/mail/aliases
1434 @end group
1435 @end smallexample
1436
1437 @opindex show-stored-names
1438 This default behavior can sometimes be inconvenient. You can force
1439 @GNUTAR{} show member names when creating archive by supplying
1440 @option{--show-stored-names} option.
1441
1442 @table @option
1443 @item --show-stored-names
1444 Print member (as opposed to @emph{file}) names when creating the archive.
1445 @end table
1446
1447 @cindex File name arguments, using @option{--list} with
1448 @xopindex{list, using with file name arguments}
1449 You can specify one or more individual member names as arguments when
1450 using @samp{list}. In this case, @command{tar} will only list the
1451 names of members you identify. For example, @w{@kbd{tar --list
1452 --file=afiles.tar apple}} would only print @file{apple}.
1453
1454 Because @command{tar} preserves paths, file names must be specified as
1455 they appear in the archive (i.e., relative to the directory from which
1456 the archive was created). Therefore, it is essential when specifying
1457 member names to @command{tar} that you give the exact member names.
1458 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1459 error message something like @samp{tar: birds: Not found in archive},
1460 because there is no member named @file{birds}, only one named
1461 @file{./birds}. While the names @file{birds} and @file{./birds} name
1462 the same file, @emph{member} names by default are compared verbatim.
1463
1464 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1465 with @file{baboon}, because this exact member name is in the archive file
1466 @file{bfiles.tar}. If you are not sure of the exact file name,
1467 use @dfn{globbing patterns}, for example:
1468
1469 @smallexample
1470 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1471 @end smallexample
1472
1473 @noindent
1474 will list all members whose name contains @samp{b}. @xref{wildcards},
1475 for a detailed discussion of globbing patterns and related
1476 @command{tar} command line options.
1477
1478 @menu
1479 * list dir::
1480 @end menu
1481
1482 @node list dir
1483 @unnumberedsubsec Listing the Contents of a Stored Directory
1484
1485 To get information about the contents of an archived directory,
1486 use the directory name as a file name argument in conjunction with
1487 @option{--list} (@option{-t}). To find out file attributes, include the
1488 @option{--verbose} (@option{-v}) option.
1489
1490 For example, to find out about files in the directory @file{practice}, in
1491 the archive file @file{music.tar}, type:
1492
1493 @smallexample
1494 $ @kbd{tar --list --verbose --file=music.tar practice}
1495 @end smallexample
1496
1497 @command{tar} responds:
1498
1499 @smallexample
1500 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1501 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1502 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1503 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1504 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1505 @end smallexample
1506
1507 When you use a directory name as a file name argument, @command{tar} acts on
1508 all the files (including sub-directories) in that directory.
1509
1510 @node extract
1511 @section How to Extract Members from an Archive
1512 @UNREVISED
1513 @cindex Extraction
1514 @cindex Retrieving files from an archive
1515 @cindex Resurrecting files from an archive
1516
1517 @opindex extract
1518 Creating an archive is only half the job---there is no point in storing
1519 files in an archive if you can't retrieve them. The act of retrieving
1520 members from an archive so they can be used and manipulated as
1521 unarchived files again is called @dfn{extraction}. To extract files
1522 from an archive, use the @option{--extract} (@option{--get} or
1523 @option{-x}) operation. As with @option{--create}, specify the name
1524 of the archive with @option{--file} (@option{-f}) option. Extracting
1525 an archive does not modify the archive in any way; you can extract it
1526 multiple times if you want or need to.
1527
1528 Using @option{--extract}, you can extract an entire archive, or specific
1529 files. The files can be directories containing other files, or not. As
1530 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1531 long form of the operation without affecting the performance.
1532
1533 @menu
1534 * extracting archives::
1535 * extracting files::
1536 * extract dir::
1537 * extracting untrusted archives::
1538 * failing commands::
1539 @end menu
1540
1541 @node extracting archives
1542 @subsection Extracting an Entire Archive
1543
1544 To extract an entire archive, specify the archive file name only, with
1545 no individual file names as arguments. For example,
1546
1547 @smallexample
1548 $ @kbd{tar -xvf collection.tar}
1549 @end smallexample
1550
1551 @noindent
1552 produces this:
1553
1554 @smallexample
1555 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1556 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1557 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1558 @end smallexample
1559
1560 @node extracting files
1561 @subsection Extracting Specific Files
1562
1563 To extract specific archive members, give their exact member names as
1564 arguments, as printed by @option{--list} (@option{-t}). If you had
1565 mistakenly deleted one of the files you had placed in the archive
1566 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1567 from the archive without changing the archive's structure. Its
1568 contents will be identical to the original file @file{blues} that you
1569 deleted.
1570
1571 First, make sure you are in the @file{practice} directory, and list the
1572 files in the directory. Now, delete the file, @samp{blues}, and list
1573 the files in the directory again.
1574
1575 You can now extract the member @file{blues} from the archive file
1576 @file{collection.tar} like this:
1577
1578 @smallexample
1579 $ @kbd{tar --extract --file=collection.tar blues}
1580 @end smallexample
1581
1582 @noindent
1583 If you list the files in the directory again, you will see that the file
1584 @file{blues} has been restored, with its original permissions, data
1585 modification times, and owner.@footnote{This is only accidentally
1586 true, but not in general. Whereas modification times are always
1587 restored, in most cases, one has to be root for restoring the owner,
1588 and use a special option for restoring permissions. Here, it just
1589 happens that the restoring user is also the owner of the archived
1590 members, and that the current @code{umask} is compatible with original
1591 permissions.} (These parameters will be identical to those which
1592 the file had when you originally placed it in the archive; any changes
1593 you may have made before deleting the file from the file system,
1594 however, will @emph{not} have been made to the archive member.) The
1595 archive file, @samp{collection.tar}, is the same as it was before you
1596 extracted @samp{blues}. You can confirm this by running @command{tar} with
1597 @option{--list} (@option{-t}).
1598
1599 Remember that as with other operations, specifying the exact member
1600 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1601 will fail, because there is no member named @file{birds}. To extract
1602 the member named @file{./birds}, you must specify @w{@kbd{tar
1603 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1604 exact member names, use @option{--list} (@option{-t}) option
1605 (@pxref{list}). You can also extract those members that match a
1606 specific @dfn{globbing pattern}. For example, to extract from
1607 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1608 directory prefix, you could type:
1609
1610 @smallexample
1611 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1612 @end smallexample
1613
1614 @noindent
1615 Here, @option{--wildcards} instructs @command{tar} to treat
1616 command line arguments as globbing patterns and @option{--no-anchored}
1617 informs it that the patterns apply to member names after any @samp{/}
1618 delimiter. The use of globbing patterns is discussed in detail in
1619 @xref{wildcards}.
1620
1621 You can extract a file to standard output by combining the above options
1622 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1623 Output}).
1624
1625 If you give the @option{--verbose} option, then @option{--extract}
1626 will print the names of the archive members as it extracts them.
1627
1628 @node extract dir
1629 @subsection Extracting Files that are Directories
1630
1631 Extracting directories which are members of an archive is similar to
1632 extracting other files. The main difference to be aware of is that if
1633 the extracted directory has the same name as any directory already in
1634 the working directory, then files in the extracted directory will be
1635 placed into the directory of the same name. Likewise, if there are
1636 files in the pre-existing directory with the same names as the members
1637 which you extract, the files from the extracted archive will replace
1638 the files already in the working directory (and possible
1639 subdirectories). This will happen regardless of whether or not the
1640 files in the working directory were more recent than those extracted
1641 (there exist, however, special options that alter this behavior
1642 @pxref{Writing}).
1643
1644 However, if a file was stored with a directory name as part of its file
1645 name, and that directory does not exist under the working directory when
1646 the file is extracted, @command{tar} will create the directory.
1647
1648 We can demonstrate how to use @option{--extract} to extract a directory
1649 file with an example. Change to the @file{practice} directory if you
1650 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1651 go back to the parent directory and extract the archive
1652 @file{music.tar}. You may either extract the entire archive, or you may
1653 extract only the files you just deleted. To extract the entire archive,
1654 don't give any file names as arguments after the archive name
1655 @file{music.tar}. To extract only the files you deleted, use the
1656 following command:
1657
1658 @smallexample
1659 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1660 practice/folk
1661 practice/jazz
1662 @end smallexample
1663
1664 @noindent
1665 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1666 would have displayed more detail about the extracted files, as shown
1667 in the example below:
1668
1669 @smallexample
1670 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1671 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1672 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1673 @end smallexample
1674
1675 @noindent
1676 Because you created the directory with @file{practice} as part of the
1677 file names of each of the files by archiving the @file{practice}
1678 directory as @file{practice}, you must give @file{practice} as part
1679 of the file names when you extract those files from the archive.
1680
1681 @node extracting untrusted archives
1682 @subsection Extracting Archives from Untrusted Sources
1683
1684 Extracting files from archives can overwrite files that already exist.
1685 If you receive an archive from an untrusted source, you should make a
1686 new directory and extract into that directory, so that you don't have
1687 to worry about the extraction overwriting one of your existing files.
1688 For example, if @file{untrusted.tar} came from somewhere else on the
1689 Internet, and you don't necessarily trust its contents, you can
1690 extract it as follows:
1691
1692 @smallexample
1693 $ @kbd{mkdir newdir}
1694 $ @kbd{cd newdir}
1695 $ @kbd{tar -xvf ../untrusted.tar}
1696 @end smallexample
1697
1698 It is also a good practice to examine contents of the archive
1699 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1700 with @option{--verbose} (@option{-v}).
1701
1702 @node failing commands
1703 @subsection Commands That Will Fail
1704
1705 Here are some sample commands you might try which will not work, and why
1706 they won't work.
1707
1708 If you try to use this command,
1709
1710 @smallexample
1711 $ @kbd{tar -xvf music.tar folk jazz}
1712 @end smallexample
1713
1714 @noindent
1715 you will get the following response:
1716
1717 @smallexample
1718 tar: folk: Not found in archive
1719 tar: jazz: Not found in archive
1720 $
1721 @end smallexample
1722
1723 @noindent
1724 This is because these files were not originally @emph{in} the parent
1725 directory @file{..}, where the archive is located; they were in the
1726 @file{practice} directory, and their file names reflect this:
1727
1728 @smallexample
1729 $ @kbd{tar -tvf music.tar}
1730 practice/folk
1731 practice/jazz
1732 practice/rock
1733 @end smallexample
1734
1735 @FIXME{make sure the above works when going through the examples in
1736 order...}
1737
1738 @noindent
1739 Likewise, if you try to use this command,
1740
1741 @smallexample
1742 $ @kbd{tar -tvf music.tar folk jazz}
1743 @end smallexample
1744
1745 @noindent
1746 you would get a similar response. Members with those names are not in the
1747 archive. You must use the correct member names, or wildcards, in order
1748 to extract the files from the archive.
1749
1750 If you have forgotten the correct names of the files in the archive,
1751 use @w{@kbd{tar --list --verbose}} to list them correctly.
1752
1753 @FIXME{more examples, here? hag thinks it's a good idea.}
1754
1755 @node going further
1756 @section Going Further Ahead in this Manual
1757
1758 @FIXME{need to write up a node here about the things that are going to
1759 be in the rest of the manual.}
1760
1761 @node tar invocation
1762 @chapter Invoking @GNUTAR{}
1763 @UNREVISED
1764
1765 This chapter is about how one invokes the @GNUTAR{}
1766 command, from the command synopsis (@pxref{Synopsis}). There are
1767 numerous options, and many styles for writing them. One mandatory
1768 option specifies the operation @command{tar} should perform
1769 (@pxref{Operation Summary}), other options are meant to detail how
1770 this operation should be performed (@pxref{Option Summary}).
1771 Non-option arguments are not always interpreted the same way,
1772 depending on what the operation is.
1773
1774 You will find in this chapter everything about option styles and rules for
1775 writing them (@pxref{Styles}). On the other hand, operations and options
1776 are fully described elsewhere, in other chapters. Here, you will find
1777 only synthetic descriptions for operations and options, together with
1778 pointers to other parts of the @command{tar} manual.
1779
1780 Some options are so special they are fully described right in this
1781 chapter. They have the effect of inhibiting the normal operation of
1782 @command{tar} or else, they globally alter the amount of feedback the user
1783 receives about what is going on. These are the @option{--help} and
1784 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1785 and @option{--interactive} options (@pxref{interactive}).
1786
1787 @menu
1788 * Synopsis::
1789 * using tar options::
1790 * Styles::
1791 * All Options::
1792 * help::
1793 * defaults::
1794 * verbose::
1795 * interactive::
1796 @end menu
1797
1798 @node Synopsis
1799 @section General Synopsis of @command{tar}
1800
1801 The @GNUTAR{} program is invoked as either one of:
1802
1803 @smallexample
1804 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1805 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1806 @end smallexample
1807
1808 The second form is for when old options are being used.
1809
1810 You can use @command{tar} to store files in an archive, to extract them from
1811 an archive, and to do other types of archive manipulation. The primary
1812 argument to @command{tar}, which is called the @dfn{operation}, specifies
1813 which action to take. The other arguments to @command{tar} are either
1814 @dfn{options}, which change the way @command{tar} performs an operation,
1815 or file names or archive members, which specify the files or members
1816 @command{tar} is to act on.
1817
1818 You can actually type in arguments in any order, even if in this manual
1819 the options always precede the other arguments, to make examples easier
1820 to understand. Further, the option stating the main operation mode
1821 (the @command{tar} main command) is usually given first.
1822
1823 Each @var{name} in the synopsis above is interpreted as an archive member
1824 name when the main command is one of @option{--compare}
1825 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1826 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1827 @option{--update} (@option{-u}). When naming archive members, you
1828 must give the exact name of the member in the archive, as it is
1829 printed by @option{--list}. For @option{--append} (@option{-r}) and
1830 @option{--create} (@option{-c}), these @var{name} arguments specify
1831 the names of either files or directory hierarchies to place in the archive.
1832 These files or hierarchies should already exist in the file system,
1833 prior to the execution of the @command{tar} command.
1834
1835 @command{tar} interprets relative file names as being relative to the
1836 working directory. @command{tar} will make all file names relative
1837 (by removing leading slashes when archiving or restoring files),
1838 unless you specify otherwise (using the @option{--absolute-names}
1839 option). @xref{absolute}, for more information about
1840 @option{--absolute-names}.
1841
1842 If you give the name of a directory as either a file name or a member
1843 name, then @command{tar} acts recursively on all the files and directories
1844 beneath that directory. For example, the name @file{/} identifies all
1845 the files in the file system to @command{tar}.
1846
1847 The distinction between file names and archive member names is especially
1848 important when shell globbing is used, and sometimes a source of confusion
1849 for newcomers. @xref{wildcards}, for more information about globbing.
1850 The problem is that shells may only glob using existing files in the
1851 file system. Only @command{tar} itself may glob on archive members, so when
1852 needed, you must ensure that wildcard characters reach @command{tar} without
1853 being interpreted by the shell first. Using a backslash before @samp{*}
1854 or @samp{?}, or putting the whole argument between quotes, is usually
1855 sufficient for this.
1856
1857 Even if @var{name}s are often specified on the command line, they
1858 can also be read from a text file in the file system, using the
1859 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1860
1861 If you don't use any file name arguments, @option{--append} (@option{-r}),
1862 @option{--delete} and @option{--concatenate} (@option{--catenate},
1863 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1864 will usually yield a diagnostic and inhibit @command{tar} execution.
1865 The other operations of @command{tar} (@option{--list},
1866 @option{--extract}, @option{--compare}, and @option{--update})
1867 will act on the entire contents of the archive.
1868
1869 @cindex exit status
1870 @cindex return status
1871 Besides successful exits, @GNUTAR{} may fail for
1872 many reasons. Some reasons correspond to bad usage, that is, when the
1873 @command{tar} command is improperly written. Errors may be
1874 encountered later, while encountering an error processing the archive
1875 or the files. Some errors are recoverable, in which case the failure
1876 is delayed until @command{tar} has completed all its work. Some
1877 errors are such that it would not meaningful, or at least risky, to
1878 continue processing: @command{tar} then aborts processing immediately.
1879 All abnormal exits, whether immediate or delayed, should always be
1880 clearly diagnosed on @code{stderr}, after a line stating the nature of
1881 the error.
1882
1883 @GNUTAR{} returns only a few exit statuses. I'm really
1884 aiming simplicity in that area, for now. If you are not using the
1885 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1886 that everything went well, besides maybe innocuous warnings. Nonzero
1887 means that something went wrong. Right now, as of today, ``nonzero''
1888 is almost always 2, except for remote operations, where it may be
1889 128.
1890
1891 @node using tar options
1892 @section Using @command{tar} Options
1893
1894 @GNUTAR{} has a total of eight operating modes which
1895 allow you to perform a variety of tasks. You are required to choose
1896 one operating mode each time you employ the @command{tar} program by
1897 specifying one, and only one operation as an argument to the
1898 @command{tar} command (two lists of four operations each may be found
1899 at @ref{frequent operations} and @ref{Operations}). Depending on
1900 circumstances, you may also wish to customize how the chosen operating
1901 mode behaves. For example, you may wish to change the way the output
1902 looks, or the format of the files that you wish to archive may require
1903 you to do something special in order to make the archive look right.
1904
1905 You can customize and control @command{tar}'s performance by running
1906 @command{tar} with one or more options (such as @option{--verbose}
1907 (@option{-v}), which we used in the tutorial). As we said in the
1908 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1909 their name suggests) optional. Depending on the operating mode, you
1910 may specify one or more options. Different options will have different
1911 effects, but in general they all change details of the operation, such
1912 as archive format, archive name, or level of user interaction. Some
1913 options make sense with all operating modes, while others are
1914 meaningful only with particular modes. You will likely use some
1915 options frequently, while you will only use others infrequently, or
1916 not at all. (A full list of options is available in @pxref{All Options}.)
1917
1918 @vrindex TAR_OPTIONS, environment variable
1919 @anchor{TAR_OPTIONS}
1920 The @env{TAR_OPTIONS} environment variable specifies default options to
1921 be placed in front of any explicit options. For example, if
1922 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1923 if the two options @option{-v} and @option{--unlink-first} had been
1924 specified before any explicit options. Option specifications are
1925 separated by whitespace. A backslash escapes the next character, so it
1926 can be used to specify an option containing whitespace or a backslash.
1927
1928 Note that @command{tar} options are case sensitive. For example, the
1929 options @option{-T} and @option{-t} are different; the first requires an
1930 argument for stating the name of a file providing a list of @var{name}s,
1931 while the second does not require an argument and is another way to
1932 write @option{--list} (@option{-t}).
1933
1934 In addition to the eight operations, there are many options to
1935 @command{tar}, and three different styles for writing both: long (mnemonic)
1936 form, short form, and old style. These styles are discussed below.
1937 Both the options and the operations can be written in any of these three
1938 styles.
1939
1940 @FIXME{menu at end of this node. need to think of an actual outline
1941 for this chapter; probably do that after stuff from chapter 4 is
1942 incorporated.}
1943
1944 @node Styles
1945 @section The Three Option Styles
1946
1947 There are three styles for writing operations and options to the command
1948 line invoking @command{tar}. The different styles were developed at
1949 different times during the history of @command{tar}. These styles will be
1950 presented below, from the most recent to the oldest.
1951
1952 Some options must take an argument. (For example, @option{--file}
1953 (@option{-f})) takes the name of an archive file as an argument. If
1954 you do not supply an archive file name, @command{tar} will use a
1955 default, but this can be confusing; thus, we recommend that you always
1956 supply a specific archive file name.) Where you @emph{place} the
1957 arguments generally depends on which style of options you choose. We
1958 will detail specific information relevant to each option style in the
1959 sections on the different option styles, below. The differences are
1960 subtle, yet can often be very important; incorrect option placement
1961 can cause you to overwrite a number of important files. We urge you
1962 to note these differences, and only use the option style(s) which
1963 makes the most sense to you until you feel comfortable with the others.
1964
1965 Some options @emph{may} take an argument (currently, there are
1966 two such options: @option{--backup} and @option{--occurrence}). Such
1967 options may have at most long and short forms, they do not have old style
1968 equivalent. The rules for specifying an argument for such options
1969 are stricter than those for specifying mandatory arguments. Please,
1970 pay special attention to them.
1971
1972 @menu
1973 * Long Options:: Long Option Style
1974 * Short Options:: Short Option Style
1975 * Old Options:: Old Option Style
1976 * Mixing:: Mixing Option Styles
1977 @end menu
1978
1979 @node Long Options
1980 @subsection Long Option Style
1981
1982 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
1983 dashes in a row, e.g., @option{--list}. The long names are more clear than
1984 their corresponding short or old names. It sometimes happens that a
1985 single long option has many different different names which are
1986 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1987 long option names can be given unique abbreviations. For example,
1988 @option{--cre} can be used in place of @option{--create} because there is no
1989 other long option which begins with @samp{cre}. (One way to find
1990 this out is by trying it and seeing what happens; if a particular
1991 abbreviation could represent more than one option, @command{tar} will tell
1992 you that that abbreviation is ambiguous and you'll know that that
1993 abbreviation won't work. You may also choose to run @samp{tar --help}
1994 to see a list of options. Be aware that if you run @command{tar} with a
1995 unique abbreviation for the long name of an option you didn't want to
1996 use, you are stuck; @command{tar} will perform the command as ordered.)
1997
1998 Long options are meant to be obvious and easy to remember, and their
1999 meanings are generally easier to discern than those of their
2000 corresponding short options (see below). For example:
2001
2002 @smallexample
2003 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2004 @end smallexample
2005
2006 @noindent
2007 gives a fairly good set of hints about what the command does, even
2008 for those not fully acquainted with @command{tar}.
2009
2010 Long options which require arguments take those arguments
2011 immediately following the option name. There are two ways of
2012 specifying a mandatory argument. It can be separated from the
2013 option name either by an equal sign, or by any amount of
2014 white space characters. For example, the @option{--file} option (which
2015 tells the name of the @command{tar} archive) is given a file such as
2016 @file{archive.tar} as argument by using any of the following notations:
2017 @option{--file=archive.tar} or @option{--file archive.tar}.
2018
2019 In contrast, optional arguments must always be introduced using
2020 an equal sign. For example, the @option{--backup} option takes
2021 an optional argument specifying backup type. It must be used
2022 as @option{--backup=@var{backup-type}}.
2023
2024 @node Short Options
2025 @subsection Short Option Style
2026
2027 Most options also have a @dfn{short option} name. Short options start with
2028 a single dash, and are followed by a single character, e.g., @option{-t}
2029 (which is equivalent to @option{--list}). The forms are absolutely
2030 identical in function; they are interchangeable.
2031
2032 The short option names are faster to type than long option names.
2033
2034 Short options which require arguments take their arguments immediately
2035 following the option, usually separated by white space. It is also
2036 possible to stick the argument right after the short option name, using
2037 no intervening space. For example, you might write @w{@option{-f
2038 archive.tar}} or @option{-farchive.tar} instead of using
2039 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2040 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2041 specific archive, here named @file{archive.tar}.
2042
2043 Short options which take optional arguments take their arguments
2044 immediately following the option letter, @emph{without any intervening
2045 white space characters}.
2046
2047 Short options' letters may be clumped together, but you are not
2048 required to do this (as compared to old options; see below). When
2049 short options are clumped as a set, use one (single) dash for them
2050 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2051 such a set is allowed to have an argument@footnote{Clustering many
2052 options, the last of which has an argument, is a rather opaque way to
2053 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2054 even be made helpful enough for considering such usages as invalid.}.
2055
2056 When the options are separated, the argument for each option which requires
2057 an argument directly follows that option, as is usual for Unix programs.
2058 For example:
2059
2060 @smallexample
2061 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2062 @end smallexample
2063
2064 If you reorder short options' locations, be sure to move any arguments
2065 that belong to them. If you do not move the arguments properly, you may
2066 end up overwriting files.
2067
2068 @node Old Options
2069 @subsection Old Option Style
2070 @UNREVISED
2071
2072 Like short options, @dfn{old options} are single letters. However, old options
2073 must be written together as a single clumped set, without spaces separating
2074 them or dashes preceding them@footnote{Beware that if you precede options
2075 with a dash, you are announcing the short option style instead of the
2076 old option style; short options are decoded differently.}. This set
2077 of letters must be the first to appear on the command line, after the
2078 @command{tar} program name and some white space; old options cannot appear
2079 anywhere else. The letter of an old option is exactly the same letter as
2080 the corresponding short option. For example, the old option @samp{t} is
2081 the same as the short option @option{-t}, and consequently, the same as the
2082 long option @option{--list}. So for example, the command @w{@samp{tar
2083 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2084
2085 When options that need arguments are given together with the command,
2086 all the associated arguments follow, in the same order as the options.
2087 Thus, the example given previously could also be written in the old
2088 style as follows:
2089
2090 @smallexample
2091 $ @kbd{tar cvbf 20 /dev/rmt0}
2092 @end smallexample
2093
2094 @noindent
2095 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2096 the argument of @option{-f}.
2097
2098 On the other hand, this old style syntax makes it difficult to match
2099 option letters with their corresponding arguments, and is often
2100 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2101 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2102 argument for @option{-f}, and @option{-v} does not have a corresponding
2103 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2104 /dev/rmt0}} is clearer, putting all arguments next to the option they
2105 pertain to.
2106
2107 If you want to reorder the letters in the old option argument, be
2108 sure to reorder any corresponding argument appropriately.
2109
2110 This old way of writing @command{tar} options can surprise even experienced
2111 users. For example, the two commands:
2112
2113 @smallexample
2114 @kbd{tar cfz archive.tar.gz file}
2115 @kbd{tar -cfz archive.tar.gz file}
2116 @end smallexample
2117
2118 @noindent
2119 are quite different. The first example uses @file{archive.tar.gz} as
2120 the value for option @samp{f} and recognizes the option @samp{z}. The
2121 second example, however, uses @file{z} as the value for option
2122 @samp{f} --- probably not what was intended.
2123
2124 Old options are kept for compatibility with old versions of @command{tar}.
2125
2126 This second example could be corrected in many ways, among which the
2127 following are equivalent:
2128
2129 @smallexample
2130 @kbd{tar -czf archive.tar.gz file}
2131 @kbd{tar -cf archive.tar.gz -z file}
2132 @kbd{tar cf archive.tar.gz -z file}
2133 @end smallexample
2134
2135 @cindex option syntax, traditional
2136 As far as we know, all @command{tar} programs, @acronym{GNU} and
2137 non-@acronym{GNU}, support old options. @GNUTAR{}
2138 supports them not only for historical reasons, but also because many
2139 people are used to them. For compatibility with Unix @command{tar},
2140 the first argument is always treated as containing command and option
2141 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2142 equivalent to @w{@samp{tar -c}:} both of them specify the
2143 @option{--create} (@option{-c}) command to create an archive.
2144
2145 @node Mixing
2146 @subsection Mixing Option Styles
2147
2148 All three styles may be intermixed in a single @command{tar} command,
2149 so long as the rules for each style are fully
2150 respected@footnote{Before @GNUTAR{} version 1.11.6,
2151 a bug prevented intermixing old style options with long options in
2152 some cases.}. Old style options and either of the modern styles of
2153 options may be mixed within a single @command{tar} command. However,
2154 old style options must be introduced as the first arguments only,
2155 following the rule for old options (old options must appear directly
2156 after the @command{tar} command and some white space). Modern options
2157 may be given only after all arguments to the old options have been
2158 collected. If this rule is not respected, a modern option might be
2159 falsely interpreted as the value of the argument to one of the old
2160 style options.
2161
2162 For example, all the following commands are wholly equivalent, and
2163 illustrate the many combinations and orderings of option styles.
2164
2165 @smallexample
2166 @kbd{tar --create --file=archive.tar}
2167 @kbd{tar --create -f archive.tar}
2168 @kbd{tar --create -farchive.tar}
2169 @kbd{tar --file=archive.tar --create}
2170 @kbd{tar --file=archive.tar -c}
2171 @kbd{tar -c --file=archive.tar}
2172 @kbd{tar -c -f archive.tar}
2173 @kbd{tar -c -farchive.tar}
2174 @kbd{tar -cf archive.tar}
2175 @kbd{tar -cfarchive.tar}
2176 @kbd{tar -f archive.tar --create}
2177 @kbd{tar -f archive.tar -c}
2178 @kbd{tar -farchive.tar --create}
2179 @kbd{tar -farchive.tar -c}
2180 @kbd{tar c --file=archive.tar}
2181 @kbd{tar c -f archive.tar}
2182 @kbd{tar c -farchive.tar}
2183 @kbd{tar cf archive.tar}
2184 @kbd{tar f archive.tar --create}
2185 @kbd{tar f archive.tar -c}
2186 @kbd{tar fc archive.tar}
2187 @end smallexample
2188
2189 On the other hand, the following commands are @emph{not} equivalent to
2190 the previous set:
2191
2192 @smallexample
2193 @kbd{tar -f -c archive.tar}
2194 @kbd{tar -fc archive.tar}
2195 @kbd{tar -fcarchive.tar}
2196 @kbd{tar -farchive.tarc}
2197 @kbd{tar cfarchive.tar}
2198 @end smallexample
2199
2200 @noindent
2201 These last examples mean something completely different from what the
2202 user intended (judging based on the example in the previous set which
2203 uses long options, whose intent is therefore very clear). The first
2204 four specify that the @command{tar} archive would be a file named
2205 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2206 respectively. The first two examples also specify a single non-option,
2207 @var{name} argument having the value @samp{archive.tar}. The last
2208 example contains only old style option letters (repeating option
2209 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2210 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2211 the first sentence of this paragraph..}
2212
2213 @node All Options
2214 @section All @command{tar} Options
2215
2216 The coming manual sections contain an alphabetical listing of all
2217 @command{tar} operations and options, with brief descriptions and cross
2218 references to more in-depth explanations in the body of the manual.
2219 They also contain an alphabetically arranged table of the short option
2220 forms with their corresponding long option. You can use this table as
2221 a reference for deciphering @command{tar} commands in scripts.
2222
2223 @menu
2224 * Operation Summary::
2225 * Option Summary::
2226 * Short Option Summary::
2227 @end menu
2228
2229 @node Operation Summary
2230 @subsection Operations
2231
2232 @table @option
2233
2234 @opsummary{append}
2235 @item --append
2236 @itemx -r
2237
2238 Appends files to the end of the archive. @xref{append}.
2239
2240 @opsummary{catenate}
2241 @item --catenate
2242 @itemx -A
2243
2244 Same as @option{--concatenate}. @xref{concatenate}.
2245
2246 @opsummary{compare}
2247 @item --compare
2248 @itemx -d
2249
2250 Compares archive members with their counterparts in the file
2251 system, and reports differences in file size, mode, owner,
2252 modification date and contents. @xref{compare}.
2253
2254 @opsummary{concatenate}
2255 @item --concatenate
2256 @itemx -A
2257
2258 Appends other @command{tar} archives to the end of the archive.
2259 @xref{concatenate}.
2260
2261 @opsummary{create}
2262 @item --create
2263 @itemx -c
2264
2265 Creates a new @command{tar} archive. @xref{create}.
2266
2267 @opsummary{delete}
2268 @item --delete
2269
2270 Deletes members from the archive. Don't try this on a archive on a
2271 tape! @xref{delete}.
2272
2273 @opsummary{diff}
2274 @item --diff
2275 @itemx -d
2276
2277 Same @option{--compare}. @xref{compare}.
2278
2279 @opsummary{extract}
2280 @item --extract
2281 @itemx -x
2282
2283 Extracts members from the archive into the file system. @xref{extract}.
2284
2285 @opsummary{get}
2286 @item --get
2287 @itemx -x
2288
2289 Same as @option{--extract}. @xref{extract}.
2290
2291 @opsummary{list}
2292 @item --list
2293 @itemx -t
2294
2295 Lists the members in an archive. @xref{list}.
2296
2297 @opsummary{update}
2298 @item --update
2299 @itemx -u
2300
2301 Adds files to the end of the archive, but only if they are newer than
2302 their counterparts already in the archive, or if they do not already
2303 exist in the archive. @xref{update}.
2304
2305 @end table
2306
2307 @node Option Summary
2308 @subsection @command{tar} Options
2309
2310 @table @option
2311
2312 @opsummary{absolute-names}
2313 @item --absolute-names
2314 @itemx -P
2315
2316 Normally when creating an archive, @command{tar} strips an initial
2317 @samp{/} from member names. This option disables that behavior.
2318 @xref{absolute}.
2319
2320 @opsummary{after-date}
2321 @item --after-date
2322
2323 (See @option{--newer}, @pxref{after})
2324
2325 @opsummary{anchored}
2326 @item --anchored
2327 A pattern must match an initial subsequence of the name's components.
2328 @xref{controlling pattern-matching}.
2329
2330 @opsummary{atime-preserve}
2331 @item --atime-preserve
2332 @itemx --atime-preserve=replace
2333 @itemx --atime-preserve=system
2334
2335 Attempt to preserve the access time of files when reading them. This
2336 option currently is effective only on files that you own, unless you
2337 have superuser privileges.
2338
2339 @option{--atime-preserve=replace} remembers the access time of a file
2340 before reading it, and then restores the access time afterwards. This
2341 may cause problems if other programs are reading the file at the same
2342 time, as the times of their accesses will be lost. On most platforms
2343 restoring the access time also requires @command{tar} to restore the
2344 data modification time too, so this option may also cause problems if
2345 other programs are writing the file at the same time. (Tar attempts
2346 to detect this situation, but cannot do so reliably due to race
2347 conditions.) Worse, on most platforms restoring the access time also
2348 updates the status change time, which means that this option is
2349 incompatible with incremental backups.
2350
2351 @option{--atime-preserve=system} avoids changing time stamps on files,
2352 without interfering with time stamp updates
2353 caused by other programs, so it works better with incremental backups.
2354 However, it requires a special @code{O_NOATIME} option from the
2355 underlying operating and file system implementation, and it also requires
2356 that searching directories does not update their access times. As of
2357 this writing (November 2005) this works only with Linux, and only with
2358 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2359 way to know whether this feature actually works. Sometimes
2360 @command{tar} knows that it does not work, and if you use
2361 @option{--atime-preserve=system} then @command{tar} complains and
2362 exits right away. But other times @command{tar} might think that the
2363 option works when it actually does not.
2364
2365 Currently @option{--atime-preserve} with no operand defaults to
2366 @option{--atime-preserve=replace}, but this may change in the future
2367 as support for @option{--atime-preserve=system} improves.
2368
2369 If your operating system does not support
2370 @option{--atime-preserve=@-system}, you might be able to preserve access
2371 times reliably by by using the @command{mount} command. For example,
2372 you can mount the file system read-only, or access the file system via
2373 a read-only loopback mount, or use the @samp{noatime} mount option
2374 available on some systems. However, mounting typically requires
2375 superuser privileges and can be a pain to manage.
2376
2377 @opsummary{backup}
2378 @item --backup=@var{backup-type}
2379
2380 Rather than deleting files from the file system, @command{tar} will
2381 back them up using simple or numbered backups, depending upon
2382 @var{backup-type}. @xref{backup}.
2383
2384 @opsummary{block-number}
2385 @item --block-number
2386 @itemx -R
2387
2388 With this option present, @command{tar} prints error messages for read errors
2389 with the block number in the archive file. @xref{block-number}.
2390
2391 @opsummary{blocking-factor}
2392 @item --blocking-factor=@var{blocking}
2393 @itemx -b @var{blocking}
2394
2395 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2396 record. @xref{Blocking Factor}.
2397
2398 @opsummary{bzip2}
2399 @item --bzip2
2400 @itemx -j
2401
2402 This option tells @command{tar} to read or write archives through
2403 @code{bzip2}. @xref{gzip}.
2404
2405 @opsummary{checkpoint}
2406 @item --checkpoint[=@var{number}]
2407
2408 This option directs @command{tar} to print periodic checkpoint
2409 messages as it reads through the archive. It is intended for when you
2410 want a visual indication that @command{tar} is still running, but
2411 don't want to see @option{--verbose} output. For a detailed
2412 description, see @ref{Progress information}.
2413
2414 @opsummary{check-links}
2415 @item --check-links
2416 @itemx -l
2417 If this option was given, @command{tar} will check the number of links
2418 dumped for each processed file. If this number does not match the
2419 total number of hard links for the file, a warning message will be
2420 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2421 synonym for @option{--one-file-system}. The current semantics, which
2422 complies to UNIX98, was introduced with version
2423 1.15.91. @xref{Changes}, for more information.}.
2424
2425 @opsummary{compress}
2426 @opsummary{uncompress}
2427 @item --compress
2428 @itemx --uncompress
2429 @itemx -Z
2430
2431 @command{tar} will use the @command{compress} program when reading or
2432 writing the archive. This allows you to directly act on archives
2433 while saving space. @xref{gzip}.
2434
2435 @opsummary{confirmation}
2436 @item --confirmation
2437
2438 (See @option{--interactive}.) @xref{interactive}.
2439
2440 @opsummary{delay-directory-restore}
2441 @item --delay-directory-restore
2442
2443 Delay setting modification times and permissions of extracted
2444 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2445
2446 @opsummary{dereference}
2447 @item --dereference
2448 @itemx -h
2449
2450 When creating a @command{tar} archive, @command{tar} will archive the
2451 file that a symbolic link points to, rather than archiving the
2452 symlink. @xref{dereference}.
2453
2454 @opsummary{directory}
2455 @item --directory=@var{dir}
2456 @itemx -C @var{dir}
2457
2458 When this option is specified, @command{tar} will change its current directory
2459 to @var{dir} before performing any operations. When this option is used
2460 during archive creation, it is order sensitive. @xref{directory}.
2461
2462 @opsummary{exclude}
2463 @item --exclude=@var{pattern}
2464
2465 When performing operations, @command{tar} will skip files that match
2466 @var{pattern}. @xref{exclude}.
2467
2468 @opsummary{exclude-from}
2469 @item --exclude-from=@var{file}
2470 @itemx -X @var{file}
2471
2472 Similar to @option{--exclude}, except @command{tar} will use the list of
2473 patterns in the file @var{file}. @xref{exclude}.
2474
2475 @opsummary{exclude-caches}
2476 @item --exclude-caches
2477
2478 Automatically excludes all directories
2479 containing a cache directory tag. @xref{exclude}.
2480
2481 @opsummary{file}
2482 @item --file=@var{archive}
2483 @itemx -f @var{archive}
2484
2485 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2486 performs operations on, rather than @command{tar}'s compilation dependent
2487 default. @xref{file tutorial}.
2488
2489 @opsummary{files-from}
2490 @item --files-from=@var{file}
2491 @itemx -T @var{file}
2492
2493 @command{tar} will use the contents of @var{file} as a list of archive members
2494 or files to operate on, in addition to those specified on the
2495 command-line. @xref{files}.
2496
2497 @opsummary{force-local}
2498 @item --force-local
2499
2500 Forces @command{tar} to interpret the filename given to @option{--file}
2501 as a local file, even if it looks like a remote tape drive name.
2502 @xref{local and remote archives}.
2503
2504 @opsummary{format}
2505 @item --format=@var{format}
2506 @itemx -H @var{format}
2507
2508 Selects output archive format. @var{Format} may be one of the
2509 following:
2510
2511 @table @samp
2512 @item v7
2513 Creates an archive that is compatible with Unix V7 @command{tar}.
2514
2515 @item oldgnu
2516 Creates an archive that is compatible with GNU @command{tar} version
2517 1.12 or earlier.
2518
2519 @item gnu
2520 Creates archive in GNU tar 1.13 format. Basically it is the same as
2521 @samp{oldgnu} with the only difference in the way it handles long
2522 numeric fields.
2523
2524 @item ustar
2525 Creates a @acronym{POSIX.1-1988} compatible archive.
2526
2527 @item posix
2528 Creates a @acronym{POSIX.1-2001 archive}.
2529
2530 @end table
2531
2532 @xref{Formats}, for a detailed discussion of these formats.
2533
2534 @opsummary{group}
2535 @item --group=@var{group}
2536
2537 Files added to the @command{tar} archive will have a group id of @var{group},
2538 rather than the group from the source file. @var{group} is first decoded
2539 as a group symbolic name, but if this interpretation fails, it has to be
2540 a decimal numeric group ID. @xref{override}.
2541
2542 Also see the comments for the @option{--owner=@var{user}} option.
2543
2544 @opsummary{gzip}
2545 @opsummary{gunzip}
2546 @opsummary{ungzip}
2547 @item --gzip
2548 @itemx --gunzip
2549 @itemx --ungzip
2550 @itemx -z
2551
2552 This option tells @command{tar} to read or write archives through
2553 @command{gzip}, allowing @command{tar} to directly operate on several
2554 kinds of compressed archives transparently. @xref{gzip}.
2555
2556 @opsummary{help}
2557 @item --help
2558 @itemx -?
2559
2560 @command{tar} will print out a short message summarizing the operations and
2561 options to @command{tar} and exit. @xref{help}.
2562
2563 @opsummary{ignore-case}
2564 @item --ignore-case
2565 Ignore case when matching member or file names with
2566 patterns. @xref{controlling pattern-matching}.
2567
2568 @opsummary{ignore-command-error}
2569 @item --ignore-command-error
2570 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2571
2572 @opsummary{ignore-failed-read}
2573 @item --ignore-failed-read
2574
2575 Do not exit unsuccessfully merely because an unreadable file was encountered.
2576 @xref{Reading}.
2577
2578 @opsummary{ignore-zeros}
2579 @item --ignore-zeros
2580 @itemx -i
2581
2582 With this option, @command{tar} will ignore zeroed blocks in the
2583 archive, which normally signals EOF. @xref{Reading}.
2584
2585 @opsummary{incremental}
2586 @item --incremental
2587 @itemx -G
2588
2589 Used to inform @command{tar} that it is working with an old
2590 @acronym{GNU}-format incremental backup archive. It is intended
2591 primarily for backwards compatibility only. @xref{Incremental Dumps},
2592 for a detailed discussion of incremental archives.
2593
2594 @opsummary{index-file}
2595 @item --index-file=@var{file}
2596
2597 Send verbose output to @var{file} instead of to standard output.
2598
2599 @opsummary{info-script}
2600 @opsummary{new-volume-script}
2601 @item --info-script=@var{script-file}
2602 @itemx --new-volume-script=@var{script-file}
2603 @itemx -F @var{script-file}
2604
2605 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2606 at the end of each tape. If @var{script-file} exits with nonzero status,
2607 @command{tar} fails immediately. @xref{info-script}, for a detailed
2608 discussion of @var{script-file}.
2609
2610 @opsummary{interactive}
2611 @item --interactive
2612 @itemx --confirmation
2613 @itemx -w
2614
2615 Specifies that @command{tar} should ask the user for confirmation before
2616 performing potentially destructive options, such as overwriting files.
2617 @xref{interactive}.
2618
2619 @opsummary{keep-newer-files}
2620 @item --keep-newer-files
2621
2622 Do not replace existing files that are newer than their archive copies
2623 when extracting files from an archive.
2624
2625 @opsummary{keep-old-files}
2626 @item --keep-old-files
2627 @itemx -k
2628
2629 Do not overwrite existing files when extracting files from an archive.
2630 @xref{Keep Old Files}.
2631
2632 @opsummary{label}
2633 @item --label=@var{name}
2634 @itemx -V @var{name}
2635
2636 When creating an archive, instructs @command{tar} to write @var{name}
2637 as a name record in the archive. When extracting or listing archives,
2638 @command{tar} will only operate on archives that have a label matching
2639 the pattern specified in @var{name}. @xref{Tape Files}.
2640
2641 @opsummary{listed-incremental}
2642 @item --listed-incremental=@var{snapshot-file}
2643 @itemx -g @var{snapshot-file}
2644
2645 During a @option{--create} operation, specifies that the archive that
2646 @command{tar} creates is a new @acronym{GNU}-format incremental
2647 backup, using @var{snapshot-file} to determine which files to backup.
2648 With other operations, informs @command{tar} that the archive is in
2649 incremental format. @xref{Incremental Dumps}.
2650
2651 @opsummary{mode}
2652 @item --mode=@var{permissions}
2653
2654 When adding files to an archive, @command{tar} will use
2655 @var{permissions} for the archive members, rather than the permissions
2656 from the files. @var{permissions} can be specified either as an octal
2657 number or as symbolic permissions, like with
2658 @command{chmod}. @xref{override}.
2659
2660 @opsummary{mtime}
2661 @item --mtime=@var{date}
2662
2663 When adding files to an archive, @command{tar} will use @var{date} as
2664 the modification time of members when creating archives, instead of
2665 their actual modification times. The value of @var{date} can be
2666 either a textual date representation (@pxref{Date input formats}) or a
2667 name of the existing file, starting with @samp{/} or @samp{.}. In the
2668 latter case, the modification time of that file is used. @xref{override}.
2669
2670 @opsummary{multi-volume}
2671 @item --multi-volume
2672 @itemx -M
2673
2674 Informs @command{tar} that it should create or otherwise operate on a
2675 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2676
2677 @opsummary{new-volume-script}
2678 @item --new-volume-script
2679
2680 (see --info-script)
2681
2682 @opsummary{seek}
2683 @item --seek
2684 @itemx -n
2685
2686 Assume that the archive media supports seeks to arbitrary
2687 locations. Usually @command{tar} determines automatically whether
2688 the archive can be seeked or not. This option is intended for use
2689 in cases when such recognition fails.
2690
2691 @opsummary{newer}
2692 @item --newer=@var{date}
2693 @itemx --after-date=@var{date}
2694 @itemx -N
2695
2696 When creating an archive, @command{tar} will only add files that have changed
2697 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2698 is taken to be the name of a file whose data modification time specifies
2699 the date. @xref{after}.
2700
2701 @opsummary{newer-mtime}
2702 @item --newer-mtime=@var{date}
2703
2704 Like @option{--newer}, but add only files whose
2705 contents have changed (as opposed to just @option{--newer}, which will
2706 also back up files for which any status information has
2707 changed). @xref{after}.
2708
2709 @opsummary{no-anchored}
2710 @item --no-anchored
2711 An exclude pattern can match any subsequence of the name's components.
2712 @xref{controlling pattern-matching}.
2713
2714 @opsummary{no-delay-directory-restore}
2715 @item --no-delay-directory-restore
2716
2717 Setting modification times and permissions of extracted
2718 directories when all files from this directory has been
2719 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2720
2721 @opsummary{no-ignore-case}
2722 @item --no-ignore-case
2723 Use case-sensitive matching.
2724 @xref{controlling pattern-matching}.
2725
2726 @opsummary{no-ignore-command-error}
2727 @item --no-ignore-command-error
2728 Print warnings about subprocesses terminated with a non-zero exit
2729 code. @xref{Writing to an External Program}.
2730
2731 @opsummary{no-overwrite-dir}
2732 @item --no-overwrite-dir
2733
2734 Preserve metadata of existing directories when extracting files
2735 from an archive. @xref{Overwrite Old Files}.
2736
2737 @opsummary{no-quote-chars}
2738 @item --no-quote-chars=@var{string}
2739 Remove characters listed in @var{string} from the list of quoted
2740 characters set by the previous @option{--quote-chars} option
2741 (@pxref{quoting styles}).
2742
2743 @opsummary{no-recursion}
2744 @item --no-recursion
2745
2746 With this option, @command{tar} will not recurse into directories.
2747 @xref{recurse}.
2748
2749 @opsummary{no-same-owner}
2750 @item --no-same-owner
2751 @itemx -o
2752
2753 When extracting an archive, do not attempt to preserve the owner
2754 specified in the @command{tar} archive. This the default behavior
2755 for ordinary users.
2756
2757 @opsummary{no-same-permissions}
2758 @item --no-same-permissions
2759
2760 When extracting an archive, subtract the user's umask from files from
2761 the permissions specified in the archive. This is the default behavior
2762 for ordinary users.
2763
2764 @opsummary{no-unquote}
2765 @item --no-unquote
2766 Treat all input file or member names literally, do not interpret
2767 escape sequences. @xref{input name quoting}.
2768
2769 @opsummary{no-wildcards}
2770 @item --no-wildcards
2771 Do not use wildcards.
2772 @xref{controlling pattern-matching}.
2773
2774 @opsummary{no-wildcards-match-slash}
2775 @item --no-wildcards-match-slash
2776 Wildcards do not match @samp{/}.
2777 @xref{controlling pattern-matching}.
2778
2779 @opsummary{null}
2780 @item --null
2781
2782 When @command{tar} is using the @option{--files-from} option, this option
2783 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2784 @command{tar} can correctly work with file names that contain newlines.
2785 @xref{nul}.
2786
2787 @opsummary{numeric-owner}
2788 @item --numeric-owner
2789
2790 This option will notify @command{tar} that it should use numeric user
2791 and group IDs when creating a @command{tar} file, rather than names.
2792 @xref{Attributes}.
2793
2794 @item -o
2795 The function of this option depends on the action @command{tar} is
2796 performing. When extracting files, @option{-o} is a synonym for
2797 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2798 restoring ownership of files being extracted.
2799
2800 When creating an archive, it is a synonym for
2801 @option{--old-archive}. This behavior is for compatibility
2802 with previous versions of @GNUTAR{}, and will be
2803 removed in the future releases.
2804
2805 @xref{Changes}, for more information.
2806
2807 @opsummary{occurrence}
2808 @item --occurrence[=@var{number}]
2809
2810 This option can be used in conjunction with one of the subcommands
2811 @option{--delete}, @option{--diff}, @option{--extract} or
2812 @option{--list} when a list of files is given either on the command
2813 line or via @option{-T} option.
2814
2815 This option instructs @command{tar} to process only the @var{number}th
2816 occurrence of each named file. @var{Number} defaults to 1, so
2817
2818 @smallexample
2819 tar -x -f archive.tar --occurrence filename
2820 @end smallexample
2821
2822 @noindent
2823 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2824 and will terminate without scanning to the end of the archive.
2825
2826 @opsummary{old-archive}
2827 @item --old-archive
2828 Synonym for @option{--format=v7}.
2829
2830 @opsummary{one-file-system}
2831 @item --one-file-system
2832 Used when creating an archive. Prevents @command{tar} from recursing into
2833 directories that are on different file systems from the current
2834 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2835 synonym for @option{--one-file-system}. This has changed in version
2836 1.15.91. @xref{Changes}, for more information.}.
2837
2838 @opsummary{overwrite}
2839 @item --overwrite
2840
2841 Overwrite existing files and directory metadata when extracting files
2842 from an archive. @xref{Overwrite Old Files}.
2843
2844 @opsummary{overwrite-dir}
2845 @item --overwrite-dir
2846
2847 Overwrite the metadata of existing directories when extracting files
2848 from an archive. @xref{Overwrite Old Files}.
2849
2850 @opsummary{owner}
2851 @item --owner=@var{user}
2852
2853 Specifies that @command{tar} should use @var{user} as the owner of members
2854 when creating archives, instead of the user associated with the source
2855 file. @var{user} is first decoded as a user symbolic name, but if
2856 this interpretation fails, it has to be a decimal numeric user ID.
2857 @xref{override}.
2858
2859 This option does not affect extraction from archives.
2860
2861 @opsummary{transform}
2862 @item --transform=@var{sed-expr}
2863
2864 Transform file or member names using @command{sed} replacement expression
2865 @var{sed-expr}. For example,
2866
2867 @smallexample
2868 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2869 @end smallexample
2870
2871 @noindent
2872 will add to @file{archive} files from the current working directory,
2873 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2874 discussion, @xref{transform}.
2875
2876 To see transformed member names in verbose listings, use
2877 @option{--show-transformed-names} option
2878 (@pxref{show-transformed-names}).
2879
2880 @opsummary{quote-chars}
2881 @item --quote-chars=@var{string}
2882 Always quote characters from @var{string}, even if the selected
2883 quoting style would not quote them (@pxref{quoting styles}).
2884
2885 @opsummary{quoting-style}
2886 @item --quoting-style=@var{style}
2887 Set quoting style to use when printing member and file names
2888 (@pxref{quoting styles}). Valid @var{style} values are:
2889 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2890 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2891 style is @code{escape}, unless overridden while configuring the
2892 package.
2893
2894 @opsummary{pax-option}
2895 @item --pax-option=@var{keyword-list}
2896 This option is meaningful only with @acronym{POSIX.1-2001} archives
2897 (@pxref{posix}). It modifies the way @command{tar} handles the
2898 extended header keywords. @var{Keyword-list} is a comma-separated
2899 list of keyword options. @xref{PAX keywords}, for a detailed
2900 discussion.
2901
2902 @opsummary{portability}
2903 @item --portability
2904 @itemx --old-archive
2905 Synonym for @option{--format=v7}.
2906
2907 @opsummary{posix}
2908 @item --posix
2909 Same as @option{--format=posix}.
2910
2911 @opsummary{preserve}
2912 @item --preserve
2913
2914 Synonymous with specifying both @option{--preserve-permissions} and
2915 @option{--same-order}. @xref{Setting Access Permissions}.
2916
2917 @opsummary{preserve-order}
2918 @item --preserve-order
2919
2920 (See @option{--same-order}; @pxref{Reading}.)
2921
2922 @opsummary{preserve-permissions}
2923 @opsummary{same-permissions}
2924 @item --preserve-permissions
2925 @itemx --same-permissions
2926 @itemx -p
2927
2928 When @command{tar} is extracting an archive, it normally subtracts the
2929 users' umask from the permissions specified in the archive and uses
2930 that number as the permissions to create the destination file.
2931 Specifying this option instructs @command{tar} that it should use the
2932 permissions directly from the archive. @xref{Setting Access Permissions}.
2933
2934 @opsummary{read-full-records}
2935 @item --read-full-records
2936 @itemx -B
2937
2938 Specifies that @command{tar} should reblock its input, for reading
2939 from pipes on systems with buggy implementations. @xref{Reading}.
2940
2941 @opsummary{record-size}
2942 @item --record-size=@var{size}
2943
2944 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2945 archive. @xref{Blocking Factor}.
2946
2947 @opsummary{recursion}
2948 @item --recursion
2949
2950 With this option, @command{tar} recurses into directories.
2951 @xref{recurse}.
2952
2953 @opsummary{recursive-unlink}
2954 @item --recursive-unlink
2955
2956 Remove existing
2957 directory hierarchies before extracting directories of the same name
2958 from the archive. @xref{Recursive Unlink}.
2959
2960 @opsummary{remove-files}
2961 @item --remove-files
2962
2963 Directs @command{tar} to remove the source file from the file system after
2964 appending it to an archive. @xref{remove files}.
2965
2966 @opsummary{restrict}
2967 @item --restrict
2968
2969 Disable use of some potentially harmful @command{tar} options.
2970 Currently this option disables shell invocaton from multi-volume menu
2971 (@pxref{Using Multiple Tapes}).
2972
2973 @opsummary{rmt-command}
2974 @item --rmt-command=@var{cmd}
2975
2976 Notifies @command{tar} that it should use @var{cmd} instead of
2977 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2978
2979 @opsummary{rsh-command}
2980 @item --rsh-command=@var{cmd}
2981
2982 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2983 devices. @xref{Device}.
2984
2985 @opsummary{same-order}
2986 @item --same-order
2987 @itemx --preserve-order
2988 @itemx -s
2989
2990 This option is an optimization for @command{tar} when running on machines with
2991 small amounts of memory. It informs @command{tar} that the list of file
2992 arguments has already been sorted to match the order of files in the
2993 archive. @xref{Reading}.
2994
2995 @opsummary{same-owner}
2996 @item --same-owner
2997
2998 When extracting an archive, @command{tar} will attempt to preserve the owner
2999 specified in the @command{tar} archive with this option present.
3000 This is the default behavior for the superuser; this option has an
3001 effect only for ordinary users. @xref{Attributes}.
3002
3003 @opsummary{same-permissions}
3004 @item --same-permissions
3005
3006 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3007
3008 @opsummary{show-defaults}
3009 @item --show-defaults
3010
3011 Displays the default options used by @command{tar} and exits
3012 successfully. This option is intended for use in shell scripts.
3013 Here is an example of what you can see using this option:
3014
3015 @smallexample
3016 $ tar --show-defaults
3017 --format=gnu -f- -b20 --quoting-style=escape \
3018 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3019 @end smallexample
3020
3021 @opsummary{show-omitted-dirs}
3022 @item --show-omitted-dirs
3023
3024 Instructs @command{tar} to mention directories its skipping over when
3025 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3026
3027 @opsummary{show-transformed-names}
3028 @opsummary{show-stored-names}
3029 @item --show-transformed-names
3030 @itemx --show-stored-names
3031
3032 Display file or member names after applying any transformations
3033 (@pxref{transform}). In particular, when used in conjunction with one of
3034 archive creation operations it instructs tar to list the member names
3035 stored in the archive, as opposed to the actual file
3036 names. @xref{listing member and file names}.
3037
3038 @opsummary{sparse}
3039 @item --sparse
3040 @itemx -S
3041
3042 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3043 sparse files efficiently. @xref{sparse}.
3044
3045 @opsummary{starting-file}
3046 @item --starting-file=@var{name}
3047 @itemx -K @var{name}
3048
3049 This option affects extraction only; @command{tar} will skip extracting
3050 files in the archive until it finds one that matches @var{name}.
3051 @xref{Scarce}.
3052
3053 @opsummary{strip-components}
3054 @item --strip-components=@var{number}
3055 Strip given @var{number} of leading components from file names before
3056 extraction.@footnote{This option was called @option{--strip-path} in
3057 version 1.14.} For example, if archive @file{archive.tar} contained
3058 @file{/some/file/name}, then running
3059
3060 @smallexample
3061 tar --extract --file archive.tar --strip-components=2
3062 @end smallexample
3063
3064 @noindent
3065 would extract this file to file @file{name}.
3066
3067 @opsummary{suffix}, summary
3068 @item --suffix=@var{suffix}
3069
3070 Alters the suffix @command{tar} uses when backing up files from the default
3071 @samp{~}. @xref{backup}.
3072
3073 @opsummary{tape-length}
3074 @item --tape-length=@var{num}
3075 @itemx -L @var{num}
3076
3077 Specifies the length of tapes that @command{tar} is writing as being
3078 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3079
3080 @opsummary{test-label}
3081 @item --test-label
3082
3083 Reads the volume label. If an argument is specified, test whether it
3084 matches the volume label. @xref{--test-label option}.
3085
3086 @opsummary{to-command}
3087 @item --to-command=@var{command}
3088
3089 During extraction @command{tar} will pipe extracted files to the
3090 standard input of @var{command}. @xref{Writing to an External Program}.
3091
3092 @opsummary{to-stdout}
3093 @item --to-stdout
3094 @itemx -O
3095
3096 During extraction, @command{tar} will extract files to stdout rather
3097 than to the file system. @xref{Writing to Standard Output}.
3098
3099 @opsummary{totals}
3100 @item --totals[=@var{signo}]
3101
3102 Displays the total number of bytes transferred when processing an
3103 archive. If an argument is given, these data are displayed on
3104 request, when signal @var{signo} is delivered to @command{tar}.
3105 @xref{totals}.
3106
3107 @opsummary{touch}
3108 @item --touch
3109 @itemx -m
3110
3111 Sets the data modification time of extracted files to the extraction time,
3112 rather than the data modification time stored in the archive.
3113 @xref{Data Modification Times}.
3114
3115 @opsummary{uncompress}
3116 @item --uncompress
3117
3118 (See @option{--compress}. @pxref{gzip})
3119
3120 @opsummary{ungzip}
3121 @item --ungzip
3122
3123 (See @option{--gzip}. @pxref{gzip})
3124
3125 @opsummary{unlink-first}
3126 @item --unlink-first
3127 @itemx -U
3128
3129 Directs @command{tar} to remove the corresponding file from the file
3130 system before extracting it from the archive. @xref{Unlink First}.
3131
3132 @opsummary{unquote}
3133 @item --unquote
3134 Enable unquoting input file or member names (default). @xref{input
3135 name quoting}.
3136
3137 @opsummary{use-compress-program}
3138 @item --use-compress-program=@var{prog}
3139
3140 Instructs @command{tar} to access the archive through @var{prog}, which is
3141 presumed to be a compression program of some sort. @xref{gzip}.
3142
3143 @opsummary{utc}
3144 @item --utc
3145
3146 Display file modification dates in @acronym{UTC}. This option implies
3147 @option{--verbose}.
3148
3149 @opsummary{verbose}
3150 @item --verbose
3151 @itemx -v
3152
3153 Specifies that @command{tar} should be more verbose about the operations its
3154 performing. This option can be specified multiple times for some
3155 operations to increase the amount of information displayed.
3156 @xref{verbose}.
3157
3158 @opsummary{verify}
3159 @item --verify
3160 @itemx -W
3161
3162 Verifies that the archive was correctly written when creating an
3163 archive. @xref{verify}.
3164
3165 @opsummary{version}
3166 @item --version
3167
3168 Print information about the program's name, version, origin and legal
3169 status, all on standard output, and then exit successfully.
3170 @xref{help}.
3171
3172 @opsummary{volno-file}
3173 @item --volno-file=@var{file}
3174
3175 Used in conjunction with @option{--multi-volume}. @command{tar} will
3176 keep track of which volume of a multi-volume archive its working in
3177 @var{file}. @xref{volno-file}.
3178
3179 @opsummary{wildcards}
3180 @item --wildcards
3181 Use wildcards when matching member names with patterns.
3182 @xref{controlling pattern-matching}.
3183
3184 @opsummary{wildcards-match-slash}
3185 @item --wildcards-match-slash
3186 Wildcards match @samp{/}.
3187 @xref{controlling pattern-matching}.
3188 @end table
3189
3190 @node Short Option Summary
3191 @subsection Short Options Cross Reference
3192
3193 Here is an alphabetized list of all of the short option forms, matching
3194 them with the equivalent long option.
3195
3196 @multitable @columnfractions 0.20 0.80
3197 @headitem Short Option @tab Reference
3198
3199 @item -A @tab @ref{--concatenate}.
3200
3201 @item -B @tab @ref{--read-full-records}.
3202
3203 @item -C @tab @ref{--directory}.
3204
3205 @item -F @tab @ref{--info-script}.
3206
3207 @item -G @tab @ref{--incremental}.
3208
3209 @item -K @tab @ref{--starting-file}.
3210
3211 @item -L @tab @ref{--tape-length}.
3212
3213 @item -M @tab @ref{--multi-volume}.
3214
3215 @item -N @tab @ref{--newer}.
3216
3217 @item -O @tab @ref{--to-stdout}.
3218
3219 @item -P @tab @ref{--absolute-names}.
3220
3221 @item -R @tab @ref{--block-number}.
3222
3223 @item -S @tab @ref{--sparse}.
3224
3225 @item -T @tab @ref{--files-from}.
3226
3227 @item -U @tab @ref{--unlink-first}.
3228
3229 @item -V @tab @ref{--label}.
3230
3231 @item -W @tab @ref{--verify}.
3232
3233 @item -X @tab @ref{--exclude-from}.
3234
3235 @item -Z @tab @ref{--compress}.
3236
3237 @item -b @tab @ref{--blocking-factor}.
3238
3239 @item -c @tab @ref{--create}.
3240
3241 @item -d @tab @ref{--compare}.
3242
3243 @item -f @tab @ref{--file}.
3244
3245 @item -g @tab @ref{--listed-incremental}.
3246
3247 @item -h @tab @ref{--dereference}.
3248
3249 @item -i @tab @ref{--ignore-zeros}.
3250
3251 @item -j @tab @ref{--bzip2}.
3252
3253 @item -k @tab @ref{--keep-old-files}.
3254
3255 @item -l @tab @ref{--check-links}.
3256
3257 @item -m @tab @ref{--touch}.
3258
3259 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3260 @ref{--portability}.
3261
3262 The later usage is deprecated. It is retained for compatibility with
3263 the earlier versions of @GNUTAR{}. In the future releases
3264 @option{-o} will be equivalent to @option{--no-same-owner} only.
3265
3266 @item -p @tab @ref{--preserve-permissions}.
3267
3268 @item -r @tab @ref{--append}.
3269
3270 @item -s @tab @ref{--same-order}.
3271
3272 @item -t @tab @ref{--list}.
3273
3274 @item -u @tab @ref{--update}.
3275
3276 @item -v @tab @ref{--verbose}.
3277
3278 @item -w @tab @ref{--interactive}.
3279
3280 @item -x @tab @ref{--extract}.
3281
3282 @item -z @tab @ref{--gzip}.
3283
3284 @end multitable
3285
3286 @node help
3287 @section @GNUTAR{} documentation
3288
3289 @cindex Getting program version number
3290 @opindex version
3291 @cindex Version of the @command{tar} program
3292 Being careful, the first thing is really checking that you are using
3293 @GNUTAR{}, indeed. The @option{--version} option
3294 causes @command{tar} to print information about its name, version,
3295 origin and legal status, all on standard output, and then exit
3296 successfully. For example, @w{@samp{tar --version}} might print:
3297
3298 @smallexample
3299 tar (GNU tar) @value{VERSION}
3300 Copyright (C) 2006 Free Software Foundation, Inc.
3301 This is free software. You may redistribute copies of it under the terms
3302 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3303 There is NO WARRANTY, to the extent permitted by law.
3304
3305 Written by John Gilmore and Jay Fenlason.
3306 @end smallexample
3307
3308 @noindent
3309 The first occurrence of @samp{tar} in the result above is the program
3310 name in the package (for example, @command{rmt} is another program),
3311 while the second occurrence of @samp{tar} is the name of the package
3312 itself, containing possibly many programs. The package is currently
3313 named @samp{tar}, after the name of the main program it
3314 contains@footnote{There are plans to merge the @command{cpio} and
3315 @command{tar} packages into a single one which would be called
3316 @code{paxutils}. So, who knows if, one of this days, the
3317 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3318 paxutils) 3.2}}}.
3319
3320 @cindex Obtaining help
3321 @cindex Listing all @command{tar} options
3322 @xopindex{help, introduction}
3323 Another thing you might want to do is checking the spelling or meaning
3324 of some particular @command{tar} option, without resorting to this
3325 manual, for once you have carefully read it. @GNUTAR{}
3326 has a short help feature, triggerable through the
3327 @option{--help} option. By using this option, @command{tar} will
3328 print a usage message listing all available options on standard
3329 output, then exit successfully, without doing anything else and
3330 ignoring all other options. Even if this is only a brief summary, it
3331 may be several screens long. So, if you are not using some kind of
3332 scrollable window, you might prefer to use something like:
3333
3334 @smallexample
3335 $ @kbd{tar --help | less}
3336 @end smallexample
3337
3338 @noindent
3339 presuming, here, that you like using @command{less} for a pager. Other
3340 popular pagers are @command{more} and @command{pg}. If you know about some
3341 @var{keyword} which interests you and do not want to read all the
3342 @option{--help} output, another common idiom is doing:
3343
3344 @smallexample
3345 tar --help | grep @var{keyword}
3346 @end smallexample
3347
3348 @noindent
3349 for getting only the pertinent lines. Notice, however, that some
3350 @command{tar} options have long description lines and the above
3351 command will list only the first of them.
3352
3353 The exact look of the option summary displayed by @kbd{tar --help} is
3354 configurable. @xref{Configuring Help Summary}, for a detailed description.
3355
3356 @opindex usage
3357 If you only wish to check the spelling of an option, running @kbd{tar
3358 --usage} may be a better choice. This will display a terse list of
3359 @command{tar} option without accompanying explanations.
3360
3361 The short help output is quite succinct, and you might have to get
3362 back to the full documentation for precise points. If you are reading
3363 this paragraph, you already have the @command{tar} manual in some
3364 form. This manual is available in a variety of forms from
3365 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3366 distribution, provided you have @TeX{} already installed somewhere,
3367 and a laser printer around. Just configure the distribution, execute
3368 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3369 usual way (contact your local guru to know how). If @GNUTAR{}
3370 has been conveniently installed at your place, this
3371 manual is also available in interactive, hypertextual form as an Info
3372 file. Just call @w{@samp{info tar}} or, if you do not have the
3373 @command{info} program handy, use the Info reader provided within
3374 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3375
3376 There is currently no @code{man} page for @GNUTAR{}.
3377 If you observe such a @code{man} page on the system you are running,
3378 either it does not belong to @GNUTAR{}, or it has not
3379 been produced by @acronym{GNU}. Some package maintainers convert
3380 @kbd{tar --help} output to a man page, using @command{help2man}. In
3381 any case, please bear in mind that the authoritative source of
3382 information about @GNUTAR{} is this Texinfo documentation.
3383
3384 @node defaults
3385 @section Obtaining @GNUTAR{} default values
3386
3387 @opindex show-defaults
3388 @GNUTAR{} has some predefined defaults that are used when you do not
3389 explicitely specify another values. To obtain a list of such
3390 defaults, use @option{--show-defaults} option. This will output the
3391 values in the form of @command{tar} command line options:
3392
3393 @smallexample
3394 @group
3395 @kbd{tar --show-defaults}
3396 --format=gnu -f- -b20 --quoting-style=escape
3397 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3398 @end group
3399 @end smallexample
3400
3401 @noindent
3402 Notice, that this option outputs only one line. The example output above
3403 has been split to fit page boundaries.
3404
3405 @noindent
3406 The above output shows that this version of @GNUTAR{} defaults to
3407 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3408 output as the archive, if no @option{--file} option has been given
3409 (@pxref{file tutorial}), the default blocking factor is 20
3410 (@pxref{Blocking Factor}). It also shows the default locations where
3411 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3412
3413 @node verbose
3414 @section Checking @command{tar} progress
3415
3416 Typically, @command{tar} performs most operations without reporting any
3417 information to the user except error messages. When using @command{tar}
3418 with many options, particularly ones with complicated or
3419 difficult-to-predict behavior, it is possible to make serious mistakes.
3420 @command{tar} provides several options that make observing @command{tar}
3421 easier. These options cause @command{tar} to print information as it
3422 progresses in its job, and you might want to use them just for being
3423 more careful about what is going on, or merely for entertaining
3424 yourself. If you have encountered a problem when operating on an
3425 archive, however, you may need more information than just an error
3426 message in order to solve the problem. The following options can be
3427 helpful diagnostic tools.
3428
3429 @cindex Verbose operation
3430 @opindex verbose
3431 Normally, the @option{--list} (@option{-t}) command to list an archive
3432 prints just the file names (one per line) and the other commands are
3433 silent. When used with most operations, the @option{--verbose}
3434 (@option{-v}) option causes @command{tar} to print the name of each
3435 file or archive member as it is processed. This and the other options
3436 which make @command{tar} print status information can be useful in
3437 monitoring @command{tar}.
3438
3439 With @option{--create} or @option{--extract}, @option{--verbose} used
3440 once just prints the names of the files or members as they are processed.
3441 Using it twice causes @command{tar} to print a longer listing
3442 (@xref{verbose member listing}, for the description) for each member.
3443 Since @option{--list} already prints the names of the members,
3444 @option{--verbose} used once with @option{--list} causes @command{tar}
3445 to print an @samp{ls -l} type listing of the files in the archive.
3446 The following examples both extract members with long list output:
3447
3448 @smallexample
3449 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3450 $ @kbd{tar xvvf archive.tar}
3451 @end smallexample
3452
3453 Verbose output appears on the standard output except when an archive is
3454 being written to the standard output, as with @samp{tar --create
3455 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3456 installer let standard output be the default archive). In that case
3457 @command{tar} writes verbose output to the standard error stream.
3458
3459 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3460 verbose output to @var{file} rather than to standard output or standard
3461 error.
3462
3463 @anchor{totals}
3464 @cindex Obtaining total status information
3465 @opindex totals
3466 The @option{--totals} option causes @command{tar} to print on the
3467 standard error the total amount of bytes transferred when processing
3468 an archive. When creating or appending to an archive, this option
3469 prints the number of bytes written to the archive and the average
3470 speed at which they have been written, e.g.:
3471
3472 @smallexample
3473 @group
3474 $ @kbd{tar -c -f archive.tar --totals /home}
3475 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3476 @end group
3477 @end smallexample
3478
3479 When reading an archive, this option displays the number of bytes
3480 read:
3481
3482 @smallexample
3483 @group
3484 $ @kbd{tar -x -f archive.tar --totals}
3485 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3486 @end group
3487 @end smallexample
3488
3489 Finally, when deleting from an archive, the @option{--totals} option
3490 displays both numbers plus number of bytes removed from the archive:
3491
3492 @smallexample
3493 @group
3494 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3495 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3496 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3497 Total bytes deleted: 1474048
3498 @end group
3499 @end smallexample
3500
3501 You can also obtain this information on request. When
3502 @option{--totals} is used with an argument, this argument is
3503 interpreted as a symbolic name of a signal, upon delivery of which the
3504 statistics is to be printed:
3505
3506 @table @option
3507 @item --totals=@var{signo}
3508 Print statistics upon delivery of signal @var{signo}. Valid arguments
3509 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3510 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3511 accepted.
3512 @end table
3513
3514 Both forms of @option{--totals} option can be used simultaneously.
3515 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3516 extract all members from its default archive and print statistics
3517 after finishing the extraction, as well as when receiving signal
3518 @code{SIGUSR1}.
3519
3520 @anchor{Progress information}
3521 @cindex Progress information
3522 @opindex checkpoint
3523 The @option{--checkpoint} option prints an occasional message
3524 as @command{tar} reads or writes the archive. It is designed for
3525 those who don't need the more detailed (and voluminous) output of
3526 @option{--block-number} (@option{-R}), but do want visual confirmation
3527 that @command{tar} is actually making forward progress. By default it
3528 prints a message each 10 records read or written. This can be changed
3529 by giving it a numeric argument after an equal sign:
3530
3531 @smallexample
3532 $ @kbd{tar -c --checkpoint=1000} /var
3533 tar: Write checkpoint 1000
3534 tar: Write checkpoint 2000
3535 tar: Write checkpoint 3000
3536 @end smallexample
3537
3538 This example shows the default checkpoint message used by
3539 @command{tar}. If you place a dot immediately after the equal
3540 sign, it will print a @samp{.} at each checkpoint. For example:
3541
3542 @smallexample
3543 $ @kbd{tar -c --checkpoint=.1000} /var
3544 ...
3545 @end smallexample
3546
3547 @opindex show-omitted-dirs
3548 @anchor{show-omitted-dirs}
3549 The @option{--show-omitted-dirs} option, when reading an archive---with
3550 @option{--list} or @option{--extract}, for example---causes a message
3551 to be printed for each directory in the archive which is skipped.
3552 This happens regardless of the reason for skipping: the directory might
3553 not have been named on the command line (implicitly or explicitly),
3554 it might be excluded by the use of the
3555 @option{--exclude=@var{pattern}} option, or some other reason.
3556
3557 @opindex block-number
3558 @cindex Block number where error occurred
3559 @anchor{block-number}
3560 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3561 every message it would normally produce, the block number within the
3562 archive where the message was triggered. Also, supplementary messages
3563 are triggered when reading blocks full of NULs, or when hitting end of
3564 file on the archive. As of now, if the archive if properly terminated
3565 with a NUL block, the reading of the file may stop before end of file
3566 is met, so the position of end of file will not usually show when
3567 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3568 drains the archive before exiting when reading the
3569 archive from a pipe.
3570
3571 @cindex Error message, block number of
3572 This option is especially useful when reading damaged archives, since
3573 it helps pinpoint the damaged sections. It can also be used with
3574 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3575 choose among several backup tapes when retrieving a file later, in
3576 favor of the tape where the file appears earliest (closest to the
3577 front of the tape). @xref{backup}.
3578
3579 @node interactive
3580 @section Asking for Confirmation During Operations
3581 @cindex Interactive operation
3582
3583 Typically, @command{tar} carries out a command without stopping for
3584 further instructions. In some situations however, you may want to
3585 exclude some files and archive members from the operation (for instance
3586 if disk or storage space is tight). You can do this by excluding
3587 certain files automatically (@pxref{Choosing}), or by performing
3588 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3589 @command{tar} also accepts @option{--confirmation} for this option.
3590
3591 @opindex interactive
3592 When the @option{--interactive} (@option{-w}) option is specified, before
3593 reading, writing, or deleting files, @command{tar} first prints a message
3594 for each such file, telling what operation it intends to take, then asks
3595 for confirmation on the terminal. The actions which require
3596 confirmation include adding a file to the archive, extracting a file
3597 from the archive, deleting a file from the archive, and deleting a file
3598 from disk. To confirm the action, you must type a line of input
3599 beginning with @samp{y}. If your input line begins with anything other
3600 than @samp{y}, @command{tar} skips that file.
3601
3602 If @command{tar} is reading the archive from the standard input,
3603 @command{tar} opens the file @file{/dev/tty} to support the interactive
3604 communications.
3605
3606 Verbose output is normally sent to standard output, separate from
3607 other error messages. However, if the archive is produced directly
3608 on standard output, then verbose output is mixed with errors on
3609 @code{stderr}. Producing the archive on standard output may be used
3610 as a way to avoid using disk space, when the archive is soon to be
3611 consumed by another process reading it, say. Some people felt the need
3612 of producing an archive on stdout, still willing to segregate between
3613 verbose output and error output. A possible approach would be using a
3614 named pipe to receive the archive, and having the consumer process to
3615 read from that named pipe. This has the advantage of letting standard
3616 output free to receive verbose output, all separate from errors.
3617
3618 @node operations
3619 @chapter @GNUTAR{} Operations
3620
3621 @menu
3622 * Basic tar::
3623 * Advanced tar::
3624 * create options::
3625 * extract options::
3626 * backup::
3627 * Applications::
3628 * looking ahead::
3629 @end menu
3630
3631 @node Basic tar
3632 @section Basic @GNUTAR{} Operations
3633
3634 The basic @command{tar} operations, @option{--create} (@option{-c}),
3635 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3636 @option{-x}), are currently presented and described in the tutorial
3637 chapter of this manual. This section provides some complementary notes
3638 for these operations.
3639
3640 @table @option
3641 @xopindex{create, complementary notes}
3642 @item --create
3643 @itemx -c
3644
3645 Creating an empty archive would have some kind of elegance. One can
3646 initialize an empty archive and later use @option{--append}
3647 (@option{-r}) for adding all members. Some applications would not
3648 welcome making an exception in the way of adding the first archive
3649 member. On the other hand, many people reported that it is
3650 dangerously too easy for @command{tar} to destroy a magnetic tape with
3651 an empty archive@footnote{This is well described in @cite{Unix-haters
3652 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3653 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3654
3655 @enumerate
3656 @item
3657 Mistakingly using @code{create} instead of @code{extract}, when the
3658 intent was to extract the full contents of an archive. This error
3659 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3660 the QWERTY keyboard. Instead of being unpacked, the archive then
3661 gets wholly destroyed. When users speak about @dfn{exploding} an
3662 archive, they usually mean something else :-).
3663
3664 @item
3665 Forgetting the argument to @code{file}, when the intent was to create
3666 an archive with a single file in it. This error is likely because a
3667 tired user can easily add the @kbd{f} key to the cluster of option
3668 letters, by the mere force of habit, without realizing the full
3669 consequence of doing so. The usual consequence is that the single
3670 file, which was meant to be saved, is rather destroyed.
3671 @end enumerate
3672
3673 So, recognizing the likelihood and the catastrophical nature of these
3674 errors, @GNUTAR{} now takes some distance from elegance, and
3675 cowardly refuses to create an archive when @option{--create} option is
3676 given, there are no arguments besides options, and
3677 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3678 around the cautiousness of @GNUTAR{} and nevertheless create an
3679 archive with nothing in it, one may still use, as the value for the
3680 @option{--files-from} option, a file with no names in it, as shown in
3681 the following commands:
3682
3683 @smallexample
3684 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3685 @kbd{tar cfT empty-archive.tar /dev/null}
3686 @end smallexample
3687
3688 @xopindex{extract, complementary notes}
3689 @item --extract
3690 @itemx --get
3691 @itemx -x
3692
3693 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3694
3695 @item @option{--list} (@option{-t})
3696
3697 @GNUTAR{} now shows dates as @samp{1996-08-30},
3698 while it used to show them as @samp{Aug 30 1996}. Preferably,
3699 people should get used to ISO 8601 dates. Local American dates should
3700 be made available again with full date localization support, once
3701 ready. In the meantime, programs not being localizable for dates
3702 should prefer international dates, that's really the way to go.
3703
3704 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3705 are curious, it contains a detailed explanation of the ISO 8601 standard.
3706
3707 @end table
3708
3709 @node Advanced tar
3710 @section Advanced @GNUTAR{} Operations
3711
3712 Now that you have learned the basics of using @GNUTAR{}, you may want
3713 to learn about further ways in which @command{tar} can help you.
3714
3715 This chapter presents five, more advanced operations which you probably
3716 won't use on a daily basis, but which serve more specialized functions.
3717 We also explain the different styles of options and why you might want
3718 to use one or another, or a combination of them in your @command{tar}
3719 commands. Additionally, this chapter includes options which allow you to
3720 define the output from @command{tar} more carefully, and provide help and
3721 error correction in special circumstances.
3722
3723 @FIXME{check this after the chapter is actually revised to make sure
3724 it still introduces the info in the chapter correctly : ).}
3725
3726 @menu
3727 * Operations::
3728 * append::
3729 * update::
3730 * concatenate::
3731 * delete::
3732 * compare::
3733 @end menu
3734
3735 @node Operations
3736 @subsection The Five Advanced @command{tar} Operations
3737 @UNREVISED
3738
3739 In the last chapter, you learned about the first three operations to
3740 @command{tar}. This chapter presents the remaining five operations to
3741 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3742 @option{--delete}, and @option{--compare}.
3743
3744 You are not likely to use these operations as frequently as those
3745 covered in the last chapter; however, since they perform specialized
3746 functions, they are quite useful when you do need to use them. We
3747 will give examples using the same directory and files that you created
3748 in the last chapter. As you may recall, the directory is called
3749 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3750 @samp{rock}, and the two archive files you created are
3751 @samp{collection.tar} and @samp{music.tar}.
3752
3753 We will also use the archive files @samp{afiles.tar} and
3754 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3755 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3756 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3757
3758 Unless we state otherwise, all practicing you do and examples you follow
3759 in this chapter will take place in the @file{practice} directory that
3760 you created in the previous chapter; see @ref{prepare for examples}.
3761 (Below in this section, we will remind you of the state of the examples
3762 where the last chapter left them.)
3763
3764 The five operations that we will cover in this chapter are:
3765
3766 @table @option
3767 @item --append
3768 @itemx -r
3769 Add new entries to an archive that already exists.
3770 @item --update
3771 @itemx -r
3772 Add more recent copies of archive members to the end of an archive, if
3773 they exist.
3774 @item --concatenate
3775 @itemx --catenate
3776 @itemx -A
3777 Add one or more pre-existing archives to the end of another archive.
3778 @item --delete
3779 Delete items from an archive (does not work on tapes).
3780 @item --compare
3781 @itemx --diff
3782 @itemx -d
3783 Compare archive members to their counterparts in the file system.
3784 @end table
3785
3786 @node append
3787 @subsection How to Add Files to Existing Archives: @option{--append}
3788 @UNREVISED
3789
3790 @opindex append
3791 If you want to add files to an existing archive, you don't need to
3792 create a new archive; you can use @option{--append} (@option{-r}).
3793 The archive must already exist in order to use @option{--append}. (A
3794 related operation is the @option{--update} operation; you can use this
3795 to add newer versions of archive members to an existing archive. To learn how to
3796 do this with @option{--update}, @pxref{update}.)
3797
3798 If you use @option{--append} to add a file that has the same name as an
3799 archive member to an archive containing that archive member, then the
3800 old member is not deleted. What does happen, however, is somewhat
3801 complex. @command{tar} @emph{allows} you to have infinite number of files
3802 with the same name. Some operations treat these same-named members no
3803 differently than any other set of archive members: for example, if you
3804 view an archive with @option{--list} (@option{-t}), you will see all
3805 of those members listed, with their data modification times, owners, etc.
3806
3807 Other operations don't deal with these members as perfectly as you might
3808 prefer; if you were to use @option{--extract} to extract the archive,
3809 only the most recently added copy of a member with the same name as four
3810 other members would end up in the working directory. This is because
3811 @option{--extract} extracts an archive in the order the members appeared
3812 in the archive; the most recently archived members will be extracted
3813 last. Additionally, an extracted member will @emph{replace} a file of
3814 the same name which existed in the directory already, and @command{tar}
3815 will not prompt you about this@footnote{Unless you give it
3816 @option{--keep-old-files} option, or the disk copy is newer than the
3817 the one in the archive and you invoke @command{tar} with
3818 @option{--keep-newer-files} option}. Thus, only the most recently archived
3819 member will end up being extracted, as it will replace the one
3820 extracted before it, and so on.
3821
3822 There exists a special option that allows you to get around this
3823 behavior and extract (or list) only a particular copy of the file.
3824 This is @option{--occurrence} option. If you run @command{tar} with
3825 this option, it will extract only the first copy of the file. You
3826 may also give this option an argument specifying the number of
3827 copy to be extracted. Thus, for example if the archive
3828 @file{archive.tar} contained three copies of file @file{myfile}, then
3829 the command
3830
3831 @smallexample
3832 tar --extract --file archive.tar --occurrence=2 myfile
3833 @end smallexample
3834
3835 @noindent
3836 would extract only the second copy. @xref{Option
3837 Summary,---occurrence}, for the description of @option{--occurrence}
3838 option.
3839
3840 @FIXME{ hag -- you might want to incorporate some of the above into the
3841 MMwtSN node; not sure. i didn't know how to make it simpler...
3842
3843 There are a few ways to get around this. (maybe xref Multiple Members
3844 with the Same Name.}
3845
3846 @cindex Members, replacing with other members
3847 @cindex Replacing members with other members
3848 If you want to replace an archive member, use @option{--delete} to
3849 delete the member you want to remove from the archive, , and then use
3850 @option{--append} to add the member you want to be in the archive. Note
3851 that you can not change the order of the archive; the most recently
3852 added member will still appear last. In this sense, you cannot truly
3853 ``replace'' one member with another. (Replacing one member with another
3854 will not work on certain types of media, such as tapes; see @ref{delete}
3855 and @ref{Media}, for more information.)
3856
3857 @menu
3858 * appending files:: Appending Files to an Archive
3859 * multiple::
3860 @end menu
3861
3862 @node appending files
3863 @subsubsection Appending Files to an Archive
3864 @UNREVISED
3865 @cindex Adding files to an Archive
3866 @cindex Appending files to an Archive
3867 @cindex Archives, Appending files to
3868
3869 The simplest way to add a file to an already existing archive is the
3870 @option{--append} (@option{-r}) operation, which writes specified
3871 files into the archive whether or not they are already among the
3872 archived files.
3873
3874 When you use @option{--append}, you @emph{must} specify file name
3875 arguments, as there is no default. If you specify a file that already
3876 exists in the archive, another copy of the file will be added to the
3877 end of the archive. As with other operations, the member names of the
3878 newly added files will be exactly the same as their names given on the
3879 command line. The @option{--verbose} (@option{-v}) option will print
3880 out the names of the files as they are written into the archive.
3881
3882 @option{--append} cannot be performed on some tape drives, unfortunately,
3883 due to deficiencies in the formats those tape drives use. The archive
3884 must be a valid @command{tar} archive, or else the results of using this
3885 operation will be unpredictable. @xref{Media}.
3886
3887 To demonstrate using @option{--append} to add a file to an archive,
3888 create a file called @file{rock} in the @file{practice} directory.
3889 Make sure you are in the @file{practice} directory. Then, run the
3890 following @command{tar} command to add @file{rock} to
3891 @file{collection.tar}:
3892
3893 @smallexample
3894 $ @kbd{tar --append --file=collection.tar rock}
3895 @end smallexample
3896
3897 @noindent
3898 If you now use the @option{--list} (@option{-t}) operation, you will see that
3899 @file{rock} has been added to the archive:
3900
3901 @smallexample
3902 $ @kbd{tar --list --file=collection.tar}
3903 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3904 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3905 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3906 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3907 @end smallexample
3908
3909 @node multiple
3910 @subsubsection Multiple Members with the Same Name
3911
3912 You can use @option{--append} (@option{-r}) to add copies of files
3913 which have been updated since the archive was created. (However, we
3914 do not recommend doing this since there is another @command{tar}
3915 option called @option{--update}; @xref{update}, for more information.
3916 We describe this use of @option{--append} here for the sake of
3917 completeness.) When you extract the archive, the older version will
3918 be effectively lost. This works because files are extracted from an
3919 archive in the order in which they were archived. Thus, when the
3920 archive is extracted, a file archived later in time will replace a
3921 file of the same name which was archived earlier, even though the
3922 older version of the file will remain in the archive unless you delete
3923 all versions of the file.
3924
3925 Supposing you change the file @file{blues} and then append the changed
3926 version to @file{collection.tar}. As you saw above, the original
3927 @file{blues} is in the archive @file{collection.tar}. If you change the
3928 file and append the new version of the file to the archive, there will
3929 be two copies in the archive. When you extract the archive, the older
3930 version of the file will be extracted first, and then replaced by the
3931 newer version when it is extracted.
3932
3933 You can append the new, changed copy of the file @file{blues} to the
3934 archive in this way:
3935
3936 @smallexample
3937 $ @kbd{tar --append --verbose --file=collection.tar blues}
3938 blues
3939 @end smallexample
3940
3941 @noindent
3942 Because you specified the @option{--verbose} option, @command{tar} has
3943 printed the name of the file being appended as it was acted on. Now
3944 list the contents of the archive:
3945
3946 @smallexample
3947 $ @kbd{tar --list --verbose --file=collection.tar}
3948 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3949 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3950 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3951 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3952 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3953 @end smallexample
3954
3955 @noindent
3956 The newest version of @file{blues} is now at the end of the archive
3957 (note the different creation dates and file sizes). If you extract
3958 the archive, the older version of the file @file{blues} will be
3959 replaced by the newer version. You can confirm this by extracting
3960 the archive and running @samp{ls} on the directory.
3961
3962 If you wish to extract the first occurrence of the file @file{blues}
3963 from the archive, use @option{--occurrence} option, as shown in
3964 the following example:
3965
3966 @smallexample
3967 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3968 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3969 @end smallexample
3970
3971 @xref{Writing}, for more information on @option{--extract} and
3972 @xref{Option Summary, --occurrence}, for the description of
3973 @option{--occurrence} option.
3974
3975 @node update
3976 @subsection Updating an Archive
3977 @UNREVISED
3978 @cindex Updating an archive
3979
3980 @opindex update
3981 In the previous section, you learned how to use @option{--append} to
3982 add a file to an existing archive. A related operation is
3983 @option{--update} (@option{-u}). The @option{--update} operation
3984 updates a @command{tar} archive by comparing the date of the specified
3985 archive members against the date of the file with the same name. If
3986 the file has been modified more recently than the archive member, then
3987 the newer version of the file is added to the archive (as with
3988 @option{--append}).
3989
3990 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3991 The operation will fail.
3992
3993 @FIXME{other examples of media on which --update will fail? need to ask
3994 charles and/or mib/thomas/dave shevett..}
3995
3996 Both @option{--update} and @option{--append} work by adding to the end
3997 of the archive. When you extract a file from the archive, only the
3998 version stored last will wind up in the file system, unless you use
3999 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4000
4001 @menu
4002 * how to update::
4003 @end menu
4004
4005 @node how to update
4006 @subsubsection How to Update an Archive Using @option{--update}
4007
4008 You must use file name arguments with the @option{--update}
4009 (@option{-u}) operation. If you don't specify any files,
4010 @command{tar} won't act on any files and won't tell you that it didn't
4011 do anything (which may end up confusing you).
4012
4013 @c note: the above parenthetical added because in fact, this
4014 @c behavior just confused the author. :-)
4015
4016 To see the @option{--update} option at work, create a new file,
4017 @file{classical}, in your practice directory, and some extra text to the
4018 file @file{blues}, using any text editor. Then invoke @command{tar} with
4019 the @samp{update} operation and the @option{--verbose} (@option{-v})
4020 option specified, using the names of all the files in the practice
4021 directory as file name arguments:
4022
4023 @smallexample
4024 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4025 blues
4026 classical
4027 $
4028 @end smallexample
4029
4030 @noindent
4031 Because we have specified verbose mode, @command{tar} prints out the names
4032 of the files it is working on, which in this case are the names of the
4033 files that needed to be updated. If you run @samp{tar --list} and look
4034 at the archive, you will see @file{blues} and @file{classical} at its
4035 end. There will be a total of two versions of the member @samp{blues};
4036 the one at the end will be newer and larger, since you added text before
4037 updating it.
4038
4039 (The reason @command{tar} does not overwrite the older file when updating
4040 it is because writing to the middle of a section of tape is a difficult
4041 process. Tapes are not designed to go backward. @xref{Media}, for more
4042 information about tapes.
4043
4044 @option{--update} (@option{-u}) is not suitable for performing backups for two
4045 reasons: it does not change directory content entries, and it
4046 lengthens the archive every time it is used. The @GNUTAR{}
4047 options intended specifically for backups are more
4048 efficient. If you need to run backups, please consult @ref{Backups}.
4049
4050 @node concatenate
4051 @subsection Combining Archives with @option{--concatenate}
4052
4053 @cindex Adding archives to an archive
4054 @cindex Concatenating Archives
4055 @opindex concatenate
4056 @opindex catenate
4057 @c @cindex @option{-A} described
4058 Sometimes it may be convenient to add a second archive onto the end of
4059 an archive rather than adding individual files to the archive. To add
4060 one or more archives to the end of another archive, you should use the
4061 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4062
4063 To use @option{--concatenate}, give the first archive with
4064 @option{--file} option and name the rest of archives to be
4065 concatenated on the command line. The members, and their member
4066 names, will be copied verbatim from those archives to the first one.
4067 @footnote{This can cause multiple members to have the same name, for
4068 information on how this affects reading the archive, @ref{multiple}.}
4069 The new, concatenated archive will be called by the same name as the
4070 one given with the @option{--file} option. As usual, if you omit
4071 @option{--file}, @command{tar} will use the value of the environment
4072 variable @env{TAPE}, or, if this has not been set, the default archive name.
4073
4074 @FIXME{There is no way to specify a new name...}
4075
4076 To demonstrate how @option{--concatenate} works, create two small archives
4077 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4078 files from @file{practice}:
4079
4080 @smallexample
4081 $ @kbd{tar -cvf bluesrock.tar blues rock}
4082 blues
4083 rock
4084 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4085 folk
4086 jazz
4087 @end smallexample
4088
4089 @noindent
4090 If you like, You can run @samp{tar --list} to make sure the archives
4091 contain what they are supposed to:
4092
4093 @smallexample
4094 $ @kbd{tar -tvf bluesrock.tar}
4095 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4096 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4097 $ @kbd{tar -tvf jazzfolk.tar}
4098 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4099 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4100 @end smallexample
4101
4102 We can concatenate these two archives with @command{tar}:
4103
4104 @smallexample
4105 $ @kbd{cd ..}
4106 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4107 @end smallexample
4108
4109 If you now list the contents of the @file{bluesrock.tar}, you will see
4110 that now it also contains the archive members of @file{jazzfolk.tar}:
4111
4112 @smallexample
4113 $ @kbd{tar --list --file=bluesrock.tar}
4114 blues
4115 rock
4116 folk
4117 jazz
4118 @end smallexample
4119
4120 When you use @option{--concatenate}, the source and target archives must
4121 already exist and must have been created using compatible format
4122 parameters. Notice, that @command{tar} does not check whether the
4123 archives it concatenates have compatible formats, it does not
4124 even check if the files are really tar archives.
4125
4126 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4127 tape drives, due to deficiencies in the formats those tape drives use.
4128
4129 @cindex @code{concatenate} vs @command{cat}
4130 @cindex @command{cat} vs @code{concatenate}
4131 It may seem more intuitive to you to want or try to use @command{cat} to
4132 concatenate two archives instead of using the @option{--concatenate}
4133 operation; after all, @command{cat} is the utility for combining files.
4134
4135 However, @command{tar} archives incorporate an end-of-file marker which
4136 must be removed if the concatenated archives are to be read properly as
4137 one archive. @option{--concatenate} removes the end-of-archive marker
4138 from the target archive before each new archive is appended. If you use
4139 @command{cat} to combine the archives, the result will not be a valid
4140 @command{tar} format archive. If you need to retrieve files from an
4141 archive that was added to using the @command{cat} utility, use the
4142 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4143 information on dealing with archives improperly combined using the
4144 @command{cat} shell utility.
4145
4146 @node delete
4147 @subsection Removing Archive Members Using @option{--delete}
4148 @UNREVISED
4149 @cindex Deleting files from an archive
4150 @cindex Removing files from an archive
4151
4152 @opindex delete
4153 You can remove members from an archive by using the @option{--delete}
4154 option. Specify the name of the archive with @option{--file}
4155 (@option{-f}) and then specify the names of the members to be deleted;
4156 if you list no member names, nothing will be deleted. The
4157 @option{--verbose} option will cause @command{tar} to print the names
4158 of the members as they are deleted. As with @option{--extract}, you
4159 must give the exact member names when using @samp{tar --delete}.
4160 @option{--delete} will remove all versions of the named file from the
4161 archive. The @option{--delete} operation can run very slowly.
4162
4163 Unlike other operations, @option{--delete} has no short form.
4164
4165 @cindex Tapes, using @option{--delete} and
4166 @cindex Deleting from tape archives
4167 This operation will rewrite the archive. You can only use
4168 @option{--delete} on an archive if the archive device allows you to
4169 write to any point on the media, such as a disk; because of this, it
4170 does not work on magnetic tapes. Do not try to delete an archive member
4171 from a magnetic tape; the action will not succeed, and you will be
4172 likely to scramble the archive and damage your tape. There is no safe
4173 way (except by completely re-writing the archive) to delete files from
4174 most kinds of magnetic tape. @xref{Media}.
4175
4176 To delete all versions of the file @file{blues} from the archive
4177 @file{collection.tar} in the @file{practice} directory, make sure you
4178 are in that directory, and then,
4179
4180 @smallexample
4181 $ @kbd{tar --list --file=collection.tar}
4182 blues
4183 folk
4184 jazz
4185 rock
4186 $ @kbd{tar --delete --file=collection.tar blues}
4187 $ @kbd{tar --list --file=collection.tar}
4188 folk
4189 jazz
4190 rock
4191 $
4192 @end smallexample
4193
4194 @FIXME{Check if the above listing is actually produced after running
4195 all the examples on collection.tar.}
4196
4197 The @option{--delete} option has been reported to work properly when
4198 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4199
4200 @node compare
4201 @subsection Comparing Archive Members with the File System
4202 @cindex Verifying the currency of an archive
4203 @UNREVISED
4204
4205 @opindex compare
4206 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4207 specified archive members against files with the same names, and then
4208 reports differences in file size, mode, owner, modification date and
4209 contents. You should @emph{only} specify archive member names, not file
4210 names. If you do not name any members, then @command{tar} will compare the
4211 entire archive. If a file is represented in the archive but does not
4212 exist in the file system, @command{tar} reports a difference.
4213
4214 You have to specify the record size of the archive when modifying an
4215 archive with a non-default record size.
4216
4217 @command{tar} ignores files in the file system that do not have
4218 corresponding members in the archive.
4219
4220 The following example compares the archive members @file{rock},
4221 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4222 files of the same name in the file system. (Note that there is no file,
4223 @file{funk}; @command{tar} will report an error message.)
4224
4225 @smallexample
4226 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4227 rock
4228 blues
4229 tar: funk not found in archive
4230 @end smallexample
4231
4232 The spirit behind the @option{--compare} (@option{--diff},
4233 @option{-d}) option is to check whether the archive represents the
4234 current state of files on disk, more than validating the integrity of
4235 the archive media. For this later goal, @xref{verify}.
4236
4237 @node create options
4238 @section Options Used by @option{--create}
4239
4240 @xopindex{create, additional options}
4241 The previous chapter described the basics of how to use
4242 @option{--create} (@option{-c}) to create an archive from a set of files.
4243 @xref{create}. This section described advanced options to be used with
4244 @option{--create}.
4245
4246 @menu
4247 * override:: Overriding File Metadata.
4248 * Ignore Failed Read::
4249 @end menu
4250
4251 @node override
4252 @subsection Overriding File Metadata
4253
4254 As described above, a @command{tar} archive keeps, for each member it contains,
4255 its @dfn{metadata}, such as modification time, mode and ownership of
4256 the file. @GNUTAR{} allows to replace these data with other values
4257 when adding files to the archive. The options described in this
4258 section affect creation of archives of any type. For POSIX archives,
4259 see also @ref{PAX keywords}, for additional ways of controlling
4260 metadata, stored in the archive.
4261
4262 @table @option
4263 @opindex mode
4264 @item --mode=@var{permissions}
4265
4266 When adding files to an archive, @command{tar} will use
4267 @var{permissions} for the archive members, rather than the permissions
4268 from the files. @var{permissions} can be specified either as an octal
4269 number or as symbolic permissions, like with
4270 @command{chmod} (@xref{File permissions, Permissions, File
4271 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4272 also has useful information for those not being overly familiar with
4273 the UNIX permission system). Using latter syntax allows for
4274 more flexibility. For example, the value @samp{a+rw} adds read and write
4275 permissions for everybody, while retaining executable bits on directories
4276 or on any other file already marked as executable:
4277
4278 @smallexample
4279 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4280 @end smallexample
4281
4282 @item --mtime=@var{date}
4283 @opindex mtime
4284
4285 When adding files to an archive, @command{tar} will use @var{date} as
4286 the modification time of members when creating archives, instead of
4287 their actual modification times. The argument @var{date} can be
4288 either a textual date representation in almost arbitrary format
4289 (@pxref{Date input formats}) or a name of the existing file, starting
4290 with @samp{/} or @samp{.}. In the latter case, the modification time
4291 of that file will be used.
4292
4293 The following example will set the modification date to 00:00:00 UTC,
4294 January 1, 1970:
4295
4296 @smallexample
4297 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4298 @end smallexample
4299
4300 @noindent
4301 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4302 will try to convert the specified date back to its textual
4303 representation and compare it with the one given with
4304 @option{--mtime} options. If the two dates differ, @command{tar} will
4305 print a warning saying what date it will use. This is to help user
4306 ensure he is using the right date.
4307
4308 For example:
4309
4310 @smallexample
4311 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4312 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4313 13:06:29.152478
4314 @dots{}
4315 @end smallexample
4316
4317 @item --owner=@var{user}
4318 @opindex owner
4319
4320 Specifies that @command{tar} should use @var{user} as the owner of members
4321 when creating archives, instead of the user associated with the source
4322 file. The argument @var{user} can be either an existing user symbolic
4323 name, or a decimal numeric user ID.
4324
4325 There is no value indicating a missing number, and @samp{0} usually means
4326 @code{root}. Some people like to force @samp{0} as the value to offer in
4327 their distributions for the owner of files, because the @code{root} user is
4328 anonymous anyway, so that might as well be the owner of anonymous
4329 archives. For example:
4330
4331 @smallexample
4332 @group
4333 $ @kbd{tar -c -f archive.tar --owner=0 .}
4334 # @r{Or:}
4335 $ @kbd{tar -c -f archive.tar --owner=root .}
4336 @end group
4337 @end smallexample
4338
4339 @item --group=@var{group}
4340 @opindex group
4341
4342 Files added to the @command{tar} archive will have a group id of @var{group},
4343 rather than the group from the source file. The argument @var{group}
4344 can be either an existing group symbolic name, or a decimal numeric group ID.
4345 @end table
4346
4347 @node Ignore Failed Read
4348 @subsection Ignore Fail Read
4349
4350 @table @option
4351 @item --ignore-failed-read
4352 @opindex ignore-failed-read
4353 Do not exit with nonzero on unreadable files or directories.
4354 @end table
4355
4356 @node extract options
4357 @section Options Used by @option{--extract}
4358 @UNREVISED
4359
4360 @xopindex{extract, additional options}
4361 The previous chapter showed how to use @option{--extract} to extract
4362 an archive into the file system. Various options cause @command{tar} to
4363 extract more information than just file contents, such as the owner,
4364 the permissions, the modification date, and so forth. This section
4365 presents options to be used with @option{--extract} when certain special
4366 considerations arise. You may review the information presented in
4367 @ref{extract} for more basic information about the
4368 @option{--extract} operation.
4369
4370 @menu
4371 * Reading:: Options to Help Read Archives
4372 * Writing:: Changing How @command{tar} Writes Files
4373 * Scarce:: Coping with Scarce Resources
4374 @end menu
4375
4376 @node Reading
4377 @subsection Options to Help Read Archives
4378 @cindex Options when reading archives
4379 @UNREVISED
4380
4381 @cindex Reading incomplete records
4382 @cindex Records, incomplete
4383 @opindex read-full-records
4384 Normally, @command{tar} will request data in full record increments from
4385 an archive storage device. If the device cannot return a full record,
4386 @command{tar} will report an error. However, some devices do not always
4387 return full records, or do not require the last record of an archive to
4388 be padded out to the next record boundary. To keep reading until you
4389 obtain a full record, or to accept an incomplete record if it contains
4390 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4391 in conjunction with the @option{--extract} or @option{--list} operations.
4392 @xref{Blocking}.
4393
4394 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4395 @command{tar} reads an archive from standard input, or from a remote
4396 machine. This is because on BSD Unix systems, attempting to read a
4397 pipe returns however much happens to be in the pipe, even if it is
4398 less than was requested. If this option were not enabled, @command{tar}
4399 would fail as soon as it read an incomplete record from the pipe.
4400
4401 If you're not sure of the blocking factor of an archive, you can
4402 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4403 @option{--blocking-factor=@var{512-size}} (@option{-b
4404 @var{512-size}}), using a blocking factor larger than what the archive
4405 uses. This lets you avoid having to determine the blocking factor
4406 of an archive. @xref{Blocking Factor}.
4407
4408 @menu
4409 * read full records::
4410 * Ignore Zeros::
4411 @end menu
4412
4413 @node read full records
4414 @unnumberedsubsubsec Reading Full Records
4415
4416 @FIXME{need sentence or so of intro here}
4417
4418 @table @option
4419 @opindex read-full-records
4420 @item --read-full-records
4421 @item -B
4422 Use in conjunction with @option{--extract} (@option{--get},
4423 @option{-x}) to read an archive which contains incomplete records, or
4424 one which has a blocking factor less than the one specified.
4425 @end table
4426
4427 @node Ignore Zeros
4428 @unnumberedsubsubsec Ignoring Blocks of Zeros
4429
4430 @cindex End-of-archive blocks, ignoring
4431 @cindex Ignoring end-of-archive blocks
4432 @opindex ignore-zeros
4433 Normally, @command{tar} stops reading when it encounters a block of zeros
4434 between file entries (which usually indicates the end of the archive).
4435 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4436 completely read an archive which contains a block of zeros before the
4437 end (i.e., a damaged archive, or one that was created by concatenating
4438 several archives together).
4439
4440 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4441 versions of @command{tar} write garbage after the end-of-archive entry,
4442 since that part of the media is never supposed to be read. @GNUTAR{}
4443 does not write after the end of an archive, but seeks to
4444 maintain compatiblity among archiving utilities.
4445
4446 @table @option
4447 @item --ignore-zeros
4448 @itemx -i
4449 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4450 encountered while reading an archive. Use in conjunction with
4451 @option{--extract} or @option{--list}.
4452 @end table
4453
4454 @node Writing
4455 @subsection Changing How @command{tar} Writes Files
4456 @UNREVISED
4457
4458 @FIXME{Introductory paragraph}
4459
4460 @menu
4461 * Dealing with Old Files::
4462 * Overwrite Old Files::
4463 * Keep Old Files::
4464 * Keep Newer Files::
4465 * Unlink First::
4466 * Recursive Unlink::
4467 * Data Modification Times::
4468 * Setting Access Permissions::
4469 * Directory Modification Times and Permissions::
4470 * Writing to Standard Output::
4471 * Writing to an External Program::
4472 * remove files::
4473 @end menu
4474
4475 @node Dealing with Old Files
4476 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4477
4478 @xopindex{overwrite-dir, introduced}
4479 When extracting files, if @command{tar} discovers that the extracted
4480 file already exists, it normally replaces the file by removing it before
4481 extracting it, to prevent confusion in the presence of hard or symbolic
4482 links. (If the existing file is a symbolic link, it is removed, not
4483 followed.) However, if a directory cannot be removed because it is
4484 nonempty, @command{tar} normally overwrites its metadata (ownership,
4485 permission, etc.). The @option{--overwrite-dir} option enables this
4486 default behavior. To be more cautious and preserve the metadata of
4487 such a directory, use the @option{--no-overwrite-dir} option.
4488
4489 @cindex Overwriting old files, prevention
4490 @xopindex{keep-old-files, introduced}
4491 To be even more cautious and prevent existing files from being replaced, use
4492 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4493 to replace or update a file that already exists, i.e., a file with the
4494 same name as an archive member prevents extraction of that archive
4495 member. Instead, it reports an error.
4496
4497 @xopindex{overwrite, introduced}
4498 To be more aggressive about altering existing files, use the
4499 @option{--overwrite} option. It causes @command{tar} to overwrite
4500 existing files and to follow existing symbolic links when extracting.
4501
4502 @cindex Protecting old files
4503 Some people argue that @GNUTAR{} should not hesitate
4504 to overwrite files with other files when extracting. When extracting
4505 a @command{tar} archive, they expect to see a faithful copy of the
4506 state of the file system when the archive was created. It is debatable
4507 that this would always be a proper behavior. For example, suppose one
4508 has an archive in which @file{usr/local} is a link to
4509 @file{usr/local2}. Since then, maybe the site removed the link and
4510 renamed the whole hierarchy from @file{/usr/local2} to
4511 @file{/usr/local}. Such things happen all the time. I guess it would
4512 not be welcome at all that @GNUTAR{} removes the
4513 whole hierarchy just to make room for the link to be reinstated
4514 (unless it @emph{also} simultaneously restores the full
4515 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4516 able to remove a whole hierarchy to reestablish a symbolic link, for
4517 example, but @emph{only if} @option{--recursive-unlink} is specified
4518 to allow this behavior. In any case, single files are silently
4519 removed.
4520
4521 @xopindex{unlink-first, introduced}
4522 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4523 some cases by causing @command{tar} to remove files unconditionally
4524 before extracting them.
4525
4526 @node Overwrite Old Files
4527 @unnumberedsubsubsec Overwrite Old Files
4528
4529 @table @option
4530 @opindex overwrite
4531 @item --overwrite
4532 Overwrite existing files and directory metadata when extracting files
4533 from an archive.
4534
4535 This causes @command{tar} to write extracted files into the file system without
4536 regard to the files already on the system; i.e., files with the same
4537 names as archive members are overwritten when the archive is extracted.
4538 It also causes @command{tar} to extract the ownership, permissions,
4539 and time stamps onto any preexisting files or directories.
4540 If the name of a corresponding file name is a symbolic link, the file
4541 pointed to by the symbolic link will be overwritten instead of the
4542 symbolic link itself (if this is possible). Moreover, special devices,
4543 empty directories and even symbolic links are automatically removed if
4544 they are in the way of extraction.
4545
4546 Be careful when using the @option{--overwrite} option, particularly when
4547 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4548 can change the contents, ownership or permissions of any file on your
4549 system. Also, many systems do not take kindly to overwriting files that
4550 are currently being executed.
4551
4552 @opindex overwrite-dir
4553 @item --overwrite-dir
4554 Overwrite the metadata of directories when extracting files from an
4555 archive, but remove other files before extracting.
4556 @end table
4557
4558 @node Keep Old Files
4559 @unnumberedsubsubsec Keep Old Files
4560
4561 @table @option
4562 @opindex keep-old-files
4563 @item --keep-old-files
4564 @itemx -k
4565 Do not replace existing files from archive. The
4566 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4567 from replacing existing files with files with the same name from the
4568 archive. The @option{--keep-old-files} option is meaningless with
4569 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4570 files in the file system during extraction.
4571 @end table
4572
4573 @node Keep Newer Files
4574 @unnumberedsubsubsec Keep Newer Files
4575
4576 @table @option
4577 @opindex keep-newer-files
4578 @item --keep-newer-files
4579 Do not replace existing files that are newer than their archive
4580 copies. This option is meaningless with @option{--list} (@option{-t}).
4581 @end table
4582
4583 @node Unlink First
4584 @unnumberedsubsubsec Unlink First
4585
4586 @table @option
4587 @opindex unlink-first
4588 @item --unlink-first
4589 @itemx -U
4590 Remove files before extracting over them.
4591 This can make @command{tar} run a bit faster if you know in advance
4592 that the extracted files all need to be removed. Normally this option
4593 slows @command{tar} down slightly, so it is disabled by default.
4594 @end table
4595
4596 @node Recursive Unlink
4597 @unnumberedsubsubsec Recursive Unlink
4598
4599 @table @option
4600 @opindex recursive-unlink
4601 @item --recursive-unlink
4602 When this option is specified, try removing files and directory hierarchies
4603 before extracting over them. @emph{This is a dangerous option!}
4604 @end table
4605
4606 If you specify the @option{--recursive-unlink} option,
4607 @command{tar} removes @emph{anything} that keeps you from extracting a file
4608 as far as current permissions will allow it. This could include removal
4609 of the contents of a full directory hierarchy.
4610
4611 @node Data Modification Times
4612 @unnumberedsubsubsec Setting Data Modification Times
4613
4614 @cindex Data modification times of extracted files
4615 @cindex Modification times of extracted files
4616 Normally, @command{tar} sets the data modification times of extracted
4617 files to the corresponding times recorded for the files in the archive, but
4618 limits the permissions of extracted files by the current @code{umask}
4619 setting.
4620
4621 To set the data modification times of extracted files to the time when
4622 the files were extracted, use the @option{--touch} (@option{-m}) option in
4623 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4624
4625 @table @option
4626 @opindex touch
4627 @item --touch
4628 @itemx -m
4629 Sets the data modification time of extracted archive members to the time
4630 they were extracted, not the time recorded for them in the archive.
4631 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4632 @end table
4633
4634 @node Setting Access Permissions
4635 @unnumberedsubsubsec Setting Access Permissions
4636
4637 @cindex Permissions of extracted files
4638 @cindex Modes of extracted files
4639 To set the modes (access permissions) of extracted files to those
4640 recorded for those files in the archive, use @option{--same-permissions}
4641 in conjunction with the @option{--extract} (@option{--get},
4642 @option{-x}) operation.
4643
4644 @table @option
4645 @opindex preserve-permissions
4646 @opindex same-permissions
4647 @item --preserve-permissions
4648 @itemx --same-permissions
4649 @c @itemx --ignore-umask
4650 @itemx -p
4651 Set modes of extracted archive members to those recorded in the
4652 archive, instead of current umask settings. Use in conjunction with
4653 @option{--extract} (@option{--get}, @option{-x}).
4654 @end table
4655
4656 @node Directory Modification Times and Permissions
4657 @unnumberedsubsubsec Directory Modification Times and Permissions
4658
4659 After sucessfully extracting a file member, @GNUTAR{} normally
4660 restores its permissions and modification times, as described in the
4661 previous sections. This cannot be done for directories, because
4662 after extracting a directory @command{tar} will almost certainly
4663 extract files into that directory and this will cause the directory
4664 modification time to be updated. Moreover, restoring that directory
4665 permissions may not permit file creation within it. Thus, restoring
4666 directory permissions and modification times must be delayed at least
4667 until all files have been extracted into that directory. @GNUTAR{}
4668 restores directories using the following approach.
4669
4670 The extracted directories are created with the mode specified in the
4671 archive, as modified by the umask of the user, which gives sufficient
4672 permissions to allow file creation. The meta-information about the
4673 directory is recorded in the temporary list of directories. When
4674 preparing to extract next archive member, @GNUTAR{} checks if the
4675 directory prefix of this file contains the remembered directory. If
4676 it does not, the program assumes that all files have been extracted
4677 into that directory, restores its modification time and permissions
4678 and removes its entry from the internal list. This approach allows
4679 to correctly restore directory meta-information in the majority of
4680 cases, while keeping memory requirements sufficiently small. It is
4681 based on the fact, that most @command{tar} archives use the predefined
4682 order of members: first the directory, then all the files and
4683 subdirectories in that directory.
4684
4685 However, this is not always true. The most important exception are
4686 incremental archives (@pxref{Incremental Dumps}). The member order in
4687 an incremental archive is reversed: first all directory members are
4688 stored, followed by other (non-directory) members. So, when extracting
4689 from incremental archives, @GNUTAR{} alters the above procedure. It
4690 remebers all restored directories, and restores their meta-data
4691 only after the entire archive has been processed. Notice, that you do
4692 not need to specity any special options for that, as @GNUTAR{}
4693 automatically detects archives in incremental format.
4694
4695 There may be cases, when such processing is required for normal archives
4696 too. Consider the following example:
4697
4698 @smallexample
4699 @group
4700 $ @kbd{tar --no-recursion -cvf archive \
4701 foo foo/file1 bar bar/file foo/file2}
4702 foo/
4703 foo/file1
4704 bar/
4705 bar/file
4706 foo/file2
4707 @end group
4708 @end smallexample
4709
4710 During the normal operation, after encountering @file{bar}
4711 @GNUTAR{} will assume that all files from the directory @file{foo}
4712 were already extracted and will therefore restore its timestamp and
4713 permission bits. However, after extracting @file{foo/file2} the
4714 directory timestamp will be offset again.
4715
4716 To correctly restore directory meta-information in such cases, use
4717 @option{delay-directory-restore} command line option:
4718
4719 @table @option
4720 @opindex delay-directory-restore
4721 @item --delay-directory-restore
4722 Delays restoring of the modification times and permissions of extracted
4723 directories until the end of extraction. This way, correct
4724 meta-information is restored even if the archive has unusual member
4725 ordering.
4726
4727 @opindex no-delay-directory-restore
4728 @item --no-delay-directory-restore
4729 Cancel the effect of the previous @option{--delay-directory-restore}.
4730 Use this option if you have used @option{--delay-directory-restore} in
4731 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4732 temporarily disable it.
4733 @end table
4734
4735 @node Writing to Standard Output
4736 @unnumberedsubsubsec Writing to Standard Output
4737
4738 @cindex Writing extracted files to standard output
4739 @cindex Standard output, writing extracted files to
4740 To write the extracted files to the standard output, instead of
4741 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4742 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4743 extracting files to send them through a pipe, and do not need to
4744 preserve them in the file system. If you extract multiple members,
4745 they appear on standard output concatenated, in the order they are
4746 found in the archive.
4747
4748 @table @option
4749 @opindex to-stdout
4750 @item --to-stdout
4751 @itemx -O
4752 Writes files to the standard output. Use only in conjunction with
4753 @option{--extract} (@option{--get}, @option{-x}). When this option is
4754 used, instead of creating the files specified, @command{tar} writes
4755 the contents of the files extracted to its standard output. This may
4756 be useful if you are only extracting the files in order to send them
4757 through a pipe. This option is meaningless with @option{--list}
4758 (@option{-t}).
4759 @end table
4760
4761 This can be useful, for example, if you have a tar archive containing
4762 a big file and don't want to store the file on disk before processing
4763 it. You can use a command like this:
4764
4765 @smallexample
4766 tar -xOzf foo.tgz bigfile | process
4767 @end smallexample
4768
4769 or even like this if you want to process the concatenation of the files:
4770
4771 @smallexample
4772 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4773 @end smallexample
4774
4775 Hovewer, @option{--to-command} may be more convenient for use with
4776 multiple files. See the next section.
4777
4778 @node Writing to an External Program
4779 @unnumberedsubsubsec Writing to an External Program
4780
4781 You can instruct @command{tar} to send the contents of each extracted
4782 file to the standard input of an external program:
4783
4784 @table @option
4785 @opindex to-command
4786 @item --to-command=@var{command}
4787 Extract files and pipe their contents to the standard input of
4788 @var{command}. When this option is used, instead of creating the
4789 files specified, @command{tar} invokes @var{command} and pipes the
4790 contents of the files to its standard output. @var{Command} may
4791 contain command line arguments. The program is executed via
4792 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4793 extracted. Non-regular files (directories, etc.) are ignored when this
4794 option is used.
4795 @end table
4796
4797 The command can obtain the information about the file it processes
4798 from the following environment variables:
4799
4800 @table @var
4801 @vrindex TAR_FILETYPE, to-command environment
4802 @item TAR_FILETYPE
4803 Type of the file. It is a single letter with the following meaning:
4804
4805 @multitable @columnfractions 0.10 0.90
4806 @item f @tab Regular file
4807 @item d @tab Directory
4808 @item l @tab Symbolic link
4809 @item h @tab Hard link
4810 @item b @tab Block device
4811 @item c @tab Character device
4812 @end multitable
4813
4814 Currently only regular files are supported.
4815
4816 @vrindex TAR_MODE, to-command environment
4817 @item TAR_MODE
4818 File mode, an octal number.
4819
4820 @vrindex TAR_FILENAME, to-command environment
4821 @item TAR_FILENAME
4822 The name of the file.
4823
4824 @vrindex TAR_REALNAME, to-command environment
4825 @item TAR_REALNAME
4826 Name of the file as stored in the archive.
4827
4828 @vrindex TAR_UNAME, to-command environment
4829 @item TAR_UNAME
4830 Name of the file owner.
4831
4832 @vrindex TAR_GNAME, to-command environment
4833 @item TAR_GNAME
4834 Name of the file owner group.
4835
4836 @vrindex TAR_ATIME, to-command environment
4837 @item TAR_ATIME
4838 Time of last access. It is a decimal number, representing seconds
4839 since the epoch. If the archive provides times with nanosecond
4840 precision, the nanoseconds are appended to the timestamp after a
4841 decimal point.
4842
4843 @vrindex TAR_MTIME, to-command environment
4844 @item TAR_MTIME
4845 Time of last modification.
4846
4847 @vrindex TAR_CTIME, to-command environment
4848 @item TAR_CTIME
4849 Time of last status change.
4850
4851 @vrindex TAR_SIZE, to-command environment
4852 @item TAR_SIZE
4853 Size of the file.
4854
4855 @vrindex TAR_UID, to-command environment
4856 @item TAR_UID
4857 UID of the file owner.
4858
4859 @vrindex TAR_GID, to-command environment
4860 @item TAR_GID
4861 GID of the file owner.
4862 @end table
4863
4864 In addition to these variables, @env{TAR_VERSION} contains the
4865 @GNUTAR{} version number.
4866
4867 If @var{command} exits with a non-0 status, @command{tar} will print
4868 an error message similar to the following:
4869
4870 @smallexample
4871 tar: 2345: Child returned status 1
4872 @end smallexample
4873
4874 Here, @samp{2345} is the PID of the finished process.
4875
4876 If this behavior is not wanted, use @option{--ignore-command-error}:
4877
4878 @table @option
4879 @opindex ignore-command-error
4880 @item --ignore-command-error
4881 Ignore exit codes of subprocesses. Notice that if the program
4882 exits on signal or otherwise terminates abnormally, the error message
4883 will be printed even if this option is used.
4884
4885 @opindex no-ignore-command-error
4886 @item --no-ignore-command-error
4887 Cancel the effect of any previous @option{--ignore-command-error}
4888 option. This option is useful if you have set
4889 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4890 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4891 @end table
4892
4893 @node remove files
4894 @unnumberedsubsubsec Removing Files
4895
4896 @FIXME{The section is too terse. Something more to add? An example,
4897 maybe?}
4898
4899 @table @option
4900 @opindex remove-files
4901 @item --remove-files
4902 Remove files after adding them to the archive.
4903 @end table
4904
4905 @node Scarce
4906 @subsection Coping with Scarce Resources
4907 @UNREVISED
4908
4909 @cindex Small memory
4910 @cindex Running out of space
4911
4912 @menu
4913 * Starting File::
4914 * Same Order::
4915 @end menu
4916
4917 @node Starting File
4918 @unnumberedsubsubsec Starting File
4919
4920 @table @option
4921 @opindex starting-file
4922 @item --starting-file=@var{name}
4923 @itemx -K @var{name}
4924 Starts an operation in the middle of an archive. Use in conjunction
4925 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4926 @end table
4927
4928 @cindex Middle of the archive, starting in the
4929 If a previous attempt to extract files failed due to lack of disk
4930 space, you can use @option{--starting-file=@var{name}} (@option{-K
4931 @var{name}}) to start extracting only after member @var{name} of the
4932 archive. This assumes, of course, that there is now free space, or
4933 that you are now extracting into a different file system. (You could
4934 also choose to suspend @command{tar}, remove unnecessary files from
4935 the file system, and then restart the same @command{tar} operation.
4936 In this case, @option{--starting-file} is not necessary.
4937 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4938
4939 @node Same Order
4940 @unnumberedsubsubsec Same Order
4941
4942 @table @option
4943 @cindex Large lists of file names on small machines
4944 @opindex same-order
4945 @opindex preserve-order
4946 @item --same-order
4947 @itemx --preserve-order
4948 @itemx -s
4949 To process large lists of file names on machines with small amounts of
4950 memory. Use in conjunction with @option{--compare} (@option{--diff},
4951 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4952 (@option{--get}, @option{-x}).
4953 @end table
4954
4955 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4956 names to be listed or extracted is sorted in the same order as the
4957 files in the archive. This allows a large list of names to be used,
4958 even on a small machine that would not otherwise be able to hold all
4959 the names in memory at the same time. Such a sorted list can easily be
4960 created by running @samp{tar -t} on the archive and editing its output.
4961
4962 This option is probably never needed on modern computer systems.
4963
4964 @node backup
4965 @section Backup options
4966
4967 @cindex backup options
4968
4969 @GNUTAR{} offers options for making backups of files
4970 before writing new versions. These options control the details of
4971 these backups. They may apply to the archive itself before it is
4972 created or rewritten, as well as individual extracted members. Other
4973 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4974 and @command{mv}, for example) offer similar options.
4975
4976 Backup options may prove unexpectedly useful when extracting archives
4977 containing many members having identical name, or when extracting archives
4978 on systems having file name limitations, making different members appear
4979 has having similar names through the side-effect of name truncation.
4980 (This is true only if we have a good scheme for truncated backup names,
4981 which I'm not sure at all: I suspect work is needed in this area.)
4982 When any existing file is backed up before being overwritten by extraction,
4983 then clashing files are automatically be renamed to be unique, and the
4984 true name is kept for only the last file of a series of clashing files.
4985 By using verbose mode, users may track exactly what happens.
4986
4987 At the detail level, some decisions are still experimental, and may
4988 change in the future, we are waiting comments from our users. So, please
4989 do not learn to depend blindly on the details of the backup features.
4990 For example, currently, directories themselves are never renamed through
4991 using these options, so, extracting a file over a directory still has
4992 good chances to fail. Also, backup options apply to created archives,
4993 not only to extracted members. For created archives, backups will not
4994 be attempted when the archive is a block or character device, or when it
4995 refers to a remote file.
4996
4997 For the sake of simplicity and efficiency, backups are made by renaming old
4998 files prior to creation or extraction, and not by copying. The original
4999 name is restored if the file creation fails. If a failure occurs after a
5000 partial extraction of a file, both the backup and the partially extracted
5001 file are kept.
5002
5003 @table @samp
5004 @item --backup[=@var{method}]
5005 @opindex backup
5006 @vindex VERSION_CONTROL
5007 @cindex backups
5008 Back up files that are about to be overwritten or removed.
5009 Without this option, the original versions are destroyed.
5010
5011 Use @var{method} to determine the type of backups made.
5012 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5013 environment variable. And if @env{VERSION_CONTROL} is not set,
5014 use the @samp{existing} method.
5015
5016 @vindex version-control @r{Emacs variable}
5017 This option corresponds to the Emacs variable @samp{version-control};
5018 the same values for @var{method} are accepted as in Emacs. This option
5019 also allows more descriptive names. The valid @var{method}s are:
5020
5021 @table @samp
5022 @item t
5023 @itemx numbered
5024 @cindex numbered @r{backup method}
5025 Always make numbered backups.
5026
5027 @item nil
5028 @itemx existing
5029 @cindex existing @r{backup method}
5030 Make numbered backups of files that already have them, simple backups
5031 of the others.
5032
5033 @item never
5034 @itemx simple
5035 @cindex simple @r{backup method}
5036 Always make simple backups.
5037
5038 @end table
5039
5040 @item --suffix=@var{suffix}
5041 @opindex suffix
5042 @cindex backup suffix
5043 @vindex SIMPLE_BACKUP_SUFFIX
5044 Append @var{suffix} to each backup file made with @option{--backup}. If this
5045 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5046 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5047 set, the default is @samp{~}, just as in Emacs.
5048
5049 @end table
5050
5051 @node Applications
5052 @section Notable @command{tar} Usages
5053 @UNREVISED
5054
5055 @FIXME{Using Unix file linking capability to recreate directory
5056 structures---linking files into one subdirectory and then
5057 @command{tar}ring that directory.}
5058
5059 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5060
5061 @findex uuencode
5062 You can easily use archive files to transport a group of files from
5063 one system to another: put all relevant files into an archive on one
5064 computer system, transfer the archive to another system, and extract
5065 the contents there. The basic transfer medium might be magnetic tape,
5066 Internet FTP, or even electronic mail (though you must encode the
5067 archive with @command{uuencode} in order to transport it properly by
5068 mail). Both machines do not have to use the same operating system, as
5069 long as they both support the @command{tar} program.
5070
5071 For example, here is how you might copy a directory's contents from
5072 one disk to another, while preserving the dates, modes, owners and
5073 link-structure of all the files therein. In this case, the transfer
5074 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5075
5076 @smallexample
5077 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5078 @end smallexample
5079
5080 @noindent
5081 You can avoid subshells by using @option{-C} option:
5082
5083 @smallexample
5084 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5085 @end smallexample
5086
5087 @noindent
5088 The command also works using short option forms:
5089
5090 @smallexample
5091 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5092 | (cd targetdir; tar --extract --file=-)}
5093 # Or:
5094 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5095 | tar --directory targetdir --extract --file=-}
5096 @end smallexample
5097
5098 @noindent
5099 This is one of the easiest methods to transfer a @command{tar} archive.
5100
5101 @node looking ahead
5102 @section Looking Ahead: The Rest of this Manual
5103
5104 You have now seen how to use all eight of the operations available to
5105 @command{tar}, and a number of the possible options. The next chapter
5106 explains how to choose and change file and archive names, how to use
5107 files to store names of other files which you can then call as
5108 arguments to @command{tar} (this can help you save time if you expect to
5109 archive the same list of files a number of times), and so forth.
5110 @FIXME{in case it's not obvious, i'm making this up in some sense
5111 based on my limited memory of what the next chapter *really* does. i
5112 just wanted to flesh out this final section a little bit so i'd
5113 remember to stick it in here. :-)}
5114
5115 If there are too many files to conveniently list on the command line,
5116 you can list the names in a file, and @command{tar} will read that file.
5117 @xref{files}.
5118
5119 There are various ways of causing @command{tar} to skip over some files,
5120 and not archive them. @xref{Choosing}.
5121
5122 @node Backups
5123 @chapter Performing Backups and Restoring Files
5124 @UNREVISED
5125
5126 @GNUTAR{} is distributed along with the scripts
5127 which the Free Software Foundation uses for performing backups. There
5128 is no corresponding scripts available yet for doing restoration of
5129 files. Even if there is a good chance those scripts may be satisfying
5130 to you, they are not the only scripts or methods available for doing
5131 backups and restore. You may well create your own, or use more
5132 sophisticated packages dedicated to that purpose.
5133
5134 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5135 Automatic Network Disk Archiver), a backup system developed by James
5136 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5137 This is free software, and it is available at these places:
5138
5139 @smallexample
5140 http://www.cs.umd.edu/projects/amanda/amanda.html
5141 ftp://ftp.cs.umd.edu/pub/amanda
5142 @end smallexample
5143
5144 @FIXME{
5145
5146 Here is a possible plan for a future documentation about the backuping
5147 scripts which are provided within the @GNUTAR{}
5148 distribution.
5149
5150 @itemize @bullet
5151 @item dumps
5152 @itemize @minus
5153 @item what are dumps
5154 @item different levels of dumps
5155 @itemize +
5156 @item full dump = dump everything
5157 @item level 1, level 2 dumps etc
5158 A level @var{n} dump dumps everything changed since the last level
5159 @var{n}-1 dump (?)
5160 @end itemize
5161 @item how to use scripts for dumps (ie, the concept)
5162 @itemize +
5163 @item scripts to run after editing backup specs (details)
5164 @end itemize
5165 @item Backup Specs, what is it.
5166 @itemize +
5167 @item how to customize
5168 @item actual text of script [/sp/dump/backup-specs]
5169 @end itemize
5170 @item Problems
5171 @itemize +
5172 @item rsh doesn't work
5173 @item rtape isn't installed
5174 @item (others?)
5175 @end itemize
5176 @item the @option{--incremental} option of tar
5177 @item tapes
5178 @itemize +
5179 @item write protection
5180 @item types of media, different sizes and types, useful for different things
5181 @item files and tape marks
5182 one tape mark between files, two at end.
5183 @item positioning the tape
5184 MT writes two at end of write,
5185 backspaces over one when writing again.
5186 @end itemize
5187 @end itemize
5188 @end itemize
5189 }
5190
5191 This chapter documents both the provided shell scripts and @command{tar}
5192 options which are more specific to usage as a backup tool.
5193
5194 To @dfn{back up} a file system means to create archives that contain
5195 all the files in that file system. Those archives can then be used to
5196 restore any or all of those files (for instance if a disk crashes or a
5197 file is accidentally deleted). File system @dfn{backups} are also
5198 called @dfn{dumps}.
5199
5200 @menu
5201 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5202 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5203 * Backup Levels:: Levels of Backups
5204 * Backup Parameters:: Setting Parameters for Backups and Restoration
5205 * Scripted Backups:: Using the Backup Scripts
5206 * Scripted Restoration:: Using the Restore Script
5207 @end menu
5208
5209 @node Full Dumps
5210 @section Using @command{tar} to Perform Full Dumps
5211 @UNREVISED
5212
5213 @cindex full dumps
5214 @cindex dumps, full
5215
5216 @cindex corrupted archives
5217 Full dumps should only be made when no other people or programs
5218 are modifying files in the file system. If files are modified while
5219 @command{tar} is making the backup, they may not be stored properly in
5220 the archive, in which case you won't be able to restore them if you
5221 have to. (Files not being modified are written with no trouble, and do
5222 not corrupt the entire archive.)
5223
5224 You will want to use the @option{--label=@var{archive-label}}
5225 (@option{-V @var{archive-label}}) option to give the archive a
5226 volume label, so you can tell what this archive is even if the label
5227 falls off the tape, or anything like that.
5228
5229 Unless the file system you are dumping is guaranteed to fit on
5230 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5231 Make sure you have enough tapes on hand to complete the backup.
5232
5233 If you want to dump each file system separately you will need to use
5234 the @option{--one-file-system} option to prevent
5235 @command{tar} from crossing file system boundaries when storing
5236 (sub)directories.
5237
5238 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5239 option is not needed, since this is a complete copy of everything in
5240 the file system, and a full restore from this backup would only be
5241 done onto a completely
5242 empty disk.
5243
5244 Unless you are in a hurry, and trust the @command{tar} program (and your
5245 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5246 option, to make sure your files really made it onto the dump properly.
5247 This will also detect cases where the file was modified while (or just
5248 after) it was being archived. Not all media (notably cartridge tapes)
5249 are capable of being verified, unfortunately.
5250
5251 @node Incremental Dumps
5252 @section Using @command{tar} to Perform Incremental Dumps
5253
5254 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5255 stores additional metadata so that exact state of the file system
5256 can be restored when extracting the archive.
5257
5258 @GNUTAR{} currently offers two options for handling incremental
5259 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5260 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5261
5262 @opindex listed-incremental
5263 The option @option{--listed-incremental} instructs tar to operate on
5264 an incremental archive with additional metadata stored in a standalone
5265 file, called a @dfn{snapshot file}. The purpose of this file is to help
5266 determine which files have been changed, added or deleted since the
5267 last backup, so that the next incremental backup will contain only
5268 modified files. The name of the snapshot file is given as an argument
5269 to the option:
5270
5271 @table @option
5272 @item --listed-incremental=@var{file}
5273 @itemx -g @var{file}
5274 Handle incremental backups with snapshot data in @var{file}.
5275 @end table
5276
5277 To create an incremental backup, you would use
5278 @option{--listed-incremental} together with @option{--create}
5279 (@pxref{create}). For example:
5280
5281 @smallexample
5282 $ @kbd{tar --create \
5283 --file=archive.1.tar \
5284 --listed-incremental=/var/log/usr.snar \
5285 /usr}
5286 @end smallexample
5287
5288 This will create in @file{archive.1.tar} an incremental backup of
5289 the @file{/usr} file system, storing additional metadata in the file
5290 @file{/var/log/usr.snar}. If this file does not exist, it will be
5291 created. The created archive will then be a @dfn{level 0 backup};
5292 please see the next section for more on backup levels.
5293
5294 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5295 determines which files are modified. In this case only these files will be
5296 stored in the archive. Suppose, for example, that after running the
5297 above command, you delete file @file{/usr/doc/old} and create
5298 directory @file{/usr/local/db} with the following contents:
5299
5300 @smallexample
5301 $ @kbd{ls /usr/local/db}
5302 /usr/local/db/data
5303 /usr/local/db/index
5304 @end smallexample
5305
5306 Some time later you create another incremental backup. You will
5307 then see:
5308
5309 @smallexample
5310 $ @kbd{tar --create \
5311 --file=archive.2.tar \
5312 --listed-incremental=/var/log/usr.snar \
5313 /usr}
5314 tar: usr/local/db: Directory is new
5315 usr/local/db/
5316 usr/local/db/data
5317 usr/local/db/index
5318 @end smallexample
5319
5320 @noindent
5321 The created archive @file{archive.2.tar} will contain only these
5322 three members. This archive is called a @dfn{level 1 backup}. Notice
5323 that @file{/var/log/usr.snar} will be updated with the new data, so if
5324 you plan to create more @samp{level 1} backups, it is necessary to
5325 create a working copy of the snapshot file before running
5326 @command{tar}. The above example will then be modified as follows:
5327
5328 @smallexample
5329 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5330 $ @kbd{tar --create \
5331 --file=archive.2.tar \
5332 --listed-incremental=/var/log/usr.snar-1 \
5333 /usr}
5334 @end smallexample
5335
5336 Incremental dumps depend crucially on time stamps, so the results are
5337 unreliable if you modify a file's time stamps during dumping (e.g.,
5338 with the @option{--atime-preserve=replace} option), or if you set the clock
5339 backwards.
5340
5341 Metadata stored in snapshot files include device numbers, which,
5342 obviously is supposed to be a non-volatile value. However, it turns
5343 out that NFS devices have undependable values when an automounter
5344 gets in the picture. This can lead to a great deal of spurious
5345 redumping in incremental dumps, so it is somewhat useless to compare
5346 two NFS devices numbers over time. The solution implemented currently
5347 is to considers all NFS devices as being equal when it comes to
5348 comparing directories; this is fairly gross, but there does not seem
5349 to be a better way to go.
5350
5351 Note that incremental archives use @command{tar} extensions and may
5352 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5353
5354 @xopindex{listed-incremental, using with @option{--extract}}
5355 @xopindex{extract, using with @option{--listed-incremental}}
5356 To extract from the incremental dumps, use
5357 @option{--listed-incremental} together with @option{--extract}
5358 option (@pxref{extracting files}). In this case, @command{tar} does
5359 not need to access snapshot file, since all the data necessary for
5360 extraction are stored in the archive itself. So, when extracting, you
5361 can give whatever argument to @option{--listed-incremental}, the usual
5362 practice is to use @option{--listed-incremental=/dev/null}.
5363 Alternatively, you can use @option{--incremental}, which needs no
5364 arguments. In general, @option{--incremental} (@option{-G}) can be
5365 used as a shortcut for @option{--listed-incremental} when listing or
5366 extracting incremental backups (for more information, regarding this
5367 option, @pxref{incremental-op}).
5368
5369 When extracting from the incremental backup @GNUTAR{} attempts to
5370 restore the exact state the file system had when the archive was
5371 created. In particular, it will @emph{delete} those files in the file
5372 system that did not exist in their directories when the archive was
5373 created. If you have created several levels of incremental files,
5374 then in order to restore the exact contents the file system had when
5375 the last level was created, you will need to restore from all backups
5376 in turn. Continuing our example, to restore the state of @file{/usr}
5377 file system, one would do@footnote{Notice, that since both archives
5378 were created withouth @option{-P} option (@pxref{absolute}), these
5379 commands should be run from the root file system.}:
5380
5381 @smallexample
5382 $ @kbd{tar --extract \
5383 --listed-incremental=/dev/null \
5384 --file archive.1.tar}
5385 $ @kbd{tar --extract \
5386 --listed-incremental=/dev/null \
5387 --file archive.2.tar}
5388 @end smallexample
5389
5390 To list the contents of an incremental archive, use @option{--list}
5391 (@pxref{list}), as usual. To obtain more information about the
5392 archive, use @option{--listed-incremental} or @option{--incremental}
5393 combined with two @option{--verbose} options@footnote{Two
5394 @option{--verbose} options were selected to avoid breaking usual
5395 verbose listing output (@option{--list --verbose}) when using in
5396 scripts.
5397
5398 @xopindex{incremental, using with @option{--list}}
5399 @xopindex{listed-incremental, using with @option{--list}}
5400 @xopindex{list, using with @option{--incremental}}
5401 @xopindex{list, using with @option{--listed-incremental}}
5402 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5403 contents of the DUMPDIR header (with terminating nulls) when
5404 @option{--incremental} or @option{--listed-incremental} option was
5405 given, no matter what the verbosity level. This behavior, and,
5406 especially, the binary output it produced were considered incovenient
5407 and were changed in version 1.16}:
5408
5409 @smallexample
5410 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5411 @end smallexample
5412
5413 This command will print, for each directory in the archive, the list
5414 of files in that directory at the time the archive was created. This
5415 information is put out in a format which is both human-readable and
5416 unambiguous for a program: each file name is printed as
5417
5418 @smallexample
5419 @var{x} @var{file}
5420 @end smallexample
5421
5422 @noindent
5423 where @var{x} is a letter describing the status of the file: @samp{Y}
5424 if the file is present in the archive, @samp{N} if the file is not
5425 included in the archive, or a @samp{D} if the file is a directory (and
5426 is included in the archive). @xref{Dumpdir}, for the detailed
5427 description of dumpdirs and status codes. Each such
5428 line is terminated by a newline character. The last line is followed
5429 by an additional newline to indicate the end of the data.
5430
5431 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5432 gives the same behavior as @option{--listed-incremental} when used
5433 with @option{--list} and @option{--extract} options. When used with
5434 @option{--create} option, it creates an incremental archive without
5435 creating snapshot file. Thus, it is impossible to create several
5436 levels of incremental backups with @option{--incremental} option.
5437
5438 @node Backup Levels
5439 @section Levels of Backups
5440
5441 An archive containing all the files in the file system is called a
5442 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5443 creating a full dump every day. This strategy, however, would waste a
5444 substantial amount of archive media and user time, as unchanged files
5445 are daily re-archived.
5446
5447 It is more efficient to do a full dump only occasionally. To back up
5448 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5449 one} dump archives all the files that have changed since the last full
5450 dump.
5451
5452 A typical dump strategy would be to perform a full dump once a week,
5453 and a level one dump once a day. This means some versions of files
5454 will in fact be archived more than once, but this dump strategy makes
5455 it possible to restore a file system to within one day of accuracy by
5456 only extracting two archives---the last weekly (full) dump and the
5457 last daily (level one) dump. The only information lost would be in
5458 files changed or created since the last daily backup. (Doing dumps
5459 more than once a day is usually not worth the trouble).
5460
5461 @GNUTAR{} comes with scripts you can use to do full
5462 and level-one (actually, even level-two and so on) dumps. Using
5463 scripts (shell programs) to perform backups and restoration is a
5464 convenient and reliable alternative to typing out file name lists
5465 and @command{tar} commands by hand.
5466
5467 Before you use these scripts, you need to edit the file
5468 @file{backup-specs}, which specifies parameters used by the backup
5469 scripts and by the restore script. This file is usually located
5470 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5471 detailed description. Once the backup parameters are set, you can
5472 perform backups or restoration by running the appropriate script.
5473
5474 The name of the backup script is @code{backup}. The name of the
5475 restore script is @code{restore}. The following sections describe
5476 their use in detail.
5477
5478 @emph{Please Note:} The backup and restoration scripts are
5479 designed to be used together. While it is possible to restore files by
5480 hand from an archive which was created using a backup script, and to create
5481 an archive by hand which could then be extracted using the restore script,
5482 it is easier to use the scripts. @xref{Incremental Dumps}, before
5483 making such an attempt.
5484
5485 @node Backup Parameters
5486 @section Setting Parameters for Backups and Restoration
5487
5488 The file @file{backup-specs} specifies backup parameters for the
5489 backup and restoration scripts provided with @command{tar}. You must
5490 edit @file{backup-specs} to fit your system configuration and schedule
5491 before using these scripts.
5492
5493 Syntactically, @file{backup-specs} is a shell script, containing
5494 mainly variable assignments. However, any valid shell construct
5495 is allowed in this file. Particularly, you may wish to define
5496 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5497 For more information about shell script syntax, please refer to
5498 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5499 g_02, the definition of the Shell Command Language}. See also
5500 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5501
5502 The shell variables controlling behavior of @code{backup} and
5503 @code{restore} are described in the following subsections.
5504
5505 @menu
5506 * General-Purpose Variables::
5507 * Magnetic Tape Control::
5508 * User Hooks::
5509 * backup-specs example:: An Example Text of @file{Backup-specs}
5510 @end menu
5511
5512 @node General-Purpose Variables
5513 @subsection General-Purpose Variables
5514
5515 @defvr {Backup variable} ADMINISTRATOR
5516 The user name of the backup administrator. @code{Backup} scripts
5517 sends a backup report to this address.
5518 @end defvr
5519
5520 @defvr {Backup variable} BACKUP_HOUR
5521 The hour at which the backups are done. This can be a number from 0
5522 to 23, or the time specification in form @var{hours}:@var{minutes},
5523 or the string @samp{now}.
5524
5525 This variable is used by @code{backup}. Its value may be overridden
5526 using @option{--time} option (@pxref{Scripted Backups}).
5527 @end defvr
5528
5529 @defvr {Backup variable} TAPE_FILE
5530
5531 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5532 is a remote archive (@pxref{remote-dev}), backup script will suppose
5533 that your @command{mt} is able to access remote devices. If @var{RSH}
5534 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5535 invocations of @command{mt}.
5536 @end defvr
5537
5538 @defvr {Backup variable} BLOCKING
5539
5540 The blocking factor @command{tar} will use when writing the dump archive.
5541 @xref{Blocking Factor}.
5542 @end defvr
5543
5544 @defvr {Backup variable} BACKUP_DIRS
5545
5546 A list of file systems to be dumped (for @code{backup}), or restored
5547 (for @code{restore}). You can include any directory
5548 name in the list --- subdirectories on that file system will be
5549 included, regardless of how they may look to other networked machines.
5550 Subdirectories on other file systems will be ignored.
5551
5552 The host name specifies which host to run @command{tar} on, and should
5553 normally be the host that actually contains the file system. However,
5554 the host machine must have @GNUTAR{} installed, and
5555 must be able to access the directory containing the backup scripts and
5556 their support files using the same file name that is used on the
5557 machine where the scripts are run (i.e. what @command{pwd} will print
5558 when in that directory on that machine). If the host that contains
5559 the file system does not have this capability, you can specify another
5560 host as long as it can access the file system through NFS.
5561
5562 If the list of file systems is very long you may wish to put it
5563 in a separate file. This file is usually named
5564 @file{/etc/backup/dirs}, but this name may be overridden in
5565 @file{backup-specs} using @code{DIRLIST} variable.
5566 @end defvr
5567
5568 @defvr {Backup variable} DIRLIST
5569
5570 A path to the file containing the list of the file systems to backup
5571 or restore. By default it is @file{/etc/backup/dirs}.
5572 @end defvr
5573
5574 @defvr {Backup variable} BACKUP_FILES
5575
5576 A list of individual files to be dumped (for @code{backup}), or restored
5577 (for @code{restore}). These should be accessible from the machine on
5578 which the backup script is run.
5579
5580 If the list of file systems is very long you may wish to store it
5581 in a separate file. This file is usually named
5582 @file{/etc/backup/files}, but this name may be overridden in
5583 @file{backup-specs} using @code{FILELIST} variable.
5584 @end defvr
5585
5586 @defvr {Backup variable} FILELIST
5587
5588 A path to the file containing the list of the individual files to backup
5589 or restore. By default it is @file{/etc/backup/files}.
5590 @end defvr
5591
5592 @defvr {Backup variable} MT
5593
5594 Full file name of @command{mt} binary.
5595 @end defvr
5596
5597 @defvr {Backup variable} RSH
5598 @anchor{RSH}
5599 Full file name of @command{rsh} binary or its equivalent. You may wish to
5600 set it to @code{ssh}, to improve security. In this case you will have
5601 to use public key authentication.
5602 @end defvr
5603
5604 @defvr {Backup variable} RSH_COMMAND
5605
5606 Full file name of @command{rsh} binary on remote mashines. This will
5607 be passed via @option{--rsh-command} option to the remote invocation
5608 of @GNUTAR{}.
5609 @end defvr
5610
5611 @defvr {Backup variable} VOLNO_FILE
5612
5613 Name of temporary file to hold volume numbers. This needs to be accessible
5614 by all the machines which have file systems to be dumped.
5615 @end defvr
5616
5617 @defvr {Backup variable} XLIST
5618
5619 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5620 located on the remote machine and containing the list of files to
5621 be excluded from the backup. Exclude file lists are searched in
5622 /etc/tar-backup directory. A common use for exclude file lists
5623 is to exclude files containing security-sensitive information
5624 (e.g., @file{/etc/shadow} from backups).
5625
5626 This variable affects only @code{backup}.
5627 @end defvr
5628
5629 @defvr {Backup variable} SLEEP_TIME
5630
5631 Time to sleep between dumps of any two successive file systems
5632
5633 This variable affects only @code{backup}.
5634 @end defvr
5635
5636 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5637
5638 Script to be run when it's time to insert a new tape in for the next
5639 volume. Administrators may want to tailor this script for their site.
5640 If this variable isn't set, @GNUTAR{} will display its built-in
5641 prompt, and will expect confirmation from the console. For the
5642 description of the default prompt, see @ref{change volume prompt}.
5643
5644 @end defvr
5645
5646 @defvr {Backup variable} SLEEP_MESSAGE
5647
5648 Message to display on the terminal while waiting for dump time. Usually
5649 this will just be some literal text.
5650 @end defvr
5651
5652 @defvr {Backup variable} TAR
5653
5654 Full file name of the @GNUTAR{} executable. If this is not set, backup
5655 scripts will search @command{tar} in the current shell path.
5656 @end defvr
5657
5658 @node Magnetic Tape Control
5659 @subsection Magnetic Tape Control
5660
5661 Backup scripts access tape device using special @dfn{hook functions}.
5662 These functions take a single argument -- the name of the tape
5663 device. Their names are kept in the following variables:
5664
5665 @defvr {Backup variable} MT_BEGIN
5666 The name of @dfn{begin} function. This function is called before
5667 accessing the drive. By default it retensions the tape:
5668
5669 @smallexample
5670 MT_BEGIN=mt_begin
5671
5672 mt_begin() @{
5673 mt -f "$1" retension
5674 @}
5675 @end smallexample
5676 @end defvr
5677
5678 @defvr {Backup variable} MT_REWIND
5679 The name of @dfn{rewind} function. The default definition is as
5680 follows:
5681
5682 @smallexample
5683 MT_REWIND=mt_rewind
5684
5685 mt_rewind() @{
5686 mt -f "$1" rewind
5687 @}
5688 @end smallexample
5689
5690 @end defvr
5691
5692 @defvr {Backup variable} MT_OFFLINE
5693 The name of the function switching the tape off line. By default
5694 it is defined as follows:
5695
5696 @smallexample
5697 MT_OFFLINE=mt_offline
5698
5699 mt_offline() @{
5700 mt -f "$1" offl
5701 @}
5702 @end smallexample
5703 @end defvr
5704
5705 @defvr {Backup variable} MT_STATUS
5706 The name of the function used to obtain the status of the archive device,
5707 including error count. Default definition:
5708
5709 @smallexample
5710 MT_STATUS=mt_status
5711
5712 mt_status() @{
5713 mt -f "$1" status
5714 @}
5715 @end smallexample
5716 @end defvr
5717
5718 @node User Hooks
5719 @subsection User Hooks
5720
5721 @dfn{User hooks} are shell functions executed before and after
5722 each @command{tar} invocation. Thus, there are @dfn{backup
5723 hooks}, which are executed before and after dumping each file
5724 system, and @dfn{restore hooks}, executed before and
5725 after restoring a file system. Each user hook is a shell function
5726 taking four arguments:
5727
5728 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5729 Its arguments are:
5730
5731 @table @var
5732 @item level
5733 Current backup or restore level.
5734
5735 @item host
5736 Name or IP address of the host machine being dumped or restored.
5737
5738 @item fs
5739 Full path name to the file system being dumped or restored.
5740
5741 @item fsname
5742 File system name with directory separators replaced with colons. This
5743 is useful, e.g., for creating unique files.
5744 @end table
5745 @end deffn
5746
5747 Following variables keep the names of user hook functions
5748
5749 @defvr {Backup variable} DUMP_BEGIN
5750 Dump begin function. It is executed before dumping the file system.
5751 @end defvr
5752
5753 @defvr {Backup variable} DUMP_END
5754 Executed after dumping the file system.
5755 @end defvr
5756
5757 @defvr {Backup variable} RESTORE_BEGIN
5758 Executed before restoring the file system.
5759 @end defvr
5760
5761 @defvr {Backup variable} RESTORE_END
5762 Executed after restoring the file system.
5763 @end defvr
5764
5765 @node backup-specs example
5766 @subsection An Example Text of @file{Backup-specs}
5767
5768 The following is an example of @file{backup-specs}:
5769
5770 @smallexample
5771 # site-specific parameters for file system backup.
5772
5773 ADMINISTRATOR=friedman
5774 BACKUP_HOUR=1
5775 TAPE_FILE=/dev/nrsmt0
5776
5777 # Use @code{ssh} instead of the less secure @code{rsh}
5778 RSH=/usr/bin/ssh
5779 RSH_COMMAND=/usr/bin/ssh
5780
5781 # Override MT_STATUS function:
5782 my_status() @{
5783 mts -t $TAPE_FILE
5784 @}
5785 MT_STATUS=my_status
5786
5787 # Disable MT_OFFLINE function
5788 MT_OFFLINE=:
5789
5790 BLOCKING=124
5791 BACKUP_DIRS="
5792 albert:/fs/fsf
5793 apple-gunkies:/gd
5794 albert:/fs/gd2
5795 albert:/fs/gp
5796 geech:/usr/jla
5797 churchy:/usr/roland
5798 albert:/
5799 albert:/usr
5800 apple-gunkies:/
5801 apple-gunkies:/usr
5802 gnu:/hack
5803 gnu:/u
5804 apple-gunkies:/com/mailer/gnu
5805 apple-gunkies:/com/archive/gnu"
5806
5807 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5808
5809 @end smallexample
5810
5811 @node Scripted Backups
5812 @section Using the Backup Scripts
5813
5814 The syntax for running a backup script is:
5815
5816 @smallexample
5817 backup --level=@var{level} --time=@var{time}
5818 @end smallexample
5819
5820 The @option{level} option requests the dump level. Thus, to produce
5821 a full dump, specify @code{--level=0} (this is the default, so
5822 @option{--level} may be omitted if its value is @code{0}).
5823 @footnote{For backward compatibility, the @code{backup} will also
5824 try to deduce the requested dump level from the name of the
5825 script itself. If the name consists of a string @samp{level-}
5826 followed by a single decimal digit, that digit is taken as
5827 the dump level number. Thus, you may create a link from @code{backup}
5828 to @code{level-1} and then run @code{level-1} whenever you need to
5829 create a level one dump.}
5830
5831 The @option{--time} option determines when should the backup be
5832 run. @var{Time} may take three forms:
5833
5834 @table @asis
5835 @item @var{hh}:@var{mm}
5836
5837 The dump must be run at @var{hh} hours @var{mm} minutes.
5838
5839 @item @var{hh}
5840
5841 The dump must be run at @var{hh} hours
5842
5843 @item now
5844
5845 The dump must be run immediately.
5846 @end table
5847
5848 You should start a script with a tape or disk mounted. Once you
5849 start a script, it prompts you for new tapes or disks as it
5850 needs them. Media volumes don't have to correspond to archive
5851 files --- a multi-volume archive can be started in the middle of a
5852 tape that already contains the end of another multi-volume archive.
5853 The @code{restore} script prompts for media by its archive volume,
5854 so to avoid an error message you should keep track of which tape
5855 (or disk) contains which volume of the archive (@pxref{Scripted
5856 Restoration}).
5857
5858 The backup scripts write two files on the file system. The first is a
5859 record file in @file{/etc/tar-backup/}, which is used by the scripts
5860 to store and retrieve information about which files were dumped. This
5861 file is not meant to be read by humans, and should not be deleted by
5862 them. @xref{Snapshot Files}, for a more detailed explanation of this
5863 file.
5864
5865 The second file is a log file containing the names of the file systems
5866 and files dumped, what time the backup was made, and any error
5867 messages that were generated, as well as how much space was left in
5868 the media volume after the last volume of the archive was written.
5869 You should check this log file after every backup. The file name is
5870 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5871 represents current date, and @var{n} represents current dump level number.
5872
5873 The script also prints the name of each system being dumped to the
5874 standard output.
5875
5876 Following is the full list of options accepted by @code{backup}
5877 script:
5878
5879 @table @option
5880 @item -l @var{level}
5881 @itemx --level=@var{level}
5882 Do backup level @var{level} (default 0).
5883
5884 @item -f
5885 @itemx --force
5886 Force backup even if today's log file already exists.
5887
5888 @item -v[@var{level}]
5889 @itemx --verbose[=@var{level}]
5890 Set verbosity level. The higher the level is, the more debugging
5891 information will be output during execution. Devault @var{level}
5892 is 100, which means the highest debugging level.
5893
5894 @item -t @var{start-time}
5895 @itemx --time=@var{start-time}
5896 Wait till @var{time}, then do backup.
5897
5898 @item -h
5899 @itemx --help
5900 Display short help message and exit.
5901
5902 @item -V
5903 @itemx --version
5904 Display information about the program's name, version, origin and legal
5905 status, all on standard output, and then exit successfully.
5906 @end table
5907
5908
5909 @node Scripted Restoration
5910 @section Using the Restore Script
5911
5912 To restore files that were archived using a scripted backup, use the
5913 @code{restore} script. Its usage is quite straightforward. In the
5914 simplest form, invoke @code{restore --all}, it will
5915 then restore all the file systems and files specified in
5916 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5917
5918 You may select the file systems (and/or files) to restore by
5919 giving @code{restore} list of @dfn{patterns} in its command
5920 line. For example, running
5921
5922 @smallexample
5923 restore 'albert:*'
5924 @end smallexample
5925
5926 @noindent
5927 will restore all file systems on the machine @samp{albert}. A more
5928 complicated example:
5929
5930 @smallexample
5931 restore 'albert:*' '*:/var'
5932 @end smallexample
5933
5934 @noindent
5935 This command will restore all file systems on the machine @samp{albert}
5936 as well as @file{/var} file system on all machines.
5937
5938 By default @code{restore} will start restoring files from the lowest
5939 available dump level (usually zero) and will continue through
5940 all available dump levels. There may be situations where such a
5941 thorough restore is not necessary. For example, you may wish to
5942 restore only files from the recent level one backup. To do so,
5943 use @option{--level} option, as shown in the example below:
5944
5945 @smallexample
5946 restore --level=1
5947 @end smallexample
5948
5949 The full list of options accepted by @code{restore} follows:
5950
5951 @table @option
5952 @item -a
5953 @itemx --all
5954 Restore all file systems and files specified in @file{backup-specs}
5955
5956 @item -l @var{level}
5957 @itemx --level=@var{level}
5958 Start restoring from the given backup level, instead of the default 0.
5959
5960 @item -v[@var{level}]
5961 @itemx --verbose[=@var{level}]
5962 Set verbosity level. The higher the level is, the more debugging
5963 information will be output during execution. Devault @var{level}
5964 is 100, which means the highest debugging level.
5965
5966 @item -h
5967 @itemx --help
5968 Display short help message and exit.
5969
5970 @item -V
5971 @itemx --version
5972 Display information about the program's name, version, origin and legal
5973 status, all on standard output, and then exit successfully.
5974 @end table
5975
5976 You should start the restore script with the media containing the
5977 first volume of the archive mounted. The script will prompt for other
5978 volumes as they are needed. If the archive is on tape, you don't need
5979 to rewind the tape to to its beginning---if the tape head is
5980 positioned past the beginning of the archive, the script will rewind
5981 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
5982 positioning.
5983
5984 @quotation
5985 @strong{Warning:} The script will delete files from the active file
5986 system if they were not in the file system when the archive was made.
5987 @end quotation
5988
5989 @xref{Incremental Dumps}, for an explanation of how the script makes
5990 that determination.
5991
5992 @node Choosing
5993 @chapter Choosing Files and Names for @command{tar}
5994 @UNREVISED
5995
5996 Certain options to @command{tar} enable you to specify a name for your
5997 archive. Other options let you decide which files to include or exclude
5998 from the archive, based on when or whether files were modified, whether
5999 the file names do or don't match specified patterns, or whether files
6000 are in specified directories.
6001
6002 This chapter discusses these options in detail.
6003
6004 @menu
6005 * file:: Choosing the Archive's Name
6006 * Selecting Archive Members::
6007 * files:: Reading Names from a File
6008 * exclude:: Excluding Some Files
6009 * wildcards:: Wildcards Patterns and Matching
6010 * quoting styles:: Ways of Quoting Special Characters in Names
6011 * transform:: Modifying File and Member Names
6012 * after:: Operating Only on New Files
6013 * recurse:: Descending into Directories
6014 * one:: Crossing File System Boundaries
6015 @end menu
6016
6017 @node file
6018 @section Choosing and Naming Archive Files
6019 @UNREVISED
6020
6021 @cindex Naming an archive
6022 @cindex Archive Name
6023 @cindex Choosing an archive file
6024 @cindex Where is the archive?
6025 By default, @command{tar} uses an archive file name that was compiled when
6026 it was built on the system; usually this name refers to some physical
6027 tape drive on the machine. However, the person who installed @command{tar}
6028 on the system may not have set the default to a meaningful value as far as
6029 most users are concerned. As a result, you will usually want to tell
6030 @command{tar} where to find (or create) the archive. The
6031 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6032 option allows you to either specify or name a file to use as the archive
6033 instead of the default archive file location.
6034
6035 @table @option
6036 @xopindex{file, short description}
6037 @item --file=@var{archive-name}
6038 @itemx -f @var{archive-name}
6039 Name the archive to create or operate on. Use in conjunction with
6040 any operation.
6041 @end table
6042
6043 For example, in this @command{tar} command,
6044
6045 @smallexample
6046 $ @kbd{tar -cvf collection.tar blues folk jazz}
6047 @end smallexample
6048
6049 @noindent
6050 @file{collection.tar} is the name of the archive. It must directly
6051 follow the @option{-f} option, since whatever directly follows @option{-f}
6052 @emph{will} end up naming the archive. If you neglect to specify an
6053 archive name, you may end up overwriting a file in the working directory
6054 with the archive you create since @command{tar} will use this file's name
6055 for the archive name.
6056
6057 An archive can be saved as a file in the file system, sent through a
6058 pipe or over a network, or written to an I/O device such as a tape,
6059 floppy disk, or CD write drive.
6060
6061 @cindex Writing new archives
6062 @cindex Archive creation
6063 If you do not name the archive, @command{tar} uses the value of the
6064 environment variable @env{TAPE} as the file name for the archive. If
6065 that is not available, @command{tar} uses a default, compiled-in archive
6066 name, usually that for tape unit zero (i.e. @file{/dev/tu00}).
6067
6068 @cindex Standard input and output
6069 @cindex tar to standard input and output
6070 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6071 archive from standard input (when listing or extracting files), or
6072 writes it to standard output (when creating an archive). If you use
6073 @file{-} as an @var{archive-name} when modifying an archive,
6074 @command{tar} reads the original archive from its standard input and
6075 writes the entire new archive to its standard output.
6076
6077 The following example is a convenient way of copying directory
6078 hierarchy from @file{sourcedir} to @file{targetdir}.
6079
6080 @smallexample
6081 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6082 @end smallexample
6083
6084 The @option{-C} option allows to avoid using subshells:
6085
6086 @smallexample
6087 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6088 @end smallexample
6089
6090 In both examples above, the leftmost @command{tar} invocation archives
6091 the contents of @file{sourcedir} to the standard output, while the
6092 rightmost one reads this archive from its standard input and
6093 extracts it. The @option{-p} option tells it to restore permissions
6094 of the extracted files.
6095
6096 @cindex Remote devices
6097 @cindex tar to a remote device
6098 @anchor{remote-dev}
6099 To specify an archive file on a device attached to a remote machine,
6100 use the following:
6101
6102 @smallexample
6103 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6104 @end smallexample
6105
6106 @noindent
6107 @command{tar} will complete the remote connection, if possible, and
6108 prompt you for a username and password. If you use
6109 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6110 will complete the remote connection, if possible, using your username
6111 as the username on the remote machine.
6112
6113 @cindex Local and remote archives
6114 @anchor{local and remote archives}
6115 If the archive file name includes a colon (@samp{:}), then it is assumed
6116 to be a file on another machine. If the archive file is
6117 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6118 host @var{host}. The remote host is accessed using the @command{rsh}
6119 program, with a username of @var{user}. If the username is omitted
6120 (along with the @samp{@@} sign), then your user name will be used.
6121 (This is the normal @command{rsh} behavior.) It is necessary for the
6122 remote machine, in addition to permitting your @command{rsh} access, to
6123 have the @file{rmt} program installed (This command is included in
6124 the @GNUTAR{} distribution and by default is installed under
6125 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6126 installation prefix). If you need to use a file whose name includes a
6127 colon, then the remote tape drive behavior
6128 can be inhibited by using the @option{--force-local} option.
6129
6130 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6131 tries to minimize input and output operations. The Amanda backup
6132 system, when used with @GNUTAR{}, has an initial sizing pass which
6133 uses this feature.
6134
6135 @node Selecting Archive Members
6136 @section Selecting Archive Members
6137 @cindex Specifying files to act on
6138 @cindex Specifying archive members
6139
6140 @dfn{File Name arguments} specify which files in the file system
6141 @command{tar} operates on, when creating or adding to an archive, or which
6142 archive members @command{tar} operates on, when reading or deleting from
6143 an archive. @xref{Operations}.
6144
6145 To specify file names, you can include them as the last arguments on
6146 the command line, as follows:
6147 @smallexample
6148 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6149 @end smallexample
6150
6151 If a file name begins with dash (@samp{-}), precede it with
6152 @option{--add-file} option to prevent it from being treated as an
6153 option.
6154
6155 @anchor{input name quoting}
6156 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6157 name, replacing @dfn{escape sequences} according to the following
6158 table:
6159
6160 @multitable @columnfractions 0.20 0.60
6161 @headitem Escape @tab Replaced with
6162 @item \a @tab Audible bell (ASCII 7)
6163 @item \b @tab Backspace (ASCII 8)
6164 @item \f @tab Form feed (ASCII 12)
6165 @item \n @tab New line (ASCII 10)
6166 @item \r @tab Carriage return (ASCII 13)
6167 @item \t @tab Horizontal tabulation (ASCII 9)
6168 @item \v @tab Vertical tabulation (ASCII 11)
6169 @item \? @tab ASCII 127
6170 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6171 of up to 3 digits)
6172 @end multitable
6173
6174 A backslash followed by any other symbol is retained.
6175
6176 This default behavior is controlled by the following command line
6177 option:
6178
6179 @table @option
6180 @opindex unquote
6181 @item --unquote
6182 Enable unquoting input file or member names (default).
6183
6184 @opindex no-unquote
6185 @item --no-unquote
6186 Disable unquoting input file or member names.
6187 @end table
6188
6189 If you specify a directory name as a file name argument, all the files
6190 in that directory are operated on by @command{tar}.
6191
6192 If you do not specify files, @command{tar} behavior differs depending
6193 on the operation mode as described below:
6194
6195 When @command{tar} is invoked with @option{--create} (@option{-c}),
6196 @command{tar} will stop immediately, reporting the following:
6197
6198 @smallexample
6199 @group
6200 $ @kbd{tar cf a.tar}
6201 tar: Cowardly refusing to create an empty archive
6202 Try `tar --help' or `tar --usage' for more information.
6203 @end group
6204 @end smallexample
6205
6206 If you specify either @option{--list} (@option{-t}) or
6207 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6208 operates on all the archive members in the archive.
6209
6210 If run with @option{--diff} option, tar will compare the archive with
6211 the contents of the current working directory.
6212
6213 If you specify any other operation, @command{tar} does nothing.
6214
6215 By default, @command{tar} takes file names from the command line. However,
6216 there are other ways to specify file or member names, or to modify the
6217 manner in which @command{tar} selects the files or members upon which to
6218 operate. In general, these methods work both for specifying the names
6219 of files and archive members.
6220
6221 @node files
6222 @section Reading Names from a File
6223
6224 @cindex Reading file names from a file
6225 @cindex Lists of file names
6226 @cindex File Name arguments, alternatives
6227 Instead of giving the names of files or archive members on the command
6228 line, you can put the names into a file, and then use the
6229 @option{--files-from=@var{file-of-names}} (@option{-T
6230 @var{file-of-names}}) option to @command{tar}. Give the name of the
6231 file which contains the list of files to include as the argument to
6232 @option{--files-from}. In the list, the file names should be separated by
6233 newlines. You will frequently use this option when you have generated
6234 the list of files to archive with the @command{find} utility.
6235
6236 @table @option
6237 @opindex files-from
6238 @item --files-from=@var{file-name}
6239 @itemx -T @var{file-name}
6240 Get names to extract or create from file @var{file-name}.
6241 @end table
6242
6243 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6244 you specify either @code{--files-from=-} or @code{-T -}), then the file
6245 names are read from standard input.
6246
6247 Unless you are running @command{tar} with @option{--create}, you can not use
6248 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6249 command.
6250
6251 Any number of @option{-T} options can be given in the command line.
6252
6253 The following example shows how to use @command{find} to generate a list of
6254 files smaller than 400K in length and put that list into a file
6255 called @file{small-files}. You can then use the @option{-T} option to
6256 @command{tar} to specify the files from that file, @file{small-files}, to
6257 create the archive @file{little.tgz}. (The @option{-z} option to
6258 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6259 more information.)
6260
6261 @smallexample
6262 $ @kbd{find . -size -400 -print > small-files}
6263 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6264 @end smallexample
6265
6266 @noindent
6267 In the file list given by @option{-T} option, any file name beginning
6268 with @samp{-} character is considered a @command{tar} option and is
6269 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6270 recognized only @option{-C} option in file lists, and only if the
6271 option and its argument occupied two consecutive lines.} For example,
6272 the common use of this feature is to change to another directory by
6273 specifying @option{-C} option:
6274
6275 @smallexample
6276 @group
6277 $ @kbd{cat list}
6278 -C/etc
6279 passwd
6280 hosts
6281 -C/lib
6282 libc.a
6283 $ @kbd{tar -c -f foo.tar --files-from list}
6284 @end group
6285 @end smallexample
6286
6287 @noindent
6288 In this example, @command{tar} will first switch to @file{/etc}
6289 directory and add files @file{passwd} and @file{hosts} to the
6290 archive. Then it will change to @file{/lib} directory and will archive
6291 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6292 contain:
6293
6294 @smallexample
6295 @group
6296 $ @kbd{tar tf foo.tar}
6297 passwd
6298 hosts
6299 libc.a
6300 @end group
6301 @end smallexample
6302
6303 @noindent
6304 @xopindex{directory, using in @option{--files-from} argument}
6305 Notice that the option parsing algorithm used with @option{-T} is
6306 stricter than the one used by shell. Namely, when specifying option
6307 arguments, you should observe the following rules:
6308
6309 @itemize @bullet
6310 @item
6311 When using short (single-letter) option form, its argument must
6312 immediately follow the option letter, without any intervening
6313 whitespace. For example: @code{-Cdir}.
6314
6315 @item
6316 When using long option form, the option argument must be separated
6317 from the option by a single equal sign. No whitespace is allowed on
6318 any side of the equal sign. For example: @code{--directory=dir}.
6319
6320 @item
6321 For both short and long option forms, the option argument can be given
6322 on the next line after the option name, e.g.:
6323
6324 @smallexample
6325 @group
6326 --directory
6327 dir
6328 @end group
6329 @end smallexample
6330
6331 @noindent
6332 and
6333
6334 @smallexample
6335 @group
6336 -C
6337 dir
6338 @end group
6339 @end smallexample
6340 @end itemize
6341
6342 @opindex add-file
6343 If you happen to have a file whose name starts with @samp{-},
6344 precede it with @option{--add-file} option to prevent it from
6345 being recognized as an option. For example: @code{--add-file=--my-file}.
6346
6347 @menu
6348 * nul::
6349 @end menu
6350
6351 @node nul
6352 @subsection @code{NUL} Terminated File Names
6353
6354 @cindex File names, terminated by @code{NUL}
6355 @cindex @code{NUL} terminated file names
6356 The @option{--null} option causes
6357 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6358 to read file names terminated by a @code{NUL} instead of a newline, so
6359 files whose names contain newlines can be archived using
6360 @option{--files-from}.
6361
6362 @table @option
6363 @opindex null
6364 @item --null
6365 Only consider @code{NUL} terminated file names, instead of files that
6366 terminate in a newline.
6367 @end table
6368
6369 The @option{--null} option is just like the one in @acronym{GNU}
6370 @command{xargs} and @command{cpio}, and is useful with the
6371 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6372 @command{tar}, @option{--null} also disables special handling for
6373 file names that begin with dash.
6374
6375 This example shows how to use @command{find} to generate a list of files
6376 larger than 800K in length and put that list into a file called
6377 @file{long-files}. The @option{-print0} option to @command{find} is just
6378 like @option{-print}, except that it separates files with a @code{NUL}
6379 rather than with a newline. You can then run @command{tar} with both the
6380 @option{--null} and @option{-T} options to specify that @command{tar} get the
6381 files from that file, @file{long-files}, to create the archive
6382 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6383 @command{tar} to recognize the @code{NUL} separator between files.
6384
6385 @smallexample
6386 $ @kbd{find . -size +800 -print0 > long-files}
6387 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6388 @end smallexample
6389
6390 @FIXME{say anything else here to conclude the section?}
6391
6392 @node exclude
6393 @section Excluding Some Files
6394 @UNREVISED
6395
6396 @cindex File names, excluding files by
6397 @cindex Excluding files by name and pattern
6398 @cindex Excluding files by file system
6399 To avoid operating on files whose names match a particular pattern,
6400 use the @option{--exclude} or @option{--exclude-from} options.
6401
6402 @table @option
6403 @opindex exclude
6404 @item --exclude=@var{pattern}
6405 Causes @command{tar} to ignore files that match the @var{pattern}.
6406 @end table
6407
6408 @findex exclude
6409 The @option{--exclude=@var{pattern}} option prevents any file or
6410 member whose name matches the shell wildcard (@var{pattern}) from
6411 being operated on.
6412 For example, to create an archive with all the contents of the directory
6413 @file{src} except for files whose names end in @file{.o}, use the
6414 command @samp{tar -cf src.tar --exclude='*.o' src}.
6415
6416 You may give multiple @option{--exclude} options.
6417
6418 @table @option
6419 @opindex exclude-from
6420 @item --exclude-from=@var{file}
6421 @itemx -X @var{file}
6422 Causes @command{tar} to ignore files that match the patterns listed in
6423 @var{file}.
6424 @end table
6425
6426 @findex exclude-from
6427 Use the @option{--exclude-from} option to read a
6428 list of patterns, one per line, from @var{file}; @command{tar} will
6429 ignore files matching those patterns. Thus if @command{tar} is
6430 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6431 single line @file{*.o}, no files whose names end in @file{.o} will be
6432 added to the archive.
6433
6434 @table @option
6435 @opindex exclude-caches
6436 @item --exclude-caches
6437 Causes @command{tar} to ignore directories containing a cache directory tag.
6438 @end table
6439
6440 @findex exclude-caches
6441 When creating an archive, the @option{--exclude-caches} option causes
6442 @command{tar} to exclude all directories that contain a @dfn{cache
6443 directory tag}. A cache directory tag is a short file with the
6444 well-known name @file{CACHEDIR.TAG} and having a standard header
6445 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6446 Various applications write cache directory tags into directories they
6447 use to hold regenerable, non-precious data, so that such data can be
6448 more easily excluded from backups.
6449
6450 @menu
6451 * problems with exclude::
6452 @end menu
6453
6454 @node problems with exclude
6455 @unnumberedsubsec Problems with Using the @code{exclude} Options
6456
6457 @xopindex{exclude, potential problems with}
6458 Some users find @samp{exclude} options confusing. Here are some common
6459 pitfalls:
6460
6461 @itemize @bullet
6462 @item
6463 The main operating mode of @command{tar} does not act on a path name
6464 explicitly listed on the command line if one of its file name
6465 components is excluded. In the example above, if
6466 you create an archive and exclude files that end with @samp{*.o}, but
6467 explicitly name the file @samp{dir.o/foo} after all the options have been
6468 listed, @samp{dir.o/foo} will be excluded from the archive.
6469
6470 @item
6471 You can sometimes confuse the meanings of @option{--exclude} and
6472 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6473 to be excluded are given as a pattern on the command line. Use
6474 @option{--exclude-from} to introduce the name of a file which contains
6475 a list of patterns, one per line; each of these patterns can exclude
6476 zero, one, or many files.
6477
6478 @item
6479 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6480 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6481 like @samp{*}. If you do not do this, the shell might expand the
6482 @samp{*} itself using files at hand, so @command{tar} might receive a
6483 list of files instead of one pattern, or none at all, making the
6484 command somewhat illegal. This might not correspond to what you want.
6485
6486 For example, write:
6487
6488 @smallexample
6489 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6490 @end smallexample
6491
6492 @noindent
6493 rather than:
6494
6495 @smallexample
6496 # @emph{Wrong!}
6497 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6498 @end smallexample
6499
6500 @item
6501 You must use use shell syntax, or globbing, rather than @code{regexp}
6502 syntax, when using exclude options in @command{tar}. If you try to use
6503 @code{regexp} syntax to describe files to be excluded, your command
6504 might fail.
6505
6506 @item
6507 @FIXME{The change in semantics must have occurred before 1.11,
6508 so I doubt if it is worth mentioning at all. Anyway, should at
6509 least specify in which version the semantics changed.}
6510 In earlier versions of @command{tar}, what is now the
6511 @option{--exclude-from} option was called @option{--exclude} instead.
6512 Now, @option{--exclude} applies to patterns listed on the command
6513 line and @option{--exclude-from} applies to patterns listed in a
6514 file.
6515
6516 @end itemize
6517
6518 @node wildcards
6519 @section Wildcards Patterns and Matching
6520
6521 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6522 @samp{*} or @samp{?} for example, are replaced and expanded into all
6523 existing files matching the given pattern. @GNUTAR{} can use wildcard
6524 patterns for matching (or globbing) archive members when extracting
6525 from or listing an archive. Wildcard patterns are also used for
6526 verifying volume labels of @command{tar} archives. This section has the
6527 purpose of explaining wildcard syntax for @command{tar}.
6528
6529 @FIXME{the next few paragraphs need work.}
6530
6531 A @var{pattern} should be written according to shell syntax, using wildcard
6532 characters to effect globbing. Most characters in the pattern stand
6533 for themselves in the matched string, and case is significant: @samp{a}
6534 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6535 pattern matches any single character in the matched string. The character
6536 @samp{*} in the pattern matches zero, one, or more single characters in
6537 the matched string. The character @samp{\} says to take the following
6538 character of the pattern @emph{literally}; it is useful when one needs to
6539 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6540
6541 The character @samp{[}, up to the matching @samp{]}, introduces a character
6542 class. A @dfn{character class} is a list of acceptable characters
6543 for the next single character of the matched string. For example,
6544 @samp{[abcde]} would match any of the first five letters of the alphabet.
6545 Note that within a character class, all of the ``special characters''
6546 listed above other than @samp{\} lose their special meaning; for example,
6547 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6548 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6549 the characters @samp{-} and @samp{]} must either come @emph{first} or
6550 @emph{last} in a character class.)
6551
6552 @cindex Excluding characters from a character class
6553 @cindex Character class, excluding characters from
6554 If the first character of the class after the opening @samp{[}
6555 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6556 Rather than listing character to match, it lists those characters which
6557 are @emph{forbidden} as the next single character of the matched string.
6558
6559 Other characters of the class stand for themselves. The special
6560 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6561 letters, is meant to represent all characters between @var{a} and
6562 @var{e}, inclusive.
6563
6564 @FIXME{need to add a sentence or so here to make this clear for those
6565 who don't have dan around.}
6566
6567 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6568 special for wildcard matches. However, if a pattern completely matches
6569 a directory prefix of a matched string, then it matches the full matched
6570 string: thus, excluding a directory also excludes all the files beneath it.
6571
6572 @menu
6573 * controlling pattern-matching::
6574 @end menu
6575
6576 @node controlling pattern-matching
6577 @unnumberedsubsec Controlling Pattern-Matching
6578
6579 For the purposes of this section, we call @dfn{exclusion members} all
6580 member names obtained while processing @option{--exclude} and
6581 @option{--exclude-from} options, and @dfn{inclusion members} those
6582 member names that were given in the command line or read from the file
6583 specified with @option{--files-from} option.
6584
6585 These two pairs of member lists are used in the following operations:
6586 @option{--diff}, @option{--extract}, @option{--list},
6587 @option{--update}.
6588
6589 There are no inclusion members in create mode (@option{--create} and
6590 @option{--append}), since in this mode the names obtained from the
6591 command line refer to @emph{files}, not archive members.
6592
6593 By default, inclusion members are compared with archive members
6594 literally @footnote{Notice that earlier @GNUTAR{} versions used
6595 globbing for inclusion members, which contradicted to UNIX98
6596 specification and was not documented. @xref{Changes}, for more
6597 information on this and other changes.} and exclusion members are
6598 treated as globbing patterns. For example:
6599
6600 @smallexample
6601 @group
6602 $ @kbd{tar tf foo.tar}
6603 a.c
6604 b.c
6605 a.txt
6606 [remarks]
6607 # @i{Member names are used verbatim:}
6608 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6609 [remarks]
6610 # @i{Exclude member names are globbed:}
6611 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6612 a.txt
6613 [remarks]
6614 @end group
6615 @end smallexample
6616
6617 This behavior can be altered by using the following options:
6618
6619 @table @option
6620 @opindex wildcards
6621 @item --wildcards
6622 Treat all member names as wildcards.
6623
6624 @opindex no-wildcards
6625 @item --no-wildcards
6626 Treat all member names as literal strings.
6627 @end table
6628
6629 Thus, to extract files whose names end in @samp{.c}, you can use:
6630
6631 @smallexample
6632 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6633 a.c
6634 b.c
6635 @end smallexample
6636
6637 @noindent
6638 Notice quoting of the pattern to prevent the shell from interpreting
6639 it.
6640
6641 The effect of @option{--wildcards} option is cancelled by
6642 @option{--no-wildcards}. This can be used to pass part of
6643 the command line arguments verbatim and other part as globbing
6644 patterns. For example, the following invocation:
6645
6646 @smallexample
6647 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6648 @end smallexample
6649
6650 @noindent
6651 instructs @command{tar} to extract from @file{foo.tar} all files whose
6652 names end in @samp{.txt} and the file named @file{[remarks]}.
6653
6654 Normally, a pattern matches a name if an initial subsequence of the
6655 name's components matches the pattern, where @samp{*}, @samp{?}, and
6656 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6657 and wildcards can match @samp{/}.
6658
6659 Other than optionally stripping leading @samp{/} from names
6660 (@pxref{absolute}), patterns and names are used as-is. For
6661 example, trailing @samp{/} is not trimmed from a user-specified name
6662 before deciding whether to exclude it.
6663
6664 However, this matching procedure can be altered by the options listed
6665 below. These options accumulate. For example:
6666
6667 @smallexample
6668 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6669 @end smallexample
6670
6671 @noindent
6672 ignores case when excluding @samp{makefile}, but not when excluding
6673 @samp{readme}.
6674
6675 @table @option
6676 @opindex anchored
6677 @opindex no-anchored
6678 @item --anchored
6679 @itemx --no-anchored
6680 If anchored, a pattern must match an initial subsequence
6681 of the name's components. Otherwise, the pattern can match any
6682 subsequence. Default is @option{--no-anchored} for exclusion members
6683 and @option{--anchored} inclusion members.
6684
6685 @opindex ignore-case
6686 @opindex no-ignore-case
6687 @item --ignore-case
6688 @itemx --no-ignore-case
6689 When ignoring case, upper-case patterns match lower-case names and vice versa.
6690 When not ignoring case (the default), matching is case-sensitive.
6691
6692 @opindex wildcards-match-slash
6693 @opindex no-wildcards-match-slash
6694 @item --wildcards-match-slash
6695 @itemx --no-wildcards-match-slash
6696 When wildcards match slash (the default for exclusion members), a
6697 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6698 name. Otherwise, @samp{/} is matched only by @samp{/}.
6699
6700 @end table
6701
6702 The @option{--recursion} and @option{--no-recursion} options
6703 (@pxref{recurse}) also affect how member patterns are interpreted. If
6704 recursion is in effect, a pattern matches a name if it matches any of
6705 the name's parent directories.
6706
6707 The following table summarizes pattern-matching default values:
6708
6709 @multitable @columnfractions .3 .7
6710 @headitem Members @tab Default settings
6711 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6712 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6713 @end multitable
6714
6715 @node quoting styles
6716 @section Quoting Member Names
6717
6718 When displaying member names, @command{tar} takes care to avoid
6719 ambiguities caused by certain characters. This is called @dfn{name
6720 quoting}. The characters in question are:
6721
6722 @itemize @bullet
6723 @item Non-printable control characters:
6724
6725 @multitable @columnfractions 0.20 0.10 0.60
6726 @headitem Character @tab ASCII @tab Character name
6727 @item \a @tab 7 @tab Audible bell
6728 @item \b @tab 8 @tab Backspace
6729 @item \f @tab 12 @tab Form feed
6730 @item \n @tab 10 @tab New line
6731 @item \r @tab 13 @tab Carriage return
6732 @item \t @tab 9 @tab Horizontal tabulation
6733 @item \v @tab 11 @tab Vertical tabulation
6734 @end multitable
6735
6736 @item Space (ASCII 32)
6737
6738 @item Single and double quotes (@samp{'} and @samp{"})
6739
6740 @item Backslash (@samp{\})
6741 @end itemize
6742
6743 The exact way @command{tar} uses to quote these characters depends on
6744 the @dfn{quoting style}. The default quoting style, called
6745 @dfn{escape} (see below), uses backslash notation to represent control
6746 characters, space and backslash. Using this quoting style, control
6747 characters are represented as listed in column @samp{Character} in the
6748 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6749
6750 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6751 using @option{--quoting-style} option:
6752
6753 @table @option
6754 @item --quoting-style=@var{style}
6755 @opindex quoting-style
6756
6757 Sets quoting style. Valid values for @var{style} argument are:
6758 literal, shell, shell-always, c, escape, locale, clocale.
6759 @end table
6760
6761 These styles are described in detail below. To illustrate their
6762 effect, we will use an imaginary tar archive @file{arch.tar}
6763 containing the following members:
6764
6765 @smallexample
6766 @group
6767 # 1. Contains horizontal tabulation character.
6768 a tab
6769 # 2. Contains newline character
6770 a
6771 newline
6772 # 3. Contains a space
6773 a space
6774 # 4. Contains double quotes
6775 a"double"quote
6776 # 5. Contains single quotes
6777 a'single'quote
6778 # 6. Contains a backslash character:
6779 a\backslash
6780 @end group
6781 @end smallexample
6782
6783 Here is how usual @command{ls} command would have listed them, if they
6784 had existed in the current working directory:
6785
6786 @smallexample
6787 @group
6788 $ @kbd{ls}
6789 a\ttab
6790 a\nnewline
6791 a\ space
6792 a"double"quote
6793 a'single'quote
6794 a\\backslash
6795 @end group
6796 @end smallexample
6797
6798 Quoting styles:
6799
6800 @table @samp
6801 @item literal
6802 No quoting, display each character as is:
6803
6804 @smallexample
6805 @group
6806 $ @kbd{tar tf arch.tar --quoting-style=literal}
6807 ./
6808 ./a space
6809 ./a'single'quote
6810 ./a"double"quote
6811 ./a\backslash
6812 ./a tab
6813 ./a
6814 newline
6815 @end group
6816 @end smallexample
6817
6818 @item shell
6819 Display characters the same way Bourne shell does:
6820 control characters, except @samp{\t} and @samp{\n}, are printed using
6821 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6822 single quote is printed as @samp{\'}. If a name contains any quoted
6823 characters, it is enclosed in single quotes. In particular, if a name
6824 contains single quotes, it is printed as several single-quoted strings:
6825
6826 @smallexample
6827 @group
6828 $ @kbd{tar tf arch.tar --quoting-style=shell}
6829 ./
6830 './a space'
6831 './a'\''single'\''quote'
6832 './a"double"quote'
6833 './a\backslash'
6834 './a tab'
6835 './a
6836 newline'
6837 @end group
6838 @end smallexample
6839
6840 @item shell-always
6841 Same as @samp{shell}, but the names are always enclosed in single
6842 quotes:
6843
6844 @smallexample
6845 @group
6846 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6847 './'
6848 './a space'
6849 './a'\''single'\''quote'
6850 './a"double"quote'
6851 './a\backslash'
6852 './a tab'
6853 './a
6854 newline'
6855 @end group
6856 @end smallexample
6857
6858 @item c
6859 Use the notation of the C programming language. All names are
6860 enclosed in double quotes. Control characters are quoted using
6861 backslash notations, double quotes are represented as @samp{\"},
6862 backslash characters are represented as @samp{\\}. Single quotes and
6863 spaces are not quoted:
6864
6865 @smallexample
6866 @group
6867 $ @kbd{tar tf arch.tar --quoting-style=c}
6868 "./"
6869 "./a space"
6870 "./a'single'quote"
6871 "./a\"double\"quote"
6872 "./a\\backslash"
6873 "./a\ttab"
6874 "./a\nnewline"
6875 @end group
6876 @end smallexample
6877
6878 @item escape
6879 Control characters are printed using backslash notation, a space is
6880 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6881 default quoting style, unless it was changed when configured the
6882 package.
6883
6884 @smallexample
6885 @group
6886 $ @kbd{tar tf arch.tar --quoting-style=escape}
6887 ./
6888 ./a space
6889 ./a'single'quote
6890 ./a"double"quote
6891 ./a\\backslash
6892 ./a\ttab
6893 ./a\nnewline
6894 @end group
6895 @end smallexample
6896
6897 @item locale
6898 Control characters, single quote and backslash are printed using
6899 backslash notation. All names are quoted using left and right
6900 quotation marks, appropriate to the current locale. If it does not
6901 define quotation marks, use @samp{`} as left and @samp{'} as right
6902 quotation marks. Any occurrences of the right quotation mark in a
6903 name are escaped with @samp{\}, for example:
6904
6905 For example:
6906
6907 @smallexample
6908 @group
6909 $ @kbd{tar tf arch.tar --quoting-style=locale}
6910 `./'
6911 `./a space'
6912 `./a\'single\'quote'
6913 `./a"double"quote'
6914 `./a\\backslash'
6915 `./a\ttab'
6916 `./a\nnewline'
6917 @end group
6918 @end smallexample
6919
6920 @item clocale
6921 Same as @samp{locale}, but @samp{"} is used for both left and right
6922 quotation marks, if not provided by the currently selected locale:
6923
6924 @smallexample
6925 @group
6926 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6927 "./"
6928 "./a space"
6929 "./a'single'quote"
6930 "./a\"double\"quote"
6931 "./a\\backslash"
6932 "./a\ttab"
6933 "./a\nnewline"
6934 @end group
6935 @end smallexample
6936 @end table
6937
6938 You can specify which characters should be quoted in addition to those
6939 implied by the current quoting style:
6940
6941 @table @option
6942 @item --quote-chars=@var{string}
6943 Always quote characters from @var{string}, even if the selected
6944 quoting style would not quote them.
6945 @end table
6946
6947 For example, using @samp{escape} quoting (compare with the usual
6948 escape listing above):
6949
6950 @smallexample
6951 @group
6952 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6953 ./
6954 ./a\ space
6955 ./a'single'quote
6956 ./a\"double\"quote
6957 ./a\\backslash
6958 ./a\ttab
6959 ./a\nnewline
6960 @end group
6961 @end smallexample
6962
6963 To disable quoting of such additional characters, use the following
6964 option:
6965
6966 @table @option
6967 @item --no-quote-chars=@var{string}
6968 Remove characters listed in @var{string} from the list of quoted
6969 characters set by the previous @option{--quote-chars} option.
6970 @end table
6971
6972 This option is particularly useful if you have added
6973 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6974 and wish to disable it for the current invocation.
6975
6976 Note, that @option{--no-quote-chars} does @emph{not} disable those
6977 characters that are quoted by default in the selected quoting style.
6978
6979 @node transform
6980 @section Modifying File and Member Names
6981
6982 @command{Tar} archives contain detailed information about files stored
6983 in them and full file names are part of that information. When
6984 storing file to an archive, its file name is recorded in the archive
6985 along with the actual file contents. When restoring from an archive,
6986 a file is created on disk with exactly the same name as that stored
6987 in the archive. In the majority of cases this is the desired behavior
6988 of a file archiver. However, there are some cases when it is not.
6989
6990 First of all, it is often unsafe to extract archive members with
6991 absolute file names or those that begin with a @file{../}. @GNUTAR{}
6992 takes special precautions when extracting such names and provides a
6993 special option for handling them, which is described in
6994 @ref{absolute}.
6995
6996 Secondly, you may wish to extract file names without some leading
6997 directory components, or with otherwise modified names. In other
6998 cases it is desirable to store files under differing names in the
6999 archive.
7000
7001 @GNUTAR{} provides two options for these needs.
7002
7003 @table @option
7004 @opindex strip-components
7005 @item --strip-components=@var{number}
7006 Strip given @var{number} of leading components from file names before
7007 extraction.
7008 @end table
7009
7010 For example, suppose you have archived whole @file{/usr} hierarchy to
7011 a tar archive named @file{usr.tar}. Among other files, this archive
7012 contains @file{usr/include/stdlib.h}, which you wish to extract to
7013 the current working directory. To do so, you type:
7014
7015 @smallexample
7016 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7017 @end smallexample
7018
7019 The option @option{--strip=2} instructs @command{tar} to strip the
7020 two leading components (@file{usr/} and @file{include/}) off the file
7021 name.
7022
7023 If you add to the above invocation @option{--verbose} (@option{-v})
7024 option, you will note that the verbose listing still contains the
7025 full file name, with the two removed components still in place. This
7026 can be inconvenient, so @command{tar} provides a special option for
7027 altering this behavior:
7028
7029 @anchor{show-transformed-names}
7030 @table @option
7031 @opindex show-transformed-names
7032 @item --show-transformed-names
7033 Display file or member names with all requested transformations
7034 applied.
7035 @end table
7036
7037 @noindent
7038 For example:
7039
7040 @smallexample
7041 @group
7042 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7043 usr/include/stdlib.h
7044 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7045 stdlib.h
7046 @end group
7047 @end smallexample
7048
7049 Notice that in both cases the file is @file{stdlib.h} extracted to the
7050 current working directory, @option{--show-transformed-names} affects
7051 only the way its name is displayed.
7052
7053 This option is especially useful for verifying whether the invocation
7054 will have the desired effect. Thus, before running
7055
7056 @smallexample
7057 $ @kbd{tar -x --strip=@var{n}}
7058 @end smallexample
7059
7060 @noindent
7061 it is often advisable to run
7062
7063 @smallexample
7064 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7065 @end smallexample
7066
7067 @noindent
7068 to make sure the command will produce the intended results.
7069
7070 In case you need to apply more complex modifications to the file name,
7071 @GNUTAR{} provides a general-purpose transformation option:
7072
7073 @table @option
7074 @opindex transform
7075 @item --transform=@var{expression}
7076 Modify file names using supplied @var{expression}.
7077 @end table
7078
7079 @noindent
7080 The @var{expression} is a @command{sed}-like replace expression of the
7081 form:
7082
7083 @smallexample
7084 s/@var{regexp}/@var{replace}/[@var{flags}]
7085 @end smallexample
7086
7087 @noindent
7088 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7089 replacement for each file name part that matches @var{regexp}. Both
7090 @var{regexp} and @var{replace} are described in detail in
7091 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7092
7093 Supported @var{flags} are:
7094
7095 @table @samp
7096 @item g
7097 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7098 just the first.
7099
7100 @item i
7101 Use case-insensitive matching
7102
7103 @item x
7104 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7105 regexps, Extended regular expressions, Extended regular expressions,
7106 sed, GNU sed}).
7107
7108 @item @var{number}
7109 Only replace the @var{number}th match of the @var{regexp}.
7110
7111 Note: the @var{posix} standard does not specify what should happen
7112 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7113 follows the GNU @command{sed} implementation in this regard, so
7114 the the interaction is defined to be: ignore matches before the
7115 @var{number}th, and then match and replace all matches from the
7116 @var{number}th on.
7117
7118 @end table
7119
7120 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7121 that it be used consistently throughout the expression. For example,
7122 the following two expressions are equivalent:
7123
7124 @smallexample
7125 @group
7126 s/one/two/
7127 s,one,two,
7128 @end group
7129 @end smallexample
7130
7131 Changing delimiters is often useful when the @var{regex} contains
7132 slashes. For example, it is more convenient to write @code{s,/,-,} than
7133 @code{s/\//-/}.
7134
7135 Here are several examples of @option{--transform} usage:
7136
7137 @enumerate
7138 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7139
7140 @smallexample
7141 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7142 @end smallexample
7143
7144 @item Strip two leading directory components (equivalent to
7145 @option{--strip-components=2}):
7146
7147 @smallexample
7148 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7149 @end smallexample
7150
7151 @item Prepend @file{/prefix/} to each file name:
7152
7153 @smallexample
7154 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7155 @end smallexample
7156
7157 @item Convert each file name to lower case:
7158
7159 @smallexample
7160 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7161 @end smallexample
7162
7163 @end enumerate
7164
7165 Unlike @option{--strip-components}, @option{--transform} can be used
7166 in any @GNUTAR{} operation mode. For example, the following command
7167 adds files to the archive while replacing the leading @file{usr/}
7168 component with @file{var/}:
7169
7170 @smallexample
7171 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7172 @end smallexample
7173
7174 To test @option{--transform} effect we suggest using
7175 @option{--show-transformed-names} option:
7176
7177 @smallexample
7178 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7179 --verbose --show-transformed-names /}
7180 @end smallexample
7181
7182 If both @option{--strip-components} and @option{--transform} are used
7183 together, then @option{--transform} is applied first, and the required
7184 number of components is then stripped from its result.
7185
7186 @node after
7187 @section Operating Only on New Files
7188 @UNREVISED
7189
7190 @cindex Excluding file by age
7191 @cindex Data Modification time, excluding files by
7192 @cindex Modification time, excluding files by
7193 @cindex Age, excluding files by
7194 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7195 @option{-N @var{date}}) option causes @command{tar} to only work on
7196 files whose data modification or status change times are newer than
7197 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7198 it is taken to be a file name; the data modification time of that file
7199 is used as the date. If you use this option when creating or appending
7200 to an archive, the archive will only include new files. If you use
7201 @option{--after-date} when extracting an archive, @command{tar} will
7202 only extract files newer than the @var{date} you specify.
7203
7204 If you only want @command{tar} to make the date comparison based on
7205 modification of the file's data (rather than status
7206 changes), then use the @option{--newer-mtime=@var{date}} option.
7207
7208 You may use these options with any operation. Note that these options
7209 differ from the @option{--update} (@option{-u}) operation in that they
7210 allow you to specify a particular date against which @command{tar} can
7211 compare when deciding whether or not to archive the files.
7212
7213 @table @option
7214 @opindex after-date
7215 @opindex newer
7216 @item --after-date=@var{date}
7217 @itemx --newer=@var{date}
7218 @itemx -N @var{date}
7219 Only store files newer than @var{date}.
7220
7221 Acts on files only if their data modification or status change times are
7222 later than @var{date}. Use in conjunction with any operation.
7223
7224 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7225 name; the data modification time of that file is used as the date.
7226
7227 @opindex newer-mtime
7228 @item --newer-mtime=@var{date}
7229 Acts like @option{--after-date}, but only looks at data modification times.
7230 @end table
7231
7232 These options limit @command{tar} to operate only on files which have
7233 been modified after the date specified. A file's status is considered to have
7234 changed if its contents have been modified, or if its owner,
7235 permissions, and so forth, have been changed. (For more information on
7236 how to specify a date, see @ref{Date input formats}; remember that the
7237 entire date argument must be quoted if it contains any spaces.)
7238
7239 Gurus would say that @option{--after-date} tests both the data
7240 modification time (@code{mtime}, the time the contents of the file
7241 were last modified) and the status change time (@code{ctime}, the time
7242 the file's status was last changed: owner, permissions, etc.@:)
7243 fields, while @option{--newer-mtime} tests only the @code{mtime}
7244 field.
7245
7246 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7247 @code{ctime} and processes the file if either one is more recent than
7248 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7249 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7250 contents of the file were looked at).
7251
7252 Date specifiers can have embedded spaces. Because of this, you may need
7253 to quote date arguments to keep the shell from parsing them as separate
7254 arguments. For example, the following command will add to the archive
7255 all the files modified less than two days ago:
7256
7257 @smallexample
7258 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7259 @end smallexample
7260
7261 When any of these options is used with the option @option{--verbose}
7262 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7263 date back to its textual representation and compare that with the
7264 one given with the option. If the two dates differ, @command{tar} will
7265 print a warning saying what date it will use. This is to help user
7266 ensure he is using the right date. For example:
7267
7268 @smallexample
7269 @group
7270 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7271 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7272 13:19:37.232434
7273 @end group
7274 @end smallexample
7275
7276 @quotation
7277 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7278 should not be used for incremental backups. @xref{Incremental Dumps},
7279 for proper way of creating incremental backups.
7280 @end quotation
7281
7282 @node recurse
7283 @section Descending into Directories
7284 @UNREVISED
7285 @cindex Avoiding recursion in directories
7286 @cindex Descending directories, avoiding
7287 @cindex Directories, avoiding recursion
7288 @cindex Recursion in directories, avoiding
7289
7290 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7291
7292 Usually, @command{tar} will recursively explore all directories (either
7293 those given on the command line or through the @option{--files-from}
7294 option) for the various files they contain. However, you may not always
7295 want @command{tar} to act this way.
7296
7297 @opindex no-recursion
7298 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7299 into specified directories. If you specify @option{--no-recursion}, you can
7300 use the @command{find} utility for hunting through levels of directories to
7301 construct a list of file names which you could then pass to @command{tar}.
7302 @command{find} allows you to be more selective when choosing which files to
7303 archive; see @ref{files}, for more information on using @command{find} with
7304 @command{tar}, or look.
7305
7306 @table @option
7307 @item --no-recursion
7308 Prevents @command{tar} from recursively descending directories.
7309
7310 @opindex recursion
7311 @item --recursion
7312 Requires @command{tar} to recursively descend directories.
7313 This is the default.
7314 @end table
7315
7316 When you use @option{--no-recursion}, @GNUTAR{} grabs
7317 directory entries themselves, but does not descend on them
7318 recursively. Many people use @command{find} for locating files they
7319 want to back up, and since @command{tar} @emph{usually} recursively
7320 descends on directories, they have to use the @samp{@w{-not -type d}}
7321 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7322 find, Finding Files}), as they usually do not want all the files in a
7323 directory. They then use the @option{--files-from} option to archive
7324 the files located via @command{find}.
7325
7326 The problem when restoring files archived in this manner is that the
7327 directories themselves are not in the archive; so the
7328 @option{--same-permissions} (@option{--preserve-permissions},
7329 @option{-p}) option does not affect them---while users might really
7330 like it to. Specifying @option{--no-recursion} is a way to tell
7331 @command{tar} to grab only the directory entries given to it, adding
7332 no new files on its own. To summarize, if you use @command{find} to
7333 create a list of files to be stored in an archive, use it as follows:
7334
7335 @smallexample
7336 @group
7337 $ @kbd{find @var{dir} @var{tests} | \
7338 tar -cf @var{archive} -T - --no-recursion}
7339 @end group
7340 @end smallexample
7341
7342 The @option{--no-recursion} option also applies when extracting: it
7343 causes @command{tar} to extract only the matched directory entries, not
7344 the files under those directories.
7345
7346 The @option{--no-recursion} option also affects how globbing patterns
7347 are interpreted (@pxref{controlling pattern-matching}).
7348
7349 The @option{--no-recursion} and @option{--recursion} options apply to
7350 later options and operands, and can be overridden by later occurrences
7351 of @option{--no-recursion} and @option{--recursion}. For example:
7352
7353 @smallexample
7354 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7355 @end smallexample
7356
7357 @noindent
7358 creates an archive with one entry for @file{grape}, and the recursive
7359 contents of @file{grape/concord}, but no entries under @file{grape}
7360 other than @file{grape/concord}.
7361
7362 @node one
7363 @section Crossing File System Boundaries
7364 @cindex File system boundaries, not crossing
7365 @UNREVISED
7366
7367 @command{tar} will normally automatically cross file system boundaries in
7368 order to archive files which are part of a directory tree. You can
7369 change this behavior by running @command{tar} and specifying
7370 @option{--one-file-system}. This option only affects files that are
7371 archived because they are in a directory that is being archived;
7372 @command{tar} will still archive files explicitly named on the command line
7373 or through @option{--files-from}, regardless of where they reside.
7374
7375 @table @option
7376 @opindex one-file-system
7377 @item --one-file-system
7378 Prevents @command{tar} from crossing file system boundaries when
7379 archiving. Use in conjunction with any write operation.
7380 @end table
7381
7382 The @option{--one-file-system} option causes @command{tar} to modify its
7383 normal behavior in archiving the contents of directories. If a file in
7384 a directory is not on the same file system as the directory itself, then
7385 @command{tar} will not archive that file. If the file is a directory
7386 itself, @command{tar} will not archive anything beneath it; in other words,
7387 @command{tar} will not cross mount points.
7388
7389 This option is useful for making full or incremental archival backups of
7390 a file system. If this option is used in conjunction with
7391 @option{--verbose} (@option{-v}), files that are excluded are
7392 mentioned by name on the standard error.
7393
7394 @menu
7395 * directory:: Changing Directory
7396 * absolute:: Absolute File Names
7397 @end menu
7398
7399 @node directory
7400 @subsection Changing the Working Directory
7401 @UNREVISED
7402
7403 @FIXME{need to read over this node now for continuity; i've switched
7404 things around some.}
7405
7406 @cindex Changing directory mid-stream
7407 @cindex Directory, changing mid-stream
7408 @cindex Working directory, specifying
7409 To change the working directory in the middle of a list of file names,
7410 either on the command line or in a file specified using
7411 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7412 This will change the working directory to the specified directory
7413 after that point in the list.
7414
7415 @table @option
7416 @opindex directory
7417 @item --directory=@var{directory}
7418 @itemx -C @var{directory}
7419 Changes the working directory in the middle of a command line.
7420 @end table
7421
7422 For example,
7423
7424 @smallexample
7425 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7426 @end smallexample
7427
7428 @noindent
7429 will place the files @file{grape} and @file{prune} from the current
7430 directory into the archive @file{jams.tar}, followed by the file
7431 @file{cherry} from the directory @file{food}. This option is especially
7432 useful when you have several widely separated files that you want to
7433 store in the same archive.
7434
7435 Note that the file @file{cherry} is recorded in the archive under the
7436 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7437 archive will contain three files that all appear to have come from the
7438 same directory; if the archive is extracted with plain @samp{tar
7439 --extract}, all three files will be written in the current directory.
7440
7441 Contrast this with the command,
7442
7443 @smallexample
7444 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7445 @end smallexample
7446
7447 @noindent
7448 which records the third file in the archive under the name
7449 @file{red/cherry} so that, if the archive is extracted using
7450 @samp{tar --extract}, the third file will be written in a subdirectory
7451 named @file{orange-colored}.
7452
7453 You can use the @option{--directory} option to make the archive
7454 independent of the original name of the directory holding the files.
7455 The following command places the files @file{/etc/passwd},
7456 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7457 @file{foo.tar}:
7458
7459 @smallexample
7460 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7461 @end smallexample
7462
7463 @noindent
7464 However, the names of the archive members will be exactly what they were
7465 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7466 They will not appear to be related by file name to the original
7467 directories where those files were located.
7468
7469 Note that @option{--directory} options are interpreted consecutively. If
7470 @option{--directory} specifies a relative file name, it is interpreted
7471 relative to the then current directory, which might not be the same as
7472 the original current working directory of @command{tar}, due to a previous
7473 @option{--directory} option.
7474
7475 When using @option{--files-from} (@pxref{files}), you can put various
7476 @command{tar} options (including @option{-C}) in the file list. Notice,
7477 however, that in this case the option and its argument may not be
7478 separated by whitespace. If you use short option, its argument must
7479 either follow the option letter immediately, without any intervening
7480 whitespace, or occupy the next line. Otherwise, if you use long
7481 option, separate its argument by an equal sign.
7482
7483 For instance, the file list for the above example will be:
7484
7485 @smallexample
7486 @group
7487 -C
7488 /etc
7489 passwd
7490 hosts
7491 -C
7492 /lib
7493 libc.a
7494 @end group
7495 @end smallexample
7496
7497 @noindent
7498 To use it, you would invoke @command{tar} as follows:
7499
7500 @smallexample
7501 $ @kbd{tar -c -f foo.tar --files-from list}
7502 @end smallexample
7503
7504 Notice also that you can only use the short option variant in the file
7505 list, i.e., always use @option{-C}, not @option{--directory}.
7506
7507 The interpretation of @option{--directory} is disabled by
7508 @option{--null} option.
7509
7510 @node absolute
7511 @subsection Absolute File Names
7512 @UNREVISED
7513
7514 @table @option
7515 @opindex absolute-names
7516 @item --absolute-names
7517 @itemx -P
7518 Do not strip leading slashes from file names, and permit file names
7519 containing a @file{..} file name component.
7520 @end table
7521
7522 By default, @GNUTAR{} drops a leading @samp{/} on
7523 input or output, and complains about file names containing a @file{..}
7524 component. This option turns off this behavior.
7525
7526 When @command{tar} extracts archive members from an archive, it strips any
7527 leading slashes (@samp{/}) from the member name. This causes absolute
7528 member names in the archive to be treated as relative file names. This
7529 allows you to have such members extracted wherever you want, instead of
7530 being restricted to extracting the member in the exact directory named
7531 in the archive. For example, if the archive member has the name
7532 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7533 really @file{etc/passwd}.
7534
7535 File names containing @file{..} can cause problems when extracting, so
7536 @command{tar} normally warns you about such files when creating an
7537 archive, and rejects attempts to extracts such files.
7538
7539 Other @command{tar} programs do not do this. As a result, if you
7540 create an archive whose member names start with a slash, they will be
7541 difficult for other people with a non-@GNUTAR{}
7542 program to use. Therefore, @GNUTAR{} also strips
7543 leading slashes from member names when putting members into the
7544 archive. For example, if you ask @command{tar} to add the file
7545 @file{/bin/ls} to an archive, it will do so, but the member name will
7546 be @file{bin/ls}.@footnote{A side effect of this is that when
7547 @option{--create} is used with @option{--verbose} the resulting output
7548 is not, generally speaking, the same as the one you'd get running
7549 @kbd{tar --list} command. This may be important if you use some
7550 scripts for comparing both outputs. @xref{listing member and file names},
7551 for the information on how to handle this case.}
7552
7553 If you use the @option{--absolute-names} (@option{-P}) option,
7554 @command{tar} will do none of these transformations.
7555
7556 To archive or extract files relative to the root directory, specify
7557 the @option{--absolute-names} (@option{-P}) option.
7558
7559 Normally, @command{tar} acts on files relative to the working
7560 directory---ignoring superior directory names when archiving, and
7561 ignoring leading slashes when extracting.
7562
7563 When you specify @option{--absolute-names} (@option{-P}),
7564 @command{tar} stores file names including all superior directory
7565 names, and preserves leading slashes. If you only invoked
7566 @command{tar} from the root directory you would never need the
7567 @option{--absolute-names} option, but using this option
7568 may be more convenient than switching to root.
7569
7570 @FIXME{Should be an example in the tutorial/wizardry section using this
7571 to transfer files between systems.}
7572
7573 @FIXME{Is write access an issue?}
7574
7575 @table @option
7576 @item --absolute-names
7577 Preserves full file names (including superior directory names) when
7578 archiving files. Preserves leading slash when extracting files.
7579
7580 @end table
7581
7582 @FIXME{this is still horrible; need to talk with dan on monday.}
7583
7584 @command{tar} prints out a message about removing the @samp{/} from
7585 file names. This message appears once per @GNUTAR{}
7586 invocation. It represents something which ought to be told; ignoring
7587 what it means can cause very serious surprises, later.
7588
7589 Some people, nevertheless, do not want to see this message. Wanting to
7590 play really dangerously, one may of course redirect @command{tar} standard
7591 error to the sink. For example, under @command{sh}:
7592
7593 @smallexample
7594 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7595 @end smallexample
7596
7597 @noindent
7598 Another solution, both nicer and simpler, would be to change to
7599 the @file{/} directory first, and then avoid absolute notation.
7600 For example:
7601
7602 @smallexample
7603 $ @kbd{(cd / && tar -c -f archive.tar home)}
7604 # @i{or}:
7605 $ @kbd{tar -c -f archive.tar -C / home}
7606 @end smallexample
7607
7608 @include getdate.texi
7609
7610 @node Formats
7611 @chapter Controlling the Archive Format
7612
7613 @cindex Tar archive formats
7614 Due to historical reasons, there are several formats of tar archives.
7615 All of them are based on the same principles, but have some subtle
7616 differences that often make them incompatible with each other.
7617
7618 GNU tar is able to create and handle archives in a variety of formats.
7619 The most frequently used formats are (in alphabetical order):
7620
7621 @table @asis
7622 @item gnu
7623 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7624 from an early @acronym{POSIX} standard, adding some improvements such as
7625 sparse file handling and incremental archives. Unfortunately these
7626 features were implemented in a way incompatible with other archive
7627 formats.
7628
7629 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7630 length.
7631
7632 @item oldgnu
7633 Format used by @GNUTAR{} of versions prior to 1.12.
7634
7635 @item v7
7636 Archive format, compatible with the V7 implementation of tar. This
7637 format imposes a number of limitations. The most important of them
7638 are:
7639
7640 @enumerate
7641 @item The maximum length of a file name is limited to 99 characters.
7642 @item The maximum length of a symbolic link is limited to 99 characters.
7643 @item It is impossible to store special files (block and character
7644 devices, fifos etc.)
7645 @item Maximum value of user or group ID is limited to 2097151 (7777777
7646 octal)
7647 @item V7 archives do not contain symbolic ownership information (user
7648 and group name of the file owner).
7649 @end enumerate
7650
7651 This format has traditionally been used by Automake when producing
7652 Makefiles. This practice will change in the future, in the meantime,
7653 however this means that projects containing filenames more than 99
7654 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7655 Automake prior to 1.9.
7656
7657 @item ustar
7658 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7659 symbolic ownership information. It is also able to store
7660 special files. However, it imposes several restrictions as well:
7661
7662 @enumerate
7663 @item The maximum length of a file name is limited to 256 characters,
7664 provided that the filename can be split at directory separator in
7665 two parts, first of them being at most 155 bytes long. So, in most
7666 cases the maximum file name length will be shorter than 256
7667 characters.
7668 @item The maximum length of a symbolic link name is limited to
7669 100 characters.
7670 @item Maximum size of a file the archive is able to accomodate
7671 is 8GB
7672 @item Maximum value of UID/GID is 2097151.
7673 @item Maximum number of bits in device major and minor numbers is 21.
7674 @end enumerate
7675
7676 @item star
7677 Format used by J@"org Schilling @command{star}
7678 implementation. @GNUTAR{} is able to read @samp{star} archives but
7679 currently does not produce them.
7680
7681 @item posix
7682 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7683 most flexible and feature-rich format. It does not impose any
7684 restrictions on file sizes or filename lengths. This format is quite
7685 recent, so not all tar implementations are able to handle it properly.
7686 However, this format is designed in such a way that any tar
7687 implementation able to read @samp{ustar} archives will be able to read
7688 most @samp{posix} archives as well, with the only exception that any
7689 additional information (such as long file names etc.) will in such
7690 case be extracted as plain text files along with the files it refers to.
7691
7692 This archive format will be the default format for future versions
7693 of @GNUTAR{}.
7694
7695 @end table
7696
7697 The following table summarizes the limitations of each of these
7698 formats:
7699
7700 @multitable @columnfractions .10 .20 .20 .20 .20
7701 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7702 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7703 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7704 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7705 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7706 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7707 @end multitable
7708
7709 The default format for @GNUTAR{} is defined at compilation
7710 time. You may check it by running @command{tar --help}, and examining
7711 the last lines of its output. Usually, @GNUTAR{} is configured
7712 to create archives in @samp{gnu} format, however, future version will
7713 switch to @samp{posix}.
7714
7715 @menu
7716 * Portability:: Making @command{tar} Archives More Portable
7717 * Compression:: Using Less Space through Compression
7718 * Attributes:: Handling File Attributes
7719 * cpio:: Comparison of @command{tar} and @command{cpio}
7720 @end menu
7721
7722 @node Portability
7723 @section Making @command{tar} Archives More Portable
7724
7725 Creating a @command{tar} archive on a particular system that is meant to be
7726 useful later on many other machines and with other versions of @command{tar}
7727 is more challenging than you might think. @command{tar} archive formats
7728 have been evolving since the first versions of Unix. Many such formats
7729 are around, and are not always compatible with each other. This section
7730 discusses a few problems, and gives some advice about making @command{tar}
7731 archives more portable.
7732
7733 One golden rule is simplicity. For example, limit your @command{tar}
7734 archives to contain only regular files and directories, avoiding
7735 other kind of special files. Do not attempt to save sparse files or
7736 contiguous files as such. Let's discuss a few more problems, in turn.
7737
7738 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7739 archives and archive labels) in GNU and PAX formats.}
7740
7741 @menu
7742 * Portable Names:: Portable Names
7743 * dereference:: Symbolic Links
7744 * old:: Old V7 Archives
7745 * ustar:: Ustar Archives
7746 * gnu:: GNU and old GNU format archives.
7747 * posix:: @acronym{POSIX} archives
7748 * Checksumming:: Checksumming Problems
7749 * Large or Negative Values:: Large files, negative time stamps, etc.
7750 @end menu
7751
7752 @node Portable Names
7753 @subsection Portable Names
7754
7755 Use portable file and member names. A name is portable if it contains
7756 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7757 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7758 contain @samp{/-}. Avoid deep directory nesting. For portability to
7759 old Unix hosts, limit your file name components to 14 characters or
7760 less.
7761
7762 If you intend to have your @command{tar} archives to be read under
7763 MSDOS, you should not rely on case distinction for file names, and you
7764 might use the @acronym{GNU} @command{doschk} program for helping you
7765 further diagnosing illegal MSDOS names, which are even more limited
7766 than System V's.
7767
7768 @node dereference
7769 @subsection Symbolic Links
7770 @cindex File names, using symbolic links
7771 @cindex Symbolic link as file name
7772
7773 @opindex dereference
7774 Normally, when @command{tar} archives a symbolic link, it writes a
7775 block to the archive naming the target of the link. In that way, the
7776 @command{tar} archive is a faithful record of the file system contents.
7777 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7778 @command{tar} to archive the files symbolic links point to, instead of
7779 the links themselves. When this option is used, when @command{tar}
7780 encounters a symbolic link, it will archive the linked-to file,
7781 instead of simply recording the presence of a symbolic link.
7782
7783 The name under which the file is stored in the file system is not
7784 recorded in the archive. To record both the symbolic link name and
7785 the file name in the system, archive the file under both names. If
7786 all links were recorded automatically by @command{tar}, an extracted file
7787 might be linked to a file name that no longer exists in the file
7788 system.
7789
7790 If a linked-to file is encountered again by @command{tar} while creating
7791 the same archive, an entire second copy of it will be stored. (This
7792 @emph{might} be considered a bug.)
7793
7794 So, for portable archives, do not archive symbolic links as such,
7795 and use @option{--dereference} (@option{-h}): many systems do not support
7796 symbolic links, and moreover, your distribution might be unusable if
7797 it contains unresolved symbolic links.
7798
7799 @node old
7800 @subsection Old V7 Archives
7801 @cindex Format, old style
7802 @cindex Old style format
7803 @cindex Old style archives
7804 @cindex v7 archive format
7805
7806 Certain old versions of @command{tar} cannot handle additional
7807 information recorded by newer @command{tar} programs. To create an
7808 archive in V7 format (not ANSI), which can be read by these old
7809 versions, specify the @option{--format=v7} option in
7810 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7811 accepts @option{--portability} or @samp{op-old-archive} for this
7812 option). When you specify it,
7813 @command{tar} leaves out information about directories, pipes, fifos,
7814 contiguous files, and device files, and specifies file ownership by
7815 group and user IDs instead of group and user names.
7816
7817 When updating an archive, do not use @option{--format=v7}
7818 unless the archive was created using this option.
7819
7820 In most cases, a @emph{new} format archive can be read by an @emph{old}
7821 @command{tar} program without serious trouble, so this option should
7822 seldom be needed. On the other hand, most modern @command{tar}s are
7823 able to read old format archives, so it might be safer for you to
7824 always use @option{--format=v7} for your distributions.
7825
7826 @node ustar
7827 @subsection Ustar Archive Format
7828
7829 @cindex ustar archive format
7830 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7831 @code{ustar}. Although it is more flexible than the V7 format, it
7832 still has many restrictions (@xref{Formats,ustar}, for the detailed
7833 description of @code{ustar} format). Along with V7 format,
7834 @code{ustar} format is a good choice for archives intended to be read
7835 with other implementations of @command{tar}.
7836
7837 To create archive in @code{ustar} format, use @option{--format=ustar}
7838 option in conjunction with the @option{--create} (@option{-c}).
7839
7840 @node gnu
7841 @subsection @acronym{GNU} and old @GNUTAR{} format
7842
7843 @cindex GNU archive format
7844 @cindex Old GNU archive format
7845 @GNUTAR{} was based on an early draft of the
7846 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7847 @command{tar}, such as the support for file names longer than 100
7848 characters, use portions of the @command{tar} header record which were
7849 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7850 @acronym{POSIX} have allocated the same parts of the header record for
7851 other purposes. As a result, @GNUTAR{} format is
7852 incompatible with the current @acronym{POSIX} specification, and with
7853 @command{tar} programs that follow it.
7854
7855 In the majority of cases, @command{tar} will be configured to create
7856 this format by default. This will change in the future releases, since
7857 we plan to make @samp{posix} format the default.
7858
7859 To force creation a @GNUTAR{} archive, use option
7860 @option{--format=gnu}.
7861
7862 @node posix
7863 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7864
7865 @cindex POSIX archive format
7866 @cindex PAX archive format
7867 Starting from version 1.14 @GNUTAR{} features full support for
7868 @acronym{POSIX.1-2001} archives.
7869
7870 A @acronym{POSIX} conformant archive will be created if @command{tar}
7871 was given @option{--format=posix} (@option{--format=pax}) option. No
7872 special option is required to read and extract from a @acronym{POSIX}
7873 archive.
7874
7875 @menu
7876 * PAX keywords:: Controlling Extended Header Keywords.
7877 @end menu
7878
7879 @node PAX keywords
7880 @subsubsection Controlling Extended Header Keywords
7881
7882 @table @option
7883 @opindex pax-option
7884 @item --pax-option=@var{keyword-list}
7885 Handle keywords in @acronym{PAX} extended headers. This option is
7886 equivalent to @option{-o} option of the @command{pax} utility.
7887 @end table
7888
7889 @var{Keyword-list} is a comma-separated
7890 list of keyword options, each keyword option taking one of
7891 the following forms:
7892
7893 @table @code
7894 @item delete=@var{pattern}
7895 When used with one of archive-creation commands,
7896 this option instructs @command{tar} to omit from extended header records
7897 that it produces any keywords matching the string @var{pattern}.
7898
7899 When used in extract or list mode, this option instructs tar
7900 to ignore any keywords matching the given @var{pattern} in the extended
7901 header records. In both cases, matching is performed using the pattern
7902 matching notation described in @acronym{POSIX 1003.2}, 3.13
7903 (@pxref{wildcards}). For example:
7904
7905 @smallexample
7906 --pax-option delete=security.*
7907 @end smallexample
7908
7909 would suppress security-related information.
7910
7911 @item exthdr.name=@var{string}
7912
7913 This keyword allows user control over the name that is written into the
7914 ustar header blocks for the extended headers. The name is obtained
7915 from @var{string} after making the following substitutions:
7916
7917 @multitable @columnfractions .25 .55
7918 @headitem Meta-character @tab Replaced By
7919 @item %d @tab The directory name of the file, equivalent to the
7920 result of the @command{dirname} utility on the translated pathname.
7921 @item %f @tab The filename of the file, equivalent to the result
7922 of the @command{basename} utility on the translated pathname.
7923 @item %p @tab The process ID of the @command{tar} process.
7924 @item %% @tab A @samp{%} character.
7925 @end multitable
7926
7927 Any other @samp{%} characters in @var{string} produce undefined
7928 results.
7929
7930 If no option @samp{exthdr.name=string} is specified, @command{tar}
7931 will use the following default value:
7932
7933 @smallexample
7934 %d/PaxHeaders.%p/%f
7935 @end smallexample
7936
7937 @item globexthdr.name=@var{string}
7938 This keyword allows user control over the name that is written into
7939 the ustar header blocks for global extended header records. The name
7940 is obtained from the contents of @var{string}, after making
7941 the following substitutions:
7942
7943 @multitable @columnfractions .25 .55
7944 @headitem Meta-character @tab Replaced By
7945 @item %n @tab An integer that represents the
7946 sequence number of the global extended header record in the archive,
7947 starting at 1.
7948 @item %p @tab The process ID of the @command{tar} process.
7949 @item %% @tab A @samp{%} character.
7950 @end multitable
7951
7952 Any other @samp{%} characters in @var{string} produce undefined results.
7953
7954 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7955 will use the following default value:
7956
7957 @smallexample
7958 $TMPDIR/GlobalHead.%p.%n
7959 @end smallexample
7960
7961 @noindent
7962 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7963 environment variable. If @var{TMPDIR} is not set, @command{tar}
7964 uses @samp{/tmp}.
7965
7966 @item @var{keyword}=@var{value}
7967 When used with one of archive-creation commands, these keyword/value pairs
7968 will be included at the beginning of the archive in a global extended
7969 header record. When used with one of archive-reading commands,
7970 @command{tar} will behave as if it has encountered these keyword/value
7971 pairs at the beginning of the archive in a global extended header
7972 record.
7973
7974 @item @var{keyword}:=@var{value}
7975 When used with one of archive-creation commands, these keyword/value pairs
7976 will be included as records at the beginning of an extended header for
7977 each file. This is effectively equivalent to @var{keyword}=@var{value}
7978 form except that it creates no global extended header records.
7979
7980 When used with one of archive-reading commands, @command{tar} will
7981 behave as if these keyword/value pairs were included as records at the
7982 end of each extended header; thus, they will override any global or
7983 file-specific extended header record keywords of the same names.
7984 For example, in the command:
7985
7986 @smallexample
7987 tar --format=posix --create \
7988 --file archive --pax-option gname:=user .
7989 @end smallexample
7990
7991 the group name will be forced to a new value for all files
7992 stored in the archive.
7993 @end table
7994
7995 @node Checksumming
7996 @subsection Checksumming Problems
7997
7998 SunOS and HP-UX @command{tar} fail to accept archives created using
7999 @GNUTAR{} and containing non-ASCII file names, that
8000 is, file names having characters with the eight bit set, because they
8001 use signed checksums, while @GNUTAR{} uses unsigned
8002 checksums while creating archives, as per @acronym{POSIX} standards. On
8003 reading, @GNUTAR{} computes both checksums and
8004 accept any. It is somewhat worrying that a lot of people may go
8005 around doing backup of their files using faulty (or at least
8006 non-standard) software, not learning about it until it's time to
8007 restore their missing files with an incompatible file extractor, or
8008 vice versa.
8009
8010 @GNUTAR{} compute checksums both ways, and accept
8011 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8012 wrong checksums. @GNUTAR{} produces the standard
8013 checksum, however, raising incompatibilities with Sun. That is to
8014 say, @GNUTAR{} has not been modified to
8015 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8016 I've been told that more recent Sun @command{tar} now read standard
8017 archives, so maybe Sun did a similar patch, after all?
8018
8019 The story seems to be that when Sun first imported @command{tar}
8020 sources on their system, they recompiled it without realizing that
8021 the checksums were computed differently, because of a change in
8022 the default signing of @code{char}'s in their compiler. So they
8023 started computing checksums wrongly. When they later realized their
8024 mistake, they merely decided to stay compatible with it, and with
8025 themselves afterwards. Presumably, but I do not really know, HP-UX
8026 has chosen that their @command{tar} archives to be compatible with Sun's.
8027 The current standards do not favor Sun @command{tar} format. In any
8028 case, it now falls on the shoulders of SunOS and HP-UX users to get
8029 a @command{tar} able to read the good archives they receive.
8030
8031 @node Large or Negative Values
8032 @subsection Large or Negative Values
8033 @cindex large values
8034 @cindex future time stamps
8035 @cindex negative time stamps
8036 @UNREVISED{}
8037
8038 The above sections suggest to use @samp{oldest possible} archive
8039 format if in doubt. However, sometimes it is not possible. If you
8040 attempt to archive a file whose metadata cannot be represented using
8041 required format, @GNUTAR{} will print error message and ignore such a
8042 file. You will than have to switch to a format that is able to
8043 handle such values. The format summary table (@pxref{Formats}) will
8044 help you to do so.
8045
8046 In particular, when trying to archive files larger than 8GB or with
8047 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8048 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8049 @acronym{POSIX} archive formats. When considering which format to
8050 choose, bear in mind that the @acronym{GNU} format uses
8051 two's-complement base-256 notation to store values that do not fit
8052 into standard @acronym{ustar} range. Such archives can generally be
8053 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8054 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8055 example, using two's complement representation for negative time
8056 stamps that assumes a signed 32-bit @code{time_t} generates archives
8057 that are not portable to hosts with differing @code{time_t}
8058 representations.
8059
8060 On the other hand, @acronym{POSIX} archives, generally speaking, can
8061 be extracted by any tar implementation that understands older
8062 @acronym{ustar} format. The only exception are files larger than 8GB.
8063
8064 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8065 POSIX-aware tars.}
8066
8067 @node Compression
8068 @section Using Less Space through Compression
8069
8070 @menu
8071 * gzip:: Creating and Reading Compressed Archives
8072 * sparse:: Archiving Sparse Files
8073 @end menu
8074
8075 @node gzip
8076 @subsection Creating and Reading Compressed Archives
8077 @cindex Compressed archives
8078 @cindex Storing archives in compressed format
8079
8080 @GNUTAR{} is able to create and read compressed archives. It supports
8081 @command{gzip} and @command{bzip2} compression programs. For backward
8082 compatibilty, it also supports @command{compress} command, although
8083 we strongly recommend against using it, since there is a patent
8084 covering the algorithm it uses and you could be sued for patent
8085 infringement merely by running @command{compress}! Besides, it is less
8086 effective than @command{gzip} and @command{bzip2}.
8087
8088 Creating a compressed archive is simple: you just specify a
8089 @dfn{compression option} along with the usual archive creation
8090 commands. The compression option is @option{-z} (@option{--gzip}) to
8091 create a @command{gzip} compressed archive, @option{-j}
8092 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
8093 @option{-Z} (@option{--compress}) to use @command{compress} program.
8094 For example:
8095
8096 @smallexample
8097 $ @kbd{tar cfz archive.tar.gz .}
8098 @end smallexample
8099
8100 Reading compressed archive is even simpler: you don't need to specify
8101 any additional options as @GNUTAR{} recognizes its format
8102 automatically. Thus, the following commands will list and extract the
8103 archive created in previous example:
8104
8105 @smallexample
8106 # List the compressed archive
8107 $ @kbd{tar tf archive.tar.gz}
8108 # Extract the compressed archive
8109 $ @kbd{tar xf archive.tar.gz}
8110 @end smallexample
8111
8112 The only case when you have to specify a decompression option while
8113 reading the archive is when reading from a pipe or from a tape drive
8114 that does not support random access. However, in this case @GNUTAR{}
8115 will indicate which option you should use. For example:
8116
8117 @smallexample
8118 $ @kbd{cat archive.tar.gz | tar tf -}
8119 tar: Archive is compressed. Use -z option
8120 tar: Error is not recoverable: exiting now
8121 @end smallexample
8122
8123 If you see such diagnostics, just add the suggested option to the
8124 invocation of @GNUTAR{}:
8125
8126 @smallexample
8127 $ @kbd{cat archive.tar.gz | tar tfz -}
8128 @end smallexample
8129
8130 Notice also, that there are several restrictions on operations on
8131 compressed archives. First of all, compressed archives cannot be
8132 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8133 (@option{--delete}) members from them. Likewise, you cannot append
8134 another @command{tar} archive to a compressed archive using
8135 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8136 compressed.
8137
8138 The following table summarizes compression options used by @GNUTAR{}.
8139
8140 @table @option
8141 @opindex gzip
8142 @opindex ungzip
8143 @item -z
8144 @itemx --gzip
8145 @itemx --ungzip
8146 Filter the archive through @command{gzip}.
8147
8148 You can use @option{--gzip} and @option{--gunzip} on physical devices
8149 (tape drives, etc.) and remote files as well as on normal files; data
8150 to or from such devices or remote files is reblocked by another copy
8151 of the @command{tar} program to enforce the specified (or default) record
8152 size. The default compression parameters are used; if you need to
8153 override them, set @env{GZIP} environment variable, e.g.:
8154
8155 @smallexample
8156 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8157 @end smallexample
8158
8159 @noindent
8160 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8161 @command{gzip} explicitly:
8162
8163 @smallexample
8164 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8165 @end smallexample
8166
8167 @cindex corrupted archives
8168 About corrupted compressed archives: @command{gzip}'ed files have no
8169 redundancy, for maximum compression. The adaptive nature of the
8170 compression scheme means that the compression tables are implicitly
8171 spread all over the archive. If you lose a few blocks, the dynamic
8172 construction of the compression tables becomes unsynchronized, and there
8173 is little chance that you could recover later in the archive.
8174
8175 There are pending suggestions for having a per-volume or per-file
8176 compression in @GNUTAR{}. This would allow for viewing the
8177 contents without decompression, and for resynchronizing decompression at
8178 every volume or file, in case of corrupted archives. Doing so, we might
8179 lose some compressibility. But this would have make recovering easier.
8180 So, there are pros and cons. We'll see!
8181
8182 @opindex bzip2
8183 @item -j
8184 @itemx --bzip2
8185 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8186
8187 @opindex compress
8188 @opindex uncompress
8189 @item -Z
8190 @itemx --compress
8191 @itemx --uncompress
8192 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8193
8194 The @acronym{GNU} Project recommends you not use
8195 @command{compress}, because there is a patent covering the algorithm it
8196 uses. You could be sued for patent infringement merely by running
8197 @command{compress}.
8198
8199 @opindex use-compress-program
8200 @item --use-compress-program=@var{prog}
8201 Use external compression program @var{prog}. Use this option if you
8202 have a compression program that @GNUTAR{} does not support. There
8203 are two requirements to which @var{prog} should comply:
8204
8205 First, when called without options, it should read data from standard
8206 input, compress it and output it on standard output.
8207
8208 Secondly, if called with @option{-d} argument, it should do exactly
8209 the opposite, i.e., read the compressed data from the standard input
8210 and produce uncompressed data on the standard output.
8211 @end table
8212
8213 @cindex gpg, using with tar
8214 @cindex gnupg, using with tar
8215 @cindex Using encrypted archives
8216 The @option{--use-compress-program} option, in particular, lets you
8217 implement your own filters, not necessarily dealing with
8218 compression/decomression. For example, suppose you wish to implement
8219 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8220 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8221 Manual}). The following script does that:
8222
8223 @smallexample
8224 @group
8225 #! /bin/sh
8226 case $1 in
8227 -d) gpg --decrypt - | gzip -d -c;;
8228 '') gzip -c | gpg -s ;;
8229 *) echo "Unknown option $1">&2; exit 1;;
8230 esac
8231 @end group
8232 @end smallexample
8233
8234 Suppose you name it @file{gpgz} and save it somewhere in your
8235 @env{PATH}. Then the following command will create a commpressed
8236 archive signed with your private key:
8237
8238 @smallexample
8239 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8240 @end smallexample
8241
8242 @noindent
8243 Likewise, the following command will list its contents:
8244
8245 @smallexample
8246 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8247 @end smallexample
8248
8249 @ignore
8250 The above is based on the following discussion:
8251
8252 I have one question, or maybe it's a suggestion if there isn't a way
8253 to do it now. I would like to use @option{--gzip}, but I'd also like
8254 the output to be fed through a program like @acronym{GNU}
8255 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8256 to use :-)), basically adding ECC protection on top of compression.
8257 It seems as if this should be quite easy to do, but I can't work out
8258 exactly how to go about it. Of course, I can pipe the standard output
8259 of @command{tar} through @command{ecc}, but then I lose (though I
8260 haven't started using it yet, I confess) the ability to have
8261 @command{tar} use @command{rmt} for it's I/O (I think).
8262
8263 I think the most straightforward thing would be to let me specify a
8264 general set of filters outboard of compression (preferably ordered,
8265 so the order can be automatically reversed on input operations, and
8266 with the options they require specifiable), but beggars shouldn't be
8267 choosers and anything you decide on would be fine with me.
8268
8269 By the way, I like @command{ecc} but if (as the comments say) it can't
8270 deal with loss of block sync, I'm tempted to throw some time at adding
8271 that capability. Supposing I were to actually do such a thing and
8272 get it (apparently) working, do you accept contributed changes to
8273 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8274
8275 Isn't that exactly the role of the
8276 @option{--use-compress-prog=@var{program}} option?
8277 I never tried it myself, but I suspect you may want to write a
8278 @var{prog} script or program able to filter stdin to stdout to
8279 way you want. It should recognize the @option{-d} option, for when
8280 extraction is needed rather than creation.
8281
8282 It has been reported that if one writes compressed data (through the
8283 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8284 the DLT compression mode, the data will actually get bigger and one will
8285 end up with less space on the tape.
8286 @end ignore
8287
8288 @node sparse
8289 @subsection Archiving Sparse Files
8290 @cindex Sparse Files
8291 @UNREVISED
8292
8293 @table @option
8294 @opindex sparse
8295 @item -S
8296 @itemx --sparse
8297 Handle sparse files efficiently.
8298 @end table
8299
8300 This option causes all files to be put in the archive to be tested for
8301 sparseness, and handled specially if they are. The @option{--sparse}
8302 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8303 backed up. Using this option dramatically decreases the amount of
8304 space needed to store such a file.
8305
8306 In later versions, this option may be removed, and the testing and
8307 treatment of sparse files may be done automatically with any special
8308 @acronym{GNU} options. For now, it is an option needing to be specified on
8309 the command line with the creation or updating of an archive.
8310
8311 Files in the file system occasionally have ``holes.'' A hole in a file
8312 is a section of the file's contents which was never written. The
8313 contents of a hole read as all zeros. On many operating systems,
8314 actual disk storage is not allocated for holes, but they are counted
8315 in the length of the file. If you archive such a file, @command{tar}
8316 could create an archive longer than the original. To have @command{tar}
8317 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8318 you use this option, then, for any file using less disk space than
8319 would be expected from its length, @command{tar} searches the file for
8320 consecutive stretches of zeros. It then records in the archive for
8321 the file where the consecutive stretches of zeros are, and only
8322 archives the ``real contents'' of the file. On extraction (using
8323 @option{--sparse} is not needed on extraction) any such
8324 files have holes created wherever the continuous stretches of zeros
8325 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8326 won't take more space than the original.
8327
8328 A file is sparse if it contains blocks of zeros whose existence is
8329 recorded, but that have no space allocated on disk. When you specify
8330 the @option{--sparse} option in conjunction with the @option{--create}
8331 (@option{-c}) operation, @command{tar} tests all files for sparseness
8332 while archiving. If @command{tar} finds a file to be sparse, it uses a
8333 sparse representation of the file in the archive. @xref{create}, for
8334 more information about creating archives.
8335
8336 @option{--sparse} is useful when archiving files, such as dbm files,
8337 likely to contain many nulls. This option dramatically
8338 decreases the amount of space needed to store such an archive.
8339
8340 @quotation
8341 @strong{Please Note:} Always use @option{--sparse} when performing file
8342 system backups, to avoid archiving the expanded forms of files stored
8343 sparsely in the system.
8344
8345 Even if your system has no sparse files currently, some may be
8346 created in the future. If you use @option{--sparse} while making file
8347 system backups as a matter of course, you can be assured the archive
8348 will never take more space on the media than the files take on disk
8349 (otherwise, archiving a disk filled with sparse files might take
8350 hundreds of tapes). @xref{Incremental Dumps}.
8351 @end quotation
8352
8353 @command{tar} ignores the @option{--sparse} option when reading an archive.
8354
8355 @table @option
8356 @item --sparse
8357 @itemx -S
8358 Files stored sparsely in the file system are represented sparsely in
8359 the archive. Use in conjunction with write operations.
8360 @end table
8361
8362 However, users should be well aware that at archive creation time,
8363 @GNUTAR{} still has to read whole disk file to
8364 locate the @dfn{holes}, and so, even if sparse files use little space
8365 on disk and in the archive, they may sometimes require inordinate
8366 amount of time for reading and examining all-zero blocks of a file.
8367 Although it works, it's painfully slow for a large (sparse) file, even
8368 though the resulting tar archive may be small. (One user reports that
8369 dumping a @file{core} file of over 400 megabytes, but with only about
8370 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8371 ELC, with full CPU utilization.)
8372
8373 This reading is required in all cases and is not related to the fact
8374 the @option{--sparse} option is used or not, so by merely @emph{not}
8375 using the option, you are not saving time@footnote{Well! We should say
8376 the whole truth, here. When @option{--sparse} is selected while creating
8377 an archive, the current @command{tar} algorithm requires sparse files to be
8378 read twice, not once. We hope to develop a new archive format for saving
8379 sparse files in which one pass will be sufficient.}.
8380
8381 Programs like @command{dump} do not have to read the entire file; by
8382 examining the file system directly, they can determine in advance
8383 exactly where the holes are and thus avoid reading through them. The
8384 only data it need read are the actual allocated data blocks.
8385 @GNUTAR{} uses a more portable and straightforward
8386 archiving approach, it would be fairly difficult that it does
8387 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8388 1990-12-10:
8389
8390 @quotation
8391 What I did say is that you cannot tell the difference between a hole and an
8392 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8393 best tells you how many holes there are; it doesn't tell you @emph{where}.
8394 Just as programs may, conceivably, care what @code{st_blocks} is (care
8395 to name one that does?), they may also care where the holes are (I have
8396 no examples of this one either, but it's equally imaginable).
8397
8398 I conclude from this that good archivers are not portable. One can
8399 arguably conclude that if you want a portable program, you can in good
8400 conscience restore files with as many holes as possible, since you can't
8401 get it right.
8402 @end quotation
8403
8404 @node Attributes
8405 @section Handling File Attributes
8406 @UNREVISED
8407
8408 When @command{tar} reads files, it updates their access times. To
8409 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8410 reset the access time retroactively or avoid changing it in the first
8411 place.
8412
8413 Handling of file attributes
8414
8415 @table @option
8416 @opindex atime-preserve
8417 @item --atime-preserve
8418 @itemx --atime-preserve=replace
8419 @itemx --atime-preserve=system
8420 Preserve the access times of files that are read. This works only for
8421 files that you own, unless you have superuser privileges.
8422
8423 @option{--atime-preserve=replace} works on most systems, but it also
8424 restores the data modification time and updates the status change
8425 time. Hence it doesn't interact with incremental dumps nicely
8426 (@pxref{Backups}), and it can set access or data modification times
8427 incorrectly if other programs access the file while @command{tar} is
8428 running.
8429
8430 @option{--atime-preserve=system} avoids changing the access time in
8431 the first place, if the operating system supports this.
8432 Unfortunately, this may or may not work on any given operating system
8433 or file system. If @command{tar} knows for sure it won't work, it
8434 complains right away.
8435
8436 Currently @option{--atime-preserve} with no operand defaults to
8437 @option{--atime-preserve=replace}, but this is intended to change to
8438 @option{--atime-preserve=system} when the latter is better-supported.
8439
8440 @opindex touch
8441 @item -m
8442 @itemx --touch
8443 Do not extract data modification time.
8444
8445 When this option is used, @command{tar} leaves the data modification times
8446 of the files it extracts as the times when the files were extracted,
8447 instead of setting it to the times recorded in the archive.
8448
8449 This option is meaningless with @option{--list} (@option{-t}).
8450
8451 @opindex same-owner
8452 @item --same-owner
8453 Create extracted files with the same ownership they have in the
8454 archive.
8455
8456 This is the default behavior for the superuser,
8457 so this option is meaningful only for non-root users, when @command{tar}
8458 is executed on those systems able to give files away. This is
8459 considered as a security flaw by many people, at least because it
8460 makes quite difficult to correctly account users for the disk space
8461 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8462 files are easily and silently lost when files are given away.
8463
8464 When writing an archive, @command{tar} writes the user id and user name
8465 separately. If it can't find a user name (because the user id is not
8466 in @file{/etc/passwd}), then it does not write one. When restoring,
8467 it tries to look the name (if one was written) up in
8468 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8469 the archive instead.
8470
8471 @opindex no-same-owner
8472 @item --no-same-owner
8473 @itemx -o
8474 Do not attempt to restore ownership when extracting. This is the
8475 default behavior for ordinary users, so this option has an effect
8476 only for the superuser.
8477
8478 @opindex numeric-owner
8479 @item --numeric-owner
8480 The @option{--numeric-owner} option allows (ANSI) archives to be written
8481 without user/group name information or such information to be ignored
8482 when extracting. It effectively disables the generation and/or use
8483 of user/group name information. This option forces extraction using
8484 the numeric ids from the archive, ignoring the names.
8485
8486 This is useful in certain circumstances, when restoring a backup from
8487 an emergency floppy with different passwd/group files for example.
8488 It is otherwise impossible to extract files with the right ownerships
8489 if the password file in use during the extraction does not match the
8490 one belonging to the file system(s) being extracted. This occurs,
8491 for example, if you are restoring your files after a major crash and
8492 had booted from an emergency floppy with no password file or put your
8493 disk into another machine to do the restore.
8494
8495 The numeric ids are @emph{always} saved into @command{tar} archives.
8496 The identifying names are added at create time when provided by the
8497 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8498 used when moving archives between a collection of machines using
8499 a centralized management for attribution of numeric ids to users
8500 and groups. This is often made through using the NIS capabilities.
8501
8502 When making a @command{tar} file for distribution to other sites, it
8503 is sometimes cleaner to use a single owner for all files in the
8504 distribution, and nicer to specify the write permission bits of the
8505 files as stored in the archive independently of their actual value on
8506 the file system. The way to prepare a clean distribution is usually
8507 to have some Makefile rule creating a directory, copying all needed
8508 files in that directory, then setting ownership and permissions as
8509 wanted (there are a lot of possible schemes), and only then making a
8510 @command{tar} archive out of this directory, before cleaning
8511 everything out. Of course, we could add a lot of options to
8512 @GNUTAR{} for fine tuning permissions and ownership.
8513 This is not the good way, I think. @GNUTAR{} is
8514 already crowded with options and moreover, the approach just explained
8515 gives you a great deal of control already.
8516
8517 @xopindex{same-permissions, short description}
8518 @xopindex{preserve-permissions, short description}
8519 @item -p
8520 @itemx --same-permissions
8521 @itemx --preserve-permissions
8522 Extract all protection information.
8523
8524 This option causes @command{tar} to set the modes (access permissions) of
8525 extracted files exactly as recorded in the archive. If this option
8526 is not used, the current @code{umask} setting limits the permissions
8527 on extracted files. This option is by default enabled when
8528 @command{tar} is executed by a superuser.
8529
8530
8531 This option is meaningless with @option{--list} (@option{-t}).
8532
8533 @opindex preserve
8534 @item --preserve
8535 Same as both @option{--same-permissions} and @option{--same-order}.
8536
8537 The @option{--preserve} option has no equivalent short option name.
8538 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8539
8540 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8541 Neither do I. --Sergey}
8542
8543 @end table
8544
8545 @node cpio
8546 @section Comparison of @command{tar} and @command{cpio}
8547 @UNREVISED
8548
8549 @FIXME{Reorganize the following material}
8550
8551 The @command{cpio} archive formats, like @command{tar}, do have maximum
8552 pathname lengths. The binary and old ASCII formats have a max path
8553 length of 256, and the new ASCII and CRC ASCII formats have a max
8554 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8555 with arbitrary pathname lengths, but other @command{cpio} implementations
8556 may crash unexplainedly trying to read them.
8557
8558 @command{tar} handles symbolic links in the form in which it comes in BSD;
8559 @command{cpio} doesn't handle symbolic links in the form in which it comes
8560 in System V prior to SVR4, and some vendors may have added symlinks
8561 to their system without enhancing @command{cpio} to know about them.
8562 Others may have enhanced it in a way other than the way I did it
8563 at Sun, and which was adopted by AT&T (and which is, I think, also
8564 present in the @command{cpio} that Berkeley picked up from AT&T and put
8565 into a later BSD release---I think I gave them my changes).
8566
8567 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8568 can handle @command{tar} format input, and write it on output, and it
8569 probably handles symbolic links. They may not have bothered doing
8570 anything to enhance @command{tar} as a result.)
8571
8572 @command{cpio} handles special files; traditional @command{tar} doesn't.
8573
8574 @command{tar} comes with V7, System III, System V, and BSD source;
8575 @command{cpio} comes only with System III, System V, and later BSD
8576 (4.3-tahoe and later).
8577
8578 @command{tar}'s way of handling multiple hard links to a file can handle
8579 file systems that support 32-bit inumbers (e.g., the BSD file system);
8580 @command{cpio}s way requires you to play some games (in its "binary"
8581 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8582 they're 18 bits---it would have to play games with the "file system ID"
8583 field of the header to make sure that the file system ID/i-number pairs
8584 of different files were always different), and I don't know which
8585 @command{cpio}s, if any, play those games. Those that don't might get
8586 confused and think two files are the same file when they're not, and
8587 make hard links between them.
8588
8589 @command{tar}s way of handling multiple hard links to a file places only
8590 one copy of the link on the tape, but the name attached to that copy
8591 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8592 way puts one copy for every link, but you can retrieve it using any
8593 of the names.
8594
8595 @quotation
8596 What type of check sum (if any) is used, and how is this calculated.
8597 @end quotation
8598
8599 See the attached manual pages for @command{tar} and @command{cpio} format.
8600 @command{tar} uses a checksum which is the sum of all the bytes in the
8601 @command{tar} header for a file; @command{cpio} uses no checksum.
8602
8603 @quotation
8604 If anyone knows why @command{cpio} was made when @command{tar} was present
8605 at the unix scene,
8606 @end quotation
8607
8608 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8609 generally-available version of UNIX had @command{tar} at the time. I don't
8610 know whether any version that was generally available @emph{within AT&T}
8611 had @command{tar}, or, if so, whether the people within AT&T who did
8612 @command{cpio} knew about it.
8613
8614 On restore, if there is a corruption on a tape @command{tar} will stop at
8615 that point, while @command{cpio} will skip over it and try to restore the
8616 rest of the files.
8617
8618 The main difference is just in the command syntax and header format.
8619
8620 @command{tar} is a little more tape-oriented in that everything is blocked
8621 to start on a record boundary.
8622
8623 @quotation
8624 Is there any differences between the ability to recover crashed
8625 archives between the two of them. (Is there any chance of recovering
8626 crashed archives at all.)
8627 @end quotation
8628
8629 Theoretically it should be easier under @command{tar} since the blocking
8630 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8631 However, modern @command{cpio}'s and variations have an option to just
8632 search for the next file header after an error with a reasonable chance
8633 of resyncing. However, lots of tape driver software won't allow you to
8634 continue past a media error which should be the only reason for getting
8635 out of sync unless a file changed sizes while you were writing the
8636 archive.
8637
8638 @quotation
8639 If anyone knows why @command{cpio} was made when @command{tar} was present
8640 at the unix scene, please tell me about this too.
8641 @end quotation
8642
8643 Probably because it is more media efficient (by not blocking everything
8644 and using only the space needed for the headers where @command{tar}
8645 always uses 512 bytes per file header) and it knows how to archive
8646 special files.
8647
8648 You might want to look at the freely available alternatives. The
8649 major ones are @command{afio}, @GNUTAR{}, and
8650 @command{pax}, each of which have their own extensions with some
8651 backwards compatibility.
8652
8653 Sparse files were @command{tar}red as sparse files (which you can
8654 easily test, because the resulting archive gets smaller, and
8655 @acronym{GNU} @command{cpio} can no longer read it).
8656
8657 @node Media
8658 @chapter Tapes and Other Archive Media
8659 @UNREVISED
8660
8661 A few special cases about tape handling warrant more detailed
8662 description. These special cases are discussed below.
8663
8664 Many complexities surround the use of @command{tar} on tape drives. Since
8665 the creation and manipulation of archives located on magnetic tape was
8666 the original purpose of @command{tar}, it contains many features making
8667 such manipulation easier.
8668
8669 Archives are usually written on dismountable media---tape cartridges,
8670 mag tapes, or floppy disks.
8671
8672 The amount of data a tape or disk holds depends not only on its size,
8673 but also on how it is formatted. A 2400 foot long reel of mag tape
8674 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8675 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8676
8677 Magnetic media are re-usable---once the archive on a tape is no longer
8678 needed, the archive can be erased and the tape or disk used over.
8679 Media quality does deteriorate with use, however. Most tapes or disks
8680 should be discarded when they begin to produce data errors. EXABYTE
8681 tape cartridges should be discarded when they generate an @dfn{error
8682 count} (number of non-usable bits) of more than 10k.
8683
8684 Magnetic media are written and erased using magnetic fields, and
8685 should be protected from such fields to avoid damage to stored data.
8686 Sticking a floppy disk to a filing cabinet using a magnet is probably
8687 not a good idea.
8688
8689 @menu
8690 * Device:: Device selection and switching
8691 * Remote Tape Server::
8692 * Common Problems and Solutions::
8693 * Blocking:: Blocking
8694 * Many:: Many archives on one tape
8695 * Using Multiple Tapes:: Using Multiple Tapes
8696 * label:: Including a Label in the Archive
8697 * verify::
8698 * Write Protection::
8699 @end menu
8700
8701 @node Device
8702 @section Device Selection and Switching
8703 @UNREVISED
8704
8705 @table @option
8706 @item -f [@var{hostname}:]@var{file}
8707 @itemx --file=[@var{hostname}:]@var{file}
8708 Use archive file or device @var{file} on @var{hostname}.
8709 @end table
8710
8711 This option is used to specify the file name of the archive @command{tar}
8712 works on.
8713
8714 If the file name is @samp{-}, @command{tar} reads the archive from standard
8715 input (when listing or extracting), or writes it to standard output
8716 (when creating). If the @samp{-} file name is given when updating an
8717 archive, @command{tar} will read the original archive from its standard
8718 input, and will write the entire new archive to its standard output.
8719
8720 If the file name contains a @samp{:}, it is interpreted as
8721 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8722 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8723 either case, @command{tar} will invoke the command @command{rsh} (or
8724 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8725 machine. If you give an alternate login name, it will be given to the
8726 @command{rsh}.
8727 Naturally, the remote machine must have an executable
8728 @command{/usr/libexec/rmt}. This program is free software from the
8729 University of California, and a copy of the source code can be found
8730 with the sources for @command{tar}; it's compiled and installed by default.
8731 The exact path to this utility is determined when configuring the package.
8732 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8733 your installation prefix. This location may also be overridden at
8734 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8735 ---rmt-command}, for detailed description of this option. @xref{Remote
8736 Tape Server}, for the description of @command{rmt} command).
8737
8738 If this option is not given, but the environment variable @env{TAPE}
8739 is set, its value is used; otherwise, old versions of @command{tar}
8740 used a default archive name (which was picked when @command{tar} was
8741 compiled). The default is normally set up to be the @dfn{first} tape
8742 drive or other transportable I/O medium on the system.
8743
8744 Starting with version 1.11.5, @GNUTAR{} uses
8745 standard input and standard output as the default device, and I will
8746 not try anymore supporting automatic device detection at installation
8747 time. This was failing really in too many cases, it was hopeless.
8748 This is now completely left to the installer to override standard
8749 input and standard output for default device, if this seems
8750 preferable. Further, I think @emph{most} actual usages of
8751 @command{tar} are done with pipes or disks, not really tapes,
8752 cartridges or diskettes.
8753
8754 Some users think that using standard input and output is running
8755 after trouble. This could lead to a nasty surprise on your screen if
8756 you forget to specify an output file name---especially if you are going
8757 through a network or terminal server capable of buffering large amounts
8758 of output. We had so many bug reports in that area of configuring
8759 default tapes automatically, and so many contradicting requests, that
8760 we finally consider the problem to be portably intractable. We could
8761 of course use something like @samp{/dev/tape} as a default, but this
8762 is @emph{also} running after various kind of trouble, going from hung
8763 processes to accidental destruction of real tapes. After having seen
8764 all this mess, using standard input and output as a default really
8765 sounds like the only clean choice left, and a very useful one too.
8766
8767 @GNUTAR{} reads and writes archive in records, I
8768 suspect this is the main reason why block devices are preferred over
8769 character devices. Most probably, block devices are more efficient
8770 too. The installer could also check for @samp{DEFTAPE} in
8771 @file{<sys/mtio.h>}.
8772
8773 @table @option
8774 @xopindex{force-local, short description}
8775 @item --force-local
8776 Archive file is local even if it contains a colon.
8777
8778 @opindex rsh-command
8779 @item --rsh-command=@var{command}
8780 Use remote @var{command} instead of @command{rsh}. This option exists
8781 so that people who use something other than the standard @command{rsh}
8782 (e.g., a Kerberized @command{rsh}) can access a remote device.
8783
8784 When this command is not used, the shell command found when
8785 the @command{tar} program was installed is used instead. This is
8786 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8787 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8788 The installer may have overridden this by defining the environment
8789 variable @env{RSH} @emph{at installation time}.
8790
8791 @item -[0-7][lmh]
8792 Specify drive and density.
8793
8794 @xopindex{multi-volume, short description}
8795 @item -M
8796 @itemx --multi-volume
8797 Create/list/extract multi-volume archive.
8798
8799 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8800 that may be larger than will fit on the medium used to hold it.
8801 @xref{Multi-Volume Archives}.
8802
8803 @xopindex{tape-length, short description}
8804 @item -L @var{num}
8805 @itemx --tape-length=@var{num}
8806 Change tape after writing @var{num} x 1024 bytes.
8807
8808 This option might be useful when your tape drivers do not properly
8809 detect end of physical tapes. By being slightly conservative on the
8810 maximum tape length, you might avoid the problem entirely.
8811
8812 @xopindex{info-script, short description}
8813 @xopindex{new-volume-script, short description}
8814 @item -F @var{file}
8815 @itemx --info-script=@var{file}
8816 @itemx --new-volume-script=@var{file}
8817 Execute @file{file} at end of each tape. This implies
8818 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8819 description of this option.
8820 @end table
8821
8822 @node Remote Tape Server
8823 @section The Remote Tape Server
8824
8825 @cindex remote tape drive
8826 @pindex rmt
8827 In order to access the tape drive on a remote machine, @command{tar}
8828 uses the remote tape server written at the University of California at
8829 Berkeley. The remote tape server must be installed as
8830 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8831 want to use. @command{tar} calls @command{rmt} by running an
8832 @command{rsh} or @command{remsh} to the remote machine, optionally
8833 using a different login name if one is supplied.
8834
8835 A copy of the source for the remote tape server is provided. It is
8836 Copyright @copyright{} 1983 by the Regents of the University of
8837 California, but can be freely distributed. It is compiled and
8838 installed by default.
8839
8840 @cindex absolute file names
8841 Unless you use the @option{--absolute-names} (@option{-P}) option,
8842 @GNUTAR{} will not allow you to create an archive that contains
8843 absolute file names (a file name beginning with @samp{/}.) If you try,
8844 @command{tar} will automatically remove the leading @samp{/} from the
8845 file names it stores in the archive. It will also type a warning
8846 message telling you what it is doing.
8847
8848 When reading an archive that was created with a different
8849 @command{tar} program, @GNUTAR{} automatically
8850 extracts entries in the archive which have absolute file names as if
8851 the file names were not absolute. This is an important feature. A
8852 visitor here once gave a @command{tar} tape to an operator to restore;
8853 the operator used Sun @command{tar} instead of @GNUTAR{},
8854 and the result was that it replaced large portions of
8855 our @file{/bin} and friends with versions from the tape; needless to
8856 say, we were unhappy about having to recover the file system from
8857 backup tapes.
8858
8859 For example, if the archive contained a file @file{/usr/bin/computoy},
8860 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8861 relative to the current directory. If you want to extract the files in
8862 an archive to the same absolute names that they had when the archive
8863 was created, you should do a @samp{cd /} before extracting the files
8864 from the archive, or you should either use the @option{--absolute-names}
8865 option, or use the command @samp{tar -C / @dots{}}.
8866
8867 @cindex Ultrix 3.1 and write failure
8868 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8869 can claim that a short write near the end of a tape succeeded,
8870 when it actually failed. This will result in the -M option not
8871 working correctly. The best workaround at the moment is to use a
8872 significantly larger blocking factor than the default 20.
8873
8874 In order to update an archive, @command{tar} must be able to backspace the
8875 archive in order to reread or rewrite a record that was just read (or
8876 written). This is currently possible only on two kinds of files: normal
8877 disk files (or any other file that can be backspaced with @samp{lseek}),
8878 and industry-standard 9-track magnetic tape (or any other kind of tape
8879 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8880
8881 This means that the @option{--append}, @option{--concatenate}, and
8882 @option{--delete} commands will not work on any other kind of file.
8883 Some media simply cannot be backspaced, which means these commands and
8884 options will never be able to work on them. These non-backspacing
8885 media include pipes and cartridge tape drives.
8886
8887 Some other media can be backspaced, and @command{tar} will work on them
8888 once @command{tar} is modified to do so.
8889
8890 Archives created with the @option{--multi-volume}, @option{--label}, and
8891 @option{--incremental} (@option{-G}) options may not be readable by other version
8892 of @command{tar}. In particular, restoring a file that was split over
8893 a volume boundary will require some careful work with @command{dd}, if
8894 it can be done at all. Other versions of @command{tar} may also create
8895 an empty file whose name is that of the volume header. Some versions
8896 of @command{tar} may create normal files instead of directories archived
8897 with the @option{--incremental} (@option{-G}) option.
8898
8899 @node Common Problems and Solutions
8900 @section Some Common Problems and their Solutions
8901
8902 @ifclear PUBLISH
8903
8904 @format
8905 errors from system:
8906 permission denied
8907 no such file or directory
8908 not owner
8909
8910 errors from @command{tar}:
8911 directory checksum error
8912 header format error
8913
8914 errors from media/system:
8915 i/o error
8916 device busy
8917 @end format
8918
8919 @end ifclear
8920
8921 @node Blocking
8922 @section Blocking
8923 @UNREVISED
8924
8925 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8926 is also confusing to the expert reader. On the other hand, readers
8927 who are new to the field have a fresh mind, and they may safely skip
8928 the next two paragraphs, as the remainder of this manual uses those
8929 two terms in a quite consistent way.
8930
8931 John Gilmore, the writer of the public domain @command{tar} from which
8932 @GNUTAR{} was originally derived, wrote (June 1995):
8933
8934 @quotation
8935 The nomenclature of tape drives comes from IBM, where I believe
8936 they were invented for the IBM 650 or so. On IBM mainframes, what
8937 is recorded on tape are tape blocks. The logical organization of
8938 data is into records. There are various ways of putting records into
8939 blocks, including @code{F} (fixed sized records), @code{V} (variable
8940 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8941 to a block), @code{VB} (variable size records, @var{n} to a block),
8942 @code{VSB} (variable spanned blocked: variable sized records that can
8943 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8944 parameter specified this to the operating system.
8945
8946 The Unix man page on @command{tar} was totally confused about this.
8947 When I wrote @code{PD TAR}, I used the historically correct terminology
8948 (@command{tar} writes data records, which are grouped into blocks).
8949 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8950 here), and now Fran@,{c}ois has migrated that terminology back
8951 into the source code too.
8952 @end quotation
8953
8954 The term @dfn{physical block} means the basic transfer chunk from or
8955 to a device, after which reading or writing may stop without anything
8956 being lost. In this manual, the term @dfn{block} usually refers to
8957 a disk physical block, @emph{assuming} that each disk block is 512
8958 bytes in length. It is true that some disk devices have different
8959 physical blocks, but @command{tar} ignore these differences in its own
8960 format, which is meant to be portable, so a @command{tar} block is always
8961 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8962 The term @dfn{logical block} often represents the basic chunk of
8963 allocation of many disk blocks as a single entity, which the operating
8964 system treats somewhat atomically; this concept is only barely used
8965 in @GNUTAR{}.
8966
8967 The term @dfn{physical record} is another way to speak of a physical
8968 block, those two terms are somewhat interchangeable. In this manual,
8969 the term @dfn{record} usually refers to a tape physical block,
8970 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8971 It is true that archives may be put on disk or used with pipes,
8972 but nevertheless, @command{tar} tries to read and write the archive one
8973 @dfn{record} at a time, whatever the medium in use. One record is made
8974 up of an integral number of blocks, and this operation of putting many
8975 disk blocks into a single tape block is called @dfn{reblocking}, or
8976 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8977 the logical organization of many characters into something meaningful
8978 to the application. The term @dfn{unit record} describes a small set
8979 of characters which are transmitted whole to or by the application,
8980 and often refers to a line of text. Those two last terms are unrelated
8981 to what we call a @dfn{record} in @GNUTAR{}.
8982
8983 When writing to tapes, @command{tar} writes the contents of the archive
8984 in chunks known as @dfn{records}. To change the default blocking
8985 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8986 @var{512-size}}) option. Each record will then be composed of
8987 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8988 @xref{Standard}.) Each file written to the archive uses at least one
8989 full record. As a result, using a larger record size can result in
8990 more wasted space for small files. On the other hand, a larger record
8991 size can often be read and written much more efficiently.
8992
8993 Further complicating the problem is that some tape drives ignore the
8994 blocking entirely. For these, a larger record size can still improve
8995 performance (because the software layers above the tape drive still
8996 honor the blocking), but not as dramatically as on tape drives that
8997 honor blocking.
8998
8999 When reading an archive, @command{tar} can usually figure out the
9000 record size on itself. When this is the case, and a non-standard
9001 record size was used when the archive was created, @command{tar} will
9002 print a message about a non-standard blocking factor, and then operate
9003 normally. On some tape devices, however, @command{tar} cannot figure
9004 out the record size itself. On most of those, you can specify a
9005 blocking factor (with @option{--blocking-factor}) larger than the
9006 actual blocking factor, and then use the @option{--read-full-records}
9007 (@option{-B}) option. (If you specify a blocking factor with
9008 @option{--blocking-factor} and don't use the
9009 @option{--read-full-records} option, then @command{tar} will not
9010 attempt to figure out the recording size itself.) On some devices,
9011 you must always specify the record size exactly with
9012 @option{--blocking-factor} when reading, because @command{tar} cannot
9013 figure it out. In any case, use @option{--list} (@option{-t}) before
9014 doing any extractions to see whether @command{tar} is reading the archive
9015 correctly.
9016
9017 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9018 putting them into records is to put a whole number of them (one or
9019 more) into each record. @command{tar} records are all the same size;
9020 at the end of the file there's a block containing all zeros, which
9021 is how you tell that the remainder of the last record(s) are garbage.
9022
9023 In a standard @command{tar} file (no options), the block size is 512
9024 and the record size is 10240, for a blocking factor of 20. What the
9025 @option{--blocking-factor} option does is sets the blocking factor,
9026 changing the record size while leaving the block size at 512 bytes.
9027 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9028 most tape drives these days prefer much bigger records in order to
9029 stream and not waste tape. When writing tapes for myself, some tend
9030 to use a factor of the order of 2048, say, giving a record size of
9031 around one megabyte.
9032
9033 If you use a blocking factor larger than 20, older @command{tar}
9034 programs might not be able to read the archive, so we recommend this
9035 as a limit to use in practice. @GNUTAR{}, however,
9036 will support arbitrarily large record sizes, limited only by the
9037 amount of virtual memory or the physical characteristics of the tape
9038 device.
9039
9040 @menu
9041 * Format Variations:: Format Variations
9042 * Blocking Factor:: The Blocking Factor of an Archive
9043 @end menu
9044
9045 @node Format Variations
9046 @subsection Format Variations
9047 @cindex Format Parameters
9048 @cindex Format Options
9049 @cindex Options, archive format specifying
9050 @cindex Options, format specifying
9051 @UNREVISED
9052
9053 Format parameters specify how an archive is written on the archive
9054 media. The best choice of format parameters will vary depending on
9055 the type and number of files being archived, and on the media used to
9056 store the archive.
9057
9058 To specify format parameters when accessing or creating an archive,
9059 you can use the options described in the following sections.
9060 If you do not specify any format parameters, @command{tar} uses
9061 default parameters. You cannot modify a compressed archive.
9062 If you create an archive with the @option{--blocking-factor} option
9063 specified (@pxref{Blocking Factor}), you must specify that
9064 blocking-factor when operating on the archive. @xref{Formats}, for other
9065 examples of format parameter considerations.
9066
9067 @node Blocking Factor
9068 @subsection The Blocking Factor of an Archive
9069 @cindex Blocking Factor
9070 @cindex Record Size
9071 @cindex Number of blocks per record
9072 @cindex Number of bytes per record
9073 @cindex Bytes per record
9074 @cindex Blocks per record
9075 @UNREVISED
9076
9077 @opindex blocking-factor
9078 The data in an archive is grouped into blocks, which are 512 bytes.
9079 Blocks are read and written in whole number multiples called
9080 @dfn{records}. The number of blocks in a record (i.e. the size of a
9081 record in units of 512 bytes) is called the @dfn{blocking factor}.
9082 The @option{--blocking-factor=@var{512-size}} (@option{-b
9083 @var{512-size}}) option specifies the blocking factor of an archive.
9084 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9085 can be specified at installation. To find out the blocking factor of
9086 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9087 This may not work on some devices.
9088
9089 Records are separated by gaps, which waste space on the archive media.
9090 If you are archiving on magnetic tape, using a larger blocking factor
9091 (and therefore larger records) provides faster throughput and allows you
9092 to fit more data on a tape (because there are fewer gaps). If you are
9093 archiving on cartridge, a very large blocking factor (say 126 or more)
9094 greatly increases performance. A smaller blocking factor, on the other
9095 hand, may be useful when archiving small files, to avoid archiving lots
9096 of nulls as @command{tar} fills out the archive to the end of the record.
9097 In general, the ideal record size depends on the size of the
9098 inter-record gaps on the tape you are using, and the average size of the
9099 files you are archiving. @xref{create}, for information on
9100 writing archives.
9101
9102 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9103
9104 Archives with blocking factors larger than 20 cannot be read
9105 by very old versions of @command{tar}, or by some newer versions
9106 of @command{tar} running on old machines with small address spaces.
9107 With @GNUTAR{}, the blocking factor of an archive is limited
9108 only by the maximum record size of the device containing the archive,
9109 or by the amount of available virtual memory.
9110
9111 Also, on some systems, not using adequate blocking factors, as sometimes
9112 imposed by the device drivers, may yield unexpected diagnostics. For
9113 example, this has been reported:
9114
9115 @smallexample
9116 Cannot write to /dev/dlt: Invalid argument
9117 @end smallexample
9118
9119 @noindent
9120 In such cases, it sometimes happen that the @command{tar} bundled by
9121 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9122 requires an explicit specification for the block size,
9123 which it cannot guess. This yields some people to consider
9124 @GNUTAR{} is misbehaving, because by comparison,
9125 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9126 for example, might resolve the problem.
9127
9128 If you use a non-default blocking factor when you create an archive, you
9129 must specify the same blocking factor when you modify that archive. Some
9130 archive devices will also require you to specify the blocking factor when
9131 reading that archive, however this is not typically the case. Usually, you
9132 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9133 reports a non-default record size and then lists the archive members as
9134 it would normally. To extract files from an archive with a non-standard
9135 blocking factor (particularly if you're not sure what the blocking factor
9136 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9137 specifying a blocking factor larger then the blocking factor of the archive
9138 (i.e. @samp{tar --extract --read-full-records --blocking-factor=300}.
9139 @xref{list}, for more information on the @option{--list} (@option{-t})
9140 operation. @xref{Reading}, for a more detailed explanation of that option.
9141
9142 @table @option
9143 @item --blocking-factor=@var{number}
9144 @itemx -b @var{number}
9145 Specifies the blocking factor of an archive. Can be used with any
9146 operation, but is usually not necessary with @option{--list} (@option{-t}).
9147 @end table
9148
9149 Device blocking
9150
9151 @table @option
9152 @item -b @var{blocks}
9153 @itemx --blocking-factor=@var{blocks}
9154 Set record size to @math{@var{blocks} * 512} bytes.
9155
9156 This option is used to specify a @dfn{blocking factor} for the archive.
9157 When reading or writing the archive, @command{tar}, will do reads and writes
9158 of the archive in records of @math{@var{block}*512} bytes. This is true
9159 even when the archive is compressed. Some devices requires that all
9160 write operations be a multiple of a certain size, and so, @command{tar}
9161 pads the archive out to the next record boundary.
9162
9163 The default blocking factor is set when @command{tar} is compiled, and is
9164 typically 20. Blocking factors larger than 20 cannot be read by very
9165 old versions of @command{tar}, or by some newer versions of @command{tar}
9166 running on old machines with small address spaces.
9167
9168 With a magnetic tape, larger records give faster throughput and fit
9169 more data on a tape (because there are fewer inter-record gaps).
9170 If the archive is in a disk file or a pipe, you may want to specify
9171 a smaller blocking factor, since a large one will result in a large
9172 number of null bytes at the end of the archive.
9173
9174 When writing cartridge or other streaming tapes, a much larger
9175 blocking factor (say 126 or more) will greatly increase performance.
9176 However, you must specify the same blocking factor when reading or
9177 updating the archive.
9178
9179 Apparently, Exabyte drives have a physical block size of 8K bytes.
9180 If we choose our blocksize as a multiple of 8k bytes, then the problem
9181 seems to disappear. Id est, we are using block size of 112 right
9182 now, and we haven't had the problem since we switched@dots{}
9183
9184 With @GNUTAR{} the blocking factor is limited only
9185 by the maximum record size of the device containing the archive, or by
9186 the amount of available virtual memory.
9187
9188 However, deblocking or reblocking is virtually avoided in a special
9189 case which often occurs in practice, but which requires all the
9190 following conditions to be simultaneously true:
9191 @itemize @bullet
9192 @item
9193 the archive is subject to a compression option,
9194 @item
9195 the archive is not handled through standard input or output, nor
9196 redirected nor piped,
9197 @item
9198 the archive is directly handled to a local disk, instead of any special
9199 device,
9200 @item
9201 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9202 invocation.
9203 @end itemize
9204
9205 If the output goes directly to a local disk, and not through
9206 stdout, then the last write is not extended to a full record size.
9207 Otherwise, reblocking occurs. Here are a few other remarks on this
9208 topic:
9209
9210 @itemize @bullet
9211
9212 @item
9213 @command{gzip} will complain about trailing garbage if asked to
9214 uncompress a compressed archive on tape, there is an option to turn
9215 the message off, but it breaks the regularity of simply having to use
9216 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9217 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9218 Gailly, by sending a copy of this message to him.
9219
9220 @item
9221 @command{compress} does not show this problem, but as Jean-loup pointed
9222 out to Michael, @samp{compress -d} silently adds garbage after
9223 the result of decompression, which tar ignores because it already
9224 recognized its end-of-file indicator. So this bug may be safely
9225 ignored.
9226
9227 @item
9228 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9229 but will still return an exit status of 2 which tar reports in turn.
9230 @command{tar} might ignore the exit status returned, but I hate doing
9231 that, as it weakens the protection @command{tar} offers users against
9232 other possible problems at decompression time. If @command{gzip} was
9233 silently skipping trailing zeros @emph{and} also avoiding setting the
9234 exit status in this innocuous case, that would solve this situation.
9235
9236 @item
9237 @command{tar} should become more solid at not stopping to read a pipe at
9238 the first null block encountered. This inelegantly breaks the pipe.
9239 @command{tar} should rather drain the pipe out before exiting itself.
9240 @end itemize
9241
9242 @xopindex{ignore-zeros, short description}
9243 @item -i
9244 @itemx --ignore-zeros
9245 Ignore blocks of zeros in archive (means EOF).
9246
9247 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9248 of zeros in the archive. Normally a block of zeros indicates the
9249 end of the archive, but when reading a damaged archive, or one which
9250 was created by concatenating several archives together, this option
9251 allows @command{tar} to read the entire archive. This option is not on
9252 by default because many versions of @command{tar} write garbage after
9253 the zeroed blocks.
9254
9255 Note that this option causes @command{tar} to read to the end of the
9256 archive file, which may sometimes avoid problems when multiple files
9257 are stored on a single physical tape.
9258
9259 @xopindex{read-full-records, short description}
9260 @item -B
9261 @itemx --read-full-records
9262 Reblock as we read (for reading 4.2BSD pipes).
9263
9264 If @option{--read-full-records} is used, @command{tar}
9265 will not panic if an attempt to read a record from the archive does
9266 not return a full record. Instead, @command{tar} will keep reading
9267 until it has obtained a full
9268 record.
9269
9270 This option is turned on by default when @command{tar} is reading
9271 an archive from standard input, or from a remote machine. This is
9272 because on BSD Unix systems, a read of a pipe will return however
9273 much happens to be in the pipe, even if it is less than @command{tar}
9274 requested. If this option was not used, @command{tar} would fail as
9275 soon as it read an incomplete record from the pipe.
9276
9277 This option is also useful with the commands for updating an archive.
9278
9279 @end table
9280
9281 Tape blocking
9282
9283 @FIXME{Appropriate options should be moved here from elsewhere.}
9284
9285 @cindex blocking factor
9286 @cindex tape blocking
9287
9288 When handling various tapes or cartridges, you have to take care of
9289 selecting a proper blocking, that is, the number of disk blocks you
9290 put together as a single tape block on the tape, without intervening
9291 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9292 with no information on it, used for decelerating the tape to a
9293 full stop, and for later regaining the reading or writing speed.
9294 When the tape driver starts reading a record, the record has to
9295 be read whole without stopping, as a tape gap is needed to stop the
9296 tape motion without loosing information.
9297
9298 @cindex Exabyte blocking
9299 @cindex DAT blocking
9300 Using higher blocking (putting more disk blocks per tape block) will use
9301 the tape more efficiently as there will be less tape gaps. But reading
9302 such tapes may be more difficult for the system, as more memory will be
9303 required to receive at once the whole record. Further, if there is a
9304 reading error on a huge record, this is less likely that the system will
9305 succeed in recovering the information. So, blocking should not be too
9306 low, nor it should be too high. @command{tar} uses by default a blocking of
9307 20 for historical reasons, and it does not really matter when reading or
9308 writing to disk. Current tape technology would easily accommodate higher
9309 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9310 We were told that for some DLT drives, the blocking should be a multiple
9311 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9312 Other manufacturers may use different recommendations for the same tapes.
9313 This might also depends of the buffering techniques used inside modern
9314 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9315 Others request blocking to be some exponent of two.
9316
9317 So, there is no fixed rule for blocking. But blocking at read time
9318 should ideally be the same as blocking used at write time. At one place
9319 I know, with a wide variety of equipment, they found it best to use a
9320 blocking of 32 to guarantee that their tapes are fully interchangeable.
9321
9322 I was also told that, for recycled tapes, prior erasure (by the same
9323 drive unit that will be used to create the archives) sometimes lowers
9324 the error rates observed at rewriting time.
9325
9326 I might also use @option{--number-blocks} instead of
9327 @option{--block-number}, so @option{--block} will then expand to
9328 @option{--blocking-factor} unambiguously.
9329
9330 @node Many
9331 @section Many Archives on One Tape
9332
9333 @FIXME{Appropriate options should be moved here from elsewhere.}
9334
9335 @findex ntape @r{device}
9336 Most tape devices have two entries in the @file{/dev} directory, or
9337 entries that come in pairs, which differ only in the minor number for
9338 this device. Let's take for example @file{/dev/tape}, which often
9339 points to the only or usual tape device of a given system. There might
9340 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9341 name is the @emph{rewinding} version of the device, while the name
9342 having @samp{nr} in it is the @emph{no rewinding} version of the same
9343 device.
9344
9345 A rewinding tape device will bring back the tape to its beginning point
9346 automatically when this device is opened or closed. Since @command{tar}
9347 opens the archive file before using it and closes it afterwards, this
9348 means that a simple:
9349
9350 @smallexample
9351 $ @kbd{tar cf /dev/tape @var{directory}}
9352 @end smallexample
9353
9354 @noindent
9355 will reposition the tape to its beginning both prior and after saving
9356 @var{directory} contents to it, thus erasing prior tape contents and
9357 making it so that any subsequent write operation will destroy what has
9358 just been saved.
9359
9360 @cindex tape positioning
9361 So, a rewinding device is normally meant to hold one and only one file.
9362 If you want to put more than one @command{tar} archive on a given tape, you
9363 will need to avoid using the rewinding version of the tape device. You
9364 will also have to pay special attention to tape positioning. Errors in
9365 positioning may overwrite the valuable data already on your tape. Many
9366 people, burnt by past experiences, will only use rewinding devices and
9367 limit themselves to one file per tape, precisely to avoid the risk of
9368 such errors. Be fully aware that writing at the wrong position on a
9369 tape loses all information past this point and most probably until the
9370 end of the tape, and this destroyed information @emph{cannot} be
9371 recovered.
9372
9373 To save @var{directory-1} as a first archive at the beginning of a
9374 tape, and leave that tape ready for a second archive, you should use:
9375
9376 @smallexample
9377 $ @kbd{mt -f /dev/nrtape rewind}
9378 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9379 @end smallexample
9380
9381 @cindex tape marks
9382 @dfn{Tape marks} are special magnetic patterns written on the tape
9383 media, which are later recognizable by the reading hardware. These
9384 marks are used after each file, when there are many on a single tape.
9385 An empty file (that is to say, two tape marks in a row) signal the
9386 logical end of the tape, after which no file exist. Usually,
9387 non-rewinding tape device drivers will react to the close request issued
9388 by @command{tar} by first writing two tape marks after your archive, and by
9389 backspacing over one of these. So, if you remove the tape at that time
9390 from the tape drive, it is properly terminated. But if you write
9391 another file at the current position, the second tape mark will be
9392 erased by the new information, leaving only one tape mark between files.
9393
9394 So, you may now save @var{directory-2} as a second archive after the
9395 first on the same tape by issuing the command:
9396
9397 @smallexample
9398 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9399 @end smallexample
9400
9401 @noindent
9402 and so on for all the archives you want to put on the same tape.
9403
9404 Another usual case is that you do not write all the archives the same
9405 day, and you need to remove and store the tape between two archive
9406 sessions. In general, you must remember how many files are already
9407 saved on your tape. Suppose your tape already has 16 files on it, and
9408 that you are ready to write the 17th. You have to take care of skipping
9409 the first 16 tape marks before saving @var{directory-17}, say, by using
9410 these commands:
9411
9412 @smallexample
9413 $ @kbd{mt -f /dev/nrtape rewind}
9414 $ @kbd{mt -f /dev/nrtape fsf 16}
9415 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9416 @end smallexample
9417
9418 In all the previous examples, we put aside blocking considerations, but
9419 you should do the proper things for that as well. @xref{Blocking}.
9420
9421 @menu
9422 * Tape Positioning:: Tape Positions and Tape Marks
9423 * mt:: The @command{mt} Utility
9424 @end menu
9425
9426 @node Tape Positioning
9427 @subsection Tape Positions and Tape Marks
9428 @UNREVISED
9429
9430 Just as archives can store more than one file from the file system,
9431 tapes can store more than one archive file. To keep track of where
9432 archive files (or any other type of file stored on tape) begin and
9433 end, tape archive devices write magnetic @dfn{tape marks} on the
9434 archive media. Tape drives write one tape mark between files,
9435 two at the end of all the file entries.
9436
9437 If you think of data as a series of records "rrrr"'s, and tape marks as
9438 "*"'s, a tape might look like the following:
9439
9440 @smallexample
9441 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9442 @end smallexample
9443
9444 Tape devices read and write tapes using a read/write @dfn{tape
9445 head}---a physical part of the device which can only access one
9446 point on the tape at a time. When you use @command{tar} to read or
9447 write archive data from a tape device, the device will begin reading
9448 or writing from wherever on the tape the tape head happens to be,
9449 regardless of which archive or what part of the archive the tape
9450 head is on. Before writing an archive, you should make sure that no
9451 data on the tape will be overwritten (unless it is no longer needed).
9452 Before reading an archive, you should make sure the tape head is at
9453 the beginning of the archive you want to read. You can do it manually
9454 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9455 that automatically (@pxref{Scripted Restoration}).
9456
9457 If you want to add new archive file entries to a tape, you should
9458 advance the tape to the end of the existing file entries, backspace
9459 over the last tape mark, and write the new archive file. If you were
9460 to add two archives to the example above, the tape might look like the
9461 following:
9462
9463 @smallexample
9464 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9465 @end smallexample
9466
9467 @node mt
9468 @subsection The @command{mt} Utility
9469 @UNREVISED
9470
9471 @FIXME{Is it true that this only works on non-block devices?
9472 should explain the difference, (fixed or variable).}
9473 @xref{Blocking Factor}.
9474
9475 You can use the @command{mt} utility to advance or rewind a tape past a
9476 specified number of archive files on the tape. This will allow you
9477 to move to the beginning of an archive before extracting or reading
9478 it, or to the end of all the archives before writing a new one.
9479 @FIXME{Why isn't there an "advance 'til you find two tape marks
9480 together"?}
9481
9482 The syntax of the @command{mt} command is:
9483
9484 @smallexample
9485 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9486 @end smallexample
9487
9488 where @var{tapename} is the name of the tape device, @var{number} is
9489 the number of times an operation is performed (with a default of one),
9490 and @var{operation} is one of the following:
9491
9492 @FIXME{is there any use for record operations?}
9493
9494 @table @option
9495 @item eof
9496 @itemx weof
9497 Writes @var{number} tape marks at the current position on the tape.
9498
9499 @item fsf
9500 Moves tape position forward @var{number} files.
9501
9502 @item bsf
9503 Moves tape position back @var{number} files.
9504
9505 @item rewind
9506 Rewinds the tape. (Ignores @var{number}).
9507
9508 @item offline
9509 @itemx rewoff1
9510 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9511
9512 @item status
9513 Prints status information about the tape unit.
9514
9515 @end table
9516
9517 @FIXME{Is there a better way to frob the spacing on the list?}
9518
9519 If you don't specify a @var{tapename}, @command{mt} uses the environment
9520 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9521 the default device specified in your @file{sys/mtio.h} file
9522 (@code{DEFTAPE} variable). If this is not defined, the program will
9523 display a descriptive error message and exit with code 1.
9524
9525 @command{mt} returns a 0 exit status when the operation(s) were
9526 successful, 1 if the command was unrecognized, and 2 if an operation
9527 failed.
9528
9529 @node Using Multiple Tapes
9530 @section Using Multiple Tapes
9531
9532 Often you might want to write a large archive, one larger than will fit
9533 on the actual tape you are using. In such a case, you can run multiple
9534 @command{tar} commands, but this can be inconvenient, particularly if you
9535 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9536 Therefore, @command{tar} provides a special mode for creating
9537 multi-volume archives.
9538
9539 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9540 on several media volumes of fixed size. Although in this section we will
9541 often call @samp{volume} a @dfn{tape}, there is absolutely no
9542 requirement for multi-volume archives to be stored on tapes. Instead,
9543 they can use whatever media type the user finds convenient, they can
9544 even be located on files.
9545
9546 When creating a multi-volume arvhive, @GNUTAR{} continues to fill
9547 current volume until it runs out of space, then it switches to
9548 next volume (usually the operator is queried to replace the tape on
9549 this point), and continues working on the new volume. This operation
9550 continues untill all requested files are dumped. If @GNUTAR{} detects
9551 end of media while dumping a file, such a file is archived in split
9552 form. Some very big files can even be split across several volumes.
9553
9554 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9555 without any special options. Consequently any file member residing
9556 entirely on one volume can be extracted or otherwise operated upon
9557 without needing the other volume. Sure enough, to extract a split
9558 member you would need all volumes its parts reside on.
9559
9560 Multi-volume archives suffer from several limitations. In particular,
9561 they cannot be compressed.
9562
9563 @GNUTAR{} is able to create multi-volume archives of two formats
9564 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9565
9566 @menu
9567 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9568 * Tape Files:: Tape Files
9569 * Tarcat:: Concatenate Volumes into a Single Archive
9570
9571 @end menu
9572
9573 @node Multi-Volume Archives
9574 @subsection Archives Longer than One Tape or Disk
9575 @cindex Multi-volume archives
9576
9577 @opindex multi-volume
9578 To create an archive that is larger than will fit on a single unit of
9579 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9580 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9581 archive can be manipulated like any other archive (provided the
9582 @option{--multi-volume} option is specified), but is stored on more
9583 than one tape or disk.
9584
9585 When you specify @option{--multi-volume}, @command{tar} does not report an
9586 error when it comes to the end of an archive volume (when reading), or
9587 the end of the media (when writing). Instead, it prompts you to load
9588 a new storage volume. If the archive is on a magnetic tape, you
9589 should change tapes when you see the prompt; if the archive is on a
9590 floppy disk, you should change disks; etc.
9591
9592 @table @option
9593 @item --multi-volume
9594 @itemx -M
9595 Creates a multi-volume archive, when used in conjunction with
9596 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9597 archive, specify @option{--multi-volume} in conjunction with that
9598 operation.
9599 For example:
9600
9601 @smallexample
9602 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9603 @end smallexample
9604 @end table
9605
9606 The method @command{tar} uses to detect end of tape is not perfect, and
9607 fails on some operating systems or on some devices. If @command{tar}
9608 cannot detect the end of the tape itself, you can use
9609 @option{--tape-length} option to inform it about the capacity of the
9610 tape:
9611
9612 @anchor{tape-length}
9613 @table @option
9614 @opindex tape-length
9615 @item --tape-length=@var{size}
9616 @itemx -L @var{size}
9617 Set maximum length of a volume. The @var{size} argument should then
9618 be the usable size of the tape in units of 1024 bytes. This option
9619 selects @option{--multi-volume} automatically. For example:
9620
9621 @smallexample
9622 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9623 @end smallexample
9624 @end table
9625
9626 @anchor{change volume prompt}
9627 When @GNUTAR{} comes to the end of a storage media, it asks you to
9628 change the volume. The built-in prompt for POSIX locale
9629 is@footnote{If you run @GNUTAR{} under a different locale, the
9630 translation to the locale's language will be used.}:
9631
9632 @smallexample
9633 Prepare volume #@var{n} for `@var{archive}' and hit return:
9634 @end smallexample
9635
9636 @noindent
9637 where @var{n} is the ordinal number of the volume to be created and
9638 @var{archive} is archive file or device name.
9639
9640 When prompting for a new tape, @command{tar} accepts any of the following
9641 responses:
9642
9643 @table @kbd
9644 @item ?
9645 Request @command{tar} to explain possible responses
9646 @item q
9647 Request @command{tar} to exit immediately.
9648 @item n @var{file-name}
9649 Request @command{tar} to write the next volume on the file @var{file-name}.
9650 @item !
9651 Request @command{tar} to run a subshell. This option can be disabled
9652 by giving @option{--restrict} command line option to
9653 @command{tar}@footnote{@xref{--restrict}, for more information about
9654 this option}.
9655 @item y
9656 Request @command{tar} to begin writing the next volume.
9657 @end table
9658
9659 (You should only type @samp{y} after you have changed the tape;
9660 otherwise @command{tar} will write over the volume it just finished.)
9661
9662 @cindex Volume number file
9663 @cindex volno file
9664 @anchor{volno-file}
9665 @opindex volno-file
9666 The volume number used by @command{tar} in its tape-changing prompt
9667 can be changed; if you give the
9668 @option{--volno-file=@var{file-of-number}} option, then
9669 @var{file-of-number} should be an unexisting file to be created, or
9670 else, a file already containing a decimal number. That number will be
9671 used as the volume number of the first volume written. When
9672 @command{tar} is finished, it will rewrite the file with the
9673 now-current volume number. (This does not change the volume number
9674 written on a tape label, as per @ref{label}, it @emph{only} affects
9675 the number used in the prompt.)
9676
9677 @cindex End-of-archive info script
9678 @cindex Info script
9679 @anchor{info-script}
9680 @opindex info-script
9681 @opindex new-volume-script
9682 If you want more elaborate behavior than this, you can write a special
9683 @dfn{new volume script}, that will be responsible for changing the
9684 volume, and instruct @command{tar} to use it instead of its normal
9685 prompting procedure:
9686
9687 @table @option
9688 @item --info-script=@var{script-name}
9689 @itemx --new-volume-script=@var{script-name}
9690 @itemx -F @var{script-name}
9691 Specify the full name of the volume script to use. The script can be
9692 used to eject cassettes, or to broadcast messages such as
9693 @samp{Someone please come change my tape} when performing unattended
9694 backups.
9695 @end table
9696
9697 The @var{script-name} is executed without any command line
9698 arguments. It inherits @command{tar}'s shell environment.
9699 Additional data is passed to it via the following
9700 environment variables:
9701
9702 @table @env
9703 @vrindex TAR_VERSION, info script environment variable
9704 @item TAR_VERSION
9705 @GNUTAR{} version number.
9706
9707 @vrindex TAR_ARCHIVE, info script environment variable
9708 @item TAR_ARCHIVE
9709 The name of the archive @command{tar} is processing.
9710
9711 @vrindex TAR_VOLUME, info script environment variable
9712 @item TAR_VOLUME
9713 Ordinal number of the volume @command{tar} is about to start.
9714
9715 @vrindex TAR_SUBCOMMAND, info script environment variable
9716 @item TAR_SUBCOMMAND
9717 Short option describing the operation @command{tar} is executing
9718 @xref{Operations}, for a complete list of subcommand options.
9719
9720 @vrindex TAR_FORMAT, info script environment variable
9721 @item TAR_FORMAT
9722 Format of the archive being processed. @xref{Formats}, for a complete
9723 list of archive format names.
9724 @end table
9725
9726 The volume script can instruct @command{tar} to use new archive name,
9727 by writing in to file descriptor 3 (see below for an example).
9728
9729 If the info script fails, @command{tar} exits; otherwise, it begins
9730 writing the next volume.
9731
9732 If you want @command{tar} to cycle through a series of files or tape
9733 drives, there are three approaches to choose from. First of all, you
9734 can give @command{tar} multiple @option{--file} options. In this case
9735 the specified files will be used, in sequence, as the successive
9736 volumes of the archive. Only when the first one in the sequence needs
9737 to be used again will @command{tar} prompt for a tape change (or run
9738 the info script). For example, suppose someone has two tape drives on
9739 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
9740 @GNUTAR{} to switch to the second drive when it needs to write the
9741 second tape, and then back to the first tape, etc., just do either of:
9742
9743 @smallexample
9744 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9745 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9746 @end smallexample
9747
9748 The second method is to use the @samp{n} response to the tape-change
9749 prompt.
9750
9751 Finally, the most flexible approach is to use a volume script, that
9752 writes new archive name to the file descriptor #3. For example, the
9753 following volume script will create a series of archive files, named
9754 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
9755 archive being created (as given by @option{--file} option) and
9756 @var{vol} is the ordinal number of the archive being created:
9757
9758 @smallexample
9759 @group
9760 #! /bin/sh
9761 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9762
9763 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9764 case $TAR_SUBCOMMAND in
9765 -c) ;;
9766 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9767 ;;
9768 *) exit 1
9769 esac
9770
9771 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9772 @end group
9773 @end smallexample
9774
9775 The same script cant be used while listing, comparing or extracting
9776 from the created archive. For example:
9777
9778 @smallexample
9779 @group
9780 # @r{Create a multi-volume archive:}
9781 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
9782 # @r{Extract from the created archive:}
9783 $ @kbd{tar -x -f archive.tar -F new-volume .}
9784 @end group
9785 @end smallexample
9786
9787 @noindent
9788 Notice, that the first command had to use @option{-L} option, since
9789 otherwise @GNUTAR{} will end up writing everything to file
9790 @file{archive.tar}.
9791
9792 You can read each individual volume of a multi-volume archive as if it
9793 were an archive by itself. For example, to list the contents of one
9794 volume, use @option{--list}, without @option{--multi-volume} specified.
9795 To extract an archive member from one volume (assuming it is described
9796 that volume), use @option{--extract}, again without
9797 @option{--multi-volume}.
9798
9799 If an archive member is split across volumes (i.e. its entry begins on
9800 one volume of the media and ends on another), you need to specify
9801 @option{--multi-volume} to extract it successfully. In this case, you
9802 should load the volume where the archive member starts, and use
9803 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9804 volumes as it needs them. @xref{extracting archives}, for more
9805 information about extracting archives.
9806
9807 Multi-volume archives can be modified like any other archive. To add
9808 files to a multi-volume archive, you need to only mount the last
9809 volume of the archive media (and new volumes, if needed). For all
9810 other operations, you need to use the entire archive.
9811
9812 If a multi-volume archive was labeled using
9813 @option{--label=@var{archive-label}} (@pxref{label}) when it was
9814 created, @command{tar} will not automatically label volumes which are
9815 added later. To label subsequent volumes, specify
9816 @option{--label=@var{archive-label}} again in conjunction with the
9817 @option{--append}, @option{--update} or @option{--concatenate} operation.
9818
9819 @FIXME{This is no longer true: Multivolume archives in @samp{POSIX}
9820 format can be extracted using any posix-compliant tar
9821 implementation. The split members can then be recreated from parts
9822 using a simple shell script. Provide more information about it:}
9823 Beware that there is @emph{no} real standard about the proper way, for
9824 a @command{tar} archive, to span volume boundaries. If you have a
9825 multi-volume created by some vendor's @command{tar}, there is almost
9826 no chance you could read all the volumes with @GNUTAR{}.
9827 The converse is also true: you may not expect
9828 multi-volume archives created by @GNUTAR{} to be
9829 fully recovered by vendor's @command{tar}. Since there is little
9830 chance that, in mixed system configurations, some vendor's
9831 @command{tar} will work on another vendor's machine, and there is a
9832 great chance that @GNUTAR{} will work on most of
9833 them, your best bet is to install @GNUTAR{} on all
9834 machines between which you know exchange of files is possible.
9835
9836 @node Tape Files
9837 @subsection Tape Files
9838 @UNREVISED
9839
9840 To give the archive a name which will be recorded in it, use the
9841 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9842 option. This will write a special block identifying
9843 @var{volume-label} as the name of the archive to the front of the
9844 archive which will be displayed when the archive is listed with
9845 @option{--list}. If you are creating a multi-volume archive with
9846 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9847 volume label will have @samp{Volume @var{nnn}} appended to the name
9848 you give, where @var{nnn} is the number of the volume of the archive.
9849 (If you use the @option{--label=@var{volume-label}}) option when
9850 reading an archive, it checks to make sure the label on the tape
9851 matches the one you give. @xref{label}.
9852
9853 When @command{tar} writes an archive to tape, it creates a single
9854 tape file. If multiple archives are written to the same tape, one
9855 after the other, they each get written as separate tape files. When
9856 extracting, it is necessary to position the tape at the right place
9857 before running @command{tar}. To do this, use the @command{mt} command.
9858 For more information on the @command{mt} command and on the organization
9859 of tapes into a sequence of tape files, see @ref{mt}.
9860
9861 People seem to often do:
9862
9863 @smallexample
9864 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9865 @end smallexample
9866
9867 or such, for pushing a common date in all volumes or an archive set.
9868
9869 @node Tarcat
9870 @subsection Concatenate Volumes into a Single Archive
9871
9872 @pindex tarcat
9873 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9874 archive to a single @command{tar} archive. Simply concatenating all
9875 volumes into one will not work, since each volume carries an additional
9876 information at the beginning. @GNUTAR{} is shipped with the shell
9877 script @command{tarcat} designed for this purpose.
9878
9879 The script takes a list of files comprising a multi-volume archive
9880 and creates the resulting archive at the standard output. For example:
9881
9882 @smallexample
9883 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9884 @end smallexample
9885
9886 The script implements a simple heuristics to determine the format of
9887 the first volume file and to decide how to process the rest of the
9888 files. However, it makes no attempt to verify whether the files are
9889 given in order or even if they are valid @command{tar} archives.
9890 It uses @command{dd} and does not filter its standard error, so you
9891 will usually see lots of spurious messages.
9892
9893 @FIXME{The script is not installed. Should we install it?}
9894
9895 @node label
9896 @section Including a Label in the Archive
9897 @cindex Labeling an archive
9898 @cindex Labels on the archive media
9899 @cindex Labeling multi-volume archives
9900 @UNREVISED
9901
9902 @opindex label
9903 To avoid problems caused by misplaced paper labels on the archive
9904 media, you can include a @dfn{label} entry---an archive member which
9905 contains the name of the archive---in the archive itself. Use the
9906 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9907 option in conjunction with the @option{--create} operation to include
9908 a label entry in the archive as it is being created.
9909
9910 @table @option
9911 @item --label=@var{archive-label}
9912 @itemx -V @var{archive-label}
9913 Includes an @dfn{archive-label} at the beginning of the archive when
9914 the archive is being created, when used in conjunction with the
9915 @option{--create} operation. Checks to make sure the archive label
9916 matches the one specified (when used in conjunction with any other
9917 operation.
9918 @end table
9919
9920 If you create an archive using both
9921 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9922 and @option{--multi-volume} (@option{-M}), each volume of the archive
9923 will have an archive label of the form @samp{@var{archive-label}
9924 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9925 next, and so on. @xref{Using Multiple Tapes}, for information on
9926 creating multiple volume archives.
9927
9928 @cindex Volume label, listing
9929 @cindex Listing volume label
9930 The volume label will be displayed by @option{--list} along with
9931 the file contents. If verbose display is requested, it will also be
9932 explicitely marked as in the example below:
9933
9934 @smallexample
9935 @group
9936 $ @kbd{tar --verbose --list --file=iamanarchive}
9937 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9938 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9939 @end group
9940 @end smallexample
9941
9942 @opindex test-label
9943 @anchor{--test-label option}
9944 However, @option{--list} option will cause listing entire
9945 contents of the archive, which may be undesirable (for example, if the
9946 archive is stored on a tape). You can request checking only the volume
9947 by specifying @option{--test-label} option. This option reads only the
9948 first block of an archive, so it can be used with slow storage
9949 devices. For example:
9950
9951 @smallexample
9952 @group
9953 $ @kbd{tar --test-label --file=iamanarchive}
9954 iamalabel
9955 @end group
9956 @end smallexample
9957
9958 If @option{--test-label} is used with a single command line
9959 argument, @command{tar} compares the volume label with the
9960 argument. It exits with code 0 if the two strings match, and with code
9961 2 otherwise. In this case no output is displayed. For example:
9962
9963 @smallexample
9964 @group
9965 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9966 @result{} 0
9967 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9968 @result{} 1
9969 @end group
9970 @end smallexample
9971
9972 If you request any operation, other than @option{--create}, along
9973 with using @option{--label} option, @command{tar} will first check if
9974 the archive label matches the one specified and will refuse to proceed
9975 if it does not. Use this as a safety precaution to avoid accidentally
9976 overwriting existing archives. For example, if you wish to add files
9977 to @file{archive}, presumably labelled with string @samp{My volume},
9978 you will get:
9979
9980 @smallexample
9981 @group
9982 $ @kbd{tar -rf archive --label 'My volume' .}
9983 tar: Archive not labeled to match `My volume'
9984 @end group
9985 @end smallexample
9986
9987 @noindent
9988 in case its label does not match. This will work even if
9989 @file{archive} is not labelled at all.
9990
9991 Similarly, @command{tar} will refuse to list or extract the
9992 archive if its label doesn't match the @var{archive-label}
9993 specified. In those cases, @var{archive-label} argument is interpreted
9994 as a globbing-style pattern which must match the actual magnetic
9995 volume label. @xref{exclude}, for a precise description of how match
9996 is attempted@footnote{Previous versions of @command{tar} used full
9997 regular expression matching, or before that, only exact string
9998 matching, instead of wildcard matchers. We decided for the sake of
9999 simplicity to use a uniform matching device through
10000 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10001 the volume label matcher will also suffix @var{archive-label} by
10002 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10003 up. Since the volume numbering is automatically added in labels at
10004 creation time, it sounded logical to equally help the user taking care
10005 of it when the archive is being read.
10006
10007 The @option{--label} was once called @option{--volume}, but is not
10008 available under that name anymore.
10009
10010 You can also use @option{--label} to get a common information on
10011 all tapes of a series. For having this information different in each
10012 series created through a single script used on a regular basis, just
10013 manage to get some date string as part of the label. For example:
10014
10015 @smallexample
10016 @group
10017 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10018 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10019 --volume="Daily backup for `date +%Y-%m-%d`"}
10020 @end group
10021 @end smallexample
10022
10023 Also note that each label has its own date and time, which corresponds
10024 to when @GNUTAR{} initially attempted to write it,
10025 often soon after the operator launches @command{tar} or types the
10026 carriage return telling that the next tape is ready. Comparing date
10027 labels does give an idea of tape throughput only if the delays for
10028 rewinding tapes and the operator switching them were negligible, which
10029 is usually not the case.
10030
10031 @node verify
10032 @section Verifying Data as It is Stored
10033 @cindex Verifying a write operation
10034 @cindex Double-checking a write operation
10035
10036 @table @option
10037 @item -W
10038 @itemx --verify
10039 @opindex verify, short description
10040 Attempt to verify the archive after writing.
10041 @end table
10042
10043 This option causes @command{tar} to verify the archive after writing it.
10044 Each volume is checked after it is written, and any discrepancies
10045 are recorded on the standard error output.
10046
10047 Verification requires that the archive be on a back-space-able medium.
10048 This means pipes, some cartridge tape drives, and some other devices
10049 cannot be verified.
10050
10051 You can insure the accuracy of an archive by comparing files in the
10052 system with archive members. @command{tar} can compare an archive to the
10053 file system as the archive is being written, to verify a write
10054 operation, or can compare a previously written archive, to insure that
10055 it is up to date.
10056
10057 @xopindex{verify, using with @option{--create}}
10058 @xopindex{create, using with @option{--verify}}
10059 To check for discrepancies in an archive immediately after it is
10060 written, use the @option{--verify} (@option{-W}) option in conjunction with
10061 the @option{--create} operation. When this option is
10062 specified, @command{tar} checks archive members against their counterparts
10063 in the file system, and reports discrepancies on the standard error.
10064
10065 To verify an archive, you must be able to read it from before the end
10066 of the last written entry. This option is useful for detecting data
10067 errors on some tapes. Archives written to pipes, some cartridge tape
10068 drives, and some other devices cannot be verified.
10069
10070 One can explicitly compare an already made archive with the file
10071 system by using the @option{--compare} (@option{--diff}, @option{-d})
10072 option, instead of using the more automatic @option{--verify} option.
10073 @xref{compare}.
10074
10075 Note that these two options have a slightly different intent. The
10076 @option{--compare} option checks how identical are the logical contents of some
10077 archive with what is on your disks, while the @option{--verify} option is
10078 really for checking if the physical contents agree and if the recording
10079 media itself is of dependable quality. So, for the @option{--verify}
10080 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10081 the archive, while it lets the speed optimization undisturbed for the
10082 @option{--compare} option. If you nevertheless use @option{--compare} for
10083 media verification, you may have to defeat the in-memory cache yourself,
10084 maybe by opening and reclosing the door latch of your recording unit,
10085 forcing some doubt in your operating system about the fact this is really
10086 the same volume as the one just written or read.
10087
10088 The @option{--verify} option would not be necessary if drivers were indeed
10089 able to detect dependably all write failures. This sometimes require many
10090 magnetic heads, some able to read after the writes occurred. One would
10091 not say that drivers unable to detect all cases are necessarily flawed,
10092 as long as programming is concerned.
10093
10094 The @option{--verify} (@option{-W}) option will not work in
10095 conjunction with the @option{--multi-volume} (@option{-M}) option or
10096 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10097 and @option{--delete} operations. @xref{Operations}, for more
10098 information on these operations.
10099
10100 Also, since @command{tar} normally strips leading @samp{/} from file
10101 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10102 /tmp/foo.tar /etc} will work as desired only if the working directory is
10103 @file{/}, as @command{tar} uses the archive's relative member names
10104 (e.g., @file{etc/motd}) when verifying the archive.
10105
10106 @node Write Protection
10107 @section Write Protection
10108
10109 Almost all tapes and diskettes, and in a few rare cases, even disks can
10110 be @dfn{write protected}, to protect data on them from being changed.
10111 Once an archive is written, you should write protect the media to prevent
10112 the archive from being accidentally overwritten or deleted. (This will
10113 protect the archive from being changed with a tape or floppy drive---it
10114 will not protect it from magnet fields or other physical hazards).
10115
10116 The write protection device itself is usually an integral part of the
10117 physical media, and can be a two position (write enabled/write
10118 disabled) switch, a notch which can be popped out or covered, a ring
10119 which can be removed from the center of a tape reel, or some other
10120 changeable feature.
10121
10122 @node Changes
10123 @appendix Changes
10124
10125 This appendix lists some important user-visible changes between
10126 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10127 version of this document is available at
10128 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10129 @GNUTAR{} documentation page}.
10130
10131 @table @asis
10132 @item Use of globbing patterns when listing and extracting.
10133
10134 Previous versions of GNU tar assumed shell-style globbing when
10135 extracting from or listing an archive. For example:
10136
10137 @smallexample
10138 $ @kbd{tar xf foo.tar '*.c'}
10139 @end smallexample
10140
10141 would extract all files whose names end in @samp{.c}. This behavior
10142 was not documented and was incompatible with traditional tar
10143 implementations. Therefore, starting from version 1.15.91, GNU tar
10144 no longer uses globbing by default. For example, the above invocation
10145 is now interpreted as a request to extract from the archive the file
10146 named @file{*.c}.
10147
10148 To facilitate transition to the new behavior for those users who got
10149 used to the previous incorrect one, @command{tar} will print a warning
10150 if it finds out that a requested member was not found in the archive
10151 and its name looks like a globbing pattern. For example:
10152
10153 @smallexample
10154 $ @kbd{tar xf foo.tar '*.c'}
10155 tar: Pattern matching characters used in file names. Please,
10156 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10157 tar: suppress this warning.
10158 tar: *.c: Not found in archive
10159 tar: Error exit delayed from previous errors
10160 @end smallexample
10161
10162 To treat member names as globbing patterns, use --wildcards option.
10163 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10164 add this option to your @env{TAR_OPTIONS} variable.
10165
10166 @xref{wildcards}, for the detailed discussion of the use of globbing
10167 patterns by @GNUTAR{}.
10168
10169 @item Use of short option @option{-o}.
10170
10171 Earlier versions of @GNUTAR{} understood @option{-o} command line
10172 option as a synonym for @option{--old-archive}.
10173
10174 @GNUTAR{} starting from version 1.13.90 understands this option as
10175 a synonym for @option{--no-same-owner}. This is compatible with
10176 UNIX98 @command{tar} implementations.
10177
10178 However, to facilitate transition, @option{-o} option retains its
10179 old semantics when it is used with one of archive-creation commands.
10180 Users are encouraged to use @option{--format=oldgnu} instead.
10181
10182 It is especially important, since versions of @acronym{GNU} Automake
10183 up to and including 1.8.4 invoke tar with this option to produce
10184 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10185 of this issue and its implications.
10186
10187 @FIXME{Change the first argument to tar-formats when the new Automake is
10188 out. The proposition to add @anchor{} to the appropriate place of its
10189 docs was accepted by Automake people --Sergey 2006-05-25}.
10190 @xref{Options, tar-v7, Changing Automake's Behavior,
10191 automake, GNU Automake}, for a description on how to use various
10192 archive formats with @command{automake}.
10193
10194 Future versions of @GNUTAR{} will understand @option{-o} only as a
10195 synonym for @option{--no-same-owner}.
10196
10197 @item Use of short option @option{-l}
10198
10199 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10200 synonym for @option{--one-file-system}. Since such usage contradicted
10201 to UNIX98 specification and harmed compatibility with other
10202 implementation, it was declared deprecated in version 1.14. However,
10203 to facilitate transition to its new semantics, it was supported by
10204 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10205 variant of @option{--check-links} was introduced in version 1.15.91.
10206
10207 @item Use of options @option{--portability} and @option{--old-archive}
10208
10209 These options are deprecated. Please use @option{--format=v7} instead.
10210
10211 @item Use of option @option{--posix}
10212
10213 This option is deprecated. Please use @option{--format=posix} instead.
10214 @end table
10215
10216 @node Configuring Help Summary
10217 @appendix Configuring Help Summary
10218
10219 Running @kbd{tar --help} displays the short @command{tar} option
10220 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10221 semantically close options. The options within each group are printed
10222 in the following order: a short option, eventually followed by a list
10223 of corresponding long option names, followed by a short description of
10224 the option. For example, here is an excerpt from the actual @kbd{tar
10225 --help} output:
10226
10227 @verbatim
10228 Main operation mode:
10229
10230 -A, --catenate, --concatenate append tar files to an archive
10231 -c, --create create a new archive
10232 -d, --diff, --compare find differences between archive and
10233 file system
10234 --delete delete from the archive
10235 @end verbatim
10236
10237 @vrindex ARGP_HELP_FMT, environment variable
10238 The exact visual representation of the help output is configurable via
10239 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10240 is a comma-separated list of @dfn{format variable} assignments. There
10241 are two kinds of format variables. An @dfn{offset variable} keeps the
10242 offset of some part of help output text from the leftmost column on
10243 the screen. A @dfn{boolean} variable is a flag that toggles some
10244 output feature on or off. Depending on the type of the corresponding
10245 variable, there are two kinds of assignments:
10246
10247 @table @asis
10248 @item Offset assignment
10249
10250 The assignment to an offset variable has the following syntax:
10251
10252 @smallexample
10253 @var{variable}=@var{value}
10254 @end smallexample
10255
10256 @noindent
10257 where @var{variable} is the variable name, and @var{value} is a
10258 numeric value to be assigned to the variable.
10259
10260 @item Boolean assignment
10261
10262 To assign @code{true} value to a variable, simply put this variable name. To
10263 assign @code{false} value, prefix the variable name with @samp{no-}. For
10264 example:
10265
10266 @smallexample
10267 @group
10268 # Assign @code{true} value:
10269 dup-args
10270 # Assign @code{false} value:
10271 no-dup-args
10272 @end group
10273 @end smallexample
10274 @end table
10275
10276 Following variables are declared:
10277
10278 @deftypevr {Help Output} boolean dup-args
10279 If true, arguments for an option are shown with both short and long
10280 options, even when a given option has both forms, for example:
10281
10282 @smallexample
10283 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10284 @end smallexample
10285
10286 If false, then if an option has both short and long forms, the
10287 argument is only shown with the long one, for example:
10288
10289 @smallexample
10290 -f, --file=ARCHIVE use archive file or device ARCHIVE
10291 @end smallexample
10292
10293 @noindent
10294 and a message indicating that the argument is applicable to both
10295 forms is printed below the options. This message can be disabled
10296 using @code{dup-args-note} (see below).
10297
10298 The default is false.
10299 @end deftypevr
10300
10301 @deftypevr {Help Output} boolean dup-args-note
10302 If this variable is true, which is the default, the following notice
10303 is displayed at the end of the help output:
10304
10305 @quotation
10306 Mandatory or optional arguments to long options are also mandatory or
10307 optional for any corresponding short options.
10308 @end quotation
10309
10310 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10311 variables @code{dup-args} or @code{dup-args-note} should be set.
10312 @end deftypevr
10313
10314 @deftypevr {Help Output} offset short-opt-col
10315 Column in which short options start. Default is 2.
10316
10317 @smallexample
10318 @group
10319 $ @kbd{tar --help|grep ARCHIVE}
10320 -f, --file=ARCHIVE use archive file or device ARCHIVE
10321 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10322 -f, --file=ARCHIVE use archive file or device ARCHIVE
10323 @end group
10324 @end smallexample
10325 @end deftypevr
10326
10327 @deftypevr {Help Output} offset long-opt-col
10328 Column in which long options start. Default is 6. For example:
10329
10330 @smallexample
10331 @group
10332 $ @kbd{tar --help|grep ARCHIVE}
10333 -f, --file=ARCHIVE use archive file or device ARCHIVE
10334 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10335 -f, --file=ARCHIVE use archive file or device ARCHIVE
10336 @end group
10337 @end smallexample
10338 @end deftypevr
10339
10340 @deftypevr {Help Output} offset doc-opt-col
10341 Column in which @dfn{doc options} start. A doc option isn't actually
10342 an option, but rather an arbitrary piece of documentation that is
10343 displayed in much the same manner as the options. For example, in
10344 the description of @option{--format} option:
10345
10346 @smallexample
10347 @group
10348 -H, --format=FORMAT create archive of the given format.
10349
10350 FORMAT is one of the following:
10351
10352 gnu GNU tar 1.13.x format
10353 oldgnu GNU format as per tar <= 1.12
10354 pax POSIX 1003.1-2001 (pax) format
10355 posix same as pax
10356 ustar POSIX 1003.1-1988 (ustar) format
10357 v7 old V7 tar format
10358 @end group
10359 @end smallexample
10360
10361 @noindent
10362 the format names are doc options. Thus, if you set
10363 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10364 will look as follows:
10365
10366 @smallexample
10367 @group
10368 -H, --format=FORMAT create archive of the given format.
10369
10370 FORMAT is one of the following:
10371
10372 gnu GNU tar 1.13.x format
10373 oldgnu GNU format as per tar <= 1.12
10374 pax POSIX 1003.1-2001 (pax) format
10375 posix same as pax
10376 ustar POSIX 1003.1-1988 (ustar) format
10377 v7 old V7 tar format
10378 @end group
10379 @end smallexample
10380 @end deftypevr
10381
10382 @deftypevr {Help Output} offset opt-doc-col
10383 Column in which option description starts. Default is 29.
10384
10385 @smallexample
10386 @group
10387 $ @kbd{tar --help|grep ARCHIVE}
10388 -f, --file=ARCHIVE use archive file or device ARCHIVE
10389 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10390 -f, --file=ARCHIVE use archive file or device ARCHIVE
10391 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10392 -f, --file=ARCHIVE
10393 use archive file or device ARCHIVE
10394 @end group
10395 @end smallexample
10396
10397 @noindent
10398 Notice, that the description starts on a separate line if
10399 @code{opt-doc-col} value is too small.
10400 @end deftypevr
10401
10402 @deftypevr {Help Output} offset header-col
10403 Column in which @dfn{group headers} are printed. A group header is a
10404 descriptive text preceding an option group. For example, in the
10405 following text:
10406
10407 @verbatim
10408 Main operation mode:
10409
10410 -A, --catenate, --concatenate append tar files to
10411 an archive
10412 -c, --create create a new archive
10413 @end verbatim
10414 @noindent
10415 @samp{Main operation mode:} is the group header.
10416
10417 The default value is 1.
10418 @end deftypevr
10419
10420 @deftypevr {Help Output} offset usage-indent
10421 Indentation of wrapped usage lines. Affects @option{--usage}
10422 output. Default is 12.
10423 @end deftypevr
10424
10425 @deftypevr {Help Output} offset rmargin
10426 Right margin of the text output. Used for wrapping.
10427 @end deftypevr
10428
10429 @node Genfile
10430 @appendix Genfile
10431 @include genfile.texi
10432
10433 @node Tar Internals
10434 @appendix Tar Internals
10435 @include intern.texi
10436
10437 @node Free Software Needs Free Documentation
10438 @appendix Free Software Needs Free Documentation
10439 @include freemanuals.texi
10440
10441 @node Copying This Manual
10442 @appendix Copying This Manual
10443
10444 @menu
10445 * GNU Free Documentation License:: License for copying this manual
10446 @end menu
10447
10448 @include fdl.texi
10449
10450 @node Index of Command Line Options
10451 @appendix Index of Command Line Options
10452
10453 This appendix contains an index of all @GNUTAR{} long command line
10454 options. The options are listed without the preceeding double-dash.
10455 For a cross-reference of short command line options, @ref{Short Option Summary}.
10456
10457 @printindex op
10458
10459 @node Index
10460 @appendix Index
10461
10462 @printindex cp
10463
10464 @summarycontents
10465 @contents
10466 @bye
10467
10468 @c Local variables:
10469 @c texinfo-column-for-description: 32
10470 @c End:
This page took 0.512305 seconds and 5 git commands to generate.