]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Update master menu
[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 * Sparse Formats:: Storing Sparse Files
383 * Snapshot Files::
384 * Dumpdir::
385
386 Storing Sparse Files
387
388 * Old GNU Format::
389 * PAX 0:: PAX Format, Versions 0.0 and 0.1
390 * PAX 1:: PAX Format, Version 1.0
391
392 Copying This Manual
393
394 * GNU Free Documentation License:: License for copying this manual
395
396 @end detailmenu
397 @end menu
398
399 @node Introduction
400 @chapter Introduction
401
402 @GNUTAR{} creates
403 and manipulates @dfn{archives} which are actually collections of
404 many other files; the program provides users with an organized and
405 systematic method for controlling a large amount of data.
406 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
407 archives need not (and these days, typically do not) reside on tapes.
408
409 @menu
410 * Book Contents:: What this Book Contains
411 * Definitions:: Some Definitions
412 * What tar Does:: What @command{tar} Does
413 * Naming tar Archives:: How @command{tar} Archives are Named
414 * Authors:: @GNUTAR{} Authors
415 * Reports:: Reporting bugs or suggestions
416 @end menu
417
418 @node Book Contents
419 @section What this Book Contains
420
421 The first part of this chapter introduces you to various terms that will
422 recur throughout the book. It also tells you who has worked on @GNUTAR{}
423 and its documentation, and where you should send bug reports
424 or comments.
425
426 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
427 gentle introduction for people who are new to using @command{tar}. It is
428 meant to be self contained, not requiring any reading from subsequent
429 chapters to make sense. It moves from topic to topic in a logical,
430 progressive order, building on information already explained.
431
432 Although the tutorial is paced and structured to allow beginners to
433 learn how to use @command{tar}, it is not intended solely for beginners.
434 The tutorial explains how to use the three most frequently used
435 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
436 two frequently used options (@samp{file} and @samp{verbose}). The other
437 chapters do not refer to the tutorial frequently; however, if a section
438 discusses something which is a complex variant of a basic concept, there
439 may be a cross reference to that basic concept. (The entire book,
440 including the tutorial, assumes that the reader understands some basic
441 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
442
443 The third chapter presents the remaining five operations, and
444 information about using @command{tar} options and option syntax.
445
446 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
447 than the reality. should think about whether this makes sense to say
448 here, or not.} The other chapters are meant to be used as a
449 reference. Each chapter presents everything that needs to be said
450 about a specific topic.
451
452 One of the chapters (@pxref{Date input formats}) exists in its
453 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
454 In addition, one section of this manual (@pxref{Standard}) contains a
455 big quote which is taken directly from @command{tar} sources.
456
457 In general, we give both long and short (abbreviated) option names
458 at least once in each section where the relevant option is covered, so
459 that novice readers will become familiar with both styles. (A few
460 options have no short versions, and the relevant sections will
461 indicate this.)
462
463 @node Definitions
464 @section Some Definitions
465
466 @cindex archive
467 @cindex tar archive
468 The @command{tar} program is used to create and manipulate @command{tar}
469 archives. An @dfn{archive} is a single file which contains the contents
470 of many files, while still identifying the names of the files, their
471 owner(s), and so forth. (In addition, archives record access
472 permissions, user and group, size in bytes, and data modification time.
473 Some archives also record the file names in each archived directory, as
474 well as other file and directory information.) You can use @command{tar}
475 to @dfn{create} a new archive in a specified directory.
476
477 @cindex member
478 @cindex archive member
479 @cindex file name
480 @cindex member name
481 The files inside an archive are called @dfn{members}. Within this
482 manual, we use the term @dfn{file} to refer only to files accessible in
483 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
484 @dfn{member} to refer only to the members of an archive. Similarly, a
485 @dfn{file name} is the name of a file, as it resides in the file system,
486 and a @dfn{member name} is the name of an archive member within the
487 archive.
488
489 @cindex extraction
490 @cindex unpacking
491 The term @dfn{extraction} refers to the process of copying an archive
492 member (or multiple members) into a file in the file system. Extracting
493 all the members of an archive is often called @dfn{extracting the
494 archive}. The term @dfn{unpack} can also be used to refer to the
495 extraction of many or all the members of an archive. Extracting an
496 archive does not destroy the archive's structure, just as creating an
497 archive does not destroy the copies of the files that exist outside of
498 the archive. You may also @dfn{list} the members in a given archive
499 (this is often thought of as ``printing'' them to the standard output,
500 or the command line), or @dfn{append} members to a pre-existing archive.
501 All of these operations can be performed using @command{tar}.
502
503 @node What tar Does
504 @section What @command{tar} Does
505
506 @cindex tar
507 The @command{tar} program provides the ability to create @command{tar}
508 archives, as well as various other kinds of manipulation. For example,
509 you can use @command{tar} on previously created archives to extract files,
510 to store additional files, or to update or list files which were already
511 stored.
512
513 Initially, @command{tar} archives were used to store files conveniently on
514 magnetic tape. The name @command{tar} comes from this use; it stands for
515 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
516 direct its output to available devices, files, or other programs (using
517 pipes). @command{tar} may even access remote devices or files (as archives).
518
519 You can use @command{tar} archives in many ways. We want to stress a few
520 of them: storage, backup, and transportation.
521
522 @FIXME{the following table entries need a bit of work..}
523 @table @asis
524 @item Storage
525 Often, @command{tar} archives are used to store related files for
526 convenient file transfer over a network. For example, the
527 @acronym{GNU} Project distributes its software bundled into
528 @command{tar} archives, so that all the files relating to a particular
529 program (or set of related programs) can be transferred as a single
530 unit.
531
532 A magnetic tape can store several files in sequence. However, the tape
533 has no names for these files; it only knows their relative position on
534 the tape. One way to store several files on one tape and retain their
535 names is by creating a @command{tar} archive. Even when the basic transfer
536 mechanism can keep track of names, as FTP can, the nuisance of handling
537 multiple files, directories, and multiple links makes @command{tar}
538 archives useful.
539
540 Archive files are also used for long-term storage. You can think of
541 this as transportation from the present into the future. (It is a
542 science-fiction idiom that you can move through time as well as in
543 space; the idea here is that @command{tar} can be used to move archives in
544 all dimensions, even time!)
545
546 @item Backup
547 Because the archive created by @command{tar} is capable of preserving
548 file information and directory structure, @command{tar} is commonly
549 used for performing full and incremental backups of disks. A backup
550 puts a collection of files (possibly pertaining to many users and
551 projects) together on a disk or a tape. This guards against
552 accidental destruction of the information in those files.
553 @GNUTAR{} has special features that allow it to be
554 used to make incremental and full dumps of all the files in a
555 file system.
556
557 @item Transportation
558 You can create an archive on one system, transfer it to another system,
559 and extract the contents there. This allows you to transport a group of
560 files from one system to another.
561 @end table
562
563 @node Naming tar Archives
564 @section How @command{tar} Archives are Named
565
566 Conventionally, @command{tar} archives are given names ending with
567 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
568 but this manual follows that convention in order to accustom readers to
569 it and to make examples more clear.
570
571 @cindex tar file
572 @cindex entry
573 @cindex tar entry
574 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
575 archive members as ``files'' or ``entries''. For people familiar with
576 the operation of @command{tar}, this causes no difficulty. However, in
577 this manual, we consistently refer to ``archives'' and ``archive
578 members'' to make learning to use @command{tar} easier for novice users.
579
580 @node Authors
581 @section @GNUTAR{} Authors
582
583 @GNUTAR{} was originally written by John Gilmore,
584 and modified by many people. The @acronym{GNU} enhancements were
585 written by Jay Fenlason, then Joy Kendall, and the whole package has
586 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
587 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
588 numerous and kind users.
589
590 We wish to stress that @command{tar} is a collective work, and owes much to
591 all those people who reported problems, offered solutions and other
592 insights, or shared their thoughts and suggestions. An impressive, yet
593 partial list of those contributors can be found in the @file{THANKS}
594 file from the @GNUTAR{} distribution.
595
596 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
597 sure i want to spell out the history in this detail, at least not for
598 the printed book. i'm just not sure it needs to be said this way.
599 i'll think about it.}
600
601 @FIXME{History is more important, and surely more interesting, than
602 actual names. Quoting names without history would be meaningless. FP}
603
604 Jay Fenlason put together a draft of a @GNUTAR{}
605 manual, borrowing notes from the original man page from John Gilmore.
606 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
607 Gorin worked on a tutorial and manual for @GNUTAR{}.
608 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
609 taking information from all these sources and merging them. Melissa
610 Weisshaus finally edited and redesigned the book to create version
611 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
612 by the current maintainer, Sergey Poznyakoff.
613
614 For version 1.12, Daniel Hagerty contributed a great deal of technical
615 consulting. In particular, he is the primary author of @ref{Backups}.
616
617 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
618 (see @url{http://savannah.gnu.org/projects/tar}), and
619 active development and maintenance work has started
620 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
621 Poznyakoff and Jeff Bailey.
622
623 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
624
625 @node Reports
626 @section Reporting bugs or suggestions
627
628 @cindex bug reports
629 @cindex reporting bugs
630 If you find problems or have suggestions about this program or manual,
631 please report them to @file{bug-tar@@gnu.org}.
632
633 When reporting a bug, please be sure to include as much detail as
634 possible, in order to reproduce it. @FIXME{Be more specific, I'd
635 like to make this node as detailed as 'Bug reporting' node in Emacs
636 manual}.
637
638 @node Tutorial
639 @chapter Tutorial Introduction to @command{tar}
640
641 This chapter guides you through some basic examples of three @command{tar}
642 operations: @option{--create}, @option{--list}, and @option{--extract}. If
643 you already know how to use some other version of @command{tar}, then you
644 may not need to read this chapter. This chapter omits most complicated
645 details about how @command{tar} works.
646
647 @menu
648 * assumptions::
649 * stylistic conventions::
650 * basic tar options:: Basic @command{tar} Operations and Options
651 * frequent operations::
652 * Two Frequent Options::
653 * create:: How to Create Archives
654 * list:: How to List Archives
655 * extract:: How to Extract Members from an Archive
656 * going further::
657 @end menu
658
659 @node assumptions
660 @section Assumptions this Tutorial Makes
661
662 This chapter is paced to allow beginners to learn about @command{tar}
663 slowly. At the same time, we will try to cover all the basic aspects of
664 these three operations. In order to accomplish both of these tasks, we
665 have made certain assumptions about your knowledge before reading this
666 manual, and the hardware you will be using:
667
668 @itemize @bullet
669 @item
670 Before you start to work through this tutorial, you should understand
671 what the terms ``archive'' and ``archive member'' mean
672 (@pxref{Definitions}). In addition, you should understand something
673 about how Unix-type operating systems work, and you should know how to
674 use some basic utilities. For example, you should know how to create,
675 list, copy, rename, edit, and delete files and directories; how to
676 change between directories; and how to figure out where you are in the
677 file system. You should have some basic understanding of directory
678 structure and how files are named according to which directory they are
679 in. You should understand concepts such as standard output and standard
680 input, what various definitions of the term ``argument'' mean, and the
681 differences between relative and absolute path names. @FIXME{and what
682 else?}
683
684 @item
685 This manual assumes that you are working from your own home directory
686 (unless we state otherwise). In this tutorial, you will create a
687 directory to practice @command{tar} commands in. When we show path names,
688 we will assume that those paths are relative to your home directory.
689 For example, my home directory path is @file{/home/fsf/melissa}. All of
690 my examples are in a subdirectory of the directory named by that path
691 name; the subdirectory is called @file{practice}.
692
693 @item
694 In general, we show examples of archives which exist on (or can be
695 written to, or worked with from) a directory on a hard disk. In most
696 cases, you could write those archives to, or work with them on any other
697 device, such as a tape drive. However, some of the later examples in
698 the tutorial and next chapter will not work on tape drives.
699 Additionally, working with tapes is much more complicated than working
700 with hard disks. For these reasons, the tutorial does not cover working
701 with tape drives. @xref{Media}, for complete information on using
702 @command{tar} archives with tape drives.
703
704 @FIXME{this is a cop out. need to add some simple tape drive info.}
705 @end itemize
706
707 @node stylistic conventions
708 @section Stylistic Conventions
709
710 In the examples, @samp{$} represents a typical shell prompt. It
711 precedes lines you should type; to make this more clear, those lines are
712 shown in @kbd{this font}, as opposed to lines which represent the
713 computer's response; those lines are shown in @code{this font}, or
714 sometimes @samp{like this}.
715
716 @c When we have lines which are too long to be
717 @c displayed in any other way, we will show them like this:
718
719 @node basic tar options
720 @section Basic @command{tar} Operations and Options
721
722 @command{tar} can take a wide variety of arguments which specify and define
723 the actions it will have on the particular set of files or the archive.
724 The main types of arguments to @command{tar} fall into one of two classes:
725 operations, and options.
726
727 Some arguments fall into a class called @dfn{operations}; exactly one of
728 these is both allowed and required for any instance of using @command{tar};
729 you may @emph{not} specify more than one. People sometimes speak of
730 @dfn{operating modes}. You are in a particular operating mode when you
731 have specified the operation which specifies it; there are eight
732 operations in total, and thus there are eight operating modes.
733
734 The other arguments fall into the class known as @dfn{options}. You are
735 not required to specify any options, and you are allowed to specify more
736 than one at a time (depending on the way you are using @command{tar} at
737 that time). Some options are used so frequently, and are so useful for
738 helping you type commands more carefully that they are effectively
739 ``required''. We will discuss them in this chapter.
740
741 You can write most of the @command{tar} operations and options in any
742 of three forms: long (mnemonic) form, short form, and old style. Some
743 of the operations and options have no short or ``old'' forms; however,
744 the operations and options which we will cover in this tutorial have
745 corresponding abbreviations. @FIXME{make sure this is still the case,
746 at the end}We will indicate those abbreviations appropriately to get
747 you used to seeing them. (Note that the ``old style'' option forms
748 exist in @GNUTAR{} for compatibility with Unix
749 @command{tar}. In this book we present a full discussion of this way
750 of writing options and operations (@pxref{Old Options}), and we discuss
751 the other two styles of writing options (@xref{Long Options}, and
752 @pxref{Short Options}).
753
754 In the examples and in the text of this tutorial, we usually use the
755 long forms of operations and options; but the ``short'' forms produce
756 the same result and can make typing long @command{tar} commands easier.
757 For example, instead of typing
758
759 @smallexample
760 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
761 @end smallexample
762
763 @noindent
764 you can type
765 @smallexample
766 @kbd{tar -c -v -f afiles.tar apple angst aspic}
767 @end smallexample
768
769 @noindent
770 or even
771 @smallexample
772 @kbd{tar -cvf afiles.tar apple angst aspic}
773 @end smallexample
774
775 @noindent
776 For more information on option syntax, see @ref{Advanced tar}. In
777 discussions in the text, when we name an option by its long form, we
778 also give the corresponding short option in parentheses.
779
780 The term, ``option'', can be confusing at times, since ``operations''
781 are often lumped in with the actual, @emph{optional} ``options'' in certain
782 general class statements. For example, we just talked about ``short and
783 long forms of options and operations''. However, experienced @command{tar}
784 users often refer to these by shorthand terms such as, ``short and long
785 options''. This term assumes that the ``operations'' are included, also.
786 Context will help you determine which definition of ``options'' to use.
787
788 Similarly, the term ``command'' can be confusing, as it is often used in
789 two different ways. People sometimes refer to @command{tar} ``commands''.
790 A @command{tar} @dfn{command} is the entire command line of user input
791 which tells @command{tar} what to do --- including the operation, options,
792 and any arguments (file names, pipes, other commands, etc). However,
793 you will also sometimes hear the term ``the @command{tar} command''. When
794 the word ``command'' is used specifically like this, a person is usually
795 referring to the @command{tar} @emph{operation}, not the whole line.
796 Again, use context to figure out which of the meanings the speaker
797 intends.
798
799 @node frequent operations
800 @section The Three Most Frequently Used Operations
801
802 Here are the three most frequently used operations (both short and long
803 forms), as well as a brief description of their meanings. The rest of
804 this chapter will cover how to use these operations in detail. We will
805 present the rest of the operations in the next chapter.
806
807 @table @option
808 @item --create
809 @itemx -c
810 Create a new @command{tar} archive.
811 @item --list
812 @itemx -t
813 List the contents of an archive.
814 @item --extract
815 @itemx -x
816 Extract one or more members from an archive.
817 @end table
818
819 @node Two Frequent Options
820 @section Two Frequently Used Options
821
822 To understand how to run @command{tar} in the three operating modes listed
823 previously, you also need to understand how to use two of the options to
824 @command{tar}: @option{--file} (which takes an archive file as an argument)
825 and @option{--verbose}. (You are usually not @emph{required} to specify
826 either of these options when you run @command{tar}, but they can be very
827 useful in making things more clear and helping you avoid errors.)
828
829 @menu
830 * file tutorial::
831 * verbose tutorial::
832 * help tutorial::
833 @end menu
834
835 @node file tutorial
836 @unnumberedsubsec The @option{--file} Option
837
838 @table @option
839 @xopindex{file, tutorial}
840 @item --file=@var{archive-name}
841 @itemx -f @var{archive-name}
842 Specify the name of an archive file.
843 @end table
844
845 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
846 use @command{tar}; this option determines the name of the archive file
847 that @command{tar} will work on.
848
849 @vrindex TAPE
850 If you don't specify this argument, then @command{tar} will examine
851 the environment variable @env{TAPE}. If it is set, its value will be
852 used as the archive name. Otherwise, @command{tar} will use the
853 default archive, determined at the compile time. Usually it is
854 standard output or some physical tape drive attached to your machine
855 (you can verify what the default is by running @kbd{tar
856 --show-defaults}, @pxref{defaults}). If there is no tape drive
857 attached, or the default is not meaningful, then @command{tar} will
858 print an error message. The error message might look roughly like one
859 of the following:
860
861 @smallexample
862 tar: can't open /dev/rmt8 : No such device or address
863 tar: can't open /dev/rsmt0 : I/O error
864 @end smallexample
865
866 @noindent
867 To avoid confusion, we recommend that you always specify an archive file
868 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
869 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
870 @ref{file}.
871
872 @node verbose tutorial
873 @unnumberedsubsec The @option{--verbose} Option
874
875 @table @option
876 @xopindex{verbose, introduced}
877 @item --verbose
878 @itemx -v
879 Show the files being worked on as @command{tar} is running.
880 @end table
881
882 @option{--verbose} (@option{-v}) shows details about the results of running
883 @command{tar}. This can be especially useful when the results might not be
884 obvious. For example, if you want to see the progress of @command{tar} as
885 it writes files into the archive, you can use the @option{--verbose}
886 option. In the beginning, you may find it useful to use
887 @option{--verbose} at all times; when you are more accustomed to
888 @command{tar}, you will likely want to use it at certain times but not at
889 others. We will use @option{--verbose} at times to help make something
890 clear, and we will give many examples both using and not using
891 @option{--verbose} to show the differences.
892
893 Each instance of @option{--verbose} on the command line increases the
894 verbosity level by one, so if you need more details on the output,
895 specify it twice.
896
897 When reading archives (@option{--list}, @option{--extract},
898 @option{--diff}), @command{tar} by default prints only the names of
899 the members being extracted. Using @option{--verbose} will show a full,
900 @command{ls} style member listing.
901
902 In contrast, when writing archives (@option{--create}, @option{--append},
903 @option{--update}), @command{tar} does not print file names by
904 default. So, a single @option{--verbose} option shows the file names
905 being added to the archive, while two @option{--verbose} options
906 enable the full listing.
907
908 For example, to create an archive in verbose mode:
909
910 @smallexample
911 $ @kbd{tar -cvf afiles.tar apple angst aspic}
912 apple
913 angst
914 aspic
915 @end smallexample
916
917 @noindent
918 Creating the same archive with the verbosity level 2 could give:
919
920 @smallexample
921 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
922 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
923 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
924 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
925 @end smallexample
926
927 @noindent
928 This works equally well using short or long forms of options. Using
929 long forms, you would simply write out the mnemonic form of the option
930 twice, like this:
931
932 @smallexample
933 $ @kbd{tar --create --verbose --verbose @dots{}}
934 @end smallexample
935
936 @noindent
937 Note that you must double the hyphens properly each time.
938
939 Later in the tutorial, we will give examples using @w{@option{--verbose
940 --verbose}}.
941
942 @anchor{verbose member listing}
943 The full output consists of six fields:
944
945 @itemize @bullet
946 @item File type and permissions in symbolic form.
947 These are displayed in the same format as the first column of
948 @command{ls -l} output (@pxref{What information is listed,
949 format=verbose, Verbose listing, fileutils, GNU file utilities}).
950
951 @item Owner name and group separated by a slash character.
952 If these data are not available (for example, when listing a @samp{v7} format
953 archive), numeric ID values are printed instead.
954
955 @item Size of the file, in bytes.
956
957 @item File modification date in ISO 8601 format.
958
959 @item File modification time.
960
961 @item File name.
962 If the name contains any special characters (white space, newlines,
963 etc.) these are displayed in an unambiguous form using so called
964 @dfn{quoting style}. For the detailed discussion of available styles
965 and on how to use them, see @ref{quoting styles}.
966
967 Depending on the file type, the name can be followed by some
968 additional information, described in the following table:
969
970 @table @samp
971 @item -> @var{link-name}
972 The file or archive member is a @dfn{symbolic link} and
973 @var{link-name} is the name of file it links to.
974
975 @item link to @var{link-name}
976 The file or archive member is a @dfn{hard link} and @var{link-name} is
977 the name of file it links to.
978
979 @item --Long Link--
980 The archive member is an old GNU format long link. You will normally
981 not encounter this.
982
983 @item --Long Name--
984 The archive member is an old GNU format long name. You will normally
985 not encounter this.
986
987 @item --Volume Header--
988 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
989
990 @item --Continued at byte @var{n}--
991 Encountered only at the beginning of a multy-volume archive
992 (@pxref{Using Multiple Tapes}). This archive member is a continuation
993 from the previous volume. The number @var{n} gives the offset where
994 the original file was split.
995
996 @item --Mangled file names--
997 This archive member contains @dfn{mangled file names} declarations,
998 a special member type that was used by early versions of @GNUTAR{}.
999 You probably will never encounter this, unless you are reading a very
1000 old archive.
1001
1002 @item unknown file type @var{c}
1003 An archive member of unknown type. @var{c} is the type character from
1004 the archive header. If you encounter such a message, it means that
1005 either your archive contains proprietary member types @GNUTAR{} is not
1006 able to handle, or the archive is corrupted.
1007 @end table
1008
1009 @end itemize
1010
1011 For example, here is an archive listing containing most of the special
1012 suffixes explained above:
1013
1014 @smallexample
1015 @group
1016 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1017 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1018 byte 32456--
1019 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1020 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1021 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1022 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1023 @end group
1024 @end smallexample
1025
1026 @smallexample
1027 @end smallexample
1028
1029 @node help tutorial
1030 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1031
1032 @table @option
1033 @opindex help
1034 @item --help
1035
1036 The @option{--help} option to @command{tar} prints out a very brief list of
1037 all operations and option available for the current version of
1038 @command{tar} available on your system.
1039 @end table
1040
1041 @node create
1042 @section How to Create Archives
1043 @UNREVISED
1044
1045 @cindex Creation of the archive
1046 @cindex Archive, creation of
1047 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1048 you use to create a @command{tar} archive. We will explain
1049 @option{--create} first because, in order to learn about the other
1050 operations, you will find it useful to have an archive available to
1051 practice on.
1052
1053 To make this easier, in this section you will first create a directory
1054 containing three files. Then, we will show you how to create an
1055 @emph{archive} (inside the new directory). Both the directory, and
1056 the archive are specifically for you to practice on. The rest of this
1057 chapter and the next chapter will show many examples using this
1058 directory and the files you will create: some of those files may be
1059 other directories and other archives.
1060
1061 The three files you will archive in this example are called
1062 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1063 @file{collection.tar}.
1064
1065 This section will proceed slowly, detailing how to use @option{--create}
1066 in @code{verbose} mode, and showing examples using both short and long
1067 forms. In the rest of the tutorial, and in the examples in the next
1068 chapter, we will proceed at a slightly quicker pace. This section
1069 moves more slowly to allow beginning users to understand how
1070 @command{tar} works.
1071
1072 @menu
1073 * prepare for examples::
1074 * Creating the archive::
1075 * create verbose::
1076 * short create::
1077 * create dir::
1078 @end menu
1079
1080 @node prepare for examples
1081 @subsection Preparing a Practice Directory for Examples
1082
1083 To follow along with this and future examples, create a new directory
1084 called @file{practice} containing files called @file{blues}, @file{folk}
1085 and @file{jazz}. The files can contain any information you like:
1086 ideally, they should contain information which relates to their names,
1087 and be of different lengths. Our examples assume that @file{practice}
1088 is a subdirectory of your home directory.
1089
1090 Now @command{cd} to the directory named @file{practice}; @file{practice}
1091 is now your @dfn{working directory}. (@emph{Please note}: Although
1092 the full path name of this directory is
1093 @file{/@var{homedir}/practice}, in our examples we will refer to
1094 this directory as @file{practice}; the @var{homedir} is presumed.
1095
1096 In general, you should check that the files to be archived exist where
1097 you think they do (in the working directory) by running @command{ls}.
1098 Because you just created the directory and the files and have changed to
1099 that directory, you probably don't need to do that this time.
1100
1101 It is very important to make sure there isn't already a file in the
1102 working directory with the archive name you intend to use (in this case,
1103 @samp{collection.tar}), or that you don't care about its contents.
1104 Whenever you use @samp{create}, @command{tar} will erase the current
1105 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1106 will not tell you if you are about to overwrite an archive unless you
1107 specify an option which does this (@pxref{backup}, for the
1108 information on how to do so). To add files to an existing archive,
1109 you need to use a different option, such as @option{--append} (@option{-r}); see
1110 @ref{append} for information on how to do this.
1111
1112 @node Creating the archive
1113 @subsection Creating the Archive
1114
1115 @xopindex{create, introduced}
1116 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1117 archive named @file{collection.tar}, use the following command:
1118
1119 @smallexample
1120 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1121 @end smallexample
1122
1123 The order of the arguments is not very important, @emph{when using long
1124 option forms}. You could also say:
1125
1126 @smallexample
1127 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1128 @end smallexample
1129
1130 @noindent
1131 However, you can see that this order is harder to understand; this is
1132 why we will list the arguments in the order that makes the commands
1133 easiest to understand (and we encourage you to do the same when you use
1134 @command{tar}, to avoid errors).
1135
1136 Note that the sequence
1137 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1138 If you substituted any other string of characters for
1139 @kbd{collection.tar}, then that string would become the name of the
1140 archive file you create.
1141
1142 The order of the options becomes more important when you begin to use
1143 short forms. With short forms, if you type commands in the wrong order
1144 (even if you type them correctly in all other ways), you may end up with
1145 results you don't expect. For this reason, it is a good idea to get
1146 into the habit of typing options in the order that makes inherent sense.
1147 @xref{short create}, for more information on this.
1148
1149 In this example, you type the command as shown above: @option{--create}
1150 is the operation which creates the new archive
1151 (@file{collection.tar}), and @option{--file} is the option which lets
1152 you give it the name you chose. The files, @file{blues}, @file{folk},
1153 and @file{jazz}, are now members of the archive, @file{collection.tar}
1154 (they are @dfn{file name arguments} to the @option{--create} operation.
1155 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1156 in the archive, they are called @emph{archive members}, not files.
1157 (@pxref{Definitions,members}).
1158
1159 When you create an archive, you @emph{must} specify which files you
1160 want placed in the archive. If you do not specify any archive
1161 members, @GNUTAR{} will complain.
1162
1163 If you now list the contents of the working directory (@command{ls}), you will
1164 find the archive file listed as well as the files you saw previously:
1165
1166 @smallexample
1167 blues folk jazz collection.tar
1168 @end smallexample
1169
1170 @noindent
1171 Creating the archive @samp{collection.tar} did not destroy the copies of
1172 the files in the directory.
1173
1174 Keep in mind that if you don't indicate an operation, @command{tar} will not
1175 run and will prompt you for one. If you don't name any files, @command{tar}
1176 will complain. You must have write access to the working directory,
1177 or else you will not be able to create an archive in that directory.
1178
1179 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1180 an existing archive; it will delete the archive and write a new one.
1181 Use @option{--append} (@option{-r}) instead. @xref{append}.
1182
1183 @node create verbose
1184 @subsection Running @option{--create} with @option{--verbose}
1185
1186 @xopindex{create, using with @option{--verbose}}
1187 @xopindex{verbose, using with @option{--create}}
1188 If you include the @option{--verbose} (@option{-v}) option on the command line,
1189 @command{tar} will list the files it is acting on as it is working. In
1190 verbose mode, the @code{create} example above would appear as:
1191
1192 @smallexample
1193 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1194 blues
1195 folk
1196 jazz
1197 @end smallexample
1198
1199 This example is just like the example we showed which did not use
1200 @option{--verbose}, except that @command{tar} generated the remaining lines
1201 @iftex
1202 (note the different font styles).
1203 @end iftex
1204 @ifinfo
1205 .
1206 @end ifinfo
1207
1208 In the rest of the examples in this chapter, we will frequently use
1209 @code{verbose} mode so we can show actions or @command{tar} responses that
1210 you would otherwise not see, and which are important for you to
1211 understand.
1212
1213 @node short create
1214 @subsection Short Forms with @samp{create}
1215
1216 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1217 basic uses of @command{tar}, and you will use it countless times.
1218 Eventually, you will probably want to use abbreviated (or ``short'')
1219 forms of options. A full discussion of the three different forms that
1220 options can take appears in @ref{Styles}; for now, here is what the
1221 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1222 using short option forms:
1223
1224 @smallexample
1225 $ @kbd{tar -cvf collection.tar blues folk jazz}
1226 blues
1227 folk
1228 jazz
1229 @end smallexample
1230
1231 @noindent
1232 As you can see, the system responds the same no matter whether you use
1233 long or short option forms.
1234
1235 @FIXME{i don't like how this is worded:} One difference between using
1236 short and long option forms is that, although the exact placement of
1237 arguments following options is no more specific when using short forms,
1238 it is easier to become confused and make a mistake when using short
1239 forms. For example, suppose you attempted the above example in the
1240 following way:
1241
1242 @smallexample
1243 $ @kbd{tar -cfv collection.tar blues folk jazz}
1244 @end smallexample
1245
1246 @noindent
1247 In this case, @command{tar} will make an archive file called @file{v},
1248 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1249 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1250 is thus taken to be the chosen archive file name. @command{tar} will try
1251 to add a file called @file{collection.tar} to the @file{v} archive file;
1252 if the file @file{collection.tar} did not already exist, @command{tar} will
1253 report an error indicating that this file does not exist. If the file
1254 @file{collection.tar} does already exist (e.g., from a previous command
1255 you may have run), then @command{tar} will add this file to the archive.
1256 Because the @option{-v} option did not get registered, @command{tar} will not
1257 run under @samp{verbose} mode, and will not report its progress.
1258
1259 The end result is that you may be quite confused about what happened,
1260 and possibly overwrite a file. To illustrate this further, we will show
1261 you how an example we showed previously would look using short forms.
1262
1263 This example,
1264
1265 @smallexample
1266 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1267 @end smallexample
1268
1269 @noindent
1270 is confusing as it is. When shown using short forms, however, it
1271 becomes much more so:
1272
1273 @smallexample
1274 $ @kbd{tar blues -c folk -f collection.tar jazz}
1275 @end smallexample
1276
1277 @noindent
1278 It would be very easy to put the wrong string of characters
1279 immediately following the @option{-f}, but doing that could sacrifice
1280 valuable data.
1281
1282 For this reason, we recommend that you pay very careful attention to
1283 the order of options and placement of file and archive names,
1284 especially when using short option forms. Not having the option name
1285 written out mnemonically can affect how well you remember which option
1286 does what, and therefore where different names have to be placed.
1287
1288 @node create dir
1289 @subsection Archiving Directories
1290
1291 @cindex Archiving Directories
1292 @cindex Directories, Archiving
1293 You can archive a directory by specifying its directory name as a
1294 file name argument to @command{tar}. The files in the directory will be
1295 archived relative to the working directory, and the directory will be
1296 re-created along with its contents when the archive is extracted.
1297
1298 To archive a directory, first move to its superior directory. If you
1299 have followed the previous instructions in this tutorial, you should
1300 type:
1301
1302 @smallexample
1303 $ @kbd{cd ..}
1304 $
1305 @end smallexample
1306
1307 @noindent
1308 This will put you into the directory which contains @file{practice},
1309 i.e., your home directory. Once in the superior directory, you can
1310 specify the subdirectory, @file{practice}, as a file name argument. To
1311 store @file{practice} in the new archive file @file{music.tar}, type:
1312
1313 @smallexample
1314 $ @kbd{tar --create --verbose --file=music.tar practice}
1315 @end smallexample
1316
1317 @noindent
1318 @command{tar} should output:
1319
1320 @smallexample
1321 practice/
1322 practice/blues
1323 practice/folk
1324 practice/jazz
1325 practice/collection.tar
1326 @end smallexample
1327
1328 Note that the archive thus created is not in the subdirectory
1329 @file{practice}, but rather in the current working directory---the
1330 directory from which @command{tar} was invoked. Before trying to archive a
1331 directory from its superior directory, you should make sure you have
1332 write access to the superior directory itself, not only the directory
1333 you are trying archive with @command{tar}. For example, you will probably
1334 not be able to store your home directory in an archive by invoking
1335 @command{tar} from the root directory; @xref{absolute}. (Note
1336 also that @file{collection.tar}, the original archive file, has itself
1337 been archived. @command{tar} will accept any file as a file to be
1338 archived, regardless of its content. When @file{music.tar} is
1339 extracted, the archive file @file{collection.tar} will be re-written
1340 into the file system).
1341
1342 If you give @command{tar} a command such as
1343
1344 @smallexample
1345 $ @kbd{tar --create --file=foo.tar .}
1346 @end smallexample
1347
1348 @noindent
1349 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1350 dumped}. This happens because @command{tar} creates the archive
1351 @file{foo.tar} in the current directory before putting any files into
1352 it. Then, when @command{tar} attempts to add all the files in the
1353 directory @file{.} to the archive, it notices that the file
1354 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1355 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1356 will continue in this case, and create the archive
1357 normally, except for the exclusion of that one file. (@emph{Please
1358 note:} Other implementations of @command{tar} may not be so clever;
1359 they will enter an infinite loop when this happens, so you should not
1360 depend on this behavior unless you are certain you are running
1361 @GNUTAR{}. In general, it is wise to always place the archive outside
1362 of the directory being dumped.
1363
1364 @node list
1365 @section How to List Archives
1366
1367 @opindex list
1368 Frequently, you will find yourself wanting to determine exactly what a
1369 particular archive contains. You can use the @option{--list}
1370 (@option{-t}) operation to get the member names as they currently
1371 appear in the archive, as well as various attributes of the files at
1372 the time they were archived. For example, you can examine the archive
1373 @file{collection.tar} that you created in the last section with the
1374 command,
1375
1376 @smallexample
1377 $ @kbd{tar --list --file=collection.tar}
1378 @end smallexample
1379
1380 @noindent
1381 The output of @command{tar} would then be:
1382
1383 @smallexample
1384 blues
1385 folk
1386 jazz
1387 @end smallexample
1388
1389 @noindent
1390 The archive @file{bfiles.tar} would list as follows:
1391
1392 @smallexample
1393 ./birds
1394 baboon
1395 ./box
1396 @end smallexample
1397
1398 @noindent
1399 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1400 @var{archive-name}}) option just as with @option{--create}
1401 (@option{-c}) to specify the name of the archive.
1402
1403 @xopindex{list, using with @option{--verbose}}
1404 @xopindex{verbose, using with @option{--list}}
1405 If you use the @option{--verbose} (@option{-v}) option with
1406 @option{--list}, then @command{tar} will print out a listing
1407 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1408 forth. This output is described in detail in @ref{verbose member listing}.
1409
1410 If you had used @option{--verbose} (@option{-v}) mode, the example
1411 above would look like:
1412
1413 @smallexample
1414 $ @kbd{tar --list --verbose --file=collection.tar folk}
1415 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1416 @end smallexample
1417
1418 @cindex listing member and file names
1419 @anchor{listing member and file names}
1420 It is important to notice that the output of @kbd{tar --list
1421 --verbose} does not necessarily match that produced by @kbd{tar
1422 --create --verbose} while creating the archive. It is because
1423 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1424 prefixes from file names before storing them in the archive
1425 (@xref{absolute}, for more information). In other
1426 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1427 an archive and @dfn{member names} when listing it. Consider this
1428 example:
1429
1430 @smallexample
1431 @group
1432 $ @kbd{tar cfv archive /etc/mail}
1433 tar: Removing leading `/' from member names
1434 /etc/mail/
1435 /etc/mail/sendmail.cf
1436 /etc/mail/aliases
1437 $ @kbd{tar tf archive}
1438 etc/mail/
1439 etc/mail/sendmail.cf
1440 etc/mail/aliases
1441 @end group
1442 @end smallexample
1443
1444 @opindex show-stored-names
1445 This default behavior can sometimes be inconvenient. You can force
1446 @GNUTAR{} show member names when creating archive by supplying
1447 @option{--show-stored-names} option.
1448
1449 @table @option
1450 @item --show-stored-names
1451 Print member (as opposed to @emph{file}) names when creating the archive.
1452 @end table
1453
1454 @cindex File name arguments, using @option{--list} with
1455 @xopindex{list, using with file name arguments}
1456 You can specify one or more individual member names as arguments when
1457 using @samp{list}. In this case, @command{tar} will only list the
1458 names of members you identify. For example, @w{@kbd{tar --list
1459 --file=afiles.tar apple}} would only print @file{apple}.
1460
1461 Because @command{tar} preserves paths, file names must be specified as
1462 they appear in the archive (i.e., relative to the directory from which
1463 the archive was created). Therefore, it is essential when specifying
1464 member names to @command{tar} that you give the exact member names.
1465 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1466 error message something like @samp{tar: birds: Not found in archive},
1467 because there is no member named @file{birds}, only one named
1468 @file{./birds}. While the names @file{birds} and @file{./birds} name
1469 the same file, @emph{member} names by default are compared verbatim.
1470
1471 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1472 with @file{baboon}, because this exact member name is in the archive file
1473 @file{bfiles.tar}. If you are not sure of the exact file name,
1474 use @dfn{globbing patterns}, for example:
1475
1476 @smallexample
1477 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1478 @end smallexample
1479
1480 @noindent
1481 will list all members whose name contains @samp{b}. @xref{wildcards},
1482 for a detailed discussion of globbing patterns and related
1483 @command{tar} command line options.
1484
1485 @menu
1486 * list dir::
1487 @end menu
1488
1489 @node list dir
1490 @unnumberedsubsec Listing the Contents of a Stored Directory
1491
1492 To get information about the contents of an archived directory,
1493 use the directory name as a file name argument in conjunction with
1494 @option{--list} (@option{-t}). To find out file attributes, include the
1495 @option{--verbose} (@option{-v}) option.
1496
1497 For example, to find out about files in the directory @file{practice}, in
1498 the archive file @file{music.tar}, type:
1499
1500 @smallexample
1501 $ @kbd{tar --list --verbose --file=music.tar practice}
1502 @end smallexample
1503
1504 @command{tar} responds:
1505
1506 @smallexample
1507 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1508 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1509 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1510 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1511 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1512 @end smallexample
1513
1514 When you use a directory name as a file name argument, @command{tar} acts on
1515 all the files (including sub-directories) in that directory.
1516
1517 @node extract
1518 @section How to Extract Members from an Archive
1519 @UNREVISED
1520 @cindex Extraction
1521 @cindex Retrieving files from an archive
1522 @cindex Resurrecting files from an archive
1523
1524 @opindex extract
1525 Creating an archive is only half the job---there is no point in storing
1526 files in an archive if you can't retrieve them. The act of retrieving
1527 members from an archive so they can be used and manipulated as
1528 unarchived files again is called @dfn{extraction}. To extract files
1529 from an archive, use the @option{--extract} (@option{--get} or
1530 @option{-x}) operation. As with @option{--create}, specify the name
1531 of the archive with @option{--file} (@option{-f}) option. Extracting
1532 an archive does not modify the archive in any way; you can extract it
1533 multiple times if you want or need to.
1534
1535 Using @option{--extract}, you can extract an entire archive, or specific
1536 files. The files can be directories containing other files, or not. As
1537 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1538 long form of the operation without affecting the performance.
1539
1540 @menu
1541 * extracting archives::
1542 * extracting files::
1543 * extract dir::
1544 * extracting untrusted archives::
1545 * failing commands::
1546 @end menu
1547
1548 @node extracting archives
1549 @subsection Extracting an Entire Archive
1550
1551 To extract an entire archive, specify the archive file name only, with
1552 no individual file names as arguments. For example,
1553
1554 @smallexample
1555 $ @kbd{tar -xvf collection.tar}
1556 @end smallexample
1557
1558 @noindent
1559 produces this:
1560
1561 @smallexample
1562 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1563 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1564 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1565 @end smallexample
1566
1567 @node extracting files
1568 @subsection Extracting Specific Files
1569
1570 To extract specific archive members, give their exact member names as
1571 arguments, as printed by @option{--list} (@option{-t}). If you had
1572 mistakenly deleted one of the files you had placed in the archive
1573 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1574 from the archive without changing the archive's structure. Its
1575 contents will be identical to the original file @file{blues} that you
1576 deleted.
1577
1578 First, make sure you are in the @file{practice} directory, and list the
1579 files in the directory. Now, delete the file, @samp{blues}, and list
1580 the files in the directory again.
1581
1582 You can now extract the member @file{blues} from the archive file
1583 @file{collection.tar} like this:
1584
1585 @smallexample
1586 $ @kbd{tar --extract --file=collection.tar blues}
1587 @end smallexample
1588
1589 @noindent
1590 If you list the files in the directory again, you will see that the file
1591 @file{blues} has been restored, with its original permissions, data
1592 modification times, and owner.@footnote{This is only accidentally
1593 true, but not in general. Whereas modification times are always
1594 restored, in most cases, one has to be root for restoring the owner,
1595 and use a special option for restoring permissions. Here, it just
1596 happens that the restoring user is also the owner of the archived
1597 members, and that the current @code{umask} is compatible with original
1598 permissions.} (These parameters will be identical to those which
1599 the file had when you originally placed it in the archive; any changes
1600 you may have made before deleting the file from the file system,
1601 however, will @emph{not} have been made to the archive member.) The
1602 archive file, @samp{collection.tar}, is the same as it was before you
1603 extracted @samp{blues}. You can confirm this by running @command{tar} with
1604 @option{--list} (@option{-t}).
1605
1606 Remember that as with other operations, specifying the exact member
1607 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1608 will fail, because there is no member named @file{birds}. To extract
1609 the member named @file{./birds}, you must specify @w{@kbd{tar
1610 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1611 exact member names, use @option{--list} (@option{-t}) option
1612 (@pxref{list}). You can also extract those members that match a
1613 specific @dfn{globbing pattern}. For example, to extract from
1614 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1615 directory prefix, you could type:
1616
1617 @smallexample
1618 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1619 @end smallexample
1620
1621 @noindent
1622 Here, @option{--wildcards} instructs @command{tar} to treat
1623 command line arguments as globbing patterns and @option{--no-anchored}
1624 informs it that the patterns apply to member names after any @samp{/}
1625 delimiter. The use of globbing patterns is discussed in detail in
1626 @xref{wildcards}.
1627
1628 You can extract a file to standard output by combining the above options
1629 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1630 Output}).
1631
1632 If you give the @option{--verbose} option, then @option{--extract}
1633 will print the names of the archive members as it extracts them.
1634
1635 @node extract dir
1636 @subsection Extracting Files that are Directories
1637
1638 Extracting directories which are members of an archive is similar to
1639 extracting other files. The main difference to be aware of is that if
1640 the extracted directory has the same name as any directory already in
1641 the working directory, then files in the extracted directory will be
1642 placed into the directory of the same name. Likewise, if there are
1643 files in the pre-existing directory with the same names as the members
1644 which you extract, the files from the extracted archive will replace
1645 the files already in the working directory (and possible
1646 subdirectories). This will happen regardless of whether or not the
1647 files in the working directory were more recent than those extracted
1648 (there exist, however, special options that alter this behavior
1649 @pxref{Writing}).
1650
1651 However, if a file was stored with a directory name as part of its file
1652 name, and that directory does not exist under the working directory when
1653 the file is extracted, @command{tar} will create the directory.
1654
1655 We can demonstrate how to use @option{--extract} to extract a directory
1656 file with an example. Change to the @file{practice} directory if you
1657 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1658 go back to the parent directory and extract the archive
1659 @file{music.tar}. You may either extract the entire archive, or you may
1660 extract only the files you just deleted. To extract the entire archive,
1661 don't give any file names as arguments after the archive name
1662 @file{music.tar}. To extract only the files you deleted, use the
1663 following command:
1664
1665 @smallexample
1666 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1667 practice/folk
1668 practice/jazz
1669 @end smallexample
1670
1671 @noindent
1672 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1673 would have displayed more detail about the extracted files, as shown
1674 in the example below:
1675
1676 @smallexample
1677 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1678 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1679 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1680 @end smallexample
1681
1682 @noindent
1683 Because you created the directory with @file{practice} as part of the
1684 file names of each of the files by archiving the @file{practice}
1685 directory as @file{practice}, you must give @file{practice} as part
1686 of the file names when you extract those files from the archive.
1687
1688 @node extracting untrusted archives
1689 @subsection Extracting Archives from Untrusted Sources
1690
1691 Extracting files from archives can overwrite files that already exist.
1692 If you receive an archive from an untrusted source, you should make a
1693 new directory and extract into that directory, so that you don't have
1694 to worry about the extraction overwriting one of your existing files.
1695 For example, if @file{untrusted.tar} came from somewhere else on the
1696 Internet, and you don't necessarily trust its contents, you can
1697 extract it as follows:
1698
1699 @smallexample
1700 $ @kbd{mkdir newdir}
1701 $ @kbd{cd newdir}
1702 $ @kbd{tar -xvf ../untrusted.tar}
1703 @end smallexample
1704
1705 It is also a good practice to examine contents of the archive
1706 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1707 with @option{--verbose} (@option{-v}).
1708
1709 @node failing commands
1710 @subsection Commands That Will Fail
1711
1712 Here are some sample commands you might try which will not work, and why
1713 they won't work.
1714
1715 If you try to use this command,
1716
1717 @smallexample
1718 $ @kbd{tar -xvf music.tar folk jazz}
1719 @end smallexample
1720
1721 @noindent
1722 you will get the following response:
1723
1724 @smallexample
1725 tar: folk: Not found in archive
1726 tar: jazz: Not found in archive
1727 $
1728 @end smallexample
1729
1730 @noindent
1731 This is because these files were not originally @emph{in} the parent
1732 directory @file{..}, where the archive is located; they were in the
1733 @file{practice} directory, and their file names reflect this:
1734
1735 @smallexample
1736 $ @kbd{tar -tvf music.tar}
1737 practice/folk
1738 practice/jazz
1739 practice/rock
1740 @end smallexample
1741
1742 @FIXME{make sure the above works when going through the examples in
1743 order...}
1744
1745 @noindent
1746 Likewise, if you try to use this command,
1747
1748 @smallexample
1749 $ @kbd{tar -tvf music.tar folk jazz}
1750 @end smallexample
1751
1752 @noindent
1753 you would get a similar response. Members with those names are not in the
1754 archive. You must use the correct member names, or wildcards, in order
1755 to extract the files from the archive.
1756
1757 If you have forgotten the correct names of the files in the archive,
1758 use @w{@kbd{tar --list --verbose}} to list them correctly.
1759
1760 @FIXME{more examples, here? hag thinks it's a good idea.}
1761
1762 @node going further
1763 @section Going Further Ahead in this Manual
1764
1765 @FIXME{need to write up a node here about the things that are going to
1766 be in the rest of the manual.}
1767
1768 @node tar invocation
1769 @chapter Invoking @GNUTAR{}
1770 @UNREVISED
1771
1772 This chapter is about how one invokes the @GNUTAR{}
1773 command, from the command synopsis (@pxref{Synopsis}). There are
1774 numerous options, and many styles for writing them. One mandatory
1775 option specifies the operation @command{tar} should perform
1776 (@pxref{Operation Summary}), other options are meant to detail how
1777 this operation should be performed (@pxref{Option Summary}).
1778 Non-option arguments are not always interpreted the same way,
1779 depending on what the operation is.
1780
1781 You will find in this chapter everything about option styles and rules for
1782 writing them (@pxref{Styles}). On the other hand, operations and options
1783 are fully described elsewhere, in other chapters. Here, you will find
1784 only synthetic descriptions for operations and options, together with
1785 pointers to other parts of the @command{tar} manual.
1786
1787 Some options are so special they are fully described right in this
1788 chapter. They have the effect of inhibiting the normal operation of
1789 @command{tar} or else, they globally alter the amount of feedback the user
1790 receives about what is going on. These are the @option{--help} and
1791 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1792 and @option{--interactive} options (@pxref{interactive}).
1793
1794 @menu
1795 * Synopsis::
1796 * using tar options::
1797 * Styles::
1798 * All Options::
1799 * help::
1800 * defaults::
1801 * verbose::
1802 * interactive::
1803 @end menu
1804
1805 @node Synopsis
1806 @section General Synopsis of @command{tar}
1807
1808 The @GNUTAR{} program is invoked as either one of:
1809
1810 @smallexample
1811 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1812 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1813 @end smallexample
1814
1815 The second form is for when old options are being used.
1816
1817 You can use @command{tar} to store files in an archive, to extract them from
1818 an archive, and to do other types of archive manipulation. The primary
1819 argument to @command{tar}, which is called the @dfn{operation}, specifies
1820 which action to take. The other arguments to @command{tar} are either
1821 @dfn{options}, which change the way @command{tar} performs an operation,
1822 or file names or archive members, which specify the files or members
1823 @command{tar} is to act on.
1824
1825 You can actually type in arguments in any order, even if in this manual
1826 the options always precede the other arguments, to make examples easier
1827 to understand. Further, the option stating the main operation mode
1828 (the @command{tar} main command) is usually given first.
1829
1830 Each @var{name} in the synopsis above is interpreted as an archive member
1831 name when the main command is one of @option{--compare}
1832 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1833 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1834 @option{--update} (@option{-u}). When naming archive members, you
1835 must give the exact name of the member in the archive, as it is
1836 printed by @option{--list}. For @option{--append} (@option{-r}) and
1837 @option{--create} (@option{-c}), these @var{name} arguments specify
1838 the names of either files or directory hierarchies to place in the archive.
1839 These files or hierarchies should already exist in the file system,
1840 prior to the execution of the @command{tar} command.
1841
1842 @command{tar} interprets relative file names as being relative to the
1843 working directory. @command{tar} will make all file names relative
1844 (by removing leading slashes when archiving or restoring files),
1845 unless you specify otherwise (using the @option{--absolute-names}
1846 option). @xref{absolute}, for more information about
1847 @option{--absolute-names}.
1848
1849 If you give the name of a directory as either a file name or a member
1850 name, then @command{tar} acts recursively on all the files and directories
1851 beneath that directory. For example, the name @file{/} identifies all
1852 the files in the file system to @command{tar}.
1853
1854 The distinction between file names and archive member names is especially
1855 important when shell globbing is used, and sometimes a source of confusion
1856 for newcomers. @xref{wildcards}, for more information about globbing.
1857 The problem is that shells may only glob using existing files in the
1858 file system. Only @command{tar} itself may glob on archive members, so when
1859 needed, you must ensure that wildcard characters reach @command{tar} without
1860 being interpreted by the shell first. Using a backslash before @samp{*}
1861 or @samp{?}, or putting the whole argument between quotes, is usually
1862 sufficient for this.
1863
1864 Even if @var{name}s are often specified on the command line, they
1865 can also be read from a text file in the file system, using the
1866 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1867
1868 If you don't use any file name arguments, @option{--append} (@option{-r}),
1869 @option{--delete} and @option{--concatenate} (@option{--catenate},
1870 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1871 will usually yield a diagnostic and inhibit @command{tar} execution.
1872 The other operations of @command{tar} (@option{--list},
1873 @option{--extract}, @option{--compare}, and @option{--update})
1874 will act on the entire contents of the archive.
1875
1876 @cindex exit status
1877 @cindex return status
1878 Besides successful exits, @GNUTAR{} may fail for
1879 many reasons. Some reasons correspond to bad usage, that is, when the
1880 @command{tar} command is improperly written. Errors may be
1881 encountered later, while encountering an error processing the archive
1882 or the files. Some errors are recoverable, in which case the failure
1883 is delayed until @command{tar} has completed all its work. Some
1884 errors are such that it would not meaningful, or at least risky, to
1885 continue processing: @command{tar} then aborts processing immediately.
1886 All abnormal exits, whether immediate or delayed, should always be
1887 clearly diagnosed on @code{stderr}, after a line stating the nature of
1888 the error.
1889
1890 @GNUTAR{} returns only a few exit statuses. I'm really
1891 aiming simplicity in that area, for now. If you are not using the
1892 @option{--compare} @option{--diff}, @option{-d}) option, zero means
1893 that everything went well, besides maybe innocuous warnings. Nonzero
1894 means that something went wrong. Right now, as of today, ``nonzero''
1895 is almost always 2, except for remote operations, where it may be
1896 128.
1897
1898 @node using tar options
1899 @section Using @command{tar} Options
1900
1901 @GNUTAR{} has a total of eight operating modes which
1902 allow you to perform a variety of tasks. You are required to choose
1903 one operating mode each time you employ the @command{tar} program by
1904 specifying one, and only one operation as an argument to the
1905 @command{tar} command (two lists of four operations each may be found
1906 at @ref{frequent operations} and @ref{Operations}). Depending on
1907 circumstances, you may also wish to customize how the chosen operating
1908 mode behaves. For example, you may wish to change the way the output
1909 looks, or the format of the files that you wish to archive may require
1910 you to do something special in order to make the archive look right.
1911
1912 You can customize and control @command{tar}'s performance by running
1913 @command{tar} with one or more options (such as @option{--verbose}
1914 (@option{-v}), which we used in the tutorial). As we said in the
1915 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1916 their name suggests) optional. Depending on the operating mode, you
1917 may specify one or more options. Different options will have different
1918 effects, but in general they all change details of the operation, such
1919 as archive format, archive name, or level of user interaction. Some
1920 options make sense with all operating modes, while others are
1921 meaningful only with particular modes. You will likely use some
1922 options frequently, while you will only use others infrequently, or
1923 not at all. (A full list of options is available in @pxref{All Options}.)
1924
1925 @vrindex TAR_OPTIONS, environment variable
1926 @anchor{TAR_OPTIONS}
1927 The @env{TAR_OPTIONS} environment variable specifies default options to
1928 be placed in front of any explicit options. For example, if
1929 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1930 if the two options @option{-v} and @option{--unlink-first} had been
1931 specified before any explicit options. Option specifications are
1932 separated by whitespace. A backslash escapes the next character, so it
1933 can be used to specify an option containing whitespace or a backslash.
1934
1935 Note that @command{tar} options are case sensitive. For example, the
1936 options @option{-T} and @option{-t} are different; the first requires an
1937 argument for stating the name of a file providing a list of @var{name}s,
1938 while the second does not require an argument and is another way to
1939 write @option{--list} (@option{-t}).
1940
1941 In addition to the eight operations, there are many options to
1942 @command{tar}, and three different styles for writing both: long (mnemonic)
1943 form, short form, and old style. These styles are discussed below.
1944 Both the options and the operations can be written in any of these three
1945 styles.
1946
1947 @FIXME{menu at end of this node. need to think of an actual outline
1948 for this chapter; probably do that after stuff from chapter 4 is
1949 incorporated.}
1950
1951 @node Styles
1952 @section The Three Option Styles
1953
1954 There are three styles for writing operations and options to the command
1955 line invoking @command{tar}. The different styles were developed at
1956 different times during the history of @command{tar}. These styles will be
1957 presented below, from the most recent to the oldest.
1958
1959 Some options must take an argument. (For example, @option{--file}
1960 (@option{-f})) takes the name of an archive file as an argument. If
1961 you do not supply an archive file name, @command{tar} will use a
1962 default, but this can be confusing; thus, we recommend that you always
1963 supply a specific archive file name.) Where you @emph{place} the
1964 arguments generally depends on which style of options you choose. We
1965 will detail specific information relevant to each option style in the
1966 sections on the different option styles, below. The differences are
1967 subtle, yet can often be very important; incorrect option placement
1968 can cause you to overwrite a number of important files. We urge you
1969 to note these differences, and only use the option style(s) which
1970 makes the most sense to you until you feel comfortable with the others.
1971
1972 Some options @emph{may} take an argument. Such options may have at
1973 most long and short forms, they do not have old style equivalent. The
1974 rules for specifying an argument for such options are stricter than
1975 those for specifying mandatory arguments. Please, pay special
1976 attention to them.
1977
1978 @menu
1979 * Long Options:: Long Option Style
1980 * Short Options:: Short Option Style
1981 * Old Options:: Old Option Style
1982 * Mixing:: Mixing Option Styles
1983 @end menu
1984
1985 @node Long Options
1986 @subsection Long Option Style
1987
1988 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
1989 dashes in a row, e.g., @option{--list}. The long names are more clear than
1990 their corresponding short or old names. It sometimes happens that a
1991 single long option has many different different names which are
1992 synonymous, such as @option{--compare} and @option{--diff}. In addition,
1993 long option names can be given unique abbreviations. For example,
1994 @option{--cre} can be used in place of @option{--create} because there is no
1995 other long option which begins with @samp{cre}. (One way to find
1996 this out is by trying it and seeing what happens; if a particular
1997 abbreviation could represent more than one option, @command{tar} will tell
1998 you that that abbreviation is ambiguous and you'll know that that
1999 abbreviation won't work. You may also choose to run @samp{tar --help}
2000 to see a list of options. Be aware that if you run @command{tar} with a
2001 unique abbreviation for the long name of an option you didn't want to
2002 use, you are stuck; @command{tar} will perform the command as ordered.)
2003
2004 Long options are meant to be obvious and easy to remember, and their
2005 meanings are generally easier to discern than those of their
2006 corresponding short options (see below). For example:
2007
2008 @smallexample
2009 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2010 @end smallexample
2011
2012 @noindent
2013 gives a fairly good set of hints about what the command does, even
2014 for those not fully acquainted with @command{tar}.
2015
2016 Long options which require arguments take those arguments
2017 immediately following the option name. There are two ways of
2018 specifying a mandatory argument. It can be separated from the
2019 option name either by an equal sign, or by any amount of
2020 white space characters. For example, the @option{--file} option (which
2021 tells the name of the @command{tar} archive) is given a file such as
2022 @file{archive.tar} as argument by using any of the following notations:
2023 @option{--file=archive.tar} or @option{--file archive.tar}.
2024
2025 In contrast, optional arguments must always be introduced using
2026 an equal sign. For example, the @option{--backup} option takes
2027 an optional argument specifying backup type. It must be used
2028 as @option{--backup=@var{backup-type}}.
2029
2030 @node Short Options
2031 @subsection Short Option Style
2032
2033 Most options also have a @dfn{short option} name. Short options start with
2034 a single dash, and are followed by a single character, e.g., @option{-t}
2035 (which is equivalent to @option{--list}). The forms are absolutely
2036 identical in function; they are interchangeable.
2037
2038 The short option names are faster to type than long option names.
2039
2040 Short options which require arguments take their arguments immediately
2041 following the option, usually separated by white space. It is also
2042 possible to stick the argument right after the short option name, using
2043 no intervening space. For example, you might write @w{@option{-f
2044 archive.tar}} or @option{-farchive.tar} instead of using
2045 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2046 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2047 specific archive, here named @file{archive.tar}.
2048
2049 Short options which take optional arguments take their arguments
2050 immediately following the option letter, @emph{without any intervening
2051 white space characters}.
2052
2053 Short options' letters may be clumped together, but you are not
2054 required to do this (as compared to old options; see below). When
2055 short options are clumped as a set, use one (single) dash for them
2056 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2057 such a set is allowed to have an argument@footnote{Clustering many
2058 options, the last of which has an argument, is a rather opaque way to
2059 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2060 even be made helpful enough for considering such usages as invalid.}.
2061
2062 When the options are separated, the argument for each option which requires
2063 an argument directly follows that option, as is usual for Unix programs.
2064 For example:
2065
2066 @smallexample
2067 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2068 @end smallexample
2069
2070 If you reorder short options' locations, be sure to move any arguments
2071 that belong to them. If you do not move the arguments properly, you may
2072 end up overwriting files.
2073
2074 @node Old Options
2075 @subsection Old Option Style
2076 @UNREVISED
2077
2078 Like short options, @dfn{old options} are single letters. However, old options
2079 must be written together as a single clumped set, without spaces separating
2080 them or dashes preceding them@footnote{Beware that if you precede options
2081 with a dash, you are announcing the short option style instead of the
2082 old option style; short options are decoded differently.}. This set
2083 of letters must be the first to appear on the command line, after the
2084 @command{tar} program name and some white space; old options cannot appear
2085 anywhere else. The letter of an old option is exactly the same letter as
2086 the corresponding short option. For example, the old option @samp{t} is
2087 the same as the short option @option{-t}, and consequently, the same as the
2088 long option @option{--list}. So for example, the command @w{@samp{tar
2089 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2090
2091 When options that need arguments are given together with the command,
2092 all the associated arguments follow, in the same order as the options.
2093 Thus, the example given previously could also be written in the old
2094 style as follows:
2095
2096 @smallexample
2097 $ @kbd{tar cvbf 20 /dev/rmt0}
2098 @end smallexample
2099
2100 @noindent
2101 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2102 the argument of @option{-f}.
2103
2104 On the other hand, this old style syntax makes it difficult to match
2105 option letters with their corresponding arguments, and is often
2106 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2107 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2108 argument for @option{-f}, and @option{-v} does not have a corresponding
2109 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2110 /dev/rmt0}} is clearer, putting all arguments next to the option they
2111 pertain to.
2112
2113 If you want to reorder the letters in the old option argument, be
2114 sure to reorder any corresponding argument appropriately.
2115
2116 This old way of writing @command{tar} options can surprise even experienced
2117 users. For example, the two commands:
2118
2119 @smallexample
2120 @kbd{tar cfz archive.tar.gz file}
2121 @kbd{tar -cfz archive.tar.gz file}
2122 @end smallexample
2123
2124 @noindent
2125 are quite different. The first example uses @file{archive.tar.gz} as
2126 the value for option @samp{f} and recognizes the option @samp{z}. The
2127 second example, however, uses @file{z} as the value for option
2128 @samp{f} --- probably not what was intended.
2129
2130 Old options are kept for compatibility with old versions of @command{tar}.
2131
2132 This second example could be corrected in many ways, among which the
2133 following are equivalent:
2134
2135 @smallexample
2136 @kbd{tar -czf archive.tar.gz file}
2137 @kbd{tar -cf archive.tar.gz -z file}
2138 @kbd{tar cf archive.tar.gz -z file}
2139 @end smallexample
2140
2141 @cindex option syntax, traditional
2142 As far as we know, all @command{tar} programs, @acronym{GNU} and
2143 non-@acronym{GNU}, support old options. @GNUTAR{}
2144 supports them not only for historical reasons, but also because many
2145 people are used to them. For compatibility with Unix @command{tar},
2146 the first argument is always treated as containing command and option
2147 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2148 equivalent to @w{@samp{tar -c}:} both of them specify the
2149 @option{--create} (@option{-c}) command to create an archive.
2150
2151 @node Mixing
2152 @subsection Mixing Option Styles
2153
2154 All three styles may be intermixed in a single @command{tar} command,
2155 so long as the rules for each style are fully
2156 respected@footnote{Before @GNUTAR{} version 1.11.6,
2157 a bug prevented intermixing old style options with long options in
2158 some cases.}. Old style options and either of the modern styles of
2159 options may be mixed within a single @command{tar} command. However,
2160 old style options must be introduced as the first arguments only,
2161 following the rule for old options (old options must appear directly
2162 after the @command{tar} command and some white space). Modern options
2163 may be given only after all arguments to the old options have been
2164 collected. If this rule is not respected, a modern option might be
2165 falsely interpreted as the value of the argument to one of the old
2166 style options.
2167
2168 For example, all the following commands are wholly equivalent, and
2169 illustrate the many combinations and orderings of option styles.
2170
2171 @smallexample
2172 @kbd{tar --create --file=archive.tar}
2173 @kbd{tar --create -f archive.tar}
2174 @kbd{tar --create -farchive.tar}
2175 @kbd{tar --file=archive.tar --create}
2176 @kbd{tar --file=archive.tar -c}
2177 @kbd{tar -c --file=archive.tar}
2178 @kbd{tar -c -f archive.tar}
2179 @kbd{tar -c -farchive.tar}
2180 @kbd{tar -cf archive.tar}
2181 @kbd{tar -cfarchive.tar}
2182 @kbd{tar -f archive.tar --create}
2183 @kbd{tar -f archive.tar -c}
2184 @kbd{tar -farchive.tar --create}
2185 @kbd{tar -farchive.tar -c}
2186 @kbd{tar c --file=archive.tar}
2187 @kbd{tar c -f archive.tar}
2188 @kbd{tar c -farchive.tar}
2189 @kbd{tar cf archive.tar}
2190 @kbd{tar f archive.tar --create}
2191 @kbd{tar f archive.tar -c}
2192 @kbd{tar fc archive.tar}
2193 @end smallexample
2194
2195 On the other hand, the following commands are @emph{not} equivalent to
2196 the previous set:
2197
2198 @smallexample
2199 @kbd{tar -f -c archive.tar}
2200 @kbd{tar -fc archive.tar}
2201 @kbd{tar -fcarchive.tar}
2202 @kbd{tar -farchive.tarc}
2203 @kbd{tar cfarchive.tar}
2204 @end smallexample
2205
2206 @noindent
2207 These last examples mean something completely different from what the
2208 user intended (judging based on the example in the previous set which
2209 uses long options, whose intent is therefore very clear). The first
2210 four specify that the @command{tar} archive would be a file named
2211 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2212 respectively. The first two examples also specify a single non-option,
2213 @var{name} argument having the value @samp{archive.tar}. The last
2214 example contains only old style option letters (repeating option
2215 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2216 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2217 the first sentence of this paragraph..}
2218
2219 @node All Options
2220 @section All @command{tar} Options
2221
2222 The coming manual sections contain an alphabetical listing of all
2223 @command{tar} operations and options, with brief descriptions and cross
2224 references to more in-depth explanations in the body of the manual.
2225 They also contain an alphabetically arranged table of the short option
2226 forms with their corresponding long option. You can use this table as
2227 a reference for deciphering @command{tar} commands in scripts.
2228
2229 @menu
2230 * Operation Summary::
2231 * Option Summary::
2232 * Short Option Summary::
2233 @end menu
2234
2235 @node Operation Summary
2236 @subsection Operations
2237
2238 @table @option
2239
2240 @opsummary{append}
2241 @item --append
2242 @itemx -r
2243
2244 Appends files to the end of the archive. @xref{append}.
2245
2246 @opsummary{catenate}
2247 @item --catenate
2248 @itemx -A
2249
2250 Same as @option{--concatenate}. @xref{concatenate}.
2251
2252 @opsummary{compare}
2253 @item --compare
2254 @itemx -d
2255
2256 Compares archive members with their counterparts in the file
2257 system, and reports differences in file size, mode, owner,
2258 modification date and contents. @xref{compare}.
2259
2260 @opsummary{concatenate}
2261 @item --concatenate
2262 @itemx -A
2263
2264 Appends other @command{tar} archives to the end of the archive.
2265 @xref{concatenate}.
2266
2267 @opsummary{create}
2268 @item --create
2269 @itemx -c
2270
2271 Creates a new @command{tar} archive. @xref{create}.
2272
2273 @opsummary{delete}
2274 @item --delete
2275
2276 Deletes members from the archive. Don't try this on a archive on a
2277 tape! @xref{delete}.
2278
2279 @opsummary{diff}
2280 @item --diff
2281 @itemx -d
2282
2283 Same @option{--compare}. @xref{compare}.
2284
2285 @opsummary{extract}
2286 @item --extract
2287 @itemx -x
2288
2289 Extracts members from the archive into the file system. @xref{extract}.
2290
2291 @opsummary{get}
2292 @item --get
2293 @itemx -x
2294
2295 Same as @option{--extract}. @xref{extract}.
2296
2297 @opsummary{list}
2298 @item --list
2299 @itemx -t
2300
2301 Lists the members in an archive. @xref{list}.
2302
2303 @opsummary{update}
2304 @item --update
2305 @itemx -u
2306
2307 Adds files to the end of the archive, but only if they are newer than
2308 their counterparts already in the archive, or if they do not already
2309 exist in the archive. @xref{update}.
2310
2311 @end table
2312
2313 @node Option Summary
2314 @subsection @command{tar} Options
2315
2316 @table @option
2317
2318 @opsummary{absolute-names}
2319 @item --absolute-names
2320 @itemx -P
2321
2322 Normally when creating an archive, @command{tar} strips an initial
2323 @samp{/} from member names. This option disables that behavior.
2324 @xref{absolute}.
2325
2326 @opsummary{after-date}
2327 @item --after-date
2328
2329 (See @option{--newer}, @pxref{after})
2330
2331 @opsummary{anchored}
2332 @item --anchored
2333 A pattern must match an initial subsequence of the name's components.
2334 @xref{controlling pattern-matching}.
2335
2336 @opsummary{atime-preserve}
2337 @item --atime-preserve
2338 @itemx --atime-preserve=replace
2339 @itemx --atime-preserve=system
2340
2341 Attempt to preserve the access time of files when reading them. This
2342 option currently is effective only on files that you own, unless you
2343 have superuser privileges.
2344
2345 @option{--atime-preserve=replace} remembers the access time of a file
2346 before reading it, and then restores the access time afterwards. This
2347 may cause problems if other programs are reading the file at the same
2348 time, as the times of their accesses will be lost. On most platforms
2349 restoring the access time also requires @command{tar} to restore the
2350 data modification time too, so this option may also cause problems if
2351 other programs are writing the file at the same time. (Tar attempts
2352 to detect this situation, but cannot do so reliably due to race
2353 conditions.) Worse, on most platforms restoring the access time also
2354 updates the status change time, which means that this option is
2355 incompatible with incremental backups.
2356
2357 @option{--atime-preserve=system} avoids changing time stamps on files,
2358 without interfering with time stamp updates
2359 caused by other programs, so it works better with incremental backups.
2360 However, it requires a special @code{O_NOATIME} option from the
2361 underlying operating and file system implementation, and it also requires
2362 that searching directories does not update their access times. As of
2363 this writing (November 2005) this works only with Linux, and only with
2364 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2365 way to know whether this feature actually works. Sometimes
2366 @command{tar} knows that it does not work, and if you use
2367 @option{--atime-preserve=system} then @command{tar} complains and
2368 exits right away. But other times @command{tar} might think that the
2369 option works when it actually does not.
2370
2371 Currently @option{--atime-preserve} with no operand defaults to
2372 @option{--atime-preserve=replace}, but this may change in the future
2373 as support for @option{--atime-preserve=system} improves.
2374
2375 If your operating system does not support
2376 @option{--atime-preserve=@-system}, you might be able to preserve access
2377 times reliably by by using the @command{mount} command. For example,
2378 you can mount the file system read-only, or access the file system via
2379 a read-only loopback mount, or use the @samp{noatime} mount option
2380 available on some systems. However, mounting typically requires
2381 superuser privileges and can be a pain to manage.
2382
2383 @opsummary{backup}
2384 @item --backup=@var{backup-type}
2385
2386 Rather than deleting files from the file system, @command{tar} will
2387 back them up using simple or numbered backups, depending upon
2388 @var{backup-type}. @xref{backup}.
2389
2390 @opsummary{block-number}
2391 @item --block-number
2392 @itemx -R
2393
2394 With this option present, @command{tar} prints error messages for read errors
2395 with the block number in the archive file. @xref{block-number}.
2396
2397 @opsummary{blocking-factor}
2398 @item --blocking-factor=@var{blocking}
2399 @itemx -b @var{blocking}
2400
2401 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2402 record. @xref{Blocking Factor}.
2403
2404 @opsummary{bzip2}
2405 @item --bzip2
2406 @itemx -j
2407
2408 This option tells @command{tar} to read or write archives through
2409 @code{bzip2}. @xref{gzip}.
2410
2411 @opsummary{checkpoint}
2412 @item --checkpoint[=@var{number}]
2413
2414 This option directs @command{tar} to print periodic checkpoint
2415 messages as it reads through the archive. It is intended for when you
2416 want a visual indication that @command{tar} is still running, but
2417 don't want to see @option{--verbose} output. For a detailed
2418 description, see @ref{Progress information}.
2419
2420 @opsummary{check-links}
2421 @item --check-links
2422 @itemx -l
2423 If this option was given, @command{tar} will check the number of links
2424 dumped for each processed file. If this number does not match the
2425 total number of hard links for the file, a warning message will be
2426 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2427 synonym for @option{--one-file-system}. The current semantics, which
2428 complies to UNIX98, was introduced with version
2429 1.15.91. @xref{Changes}, for more information.}.
2430
2431 @opsummary{compress}
2432 @opsummary{uncompress}
2433 @item --compress
2434 @itemx --uncompress
2435 @itemx -Z
2436
2437 @command{tar} will use the @command{compress} program when reading or
2438 writing the archive. This allows you to directly act on archives
2439 while saving space. @xref{gzip}.
2440
2441 @opsummary{confirmation}
2442 @item --confirmation
2443
2444 (See @option{--interactive}.) @xref{interactive}.
2445
2446 @opsummary{delay-directory-restore}
2447 @item --delay-directory-restore
2448
2449 Delay setting modification times and permissions of extracted
2450 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2451
2452 @opsummary{dereference}
2453 @item --dereference
2454 @itemx -h
2455
2456 When creating a @command{tar} archive, @command{tar} will archive the
2457 file that a symbolic link points to, rather than archiving the
2458 symlink. @xref{dereference}.
2459
2460 @opsummary{directory}
2461 @item --directory=@var{dir}
2462 @itemx -C @var{dir}
2463
2464 When this option is specified, @command{tar} will change its current directory
2465 to @var{dir} before performing any operations. When this option is used
2466 during archive creation, it is order sensitive. @xref{directory}.
2467
2468 @opsummary{exclude}
2469 @item --exclude=@var{pattern}
2470
2471 When performing operations, @command{tar} will skip files that match
2472 @var{pattern}. @xref{exclude}.
2473
2474 @opsummary{exclude-from}
2475 @item --exclude-from=@var{file}
2476 @itemx -X @var{file}
2477
2478 Similar to @option{--exclude}, except @command{tar} will use the list of
2479 patterns in the file @var{file}. @xref{exclude}.
2480
2481 @opsummary{exclude-caches}
2482 @item --exclude-caches
2483
2484 Automatically excludes all directories
2485 containing a cache directory tag. @xref{exclude}.
2486
2487 @opsummary{file}
2488 @item --file=@var{archive}
2489 @itemx -f @var{archive}
2490
2491 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2492 performs operations on, rather than @command{tar}'s compilation dependent
2493 default. @xref{file tutorial}.
2494
2495 @opsummary{files-from}
2496 @item --files-from=@var{file}
2497 @itemx -T @var{file}
2498
2499 @command{tar} will use the contents of @var{file} as a list of archive members
2500 or files to operate on, in addition to those specified on the
2501 command-line. @xref{files}.
2502
2503 @opsummary{force-local}
2504 @item --force-local
2505
2506 Forces @command{tar} to interpret the filename given to @option{--file}
2507 as a local file, even if it looks like a remote tape drive name.
2508 @xref{local and remote archives}.
2509
2510 @opsummary{format}
2511 @item --format=@var{format}
2512 @itemx -H @var{format}
2513
2514 Selects output archive format. @var{Format} may be one of the
2515 following:
2516
2517 @table @samp
2518 @item v7
2519 Creates an archive that is compatible with Unix V7 @command{tar}.
2520
2521 @item oldgnu
2522 Creates an archive that is compatible with GNU @command{tar} version
2523 1.12 or earlier.
2524
2525 @item gnu
2526 Creates archive in GNU tar 1.13 format. Basically it is the same as
2527 @samp{oldgnu} with the only difference in the way it handles long
2528 numeric fields.
2529
2530 @item ustar
2531 Creates a @acronym{POSIX.1-1988} compatible archive.
2532
2533 @item posix
2534 Creates a @acronym{POSIX.1-2001 archive}.
2535
2536 @end table
2537
2538 @xref{Formats}, for a detailed discussion of these formats.
2539
2540 @opsummary{group}
2541 @item --group=@var{group}
2542
2543 Files added to the @command{tar} archive will have a group id of @var{group},
2544 rather than the group from the source file. @var{group} is first decoded
2545 as a group symbolic name, but if this interpretation fails, it has to be
2546 a decimal numeric group ID. @xref{override}.
2547
2548 Also see the comments for the @option{--owner=@var{user}} option.
2549
2550 @opsummary{gzip}
2551 @opsummary{gunzip}
2552 @opsummary{ungzip}
2553 @item --gzip
2554 @itemx --gunzip
2555 @itemx --ungzip
2556 @itemx -z
2557
2558 This option tells @command{tar} to read or write archives through
2559 @command{gzip}, allowing @command{tar} to directly operate on several
2560 kinds of compressed archives transparently. @xref{gzip}.
2561
2562 @opsummary{help}
2563 @item --help
2564 @itemx -?
2565
2566 @command{tar} will print out a short message summarizing the operations and
2567 options to @command{tar} and exit. @xref{help}.
2568
2569 @opsummary{ignore-case}
2570 @item --ignore-case
2571 Ignore case when matching member or file names with
2572 patterns. @xref{controlling pattern-matching}.
2573
2574 @opsummary{ignore-command-error}
2575 @item --ignore-command-error
2576 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2577
2578 @opsummary{ignore-failed-read}
2579 @item --ignore-failed-read
2580
2581 Do not exit unsuccessfully merely because an unreadable file was encountered.
2582 @xref{Reading}.
2583
2584 @opsummary{ignore-zeros}
2585 @item --ignore-zeros
2586 @itemx -i
2587
2588 With this option, @command{tar} will ignore zeroed blocks in the
2589 archive, which normally signals EOF. @xref{Reading}.
2590
2591 @opsummary{incremental}
2592 @item --incremental
2593 @itemx -G
2594
2595 Used to inform @command{tar} that it is working with an old
2596 @acronym{GNU}-format incremental backup archive. It is intended
2597 primarily for backwards compatibility only. @xref{Incremental Dumps},
2598 for a detailed discussion of incremental archives.
2599
2600 @opsummary{index-file}
2601 @item --index-file=@var{file}
2602
2603 Send verbose output to @var{file} instead of to standard output.
2604
2605 @opsummary{info-script}
2606 @opsummary{new-volume-script}
2607 @item --info-script=@var{script-file}
2608 @itemx --new-volume-script=@var{script-file}
2609 @itemx -F @var{script-file}
2610
2611 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2612 at the end of each tape. If @var{script-file} exits with nonzero status,
2613 @command{tar} fails immediately. @xref{info-script}, for a detailed
2614 discussion of @var{script-file}.
2615
2616 @opsummary{interactive}
2617 @item --interactive
2618 @itemx --confirmation
2619 @itemx -w
2620
2621 Specifies that @command{tar} should ask the user for confirmation before
2622 performing potentially destructive options, such as overwriting files.
2623 @xref{interactive}.
2624
2625 @opsummary{keep-newer-files}
2626 @item --keep-newer-files
2627
2628 Do not replace existing files that are newer than their archive copies
2629 when extracting files from an archive.
2630
2631 @opsummary{keep-old-files}
2632 @item --keep-old-files
2633 @itemx -k
2634
2635 Do not overwrite existing files when extracting files from an archive.
2636 @xref{Keep Old Files}.
2637
2638 @opsummary{label}
2639 @item --label=@var{name}
2640 @itemx -V @var{name}
2641
2642 When creating an archive, instructs @command{tar} to write @var{name}
2643 as a name record in the archive. When extracting or listing archives,
2644 @command{tar} will only operate on archives that have a label matching
2645 the pattern specified in @var{name}. @xref{Tape Files}.
2646
2647 @opsummary{listed-incremental}
2648 @item --listed-incremental=@var{snapshot-file}
2649 @itemx -g @var{snapshot-file}
2650
2651 During a @option{--create} operation, specifies that the archive that
2652 @command{tar} creates is a new @acronym{GNU}-format incremental
2653 backup, using @var{snapshot-file} to determine which files to backup.
2654 With other operations, informs @command{tar} that the archive is in
2655 incremental format. @xref{Incremental Dumps}.
2656
2657 @opsummary{mode}
2658 @item --mode=@var{permissions}
2659
2660 When adding files to an archive, @command{tar} will use
2661 @var{permissions} for the archive members, rather than the permissions
2662 from the files. @var{permissions} can be specified either as an octal
2663 number or as symbolic permissions, like with
2664 @command{chmod}. @xref{override}.
2665
2666 @opsummary{mtime}
2667 @item --mtime=@var{date}
2668
2669 When adding files to an archive, @command{tar} will use @var{date} as
2670 the modification time of members when creating archives, instead of
2671 their actual modification times. The value of @var{date} can be
2672 either a textual date representation (@pxref{Date input formats}) or a
2673 name of the existing file, starting with @samp{/} or @samp{.}. In the
2674 latter case, the modification time of that file is used. @xref{override}.
2675
2676 @opsummary{multi-volume}
2677 @item --multi-volume
2678 @itemx -M
2679
2680 Informs @command{tar} that it should create or otherwise operate on a
2681 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2682
2683 @opsummary{new-volume-script}
2684 @item --new-volume-script
2685
2686 (see --info-script)
2687
2688 @opsummary{seek}
2689 @item --seek
2690 @itemx -n
2691
2692 Assume that the archive media supports seeks to arbitrary
2693 locations. Usually @command{tar} determines automatically whether
2694 the archive can be seeked or not. This option is intended for use
2695 in cases when such recognition fails.
2696
2697 @opsummary{newer}
2698 @item --newer=@var{date}
2699 @itemx --after-date=@var{date}
2700 @itemx -N
2701
2702 When creating an archive, @command{tar} will only add files that have changed
2703 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2704 is taken to be the name of a file whose data modification time specifies
2705 the date. @xref{after}.
2706
2707 @opsummary{newer-mtime}
2708 @item --newer-mtime=@var{date}
2709
2710 Like @option{--newer}, but add only files whose
2711 contents have changed (as opposed to just @option{--newer}, which will
2712 also back up files for which any status information has
2713 changed). @xref{after}.
2714
2715 @opsummary{no-anchored}
2716 @item --no-anchored
2717 An exclude pattern can match any subsequence of the name's components.
2718 @xref{controlling pattern-matching}.
2719
2720 @opsummary{no-delay-directory-restore}
2721 @item --no-delay-directory-restore
2722
2723 Setting modification times and permissions of extracted
2724 directories when all files from this directory has been
2725 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2726
2727 @opsummary{no-ignore-case}
2728 @item --no-ignore-case
2729 Use case-sensitive matching.
2730 @xref{controlling pattern-matching}.
2731
2732 @opsummary{no-ignore-command-error}
2733 @item --no-ignore-command-error
2734 Print warnings about subprocesses terminated with a non-zero exit
2735 code. @xref{Writing to an External Program}.
2736
2737 @opsummary{no-overwrite-dir}
2738 @item --no-overwrite-dir
2739
2740 Preserve metadata of existing directories when extracting files
2741 from an archive. @xref{Overwrite Old Files}.
2742
2743 @opsummary{no-quote-chars}
2744 @item --no-quote-chars=@var{string}
2745 Remove characters listed in @var{string} from the list of quoted
2746 characters set by the previous @option{--quote-chars} option
2747 (@pxref{quoting styles}).
2748
2749 @opsummary{no-recursion}
2750 @item --no-recursion
2751
2752 With this option, @command{tar} will not recurse into directories.
2753 @xref{recurse}.
2754
2755 @opsummary{no-same-owner}
2756 @item --no-same-owner
2757 @itemx -o
2758
2759 When extracting an archive, do not attempt to preserve the owner
2760 specified in the @command{tar} archive. This the default behavior
2761 for ordinary users.
2762
2763 @opsummary{no-same-permissions}
2764 @item --no-same-permissions
2765
2766 When extracting an archive, subtract the user's umask from files from
2767 the permissions specified in the archive. This is the default behavior
2768 for ordinary users.
2769
2770 @opsummary{no-unquote}
2771 @item --no-unquote
2772 Treat all input file or member names literally, do not interpret
2773 escape sequences. @xref{input name quoting}.
2774
2775 @opsummary{no-wildcards}
2776 @item --no-wildcards
2777 Do not use wildcards.
2778 @xref{controlling pattern-matching}.
2779
2780 @opsummary{no-wildcards-match-slash}
2781 @item --no-wildcards-match-slash
2782 Wildcards do not match @samp{/}.
2783 @xref{controlling pattern-matching}.
2784
2785 @opsummary{null}
2786 @item --null
2787
2788 When @command{tar} is using the @option{--files-from} option, this option
2789 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2790 @command{tar} can correctly work with file names that contain newlines.
2791 @xref{nul}.
2792
2793 @opsummary{numeric-owner}
2794 @item --numeric-owner
2795
2796 This option will notify @command{tar} that it should use numeric user
2797 and group IDs when creating a @command{tar} file, rather than names.
2798 @xref{Attributes}.
2799
2800 @item -o
2801 The function of this option depends on the action @command{tar} is
2802 performing. When extracting files, @option{-o} is a synonym for
2803 @option{--no-same-owner}, i.e. it prevents @command{tar} from
2804 restoring ownership of files being extracted.
2805
2806 When creating an archive, it is a synonym for
2807 @option{--old-archive}. This behavior is for compatibility
2808 with previous versions of @GNUTAR{}, and will be
2809 removed in the future releases.
2810
2811 @xref{Changes}, for more information.
2812
2813 @opsummary{occurrence}
2814 @item --occurrence[=@var{number}]
2815
2816 This option can be used in conjunction with one of the subcommands
2817 @option{--delete}, @option{--diff}, @option{--extract} or
2818 @option{--list} when a list of files is given either on the command
2819 line or via @option{-T} option.
2820
2821 This option instructs @command{tar} to process only the @var{number}th
2822 occurrence of each named file. @var{Number} defaults to 1, so
2823
2824 @smallexample
2825 tar -x -f archive.tar --occurrence filename
2826 @end smallexample
2827
2828 @noindent
2829 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2830 and will terminate without scanning to the end of the archive.
2831
2832 @opsummary{old-archive}
2833 @item --old-archive
2834 Synonym for @option{--format=v7}.
2835
2836 @opsummary{one-file-system}
2837 @item --one-file-system
2838 Used when creating an archive. Prevents @command{tar} from recursing into
2839 directories that are on different file systems from the current
2840 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2841 synonym for @option{--one-file-system}. This has changed in version
2842 1.15.91. @xref{Changes}, for more information.}.
2843
2844 @opsummary{overwrite}
2845 @item --overwrite
2846
2847 Overwrite existing files and directory metadata when extracting files
2848 from an archive. @xref{Overwrite Old Files}.
2849
2850 @opsummary{overwrite-dir}
2851 @item --overwrite-dir
2852
2853 Overwrite the metadata of existing directories when extracting files
2854 from an archive. @xref{Overwrite Old Files}.
2855
2856 @opsummary{owner}
2857 @item --owner=@var{user}
2858
2859 Specifies that @command{tar} should use @var{user} as the owner of members
2860 when creating archives, instead of the user associated with the source
2861 file. @var{user} is first decoded as a user symbolic name, but if
2862 this interpretation fails, it has to be a decimal numeric user ID.
2863 @xref{override}.
2864
2865 This option does not affect extraction from archives.
2866
2867 @opsummary{transform}
2868 @item --transform=@var{sed-expr}
2869
2870 Transform file or member names using @command{sed} replacement expression
2871 @var{sed-expr}. For example,
2872
2873 @smallexample
2874 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2875 @end smallexample
2876
2877 @noindent
2878 will add to @file{archive} files from the current working directory,
2879 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2880 discussion, @xref{transform}.
2881
2882 To see transformed member names in verbose listings, use
2883 @option{--show-transformed-names} option
2884 (@pxref{show-transformed-names}).
2885
2886 @opsummary{quote-chars}
2887 @item --quote-chars=@var{string}
2888 Always quote characters from @var{string}, even if the selected
2889 quoting style would not quote them (@pxref{quoting styles}).
2890
2891 @opsummary{quoting-style}
2892 @item --quoting-style=@var{style}
2893 Set quoting style to use when printing member and file names
2894 (@pxref{quoting styles}). Valid @var{style} values are:
2895 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2896 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2897 style is @code{escape}, unless overridden while configuring the
2898 package.
2899
2900 @opsummary{pax-option}
2901 @item --pax-option=@var{keyword-list}
2902 This option is meaningful only with @acronym{POSIX.1-2001} archives
2903 (@pxref{posix}). It modifies the way @command{tar} handles the
2904 extended header keywords. @var{Keyword-list} is a comma-separated
2905 list of keyword options. @xref{PAX keywords}, for a detailed
2906 discussion.
2907
2908 @opsummary{portability}
2909 @item --portability
2910 @itemx --old-archive
2911 Synonym for @option{--format=v7}.
2912
2913 @opsummary{posix}
2914 @item --posix
2915 Same as @option{--format=posix}.
2916
2917 @opsummary{preserve}
2918 @item --preserve
2919
2920 Synonymous with specifying both @option{--preserve-permissions} and
2921 @option{--same-order}. @xref{Setting Access Permissions}.
2922
2923 @opsummary{preserve-order}
2924 @item --preserve-order
2925
2926 (See @option{--same-order}; @pxref{Reading}.)
2927
2928 @opsummary{preserve-permissions}
2929 @opsummary{same-permissions}
2930 @item --preserve-permissions
2931 @itemx --same-permissions
2932 @itemx -p
2933
2934 When @command{tar} is extracting an archive, it normally subtracts the
2935 users' umask from the permissions specified in the archive and uses
2936 that number as the permissions to create the destination file.
2937 Specifying this option instructs @command{tar} that it should use the
2938 permissions directly from the archive. @xref{Setting Access Permissions}.
2939
2940 @opsummary{read-full-records}
2941 @item --read-full-records
2942 @itemx -B
2943
2944 Specifies that @command{tar} should reblock its input, for reading
2945 from pipes on systems with buggy implementations. @xref{Reading}.
2946
2947 @opsummary{record-size}
2948 @item --record-size=@var{size}
2949
2950 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2951 archive. @xref{Blocking Factor}.
2952
2953 @opsummary{recursion}
2954 @item --recursion
2955
2956 With this option, @command{tar} recurses into directories.
2957 @xref{recurse}.
2958
2959 @opsummary{recursive-unlink}
2960 @item --recursive-unlink
2961
2962 Remove existing
2963 directory hierarchies before extracting directories of the same name
2964 from the archive. @xref{Recursive Unlink}.
2965
2966 @opsummary{remove-files}
2967 @item --remove-files
2968
2969 Directs @command{tar} to remove the source file from the file system after
2970 appending it to an archive. @xref{remove files}.
2971
2972 @opsummary{restrict}
2973 @item --restrict
2974
2975 Disable use of some potentially harmful @command{tar} options.
2976 Currently this option disables shell invocaton from multi-volume menu
2977 (@pxref{Using Multiple Tapes}).
2978
2979 @opsummary{rmt-command}
2980 @item --rmt-command=@var{cmd}
2981
2982 Notifies @command{tar} that it should use @var{cmd} instead of
2983 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
2984
2985 @opsummary{rsh-command}
2986 @item --rsh-command=@var{cmd}
2987
2988 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
2989 devices. @xref{Device}.
2990
2991 @opsummary{same-order}
2992 @item --same-order
2993 @itemx --preserve-order
2994 @itemx -s
2995
2996 This option is an optimization for @command{tar} when running on machines with
2997 small amounts of memory. It informs @command{tar} that the list of file
2998 arguments has already been sorted to match the order of files in the
2999 archive. @xref{Reading}.
3000
3001 @opsummary{same-owner}
3002 @item --same-owner
3003
3004 When extracting an archive, @command{tar} will attempt to preserve the owner
3005 specified in the @command{tar} archive with this option present.
3006 This is the default behavior for the superuser; this option has an
3007 effect only for ordinary users. @xref{Attributes}.
3008
3009 @opsummary{same-permissions}
3010 @item --same-permissions
3011
3012 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3013
3014 @opsummary{show-defaults}
3015 @item --show-defaults
3016
3017 Displays the default options used by @command{tar} and exits
3018 successfully. This option is intended for use in shell scripts.
3019 Here is an example of what you can see using this option:
3020
3021 @smallexample
3022 $ tar --show-defaults
3023 --format=gnu -f- -b20 --quoting-style=escape \
3024 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3025 @end smallexample
3026
3027 @opsummary{show-omitted-dirs}
3028 @item --show-omitted-dirs
3029
3030 Instructs @command{tar} to mention directories its skipping over when
3031 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3032
3033 @opsummary{show-transformed-names}
3034 @opsummary{show-stored-names}
3035 @item --show-transformed-names
3036 @itemx --show-stored-names
3037
3038 Display file or member names after applying any transformations
3039 (@pxref{transform}). In particular, when used in conjunction with one of
3040 archive creation operations it instructs tar to list the member names
3041 stored in the archive, as opposed to the actual file
3042 names. @xref{listing member and file names}.
3043
3044 @opsummary{sparse}
3045 @item --sparse
3046 @itemx -S
3047
3048 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3049 sparse files efficiently. @xref{sparse}.
3050
3051 @opsummary{starting-file}
3052 @item --starting-file=@var{name}
3053 @itemx -K @var{name}
3054
3055 This option affects extraction only; @command{tar} will skip extracting
3056 files in the archive until it finds one that matches @var{name}.
3057 @xref{Scarce}.
3058
3059 @opsummary{strip-components}
3060 @item --strip-components=@var{number}
3061 Strip given @var{number} of leading components from file names before
3062 extraction.@footnote{This option was called @option{--strip-path} in
3063 version 1.14.} For example, if archive @file{archive.tar} contained
3064 @file{/some/file/name}, then running
3065
3066 @smallexample
3067 tar --extract --file archive.tar --strip-components=2
3068 @end smallexample
3069
3070 @noindent
3071 would extract this file to file @file{name}.
3072
3073 @opsummary{suffix}, summary
3074 @item --suffix=@var{suffix}
3075
3076 Alters the suffix @command{tar} uses when backing up files from the default
3077 @samp{~}. @xref{backup}.
3078
3079 @opsummary{tape-length}
3080 @item --tape-length=@var{num}
3081 @itemx -L @var{num}
3082
3083 Specifies the length of tapes that @command{tar} is writing as being
3084 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3085
3086 @opsummary{test-label}
3087 @item --test-label
3088
3089 Reads the volume label. If an argument is specified, test whether it
3090 matches the volume label. @xref{--test-label option}.
3091
3092 @opsummary{to-command}
3093 @item --to-command=@var{command}
3094
3095 During extraction @command{tar} will pipe extracted files to the
3096 standard input of @var{command}. @xref{Writing to an External Program}.
3097
3098 @opsummary{to-stdout}
3099 @item --to-stdout
3100 @itemx -O
3101
3102 During extraction, @command{tar} will extract files to stdout rather
3103 than to the file system. @xref{Writing to Standard Output}.
3104
3105 @opsummary{totals}
3106 @item --totals[=@var{signo}]
3107
3108 Displays the total number of bytes transferred when processing an
3109 archive. If an argument is given, these data are displayed on
3110 request, when signal @var{signo} is delivered to @command{tar}.
3111 @xref{totals}.
3112
3113 @opsummary{touch}
3114 @item --touch
3115 @itemx -m
3116
3117 Sets the data modification time of extracted files to the extraction time,
3118 rather than the data modification time stored in the archive.
3119 @xref{Data Modification Times}.
3120
3121 @opsummary{uncompress}
3122 @item --uncompress
3123
3124 (See @option{--compress}. @pxref{gzip})
3125
3126 @opsummary{ungzip}
3127 @item --ungzip
3128
3129 (See @option{--gzip}. @pxref{gzip})
3130
3131 @opsummary{unlink-first}
3132 @item --unlink-first
3133 @itemx -U
3134
3135 Directs @command{tar} to remove the corresponding file from the file
3136 system before extracting it from the archive. @xref{Unlink First}.
3137
3138 @opsummary{unquote}
3139 @item --unquote
3140 Enable unquoting input file or member names (default). @xref{input
3141 name quoting}.
3142
3143 @opsummary{use-compress-program}
3144 @item --use-compress-program=@var{prog}
3145
3146 Instructs @command{tar} to access the archive through @var{prog}, which is
3147 presumed to be a compression program of some sort. @xref{gzip}.
3148
3149 @opsummary{utc}
3150 @item --utc
3151
3152 Display file modification dates in @acronym{UTC}. This option implies
3153 @option{--verbose}.
3154
3155 @opsummary{verbose}
3156 @item --verbose
3157 @itemx -v
3158
3159 Specifies that @command{tar} should be more verbose about the operations its
3160 performing. This option can be specified multiple times for some
3161 operations to increase the amount of information displayed.
3162 @xref{verbose}.
3163
3164 @opsummary{verify}
3165 @item --verify
3166 @itemx -W
3167
3168 Verifies that the archive was correctly written when creating an
3169 archive. @xref{verify}.
3170
3171 @opsummary{version}
3172 @item --version
3173
3174 Print information about the program's name, version, origin and legal
3175 status, all on standard output, and then exit successfully.
3176 @xref{help}.
3177
3178 @opsummary{volno-file}
3179 @item --volno-file=@var{file}
3180
3181 Used in conjunction with @option{--multi-volume}. @command{tar} will
3182 keep track of which volume of a multi-volume archive its working in
3183 @var{file}. @xref{volno-file}.
3184
3185 @opsummary{wildcards}
3186 @item --wildcards
3187 Use wildcards when matching member names with patterns.
3188 @xref{controlling pattern-matching}.
3189
3190 @opsummary{wildcards-match-slash}
3191 @item --wildcards-match-slash
3192 Wildcards match @samp{/}.
3193 @xref{controlling pattern-matching}.
3194 @end table
3195
3196 @node Short Option Summary
3197 @subsection Short Options Cross Reference
3198
3199 Here is an alphabetized list of all of the short option forms, matching
3200 them with the equivalent long option.
3201
3202 @multitable @columnfractions 0.20 0.80
3203 @headitem Short Option @tab Reference
3204
3205 @item -A @tab @ref{--concatenate}.
3206
3207 @item -B @tab @ref{--read-full-records}.
3208
3209 @item -C @tab @ref{--directory}.
3210
3211 @item -F @tab @ref{--info-script}.
3212
3213 @item -G @tab @ref{--incremental}.
3214
3215 @item -K @tab @ref{--starting-file}.
3216
3217 @item -L @tab @ref{--tape-length}.
3218
3219 @item -M @tab @ref{--multi-volume}.
3220
3221 @item -N @tab @ref{--newer}.
3222
3223 @item -O @tab @ref{--to-stdout}.
3224
3225 @item -P @tab @ref{--absolute-names}.
3226
3227 @item -R @tab @ref{--block-number}.
3228
3229 @item -S @tab @ref{--sparse}.
3230
3231 @item -T @tab @ref{--files-from}.
3232
3233 @item -U @tab @ref{--unlink-first}.
3234
3235 @item -V @tab @ref{--label}.
3236
3237 @item -W @tab @ref{--verify}.
3238
3239 @item -X @tab @ref{--exclude-from}.
3240
3241 @item -Z @tab @ref{--compress}.
3242
3243 @item -b @tab @ref{--blocking-factor}.
3244
3245 @item -c @tab @ref{--create}.
3246
3247 @item -d @tab @ref{--compare}.
3248
3249 @item -f @tab @ref{--file}.
3250
3251 @item -g @tab @ref{--listed-incremental}.
3252
3253 @item -h @tab @ref{--dereference}.
3254
3255 @item -i @tab @ref{--ignore-zeros}.
3256
3257 @item -j @tab @ref{--bzip2}.
3258
3259 @item -k @tab @ref{--keep-old-files}.
3260
3261 @item -l @tab @ref{--check-links}.
3262
3263 @item -m @tab @ref{--touch}.
3264
3265 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3266 @ref{--portability}.
3267
3268 The later usage is deprecated. It is retained for compatibility with
3269 the earlier versions of @GNUTAR{}. In the future releases
3270 @option{-o} will be equivalent to @option{--no-same-owner} only.
3271
3272 @item -p @tab @ref{--preserve-permissions}.
3273
3274 @item -r @tab @ref{--append}.
3275
3276 @item -s @tab @ref{--same-order}.
3277
3278 @item -t @tab @ref{--list}.
3279
3280 @item -u @tab @ref{--update}.
3281
3282 @item -v @tab @ref{--verbose}.
3283
3284 @item -w @tab @ref{--interactive}.
3285
3286 @item -x @tab @ref{--extract}.
3287
3288 @item -z @tab @ref{--gzip}.
3289
3290 @end multitable
3291
3292 @node help
3293 @section @GNUTAR{} documentation
3294
3295 @cindex Getting program version number
3296 @opindex version
3297 @cindex Version of the @command{tar} program
3298 Being careful, the first thing is really checking that you are using
3299 @GNUTAR{}, indeed. The @option{--version} option
3300 causes @command{tar} to print information about its name, version,
3301 origin and legal status, all on standard output, and then exit
3302 successfully. For example, @w{@samp{tar --version}} might print:
3303
3304 @smallexample
3305 tar (GNU tar) @value{VERSION}
3306 Copyright (C) 2006 Free Software Foundation, Inc.
3307 This is free software. You may redistribute copies of it under the terms
3308 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3309 There is NO WARRANTY, to the extent permitted by law.
3310
3311 Written by John Gilmore and Jay Fenlason.
3312 @end smallexample
3313
3314 @noindent
3315 The first occurrence of @samp{tar} in the result above is the program
3316 name in the package (for example, @command{rmt} is another program),
3317 while the second occurrence of @samp{tar} is the name of the package
3318 itself, containing possibly many programs. The package is currently
3319 named @samp{tar}, after the name of the main program it
3320 contains@footnote{There are plans to merge the @command{cpio} and
3321 @command{tar} packages into a single one which would be called
3322 @code{paxutils}. So, who knows if, one of this days, the
3323 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3324 paxutils) 3.2}}}.
3325
3326 @cindex Obtaining help
3327 @cindex Listing all @command{tar} options
3328 @xopindex{help, introduction}
3329 Another thing you might want to do is checking the spelling or meaning
3330 of some particular @command{tar} option, without resorting to this
3331 manual, for once you have carefully read it. @GNUTAR{}
3332 has a short help feature, triggerable through the
3333 @option{--help} option. By using this option, @command{tar} will
3334 print a usage message listing all available options on standard
3335 output, then exit successfully, without doing anything else and
3336 ignoring all other options. Even if this is only a brief summary, it
3337 may be several screens long. So, if you are not using some kind of
3338 scrollable window, you might prefer to use something like:
3339
3340 @smallexample
3341 $ @kbd{tar --help | less}
3342 @end smallexample
3343
3344 @noindent
3345 presuming, here, that you like using @command{less} for a pager. Other
3346 popular pagers are @command{more} and @command{pg}. If you know about some
3347 @var{keyword} which interests you and do not want to read all the
3348 @option{--help} output, another common idiom is doing:
3349
3350 @smallexample
3351 tar --help | grep @var{keyword}
3352 @end smallexample
3353
3354 @noindent
3355 for getting only the pertinent lines. Notice, however, that some
3356 @command{tar} options have long description lines and the above
3357 command will list only the first of them.
3358
3359 The exact look of the option summary displayed by @kbd{tar --help} is
3360 configurable. @xref{Configuring Help Summary}, for a detailed description.
3361
3362 @opindex usage
3363 If you only wish to check the spelling of an option, running @kbd{tar
3364 --usage} may be a better choice. This will display a terse list of
3365 @command{tar} option without accompanying explanations.
3366
3367 The short help output is quite succinct, and you might have to get
3368 back to the full documentation for precise points. If you are reading
3369 this paragraph, you already have the @command{tar} manual in some
3370 form. This manual is available in a variety of forms from
3371 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3372 distribution, provided you have @TeX{} already installed somewhere,
3373 and a laser printer around. Just configure the distribution, execute
3374 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3375 usual way (contact your local guru to know how). If @GNUTAR{}
3376 has been conveniently installed at your place, this
3377 manual is also available in interactive, hypertextual form as an Info
3378 file. Just call @w{@samp{info tar}} or, if you do not have the
3379 @command{info} program handy, use the Info reader provided within
3380 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3381
3382 There is currently no @code{man} page for @GNUTAR{}.
3383 If you observe such a @code{man} page on the system you are running,
3384 either it does not belong to @GNUTAR{}, or it has not
3385 been produced by @acronym{GNU}. Some package maintainers convert
3386 @kbd{tar --help} output to a man page, using @command{help2man}. In
3387 any case, please bear in mind that the authoritative source of
3388 information about @GNUTAR{} is this Texinfo documentation.
3389
3390 @node defaults
3391 @section Obtaining @GNUTAR{} default values
3392
3393 @opindex show-defaults
3394 @GNUTAR{} has some predefined defaults that are used when you do not
3395 explicitely specify another values. To obtain a list of such
3396 defaults, use @option{--show-defaults} option. This will output the
3397 values in the form of @command{tar} command line options:
3398
3399 @smallexample
3400 @group
3401 @kbd{tar --show-defaults}
3402 --format=gnu -f- -b20 --quoting-style=escape
3403 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3404 @end group
3405 @end smallexample
3406
3407 @noindent
3408 Notice, that this option outputs only one line. The example output above
3409 has been split to fit page boundaries.
3410
3411 @noindent
3412 The above output shows that this version of @GNUTAR{} defaults to
3413 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3414 output as the archive, if no @option{--file} option has been given
3415 (@pxref{file tutorial}), the default blocking factor is 20
3416 (@pxref{Blocking Factor}). It also shows the default locations where
3417 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3418
3419 @node verbose
3420 @section Checking @command{tar} progress
3421
3422 Typically, @command{tar} performs most operations without reporting any
3423 information to the user except error messages. When using @command{tar}
3424 with many options, particularly ones with complicated or
3425 difficult-to-predict behavior, it is possible to make serious mistakes.
3426 @command{tar} provides several options that make observing @command{tar}
3427 easier. These options cause @command{tar} to print information as it
3428 progresses in its job, and you might want to use them just for being
3429 more careful about what is going on, or merely for entertaining
3430 yourself. If you have encountered a problem when operating on an
3431 archive, however, you may need more information than just an error
3432 message in order to solve the problem. The following options can be
3433 helpful diagnostic tools.
3434
3435 @cindex Verbose operation
3436 @opindex verbose
3437 Normally, the @option{--list} (@option{-t}) command to list an archive
3438 prints just the file names (one per line) and the other commands are
3439 silent. When used with most operations, the @option{--verbose}
3440 (@option{-v}) option causes @command{tar} to print the name of each
3441 file or archive member as it is processed. This and the other options
3442 which make @command{tar} print status information can be useful in
3443 monitoring @command{tar}.
3444
3445 With @option{--create} or @option{--extract}, @option{--verbose} used
3446 once just prints the names of the files or members as they are processed.
3447 Using it twice causes @command{tar} to print a longer listing
3448 (@xref{verbose member listing}, for the description) for each member.
3449 Since @option{--list} already prints the names of the members,
3450 @option{--verbose} used once with @option{--list} causes @command{tar}
3451 to print an @samp{ls -l} type listing of the files in the archive.
3452 The following examples both extract members with long list output:
3453
3454 @smallexample
3455 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3456 $ @kbd{tar xvvf archive.tar}
3457 @end smallexample
3458
3459 Verbose output appears on the standard output except when an archive is
3460 being written to the standard output, as with @samp{tar --create
3461 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3462 installer let standard output be the default archive). In that case
3463 @command{tar} writes verbose output to the standard error stream.
3464
3465 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3466 verbose output to @var{file} rather than to standard output or standard
3467 error.
3468
3469 @anchor{totals}
3470 @cindex Obtaining total status information
3471 @opindex totals
3472 The @option{--totals} option causes @command{tar} to print on the
3473 standard error the total amount of bytes transferred when processing
3474 an archive. When creating or appending to an archive, this option
3475 prints the number of bytes written to the archive and the average
3476 speed at which they have been written, e.g.:
3477
3478 @smallexample
3479 @group
3480 $ @kbd{tar -c -f archive.tar --totals /home}
3481 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3482 @end group
3483 @end smallexample
3484
3485 When reading an archive, this option displays the number of bytes
3486 read:
3487
3488 @smallexample
3489 @group
3490 $ @kbd{tar -x -f archive.tar --totals}
3491 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3492 @end group
3493 @end smallexample
3494
3495 Finally, when deleting from an archive, the @option{--totals} option
3496 displays both numbers plus number of bytes removed from the archive:
3497
3498 @smallexample
3499 @group
3500 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3501 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3502 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3503 Total bytes deleted: 1474048
3504 @end group
3505 @end smallexample
3506
3507 You can also obtain this information on request. When
3508 @option{--totals} is used with an argument, this argument is
3509 interpreted as a symbolic name of a signal, upon delivery of which the
3510 statistics is to be printed:
3511
3512 @table @option
3513 @item --totals=@var{signo}
3514 Print statistics upon delivery of signal @var{signo}. Valid arguments
3515 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3516 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3517 accepted.
3518 @end table
3519
3520 Both forms of @option{--totals} option can be used simultaneously.
3521 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3522 extract all members from its default archive and print statistics
3523 after finishing the extraction, as well as when receiving signal
3524 @code{SIGUSR1}.
3525
3526 @anchor{Progress information}
3527 @cindex Progress information
3528 @opindex checkpoint
3529 The @option{--checkpoint} option prints an occasional message
3530 as @command{tar} reads or writes the archive. It is designed for
3531 those who don't need the more detailed (and voluminous) output of
3532 @option{--block-number} (@option{-R}), but do want visual confirmation
3533 that @command{tar} is actually making forward progress. By default it
3534 prints a message each 10 records read or written. This can be changed
3535 by giving it a numeric argument after an equal sign:
3536
3537 @smallexample
3538 $ @kbd{tar -c --checkpoint=1000} /var
3539 tar: Write checkpoint 1000
3540 tar: Write checkpoint 2000
3541 tar: Write checkpoint 3000
3542 @end smallexample
3543
3544 This example shows the default checkpoint message used by
3545 @command{tar}. If you place a dot immediately after the equal
3546 sign, it will print a @samp{.} at each checkpoint. For example:
3547
3548 @smallexample
3549 $ @kbd{tar -c --checkpoint=.1000} /var
3550 ...
3551 @end smallexample
3552
3553 @opindex show-omitted-dirs
3554 @anchor{show-omitted-dirs}
3555 The @option{--show-omitted-dirs} option, when reading an archive---with
3556 @option{--list} or @option{--extract}, for example---causes a message
3557 to be printed for each directory in the archive which is skipped.
3558 This happens regardless of the reason for skipping: the directory might
3559 not have been named on the command line (implicitly or explicitly),
3560 it might be excluded by the use of the
3561 @option{--exclude=@var{pattern}} option, or some other reason.
3562
3563 @opindex block-number
3564 @cindex Block number where error occurred
3565 @anchor{block-number}
3566 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3567 every message it would normally produce, the block number within the
3568 archive where the message was triggered. Also, supplementary messages
3569 are triggered when reading blocks full of NULs, or when hitting end of
3570 file on the archive. As of now, if the archive if properly terminated
3571 with a NUL block, the reading of the file may stop before end of file
3572 is met, so the position of end of file will not usually show when
3573 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3574 drains the archive before exiting when reading the
3575 archive from a pipe.
3576
3577 @cindex Error message, block number of
3578 This option is especially useful when reading damaged archives, since
3579 it helps pinpoint the damaged sections. It can also be used with
3580 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3581 choose among several backup tapes when retrieving a file later, in
3582 favor of the tape where the file appears earliest (closest to the
3583 front of the tape). @xref{backup}.
3584
3585 @node interactive
3586 @section Asking for Confirmation During Operations
3587 @cindex Interactive operation
3588
3589 Typically, @command{tar} carries out a command without stopping for
3590 further instructions. In some situations however, you may want to
3591 exclude some files and archive members from the operation (for instance
3592 if disk or storage space is tight). You can do this by excluding
3593 certain files automatically (@pxref{Choosing}), or by performing
3594 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3595 @command{tar} also accepts @option{--confirmation} for this option.
3596
3597 @opindex interactive
3598 When the @option{--interactive} (@option{-w}) option is specified, before
3599 reading, writing, or deleting files, @command{tar} first prints a message
3600 for each such file, telling what operation it intends to take, then asks
3601 for confirmation on the terminal. The actions which require
3602 confirmation include adding a file to the archive, extracting a file
3603 from the archive, deleting a file from the archive, and deleting a file
3604 from disk. To confirm the action, you must type a line of input
3605 beginning with @samp{y}. If your input line begins with anything other
3606 than @samp{y}, @command{tar} skips that file.
3607
3608 If @command{tar} is reading the archive from the standard input,
3609 @command{tar} opens the file @file{/dev/tty} to support the interactive
3610 communications.
3611
3612 Verbose output is normally sent to standard output, separate from
3613 other error messages. However, if the archive is produced directly
3614 on standard output, then verbose output is mixed with errors on
3615 @code{stderr}. Producing the archive on standard output may be used
3616 as a way to avoid using disk space, when the archive is soon to be
3617 consumed by another process reading it, say. Some people felt the need
3618 of producing an archive on stdout, still willing to segregate between
3619 verbose output and error output. A possible approach would be using a
3620 named pipe to receive the archive, and having the consumer process to
3621 read from that named pipe. This has the advantage of letting standard
3622 output free to receive verbose output, all separate from errors.
3623
3624 @node operations
3625 @chapter @GNUTAR{} Operations
3626
3627 @menu
3628 * Basic tar::
3629 * Advanced tar::
3630 * create options::
3631 * extract options::
3632 * backup::
3633 * Applications::
3634 * looking ahead::
3635 @end menu
3636
3637 @node Basic tar
3638 @section Basic @GNUTAR{} Operations
3639
3640 The basic @command{tar} operations, @option{--create} (@option{-c}),
3641 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3642 @option{-x}), are currently presented and described in the tutorial
3643 chapter of this manual. This section provides some complementary notes
3644 for these operations.
3645
3646 @table @option
3647 @xopindex{create, complementary notes}
3648 @item --create
3649 @itemx -c
3650
3651 Creating an empty archive would have some kind of elegance. One can
3652 initialize an empty archive and later use @option{--append}
3653 (@option{-r}) for adding all members. Some applications would not
3654 welcome making an exception in the way of adding the first archive
3655 member. On the other hand, many people reported that it is
3656 dangerously too easy for @command{tar} to destroy a magnetic tape with
3657 an empty archive@footnote{This is well described in @cite{Unix-haters
3658 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3659 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3660
3661 @enumerate
3662 @item
3663 Mistakingly using @code{create} instead of @code{extract}, when the
3664 intent was to extract the full contents of an archive. This error
3665 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3666 the QWERTY keyboard. Instead of being unpacked, the archive then
3667 gets wholly destroyed. When users speak about @dfn{exploding} an
3668 archive, they usually mean something else :-).
3669
3670 @item
3671 Forgetting the argument to @code{file}, when the intent was to create
3672 an archive with a single file in it. This error is likely because a
3673 tired user can easily add the @kbd{f} key to the cluster of option
3674 letters, by the mere force of habit, without realizing the full
3675 consequence of doing so. The usual consequence is that the single
3676 file, which was meant to be saved, is rather destroyed.
3677 @end enumerate
3678
3679 So, recognizing the likelihood and the catastrophical nature of these
3680 errors, @GNUTAR{} now takes some distance from elegance, and
3681 cowardly refuses to create an archive when @option{--create} option is
3682 given, there are no arguments besides options, and
3683 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3684 around the cautiousness of @GNUTAR{} and nevertheless create an
3685 archive with nothing in it, one may still use, as the value for the
3686 @option{--files-from} option, a file with no names in it, as shown in
3687 the following commands:
3688
3689 @smallexample
3690 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3691 @kbd{tar cfT empty-archive.tar /dev/null}
3692 @end smallexample
3693
3694 @xopindex{extract, complementary notes}
3695 @item --extract
3696 @itemx --get
3697 @itemx -x
3698
3699 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3700
3701 @item @option{--list} (@option{-t})
3702
3703 @GNUTAR{} now shows dates as @samp{1996-08-30},
3704 while it used to show them as @samp{Aug 30 1996}. Preferably,
3705 people should get used to ISO 8601 dates. Local American dates should
3706 be made available again with full date localization support, once
3707 ready. In the meantime, programs not being localizable for dates
3708 should prefer international dates, that's really the way to go.
3709
3710 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3711 are curious, it contains a detailed explanation of the ISO 8601 standard.
3712
3713 @end table
3714
3715 @node Advanced tar
3716 @section Advanced @GNUTAR{} Operations
3717
3718 Now that you have learned the basics of using @GNUTAR{}, you may want
3719 to learn about further ways in which @command{tar} can help you.
3720
3721 This chapter presents five, more advanced operations which you probably
3722 won't use on a daily basis, but which serve more specialized functions.
3723 We also explain the different styles of options and why you might want
3724 to use one or another, or a combination of them in your @command{tar}
3725 commands. Additionally, this chapter includes options which allow you to
3726 define the output from @command{tar} more carefully, and provide help and
3727 error correction in special circumstances.
3728
3729 @FIXME{check this after the chapter is actually revised to make sure
3730 it still introduces the info in the chapter correctly : ).}
3731
3732 @menu
3733 * Operations::
3734 * append::
3735 * update::
3736 * concatenate::
3737 * delete::
3738 * compare::
3739 @end menu
3740
3741 @node Operations
3742 @subsection The Five Advanced @command{tar} Operations
3743 @UNREVISED
3744
3745 In the last chapter, you learned about the first three operations to
3746 @command{tar}. This chapter presents the remaining five operations to
3747 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3748 @option{--delete}, and @option{--compare}.
3749
3750 You are not likely to use these operations as frequently as those
3751 covered in the last chapter; however, since they perform specialized
3752 functions, they are quite useful when you do need to use them. We
3753 will give examples using the same directory and files that you created
3754 in the last chapter. As you may recall, the directory is called
3755 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3756 @samp{rock}, and the two archive files you created are
3757 @samp{collection.tar} and @samp{music.tar}.
3758
3759 We will also use the archive files @samp{afiles.tar} and
3760 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3761 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3762 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3763
3764 Unless we state otherwise, all practicing you do and examples you follow
3765 in this chapter will take place in the @file{practice} directory that
3766 you created in the previous chapter; see @ref{prepare for examples}.
3767 (Below in this section, we will remind you of the state of the examples
3768 where the last chapter left them.)
3769
3770 The five operations that we will cover in this chapter are:
3771
3772 @table @option
3773 @item --append
3774 @itemx -r
3775 Add new entries to an archive that already exists.
3776 @item --update
3777 @itemx -r
3778 Add more recent copies of archive members to the end of an archive, if
3779 they exist.
3780 @item --concatenate
3781 @itemx --catenate
3782 @itemx -A
3783 Add one or more pre-existing archives to the end of another archive.
3784 @item --delete
3785 Delete items from an archive (does not work on tapes).
3786 @item --compare
3787 @itemx --diff
3788 @itemx -d
3789 Compare archive members to their counterparts in the file system.
3790 @end table
3791
3792 @node append
3793 @subsection How to Add Files to Existing Archives: @option{--append}
3794 @UNREVISED
3795
3796 @opindex append
3797 If you want to add files to an existing archive, you don't need to
3798 create a new archive; you can use @option{--append} (@option{-r}).
3799 The archive must already exist in order to use @option{--append}. (A
3800 related operation is the @option{--update} operation; you can use this
3801 to add newer versions of archive members to an existing archive. To learn how to
3802 do this with @option{--update}, @pxref{update}.)
3803
3804 If you use @option{--append} to add a file that has the same name as an
3805 archive member to an archive containing that archive member, then the
3806 old member is not deleted. What does happen, however, is somewhat
3807 complex. @command{tar} @emph{allows} you to have infinite number of files
3808 with the same name. Some operations treat these same-named members no
3809 differently than any other set of archive members: for example, if you
3810 view an archive with @option{--list} (@option{-t}), you will see all
3811 of those members listed, with their data modification times, owners, etc.
3812
3813 Other operations don't deal with these members as perfectly as you might
3814 prefer; if you were to use @option{--extract} to extract the archive,
3815 only the most recently added copy of a member with the same name as four
3816 other members would end up in the working directory. This is because
3817 @option{--extract} extracts an archive in the order the members appeared
3818 in the archive; the most recently archived members will be extracted
3819 last. Additionally, an extracted member will @emph{replace} a file of
3820 the same name which existed in the directory already, and @command{tar}
3821 will not prompt you about this@footnote{Unless you give it
3822 @option{--keep-old-files} option, or the disk copy is newer than the
3823 the one in the archive and you invoke @command{tar} with
3824 @option{--keep-newer-files} option}. Thus, only the most recently archived
3825 member will end up being extracted, as it will replace the one
3826 extracted before it, and so on.
3827
3828 There exists a special option that allows you to get around this
3829 behavior and extract (or list) only a particular copy of the file.
3830 This is @option{--occurrence} option. If you run @command{tar} with
3831 this option, it will extract only the first copy of the file. You
3832 may also give this option an argument specifying the number of
3833 copy to be extracted. Thus, for example if the archive
3834 @file{archive.tar} contained three copies of file @file{myfile}, then
3835 the command
3836
3837 @smallexample
3838 tar --extract --file archive.tar --occurrence=2 myfile
3839 @end smallexample
3840
3841 @noindent
3842 would extract only the second copy. @xref{Option
3843 Summary,---occurrence}, for the description of @option{--occurrence}
3844 option.
3845
3846 @FIXME{ hag -- you might want to incorporate some of the above into the
3847 MMwtSN node; not sure. i didn't know how to make it simpler...
3848
3849 There are a few ways to get around this. (maybe xref Multiple Members
3850 with the Same Name.}
3851
3852 @cindex Members, replacing with other members
3853 @cindex Replacing members with other members
3854 If you want to replace an archive member, use @option{--delete} to
3855 delete the member you want to remove from the archive, , and then use
3856 @option{--append} to add the member you want to be in the archive. Note
3857 that you can not change the order of the archive; the most recently
3858 added member will still appear last. In this sense, you cannot truly
3859 ``replace'' one member with another. (Replacing one member with another
3860 will not work on certain types of media, such as tapes; see @ref{delete}
3861 and @ref{Media}, for more information.)
3862
3863 @menu
3864 * appending files:: Appending Files to an Archive
3865 * multiple::
3866 @end menu
3867
3868 @node appending files
3869 @subsubsection Appending Files to an Archive
3870 @UNREVISED
3871 @cindex Adding files to an Archive
3872 @cindex Appending files to an Archive
3873 @cindex Archives, Appending files to
3874
3875 The simplest way to add a file to an already existing archive is the
3876 @option{--append} (@option{-r}) operation, which writes specified
3877 files into the archive whether or not they are already among the
3878 archived files.
3879
3880 When you use @option{--append}, you @emph{must} specify file name
3881 arguments, as there is no default. If you specify a file that already
3882 exists in the archive, another copy of the file will be added to the
3883 end of the archive. As with other operations, the member names of the
3884 newly added files will be exactly the same as their names given on the
3885 command line. The @option{--verbose} (@option{-v}) option will print
3886 out the names of the files as they are written into the archive.
3887
3888 @option{--append} cannot be performed on some tape drives, unfortunately,
3889 due to deficiencies in the formats those tape drives use. The archive
3890 must be a valid @command{tar} archive, or else the results of using this
3891 operation will be unpredictable. @xref{Media}.
3892
3893 To demonstrate using @option{--append} to add a file to an archive,
3894 create a file called @file{rock} in the @file{practice} directory.
3895 Make sure you are in the @file{practice} directory. Then, run the
3896 following @command{tar} command to add @file{rock} to
3897 @file{collection.tar}:
3898
3899 @smallexample
3900 $ @kbd{tar --append --file=collection.tar rock}
3901 @end smallexample
3902
3903 @noindent
3904 If you now use the @option{--list} (@option{-t}) operation, you will see that
3905 @file{rock} has been added to the archive:
3906
3907 @smallexample
3908 $ @kbd{tar --list --file=collection.tar}
3909 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3910 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3911 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3912 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3913 @end smallexample
3914
3915 @node multiple
3916 @subsubsection Multiple Members with the Same Name
3917
3918 You can use @option{--append} (@option{-r}) to add copies of files
3919 which have been updated since the archive was created. (However, we
3920 do not recommend doing this since there is another @command{tar}
3921 option called @option{--update}; @xref{update}, for more information.
3922 We describe this use of @option{--append} here for the sake of
3923 completeness.) When you extract the archive, the older version will
3924 be effectively lost. This works because files are extracted from an
3925 archive in the order in which they were archived. Thus, when the
3926 archive is extracted, a file archived later in time will replace a
3927 file of the same name which was archived earlier, even though the
3928 older version of the file will remain in the archive unless you delete
3929 all versions of the file.
3930
3931 Supposing you change the file @file{blues} and then append the changed
3932 version to @file{collection.tar}. As you saw above, the original
3933 @file{blues} is in the archive @file{collection.tar}. If you change the
3934 file and append the new version of the file to the archive, there will
3935 be two copies in the archive. When you extract the archive, the older
3936 version of the file will be extracted first, and then replaced by the
3937 newer version when it is extracted.
3938
3939 You can append the new, changed copy of the file @file{blues} to the
3940 archive in this way:
3941
3942 @smallexample
3943 $ @kbd{tar --append --verbose --file=collection.tar blues}
3944 blues
3945 @end smallexample
3946
3947 @noindent
3948 Because you specified the @option{--verbose} option, @command{tar} has
3949 printed the name of the file being appended as it was acted on. Now
3950 list the contents of the archive:
3951
3952 @smallexample
3953 $ @kbd{tar --list --verbose --file=collection.tar}
3954 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3955 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3956 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3957 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3958 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3959 @end smallexample
3960
3961 @noindent
3962 The newest version of @file{blues} is now at the end of the archive
3963 (note the different creation dates and file sizes). If you extract
3964 the archive, the older version of the file @file{blues} will be
3965 replaced by the newer version. You can confirm this by extracting
3966 the archive and running @samp{ls} on the directory.
3967
3968 If you wish to extract the first occurrence of the file @file{blues}
3969 from the archive, use @option{--occurrence} option, as shown in
3970 the following example:
3971
3972 @smallexample
3973 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
3974 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3975 @end smallexample
3976
3977 @xref{Writing}, for more information on @option{--extract} and
3978 @xref{Option Summary, --occurrence}, for the description of
3979 @option{--occurrence} option.
3980
3981 @node update
3982 @subsection Updating an Archive
3983 @UNREVISED
3984 @cindex Updating an archive
3985
3986 @opindex update
3987 In the previous section, you learned how to use @option{--append} to
3988 add a file to an existing archive. A related operation is
3989 @option{--update} (@option{-u}). The @option{--update} operation
3990 updates a @command{tar} archive by comparing the date of the specified
3991 archive members against the date of the file with the same name. If
3992 the file has been modified more recently than the archive member, then
3993 the newer version of the file is added to the archive (as with
3994 @option{--append}).
3995
3996 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
3997 The operation will fail.
3998
3999 @FIXME{other examples of media on which --update will fail? need to ask
4000 charles and/or mib/thomas/dave shevett..}
4001
4002 Both @option{--update} and @option{--append} work by adding to the end
4003 of the archive. When you extract a file from the archive, only the
4004 version stored last will wind up in the file system, unless you use
4005 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4006
4007 @menu
4008 * how to update::
4009 @end menu
4010
4011 @node how to update
4012 @subsubsection How to Update an Archive Using @option{--update}
4013
4014 You must use file name arguments with the @option{--update}
4015 (@option{-u}) operation. If you don't specify any files,
4016 @command{tar} won't act on any files and won't tell you that it didn't
4017 do anything (which may end up confusing you).
4018
4019 @c note: the above parenthetical added because in fact, this
4020 @c behavior just confused the author. :-)
4021
4022 To see the @option{--update} option at work, create a new file,
4023 @file{classical}, in your practice directory, and some extra text to the
4024 file @file{blues}, using any text editor. Then invoke @command{tar} with
4025 the @samp{update} operation and the @option{--verbose} (@option{-v})
4026 option specified, using the names of all the files in the practice
4027 directory as file name arguments:
4028
4029 @smallexample
4030 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4031 blues
4032 classical
4033 $
4034 @end smallexample
4035
4036 @noindent
4037 Because we have specified verbose mode, @command{tar} prints out the names
4038 of the files it is working on, which in this case are the names of the
4039 files that needed to be updated. If you run @samp{tar --list} and look
4040 at the archive, you will see @file{blues} and @file{classical} at its
4041 end. There will be a total of two versions of the member @samp{blues};
4042 the one at the end will be newer and larger, since you added text before
4043 updating it.
4044
4045 (The reason @command{tar} does not overwrite the older file when updating
4046 it is because writing to the middle of a section of tape is a difficult
4047 process. Tapes are not designed to go backward. @xref{Media}, for more
4048 information about tapes.
4049
4050 @option{--update} (@option{-u}) is not suitable for performing backups for two
4051 reasons: it does not change directory content entries, and it
4052 lengthens the archive every time it is used. The @GNUTAR{}
4053 options intended specifically for backups are more
4054 efficient. If you need to run backups, please consult @ref{Backups}.
4055
4056 @node concatenate
4057 @subsection Combining Archives with @option{--concatenate}
4058
4059 @cindex Adding archives to an archive
4060 @cindex Concatenating Archives
4061 @opindex concatenate
4062 @opindex catenate
4063 @c @cindex @option{-A} described
4064 Sometimes it may be convenient to add a second archive onto the end of
4065 an archive rather than adding individual files to the archive. To add
4066 one or more archives to the end of another archive, you should use the
4067 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4068
4069 To use @option{--concatenate}, give the first archive with
4070 @option{--file} option and name the rest of archives to be
4071 concatenated on the command line. The members, and their member
4072 names, will be copied verbatim from those archives to the first one.
4073 @footnote{This can cause multiple members to have the same name, for
4074 information on how this affects reading the archive, @ref{multiple}.}
4075 The new, concatenated archive will be called by the same name as the
4076 one given with the @option{--file} option. As usual, if you omit
4077 @option{--file}, @command{tar} will use the value of the environment
4078 variable @env{TAPE}, or, if this has not been set, the default archive name.
4079
4080 @FIXME{There is no way to specify a new name...}
4081
4082 To demonstrate how @option{--concatenate} works, create two small archives
4083 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4084 files from @file{practice}:
4085
4086 @smallexample
4087 $ @kbd{tar -cvf bluesrock.tar blues rock}
4088 blues
4089 rock
4090 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4091 folk
4092 jazz
4093 @end smallexample
4094
4095 @noindent
4096 If you like, You can run @samp{tar --list} to make sure the archives
4097 contain what they are supposed to:
4098
4099 @smallexample
4100 $ @kbd{tar -tvf bluesrock.tar}
4101 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4102 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4103 $ @kbd{tar -tvf jazzfolk.tar}
4104 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4105 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4106 @end smallexample
4107
4108 We can concatenate these two archives with @command{tar}:
4109
4110 @smallexample
4111 $ @kbd{cd ..}
4112 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4113 @end smallexample
4114
4115 If you now list the contents of the @file{bluesrock.tar}, you will see
4116 that now it also contains the archive members of @file{jazzfolk.tar}:
4117
4118 @smallexample
4119 $ @kbd{tar --list --file=bluesrock.tar}
4120 blues
4121 rock
4122 folk
4123 jazz
4124 @end smallexample
4125
4126 When you use @option{--concatenate}, the source and target archives must
4127 already exist and must have been created using compatible format
4128 parameters. Notice, that @command{tar} does not check whether the
4129 archives it concatenates have compatible formats, it does not
4130 even check if the files are really tar archives.
4131
4132 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4133 tape drives, due to deficiencies in the formats those tape drives use.
4134
4135 @cindex @code{concatenate} vs @command{cat}
4136 @cindex @command{cat} vs @code{concatenate}
4137 It may seem more intuitive to you to want or try to use @command{cat} to
4138 concatenate two archives instead of using the @option{--concatenate}
4139 operation; after all, @command{cat} is the utility for combining files.
4140
4141 However, @command{tar} archives incorporate an end-of-file marker which
4142 must be removed if the concatenated archives are to be read properly as
4143 one archive. @option{--concatenate} removes the end-of-archive marker
4144 from the target archive before each new archive is appended. If you use
4145 @command{cat} to combine the archives, the result will not be a valid
4146 @command{tar} format archive. If you need to retrieve files from an
4147 archive that was added to using the @command{cat} utility, use the
4148 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4149 information on dealing with archives improperly combined using the
4150 @command{cat} shell utility.
4151
4152 @node delete
4153 @subsection Removing Archive Members Using @option{--delete}
4154 @UNREVISED
4155 @cindex Deleting files from an archive
4156 @cindex Removing files from an archive
4157
4158 @opindex delete
4159 You can remove members from an archive by using the @option{--delete}
4160 option. Specify the name of the archive with @option{--file}
4161 (@option{-f}) and then specify the names of the members to be deleted;
4162 if you list no member names, nothing will be deleted. The
4163 @option{--verbose} option will cause @command{tar} to print the names
4164 of the members as they are deleted. As with @option{--extract}, you
4165 must give the exact member names when using @samp{tar --delete}.
4166 @option{--delete} will remove all versions of the named file from the
4167 archive. The @option{--delete} operation can run very slowly.
4168
4169 Unlike other operations, @option{--delete} has no short form.
4170
4171 @cindex Tapes, using @option{--delete} and
4172 @cindex Deleting from tape archives
4173 This operation will rewrite the archive. You can only use
4174 @option{--delete} on an archive if the archive device allows you to
4175 write to any point on the media, such as a disk; because of this, it
4176 does not work on magnetic tapes. Do not try to delete an archive member
4177 from a magnetic tape; the action will not succeed, and you will be
4178 likely to scramble the archive and damage your tape. There is no safe
4179 way (except by completely re-writing the archive) to delete files from
4180 most kinds of magnetic tape. @xref{Media}.
4181
4182 To delete all versions of the file @file{blues} from the archive
4183 @file{collection.tar} in the @file{practice} directory, make sure you
4184 are in that directory, and then,
4185
4186 @smallexample
4187 $ @kbd{tar --list --file=collection.tar}
4188 blues
4189 folk
4190 jazz
4191 rock
4192 $ @kbd{tar --delete --file=collection.tar blues}
4193 $ @kbd{tar --list --file=collection.tar}
4194 folk
4195 jazz
4196 rock
4197 $
4198 @end smallexample
4199
4200 @FIXME{Check if the above listing is actually produced after running
4201 all the examples on collection.tar.}
4202
4203 The @option{--delete} option has been reported to work properly when
4204 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4205
4206 @node compare
4207 @subsection Comparing Archive Members with the File System
4208 @cindex Verifying the currency of an archive
4209 @UNREVISED
4210
4211 @opindex compare
4212 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4213 specified archive members against files with the same names, and then
4214 reports differences in file size, mode, owner, modification date and
4215 contents. You should @emph{only} specify archive member names, not file
4216 names. If you do not name any members, then @command{tar} will compare the
4217 entire archive. If a file is represented in the archive but does not
4218 exist in the file system, @command{tar} reports a difference.
4219
4220 You have to specify the record size of the archive when modifying an
4221 archive with a non-default record size.
4222
4223 @command{tar} ignores files in the file system that do not have
4224 corresponding members in the archive.
4225
4226 The following example compares the archive members @file{rock},
4227 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4228 files of the same name in the file system. (Note that there is no file,
4229 @file{funk}; @command{tar} will report an error message.)
4230
4231 @smallexample
4232 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4233 rock
4234 blues
4235 tar: funk not found in archive
4236 @end smallexample
4237
4238 The spirit behind the @option{--compare} (@option{--diff},
4239 @option{-d}) option is to check whether the archive represents the
4240 current state of files on disk, more than validating the integrity of
4241 the archive media. For this later goal, @xref{verify}.
4242
4243 @node create options
4244 @section Options Used by @option{--create}
4245
4246 @xopindex{create, additional options}
4247 The previous chapter described the basics of how to use
4248 @option{--create} (@option{-c}) to create an archive from a set of files.
4249 @xref{create}. This section described advanced options to be used with
4250 @option{--create}.
4251
4252 @menu
4253 * override:: Overriding File Metadata.
4254 * Ignore Failed Read::
4255 @end menu
4256
4257 @node override
4258 @subsection Overriding File Metadata
4259
4260 As described above, a @command{tar} archive keeps, for each member it contains,
4261 its @dfn{metadata}, such as modification time, mode and ownership of
4262 the file. @GNUTAR{} allows to replace these data with other values
4263 when adding files to the archive. The options described in this
4264 section affect creation of archives of any type. For POSIX archives,
4265 see also @ref{PAX keywords}, for additional ways of controlling
4266 metadata, stored in the archive.
4267
4268 @table @option
4269 @opindex mode
4270 @item --mode=@var{permissions}
4271
4272 When adding files to an archive, @command{tar} will use
4273 @var{permissions} for the archive members, rather than the permissions
4274 from the files. @var{permissions} can be specified either as an octal
4275 number or as symbolic permissions, like with
4276 @command{chmod} (@xref{File permissions, Permissions, File
4277 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4278 also has useful information for those not being overly familiar with
4279 the UNIX permission system). Using latter syntax allows for
4280 more flexibility. For example, the value @samp{a+rw} adds read and write
4281 permissions for everybody, while retaining executable bits on directories
4282 or on any other file already marked as executable:
4283
4284 @smallexample
4285 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4286 @end smallexample
4287
4288 @item --mtime=@var{date}
4289 @opindex mtime
4290
4291 When adding files to an archive, @command{tar} will use @var{date} as
4292 the modification time of members when creating archives, instead of
4293 their actual modification times. The argument @var{date} can be
4294 either a textual date representation in almost arbitrary format
4295 (@pxref{Date input formats}) or a name of the existing file, starting
4296 with @samp{/} or @samp{.}. In the latter case, the modification time
4297 of that file will be used.
4298
4299 The following example will set the modification date to 00:00:00 UTC,
4300 January 1, 1970:
4301
4302 @smallexample
4303 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4304 @end smallexample
4305
4306 @noindent
4307 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4308 will try to convert the specified date back to its textual
4309 representation and compare it with the one given with
4310 @option{--mtime} options. If the two dates differ, @command{tar} will
4311 print a warning saying what date it will use. This is to help user
4312 ensure he is using the right date.
4313
4314 For example:
4315
4316 @smallexample
4317 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4318 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4319 13:06:29.152478
4320 @dots{}
4321 @end smallexample
4322
4323 @item --owner=@var{user}
4324 @opindex owner
4325
4326 Specifies that @command{tar} should use @var{user} as the owner of members
4327 when creating archives, instead of the user associated with the source
4328 file. The argument @var{user} can be either an existing user symbolic
4329 name, or a decimal numeric user ID.
4330
4331 There is no value indicating a missing number, and @samp{0} usually means
4332 @code{root}. Some people like to force @samp{0} as the value to offer in
4333 their distributions for the owner of files, because the @code{root} user is
4334 anonymous anyway, so that might as well be the owner of anonymous
4335 archives. For example:
4336
4337 @smallexample
4338 @group
4339 $ @kbd{tar -c -f archive.tar --owner=0 .}
4340 # @r{Or:}
4341 $ @kbd{tar -c -f archive.tar --owner=root .}
4342 @end group
4343 @end smallexample
4344
4345 @item --group=@var{group}
4346 @opindex group
4347
4348 Files added to the @command{tar} archive will have a group id of @var{group},
4349 rather than the group from the source file. The argument @var{group}
4350 can be either an existing group symbolic name, or a decimal numeric group ID.
4351 @end table
4352
4353 @node Ignore Failed Read
4354 @subsection Ignore Fail Read
4355
4356 @table @option
4357 @item --ignore-failed-read
4358 @opindex ignore-failed-read
4359 Do not exit with nonzero on unreadable files or directories.
4360 @end table
4361
4362 @node extract options
4363 @section Options Used by @option{--extract}
4364 @UNREVISED
4365
4366 @xopindex{extract, additional options}
4367 The previous chapter showed how to use @option{--extract} to extract
4368 an archive into the file system. Various options cause @command{tar} to
4369 extract more information than just file contents, such as the owner,
4370 the permissions, the modification date, and so forth. This section
4371 presents options to be used with @option{--extract} when certain special
4372 considerations arise. You may review the information presented in
4373 @ref{extract} for more basic information about the
4374 @option{--extract} operation.
4375
4376 @menu
4377 * Reading:: Options to Help Read Archives
4378 * Writing:: Changing How @command{tar} Writes Files
4379 * Scarce:: Coping with Scarce Resources
4380 @end menu
4381
4382 @node Reading
4383 @subsection Options to Help Read Archives
4384 @cindex Options when reading archives
4385 @UNREVISED
4386
4387 @cindex Reading incomplete records
4388 @cindex Records, incomplete
4389 @opindex read-full-records
4390 Normally, @command{tar} will request data in full record increments from
4391 an archive storage device. If the device cannot return a full record,
4392 @command{tar} will report an error. However, some devices do not always
4393 return full records, or do not require the last record of an archive to
4394 be padded out to the next record boundary. To keep reading until you
4395 obtain a full record, or to accept an incomplete record if it contains
4396 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4397 in conjunction with the @option{--extract} or @option{--list} operations.
4398 @xref{Blocking}.
4399
4400 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4401 @command{tar} reads an archive from standard input, or from a remote
4402 machine. This is because on BSD Unix systems, attempting to read a
4403 pipe returns however much happens to be in the pipe, even if it is
4404 less than was requested. If this option were not enabled, @command{tar}
4405 would fail as soon as it read an incomplete record from the pipe.
4406
4407 If you're not sure of the blocking factor of an archive, you can
4408 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4409 @option{--blocking-factor=@var{512-size}} (@option{-b
4410 @var{512-size}}), using a blocking factor larger than what the archive
4411 uses. This lets you avoid having to determine the blocking factor
4412 of an archive. @xref{Blocking Factor}.
4413
4414 @menu
4415 * read full records::
4416 * Ignore Zeros::
4417 @end menu
4418
4419 @node read full records
4420 @unnumberedsubsubsec Reading Full Records
4421
4422 @FIXME{need sentence or so of intro here}
4423
4424 @table @option
4425 @opindex read-full-records
4426 @item --read-full-records
4427 @item -B
4428 Use in conjunction with @option{--extract} (@option{--get},
4429 @option{-x}) to read an archive which contains incomplete records, or
4430 one which has a blocking factor less than the one specified.
4431 @end table
4432
4433 @node Ignore Zeros
4434 @unnumberedsubsubsec Ignoring Blocks of Zeros
4435
4436 @cindex End-of-archive blocks, ignoring
4437 @cindex Ignoring end-of-archive blocks
4438 @opindex ignore-zeros
4439 Normally, @command{tar} stops reading when it encounters a block of zeros
4440 between file entries (which usually indicates the end of the archive).
4441 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4442 completely read an archive which contains a block of zeros before the
4443 end (i.e., a damaged archive, or one that was created by concatenating
4444 several archives together).
4445
4446 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4447 versions of @command{tar} write garbage after the end-of-archive entry,
4448 since that part of the media is never supposed to be read. @GNUTAR{}
4449 does not write after the end of an archive, but seeks to
4450 maintain compatiblity among archiving utilities.
4451
4452 @table @option
4453 @item --ignore-zeros
4454 @itemx -i
4455 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4456 encountered while reading an archive. Use in conjunction with
4457 @option{--extract} or @option{--list}.
4458 @end table
4459
4460 @node Writing
4461 @subsection Changing How @command{tar} Writes Files
4462 @UNREVISED
4463
4464 @FIXME{Introductory paragraph}
4465
4466 @menu
4467 * Dealing with Old Files::
4468 * Overwrite Old Files::
4469 * Keep Old Files::
4470 * Keep Newer Files::
4471 * Unlink First::
4472 * Recursive Unlink::
4473 * Data Modification Times::
4474 * Setting Access Permissions::
4475 * Directory Modification Times and Permissions::
4476 * Writing to Standard Output::
4477 * Writing to an External Program::
4478 * remove files::
4479 @end menu
4480
4481 @node Dealing with Old Files
4482 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4483
4484 @xopindex{overwrite-dir, introduced}
4485 When extracting files, if @command{tar} discovers that the extracted
4486 file already exists, it normally replaces the file by removing it before
4487 extracting it, to prevent confusion in the presence of hard or symbolic
4488 links. (If the existing file is a symbolic link, it is removed, not
4489 followed.) However, if a directory cannot be removed because it is
4490 nonempty, @command{tar} normally overwrites its metadata (ownership,
4491 permission, etc.). The @option{--overwrite-dir} option enables this
4492 default behavior. To be more cautious and preserve the metadata of
4493 such a directory, use the @option{--no-overwrite-dir} option.
4494
4495 @cindex Overwriting old files, prevention
4496 @xopindex{keep-old-files, introduced}
4497 To be even more cautious and prevent existing files from being replaced, use
4498 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4499 to replace or update a file that already exists, i.e., a file with the
4500 same name as an archive member prevents extraction of that archive
4501 member. Instead, it reports an error.
4502
4503 @xopindex{overwrite, introduced}
4504 To be more aggressive about altering existing files, use the
4505 @option{--overwrite} option. It causes @command{tar} to overwrite
4506 existing files and to follow existing symbolic links when extracting.
4507
4508 @cindex Protecting old files
4509 Some people argue that @GNUTAR{} should not hesitate
4510 to overwrite files with other files when extracting. When extracting
4511 a @command{tar} archive, they expect to see a faithful copy of the
4512 state of the file system when the archive was created. It is debatable
4513 that this would always be a proper behavior. For example, suppose one
4514 has an archive in which @file{usr/local} is a link to
4515 @file{usr/local2}. Since then, maybe the site removed the link and
4516 renamed the whole hierarchy from @file{/usr/local2} to
4517 @file{/usr/local}. Such things happen all the time. I guess it would
4518 not be welcome at all that @GNUTAR{} removes the
4519 whole hierarchy just to make room for the link to be reinstated
4520 (unless it @emph{also} simultaneously restores the full
4521 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4522 able to remove a whole hierarchy to reestablish a symbolic link, for
4523 example, but @emph{only if} @option{--recursive-unlink} is specified
4524 to allow this behavior. In any case, single files are silently
4525 removed.
4526
4527 @xopindex{unlink-first, introduced}
4528 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4529 some cases by causing @command{tar} to remove files unconditionally
4530 before extracting them.
4531
4532 @node Overwrite Old Files
4533 @unnumberedsubsubsec Overwrite Old Files
4534
4535 @table @option
4536 @opindex overwrite
4537 @item --overwrite
4538 Overwrite existing files and directory metadata when extracting files
4539 from an archive.
4540
4541 This causes @command{tar} to write extracted files into the file system without
4542 regard to the files already on the system; i.e., files with the same
4543 names as archive members are overwritten when the archive is extracted.
4544 It also causes @command{tar} to extract the ownership, permissions,
4545 and time stamps onto any preexisting files or directories.
4546 If the name of a corresponding file name is a symbolic link, the file
4547 pointed to by the symbolic link will be overwritten instead of the
4548 symbolic link itself (if this is possible). Moreover, special devices,
4549 empty directories and even symbolic links are automatically removed if
4550 they are in the way of extraction.
4551
4552 Be careful when using the @option{--overwrite} option, particularly when
4553 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4554 can change the contents, ownership or permissions of any file on your
4555 system. Also, many systems do not take kindly to overwriting files that
4556 are currently being executed.
4557
4558 @opindex overwrite-dir
4559 @item --overwrite-dir
4560 Overwrite the metadata of directories when extracting files from an
4561 archive, but remove other files before extracting.
4562 @end table
4563
4564 @node Keep Old Files
4565 @unnumberedsubsubsec Keep Old Files
4566
4567 @table @option
4568 @opindex keep-old-files
4569 @item --keep-old-files
4570 @itemx -k
4571 Do not replace existing files from archive. The
4572 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4573 from replacing existing files with files with the same name from the
4574 archive. The @option{--keep-old-files} option is meaningless with
4575 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4576 files in the file system during extraction.
4577 @end table
4578
4579 @node Keep Newer Files
4580 @unnumberedsubsubsec Keep Newer Files
4581
4582 @table @option
4583 @opindex keep-newer-files
4584 @item --keep-newer-files
4585 Do not replace existing files that are newer than their archive
4586 copies. This option is meaningless with @option{--list} (@option{-t}).
4587 @end table
4588
4589 @node Unlink First
4590 @unnumberedsubsubsec Unlink First
4591
4592 @table @option
4593 @opindex unlink-first
4594 @item --unlink-first
4595 @itemx -U
4596 Remove files before extracting over them.
4597 This can make @command{tar} run a bit faster if you know in advance
4598 that the extracted files all need to be removed. Normally this option
4599 slows @command{tar} down slightly, so it is disabled by default.
4600 @end table
4601
4602 @node Recursive Unlink
4603 @unnumberedsubsubsec Recursive Unlink
4604
4605 @table @option
4606 @opindex recursive-unlink
4607 @item --recursive-unlink
4608 When this option is specified, try removing files and directory hierarchies
4609 before extracting over them. @emph{This is a dangerous option!}
4610 @end table
4611
4612 If you specify the @option{--recursive-unlink} option,
4613 @command{tar} removes @emph{anything} that keeps you from extracting a file
4614 as far as current permissions will allow it. This could include removal
4615 of the contents of a full directory hierarchy.
4616
4617 @node Data Modification Times
4618 @unnumberedsubsubsec Setting Data Modification Times
4619
4620 @cindex Data modification times of extracted files
4621 @cindex Modification times of extracted files
4622 Normally, @command{tar} sets the data modification times of extracted
4623 files to the corresponding times recorded for the files in the archive, but
4624 limits the permissions of extracted files by the current @code{umask}
4625 setting.
4626
4627 To set the data modification times of extracted files to the time when
4628 the files were extracted, use the @option{--touch} (@option{-m}) option in
4629 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4630
4631 @table @option
4632 @opindex touch
4633 @item --touch
4634 @itemx -m
4635 Sets the data modification time of extracted archive members to the time
4636 they were extracted, not the time recorded for them in the archive.
4637 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4638 @end table
4639
4640 @node Setting Access Permissions
4641 @unnumberedsubsubsec Setting Access Permissions
4642
4643 @cindex Permissions of extracted files
4644 @cindex Modes of extracted files
4645 To set the modes (access permissions) of extracted files to those
4646 recorded for those files in the archive, use @option{--same-permissions}
4647 in conjunction with the @option{--extract} (@option{--get},
4648 @option{-x}) operation.
4649
4650 @table @option
4651 @opindex preserve-permissions
4652 @opindex same-permissions
4653 @item --preserve-permissions
4654 @itemx --same-permissions
4655 @c @itemx --ignore-umask
4656 @itemx -p
4657 Set modes of extracted archive members to those recorded in the
4658 archive, instead of current umask settings. Use in conjunction with
4659 @option{--extract} (@option{--get}, @option{-x}).
4660 @end table
4661
4662 @node Directory Modification Times and Permissions
4663 @unnumberedsubsubsec Directory Modification Times and Permissions
4664
4665 After sucessfully extracting a file member, @GNUTAR{} normally
4666 restores its permissions and modification times, as described in the
4667 previous sections. This cannot be done for directories, because
4668 after extracting a directory @command{tar} will almost certainly
4669 extract files into that directory and this will cause the directory
4670 modification time to be updated. Moreover, restoring that directory
4671 permissions may not permit file creation within it. Thus, restoring
4672 directory permissions and modification times must be delayed at least
4673 until all files have been extracted into that directory. @GNUTAR{}
4674 restores directories using the following approach.
4675
4676 The extracted directories are created with the mode specified in the
4677 archive, as modified by the umask of the user, which gives sufficient
4678 permissions to allow file creation. The meta-information about the
4679 directory is recorded in the temporary list of directories. When
4680 preparing to extract next archive member, @GNUTAR{} checks if the
4681 directory prefix of this file contains the remembered directory. If
4682 it does not, the program assumes that all files have been extracted
4683 into that directory, restores its modification time and permissions
4684 and removes its entry from the internal list. This approach allows
4685 to correctly restore directory meta-information in the majority of
4686 cases, while keeping memory requirements sufficiently small. It is
4687 based on the fact, that most @command{tar} archives use the predefined
4688 order of members: first the directory, then all the files and
4689 subdirectories in that directory.
4690
4691 However, this is not always true. The most important exception are
4692 incremental archives (@pxref{Incremental Dumps}). The member order in
4693 an incremental archive is reversed: first all directory members are
4694 stored, followed by other (non-directory) members. So, when extracting
4695 from incremental archives, @GNUTAR{} alters the above procedure. It
4696 remebers all restored directories, and restores their meta-data
4697 only after the entire archive has been processed. Notice, that you do
4698 not need to specity any special options for that, as @GNUTAR{}
4699 automatically detects archives in incremental format.
4700
4701 There may be cases, when such processing is required for normal archives
4702 too. Consider the following example:
4703
4704 @smallexample
4705 @group
4706 $ @kbd{tar --no-recursion -cvf archive \
4707 foo foo/file1 bar bar/file foo/file2}
4708 foo/
4709 foo/file1
4710 bar/
4711 bar/file
4712 foo/file2
4713 @end group
4714 @end smallexample
4715
4716 During the normal operation, after encountering @file{bar}
4717 @GNUTAR{} will assume that all files from the directory @file{foo}
4718 were already extracted and will therefore restore its timestamp and
4719 permission bits. However, after extracting @file{foo/file2} the
4720 directory timestamp will be offset again.
4721
4722 To correctly restore directory meta-information in such cases, use
4723 @option{delay-directory-restore} command line option:
4724
4725 @table @option
4726 @opindex delay-directory-restore
4727 @item --delay-directory-restore
4728 Delays restoring of the modification times and permissions of extracted
4729 directories until the end of extraction. This way, correct
4730 meta-information is restored even if the archive has unusual member
4731 ordering.
4732
4733 @opindex no-delay-directory-restore
4734 @item --no-delay-directory-restore
4735 Cancel the effect of the previous @option{--delay-directory-restore}.
4736 Use this option if you have used @option{--delay-directory-restore} in
4737 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4738 temporarily disable it.
4739 @end table
4740
4741 @node Writing to Standard Output
4742 @unnumberedsubsubsec Writing to Standard Output
4743
4744 @cindex Writing extracted files to standard output
4745 @cindex Standard output, writing extracted files to
4746 To write the extracted files to the standard output, instead of
4747 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4748 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4749 extracting files to send them through a pipe, and do not need to
4750 preserve them in the file system. If you extract multiple members,
4751 they appear on standard output concatenated, in the order they are
4752 found in the archive.
4753
4754 @table @option
4755 @opindex to-stdout
4756 @item --to-stdout
4757 @itemx -O
4758 Writes files to the standard output. Use only in conjunction with
4759 @option{--extract} (@option{--get}, @option{-x}). When this option is
4760 used, instead of creating the files specified, @command{tar} writes
4761 the contents of the files extracted to its standard output. This may
4762 be useful if you are only extracting the files in order to send them
4763 through a pipe. This option is meaningless with @option{--list}
4764 (@option{-t}).
4765 @end table
4766
4767 This can be useful, for example, if you have a tar archive containing
4768 a big file and don't want to store the file on disk before processing
4769 it. You can use a command like this:
4770
4771 @smallexample
4772 tar -xOzf foo.tgz bigfile | process
4773 @end smallexample
4774
4775 or even like this if you want to process the concatenation of the files:
4776
4777 @smallexample
4778 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4779 @end smallexample
4780
4781 Hovewer, @option{--to-command} may be more convenient for use with
4782 multiple files. See the next section.
4783
4784 @node Writing to an External Program
4785 @unnumberedsubsubsec Writing to an External Program
4786
4787 You can instruct @command{tar} to send the contents of each extracted
4788 file to the standard input of an external program:
4789
4790 @table @option
4791 @opindex to-command
4792 @item --to-command=@var{command}
4793 Extract files and pipe their contents to the standard input of
4794 @var{command}. When this option is used, instead of creating the
4795 files specified, @command{tar} invokes @var{command} and pipes the
4796 contents of the files to its standard output. @var{Command} may
4797 contain command line arguments. The program is executed via
4798 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4799 extracted. Non-regular files (directories, etc.) are ignored when this
4800 option is used.
4801 @end table
4802
4803 The command can obtain the information about the file it processes
4804 from the following environment variables:
4805
4806 @table @var
4807 @vrindex TAR_FILETYPE, to-command environment
4808 @item TAR_FILETYPE
4809 Type of the file. It is a single letter with the following meaning:
4810
4811 @multitable @columnfractions 0.10 0.90
4812 @item f @tab Regular file
4813 @item d @tab Directory
4814 @item l @tab Symbolic link
4815 @item h @tab Hard link
4816 @item b @tab Block device
4817 @item c @tab Character device
4818 @end multitable
4819
4820 Currently only regular files are supported.
4821
4822 @vrindex TAR_MODE, to-command environment
4823 @item TAR_MODE
4824 File mode, an octal number.
4825
4826 @vrindex TAR_FILENAME, to-command environment
4827 @item TAR_FILENAME
4828 The name of the file.
4829
4830 @vrindex TAR_REALNAME, to-command environment
4831 @item TAR_REALNAME
4832 Name of the file as stored in the archive.
4833
4834 @vrindex TAR_UNAME, to-command environment
4835 @item TAR_UNAME
4836 Name of the file owner.
4837
4838 @vrindex TAR_GNAME, to-command environment
4839 @item TAR_GNAME
4840 Name of the file owner group.
4841
4842 @vrindex TAR_ATIME, to-command environment
4843 @item TAR_ATIME
4844 Time of last access. It is a decimal number, representing seconds
4845 since the epoch. If the archive provides times with nanosecond
4846 precision, the nanoseconds are appended to the timestamp after a
4847 decimal point.
4848
4849 @vrindex TAR_MTIME, to-command environment
4850 @item TAR_MTIME
4851 Time of last modification.
4852
4853 @vrindex TAR_CTIME, to-command environment
4854 @item TAR_CTIME
4855 Time of last status change.
4856
4857 @vrindex TAR_SIZE, to-command environment
4858 @item TAR_SIZE
4859 Size of the file.
4860
4861 @vrindex TAR_UID, to-command environment
4862 @item TAR_UID
4863 UID of the file owner.
4864
4865 @vrindex TAR_GID, to-command environment
4866 @item TAR_GID
4867 GID of the file owner.
4868 @end table
4869
4870 In addition to these variables, @env{TAR_VERSION} contains the
4871 @GNUTAR{} version number.
4872
4873 If @var{command} exits with a non-0 status, @command{tar} will print
4874 an error message similar to the following:
4875
4876 @smallexample
4877 tar: 2345: Child returned status 1
4878 @end smallexample
4879
4880 Here, @samp{2345} is the PID of the finished process.
4881
4882 If this behavior is not wanted, use @option{--ignore-command-error}:
4883
4884 @table @option
4885 @opindex ignore-command-error
4886 @item --ignore-command-error
4887 Ignore exit codes of subprocesses. Notice that if the program
4888 exits on signal or otherwise terminates abnormally, the error message
4889 will be printed even if this option is used.
4890
4891 @opindex no-ignore-command-error
4892 @item --no-ignore-command-error
4893 Cancel the effect of any previous @option{--ignore-command-error}
4894 option. This option is useful if you have set
4895 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4896 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4897 @end table
4898
4899 @node remove files
4900 @unnumberedsubsubsec Removing Files
4901
4902 @FIXME{The section is too terse. Something more to add? An example,
4903 maybe?}
4904
4905 @table @option
4906 @opindex remove-files
4907 @item --remove-files
4908 Remove files after adding them to the archive.
4909 @end table
4910
4911 @node Scarce
4912 @subsection Coping with Scarce Resources
4913 @UNREVISED
4914
4915 @cindex Small memory
4916 @cindex Running out of space
4917
4918 @menu
4919 * Starting File::
4920 * Same Order::
4921 @end menu
4922
4923 @node Starting File
4924 @unnumberedsubsubsec Starting File
4925
4926 @table @option
4927 @opindex starting-file
4928 @item --starting-file=@var{name}
4929 @itemx -K @var{name}
4930 Starts an operation in the middle of an archive. Use in conjunction
4931 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4932 @end table
4933
4934 @cindex Middle of the archive, starting in the
4935 If a previous attempt to extract files failed due to lack of disk
4936 space, you can use @option{--starting-file=@var{name}} (@option{-K
4937 @var{name}}) to start extracting only after member @var{name} of the
4938 archive. This assumes, of course, that there is now free space, or
4939 that you are now extracting into a different file system. (You could
4940 also choose to suspend @command{tar}, remove unnecessary files from
4941 the file system, and then restart the same @command{tar} operation.
4942 In this case, @option{--starting-file} is not necessary.
4943 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4944
4945 @node Same Order
4946 @unnumberedsubsubsec Same Order
4947
4948 @table @option
4949 @cindex Large lists of file names on small machines
4950 @opindex same-order
4951 @opindex preserve-order
4952 @item --same-order
4953 @itemx --preserve-order
4954 @itemx -s
4955 To process large lists of file names on machines with small amounts of
4956 memory. Use in conjunction with @option{--compare} (@option{--diff},
4957 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4958 (@option{--get}, @option{-x}).
4959 @end table
4960
4961 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4962 names to be listed or extracted is sorted in the same order as the
4963 files in the archive. This allows a large list of names to be used,
4964 even on a small machine that would not otherwise be able to hold all
4965 the names in memory at the same time. Such a sorted list can easily be
4966 created by running @samp{tar -t} on the archive and editing its output.
4967
4968 This option is probably never needed on modern computer systems.
4969
4970 @node backup
4971 @section Backup options
4972
4973 @cindex backup options
4974
4975 @GNUTAR{} offers options for making backups of files
4976 before writing new versions. These options control the details of
4977 these backups. They may apply to the archive itself before it is
4978 created or rewritten, as well as individual extracted members. Other
4979 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
4980 and @command{mv}, for example) offer similar options.
4981
4982 Backup options may prove unexpectedly useful when extracting archives
4983 containing many members having identical name, or when extracting archives
4984 on systems having file name limitations, making different members appear
4985 has having similar names through the side-effect of name truncation.
4986 (This is true only if we have a good scheme for truncated backup names,
4987 which I'm not sure at all: I suspect work is needed in this area.)
4988 When any existing file is backed up before being overwritten by extraction,
4989 then clashing files are automatically be renamed to be unique, and the
4990 true name is kept for only the last file of a series of clashing files.
4991 By using verbose mode, users may track exactly what happens.
4992
4993 At the detail level, some decisions are still experimental, and may
4994 change in the future, we are waiting comments from our users. So, please
4995 do not learn to depend blindly on the details of the backup features.
4996 For example, currently, directories themselves are never renamed through
4997 using these options, so, extracting a file over a directory still has
4998 good chances to fail. Also, backup options apply to created archives,
4999 not only to extracted members. For created archives, backups will not
5000 be attempted when the archive is a block or character device, or when it
5001 refers to a remote file.
5002
5003 For the sake of simplicity and efficiency, backups are made by renaming old
5004 files prior to creation or extraction, and not by copying. The original
5005 name is restored if the file creation fails. If a failure occurs after a
5006 partial extraction of a file, both the backup and the partially extracted
5007 file are kept.
5008
5009 @table @samp
5010 @item --backup[=@var{method}]
5011 @opindex backup
5012 @vindex VERSION_CONTROL
5013 @cindex backups
5014 Back up files that are about to be overwritten or removed.
5015 Without this option, the original versions are destroyed.
5016
5017 Use @var{method} to determine the type of backups made.
5018 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5019 environment variable. And if @env{VERSION_CONTROL} is not set,
5020 use the @samp{existing} method.
5021
5022 @vindex version-control @r{Emacs variable}
5023 This option corresponds to the Emacs variable @samp{version-control};
5024 the same values for @var{method} are accepted as in Emacs. This option
5025 also allows more descriptive names. The valid @var{method}s are:
5026
5027 @table @samp
5028 @item t
5029 @itemx numbered
5030 @cindex numbered @r{backup method}
5031 Always make numbered backups.
5032
5033 @item nil
5034 @itemx existing
5035 @cindex existing @r{backup method}
5036 Make numbered backups of files that already have them, simple backups
5037 of the others.
5038
5039 @item never
5040 @itemx simple
5041 @cindex simple @r{backup method}
5042 Always make simple backups.
5043
5044 @end table
5045
5046 @item --suffix=@var{suffix}
5047 @opindex suffix
5048 @cindex backup suffix
5049 @vindex SIMPLE_BACKUP_SUFFIX
5050 Append @var{suffix} to each backup file made with @option{--backup}. If this
5051 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5052 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5053 set, the default is @samp{~}, just as in Emacs.
5054
5055 @end table
5056
5057 @node Applications
5058 @section Notable @command{tar} Usages
5059 @UNREVISED
5060
5061 @FIXME{Using Unix file linking capability to recreate directory
5062 structures---linking files into one subdirectory and then
5063 @command{tar}ring that directory.}
5064
5065 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5066
5067 @findex uuencode
5068 You can easily use archive files to transport a group of files from
5069 one system to another: put all relevant files into an archive on one
5070 computer system, transfer the archive to another system, and extract
5071 the contents there. The basic transfer medium might be magnetic tape,
5072 Internet FTP, or even electronic mail (though you must encode the
5073 archive with @command{uuencode} in order to transport it properly by
5074 mail). Both machines do not have to use the same operating system, as
5075 long as they both support the @command{tar} program.
5076
5077 For example, here is how you might copy a directory's contents from
5078 one disk to another, while preserving the dates, modes, owners and
5079 link-structure of all the files therein. In this case, the transfer
5080 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5081
5082 @smallexample
5083 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5084 @end smallexample
5085
5086 @noindent
5087 You can avoid subshells by using @option{-C} option:
5088
5089 @smallexample
5090 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5091 @end smallexample
5092
5093 @noindent
5094 The command also works using short option forms:
5095
5096 @smallexample
5097 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5098 | (cd targetdir; tar --extract --file=-)}
5099 # Or:
5100 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5101 | tar --directory targetdir --extract --file=-}
5102 @end smallexample
5103
5104 @noindent
5105 This is one of the easiest methods to transfer a @command{tar} archive.
5106
5107 @node looking ahead
5108 @section Looking Ahead: The Rest of this Manual
5109
5110 You have now seen how to use all eight of the operations available to
5111 @command{tar}, and a number of the possible options. The next chapter
5112 explains how to choose and change file and archive names, how to use
5113 files to store names of other files which you can then call as
5114 arguments to @command{tar} (this can help you save time if you expect to
5115 archive the same list of files a number of times), and so forth.
5116 @FIXME{in case it's not obvious, i'm making this up in some sense
5117 based on my limited memory of what the next chapter *really* does. i
5118 just wanted to flesh out this final section a little bit so i'd
5119 remember to stick it in here. :-)}
5120
5121 If there are too many files to conveniently list on the command line,
5122 you can list the names in a file, and @command{tar} will read that file.
5123 @xref{files}.
5124
5125 There are various ways of causing @command{tar} to skip over some files,
5126 and not archive them. @xref{Choosing}.
5127
5128 @node Backups
5129 @chapter Performing Backups and Restoring Files
5130 @UNREVISED
5131
5132 @GNUTAR{} is distributed along with the scripts
5133 which the Free Software Foundation uses for performing backups. There
5134 is no corresponding scripts available yet for doing restoration of
5135 files. Even if there is a good chance those scripts may be satisfying
5136 to you, they are not the only scripts or methods available for doing
5137 backups and restore. You may well create your own, or use more
5138 sophisticated packages dedicated to that purpose.
5139
5140 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5141 Automatic Network Disk Archiver), a backup system developed by James
5142 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5143 This is free software, and it is available at these places:
5144
5145 @smallexample
5146 http://www.cs.umd.edu/projects/amanda/amanda.html
5147 ftp://ftp.cs.umd.edu/pub/amanda
5148 @end smallexample
5149
5150 @FIXME{
5151
5152 Here is a possible plan for a future documentation about the backuping
5153 scripts which are provided within the @GNUTAR{}
5154 distribution.
5155
5156 @itemize @bullet
5157 @item dumps
5158 @itemize @minus
5159 @item what are dumps
5160 @item different levels of dumps
5161 @itemize +
5162 @item full dump = dump everything
5163 @item level 1, level 2 dumps etc
5164 A level @var{n} dump dumps everything changed since the last level
5165 @var{n}-1 dump (?)
5166 @end itemize
5167 @item how to use scripts for dumps (ie, the concept)
5168 @itemize +
5169 @item scripts to run after editing backup specs (details)
5170 @end itemize
5171 @item Backup Specs, what is it.
5172 @itemize +
5173 @item how to customize
5174 @item actual text of script [/sp/dump/backup-specs]
5175 @end itemize
5176 @item Problems
5177 @itemize +
5178 @item rsh doesn't work
5179 @item rtape isn't installed
5180 @item (others?)
5181 @end itemize
5182 @item the @option{--incremental} option of tar
5183 @item tapes
5184 @itemize +
5185 @item write protection
5186 @item types of media, different sizes and types, useful for different things
5187 @item files and tape marks
5188 one tape mark between files, two at end.
5189 @item positioning the tape
5190 MT writes two at end of write,
5191 backspaces over one when writing again.
5192 @end itemize
5193 @end itemize
5194 @end itemize
5195 }
5196
5197 This chapter documents both the provided shell scripts and @command{tar}
5198 options which are more specific to usage as a backup tool.
5199
5200 To @dfn{back up} a file system means to create archives that contain
5201 all the files in that file system. Those archives can then be used to
5202 restore any or all of those files (for instance if a disk crashes or a
5203 file is accidentally deleted). File system @dfn{backups} are also
5204 called @dfn{dumps}.
5205
5206 @menu
5207 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5208 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5209 * Backup Levels:: Levels of Backups
5210 * Backup Parameters:: Setting Parameters for Backups and Restoration
5211 * Scripted Backups:: Using the Backup Scripts
5212 * Scripted Restoration:: Using the Restore Script
5213 @end menu
5214
5215 @node Full Dumps
5216 @section Using @command{tar} to Perform Full Dumps
5217 @UNREVISED
5218
5219 @cindex full dumps
5220 @cindex dumps, full
5221
5222 @cindex corrupted archives
5223 Full dumps should only be made when no other people or programs
5224 are modifying files in the file system. If files are modified while
5225 @command{tar} is making the backup, they may not be stored properly in
5226 the archive, in which case you won't be able to restore them if you
5227 have to. (Files not being modified are written with no trouble, and do
5228 not corrupt the entire archive.)
5229
5230 You will want to use the @option{--label=@var{archive-label}}
5231 (@option{-V @var{archive-label}}) option to give the archive a
5232 volume label, so you can tell what this archive is even if the label
5233 falls off the tape, or anything like that.
5234
5235 Unless the file system you are dumping is guaranteed to fit on
5236 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5237 Make sure you have enough tapes on hand to complete the backup.
5238
5239 If you want to dump each file system separately you will need to use
5240 the @option{--one-file-system} option to prevent
5241 @command{tar} from crossing file system boundaries when storing
5242 (sub)directories.
5243
5244 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5245 option is not needed, since this is a complete copy of everything in
5246 the file system, and a full restore from this backup would only be
5247 done onto a completely
5248 empty disk.
5249
5250 Unless you are in a hurry, and trust the @command{tar} program (and your
5251 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5252 option, to make sure your files really made it onto the dump properly.
5253 This will also detect cases where the file was modified while (or just
5254 after) it was being archived. Not all media (notably cartridge tapes)
5255 are capable of being verified, unfortunately.
5256
5257 @node Incremental Dumps
5258 @section Using @command{tar} to Perform Incremental Dumps
5259
5260 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5261 stores additional metadata so that exact state of the file system
5262 can be restored when extracting the archive.
5263
5264 @GNUTAR{} currently offers two options for handling incremental
5265 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5266 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5267
5268 @opindex listed-incremental
5269 The option @option{--listed-incremental} instructs tar to operate on
5270 an incremental archive with additional metadata stored in a standalone
5271 file, called a @dfn{snapshot file}. The purpose of this file is to help
5272 determine which files have been changed, added or deleted since the
5273 last backup, so that the next incremental backup will contain only
5274 modified files. The name of the snapshot file is given as an argument
5275 to the option:
5276
5277 @table @option
5278 @item --listed-incremental=@var{file}
5279 @itemx -g @var{file}
5280 Handle incremental backups with snapshot data in @var{file}.
5281 @end table
5282
5283 To create an incremental backup, you would use
5284 @option{--listed-incremental} together with @option{--create}
5285 (@pxref{create}). For example:
5286
5287 @smallexample
5288 $ @kbd{tar --create \
5289 --file=archive.1.tar \
5290 --listed-incremental=/var/log/usr.snar \
5291 /usr}
5292 @end smallexample
5293
5294 This will create in @file{archive.1.tar} an incremental backup of
5295 the @file{/usr} file system, storing additional metadata in the file
5296 @file{/var/log/usr.snar}. If this file does not exist, it will be
5297 created. The created archive will then be a @dfn{level 0 backup};
5298 please see the next section for more on backup levels.
5299
5300 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5301 determines which files are modified. In this case only these files will be
5302 stored in the archive. Suppose, for example, that after running the
5303 above command, you delete file @file{/usr/doc/old} and create
5304 directory @file{/usr/local/db} with the following contents:
5305
5306 @smallexample
5307 $ @kbd{ls /usr/local/db}
5308 /usr/local/db/data
5309 /usr/local/db/index
5310 @end smallexample
5311
5312 Some time later you create another incremental backup. You will
5313 then see:
5314
5315 @smallexample
5316 $ @kbd{tar --create \
5317 --file=archive.2.tar \
5318 --listed-incremental=/var/log/usr.snar \
5319 /usr}
5320 tar: usr/local/db: Directory is new
5321 usr/local/db/
5322 usr/local/db/data
5323 usr/local/db/index
5324 @end smallexample
5325
5326 @noindent
5327 The created archive @file{archive.2.tar} will contain only these
5328 three members. This archive is called a @dfn{level 1 backup}. Notice
5329 that @file{/var/log/usr.snar} will be updated with the new data, so if
5330 you plan to create more @samp{level 1} backups, it is necessary to
5331 create a working copy of the snapshot file before running
5332 @command{tar}. The above example will then be modified as follows:
5333
5334 @smallexample
5335 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5336 $ @kbd{tar --create \
5337 --file=archive.2.tar \
5338 --listed-incremental=/var/log/usr.snar-1 \
5339 /usr}
5340 @end smallexample
5341
5342 Incremental dumps depend crucially on time stamps, so the results are
5343 unreliable if you modify a file's time stamps during dumping (e.g.,
5344 with the @option{--atime-preserve=replace} option), or if you set the clock
5345 backwards.
5346
5347 Metadata stored in snapshot files include device numbers, which,
5348 obviously is supposed to be a non-volatile value. However, it turns
5349 out that NFS devices have undependable values when an automounter
5350 gets in the picture. This can lead to a great deal of spurious
5351 redumping in incremental dumps, so it is somewhat useless to compare
5352 two NFS devices numbers over time. The solution implemented currently
5353 is to considers all NFS devices as being equal when it comes to
5354 comparing directories; this is fairly gross, but there does not seem
5355 to be a better way to go.
5356
5357 Note that incremental archives use @command{tar} extensions and may
5358 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5359
5360 @xopindex{listed-incremental, using with @option{--extract}}
5361 @xopindex{extract, using with @option{--listed-incremental}}
5362 To extract from the incremental dumps, use
5363 @option{--listed-incremental} together with @option{--extract}
5364 option (@pxref{extracting files}). In this case, @command{tar} does
5365 not need to access snapshot file, since all the data necessary for
5366 extraction are stored in the archive itself. So, when extracting, you
5367 can give whatever argument to @option{--listed-incremental}, the usual
5368 practice is to use @option{--listed-incremental=/dev/null}.
5369 Alternatively, you can use @option{--incremental}, which needs no
5370 arguments. In general, @option{--incremental} (@option{-G}) can be
5371 used as a shortcut for @option{--listed-incremental} when listing or
5372 extracting incremental backups (for more information, regarding this
5373 option, @pxref{incremental-op}).
5374
5375 When extracting from the incremental backup @GNUTAR{} attempts to
5376 restore the exact state the file system had when the archive was
5377 created. In particular, it will @emph{delete} those files in the file
5378 system that did not exist in their directories when the archive was
5379 created. If you have created several levels of incremental files,
5380 then in order to restore the exact contents the file system had when
5381 the last level was created, you will need to restore from all backups
5382 in turn. Continuing our example, to restore the state of @file{/usr}
5383 file system, one would do@footnote{Notice, that since both archives
5384 were created withouth @option{-P} option (@pxref{absolute}), these
5385 commands should be run from the root file system.}:
5386
5387 @smallexample
5388 $ @kbd{tar --extract \
5389 --listed-incremental=/dev/null \
5390 --file archive.1.tar}
5391 $ @kbd{tar --extract \
5392 --listed-incremental=/dev/null \
5393 --file archive.2.tar}
5394 @end smallexample
5395
5396 To list the contents of an incremental archive, use @option{--list}
5397 (@pxref{list}), as usual. To obtain more information about the
5398 archive, use @option{--listed-incremental} or @option{--incremental}
5399 combined with two @option{--verbose} options@footnote{Two
5400 @option{--verbose} options were selected to avoid breaking usual
5401 verbose listing output (@option{--list --verbose}) when using in
5402 scripts.
5403
5404 @xopindex{incremental, using with @option{--list}}
5405 @xopindex{listed-incremental, using with @option{--list}}
5406 @xopindex{list, using with @option{--incremental}}
5407 @xopindex{list, using with @option{--listed-incremental}}
5408 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5409 contents of the DUMPDIR header (with terminating nulls) when
5410 @option{--incremental} or @option{--listed-incremental} option was
5411 given, no matter what the verbosity level. This behavior, and,
5412 especially, the binary output it produced were considered incovenient
5413 and were changed in version 1.16}:
5414
5415 @smallexample
5416 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5417 @end smallexample
5418
5419 This command will print, for each directory in the archive, the list
5420 of files in that directory at the time the archive was created. This
5421 information is put out in a format which is both human-readable and
5422 unambiguous for a program: each file name is printed as
5423
5424 @smallexample
5425 @var{x} @var{file}
5426 @end smallexample
5427
5428 @noindent
5429 where @var{x} is a letter describing the status of the file: @samp{Y}
5430 if the file is present in the archive, @samp{N} if the file is not
5431 included in the archive, or a @samp{D} if the file is a directory (and
5432 is included in the archive). @xref{Dumpdir}, for the detailed
5433 description of dumpdirs and status codes. Each such
5434 line is terminated by a newline character. The last line is followed
5435 by an additional newline to indicate the end of the data.
5436
5437 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5438 gives the same behavior as @option{--listed-incremental} when used
5439 with @option{--list} and @option{--extract} options. When used with
5440 @option{--create} option, it creates an incremental archive without
5441 creating snapshot file. Thus, it is impossible to create several
5442 levels of incremental backups with @option{--incremental} option.
5443
5444 @node Backup Levels
5445 @section Levels of Backups
5446
5447 An archive containing all the files in the file system is called a
5448 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5449 creating a full dump every day. This strategy, however, would waste a
5450 substantial amount of archive media and user time, as unchanged files
5451 are daily re-archived.
5452
5453 It is more efficient to do a full dump only occasionally. To back up
5454 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5455 one} dump archives all the files that have changed since the last full
5456 dump.
5457
5458 A typical dump strategy would be to perform a full dump once a week,
5459 and a level one dump once a day. This means some versions of files
5460 will in fact be archived more than once, but this dump strategy makes
5461 it possible to restore a file system to within one day of accuracy by
5462 only extracting two archives---the last weekly (full) dump and the
5463 last daily (level one) dump. The only information lost would be in
5464 files changed or created since the last daily backup. (Doing dumps
5465 more than once a day is usually not worth the trouble).
5466
5467 @GNUTAR{} comes with scripts you can use to do full
5468 and level-one (actually, even level-two and so on) dumps. Using
5469 scripts (shell programs) to perform backups and restoration is a
5470 convenient and reliable alternative to typing out file name lists
5471 and @command{tar} commands by hand.
5472
5473 Before you use these scripts, you need to edit the file
5474 @file{backup-specs}, which specifies parameters used by the backup
5475 scripts and by the restore script. This file is usually located
5476 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5477 detailed description. Once the backup parameters are set, you can
5478 perform backups or restoration by running the appropriate script.
5479
5480 The name of the backup script is @code{backup}. The name of the
5481 restore script is @code{restore}. The following sections describe
5482 their use in detail.
5483
5484 @emph{Please Note:} The backup and restoration scripts are
5485 designed to be used together. While it is possible to restore files by
5486 hand from an archive which was created using a backup script, and to create
5487 an archive by hand which could then be extracted using the restore script,
5488 it is easier to use the scripts. @xref{Incremental Dumps}, before
5489 making such an attempt.
5490
5491 @node Backup Parameters
5492 @section Setting Parameters for Backups and Restoration
5493
5494 The file @file{backup-specs} specifies backup parameters for the
5495 backup and restoration scripts provided with @command{tar}. You must
5496 edit @file{backup-specs} to fit your system configuration and schedule
5497 before using these scripts.
5498
5499 Syntactically, @file{backup-specs} is a shell script, containing
5500 mainly variable assignments. However, any valid shell construct
5501 is allowed in this file. Particularly, you may wish to define
5502 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5503 For more information about shell script syntax, please refer to
5504 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5505 g_02, the definition of the Shell Command Language}. See also
5506 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5507
5508 The shell variables controlling behavior of @code{backup} and
5509 @code{restore} are described in the following subsections.
5510
5511 @menu
5512 * General-Purpose Variables::
5513 * Magnetic Tape Control::
5514 * User Hooks::
5515 * backup-specs example:: An Example Text of @file{Backup-specs}
5516 @end menu
5517
5518 @node General-Purpose Variables
5519 @subsection General-Purpose Variables
5520
5521 @defvr {Backup variable} ADMINISTRATOR
5522 The user name of the backup administrator. @code{Backup} scripts
5523 sends a backup report to this address.
5524 @end defvr
5525
5526 @defvr {Backup variable} BACKUP_HOUR
5527 The hour at which the backups are done. This can be a number from 0
5528 to 23, or the time specification in form @var{hours}:@var{minutes},
5529 or the string @samp{now}.
5530
5531 This variable is used by @code{backup}. Its value may be overridden
5532 using @option{--time} option (@pxref{Scripted Backups}).
5533 @end defvr
5534
5535 @defvr {Backup variable} TAPE_FILE
5536
5537 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5538 is a remote archive (@pxref{remote-dev}), backup script will suppose
5539 that your @command{mt} is able to access remote devices. If @var{RSH}
5540 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5541 invocations of @command{mt}.
5542 @end defvr
5543
5544 @defvr {Backup variable} BLOCKING
5545
5546 The blocking factor @command{tar} will use when writing the dump archive.
5547 @xref{Blocking Factor}.
5548 @end defvr
5549
5550 @defvr {Backup variable} BACKUP_DIRS
5551
5552 A list of file systems to be dumped (for @code{backup}), or restored
5553 (for @code{restore}). You can include any directory
5554 name in the list --- subdirectories on that file system will be
5555 included, regardless of how they may look to other networked machines.
5556 Subdirectories on other file systems will be ignored.
5557
5558 The host name specifies which host to run @command{tar} on, and should
5559 normally be the host that actually contains the file system. However,
5560 the host machine must have @GNUTAR{} installed, and
5561 must be able to access the directory containing the backup scripts and
5562 their support files using the same file name that is used on the
5563 machine where the scripts are run (i.e. what @command{pwd} will print
5564 when in that directory on that machine). If the host that contains
5565 the file system does not have this capability, you can specify another
5566 host as long as it can access the file system through NFS.
5567
5568 If the list of file systems is very long you may wish to put it
5569 in a separate file. This file is usually named
5570 @file{/etc/backup/dirs}, but this name may be overridden in
5571 @file{backup-specs} using @code{DIRLIST} variable.
5572 @end defvr
5573
5574 @defvr {Backup variable} DIRLIST
5575
5576 A path to the file containing the list of the file systems to backup
5577 or restore. By default it is @file{/etc/backup/dirs}.
5578 @end defvr
5579
5580 @defvr {Backup variable} BACKUP_FILES
5581
5582 A list of individual files to be dumped (for @code{backup}), or restored
5583 (for @code{restore}). These should be accessible from the machine on
5584 which the backup script is run.
5585
5586 If the list of file systems is very long you may wish to store it
5587 in a separate file. This file is usually named
5588 @file{/etc/backup/files}, but this name may be overridden in
5589 @file{backup-specs} using @code{FILELIST} variable.
5590 @end defvr
5591
5592 @defvr {Backup variable} FILELIST
5593
5594 A path to the file containing the list of the individual files to backup
5595 or restore. By default it is @file{/etc/backup/files}.
5596 @end defvr
5597
5598 @defvr {Backup variable} MT
5599
5600 Full file name of @command{mt} binary.
5601 @end defvr
5602
5603 @defvr {Backup variable} RSH
5604 @anchor{RSH}
5605 Full file name of @command{rsh} binary or its equivalent. You may wish to
5606 set it to @code{ssh}, to improve security. In this case you will have
5607 to use public key authentication.
5608 @end defvr
5609
5610 @defvr {Backup variable} RSH_COMMAND
5611
5612 Full file name of @command{rsh} binary on remote mashines. This will
5613 be passed via @option{--rsh-command} option to the remote invocation
5614 of @GNUTAR{}.
5615 @end defvr
5616
5617 @defvr {Backup variable} VOLNO_FILE
5618
5619 Name of temporary file to hold volume numbers. This needs to be accessible
5620 by all the machines which have file systems to be dumped.
5621 @end defvr
5622
5623 @defvr {Backup variable} XLIST
5624
5625 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5626 located on the remote machine and containing the list of files to
5627 be excluded from the backup. Exclude file lists are searched in
5628 /etc/tar-backup directory. A common use for exclude file lists
5629 is to exclude files containing security-sensitive information
5630 (e.g., @file{/etc/shadow} from backups).
5631
5632 This variable affects only @code{backup}.
5633 @end defvr
5634
5635 @defvr {Backup variable} SLEEP_TIME
5636
5637 Time to sleep between dumps of any two successive file systems
5638
5639 This variable affects only @code{backup}.
5640 @end defvr
5641
5642 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5643
5644 Script to be run when it's time to insert a new tape in for the next
5645 volume. Administrators may want to tailor this script for their site.
5646 If this variable isn't set, @GNUTAR{} will display its built-in
5647 prompt, and will expect confirmation from the console. For the
5648 description of the default prompt, see @ref{change volume prompt}.
5649
5650 @end defvr
5651
5652 @defvr {Backup variable} SLEEP_MESSAGE
5653
5654 Message to display on the terminal while waiting for dump time. Usually
5655 this will just be some literal text.
5656 @end defvr
5657
5658 @defvr {Backup variable} TAR
5659
5660 Full file name of the @GNUTAR{} executable. If this is not set, backup
5661 scripts will search @command{tar} in the current shell path.
5662 @end defvr
5663
5664 @node Magnetic Tape Control
5665 @subsection Magnetic Tape Control
5666
5667 Backup scripts access tape device using special @dfn{hook functions}.
5668 These functions take a single argument -- the name of the tape
5669 device. Their names are kept in the following variables:
5670
5671 @defvr {Backup variable} MT_BEGIN
5672 The name of @dfn{begin} function. This function is called before
5673 accessing the drive. By default it retensions the tape:
5674
5675 @smallexample
5676 MT_BEGIN=mt_begin
5677
5678 mt_begin() @{
5679 mt -f "$1" retension
5680 @}
5681 @end smallexample
5682 @end defvr
5683
5684 @defvr {Backup variable} MT_REWIND
5685 The name of @dfn{rewind} function. The default definition is as
5686 follows:
5687
5688 @smallexample
5689 MT_REWIND=mt_rewind
5690
5691 mt_rewind() @{
5692 mt -f "$1" rewind
5693 @}
5694 @end smallexample
5695
5696 @end defvr
5697
5698 @defvr {Backup variable} MT_OFFLINE
5699 The name of the function switching the tape off line. By default
5700 it is defined as follows:
5701
5702 @smallexample
5703 MT_OFFLINE=mt_offline
5704
5705 mt_offline() @{
5706 mt -f "$1" offl
5707 @}
5708 @end smallexample
5709 @end defvr
5710
5711 @defvr {Backup variable} MT_STATUS
5712 The name of the function used to obtain the status of the archive device,
5713 including error count. Default definition:
5714
5715 @smallexample
5716 MT_STATUS=mt_status
5717
5718 mt_status() @{
5719 mt -f "$1" status
5720 @}
5721 @end smallexample
5722 @end defvr
5723
5724 @node User Hooks
5725 @subsection User Hooks
5726
5727 @dfn{User hooks} are shell functions executed before and after
5728 each @command{tar} invocation. Thus, there are @dfn{backup
5729 hooks}, which are executed before and after dumping each file
5730 system, and @dfn{restore hooks}, executed before and
5731 after restoring a file system. Each user hook is a shell function
5732 taking four arguments:
5733
5734 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5735 Its arguments are:
5736
5737 @table @var
5738 @item level
5739 Current backup or restore level.
5740
5741 @item host
5742 Name or IP address of the host machine being dumped or restored.
5743
5744 @item fs
5745 Full path name to the file system being dumped or restored.
5746
5747 @item fsname
5748 File system name with directory separators replaced with colons. This
5749 is useful, e.g., for creating unique files.
5750 @end table
5751 @end deffn
5752
5753 Following variables keep the names of user hook functions
5754
5755 @defvr {Backup variable} DUMP_BEGIN
5756 Dump begin function. It is executed before dumping the file system.
5757 @end defvr
5758
5759 @defvr {Backup variable} DUMP_END
5760 Executed after dumping the file system.
5761 @end defvr
5762
5763 @defvr {Backup variable} RESTORE_BEGIN
5764 Executed before restoring the file system.
5765 @end defvr
5766
5767 @defvr {Backup variable} RESTORE_END
5768 Executed after restoring the file system.
5769 @end defvr
5770
5771 @node backup-specs example
5772 @subsection An Example Text of @file{Backup-specs}
5773
5774 The following is an example of @file{backup-specs}:
5775
5776 @smallexample
5777 # site-specific parameters for file system backup.
5778
5779 ADMINISTRATOR=friedman
5780 BACKUP_HOUR=1
5781 TAPE_FILE=/dev/nrsmt0
5782
5783 # Use @code{ssh} instead of the less secure @code{rsh}
5784 RSH=/usr/bin/ssh
5785 RSH_COMMAND=/usr/bin/ssh
5786
5787 # Override MT_STATUS function:
5788 my_status() @{
5789 mts -t $TAPE_FILE
5790 @}
5791 MT_STATUS=my_status
5792
5793 # Disable MT_OFFLINE function
5794 MT_OFFLINE=:
5795
5796 BLOCKING=124
5797 BACKUP_DIRS="
5798 albert:/fs/fsf
5799 apple-gunkies:/gd
5800 albert:/fs/gd2
5801 albert:/fs/gp
5802 geech:/usr/jla
5803 churchy:/usr/roland
5804 albert:/
5805 albert:/usr
5806 apple-gunkies:/
5807 apple-gunkies:/usr
5808 gnu:/hack
5809 gnu:/u
5810 apple-gunkies:/com/mailer/gnu
5811 apple-gunkies:/com/archive/gnu"
5812
5813 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5814
5815 @end smallexample
5816
5817 @node Scripted Backups
5818 @section Using the Backup Scripts
5819
5820 The syntax for running a backup script is:
5821
5822 @smallexample
5823 backup --level=@var{level} --time=@var{time}
5824 @end smallexample
5825
5826 The @option{level} option requests the dump level. Thus, to produce
5827 a full dump, specify @code{--level=0} (this is the default, so
5828 @option{--level} may be omitted if its value is @code{0}).
5829 @footnote{For backward compatibility, the @code{backup} will also
5830 try to deduce the requested dump level from the name of the
5831 script itself. If the name consists of a string @samp{level-}
5832 followed by a single decimal digit, that digit is taken as
5833 the dump level number. Thus, you may create a link from @code{backup}
5834 to @code{level-1} and then run @code{level-1} whenever you need to
5835 create a level one dump.}
5836
5837 The @option{--time} option determines when should the backup be
5838 run. @var{Time} may take three forms:
5839
5840 @table @asis
5841 @item @var{hh}:@var{mm}
5842
5843 The dump must be run at @var{hh} hours @var{mm} minutes.
5844
5845 @item @var{hh}
5846
5847 The dump must be run at @var{hh} hours
5848
5849 @item now
5850
5851 The dump must be run immediately.
5852 @end table
5853
5854 You should start a script with a tape or disk mounted. Once you
5855 start a script, it prompts you for new tapes or disks as it
5856 needs them. Media volumes don't have to correspond to archive
5857 files --- a multi-volume archive can be started in the middle of a
5858 tape that already contains the end of another multi-volume archive.
5859 The @code{restore} script prompts for media by its archive volume,
5860 so to avoid an error message you should keep track of which tape
5861 (or disk) contains which volume of the archive (@pxref{Scripted
5862 Restoration}).
5863
5864 The backup scripts write two files on the file system. The first is a
5865 record file in @file{/etc/tar-backup/}, which is used by the scripts
5866 to store and retrieve information about which files were dumped. This
5867 file is not meant to be read by humans, and should not be deleted by
5868 them. @xref{Snapshot Files}, for a more detailed explanation of this
5869 file.
5870
5871 The second file is a log file containing the names of the file systems
5872 and files dumped, what time the backup was made, and any error
5873 messages that were generated, as well as how much space was left in
5874 the media volume after the last volume of the archive was written.
5875 You should check this log file after every backup. The file name is
5876 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5877 represents current date, and @var{n} represents current dump level number.
5878
5879 The script also prints the name of each system being dumped to the
5880 standard output.
5881
5882 Following is the full list of options accepted by @code{backup}
5883 script:
5884
5885 @table @option
5886 @item -l @var{level}
5887 @itemx --level=@var{level}
5888 Do backup level @var{level} (default 0).
5889
5890 @item -f
5891 @itemx --force
5892 Force backup even if today's log file already exists.
5893
5894 @item -v[@var{level}]
5895 @itemx --verbose[=@var{level}]
5896 Set verbosity level. The higher the level is, the more debugging
5897 information will be output during execution. Devault @var{level}
5898 is 100, which means the highest debugging level.
5899
5900 @item -t @var{start-time}
5901 @itemx --time=@var{start-time}
5902 Wait till @var{time}, then do backup.
5903
5904 @item -h
5905 @itemx --help
5906 Display short help message and exit.
5907
5908 @item -V
5909 @itemx --version
5910 Display information about the program's name, version, origin and legal
5911 status, all on standard output, and then exit successfully.
5912 @end table
5913
5914
5915 @node Scripted Restoration
5916 @section Using the Restore Script
5917
5918 To restore files that were archived using a scripted backup, use the
5919 @code{restore} script. Its usage is quite straightforward. In the
5920 simplest form, invoke @code{restore --all}, it will
5921 then restore all the file systems and files specified in
5922 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5923
5924 You may select the file systems (and/or files) to restore by
5925 giving @code{restore} list of @dfn{patterns} in its command
5926 line. For example, running
5927
5928 @smallexample
5929 restore 'albert:*'
5930 @end smallexample
5931
5932 @noindent
5933 will restore all file systems on the machine @samp{albert}. A more
5934 complicated example:
5935
5936 @smallexample
5937 restore 'albert:*' '*:/var'
5938 @end smallexample
5939
5940 @noindent
5941 This command will restore all file systems on the machine @samp{albert}
5942 as well as @file{/var} file system on all machines.
5943
5944 By default @code{restore} will start restoring files from the lowest
5945 available dump level (usually zero) and will continue through
5946 all available dump levels. There may be situations where such a
5947 thorough restore is not necessary. For example, you may wish to
5948 restore only files from the recent level one backup. To do so,
5949 use @option{--level} option, as shown in the example below:
5950
5951 @smallexample
5952 restore --level=1
5953 @end smallexample
5954
5955 The full list of options accepted by @code{restore} follows:
5956
5957 @table @option
5958 @item -a
5959 @itemx --all
5960 Restore all file systems and files specified in @file{backup-specs}
5961
5962 @item -l @var{level}
5963 @itemx --level=@var{level}
5964 Start restoring from the given backup level, instead of the default 0.
5965
5966 @item -v[@var{level}]
5967 @itemx --verbose[=@var{level}]
5968 Set verbosity level. The higher the level is, the more debugging
5969 information will be output during execution. Devault @var{level}
5970 is 100, which means the highest debugging level.
5971
5972 @item -h
5973 @itemx --help
5974 Display short help message and exit.
5975
5976 @item -V
5977 @itemx --version
5978 Display information about the program's name, version, origin and legal
5979 status, all on standard output, and then exit successfully.
5980 @end table
5981
5982 You should start the restore script with the media containing the
5983 first volume of the archive mounted. The script will prompt for other
5984 volumes as they are needed. If the archive is on tape, you don't need
5985 to rewind the tape to to its beginning---if the tape head is
5986 positioned past the beginning of the archive, the script will rewind
5987 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
5988 positioning.
5989
5990 @quotation
5991 @strong{Warning:} The script will delete files from the active file
5992 system if they were not in the file system when the archive was made.
5993 @end quotation
5994
5995 @xref{Incremental Dumps}, for an explanation of how the script makes
5996 that determination.
5997
5998 @node Choosing
5999 @chapter Choosing Files and Names for @command{tar}
6000 @UNREVISED
6001
6002 Certain options to @command{tar} enable you to specify a name for your
6003 archive. Other options let you decide which files to include or exclude
6004 from the archive, based on when or whether files were modified, whether
6005 the file names do or don't match specified patterns, or whether files
6006 are in specified directories.
6007
6008 This chapter discusses these options in detail.
6009
6010 @menu
6011 * file:: Choosing the Archive's Name
6012 * Selecting Archive Members::
6013 * files:: Reading Names from a File
6014 * exclude:: Excluding Some Files
6015 * wildcards:: Wildcards Patterns and Matching
6016 * quoting styles:: Ways of Quoting Special Characters in Names
6017 * transform:: Modifying File and Member Names
6018 * after:: Operating Only on New Files
6019 * recurse:: Descending into Directories
6020 * one:: Crossing File System Boundaries
6021 @end menu
6022
6023 @node file
6024 @section Choosing and Naming Archive Files
6025 @UNREVISED
6026
6027 @cindex Naming an archive
6028 @cindex Archive Name
6029 @cindex Choosing an archive file
6030 @cindex Where is the archive?
6031 By default, @command{tar} uses an archive file name that was compiled when
6032 it was built on the system; usually this name refers to some physical
6033 tape drive on the machine. However, the person who installed @command{tar}
6034 on the system may not have set the default to a meaningful value as far as
6035 most users are concerned. As a result, you will usually want to tell
6036 @command{tar} where to find (or create) the archive. The
6037 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6038 option allows you to either specify or name a file to use as the archive
6039 instead of the default archive file location.
6040
6041 @table @option
6042 @xopindex{file, short description}
6043 @item --file=@var{archive-name}
6044 @itemx -f @var{archive-name}
6045 Name the archive to create or operate on. Use in conjunction with
6046 any operation.
6047 @end table
6048
6049 For example, in this @command{tar} command,
6050
6051 @smallexample
6052 $ @kbd{tar -cvf collection.tar blues folk jazz}
6053 @end smallexample
6054
6055 @noindent
6056 @file{collection.tar} is the name of the archive. It must directly
6057 follow the @option{-f} option, since whatever directly follows @option{-f}
6058 @emph{will} end up naming the archive. If you neglect to specify an
6059 archive name, you may end up overwriting a file in the working directory
6060 with the archive you create since @command{tar} will use this file's name
6061 for the archive name.
6062
6063 An archive can be saved as a file in the file system, sent through a
6064 pipe or over a network, or written to an I/O device such as a tape,
6065 floppy disk, or CD write drive.
6066
6067 @cindex Writing new archives
6068 @cindex Archive creation
6069 If you do not name the archive, @command{tar} uses the value of the
6070 environment variable @env{TAPE} as the file name for the archive. If
6071 that is not available, @command{tar} uses a default, compiled-in archive
6072 name, usually that for tape unit zero (i.e. @file{/dev/tu00}).
6073
6074 @cindex Standard input and output
6075 @cindex tar to standard input and output
6076 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6077 archive from standard input (when listing or extracting files), or
6078 writes it to standard output (when creating an archive). If you use
6079 @file{-} as an @var{archive-name} when modifying an archive,
6080 @command{tar} reads the original archive from its standard input and
6081 writes the entire new archive to its standard output.
6082
6083 The following example is a convenient way of copying directory
6084 hierarchy from @file{sourcedir} to @file{targetdir}.
6085
6086 @smallexample
6087 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6088 @end smallexample
6089
6090 The @option{-C} option allows to avoid using subshells:
6091
6092 @smallexample
6093 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6094 @end smallexample
6095
6096 In both examples above, the leftmost @command{tar} invocation archives
6097 the contents of @file{sourcedir} to the standard output, while the
6098 rightmost one reads this archive from its standard input and
6099 extracts it. The @option{-p} option tells it to restore permissions
6100 of the extracted files.
6101
6102 @cindex Remote devices
6103 @cindex tar to a remote device
6104 @anchor{remote-dev}
6105 To specify an archive file on a device attached to a remote machine,
6106 use the following:
6107
6108 @smallexample
6109 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6110 @end smallexample
6111
6112 @noindent
6113 @command{tar} will complete the remote connection, if possible, and
6114 prompt you for a username and password. If you use
6115 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6116 will complete the remote connection, if possible, using your username
6117 as the username on the remote machine.
6118
6119 @cindex Local and remote archives
6120 @anchor{local and remote archives}
6121 If the archive file name includes a colon (@samp{:}), then it is assumed
6122 to be a file on another machine. If the archive file is
6123 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6124 host @var{host}. The remote host is accessed using the @command{rsh}
6125 program, with a username of @var{user}. If the username is omitted
6126 (along with the @samp{@@} sign), then your user name will be used.
6127 (This is the normal @command{rsh} behavior.) It is necessary for the
6128 remote machine, in addition to permitting your @command{rsh} access, to
6129 have the @file{rmt} program installed (This command is included in
6130 the @GNUTAR{} distribution and by default is installed under
6131 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6132 installation prefix). If you need to use a file whose name includes a
6133 colon, then the remote tape drive behavior
6134 can be inhibited by using the @option{--force-local} option.
6135
6136 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6137 tries to minimize input and output operations. The Amanda backup
6138 system, when used with @GNUTAR{}, has an initial sizing pass which
6139 uses this feature.
6140
6141 @node Selecting Archive Members
6142 @section Selecting Archive Members
6143 @cindex Specifying files to act on
6144 @cindex Specifying archive members
6145
6146 @dfn{File Name arguments} specify which files in the file system
6147 @command{tar} operates on, when creating or adding to an archive, or which
6148 archive members @command{tar} operates on, when reading or deleting from
6149 an archive. @xref{Operations}.
6150
6151 To specify file names, you can include them as the last arguments on
6152 the command line, as follows:
6153 @smallexample
6154 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6155 @end smallexample
6156
6157 If a file name begins with dash (@samp{-}), precede it with
6158 @option{--add-file} option to prevent it from being treated as an
6159 option.
6160
6161 @anchor{input name quoting}
6162 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6163 name, replacing @dfn{escape sequences} according to the following
6164 table:
6165
6166 @multitable @columnfractions 0.20 0.60
6167 @headitem Escape @tab Replaced with
6168 @item \a @tab Audible bell (ASCII 7)
6169 @item \b @tab Backspace (ASCII 8)
6170 @item \f @tab Form feed (ASCII 12)
6171 @item \n @tab New line (ASCII 10)
6172 @item \r @tab Carriage return (ASCII 13)
6173 @item \t @tab Horizontal tabulation (ASCII 9)
6174 @item \v @tab Vertical tabulation (ASCII 11)
6175 @item \? @tab ASCII 127
6176 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6177 of up to 3 digits)
6178 @end multitable
6179
6180 A backslash followed by any other symbol is retained.
6181
6182 This default behavior is controlled by the following command line
6183 option:
6184
6185 @table @option
6186 @opindex unquote
6187 @item --unquote
6188 Enable unquoting input file or member names (default).
6189
6190 @opindex no-unquote
6191 @item --no-unquote
6192 Disable unquoting input file or member names.
6193 @end table
6194
6195 If you specify a directory name as a file name argument, all the files
6196 in that directory are operated on by @command{tar}.
6197
6198 If you do not specify files, @command{tar} behavior differs depending
6199 on the operation mode as described below:
6200
6201 When @command{tar} is invoked with @option{--create} (@option{-c}),
6202 @command{tar} will stop immediately, reporting the following:
6203
6204 @smallexample
6205 @group
6206 $ @kbd{tar cf a.tar}
6207 tar: Cowardly refusing to create an empty archive
6208 Try `tar --help' or `tar --usage' for more information.
6209 @end group
6210 @end smallexample
6211
6212 If you specify either @option{--list} (@option{-t}) or
6213 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6214 operates on all the archive members in the archive.
6215
6216 If run with @option{--diff} option, tar will compare the archive with
6217 the contents of the current working directory.
6218
6219 If you specify any other operation, @command{tar} does nothing.
6220
6221 By default, @command{tar} takes file names from the command line. However,
6222 there are other ways to specify file or member names, or to modify the
6223 manner in which @command{tar} selects the files or members upon which to
6224 operate. In general, these methods work both for specifying the names
6225 of files and archive members.
6226
6227 @node files
6228 @section Reading Names from a File
6229
6230 @cindex Reading file names from a file
6231 @cindex Lists of file names
6232 @cindex File Name arguments, alternatives
6233 Instead of giving the names of files or archive members on the command
6234 line, you can put the names into a file, and then use the
6235 @option{--files-from=@var{file-of-names}} (@option{-T
6236 @var{file-of-names}}) option to @command{tar}. Give the name of the
6237 file which contains the list of files to include as the argument to
6238 @option{--files-from}. In the list, the file names should be separated by
6239 newlines. You will frequently use this option when you have generated
6240 the list of files to archive with the @command{find} utility.
6241
6242 @table @option
6243 @opindex files-from
6244 @item --files-from=@var{file-name}
6245 @itemx -T @var{file-name}
6246 Get names to extract or create from file @var{file-name}.
6247 @end table
6248
6249 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6250 you specify either @code{--files-from=-} or @code{-T -}), then the file
6251 names are read from standard input.
6252
6253 Unless you are running @command{tar} with @option{--create}, you can not use
6254 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6255 command.
6256
6257 Any number of @option{-T} options can be given in the command line.
6258
6259 The following example shows how to use @command{find} to generate a list of
6260 files smaller than 400K in length and put that list into a file
6261 called @file{small-files}. You can then use the @option{-T} option to
6262 @command{tar} to specify the files from that file, @file{small-files}, to
6263 create the archive @file{little.tgz}. (The @option{-z} option to
6264 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6265 more information.)
6266
6267 @smallexample
6268 $ @kbd{find . -size -400 -print > small-files}
6269 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6270 @end smallexample
6271
6272 @noindent
6273 In the file list given by @option{-T} option, any file name beginning
6274 with @samp{-} character is considered a @command{tar} option and is
6275 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6276 recognized only @option{-C} option in file lists, and only if the
6277 option and its argument occupied two consecutive lines.} For example,
6278 the common use of this feature is to change to another directory by
6279 specifying @option{-C} option:
6280
6281 @smallexample
6282 @group
6283 $ @kbd{cat list}
6284 -C/etc
6285 passwd
6286 hosts
6287 -C/lib
6288 libc.a
6289 $ @kbd{tar -c -f foo.tar --files-from list}
6290 @end group
6291 @end smallexample
6292
6293 @noindent
6294 In this example, @command{tar} will first switch to @file{/etc}
6295 directory and add files @file{passwd} and @file{hosts} to the
6296 archive. Then it will change to @file{/lib} directory and will archive
6297 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6298 contain:
6299
6300 @smallexample
6301 @group
6302 $ @kbd{tar tf foo.tar}
6303 passwd
6304 hosts
6305 libc.a
6306 @end group
6307 @end smallexample
6308
6309 @noindent
6310 @xopindex{directory, using in @option{--files-from} argument}
6311 Notice that the option parsing algorithm used with @option{-T} is
6312 stricter than the one used by shell. Namely, when specifying option
6313 arguments, you should observe the following rules:
6314
6315 @itemize @bullet
6316 @item
6317 When using short (single-letter) option form, its argument must
6318 immediately follow the option letter, without any intervening
6319 whitespace. For example: @code{-Cdir}.
6320
6321 @item
6322 When using long option form, the option argument must be separated
6323 from the option by a single equal sign. No whitespace is allowed on
6324 any side of the equal sign. For example: @code{--directory=dir}.
6325
6326 @item
6327 For both short and long option forms, the option argument can be given
6328 on the next line after the option name, e.g.:
6329
6330 @smallexample
6331 @group
6332 --directory
6333 dir
6334 @end group
6335 @end smallexample
6336
6337 @noindent
6338 and
6339
6340 @smallexample
6341 @group
6342 -C
6343 dir
6344 @end group
6345 @end smallexample
6346 @end itemize
6347
6348 @opindex add-file
6349 If you happen to have a file whose name starts with @samp{-},
6350 precede it with @option{--add-file} option to prevent it from
6351 being recognized as an option. For example: @code{--add-file=--my-file}.
6352
6353 @menu
6354 * nul::
6355 @end menu
6356
6357 @node nul
6358 @subsection @code{NUL} Terminated File Names
6359
6360 @cindex File names, terminated by @code{NUL}
6361 @cindex @code{NUL} terminated file names
6362 The @option{--null} option causes
6363 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6364 to read file names terminated by a @code{NUL} instead of a newline, so
6365 files whose names contain newlines can be archived using
6366 @option{--files-from}.
6367
6368 @table @option
6369 @opindex null
6370 @item --null
6371 Only consider @code{NUL} terminated file names, instead of files that
6372 terminate in a newline.
6373 @end table
6374
6375 The @option{--null} option is just like the one in @acronym{GNU}
6376 @command{xargs} and @command{cpio}, and is useful with the
6377 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6378 @command{tar}, @option{--null} also disables special handling for
6379 file names that begin with dash.
6380
6381 This example shows how to use @command{find} to generate a list of files
6382 larger than 800K in length and put that list into a file called
6383 @file{long-files}. The @option{-print0} option to @command{find} is just
6384 like @option{-print}, except that it separates files with a @code{NUL}
6385 rather than with a newline. You can then run @command{tar} with both the
6386 @option{--null} and @option{-T} options to specify that @command{tar} get the
6387 files from that file, @file{long-files}, to create the archive
6388 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6389 @command{tar} to recognize the @code{NUL} separator between files.
6390
6391 @smallexample
6392 $ @kbd{find . -size +800 -print0 > long-files}
6393 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6394 @end smallexample
6395
6396 @FIXME{say anything else here to conclude the section?}
6397
6398 @node exclude
6399 @section Excluding Some Files
6400 @UNREVISED
6401
6402 @cindex File names, excluding files by
6403 @cindex Excluding files by name and pattern
6404 @cindex Excluding files by file system
6405 To avoid operating on files whose names match a particular pattern,
6406 use the @option{--exclude} or @option{--exclude-from} options.
6407
6408 @table @option
6409 @opindex exclude
6410 @item --exclude=@var{pattern}
6411 Causes @command{tar} to ignore files that match the @var{pattern}.
6412 @end table
6413
6414 @findex exclude
6415 The @option{--exclude=@var{pattern}} option prevents any file or
6416 member whose name matches the shell wildcard (@var{pattern}) from
6417 being operated on.
6418 For example, to create an archive with all the contents of the directory
6419 @file{src} except for files whose names end in @file{.o}, use the
6420 command @samp{tar -cf src.tar --exclude='*.o' src}.
6421
6422 You may give multiple @option{--exclude} options.
6423
6424 @table @option
6425 @opindex exclude-from
6426 @item --exclude-from=@var{file}
6427 @itemx -X @var{file}
6428 Causes @command{tar} to ignore files that match the patterns listed in
6429 @var{file}.
6430 @end table
6431
6432 @findex exclude-from
6433 Use the @option{--exclude-from} option to read a
6434 list of patterns, one per line, from @var{file}; @command{tar} will
6435 ignore files matching those patterns. Thus if @command{tar} is
6436 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6437 single line @file{*.o}, no files whose names end in @file{.o} will be
6438 added to the archive.
6439
6440 @table @option
6441 @opindex exclude-caches
6442 @item --exclude-caches
6443 Causes @command{tar} to ignore directories containing a cache directory tag.
6444 @end table
6445
6446 @findex exclude-caches
6447 When creating an archive, the @option{--exclude-caches} option causes
6448 @command{tar} to exclude all directories that contain a @dfn{cache
6449 directory tag}. A cache directory tag is a short file with the
6450 well-known name @file{CACHEDIR.TAG} and having a standard header
6451 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6452 Various applications write cache directory tags into directories they
6453 use to hold regenerable, non-precious data, so that such data can be
6454 more easily excluded from backups.
6455
6456 @menu
6457 * problems with exclude::
6458 @end menu
6459
6460 @node problems with exclude
6461 @unnumberedsubsec Problems with Using the @code{exclude} Options
6462
6463 @xopindex{exclude, potential problems with}
6464 Some users find @samp{exclude} options confusing. Here are some common
6465 pitfalls:
6466
6467 @itemize @bullet
6468 @item
6469 The main operating mode of @command{tar} does not act on a path name
6470 explicitly listed on the command line if one of its file name
6471 components is excluded. In the example above, if
6472 you create an archive and exclude files that end with @samp{*.o}, but
6473 explicitly name the file @samp{dir.o/foo} after all the options have been
6474 listed, @samp{dir.o/foo} will be excluded from the archive.
6475
6476 @item
6477 You can sometimes confuse the meanings of @option{--exclude} and
6478 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6479 to be excluded are given as a pattern on the command line. Use
6480 @option{--exclude-from} to introduce the name of a file which contains
6481 a list of patterns, one per line; each of these patterns can exclude
6482 zero, one, or many files.
6483
6484 @item
6485 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6486 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6487 like @samp{*}. If you do not do this, the shell might expand the
6488 @samp{*} itself using files at hand, so @command{tar} might receive a
6489 list of files instead of one pattern, or none at all, making the
6490 command somewhat illegal. This might not correspond to what you want.
6491
6492 For example, write:
6493
6494 @smallexample
6495 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6496 @end smallexample
6497
6498 @noindent
6499 rather than:
6500
6501 @smallexample
6502 # @emph{Wrong!}
6503 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6504 @end smallexample
6505
6506 @item
6507 You must use use shell syntax, or globbing, rather than @code{regexp}
6508 syntax, when using exclude options in @command{tar}. If you try to use
6509 @code{regexp} syntax to describe files to be excluded, your command
6510 might fail.
6511
6512 @item
6513 @FIXME{The change in semantics must have occurred before 1.11,
6514 so I doubt if it is worth mentioning at all. Anyway, should at
6515 least specify in which version the semantics changed.}
6516 In earlier versions of @command{tar}, what is now the
6517 @option{--exclude-from} option was called @option{--exclude} instead.
6518 Now, @option{--exclude} applies to patterns listed on the command
6519 line and @option{--exclude-from} applies to patterns listed in a
6520 file.
6521
6522 @end itemize
6523
6524 @node wildcards
6525 @section Wildcards Patterns and Matching
6526
6527 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6528 @samp{*} or @samp{?} for example, are replaced and expanded into all
6529 existing files matching the given pattern. @GNUTAR{} can use wildcard
6530 patterns for matching (or globbing) archive members when extracting
6531 from or listing an archive. Wildcard patterns are also used for
6532 verifying volume labels of @command{tar} archives. This section has the
6533 purpose of explaining wildcard syntax for @command{tar}.
6534
6535 @FIXME{the next few paragraphs need work.}
6536
6537 A @var{pattern} should be written according to shell syntax, using wildcard
6538 characters to effect globbing. Most characters in the pattern stand
6539 for themselves in the matched string, and case is significant: @samp{a}
6540 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6541 pattern matches any single character in the matched string. The character
6542 @samp{*} in the pattern matches zero, one, or more single characters in
6543 the matched string. The character @samp{\} says to take the following
6544 character of the pattern @emph{literally}; it is useful when one needs to
6545 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6546
6547 The character @samp{[}, up to the matching @samp{]}, introduces a character
6548 class. A @dfn{character class} is a list of acceptable characters
6549 for the next single character of the matched string. For example,
6550 @samp{[abcde]} would match any of the first five letters of the alphabet.
6551 Note that within a character class, all of the ``special characters''
6552 listed above other than @samp{\} lose their special meaning; for example,
6553 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6554 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6555 the characters @samp{-} and @samp{]} must either come @emph{first} or
6556 @emph{last} in a character class.)
6557
6558 @cindex Excluding characters from a character class
6559 @cindex Character class, excluding characters from
6560 If the first character of the class after the opening @samp{[}
6561 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6562 Rather than listing character to match, it lists those characters which
6563 are @emph{forbidden} as the next single character of the matched string.
6564
6565 Other characters of the class stand for themselves. The special
6566 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6567 letters, is meant to represent all characters between @var{a} and
6568 @var{e}, inclusive.
6569
6570 @FIXME{need to add a sentence or so here to make this clear for those
6571 who don't have dan around.}
6572
6573 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6574 special for wildcard matches. However, if a pattern completely matches
6575 a directory prefix of a matched string, then it matches the full matched
6576 string: thus, excluding a directory also excludes all the files beneath it.
6577
6578 @menu
6579 * controlling pattern-matching::
6580 @end menu
6581
6582 @node controlling pattern-matching
6583 @unnumberedsubsec Controlling Pattern-Matching
6584
6585 For the purposes of this section, we call @dfn{exclusion members} all
6586 member names obtained while processing @option{--exclude} and
6587 @option{--exclude-from} options, and @dfn{inclusion members} those
6588 member names that were given in the command line or read from the file
6589 specified with @option{--files-from} option.
6590
6591 These two pairs of member lists are used in the following operations:
6592 @option{--diff}, @option{--extract}, @option{--list},
6593 @option{--update}.
6594
6595 There are no inclusion members in create mode (@option{--create} and
6596 @option{--append}), since in this mode the names obtained from the
6597 command line refer to @emph{files}, not archive members.
6598
6599 By default, inclusion members are compared with archive members
6600 literally @footnote{Notice that earlier @GNUTAR{} versions used
6601 globbing for inclusion members, which contradicted to UNIX98
6602 specification and was not documented. @xref{Changes}, for more
6603 information on this and other changes.} and exclusion members are
6604 treated as globbing patterns. For example:
6605
6606 @smallexample
6607 @group
6608 $ @kbd{tar tf foo.tar}
6609 a.c
6610 b.c
6611 a.txt
6612 [remarks]
6613 # @i{Member names are used verbatim:}
6614 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6615 [remarks]
6616 # @i{Exclude member names are globbed:}
6617 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6618 a.txt
6619 [remarks]
6620 @end group
6621 @end smallexample
6622
6623 This behavior can be altered by using the following options:
6624
6625 @table @option
6626 @opindex wildcards
6627 @item --wildcards
6628 Treat all member names as wildcards.
6629
6630 @opindex no-wildcards
6631 @item --no-wildcards
6632 Treat all member names as literal strings.
6633 @end table
6634
6635 Thus, to extract files whose names end in @samp{.c}, you can use:
6636
6637 @smallexample
6638 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6639 a.c
6640 b.c
6641 @end smallexample
6642
6643 @noindent
6644 Notice quoting of the pattern to prevent the shell from interpreting
6645 it.
6646
6647 The effect of @option{--wildcards} option is cancelled by
6648 @option{--no-wildcards}. This can be used to pass part of
6649 the command line arguments verbatim and other part as globbing
6650 patterns. For example, the following invocation:
6651
6652 @smallexample
6653 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6654 @end smallexample
6655
6656 @noindent
6657 instructs @command{tar} to extract from @file{foo.tar} all files whose
6658 names end in @samp{.txt} and the file named @file{[remarks]}.
6659
6660 Normally, a pattern matches a name if an initial subsequence of the
6661 name's components matches the pattern, where @samp{*}, @samp{?}, and
6662 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6663 and wildcards can match @samp{/}.
6664
6665 Other than optionally stripping leading @samp{/} from names
6666 (@pxref{absolute}), patterns and names are used as-is. For
6667 example, trailing @samp{/} is not trimmed from a user-specified name
6668 before deciding whether to exclude it.
6669
6670 However, this matching procedure can be altered by the options listed
6671 below. These options accumulate. For example:
6672
6673 @smallexample
6674 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6675 @end smallexample
6676
6677 @noindent
6678 ignores case when excluding @samp{makefile}, but not when excluding
6679 @samp{readme}.
6680
6681 @table @option
6682 @opindex anchored
6683 @opindex no-anchored
6684 @item --anchored
6685 @itemx --no-anchored
6686 If anchored, a pattern must match an initial subsequence
6687 of the name's components. Otherwise, the pattern can match any
6688 subsequence. Default is @option{--no-anchored} for exclusion members
6689 and @option{--anchored} inclusion members.
6690
6691 @opindex ignore-case
6692 @opindex no-ignore-case
6693 @item --ignore-case
6694 @itemx --no-ignore-case
6695 When ignoring case, upper-case patterns match lower-case names and vice versa.
6696 When not ignoring case (the default), matching is case-sensitive.
6697
6698 @opindex wildcards-match-slash
6699 @opindex no-wildcards-match-slash
6700 @item --wildcards-match-slash
6701 @itemx --no-wildcards-match-slash
6702 When wildcards match slash (the default for exclusion members), a
6703 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6704 name. Otherwise, @samp{/} is matched only by @samp{/}.
6705
6706 @end table
6707
6708 The @option{--recursion} and @option{--no-recursion} options
6709 (@pxref{recurse}) also affect how member patterns are interpreted. If
6710 recursion is in effect, a pattern matches a name if it matches any of
6711 the name's parent directories.
6712
6713 The following table summarizes pattern-matching default values:
6714
6715 @multitable @columnfractions .3 .7
6716 @headitem Members @tab Default settings
6717 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6718 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6719 @end multitable
6720
6721 @node quoting styles
6722 @section Quoting Member Names
6723
6724 When displaying member names, @command{tar} takes care to avoid
6725 ambiguities caused by certain characters. This is called @dfn{name
6726 quoting}. The characters in question are:
6727
6728 @itemize @bullet
6729 @item Non-printable control characters:
6730
6731 @multitable @columnfractions 0.20 0.10 0.60
6732 @headitem Character @tab ASCII @tab Character name
6733 @item \a @tab 7 @tab Audible bell
6734 @item \b @tab 8 @tab Backspace
6735 @item \f @tab 12 @tab Form feed
6736 @item \n @tab 10 @tab New line
6737 @item \r @tab 13 @tab Carriage return
6738 @item \t @tab 9 @tab Horizontal tabulation
6739 @item \v @tab 11 @tab Vertical tabulation
6740 @end multitable
6741
6742 @item Space (ASCII 32)
6743
6744 @item Single and double quotes (@samp{'} and @samp{"})
6745
6746 @item Backslash (@samp{\})
6747 @end itemize
6748
6749 The exact way @command{tar} uses to quote these characters depends on
6750 the @dfn{quoting style}. The default quoting style, called
6751 @dfn{escape} (see below), uses backslash notation to represent control
6752 characters, space and backslash. Using this quoting style, control
6753 characters are represented as listed in column @samp{Character} in the
6754 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6755
6756 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6757 using @option{--quoting-style} option:
6758
6759 @table @option
6760 @item --quoting-style=@var{style}
6761 @opindex quoting-style
6762
6763 Sets quoting style. Valid values for @var{style} argument are:
6764 literal, shell, shell-always, c, escape, locale, clocale.
6765 @end table
6766
6767 These styles are described in detail below. To illustrate their
6768 effect, we will use an imaginary tar archive @file{arch.tar}
6769 containing the following members:
6770
6771 @smallexample
6772 @group
6773 # 1. Contains horizontal tabulation character.
6774 a tab
6775 # 2. Contains newline character
6776 a
6777 newline
6778 # 3. Contains a space
6779 a space
6780 # 4. Contains double quotes
6781 a"double"quote
6782 # 5. Contains single quotes
6783 a'single'quote
6784 # 6. Contains a backslash character:
6785 a\backslash
6786 @end group
6787 @end smallexample
6788
6789 Here is how usual @command{ls} command would have listed them, if they
6790 had existed in the current working directory:
6791
6792 @smallexample
6793 @group
6794 $ @kbd{ls}
6795 a\ttab
6796 a\nnewline
6797 a\ space
6798 a"double"quote
6799 a'single'quote
6800 a\\backslash
6801 @end group
6802 @end smallexample
6803
6804 Quoting styles:
6805
6806 @table @samp
6807 @item literal
6808 No quoting, display each character as is:
6809
6810 @smallexample
6811 @group
6812 $ @kbd{tar tf arch.tar --quoting-style=literal}
6813 ./
6814 ./a space
6815 ./a'single'quote
6816 ./a"double"quote
6817 ./a\backslash
6818 ./a tab
6819 ./a
6820 newline
6821 @end group
6822 @end smallexample
6823
6824 @item shell
6825 Display characters the same way Bourne shell does:
6826 control characters, except @samp{\t} and @samp{\n}, are printed using
6827 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6828 single quote is printed as @samp{\'}. If a name contains any quoted
6829 characters, it is enclosed in single quotes. In particular, if a name
6830 contains single quotes, it is printed as several single-quoted strings:
6831
6832 @smallexample
6833 @group
6834 $ @kbd{tar tf arch.tar --quoting-style=shell}
6835 ./
6836 './a space'
6837 './a'\''single'\''quote'
6838 './a"double"quote'
6839 './a\backslash'
6840 './a tab'
6841 './a
6842 newline'
6843 @end group
6844 @end smallexample
6845
6846 @item shell-always
6847 Same as @samp{shell}, but the names are always enclosed in single
6848 quotes:
6849
6850 @smallexample
6851 @group
6852 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6853 './'
6854 './a space'
6855 './a'\''single'\''quote'
6856 './a"double"quote'
6857 './a\backslash'
6858 './a tab'
6859 './a
6860 newline'
6861 @end group
6862 @end smallexample
6863
6864 @item c
6865 Use the notation of the C programming language. All names are
6866 enclosed in double quotes. Control characters are quoted using
6867 backslash notations, double quotes are represented as @samp{\"},
6868 backslash characters are represented as @samp{\\}. Single quotes and
6869 spaces are not quoted:
6870
6871 @smallexample
6872 @group
6873 $ @kbd{tar tf arch.tar --quoting-style=c}
6874 "./"
6875 "./a space"
6876 "./a'single'quote"
6877 "./a\"double\"quote"
6878 "./a\\backslash"
6879 "./a\ttab"
6880 "./a\nnewline"
6881 @end group
6882 @end smallexample
6883
6884 @item escape
6885 Control characters are printed using backslash notation, a space is
6886 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6887 default quoting style, unless it was changed when configured the
6888 package.
6889
6890 @smallexample
6891 @group
6892 $ @kbd{tar tf arch.tar --quoting-style=escape}
6893 ./
6894 ./a space
6895 ./a'single'quote
6896 ./a"double"quote
6897 ./a\\backslash
6898 ./a\ttab
6899 ./a\nnewline
6900 @end group
6901 @end smallexample
6902
6903 @item locale
6904 Control characters, single quote and backslash are printed using
6905 backslash notation. All names are quoted using left and right
6906 quotation marks, appropriate to the current locale. If it does not
6907 define quotation marks, use @samp{`} as left and @samp{'} as right
6908 quotation marks. Any occurrences of the right quotation mark in a
6909 name are escaped with @samp{\}, for example:
6910
6911 For example:
6912
6913 @smallexample
6914 @group
6915 $ @kbd{tar tf arch.tar --quoting-style=locale}
6916 `./'
6917 `./a space'
6918 `./a\'single\'quote'
6919 `./a"double"quote'
6920 `./a\\backslash'
6921 `./a\ttab'
6922 `./a\nnewline'
6923 @end group
6924 @end smallexample
6925
6926 @item clocale
6927 Same as @samp{locale}, but @samp{"} is used for both left and right
6928 quotation marks, if not provided by the currently selected locale:
6929
6930 @smallexample
6931 @group
6932 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6933 "./"
6934 "./a space"
6935 "./a'single'quote"
6936 "./a\"double\"quote"
6937 "./a\\backslash"
6938 "./a\ttab"
6939 "./a\nnewline"
6940 @end group
6941 @end smallexample
6942 @end table
6943
6944 You can specify which characters should be quoted in addition to those
6945 implied by the current quoting style:
6946
6947 @table @option
6948 @item --quote-chars=@var{string}
6949 Always quote characters from @var{string}, even if the selected
6950 quoting style would not quote them.
6951 @end table
6952
6953 For example, using @samp{escape} quoting (compare with the usual
6954 escape listing above):
6955
6956 @smallexample
6957 @group
6958 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6959 ./
6960 ./a\ space
6961 ./a'single'quote
6962 ./a\"double\"quote
6963 ./a\\backslash
6964 ./a\ttab
6965 ./a\nnewline
6966 @end group
6967 @end smallexample
6968
6969 To disable quoting of such additional characters, use the following
6970 option:
6971
6972 @table @option
6973 @item --no-quote-chars=@var{string}
6974 Remove characters listed in @var{string} from the list of quoted
6975 characters set by the previous @option{--quote-chars} option.
6976 @end table
6977
6978 This option is particularly useful if you have added
6979 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
6980 and wish to disable it for the current invocation.
6981
6982 Note, that @option{--no-quote-chars} does @emph{not} disable those
6983 characters that are quoted by default in the selected quoting style.
6984
6985 @node transform
6986 @section Modifying File and Member Names
6987
6988 @command{Tar} archives contain detailed information about files stored
6989 in them and full file names are part of that information. When
6990 storing file to an archive, its file name is recorded in the archive
6991 along with the actual file contents. When restoring from an archive,
6992 a file is created on disk with exactly the same name as that stored
6993 in the archive. In the majority of cases this is the desired behavior
6994 of a file archiver. However, there are some cases when it is not.
6995
6996 First of all, it is often unsafe to extract archive members with
6997 absolute file names or those that begin with a @file{../}. @GNUTAR{}
6998 takes special precautions when extracting such names and provides a
6999 special option for handling them, which is described in
7000 @ref{absolute}.
7001
7002 Secondly, you may wish to extract file names without some leading
7003 directory components, or with otherwise modified names. In other
7004 cases it is desirable to store files under differing names in the
7005 archive.
7006
7007 @GNUTAR{} provides two options for these needs.
7008
7009 @table @option
7010 @opindex strip-components
7011 @item --strip-components=@var{number}
7012 Strip given @var{number} of leading components from file names before
7013 extraction.
7014 @end table
7015
7016 For example, suppose you have archived whole @file{/usr} hierarchy to
7017 a tar archive named @file{usr.tar}. Among other files, this archive
7018 contains @file{usr/include/stdlib.h}, which you wish to extract to
7019 the current working directory. To do so, you type:
7020
7021 @smallexample
7022 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7023 @end smallexample
7024
7025 The option @option{--strip=2} instructs @command{tar} to strip the
7026 two leading components (@file{usr/} and @file{include/}) off the file
7027 name.
7028
7029 If you add to the above invocation @option{--verbose} (@option{-v})
7030 option, you will note that the verbose listing still contains the
7031 full file name, with the two removed components still in place. This
7032 can be inconvenient, so @command{tar} provides a special option for
7033 altering this behavior:
7034
7035 @anchor{show-transformed-names}
7036 @table @option
7037 @opindex show-transformed-names
7038 @item --show-transformed-names
7039 Display file or member names with all requested transformations
7040 applied.
7041 @end table
7042
7043 @noindent
7044 For example:
7045
7046 @smallexample
7047 @group
7048 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7049 usr/include/stdlib.h
7050 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7051 stdlib.h
7052 @end group
7053 @end smallexample
7054
7055 Notice that in both cases the file is @file{stdlib.h} extracted to the
7056 current working directory, @option{--show-transformed-names} affects
7057 only the way its name is displayed.
7058
7059 This option is especially useful for verifying whether the invocation
7060 will have the desired effect. Thus, before running
7061
7062 @smallexample
7063 $ @kbd{tar -x --strip=@var{n}}
7064 @end smallexample
7065
7066 @noindent
7067 it is often advisable to run
7068
7069 @smallexample
7070 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7071 @end smallexample
7072
7073 @noindent
7074 to make sure the command will produce the intended results.
7075
7076 In case you need to apply more complex modifications to the file name,
7077 @GNUTAR{} provides a general-purpose transformation option:
7078
7079 @table @option
7080 @opindex transform
7081 @item --transform=@var{expression}
7082 Modify file names using supplied @var{expression}.
7083 @end table
7084
7085 @noindent
7086 The @var{expression} is a @command{sed}-like replace expression of the
7087 form:
7088
7089 @smallexample
7090 s/@var{regexp}/@var{replace}/[@var{flags}]
7091 @end smallexample
7092
7093 @noindent
7094 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7095 replacement for each file name part that matches @var{regexp}. Both
7096 @var{regexp} and @var{replace} are described in detail in
7097 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7098
7099 Supported @var{flags} are:
7100
7101 @table @samp
7102 @item g
7103 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7104 just the first.
7105
7106 @item i
7107 Use case-insensitive matching
7108
7109 @item x
7110 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7111 regexps, Extended regular expressions, Extended regular expressions,
7112 sed, GNU sed}).
7113
7114 @item @var{number}
7115 Only replace the @var{number}th match of the @var{regexp}.
7116
7117 Note: the @var{posix} standard does not specify what should happen
7118 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7119 follows the GNU @command{sed} implementation in this regard, so
7120 the the interaction is defined to be: ignore matches before the
7121 @var{number}th, and then match and replace all matches from the
7122 @var{number}th on.
7123
7124 @end table
7125
7126 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7127 that it be used consistently throughout the expression. For example,
7128 the following two expressions are equivalent:
7129
7130 @smallexample
7131 @group
7132 s/one/two/
7133 s,one,two,
7134 @end group
7135 @end smallexample
7136
7137 Changing delimiters is often useful when the @var{regex} contains
7138 slashes. For example, it is more convenient to write @code{s,/,-,} than
7139 @code{s/\//-/}.
7140
7141 Here are several examples of @option{--transform} usage:
7142
7143 @enumerate
7144 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7145
7146 @smallexample
7147 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7148 @end smallexample
7149
7150 @item Strip two leading directory components (equivalent to
7151 @option{--strip-components=2}):
7152
7153 @smallexample
7154 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7155 @end smallexample
7156
7157 @item Prepend @file{/prefix/} to each file name:
7158
7159 @smallexample
7160 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7161 @end smallexample
7162
7163 @item Convert each file name to lower case:
7164
7165 @smallexample
7166 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7167 @end smallexample
7168
7169 @end enumerate
7170
7171 Unlike @option{--strip-components}, @option{--transform} can be used
7172 in any @GNUTAR{} operation mode. For example, the following command
7173 adds files to the archive while replacing the leading @file{usr/}
7174 component with @file{var/}:
7175
7176 @smallexample
7177 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7178 @end smallexample
7179
7180 To test @option{--transform} effect we suggest using
7181 @option{--show-transformed-names} option:
7182
7183 @smallexample
7184 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7185 --verbose --show-transformed-names /}
7186 @end smallexample
7187
7188 If both @option{--strip-components} and @option{--transform} are used
7189 together, then @option{--transform} is applied first, and the required
7190 number of components is then stripped from its result.
7191
7192 @node after
7193 @section Operating Only on New Files
7194 @UNREVISED
7195
7196 @cindex Excluding file by age
7197 @cindex Data Modification time, excluding files by
7198 @cindex Modification time, excluding files by
7199 @cindex Age, excluding files by
7200 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7201 @option{-N @var{date}}) option causes @command{tar} to only work on
7202 files whose data modification or status change times are newer than
7203 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7204 it is taken to be a file name; the data modification time of that file
7205 is used as the date. If you use this option when creating or appending
7206 to an archive, the archive will only include new files. If you use
7207 @option{--after-date} when extracting an archive, @command{tar} will
7208 only extract files newer than the @var{date} you specify.
7209
7210 If you only want @command{tar} to make the date comparison based on
7211 modification of the file's data (rather than status
7212 changes), then use the @option{--newer-mtime=@var{date}} option.
7213
7214 You may use these options with any operation. Note that these options
7215 differ from the @option{--update} (@option{-u}) operation in that they
7216 allow you to specify a particular date against which @command{tar} can
7217 compare when deciding whether or not to archive the files.
7218
7219 @table @option
7220 @opindex after-date
7221 @opindex newer
7222 @item --after-date=@var{date}
7223 @itemx --newer=@var{date}
7224 @itemx -N @var{date}
7225 Only store files newer than @var{date}.
7226
7227 Acts on files only if their data modification or status change times are
7228 later than @var{date}. Use in conjunction with any operation.
7229
7230 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7231 name; the data modification time of that file is used as the date.
7232
7233 @opindex newer-mtime
7234 @item --newer-mtime=@var{date}
7235 Acts like @option{--after-date}, but only looks at data modification times.
7236 @end table
7237
7238 These options limit @command{tar} to operate only on files which have
7239 been modified after the date specified. A file's status is considered to have
7240 changed if its contents have been modified, or if its owner,
7241 permissions, and so forth, have been changed. (For more information on
7242 how to specify a date, see @ref{Date input formats}; remember that the
7243 entire date argument must be quoted if it contains any spaces.)
7244
7245 Gurus would say that @option{--after-date} tests both the data
7246 modification time (@code{mtime}, the time the contents of the file
7247 were last modified) and the status change time (@code{ctime}, the time
7248 the file's status was last changed: owner, permissions, etc.@:)
7249 fields, while @option{--newer-mtime} tests only the @code{mtime}
7250 field.
7251
7252 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7253 @code{ctime} and processes the file if either one is more recent than
7254 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7255 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7256 contents of the file were looked at).
7257
7258 Date specifiers can have embedded spaces. Because of this, you may need
7259 to quote date arguments to keep the shell from parsing them as separate
7260 arguments. For example, the following command will add to the archive
7261 all the files modified less than two days ago:
7262
7263 @smallexample
7264 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7265 @end smallexample
7266
7267 When any of these options is used with the option @option{--verbose}
7268 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7269 date back to its textual representation and compare that with the
7270 one given with the option. If the two dates differ, @command{tar} will
7271 print a warning saying what date it will use. This is to help user
7272 ensure he is using the right date. For example:
7273
7274 @smallexample
7275 @group
7276 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7277 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7278 13:19:37.232434
7279 @end group
7280 @end smallexample
7281
7282 @quotation
7283 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7284 should not be used for incremental backups. @xref{Incremental Dumps},
7285 for proper way of creating incremental backups.
7286 @end quotation
7287
7288 @node recurse
7289 @section Descending into Directories
7290 @UNREVISED
7291 @cindex Avoiding recursion in directories
7292 @cindex Descending directories, avoiding
7293 @cindex Directories, avoiding recursion
7294 @cindex Recursion in directories, avoiding
7295
7296 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7297
7298 Usually, @command{tar} will recursively explore all directories (either
7299 those given on the command line or through the @option{--files-from}
7300 option) for the various files they contain. However, you may not always
7301 want @command{tar} to act this way.
7302
7303 @opindex no-recursion
7304 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7305 into specified directories. If you specify @option{--no-recursion}, you can
7306 use the @command{find} utility for hunting through levels of directories to
7307 construct a list of file names which you could then pass to @command{tar}.
7308 @command{find} allows you to be more selective when choosing which files to
7309 archive; see @ref{files}, for more information on using @command{find} with
7310 @command{tar}, or look.
7311
7312 @table @option
7313 @item --no-recursion
7314 Prevents @command{tar} from recursively descending directories.
7315
7316 @opindex recursion
7317 @item --recursion
7318 Requires @command{tar} to recursively descend directories.
7319 This is the default.
7320 @end table
7321
7322 When you use @option{--no-recursion}, @GNUTAR{} grabs
7323 directory entries themselves, but does not descend on them
7324 recursively. Many people use @command{find} for locating files they
7325 want to back up, and since @command{tar} @emph{usually} recursively
7326 descends on directories, they have to use the @samp{@w{-not -type d}}
7327 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7328 find, Finding Files}), as they usually do not want all the files in a
7329 directory. They then use the @option{--files-from} option to archive
7330 the files located via @command{find}.
7331
7332 The problem when restoring files archived in this manner is that the
7333 directories themselves are not in the archive; so the
7334 @option{--same-permissions} (@option{--preserve-permissions},
7335 @option{-p}) option does not affect them---while users might really
7336 like it to. Specifying @option{--no-recursion} is a way to tell
7337 @command{tar} to grab only the directory entries given to it, adding
7338 no new files on its own. To summarize, if you use @command{find} to
7339 create a list of files to be stored in an archive, use it as follows:
7340
7341 @smallexample
7342 @group
7343 $ @kbd{find @var{dir} @var{tests} | \
7344 tar -cf @var{archive} -T - --no-recursion}
7345 @end group
7346 @end smallexample
7347
7348 The @option{--no-recursion} option also applies when extracting: it
7349 causes @command{tar} to extract only the matched directory entries, not
7350 the files under those directories.
7351
7352 The @option{--no-recursion} option also affects how globbing patterns
7353 are interpreted (@pxref{controlling pattern-matching}).
7354
7355 The @option{--no-recursion} and @option{--recursion} options apply to
7356 later options and operands, and can be overridden by later occurrences
7357 of @option{--no-recursion} and @option{--recursion}. For example:
7358
7359 @smallexample
7360 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7361 @end smallexample
7362
7363 @noindent
7364 creates an archive with one entry for @file{grape}, and the recursive
7365 contents of @file{grape/concord}, but no entries under @file{grape}
7366 other than @file{grape/concord}.
7367
7368 @node one
7369 @section Crossing File System Boundaries
7370 @cindex File system boundaries, not crossing
7371 @UNREVISED
7372
7373 @command{tar} will normally automatically cross file system boundaries in
7374 order to archive files which are part of a directory tree. You can
7375 change this behavior by running @command{tar} and specifying
7376 @option{--one-file-system}. This option only affects files that are
7377 archived because they are in a directory that is being archived;
7378 @command{tar} will still archive files explicitly named on the command line
7379 or through @option{--files-from}, regardless of where they reside.
7380
7381 @table @option
7382 @opindex one-file-system
7383 @item --one-file-system
7384 Prevents @command{tar} from crossing file system boundaries when
7385 archiving. Use in conjunction with any write operation.
7386 @end table
7387
7388 The @option{--one-file-system} option causes @command{tar} to modify its
7389 normal behavior in archiving the contents of directories. If a file in
7390 a directory is not on the same file system as the directory itself, then
7391 @command{tar} will not archive that file. If the file is a directory
7392 itself, @command{tar} will not archive anything beneath it; in other words,
7393 @command{tar} will not cross mount points.
7394
7395 This option is useful for making full or incremental archival backups of
7396 a file system. If this option is used in conjunction with
7397 @option{--verbose} (@option{-v}), files that are excluded are
7398 mentioned by name on the standard error.
7399
7400 @menu
7401 * directory:: Changing Directory
7402 * absolute:: Absolute File Names
7403 @end menu
7404
7405 @node directory
7406 @subsection Changing the Working Directory
7407 @UNREVISED
7408
7409 @FIXME{need to read over this node now for continuity; i've switched
7410 things around some.}
7411
7412 @cindex Changing directory mid-stream
7413 @cindex Directory, changing mid-stream
7414 @cindex Working directory, specifying
7415 To change the working directory in the middle of a list of file names,
7416 either on the command line or in a file specified using
7417 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7418 This will change the working directory to the specified directory
7419 after that point in the list.
7420
7421 @table @option
7422 @opindex directory
7423 @item --directory=@var{directory}
7424 @itemx -C @var{directory}
7425 Changes the working directory in the middle of a command line.
7426 @end table
7427
7428 For example,
7429
7430 @smallexample
7431 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7432 @end smallexample
7433
7434 @noindent
7435 will place the files @file{grape} and @file{prune} from the current
7436 directory into the archive @file{jams.tar}, followed by the file
7437 @file{cherry} from the directory @file{food}. This option is especially
7438 useful when you have several widely separated files that you want to
7439 store in the same archive.
7440
7441 Note that the file @file{cherry} is recorded in the archive under the
7442 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7443 archive will contain three files that all appear to have come from the
7444 same directory; if the archive is extracted with plain @samp{tar
7445 --extract}, all three files will be written in the current directory.
7446
7447 Contrast this with the command,
7448
7449 @smallexample
7450 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7451 @end smallexample
7452
7453 @noindent
7454 which records the third file in the archive under the name
7455 @file{red/cherry} so that, if the archive is extracted using
7456 @samp{tar --extract}, the third file will be written in a subdirectory
7457 named @file{orange-colored}.
7458
7459 You can use the @option{--directory} option to make the archive
7460 independent of the original name of the directory holding the files.
7461 The following command places the files @file{/etc/passwd},
7462 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7463 @file{foo.tar}:
7464
7465 @smallexample
7466 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7467 @end smallexample
7468
7469 @noindent
7470 However, the names of the archive members will be exactly what they were
7471 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7472 They will not appear to be related by file name to the original
7473 directories where those files were located.
7474
7475 Note that @option{--directory} options are interpreted consecutively. If
7476 @option{--directory} specifies a relative file name, it is interpreted
7477 relative to the then current directory, which might not be the same as
7478 the original current working directory of @command{tar}, due to a previous
7479 @option{--directory} option.
7480
7481 When using @option{--files-from} (@pxref{files}), you can put various
7482 @command{tar} options (including @option{-C}) in the file list. Notice,
7483 however, that in this case the option and its argument may not be
7484 separated by whitespace. If you use short option, its argument must
7485 either follow the option letter immediately, without any intervening
7486 whitespace, or occupy the next line. Otherwise, if you use long
7487 option, separate its argument by an equal sign.
7488
7489 For instance, the file list for the above example will be:
7490
7491 @smallexample
7492 @group
7493 -C
7494 /etc
7495 passwd
7496 hosts
7497 -C
7498 /lib
7499 libc.a
7500 @end group
7501 @end smallexample
7502
7503 @noindent
7504 To use it, you would invoke @command{tar} as follows:
7505
7506 @smallexample
7507 $ @kbd{tar -c -f foo.tar --files-from list}
7508 @end smallexample
7509
7510 Notice also that you can only use the short option variant in the file
7511 list, i.e., always use @option{-C}, not @option{--directory}.
7512
7513 The interpretation of @option{--directory} is disabled by
7514 @option{--null} option.
7515
7516 @node absolute
7517 @subsection Absolute File Names
7518 @UNREVISED
7519
7520 @table @option
7521 @opindex absolute-names
7522 @item --absolute-names
7523 @itemx -P
7524 Do not strip leading slashes from file names, and permit file names
7525 containing a @file{..} file name component.
7526 @end table
7527
7528 By default, @GNUTAR{} drops a leading @samp{/} on
7529 input or output, and complains about file names containing a @file{..}
7530 component. This option turns off this behavior.
7531
7532 When @command{tar} extracts archive members from an archive, it strips any
7533 leading slashes (@samp{/}) from the member name. This causes absolute
7534 member names in the archive to be treated as relative file names. This
7535 allows you to have such members extracted wherever you want, instead of
7536 being restricted to extracting the member in the exact directory named
7537 in the archive. For example, if the archive member has the name
7538 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7539 really @file{etc/passwd}.
7540
7541 File names containing @file{..} can cause problems when extracting, so
7542 @command{tar} normally warns you about such files when creating an
7543 archive, and rejects attempts to extracts such files.
7544
7545 Other @command{tar} programs do not do this. As a result, if you
7546 create an archive whose member names start with a slash, they will be
7547 difficult for other people with a non-@GNUTAR{}
7548 program to use. Therefore, @GNUTAR{} also strips
7549 leading slashes from member names when putting members into the
7550 archive. For example, if you ask @command{tar} to add the file
7551 @file{/bin/ls} to an archive, it will do so, but the member name will
7552 be @file{bin/ls}.@footnote{A side effect of this is that when
7553 @option{--create} is used with @option{--verbose} the resulting output
7554 is not, generally speaking, the same as the one you'd get running
7555 @kbd{tar --list} command. This may be important if you use some
7556 scripts for comparing both outputs. @xref{listing member and file names},
7557 for the information on how to handle this case.}
7558
7559 If you use the @option{--absolute-names} (@option{-P}) option,
7560 @command{tar} will do none of these transformations.
7561
7562 To archive or extract files relative to the root directory, specify
7563 the @option{--absolute-names} (@option{-P}) option.
7564
7565 Normally, @command{tar} acts on files relative to the working
7566 directory---ignoring superior directory names when archiving, and
7567 ignoring leading slashes when extracting.
7568
7569 When you specify @option{--absolute-names} (@option{-P}),
7570 @command{tar} stores file names including all superior directory
7571 names, and preserves leading slashes. If you only invoked
7572 @command{tar} from the root directory you would never need the
7573 @option{--absolute-names} option, but using this option
7574 may be more convenient than switching to root.
7575
7576 @FIXME{Should be an example in the tutorial/wizardry section using this
7577 to transfer files between systems.}
7578
7579 @FIXME{Is write access an issue?}
7580
7581 @table @option
7582 @item --absolute-names
7583 Preserves full file names (including superior directory names) when
7584 archiving files. Preserves leading slash when extracting files.
7585
7586 @end table
7587
7588 @FIXME{this is still horrible; need to talk with dan on monday.}
7589
7590 @command{tar} prints out a message about removing the @samp{/} from
7591 file names. This message appears once per @GNUTAR{}
7592 invocation. It represents something which ought to be told; ignoring
7593 what it means can cause very serious surprises, later.
7594
7595 Some people, nevertheless, do not want to see this message. Wanting to
7596 play really dangerously, one may of course redirect @command{tar} standard
7597 error to the sink. For example, under @command{sh}:
7598
7599 @smallexample
7600 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7601 @end smallexample
7602
7603 @noindent
7604 Another solution, both nicer and simpler, would be to change to
7605 the @file{/} directory first, and then avoid absolute notation.
7606 For example:
7607
7608 @smallexample
7609 $ @kbd{(cd / && tar -c -f archive.tar home)}
7610 # @i{or}:
7611 $ @kbd{tar -c -f archive.tar -C / home}
7612 @end smallexample
7613
7614 @include getdate.texi
7615
7616 @node Formats
7617 @chapter Controlling the Archive Format
7618
7619 @cindex Tar archive formats
7620 Due to historical reasons, there are several formats of tar archives.
7621 All of them are based on the same principles, but have some subtle
7622 differences that often make them incompatible with each other.
7623
7624 GNU tar is able to create and handle archives in a variety of formats.
7625 The most frequently used formats are (in alphabetical order):
7626
7627 @table @asis
7628 @item gnu
7629 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7630 from an early @acronym{POSIX} standard, adding some improvements such as
7631 sparse file handling and incremental archives. Unfortunately these
7632 features were implemented in a way incompatible with other archive
7633 formats.
7634
7635 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7636 length.
7637
7638 @item oldgnu
7639 Format used by @GNUTAR{} of versions prior to 1.12.
7640
7641 @item v7
7642 Archive format, compatible with the V7 implementation of tar. This
7643 format imposes a number of limitations. The most important of them
7644 are:
7645
7646 @enumerate
7647 @item The maximum length of a file name is limited to 99 characters.
7648 @item The maximum length of a symbolic link is limited to 99 characters.
7649 @item It is impossible to store special files (block and character
7650 devices, fifos etc.)
7651 @item Maximum value of user or group ID is limited to 2097151 (7777777
7652 octal)
7653 @item V7 archives do not contain symbolic ownership information (user
7654 and group name of the file owner).
7655 @end enumerate
7656
7657 This format has traditionally been used by Automake when producing
7658 Makefiles. This practice will change in the future, in the meantime,
7659 however this means that projects containing filenames more than 99
7660 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7661 Automake prior to 1.9.
7662
7663 @item ustar
7664 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7665 symbolic ownership information. It is also able to store
7666 special files. However, it imposes several restrictions as well:
7667
7668 @enumerate
7669 @item The maximum length of a file name is limited to 256 characters,
7670 provided that the filename can be split at directory separator in
7671 two parts, first of them being at most 155 bytes long. So, in most
7672 cases the maximum file name length will be shorter than 256
7673 characters.
7674 @item The maximum length of a symbolic link name is limited to
7675 100 characters.
7676 @item Maximum size of a file the archive is able to accomodate
7677 is 8GB
7678 @item Maximum value of UID/GID is 2097151.
7679 @item Maximum number of bits in device major and minor numbers is 21.
7680 @end enumerate
7681
7682 @item star
7683 Format used by J@"org Schilling @command{star}
7684 implementation. @GNUTAR{} is able to read @samp{star} archives but
7685 currently does not produce them.
7686
7687 @item posix
7688 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7689 most flexible and feature-rich format. It does not impose any
7690 restrictions on file sizes or filename lengths. This format is quite
7691 recent, so not all tar implementations are able to handle it properly.
7692 However, this format is designed in such a way that any tar
7693 implementation able to read @samp{ustar} archives will be able to read
7694 most @samp{posix} archives as well, with the only exception that any
7695 additional information (such as long file names etc.) will in such
7696 case be extracted as plain text files along with the files it refers to.
7697
7698 This archive format will be the default format for future versions
7699 of @GNUTAR{}.
7700
7701 @end table
7702
7703 The following table summarizes the limitations of each of these
7704 formats:
7705
7706 @multitable @columnfractions .10 .20 .20 .20 .20
7707 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7708 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7709 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7710 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7711 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7712 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7713 @end multitable
7714
7715 The default format for @GNUTAR{} is defined at compilation
7716 time. You may check it by running @command{tar --help}, and examining
7717 the last lines of its output. Usually, @GNUTAR{} is configured
7718 to create archives in @samp{gnu} format, however, future version will
7719 switch to @samp{posix}.
7720
7721 @menu
7722 * Portability:: Making @command{tar} Archives More Portable
7723 * Compression:: Using Less Space through Compression
7724 * Attributes:: Handling File Attributes
7725 * cpio:: Comparison of @command{tar} and @command{cpio}
7726 @end menu
7727
7728 @node Portability
7729 @section Making @command{tar} Archives More Portable
7730
7731 Creating a @command{tar} archive on a particular system that is meant to be
7732 useful later on many other machines and with other versions of @command{tar}
7733 is more challenging than you might think. @command{tar} archive formats
7734 have been evolving since the first versions of Unix. Many such formats
7735 are around, and are not always compatible with each other. This section
7736 discusses a few problems, and gives some advice about making @command{tar}
7737 archives more portable.
7738
7739 One golden rule is simplicity. For example, limit your @command{tar}
7740 archives to contain only regular files and directories, avoiding
7741 other kind of special files. Do not attempt to save sparse files or
7742 contiguous files as such. Let's discuss a few more problems, in turn.
7743
7744 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
7745 archives and archive labels) in GNU and PAX formats.}
7746
7747 @menu
7748 * Portable Names:: Portable Names
7749 * dereference:: Symbolic Links
7750 * old:: Old V7 Archives
7751 * ustar:: Ustar Archives
7752 * gnu:: GNU and old GNU format archives.
7753 * posix:: @acronym{POSIX} archives
7754 * Checksumming:: Checksumming Problems
7755 * Large or Negative Values:: Large files, negative time stamps, etc.
7756 @end menu
7757
7758 @node Portable Names
7759 @subsection Portable Names
7760
7761 Use portable file and member names. A name is portable if it contains
7762 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
7763 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
7764 contain @samp{/-}. Avoid deep directory nesting. For portability to
7765 old Unix hosts, limit your file name components to 14 characters or
7766 less.
7767
7768 If you intend to have your @command{tar} archives to be read under
7769 MSDOS, you should not rely on case distinction for file names, and you
7770 might use the @acronym{GNU} @command{doschk} program for helping you
7771 further diagnosing illegal MSDOS names, which are even more limited
7772 than System V's.
7773
7774 @node dereference
7775 @subsection Symbolic Links
7776 @cindex File names, using symbolic links
7777 @cindex Symbolic link as file name
7778
7779 @opindex dereference
7780 Normally, when @command{tar} archives a symbolic link, it writes a
7781 block to the archive naming the target of the link. In that way, the
7782 @command{tar} archive is a faithful record of the file system contents.
7783 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
7784 @command{tar} to archive the files symbolic links point to, instead of
7785 the links themselves. When this option is used, when @command{tar}
7786 encounters a symbolic link, it will archive the linked-to file,
7787 instead of simply recording the presence of a symbolic link.
7788
7789 The name under which the file is stored in the file system is not
7790 recorded in the archive. To record both the symbolic link name and
7791 the file name in the system, archive the file under both names. If
7792 all links were recorded automatically by @command{tar}, an extracted file
7793 might be linked to a file name that no longer exists in the file
7794 system.
7795
7796 If a linked-to file is encountered again by @command{tar} while creating
7797 the same archive, an entire second copy of it will be stored. (This
7798 @emph{might} be considered a bug.)
7799
7800 So, for portable archives, do not archive symbolic links as such,
7801 and use @option{--dereference} (@option{-h}): many systems do not support
7802 symbolic links, and moreover, your distribution might be unusable if
7803 it contains unresolved symbolic links.
7804
7805 @node old
7806 @subsection Old V7 Archives
7807 @cindex Format, old style
7808 @cindex Old style format
7809 @cindex Old style archives
7810 @cindex v7 archive format
7811
7812 Certain old versions of @command{tar} cannot handle additional
7813 information recorded by newer @command{tar} programs. To create an
7814 archive in V7 format (not ANSI), which can be read by these old
7815 versions, specify the @option{--format=v7} option in
7816 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
7817 accepts @option{--portability} or @samp{op-old-archive} for this
7818 option). When you specify it,
7819 @command{tar} leaves out information about directories, pipes, fifos,
7820 contiguous files, and device files, and specifies file ownership by
7821 group and user IDs instead of group and user names.
7822
7823 When updating an archive, do not use @option{--format=v7}
7824 unless the archive was created using this option.
7825
7826 In most cases, a @emph{new} format archive can be read by an @emph{old}
7827 @command{tar} program without serious trouble, so this option should
7828 seldom be needed. On the other hand, most modern @command{tar}s are
7829 able to read old format archives, so it might be safer for you to
7830 always use @option{--format=v7} for your distributions.
7831
7832 @node ustar
7833 @subsection Ustar Archive Format
7834
7835 @cindex ustar archive format
7836 Archive format defined by @acronym{POSIX}.1-1988 specification is called
7837 @code{ustar}. Although it is more flexible than the V7 format, it
7838 still has many restrictions (@xref{Formats,ustar}, for the detailed
7839 description of @code{ustar} format). Along with V7 format,
7840 @code{ustar} format is a good choice for archives intended to be read
7841 with other implementations of @command{tar}.
7842
7843 To create archive in @code{ustar} format, use @option{--format=ustar}
7844 option in conjunction with the @option{--create} (@option{-c}).
7845
7846 @node gnu
7847 @subsection @acronym{GNU} and old @GNUTAR{} format
7848
7849 @cindex GNU archive format
7850 @cindex Old GNU archive format
7851 @GNUTAR{} was based on an early draft of the
7852 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
7853 @command{tar}, such as the support for file names longer than 100
7854 characters, use portions of the @command{tar} header record which were
7855 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
7856 @acronym{POSIX} have allocated the same parts of the header record for
7857 other purposes. As a result, @GNUTAR{} format is
7858 incompatible with the current @acronym{POSIX} specification, and with
7859 @command{tar} programs that follow it.
7860
7861 In the majority of cases, @command{tar} will be configured to create
7862 this format by default. This will change in the future releases, since
7863 we plan to make @samp{posix} format the default.
7864
7865 To force creation a @GNUTAR{} archive, use option
7866 @option{--format=gnu}.
7867
7868 @node posix
7869 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
7870
7871 @cindex POSIX archive format
7872 @cindex PAX archive format
7873 Starting from version 1.14 @GNUTAR{} features full support for
7874 @acronym{POSIX.1-2001} archives.
7875
7876 A @acronym{POSIX} conformant archive will be created if @command{tar}
7877 was given @option{--format=posix} (@option{--format=pax}) option. No
7878 special option is required to read and extract from a @acronym{POSIX}
7879 archive.
7880
7881 @menu
7882 * PAX keywords:: Controlling Extended Header Keywords.
7883 @end menu
7884
7885 @node PAX keywords
7886 @subsubsection Controlling Extended Header Keywords
7887
7888 @table @option
7889 @opindex pax-option
7890 @item --pax-option=@var{keyword-list}
7891 Handle keywords in @acronym{PAX} extended headers. This option is
7892 equivalent to @option{-o} option of the @command{pax} utility.
7893 @end table
7894
7895 @var{Keyword-list} is a comma-separated
7896 list of keyword options, each keyword option taking one of
7897 the following forms:
7898
7899 @table @code
7900 @item delete=@var{pattern}
7901 When used with one of archive-creation commands,
7902 this option instructs @command{tar} to omit from extended header records
7903 that it produces any keywords matching the string @var{pattern}.
7904
7905 When used in extract or list mode, this option instructs tar
7906 to ignore any keywords matching the given @var{pattern} in the extended
7907 header records. In both cases, matching is performed using the pattern
7908 matching notation described in @acronym{POSIX 1003.2}, 3.13
7909 (@pxref{wildcards}). For example:
7910
7911 @smallexample
7912 --pax-option delete=security.*
7913 @end smallexample
7914
7915 would suppress security-related information.
7916
7917 @item exthdr.name=@var{string}
7918
7919 This keyword allows user control over the name that is written into the
7920 ustar header blocks for the extended headers. The name is obtained
7921 from @var{string} after making the following substitutions:
7922
7923 @multitable @columnfractions .25 .55
7924 @headitem Meta-character @tab Replaced By
7925 @item %d @tab The directory name of the file, equivalent to the
7926 result of the @command{dirname} utility on the translated pathname.
7927 @item %f @tab The filename of the file, equivalent to the result
7928 of the @command{basename} utility on the translated pathname.
7929 @item %p @tab The process ID of the @command{tar} process.
7930 @item %% @tab A @samp{%} character.
7931 @end multitable
7932
7933 Any other @samp{%} characters in @var{string} produce undefined
7934 results.
7935
7936 If no option @samp{exthdr.name=string} is specified, @command{tar}
7937 will use the following default value:
7938
7939 @smallexample
7940 %d/PaxHeaders.%p/%f
7941 @end smallexample
7942
7943 @item globexthdr.name=@var{string}
7944 This keyword allows user control over the name that is written into
7945 the ustar header blocks for global extended header records. The name
7946 is obtained from the contents of @var{string}, after making
7947 the following substitutions:
7948
7949 @multitable @columnfractions .25 .55
7950 @headitem Meta-character @tab Replaced By
7951 @item %n @tab An integer that represents the
7952 sequence number of the global extended header record in the archive,
7953 starting at 1.
7954 @item %p @tab The process ID of the @command{tar} process.
7955 @item %% @tab A @samp{%} character.
7956 @end multitable
7957
7958 Any other @samp{%} characters in @var{string} produce undefined results.
7959
7960 If no option @samp{globexthdr.name=string} is specified, @command{tar}
7961 will use the following default value:
7962
7963 @smallexample
7964 $TMPDIR/GlobalHead.%p.%n
7965 @end smallexample
7966
7967 @noindent
7968 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
7969 environment variable. If @var{TMPDIR} is not set, @command{tar}
7970 uses @samp{/tmp}.
7971
7972 @item @var{keyword}=@var{value}
7973 When used with one of archive-creation commands, these keyword/value pairs
7974 will be included at the beginning of the archive in a global extended
7975 header record. When used with one of archive-reading commands,
7976 @command{tar} will behave as if it has encountered these keyword/value
7977 pairs at the beginning of the archive in a global extended header
7978 record.
7979
7980 @item @var{keyword}:=@var{value}
7981 When used with one of archive-creation commands, these keyword/value pairs
7982 will be included as records at the beginning of an extended header for
7983 each file. This is effectively equivalent to @var{keyword}=@var{value}
7984 form except that it creates no global extended header records.
7985
7986 When used with one of archive-reading commands, @command{tar} will
7987 behave as if these keyword/value pairs were included as records at the
7988 end of each extended header; thus, they will override any global or
7989 file-specific extended header record keywords of the same names.
7990 For example, in the command:
7991
7992 @smallexample
7993 tar --format=posix --create \
7994 --file archive --pax-option gname:=user .
7995 @end smallexample
7996
7997 the group name will be forced to a new value for all files
7998 stored in the archive.
7999 @end table
8000
8001 @node Checksumming
8002 @subsection Checksumming Problems
8003
8004 SunOS and HP-UX @command{tar} fail to accept archives created using
8005 @GNUTAR{} and containing non-ASCII file names, that
8006 is, file names having characters with the eight bit set, because they
8007 use signed checksums, while @GNUTAR{} uses unsigned
8008 checksums while creating archives, as per @acronym{POSIX} standards. On
8009 reading, @GNUTAR{} computes both checksums and
8010 accept any. It is somewhat worrying that a lot of people may go
8011 around doing backup of their files using faulty (or at least
8012 non-standard) software, not learning about it until it's time to
8013 restore their missing files with an incompatible file extractor, or
8014 vice versa.
8015
8016 @GNUTAR{} compute checksums both ways, and accept
8017 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8018 wrong checksums. @GNUTAR{} produces the standard
8019 checksum, however, raising incompatibilities with Sun. That is to
8020 say, @GNUTAR{} has not been modified to
8021 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8022 I've been told that more recent Sun @command{tar} now read standard
8023 archives, so maybe Sun did a similar patch, after all?
8024
8025 The story seems to be that when Sun first imported @command{tar}
8026 sources on their system, they recompiled it without realizing that
8027 the checksums were computed differently, because of a change in
8028 the default signing of @code{char}'s in their compiler. So they
8029 started computing checksums wrongly. When they later realized their
8030 mistake, they merely decided to stay compatible with it, and with
8031 themselves afterwards. Presumably, but I do not really know, HP-UX
8032 has chosen that their @command{tar} archives to be compatible with Sun's.
8033 The current standards do not favor Sun @command{tar} format. In any
8034 case, it now falls on the shoulders of SunOS and HP-UX users to get
8035 a @command{tar} able to read the good archives they receive.
8036
8037 @node Large or Negative Values
8038 @subsection Large or Negative Values
8039 @cindex large values
8040 @cindex future time stamps
8041 @cindex negative time stamps
8042 @UNREVISED{}
8043
8044 The above sections suggest to use @samp{oldest possible} archive
8045 format if in doubt. However, sometimes it is not possible. If you
8046 attempt to archive a file whose metadata cannot be represented using
8047 required format, @GNUTAR{} will print error message and ignore such a
8048 file. You will than have to switch to a format that is able to
8049 handle such values. The format summary table (@pxref{Formats}) will
8050 help you to do so.
8051
8052 In particular, when trying to archive files larger than 8GB or with
8053 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8054 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8055 @acronym{POSIX} archive formats. When considering which format to
8056 choose, bear in mind that the @acronym{GNU} format uses
8057 two's-complement base-256 notation to store values that do not fit
8058 into standard @acronym{ustar} range. Such archives can generally be
8059 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8060 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8061 example, using two's complement representation for negative time
8062 stamps that assumes a signed 32-bit @code{time_t} generates archives
8063 that are not portable to hosts with differing @code{time_t}
8064 representations.
8065
8066 On the other hand, @acronym{POSIX} archives, generally speaking, can
8067 be extracted by any tar implementation that understands older
8068 @acronym{ustar} format. The only exception are files larger than 8GB.
8069
8070 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8071 POSIX-aware tars.}
8072
8073 @node Compression
8074 @section Using Less Space through Compression
8075
8076 @menu
8077 * gzip:: Creating and Reading Compressed Archives
8078 * sparse:: Archiving Sparse Files
8079 @end menu
8080
8081 @node gzip
8082 @subsection Creating and Reading Compressed Archives
8083 @cindex Compressed archives
8084 @cindex Storing archives in compressed format
8085
8086 @GNUTAR{} is able to create and read compressed archives. It supports
8087 @command{gzip} and @command{bzip2} compression programs. For backward
8088 compatibilty, it also supports @command{compress} command, although
8089 we strongly recommend against using it, since there is a patent
8090 covering the algorithm it uses and you could be sued for patent
8091 infringement merely by running @command{compress}! Besides, it is less
8092 effective than @command{gzip} and @command{bzip2}.
8093
8094 Creating a compressed archive is simple: you just specify a
8095 @dfn{compression option} along with the usual archive creation
8096 commands. The compression option is @option{-z} (@option{--gzip}) to
8097 create a @command{gzip} compressed archive, @option{-j}
8098 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
8099 @option{-Z} (@option{--compress}) to use @command{compress} program.
8100 For example:
8101
8102 @smallexample
8103 $ @kbd{tar cfz archive.tar.gz .}
8104 @end smallexample
8105
8106 Reading compressed archive is even simpler: you don't need to specify
8107 any additional options as @GNUTAR{} recognizes its format
8108 automatically. Thus, the following commands will list and extract the
8109 archive created in previous example:
8110
8111 @smallexample
8112 # List the compressed archive
8113 $ @kbd{tar tf archive.tar.gz}
8114 # Extract the compressed archive
8115 $ @kbd{tar xf archive.tar.gz}
8116 @end smallexample
8117
8118 The only case when you have to specify a decompression option while
8119 reading the archive is when reading from a pipe or from a tape drive
8120 that does not support random access. However, in this case @GNUTAR{}
8121 will indicate which option you should use. For example:
8122
8123 @smallexample
8124 $ @kbd{cat archive.tar.gz | tar tf -}
8125 tar: Archive is compressed. Use -z option
8126 tar: Error is not recoverable: exiting now
8127 @end smallexample
8128
8129 If you see such diagnostics, just add the suggested option to the
8130 invocation of @GNUTAR{}:
8131
8132 @smallexample
8133 $ @kbd{cat archive.tar.gz | tar tfz -}
8134 @end smallexample
8135
8136 Notice also, that there are several restrictions on operations on
8137 compressed archives. First of all, compressed archives cannot be
8138 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8139 (@option{--delete}) members from them. Likewise, you cannot append
8140 another @command{tar} archive to a compressed archive using
8141 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8142 compressed.
8143
8144 The following table summarizes compression options used by @GNUTAR{}.
8145
8146 @table @option
8147 @opindex gzip
8148 @opindex ungzip
8149 @item -z
8150 @itemx --gzip
8151 @itemx --ungzip
8152 Filter the archive through @command{gzip}.
8153
8154 You can use @option{--gzip} and @option{--gunzip} on physical devices
8155 (tape drives, etc.) and remote files as well as on normal files; data
8156 to or from such devices or remote files is reblocked by another copy
8157 of the @command{tar} program to enforce the specified (or default) record
8158 size. The default compression parameters are used; if you need to
8159 override them, set @env{GZIP} environment variable, e.g.:
8160
8161 @smallexample
8162 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8163 @end smallexample
8164
8165 @noindent
8166 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8167 @command{gzip} explicitly:
8168
8169 @smallexample
8170 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8171 @end smallexample
8172
8173 @cindex corrupted archives
8174 About corrupted compressed archives: @command{gzip}'ed files have no
8175 redundancy, for maximum compression. The adaptive nature of the
8176 compression scheme means that the compression tables are implicitly
8177 spread all over the archive. If you lose a few blocks, the dynamic
8178 construction of the compression tables becomes unsynchronized, and there
8179 is little chance that you could recover later in the archive.
8180
8181 There are pending suggestions for having a per-volume or per-file
8182 compression in @GNUTAR{}. This would allow for viewing the
8183 contents without decompression, and for resynchronizing decompression at
8184 every volume or file, in case of corrupted archives. Doing so, we might
8185 lose some compressibility. But this would have make recovering easier.
8186 So, there are pros and cons. We'll see!
8187
8188 @opindex bzip2
8189 @item -j
8190 @itemx --bzip2
8191 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8192
8193 @opindex compress
8194 @opindex uncompress
8195 @item -Z
8196 @itemx --compress
8197 @itemx --uncompress
8198 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8199
8200 The @acronym{GNU} Project recommends you not use
8201 @command{compress}, because there is a patent covering the algorithm it
8202 uses. You could be sued for patent infringement merely by running
8203 @command{compress}.
8204
8205 @opindex use-compress-program
8206 @item --use-compress-program=@var{prog}
8207 Use external compression program @var{prog}. Use this option if you
8208 have a compression program that @GNUTAR{} does not support. There
8209 are two requirements to which @var{prog} should comply:
8210
8211 First, when called without options, it should read data from standard
8212 input, compress it and output it on standard output.
8213
8214 Secondly, if called with @option{-d} argument, it should do exactly
8215 the opposite, i.e., read the compressed data from the standard input
8216 and produce uncompressed data on the standard output.
8217 @end table
8218
8219 @cindex gpg, using with tar
8220 @cindex gnupg, using with tar
8221 @cindex Using encrypted archives
8222 The @option{--use-compress-program} option, in particular, lets you
8223 implement your own filters, not necessarily dealing with
8224 compression/decomression. For example, suppose you wish to implement
8225 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8226 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8227 Manual}). The following script does that:
8228
8229 @smallexample
8230 @group
8231 #! /bin/sh
8232 case $1 in
8233 -d) gpg --decrypt - | gzip -d -c;;
8234 '') gzip -c | gpg -s ;;
8235 *) echo "Unknown option $1">&2; exit 1;;
8236 esac
8237 @end group
8238 @end smallexample
8239
8240 Suppose you name it @file{gpgz} and save it somewhere in your
8241 @env{PATH}. Then the following command will create a commpressed
8242 archive signed with your private key:
8243
8244 @smallexample
8245 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8246 @end smallexample
8247
8248 @noindent
8249 Likewise, the following command will list its contents:
8250
8251 @smallexample
8252 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8253 @end smallexample
8254
8255 @ignore
8256 The above is based on the following discussion:
8257
8258 I have one question, or maybe it's a suggestion if there isn't a way
8259 to do it now. I would like to use @option{--gzip}, but I'd also like
8260 the output to be fed through a program like @acronym{GNU}
8261 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8262 to use :-)), basically adding ECC protection on top of compression.
8263 It seems as if this should be quite easy to do, but I can't work out
8264 exactly how to go about it. Of course, I can pipe the standard output
8265 of @command{tar} through @command{ecc}, but then I lose (though I
8266 haven't started using it yet, I confess) the ability to have
8267 @command{tar} use @command{rmt} for it's I/O (I think).
8268
8269 I think the most straightforward thing would be to let me specify a
8270 general set of filters outboard of compression (preferably ordered,
8271 so the order can be automatically reversed on input operations, and
8272 with the options they require specifiable), but beggars shouldn't be
8273 choosers and anything you decide on would be fine with me.
8274
8275 By the way, I like @command{ecc} but if (as the comments say) it can't
8276 deal with loss of block sync, I'm tempted to throw some time at adding
8277 that capability. Supposing I were to actually do such a thing and
8278 get it (apparently) working, do you accept contributed changes to
8279 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8280
8281 Isn't that exactly the role of the
8282 @option{--use-compress-prog=@var{program}} option?
8283 I never tried it myself, but I suspect you may want to write a
8284 @var{prog} script or program able to filter stdin to stdout to
8285 way you want. It should recognize the @option{-d} option, for when
8286 extraction is needed rather than creation.
8287
8288 It has been reported that if one writes compressed data (through the
8289 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8290 the DLT compression mode, the data will actually get bigger and one will
8291 end up with less space on the tape.
8292 @end ignore
8293
8294 @node sparse
8295 @subsection Archiving Sparse Files
8296 @cindex Sparse Files
8297 @UNREVISED
8298
8299 @table @option
8300 @opindex sparse
8301 @item -S
8302 @itemx --sparse
8303 Handle sparse files efficiently.
8304 @end table
8305
8306 This option causes all files to be put in the archive to be tested for
8307 sparseness, and handled specially if they are. The @option{--sparse}
8308 (@option{-S}) option is useful when many @code{dbm} files, for example, are being
8309 backed up. Using this option dramatically decreases the amount of
8310 space needed to store such a file.
8311
8312 In later versions, this option may be removed, and the testing and
8313 treatment of sparse files may be done automatically with any special
8314 @acronym{GNU} options. For now, it is an option needing to be specified on
8315 the command line with the creation or updating of an archive.
8316
8317 Files in the file system occasionally have @dfn{holes}. A @dfn{hole} in a file
8318 is a section of the file's contents which was never written. The
8319 contents of a hole read as all zeros. On many operating systems,
8320 actual disk storage is not allocated for holes, but they are counted
8321 in the length of the file. If you archive such a file, @command{tar}
8322 could create an archive longer than the original. To have @command{tar}
8323 attempt to recognize the holes in a file, use @option{--sparse} (@option{-S}). When
8324 you use this option, then, for any file using less disk space than
8325 would be expected from its length, @command{tar} searches the file for
8326 consecutive stretches of zeros. It then records in the archive for
8327 the file where the consecutive stretches of zeros are, and only
8328 archives the ``real contents'' of the file. On extraction (using
8329 @option{--sparse} is not needed on extraction) any such
8330 files have holes created wherever the continuous stretches of zeros
8331 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8332 won't take more space than the original.
8333
8334 A file is sparse if it contains blocks of zeros whose existence is
8335 recorded, but that have no space allocated on disk. When you specify
8336 the @option{--sparse} option in conjunction with the @option{--create}
8337 (@option{-c}) operation, @command{tar} tests all files for sparseness
8338 while archiving. If @command{tar} finds a file to be sparse, it uses a
8339 sparse representation of the file in the archive. @xref{create}, for
8340 more information about creating archives.
8341
8342 @option{--sparse} is useful when archiving files, such as dbm files,
8343 likely to contain many nulls. This option dramatically
8344 decreases the amount of space needed to store such an archive.
8345
8346 @quotation
8347 @strong{Please Note:} Always use @option{--sparse} when performing file
8348 system backups, to avoid archiving the expanded forms of files stored
8349 sparsely in the system.
8350
8351 Even if your system has no sparse files currently, some may be
8352 created in the future. If you use @option{--sparse} while making file
8353 system backups as a matter of course, you can be assured the archive
8354 will never take more space on the media than the files take on disk
8355 (otherwise, archiving a disk filled with sparse files might take
8356 hundreds of tapes). @xref{Incremental Dumps}.
8357 @end quotation
8358
8359 @command{tar} ignores the @option{--sparse} option when reading an archive.
8360
8361 @table @option
8362 @item --sparse
8363 @itemx -S
8364 Files stored sparsely in the file system are represented sparsely in
8365 the archive. Use in conjunction with write operations.
8366 @end table
8367
8368 However, users should be well aware that at archive creation time,
8369 @GNUTAR{} still has to read whole disk file to
8370 locate the @dfn{holes}, and so, even if sparse files use little space
8371 on disk and in the archive, they may sometimes require inordinate
8372 amount of time for reading and examining all-zero blocks of a file.
8373 Although it works, it's painfully slow for a large (sparse) file, even
8374 though the resulting tar archive may be small. (One user reports that
8375 dumping a @file{core} file of over 400 megabytes, but with only about
8376 3 megabytes of actual data, took about 9 minutes on a Sun Sparcstation
8377 ELC, with full CPU utilization.)
8378
8379 This reading is required in all cases and is not related to the fact
8380 the @option{--sparse} option is used or not, so by merely @emph{not}
8381 using the option, you are not saving time@footnote{Well! We should say
8382 the whole truth, here. When @option{--sparse} is selected while creating
8383 an archive, the current @command{tar} algorithm requires sparse files to be
8384 read twice, not once. We hope to develop a new archive format for saving
8385 sparse files in which one pass will be sufficient.}.
8386
8387 Programs like @command{dump} do not have to read the entire file; by
8388 examining the file system directly, they can determine in advance
8389 exactly where the holes are and thus avoid reading through them. The
8390 only data it need read are the actual allocated data blocks.
8391 @GNUTAR{} uses a more portable and straightforward
8392 archiving approach, it would be fairly difficult that it does
8393 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8394 1990-12-10:
8395
8396 @quotation
8397 What I did say is that you cannot tell the difference between a hole and an
8398 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8399 best tells you how many holes there are; it doesn't tell you @emph{where}.
8400 Just as programs may, conceivably, care what @code{st_blocks} is (care
8401 to name one that does?), they may also care where the holes are (I have
8402 no examples of this one either, but it's equally imaginable).
8403
8404 I conclude from this that good archivers are not portable. One can
8405 arguably conclude that if you want a portable program, you can in good
8406 conscience restore files with as many holes as possible, since you can't
8407 get it right.
8408 @end quotation
8409
8410 @node Attributes
8411 @section Handling File Attributes
8412 @UNREVISED
8413
8414 When @command{tar} reads files, it updates their access times. To
8415 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8416 reset the access time retroactively or avoid changing it in the first
8417 place.
8418
8419 Handling of file attributes
8420
8421 @table @option
8422 @opindex atime-preserve
8423 @item --atime-preserve
8424 @itemx --atime-preserve=replace
8425 @itemx --atime-preserve=system
8426 Preserve the access times of files that are read. This works only for
8427 files that you own, unless you have superuser privileges.
8428
8429 @option{--atime-preserve=replace} works on most systems, but it also
8430 restores the data modification time and updates the status change
8431 time. Hence it doesn't interact with incremental dumps nicely
8432 (@pxref{Backups}), and it can set access or data modification times
8433 incorrectly if other programs access the file while @command{tar} is
8434 running.
8435
8436 @option{--atime-preserve=system} avoids changing the access time in
8437 the first place, if the operating system supports this.
8438 Unfortunately, this may or may not work on any given operating system
8439 or file system. If @command{tar} knows for sure it won't work, it
8440 complains right away.
8441
8442 Currently @option{--atime-preserve} with no operand defaults to
8443 @option{--atime-preserve=replace}, but this is intended to change to
8444 @option{--atime-preserve=system} when the latter is better-supported.
8445
8446 @opindex touch
8447 @item -m
8448 @itemx --touch
8449 Do not extract data modification time.
8450
8451 When this option is used, @command{tar} leaves the data modification times
8452 of the files it extracts as the times when the files were extracted,
8453 instead of setting it to the times recorded in the archive.
8454
8455 This option is meaningless with @option{--list} (@option{-t}).
8456
8457 @opindex same-owner
8458 @item --same-owner
8459 Create extracted files with the same ownership they have in the
8460 archive.
8461
8462 This is the default behavior for the superuser,
8463 so this option is meaningful only for non-root users, when @command{tar}
8464 is executed on those systems able to give files away. This is
8465 considered as a security flaw by many people, at least because it
8466 makes quite difficult to correctly account users for the disk space
8467 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8468 files are easily and silently lost when files are given away.
8469
8470 When writing an archive, @command{tar} writes the user id and user name
8471 separately. If it can't find a user name (because the user id is not
8472 in @file{/etc/passwd}), then it does not write one. When restoring,
8473 it tries to look the name (if one was written) up in
8474 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8475 the archive instead.
8476
8477 @opindex no-same-owner
8478 @item --no-same-owner
8479 @itemx -o
8480 Do not attempt to restore ownership when extracting. This is the
8481 default behavior for ordinary users, so this option has an effect
8482 only for the superuser.
8483
8484 @opindex numeric-owner
8485 @item --numeric-owner
8486 The @option{--numeric-owner} option allows (ANSI) archives to be written
8487 without user/group name information or such information to be ignored
8488 when extracting. It effectively disables the generation and/or use
8489 of user/group name information. This option forces extraction using
8490 the numeric ids from the archive, ignoring the names.
8491
8492 This is useful in certain circumstances, when restoring a backup from
8493 an emergency floppy with different passwd/group files for example.
8494 It is otherwise impossible to extract files with the right ownerships
8495 if the password file in use during the extraction does not match the
8496 one belonging to the file system(s) being extracted. This occurs,
8497 for example, if you are restoring your files after a major crash and
8498 had booted from an emergency floppy with no password file or put your
8499 disk into another machine to do the restore.
8500
8501 The numeric ids are @emph{always} saved into @command{tar} archives.
8502 The identifying names are added at create time when provided by the
8503 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8504 used when moving archives between a collection of machines using
8505 a centralized management for attribution of numeric ids to users
8506 and groups. This is often made through using the NIS capabilities.
8507
8508 When making a @command{tar} file for distribution to other sites, it
8509 is sometimes cleaner to use a single owner for all files in the
8510 distribution, and nicer to specify the write permission bits of the
8511 files as stored in the archive independently of their actual value on
8512 the file system. The way to prepare a clean distribution is usually
8513 to have some Makefile rule creating a directory, copying all needed
8514 files in that directory, then setting ownership and permissions as
8515 wanted (there are a lot of possible schemes), and only then making a
8516 @command{tar} archive out of this directory, before cleaning
8517 everything out. Of course, we could add a lot of options to
8518 @GNUTAR{} for fine tuning permissions and ownership.
8519 This is not the good way, I think. @GNUTAR{} is
8520 already crowded with options and moreover, the approach just explained
8521 gives you a great deal of control already.
8522
8523 @xopindex{same-permissions, short description}
8524 @xopindex{preserve-permissions, short description}
8525 @item -p
8526 @itemx --same-permissions
8527 @itemx --preserve-permissions
8528 Extract all protection information.
8529
8530 This option causes @command{tar} to set the modes (access permissions) of
8531 extracted files exactly as recorded in the archive. If this option
8532 is not used, the current @code{umask} setting limits the permissions
8533 on extracted files. This option is by default enabled when
8534 @command{tar} is executed by a superuser.
8535
8536
8537 This option is meaningless with @option{--list} (@option{-t}).
8538
8539 @opindex preserve
8540 @item --preserve
8541 Same as both @option{--same-permissions} and @option{--same-order}.
8542
8543 The @option{--preserve} option has no equivalent short option name.
8544 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8545
8546 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8547 Neither do I. --Sergey}
8548
8549 @end table
8550
8551 @node cpio
8552 @section Comparison of @command{tar} and @command{cpio}
8553 @UNREVISED
8554
8555 @FIXME{Reorganize the following material}
8556
8557 The @command{cpio} archive formats, like @command{tar}, do have maximum
8558 pathname lengths. The binary and old ASCII formats have a max path
8559 length of 256, and the new ASCII and CRC ASCII formats have a max
8560 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8561 with arbitrary pathname lengths, but other @command{cpio} implementations
8562 may crash unexplainedly trying to read them.
8563
8564 @command{tar} handles symbolic links in the form in which it comes in BSD;
8565 @command{cpio} doesn't handle symbolic links in the form in which it comes
8566 in System V prior to SVR4, and some vendors may have added symlinks
8567 to their system without enhancing @command{cpio} to know about them.
8568 Others may have enhanced it in a way other than the way I did it
8569 at Sun, and which was adopted by AT&T (and which is, I think, also
8570 present in the @command{cpio} that Berkeley picked up from AT&T and put
8571 into a later BSD release---I think I gave them my changes).
8572
8573 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8574 can handle @command{tar} format input, and write it on output, and it
8575 probably handles symbolic links. They may not have bothered doing
8576 anything to enhance @command{tar} as a result.)
8577
8578 @command{cpio} handles special files; traditional @command{tar} doesn't.
8579
8580 @command{tar} comes with V7, System III, System V, and BSD source;
8581 @command{cpio} comes only with System III, System V, and later BSD
8582 (4.3-tahoe and later).
8583
8584 @command{tar}'s way of handling multiple hard links to a file can handle
8585 file systems that support 32-bit inumbers (e.g., the BSD file system);
8586 @command{cpio}s way requires you to play some games (in its "binary"
8587 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8588 they're 18 bits---it would have to play games with the "file system ID"
8589 field of the header to make sure that the file system ID/i-number pairs
8590 of different files were always different), and I don't know which
8591 @command{cpio}s, if any, play those games. Those that don't might get
8592 confused and think two files are the same file when they're not, and
8593 make hard links between them.
8594
8595 @command{tar}s way of handling multiple hard links to a file places only
8596 one copy of the link on the tape, but the name attached to that copy
8597 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8598 way puts one copy for every link, but you can retrieve it using any
8599 of the names.
8600
8601 @quotation
8602 What type of check sum (if any) is used, and how is this calculated.
8603 @end quotation
8604
8605 See the attached manual pages for @command{tar} and @command{cpio} format.
8606 @command{tar} uses a checksum which is the sum of all the bytes in the
8607 @command{tar} header for a file; @command{cpio} uses no checksum.
8608
8609 @quotation
8610 If anyone knows why @command{cpio} was made when @command{tar} was present
8611 at the unix scene,
8612 @end quotation
8613
8614 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8615 generally-available version of UNIX had @command{tar} at the time. I don't
8616 know whether any version that was generally available @emph{within AT&T}
8617 had @command{tar}, or, if so, whether the people within AT&T who did
8618 @command{cpio} knew about it.
8619
8620 On restore, if there is a corruption on a tape @command{tar} will stop at
8621 that point, while @command{cpio} will skip over it and try to restore the
8622 rest of the files.
8623
8624 The main difference is just in the command syntax and header format.
8625
8626 @command{tar} is a little more tape-oriented in that everything is blocked
8627 to start on a record boundary.
8628
8629 @quotation
8630 Is there any differences between the ability to recover crashed
8631 archives between the two of them. (Is there any chance of recovering
8632 crashed archives at all.)
8633 @end quotation
8634
8635 Theoretically it should be easier under @command{tar} since the blocking
8636 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
8637 However, modern @command{cpio}'s and variations have an option to just
8638 search for the next file header after an error with a reasonable chance
8639 of resyncing. However, lots of tape driver software won't allow you to
8640 continue past a media error which should be the only reason for getting
8641 out of sync unless a file changed sizes while you were writing the
8642 archive.
8643
8644 @quotation
8645 If anyone knows why @command{cpio} was made when @command{tar} was present
8646 at the unix scene, please tell me about this too.
8647 @end quotation
8648
8649 Probably because it is more media efficient (by not blocking everything
8650 and using only the space needed for the headers where @command{tar}
8651 always uses 512 bytes per file header) and it knows how to archive
8652 special files.
8653
8654 You might want to look at the freely available alternatives. The
8655 major ones are @command{afio}, @GNUTAR{}, and
8656 @command{pax}, each of which have their own extensions with some
8657 backwards compatibility.
8658
8659 Sparse files were @command{tar}red as sparse files (which you can
8660 easily test, because the resulting archive gets smaller, and
8661 @acronym{GNU} @command{cpio} can no longer read it).
8662
8663 @node Media
8664 @chapter Tapes and Other Archive Media
8665 @UNREVISED
8666
8667 A few special cases about tape handling warrant more detailed
8668 description. These special cases are discussed below.
8669
8670 Many complexities surround the use of @command{tar} on tape drives. Since
8671 the creation and manipulation of archives located on magnetic tape was
8672 the original purpose of @command{tar}, it contains many features making
8673 such manipulation easier.
8674
8675 Archives are usually written on dismountable media---tape cartridges,
8676 mag tapes, or floppy disks.
8677
8678 The amount of data a tape or disk holds depends not only on its size,
8679 but also on how it is formatted. A 2400 foot long reel of mag tape
8680 holds 40 megabytes of data when formatted at 1600 bits per inch. The
8681 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
8682
8683 Magnetic media are re-usable---once the archive on a tape is no longer
8684 needed, the archive can be erased and the tape or disk used over.
8685 Media quality does deteriorate with use, however. Most tapes or disks
8686 should be discarded when they begin to produce data errors. EXABYTE
8687 tape cartridges should be discarded when they generate an @dfn{error
8688 count} (number of non-usable bits) of more than 10k.
8689
8690 Magnetic media are written and erased using magnetic fields, and
8691 should be protected from such fields to avoid damage to stored data.
8692 Sticking a floppy disk to a filing cabinet using a magnet is probably
8693 not a good idea.
8694
8695 @menu
8696 * Device:: Device selection and switching
8697 * Remote Tape Server::
8698 * Common Problems and Solutions::
8699 * Blocking:: Blocking
8700 * Many:: Many archives on one tape
8701 * Using Multiple Tapes:: Using Multiple Tapes
8702 * label:: Including a Label in the Archive
8703 * verify::
8704 * Write Protection::
8705 @end menu
8706
8707 @node Device
8708 @section Device Selection and Switching
8709 @UNREVISED
8710
8711 @table @option
8712 @item -f [@var{hostname}:]@var{file}
8713 @itemx --file=[@var{hostname}:]@var{file}
8714 Use archive file or device @var{file} on @var{hostname}.
8715 @end table
8716
8717 This option is used to specify the file name of the archive @command{tar}
8718 works on.
8719
8720 If the file name is @samp{-}, @command{tar} reads the archive from standard
8721 input (when listing or extracting), or writes it to standard output
8722 (when creating). If the @samp{-} file name is given when updating an
8723 archive, @command{tar} will read the original archive from its standard
8724 input, and will write the entire new archive to its standard output.
8725
8726 If the file name contains a @samp{:}, it is interpreted as
8727 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
8728 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
8729 either case, @command{tar} will invoke the command @command{rsh} (or
8730 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
8731 machine. If you give an alternate login name, it will be given to the
8732 @command{rsh}.
8733 Naturally, the remote machine must have an executable
8734 @command{/usr/libexec/rmt}. This program is free software from the
8735 University of California, and a copy of the source code can be found
8736 with the sources for @command{tar}; it's compiled and installed by default.
8737 The exact path to this utility is determined when configuring the package.
8738 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
8739 your installation prefix. This location may also be overridden at
8740 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
8741 ---rmt-command}, for detailed description of this option. @xref{Remote
8742 Tape Server}, for the description of @command{rmt} command).
8743
8744 If this option is not given, but the environment variable @env{TAPE}
8745 is set, its value is used; otherwise, old versions of @command{tar}
8746 used a default archive name (which was picked when @command{tar} was
8747 compiled). The default is normally set up to be the @dfn{first} tape
8748 drive or other transportable I/O medium on the system.
8749
8750 Starting with version 1.11.5, @GNUTAR{} uses
8751 standard input and standard output as the default device, and I will
8752 not try anymore supporting automatic device detection at installation
8753 time. This was failing really in too many cases, it was hopeless.
8754 This is now completely left to the installer to override standard
8755 input and standard output for default device, if this seems
8756 preferable. Further, I think @emph{most} actual usages of
8757 @command{tar} are done with pipes or disks, not really tapes,
8758 cartridges or diskettes.
8759
8760 Some users think that using standard input and output is running
8761 after trouble. This could lead to a nasty surprise on your screen if
8762 you forget to specify an output file name---especially if you are going
8763 through a network or terminal server capable of buffering large amounts
8764 of output. We had so many bug reports in that area of configuring
8765 default tapes automatically, and so many contradicting requests, that
8766 we finally consider the problem to be portably intractable. We could
8767 of course use something like @samp{/dev/tape} as a default, but this
8768 is @emph{also} running after various kind of trouble, going from hung
8769 processes to accidental destruction of real tapes. After having seen
8770 all this mess, using standard input and output as a default really
8771 sounds like the only clean choice left, and a very useful one too.
8772
8773 @GNUTAR{} reads and writes archive in records, I
8774 suspect this is the main reason why block devices are preferred over
8775 character devices. Most probably, block devices are more efficient
8776 too. The installer could also check for @samp{DEFTAPE} in
8777 @file{<sys/mtio.h>}.
8778
8779 @table @option
8780 @xopindex{force-local, short description}
8781 @item --force-local
8782 Archive file is local even if it contains a colon.
8783
8784 @opindex rsh-command
8785 @item --rsh-command=@var{command}
8786 Use remote @var{command} instead of @command{rsh}. This option exists
8787 so that people who use something other than the standard @command{rsh}
8788 (e.g., a Kerberized @command{rsh}) can access a remote device.
8789
8790 When this command is not used, the shell command found when
8791 the @command{tar} program was installed is used instead. This is
8792 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
8793 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
8794 The installer may have overridden this by defining the environment
8795 variable @env{RSH} @emph{at installation time}.
8796
8797 @item -[0-7][lmh]
8798 Specify drive and density.
8799
8800 @xopindex{multi-volume, short description}
8801 @item -M
8802 @itemx --multi-volume
8803 Create/list/extract multi-volume archive.
8804
8805 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
8806 that may be larger than will fit on the medium used to hold it.
8807 @xref{Multi-Volume Archives}.
8808
8809 @xopindex{tape-length, short description}
8810 @item -L @var{num}
8811 @itemx --tape-length=@var{num}
8812 Change tape after writing @var{num} x 1024 bytes.
8813
8814 This option might be useful when your tape drivers do not properly
8815 detect end of physical tapes. By being slightly conservative on the
8816 maximum tape length, you might avoid the problem entirely.
8817
8818 @xopindex{info-script, short description}
8819 @xopindex{new-volume-script, short description}
8820 @item -F @var{file}
8821 @itemx --info-script=@var{file}
8822 @itemx --new-volume-script=@var{file}
8823 Execute @file{file} at end of each tape. This implies
8824 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
8825 description of this option.
8826 @end table
8827
8828 @node Remote Tape Server
8829 @section The Remote Tape Server
8830
8831 @cindex remote tape drive
8832 @pindex rmt
8833 In order to access the tape drive on a remote machine, @command{tar}
8834 uses the remote tape server written at the University of California at
8835 Berkeley. The remote tape server must be installed as
8836 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
8837 want to use. @command{tar} calls @command{rmt} by running an
8838 @command{rsh} or @command{remsh} to the remote machine, optionally
8839 using a different login name if one is supplied.
8840
8841 A copy of the source for the remote tape server is provided. It is
8842 Copyright @copyright{} 1983 by the Regents of the University of
8843 California, but can be freely distributed. It is compiled and
8844 installed by default.
8845
8846 @cindex absolute file names
8847 Unless you use the @option{--absolute-names} (@option{-P}) option,
8848 @GNUTAR{} will not allow you to create an archive that contains
8849 absolute file names (a file name beginning with @samp{/}.) If you try,
8850 @command{tar} will automatically remove the leading @samp{/} from the
8851 file names it stores in the archive. It will also type a warning
8852 message telling you what it is doing.
8853
8854 When reading an archive that was created with a different
8855 @command{tar} program, @GNUTAR{} automatically
8856 extracts entries in the archive which have absolute file names as if
8857 the file names were not absolute. This is an important feature. A
8858 visitor here once gave a @command{tar} tape to an operator to restore;
8859 the operator used Sun @command{tar} instead of @GNUTAR{},
8860 and the result was that it replaced large portions of
8861 our @file{/bin} and friends with versions from the tape; needless to
8862 say, we were unhappy about having to recover the file system from
8863 backup tapes.
8864
8865 For example, if the archive contained a file @file{/usr/bin/computoy},
8866 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
8867 relative to the current directory. If you want to extract the files in
8868 an archive to the same absolute names that they had when the archive
8869 was created, you should do a @samp{cd /} before extracting the files
8870 from the archive, or you should either use the @option{--absolute-names}
8871 option, or use the command @samp{tar -C / @dots{}}.
8872
8873 @cindex Ultrix 3.1 and write failure
8874 Some versions of Unix (Ultrix 3.1 is known to have this problem),
8875 can claim that a short write near the end of a tape succeeded,
8876 when it actually failed. This will result in the -M option not
8877 working correctly. The best workaround at the moment is to use a
8878 significantly larger blocking factor than the default 20.
8879
8880 In order to update an archive, @command{tar} must be able to backspace the
8881 archive in order to reread or rewrite a record that was just read (or
8882 written). This is currently possible only on two kinds of files: normal
8883 disk files (or any other file that can be backspaced with @samp{lseek}),
8884 and industry-standard 9-track magnetic tape (or any other kind of tape
8885 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
8886
8887 This means that the @option{--append}, @option{--concatenate}, and
8888 @option{--delete} commands will not work on any other kind of file.
8889 Some media simply cannot be backspaced, which means these commands and
8890 options will never be able to work on them. These non-backspacing
8891 media include pipes and cartridge tape drives.
8892
8893 Some other media can be backspaced, and @command{tar} will work on them
8894 once @command{tar} is modified to do so.
8895
8896 Archives created with the @option{--multi-volume}, @option{--label}, and
8897 @option{--incremental} (@option{-G}) options may not be readable by other version
8898 of @command{tar}. In particular, restoring a file that was split over
8899 a volume boundary will require some careful work with @command{dd}, if
8900 it can be done at all. Other versions of @command{tar} may also create
8901 an empty file whose name is that of the volume header. Some versions
8902 of @command{tar} may create normal files instead of directories archived
8903 with the @option{--incremental} (@option{-G}) option.
8904
8905 @node Common Problems and Solutions
8906 @section Some Common Problems and their Solutions
8907
8908 @ifclear PUBLISH
8909
8910 @format
8911 errors from system:
8912 permission denied
8913 no such file or directory
8914 not owner
8915
8916 errors from @command{tar}:
8917 directory checksum error
8918 header format error
8919
8920 errors from media/system:
8921 i/o error
8922 device busy
8923 @end format
8924
8925 @end ifclear
8926
8927 @node Blocking
8928 @section Blocking
8929 @UNREVISED
8930
8931 @dfn{Block} and @dfn{record} terminology is rather confused, and it
8932 is also confusing to the expert reader. On the other hand, readers
8933 who are new to the field have a fresh mind, and they may safely skip
8934 the next two paragraphs, as the remainder of this manual uses those
8935 two terms in a quite consistent way.
8936
8937 John Gilmore, the writer of the public domain @command{tar} from which
8938 @GNUTAR{} was originally derived, wrote (June 1995):
8939
8940 @quotation
8941 The nomenclature of tape drives comes from IBM, where I believe
8942 they were invented for the IBM 650 or so. On IBM mainframes, what
8943 is recorded on tape are tape blocks. The logical organization of
8944 data is into records. There are various ways of putting records into
8945 blocks, including @code{F} (fixed sized records), @code{V} (variable
8946 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
8947 to a block), @code{VB} (variable size records, @var{n} to a block),
8948 @code{VSB} (variable spanned blocked: variable sized records that can
8949 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
8950 parameter specified this to the operating system.
8951
8952 The Unix man page on @command{tar} was totally confused about this.
8953 When I wrote @code{PD TAR}, I used the historically correct terminology
8954 (@command{tar} writes data records, which are grouped into blocks).
8955 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
8956 here), and now Fran@,{c}ois has migrated that terminology back
8957 into the source code too.
8958 @end quotation
8959
8960 The term @dfn{physical block} means the basic transfer chunk from or
8961 to a device, after which reading or writing may stop without anything
8962 being lost. In this manual, the term @dfn{block} usually refers to
8963 a disk physical block, @emph{assuming} that each disk block is 512
8964 bytes in length. It is true that some disk devices have different
8965 physical blocks, but @command{tar} ignore these differences in its own
8966 format, which is meant to be portable, so a @command{tar} block is always
8967 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
8968 The term @dfn{logical block} often represents the basic chunk of
8969 allocation of many disk blocks as a single entity, which the operating
8970 system treats somewhat atomically; this concept is only barely used
8971 in @GNUTAR{}.
8972
8973 The term @dfn{physical record} is another way to speak of a physical
8974 block, those two terms are somewhat interchangeable. In this manual,
8975 the term @dfn{record} usually refers to a tape physical block,
8976 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
8977 It is true that archives may be put on disk or used with pipes,
8978 but nevertheless, @command{tar} tries to read and write the archive one
8979 @dfn{record} at a time, whatever the medium in use. One record is made
8980 up of an integral number of blocks, and this operation of putting many
8981 disk blocks into a single tape block is called @dfn{reblocking}, or
8982 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
8983 the logical organization of many characters into something meaningful
8984 to the application. The term @dfn{unit record} describes a small set
8985 of characters which are transmitted whole to or by the application,
8986 and often refers to a line of text. Those two last terms are unrelated
8987 to what we call a @dfn{record} in @GNUTAR{}.
8988
8989 When writing to tapes, @command{tar} writes the contents of the archive
8990 in chunks known as @dfn{records}. To change the default blocking
8991 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
8992 @var{512-size}}) option. Each record will then be composed of
8993 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
8994 @xref{Standard}.) Each file written to the archive uses at least one
8995 full record. As a result, using a larger record size can result in
8996 more wasted space for small files. On the other hand, a larger record
8997 size can often be read and written much more efficiently.
8998
8999 Further complicating the problem is that some tape drives ignore the
9000 blocking entirely. For these, a larger record size can still improve
9001 performance (because the software layers above the tape drive still
9002 honor the blocking), but not as dramatically as on tape drives that
9003 honor blocking.
9004
9005 When reading an archive, @command{tar} can usually figure out the
9006 record size on itself. When this is the case, and a non-standard
9007 record size was used when the archive was created, @command{tar} will
9008 print a message about a non-standard blocking factor, and then operate
9009 normally. On some tape devices, however, @command{tar} cannot figure
9010 out the record size itself. On most of those, you can specify a
9011 blocking factor (with @option{--blocking-factor}) larger than the
9012 actual blocking factor, and then use the @option{--read-full-records}
9013 (@option{-B}) option. (If you specify a blocking factor with
9014 @option{--blocking-factor} and don't use the
9015 @option{--read-full-records} option, then @command{tar} will not
9016 attempt to figure out the recording size itself.) On some devices,
9017 you must always specify the record size exactly with
9018 @option{--blocking-factor} when reading, because @command{tar} cannot
9019 figure it out. In any case, use @option{--list} (@option{-t}) before
9020 doing any extractions to see whether @command{tar} is reading the archive
9021 correctly.
9022
9023 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9024 putting them into records is to put a whole number of them (one or
9025 more) into each record. @command{tar} records are all the same size;
9026 at the end of the file there's a block containing all zeros, which
9027 is how you tell that the remainder of the last record(s) are garbage.
9028
9029 In a standard @command{tar} file (no options), the block size is 512
9030 and the record size is 10240, for a blocking factor of 20. What the
9031 @option{--blocking-factor} option does is sets the blocking factor,
9032 changing the record size while leaving the block size at 512 bytes.
9033 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9034 most tape drives these days prefer much bigger records in order to
9035 stream and not waste tape. When writing tapes for myself, some tend
9036 to use a factor of the order of 2048, say, giving a record size of
9037 around one megabyte.
9038
9039 If you use a blocking factor larger than 20, older @command{tar}
9040 programs might not be able to read the archive, so we recommend this
9041 as a limit to use in practice. @GNUTAR{}, however,
9042 will support arbitrarily large record sizes, limited only by the
9043 amount of virtual memory or the physical characteristics of the tape
9044 device.
9045
9046 @menu
9047 * Format Variations:: Format Variations
9048 * Blocking Factor:: The Blocking Factor of an Archive
9049 @end menu
9050
9051 @node Format Variations
9052 @subsection Format Variations
9053 @cindex Format Parameters
9054 @cindex Format Options
9055 @cindex Options, archive format specifying
9056 @cindex Options, format specifying
9057 @UNREVISED
9058
9059 Format parameters specify how an archive is written on the archive
9060 media. The best choice of format parameters will vary depending on
9061 the type and number of files being archived, and on the media used to
9062 store the archive.
9063
9064 To specify format parameters when accessing or creating an archive,
9065 you can use the options described in the following sections.
9066 If you do not specify any format parameters, @command{tar} uses
9067 default parameters. You cannot modify a compressed archive.
9068 If you create an archive with the @option{--blocking-factor} option
9069 specified (@pxref{Blocking Factor}), you must specify that
9070 blocking-factor when operating on the archive. @xref{Formats}, for other
9071 examples of format parameter considerations.
9072
9073 @node Blocking Factor
9074 @subsection The Blocking Factor of an Archive
9075 @cindex Blocking Factor
9076 @cindex Record Size
9077 @cindex Number of blocks per record
9078 @cindex Number of bytes per record
9079 @cindex Bytes per record
9080 @cindex Blocks per record
9081 @UNREVISED
9082
9083 @opindex blocking-factor
9084 The data in an archive is grouped into blocks, which are 512 bytes.
9085 Blocks are read and written in whole number multiples called
9086 @dfn{records}. The number of blocks in a record (i.e. the size of a
9087 record in units of 512 bytes) is called the @dfn{blocking factor}.
9088 The @option{--blocking-factor=@var{512-size}} (@option{-b
9089 @var{512-size}}) option specifies the blocking factor of an archive.
9090 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9091 can be specified at installation. To find out the blocking factor of
9092 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9093 This may not work on some devices.
9094
9095 Records are separated by gaps, which waste space on the archive media.
9096 If you are archiving on magnetic tape, using a larger blocking factor
9097 (and therefore larger records) provides faster throughput and allows you
9098 to fit more data on a tape (because there are fewer gaps). If you are
9099 archiving on cartridge, a very large blocking factor (say 126 or more)
9100 greatly increases performance. A smaller blocking factor, on the other
9101 hand, may be useful when archiving small files, to avoid archiving lots
9102 of nulls as @command{tar} fills out the archive to the end of the record.
9103 In general, the ideal record size depends on the size of the
9104 inter-record gaps on the tape you are using, and the average size of the
9105 files you are archiving. @xref{create}, for information on
9106 writing archives.
9107
9108 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9109
9110 Archives with blocking factors larger than 20 cannot be read
9111 by very old versions of @command{tar}, or by some newer versions
9112 of @command{tar} running on old machines with small address spaces.
9113 With @GNUTAR{}, the blocking factor of an archive is limited
9114 only by the maximum record size of the device containing the archive,
9115 or by the amount of available virtual memory.
9116
9117 Also, on some systems, not using adequate blocking factors, as sometimes
9118 imposed by the device drivers, may yield unexpected diagnostics. For
9119 example, this has been reported:
9120
9121 @smallexample
9122 Cannot write to /dev/dlt: Invalid argument
9123 @end smallexample
9124
9125 @noindent
9126 In such cases, it sometimes happen that the @command{tar} bundled by
9127 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9128 requires an explicit specification for the block size,
9129 which it cannot guess. This yields some people to consider
9130 @GNUTAR{} is misbehaving, because by comparison,
9131 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9132 for example, might resolve the problem.
9133
9134 If you use a non-default blocking factor when you create an archive, you
9135 must specify the same blocking factor when you modify that archive. Some
9136 archive devices will also require you to specify the blocking factor when
9137 reading that archive, however this is not typically the case. Usually, you
9138 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9139 reports a non-default record size and then lists the archive members as
9140 it would normally. To extract files from an archive with a non-standard
9141 blocking factor (particularly if you're not sure what the blocking factor
9142 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9143 specifying a blocking factor larger then the blocking factor of the archive
9144 (i.e. @samp{tar --extract --read-full-records --blocking-factor=300}.
9145 @xref{list}, for more information on the @option{--list} (@option{-t})
9146 operation. @xref{Reading}, for a more detailed explanation of that option.
9147
9148 @table @option
9149 @item --blocking-factor=@var{number}
9150 @itemx -b @var{number}
9151 Specifies the blocking factor of an archive. Can be used with any
9152 operation, but is usually not necessary with @option{--list} (@option{-t}).
9153 @end table
9154
9155 Device blocking
9156
9157 @table @option
9158 @item -b @var{blocks}
9159 @itemx --blocking-factor=@var{blocks}
9160 Set record size to @math{@var{blocks} * 512} bytes.
9161
9162 This option is used to specify a @dfn{blocking factor} for the archive.
9163 When reading or writing the archive, @command{tar}, will do reads and writes
9164 of the archive in records of @math{@var{block}*512} bytes. This is true
9165 even when the archive is compressed. Some devices requires that all
9166 write operations be a multiple of a certain size, and so, @command{tar}
9167 pads the archive out to the next record boundary.
9168
9169 The default blocking factor is set when @command{tar} is compiled, and is
9170 typically 20. Blocking factors larger than 20 cannot be read by very
9171 old versions of @command{tar}, or by some newer versions of @command{tar}
9172 running on old machines with small address spaces.
9173
9174 With a magnetic tape, larger records give faster throughput and fit
9175 more data on a tape (because there are fewer inter-record gaps).
9176 If the archive is in a disk file or a pipe, you may want to specify
9177 a smaller blocking factor, since a large one will result in a large
9178 number of null bytes at the end of the archive.
9179
9180 When writing cartridge or other streaming tapes, a much larger
9181 blocking factor (say 126 or more) will greatly increase performance.
9182 However, you must specify the same blocking factor when reading or
9183 updating the archive.
9184
9185 Apparently, Exabyte drives have a physical block size of 8K bytes.
9186 If we choose our blocksize as a multiple of 8k bytes, then the problem
9187 seems to disappear. Id est, we are using block size of 112 right
9188 now, and we haven't had the problem since we switched@dots{}
9189
9190 With @GNUTAR{} the blocking factor is limited only
9191 by the maximum record size of the device containing the archive, or by
9192 the amount of available virtual memory.
9193
9194 However, deblocking or reblocking is virtually avoided in a special
9195 case which often occurs in practice, but which requires all the
9196 following conditions to be simultaneously true:
9197 @itemize @bullet
9198 @item
9199 the archive is subject to a compression option,
9200 @item
9201 the archive is not handled through standard input or output, nor
9202 redirected nor piped,
9203 @item
9204 the archive is directly handled to a local disk, instead of any special
9205 device,
9206 @item
9207 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9208 invocation.
9209 @end itemize
9210
9211 If the output goes directly to a local disk, and not through
9212 stdout, then the last write is not extended to a full record size.
9213 Otherwise, reblocking occurs. Here are a few other remarks on this
9214 topic:
9215
9216 @itemize @bullet
9217
9218 @item
9219 @command{gzip} will complain about trailing garbage if asked to
9220 uncompress a compressed archive on tape, there is an option to turn
9221 the message off, but it breaks the regularity of simply having to use
9222 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9223 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9224 Gailly, by sending a copy of this message to him.
9225
9226 @item
9227 @command{compress} does not show this problem, but as Jean-loup pointed
9228 out to Michael, @samp{compress -d} silently adds garbage after
9229 the result of decompression, which tar ignores because it already
9230 recognized its end-of-file indicator. So this bug may be safely
9231 ignored.
9232
9233 @item
9234 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9235 but will still return an exit status of 2 which tar reports in turn.
9236 @command{tar} might ignore the exit status returned, but I hate doing
9237 that, as it weakens the protection @command{tar} offers users against
9238 other possible problems at decompression time. If @command{gzip} was
9239 silently skipping trailing zeros @emph{and} also avoiding setting the
9240 exit status in this innocuous case, that would solve this situation.
9241
9242 @item
9243 @command{tar} should become more solid at not stopping to read a pipe at
9244 the first null block encountered. This inelegantly breaks the pipe.
9245 @command{tar} should rather drain the pipe out before exiting itself.
9246 @end itemize
9247
9248 @xopindex{ignore-zeros, short description}
9249 @item -i
9250 @itemx --ignore-zeros
9251 Ignore blocks of zeros in archive (means EOF).
9252
9253 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9254 of zeros in the archive. Normally a block of zeros indicates the
9255 end of the archive, but when reading a damaged archive, or one which
9256 was created by concatenating several archives together, this option
9257 allows @command{tar} to read the entire archive. This option is not on
9258 by default because many versions of @command{tar} write garbage after
9259 the zeroed blocks.
9260
9261 Note that this option causes @command{tar} to read to the end of the
9262 archive file, which may sometimes avoid problems when multiple files
9263 are stored on a single physical tape.
9264
9265 @xopindex{read-full-records, short description}
9266 @item -B
9267 @itemx --read-full-records
9268 Reblock as we read (for reading 4.2BSD pipes).
9269
9270 If @option{--read-full-records} is used, @command{tar}
9271 will not panic if an attempt to read a record from the archive does
9272 not return a full record. Instead, @command{tar} will keep reading
9273 until it has obtained a full
9274 record.
9275
9276 This option is turned on by default when @command{tar} is reading
9277 an archive from standard input, or from a remote machine. This is
9278 because on BSD Unix systems, a read of a pipe will return however
9279 much happens to be in the pipe, even if it is less than @command{tar}
9280 requested. If this option was not used, @command{tar} would fail as
9281 soon as it read an incomplete record from the pipe.
9282
9283 This option is also useful with the commands for updating an archive.
9284
9285 @end table
9286
9287 Tape blocking
9288
9289 @FIXME{Appropriate options should be moved here from elsewhere.}
9290
9291 @cindex blocking factor
9292 @cindex tape blocking
9293
9294 When handling various tapes or cartridges, you have to take care of
9295 selecting a proper blocking, that is, the number of disk blocks you
9296 put together as a single tape block on the tape, without intervening
9297 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9298 with no information on it, used for decelerating the tape to a
9299 full stop, and for later regaining the reading or writing speed.
9300 When the tape driver starts reading a record, the record has to
9301 be read whole without stopping, as a tape gap is needed to stop the
9302 tape motion without loosing information.
9303
9304 @cindex Exabyte blocking
9305 @cindex DAT blocking
9306 Using higher blocking (putting more disk blocks per tape block) will use
9307 the tape more efficiently as there will be less tape gaps. But reading
9308 such tapes may be more difficult for the system, as more memory will be
9309 required to receive at once the whole record. Further, if there is a
9310 reading error on a huge record, this is less likely that the system will
9311 succeed in recovering the information. So, blocking should not be too
9312 low, nor it should be too high. @command{tar} uses by default a blocking of
9313 20 for historical reasons, and it does not really matter when reading or
9314 writing to disk. Current tape technology would easily accommodate higher
9315 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9316 We were told that for some DLT drives, the blocking should be a multiple
9317 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9318 Other manufacturers may use different recommendations for the same tapes.
9319 This might also depends of the buffering techniques used inside modern
9320 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9321 Others request blocking to be some exponent of two.
9322
9323 So, there is no fixed rule for blocking. But blocking at read time
9324 should ideally be the same as blocking used at write time. At one place
9325 I know, with a wide variety of equipment, they found it best to use a
9326 blocking of 32 to guarantee that their tapes are fully interchangeable.
9327
9328 I was also told that, for recycled tapes, prior erasure (by the same
9329 drive unit that will be used to create the archives) sometimes lowers
9330 the error rates observed at rewriting time.
9331
9332 I might also use @option{--number-blocks} instead of
9333 @option{--block-number}, so @option{--block} will then expand to
9334 @option{--blocking-factor} unambiguously.
9335
9336 @node Many
9337 @section Many Archives on One Tape
9338
9339 @FIXME{Appropriate options should be moved here from elsewhere.}
9340
9341 @findex ntape @r{device}
9342 Most tape devices have two entries in the @file{/dev} directory, or
9343 entries that come in pairs, which differ only in the minor number for
9344 this device. Let's take for example @file{/dev/tape}, which often
9345 points to the only or usual tape device of a given system. There might
9346 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9347 name is the @emph{rewinding} version of the device, while the name
9348 having @samp{nr} in it is the @emph{no rewinding} version of the same
9349 device.
9350
9351 A rewinding tape device will bring back the tape to its beginning point
9352 automatically when this device is opened or closed. Since @command{tar}
9353 opens the archive file before using it and closes it afterwards, this
9354 means that a simple:
9355
9356 @smallexample
9357 $ @kbd{tar cf /dev/tape @var{directory}}
9358 @end smallexample
9359
9360 @noindent
9361 will reposition the tape to its beginning both prior and after saving
9362 @var{directory} contents to it, thus erasing prior tape contents and
9363 making it so that any subsequent write operation will destroy what has
9364 just been saved.
9365
9366 @cindex tape positioning
9367 So, a rewinding device is normally meant to hold one and only one file.
9368 If you want to put more than one @command{tar} archive on a given tape, you
9369 will need to avoid using the rewinding version of the tape device. You
9370 will also have to pay special attention to tape positioning. Errors in
9371 positioning may overwrite the valuable data already on your tape. Many
9372 people, burnt by past experiences, will only use rewinding devices and
9373 limit themselves to one file per tape, precisely to avoid the risk of
9374 such errors. Be fully aware that writing at the wrong position on a
9375 tape loses all information past this point and most probably until the
9376 end of the tape, and this destroyed information @emph{cannot} be
9377 recovered.
9378
9379 To save @var{directory-1} as a first archive at the beginning of a
9380 tape, and leave that tape ready for a second archive, you should use:
9381
9382 @smallexample
9383 $ @kbd{mt -f /dev/nrtape rewind}
9384 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9385 @end smallexample
9386
9387 @cindex tape marks
9388 @dfn{Tape marks} are special magnetic patterns written on the tape
9389 media, which are later recognizable by the reading hardware. These
9390 marks are used after each file, when there are many on a single tape.
9391 An empty file (that is to say, two tape marks in a row) signal the
9392 logical end of the tape, after which no file exist. Usually,
9393 non-rewinding tape device drivers will react to the close request issued
9394 by @command{tar} by first writing two tape marks after your archive, and by
9395 backspacing over one of these. So, if you remove the tape at that time
9396 from the tape drive, it is properly terminated. But if you write
9397 another file at the current position, the second tape mark will be
9398 erased by the new information, leaving only one tape mark between files.
9399
9400 So, you may now save @var{directory-2} as a second archive after the
9401 first on the same tape by issuing the command:
9402
9403 @smallexample
9404 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9405 @end smallexample
9406
9407 @noindent
9408 and so on for all the archives you want to put on the same tape.
9409
9410 Another usual case is that you do not write all the archives the same
9411 day, and you need to remove and store the tape between two archive
9412 sessions. In general, you must remember how many files are already
9413 saved on your tape. Suppose your tape already has 16 files on it, and
9414 that you are ready to write the 17th. You have to take care of skipping
9415 the first 16 tape marks before saving @var{directory-17}, say, by using
9416 these commands:
9417
9418 @smallexample
9419 $ @kbd{mt -f /dev/nrtape rewind}
9420 $ @kbd{mt -f /dev/nrtape fsf 16}
9421 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9422 @end smallexample
9423
9424 In all the previous examples, we put aside blocking considerations, but
9425 you should do the proper things for that as well. @xref{Blocking}.
9426
9427 @menu
9428 * Tape Positioning:: Tape Positions and Tape Marks
9429 * mt:: The @command{mt} Utility
9430 @end menu
9431
9432 @node Tape Positioning
9433 @subsection Tape Positions and Tape Marks
9434 @UNREVISED
9435
9436 Just as archives can store more than one file from the file system,
9437 tapes can store more than one archive file. To keep track of where
9438 archive files (or any other type of file stored on tape) begin and
9439 end, tape archive devices write magnetic @dfn{tape marks} on the
9440 archive media. Tape drives write one tape mark between files,
9441 two at the end of all the file entries.
9442
9443 If you think of data as a series of records "rrrr"'s, and tape marks as
9444 "*"'s, a tape might look like the following:
9445
9446 @smallexample
9447 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9448 @end smallexample
9449
9450 Tape devices read and write tapes using a read/write @dfn{tape
9451 head}---a physical part of the device which can only access one
9452 point on the tape at a time. When you use @command{tar} to read or
9453 write archive data from a tape device, the device will begin reading
9454 or writing from wherever on the tape the tape head happens to be,
9455 regardless of which archive or what part of the archive the tape
9456 head is on. Before writing an archive, you should make sure that no
9457 data on the tape will be overwritten (unless it is no longer needed).
9458 Before reading an archive, you should make sure the tape head is at
9459 the beginning of the archive you want to read. You can do it manually
9460 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9461 that automatically (@pxref{Scripted Restoration}).
9462
9463 If you want to add new archive file entries to a tape, you should
9464 advance the tape to the end of the existing file entries, backspace
9465 over the last tape mark, and write the new archive file. If you were
9466 to add two archives to the example above, the tape might look like the
9467 following:
9468
9469 @smallexample
9470 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9471 @end smallexample
9472
9473 @node mt
9474 @subsection The @command{mt} Utility
9475 @UNREVISED
9476
9477 @FIXME{Is it true that this only works on non-block devices?
9478 should explain the difference, (fixed or variable).}
9479 @xref{Blocking Factor}.
9480
9481 You can use the @command{mt} utility to advance or rewind a tape past a
9482 specified number of archive files on the tape. This will allow you
9483 to move to the beginning of an archive before extracting or reading
9484 it, or to the end of all the archives before writing a new one.
9485 @FIXME{Why isn't there an "advance 'til you find two tape marks
9486 together"?}
9487
9488 The syntax of the @command{mt} command is:
9489
9490 @smallexample
9491 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9492 @end smallexample
9493
9494 where @var{tapename} is the name of the tape device, @var{number} is
9495 the number of times an operation is performed (with a default of one),
9496 and @var{operation} is one of the following:
9497
9498 @FIXME{is there any use for record operations?}
9499
9500 @table @option
9501 @item eof
9502 @itemx weof
9503 Writes @var{number} tape marks at the current position on the tape.
9504
9505 @item fsf
9506 Moves tape position forward @var{number} files.
9507
9508 @item bsf
9509 Moves tape position back @var{number} files.
9510
9511 @item rewind
9512 Rewinds the tape. (Ignores @var{number}).
9513
9514 @item offline
9515 @itemx rewoff1
9516 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9517
9518 @item status
9519 Prints status information about the tape unit.
9520
9521 @end table
9522
9523 @FIXME{Is there a better way to frob the spacing on the list?}
9524
9525 If you don't specify a @var{tapename}, @command{mt} uses the environment
9526 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9527 the default device specified in your @file{sys/mtio.h} file
9528 (@code{DEFTAPE} variable). If this is not defined, the program will
9529 display a descriptive error message and exit with code 1.
9530
9531 @command{mt} returns a 0 exit status when the operation(s) were
9532 successful, 1 if the command was unrecognized, and 2 if an operation
9533 failed.
9534
9535 @node Using Multiple Tapes
9536 @section Using Multiple Tapes
9537
9538 Often you might want to write a large archive, one larger than will fit
9539 on the actual tape you are using. In such a case, you can run multiple
9540 @command{tar} commands, but this can be inconvenient, particularly if you
9541 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9542 Therefore, @command{tar} provides a special mode for creating
9543 multi-volume archives.
9544
9545 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9546 on several media volumes of fixed size. Although in this section we will
9547 often call @samp{volume} a @dfn{tape}, there is absolutely no
9548 requirement for multi-volume archives to be stored on tapes. Instead,
9549 they can use whatever media type the user finds convenient, they can
9550 even be located on files.
9551
9552 When creating a multi-volume arvhive, @GNUTAR{} continues to fill
9553 current volume until it runs out of space, then it switches to
9554 next volume (usually the operator is queried to replace the tape on
9555 this point), and continues working on the new volume. This operation
9556 continues untill all requested files are dumped. If @GNUTAR{} detects
9557 end of media while dumping a file, such a file is archived in split
9558 form. Some very big files can even be split across several volumes.
9559
9560 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9561 without any special options. Consequently any file member residing
9562 entirely on one volume can be extracted or otherwise operated upon
9563 without needing the other volume. Sure enough, to extract a split
9564 member you would need all volumes its parts reside on.
9565
9566 Multi-volume archives suffer from several limitations. In particular,
9567 they cannot be compressed.
9568
9569 @GNUTAR{} is able to create multi-volume archives of two formats
9570 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9571
9572 @menu
9573 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9574 * Tape Files:: Tape Files
9575 * Tarcat:: Concatenate Volumes into a Single Archive
9576
9577 @end menu
9578
9579 @node Multi-Volume Archives
9580 @subsection Archives Longer than One Tape or Disk
9581 @cindex Multi-volume archives
9582
9583 @opindex multi-volume
9584 To create an archive that is larger than will fit on a single unit of
9585 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9586 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9587 archive can be manipulated like any other archive (provided the
9588 @option{--multi-volume} option is specified), but is stored on more
9589 than one tape or disk.
9590
9591 When you specify @option{--multi-volume}, @command{tar} does not report an
9592 error when it comes to the end of an archive volume (when reading), or
9593 the end of the media (when writing). Instead, it prompts you to load
9594 a new storage volume. If the archive is on a magnetic tape, you
9595 should change tapes when you see the prompt; if the archive is on a
9596 floppy disk, you should change disks; etc.
9597
9598 @table @option
9599 @item --multi-volume
9600 @itemx -M
9601 Creates a multi-volume archive, when used in conjunction with
9602 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9603 archive, specify @option{--multi-volume} in conjunction with that
9604 operation.
9605 For example:
9606
9607 @smallexample
9608 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9609 @end smallexample
9610 @end table
9611
9612 The method @command{tar} uses to detect end of tape is not perfect, and
9613 fails on some operating systems or on some devices. If @command{tar}
9614 cannot detect the end of the tape itself, you can use
9615 @option{--tape-length} option to inform it about the capacity of the
9616 tape:
9617
9618 @anchor{tape-length}
9619 @table @option
9620 @opindex tape-length
9621 @item --tape-length=@var{size}
9622 @itemx -L @var{size}
9623 Set maximum length of a volume. The @var{size} argument should then
9624 be the usable size of the tape in units of 1024 bytes. This option
9625 selects @option{--multi-volume} automatically. For example:
9626
9627 @smallexample
9628 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9629 @end smallexample
9630 @end table
9631
9632 @anchor{change volume prompt}
9633 When @GNUTAR{} comes to the end of a storage media, it asks you to
9634 change the volume. The built-in prompt for POSIX locale
9635 is@footnote{If you run @GNUTAR{} under a different locale, the
9636 translation to the locale's language will be used.}:
9637
9638 @smallexample
9639 Prepare volume #@var{n} for `@var{archive}' and hit return:
9640 @end smallexample
9641
9642 @noindent
9643 where @var{n} is the ordinal number of the volume to be created and
9644 @var{archive} is archive file or device name.
9645
9646 When prompting for a new tape, @command{tar} accepts any of the following
9647 responses:
9648
9649 @table @kbd
9650 @item ?
9651 Request @command{tar} to explain possible responses
9652 @item q
9653 Request @command{tar} to exit immediately.
9654 @item n @var{file-name}
9655 Request @command{tar} to write the next volume on the file @var{file-name}.
9656 @item !
9657 Request @command{tar} to run a subshell. This option can be disabled
9658 by giving @option{--restrict} command line option to
9659 @command{tar}@footnote{@xref{--restrict}, for more information about
9660 this option}.
9661 @item y
9662 Request @command{tar} to begin writing the next volume.
9663 @end table
9664
9665 (You should only type @samp{y} after you have changed the tape;
9666 otherwise @command{tar} will write over the volume it just finished.)
9667
9668 @cindex Volume number file
9669 @cindex volno file
9670 @anchor{volno-file}
9671 @opindex volno-file
9672 The volume number used by @command{tar} in its tape-changing prompt
9673 can be changed; if you give the
9674 @option{--volno-file=@var{file-of-number}} option, then
9675 @var{file-of-number} should be an unexisting file to be created, or
9676 else, a file already containing a decimal number. That number will be
9677 used as the volume number of the first volume written. When
9678 @command{tar} is finished, it will rewrite the file with the
9679 now-current volume number. (This does not change the volume number
9680 written on a tape label, as per @ref{label}, it @emph{only} affects
9681 the number used in the prompt.)
9682
9683 @cindex End-of-archive info script
9684 @cindex Info script
9685 @anchor{info-script}
9686 @opindex info-script
9687 @opindex new-volume-script
9688 If you want more elaborate behavior than this, you can write a special
9689 @dfn{new volume script}, that will be responsible for changing the
9690 volume, and instruct @command{tar} to use it instead of its normal
9691 prompting procedure:
9692
9693 @table @option
9694 @item --info-script=@var{script-name}
9695 @itemx --new-volume-script=@var{script-name}
9696 @itemx -F @var{script-name}
9697 Specify the full name of the volume script to use. The script can be
9698 used to eject cassettes, or to broadcast messages such as
9699 @samp{Someone please come change my tape} when performing unattended
9700 backups.
9701 @end table
9702
9703 The @var{script-name} is executed without any command line
9704 arguments. It inherits @command{tar}'s shell environment.
9705 Additional data is passed to it via the following
9706 environment variables:
9707
9708 @table @env
9709 @vrindex TAR_VERSION, info script environment variable
9710 @item TAR_VERSION
9711 @GNUTAR{} version number.
9712
9713 @vrindex TAR_ARCHIVE, info script environment variable
9714 @item TAR_ARCHIVE
9715 The name of the archive @command{tar} is processing.
9716
9717 @vrindex TAR_VOLUME, info script environment variable
9718 @item TAR_VOLUME
9719 Ordinal number of the volume @command{tar} is about to start.
9720
9721 @vrindex TAR_SUBCOMMAND, info script environment variable
9722 @item TAR_SUBCOMMAND
9723 Short option describing the operation @command{tar} is executing
9724 @xref{Operations}, for a complete list of subcommand options.
9725
9726 @vrindex TAR_FORMAT, info script environment variable
9727 @item TAR_FORMAT
9728 Format of the archive being processed. @xref{Formats}, for a complete
9729 list of archive format names.
9730 @end table
9731
9732 The volume script can instruct @command{tar} to use new archive name,
9733 by writing in to file descriptor 3 (see below for an example).
9734
9735 If the info script fails, @command{tar} exits; otherwise, it begins
9736 writing the next volume.
9737
9738 If you want @command{tar} to cycle through a series of files or tape
9739 drives, there are three approaches to choose from. First of all, you
9740 can give @command{tar} multiple @option{--file} options. In this case
9741 the specified files will be used, in sequence, as the successive
9742 volumes of the archive. Only when the first one in the sequence needs
9743 to be used again will @command{tar} prompt for a tape change (or run
9744 the info script). For example, suppose someone has two tape drives on
9745 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
9746 @GNUTAR{} to switch to the second drive when it needs to write the
9747 second tape, and then back to the first tape, etc., just do either of:
9748
9749 @smallexample
9750 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
9751 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
9752 @end smallexample
9753
9754 The second method is to use the @samp{n} response to the tape-change
9755 prompt.
9756
9757 Finally, the most flexible approach is to use a volume script, that
9758 writes new archive name to the file descriptor #3. For example, the
9759 following volume script will create a series of archive files, named
9760 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
9761 archive being created (as given by @option{--file} option) and
9762 @var{vol} is the ordinal number of the archive being created:
9763
9764 @smallexample
9765 @group
9766 #! /bin/sh
9767 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
9768
9769 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
9770 case $TAR_SUBCOMMAND in
9771 -c) ;;
9772 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
9773 ;;
9774 *) exit 1
9775 esac
9776
9777 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
9778 @end group
9779 @end smallexample
9780
9781 The same script cant be used while listing, comparing or extracting
9782 from the created archive. For example:
9783
9784 @smallexample
9785 @group
9786 # @r{Create a multi-volume archive:}
9787 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
9788 # @r{Extract from the created archive:}
9789 $ @kbd{tar -x -f archive.tar -F new-volume .}
9790 @end group
9791 @end smallexample
9792
9793 @noindent
9794 Notice, that the first command had to use @option{-L} option, since
9795 otherwise @GNUTAR{} will end up writing everything to file
9796 @file{archive.tar}.
9797
9798 You can read each individual volume of a multi-volume archive as if it
9799 were an archive by itself. For example, to list the contents of one
9800 volume, use @option{--list}, without @option{--multi-volume} specified.
9801 To extract an archive member from one volume (assuming it is described
9802 that volume), use @option{--extract}, again without
9803 @option{--multi-volume}.
9804
9805 If an archive member is split across volumes (i.e. its entry begins on
9806 one volume of the media and ends on another), you need to specify
9807 @option{--multi-volume} to extract it successfully. In this case, you
9808 should load the volume where the archive member starts, and use
9809 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
9810 volumes as it needs them. @xref{extracting archives}, for more
9811 information about extracting archives.
9812
9813 Multi-volume archives can be modified like any other archive. To add
9814 files to a multi-volume archive, you need to only mount the last
9815 volume of the archive media (and new volumes, if needed). For all
9816 other operations, you need to use the entire archive.
9817
9818 If a multi-volume archive was labeled using
9819 @option{--label=@var{archive-label}} (@pxref{label}) when it was
9820 created, @command{tar} will not automatically label volumes which are
9821 added later. To label subsequent volumes, specify
9822 @option{--label=@var{archive-label}} again in conjunction with the
9823 @option{--append}, @option{--update} or @option{--concatenate} operation.
9824
9825 @FIXME{This is no longer true: Multivolume archives in @samp{POSIX}
9826 format can be extracted using any posix-compliant tar
9827 implementation. The split members can then be recreated from parts
9828 using a simple shell script. Provide more information about it:}
9829 Beware that there is @emph{no} real standard about the proper way, for
9830 a @command{tar} archive, to span volume boundaries. If you have a
9831 multi-volume created by some vendor's @command{tar}, there is almost
9832 no chance you could read all the volumes with @GNUTAR{}.
9833 The converse is also true: you may not expect
9834 multi-volume archives created by @GNUTAR{} to be
9835 fully recovered by vendor's @command{tar}. Since there is little
9836 chance that, in mixed system configurations, some vendor's
9837 @command{tar} will work on another vendor's machine, and there is a
9838 great chance that @GNUTAR{} will work on most of
9839 them, your best bet is to install @GNUTAR{} on all
9840 machines between which you know exchange of files is possible.
9841
9842 @node Tape Files
9843 @subsection Tape Files
9844 @UNREVISED
9845
9846 To give the archive a name which will be recorded in it, use the
9847 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
9848 option. This will write a special block identifying
9849 @var{volume-label} as the name of the archive to the front of the
9850 archive which will be displayed when the archive is listed with
9851 @option{--list}. If you are creating a multi-volume archive with
9852 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
9853 volume label will have @samp{Volume @var{nnn}} appended to the name
9854 you give, where @var{nnn} is the number of the volume of the archive.
9855 (If you use the @option{--label=@var{volume-label}}) option when
9856 reading an archive, it checks to make sure the label on the tape
9857 matches the one you give. @xref{label}.
9858
9859 When @command{tar} writes an archive to tape, it creates a single
9860 tape file. If multiple archives are written to the same tape, one
9861 after the other, they each get written as separate tape files. When
9862 extracting, it is necessary to position the tape at the right place
9863 before running @command{tar}. To do this, use the @command{mt} command.
9864 For more information on the @command{mt} command and on the organization
9865 of tapes into a sequence of tape files, see @ref{mt}.
9866
9867 People seem to often do:
9868
9869 @smallexample
9870 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
9871 @end smallexample
9872
9873 or such, for pushing a common date in all volumes or an archive set.
9874
9875 @node Tarcat
9876 @subsection Concatenate Volumes into a Single Archive
9877
9878 @pindex tarcat
9879 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
9880 archive to a single @command{tar} archive. Simply concatenating all
9881 volumes into one will not work, since each volume carries an additional
9882 information at the beginning. @GNUTAR{} is shipped with the shell
9883 script @command{tarcat} designed for this purpose.
9884
9885 The script takes a list of files comprising a multi-volume archive
9886 and creates the resulting archive at the standard output. For example:
9887
9888 @smallexample
9889 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
9890 @end smallexample
9891
9892 The script implements a simple heuristics to determine the format of
9893 the first volume file and to decide how to process the rest of the
9894 files. However, it makes no attempt to verify whether the files are
9895 given in order or even if they are valid @command{tar} archives.
9896 It uses @command{dd} and does not filter its standard error, so you
9897 will usually see lots of spurious messages.
9898
9899 @FIXME{The script is not installed. Should we install it?}
9900
9901 @node label
9902 @section Including a Label in the Archive
9903 @cindex Labeling an archive
9904 @cindex Labels on the archive media
9905 @cindex Labeling multi-volume archives
9906 @UNREVISED
9907
9908 @opindex label
9909 To avoid problems caused by misplaced paper labels on the archive
9910 media, you can include a @dfn{label} entry---an archive member which
9911 contains the name of the archive---in the archive itself. Use the
9912 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9913 option in conjunction with the @option{--create} operation to include
9914 a label entry in the archive as it is being created.
9915
9916 @table @option
9917 @item --label=@var{archive-label}
9918 @itemx -V @var{archive-label}
9919 Includes an @dfn{archive-label} at the beginning of the archive when
9920 the archive is being created, when used in conjunction with the
9921 @option{--create} operation. Checks to make sure the archive label
9922 matches the one specified (when used in conjunction with any other
9923 operation.
9924 @end table
9925
9926 If you create an archive using both
9927 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
9928 and @option{--multi-volume} (@option{-M}), each volume of the archive
9929 will have an archive label of the form @samp{@var{archive-label}
9930 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
9931 next, and so on. @xref{Using Multiple Tapes}, for information on
9932 creating multiple volume archives.
9933
9934 @cindex Volume label, listing
9935 @cindex Listing volume label
9936 The volume label will be displayed by @option{--list} along with
9937 the file contents. If verbose display is requested, it will also be
9938 explicitely marked as in the example below:
9939
9940 @smallexample
9941 @group
9942 $ @kbd{tar --verbose --list --file=iamanarchive}
9943 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
9944 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
9945 @end group
9946 @end smallexample
9947
9948 @opindex test-label
9949 @anchor{--test-label option}
9950 However, @option{--list} option will cause listing entire
9951 contents of the archive, which may be undesirable (for example, if the
9952 archive is stored on a tape). You can request checking only the volume
9953 by specifying @option{--test-label} option. This option reads only the
9954 first block of an archive, so it can be used with slow storage
9955 devices. For example:
9956
9957 @smallexample
9958 @group
9959 $ @kbd{tar --test-label --file=iamanarchive}
9960 iamalabel
9961 @end group
9962 @end smallexample
9963
9964 If @option{--test-label} is used with a single command line
9965 argument, @command{tar} compares the volume label with the
9966 argument. It exits with code 0 if the two strings match, and with code
9967 2 otherwise. In this case no output is displayed. For example:
9968
9969 @smallexample
9970 @group
9971 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
9972 @result{} 0
9973 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
9974 @result{} 1
9975 @end group
9976 @end smallexample
9977
9978 If you request any operation, other than @option{--create}, along
9979 with using @option{--label} option, @command{tar} will first check if
9980 the archive label matches the one specified and will refuse to proceed
9981 if it does not. Use this as a safety precaution to avoid accidentally
9982 overwriting existing archives. For example, if you wish to add files
9983 to @file{archive}, presumably labelled with string @samp{My volume},
9984 you will get:
9985
9986 @smallexample
9987 @group
9988 $ @kbd{tar -rf archive --label 'My volume' .}
9989 tar: Archive not labeled to match `My volume'
9990 @end group
9991 @end smallexample
9992
9993 @noindent
9994 in case its label does not match. This will work even if
9995 @file{archive} is not labelled at all.
9996
9997 Similarly, @command{tar} will refuse to list or extract the
9998 archive if its label doesn't match the @var{archive-label}
9999 specified. In those cases, @var{archive-label} argument is interpreted
10000 as a globbing-style pattern which must match the actual magnetic
10001 volume label. @xref{exclude}, for a precise description of how match
10002 is attempted@footnote{Previous versions of @command{tar} used full
10003 regular expression matching, or before that, only exact string
10004 matching, instead of wildcard matchers. We decided for the sake of
10005 simplicity to use a uniform matching device through
10006 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10007 the volume label matcher will also suffix @var{archive-label} by
10008 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10009 up. Since the volume numbering is automatically added in labels at
10010 creation time, it sounded logical to equally help the user taking care
10011 of it when the archive is being read.
10012
10013 The @option{--label} was once called @option{--volume}, but is not
10014 available under that name anymore.
10015
10016 You can also use @option{--label} to get a common information on
10017 all tapes of a series. For having this information different in each
10018 series created through a single script used on a regular basis, just
10019 manage to get some date string as part of the label. For example:
10020
10021 @smallexample
10022 @group
10023 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10024 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10025 --volume="Daily backup for `date +%Y-%m-%d`"}
10026 @end group
10027 @end smallexample
10028
10029 Also note that each label has its own date and time, which corresponds
10030 to when @GNUTAR{} initially attempted to write it,
10031 often soon after the operator launches @command{tar} or types the
10032 carriage return telling that the next tape is ready. Comparing date
10033 labels does give an idea of tape throughput only if the delays for
10034 rewinding tapes and the operator switching them were negligible, which
10035 is usually not the case.
10036
10037 @node verify
10038 @section Verifying Data as It is Stored
10039 @cindex Verifying a write operation
10040 @cindex Double-checking a write operation
10041
10042 @table @option
10043 @item -W
10044 @itemx --verify
10045 @opindex verify, short description
10046 Attempt to verify the archive after writing.
10047 @end table
10048
10049 This option causes @command{tar} to verify the archive after writing it.
10050 Each volume is checked after it is written, and any discrepancies
10051 are recorded on the standard error output.
10052
10053 Verification requires that the archive be on a back-space-able medium.
10054 This means pipes, some cartridge tape drives, and some other devices
10055 cannot be verified.
10056
10057 You can insure the accuracy of an archive by comparing files in the
10058 system with archive members. @command{tar} can compare an archive to the
10059 file system as the archive is being written, to verify a write
10060 operation, or can compare a previously written archive, to insure that
10061 it is up to date.
10062
10063 @xopindex{verify, using with @option{--create}}
10064 @xopindex{create, using with @option{--verify}}
10065 To check for discrepancies in an archive immediately after it is
10066 written, use the @option{--verify} (@option{-W}) option in conjunction with
10067 the @option{--create} operation. When this option is
10068 specified, @command{tar} checks archive members against their counterparts
10069 in the file system, and reports discrepancies on the standard error.
10070
10071 To verify an archive, you must be able to read it from before the end
10072 of the last written entry. This option is useful for detecting data
10073 errors on some tapes. Archives written to pipes, some cartridge tape
10074 drives, and some other devices cannot be verified.
10075
10076 One can explicitly compare an already made archive with the file
10077 system by using the @option{--compare} (@option{--diff}, @option{-d})
10078 option, instead of using the more automatic @option{--verify} option.
10079 @xref{compare}.
10080
10081 Note that these two options have a slightly different intent. The
10082 @option{--compare} option checks how identical are the logical contents of some
10083 archive with what is on your disks, while the @option{--verify} option is
10084 really for checking if the physical contents agree and if the recording
10085 media itself is of dependable quality. So, for the @option{--verify}
10086 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10087 the archive, while it lets the speed optimization undisturbed for the
10088 @option{--compare} option. If you nevertheless use @option{--compare} for
10089 media verification, you may have to defeat the in-memory cache yourself,
10090 maybe by opening and reclosing the door latch of your recording unit,
10091 forcing some doubt in your operating system about the fact this is really
10092 the same volume as the one just written or read.
10093
10094 The @option{--verify} option would not be necessary if drivers were indeed
10095 able to detect dependably all write failures. This sometimes require many
10096 magnetic heads, some able to read after the writes occurred. One would
10097 not say that drivers unable to detect all cases are necessarily flawed,
10098 as long as programming is concerned.
10099
10100 The @option{--verify} (@option{-W}) option will not work in
10101 conjunction with the @option{--multi-volume} (@option{-M}) option or
10102 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10103 and @option{--delete} operations. @xref{Operations}, for more
10104 information on these operations.
10105
10106 Also, since @command{tar} normally strips leading @samp{/} from file
10107 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10108 /tmp/foo.tar /etc} will work as desired only if the working directory is
10109 @file{/}, as @command{tar} uses the archive's relative member names
10110 (e.g., @file{etc/motd}) when verifying the archive.
10111
10112 @node Write Protection
10113 @section Write Protection
10114
10115 Almost all tapes and diskettes, and in a few rare cases, even disks can
10116 be @dfn{write protected}, to protect data on them from being changed.
10117 Once an archive is written, you should write protect the media to prevent
10118 the archive from being accidentally overwritten or deleted. (This will
10119 protect the archive from being changed with a tape or floppy drive---it
10120 will not protect it from magnet fields or other physical hazards).
10121
10122 The write protection device itself is usually an integral part of the
10123 physical media, and can be a two position (write enabled/write
10124 disabled) switch, a notch which can be popped out or covered, a ring
10125 which can be removed from the center of a tape reel, or some other
10126 changeable feature.
10127
10128 @node Changes
10129 @appendix Changes
10130
10131 This appendix lists some important user-visible changes between
10132 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10133 version of this document is available at
10134 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10135 @GNUTAR{} documentation page}.
10136
10137 @table @asis
10138 @item Use of globbing patterns when listing and extracting.
10139
10140 Previous versions of GNU tar assumed shell-style globbing when
10141 extracting from or listing an archive. For example:
10142
10143 @smallexample
10144 $ @kbd{tar xf foo.tar '*.c'}
10145 @end smallexample
10146
10147 would extract all files whose names end in @samp{.c}. This behavior
10148 was not documented and was incompatible with traditional tar
10149 implementations. Therefore, starting from version 1.15.91, GNU tar
10150 no longer uses globbing by default. For example, the above invocation
10151 is now interpreted as a request to extract from the archive the file
10152 named @file{*.c}.
10153
10154 To facilitate transition to the new behavior for those users who got
10155 used to the previous incorrect one, @command{tar} will print a warning
10156 if it finds out that a requested member was not found in the archive
10157 and its name looks like a globbing pattern. For example:
10158
10159 @smallexample
10160 $ @kbd{tar xf foo.tar '*.c'}
10161 tar: Pattern matching characters used in file names. Please,
10162 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10163 tar: suppress this warning.
10164 tar: *.c: Not found in archive
10165 tar: Error exit delayed from previous errors
10166 @end smallexample
10167
10168 To treat member names as globbing patterns, use --wildcards option.
10169 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10170 add this option to your @env{TAR_OPTIONS} variable.
10171
10172 @xref{wildcards}, for the detailed discussion of the use of globbing
10173 patterns by @GNUTAR{}.
10174
10175 @item Use of short option @option{-o}.
10176
10177 Earlier versions of @GNUTAR{} understood @option{-o} command line
10178 option as a synonym for @option{--old-archive}.
10179
10180 @GNUTAR{} starting from version 1.13.90 understands this option as
10181 a synonym for @option{--no-same-owner}. This is compatible with
10182 UNIX98 @command{tar} implementations.
10183
10184 However, to facilitate transition, @option{-o} option retains its
10185 old semantics when it is used with one of archive-creation commands.
10186 Users are encouraged to use @option{--format=oldgnu} instead.
10187
10188 It is especially important, since versions of @acronym{GNU} Automake
10189 up to and including 1.8.4 invoke tar with this option to produce
10190 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10191 of this issue and its implications.
10192
10193 @FIXME{Change the first argument to tar-formats when the new Automake is
10194 out. The proposition to add @anchor{} to the appropriate place of its
10195 docs was accepted by Automake people --Sergey 2006-05-25}.
10196 @xref{Options, tar-v7, Changing Automake's Behavior,
10197 automake, GNU Automake}, for a description on how to use various
10198 archive formats with @command{automake}.
10199
10200 Future versions of @GNUTAR{} will understand @option{-o} only as a
10201 synonym for @option{--no-same-owner}.
10202
10203 @item Use of short option @option{-l}
10204
10205 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10206 synonym for @option{--one-file-system}. Since such usage contradicted
10207 to UNIX98 specification and harmed compatibility with other
10208 implementation, it was declared deprecated in version 1.14. However,
10209 to facilitate transition to its new semantics, it was supported by
10210 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10211 variant of @option{--check-links} was introduced in version 1.15.91.
10212
10213 @item Use of options @option{--portability} and @option{--old-archive}
10214
10215 These options are deprecated. Please use @option{--format=v7} instead.
10216
10217 @item Use of option @option{--posix}
10218
10219 This option is deprecated. Please use @option{--format=posix} instead.
10220 @end table
10221
10222 @node Configuring Help Summary
10223 @appendix Configuring Help Summary
10224
10225 Running @kbd{tar --help} displays the short @command{tar} option
10226 summary (@pxref{help}). This summary is organised by @dfn{groups} of
10227 semantically close options. The options within each group are printed
10228 in the following order: a short option, eventually followed by a list
10229 of corresponding long option names, followed by a short description of
10230 the option. For example, here is an excerpt from the actual @kbd{tar
10231 --help} output:
10232
10233 @verbatim
10234 Main operation mode:
10235
10236 -A, --catenate, --concatenate append tar files to an archive
10237 -c, --create create a new archive
10238 -d, --diff, --compare find differences between archive and
10239 file system
10240 --delete delete from the archive
10241 @end verbatim
10242
10243 @vrindex ARGP_HELP_FMT, environment variable
10244 The exact visual representation of the help output is configurable via
10245 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10246 is a comma-separated list of @dfn{format variable} assignments. There
10247 are two kinds of format variables. An @dfn{offset variable} keeps the
10248 offset of some part of help output text from the leftmost column on
10249 the screen. A @dfn{boolean} variable is a flag that toggles some
10250 output feature on or off. Depending on the type of the corresponding
10251 variable, there are two kinds of assignments:
10252
10253 @table @asis
10254 @item Offset assignment
10255
10256 The assignment to an offset variable has the following syntax:
10257
10258 @smallexample
10259 @var{variable}=@var{value}
10260 @end smallexample
10261
10262 @noindent
10263 where @var{variable} is the variable name, and @var{value} is a
10264 numeric value to be assigned to the variable.
10265
10266 @item Boolean assignment
10267
10268 To assign @code{true} value to a variable, simply put this variable name. To
10269 assign @code{false} value, prefix the variable name with @samp{no-}. For
10270 example:
10271
10272 @smallexample
10273 @group
10274 # Assign @code{true} value:
10275 dup-args
10276 # Assign @code{false} value:
10277 no-dup-args
10278 @end group
10279 @end smallexample
10280 @end table
10281
10282 Following variables are declared:
10283
10284 @deftypevr {Help Output} boolean dup-args
10285 If true, arguments for an option are shown with both short and long
10286 options, even when a given option has both forms, for example:
10287
10288 @smallexample
10289 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10290 @end smallexample
10291
10292 If false, then if an option has both short and long forms, the
10293 argument is only shown with the long one, for example:
10294
10295 @smallexample
10296 -f, --file=ARCHIVE use archive file or device ARCHIVE
10297 @end smallexample
10298
10299 @noindent
10300 and a message indicating that the argument is applicable to both
10301 forms is printed below the options. This message can be disabled
10302 using @code{dup-args-note} (see below).
10303
10304 The default is false.
10305 @end deftypevr
10306
10307 @deftypevr {Help Output} boolean dup-args-note
10308 If this variable is true, which is the default, the following notice
10309 is displayed at the end of the help output:
10310
10311 @quotation
10312 Mandatory or optional arguments to long options are also mandatory or
10313 optional for any corresponding short options.
10314 @end quotation
10315
10316 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10317 variables @code{dup-args} or @code{dup-args-note} should be set.
10318 @end deftypevr
10319
10320 @deftypevr {Help Output} offset short-opt-col
10321 Column in which short options start. Default is 2.
10322
10323 @smallexample
10324 @group
10325 $ @kbd{tar --help|grep ARCHIVE}
10326 -f, --file=ARCHIVE use archive file or device ARCHIVE
10327 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10328 -f, --file=ARCHIVE use archive file or device ARCHIVE
10329 @end group
10330 @end smallexample
10331 @end deftypevr
10332
10333 @deftypevr {Help Output} offset long-opt-col
10334 Column in which long options start. Default is 6. For example:
10335
10336 @smallexample
10337 @group
10338 $ @kbd{tar --help|grep ARCHIVE}
10339 -f, --file=ARCHIVE use archive file or device ARCHIVE
10340 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10341 -f, --file=ARCHIVE use archive file or device ARCHIVE
10342 @end group
10343 @end smallexample
10344 @end deftypevr
10345
10346 @deftypevr {Help Output} offset doc-opt-col
10347 Column in which @dfn{doc options} start. A doc option isn't actually
10348 an option, but rather an arbitrary piece of documentation that is
10349 displayed in much the same manner as the options. For example, in
10350 the description of @option{--format} option:
10351
10352 @smallexample
10353 @group
10354 -H, --format=FORMAT create archive of the given format.
10355
10356 FORMAT is one of the following:
10357
10358 gnu GNU tar 1.13.x format
10359 oldgnu GNU format as per tar <= 1.12
10360 pax POSIX 1003.1-2001 (pax) format
10361 posix same as pax
10362 ustar POSIX 1003.1-1988 (ustar) format
10363 v7 old V7 tar format
10364 @end group
10365 @end smallexample
10366
10367 @noindent
10368 the format names are doc options. Thus, if you set
10369 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10370 will look as follows:
10371
10372 @smallexample
10373 @group
10374 -H, --format=FORMAT create archive of the given format.
10375
10376 FORMAT is one of the following:
10377
10378 gnu GNU tar 1.13.x format
10379 oldgnu GNU format as per tar <= 1.12
10380 pax POSIX 1003.1-2001 (pax) format
10381 posix same as pax
10382 ustar POSIX 1003.1-1988 (ustar) format
10383 v7 old V7 tar format
10384 @end group
10385 @end smallexample
10386 @end deftypevr
10387
10388 @deftypevr {Help Output} offset opt-doc-col
10389 Column in which option description starts. Default is 29.
10390
10391 @smallexample
10392 @group
10393 $ @kbd{tar --help|grep ARCHIVE}
10394 -f, --file=ARCHIVE use archive file or device ARCHIVE
10395 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10396 -f, --file=ARCHIVE use archive file or device ARCHIVE
10397 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10398 -f, --file=ARCHIVE
10399 use archive file or device ARCHIVE
10400 @end group
10401 @end smallexample
10402
10403 @noindent
10404 Notice, that the description starts on a separate line if
10405 @code{opt-doc-col} value is too small.
10406 @end deftypevr
10407
10408 @deftypevr {Help Output} offset header-col
10409 Column in which @dfn{group headers} are printed. A group header is a
10410 descriptive text preceding an option group. For example, in the
10411 following text:
10412
10413 @verbatim
10414 Main operation mode:
10415
10416 -A, --catenate, --concatenate append tar files to
10417 an archive
10418 -c, --create create a new archive
10419 @end verbatim
10420 @noindent
10421 @samp{Main operation mode:} is the group header.
10422
10423 The default value is 1.
10424 @end deftypevr
10425
10426 @deftypevr {Help Output} offset usage-indent
10427 Indentation of wrapped usage lines. Affects @option{--usage}
10428 output. Default is 12.
10429 @end deftypevr
10430
10431 @deftypevr {Help Output} offset rmargin
10432 Right margin of the text output. Used for wrapping.
10433 @end deftypevr
10434
10435 @node Genfile
10436 @appendix Genfile
10437 @include genfile.texi
10438
10439 @node Tar Internals
10440 @appendix Tar Internals
10441 @include intern.texi
10442
10443 @node Free Software Needs Free Documentation
10444 @appendix Free Software Needs Free Documentation
10445 @include freemanuals.texi
10446
10447 @node Copying This Manual
10448 @appendix Copying This Manual
10449
10450 @menu
10451 * GNU Free Documentation License:: License for copying this manual
10452 @end menu
10453
10454 @include fdl.texi
10455
10456 @node Index of Command Line Options
10457 @appendix Index of Command Line Options
10458
10459 This appendix contains an index of all @GNUTAR{} long command line
10460 options. The options are listed without the preceeding double-dash.
10461 For a cross-reference of short command line options, @ref{Short Option Summary}.
10462
10463 @printindex op
10464
10465 @node Index
10466 @appendix Index
10467
10468 @printindex cp
10469
10470 @summarycontents
10471 @contents
10472 @bye
10473
10474 @c Local variables:
10475 @c texinfo-column-for-description: 32
10476 @c End:
This page took 0.472042 seconds and 5 git commands to generate.