]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Update documentation of --exclude-tag
[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 Free Software Foundation, Inc.
39
40 @quotation
41 Permission is granted to copy, distribute and/or modify this document
42 under the terms of the GNU Free Documentation License, Version 1.1 or
43 any later version published by the Free Software Foundation; with no
44 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
45 and with the Back-Cover Texts as in (a) below. A copy of the license
46 is included in the section entitled "GNU Free Documentation License".
47
48 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
49 this GNU Manual. Buying copies from GNU Press supports the FSF in
50 developing GNU and promoting software freedom.''
51 @end quotation
52 @end copying
53
54 @dircategory Archiving
55 @direntry
56 * Tar: (tar). Making tape (or disk) archives.
57 @end direntry
58
59 @dircategory Individual utilities
60 @direntry
61 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
62 @end direntry
63
64 @shorttitlepage @acronym{GNU} @command{tar}
65
66 @titlepage
67 @title @acronym{GNU} tar: an archiver tool
68 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
69 @author John Gilmore, Jay Fenlason et al.
70
71 @page
72 @vskip 0pt plus 1filll
73 @insertcopying
74 @end titlepage
75
76 @ifnottex
77 @node Top
78 @top @acronym{GNU} tar: an archiver tool
79
80 @insertcopying
81
82 @cindex file archival
83 @cindex archiving files
84
85 The first part of this master menu lists the major nodes in this Info
86 document. The rest of the menu lists all the lower level nodes.
87 @end ifnottex
88
89 @c The master menu goes here.
90 @c
91 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
92 @c loaded and run texinfo-master-menu.
93 @c To update it from the command line, run
94 @c
95 @c make master-menu
96
97 @menu
98 * Introduction::
99 * Tutorial::
100 * tar invocation::
101 * operations::
102 * Backups::
103 * Choosing::
104 * Date input formats::
105 * Formats::
106 * Media::
107
108 Appendices
109
110 * Changes::
111 * Configuring Help Summary::
112 * Tar Internals::
113 * Genfile::
114 * Free Software Needs Free Documentation::
115 * Copying This Manual::
116 * Index of Command Line Options::
117 * Index::
118
119 @detailmenu
120 --- The Detailed Node Listing ---
121
122 Introduction
123
124 * Book Contents:: What this Book Contains
125 * Definitions:: Some Definitions
126 * What tar Does:: What @command{tar} Does
127 * Naming tar Archives:: How @command{tar} Archives are Named
128 * Authors:: @GNUTAR{} Authors
129 * Reports:: Reporting bugs or suggestions
130
131 Tutorial Introduction to @command{tar}
132
133 * assumptions::
134 * stylistic conventions::
135 * basic tar options:: Basic @command{tar} Operations and Options
136 * frequent operations::
137 * Two Frequent Options::
138 * create:: How to Create Archives
139 * list:: How to List Archives
140 * extract:: How to Extract Members from an Archive
141 * going further::
142
143 Two Frequently Used Options
144
145 * file tutorial::
146 * verbose tutorial::
147 * help tutorial::
148
149 How to Create Archives
150
151 * prepare for examples::
152 * Creating the archive::
153 * create verbose::
154 * short create::
155 * create dir::
156
157 How to List Archives
158
159 * list dir::
160
161 How to Extract Members from an Archive
162
163 * extracting archives::
164 * extracting files::
165 * extract dir::
166 * extracting untrusted archives::
167 * failing commands::
168
169 Invoking @GNUTAR{}
170
171 * Synopsis::
172 * using tar options::
173 * Styles::
174 * All Options::
175 * help::
176 * defaults::
177 * verbose::
178 * interactive::
179
180 The Three Option Styles
181
182 * Long Options:: Long Option Style
183 * Short Options:: Short Option Style
184 * Old Options:: Old Option Style
185 * Mixing:: Mixing Option Styles
186
187 All @command{tar} Options
188
189 * Operation Summary::
190 * Option Summary::
191 * Short Option Summary::
192
193 @GNUTAR{} Operations
194
195 * Basic tar::
196 * Advanced tar::
197 * create options::
198 * extract options::
199 * backup::
200 * Applications::
201 * looking ahead::
202
203 Advanced @GNUTAR{} Operations
204
205 * Operations::
206 * append::
207 * update::
208 * concatenate::
209 * delete::
210 * compare::
211
212 How to Add Files to Existing Archives: @option{--append}
213
214 * appending files:: Appending Files to an Archive
215 * multiple::
216
217 Updating an Archive
218
219 * how to update::
220
221 Options Used by @option{--create}
222
223 * override:: Overriding File Metadata.
224 * Ignore Failed Read::
225
226 Options Used by @option{--extract}
227
228 * Reading:: Options to Help Read Archives
229 * Writing:: Changing How @command{tar} Writes Files
230 * Scarce:: Coping with Scarce Resources
231
232 Options to Help Read Archives
233
234 * read full records::
235 * Ignore Zeros::
236
237 Changing How @command{tar} Writes Files
238
239 * Dealing with Old Files::
240 * Overwrite Old Files::
241 * Keep Old Files::
242 * Keep Newer Files::
243 * Unlink First::
244 * Recursive Unlink::
245 * Data Modification Times::
246 * Setting Access Permissions::
247 * Directory Modification Times and Permissions::
248 * Writing to Standard Output::
249 * Writing to an External Program::
250 * remove files::
251
252 Coping with Scarce Resources
253
254 * Starting File::
255 * Same Order::
256
257 Performing Backups and Restoring Files
258
259 * Full Dumps:: Using @command{tar} to Perform Full Dumps
260 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
261 * Backup Levels:: Levels of Backups
262 * Backup Parameters:: Setting Parameters for Backups and Restoration
263 * Scripted Backups:: Using the Backup Scripts
264 * Scripted Restoration:: Using the Restore Script
265
266 Setting Parameters for Backups and Restoration
267
268 * General-Purpose Variables::
269 * Magnetic Tape Control::
270 * User Hooks::
271 * backup-specs example:: An Example Text of @file{Backup-specs}
272
273 Choosing Files and Names for @command{tar}
274
275 * file:: Choosing the Archive's Name
276 * Selecting Archive Members::
277 * files:: Reading Names from a File
278 * exclude:: Excluding Some Files
279 * wildcards:: Wildcards Patterns and Matching
280 * quoting styles:: Ways of Quoting Special Characters in Names
281 * transform:: Modifying File and Member Names
282 * after:: Operating Only on New Files
283 * recurse:: Descending into Directories
284 * one:: Crossing File System Boundaries
285
286 Reading Names from a File
287
288 * nul::
289
290 Excluding Some Files
291
292 * problems with exclude::
293
294 Wildcards Patterns and Matching
295
296 * controlling pattern-matching::
297
298 Crossing File System Boundaries
299
300 * directory:: Changing Directory
301 * absolute:: Absolute File Names
302
303 Date input formats
304
305 * General date syntax:: Common rules.
306 * Calendar date items:: 19 Dec 1994.
307 * Time of day items:: 9:20pm.
308 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
309 * Day of week items:: Monday and others.
310 * Relative items in date strings:: next tuesday, 2 years ago.
311 * Pure numbers in date strings:: 19931219, 1440.
312 * Seconds since the Epoch:: @@1078100502.
313 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
314 * Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al.
315
316 Controlling the Archive Format
317
318 * Portability:: Making @command{tar} Archives More Portable
319 * Compression:: Using Less Space through Compression
320 * Attributes:: Handling File Attributes
321 * cpio:: Comparison of @command{tar} and @command{cpio}
322
323 Making @command{tar} Archives More Portable
324
325 * Portable Names:: Portable Names
326 * dereference:: Symbolic Links
327 * old:: Old V7 Archives
328 * ustar:: Ustar Archives
329 * gnu:: GNU and old GNU format archives.
330 * posix:: @acronym{POSIX} archives
331 * Checksumming:: Checksumming Problems
332 * Large or Negative Values:: Large files, negative time stamps, etc.
333 * Other Tars:: How to Extract GNU-Specific Data Using
334 Other @command{tar} Implementations
335
336 @GNUTAR{} and @acronym{POSIX} @command{tar}
337
338 * PAX keywords:: Controlling Extended Header Keywords.
339
340 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
341
342 * Split Recovery:: Members Split Between Volumes
343 * Sparse Recovery:: Sparse Members
344
345 Using Less Space through Compression
346
347 * gzip:: Creating and Reading Compressed Archives
348 * sparse:: Archiving Sparse Files
349
350 Tapes and Other Archive Media
351
352 * Device:: Device selection and switching
353 * Remote Tape Server::
354 * Common Problems and Solutions::
355 * Blocking:: Blocking
356 * Many:: Many archives on one tape
357 * Using Multiple Tapes:: Using Multiple Tapes
358 * label:: Including a Label in the Archive
359 * verify::
360 * Write Protection::
361
362 Blocking
363
364 * Format Variations:: Format Variations
365 * Blocking Factor:: The Blocking Factor of an Archive
366
367 Many Archives on One Tape
368
369 * Tape Positioning:: Tape Positions and Tape Marks
370 * mt:: The @command{mt} Utility
371
372 Using Multiple Tapes
373
374 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
375 * Tape Files:: Tape Files
376 * Tarcat:: Concatenate Volumes into a Single Archive
377
378
379 Tar Internals
380
381 * Standard:: Basic Tar Format
382 * Extensions:: @acronym{GNU} Extensions to the Archive Format
383 * Sparse Formats:: Storing Sparse Files
384 * Snapshot Files::
385 * Dumpdir::
386
387 Storing Sparse Files
388
389 * Old GNU Format::
390 * PAX 0:: PAX Format, Versions 0.0 and 0.1
391 * PAX 1:: PAX Format, Version 1.0
392
393 Genfile
394
395 * Generate Mode:: File Generation Mode.
396 * Status Mode:: File Status Mode.
397 * Exec Mode:: Synchronous Execution mode.
398
399 Copying This Manual
400
401 * GNU Free Documentation License:: License for copying this manual
402
403 @end detailmenu
404 @end menu
405
406 @node Introduction
407 @chapter Introduction
408
409 @GNUTAR{} creates
410 and manipulates @dfn{archives} which are actually collections of
411 many other files; the program provides users with an organized and
412 systematic method for controlling a large amount of data.
413 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
414 archives need not (and these days, typically do not) reside on tapes.
415
416 @menu
417 * Book Contents:: What this Book Contains
418 * Definitions:: Some Definitions
419 * What tar Does:: What @command{tar} Does
420 * Naming tar Archives:: How @command{tar} Archives are Named
421 * Authors:: @GNUTAR{} Authors
422 * Reports:: Reporting bugs or suggestions
423 @end menu
424
425 @node Book Contents
426 @section What this Book Contains
427
428 The first part of this chapter introduces you to various terms that will
429 recur throughout the book. It also tells you who has worked on @GNUTAR{}
430 and its documentation, and where you should send bug reports
431 or comments.
432
433 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
434 gentle introduction for people who are new to using @command{tar}. It is
435 meant to be self contained, not requiring any reading from subsequent
436 chapters to make sense. It moves from topic to topic in a logical,
437 progressive order, building on information already explained.
438
439 Although the tutorial is paced and structured to allow beginners to
440 learn how to use @command{tar}, it is not intended solely for beginners.
441 The tutorial explains how to use the three most frequently used
442 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
443 two frequently used options (@samp{file} and @samp{verbose}). The other
444 chapters do not refer to the tutorial frequently; however, if a section
445 discusses something which is a complex variant of a basic concept, there
446 may be a cross reference to that basic concept. (The entire book,
447 including the tutorial, assumes that the reader understands some basic
448 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
449
450 The third chapter presents the remaining five operations, and
451 information about using @command{tar} options and option syntax.
452
453 @FIXME{this sounds more like a @acronym{GNU} Project Manuals Concept [tm] more
454 than the reality. should think about whether this makes sense to say
455 here, or not.} The other chapters are meant to be used as a
456 reference. Each chapter presents everything that needs to be said
457 about a specific topic.
458
459 One of the chapters (@pxref{Date input formats}) exists in its
460 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
461 In addition, one section of this manual (@pxref{Standard}) contains a
462 big quote which is taken directly from @command{tar} sources.
463
464 In general, we give both long and short (abbreviated) option names
465 at least once in each section where the relevant option is covered, so
466 that novice readers will become familiar with both styles. (A few
467 options have no short versions, and the relevant sections will
468 indicate this.)
469
470 @node Definitions
471 @section Some Definitions
472
473 @cindex archive
474 @cindex tar archive
475 The @command{tar} program is used to create and manipulate @command{tar}
476 archives. An @dfn{archive} is a single file which contains the contents
477 of many files, while still identifying the names of the files, their
478 owner(s), and so forth. (In addition, archives record access
479 permissions, user and group, size in bytes, and data modification time.
480 Some archives also record the file names in each archived directory, as
481 well as other file and directory information.) You can use @command{tar}
482 to @dfn{create} a new archive in a specified directory.
483
484 @cindex member
485 @cindex archive member
486 @cindex file name
487 @cindex member name
488 The files inside an archive are called @dfn{members}. Within this
489 manual, we use the term @dfn{file} to refer only to files accessible in
490 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
491 @dfn{member} to refer only to the members of an archive. Similarly, a
492 @dfn{file name} is the name of a file, as it resides in the file system,
493 and a @dfn{member name} is the name of an archive member within the
494 archive.
495
496 @cindex extraction
497 @cindex unpacking
498 The term @dfn{extraction} refers to the process of copying an archive
499 member (or multiple members) into a file in the file system. Extracting
500 all the members of an archive is often called @dfn{extracting the
501 archive}. The term @dfn{unpack} can also be used to refer to the
502 extraction of many or all the members of an archive. Extracting an
503 archive does not destroy the archive's structure, just as creating an
504 archive does not destroy the copies of the files that exist outside of
505 the archive. You may also @dfn{list} the members in a given archive
506 (this is often thought of as ``printing'' them to the standard output,
507 or the command line), or @dfn{append} members to a pre-existing archive.
508 All of these operations can be performed using @command{tar}.
509
510 @node What tar Does
511 @section What @command{tar} Does
512
513 @cindex tar
514 The @command{tar} program provides the ability to create @command{tar}
515 archives, as well as various other kinds of manipulation. For example,
516 you can use @command{tar} on previously created archives to extract files,
517 to store additional files, or to update or list files which were already
518 stored.
519
520 Initially, @command{tar} archives were used to store files conveniently on
521 magnetic tape. The name @command{tar} comes from this use; it stands for
522 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
523 direct its output to available devices, files, or other programs (using
524 pipes). @command{tar} may even access remote devices or files (as archives).
525
526 You can use @command{tar} archives in many ways. We want to stress a few
527 of them: storage, backup, and transportation.
528
529 @FIXME{the following table entries need a bit of work.}
530 @table @asis
531 @item Storage
532 Often, @command{tar} archives are used to store related files for
533 convenient file transfer over a network. For example, the
534 @acronym{GNU} Project distributes its software bundled into
535 @command{tar} archives, so that all the files relating to a particular
536 program (or set of related programs) can be transferred as a single
537 unit.
538
539 A magnetic tape can store several files in sequence. However, the tape
540 has no names for these files; it only knows their relative position on
541 the tape. One way to store several files on one tape and retain their
542 names is by creating a @command{tar} archive. Even when the basic transfer
543 mechanism can keep track of names, as FTP can, the nuisance of handling
544 multiple files, directories, and multiple links makes @command{tar}
545 archives useful.
546
547 Archive files are also used for long-term storage. You can think of
548 this as transportation from the present into the future. (It is a
549 science-fiction idiom that you can move through time as well as in
550 space; the idea here is that @command{tar} can be used to move archives in
551 all dimensions, even time!)
552
553 @item Backup
554 Because the archive created by @command{tar} is capable of preserving
555 file information and directory structure, @command{tar} is commonly
556 used for performing full and incremental backups of disks. A backup
557 puts a collection of files (possibly pertaining to many users and
558 projects) together on a disk or a tape. This guards against
559 accidental destruction of the information in those files.
560 @GNUTAR{} has special features that allow it to be
561 used to make incremental and full dumps of all the files in a
562 file system.
563
564 @item Transportation
565 You can create an archive on one system, transfer it to another system,
566 and extract the contents there. This allows you to transport a group of
567 files from one system to another.
568 @end table
569
570 @node Naming tar Archives
571 @section How @command{tar} Archives are Named
572
573 Conventionally, @command{tar} archives are given names ending with
574 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
575 but this manual follows that convention in order to accustom readers to
576 it and to make examples more clear.
577
578 @cindex tar file
579 @cindex entry
580 @cindex tar entry
581 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
582 archive members as ``files'' or ``entries''. For people familiar with
583 the operation of @command{tar}, this causes no difficulty. However, in
584 this manual, we consistently refer to ``archives'' and ``archive
585 members'' to make learning to use @command{tar} easier for novice users.
586
587 @node Authors
588 @section @GNUTAR{} Authors
589
590 @GNUTAR{} was originally written by John Gilmore,
591 and modified by many people. The @acronym{GNU} enhancements were
592 written by Jay Fenlason, then Joy Kendall, and the whole package has
593 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
594 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
595 numerous and kind users.
596
597 We wish to stress that @command{tar} is a collective work, and owes much to
598 all those people who reported problems, offered solutions and other
599 insights, or shared their thoughts and suggestions. An impressive, yet
600 partial list of those contributors can be found in the @file{THANKS}
601 file from the @GNUTAR{} distribution.
602
603 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
604 sure i want to spell out the history in this detail, at least not for
605 the printed book. i'm just not sure it needs to be said this way.
606 i'll think about it.}
607
608 @FIXME{History is more important, and surely more interesting, than
609 actual names. Quoting names without history would be meaningless. FP}
610
611 Jay Fenlason put together a draft of a @GNUTAR{}
612 manual, borrowing notes from the original man page from John Gilmore.
613 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
614 Gorin worked on a tutorial and manual for @GNUTAR{}.
615 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
616 taking information from all these sources and merging them. Melissa
617 Weisshaus finally edited and redesigned the book to create version
618 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
619 by the current maintainer, Sergey Poznyakoff.
620
621 For version 1.12, Daniel Hagerty contributed a great deal of technical
622 consulting. In particular, he is the primary author of @ref{Backups}.
623
624 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
625 (see @url{http://savannah.gnu.org/projects/tar}), and
626 active development and maintenance work has started
627 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
628 Poznyakoff and Jeff Bailey.
629
630 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
631
632 @node Reports
633 @section Reporting bugs or suggestions
634
635 @cindex bug reports
636 @cindex reporting bugs
637 If you find problems or have suggestions about this program or manual,
638 please report them to @file{bug-tar@@gnu.org}.
639
640 When reporting a bug, please be sure to include as much detail as
641 possible, in order to reproduce it. @FIXME{Be more specific, I'd
642 like to make this node as detailed as 'Bug reporting' node in Emacs
643 manual}.
644
645 @node Tutorial
646 @chapter Tutorial Introduction to @command{tar}
647
648 This chapter guides you through some basic examples of three @command{tar}
649 operations: @option{--create}, @option{--list}, and @option{--extract}. If
650 you already know how to use some other version of @command{tar}, then you
651 may not need to read this chapter. This chapter omits most complicated
652 details about how @command{tar} works.
653
654 @menu
655 * assumptions::
656 * stylistic conventions::
657 * basic tar options:: Basic @command{tar} Operations and Options
658 * frequent operations::
659 * Two Frequent Options::
660 * create:: How to Create Archives
661 * list:: How to List Archives
662 * extract:: How to Extract Members from an Archive
663 * going further::
664 @end menu
665
666 @node assumptions
667 @section Assumptions this Tutorial Makes
668
669 This chapter is paced to allow beginners to learn about @command{tar}
670 slowly. At the same time, we will try to cover all the basic aspects of
671 these three operations. In order to accomplish both of these tasks, we
672 have made certain assumptions about your knowledge before reading this
673 manual, and the hardware you will be using:
674
675 @itemize @bullet
676 @item
677 Before you start to work through this tutorial, you should understand
678 what the terms ``archive'' and ``archive member'' mean
679 (@pxref{Definitions}). In addition, you should understand something
680 about how Unix-type operating systems work, and you should know how to
681 use some basic utilities. For example, you should know how to create,
682 list, copy, rename, edit, and delete files and directories; how to
683 change between directories; and how to figure out where you are in the
684 file system. You should have some basic understanding of directory
685 structure and how files are named according to which directory they are
686 in. You should understand concepts such as standard output and standard
687 input, what various definitions of the term ``argument'' mean, and the
688 differences between relative and absolute path names. @FIXME{and what
689 else?}
690
691 @item
692 This manual assumes that you are working from your own home directory
693 (unless we state otherwise). In this tutorial, you will create a
694 directory to practice @command{tar} commands in. When we show path names,
695 we will assume that those paths are relative to your home directory.
696 For example, my home directory path is @file{/home/fsf/melissa}. All of
697 my examples are in a subdirectory of the directory named by that path
698 name; the subdirectory is called @file{practice}.
699
700 @item
701 In general, we show examples of archives which exist on (or can be
702 written to, or worked with from) a directory on a hard disk. In most
703 cases, you could write those archives to, or work with them on any other
704 device, such as a tape drive. However, some of the later examples in
705 the tutorial and next chapter will not work on tape drives.
706 Additionally, working with tapes is much more complicated than working
707 with hard disks. For these reasons, the tutorial does not cover working
708 with tape drives. @xref{Media}, for complete information on using
709 @command{tar} archives with tape drives.
710
711 @FIXME{this is a cop out. need to add some simple tape drive info.}
712 @end itemize
713
714 @node stylistic conventions
715 @section Stylistic Conventions
716
717 In the examples, @samp{$} represents a typical shell prompt. It
718 precedes lines you should type; to make this more clear, those lines are
719 shown in @kbd{this font}, as opposed to lines which represent the
720 computer's response; those lines are shown in @code{this font}, or
721 sometimes @samp{like this}.
722
723 @c When we have lines which are too long to be
724 @c displayed in any other way, we will show them like this:
725
726 @node basic tar options
727 @section Basic @command{tar} Operations and Options
728
729 @command{tar} can take a wide variety of arguments which specify and define
730 the actions it will have on the particular set of files or the archive.
731 The main types of arguments to @command{tar} fall into one of two classes:
732 operations, and options.
733
734 Some arguments fall into a class called @dfn{operations}; exactly one of
735 these is both allowed and required for any instance of using @command{tar};
736 you may @emph{not} specify more than one. People sometimes speak of
737 @dfn{operating modes}. You are in a particular operating mode when you
738 have specified the operation which specifies it; there are eight
739 operations in total, and thus there are eight operating modes.
740
741 The other arguments fall into the class known as @dfn{options}. You are
742 not required to specify any options, and you are allowed to specify more
743 than one at a time (depending on the way you are using @command{tar} at
744 that time). Some options are used so frequently, and are so useful for
745 helping you type commands more carefully that they are effectively
746 ``required''. We will discuss them in this chapter.
747
748 You can write most of the @command{tar} operations and options in any
749 of three forms: long (mnemonic) form, short form, and old style. Some
750 of the operations and options have no short or ``old'' forms; however,
751 the operations and options which we will cover in this tutorial have
752 corresponding abbreviations. @FIXME{make sure this is still the case,
753 at the end}We will indicate those abbreviations appropriately to get
754 you used to seeing them. (Note that the ``old style'' option forms
755 exist in @GNUTAR{} for compatibility with Unix
756 @command{tar}. In this book we present a full discussion of this way
757 of writing options and operations (@pxref{Old Options}), and we discuss
758 the other two styles of writing options (@xref{Long Options}, and
759 @pxref{Short Options}).
760
761 In the examples and in the text of this tutorial, we usually use the
762 long forms of operations and options; but the ``short'' forms produce
763 the same result and can make typing long @command{tar} commands easier.
764 For example, instead of typing
765
766 @smallexample
767 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
768 @end smallexample
769
770 @noindent
771 you can type
772 @smallexample
773 @kbd{tar -c -v -f afiles.tar apple angst aspic}
774 @end smallexample
775
776 @noindent
777 or even
778 @smallexample
779 @kbd{tar -cvf afiles.tar apple angst aspic}
780 @end smallexample
781
782 @noindent
783 For more information on option syntax, see @ref{Advanced tar}. In
784 discussions in the text, when we name an option by its long form, we
785 also give the corresponding short option in parentheses.
786
787 The term, ``option'', can be confusing at times, since ``operations''
788 are often lumped in with the actual, @emph{optional} ``options'' in certain
789 general class statements. For example, we just talked about ``short and
790 long forms of options and operations''. However, experienced @command{tar}
791 users often refer to these by shorthand terms such as, ``short and long
792 options''. This term assumes that the ``operations'' are included, also.
793 Context will help you determine which definition of ``options'' to use.
794
795 Similarly, the term ``command'' can be confusing, as it is often used in
796 two different ways. People sometimes refer to @command{tar} ``commands''.
797 A @command{tar} @dfn{command} is the entire command line of user input
798 which tells @command{tar} what to do --- including the operation, options,
799 and any arguments (file names, pipes, other commands, etc.). However,
800 you will also sometimes hear the term ``the @command{tar} command''. When
801 the word ``command'' is used specifically like this, a person is usually
802 referring to the @command{tar} @emph{operation}, not the whole line.
803 Again, use context to figure out which of the meanings the speaker
804 intends.
805
806 @node frequent operations
807 @section The Three Most Frequently Used Operations
808
809 Here are the three most frequently used operations (both short and long
810 forms), as well as a brief description of their meanings. The rest of
811 this chapter will cover how to use these operations in detail. We will
812 present the rest of the operations in the next chapter.
813
814 @table @option
815 @item --create
816 @itemx -c
817 Create a new @command{tar} archive.
818 @item --list
819 @itemx -t
820 List the contents of an archive.
821 @item --extract
822 @itemx -x
823 Extract one or more members from an archive.
824 @end table
825
826 @node Two Frequent Options
827 @section Two Frequently Used Options
828
829 To understand how to run @command{tar} in the three operating modes listed
830 previously, you also need to understand how to use two of the options to
831 @command{tar}: @option{--file} (which takes an archive file as an argument)
832 and @option{--verbose}. (You are usually not @emph{required} to specify
833 either of these options when you run @command{tar}, but they can be very
834 useful in making things more clear and helping you avoid errors.)
835
836 @menu
837 * file tutorial::
838 * verbose tutorial::
839 * help tutorial::
840 @end menu
841
842 @node file tutorial
843 @unnumberedsubsec The @option{--file} Option
844
845 @table @option
846 @xopindex{file, tutorial}
847 @item --file=@var{archive-name}
848 @itemx -f @var{archive-name}
849 Specify the name of an archive file.
850 @end table
851
852 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
853 use @command{tar}; this option determines the name of the archive file
854 that @command{tar} will work on.
855
856 @vrindex TAPE
857 If you don't specify this argument, then @command{tar} will examine
858 the environment variable @env{TAPE}. If it is set, its value will be
859 used as the archive name. Otherwise, @command{tar} will use the
860 default archive, determined at the compile time. Usually it is
861 standard output or some physical tape drive attached to your machine
862 (you can verify what the default is by running @kbd{tar
863 --show-defaults}, @pxref{defaults}). If there is no tape drive
864 attached, or the default is not meaningful, then @command{tar} will
865 print an error message. The error message might look roughly like one
866 of the following:
867
868 @smallexample
869 tar: can't open /dev/rmt8 : No such device or address
870 tar: can't open /dev/rsmt0 : I/O error
871 @end smallexample
872
873 @noindent
874 To avoid confusion, we recommend that you always specify an archive file
875 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
876 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
877 @ref{file}.
878
879 @node verbose tutorial
880 @unnumberedsubsec The @option{--verbose} Option
881
882 @table @option
883 @xopindex{verbose, introduced}
884 @item --verbose
885 @itemx -v
886 Show the files being worked on as @command{tar} is running.
887 @end table
888
889 @option{--verbose} (@option{-v}) shows details about the results of running
890 @command{tar}. This can be especially useful when the results might not be
891 obvious. For example, if you want to see the progress of @command{tar} as
892 it writes files into the archive, you can use the @option{--verbose}
893 option. In the beginning, you may find it useful to use
894 @option{--verbose} at all times; when you are more accustomed to
895 @command{tar}, you will likely want to use it at certain times but not at
896 others. We will use @option{--verbose} at times to help make something
897 clear, and we will give many examples both using and not using
898 @option{--verbose} to show the differences.
899
900 Each instance of @option{--verbose} on the command line increases the
901 verbosity level by one, so if you need more details on the output,
902 specify it twice.
903
904 When reading archives (@option{--list}, @option{--extract},
905 @option{--diff}), @command{tar} by default prints only the names of
906 the members being extracted. Using @option{--verbose} will show a full,
907 @command{ls} style member listing.
908
909 In contrast, when writing archives (@option{--create}, @option{--append},
910 @option{--update}), @command{tar} does not print file names by
911 default. So, a single @option{--verbose} option shows the file names
912 being added to the archive, while two @option{--verbose} options
913 enable the full listing.
914
915 For example, to create an archive in verbose mode:
916
917 @smallexample
918 $ @kbd{tar -cvf afiles.tar apple angst aspic}
919 apple
920 angst
921 aspic
922 @end smallexample
923
924 @noindent
925 Creating the same archive with the verbosity level 2 could give:
926
927 @smallexample
928 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
929 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
930 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
931 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
932 @end smallexample
933
934 @noindent
935 This works equally well using short or long forms of options. Using
936 long forms, you would simply write out the mnemonic form of the option
937 twice, like this:
938
939 @smallexample
940 $ @kbd{tar --create --verbose --verbose @dots{}}
941 @end smallexample
942
943 @noindent
944 Note that you must double the hyphens properly each time.
945
946 Later in the tutorial, we will give examples using @w{@option{--verbose
947 --verbose}}.
948
949 @anchor{verbose member listing}
950 The full output consists of six fields:
951
952 @itemize @bullet
953 @item File type and permissions in symbolic form.
954 These are displayed in the same format as the first column of
955 @command{ls -l} output (@pxref{What information is listed,
956 format=verbose, Verbose listing, fileutils, GNU file utilities}).
957
958 @item Owner name and group separated by a slash character.
959 If these data are not available (for example, when listing a @samp{v7} format
960 archive), numeric ID values are printed instead.
961
962 @item Size of the file, in bytes.
963
964 @item File modification date in ISO 8601 format.
965
966 @item File modification time.
967
968 @item File name.
969 If the name contains any special characters (white space, newlines,
970 etc.) these are displayed in an unambiguous form using so called
971 @dfn{quoting style}. For the detailed discussion of available styles
972 and on how to use them, see @ref{quoting styles}.
973
974 Depending on the file type, the name can be followed by some
975 additional information, described in the following table:
976
977 @table @samp
978 @item -> @var{link-name}
979 The file or archive member is a @dfn{symbolic link} and
980 @var{link-name} is the name of file it links to.
981
982 @item link to @var{link-name}
983 The file or archive member is a @dfn{hard link} and @var{link-name} is
984 the name of file it links to.
985
986 @item --Long Link--
987 The archive member is an old GNU format long link. You will normally
988 not encounter this.
989
990 @item --Long Name--
991 The archive member is an old GNU format long name. You will normally
992 not encounter this.
993
994 @item --Volume Header--
995 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
996
997 @item --Continued at byte @var{n}--
998 Encountered only at the beginning of a multi-volume archive
999 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1000 from the previous volume. The number @var{n} gives the offset where
1001 the original file was split.
1002
1003 @item unknown file type @var{c}
1004 An archive member of unknown type. @var{c} is the type character from
1005 the archive header. If you encounter such a message, it means that
1006 either your archive contains proprietary member types @GNUTAR{} is not
1007 able to handle, or the archive is corrupted.
1008 @end table
1009
1010 @end itemize
1011
1012 For example, here is an archive listing containing most of the special
1013 suffixes explained above:
1014
1015 @smallexample
1016 @group
1017 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1018 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1019 byte 32456--
1020 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1021 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1022 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1023 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1024 @end group
1025 @end smallexample
1026
1027 @smallexample
1028 @end smallexample
1029
1030 @node help tutorial
1031 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1032
1033 @table @option
1034 @opindex help
1035 @item --help
1036
1037 The @option{--help} option to @command{tar} prints out a very brief list of
1038 all operations and option available for the current version of
1039 @command{tar} available on your system.
1040 @end table
1041
1042 @node create
1043 @section How to Create Archives
1044 @UNREVISED
1045
1046 @cindex Creation of the archive
1047 @cindex Archive, creation of
1048 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1049 you use to create a @command{tar} archive. We will explain
1050 @option{--create} first because, in order to learn about the other
1051 operations, you will find it useful to have an archive available to
1052 practice on.
1053
1054 To make this easier, in this section you will first create a directory
1055 containing three files. Then, we will show you how to create an
1056 @emph{archive} (inside the new directory). Both the directory, and
1057 the archive are specifically for you to practice on. The rest of this
1058 chapter and the next chapter will show many examples using this
1059 directory and the files you will create: some of those files may be
1060 other directories and other archives.
1061
1062 The three files you will archive in this example are called
1063 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1064 @file{collection.tar}.
1065
1066 This section will proceed slowly, detailing how to use @option{--create}
1067 in @code{verbose} mode, and showing examples using both short and long
1068 forms. In the rest of the tutorial, and in the examples in the next
1069 chapter, we will proceed at a slightly quicker pace. This section
1070 moves more slowly to allow beginning users to understand how
1071 @command{tar} works.
1072
1073 @menu
1074 * prepare for examples::
1075 * Creating the archive::
1076 * create verbose::
1077 * short create::
1078 * create dir::
1079 @end menu
1080
1081 @node prepare for examples
1082 @subsection Preparing a Practice Directory for Examples
1083
1084 To follow along with this and future examples, create a new directory
1085 called @file{practice} containing files called @file{blues}, @file{folk}
1086 and @file{jazz}. The files can contain any information you like:
1087 ideally, they should contain information which relates to their names,
1088 and be of different lengths. Our examples assume that @file{practice}
1089 is a subdirectory of your home directory.
1090
1091 Now @command{cd} to the directory named @file{practice}; @file{practice}
1092 is now your @dfn{working directory}. (@emph{Please note}: Although
1093 the full path name of this directory is
1094 @file{/@var{homedir}/practice}, in our examples we will refer to
1095 this directory as @file{practice}; the @var{homedir} is presumed.
1096
1097 In general, you should check that the files to be archived exist where
1098 you think they do (in the working directory) by running @command{ls}.
1099 Because you just created the directory and the files and have changed to
1100 that directory, you probably don't need to do that this time.
1101
1102 It is very important to make sure there isn't already a file in the
1103 working directory with the archive name you intend to use (in this case,
1104 @samp{collection.tar}), or that you don't care about its contents.
1105 Whenever you use @samp{create}, @command{tar} will erase the current
1106 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1107 will not tell you if you are about to overwrite an archive unless you
1108 specify an option which does this (@pxref{backup}, for the
1109 information on how to do so). To add files to an existing archive,
1110 you need to use a different option, such as @option{--append} (@option{-r}); see
1111 @ref{append} for information on how to do this.
1112
1113 @node Creating the archive
1114 @subsection Creating the Archive
1115
1116 @xopindex{create, introduced}
1117 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1118 archive named @file{collection.tar}, use the following command:
1119
1120 @smallexample
1121 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1122 @end smallexample
1123
1124 The order of the arguments is not very important, @emph{when using long
1125 option forms}. You could also say:
1126
1127 @smallexample
1128 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1129 @end smallexample
1130
1131 @noindent
1132 However, you can see that this order is harder to understand; this is
1133 why we will list the arguments in the order that makes the commands
1134 easiest to understand (and we encourage you to do the same when you use
1135 @command{tar}, to avoid errors).
1136
1137 Note that the sequence
1138 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1139 If you substituted any other string of characters for
1140 @kbd{collection.tar}, then that string would become the name of the
1141 archive file you create.
1142
1143 The order of the options becomes more important when you begin to use
1144 short forms. With short forms, if you type commands in the wrong order
1145 (even if you type them correctly in all other ways), you may end up with
1146 results you don't expect. For this reason, it is a good idea to get
1147 into the habit of typing options in the order that makes inherent sense.
1148 @xref{short create}, for more information on this.
1149
1150 In this example, you type the command as shown above: @option{--create}
1151 is the operation which creates the new archive
1152 (@file{collection.tar}), and @option{--file} is the option which lets
1153 you give it the name you chose. The files, @file{blues}, @file{folk},
1154 and @file{jazz}, are now members of the archive, @file{collection.tar}
1155 (they are @dfn{file name arguments} to the @option{--create} operation.
1156 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1157 in the archive, they are called @emph{archive members}, not files.
1158 (@pxref{Definitions,members}).
1159
1160 When you create an archive, you @emph{must} specify which files you
1161 want placed in the archive. If you do not specify any archive
1162 members, @GNUTAR{} will complain.
1163
1164 If you now list the contents of the working directory (@command{ls}), you will
1165 find the archive file listed as well as the files you saw previously:
1166
1167 @smallexample
1168 blues folk jazz collection.tar
1169 @end smallexample
1170
1171 @noindent
1172 Creating the archive @samp{collection.tar} did not destroy the copies of
1173 the files in the directory.
1174
1175 Keep in mind that if you don't indicate an operation, @command{tar} will not
1176 run and will prompt you for one. If you don't name any files, @command{tar}
1177 will complain. You must have write access to the working directory,
1178 or else you will not be able to create an archive in that directory.
1179
1180 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1181 an existing archive; it will delete the archive and write a new one.
1182 Use @option{--append} (@option{-r}) instead. @xref{append}.
1183
1184 @node create verbose
1185 @subsection Running @option{--create} with @option{--verbose}
1186
1187 @xopindex{create, using with @option{--verbose}}
1188 @xopindex{verbose, using with @option{--create}}
1189 If you include the @option{--verbose} (@option{-v}) option on the command line,
1190 @command{tar} will list the files it is acting on as it is working. In
1191 verbose mode, the @code{create} example above would appear as:
1192
1193 @smallexample
1194 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1195 blues
1196 folk
1197 jazz
1198 @end smallexample
1199
1200 This example is just like the example we showed which did not use
1201 @option{--verbose}, except that @command{tar} generated the remaining lines
1202 @iftex
1203 (note the different font styles).
1204 @end iftex
1205 @ifinfo
1206 .
1207 @end ifinfo
1208
1209 In the rest of the examples in this chapter, we will frequently use
1210 @code{verbose} mode so we can show actions or @command{tar} responses that
1211 you would otherwise not see, and which are important for you to
1212 understand.
1213
1214 @node short create
1215 @subsection Short Forms with @samp{create}
1216
1217 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1218 basic uses of @command{tar}, and you will use it countless times.
1219 Eventually, you will probably want to use abbreviated (or ``short'')
1220 forms of options. A full discussion of the three different forms that
1221 options can take appears in @ref{Styles}; for now, here is what the
1222 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1223 using short option forms:
1224
1225 @smallexample
1226 $ @kbd{tar -cvf collection.tar blues folk jazz}
1227 blues
1228 folk
1229 jazz
1230 @end smallexample
1231
1232 @noindent
1233 As you can see, the system responds the same no matter whether you use
1234 long or short option forms.
1235
1236 @FIXME{i don't like how this is worded:} One difference between using
1237 short and long option forms is that, although the exact placement of
1238 arguments following options is no more specific when using short forms,
1239 it is easier to become confused and make a mistake when using short
1240 forms. For example, suppose you attempted the above example in the
1241 following way:
1242
1243 @smallexample
1244 $ @kbd{tar -cfv collection.tar blues folk jazz}
1245 @end smallexample
1246
1247 @noindent
1248 In this case, @command{tar} will make an archive file called @file{v},
1249 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1250 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1251 is thus taken to be the chosen archive file name. @command{tar} will try
1252 to add a file called @file{collection.tar} to the @file{v} archive file;
1253 if the file @file{collection.tar} did not already exist, @command{tar} will
1254 report an error indicating that this file does not exist. If the file
1255 @file{collection.tar} does already exist (e.g., from a previous command
1256 you may have run), then @command{tar} will add this file to the archive.
1257 Because the @option{-v} option did not get registered, @command{tar} will not
1258 run under @samp{verbose} mode, and will not report its progress.
1259
1260 The end result is that you may be quite confused about what happened,
1261 and possibly overwrite a file. To illustrate this further, we will show
1262 you how an example we showed previously would look using short forms.
1263
1264 This example,
1265
1266 @smallexample
1267 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1268 @end smallexample
1269
1270 @noindent
1271 is confusing as it is. When shown using short forms, however, it
1272 becomes much more so:
1273
1274 @smallexample
1275 $ @kbd{tar blues -c folk -f collection.tar jazz}
1276 @end smallexample
1277
1278 @noindent
1279 It would be very easy to put the wrong string of characters
1280 immediately following the @option{-f}, but doing that could sacrifice
1281 valuable data.
1282
1283 For this reason, we recommend that you pay very careful attention to
1284 the order of options and placement of file and archive names,
1285 especially when using short option forms. Not having the option name
1286 written out mnemonically can affect how well you remember which option
1287 does what, and therefore where different names have to be placed.
1288
1289 @node create dir
1290 @subsection Archiving Directories
1291
1292 @cindex Archiving Directories
1293 @cindex Directories, Archiving
1294 You can archive a directory by specifying its directory name as a
1295 file name argument to @command{tar}. The files in the directory will be
1296 archived relative to the working directory, and the directory will be
1297 re-created along with its contents when the archive is extracted.
1298
1299 To archive a directory, first move to its superior directory. If you
1300 have followed the previous instructions in this tutorial, you should
1301 type:
1302
1303 @smallexample
1304 $ @kbd{cd ..}
1305 $
1306 @end smallexample
1307
1308 @noindent
1309 This will put you into the directory which contains @file{practice},
1310 i.e., your home directory. Once in the superior directory, you can
1311 specify the subdirectory, @file{practice}, as a file name argument. To
1312 store @file{practice} in the new archive file @file{music.tar}, type:
1313
1314 @smallexample
1315 $ @kbd{tar --create --verbose --file=music.tar practice}
1316 @end smallexample
1317
1318 @noindent
1319 @command{tar} should output:
1320
1321 @smallexample
1322 practice/
1323 practice/blues
1324 practice/folk
1325 practice/jazz
1326 practice/collection.tar
1327 @end smallexample
1328
1329 Note that the archive thus created is not in the subdirectory
1330 @file{practice}, but rather in the current working directory---the
1331 directory from which @command{tar} was invoked. Before trying to archive a
1332 directory from its superior directory, you should make sure you have
1333 write access to the superior directory itself, not only the directory
1334 you are trying archive with @command{tar}. For example, you will probably
1335 not be able to store your home directory in an archive by invoking
1336 @command{tar} from the root directory; @xref{absolute}. (Note
1337 also that @file{collection.tar}, the original archive file, has itself
1338 been archived. @command{tar} will accept any file as a file to be
1339 archived, regardless of its content. When @file{music.tar} is
1340 extracted, the archive file @file{collection.tar} will be re-written
1341 into the file system).
1342
1343 If you give @command{tar} a command such as
1344
1345 @smallexample
1346 $ @kbd{tar --create --file=foo.tar .}
1347 @end smallexample
1348
1349 @noindent
1350 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1351 dumped}. This happens because @command{tar} creates the archive
1352 @file{foo.tar} in the current directory before putting any files into
1353 it. Then, when @command{tar} attempts to add all the files in the
1354 directory @file{.} to the archive, it notices that the file
1355 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1356 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1357 will continue in this case, and create the archive
1358 normally, except for the exclusion of that one file. (@emph{Please
1359 note:} Other implementations of @command{tar} may not be so clever;
1360 they will enter an infinite loop when this happens, so you should not
1361 depend on this behavior unless you are certain you are running
1362 @GNUTAR{}. In general, it is wise to always place the archive outside
1363 of the directory being dumped.
1364
1365 @node list
1366 @section How to List Archives
1367
1368 @opindex list
1369 Frequently, you will find yourself wanting to determine exactly what a
1370 particular archive contains. You can use the @option{--list}
1371 (@option{-t}) operation to get the member names as they currently
1372 appear in the archive, as well as various attributes of the files at
1373 the time they were archived. For example, you can examine the archive
1374 @file{collection.tar} that you created in the last section with the
1375 command,
1376
1377 @smallexample
1378 $ @kbd{tar --list --file=collection.tar}
1379 @end smallexample
1380
1381 @noindent
1382 The output of @command{tar} would then be:
1383
1384 @smallexample
1385 blues
1386 folk
1387 jazz
1388 @end smallexample
1389
1390 @noindent
1391 The archive @file{bfiles.tar} would list as follows:
1392
1393 @smallexample
1394 ./birds
1395 baboon
1396 ./box
1397 @end smallexample
1398
1399 @noindent
1400 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1401 @var{archive-name}}) option just as with @option{--create}
1402 (@option{-c}) to specify the name of the archive.
1403
1404 @xopindex{list, using with @option{--verbose}}
1405 @xopindex{verbose, using with @option{--list}}
1406 If you use the @option{--verbose} (@option{-v}) option with
1407 @option{--list}, then @command{tar} will print out a listing
1408 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1409 forth. This output is described in detail in @ref{verbose member listing}.
1410
1411 If you had used @option{--verbose} (@option{-v}) mode, the example
1412 above would look like:
1413
1414 @smallexample
1415 $ @kbd{tar --list --verbose --file=collection.tar folk}
1416 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1417 @end smallexample
1418
1419 @cindex listing member and file names
1420 @anchor{listing member and file names}
1421 It is important to notice that the output of @kbd{tar --list
1422 --verbose} does not necessarily match that produced by @kbd{tar
1423 --create --verbose} while creating the archive. It is because
1424 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1425 prefixes from file names before storing them in the archive
1426 (@xref{absolute}, for more information). In other
1427 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1428 an archive and @dfn{member names} when listing it. Consider this
1429 example:
1430
1431 @smallexample
1432 @group
1433 $ @kbd{tar cfv archive /etc/mail}
1434 tar: Removing leading `/' from member names
1435 /etc/mail/
1436 /etc/mail/sendmail.cf
1437 /etc/mail/aliases
1438 $ @kbd{tar tf archive}
1439 etc/mail/
1440 etc/mail/sendmail.cf
1441 etc/mail/aliases
1442 @end group
1443 @end smallexample
1444
1445 @opindex show-stored-names
1446 This default behavior can sometimes be inconvenient. You can force
1447 @GNUTAR{} show member names when creating archive by supplying
1448 @option{--show-stored-names} option.
1449
1450 @table @option
1451 @item --show-stored-names
1452 Print member (as opposed to @emph{file}) names when creating the archive.
1453 @end table
1454
1455 @cindex File name arguments, using @option{--list} with
1456 @xopindex{list, using with file name arguments}
1457 You can specify one or more individual member names as arguments when
1458 using @samp{list}. In this case, @command{tar} will only list the
1459 names of members you identify. For example, @w{@kbd{tar --list
1460 --file=afiles.tar apple}} would only print @file{apple}.
1461
1462 Because @command{tar} preserves paths, file names must be specified as
1463 they appear in the archive (i.e., relative to the directory from which
1464 the archive was created). Therefore, it is essential when specifying
1465 member names to @command{tar} that you give the exact member names.
1466 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1467 error message something like @samp{tar: birds: Not found in archive},
1468 because there is no member named @file{birds}, only one named
1469 @file{./birds}. While the names @file{birds} and @file{./birds} name
1470 the same file, @emph{member} names by default are compared verbatim.
1471
1472 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1473 with @file{baboon}, because this exact member name is in the archive file
1474 @file{bfiles.tar}. If you are not sure of the exact file name,
1475 use @dfn{globbing patterns}, for example:
1476
1477 @smallexample
1478 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1479 @end smallexample
1480
1481 @noindent
1482 will list all members whose name contains @samp{b}. @xref{wildcards},
1483 for a detailed discussion of globbing patterns and related
1484 @command{tar} command line options.
1485
1486 @menu
1487 * list dir::
1488 @end menu
1489
1490 @node list dir
1491 @unnumberedsubsec Listing the Contents of a Stored Directory
1492
1493 To get information about the contents of an archived directory,
1494 use the directory name as a file name argument in conjunction with
1495 @option{--list} (@option{-t}). To find out file attributes, include the
1496 @option{--verbose} (@option{-v}) option.
1497
1498 For example, to find out about files in the directory @file{practice}, in
1499 the archive file @file{music.tar}, type:
1500
1501 @smallexample
1502 $ @kbd{tar --list --verbose --file=music.tar practice}
1503 @end smallexample
1504
1505 @command{tar} responds:
1506
1507 @smallexample
1508 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1509 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1510 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1511 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1512 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1513 @end smallexample
1514
1515 When you use a directory name as a file name argument, @command{tar} acts on
1516 all the files (including sub-directories) in that directory.
1517
1518 @node extract
1519 @section How to Extract Members from an Archive
1520 @UNREVISED
1521 @cindex Extraction
1522 @cindex Retrieving files from an archive
1523 @cindex Resurrecting files from an archive
1524
1525 @opindex extract
1526 Creating an archive is only half the job---there is no point in storing
1527 files in an archive if you can't retrieve them. The act of retrieving
1528 members from an archive so they can be used and manipulated as
1529 unarchived files again is called @dfn{extraction}. To extract files
1530 from an archive, use the @option{--extract} (@option{--get} or
1531 @option{-x}) operation. As with @option{--create}, specify the name
1532 of the archive with @option{--file} (@option{-f}) option. Extracting
1533 an archive does not modify the archive in any way; you can extract it
1534 multiple times if you want or need to.
1535
1536 Using @option{--extract}, you can extract an entire archive, or specific
1537 files. The files can be directories containing other files, or not. As
1538 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1539 long form of the operation without affecting the performance.
1540
1541 @menu
1542 * extracting archives::
1543 * extracting files::
1544 * extract dir::
1545 * extracting untrusted archives::
1546 * failing commands::
1547 @end menu
1548
1549 @node extracting archives
1550 @subsection Extracting an Entire Archive
1551
1552 To extract an entire archive, specify the archive file name only, with
1553 no individual file names as arguments. For example,
1554
1555 @smallexample
1556 $ @kbd{tar -xvf collection.tar}
1557 @end smallexample
1558
1559 @noindent
1560 produces this:
1561
1562 @smallexample
1563 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1564 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1565 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1566 @end smallexample
1567
1568 @node extracting files
1569 @subsection Extracting Specific Files
1570
1571 To extract specific archive members, give their exact member names as
1572 arguments, as printed by @option{--list} (@option{-t}). If you had
1573 mistakenly deleted one of the files you had placed in the archive
1574 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1575 from the archive without changing the archive's structure. Its
1576 contents will be identical to the original file @file{blues} that you
1577 deleted.
1578
1579 First, make sure you are in the @file{practice} directory, and list the
1580 files in the directory. Now, delete the file, @samp{blues}, and list
1581 the files in the directory again.
1582
1583 You can now extract the member @file{blues} from the archive file
1584 @file{collection.tar} like this:
1585
1586 @smallexample
1587 $ @kbd{tar --extract --file=collection.tar blues}
1588 @end smallexample
1589
1590 @noindent
1591 If you list the files in the directory again, you will see that the file
1592 @file{blues} has been restored, with its original permissions, data
1593 modification times, and owner.@footnote{This is only accidentally
1594 true, but not in general. Whereas modification times are always
1595 restored, in most cases, one has to be root for restoring the owner,
1596 and use a special option for restoring permissions. Here, it just
1597 happens that the restoring user is also the owner of the archived
1598 members, and that the current @code{umask} is compatible with original
1599 permissions.} (These parameters will be identical to those which
1600 the file had when you originally placed it in the archive; any changes
1601 you may have made before deleting the file from the file system,
1602 however, will @emph{not} have been made to the archive member.) The
1603 archive file, @samp{collection.tar}, is the same as it was before you
1604 extracted @samp{blues}. You can confirm this by running @command{tar} with
1605 @option{--list} (@option{-t}).
1606
1607 Remember that as with other operations, specifying the exact member
1608 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1609 will fail, because there is no member named @file{birds}. To extract
1610 the member named @file{./birds}, you must specify @w{@kbd{tar
1611 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1612 exact member names, use @option{--list} (@option{-t}) option
1613 (@pxref{list}). You can also extract those members that match a
1614 specific @dfn{globbing pattern}. For example, to extract from
1615 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1616 directory prefix, you could type:
1617
1618 @smallexample
1619 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1620 @end smallexample
1621
1622 @noindent
1623 Here, @option{--wildcards} instructs @command{tar} to treat
1624 command line arguments as globbing patterns and @option{--no-anchored}
1625 informs it that the patterns apply to member names after any @samp{/}
1626 delimiter. The use of globbing patterns is discussed in detail in
1627 @xref{wildcards}.
1628
1629 You can extract a file to standard output by combining the above options
1630 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1631 Output}).
1632
1633 If you give the @option{--verbose} option, then @option{--extract}
1634 will print the names of the archive members as it extracts them.
1635
1636 @node extract dir
1637 @subsection Extracting Files that are Directories
1638
1639 Extracting directories which are members of an archive is similar to
1640 extracting other files. The main difference to be aware of is that if
1641 the extracted directory has the same name as any directory already in
1642 the working directory, then files in the extracted directory will be
1643 placed into the directory of the same name. Likewise, if there are
1644 files in the pre-existing directory with the same names as the members
1645 which you extract, the files from the extracted archive will replace
1646 the files already in the working directory (and possible
1647 subdirectories). This will happen regardless of whether or not the
1648 files in the working directory were more recent than those extracted
1649 (there exist, however, special options that alter this behavior
1650 @pxref{Writing}).
1651
1652 However, if a file was stored with a directory name as part of its file
1653 name, and that directory does not exist under the working directory when
1654 the file is extracted, @command{tar} will create the directory.
1655
1656 We can demonstrate how to use @option{--extract} to extract a directory
1657 file with an example. Change to the @file{practice} directory if you
1658 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1659 go back to the parent directory and extract the archive
1660 @file{music.tar}. You may either extract the entire archive, or you may
1661 extract only the files you just deleted. To extract the entire archive,
1662 don't give any file names as arguments after the archive name
1663 @file{music.tar}. To extract only the files you deleted, use the
1664 following command:
1665
1666 @smallexample
1667 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1668 practice/folk
1669 practice/jazz
1670 @end smallexample
1671
1672 @noindent
1673 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1674 would have displayed more detail about the extracted files, as shown
1675 in the example below:
1676
1677 @smallexample
1678 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1679 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1680 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1681 @end smallexample
1682
1683 @noindent
1684 Because you created the directory with @file{practice} as part of the
1685 file names of each of the files by archiving the @file{practice}
1686 directory as @file{practice}, you must give @file{practice} as part
1687 of the file names when you extract those files from the archive.
1688
1689 @node extracting untrusted archives
1690 @subsection Extracting Archives from Untrusted Sources
1691
1692 Extracting files from archives can overwrite files that already exist.
1693 If you receive an archive from an untrusted source, you should make a
1694 new directory and extract into that directory, so that you don't have
1695 to worry about the extraction overwriting one of your existing files.
1696 For example, if @file{untrusted.tar} came from somewhere else on the
1697 Internet, and you don't necessarily trust its contents, you can
1698 extract it as follows:
1699
1700 @smallexample
1701 $ @kbd{mkdir newdir}
1702 $ @kbd{cd newdir}
1703 $ @kbd{tar -xvf ../untrusted.tar}
1704 @end smallexample
1705
1706 It is also a good practice to examine contents of the archive
1707 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1708 with @option{--verbose} (@option{-v}).
1709
1710 @node failing commands
1711 @subsection Commands That Will Fail
1712
1713 Here are some sample commands you might try which will not work, and why
1714 they won't work.
1715
1716 If you try to use this command,
1717
1718 @smallexample
1719 $ @kbd{tar -xvf music.tar folk jazz}
1720 @end smallexample
1721
1722 @noindent
1723 you will get the following response:
1724
1725 @smallexample
1726 tar: folk: Not found in archive
1727 tar: jazz: Not found in archive
1728 $
1729 @end smallexample
1730
1731 @noindent
1732 This is because these files were not originally @emph{in} the parent
1733 directory @file{..}, where the archive is located; they were in the
1734 @file{practice} directory, and their file names reflect this:
1735
1736 @smallexample
1737 $ @kbd{tar -tvf music.tar}
1738 practice/folk
1739 practice/jazz
1740 practice/rock
1741 @end smallexample
1742
1743 @FIXME{make sure the above works when going through the examples in
1744 order...}
1745
1746 @noindent
1747 Likewise, if you try to use this command,
1748
1749 @smallexample
1750 $ @kbd{tar -tvf music.tar folk jazz}
1751 @end smallexample
1752
1753 @noindent
1754 you would get a similar response. Members with those names are not in the
1755 archive. You must use the correct member names, or wildcards, in order
1756 to extract the files from the archive.
1757
1758 If you have forgotten the correct names of the files in the archive,
1759 use @w{@kbd{tar --list --verbose}} to list them correctly.
1760
1761 @FIXME{more examples, here? hag thinks it's a good idea.}
1762
1763 @node going further
1764 @section Going Further Ahead in this Manual
1765
1766 @FIXME{need to write up a node here about the things that are going to
1767 be in the rest of the manual.}
1768
1769 @node tar invocation
1770 @chapter Invoking @GNUTAR{}
1771 @UNREVISED
1772
1773 This chapter is about how one invokes the @GNUTAR{}
1774 command, from the command synopsis (@pxref{Synopsis}). There are
1775 numerous options, and many styles for writing them. One mandatory
1776 option specifies the operation @command{tar} should perform
1777 (@pxref{Operation Summary}), other options are meant to detail how
1778 this operation should be performed (@pxref{Option Summary}).
1779 Non-option arguments are not always interpreted the same way,
1780 depending on what the operation is.
1781
1782 You will find in this chapter everything about option styles and rules for
1783 writing them (@pxref{Styles}). On the other hand, operations and options
1784 are fully described elsewhere, in other chapters. Here, you will find
1785 only synthetic descriptions for operations and options, together with
1786 pointers to other parts of the @command{tar} manual.
1787
1788 Some options are so special they are fully described right in this
1789 chapter. They have the effect of inhibiting the normal operation of
1790 @command{tar} or else, they globally alter the amount of feedback the user
1791 receives about what is going on. These are the @option{--help} and
1792 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1793 and @option{--interactive} options (@pxref{interactive}).
1794
1795 @menu
1796 * Synopsis::
1797 * using tar options::
1798 * Styles::
1799 * All Options::
1800 * help::
1801 * defaults::
1802 * verbose::
1803 * interactive::
1804 @end menu
1805
1806 @node Synopsis
1807 @section General Synopsis of @command{tar}
1808
1809 The @GNUTAR{} program is invoked as either one of:
1810
1811 @smallexample
1812 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1813 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1814 @end smallexample
1815
1816 The second form is for when old options are being used.
1817
1818 You can use @command{tar} to store files in an archive, to extract them from
1819 an archive, and to do other types of archive manipulation. The primary
1820 argument to @command{tar}, which is called the @dfn{operation}, specifies
1821 which action to take. The other arguments to @command{tar} are either
1822 @dfn{options}, which change the way @command{tar} performs an operation,
1823 or file names or archive members, which specify the files or members
1824 @command{tar} is to act on.
1825
1826 You can actually type in arguments in any order, even if in this manual
1827 the options always precede the other arguments, to make examples easier
1828 to understand. Further, the option stating the main operation mode
1829 (the @command{tar} main command) is usually given first.
1830
1831 Each @var{name} in the synopsis above is interpreted as an archive member
1832 name when the main command is one of @option{--compare}
1833 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1834 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1835 @option{--update} (@option{-u}). When naming archive members, you
1836 must give the exact name of the member in the archive, as it is
1837 printed by @option{--list}. For @option{--append} (@option{-r}) and
1838 @option{--create} (@option{-c}), these @var{name} arguments specify
1839 the names of either files or directory hierarchies to place in the archive.
1840 These files or hierarchies should already exist in the file system,
1841 prior to the execution of the @command{tar} command.
1842
1843 @command{tar} interprets relative file names as being relative to the
1844 working directory. @command{tar} will make all file names relative
1845 (by removing leading slashes when archiving or restoring files),
1846 unless you specify otherwise (using the @option{--absolute-names}
1847 option). @xref{absolute}, for more information about
1848 @option{--absolute-names}.
1849
1850 If you give the name of a directory as either a file name or a member
1851 name, then @command{tar} acts recursively on all the files and directories
1852 beneath that directory. For example, the name @file{/} identifies all
1853 the files in the file system to @command{tar}.
1854
1855 The distinction between file names and archive member names is especially
1856 important when shell globbing is used, and sometimes a source of confusion
1857 for newcomers. @xref{wildcards}, for more information about globbing.
1858 The problem is that shells may only glob using existing files in the
1859 file system. Only @command{tar} itself may glob on archive members, so when
1860 needed, you must ensure that wildcard characters reach @command{tar} without
1861 being interpreted by the shell first. Using a backslash before @samp{*}
1862 or @samp{?}, or putting the whole argument between quotes, is usually
1863 sufficient for this.
1864
1865 Even if @var{name}s are often specified on the command line, they
1866 can also be read from a text file in the file system, using the
1867 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1868
1869 If you don't use any file name arguments, @option{--append} (@option{-r}),
1870 @option{--delete} and @option{--concatenate} (@option{--catenate},
1871 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1872 will usually yield a diagnostic and inhibit @command{tar} execution.
1873 The other operations of @command{tar} (@option{--list},
1874 @option{--extract}, @option{--compare}, and @option{--update})
1875 will act on the entire contents of the archive.
1876
1877 @cindex exit status
1878 @cindex return status
1879 Besides successful exits, @GNUTAR{} may fail for
1880 many reasons. Some reasons correspond to bad usage, that is, when the
1881 @command{tar} command is improperly written. Errors may be
1882 encountered later, while encountering an error processing the archive
1883 or the files. Some errors are recoverable, in which case the failure
1884 is delayed until @command{tar} has completed all its work. Some
1885 errors are such that it would not meaningful, or at least risky, to
1886 continue processing: @command{tar} then aborts processing immediately.
1887 All abnormal exits, whether immediate or delayed, should always be
1888 clearly diagnosed on @code{stderr}, after a line stating the nature of
1889 the error.
1890
1891 Possible exit codes of @GNUTAR{} are summarized in the following
1892 table:
1893
1894 @table @asis
1895 @item 0
1896 @samp{Successful termination}.
1897
1898 @item 1
1899 @samp{Some files differ}. If tar was invoked with @option{--compare}
1900 (@option{--diff}, @option{-d}) command line option, this means that
1901 some files in the archive differ from their disk counterparts
1902 (@pxref{compare}). If tar was given @option{--create},
1903 @option{--append} or @option{--update} option, this exit code means
1904 that some files were changed while being archived and so the resulting
1905 archive does not contain the exact copy of the file set.
1906
1907 @item 2
1908 @samp{Fatal error}. This means that some fatal, unrecoverable error
1909 occurred.
1910 @end table
1911
1912 If @command{tar} has invoked a subprocess and that subprocess exited with a
1913 nonzero exit code, @command{tar} exits with that code as well.
1914 This can happen, for example, if @command{tar} was given some
1915 compression option (@pxref{gzip}) and the external compressor program
1916 failed. Another example is @command{rmt} failure during backup to the
1917 remote device (@pxref{Remote Tape Server}).
1918
1919 @node using tar options
1920 @section Using @command{tar} Options
1921
1922 @GNUTAR{} has a total of eight operating modes which
1923 allow you to perform a variety of tasks. You are required to choose
1924 one operating mode each time you employ the @command{tar} program by
1925 specifying one, and only one operation as an argument to the
1926 @command{tar} command (two lists of four operations each may be found
1927 at @ref{frequent operations} and @ref{Operations}). Depending on
1928 circumstances, you may also wish to customize how the chosen operating
1929 mode behaves. For example, you may wish to change the way the output
1930 looks, or the format of the files that you wish to archive may require
1931 you to do something special in order to make the archive look right.
1932
1933 You can customize and control @command{tar}'s performance by running
1934 @command{tar} with one or more options (such as @option{--verbose}
1935 (@option{-v}), which we used in the tutorial). As we said in the
1936 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1937 their name suggests) optional. Depending on the operating mode, you
1938 may specify one or more options. Different options will have different
1939 effects, but in general they all change details of the operation, such
1940 as archive format, archive name, or level of user interaction. Some
1941 options make sense with all operating modes, while others are
1942 meaningful only with particular modes. You will likely use some
1943 options frequently, while you will only use others infrequently, or
1944 not at all. (A full list of options is available in @pxref{All Options}.)
1945
1946 @vrindex TAR_OPTIONS, environment variable
1947 @anchor{TAR_OPTIONS}
1948 The @env{TAR_OPTIONS} environment variable specifies default options to
1949 be placed in front of any explicit options. For example, if
1950 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1951 if the two options @option{-v} and @option{--unlink-first} had been
1952 specified before any explicit options. Option specifications are
1953 separated by whitespace. A backslash escapes the next character, so it
1954 can be used to specify an option containing whitespace or a backslash.
1955
1956 Note that @command{tar} options are case sensitive. For example, the
1957 options @option{-T} and @option{-t} are different; the first requires an
1958 argument for stating the name of a file providing a list of @var{name}s,
1959 while the second does not require an argument and is another way to
1960 write @option{--list} (@option{-t}).
1961
1962 In addition to the eight operations, there are many options to
1963 @command{tar}, and three different styles for writing both: long (mnemonic)
1964 form, short form, and old style. These styles are discussed below.
1965 Both the options and the operations can be written in any of these three
1966 styles.
1967
1968 @FIXME{menu at end of this node. need to think of an actual outline
1969 for this chapter; probably do that after stuff from chapter 4 is
1970 incorporated.}
1971
1972 @node Styles
1973 @section The Three Option Styles
1974
1975 There are three styles for writing operations and options to the command
1976 line invoking @command{tar}. The different styles were developed at
1977 different times during the history of @command{tar}. These styles will be
1978 presented below, from the most recent to the oldest.
1979
1980 Some options must take an argument. (For example, @option{--file}
1981 (@option{-f})) takes the name of an archive file as an argument. If
1982 you do not supply an archive file name, @command{tar} will use a
1983 default, but this can be confusing; thus, we recommend that you always
1984 supply a specific archive file name.) Where you @emph{place} the
1985 arguments generally depends on which style of options you choose. We
1986 will detail specific information relevant to each option style in the
1987 sections on the different option styles, below. The differences are
1988 subtle, yet can often be very important; incorrect option placement
1989 can cause you to overwrite a number of important files. We urge you
1990 to note these differences, and only use the option style(s) which
1991 makes the most sense to you until you feel comfortable with the others.
1992
1993 Some options @emph{may} take an argument. Such options may have at
1994 most long and short forms, they do not have old style equivalent. The
1995 rules for specifying an argument for such options are stricter than
1996 those for specifying mandatory arguments. Please, pay special
1997 attention to them.
1998
1999 @menu
2000 * Long Options:: Long Option Style
2001 * Short Options:: Short Option Style
2002 * Old Options:: Old Option Style
2003 * Mixing:: Mixing Option Styles
2004 @end menu
2005
2006 @node Long Options
2007 @subsection Long Option Style
2008
2009 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2010 dashes in a row, e.g., @option{--list}. The long names are more clear than
2011 their corresponding short or old names. It sometimes happens that a
2012 single long option has many different names which are
2013 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2014 long option names can be given unique abbreviations. For example,
2015 @option{--cre} can be used in place of @option{--create} because there is no
2016 other long option which begins with @samp{cre}. (One way to find
2017 this out is by trying it and seeing what happens; if a particular
2018 abbreviation could represent more than one option, @command{tar} will tell
2019 you that that abbreviation is ambiguous and you'll know that that
2020 abbreviation won't work. You may also choose to run @samp{tar --help}
2021 to see a list of options. Be aware that if you run @command{tar} with a
2022 unique abbreviation for the long name of an option you didn't want to
2023 use, you are stuck; @command{tar} will perform the command as ordered.)
2024
2025 Long options are meant to be obvious and easy to remember, and their
2026 meanings are generally easier to discern than those of their
2027 corresponding short options (see below). For example:
2028
2029 @smallexample
2030 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2031 @end smallexample
2032
2033 @noindent
2034 gives a fairly good set of hints about what the command does, even
2035 for those not fully acquainted with @command{tar}.
2036
2037 Long options which require arguments take those arguments
2038 immediately following the option name. There are two ways of
2039 specifying a mandatory argument. It can be separated from the
2040 option name either by an equal sign, or by any amount of
2041 white space characters. For example, the @option{--file} option (which
2042 tells the name of the @command{tar} archive) is given a file such as
2043 @file{archive.tar} as argument by using any of the following notations:
2044 @option{--file=archive.tar} or @option{--file archive.tar}.
2045
2046 In contrast, optional arguments must always be introduced using
2047 an equal sign. For example, the @option{--backup} option takes
2048 an optional argument specifying backup type. It must be used
2049 as @option{--backup=@var{backup-type}}.
2050
2051 @node Short Options
2052 @subsection Short Option Style
2053
2054 Most options also have a @dfn{short option} name. Short options start with
2055 a single dash, and are followed by a single character, e.g., @option{-t}
2056 (which is equivalent to @option{--list}). The forms are absolutely
2057 identical in function; they are interchangeable.
2058
2059 The short option names are faster to type than long option names.
2060
2061 Short options which require arguments take their arguments immediately
2062 following the option, usually separated by white space. It is also
2063 possible to stick the argument right after the short option name, using
2064 no intervening space. For example, you might write @w{@option{-f
2065 archive.tar}} or @option{-farchive.tar} instead of using
2066 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2067 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2068 specific archive, here named @file{archive.tar}.
2069
2070 Short options which take optional arguments take their arguments
2071 immediately following the option letter, @emph{without any intervening
2072 white space characters}.
2073
2074 Short options' letters may be clumped together, but you are not
2075 required to do this (as compared to old options; see below). When
2076 short options are clumped as a set, use one (single) dash for them
2077 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2078 such a set is allowed to have an argument@footnote{Clustering many
2079 options, the last of which has an argument, is a rather opaque way to
2080 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2081 even be made helpful enough for considering such usages as invalid.}.
2082
2083 When the options are separated, the argument for each option which requires
2084 an argument directly follows that option, as is usual for Unix programs.
2085 For example:
2086
2087 @smallexample
2088 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2089 @end smallexample
2090
2091 If you reorder short options' locations, be sure to move any arguments
2092 that belong to them. If you do not move the arguments properly, you may
2093 end up overwriting files.
2094
2095 @node Old Options
2096 @subsection Old Option Style
2097 @UNREVISED
2098
2099 Like short options, @dfn{old options} are single letters. However, old options
2100 must be written together as a single clumped set, without spaces separating
2101 them or dashes preceding them@footnote{Beware that if you precede options
2102 with a dash, you are announcing the short option style instead of the
2103 old option style; short options are decoded differently.}. This set
2104 of letters must be the first to appear on the command line, after the
2105 @command{tar} program name and some white space; old options cannot appear
2106 anywhere else. The letter of an old option is exactly the same letter as
2107 the corresponding short option. For example, the old option @samp{t} is
2108 the same as the short option @option{-t}, and consequently, the same as the
2109 long option @option{--list}. So for example, the command @w{@samp{tar
2110 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2111
2112 When options that need arguments are given together with the command,
2113 all the associated arguments follow, in the same order as the options.
2114 Thus, the example given previously could also be written in the old
2115 style as follows:
2116
2117 @smallexample
2118 $ @kbd{tar cvbf 20 /dev/rmt0}
2119 @end smallexample
2120
2121 @noindent
2122 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2123 the argument of @option{-f}.
2124
2125 On the other hand, this old style syntax makes it difficult to match
2126 option letters with their corresponding arguments, and is often
2127 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2128 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2129 argument for @option{-f}, and @option{-v} does not have a corresponding
2130 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2131 /dev/rmt0}} is clearer, putting all arguments next to the option they
2132 pertain to.
2133
2134 If you want to reorder the letters in the old option argument, be
2135 sure to reorder any corresponding argument appropriately.
2136
2137 This old way of writing @command{tar} options can surprise even experienced
2138 users. For example, the two commands:
2139
2140 @smallexample
2141 @kbd{tar cfz archive.tar.gz file}
2142 @kbd{tar -cfz archive.tar.gz file}
2143 @end smallexample
2144
2145 @noindent
2146 are quite different. The first example uses @file{archive.tar.gz} as
2147 the value for option @samp{f} and recognizes the option @samp{z}. The
2148 second example, however, uses @file{z} as the value for option
2149 @samp{f} --- probably not what was intended.
2150
2151 Old options are kept for compatibility with old versions of @command{tar}.
2152
2153 This second example could be corrected in many ways, among which the
2154 following are equivalent:
2155
2156 @smallexample
2157 @kbd{tar -czf archive.tar.gz file}
2158 @kbd{tar -cf archive.tar.gz -z file}
2159 @kbd{tar cf archive.tar.gz -z file}
2160 @end smallexample
2161
2162 @cindex option syntax, traditional
2163 As far as we know, all @command{tar} programs, @acronym{GNU} and
2164 non-@acronym{GNU}, support old options. @GNUTAR{}
2165 supports them not only for historical reasons, but also because many
2166 people are used to them. For compatibility with Unix @command{tar},
2167 the first argument is always treated as containing command and option
2168 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2169 equivalent to @w{@samp{tar -c}:} both of them specify the
2170 @option{--create} (@option{-c}) command to create an archive.
2171
2172 @node Mixing
2173 @subsection Mixing Option Styles
2174
2175 All three styles may be intermixed in a single @command{tar} command,
2176 so long as the rules for each style are fully
2177 respected@footnote{Before @GNUTAR{} version 1.11.6,
2178 a bug prevented intermixing old style options with long options in
2179 some cases.}. Old style options and either of the modern styles of
2180 options may be mixed within a single @command{tar} command. However,
2181 old style options must be introduced as the first arguments only,
2182 following the rule for old options (old options must appear directly
2183 after the @command{tar} command and some white space). Modern options
2184 may be given only after all arguments to the old options have been
2185 collected. If this rule is not respected, a modern option might be
2186 falsely interpreted as the value of the argument to one of the old
2187 style options.
2188
2189 For example, all the following commands are wholly equivalent, and
2190 illustrate the many combinations and orderings of option styles.
2191
2192 @smallexample
2193 @kbd{tar --create --file=archive.tar}
2194 @kbd{tar --create -f archive.tar}
2195 @kbd{tar --create -farchive.tar}
2196 @kbd{tar --file=archive.tar --create}
2197 @kbd{tar --file=archive.tar -c}
2198 @kbd{tar -c --file=archive.tar}
2199 @kbd{tar -c -f archive.tar}
2200 @kbd{tar -c -farchive.tar}
2201 @kbd{tar -cf archive.tar}
2202 @kbd{tar -cfarchive.tar}
2203 @kbd{tar -f archive.tar --create}
2204 @kbd{tar -f archive.tar -c}
2205 @kbd{tar -farchive.tar --create}
2206 @kbd{tar -farchive.tar -c}
2207 @kbd{tar c --file=archive.tar}
2208 @kbd{tar c -f archive.tar}
2209 @kbd{tar c -farchive.tar}
2210 @kbd{tar cf archive.tar}
2211 @kbd{tar f archive.tar --create}
2212 @kbd{tar f archive.tar -c}
2213 @kbd{tar fc archive.tar}
2214 @end smallexample
2215
2216 On the other hand, the following commands are @emph{not} equivalent to
2217 the previous set:
2218
2219 @smallexample
2220 @kbd{tar -f -c archive.tar}
2221 @kbd{tar -fc archive.tar}
2222 @kbd{tar -fcarchive.tar}
2223 @kbd{tar -farchive.tarc}
2224 @kbd{tar cfarchive.tar}
2225 @end smallexample
2226
2227 @noindent
2228 These last examples mean something completely different from what the
2229 user intended (judging based on the example in the previous set which
2230 uses long options, whose intent is therefore very clear). The first
2231 four specify that the @command{tar} archive would be a file named
2232 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2233 respectively. The first two examples also specify a single non-option,
2234 @var{name} argument having the value @samp{archive.tar}. The last
2235 example contains only old style option letters (repeating option
2236 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2237 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2238 the first sentence of this paragraph..}
2239
2240 @node All Options
2241 @section All @command{tar} Options
2242
2243 The coming manual sections contain an alphabetical listing of all
2244 @command{tar} operations and options, with brief descriptions and cross
2245 references to more in-depth explanations in the body of the manual.
2246 They also contain an alphabetically arranged table of the short option
2247 forms with their corresponding long option. You can use this table as
2248 a reference for deciphering @command{tar} commands in scripts.
2249
2250 @menu
2251 * Operation Summary::
2252 * Option Summary::
2253 * Short Option Summary::
2254 @end menu
2255
2256 @node Operation Summary
2257 @subsection Operations
2258
2259 @table @option
2260
2261 @opsummary{append}
2262 @item --append
2263 @itemx -r
2264
2265 Appends files to the end of the archive. @xref{append}.
2266
2267 @opsummary{catenate}
2268 @item --catenate
2269 @itemx -A
2270
2271 Same as @option{--concatenate}. @xref{concatenate}.
2272
2273 @opsummary{compare}
2274 @item --compare
2275 @itemx -d
2276
2277 Compares archive members with their counterparts in the file
2278 system, and reports differences in file size, mode, owner,
2279 modification date and contents. @xref{compare}.
2280
2281 @opsummary{concatenate}
2282 @item --concatenate
2283 @itemx -A
2284
2285 Appends other @command{tar} archives to the end of the archive.
2286 @xref{concatenate}.
2287
2288 @opsummary{create}
2289 @item --create
2290 @itemx -c
2291
2292 Creates a new @command{tar} archive. @xref{create}.
2293
2294 @opsummary{delete}
2295 @item --delete
2296
2297 Deletes members from the archive. Don't try this on a archive on a
2298 tape! @xref{delete}.
2299
2300 @opsummary{diff}
2301 @item --diff
2302 @itemx -d
2303
2304 Same @option{--compare}. @xref{compare}.
2305
2306 @opsummary{extract}
2307 @item --extract
2308 @itemx -x
2309
2310 Extracts members from the archive into the file system. @xref{extract}.
2311
2312 @opsummary{get}
2313 @item --get
2314 @itemx -x
2315
2316 Same as @option{--extract}. @xref{extract}.
2317
2318 @opsummary{list}
2319 @item --list
2320 @itemx -t
2321
2322 Lists the members in an archive. @xref{list}.
2323
2324 @opsummary{update}
2325 @item --update
2326 @itemx -u
2327
2328 Adds files to the end of the archive, but only if they are newer than
2329 their counterparts already in the archive, or if they do not already
2330 exist in the archive. @xref{update}.
2331
2332 @end table
2333
2334 @node Option Summary
2335 @subsection @command{tar} Options
2336
2337 @table @option
2338
2339 @opsummary{absolute-names}
2340 @item --absolute-names
2341 @itemx -P
2342
2343 Normally when creating an archive, @command{tar} strips an initial
2344 @samp{/} from member names. This option disables that behavior.
2345 @xref{absolute}.
2346
2347 @opsummary{after-date}
2348 @item --after-date
2349
2350 (See @option{--newer}, @pxref{after})
2351
2352 @opsummary{anchored}
2353 @item --anchored
2354 A pattern must match an initial subsequence of the name's components.
2355 @xref{controlling pattern-matching}.
2356
2357 @opsummary{atime-preserve}
2358 @item --atime-preserve
2359 @itemx --atime-preserve=replace
2360 @itemx --atime-preserve=system
2361
2362 Attempt to preserve the access time of files when reading them. This
2363 option currently is effective only on files that you own, unless you
2364 have superuser privileges.
2365
2366 @option{--atime-preserve=replace} remembers the access time of a file
2367 before reading it, and then restores the access time afterwards. This
2368 may cause problems if other programs are reading the file at the same
2369 time, as the times of their accesses will be lost. On most platforms
2370 restoring the access time also requires @command{tar} to restore the
2371 data modification time too, so this option may also cause problems if
2372 other programs are writing the file at the same time. (Tar attempts
2373 to detect this situation, but cannot do so reliably due to race
2374 conditions.) Worse, on most platforms restoring the access time also
2375 updates the status change time, which means that this option is
2376 incompatible with incremental backups.
2377
2378 @option{--atime-preserve=system} avoids changing time stamps on files,
2379 without interfering with time stamp updates
2380 caused by other programs, so it works better with incremental backups.
2381 However, it requires a special @code{O_NOATIME} option from the
2382 underlying operating and file system implementation, and it also requires
2383 that searching directories does not update their access times. As of
2384 this writing (November 2005) this works only with Linux, and only with
2385 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2386 way to know whether this feature actually works. Sometimes
2387 @command{tar} knows that it does not work, and if you use
2388 @option{--atime-preserve=system} then @command{tar} complains and
2389 exits right away. But other times @command{tar} might think that the
2390 option works when it actually does not.
2391
2392 Currently @option{--atime-preserve} with no operand defaults to
2393 @option{--atime-preserve=replace}, but this may change in the future
2394 as support for @option{--atime-preserve=system} improves.
2395
2396 If your operating system does not support
2397 @option{--atime-preserve=@-system}, you might be able to preserve access
2398 times reliably by by using the @command{mount} command. For example,
2399 you can mount the file system read-only, or access the file system via
2400 a read-only loopback mount, or use the @samp{noatime} mount option
2401 available on some systems. However, mounting typically requires
2402 superuser privileges and can be a pain to manage.
2403
2404 @opsummary{backup}
2405 @item --backup=@var{backup-type}
2406
2407 Rather than deleting files from the file system, @command{tar} will
2408 back them up using simple or numbered backups, depending upon
2409 @var{backup-type}. @xref{backup}.
2410
2411 @opsummary{block-number}
2412 @item --block-number
2413 @itemx -R
2414
2415 With this option present, @command{tar} prints error messages for read errors
2416 with the block number in the archive file. @xref{block-number}.
2417
2418 @opsummary{blocking-factor}
2419 @item --blocking-factor=@var{blocking}
2420 @itemx -b @var{blocking}
2421
2422 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2423 record. @xref{Blocking Factor}.
2424
2425 @opsummary{bzip2}
2426 @item --bzip2
2427 @itemx -j
2428
2429 This option tells @command{tar} to read or write archives through
2430 @code{bzip2}. @xref{gzip}.
2431
2432 @opsummary{checkpoint}
2433 @item --checkpoint[=@var{number}]
2434
2435 This option directs @command{tar} to print periodic checkpoint
2436 messages as it reads through the archive. It is intended for when you
2437 want a visual indication that @command{tar} is still running, but
2438 don't want to see @option{--verbose} output. For a detailed
2439 description, see @ref{Progress information}.
2440
2441 @opsummary{check-links}
2442 @item --check-links
2443 @itemx -l
2444 If this option was given, @command{tar} will check the number of links
2445 dumped for each processed file. If this number does not match the
2446 total number of hard links for the file, a warning message will be
2447 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2448 synonym for @option{--one-file-system}. The current semantics, which
2449 complies to UNIX98, was introduced with version
2450 1.15.91. @xref{Changes}, for more information.}.
2451
2452 @opsummary{compress}
2453 @opsummary{uncompress}
2454 @item --compress
2455 @itemx --uncompress
2456 @itemx -Z
2457
2458 @command{tar} will use the @command{compress} program when reading or
2459 writing the archive. This allows you to directly act on archives
2460 while saving space. @xref{gzip}.
2461
2462 @opsummary{confirmation}
2463 @item --confirmation
2464
2465 (See @option{--interactive}.) @xref{interactive}.
2466
2467 @opsummary{delay-directory-restore}
2468 @item --delay-directory-restore
2469
2470 Delay setting modification times and permissions of extracted
2471 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2472
2473 @opsummary{dereference}
2474 @item --dereference
2475 @itemx -h
2476
2477 When creating a @command{tar} archive, @command{tar} will archive the
2478 file that a symbolic link points to, rather than archiving the
2479 symlink. @xref{dereference}.
2480
2481 @opsummary{directory}
2482 @item --directory=@var{dir}
2483 @itemx -C @var{dir}
2484
2485 When this option is specified, @command{tar} will change its current directory
2486 to @var{dir} before performing any operations. When this option is used
2487 during archive creation, it is order sensitive. @xref{directory}.
2488
2489 @opsummary{exclude}
2490 @item --exclude=@var{pattern}
2491
2492 When performing operations, @command{tar} will skip files that match
2493 @var{pattern}. @xref{exclude}.
2494
2495 @opsummary{exclude-from}
2496 @item --exclude-from=@var{file}
2497 @itemx -X @var{file}
2498
2499 Similar to @option{--exclude}, except @command{tar} will use the list of
2500 patterns in the file @var{file}. @xref{exclude}.
2501
2502 @opsummary{exclude-caches}
2503 @item --exclude-caches
2504
2505 Automatically excludes all directories
2506 containing a cache directory tag. @xref{exclude}.
2507
2508 @opsummary{exclude-tag}
2509 @item --exclude-tag=@var{file}
2510
2511 Exclude all directories, containing file named @var{file}. @xref{exclude}.
2512
2513 @opsummary{file}
2514 @item --file=@var{archive}
2515 @itemx -f @var{archive}
2516
2517 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2518 performs operations on, rather than @command{tar}'s compilation dependent
2519 default. @xref{file tutorial}.
2520
2521 @opsummary{files-from}
2522 @item --files-from=@var{file}
2523 @itemx -T @var{file}
2524
2525 @command{tar} will use the contents of @var{file} as a list of archive members
2526 or files to operate on, in addition to those specified on the
2527 command-line. @xref{files}.
2528
2529 @opsummary{force-local}
2530 @item --force-local
2531
2532 Forces @command{tar} to interpret the filename given to @option{--file}
2533 as a local file, even if it looks like a remote tape drive name.
2534 @xref{local and remote archives}.
2535
2536 @opsummary{format}
2537 @item --format=@var{format}
2538 @itemx -H @var{format}
2539
2540 Selects output archive format. @var{Format} may be one of the
2541 following:
2542
2543 @table @samp
2544 @item v7
2545 Creates an archive that is compatible with Unix V7 @command{tar}.
2546
2547 @item oldgnu
2548 Creates an archive that is compatible with GNU @command{tar} version
2549 1.12 or earlier.
2550
2551 @item gnu
2552 Creates archive in GNU tar 1.13 format. Basically it is the same as
2553 @samp{oldgnu} with the only difference in the way it handles long
2554 numeric fields.
2555
2556 @item ustar
2557 Creates a @acronym{POSIX.1-1988} compatible archive.
2558
2559 @item posix
2560 Creates a @acronym{POSIX.1-2001 archive}.
2561
2562 @end table
2563
2564 @xref{Formats}, for a detailed discussion of these formats.
2565
2566 @opsummary{group}
2567 @item --group=@var{group}
2568
2569 Files added to the @command{tar} archive will have a group id of @var{group},
2570 rather than the group from the source file. @var{group} is first decoded
2571 as a group symbolic name, but if this interpretation fails, it has to be
2572 a decimal numeric group ID. @xref{override}.
2573
2574 Also see the comments for the @option{--owner=@var{user}} option.
2575
2576 @opsummary{gzip}
2577 @opsummary{gunzip}
2578 @opsummary{ungzip}
2579 @item --gzip
2580 @itemx --gunzip
2581 @itemx --ungzip
2582 @itemx -z
2583
2584 This option tells @command{tar} to read or write archives through
2585 @command{gzip}, allowing @command{tar} to directly operate on several
2586 kinds of compressed archives transparently. @xref{gzip}.
2587
2588 @opsummary{help}
2589 @item --help
2590 @itemx -?
2591
2592 @command{tar} will print out a short message summarizing the operations and
2593 options to @command{tar} and exit. @xref{help}.
2594
2595 @opsummary{ignore-case}
2596 @item --ignore-case
2597 Ignore case when matching member or file names with
2598 patterns. @xref{controlling pattern-matching}.
2599
2600 @opsummary{ignore-command-error}
2601 @item --ignore-command-error
2602 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2603
2604 @opsummary{ignore-failed-read}
2605 @item --ignore-failed-read
2606
2607 Do not exit unsuccessfully merely because an unreadable file was encountered.
2608 @xref{Reading}.
2609
2610 @opsummary{ignore-zeros}
2611 @item --ignore-zeros
2612 @itemx -i
2613
2614 With this option, @command{tar} will ignore zeroed blocks in the
2615 archive, which normally signals EOF. @xref{Reading}.
2616
2617 @opsummary{incremental}
2618 @item --incremental
2619 @itemx -G
2620
2621 Used to inform @command{tar} that it is working with an old
2622 @acronym{GNU}-format incremental backup archive. It is intended
2623 primarily for backwards compatibility only. @xref{Incremental Dumps},
2624 for a detailed discussion of incremental archives.
2625
2626 @opsummary{index-file}
2627 @item --index-file=@var{file}
2628
2629 Send verbose output to @var{file} instead of to standard output.
2630
2631 @opsummary{info-script}
2632 @opsummary{new-volume-script}
2633 @item --info-script=@var{script-file}
2634 @itemx --new-volume-script=@var{script-file}
2635 @itemx -F @var{script-file}
2636
2637 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2638 at the end of each tape. If @var{script-file} exits with nonzero status,
2639 @command{tar} fails immediately. @xref{info-script}, for a detailed
2640 discussion of @var{script-file}.
2641
2642 @opsummary{interactive}
2643 @item --interactive
2644 @itemx --confirmation
2645 @itemx -w
2646
2647 Specifies that @command{tar} should ask the user for confirmation before
2648 performing potentially destructive options, such as overwriting files.
2649 @xref{interactive}.
2650
2651 @opsummary{keep-newer-files}
2652 @item --keep-newer-files
2653
2654 Do not replace existing files that are newer than their archive copies
2655 when extracting files from an archive.
2656
2657 @opsummary{keep-old-files}
2658 @item --keep-old-files
2659 @itemx -k
2660
2661 Do not overwrite existing files when extracting files from an archive.
2662 @xref{Keep Old Files}.
2663
2664 @opsummary{label}
2665 @item --label=@var{name}
2666 @itemx -V @var{name}
2667
2668 When creating an archive, instructs @command{tar} to write @var{name}
2669 as a name record in the archive. When extracting or listing archives,
2670 @command{tar} will only operate on archives that have a label matching
2671 the pattern specified in @var{name}. @xref{Tape Files}.
2672
2673 @opsummary{listed-incremental}
2674 @item --listed-incremental=@var{snapshot-file}
2675 @itemx -g @var{snapshot-file}
2676
2677 During a @option{--create} operation, specifies that the archive that
2678 @command{tar} creates is a new @acronym{GNU}-format incremental
2679 backup, using @var{snapshot-file} to determine which files to backup.
2680 With other operations, informs @command{tar} that the archive is in
2681 incremental format. @xref{Incremental Dumps}.
2682
2683 @opsummary{mode}
2684 @item --mode=@var{permissions}
2685
2686 When adding files to an archive, @command{tar} will use
2687 @var{permissions} for the archive members, rather than the permissions
2688 from the files. @var{permissions} can be specified either as an octal
2689 number or as symbolic permissions, like with
2690 @command{chmod}. @xref{override}.
2691
2692 @opsummary{mtime}
2693 @item --mtime=@var{date}
2694
2695 When adding files to an archive, @command{tar} will use @var{date} as
2696 the modification time of members when creating archives, instead of
2697 their actual modification times. The value of @var{date} can be
2698 either a textual date representation (@pxref{Date input formats}) or a
2699 name of the existing file, starting with @samp{/} or @samp{.}. In the
2700 latter case, the modification time of that file is used. @xref{override}.
2701
2702 @opsummary{multi-volume}
2703 @item --multi-volume
2704 @itemx -M
2705
2706 Informs @command{tar} that it should create or otherwise operate on a
2707 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2708
2709 @opsummary{new-volume-script}
2710 @item --new-volume-script
2711
2712 (see --info-script)
2713
2714 @opsummary{seek}
2715 @item --seek
2716 @itemx -n
2717
2718 Assume that the archive media supports seeks to arbitrary
2719 locations. Usually @command{tar} determines automatically whether
2720 the archive can be seeked or not. This option is intended for use
2721 in cases when such recognition fails.
2722
2723 @opsummary{newer}
2724 @item --newer=@var{date}
2725 @itemx --after-date=@var{date}
2726 @itemx -N
2727
2728 When creating an archive, @command{tar} will only add files that have changed
2729 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2730 is taken to be the name of a file whose data modification time specifies
2731 the date. @xref{after}.
2732
2733 @opsummary{newer-mtime}
2734 @item --newer-mtime=@var{date}
2735
2736 Like @option{--newer}, but add only files whose
2737 contents have changed (as opposed to just @option{--newer}, which will
2738 also back up files for which any status information has
2739 changed). @xref{after}.
2740
2741 @opsummary{no-anchored}
2742 @item --no-anchored
2743 An exclude pattern can match any subsequence of the name's components.
2744 @xref{controlling pattern-matching}.
2745
2746 @opsummary{no-delay-directory-restore}
2747 @item --no-delay-directory-restore
2748
2749 Setting modification times and permissions of extracted
2750 directories when all files from this directory has been
2751 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2752
2753 @opsummary{no-ignore-case}
2754 @item --no-ignore-case
2755 Use case-sensitive matching.
2756 @xref{controlling pattern-matching}.
2757
2758 @opsummary{no-ignore-command-error}
2759 @item --no-ignore-command-error
2760 Print warnings about subprocesses terminated with a non-zero exit
2761 code. @xref{Writing to an External Program}.
2762
2763 @opsummary{no-overwrite-dir}
2764 @item --no-overwrite-dir
2765
2766 Preserve metadata of existing directories when extracting files
2767 from an archive. @xref{Overwrite Old Files}.
2768
2769 @opsummary{no-quote-chars}
2770 @item --no-quote-chars=@var{string}
2771 Remove characters listed in @var{string} from the list of quoted
2772 characters set by the previous @option{--quote-chars} option
2773 (@pxref{quoting styles}).
2774
2775 @opsummary{no-recursion}
2776 @item --no-recursion
2777
2778 With this option, @command{tar} will not recurse into directories.
2779 @xref{recurse}.
2780
2781 @opsummary{no-same-owner}
2782 @item --no-same-owner
2783 @itemx -o
2784
2785 When extracting an archive, do not attempt to preserve the owner
2786 specified in the @command{tar} archive. This the default behavior
2787 for ordinary users.
2788
2789 @opsummary{no-same-permissions}
2790 @item --no-same-permissions
2791
2792 When extracting an archive, subtract the user's umask from files from
2793 the permissions specified in the archive. This is the default behavior
2794 for ordinary users.
2795
2796 @opsummary{no-unquote}
2797 @item --no-unquote
2798 Treat all input file or member names literally, do not interpret
2799 escape sequences. @xref{input name quoting}.
2800
2801 @opsummary{no-wildcards}
2802 @item --no-wildcards
2803 Do not use wildcards.
2804 @xref{controlling pattern-matching}.
2805
2806 @opsummary{no-wildcards-match-slash}
2807 @item --no-wildcards-match-slash
2808 Wildcards do not match @samp{/}.
2809 @xref{controlling pattern-matching}.
2810
2811 @opsummary{null}
2812 @item --null
2813
2814 When @command{tar} is using the @option{--files-from} option, this option
2815 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2816 @command{tar} can correctly work with file names that contain newlines.
2817 @xref{nul}.
2818
2819 @opsummary{numeric-owner}
2820 @item --numeric-owner
2821
2822 This option will notify @command{tar} that it should use numeric user
2823 and group IDs when creating a @command{tar} file, rather than names.
2824 @xref{Attributes}.
2825
2826 @item -o
2827 The function of this option depends on the action @command{tar} is
2828 performing. When extracting files, @option{-o} is a synonym for
2829 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2830 restoring ownership of files being extracted.
2831
2832 When creating an archive, it is a synonym for
2833 @option{--old-archive}. This behavior is for compatibility
2834 with previous versions of @GNUTAR{}, and will be
2835 removed in the future releases.
2836
2837 @xref{Changes}, for more information.
2838
2839 @opsummary{occurrence}
2840 @item --occurrence[=@var{number}]
2841
2842 This option can be used in conjunction with one of the subcommands
2843 @option{--delete}, @option{--diff}, @option{--extract} or
2844 @option{--list} when a list of files is given either on the command
2845 line or via @option{-T} option.
2846
2847 This option instructs @command{tar} to process only the @var{number}th
2848 occurrence of each named file. @var{Number} defaults to 1, so
2849
2850 @smallexample
2851 tar -x -f archive.tar --occurrence filename
2852 @end smallexample
2853
2854 @noindent
2855 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2856 and will terminate without scanning to the end of the archive.
2857
2858 @opsummary{old-archive}
2859 @item --old-archive
2860 Synonym for @option{--format=v7}.
2861
2862 @opsummary{one-file-system}
2863 @item --one-file-system
2864 Used when creating an archive. Prevents @command{tar} from recursing into
2865 directories that are on different file systems from the current
2866 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2867 synonym for @option{--one-file-system}. This has changed in version
2868 1.15.91. @xref{Changes}, for more information.}.
2869
2870 @opsummary{overwrite}
2871 @item --overwrite
2872
2873 Overwrite existing files and directory metadata when extracting files
2874 from an archive. @xref{Overwrite Old Files}.
2875
2876 @opsummary{overwrite-dir}
2877 @item --overwrite-dir
2878
2879 Overwrite the metadata of existing directories when extracting files
2880 from an archive. @xref{Overwrite Old Files}.
2881
2882 @opsummary{owner}
2883 @item --owner=@var{user}
2884
2885 Specifies that @command{tar} should use @var{user} as the owner of members
2886 when creating archives, instead of the user associated with the source
2887 file. @var{user} is first decoded as a user symbolic name, but if
2888 this interpretation fails, it has to be a decimal numeric user ID.
2889 @xref{override}.
2890
2891 This option does not affect extraction from archives.
2892
2893 @opsummary{transform}
2894 @item --transform=@var{sed-expr}
2895
2896 Transform file or member names using @command{sed} replacement expression
2897 @var{sed-expr}. For example,
2898
2899 @smallexample
2900 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2901 @end smallexample
2902
2903 @noindent
2904 will add to @file{archive} files from the current working directory,
2905 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2906 discussion, @xref{transform}.
2907
2908 To see transformed member names in verbose listings, use
2909 @option{--show-transformed-names} option
2910 (@pxref{show-transformed-names}).
2911
2912 @opsummary{quote-chars}
2913 @item --quote-chars=@var{string}
2914 Always quote characters from @var{string}, even if the selected
2915 quoting style would not quote them (@pxref{quoting styles}).
2916
2917 @opsummary{quoting-style}
2918 @item --quoting-style=@var{style}
2919 Set quoting style to use when printing member and file names
2920 (@pxref{quoting styles}). Valid @var{style} values are:
2921 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2922 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2923 style is @code{escape}, unless overridden while configuring the
2924 package.
2925
2926 @opsummary{pax-option}
2927 @item --pax-option=@var{keyword-list}
2928 This option is meaningful only with @acronym{POSIX.1-2001} archives
2929 (@pxref{posix}). It modifies the way @command{tar} handles the
2930 extended header keywords. @var{Keyword-list} is a comma-separated
2931 list of keyword options. @xref{PAX keywords}, for a detailed
2932 discussion.
2933
2934 @opsummary{portability}
2935 @item --portability
2936 @itemx --old-archive
2937 Synonym for @option{--format=v7}.
2938
2939 @opsummary{posix}
2940 @item --posix
2941 Same as @option{--format=posix}.
2942
2943 @opsummary{preserve}
2944 @item --preserve
2945
2946 Synonymous with specifying both @option{--preserve-permissions} and
2947 @option{--same-order}. @xref{Setting Access Permissions}.
2948
2949 @opsummary{preserve-order}
2950 @item --preserve-order
2951
2952 (See @option{--same-order}; @pxref{Reading}.)
2953
2954 @opsummary{preserve-permissions}
2955 @opsummary{same-permissions}
2956 @item --preserve-permissions
2957 @itemx --same-permissions
2958 @itemx -p
2959
2960 When @command{tar} is extracting an archive, it normally subtracts the
2961 users' umask from the permissions specified in the archive and uses
2962 that number as the permissions to create the destination file.
2963 Specifying this option instructs @command{tar} that it should use the
2964 permissions directly from the archive. @xref{Setting Access Permissions}.
2965
2966 @opsummary{read-full-records}
2967 @item --read-full-records
2968 @itemx -B
2969
2970 Specifies that @command{tar} should reblock its input, for reading
2971 from pipes on systems with buggy implementations. @xref{Reading}.
2972
2973 @opsummary{record-size}
2974 @item --record-size=@var{size}
2975
2976 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2977 archive. @xref{Blocking Factor}.
2978
2979 @opsummary{recursion}
2980 @item --recursion
2981
2982 With this option, @command{tar} recurses into directories.
2983 @xref{recurse}.
2984
2985 @opsummary{recursive-unlink}
2986 @item --recursive-unlink
2987
2988 Remove existing
2989 directory hierarchies before extracting directories of the same name
2990 from the archive. @xref{Recursive Unlink}.
2991
2992 @opsummary{remove-files}
2993 @item --remove-files
2994
2995 Directs @command{tar} to remove the source file from the file system after
2996 appending it to an archive. @xref{remove files}.
2997
2998 @opsummary{restrict}
2999 @item --restrict
3000
3001 Disable use of some potentially harmful @command{tar} options.
3002 Currently this option disables shell invocation from multi-volume menu
3003 (@pxref{Using Multiple Tapes}).
3004
3005 @opsummary{rmt-command}
3006 @item --rmt-command=@var{cmd}
3007
3008 Notifies @command{tar} that it should use @var{cmd} instead of
3009 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3010
3011 @opsummary{rsh-command}
3012 @item --rsh-command=@var{cmd}
3013
3014 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3015 devices. @xref{Device}.
3016
3017 @opsummary{same-order}
3018 @item --same-order
3019 @itemx --preserve-order
3020 @itemx -s
3021
3022 This option is an optimization for @command{tar} when running on machines with
3023 small amounts of memory. It informs @command{tar} that the list of file
3024 arguments has already been sorted to match the order of files in the
3025 archive. @xref{Reading}.
3026
3027 @opsummary{same-owner}
3028 @item --same-owner
3029
3030 When extracting an archive, @command{tar} will attempt to preserve the owner
3031 specified in the @command{tar} archive with this option present.
3032 This is the default behavior for the superuser; this option has an
3033 effect only for ordinary users. @xref{Attributes}.
3034
3035 @opsummary{same-permissions}
3036 @item --same-permissions
3037
3038 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3039
3040 @opsummary{show-defaults}
3041 @item --show-defaults
3042
3043 Displays the default options used by @command{tar} and exits
3044 successfully. This option is intended for use in shell scripts.
3045 Here is an example of what you can see using this option:
3046
3047 @smallexample
3048 $ tar --show-defaults
3049 --format=gnu -f- -b20 --quoting-style=escape \
3050 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3051 @end smallexample
3052
3053 @opsummary{show-omitted-dirs}
3054 @item --show-omitted-dirs
3055
3056 Instructs @command{tar} to mention directories its skipping over when
3057 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3058
3059 @opsummary{show-transformed-names}
3060 @opsummary{show-stored-names}
3061 @item --show-transformed-names
3062 @itemx --show-stored-names
3063
3064 Display file or member names after applying any transformations
3065 (@pxref{transform}). In particular, when used in conjunction with one of
3066 archive creation operations it instructs tar to list the member names
3067 stored in the archive, as opposed to the actual file
3068 names. @xref{listing member and file names}.
3069
3070 @opsummary{sparse}
3071 @item --sparse
3072 @itemx -S
3073
3074 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3075 sparse files efficiently. @xref{sparse}.
3076
3077 @opsummary{sparse-version}
3078 @item --sparse-version=@var{version}
3079
3080 Specified the @dfn{format version} to use when archiving sparse
3081 files. Implies @option{--sparse}. @xref{sparse}. For the description
3082 of the supported sparse formats, @xref{Sparse Formats}.
3083
3084 @opsummary{starting-file}
3085 @item --starting-file=@var{name}
3086 @itemx -K @var{name}
3087
3088 This option affects extraction only; @command{tar} will skip extracting
3089 files in the archive until it finds one that matches @var{name}.
3090 @xref{Scarce}.
3091
3092 @opsummary{strip-components}
3093 @item --strip-components=@var{number}
3094 Strip given @var{number} of leading components from file names before
3095 extraction.@footnote{This option was called @option{--strip-path} in
3096 version 1.14.} For example, if archive @file{archive.tar} contained
3097 @file{/some/file/name}, then running
3098
3099 @smallexample
3100 tar --extract --file archive.tar --strip-components=2
3101 @end smallexample
3102
3103 @noindent
3104 would extract this file to file @file{name}.
3105
3106 @opsummary{suffix}, summary
3107 @item --suffix=@var{suffix}
3108
3109 Alters the suffix @command{tar} uses when backing up files from the default
3110 @samp{~}. @xref{backup}.
3111
3112 @opsummary{tape-length}
3113 @item --tape-length=@var{num}
3114 @itemx -L @var{num}
3115
3116 Specifies the length of tapes that @command{tar} is writing as being
3117 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3118
3119 @opsummary{test-label}
3120 @item --test-label
3121
3122 Reads the volume label. If an argument is specified, test whether it
3123 matches the volume label. @xref{--test-label option}.
3124
3125 @opsummary{to-command}
3126 @item --to-command=@var{command}
3127
3128 During extraction @command{tar} will pipe extracted files to the
3129 standard input of @var{command}. @xref{Writing to an External Program}.
3130
3131 @opsummary{to-stdout}
3132 @item --to-stdout
3133 @itemx -O
3134
3135 During extraction, @command{tar} will extract files to stdout rather
3136 than to the file system. @xref{Writing to Standard Output}.
3137
3138 @opsummary{totals}
3139 @item --totals[=@var{signo}]
3140
3141 Displays the total number of bytes transferred when processing an
3142 archive. If an argument is given, these data are displayed on
3143 request, when signal @var{signo} is delivered to @command{tar}.
3144 @xref{totals}.
3145
3146 @opsummary{touch}
3147 @item --touch
3148 @itemx -m
3149
3150 Sets the data modification time of extracted files to the extraction time,
3151 rather than the data modification time stored in the archive.
3152 @xref{Data Modification Times}.
3153
3154 @opsummary{uncompress}
3155 @item --uncompress
3156
3157 (See @option{--compress}. @pxref{gzip})
3158
3159 @opsummary{ungzip}
3160 @item --ungzip
3161
3162 (See @option{--gzip}. @pxref{gzip})
3163
3164 @opsummary{unlink-first}
3165 @item --unlink-first
3166 @itemx -U
3167
3168 Directs @command{tar} to remove the corresponding file from the file
3169 system before extracting it from the archive. @xref{Unlink First}.
3170
3171 @opsummary{unquote}
3172 @item --unquote
3173 Enable unquoting input file or member names (default). @xref{input
3174 name quoting}.
3175
3176 @opsummary{use-compress-program}
3177 @item --use-compress-program=@var{prog}
3178
3179 Instructs @command{tar} to access the archive through @var{prog}, which is
3180 presumed to be a compression program of some sort. @xref{gzip}.
3181
3182 @opsummary{utc}
3183 @item --utc
3184
3185 Display file modification dates in @acronym{UTC}. This option implies
3186 @option{--verbose}.
3187
3188 @opsummary{verbose}
3189 @item --verbose
3190 @itemx -v
3191
3192 Specifies that @command{tar} should be more verbose about the operations its
3193 performing. This option can be specified multiple times for some
3194 operations to increase the amount of information displayed.
3195 @xref{verbose}.
3196
3197 @opsummary{verify}
3198 @item --verify
3199 @itemx -W
3200
3201 Verifies that the archive was correctly written when creating an
3202 archive. @xref{verify}.
3203
3204 @opsummary{version}
3205 @item --version
3206
3207 Print information about the program's name, version, origin and legal
3208 status, all on standard output, and then exit successfully.
3209 @xref{help}.
3210
3211 @opsummary{volno-file}
3212 @item --volno-file=@var{file}
3213
3214 Used in conjunction with @option{--multi-volume}. @command{tar} will
3215 keep track of which volume of a multi-volume archive its working in
3216 @var{file}. @xref{volno-file}.
3217
3218 @opsummary{wildcards}
3219 @item --wildcards
3220 Use wildcards when matching member names with patterns.
3221 @xref{controlling pattern-matching}.
3222
3223 @opsummary{wildcards-match-slash}
3224 @item --wildcards-match-slash
3225 Wildcards match @samp{/}.
3226 @xref{controlling pattern-matching}.
3227 @end table
3228
3229 @node Short Option Summary
3230 @subsection Short Options Cross Reference
3231
3232 Here is an alphabetized list of all of the short option forms, matching
3233 them with the equivalent long option.
3234
3235 @multitable @columnfractions 0.20 0.80
3236 @headitem Short Option @tab Reference
3237
3238 @item -A @tab @ref{--concatenate}.
3239
3240 @item -B @tab @ref{--read-full-records}.
3241
3242 @item -C @tab @ref{--directory}.
3243
3244 @item -F @tab @ref{--info-script}.
3245
3246 @item -G @tab @ref{--incremental}.
3247
3248 @item -K @tab @ref{--starting-file}.
3249
3250 @item -L @tab @ref{--tape-length}.
3251
3252 @item -M @tab @ref{--multi-volume}.
3253
3254 @item -N @tab @ref{--newer}.
3255
3256 @item -O @tab @ref{--to-stdout}.
3257
3258 @item -P @tab @ref{--absolute-names}.
3259
3260 @item -R @tab @ref{--block-number}.
3261
3262 @item -S @tab @ref{--sparse}.
3263
3264 @item -T @tab @ref{--files-from}.
3265
3266 @item -U @tab @ref{--unlink-first}.
3267
3268 @item -V @tab @ref{--label}.
3269
3270 @item -W @tab @ref{--verify}.
3271
3272 @item -X @tab @ref{--exclude-from}.
3273
3274 @item -Z @tab @ref{--compress}.
3275
3276 @item -b @tab @ref{--blocking-factor}.
3277
3278 @item -c @tab @ref{--create}.
3279
3280 @item -d @tab @ref{--compare}.
3281
3282 @item -f @tab @ref{--file}.
3283
3284 @item -g @tab @ref{--listed-incremental}.
3285
3286 @item -h @tab @ref{--dereference}.
3287
3288 @item -i @tab @ref{--ignore-zeros}.
3289
3290 @item -j @tab @ref{--bzip2}.
3291
3292 @item -k @tab @ref{--keep-old-files}.
3293
3294 @item -l @tab @ref{--check-links}.
3295
3296 @item -m @tab @ref{--touch}.
3297
3298 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3299 @ref{--portability}.
3300
3301 The later usage is deprecated. It is retained for compatibility with
3302 the earlier versions of @GNUTAR{}. In the future releases
3303 @option{-o} will be equivalent to @option{--no-same-owner} only.
3304
3305 @item -p @tab @ref{--preserve-permissions}.
3306
3307 @item -r @tab @ref{--append}.
3308
3309 @item -s @tab @ref{--same-order}.
3310
3311 @item -t @tab @ref{--list}.
3312
3313 @item -u @tab @ref{--update}.
3314
3315 @item -v @tab @ref{--verbose}.
3316
3317 @item -w @tab @ref{--interactive}.
3318
3319 @item -x @tab @ref{--extract}.
3320
3321 @item -z @tab @ref{--gzip}.
3322
3323 @end multitable
3324
3325 @node help
3326 @section @GNUTAR{} documentation
3327
3328 @cindex Getting program version number
3329 @opindex version
3330 @cindex Version of the @command{tar} program
3331 Being careful, the first thing is really checking that you are using
3332 @GNUTAR{}, indeed. The @option{--version} option
3333 causes @command{tar} to print information about its name, version,
3334 origin and legal status, all on standard output, and then exit
3335 successfully. For example, @w{@samp{tar --version}} might print:
3336
3337 @smallexample
3338 tar (GNU tar) @value{VERSION}
3339 Copyright (C) 2006 Free Software Foundation, Inc.
3340 This is free software. You may redistribute copies of it under the terms
3341 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3342 There is NO WARRANTY, to the extent permitted by law.
3343
3344 Written by John Gilmore and Jay Fenlason.
3345 @end smallexample
3346
3347 @noindent
3348 The first occurrence of @samp{tar} in the result above is the program
3349 name in the package (for example, @command{rmt} is another program),
3350 while the second occurrence of @samp{tar} is the name of the package
3351 itself, containing possibly many programs. The package is currently
3352 named @samp{tar}, after the name of the main program it
3353 contains@footnote{There are plans to merge the @command{cpio} and
3354 @command{tar} packages into a single one which would be called
3355 @code{paxutils}. So, who knows if, one of this days, the
3356 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3357 paxutils) 3.2}}}.
3358
3359 @cindex Obtaining help
3360 @cindex Listing all @command{tar} options
3361 @xopindex{help, introduction}
3362 Another thing you might want to do is checking the spelling or meaning
3363 of some particular @command{tar} option, without resorting to this
3364 manual, for once you have carefully read it. @GNUTAR{}
3365 has a short help feature, triggerable through the
3366 @option{--help} option. By using this option, @command{tar} will
3367 print a usage message listing all available options on standard
3368 output, then exit successfully, without doing anything else and
3369 ignoring all other options. Even if this is only a brief summary, it
3370 may be several screens long. So, if you are not using some kind of
3371 scrollable window, you might prefer to use something like:
3372
3373 @smallexample
3374 $ @kbd{tar --help | less}
3375 @end smallexample
3376
3377 @noindent
3378 presuming, here, that you like using @command{less} for a pager. Other
3379 popular pagers are @command{more} and @command{pg}. If you know about some
3380 @var{keyword} which interests you and do not want to read all the
3381 @option{--help} output, another common idiom is doing:
3382
3383 @smallexample
3384 tar --help | grep @var{keyword}
3385 @end smallexample
3386
3387 @noindent
3388 for getting only the pertinent lines. Notice, however, that some
3389 @command{tar} options have long description lines and the above
3390 command will list only the first of them.
3391
3392 The exact look of the option summary displayed by @kbd{tar --help} is
3393 configurable. @xref{Configuring Help Summary}, for a detailed description.
3394
3395 @opindex usage
3396 If you only wish to check the spelling of an option, running @kbd{tar
3397 --usage} may be a better choice. This will display a terse list of
3398 @command{tar} option without accompanying explanations.
3399
3400 The short help output is quite succinct, and you might have to get
3401 back to the full documentation for precise points. If you are reading
3402 this paragraph, you already have the @command{tar} manual in some
3403 form. This manual is available in a variety of forms from
3404 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3405 distribution, provided you have @TeX{} already installed somewhere,
3406 and a laser printer around. Just configure the distribution, execute
3407 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3408 usual way (contact your local guru to know how). If @GNUTAR{}
3409 has been conveniently installed at your place, this
3410 manual is also available in interactive, hypertextual form as an Info
3411 file. Just call @w{@samp{info tar}} or, if you do not have the
3412 @command{info} program handy, use the Info reader provided within
3413 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3414
3415 There is currently no @code{man} page for @GNUTAR{}.
3416 If you observe such a @code{man} page on the system you are running,
3417 either it does not belong to @GNUTAR{}, or it has not
3418 been produced by @acronym{GNU}. Some package maintainers convert
3419 @kbd{tar --help} output to a man page, using @command{help2man}. In
3420 any case, please bear in mind that the authoritative source of
3421 information about @GNUTAR{} is this Texinfo documentation.
3422
3423 @node defaults
3424 @section Obtaining @GNUTAR{} default values
3425
3426 @opindex show-defaults
3427 @GNUTAR{} has some predefined defaults that are used when you do not
3428 explicitly specify another values. To obtain a list of such
3429 defaults, use @option{--show-defaults} option. This will output the
3430 values in the form of @command{tar} command line options:
3431
3432 @smallexample
3433 @group
3434 @kbd{tar --show-defaults}
3435 --format=gnu -f- -b20 --quoting-style=escape
3436 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3437 @end group
3438 @end smallexample
3439
3440 @noindent
3441 Notice, that this option outputs only one line. The example output above
3442 has been split to fit page boundaries.
3443
3444 @noindent
3445 The above output shows that this version of @GNUTAR{} defaults to
3446 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3447 output as the archive, if no @option{--file} option has been given
3448 (@pxref{file tutorial}), the default blocking factor is 20
3449 (@pxref{Blocking Factor}). It also shows the default locations where
3450 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3451
3452 @node verbose
3453 @section Checking @command{tar} progress
3454
3455 Typically, @command{tar} performs most operations without reporting any
3456 information to the user except error messages. When using @command{tar}
3457 with many options, particularly ones with complicated or
3458 difficult-to-predict behavior, it is possible to make serious mistakes.
3459 @command{tar} provides several options that make observing @command{tar}
3460 easier. These options cause @command{tar} to print information as it
3461 progresses in its job, and you might want to use them just for being
3462 more careful about what is going on, or merely for entertaining
3463 yourself. If you have encountered a problem when operating on an
3464 archive, however, you may need more information than just an error
3465 message in order to solve the problem. The following options can be
3466 helpful diagnostic tools.
3467
3468 @cindex Verbose operation
3469 @opindex verbose
3470 Normally, the @option{--list} (@option{-t}) command to list an archive
3471 prints just the file names (one per line) and the other commands are
3472 silent. When used with most operations, the @option{--verbose}
3473 (@option{-v}) option causes @command{tar} to print the name of each
3474 file or archive member as it is processed. This and the other options
3475 which make @command{tar} print status information can be useful in
3476 monitoring @command{tar}.
3477
3478 With @option{--create} or @option{--extract}, @option{--verbose} used
3479 once just prints the names of the files or members as they are processed.
3480 Using it twice causes @command{tar} to print a longer listing
3481 (@xref{verbose member listing}, for the description) for each member.
3482 Since @option{--list} already prints the names of the members,
3483 @option{--verbose} used once with @option{--list} causes @command{tar}
3484 to print an @samp{ls -l} type listing of the files in the archive.
3485 The following examples both extract members with long list output:
3486
3487 @smallexample
3488 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3489 $ @kbd{tar xvvf archive.tar}
3490 @end smallexample
3491
3492 Verbose output appears on the standard output except when an archive is
3493 being written to the standard output, as with @samp{tar --create
3494 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3495 installer let standard output be the default archive). In that case
3496 @command{tar} writes verbose output to the standard error stream.
3497
3498 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3499 verbose output to @var{file} rather than to standard output or standard
3500 error.
3501
3502 @anchor{totals}
3503 @cindex Obtaining total status information
3504 @opindex totals
3505 The @option{--totals} option causes @command{tar} to print on the
3506 standard error the total amount of bytes transferred when processing
3507 an archive. When creating or appending to an archive, this option
3508 prints the number of bytes written to the archive and the average
3509 speed at which they have been written, e.g.:
3510
3511 @smallexample
3512 @group
3513 $ @kbd{tar -c -f archive.tar --totals /home}
3514 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3515 @end group
3516 @end smallexample
3517
3518 When reading an archive, this option displays the number of bytes
3519 read:
3520
3521 @smallexample
3522 @group
3523 $ @kbd{tar -x -f archive.tar --totals}
3524 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3525 @end group
3526 @end smallexample
3527
3528 Finally, when deleting from an archive, the @option{--totals} option
3529 displays both numbers plus number of bytes removed from the archive:
3530
3531 @smallexample
3532 @group
3533 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3534 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3535 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3536 Total bytes deleted: 1474048
3537 @end group
3538 @end smallexample
3539
3540 You can also obtain this information on request. When
3541 @option{--totals} is used with an argument, this argument is
3542 interpreted as a symbolic name of a signal, upon delivery of which the
3543 statistics is to be printed:
3544
3545 @table @option
3546 @item --totals=@var{signo}
3547 Print statistics upon delivery of signal @var{signo}. Valid arguments
3548 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3549 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3550 accepted.
3551 @end table
3552
3553 Both forms of @option{--totals} option can be used simultaneously.
3554 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3555 extract all members from its default archive and print statistics
3556 after finishing the extraction, as well as when receiving signal
3557 @code{SIGUSR1}.
3558
3559 @anchor{Progress information}
3560 @cindex Progress information
3561 @opindex checkpoint
3562 The @option{--checkpoint} option prints an occasional message
3563 as @command{tar} reads or writes the archive. It is designed for
3564 those who don't need the more detailed (and voluminous) output of
3565 @option{--block-number} (@option{-R}), but do want visual confirmation
3566 that @command{tar} is actually making forward progress. By default it
3567 prints a message each 10 records read or written. This can be changed
3568 by giving it a numeric argument after an equal sign:
3569
3570 @smallexample
3571 $ @kbd{tar -c --checkpoint=1000} /var
3572 tar: Write checkpoint 1000
3573 tar: Write checkpoint 2000
3574 tar: Write checkpoint 3000
3575 @end smallexample
3576
3577 This example shows the default checkpoint message used by
3578 @command{tar}. If you place a dot immediately after the equal
3579 sign, it will print a @samp{.} at each checkpoint. For example:
3580
3581 @smallexample
3582 $ @kbd{tar -c --checkpoint=.1000} /var
3583 ...
3584 @end smallexample
3585
3586 @opindex show-omitted-dirs
3587 @anchor{show-omitted-dirs}
3588 The @option{--show-omitted-dirs} option, when reading an archive---with
3589 @option{--list} or @option{--extract}, for example---causes a message
3590 to be printed for each directory in the archive which is skipped.
3591 This happens regardless of the reason for skipping: the directory might
3592 not have been named on the command line (implicitly or explicitly),
3593 it might be excluded by the use of the
3594 @option{--exclude=@var{pattern}} option, or some other reason.
3595
3596 @opindex block-number
3597 @cindex Block number where error occurred
3598 @anchor{block-number}
3599 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3600 every message it would normally produce, the block number within the
3601 archive where the message was triggered. Also, supplementary messages
3602 are triggered when reading blocks full of NULs, or when hitting end of
3603 file on the archive. As of now, if the archive if properly terminated
3604 with a NUL block, the reading of the file may stop before end of file
3605 is met, so the position of end of file will not usually show when
3606 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3607 drains the archive before exiting when reading the
3608 archive from a pipe.
3609
3610 @cindex Error message, block number of
3611 This option is especially useful when reading damaged archives, since
3612 it helps pinpoint the damaged sections. It can also be used with
3613 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3614 choose among several backup tapes when retrieving a file later, in
3615 favor of the tape where the file appears earliest (closest to the
3616 front of the tape). @xref{backup}.
3617
3618 @node interactive
3619 @section Asking for Confirmation During Operations
3620 @cindex Interactive operation
3621
3622 Typically, @command{tar} carries out a command without stopping for
3623 further instructions. In some situations however, you may want to
3624 exclude some files and archive members from the operation (for instance
3625 if disk or storage space is tight). You can do this by excluding
3626 certain files automatically (@pxref{Choosing}), or by performing
3627 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3628 @command{tar} also accepts @option{--confirmation} for this option.
3629
3630 @opindex interactive
3631 When the @option{--interactive} (@option{-w}) option is specified, before
3632 reading, writing, or deleting files, @command{tar} first prints a message
3633 for each such file, telling what operation it intends to take, then asks
3634 for confirmation on the terminal. The actions which require
3635 confirmation include adding a file to the archive, extracting a file
3636 from the archive, deleting a file from the archive, and deleting a file
3637 from disk. To confirm the action, you must type a line of input
3638 beginning with @samp{y}. If your input line begins with anything other
3639 than @samp{y}, @command{tar} skips that file.
3640
3641 If @command{tar} is reading the archive from the standard input,
3642 @command{tar} opens the file @file{/dev/tty} to support the interactive
3643 communications.
3644
3645 Verbose output is normally sent to standard output, separate from
3646 other error messages. However, if the archive is produced directly
3647 on standard output, then verbose output is mixed with errors on
3648 @code{stderr}. Producing the archive on standard output may be used
3649 as a way to avoid using disk space, when the archive is soon to be
3650 consumed by another process reading it, say. Some people felt the need
3651 of producing an archive on stdout, still willing to segregate between
3652 verbose output and error output. A possible approach would be using a
3653 named pipe to receive the archive, and having the consumer process to
3654 read from that named pipe. This has the advantage of letting standard
3655 output free to receive verbose output, all separate from errors.
3656
3657 @node operations
3658 @chapter @GNUTAR{} Operations
3659
3660 @menu
3661 * Basic tar::
3662 * Advanced tar::
3663 * create options::
3664 * extract options::
3665 * backup::
3666 * Applications::
3667 * looking ahead::
3668 @end menu
3669
3670 @node Basic tar
3671 @section Basic @GNUTAR{} Operations
3672
3673 The basic @command{tar} operations, @option{--create} (@option{-c}),
3674 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3675 @option{-x}), are currently presented and described in the tutorial
3676 chapter of this manual. This section provides some complementary notes
3677 for these operations.
3678
3679 @table @option
3680 @xopindex{create, complementary notes}
3681 @item --create
3682 @itemx -c
3683
3684 Creating an empty archive would have some kind of elegance. One can
3685 initialize an empty archive and later use @option{--append}
3686 (@option{-r}) for adding all members. Some applications would not
3687 welcome making an exception in the way of adding the first archive
3688 member. On the other hand, many people reported that it is
3689 dangerously too easy for @command{tar} to destroy a magnetic tape with
3690 an empty archive@footnote{This is well described in @cite{Unix-haters
3691 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3692 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3693
3694 @enumerate
3695 @item
3696 Mistakingly using @code{create} instead of @code{extract}, when the
3697 intent was to extract the full contents of an archive. This error
3698 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3699 the QWERTY keyboard. Instead of being unpacked, the archive then
3700 gets wholly destroyed. When users speak about @dfn{exploding} an
3701 archive, they usually mean something else :-).
3702
3703 @item
3704 Forgetting the argument to @code{file}, when the intent was to create
3705 an archive with a single file in it. This error is likely because a
3706 tired user can easily add the @kbd{f} key to the cluster of option
3707 letters, by the mere force of habit, without realizing the full
3708 consequence of doing so. The usual consequence is that the single
3709 file, which was meant to be saved, is rather destroyed.
3710 @end enumerate
3711
3712 So, recognizing the likelihood and the catastrophic nature of these
3713 errors, @GNUTAR{} now takes some distance from elegance, and
3714 cowardly refuses to create an archive when @option{--create} option is
3715 given, there are no arguments besides options, and
3716 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3717 around the cautiousness of @GNUTAR{} and nevertheless create an
3718 archive with nothing in it, one may still use, as the value for the
3719 @option{--files-from} option, a file with no names in it, as shown in
3720 the following commands:
3721
3722 @smallexample
3723 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3724 @kbd{tar cfT empty-archive.tar /dev/null}
3725 @end smallexample
3726
3727 @xopindex{extract, complementary notes}
3728 @item --extract
3729 @itemx --get
3730 @itemx -x
3731
3732 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3733
3734 @item @option{--list} (@option{-t})
3735
3736 @GNUTAR{} now shows dates as @samp{1996-08-30},
3737 while it used to show them as @samp{Aug 30 1996}. Preferably,
3738 people should get used to ISO 8601 dates. Local American dates should
3739 be made available again with full date localization support, once
3740 ready. In the meantime, programs not being localizable for dates
3741 should prefer international dates, that's really the way to go.
3742
3743 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3744 are curious, it contains a detailed explanation of the ISO 8601 standard.
3745
3746 @end table
3747
3748 @node Advanced tar
3749 @section Advanced @GNUTAR{} Operations
3750
3751 Now that you have learned the basics of using @GNUTAR{}, you may want
3752 to learn about further ways in which @command{tar} can help you.
3753
3754 This chapter presents five, more advanced operations which you probably
3755 won't use on a daily basis, but which serve more specialized functions.
3756 We also explain the different styles of options and why you might want
3757 to use one or another, or a combination of them in your @command{tar}
3758 commands. Additionally, this chapter includes options which allow you to
3759 define the output from @command{tar} more carefully, and provide help and
3760 error correction in special circumstances.
3761
3762 @FIXME{check this after the chapter is actually revised to make sure
3763 it still introduces the info in the chapter correctly : ).}
3764
3765 @menu
3766 * Operations::
3767 * append::
3768 * update::
3769 * concatenate::
3770 * delete::
3771 * compare::
3772 @end menu
3773
3774 @node Operations
3775 @subsection The Five Advanced @command{tar} Operations
3776 @UNREVISED
3777
3778 In the last chapter, you learned about the first three operations to
3779 @command{tar}. This chapter presents the remaining five operations to
3780 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3781 @option{--delete}, and @option{--compare}.
3782
3783 You are not likely to use these operations as frequently as those
3784 covered in the last chapter; however, since they perform specialized
3785 functions, they are quite useful when you do need to use them. We
3786 will give examples using the same directory and files that you created
3787 in the last chapter. As you may recall, the directory is called
3788 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3789 @samp{rock}, and the two archive files you created are
3790 @samp{collection.tar} and @samp{music.tar}.
3791
3792 We will also use the archive files @samp{afiles.tar} and
3793 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3794 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3795 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3796
3797 Unless we state otherwise, all practicing you do and examples you follow
3798 in this chapter will take place in the @file{practice} directory that
3799 you created in the previous chapter; see @ref{prepare for examples}.
3800 (Below in this section, we will remind you of the state of the examples
3801 where the last chapter left them.)
3802
3803 The five operations that we will cover in this chapter are:
3804
3805 @table @option
3806 @item --append
3807 @itemx -r
3808 Add new entries to an archive that already exists.
3809 @item --update
3810 @itemx -r
3811 Add more recent copies of archive members to the end of an archive, if
3812 they exist.
3813 @item --concatenate
3814 @itemx --catenate
3815 @itemx -A
3816 Add one or more pre-existing archives to the end of another archive.
3817 @item --delete
3818 Delete items from an archive (does not work on tapes).
3819 @item --compare
3820 @itemx --diff
3821 @itemx -d
3822 Compare archive members to their counterparts in the file system.
3823 @end table
3824
3825 @node append
3826 @subsection How to Add Files to Existing Archives: @option{--append}
3827 @UNREVISED
3828
3829 @opindex append
3830 If you want to add files to an existing archive, you don't need to
3831 create a new archive; you can use @option{--append} (@option{-r}).
3832 The archive must already exist in order to use @option{--append}. (A
3833 related operation is the @option{--update} operation; you can use this
3834 to add newer versions of archive members to an existing archive. To learn how to
3835 do this with @option{--update}, @pxref{update}.)
3836
3837 If you use @option{--append} to add a file that has the same name as an
3838 archive member to an archive containing that archive member, then the
3839 old member is not deleted. What does happen, however, is somewhat
3840 complex. @command{tar} @emph{allows} you to have infinite number of files
3841 with the same name. Some operations treat these same-named members no
3842 differently than any other set of archive members: for example, if you
3843 view an archive with @option{--list} (@option{-t}), you will see all
3844 of those members listed, with their data modification times, owners, etc.
3845
3846 Other operations don't deal with these members as perfectly as you might
3847 prefer; if you were to use @option{--extract} to extract the archive,
3848 only the most recently added copy of a member with the same name as four
3849 other members would end up in the working directory. This is because
3850 @option{--extract} extracts an archive in the order the members appeared
3851 in the archive; the most recently archived members will be extracted
3852 last. Additionally, an extracted member will @emph{replace} a file of
3853 the same name which existed in the directory already, and @command{tar}
3854 will not prompt you about this@footnote{Unless you give it
3855 @option{--keep-old-files} option, or the disk copy is newer than the
3856 the one in the archive and you invoke @command{tar} with
3857 @option{--keep-newer-files} option}. Thus, only the most recently archived
3858 member will end up being extracted, as it will replace the one
3859 extracted before it, and so on.
3860
3861 There exists a special option that allows you to get around this
3862 behavior and extract (or list) only a particular copy of the file.
3863 This is @option{--occurrence} option. If you run @command{tar} with
3864 this option, it will extract only the first copy of the file. You
3865 may also give this option an argument specifying the number of
3866 copy to be extracted. Thus, for example if the archive
3867 @file{archive.tar} contained three copies of file @file{myfile}, then
3868 the command
3869
3870 @smallexample
3871 tar --extract --file archive.tar --occurrence=2 myfile
3872 @end smallexample
3873
3874 @noindent
3875 would extract only the second copy. @xref{Option
3876 Summary,---occurrence}, for the description of @option{--occurrence}
3877 option.
3878
3879 @FIXME{ hag -- you might want to incorporate some of the above into the
3880 MMwtSN node; not sure. i didn't know how to make it simpler...
3881
3882 There are a few ways to get around this. (maybe xref Multiple Members
3883 with the Same Name.}
3884
3885 @cindex Members, replacing with other members
3886 @cindex Replacing members with other members
3887 If you want to replace an archive member, use @option{--delete} to
3888 delete the member you want to remove from the archive, , and then use
3889 @option{--append} to add the member you want to be in the archive. Note
3890 that you can not change the order of the archive; the most recently
3891 added member will still appear last. In this sense, you cannot truly
3892 ``replace'' one member with another. (Replacing one member with another
3893 will not work on certain types of media, such as tapes; see @ref{delete}
3894 and @ref{Media}, for more information.)
3895
3896 @menu
3897 * appending files:: Appending Files to an Archive
3898 * multiple::
3899 @end menu
3900
3901 @node appending files
3902 @subsubsection Appending Files to an Archive
3903 @UNREVISED
3904 @cindex Adding files to an Archive
3905 @cindex Appending files to an Archive
3906 @cindex Archives, Appending files to
3907
3908 The simplest way to add a file to an already existing archive is the
3909 @option{--append} (@option{-r}) operation, which writes specified
3910 files into the archive whether or not they are already among the
3911 archived files.
3912
3913 When you use @option{--append}, you @emph{must} specify file name
3914 arguments, as there is no default. If you specify a file that already
3915 exists in the archive, another copy of the file will be added to the
3916 end of the archive. As with other operations, the member names of the
3917 newly added files will be exactly the same as their names given on the
3918 command line. The @option{--verbose} (@option{-v}) option will print
3919 out the names of the files as they are written into the archive.
3920
3921 @option{--append} cannot be performed on some tape drives, unfortunately,
3922 due to deficiencies in the formats those tape drives use. The archive
3923 must be a valid @command{tar} archive, or else the results of using this
3924 operation will be unpredictable. @xref{Media}.
3925
3926 To demonstrate using @option{--append} to add a file to an archive,
3927 create a file called @file{rock} in the @file{practice} directory.
3928 Make sure you are in the @file{practice} directory. Then, run the
3929 following @command{tar} command to add @file{rock} to
3930 @file{collection.tar}:
3931
3932 @smallexample
3933 $ @kbd{tar --append --file=collection.tar rock}
3934 @end smallexample
3935
3936 @noindent
3937 If you now use the @option{--list} (@option{-t}) operation, you will see that
3938 @file{rock} has been added to the archive:
3939
3940 @smallexample
3941 $ @kbd{tar --list --file=collection.tar}
3942 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3943 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3944 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3945 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3946 @end smallexample
3947
3948 @node multiple
3949 @subsubsection Multiple Members with the Same Name
3950
3951 You can use @option{--append} (@option{-r}) to add copies of files
3952 which have been updated since the archive was created. (However, we
3953 do not recommend doing this since there is another @command{tar}
3954 option called @option{--update}; @xref{update}, for more information.
3955 We describe this use of @option{--append} here for the sake of
3956 completeness.) When you extract the archive, the older version will
3957 be effectively lost. This works because files are extracted from an
3958 archive in the order in which they were archived. Thus, when the
3959 archive is extracted, a file archived later in time will replace a
3960 file of the same name which was archived earlier, even though the
3961 older version of the file will remain in the archive unless you delete
3962 all versions of the file.
3963
3964 Supposing you change the file @file{blues} and then append the changed
3965 version to @file{collection.tar}. As you saw above, the original
3966 @file{blues} is in the archive @file{collection.tar}. If you change the
3967 file and append the new version of the file to the archive, there will
3968 be two copies in the archive. When you extract the archive, the older
3969 version of the file will be extracted first, and then replaced by the
3970 newer version when it is extracted.
3971
3972 You can append the new, changed copy of the file @file{blues} to the
3973 archive in this way:
3974
3975 @smallexample
3976 $ @kbd{tar --append --verbose --file=collection.tar blues}
3977 blues
3978 @end smallexample
3979
3980 @noindent
3981 Because you specified the @option{--verbose} option, @command{tar} has
3982 printed the name of the file being appended as it was acted on. Now
3983 list the contents of the archive:
3984
3985 @smallexample
3986 $ @kbd{tar --list --verbose --file=collection.tar}
3987 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3988 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3989 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3990 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3991 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3992 @end smallexample
3993
3994 @noindent
3995 The newest version of @file{blues} is now at the end of the archive
3996 (note the different creation dates and file sizes). If you extract
3997 the archive, the older version of the file @file{blues} will be
3998 replaced by the newer version. You can confirm this by extracting
3999 the archive and running @samp{ls} on the directory.
4000
4001 If you wish to extract the first occurrence of the file @file{blues}
4002 from the archive, use @option{--occurrence} option, as shown in
4003 the following example:
4004
4005 @smallexample
4006 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4007 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4008 @end smallexample
4009
4010 @xref{Writing}, for more information on @option{--extract} and
4011 @xref{Option Summary, --occurrence}, for the description of
4012 @option{--occurrence} option.
4013
4014 @node update
4015 @subsection Updating an Archive
4016 @UNREVISED
4017 @cindex Updating an archive
4018
4019 @opindex update
4020 In the previous section, you learned how to use @option{--append} to
4021 add a file to an existing archive. A related operation is
4022 @option{--update} (@option{-u}). The @option{--update} operation
4023 updates a @command{tar} archive by comparing the date of the specified
4024 archive members against the date of the file with the same name. If
4025 the file has been modified more recently than the archive member, then
4026 the newer version of the file is added to the archive (as with
4027 @option{--append}).
4028
4029 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4030 The operation will fail.
4031
4032 @FIXME{other examples of media on which --update will fail? need to ask
4033 charles and/or mib/thomas/dave shevett..}
4034
4035 Both @option{--update} and @option{--append} work by adding to the end
4036 of the archive. When you extract a file from the archive, only the
4037 version stored last will wind up in the file system, unless you use
4038 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4039
4040 @menu
4041 * how to update::
4042 @end menu
4043
4044 @node how to update
4045 @subsubsection How to Update an Archive Using @option{--update}
4046
4047 You must use file name arguments with the @option{--update}
4048 (@option{-u}) operation. If you don't specify any files,
4049 @command{tar} won't act on any files and won't tell you that it didn't
4050 do anything (which may end up confusing you).
4051
4052 @c note: the above parenthetical added because in fact, this
4053 @c behavior just confused the author. :-)
4054
4055 To see the @option{--update} option at work, create a new file,
4056 @file{classical}, in your practice directory, and some extra text to the
4057 file @file{blues}, using any text editor. Then invoke @command{tar} with
4058 the @samp{update} operation and the @option{--verbose} (@option{-v})
4059 option specified, using the names of all the files in the practice
4060 directory as file name arguments:
4061
4062 @smallexample
4063 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4064 blues
4065 classical
4066 $
4067 @end smallexample
4068
4069 @noindent
4070 Because we have specified verbose mode, @command{tar} prints out the names
4071 of the files it is working on, which in this case are the names of the
4072 files that needed to be updated. If you run @samp{tar --list} and look
4073 at the archive, you will see @file{blues} and @file{classical} at its
4074 end. There will be a total of two versions of the member @samp{blues};
4075 the one at the end will be newer and larger, since you added text before
4076 updating it.
4077
4078 (The reason @command{tar} does not overwrite the older file when updating
4079 it is because writing to the middle of a section of tape is a difficult
4080 process. Tapes are not designed to go backward. @xref{Media}, for more
4081 information about tapes.
4082
4083 @option{--update} (@option{-u}) is not suitable for performing backups for two
4084 reasons: it does not change directory content entries, and it
4085 lengthens the archive every time it is used. The @GNUTAR{}
4086 options intended specifically for backups are more
4087 efficient. If you need to run backups, please consult @ref{Backups}.
4088
4089 @node concatenate
4090 @subsection Combining Archives with @option{--concatenate}
4091
4092 @cindex Adding archives to an archive
4093 @cindex Concatenating Archives
4094 @opindex concatenate
4095 @opindex catenate
4096 @c @cindex @option{-A} described
4097 Sometimes it may be convenient to add a second archive onto the end of
4098 an archive rather than adding individual files to the archive. To add
4099 one or more archives to the end of another archive, you should use the
4100 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4101
4102 To use @option{--concatenate}, give the first archive with
4103 @option{--file} option and name the rest of archives to be
4104 concatenated on the command line. The members, and their member
4105 names, will be copied verbatim from those archives to the first one.
4106 @footnote{This can cause multiple members to have the same name, for
4107 information on how this affects reading the archive, @ref{multiple}.}
4108 The new, concatenated archive will be called by the same name as the
4109 one given with the @option{--file} option. As usual, if you omit
4110 @option{--file}, @command{tar} will use the value of the environment
4111 variable @env{TAPE}, or, if this has not been set, the default archive name.
4112
4113 @FIXME{There is no way to specify a new name...}
4114
4115 To demonstrate how @option{--concatenate} works, create two small archives
4116 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4117 files from @file{practice}:
4118
4119 @smallexample
4120 $ @kbd{tar -cvf bluesrock.tar blues rock}
4121 blues
4122 rock
4123 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4124 folk
4125 jazz
4126 @end smallexample
4127
4128 @noindent
4129 If you like, You can run @samp{tar --list} to make sure the archives
4130 contain what they are supposed to:
4131
4132 @smallexample
4133 $ @kbd{tar -tvf bluesrock.tar}
4134 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4135 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4136 $ @kbd{tar -tvf jazzfolk.tar}
4137 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4138 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4139 @end smallexample
4140
4141 We can concatenate these two archives with @command{tar}:
4142
4143 @smallexample
4144 $ @kbd{cd ..}
4145 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4146 @end smallexample
4147
4148 If you now list the contents of the @file{bluesrock.tar}, you will see
4149 that now it also contains the archive members of @file{jazzfolk.tar}:
4150
4151 @smallexample
4152 $ @kbd{tar --list --file=bluesrock.tar}
4153 blues
4154 rock
4155 folk
4156 jazz
4157 @end smallexample
4158
4159 When you use @option{--concatenate}, the source and target archives must
4160 already exist and must have been created using compatible format
4161 parameters. Notice, that @command{tar} does not check whether the
4162 archives it concatenates have compatible formats, it does not
4163 even check if the files are really tar archives.
4164
4165 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4166 tape drives, due to deficiencies in the formats those tape drives use.
4167
4168 @cindex @code{concatenate} vs @command{cat}
4169 @cindex @command{cat} vs @code{concatenate}
4170 It may seem more intuitive to you to want or try to use @command{cat} to
4171 concatenate two archives instead of using the @option{--concatenate}
4172 operation; after all, @command{cat} is the utility for combining files.
4173
4174 However, @command{tar} archives incorporate an end-of-file marker which
4175 must be removed if the concatenated archives are to be read properly as
4176 one archive. @option{--concatenate} removes the end-of-archive marker
4177 from the target archive before each new archive is appended. If you use
4178 @command{cat} to combine the archives, the result will not be a valid
4179 @command{tar} format archive. If you need to retrieve files from an
4180 archive that was added to using the @command{cat} utility, use the
4181 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4182 information on dealing with archives improperly combined using the
4183 @command{cat} shell utility.
4184
4185 @node delete
4186 @subsection Removing Archive Members Using @option{--delete}
4187 @UNREVISED
4188 @cindex Deleting files from an archive
4189 @cindex Removing files from an archive
4190
4191 @opindex delete
4192 You can remove members from an archive by using the @option{--delete}
4193 option. Specify the name of the archive with @option{--file}
4194 (@option{-f}) and then specify the names of the members to be deleted;
4195 if you list no member names, nothing will be deleted. The
4196 @option{--verbose} option will cause @command{tar} to print the names
4197 of the members as they are deleted. As with @option{--extract}, you
4198 must give the exact member names when using @samp{tar --delete}.
4199 @option{--delete} will remove all versions of the named file from the
4200 archive. The @option{--delete} operation can run very slowly.
4201
4202 Unlike other operations, @option{--delete} has no short form.
4203
4204 @cindex Tapes, using @option{--delete} and
4205 @cindex Deleting from tape archives
4206 This operation will rewrite the archive. You can only use
4207 @option{--delete} on an archive if the archive device allows you to
4208 write to any point on the media, such as a disk; because of this, it
4209 does not work on magnetic tapes. Do not try to delete an archive member
4210 from a magnetic tape; the action will not succeed, and you will be
4211 likely to scramble the archive and damage your tape. There is no safe
4212 way (except by completely re-writing the archive) to delete files from
4213 most kinds of magnetic tape. @xref{Media}.
4214
4215 To delete all versions of the file @file{blues} from the archive
4216 @file{collection.tar} in the @file{practice} directory, make sure you
4217 are in that directory, and then,
4218
4219 @smallexample
4220 $ @kbd{tar --list --file=collection.tar}
4221 blues
4222 folk
4223 jazz
4224 rock
4225 $ @kbd{tar --delete --file=collection.tar blues}
4226 $ @kbd{tar --list --file=collection.tar}
4227 folk
4228 jazz
4229 rock
4230 $
4231 @end smallexample
4232
4233 @FIXME{Check if the above listing is actually produced after running
4234 all the examples on collection.tar.}
4235
4236 The @option{--delete} option has been reported to work properly when
4237 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4238
4239 @node compare
4240 @subsection Comparing Archive Members with the File System
4241 @cindex Verifying the currency of an archive
4242 @UNREVISED
4243
4244 @opindex compare
4245 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4246 specified archive members against files with the same names, and then
4247 reports differences in file size, mode, owner, modification date and
4248 contents. You should @emph{only} specify archive member names, not file
4249 names. If you do not name any members, then @command{tar} will compare the
4250 entire archive. If a file is represented in the archive but does not
4251 exist in the file system, @command{tar} reports a difference.
4252
4253 You have to specify the record size of the archive when modifying an
4254 archive with a non-default record size.
4255
4256 @command{tar} ignores files in the file system that do not have
4257 corresponding members in the archive.
4258
4259 The following example compares the archive members @file{rock},
4260 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4261 files of the same name in the file system. (Note that there is no file,
4262 @file{funk}; @command{tar} will report an error message.)
4263
4264 @smallexample
4265 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4266 rock
4267 blues
4268 tar: funk not found in archive
4269 @end smallexample
4270
4271 The spirit behind the @option{--compare} (@option{--diff},
4272 @option{-d}) option is to check whether the archive represents the
4273 current state of files on disk, more than validating the integrity of
4274 the archive media. For this later goal, @xref{verify}.
4275
4276 @node create options
4277 @section Options Used by @option{--create}
4278
4279 @xopindex{create, additional options}
4280 The previous chapter described the basics of how to use
4281 @option{--create} (@option{-c}) to create an archive from a set of files.
4282 @xref{create}. This section described advanced options to be used with
4283 @option{--create}.
4284
4285 @menu
4286 * override:: Overriding File Metadata.
4287 * Ignore Failed Read::
4288 @end menu
4289
4290 @node override
4291 @subsection Overriding File Metadata
4292
4293 As described above, a @command{tar} archive keeps, for each member it contains,
4294 its @dfn{metadata}, such as modification time, mode and ownership of
4295 the file. @GNUTAR{} allows to replace these data with other values
4296 when adding files to the archive. The options described in this
4297 section affect creation of archives of any type. For POSIX archives,
4298 see also @ref{PAX keywords}, for additional ways of controlling
4299 metadata, stored in the archive.
4300
4301 @table @option
4302 @opindex mode
4303 @item --mode=@var{permissions}
4304
4305 When adding files to an archive, @command{tar} will use
4306 @var{permissions} for the archive members, rather than the permissions
4307 from the files. @var{permissions} can be specified either as an octal
4308 number or as symbolic permissions, like with
4309 @command{chmod} (@xref{File permissions, Permissions, File
4310 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4311 also has useful information for those not being overly familiar with
4312 the UNIX permission system). Using latter syntax allows for
4313 more flexibility. For example, the value @samp{a+rw} adds read and write
4314 permissions for everybody, while retaining executable bits on directories
4315 or on any other file already marked as executable:
4316
4317 @smallexample
4318 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4319 @end smallexample
4320
4321 @item --mtime=@var{date}
4322 @opindex mtime
4323
4324 When adding files to an archive, @command{tar} will use @var{date} as
4325 the modification time of members when creating archives, instead of
4326 their actual modification times. The argument @var{date} can be
4327 either a textual date representation in almost arbitrary format
4328 (@pxref{Date input formats}) or a name of the existing file, starting
4329 with @samp{/} or @samp{.}. In the latter case, the modification time
4330 of that file will be used.
4331
4332 The following example will set the modification date to 00:00:00 UTC,
4333 January 1, 1970:
4334
4335 @smallexample
4336 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4337 @end smallexample
4338
4339 @noindent
4340 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4341 will try to convert the specified date back to its textual
4342 representation and compare it with the one given with
4343 @option{--mtime} options. If the two dates differ, @command{tar} will
4344 print a warning saying what date it will use. This is to help user
4345 ensure he is using the right date.
4346
4347 For example:
4348
4349 @smallexample
4350 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4351 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4352 13:06:29.152478
4353 @dots{}
4354 @end smallexample
4355
4356 @item --owner=@var{user}
4357 @opindex owner
4358
4359 Specifies that @command{tar} should use @var{user} as the owner of members
4360 when creating archives, instead of the user associated with the source
4361 file. The argument @var{user} can be either an existing user symbolic
4362 name, or a decimal numeric user ID.
4363
4364 There is no value indicating a missing number, and @samp{0} usually means
4365 @code{root}. Some people like to force @samp{0} as the value to offer in
4366 their distributions for the owner of files, because the @code{root} user is
4367 anonymous anyway, so that might as well be the owner of anonymous
4368 archives. For example:
4369
4370 @smallexample
4371 @group
4372 $ @kbd{tar -c -f archive.tar --owner=0 .}
4373 # @r{Or:}
4374 $ @kbd{tar -c -f archive.tar --owner=root .}
4375 @end group
4376 @end smallexample
4377
4378 @item --group=@var{group}
4379 @opindex group
4380
4381 Files added to the @command{tar} archive will have a group id of @var{group},
4382 rather than the group from the source file. The argument @var{group}
4383 can be either an existing group symbolic name, or a decimal numeric group ID.
4384 @end table
4385
4386 @node Ignore Failed Read
4387 @subsection Ignore Fail Read
4388
4389 @table @option
4390 @item --ignore-failed-read
4391 @opindex ignore-failed-read
4392 Do not exit with nonzero on unreadable files or directories.
4393 @end table
4394
4395 @node extract options
4396 @section Options Used by @option{--extract}
4397 @UNREVISED
4398
4399 @xopindex{extract, additional options}
4400 The previous chapter showed how to use @option{--extract} to extract
4401 an archive into the file system. Various options cause @command{tar} to
4402 extract more information than just file contents, such as the owner,
4403 the permissions, the modification date, and so forth. This section
4404 presents options to be used with @option{--extract} when certain special
4405 considerations arise. You may review the information presented in
4406 @ref{extract} for more basic information about the
4407 @option{--extract} operation.
4408
4409 @menu
4410 * Reading:: Options to Help Read Archives
4411 * Writing:: Changing How @command{tar} Writes Files
4412 * Scarce:: Coping with Scarce Resources
4413 @end menu
4414
4415 @node Reading
4416 @subsection Options to Help Read Archives
4417 @cindex Options when reading archives
4418 @UNREVISED
4419
4420 @cindex Reading incomplete records
4421 @cindex Records, incomplete
4422 @opindex read-full-records
4423 Normally, @command{tar} will request data in full record increments from
4424 an archive storage device. If the device cannot return a full record,
4425 @command{tar} will report an error. However, some devices do not always
4426 return full records, or do not require the last record of an archive to
4427 be padded out to the next record boundary. To keep reading until you
4428 obtain a full record, or to accept an incomplete record if it contains
4429 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4430 in conjunction with the @option{--extract} or @option{--list} operations.
4431 @xref{Blocking}.
4432
4433 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4434 @command{tar} reads an archive from standard input, or from a remote
4435 machine. This is because on BSD Unix systems, attempting to read a
4436 pipe returns however much happens to be in the pipe, even if it is
4437 less than was requested. If this option were not enabled, @command{tar}
4438 would fail as soon as it read an incomplete record from the pipe.
4439
4440 If you're not sure of the blocking factor of an archive, you can
4441 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4442 @option{--blocking-factor=@var{512-size}} (@option{-b
4443 @var{512-size}}), using a blocking factor larger than what the archive
4444 uses. This lets you avoid having to determine the blocking factor
4445 of an archive. @xref{Blocking Factor}.
4446
4447 @menu
4448 * read full records::
4449 * Ignore Zeros::
4450 @end menu
4451
4452 @node read full records
4453 @unnumberedsubsubsec Reading Full Records
4454
4455 @FIXME{need sentence or so of intro here}
4456
4457 @table @option
4458 @opindex read-full-records
4459 @item --read-full-records
4460 @item -B
4461 Use in conjunction with @option{--extract} (@option{--get},
4462 @option{-x}) to read an archive which contains incomplete records, or
4463 one which has a blocking factor less than the one specified.
4464 @end table
4465
4466 @node Ignore Zeros
4467 @unnumberedsubsubsec Ignoring Blocks of Zeros
4468
4469 @cindex End-of-archive blocks, ignoring
4470 @cindex Ignoring end-of-archive blocks
4471 @opindex ignore-zeros
4472 Normally, @command{tar} stops reading when it encounters a block of zeros
4473 between file entries (which usually indicates the end of the archive).
4474 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4475 completely read an archive which contains a block of zeros before the
4476 end (i.e., a damaged archive, or one that was created by concatenating
4477 several archives together).
4478
4479 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4480 versions of @command{tar} write garbage after the end-of-archive entry,
4481 since that part of the media is never supposed to be read. @GNUTAR{}
4482 does not write after the end of an archive, but seeks to
4483 maintain compatibility among archiving utilities.
4484
4485 @table @option
4486 @item --ignore-zeros
4487 @itemx -i
4488 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4489 encountered while reading an archive. Use in conjunction with
4490 @option{--extract} or @option{--list}.
4491 @end table
4492
4493 @node Writing
4494 @subsection Changing How @command{tar} Writes Files
4495 @UNREVISED
4496
4497 @FIXME{Introductory paragraph}
4498
4499 @menu
4500 * Dealing with Old Files::
4501 * Overwrite Old Files::
4502 * Keep Old Files::
4503 * Keep Newer Files::
4504 * Unlink First::
4505 * Recursive Unlink::
4506 * Data Modification Times::
4507 * Setting Access Permissions::
4508 * Directory Modification Times and Permissions::
4509 * Writing to Standard Output::
4510 * Writing to an External Program::
4511 * remove files::
4512 @end menu
4513
4514 @node Dealing with Old Files
4515 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4516
4517 @xopindex{overwrite-dir, introduced}
4518 When extracting files, if @command{tar} discovers that the extracted
4519 file already exists, it normally replaces the file by removing it before
4520 extracting it, to prevent confusion in the presence of hard or symbolic
4521 links. (If the existing file is a symbolic link, it is removed, not
4522 followed.) However, if a directory cannot be removed because it is
4523 nonempty, @command{tar} normally overwrites its metadata (ownership,
4524 permission, etc.). The @option{--overwrite-dir} option enables this
4525 default behavior. To be more cautious and preserve the metadata of
4526 such a directory, use the @option{--no-overwrite-dir} option.
4527
4528 @cindex Overwriting old files, prevention
4529 @xopindex{keep-old-files, introduced}
4530 To be even more cautious and prevent existing files from being replaced, use
4531 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4532 to replace or update a file that already exists, i.e., a file with the
4533 same name as an archive member prevents extraction of that archive
4534 member. Instead, it reports an error.
4535
4536 @xopindex{overwrite, introduced}
4537 To be more aggressive about altering existing files, use the
4538 @option{--overwrite} option. It causes @command{tar} to overwrite
4539 existing files and to follow existing symbolic links when extracting.
4540
4541 @cindex Protecting old files
4542 Some people argue that @GNUTAR{} should not hesitate
4543 to overwrite files with other files when extracting. When extracting
4544 a @command{tar} archive, they expect to see a faithful copy of the
4545 state of the file system when the archive was created. It is debatable
4546 that this would always be a proper behavior. For example, suppose one
4547 has an archive in which @file{usr/local} is a link to
4548 @file{usr/local2}. Since then, maybe the site removed the link and
4549 renamed the whole hierarchy from @file{/usr/local2} to
4550 @file{/usr/local}. Such things happen all the time. I guess it would
4551 not be welcome at all that @GNUTAR{} removes the
4552 whole hierarchy just to make room for the link to be reinstated
4553 (unless it @emph{also} simultaneously restores the full
4554 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4555 able to remove a whole hierarchy to reestablish a symbolic link, for
4556 example, but @emph{only if} @option{--recursive-unlink} is specified
4557 to allow this behavior. In any case, single files are silently
4558 removed.
4559
4560 @xopindex{unlink-first, introduced}
4561 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4562 some cases by causing @command{tar} to remove files unconditionally
4563 before extracting them.
4564
4565 @node Overwrite Old Files
4566 @unnumberedsubsubsec Overwrite Old Files
4567
4568 @table @option
4569 @opindex overwrite
4570 @item --overwrite
4571 Overwrite existing files and directory metadata when extracting files
4572 from an archive.
4573
4574 This causes @command{tar} to write extracted files into the file system without
4575 regard to the files already on the system; i.e., files with the same
4576 names as archive members are overwritten when the archive is extracted.
4577 It also causes @command{tar} to extract the ownership, permissions,
4578 and time stamps onto any preexisting files or directories.
4579 If the name of a corresponding file name is a symbolic link, the file
4580 pointed to by the symbolic link will be overwritten instead of the
4581 symbolic link itself (if this is possible). Moreover, special devices,
4582 empty directories and even symbolic links are automatically removed if
4583 they are in the way of extraction.
4584
4585 Be careful when using the @option{--overwrite} option, particularly when
4586 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4587 can change the contents, ownership or permissions of any file on your
4588 system. Also, many systems do not take kindly to overwriting files that
4589 are currently being executed.
4590
4591 @opindex overwrite-dir
4592 @item --overwrite-dir
4593 Overwrite the metadata of directories when extracting files from an
4594 archive, but remove other files before extracting.
4595 @end table
4596
4597 @node Keep Old Files
4598 @unnumberedsubsubsec Keep Old Files
4599
4600 @table @option
4601 @opindex keep-old-files
4602 @item --keep-old-files
4603 @itemx -k
4604 Do not replace existing files from archive. The
4605 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4606 from replacing existing files with files with the same name from the
4607 archive. The @option{--keep-old-files} option is meaningless with
4608 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4609 files in the file system during extraction.
4610 @end table
4611
4612 @node Keep Newer Files
4613 @unnumberedsubsubsec Keep Newer Files
4614
4615 @table @option
4616 @opindex keep-newer-files
4617 @item --keep-newer-files
4618 Do not replace existing files that are newer than their archive
4619 copies. This option is meaningless with @option{--list} (@option{-t}).
4620 @end table
4621
4622 @node Unlink First
4623 @unnumberedsubsubsec Unlink First
4624
4625 @table @option
4626 @opindex unlink-first
4627 @item --unlink-first
4628 @itemx -U
4629 Remove files before extracting over them.
4630 This can make @command{tar} run a bit faster if you know in advance
4631 that the extracted files all need to be removed. Normally this option
4632 slows @command{tar} down slightly, so it is disabled by default.
4633 @end table
4634
4635 @node Recursive Unlink
4636 @unnumberedsubsubsec Recursive Unlink
4637
4638 @table @option
4639 @opindex recursive-unlink
4640 @item --recursive-unlink
4641 When this option is specified, try removing files and directory hierarchies
4642 before extracting over them. @emph{This is a dangerous option!}
4643 @end table
4644
4645 If you specify the @option{--recursive-unlink} option,
4646 @command{tar} removes @emph{anything} that keeps you from extracting a file
4647 as far as current permissions will allow it. This could include removal
4648 of the contents of a full directory hierarchy.
4649
4650 @node Data Modification Times
4651 @unnumberedsubsubsec Setting Data Modification Times
4652
4653 @cindex Data modification times of extracted files
4654 @cindex Modification times of extracted files
4655 Normally, @command{tar} sets the data modification times of extracted
4656 files to the corresponding times recorded for the files in the archive, but
4657 limits the permissions of extracted files by the current @code{umask}
4658 setting.
4659
4660 To set the data modification times of extracted files to the time when
4661 the files were extracted, use the @option{--touch} (@option{-m}) option in
4662 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4663
4664 @table @option
4665 @opindex touch
4666 @item --touch
4667 @itemx -m
4668 Sets the data modification time of extracted archive members to the time
4669 they were extracted, not the time recorded for them in the archive.
4670 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4671 @end table
4672
4673 @node Setting Access Permissions
4674 @unnumberedsubsubsec Setting Access Permissions
4675
4676 @cindex Permissions of extracted files
4677 @cindex Modes of extracted files
4678 To set the modes (access permissions) of extracted files to those
4679 recorded for those files in the archive, use @option{--same-permissions}
4680 in conjunction with the @option{--extract} (@option{--get},
4681 @option{-x}) operation.
4682
4683 @table @option
4684 @opindex preserve-permissions
4685 @opindex same-permissions
4686 @item --preserve-permissions
4687 @itemx --same-permissions
4688 @c @itemx --ignore-umask
4689 @itemx -p
4690 Set modes of extracted archive members to those recorded in the
4691 archive, instead of current umask settings. Use in conjunction with
4692 @option{--extract} (@option{--get}, @option{-x}).
4693 @end table
4694
4695 @node Directory Modification Times and Permissions
4696 @unnumberedsubsubsec Directory Modification Times and Permissions
4697
4698 After successfully extracting a file member, @GNUTAR{} normally
4699 restores its permissions and modification times, as described in the
4700 previous sections. This cannot be done for directories, because
4701 after extracting a directory @command{tar} will almost certainly
4702 extract files into that directory and this will cause the directory
4703 modification time to be updated. Moreover, restoring that directory
4704 permissions may not permit file creation within it. Thus, restoring
4705 directory permissions and modification times must be delayed at least
4706 until all files have been extracted into that directory. @GNUTAR{}
4707 restores directories using the following approach.
4708
4709 The extracted directories are created with the mode specified in the
4710 archive, as modified by the umask of the user, which gives sufficient
4711 permissions to allow file creation. The meta-information about the
4712 directory is recorded in the temporary list of directories. When
4713 preparing to extract next archive member, @GNUTAR{} checks if the
4714 directory prefix of this file contains the remembered directory. If
4715 it does not, the program assumes that all files have been extracted
4716 into that directory, restores its modification time and permissions
4717 and removes its entry from the internal list. This approach allows
4718 to correctly restore directory meta-information in the majority of
4719 cases, while keeping memory requirements sufficiently small. It is
4720 based on the fact, that most @command{tar} archives use the predefined
4721 order of members: first the directory, then all the files and
4722 subdirectories in that directory.
4723
4724 However, this is not always true. The most important exception are
4725 incremental archives (@pxref{Incremental Dumps}). The member order in
4726 an incremental archive is reversed: first all directory members are
4727 stored, followed by other (non-directory) members. So, when extracting
4728 from incremental archives, @GNUTAR{} alters the above procedure. It
4729 remembers all restored directories, and restores their meta-data
4730 only after the entire archive has been processed. Notice, that you do
4731 not need to specify any special options for that, as @GNUTAR{}
4732 automatically detects archives in incremental format.
4733
4734 There may be cases, when such processing is required for normal archives
4735 too. Consider the following example:
4736
4737 @smallexample
4738 @group
4739 $ @kbd{tar --no-recursion -cvf archive \
4740 foo foo/file1 bar bar/file foo/file2}
4741 foo/
4742 foo/file1
4743 bar/
4744 bar/file
4745 foo/file2
4746 @end group
4747 @end smallexample
4748
4749 During the normal operation, after encountering @file{bar}
4750 @GNUTAR{} will assume that all files from the directory @file{foo}
4751 were already extracted and will therefore restore its timestamp and
4752 permission bits. However, after extracting @file{foo/file2} the
4753 directory timestamp will be offset again.
4754
4755 To correctly restore directory meta-information in such cases, use
4756 @option{delay-directory-restore} command line option:
4757
4758 @table @option
4759 @opindex delay-directory-restore
4760 @item --delay-directory-restore
4761 Delays restoring of the modification times and permissions of extracted
4762 directories until the end of extraction. This way, correct
4763 meta-information is restored even if the archive has unusual member
4764 ordering.
4765
4766 @opindex no-delay-directory-restore
4767 @item --no-delay-directory-restore
4768 Cancel the effect of the previous @option{--delay-directory-restore}.
4769 Use this option if you have used @option{--delay-directory-restore} in
4770 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4771 temporarily disable it.
4772 @end table
4773
4774 @node Writing to Standard Output
4775 @unnumberedsubsubsec Writing to Standard Output
4776
4777 @cindex Writing extracted files to standard output
4778 @cindex Standard output, writing extracted files to
4779 To write the extracted files to the standard output, instead of
4780 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4781 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4782 extracting files to send them through a pipe, and do not need to
4783 preserve them in the file system. If you extract multiple members,
4784 they appear on standard output concatenated, in the order they are
4785 found in the archive.
4786
4787 @table @option
4788 @opindex to-stdout
4789 @item --to-stdout
4790 @itemx -O
4791 Writes files to the standard output. Use only in conjunction with
4792 @option{--extract} (@option{--get}, @option{-x}). When this option is
4793 used, instead of creating the files specified, @command{tar} writes
4794 the contents of the files extracted to its standard output. This may
4795 be useful if you are only extracting the files in order to send them
4796 through a pipe. This option is meaningless with @option{--list}
4797 (@option{-t}).
4798 @end table
4799
4800 This can be useful, for example, if you have a tar archive containing
4801 a big file and don't want to store the file on disk before processing
4802 it. You can use a command like this:
4803
4804 @smallexample
4805 tar -xOzf foo.tgz bigfile | process
4806 @end smallexample
4807
4808 or even like this if you want to process the concatenation of the files:
4809
4810 @smallexample
4811 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4812 @end smallexample
4813
4814 However, @option{--to-command} may be more convenient for use with
4815 multiple files. See the next section.
4816
4817 @node Writing to an External Program
4818 @unnumberedsubsubsec Writing to an External Program
4819
4820 You can instruct @command{tar} to send the contents of each extracted
4821 file to the standard input of an external program:
4822
4823 @table @option
4824 @opindex to-command
4825 @item --to-command=@var{command}
4826 Extract files and pipe their contents to the standard input of
4827 @var{command}. When this option is used, instead of creating the
4828 files specified, @command{tar} invokes @var{command} and pipes the
4829 contents of the files to its standard output. @var{Command} may
4830 contain command line arguments. The program is executed via
4831 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4832 extracted. Non-regular files (directories, etc.) are ignored when this
4833 option is used.
4834 @end table
4835
4836 The command can obtain the information about the file it processes
4837 from the following environment variables:
4838
4839 @table @var
4840 @vrindex TAR_FILETYPE, to-command environment
4841 @item TAR_FILETYPE
4842 Type of the file. It is a single letter with the following meaning:
4843
4844 @multitable @columnfractions 0.10 0.90
4845 @item f @tab Regular file
4846 @item d @tab Directory
4847 @item l @tab Symbolic link
4848 @item h @tab Hard link
4849 @item b @tab Block device
4850 @item c @tab Character device
4851 @end multitable
4852
4853 Currently only regular files are supported.
4854
4855 @vrindex TAR_MODE, to-command environment
4856 @item TAR_MODE
4857 File mode, an octal number.
4858
4859 @vrindex TAR_FILENAME, to-command environment
4860 @item TAR_FILENAME
4861 The name of the file.
4862
4863 @vrindex TAR_REALNAME, to-command environment
4864 @item TAR_REALNAME
4865 Name of the file as stored in the archive.
4866
4867 @vrindex TAR_UNAME, to-command environment
4868 @item TAR_UNAME
4869 Name of the file owner.
4870
4871 @vrindex TAR_GNAME, to-command environment
4872 @item TAR_GNAME
4873 Name of the file owner group.
4874
4875 @vrindex TAR_ATIME, to-command environment
4876 @item TAR_ATIME
4877 Time of last access. It is a decimal number, representing seconds
4878 since the epoch. If the archive provides times with nanosecond
4879 precision, the nanoseconds are appended to the timestamp after a
4880 decimal point.
4881
4882 @vrindex TAR_MTIME, to-command environment
4883 @item TAR_MTIME
4884 Time of last modification.
4885
4886 @vrindex TAR_CTIME, to-command environment
4887 @item TAR_CTIME
4888 Time of last status change.
4889
4890 @vrindex TAR_SIZE, to-command environment
4891 @item TAR_SIZE
4892 Size of the file.
4893
4894 @vrindex TAR_UID, to-command environment
4895 @item TAR_UID
4896 UID of the file owner.
4897
4898 @vrindex TAR_GID, to-command environment
4899 @item TAR_GID
4900 GID of the file owner.
4901 @end table
4902
4903 In addition to these variables, @env{TAR_VERSION} contains the
4904 @GNUTAR{} version number.
4905
4906 If @var{command} exits with a non-0 status, @command{tar} will print
4907 an error message similar to the following:
4908
4909 @smallexample
4910 tar: 2345: Child returned status 1
4911 @end smallexample
4912
4913 Here, @samp{2345} is the PID of the finished process.
4914
4915 If this behavior is not wanted, use @option{--ignore-command-error}:
4916
4917 @table @option
4918 @opindex ignore-command-error
4919 @item --ignore-command-error
4920 Ignore exit codes of subprocesses. Notice that if the program
4921 exits on signal or otherwise terminates abnormally, the error message
4922 will be printed even if this option is used.
4923
4924 @opindex no-ignore-command-error
4925 @item --no-ignore-command-error
4926 Cancel the effect of any previous @option{--ignore-command-error}
4927 option. This option is useful if you have set
4928 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4929 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4930 @end table
4931
4932 @node remove files
4933 @unnumberedsubsubsec Removing Files
4934
4935 @FIXME{The section is too terse. Something more to add? An example,
4936 maybe?}
4937
4938 @table @option
4939 @opindex remove-files
4940 @item --remove-files
4941 Remove files after adding them to the archive.
4942 @end table
4943
4944 @node Scarce
4945 @subsection Coping with Scarce Resources
4946 @UNREVISED
4947
4948 @cindex Small memory
4949 @cindex Running out of space
4950
4951 @menu
4952 * Starting File::
4953 * Same Order::
4954 @end menu
4955
4956 @node Starting File
4957 @unnumberedsubsubsec Starting File
4958
4959 @table @option
4960 @opindex starting-file
4961 @item --starting-file=@var{name}
4962 @itemx -K @var{name}
4963 Starts an operation in the middle of an archive. Use in conjunction
4964 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4965 @end table
4966
4967 @cindex Middle of the archive, starting in the
4968 If a previous attempt to extract files failed due to lack of disk
4969 space, you can use @option{--starting-file=@var{name}} (@option{-K
4970 @var{name}}) to start extracting only after member @var{name} of the
4971 archive. This assumes, of course, that there is now free space, or
4972 that you are now extracting into a different file system. (You could
4973 also choose to suspend @command{tar}, remove unnecessary files from
4974 the file system, and then restart the same @command{tar} operation.
4975 In this case, @option{--starting-file} is not necessary.
4976 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4977
4978 @node Same Order
4979 @unnumberedsubsubsec Same Order
4980
4981 @table @option
4982 @cindex Large lists of file names on small machines
4983 @opindex same-order
4984 @opindex preserve-order
4985 @item --same-order
4986 @itemx --preserve-order
4987 @itemx -s
4988 To process large lists of file names on machines with small amounts of
4989 memory. Use in conjunction with @option{--compare} (@option{--diff},
4990 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4991 (@option{--get}, @option{-x}).
4992 @end table
4993
4994 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4995 names to be listed or extracted is sorted in the same order as the
4996 files in the archive. This allows a large list of names to be used,
4997 even on a small machine that would not otherwise be able to hold all
4998 the names in memory at the same time. Such a sorted list can easily be
4999 created by running @samp{tar -t} on the archive and editing its output.
5000
5001 This option is probably never needed on modern computer systems.
5002
5003 @node backup
5004 @section Backup options
5005
5006 @cindex backup options
5007
5008 @GNUTAR{} offers options for making backups of files
5009 before writing new versions. These options control the details of
5010 these backups. They may apply to the archive itself before it is
5011 created or rewritten, as well as individual extracted members. Other
5012 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5013 and @command{mv}, for example) offer similar options.
5014
5015 Backup options may prove unexpectedly useful when extracting archives
5016 containing many members having identical name, or when extracting archives
5017 on systems having file name limitations, making different members appear
5018 has having similar names through the side-effect of name truncation.
5019 (This is true only if we have a good scheme for truncated backup names,
5020 which I'm not sure at all: I suspect work is needed in this area.)
5021 When any existing file is backed up before being overwritten by extraction,
5022 then clashing files are automatically be renamed to be unique, and the
5023 true name is kept for only the last file of a series of clashing files.
5024 By using verbose mode, users may track exactly what happens.
5025
5026 At the detail level, some decisions are still experimental, and may
5027 change in the future, we are waiting comments from our users. So, please
5028 do not learn to depend blindly on the details of the backup features.
5029 For example, currently, directories themselves are never renamed through
5030 using these options, so, extracting a file over a directory still has
5031 good chances to fail. Also, backup options apply to created archives,
5032 not only to extracted members. For created archives, backups will not
5033 be attempted when the archive is a block or character device, or when it
5034 refers to a remote file.
5035
5036 For the sake of simplicity and efficiency, backups are made by renaming old
5037 files prior to creation or extraction, and not by copying. The original
5038 name is restored if the file creation fails. If a failure occurs after a
5039 partial extraction of a file, both the backup and the partially extracted
5040 file are kept.
5041
5042 @table @samp
5043 @item --backup[=@var{method}]
5044 @opindex backup
5045 @vindex VERSION_CONTROL
5046 @cindex backups
5047 Back up files that are about to be overwritten or removed.
5048 Without this option, the original versions are destroyed.
5049
5050 Use @var{method} to determine the type of backups made.
5051 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5052 environment variable. And if @env{VERSION_CONTROL} is not set,
5053 use the @samp{existing} method.
5054
5055 @vindex version-control @r{Emacs variable}
5056 This option corresponds to the Emacs variable @samp{version-control};
5057 the same values for @var{method} are accepted as in Emacs. This option
5058 also allows more descriptive names. The valid @var{method}s are:
5059
5060 @table @samp
5061 @item t
5062 @itemx numbered
5063 @cindex numbered @r{backup method}
5064 Always make numbered backups.
5065
5066 @item nil
5067 @itemx existing
5068 @cindex existing @r{backup method}
5069 Make numbered backups of files that already have them, simple backups
5070 of the others.
5071
5072 @item never
5073 @itemx simple
5074 @cindex simple @r{backup method}
5075 Always make simple backups.
5076
5077 @end table
5078
5079 @item --suffix=@var{suffix}
5080 @opindex suffix
5081 @cindex backup suffix
5082 @vindex SIMPLE_BACKUP_SUFFIX
5083 Append @var{suffix} to each backup file made with @option{--backup}. If this
5084 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5085 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5086 set, the default is @samp{~}, just as in Emacs.
5087
5088 @end table
5089
5090 @node Applications
5091 @section Notable @command{tar} Usages
5092 @UNREVISED
5093
5094 @FIXME{Using Unix file linking capability to recreate directory
5095 structures---linking files into one subdirectory and then
5096 @command{tar}ring that directory.}
5097
5098 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5099
5100 @findex uuencode
5101 You can easily use archive files to transport a group of files from
5102 one system to another: put all relevant files into an archive on one
5103 computer system, transfer the archive to another system, and extract
5104 the contents there. The basic transfer medium might be magnetic tape,
5105 Internet FTP, or even electronic mail (though you must encode the
5106 archive with @command{uuencode} in order to transport it properly by
5107 mail). Both machines do not have to use the same operating system, as
5108 long as they both support the @command{tar} program.
5109
5110 For example, here is how you might copy a directory's contents from
5111 one disk to another, while preserving the dates, modes, owners and
5112 link-structure of all the files therein. In this case, the transfer
5113 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5114
5115 @smallexample
5116 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5117 @end smallexample
5118
5119 @noindent
5120 You can avoid subshells by using @option{-C} option:
5121
5122 @smallexample
5123 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5124 @end smallexample
5125
5126 @noindent
5127 The command also works using short option forms:
5128
5129 @smallexample
5130 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5131 | (cd targetdir; tar --extract --file=-)}
5132 # Or:
5133 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5134 | tar --directory targetdir --extract --file=-}
5135 @end smallexample
5136
5137 @noindent
5138 This is one of the easiest methods to transfer a @command{tar} archive.
5139
5140 @node looking ahead
5141 @section Looking Ahead: The Rest of this Manual
5142
5143 You have now seen how to use all eight of the operations available to
5144 @command{tar}, and a number of the possible options. The next chapter
5145 explains how to choose and change file and archive names, how to use
5146 files to store names of other files which you can then call as
5147 arguments to @command{tar} (this can help you save time if you expect to
5148 archive the same list of files a number of times), and so forth.
5149 @FIXME{in case it's not obvious, i'm making this up in some sense
5150 based on my limited memory of what the next chapter *really* does. i
5151 just wanted to flesh out this final section a little bit so i'd
5152 remember to stick it in here. :-)}
5153
5154 If there are too many files to conveniently list on the command line,
5155 you can list the names in a file, and @command{tar} will read that file.
5156 @xref{files}.
5157
5158 There are various ways of causing @command{tar} to skip over some files,
5159 and not archive them. @xref{Choosing}.
5160
5161 @node Backups
5162 @chapter Performing Backups and Restoring Files
5163 @UNREVISED
5164
5165 @GNUTAR{} is distributed along with the scripts
5166 which the Free Software Foundation uses for performing backups. There
5167 is no corresponding scripts available yet for doing restoration of
5168 files. Even if there is a good chance those scripts may be satisfying
5169 to you, they are not the only scripts or methods available for doing
5170 backups and restore. You may well create your own, or use more
5171 sophisticated packages dedicated to that purpose.
5172
5173 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5174 Automatic Network Disk Archiver), a backup system developed by James
5175 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5176 This is free software, and it is available at these places:
5177
5178 @smallexample
5179 http://www.cs.umd.edu/projects/amanda/amanda.html
5180 ftp://ftp.cs.umd.edu/pub/amanda
5181 @end smallexample
5182
5183 @FIXME{
5184
5185 Here is a possible plan for a future documentation about the backuping
5186 scripts which are provided within the @GNUTAR{}
5187 distribution.
5188
5189 @itemize @bullet
5190 @item dumps
5191 @itemize @minus
5192 @item what are dumps
5193 @item different levels of dumps
5194 @itemize +
5195 @item full dump = dump everything
5196 @item level 1, level 2 dumps etc
5197 A level @var{n} dump dumps everything changed since the last level
5198 @var{n}-1 dump (?)
5199 @end itemize
5200 @item how to use scripts for dumps (ie, the concept)
5201 @itemize +
5202 @item scripts to run after editing backup specs (details)
5203 @end itemize
5204 @item Backup Specs, what is it.
5205 @itemize +
5206 @item how to customize
5207 @item actual text of script [/sp/dump/backup-specs]
5208 @end itemize
5209 @item Problems
5210 @itemize +
5211 @item rsh doesn't work
5212 @item rtape isn't installed
5213 @item (others?)
5214 @end itemize
5215 @item the @option{--incremental} option of tar
5216 @item tapes
5217 @itemize +
5218 @item write protection
5219 @item types of media, different sizes and types, useful for different things
5220 @item files and tape marks
5221 one tape mark between files, two at end.
5222 @item positioning the tape
5223 MT writes two at end of write,
5224 backspaces over one when writing again.
5225 @end itemize
5226 @end itemize
5227 @end itemize
5228 }
5229
5230 This chapter documents both the provided shell scripts and @command{tar}
5231 options which are more specific to usage as a backup tool.
5232
5233 To @dfn{back up} a file system means to create archives that contain
5234 all the files in that file system. Those archives can then be used to
5235 restore any or all of those files (for instance if a disk crashes or a
5236 file is accidentally deleted). File system @dfn{backups} are also
5237 called @dfn{dumps}.
5238
5239 @menu
5240 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5241 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5242 * Backup Levels:: Levels of Backups
5243 * Backup Parameters:: Setting Parameters for Backups and Restoration
5244 * Scripted Backups:: Using the Backup Scripts
5245 * Scripted Restoration:: Using the Restore Script
5246 @end menu
5247
5248 @node Full Dumps
5249 @section Using @command{tar} to Perform Full Dumps
5250 @UNREVISED
5251
5252 @cindex full dumps
5253 @cindex dumps, full
5254
5255 @cindex corrupted archives
5256 Full dumps should only be made when no other people or programs
5257 are modifying files in the file system. If files are modified while
5258 @command{tar} is making the backup, they may not be stored properly in
5259 the archive, in which case you won't be able to restore them if you
5260 have to. (Files not being modified are written with no trouble, and do
5261 not corrupt the entire archive.)
5262
5263 You will want to use the @option{--label=@var{archive-label}}
5264 (@option{-V @var{archive-label}}) option to give the archive a
5265 volume label, so you can tell what this archive is even if the label
5266 falls off the tape, or anything like that.
5267
5268 Unless the file system you are dumping is guaranteed to fit on
5269 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5270 Make sure you have enough tapes on hand to complete the backup.
5271
5272 If you want to dump each file system separately you will need to use
5273 the @option{--one-file-system} option to prevent
5274 @command{tar} from crossing file system boundaries when storing
5275 (sub)directories.
5276
5277 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5278 option is not needed, since this is a complete copy of everything in
5279 the file system, and a full restore from this backup would only be
5280 done onto a completely
5281 empty disk.
5282
5283 Unless you are in a hurry, and trust the @command{tar} program (and your
5284 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5285 option, to make sure your files really made it onto the dump properly.
5286 This will also detect cases where the file was modified while (or just
5287 after) it was being archived. Not all media (notably cartridge tapes)
5288 are capable of being verified, unfortunately.
5289
5290 @node Incremental Dumps
5291 @section Using @command{tar} to Perform Incremental Dumps
5292
5293 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5294 stores additional metadata so that exact state of the file system
5295 can be restored when extracting the archive.
5296
5297 @GNUTAR{} currently offers two options for handling incremental
5298 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5299 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5300
5301 @opindex listed-incremental
5302 The option @option{--listed-incremental} instructs tar to operate on
5303 an incremental archive with additional metadata stored in a standalone
5304 file, called a @dfn{snapshot file}. The purpose of this file is to help
5305 determine which files have been changed, added or deleted since the
5306 last backup, so that the next incremental backup will contain only
5307 modified files. The name of the snapshot file is given as an argument
5308 to the option:
5309
5310 @table @option
5311 @item --listed-incremental=@var{file}
5312 @itemx -g @var{file}
5313 Handle incremental backups with snapshot data in @var{file}.
5314 @end table
5315
5316 To create an incremental backup, you would use
5317 @option{--listed-incremental} together with @option{--create}
5318 (@pxref{create}). For example:
5319
5320 @smallexample
5321 $ @kbd{tar --create \
5322 --file=archive.1.tar \
5323 --listed-incremental=/var/log/usr.snar \
5324 /usr}
5325 @end smallexample
5326
5327 This will create in @file{archive.1.tar} an incremental backup of
5328 the @file{/usr} file system, storing additional metadata in the file
5329 @file{/var/log/usr.snar}. If this file does not exist, it will be
5330 created. The created archive will then be a @dfn{level 0 backup};
5331 please see the next section for more on backup levels.
5332
5333 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5334 determines which files are modified. In this case only these files will be
5335 stored in the archive. Suppose, for example, that after running the
5336 above command, you delete file @file{/usr/doc/old} and create
5337 directory @file{/usr/local/db} with the following contents:
5338
5339 @smallexample
5340 $ @kbd{ls /usr/local/db}
5341 /usr/local/db/data
5342 /usr/local/db/index
5343 @end smallexample
5344
5345 Some time later you create another incremental backup. You will
5346 then see:
5347
5348 @smallexample
5349 $ @kbd{tar --create \
5350 --file=archive.2.tar \
5351 --listed-incremental=/var/log/usr.snar \
5352 /usr}
5353 tar: usr/local/db: Directory is new
5354 usr/local/db/
5355 usr/local/db/data
5356 usr/local/db/index
5357 @end smallexample
5358
5359 @noindent
5360 The created archive @file{archive.2.tar} will contain only these
5361 three members. This archive is called a @dfn{level 1 backup}. Notice
5362 that @file{/var/log/usr.snar} will be updated with the new data, so if
5363 you plan to create more @samp{level 1} backups, it is necessary to
5364 create a working copy of the snapshot file before running
5365 @command{tar}. The above example will then be modified as follows:
5366
5367 @smallexample
5368 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5369 $ @kbd{tar --create \
5370 --file=archive.2.tar \
5371 --listed-incremental=/var/log/usr.snar-1 \
5372 /usr}
5373 @end smallexample
5374
5375 Incremental dumps depend crucially on time stamps, so the results are
5376 unreliable if you modify a file's time stamps during dumping (e.g.,
5377 with the @option{--atime-preserve=replace} option), or if you set the clock
5378 backwards.
5379
5380 Metadata stored in snapshot files include device numbers, which,
5381 obviously is supposed to be a non-volatile value. However, it turns
5382 out that NFS devices have undependable values when an automounter
5383 gets in the picture. This can lead to a great deal of spurious
5384 redumping in incremental dumps, so it is somewhat useless to compare
5385 two NFS devices numbers over time. The solution implemented currently
5386 is to considers all NFS devices as being equal when it comes to
5387 comparing directories; this is fairly gross, but there does not seem
5388 to be a better way to go.
5389
5390 Note that incremental archives use @command{tar} extensions and may
5391 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5392
5393 @xopindex{listed-incremental, using with @option{--extract}}
5394 @xopindex{extract, using with @option{--listed-incremental}}
5395 To extract from the incremental dumps, use
5396 @option{--listed-incremental} together with @option{--extract}
5397 option (@pxref{extracting files}). In this case, @command{tar} does
5398 not need to access snapshot file, since all the data necessary for
5399 extraction are stored in the archive itself. So, when extracting, you
5400 can give whatever argument to @option{--listed-incremental}, the usual
5401 practice is to use @option{--listed-incremental=/dev/null}.
5402 Alternatively, you can use @option{--incremental}, which needs no
5403 arguments. In general, @option{--incremental} (@option{-G}) can be
5404 used as a shortcut for @option{--listed-incremental} when listing or
5405 extracting incremental backups (for more information, regarding this
5406 option, @pxref{incremental-op}).
5407
5408 When extracting from the incremental backup @GNUTAR{} attempts to
5409 restore the exact state the file system had when the archive was
5410 created. In particular, it will @emph{delete} those files in the file
5411 system that did not exist in their directories when the archive was
5412 created. If you have created several levels of incremental files,
5413 then in order to restore the exact contents the file system had when
5414 the last level was created, you will need to restore from all backups
5415 in turn. Continuing our example, to restore the state of @file{/usr}
5416 file system, one would do@footnote{Notice, that since both archives
5417 were created without @option{-P} option (@pxref{absolute}), these
5418 commands should be run from the root file system.}:
5419
5420 @smallexample
5421 $ @kbd{tar --extract \
5422 --listed-incremental=/dev/null \
5423 --file archive.1.tar}
5424 $ @kbd{tar --extract \
5425 --listed-incremental=/dev/null \
5426 --file archive.2.tar}
5427 @end smallexample
5428
5429 To list the contents of an incremental archive, use @option{--list}
5430 (@pxref{list}), as usual. To obtain more information about the
5431 archive, use @option{--listed-incremental} or @option{--incremental}
5432 combined with two @option{--verbose} options@footnote{Two
5433 @option{--verbose} options were selected to avoid breaking usual
5434 verbose listing output (@option{--list --verbose}) when using in
5435 scripts.
5436
5437 @xopindex{incremental, using with @option{--list}}
5438 @xopindex{listed-incremental, using with @option{--list}}
5439 @xopindex{list, using with @option{--incremental}}
5440 @xopindex{list, using with @option{--listed-incremental}}
5441 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5442 contents of the DUMPDIR header (with terminating nulls) when
5443 @option{--incremental} or @option{--listed-incremental} option was
5444 given, no matter what the verbosity level. This behavior, and,
5445 especially, the binary output it produced were considered inconvenient
5446 and were changed in version 1.16}:
5447
5448 @smallexample
5449 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5450 @end smallexample
5451
5452 This command will print, for each directory in the archive, the list
5453 of files in that directory at the time the archive was created. This
5454 information is put out in a format which is both human-readable and
5455 unambiguous for a program: each file name is printed as
5456
5457 @smallexample
5458 @var{x} @var{file}
5459 @end smallexample
5460
5461 @noindent
5462 where @var{x} is a letter describing the status of the file: @samp{Y}
5463 if the file is present in the archive, @samp{N} if the file is not
5464 included in the archive, or a @samp{D} if the file is a directory (and
5465 is included in the archive). @xref{Dumpdir}, for the detailed
5466 description of dumpdirs and status codes. Each such
5467 line is terminated by a newline character. The last line is followed
5468 by an additional newline to indicate the end of the data.
5469
5470 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5471 gives the same behavior as @option{--listed-incremental} when used
5472 with @option{--list} and @option{--extract} options. When used with
5473 @option{--create} option, it creates an incremental archive without
5474 creating snapshot file. Thus, it is impossible to create several
5475 levels of incremental backups with @option{--incremental} option.
5476
5477 @node Backup Levels
5478 @section Levels of Backups
5479
5480 An archive containing all the files in the file system is called a
5481 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5482 creating a full dump every day. This strategy, however, would waste a
5483 substantial amount of archive media and user time, as unchanged files
5484 are daily re-archived.
5485
5486 It is more efficient to do a full dump only occasionally. To back up
5487 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5488 one} dump archives all the files that have changed since the last full
5489 dump.
5490
5491 A typical dump strategy would be to perform a full dump once a week,
5492 and a level one dump once a day. This means some versions of files
5493 will in fact be archived more than once, but this dump strategy makes
5494 it possible to restore a file system to within one day of accuracy by
5495 only extracting two archives---the last weekly (full) dump and the
5496 last daily (level one) dump. The only information lost would be in
5497 files changed or created since the last daily backup. (Doing dumps
5498 more than once a day is usually not worth the trouble).
5499
5500 @GNUTAR{} comes with scripts you can use to do full
5501 and level-one (actually, even level-two and so on) dumps. Using
5502 scripts (shell programs) to perform backups and restoration is a
5503 convenient and reliable alternative to typing out file name lists
5504 and @command{tar} commands by hand.
5505
5506 Before you use these scripts, you need to edit the file
5507 @file{backup-specs}, which specifies parameters used by the backup
5508 scripts and by the restore script. This file is usually located
5509 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5510 detailed description. Once the backup parameters are set, you can
5511 perform backups or restoration by running the appropriate script.
5512
5513 The name of the backup script is @code{backup}. The name of the
5514 restore script is @code{restore}. The following sections describe
5515 their use in detail.
5516
5517 @emph{Please Note:} The backup and restoration scripts are
5518 designed to be used together. While it is possible to restore files by
5519 hand from an archive which was created using a backup script, and to create
5520 an archive by hand which could then be extracted using the restore script,
5521 it is easier to use the scripts. @xref{Incremental Dumps}, before
5522 making such an attempt.
5523
5524 @node Backup Parameters
5525 @section Setting Parameters for Backups and Restoration
5526
5527 The file @file{backup-specs} specifies backup parameters for the
5528 backup and restoration scripts provided with @command{tar}. You must
5529 edit @file{backup-specs} to fit your system configuration and schedule
5530 before using these scripts.
5531
5532 Syntactically, @file{backup-specs} is a shell script, containing
5533 mainly variable assignments. However, any valid shell construct
5534 is allowed in this file. Particularly, you may wish to define
5535 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5536 For more information about shell script syntax, please refer to
5537 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5538 g_02, the definition of the Shell Command Language}. See also
5539 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5540
5541 The shell variables controlling behavior of @code{backup} and
5542 @code{restore} are described in the following subsections.
5543
5544 @menu
5545 * General-Purpose Variables::
5546 * Magnetic Tape Control::
5547 * User Hooks::
5548 * backup-specs example:: An Example Text of @file{Backup-specs}
5549 @end menu
5550
5551 @node General-Purpose Variables
5552 @subsection General-Purpose Variables
5553
5554 @defvr {Backup variable} ADMINISTRATOR
5555 The user name of the backup administrator. @code{Backup} scripts
5556 sends a backup report to this address.
5557 @end defvr
5558
5559 @defvr {Backup variable} BACKUP_HOUR
5560 The hour at which the backups are done. This can be a number from 0
5561 to 23, or the time specification in form @var{hours}:@var{minutes},
5562 or the string @samp{now}.
5563
5564 This variable is used by @code{backup}. Its value may be overridden
5565 using @option{--time} option (@pxref{Scripted Backups}).
5566 @end defvr
5567
5568 @defvr {Backup variable} TAPE_FILE
5569
5570 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5571 is a remote archive (@pxref{remote-dev}), backup script will suppose
5572 that your @command{mt} is able to access remote devices. If @var{RSH}
5573 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5574 invocations of @command{mt}.
5575 @end defvr
5576
5577 @defvr {Backup variable} BLOCKING
5578
5579 The blocking factor @command{tar} will use when writing the dump archive.
5580 @xref{Blocking Factor}.
5581 @end defvr
5582
5583 @defvr {Backup variable} BACKUP_DIRS
5584
5585 A list of file systems to be dumped (for @code{backup}), or restored
5586 (for @code{restore}). You can include any directory
5587 name in the list --- subdirectories on that file system will be
5588 included, regardless of how they may look to other networked machines.
5589 Subdirectories on other file systems will be ignored.
5590
5591 The host name specifies which host to run @command{tar} on, and should
5592 normally be the host that actually contains the file system. However,
5593 the host machine must have @GNUTAR{} installed, and
5594 must be able to access the directory containing the backup scripts and
5595 their support files using the same file name that is used on the
5596 machine where the scripts are run (i.e., what @command{pwd} will print
5597 when in that directory on that machine). If the host that contains
5598 the file system does not have this capability, you can specify another
5599 host as long as it can access the file system through NFS.
5600
5601 If the list of file systems is very long you may wish to put it
5602 in a separate file. This file is usually named
5603 @file{/etc/backup/dirs}, but this name may be overridden in
5604 @file{backup-specs} using @code{DIRLIST} variable.
5605 @end defvr
5606
5607 @defvr {Backup variable} DIRLIST
5608
5609 A path to the file containing the list of the file systems to backup
5610 or restore. By default it is @file{/etc/backup/dirs}.
5611 @end defvr
5612
5613 @defvr {Backup variable} BACKUP_FILES
5614
5615 A list of individual files to be dumped (for @code{backup}), or restored
5616 (for @code{restore}). These should be accessible from the machine on
5617 which the backup script is run.
5618
5619 If the list of file systems is very long you may wish to store it
5620 in a separate file. This file is usually named
5621 @file{/etc/backup/files}, but this name may be overridden in
5622 @file{backup-specs} using @code{FILELIST} variable.
5623 @end defvr
5624
5625 @defvr {Backup variable} FILELIST
5626
5627 A path to the file containing the list of the individual files to backup
5628 or restore. By default it is @file{/etc/backup/files}.
5629 @end defvr
5630
5631 @defvr {Backup variable} MT
5632
5633 Full file name of @command{mt} binary.
5634 @end defvr
5635
5636 @defvr {Backup variable} RSH
5637 @anchor{RSH}
5638 Full file name of @command{rsh} binary or its equivalent. You may wish to
5639 set it to @code{ssh}, to improve security. In this case you will have
5640 to use public key authentication.
5641 @end defvr
5642
5643 @defvr {Backup variable} RSH_COMMAND
5644
5645 Full file name of @command{rsh} binary on remote machines. This will
5646 be passed via @option{--rsh-command} option to the remote invocation
5647 of @GNUTAR{}.
5648 @end defvr
5649
5650 @defvr {Backup variable} VOLNO_FILE
5651
5652 Name of temporary file to hold volume numbers. This needs to be accessible
5653 by all the machines which have file systems to be dumped.
5654 @end defvr
5655
5656 @defvr {Backup variable} XLIST
5657
5658 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5659 located on the remote machine and containing the list of files to
5660 be excluded from the backup. Exclude file lists are searched in
5661 /etc/tar-backup directory. A common use for exclude file lists
5662 is to exclude files containing security-sensitive information
5663 (e.g., @file{/etc/shadow} from backups).
5664
5665 This variable affects only @code{backup}.
5666 @end defvr
5667
5668 @defvr {Backup variable} SLEEP_TIME
5669
5670 Time to sleep between dumps of any two successive file systems
5671
5672 This variable affects only @code{backup}.
5673 @end defvr
5674
5675 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5676
5677 Script to be run when it's time to insert a new tape in for the next
5678 volume. Administrators may want to tailor this script for their site.
5679 If this variable isn't set, @GNUTAR{} will display its built-in
5680 prompt, and will expect confirmation from the console. For the
5681 description of the default prompt, see @ref{change volume prompt}.
5682
5683 @end defvr
5684
5685 @defvr {Backup variable} SLEEP_MESSAGE
5686
5687 Message to display on the terminal while waiting for dump time. Usually
5688 this will just be some literal text.
5689 @end defvr
5690
5691 @defvr {Backup variable} TAR
5692
5693 Full file name of the @GNUTAR{} executable. If this is not set, backup
5694 scripts will search @command{tar} in the current shell path.
5695 @end defvr
5696
5697 @node Magnetic Tape Control
5698 @subsection Magnetic Tape Control
5699
5700 Backup scripts access tape device using special @dfn{hook functions}.
5701 These functions take a single argument -- the name of the tape
5702 device. Their names are kept in the following variables:
5703
5704 @defvr {Backup variable} MT_BEGIN
5705 The name of @dfn{begin} function. This function is called before
5706 accessing the drive. By default it retensions the tape:
5707
5708 @smallexample
5709 MT_BEGIN=mt_begin
5710
5711 mt_begin() @{
5712 mt -f "$1" retension
5713 @}
5714 @end smallexample
5715 @end defvr
5716
5717 @defvr {Backup variable} MT_REWIND
5718 The name of @dfn{rewind} function. The default definition is as
5719 follows:
5720
5721 @smallexample
5722 MT_REWIND=mt_rewind
5723
5724 mt_rewind() @{
5725 mt -f "$1" rewind
5726 @}
5727 @end smallexample
5728
5729 @end defvr
5730
5731 @defvr {Backup variable} MT_OFFLINE
5732 The name of the function switching the tape off line. By default
5733 it is defined as follows:
5734
5735 @smallexample
5736 MT_OFFLINE=mt_offline
5737
5738 mt_offline() @{
5739 mt -f "$1" offl
5740 @}
5741 @end smallexample
5742 @end defvr
5743
5744 @defvr {Backup variable} MT_STATUS
5745 The name of the function used to obtain the status of the archive device,
5746 including error count. Default definition:
5747
5748 @smallexample
5749 MT_STATUS=mt_status
5750
5751 mt_status() @{
5752 mt -f "$1" status
5753 @}
5754 @end smallexample
5755 @end defvr
5756
5757 @node User Hooks
5758 @subsection User Hooks
5759
5760 @dfn{User hooks} are shell functions executed before and after
5761 each @command{tar} invocation. Thus, there are @dfn{backup
5762 hooks}, which are executed before and after dumping each file
5763 system, and @dfn{restore hooks}, executed before and
5764 after restoring a file system. Each user hook is a shell function
5765 taking four arguments:
5766
5767 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5768 Its arguments are:
5769
5770 @table @var
5771 @item level
5772 Current backup or restore level.
5773
5774 @item host
5775 Name or IP address of the host machine being dumped or restored.
5776
5777 @item fs
5778 Full path name to the file system being dumped or restored.
5779
5780 @item fsname
5781 File system name with directory separators replaced with colons. This
5782 is useful, e.g., for creating unique files.
5783 @end table
5784 @end deffn
5785
5786 Following variables keep the names of user hook functions
5787
5788 @defvr {Backup variable} DUMP_BEGIN
5789 Dump begin function. It is executed before dumping the file system.
5790 @end defvr
5791
5792 @defvr {Backup variable} DUMP_END
5793 Executed after dumping the file system.
5794 @end defvr
5795
5796 @defvr {Backup variable} RESTORE_BEGIN
5797 Executed before restoring the file system.
5798 @end defvr
5799
5800 @defvr {Backup variable} RESTORE_END
5801 Executed after restoring the file system.
5802 @end defvr
5803
5804 @node backup-specs example
5805 @subsection An Example Text of @file{Backup-specs}
5806
5807 The following is an example of @file{backup-specs}:
5808
5809 @smallexample
5810 # site-specific parameters for file system backup.
5811
5812 ADMINISTRATOR=friedman
5813 BACKUP_HOUR=1
5814 TAPE_FILE=/dev/nrsmt0
5815
5816 # Use @code{ssh} instead of the less secure @code{rsh}
5817 RSH=/usr/bin/ssh
5818 RSH_COMMAND=/usr/bin/ssh
5819
5820 # Override MT_STATUS function:
5821 my_status() @{
5822 mts -t $TAPE_FILE
5823 @}
5824 MT_STATUS=my_status
5825
5826 # Disable MT_OFFLINE function
5827 MT_OFFLINE=:
5828
5829 BLOCKING=124
5830 BACKUP_DIRS="
5831 albert:/fs/fsf
5832 apple-gunkies:/gd
5833 albert:/fs/gd2
5834 albert:/fs/gp
5835 geech:/usr/jla
5836 churchy:/usr/roland
5837 albert:/
5838 albert:/usr
5839 apple-gunkies:/
5840 apple-gunkies:/usr
5841 gnu:/hack
5842 gnu:/u
5843 apple-gunkies:/com/mailer/gnu
5844 apple-gunkies:/com/archive/gnu"
5845
5846 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5847
5848 @end smallexample
5849
5850 @node Scripted Backups
5851 @section Using the Backup Scripts
5852
5853 The syntax for running a backup script is:
5854
5855 @smallexample
5856 backup --level=@var{level} --time=@var{time}
5857 @end smallexample
5858
5859 The @option{level} option requests the dump level. Thus, to produce
5860 a full dump, specify @code{--level=0} (this is the default, so
5861 @option{--level} may be omitted if its value is @code{0}).
5862 @footnote{For backward compatibility, the @code{backup} will also
5863 try to deduce the requested dump level from the name of the
5864 script itself. If the name consists of a string @samp{level-}
5865 followed by a single decimal digit, that digit is taken as
5866 the dump level number. Thus, you may create a link from @code{backup}
5867 to @code{level-1} and then run @code{level-1} whenever you need to
5868 create a level one dump.}
5869
5870 The @option{--time} option determines when should the backup be
5871 run. @var{Time} may take three forms:
5872
5873 @table @asis
5874 @item @var{hh}:@var{mm}
5875
5876 The dump must be run at @var{hh} hours @var{mm} minutes.
5877
5878 @item @var{hh}
5879
5880 The dump must be run at @var{hh} hours
5881
5882 @item now
5883
5884 The dump must be run immediately.
5885 @end table
5886
5887 You should start a script with a tape or disk mounted. Once you
5888 start a script, it prompts you for new tapes or disks as it
5889 needs them. Media volumes don't have to correspond to archive
5890 files --- a multi-volume archive can be started in the middle of a
5891 tape that already contains the end of another multi-volume archive.
5892 The @code{restore} script prompts for media by its archive volume,
5893 so to avoid an error message you should keep track of which tape
5894 (or disk) contains which volume of the archive (@pxref{Scripted
5895 Restoration}).
5896
5897 The backup scripts write two files on the file system. The first is a
5898 record file in @file{/etc/tar-backup/}, which is used by the scripts
5899 to store and retrieve information about which files were dumped. This
5900 file is not meant to be read by humans, and should not be deleted by
5901 them. @xref{Snapshot Files}, for a more detailed explanation of this
5902 file.
5903
5904 The second file is a log file containing the names of the file systems
5905 and files dumped, what time the backup was made, and any error
5906 messages that were generated, as well as how much space was left in
5907 the media volume after the last volume of the archive was written.
5908 You should check this log file after every backup. The file name is
5909 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5910 represents current date, and @var{n} represents current dump level number.
5911
5912 The script also prints the name of each system being dumped to the
5913 standard output.
5914
5915 Following is the full list of options accepted by @code{backup}
5916 script:
5917
5918 @table @option
5919 @item -l @var{level}
5920 @itemx --level=@var{level}
5921 Do backup level @var{level} (default 0).
5922
5923 @item -f
5924 @itemx --force
5925 Force backup even if today's log file already exists.
5926
5927 @item -v[@var{level}]
5928 @itemx --verbose[=@var{level}]
5929 Set verbosity level. The higher the level is, the more debugging
5930 information will be output during execution. Default @var{level}
5931 is 100, which means the highest debugging level.
5932
5933 @item -t @var{start-time}
5934 @itemx --time=@var{start-time}
5935 Wait till @var{time}, then do backup.
5936
5937 @item -h
5938 @itemx --help
5939 Display short help message and exit.
5940
5941 @item -V
5942 @itemx --version
5943 Display information about the program's name, version, origin and legal
5944 status, all on standard output, and then exit successfully.
5945 @end table
5946
5947
5948 @node Scripted Restoration
5949 @section Using the Restore Script
5950
5951 To restore files that were archived using a scripted backup, use the
5952 @code{restore} script. Its usage is quite straightforward. In the
5953 simplest form, invoke @code{restore --all}, it will
5954 then restore all the file systems and files specified in
5955 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5956
5957 You may select the file systems (and/or files) to restore by
5958 giving @code{restore} list of @dfn{patterns} in its command
5959 line. For example, running
5960
5961 @smallexample
5962 restore 'albert:*'
5963 @end smallexample
5964
5965 @noindent
5966 will restore all file systems on the machine @samp{albert}. A more
5967 complicated example:
5968
5969 @smallexample
5970 restore 'albert:*' '*:/var'
5971 @end smallexample
5972
5973 @noindent
5974 This command will restore all file systems on the machine @samp{albert}
5975 as well as @file{/var} file system on all machines.
5976
5977 By default @code{restore} will start restoring files from the lowest
5978 available dump level (usually zero) and will continue through
5979 all available dump levels. There may be situations where such a
5980 thorough restore is not necessary. For example, you may wish to
5981 restore only files from the recent level one backup. To do so,
5982 use @option{--level} option, as shown in the example below:
5983
5984 @smallexample
5985 restore --level=1
5986 @end smallexample
5987
5988 The full list of options accepted by @code{restore} follows:
5989
5990 @table @option
5991 @item -a
5992 @itemx --all
5993 Restore all file systems and files specified in @file{backup-specs}
5994
5995 @item -l @var{level}
5996 @itemx --level=@var{level}
5997 Start restoring from the given backup level, instead of the default 0.
5998
5999 @item -v[@var{level}]
6000 @itemx --verbose[=@var{level}]
6001 Set verbosity level. The higher the level is, the more debugging
6002 information will be output during execution. Default @var{level}
6003 is 100, which means the highest debugging level.
6004
6005 @item -h
6006 @itemx --help
6007 Display short help message and exit.
6008
6009 @item -V
6010 @itemx --version
6011 Display information about the program's name, version, origin and legal
6012 status, all on standard output, and then exit successfully.
6013 @end table
6014
6015 You should start the restore script with the media containing the
6016 first volume of the archive mounted. The script will prompt for other
6017 volumes as they are needed. If the archive is on tape, you don't need
6018 to rewind the tape to to its beginning---if the tape head is
6019 positioned past the beginning of the archive, the script will rewind
6020 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6021 positioning.
6022
6023 @quotation
6024 @strong{Warning:} The script will delete files from the active file
6025 system if they were not in the file system when the archive was made.
6026 @end quotation
6027
6028 @xref{Incremental Dumps}, for an explanation of how the script makes
6029 that determination.
6030
6031 @node Choosing
6032 @chapter Choosing Files and Names for @command{tar}
6033 @UNREVISED
6034
6035 Certain options to @command{tar} enable you to specify a name for your
6036 archive. Other options let you decide which files to include or exclude
6037 from the archive, based on when or whether files were modified, whether
6038 the file names do or don't match specified patterns, or whether files
6039 are in specified directories.
6040
6041 This chapter discusses these options in detail.
6042
6043 @menu
6044 * file:: Choosing the Archive's Name
6045 * Selecting Archive Members::
6046 * files:: Reading Names from a File
6047 * exclude:: Excluding Some Files
6048 * wildcards:: Wildcards Patterns and Matching
6049 * quoting styles:: Ways of Quoting Special Characters in Names
6050 * transform:: Modifying File and Member Names
6051 * after:: Operating Only on New Files
6052 * recurse:: Descending into Directories
6053 * one:: Crossing File System Boundaries
6054 @end menu
6055
6056 @node file
6057 @section Choosing and Naming Archive Files
6058 @UNREVISED
6059
6060 @cindex Naming an archive
6061 @cindex Archive Name
6062 @cindex Choosing an archive file
6063 @cindex Where is the archive?
6064 By default, @command{tar} uses an archive file name that was compiled when
6065 it was built on the system; usually this name refers to some physical
6066 tape drive on the machine. However, the person who installed @command{tar}
6067 on the system may not have set the default to a meaningful value as far as
6068 most users are concerned. As a result, you will usually want to tell
6069 @command{tar} where to find (or create) the archive. The
6070 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6071 option allows you to either specify or name a file to use as the archive
6072 instead of the default archive file location.
6073
6074 @table @option
6075 @xopindex{file, short description}
6076 @item --file=@var{archive-name}
6077 @itemx -f @var{archive-name}
6078 Name the archive to create or operate on. Use in conjunction with
6079 any operation.
6080 @end table
6081
6082 For example, in this @command{tar} command,
6083
6084 @smallexample
6085 $ @kbd{tar -cvf collection.tar blues folk jazz}
6086 @end smallexample
6087
6088 @noindent
6089 @file{collection.tar} is the name of the archive. It must directly
6090 follow the @option{-f} option, since whatever directly follows @option{-f}
6091 @emph{will} end up naming the archive. If you neglect to specify an
6092 archive name, you may end up overwriting a file in the working directory
6093 with the archive you create since @command{tar} will use this file's name
6094 for the archive name.
6095
6096 An archive can be saved as a file in the file system, sent through a
6097 pipe or over a network, or written to an I/O device such as a tape,
6098 floppy disk, or CD write drive.
6099
6100 @cindex Writing new archives
6101 @cindex Archive creation
6102 If you do not name the archive, @command{tar} uses the value of the
6103 environment variable @env{TAPE} as the file name for the archive. If
6104 that is not available, @command{tar} uses a default, compiled-in archive
6105 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6106
6107 @cindex Standard input and output
6108 @cindex tar to standard input and output
6109 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6110 archive from standard input (when listing or extracting files), or
6111 writes it to standard output (when creating an archive). If you use
6112 @file{-} as an @var{archive-name} when modifying an archive,
6113 @command{tar} reads the original archive from its standard input and
6114 writes the entire new archive to its standard output.
6115
6116 The following example is a convenient way of copying directory
6117 hierarchy from @file{sourcedir} to @file{targetdir}.
6118
6119 @smallexample
6120 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6121 @end smallexample
6122
6123 The @option{-C} option allows to avoid using subshells:
6124
6125 @smallexample
6126 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6127 @end smallexample
6128
6129 In both examples above, the leftmost @command{tar} invocation archives
6130 the contents of @file{sourcedir} to the standard output, while the
6131 rightmost one reads this archive from its standard input and
6132 extracts it. The @option{-p} option tells it to restore permissions
6133 of the extracted files.
6134
6135 @cindex Remote devices
6136 @cindex tar to a remote device
6137 @anchor{remote-dev}
6138 To specify an archive file on a device attached to a remote machine,
6139 use the following:
6140
6141 @smallexample
6142 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6143 @end smallexample
6144
6145 @noindent
6146 @command{tar} will complete the remote connection, if possible, and
6147 prompt you for a username and password. If you use
6148 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6149 will complete the remote connection, if possible, using your username
6150 as the username on the remote machine.
6151
6152 @cindex Local and remote archives
6153 @anchor{local and remote archives}
6154 If the archive file name includes a colon (@samp{:}), then it is assumed
6155 to be a file on another machine. If the archive file is
6156 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6157 host @var{host}. The remote host is accessed using the @command{rsh}
6158 program, with a username of @var{user}. If the username is omitted
6159 (along with the @samp{@@} sign), then your user name will be used.
6160 (This is the normal @command{rsh} behavior.) It is necessary for the
6161 remote machine, in addition to permitting your @command{rsh} access, to
6162 have the @file{rmt} program installed (This command is included in
6163 the @GNUTAR{} distribution and by default is installed under
6164 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6165 installation prefix). If you need to use a file whose name includes a
6166 colon, then the remote tape drive behavior
6167 can be inhibited by using the @option{--force-local} option.
6168
6169 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6170 tries to minimize input and output operations. The Amanda backup
6171 system, when used with @GNUTAR{}, has an initial sizing pass which
6172 uses this feature.
6173
6174 @node Selecting Archive Members
6175 @section Selecting Archive Members
6176 @cindex Specifying files to act on
6177 @cindex Specifying archive members
6178
6179 @dfn{File Name arguments} specify which files in the file system
6180 @command{tar} operates on, when creating or adding to an archive, or which
6181 archive members @command{tar} operates on, when reading or deleting from
6182 an archive. @xref{Operations}.
6183
6184 To specify file names, you can include them as the last arguments on
6185 the command line, as follows:
6186 @smallexample
6187 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6188 @end smallexample
6189
6190 If a file name begins with dash (@samp{-}), precede it with
6191 @option{--add-file} option to prevent it from being treated as an
6192 option.
6193
6194 @anchor{input name quoting}
6195 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6196 name, replacing @dfn{escape sequences} according to the following
6197 table:
6198
6199 @multitable @columnfractions 0.20 0.60
6200 @headitem Escape @tab Replaced with
6201 @item \a @tab Audible bell (ASCII 7)
6202 @item \b @tab Backspace (ASCII 8)
6203 @item \f @tab Form feed (ASCII 12)
6204 @item \n @tab New line (ASCII 10)
6205 @item \r @tab Carriage return (ASCII 13)
6206 @item \t @tab Horizontal tabulation (ASCII 9)
6207 @item \v @tab Vertical tabulation (ASCII 11)
6208 @item \? @tab ASCII 127
6209 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6210 of up to 3 digits)
6211 @end multitable
6212
6213 A backslash followed by any other symbol is retained.
6214
6215 This default behavior is controlled by the following command line
6216 option:
6217
6218 @table @option
6219 @opindex unquote
6220 @item --unquote
6221 Enable unquoting input file or member names (default).
6222
6223 @opindex no-unquote
6224 @item --no-unquote
6225 Disable unquoting input file or member names.
6226 @end table
6227
6228 If you specify a directory name as a file name argument, all the files
6229 in that directory are operated on by @command{tar}.
6230
6231 If you do not specify files, @command{tar} behavior differs depending
6232 on the operation mode as described below:
6233
6234 When @command{tar} is invoked with @option{--create} (@option{-c}),
6235 @command{tar} will stop immediately, reporting the following:
6236
6237 @smallexample
6238 @group
6239 $ @kbd{tar cf a.tar}
6240 tar: Cowardly refusing to create an empty archive
6241 Try `tar --help' or `tar --usage' for more information.
6242 @end group
6243 @end smallexample
6244
6245 If you specify either @option{--list} (@option{-t}) or
6246 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6247 operates on all the archive members in the archive.
6248
6249 If run with @option{--diff} option, tar will compare the archive with
6250 the contents of the current working directory.
6251
6252 If you specify any other operation, @command{tar} does nothing.
6253
6254 By default, @command{tar} takes file names from the command line. However,
6255 there are other ways to specify file or member names, or to modify the
6256 manner in which @command{tar} selects the files or members upon which to
6257 operate. In general, these methods work both for specifying the names
6258 of files and archive members.
6259
6260 @node files
6261 @section Reading Names from a File
6262
6263 @cindex Reading file names from a file
6264 @cindex Lists of file names
6265 @cindex File Name arguments, alternatives
6266 Instead of giving the names of files or archive members on the command
6267 line, you can put the names into a file, and then use the
6268 @option{--files-from=@var{file-of-names}} (@option{-T
6269 @var{file-of-names}}) option to @command{tar}. Give the name of the
6270 file which contains the list of files to include as the argument to
6271 @option{--files-from}. In the list, the file names should be separated by
6272 newlines. You will frequently use this option when you have generated
6273 the list of files to archive with the @command{find} utility.
6274
6275 @table @option
6276 @opindex files-from
6277 @item --files-from=@var{file-name}
6278 @itemx -T @var{file-name}
6279 Get names to extract or create from file @var{file-name}.
6280 @end table
6281
6282 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6283 you specify either @code{--files-from=-} or @code{-T -}), then the file
6284 names are read from standard input.
6285
6286 Unless you are running @command{tar} with @option{--create}, you can not use
6287 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6288 command.
6289
6290 Any number of @option{-T} options can be given in the command line.
6291
6292 The following example shows how to use @command{find} to generate a list of
6293 files smaller than 400K in length and put that list into a file
6294 called @file{small-files}. You can then use the @option{-T} option to
6295 @command{tar} to specify the files from that file, @file{small-files}, to
6296 create the archive @file{little.tgz}. (The @option{-z} option to
6297 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6298 more information.)
6299
6300 @smallexample
6301 $ @kbd{find . -size -400 -print > small-files}
6302 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6303 @end smallexample
6304
6305 @noindent
6306 In the file list given by @option{-T} option, any file name beginning
6307 with @samp{-} character is considered a @command{tar} option and is
6308 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6309 recognized only @option{-C} option in file lists, and only if the
6310 option and its argument occupied two consecutive lines.} For example,
6311 the common use of this feature is to change to another directory by
6312 specifying @option{-C} option:
6313
6314 @smallexample
6315 @group
6316 $ @kbd{cat list}
6317 -C/etc
6318 passwd
6319 hosts
6320 -C/lib
6321 libc.a
6322 $ @kbd{tar -c -f foo.tar --files-from list}
6323 @end group
6324 @end smallexample
6325
6326 @noindent
6327 In this example, @command{tar} will first switch to @file{/etc}
6328 directory and add files @file{passwd} and @file{hosts} to the
6329 archive. Then it will change to @file{/lib} directory and will archive
6330 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6331 contain:
6332
6333 @smallexample
6334 @group
6335 $ @kbd{tar tf foo.tar}
6336 passwd
6337 hosts
6338 libc.a
6339 @end group
6340 @end smallexample
6341
6342 @noindent
6343 @xopindex{directory, using in @option{--files-from} argument}
6344 Notice that the option parsing algorithm used with @option{-T} is
6345 stricter than the one used by shell. Namely, when specifying option
6346 arguments, you should observe the following rules:
6347
6348 @itemize @bullet
6349 @item
6350 When using short (single-letter) option form, its argument must
6351 immediately follow the option letter, without any intervening
6352 whitespace. For example: @code{-Cdir}.
6353
6354 @item
6355 When using long option form, the option argument must be separated
6356 from the option by a single equal sign. No whitespace is allowed on
6357 any side of the equal sign. For example: @code{--directory=dir}.
6358
6359 @item
6360 For both short and long option forms, the option argument can be given
6361 on the next line after the option name, e.g.:
6362
6363 @smallexample
6364 @group
6365 --directory
6366 dir
6367 @end group
6368 @end smallexample
6369
6370 @noindent
6371 and
6372
6373 @smallexample
6374 @group
6375 -C
6376 dir
6377 @end group
6378 @end smallexample
6379 @end itemize
6380
6381 @opindex add-file
6382 If you happen to have a file whose name starts with @samp{-},
6383 precede it with @option{--add-file} option to prevent it from
6384 being recognized as an option. For example: @code{--add-file=--my-file}.
6385
6386 @menu
6387 * nul::
6388 @end menu
6389
6390 @node nul
6391 @subsection @code{NUL} Terminated File Names
6392
6393 @cindex File names, terminated by @code{NUL}
6394 @cindex @code{NUL} terminated file names
6395 The @option{--null} option causes
6396 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6397 to read file names terminated by a @code{NUL} instead of a newline, so
6398 files whose names contain newlines can be archived using
6399 @option{--files-from}.
6400
6401 @table @option
6402 @opindex null
6403 @item --null
6404 Only consider @code{NUL} terminated file names, instead of files that
6405 terminate in a newline.
6406 @end table
6407
6408 The @option{--null} option is just like the one in @acronym{GNU}
6409 @command{xargs} and @command{cpio}, and is useful with the
6410 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6411 @command{tar}, @option{--null} also disables special handling for
6412 file names that begin with dash.
6413
6414 This example shows how to use @command{find} to generate a list of files
6415 larger than 800K in length and put that list into a file called
6416 @file{long-files}. The @option{-print0} option to @command{find} is just
6417 like @option{-print}, except that it separates files with a @code{NUL}
6418 rather than with a newline. You can then run @command{tar} with both the
6419 @option{--null} and @option{-T} options to specify that @command{tar} get the
6420 files from that file, @file{long-files}, to create the archive
6421 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6422 @command{tar} to recognize the @code{NUL} separator between files.
6423
6424 @smallexample
6425 $ @kbd{find . -size +800 -print0 > long-files}
6426 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6427 @end smallexample
6428
6429 @FIXME{say anything else here to conclude the section?}
6430
6431 @node exclude
6432 @section Excluding Some Files
6433 @UNREVISED
6434
6435 @cindex File names, excluding files by
6436 @cindex Excluding files by name and pattern
6437 @cindex Excluding files by file system
6438 To avoid operating on files whose names match a particular pattern,
6439 use the @option{--exclude} or @option{--exclude-from} options.
6440
6441 @table @option
6442 @opindex exclude
6443 @item --exclude=@var{pattern}
6444 Causes @command{tar} to ignore files that match the @var{pattern}.
6445 @end table
6446
6447 @findex exclude
6448 The @option{--exclude=@var{pattern}} option prevents any file or
6449 member whose name matches the shell wildcard (@var{pattern}) from
6450 being operated on.
6451 For example, to create an archive with all the contents of the directory
6452 @file{src} except for files whose names end in @file{.o}, use the
6453 command @samp{tar -cf src.tar --exclude='*.o' src}.
6454
6455 You may give multiple @option{--exclude} options.
6456
6457 @table @option
6458 @opindex exclude-from
6459 @item --exclude-from=@var{file}
6460 @itemx -X @var{file}
6461 Causes @command{tar} to ignore files that match the patterns listed in
6462 @var{file}.
6463 @end table
6464
6465 @findex exclude-from
6466 Use the @option{--exclude-from} option to read a
6467 list of patterns, one per line, from @var{file}; @command{tar} will
6468 ignore files matching those patterns. Thus if @command{tar} is
6469 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6470 single line @file{*.o}, no files whose names end in @file{.o} will be
6471 added to the archive.
6472
6473 @table @option
6474 @opindex exclude-caches
6475 @item --exclude-caches
6476 Causes @command{tar} to ignore directories containing a cache directory tag.
6477 @end table
6478
6479 @findex exclude-caches
6480 When creating an archive, the @option{--exclude-caches} option causes
6481 @command{tar} to exclude all directories that contain a @dfn{cache
6482 directory tag}. A cache directory tag is a short file with the
6483 well-known name @file{CACHEDIR.TAG} and having a standard header
6484 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6485 Various applications write cache directory tags into directories they
6486 use to hold regenerable, non-precious data, so that such data can be
6487 more easily excluded from backups.
6488
6489 @findex exclude-tag
6490 Another option, @option{--exclude-tag}, provides a generalization of
6491 this concept. It takes a single argument, a file name to look for.
6492 Any directory that contains this file will be excluded from the dump.
6493
6494 @table @option
6495 @opindex exclude-tag
6496 @item --exclude-tag=@var{file}
6497 Causes @command{tar} to ignore directories containing @var{file}.
6498 Multiple @option{--exclude-tag} options can be given.
6499 @end table
6500
6501 For example:
6502
6503 @smallexample
6504 $ @kbd{find dir}
6505 dir
6506 dir/blues
6507 dir/jazz
6508 dir/folk
6509 dir/folk/tagfile
6510 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v}
6511 dir/
6512 dir/blues
6513 dir/jazz
6514 ./tar: dir/folk/: contains a cache directory tag tagfile; not dumped
6515 $ @kbd{tar -tf archive.tar}
6516 dir/
6517 dir/blues
6518 dir/jazz
6519 @end smallexample
6520
6521 @menu
6522 * problems with exclude::
6523 @end menu
6524
6525 @node problems with exclude
6526 @unnumberedsubsec Problems with Using the @code{exclude} Options
6527
6528 @xopindex{exclude, potential problems with}
6529 Some users find @samp{exclude} options confusing. Here are some common
6530 pitfalls:
6531
6532 @itemize @bullet
6533 @item
6534 The main operating mode of @command{tar} does not act on a path name
6535 explicitly listed on the command line if one of its file name
6536 components is excluded. In the example above, if
6537 you create an archive and exclude files that end with @samp{*.o}, but
6538 explicitly name the file @samp{dir.o/foo} after all the options have been
6539 listed, @samp{dir.o/foo} will be excluded from the archive.
6540
6541 @item
6542 You can sometimes confuse the meanings of @option{--exclude} and
6543 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6544 to be excluded are given as a pattern on the command line. Use
6545 @option{--exclude-from} to introduce the name of a file which contains
6546 a list of patterns, one per line; each of these patterns can exclude
6547 zero, one, or many files.
6548
6549 @item
6550 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6551 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6552 like @samp{*}. If you do not do this, the shell might expand the
6553 @samp{*} itself using files at hand, so @command{tar} might receive a
6554 list of files instead of one pattern, or none at all, making the
6555 command somewhat illegal. This might not correspond to what you want.
6556
6557 For example, write:
6558
6559 @smallexample
6560 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6561 @end smallexample
6562
6563 @noindent
6564 rather than:
6565
6566 @smallexample
6567 # @emph{Wrong!}
6568 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6569 @end smallexample
6570
6571 @item
6572 You must use use shell syntax, or globbing, rather than @code{regexp}
6573 syntax, when using exclude options in @command{tar}. If you try to use
6574 @code{regexp} syntax to describe files to be excluded, your command
6575 might fail.
6576
6577 @item
6578 @FIXME{The change in semantics must have occurred before 1.11,
6579 so I doubt if it is worth mentioning at all. Anyway, should at
6580 least specify in which version the semantics changed.}
6581 In earlier versions of @command{tar}, what is now the
6582 @option{--exclude-from} option was called @option{--exclude} instead.
6583 Now, @option{--exclude} applies to patterns listed on the command
6584 line and @option{--exclude-from} applies to patterns listed in a
6585 file.
6586
6587 @end itemize
6588
6589 @node wildcards
6590 @section Wildcards Patterns and Matching
6591
6592 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6593 @samp{*} or @samp{?} for example, are replaced and expanded into all
6594 existing files matching the given pattern. @GNUTAR{} can use wildcard
6595 patterns for matching (or globbing) archive members when extracting
6596 from or listing an archive. Wildcard patterns are also used for
6597 verifying volume labels of @command{tar} archives. This section has the
6598 purpose of explaining wildcard syntax for @command{tar}.
6599
6600 @FIXME{the next few paragraphs need work.}
6601
6602 A @var{pattern} should be written according to shell syntax, using wildcard
6603 characters to effect globbing. Most characters in the pattern stand
6604 for themselves in the matched string, and case is significant: @samp{a}
6605 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6606 pattern matches any single character in the matched string. The character
6607 @samp{*} in the pattern matches zero, one, or more single characters in
6608 the matched string. The character @samp{\} says to take the following
6609 character of the pattern @emph{literally}; it is useful when one needs to
6610 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6611
6612 The character @samp{[}, up to the matching @samp{]}, introduces a character
6613 class. A @dfn{character class} is a list of acceptable characters
6614 for the next single character of the matched string. For example,
6615 @samp{[abcde]} would match any of the first five letters of the alphabet.
6616 Note that within a character class, all of the ``special characters''
6617 listed above other than @samp{\} lose their special meaning; for example,
6618 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6619 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6620 the characters @samp{-} and @samp{]} must either come @emph{first} or
6621 @emph{last} in a character class.)
6622
6623 @cindex Excluding characters from a character class
6624 @cindex Character class, excluding characters from
6625 If the first character of the class after the opening @samp{[}
6626 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6627 Rather than listing character to match, it lists those characters which
6628 are @emph{forbidden} as the next single character of the matched string.
6629
6630 Other characters of the class stand for themselves. The special
6631 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6632 letters, is meant to represent all characters between @var{a} and
6633 @var{e}, inclusive.
6634
6635 @FIXME{need to add a sentence or so here to make this clear for those
6636 who don't have dan around.}
6637
6638 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6639 special for wildcard matches. However, if a pattern completely matches
6640 a directory prefix of a matched string, then it matches the full matched
6641 string: thus, excluding a directory also excludes all the files beneath it.
6642
6643 @menu
6644 * controlling pattern-matching::
6645 @end menu
6646
6647 @node controlling pattern-matching
6648 @unnumberedsubsec Controlling Pattern-Matching
6649
6650 For the purposes of this section, we call @dfn{exclusion members} all
6651 member names obtained while processing @option{--exclude} and
6652 @option{--exclude-from} options, and @dfn{inclusion members} those
6653 member names that were given in the command line or read from the file
6654 specified with @option{--files-from} option.
6655
6656 These two pairs of member lists are used in the following operations:
6657 @option{--diff}, @option{--extract}, @option{--list},
6658 @option{--update}.
6659
6660 There are no inclusion members in create mode (@option{--create} and
6661 @option{--append}), since in this mode the names obtained from the
6662 command line refer to @emph{files}, not archive members.
6663
6664 By default, inclusion members are compared with archive members
6665 literally @footnote{Notice that earlier @GNUTAR{} versions used
6666 globbing for inclusion members, which contradicted to UNIX98
6667 specification and was not documented. @xref{Changes}, for more
6668 information on this and other changes.} and exclusion members are
6669 treated as globbing patterns. For example:
6670
6671 @smallexample
6672 @group
6673 $ @kbd{tar tf foo.tar}
6674 a.c
6675 b.c
6676 a.txt
6677 [remarks]
6678 # @i{Member names are used verbatim:}
6679 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6680 [remarks]
6681 # @i{Exclude member names are globbed:}
6682 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6683 a.txt
6684 [remarks]
6685 @end group
6686 @end smallexample
6687
6688 This behavior can be altered by using the following options:
6689
6690 @table @option
6691 @opindex wildcards
6692 @item --wildcards
6693 Treat all member names as wildcards.
6694
6695 @opindex no-wildcards
6696 @item --no-wildcards
6697 Treat all member names as literal strings.
6698 @end table
6699
6700 Thus, to extract files whose names end in @samp{.c}, you can use:
6701
6702 @smallexample
6703 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6704 a.c
6705 b.c
6706 @end smallexample
6707
6708 @noindent
6709 Notice quoting of the pattern to prevent the shell from interpreting
6710 it.
6711
6712 The effect of @option{--wildcards} option is canceled by
6713 @option{--no-wildcards}. This can be used to pass part of
6714 the command line arguments verbatim and other part as globbing
6715 patterns. For example, the following invocation:
6716
6717 @smallexample
6718 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6719 @end smallexample
6720
6721 @noindent
6722 instructs @command{tar} to extract from @file{foo.tar} all files whose
6723 names end in @samp{.txt} and the file named @file{[remarks]}.
6724
6725 Normally, a pattern matches a name if an initial subsequence of the
6726 name's components matches the pattern, where @samp{*}, @samp{?}, and
6727 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6728 and wildcards can match @samp{/}.
6729
6730 Other than optionally stripping leading @samp{/} from names
6731 (@pxref{absolute}), patterns and names are used as-is. For
6732 example, trailing @samp{/} is not trimmed from a user-specified name
6733 before deciding whether to exclude it.
6734
6735 However, this matching procedure can be altered by the options listed
6736 below. These options accumulate. For example:
6737
6738 @smallexample
6739 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6740 @end smallexample
6741
6742 @noindent
6743 ignores case when excluding @samp{makefile}, but not when excluding
6744 @samp{readme}.
6745
6746 @table @option
6747 @opindex anchored
6748 @opindex no-anchored
6749 @item --anchored
6750 @itemx --no-anchored
6751 If anchored, a pattern must match an initial subsequence
6752 of the name's components. Otherwise, the pattern can match any
6753 subsequence. Default is @option{--no-anchored} for exclusion members
6754 and @option{--anchored} inclusion members.
6755
6756 @opindex ignore-case
6757 @opindex no-ignore-case
6758 @item --ignore-case
6759 @itemx --no-ignore-case
6760 When ignoring case, upper-case patterns match lower-case names and vice versa.
6761 When not ignoring case (the default), matching is case-sensitive.
6762
6763 @opindex wildcards-match-slash
6764 @opindex no-wildcards-match-slash
6765 @item --wildcards-match-slash
6766 @itemx --no-wildcards-match-slash
6767 When wildcards match slash (the default for exclusion members), a
6768 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6769 name. Otherwise, @samp{/} is matched only by @samp{/}.
6770
6771 @end table
6772
6773 The @option{--recursion} and @option{--no-recursion} options
6774 (@pxref{recurse}) also affect how member patterns are interpreted. If
6775 recursion is in effect, a pattern matches a name if it matches any of
6776 the name's parent directories.
6777
6778 The following table summarizes pattern-matching default values:
6779
6780 @multitable @columnfractions .3 .7
6781 @headitem Members @tab Default settings
6782 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6783 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6784 @end multitable
6785
6786 @node quoting styles
6787 @section Quoting Member Names
6788
6789 When displaying member names, @command{tar} takes care to avoid
6790 ambiguities caused by certain characters. This is called @dfn{name
6791 quoting}. The characters in question are:
6792
6793 @itemize @bullet
6794 @item Non-printable control characters:
6795
6796 @multitable @columnfractions 0.20 0.10 0.60
6797 @headitem Character @tab ASCII @tab Character name
6798 @item \a @tab 7 @tab Audible bell
6799 @item \b @tab 8 @tab Backspace
6800 @item \f @tab 12 @tab Form feed
6801 @item \n @tab 10 @tab New line
6802 @item \r @tab 13 @tab Carriage return
6803 @item \t @tab 9 @tab Horizontal tabulation
6804 @item \v @tab 11 @tab Vertical tabulation
6805 @end multitable
6806
6807 @item Space (ASCII 32)
6808
6809 @item Single and double quotes (@samp{'} and @samp{"})
6810
6811 @item Backslash (@samp{\})
6812 @end itemize
6813
6814 The exact way @command{tar} uses to quote these characters depends on
6815 the @dfn{quoting style}. The default quoting style, called
6816 @dfn{escape} (see below), uses backslash notation to represent control
6817 characters, space and backslash. Using this quoting style, control
6818 characters are represented as listed in column @samp{Character} in the
6819 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6820
6821 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6822 using @option{--quoting-style} option:
6823
6824 @table @option
6825 @item --quoting-style=@var{style}
6826 @opindex quoting-style
6827
6828 Sets quoting style. Valid values for @var{style} argument are:
6829 literal, shell, shell-always, c, escape, locale, clocale.
6830 @end table
6831
6832 These styles are described in detail below. To illustrate their
6833 effect, we will use an imaginary tar archive @file{arch.tar}
6834 containing the following members:
6835
6836 @smallexample
6837 @group
6838 # 1. Contains horizontal tabulation character.
6839 a tab
6840 # 2. Contains newline character
6841 a
6842 newline
6843 # 3. Contains a space
6844 a space
6845 # 4. Contains double quotes
6846 a"double"quote
6847 # 5. Contains single quotes
6848 a'single'quote
6849 # 6. Contains a backslash character:
6850 a\backslash
6851 @end group
6852 @end smallexample
6853
6854 Here is how usual @command{ls} command would have listed them, if they
6855 had existed in the current working directory:
6856
6857 @smallexample
6858 @group
6859 $ @kbd{ls}
6860 a\ttab
6861 a\nnewline
6862 a\ space
6863 a"double"quote
6864 a'single'quote
6865 a\\backslash
6866 @end group
6867 @end smallexample
6868
6869 Quoting styles:
6870
6871 @table @samp
6872 @item literal
6873 No quoting, display each character as is:
6874
6875 @smallexample
6876 @group
6877 $ @kbd{tar tf arch.tar --quoting-style=literal}
6878 ./
6879 ./a space
6880 ./a'single'quote
6881 ./a"double"quote
6882 ./a\backslash
6883 ./a tab
6884 ./a
6885 newline
6886 @end group
6887 @end smallexample
6888
6889 @item shell
6890 Display characters the same way Bourne shell does:
6891 control characters, except @samp{\t} and @samp{\n}, are printed using
6892 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6893 single quote is printed as @samp{\'}. If a name contains any quoted
6894 characters, it is enclosed in single quotes. In particular, if a name
6895 contains single quotes, it is printed as several single-quoted strings:
6896
6897 @smallexample
6898 @group
6899 $ @kbd{tar tf arch.tar --quoting-style=shell}
6900 ./
6901 './a space'
6902 './a'\''single'\''quote'
6903 './a"double"quote'
6904 './a\backslash'
6905 './a tab'
6906 './a
6907 newline'
6908 @end group
6909 @end smallexample
6910
6911 @item shell-always
6912 Same as @samp{shell}, but the names are always enclosed in single
6913 quotes:
6914
6915 @smallexample
6916 @group
6917 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6918 './'
6919 './a space'
6920 './a'\''single'\''quote'
6921 './a"double"quote'
6922 './a\backslash'
6923 './a tab'
6924 './a
6925 newline'
6926 @end group
6927 @end smallexample
6928
6929 @item c
6930 Use the notation of the C programming language. All names are
6931 enclosed in double quotes. Control characters are quoted using
6932 backslash notations, double quotes are represented as @samp{\"},
6933 backslash characters are represented as @samp{\\}. Single quotes and
6934 spaces are not quoted:
6935
6936 @smallexample
6937 @group
6938 $ @kbd{tar tf arch.tar --quoting-style=c}
6939 "./"
6940 "./a space"
6941 "./a'single'quote"
6942 "./a\"double\"quote"
6943 "./a\\backslash"
6944 "./a\ttab"
6945 "./a\nnewline"
6946 @end group
6947 @end smallexample
6948
6949 @item escape
6950 Control characters are printed using backslash notation, a space is
6951 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6952 default quoting style, unless it was changed when configured the
6953 package.
6954
6955 @smallexample
6956 @group
6957 $ @kbd{tar tf arch.tar --quoting-style=escape}
6958 ./
6959 ./a space
6960 ./a'single'quote
6961 ./a"double"quote
6962 ./a\\backslash
6963 ./a\ttab
6964 ./a\nnewline
6965 @end group
6966 @end smallexample
6967
6968 @item locale
6969 Control characters, single quote and backslash are printed using
6970 backslash notation. All names are quoted using left and right
6971 quotation marks, appropriate to the current locale. If it does not
6972 define quotation marks, use @samp{`} as left and @samp{'} as right
6973 quotation marks. Any occurrences of the right quotation mark in a
6974 name are escaped with @samp{\}, for example:
6975
6976 For example:
6977
6978 @smallexample
6979 @group
6980 $ @kbd{tar tf arch.tar --quoting-style=locale}
6981 `./'
6982 `./a space'
6983 `./a\'single\'quote'
6984 `./a"double"quote'
6985 `./a\\backslash'
6986 `./a\ttab'
6987 `./a\nnewline'
6988 @end group
6989 @end smallexample
6990
6991 @item clocale
6992 Same as @samp{locale}, but @samp{"} is used for both left and right
6993 quotation marks, if not provided by the currently selected locale:
6994
6995 @smallexample
6996 @group
6997 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6998 "./"
6999 "./a space"
7000 "./a'single'quote"
7001 "./a\"double\"quote"
7002 "./a\\backslash"
7003 "./a\ttab"
7004 "./a\nnewline"
7005 @end group
7006 @end smallexample
7007 @end table
7008
7009 You can specify which characters should be quoted in addition to those
7010 implied by the current quoting style:
7011
7012 @table @option
7013 @item --quote-chars=@var{string}
7014 Always quote characters from @var{string}, even if the selected
7015 quoting style would not quote them.
7016 @end table
7017
7018 For example, using @samp{escape} quoting (compare with the usual
7019 escape listing above):
7020
7021 @smallexample
7022 @group
7023 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7024 ./
7025 ./a\ space
7026 ./a'single'quote
7027 ./a\"double\"quote
7028 ./a\\backslash
7029 ./a\ttab
7030 ./a\nnewline
7031 @end group
7032 @end smallexample
7033
7034 To disable quoting of such additional characters, use the following
7035 option:
7036
7037 @table @option
7038 @item --no-quote-chars=@var{string}
7039 Remove characters listed in @var{string} from the list of quoted
7040 characters set by the previous @option{--quote-chars} option.
7041 @end table
7042
7043 This option is particularly useful if you have added
7044 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7045 and wish to disable it for the current invocation.
7046
7047 Note, that @option{--no-quote-chars} does @emph{not} disable those
7048 characters that are quoted by default in the selected quoting style.
7049
7050 @node transform
7051 @section Modifying File and Member Names
7052
7053 @command{Tar} archives contain detailed information about files stored
7054 in them and full file names are part of that information. When
7055 storing file to an archive, its file name is recorded in the archive
7056 along with the actual file contents. When restoring from an archive,
7057 a file is created on disk with exactly the same name as that stored
7058 in the archive. In the majority of cases this is the desired behavior
7059 of a file archiver. However, there are some cases when it is not.
7060
7061 First of all, it is often unsafe to extract archive members with
7062 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7063 takes special precautions when extracting such names and provides a
7064 special option for handling them, which is described in
7065 @ref{absolute}.
7066
7067 Secondly, you may wish to extract file names without some leading
7068 directory components, or with otherwise modified names. In other
7069 cases it is desirable to store files under differing names in the
7070 archive.
7071
7072 @GNUTAR{} provides two options for these needs.
7073
7074 @table @option
7075 @opindex strip-components
7076 @item --strip-components=@var{number}
7077 Strip given @var{number} of leading components from file names before
7078 extraction.
7079 @end table
7080
7081 For example, suppose you have archived whole @file{/usr} hierarchy to
7082 a tar archive named @file{usr.tar}. Among other files, this archive
7083 contains @file{usr/include/stdlib.h}, which you wish to extract to
7084 the current working directory. To do so, you type:
7085
7086 @smallexample
7087 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7088 @end smallexample
7089
7090 The option @option{--strip=2} instructs @command{tar} to strip the
7091 two leading components (@file{usr/} and @file{include/}) off the file
7092 name.
7093
7094 If you add to the above invocation @option{--verbose} (@option{-v})
7095 option, you will note that the verbose listing still contains the
7096 full file name, with the two removed components still in place. This
7097 can be inconvenient, so @command{tar} provides a special option for
7098 altering this behavior:
7099
7100 @anchor{show-transformed-names}
7101 @table @option
7102 @opindex show-transformed-names
7103 @item --show-transformed-names
7104 Display file or member names with all requested transformations
7105 applied.
7106 @end table
7107
7108 @noindent
7109 For example:
7110
7111 @smallexample
7112 @group
7113 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7114 usr/include/stdlib.h
7115 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7116 stdlib.h
7117 @end group
7118 @end smallexample
7119
7120 Notice that in both cases the file is @file{stdlib.h} extracted to the
7121 current working directory, @option{--show-transformed-names} affects
7122 only the way its name is displayed.
7123
7124 This option is especially useful for verifying whether the invocation
7125 will have the desired effect. Thus, before running
7126
7127 @smallexample
7128 $ @kbd{tar -x --strip=@var{n}}
7129 @end smallexample
7130
7131 @noindent
7132 it is often advisable to run
7133
7134 @smallexample
7135 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7136 @end smallexample
7137
7138 @noindent
7139 to make sure the command will produce the intended results.
7140
7141 In case you need to apply more complex modifications to the file name,
7142 @GNUTAR{} provides a general-purpose transformation option:
7143
7144 @table @option
7145 @opindex transform
7146 @item --transform=@var{expression}
7147 Modify file names using supplied @var{expression}.
7148 @end table
7149
7150 @noindent
7151 The @var{expression} is a @command{sed}-like replace expression of the
7152 form:
7153
7154 @smallexample
7155 s/@var{regexp}/@var{replace}/[@var{flags}]
7156 @end smallexample
7157
7158 @noindent
7159 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7160 replacement for each file name part that matches @var{regexp}. Both
7161 @var{regexp} and @var{replace} are described in detail in
7162 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7163
7164 Supported @var{flags} are:
7165
7166 @table @samp
7167 @item g
7168 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7169 just the first.
7170
7171 @item i
7172 Use case-insensitive matching
7173
7174 @item x
7175 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7176 regexps, Extended regular expressions, Extended regular expressions,
7177 sed, GNU sed}).
7178
7179 @item @var{number}
7180 Only replace the @var{number}th match of the @var{regexp}.
7181
7182 Note: the @var{posix} standard does not specify what should happen
7183 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7184 follows the GNU @command{sed} implementation in this regard, so
7185 the interaction is defined to be: ignore matches before the
7186 @var{number}th, and then match and replace all matches from the
7187 @var{number}th on.
7188
7189 @end table
7190
7191 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7192 that it be used consistently throughout the expression. For example,
7193 the following two expressions are equivalent:
7194
7195 @smallexample
7196 @group
7197 s/one/two/
7198 s,one,two,
7199 @end group
7200 @end smallexample
7201
7202 Changing delimiters is often useful when the @var{regex} contains
7203 slashes. For example, it is more convenient to write @code{s,/,-,} than
7204 @code{s/\//-/}.
7205
7206 Here are several examples of @option{--transform} usage:
7207
7208 @enumerate
7209 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7210
7211 @smallexample
7212 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7213 @end smallexample
7214
7215 @item Strip two leading directory components (equivalent to
7216 @option{--strip-components=2}):
7217
7218 @smallexample
7219 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7220 @end smallexample
7221
7222 @item Prepend @file{/prefix/} to each file name:
7223
7224 @smallexample
7225 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7226 @end smallexample
7227
7228 @item Convert each file name to lower case:
7229
7230 @smallexample
7231 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7232 @end smallexample
7233
7234 @end enumerate
7235
7236 Unlike @option{--strip-components}, @option{--transform} can be used
7237 in any @GNUTAR{} operation mode. For example, the following command
7238 adds files to the archive while replacing the leading @file{usr/}
7239 component with @file{var/}:
7240
7241 @smallexample
7242 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7243 @end smallexample
7244
7245 To test @option{--transform} effect we suggest using
7246 @option{--show-transformed-names} option:
7247
7248 @smallexample
7249 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7250 --verbose --show-transformed-names /}
7251 @end smallexample
7252
7253 If both @option{--strip-components} and @option{--transform} are used
7254 together, then @option{--transform} is applied first, and the required
7255 number of components is then stripped from its result.
7256
7257 @node after
7258 @section Operating Only on New Files
7259 @UNREVISED
7260
7261 @cindex Excluding file by age
7262 @cindex Data Modification time, excluding files by
7263 @cindex Modification time, excluding files by
7264 @cindex Age, excluding files by
7265 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7266 @option{-N @var{date}}) option causes @command{tar} to only work on
7267 files whose data modification or status change times are newer than
7268 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7269 it is taken to be a file name; the data modification time of that file
7270 is used as the date. If you use this option when creating or appending
7271 to an archive, the archive will only include new files. If you use
7272 @option{--after-date} when extracting an archive, @command{tar} will
7273 only extract files newer than the @var{date} you specify.
7274
7275 If you only want @command{tar} to make the date comparison based on
7276 modification of the file's data (rather than status
7277 changes), then use the @option{--newer-mtime=@var{date}} option.
7278
7279 You may use these options with any operation. Note that these options
7280 differ from the @option{--update} (@option{-u}) operation in that they
7281 allow you to specify a particular date against which @command{tar} can
7282 compare when deciding whether or not to archive the files.
7283
7284 @table @option
7285 @opindex after-date
7286 @opindex newer
7287 @item --after-date=@var{date}
7288 @itemx --newer=@var{date}
7289 @itemx -N @var{date}
7290 Only store files newer than @var{date}.
7291
7292 Acts on files only if their data modification or status change times are
7293 later than @var{date}. Use in conjunction with any operation.
7294
7295 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7296 name; the data modification time of that file is used as the date.
7297
7298 @opindex newer-mtime
7299 @item --newer-mtime=@var{date}
7300 Acts like @option{--after-date}, but only looks at data modification times.
7301 @end table
7302
7303 These options limit @command{tar} to operate only on files which have
7304 been modified after the date specified. A file's status is considered to have
7305 changed if its contents have been modified, or if its owner,
7306 permissions, and so forth, have been changed. (For more information on
7307 how to specify a date, see @ref{Date input formats}; remember that the
7308 entire date argument must be quoted if it contains any spaces.)
7309
7310 Gurus would say that @option{--after-date} tests both the data
7311 modification time (@code{mtime}, the time the contents of the file
7312 were last modified) and the status change time (@code{ctime}, the time
7313 the file's status was last changed: owner, permissions, etc.@:)
7314 fields, while @option{--newer-mtime} tests only the @code{mtime}
7315 field.
7316
7317 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7318 @code{ctime} and processes the file if either one is more recent than
7319 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7320 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7321 contents of the file were looked at).
7322
7323 Date specifiers can have embedded spaces. Because of this, you may need
7324 to quote date arguments to keep the shell from parsing them as separate
7325 arguments. For example, the following command will add to the archive
7326 all the files modified less than two days ago:
7327
7328 @smallexample
7329 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7330 @end smallexample
7331
7332 When any of these options is used with the option @option{--verbose}
7333 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7334 date back to its textual representation and compare that with the
7335 one given with the option. If the two dates differ, @command{tar} will
7336 print a warning saying what date it will use. This is to help user
7337 ensure he is using the right date. For example:
7338
7339 @smallexample
7340 @group
7341 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7342 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7343 13:19:37.232434
7344 @end group
7345 @end smallexample
7346
7347 @quotation
7348 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7349 should not be used for incremental backups. @xref{Incremental Dumps},
7350 for proper way of creating incremental backups.
7351 @end quotation
7352
7353 @node recurse
7354 @section Descending into Directories
7355 @UNREVISED
7356 @cindex Avoiding recursion in directories
7357 @cindex Descending directories, avoiding
7358 @cindex Directories, avoiding recursion
7359 @cindex Recursion in directories, avoiding
7360
7361 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7362
7363 Usually, @command{tar} will recursively explore all directories (either
7364 those given on the command line or through the @option{--files-from}
7365 option) for the various files they contain. However, you may not always
7366 want @command{tar} to act this way.
7367
7368 @opindex no-recursion
7369 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7370 into specified directories. If you specify @option{--no-recursion}, you can
7371 use the @command{find} utility for hunting through levels of directories to
7372 construct a list of file names which you could then pass to @command{tar}.
7373 @command{find} allows you to be more selective when choosing which files to
7374 archive; see @ref{files}, for more information on using @command{find} with
7375 @command{tar}, or look.
7376
7377 @table @option
7378 @item --no-recursion
7379 Prevents @command{tar} from recursively descending directories.
7380
7381 @opindex recursion
7382 @item --recursion
7383 Requires @command{tar} to recursively descend directories.
7384 This is the default.
7385 @end table
7386
7387 When you use @option{--no-recursion}, @GNUTAR{} grabs
7388 directory entries themselves, but does not descend on them
7389 recursively. Many people use @command{find} for locating files they
7390 want to back up, and since @command{tar} @emph{usually} recursively
7391 descends on directories, they have to use the @samp{@w{-not -type d}}
7392 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7393 find, Finding Files}), as they usually do not want all the files in a
7394 directory. They then use the @option{--files-from} option to archive
7395 the files located via @command{find}.
7396
7397 The problem when restoring files archived in this manner is that the
7398 directories themselves are not in the archive; so the
7399 @option{--same-permissions} (@option{--preserve-permissions},
7400 @option{-p}) option does not affect them---while users might really
7401 like it to. Specifying @option{--no-recursion} is a way to tell
7402 @command{tar} to grab only the directory entries given to it, adding
7403 no new files on its own. To summarize, if you use @command{find} to
7404 create a list of files to be stored in an archive, use it as follows:
7405
7406 @smallexample
7407 @group
7408 $ @kbd{find @var{dir} @var{tests} | \
7409 tar -cf @var{archive} -T - --no-recursion}
7410 @end group
7411 @end smallexample
7412
7413 The @option{--no-recursion} option also applies when extracting: it
7414 causes @command{tar} to extract only the matched directory entries, not
7415 the files under those directories.
7416
7417 The @option{--no-recursion} option also affects how globbing patterns
7418 are interpreted (@pxref{controlling pattern-matching}).
7419
7420 The @option{--no-recursion} and @option{--recursion} options apply to
7421 later options and operands, and can be overridden by later occurrences
7422 of @option{--no-recursion} and @option{--recursion}. For example:
7423
7424 @smallexample
7425 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7426 @end smallexample
7427
7428 @noindent
7429 creates an archive with one entry for @file{grape}, and the recursive
7430 contents of @file{grape/concord}, but no entries under @file{grape}
7431 other than @file{grape/concord}.
7432
7433 @node one
7434 @section Crossing File System Boundaries
7435 @cindex File system boundaries, not crossing
7436 @UNREVISED
7437
7438 @command{tar} will normally automatically cross file system boundaries in
7439 order to archive files which are part of a directory tree. You can
7440 change this behavior by running @command{tar} and specifying
7441 @option{--one-file-system}. This option only affects files that are
7442 archived because they are in a directory that is being archived;
7443 @command{tar} will still archive files explicitly named on the command line
7444 or through @option{--files-from}, regardless of where they reside.
7445
7446 @table @option
7447 @opindex one-file-system
7448 @item --one-file-system
7449 Prevents @command{tar} from crossing file system boundaries when
7450 archiving. Use in conjunction with any write operation.
7451 @end table
7452
7453 The @option{--one-file-system} option causes @command{tar} to modify its
7454 normal behavior in archiving the contents of directories. If a file in
7455 a directory is not on the same file system as the directory itself, then
7456 @command{tar} will not archive that file. If the file is a directory
7457 itself, @command{tar} will not archive anything beneath it; in other words,
7458 @command{tar} will not cross mount points.
7459
7460 This option is useful for making full or incremental archival backups of
7461 a file system. If this option is used in conjunction with
7462 @option{--verbose} (@option{-v}), files that are excluded are
7463 mentioned by name on the standard error.
7464
7465 @menu
7466 * directory:: Changing Directory
7467 * absolute:: Absolute File Names
7468 @end menu
7469
7470 @node directory
7471 @subsection Changing the Working Directory
7472
7473 @FIXME{need to read over this node now for continuity; i've switched
7474 things around some.}
7475
7476 @cindex Changing directory mid-stream
7477 @cindex Directory, changing mid-stream
7478 @cindex Working directory, specifying
7479 To change the working directory in the middle of a list of file names,
7480 either on the command line or in a file specified using
7481 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7482 This will change the working directory to the specified directory
7483 after that point in the list.
7484
7485 @table @option
7486 @opindex directory
7487 @item --directory=@var{directory}
7488 @itemx -C @var{directory}
7489 Changes the working directory in the middle of a command line.
7490 @end table
7491
7492 For example,
7493
7494 @smallexample
7495 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7496 @end smallexample
7497
7498 @noindent
7499 will place the files @file{grape} and @file{prune} from the current
7500 directory into the archive @file{jams.tar}, followed by the file
7501 @file{cherry} from the directory @file{food}. This option is especially
7502 useful when you have several widely separated files that you want to
7503 store in the same archive.
7504
7505 Note that the file @file{cherry} is recorded in the archive under the
7506 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7507 archive will contain three files that all appear to have come from the
7508 same directory; if the archive is extracted with plain @samp{tar
7509 --extract}, all three files will be written in the current directory.
7510
7511 Contrast this with the command,
7512
7513 @smallexample
7514 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7515 @end smallexample
7516
7517 @noindent
7518 which records the third file in the archive under the name
7519 @file{red/cherry} so that, if the archive is extracted using
7520 @samp{tar --extract}, the third file will be written in a subdirectory
7521 named @file{orange-colored}.
7522
7523 You can use the @option{--directory} option to make the archive
7524 independent of the original name of the directory holding the files.
7525 The following command places the files @file{/etc/passwd},
7526 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7527 @file{foo.tar}:
7528
7529 @smallexample
7530 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7531 @end smallexample
7532
7533 @noindent
7534 However, the names of the archive members will be exactly what they were
7535 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7536 They will not appear to be related by file name to the original
7537 directories where those files were located.
7538
7539 Note that @option{--directory} options are interpreted consecutively. If
7540 @option{--directory} specifies a relative file name, it is interpreted
7541 relative to the then current directory, which might not be the same as
7542 the original current working directory of @command{tar}, due to a previous
7543 @option{--directory} option.
7544
7545 When using @option{--files-from} (@pxref{files}), you can put various
7546 @command{tar} options (including @option{-C}) in the file list. Notice,
7547 however, that in this case the option and its argument may not be
7548 separated by whitespace. If you use short option, its argument must
7549 either follow the option letter immediately, without any intervening
7550 whitespace, or occupy the next line. Otherwise, if you use long
7551 option, separate its argument by an equal sign.
7552
7553 For instance, the file list for the above example will be:
7554
7555 @smallexample
7556 @group
7557 -C/etc
7558 passwd
7559 hosts
7560 --directory=/lib
7561 libc.a
7562 @end group
7563 @end smallexample
7564
7565 @noindent
7566 To use it, you would invoke @command{tar} as follows:
7567
7568 @smallexample
7569 $ @kbd{tar -c -f foo.tar --files-from list}
7570 @end smallexample
7571
7572 The interpretation of @option{--directory} is disabled by
7573 @option{--null} option.
7574
7575 @node absolute
7576 @subsection Absolute File Names
7577 @UNREVISED
7578
7579 @table @option
7580 @opindex absolute-names
7581 @item --absolute-names
7582 @itemx -P
7583 Do not strip leading slashes from file names, and permit file names
7584 containing a @file{..} file name component.
7585 @end table
7586
7587 By default, @GNUTAR{} drops a leading @samp{/} on
7588 input or output, and complains about file names containing a @file{..}
7589 component. This option turns off this behavior.
7590
7591 When @command{tar} extracts archive members from an archive, it strips any
7592 leading slashes (@samp{/}) from the member name. This causes absolute
7593 member names in the archive to be treated as relative file names. This
7594 allows you to have such members extracted wherever you want, instead of
7595 being restricted to extracting the member in the exact directory named
7596 in the archive. For example, if the archive member has the name
7597 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7598 really @file{etc/passwd}.
7599
7600 File names containing @file{..} can cause problems when extracting, so
7601 @command{tar} normally warns you about such files when creating an
7602 archive, and rejects attempts to extracts such files.
7603
7604 Other @command{tar} programs do not do this. As a result, if you
7605 create an archive whose member names start with a slash, they will be
7606 difficult for other people with a non-@GNUTAR{}
7607 program to use. Therefore, @GNUTAR{} also strips
7608 leading slashes from member names when putting members into the
7609 archive. For example, if you ask @command{tar} to add the file
7610 @file{/bin/ls} to an archive, it will do so, but the member name will
7611 be @file{bin/ls}.@footnote{A side effect of this is that when
7612 @option{--create} is used with @option{--verbose} the resulting output
7613 is not, generally speaking, the same as the one you'd get running
7614 @kbd{tar --list} command. This may be important if you use some
7615 scripts for comparing both outputs. @xref{listing member and file names},
7616 for the information on how to handle this case.}
7617
7618 If you use the @option{--absolute-names} (@option{-P}) option,
7619 @command{tar} will do none of these transformations.
7620
7621 To archive or extract files relative to the root directory, specify
7622 the @option{--absolute-names} (@option{-P}) option.
7623
7624 Normally, @command{tar} acts on files relative to the working
7625 directory---ignoring superior directory names when archiving, and
7626 ignoring leading slashes when extracting.
7627
7628 When you specify @option{--absolute-names} (@option{-P}),
7629 @command{tar} stores file names including all superior directory
7630 names, and preserves leading slashes. If you only invoked
7631 @command{tar} from the root directory you would never need the
7632 @option{--absolute-names} option, but using this option
7633 may be more convenient than switching to root.
7634
7635 @FIXME{Should be an example in the tutorial/wizardry section using this
7636 to transfer files between systems.}
7637
7638 @FIXME{Is write access an issue?}
7639
7640 @table @option
7641 @item --absolute-names
7642 Preserves full file names (including superior directory names) when
7643 archiving files. Preserves leading slash when extracting files.
7644
7645 @end table
7646
7647 @FIXME{this is still horrible; need to talk with dan on monday.}
7648
7649 @command{tar} prints out a message about removing the @samp{/} from
7650 file names. This message appears once per @GNUTAR{}
7651 invocation. It represents something which ought to be told; ignoring
7652 what it means can cause very serious surprises, later.
7653
7654 Some people, nevertheless, do not want to see this message. Wanting to
7655 play really dangerously, one may of course redirect @command{tar} standard
7656 error to the sink. For example, under @command{sh}:
7657
7658 @smallexample
7659 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7660 @end smallexample
7661
7662 @noindent
7663 Another solution, both nicer and simpler, would be to change to
7664 the @file{/} directory first, and then avoid absolute notation.
7665 For example:
7666
7667 @smallexample
7668 $ @kbd{(cd / && tar -c -f archive.tar home)}
7669 # @i{or}:
7670 $ @kbd{tar -c -f archive.tar -C / home}
7671 @end smallexample
7672
7673 @include getdate.texi
7674
7675 @node Formats
7676 @chapter Controlling the Archive Format
7677
7678 @cindex Tar archive formats
7679 Due to historical reasons, there are several formats of tar archives.
7680 All of them are based on the same principles, but have some subtle
7681 differences that often make them incompatible with each other.
7682
7683 GNU tar is able to create and handle archives in a variety of formats.
7684 The most frequently used formats are (in alphabetical order):
7685
7686 @table @asis
7687 @item gnu
7688 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7689 from an early @acronym{POSIX} standard, adding some improvements such as
7690 sparse file handling and incremental archives. Unfortunately these
7691 features were implemented in a way incompatible with other archive
7692 formats.
7693
7694 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7695 length.
7696
7697 @item oldgnu
7698 Format used by @GNUTAR{} of versions prior to 1.12.
7699
7700 @item v7
7701 Archive format, compatible with the V7 implementation of tar. This
7702 format imposes a number of limitations. The most important of them
7703 are:
7704
7705 @enumerate
7706 @item The maximum length of a file name is limited to 99 characters.
7707 @item The maximum length of a symbolic link is limited to 99 characters.
7708 @item It is impossible to store special files (block and character
7709 devices, fifos etc.)
7710 @item Maximum value of user or group ID is limited to 2097151 (7777777
7711 octal)
7712 @item V7 archives do not contain symbolic ownership information (user
7713 and group name of the file owner).
7714 @end enumerate
7715
7716 This format has traditionally been used by Automake when producing
7717 Makefiles. This practice will change in the future, in the meantime,
7718 however this means that projects containing filenames more than 99
7719 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7720 Automake prior to 1.9.
7721
7722 @item ustar
7723 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7724 symbolic ownership information. It is also able to store
7725 special files. However, it imposes several restrictions as well:
7726
7727 @enumerate
7728 @item The maximum length of a file name is limited to 256 characters,
7729 provided that the filename can be split at directory separator in
7730 two parts, first of them being at most 155 bytes long. So, in most
7731 cases the maximum file name length will be shorter than 256
7732 characters.
7733 @item The maximum length of a symbolic link name is limited to
7734 100 characters.
7735 @item Maximum size of a file the archive is able to accommodate
7736 is 8GB
7737 @item Maximum value of UID/GID is 2097151.
7738 @item Maximum number of bits in device major and minor numbers is 21.
7739 @end enumerate
7740
7741 @item star
7742 Format used by J@"org Schilling @command{star}
7743 implementation. @GNUTAR{} is able to read @samp{star} archives but
7744 currently does not produce them.
7745
7746 @item posix
7747 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7748 most flexible and feature-rich format. It does not impose any
7749 restrictions on file sizes or filename lengths. This format is quite
7750 recent, so not all tar implementations are able to handle it properly.
7751 However, this format is designed in such a way that any tar
7752 implementation able to read @samp{ustar} archives will be able to read
7753 most @samp{posix} archives as well, with the only exception that any
7754 additional information (such as long file names etc.) will in such
7755 case be extracted as plain text files along with the files it refers to.
7756
7757 This archive format will be the default format for future versions
7758 of @GNUTAR{}.
7759
7760 @end table
7761
7762 The following table summarizes the limitations of each of these
7763 formats:
7764
7765 @multitable @columnfractions .10 .20 .20 .20 .20
7766 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7767 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7768 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7769 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7770 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7771 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7772 @end multitable
7773
7774 The default format for @GNUTAR{} is defined at compilation
7775 time. You may check it by running @command{tar --help}, and examining
7776 the last lines of its output. Usually, @GNUTAR{} is configured
7777 to create archives in @samp{gnu} format, however, future version will
7778 switch to @samp{posix}.
7779
7780 @menu
7781 * Compression:: Using Less Space through Compression
7782 * Attributes:: Handling File Attributes
7783 * Portability:: Making @command{tar} Archives More Portable
7784 * cpio:: Comparison of @command{tar} and @command{cpio}
7785 @end menu
7786
7787 @node Compression
7788 @section Using Less Space through Compression
7789
7790 @menu
7791 * gzip:: Creating and Reading Compressed Archives
7792 * sparse:: Archiving Sparse Files
7793 @end menu
7794
7795 @node gzip
7796 @subsection Creating and Reading Compressed Archives
7797 @cindex Compressed archives
7798 @cindex Storing archives in compressed format
7799
7800 @GNUTAR{} is able to create and read compressed archives. It supports
7801 @command{gzip} and @command{bzip2} compression programs. For backward
7802 compatibility, it also supports @command{compress} command, although
7803 we strongly recommend against using it, since there is a patent
7804 covering the algorithm it uses and you could be sued for patent
7805 infringement merely by running @command{compress}! Besides, it is less
7806 effective than @command{gzip} and @command{bzip2}.
7807
7808 Creating a compressed archive is simple: you just specify a
7809 @dfn{compression option} along with the usual archive creation
7810 commands. The compression option is @option{-z} (@option{--gzip}) to
7811 create a @command{gzip} compressed archive, @option{-j}
7812 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7813 @option{-Z} (@option{--compress}) to use @command{compress} program.
7814 For example:
7815
7816 @smallexample
7817 $ @kbd{tar cfz archive.tar.gz .}
7818 @end smallexample
7819
7820 Reading compressed archive is even simpler: you don't need to specify
7821 any additional options as @GNUTAR{} recognizes its format
7822 automatically. Thus, the following commands will list and extract the
7823 archive created in previous example:
7824
7825 @smallexample
7826 # List the compressed archive
7827 $ @kbd{tar tf archive.tar.gz}
7828 # Extract the compressed archive
7829 $ @kbd{tar xf archive.tar.gz}
7830 @end smallexample
7831
7832 The only case when you have to specify a decompression option while
7833 reading the archive is when reading from a pipe or from a tape drive
7834 that does not support random access. However, in this case @GNUTAR{}
7835 will indicate which option you should use. For example:
7836
7837 @smallexample
7838 $ @kbd{cat archive.tar.gz | tar tf -}
7839 tar: Archive is compressed. Use -z option
7840 tar: Error is not recoverable: exiting now
7841 @end smallexample
7842
7843 If you see such diagnostics, just add the suggested option to the
7844 invocation of @GNUTAR{}:
7845
7846 @smallexample
7847 $ @kbd{cat archive.tar.gz | tar tfz -}
7848 @end smallexample
7849
7850 Notice also, that there are several restrictions on operations on
7851 compressed archives. First of all, compressed archives cannot be
7852 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
7853 (@option{--delete}) members from them. Likewise, you cannot append
7854 another @command{tar} archive to a compressed archive using
7855 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
7856 compressed.
7857
7858 The following table summarizes compression options used by @GNUTAR{}.
7859
7860 @table @option
7861 @opindex gzip
7862 @opindex ungzip
7863 @item -z
7864 @itemx --gzip
7865 @itemx --ungzip
7866 Filter the archive through @command{gzip}.
7867
7868 You can use @option{--gzip} and @option{--gunzip} on physical devices
7869 (tape drives, etc.) and remote files as well as on normal files; data
7870 to or from such devices or remote files is reblocked by another copy
7871 of the @command{tar} program to enforce the specified (or default) record
7872 size. The default compression parameters are used; if you need to
7873 override them, set @env{GZIP} environment variable, e.g.:
7874
7875 @smallexample
7876 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
7877 @end smallexample
7878
7879 @noindent
7880 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
7881 @command{gzip} explicitly:
7882
7883 @smallexample
7884 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
7885 @end smallexample
7886
7887 @cindex corrupted archives
7888 About corrupted compressed archives: @command{gzip}'ed files have no
7889 redundancy, for maximum compression. The adaptive nature of the
7890 compression scheme means that the compression tables are implicitly
7891 spread all over the archive. If you lose a few blocks, the dynamic
7892 construction of the compression tables becomes unsynchronized, and there
7893 is little chance that you could recover later in the archive.
7894
7895 There are pending suggestions for having a per-volume or per-file
7896 compression in @GNUTAR{}. This would allow for viewing the
7897 contents without decompression, and for resynchronizing decompression at
7898 every volume or file, in case of corrupted archives. Doing so, we might
7899 lose some compressibility. But this would have make recovering easier.
7900 So, there are pros and cons. We'll see!
7901
7902 @opindex bzip2
7903 @item -j
7904 @itemx --bzip2
7905 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
7906
7907 @opindex compress
7908 @opindex uncompress
7909 @item -Z
7910 @itemx --compress
7911 @itemx --uncompress
7912 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
7913
7914 The @acronym{GNU} Project recommends you not use
7915 @command{compress}, because there is a patent covering the algorithm it
7916 uses. You could be sued for patent infringement merely by running
7917 @command{compress}.
7918
7919 @opindex use-compress-program
7920 @item --use-compress-program=@var{prog}
7921 Use external compression program @var{prog}. Use this option if you
7922 have a compression program that @GNUTAR{} does not support. There
7923 are two requirements to which @var{prog} should comply:
7924
7925 First, when called without options, it should read data from standard
7926 input, compress it and output it on standard output.
7927
7928 Secondly, if called with @option{-d} argument, it should do exactly
7929 the opposite, i.e., read the compressed data from the standard input
7930 and produce uncompressed data on the standard output.
7931 @end table
7932
7933 @cindex gpg, using with tar
7934 @cindex gnupg, using with tar
7935 @cindex Using encrypted archives
7936 The @option{--use-compress-program} option, in particular, lets you
7937 implement your own filters, not necessarily dealing with
7938 compression/decompression. For example, suppose you wish to implement
7939 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
7940 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
7941 Manual}). The following script does that:
7942
7943 @smallexample
7944 @group
7945 #! /bin/sh
7946 case $1 in
7947 -d) gpg --decrypt - | gzip -d -c;;
7948 '') gzip -c | gpg -s ;;
7949 *) echo "Unknown option $1">&2; exit 1;;
7950 esac
7951 @end group
7952 @end smallexample
7953
7954 Suppose you name it @file{gpgz} and save it somewhere in your
7955 @env{PATH}. Then the following command will create a compressed
7956 archive signed with your private key:
7957
7958 @smallexample
7959 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
7960 @end smallexample
7961
7962 @noindent
7963 Likewise, the following command will list its contents:
7964
7965 @smallexample
7966 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
7967 @end smallexample
7968
7969 @ignore
7970 The above is based on the following discussion:
7971
7972 I have one question, or maybe it's a suggestion if there isn't a way
7973 to do it now. I would like to use @option{--gzip}, but I'd also like
7974 the output to be fed through a program like @acronym{GNU}
7975 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7976 to use :-)), basically adding ECC protection on top of compression.
7977 It seems as if this should be quite easy to do, but I can't work out
7978 exactly how to go about it. Of course, I can pipe the standard output
7979 of @command{tar} through @command{ecc}, but then I lose (though I
7980 haven't started using it yet, I confess) the ability to have
7981 @command{tar} use @command{rmt} for it's I/O (I think).
7982
7983 I think the most straightforward thing would be to let me specify a
7984 general set of filters outboard of compression (preferably ordered,
7985 so the order can be automatically reversed on input operations, and
7986 with the options they require specifiable), but beggars shouldn't be
7987 choosers and anything you decide on would be fine with me.
7988
7989 By the way, I like @command{ecc} but if (as the comments say) it can't
7990 deal with loss of block sync, I'm tempted to throw some time at adding
7991 that capability. Supposing I were to actually do such a thing and
7992 get it (apparently) working, do you accept contributed changes to
7993 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7994
7995 Isn't that exactly the role of the
7996 @option{--use-compress-prog=@var{program}} option?
7997 I never tried it myself, but I suspect you may want to write a
7998 @var{prog} script or program able to filter stdin to stdout to
7999 way you want. It should recognize the @option{-d} option, for when
8000 extraction is needed rather than creation.
8001
8002 It has been reported that if one writes compressed data (through the
8003 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
8004 the DLT compression mode, the data will actually get bigger and one will
8005 end up with less space on the tape.
8006 @end ignore
8007
8008 @node sparse
8009 @subsection Archiving Sparse Files
8010 @cindex Sparse Files
8011
8012 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
8013 in a file is a section of the file's contents which was never written.
8014 The contents of a hole reads as all zeros. On many operating systems,
8015 actual disk storage is not allocated for holes, but they are counted
8016 in the length of the file. If you archive such a file, @command{tar}
8017 could create an archive longer than the original. To have @command{tar}
8018 attempt to recognize the holes in a file, use @option{--sparse}
8019 (@option{-S}). When you use this option, then, for any file using
8020 less disk space than would be expected from its length, @command{tar}
8021 searches the file for consecutive stretches of zeros. It then records
8022 in the archive for the file where the consecutive stretches of zeros
8023 are, and only archives the ``real contents'' of the file. On
8024 extraction (using @option{--sparse} is not needed on extraction) any
8025 such files have holes created wherever the continuous stretches of zeros
8026 were found. Thus, if you use @option{--sparse}, @command{tar} archives
8027 won't take more space than the original.
8028
8029 @table @option
8030 @opindex sparse
8031 @item -S
8032 @itemx --sparse
8033 This option instructs @command{tar} to test each file for sparseness
8034 before attempting to archive it. If the file is found to be sparse it
8035 is treated specially, thus allowing to decrease the amount of space
8036 used by its image in the archive.
8037
8038 This option is meaningful only when creating or updating archives. It
8039 has no effect on extraction.
8040 @end table
8041
8042 Consider using @option{--sparse} when performing file system backups,
8043 to avoid archiving the expanded forms of files stored sparsely in the
8044 system.
8045
8046 Even if your system has no sparse files currently, some may be
8047 created in the future. If you use @option{--sparse} while making file
8048 system backups as a matter of course, you can be assured the archive
8049 will never take more space on the media than the files take on disk
8050 (otherwise, archiving a disk filled with sparse files might take
8051 hundreds of tapes). @xref{Incremental Dumps}.
8052
8053 However, be aware that @option{--sparse} option presents a serious
8054 drawback. Namely, in order to determine if the file is sparse
8055 @command{tar} has to read it before trying to archive it, so in total
8056 the file is read @strong{twice}. So, always bear in mind that the
8057 time needed to process all files with this option is roughly twice
8058 the time needed to archive them without it.
8059 @FIXME{A technical note:
8060
8061 Programs like @command{dump} do not have to read the entire file; by
8062 examining the file system directly, they can determine in advance
8063 exactly where the holes are and thus avoid reading through them. The
8064 only data it need read are the actual allocated data blocks.
8065 @GNUTAR{} uses a more portable and straightforward
8066 archiving approach, it would be fairly difficult that it does
8067 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8068 1990-12-10:
8069
8070 @quotation
8071 What I did say is that you cannot tell the difference between a hole and an
8072 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8073 best tells you how many holes there are; it doesn't tell you @emph{where}.
8074 Just as programs may, conceivably, care what @code{st_blocks} is (care
8075 to name one that does?), they may also care where the holes are (I have
8076 no examples of this one either, but it's equally imaginable).
8077
8078 I conclude from this that good archivers are not portable. One can
8079 arguably conclude that if you want a portable program, you can in good
8080 conscience restore files with as many holes as possible, since you can't
8081 get it right.
8082 @end quotation
8083 }
8084
8085 @cindex sparse formats, defined
8086 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8087 sparse files using in three distinct ways, called @dfn{sparse
8088 formats}. A sparse format is identified by its @dfn{number},
8089 consisting, as usual of two decimal numbers, delimited by a dot. By
8090 default, format @samp{1.0} is used. If, for some reason, you wish to
8091 use an earlier format, you can select it using
8092 @option{--sparse-version} option.
8093
8094 @table @option
8095 @opindex sparse-version
8096 @item --sparse-version=@var{version}
8097
8098 Select the format to store sparse files in. Valid @var{version} values
8099 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8100 for a detailed description of each format.
8101 @end table
8102
8103 Using @option{--sparse-format} option implies @option{--sparse}.
8104
8105 @node Attributes
8106 @section Handling File Attributes
8107 @UNREVISED
8108
8109 When @command{tar} reads files, it updates their access times. To
8110 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8111 reset the access time retroactively or avoid changing it in the first
8112 place.
8113
8114 Handling of file attributes
8115
8116 @table @option
8117 @opindex atime-preserve
8118 @item --atime-preserve
8119 @itemx --atime-preserve=replace
8120 @itemx --atime-preserve=system
8121 Preserve the access times of files that are read. This works only for
8122 files that you own, unless you have superuser privileges.
8123
8124 @option{--atime-preserve=replace} works on most systems, but it also
8125 restores the data modification time and updates the status change
8126 time. Hence it doesn't interact with incremental dumps nicely
8127 (@pxref{Incremental Dumps}), and it can set access or data modification times
8128 incorrectly if other programs access the file while @command{tar} is
8129 running.
8130
8131 @option{--atime-preserve=system} avoids changing the access time in
8132 the first place, if the operating system supports this.
8133 Unfortunately, this may or may not work on any given operating system
8134 or file system. If @command{tar} knows for sure it won't work, it
8135 complains right away.
8136
8137 Currently @option{--atime-preserve} with no operand defaults to
8138 @option{--atime-preserve=replace}, but this is intended to change to
8139 @option{--atime-preserve=system} when the latter is better-supported.
8140
8141 @opindex touch
8142 @item -m
8143 @itemx --touch
8144 Do not extract data modification time.
8145
8146 When this option is used, @command{tar} leaves the data modification times
8147 of the files it extracts as the times when the files were extracted,
8148 instead of setting it to the times recorded in the archive.
8149
8150 This option is meaningless with @option{--list} (@option{-t}).
8151
8152 @opindex same-owner
8153 @item --same-owner
8154 Create extracted files with the same ownership they have in the
8155 archive.
8156
8157 This is the default behavior for the superuser,
8158 so this option is meaningful only for non-root users, when @command{tar}
8159 is executed on those systems able to give files away. This is
8160 considered as a security flaw by many people, at least because it
8161 makes quite difficult to correctly account users for the disk space
8162 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8163 files are easily and silently lost when files are given away.
8164
8165 When writing an archive, @command{tar} writes the user id and user name
8166 separately. If it can't find a user name (because the user id is not
8167 in @file{/etc/passwd}), then it does not write one. When restoring,
8168 it tries to look the name (if one was written) up in
8169 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8170 the archive instead.
8171
8172 @opindex no-same-owner
8173 @item --no-same-owner
8174 @itemx -o
8175 Do not attempt to restore ownership when extracting. This is the
8176 default behavior for ordinary users, so this option has an effect
8177 only for the superuser.
8178
8179 @opindex numeric-owner
8180 @item --numeric-owner
8181 The @option{--numeric-owner} option allows (ANSI) archives to be written
8182 without user/group name information or such information to be ignored
8183 when extracting. It effectively disables the generation and/or use
8184 of user/group name information. This option forces extraction using
8185 the numeric ids from the archive, ignoring the names.
8186
8187 This is useful in certain circumstances, when restoring a backup from
8188 an emergency floppy with different passwd/group files for example.
8189 It is otherwise impossible to extract files with the right ownerships
8190 if the password file in use during the extraction does not match the
8191 one belonging to the file system(s) being extracted. This occurs,
8192 for example, if you are restoring your files after a major crash and
8193 had booted from an emergency floppy with no password file or put your
8194 disk into another machine to do the restore.
8195
8196 The numeric ids are @emph{always} saved into @command{tar} archives.
8197 The identifying names are added at create time when provided by the
8198 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8199 used when moving archives between a collection of machines using
8200 a centralized management for attribution of numeric ids to users
8201 and groups. This is often made through using the NIS capabilities.
8202
8203 When making a @command{tar} file for distribution to other sites, it
8204 is sometimes cleaner to use a single owner for all files in the
8205 distribution, and nicer to specify the write permission bits of the
8206 files as stored in the archive independently of their actual value on
8207 the file system. The way to prepare a clean distribution is usually
8208 to have some Makefile rule creating a directory, copying all needed
8209 files in that directory, then setting ownership and permissions as
8210 wanted (there are a lot of possible schemes), and only then making a
8211 @command{tar} archive out of this directory, before cleaning
8212 everything out. Of course, we could add a lot of options to
8213 @GNUTAR{} for fine tuning permissions and ownership.
8214 This is not the good way, I think. @GNUTAR{} is
8215 already crowded with options and moreover, the approach just explained
8216 gives you a great deal of control already.
8217
8218 @xopindex{same-permissions, short description}
8219 @xopindex{preserve-permissions, short description}
8220 @item -p
8221 @itemx --same-permissions
8222 @itemx --preserve-permissions
8223 Extract all protection information.
8224
8225 This option causes @command{tar} to set the modes (access permissions) of
8226 extracted files exactly as recorded in the archive. If this option
8227 is not used, the current @code{umask} setting limits the permissions
8228 on extracted files. This option is by default enabled when
8229 @command{tar} is executed by a superuser.
8230
8231
8232 This option is meaningless with @option{--list} (@option{-t}).
8233
8234 @opindex preserve
8235 @item --preserve
8236 Same as both @option{--same-permissions} and @option{--same-order}.
8237
8238 The @option{--preserve} option has no equivalent short option name.
8239 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8240
8241 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8242 Neither do I. --Sergey}
8243
8244 @end table
8245
8246 @node Portability
8247 @section Making @command{tar} Archives More Portable
8248
8249 Creating a @command{tar} archive on a particular system that is meant to be
8250 useful later on many other machines and with other versions of @command{tar}
8251 is more challenging than you might think. @command{tar} archive formats
8252 have been evolving since the first versions of Unix. Many such formats
8253 are around, and are not always compatible with each other. This section
8254 discusses a few problems, and gives some advice about making @command{tar}
8255 archives more portable.
8256
8257 One golden rule is simplicity. For example, limit your @command{tar}
8258 archives to contain only regular files and directories, avoiding
8259 other kind of special files. Do not attempt to save sparse files or
8260 contiguous files as such. Let's discuss a few more problems, in turn.
8261
8262 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8263 archives and archive labels) in GNU and PAX formats.}
8264
8265 @menu
8266 * Portable Names:: Portable Names
8267 * dereference:: Symbolic Links
8268 * old:: Old V7 Archives
8269 * ustar:: Ustar Archives
8270 * gnu:: GNU and old GNU format archives.
8271 * posix:: @acronym{POSIX} archives
8272 * Checksumming:: Checksumming Problems
8273 * Large or Negative Values:: Large files, negative time stamps, etc.
8274 * Other Tars:: How to Extract GNU-Specific Data Using
8275 Other @command{tar} Implementations
8276 @end menu
8277
8278 @node Portable Names
8279 @subsection Portable Names
8280
8281 Use portable file and member names. A name is portable if it contains
8282 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8283 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8284 contain @samp{/-}. Avoid deep directory nesting. For portability to
8285 old Unix hosts, limit your file name components to 14 characters or
8286 less.
8287
8288 If you intend to have your @command{tar} archives to be read under
8289 MSDOS, you should not rely on case distinction for file names, and you
8290 might use the @acronym{GNU} @command{doschk} program for helping you
8291 further diagnosing illegal MSDOS names, which are even more limited
8292 than System V's.
8293
8294 @node dereference
8295 @subsection Symbolic Links
8296 @cindex File names, using symbolic links
8297 @cindex Symbolic link as file name
8298
8299 @opindex dereference
8300 Normally, when @command{tar} archives a symbolic link, it writes a
8301 block to the archive naming the target of the link. In that way, the
8302 @command{tar} archive is a faithful record of the file system contents.
8303 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8304 @command{tar} to archive the files symbolic links point to, instead of
8305 the links themselves. When this option is used, when @command{tar}
8306 encounters a symbolic link, it will archive the linked-to file,
8307 instead of simply recording the presence of a symbolic link.
8308
8309 The name under which the file is stored in the file system is not
8310 recorded in the archive. To record both the symbolic link name and
8311 the file name in the system, archive the file under both names. If
8312 all links were recorded automatically by @command{tar}, an extracted file
8313 might be linked to a file name that no longer exists in the file
8314 system.
8315
8316 If a linked-to file is encountered again by @command{tar} while creating
8317 the same archive, an entire second copy of it will be stored. (This
8318 @emph{might} be considered a bug.)
8319
8320 So, for portable archives, do not archive symbolic links as such,
8321 and use @option{--dereference} (@option{-h}): many systems do not support
8322 symbolic links, and moreover, your distribution might be unusable if
8323 it contains unresolved symbolic links.
8324
8325 @node old
8326 @subsection Old V7 Archives
8327 @cindex Format, old style
8328 @cindex Old style format
8329 @cindex Old style archives
8330 @cindex v7 archive format
8331
8332 Certain old versions of @command{tar} cannot handle additional
8333 information recorded by newer @command{tar} programs. To create an
8334 archive in V7 format (not ANSI), which can be read by these old
8335 versions, specify the @option{--format=v7} option in
8336 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8337 accepts @option{--portability} or @option{--old-archive} for this
8338 option). When you specify it,
8339 @command{tar} leaves out information about directories, pipes, fifos,
8340 contiguous files, and device files, and specifies file ownership by
8341 group and user IDs instead of group and user names.
8342
8343 When updating an archive, do not use @option{--format=v7}
8344 unless the archive was created using this option.
8345
8346 In most cases, a @emph{new} format archive can be read by an @emph{old}
8347 @command{tar} program without serious trouble, so this option should
8348 seldom be needed. On the other hand, most modern @command{tar}s are
8349 able to read old format archives, so it might be safer for you to
8350 always use @option{--format=v7} for your distributions. Notice,
8351 however, that @samp{ustar} format is a better alternative, as it is
8352 free from many of @samp{v7}'s drawbacks.
8353
8354 @node ustar
8355 @subsection Ustar Archive Format
8356
8357 @cindex ustar archive format
8358 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8359 @code{ustar}. Although it is more flexible than the V7 format, it
8360 still has many restrictions (@xref{Formats,ustar}, for the detailed
8361 description of @code{ustar} format). Along with V7 format,
8362 @code{ustar} format is a good choice for archives intended to be read
8363 with other implementations of @command{tar}.
8364
8365 To create archive in @code{ustar} format, use @option{--format=ustar}
8366 option in conjunction with the @option{--create} (@option{-c}).
8367
8368 @node gnu
8369 @subsection @acronym{GNU} and old @GNUTAR{} format
8370
8371 @cindex GNU archive format
8372 @cindex Old GNU archive format
8373 @GNUTAR{} was based on an early draft of the
8374 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8375 @command{tar}, such as the support for file names longer than 100
8376 characters, use portions of the @command{tar} header record which were
8377 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8378 @acronym{POSIX} have allocated the same parts of the header record for
8379 other purposes. As a result, @GNUTAR{} format is
8380 incompatible with the current @acronym{POSIX} specification, and with
8381 @command{tar} programs that follow it.
8382
8383 In the majority of cases, @command{tar} will be configured to create
8384 this format by default. This will change in the future releases, since
8385 we plan to make @samp{POSIX} format the default.
8386
8387 To force creation a @GNUTAR{} archive, use option
8388 @option{--format=gnu}.
8389
8390 @node posix
8391 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8392
8393 @cindex POSIX archive format
8394 @cindex PAX archive format
8395 Starting from version 1.14 @GNUTAR{} features full support for
8396 @acronym{POSIX.1-2001} archives.
8397
8398 A @acronym{POSIX} conformant archive will be created if @command{tar}
8399 was given @option{--format=posix} (@option{--format=pax}) option. No
8400 special option is required to read and extract from a @acronym{POSIX}
8401 archive.
8402
8403 @menu
8404 * PAX keywords:: Controlling Extended Header Keywords.
8405 @end menu
8406
8407 @node PAX keywords
8408 @subsubsection Controlling Extended Header Keywords
8409
8410 @table @option
8411 @opindex pax-option
8412 @item --pax-option=@var{keyword-list}
8413 Handle keywords in @acronym{PAX} extended headers. This option is
8414 equivalent to @option{-o} option of the @command{pax} utility.
8415 @end table
8416
8417 @var{Keyword-list} is a comma-separated
8418 list of keyword options, each keyword option taking one of
8419 the following forms:
8420
8421 @table @code
8422 @item delete=@var{pattern}
8423 When used with one of archive-creation commands,
8424 this option instructs @command{tar} to omit from extended header records
8425 that it produces any keywords matching the string @var{pattern}.
8426
8427 When used in extract or list mode, this option instructs tar
8428 to ignore any keywords matching the given @var{pattern} in the extended
8429 header records. In both cases, matching is performed using the pattern
8430 matching notation described in @acronym{POSIX 1003.2}, 3.13
8431 (@pxref{wildcards}). For example:
8432
8433 @smallexample
8434 --pax-option delete=security.*
8435 @end smallexample
8436
8437 would suppress security-related information.
8438
8439 @item exthdr.name=@var{string}
8440
8441 This keyword allows user control over the name that is written into the
8442 ustar header blocks for the extended headers. The name is obtained
8443 from @var{string} after making the following substitutions:
8444
8445 @multitable @columnfractions .25 .55
8446 @headitem Meta-character @tab Replaced By
8447 @item %d @tab The directory name of the file, equivalent to the
8448 result of the @command{dirname} utility on the translated pathname.
8449 @item %f @tab The filename of the file, equivalent to the result
8450 of the @command{basename} utility on the translated pathname.
8451 @item %p @tab The process ID of the @command{tar} process.
8452 @item %% @tab A @samp{%} character.
8453 @end multitable
8454
8455 Any other @samp{%} characters in @var{string} produce undefined
8456 results.
8457
8458 If no option @samp{exthdr.name=string} is specified, @command{tar}
8459 will use the following default value:
8460
8461 @smallexample
8462 %d/PaxHeaders.%p/%f
8463 @end smallexample
8464
8465 @item globexthdr.name=@var{string}
8466 This keyword allows user control over the name that is written into
8467 the ustar header blocks for global extended header records. The name
8468 is obtained from the contents of @var{string}, after making
8469 the following substitutions:
8470
8471 @multitable @columnfractions .25 .55
8472 @headitem Meta-character @tab Replaced By
8473 @item %n @tab An integer that represents the
8474 sequence number of the global extended header record in the archive,
8475 starting at 1.
8476 @item %p @tab The process ID of the @command{tar} process.
8477 @item %% @tab A @samp{%} character.
8478 @end multitable
8479
8480 Any other @samp{%} characters in @var{string} produce undefined results.
8481
8482 If no option @samp{globexthdr.name=string} is specified, @command{tar}
8483 will use the following default value:
8484
8485 @smallexample
8486 $TMPDIR/GlobalHead.%p.%n
8487 @end smallexample
8488
8489 @noindent
8490 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
8491 environment variable. If @var{TMPDIR} is not set, @command{tar}
8492 uses @samp{/tmp}.
8493
8494 @item @var{keyword}=@var{value}
8495 When used with one of archive-creation commands, these keyword/value pairs
8496 will be included at the beginning of the archive in a global extended
8497 header record. When used with one of archive-reading commands,
8498 @command{tar} will behave as if it has encountered these keyword/value
8499 pairs at the beginning of the archive in a global extended header
8500 record.
8501
8502 @item @var{keyword}:=@var{value}
8503 When used with one of archive-creation commands, these keyword/value pairs
8504 will be included as records at the beginning of an extended header for
8505 each file. This is effectively equivalent to @var{keyword}=@var{value}
8506 form except that it creates no global extended header records.
8507
8508 When used with one of archive-reading commands, @command{tar} will
8509 behave as if these keyword/value pairs were included as records at the
8510 end of each extended header; thus, they will override any global or
8511 file-specific extended header record keywords of the same names.
8512 For example, in the command:
8513
8514 @smallexample
8515 tar --format=posix --create \
8516 --file archive --pax-option gname:=user .
8517 @end smallexample
8518
8519 the group name will be forced to a new value for all files
8520 stored in the archive.
8521 @end table
8522
8523 @node Checksumming
8524 @subsection Checksumming Problems
8525
8526 SunOS and HP-UX @command{tar} fail to accept archives created using
8527 @GNUTAR{} and containing non-ASCII file names, that
8528 is, file names having characters with the eight bit set, because they
8529 use signed checksums, while @GNUTAR{} uses unsigned
8530 checksums while creating archives, as per @acronym{POSIX} standards. On
8531 reading, @GNUTAR{} computes both checksums and
8532 accept any. It is somewhat worrying that a lot of people may go
8533 around doing backup of their files using faulty (or at least
8534 non-standard) software, not learning about it until it's time to
8535 restore their missing files with an incompatible file extractor, or
8536 vice versa.
8537
8538 @GNUTAR{} compute checksums both ways, and accept
8539 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8540 wrong checksums. @GNUTAR{} produces the standard
8541 checksum, however, raising incompatibilities with Sun. That is to
8542 say, @GNUTAR{} has not been modified to
8543 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8544 I've been told that more recent Sun @command{tar} now read standard
8545 archives, so maybe Sun did a similar patch, after all?
8546
8547 The story seems to be that when Sun first imported @command{tar}
8548 sources on their system, they recompiled it without realizing that
8549 the checksums were computed differently, because of a change in
8550 the default signing of @code{char}'s in their compiler. So they
8551 started computing checksums wrongly. When they later realized their
8552 mistake, they merely decided to stay compatible with it, and with
8553 themselves afterwards. Presumably, but I do not really know, HP-UX
8554 has chosen that their @command{tar} archives to be compatible with Sun's.
8555 The current standards do not favor Sun @command{tar} format. In any
8556 case, it now falls on the shoulders of SunOS and HP-UX users to get
8557 a @command{tar} able to read the good archives they receive.
8558
8559 @node Large or Negative Values
8560 @subsection Large or Negative Values
8561 @cindex large values
8562 @cindex future time stamps
8563 @cindex negative time stamps
8564 @UNREVISED{}
8565
8566 The above sections suggest to use @samp{oldest possible} archive
8567 format if in doubt. However, sometimes it is not possible. If you
8568 attempt to archive a file whose metadata cannot be represented using
8569 required format, @GNUTAR{} will print error message and ignore such a
8570 file. You will than have to switch to a format that is able to
8571 handle such values. The format summary table (@pxref{Formats}) will
8572 help you to do so.
8573
8574 In particular, when trying to archive files larger than 8GB or with
8575 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8576 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8577 @acronym{POSIX} archive formats. When considering which format to
8578 choose, bear in mind that the @acronym{GNU} format uses
8579 two's-complement base-256 notation to store values that do not fit
8580 into standard @acronym{ustar} range. Such archives can generally be
8581 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8582 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8583 example, using two's complement representation for negative time
8584 stamps that assumes a signed 32-bit @code{time_t} generates archives
8585 that are not portable to hosts with differing @code{time_t}
8586 representations.
8587
8588 On the other hand, @acronym{POSIX} archives, generally speaking, can
8589 be extracted by any tar implementation that understands older
8590 @acronym{ustar} format. The only exception are files larger than 8GB.
8591
8592 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8593 POSIX-aware tars.}
8594
8595 @node Other Tars
8596 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
8597
8598 In previous sections you became acquainted with various quirks
8599 necessary to make your archives portable. Sometimes you may need to
8600 extract archives containing GNU-specific members using some
8601 third-party @command{tar} implementation or an older version of
8602 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
8603 but if it is for some reason impossible, this section will explain
8604 how to cope without it.
8605
8606 When we speak about @dfn{GNU-specific} members we mean two classes of
8607 them: members split between the volumes of a multi-volume archive and
8608 sparse members. You will be able to always recover such members if
8609 the archive is in PAX format. In addition split members can be
8610 recovered from archives in old GNU format. The following subsections
8611 describe the required procedures in detail.
8612
8613 @menu
8614 * Split Recovery:: Members Split Between Volumes
8615 * Sparse Recovery:: Sparse Members
8616 @end menu
8617
8618 @node Split Recovery
8619 @subsubsection Extracting Members Split Between Volumes
8620
8621 @cindex Mutli-volume archives, extracting using non-GNU tars
8622 If a member is split between several volumes of an old GNU format archive
8623 most third party @command{tar} implementation will fail to extract
8624 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
8625 This program is available from
8626 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
8627 home page}. It concatenates several archive volumes into a single
8628 valid archive. For example, if you have three volumes named from
8629 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
8630 extract them using a third-party @command{tar}:
8631
8632 @smallexample
8633 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
8634 @end smallexample
8635
8636 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
8637 You could use this approach for most (although not all) PAX
8638 format archives as well. However, extracting split members from a PAX
8639 archive is a much easier task, because PAX volumes are constructed in
8640 such a way that each part of a split member is extracted to a
8641 different file by @command{tar} implementations that are not aware of
8642 GNU extensions. More specifically, the very first part retains its
8643 original name, and all subsequent parts are named using the pattern:
8644
8645 @smallexample
8646 %d/GNUFileParts.%p/%f.%n
8647 @end smallexample
8648
8649 @noindent
8650 where symbols preceeded by @samp{%} are @dfn{macro characters} that
8651 have the following meaning:
8652
8653 @multitable @columnfractions .25 .55
8654 @headitem Meta-character @tab Replaced By
8655 @item %d @tab The directory name of the file, equivalent to the
8656 result of the @command{dirname} utility on its full name.
8657 @item %f @tab The file name of the file, equivalent to the result
8658 of the @command{basename} utility on its full name.
8659 @item %p @tab The process ID of the @command{tar} process that
8660 created the archive.
8661 @item %n @tab Ordinal number of this particular part.
8662 @end multitable
8663
8664 For example, if the file @file{var/longfile} was split during archive
8665 creation between three volumes, and the creator @command{tar} process
8666 had process ID @samp{27962}, then the member names will be:
8667
8668 @smallexample
8669 var/longfile
8670 var/GNUFileParts.27962/longfile.1
8671 var/GNUFileParts.27962/longfile.2
8672 @end smallexample
8673
8674 When you extract your archive using a third-party @command{tar}, these
8675 files will be created on your disk, and the only thing you will need
8676 to do to restore your file in its original form is concatenate them in
8677 the proper order, for example:
8678
8679 @smallexample
8680 @group
8681 $ @kbd{cd var}
8682 $ @kbd{cat GNUFileParts.27962/longfile.1 \
8683 GNUFileParts.27962/longfile.2 >> longfile}
8684 $ rm -f GNUFileParts.27962
8685 @end group
8686 @end smallexample
8687
8688 Notice, that if the @command{tar} implementation you use supports PAX
8689 format archives, it will probably emit warnings about unknown keywords
8690 during extraction. They will look like this:
8691
8692 @smallexample
8693 @group
8694 Tar file too small
8695 Unknown extended header keyword 'GNU.volume.filename' ignored.
8696 Unknown extended header keyword 'GNU.volume.size' ignored.
8697 Unknown extended header keyword 'GNU.volume.offset' ignored.
8698 @end group
8699 @end smallexample
8700
8701 @noindent
8702 You can safely ignore these warnings.
8703
8704 If your @command{tar} implementation is not PAX-aware, you will get
8705 more warnings and more files generated on your disk, e.g.:
8706
8707 @smallexample
8708 @group
8709 $ @kbd{tar xf vol-1.tar}
8710 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
8711 normal file
8712 Unexpected EOF in archive
8713 $ @kbd{tar xf vol-2.tar}
8714 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
8715 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
8716 'x', extracted as normal file
8717 @end group
8718 @end smallexample
8719
8720 Ignore these warnings. The @file{PaxHeaders.*} directories created
8721 will contain files with @dfn{extended header keywords} describing the
8722 extracted files. You can delete them, unless they describe sparse
8723 members. Read further to learn more about them.
8724
8725 @node Sparse Recovery
8726 @subsubsection Extracting Sparse Members
8727
8728 @cindex sparse files, extracting with non-GNU tars
8729 Any @command{tar} implementation will be able to extract sparse members from a
8730 PAX archive. However, the extracted files will be @dfn{condensed},
8731 i.e., any zero blocks will be removed from them. When we restore such
8732 a condensed file to its original form, by adding zero bloks (or
8733 @dfn{holes}) back to their original locations, we call this process
8734 @dfn{expanding} a compressed sparse file.
8735
8736 @pindex xsparse
8737 To expand a file, you will need a simple auxiliary program called
8738 @command{xsparse}. It is available in source form from
8739 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
8740 home page}.
8741
8742 @cindex sparse files v.1.0, extracting with non-GNU tars
8743 Let's begin with archive members in @dfn{sparse format
8744 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
8745 The condensed file will contain both file map and file data, so no
8746 additional data will be needed to restore it. If the original file
8747 name was @file{@var{dir}/@var{name}}, then the condensed file will be
8748 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
8749 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
8750 @dfn{process ID} of the @command{tar} process which created the
8751 archive (@pxref{PAX keywords}).}.
8752
8753 To expand a version 1.0 file, run @command{xsparse} as follows:
8754
8755 @smallexample
8756 $ @kbd{xsparse @file{cond-file}}
8757 @end smallexample
8758
8759 @noindent
8760 where @file{cond-file} is the name of the condensed file. The utility
8761 will deduce the name for the resulting expanded file using the
8762 following algorithm:
8763
8764 @enumerate 1
8765 @item If @file{cond-file} does not contain any directories,
8766 @file{../cond-file} will be used;
8767
8768 @item If @file{cond-file} has the form
8769 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
8770 are simple names, with no @samp{/} characters in them, the output file
8771 name will be @file{@var{dir}/@var{name}}.
8772
8773 @item Otherwise, if @file{cond-file} has the form
8774 @file{@var{dir}/@var{name}}, the output file name will be
8775 @file{@var{name}}.
8776 @end enumerate
8777
8778 In the unlikely case when this algorithm does not suite your needs,
8779 you can explicitly specify output file name as a second argument to
8780 the command:
8781
8782 @smallexample
8783 $ @kbd{xsparse @file{cond-file} @file{out-file}}
8784 @end smallexample
8785
8786 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
8787 first. In this mode, the command does not actually expand the file,
8788 but verbosely lists all actions it would be taking to do so. The dry
8789 run mode is enabled by @option{-n} command line argument:
8790
8791 @smallexample
8792 @group
8793 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
8794 Reading v.1.0 sparse map
8795 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8796 `/home/gray/sparsefile'
8797 Finished dry run
8798 @end group
8799 @end smallexample
8800
8801 To actually expand the file, you would run:
8802
8803 @smallexample
8804 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
8805 @end smallexample
8806
8807 @noindent
8808 The program behaves the same way all UNIX utilities do: it will keep
8809 quiet unless it has simething important to tell you (e.g. an error
8810 condition or something). If you wish it to produce verbose output,
8811 similar to that from the dry run mode, use @option{-v} option:
8812
8813 @smallexample
8814 @group
8815 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
8816 Reading v.1.0 sparse map
8817 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8818 `/home/gray/sparsefile'
8819 Done
8820 @end group
8821 @end smallexample
8822
8823 Additionally, if your @command{tar} implementation has extracted the
8824 @dfn{extended headers} for this file, you can instruct @command{xstar}
8825 to use them in order to verify the integrity of the expanded file.
8826 The option @option{-x} sets the name of the extended header file to
8827 use. Continuing our example:
8828
8829 @smallexample
8830 @group
8831 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
8832 /home/gray/GNUSparseFile.6058/sparsefile}
8833 Reading extended header file
8834 Found variable GNU.sparse.major = 1
8835 Found variable GNU.sparse.minor = 0
8836 Found variable GNU.sparse.name = sparsefile
8837 Found variable GNU.sparse.realsize = 217481216
8838 Reading v.1.0 sparse map
8839 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8840 `/home/gray/sparsefile'
8841 Done
8842 @end group
8843 @end smallexample
8844
8845 @anchor{extracting sparse v.0.x}
8846 @cindex sparse files v.0.1, extracting with non-GNU tars
8847 @cindex sparse files v.0.0, extracting with non-GNU tars
8848 An @dfn{extended header} is a special @command{tar} archive header
8849 that precedes an archive member and contains a set of
8850 @dfn{variables}, describing the member properties that cannot be
8851 stored in the standard @code{ustar} header. While optional for
8852 expanding sparse version 1.0 members, use of extended headers is
8853 mandatory when expanding sparse members in older sparse formats: v.0.0
8854 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
8855 Formats}.) So, for this format, the question is: how to obtain
8856 extended headers from the archive?
8857
8858 If you use a @command{tar} implementation that does not support PAX
8859 format, extended headers for each member will be extracted as a
8860 separate file. If we represent the member name as
8861 @file{@var{dir}/@var{name}}, then the extended header file will be
8862 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
8863 @var{n} is an integer number.
8864
8865 Things become more difficult if your @command{tar} implementation
8866 does support PAX headers, because in this case you will have to
8867 manually extract the headers. We recommend the following algorithm:
8868
8869 @enumerate 1
8870 @item
8871 Consult the documentation of your @command{tar} implementation for an
8872 option that prints @dfn{block numbers} along with the archive
8873 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
8874 @command{star} has @option{-block-number}.
8875
8876 @item
8877 Obtain verbose listing using the @samp{block number} option, and
8878 find block numbers of the sparse member in question and the member
8879 immediately following it. For example, running @command{star} on our
8880 archive we obtain:
8881
8882 @smallexample
8883 @group
8884 $ @kbd{star -t -v -block-number -f arc.tar}
8885 @dots{}
8886 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
8887 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
8888 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
8889 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
8890 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
8891 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
8892 @dots{}
8893 @end group
8894 @end smallexample
8895
8896 @noindent
8897 (as usual, ignore the warnings about unknown keywords.)
8898
8899 @item
8900 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
8901 and @var{Bn} be the block number of the next member.
8902 Compute:
8903
8904 @smallexample
8905 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
8906 @end smallexample
8907
8908 @noindent
8909 This number gives the size of the extended header part in tar @dfn{blocks}.
8910 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
8911 = 7}.
8912
8913 @item
8914 Use @command{dd} to extract the headers:
8915
8916 @smallexample
8917 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
8918 @end smallexample
8919
8920 @noindent
8921 where @var{archive} is the archive name, @var{hname} is a name of the
8922 file to store the extended header in, @var{Bs} and @var{N} are
8923 computed in previous steps.
8924
8925 In our example, this command will be
8926
8927 @smallexample
8928 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
8929 @end smallexample
8930 @end enumerate
8931
8932 Finally, you can expand the condensed file, using the obtained header:
8933
8934 @smallexample
8935 @group
8936 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
8937 Reading extended header file
8938 Found variable GNU.sparse.size = 217481216
8939 Found variable GNU.sparse.numblocks = 208
8940 Found variable GNU.sparse.name = sparsefile
8941 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
8942 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
8943 Done
8944 @end group
8945 @end smallexample
8946
8947 @node cpio
8948 @section Comparison of @command{tar} and @command{cpio}
8949 @UNREVISED
8950
8951 @FIXME{Reorganize the following material}
8952
8953 The @command{cpio} archive formats, like @command{tar}, do have maximum
8954 pathname lengths. The binary and old ASCII formats have a max path
8955 length of 256, and the new ASCII and CRC ASCII formats have a max
8956 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8957 with arbitrary pathname lengths, but other @command{cpio} implementations
8958 may crash unexplainedly trying to read them.
8959
8960 @command{tar} handles symbolic links in the form in which it comes in BSD;
8961 @command{cpio} doesn't handle symbolic links in the form in which it comes
8962 in System V prior to SVR4, and some vendors may have added symlinks
8963 to their system without enhancing @command{cpio} to know about them.
8964 Others may have enhanced it in a way other than the way I did it
8965 at Sun, and which was adopted by AT&T (and which is, I think, also
8966 present in the @command{cpio} that Berkeley picked up from AT&T and put
8967 into a later BSD release---I think I gave them my changes).
8968
8969 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8970 can handle @command{tar} format input, and write it on output, and it
8971 probably handles symbolic links. They may not have bothered doing
8972 anything to enhance @command{tar} as a result.)
8973
8974 @command{cpio} handles special files; traditional @command{tar} doesn't.
8975
8976 @command{tar} comes with V7, System III, System V, and BSD source;
8977 @command{cpio} comes only with System III, System V, and later BSD
8978 (4.3-tahoe and later).
8979
8980 @command{tar}'s way of handling multiple hard links to a file can handle
8981 file systems that support 32-bit inumbers (e.g., the BSD file system);
8982 @command{cpio}s way requires you to play some games (in its "binary"
8983 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8984 they're 18 bits---it would have to play games with the "file system ID"
8985 field of the header to make sure that the file system ID/i-number pairs
8986 of different files were always different), and I don't know which
8987 @command{cpio}s, if any, play those games. Those that don't might get
8988 confused and think two files are the same file when they're not, and
8989 make hard links between them.
8990
8991 @command{tar}s way of handling multiple hard links to a file places only
8992 one copy of the link on the tape, but the name attached to that copy
8993 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8994 way puts one copy for every link, but you can retrieve it using any
8995 of the names.
8996
8997 @quotation
8998 What type of check sum (if any) is used, and how is this calculated.
8999 @end quotation
9000
9001 See the attached manual pages for @command{tar} and @command{cpio} format.
9002 @command{tar} uses a checksum which is the sum of all the bytes in the
9003 @command{tar} header for a file; @command{cpio} uses no checksum.
9004
9005 @quotation
9006 If anyone knows why @command{cpio} was made when @command{tar} was present
9007 at the unix scene,
9008 @end quotation
9009
9010 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
9011 generally-available version of UNIX had @command{tar} at the time. I don't
9012 know whether any version that was generally available @emph{within AT&T}
9013 had @command{tar}, or, if so, whether the people within AT&T who did
9014 @command{cpio} knew about it.
9015
9016 On restore, if there is a corruption on a tape @command{tar} will stop at
9017 that point, while @command{cpio} will skip over it and try to restore the
9018 rest of the files.
9019
9020 The main difference is just in the command syntax and header format.
9021
9022 @command{tar} is a little more tape-oriented in that everything is blocked
9023 to start on a record boundary.
9024
9025 @quotation
9026 Is there any differences between the ability to recover crashed
9027 archives between the two of them. (Is there any chance of recovering
9028 crashed archives at all.)
9029 @end quotation
9030
9031 Theoretically it should be easier under @command{tar} since the blocking
9032 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9033 However, modern @command{cpio}'s and variations have an option to just
9034 search for the next file header after an error with a reasonable chance
9035 of resyncing. However, lots of tape driver software won't allow you to
9036 continue past a media error which should be the only reason for getting
9037 out of sync unless a file changed sizes while you were writing the
9038 archive.
9039
9040 @quotation
9041 If anyone knows why @command{cpio} was made when @command{tar} was present
9042 at the unix scene, please tell me about this too.
9043 @end quotation
9044
9045 Probably because it is more media efficient (by not blocking everything
9046 and using only the space needed for the headers where @command{tar}
9047 always uses 512 bytes per file header) and it knows how to archive
9048 special files.
9049
9050 You might want to look at the freely available alternatives. The
9051 major ones are @command{afio}, @GNUTAR{}, and
9052 @command{pax}, each of which have their own extensions with some
9053 backwards compatibility.
9054
9055 Sparse files were @command{tar}red as sparse files (which you can
9056 easily test, because the resulting archive gets smaller, and
9057 @acronym{GNU} @command{cpio} can no longer read it).
9058
9059 @node Media
9060 @chapter Tapes and Other Archive Media
9061 @UNREVISED
9062
9063 A few special cases about tape handling warrant more detailed
9064 description. These special cases are discussed below.
9065
9066 Many complexities surround the use of @command{tar} on tape drives. Since
9067 the creation and manipulation of archives located on magnetic tape was
9068 the original purpose of @command{tar}, it contains many features making
9069 such manipulation easier.
9070
9071 Archives are usually written on dismountable media---tape cartridges,
9072 mag tapes, or floppy disks.
9073
9074 The amount of data a tape or disk holds depends not only on its size,
9075 but also on how it is formatted. A 2400 foot long reel of mag tape
9076 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9077 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9078
9079 Magnetic media are re-usable---once the archive on a tape is no longer
9080 needed, the archive can be erased and the tape or disk used over.
9081 Media quality does deteriorate with use, however. Most tapes or disks
9082 should be discarded when they begin to produce data errors. EXABYTE
9083 tape cartridges should be discarded when they generate an @dfn{error
9084 count} (number of non-usable bits) of more than 10k.
9085
9086 Magnetic media are written and erased using magnetic fields, and
9087 should be protected from such fields to avoid damage to stored data.
9088 Sticking a floppy disk to a filing cabinet using a magnet is probably
9089 not a good idea.
9090
9091 @menu
9092 * Device:: Device selection and switching
9093 * Remote Tape Server::
9094 * Common Problems and Solutions::
9095 * Blocking:: Blocking
9096 * Many:: Many archives on one tape
9097 * Using Multiple Tapes:: Using Multiple Tapes
9098 * label:: Including a Label in the Archive
9099 * verify::
9100 * Write Protection::
9101 @end menu
9102
9103 @node Device
9104 @section Device Selection and Switching
9105 @UNREVISED
9106
9107 @table @option
9108 @item -f [@var{hostname}:]@var{file}
9109 @itemx --file=[@var{hostname}:]@var{file}
9110 Use archive file or device @var{file} on @var{hostname}.
9111 @end table
9112
9113 This option is used to specify the file name of the archive @command{tar}
9114 works on.
9115
9116 If the file name is @samp{-}, @command{tar} reads the archive from standard
9117 input (when listing or extracting), or writes it to standard output
9118 (when creating). If the @samp{-} file name is given when updating an
9119 archive, @command{tar} will read the original archive from its standard
9120 input, and will write the entire new archive to its standard output.
9121
9122 If the file name contains a @samp{:}, it is interpreted as
9123 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9124 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9125 either case, @command{tar} will invoke the command @command{rsh} (or
9126 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9127 machine. If you give an alternate login name, it will be given to the
9128 @command{rsh}.
9129 Naturally, the remote machine must have an executable
9130 @command{/usr/libexec/rmt}. This program is free software from the
9131 University of California, and a copy of the source code can be found
9132 with the sources for @command{tar}; it's compiled and installed by default.
9133 The exact path to this utility is determined when configuring the package.
9134 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9135 your installation prefix. This location may also be overridden at
9136 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9137 ---rmt-command}, for detailed description of this option. @xref{Remote
9138 Tape Server}, for the description of @command{rmt} command).
9139
9140 If this option is not given, but the environment variable @env{TAPE}
9141 is set, its value is used; otherwise, old versions of @command{tar}
9142 used a default archive name (which was picked when @command{tar} was
9143 compiled). The default is normally set up to be the @dfn{first} tape
9144 drive or other transportable I/O medium on the system.
9145
9146 Starting with version 1.11.5, @GNUTAR{} uses
9147 standard input and standard output as the default device, and I will
9148 not try anymore supporting automatic device detection at installation
9149 time. This was failing really in too many cases, it was hopeless.
9150 This is now completely left to the installer to override standard
9151 input and standard output for default device, if this seems
9152 preferable. Further, I think @emph{most} actual usages of
9153 @command{tar} are done with pipes or disks, not really tapes,
9154 cartridges or diskettes.
9155
9156 Some users think that using standard input and output is running
9157 after trouble. This could lead to a nasty surprise on your screen if
9158 you forget to specify an output file name---especially if you are going
9159 through a network or terminal server capable of buffering large amounts
9160 of output. We had so many bug reports in that area of configuring
9161 default tapes automatically, and so many contradicting requests, that
9162 we finally consider the problem to be portably intractable. We could
9163 of course use something like @samp{/dev/tape} as a default, but this
9164 is @emph{also} running after various kind of trouble, going from hung
9165 processes to accidental destruction of real tapes. After having seen
9166 all this mess, using standard input and output as a default really
9167 sounds like the only clean choice left, and a very useful one too.
9168
9169 @GNUTAR{} reads and writes archive in records, I
9170 suspect this is the main reason why block devices are preferred over
9171 character devices. Most probably, block devices are more efficient
9172 too. The installer could also check for @samp{DEFTAPE} in
9173 @file{<sys/mtio.h>}.
9174
9175 @table @option
9176 @xopindex{force-local, short description}
9177 @item --force-local
9178 Archive file is local even if it contains a colon.
9179
9180 @opindex rsh-command
9181 @item --rsh-command=@var{command}
9182 Use remote @var{command} instead of @command{rsh}. This option exists
9183 so that people who use something other than the standard @command{rsh}
9184 (e.g., a Kerberized @command{rsh}) can access a remote device.
9185
9186 When this command is not used, the shell command found when
9187 the @command{tar} program was installed is used instead. This is
9188 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9189 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9190 The installer may have overridden this by defining the environment
9191 variable @env{RSH} @emph{at installation time}.
9192
9193 @item -[0-7][lmh]
9194 Specify drive and density.
9195
9196 @xopindex{multi-volume, short description}
9197 @item -M
9198 @itemx --multi-volume
9199 Create/list/extract multi-volume archive.
9200
9201 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9202 that may be larger than will fit on the medium used to hold it.
9203 @xref{Multi-Volume Archives}.
9204
9205 @xopindex{tape-length, short description}
9206 @item -L @var{num}
9207 @itemx --tape-length=@var{num}
9208 Change tape after writing @var{num} x 1024 bytes.
9209
9210 This option might be useful when your tape drivers do not properly
9211 detect end of physical tapes. By being slightly conservative on the
9212 maximum tape length, you might avoid the problem entirely.
9213
9214 @xopindex{info-script, short description}
9215 @xopindex{new-volume-script, short description}
9216 @item -F @var{file}
9217 @itemx --info-script=@var{file}
9218 @itemx --new-volume-script=@var{file}
9219 Execute @file{file} at end of each tape. This implies
9220 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9221 description of this option.
9222 @end table
9223
9224 @node Remote Tape Server
9225 @section The Remote Tape Server
9226
9227 @cindex remote tape drive
9228 @pindex rmt
9229 In order to access the tape drive on a remote machine, @command{tar}
9230 uses the remote tape server written at the University of California at
9231 Berkeley. The remote tape server must be installed as
9232 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9233 want to use. @command{tar} calls @command{rmt} by running an
9234 @command{rsh} or @command{remsh} to the remote machine, optionally
9235 using a different login name if one is supplied.
9236
9237 A copy of the source for the remote tape server is provided. It is
9238 Copyright @copyright{} 1983 by the Regents of the University of
9239 California, but can be freely distributed. It is compiled and
9240 installed by default.
9241
9242 @cindex absolute file names
9243 Unless you use the @option{--absolute-names} (@option{-P}) option,
9244 @GNUTAR{} will not allow you to create an archive that contains
9245 absolute file names (a file name beginning with @samp{/}.) If you try,
9246 @command{tar} will automatically remove the leading @samp{/} from the
9247 file names it stores in the archive. It will also type a warning
9248 message telling you what it is doing.
9249
9250 When reading an archive that was created with a different
9251 @command{tar} program, @GNUTAR{} automatically
9252 extracts entries in the archive which have absolute file names as if
9253 the file names were not absolute. This is an important feature. A
9254 visitor here once gave a @command{tar} tape to an operator to restore;
9255 the operator used Sun @command{tar} instead of @GNUTAR{},
9256 and the result was that it replaced large portions of
9257 our @file{/bin} and friends with versions from the tape; needless to
9258 say, we were unhappy about having to recover the file system from
9259 backup tapes.
9260
9261 For example, if the archive contained a file @file{/usr/bin/computoy},
9262 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9263 relative to the current directory. If you want to extract the files in
9264 an archive to the same absolute names that they had when the archive
9265 was created, you should do a @samp{cd /} before extracting the files
9266 from the archive, or you should either use the @option{--absolute-names}
9267 option, or use the command @samp{tar -C / @dots{}}.
9268
9269 @cindex Ultrix 3.1 and write failure
9270 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9271 can claim that a short write near the end of a tape succeeded,
9272 when it actually failed. This will result in the -M option not
9273 working correctly. The best workaround at the moment is to use a
9274 significantly larger blocking factor than the default 20.
9275
9276 In order to update an archive, @command{tar} must be able to backspace the
9277 archive in order to reread or rewrite a record that was just read (or
9278 written). This is currently possible only on two kinds of files: normal
9279 disk files (or any other file that can be backspaced with @samp{lseek}),
9280 and industry-standard 9-track magnetic tape (or any other kind of tape
9281 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9282
9283 This means that the @option{--append}, @option{--concatenate}, and
9284 @option{--delete} commands will not work on any other kind of file.
9285 Some media simply cannot be backspaced, which means these commands and
9286 options will never be able to work on them. These non-backspacing
9287 media include pipes and cartridge tape drives.
9288
9289 Some other media can be backspaced, and @command{tar} will work on them
9290 once @command{tar} is modified to do so.
9291
9292 Archives created with the @option{--multi-volume}, @option{--label}, and
9293 @option{--incremental} (@option{-G}) options may not be readable by other version
9294 of @command{tar}. In particular, restoring a file that was split over
9295 a volume boundary will require some careful work with @command{dd}, if
9296 it can be done at all. Other versions of @command{tar} may also create
9297 an empty file whose name is that of the volume header. Some versions
9298 of @command{tar} may create normal files instead of directories archived
9299 with the @option{--incremental} (@option{-G}) option.
9300
9301 @node Common Problems and Solutions
9302 @section Some Common Problems and their Solutions
9303
9304 @ifclear PUBLISH
9305
9306 @format
9307 errors from system:
9308 permission denied
9309 no such file or directory
9310 not owner
9311
9312 errors from @command{tar}:
9313 directory checksum error
9314 header format error
9315
9316 errors from media/system:
9317 i/o error
9318 device busy
9319 @end format
9320
9321 @end ifclear
9322
9323 @node Blocking
9324 @section Blocking
9325 @UNREVISED
9326
9327 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9328 is also confusing to the expert reader. On the other hand, readers
9329 who are new to the field have a fresh mind, and they may safely skip
9330 the next two paragraphs, as the remainder of this manual uses those
9331 two terms in a quite consistent way.
9332
9333 John Gilmore, the writer of the public domain @command{tar} from which
9334 @GNUTAR{} was originally derived, wrote (June 1995):
9335
9336 @quotation
9337 The nomenclature of tape drives comes from IBM, where I believe
9338 they were invented for the IBM 650 or so. On IBM mainframes, what
9339 is recorded on tape are tape blocks. The logical organization of
9340 data is into records. There are various ways of putting records into
9341 blocks, including @code{F} (fixed sized records), @code{V} (variable
9342 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9343 to a block), @code{VB} (variable size records, @var{n} to a block),
9344 @code{VSB} (variable spanned blocked: variable sized records that can
9345 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9346 parameter specified this to the operating system.
9347
9348 The Unix man page on @command{tar} was totally confused about this.
9349 When I wrote @code{PD TAR}, I used the historically correct terminology
9350 (@command{tar} writes data records, which are grouped into blocks).
9351 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9352 here), and now Fran@,{c}ois has migrated that terminology back
9353 into the source code too.
9354 @end quotation
9355
9356 The term @dfn{physical block} means the basic transfer chunk from or
9357 to a device, after which reading or writing may stop without anything
9358 being lost. In this manual, the term @dfn{block} usually refers to
9359 a disk physical block, @emph{assuming} that each disk block is 512
9360 bytes in length. It is true that some disk devices have different
9361 physical blocks, but @command{tar} ignore these differences in its own
9362 format, which is meant to be portable, so a @command{tar} block is always
9363 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9364 The term @dfn{logical block} often represents the basic chunk of
9365 allocation of many disk blocks as a single entity, which the operating
9366 system treats somewhat atomically; this concept is only barely used
9367 in @GNUTAR{}.
9368
9369 The term @dfn{physical record} is another way to speak of a physical
9370 block, those two terms are somewhat interchangeable. In this manual,
9371 the term @dfn{record} usually refers to a tape physical block,
9372 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9373 It is true that archives may be put on disk or used with pipes,
9374 but nevertheless, @command{tar} tries to read and write the archive one
9375 @dfn{record} at a time, whatever the medium in use. One record is made
9376 up of an integral number of blocks, and this operation of putting many
9377 disk blocks into a single tape block is called @dfn{reblocking}, or
9378 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9379 the logical organization of many characters into something meaningful
9380 to the application. The term @dfn{unit record} describes a small set
9381 of characters which are transmitted whole to or by the application,
9382 and often refers to a line of text. Those two last terms are unrelated
9383 to what we call a @dfn{record} in @GNUTAR{}.
9384
9385 When writing to tapes, @command{tar} writes the contents of the archive
9386 in chunks known as @dfn{records}. To change the default blocking
9387 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9388 @var{512-size}}) option. Each record will then be composed of
9389 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9390 @xref{Standard}.) Each file written to the archive uses at least one
9391 full record. As a result, using a larger record size can result in
9392 more wasted space for small files. On the other hand, a larger record
9393 size can often be read and written much more efficiently.
9394
9395 Further complicating the problem is that some tape drives ignore the
9396 blocking entirely. For these, a larger record size can still improve
9397 performance (because the software layers above the tape drive still
9398 honor the blocking), but not as dramatically as on tape drives that
9399 honor blocking.
9400
9401 When reading an archive, @command{tar} can usually figure out the
9402 record size on itself. When this is the case, and a non-standard
9403 record size was used when the archive was created, @command{tar} will
9404 print a message about a non-standard blocking factor, and then operate
9405 normally. On some tape devices, however, @command{tar} cannot figure
9406 out the record size itself. On most of those, you can specify a
9407 blocking factor (with @option{--blocking-factor}) larger than the
9408 actual blocking factor, and then use the @option{--read-full-records}
9409 (@option{-B}) option. (If you specify a blocking factor with
9410 @option{--blocking-factor} and don't use the
9411 @option{--read-full-records} option, then @command{tar} will not
9412 attempt to figure out the recording size itself.) On some devices,
9413 you must always specify the record size exactly with
9414 @option{--blocking-factor} when reading, because @command{tar} cannot
9415 figure it out. In any case, use @option{--list} (@option{-t}) before
9416 doing any extractions to see whether @command{tar} is reading the archive
9417 correctly.
9418
9419 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9420 putting them into records is to put a whole number of them (one or
9421 more) into each record. @command{tar} records are all the same size;
9422 at the end of the file there's a block containing all zeros, which
9423 is how you tell that the remainder of the last record(s) are garbage.
9424
9425 In a standard @command{tar} file (no options), the block size is 512
9426 and the record size is 10240, for a blocking factor of 20. What the
9427 @option{--blocking-factor} option does is sets the blocking factor,
9428 changing the record size while leaving the block size at 512 bytes.
9429 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9430 most tape drives these days prefer much bigger records in order to
9431 stream and not waste tape. When writing tapes for myself, some tend
9432 to use a factor of the order of 2048, say, giving a record size of
9433 around one megabyte.
9434
9435 If you use a blocking factor larger than 20, older @command{tar}
9436 programs might not be able to read the archive, so we recommend this
9437 as a limit to use in practice. @GNUTAR{}, however,
9438 will support arbitrarily large record sizes, limited only by the
9439 amount of virtual memory or the physical characteristics of the tape
9440 device.
9441
9442 @menu
9443 * Format Variations:: Format Variations
9444 * Blocking Factor:: The Blocking Factor of an Archive
9445 @end menu
9446
9447 @node Format Variations
9448 @subsection Format Variations
9449 @cindex Format Parameters
9450 @cindex Format Options
9451 @cindex Options, archive format specifying
9452 @cindex Options, format specifying
9453 @UNREVISED
9454
9455 Format parameters specify how an archive is written on the archive
9456 media. The best choice of format parameters will vary depending on
9457 the type and number of files being archived, and on the media used to
9458 store the archive.
9459
9460 To specify format parameters when accessing or creating an archive,
9461 you can use the options described in the following sections.
9462 If you do not specify any format parameters, @command{tar} uses
9463 default parameters. You cannot modify a compressed archive.
9464 If you create an archive with the @option{--blocking-factor} option
9465 specified (@pxref{Blocking Factor}), you must specify that
9466 blocking-factor when operating on the archive. @xref{Formats}, for other
9467 examples of format parameter considerations.
9468
9469 @node Blocking Factor
9470 @subsection The Blocking Factor of an Archive
9471 @cindex Blocking Factor
9472 @cindex Record Size
9473 @cindex Number of blocks per record
9474 @cindex Number of bytes per record
9475 @cindex Bytes per record
9476 @cindex Blocks per record
9477 @UNREVISED
9478
9479 @opindex blocking-factor
9480 The data in an archive is grouped into blocks, which are 512 bytes.
9481 Blocks are read and written in whole number multiples called
9482 @dfn{records}. The number of blocks in a record (i.e., the size of a
9483 record in units of 512 bytes) is called the @dfn{blocking factor}.
9484 The @option{--blocking-factor=@var{512-size}} (@option{-b
9485 @var{512-size}}) option specifies the blocking factor of an archive.
9486 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9487 can be specified at installation. To find out the blocking factor of
9488 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9489 This may not work on some devices.
9490
9491 Records are separated by gaps, which waste space on the archive media.
9492 If you are archiving on magnetic tape, using a larger blocking factor
9493 (and therefore larger records) provides faster throughput and allows you
9494 to fit more data on a tape (because there are fewer gaps). If you are
9495 archiving on cartridge, a very large blocking factor (say 126 or more)
9496 greatly increases performance. A smaller blocking factor, on the other
9497 hand, may be useful when archiving small files, to avoid archiving lots
9498 of nulls as @command{tar} fills out the archive to the end of the record.
9499 In general, the ideal record size depends on the size of the
9500 inter-record gaps on the tape you are using, and the average size of the
9501 files you are archiving. @xref{create}, for information on
9502 writing archives.
9503
9504 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9505
9506 Archives with blocking factors larger than 20 cannot be read
9507 by very old versions of @command{tar}, or by some newer versions
9508 of @command{tar} running on old machines with small address spaces.
9509 With @GNUTAR{}, the blocking factor of an archive is limited
9510 only by the maximum record size of the device containing the archive,
9511 or by the amount of available virtual memory.
9512
9513 Also, on some systems, not using adequate blocking factors, as sometimes
9514 imposed by the device drivers, may yield unexpected diagnostics. For
9515 example, this has been reported:
9516
9517 @smallexample
9518 Cannot write to /dev/dlt: Invalid argument
9519 @end smallexample
9520
9521 @noindent
9522 In such cases, it sometimes happen that the @command{tar} bundled by
9523 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9524 requires an explicit specification for the block size,
9525 which it cannot guess. This yields some people to consider
9526 @GNUTAR{} is misbehaving, because by comparison,
9527 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9528 for example, might resolve the problem.
9529
9530 If you use a non-default blocking factor when you create an archive, you
9531 must specify the same blocking factor when you modify that archive. Some
9532 archive devices will also require you to specify the blocking factor when
9533 reading that archive, however this is not typically the case. Usually, you
9534 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9535 reports a non-default record size and then lists the archive members as
9536 it would normally. To extract files from an archive with a non-standard
9537 blocking factor (particularly if you're not sure what the blocking factor
9538 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9539 specifying a blocking factor larger then the blocking factor of the archive
9540 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
9541 @xref{list}, for more information on the @option{--list} (@option{-t})
9542 operation. @xref{Reading}, for a more detailed explanation of that option.
9543
9544 @table @option
9545 @item --blocking-factor=@var{number}
9546 @itemx -b @var{number}
9547 Specifies the blocking factor of an archive. Can be used with any
9548 operation, but is usually not necessary with @option{--list} (@option{-t}).
9549 @end table
9550
9551 Device blocking
9552
9553 @table @option
9554 @item -b @var{blocks}
9555 @itemx --blocking-factor=@var{blocks}
9556 Set record size to @math{@var{blocks} * 512} bytes.
9557
9558 This option is used to specify a @dfn{blocking factor} for the archive.
9559 When reading or writing the archive, @command{tar}, will do reads and writes
9560 of the archive in records of @math{@var{block}*512} bytes. This is true
9561 even when the archive is compressed. Some devices requires that all
9562 write operations be a multiple of a certain size, and so, @command{tar}
9563 pads the archive out to the next record boundary.
9564
9565 The default blocking factor is set when @command{tar} is compiled, and is
9566 typically 20. Blocking factors larger than 20 cannot be read by very
9567 old versions of @command{tar}, or by some newer versions of @command{tar}
9568 running on old machines with small address spaces.
9569
9570 With a magnetic tape, larger records give faster throughput and fit
9571 more data on a tape (because there are fewer inter-record gaps).
9572 If the archive is in a disk file or a pipe, you may want to specify
9573 a smaller blocking factor, since a large one will result in a large
9574 number of null bytes at the end of the archive.
9575
9576 When writing cartridge or other streaming tapes, a much larger
9577 blocking factor (say 126 or more) will greatly increase performance.
9578 However, you must specify the same blocking factor when reading or
9579 updating the archive.
9580
9581 Apparently, Exabyte drives have a physical block size of 8K bytes.
9582 If we choose our blocksize as a multiple of 8k bytes, then the problem
9583 seems to disappear. Id est, we are using block size of 112 right
9584 now, and we haven't had the problem since we switched@dots{}
9585
9586 With @GNUTAR{} the blocking factor is limited only
9587 by the maximum record size of the device containing the archive, or by
9588 the amount of available virtual memory.
9589
9590 However, deblocking or reblocking is virtually avoided in a special
9591 case which often occurs in practice, but which requires all the
9592 following conditions to be simultaneously true:
9593 @itemize @bullet
9594 @item
9595 the archive is subject to a compression option,
9596 @item
9597 the archive is not handled through standard input or output, nor
9598 redirected nor piped,
9599 @item
9600 the archive is directly handled to a local disk, instead of any special
9601 device,
9602 @item
9603 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9604 invocation.
9605 @end itemize
9606
9607 If the output goes directly to a local disk, and not through
9608 stdout, then the last write is not extended to a full record size.
9609 Otherwise, reblocking occurs. Here are a few other remarks on this
9610 topic:
9611
9612 @itemize @bullet
9613
9614 @item
9615 @command{gzip} will complain about trailing garbage if asked to
9616 uncompress a compressed archive on tape, there is an option to turn
9617 the message off, but it breaks the regularity of simply having to use
9618 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9619 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9620 Gailly, by sending a copy of this message to him.
9621
9622 @item
9623 @command{compress} does not show this problem, but as Jean-loup pointed
9624 out to Michael, @samp{compress -d} silently adds garbage after
9625 the result of decompression, which tar ignores because it already
9626 recognized its end-of-file indicator. So this bug may be safely
9627 ignored.
9628
9629 @item
9630 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9631 but will still return an exit status of 2 which tar reports in turn.
9632 @command{tar} might ignore the exit status returned, but I hate doing
9633 that, as it weakens the protection @command{tar} offers users against
9634 other possible problems at decompression time. If @command{gzip} was
9635 silently skipping trailing zeros @emph{and} also avoiding setting the
9636 exit status in this innocuous case, that would solve this situation.
9637
9638 @item
9639 @command{tar} should become more solid at not stopping to read a pipe at
9640 the first null block encountered. This inelegantly breaks the pipe.
9641 @command{tar} should rather drain the pipe out before exiting itself.
9642 @end itemize
9643
9644 @xopindex{ignore-zeros, short description}
9645 @item -i
9646 @itemx --ignore-zeros
9647 Ignore blocks of zeros in archive (means EOF).
9648
9649 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9650 of zeros in the archive. Normally a block of zeros indicates the
9651 end of the archive, but when reading a damaged archive, or one which
9652 was created by concatenating several archives together, this option
9653 allows @command{tar} to read the entire archive. This option is not on
9654 by default because many versions of @command{tar} write garbage after
9655 the zeroed blocks.
9656
9657 Note that this option causes @command{tar} to read to the end of the
9658 archive file, which may sometimes avoid problems when multiple files
9659 are stored on a single physical tape.
9660
9661 @xopindex{read-full-records, short description}
9662 @item -B
9663 @itemx --read-full-records
9664 Reblock as we read (for reading 4.2BSD pipes).
9665
9666 If @option{--read-full-records} is used, @command{tar}
9667 will not panic if an attempt to read a record from the archive does
9668 not return a full record. Instead, @command{tar} will keep reading
9669 until it has obtained a full
9670 record.
9671
9672 This option is turned on by default when @command{tar} is reading
9673 an archive from standard input, or from a remote machine. This is
9674 because on BSD Unix systems, a read of a pipe will return however
9675 much happens to be in the pipe, even if it is less than @command{tar}
9676 requested. If this option was not used, @command{tar} would fail as
9677 soon as it read an incomplete record from the pipe.
9678
9679 This option is also useful with the commands for updating an archive.
9680
9681 @end table
9682
9683 Tape blocking
9684
9685 @FIXME{Appropriate options should be moved here from elsewhere.}
9686
9687 @cindex blocking factor
9688 @cindex tape blocking
9689
9690 When handling various tapes or cartridges, you have to take care of
9691 selecting a proper blocking, that is, the number of disk blocks you
9692 put together as a single tape block on the tape, without intervening
9693 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9694 with no information on it, used for decelerating the tape to a
9695 full stop, and for later regaining the reading or writing speed.
9696 When the tape driver starts reading a record, the record has to
9697 be read whole without stopping, as a tape gap is needed to stop the
9698 tape motion without loosing information.
9699
9700 @cindex Exabyte blocking
9701 @cindex DAT blocking
9702 Using higher blocking (putting more disk blocks per tape block) will use
9703 the tape more efficiently as there will be less tape gaps. But reading
9704 such tapes may be more difficult for the system, as more memory will be
9705 required to receive at once the whole record. Further, if there is a
9706 reading error on a huge record, this is less likely that the system will
9707 succeed in recovering the information. So, blocking should not be too
9708 low, nor it should be too high. @command{tar} uses by default a blocking of
9709 20 for historical reasons, and it does not really matter when reading or
9710 writing to disk. Current tape technology would easily accommodate higher
9711 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9712 We were told that for some DLT drives, the blocking should be a multiple
9713 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9714 Other manufacturers may use different recommendations for the same tapes.
9715 This might also depends of the buffering techniques used inside modern
9716 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9717 Others request blocking to be some exponent of two.
9718
9719 So, there is no fixed rule for blocking. But blocking at read time
9720 should ideally be the same as blocking used at write time. At one place
9721 I know, with a wide variety of equipment, they found it best to use a
9722 blocking of 32 to guarantee that their tapes are fully interchangeable.
9723
9724 I was also told that, for recycled tapes, prior erasure (by the same
9725 drive unit that will be used to create the archives) sometimes lowers
9726 the error rates observed at rewriting time.
9727
9728 I might also use @option{--number-blocks} instead of
9729 @option{--block-number}, so @option{--block} will then expand to
9730 @option{--blocking-factor} unambiguously.
9731
9732 @node Many
9733 @section Many Archives on One Tape
9734
9735 @FIXME{Appropriate options should be moved here from elsewhere.}
9736
9737 @findex ntape @r{device}
9738 Most tape devices have two entries in the @file{/dev} directory, or
9739 entries that come in pairs, which differ only in the minor number for
9740 this device. Let's take for example @file{/dev/tape}, which often
9741 points to the only or usual tape device of a given system. There might
9742 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9743 name is the @emph{rewinding} version of the device, while the name
9744 having @samp{nr} in it is the @emph{no rewinding} version of the same
9745 device.
9746
9747 A rewinding tape device will bring back the tape to its beginning point
9748 automatically when this device is opened or closed. Since @command{tar}
9749 opens the archive file before using it and closes it afterwards, this
9750 means that a simple:
9751
9752 @smallexample
9753 $ @kbd{tar cf /dev/tape @var{directory}}
9754 @end smallexample
9755
9756 @noindent
9757 will reposition the tape to its beginning both prior and after saving
9758 @var{directory} contents to it, thus erasing prior tape contents and
9759 making it so that any subsequent write operation will destroy what has
9760 just been saved.
9761
9762 @cindex tape positioning
9763 So, a rewinding device is normally meant to hold one and only one file.
9764 If you want to put more than one @command{tar} archive on a given tape, you
9765 will need to avoid using the rewinding version of the tape device. You
9766 will also have to pay special attention to tape positioning. Errors in
9767 positioning may overwrite the valuable data already on your tape. Many
9768 people, burnt by past experiences, will only use rewinding devices and
9769 limit themselves to one file per tape, precisely to avoid the risk of
9770 such errors. Be fully aware that writing at the wrong position on a
9771 tape loses all information past this point and most probably until the
9772 end of the tape, and this destroyed information @emph{cannot} be
9773 recovered.
9774
9775 To save @var{directory-1} as a first archive at the beginning of a
9776 tape, and leave that tape ready for a second archive, you should use:
9777
9778 @smallexample
9779 $ @kbd{mt -f /dev/nrtape rewind}
9780 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9781 @end smallexample
9782
9783 @cindex tape marks
9784 @dfn{Tape marks} are special magnetic patterns written on the tape
9785 media, which are later recognizable by the reading hardware. These
9786 marks are used after each file, when there are many on a single tape.
9787 An empty file (that is to say, two tape marks in a row) signal the
9788 logical end of the tape, after which no file exist. Usually,
9789 non-rewinding tape device drivers will react to the close request issued
9790 by @command{tar} by first writing two tape marks after your archive, and by
9791 backspacing over one of these. So, if you remove the tape at that time
9792 from the tape drive, it is properly terminated. But if you write
9793 another file at the current position, the second tape mark will be
9794 erased by the new information, leaving only one tape mark between files.
9795
9796 So, you may now save @var{directory-2} as a second archive after the
9797 first on the same tape by issuing the command:
9798
9799 @smallexample
9800 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9801 @end smallexample
9802
9803 @noindent
9804 and so on for all the archives you want to put on the same tape.
9805
9806 Another usual case is that you do not write all the archives the same
9807 day, and you need to remove and store the tape between two archive
9808 sessions. In general, you must remember how many files are already
9809 saved on your tape. Suppose your tape already has 16 files on it, and
9810 that you are ready to write the 17th. You have to take care of skipping
9811 the first 16 tape marks before saving @var{directory-17}, say, by using
9812 these commands:
9813
9814 @smallexample
9815 $ @kbd{mt -f /dev/nrtape rewind}
9816 $ @kbd{mt -f /dev/nrtape fsf 16}
9817 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9818 @end smallexample
9819
9820 In all the previous examples, we put aside blocking considerations, but
9821 you should do the proper things for that as well. @xref{Blocking}.
9822
9823 @menu
9824 * Tape Positioning:: Tape Positions and Tape Marks
9825 * mt:: The @command{mt} Utility
9826 @end menu
9827
9828 @node Tape Positioning
9829 @subsection Tape Positions and Tape Marks
9830 @UNREVISED
9831
9832 Just as archives can store more than one file from the file system,
9833 tapes can store more than one archive file. To keep track of where
9834 archive files (or any other type of file stored on tape) begin and
9835 end, tape archive devices write magnetic @dfn{tape marks} on the
9836 archive media. Tape drives write one tape mark between files,
9837 two at the end of all the file entries.
9838
9839 If you think of data as a series of records "rrrr"'s, and tape marks as
9840 "*"'s, a tape might look like the following:
9841
9842 @smallexample
9843 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9844 @end smallexample
9845
9846 Tape devices read and write tapes using a read/write @dfn{tape
9847 head}---a physical part of the device which can only access one
9848 point on the tape at a time. When you use @command{tar} to read or
9849 write archive data from a tape device, the device will begin reading
9850 or writing from wherever on the tape the tape head happens to be,
9851 regardless of which archive or what part of the archive the tape
9852 head is on. Before writing an archive, you should make sure that no
9853 data on the tape will be overwritten (unless it is no longer needed).
9854 Before reading an archive, you should make sure the tape head is at
9855 the beginning of the archive you want to read. You can do it manually
9856 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9857 that automatically (@pxref{Scripted Restoration}).
9858
9859 If you want to add new archive file entries to a tape, you should
9860 advance the tape to the end of the existing file entries, backspace
9861 over the last tape mark, and write the new archive file. If you were
9862 to add two archives to the example above, the tape might look like the
9863 following:
9864
9865 @smallexample
9866 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9867 @end smallexample
9868
9869 @node mt
9870 @subsection The @command{mt} Utility
9871 @UNREVISED
9872
9873 @FIXME{Is it true that this only works on non-block devices?
9874 should explain the difference, (fixed or variable).}
9875 @xref{Blocking Factor}.
9876
9877 You can use the @command{mt} utility to advance or rewind a tape past a
9878 specified number of archive files on the tape. This will allow you
9879 to move to the beginning of an archive before extracting or reading
9880 it, or to the end of all the archives before writing a new one.
9881 @FIXME{Why isn't there an "advance 'til you find two tape marks
9882 together"?}
9883
9884 The syntax of the @command{mt} command is:
9885
9886 @smallexample
9887 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9888 @end smallexample
9889
9890 where @var{tapename} is the name of the tape device, @var{number} is
9891 the number of times an operation is performed (with a default of one),
9892 and @var{operation} is one of the following:
9893
9894 @FIXME{is there any use for record operations?}
9895
9896 @table @option
9897 @item eof
9898 @itemx weof
9899 Writes @var{number} tape marks at the current position on the tape.
9900
9901 @item fsf
9902 Moves tape position forward @var{number} files.
9903
9904 @item bsf
9905 Moves tape position back @var{number} files.
9906
9907 @item rewind
9908 Rewinds the tape. (Ignores @var{number}).
9909
9910 @item offline
9911 @itemx rewoff1
9912 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9913
9914 @item status
9915 Prints status information about the tape unit.
9916
9917 @end table
9918
9919 @FIXME{Is there a better way to frob the spacing on the list?}
9920
9921 If you don't specify a @var{tapename}, @command{mt} uses the environment
9922 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9923 the default device specified in your @file{sys/mtio.h} file
9924 (@code{DEFTAPE} variable). If this is not defined, the program will
9925 display a descriptive error message and exit with code 1.
9926
9927 @command{mt} returns a 0 exit status when the operation(s) were
9928 successful, 1 if the command was unrecognized, and 2 if an operation
9929 failed.
9930
9931 @node Using Multiple Tapes
9932 @section Using Multiple Tapes
9933
9934 Often you might want to write a large archive, one larger than will fit
9935 on the actual tape you are using. In such a case, you can run multiple
9936 @command{tar} commands, but this can be inconvenient, particularly if you
9937 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9938 Therefore, @command{tar} provides a special mode for creating
9939 multi-volume archives.
9940
9941 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9942 on several media volumes of fixed size. Although in this section we will
9943 often call @samp{volume} a @dfn{tape}, there is absolutely no
9944 requirement for multi-volume archives to be stored on tapes. Instead,
9945 they can use whatever media type the user finds convenient, they can
9946 even be located on files.
9947
9948 When creating a multi-volume archive, @GNUTAR{} continues to fill
9949 current volume until it runs out of space, then it switches to
9950 next volume (usually the operator is queried to replace the tape on
9951 this point), and continues working on the new volume. This operation
9952 continues until all requested files are dumped. If @GNUTAR{} detects
9953 end of media while dumping a file, such a file is archived in split
9954 form. Some very big files can even be split across several volumes.
9955
9956 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9957 without any special options. Consequently any file member residing
9958 entirely on one volume can be extracted or otherwise operated upon
9959 without needing the other volume. Sure enough, to extract a split
9960 member you would need all volumes its parts reside on.
9961
9962 Multi-volume archives suffer from several limitations. In particular,
9963 they cannot be compressed.
9964
9965 @GNUTAR{} is able to create multi-volume archives of two formats
9966 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9967
9968 @menu
9969 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9970 * Tape Files:: Tape Files
9971 * Tarcat:: Concatenate Volumes into a Single Archive
9972
9973 @end menu
9974
9975 @node Multi-Volume Archives
9976 @subsection Archives Longer than One Tape or Disk
9977 @cindex Multi-volume archives
9978
9979 @opindex multi-volume
9980 To create an archive that is larger than will fit on a single unit of
9981 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9982 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9983 archive can be manipulated like any other archive (provided the
9984 @option{--multi-volume} option is specified), but is stored on more
9985 than one tape or disk.
9986
9987 When you specify @option{--multi-volume}, @command{tar} does not report an
9988 error when it comes to the end of an archive volume (when reading), or
9989 the end of the media (when writing). Instead, it prompts you to load
9990 a new storage volume. If the archive is on a magnetic tape, you
9991 should change tapes when you see the prompt; if the archive is on a
9992 floppy disk, you should change disks; etc.
9993
9994 @table @option
9995 @item --multi-volume
9996 @itemx -M
9997 Creates a multi-volume archive, when used in conjunction with
9998 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9999 archive, specify @option{--multi-volume} in conjunction with that
10000 operation.
10001 For example:
10002
10003 @smallexample
10004 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
10005 @end smallexample
10006 @end table
10007
10008 The method @command{tar} uses to detect end of tape is not perfect, and
10009 fails on some operating systems or on some devices. If @command{tar}
10010 cannot detect the end of the tape itself, you can use
10011 @option{--tape-length} option to inform it about the capacity of the
10012 tape:
10013
10014 @anchor{tape-length}
10015 @table @option
10016 @opindex tape-length
10017 @item --tape-length=@var{size}
10018 @itemx -L @var{size}
10019 Set maximum length of a volume. The @var{size} argument should then
10020 be the usable size of the tape in units of 1024 bytes. This option
10021 selects @option{--multi-volume} automatically. For example:
10022
10023 @smallexample
10024 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
10025 @end smallexample
10026 @end table
10027
10028 @anchor{change volume prompt}
10029 When @GNUTAR{} comes to the end of a storage media, it asks you to
10030 change the volume. The built-in prompt for POSIX locale
10031 is@footnote{If you run @GNUTAR{} under a different locale, the
10032 translation to the locale's language will be used.}:
10033
10034 @smallexample
10035 Prepare volume #@var{n} for `@var{archive}' and hit return:
10036 @end smallexample
10037
10038 @noindent
10039 where @var{n} is the ordinal number of the volume to be created and
10040 @var{archive} is archive file or device name.
10041
10042 When prompting for a new tape, @command{tar} accepts any of the following
10043 responses:
10044
10045 @table @kbd
10046 @item ?
10047 Request @command{tar} to explain possible responses
10048 @item q
10049 Request @command{tar} to exit immediately.
10050 @item n @var{file-name}
10051 Request @command{tar} to write the next volume on the file @var{file-name}.
10052 @item !
10053 Request @command{tar} to run a subshell. This option can be disabled
10054 by giving @option{--restrict} command line option to
10055 @command{tar}@footnote{@xref{--restrict}, for more information about
10056 this option}.
10057 @item y
10058 Request @command{tar} to begin writing the next volume.
10059 @end table
10060
10061 (You should only type @samp{y} after you have changed the tape;
10062 otherwise @command{tar} will write over the volume it just finished.)
10063
10064 @cindex Volume number file
10065 @cindex volno file
10066 @anchor{volno-file}
10067 @opindex volno-file
10068 The volume number used by @command{tar} in its tape-changing prompt
10069 can be changed; if you give the
10070 @option{--volno-file=@var{file-of-number}} option, then
10071 @var{file-of-number} should be an non-existing file to be created, or
10072 else, a file already containing a decimal number. That number will be
10073 used as the volume number of the first volume written. When
10074 @command{tar} is finished, it will rewrite the file with the
10075 now-current volume number. (This does not change the volume number
10076 written on a tape label, as per @ref{label}, it @emph{only} affects
10077 the number used in the prompt.)
10078
10079 @cindex End-of-archive info script
10080 @cindex Info script
10081 @anchor{info-script}
10082 @opindex info-script
10083 @opindex new-volume-script
10084 If you want more elaborate behavior than this, you can write a special
10085 @dfn{new volume script}, that will be responsible for changing the
10086 volume, and instruct @command{tar} to use it instead of its normal
10087 prompting procedure:
10088
10089 @table @option
10090 @item --info-script=@var{script-name}
10091 @itemx --new-volume-script=@var{script-name}
10092 @itemx -F @var{script-name}
10093 Specify the full name of the volume script to use. The script can be
10094 used to eject cassettes, or to broadcast messages such as
10095 @samp{Someone please come change my tape} when performing unattended
10096 backups.
10097 @end table
10098
10099 The @var{script-name} is executed without any command line
10100 arguments. It inherits @command{tar}'s shell environment.
10101 Additional data is passed to it via the following
10102 environment variables:
10103
10104 @table @env
10105 @vrindex TAR_VERSION, info script environment variable
10106 @item TAR_VERSION
10107 @GNUTAR{} version number.
10108
10109 @vrindex TAR_ARCHIVE, info script environment variable
10110 @item TAR_ARCHIVE
10111 The name of the archive @command{tar} is processing.
10112
10113 @vrindex TAR_VOLUME, info script environment variable
10114 @item TAR_VOLUME
10115 Ordinal number of the volume @command{tar} is about to start.
10116
10117 @vrindex TAR_SUBCOMMAND, info script environment variable
10118 @item TAR_SUBCOMMAND
10119 Short option describing the operation @command{tar} is executing
10120 @xref{Operations}, for a complete list of subcommand options.
10121
10122 @vrindex TAR_FORMAT, info script environment variable
10123 @item TAR_FORMAT
10124 Format of the archive being processed. @xref{Formats}, for a complete
10125 list of archive format names.
10126 @end table
10127
10128 The volume script can instruct @command{tar} to use new archive name,
10129 by writing in to file descriptor 3 (see below for an example).
10130
10131 If the info script fails, @command{tar} exits; otherwise, it begins
10132 writing the next volume.
10133
10134 If you want @command{tar} to cycle through a series of files or tape
10135 drives, there are three approaches to choose from. First of all, you
10136 can give @command{tar} multiple @option{--file} options. In this case
10137 the specified files will be used, in sequence, as the successive
10138 volumes of the archive. Only when the first one in the sequence needs
10139 to be used again will @command{tar} prompt for a tape change (or run
10140 the info script). For example, suppose someone has two tape drives on
10141 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10142 @GNUTAR{} to switch to the second drive when it needs to write the
10143 second tape, and then back to the first tape, etc., just do either of:
10144
10145 @smallexample
10146 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10147 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10148 @end smallexample
10149
10150 The second method is to use the @samp{n} response to the tape-change
10151 prompt.
10152
10153 Finally, the most flexible approach is to use a volume script, that
10154 writes new archive name to the file descriptor #3. For example, the
10155 following volume script will create a series of archive files, named
10156 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10157 archive being created (as given by @option{--file} option) and
10158 @var{vol} is the ordinal number of the archive being created:
10159
10160 @smallexample
10161 @group
10162 #! /bin/sh
10163 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10164
10165 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10166 case $TAR_SUBCOMMAND in
10167 -c) ;;
10168 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10169 ;;
10170 *) exit 1
10171 esac
10172
10173 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
10174 @end group
10175 @end smallexample
10176
10177 The same script cant be used while listing, comparing or extracting
10178 from the created archive. For example:
10179
10180 @smallexample
10181 @group
10182 # @r{Create a multi-volume archive:}
10183 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10184 # @r{Extract from the created archive:}
10185 $ @kbd{tar -x -f archive.tar -F new-volume .}
10186 @end group
10187 @end smallexample
10188
10189 @noindent
10190 Notice, that the first command had to use @option{-L} option, since
10191 otherwise @GNUTAR{} will end up writing everything to file
10192 @file{archive.tar}.
10193
10194 You can read each individual volume of a multi-volume archive as if it
10195 were an archive by itself. For example, to list the contents of one
10196 volume, use @option{--list}, without @option{--multi-volume} specified.
10197 To extract an archive member from one volume (assuming it is described
10198 that volume), use @option{--extract}, again without
10199 @option{--multi-volume}.
10200
10201 If an archive member is split across volumes (i.e., its entry begins on
10202 one volume of the media and ends on another), you need to specify
10203 @option{--multi-volume} to extract it successfully. In this case, you
10204 should load the volume where the archive member starts, and use
10205 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10206 volumes as it needs them. @xref{extracting archives}, for more
10207 information about extracting archives.
10208
10209 Multi-volume archives can be modified like any other archive. To add
10210 files to a multi-volume archive, you need to only mount the last
10211 volume of the archive media (and new volumes, if needed). For all
10212 other operations, you need to use the entire archive.
10213
10214 If a multi-volume archive was labeled using
10215 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10216 created, @command{tar} will not automatically label volumes which are
10217 added later. To label subsequent volumes, specify
10218 @option{--label=@var{archive-label}} again in conjunction with the
10219 @option{--append}, @option{--update} or @option{--concatenate} operation.
10220
10221 Notice that multi-volume support is a GNU extension and the archives
10222 created in this mode should be read only using @GNUTAR{}. If you
10223 absolutely have to process such archives using a third-party @command{tar}
10224 implementation, read @ref{Split Recovery}.
10225
10226 @node Tape Files
10227 @subsection Tape Files
10228 @UNREVISED
10229
10230 To give the archive a name which will be recorded in it, use the
10231 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10232 option. This will write a special block identifying
10233 @var{volume-label} as the name of the archive to the front of the
10234 archive which will be displayed when the archive is listed with
10235 @option{--list}. If you are creating a multi-volume archive with
10236 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10237 volume label will have @samp{Volume @var{nnn}} appended to the name
10238 you give, where @var{nnn} is the number of the volume of the archive.
10239 (If you use the @option{--label=@var{volume-label}}) option when
10240 reading an archive, it checks to make sure the label on the tape
10241 matches the one you give. @xref{label}.
10242
10243 When @command{tar} writes an archive to tape, it creates a single
10244 tape file. If multiple archives are written to the same tape, one
10245 after the other, they each get written as separate tape files. When
10246 extracting, it is necessary to position the tape at the right place
10247 before running @command{tar}. To do this, use the @command{mt} command.
10248 For more information on the @command{mt} command and on the organization
10249 of tapes into a sequence of tape files, see @ref{mt}.
10250
10251 People seem to often do:
10252
10253 @smallexample
10254 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10255 @end smallexample
10256
10257 or such, for pushing a common date in all volumes or an archive set.
10258
10259 @node Tarcat
10260 @subsection Concatenate Volumes into a Single Archive
10261
10262 @pindex tarcat
10263 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10264 archive to a single @command{tar} archive. Simply concatenating all
10265 volumes into one will not work, since each volume carries an additional
10266 information at the beginning. @GNUTAR{} is shipped with the shell
10267 script @command{tarcat} designed for this purpose.
10268
10269 The script takes a list of files comprising a multi-volume archive
10270 and creates the resulting archive at the standard output. For example:
10271
10272 @smallexample
10273 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10274 @end smallexample
10275
10276 The script implements a simple heuristics to determine the format of
10277 the first volume file and to decide how to process the rest of the
10278 files. However, it makes no attempt to verify whether the files are
10279 given in order or even if they are valid @command{tar} archives.
10280 It uses @command{dd} and does not filter its standard error, so you
10281 will usually see lots of spurious messages.
10282
10283 @FIXME{The script is not installed. Should we install it?}
10284
10285 @node label
10286 @section Including a Label in the Archive
10287 @cindex Labeling an archive
10288 @cindex Labels on the archive media
10289 @cindex Labeling multi-volume archives
10290 @UNREVISED
10291
10292 @opindex label
10293 To avoid problems caused by misplaced paper labels on the archive
10294 media, you can include a @dfn{label} entry---an archive member which
10295 contains the name of the archive---in the archive itself. Use the
10296 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10297 option in conjunction with the @option{--create} operation to include
10298 a label entry in the archive as it is being created.
10299
10300 @table @option
10301 @item --label=@var{archive-label}
10302 @itemx -V @var{archive-label}
10303 Includes an @dfn{archive-label} at the beginning of the archive when
10304 the archive is being created, when used in conjunction with the
10305 @option{--create} operation. Checks to make sure the archive label
10306 matches the one specified (when used in conjunction with any other
10307 operation.
10308 @end table
10309
10310 If you create an archive using both
10311 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10312 and @option{--multi-volume} (@option{-M}), each volume of the archive
10313 will have an archive label of the form @samp{@var{archive-label}
10314 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10315 next, and so on. @xref{Using Multiple Tapes}, for information on
10316 creating multiple volume archives.
10317
10318 @cindex Volume label, listing
10319 @cindex Listing volume label
10320 The volume label will be displayed by @option{--list} along with
10321 the file contents. If verbose display is requested, it will also be
10322 explicitly marked as in the example below:
10323
10324 @smallexample
10325 @group
10326 $ @kbd{tar --verbose --list --file=iamanarchive}
10327 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10328 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10329 @end group
10330 @end smallexample
10331
10332 @opindex test-label
10333 @anchor{--test-label option}
10334 However, @option{--list} option will cause listing entire
10335 contents of the archive, which may be undesirable (for example, if the
10336 archive is stored on a tape). You can request checking only the volume
10337 by specifying @option{--test-label} option. This option reads only the
10338 first block of an archive, so it can be used with slow storage
10339 devices. For example:
10340
10341 @smallexample
10342 @group
10343 $ @kbd{tar --test-label --file=iamanarchive}
10344 iamalabel
10345 @end group
10346 @end smallexample
10347
10348 If @option{--test-label} is used with a single command line
10349 argument, @command{tar} compares the volume label with the
10350 argument. It exits with code 0 if the two strings match, and with code
10351 2 otherwise. In this case no output is displayed. For example:
10352
10353 @smallexample
10354 @group
10355 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10356 @result{} 0
10357 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10358 @result{} 1
10359 @end group
10360 @end smallexample
10361
10362 If you request any operation, other than @option{--create}, along
10363 with using @option{--label} option, @command{tar} will first check if
10364 the archive label matches the one specified and will refuse to proceed
10365 if it does not. Use this as a safety precaution to avoid accidentally
10366 overwriting existing archives. For example, if you wish to add files
10367 to @file{archive}, presumably labeled with string @samp{My volume},
10368 you will get:
10369
10370 @smallexample
10371 @group
10372 $ @kbd{tar -rf archive --label 'My volume' .}
10373 tar: Archive not labeled to match `My volume'
10374 @end group
10375 @end smallexample
10376
10377 @noindent
10378 in case its label does not match. This will work even if
10379 @file{archive} is not labeled at all.
10380
10381 Similarly, @command{tar} will refuse to list or extract the
10382 archive if its label doesn't match the @var{archive-label}
10383 specified. In those cases, @var{archive-label} argument is interpreted
10384 as a globbing-style pattern which must match the actual magnetic
10385 volume label. @xref{exclude}, for a precise description of how match
10386 is attempted@footnote{Previous versions of @command{tar} used full
10387 regular expression matching, or before that, only exact string
10388 matching, instead of wildcard matchers. We decided for the sake of
10389 simplicity to use a uniform matching device through
10390 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10391 the volume label matcher will also suffix @var{archive-label} by
10392 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10393 up. Since the volume numbering is automatically added in labels at
10394 creation time, it sounded logical to equally help the user taking care
10395 of it when the archive is being read.
10396
10397 The @option{--label} was once called @option{--volume}, but is not
10398 available under that name anymore.
10399
10400 You can also use @option{--label} to get a common information on
10401 all tapes of a series. For having this information different in each
10402 series created through a single script used on a regular basis, just
10403 manage to get some date string as part of the label. For example:
10404
10405 @smallexample
10406 @group
10407 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10408 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10409 --volume="Daily backup for `date +%Y-%m-%d`"}
10410 @end group
10411 @end smallexample
10412
10413 Also note that each label has its own date and time, which corresponds
10414 to when @GNUTAR{} initially attempted to write it,
10415 often soon after the operator launches @command{tar} or types the
10416 carriage return telling that the next tape is ready. Comparing date
10417 labels does give an idea of tape throughput only if the delays for
10418 rewinding tapes and the operator switching them were negligible, which
10419 is usually not the case.
10420
10421 @node verify
10422 @section Verifying Data as It is Stored
10423 @cindex Verifying a write operation
10424 @cindex Double-checking a write operation
10425
10426 @table @option
10427 @item -W
10428 @itemx --verify
10429 @opindex verify, short description
10430 Attempt to verify the archive after writing.
10431 @end table
10432
10433 This option causes @command{tar} to verify the archive after writing it.
10434 Each volume is checked after it is written, and any discrepancies
10435 are recorded on the standard error output.
10436
10437 Verification requires that the archive be on a back-space-able medium.
10438 This means pipes, some cartridge tape drives, and some other devices
10439 cannot be verified.
10440
10441 You can insure the accuracy of an archive by comparing files in the
10442 system with archive members. @command{tar} can compare an archive to the
10443 file system as the archive is being written, to verify a write
10444 operation, or can compare a previously written archive, to insure that
10445 it is up to date.
10446
10447 @xopindex{verify, using with @option{--create}}
10448 @xopindex{create, using with @option{--verify}}
10449 To check for discrepancies in an archive immediately after it is
10450 written, use the @option{--verify} (@option{-W}) option in conjunction with
10451 the @option{--create} operation. When this option is
10452 specified, @command{tar} checks archive members against their counterparts
10453 in the file system, and reports discrepancies on the standard error.
10454
10455 To verify an archive, you must be able to read it from before the end
10456 of the last written entry. This option is useful for detecting data
10457 errors on some tapes. Archives written to pipes, some cartridge tape
10458 drives, and some other devices cannot be verified.
10459
10460 One can explicitly compare an already made archive with the file
10461 system by using the @option{--compare} (@option{--diff}, @option{-d})
10462 option, instead of using the more automatic @option{--verify} option.
10463 @xref{compare}.
10464
10465 Note that these two options have a slightly different intent. The
10466 @option{--compare} option checks how identical are the logical contents of some
10467 archive with what is on your disks, while the @option{--verify} option is
10468 really for checking if the physical contents agree and if the recording
10469 media itself is of dependable quality. So, for the @option{--verify}
10470 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10471 the archive, while it lets the speed optimization undisturbed for the
10472 @option{--compare} option. If you nevertheless use @option{--compare} for
10473 media verification, you may have to defeat the in-memory cache yourself,
10474 maybe by opening and reclosing the door latch of your recording unit,
10475 forcing some doubt in your operating system about the fact this is really
10476 the same volume as the one just written or read.
10477
10478 The @option{--verify} option would not be necessary if drivers were indeed
10479 able to detect dependably all write failures. This sometimes require many
10480 magnetic heads, some able to read after the writes occurred. One would
10481 not say that drivers unable to detect all cases are necessarily flawed,
10482 as long as programming is concerned.
10483
10484 The @option{--verify} (@option{-W}) option will not work in
10485 conjunction with the @option{--multi-volume} (@option{-M}) option or
10486 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10487 and @option{--delete} operations. @xref{Operations}, for more
10488 information on these operations.
10489
10490 Also, since @command{tar} normally strips leading @samp{/} from file
10491 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10492 /tmp/foo.tar /etc} will work as desired only if the working directory is
10493 @file{/}, as @command{tar} uses the archive's relative member names
10494 (e.g., @file{etc/motd}) when verifying the archive.
10495
10496 @node Write Protection
10497 @section Write Protection
10498
10499 Almost all tapes and diskettes, and in a few rare cases, even disks can
10500 be @dfn{write protected}, to protect data on them from being changed.
10501 Once an archive is written, you should write protect the media to prevent
10502 the archive from being accidentally overwritten or deleted. (This will
10503 protect the archive from being changed with a tape or floppy drive---it
10504 will not protect it from magnet fields or other physical hazards).
10505
10506 The write protection device itself is usually an integral part of the
10507 physical media, and can be a two position (write enabled/write
10508 disabled) switch, a notch which can be popped out or covered, a ring
10509 which can be removed from the center of a tape reel, or some other
10510 changeable feature.
10511
10512 @node Changes
10513 @appendix Changes
10514
10515 This appendix lists some important user-visible changes between
10516 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10517 version of this document is available at
10518 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10519 @GNUTAR{} documentation page}.
10520
10521 @table @asis
10522 @item Use of globbing patterns when listing and extracting.
10523
10524 Previous versions of GNU tar assumed shell-style globbing when
10525 extracting from or listing an archive. For example:
10526
10527 @smallexample
10528 $ @kbd{tar xf foo.tar '*.c'}
10529 @end smallexample
10530
10531 would extract all files whose names end in @samp{.c}. This behavior
10532 was not documented and was incompatible with traditional tar
10533 implementations. Therefore, starting from version 1.15.91, GNU tar
10534 no longer uses globbing by default. For example, the above invocation
10535 is now interpreted as a request to extract from the archive the file
10536 named @file{*.c}.
10537
10538 To facilitate transition to the new behavior for those users who got
10539 used to the previous incorrect one, @command{tar} will print a warning
10540 if it finds out that a requested member was not found in the archive
10541 and its name looks like a globbing pattern. For example:
10542
10543 @smallexample
10544 $ @kbd{tar xf foo.tar '*.c'}
10545 tar: Pattern matching characters used in file names. Please,
10546 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10547 tar: suppress this warning.
10548 tar: *.c: Not found in archive
10549 tar: Error exit delayed from previous errors
10550 @end smallexample
10551
10552 To treat member names as globbing patterns, use --wildcards option.
10553 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10554 add this option to your @env{TAR_OPTIONS} variable.
10555
10556 @xref{wildcards}, for the detailed discussion of the use of globbing
10557 patterns by @GNUTAR{}.
10558
10559 @item Use of short option @option{-o}.
10560
10561 Earlier versions of @GNUTAR{} understood @option{-o} command line
10562 option as a synonym for @option{--old-archive}.
10563
10564 @GNUTAR{} starting from version 1.13.90 understands this option as
10565 a synonym for @option{--no-same-owner}. This is compatible with
10566 UNIX98 @command{tar} implementations.
10567
10568 However, to facilitate transition, @option{-o} option retains its
10569 old semantics when it is used with one of archive-creation commands.
10570 Users are encouraged to use @option{--format=oldgnu} instead.
10571
10572 It is especially important, since versions of @acronym{GNU} Automake
10573 up to and including 1.8.4 invoke tar with this option to produce
10574 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10575 of this issue and its implications.
10576
10577 @FIXME{Change the first argument to tar-formats when the new Automake is
10578 out. The proposition to add @anchor{} to the appropriate place of its
10579 docs was accepted by Automake people --Sergey 2006-05-25}.
10580 @xref{Options, tar-v7, Changing Automake's Behavior,
10581 automake, GNU Automake}, for a description on how to use various
10582 archive formats with @command{automake}.
10583
10584 Future versions of @GNUTAR{} will understand @option{-o} only as a
10585 synonym for @option{--no-same-owner}.
10586
10587 @item Use of short option @option{-l}
10588
10589 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10590 synonym for @option{--one-file-system}. Since such usage contradicted
10591 to UNIX98 specification and harmed compatibility with other
10592 implementation, it was declared deprecated in version 1.14. However,
10593 to facilitate transition to its new semantics, it was supported by
10594 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10595 variant of @option{--check-links} was introduced in version 1.15.91.
10596
10597 @item Use of options @option{--portability} and @option{--old-archive}
10598
10599 These options are deprecated. Please use @option{--format=v7} instead.
10600
10601 @item Use of option @option{--posix}
10602
10603 This option is deprecated. Please use @option{--format=posix} instead.
10604 @end table
10605
10606 @node Configuring Help Summary
10607 @appendix Configuring Help Summary
10608
10609 Running @kbd{tar --help} displays the short @command{tar} option
10610 summary (@pxref{help}). This summary is organized by @dfn{groups} of
10611 semantically close options. The options within each group are printed
10612 in the following order: a short option, eventually followed by a list
10613 of corresponding long option names, followed by a short description of
10614 the option. For example, here is an excerpt from the actual @kbd{tar
10615 --help} output:
10616
10617 @verbatim
10618 Main operation mode:
10619
10620 -A, --catenate, --concatenate append tar files to an archive
10621 -c, --create create a new archive
10622 -d, --diff, --compare find differences between archive and
10623 file system
10624 --delete delete from the archive
10625 @end verbatim
10626
10627 @vrindex ARGP_HELP_FMT, environment variable
10628 The exact visual representation of the help output is configurable via
10629 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10630 is a comma-separated list of @dfn{format variable} assignments. There
10631 are two kinds of format variables. An @dfn{offset variable} keeps the
10632 offset of some part of help output text from the leftmost column on
10633 the screen. A @dfn{boolean} variable is a flag that toggles some
10634 output feature on or off. Depending on the type of the corresponding
10635 variable, there are two kinds of assignments:
10636
10637 @table @asis
10638 @item Offset assignment
10639
10640 The assignment to an offset variable has the following syntax:
10641
10642 @smallexample
10643 @var{variable}=@var{value}
10644 @end smallexample
10645
10646 @noindent
10647 where @var{variable} is the variable name, and @var{value} is a
10648 numeric value to be assigned to the variable.
10649
10650 @item Boolean assignment
10651
10652 To assign @code{true} value to a variable, simply put this variable name. To
10653 assign @code{false} value, prefix the variable name with @samp{no-}. For
10654 example:
10655
10656 @smallexample
10657 @group
10658 # Assign @code{true} value:
10659 dup-args
10660 # Assign @code{false} value:
10661 no-dup-args
10662 @end group
10663 @end smallexample
10664 @end table
10665
10666 Following variables are declared:
10667
10668 @deftypevr {Help Output} boolean dup-args
10669 If true, arguments for an option are shown with both short and long
10670 options, even when a given option has both forms, for example:
10671
10672 @smallexample
10673 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10674 @end smallexample
10675
10676 If false, then if an option has both short and long forms, the
10677 argument is only shown with the long one, for example:
10678
10679 @smallexample
10680 -f, --file=ARCHIVE use archive file or device ARCHIVE
10681 @end smallexample
10682
10683 @noindent
10684 and a message indicating that the argument is applicable to both
10685 forms is printed below the options. This message can be disabled
10686 using @code{dup-args-note} (see below).
10687
10688 The default is false.
10689 @end deftypevr
10690
10691 @deftypevr {Help Output} boolean dup-args-note
10692 If this variable is true, which is the default, the following notice
10693 is displayed at the end of the help output:
10694
10695 @quotation
10696 Mandatory or optional arguments to long options are also mandatory or
10697 optional for any corresponding short options.
10698 @end quotation
10699
10700 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10701 variables @code{dup-args} or @code{dup-args-note} should be set.
10702 @end deftypevr
10703
10704 @deftypevr {Help Output} offset short-opt-col
10705 Column in which short options start. Default is 2.
10706
10707 @smallexample
10708 @group
10709 $ @kbd{tar --help|grep ARCHIVE}
10710 -f, --file=ARCHIVE use archive file or device ARCHIVE
10711 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10712 -f, --file=ARCHIVE use archive file or device ARCHIVE
10713 @end group
10714 @end smallexample
10715 @end deftypevr
10716
10717 @deftypevr {Help Output} offset long-opt-col
10718 Column in which long options start. Default is 6. For example:
10719
10720 @smallexample
10721 @group
10722 $ @kbd{tar --help|grep ARCHIVE}
10723 -f, --file=ARCHIVE use archive file or device ARCHIVE
10724 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10725 -f, --file=ARCHIVE use archive file or device ARCHIVE
10726 @end group
10727 @end smallexample
10728 @end deftypevr
10729
10730 @deftypevr {Help Output} offset doc-opt-col
10731 Column in which @dfn{doc options} start. A doc option isn't actually
10732 an option, but rather an arbitrary piece of documentation that is
10733 displayed in much the same manner as the options. For example, in
10734 the description of @option{--format} option:
10735
10736 @smallexample
10737 @group
10738 -H, --format=FORMAT create archive of the given format.
10739
10740 FORMAT is one of the following:
10741
10742 gnu GNU tar 1.13.x format
10743 oldgnu GNU format as per tar <= 1.12
10744 pax POSIX 1003.1-2001 (pax) format
10745 posix same as pax
10746 ustar POSIX 1003.1-1988 (ustar) format
10747 v7 old V7 tar format
10748 @end group
10749 @end smallexample
10750
10751 @noindent
10752 the format names are doc options. Thus, if you set
10753 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10754 will look as follows:
10755
10756 @smallexample
10757 @group
10758 -H, --format=FORMAT create archive of the given format.
10759
10760 FORMAT is one of the following:
10761
10762 gnu GNU tar 1.13.x format
10763 oldgnu GNU format as per tar <= 1.12
10764 pax POSIX 1003.1-2001 (pax) format
10765 posix same as pax
10766 ustar POSIX 1003.1-1988 (ustar) format
10767 v7 old V7 tar format
10768 @end group
10769 @end smallexample
10770 @end deftypevr
10771
10772 @deftypevr {Help Output} offset opt-doc-col
10773 Column in which option description starts. Default is 29.
10774
10775 @smallexample
10776 @group
10777 $ @kbd{tar --help|grep ARCHIVE}
10778 -f, --file=ARCHIVE use archive file or device ARCHIVE
10779 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10780 -f, --file=ARCHIVE use archive file or device ARCHIVE
10781 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10782 -f, --file=ARCHIVE
10783 use archive file or device ARCHIVE
10784 @end group
10785 @end smallexample
10786
10787 @noindent
10788 Notice, that the description starts on a separate line if
10789 @code{opt-doc-col} value is too small.
10790 @end deftypevr
10791
10792 @deftypevr {Help Output} offset header-col
10793 Column in which @dfn{group headers} are printed. A group header is a
10794 descriptive text preceding an option group. For example, in the
10795 following text:
10796
10797 @verbatim
10798 Main operation mode:
10799
10800 -A, --catenate, --concatenate append tar files to
10801 an archive
10802 -c, --create create a new archive
10803 @end verbatim
10804 @noindent
10805 @samp{Main operation mode:} is the group header.
10806
10807 The default value is 1.
10808 @end deftypevr
10809
10810 @deftypevr {Help Output} offset usage-indent
10811 Indentation of wrapped usage lines. Affects @option{--usage}
10812 output. Default is 12.
10813 @end deftypevr
10814
10815 @deftypevr {Help Output} offset rmargin
10816 Right margin of the text output. Used for wrapping.
10817 @end deftypevr
10818
10819 @node Tar Internals
10820 @appendix Tar Internals
10821 @include intern.texi
10822
10823 @node Genfile
10824 @appendix Genfile
10825 @include genfile.texi
10826
10827 @node Free Software Needs Free Documentation
10828 @appendix Free Software Needs Free Documentation
10829 @include freemanuals.texi
10830
10831 @node Copying This Manual
10832 @appendix Copying This Manual
10833
10834 @menu
10835 * GNU Free Documentation License:: License for copying this manual
10836 @end menu
10837
10838 @include fdl.texi
10839
10840 @node Index of Command Line Options
10841 @appendix Index of Command Line Options
10842
10843 This appendix contains an index of all @GNUTAR{} long command line
10844 options. The options are listed without the preceding double-dash.
10845 For a cross-reference of short command line options, @ref{Short Option Summary}.
10846
10847 @printindex op
10848
10849 @node Index
10850 @appendix Index
10851
10852 @printindex cp
10853
10854 @summarycontents
10855 @contents
10856 @bye
10857
10858 @c Local variables:
10859 @c texinfo-column-for-description: 32
10860 @c End:
This page took 0.509348 seconds and 5 git commands to generate.