]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Document changes to the --transform option.
[chaz/tar] / doc / tar.texi
1 \input texinfo @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename tar.info
4 @include version.texi
5 @settitle GNU tar @value{VERSION}
6 @setchapternewpage odd
7
8 @finalout
9
10 @smallbook
11 @c %**end of header
12
13 @c Maintenance notes:
14 @c 1. Pay attention to @FIXME{}s and @UNREVISED{}s
15 @c 2. Before creating final variant:
16 @c 2.1. Run `make check-options' to make sure all options are properly
17 @c documented;
18 @c 2.2. 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, 2007, 2008 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 have the freedom to
49 copy and modify this GNU manual. Buying copies from the FSF
50 supports it in 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 * Fixing Snapshot Files::
113 * Tar Internals::
114 * Genfile::
115 * Free Software Needs Free Documentation::
116 * Copying This Manual::
117 * Index of Command Line Options::
118 * Index::
119
120 @detailmenu
121 --- The Detailed Node Listing ---
122
123 Introduction
124
125 * Book Contents:: What this Book Contains
126 * Definitions:: Some Definitions
127 * What tar Does:: What @command{tar} Does
128 * Naming tar Archives:: How @command{tar} Archives are Named
129 * Authors:: @GNUTAR{} Authors
130 * Reports:: Reporting bugs or suggestions
131
132 Tutorial Introduction to @command{tar}
133
134 * assumptions::
135 * stylistic conventions::
136 * basic tar options:: Basic @command{tar} Operations and Options
137 * frequent operations::
138 * Two Frequent Options::
139 * create:: How to Create Archives
140 * list:: How to List Archives
141 * extract:: How to Extract Members from an Archive
142 * going further::
143
144 Two Frequently Used Options
145
146 * file tutorial::
147 * verbose tutorial::
148 * help tutorial::
149
150 How to Create Archives
151
152 * prepare for examples::
153 * Creating the archive::
154 * create verbose::
155 * short create::
156 * create dir::
157
158 How to List Archives
159
160 * list dir::
161
162 How to Extract Members from an Archive
163
164 * extracting archives::
165 * extracting files::
166 * extract dir::
167 * extracting untrusted archives::
168 * failing commands::
169
170 Invoking @GNUTAR{}
171
172 * Synopsis::
173 * using tar options::
174 * Styles::
175 * All Options::
176 * help::
177 * defaults::
178 * verbose::
179 * checkpoints::
180 * interactive::
181
182 The Three Option Styles
183
184 * Long Options:: Long Option Style
185 * Short Options:: Short Option Style
186 * Old Options:: Old Option Style
187 * Mixing:: Mixing Option Styles
188
189 All @command{tar} Options
190
191 * Operation Summary::
192 * Option Summary::
193 * Short Option Summary::
194
195 @GNUTAR{} Operations
196
197 * Basic tar::
198 * Advanced tar::
199 * create options::
200 * extract options::
201 * backup::
202 * Applications::
203 * looking ahead::
204
205 Advanced @GNUTAR{} Operations
206
207 * Operations::
208 * append::
209 * update::
210 * concatenate::
211 * delete::
212 * compare::
213
214 How to Add Files to Existing Archives: @option{--append}
215
216 * appending files:: Appending Files to an Archive
217 * multiple::
218
219 Updating an Archive
220
221 * how to update::
222
223 Options Used by @option{--create}
224
225 * override:: Overriding File Metadata.
226 * Ignore Failed Read::
227
228 Options Used by @option{--extract}
229
230 * Reading:: Options to Help Read Archives
231 * Writing:: Changing How @command{tar} Writes Files
232 * Scarce:: Coping with Scarce Resources
233
234 Options to Help Read Archives
235
236 * read full records::
237 * Ignore Zeros::
238
239 Changing How @command{tar} Writes Files
240
241 * Dealing with Old Files::
242 * Overwrite Old Files::
243 * Keep Old Files::
244 * Keep Newer Files::
245 * Unlink First::
246 * Recursive Unlink::
247 * Data Modification Times::
248 * Setting Access Permissions::
249 * Directory Modification Times and Permissions::
250 * Writing to Standard Output::
251 * Writing to an External Program::
252 * remove files::
253
254 Coping with Scarce Resources
255
256 * Starting File::
257 * Same Order::
258
259 Performing Backups and Restoring Files
260
261 * Full Dumps:: Using @command{tar} to Perform Full Dumps
262 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
263 * Backup Levels:: Levels of Backups
264 * Backup Parameters:: Setting Parameters for Backups and Restoration
265 * Scripted Backups:: Using the Backup Scripts
266 * Scripted Restoration:: Using the Restore Script
267
268 Setting Parameters for Backups and Restoration
269
270 * General-Purpose Variables::
271 * Magnetic Tape Control::
272 * User Hooks::
273 * backup-specs example:: An Example Text of @file{Backup-specs}
274
275 Choosing Files and Names for @command{tar}
276
277 * file:: Choosing the Archive's Name
278 * Selecting Archive Members::
279 * files:: Reading Names from a File
280 * exclude:: Excluding Some Files
281 * wildcards:: Wildcards Patterns and Matching
282 * quoting styles:: Ways of Quoting Special Characters in Names
283 * transform:: Modifying File and Member Names
284 * after:: Operating Only on New Files
285 * recurse:: Descending into Directories
286 * one:: Crossing File System Boundaries
287
288 Reading Names from a File
289
290 * nul::
291
292 Excluding Some Files
293
294 * problems with exclude::
295
296 Wildcards Patterns and Matching
297
298 * controlling pattern-matching::
299
300 Crossing File System Boundaries
301
302 * directory:: Changing Directory
303 * absolute:: Absolute File Names
304
305 Date input formats
306
307 * General date syntax:: Common rules.
308 * Calendar date items:: 19 Dec 1994.
309 * Time of day items:: 9:20pm.
310 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
311 * Day of week items:: Monday and others.
312 * Relative items in date strings:: next tuesday, 2 years ago.
313 * Pure numbers in date strings:: 19931219, 1440.
314 * Seconds since the Epoch:: @@1078100502.
315 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
316 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
317
318 Controlling the Archive Format
319
320 * Compression:: Using Less Space through Compression
321 * Attributes:: Handling File Attributes
322 * Portability:: Making @command{tar} Archives More Portable
323 * cpio:: Comparison of @command{tar} and @command{cpio}
324
325 Using Less Space through Compression
326
327 * gzip:: Creating and Reading Compressed Archives
328 * sparse:: Archiving Sparse Files
329
330 Making @command{tar} Archives More Portable
331
332 * Portable Names:: Portable Names
333 * dereference:: Symbolic Links
334 * hard links:: Hard Links
335 * old:: Old V7 Archives
336 * ustar:: Ustar Archives
337 * gnu:: GNU and old GNU format archives.
338 * posix:: @acronym{POSIX} archives
339 * Checksumming:: Checksumming Problems
340 * Large or Negative Values:: Large files, negative time stamps, etc.
341 * Other Tars:: How to Extract GNU-Specific Data Using
342 Other @command{tar} Implementations
343
344 @GNUTAR{} and @acronym{POSIX} @command{tar}
345
346 * PAX keywords:: Controlling Extended Header Keywords.
347
348 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
349
350 * Split Recovery:: Members Split Between Volumes
351 * Sparse Recovery:: Sparse Members
352
353 Tapes and Other Archive Media
354
355 * Device:: Device selection and switching
356 * Remote Tape Server::
357 * Common Problems and Solutions::
358 * Blocking:: Blocking
359 * Many:: Many archives on one tape
360 * Using Multiple Tapes:: Using Multiple Tapes
361 * label:: Including a Label in the Archive
362 * verify::
363 * Write Protection::
364
365 Blocking
366
367 * Format Variations:: Format Variations
368 * Blocking Factor:: The Blocking Factor of an Archive
369
370 Many Archives on One Tape
371
372 * Tape Positioning:: Tape Positions and Tape Marks
373 * mt:: The @command{mt} Utility
374
375 Using Multiple Tapes
376
377 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
378 * Tape Files:: Tape Files
379 * Tarcat:: Concatenate Volumes into a Single Archive
380
381
382 Tar Internals
383
384 * Standard:: Basic Tar Format
385 * Extensions:: @acronym{GNU} Extensions to the Archive Format
386 * Sparse Formats:: Storing Sparse Files
387 * Snapshot Files::
388 * Dumpdir::
389
390 Storing Sparse Files
391
392 * Old GNU Format::
393 * PAX 0:: PAX Format, Versions 0.0 and 0.1
394 * PAX 1:: PAX Format, Version 1.0
395
396 Genfile
397
398 * Generate Mode:: File Generation Mode.
399 * Status Mode:: File Status Mode.
400 * Exec Mode:: Synchronous Execution mode.
401
402 Copying This Manual
403
404 * GNU Free Documentation License:: License for copying this manual
405
406 @end detailmenu
407 @end menu
408
409 @node Introduction
410 @chapter Introduction
411
412 @GNUTAR{} creates
413 and manipulates @dfn{archives} which are actually collections of
414 many other files; the program provides users with an organized and
415 systematic method for controlling a large amount of data.
416 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
417 archives need not (and these days, typically do not) reside on tapes.
418
419 @menu
420 * Book Contents:: What this Book Contains
421 * Definitions:: Some Definitions
422 * What tar Does:: What @command{tar} Does
423 * Naming tar Archives:: How @command{tar} Archives are Named
424 * Authors:: @GNUTAR{} Authors
425 * Reports:: Reporting bugs or suggestions
426 @end menu
427
428 @node Book Contents
429 @section What this Book Contains
430
431 The first part of this chapter introduces you to various terms that will
432 recur throughout the book. It also tells you who has worked on @GNUTAR{}
433 and its documentation, and where you should send bug reports
434 or comments.
435
436 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
437 gentle introduction for people who are new to using @command{tar}. It is
438 meant to be self contained, not requiring any reading from subsequent
439 chapters to make sense. It moves from topic to topic in a logical,
440 progressive order, building on information already explained.
441
442 Although the tutorial is paced and structured to allow beginners to
443 learn how to use @command{tar}, it is not intended solely for beginners.
444 The tutorial explains how to use the three most frequently used
445 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
446 two frequently used options (@samp{file} and @samp{verbose}). The other
447 chapters do not refer to the tutorial frequently; however, if a section
448 discusses something which is a complex variant of a basic concept, there
449 may be a cross reference to that basic concept. (The entire book,
450 including the tutorial, assumes that the reader understands some basic
451 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
452
453 The third chapter presents the remaining five operations, and
454 information about using @command{tar} options and option syntax.
455
456 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
457 than the reality. should think about whether this makes sense to say
458 here, or not.} The other chapters are meant to be used as a
459 reference. Each chapter presents everything that needs to be said
460 about a specific topic.
461
462 One of the chapters (@pxref{Date input formats}) exists in its
463 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
464 In addition, one section of this manual (@pxref{Standard}) contains a
465 big quote which is taken directly from @command{tar} sources.
466
467 In general, we give both long and short (abbreviated) option names
468 at least once in each section where the relevant option is covered, so
469 that novice readers will become familiar with both styles. (A few
470 options have no short versions, and the relevant sections will
471 indicate this.)
472
473 @node Definitions
474 @section Some Definitions
475
476 @cindex archive
477 @cindex tar archive
478 The @command{tar} program is used to create and manipulate @command{tar}
479 archives. An @dfn{archive} is a single file which contains the contents
480 of many files, while still identifying the names of the files, their
481 owner(s), and so forth. (In addition, archives record access
482 permissions, user and group, size in bytes, and data modification time.
483 Some archives also record the file names in each archived directory, as
484 well as other file and directory information.) You can use @command{tar}
485 to @dfn{create} a new archive in a specified directory.
486
487 @cindex member
488 @cindex archive member
489 @cindex file name
490 @cindex member name
491 The files inside an archive are called @dfn{members}. Within this
492 manual, we use the term @dfn{file} to refer only to files accessible in
493 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
494 @dfn{member} to refer only to the members of an archive. Similarly, a
495 @dfn{file name} is the name of a file, as it resides in the file system,
496 and a @dfn{member name} is the name of an archive member within the
497 archive.
498
499 @cindex extraction
500 @cindex unpacking
501 The term @dfn{extraction} refers to the process of copying an archive
502 member (or multiple members) into a file in the file system. Extracting
503 all the members of an archive is often called @dfn{extracting the
504 archive}. The term @dfn{unpack} can also be used to refer to the
505 extraction of many or all the members of an archive. Extracting an
506 archive does not destroy the archive's structure, just as creating an
507 archive does not destroy the copies of the files that exist outside of
508 the archive. You may also @dfn{list} the members in a given archive
509 (this is often thought of as ``printing'' them to the standard output,
510 or the command line), or @dfn{append} members to a pre-existing archive.
511 All of these operations can be performed using @command{tar}.
512
513 @node What tar Does
514 @section What @command{tar} Does
515
516 @cindex tar
517 The @command{tar} program provides the ability to create @command{tar}
518 archives, as well as various other kinds of manipulation. For example,
519 you can use @command{tar} on previously created archives to extract files,
520 to store additional files, or to update or list files which were already
521 stored.
522
523 Initially, @command{tar} archives were used to store files conveniently on
524 magnetic tape. The name @command{tar} comes from this use; it stands for
525 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
526 direct its output to available devices, files, or other programs (using
527 pipes). @command{tar} may even access remote devices or files (as archives).
528
529 You can use @command{tar} archives in many ways. We want to stress a few
530 of them: storage, backup, and transportation.
531
532 @FIXME{the following table entries need a bit of work.}
533 @table @asis
534 @item Storage
535 Often, @command{tar} archives are used to store related files for
536 convenient file transfer over a network. For example, the
537 @acronym{GNU} Project distributes its software bundled into
538 @command{tar} archives, so that all the files relating to a particular
539 program (or set of related programs) can be transferred as a single
540 unit.
541
542 A magnetic tape can store several files in sequence. However, the tape
543 has no names for these files; it only knows their relative position on
544 the tape. One way to store several files on one tape and retain their
545 names is by creating a @command{tar} archive. Even when the basic transfer
546 mechanism can keep track of names, as FTP can, the nuisance of handling
547 multiple files, directories, and multiple links makes @command{tar}
548 archives useful.
549
550 Archive files are also used for long-term storage. You can think of
551 this as transportation from the present into the future. (It is a
552 science-fiction idiom that you can move through time as well as in
553 space; the idea here is that @command{tar} can be used to move archives in
554 all dimensions, even time!)
555
556 @item Backup
557 Because the archive created by @command{tar} is capable of preserving
558 file information and directory structure, @command{tar} is commonly
559 used for performing full and incremental backups of disks. A backup
560 puts a collection of files (possibly pertaining to many users and
561 projects) together on a disk or a tape. This guards against
562 accidental destruction of the information in those files.
563 @GNUTAR{} has special features that allow it to be
564 used to make incremental and full dumps of all the files in a
565 file system.
566
567 @item Transportation
568 You can create an archive on one system, transfer it to another system,
569 and extract the contents there. This allows you to transport a group of
570 files from one system to another.
571 @end table
572
573 @node Naming tar Archives
574 @section How @command{tar} Archives are Named
575
576 Conventionally, @command{tar} archives are given names ending with
577 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
578 but this manual follows that convention in order to accustom readers to
579 it and to make examples more clear.
580
581 @cindex tar file
582 @cindex entry
583 @cindex tar entry
584 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
585 archive members as ``files'' or ``entries''. For people familiar with
586 the operation of @command{tar}, this causes no difficulty. However, in
587 this manual, we consistently refer to ``archives'' and ``archive
588 members'' to make learning to use @command{tar} easier for novice users.
589
590 @node Authors
591 @section @GNUTAR{} Authors
592
593 @GNUTAR{} was originally written by John Gilmore,
594 and modified by many people. The @acronym{GNU} enhancements were
595 written by Jay Fenlason, then Joy Kendall, and the whole package has
596 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
597 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
598 numerous and kind users.
599
600 We wish to stress that @command{tar} is a collective work, and owes much to
601 all those people who reported problems, offered solutions and other
602 insights, or shared their thoughts and suggestions. An impressive, yet
603 partial list of those contributors can be found in the @file{THANKS}
604 file from the @GNUTAR{} distribution.
605
606 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
607 sure i want to spell out the history in this detail, at least not for
608 the printed book. i'm just not sure it needs to be said this way.
609 i'll think about it.}
610
611 @FIXME{History is more important, and surely more interesting, than
612 actual names. Quoting names without history would be meaningless. FP}
613
614 Jay Fenlason put together a draft of a @GNUTAR{}
615 manual, borrowing notes from the original man page from John Gilmore.
616 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
617 Gorin worked on a tutorial and manual for @GNUTAR{}.
618 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
619 taking information from all these sources and merging them. Melissa
620 Weisshaus finally edited and redesigned the book to create version
621 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
622 by the current maintainer, Sergey Poznyakoff.
623
624 For version 1.12, Daniel Hagerty contributed a great deal of technical
625 consulting. In particular, he is the primary author of @ref{Backups}.
626
627 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
628 (see @url{http://savannah.gnu.org/projects/tar}), and
629 active development and maintenance work has started
630 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
631 Poznyakoff and Jeff Bailey.
632
633 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
634
635 @node Reports
636 @section Reporting bugs or suggestions
637
638 @cindex bug reports
639 @cindex reporting bugs
640 If you find problems or have suggestions about this program or manual,
641 please report them to @file{bug-tar@@gnu.org}.
642
643 When reporting a bug, please be sure to include as much detail as
644 possible, in order to reproduce it. @FIXME{Be more specific, I'd
645 like to make this node as detailed as 'Bug reporting' node in Emacs
646 manual}.
647
648 @node Tutorial
649 @chapter Tutorial Introduction to @command{tar}
650
651 This chapter guides you through some basic examples of three @command{tar}
652 operations: @option{--create}, @option{--list}, and @option{--extract}. If
653 you already know how to use some other version of @command{tar}, then you
654 may not need to read this chapter. This chapter omits most complicated
655 details about how @command{tar} works.
656
657 @menu
658 * assumptions::
659 * stylistic conventions::
660 * basic tar options:: Basic @command{tar} Operations and Options
661 * frequent operations::
662 * Two Frequent Options::
663 * create:: How to Create Archives
664 * list:: How to List Archives
665 * extract:: How to Extract Members from an Archive
666 * going further::
667 @end menu
668
669 @node assumptions
670 @section Assumptions this Tutorial Makes
671
672 This chapter is paced to allow beginners to learn about @command{tar}
673 slowly. At the same time, we will try to cover all the basic aspects of
674 these three operations. In order to accomplish both of these tasks, we
675 have made certain assumptions about your knowledge before reading this
676 manual, and the hardware you will be using:
677
678 @itemize @bullet
679 @item
680 Before you start to work through this tutorial, you should understand
681 what the terms ``archive'' and ``archive member'' mean
682 (@pxref{Definitions}). In addition, you should understand something
683 about how Unix-type operating systems work, and you should know how to
684 use some basic utilities. For example, you should know how to create,
685 list, copy, rename, edit, and delete files and directories; how to
686 change between directories; and how to figure out where you are in the
687 file system. You should have some basic understanding of directory
688 structure and how files are named according to which directory they are
689 in. You should understand concepts such as standard output and standard
690 input, what various definitions of the term ``argument'' mean, and the
691 differences between relative and absolute file names. @FIXME{and what
692 else?}
693
694 @item
695 This manual assumes that you are working from your own home directory
696 (unless we state otherwise). In this tutorial, you will create a
697 directory to practice @command{tar} commands in. When we show file names,
698 we will assume that those names are relative to your home directory.
699 For example, my home directory is @file{/home/fsf/melissa}. All of
700 my examples are in a subdirectory of the directory named by that file
701 name; the subdirectory is called @file{practice}.
702
703 @item
704 In general, we show examples of archives which exist on (or can be
705 written to, or worked with from) a directory on a hard disk. In most
706 cases, you could write those archives to, or work with them on any other
707 device, such as a tape drive. However, some of the later examples in
708 the tutorial and next chapter will not work on tape drives.
709 Additionally, working with tapes is much more complicated than working
710 with hard disks. For these reasons, the tutorial does not cover working
711 with tape drives. @xref{Media}, for complete information on using
712 @command{tar} archives with tape drives.
713
714 @FIXME{this is a cop out. need to add some simple tape drive info.}
715 @end itemize
716
717 @node stylistic conventions
718 @section Stylistic Conventions
719
720 In the examples, @samp{$} represents a typical shell prompt. It
721 precedes lines you should type; to make this more clear, those lines are
722 shown in @kbd{this font}, as opposed to lines which represent the
723 computer's response; those lines are shown in @code{this font}, or
724 sometimes @samp{like this}.
725
726 @c When we have lines which are too long to be
727 @c displayed in any other way, we will show them like this:
728
729 @node basic tar options
730 @section Basic @command{tar} Operations and Options
731
732 @command{tar} can take a wide variety of arguments which specify and define
733 the actions it will have on the particular set of files or the archive.
734 The main types of arguments to @command{tar} fall into one of two classes:
735 operations, and options.
736
737 Some arguments fall into a class called @dfn{operations}; exactly one of
738 these is both allowed and required for any instance of using @command{tar};
739 you may @emph{not} specify more than one. People sometimes speak of
740 @dfn{operating modes}. You are in a particular operating mode when you
741 have specified the operation which specifies it; there are eight
742 operations in total, and thus there are eight operating modes.
743
744 The other arguments fall into the class known as @dfn{options}. You are
745 not required to specify any options, and you are allowed to specify more
746 than one at a time (depending on the way you are using @command{tar} at
747 that time). Some options are used so frequently, and are so useful for
748 helping you type commands more carefully that they are effectively
749 ``required''. We will discuss them in this chapter.
750
751 You can write most of the @command{tar} operations and options in any
752 of three forms: long (mnemonic) form, short form, and old style. Some
753 of the operations and options have no short or ``old'' forms; however,
754 the operations and options which we will cover in this tutorial have
755 corresponding abbreviations. @FIXME{make sure this is still the case,
756 at the end}We will indicate those abbreviations appropriately to get
757 you used to seeing them. (Note that the ``old style'' option forms
758 exist in @GNUTAR{} for compatibility with Unix
759 @command{tar}. In this book we present a full discussion of this way
760 of writing options and operations (@pxref{Old Options}), and we discuss
761 the other two styles of writing options (@xref{Long Options}, and
762 @pxref{Short Options}).
763
764 In the examples and in the text of this tutorial, we usually use the
765 long forms of operations and options; but the ``short'' forms produce
766 the same result and can make typing long @command{tar} commands easier.
767 For example, instead of typing
768
769 @smallexample
770 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
771 @end smallexample
772
773 @noindent
774 you can type
775 @smallexample
776 @kbd{tar -c -v -f afiles.tar apple angst aspic}
777 @end smallexample
778
779 @noindent
780 or even
781 @smallexample
782 @kbd{tar -cvf afiles.tar apple angst aspic}
783 @end smallexample
784
785 @noindent
786 For more information on option syntax, see @ref{Advanced tar}. In
787 discussions in the text, when we name an option by its long form, we
788 also give the corresponding short option in parentheses.
789
790 The term, ``option'', can be confusing at times, since ``operations''
791 are often lumped in with the actual, @emph{optional} ``options'' in certain
792 general class statements. For example, we just talked about ``short and
793 long forms of options and operations''. However, experienced @command{tar}
794 users often refer to these by shorthand terms such as, ``short and long
795 options''. This term assumes that the ``operations'' are included, also.
796 Context will help you determine which definition of ``options'' to use.
797
798 Similarly, the term ``command'' can be confusing, as it is often used in
799 two different ways. People sometimes refer to @command{tar} ``commands''.
800 A @command{tar} @dfn{command} is the entire command line of user input
801 which tells @command{tar} what to do --- including the operation, options,
802 and any arguments (file names, pipes, other commands, etc.). However,
803 you will also sometimes hear the term ``the @command{tar} command''. When
804 the word ``command'' is used specifically like this, a person is usually
805 referring to the @command{tar} @emph{operation}, not the whole line.
806 Again, use context to figure out which of the meanings the speaker
807 intends.
808
809 @node frequent operations
810 @section The Three Most Frequently Used Operations
811
812 Here are the three most frequently used operations (both short and long
813 forms), as well as a brief description of their meanings. The rest of
814 this chapter will cover how to use these operations in detail. We will
815 present the rest of the operations in the next chapter.
816
817 @table @option
818 @item --create
819 @itemx -c
820 Create a new @command{tar} archive.
821 @item --list
822 @itemx -t
823 List the contents of an archive.
824 @item --extract
825 @itemx -x
826 Extract one or more members from an archive.
827 @end table
828
829 @node Two Frequent Options
830 @section Two Frequently Used Options
831
832 To understand how to run @command{tar} in the three operating modes listed
833 previously, you also need to understand how to use two of the options to
834 @command{tar}: @option{--file} (which takes an archive file as an argument)
835 and @option{--verbose}. (You are usually not @emph{required} to specify
836 either of these options when you run @command{tar}, but they can be very
837 useful in making things more clear and helping you avoid errors.)
838
839 @menu
840 * file tutorial::
841 * verbose tutorial::
842 * help tutorial::
843 @end menu
844
845 @node file tutorial
846 @unnumberedsubsec The @option{--file} Option
847
848 @table @option
849 @xopindex{file, tutorial}
850 @item --file=@var{archive-name}
851 @itemx -f @var{archive-name}
852 Specify the name of an archive file.
853 @end table
854
855 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
856 use @command{tar}; this option determines the name of the archive file
857 that @command{tar} will work on.
858
859 @vrindex TAPE
860 If you don't specify this argument, then @command{tar} will examine
861 the environment variable @env{TAPE}. If it is set, its value will be
862 used as the archive name. Otherwise, @command{tar} will use the
863 default archive, determined at the compile time. Usually it is
864 standard output or some physical tape drive attached to your machine
865 (you can verify what the default is by running @kbd{tar
866 --show-defaults}, @pxref{defaults}). If there is no tape drive
867 attached, or the default is not meaningful, then @command{tar} will
868 print an error message. The error message might look roughly like one
869 of the following:
870
871 @smallexample
872 tar: can't open /dev/rmt8 : No such device or address
873 tar: can't open /dev/rsmt0 : I/O error
874 @end smallexample
875
876 @noindent
877 To avoid confusion, we recommend that you always specify an archive file
878 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
879 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
880 @ref{file}.
881
882 @node verbose tutorial
883 @unnumberedsubsec The @option{--verbose} Option
884
885 @table @option
886 @xopindex{verbose, introduced}
887 @item --verbose
888 @itemx -v
889 Show the files being worked on as @command{tar} is running.
890 @end table
891
892 @option{--verbose} (@option{-v}) shows details about the results of running
893 @command{tar}. This can be especially useful when the results might not be
894 obvious. For example, if you want to see the progress of @command{tar} as
895 it writes files into the archive, you can use the @option{--verbose}
896 option. In the beginning, you may find it useful to use
897 @option{--verbose} at all times; when you are more accustomed to
898 @command{tar}, you will likely want to use it at certain times but not at
899 others. We will use @option{--verbose} at times to help make something
900 clear, and we will give many examples both using and not using
901 @option{--verbose} to show the differences.
902
903 Each instance of @option{--verbose} on the command line increases the
904 verbosity level by one, so if you need more details on the output,
905 specify it twice.
906
907 When reading archives (@option{--list}, @option{--extract},
908 @option{--diff}), @command{tar} by default prints only the names of
909 the members being extracted. Using @option{--verbose} will show a full,
910 @command{ls} style member listing.
911
912 In contrast, when writing archives (@option{--create}, @option{--append},
913 @option{--update}), @command{tar} does not print file names by
914 default. So, a single @option{--verbose} option shows the file names
915 being added to the archive, while two @option{--verbose} options
916 enable the full listing.
917
918 For example, to create an archive in verbose mode:
919
920 @smallexample
921 $ @kbd{tar -cvf afiles.tar apple angst aspic}
922 apple
923 angst
924 aspic
925 @end smallexample
926
927 @noindent
928 Creating the same archive with the verbosity level 2 could give:
929
930 @smallexample
931 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
932 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
933 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
934 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
935 @end smallexample
936
937 @noindent
938 This works equally well using short or long forms of options. Using
939 long forms, you would simply write out the mnemonic form of the option
940 twice, like this:
941
942 @smallexample
943 $ @kbd{tar --create --verbose --verbose @dots{}}
944 @end smallexample
945
946 @noindent
947 Note that you must double the hyphens properly each time.
948
949 Later in the tutorial, we will give examples using @w{@option{--verbose
950 --verbose}}.
951
952 @anchor{verbose member listing}
953 The full output consists of six fields:
954
955 @itemize @bullet
956 @item File type and permissions in symbolic form.
957 These are displayed in the same format as the first column of
958 @command{ls -l} output (@pxref{What information is listed,
959 format=verbose, Verbose listing, fileutils, GNU file utilities}).
960
961 @item Owner name and group separated by a slash character.
962 If these data are not available (for example, when listing a @samp{v7} format
963 archive), numeric @acronym{ID} values are printed instead.
964
965 @item Size of the file, in bytes.
966
967 @item File modification date in ISO 8601 format.
968
969 @item File modification time.
970
971 @item File name.
972 If the name contains any special characters (white space, newlines,
973 etc.) these are displayed in an unambiguous form using so called
974 @dfn{quoting style}. For the detailed discussion of available styles
975 and on how to use them, see @ref{quoting styles}.
976
977 Depending on the file type, the name can be followed by some
978 additional information, described in the following table:
979
980 @table @samp
981 @item -> @var{link-name}
982 The file or archive member is a @dfn{symbolic link} and
983 @var{link-name} is the name of file it links to.
984
985 @item link to @var{link-name}
986 The file or archive member is a @dfn{hard link} and @var{link-name} is
987 the name of file it links to.
988
989 @item --Long Link--
990 The archive member is an old GNU format long link. You will normally
991 not encounter this.
992
993 @item --Long Name--
994 The archive member is an old GNU format long name. You will normally
995 not encounter this.
996
997 @item --Volume Header--
998 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
999
1000 @item --Continued at byte @var{n}--
1001 Encountered only at the beginning of a multi-volume archive
1002 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1003 from the previous volume. The number @var{n} gives the offset where
1004 the original file was split.
1005
1006 @item unknown file type @var{c}
1007 An archive member of unknown type. @var{c} is the type character from
1008 the archive header. If you encounter such a message, it means that
1009 either your archive contains proprietary member types @GNUTAR{} is not
1010 able to handle, or the archive is corrupted.
1011 @end table
1012
1013 @end itemize
1014
1015 For example, here is an archive listing containing most of the special
1016 suffixes explained above:
1017
1018 @smallexample
1019 @group
1020 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1021 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1022 byte 32456--
1023 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1024 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1025 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1026 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1027 @end group
1028 @end smallexample
1029
1030 @smallexample
1031 @end smallexample
1032
1033 @node help tutorial
1034 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1035
1036 @table @option
1037 @opindex help
1038 @item --help
1039
1040 The @option{--help} option to @command{tar} prints out a very brief list of
1041 all operations and option available for the current version of
1042 @command{tar} available on your system.
1043 @end table
1044
1045 @node create
1046 @section How to Create Archives
1047 @UNREVISED
1048
1049 @cindex Creation of the archive
1050 @cindex Archive, creation of
1051 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1052 you use to create a @command{tar} archive. We will explain
1053 @option{--create} first because, in order to learn about the other
1054 operations, you will find it useful to have an archive available to
1055 practice on.
1056
1057 To make this easier, in this section you will first create a directory
1058 containing three files. Then, we will show you how to create an
1059 @emph{archive} (inside the new directory). Both the directory, and
1060 the archive are specifically for you to practice on. The rest of this
1061 chapter and the next chapter will show many examples using this
1062 directory and the files you will create: some of those files may be
1063 other directories and other archives.
1064
1065 The three files you will archive in this example are called
1066 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1067 @file{collection.tar}.
1068
1069 This section will proceed slowly, detailing how to use @option{--create}
1070 in @code{verbose} mode, and showing examples using both short and long
1071 forms. In the rest of the tutorial, and in the examples in the next
1072 chapter, we will proceed at a slightly quicker pace. This section
1073 moves more slowly to allow beginning users to understand how
1074 @command{tar} works.
1075
1076 @menu
1077 * prepare for examples::
1078 * Creating the archive::
1079 * create verbose::
1080 * short create::
1081 * create dir::
1082 @end menu
1083
1084 @node prepare for examples
1085 @subsection Preparing a Practice Directory for Examples
1086
1087 To follow along with this and future examples, create a new directory
1088 called @file{practice} containing files called @file{blues}, @file{folk}
1089 and @file{jazz}. The files can contain any information you like:
1090 ideally, they should contain information which relates to their names,
1091 and be of different lengths. Our examples assume that @file{practice}
1092 is a subdirectory of your home directory.
1093
1094 Now @command{cd} to the directory named @file{practice}; @file{practice}
1095 is now your @dfn{working directory}. (@emph{Please note}: Although
1096 the full file name of this directory is
1097 @file{/@var{homedir}/practice}, in our examples we will refer to
1098 this directory as @file{practice}; the @var{homedir} is presumed.
1099
1100 In general, you should check that the files to be archived exist where
1101 you think they do (in the working directory) by running @command{ls}.
1102 Because you just created the directory and the files and have changed to
1103 that directory, you probably don't need to do that this time.
1104
1105 It is very important to make sure there isn't already a file in the
1106 working directory with the archive name you intend to use (in this case,
1107 @samp{collection.tar}), or that you don't care about its contents.
1108 Whenever you use @samp{create}, @command{tar} will erase the current
1109 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1110 will not tell you if you are about to overwrite an archive unless you
1111 specify an option which does this (@pxref{backup}, for the
1112 information on how to do so). To add files to an existing archive,
1113 you need to use a different option, such as @option{--append} (@option{-r}); see
1114 @ref{append} for information on how to do this.
1115
1116 @node Creating the archive
1117 @subsection Creating the Archive
1118
1119 @xopindex{create, introduced}
1120 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1121 archive named @file{collection.tar}, use the following command:
1122
1123 @smallexample
1124 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1125 @end smallexample
1126
1127 The order of the arguments is not very important, @emph{when using long
1128 option forms}. You could also say:
1129
1130 @smallexample
1131 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1132 @end smallexample
1133
1134 @noindent
1135 However, you can see that this order is harder to understand; this is
1136 why we will list the arguments in the order that makes the commands
1137 easiest to understand (and we encourage you to do the same when you use
1138 @command{tar}, to avoid errors).
1139
1140 Note that the sequence
1141 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1142 If you substituted any other string of characters for
1143 @kbd{collection.tar}, then that string would become the name of the
1144 archive file you create.
1145
1146 The order of the options becomes more important when you begin to use
1147 short forms. With short forms, if you type commands in the wrong order
1148 (even if you type them correctly in all other ways), you may end up with
1149 results you don't expect. For this reason, it is a good idea to get
1150 into the habit of typing options in the order that makes inherent sense.
1151 @xref{short create}, for more information on this.
1152
1153 In this example, you type the command as shown above: @option{--create}
1154 is the operation which creates the new archive
1155 (@file{collection.tar}), and @option{--file} is the option which lets
1156 you give it the name you chose. The files, @file{blues}, @file{folk},
1157 and @file{jazz}, are now members of the archive, @file{collection.tar}
1158 (they are @dfn{file name arguments} to the @option{--create} operation.
1159 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1160 in the archive, they are called @emph{archive members}, not files.
1161 (@pxref{Definitions,members}).
1162
1163 When you create an archive, you @emph{must} specify which files you
1164 want placed in the archive. If you do not specify any archive
1165 members, @GNUTAR{} will complain.
1166
1167 If you now list the contents of the working directory (@command{ls}), you will
1168 find the archive file listed as well as the files you saw previously:
1169
1170 @smallexample
1171 blues folk jazz collection.tar
1172 @end smallexample
1173
1174 @noindent
1175 Creating the archive @samp{collection.tar} did not destroy the copies of
1176 the files in the directory.
1177
1178 Keep in mind that if you don't indicate an operation, @command{tar} will not
1179 run and will prompt you for one. If you don't name any files, @command{tar}
1180 will complain. You must have write access to the working directory,
1181 or else you will not be able to create an archive in that directory.
1182
1183 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1184 an existing archive; it will delete the archive and write a new one.
1185 Use @option{--append} (@option{-r}) instead. @xref{append}.
1186
1187 @node create verbose
1188 @subsection Running @option{--create} with @option{--verbose}
1189
1190 @xopindex{create, using with @option{--verbose}}
1191 @xopindex{verbose, using with @option{--create}}
1192 If you include the @option{--verbose} (@option{-v}) option on the command line,
1193 @command{tar} will list the files it is acting on as it is working. In
1194 verbose mode, the @code{create} example above would appear as:
1195
1196 @smallexample
1197 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1198 blues
1199 folk
1200 jazz
1201 @end smallexample
1202
1203 This example is just like the example we showed which did not use
1204 @option{--verbose}, except that @command{tar} generated the remaining lines
1205 @iftex
1206 (note the different font styles).
1207 @end iftex
1208 @ifinfo
1209 .
1210 @end ifinfo
1211
1212 In the rest of the examples in this chapter, we will frequently use
1213 @code{verbose} mode so we can show actions or @command{tar} responses that
1214 you would otherwise not see, and which are important for you to
1215 understand.
1216
1217 @node short create
1218 @subsection Short Forms with @samp{create}
1219
1220 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1221 basic uses of @command{tar}, and you will use it countless times.
1222 Eventually, you will probably want to use abbreviated (or ``short'')
1223 forms of options. A full discussion of the three different forms that
1224 options can take appears in @ref{Styles}; for now, here is what the
1225 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1226 using short option forms:
1227
1228 @smallexample
1229 $ @kbd{tar -cvf collection.tar blues folk jazz}
1230 blues
1231 folk
1232 jazz
1233 @end smallexample
1234
1235 @noindent
1236 As you can see, the system responds the same no matter whether you use
1237 long or short option forms.
1238
1239 @FIXME{i don't like how this is worded:} One difference between using
1240 short and long option forms is that, although the exact placement of
1241 arguments following options is no more specific when using short forms,
1242 it is easier to become confused and make a mistake when using short
1243 forms. For example, suppose you attempted the above example in the
1244 following way:
1245
1246 @smallexample
1247 $ @kbd{tar -cfv collection.tar blues folk jazz}
1248 @end smallexample
1249
1250 @noindent
1251 In this case, @command{tar} will make an archive file called @file{v},
1252 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1253 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1254 is thus taken to be the chosen archive file name. @command{tar} will try
1255 to add a file called @file{collection.tar} to the @file{v} archive file;
1256 if the file @file{collection.tar} did not already exist, @command{tar} will
1257 report an error indicating that this file does not exist. If the file
1258 @file{collection.tar} does already exist (e.g., from a previous command
1259 you may have run), then @command{tar} will add this file to the archive.
1260 Because the @option{-v} option did not get registered, @command{tar} will not
1261 run under @samp{verbose} mode, and will not report its progress.
1262
1263 The end result is that you may be quite confused about what happened,
1264 and possibly overwrite a file. To illustrate this further, we will show
1265 you how an example we showed previously would look using short forms.
1266
1267 This example,
1268
1269 @smallexample
1270 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1271 @end smallexample
1272
1273 @noindent
1274 is confusing as it is. When shown using short forms, however, it
1275 becomes much more so:
1276
1277 @smallexample
1278 $ @kbd{tar blues -c folk -f collection.tar jazz}
1279 @end smallexample
1280
1281 @noindent
1282 It would be very easy to put the wrong string of characters
1283 immediately following the @option{-f}, but doing that could sacrifice
1284 valuable data.
1285
1286 For this reason, we recommend that you pay very careful attention to
1287 the order of options and placement of file and archive names,
1288 especially when using short option forms. Not having the option name
1289 written out mnemonically can affect how well you remember which option
1290 does what, and therefore where different names have to be placed.
1291
1292 @node create dir
1293 @subsection Archiving Directories
1294
1295 @cindex Archiving Directories
1296 @cindex Directories, Archiving
1297 You can archive a directory by specifying its directory name as a
1298 file name argument to @command{tar}. The files in the directory will be
1299 archived relative to the working directory, and the directory will be
1300 re-created along with its contents when the archive is extracted.
1301
1302 To archive a directory, first move to its superior directory. If you
1303 have followed the previous instructions in this tutorial, you should
1304 type:
1305
1306 @smallexample
1307 $ @kbd{cd ..}
1308 $
1309 @end smallexample
1310
1311 @noindent
1312 This will put you into the directory which contains @file{practice},
1313 i.e., your home directory. Once in the superior directory, you can
1314 specify the subdirectory, @file{practice}, as a file name argument. To
1315 store @file{practice} in the new archive file @file{music.tar}, type:
1316
1317 @smallexample
1318 $ @kbd{tar --create --verbose --file=music.tar practice}
1319 @end smallexample
1320
1321 @noindent
1322 @command{tar} should output:
1323
1324 @smallexample
1325 practice/
1326 practice/blues
1327 practice/folk
1328 practice/jazz
1329 practice/collection.tar
1330 @end smallexample
1331
1332 Note that the archive thus created is not in the subdirectory
1333 @file{practice}, but rather in the current working directory---the
1334 directory from which @command{tar} was invoked. Before trying to archive a
1335 directory from its superior directory, you should make sure you have
1336 write access to the superior directory itself, not only the directory
1337 you are trying archive with @command{tar}. For example, you will probably
1338 not be able to store your home directory in an archive by invoking
1339 @command{tar} from the root directory; @xref{absolute}. (Note
1340 also that @file{collection.tar}, the original archive file, has itself
1341 been archived. @command{tar} will accept any file as a file to be
1342 archived, regardless of its content. When @file{music.tar} is
1343 extracted, the archive file @file{collection.tar} will be re-written
1344 into the file system).
1345
1346 If you give @command{tar} a command such as
1347
1348 @smallexample
1349 $ @kbd{tar --create --file=foo.tar .}
1350 @end smallexample
1351
1352 @noindent
1353 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1354 dumped}. This happens because @command{tar} creates the archive
1355 @file{foo.tar} in the current directory before putting any files into
1356 it. Then, when @command{tar} attempts to add all the files in the
1357 directory @file{.} to the archive, it notices that the file
1358 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1359 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1360 will continue in this case, and create the archive
1361 normally, except for the exclusion of that one file. (@emph{Please
1362 note:} Other implementations of @command{tar} may not be so clever;
1363 they will enter an infinite loop when this happens, so you should not
1364 depend on this behavior unless you are certain you are running
1365 @GNUTAR{}. In general, it is wise to always place the archive outside
1366 of the directory being dumped.
1367
1368 @node list
1369 @section How to List Archives
1370
1371 @opindex list
1372 Frequently, you will find yourself wanting to determine exactly what a
1373 particular archive contains. You can use the @option{--list}
1374 (@option{-t}) operation to get the member names as they currently
1375 appear in the archive, as well as various attributes of the files at
1376 the time they were archived. For example, you can examine the archive
1377 @file{collection.tar} that you created in the last section with the
1378 command,
1379
1380 @smallexample
1381 $ @kbd{tar --list --file=collection.tar}
1382 @end smallexample
1383
1384 @noindent
1385 The output of @command{tar} would then be:
1386
1387 @smallexample
1388 blues
1389 folk
1390 jazz
1391 @end smallexample
1392
1393 @noindent
1394 The archive @file{bfiles.tar} would list as follows:
1395
1396 @smallexample
1397 ./birds
1398 baboon
1399 ./box
1400 @end smallexample
1401
1402 @noindent
1403 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1404 @var{archive-name}}) option just as with @option{--create}
1405 (@option{-c}) to specify the name of the archive.
1406
1407 @xopindex{list, using with @option{--verbose}}
1408 @xopindex{verbose, using with @option{--list}}
1409 If you use the @option{--verbose} (@option{-v}) option with
1410 @option{--list}, then @command{tar} will print out a listing
1411 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1412 forth. This output is described in detail in @ref{verbose member listing}.
1413
1414 If you had used @option{--verbose} (@option{-v}) mode, the example
1415 above would look like:
1416
1417 @smallexample
1418 $ @kbd{tar --list --verbose --file=collection.tar folk}
1419 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1420 @end smallexample
1421
1422 @cindex listing member and file names
1423 @anchor{listing member and file names}
1424 It is important to notice that the output of @kbd{tar --list
1425 --verbose} does not necessarily match that produced by @kbd{tar
1426 --create --verbose} while creating the archive. It is because
1427 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1428 prefixes from file names before storing them in the archive
1429 (@xref{absolute}, for more information). In other
1430 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1431 an archive and @dfn{member names} when listing it. Consider this
1432 example:
1433
1434 @smallexample
1435 @group
1436 $ @kbd{tar cfv archive /etc/mail}
1437 tar: Removing leading `/' from member names
1438 /etc/mail/
1439 /etc/mail/sendmail.cf
1440 /etc/mail/aliases
1441 $ @kbd{tar tf archive}
1442 etc/mail/
1443 etc/mail/sendmail.cf
1444 etc/mail/aliases
1445 @end group
1446 @end smallexample
1447
1448 @opindex show-stored-names
1449 This default behavior can sometimes be inconvenient. You can force
1450 @GNUTAR{} show member names when creating archive by supplying
1451 @option{--show-stored-names} option.
1452
1453 @table @option
1454 @item --show-stored-names
1455 Print member (as opposed to @emph{file}) names when creating the archive.
1456 @end table
1457
1458 @cindex File name arguments, using @option{--list} with
1459 @xopindex{list, using with file name arguments}
1460 You can specify one or more individual member names as arguments when
1461 using @samp{list}. In this case, @command{tar} will only list the
1462 names of members you identify. For example, @w{@kbd{tar --list
1463 --file=afiles.tar apple}} would only print @file{apple}.
1464
1465 Because @command{tar} preserves file names, these must be specified as
1466 they appear in the archive (i.e., relative to the directory from which
1467 the archive was created). Therefore, it is essential when specifying
1468 member names to @command{tar} that you give the exact member names.
1469 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1470 error message something like @samp{tar: birds: Not found in archive},
1471 because there is no member named @file{birds}, only one named
1472 @file{./birds}. While the names @file{birds} and @file{./birds} name
1473 the same file, @emph{member} names by default are compared verbatim.
1474
1475 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1476 with @file{baboon}, because this exact member name is in the archive file
1477 @file{bfiles.tar}. If you are not sure of the exact file name,
1478 use @dfn{globbing patterns}, for example:
1479
1480 @smallexample
1481 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1482 @end smallexample
1483
1484 @noindent
1485 will list all members whose name contains @samp{b}. @xref{wildcards},
1486 for a detailed discussion of globbing patterns and related
1487 @command{tar} command line options.
1488
1489 @menu
1490 * list dir::
1491 @end menu
1492
1493 @node list dir
1494 @unnumberedsubsec Listing the Contents of a Stored Directory
1495
1496 To get information about the contents of an archived directory,
1497 use the directory name as a file name argument in conjunction with
1498 @option{--list} (@option{-t}). To find out file attributes, include the
1499 @option{--verbose} (@option{-v}) option.
1500
1501 For example, to find out about files in the directory @file{practice}, in
1502 the archive file @file{music.tar}, type:
1503
1504 @smallexample
1505 $ @kbd{tar --list --verbose --file=music.tar practice}
1506 @end smallexample
1507
1508 @command{tar} responds:
1509
1510 @smallexample
1511 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1512 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1513 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1514 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1515 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1516 @end smallexample
1517
1518 When you use a directory name as a file name argument, @command{tar} acts on
1519 all the files (including sub-directories) in that directory.
1520
1521 @node extract
1522 @section How to Extract Members from an Archive
1523 @UNREVISED
1524 @cindex Extraction
1525 @cindex Retrieving files from an archive
1526 @cindex Resurrecting files from an archive
1527
1528 @opindex extract
1529 Creating an archive is only half the job---there is no point in storing
1530 files in an archive if you can't retrieve them. The act of retrieving
1531 members from an archive so they can be used and manipulated as
1532 unarchived files again is called @dfn{extraction}. To extract files
1533 from an archive, use the @option{--extract} (@option{--get} or
1534 @option{-x}) operation. As with @option{--create}, specify the name
1535 of the archive with @option{--file} (@option{-f}) option. Extracting
1536 an archive does not modify the archive in any way; you can extract it
1537 multiple times if you want or need to.
1538
1539 Using @option{--extract}, you can extract an entire archive, or specific
1540 files. The files can be directories containing other files, or not. As
1541 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1542 long form of the operation without affecting the performance.
1543
1544 @menu
1545 * extracting archives::
1546 * extracting files::
1547 * extract dir::
1548 * extracting untrusted archives::
1549 * failing commands::
1550 @end menu
1551
1552 @node extracting archives
1553 @subsection Extracting an Entire Archive
1554
1555 To extract an entire archive, specify the archive file name only, with
1556 no individual file names as arguments. For example,
1557
1558 @smallexample
1559 $ @kbd{tar -xvf collection.tar}
1560 @end smallexample
1561
1562 @noindent
1563 produces this:
1564
1565 @smallexample
1566 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1567 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1568 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1569 @end smallexample
1570
1571 @node extracting files
1572 @subsection Extracting Specific Files
1573
1574 To extract specific archive members, give their exact member names as
1575 arguments, as printed by @option{--list} (@option{-t}). If you had
1576 mistakenly deleted one of the files you had placed in the archive
1577 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1578 from the archive without changing the archive's structure. Its
1579 contents will be identical to the original file @file{blues} that you
1580 deleted.
1581
1582 First, make sure you are in the @file{practice} directory, and list the
1583 files in the directory. Now, delete the file, @samp{blues}, and list
1584 the files in the directory again.
1585
1586 You can now extract the member @file{blues} from the archive file
1587 @file{collection.tar} like this:
1588
1589 @smallexample
1590 $ @kbd{tar --extract --file=collection.tar blues}
1591 @end smallexample
1592
1593 @noindent
1594 If you list the files in the directory again, you will see that the file
1595 @file{blues} has been restored, with its original permissions, data
1596 modification times, and owner.@footnote{This is only accidentally
1597 true, but not in general. Whereas modification times are always
1598 restored, in most cases, one has to be root for restoring the owner,
1599 and use a special option for restoring permissions. Here, it just
1600 happens that the restoring user is also the owner of the archived
1601 members, and that the current @code{umask} is compatible with original
1602 permissions.} (These parameters will be identical to those which
1603 the file had when you originally placed it in the archive; any changes
1604 you may have made before deleting the file from the file system,
1605 however, will @emph{not} have been made to the archive member.) The
1606 archive file, @samp{collection.tar}, is the same as it was before you
1607 extracted @samp{blues}. You can confirm this by running @command{tar} with
1608 @option{--list} (@option{-t}).
1609
1610 Remember that as with other operations, specifying the exact member
1611 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1612 will fail, because there is no member named @file{birds}. To extract
1613 the member named @file{./birds}, you must specify @w{@kbd{tar
1614 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1615 exact member names, use @option{--list} (@option{-t}) option
1616 (@pxref{list}). You can also extract those members that match a
1617 specific @dfn{globbing pattern}. For example, to extract from
1618 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1619 directory prefix, you could type:
1620
1621 @smallexample
1622 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1623 @end smallexample
1624
1625 @noindent
1626 Here, @option{--wildcards} instructs @command{tar} to treat
1627 command line arguments as globbing patterns and @option{--no-anchored}
1628 informs it that the patterns apply to member names after any @samp{/}
1629 delimiter. The use of globbing patterns is discussed in detail in
1630 @xref{wildcards}.
1631
1632 You can extract a file to standard output by combining the above options
1633 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1634 Output}).
1635
1636 If you give the @option{--verbose} option, then @option{--extract}
1637 will print the names of the archive members as it extracts them.
1638
1639 @node extract dir
1640 @subsection Extracting Files that are Directories
1641
1642 Extracting directories which are members of an archive is similar to
1643 extracting other files. The main difference to be aware of is that if
1644 the extracted directory has the same name as any directory already in
1645 the working directory, then files in the extracted directory will be
1646 placed into the directory of the same name. Likewise, if there are
1647 files in the pre-existing directory with the same names as the members
1648 which you extract, the files from the extracted archive will replace
1649 the files already in the working directory (and possible
1650 subdirectories). This will happen regardless of whether or not the
1651 files in the working directory were more recent than those extracted
1652 (there exist, however, special options that alter this behavior
1653 @pxref{Writing}).
1654
1655 However, if a file was stored with a directory name as part of its file
1656 name, and that directory does not exist under the working directory when
1657 the file is extracted, @command{tar} will create the directory.
1658
1659 We can demonstrate how to use @option{--extract} to extract a directory
1660 file with an example. Change to the @file{practice} directory if you
1661 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1662 go back to the parent directory and extract the archive
1663 @file{music.tar}. You may either extract the entire archive, or you may
1664 extract only the files you just deleted. To extract the entire archive,
1665 don't give any file names as arguments after the archive name
1666 @file{music.tar}. To extract only the files you deleted, use the
1667 following command:
1668
1669 @smallexample
1670 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1671 practice/folk
1672 practice/jazz
1673 @end smallexample
1674
1675 @noindent
1676 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1677 would have displayed more detail about the extracted files, as shown
1678 in the example below:
1679
1680 @smallexample
1681 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1682 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1683 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1684 @end smallexample
1685
1686 @noindent
1687 Because you created the directory with @file{practice} as part of the
1688 file names of each of the files by archiving the @file{practice}
1689 directory as @file{practice}, you must give @file{practice} as part
1690 of the file names when you extract those files from the archive.
1691
1692 @node extracting untrusted archives
1693 @subsection Extracting Archives from Untrusted Sources
1694
1695 Extracting files from archives can overwrite files that already exist.
1696 If you receive an archive from an untrusted source, you should make a
1697 new directory and extract into that directory, so that you don't have
1698 to worry about the extraction overwriting one of your existing files.
1699 For example, if @file{untrusted.tar} came from somewhere else on the
1700 Internet, and you don't necessarily trust its contents, you can
1701 extract it as follows:
1702
1703 @smallexample
1704 $ @kbd{mkdir newdir}
1705 $ @kbd{cd newdir}
1706 $ @kbd{tar -xvf ../untrusted.tar}
1707 @end smallexample
1708
1709 It is also a good practice to examine contents of the archive
1710 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1711 with @option{--verbose} (@option{-v}).
1712
1713 @node failing commands
1714 @subsection Commands That Will Fail
1715
1716 Here are some sample commands you might try which will not work, and why
1717 they won't work.
1718
1719 If you try to use this command,
1720
1721 @smallexample
1722 $ @kbd{tar -xvf music.tar folk jazz}
1723 @end smallexample
1724
1725 @noindent
1726 you will get the following response:
1727
1728 @smallexample
1729 tar: folk: Not found in archive
1730 tar: jazz: Not found in archive
1731 $
1732 @end smallexample
1733
1734 @noindent
1735 This is because these files were not originally @emph{in} the parent
1736 directory @file{..}, where the archive is located; they were in the
1737 @file{practice} directory, and their file names reflect this:
1738
1739 @smallexample
1740 $ @kbd{tar -tvf music.tar}
1741 practice/folk
1742 practice/jazz
1743 practice/rock
1744 @end smallexample
1745
1746 @FIXME{make sure the above works when going through the examples in
1747 order...}
1748
1749 @noindent
1750 Likewise, if you try to use this command,
1751
1752 @smallexample
1753 $ @kbd{tar -tvf music.tar folk jazz}
1754 @end smallexample
1755
1756 @noindent
1757 you would get a similar response. Members with those names are not in the
1758 archive. You must use the correct member names, or wildcards, in order
1759 to extract the files from the archive.
1760
1761 If you have forgotten the correct names of the files in the archive,
1762 use @w{@kbd{tar --list --verbose}} to list them correctly.
1763
1764 @FIXME{more examples, here? hag thinks it's a good idea.}
1765
1766 @node going further
1767 @section Going Further Ahead in this Manual
1768
1769 @FIXME{need to write up a node here about the things that are going to
1770 be in the rest of the manual.}
1771
1772 @node tar invocation
1773 @chapter Invoking @GNUTAR{}
1774 @UNREVISED
1775
1776 This chapter is about how one invokes the @GNUTAR{}
1777 command, from the command synopsis (@pxref{Synopsis}). There are
1778 numerous options, and many styles for writing them. One mandatory
1779 option specifies the operation @command{tar} should perform
1780 (@pxref{Operation Summary}), other options are meant to detail how
1781 this operation should be performed (@pxref{Option Summary}).
1782 Non-option arguments are not always interpreted the same way,
1783 depending on what the operation is.
1784
1785 You will find in this chapter everything about option styles and rules for
1786 writing them (@pxref{Styles}). On the other hand, operations and options
1787 are fully described elsewhere, in other chapters. Here, you will find
1788 only synthetic descriptions for operations and options, together with
1789 pointers to other parts of the @command{tar} manual.
1790
1791 Some options are so special they are fully described right in this
1792 chapter. They have the effect of inhibiting the normal operation of
1793 @command{tar} or else, they globally alter the amount of feedback the user
1794 receives about what is going on. These are the @option{--help} and
1795 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1796 and @option{--interactive} options (@pxref{interactive}).
1797
1798 @menu
1799 * Synopsis::
1800 * using tar options::
1801 * Styles::
1802 * All Options::
1803 * help::
1804 * defaults::
1805 * verbose::
1806 * checkpoints::
1807 * interactive::
1808 @end menu
1809
1810 @node Synopsis
1811 @section General Synopsis of @command{tar}
1812
1813 The @GNUTAR{} program is invoked as either one of:
1814
1815 @smallexample
1816 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1817 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1818 @end smallexample
1819
1820 The second form is for when old options are being used.
1821
1822 You can use @command{tar} to store files in an archive, to extract them from
1823 an archive, and to do other types of archive manipulation. The primary
1824 argument to @command{tar}, which is called the @dfn{operation}, specifies
1825 which action to take. The other arguments to @command{tar} are either
1826 @dfn{options}, which change the way @command{tar} performs an operation,
1827 or file names or archive members, which specify the files or members
1828 @command{tar} is to act on.
1829
1830 You can actually type in arguments in any order, even if in this manual
1831 the options always precede the other arguments, to make examples easier
1832 to understand. Further, the option stating the main operation mode
1833 (the @command{tar} main command) is usually given first.
1834
1835 Each @var{name} in the synopsis above is interpreted as an archive member
1836 name when the main command is one of @option{--compare}
1837 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1838 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1839 @option{--update} (@option{-u}). When naming archive members, you
1840 must give the exact name of the member in the archive, as it is
1841 printed by @option{--list}. For @option{--append} (@option{-r}) and
1842 @option{--create} (@option{-c}), these @var{name} arguments specify
1843 the names of either files or directory hierarchies to place in the archive.
1844 These files or hierarchies should already exist in the file system,
1845 prior to the execution of the @command{tar} command.
1846
1847 @command{tar} interprets relative file names as being relative to the
1848 working directory. @command{tar} will make all file names relative
1849 (by removing leading slashes when archiving or restoring files),
1850 unless you specify otherwise (using the @option{--absolute-names}
1851 option). @xref{absolute}, for more information about
1852 @option{--absolute-names}.
1853
1854 If you give the name of a directory as either a file name or a member
1855 name, then @command{tar} acts recursively on all the files and directories
1856 beneath that directory. For example, the name @file{/} identifies all
1857 the files in the file system to @command{tar}.
1858
1859 The distinction between file names and archive member names is especially
1860 important when shell globbing is used, and sometimes a source of confusion
1861 for newcomers. @xref{wildcards}, for more information about globbing.
1862 The problem is that shells may only glob using existing files in the
1863 file system. Only @command{tar} itself may glob on archive members, so when
1864 needed, you must ensure that wildcard characters reach @command{tar} without
1865 being interpreted by the shell first. Using a backslash before @samp{*}
1866 or @samp{?}, or putting the whole argument between quotes, is usually
1867 sufficient for this.
1868
1869 Even if @var{name}s are often specified on the command line, they
1870 can also be read from a text file in the file system, using the
1871 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1872
1873 If you don't use any file name arguments, @option{--append} (@option{-r}),
1874 @option{--delete} and @option{--concatenate} (@option{--catenate},
1875 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1876 will usually yield a diagnostic and inhibit @command{tar} execution.
1877 The other operations of @command{tar} (@option{--list},
1878 @option{--extract}, @option{--compare}, and @option{--update})
1879 will act on the entire contents of the archive.
1880
1881 @cindex exit status
1882 @cindex return status
1883 Besides successful exits, @GNUTAR{} may fail for
1884 many reasons. Some reasons correspond to bad usage, that is, when the
1885 @command{tar} command is improperly written. Errors may be
1886 encountered later, while encountering an error processing the archive
1887 or the files. Some errors are recoverable, in which case the failure
1888 is delayed until @command{tar} has completed all its work. Some
1889 errors are such that it would not meaningful, or at least risky, to
1890 continue processing: @command{tar} then aborts processing immediately.
1891 All abnormal exits, whether immediate or delayed, should always be
1892 clearly diagnosed on @code{stderr}, after a line stating the nature of
1893 the error.
1894
1895 Possible exit codes of @GNUTAR{} are summarized in the following
1896 table:
1897
1898 @table @asis
1899 @item 0
1900 @samp{Successful termination}.
1901
1902 @item 1
1903 @samp{Some files differ}. If tar was invoked with @option{--compare}
1904 (@option{--diff}, @option{-d}) command line option, this means that
1905 some files in the archive differ from their disk counterparts
1906 (@pxref{compare}). If tar was given @option{--create},
1907 @option{--append} or @option{--update} option, this exit code means
1908 that some files were changed while being archived and so the resulting
1909 archive does not contain the exact copy of the file set.
1910
1911 @item 2
1912 @samp{Fatal error}. This means that some fatal, unrecoverable error
1913 occurred.
1914 @end table
1915
1916 If @command{tar} has invoked a subprocess and that subprocess exited with a
1917 nonzero exit code, @command{tar} exits with that code as well.
1918 This can happen, for example, if @command{tar} was given some
1919 compression option (@pxref{gzip}) and the external compressor program
1920 failed. Another example is @command{rmt} failure during backup to the
1921 remote device (@pxref{Remote Tape Server}).
1922
1923 @node using tar options
1924 @section Using @command{tar} Options
1925
1926 @GNUTAR{} has a total of eight operating modes which
1927 allow you to perform a variety of tasks. You are required to choose
1928 one operating mode each time you employ the @command{tar} program by
1929 specifying one, and only one operation as an argument to the
1930 @command{tar} command (two lists of four operations each may be found
1931 at @ref{frequent operations} and @ref{Operations}). Depending on
1932 circumstances, you may also wish to customize how the chosen operating
1933 mode behaves. For example, you may wish to change the way the output
1934 looks, or the format of the files that you wish to archive may require
1935 you to do something special in order to make the archive look right.
1936
1937 You can customize and control @command{tar}'s performance by running
1938 @command{tar} with one or more options (such as @option{--verbose}
1939 (@option{-v}), which we used in the tutorial). As we said in the
1940 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1941 their name suggests) optional. Depending on the operating mode, you
1942 may specify one or more options. Different options will have different
1943 effects, but in general they all change details of the operation, such
1944 as archive format, archive name, or level of user interaction. Some
1945 options make sense with all operating modes, while others are
1946 meaningful only with particular modes. You will likely use some
1947 options frequently, while you will only use others infrequently, or
1948 not at all. (A full list of options is available in @pxref{All Options}.)
1949
1950 @vrindex TAR_OPTIONS, environment variable
1951 @anchor{TAR_OPTIONS}
1952 The @env{TAR_OPTIONS} environment variable specifies default options to
1953 be placed in front of any explicit options. For example, if
1954 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1955 if the two options @option{-v} and @option{--unlink-first} had been
1956 specified before any explicit options. Option specifications are
1957 separated by whitespace. A backslash escapes the next character, so it
1958 can be used to specify an option containing whitespace or a backslash.
1959
1960 Note that @command{tar} options are case sensitive. For example, the
1961 options @option{-T} and @option{-t} are different; the first requires an
1962 argument for stating the name of a file providing a list of @var{name}s,
1963 while the second does not require an argument and is another way to
1964 write @option{--list} (@option{-t}).
1965
1966 In addition to the eight operations, there are many options to
1967 @command{tar}, and three different styles for writing both: long (mnemonic)
1968 form, short form, and old style. These styles are discussed below.
1969 Both the options and the operations can be written in any of these three
1970 styles.
1971
1972 @FIXME{menu at end of this node. need to think of an actual outline
1973 for this chapter; probably do that after stuff from chapter 4 is
1974 incorporated.}
1975
1976 @node Styles
1977 @section The Three Option Styles
1978
1979 There are three styles for writing operations and options to the command
1980 line invoking @command{tar}. The different styles were developed at
1981 different times during the history of @command{tar}. These styles will be
1982 presented below, from the most recent to the oldest.
1983
1984 Some options must take an argument. (For example, @option{--file}
1985 (@option{-f})) takes the name of an archive file as an argument. If
1986 you do not supply an archive file name, @command{tar} will use a
1987 default, but this can be confusing; thus, we recommend that you always
1988 supply a specific archive file name.) Where you @emph{place} the
1989 arguments generally depends on which style of options you choose. We
1990 will detail specific information relevant to each option style in the
1991 sections on the different option styles, below. The differences are
1992 subtle, yet can often be very important; incorrect option placement
1993 can cause you to overwrite a number of important files. We urge you
1994 to note these differences, and only use the option style(s) which
1995 makes the most sense to you until you feel comfortable with the others.
1996
1997 Some options @emph{may} take an argument. Such options may have at
1998 most long and short forms, they do not have old style equivalent. The
1999 rules for specifying an argument for such options are stricter than
2000 those for specifying mandatory arguments. Please, pay special
2001 attention to them.
2002
2003 @menu
2004 * Long Options:: Long Option Style
2005 * Short Options:: Short Option Style
2006 * Old Options:: Old Option Style
2007 * Mixing:: Mixing Option Styles
2008 @end menu
2009
2010 @node Long Options
2011 @subsection Long Option Style
2012
2013 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2014 dashes in a row, e.g., @option{--list}. The long names are more clear than
2015 their corresponding short or old names. It sometimes happens that a
2016 single long option has many different names which are
2017 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2018 long option names can be given unique abbreviations. For example,
2019 @option{--cre} can be used in place of @option{--create} because there is no
2020 other long option which begins with @samp{cre}. (One way to find
2021 this out is by trying it and seeing what happens; if a particular
2022 abbreviation could represent more than one option, @command{tar} will tell
2023 you that that abbreviation is ambiguous and you'll know that that
2024 abbreviation won't work. You may also choose to run @samp{tar --help}
2025 to see a list of options. Be aware that if you run @command{tar} with a
2026 unique abbreviation for the long name of an option you didn't want to
2027 use, you are stuck; @command{tar} will perform the command as ordered.)
2028
2029 Long options are meant to be obvious and easy to remember, and their
2030 meanings are generally easier to discern than those of their
2031 corresponding short options (see below). For example:
2032
2033 @smallexample
2034 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2035 @end smallexample
2036
2037 @noindent
2038 gives a fairly good set of hints about what the command does, even
2039 for those not fully acquainted with @command{tar}.
2040
2041 Long options which require arguments take those arguments
2042 immediately following the option name. There are two ways of
2043 specifying a mandatory argument. It can be separated from the
2044 option name either by an equal sign, or by any amount of
2045 white space characters. For example, the @option{--file} option (which
2046 tells the name of the @command{tar} archive) is given a file such as
2047 @file{archive.tar} as argument by using any of the following notations:
2048 @option{--file=archive.tar} or @option{--file archive.tar}.
2049
2050 In contrast, optional arguments must always be introduced using
2051 an equal sign. For example, the @option{--backup} option takes
2052 an optional argument specifying backup type. It must be used
2053 as @option{--backup=@var{backup-type}}.
2054
2055 @node Short Options
2056 @subsection Short Option Style
2057
2058 Most options also have a @dfn{short option} name. Short options start with
2059 a single dash, and are followed by a single character, e.g., @option{-t}
2060 (which is equivalent to @option{--list}). The forms are absolutely
2061 identical in function; they are interchangeable.
2062
2063 The short option names are faster to type than long option names.
2064
2065 Short options which require arguments take their arguments immediately
2066 following the option, usually separated by white space. It is also
2067 possible to stick the argument right after the short option name, using
2068 no intervening space. For example, you might write @w{@option{-f
2069 archive.tar}} or @option{-farchive.tar} instead of using
2070 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2071 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2072 specific archive, here named @file{archive.tar}.
2073
2074 Short options which take optional arguments take their arguments
2075 immediately following the option letter, @emph{without any intervening
2076 white space characters}.
2077
2078 Short options' letters may be clumped together, but you are not
2079 required to do this (as compared to old options; see below). When
2080 short options are clumped as a set, use one (single) dash for them
2081 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2082 such a set is allowed to have an argument@footnote{Clustering many
2083 options, the last of which has an argument, is a rather opaque way to
2084 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2085 even be made helpful enough for considering such usages as invalid.}.
2086
2087 When the options are separated, the argument for each option which requires
2088 an argument directly follows that option, as is usual for Unix programs.
2089 For example:
2090
2091 @smallexample
2092 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2093 @end smallexample
2094
2095 If you reorder short options' locations, be sure to move any arguments
2096 that belong to them. If you do not move the arguments properly, you may
2097 end up overwriting files.
2098
2099 @node Old Options
2100 @subsection Old Option Style
2101 @UNREVISED
2102
2103 Like short options, @dfn{old options} are single letters. However, old options
2104 must be written together as a single clumped set, without spaces separating
2105 them or dashes preceding them@footnote{Beware that if you precede options
2106 with a dash, you are announcing the short option style instead of the
2107 old option style; short options are decoded differently.}. This set
2108 of letters must be the first to appear on the command line, after the
2109 @command{tar} program name and some white space; old options cannot appear
2110 anywhere else. The letter of an old option is exactly the same letter as
2111 the corresponding short option. For example, the old option @samp{t} is
2112 the same as the short option @option{-t}, and consequently, the same as the
2113 long option @option{--list}. So for example, the command @w{@samp{tar
2114 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2115
2116 When options that need arguments are given together with the command,
2117 all the associated arguments follow, in the same order as the options.
2118 Thus, the example given previously could also be written in the old
2119 style as follows:
2120
2121 @smallexample
2122 $ @kbd{tar cvbf 20 /dev/rmt0}
2123 @end smallexample
2124
2125 @noindent
2126 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2127 the argument of @option{-f}.
2128
2129 On the other hand, this old style syntax makes it difficult to match
2130 option letters with their corresponding arguments, and is often
2131 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2132 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2133 argument for @option{-f}, and @option{-v} does not have a corresponding
2134 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2135 /dev/rmt0}} is clearer, putting all arguments next to the option they
2136 pertain to.
2137
2138 If you want to reorder the letters in the old option argument, be
2139 sure to reorder any corresponding argument appropriately.
2140
2141 This old way of writing @command{tar} options can surprise even experienced
2142 users. For example, the two commands:
2143
2144 @smallexample
2145 @kbd{tar cfz archive.tar.gz file}
2146 @kbd{tar -cfz archive.tar.gz file}
2147 @end smallexample
2148
2149 @noindent
2150 are quite different. The first example uses @file{archive.tar.gz} as
2151 the value for option @samp{f} and recognizes the option @samp{z}. The
2152 second example, however, uses @file{z} as the value for option
2153 @samp{f} --- probably not what was intended.
2154
2155 Old options are kept for compatibility with old versions of @command{tar}.
2156
2157 This second example could be corrected in many ways, among which the
2158 following are equivalent:
2159
2160 @smallexample
2161 @kbd{tar -czf archive.tar.gz file}
2162 @kbd{tar -cf archive.tar.gz -z file}
2163 @kbd{tar cf archive.tar.gz -z file}
2164 @end smallexample
2165
2166 @cindex option syntax, traditional
2167 As far as we know, all @command{tar} programs, @acronym{GNU} and
2168 non-@acronym{GNU}, support old options. @GNUTAR{}
2169 supports them not only for historical reasons, but also because many
2170 people are used to them. For compatibility with Unix @command{tar},
2171 the first argument is always treated as containing command and option
2172 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2173 equivalent to @w{@samp{tar -c}:} both of them specify the
2174 @option{--create} (@option{-c}) command to create an archive.
2175
2176 @node Mixing
2177 @subsection Mixing Option Styles
2178
2179 All three styles may be intermixed in a single @command{tar} command,
2180 so long as the rules for each style are fully
2181 respected@footnote{Before @GNUTAR{} version 1.11.6,
2182 a bug prevented intermixing old style options with long options in
2183 some cases.}. Old style options and either of the modern styles of
2184 options may be mixed within a single @command{tar} command. However,
2185 old style options must be introduced as the first arguments only,
2186 following the rule for old options (old options must appear directly
2187 after the @command{tar} command and some white space). Modern options
2188 may be given only after all arguments to the old options have been
2189 collected. If this rule is not respected, a modern option might be
2190 falsely interpreted as the value of the argument to one of the old
2191 style options.
2192
2193 For example, all the following commands are wholly equivalent, and
2194 illustrate the many combinations and orderings of option styles.
2195
2196 @smallexample
2197 @kbd{tar --create --file=archive.tar}
2198 @kbd{tar --create -f archive.tar}
2199 @kbd{tar --create -farchive.tar}
2200 @kbd{tar --file=archive.tar --create}
2201 @kbd{tar --file=archive.tar -c}
2202 @kbd{tar -c --file=archive.tar}
2203 @kbd{tar -c -f archive.tar}
2204 @kbd{tar -c -farchive.tar}
2205 @kbd{tar -cf archive.tar}
2206 @kbd{tar -cfarchive.tar}
2207 @kbd{tar -f archive.tar --create}
2208 @kbd{tar -f archive.tar -c}
2209 @kbd{tar -farchive.tar --create}
2210 @kbd{tar -farchive.tar -c}
2211 @kbd{tar c --file=archive.tar}
2212 @kbd{tar c -f archive.tar}
2213 @kbd{tar c -farchive.tar}
2214 @kbd{tar cf archive.tar}
2215 @kbd{tar f archive.tar --create}
2216 @kbd{tar f archive.tar -c}
2217 @kbd{tar fc archive.tar}
2218 @end smallexample
2219
2220 On the other hand, the following commands are @emph{not} equivalent to
2221 the previous set:
2222
2223 @smallexample
2224 @kbd{tar -f -c archive.tar}
2225 @kbd{tar -fc archive.tar}
2226 @kbd{tar -fcarchive.tar}
2227 @kbd{tar -farchive.tarc}
2228 @kbd{tar cfarchive.tar}
2229 @end smallexample
2230
2231 @noindent
2232 These last examples mean something completely different from what the
2233 user intended (judging based on the example in the previous set which
2234 uses long options, whose intent is therefore very clear). The first
2235 four specify that the @command{tar} archive would be a file named
2236 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2237 respectively. The first two examples also specify a single non-option,
2238 @var{name} argument having the value @samp{archive.tar}. The last
2239 example contains only old style option letters (repeating option
2240 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2241 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2242 the first sentence of this paragraph..}
2243
2244 @node All Options
2245 @section All @command{tar} Options
2246
2247 The coming manual sections contain an alphabetical listing of all
2248 @command{tar} operations and options, with brief descriptions and cross
2249 references to more in-depth explanations in the body of the manual.
2250 They also contain an alphabetically arranged table of the short option
2251 forms with their corresponding long option. You can use this table as
2252 a reference for deciphering @command{tar} commands in scripts.
2253
2254 @menu
2255 * Operation Summary::
2256 * Option Summary::
2257 * Short Option Summary::
2258 @end menu
2259
2260 @node Operation Summary
2261 @subsection Operations
2262
2263 @table @option
2264
2265 @opsummary{append}
2266 @item --append
2267 @itemx -r
2268
2269 Appends files to the end of the archive. @xref{append}.
2270
2271 @opsummary{catenate}
2272 @item --catenate
2273 @itemx -A
2274
2275 Same as @option{--concatenate}. @xref{concatenate}.
2276
2277 @opsummary{compare}
2278 @item --compare
2279 @itemx -d
2280
2281 Compares archive members with their counterparts in the file
2282 system, and reports differences in file size, mode, owner,
2283 modification date and contents. @xref{compare}.
2284
2285 @opsummary{concatenate}
2286 @item --concatenate
2287 @itemx -A
2288
2289 Appends other @command{tar} archives to the end of the archive.
2290 @xref{concatenate}.
2291
2292 @opsummary{create}
2293 @item --create
2294 @itemx -c
2295
2296 Creates a new @command{tar} archive. @xref{create}.
2297
2298 @opsummary{delete}
2299 @item --delete
2300
2301 Deletes members from the archive. Don't try this on a archive on a
2302 tape! @xref{delete}.
2303
2304 @opsummary{diff}
2305 @item --diff
2306 @itemx -d
2307
2308 Same @option{--compare}. @xref{compare}.
2309
2310 @opsummary{extract}
2311 @item --extract
2312 @itemx -x
2313
2314 Extracts members from the archive into the file system. @xref{extract}.
2315
2316 @opsummary{get}
2317 @item --get
2318 @itemx -x
2319
2320 Same as @option{--extract}. @xref{extract}.
2321
2322 @opsummary{list}
2323 @item --list
2324 @itemx -t
2325
2326 Lists the members in an archive. @xref{list}.
2327
2328 @opsummary{update}
2329 @item --update
2330 @itemx -u
2331
2332 Adds files to the end of the archive, but only if they are newer than
2333 their counterparts already in the archive, or if they do not already
2334 exist in the archive. @xref{update}.
2335
2336 @end table
2337
2338 @node Option Summary
2339 @subsection @command{tar} Options
2340
2341 @table @option
2342
2343 @opsummary{absolute-names}
2344 @item --absolute-names
2345 @itemx -P
2346
2347 Normally when creating an archive, @command{tar} strips an initial
2348 @samp{/} from member names. This option disables that behavior.
2349 @xref{absolute}.
2350
2351 @opsummary{after-date}
2352 @item --after-date
2353
2354 (See @option{--newer}, @pxref{after})
2355
2356 @opsummary{anchored}
2357 @item --anchored
2358 A pattern must match an initial subsequence of the name's components.
2359 @xref{controlling pattern-matching}.
2360
2361 @opsummary{atime-preserve}
2362 @item --atime-preserve
2363 @itemx --atime-preserve=replace
2364 @itemx --atime-preserve=system
2365
2366 Attempt to preserve the access time of files when reading them. This
2367 option currently is effective only on files that you own, unless you
2368 have superuser privileges.
2369
2370 @option{--atime-preserve=replace} remembers the access time of a file
2371 before reading it, and then restores the access time afterwards. This
2372 may cause problems if other programs are reading the file at the same
2373 time, as the times of their accesses will be lost. On most platforms
2374 restoring the access time also requires @command{tar} to restore the
2375 data modification time too, so this option may also cause problems if
2376 other programs are writing the file at the same time. (Tar attempts
2377 to detect this situation, but cannot do so reliably due to race
2378 conditions.) Worse, on most platforms restoring the access time also
2379 updates the status change time, which means that this option is
2380 incompatible with incremental backups.
2381
2382 @option{--atime-preserve=system} avoids changing time stamps on files,
2383 without interfering with time stamp updates
2384 caused by other programs, so it works better with incremental backups.
2385 However, it requires a special @code{O_NOATIME} option from the
2386 underlying operating and file system implementation, and it also requires
2387 that searching directories does not update their access times. As of
2388 this writing (November 2005) this works only with Linux, and only with
2389 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2390 way to know whether this feature actually works. Sometimes
2391 @command{tar} knows that it does not work, and if you use
2392 @option{--atime-preserve=system} then @command{tar} complains and
2393 exits right away. But other times @command{tar} might think that the
2394 option works when it actually does not.
2395
2396 Currently @option{--atime-preserve} with no operand defaults to
2397 @option{--atime-preserve=replace}, but this may change in the future
2398 as support for @option{--atime-preserve=system} improves.
2399
2400 If your operating system does not support
2401 @option{--atime-preserve=@-system}, you might be able to preserve access
2402 times reliably by by using the @command{mount} command. For example,
2403 you can mount the file system read-only, or access the file system via
2404 a read-only loopback mount, or use the @samp{noatime} mount option
2405 available on some systems. However, mounting typically requires
2406 superuser privileges and can be a pain to manage.
2407
2408 @opsummary{auto-compress}
2409 @item --auto-compress
2410 @itemx -a
2411
2412 During a @option{--create} operation, enables automatic compressed
2413 format recognition based on the archive suffix. @xref{gzip}.
2414
2415 @opsummary{backup}
2416 @item --backup=@var{backup-type}
2417
2418 Rather than deleting files from the file system, @command{tar} will
2419 back them up using simple or numbered backups, depending upon
2420 @var{backup-type}. @xref{backup}.
2421
2422 @opsummary{block-number}
2423 @item --block-number
2424 @itemx -R
2425
2426 With this option present, @command{tar} prints error messages for read errors
2427 with the block number in the archive file. @xref{block-number}.
2428
2429 @opsummary{blocking-factor}
2430 @item --blocking-factor=@var{blocking}
2431 @itemx -b @var{blocking}
2432
2433 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2434 record. @xref{Blocking Factor}.
2435
2436 @opsummary{bzip2}
2437 @item --bzip2
2438 @itemx -j
2439
2440 This option tells @command{tar} to read or write archives through
2441 @code{bzip2}. @xref{gzip}.
2442
2443 @opsummary{checkpoint}
2444 @item --checkpoint[=@var{number}]
2445
2446 This option directs @command{tar} to print periodic checkpoint
2447 messages as it reads through the archive. It is intended for when you
2448 want a visual indication that @command{tar} is still running, but
2449 don't want to see @option{--verbose} output. You can also instruct
2450 @command{tar} to execute a list of actions on each checkpoint, see
2451 @option{--checklist-action} below. For a detailed description, see
2452 @ref{checkpoints}.
2453
2454 @opsummary{checkpoint-action}
2455 @item --checkpoint-action=@var{action}
2456 Instruct @command{tar} to execute an action upon hitting a
2457 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2458 for a complete description.
2459
2460 The @var{action} argument can be one of the following:
2461
2462 @table @asis
2463 @item bell
2464 Produce an audible bell on the console.
2465
2466 @item dot
2467 @itemx .
2468 Print a single dot on the standard listing stream.
2469
2470 @item echo
2471 Display a textual message on the standard error, with the status and
2472 number of the checkpoint. This is the default.
2473
2474 @item echo=@var{string}
2475 Display @var{string} on the standard error. Before output, the string
2476 is subject to meta-character expansion.
2477
2478 @item exec=@var{command}
2479 Execute the given @var{command}.
2480
2481 @item sleep=@var{time}
2482 Wait for @var{time} seconds.
2483
2484 @item ttyout=@var{string}
2485 Output @var{string} on the current console (@file{/dev/tty}).
2486 @end table
2487
2488 Several @option{--checkpoint-action} options can be specified. The
2489 supplied actions will be executed in order of their appearance in the
2490 command line.
2491
2492 Using @option{--checkpoint-action} without @option{--checkpoint}
2493 assumes default checkpoint frequency of one checkpoint per 10 records.
2494
2495 @opsummary{check-links}
2496 @item --check-links
2497 @itemx -l
2498 If this option was given, @command{tar} will check the number of links
2499 dumped for each processed file. If this number does not match the
2500 total number of hard links for the file, a warning message will be
2501 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2502 synonym for @option{--one-file-system}. The current semantics, which
2503 complies to UNIX98, was introduced with version
2504 1.15.91. @xref{Changes}, for more information.}.
2505
2506 @xref{hard links}.
2507
2508 @opsummary{compress}
2509 @opsummary{uncompress}
2510 @item --compress
2511 @itemx --uncompress
2512 @itemx -Z
2513
2514 @command{tar} will use the @command{compress} program when reading or
2515 writing the archive. This allows you to directly act on archives
2516 while saving space. @xref{gzip}.
2517
2518 @opsummary{confirmation}
2519 @item --confirmation
2520
2521 (See @option{--interactive}.) @xref{interactive}.
2522
2523 @opsummary{delay-directory-restore}
2524 @item --delay-directory-restore
2525
2526 Delay setting modification times and permissions of extracted
2527 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2528
2529 @opsummary{dereference}
2530 @item --dereference
2531 @itemx -h
2532
2533 When creating a @command{tar} archive, @command{tar} will archive the
2534 file that a symbolic link points to, rather than archiving the
2535 symlink. @xref{dereference}.
2536
2537 @opsummary{directory}
2538 @item --directory=@var{dir}
2539 @itemx -C @var{dir}
2540
2541 When this option is specified, @command{tar} will change its current directory
2542 to @var{dir} before performing any operations. When this option is used
2543 during archive creation, it is order sensitive. @xref{directory}.
2544
2545 @opsummary{exclude}
2546 @item --exclude=@var{pattern}
2547
2548 When performing operations, @command{tar} will skip files that match
2549 @var{pattern}. @xref{exclude}.
2550
2551 @opsummary{exclude-from}
2552 @item --exclude-from=@var{file}
2553 @itemx -X @var{file}
2554
2555 Similar to @option{--exclude}, except @command{tar} will use the list of
2556 patterns in the file @var{file}. @xref{exclude}.
2557
2558 @opsummary{exclude-caches}
2559 @item --exclude-caches
2560
2561 Exclude from dump any directory containing a valid cache directory
2562 tag file, but still dump the directory node and the tag file itself.
2563
2564 @xref{exclude}.
2565
2566 @opsummary{exclude-caches-under}
2567 @item --exclude-caches-under
2568
2569 Exclude from dump any directory containing a valid cache directory
2570 tag file, but still dump the directory node itself.
2571
2572 @xref{exclude}.
2573
2574 @opsummary{exclude-caches-all}
2575 @item --exclude-caches-all
2576
2577 Exclude from dump any directory containing a valid cache directory
2578 tag file. @xref{exclude}.
2579
2580 @opsummary{exclude-tag}
2581 @item --exclude-tag=@var{file}
2582
2583 Exclude from dump any directory containing file named @var{file}, but
2584 dump the directory node and @var{file} itself. @xref{exclude}.
2585
2586 @opsummary{exclude-tag-under}
2587 @item --exclude-tag-under=@var{file}
2588
2589 Exclude from dump the contents of any directory containing file
2590 named @var{file}, but dump the directory node itself. @xref{exclude}.
2591
2592 @opsummary{exclude-tag-all}
2593 @item --exclude-tag-all=@var{file}
2594
2595 Exclude from dump any directory containing file named @var{file}.
2596 @xref{exclude}.
2597
2598 @opsummary{exclude-vcs}
2599 @item --exclude-vcs
2600
2601 Exclude from dump directories and files, that are internal for some
2602 widely used version control systems.
2603
2604 @xref{exclude}.
2605
2606 @opsummary{file}
2607 @item --file=@var{archive}
2608 @itemx -f @var{archive}
2609
2610 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2611 performs operations on, rather than @command{tar}'s compilation dependent
2612 default. @xref{file tutorial}.
2613
2614 @opsummary{files-from}
2615 @item --files-from=@var{file}
2616 @itemx -T @var{file}
2617
2618 @command{tar} will use the contents of @var{file} as a list of archive members
2619 or files to operate on, in addition to those specified on the
2620 command-line. @xref{files}.
2621
2622 @opsummary{force-local}
2623 @item --force-local
2624
2625 Forces @command{tar} to interpret the file name given to @option{--file}
2626 as a local file, even if it looks like a remote tape drive name.
2627 @xref{local and remote archives}.
2628
2629 @opsummary{format}
2630 @item --format=@var{format}
2631 @itemx -H @var{format}
2632
2633 Selects output archive format. @var{Format} may be one of the
2634 following:
2635
2636 @table @samp
2637 @item v7
2638 Creates an archive that is compatible with Unix V7 @command{tar}.
2639
2640 @item oldgnu
2641 Creates an archive that is compatible with GNU @command{tar} version
2642 1.12 or earlier.
2643
2644 @item gnu
2645 Creates archive in GNU tar 1.13 format. Basically it is the same as
2646 @samp{oldgnu} with the only difference in the way it handles long
2647 numeric fields.
2648
2649 @item ustar
2650 Creates a @acronym{POSIX.1-1988} compatible archive.
2651
2652 @item posix
2653 Creates a @acronym{POSIX.1-2001 archive}.
2654
2655 @end table
2656
2657 @xref{Formats}, for a detailed discussion of these formats.
2658
2659 @opsummary{group}
2660 @item --group=@var{group}
2661
2662 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2663 rather than the group from the source file. @var{group} is first decoded
2664 as a group symbolic name, but if this interpretation fails, it has to be
2665 a decimal numeric group @acronym{ID}. @xref{override}.
2666
2667 Also see the comments for the @option{--owner=@var{user}} option.
2668
2669 @opsummary{gzip}
2670 @opsummary{gunzip}
2671 @opsummary{ungzip}
2672 @item --gzip
2673 @itemx --gunzip
2674 @itemx --ungzip
2675 @itemx -z
2676
2677 This option tells @command{tar} to read or write archives through
2678 @command{gzip}, allowing @command{tar} to directly operate on several
2679 kinds of compressed archives transparently. @xref{gzip}.
2680
2681 @opsummary{hard-dereference}
2682 @item --hard-dereference
2683 When creating an archive, dereference hard links and store the files
2684 they refer to, instead of creating usual hard link members.
2685
2686 @xref{hard links}.
2687
2688 @opsummary{help}
2689 @item --help
2690 @itemx -?
2691
2692 @command{tar} will print out a short message summarizing the operations and
2693 options to @command{tar} and exit. @xref{help}.
2694
2695 @opsummary{ignore-case}
2696 @item --ignore-case
2697 Ignore case when matching member or file names with
2698 patterns. @xref{controlling pattern-matching}.
2699
2700 @opsummary{ignore-command-error}
2701 @item --ignore-command-error
2702 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2703
2704 @opsummary{ignore-failed-read}
2705 @item --ignore-failed-read
2706
2707 Do not exit unsuccessfully merely because an unreadable file was encountered.
2708 @xref{Reading}.
2709
2710 @opsummary{ignore-zeros}
2711 @item --ignore-zeros
2712 @itemx -i
2713
2714 With this option, @command{tar} will ignore zeroed blocks in the
2715 archive, which normally signals EOF. @xref{Reading}.
2716
2717 @opsummary{incremental}
2718 @item --incremental
2719 @itemx -G
2720
2721 Informs @command{tar} that it is working with an old
2722 @acronym{GNU}-format incremental backup archive. It is intended
2723 primarily for backwards compatibility only. @xref{Incremental Dumps},
2724 for a detailed discussion of incremental archives.
2725
2726 @opsummary{index-file}
2727 @item --index-file=@var{file}
2728
2729 Send verbose output to @var{file} instead of to standard output.
2730
2731 @opsummary{info-script}
2732 @opsummary{new-volume-script}
2733 @item --info-script=@var{script-file}
2734 @itemx --new-volume-script=@var{script-file}
2735 @itemx -F @var{script-file}
2736
2737 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2738 at the end of each tape. If @var{script-file} exits with nonzero status,
2739 @command{tar} fails immediately. @xref{info-script}, for a detailed
2740 discussion of @var{script-file}.
2741
2742 @opsummary{interactive}
2743 @item --interactive
2744 @itemx --confirmation
2745 @itemx -w
2746
2747 Specifies that @command{tar} should ask the user for confirmation before
2748 performing potentially destructive options, such as overwriting files.
2749 @xref{interactive}.
2750
2751 @opsummary{keep-newer-files}
2752 @item --keep-newer-files
2753
2754 Do not replace existing files that are newer than their archive copies
2755 when extracting files from an archive.
2756
2757 @opsummary{keep-old-files}
2758 @item --keep-old-files
2759 @itemx -k
2760
2761 Do not overwrite existing files when extracting files from an archive.
2762 @xref{Keep Old Files}.
2763
2764 @opsummary{label}
2765 @item --label=@var{name}
2766 @itemx -V @var{name}
2767
2768 When creating an archive, instructs @command{tar} to write @var{name}
2769 as a name record in the archive. When extracting or listing archives,
2770 @command{tar} will only operate on archives that have a label matching
2771 the pattern specified in @var{name}. @xref{Tape Files}.
2772
2773 @opsummary{listed-incremental}
2774 @item --listed-incremental=@var{snapshot-file}
2775 @itemx -g @var{snapshot-file}
2776
2777 During a @option{--create} operation, specifies that the archive that
2778 @command{tar} creates is a new @acronym{GNU}-format incremental
2779 backup, using @var{snapshot-file} to determine which files to backup.
2780 With other operations, informs @command{tar} that the archive is in
2781 incremental format. @xref{Incremental Dumps}.
2782
2783 @opsummary{lzma}
2784 @item --lzma
2785
2786 This option tells @command{tar} to read or write archives through
2787 @command{lzma}. @xref{gzip}.
2788
2789 @opsummary{mode}
2790 @item --mode=@var{permissions}
2791
2792 When adding files to an archive, @command{tar} will use
2793 @var{permissions} for the archive members, rather than the permissions
2794 from the files. @var{permissions} can be specified either as an octal
2795 number or as symbolic permissions, like with
2796 @command{chmod}. @xref{override}.
2797
2798 @opsummary{mtime}
2799 @item --mtime=@var{date}
2800
2801 When adding files to an archive, @command{tar} will use @var{date} as
2802 the modification time of members when creating archives, instead of
2803 their actual modification times. The value of @var{date} can be
2804 either a textual date representation (@pxref{Date input formats}) or a
2805 name of the existing file, starting with @samp{/} or @samp{.}. In the
2806 latter case, the modification time of that file is used. @xref{override}.
2807
2808 @opsummary{multi-volume}
2809 @item --multi-volume
2810 @itemx -M
2811
2812 Informs @command{tar} that it should create or otherwise operate on a
2813 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2814
2815 @opsummary{new-volume-script}
2816 @item --new-volume-script
2817
2818 (see --info-script)
2819
2820 @opsummary{newer}
2821 @item --newer=@var{date}
2822 @itemx --after-date=@var{date}
2823 @itemx -N
2824
2825 When creating an archive, @command{tar} will only add files that have changed
2826 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2827 is taken to be the name of a file whose data modification time specifies
2828 the date. @xref{after}.
2829
2830 @opsummary{newer-mtime}
2831 @item --newer-mtime=@var{date}
2832
2833 Like @option{--newer}, but add only files whose
2834 contents have changed (as opposed to just @option{--newer}, which will
2835 also back up files for which any status information has
2836 changed). @xref{after}.
2837
2838 @opsummary{no-anchored}
2839 @item --no-anchored
2840 An exclude pattern can match any subsequence of the name's components.
2841 @xref{controlling pattern-matching}.
2842
2843 @opsummary{no-delay-directory-restore}
2844 @item --no-delay-directory-restore
2845
2846 Modification times and permissions of extracted
2847 directories are set when all files from this directory have been
2848 extracted. This is the default.
2849 @xref{Directory Modification Times and Permissions}.
2850
2851 @opsummary{no-ignore-case}
2852 @item --no-ignore-case
2853 Use case-sensitive matching.
2854 @xref{controlling pattern-matching}.
2855
2856 @opsummary{no-ignore-command-error}
2857 @item --no-ignore-command-error
2858 Print warnings about subprocesses that terminated with a nonzero exit
2859 code. @xref{Writing to an External Program}.
2860
2861 @opsummary{no-overwrite-dir}
2862 @item --no-overwrite-dir
2863
2864 Preserve metadata of existing directories when extracting files
2865 from an archive. @xref{Overwrite Old Files}.
2866
2867 @opsummary{no-quote-chars}
2868 @item --no-quote-chars=@var{string}
2869 Remove characters listed in @var{string} from the list of quoted
2870 characters set by the previous @option{--quote-chars} option
2871 (@pxref{quoting styles}).
2872
2873 @opsummary{no-recursion}
2874 @item --no-recursion
2875
2876 With this option, @command{tar} will not recurse into directories.
2877 @xref{recurse}.
2878
2879 @opsummary{no-same-owner}
2880 @item --no-same-owner
2881 @itemx -o
2882
2883 When extracting an archive, do not attempt to preserve the owner
2884 specified in the @command{tar} archive. This the default behavior
2885 for ordinary users.
2886
2887 @opsummary{no-same-permissions}
2888 @item --no-same-permissions
2889
2890 When extracting an archive, subtract the user's umask from files from
2891 the permissions specified in the archive. This is the default behavior
2892 for ordinary users.
2893
2894 @opsummary{no-unquote}
2895 @item --no-unquote
2896 Treat all input file or member names literally, do not interpret
2897 escape sequences. @xref{input name quoting}.
2898
2899 @opsummary{no-wildcards}
2900 @item --no-wildcards
2901 Do not use wildcards.
2902 @xref{controlling pattern-matching}.
2903
2904 @opsummary{no-wildcards-match-slash}
2905 @item --no-wildcards-match-slash
2906 Wildcards do not match @samp{/}.
2907 @xref{controlling pattern-matching}.
2908
2909 @opsummary{null}
2910 @item --null
2911
2912 When @command{tar} is using the @option{--files-from} option, this option
2913 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
2914 @command{tar} can correctly work with file names that contain newlines.
2915 @xref{nul}.
2916
2917 @opsummary{numeric-owner}
2918 @item --numeric-owner
2919
2920 This option will notify @command{tar} that it should use numeric user
2921 and group IDs when creating a @command{tar} file, rather than names.
2922 @xref{Attributes}.
2923
2924 @item -o
2925 The function of this option depends on the action @command{tar} is
2926 performing. When extracting files, @option{-o} is a synonym for
2927 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2928 restoring ownership of files being extracted.
2929
2930 When creating an archive, it is a synonym for
2931 @option{--old-archive}. This behavior is for compatibility
2932 with previous versions of @GNUTAR{}, and will be
2933 removed in future releases.
2934
2935 @xref{Changes}, for more information.
2936
2937 @opsummary{occurrence}
2938 @item --occurrence[=@var{number}]
2939
2940 This option can be used in conjunction with one of the subcommands
2941 @option{--delete}, @option{--diff}, @option{--extract} or
2942 @option{--list} when a list of files is given either on the command
2943 line or via @option{-T} option.
2944
2945 This option instructs @command{tar} to process only the @var{number}th
2946 occurrence of each named file. @var{Number} defaults to 1, so
2947
2948 @smallexample
2949 tar -x -f archive.tar --occurrence filename
2950 @end smallexample
2951
2952 @noindent
2953 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2954 and will terminate without scanning to the end of the archive.
2955
2956 @opsummary{old-archive}
2957 @item --old-archive
2958 Synonym for @option{--format=v7}.
2959
2960 @opsummary{one-file-system}
2961 @item --one-file-system
2962 Used when creating an archive. Prevents @command{tar} from recursing into
2963 directories that are on different file systems from the current
2964 directory.
2965
2966 @opsummary{overwrite}
2967 @item --overwrite
2968
2969 Overwrite existing files and directory metadata when extracting files
2970 from an archive. @xref{Overwrite Old Files}.
2971
2972 @opsummary{overwrite-dir}
2973 @item --overwrite-dir
2974
2975 Overwrite the metadata of existing directories when extracting files
2976 from an archive. @xref{Overwrite Old Files}.
2977
2978 @opsummary{owner}
2979 @item --owner=@var{user}
2980
2981 Specifies that @command{tar} should use @var{user} as the owner of members
2982 when creating archives, instead of the user associated with the source
2983 file. @var{user} is first decoded as a user symbolic name, but if
2984 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
2985 @xref{override}.
2986
2987 This option does not affect extraction from archives.
2988
2989 @opsummary{pax-option}
2990 @item --pax-option=@var{keyword-list}
2991 This option is meaningful only with @acronym{POSIX.1-2001} archives
2992 (@pxref{posix}). It modifies the way @command{tar} handles the
2993 extended header keywords. @var{Keyword-list} is a comma-separated
2994 list of keyword options. @xref{PAX keywords}, for a detailed
2995 discussion.
2996
2997 @opsummary{portability}
2998 @item --portability
2999 @itemx --old-archive
3000 Synonym for @option{--format=v7}.
3001
3002 @opsummary{posix}
3003 @item --posix
3004 Same as @option{--format=posix}.
3005
3006 @opsummary{preserve}
3007 @item --preserve
3008
3009 Synonymous with specifying both @option{--preserve-permissions} and
3010 @option{--same-order}. @xref{Setting Access Permissions}.
3011
3012 @opsummary{preserve-order}
3013 @item --preserve-order
3014
3015 (See @option{--same-order}; @pxref{Reading}.)
3016
3017 @opsummary{preserve-permissions}
3018 @opsummary{same-permissions}
3019 @item --preserve-permissions
3020 @itemx --same-permissions
3021 @itemx -p
3022
3023 When @command{tar} is extracting an archive, it normally subtracts the
3024 users' umask from the permissions specified in the archive and uses
3025 that number as the permissions to create the destination file.
3026 Specifying this option instructs @command{tar} that it should use the
3027 permissions directly from the archive. @xref{Setting Access Permissions}.
3028
3029 @opsummary{quote-chars}
3030 @item --quote-chars=@var{string}
3031 Always quote characters from @var{string}, even if the selected
3032 quoting style would not quote them (@pxref{quoting styles}).
3033
3034 @opsummary{quoting-style}
3035 @item --quoting-style=@var{style}
3036 Set quoting style to use when printing member and file names
3037 (@pxref{quoting styles}). Valid @var{style} values are:
3038 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3039 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3040 style is @code{escape}, unless overridden while configuring the
3041 package.
3042
3043 @opsummary{read-full-records}
3044 @item --read-full-records
3045 @itemx -B
3046
3047 Specifies that @command{tar} should reblock its input, for reading
3048 from pipes on systems with buggy implementations. @xref{Reading}.
3049
3050 @opsummary{record-size}
3051 @item --record-size=@var{size}
3052
3053 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3054 archive. @xref{Blocking Factor}.
3055
3056 @opsummary{recursion}
3057 @item --recursion
3058
3059 With this option, @command{tar} recurses into directories (default).
3060 @xref{recurse}.
3061
3062 @opsummary{recursive-unlink}
3063 @item --recursive-unlink
3064
3065 Remove existing
3066 directory hierarchies before extracting directories of the same name
3067 from the archive. @xref{Recursive Unlink}.
3068
3069 @opsummary{remove-files}
3070 @item --remove-files
3071
3072 Directs @command{tar} to remove the source file from the file system after
3073 appending it to an archive. @xref{remove files}.
3074
3075 @opsummary{restrict}
3076 @item --restrict
3077
3078 Disable use of some potentially harmful @command{tar} options.
3079 Currently this option disables shell invocation from multi-volume menu
3080 (@pxref{Using Multiple Tapes}).
3081
3082 @opsummary{rmt-command}
3083 @item --rmt-command=@var{cmd}
3084
3085 Notifies @command{tar} that it should use @var{cmd} instead of
3086 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3087
3088 @opsummary{rsh-command}
3089 @item --rsh-command=@var{cmd}
3090
3091 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3092 devices. @xref{Device}.
3093
3094 @opsummary{same-order}
3095 @item --same-order
3096 @itemx --preserve-order
3097 @itemx -s
3098
3099 This option is an optimization for @command{tar} when running on machines with
3100 small amounts of memory. It informs @command{tar} that the list of file
3101 arguments has already been sorted to match the order of files in the
3102 archive. @xref{Reading}.
3103
3104 @opsummary{same-owner}
3105 @item --same-owner
3106
3107 When extracting an archive, @command{tar} will attempt to preserve the owner
3108 specified in the @command{tar} archive with this option present.
3109 This is the default behavior for the superuser; this option has an
3110 effect only for ordinary users. @xref{Attributes}.
3111
3112 @opsummary{same-permissions}
3113 @item --same-permissions
3114
3115 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3116
3117 @opsummary{seek}
3118 @item --seek
3119 @itemx -n
3120
3121 Assume that the archive media supports seeks to arbitrary
3122 locations. Usually @command{tar} determines automatically whether
3123 the archive can be seeked or not. This option is intended for use
3124 in cases when such recognition fails.
3125
3126 @opsummary{show-defaults}
3127 @item --show-defaults
3128
3129 Displays the default options used by @command{tar} and exits
3130 successfully. This option is intended for use in shell scripts.
3131 Here is an example of what you can see using this option:
3132
3133 @smallexample
3134 $ tar --show-defaults
3135 --format=gnu -f- -b20 --quoting-style=escape \
3136 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3137 @end smallexample
3138
3139 @opsummary{show-omitted-dirs}
3140 @item --show-omitted-dirs
3141
3142 Instructs @command{tar} to mention the directories it is skipping when
3143 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3144
3145 @opsummary{show-transformed-names}
3146 @opsummary{show-stored-names}
3147 @item --show-transformed-names
3148 @itemx --show-stored-names
3149
3150 Display file or member names after applying any transformations
3151 (@pxref{transform}). In particular, when used in conjunction with one of
3152 the archive creation operations it instructs @command{tar} to list the
3153 member names stored in the archive, as opposed to the actual file
3154 names. @xref{listing member and file names}.
3155
3156 @opsummary{sparse}
3157 @item --sparse
3158 @itemx -S
3159
3160 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3161 sparse files efficiently. @xref{sparse}.
3162
3163 @opsummary{sparse-version}
3164 @item --sparse-version=@var{version}
3165
3166 Specifies the @dfn{format version} to use when archiving sparse
3167 files. Implies @option{--sparse}. @xref{sparse}. For the description
3168 of the supported sparse formats, @xref{Sparse Formats}.
3169
3170 @opsummary{starting-file}
3171 @item --starting-file=@var{name}
3172 @itemx -K @var{name}
3173
3174 This option affects extraction only; @command{tar} will skip extracting
3175 files in the archive until it finds one that matches @var{name}.
3176 @xref{Scarce}.
3177
3178 @opsummary{strip-components}
3179 @item --strip-components=@var{number}
3180 Strip given @var{number} of leading components from file names before
3181 extraction. For example, if archive @file{archive.tar} contained
3182 @file{/some/file/name}, then running
3183
3184 @smallexample
3185 tar --extract --file archive.tar --strip-components=2
3186 @end smallexample
3187
3188 @noindent
3189 would extract this file to file @file{name}.
3190
3191 @opsummary{suffix}, summary
3192 @item --suffix=@var{suffix}
3193
3194 Alters the suffix @command{tar} uses when backing up files from the default
3195 @samp{~}. @xref{backup}.
3196
3197 @opsummary{tape-length}
3198 @item --tape-length=@var{num}
3199 @itemx -L @var{num}
3200
3201 Specifies the length of tapes that @command{tar} is writing as being
3202 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3203
3204 @opsummary{test-label}
3205 @item --test-label
3206
3207 Reads the volume label. If an argument is specified, test whether it
3208 matches the volume label. @xref{--test-label option}.
3209
3210 @opsummary{to-command}
3211 @item --to-command=@var{command}
3212
3213 During extraction @command{tar} will pipe extracted files to the
3214 standard input of @var{command}. @xref{Writing to an External Program}.
3215
3216 @opsummary{to-stdout}
3217 @item --to-stdout
3218 @itemx -O
3219
3220 During extraction, @command{tar} will extract files to stdout rather
3221 than to the file system. @xref{Writing to Standard Output}.
3222
3223 @opsummary{totals}
3224 @item --totals[=@var{signo}]
3225
3226 Displays the total number of bytes transferred when processing an
3227 archive. If an argument is given, these data are displayed on
3228 request, when signal @var{signo} is delivered to @command{tar}.
3229 @xref{totals}.
3230
3231 @opsummary{touch}
3232 @item --touch
3233 @itemx -m
3234
3235 Sets the data modification time of extracted files to the extraction time,
3236 rather than the data modification time stored in the archive.
3237 @xref{Data Modification Times}.
3238
3239 @opsummary{transform}
3240 @item --transform=@var{sed-expr}
3241
3242 Transform file or member names using @command{sed} replacement expression
3243 @var{sed-expr}. For example,
3244
3245 @smallexample
3246 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3247 @end smallexample
3248
3249 @noindent
3250 will add to @file{archive} files from the current working directory,
3251 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3252 discussion, @xref{transform}.
3253
3254 To see transformed member names in verbose listings, use
3255 @option{--show-transformed-names} option
3256 (@pxref{show-transformed-names}).
3257
3258 @opsummary{uncompress}
3259 @item --uncompress
3260
3261 (See @option{--compress}. @pxref{gzip})
3262
3263 @opsummary{ungzip}
3264 @item --ungzip
3265
3266 (See @option{--gzip}. @pxref{gzip})
3267
3268 @opsummary{unlink-first}
3269 @item --unlink-first
3270 @itemx -U
3271
3272 Directs @command{tar} to remove the corresponding file from the file
3273 system before extracting it from the archive. @xref{Unlink First}.
3274
3275 @opsummary{unquote}
3276 @item --unquote
3277 Enable unquoting input file or member names (default). @xref{input
3278 name quoting}.
3279
3280 @opsummary{use-compress-program}
3281 @item --use-compress-program=@var{prog}
3282
3283 Instructs @command{tar} to access the archive through @var{prog}, which is
3284 presumed to be a compression program of some sort. @xref{gzip}.
3285
3286 @opsummary{utc}
3287 @item --utc
3288
3289 Display file modification dates in @acronym{UTC}. This option implies
3290 @option{--verbose}.
3291
3292 @opsummary{verbose}
3293 @item --verbose
3294 @itemx -v
3295
3296 Specifies that @command{tar} should be more verbose about the
3297 operations it is performing. This option can be specified multiple
3298 times for some operations to increase the amount of information displayed.
3299 @xref{verbose}.
3300
3301 @opsummary{verify}
3302 @item --verify
3303 @itemx -W
3304
3305 Verifies that the archive was correctly written when creating an
3306 archive. @xref{verify}.
3307
3308 @opsummary{version}
3309 @item --version
3310
3311 Print information about the program's name, version, origin and legal
3312 status, all on standard output, and then exit successfully.
3313 @xref{help}.
3314
3315 @opsummary{volno-file}
3316 @item --volno-file=@var{file}
3317
3318 Used in conjunction with @option{--multi-volume}. @command{tar} will
3319 keep track of which volume of a multi-volume archive it is working in
3320 @var{file}. @xref{volno-file}.
3321
3322 @opsummary{wildcards}
3323 @item --wildcards
3324 Use wildcards when matching member names with patterns.
3325 @xref{controlling pattern-matching}.
3326
3327 @opsummary{wildcards-match-slash}
3328 @item --wildcards-match-slash
3329 Wildcards match @samp{/}.
3330 @xref{controlling pattern-matching}.
3331 @end table
3332
3333 @node Short Option Summary
3334 @subsection Short Options Cross Reference
3335
3336 Here is an alphabetized list of all of the short option forms, matching
3337 them with the equivalent long option.
3338
3339 @multitable @columnfractions 0.20 0.80
3340 @headitem Short Option @tab Reference
3341
3342 @item -A @tab @ref{--concatenate}.
3343
3344 @item -B @tab @ref{--read-full-records}.
3345
3346 @item -C @tab @ref{--directory}.
3347
3348 @item -F @tab @ref{--info-script}.
3349
3350 @item -G @tab @ref{--incremental}.
3351
3352 @item -K @tab @ref{--starting-file}.
3353
3354 @item -L @tab @ref{--tape-length}.
3355
3356 @item -M @tab @ref{--multi-volume}.
3357
3358 @item -N @tab @ref{--newer}.
3359
3360 @item -O @tab @ref{--to-stdout}.
3361
3362 @item -P @tab @ref{--absolute-names}.
3363
3364 @item -R @tab @ref{--block-number}.
3365
3366 @item -S @tab @ref{--sparse}.
3367
3368 @item -T @tab @ref{--files-from}.
3369
3370 @item -U @tab @ref{--unlink-first}.
3371
3372 @item -V @tab @ref{--label}.
3373
3374 @item -W @tab @ref{--verify}.
3375
3376 @item -X @tab @ref{--exclude-from}.
3377
3378 @item -Z @tab @ref{--compress}.
3379
3380 @item -b @tab @ref{--blocking-factor}.
3381
3382 @item -c @tab @ref{--create}.
3383
3384 @item -d @tab @ref{--compare}.
3385
3386 @item -f @tab @ref{--file}.
3387
3388 @item -g @tab @ref{--listed-incremental}.
3389
3390 @item -h @tab @ref{--dereference}.
3391
3392 @item -i @tab @ref{--ignore-zeros}.
3393
3394 @item -j @tab @ref{--bzip2}.
3395
3396 @item -k @tab @ref{--keep-old-files}.
3397
3398 @item -l @tab @ref{--check-links}.
3399
3400 @item -m @tab @ref{--touch}.
3401
3402 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3403 @ref{--portability}.
3404
3405 The later usage is deprecated. It is retained for compatibility with
3406 the earlier versions of @GNUTAR{}. In future releases
3407 @option{-o} will be equivalent to @option{--no-same-owner} only.
3408
3409 @item -p @tab @ref{--preserve-permissions}.
3410
3411 @item -r @tab @ref{--append}.
3412
3413 @item -s @tab @ref{--same-order}.
3414
3415 @item -t @tab @ref{--list}.
3416
3417 @item -u @tab @ref{--update}.
3418
3419 @item -v @tab @ref{--verbose}.
3420
3421 @item -w @tab @ref{--interactive}.
3422
3423 @item -x @tab @ref{--extract}.
3424
3425 @item -z @tab @ref{--gzip}.
3426
3427 @end multitable
3428
3429 @node help
3430 @section @GNUTAR{} documentation
3431
3432 @cindex Getting program version number
3433 @opindex version
3434 @cindex Version of the @command{tar} program
3435 Being careful, the first thing is really checking that you are using
3436 @GNUTAR{}, indeed. The @option{--version} option
3437 causes @command{tar} to print information about its name, version,
3438 origin and legal status, all on standard output, and then exit
3439 successfully. For example, @w{@samp{tar --version}} might print:
3440
3441 @smallexample
3442 tar (GNU tar) @value{VERSION}
3443 Copyright (C) 2008 Free Software Foundation, Inc.
3444 This is free software. You may redistribute copies of it under the terms
3445 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3446 There is NO WARRANTY, to the extent permitted by law.
3447
3448 Written by John Gilmore and Jay Fenlason.
3449 @end smallexample
3450
3451 @noindent
3452 The first occurrence of @samp{tar} in the result above is the program
3453 name in the package (for example, @command{rmt} is another program),
3454 while the second occurrence of @samp{tar} is the name of the package
3455 itself, containing possibly many programs. The package is currently
3456 named @samp{tar}, after the name of the main program it
3457 contains@footnote{There are plans to merge the @command{cpio} and
3458 @command{tar} packages into a single one which would be called
3459 @code{paxutils}. So, who knows if, one of this days, the
3460 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3461 paxutils) 3.2}}}.
3462
3463 @cindex Obtaining help
3464 @cindex Listing all @command{tar} options
3465 @xopindex{help, introduction}
3466 Another thing you might want to do is checking the spelling or meaning
3467 of some particular @command{tar} option, without resorting to this
3468 manual, for once you have carefully read it. @GNUTAR{}
3469 has a short help feature, triggerable through the
3470 @option{--help} option. By using this option, @command{tar} will
3471 print a usage message listing all available options on standard
3472 output, then exit successfully, without doing anything else and
3473 ignoring all other options. Even if this is only a brief summary, it
3474 may be several screens long. So, if you are not using some kind of
3475 scrollable window, you might prefer to use something like:
3476
3477 @smallexample
3478 $ @kbd{tar --help | less}
3479 @end smallexample
3480
3481 @noindent
3482 presuming, here, that you like using @command{less} for a pager. Other
3483 popular pagers are @command{more} and @command{pg}. If you know about some
3484 @var{keyword} which interests you and do not want to read all the
3485 @option{--help} output, another common idiom is doing:
3486
3487 @smallexample
3488 tar --help | grep @var{keyword}
3489 @end smallexample
3490
3491 @noindent
3492 for getting only the pertinent lines. Notice, however, that some
3493 @command{tar} options have long description lines and the above
3494 command will list only the first of them.
3495
3496 The exact look of the option summary displayed by @kbd{tar --help} is
3497 configurable. @xref{Configuring Help Summary}, for a detailed description.
3498
3499 @opindex usage
3500 If you only wish to check the spelling of an option, running @kbd{tar
3501 --usage} may be a better choice. This will display a terse list of
3502 @command{tar} option without accompanying explanations.
3503
3504 The short help output is quite succinct, and you might have to get
3505 back to the full documentation for precise points. If you are reading
3506 this paragraph, you already have the @command{tar} manual in some
3507 form. This manual is available in a variety of forms from
3508 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3509 distribution, provided you have @TeX{} already installed somewhere,
3510 and a laser printer around. Just configure the distribution, execute
3511 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3512 usual way (contact your local guru to know how). If @GNUTAR{}
3513 has been conveniently installed at your place, this
3514 manual is also available in interactive, hypertextual form as an Info
3515 file. Just call @w{@samp{info tar}} or, if you do not have the
3516 @command{info} program handy, use the Info reader provided within
3517 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3518
3519 There is currently no @code{man} page for @GNUTAR{}.
3520 If you observe such a @code{man} page on the system you are running,
3521 either it does not belong to @GNUTAR{}, or it has not
3522 been produced by @acronym{GNU}. Some package maintainers convert
3523 @kbd{tar --help} output to a man page, using @command{help2man}. In
3524 any case, please bear in mind that the authoritative source of
3525 information about @GNUTAR{} is this Texinfo documentation.
3526
3527 @node defaults
3528 @section Obtaining @GNUTAR{} default values
3529
3530 @opindex show-defaults
3531 @GNUTAR{} has some predefined defaults that are used when you do not
3532 explicitly specify another values. To obtain a list of such
3533 defaults, use @option{--show-defaults} option. This will output the
3534 values in the form of @command{tar} command line options:
3535
3536 @smallexample
3537 @group
3538 @kbd{tar --show-defaults}
3539 --format=gnu -f- -b20 --quoting-style=escape
3540 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3541 @end group
3542 @end smallexample
3543
3544 @noindent
3545 Notice, that this option outputs only one line. The example output above
3546 has been split to fit page boundaries.
3547
3548 @noindent
3549 The above output shows that this version of @GNUTAR{} defaults to
3550 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3551 output as the archive, if no @option{--file} option has been given
3552 (@pxref{file tutorial}), the default blocking factor is 20
3553 (@pxref{Blocking Factor}). It also shows the default locations where
3554 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3555
3556 @node verbose
3557 @section Checking @command{tar} progress
3558
3559 Typically, @command{tar} performs most operations without reporting any
3560 information to the user except error messages. When using @command{tar}
3561 with many options, particularly ones with complicated or
3562 difficult-to-predict behavior, it is possible to make serious mistakes.
3563 @command{tar} provides several options that make observing @command{tar}
3564 easier. These options cause @command{tar} to print information as it
3565 progresses in its job, and you might want to use them just for being
3566 more careful about what is going on, or merely for entertaining
3567 yourself. If you have encountered a problem when operating on an
3568 archive, however, you may need more information than just an error
3569 message in order to solve the problem. The following options can be
3570 helpful diagnostic tools.
3571
3572 @cindex Verbose operation
3573 @opindex verbose
3574 Normally, the @option{--list} (@option{-t}) command to list an archive
3575 prints just the file names (one per line) and the other commands are
3576 silent. When used with most operations, the @option{--verbose}
3577 (@option{-v}) option causes @command{tar} to print the name of each
3578 file or archive member as it is processed. This and the other options
3579 which make @command{tar} print status information can be useful in
3580 monitoring @command{tar}.
3581
3582 With @option{--create} or @option{--extract}, @option{--verbose} used
3583 once just prints the names of the files or members as they are processed.
3584 Using it twice causes @command{tar} to print a longer listing
3585 (@xref{verbose member listing}, for the description) for each member.
3586 Since @option{--list} already prints the names of the members,
3587 @option{--verbose} used once with @option{--list} causes @command{tar}
3588 to print an @samp{ls -l} type listing of the files in the archive.
3589 The following examples both extract members with long list output:
3590
3591 @smallexample
3592 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3593 $ @kbd{tar xvvf archive.tar}
3594 @end smallexample
3595
3596 Verbose output appears on the standard output except when an archive is
3597 being written to the standard output, as with @samp{tar --create
3598 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3599 installer let standard output be the default archive). In that case
3600 @command{tar} writes verbose output to the standard error stream.
3601
3602 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3603 verbose output to @var{file} rather than to standard output or standard
3604 error.
3605
3606 @anchor{totals}
3607 @cindex Obtaining total status information
3608 @opindex totals
3609 The @option{--totals} option causes @command{tar} to print on the
3610 standard error the total amount of bytes transferred when processing
3611 an archive. When creating or appending to an archive, this option
3612 prints the number of bytes written to the archive and the average
3613 speed at which they have been written, e.g.:
3614
3615 @smallexample
3616 @group
3617 $ @kbd{tar -c -f archive.tar --totals /home}
3618 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3619 @end group
3620 @end smallexample
3621
3622 When reading an archive, this option displays the number of bytes
3623 read:
3624
3625 @smallexample
3626 @group
3627 $ @kbd{tar -x -f archive.tar --totals}
3628 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3629 @end group
3630 @end smallexample
3631
3632 Finally, when deleting from an archive, the @option{--totals} option
3633 displays both numbers plus number of bytes removed from the archive:
3634
3635 @smallexample
3636 @group
3637 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3638 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3639 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3640 Total bytes deleted: 1474048
3641 @end group
3642 @end smallexample
3643
3644 You can also obtain this information on request. When
3645 @option{--totals} is used with an argument, this argument is
3646 interpreted as a symbolic name of a signal, upon delivery of which the
3647 statistics is to be printed:
3648
3649 @table @option
3650 @item --totals=@var{signo}
3651 Print statistics upon delivery of signal @var{signo}. Valid arguments
3652 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3653 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3654 accepted.
3655 @end table
3656
3657 Both forms of @option{--totals} option can be used simultaneously.
3658 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3659 extract all members from its default archive and print statistics
3660 after finishing the extraction, as well as when receiving signal
3661 @code{SIGUSR1}.
3662
3663 @anchor{Progress information}
3664 @cindex Progress information
3665 The @option{--checkpoint} option prints an occasional message
3666 as @command{tar} reads or writes the archive. It is designed for
3667 those who don't need the more detailed (and voluminous) output of
3668 @option{--block-number} (@option{-R}), but do want visual confirmation
3669 that @command{tar} is actually making forward progress. By default it
3670 prints a message each 10 records read or written. This can be changed
3671 by giving it a numeric argument after an equal sign:
3672
3673 @smallexample
3674 $ @kbd{tar -c --checkpoint=1000} /var
3675 tar: Write checkpoint 1000
3676 tar: Write checkpoint 2000
3677 tar: Write checkpoint 3000
3678 @end smallexample
3679
3680 This example shows the default checkpoint message used by
3681 @command{tar}. If you place a dot immediately after the equal
3682 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3683 actually a shortcut for @option{--checkpoint=@var{n}
3684 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3685
3686 @smallexample
3687 $ @kbd{tar -c --checkpoint=.1000} /var
3688 ...
3689 @end smallexample
3690
3691 The @option{--checkpoint} option provides a flexible mechanism for
3692 executing arbitrary actions upon hitting checkpoints, see the next
3693 section (@pxref{checkpoints}), for more information on it.
3694
3695 @opindex show-omitted-dirs
3696 @anchor{show-omitted-dirs}
3697 The @option{--show-omitted-dirs} option, when reading an archive---with
3698 @option{--list} or @option{--extract}, for example---causes a message
3699 to be printed for each directory in the archive which is skipped.
3700 This happens regardless of the reason for skipping: the directory might
3701 not have been named on the command line (implicitly or explicitly),
3702 it might be excluded by the use of the
3703 @option{--exclude=@var{pattern}} option, or some other reason.
3704
3705 @opindex block-number
3706 @cindex Block number where error occurred
3707 @anchor{block-number}
3708 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3709 every message it would normally produce, the block number within the
3710 archive where the message was triggered. Also, supplementary messages
3711 are triggered when reading blocks full of NULs, or when hitting end of
3712 file on the archive. As of now, if the archive if properly terminated
3713 with a NUL block, the reading of the file may stop before end of file
3714 is met, so the position of end of file will not usually show when
3715 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3716 drains the archive before exiting when reading the
3717 archive from a pipe.
3718
3719 @cindex Error message, block number of
3720 This option is especially useful when reading damaged archives, since
3721 it helps pinpoint the damaged sections. It can also be used with
3722 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3723 choose among several backup tapes when retrieving a file later, in
3724 favor of the tape where the file appears earliest (closest to the
3725 front of the tape). @xref{backup}.
3726
3727 @node checkpoints
3728 @section Checkpoints
3729 @cindex checkpoints, defined
3730 @opindex checkpoint
3731 @opindex checkpoint-action
3732
3733 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3734 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3735 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3736 periodically execute arbitrary actions.
3737
3738 The checkpoint facility is enabled using the following option:
3739
3740 @table @option
3741 @xopindex{checkpoint, defined}
3742 @item --checkpoint[=@var{n}]
3743 Schedule checkpoints before writing or reading each @var{n}th record.
3744 The default value for @var{n} is 10.
3745 @end table
3746
3747 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3748 These actions include: pausing, displaying textual messages, and
3749 executing arbitrary external programs. Actions are defined using
3750 the @option{--checkpoint-action} option.
3751
3752 @table @option
3753 @xopindex{checkpoint-action, defined}
3754 @item --checkpoint-action=@var{action}
3755 Execute an @var{action} at each checkpoint.
3756 @end table
3757
3758 @cindex @code{echo}, checkpoint action
3759 The simplest value of @var{action} is @samp{echo}. It instructs
3760 @command{tar} to display the default message on the standard error
3761 stream upon arriving at each checkpoint. The default message is (in
3762 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3763 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3764 Here, @var{n} represents ordinal number of the checkpoint.
3765
3766 In another locales, translated versions of this message are used.
3767
3768 This is the default action, so running:
3769
3770 @smallexample
3771 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3772 @end smallexample
3773
3774 @noindent
3775 is equivalent to:
3776
3777 @smallexample
3778 $ @kbd{tar -c --checkpoint=1000} /var
3779 @end smallexample
3780
3781 The @samp{echo} action also allows to supply a customized message.
3782 You do so by placing an equals sign and the message right after it,
3783 e.g.:
3784
3785 @smallexample
3786 --checkpoint-action="echo=Hit %s checkpoint #%u"
3787 @end smallexample
3788
3789 The @samp{%s} and @samp{%u} in the above example are
3790 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3791 the @dfn{type} of the checkpoint: @samp{write} or
3792 @samp{read} (or a corresponding translated version in locales other
3793 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3794 the ordinal number of the checkpoint. Thus, the above example could
3795 produce the following output when used with the @option{--create}
3796 option:
3797
3798 @smallexample
3799 tar: Hit write checkpoint #10
3800 tar: Hit write checkpoint #20
3801 tar: Hit write checkpoint #30
3802 @end smallexample
3803
3804 Aside from meta-character expansion, the message string is subject to
3805 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3806 replaced with their corresponding @acronym{ASCII} characters
3807 (@pxref{escape sequences}). E.g. the following action will produce an
3808 audible bell and the message described above at each checkpoint:
3809
3810 @smallexample
3811 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3812 @end smallexample
3813
3814 @cindex @code{bell}, checkpoint action
3815 There is also a special action which produces an audible signal:
3816 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3817 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3818 whereas @samp{echo='\a'} sends it to the standard error.
3819
3820 @cindex @code{ttyout}, checkpoint action
3821 The @samp{ttyout=@var{string}} action outputs @var{string} to
3822 @file{/dev/tty}, so it can be used even if the standard output is
3823 redirected elsewhere. The @var{string} is subject to the same
3824 modifications as with @samp{echo} action. In contrast to the latter,
3825 @samp{ttyout} does not prepend @command{tar} executable name to the
3826 string, nor does it output a newline after it. For example, the
3827 following action will print the checkpoint message at the same screen
3828 line, overwriting any previous message:
3829
3830 @smallexample
3831 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3832 @end smallexample
3833
3834 @cindex @code{dot}, checkpoint action
3835 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3836 instructs @command{tar} to print a single dot on the standard listing
3837 stream, e.g.:
3838
3839 @smallexample
3840 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3841 ...
3842 @end smallexample
3843
3844 For compatibility with previous @GNUTAR{} versions, this action can
3845 be abbreviated by placing a dot in front of the checkpoint frequency,
3846 as shown in the previous section.
3847
3848 @cindex @code{sleep}, checkpoint action
3849 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
3850 amount of seconds. The following example will stop for 30 seconds at each
3851 checkpoint:
3852
3853 @smallexample
3854 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
3855 @end smallexample
3856
3857 @cindex @code{exec}, checkpoint action
3858 Finally, the @code{exec} action executes a given external program.
3859 For example:
3860
3861 @smallexample
3862 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
3863 @end smallexample
3864
3865 This program is executed using @command{/bin/sh -c}, with no
3866 additional arguments. Its exit code is ignored. It gets a copy of
3867 @command{tar}'s environment plus the following variables:
3868
3869 @table @env
3870 @vrindex TAR_VERSION, checkpoint script environment
3871 @item TAR_VERSION
3872 @GNUTAR{} version number.
3873
3874 @vrindex TAR_ARCHIVE, checkpoint script environment
3875 @item TAR_ARCHIVE
3876 The name of the archive @command{tar} is processing.
3877
3878 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
3879 @item TAR_BLOCKING_FACTOR
3880 Current blocking factor (@pxref{Blocking}.
3881
3882 @vrindex TAR_CHECKPOINT, checkpoint script environment
3883 @item TAR_CHECKPOINT
3884 The checkpoint number.
3885
3886 @vrindex TAR_SUBCOMMAND, checkpoint script environment
3887 @item TAR_SUBCOMMAND
3888 A short option describing the operation @command{tar} is executing
3889 @xref{Operations}, for a complete list of subcommand options.
3890
3891 @vrindex TAR_FORMAT, checkpoint script environment
3892 @item TAR_FORMAT
3893 Format of the archive being processed. @xref{Formats}, for a complete
3894 list of archive format names.
3895 @end table
3896
3897 Any number of actions can be defined, by supplying several
3898 @option{--checkpoint-action} options in the command line. For
3899 example, the command below displays two messages, pauses
3900 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
3901
3902 @example
3903 @group
3904 $ @kbd{tar -c -f arc.tar \
3905 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
3906 --checkpoint-action='echo=Sleeping for 30 seconds' \
3907 --checkpoint-action='sleep=30' \
3908 --checkpoint-action='exec=/sbin/cpoint'}
3909 @end group
3910 @end example
3911
3912 This example also illustrates the fact that
3913 @option{--checkpoint-action} can be used without
3914 @option{--checkpoint}. In this case, the default checkpoint frequency
3915 (at each 10th record) is assumed.
3916
3917 @node interactive
3918 @section Asking for Confirmation During Operations
3919 @cindex Interactive operation
3920
3921 Typically, @command{tar} carries out a command without stopping for
3922 further instructions. In some situations however, you may want to
3923 exclude some files and archive members from the operation (for instance
3924 if disk or storage space is tight). You can do this by excluding
3925 certain files automatically (@pxref{Choosing}), or by performing
3926 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3927 @command{tar} also accepts @option{--confirmation} for this option.
3928
3929 @opindex interactive
3930 When the @option{--interactive} (@option{-w}) option is specified, before
3931 reading, writing, or deleting files, @command{tar} first prints a message
3932 for each such file, telling what operation it intends to take, then asks
3933 for confirmation on the terminal. The actions which require
3934 confirmation include adding a file to the archive, extracting a file
3935 from the archive, deleting a file from the archive, and deleting a file
3936 from disk. To confirm the action, you must type a line of input
3937 beginning with @samp{y}. If your input line begins with anything other
3938 than @samp{y}, @command{tar} skips that file.
3939
3940 If @command{tar} is reading the archive from the standard input,
3941 @command{tar} opens the file @file{/dev/tty} to support the interactive
3942 communications.
3943
3944 Verbose output is normally sent to standard output, separate from
3945 other error messages. However, if the archive is produced directly
3946 on standard output, then verbose output is mixed with errors on
3947 @code{stderr}. Producing the archive on standard output may be used
3948 as a way to avoid using disk space, when the archive is soon to be
3949 consumed by another process reading it, say. Some people felt the need
3950 of producing an archive on stdout, still willing to segregate between
3951 verbose output and error output. A possible approach would be using a
3952 named pipe to receive the archive, and having the consumer process to
3953 read from that named pipe. This has the advantage of letting standard
3954 output free to receive verbose output, all separate from errors.
3955
3956 @node operations
3957 @chapter @GNUTAR{} Operations
3958
3959 @menu
3960 * Basic tar::
3961 * Advanced tar::
3962 * create options::
3963 * extract options::
3964 * backup::
3965 * Applications::
3966 * looking ahead::
3967 @end menu
3968
3969 @node Basic tar
3970 @section Basic @GNUTAR{} Operations
3971
3972 The basic @command{tar} operations, @option{--create} (@option{-c}),
3973 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3974 @option{-x}), are currently presented and described in the tutorial
3975 chapter of this manual. This section provides some complementary notes
3976 for these operations.
3977
3978 @table @option
3979 @xopindex{create, complementary notes}
3980 @item --create
3981 @itemx -c
3982
3983 Creating an empty archive would have some kind of elegance. One can
3984 initialize an empty archive and later use @option{--append}
3985 (@option{-r}) for adding all members. Some applications would not
3986 welcome making an exception in the way of adding the first archive
3987 member. On the other hand, many people reported that it is
3988 dangerously too easy for @command{tar} to destroy a magnetic tape with
3989 an empty archive@footnote{This is well described in @cite{Unix-haters
3990 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3991 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3992
3993 @enumerate
3994 @item
3995 Mistakingly using @code{create} instead of @code{extract}, when the
3996 intent was to extract the full contents of an archive. This error
3997 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3998 the QWERTY keyboard. Instead of being unpacked, the archive then
3999 gets wholly destroyed. When users speak about @dfn{exploding} an
4000 archive, they usually mean something else :-).
4001
4002 @item
4003 Forgetting the argument to @code{file}, when the intent was to create
4004 an archive with a single file in it. This error is likely because a
4005 tired user can easily add the @kbd{f} key to the cluster of option
4006 letters, by the mere force of habit, without realizing the full
4007 consequence of doing so. The usual consequence is that the single
4008 file, which was meant to be saved, is rather destroyed.
4009 @end enumerate
4010
4011 So, recognizing the likelihood and the catastrophic nature of these
4012 errors, @GNUTAR{} now takes some distance from elegance, and
4013 cowardly refuses to create an archive when @option{--create} option is
4014 given, there are no arguments besides options, and
4015 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4016 around the cautiousness of @GNUTAR{} and nevertheless create an
4017 archive with nothing in it, one may still use, as the value for the
4018 @option{--files-from} option, a file with no names in it, as shown in
4019 the following commands:
4020
4021 @smallexample
4022 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4023 @kbd{tar cfT empty-archive.tar /dev/null}
4024 @end smallexample
4025
4026 @xopindex{extract, complementary notes}
4027 @item --extract
4028 @itemx --get
4029 @itemx -x
4030
4031 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4032
4033 @item @option{--list} (@option{-t})
4034
4035 @GNUTAR{} now shows dates as @samp{1996-08-30},
4036 while it used to show them as @samp{Aug 30 1996}. Preferably,
4037 people should get used to ISO 8601 dates. Local American dates should
4038 be made available again with full date localization support, once
4039 ready. In the meantime, programs not being localizable for dates
4040 should prefer international dates, that's really the way to go.
4041
4042 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4043 are curious, it contains a detailed explanation of the ISO 8601 standard.
4044
4045 @end table
4046
4047 @node Advanced tar
4048 @section Advanced @GNUTAR{} Operations
4049
4050 Now that you have learned the basics of using @GNUTAR{}, you may want
4051 to learn about further ways in which @command{tar} can help you.
4052
4053 This chapter presents five, more advanced operations which you probably
4054 won't use on a daily basis, but which serve more specialized functions.
4055 We also explain the different styles of options and why you might want
4056 to use one or another, or a combination of them in your @command{tar}
4057 commands. Additionally, this chapter includes options which allow you to
4058 define the output from @command{tar} more carefully, and provide help and
4059 error correction in special circumstances.
4060
4061 @FIXME{check this after the chapter is actually revised to make sure
4062 it still introduces the info in the chapter correctly : ).}
4063
4064 @menu
4065 * Operations::
4066 * append::
4067 * update::
4068 * concatenate::
4069 * delete::
4070 * compare::
4071 @end menu
4072
4073 @node Operations
4074 @subsection The Five Advanced @command{tar} Operations
4075 @UNREVISED
4076
4077 In the last chapter, you learned about the first three operations to
4078 @command{tar}. This chapter presents the remaining five operations to
4079 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4080 @option{--delete}, and @option{--compare}.
4081
4082 You are not likely to use these operations as frequently as those
4083 covered in the last chapter; however, since they perform specialized
4084 functions, they are quite useful when you do need to use them. We
4085 will give examples using the same directory and files that you created
4086 in the last chapter. As you may recall, the directory is called
4087 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4088 @samp{rock}, and the two archive files you created are
4089 @samp{collection.tar} and @samp{music.tar}.
4090
4091 We will also use the archive files @samp{afiles.tar} and
4092 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4093 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4094 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4095
4096 Unless we state otherwise, all practicing you do and examples you follow
4097 in this chapter will take place in the @file{practice} directory that
4098 you created in the previous chapter; see @ref{prepare for examples}.
4099 (Below in this section, we will remind you of the state of the examples
4100 where the last chapter left them.)
4101
4102 The five operations that we will cover in this chapter are:
4103
4104 @table @option
4105 @item --append
4106 @itemx -r
4107 Add new entries to an archive that already exists.
4108 @item --update
4109 @itemx -r
4110 Add more recent copies of archive members to the end of an archive, if
4111 they exist.
4112 @item --concatenate
4113 @itemx --catenate
4114 @itemx -A
4115 Add one or more pre-existing archives to the end of another archive.
4116 @item --delete
4117 Delete items from an archive (does not work on tapes).
4118 @item --compare
4119 @itemx --diff
4120 @itemx -d
4121 Compare archive members to their counterparts in the file system.
4122 @end table
4123
4124 @node append
4125 @subsection How to Add Files to Existing Archives: @option{--append}
4126 @UNREVISED
4127
4128 @opindex append
4129 If you want to add files to an existing archive, you don't need to
4130 create a new archive; you can use @option{--append} (@option{-r}).
4131 The archive must already exist in order to use @option{--append}. (A
4132 related operation is the @option{--update} operation; you can use this
4133 to add newer versions of archive members to an existing archive. To learn how to
4134 do this with @option{--update}, @pxref{update}.)
4135
4136 If you use @option{--append} to add a file that has the same name as an
4137 archive member to an archive containing that archive member, then the
4138 old member is not deleted. What does happen, however, is somewhat
4139 complex. @command{tar} @emph{allows} you to have infinite number of files
4140 with the same name. Some operations treat these same-named members no
4141 differently than any other set of archive members: for example, if you
4142 view an archive with @option{--list} (@option{-t}), you will see all
4143 of those members listed, with their data modification times, owners, etc.
4144
4145 Other operations don't deal with these members as perfectly as you might
4146 prefer; if you were to use @option{--extract} to extract the archive,
4147 only the most recently added copy of a member with the same name as four
4148 other members would end up in the working directory. This is because
4149 @option{--extract} extracts an archive in the order the members appeared
4150 in the archive; the most recently archived members will be extracted
4151 last. Additionally, an extracted member will @emph{replace} a file of
4152 the same name which existed in the directory already, and @command{tar}
4153 will not prompt you about this@footnote{Unless you give it
4154 @option{--keep-old-files} option, or the disk copy is newer than the
4155 the one in the archive and you invoke @command{tar} with
4156 @option{--keep-newer-files} option}. Thus, only the most recently archived
4157 member will end up being extracted, as it will replace the one
4158 extracted before it, and so on.
4159
4160 There exists a special option that allows you to get around this
4161 behavior and extract (or list) only a particular copy of the file.
4162 This is @option{--occurrence} option. If you run @command{tar} with
4163 this option, it will extract only the first copy of the file. You
4164 may also give this option an argument specifying the number of
4165 copy to be extracted. Thus, for example if the archive
4166 @file{archive.tar} contained three copies of file @file{myfile}, then
4167 the command
4168
4169 @smallexample
4170 tar --extract --file archive.tar --occurrence=2 myfile
4171 @end smallexample
4172
4173 @noindent
4174 would extract only the second copy. @xref{Option
4175 Summary,---occurrence}, for the description of @option{--occurrence}
4176 option.
4177
4178 @FIXME{ hag -- you might want to incorporate some of the above into the
4179 MMwtSN node; not sure. i didn't know how to make it simpler...
4180
4181 There are a few ways to get around this. (maybe xref Multiple Members
4182 with the Same Name.}
4183
4184 @cindex Members, replacing with other members
4185 @cindex Replacing members with other members
4186 If you want to replace an archive member, use @option{--delete} to
4187 delete the member you want to remove from the archive, , and then use
4188 @option{--append} to add the member you want to be in the archive. Note
4189 that you can not change the order of the archive; the most recently
4190 added member will still appear last. In this sense, you cannot truly
4191 ``replace'' one member with another. (Replacing one member with another
4192 will not work on certain types of media, such as tapes; see @ref{delete}
4193 and @ref{Media}, for more information.)
4194
4195 @menu
4196 * appending files:: Appending Files to an Archive
4197 * multiple::
4198 @end menu
4199
4200 @node appending files
4201 @subsubsection Appending Files to an Archive
4202 @UNREVISED
4203 @cindex Adding files to an Archive
4204 @cindex Appending files to an Archive
4205 @cindex Archives, Appending files to
4206
4207 The simplest way to add a file to an already existing archive is the
4208 @option{--append} (@option{-r}) operation, which writes specified
4209 files into the archive whether or not they are already among the
4210 archived files.
4211
4212 When you use @option{--append}, you @emph{must} specify file name
4213 arguments, as there is no default. If you specify a file that already
4214 exists in the archive, another copy of the file will be added to the
4215 end of the archive. As with other operations, the member names of the
4216 newly added files will be exactly the same as their names given on the
4217 command line. The @option{--verbose} (@option{-v}) option will print
4218 out the names of the files as they are written into the archive.
4219
4220 @option{--append} cannot be performed on some tape drives, unfortunately,
4221 due to deficiencies in the formats those tape drives use. The archive
4222 must be a valid @command{tar} archive, or else the results of using this
4223 operation will be unpredictable. @xref{Media}.
4224
4225 To demonstrate using @option{--append} to add a file to an archive,
4226 create a file called @file{rock} in the @file{practice} directory.
4227 Make sure you are in the @file{practice} directory. Then, run the
4228 following @command{tar} command to add @file{rock} to
4229 @file{collection.tar}:
4230
4231 @smallexample
4232 $ @kbd{tar --append --file=collection.tar rock}
4233 @end smallexample
4234
4235 @noindent
4236 If you now use the @option{--list} (@option{-t}) operation, you will see that
4237 @file{rock} has been added to the archive:
4238
4239 @smallexample
4240 $ @kbd{tar --list --file=collection.tar}
4241 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4242 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4243 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4244 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4245 @end smallexample
4246
4247 @node multiple
4248 @subsubsection Multiple Members with the Same Name
4249
4250 You can use @option{--append} (@option{-r}) to add copies of files
4251 which have been updated since the archive was created. (However, we
4252 do not recommend doing this since there is another @command{tar}
4253 option called @option{--update}; @xref{update}, for more information.
4254 We describe this use of @option{--append} here for the sake of
4255 completeness.) When you extract the archive, the older version will
4256 be effectively lost. This works because files are extracted from an
4257 archive in the order in which they were archived. Thus, when the
4258 archive is extracted, a file archived later in time will replace a
4259 file of the same name which was archived earlier, even though the
4260 older version of the file will remain in the archive unless you delete
4261 all versions of the file.
4262
4263 Supposing you change the file @file{blues} and then append the changed
4264 version to @file{collection.tar}. As you saw above, the original
4265 @file{blues} is in the archive @file{collection.tar}. If you change the
4266 file and append the new version of the file to the archive, there will
4267 be two copies in the archive. When you extract the archive, the older
4268 version of the file will be extracted first, and then replaced by the
4269 newer version when it is extracted.
4270
4271 You can append the new, changed copy of the file @file{blues} to the
4272 archive in this way:
4273
4274 @smallexample
4275 $ @kbd{tar --append --verbose --file=collection.tar blues}
4276 blues
4277 @end smallexample
4278
4279 @noindent
4280 Because you specified the @option{--verbose} option, @command{tar} has
4281 printed the name of the file being appended as it was acted on. Now
4282 list the contents of the archive:
4283
4284 @smallexample
4285 $ @kbd{tar --list --verbose --file=collection.tar}
4286 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4287 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4288 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4289 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4290 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4291 @end smallexample
4292
4293 @noindent
4294 The newest version of @file{blues} is now at the end of the archive
4295 (note the different creation dates and file sizes). If you extract
4296 the archive, the older version of the file @file{blues} will be
4297 replaced by the newer version. You can confirm this by extracting
4298 the archive and running @samp{ls} on the directory.
4299
4300 If you wish to extract the first occurrence of the file @file{blues}
4301 from the archive, use @option{--occurrence} option, as shown in
4302 the following example:
4303
4304 @smallexample
4305 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4306 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4307 @end smallexample
4308
4309 @xref{Writing}, for more information on @option{--extract} and
4310 @xref{Option Summary, --occurrence}, for the description of
4311 @option{--occurrence} option.
4312
4313 @node update
4314 @subsection Updating an Archive
4315 @UNREVISED
4316 @cindex Updating an archive
4317
4318 @opindex update
4319 In the previous section, you learned how to use @option{--append} to
4320 add a file to an existing archive. A related operation is
4321 @option{--update} (@option{-u}). The @option{--update} operation
4322 updates a @command{tar} archive by comparing the date of the specified
4323 archive members against the date of the file with the same name. If
4324 the file has been modified more recently than the archive member, then
4325 the newer version of the file is added to the archive (as with
4326 @option{--append}).
4327
4328 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4329 The operation will fail.
4330
4331 @FIXME{other examples of media on which --update will fail? need to ask
4332 charles and/or mib/thomas/dave shevett..}
4333
4334 Both @option{--update} and @option{--append} work by adding to the end
4335 of the archive. When you extract a file from the archive, only the
4336 version stored last will wind up in the file system, unless you use
4337 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4338
4339 @menu
4340 * how to update::
4341 @end menu
4342
4343 @node how to update
4344 @subsubsection How to Update an Archive Using @option{--update}
4345
4346 You must use file name arguments with the @option{--update}
4347 (@option{-u}) operation. If you don't specify any files,
4348 @command{tar} won't act on any files and won't tell you that it didn't
4349 do anything (which may end up confusing you).
4350
4351 @c note: the above parenthetical added because in fact, this
4352 @c behavior just confused the author. :-)
4353
4354 To see the @option{--update} option at work, create a new file,
4355 @file{classical}, in your practice directory, and some extra text to the
4356 file @file{blues}, using any text editor. Then invoke @command{tar} with
4357 the @samp{update} operation and the @option{--verbose} (@option{-v})
4358 option specified, using the names of all the files in the practice
4359 directory as file name arguments:
4360
4361 @smallexample
4362 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4363 blues
4364 classical
4365 $
4366 @end smallexample
4367
4368 @noindent
4369 Because we have specified verbose mode, @command{tar} prints out the names
4370 of the files it is working on, which in this case are the names of the
4371 files that needed to be updated. If you run @samp{tar --list} and look
4372 at the archive, you will see @file{blues} and @file{classical} at its
4373 end. There will be a total of two versions of the member @samp{blues};
4374 the one at the end will be newer and larger, since you added text before
4375 updating it.
4376
4377 (The reason @command{tar} does not overwrite the older file when updating
4378 it is because writing to the middle of a section of tape is a difficult
4379 process. Tapes are not designed to go backward. @xref{Media}, for more
4380 information about tapes.
4381
4382 @option{--update} (@option{-u}) is not suitable for performing backups for two
4383 reasons: it does not change directory content entries, and it
4384 lengthens the archive every time it is used. The @GNUTAR{}
4385 options intended specifically for backups are more
4386 efficient. If you need to run backups, please consult @ref{Backups}.
4387
4388 @node concatenate
4389 @subsection Combining Archives with @option{--concatenate}
4390
4391 @cindex Adding archives to an archive
4392 @cindex Concatenating Archives
4393 @opindex concatenate
4394 @opindex catenate
4395 @c @cindex @option{-A} described
4396 Sometimes it may be convenient to add a second archive onto the end of
4397 an archive rather than adding individual files to the archive. To add
4398 one or more archives to the end of another archive, you should use the
4399 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4400
4401 To use @option{--concatenate}, give the first archive with
4402 @option{--file} option and name the rest of archives to be
4403 concatenated on the command line. The members, and their member
4404 names, will be copied verbatim from those archives to the first one.
4405 @footnote{This can cause multiple members to have the same name, for
4406 information on how this affects reading the archive, @ref{multiple}.}
4407 The new, concatenated archive will be called by the same name as the
4408 one given with the @option{--file} option. As usual, if you omit
4409 @option{--file}, @command{tar} will use the value of the environment
4410 variable @env{TAPE}, or, if this has not been set, the default archive name.
4411
4412 @FIXME{There is no way to specify a new name...}
4413
4414 To demonstrate how @option{--concatenate} works, create two small archives
4415 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4416 files from @file{practice}:
4417
4418 @smallexample
4419 $ @kbd{tar -cvf bluesrock.tar blues rock}
4420 blues
4421 rock
4422 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4423 folk
4424 jazz
4425 @end smallexample
4426
4427 @noindent
4428 If you like, You can run @samp{tar --list} to make sure the archives
4429 contain what they are supposed to:
4430
4431 @smallexample
4432 $ @kbd{tar -tvf bluesrock.tar}
4433 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4434 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4435 $ @kbd{tar -tvf jazzfolk.tar}
4436 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4437 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4438 @end smallexample
4439
4440 We can concatenate these two archives with @command{tar}:
4441
4442 @smallexample
4443 $ @kbd{cd ..}
4444 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4445 @end smallexample
4446
4447 If you now list the contents of the @file{bluesrock.tar}, you will see
4448 that now it also contains the archive members of @file{jazzfolk.tar}:
4449
4450 @smallexample
4451 $ @kbd{tar --list --file=bluesrock.tar}
4452 blues
4453 rock
4454 folk
4455 jazz
4456 @end smallexample
4457
4458 When you use @option{--concatenate}, the source and target archives must
4459 already exist and must have been created using compatible format
4460 parameters. Notice, that @command{tar} does not check whether the
4461 archives it concatenates have compatible formats, it does not
4462 even check if the files are really tar archives.
4463
4464 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4465 tape drives, due to deficiencies in the formats those tape drives use.
4466
4467 @cindex @code{concatenate} vs @command{cat}
4468 @cindex @command{cat} vs @code{concatenate}
4469 It may seem more intuitive to you to want or try to use @command{cat} to
4470 concatenate two archives instead of using the @option{--concatenate}
4471 operation; after all, @command{cat} is the utility for combining files.
4472
4473 However, @command{tar} archives incorporate an end-of-file marker which
4474 must be removed if the concatenated archives are to be read properly as
4475 one archive. @option{--concatenate} removes the end-of-archive marker
4476 from the target archive before each new archive is appended. If you use
4477 @command{cat} to combine the archives, the result will not be a valid
4478 @command{tar} format archive. If you need to retrieve files from an
4479 archive that was added to using the @command{cat} utility, use the
4480 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4481 information on dealing with archives improperly combined using the
4482 @command{cat} shell utility.
4483
4484 @node delete
4485 @subsection Removing Archive Members Using @option{--delete}
4486 @UNREVISED
4487 @cindex Deleting files from an archive
4488 @cindex Removing files from an archive
4489
4490 @opindex delete
4491 You can remove members from an archive by using the @option{--delete}
4492 option. Specify the name of the archive with @option{--file}
4493 (@option{-f}) and then specify the names of the members to be deleted;
4494 if you list no member names, nothing will be deleted. The
4495 @option{--verbose} option will cause @command{tar} to print the names
4496 of the members as they are deleted. As with @option{--extract}, you
4497 must give the exact member names when using @samp{tar --delete}.
4498 @option{--delete} will remove all versions of the named file from the
4499 archive. The @option{--delete} operation can run very slowly.
4500
4501 Unlike other operations, @option{--delete} has no short form.
4502
4503 @cindex Tapes, using @option{--delete} and
4504 @cindex Deleting from tape archives
4505 This operation will rewrite the archive. You can only use
4506 @option{--delete} on an archive if the archive device allows you to
4507 write to any point on the media, such as a disk; because of this, it
4508 does not work on magnetic tapes. Do not try to delete an archive member
4509 from a magnetic tape; the action will not succeed, and you will be
4510 likely to scramble the archive and damage your tape. There is no safe
4511 way (except by completely re-writing the archive) to delete files from
4512 most kinds of magnetic tape. @xref{Media}.
4513
4514 To delete all versions of the file @file{blues} from the archive
4515 @file{collection.tar} in the @file{practice} directory, make sure you
4516 are in that directory, and then,
4517
4518 @smallexample
4519 $ @kbd{tar --list --file=collection.tar}
4520 blues
4521 folk
4522 jazz
4523 rock
4524 $ @kbd{tar --delete --file=collection.tar blues}
4525 $ @kbd{tar --list --file=collection.tar}
4526 folk
4527 jazz
4528 rock
4529 $
4530 @end smallexample
4531
4532 @FIXME{Check if the above listing is actually produced after running
4533 all the examples on collection.tar.}
4534
4535 The @option{--delete} option has been reported to work properly when
4536 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4537
4538 @node compare
4539 @subsection Comparing Archive Members with the File System
4540 @cindex Verifying the currency of an archive
4541 @UNREVISED
4542
4543 @opindex compare
4544 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4545 specified archive members against files with the same names, and then
4546 reports differences in file size, mode, owner, modification date and
4547 contents. You should @emph{only} specify archive member names, not file
4548 names. If you do not name any members, then @command{tar} will compare the
4549 entire archive. If a file is represented in the archive but does not
4550 exist in the file system, @command{tar} reports a difference.
4551
4552 You have to specify the record size of the archive when modifying an
4553 archive with a non-default record size.
4554
4555 @command{tar} ignores files in the file system that do not have
4556 corresponding members in the archive.
4557
4558 The following example compares the archive members @file{rock},
4559 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4560 files of the same name in the file system. (Note that there is no file,
4561 @file{funk}; @command{tar} will report an error message.)
4562
4563 @smallexample
4564 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4565 rock
4566 blues
4567 tar: funk not found in archive
4568 @end smallexample
4569
4570 The spirit behind the @option{--compare} (@option{--diff},
4571 @option{-d}) option is to check whether the archive represents the
4572 current state of files on disk, more than validating the integrity of
4573 the archive media. For this later goal, @xref{verify}.
4574
4575 @node create options
4576 @section Options Used by @option{--create}
4577
4578 @xopindex{create, additional options}
4579 The previous chapter described the basics of how to use
4580 @option{--create} (@option{-c}) to create an archive from a set of files.
4581 @xref{create}. This section described advanced options to be used with
4582 @option{--create}.
4583
4584 @menu
4585 * override:: Overriding File Metadata.
4586 * Ignore Failed Read::
4587 @end menu
4588
4589 @node override
4590 @subsection Overriding File Metadata
4591
4592 As described above, a @command{tar} archive keeps, for each member it contains,
4593 its @dfn{metadata}, such as modification time, mode and ownership of
4594 the file. @GNUTAR{} allows to replace these data with other values
4595 when adding files to the archive. The options described in this
4596 section affect creation of archives of any type. For POSIX archives,
4597 see also @ref{PAX keywords}, for additional ways of controlling
4598 metadata, stored in the archive.
4599
4600 @table @option
4601 @opindex mode
4602 @item --mode=@var{permissions}
4603
4604 When adding files to an archive, @command{tar} will use
4605 @var{permissions} for the archive members, rather than the permissions
4606 from the files. @var{permissions} can be specified either as an octal
4607 number or as symbolic permissions, like with
4608 @command{chmod} (@xref{File permissions, Permissions, File
4609 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4610 also has useful information for those not being overly familiar with
4611 the UNIX permission system). Using latter syntax allows for
4612 more flexibility. For example, the value @samp{a+rw} adds read and write
4613 permissions for everybody, while retaining executable bits on directories
4614 or on any other file already marked as executable:
4615
4616 @smallexample
4617 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4618 @end smallexample
4619
4620 @item --mtime=@var{date}
4621 @opindex mtime
4622
4623 When adding files to an archive, @command{tar} will use @var{date} as
4624 the modification time of members when creating archives, instead of
4625 their actual modification times. The argument @var{date} can be
4626 either a textual date representation in almost arbitrary format
4627 (@pxref{Date input formats}) or a name of the existing file, starting
4628 with @samp{/} or @samp{.}. In the latter case, the modification time
4629 of that file will be used.
4630
4631 The following example will set the modification date to 00:00:00 UTC,
4632 January 1, 1970:
4633
4634 @smallexample
4635 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4636 @end smallexample
4637
4638 @noindent
4639 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4640 will try to convert the specified date back to its textual
4641 representation and compare it with the one given with
4642 @option{--mtime} options. If the two dates differ, @command{tar} will
4643 print a warning saying what date it will use. This is to help user
4644 ensure he is using the right date.
4645
4646 For example:
4647
4648 @smallexample
4649 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4650 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4651 13:06:29.152478
4652 @dots{}
4653 @end smallexample
4654
4655 @item --owner=@var{user}
4656 @opindex owner
4657
4658 Specifies that @command{tar} should use @var{user} as the owner of members
4659 when creating archives, instead of the user associated with the source
4660 file. The argument @var{user} can be either an existing user symbolic
4661 name, or a decimal numeric user @acronym{ID}.
4662
4663 There is no value indicating a missing number, and @samp{0} usually means
4664 @code{root}. Some people like to force @samp{0} as the value to offer in
4665 their distributions for the owner of files, because the @code{root} user is
4666 anonymous anyway, so that might as well be the owner of anonymous
4667 archives. For example:
4668
4669 @smallexample
4670 @group
4671 $ @kbd{tar -c -f archive.tar --owner=0 .}
4672 # @r{Or:}
4673 $ @kbd{tar -c -f archive.tar --owner=root .}
4674 @end group
4675 @end smallexample
4676
4677 @item --group=@var{group}
4678 @opindex group
4679
4680 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4681 rather than the group from the source file. The argument @var{group}
4682 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4683 @end table
4684
4685 @node Ignore Failed Read
4686 @subsection Ignore Fail Read
4687
4688 @table @option
4689 @item --ignore-failed-read
4690 @opindex ignore-failed-read
4691 Do not exit with nonzero on unreadable files or directories.
4692 @end table
4693
4694 @node extract options
4695 @section Options Used by @option{--extract}
4696 @UNREVISED
4697
4698 @xopindex{extract, additional options}
4699 The previous chapter showed how to use @option{--extract} to extract
4700 an archive into the file system. Various options cause @command{tar} to
4701 extract more information than just file contents, such as the owner,
4702 the permissions, the modification date, and so forth. This section
4703 presents options to be used with @option{--extract} when certain special
4704 considerations arise. You may review the information presented in
4705 @ref{extract} for more basic information about the
4706 @option{--extract} operation.
4707
4708 @menu
4709 * Reading:: Options to Help Read Archives
4710 * Writing:: Changing How @command{tar} Writes Files
4711 * Scarce:: Coping with Scarce Resources
4712 @end menu
4713
4714 @node Reading
4715 @subsection Options to Help Read Archives
4716 @cindex Options when reading archives
4717 @UNREVISED
4718
4719 @cindex Reading incomplete records
4720 @cindex Records, incomplete
4721 @opindex read-full-records
4722 Normally, @command{tar} will request data in full record increments from
4723 an archive storage device. If the device cannot return a full record,
4724 @command{tar} will report an error. However, some devices do not always
4725 return full records, or do not require the last record of an archive to
4726 be padded out to the next record boundary. To keep reading until you
4727 obtain a full record, or to accept an incomplete record if it contains
4728 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4729 in conjunction with the @option{--extract} or @option{--list} operations.
4730 @xref{Blocking}.
4731
4732 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4733 @command{tar} reads an archive from standard input, or from a remote
4734 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
4735 pipe returns however much happens to be in the pipe, even if it is
4736 less than was requested. If this option were not enabled, @command{tar}
4737 would fail as soon as it read an incomplete record from the pipe.
4738
4739 If you're not sure of the blocking factor of an archive, you can
4740 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4741 @option{--blocking-factor=@var{512-size}} (@option{-b
4742 @var{512-size}}), using a blocking factor larger than what the archive
4743 uses. This lets you avoid having to determine the blocking factor
4744 of an archive. @xref{Blocking Factor}.
4745
4746 @menu
4747 * read full records::
4748 * Ignore Zeros::
4749 @end menu
4750
4751 @node read full records
4752 @unnumberedsubsubsec Reading Full Records
4753
4754 @FIXME{need sentence or so of intro here}
4755
4756 @table @option
4757 @opindex read-full-records
4758 @item --read-full-records
4759 @item -B
4760 Use in conjunction with @option{--extract} (@option{--get},
4761 @option{-x}) to read an archive which contains incomplete records, or
4762 one which has a blocking factor less than the one specified.
4763 @end table
4764
4765 @node Ignore Zeros
4766 @unnumberedsubsubsec Ignoring Blocks of Zeros
4767
4768 @cindex End-of-archive blocks, ignoring
4769 @cindex Ignoring end-of-archive blocks
4770 @opindex ignore-zeros
4771 Normally, @command{tar} stops reading when it encounters a block of zeros
4772 between file entries (which usually indicates the end of the archive).
4773 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4774 completely read an archive which contains a block of zeros before the
4775 end (i.e., a damaged archive, or one that was created by concatenating
4776 several archives together).
4777
4778 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4779 versions of @command{tar} write garbage after the end-of-archive entry,
4780 since that part of the media is never supposed to be read. @GNUTAR{}
4781 does not write after the end of an archive, but seeks to
4782 maintain compatibility among archiving utilities.
4783
4784 @table @option
4785 @item --ignore-zeros
4786 @itemx -i
4787 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4788 encountered while reading an archive. Use in conjunction with
4789 @option{--extract} or @option{--list}.
4790 @end table
4791
4792 @node Writing
4793 @subsection Changing How @command{tar} Writes Files
4794 @UNREVISED
4795
4796 @FIXME{Introductory paragraph}
4797
4798 @menu
4799 * Dealing with Old Files::
4800 * Overwrite Old Files::
4801 * Keep Old Files::
4802 * Keep Newer Files::
4803 * Unlink First::
4804 * Recursive Unlink::
4805 * Data Modification Times::
4806 * Setting Access Permissions::
4807 * Directory Modification Times and Permissions::
4808 * Writing to Standard Output::
4809 * Writing to an External Program::
4810 * remove files::
4811 @end menu
4812
4813 @node Dealing with Old Files
4814 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4815
4816 @xopindex{overwrite-dir, introduced}
4817 When extracting files, if @command{tar} discovers that the extracted
4818 file already exists, it normally replaces the file by removing it before
4819 extracting it, to prevent confusion in the presence of hard or symbolic
4820 links. (If the existing file is a symbolic link, it is removed, not
4821 followed.) However, if a directory cannot be removed because it is
4822 nonempty, @command{tar} normally overwrites its metadata (ownership,
4823 permission, etc.). The @option{--overwrite-dir} option enables this
4824 default behavior. To be more cautious and preserve the metadata of
4825 such a directory, use the @option{--no-overwrite-dir} option.
4826
4827 @cindex Overwriting old files, prevention
4828 @xopindex{keep-old-files, introduced}
4829 To be even more cautious and prevent existing files from being replaced, use
4830 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4831 to replace or update a file that already exists, i.e., a file with the
4832 same name as an archive member prevents extraction of that archive
4833 member. Instead, it reports an error.
4834
4835 @xopindex{overwrite, introduced}
4836 To be more aggressive about altering existing files, use the
4837 @option{--overwrite} option. It causes @command{tar} to overwrite
4838 existing files and to follow existing symbolic links when extracting.
4839
4840 @cindex Protecting old files
4841 Some people argue that @GNUTAR{} should not hesitate
4842 to overwrite files with other files when extracting. When extracting
4843 a @command{tar} archive, they expect to see a faithful copy of the
4844 state of the file system when the archive was created. It is debatable
4845 that this would always be a proper behavior. For example, suppose one
4846 has an archive in which @file{usr/local} is a link to
4847 @file{usr/local2}. Since then, maybe the site removed the link and
4848 renamed the whole hierarchy from @file{/usr/local2} to
4849 @file{/usr/local}. Such things happen all the time. I guess it would
4850 not be welcome at all that @GNUTAR{} removes the
4851 whole hierarchy just to make room for the link to be reinstated
4852 (unless it @emph{also} simultaneously restores the full
4853 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4854 able to remove a whole hierarchy to reestablish a symbolic link, for
4855 example, but @emph{only if} @option{--recursive-unlink} is specified
4856 to allow this behavior. In any case, single files are silently
4857 removed.
4858
4859 @xopindex{unlink-first, introduced}
4860 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4861 some cases by causing @command{tar} to remove files unconditionally
4862 before extracting them.
4863
4864 @node Overwrite Old Files
4865 @unnumberedsubsubsec Overwrite Old Files
4866
4867 @table @option
4868 @opindex overwrite
4869 @item --overwrite
4870 Overwrite existing files and directory metadata when extracting files
4871 from an archive.
4872
4873 This causes @command{tar} to write extracted files into the file system without
4874 regard to the files already on the system; i.e., files with the same
4875 names as archive members are overwritten when the archive is extracted.
4876 It also causes @command{tar} to extract the ownership, permissions,
4877 and time stamps onto any preexisting files or directories.
4878 If the name of a corresponding file name is a symbolic link, the file
4879 pointed to by the symbolic link will be overwritten instead of the
4880 symbolic link itself (if this is possible). Moreover, special devices,
4881 empty directories and even symbolic links are automatically removed if
4882 they are in the way of extraction.
4883
4884 Be careful when using the @option{--overwrite} option, particularly when
4885 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4886 can change the contents, ownership or permissions of any file on your
4887 system. Also, many systems do not take kindly to overwriting files that
4888 are currently being executed.
4889
4890 @opindex overwrite-dir
4891 @item --overwrite-dir
4892 Overwrite the metadata of directories when extracting files from an
4893 archive, but remove other files before extracting.
4894 @end table
4895
4896 @node Keep Old Files
4897 @unnumberedsubsubsec Keep Old Files
4898
4899 @table @option
4900 @opindex keep-old-files
4901 @item --keep-old-files
4902 @itemx -k
4903 Do not replace existing files from archive. The
4904 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4905 from replacing existing files with files with the same name from the
4906 archive. The @option{--keep-old-files} option is meaningless with
4907 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4908 files in the file system during extraction.
4909 @end table
4910
4911 @node Keep Newer Files
4912 @unnumberedsubsubsec Keep Newer Files
4913
4914 @table @option
4915 @opindex keep-newer-files
4916 @item --keep-newer-files
4917 Do not replace existing files that are newer than their archive
4918 copies. This option is meaningless with @option{--list} (@option{-t}).
4919 @end table
4920
4921 @node Unlink First
4922 @unnumberedsubsubsec Unlink First
4923
4924 @table @option
4925 @opindex unlink-first
4926 @item --unlink-first
4927 @itemx -U
4928 Remove files before extracting over them.
4929 This can make @command{tar} run a bit faster if you know in advance
4930 that the extracted files all need to be removed. Normally this option
4931 slows @command{tar} down slightly, so it is disabled by default.
4932 @end table
4933
4934 @node Recursive Unlink
4935 @unnumberedsubsubsec Recursive Unlink
4936
4937 @table @option
4938 @opindex recursive-unlink
4939 @item --recursive-unlink
4940 When this option is specified, try removing files and directory hierarchies
4941 before extracting over them. @emph{This is a dangerous option!}
4942 @end table
4943
4944 If you specify the @option{--recursive-unlink} option,
4945 @command{tar} removes @emph{anything} that keeps you from extracting a file
4946 as far as current permissions will allow it. This could include removal
4947 of the contents of a full directory hierarchy.
4948
4949 @node Data Modification Times
4950 @unnumberedsubsubsec Setting Data Modification Times
4951
4952 @cindex Data modification times of extracted files
4953 @cindex Modification times of extracted files
4954 Normally, @command{tar} sets the data modification times of extracted
4955 files to the corresponding times recorded for the files in the archive, but
4956 limits the permissions of extracted files by the current @code{umask}
4957 setting.
4958
4959 To set the data modification times of extracted files to the time when
4960 the files were extracted, use the @option{--touch} (@option{-m}) option in
4961 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4962
4963 @table @option
4964 @opindex touch
4965 @item --touch
4966 @itemx -m
4967 Sets the data modification time of extracted archive members to the time
4968 they were extracted, not the time recorded for them in the archive.
4969 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4970 @end table
4971
4972 @node Setting Access Permissions
4973 @unnumberedsubsubsec Setting Access Permissions
4974
4975 @cindex Permissions of extracted files
4976 @cindex Modes of extracted files
4977 To set the modes (access permissions) of extracted files to those
4978 recorded for those files in the archive, use @option{--same-permissions}
4979 in conjunction with the @option{--extract} (@option{--get},
4980 @option{-x}) operation.
4981
4982 @table @option
4983 @opindex preserve-permissions
4984 @opindex same-permissions
4985 @item --preserve-permissions
4986 @itemx --same-permissions
4987 @c @itemx --ignore-umask
4988 @itemx -p
4989 Set modes of extracted archive members to those recorded in the
4990 archive, instead of current umask settings. Use in conjunction with
4991 @option{--extract} (@option{--get}, @option{-x}).
4992 @end table
4993
4994 @node Directory Modification Times and Permissions
4995 @unnumberedsubsubsec Directory Modification Times and Permissions
4996
4997 After successfully extracting a file member, @GNUTAR{} normally
4998 restores its permissions and modification times, as described in the
4999 previous sections. This cannot be done for directories, because
5000 after extracting a directory @command{tar} will almost certainly
5001 extract files into that directory and this will cause the directory
5002 modification time to be updated. Moreover, restoring that directory
5003 permissions may not permit file creation within it. Thus, restoring
5004 directory permissions and modification times must be delayed at least
5005 until all files have been extracted into that directory. @GNUTAR{}
5006 restores directories using the following approach.
5007
5008 The extracted directories are created with the mode specified in the
5009 archive, as modified by the umask of the user, which gives sufficient
5010 permissions to allow file creation. The meta-information about the
5011 directory is recorded in the temporary list of directories. When
5012 preparing to extract next archive member, @GNUTAR{} checks if the
5013 directory prefix of this file contains the remembered directory. If
5014 it does not, the program assumes that all files have been extracted
5015 into that directory, restores its modification time and permissions
5016 and removes its entry from the internal list. This approach allows
5017 to correctly restore directory meta-information in the majority of
5018 cases, while keeping memory requirements sufficiently small. It is
5019 based on the fact, that most @command{tar} archives use the predefined
5020 order of members: first the directory, then all the files and
5021 subdirectories in that directory.
5022
5023 However, this is not always true. The most important exception are
5024 incremental archives (@pxref{Incremental Dumps}). The member order in
5025 an incremental archive is reversed: first all directory members are
5026 stored, followed by other (non-directory) members. So, when extracting
5027 from incremental archives, @GNUTAR{} alters the above procedure. It
5028 remembers all restored directories, and restores their meta-data
5029 only after the entire archive has been processed. Notice, that you do
5030 not need to specify any special options for that, as @GNUTAR{}
5031 automatically detects archives in incremental format.
5032
5033 There may be cases, when such processing is required for normal archives
5034 too. Consider the following example:
5035
5036 @smallexample
5037 @group
5038 $ @kbd{tar --no-recursion -cvf archive \
5039 foo foo/file1 bar bar/file foo/file2}
5040 foo/
5041 foo/file1
5042 bar/
5043 bar/file
5044 foo/file2
5045 @end group
5046 @end smallexample
5047
5048 During the normal operation, after encountering @file{bar}
5049 @GNUTAR{} will assume that all files from the directory @file{foo}
5050 were already extracted and will therefore restore its timestamp and
5051 permission bits. However, after extracting @file{foo/file2} the
5052 directory timestamp will be offset again.
5053
5054 To correctly restore directory meta-information in such cases, use
5055 @option{delay-directory-restore} command line option:
5056
5057 @table @option
5058 @opindex delay-directory-restore
5059 @item --delay-directory-restore
5060 Delays restoring of the modification times and permissions of extracted
5061 directories until the end of extraction. This way, correct
5062 meta-information is restored even if the archive has unusual member
5063 ordering.
5064
5065 @opindex no-delay-directory-restore
5066 @item --no-delay-directory-restore
5067 Cancel the effect of the previous @option{--delay-directory-restore}.
5068 Use this option if you have used @option{--delay-directory-restore} in
5069 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5070 temporarily disable it.
5071 @end table
5072
5073 @node Writing to Standard Output
5074 @unnumberedsubsubsec Writing to Standard Output
5075
5076 @cindex Writing extracted files to standard output
5077 @cindex Standard output, writing extracted files to
5078 To write the extracted files to the standard output, instead of
5079 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5080 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5081 extracting files to send them through a pipe, and do not need to
5082 preserve them in the file system. If you extract multiple members,
5083 they appear on standard output concatenated, in the order they are
5084 found in the archive.
5085
5086 @table @option
5087 @opindex to-stdout
5088 @item --to-stdout
5089 @itemx -O
5090 Writes files to the standard output. Use only in conjunction with
5091 @option{--extract} (@option{--get}, @option{-x}). When this option is
5092 used, instead of creating the files specified, @command{tar} writes
5093 the contents of the files extracted to its standard output. This may
5094 be useful if you are only extracting the files in order to send them
5095 through a pipe. This option is meaningless with @option{--list}
5096 (@option{-t}).
5097 @end table
5098
5099 This can be useful, for example, if you have a tar archive containing
5100 a big file and don't want to store the file on disk before processing
5101 it. You can use a command like this:
5102
5103 @smallexample
5104 tar -xOzf foo.tgz bigfile | process
5105 @end smallexample
5106
5107 or even like this if you want to process the concatenation of the files:
5108
5109 @smallexample
5110 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5111 @end smallexample
5112
5113 However, @option{--to-command} may be more convenient for use with
5114 multiple files. See the next section.
5115
5116 @node Writing to an External Program
5117 @unnumberedsubsubsec Writing to an External Program
5118
5119 You can instruct @command{tar} to send the contents of each extracted
5120 file to the standard input of an external program:
5121
5122 @table @option
5123 @opindex to-command
5124 @item --to-command=@var{command}
5125 Extract files and pipe their contents to the standard input of
5126 @var{command}. When this option is used, instead of creating the
5127 files specified, @command{tar} invokes @var{command} and pipes the
5128 contents of the files to its standard output. @var{Command} may
5129 contain command line arguments. The program is executed via
5130 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5131 extracted. Non-regular files (directories, etc.) are ignored when this
5132 option is used.
5133 @end table
5134
5135 The command can obtain the information about the file it processes
5136 from the following environment variables:
5137
5138 @table @env
5139 @vrindex TAR_FILETYPE, to-command environment
5140 @item TAR_FILETYPE
5141 Type of the file. It is a single letter with the following meaning:
5142
5143 @multitable @columnfractions 0.10 0.90
5144 @item f @tab Regular file
5145 @item d @tab Directory
5146 @item l @tab Symbolic link
5147 @item h @tab Hard link
5148 @item b @tab Block device
5149 @item c @tab Character device
5150 @end multitable
5151
5152 Currently only regular files are supported.
5153
5154 @vrindex TAR_MODE, to-command environment
5155 @item TAR_MODE
5156 File mode, an octal number.
5157
5158 @vrindex TAR_FILENAME, to-command environment
5159 @item TAR_FILENAME
5160 The name of the file.
5161
5162 @vrindex TAR_REALNAME, to-command environment
5163 @item TAR_REALNAME
5164 Name of the file as stored in the archive.
5165
5166 @vrindex TAR_UNAME, to-command environment
5167 @item TAR_UNAME
5168 Name of the file owner.
5169
5170 @vrindex TAR_GNAME, to-command environment
5171 @item TAR_GNAME
5172 Name of the file owner group.
5173
5174 @vrindex TAR_ATIME, to-command environment
5175 @item TAR_ATIME
5176 Time of last access. It is a decimal number, representing seconds
5177 since the epoch. If the archive provides times with nanosecond
5178 precision, the nanoseconds are appended to the timestamp after a
5179 decimal point.
5180
5181 @vrindex TAR_MTIME, to-command environment
5182 @item TAR_MTIME
5183 Time of last modification.
5184
5185 @vrindex TAR_CTIME, to-command environment
5186 @item TAR_CTIME
5187 Time of last status change.
5188
5189 @vrindex TAR_SIZE, to-command environment
5190 @item TAR_SIZE
5191 Size of the file.
5192
5193 @vrindex TAR_UID, to-command environment
5194 @item TAR_UID
5195 UID of the file owner.
5196
5197 @vrindex TAR_GID, to-command environment
5198 @item TAR_GID
5199 GID of the file owner.
5200 @end table
5201
5202 In addition to these variables, @env{TAR_VERSION} contains the
5203 @GNUTAR{} version number.
5204
5205 If @var{command} exits with a non-0 status, @command{tar} will print
5206 an error message similar to the following:
5207
5208 @smallexample
5209 tar: 2345: Child returned status 1
5210 @end smallexample
5211
5212 Here, @samp{2345} is the PID of the finished process.
5213
5214 If this behavior is not wanted, use @option{--ignore-command-error}:
5215
5216 @table @option
5217 @opindex ignore-command-error
5218 @item --ignore-command-error
5219 Ignore exit codes of subprocesses. Notice that if the program
5220 exits on signal or otherwise terminates abnormally, the error message
5221 will be printed even if this option is used.
5222
5223 @opindex no-ignore-command-error
5224 @item --no-ignore-command-error
5225 Cancel the effect of any previous @option{--ignore-command-error}
5226 option. This option is useful if you have set
5227 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5228 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5229 @end table
5230
5231 @node remove files
5232 @unnumberedsubsubsec Removing Files
5233
5234 @FIXME{The section is too terse. Something more to add? An example,
5235 maybe?}
5236
5237 @table @option
5238 @opindex remove-files
5239 @item --remove-files
5240 Remove files after adding them to the archive.
5241 @end table
5242
5243 @node Scarce
5244 @subsection Coping with Scarce Resources
5245 @UNREVISED
5246
5247 @cindex Small memory
5248 @cindex Running out of space
5249
5250 @menu
5251 * Starting File::
5252 * Same Order::
5253 @end menu
5254
5255 @node Starting File
5256 @unnumberedsubsubsec Starting File
5257
5258 @table @option
5259 @opindex starting-file
5260 @item --starting-file=@var{name}
5261 @itemx -K @var{name}
5262 Starts an operation in the middle of an archive. Use in conjunction
5263 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5264 @end table
5265
5266 @cindex Middle of the archive, starting in the
5267 If a previous attempt to extract files failed due to lack of disk
5268 space, you can use @option{--starting-file=@var{name}} (@option{-K
5269 @var{name}}) to start extracting only after member @var{name} of the
5270 archive. This assumes, of course, that there is now free space, or
5271 that you are now extracting into a different file system. (You could
5272 also choose to suspend @command{tar}, remove unnecessary files from
5273 the file system, and then restart the same @command{tar} operation.
5274 In this case, @option{--starting-file} is not necessary.
5275 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
5276
5277 @node Same Order
5278 @unnumberedsubsubsec Same Order
5279
5280 @table @option
5281 @cindex Large lists of file names on small machines
5282 @opindex same-order
5283 @opindex preserve-order
5284 @item --same-order
5285 @itemx --preserve-order
5286 @itemx -s
5287 To process large lists of file names on machines with small amounts of
5288 memory. Use in conjunction with @option{--compare} (@option{--diff},
5289 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5290 (@option{--get}, @option{-x}).
5291 @end table
5292
5293 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5294 names to be listed or extracted is sorted in the same order as the
5295 files in the archive. This allows a large list of names to be used,
5296 even on a small machine that would not otherwise be able to hold all
5297 the names in memory at the same time. Such a sorted list can easily be
5298 created by running @samp{tar -t} on the archive and editing its output.
5299
5300 This option is probably never needed on modern computer systems.
5301
5302 @node backup
5303 @section Backup options
5304
5305 @cindex backup options
5306
5307 @GNUTAR{} offers options for making backups of files
5308 before writing new versions. These options control the details of
5309 these backups. They may apply to the archive itself before it is
5310 created or rewritten, as well as individual extracted members. Other
5311 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5312 and @command{mv}, for example) offer similar options.
5313
5314 Backup options may prove unexpectedly useful when extracting archives
5315 containing many members having identical name, or when extracting archives
5316 on systems having file name limitations, making different members appear
5317 has having similar names through the side-effect of name truncation.
5318 (This is true only if we have a good scheme for truncated backup names,
5319 which I'm not sure at all: I suspect work is needed in this area.)
5320 When any existing file is backed up before being overwritten by extraction,
5321 then clashing files are automatically be renamed to be unique, and the
5322 true name is kept for only the last file of a series of clashing files.
5323 By using verbose mode, users may track exactly what happens.
5324
5325 At the detail level, some decisions are still experimental, and may
5326 change in the future, we are waiting comments from our users. So, please
5327 do not learn to depend blindly on the details of the backup features.
5328 For example, currently, directories themselves are never renamed through
5329 using these options, so, extracting a file over a directory still has
5330 good chances to fail. Also, backup options apply to created archives,
5331 not only to extracted members. For created archives, backups will not
5332 be attempted when the archive is a block or character device, or when it
5333 refers to a remote file.
5334
5335 For the sake of simplicity and efficiency, backups are made by renaming old
5336 files prior to creation or extraction, and not by copying. The original
5337 name is restored if the file creation fails. If a failure occurs after a
5338 partial extraction of a file, both the backup and the partially extracted
5339 file are kept.
5340
5341 @table @samp
5342 @item --backup[=@var{method}]
5343 @opindex backup
5344 @vindex VERSION_CONTROL
5345 @cindex backups
5346 Back up files that are about to be overwritten or removed.
5347 Without this option, the original versions are destroyed.
5348
5349 Use @var{method} to determine the type of backups made.
5350 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5351 environment variable. And if @env{VERSION_CONTROL} is not set,
5352 use the @samp{existing} method.
5353
5354 @vindex version-control @r{Emacs variable}
5355 This option corresponds to the Emacs variable @samp{version-control};
5356 the same values for @var{method} are accepted as in Emacs. This option
5357 also allows more descriptive names. The valid @var{method}s are:
5358
5359 @table @samp
5360 @item t
5361 @itemx numbered
5362 @cindex numbered @r{backup method}
5363 Always make numbered backups.
5364
5365 @item nil
5366 @itemx existing
5367 @cindex existing @r{backup method}
5368 Make numbered backups of files that already have them, simple backups
5369 of the others.
5370
5371 @item never
5372 @itemx simple
5373 @cindex simple @r{backup method}
5374 Always make simple backups.
5375
5376 @end table
5377
5378 @item --suffix=@var{suffix}
5379 @opindex suffix
5380 @cindex backup suffix
5381 @vindex SIMPLE_BACKUP_SUFFIX
5382 Append @var{suffix} to each backup file made with @option{--backup}. If this
5383 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5384 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5385 set, the default is @samp{~}, just as in Emacs.
5386
5387 @end table
5388
5389 @node Applications
5390 @section Notable @command{tar} Usages
5391 @UNREVISED
5392
5393 @FIXME{Using Unix file linking capability to recreate directory
5394 structures---linking files into one subdirectory and then
5395 @command{tar}ring that directory.}
5396
5397 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5398
5399 @findex uuencode
5400 You can easily use archive files to transport a group of files from
5401 one system to another: put all relevant files into an archive on one
5402 computer system, transfer the archive to another system, and extract
5403 the contents there. The basic transfer medium might be magnetic tape,
5404 Internet FTP, or even electronic mail (though you must encode the
5405 archive with @command{uuencode} in order to transport it properly by
5406 mail). Both machines do not have to use the same operating system, as
5407 long as they both support the @command{tar} program.
5408
5409 For example, here is how you might copy a directory's contents from
5410 one disk to another, while preserving the dates, modes, owners and
5411 link-structure of all the files therein. In this case, the transfer
5412 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5413
5414 @smallexample
5415 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5416 @end smallexample
5417
5418 @noindent
5419 You can avoid subshells by using @option{-C} option:
5420
5421 @smallexample
5422 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5423 @end smallexample
5424
5425 @noindent
5426 The command also works using short option forms:
5427
5428 @smallexample
5429 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5430 | (cd targetdir; tar --extract --file=-)}
5431 # Or:
5432 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5433 | tar --directory targetdir --extract --file=-}
5434 @end smallexample
5435
5436 @noindent
5437 This is one of the easiest methods to transfer a @command{tar} archive.
5438
5439 @node looking ahead
5440 @section Looking Ahead: The Rest of this Manual
5441
5442 You have now seen how to use all eight of the operations available to
5443 @command{tar}, and a number of the possible options. The next chapter
5444 explains how to choose and change file and archive names, how to use
5445 files to store names of other files which you can then call as
5446 arguments to @command{tar} (this can help you save time if you expect to
5447 archive the same list of files a number of times), and so forth.
5448 @FIXME{in case it's not obvious, i'm making this up in some sense
5449 based on my limited memory of what the next chapter *really* does. i
5450 just wanted to flesh out this final section a little bit so i'd
5451 remember to stick it in here. :-)}
5452
5453 If there are too many files to conveniently list on the command line,
5454 you can list the names in a file, and @command{tar} will read that file.
5455 @xref{files}.
5456
5457 There are various ways of causing @command{tar} to skip over some files,
5458 and not archive them. @xref{Choosing}.
5459
5460 @node Backups
5461 @chapter Performing Backups and Restoring Files
5462 @UNREVISED
5463
5464 @GNUTAR{} is distributed along with the scripts
5465 which the Free Software Foundation uses for performing backups. There
5466 is no corresponding scripts available yet for doing restoration of
5467 files. Even if there is a good chance those scripts may be satisfying
5468 to you, they are not the only scripts or methods available for doing
5469 backups and restore. You may well create your own, or use more
5470 sophisticated packages dedicated to that purpose.
5471
5472 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5473 Automatic Network Disk Archiver), a backup system developed by James
5474 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5475 This is free software, and it is available at these places:
5476
5477 @smallexample
5478 http://www.cs.umd.edu/projects/amanda/amanda.html
5479 ftp://ftp.cs.umd.edu/pub/amanda
5480 @end smallexample
5481
5482 @FIXME{
5483
5484 Here is a possible plan for a future documentation about the backuping
5485 scripts which are provided within the @GNUTAR{}
5486 distribution.
5487
5488 @itemize @bullet
5489 @item dumps
5490 @itemize @minus
5491 @item what are dumps
5492 @item different levels of dumps
5493 @itemize +
5494 @item full dump = dump everything
5495 @item level 1, level 2 dumps etc
5496 A level @var{n} dump dumps everything changed since the last level
5497 @var{n}-1 dump (?)
5498 @end itemize
5499 @item how to use scripts for dumps (ie, the concept)
5500 @itemize +
5501 @item scripts to run after editing backup specs (details)
5502 @end itemize
5503 @item Backup Specs, what is it.
5504 @itemize +
5505 @item how to customize
5506 @item actual text of script [/sp/dump/backup-specs]
5507 @end itemize
5508 @item Problems
5509 @itemize +
5510 @item rsh doesn't work
5511 @item rtape isn't installed
5512 @item (others?)
5513 @end itemize
5514 @item the @option{--incremental} option of tar
5515 @item tapes
5516 @itemize +
5517 @item write protection
5518 @item types of media, different sizes and types, useful for different things
5519 @item files and tape marks
5520 one tape mark between files, two at end.
5521 @item positioning the tape
5522 MT writes two at end of write,
5523 backspaces over one when writing again.
5524 @end itemize
5525 @end itemize
5526 @end itemize
5527 }
5528
5529 This chapter documents both the provided shell scripts and @command{tar}
5530 options which are more specific to usage as a backup tool.
5531
5532 To @dfn{back up} a file system means to create archives that contain
5533 all the files in that file system. Those archives can then be used to
5534 restore any or all of those files (for instance if a disk crashes or a
5535 file is accidentally deleted). File system @dfn{backups} are also
5536 called @dfn{dumps}.
5537
5538 @menu
5539 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5540 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5541 * Backup Levels:: Levels of Backups
5542 * Backup Parameters:: Setting Parameters for Backups and Restoration
5543 * Scripted Backups:: Using the Backup Scripts
5544 * Scripted Restoration:: Using the Restore Script
5545 @end menu
5546
5547 @node Full Dumps
5548 @section Using @command{tar} to Perform Full Dumps
5549 @UNREVISED
5550
5551 @cindex full dumps
5552 @cindex dumps, full
5553
5554 @cindex corrupted archives
5555 Full dumps should only be made when no other people or programs
5556 are modifying files in the file system. If files are modified while
5557 @command{tar} is making the backup, they may not be stored properly in
5558 the archive, in which case you won't be able to restore them if you
5559 have to. (Files not being modified are written with no trouble, and do
5560 not corrupt the entire archive.)
5561
5562 You will want to use the @option{--label=@var{archive-label}}
5563 (@option{-V @var{archive-label}}) option to give the archive a
5564 volume label, so you can tell what this archive is even if the label
5565 falls off the tape, or anything like that.
5566
5567 Unless the file system you are dumping is guaranteed to fit on
5568 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5569 Make sure you have enough tapes on hand to complete the backup.
5570
5571 If you want to dump each file system separately you will need to use
5572 the @option{--one-file-system} option to prevent
5573 @command{tar} from crossing file system boundaries when storing
5574 (sub)directories.
5575
5576 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5577 option is not needed, since this is a complete copy of everything in
5578 the file system, and a full restore from this backup would only be
5579 done onto a completely
5580 empty disk.
5581
5582 Unless you are in a hurry, and trust the @command{tar} program (and your
5583 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5584 option, to make sure your files really made it onto the dump properly.
5585 This will also detect cases where the file was modified while (or just
5586 after) it was being archived. Not all media (notably cartridge tapes)
5587 are capable of being verified, unfortunately.
5588
5589 @node Incremental Dumps
5590 @section Using @command{tar} to Perform Incremental Dumps
5591
5592 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5593 stores additional metadata so that exact state of the file system
5594 can be restored when extracting the archive.
5595
5596 @GNUTAR{} currently offers two options for handling incremental
5597 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5598 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5599
5600 @opindex listed-incremental
5601 The option @option{--listed-incremental} instructs tar to operate on
5602 an incremental archive with additional metadata stored in a standalone
5603 file, called a @dfn{snapshot file}. The purpose of this file is to help
5604 determine which files have been changed, added or deleted since the
5605 last backup, so that the next incremental backup will contain only
5606 modified files. The name of the snapshot file is given as an argument
5607 to the option:
5608
5609 @table @option
5610 @item --listed-incremental=@var{file}
5611 @itemx -g @var{file}
5612 Handle incremental backups with snapshot data in @var{file}.
5613 @end table
5614
5615 To create an incremental backup, you would use
5616 @option{--listed-incremental} together with @option{--create}
5617 (@pxref{create}). For example:
5618
5619 @smallexample
5620 $ @kbd{tar --create \
5621 --file=archive.1.tar \
5622 --listed-incremental=/var/log/usr.snar \
5623 /usr}
5624 @end smallexample
5625
5626 This will create in @file{archive.1.tar} an incremental backup of
5627 the @file{/usr} file system, storing additional metadata in the file
5628 @file{/var/log/usr.snar}. If this file does not exist, it will be
5629 created. The created archive will then be a @dfn{level 0 backup};
5630 please see the next section for more on backup levels.
5631
5632 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5633 determines which files are modified. In this case only these files will be
5634 stored in the archive. Suppose, for example, that after running the
5635 above command, you delete file @file{/usr/doc/old} and create
5636 directory @file{/usr/local/db} with the following contents:
5637
5638 @smallexample
5639 $ @kbd{ls /usr/local/db}
5640 /usr/local/db/data
5641 /usr/local/db/index
5642 @end smallexample
5643
5644 Some time later you create another incremental backup. You will
5645 then see:
5646
5647 @smallexample
5648 $ @kbd{tar --create \
5649 --file=archive.2.tar \
5650 --listed-incremental=/var/log/usr.snar \
5651 /usr}
5652 tar: usr/local/db: Directory is new
5653 usr/local/db/
5654 usr/local/db/data
5655 usr/local/db/index
5656 @end smallexample
5657
5658 @noindent
5659 The created archive @file{archive.2.tar} will contain only these
5660 three members. This archive is called a @dfn{level 1 backup}. Notice
5661 that @file{/var/log/usr.snar} will be updated with the new data, so if
5662 you plan to create more @samp{level 1} backups, it is necessary to
5663 create a working copy of the snapshot file before running
5664 @command{tar}. The above example will then be modified as follows:
5665
5666 @smallexample
5667 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5668 $ @kbd{tar --create \
5669 --file=archive.2.tar \
5670 --listed-incremental=/var/log/usr.snar-1 \
5671 /usr}
5672 @end smallexample
5673
5674 Incremental dumps depend crucially on time stamps, so the results are
5675 unreliable if you modify a file's time stamps during dumping (e.g.,
5676 with the @option{--atime-preserve=replace} option), or if you set the clock
5677 backwards.
5678
5679 @cindex Device numbers, using in incremental backups
5680 Metadata stored in snapshot files include device numbers, which,
5681 obviously is supposed to be a non-volatile value. However, it turns
5682 out that NFS devices have undependable values when an automounter
5683 gets in the picture. This can lead to a great deal of spurious
5684 redumping in incremental dumps, so it is somewhat useless to compare
5685 two NFS devices numbers over time. The solution implemented currently
5686 is to considers all NFS devices as being equal when it comes to
5687 comparing directories; this is fairly gross, but there does not seem
5688 to be a better way to go.
5689
5690 If you are using the @i{Linux} kernel, the device numbers can also
5691 change when upgrading to some newer versions of the kernel. This can
5692 cause the next backup to be full backup on the affected filesystems.
5693 @xref{Fixing Snapshot Files}, for the information on how to handle this case.
5694
5695 Note that incremental archives use @command{tar} extensions and may
5696 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5697
5698 @xopindex{listed-incremental, using with @option{--extract}}
5699 @xopindex{extract, using with @option{--listed-incremental}}
5700 To extract from the incremental dumps, use
5701 @option{--listed-incremental} together with @option{--extract}
5702 option (@pxref{extracting files}). In this case, @command{tar} does
5703 not need to access snapshot file, since all the data necessary for
5704 extraction are stored in the archive itself. So, when extracting, you
5705 can give whatever argument to @option{--listed-incremental}, the usual
5706 practice is to use @option{--listed-incremental=/dev/null}.
5707 Alternatively, you can use @option{--incremental}, which needs no
5708 arguments. In general, @option{--incremental} (@option{-G}) can be
5709 used as a shortcut for @option{--listed-incremental} when listing or
5710 extracting incremental backups (for more information, regarding this
5711 option, @pxref{incremental-op}).
5712
5713 When extracting from the incremental backup @GNUTAR{} attempts to
5714 restore the exact state the file system had when the archive was
5715 created. In particular, it will @emph{delete} those files in the file
5716 system that did not exist in their directories when the archive was
5717 created. If you have created several levels of incremental files,
5718 then in order to restore the exact contents the file system had when
5719 the last level was created, you will need to restore from all backups
5720 in turn. Continuing our example, to restore the state of @file{/usr}
5721 file system, one would do@footnote{Notice, that since both archives
5722 were created without @option{-P} option (@pxref{absolute}), these
5723 commands should be run from the root file system.}:
5724
5725 @smallexample
5726 $ @kbd{tar --extract \
5727 --listed-incremental=/dev/null \
5728 --file archive.1.tar}
5729 $ @kbd{tar --extract \
5730 --listed-incremental=/dev/null \
5731 --file archive.2.tar}
5732 @end smallexample
5733
5734 To list the contents of an incremental archive, use @option{--list}
5735 (@pxref{list}), as usual. To obtain more information about the
5736 archive, use @option{--listed-incremental} or @option{--incremental}
5737 combined with two @option{--verbose} options@footnote{Two
5738 @option{--verbose} options were selected to avoid breaking usual
5739 verbose listing output (@option{--list --verbose}) when using in
5740 scripts.
5741
5742 @xopindex{incremental, using with @option{--list}}
5743 @xopindex{listed-incremental, using with @option{--list}}
5744 @xopindex{list, using with @option{--incremental}}
5745 @xopindex{list, using with @option{--listed-incremental}}
5746 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5747 contents of the DUMPDIR header (with terminating nulls) when
5748 @option{--incremental} or @option{--listed-incremental} option was
5749 given, no matter what the verbosity level. This behavior, and,
5750 especially, the binary output it produced were considered inconvenient
5751 and were changed in version 1.16}:
5752
5753 @smallexample
5754 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5755 @end smallexample
5756
5757 This command will print, for each directory in the archive, the list
5758 of files in that directory at the time the archive was created. This
5759 information is put out in a format which is both human-readable and
5760 unambiguous for a program: each file name is printed as
5761
5762 @smallexample
5763 @var{x} @var{file}
5764 @end smallexample
5765
5766 @noindent
5767 where @var{x} is a letter describing the status of the file: @samp{Y}
5768 if the file is present in the archive, @samp{N} if the file is not
5769 included in the archive, or a @samp{D} if the file is a directory (and
5770 is included in the archive). @xref{Dumpdir}, for the detailed
5771 description of dumpdirs and status codes. Each such
5772 line is terminated by a newline character. The last line is followed
5773 by an additional newline to indicate the end of the data.
5774
5775 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5776 gives the same behavior as @option{--listed-incremental} when used
5777 with @option{--list} and @option{--extract} options. When used with
5778 @option{--create} option, it creates an incremental archive without
5779 creating snapshot file. Thus, it is impossible to create several
5780 levels of incremental backups with @option{--incremental} option.
5781
5782 @node Backup Levels
5783 @section Levels of Backups
5784
5785 An archive containing all the files in the file system is called a
5786 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5787 creating a full dump every day. This strategy, however, would waste a
5788 substantial amount of archive media and user time, as unchanged files
5789 are daily re-archived.
5790
5791 It is more efficient to do a full dump only occasionally. To back up
5792 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5793 one} dump archives all the files that have changed since the last full
5794 dump.
5795
5796 A typical dump strategy would be to perform a full dump once a week,
5797 and a level one dump once a day. This means some versions of files
5798 will in fact be archived more than once, but this dump strategy makes
5799 it possible to restore a file system to within one day of accuracy by
5800 only extracting two archives---the last weekly (full) dump and the
5801 last daily (level one) dump. The only information lost would be in
5802 files changed or created since the last daily backup. (Doing dumps
5803 more than once a day is usually not worth the trouble).
5804
5805 @GNUTAR{} comes with scripts you can use to do full
5806 and level-one (actually, even level-two and so on) dumps. Using
5807 scripts (shell programs) to perform backups and restoration is a
5808 convenient and reliable alternative to typing out file name lists
5809 and @command{tar} commands by hand.
5810
5811 Before you use these scripts, you need to edit the file
5812 @file{backup-specs}, which specifies parameters used by the backup
5813 scripts and by the restore script. This file is usually located
5814 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5815 detailed description. Once the backup parameters are set, you can
5816 perform backups or restoration by running the appropriate script.
5817
5818 The name of the backup script is @code{backup}. The name of the
5819 restore script is @code{restore}. The following sections describe
5820 their use in detail.
5821
5822 @emph{Please Note:} The backup and restoration scripts are
5823 designed to be used together. While it is possible to restore files by
5824 hand from an archive which was created using a backup script, and to create
5825 an archive by hand which could then be extracted using the restore script,
5826 it is easier to use the scripts. @xref{Incremental Dumps}, before
5827 making such an attempt.
5828
5829 @node Backup Parameters
5830 @section Setting Parameters for Backups and Restoration
5831
5832 The file @file{backup-specs} specifies backup parameters for the
5833 backup and restoration scripts provided with @command{tar}. You must
5834 edit @file{backup-specs} to fit your system configuration and schedule
5835 before using these scripts.
5836
5837 Syntactically, @file{backup-specs} is a shell script, containing
5838 mainly variable assignments. However, any valid shell construct
5839 is allowed in this file. Particularly, you may wish to define
5840 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5841 For more information about shell script syntax, please refer to
5842 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5843 g_02, the definition of the Shell Command Language}. See also
5844 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5845
5846 The shell variables controlling behavior of @code{backup} and
5847 @code{restore} are described in the following subsections.
5848
5849 @menu
5850 * General-Purpose Variables::
5851 * Magnetic Tape Control::
5852 * User Hooks::
5853 * backup-specs example:: An Example Text of @file{Backup-specs}
5854 @end menu
5855
5856 @node General-Purpose Variables
5857 @subsection General-Purpose Variables
5858
5859 @defvr {Backup variable} ADMINISTRATOR
5860 The user name of the backup administrator. @code{Backup} scripts
5861 sends a backup report to this address.
5862 @end defvr
5863
5864 @defvr {Backup variable} BACKUP_HOUR
5865 The hour at which the backups are done. This can be a number from 0
5866 to 23, or the time specification in form @var{hours}:@var{minutes},
5867 or the string @samp{now}.
5868
5869 This variable is used by @code{backup}. Its value may be overridden
5870 using @option{--time} option (@pxref{Scripted Backups}).
5871 @end defvr
5872
5873 @defvr {Backup variable} TAPE_FILE
5874
5875 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5876 is a remote archive (@pxref{remote-dev}), backup script will suppose
5877 that your @command{mt} is able to access remote devices. If @var{RSH}
5878 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5879 invocations of @command{mt}.
5880 @end defvr
5881
5882 @defvr {Backup variable} BLOCKING
5883
5884 The blocking factor @command{tar} will use when writing the dump archive.
5885 @xref{Blocking Factor}.
5886 @end defvr
5887
5888 @defvr {Backup variable} BACKUP_DIRS
5889
5890 A list of file systems to be dumped (for @code{backup}), or restored
5891 (for @code{restore}). You can include any directory
5892 name in the list --- subdirectories on that file system will be
5893 included, regardless of how they may look to other networked machines.
5894 Subdirectories on other file systems will be ignored.
5895
5896 The host name specifies which host to run @command{tar} on, and should
5897 normally be the host that actually contains the file system. However,
5898 the host machine must have @GNUTAR{} installed, and
5899 must be able to access the directory containing the backup scripts and
5900 their support files using the same file name that is used on the
5901 machine where the scripts are run (i.e., what @command{pwd} will print
5902 when in that directory on that machine). If the host that contains
5903 the file system does not have this capability, you can specify another
5904 host as long as it can access the file system through NFS.
5905
5906 If the list of file systems is very long you may wish to put it
5907 in a separate file. This file is usually named
5908 @file{/etc/backup/dirs}, but this name may be overridden in
5909 @file{backup-specs} using @code{DIRLIST} variable.
5910 @end defvr
5911
5912 @defvr {Backup variable} DIRLIST
5913
5914 The name of the file that contains a list of file systems to backup
5915 or restore. By default it is @file{/etc/backup/dirs}.
5916 @end defvr
5917
5918 @defvr {Backup variable} BACKUP_FILES
5919
5920 A list of individual files to be dumped (for @code{backup}), or restored
5921 (for @code{restore}). These should be accessible from the machine on
5922 which the backup script is run.
5923
5924 If the list of file systems is very long you may wish to store it
5925 in a separate file. This file is usually named
5926 @file{/etc/backup/files}, but this name may be overridden in
5927 @file{backup-specs} using @code{FILELIST} variable.
5928 @end defvr
5929
5930 @defvr {Backup variable} FILELIST
5931
5932 The name of the file that contains a list of individual files to backup
5933 or restore. By default it is @file{/etc/backup/files}.
5934 @end defvr
5935
5936 @defvr {Backup variable} MT
5937
5938 Full file name of @command{mt} binary.
5939 @end defvr
5940
5941 @defvr {Backup variable} RSH
5942 @anchor{RSH}
5943 Full file name of @command{rsh} binary or its equivalent. You may wish to
5944 set it to @code{ssh}, to improve security. In this case you will have
5945 to use public key authentication.
5946 @end defvr
5947
5948 @defvr {Backup variable} RSH_COMMAND
5949
5950 Full file name of @command{rsh} binary on remote machines. This will
5951 be passed via @option{--rsh-command} option to the remote invocation
5952 of @GNUTAR{}.
5953 @end defvr
5954
5955 @defvr {Backup variable} VOLNO_FILE
5956
5957 Name of temporary file to hold volume numbers. This needs to be accessible
5958 by all the machines which have file systems to be dumped.
5959 @end defvr
5960
5961 @defvr {Backup variable} XLIST
5962
5963 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5964 located on the remote machine and containing the list of files to
5965 be excluded from the backup. Exclude file lists are searched in
5966 /etc/tar-backup directory. A common use for exclude file lists
5967 is to exclude files containing security-sensitive information
5968 (e.g., @file{/etc/shadow} from backups).
5969
5970 This variable affects only @code{backup}.
5971 @end defvr
5972
5973 @defvr {Backup variable} SLEEP_TIME
5974
5975 Time to sleep between dumps of any two successive file systems
5976
5977 This variable affects only @code{backup}.
5978 @end defvr
5979
5980 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5981
5982 Script to be run when it's time to insert a new tape in for the next
5983 volume. Administrators may want to tailor this script for their site.
5984 If this variable isn't set, @GNUTAR{} will display its built-in
5985 prompt, and will expect confirmation from the console. For the
5986 description of the default prompt, see @ref{change volume prompt}.
5987
5988 @end defvr
5989
5990 @defvr {Backup variable} SLEEP_MESSAGE
5991
5992 Message to display on the terminal while waiting for dump time. Usually
5993 this will just be some literal text.
5994 @end defvr
5995
5996 @defvr {Backup variable} TAR
5997
5998 Full file name of the @GNUTAR{} executable. If this is not set, backup
5999 scripts will search @command{tar} in the current shell path.
6000 @end defvr
6001
6002 @node Magnetic Tape Control
6003 @subsection Magnetic Tape Control
6004
6005 Backup scripts access tape device using special @dfn{hook functions}.
6006 These functions take a single argument -- the name of the tape
6007 device. Their names are kept in the following variables:
6008
6009 @defvr {Backup variable} MT_BEGIN
6010 The name of @dfn{begin} function. This function is called before
6011 accessing the drive. By default it retensions the tape:
6012
6013 @smallexample
6014 MT_BEGIN=mt_begin
6015
6016 mt_begin() @{
6017 mt -f "$1" retension
6018 @}
6019 @end smallexample
6020 @end defvr
6021
6022 @defvr {Backup variable} MT_REWIND
6023 The name of @dfn{rewind} function. The default definition is as
6024 follows:
6025
6026 @smallexample
6027 MT_REWIND=mt_rewind
6028
6029 mt_rewind() @{
6030 mt -f "$1" rewind
6031 @}
6032 @end smallexample
6033
6034 @end defvr
6035
6036 @defvr {Backup variable} MT_OFFLINE
6037 The name of the function switching the tape off line. By default
6038 it is defined as follows:
6039
6040 @smallexample
6041 MT_OFFLINE=mt_offline
6042
6043 mt_offline() @{
6044 mt -f "$1" offl
6045 @}
6046 @end smallexample
6047 @end defvr
6048
6049 @defvr {Backup variable} MT_STATUS
6050 The name of the function used to obtain the status of the archive device,
6051 including error count. Default definition:
6052
6053 @smallexample
6054 MT_STATUS=mt_status
6055
6056 mt_status() @{
6057 mt -f "$1" status
6058 @}
6059 @end smallexample
6060 @end defvr
6061
6062 @node User Hooks
6063 @subsection User Hooks
6064
6065 @dfn{User hooks} are shell functions executed before and after
6066 each @command{tar} invocation. Thus, there are @dfn{backup
6067 hooks}, which are executed before and after dumping each file
6068 system, and @dfn{restore hooks}, executed before and
6069 after restoring a file system. Each user hook is a shell function
6070 taking four arguments:
6071
6072 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6073 Its arguments are:
6074
6075 @table @var
6076 @item level
6077 Current backup or restore level.
6078
6079 @item host
6080 Name or IP address of the host machine being dumped or restored.
6081
6082 @item fs
6083 Full file name of the file system being dumped or restored.
6084
6085 @item fsname
6086 File system name with directory separators replaced with colons. This
6087 is useful, e.g., for creating unique files.
6088 @end table
6089 @end deffn
6090
6091 Following variables keep the names of user hook functions
6092
6093 @defvr {Backup variable} DUMP_BEGIN
6094 Dump begin function. It is executed before dumping the file system.
6095 @end defvr
6096
6097 @defvr {Backup variable} DUMP_END
6098 Executed after dumping the file system.
6099 @end defvr
6100
6101 @defvr {Backup variable} RESTORE_BEGIN
6102 Executed before restoring the file system.
6103 @end defvr
6104
6105 @defvr {Backup variable} RESTORE_END
6106 Executed after restoring the file system.
6107 @end defvr
6108
6109 @node backup-specs example
6110 @subsection An Example Text of @file{Backup-specs}
6111
6112 The following is an example of @file{backup-specs}:
6113
6114 @smallexample
6115 # site-specific parameters for file system backup.
6116
6117 ADMINISTRATOR=friedman
6118 BACKUP_HOUR=1
6119 TAPE_FILE=/dev/nrsmt0
6120
6121 # Use @code{ssh} instead of the less secure @code{rsh}
6122 RSH=/usr/bin/ssh
6123 RSH_COMMAND=/usr/bin/ssh
6124
6125 # Override MT_STATUS function:
6126 my_status() @{
6127 mts -t $TAPE_FILE
6128 @}
6129 MT_STATUS=my_status
6130
6131 # Disable MT_OFFLINE function
6132 MT_OFFLINE=:
6133
6134 BLOCKING=124
6135 BACKUP_DIRS="
6136 albert:/fs/fsf
6137 apple-gunkies:/gd
6138 albert:/fs/gd2
6139 albert:/fs/gp
6140 geech:/usr/jla
6141 churchy:/usr/roland
6142 albert:/
6143 albert:/usr
6144 apple-gunkies:/
6145 apple-gunkies:/usr
6146 gnu:/hack
6147 gnu:/u
6148 apple-gunkies:/com/mailer/gnu
6149 apple-gunkies:/com/archive/gnu"
6150
6151 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6152
6153 @end smallexample
6154
6155 @node Scripted Backups
6156 @section Using the Backup Scripts
6157
6158 The syntax for running a backup script is:
6159
6160 @smallexample
6161 backup --level=@var{level} --time=@var{time}
6162 @end smallexample
6163
6164 The @option{level} option requests the dump level. Thus, to produce
6165 a full dump, specify @code{--level=0} (this is the default, so
6166 @option{--level} may be omitted if its value is @code{0}).
6167 @footnote{For backward compatibility, the @code{backup} will also
6168 try to deduce the requested dump level from the name of the
6169 script itself. If the name consists of a string @samp{level-}
6170 followed by a single decimal digit, that digit is taken as
6171 the dump level number. Thus, you may create a link from @code{backup}
6172 to @code{level-1} and then run @code{level-1} whenever you need to
6173 create a level one dump.}
6174
6175 The @option{--time} option determines when should the backup be
6176 run. @var{Time} may take three forms:
6177
6178 @table @asis
6179 @item @var{hh}:@var{mm}
6180
6181 The dump must be run at @var{hh} hours @var{mm} minutes.
6182
6183 @item @var{hh}
6184
6185 The dump must be run at @var{hh} hours
6186
6187 @item now
6188
6189 The dump must be run immediately.
6190 @end table
6191
6192 You should start a script with a tape or disk mounted. Once you
6193 start a script, it prompts you for new tapes or disks as it
6194 needs them. Media volumes don't have to correspond to archive
6195 files --- a multi-volume archive can be started in the middle of a
6196 tape that already contains the end of another multi-volume archive.
6197 The @code{restore} script prompts for media by its archive volume,
6198 so to avoid an error message you should keep track of which tape
6199 (or disk) contains which volume of the archive (@pxref{Scripted
6200 Restoration}).
6201
6202 The backup scripts write two files on the file system. The first is a
6203 record file in @file{/etc/tar-backup/}, which is used by the scripts
6204 to store and retrieve information about which files were dumped. This
6205 file is not meant to be read by humans, and should not be deleted by
6206 them. @xref{Snapshot Files}, for a more detailed explanation of this
6207 file.
6208
6209 The second file is a log file containing the names of the file systems
6210 and files dumped, what time the backup was made, and any error
6211 messages that were generated, as well as how much space was left in
6212 the media volume after the last volume of the archive was written.
6213 You should check this log file after every backup. The file name is
6214 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6215 represents current date, and @var{n} represents current dump level number.
6216
6217 The script also prints the name of each system being dumped to the
6218 standard output.
6219
6220 Following is the full list of options accepted by @code{backup}
6221 script:
6222
6223 @table @option
6224 @item -l @var{level}
6225 @itemx --level=@var{level}
6226 Do backup level @var{level} (default 0).
6227
6228 @item -f
6229 @itemx --force
6230 Force backup even if today's log file already exists.
6231
6232 @item -v[@var{level}]
6233 @itemx --verbose[=@var{level}]
6234 Set verbosity level. The higher the level is, the more debugging
6235 information will be output during execution. Default @var{level}
6236 is 100, which means the highest debugging level.
6237
6238 @item -t @var{start-time}
6239 @itemx --time=@var{start-time}
6240 Wait till @var{time}, then do backup.
6241
6242 @item -h
6243 @itemx --help
6244 Display short help message and exit.
6245
6246 @item -V
6247 @itemx --version
6248 Display information about the program's name, version, origin and legal
6249 status, all on standard output, and then exit successfully.
6250 @end table
6251
6252
6253 @node Scripted Restoration
6254 @section Using the Restore Script
6255
6256 To restore files that were archived using a scripted backup, use the
6257 @code{restore} script. Its usage is quite straightforward. In the
6258 simplest form, invoke @code{restore --all}, it will
6259 then restore all the file systems and files specified in
6260 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6261
6262 You may select the file systems (and/or files) to restore by
6263 giving @code{restore} list of @dfn{patterns} in its command
6264 line. For example, running
6265
6266 @smallexample
6267 restore 'albert:*'
6268 @end smallexample
6269
6270 @noindent
6271 will restore all file systems on the machine @samp{albert}. A more
6272 complicated example:
6273
6274 @smallexample
6275 restore 'albert:*' '*:/var'
6276 @end smallexample
6277
6278 @noindent
6279 This command will restore all file systems on the machine @samp{albert}
6280 as well as @file{/var} file system on all machines.
6281
6282 By default @code{restore} will start restoring files from the lowest
6283 available dump level (usually zero) and will continue through
6284 all available dump levels. There may be situations where such a
6285 thorough restore is not necessary. For example, you may wish to
6286 restore only files from the recent level one backup. To do so,
6287 use @option{--level} option, as shown in the example below:
6288
6289 @smallexample
6290 restore --level=1
6291 @end smallexample
6292
6293 The full list of options accepted by @code{restore} follows:
6294
6295 @table @option
6296 @item -a
6297 @itemx --all
6298 Restore all file systems and files specified in @file{backup-specs}
6299
6300 @item -l @var{level}
6301 @itemx --level=@var{level}
6302 Start restoring from the given backup level, instead of the default 0.
6303
6304 @item -v[@var{level}]
6305 @itemx --verbose[=@var{level}]
6306 Set verbosity level. The higher the level is, the more debugging
6307 information will be output during execution. Default @var{level}
6308 is 100, which means the highest debugging level.
6309
6310 @item -h
6311 @itemx --help
6312 Display short help message and exit.
6313
6314 @item -V
6315 @itemx --version
6316 Display information about the program's name, version, origin and legal
6317 status, all on standard output, and then exit successfully.
6318 @end table
6319
6320 You should start the restore script with the media containing the
6321 first volume of the archive mounted. The script will prompt for other
6322 volumes as they are needed. If the archive is on tape, you don't need
6323 to rewind the tape to to its beginning---if the tape head is
6324 positioned past the beginning of the archive, the script will rewind
6325 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6326 positioning.
6327
6328 @quotation
6329 @strong{Warning:} The script will delete files from the active file
6330 system if they were not in the file system when the archive was made.
6331 @end quotation
6332
6333 @xref{Incremental Dumps}, for an explanation of how the script makes
6334 that determination.
6335
6336 @node Choosing
6337 @chapter Choosing Files and Names for @command{tar}
6338 @UNREVISED
6339
6340 Certain options to @command{tar} enable you to specify a name for your
6341 archive. Other options let you decide which files to include or exclude
6342 from the archive, based on when or whether files were modified, whether
6343 the file names do or don't match specified patterns, or whether files
6344 are in specified directories.
6345
6346 This chapter discusses these options in detail.
6347
6348 @menu
6349 * file:: Choosing the Archive's Name
6350 * Selecting Archive Members::
6351 * files:: Reading Names from a File
6352 * exclude:: Excluding Some Files
6353 * wildcards:: Wildcards Patterns and Matching
6354 * quoting styles:: Ways of Quoting Special Characters in Names
6355 * transform:: Modifying File and Member Names
6356 * after:: Operating Only on New Files
6357 * recurse:: Descending into Directories
6358 * one:: Crossing File System Boundaries
6359 @end menu
6360
6361 @node file
6362 @section Choosing and Naming Archive Files
6363 @UNREVISED
6364
6365 @cindex Naming an archive
6366 @cindex Archive Name
6367 @cindex Choosing an archive file
6368 @cindex Where is the archive?
6369 By default, @command{tar} uses an archive file name that was compiled when
6370 it was built on the system; usually this name refers to some physical
6371 tape drive on the machine. However, the person who installed @command{tar}
6372 on the system may not have set the default to a meaningful value as far as
6373 most users are concerned. As a result, you will usually want to tell
6374 @command{tar} where to find (or create) the archive. The
6375 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6376 option allows you to either specify or name a file to use as the archive
6377 instead of the default archive file location.
6378
6379 @table @option
6380 @xopindex{file, short description}
6381 @item --file=@var{archive-name}
6382 @itemx -f @var{archive-name}
6383 Name the archive to create or operate on. Use in conjunction with
6384 any operation.
6385 @end table
6386
6387 For example, in this @command{tar} command,
6388
6389 @smallexample
6390 $ @kbd{tar -cvf collection.tar blues folk jazz}
6391 @end smallexample
6392
6393 @noindent
6394 @file{collection.tar} is the name of the archive. It must directly
6395 follow the @option{-f} option, since whatever directly follows @option{-f}
6396 @emph{will} end up naming the archive. If you neglect to specify an
6397 archive name, you may end up overwriting a file in the working directory
6398 with the archive you create since @command{tar} will use this file's name
6399 for the archive name.
6400
6401 An archive can be saved as a file in the file system, sent through a
6402 pipe or over a network, or written to an I/O device such as a tape,
6403 floppy disk, or CD write drive.
6404
6405 @cindex Writing new archives
6406 @cindex Archive creation
6407 If you do not name the archive, @command{tar} uses the value of the
6408 environment variable @env{TAPE} as the file name for the archive. If
6409 that is not available, @command{tar} uses a default, compiled-in archive
6410 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6411
6412 @cindex Standard input and output
6413 @cindex tar to standard input and output
6414 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6415 archive from standard input (when listing or extracting files), or
6416 writes it to standard output (when creating an archive). If you use
6417 @file{-} as an @var{archive-name} when modifying an archive,
6418 @command{tar} reads the original archive from its standard input and
6419 writes the entire new archive to its standard output.
6420
6421 The following example is a convenient way of copying directory
6422 hierarchy from @file{sourcedir} to @file{targetdir}.
6423
6424 @smallexample
6425 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6426 @end smallexample
6427
6428 The @option{-C} option allows to avoid using subshells:
6429
6430 @smallexample
6431 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6432 @end smallexample
6433
6434 In both examples above, the leftmost @command{tar} invocation archives
6435 the contents of @file{sourcedir} to the standard output, while the
6436 rightmost one reads this archive from its standard input and
6437 extracts it. The @option{-p} option tells it to restore permissions
6438 of the extracted files.
6439
6440 @cindex Remote devices
6441 @cindex tar to a remote device
6442 @anchor{remote-dev}
6443 To specify an archive file on a device attached to a remote machine,
6444 use the following:
6445
6446 @smallexample
6447 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6448 @end smallexample
6449
6450 @noindent
6451 @command{tar} will complete the remote connection, if possible, and
6452 prompt you for a username and password. If you use
6453 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6454 will complete the remote connection, if possible, using your username
6455 as the username on the remote machine.
6456
6457 @cindex Local and remote archives
6458 @anchor{local and remote archives}
6459 If the archive file name includes a colon (@samp{:}), then it is assumed
6460 to be a file on another machine. If the archive file is
6461 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6462 host @var{host}. The remote host is accessed using the @command{rsh}
6463 program, with a username of @var{user}. If the username is omitted
6464 (along with the @samp{@@} sign), then your user name will be used.
6465 (This is the normal @command{rsh} behavior.) It is necessary for the
6466 remote machine, in addition to permitting your @command{rsh} access, to
6467 have the @file{rmt} program installed (This command is included in
6468 the @GNUTAR{} distribution and by default is installed under
6469 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6470 installation prefix). If you need to use a file whose name includes a
6471 colon, then the remote tape drive behavior
6472 can be inhibited by using the @option{--force-local} option.
6473
6474 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6475 tries to minimize input and output operations. The Amanda backup
6476 system, when used with @GNUTAR{}, has an initial sizing pass which
6477 uses this feature.
6478
6479 @node Selecting Archive Members
6480 @section Selecting Archive Members
6481 @cindex Specifying files to act on
6482 @cindex Specifying archive members
6483
6484 @dfn{File Name arguments} specify which files in the file system
6485 @command{tar} operates on, when creating or adding to an archive, or which
6486 archive members @command{tar} operates on, when reading or deleting from
6487 an archive. @xref{Operations}.
6488
6489 To specify file names, you can include them as the last arguments on
6490 the command line, as follows:
6491 @smallexample
6492 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6493 @end smallexample
6494
6495 If a file name begins with dash (@samp{-}), precede it with
6496 @option{--add-file} option to prevent it from being treated as an
6497 option.
6498
6499 @anchor{input name quoting}
6500 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6501 name, replacing @dfn{escape sequences} according to the following
6502 table:
6503
6504 @multitable @columnfractions 0.20 0.60
6505 @headitem Escape @tab Replaced with
6506 @item \a @tab Audible bell (@acronym{ASCII} 7)
6507 @item \b @tab Backspace (@acronym{ASCII} 8)
6508 @item \f @tab Form feed (@acronym{ASCII} 12)
6509 @item \n @tab New line (@acronym{ASCII} 10)
6510 @item \r @tab Carriage return (@acronym{ASCII} 13)
6511 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6512 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6513 @item \? @tab @acronym{ASCII} 127
6514 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6515 of up to 3 digits)
6516 @end multitable
6517
6518 A backslash followed by any other symbol is retained.
6519
6520 This default behavior is controlled by the following command line
6521 option:
6522
6523 @table @option
6524 @opindex unquote
6525 @item --unquote
6526 Enable unquoting input file or member names (default).
6527
6528 @opindex no-unquote
6529 @item --no-unquote
6530 Disable unquoting input file or member names.
6531 @end table
6532
6533 If you specify a directory name as a file name argument, all the files
6534 in that directory are operated on by @command{tar}.
6535
6536 If you do not specify files, @command{tar} behavior differs depending
6537 on the operation mode as described below:
6538
6539 When @command{tar} is invoked with @option{--create} (@option{-c}),
6540 @command{tar} will stop immediately, reporting the following:
6541
6542 @smallexample
6543 @group
6544 $ @kbd{tar cf a.tar}
6545 tar: Cowardly refusing to create an empty archive
6546 Try `tar --help' or `tar --usage' for more information.
6547 @end group
6548 @end smallexample
6549
6550 If you specify either @option{--list} (@option{-t}) or
6551 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6552 operates on all the archive members in the archive.
6553
6554 If run with @option{--diff} option, tar will compare the archive with
6555 the contents of the current working directory.
6556
6557 If you specify any other operation, @command{tar} does nothing.
6558
6559 By default, @command{tar} takes file names from the command line. However,
6560 there are other ways to specify file or member names, or to modify the
6561 manner in which @command{tar} selects the files or members upon which to
6562 operate. In general, these methods work both for specifying the names
6563 of files and archive members.
6564
6565 @node files
6566 @section Reading Names from a File
6567
6568 @cindex Reading file names from a file
6569 @cindex Lists of file names
6570 @cindex File Name arguments, alternatives
6571 Instead of giving the names of files or archive members on the command
6572 line, you can put the names into a file, and then use the
6573 @option{--files-from=@var{file-of-names}} (@option{-T
6574 @var{file-of-names}}) option to @command{tar}. Give the name of the
6575 file which contains the list of files to include as the argument to
6576 @option{--files-from}. In the list, the file names should be separated by
6577 newlines. You will frequently use this option when you have generated
6578 the list of files to archive with the @command{find} utility.
6579
6580 @table @option
6581 @opindex files-from
6582 @item --files-from=@var{file-name}
6583 @itemx -T @var{file-name}
6584 Get names to extract or create from file @var{file-name}.
6585 @end table
6586
6587 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6588 you specify either @code{--files-from=-} or @code{-T -}), then the file
6589 names are read from standard input.
6590
6591 Unless you are running @command{tar} with @option{--create}, you can not use
6592 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6593 command.
6594
6595 Any number of @option{-T} options can be given in the command line.
6596
6597 The following example shows how to use @command{find} to generate a list of
6598 files smaller than 400K in length and put that list into a file
6599 called @file{small-files}. You can then use the @option{-T} option to
6600 @command{tar} to specify the files from that file, @file{small-files}, to
6601 create the archive @file{little.tgz}. (The @option{-z} option to
6602 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6603 more information.)
6604
6605 @smallexample
6606 $ @kbd{find . -size -400 -print > small-files}
6607 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6608 @end smallexample
6609
6610 @noindent
6611 In the file list given by @option{-T} option, any file name beginning
6612 with @samp{-} character is considered a @command{tar} option and is
6613 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6614 recognized only @option{-C} option in file lists, and only if the
6615 option and its argument occupied two consecutive lines.} For example,
6616 the common use of this feature is to change to another directory by
6617 specifying @option{-C} option:
6618
6619 @smallexample
6620 @group
6621 $ @kbd{cat list}
6622 -C/etc
6623 passwd
6624 hosts
6625 -C/lib
6626 libc.a
6627 $ @kbd{tar -c -f foo.tar --files-from list}
6628 @end group
6629 @end smallexample
6630
6631 @noindent
6632 In this example, @command{tar} will first switch to @file{/etc}
6633 directory and add files @file{passwd} and @file{hosts} to the
6634 archive. Then it will change to @file{/lib} directory and will archive
6635 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6636 contain:
6637
6638 @smallexample
6639 @group
6640 $ @kbd{tar tf foo.tar}
6641 passwd
6642 hosts
6643 libc.a
6644 @end group
6645 @end smallexample
6646
6647 @noindent
6648 @xopindex{directory, using in @option{--files-from} argument}
6649 Notice that the option parsing algorithm used with @option{-T} is
6650 stricter than the one used by shell. Namely, when specifying option
6651 arguments, you should observe the following rules:
6652
6653 @itemize @bullet
6654 @item
6655 When using short (single-letter) option form, its argument must
6656 immediately follow the option letter, without any intervening
6657 whitespace. For example: @code{-Cdir}.
6658
6659 @item
6660 When using long option form, the option argument must be separated
6661 from the option by a single equal sign. No whitespace is allowed on
6662 any side of the equal sign. For example: @code{--directory=dir}.
6663
6664 @item
6665 For both short and long option forms, the option argument can be given
6666 on the next line after the option name, e.g.:
6667
6668 @smallexample
6669 @group
6670 --directory
6671 dir
6672 @end group
6673 @end smallexample
6674
6675 @noindent
6676 and
6677
6678 @smallexample
6679 @group
6680 -C
6681 dir
6682 @end group
6683 @end smallexample
6684 @end itemize
6685
6686 @opindex add-file
6687 If you happen to have a file whose name starts with @samp{-},
6688 precede it with @option{--add-file} option to prevent it from
6689 being recognized as an option. For example: @code{--add-file=--my-file}.
6690
6691 @menu
6692 * nul::
6693 @end menu
6694
6695 @node nul
6696 @subsection @code{NUL} Terminated File Names
6697
6698 @cindex File names, terminated by @code{NUL}
6699 @cindex @code{NUL} terminated file names
6700 The @option{--null} option causes
6701 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6702 to read file names terminated by a @code{NUL} instead of a newline, so
6703 files whose names contain newlines can be archived using
6704 @option{--files-from}.
6705
6706 @table @option
6707 @opindex null
6708 @item --null
6709 Only consider @code{NUL} terminated file names, instead of files that
6710 terminate in a newline.
6711 @end table
6712
6713 The @option{--null} option is just like the one in @acronym{GNU}
6714 @command{xargs} and @command{cpio}, and is useful with the
6715 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6716 @command{tar}, @option{--null} also disables special handling for
6717 file names that begin with dash.
6718
6719 This example shows how to use @command{find} to generate a list of files
6720 larger than 800K in length and put that list into a file called
6721 @file{long-files}. The @option{-print0} option to @command{find} is just
6722 like @option{-print}, except that it separates files with a @code{NUL}
6723 rather than with a newline. You can then run @command{tar} with both the
6724 @option{--null} and @option{-T} options to specify that @command{tar} get the
6725 files from that file, @file{long-files}, to create the archive
6726 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6727 @command{tar} to recognize the @code{NUL} separator between files.
6728
6729 @smallexample
6730 $ @kbd{find . -size +800 -print0 > long-files}
6731 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6732 @end smallexample
6733
6734 @FIXME{say anything else here to conclude the section?}
6735
6736 @node exclude
6737 @section Excluding Some Files
6738 @UNREVISED
6739
6740 @cindex File names, excluding files by
6741 @cindex Excluding files by name and pattern
6742 @cindex Excluding files by file system
6743 To avoid operating on files whose names match a particular pattern,
6744 use the @option{--exclude} or @option{--exclude-from} options.
6745
6746 @table @option
6747 @opindex exclude
6748 @item --exclude=@var{pattern}
6749 Causes @command{tar} to ignore files that match the @var{pattern}.
6750 @end table
6751
6752 @findex exclude
6753 The @option{--exclude=@var{pattern}} option prevents any file or
6754 member whose name matches the shell wildcard (@var{pattern}) from
6755 being operated on.
6756 For example, to create an archive with all the contents of the directory
6757 @file{src} except for files whose names end in @file{.o}, use the
6758 command @samp{tar -cf src.tar --exclude='*.o' src}.
6759
6760 You may give multiple @option{--exclude} options.
6761
6762 @table @option
6763 @opindex exclude-from
6764 @item --exclude-from=@var{file}
6765 @itemx -X @var{file}
6766 Causes @command{tar} to ignore files that match the patterns listed in
6767 @var{file}.
6768 @end table
6769
6770 @findex exclude-from
6771 Use the @option{--exclude-from} option to read a
6772 list of patterns, one per line, from @var{file}; @command{tar} will
6773 ignore files matching those patterns. Thus if @command{tar} is
6774 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6775 single line @file{*.o}, no files whose names end in @file{.o} will be
6776 added to the archive.
6777
6778 Notice, that lines from @var{file} are read verbatim. One of the
6779 frequent errors is leaving some extra whitespace after a file name,
6780 which is difficult to catch using text editors.
6781
6782 However, empty lines are OK.
6783
6784 @cindex version control system, excluding files
6785 @cindex VCS, excluding files
6786 @cindex SCCS, excluding files
6787 @cindex RCS, excluding files
6788 @cindex CVS, excluding files
6789 @cindex SVN, excluding files
6790 @cindex git, excluding files
6791 @table @option
6792 @opindex exclude-vcs
6793 @item --exclude-vcs
6794 Exclude files and directories used by some version control systems.
6795 @end table
6796
6797 As of version @value{VERSION}, the following files are excluded:
6798
6799 @itemize @bullet
6800 @item @file{CVS/}, and everything under it
6801 @item @file{RCS/}, and everything under it
6802 @item @file{SCCS/}, and everything under it
6803 @item @file{.git/}, and everything under it
6804 @item @file{.gitignore}
6805 @item @file{.cvsignore}
6806 @item @file{.svn/}, and everything under it
6807 @item @file{.arch-ids/}, and everything under it
6808 @item @file{@{arch@}/}, and everything under it
6809 @item @file{=RELEASE-ID}
6810 @item @file{=meta-update}
6811 @item @file{=update}
6812 @end itemize
6813
6814 @findex exclude-caches
6815 When creating an archive, the @option{--exclude-caches} option family
6816 causes @command{tar} to exclude all directories that contain a @dfn{cache
6817 directory tag}. A cache directory tag is a short file with the
6818 well-known name @file{CACHEDIR.TAG} and having a standard header
6819 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6820 Various applications write cache directory tags into directories they
6821 use to hold regenerable, non-precious data, so that such data can be
6822 more easily excluded from backups.
6823
6824 There are three @samp{exclude-caches} options, each providing a different
6825 exclusion semantics:
6826
6827 @table @option
6828 @opindex exclude-caches
6829 @item --exclude-caches
6830 Do not archive the contents of the directory, but archive the
6831 directory itself and the @file{CACHEDIR.TAG} file.
6832
6833 @opindex exclude-caches-under
6834 @item --exclude-caches-under
6835 Do not archive the contents of the directory, nor the
6836 @file{CACHEDIR.TAG} file, archive only the directory itself.
6837
6838 @opindex exclude-caches-all
6839 @item --exclude-caches-all
6840 Omit directories containing @file{CACHEDIR.TAG} file entirely.
6841 @end table
6842
6843 @findex exclude-tag
6844 Another option family, @option{--exclude-tag}, provides a generalization of
6845 this concept. It takes a single argument, a file name to look for.
6846 Any directory that contains this file will be excluded from the dump.
6847 Similarly to @samp{exclude-caches}, there are three options in this
6848 option family:
6849
6850 @table @option
6851 @opindex exclude-tag
6852 @item --exclude-tag=@var{file}
6853 Do not dump the contents of the directory, but dump the
6854 directory itself and the @var{file}.
6855
6856 @opindex exclude-tag-under
6857 @item --exclude-tag-under=@var{file}
6858 Do not dump the contents of the directory, nor the
6859 @var{file}, archive only the directory itself.
6860
6861 @opindex exclude-tag-all
6862 @item --exclude-tag-all=@var{file}
6863 Omit directories containing @var{file} file entirely.
6864 @end table
6865
6866 Multiple @option{--exclude-tag*} options can be given.
6867
6868 For example, given this directory:
6869
6870 @smallexample
6871 @group
6872 $ @kbd{find dir}
6873 dir
6874 dir/blues
6875 dir/jazz
6876 dir/folk
6877 dir/folk/tagfile
6878 dir/folk/sanjuan
6879 dir/folk/trote
6880 @end group
6881 @end smallexample
6882
6883 The @option{--exclude-tag} will produce the following:
6884
6885 @smallexample
6886 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
6887 dir/
6888 dir/blues
6889 dir/jazz
6890 dir/folk/
6891 tar: dir/folk/: contains a cache directory tag tagfile;
6892 contents not dumped
6893 dir/folk/tagfile
6894 @end smallexample
6895
6896 Both the @file{dir/folk} directory and its tagfile are preserved in
6897 the archive, however the rest of files in this directory are not.
6898
6899 Now, using the @option{--exclude-tag-under} option will exclude
6900 @file{tagfile} from the dump, while still preserving the directory
6901 itself, as shown in this example:
6902
6903 @smallexample
6904 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
6905 dir/
6906 dir/blues
6907 dir/jazz
6908 dir/folk/
6909 ./tar: dir/folk/: contains a cache directory tag tagfile;
6910 contents not dumped
6911 @end smallexample
6912
6913 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
6914 directory entirely:
6915
6916 @smallexample
6917 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
6918 dir/
6919 dir/blues
6920 dir/jazz
6921 ./tar: dir/folk/: contains a cache directory tag tagfile;
6922 directory not dumped
6923 @end smallexample
6924
6925 @menu
6926 * problems with exclude::
6927 @end menu
6928
6929 @node problems with exclude
6930 @unnumberedsubsec Problems with Using the @code{exclude} Options
6931
6932 @xopindex{exclude, potential problems with}
6933 Some users find @samp{exclude} options confusing. Here are some common
6934 pitfalls:
6935
6936 @itemize @bullet
6937 @item
6938 The main operating mode of @command{tar} does not act on a file name
6939 explicitly listed on the command line, if one of its file name
6940 components is excluded. In the example above, if
6941 you create an archive and exclude files that end with @samp{*.o}, but
6942 explicitly name the file @samp{dir.o/foo} after all the options have been
6943 listed, @samp{dir.o/foo} will be excluded from the archive.
6944
6945 @item
6946 You can sometimes confuse the meanings of @option{--exclude} and
6947 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6948 to be excluded are given as a pattern on the command line. Use
6949 @option{--exclude-from} to introduce the name of a file which contains
6950 a list of patterns, one per line; each of these patterns can exclude
6951 zero, one, or many files.
6952
6953 @item
6954 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6955 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6956 like @samp{*}. If you do not do this, the shell might expand the
6957 @samp{*} itself using files at hand, so @command{tar} might receive a
6958 list of files instead of one pattern, or none at all, making the
6959 command somewhat illegal. This might not correspond to what you want.
6960
6961 For example, write:
6962
6963 @smallexample
6964 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6965 @end smallexample
6966
6967 @noindent
6968 rather than:
6969
6970 @smallexample
6971 # @emph{Wrong!}
6972 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6973 @end smallexample
6974
6975 @item
6976 You must use use shell syntax, or globbing, rather than @code{regexp}
6977 syntax, when using exclude options in @command{tar}. If you try to use
6978 @code{regexp} syntax to describe files to be excluded, your command
6979 might fail.
6980
6981 @item
6982 @FIXME{The change in semantics must have occurred before 1.11,
6983 so I doubt if it is worth mentioning at all. Anyway, should at
6984 least specify in which version the semantics changed.}
6985 In earlier versions of @command{tar}, what is now the
6986 @option{--exclude-from} option was called @option{--exclude} instead.
6987 Now, @option{--exclude} applies to patterns listed on the command
6988 line and @option{--exclude-from} applies to patterns listed in a
6989 file.
6990
6991 @end itemize
6992
6993 @node wildcards
6994 @section Wildcards Patterns and Matching
6995
6996 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6997 @samp{*} or @samp{?} for example, are replaced and expanded into all
6998 existing files matching the given pattern. @GNUTAR{} can use wildcard
6999 patterns for matching (or globbing) archive members when extracting
7000 from or listing an archive. Wildcard patterns are also used for
7001 verifying volume labels of @command{tar} archives. This section has the
7002 purpose of explaining wildcard syntax for @command{tar}.
7003
7004 @FIXME{the next few paragraphs need work.}
7005
7006 A @var{pattern} should be written according to shell syntax, using wildcard
7007 characters to effect globbing. Most characters in the pattern stand
7008 for themselves in the matched string, and case is significant: @samp{a}
7009 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7010 pattern matches any single character in the matched string. The character
7011 @samp{*} in the pattern matches zero, one, or more single characters in
7012 the matched string. The character @samp{\} says to take the following
7013 character of the pattern @emph{literally}; it is useful when one needs to
7014 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7015
7016 The character @samp{[}, up to the matching @samp{]}, introduces a character
7017 class. A @dfn{character class} is a list of acceptable characters
7018 for the next single character of the matched string. For example,
7019 @samp{[abcde]} would match any of the first five letters of the alphabet.
7020 Note that within a character class, all of the ``special characters''
7021 listed above other than @samp{\} lose their special meaning; for example,
7022 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7023 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7024 the characters @samp{-} and @samp{]} must either come @emph{first} or
7025 @emph{last} in a character class.)
7026
7027 @cindex Excluding characters from a character class
7028 @cindex Character class, excluding characters from
7029 If the first character of the class after the opening @samp{[}
7030 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7031 Rather than listing character to match, it lists those characters which
7032 are @emph{forbidden} as the next single character of the matched string.
7033
7034 Other characters of the class stand for themselves. The special
7035 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7036 letters, is meant to represent all characters between @var{a} and
7037 @var{e}, inclusive.
7038
7039 @FIXME{need to add a sentence or so here to make this clear for those
7040 who don't have dan around.}
7041
7042 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7043 special for wildcard matches. However, if a pattern completely matches
7044 a directory prefix of a matched string, then it matches the full matched
7045 string: thus, excluding a directory also excludes all the files beneath it.
7046
7047 @menu
7048 * controlling pattern-matching::
7049 @end menu
7050
7051 @node controlling pattern-matching
7052 @unnumberedsubsec Controlling Pattern-Matching
7053
7054 For the purposes of this section, we call @dfn{exclusion members} all
7055 member names obtained while processing @option{--exclude} and
7056 @option{--exclude-from} options, and @dfn{inclusion members} those
7057 member names that were given in the command line or read from the file
7058 specified with @option{--files-from} option.
7059
7060 These two pairs of member lists are used in the following operations:
7061 @option{--diff}, @option{--extract}, @option{--list},
7062 @option{--update}.
7063
7064 There are no inclusion members in create mode (@option{--create} and
7065 @option{--append}), since in this mode the names obtained from the
7066 command line refer to @emph{files}, not archive members.
7067
7068 By default, inclusion members are compared with archive members
7069 literally @footnote{Notice that earlier @GNUTAR{} versions used
7070 globbing for inclusion members, which contradicted to UNIX98
7071 specification and was not documented. @xref{Changes}, for more
7072 information on this and other changes.} and exclusion members are
7073 treated as globbing patterns. For example:
7074
7075 @smallexample
7076 @group
7077 $ @kbd{tar tf foo.tar}
7078 a.c
7079 b.c
7080 a.txt
7081 [remarks]
7082 # @i{Member names are used verbatim:}
7083 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7084 [remarks]
7085 # @i{Exclude member names are globbed:}
7086 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7087 a.txt
7088 [remarks]
7089 @end group
7090 @end smallexample
7091
7092 This behavior can be altered by using the following options:
7093
7094 @table @option
7095 @opindex wildcards
7096 @item --wildcards
7097 Treat all member names as wildcards.
7098
7099 @opindex no-wildcards
7100 @item --no-wildcards
7101 Treat all member names as literal strings.
7102 @end table
7103
7104 Thus, to extract files whose names end in @samp{.c}, you can use:
7105
7106 @smallexample
7107 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7108 a.c
7109 b.c
7110 @end smallexample
7111
7112 @noindent
7113 Notice quoting of the pattern to prevent the shell from interpreting
7114 it.
7115
7116 The effect of @option{--wildcards} option is canceled by
7117 @option{--no-wildcards}. This can be used to pass part of
7118 the command line arguments verbatim and other part as globbing
7119 patterns. For example, the following invocation:
7120
7121 @smallexample
7122 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7123 @end smallexample
7124
7125 @noindent
7126 instructs @command{tar} to extract from @file{foo.tar} all files whose
7127 names end in @samp{.txt} and the file named @file{[remarks]}.
7128
7129 Normally, a pattern matches a name if an initial subsequence of the
7130 name's components matches the pattern, where @samp{*}, @samp{?}, and
7131 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7132 and wildcards can match @samp{/}.
7133
7134 Other than optionally stripping leading @samp{/} from names
7135 (@pxref{absolute}), patterns and names are used as-is. For
7136 example, trailing @samp{/} is not trimmed from a user-specified name
7137 before deciding whether to exclude it.
7138
7139 However, this matching procedure can be altered by the options listed
7140 below. These options accumulate. For example:
7141
7142 @smallexample
7143 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7144 @end smallexample
7145
7146 @noindent
7147 ignores case when excluding @samp{makefile}, but not when excluding
7148 @samp{readme}.
7149
7150 @table @option
7151 @opindex anchored
7152 @opindex no-anchored
7153 @item --anchored
7154 @itemx --no-anchored
7155 If anchored, a pattern must match an initial subsequence
7156 of the name's components. Otherwise, the pattern can match any
7157 subsequence. Default is @option{--no-anchored} for exclusion members
7158 and @option{--anchored} inclusion members.
7159
7160 @opindex ignore-case
7161 @opindex no-ignore-case
7162 @item --ignore-case
7163 @itemx --no-ignore-case
7164 When ignoring case, upper-case patterns match lower-case names and vice versa.
7165 When not ignoring case (the default), matching is case-sensitive.
7166
7167 @opindex wildcards-match-slash
7168 @opindex no-wildcards-match-slash
7169 @item --wildcards-match-slash
7170 @itemx --no-wildcards-match-slash
7171 When wildcards match slash (the default for exclusion members), a
7172 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7173 name. Otherwise, @samp{/} is matched only by @samp{/}.
7174
7175 @end table
7176
7177 The @option{--recursion} and @option{--no-recursion} options
7178 (@pxref{recurse}) also affect how member patterns are interpreted. If
7179 recursion is in effect, a pattern matches a name if it matches any of
7180 the name's parent directories.
7181
7182 The following table summarizes pattern-matching default values:
7183
7184 @multitable @columnfractions .3 .7
7185 @headitem Members @tab Default settings
7186 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7187 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7188 @end multitable
7189
7190 @node quoting styles
7191 @section Quoting Member Names
7192
7193 When displaying member names, @command{tar} takes care to avoid
7194 ambiguities caused by certain characters. This is called @dfn{name
7195 quoting}. The characters in question are:
7196
7197 @itemize @bullet
7198 @item Non-printable control characters:
7199 @anchor{escape sequences}
7200 @multitable @columnfractions 0.20 0.10 0.60
7201 @headitem Character @tab @acronym{ASCII} @tab Character name
7202 @item \a @tab 7 @tab Audible bell
7203 @item \b @tab 8 @tab Backspace
7204 @item \f @tab 12 @tab Form feed
7205 @item \n @tab 10 @tab New line
7206 @item \r @tab 13 @tab Carriage return
7207 @item \t @tab 9 @tab Horizontal tabulation
7208 @item \v @tab 11 @tab Vertical tabulation
7209 @end multitable
7210
7211 @item Space (@acronym{ASCII} 32)
7212
7213 @item Single and double quotes (@samp{'} and @samp{"})
7214
7215 @item Backslash (@samp{\})
7216 @end itemize
7217
7218 The exact way @command{tar} uses to quote these characters depends on
7219 the @dfn{quoting style}. The default quoting style, called
7220 @dfn{escape} (see below), uses backslash notation to represent control
7221 characters, space and backslash. Using this quoting style, control
7222 characters are represented as listed in column @samp{Character} in the
7223 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7224
7225 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7226 using @option{--quoting-style} option:
7227
7228 @table @option
7229 @item --quoting-style=@var{style}
7230 @opindex quoting-style
7231
7232 Sets quoting style. Valid values for @var{style} argument are:
7233 literal, shell, shell-always, c, escape, locale, clocale.
7234 @end table
7235
7236 These styles are described in detail below. To illustrate their
7237 effect, we will use an imaginary tar archive @file{arch.tar}
7238 containing the following members:
7239
7240 @smallexample
7241 @group
7242 # 1. Contains horizontal tabulation character.
7243 a tab
7244 # 2. Contains newline character
7245 a
7246 newline
7247 # 3. Contains a space
7248 a space
7249 # 4. Contains double quotes
7250 a"double"quote
7251 # 5. Contains single quotes
7252 a'single'quote
7253 # 6. Contains a backslash character:
7254 a\backslash
7255 @end group
7256 @end smallexample
7257
7258 Here is how usual @command{ls} command would have listed them, if they
7259 had existed in the current working directory:
7260
7261 @smallexample
7262 @group
7263 $ @kbd{ls}
7264 a\ttab
7265 a\nnewline
7266 a\ space
7267 a"double"quote
7268 a'single'quote
7269 a\\backslash
7270 @end group
7271 @end smallexample
7272
7273 Quoting styles:
7274
7275 @table @samp
7276 @item literal
7277 No quoting, display each character as is:
7278
7279 @smallexample
7280 @group
7281 $ @kbd{tar tf arch.tar --quoting-style=literal}
7282 ./
7283 ./a space
7284 ./a'single'quote
7285 ./a"double"quote
7286 ./a\backslash
7287 ./a tab
7288 ./a
7289 newline
7290 @end group
7291 @end smallexample
7292
7293 @item shell
7294 Display characters the same way Bourne shell does:
7295 control characters, except @samp{\t} and @samp{\n}, are printed using
7296 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7297 single quote is printed as @samp{\'}. If a name contains any quoted
7298 characters, it is enclosed in single quotes. In particular, if a name
7299 contains single quotes, it is printed as several single-quoted strings:
7300
7301 @smallexample
7302 @group
7303 $ @kbd{tar tf arch.tar --quoting-style=shell}
7304 ./
7305 './a space'
7306 './a'\''single'\''quote'
7307 './a"double"quote'
7308 './a\backslash'
7309 './a tab'
7310 './a
7311 newline'
7312 @end group
7313 @end smallexample
7314
7315 @item shell-always
7316 Same as @samp{shell}, but the names are always enclosed in single
7317 quotes:
7318
7319 @smallexample
7320 @group
7321 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7322 './'
7323 './a space'
7324 './a'\''single'\''quote'
7325 './a"double"quote'
7326 './a\backslash'
7327 './a tab'
7328 './a
7329 newline'
7330 @end group
7331 @end smallexample
7332
7333 @item c
7334 Use the notation of the C programming language. All names are
7335 enclosed in double quotes. Control characters are quoted using
7336 backslash notations, double quotes are represented as @samp{\"},
7337 backslash characters are represented as @samp{\\}. Single quotes and
7338 spaces are not quoted:
7339
7340 @smallexample
7341 @group
7342 $ @kbd{tar tf arch.tar --quoting-style=c}
7343 "./"
7344 "./a space"
7345 "./a'single'quote"
7346 "./a\"double\"quote"
7347 "./a\\backslash"
7348 "./a\ttab"
7349 "./a\nnewline"
7350 @end group
7351 @end smallexample
7352
7353 @item escape
7354 Control characters are printed using backslash notation, a space is
7355 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7356 default quoting style, unless it was changed when configured the
7357 package.
7358
7359 @smallexample
7360 @group
7361 $ @kbd{tar tf arch.tar --quoting-style=escape}
7362 ./
7363 ./a space
7364 ./a'single'quote
7365 ./a"double"quote
7366 ./a\\backslash
7367 ./a\ttab
7368 ./a\nnewline
7369 @end group
7370 @end smallexample
7371
7372 @item locale
7373 Control characters, single quote and backslash are printed using
7374 backslash notation. All names are quoted using left and right
7375 quotation marks, appropriate to the current locale. If it does not
7376 define quotation marks, use @samp{`} as left and @samp{'} as right
7377 quotation marks. Any occurrences of the right quotation mark in a
7378 name are escaped with @samp{\}, for example:
7379
7380 For example:
7381
7382 @smallexample
7383 @group
7384 $ @kbd{tar tf arch.tar --quoting-style=locale}
7385 `./'
7386 `./a space'
7387 `./a\'single\'quote'
7388 `./a"double"quote'
7389 `./a\\backslash'
7390 `./a\ttab'
7391 `./a\nnewline'
7392 @end group
7393 @end smallexample
7394
7395 @item clocale
7396 Same as @samp{locale}, but @samp{"} is used for both left and right
7397 quotation marks, if not provided by the currently selected locale:
7398
7399 @smallexample
7400 @group
7401 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7402 "./"
7403 "./a space"
7404 "./a'single'quote"
7405 "./a\"double\"quote"
7406 "./a\\backslash"
7407 "./a\ttab"
7408 "./a\nnewline"
7409 @end group
7410 @end smallexample
7411 @end table
7412
7413 You can specify which characters should be quoted in addition to those
7414 implied by the current quoting style:
7415
7416 @table @option
7417 @item --quote-chars=@var{string}
7418 Always quote characters from @var{string}, even if the selected
7419 quoting style would not quote them.
7420 @end table
7421
7422 For example, using @samp{escape} quoting (compare with the usual
7423 escape listing above):
7424
7425 @smallexample
7426 @group
7427 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7428 ./
7429 ./a\ space
7430 ./a'single'quote
7431 ./a\"double\"quote
7432 ./a\\backslash
7433 ./a\ttab
7434 ./a\nnewline
7435 @end group
7436 @end smallexample
7437
7438 To disable quoting of such additional characters, use the following
7439 option:
7440
7441 @table @option
7442 @item --no-quote-chars=@var{string}
7443 Remove characters listed in @var{string} from the list of quoted
7444 characters set by the previous @option{--quote-chars} option.
7445 @end table
7446
7447 This option is particularly useful if you have added
7448 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7449 and wish to disable it for the current invocation.
7450
7451 Note, that @option{--no-quote-chars} does @emph{not} disable those
7452 characters that are quoted by default in the selected quoting style.
7453
7454 @node transform
7455 @section Modifying File and Member Names
7456
7457 @command{Tar} archives contain detailed information about files stored
7458 in them and full file names are part of that information. When
7459 storing file to an archive, its file name is recorded in the archive
7460 along with the actual file contents. When restoring from an archive,
7461 a file is created on disk with exactly the same name as that stored
7462 in the archive. In the majority of cases this is the desired behavior
7463 of a file archiver. However, there are some cases when it is not.
7464
7465 First of all, it is often unsafe to extract archive members with
7466 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7467 takes special precautions when extracting such names and provides a
7468 special option for handling them, which is described in
7469 @ref{absolute}.
7470
7471 Secondly, you may wish to extract file names without some leading
7472 directory components, or with otherwise modified names. In other
7473 cases it is desirable to store files under differing names in the
7474 archive.
7475
7476 @GNUTAR{} provides two options for these needs.
7477
7478 @table @option
7479 @opindex strip-components
7480 @item --strip-components=@var{number}
7481 Strip given @var{number} of leading components from file names before
7482 extraction.
7483 @end table
7484
7485 For example, suppose you have archived whole @file{/usr} hierarchy to
7486 a tar archive named @file{usr.tar}. Among other files, this archive
7487 contains @file{usr/include/stdlib.h}, which you wish to extract to
7488 the current working directory. To do so, you type:
7489
7490 @smallexample
7491 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7492 @end smallexample
7493
7494 The option @option{--strip=2} instructs @command{tar} to strip the
7495 two leading components (@file{usr/} and @file{include/}) off the file
7496 name.
7497
7498 If you add to the above invocation @option{--verbose} (@option{-v})
7499 option, you will note that the verbose listing still contains the
7500 full file name, with the two removed components still in place. This
7501 can be inconvenient, so @command{tar} provides a special option for
7502 altering this behavior:
7503
7504 @anchor{show-transformed-names}
7505 @table @option
7506 @opindex show-transformed-names
7507 @item --show-transformed-names
7508 Display file or member names with all requested transformations
7509 applied.
7510 @end table
7511
7512 @noindent
7513 For example:
7514
7515 @smallexample
7516 @group
7517 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7518 usr/include/stdlib.h
7519 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7520 stdlib.h
7521 @end group
7522 @end smallexample
7523
7524 Notice that in both cases the file is @file{stdlib.h} extracted to the
7525 current working directory, @option{--show-transformed-names} affects
7526 only the way its name is displayed.
7527
7528 This option is especially useful for verifying whether the invocation
7529 will have the desired effect. Thus, before running
7530
7531 @smallexample
7532 $ @kbd{tar -x --strip=@var{n}}
7533 @end smallexample
7534
7535 @noindent
7536 it is often advisable to run
7537
7538 @smallexample
7539 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7540 @end smallexample
7541
7542 @noindent
7543 to make sure the command will produce the intended results.
7544
7545 In case you need to apply more complex modifications to the file name,
7546 @GNUTAR{} provides a general-purpose transformation option:
7547
7548 @table @option
7549 @opindex transform
7550 @item --transform=@var{expression}
7551 Modify file names using supplied @var{expression}.
7552 @end table
7553
7554 @noindent
7555 The @var{expression} is a @command{sed}-like replace expression of the
7556 form:
7557
7558 @smallexample
7559 s/@var{regexp}/@var{replace}/[@var{flags}]
7560 @end smallexample
7561
7562 @noindent
7563 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7564 replacement for each file name part that matches @var{regexp}. Both
7565 @var{regexp} and @var{replace} are described in detail in
7566 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7567
7568 As in @command{sed}, you can give several replace expressions,
7569 separated by a semicolon.
7570
7571 Supported @var{flags} are:
7572
7573 @table @samp
7574 @item g
7575 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7576 just the first.
7577
7578 @item i
7579 Use case-insensitive matching
7580
7581 @item x
7582 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7583 regexps, Extended regular expressions, Extended regular expressions,
7584 sed, GNU sed}).
7585
7586 @item @var{number}
7587 Only replace the @var{number}th match of the @var{regexp}.
7588
7589 Note: the @var{posix} standard does not specify what should happen
7590 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7591 follows the GNU @command{sed} implementation in this regard, so
7592 the interaction is defined to be: ignore matches before the
7593 @var{number}th, and then match and replace all matches from the
7594 @var{number}th on.
7595
7596 @end table
7597
7598 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7599 that it be used consistently throughout the expression. For example,
7600 the following two expressions are equivalent:
7601
7602 @smallexample
7603 @group
7604 s/one/two/
7605 s,one,two,
7606 @end group
7607 @end smallexample
7608
7609 Changing delimiters is often useful when the @var{regex} contains
7610 slashes. For example, it is more convenient to write @code{s,/,-,} than
7611 @code{s/\//-/}.
7612
7613 Here are several examples of @option{--transform} usage:
7614
7615 @enumerate
7616 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7617
7618 @smallexample
7619 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7620 @end smallexample
7621
7622 @item Strip two leading directory components (equivalent to
7623 @option{--strip-components=2}):
7624
7625 @smallexample
7626 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7627 @end smallexample
7628
7629 @item Prepend @file{/prefix/} to each file name:
7630
7631 @smallexample
7632 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7633 @end smallexample
7634
7635 @item Convert each file name to lower case:
7636
7637 @smallexample
7638 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7639 @end smallexample
7640
7641 @end enumerate
7642
7643 Unlike @option{--strip-components}, @option{--transform} can be used
7644 in any @GNUTAR{} operation mode. For example, the following command
7645 adds files to the archive while replacing the leading @file{usr/}
7646 component with @file{var/}:
7647
7648 @smallexample
7649 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7650 @end smallexample
7651
7652 To test @option{--transform} effect we suggest using
7653 @option{--show-transformed-names} option:
7654
7655 @smallexample
7656 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7657 --verbose --show-transformed-names /}
7658 @end smallexample
7659
7660 If both @option{--strip-components} and @option{--transform} are used
7661 together, then @option{--transform} is applied first, and the required
7662 number of components is then stripped from its result.
7663
7664 You can use as many @option{--transform} options in a single command
7665 line as you want. The specified expressions will then be applied in
7666 order of their appearance. For example, the following two invocations
7667 are equivalent:
7668
7669 @smallexample
7670 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
7671 --transform='s,/usr/local,/usr/,'}
7672 $ @kbd{tar -cf arch.tar \
7673 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
7674 @end smallexample
7675
7676 @node after
7677 @section Operating Only on New Files
7678 @UNREVISED
7679
7680 @cindex Excluding file by age
7681 @cindex Data Modification time, excluding files by
7682 @cindex Modification time, excluding files by
7683 @cindex Age, excluding files by
7684 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7685 @option{-N @var{date}}) option causes @command{tar} to only work on
7686 files whose data modification or status change times are newer than
7687 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7688 it is taken to be a file name; the data modification time of that file
7689 is used as the date. If you use this option when creating or appending
7690 to an archive, the archive will only include new files. If you use
7691 @option{--after-date} when extracting an archive, @command{tar} will
7692 only extract files newer than the @var{date} you specify.
7693
7694 If you only want @command{tar} to make the date comparison based on
7695 modification of the file's data (rather than status
7696 changes), then use the @option{--newer-mtime=@var{date}} option.
7697
7698 You may use these options with any operation. Note that these options
7699 differ from the @option{--update} (@option{-u}) operation in that they
7700 allow you to specify a particular date against which @command{tar} can
7701 compare when deciding whether or not to archive the files.
7702
7703 @table @option
7704 @opindex after-date
7705 @opindex newer
7706 @item --after-date=@var{date}
7707 @itemx --newer=@var{date}
7708 @itemx -N @var{date}
7709 Only store files newer than @var{date}.
7710
7711 Acts on files only if their data modification or status change times are
7712 later than @var{date}. Use in conjunction with any operation.
7713
7714 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7715 name; the data modification time of that file is used as the date.
7716
7717 @opindex newer-mtime
7718 @item --newer-mtime=@var{date}
7719 Acts like @option{--after-date}, but only looks at data modification times.
7720 @end table
7721
7722 These options limit @command{tar} to operate only on files which have
7723 been modified after the date specified. A file's status is considered to have
7724 changed if its contents have been modified, or if its owner,
7725 permissions, and so forth, have been changed. (For more information on
7726 how to specify a date, see @ref{Date input formats}; remember that the
7727 entire date argument must be quoted if it contains any spaces.)
7728
7729 Gurus would say that @option{--after-date} tests both the data
7730 modification time (@code{mtime}, the time the contents of the file
7731 were last modified) and the status change time (@code{ctime}, the time
7732 the file's status was last changed: owner, permissions, etc.@:)
7733 fields, while @option{--newer-mtime} tests only the @code{mtime}
7734 field.
7735
7736 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7737 @code{ctime} and processes the file if either one is more recent than
7738 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7739 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7740 contents of the file were looked at).
7741
7742 Date specifiers can have embedded spaces. Because of this, you may need
7743 to quote date arguments to keep the shell from parsing them as separate
7744 arguments. For example, the following command will add to the archive
7745 all the files modified less than two days ago:
7746
7747 @smallexample
7748 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7749 @end smallexample
7750
7751 When any of these options is used with the option @option{--verbose}
7752 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7753 date back to its textual representation and compare that with the
7754 one given with the option. If the two dates differ, @command{tar} will
7755 print a warning saying what date it will use. This is to help user
7756 ensure he is using the right date. For example:
7757
7758 @smallexample
7759 @group
7760 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7761 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7762 13:19:37.232434
7763 @end group
7764 @end smallexample
7765
7766 @quotation
7767 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7768 should not be used for incremental backups. @xref{Incremental Dumps},
7769 for proper way of creating incremental backups.
7770 @end quotation
7771
7772 @node recurse
7773 @section Descending into Directories
7774 @UNREVISED
7775 @cindex Avoiding recursion in directories
7776 @cindex Descending directories, avoiding
7777 @cindex Directories, avoiding recursion
7778 @cindex Recursion in directories, avoiding
7779
7780 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7781
7782 Usually, @command{tar} will recursively explore all directories (either
7783 those given on the command line or through the @option{--files-from}
7784 option) for the various files they contain. However, you may not always
7785 want @command{tar} to act this way.
7786
7787 @opindex no-recursion
7788 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7789 into specified directories. If you specify @option{--no-recursion}, you can
7790 use the @command{find} utility for hunting through levels of directories to
7791 construct a list of file names which you could then pass to @command{tar}.
7792 @command{find} allows you to be more selective when choosing which files to
7793 archive; see @ref{files}, for more information on using @command{find} with
7794 @command{tar}, or look.
7795
7796 @table @option
7797 @item --no-recursion
7798 Prevents @command{tar} from recursively descending directories.
7799
7800 @opindex recursion
7801 @item --recursion
7802 Requires @command{tar} to recursively descend directories.
7803 This is the default.
7804 @end table
7805
7806 When you use @option{--no-recursion}, @GNUTAR{} grabs
7807 directory entries themselves, but does not descend on them
7808 recursively. Many people use @command{find} for locating files they
7809 want to back up, and since @command{tar} @emph{usually} recursively
7810 descends on directories, they have to use the @samp{@w{-not -type d}}
7811 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7812 find, Finding Files}), as they usually do not want all the files in a
7813 directory. They then use the @option{--files-from} option to archive
7814 the files located via @command{find}.
7815
7816 The problem when restoring files archived in this manner is that the
7817 directories themselves are not in the archive; so the
7818 @option{--same-permissions} (@option{--preserve-permissions},
7819 @option{-p}) option does not affect them---while users might really
7820 like it to. Specifying @option{--no-recursion} is a way to tell
7821 @command{tar} to grab only the directory entries given to it, adding
7822 no new files on its own. To summarize, if you use @command{find} to
7823 create a list of files to be stored in an archive, use it as follows:
7824
7825 @smallexample
7826 @group
7827 $ @kbd{find @var{dir} @var{tests} | \
7828 tar -cf @var{archive} -T - --no-recursion}
7829 @end group
7830 @end smallexample
7831
7832 The @option{--no-recursion} option also applies when extracting: it
7833 causes @command{tar} to extract only the matched directory entries, not
7834 the files under those directories.
7835
7836 The @option{--no-recursion} option also affects how globbing patterns
7837 are interpreted (@pxref{controlling pattern-matching}).
7838
7839 The @option{--no-recursion} and @option{--recursion} options apply to
7840 later options and operands, and can be overridden by later occurrences
7841 of @option{--no-recursion} and @option{--recursion}. For example:
7842
7843 @smallexample
7844 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7845 @end smallexample
7846
7847 @noindent
7848 creates an archive with one entry for @file{grape}, and the recursive
7849 contents of @file{grape/concord}, but no entries under @file{grape}
7850 other than @file{grape/concord}.
7851
7852 @node one
7853 @section Crossing File System Boundaries
7854 @cindex File system boundaries, not crossing
7855 @UNREVISED
7856
7857 @command{tar} will normally automatically cross file system boundaries in
7858 order to archive files which are part of a directory tree. You can
7859 change this behavior by running @command{tar} and specifying
7860 @option{--one-file-system}. This option only affects files that are
7861 archived because they are in a directory that is being archived;
7862 @command{tar} will still archive files explicitly named on the command line
7863 or through @option{--files-from}, regardless of where they reside.
7864
7865 @table @option
7866 @opindex one-file-system
7867 @item --one-file-system
7868 Prevents @command{tar} from crossing file system boundaries when
7869 archiving. Use in conjunction with any write operation.
7870 @end table
7871
7872 The @option{--one-file-system} option causes @command{tar} to modify its
7873 normal behavior in archiving the contents of directories. If a file in
7874 a directory is not on the same file system as the directory itself, then
7875 @command{tar} will not archive that file. If the file is a directory
7876 itself, @command{tar} will not archive anything beneath it; in other words,
7877 @command{tar} will not cross mount points.
7878
7879 This option is useful for making full or incremental archival backups of
7880 a file system. If this option is used in conjunction with
7881 @option{--verbose} (@option{-v}), files that are excluded are
7882 mentioned by name on the standard error.
7883
7884 @menu
7885 * directory:: Changing Directory
7886 * absolute:: Absolute File Names
7887 @end menu
7888
7889 @node directory
7890 @subsection Changing the Working Directory
7891
7892 @FIXME{need to read over this node now for continuity; i've switched
7893 things around some.}
7894
7895 @cindex Changing directory mid-stream
7896 @cindex Directory, changing mid-stream
7897 @cindex Working directory, specifying
7898 To change the working directory in the middle of a list of file names,
7899 either on the command line or in a file specified using
7900 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7901 This will change the working directory to the specified directory
7902 after that point in the list.
7903
7904 @table @option
7905 @opindex directory
7906 @item --directory=@var{directory}
7907 @itemx -C @var{directory}
7908 Changes the working directory in the middle of a command line.
7909 @end table
7910
7911 For example,
7912
7913 @smallexample
7914 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7915 @end smallexample
7916
7917 @noindent
7918 will place the files @file{grape} and @file{prune} from the current
7919 directory into the archive @file{jams.tar}, followed by the file
7920 @file{cherry} from the directory @file{food}. This option is especially
7921 useful when you have several widely separated files that you want to
7922 store in the same archive.
7923
7924 Note that the file @file{cherry} is recorded in the archive under the
7925 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7926 archive will contain three files that all appear to have come from the
7927 same directory; if the archive is extracted with plain @samp{tar
7928 --extract}, all three files will be written in the current directory.
7929
7930 Contrast this with the command,
7931
7932 @smallexample
7933 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7934 @end smallexample
7935
7936 @noindent
7937 which records the third file in the archive under the name
7938 @file{red/cherry} so that, if the archive is extracted using
7939 @samp{tar --extract}, the third file will be written in a subdirectory
7940 named @file{orange-colored}.
7941
7942 You can use the @option{--directory} option to make the archive
7943 independent of the original name of the directory holding the files.
7944 The following command places the files @file{/etc/passwd},
7945 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7946 @file{foo.tar}:
7947
7948 @smallexample
7949 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7950 @end smallexample
7951
7952 @noindent
7953 However, the names of the archive members will be exactly what they were
7954 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7955 They will not appear to be related by file name to the original
7956 directories where those files were located.
7957
7958 Note that @option{--directory} options are interpreted consecutively. If
7959 @option{--directory} specifies a relative file name, it is interpreted
7960 relative to the then current directory, which might not be the same as
7961 the original current working directory of @command{tar}, due to a previous
7962 @option{--directory} option.
7963
7964 When using @option{--files-from} (@pxref{files}), you can put various
7965 @command{tar} options (including @option{-C}) in the file list. Notice,
7966 however, that in this case the option and its argument may not be
7967 separated by whitespace. If you use short option, its argument must
7968 either follow the option letter immediately, without any intervening
7969 whitespace, or occupy the next line. Otherwise, if you use long
7970 option, separate its argument by an equal sign.
7971
7972 For instance, the file list for the above example will be:
7973
7974 @smallexample
7975 @group
7976 -C/etc
7977 passwd
7978 hosts
7979 --directory=/lib
7980 libc.a
7981 @end group
7982 @end smallexample
7983
7984 @noindent
7985 To use it, you would invoke @command{tar} as follows:
7986
7987 @smallexample
7988 $ @kbd{tar -c -f foo.tar --files-from list}
7989 @end smallexample
7990
7991 The interpretation of @option{--directory} is disabled by
7992 @option{--null} option.
7993
7994 @node absolute
7995 @subsection Absolute File Names
7996 @UNREVISED
7997
7998 @table @option
7999 @opindex absolute-names
8000 @item --absolute-names
8001 @itemx -P
8002 Do not strip leading slashes from file names, and permit file names
8003 containing a @file{..} file name component.
8004 @end table
8005
8006 By default, @GNUTAR{} drops a leading @samp{/} on
8007 input or output, and complains about file names containing a @file{..}
8008 component. This option turns off this behavior.
8009
8010 When @command{tar} extracts archive members from an archive, it strips any
8011 leading slashes (@samp{/}) from the member name. This causes absolute
8012 member names in the archive to be treated as relative file names. This
8013 allows you to have such members extracted wherever you want, instead of
8014 being restricted to extracting the member in the exact directory named
8015 in the archive. For example, if the archive member has the name
8016 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8017 really @file{etc/passwd}.
8018
8019 File names containing @file{..} can cause problems when extracting, so
8020 @command{tar} normally warns you about such files when creating an
8021 archive, and rejects attempts to extracts such files.
8022
8023 Other @command{tar} programs do not do this. As a result, if you
8024 create an archive whose member names start with a slash, they will be
8025 difficult for other people with a non-@GNUTAR{}
8026 program to use. Therefore, @GNUTAR{} also strips
8027 leading slashes from member names when putting members into the
8028 archive. For example, if you ask @command{tar} to add the file
8029 @file{/bin/ls} to an archive, it will do so, but the member name will
8030 be @file{bin/ls}.@footnote{A side effect of this is that when
8031 @option{--create} is used with @option{--verbose} the resulting output
8032 is not, generally speaking, the same as the one you'd get running
8033 @kbd{tar --list} command. This may be important if you use some
8034 scripts for comparing both outputs. @xref{listing member and file names},
8035 for the information on how to handle this case.}
8036
8037 If you use the @option{--absolute-names} (@option{-P}) option,
8038 @command{tar} will do none of these transformations.
8039
8040 To archive or extract files relative to the root directory, specify
8041 the @option{--absolute-names} (@option{-P}) option.
8042
8043 Normally, @command{tar} acts on files relative to the working
8044 directory---ignoring superior directory names when archiving, and
8045 ignoring leading slashes when extracting.
8046
8047 When you specify @option{--absolute-names} (@option{-P}),
8048 @command{tar} stores file names including all superior directory
8049 names, and preserves leading slashes. If you only invoked
8050 @command{tar} from the root directory you would never need the
8051 @option{--absolute-names} option, but using this option
8052 may be more convenient than switching to root.
8053
8054 @FIXME{Should be an example in the tutorial/wizardry section using this
8055 to transfer files between systems.}
8056
8057 @FIXME{Is write access an issue?}
8058
8059 @table @option
8060 @item --absolute-names
8061 Preserves full file names (including superior directory names) when
8062 archiving files. Preserves leading slash when extracting files.
8063
8064 @end table
8065
8066 @FIXME{this is still horrible; need to talk with dan on monday.}
8067
8068 @command{tar} prints out a message about removing the @samp{/} from
8069 file names. This message appears once per @GNUTAR{}
8070 invocation. It represents something which ought to be told; ignoring
8071 what it means can cause very serious surprises, later.
8072
8073 Some people, nevertheless, do not want to see this message. Wanting to
8074 play really dangerously, one may of course redirect @command{tar} standard
8075 error to the sink. For example, under @command{sh}:
8076
8077 @smallexample
8078 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8079 @end smallexample
8080
8081 @noindent
8082 Another solution, both nicer and simpler, would be to change to
8083 the @file{/} directory first, and then avoid absolute notation.
8084 For example:
8085
8086 @smallexample
8087 $ @kbd{(cd / && tar -c -f archive.tar home)}
8088 # @i{or}:
8089 $ @kbd{tar -c -f archive.tar -C / home}
8090 @end smallexample
8091
8092 @include getdate.texi
8093
8094 @node Formats
8095 @chapter Controlling the Archive Format
8096
8097 @cindex Tar archive formats
8098 Due to historical reasons, there are several formats of tar archives.
8099 All of them are based on the same principles, but have some subtle
8100 differences that often make them incompatible with each other.
8101
8102 GNU tar is able to create and handle archives in a variety of formats.
8103 The most frequently used formats are (in alphabetical order):
8104
8105 @table @asis
8106 @item gnu
8107 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8108 from an early @acronym{POSIX} standard, adding some improvements such as
8109 sparse file handling and incremental archives. Unfortunately these
8110 features were implemented in a way incompatible with other archive
8111 formats.
8112
8113 Archives in @samp{gnu} format are able to hold file names of unlimited
8114 length.
8115
8116 @item oldgnu
8117 Format used by @GNUTAR{} of versions prior to 1.12.
8118
8119 @item v7
8120 Archive format, compatible with the V7 implementation of tar. This
8121 format imposes a number of limitations. The most important of them
8122 are:
8123
8124 @enumerate
8125 @item The maximum length of a file name is limited to 99 characters.
8126 @item The maximum length of a symbolic link is limited to 99 characters.
8127 @item It is impossible to store special files (block and character
8128 devices, fifos etc.)
8129 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8130 octal)
8131 @item V7 archives do not contain symbolic ownership information (user
8132 and group name of the file owner).
8133 @end enumerate
8134
8135 This format has traditionally been used by Automake when producing
8136 Makefiles. This practice will change in the future, in the meantime,
8137 however this means that projects containing file names more than 99
8138 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8139 Automake prior to 1.9.
8140
8141 @item ustar
8142 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8143 symbolic ownership information. It is also able to store
8144 special files. However, it imposes several restrictions as well:
8145
8146 @enumerate
8147 @item The maximum length of a file name is limited to 256 characters,
8148 provided that the file name can be split at a directory separator in
8149 two parts, first of them being at most 155 bytes long. So, in most
8150 cases the maximum file name length will be shorter than 256
8151 characters.
8152 @item The maximum length of a symbolic link name is limited to
8153 100 characters.
8154 @item Maximum size of a file the archive is able to accommodate
8155 is 8GB
8156 @item Maximum value of UID/GID is 2097151.
8157 @item Maximum number of bits in device major and minor numbers is 21.
8158 @end enumerate
8159
8160 @item star
8161 Format used by J@"org Schilling @command{star}
8162 implementation. @GNUTAR{} is able to read @samp{star} archives but
8163 currently does not produce them.
8164
8165 @item posix
8166 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8167 most flexible and feature-rich format. It does not impose any
8168 restrictions on file sizes or file name lengths. This format is quite
8169 recent, so not all tar implementations are able to handle it properly.
8170 However, this format is designed in such a way that any tar
8171 implementation able to read @samp{ustar} archives will be able to read
8172 most @samp{posix} archives as well, with the only exception that any
8173 additional information (such as long file names etc.) will in such
8174 case be extracted as plain text files along with the files it refers to.
8175
8176 This archive format will be the default format for future versions
8177 of @GNUTAR{}.
8178
8179 @end table
8180
8181 The following table summarizes the limitations of each of these
8182 formats:
8183
8184 @multitable @columnfractions .10 .20 .20 .20 .20
8185 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8186 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8187 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8188 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8189 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8190 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8191 @end multitable
8192
8193 The default format for @GNUTAR{} is defined at compilation
8194 time. You may check it by running @command{tar --help}, and examining
8195 the last lines of its output. Usually, @GNUTAR{} is configured
8196 to create archives in @samp{gnu} format, however, future version will
8197 switch to @samp{posix}.
8198
8199 @menu
8200 * Compression:: Using Less Space through Compression
8201 * Attributes:: Handling File Attributes
8202 * Portability:: Making @command{tar} Archives More Portable
8203 * cpio:: Comparison of @command{tar} and @command{cpio}
8204 @end menu
8205
8206 @node Compression
8207 @section Using Less Space through Compression
8208
8209 @menu
8210 * gzip:: Creating and Reading Compressed Archives
8211 * sparse:: Archiving Sparse Files
8212 @end menu
8213
8214 @node gzip
8215 @subsection Creating and Reading Compressed Archives
8216 @cindex Compressed archives
8217 @cindex Storing archives in compressed format
8218
8219 @GNUTAR{} is able to create and read compressed archives. It supports
8220 @command{gzip}, @command{bzip2} and @command{lzma} compression
8221 programs. For backward compatibility, it also supports
8222 @command{compress} command, although we strongly recommend against
8223 using it, because it is by far less effective than other compression
8224 programs@footnote{It also had patent problems in the past.}.
8225
8226 Creating a compressed archive is simple: you just specify a
8227 @dfn{compression option} along with the usual archive creation
8228 commands. The compression option is @option{-z} (@option{--gzip}) to
8229 create a @command{gzip} compressed archive, @option{-j}
8230 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8231 @command{lzma} to create an @asis{LZMA} compressed archive and
8232 @option{-Z} (@option{--compress}) to use @command{compress} program.
8233 For example:
8234
8235 @smallexample
8236 $ @kbd{tar cfz archive.tar.gz .}
8237 @end smallexample
8238
8239 You can also let @GNUTAR{} select the compression program basing on
8240 the suffix of the archive file name. This is done using
8241 @option{--auto-compress} (@option{-a}) command line option. For
8242 example, the following invocation will use @command{bzip2} for
8243 compression:
8244
8245 @smallexample
8246 $ @kbd{tar cfa archive.tar.bz2 .}
8247 @end smallexample
8248
8249 @noindent
8250 whereas the following one will use @command{lzma}:
8251
8252 @smallexample
8253 $ @kbd{tar cfa archive.tar.lzma .}
8254 @end smallexample
8255
8256 For a complete list of file name suffixes recognized by @GNUTAR{},
8257 @ref{auto-compress}.
8258
8259 Reading compressed archive is even simpler: you don't need to specify
8260 any additional options as @GNUTAR{} recognizes its format
8261 automatically. Thus, the following commands will list and extract the
8262 archive created in previous example:
8263
8264 @smallexample
8265 # List the compressed archive
8266 $ @kbd{tar tf archive.tar.gz}
8267 # Extract the compressed archive
8268 $ @kbd{tar xf archive.tar.gz}
8269 @end smallexample
8270
8271 The only case when you have to specify a decompression option while
8272 reading the archive is when reading from a pipe or from a tape drive
8273 that does not support random access. However, in this case @GNUTAR{}
8274 will indicate which option you should use. For example:
8275
8276 @smallexample
8277 $ @kbd{cat archive.tar.gz | tar tf -}
8278 tar: Archive is compressed. Use -z option
8279 tar: Error is not recoverable: exiting now
8280 @end smallexample
8281
8282 If you see such diagnostics, just add the suggested option to the
8283 invocation of @GNUTAR{}:
8284
8285 @smallexample
8286 $ @kbd{cat archive.tar.gz | tar tfz -}
8287 @end smallexample
8288
8289 Notice also, that there are several restrictions on operations on
8290 compressed archives. First of all, compressed archives cannot be
8291 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
8292 (@option{--delete}) members from them. Likewise, you cannot append
8293 another @command{tar} archive to a compressed archive using
8294 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
8295 compressed.
8296
8297 The following table summarizes compression options used by @GNUTAR{}.
8298
8299 @table @option
8300 @anchor{auto-compress}
8301 @opindex auto-compress
8302 @item --auto-compress
8303 @itemx -a
8304 Select a compression program to use by the archive file name
8305 suffix. The following suffixes are recognized:
8306
8307 @multitable @columnfractions 0.3 0.6
8308 @headitem Suffix @tab Compression program
8309 @item @samp{.gz} @tab @command{gzip}
8310 @item @samp{.tgz} @tab @command{gzip}
8311 @item @samp{.taz} @tab @command{gzip}
8312 @item @samp{.Z} @tab @command{compress}
8313 @item @samp{.taZ} @tab @command{compress}
8314 @item @samp{.bz2} @tab @command{bzip2}
8315 @item @samp{.tz2} @tab @command{bzip2}
8316 @item @samp{.tbz2} @tab @command{bzip2}
8317 @item @samp{.tbz} @tab @command{bzip2}
8318 @item @samp{.lzma} @tab @command{lzma}
8319 @item @samp{.tlz} @tab @command{lzma}
8320 @end multitable
8321
8322 @opindex gzip
8323 @opindex ungzip
8324 @item -z
8325 @itemx --gzip
8326 @itemx --ungzip
8327 Filter the archive through @command{gzip}.
8328
8329 You can use @option{--gzip} and @option{--gunzip} on physical devices
8330 (tape drives, etc.) and remote files as well as on normal files; data
8331 to or from such devices or remote files is reblocked by another copy
8332 of the @command{tar} program to enforce the specified (or default) record
8333 size. The default compression parameters are used; if you need to
8334 override them, set @env{GZIP} environment variable, e.g.:
8335
8336 @smallexample
8337 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8338 @end smallexample
8339
8340 @noindent
8341 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
8342 @command{gzip} explicitly:
8343
8344 @smallexample
8345 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8346 @end smallexample
8347
8348 @cindex corrupted archives
8349 About corrupted compressed archives: @command{gzip}'ed files have no
8350 redundancy, for maximum compression. The adaptive nature of the
8351 compression scheme means that the compression tables are implicitly
8352 spread all over the archive. If you lose a few blocks, the dynamic
8353 construction of the compression tables becomes unsynchronized, and there
8354 is little chance that you could recover later in the archive.
8355
8356 There are pending suggestions for having a per-volume or per-file
8357 compression in @GNUTAR{}. This would allow for viewing the
8358 contents without decompression, and for resynchronizing decompression at
8359 every volume or file, in case of corrupted archives. Doing so, we might
8360 lose some compressibility. But this would have make recovering easier.
8361 So, there are pros and cons. We'll see!
8362
8363 @opindex bzip2
8364 @item -j
8365 @itemx --bzip2
8366 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
8367
8368 @opindex lzma
8369 @item --lzma
8370 Filter the archive through @command{lzma}. Otherwise like @option{--gzip}.
8371
8372 @opindex compress
8373 @opindex uncompress
8374 @item -Z
8375 @itemx --compress
8376 @itemx --uncompress
8377 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
8378
8379 @opindex use-compress-program
8380 @item --use-compress-program=@var{prog}
8381 Use external compression program @var{prog}. Use this option if you
8382 have a compression program that @GNUTAR{} does not support. There
8383 are two requirements to which @var{prog} should comply:
8384
8385 First, when called without options, it should read data from standard
8386 input, compress it and output it on standard output.
8387
8388 Secondly, if called with @option{-d} argument, it should do exactly
8389 the opposite, i.e., read the compressed data from the standard input
8390 and produce uncompressed data on the standard output.
8391 @end table
8392
8393 @cindex gpg, using with tar
8394 @cindex gnupg, using with tar
8395 @cindex Using encrypted archives
8396 The @option{--use-compress-program} option, in particular, lets you
8397 implement your own filters, not necessarily dealing with
8398 compression/decompression. For example, suppose you wish to implement
8399 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8400 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8401 Manual}). The following script does that:
8402
8403 @smallexample
8404 @group
8405 #! /bin/sh
8406 case $1 in
8407 -d) gpg --decrypt - | gzip -d -c;;
8408 '') gzip -c | gpg -s ;;
8409 *) echo "Unknown option $1">&2; exit 1;;
8410 esac
8411 @end group
8412 @end smallexample
8413
8414 Suppose you name it @file{gpgz} and save it somewhere in your
8415 @env{PATH}. Then the following command will create a compressed
8416 archive signed with your private key:
8417
8418 @smallexample
8419 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
8420 @end smallexample
8421
8422 @noindent
8423 Likewise, the following command will list its contents:
8424
8425 @smallexample
8426 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
8427 @end smallexample
8428
8429 @ignore
8430 The above is based on the following discussion:
8431
8432 I have one question, or maybe it's a suggestion if there isn't a way
8433 to do it now. I would like to use @option{--gzip}, but I'd also like
8434 the output to be fed through a program like @acronym{GNU}
8435 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8436 to use :-)), basically adding ECC protection on top of compression.
8437 It seems as if this should be quite easy to do, but I can't work out
8438 exactly how to go about it. Of course, I can pipe the standard output
8439 of @command{tar} through @command{ecc}, but then I lose (though I
8440 haven't started using it yet, I confess) the ability to have
8441 @command{tar} use @command{rmt} for it's I/O (I think).
8442
8443 I think the most straightforward thing would be to let me specify a
8444 general set of filters outboard of compression (preferably ordered,
8445 so the order can be automatically reversed on input operations, and
8446 with the options they require specifiable), but beggars shouldn't be
8447 choosers and anything you decide on would be fine with me.
8448
8449 By the way, I like @command{ecc} but if (as the comments say) it can't
8450 deal with loss of block sync, I'm tempted to throw some time at adding
8451 that capability. Supposing I were to actually do such a thing and
8452 get it (apparently) working, do you accept contributed changes to
8453 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
8454
8455 Isn't that exactly the role of the
8456 @option{--use-compress-prog=@var{program}} option?
8457 I never tried it myself, but I suspect you may want to write a
8458 @var{prog} script or program able to filter stdin to stdout to
8459 way you want. It should recognize the @option{-d} option, for when
8460 extraction is needed rather than creation.
8461
8462 It has been reported that if one writes compressed data (through the
8463 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8464 the DLT compression mode, the data will actually get bigger and one will
8465 end up with less space on the tape.
8466 @end ignore
8467
8468 @node sparse
8469 @subsection Archiving Sparse Files
8470 @cindex Sparse Files
8471
8472 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
8473 in a file is a section of the file's contents which was never written.
8474 The contents of a hole reads as all zeros. On many operating systems,
8475 actual disk storage is not allocated for holes, but they are counted
8476 in the length of the file. If you archive such a file, @command{tar}
8477 could create an archive longer than the original. To have @command{tar}
8478 attempt to recognize the holes in a file, use @option{--sparse}
8479 (@option{-S}). When you use this option, then, for any file using
8480 less disk space than would be expected from its length, @command{tar}
8481 searches the file for consecutive stretches of zeros. It then records
8482 in the archive for the file where the consecutive stretches of zeros
8483 are, and only archives the ``real contents'' of the file. On
8484 extraction (using @option{--sparse} is not needed on extraction) any
8485 such files have holes created wherever the continuous stretches of zeros
8486 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8487 won't take more space than the original.
8488
8489 @table @option
8490 @opindex sparse
8491 @item -S
8492 @itemx --sparse
8493 This option instructs @command{tar} to test each file for sparseness
8494 before attempting to archive it. If the file is found to be sparse it
8495 is treated specially, thus allowing to decrease the amount of space
8496 used by its image in the archive.
8497
8498 This option is meaningful only when creating or updating archives. It
8499 has no effect on extraction.
8500 @end table
8501
8502 Consider using @option{--sparse} when performing file system backups,
8503 to avoid archiving the expanded forms of files stored sparsely in the
8504 system.
8505
8506 Even if your system has no sparse files currently, some may be
8507 created in the future. If you use @option{--sparse} while making file
8508 system backups as a matter of course, you can be assured the archive
8509 will never take more space on the media than the files take on disk
8510 (otherwise, archiving a disk filled with sparse files might take
8511 hundreds of tapes). @xref{Incremental Dumps}.
8512
8513 However, be aware that @option{--sparse} option presents a serious
8514 drawback. Namely, in order to determine if the file is sparse
8515 @command{tar} has to read it before trying to archive it, so in total
8516 the file is read @strong{twice}. So, always bear in mind that the
8517 time needed to process all files with this option is roughly twice
8518 the time needed to archive them without it.
8519 @FIXME{A technical note:
8520
8521 Programs like @command{dump} do not have to read the entire file; by
8522 examining the file system directly, they can determine in advance
8523 exactly where the holes are and thus avoid reading through them. The
8524 only data it need read are the actual allocated data blocks.
8525 @GNUTAR{} uses a more portable and straightforward
8526 archiving approach, it would be fairly difficult that it does
8527 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8528 1990-12-10:
8529
8530 @quotation
8531 What I did say is that you cannot tell the difference between a hole and an
8532 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8533 best tells you how many holes there are; it doesn't tell you @emph{where}.
8534 Just as programs may, conceivably, care what @code{st_blocks} is (care
8535 to name one that does?), they may also care where the holes are (I have
8536 no examples of this one either, but it's equally imaginable).
8537
8538 I conclude from this that good archivers are not portable. One can
8539 arguably conclude that if you want a portable program, you can in good
8540 conscience restore files with as many holes as possible, since you can't
8541 get it right.
8542 @end quotation
8543 }
8544
8545 @cindex sparse formats, defined
8546 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8547 sparse files using in three distinct ways, called @dfn{sparse
8548 formats}. A sparse format is identified by its @dfn{number},
8549 consisting, as usual of two decimal numbers, delimited by a dot. By
8550 default, format @samp{1.0} is used. If, for some reason, you wish to
8551 use an earlier format, you can select it using
8552 @option{--sparse-version} option.
8553
8554 @table @option
8555 @opindex sparse-version
8556 @item --sparse-version=@var{version}
8557
8558 Select the format to store sparse files in. Valid @var{version} values
8559 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8560 for a detailed description of each format.
8561 @end table
8562
8563 Using @option{--sparse-format} option implies @option{--sparse}.
8564
8565 @node Attributes
8566 @section Handling File Attributes
8567 @UNREVISED
8568
8569 When @command{tar} reads files, it updates their access times. To
8570 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8571 reset the access time retroactively or avoid changing it in the first
8572 place.
8573
8574 Handling of file attributes
8575
8576 @table @option
8577 @opindex atime-preserve
8578 @item --atime-preserve
8579 @itemx --atime-preserve=replace
8580 @itemx --atime-preserve=system
8581 Preserve the access times of files that are read. This works only for
8582 files that you own, unless you have superuser privileges.
8583
8584 @option{--atime-preserve=replace} works on most systems, but it also
8585 restores the data modification time and updates the status change
8586 time. Hence it doesn't interact with incremental dumps nicely
8587 (@pxref{Incremental Dumps}), and it can set access or data modification times
8588 incorrectly if other programs access the file while @command{tar} is
8589 running.
8590
8591 @option{--atime-preserve=system} avoids changing the access time in
8592 the first place, if the operating system supports this.
8593 Unfortunately, this may or may not work on any given operating system
8594 or file system. If @command{tar} knows for sure it won't work, it
8595 complains right away.
8596
8597 Currently @option{--atime-preserve} with no operand defaults to
8598 @option{--atime-preserve=replace}, but this is intended to change to
8599 @option{--atime-preserve=system} when the latter is better-supported.
8600
8601 @opindex touch
8602 @item -m
8603 @itemx --touch
8604 Do not extract data modification time.
8605
8606 When this option is used, @command{tar} leaves the data modification times
8607 of the files it extracts as the times when the files were extracted,
8608 instead of setting it to the times recorded in the archive.
8609
8610 This option is meaningless with @option{--list} (@option{-t}).
8611
8612 @opindex same-owner
8613 @item --same-owner
8614 Create extracted files with the same ownership they have in the
8615 archive.
8616
8617 This is the default behavior for the superuser,
8618 so this option is meaningful only for non-root users, when @command{tar}
8619 is executed on those systems able to give files away. This is
8620 considered as a security flaw by many people, at least because it
8621 makes quite difficult to correctly account users for the disk space
8622 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8623 files are easily and silently lost when files are given away.
8624
8625 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
8626 separately. If it can't find a user name (because the user @acronym{ID} is not
8627 in @file{/etc/passwd}), then it does not write one. When restoring,
8628 it tries to look the name (if one was written) up in
8629 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
8630 the archive instead.
8631
8632 @opindex no-same-owner
8633 @item --no-same-owner
8634 @itemx -o
8635 Do not attempt to restore ownership when extracting. This is the
8636 default behavior for ordinary users, so this option has an effect
8637 only for the superuser.
8638
8639 @opindex numeric-owner
8640 @item --numeric-owner
8641 The @option{--numeric-owner} option allows (ANSI) archives to be written
8642 without user/group name information or such information to be ignored
8643 when extracting. It effectively disables the generation and/or use
8644 of user/group name information. This option forces extraction using
8645 the numeric ids from the archive, ignoring the names.
8646
8647 This is useful in certain circumstances, when restoring a backup from
8648 an emergency floppy with different passwd/group files for example.
8649 It is otherwise impossible to extract files with the right ownerships
8650 if the password file in use during the extraction does not match the
8651 one belonging to the file system(s) being extracted. This occurs,
8652 for example, if you are restoring your files after a major crash and
8653 had booted from an emergency floppy with no password file or put your
8654 disk into another machine to do the restore.
8655
8656 The numeric ids are @emph{always} saved into @command{tar} archives.
8657 The identifying names are added at create time when provided by the
8658 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8659 used when moving archives between a collection of machines using
8660 a centralized management for attribution of numeric ids to users
8661 and groups. This is often made through using the NIS capabilities.
8662
8663 When making a @command{tar} file for distribution to other sites, it
8664 is sometimes cleaner to use a single owner for all files in the
8665 distribution, and nicer to specify the write permission bits of the
8666 files as stored in the archive independently of their actual value on
8667 the file system. The way to prepare a clean distribution is usually
8668 to have some Makefile rule creating a directory, copying all needed
8669 files in that directory, then setting ownership and permissions as
8670 wanted (there are a lot of possible schemes), and only then making a
8671 @command{tar} archive out of this directory, before cleaning
8672 everything out. Of course, we could add a lot of options to
8673 @GNUTAR{} for fine tuning permissions and ownership.
8674 This is not the good way, I think. @GNUTAR{} is
8675 already crowded with options and moreover, the approach just explained
8676 gives you a great deal of control already.
8677
8678 @xopindex{same-permissions, short description}
8679 @xopindex{preserve-permissions, short description}
8680 @item -p
8681 @itemx --same-permissions
8682 @itemx --preserve-permissions
8683 Extract all protection information.
8684
8685 This option causes @command{tar} to set the modes (access permissions) of
8686 extracted files exactly as recorded in the archive. If this option
8687 is not used, the current @code{umask} setting limits the permissions
8688 on extracted files. This option is by default enabled when
8689 @command{tar} is executed by a superuser.
8690
8691
8692 This option is meaningless with @option{--list} (@option{-t}).
8693
8694 @opindex preserve
8695 @item --preserve
8696 Same as both @option{--same-permissions} and @option{--same-order}.
8697
8698 The @option{--preserve} option has no equivalent short option name.
8699 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8700
8701 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8702 Neither do I. --Sergey}
8703
8704 @end table
8705
8706 @node Portability
8707 @section Making @command{tar} Archives More Portable
8708
8709 Creating a @command{tar} archive on a particular system that is meant to be
8710 useful later on many other machines and with other versions of @command{tar}
8711 is more challenging than you might think. @command{tar} archive formats
8712 have been evolving since the first versions of Unix. Many such formats
8713 are around, and are not always compatible with each other. This section
8714 discusses a few problems, and gives some advice about making @command{tar}
8715 archives more portable.
8716
8717 One golden rule is simplicity. For example, limit your @command{tar}
8718 archives to contain only regular files and directories, avoiding
8719 other kind of special files. Do not attempt to save sparse files or
8720 contiguous files as such. Let's discuss a few more problems, in turn.
8721
8722 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8723 archives and archive labels) in GNU and PAX formats.}
8724
8725 @menu
8726 * Portable Names:: Portable Names
8727 * dereference:: Symbolic Links
8728 * hard links:: Hard Links
8729 * old:: Old V7 Archives
8730 * ustar:: Ustar Archives
8731 * gnu:: GNU and old GNU format archives.
8732 * posix:: @acronym{POSIX} archives
8733 * Checksumming:: Checksumming Problems
8734 * Large or Negative Values:: Large files, negative time stamps, etc.
8735 * Other Tars:: How to Extract GNU-Specific Data Using
8736 Other @command{tar} Implementations
8737 @end menu
8738
8739 @node Portable Names
8740 @subsection Portable Names
8741
8742 Use portable file and member names. A name is portable if it contains
8743 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8744 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8745 contain @samp{/-}. Avoid deep directory nesting. For portability to
8746 old Unix hosts, limit your file name components to 14 characters or
8747 less.
8748
8749 If you intend to have your @command{tar} archives to be read under
8750 MSDOS, you should not rely on case distinction for file names, and you
8751 might use the @acronym{GNU} @command{doschk} program for helping you
8752 further diagnosing illegal MSDOS names, which are even more limited
8753 than System V's.
8754
8755 @node dereference
8756 @subsection Symbolic Links
8757 @cindex File names, using symbolic links
8758 @cindex Symbolic link as file name
8759
8760 @opindex dereference
8761 Normally, when @command{tar} archives a symbolic link, it writes a
8762 block to the archive naming the target of the link. In that way, the
8763 @command{tar} archive is a faithful record of the file system contents.
8764 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8765 @command{tar} to archive the files symbolic links point to, instead of
8766 the links themselves. When this option is used, when @command{tar}
8767 encounters a symbolic link, it will archive the linked-to file,
8768 instead of simply recording the presence of a symbolic link.
8769
8770 The name under which the file is stored in the file system is not
8771 recorded in the archive. To record both the symbolic link name and
8772 the file name in the system, archive the file under both names. If
8773 all links were recorded automatically by @command{tar}, an extracted file
8774 might be linked to a file name that no longer exists in the file
8775 system.
8776
8777 If a linked-to file is encountered again by @command{tar} while creating
8778 the same archive, an entire second copy of it will be stored. (This
8779 @emph{might} be considered a bug.)
8780
8781 So, for portable archives, do not archive symbolic links as such,
8782 and use @option{--dereference} (@option{-h}): many systems do not support
8783 symbolic links, and moreover, your distribution might be unusable if
8784 it contains unresolved symbolic links.
8785
8786 @node hard links
8787 @subsection Hard Links
8788 @UNREVISED{}
8789 @cindex File names, using hard links
8790 @cindex hard links, dereferencing
8791 @cindex dereferencing hard links
8792
8793 Normally, when @command{tar} archives a hard link, it writes a
8794 block to the archive naming the target of the link (a @samp{1} type
8795 block). In that way, the actual file contents is stored in file only
8796 once. For example, consider the following two files:
8797
8798 @smallexample
8799 @group
8800 $ ls
8801 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
8802 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
8803 @end group
8804 @end smallexample
8805
8806 Here, @file{jeden} is a link to @file{one}. When archiving this
8807 directory with a verbose level 2, you will get an output similar to
8808 the following:
8809
8810 @smallexample
8811 $ tar cfvv ../archive.tar .
8812 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8813 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8814 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
8815 @end smallexample
8816
8817 The last line shows that, instead of storing two copies of the file,
8818 @command{tar} stored it only once, under the name @file{jeden}, and
8819 stored file @file{one} as a hard link to this file.
8820
8821 It may be important to know that all hard links to the given file are
8822 stored in the archive. For example, this may be necessary for exact
8823 reproduction of the file system. The following option does that:
8824
8825 @table @option
8826 @xopindex{check-links, described}
8827 @item --check-links
8828 @itemx -l
8829 Check the number of links dumped for each processed file. If this
8830 number does not match the total number of hard links for the file, print
8831 a warning message.
8832 @end table
8833
8834 For example, trying to archive only file @file{jeden} with this option
8835 produces the following diagnostics:
8836
8837 @smallexample
8838 $ tar -c -f ../archive.tar jeden
8839 tar: Missing links to `jeden'.
8840 @end smallexample
8841
8842 Although creating special records for hard links helps keep a faithful
8843 record of the file system contents and makes archives more compact, it
8844 may present some difficulties when extracting individual members from
8845 the archive. For example, trying to extract file @file{one} from the
8846 archive created in previous examples produces, in the absense of file
8847 @file{jeden}:
8848
8849 @smallexample
8850 $ tar xf archive.tar ./one
8851 tar: ./one: Cannot hard link to `./jeden': No such file or directory
8852 tar: Error exit delayed from previous errors
8853 @end smallexample
8854
8855 The reason for this behavior is that @command{tar} cannot seek back in
8856 the archive to the previous member (in this case, @file{one}), to
8857 extract it@footnote{There are plans to fix this in future releases.}.
8858 If you wish to avoid such problems at the cost of a bigger archive,
8859 use the following option:
8860
8861 @table @option
8862 @xopindex{hard-dereference, described}
8863 @item --hard-dereference
8864 Dereference hard links and store the files they refer to.
8865 @end table
8866
8867 For example, trying this option on our two sample files, we get two
8868 copies in the archive, each of which can then be extracted
8869 independently of the other:
8870
8871 @smallexample
8872 @group
8873 $ tar -c -vv -f ../archive.tar --hard-dereference .
8874 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
8875 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
8876 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
8877 @end group
8878 @end smallexample
8879
8880 @node old
8881 @subsection Old V7 Archives
8882 @cindex Format, old style
8883 @cindex Old style format
8884 @cindex Old style archives
8885 @cindex v7 archive format
8886
8887 Certain old versions of @command{tar} cannot handle additional
8888 information recorded by newer @command{tar} programs. To create an
8889 archive in V7 format (not ANSI), which can be read by these old
8890 versions, specify the @option{--format=v7} option in
8891 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8892 accepts @option{--portability} or @option{--old-archive} for this
8893 option). When you specify it,
8894 @command{tar} leaves out information about directories, pipes, fifos,
8895 contiguous files, and device files, and specifies file ownership by
8896 group and user IDs instead of group and user names.
8897
8898 When updating an archive, do not use @option{--format=v7}
8899 unless the archive was created using this option.
8900
8901 In most cases, a @emph{new} format archive can be read by an @emph{old}
8902 @command{tar} program without serious trouble, so this option should
8903 seldom be needed. On the other hand, most modern @command{tar}s are
8904 able to read old format archives, so it might be safer for you to
8905 always use @option{--format=v7} for your distributions. Notice,
8906 however, that @samp{ustar} format is a better alternative, as it is
8907 free from many of @samp{v7}'s drawbacks.
8908
8909 @node ustar
8910 @subsection Ustar Archive Format
8911
8912 @cindex ustar archive format
8913 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8914 @code{ustar}. Although it is more flexible than the V7 format, it
8915 still has many restrictions (@xref{Formats,ustar}, for the detailed
8916 description of @code{ustar} format). Along with V7 format,
8917 @code{ustar} format is a good choice for archives intended to be read
8918 with other implementations of @command{tar}.
8919
8920 To create archive in @code{ustar} format, use @option{--format=ustar}
8921 option in conjunction with the @option{--create} (@option{-c}).
8922
8923 @node gnu
8924 @subsection @acronym{GNU} and old @GNUTAR{} format
8925
8926 @cindex GNU archive format
8927 @cindex Old GNU archive format
8928 @GNUTAR{} was based on an early draft of the
8929 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8930 @command{tar}, such as the support for file names longer than 100
8931 characters, use portions of the @command{tar} header record which were
8932 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8933 @acronym{POSIX} have allocated the same parts of the header record for
8934 other purposes. As a result, @GNUTAR{} format is
8935 incompatible with the current @acronym{POSIX} specification, and with
8936 @command{tar} programs that follow it.
8937
8938 In the majority of cases, @command{tar} will be configured to create
8939 this format by default. This will change in future releases, since
8940 we plan to make @samp{POSIX} format the default.
8941
8942 To force creation a @GNUTAR{} archive, use option
8943 @option{--format=gnu}.
8944
8945 @node posix
8946 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8947
8948 @cindex POSIX archive format
8949 @cindex PAX archive format
8950 Starting from version 1.14 @GNUTAR{} features full support for
8951 @acronym{POSIX.1-2001} archives.
8952
8953 A @acronym{POSIX} conformant archive will be created if @command{tar}
8954 was given @option{--format=posix} (@option{--format=pax}) option. No
8955 special option is required to read and extract from a @acronym{POSIX}
8956 archive.
8957
8958 @menu
8959 * PAX keywords:: Controlling Extended Header Keywords.
8960 @end menu
8961
8962 @node PAX keywords
8963 @subsubsection Controlling Extended Header Keywords
8964
8965 @table @option
8966 @opindex pax-option
8967 @item --pax-option=@var{keyword-list}
8968 Handle keywords in @acronym{PAX} extended headers. This option is
8969 equivalent to @option{-o} option of the @command{pax} utility.
8970 @end table
8971
8972 @var{Keyword-list} is a comma-separated
8973 list of keyword options, each keyword option taking one of
8974 the following forms:
8975
8976 @table @code
8977 @item delete=@var{pattern}
8978 When used with one of archive-creation commands,
8979 this option instructs @command{tar} to omit from extended header records
8980 that it produces any keywords matching the string @var{pattern}.
8981
8982 When used in extract or list mode, this option instructs tar
8983 to ignore any keywords matching the given @var{pattern} in the extended
8984 header records. In both cases, matching is performed using the pattern
8985 matching notation described in @acronym{POSIX 1003.2}, 3.13
8986 (@pxref{wildcards}). For example:
8987
8988 @smallexample
8989 --pax-option delete=security.*
8990 @end smallexample
8991
8992 would suppress security-related information.
8993
8994 @item exthdr.name=@var{string}
8995
8996 This keyword allows user control over the name that is written into the
8997 ustar header blocks for the extended headers. The name is obtained
8998 from @var{string} after making the following substitutions:
8999
9000 @multitable @columnfractions .25 .55
9001 @headitem Meta-character @tab Replaced By
9002 @item %d @tab The directory name of the file, equivalent to the
9003 result of the @command{dirname} utility on the translated file name.
9004 @item %f @tab The name of the file with the directory information
9005 stripped, equivalent to the result of the @command{basename} utility
9006 on the translated file name.
9007 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9008 @item %% @tab A @samp{%} character.
9009 @end multitable
9010
9011 Any other @samp{%} characters in @var{string} produce undefined
9012 results.
9013
9014 If no option @samp{exthdr.name=string} is specified, @command{tar}
9015 will use the following default value:
9016
9017 @smallexample
9018 %d/PaxHeaders.%p/%f
9019 @end smallexample
9020
9021 @item globexthdr.name=@var{string}
9022 This keyword allows user control over the name that is written into
9023 the ustar header blocks for global extended header records. The name
9024 is obtained from the contents of @var{string}, after making
9025 the following substitutions:
9026
9027 @multitable @columnfractions .25 .55
9028 @headitem Meta-character @tab Replaced By
9029 @item %n @tab An integer that represents the
9030 sequence number of the global extended header record in the archive,
9031 starting at 1.
9032 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9033 @item %% @tab A @samp{%} character.
9034 @end multitable
9035
9036 Any other @samp{%} characters in @var{string} produce undefined results.
9037
9038 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9039 will use the following default value:
9040
9041 @smallexample
9042 $TMPDIR/GlobalHead.%p.%n
9043 @end smallexample
9044
9045 @noindent
9046 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9047 environment variable. If @var{TMPDIR} is not set, @command{tar}
9048 uses @samp{/tmp}.
9049
9050 @item @var{keyword}=@var{value}
9051 When used with one of archive-creation commands, these keyword/value pairs
9052 will be included at the beginning of the archive in a global extended
9053 header record. When used with one of archive-reading commands,
9054 @command{tar} will behave as if it has encountered these keyword/value
9055 pairs at the beginning of the archive in a global extended header
9056 record.
9057
9058 @item @var{keyword}:=@var{value}
9059 When used with one of archive-creation commands, these keyword/value pairs
9060 will be included as records at the beginning of an extended header for
9061 each file. This is effectively equivalent to @var{keyword}=@var{value}
9062 form except that it creates no global extended header records.
9063
9064 When used with one of archive-reading commands, @command{tar} will
9065 behave as if these keyword/value pairs were included as records at the
9066 end of each extended header; thus, they will override any global or
9067 file-specific extended header record keywords of the same names.
9068 For example, in the command:
9069
9070 @smallexample
9071 tar --format=posix --create \
9072 --file archive --pax-option gname:=user .
9073 @end smallexample
9074
9075 the group name will be forced to a new value for all files
9076 stored in the archive.
9077 @end table
9078
9079 @node Checksumming
9080 @subsection Checksumming Problems
9081
9082 SunOS and HP-UX @command{tar} fail to accept archives created using
9083 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9084 is, file names having characters with the eight bit set, because they
9085 use signed checksums, while @GNUTAR{} uses unsigned
9086 checksums while creating archives, as per @acronym{POSIX} standards. On
9087 reading, @GNUTAR{} computes both checksums and
9088 accept any. It is somewhat worrying that a lot of people may go
9089 around doing backup of their files using faulty (or at least
9090 non-standard) software, not learning about it until it's time to
9091 restore their missing files with an incompatible file extractor, or
9092 vice versa.
9093
9094 @GNUTAR{} compute checksums both ways, and accept
9095 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9096 wrong checksums. @GNUTAR{} produces the standard
9097 checksum, however, raising incompatibilities with Sun. That is to
9098 say, @GNUTAR{} has not been modified to
9099 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9100 I've been told that more recent Sun @command{tar} now read standard
9101 archives, so maybe Sun did a similar patch, after all?
9102
9103 The story seems to be that when Sun first imported @command{tar}
9104 sources on their system, they recompiled it without realizing that
9105 the checksums were computed differently, because of a change in
9106 the default signing of @code{char}'s in their compiler. So they
9107 started computing checksums wrongly. When they later realized their
9108 mistake, they merely decided to stay compatible with it, and with
9109 themselves afterwards. Presumably, but I do not really know, HP-UX
9110 has chosen that their @command{tar} archives to be compatible with Sun's.
9111 The current standards do not favor Sun @command{tar} format. In any
9112 case, it now falls on the shoulders of SunOS and HP-UX users to get
9113 a @command{tar} able to read the good archives they receive.
9114
9115 @node Large or Negative Values
9116 @subsection Large or Negative Values
9117 @cindex large values
9118 @cindex future time stamps
9119 @cindex negative time stamps
9120 @UNREVISED{}
9121
9122 The above sections suggest to use @samp{oldest possible} archive
9123 format if in doubt. However, sometimes it is not possible. If you
9124 attempt to archive a file whose metadata cannot be represented using
9125 required format, @GNUTAR{} will print error message and ignore such a
9126 file. You will than have to switch to a format that is able to
9127 handle such values. The format summary table (@pxref{Formats}) will
9128 help you to do so.
9129
9130 In particular, when trying to archive files larger than 8GB or with
9131 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9132 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9133 @acronym{POSIX} archive formats. When considering which format to
9134 choose, bear in mind that the @acronym{GNU} format uses
9135 two's-complement base-256 notation to store values that do not fit
9136 into standard @acronym{ustar} range. Such archives can generally be
9137 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9138 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9139 example, using two's complement representation for negative time
9140 stamps that assumes a signed 32-bit @code{time_t} generates archives
9141 that are not portable to hosts with differing @code{time_t}
9142 representations.
9143
9144 On the other hand, @acronym{POSIX} archives, generally speaking, can
9145 be extracted by any tar implementation that understands older
9146 @acronym{ustar} format. The only exception are files larger than 8GB.
9147
9148 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9149 POSIX-aware tars.}
9150
9151 @node Other Tars
9152 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9153
9154 In previous sections you became acquainted with various quirks
9155 necessary to make your archives portable. Sometimes you may need to
9156 extract archives containing GNU-specific members using some
9157 third-party @command{tar} implementation or an older version of
9158 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9159 but if it is for some reason impossible, this section will explain
9160 how to cope without it.
9161
9162 When we speak about @dfn{GNU-specific} members we mean two classes of
9163 them: members split between the volumes of a multi-volume archive and
9164 sparse members. You will be able to always recover such members if
9165 the archive is in PAX format. In addition split members can be
9166 recovered from archives in old GNU format. The following subsections
9167 describe the required procedures in detail.
9168
9169 @menu
9170 * Split Recovery:: Members Split Between Volumes
9171 * Sparse Recovery:: Sparse Members
9172 @end menu
9173
9174 @node Split Recovery
9175 @subsubsection Extracting Members Split Between Volumes
9176
9177 @cindex Mutli-volume archives, extracting using non-GNU tars
9178 If a member is split between several volumes of an old GNU format archive
9179 most third party @command{tar} implementation will fail to extract
9180 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9181 This program is available from
9182 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9183 home page}. It concatenates several archive volumes into a single
9184 valid archive. For example, if you have three volumes named from
9185 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9186 extract them using a third-party @command{tar}:
9187
9188 @smallexample
9189 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9190 @end smallexample
9191
9192 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9193 You could use this approach for most (although not all) PAX
9194 format archives as well. However, extracting split members from a PAX
9195 archive is a much easier task, because PAX volumes are constructed in
9196 such a way that each part of a split member is extracted to a
9197 different file by @command{tar} implementations that are not aware of
9198 GNU extensions. More specifically, the very first part retains its
9199 original name, and all subsequent parts are named using the pattern:
9200
9201 @smallexample
9202 %d/GNUFileParts.%p/%f.%n
9203 @end smallexample
9204
9205 @noindent
9206 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9207 have the following meaning:
9208
9209 @multitable @columnfractions .25 .55
9210 @headitem Meta-character @tab Replaced By
9211 @item %d @tab The directory name of the file, equivalent to the
9212 result of the @command{dirname} utility on its full name.
9213 @item %f @tab The file name of the file, equivalent to the result
9214 of the @command{basename} utility on its full name.
9215 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9216 created the archive.
9217 @item %n @tab Ordinal number of this particular part.
9218 @end multitable
9219
9220 For example, if the file @file{var/longfile} was split during archive
9221 creation between three volumes, and the creator @command{tar} process
9222 had process @acronym{ID} @samp{27962}, then the member names will be:
9223
9224 @smallexample
9225 var/longfile
9226 var/GNUFileParts.27962/longfile.1
9227 var/GNUFileParts.27962/longfile.2
9228 @end smallexample
9229
9230 When you extract your archive using a third-party @command{tar}, these
9231 files will be created on your disk, and the only thing you will need
9232 to do to restore your file in its original form is concatenate them in
9233 the proper order, for example:
9234
9235 @smallexample
9236 @group
9237 $ @kbd{cd var}
9238 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9239 GNUFileParts.27962/longfile.2 >> longfile}
9240 $ rm -f GNUFileParts.27962
9241 @end group
9242 @end smallexample
9243
9244 Notice, that if the @command{tar} implementation you use supports PAX
9245 format archives, it will probably emit warnings about unknown keywords
9246 during extraction. They will look like this:
9247
9248 @smallexample
9249 @group
9250 Tar file too small
9251 Unknown extended header keyword 'GNU.volume.filename' ignored.
9252 Unknown extended header keyword 'GNU.volume.size' ignored.
9253 Unknown extended header keyword 'GNU.volume.offset' ignored.
9254 @end group
9255 @end smallexample
9256
9257 @noindent
9258 You can safely ignore these warnings.
9259
9260 If your @command{tar} implementation is not PAX-aware, you will get
9261 more warnings and more files generated on your disk, e.g.:
9262
9263 @smallexample
9264 @group
9265 $ @kbd{tar xf vol-1.tar}
9266 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9267 normal file
9268 Unexpected EOF in archive
9269 $ @kbd{tar xf vol-2.tar}
9270 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9271 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9272 'x', extracted as normal file
9273 @end group
9274 @end smallexample
9275
9276 Ignore these warnings. The @file{PaxHeaders.*} directories created
9277 will contain files with @dfn{extended header keywords} describing the
9278 extracted files. You can delete them, unless they describe sparse
9279 members. Read further to learn more about them.
9280
9281 @node Sparse Recovery
9282 @subsubsection Extracting Sparse Members
9283
9284 @cindex sparse files, extracting with non-GNU tars
9285 Any @command{tar} implementation will be able to extract sparse members from a
9286 PAX archive. However, the extracted files will be @dfn{condensed},
9287 i.e., any zero blocks will be removed from them. When we restore such
9288 a condensed file to its original form, by adding zero blocks (or
9289 @dfn{holes}) back to their original locations, we call this process
9290 @dfn{expanding} a compressed sparse file.
9291
9292 @pindex xsparse
9293 To expand a file, you will need a simple auxiliary program called
9294 @command{xsparse}. It is available in source form from
9295 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9296 home page}.
9297
9298 @cindex sparse files v.1.0, extracting with non-GNU tars
9299 Let's begin with archive members in @dfn{sparse format
9300 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9301 The condensed file will contain both file map and file data, so no
9302 additional data will be needed to restore it. If the original file
9303 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9304 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9305 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
9306 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9307 archive (@pxref{PAX keywords}).}.
9308
9309 To expand a version 1.0 file, run @command{xsparse} as follows:
9310
9311 @smallexample
9312 $ @kbd{xsparse @file{cond-file}}
9313 @end smallexample
9314
9315 @noindent
9316 where @file{cond-file} is the name of the condensed file. The utility
9317 will deduce the name for the resulting expanded file using the
9318 following algorithm:
9319
9320 @enumerate 1
9321 @item If @file{cond-file} does not contain any directories,
9322 @file{../cond-file} will be used;
9323
9324 @item If @file{cond-file} has the form
9325 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
9326 are simple names, with no @samp{/} characters in them, the output file
9327 name will be @file{@var{dir}/@var{name}}.
9328
9329 @item Otherwise, if @file{cond-file} has the form
9330 @file{@var{dir}/@var{name}}, the output file name will be
9331 @file{@var{name}}.
9332 @end enumerate
9333
9334 In the unlikely case when this algorithm does not suit your needs,
9335 you can explicitly specify output file name as a second argument to
9336 the command:
9337
9338 @smallexample
9339 $ @kbd{xsparse @file{cond-file} @file{out-file}}
9340 @end smallexample
9341
9342 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
9343 first. In this mode, the command does not actually expand the file,
9344 but verbosely lists all actions it would be taking to do so. The dry
9345 run mode is enabled by @option{-n} command line argument:
9346
9347 @smallexample
9348 @group
9349 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
9350 Reading v.1.0 sparse map
9351 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9352 `/home/gray/sparsefile'
9353 Finished dry run
9354 @end group
9355 @end smallexample
9356
9357 To actually expand the file, you would run:
9358
9359 @smallexample
9360 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9361 @end smallexample
9362
9363 @noindent
9364 The program behaves the same way all UNIX utilities do: it will keep
9365 quiet unless it has simething important to tell you (e.g. an error
9366 condition or something). If you wish it to produce verbose output,
9367 similar to that from the dry run mode, use @option{-v} option:
9368
9369 @smallexample
9370 @group
9371 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
9372 Reading v.1.0 sparse map
9373 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9374 `/home/gray/sparsefile'
9375 Done
9376 @end group
9377 @end smallexample
9378
9379 Additionally, if your @command{tar} implementation has extracted the
9380 @dfn{extended headers} for this file, you can instruct @command{xstar}
9381 to use them in order to verify the integrity of the expanded file.
9382 The option @option{-x} sets the name of the extended header file to
9383 use. Continuing our example:
9384
9385 @smallexample
9386 @group
9387 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
9388 /home/gray/GNUSparseFile.6058/sparsefile}
9389 Reading extended header file
9390 Found variable GNU.sparse.major = 1
9391 Found variable GNU.sparse.minor = 0
9392 Found variable GNU.sparse.name = sparsefile
9393 Found variable GNU.sparse.realsize = 217481216
9394 Reading v.1.0 sparse map
9395 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9396 `/home/gray/sparsefile'
9397 Done
9398 @end group
9399 @end smallexample
9400
9401 @anchor{extracting sparse v.0.x}
9402 @cindex sparse files v.0.1, extracting with non-GNU tars
9403 @cindex sparse files v.0.0, extracting with non-GNU tars
9404 An @dfn{extended header} is a special @command{tar} archive header
9405 that precedes an archive member and contains a set of
9406 @dfn{variables}, describing the member properties that cannot be
9407 stored in the standard @code{ustar} header. While optional for
9408 expanding sparse version 1.0 members, the use of extended headers is
9409 mandatory when expanding sparse members in older sparse formats: v.0.0
9410 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
9411 Formats}.) So, for these formats, the question is: how to obtain
9412 extended headers from the archive?
9413
9414 If you use a @command{tar} implementation that does not support PAX
9415 format, extended headers for each member will be extracted as a
9416 separate file. If we represent the member name as
9417 @file{@var{dir}/@var{name}}, then the extended header file will be
9418 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
9419 @var{n} is an integer number.
9420
9421 Things become more difficult if your @command{tar} implementation
9422 does support PAX headers, because in this case you will have to
9423 manually extract the headers. We recommend the following algorithm:
9424
9425 @enumerate 1
9426 @item
9427 Consult the documentation of your @command{tar} implementation for an
9428 option that prints @dfn{block numbers} along with the archive
9429 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
9430 @command{star} has @option{-block-number}.
9431
9432 @item
9433 Obtain verbose listing using the @samp{block number} option, and
9434 find block numbers of the sparse member in question and the member
9435 immediately following it. For example, running @command{star} on our
9436 archive we obtain:
9437
9438 @smallexample
9439 @group
9440 $ @kbd{star -t -v -block-number -f arc.tar}
9441 @dots{}
9442 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
9443 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
9444 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
9445 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
9446 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
9447 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
9448 @dots{}
9449 @end group
9450 @end smallexample
9451
9452 @noindent
9453 (as usual, ignore the warnings about unknown keywords.)
9454
9455 @item
9456 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
9457 and @var{Bn} be the block number of the next member.
9458 Compute:
9459
9460 @smallexample
9461 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
9462 @end smallexample
9463
9464 @noindent
9465 This number gives the size of the extended header part in tar @dfn{blocks}.
9466 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
9467 = 7}.
9468
9469 @item
9470 Use @command{dd} to extract the headers:
9471
9472 @smallexample
9473 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
9474 @end smallexample
9475
9476 @noindent
9477 where @var{archive} is the archive name, @var{hname} is a name of the
9478 file to store the extended header in, @var{Bs} and @var{N} are
9479 computed in previous steps.
9480
9481 In our example, this command will be
9482
9483 @smallexample
9484 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
9485 @end smallexample
9486 @end enumerate
9487
9488 Finally, you can expand the condensed file, using the obtained header:
9489
9490 @smallexample
9491 @group
9492 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
9493 Reading extended header file
9494 Found variable GNU.sparse.size = 217481216
9495 Found variable GNU.sparse.numblocks = 208
9496 Found variable GNU.sparse.name = sparsefile
9497 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
9498 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
9499 Done
9500 @end group
9501 @end smallexample
9502
9503 @node cpio
9504 @section Comparison of @command{tar} and @command{cpio}
9505 @UNREVISED
9506
9507 @FIXME{Reorganize the following material}
9508
9509 The @command{cpio} archive formats, like @command{tar}, do have maximum
9510 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
9511 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
9512 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
9513 with arbitrary file name lengths, but other @command{cpio} implementations
9514 may crash unexplainedly trying to read them.
9515
9516 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
9517 @command{cpio} doesn't handle symbolic links in the form in which it comes
9518 in System V prior to SVR4, and some vendors may have added symlinks
9519 to their system without enhancing @command{cpio} to know about them.
9520 Others may have enhanced it in a way other than the way I did it
9521 at Sun, and which was adopted by AT&T (and which is, I think, also
9522 present in the @command{cpio} that Berkeley picked up from AT&T and put
9523 into a later @acronym{BSD} release---I think I gave them my changes).
9524
9525 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
9526 can handle @command{tar} format input, and write it on output, and it
9527 probably handles symbolic links. They may not have bothered doing
9528 anything to enhance @command{tar} as a result.)
9529
9530 @command{cpio} handles special files; traditional @command{tar} doesn't.
9531
9532 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
9533 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
9534 (4.3-tahoe and later).
9535
9536 @command{tar}'s way of handling multiple hard links to a file can handle
9537 file systems that support 32-bit inumbers (e.g., the @acronym{BSD} file system);
9538 @command{cpio}s way requires you to play some games (in its ``binary''
9539 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
9540 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
9541 field of the header to make sure that the file system @acronym{ID}/i-number pairs
9542 of different files were always different), and I don't know which
9543 @command{cpio}s, if any, play those games. Those that don't might get
9544 confused and think two files are the same file when they're not, and
9545 make hard links between them.
9546
9547 @command{tar}s way of handling multiple hard links to a file places only
9548 one copy of the link on the tape, but the name attached to that copy
9549 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
9550 way puts one copy for every link, but you can retrieve it using any
9551 of the names.
9552
9553 @quotation
9554 What type of check sum (if any) is used, and how is this calculated.
9555 @end quotation
9556
9557 See the attached manual pages for @command{tar} and @command{cpio} format.
9558 @command{tar} uses a checksum which is the sum of all the bytes in the
9559 @command{tar} header for a file; @command{cpio} uses no checksum.
9560
9561 @quotation
9562 If anyone knows why @command{cpio} was made when @command{tar} was present
9563 at the unix scene,
9564 @end quotation
9565
9566 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
9567 generally-available version of UNIX had @command{tar} at the time. I don't
9568 know whether any version that was generally available @emph{within AT&T}
9569 had @command{tar}, or, if so, whether the people within AT&T who did
9570 @command{cpio} knew about it.
9571
9572 On restore, if there is a corruption on a tape @command{tar} will stop at
9573 that point, while @command{cpio} will skip over it and try to restore the
9574 rest of the files.
9575
9576 The main difference is just in the command syntax and header format.
9577
9578 @command{tar} is a little more tape-oriented in that everything is blocked
9579 to start on a record boundary.
9580
9581 @quotation
9582 Is there any differences between the ability to recover crashed
9583 archives between the two of them. (Is there any chance of recovering
9584 crashed archives at all.)
9585 @end quotation
9586
9587 Theoretically it should be easier under @command{tar} since the blocking
9588 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9589 However, modern @command{cpio}'s and variations have an option to just
9590 search for the next file header after an error with a reasonable chance
9591 of resyncing. However, lots of tape driver software won't allow you to
9592 continue past a media error which should be the only reason for getting
9593 out of sync unless a file changed sizes while you were writing the
9594 archive.
9595
9596 @quotation
9597 If anyone knows why @command{cpio} was made when @command{tar} was present
9598 at the unix scene, please tell me about this too.
9599 @end quotation
9600
9601 Probably because it is more media efficient (by not blocking everything
9602 and using only the space needed for the headers where @command{tar}
9603 always uses 512 bytes per file header) and it knows how to archive
9604 special files.
9605
9606 You might want to look at the freely available alternatives. The
9607 major ones are @command{afio}, @GNUTAR{}, and
9608 @command{pax}, each of which have their own extensions with some
9609 backwards compatibility.
9610
9611 Sparse files were @command{tar}red as sparse files (which you can
9612 easily test, because the resulting archive gets smaller, and
9613 @acronym{GNU} @command{cpio} can no longer read it).
9614
9615 @node Media
9616 @chapter Tapes and Other Archive Media
9617 @UNREVISED
9618
9619 A few special cases about tape handling warrant more detailed
9620 description. These special cases are discussed below.
9621
9622 Many complexities surround the use of @command{tar} on tape drives. Since
9623 the creation and manipulation of archives located on magnetic tape was
9624 the original purpose of @command{tar}, it contains many features making
9625 such manipulation easier.
9626
9627 Archives are usually written on dismountable media---tape cartridges,
9628 mag tapes, or floppy disks.
9629
9630 The amount of data a tape or disk holds depends not only on its size,
9631 but also on how it is formatted. A 2400 foot long reel of mag tape
9632 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9633 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9634
9635 Magnetic media are re-usable---once the archive on a tape is no longer
9636 needed, the archive can be erased and the tape or disk used over.
9637 Media quality does deteriorate with use, however. Most tapes or disks
9638 should be discarded when they begin to produce data errors. EXABYTE
9639 tape cartridges should be discarded when they generate an @dfn{error
9640 count} (number of non-usable bits) of more than 10k.
9641
9642 Magnetic media are written and erased using magnetic fields, and
9643 should be protected from such fields to avoid damage to stored data.
9644 Sticking a floppy disk to a filing cabinet using a magnet is probably
9645 not a good idea.
9646
9647 @menu
9648 * Device:: Device selection and switching
9649 * Remote Tape Server::
9650 * Common Problems and Solutions::
9651 * Blocking:: Blocking
9652 * Many:: Many archives on one tape
9653 * Using Multiple Tapes:: Using Multiple Tapes
9654 * label:: Including a Label in the Archive
9655 * verify::
9656 * Write Protection::
9657 @end menu
9658
9659 @node Device
9660 @section Device Selection and Switching
9661 @UNREVISED
9662
9663 @table @option
9664 @item -f [@var{hostname}:]@var{file}
9665 @itemx --file=[@var{hostname}:]@var{file}
9666 Use archive file or device @var{file} on @var{hostname}.
9667 @end table
9668
9669 This option is used to specify the file name of the archive @command{tar}
9670 works on.
9671
9672 If the file name is @samp{-}, @command{tar} reads the archive from standard
9673 input (when listing or extracting), or writes it to standard output
9674 (when creating). If the @samp{-} file name is given when updating an
9675 archive, @command{tar} will read the original archive from its standard
9676 input, and will write the entire new archive to its standard output.
9677
9678 If the file name contains a @samp{:}, it is interpreted as
9679 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9680 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9681 either case, @command{tar} will invoke the command @command{rsh} (or
9682 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9683 machine. If you give an alternate login name, it will be given to the
9684 @command{rsh}.
9685 Naturally, the remote machine must have an executable
9686 @command{/usr/libexec/rmt}. This program is free software from the
9687 University of California, and a copy of the source code can be found
9688 with the sources for @command{tar}; it's compiled and installed by default.
9689 The exact path to this utility is determined when configuring the package.
9690 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9691 your installation prefix. This location may also be overridden at
9692 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9693 ---rmt-command}, for detailed description of this option. @xref{Remote
9694 Tape Server}, for the description of @command{rmt} command).
9695
9696 If this option is not given, but the environment variable @env{TAPE}
9697 is set, its value is used; otherwise, old versions of @command{tar}
9698 used a default archive name (which was picked when @command{tar} was
9699 compiled). The default is normally set up to be the @dfn{first} tape
9700 drive or other transportable I/O medium on the system.
9701
9702 Starting with version 1.11.5, @GNUTAR{} uses
9703 standard input and standard output as the default device, and I will
9704 not try anymore supporting automatic device detection at installation
9705 time. This was failing really in too many cases, it was hopeless.
9706 This is now completely left to the installer to override standard
9707 input and standard output for default device, if this seems
9708 preferable. Further, I think @emph{most} actual usages of
9709 @command{tar} are done with pipes or disks, not really tapes,
9710 cartridges or diskettes.
9711
9712 Some users think that using standard input and output is running
9713 after trouble. This could lead to a nasty surprise on your screen if
9714 you forget to specify an output file name---especially if you are going
9715 through a network or terminal server capable of buffering large amounts
9716 of output. We had so many bug reports in that area of configuring
9717 default tapes automatically, and so many contradicting requests, that
9718 we finally consider the problem to be portably intractable. We could
9719 of course use something like @samp{/dev/tape} as a default, but this
9720 is @emph{also} running after various kind of trouble, going from hung
9721 processes to accidental destruction of real tapes. After having seen
9722 all this mess, using standard input and output as a default really
9723 sounds like the only clean choice left, and a very useful one too.
9724
9725 @GNUTAR{} reads and writes archive in records, I
9726 suspect this is the main reason why block devices are preferred over
9727 character devices. Most probably, block devices are more efficient
9728 too. The installer could also check for @samp{DEFTAPE} in
9729 @file{<sys/mtio.h>}.
9730
9731 @table @option
9732 @xopindex{force-local, short description}
9733 @item --force-local
9734 Archive file is local even if it contains a colon.
9735
9736 @opindex rsh-command
9737 @item --rsh-command=@var{command}
9738 Use remote @var{command} instead of @command{rsh}. This option exists
9739 so that people who use something other than the standard @command{rsh}
9740 (e.g., a Kerberized @command{rsh}) can access a remote device.
9741
9742 When this command is not used, the shell command found when
9743 the @command{tar} program was installed is used instead. This is
9744 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9745 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9746 The installer may have overridden this by defining the environment
9747 variable @env{RSH} @emph{at installation time}.
9748
9749 @item -[0-7][lmh]
9750 Specify drive and density.
9751
9752 @xopindex{multi-volume, short description}
9753 @item -M
9754 @itemx --multi-volume
9755 Create/list/extract multi-volume archive.
9756
9757 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9758 that may be larger than will fit on the medium used to hold it.
9759 @xref{Multi-Volume Archives}.
9760
9761 @xopindex{tape-length, short description}
9762 @item -L @var{num}
9763 @itemx --tape-length=@var{num}
9764 Change tape after writing @var{num} x 1024 bytes.
9765
9766 This option might be useful when your tape drivers do not properly
9767 detect end of physical tapes. By being slightly conservative on the
9768 maximum tape length, you might avoid the problem entirely.
9769
9770 @xopindex{info-script, short description}
9771 @xopindex{new-volume-script, short description}
9772 @item -F @var{file}
9773 @itemx --info-script=@var{file}
9774 @itemx --new-volume-script=@var{file}
9775 Execute @file{file} at end of each tape. This implies
9776 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9777 description of this option.
9778 @end table
9779
9780 @node Remote Tape Server
9781 @section The Remote Tape Server
9782
9783 @cindex remote tape drive
9784 @pindex rmt
9785 In order to access the tape drive on a remote machine, @command{tar}
9786 uses the remote tape server written at the University of California at
9787 Berkeley. The remote tape server must be installed as
9788 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9789 want to use. @command{tar} calls @command{rmt} by running an
9790 @command{rsh} or @command{remsh} to the remote machine, optionally
9791 using a different login name if one is supplied.
9792
9793 A copy of the source for the remote tape server is provided. It is
9794 Copyright @copyright{} 1983 by the Regents of the University of
9795 California, but can be freely distributed. It is compiled and
9796 installed by default.
9797
9798 @cindex absolute file names
9799 Unless you use the @option{--absolute-names} (@option{-P}) option,
9800 @GNUTAR{} will not allow you to create an archive that contains
9801 absolute file names (a file name beginning with @samp{/}.) If you try,
9802 @command{tar} will automatically remove the leading @samp{/} from the
9803 file names it stores in the archive. It will also type a warning
9804 message telling you what it is doing.
9805
9806 When reading an archive that was created with a different
9807 @command{tar} program, @GNUTAR{} automatically
9808 extracts entries in the archive which have absolute file names as if
9809 the file names were not absolute. This is an important feature. A
9810 visitor here once gave a @command{tar} tape to an operator to restore;
9811 the operator used Sun @command{tar} instead of @GNUTAR{},
9812 and the result was that it replaced large portions of
9813 our @file{/bin} and friends with versions from the tape; needless to
9814 say, we were unhappy about having to recover the file system from
9815 backup tapes.
9816
9817 For example, if the archive contained a file @file{/usr/bin/computoy},
9818 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9819 relative to the current directory. If you want to extract the files in
9820 an archive to the same absolute names that they had when the archive
9821 was created, you should do a @samp{cd /} before extracting the files
9822 from the archive, or you should either use the @option{--absolute-names}
9823 option, or use the command @samp{tar -C / @dots{}}.
9824
9825 @cindex Ultrix 3.1 and write failure
9826 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9827 can claim that a short write near the end of a tape succeeded,
9828 when it actually failed. This will result in the -M option not
9829 working correctly. The best workaround at the moment is to use a
9830 significantly larger blocking factor than the default 20.
9831
9832 In order to update an archive, @command{tar} must be able to backspace the
9833 archive in order to reread or rewrite a record that was just read (or
9834 written). This is currently possible only on two kinds of files: normal
9835 disk files (or any other file that can be backspaced with @samp{lseek}),
9836 and industry-standard 9-track magnetic tape (or any other kind of tape
9837 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9838
9839 This means that the @option{--append}, @option{--concatenate}, and
9840 @option{--delete} commands will not work on any other kind of file.
9841 Some media simply cannot be backspaced, which means these commands and
9842 options will never be able to work on them. These non-backspacing
9843 media include pipes and cartridge tape drives.
9844
9845 Some other media can be backspaced, and @command{tar} will work on them
9846 once @command{tar} is modified to do so.
9847
9848 Archives created with the @option{--multi-volume}, @option{--label}, and
9849 @option{--incremental} (@option{-G}) options may not be readable by other version
9850 of @command{tar}. In particular, restoring a file that was split over
9851 a volume boundary will require some careful work with @command{dd}, if
9852 it can be done at all. Other versions of @command{tar} may also create
9853 an empty file whose name is that of the volume header. Some versions
9854 of @command{tar} may create normal files instead of directories archived
9855 with the @option{--incremental} (@option{-G}) option.
9856
9857 @node Common Problems and Solutions
9858 @section Some Common Problems and their Solutions
9859
9860 @ifclear PUBLISH
9861
9862 @format
9863 errors from system:
9864 permission denied
9865 no such file or directory
9866 not owner
9867
9868 errors from @command{tar}:
9869 directory checksum error
9870 header format error
9871
9872 errors from media/system:
9873 i/o error
9874 device busy
9875 @end format
9876
9877 @end ifclear
9878
9879 @node Blocking
9880 @section Blocking
9881 @UNREVISED
9882
9883 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9884 is also confusing to the expert reader. On the other hand, readers
9885 who are new to the field have a fresh mind, and they may safely skip
9886 the next two paragraphs, as the remainder of this manual uses those
9887 two terms in a quite consistent way.
9888
9889 John Gilmore, the writer of the public domain @command{tar} from which
9890 @GNUTAR{} was originally derived, wrote (June 1995):
9891
9892 @quotation
9893 The nomenclature of tape drives comes from IBM, where I believe
9894 they were invented for the IBM 650 or so. On IBM mainframes, what
9895 is recorded on tape are tape blocks. The logical organization of
9896 data is into records. There are various ways of putting records into
9897 blocks, including @code{F} (fixed sized records), @code{V} (variable
9898 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9899 to a block), @code{VB} (variable size records, @var{n} to a block),
9900 @code{VSB} (variable spanned blocked: variable sized records that can
9901 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9902 parameter specified this to the operating system.
9903
9904 The Unix man page on @command{tar} was totally confused about this.
9905 When I wrote @code{PD TAR}, I used the historically correct terminology
9906 (@command{tar} writes data records, which are grouped into blocks).
9907 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9908 here), and now Fran@,{c}ois has migrated that terminology back
9909 into the source code too.
9910 @end quotation
9911
9912 The term @dfn{physical block} means the basic transfer chunk from or
9913 to a device, after which reading or writing may stop without anything
9914 being lost. In this manual, the term @dfn{block} usually refers to
9915 a disk physical block, @emph{assuming} that each disk block is 512
9916 bytes in length. It is true that some disk devices have different
9917 physical blocks, but @command{tar} ignore these differences in its own
9918 format, which is meant to be portable, so a @command{tar} block is always
9919 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9920 The term @dfn{logical block} often represents the basic chunk of
9921 allocation of many disk blocks as a single entity, which the operating
9922 system treats somewhat atomically; this concept is only barely used
9923 in @GNUTAR{}.
9924
9925 The term @dfn{physical record} is another way to speak of a physical
9926 block, those two terms are somewhat interchangeable. In this manual,
9927 the term @dfn{record} usually refers to a tape physical block,
9928 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9929 It is true that archives may be put on disk or used with pipes,
9930 but nevertheless, @command{tar} tries to read and write the archive one
9931 @dfn{record} at a time, whatever the medium in use. One record is made
9932 up of an integral number of blocks, and this operation of putting many
9933 disk blocks into a single tape block is called @dfn{reblocking}, or
9934 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9935 the logical organization of many characters into something meaningful
9936 to the application. The term @dfn{unit record} describes a small set
9937 of characters which are transmitted whole to or by the application,
9938 and often refers to a line of text. Those two last terms are unrelated
9939 to what we call a @dfn{record} in @GNUTAR{}.
9940
9941 When writing to tapes, @command{tar} writes the contents of the archive
9942 in chunks known as @dfn{records}. To change the default blocking
9943 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9944 @var{512-size}}) option. Each record will then be composed of
9945 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9946 @xref{Standard}.) Each file written to the archive uses at least one
9947 full record. As a result, using a larger record size can result in
9948 more wasted space for small files. On the other hand, a larger record
9949 size can often be read and written much more efficiently.
9950
9951 Further complicating the problem is that some tape drives ignore the
9952 blocking entirely. For these, a larger record size can still improve
9953 performance (because the software layers above the tape drive still
9954 honor the blocking), but not as dramatically as on tape drives that
9955 honor blocking.
9956
9957 When reading an archive, @command{tar} can usually figure out the
9958 record size on itself. When this is the case, and a non-standard
9959 record size was used when the archive was created, @command{tar} will
9960 print a message about a non-standard blocking factor, and then operate
9961 normally. On some tape devices, however, @command{tar} cannot figure
9962 out the record size itself. On most of those, you can specify a
9963 blocking factor (with @option{--blocking-factor}) larger than the
9964 actual blocking factor, and then use the @option{--read-full-records}
9965 (@option{-B}) option. (If you specify a blocking factor with
9966 @option{--blocking-factor} and don't use the
9967 @option{--read-full-records} option, then @command{tar} will not
9968 attempt to figure out the recording size itself.) On some devices,
9969 you must always specify the record size exactly with
9970 @option{--blocking-factor} when reading, because @command{tar} cannot
9971 figure it out. In any case, use @option{--list} (@option{-t}) before
9972 doing any extractions to see whether @command{tar} is reading the archive
9973 correctly.
9974
9975 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9976 putting them into records is to put a whole number of them (one or
9977 more) into each record. @command{tar} records are all the same size;
9978 at the end of the file there's a block containing all zeros, which
9979 is how you tell that the remainder of the last record(s) are garbage.
9980
9981 In a standard @command{tar} file (no options), the block size is 512
9982 and the record size is 10240, for a blocking factor of 20. What the
9983 @option{--blocking-factor} option does is sets the blocking factor,
9984 changing the record size while leaving the block size at 512 bytes.
9985 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9986 most tape drives these days prefer much bigger records in order to
9987 stream and not waste tape. When writing tapes for myself, some tend
9988 to use a factor of the order of 2048, say, giving a record size of
9989 around one megabyte.
9990
9991 If you use a blocking factor larger than 20, older @command{tar}
9992 programs might not be able to read the archive, so we recommend this
9993 as a limit to use in practice. @GNUTAR{}, however,
9994 will support arbitrarily large record sizes, limited only by the
9995 amount of virtual memory or the physical characteristics of the tape
9996 device.
9997
9998 @menu
9999 * Format Variations:: Format Variations
10000 * Blocking Factor:: The Blocking Factor of an Archive
10001 @end menu
10002
10003 @node Format Variations
10004 @subsection Format Variations
10005 @cindex Format Parameters
10006 @cindex Format Options
10007 @cindex Options, archive format specifying
10008 @cindex Options, format specifying
10009 @UNREVISED
10010
10011 Format parameters specify how an archive is written on the archive
10012 media. The best choice of format parameters will vary depending on
10013 the type and number of files being archived, and on the media used to
10014 store the archive.
10015
10016 To specify format parameters when accessing or creating an archive,
10017 you can use the options described in the following sections.
10018 If you do not specify any format parameters, @command{tar} uses
10019 default parameters. You cannot modify a compressed archive.
10020 If you create an archive with the @option{--blocking-factor} option
10021 specified (@pxref{Blocking Factor}), you must specify that
10022 blocking-factor when operating on the archive. @xref{Formats}, for other
10023 examples of format parameter considerations.
10024
10025 @node Blocking Factor
10026 @subsection The Blocking Factor of an Archive
10027 @cindex Blocking Factor
10028 @cindex Record Size
10029 @cindex Number of blocks per record
10030 @cindex Number of bytes per record
10031 @cindex Bytes per record
10032 @cindex Blocks per record
10033 @UNREVISED
10034
10035 @opindex blocking-factor
10036 The data in an archive is grouped into blocks, which are 512 bytes.
10037 Blocks are read and written in whole number multiples called
10038 @dfn{records}. The number of blocks in a record (i.e., the size of a
10039 record in units of 512 bytes) is called the @dfn{blocking factor}.
10040 The @option{--blocking-factor=@var{512-size}} (@option{-b
10041 @var{512-size}}) option specifies the blocking factor of an archive.
10042 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10043 can be specified at installation. To find out the blocking factor of
10044 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10045 This may not work on some devices.
10046
10047 Records are separated by gaps, which waste space on the archive media.
10048 If you are archiving on magnetic tape, using a larger blocking factor
10049 (and therefore larger records) provides faster throughput and allows you
10050 to fit more data on a tape (because there are fewer gaps). If you are
10051 archiving on cartridge, a very large blocking factor (say 126 or more)
10052 greatly increases performance. A smaller blocking factor, on the other
10053 hand, may be useful when archiving small files, to avoid archiving lots
10054 of nulls as @command{tar} fills out the archive to the end of the record.
10055 In general, the ideal record size depends on the size of the
10056 inter-record gaps on the tape you are using, and the average size of the
10057 files you are archiving. @xref{create}, for information on
10058 writing archives.
10059
10060 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10061
10062 Archives with blocking factors larger than 20 cannot be read
10063 by very old versions of @command{tar}, or by some newer versions
10064 of @command{tar} running on old machines with small address spaces.
10065 With @GNUTAR{}, the blocking factor of an archive is limited
10066 only by the maximum record size of the device containing the archive,
10067 or by the amount of available virtual memory.
10068
10069 Also, on some systems, not using adequate blocking factors, as sometimes
10070 imposed by the device drivers, may yield unexpected diagnostics. For
10071 example, this has been reported:
10072
10073 @smallexample
10074 Cannot write to /dev/dlt: Invalid argument
10075 @end smallexample
10076
10077 @noindent
10078 In such cases, it sometimes happen that the @command{tar} bundled by
10079 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10080 requires an explicit specification for the block size,
10081 which it cannot guess. This yields some people to consider
10082 @GNUTAR{} is misbehaving, because by comparison,
10083 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10084 for example, might resolve the problem.
10085
10086 If you use a non-default blocking factor when you create an archive, you
10087 must specify the same blocking factor when you modify that archive. Some
10088 archive devices will also require you to specify the blocking factor when
10089 reading that archive, however this is not typically the case. Usually, you
10090 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10091 reports a non-default record size and then lists the archive members as
10092 it would normally. To extract files from an archive with a non-standard
10093 blocking factor (particularly if you're not sure what the blocking factor
10094 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10095 specifying a blocking factor larger then the blocking factor of the archive
10096 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
10097 @xref{list}, for more information on the @option{--list} (@option{-t})
10098 operation. @xref{Reading}, for a more detailed explanation of that option.
10099
10100 @table @option
10101 @item --blocking-factor=@var{number}
10102 @itemx -b @var{number}
10103 Specifies the blocking factor of an archive. Can be used with any
10104 operation, but is usually not necessary with @option{--list} (@option{-t}).
10105 @end table
10106
10107 Device blocking
10108
10109 @table @option
10110 @item -b @var{blocks}
10111 @itemx --blocking-factor=@var{blocks}
10112 Set record size to @math{@var{blocks} * 512} bytes.
10113
10114 This option is used to specify a @dfn{blocking factor} for the archive.
10115 When reading or writing the archive, @command{tar}, will do reads and writes
10116 of the archive in records of @math{@var{block}*512} bytes. This is true
10117 even when the archive is compressed. Some devices requires that all
10118 write operations be a multiple of a certain size, and so, @command{tar}
10119 pads the archive out to the next record boundary.
10120
10121 The default blocking factor is set when @command{tar} is compiled, and is
10122 typically 20. Blocking factors larger than 20 cannot be read by very
10123 old versions of @command{tar}, or by some newer versions of @command{tar}
10124 running on old machines with small address spaces.
10125
10126 With a magnetic tape, larger records give faster throughput and fit
10127 more data on a tape (because there are fewer inter-record gaps).
10128 If the archive is in a disk file or a pipe, you may want to specify
10129 a smaller blocking factor, since a large one will result in a large
10130 number of null bytes at the end of the archive.
10131
10132 When writing cartridge or other streaming tapes, a much larger
10133 blocking factor (say 126 or more) will greatly increase performance.
10134 However, you must specify the same blocking factor when reading or
10135 updating the archive.
10136
10137 Apparently, Exabyte drives have a physical block size of 8K bytes.
10138 If we choose our blocksize as a multiple of 8k bytes, then the problem
10139 seems to disappear. Id est, we are using block size of 112 right
10140 now, and we haven't had the problem since we switched@dots{}
10141
10142 With @GNUTAR{} the blocking factor is limited only
10143 by the maximum record size of the device containing the archive, or by
10144 the amount of available virtual memory.
10145
10146 However, deblocking or reblocking is virtually avoided in a special
10147 case which often occurs in practice, but which requires all the
10148 following conditions to be simultaneously true:
10149 @itemize @bullet
10150 @item
10151 the archive is subject to a compression option,
10152 @item
10153 the archive is not handled through standard input or output, nor
10154 redirected nor piped,
10155 @item
10156 the archive is directly handled to a local disk, instead of any special
10157 device,
10158 @item
10159 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10160 invocation.
10161 @end itemize
10162
10163 If the output goes directly to a local disk, and not through
10164 stdout, then the last write is not extended to a full record size.
10165 Otherwise, reblocking occurs. Here are a few other remarks on this
10166 topic:
10167
10168 @itemize @bullet
10169
10170 @item
10171 @command{gzip} will complain about trailing garbage if asked to
10172 uncompress a compressed archive on tape, there is an option to turn
10173 the message off, but it breaks the regularity of simply having to use
10174 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10175 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10176 Gailly, by sending a copy of this message to him.
10177
10178 @item
10179 @command{compress} does not show this problem, but as Jean-loup pointed
10180 out to Michael, @samp{compress -d} silently adds garbage after
10181 the result of decompression, which tar ignores because it already
10182 recognized its end-of-file indicator. So this bug may be safely
10183 ignored.
10184
10185 @item
10186 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10187 but will still return an exit status of 2 which tar reports in turn.
10188 @command{tar} might ignore the exit status returned, but I hate doing
10189 that, as it weakens the protection @command{tar} offers users against
10190 other possible problems at decompression time. If @command{gzip} was
10191 silently skipping trailing zeros @emph{and} also avoiding setting the
10192 exit status in this innocuous case, that would solve this situation.
10193
10194 @item
10195 @command{tar} should become more solid at not stopping to read a pipe at
10196 the first null block encountered. This inelegantly breaks the pipe.
10197 @command{tar} should rather drain the pipe out before exiting itself.
10198 @end itemize
10199
10200 @xopindex{ignore-zeros, short description}
10201 @item -i
10202 @itemx --ignore-zeros
10203 Ignore blocks of zeros in archive (means EOF).
10204
10205 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10206 of zeros in the archive. Normally a block of zeros indicates the
10207 end of the archive, but when reading a damaged archive, or one which
10208 was created by concatenating several archives together, this option
10209 allows @command{tar} to read the entire archive. This option is not on
10210 by default because many versions of @command{tar} write garbage after
10211 the zeroed blocks.
10212
10213 Note that this option causes @command{tar} to read to the end of the
10214 archive file, which may sometimes avoid problems when multiple files
10215 are stored on a single physical tape.
10216
10217 @xopindex{read-full-records, short description}
10218 @item -B
10219 @itemx --read-full-records
10220 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10221
10222 If @option{--read-full-records} is used, @command{tar}
10223 will not panic if an attempt to read a record from the archive does
10224 not return a full record. Instead, @command{tar} will keep reading
10225 until it has obtained a full
10226 record.
10227
10228 This option is turned on by default when @command{tar} is reading
10229 an archive from standard input, or from a remote machine. This is
10230 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10231 much happens to be in the pipe, even if it is less than @command{tar}
10232 requested. If this option was not used, @command{tar} would fail as
10233 soon as it read an incomplete record from the pipe.
10234
10235 This option is also useful with the commands for updating an archive.
10236
10237 @end table
10238
10239 Tape blocking
10240
10241 @FIXME{Appropriate options should be moved here from elsewhere.}
10242
10243 @cindex blocking factor
10244 @cindex tape blocking
10245
10246 When handling various tapes or cartridges, you have to take care of
10247 selecting a proper blocking, that is, the number of disk blocks you
10248 put together as a single tape block on the tape, without intervening
10249 tape gaps. A @dfn{tape gap} is a small landing area on the tape
10250 with no information on it, used for decelerating the tape to a
10251 full stop, and for later regaining the reading or writing speed.
10252 When the tape driver starts reading a record, the record has to
10253 be read whole without stopping, as a tape gap is needed to stop the
10254 tape motion without loosing information.
10255
10256 @cindex Exabyte blocking
10257 @cindex DAT blocking
10258 Using higher blocking (putting more disk blocks per tape block) will use
10259 the tape more efficiently as there will be less tape gaps. But reading
10260 such tapes may be more difficult for the system, as more memory will be
10261 required to receive at once the whole record. Further, if there is a
10262 reading error on a huge record, this is less likely that the system will
10263 succeed in recovering the information. So, blocking should not be too
10264 low, nor it should be too high. @command{tar} uses by default a blocking of
10265 20 for historical reasons, and it does not really matter when reading or
10266 writing to disk. Current tape technology would easily accommodate higher
10267 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10268 We were told that for some DLT drives, the blocking should be a multiple
10269 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10270 Other manufacturers may use different recommendations for the same tapes.
10271 This might also depends of the buffering techniques used inside modern
10272 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
10273 Others request blocking to be some exponent of two.
10274
10275 So, there is no fixed rule for blocking. But blocking at read time
10276 should ideally be the same as blocking used at write time. At one place
10277 I know, with a wide variety of equipment, they found it best to use a
10278 blocking of 32 to guarantee that their tapes are fully interchangeable.
10279
10280 I was also told that, for recycled tapes, prior erasure (by the same
10281 drive unit that will be used to create the archives) sometimes lowers
10282 the error rates observed at rewriting time.
10283
10284 I might also use @option{--number-blocks} instead of
10285 @option{--block-number}, so @option{--block} will then expand to
10286 @option{--blocking-factor} unambiguously.
10287
10288 @node Many
10289 @section Many Archives on One Tape
10290
10291 @FIXME{Appropriate options should be moved here from elsewhere.}
10292
10293 @findex ntape @r{device}
10294 Most tape devices have two entries in the @file{/dev} directory, or
10295 entries that come in pairs, which differ only in the minor number for
10296 this device. Let's take for example @file{/dev/tape}, which often
10297 points to the only or usual tape device of a given system. There might
10298 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
10299 name is the @emph{rewinding} version of the device, while the name
10300 having @samp{nr} in it is the @emph{no rewinding} version of the same
10301 device.
10302
10303 A rewinding tape device will bring back the tape to its beginning point
10304 automatically when this device is opened or closed. Since @command{tar}
10305 opens the archive file before using it and closes it afterwards, this
10306 means that a simple:
10307
10308 @smallexample
10309 $ @kbd{tar cf /dev/tape @var{directory}}
10310 @end smallexample
10311
10312 @noindent
10313 will reposition the tape to its beginning both prior and after saving
10314 @var{directory} contents to it, thus erasing prior tape contents and
10315 making it so that any subsequent write operation will destroy what has
10316 just been saved.
10317
10318 @cindex tape positioning
10319 So, a rewinding device is normally meant to hold one and only one file.
10320 If you want to put more than one @command{tar} archive on a given tape, you
10321 will need to avoid using the rewinding version of the tape device. You
10322 will also have to pay special attention to tape positioning. Errors in
10323 positioning may overwrite the valuable data already on your tape. Many
10324 people, burnt by past experiences, will only use rewinding devices and
10325 limit themselves to one file per tape, precisely to avoid the risk of
10326 such errors. Be fully aware that writing at the wrong position on a
10327 tape loses all information past this point and most probably until the
10328 end of the tape, and this destroyed information @emph{cannot} be
10329 recovered.
10330
10331 To save @var{directory-1} as a first archive at the beginning of a
10332 tape, and leave that tape ready for a second archive, you should use:
10333
10334 @smallexample
10335 $ @kbd{mt -f /dev/nrtape rewind}
10336 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
10337 @end smallexample
10338
10339 @cindex tape marks
10340 @dfn{Tape marks} are special magnetic patterns written on the tape
10341 media, which are later recognizable by the reading hardware. These
10342 marks are used after each file, when there are many on a single tape.
10343 An empty file (that is to say, two tape marks in a row) signal the
10344 logical end of the tape, after which no file exist. Usually,
10345 non-rewinding tape device drivers will react to the close request issued
10346 by @command{tar} by first writing two tape marks after your archive, and by
10347 backspacing over one of these. So, if you remove the tape at that time
10348 from the tape drive, it is properly terminated. But if you write
10349 another file at the current position, the second tape mark will be
10350 erased by the new information, leaving only one tape mark between files.
10351
10352 So, you may now save @var{directory-2} as a second archive after the
10353 first on the same tape by issuing the command:
10354
10355 @smallexample
10356 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
10357 @end smallexample
10358
10359 @noindent
10360 and so on for all the archives you want to put on the same tape.
10361
10362 Another usual case is that you do not write all the archives the same
10363 day, and you need to remove and store the tape between two archive
10364 sessions. In general, you must remember how many files are already
10365 saved on your tape. Suppose your tape already has 16 files on it, and
10366 that you are ready to write the 17th. You have to take care of skipping
10367 the first 16 tape marks before saving @var{directory-17}, say, by using
10368 these commands:
10369
10370 @smallexample
10371 $ @kbd{mt -f /dev/nrtape rewind}
10372 $ @kbd{mt -f /dev/nrtape fsf 16}
10373 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
10374 @end smallexample
10375
10376 In all the previous examples, we put aside blocking considerations, but
10377 you should do the proper things for that as well. @xref{Blocking}.
10378
10379 @menu
10380 * Tape Positioning:: Tape Positions and Tape Marks
10381 * mt:: The @command{mt} Utility
10382 @end menu
10383
10384 @node Tape Positioning
10385 @subsection Tape Positions and Tape Marks
10386 @UNREVISED
10387
10388 Just as archives can store more than one file from the file system,
10389 tapes can store more than one archive file. To keep track of where
10390 archive files (or any other type of file stored on tape) begin and
10391 end, tape archive devices write magnetic @dfn{tape marks} on the
10392 archive media. Tape drives write one tape mark between files,
10393 two at the end of all the file entries.
10394
10395 If you think of data as a series of records "rrrr"'s, and tape marks as
10396 "*"'s, a tape might look like the following:
10397
10398 @smallexample
10399 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
10400 @end smallexample
10401
10402 Tape devices read and write tapes using a read/write @dfn{tape
10403 head}---a physical part of the device which can only access one
10404 point on the tape at a time. When you use @command{tar} to read or
10405 write archive data from a tape device, the device will begin reading
10406 or writing from wherever on the tape the tape head happens to be,
10407 regardless of which archive or what part of the archive the tape
10408 head is on. Before writing an archive, you should make sure that no
10409 data on the tape will be overwritten (unless it is no longer needed).
10410 Before reading an archive, you should make sure the tape head is at
10411 the beginning of the archive you want to read. You can do it manually
10412 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
10413 that automatically (@pxref{Scripted Restoration}).
10414
10415 If you want to add new archive file entries to a tape, you should
10416 advance the tape to the end of the existing file entries, backspace
10417 over the last tape mark, and write the new archive file. If you were
10418 to add two archives to the example above, the tape might look like the
10419 following:
10420
10421 @smallexample
10422 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
10423 @end smallexample
10424
10425 @node mt
10426 @subsection The @command{mt} Utility
10427 @UNREVISED
10428
10429 @FIXME{Is it true that this only works on non-block devices?
10430 should explain the difference, (fixed or variable).}
10431 @xref{Blocking Factor}.
10432
10433 You can use the @command{mt} utility to advance or rewind a tape past a
10434 specified number of archive files on the tape. This will allow you
10435 to move to the beginning of an archive before extracting or reading
10436 it, or to the end of all the archives before writing a new one.
10437 @FIXME{Why isn't there an "advance 'til you find two tape marks
10438 together"?}
10439
10440 The syntax of the @command{mt} command is:
10441
10442 @smallexample
10443 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
10444 @end smallexample
10445
10446 where @var{tapename} is the name of the tape device, @var{number} is
10447 the number of times an operation is performed (with a default of one),
10448 and @var{operation} is one of the following:
10449
10450 @FIXME{is there any use for record operations?}
10451
10452 @table @option
10453 @item eof
10454 @itemx weof
10455 Writes @var{number} tape marks at the current position on the tape.
10456
10457 @item fsf
10458 Moves tape position forward @var{number} files.
10459
10460 @item bsf
10461 Moves tape position back @var{number} files.
10462
10463 @item rewind
10464 Rewinds the tape. (Ignores @var{number}).
10465
10466 @item offline
10467 @itemx rewoff1
10468 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
10469
10470 @item status
10471 Prints status information about the tape unit.
10472
10473 @end table
10474
10475 @FIXME{Is there a better way to frob the spacing on the list?}
10476
10477 If you don't specify a @var{tapename}, @command{mt} uses the environment
10478 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
10479 the default device specified in your @file{sys/mtio.h} file
10480 (@code{DEFTAPE} variable). If this is not defined, the program will
10481 display a descriptive error message and exit with code 1.
10482
10483 @command{mt} returns a 0 exit status when the operation(s) were
10484 successful, 1 if the command was unrecognized, and 2 if an operation
10485 failed.
10486
10487 @node Using Multiple Tapes
10488 @section Using Multiple Tapes
10489
10490 Often you might want to write a large archive, one larger than will fit
10491 on the actual tape you are using. In such a case, you can run multiple
10492 @command{tar} commands, but this can be inconvenient, particularly if you
10493 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
10494 Therefore, @command{tar} provides a special mode for creating
10495 multi-volume archives.
10496
10497 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
10498 on several media volumes of fixed size. Although in this section we will
10499 often call @samp{volume} a @dfn{tape}, there is absolutely no
10500 requirement for multi-volume archives to be stored on tapes. Instead,
10501 they can use whatever media type the user finds convenient, they can
10502 even be located on files.
10503
10504 When creating a multi-volume archive, @GNUTAR{} continues to fill
10505 current volume until it runs out of space, then it switches to
10506 next volume (usually the operator is queried to replace the tape on
10507 this point), and continues working on the new volume. This operation
10508 continues until all requested files are dumped. If @GNUTAR{} detects
10509 end of media while dumping a file, such a file is archived in split
10510 form. Some very big files can even be split across several volumes.
10511
10512 Each volume is itself a valid @GNUTAR{} archive, so it can be read
10513 without any special options. Consequently any file member residing
10514 entirely on one volume can be extracted or otherwise operated upon
10515 without needing the other volume. Sure enough, to extract a split
10516 member you would need all volumes its parts reside on.
10517
10518 Multi-volume archives suffer from several limitations. In particular,
10519 they cannot be compressed.
10520
10521 @GNUTAR{} is able to create multi-volume archives of two formats
10522 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
10523
10524 @menu
10525 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
10526 * Tape Files:: Tape Files
10527 * Tarcat:: Concatenate Volumes into a Single Archive
10528
10529 @end menu
10530
10531 @node Multi-Volume Archives
10532 @subsection Archives Longer than One Tape or Disk
10533 @cindex Multi-volume archives
10534
10535 @opindex multi-volume
10536 To create an archive that is larger than will fit on a single unit of
10537 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
10538 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
10539 archive can be manipulated like any other archive (provided the
10540 @option{--multi-volume} option is specified), but is stored on more
10541 than one tape or disk.
10542
10543 When you specify @option{--multi-volume}, @command{tar} does not report an
10544 error when it comes to the end of an archive volume (when reading), or
10545 the end of the media (when writing). Instead, it prompts you to load
10546 a new storage volume. If the archive is on a magnetic tape, you
10547 should change tapes when you see the prompt; if the archive is on a
10548 floppy disk, you should change disks; etc.
10549
10550 @table @option
10551 @item --multi-volume
10552 @itemx -M
10553 Creates a multi-volume archive, when used in conjunction with
10554 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
10555 archive, specify @option{--multi-volume} in conjunction with that
10556 operation.
10557 For example:
10558
10559 @smallexample
10560 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
10561 @end smallexample
10562 @end table
10563
10564 The method @command{tar} uses to detect end of tape is not perfect, and
10565 fails on some operating systems or on some devices. If @command{tar}
10566 cannot detect the end of the tape itself, you can use
10567 @option{--tape-length} option to inform it about the capacity of the
10568 tape:
10569
10570 @anchor{tape-length}
10571 @table @option
10572 @opindex tape-length
10573 @item --tape-length=@var{size}
10574 @itemx -L @var{size}
10575 Set maximum length of a volume. The @var{size} argument should then
10576 be the usable size of the tape in units of 1024 bytes. This option
10577 selects @option{--multi-volume} automatically. For example:
10578
10579 @smallexample
10580 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
10581 @end smallexample
10582 @end table
10583
10584 @anchor{change volume prompt}
10585 When @GNUTAR{} comes to the end of a storage media, it asks you to
10586 change the volume. The built-in prompt for POSIX locale
10587 is@footnote{If you run @GNUTAR{} under a different locale, the
10588 translation to the locale's language will be used.}:
10589
10590 @smallexample
10591 Prepare volume #@var{n} for `@var{archive}' and hit return:
10592 @end smallexample
10593
10594 @noindent
10595 where @var{n} is the ordinal number of the volume to be created and
10596 @var{archive} is archive file or device name.
10597
10598 When prompting for a new tape, @command{tar} accepts any of the following
10599 responses:
10600
10601 @table @kbd
10602 @item ?
10603 Request @command{tar} to explain possible responses
10604 @item q
10605 Request @command{tar} to exit immediately.
10606 @item n @var{file-name}
10607 Request @command{tar} to write the next volume on the file @var{file-name}.
10608 @item !
10609 Request @command{tar} to run a subshell. This option can be disabled
10610 by giving @option{--restrict} command line option to
10611 @command{tar}@footnote{@xref{--restrict}, for more information about
10612 this option}.
10613 @item y
10614 Request @command{tar} to begin writing the next volume.
10615 @end table
10616
10617 (You should only type @samp{y} after you have changed the tape;
10618 otherwise @command{tar} will write over the volume it just finished.)
10619
10620 @cindex Volume number file
10621 @cindex volno file
10622 @anchor{volno-file}
10623 @opindex volno-file
10624 The volume number used by @command{tar} in its tape-changing prompt
10625 can be changed; if you give the
10626 @option{--volno-file=@var{file-of-number}} option, then
10627 @var{file-of-number} should be an non-existing file to be created, or
10628 else, a file already containing a decimal number. That number will be
10629 used as the volume number of the first volume written. When
10630 @command{tar} is finished, it will rewrite the file with the
10631 now-current volume number. (This does not change the volume number
10632 written on a tape label, as per @ref{label}, it @emph{only} affects
10633 the number used in the prompt.)
10634
10635 @cindex End-of-archive info script
10636 @cindex Info script
10637 @anchor{info-script}
10638 @opindex info-script
10639 @opindex new-volume-script
10640 If you want more elaborate behavior than this, you can write a special
10641 @dfn{new volume script}, that will be responsible for changing the
10642 volume, and instruct @command{tar} to use it instead of its normal
10643 prompting procedure:
10644
10645 @table @option
10646 @item --info-script=@var{script-name}
10647 @itemx --new-volume-script=@var{script-name}
10648 @itemx -F @var{script-name}
10649 Specify the full name of the volume script to use. The script can be
10650 used to eject cassettes, or to broadcast messages such as
10651 @samp{Someone please come change my tape} when performing unattended
10652 backups.
10653 @end table
10654
10655 The @var{script-name} is executed without any command line
10656 arguments. It inherits @command{tar}'s shell environment.
10657 Additional data is passed to it via the following
10658 environment variables:
10659
10660 @table @env
10661 @vrindex TAR_VERSION, info script environment variable
10662 @item TAR_VERSION
10663 @GNUTAR{} version number.
10664
10665 @vrindex TAR_ARCHIVE, info script environment variable
10666 @item TAR_ARCHIVE
10667 The name of the archive @command{tar} is processing.
10668
10669 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
10670 @item TAR_BLOCKING_FACTOR
10671 Current blocking factor (@pxref{Blocking}.
10672
10673 @vrindex TAR_VOLUME, info script environment variable
10674 @item TAR_VOLUME
10675 Ordinal number of the volume @command{tar} is about to start.
10676
10677 @vrindex TAR_SUBCOMMAND, info script environment variable
10678 @item TAR_SUBCOMMAND
10679 A short option describing the operation @command{tar} is executing
10680 @xref{Operations}, for a complete list of subcommand options.
10681
10682 @vrindex TAR_FORMAT, info script environment variable
10683 @item TAR_FORMAT
10684 Format of the archive being processed. @xref{Formats}, for a complete
10685 list of archive format names.
10686
10687 @vrindex TAR_FD, info script environment variable
10688 @item TAR_FD
10689 File descriptor which can be used to communicate the new volume
10690 name to @command{tar}.
10691 @end table
10692
10693 The volume script can instruct @command{tar} to use new archive name,
10694 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
10695
10696 If the info script fails, @command{tar} exits; otherwise, it begins
10697 writing the next volume.
10698
10699 If you want @command{tar} to cycle through a series of files or tape
10700 drives, there are three approaches to choose from. First of all, you
10701 can give @command{tar} multiple @option{--file} options. In this case
10702 the specified files will be used, in sequence, as the successive
10703 volumes of the archive. Only when the first one in the sequence needs
10704 to be used again will @command{tar} prompt for a tape change (or run
10705 the info script). For example, suppose someone has two tape drives on
10706 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10707 @GNUTAR{} to switch to the second drive when it needs to write the
10708 second tape, and then back to the first tape, etc., just do either of:
10709
10710 @smallexample
10711 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10712 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10713 @end smallexample
10714
10715 The second method is to use the @samp{n} response to the tape-change
10716 prompt.
10717
10718 Finally, the most flexible approach is to use a volume script, that
10719 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
10720 following volume script will create a series of archive files, named
10721 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10722 archive being created (as given by @option{--file} option) and
10723 @var{vol} is the ordinal number of the archive being created:
10724
10725 @smallexample
10726 @group
10727 #! /bin/sh
10728 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10729
10730 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10731 case $TAR_SUBCOMMAND in
10732 -c) ;;
10733 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10734 ;;
10735 *) exit 1
10736 esac
10737
10738 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
10739 @end group
10740 @end smallexample
10741
10742 The same script can be used while listing, comparing or extracting
10743 from the created archive. For example:
10744
10745 @smallexample
10746 @group
10747 # @r{Create a multi-volume archive:}
10748 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10749 # @r{Extract from the created archive:}
10750 $ @kbd{tar -x -f archive.tar -F new-volume .}
10751 @end group
10752 @end smallexample
10753
10754 @noindent
10755 Notice, that the first command had to use @option{-L} option, since
10756 otherwise @GNUTAR{} will end up writing everything to file
10757 @file{archive.tar}.
10758
10759 You can read each individual volume of a multi-volume archive as if it
10760 were an archive by itself. For example, to list the contents of one
10761 volume, use @option{--list}, without @option{--multi-volume} specified.
10762 To extract an archive member from one volume (assuming it is described
10763 that volume), use @option{--extract}, again without
10764 @option{--multi-volume}.
10765
10766 If an archive member is split across volumes (i.e., its entry begins on
10767 one volume of the media and ends on another), you need to specify
10768 @option{--multi-volume} to extract it successfully. In this case, you
10769 should load the volume where the archive member starts, and use
10770 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10771 volumes as it needs them. @xref{extracting archives}, for more
10772 information about extracting archives.
10773
10774 Multi-volume archives can be modified like any other archive. To add
10775 files to a multi-volume archive, you need to only mount the last
10776 volume of the archive media (and new volumes, if needed). For all
10777 other operations, you need to use the entire archive.
10778
10779 If a multi-volume archive was labeled using
10780 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10781 created, @command{tar} will not automatically label volumes which are
10782 added later. To label subsequent volumes, specify
10783 @option{--label=@var{archive-label}} again in conjunction with the
10784 @option{--append}, @option{--update} or @option{--concatenate} operation.
10785
10786 Notice that multi-volume support is a GNU extension and the archives
10787 created in this mode should be read only using @GNUTAR{}. If you
10788 absolutely have to process such archives using a third-party @command{tar}
10789 implementation, read @ref{Split Recovery}.
10790
10791 @node Tape Files
10792 @subsection Tape Files
10793 @UNREVISED
10794
10795 To give the archive a name which will be recorded in it, use the
10796 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10797 option. This will write a special block identifying
10798 @var{volume-label} as the name of the archive to the front of the
10799 archive which will be displayed when the archive is listed with
10800 @option{--list}. If you are creating a multi-volume archive with
10801 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10802 volume label will have @samp{Volume @var{nnn}} appended to the name
10803 you give, where @var{nnn} is the number of the volume of the archive.
10804 (If you use the @option{--label=@var{volume-label}}) option when
10805 reading an archive, it checks to make sure the label on the tape
10806 matches the one you give. @xref{label}.
10807
10808 When @command{tar} writes an archive to tape, it creates a single
10809 tape file. If multiple archives are written to the same tape, one
10810 after the other, they each get written as separate tape files. When
10811 extracting, it is necessary to position the tape at the right place
10812 before running @command{tar}. To do this, use the @command{mt} command.
10813 For more information on the @command{mt} command and on the organization
10814 of tapes into a sequence of tape files, see @ref{mt}.
10815
10816 People seem to often do:
10817
10818 @smallexample
10819 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10820 @end smallexample
10821
10822 or such, for pushing a common date in all volumes or an archive set.
10823
10824 @node Tarcat
10825 @subsection Concatenate Volumes into a Single Archive
10826
10827 @pindex tarcat
10828 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10829 archive to a single @command{tar} archive. Simply concatenating all
10830 volumes into one will not work, since each volume carries an additional
10831 information at the beginning. @GNUTAR{} is shipped with the shell
10832 script @command{tarcat} designed for this purpose.
10833
10834 The script takes a list of files comprising a multi-volume archive
10835 and creates the resulting archive at the standard output. For example:
10836
10837 @smallexample
10838 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10839 @end smallexample
10840
10841 The script implements a simple heuristics to determine the format of
10842 the first volume file and to decide how to process the rest of the
10843 files. However, it makes no attempt to verify whether the files are
10844 given in order or even if they are valid @command{tar} archives.
10845 It uses @command{dd} and does not filter its standard error, so you
10846 will usually see lots of spurious messages.
10847
10848 @FIXME{The script is not installed. Should we install it?}
10849
10850 @node label
10851 @section Including a Label in the Archive
10852 @cindex Labeling an archive
10853 @cindex Labels on the archive media
10854 @cindex Labeling multi-volume archives
10855 @UNREVISED
10856
10857 @opindex label
10858 To avoid problems caused by misplaced paper labels on the archive
10859 media, you can include a @dfn{label} entry---an archive member which
10860 contains the name of the archive---in the archive itself. Use the
10861 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10862 option in conjunction with the @option{--create} operation to include
10863 a label entry in the archive as it is being created.
10864
10865 @table @option
10866 @item --label=@var{archive-label}
10867 @itemx -V @var{archive-label}
10868 Includes an @dfn{archive-label} at the beginning of the archive when
10869 the archive is being created, when used in conjunction with the
10870 @option{--create} operation. Checks to make sure the archive label
10871 matches the one specified (when used in conjunction with any other
10872 operation.
10873 @end table
10874
10875 If you create an archive using both
10876 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10877 and @option{--multi-volume} (@option{-M}), each volume of the archive
10878 will have an archive label of the form @samp{@var{archive-label}
10879 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10880 next, and so on. @xref{Using Multiple Tapes}, for information on
10881 creating multiple volume archives.
10882
10883 @cindex Volume label, listing
10884 @cindex Listing volume label
10885 The volume label will be displayed by @option{--list} along with
10886 the file contents. If verbose display is requested, it will also be
10887 explicitly marked as in the example below:
10888
10889 @smallexample
10890 @group
10891 $ @kbd{tar --verbose --list --file=iamanarchive}
10892 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10893 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10894 @end group
10895 @end smallexample
10896
10897 @opindex test-label
10898 @anchor{--test-label option}
10899 However, @option{--list} option will cause listing entire
10900 contents of the archive, which may be undesirable (for example, if the
10901 archive is stored on a tape). You can request checking only the volume
10902 by specifying @option{--test-label} option. This option reads only the
10903 first block of an archive, so it can be used with slow storage
10904 devices. For example:
10905
10906 @smallexample
10907 @group
10908 $ @kbd{tar --test-label --file=iamanarchive}
10909 iamalabel
10910 @end group
10911 @end smallexample
10912
10913 If @option{--test-label} is used with a single command line
10914 argument, @command{tar} compares the volume label with the
10915 argument. It exits with code 0 if the two strings match, and with code
10916 2 otherwise. In this case no output is displayed. For example:
10917
10918 @smallexample
10919 @group
10920 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10921 @result{} 0
10922 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10923 @result{} 1
10924 @end group
10925 @end smallexample
10926
10927 If you request any operation, other than @option{--create}, along
10928 with using @option{--label} option, @command{tar} will first check if
10929 the archive label matches the one specified and will refuse to proceed
10930 if it does not. Use this as a safety precaution to avoid accidentally
10931 overwriting existing archives. For example, if you wish to add files
10932 to @file{archive}, presumably labeled with string @samp{My volume},
10933 you will get:
10934
10935 @smallexample
10936 @group
10937 $ @kbd{tar -rf archive --label 'My volume' .}
10938 tar: Archive not labeled to match `My volume'
10939 @end group
10940 @end smallexample
10941
10942 @noindent
10943 in case its label does not match. This will work even if
10944 @file{archive} is not labeled at all.
10945
10946 Similarly, @command{tar} will refuse to list or extract the
10947 archive if its label doesn't match the @var{archive-label}
10948 specified. In those cases, @var{archive-label} argument is interpreted
10949 as a globbing-style pattern which must match the actual magnetic
10950 volume label. @xref{exclude}, for a precise description of how match
10951 is attempted@footnote{Previous versions of @command{tar} used full
10952 regular expression matching, or before that, only exact string
10953 matching, instead of wildcard matchers. We decided for the sake of
10954 simplicity to use a uniform matching device through
10955 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10956 the volume label matcher will also suffix @var{archive-label} by
10957 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10958 up. Since the volume numbering is automatically added in labels at
10959 creation time, it sounded logical to equally help the user taking care
10960 of it when the archive is being read.
10961
10962 The @option{--label} was once called @option{--volume}, but is not
10963 available under that name anymore.
10964
10965 You can also use @option{--label} to get a common information on
10966 all tapes of a series. For having this information different in each
10967 series created through a single script used on a regular basis, just
10968 manage to get some date string as part of the label. For example:
10969
10970 @smallexample
10971 @group
10972 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10973 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10974 --volume="Daily backup for `date +%Y-%m-%d`"}
10975 @end group
10976 @end smallexample
10977
10978 Also note that each label has its own date and time, which corresponds
10979 to when @GNUTAR{} initially attempted to write it,
10980 often soon after the operator launches @command{tar} or types the
10981 carriage return telling that the next tape is ready. Comparing date
10982 labels does give an idea of tape throughput only if the delays for
10983 rewinding tapes and the operator switching them were negligible, which
10984 is usually not the case.
10985
10986 @node verify
10987 @section Verifying Data as It is Stored
10988 @cindex Verifying a write operation
10989 @cindex Double-checking a write operation
10990
10991 @table @option
10992 @item -W
10993 @itemx --verify
10994 @opindex verify, short description
10995 Attempt to verify the archive after writing.
10996 @end table
10997
10998 This option causes @command{tar} to verify the archive after writing it.
10999 Each volume is checked after it is written, and any discrepancies
11000 are recorded on the standard error output.
11001
11002 Verification requires that the archive be on a back-space-able medium.
11003 This means pipes, some cartridge tape drives, and some other devices
11004 cannot be verified.
11005
11006 You can insure the accuracy of an archive by comparing files in the
11007 system with archive members. @command{tar} can compare an archive to the
11008 file system as the archive is being written, to verify a write
11009 operation, or can compare a previously written archive, to insure that
11010 it is up to date.
11011
11012 @xopindex{verify, using with @option{--create}}
11013 @xopindex{create, using with @option{--verify}}
11014 To check for discrepancies in an archive immediately after it is
11015 written, use the @option{--verify} (@option{-W}) option in conjunction with
11016 the @option{--create} operation. When this option is
11017 specified, @command{tar} checks archive members against their counterparts
11018 in the file system, and reports discrepancies on the standard error.
11019
11020 To verify an archive, you must be able to read it from before the end
11021 of the last written entry. This option is useful for detecting data
11022 errors on some tapes. Archives written to pipes, some cartridge tape
11023 drives, and some other devices cannot be verified.
11024
11025 One can explicitly compare an already made archive with the file
11026 system by using the @option{--compare} (@option{--diff}, @option{-d})
11027 option, instead of using the more automatic @option{--verify} option.
11028 @xref{compare}.
11029
11030 Note that these two options have a slightly different intent. The
11031 @option{--compare} option checks how identical are the logical contents of some
11032 archive with what is on your disks, while the @option{--verify} option is
11033 really for checking if the physical contents agree and if the recording
11034 media itself is of dependable quality. So, for the @option{--verify}
11035 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11036 the archive, while it lets the speed optimization undisturbed for the
11037 @option{--compare} option. If you nevertheless use @option{--compare} for
11038 media verification, you may have to defeat the in-memory cache yourself,
11039 maybe by opening and reclosing the door latch of your recording unit,
11040 forcing some doubt in your operating system about the fact this is really
11041 the same volume as the one just written or read.
11042
11043 The @option{--verify} option would not be necessary if drivers were indeed
11044 able to detect dependably all write failures. This sometimes require many
11045 magnetic heads, some able to read after the writes occurred. One would
11046 not say that drivers unable to detect all cases are necessarily flawed,
11047 as long as programming is concerned.
11048
11049 The @option{--verify} (@option{-W}) option will not work in
11050 conjunction with the @option{--multi-volume} (@option{-M}) option or
11051 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11052 and @option{--delete} operations. @xref{Operations}, for more
11053 information on these operations.
11054
11055 Also, since @command{tar} normally strips leading @samp{/} from file
11056 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11057 /tmp/foo.tar /etc} will work as desired only if the working directory is
11058 @file{/}, as @command{tar} uses the archive's relative member names
11059 (e.g., @file{etc/motd}) when verifying the archive.
11060
11061 @node Write Protection
11062 @section Write Protection
11063
11064 Almost all tapes and diskettes, and in a few rare cases, even disks can
11065 be @dfn{write protected}, to protect data on them from being changed.
11066 Once an archive is written, you should write protect the media to prevent
11067 the archive from being accidentally overwritten or deleted. (This will
11068 protect the archive from being changed with a tape or floppy drive---it
11069 will not protect it from magnet fields or other physical hazards).
11070
11071 The write protection device itself is usually an integral part of the
11072 physical media, and can be a two position (write enabled/write
11073 disabled) switch, a notch which can be popped out or covered, a ring
11074 which can be removed from the center of a tape reel, or some other
11075 changeable feature.
11076
11077 @node Changes
11078 @appendix Changes
11079
11080 This appendix lists some important user-visible changes between
11081 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
11082 version of this document is available at
11083 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
11084 @GNUTAR{} documentation page}.
11085
11086 @table @asis
11087 @item Use of globbing patterns when listing and extracting.
11088
11089 Previous versions of GNU tar assumed shell-style globbing when
11090 extracting from or listing an archive. For example:
11091
11092 @smallexample
11093 $ @kbd{tar xf foo.tar '*.c'}
11094 @end smallexample
11095
11096 would extract all files whose names end in @samp{.c}. This behavior
11097 was not documented and was incompatible with traditional tar
11098 implementations. Therefore, starting from version 1.15.91, GNU tar
11099 no longer uses globbing by default. For example, the above invocation
11100 is now interpreted as a request to extract from the archive the file
11101 named @file{*.c}.
11102
11103 To facilitate transition to the new behavior for those users who got
11104 used to the previous incorrect one, @command{tar} will print a warning
11105 if it finds out that a requested member was not found in the archive
11106 and its name looks like a globbing pattern. For example:
11107
11108 @smallexample
11109 $ @kbd{tar xf foo.tar '*.c'}
11110 tar: Pattern matching characters used in file names. Please,
11111 tar: use --wildcards to enable pattern matching, or --no-wildcards to
11112 tar: suppress this warning.
11113 tar: *.c: Not found in archive
11114 tar: Error exit delayed from previous errors
11115 @end smallexample
11116
11117 To treat member names as globbing patterns, use --wildcards option.
11118 If you want to tar to mimic the behavior of versions prior to 1.15.91,
11119 add this option to your @env{TAR_OPTIONS} variable.
11120
11121 @xref{wildcards}, for the detailed discussion of the use of globbing
11122 patterns by @GNUTAR{}.
11123
11124 @item Use of short option @option{-o}.
11125
11126 Earlier versions of @GNUTAR{} understood @option{-o} command line
11127 option as a synonym for @option{--old-archive}.
11128
11129 @GNUTAR{} starting from version 1.13.90 understands this option as
11130 a synonym for @option{--no-same-owner}. This is compatible with
11131 UNIX98 @command{tar} implementations.
11132
11133 However, to facilitate transition, @option{-o} option retains its
11134 old semantics when it is used with one of archive-creation commands.
11135 Users are encouraged to use @option{--format=oldgnu} instead.
11136
11137 It is especially important, since versions of @acronym{GNU} Automake
11138 up to and including 1.8.4 invoke tar with this option to produce
11139 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
11140 of this issue and its implications.
11141
11142 @FIXME{Change the first argument to tar-formats when the new Automake is
11143 out. The proposition to add @anchor{} to the appropriate place of its
11144 docs was accepted by Automake people --Sergey 2006-05-25}.
11145 @xref{Options, tar-v7, Changing Automake's Behavior,
11146 automake, GNU Automake}, for a description on how to use various
11147 archive formats with @command{automake}.
11148
11149 Future versions of @GNUTAR{} will understand @option{-o} only as a
11150 synonym for @option{--no-same-owner}.
11151
11152 @item Use of short option @option{-l}
11153
11154 Earlier versions of @GNUTAR{} understood @option{-l} option as a
11155 synonym for @option{--one-file-system}. Since such usage contradicted
11156 to UNIX98 specification and harmed compatibility with other
11157 implementation, it was declared deprecated in version 1.14. However,
11158 to facilitate transition to its new semantics, it was supported by
11159 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
11160 variant of @option{--check-links} was introduced in version 1.15.91.
11161
11162 @item Use of options @option{--portability} and @option{--old-archive}
11163
11164 These options are deprecated. Please use @option{--format=v7} instead.
11165
11166 @item Use of option @option{--posix}
11167
11168 This option is deprecated. Please use @option{--format=posix} instead.
11169 @end table
11170
11171 @node Configuring Help Summary
11172 @appendix Configuring Help Summary
11173
11174 Running @kbd{tar --help} displays the short @command{tar} option
11175 summary (@pxref{help}). This summary is organized by @dfn{groups} of
11176 semantically close options. The options within each group are printed
11177 in the following order: a short option, eventually followed by a list
11178 of corresponding long option names, followed by a short description of
11179 the option. For example, here is an excerpt from the actual @kbd{tar
11180 --help} output:
11181
11182 @verbatim
11183 Main operation mode:
11184
11185 -A, --catenate, --concatenate append tar files to an archive
11186 -c, --create create a new archive
11187 -d, --diff, --compare find differences between archive and
11188 file system
11189 --delete delete from the archive
11190 @end verbatim
11191
11192 @vrindex ARGP_HELP_FMT, environment variable
11193 The exact visual representation of the help output is configurable via
11194 @env{ARGP_HELP_FMT} environment variable. The value of this variable
11195 is a comma-separated list of @dfn{format variable} assignments. There
11196 are two kinds of format variables. An @dfn{offset variable} keeps the
11197 offset of some part of help output text from the leftmost column on
11198 the screen. A @dfn{boolean} variable is a flag that toggles some
11199 output feature on or off. Depending on the type of the corresponding
11200 variable, there are two kinds of assignments:
11201
11202 @table @asis
11203 @item Offset assignment
11204
11205 The assignment to an offset variable has the following syntax:
11206
11207 @smallexample
11208 @var{variable}=@var{value}
11209 @end smallexample
11210
11211 @noindent
11212 where @var{variable} is the variable name, and @var{value} is a
11213 numeric value to be assigned to the variable.
11214
11215 @item Boolean assignment
11216
11217 To assign @code{true} value to a variable, simply put this variable name. To
11218 assign @code{false} value, prefix the variable name with @samp{no-}. For
11219 example:
11220
11221 @smallexample
11222 @group
11223 # Assign @code{true} value:
11224 dup-args
11225 # Assign @code{false} value:
11226 no-dup-args
11227 @end group
11228 @end smallexample
11229 @end table
11230
11231 Following variables are declared:
11232
11233 @deftypevr {Help Output} boolean dup-args
11234 If true, arguments for an option are shown with both short and long
11235 options, even when a given option has both forms, for example:
11236
11237 @smallexample
11238 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
11239 @end smallexample
11240
11241 If false, then if an option has both short and long forms, the
11242 argument is only shown with the long one, for example:
11243
11244 @smallexample
11245 -f, --file=ARCHIVE use archive file or device ARCHIVE
11246 @end smallexample
11247
11248 @noindent
11249 and a message indicating that the argument is applicable to both
11250 forms is printed below the options. This message can be disabled
11251 using @code{dup-args-note} (see below).
11252
11253 The default is false.
11254 @end deftypevr
11255
11256 @deftypevr {Help Output} boolean dup-args-note
11257 If this variable is true, which is the default, the following notice
11258 is displayed at the end of the help output:
11259
11260 @quotation
11261 Mandatory or optional arguments to long options are also mandatory or
11262 optional for any corresponding short options.
11263 @end quotation
11264
11265 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
11266 variables @code{dup-args} or @code{dup-args-note} should be set.
11267 @end deftypevr
11268
11269 @deftypevr {Help Output} offset short-opt-col
11270 Column in which short options start. Default is 2.
11271
11272 @smallexample
11273 @group
11274 $ @kbd{tar --help|grep ARCHIVE}
11275 -f, --file=ARCHIVE use archive file or device ARCHIVE
11276 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
11277 -f, --file=ARCHIVE use archive file or device ARCHIVE
11278 @end group
11279 @end smallexample
11280 @end deftypevr
11281
11282 @deftypevr {Help Output} offset long-opt-col
11283 Column in which long options start. Default is 6. For example:
11284
11285 @smallexample
11286 @group
11287 $ @kbd{tar --help|grep ARCHIVE}
11288 -f, --file=ARCHIVE use archive file or device ARCHIVE
11289 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
11290 -f, --file=ARCHIVE use archive file or device ARCHIVE
11291 @end group
11292 @end smallexample
11293 @end deftypevr
11294
11295 @deftypevr {Help Output} offset doc-opt-col
11296 Column in which @dfn{doc options} start. A doc option isn't actually
11297 an option, but rather an arbitrary piece of documentation that is
11298 displayed in much the same manner as the options. For example, in
11299 the description of @option{--format} option:
11300
11301 @smallexample
11302 @group
11303 -H, --format=FORMAT create archive of the given format.
11304
11305 FORMAT is one of the following:
11306
11307 gnu GNU tar 1.13.x format
11308 oldgnu GNU format as per tar <= 1.12
11309 pax POSIX 1003.1-2001 (pax) format
11310 posix same as pax
11311 ustar POSIX 1003.1-1988 (ustar) format
11312 v7 old V7 tar format
11313 @end group
11314 @end smallexample
11315
11316 @noindent
11317 the format names are doc options. Thus, if you set
11318 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
11319 will look as follows:
11320
11321 @smallexample
11322 @group
11323 -H, --format=FORMAT create archive of the given format.
11324
11325 FORMAT is one of the following:
11326
11327 gnu GNU tar 1.13.x format
11328 oldgnu GNU format as per tar <= 1.12
11329 pax POSIX 1003.1-2001 (pax) format
11330 posix same as pax
11331 ustar POSIX 1003.1-1988 (ustar) format
11332 v7 old V7 tar format
11333 @end group
11334 @end smallexample
11335 @end deftypevr
11336
11337 @deftypevr {Help Output} offset opt-doc-col
11338 Column in which option description starts. Default is 29.
11339
11340 @smallexample
11341 @group
11342 $ @kbd{tar --help|grep ARCHIVE}
11343 -f, --file=ARCHIVE use archive file or device ARCHIVE
11344 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
11345 -f, --file=ARCHIVE use archive file or device ARCHIVE
11346 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
11347 -f, --file=ARCHIVE
11348 use archive file or device ARCHIVE
11349 @end group
11350 @end smallexample
11351
11352 @noindent
11353 Notice, that the description starts on a separate line if
11354 @code{opt-doc-col} value is too small.
11355 @end deftypevr
11356
11357 @deftypevr {Help Output} offset header-col
11358 Column in which @dfn{group headers} are printed. A group header is a
11359 descriptive text preceding an option group. For example, in the
11360 following text:
11361
11362 @verbatim
11363 Main operation mode:
11364
11365 -A, --catenate, --concatenate append tar files to
11366 an archive
11367 -c, --create create a new archive
11368 @end verbatim
11369 @noindent
11370 @samp{Main operation mode:} is the group header.
11371
11372 The default value is 1.
11373 @end deftypevr
11374
11375 @deftypevr {Help Output} offset usage-indent
11376 Indentation of wrapped usage lines. Affects @option{--usage}
11377 output. Default is 12.
11378 @end deftypevr
11379
11380 @deftypevr {Help Output} offset rmargin
11381 Right margin of the text output. Used for wrapping.
11382 @end deftypevr
11383
11384 @node Fixing Snapshot Files
11385 @appendix Fixing Snapshot Files
11386 @include tar-snapshot-edit.texi
11387
11388 @node Tar Internals
11389 @appendix Tar Internals
11390 @include intern.texi
11391
11392 @node Genfile
11393 @appendix Genfile
11394 @include genfile.texi
11395
11396 @node Free Software Needs Free Documentation
11397 @appendix Free Software Needs Free Documentation
11398 @include freemanuals.texi
11399
11400 @node Copying This Manual
11401 @appendix Copying This Manual
11402
11403 @menu
11404 * GNU Free Documentation License:: License for copying this manual
11405 @end menu
11406
11407 @include fdl.texi
11408
11409 @node Index of Command Line Options
11410 @appendix Index of Command Line Options
11411
11412 This appendix contains an index of all @GNUTAR{} long command line
11413 options. The options are listed without the preceding double-dash.
11414 For a cross-reference of short command line options, @ref{Short Option Summary}.
11415
11416 @printindex op
11417
11418 @node Index
11419 @appendix Index
11420
11421 @printindex cp
11422
11423 @summarycontents
11424 @contents
11425 @bye
11426
11427 @c Local variables:
11428 @c texinfo-column-for-description: 32
11429 @c End:
This page took 0.497027 seconds and 5 git commands to generate.