]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Remove trailing white space.
[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 --Mangled file names--
1004 This archive member contains @dfn{mangled file names} declarations,
1005 a special member type that was used by early versions of @GNUTAR{}.
1006 You probably will never encounter this, unless you are reading a very
1007 old archive.
1008
1009 @item unknown file type @var{c}
1010 An archive member of unknown type. @var{c} is the type character from
1011 the archive header. If you encounter such a message, it means that
1012 either your archive contains proprietary member types @GNUTAR{} is not
1013 able to handle, or the archive is corrupted.
1014 @end table
1015
1016 @end itemize
1017
1018 For example, here is an archive listing containing most of the special
1019 suffixes explained above:
1020
1021 @smallexample
1022 @group
1023 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1024 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1025 byte 32456--
1026 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1027 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1028 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1029 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1030 @end group
1031 @end smallexample
1032
1033 @smallexample
1034 @end smallexample
1035
1036 @node help tutorial
1037 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1038
1039 @table @option
1040 @opindex help
1041 @item --help
1042
1043 The @option{--help} option to @command{tar} prints out a very brief list of
1044 all operations and option available for the current version of
1045 @command{tar} available on your system.
1046 @end table
1047
1048 @node create
1049 @section How to Create Archives
1050 @UNREVISED
1051
1052 @cindex Creation of the archive
1053 @cindex Archive, creation of
1054 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1055 you use to create a @command{tar} archive. We will explain
1056 @option{--create} first because, in order to learn about the other
1057 operations, you will find it useful to have an archive available to
1058 practice on.
1059
1060 To make this easier, in this section you will first create a directory
1061 containing three files. Then, we will show you how to create an
1062 @emph{archive} (inside the new directory). Both the directory, and
1063 the archive are specifically for you to practice on. The rest of this
1064 chapter and the next chapter will show many examples using this
1065 directory and the files you will create: some of those files may be
1066 other directories and other archives.
1067
1068 The three files you will archive in this example are called
1069 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1070 @file{collection.tar}.
1071
1072 This section will proceed slowly, detailing how to use @option{--create}
1073 in @code{verbose} mode, and showing examples using both short and long
1074 forms. In the rest of the tutorial, and in the examples in the next
1075 chapter, we will proceed at a slightly quicker pace. This section
1076 moves more slowly to allow beginning users to understand how
1077 @command{tar} works.
1078
1079 @menu
1080 * prepare for examples::
1081 * Creating the archive::
1082 * create verbose::
1083 * short create::
1084 * create dir::
1085 @end menu
1086
1087 @node prepare for examples
1088 @subsection Preparing a Practice Directory for Examples
1089
1090 To follow along with this and future examples, create a new directory
1091 called @file{practice} containing files called @file{blues}, @file{folk}
1092 and @file{jazz}. The files can contain any information you like:
1093 ideally, they should contain information which relates to their names,
1094 and be of different lengths. Our examples assume that @file{practice}
1095 is a subdirectory of your home directory.
1096
1097 Now @command{cd} to the directory named @file{practice}; @file{practice}
1098 is now your @dfn{working directory}. (@emph{Please note}: Although
1099 the full path name of this directory is
1100 @file{/@var{homedir}/practice}, in our examples we will refer to
1101 this directory as @file{practice}; the @var{homedir} is presumed.
1102
1103 In general, you should check that the files to be archived exist where
1104 you think they do (in the working directory) by running @command{ls}.
1105 Because you just created the directory and the files and have changed to
1106 that directory, you probably don't need to do that this time.
1107
1108 It is very important to make sure there isn't already a file in the
1109 working directory with the archive name you intend to use (in this case,
1110 @samp{collection.tar}), or that you don't care about its contents.
1111 Whenever you use @samp{create}, @command{tar} will erase the current
1112 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1113 will not tell you if you are about to overwrite an archive unless you
1114 specify an option which does this (@pxref{backup}, for the
1115 information on how to do so). To add files to an existing archive,
1116 you need to use a different option, such as @option{--append} (@option{-r}); see
1117 @ref{append} for information on how to do this.
1118
1119 @node Creating the archive
1120 @subsection Creating the Archive
1121
1122 @xopindex{create, introduced}
1123 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1124 archive named @file{collection.tar}, use the following command:
1125
1126 @smallexample
1127 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1128 @end smallexample
1129
1130 The order of the arguments is not very important, @emph{when using long
1131 option forms}. You could also say:
1132
1133 @smallexample
1134 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1135 @end smallexample
1136
1137 @noindent
1138 However, you can see that this order is harder to understand; this is
1139 why we will list the arguments in the order that makes the commands
1140 easiest to understand (and we encourage you to do the same when you use
1141 @command{tar}, to avoid errors).
1142
1143 Note that the sequence
1144 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1145 If you substituted any other string of characters for
1146 @kbd{collection.tar}, then that string would become the name of the
1147 archive file you create.
1148
1149 The order of the options becomes more important when you begin to use
1150 short forms. With short forms, if you type commands in the wrong order
1151 (even if you type them correctly in all other ways), you may end up with
1152 results you don't expect. For this reason, it is a good idea to get
1153 into the habit of typing options in the order that makes inherent sense.
1154 @xref{short create}, for more information on this.
1155
1156 In this example, you type the command as shown above: @option{--create}
1157 is the operation which creates the new archive
1158 (@file{collection.tar}), and @option{--file} is the option which lets
1159 you give it the name you chose. The files, @file{blues}, @file{folk},
1160 and @file{jazz}, are now members of the archive, @file{collection.tar}
1161 (they are @dfn{file name arguments} to the @option{--create} operation.
1162 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1163 in the archive, they are called @emph{archive members}, not files.
1164 (@pxref{Definitions,members}).
1165
1166 When you create an archive, you @emph{must} specify which files you
1167 want placed in the archive. If you do not specify any archive
1168 members, @GNUTAR{} will complain.
1169
1170 If you now list the contents of the working directory (@command{ls}), you will
1171 find the archive file listed as well as the files you saw previously:
1172
1173 @smallexample
1174 blues folk jazz collection.tar
1175 @end smallexample
1176
1177 @noindent
1178 Creating the archive @samp{collection.tar} did not destroy the copies of
1179 the files in the directory.
1180
1181 Keep in mind that if you don't indicate an operation, @command{tar} will not
1182 run and will prompt you for one. If you don't name any files, @command{tar}
1183 will complain. You must have write access to the working directory,
1184 or else you will not be able to create an archive in that directory.
1185
1186 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1187 an existing archive; it will delete the archive and write a new one.
1188 Use @option{--append} (@option{-r}) instead. @xref{append}.
1189
1190 @node create verbose
1191 @subsection Running @option{--create} with @option{--verbose}
1192
1193 @xopindex{create, using with @option{--verbose}}
1194 @xopindex{verbose, using with @option{--create}}
1195 If you include the @option{--verbose} (@option{-v}) option on the command line,
1196 @command{tar} will list the files it is acting on as it is working. In
1197 verbose mode, the @code{create} example above would appear as:
1198
1199 @smallexample
1200 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1201 blues
1202 folk
1203 jazz
1204 @end smallexample
1205
1206 This example is just like the example we showed which did not use
1207 @option{--verbose}, except that @command{tar} generated the remaining lines
1208 @iftex
1209 (note the different font styles).
1210 @end iftex
1211 @ifinfo
1212 .
1213 @end ifinfo
1214
1215 In the rest of the examples in this chapter, we will frequently use
1216 @code{verbose} mode so we can show actions or @command{tar} responses that
1217 you would otherwise not see, and which are important for you to
1218 understand.
1219
1220 @node short create
1221 @subsection Short Forms with @samp{create}
1222
1223 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1224 basic uses of @command{tar}, and you will use it countless times.
1225 Eventually, you will probably want to use abbreviated (or ``short'')
1226 forms of options. A full discussion of the three different forms that
1227 options can take appears in @ref{Styles}; for now, here is what the
1228 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1229 using short option forms:
1230
1231 @smallexample
1232 $ @kbd{tar -cvf collection.tar blues folk jazz}
1233 blues
1234 folk
1235 jazz
1236 @end smallexample
1237
1238 @noindent
1239 As you can see, the system responds the same no matter whether you use
1240 long or short option forms.
1241
1242 @FIXME{i don't like how this is worded:} One difference between using
1243 short and long option forms is that, although the exact placement of
1244 arguments following options is no more specific when using short forms,
1245 it is easier to become confused and make a mistake when using short
1246 forms. For example, suppose you attempted the above example in the
1247 following way:
1248
1249 @smallexample
1250 $ @kbd{tar -cfv collection.tar blues folk jazz}
1251 @end smallexample
1252
1253 @noindent
1254 In this case, @command{tar} will make an archive file called @file{v},
1255 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1256 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1257 is thus taken to be the chosen archive file name. @command{tar} will try
1258 to add a file called @file{collection.tar} to the @file{v} archive file;
1259 if the file @file{collection.tar} did not already exist, @command{tar} will
1260 report an error indicating that this file does not exist. If the file
1261 @file{collection.tar} does already exist (e.g., from a previous command
1262 you may have run), then @command{tar} will add this file to the archive.
1263 Because the @option{-v} option did not get registered, @command{tar} will not
1264 run under @samp{verbose} mode, and will not report its progress.
1265
1266 The end result is that you may be quite confused about what happened,
1267 and possibly overwrite a file. To illustrate this further, we will show
1268 you how an example we showed previously would look using short forms.
1269
1270 This example,
1271
1272 @smallexample
1273 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1274 @end smallexample
1275
1276 @noindent
1277 is confusing as it is. When shown using short forms, however, it
1278 becomes much more so:
1279
1280 @smallexample
1281 $ @kbd{tar blues -c folk -f collection.tar jazz}
1282 @end smallexample
1283
1284 @noindent
1285 It would be very easy to put the wrong string of characters
1286 immediately following the @option{-f}, but doing that could sacrifice
1287 valuable data.
1288
1289 For this reason, we recommend that you pay very careful attention to
1290 the order of options and placement of file and archive names,
1291 especially when using short option forms. Not having the option name
1292 written out mnemonically can affect how well you remember which option
1293 does what, and therefore where different names have to be placed.
1294
1295 @node create dir
1296 @subsection Archiving Directories
1297
1298 @cindex Archiving Directories
1299 @cindex Directories, Archiving
1300 You can archive a directory by specifying its directory name as a
1301 file name argument to @command{tar}. The files in the directory will be
1302 archived relative to the working directory, and the directory will be
1303 re-created along with its contents when the archive is extracted.
1304
1305 To archive a directory, first move to its superior directory. If you
1306 have followed the previous instructions in this tutorial, you should
1307 type:
1308
1309 @smallexample
1310 $ @kbd{cd ..}
1311 $
1312 @end smallexample
1313
1314 @noindent
1315 This will put you into the directory which contains @file{practice},
1316 i.e., your home directory. Once in the superior directory, you can
1317 specify the subdirectory, @file{practice}, as a file name argument. To
1318 store @file{practice} in the new archive file @file{music.tar}, type:
1319
1320 @smallexample
1321 $ @kbd{tar --create --verbose --file=music.tar practice}
1322 @end smallexample
1323
1324 @noindent
1325 @command{tar} should output:
1326
1327 @smallexample
1328 practice/
1329 practice/blues
1330 practice/folk
1331 practice/jazz
1332 practice/collection.tar
1333 @end smallexample
1334
1335 Note that the archive thus created is not in the subdirectory
1336 @file{practice}, but rather in the current working directory---the
1337 directory from which @command{tar} was invoked. Before trying to archive a
1338 directory from its superior directory, you should make sure you have
1339 write access to the superior directory itself, not only the directory
1340 you are trying archive with @command{tar}. For example, you will probably
1341 not be able to store your home directory in an archive by invoking
1342 @command{tar} from the root directory; @xref{absolute}. (Note
1343 also that @file{collection.tar}, the original archive file, has itself
1344 been archived. @command{tar} will accept any file as a file to be
1345 archived, regardless of its content. When @file{music.tar} is
1346 extracted, the archive file @file{collection.tar} will be re-written
1347 into the file system).
1348
1349 If you give @command{tar} a command such as
1350
1351 @smallexample
1352 $ @kbd{tar --create --file=foo.tar .}
1353 @end smallexample
1354
1355 @noindent
1356 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1357 dumped}. This happens because @command{tar} creates the archive
1358 @file{foo.tar} in the current directory before putting any files into
1359 it. Then, when @command{tar} attempts to add all the files in the
1360 directory @file{.} to the archive, it notices that the file
1361 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1362 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1363 will continue in this case, and create the archive
1364 normally, except for the exclusion of that one file. (@emph{Please
1365 note:} Other implementations of @command{tar} may not be so clever;
1366 they will enter an infinite loop when this happens, so you should not
1367 depend on this behavior unless you are certain you are running
1368 @GNUTAR{}. In general, it is wise to always place the archive outside
1369 of the directory being dumped.
1370
1371 @node list
1372 @section How to List Archives
1373
1374 @opindex list
1375 Frequently, you will find yourself wanting to determine exactly what a
1376 particular archive contains. You can use the @option{--list}
1377 (@option{-t}) operation to get the member names as they currently
1378 appear in the archive, as well as various attributes of the files at
1379 the time they were archived. For example, you can examine the archive
1380 @file{collection.tar} that you created in the last section with the
1381 command,
1382
1383 @smallexample
1384 $ @kbd{tar --list --file=collection.tar}
1385 @end smallexample
1386
1387 @noindent
1388 The output of @command{tar} would then be:
1389
1390 @smallexample
1391 blues
1392 folk
1393 jazz
1394 @end smallexample
1395
1396 @noindent
1397 The archive @file{bfiles.tar} would list as follows:
1398
1399 @smallexample
1400 ./birds
1401 baboon
1402 ./box
1403 @end smallexample
1404
1405 @noindent
1406 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1407 @var{archive-name}}) option just as with @option{--create}
1408 (@option{-c}) to specify the name of the archive.
1409
1410 @xopindex{list, using with @option{--verbose}}
1411 @xopindex{verbose, using with @option{--list}}
1412 If you use the @option{--verbose} (@option{-v}) option with
1413 @option{--list}, then @command{tar} will print out a listing
1414 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1415 forth. This output is described in detail in @ref{verbose member listing}.
1416
1417 If you had used @option{--verbose} (@option{-v}) mode, the example
1418 above would look like:
1419
1420 @smallexample
1421 $ @kbd{tar --list --verbose --file=collection.tar folk}
1422 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1423 @end smallexample
1424
1425 @cindex listing member and file names
1426 @anchor{listing member and file names}
1427 It is important to notice that the output of @kbd{tar --list
1428 --verbose} does not necessarily match that produced by @kbd{tar
1429 --create --verbose} while creating the archive. It is because
1430 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1431 prefixes from file names before storing them in the archive
1432 (@xref{absolute}, for more information). In other
1433 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1434 an archive and @dfn{member names} when listing it. Consider this
1435 example:
1436
1437 @smallexample
1438 @group
1439 $ @kbd{tar cfv archive /etc/mail}
1440 tar: Removing leading `/' from member names
1441 /etc/mail/
1442 /etc/mail/sendmail.cf
1443 /etc/mail/aliases
1444 $ @kbd{tar tf archive}
1445 etc/mail/
1446 etc/mail/sendmail.cf
1447 etc/mail/aliases
1448 @end group
1449 @end smallexample
1450
1451 @opindex show-stored-names
1452 This default behavior can sometimes be inconvenient. You can force
1453 @GNUTAR{} show member names when creating archive by supplying
1454 @option{--show-stored-names} option.
1455
1456 @table @option
1457 @item --show-stored-names
1458 Print member (as opposed to @emph{file}) names when creating the archive.
1459 @end table
1460
1461 @cindex File name arguments, using @option{--list} with
1462 @xopindex{list, using with file name arguments}
1463 You can specify one or more individual member names as arguments when
1464 using @samp{list}. In this case, @command{tar} will only list the
1465 names of members you identify. For example, @w{@kbd{tar --list
1466 --file=afiles.tar apple}} would only print @file{apple}.
1467
1468 Because @command{tar} preserves paths, file names must be specified as
1469 they appear in the archive (i.e., relative to the directory from which
1470 the archive was created). Therefore, it is essential when specifying
1471 member names to @command{tar} that you give the exact member names.
1472 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1473 error message something like @samp{tar: birds: Not found in archive},
1474 because there is no member named @file{birds}, only one named
1475 @file{./birds}. While the names @file{birds} and @file{./birds} name
1476 the same file, @emph{member} names by default are compared verbatim.
1477
1478 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1479 with @file{baboon}, because this exact member name is in the archive file
1480 @file{bfiles.tar}. If you are not sure of the exact file name,
1481 use @dfn{globbing patterns}, for example:
1482
1483 @smallexample
1484 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1485 @end smallexample
1486
1487 @noindent
1488 will list all members whose name contains @samp{b}. @xref{wildcards},
1489 for a detailed discussion of globbing patterns and related
1490 @command{tar} command line options.
1491
1492 @menu
1493 * list dir::
1494 @end menu
1495
1496 @node list dir
1497 @unnumberedsubsec Listing the Contents of a Stored Directory
1498
1499 To get information about the contents of an archived directory,
1500 use the directory name as a file name argument in conjunction with
1501 @option{--list} (@option{-t}). To find out file attributes, include the
1502 @option{--verbose} (@option{-v}) option.
1503
1504 For example, to find out about files in the directory @file{practice}, in
1505 the archive file @file{music.tar}, type:
1506
1507 @smallexample
1508 $ @kbd{tar --list --verbose --file=music.tar practice}
1509 @end smallexample
1510
1511 @command{tar} responds:
1512
1513 @smallexample
1514 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1515 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1516 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1517 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1518 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1519 @end smallexample
1520
1521 When you use a directory name as a file name argument, @command{tar} acts on
1522 all the files (including sub-directories) in that directory.
1523
1524 @node extract
1525 @section How to Extract Members from an Archive
1526 @UNREVISED
1527 @cindex Extraction
1528 @cindex Retrieving files from an archive
1529 @cindex Resurrecting files from an archive
1530
1531 @opindex extract
1532 Creating an archive is only half the job---there is no point in storing
1533 files in an archive if you can't retrieve them. The act of retrieving
1534 members from an archive so they can be used and manipulated as
1535 unarchived files again is called @dfn{extraction}. To extract files
1536 from an archive, use the @option{--extract} (@option{--get} or
1537 @option{-x}) operation. As with @option{--create}, specify the name
1538 of the archive with @option{--file} (@option{-f}) option. Extracting
1539 an archive does not modify the archive in any way; you can extract it
1540 multiple times if you want or need to.
1541
1542 Using @option{--extract}, you can extract an entire archive, or specific
1543 files. The files can be directories containing other files, or not. As
1544 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1545 long form of the operation without affecting the performance.
1546
1547 @menu
1548 * extracting archives::
1549 * extracting files::
1550 * extract dir::
1551 * extracting untrusted archives::
1552 * failing commands::
1553 @end menu
1554
1555 @node extracting archives
1556 @subsection Extracting an Entire Archive
1557
1558 To extract an entire archive, specify the archive file name only, with
1559 no individual file names as arguments. For example,
1560
1561 @smallexample
1562 $ @kbd{tar -xvf collection.tar}
1563 @end smallexample
1564
1565 @noindent
1566 produces this:
1567
1568 @smallexample
1569 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1570 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1571 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1572 @end smallexample
1573
1574 @node extracting files
1575 @subsection Extracting Specific Files
1576
1577 To extract specific archive members, give their exact member names as
1578 arguments, as printed by @option{--list} (@option{-t}). If you had
1579 mistakenly deleted one of the files you had placed in the archive
1580 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1581 from the archive without changing the archive's structure. Its
1582 contents will be identical to the original file @file{blues} that you
1583 deleted.
1584
1585 First, make sure you are in the @file{practice} directory, and list the
1586 files in the directory. Now, delete the file, @samp{blues}, and list
1587 the files in the directory again.
1588
1589 You can now extract the member @file{blues} from the archive file
1590 @file{collection.tar} like this:
1591
1592 @smallexample
1593 $ @kbd{tar --extract --file=collection.tar blues}
1594 @end smallexample
1595
1596 @noindent
1597 If you list the files in the directory again, you will see that the file
1598 @file{blues} has been restored, with its original permissions, data
1599 modification times, and owner.@footnote{This is only accidentally
1600 true, but not in general. Whereas modification times are always
1601 restored, in most cases, one has to be root for restoring the owner,
1602 and use a special option for restoring permissions. Here, it just
1603 happens that the restoring user is also the owner of the archived
1604 members, and that the current @code{umask} is compatible with original
1605 permissions.} (These parameters will be identical to those which
1606 the file had when you originally placed it in the archive; any changes
1607 you may have made before deleting the file from the file system,
1608 however, will @emph{not} have been made to the archive member.) The
1609 archive file, @samp{collection.tar}, is the same as it was before you
1610 extracted @samp{blues}. You can confirm this by running @command{tar} with
1611 @option{--list} (@option{-t}).
1612
1613 Remember that as with other operations, specifying the exact member
1614 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1615 will fail, because there is no member named @file{birds}. To extract
1616 the member named @file{./birds}, you must specify @w{@kbd{tar
1617 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1618 exact member names, use @option{--list} (@option{-t}) option
1619 (@pxref{list}). You can also extract those members that match a
1620 specific @dfn{globbing pattern}. For example, to extract from
1621 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1622 directory prefix, you could type:
1623
1624 @smallexample
1625 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1626 @end smallexample
1627
1628 @noindent
1629 Here, @option{--wildcards} instructs @command{tar} to treat
1630 command line arguments as globbing patterns and @option{--no-anchored}
1631 informs it that the patterns apply to member names after any @samp{/}
1632 delimiter. The use of globbing patterns is discussed in detail in
1633 @xref{wildcards}.
1634
1635 You can extract a file to standard output by combining the above options
1636 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1637 Output}).
1638
1639 If you give the @option{--verbose} option, then @option{--extract}
1640 will print the names of the archive members as it extracts them.
1641
1642 @node extract dir
1643 @subsection Extracting Files that are Directories
1644
1645 Extracting directories which are members of an archive is similar to
1646 extracting other files. The main difference to be aware of is that if
1647 the extracted directory has the same name as any directory already in
1648 the working directory, then files in the extracted directory will be
1649 placed into the directory of the same name. Likewise, if there are
1650 files in the pre-existing directory with the same names as the members
1651 which you extract, the files from the extracted archive will replace
1652 the files already in the working directory (and possible
1653 subdirectories). This will happen regardless of whether or not the
1654 files in the working directory were more recent than those extracted
1655 (there exist, however, special options that alter this behavior
1656 @pxref{Writing}).
1657
1658 However, if a file was stored with a directory name as part of its file
1659 name, and that directory does not exist under the working directory when
1660 the file is extracted, @command{tar} will create the directory.
1661
1662 We can demonstrate how to use @option{--extract} to extract a directory
1663 file with an example. Change to the @file{practice} directory if you
1664 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1665 go back to the parent directory and extract the archive
1666 @file{music.tar}. You may either extract the entire archive, or you may
1667 extract only the files you just deleted. To extract the entire archive,
1668 don't give any file names as arguments after the archive name
1669 @file{music.tar}. To extract only the files you deleted, use the
1670 following command:
1671
1672 @smallexample
1673 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1674 practice/folk
1675 practice/jazz
1676 @end smallexample
1677
1678 @noindent
1679 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1680 would have displayed more detail about the extracted files, as shown
1681 in the example below:
1682
1683 @smallexample
1684 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1685 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1686 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1687 @end smallexample
1688
1689 @noindent
1690 Because you created the directory with @file{practice} as part of the
1691 file names of each of the files by archiving the @file{practice}
1692 directory as @file{practice}, you must give @file{practice} as part
1693 of the file names when you extract those files from the archive.
1694
1695 @node extracting untrusted archives
1696 @subsection Extracting Archives from Untrusted Sources
1697
1698 Extracting files from archives can overwrite files that already exist.
1699 If you receive an archive from an untrusted source, you should make a
1700 new directory and extract into that directory, so that you don't have
1701 to worry about the extraction overwriting one of your existing files.
1702 For example, if @file{untrusted.tar} came from somewhere else on the
1703 Internet, and you don't necessarily trust its contents, you can
1704 extract it as follows:
1705
1706 @smallexample
1707 $ @kbd{mkdir newdir}
1708 $ @kbd{cd newdir}
1709 $ @kbd{tar -xvf ../untrusted.tar}
1710 @end smallexample
1711
1712 It is also a good practice to examine contents of the archive
1713 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1714 with @option{--verbose} (@option{-v}).
1715
1716 @node failing commands
1717 @subsection Commands That Will Fail
1718
1719 Here are some sample commands you might try which will not work, and why
1720 they won't work.
1721
1722 If you try to use this command,
1723
1724 @smallexample
1725 $ @kbd{tar -xvf music.tar folk jazz}
1726 @end smallexample
1727
1728 @noindent
1729 you will get the following response:
1730
1731 @smallexample
1732 tar: folk: Not found in archive
1733 tar: jazz: Not found in archive
1734 $
1735 @end smallexample
1736
1737 @noindent
1738 This is because these files were not originally @emph{in} the parent
1739 directory @file{..}, where the archive is located; they were in the
1740 @file{practice} directory, and their file names reflect this:
1741
1742 @smallexample
1743 $ @kbd{tar -tvf music.tar}
1744 practice/folk
1745 practice/jazz
1746 practice/rock
1747 @end smallexample
1748
1749 @FIXME{make sure the above works when going through the examples in
1750 order...}
1751
1752 @noindent
1753 Likewise, if you try to use this command,
1754
1755 @smallexample
1756 $ @kbd{tar -tvf music.tar folk jazz}
1757 @end smallexample
1758
1759 @noindent
1760 you would get a similar response. Members with those names are not in the
1761 archive. You must use the correct member names, or wildcards, in order
1762 to extract the files from the archive.
1763
1764 If you have forgotten the correct names of the files in the archive,
1765 use @w{@kbd{tar --list --verbose}} to list them correctly.
1766
1767 @FIXME{more examples, here? hag thinks it's a good idea.}
1768
1769 @node going further
1770 @section Going Further Ahead in this Manual
1771
1772 @FIXME{need to write up a node here about the things that are going to
1773 be in the rest of the manual.}
1774
1775 @node tar invocation
1776 @chapter Invoking @GNUTAR{}
1777 @UNREVISED
1778
1779 This chapter is about how one invokes the @GNUTAR{}
1780 command, from the command synopsis (@pxref{Synopsis}). There are
1781 numerous options, and many styles for writing them. One mandatory
1782 option specifies the operation @command{tar} should perform
1783 (@pxref{Operation Summary}), other options are meant to detail how
1784 this operation should be performed (@pxref{Option Summary}).
1785 Non-option arguments are not always interpreted the same way,
1786 depending on what the operation is.
1787
1788 You will find in this chapter everything about option styles and rules for
1789 writing them (@pxref{Styles}). On the other hand, operations and options
1790 are fully described elsewhere, in other chapters. Here, you will find
1791 only synthetic descriptions for operations and options, together with
1792 pointers to other parts of the @command{tar} manual.
1793
1794 Some options are so special they are fully described right in this
1795 chapter. They have the effect of inhibiting the normal operation of
1796 @command{tar} or else, they globally alter the amount of feedback the user
1797 receives about what is going on. These are the @option{--help} and
1798 @option{--version} (@pxref{help}), @option{--verbose} (@pxref{verbose})
1799 and @option{--interactive} options (@pxref{interactive}).
1800
1801 @menu
1802 * Synopsis::
1803 * using tar options::
1804 * Styles::
1805 * All Options::
1806 * help::
1807 * defaults::
1808 * verbose::
1809 * interactive::
1810 @end menu
1811
1812 @node Synopsis
1813 @section General Synopsis of @command{tar}
1814
1815 The @GNUTAR{} program is invoked as either one of:
1816
1817 @smallexample
1818 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1819 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1820 @end smallexample
1821
1822 The second form is for when old options are being used.
1823
1824 You can use @command{tar} to store files in an archive, to extract them from
1825 an archive, and to do other types of archive manipulation. The primary
1826 argument to @command{tar}, which is called the @dfn{operation}, specifies
1827 which action to take. The other arguments to @command{tar} are either
1828 @dfn{options}, which change the way @command{tar} performs an operation,
1829 or file names or archive members, which specify the files or members
1830 @command{tar} is to act on.
1831
1832 You can actually type in arguments in any order, even if in this manual
1833 the options always precede the other arguments, to make examples easier
1834 to understand. Further, the option stating the main operation mode
1835 (the @command{tar} main command) is usually given first.
1836
1837 Each @var{name} in the synopsis above is interpreted as an archive member
1838 name when the main command is one of @option{--compare}
1839 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1840 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1841 @option{--update} (@option{-u}). When naming archive members, you
1842 must give the exact name of the member in the archive, as it is
1843 printed by @option{--list}. For @option{--append} (@option{-r}) and
1844 @option{--create} (@option{-c}), these @var{name} arguments specify
1845 the names of either files or directory hierarchies to place in the archive.
1846 These files or hierarchies should already exist in the file system,
1847 prior to the execution of the @command{tar} command.
1848
1849 @command{tar} interprets relative file names as being relative to the
1850 working directory. @command{tar} will make all file names relative
1851 (by removing leading slashes when archiving or restoring files),
1852 unless you specify otherwise (using the @option{--absolute-names}
1853 option). @xref{absolute}, for more information about
1854 @option{--absolute-names}.
1855
1856 If you give the name of a directory as either a file name or a member
1857 name, then @command{tar} acts recursively on all the files and directories
1858 beneath that directory. For example, the name @file{/} identifies all
1859 the files in the file system to @command{tar}.
1860
1861 The distinction between file names and archive member names is especially
1862 important when shell globbing is used, and sometimes a source of confusion
1863 for newcomers. @xref{wildcards}, for more information about globbing.
1864 The problem is that shells may only glob using existing files in the
1865 file system. Only @command{tar} itself may glob on archive members, so when
1866 needed, you must ensure that wildcard characters reach @command{tar} without
1867 being interpreted by the shell first. Using a backslash before @samp{*}
1868 or @samp{?}, or putting the whole argument between quotes, is usually
1869 sufficient for this.
1870
1871 Even if @var{name}s are often specified on the command line, they
1872 can also be read from a text file in the file system, using the
1873 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1874
1875 If you don't use any file name arguments, @option{--append} (@option{-r}),
1876 @option{--delete} and @option{--concatenate} (@option{--catenate},
1877 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1878 will usually yield a diagnostic and inhibit @command{tar} execution.
1879 The other operations of @command{tar} (@option{--list},
1880 @option{--extract}, @option{--compare}, and @option{--update})
1881 will act on the entire contents of the archive.
1882
1883 @cindex exit status
1884 @cindex return status
1885 Besides successful exits, @GNUTAR{} may fail for
1886 many reasons. Some reasons correspond to bad usage, that is, when the
1887 @command{tar} command is improperly written. Errors may be
1888 encountered later, while encountering an error processing the archive
1889 or the files. Some errors are recoverable, in which case the failure
1890 is delayed until @command{tar} has completed all its work. Some
1891 errors are such that it would not meaningful, or at least risky, to
1892 continue processing: @command{tar} then aborts processing immediately.
1893 All abnormal exits, whether immediate or delayed, should always be
1894 clearly diagnosed on @code{stderr}, after a line stating the nature of
1895 the error.
1896
1897 Possible exit codes of @GNUTAR{} are summarized in the following
1898 table:
1899
1900 @table @asis
1901 @item 0
1902 @samp{Successful termination}.
1903
1904 @item 1
1905 @samp{Some files differ}. If tar was invoked with @option{--compare}
1906 (@option{--diff}, @option{-d}) command line option, this means that
1907 some files in the archive differ from their disk counterparts
1908 (@pxref{compare}). If tar was given @option{--create},
1909 @option{--append} or @option{--update} option, this exit code means
1910 that some files were changed while being archived and so the resulting
1911 archive does not contain the exact copy of the file set.
1912
1913 @item 2
1914 @samp{Fatal error}. This means that some fatal, unrecoverable error
1915 occurred.
1916 @end table
1917
1918 If @command{tar} has invoked a subprocess and that subprocess exited with a
1919 nonzero exit code, @command{tar} exits with that code as well.
1920 This can happen, for example, if @command{tar} was given some
1921 compression option (@pxref{gzip}) and the external compressor program
1922 failed. Another example is @command{rmt} failure during backup to the
1923 remote device (@pxref{Remote Tape Server}).
1924
1925 @node using tar options
1926 @section Using @command{tar} Options
1927
1928 @GNUTAR{} has a total of eight operating modes which
1929 allow you to perform a variety of tasks. You are required to choose
1930 one operating mode each time you employ the @command{tar} program by
1931 specifying one, and only one operation as an argument to the
1932 @command{tar} command (two lists of four operations each may be found
1933 at @ref{frequent operations} and @ref{Operations}). Depending on
1934 circumstances, you may also wish to customize how the chosen operating
1935 mode behaves. For example, you may wish to change the way the output
1936 looks, or the format of the files that you wish to archive may require
1937 you to do something special in order to make the archive look right.
1938
1939 You can customize and control @command{tar}'s performance by running
1940 @command{tar} with one or more options (such as @option{--verbose}
1941 (@option{-v}), which we used in the tutorial). As we said in the
1942 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1943 their name suggests) optional. Depending on the operating mode, you
1944 may specify one or more options. Different options will have different
1945 effects, but in general they all change details of the operation, such
1946 as archive format, archive name, or level of user interaction. Some
1947 options make sense with all operating modes, while others are
1948 meaningful only with particular modes. You will likely use some
1949 options frequently, while you will only use others infrequently, or
1950 not at all. (A full list of options is available in @pxref{All Options}.)
1951
1952 @vrindex TAR_OPTIONS, environment variable
1953 @anchor{TAR_OPTIONS}
1954 The @env{TAR_OPTIONS} environment variable specifies default options to
1955 be placed in front of any explicit options. For example, if
1956 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1957 if the two options @option{-v} and @option{--unlink-first} had been
1958 specified before any explicit options. Option specifications are
1959 separated by whitespace. A backslash escapes the next character, so it
1960 can be used to specify an option containing whitespace or a backslash.
1961
1962 Note that @command{tar} options are case sensitive. For example, the
1963 options @option{-T} and @option{-t} are different; the first requires an
1964 argument for stating the name of a file providing a list of @var{name}s,
1965 while the second does not require an argument and is another way to
1966 write @option{--list} (@option{-t}).
1967
1968 In addition to the eight operations, there are many options to
1969 @command{tar}, and three different styles for writing both: long (mnemonic)
1970 form, short form, and old style. These styles are discussed below.
1971 Both the options and the operations can be written in any of these three
1972 styles.
1973
1974 @FIXME{menu at end of this node. need to think of an actual outline
1975 for this chapter; probably do that after stuff from chapter 4 is
1976 incorporated.}
1977
1978 @node Styles
1979 @section The Three Option Styles
1980
1981 There are three styles for writing operations and options to the command
1982 line invoking @command{tar}. The different styles were developed at
1983 different times during the history of @command{tar}. These styles will be
1984 presented below, from the most recent to the oldest.
1985
1986 Some options must take an argument. (For example, @option{--file}
1987 (@option{-f})) takes the name of an archive file as an argument. If
1988 you do not supply an archive file name, @command{tar} will use a
1989 default, but this can be confusing; thus, we recommend that you always
1990 supply a specific archive file name.) Where you @emph{place} the
1991 arguments generally depends on which style of options you choose. We
1992 will detail specific information relevant to each option style in the
1993 sections on the different option styles, below. The differences are
1994 subtle, yet can often be very important; incorrect option placement
1995 can cause you to overwrite a number of important files. We urge you
1996 to note these differences, and only use the option style(s) which
1997 makes the most sense to you until you feel comfortable with the others.
1998
1999 Some options @emph{may} take an argument. Such options may have at
2000 most long and short forms, they do not have old style equivalent. The
2001 rules for specifying an argument for such options are stricter than
2002 those for specifying mandatory arguments. Please, pay special
2003 attention to them.
2004
2005 @menu
2006 * Long Options:: Long Option Style
2007 * Short Options:: Short Option Style
2008 * Old Options:: Old Option Style
2009 * Mixing:: Mixing Option Styles
2010 @end menu
2011
2012 @node Long Options
2013 @subsection Long Option Style
2014
2015 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2016 dashes in a row, e.g., @option{--list}. The long names are more clear than
2017 their corresponding short or old names. It sometimes happens that a
2018 single long option has many different different names which are
2019 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2020 long option names can be given unique abbreviations. For example,
2021 @option{--cre} can be used in place of @option{--create} because there is no
2022 other long option which begins with @samp{cre}. (One way to find
2023 this out is by trying it and seeing what happens; if a particular
2024 abbreviation could represent more than one option, @command{tar} will tell
2025 you that that abbreviation is ambiguous and you'll know that that
2026 abbreviation won't work. You may also choose to run @samp{tar --help}
2027 to see a list of options. Be aware that if you run @command{tar} with a
2028 unique abbreviation for the long name of an option you didn't want to
2029 use, you are stuck; @command{tar} will perform the command as ordered.)
2030
2031 Long options are meant to be obvious and easy to remember, and their
2032 meanings are generally easier to discern than those of their
2033 corresponding short options (see below). For example:
2034
2035 @smallexample
2036 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2037 @end smallexample
2038
2039 @noindent
2040 gives a fairly good set of hints about what the command does, even
2041 for those not fully acquainted with @command{tar}.
2042
2043 Long options which require arguments take those arguments
2044 immediately following the option name. There are two ways of
2045 specifying a mandatory argument. It can be separated from the
2046 option name either by an equal sign, or by any amount of
2047 white space characters. For example, the @option{--file} option (which
2048 tells the name of the @command{tar} archive) is given a file such as
2049 @file{archive.tar} as argument by using any of the following notations:
2050 @option{--file=archive.tar} or @option{--file archive.tar}.
2051
2052 In contrast, optional arguments must always be introduced using
2053 an equal sign. For example, the @option{--backup} option takes
2054 an optional argument specifying backup type. It must be used
2055 as @option{--backup=@var{backup-type}}.
2056
2057 @node Short Options
2058 @subsection Short Option Style
2059
2060 Most options also have a @dfn{short option} name. Short options start with
2061 a single dash, and are followed by a single character, e.g., @option{-t}
2062 (which is equivalent to @option{--list}). The forms are absolutely
2063 identical in function; they are interchangeable.
2064
2065 The short option names are faster to type than long option names.
2066
2067 Short options which require arguments take their arguments immediately
2068 following the option, usually separated by white space. It is also
2069 possible to stick the argument right after the short option name, using
2070 no intervening space. For example, you might write @w{@option{-f
2071 archive.tar}} or @option{-farchive.tar} instead of using
2072 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2073 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2074 specific archive, here named @file{archive.tar}.
2075
2076 Short options which take optional arguments take their arguments
2077 immediately following the option letter, @emph{without any intervening
2078 white space characters}.
2079
2080 Short options' letters may be clumped together, but you are not
2081 required to do this (as compared to old options; see below). When
2082 short options are clumped as a set, use one (single) dash for them
2083 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2084 such a set is allowed to have an argument@footnote{Clustering many
2085 options, the last of which has an argument, is a rather opaque way to
2086 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2087 even be made helpful enough for considering such usages as invalid.}.
2088
2089 When the options are separated, the argument for each option which requires
2090 an argument directly follows that option, as is usual for Unix programs.
2091 For example:
2092
2093 @smallexample
2094 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2095 @end smallexample
2096
2097 If you reorder short options' locations, be sure to move any arguments
2098 that belong to them. If you do not move the arguments properly, you may
2099 end up overwriting files.
2100
2101 @node Old Options
2102 @subsection Old Option Style
2103 @UNREVISED
2104
2105 Like short options, @dfn{old options} are single letters. However, old options
2106 must be written together as a single clumped set, without spaces separating
2107 them or dashes preceding them@footnote{Beware that if you precede options
2108 with a dash, you are announcing the short option style instead of the
2109 old option style; short options are decoded differently.}. This set
2110 of letters must be the first to appear on the command line, after the
2111 @command{tar} program name and some white space; old options cannot appear
2112 anywhere else. The letter of an old option is exactly the same letter as
2113 the corresponding short option. For example, the old option @samp{t} is
2114 the same as the short option @option{-t}, and consequently, the same as the
2115 long option @option{--list}. So for example, the command @w{@samp{tar
2116 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2117
2118 When options that need arguments are given together with the command,
2119 all the associated arguments follow, in the same order as the options.
2120 Thus, the example given previously could also be written in the old
2121 style as follows:
2122
2123 @smallexample
2124 $ @kbd{tar cvbf 20 /dev/rmt0}
2125 @end smallexample
2126
2127 @noindent
2128 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2129 the argument of @option{-f}.
2130
2131 On the other hand, this old style syntax makes it difficult to match
2132 option letters with their corresponding arguments, and is often
2133 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2134 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2135 argument for @option{-f}, and @option{-v} does not have a corresponding
2136 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2137 /dev/rmt0}} is clearer, putting all arguments next to the option they
2138 pertain to.
2139
2140 If you want to reorder the letters in the old option argument, be
2141 sure to reorder any corresponding argument appropriately.
2142
2143 This old way of writing @command{tar} options can surprise even experienced
2144 users. For example, the two commands:
2145
2146 @smallexample
2147 @kbd{tar cfz archive.tar.gz file}
2148 @kbd{tar -cfz archive.tar.gz file}
2149 @end smallexample
2150
2151 @noindent
2152 are quite different. The first example uses @file{archive.tar.gz} as
2153 the value for option @samp{f} and recognizes the option @samp{z}. The
2154 second example, however, uses @file{z} as the value for option
2155 @samp{f} --- probably not what was intended.
2156
2157 Old options are kept for compatibility with old versions of @command{tar}.
2158
2159 This second example could be corrected in many ways, among which the
2160 following are equivalent:
2161
2162 @smallexample
2163 @kbd{tar -czf archive.tar.gz file}
2164 @kbd{tar -cf archive.tar.gz -z file}
2165 @kbd{tar cf archive.tar.gz -z file}
2166 @end smallexample
2167
2168 @cindex option syntax, traditional
2169 As far as we know, all @command{tar} programs, @acronym{GNU} and
2170 non-@acronym{GNU}, support old options. @GNUTAR{}
2171 supports them not only for historical reasons, but also because many
2172 people are used to them. For compatibility with Unix @command{tar},
2173 the first argument is always treated as containing command and option
2174 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2175 equivalent to @w{@samp{tar -c}:} both of them specify the
2176 @option{--create} (@option{-c}) command to create an archive.
2177
2178 @node Mixing
2179 @subsection Mixing Option Styles
2180
2181 All three styles may be intermixed in a single @command{tar} command,
2182 so long as the rules for each style are fully
2183 respected@footnote{Before @GNUTAR{} version 1.11.6,
2184 a bug prevented intermixing old style options with long options in
2185 some cases.}. Old style options and either of the modern styles of
2186 options may be mixed within a single @command{tar} command. However,
2187 old style options must be introduced as the first arguments only,
2188 following the rule for old options (old options must appear directly
2189 after the @command{tar} command and some white space). Modern options
2190 may be given only after all arguments to the old options have been
2191 collected. If this rule is not respected, a modern option might be
2192 falsely interpreted as the value of the argument to one of the old
2193 style options.
2194
2195 For example, all the following commands are wholly equivalent, and
2196 illustrate the many combinations and orderings of option styles.
2197
2198 @smallexample
2199 @kbd{tar --create --file=archive.tar}
2200 @kbd{tar --create -f archive.tar}
2201 @kbd{tar --create -farchive.tar}
2202 @kbd{tar --file=archive.tar --create}
2203 @kbd{tar --file=archive.tar -c}
2204 @kbd{tar -c --file=archive.tar}
2205 @kbd{tar -c -f archive.tar}
2206 @kbd{tar -c -farchive.tar}
2207 @kbd{tar -cf archive.tar}
2208 @kbd{tar -cfarchive.tar}
2209 @kbd{tar -f archive.tar --create}
2210 @kbd{tar -f archive.tar -c}
2211 @kbd{tar -farchive.tar --create}
2212 @kbd{tar -farchive.tar -c}
2213 @kbd{tar c --file=archive.tar}
2214 @kbd{tar c -f archive.tar}
2215 @kbd{tar c -farchive.tar}
2216 @kbd{tar cf archive.tar}
2217 @kbd{tar f archive.tar --create}
2218 @kbd{tar f archive.tar -c}
2219 @kbd{tar fc archive.tar}
2220 @end smallexample
2221
2222 On the other hand, the following commands are @emph{not} equivalent to
2223 the previous set:
2224
2225 @smallexample
2226 @kbd{tar -f -c archive.tar}
2227 @kbd{tar -fc archive.tar}
2228 @kbd{tar -fcarchive.tar}
2229 @kbd{tar -farchive.tarc}
2230 @kbd{tar cfarchive.tar}
2231 @end smallexample
2232
2233 @noindent
2234 These last examples mean something completely different from what the
2235 user intended (judging based on the example in the previous set which
2236 uses long options, whose intent is therefore very clear). The first
2237 four specify that the @command{tar} archive would be a file named
2238 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2239 respectively. The first two examples also specify a single non-option,
2240 @var{name} argument having the value @samp{archive.tar}. The last
2241 example contains only old style option letters (repeating option
2242 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2243 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2244 the first sentence of this paragraph..}
2245
2246 @node All Options
2247 @section All @command{tar} Options
2248
2249 The coming manual sections contain an alphabetical listing of all
2250 @command{tar} operations and options, with brief descriptions and cross
2251 references to more in-depth explanations in the body of the manual.
2252 They also contain an alphabetically arranged table of the short option
2253 forms with their corresponding long option. You can use this table as
2254 a reference for deciphering @command{tar} commands in scripts.
2255
2256 @menu
2257 * Operation Summary::
2258 * Option Summary::
2259 * Short Option Summary::
2260 @end menu
2261
2262 @node Operation Summary
2263 @subsection Operations
2264
2265 @table @option
2266
2267 @opsummary{append}
2268 @item --append
2269 @itemx -r
2270
2271 Appends files to the end of the archive. @xref{append}.
2272
2273 @opsummary{catenate}
2274 @item --catenate
2275 @itemx -A
2276
2277 Same as @option{--concatenate}. @xref{concatenate}.
2278
2279 @opsummary{compare}
2280 @item --compare
2281 @itemx -d
2282
2283 Compares archive members with their counterparts in the file
2284 system, and reports differences in file size, mode, owner,
2285 modification date and contents. @xref{compare}.
2286
2287 @opsummary{concatenate}
2288 @item --concatenate
2289 @itemx -A
2290
2291 Appends other @command{tar} archives to the end of the archive.
2292 @xref{concatenate}.
2293
2294 @opsummary{create}
2295 @item --create
2296 @itemx -c
2297
2298 Creates a new @command{tar} archive. @xref{create}.
2299
2300 @opsummary{delete}
2301 @item --delete
2302
2303 Deletes members from the archive. Don't try this on a archive on a
2304 tape! @xref{delete}.
2305
2306 @opsummary{diff}
2307 @item --diff
2308 @itemx -d
2309
2310 Same @option{--compare}. @xref{compare}.
2311
2312 @opsummary{extract}
2313 @item --extract
2314 @itemx -x
2315
2316 Extracts members from the archive into the file system. @xref{extract}.
2317
2318 @opsummary{get}
2319 @item --get
2320 @itemx -x
2321
2322 Same as @option{--extract}. @xref{extract}.
2323
2324 @opsummary{list}
2325 @item --list
2326 @itemx -t
2327
2328 Lists the members in an archive. @xref{list}.
2329
2330 @opsummary{update}
2331 @item --update
2332 @itemx -u
2333
2334 Adds files to the end of the archive, but only if they are newer than
2335 their counterparts already in the archive, or if they do not already
2336 exist in the archive. @xref{update}.
2337
2338 @end table
2339
2340 @node Option Summary
2341 @subsection @command{tar} Options
2342
2343 @table @option
2344
2345 @opsummary{absolute-names}
2346 @item --absolute-names
2347 @itemx -P
2348
2349 Normally when creating an archive, @command{tar} strips an initial
2350 @samp{/} from member names. This option disables that behavior.
2351 @xref{absolute}.
2352
2353 @opsummary{after-date}
2354 @item --after-date
2355
2356 (See @option{--newer}, @pxref{after})
2357
2358 @opsummary{anchored}
2359 @item --anchored
2360 A pattern must match an initial subsequence of the name's components.
2361 @xref{controlling pattern-matching}.
2362
2363 @opsummary{atime-preserve}
2364 @item --atime-preserve
2365 @itemx --atime-preserve=replace
2366 @itemx --atime-preserve=system
2367
2368 Attempt to preserve the access time of files when reading them. This
2369 option currently is effective only on files that you own, unless you
2370 have superuser privileges.
2371
2372 @option{--atime-preserve=replace} remembers the access time of a file
2373 before reading it, and then restores the access time afterwards. This
2374 may cause problems if other programs are reading the file at the same
2375 time, as the times of their accesses will be lost. On most platforms
2376 restoring the access time also requires @command{tar} to restore the
2377 data modification time too, so this option may also cause problems if
2378 other programs are writing the file at the same time. (Tar attempts
2379 to detect this situation, but cannot do so reliably due to race
2380 conditions.) Worse, on most platforms restoring the access time also
2381 updates the status change time, which means that this option is
2382 incompatible with incremental backups.
2383
2384 @option{--atime-preserve=system} avoids changing time stamps on files,
2385 without interfering with time stamp updates
2386 caused by other programs, so it works better with incremental backups.
2387 However, it requires a special @code{O_NOATIME} option from the
2388 underlying operating and file system implementation, and it also requires
2389 that searching directories does not update their access times. As of
2390 this writing (November 2005) this works only with Linux, and only with
2391 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2392 way to know whether this feature actually works. Sometimes
2393 @command{tar} knows that it does not work, and if you use
2394 @option{--atime-preserve=system} then @command{tar} complains and
2395 exits right away. But other times @command{tar} might think that the
2396 option works when it actually does not.
2397
2398 Currently @option{--atime-preserve} with no operand defaults to
2399 @option{--atime-preserve=replace}, but this may change in the future
2400 as support for @option{--atime-preserve=system} improves.
2401
2402 If your operating system does not support
2403 @option{--atime-preserve=@-system}, you might be able to preserve access
2404 times reliably by by using the @command{mount} command. For example,
2405 you can mount the file system read-only, or access the file system via
2406 a read-only loopback mount, or use the @samp{noatime} mount option
2407 available on some systems. However, mounting typically requires
2408 superuser privileges and can be a pain to manage.
2409
2410 @opsummary{backup}
2411 @item --backup=@var{backup-type}
2412
2413 Rather than deleting files from the file system, @command{tar} will
2414 back them up using simple or numbered backups, depending upon
2415 @var{backup-type}. @xref{backup}.
2416
2417 @opsummary{block-number}
2418 @item --block-number
2419 @itemx -R
2420
2421 With this option present, @command{tar} prints error messages for read errors
2422 with the block number in the archive file. @xref{block-number}.
2423
2424 @opsummary{blocking-factor}
2425 @item --blocking-factor=@var{blocking}
2426 @itemx -b @var{blocking}
2427
2428 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2429 record. @xref{Blocking Factor}.
2430
2431 @opsummary{bzip2}
2432 @item --bzip2
2433 @itemx -j
2434
2435 This option tells @command{tar} to read or write archives through
2436 @code{bzip2}. @xref{gzip}.
2437
2438 @opsummary{checkpoint}
2439 @item --checkpoint[=@var{number}]
2440
2441 This option directs @command{tar} to print periodic checkpoint
2442 messages as it reads through the archive. It is intended for when you
2443 want a visual indication that @command{tar} is still running, but
2444 don't want to see @option{--verbose} output. For a detailed
2445 description, see @ref{Progress information}.
2446
2447 @opsummary{check-links}
2448 @item --check-links
2449 @itemx -l
2450 If this option was given, @command{tar} will check the number of links
2451 dumped for each processed file. If this number does not match the
2452 total number of hard links for the file, a warning message will be
2453 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2454 synonym for @option{--one-file-system}. The current semantics, which
2455 complies to UNIX98, was introduced with version
2456 1.15.91. @xref{Changes}, for more information.}.
2457
2458 @opsummary{compress}
2459 @opsummary{uncompress}
2460 @item --compress
2461 @itemx --uncompress
2462 @itemx -Z
2463
2464 @command{tar} will use the @command{compress} program when reading or
2465 writing the archive. This allows you to directly act on archives
2466 while saving space. @xref{gzip}.
2467
2468 @opsummary{confirmation}
2469 @item --confirmation
2470
2471 (See @option{--interactive}.) @xref{interactive}.
2472
2473 @opsummary{delay-directory-restore}
2474 @item --delay-directory-restore
2475
2476 Delay setting modification times and permissions of extracted
2477 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2478
2479 @opsummary{dereference}
2480 @item --dereference
2481 @itemx -h
2482
2483 When creating a @command{tar} archive, @command{tar} will archive the
2484 file that a symbolic link points to, rather than archiving the
2485 symlink. @xref{dereference}.
2486
2487 @opsummary{directory}
2488 @item --directory=@var{dir}
2489 @itemx -C @var{dir}
2490
2491 When this option is specified, @command{tar} will change its current directory
2492 to @var{dir} before performing any operations. When this option is used
2493 during archive creation, it is order sensitive. @xref{directory}.
2494
2495 @opsummary{exclude}
2496 @item --exclude=@var{pattern}
2497
2498 When performing operations, @command{tar} will skip files that match
2499 @var{pattern}. @xref{exclude}.
2500
2501 @opsummary{exclude-from}
2502 @item --exclude-from=@var{file}
2503 @itemx -X @var{file}
2504
2505 Similar to @option{--exclude}, except @command{tar} will use the list of
2506 patterns in the file @var{file}. @xref{exclude}.
2507
2508 @opsummary{exclude-caches}
2509 @item --exclude-caches
2510
2511 Automatically excludes all directories
2512 containing a cache directory tag. @xref{exclude}.
2513
2514 @opsummary{file}
2515 @item --file=@var{archive}
2516 @itemx -f @var{archive}
2517
2518 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2519 performs operations on, rather than @command{tar}'s compilation dependent
2520 default. @xref{file tutorial}.
2521
2522 @opsummary{files-from}
2523 @item --files-from=@var{file}
2524 @itemx -T @var{file}
2525
2526 @command{tar} will use the contents of @var{file} as a list of archive members
2527 or files to operate on, in addition to those specified on the
2528 command-line. @xref{files}.
2529
2530 @opsummary{force-local}
2531 @item --force-local
2532
2533 Forces @command{tar} to interpret the filename given to @option{--file}
2534 as a local file, even if it looks like a remote tape drive name.
2535 @xref{local and remote archives}.
2536
2537 @opsummary{format}
2538 @item --format=@var{format}
2539 @itemx -H @var{format}
2540
2541 Selects output archive format. @var{Format} may be one of the
2542 following:
2543
2544 @table @samp
2545 @item v7
2546 Creates an archive that is compatible with Unix V7 @command{tar}.
2547
2548 @item oldgnu
2549 Creates an archive that is compatible with GNU @command{tar} version
2550 1.12 or earlier.
2551
2552 @item gnu
2553 Creates archive in GNU tar 1.13 format. Basically it is the same as
2554 @samp{oldgnu} with the only difference in the way it handles long
2555 numeric fields.
2556
2557 @item ustar
2558 Creates a @acronym{POSIX.1-1988} compatible archive.
2559
2560 @item posix
2561 Creates a @acronym{POSIX.1-2001 archive}.
2562
2563 @end table
2564
2565 @xref{Formats}, for a detailed discussion of these formats.
2566
2567 @opsummary{group}
2568 @item --group=@var{group}
2569
2570 Files added to the @command{tar} archive will have a group id of @var{group},
2571 rather than the group from the source file. @var{group} is first decoded
2572 as a group symbolic name, but if this interpretation fails, it has to be
2573 a decimal numeric group ID. @xref{override}.
2574
2575 Also see the comments for the @option{--owner=@var{user}} option.
2576
2577 @opsummary{gzip}
2578 @opsummary{gunzip}
2579 @opsummary{ungzip}
2580 @item --gzip
2581 @itemx --gunzip
2582 @itemx --ungzip
2583 @itemx -z
2584
2585 This option tells @command{tar} to read or write archives through
2586 @command{gzip}, allowing @command{tar} to directly operate on several
2587 kinds of compressed archives transparently. @xref{gzip}.
2588
2589 @opsummary{help}
2590 @item --help
2591 @itemx -?
2592
2593 @command{tar} will print out a short message summarizing the operations and
2594 options to @command{tar} and exit. @xref{help}.
2595
2596 @opsummary{ignore-case}
2597 @item --ignore-case
2598 Ignore case when matching member or file names with
2599 patterns. @xref{controlling pattern-matching}.
2600
2601 @opsummary{ignore-command-error}
2602 @item --ignore-command-error
2603 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2604
2605 @opsummary{ignore-failed-read}
2606 @item --ignore-failed-read
2607
2608 Do not exit unsuccessfully merely because an unreadable file was encountered.
2609 @xref{Reading}.
2610
2611 @opsummary{ignore-zeros}
2612 @item --ignore-zeros
2613 @itemx -i
2614
2615 With this option, @command{tar} will ignore zeroed blocks in the
2616 archive, which normally signals EOF. @xref{Reading}.
2617
2618 @opsummary{incremental}
2619 @item --incremental
2620 @itemx -G
2621
2622 Used to inform @command{tar} that it is working with an old
2623 @acronym{GNU}-format incremental backup archive. It is intended
2624 primarily for backwards compatibility only. @xref{Incremental Dumps},
2625 for a detailed discussion of incremental archives.
2626
2627 @opsummary{index-file}
2628 @item --index-file=@var{file}
2629
2630 Send verbose output to @var{file} instead of to standard output.
2631
2632 @opsummary{info-script}
2633 @opsummary{new-volume-script}
2634 @item --info-script=@var{script-file}
2635 @itemx --new-volume-script=@var{script-file}
2636 @itemx -F @var{script-file}
2637
2638 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2639 at the end of each tape. If @var{script-file} exits with nonzero status,
2640 @command{tar} fails immediately. @xref{info-script}, for a detailed
2641 discussion of @var{script-file}.
2642
2643 @opsummary{interactive}
2644 @item --interactive
2645 @itemx --confirmation
2646 @itemx -w
2647
2648 Specifies that @command{tar} should ask the user for confirmation before
2649 performing potentially destructive options, such as overwriting files.
2650 @xref{interactive}.
2651
2652 @opsummary{keep-newer-files}
2653 @item --keep-newer-files
2654
2655 Do not replace existing files that are newer than their archive copies
2656 when extracting files from an archive.
2657
2658 @opsummary{keep-old-files}
2659 @item --keep-old-files
2660 @itemx -k
2661
2662 Do not overwrite existing files when extracting files from an archive.
2663 @xref{Keep Old Files}.
2664
2665 @opsummary{label}
2666 @item --label=@var{name}
2667 @itemx -V @var{name}
2668
2669 When creating an archive, instructs @command{tar} to write @var{name}
2670 as a name record in the archive. When extracting or listing archives,
2671 @command{tar} will only operate on archives that have a label matching
2672 the pattern specified in @var{name}. @xref{Tape Files}.
2673
2674 @opsummary{listed-incremental}
2675 @item --listed-incremental=@var{snapshot-file}
2676 @itemx -g @var{snapshot-file}
2677
2678 During a @option{--create} operation, specifies that the archive that
2679 @command{tar} creates is a new @acronym{GNU}-format incremental
2680 backup, using @var{snapshot-file} to determine which files to backup.
2681 With other operations, informs @command{tar} that the archive is in
2682 incremental format. @xref{Incremental Dumps}.
2683
2684 @opsummary{mode}
2685 @item --mode=@var{permissions}
2686
2687 When adding files to an archive, @command{tar} will use
2688 @var{permissions} for the archive members, rather than the permissions
2689 from the files. @var{permissions} can be specified either as an octal
2690 number or as symbolic permissions, like with
2691 @command{chmod}. @xref{override}.
2692
2693 @opsummary{mtime}
2694 @item --mtime=@var{date}
2695
2696 When adding files to an archive, @command{tar} will use @var{date} as
2697 the modification time of members when creating archives, instead of
2698 their actual modification times. The value of @var{date} can be
2699 either a textual date representation (@pxref{Date input formats}) or a
2700 name of the existing file, starting with @samp{/} or @samp{.}. In the
2701 latter case, the modification time of that file is used. @xref{override}.
2702
2703 @opsummary{multi-volume}
2704 @item --multi-volume
2705 @itemx -M
2706
2707 Informs @command{tar} that it should create or otherwise operate on a
2708 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2709
2710 @opsummary{new-volume-script}
2711 @item --new-volume-script
2712
2713 (see --info-script)
2714
2715 @opsummary{seek}
2716 @item --seek
2717 @itemx -n
2718
2719 Assume that the archive media supports seeks to arbitrary
2720 locations. Usually @command{tar} determines automatically whether
2721 the archive can be seeked or not. This option is intended for use
2722 in cases when such recognition fails.
2723
2724 @opsummary{newer}
2725 @item --newer=@var{date}
2726 @itemx --after-date=@var{date}
2727 @itemx -N
2728
2729 When creating an archive, @command{tar} will only add files that have changed
2730 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2731 is taken to be the name of a file whose data modification time specifies
2732 the date. @xref{after}.
2733
2734 @opsummary{newer-mtime}
2735 @item --newer-mtime=@var{date}
2736
2737 Like @option{--newer}, but add only files whose
2738 contents have changed (as opposed to just @option{--newer}, which will
2739 also back up files for which any status information has
2740 changed). @xref{after}.
2741
2742 @opsummary{no-anchored}
2743 @item --no-anchored
2744 An exclude pattern can match any subsequence of the name's components.
2745 @xref{controlling pattern-matching}.
2746
2747 @opsummary{no-delay-directory-restore}
2748 @item --no-delay-directory-restore
2749
2750 Setting modification times and permissions of extracted
2751 directories when all files from this directory has been
2752 extracted. This is the default. @xref{Directory Modification Times and Permissions}.
2753
2754 @opsummary{no-ignore-case}
2755 @item --no-ignore-case
2756 Use case-sensitive matching.
2757 @xref{controlling pattern-matching}.
2758
2759 @opsummary{no-ignore-command-error}
2760 @item --no-ignore-command-error
2761 Print warnings about subprocesses terminated with a non-zero exit
2762 code. @xref{Writing to an External Program}.
2763
2764 @opsummary{no-overwrite-dir}
2765 @item --no-overwrite-dir
2766
2767 Preserve metadata of existing directories when extracting files
2768 from an archive. @xref{Overwrite Old Files}.
2769
2770 @opsummary{no-quote-chars}
2771 @item --no-quote-chars=@var{string}
2772 Remove characters listed in @var{string} from the list of quoted
2773 characters set by the previous @option{--quote-chars} option
2774 (@pxref{quoting styles}).
2775
2776 @opsummary{no-recursion}
2777 @item --no-recursion
2778
2779 With this option, @command{tar} will not recurse into directories.
2780 @xref{recurse}.
2781
2782 @opsummary{no-same-owner}
2783 @item --no-same-owner
2784 @itemx -o
2785
2786 When extracting an archive, do not attempt to preserve the owner
2787 specified in the @command{tar} archive. This the default behavior
2788 for ordinary users.
2789
2790 @opsummary{no-same-permissions}
2791 @item --no-same-permissions
2792
2793 When extracting an archive, subtract the user's umask from files from
2794 the permissions specified in the archive. This is the default behavior
2795 for ordinary users.
2796
2797 @opsummary{no-unquote}
2798 @item --no-unquote
2799 Treat all input file or member names literally, do not interpret
2800 escape sequences. @xref{input name quoting}.
2801
2802 @opsummary{no-wildcards}
2803 @item --no-wildcards
2804 Do not use wildcards.
2805 @xref{controlling pattern-matching}.
2806
2807 @opsummary{no-wildcards-match-slash}
2808 @item --no-wildcards-match-slash
2809 Wildcards do not match @samp{/}.
2810 @xref{controlling pattern-matching}.
2811
2812 @opsummary{null}
2813 @item --null
2814
2815 When @command{tar} is using the @option{--files-from} option, this option
2816 instructs @command{tar} to expect filenames terminated with @option{NUL}, so
2817 @command{tar} can correctly work with file names that contain newlines.
2818 @xref{nul}.
2819
2820 @opsummary{numeric-owner}
2821 @item --numeric-owner
2822
2823 This option will notify @command{tar} that it should use numeric user
2824 and group IDs when creating a @command{tar} file, rather than names.
2825 @xref{Attributes}.
2826
2827 @item -o
2828 The function of this option depends on the action @command{tar} is
2829 performing. When extracting files, @option{-o} is a synonym for
2830 @option{--no-same-owner}, i.e., it prevents @command{tar} from
2831 restoring ownership of files being extracted.
2832
2833 When creating an archive, it is a synonym for
2834 @option{--old-archive}. This behavior is for compatibility
2835 with previous versions of @GNUTAR{}, and will be
2836 removed in the future releases.
2837
2838 @xref{Changes}, for more information.
2839
2840 @opsummary{occurrence}
2841 @item --occurrence[=@var{number}]
2842
2843 This option can be used in conjunction with one of the subcommands
2844 @option{--delete}, @option{--diff}, @option{--extract} or
2845 @option{--list} when a list of files is given either on the command
2846 line or via @option{-T} option.
2847
2848 This option instructs @command{tar} to process only the @var{number}th
2849 occurrence of each named file. @var{Number} defaults to 1, so
2850
2851 @smallexample
2852 tar -x -f archive.tar --occurrence filename
2853 @end smallexample
2854
2855 @noindent
2856 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
2857 and will terminate without scanning to the end of the archive.
2858
2859 @opsummary{old-archive}
2860 @item --old-archive
2861 Synonym for @option{--format=v7}.
2862
2863 @opsummary{one-file-system}
2864 @item --one-file-system
2865 Used when creating an archive. Prevents @command{tar} from recursing into
2866 directories that are on different file systems from the current
2867 directory @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2868 synonym for @option{--one-file-system}. This has changed in version
2869 1.15.91. @xref{Changes}, for more information.}.
2870
2871 @opsummary{overwrite}
2872 @item --overwrite
2873
2874 Overwrite existing files and directory metadata when extracting files
2875 from an archive. @xref{Overwrite Old Files}.
2876
2877 @opsummary{overwrite-dir}
2878 @item --overwrite-dir
2879
2880 Overwrite the metadata of existing directories when extracting files
2881 from an archive. @xref{Overwrite Old Files}.
2882
2883 @opsummary{owner}
2884 @item --owner=@var{user}
2885
2886 Specifies that @command{tar} should use @var{user} as the owner of members
2887 when creating archives, instead of the user associated with the source
2888 file. @var{user} is first decoded as a user symbolic name, but if
2889 this interpretation fails, it has to be a decimal numeric user ID.
2890 @xref{override}.
2891
2892 This option does not affect extraction from archives.
2893
2894 @opsummary{transform}
2895 @item --transform=@var{sed-expr}
2896
2897 Transform file or member names using @command{sed} replacement expression
2898 @var{sed-expr}. For example,
2899
2900 @smallexample
2901 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
2902 @end smallexample
2903
2904 @noindent
2905 will add to @file{archive} files from the current working directory,
2906 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
2907 discussion, @xref{transform}.
2908
2909 To see transformed member names in verbose listings, use
2910 @option{--show-transformed-names} option
2911 (@pxref{show-transformed-names}).
2912
2913 @opsummary{quote-chars}
2914 @item --quote-chars=@var{string}
2915 Always quote characters from @var{string}, even if the selected
2916 quoting style would not quote them (@pxref{quoting styles}).
2917
2918 @opsummary{quoting-style}
2919 @item --quoting-style=@var{style}
2920 Set quoting style to use when printing member and file names
2921 (@pxref{quoting styles}). Valid @var{style} values are:
2922 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
2923 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
2924 style is @code{escape}, unless overridden while configuring the
2925 package.
2926
2927 @opsummary{pax-option}
2928 @item --pax-option=@var{keyword-list}
2929 This option is meaningful only with @acronym{POSIX.1-2001} archives
2930 (@pxref{posix}). It modifies the way @command{tar} handles the
2931 extended header keywords. @var{Keyword-list} is a comma-separated
2932 list of keyword options. @xref{PAX keywords}, for a detailed
2933 discussion.
2934
2935 @opsummary{portability}
2936 @item --portability
2937 @itemx --old-archive
2938 Synonym for @option{--format=v7}.
2939
2940 @opsummary{posix}
2941 @item --posix
2942 Same as @option{--format=posix}.
2943
2944 @opsummary{preserve}
2945 @item --preserve
2946
2947 Synonymous with specifying both @option{--preserve-permissions} and
2948 @option{--same-order}. @xref{Setting Access Permissions}.
2949
2950 @opsummary{preserve-order}
2951 @item --preserve-order
2952
2953 (See @option{--same-order}; @pxref{Reading}.)
2954
2955 @opsummary{preserve-permissions}
2956 @opsummary{same-permissions}
2957 @item --preserve-permissions
2958 @itemx --same-permissions
2959 @itemx -p
2960
2961 When @command{tar} is extracting an archive, it normally subtracts the
2962 users' umask from the permissions specified in the archive and uses
2963 that number as the permissions to create the destination file.
2964 Specifying this option instructs @command{tar} that it should use the
2965 permissions directly from the archive. @xref{Setting Access Permissions}.
2966
2967 @opsummary{read-full-records}
2968 @item --read-full-records
2969 @itemx -B
2970
2971 Specifies that @command{tar} should reblock its input, for reading
2972 from pipes on systems with buggy implementations. @xref{Reading}.
2973
2974 @opsummary{record-size}
2975 @item --record-size=@var{size}
2976
2977 Instructs @command{tar} to use @var{size} bytes per record when accessing the
2978 archive. @xref{Blocking Factor}.
2979
2980 @opsummary{recursion}
2981 @item --recursion
2982
2983 With this option, @command{tar} recurses into directories.
2984 @xref{recurse}.
2985
2986 @opsummary{recursive-unlink}
2987 @item --recursive-unlink
2988
2989 Remove existing
2990 directory hierarchies before extracting directories of the same name
2991 from the archive. @xref{Recursive Unlink}.
2992
2993 @opsummary{remove-files}
2994 @item --remove-files
2995
2996 Directs @command{tar} to remove the source file from the file system after
2997 appending it to an archive. @xref{remove files}.
2998
2999 @opsummary{restrict}
3000 @item --restrict
3001
3002 Disable use of some potentially harmful @command{tar} options.
3003 Currently this option disables shell invocation from multi-volume menu
3004 (@pxref{Using Multiple Tapes}).
3005
3006 @opsummary{rmt-command}
3007 @item --rmt-command=@var{cmd}
3008
3009 Notifies @command{tar} that it should use @var{cmd} instead of
3010 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3011
3012 @opsummary{rsh-command}
3013 @item --rsh-command=@var{cmd}
3014
3015 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3016 devices. @xref{Device}.
3017
3018 @opsummary{same-order}
3019 @item --same-order
3020 @itemx --preserve-order
3021 @itemx -s
3022
3023 This option is an optimization for @command{tar} when running on machines with
3024 small amounts of memory. It informs @command{tar} that the list of file
3025 arguments has already been sorted to match the order of files in the
3026 archive. @xref{Reading}.
3027
3028 @opsummary{same-owner}
3029 @item --same-owner
3030
3031 When extracting an archive, @command{tar} will attempt to preserve the owner
3032 specified in the @command{tar} archive with this option present.
3033 This is the default behavior for the superuser; this option has an
3034 effect only for ordinary users. @xref{Attributes}.
3035
3036 @opsummary{same-permissions}
3037 @item --same-permissions
3038
3039 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3040
3041 @opsummary{show-defaults}
3042 @item --show-defaults
3043
3044 Displays the default options used by @command{tar} and exits
3045 successfully. This option is intended for use in shell scripts.
3046 Here is an example of what you can see using this option:
3047
3048 @smallexample
3049 $ tar --show-defaults
3050 --format=gnu -f- -b20 --quoting-style=escape \
3051 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3052 @end smallexample
3053
3054 @opsummary{show-omitted-dirs}
3055 @item --show-omitted-dirs
3056
3057 Instructs @command{tar} to mention directories its skipping over when
3058 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3059
3060 @opsummary{show-transformed-names}
3061 @opsummary{show-stored-names}
3062 @item --show-transformed-names
3063 @itemx --show-stored-names
3064
3065 Display file or member names after applying any transformations
3066 (@pxref{transform}). In particular, when used in conjunction with one of
3067 archive creation operations it instructs tar to list the member names
3068 stored in the archive, as opposed to the actual file
3069 names. @xref{listing member and file names}.
3070
3071 @opsummary{sparse}
3072 @item --sparse
3073 @itemx -S
3074
3075 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3076 sparse files efficiently. @xref{sparse}.
3077
3078 @opsummary{sparse-version}
3079 @item --sparse-version=@var{version}
3080
3081 Specified the @dfn{format version} to use when archiving sparse
3082 files. Implies @option{--sparse}. @xref{sparse}. For the description
3083 of the supported sparse formats, @xref{Sparse Formats}.
3084
3085 @opsummary{starting-file}
3086 @item --starting-file=@var{name}
3087 @itemx -K @var{name}
3088
3089 This option affects extraction only; @command{tar} will skip extracting
3090 files in the archive until it finds one that matches @var{name}.
3091 @xref{Scarce}.
3092
3093 @opsummary{strip-components}
3094 @item --strip-components=@var{number}
3095 Strip given @var{number} of leading components from file names before
3096 extraction.@footnote{This option was called @option{--strip-path} in
3097 version 1.14.} For example, if archive @file{archive.tar} contained
3098 @file{/some/file/name}, then running
3099
3100 @smallexample
3101 tar --extract --file archive.tar --strip-components=2
3102 @end smallexample
3103
3104 @noindent
3105 would extract this file to file @file{name}.
3106
3107 @opsummary{suffix}, summary
3108 @item --suffix=@var{suffix}
3109
3110 Alters the suffix @command{tar} uses when backing up files from the default
3111 @samp{~}. @xref{backup}.
3112
3113 @opsummary{tape-length}
3114 @item --tape-length=@var{num}
3115 @itemx -L @var{num}
3116
3117 Specifies the length of tapes that @command{tar} is writing as being
3118 @w{@var{num} x 1024} bytes long. @xref{Using Multiple Tapes}.
3119
3120 @opsummary{test-label}
3121 @item --test-label
3122
3123 Reads the volume label. If an argument is specified, test whether it
3124 matches the volume label. @xref{--test-label option}.
3125
3126 @opsummary{to-command}
3127 @item --to-command=@var{command}
3128
3129 During extraction @command{tar} will pipe extracted files to the
3130 standard input of @var{command}. @xref{Writing to an External Program}.
3131
3132 @opsummary{to-stdout}
3133 @item --to-stdout
3134 @itemx -O
3135
3136 During extraction, @command{tar} will extract files to stdout rather
3137 than to the file system. @xref{Writing to Standard Output}.
3138
3139 @opsummary{totals}
3140 @item --totals[=@var{signo}]
3141
3142 Displays the total number of bytes transferred when processing an
3143 archive. If an argument is given, these data are displayed on
3144 request, when signal @var{signo} is delivered to @command{tar}.
3145 @xref{totals}.
3146
3147 @opsummary{touch}
3148 @item --touch
3149 @itemx -m
3150
3151 Sets the data modification time of extracted files to the extraction time,
3152 rather than the data modification time stored in the archive.
3153 @xref{Data Modification Times}.
3154
3155 @opsummary{uncompress}
3156 @item --uncompress
3157
3158 (See @option{--compress}. @pxref{gzip})
3159
3160 @opsummary{ungzip}
3161 @item --ungzip
3162
3163 (See @option{--gzip}. @pxref{gzip})
3164
3165 @opsummary{unlink-first}
3166 @item --unlink-first
3167 @itemx -U
3168
3169 Directs @command{tar} to remove the corresponding file from the file
3170 system before extracting it from the archive. @xref{Unlink First}.
3171
3172 @opsummary{unquote}
3173 @item --unquote
3174 Enable unquoting input file or member names (default). @xref{input
3175 name quoting}.
3176
3177 @opsummary{use-compress-program}
3178 @item --use-compress-program=@var{prog}
3179
3180 Instructs @command{tar} to access the archive through @var{prog}, which is
3181 presumed to be a compression program of some sort. @xref{gzip}.
3182
3183 @opsummary{utc}
3184 @item --utc
3185
3186 Display file modification dates in @acronym{UTC}. This option implies
3187 @option{--verbose}.
3188
3189 @opsummary{verbose}
3190 @item --verbose
3191 @itemx -v
3192
3193 Specifies that @command{tar} should be more verbose about the operations its
3194 performing. This option can be specified multiple times for some
3195 operations to increase the amount of information displayed.
3196 @xref{verbose}.
3197
3198 @opsummary{verify}
3199 @item --verify
3200 @itemx -W
3201
3202 Verifies that the archive was correctly written when creating an
3203 archive. @xref{verify}.
3204
3205 @opsummary{version}
3206 @item --version
3207
3208 Print information about the program's name, version, origin and legal
3209 status, all on standard output, and then exit successfully.
3210 @xref{help}.
3211
3212 @opsummary{volno-file}
3213 @item --volno-file=@var{file}
3214
3215 Used in conjunction with @option{--multi-volume}. @command{tar} will
3216 keep track of which volume of a multi-volume archive its working in
3217 @var{file}. @xref{volno-file}.
3218
3219 @opsummary{wildcards}
3220 @item --wildcards
3221 Use wildcards when matching member names with patterns.
3222 @xref{controlling pattern-matching}.
3223
3224 @opsummary{wildcards-match-slash}
3225 @item --wildcards-match-slash
3226 Wildcards match @samp{/}.
3227 @xref{controlling pattern-matching}.
3228 @end table
3229
3230 @node Short Option Summary
3231 @subsection Short Options Cross Reference
3232
3233 Here is an alphabetized list of all of the short option forms, matching
3234 them with the equivalent long option.
3235
3236 @multitable @columnfractions 0.20 0.80
3237 @headitem Short Option @tab Reference
3238
3239 @item -A @tab @ref{--concatenate}.
3240
3241 @item -B @tab @ref{--read-full-records}.
3242
3243 @item -C @tab @ref{--directory}.
3244
3245 @item -F @tab @ref{--info-script}.
3246
3247 @item -G @tab @ref{--incremental}.
3248
3249 @item -K @tab @ref{--starting-file}.
3250
3251 @item -L @tab @ref{--tape-length}.
3252
3253 @item -M @tab @ref{--multi-volume}.
3254
3255 @item -N @tab @ref{--newer}.
3256
3257 @item -O @tab @ref{--to-stdout}.
3258
3259 @item -P @tab @ref{--absolute-names}.
3260
3261 @item -R @tab @ref{--block-number}.
3262
3263 @item -S @tab @ref{--sparse}.
3264
3265 @item -T @tab @ref{--files-from}.
3266
3267 @item -U @tab @ref{--unlink-first}.
3268
3269 @item -V @tab @ref{--label}.
3270
3271 @item -W @tab @ref{--verify}.
3272
3273 @item -X @tab @ref{--exclude-from}.
3274
3275 @item -Z @tab @ref{--compress}.
3276
3277 @item -b @tab @ref{--blocking-factor}.
3278
3279 @item -c @tab @ref{--create}.
3280
3281 @item -d @tab @ref{--compare}.
3282
3283 @item -f @tab @ref{--file}.
3284
3285 @item -g @tab @ref{--listed-incremental}.
3286
3287 @item -h @tab @ref{--dereference}.
3288
3289 @item -i @tab @ref{--ignore-zeros}.
3290
3291 @item -j @tab @ref{--bzip2}.
3292
3293 @item -k @tab @ref{--keep-old-files}.
3294
3295 @item -l @tab @ref{--check-links}.
3296
3297 @item -m @tab @ref{--touch}.
3298
3299 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3300 @ref{--portability}.
3301
3302 The later usage is deprecated. It is retained for compatibility with
3303 the earlier versions of @GNUTAR{}. In the future releases
3304 @option{-o} will be equivalent to @option{--no-same-owner} only.
3305
3306 @item -p @tab @ref{--preserve-permissions}.
3307
3308 @item -r @tab @ref{--append}.
3309
3310 @item -s @tab @ref{--same-order}.
3311
3312 @item -t @tab @ref{--list}.
3313
3314 @item -u @tab @ref{--update}.
3315
3316 @item -v @tab @ref{--verbose}.
3317
3318 @item -w @tab @ref{--interactive}.
3319
3320 @item -x @tab @ref{--extract}.
3321
3322 @item -z @tab @ref{--gzip}.
3323
3324 @end multitable
3325
3326 @node help
3327 @section @GNUTAR{} documentation
3328
3329 @cindex Getting program version number
3330 @opindex version
3331 @cindex Version of the @command{tar} program
3332 Being careful, the first thing is really checking that you are using
3333 @GNUTAR{}, indeed. The @option{--version} option
3334 causes @command{tar} to print information about its name, version,
3335 origin and legal status, all on standard output, and then exit
3336 successfully. For example, @w{@samp{tar --version}} might print:
3337
3338 @smallexample
3339 tar (GNU tar) @value{VERSION}
3340 Copyright (C) 2006 Free Software Foundation, Inc.
3341 This is free software. You may redistribute copies of it under the terms
3342 of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
3343 There is NO WARRANTY, to the extent permitted by law.
3344
3345 Written by John Gilmore and Jay Fenlason.
3346 @end smallexample
3347
3348 @noindent
3349 The first occurrence of @samp{tar} in the result above is the program
3350 name in the package (for example, @command{rmt} is another program),
3351 while the second occurrence of @samp{tar} is the name of the package
3352 itself, containing possibly many programs. The package is currently
3353 named @samp{tar}, after the name of the main program it
3354 contains@footnote{There are plans to merge the @command{cpio} and
3355 @command{tar} packages into a single one which would be called
3356 @code{paxutils}. So, who knows if, one of this days, the
3357 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3358 paxutils) 3.2}}}.
3359
3360 @cindex Obtaining help
3361 @cindex Listing all @command{tar} options
3362 @xopindex{help, introduction}
3363 Another thing you might want to do is checking the spelling or meaning
3364 of some particular @command{tar} option, without resorting to this
3365 manual, for once you have carefully read it. @GNUTAR{}
3366 has a short help feature, triggerable through the
3367 @option{--help} option. By using this option, @command{tar} will
3368 print a usage message listing all available options on standard
3369 output, then exit successfully, without doing anything else and
3370 ignoring all other options. Even if this is only a brief summary, it
3371 may be several screens long. So, if you are not using some kind of
3372 scrollable window, you might prefer to use something like:
3373
3374 @smallexample
3375 $ @kbd{tar --help | less}
3376 @end smallexample
3377
3378 @noindent
3379 presuming, here, that you like using @command{less} for a pager. Other
3380 popular pagers are @command{more} and @command{pg}. If you know about some
3381 @var{keyword} which interests you and do not want to read all the
3382 @option{--help} output, another common idiom is doing:
3383
3384 @smallexample
3385 tar --help | grep @var{keyword}
3386 @end smallexample
3387
3388 @noindent
3389 for getting only the pertinent lines. Notice, however, that some
3390 @command{tar} options have long description lines and the above
3391 command will list only the first of them.
3392
3393 The exact look of the option summary displayed by @kbd{tar --help} is
3394 configurable. @xref{Configuring Help Summary}, for a detailed description.
3395
3396 @opindex usage
3397 If you only wish to check the spelling of an option, running @kbd{tar
3398 --usage} may be a better choice. This will display a terse list of
3399 @command{tar} option without accompanying explanations.
3400
3401 The short help output is quite succinct, and you might have to get
3402 back to the full documentation for precise points. If you are reading
3403 this paragraph, you already have the @command{tar} manual in some
3404 form. This manual is available in a variety of forms from
3405 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3406 distribution, provided you have @TeX{} already installed somewhere,
3407 and a laser printer around. Just configure the distribution, execute
3408 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3409 usual way (contact your local guru to know how). If @GNUTAR{}
3410 has been conveniently installed at your place, this
3411 manual is also available in interactive, hypertextual form as an Info
3412 file. Just call @w{@samp{info tar}} or, if you do not have the
3413 @command{info} program handy, use the Info reader provided within
3414 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3415
3416 There is currently no @code{man} page for @GNUTAR{}.
3417 If you observe such a @code{man} page on the system you are running,
3418 either it does not belong to @GNUTAR{}, or it has not
3419 been produced by @acronym{GNU}. Some package maintainers convert
3420 @kbd{tar --help} output to a man page, using @command{help2man}. In
3421 any case, please bear in mind that the authoritative source of
3422 information about @GNUTAR{} is this Texinfo documentation.
3423
3424 @node defaults
3425 @section Obtaining @GNUTAR{} default values
3426
3427 @opindex show-defaults
3428 @GNUTAR{} has some predefined defaults that are used when you do not
3429 explicitly specify another values. To obtain a list of such
3430 defaults, use @option{--show-defaults} option. This will output the
3431 values in the form of @command{tar} command line options:
3432
3433 @smallexample
3434 @group
3435 @kbd{tar --show-defaults}
3436 --format=gnu -f- -b20 --quoting-style=escape
3437 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3438 @end group
3439 @end smallexample
3440
3441 @noindent
3442 Notice, that this option outputs only one line. The example output above
3443 has been split to fit page boundaries.
3444
3445 @noindent
3446 The above output shows that this version of @GNUTAR{} defaults to
3447 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3448 output as the archive, if no @option{--file} option has been given
3449 (@pxref{file tutorial}), the default blocking factor is 20
3450 (@pxref{Blocking Factor}). It also shows the default locations where
3451 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3452
3453 @node verbose
3454 @section Checking @command{tar} progress
3455
3456 Typically, @command{tar} performs most operations without reporting any
3457 information to the user except error messages. When using @command{tar}
3458 with many options, particularly ones with complicated or
3459 difficult-to-predict behavior, it is possible to make serious mistakes.
3460 @command{tar} provides several options that make observing @command{tar}
3461 easier. These options cause @command{tar} to print information as it
3462 progresses in its job, and you might want to use them just for being
3463 more careful about what is going on, or merely for entertaining
3464 yourself. If you have encountered a problem when operating on an
3465 archive, however, you may need more information than just an error
3466 message in order to solve the problem. The following options can be
3467 helpful diagnostic tools.
3468
3469 @cindex Verbose operation
3470 @opindex verbose
3471 Normally, the @option{--list} (@option{-t}) command to list an archive
3472 prints just the file names (one per line) and the other commands are
3473 silent. When used with most operations, the @option{--verbose}
3474 (@option{-v}) option causes @command{tar} to print the name of each
3475 file or archive member as it is processed. This and the other options
3476 which make @command{tar} print status information can be useful in
3477 monitoring @command{tar}.
3478
3479 With @option{--create} or @option{--extract}, @option{--verbose} used
3480 once just prints the names of the files or members as they are processed.
3481 Using it twice causes @command{tar} to print a longer listing
3482 (@xref{verbose member listing}, for the description) for each member.
3483 Since @option{--list} already prints the names of the members,
3484 @option{--verbose} used once with @option{--list} causes @command{tar}
3485 to print an @samp{ls -l} type listing of the files in the archive.
3486 The following examples both extract members with long list output:
3487
3488 @smallexample
3489 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3490 $ @kbd{tar xvvf archive.tar}
3491 @end smallexample
3492
3493 Verbose output appears on the standard output except when an archive is
3494 being written to the standard output, as with @samp{tar --create
3495 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3496 installer let standard output be the default archive). In that case
3497 @command{tar} writes verbose output to the standard error stream.
3498
3499 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3500 verbose output to @var{file} rather than to standard output or standard
3501 error.
3502
3503 @anchor{totals}
3504 @cindex Obtaining total status information
3505 @opindex totals
3506 The @option{--totals} option causes @command{tar} to print on the
3507 standard error the total amount of bytes transferred when processing
3508 an archive. When creating or appending to an archive, this option
3509 prints the number of bytes written to the archive and the average
3510 speed at which they have been written, e.g.:
3511
3512 @smallexample
3513 @group
3514 $ @kbd{tar -c -f archive.tar --totals /home}
3515 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3516 @end group
3517 @end smallexample
3518
3519 When reading an archive, this option displays the number of bytes
3520 read:
3521
3522 @smallexample
3523 @group
3524 $ @kbd{tar -x -f archive.tar --totals}
3525 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3526 @end group
3527 @end smallexample
3528
3529 Finally, when deleting from an archive, the @option{--totals} option
3530 displays both numbers plus number of bytes removed from the archive:
3531
3532 @smallexample
3533 @group
3534 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3535 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3536 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3537 Total bytes deleted: 1474048
3538 @end group
3539 @end smallexample
3540
3541 You can also obtain this information on request. When
3542 @option{--totals} is used with an argument, this argument is
3543 interpreted as a symbolic name of a signal, upon delivery of which the
3544 statistics is to be printed:
3545
3546 @table @option
3547 @item --totals=@var{signo}
3548 Print statistics upon delivery of signal @var{signo}. Valid arguments
3549 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3550 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3551 accepted.
3552 @end table
3553
3554 Both forms of @option{--totals} option can be used simultaneously.
3555 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3556 extract all members from its default archive and print statistics
3557 after finishing the extraction, as well as when receiving signal
3558 @code{SIGUSR1}.
3559
3560 @anchor{Progress information}
3561 @cindex Progress information
3562 @opindex checkpoint
3563 The @option{--checkpoint} option prints an occasional message
3564 as @command{tar} reads or writes the archive. It is designed for
3565 those who don't need the more detailed (and voluminous) output of
3566 @option{--block-number} (@option{-R}), but do want visual confirmation
3567 that @command{tar} is actually making forward progress. By default it
3568 prints a message each 10 records read or written. This can be changed
3569 by giving it a numeric argument after an equal sign:
3570
3571 @smallexample
3572 $ @kbd{tar -c --checkpoint=1000} /var
3573 tar: Write checkpoint 1000
3574 tar: Write checkpoint 2000
3575 tar: Write checkpoint 3000
3576 @end smallexample
3577
3578 This example shows the default checkpoint message used by
3579 @command{tar}. If you place a dot immediately after the equal
3580 sign, it will print a @samp{.} at each checkpoint. For example:
3581
3582 @smallexample
3583 $ @kbd{tar -c --checkpoint=.1000} /var
3584 ...
3585 @end smallexample
3586
3587 @opindex show-omitted-dirs
3588 @anchor{show-omitted-dirs}
3589 The @option{--show-omitted-dirs} option, when reading an archive---with
3590 @option{--list} or @option{--extract}, for example---causes a message
3591 to be printed for each directory in the archive which is skipped.
3592 This happens regardless of the reason for skipping: the directory might
3593 not have been named on the command line (implicitly or explicitly),
3594 it might be excluded by the use of the
3595 @option{--exclude=@var{pattern}} option, or some other reason.
3596
3597 @opindex block-number
3598 @cindex Block number where error occurred
3599 @anchor{block-number}
3600 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3601 every message it would normally produce, the block number within the
3602 archive where the message was triggered. Also, supplementary messages
3603 are triggered when reading blocks full of NULs, or when hitting end of
3604 file on the archive. As of now, if the archive if properly terminated
3605 with a NUL block, the reading of the file may stop before end of file
3606 is met, so the position of end of file will not usually show when
3607 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3608 drains the archive before exiting when reading the
3609 archive from a pipe.
3610
3611 @cindex Error message, block number of
3612 This option is especially useful when reading damaged archives, since
3613 it helps pinpoint the damaged sections. It can also be used with
3614 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3615 choose among several backup tapes when retrieving a file later, in
3616 favor of the tape where the file appears earliest (closest to the
3617 front of the tape). @xref{backup}.
3618
3619 @node interactive
3620 @section Asking for Confirmation During Operations
3621 @cindex Interactive operation
3622
3623 Typically, @command{tar} carries out a command without stopping for
3624 further instructions. In some situations however, you may want to
3625 exclude some files and archive members from the operation (for instance
3626 if disk or storage space is tight). You can do this by excluding
3627 certain files automatically (@pxref{Choosing}), or by performing
3628 an operation interactively, using the @option{--interactive} (@option{-w}) option.
3629 @command{tar} also accepts @option{--confirmation} for this option.
3630
3631 @opindex interactive
3632 When the @option{--interactive} (@option{-w}) option is specified, before
3633 reading, writing, or deleting files, @command{tar} first prints a message
3634 for each such file, telling what operation it intends to take, then asks
3635 for confirmation on the terminal. The actions which require
3636 confirmation include adding a file to the archive, extracting a file
3637 from the archive, deleting a file from the archive, and deleting a file
3638 from disk. To confirm the action, you must type a line of input
3639 beginning with @samp{y}. If your input line begins with anything other
3640 than @samp{y}, @command{tar} skips that file.
3641
3642 If @command{tar} is reading the archive from the standard input,
3643 @command{tar} opens the file @file{/dev/tty} to support the interactive
3644 communications.
3645
3646 Verbose output is normally sent to standard output, separate from
3647 other error messages. However, if the archive is produced directly
3648 on standard output, then verbose output is mixed with errors on
3649 @code{stderr}. Producing the archive on standard output may be used
3650 as a way to avoid using disk space, when the archive is soon to be
3651 consumed by another process reading it, say. Some people felt the need
3652 of producing an archive on stdout, still willing to segregate between
3653 verbose output and error output. A possible approach would be using a
3654 named pipe to receive the archive, and having the consumer process to
3655 read from that named pipe. This has the advantage of letting standard
3656 output free to receive verbose output, all separate from errors.
3657
3658 @node operations
3659 @chapter @GNUTAR{} Operations
3660
3661 @menu
3662 * Basic tar::
3663 * Advanced tar::
3664 * create options::
3665 * extract options::
3666 * backup::
3667 * Applications::
3668 * looking ahead::
3669 @end menu
3670
3671 @node Basic tar
3672 @section Basic @GNUTAR{} Operations
3673
3674 The basic @command{tar} operations, @option{--create} (@option{-c}),
3675 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
3676 @option{-x}), are currently presented and described in the tutorial
3677 chapter of this manual. This section provides some complementary notes
3678 for these operations.
3679
3680 @table @option
3681 @xopindex{create, complementary notes}
3682 @item --create
3683 @itemx -c
3684
3685 Creating an empty archive would have some kind of elegance. One can
3686 initialize an empty archive and later use @option{--append}
3687 (@option{-r}) for adding all members. Some applications would not
3688 welcome making an exception in the way of adding the first archive
3689 member. On the other hand, many people reported that it is
3690 dangerously too easy for @command{tar} to destroy a magnetic tape with
3691 an empty archive@footnote{This is well described in @cite{Unix-haters
3692 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
3693 Books, ISBN 1-56884-203-1.}. The two most common errors are:
3694
3695 @enumerate
3696 @item
3697 Mistakingly using @code{create} instead of @code{extract}, when the
3698 intent was to extract the full contents of an archive. This error
3699 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
3700 the QWERTY keyboard. Instead of being unpacked, the archive then
3701 gets wholly destroyed. When users speak about @dfn{exploding} an
3702 archive, they usually mean something else :-).
3703
3704 @item
3705 Forgetting the argument to @code{file}, when the intent was to create
3706 an archive with a single file in it. This error is likely because a
3707 tired user can easily add the @kbd{f} key to the cluster of option
3708 letters, by the mere force of habit, without realizing the full
3709 consequence of doing so. The usual consequence is that the single
3710 file, which was meant to be saved, is rather destroyed.
3711 @end enumerate
3712
3713 So, recognizing the likelihood and the catastrophic nature of these
3714 errors, @GNUTAR{} now takes some distance from elegance, and
3715 cowardly refuses to create an archive when @option{--create} option is
3716 given, there are no arguments besides options, and
3717 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
3718 around the cautiousness of @GNUTAR{} and nevertheless create an
3719 archive with nothing in it, one may still use, as the value for the
3720 @option{--files-from} option, a file with no names in it, as shown in
3721 the following commands:
3722
3723 @smallexample
3724 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
3725 @kbd{tar cfT empty-archive.tar /dev/null}
3726 @end smallexample
3727
3728 @xopindex{extract, complementary notes}
3729 @item --extract
3730 @itemx --get
3731 @itemx -x
3732
3733 A socket is stored, within a @GNUTAR{} archive, as a pipe.
3734
3735 @item @option{--list} (@option{-t})
3736
3737 @GNUTAR{} now shows dates as @samp{1996-08-30},
3738 while it used to show them as @samp{Aug 30 1996}. Preferably,
3739 people should get used to ISO 8601 dates. Local American dates should
3740 be made available again with full date localization support, once
3741 ready. In the meantime, programs not being localizable for dates
3742 should prefer international dates, that's really the way to go.
3743
3744 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
3745 are curious, it contains a detailed explanation of the ISO 8601 standard.
3746
3747 @end table
3748
3749 @node Advanced tar
3750 @section Advanced @GNUTAR{} Operations
3751
3752 Now that you have learned the basics of using @GNUTAR{}, you may want
3753 to learn about further ways in which @command{tar} can help you.
3754
3755 This chapter presents five, more advanced operations which you probably
3756 won't use on a daily basis, but which serve more specialized functions.
3757 We also explain the different styles of options and why you might want
3758 to use one or another, or a combination of them in your @command{tar}
3759 commands. Additionally, this chapter includes options which allow you to
3760 define the output from @command{tar} more carefully, and provide help and
3761 error correction in special circumstances.
3762
3763 @FIXME{check this after the chapter is actually revised to make sure
3764 it still introduces the info in the chapter correctly : ).}
3765
3766 @menu
3767 * Operations::
3768 * append::
3769 * update::
3770 * concatenate::
3771 * delete::
3772 * compare::
3773 @end menu
3774
3775 @node Operations
3776 @subsection The Five Advanced @command{tar} Operations
3777 @UNREVISED
3778
3779 In the last chapter, you learned about the first three operations to
3780 @command{tar}. This chapter presents the remaining five operations to
3781 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
3782 @option{--delete}, and @option{--compare}.
3783
3784 You are not likely to use these operations as frequently as those
3785 covered in the last chapter; however, since they perform specialized
3786 functions, they are quite useful when you do need to use them. We
3787 will give examples using the same directory and files that you created
3788 in the last chapter. As you may recall, the directory is called
3789 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
3790 @samp{rock}, and the two archive files you created are
3791 @samp{collection.tar} and @samp{music.tar}.
3792
3793 We will also use the archive files @samp{afiles.tar} and
3794 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
3795 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
3796 @samp{./birds}, @samp{baboon}, and @samp{./box}.
3797
3798 Unless we state otherwise, all practicing you do and examples you follow
3799 in this chapter will take place in the @file{practice} directory that
3800 you created in the previous chapter; see @ref{prepare for examples}.
3801 (Below in this section, we will remind you of the state of the examples
3802 where the last chapter left them.)
3803
3804 The five operations that we will cover in this chapter are:
3805
3806 @table @option
3807 @item --append
3808 @itemx -r
3809 Add new entries to an archive that already exists.
3810 @item --update
3811 @itemx -r
3812 Add more recent copies of archive members to the end of an archive, if
3813 they exist.
3814 @item --concatenate
3815 @itemx --catenate
3816 @itemx -A
3817 Add one or more pre-existing archives to the end of another archive.
3818 @item --delete
3819 Delete items from an archive (does not work on tapes).
3820 @item --compare
3821 @itemx --diff
3822 @itemx -d
3823 Compare archive members to their counterparts in the file system.
3824 @end table
3825
3826 @node append
3827 @subsection How to Add Files to Existing Archives: @option{--append}
3828 @UNREVISED
3829
3830 @opindex append
3831 If you want to add files to an existing archive, you don't need to
3832 create a new archive; you can use @option{--append} (@option{-r}).
3833 The archive must already exist in order to use @option{--append}. (A
3834 related operation is the @option{--update} operation; you can use this
3835 to add newer versions of archive members to an existing archive. To learn how to
3836 do this with @option{--update}, @pxref{update}.)
3837
3838 If you use @option{--append} to add a file that has the same name as an
3839 archive member to an archive containing that archive member, then the
3840 old member is not deleted. What does happen, however, is somewhat
3841 complex. @command{tar} @emph{allows} you to have infinite number of files
3842 with the same name. Some operations treat these same-named members no
3843 differently than any other set of archive members: for example, if you
3844 view an archive with @option{--list} (@option{-t}), you will see all
3845 of those members listed, with their data modification times, owners, etc.
3846
3847 Other operations don't deal with these members as perfectly as you might
3848 prefer; if you were to use @option{--extract} to extract the archive,
3849 only the most recently added copy of a member with the same name as four
3850 other members would end up in the working directory. This is because
3851 @option{--extract} extracts an archive in the order the members appeared
3852 in the archive; the most recently archived members will be extracted
3853 last. Additionally, an extracted member will @emph{replace} a file of
3854 the same name which existed in the directory already, and @command{tar}
3855 will not prompt you about this@footnote{Unless you give it
3856 @option{--keep-old-files} option, or the disk copy is newer than the
3857 the one in the archive and you invoke @command{tar} with
3858 @option{--keep-newer-files} option}. Thus, only the most recently archived
3859 member will end up being extracted, as it will replace the one
3860 extracted before it, and so on.
3861
3862 There exists a special option that allows you to get around this
3863 behavior and extract (or list) only a particular copy of the file.
3864 This is @option{--occurrence} option. If you run @command{tar} with
3865 this option, it will extract only the first copy of the file. You
3866 may also give this option an argument specifying the number of
3867 copy to be extracted. Thus, for example if the archive
3868 @file{archive.tar} contained three copies of file @file{myfile}, then
3869 the command
3870
3871 @smallexample
3872 tar --extract --file archive.tar --occurrence=2 myfile
3873 @end smallexample
3874
3875 @noindent
3876 would extract only the second copy. @xref{Option
3877 Summary,---occurrence}, for the description of @option{--occurrence}
3878 option.
3879
3880 @FIXME{ hag -- you might want to incorporate some of the above into the
3881 MMwtSN node; not sure. i didn't know how to make it simpler...
3882
3883 There are a few ways to get around this. (maybe xref Multiple Members
3884 with the Same Name.}
3885
3886 @cindex Members, replacing with other members
3887 @cindex Replacing members with other members
3888 If you want to replace an archive member, use @option{--delete} to
3889 delete the member you want to remove from the archive, , and then use
3890 @option{--append} to add the member you want to be in the archive. Note
3891 that you can not change the order of the archive; the most recently
3892 added member will still appear last. In this sense, you cannot truly
3893 ``replace'' one member with another. (Replacing one member with another
3894 will not work on certain types of media, such as tapes; see @ref{delete}
3895 and @ref{Media}, for more information.)
3896
3897 @menu
3898 * appending files:: Appending Files to an Archive
3899 * multiple::
3900 @end menu
3901
3902 @node appending files
3903 @subsubsection Appending Files to an Archive
3904 @UNREVISED
3905 @cindex Adding files to an Archive
3906 @cindex Appending files to an Archive
3907 @cindex Archives, Appending files to
3908
3909 The simplest way to add a file to an already existing archive is the
3910 @option{--append} (@option{-r}) operation, which writes specified
3911 files into the archive whether or not they are already among the
3912 archived files.
3913
3914 When you use @option{--append}, you @emph{must} specify file name
3915 arguments, as there is no default. If you specify a file that already
3916 exists in the archive, another copy of the file will be added to the
3917 end of the archive. As with other operations, the member names of the
3918 newly added files will be exactly the same as their names given on the
3919 command line. The @option{--verbose} (@option{-v}) option will print
3920 out the names of the files as they are written into the archive.
3921
3922 @option{--append} cannot be performed on some tape drives, unfortunately,
3923 due to deficiencies in the formats those tape drives use. The archive
3924 must be a valid @command{tar} archive, or else the results of using this
3925 operation will be unpredictable. @xref{Media}.
3926
3927 To demonstrate using @option{--append} to add a file to an archive,
3928 create a file called @file{rock} in the @file{practice} directory.
3929 Make sure you are in the @file{practice} directory. Then, run the
3930 following @command{tar} command to add @file{rock} to
3931 @file{collection.tar}:
3932
3933 @smallexample
3934 $ @kbd{tar --append --file=collection.tar rock}
3935 @end smallexample
3936
3937 @noindent
3938 If you now use the @option{--list} (@option{-t}) operation, you will see that
3939 @file{rock} has been added to the archive:
3940
3941 @smallexample
3942 $ @kbd{tar --list --file=collection.tar}
3943 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3944 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3945 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3946 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3947 @end smallexample
3948
3949 @node multiple
3950 @subsubsection Multiple Members with the Same Name
3951
3952 You can use @option{--append} (@option{-r}) to add copies of files
3953 which have been updated since the archive was created. (However, we
3954 do not recommend doing this since there is another @command{tar}
3955 option called @option{--update}; @xref{update}, for more information.
3956 We describe this use of @option{--append} here for the sake of
3957 completeness.) When you extract the archive, the older version will
3958 be effectively lost. This works because files are extracted from an
3959 archive in the order in which they were archived. Thus, when the
3960 archive is extracted, a file archived later in time will replace a
3961 file of the same name which was archived earlier, even though the
3962 older version of the file will remain in the archive unless you delete
3963 all versions of the file.
3964
3965 Supposing you change the file @file{blues} and then append the changed
3966 version to @file{collection.tar}. As you saw above, the original
3967 @file{blues} is in the archive @file{collection.tar}. If you change the
3968 file and append the new version of the file to the archive, there will
3969 be two copies in the archive. When you extract the archive, the older
3970 version of the file will be extracted first, and then replaced by the
3971 newer version when it is extracted.
3972
3973 You can append the new, changed copy of the file @file{blues} to the
3974 archive in this way:
3975
3976 @smallexample
3977 $ @kbd{tar --append --verbose --file=collection.tar blues}
3978 blues
3979 @end smallexample
3980
3981 @noindent
3982 Because you specified the @option{--verbose} option, @command{tar} has
3983 printed the name of the file being appended as it was acted on. Now
3984 list the contents of the archive:
3985
3986 @smallexample
3987 $ @kbd{tar --list --verbose --file=collection.tar}
3988 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
3989 -rw-r--r-- me user 21 1996-09-23 16:44 blues
3990 -rw-r--r-- me user 20 1996-09-23 16:44 folk
3991 -rw-r--r-- me user 20 1996-09-23 16:44 rock
3992 -rw-r--r-- me user 58 1996-10-24 18:30 blues
3993 @end smallexample
3994
3995 @noindent
3996 The newest version of @file{blues} is now at the end of the archive
3997 (note the different creation dates and file sizes). If you extract
3998 the archive, the older version of the file @file{blues} will be
3999 replaced by the newer version. You can confirm this by extracting
4000 the archive and running @samp{ls} on the directory.
4001
4002 If you wish to extract the first occurrence of the file @file{blues}
4003 from the archive, use @option{--occurrence} option, as shown in
4004 the following example:
4005
4006 @smallexample
4007 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4008 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4009 @end smallexample
4010
4011 @xref{Writing}, for more information on @option{--extract} and
4012 @xref{Option Summary, --occurrence}, for the description of
4013 @option{--occurrence} option.
4014
4015 @node update
4016 @subsection Updating an Archive
4017 @UNREVISED
4018 @cindex Updating an archive
4019
4020 @opindex update
4021 In the previous section, you learned how to use @option{--append} to
4022 add a file to an existing archive. A related operation is
4023 @option{--update} (@option{-u}). The @option{--update} operation
4024 updates a @command{tar} archive by comparing the date of the specified
4025 archive members against the date of the file with the same name. If
4026 the file has been modified more recently than the archive member, then
4027 the newer version of the file is added to the archive (as with
4028 @option{--append}).
4029
4030 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4031 The operation will fail.
4032
4033 @FIXME{other examples of media on which --update will fail? need to ask
4034 charles and/or mib/thomas/dave shevett..}
4035
4036 Both @option{--update} and @option{--append} work by adding to the end
4037 of the archive. When you extract a file from the archive, only the
4038 version stored last will wind up in the file system, unless you use
4039 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4040
4041 @menu
4042 * how to update::
4043 @end menu
4044
4045 @node how to update
4046 @subsubsection How to Update an Archive Using @option{--update}
4047
4048 You must use file name arguments with the @option{--update}
4049 (@option{-u}) operation. If you don't specify any files,
4050 @command{tar} won't act on any files and won't tell you that it didn't
4051 do anything (which may end up confusing you).
4052
4053 @c note: the above parenthetical added because in fact, this
4054 @c behavior just confused the author. :-)
4055
4056 To see the @option{--update} option at work, create a new file,
4057 @file{classical}, in your practice directory, and some extra text to the
4058 file @file{blues}, using any text editor. Then invoke @command{tar} with
4059 the @samp{update} operation and the @option{--verbose} (@option{-v})
4060 option specified, using the names of all the files in the practice
4061 directory as file name arguments:
4062
4063 @smallexample
4064 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4065 blues
4066 classical
4067 $
4068 @end smallexample
4069
4070 @noindent
4071 Because we have specified verbose mode, @command{tar} prints out the names
4072 of the files it is working on, which in this case are the names of the
4073 files that needed to be updated. If you run @samp{tar --list} and look
4074 at the archive, you will see @file{blues} and @file{classical} at its
4075 end. There will be a total of two versions of the member @samp{blues};
4076 the one at the end will be newer and larger, since you added text before
4077 updating it.
4078
4079 (The reason @command{tar} does not overwrite the older file when updating
4080 it is because writing to the middle of a section of tape is a difficult
4081 process. Tapes are not designed to go backward. @xref{Media}, for more
4082 information about tapes.
4083
4084 @option{--update} (@option{-u}) is not suitable for performing backups for two
4085 reasons: it does not change directory content entries, and it
4086 lengthens the archive every time it is used. The @GNUTAR{}
4087 options intended specifically for backups are more
4088 efficient. If you need to run backups, please consult @ref{Backups}.
4089
4090 @node concatenate
4091 @subsection Combining Archives with @option{--concatenate}
4092
4093 @cindex Adding archives to an archive
4094 @cindex Concatenating Archives
4095 @opindex concatenate
4096 @opindex catenate
4097 @c @cindex @option{-A} described
4098 Sometimes it may be convenient to add a second archive onto the end of
4099 an archive rather than adding individual files to the archive. To add
4100 one or more archives to the end of another archive, you should use the
4101 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4102
4103 To use @option{--concatenate}, give the first archive with
4104 @option{--file} option and name the rest of archives to be
4105 concatenated on the command line. The members, and their member
4106 names, will be copied verbatim from those archives to the first one.
4107 @footnote{This can cause multiple members to have the same name, for
4108 information on how this affects reading the archive, @ref{multiple}.}
4109 The new, concatenated archive will be called by the same name as the
4110 one given with the @option{--file} option. As usual, if you omit
4111 @option{--file}, @command{tar} will use the value of the environment
4112 variable @env{TAPE}, or, if this has not been set, the default archive name.
4113
4114 @FIXME{There is no way to specify a new name...}
4115
4116 To demonstrate how @option{--concatenate} works, create two small archives
4117 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4118 files from @file{practice}:
4119
4120 @smallexample
4121 $ @kbd{tar -cvf bluesrock.tar blues rock}
4122 blues
4123 rock
4124 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4125 folk
4126 jazz
4127 @end smallexample
4128
4129 @noindent
4130 If you like, You can run @samp{tar --list} to make sure the archives
4131 contain what they are supposed to:
4132
4133 @smallexample
4134 $ @kbd{tar -tvf bluesrock.tar}
4135 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4136 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4137 $ @kbd{tar -tvf jazzfolk.tar}
4138 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4139 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4140 @end smallexample
4141
4142 We can concatenate these two archives with @command{tar}:
4143
4144 @smallexample
4145 $ @kbd{cd ..}
4146 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4147 @end smallexample
4148
4149 If you now list the contents of the @file{bluesrock.tar}, you will see
4150 that now it also contains the archive members of @file{jazzfolk.tar}:
4151
4152 @smallexample
4153 $ @kbd{tar --list --file=bluesrock.tar}
4154 blues
4155 rock
4156 folk
4157 jazz
4158 @end smallexample
4159
4160 When you use @option{--concatenate}, the source and target archives must
4161 already exist and must have been created using compatible format
4162 parameters. Notice, that @command{tar} does not check whether the
4163 archives it concatenates have compatible formats, it does not
4164 even check if the files are really tar archives.
4165
4166 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4167 tape drives, due to deficiencies in the formats those tape drives use.
4168
4169 @cindex @code{concatenate} vs @command{cat}
4170 @cindex @command{cat} vs @code{concatenate}
4171 It may seem more intuitive to you to want or try to use @command{cat} to
4172 concatenate two archives instead of using the @option{--concatenate}
4173 operation; after all, @command{cat} is the utility for combining files.
4174
4175 However, @command{tar} archives incorporate an end-of-file marker which
4176 must be removed if the concatenated archives are to be read properly as
4177 one archive. @option{--concatenate} removes the end-of-archive marker
4178 from the target archive before each new archive is appended. If you use
4179 @command{cat} to combine the archives, the result will not be a valid
4180 @command{tar} format archive. If you need to retrieve files from an
4181 archive that was added to using the @command{cat} utility, use the
4182 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4183 information on dealing with archives improperly combined using the
4184 @command{cat} shell utility.
4185
4186 @node delete
4187 @subsection Removing Archive Members Using @option{--delete}
4188 @UNREVISED
4189 @cindex Deleting files from an archive
4190 @cindex Removing files from an archive
4191
4192 @opindex delete
4193 You can remove members from an archive by using the @option{--delete}
4194 option. Specify the name of the archive with @option{--file}
4195 (@option{-f}) and then specify the names of the members to be deleted;
4196 if you list no member names, nothing will be deleted. The
4197 @option{--verbose} option will cause @command{tar} to print the names
4198 of the members as they are deleted. As with @option{--extract}, you
4199 must give the exact member names when using @samp{tar --delete}.
4200 @option{--delete} will remove all versions of the named file from the
4201 archive. The @option{--delete} operation can run very slowly.
4202
4203 Unlike other operations, @option{--delete} has no short form.
4204
4205 @cindex Tapes, using @option{--delete} and
4206 @cindex Deleting from tape archives
4207 This operation will rewrite the archive. You can only use
4208 @option{--delete} on an archive if the archive device allows you to
4209 write to any point on the media, such as a disk; because of this, it
4210 does not work on magnetic tapes. Do not try to delete an archive member
4211 from a magnetic tape; the action will not succeed, and you will be
4212 likely to scramble the archive and damage your tape. There is no safe
4213 way (except by completely re-writing the archive) to delete files from
4214 most kinds of magnetic tape. @xref{Media}.
4215
4216 To delete all versions of the file @file{blues} from the archive
4217 @file{collection.tar} in the @file{practice} directory, make sure you
4218 are in that directory, and then,
4219
4220 @smallexample
4221 $ @kbd{tar --list --file=collection.tar}
4222 blues
4223 folk
4224 jazz
4225 rock
4226 $ @kbd{tar --delete --file=collection.tar blues}
4227 $ @kbd{tar --list --file=collection.tar}
4228 folk
4229 jazz
4230 rock
4231 $
4232 @end smallexample
4233
4234 @FIXME{Check if the above listing is actually produced after running
4235 all the examples on collection.tar.}
4236
4237 The @option{--delete} option has been reported to work properly when
4238 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4239
4240 @node compare
4241 @subsection Comparing Archive Members with the File System
4242 @cindex Verifying the currency of an archive
4243 @UNREVISED
4244
4245 @opindex compare
4246 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4247 specified archive members against files with the same names, and then
4248 reports differences in file size, mode, owner, modification date and
4249 contents. You should @emph{only} specify archive member names, not file
4250 names. If you do not name any members, then @command{tar} will compare the
4251 entire archive. If a file is represented in the archive but does not
4252 exist in the file system, @command{tar} reports a difference.
4253
4254 You have to specify the record size of the archive when modifying an
4255 archive with a non-default record size.
4256
4257 @command{tar} ignores files in the file system that do not have
4258 corresponding members in the archive.
4259
4260 The following example compares the archive members @file{rock},
4261 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4262 files of the same name in the file system. (Note that there is no file,
4263 @file{funk}; @command{tar} will report an error message.)
4264
4265 @smallexample
4266 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4267 rock
4268 blues
4269 tar: funk not found in archive
4270 @end smallexample
4271
4272 The spirit behind the @option{--compare} (@option{--diff},
4273 @option{-d}) option is to check whether the archive represents the
4274 current state of files on disk, more than validating the integrity of
4275 the archive media. For this later goal, @xref{verify}.
4276
4277 @node create options
4278 @section Options Used by @option{--create}
4279
4280 @xopindex{create, additional options}
4281 The previous chapter described the basics of how to use
4282 @option{--create} (@option{-c}) to create an archive from a set of files.
4283 @xref{create}. This section described advanced options to be used with
4284 @option{--create}.
4285
4286 @menu
4287 * override:: Overriding File Metadata.
4288 * Ignore Failed Read::
4289 @end menu
4290
4291 @node override
4292 @subsection Overriding File Metadata
4293
4294 As described above, a @command{tar} archive keeps, for each member it contains,
4295 its @dfn{metadata}, such as modification time, mode and ownership of
4296 the file. @GNUTAR{} allows to replace these data with other values
4297 when adding files to the archive. The options described in this
4298 section affect creation of archives of any type. For POSIX archives,
4299 see also @ref{PAX keywords}, for additional ways of controlling
4300 metadata, stored in the archive.
4301
4302 @table @option
4303 @opindex mode
4304 @item --mode=@var{permissions}
4305
4306 When adding files to an archive, @command{tar} will use
4307 @var{permissions} for the archive members, rather than the permissions
4308 from the files. @var{permissions} can be specified either as an octal
4309 number or as symbolic permissions, like with
4310 @command{chmod} (@xref{File permissions, Permissions, File
4311 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4312 also has useful information for those not being overly familiar with
4313 the UNIX permission system). Using latter syntax allows for
4314 more flexibility. For example, the value @samp{a+rw} adds read and write
4315 permissions for everybody, while retaining executable bits on directories
4316 or on any other file already marked as executable:
4317
4318 @smallexample
4319 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4320 @end smallexample
4321
4322 @item --mtime=@var{date}
4323 @opindex mtime
4324
4325 When adding files to an archive, @command{tar} will use @var{date} as
4326 the modification time of members when creating archives, instead of
4327 their actual modification times. The argument @var{date} can be
4328 either a textual date representation in almost arbitrary format
4329 (@pxref{Date input formats}) or a name of the existing file, starting
4330 with @samp{/} or @samp{.}. In the latter case, the modification time
4331 of that file will be used.
4332
4333 The following example will set the modification date to 00:00:00 UTC,
4334 January 1, 1970:
4335
4336 @smallexample
4337 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4338 @end smallexample
4339
4340 @noindent
4341 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4342 will try to convert the specified date back to its textual
4343 representation and compare it with the one given with
4344 @option{--mtime} options. If the two dates differ, @command{tar} will
4345 print a warning saying what date it will use. This is to help user
4346 ensure he is using the right date.
4347
4348 For example:
4349
4350 @smallexample
4351 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4352 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4353 13:06:29.152478
4354 @dots{}
4355 @end smallexample
4356
4357 @item --owner=@var{user}
4358 @opindex owner
4359
4360 Specifies that @command{tar} should use @var{user} as the owner of members
4361 when creating archives, instead of the user associated with the source
4362 file. The argument @var{user} can be either an existing user symbolic
4363 name, or a decimal numeric user ID.
4364
4365 There is no value indicating a missing number, and @samp{0} usually means
4366 @code{root}. Some people like to force @samp{0} as the value to offer in
4367 their distributions for the owner of files, because the @code{root} user is
4368 anonymous anyway, so that might as well be the owner of anonymous
4369 archives. For example:
4370
4371 @smallexample
4372 @group
4373 $ @kbd{tar -c -f archive.tar --owner=0 .}
4374 # @r{Or:}
4375 $ @kbd{tar -c -f archive.tar --owner=root .}
4376 @end group
4377 @end smallexample
4378
4379 @item --group=@var{group}
4380 @opindex group
4381
4382 Files added to the @command{tar} archive will have a group id of @var{group},
4383 rather than the group from the source file. The argument @var{group}
4384 can be either an existing group symbolic name, or a decimal numeric group ID.
4385 @end table
4386
4387 @node Ignore Failed Read
4388 @subsection Ignore Fail Read
4389
4390 @table @option
4391 @item --ignore-failed-read
4392 @opindex ignore-failed-read
4393 Do not exit with nonzero on unreadable files or directories.
4394 @end table
4395
4396 @node extract options
4397 @section Options Used by @option{--extract}
4398 @UNREVISED
4399
4400 @xopindex{extract, additional options}
4401 The previous chapter showed how to use @option{--extract} to extract
4402 an archive into the file system. Various options cause @command{tar} to
4403 extract more information than just file contents, such as the owner,
4404 the permissions, the modification date, and so forth. This section
4405 presents options to be used with @option{--extract} when certain special
4406 considerations arise. You may review the information presented in
4407 @ref{extract} for more basic information about the
4408 @option{--extract} operation.
4409
4410 @menu
4411 * Reading:: Options to Help Read Archives
4412 * Writing:: Changing How @command{tar} Writes Files
4413 * Scarce:: Coping with Scarce Resources
4414 @end menu
4415
4416 @node Reading
4417 @subsection Options to Help Read Archives
4418 @cindex Options when reading archives
4419 @UNREVISED
4420
4421 @cindex Reading incomplete records
4422 @cindex Records, incomplete
4423 @opindex read-full-records
4424 Normally, @command{tar} will request data in full record increments from
4425 an archive storage device. If the device cannot return a full record,
4426 @command{tar} will report an error. However, some devices do not always
4427 return full records, or do not require the last record of an archive to
4428 be padded out to the next record boundary. To keep reading until you
4429 obtain a full record, or to accept an incomplete record if it contains
4430 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
4431 in conjunction with the @option{--extract} or @option{--list} operations.
4432 @xref{Blocking}.
4433
4434 The @option{--read-full-records} (@option{-B}) option is turned on by default when
4435 @command{tar} reads an archive from standard input, or from a remote
4436 machine. This is because on BSD Unix systems, attempting to read a
4437 pipe returns however much happens to be in the pipe, even if it is
4438 less than was requested. If this option were not enabled, @command{tar}
4439 would fail as soon as it read an incomplete record from the pipe.
4440
4441 If you're not sure of the blocking factor of an archive, you can
4442 read the archive by specifying @option{--read-full-records} (@option{-B}) and
4443 @option{--blocking-factor=@var{512-size}} (@option{-b
4444 @var{512-size}}), using a blocking factor larger than what the archive
4445 uses. This lets you avoid having to determine the blocking factor
4446 of an archive. @xref{Blocking Factor}.
4447
4448 @menu
4449 * read full records::
4450 * Ignore Zeros::
4451 @end menu
4452
4453 @node read full records
4454 @unnumberedsubsubsec Reading Full Records
4455
4456 @FIXME{need sentence or so of intro here}
4457
4458 @table @option
4459 @opindex read-full-records
4460 @item --read-full-records
4461 @item -B
4462 Use in conjunction with @option{--extract} (@option{--get},
4463 @option{-x}) to read an archive which contains incomplete records, or
4464 one which has a blocking factor less than the one specified.
4465 @end table
4466
4467 @node Ignore Zeros
4468 @unnumberedsubsubsec Ignoring Blocks of Zeros
4469
4470 @cindex End-of-archive blocks, ignoring
4471 @cindex Ignoring end-of-archive blocks
4472 @opindex ignore-zeros
4473 Normally, @command{tar} stops reading when it encounters a block of zeros
4474 between file entries (which usually indicates the end of the archive).
4475 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
4476 completely read an archive which contains a block of zeros before the
4477 end (i.e., a damaged archive, or one that was created by concatenating
4478 several archives together).
4479
4480 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
4481 versions of @command{tar} write garbage after the end-of-archive entry,
4482 since that part of the media is never supposed to be read. @GNUTAR{}
4483 does not write after the end of an archive, but seeks to
4484 maintain compatibility among archiving utilities.
4485
4486 @table @option
4487 @item --ignore-zeros
4488 @itemx -i
4489 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
4490 encountered while reading an archive. Use in conjunction with
4491 @option{--extract} or @option{--list}.
4492 @end table
4493
4494 @node Writing
4495 @subsection Changing How @command{tar} Writes Files
4496 @UNREVISED
4497
4498 @FIXME{Introductory paragraph}
4499
4500 @menu
4501 * Dealing with Old Files::
4502 * Overwrite Old Files::
4503 * Keep Old Files::
4504 * Keep Newer Files::
4505 * Unlink First::
4506 * Recursive Unlink::
4507 * Data Modification Times::
4508 * Setting Access Permissions::
4509 * Directory Modification Times and Permissions::
4510 * Writing to Standard Output::
4511 * Writing to an External Program::
4512 * remove files::
4513 @end menu
4514
4515 @node Dealing with Old Files
4516 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
4517
4518 @xopindex{overwrite-dir, introduced}
4519 When extracting files, if @command{tar} discovers that the extracted
4520 file already exists, it normally replaces the file by removing it before
4521 extracting it, to prevent confusion in the presence of hard or symbolic
4522 links. (If the existing file is a symbolic link, it is removed, not
4523 followed.) However, if a directory cannot be removed because it is
4524 nonempty, @command{tar} normally overwrites its metadata (ownership,
4525 permission, etc.). The @option{--overwrite-dir} option enables this
4526 default behavior. To be more cautious and preserve the metadata of
4527 such a directory, use the @option{--no-overwrite-dir} option.
4528
4529 @cindex Overwriting old files, prevention
4530 @xopindex{keep-old-files, introduced}
4531 To be even more cautious and prevent existing files from being replaced, use
4532 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
4533 to replace or update a file that already exists, i.e., a file with the
4534 same name as an archive member prevents extraction of that archive
4535 member. Instead, it reports an error.
4536
4537 @xopindex{overwrite, introduced}
4538 To be more aggressive about altering existing files, use the
4539 @option{--overwrite} option. It causes @command{tar} to overwrite
4540 existing files and to follow existing symbolic links when extracting.
4541
4542 @cindex Protecting old files
4543 Some people argue that @GNUTAR{} should not hesitate
4544 to overwrite files with other files when extracting. When extracting
4545 a @command{tar} archive, they expect to see a faithful copy of the
4546 state of the file system when the archive was created. It is debatable
4547 that this would always be a proper behavior. For example, suppose one
4548 has an archive in which @file{usr/local} is a link to
4549 @file{usr/local2}. Since then, maybe the site removed the link and
4550 renamed the whole hierarchy from @file{/usr/local2} to
4551 @file{/usr/local}. Such things happen all the time. I guess it would
4552 not be welcome at all that @GNUTAR{} removes the
4553 whole hierarchy just to make room for the link to be reinstated
4554 (unless it @emph{also} simultaneously restores the full
4555 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
4556 able to remove a whole hierarchy to reestablish a symbolic link, for
4557 example, but @emph{only if} @option{--recursive-unlink} is specified
4558 to allow this behavior. In any case, single files are silently
4559 removed.
4560
4561 @xopindex{unlink-first, introduced}
4562 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
4563 some cases by causing @command{tar} to remove files unconditionally
4564 before extracting them.
4565
4566 @node Overwrite Old Files
4567 @unnumberedsubsubsec Overwrite Old Files
4568
4569 @table @option
4570 @opindex overwrite
4571 @item --overwrite
4572 Overwrite existing files and directory metadata when extracting files
4573 from an archive.
4574
4575 This causes @command{tar} to write extracted files into the file system without
4576 regard to the files already on the system; i.e., files with the same
4577 names as archive members are overwritten when the archive is extracted.
4578 It also causes @command{tar} to extract the ownership, permissions,
4579 and time stamps onto any preexisting files or directories.
4580 If the name of a corresponding file name is a symbolic link, the file
4581 pointed to by the symbolic link will be overwritten instead of the
4582 symbolic link itself (if this is possible). Moreover, special devices,
4583 empty directories and even symbolic links are automatically removed if
4584 they are in the way of extraction.
4585
4586 Be careful when using the @option{--overwrite} option, particularly when
4587 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
4588 can change the contents, ownership or permissions of any file on your
4589 system. Also, many systems do not take kindly to overwriting files that
4590 are currently being executed.
4591
4592 @opindex overwrite-dir
4593 @item --overwrite-dir
4594 Overwrite the metadata of directories when extracting files from an
4595 archive, but remove other files before extracting.
4596 @end table
4597
4598 @node Keep Old Files
4599 @unnumberedsubsubsec Keep Old Files
4600
4601 @table @option
4602 @opindex keep-old-files
4603 @item --keep-old-files
4604 @itemx -k
4605 Do not replace existing files from archive. The
4606 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
4607 from replacing existing files with files with the same name from the
4608 archive. The @option{--keep-old-files} option is meaningless with
4609 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
4610 files in the file system during extraction.
4611 @end table
4612
4613 @node Keep Newer Files
4614 @unnumberedsubsubsec Keep Newer Files
4615
4616 @table @option
4617 @opindex keep-newer-files
4618 @item --keep-newer-files
4619 Do not replace existing files that are newer than their archive
4620 copies. This option is meaningless with @option{--list} (@option{-t}).
4621 @end table
4622
4623 @node Unlink First
4624 @unnumberedsubsubsec Unlink First
4625
4626 @table @option
4627 @opindex unlink-first
4628 @item --unlink-first
4629 @itemx -U
4630 Remove files before extracting over them.
4631 This can make @command{tar} run a bit faster if you know in advance
4632 that the extracted files all need to be removed. Normally this option
4633 slows @command{tar} down slightly, so it is disabled by default.
4634 @end table
4635
4636 @node Recursive Unlink
4637 @unnumberedsubsubsec Recursive Unlink
4638
4639 @table @option
4640 @opindex recursive-unlink
4641 @item --recursive-unlink
4642 When this option is specified, try removing files and directory hierarchies
4643 before extracting over them. @emph{This is a dangerous option!}
4644 @end table
4645
4646 If you specify the @option{--recursive-unlink} option,
4647 @command{tar} removes @emph{anything} that keeps you from extracting a file
4648 as far as current permissions will allow it. This could include removal
4649 of the contents of a full directory hierarchy.
4650
4651 @node Data Modification Times
4652 @unnumberedsubsubsec Setting Data Modification Times
4653
4654 @cindex Data modification times of extracted files
4655 @cindex Modification times of extracted files
4656 Normally, @command{tar} sets the data modification times of extracted
4657 files to the corresponding times recorded for the files in the archive, but
4658 limits the permissions of extracted files by the current @code{umask}
4659 setting.
4660
4661 To set the data modification times of extracted files to the time when
4662 the files were extracted, use the @option{--touch} (@option{-m}) option in
4663 conjunction with @option{--extract} (@option{--get}, @option{-x}).
4664
4665 @table @option
4666 @opindex touch
4667 @item --touch
4668 @itemx -m
4669 Sets the data modification time of extracted archive members to the time
4670 they were extracted, not the time recorded for them in the archive.
4671 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
4672 @end table
4673
4674 @node Setting Access Permissions
4675 @unnumberedsubsubsec Setting Access Permissions
4676
4677 @cindex Permissions of extracted files
4678 @cindex Modes of extracted files
4679 To set the modes (access permissions) of extracted files to those
4680 recorded for those files in the archive, use @option{--same-permissions}
4681 in conjunction with the @option{--extract} (@option{--get},
4682 @option{-x}) operation.
4683
4684 @table @option
4685 @opindex preserve-permissions
4686 @opindex same-permissions
4687 @item --preserve-permissions
4688 @itemx --same-permissions
4689 @c @itemx --ignore-umask
4690 @itemx -p
4691 Set modes of extracted archive members to those recorded in the
4692 archive, instead of current umask settings. Use in conjunction with
4693 @option{--extract} (@option{--get}, @option{-x}).
4694 @end table
4695
4696 @node Directory Modification Times and Permissions
4697 @unnumberedsubsubsec Directory Modification Times and Permissions
4698
4699 After successfully extracting a file member, @GNUTAR{} normally
4700 restores its permissions and modification times, as described in the
4701 previous sections. This cannot be done for directories, because
4702 after extracting a directory @command{tar} will almost certainly
4703 extract files into that directory and this will cause the directory
4704 modification time to be updated. Moreover, restoring that directory
4705 permissions may not permit file creation within it. Thus, restoring
4706 directory permissions and modification times must be delayed at least
4707 until all files have been extracted into that directory. @GNUTAR{}
4708 restores directories using the following approach.
4709
4710 The extracted directories are created with the mode specified in the
4711 archive, as modified by the umask of the user, which gives sufficient
4712 permissions to allow file creation. The meta-information about the
4713 directory is recorded in the temporary list of directories. When
4714 preparing to extract next archive member, @GNUTAR{} checks if the
4715 directory prefix of this file contains the remembered directory. If
4716 it does not, the program assumes that all files have been extracted
4717 into that directory, restores its modification time and permissions
4718 and removes its entry from the internal list. This approach allows
4719 to correctly restore directory meta-information in the majority of
4720 cases, while keeping memory requirements sufficiently small. It is
4721 based on the fact, that most @command{tar} archives use the predefined
4722 order of members: first the directory, then all the files and
4723 subdirectories in that directory.
4724
4725 However, this is not always true. The most important exception are
4726 incremental archives (@pxref{Incremental Dumps}). The member order in
4727 an incremental archive is reversed: first all directory members are
4728 stored, followed by other (non-directory) members. So, when extracting
4729 from incremental archives, @GNUTAR{} alters the above procedure. It
4730 remembers all restored directories, and restores their meta-data
4731 only after the entire archive has been processed. Notice, that you do
4732 not need to specify any special options for that, as @GNUTAR{}
4733 automatically detects archives in incremental format.
4734
4735 There may be cases, when such processing is required for normal archives
4736 too. Consider the following example:
4737
4738 @smallexample
4739 @group
4740 $ @kbd{tar --no-recursion -cvf archive \
4741 foo foo/file1 bar bar/file foo/file2}
4742 foo/
4743 foo/file1
4744 bar/
4745 bar/file
4746 foo/file2
4747 @end group
4748 @end smallexample
4749
4750 During the normal operation, after encountering @file{bar}
4751 @GNUTAR{} will assume that all files from the directory @file{foo}
4752 were already extracted and will therefore restore its timestamp and
4753 permission bits. However, after extracting @file{foo/file2} the
4754 directory timestamp will be offset again.
4755
4756 To correctly restore directory meta-information in such cases, use
4757 @option{delay-directory-restore} command line option:
4758
4759 @table @option
4760 @opindex delay-directory-restore
4761 @item --delay-directory-restore
4762 Delays restoring of the modification times and permissions of extracted
4763 directories until the end of extraction. This way, correct
4764 meta-information is restored even if the archive has unusual member
4765 ordering.
4766
4767 @opindex no-delay-directory-restore
4768 @item --no-delay-directory-restore
4769 Cancel the effect of the previous @option{--delay-directory-restore}.
4770 Use this option if you have used @option{--delay-directory-restore} in
4771 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
4772 temporarily disable it.
4773 @end table
4774
4775 @node Writing to Standard Output
4776 @unnumberedsubsubsec Writing to Standard Output
4777
4778 @cindex Writing extracted files to standard output
4779 @cindex Standard output, writing extracted files to
4780 To write the extracted files to the standard output, instead of
4781 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
4782 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
4783 extracting files to send them through a pipe, and do not need to
4784 preserve them in the file system. If you extract multiple members,
4785 they appear on standard output concatenated, in the order they are
4786 found in the archive.
4787
4788 @table @option
4789 @opindex to-stdout
4790 @item --to-stdout
4791 @itemx -O
4792 Writes files to the standard output. Use only in conjunction with
4793 @option{--extract} (@option{--get}, @option{-x}). When this option is
4794 used, instead of creating the files specified, @command{tar} writes
4795 the contents of the files extracted to its standard output. This may
4796 be useful if you are only extracting the files in order to send them
4797 through a pipe. This option is meaningless with @option{--list}
4798 (@option{-t}).
4799 @end table
4800
4801 This can be useful, for example, if you have a tar archive containing
4802 a big file and don't want to store the file on disk before processing
4803 it. You can use a command like this:
4804
4805 @smallexample
4806 tar -xOzf foo.tgz bigfile | process
4807 @end smallexample
4808
4809 or even like this if you want to process the concatenation of the files:
4810
4811 @smallexample
4812 tar -xOzf foo.tgz bigfile1 bigfile2 | process
4813 @end smallexample
4814
4815 However, @option{--to-command} may be more convenient for use with
4816 multiple files. See the next section.
4817
4818 @node Writing to an External Program
4819 @unnumberedsubsubsec Writing to an External Program
4820
4821 You can instruct @command{tar} to send the contents of each extracted
4822 file to the standard input of an external program:
4823
4824 @table @option
4825 @opindex to-command
4826 @item --to-command=@var{command}
4827 Extract files and pipe their contents to the standard input of
4828 @var{command}. When this option is used, instead of creating the
4829 files specified, @command{tar} invokes @var{command} and pipes the
4830 contents of the files to its standard output. @var{Command} may
4831 contain command line arguments. The program is executed via
4832 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
4833 extracted. Non-regular files (directories, etc.) are ignored when this
4834 option is used.
4835 @end table
4836
4837 The command can obtain the information about the file it processes
4838 from the following environment variables:
4839
4840 @table @var
4841 @vrindex TAR_FILETYPE, to-command environment
4842 @item TAR_FILETYPE
4843 Type of the file. It is a single letter with the following meaning:
4844
4845 @multitable @columnfractions 0.10 0.90
4846 @item f @tab Regular file
4847 @item d @tab Directory
4848 @item l @tab Symbolic link
4849 @item h @tab Hard link
4850 @item b @tab Block device
4851 @item c @tab Character device
4852 @end multitable
4853
4854 Currently only regular files are supported.
4855
4856 @vrindex TAR_MODE, to-command environment
4857 @item TAR_MODE
4858 File mode, an octal number.
4859
4860 @vrindex TAR_FILENAME, to-command environment
4861 @item TAR_FILENAME
4862 The name of the file.
4863
4864 @vrindex TAR_REALNAME, to-command environment
4865 @item TAR_REALNAME
4866 Name of the file as stored in the archive.
4867
4868 @vrindex TAR_UNAME, to-command environment
4869 @item TAR_UNAME
4870 Name of the file owner.
4871
4872 @vrindex TAR_GNAME, to-command environment
4873 @item TAR_GNAME
4874 Name of the file owner group.
4875
4876 @vrindex TAR_ATIME, to-command environment
4877 @item TAR_ATIME
4878 Time of last access. It is a decimal number, representing seconds
4879 since the epoch. If the archive provides times with nanosecond
4880 precision, the nanoseconds are appended to the timestamp after a
4881 decimal point.
4882
4883 @vrindex TAR_MTIME, to-command environment
4884 @item TAR_MTIME
4885 Time of last modification.
4886
4887 @vrindex TAR_CTIME, to-command environment
4888 @item TAR_CTIME
4889 Time of last status change.
4890
4891 @vrindex TAR_SIZE, to-command environment
4892 @item TAR_SIZE
4893 Size of the file.
4894
4895 @vrindex TAR_UID, to-command environment
4896 @item TAR_UID
4897 UID of the file owner.
4898
4899 @vrindex TAR_GID, to-command environment
4900 @item TAR_GID
4901 GID of the file owner.
4902 @end table
4903
4904 In addition to these variables, @env{TAR_VERSION} contains the
4905 @GNUTAR{} version number.
4906
4907 If @var{command} exits with a non-0 status, @command{tar} will print
4908 an error message similar to the following:
4909
4910 @smallexample
4911 tar: 2345: Child returned status 1
4912 @end smallexample
4913
4914 Here, @samp{2345} is the PID of the finished process.
4915
4916 If this behavior is not wanted, use @option{--ignore-command-error}:
4917
4918 @table @option
4919 @opindex ignore-command-error
4920 @item --ignore-command-error
4921 Ignore exit codes of subprocesses. Notice that if the program
4922 exits on signal or otherwise terminates abnormally, the error message
4923 will be printed even if this option is used.
4924
4925 @opindex no-ignore-command-error
4926 @item --no-ignore-command-error
4927 Cancel the effect of any previous @option{--ignore-command-error}
4928 option. This option is useful if you have set
4929 @option{--ignore-command-error} in @env{TAR_OPTIONS}
4930 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
4931 @end table
4932
4933 @node remove files
4934 @unnumberedsubsubsec Removing Files
4935
4936 @FIXME{The section is too terse. Something more to add? An example,
4937 maybe?}
4938
4939 @table @option
4940 @opindex remove-files
4941 @item --remove-files
4942 Remove files after adding them to the archive.
4943 @end table
4944
4945 @node Scarce
4946 @subsection Coping with Scarce Resources
4947 @UNREVISED
4948
4949 @cindex Small memory
4950 @cindex Running out of space
4951
4952 @menu
4953 * Starting File::
4954 * Same Order::
4955 @end menu
4956
4957 @node Starting File
4958 @unnumberedsubsubsec Starting File
4959
4960 @table @option
4961 @opindex starting-file
4962 @item --starting-file=@var{name}
4963 @itemx -K @var{name}
4964 Starts an operation in the middle of an archive. Use in conjunction
4965 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
4966 @end table
4967
4968 @cindex Middle of the archive, starting in the
4969 If a previous attempt to extract files failed due to lack of disk
4970 space, you can use @option{--starting-file=@var{name}} (@option{-K
4971 @var{name}}) to start extracting only after member @var{name} of the
4972 archive. This assumes, of course, that there is now free space, or
4973 that you are now extracting into a different file system. (You could
4974 also choose to suspend @command{tar}, remove unnecessary files from
4975 the file system, and then restart the same @command{tar} operation.
4976 In this case, @option{--starting-file} is not necessary.
4977 @xref{Incremental Dumps}, @xref{interactive}, and @ref{exclude}.)
4978
4979 @node Same Order
4980 @unnumberedsubsubsec Same Order
4981
4982 @table @option
4983 @cindex Large lists of file names on small machines
4984 @opindex same-order
4985 @opindex preserve-order
4986 @item --same-order
4987 @itemx --preserve-order
4988 @itemx -s
4989 To process large lists of file names on machines with small amounts of
4990 memory. Use in conjunction with @option{--compare} (@option{--diff},
4991 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
4992 (@option{--get}, @option{-x}).
4993 @end table
4994
4995 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
4996 names to be listed or extracted is sorted in the same order as the
4997 files in the archive. This allows a large list of names to be used,
4998 even on a small machine that would not otherwise be able to hold all
4999 the names in memory at the same time. Such a sorted list can easily be
5000 created by running @samp{tar -t} on the archive and editing its output.
5001
5002 This option is probably never needed on modern computer systems.
5003
5004 @node backup
5005 @section Backup options
5006
5007 @cindex backup options
5008
5009 @GNUTAR{} offers options for making backups of files
5010 before writing new versions. These options control the details of
5011 these backups. They may apply to the archive itself before it is
5012 created or rewritten, as well as individual extracted members. Other
5013 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5014 and @command{mv}, for example) offer similar options.
5015
5016 Backup options may prove unexpectedly useful when extracting archives
5017 containing many members having identical name, or when extracting archives
5018 on systems having file name limitations, making different members appear
5019 has having similar names through the side-effect of name truncation.
5020 (This is true only if we have a good scheme for truncated backup names,
5021 which I'm not sure at all: I suspect work is needed in this area.)
5022 When any existing file is backed up before being overwritten by extraction,
5023 then clashing files are automatically be renamed to be unique, and the
5024 true name is kept for only the last file of a series of clashing files.
5025 By using verbose mode, users may track exactly what happens.
5026
5027 At the detail level, some decisions are still experimental, and may
5028 change in the future, we are waiting comments from our users. So, please
5029 do not learn to depend blindly on the details of the backup features.
5030 For example, currently, directories themselves are never renamed through
5031 using these options, so, extracting a file over a directory still has
5032 good chances to fail. Also, backup options apply to created archives,
5033 not only to extracted members. For created archives, backups will not
5034 be attempted when the archive is a block or character device, or when it
5035 refers to a remote file.
5036
5037 For the sake of simplicity and efficiency, backups are made by renaming old
5038 files prior to creation or extraction, and not by copying. The original
5039 name is restored if the file creation fails. If a failure occurs after a
5040 partial extraction of a file, both the backup and the partially extracted
5041 file are kept.
5042
5043 @table @samp
5044 @item --backup[=@var{method}]
5045 @opindex backup
5046 @vindex VERSION_CONTROL
5047 @cindex backups
5048 Back up files that are about to be overwritten or removed.
5049 Without this option, the original versions are destroyed.
5050
5051 Use @var{method} to determine the type of backups made.
5052 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5053 environment variable. And if @env{VERSION_CONTROL} is not set,
5054 use the @samp{existing} method.
5055
5056 @vindex version-control @r{Emacs variable}
5057 This option corresponds to the Emacs variable @samp{version-control};
5058 the same values for @var{method} are accepted as in Emacs. This option
5059 also allows more descriptive names. The valid @var{method}s are:
5060
5061 @table @samp
5062 @item t
5063 @itemx numbered
5064 @cindex numbered @r{backup method}
5065 Always make numbered backups.
5066
5067 @item nil
5068 @itemx existing
5069 @cindex existing @r{backup method}
5070 Make numbered backups of files that already have them, simple backups
5071 of the others.
5072
5073 @item never
5074 @itemx simple
5075 @cindex simple @r{backup method}
5076 Always make simple backups.
5077
5078 @end table
5079
5080 @item --suffix=@var{suffix}
5081 @opindex suffix
5082 @cindex backup suffix
5083 @vindex SIMPLE_BACKUP_SUFFIX
5084 Append @var{suffix} to each backup file made with @option{--backup}. If this
5085 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5086 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5087 set, the default is @samp{~}, just as in Emacs.
5088
5089 @end table
5090
5091 @node Applications
5092 @section Notable @command{tar} Usages
5093 @UNREVISED
5094
5095 @FIXME{Using Unix file linking capability to recreate directory
5096 structures---linking files into one subdirectory and then
5097 @command{tar}ring that directory.}
5098
5099 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5100
5101 @findex uuencode
5102 You can easily use archive files to transport a group of files from
5103 one system to another: put all relevant files into an archive on one
5104 computer system, transfer the archive to another system, and extract
5105 the contents there. The basic transfer medium might be magnetic tape,
5106 Internet FTP, or even electronic mail (though you must encode the
5107 archive with @command{uuencode} in order to transport it properly by
5108 mail). Both machines do not have to use the same operating system, as
5109 long as they both support the @command{tar} program.
5110
5111 For example, here is how you might copy a directory's contents from
5112 one disk to another, while preserving the dates, modes, owners and
5113 link-structure of all the files therein. In this case, the transfer
5114 medium is a @dfn{pipe}, which is one a Unix redirection mechanism:
5115
5116 @smallexample
5117 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5118 @end smallexample
5119
5120 @noindent
5121 You can avoid subshells by using @option{-C} option:
5122
5123 @smallexample
5124 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5125 @end smallexample
5126
5127 @noindent
5128 The command also works using short option forms:
5129
5130 @smallexample
5131 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5132 | (cd targetdir; tar --extract --file=-)}
5133 # Or:
5134 $ @kbd{tar --directory sourcedir --create --file=- . ) \
5135 | tar --directory targetdir --extract --file=-}
5136 @end smallexample
5137
5138 @noindent
5139 This is one of the easiest methods to transfer a @command{tar} archive.
5140
5141 @node looking ahead
5142 @section Looking Ahead: The Rest of this Manual
5143
5144 You have now seen how to use all eight of the operations available to
5145 @command{tar}, and a number of the possible options. The next chapter
5146 explains how to choose and change file and archive names, how to use
5147 files to store names of other files which you can then call as
5148 arguments to @command{tar} (this can help you save time if you expect to
5149 archive the same list of files a number of times), and so forth.
5150 @FIXME{in case it's not obvious, i'm making this up in some sense
5151 based on my limited memory of what the next chapter *really* does. i
5152 just wanted to flesh out this final section a little bit so i'd
5153 remember to stick it in here. :-)}
5154
5155 If there are too many files to conveniently list on the command line,
5156 you can list the names in a file, and @command{tar} will read that file.
5157 @xref{files}.
5158
5159 There are various ways of causing @command{tar} to skip over some files,
5160 and not archive them. @xref{Choosing}.
5161
5162 @node Backups
5163 @chapter Performing Backups and Restoring Files
5164 @UNREVISED
5165
5166 @GNUTAR{} is distributed along with the scripts
5167 which the Free Software Foundation uses for performing backups. There
5168 is no corresponding scripts available yet for doing restoration of
5169 files. Even if there is a good chance those scripts may be satisfying
5170 to you, they are not the only scripts or methods available for doing
5171 backups and restore. You may well create your own, or use more
5172 sophisticated packages dedicated to that purpose.
5173
5174 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5175 Automatic Network Disk Archiver), a backup system developed by James
5176 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5177 This is free software, and it is available at these places:
5178
5179 @smallexample
5180 http://www.cs.umd.edu/projects/amanda/amanda.html
5181 ftp://ftp.cs.umd.edu/pub/amanda
5182 @end smallexample
5183
5184 @FIXME{
5185
5186 Here is a possible plan for a future documentation about the backuping
5187 scripts which are provided within the @GNUTAR{}
5188 distribution.
5189
5190 @itemize @bullet
5191 @item dumps
5192 @itemize @minus
5193 @item what are dumps
5194 @item different levels of dumps
5195 @itemize +
5196 @item full dump = dump everything
5197 @item level 1, level 2 dumps etc
5198 A level @var{n} dump dumps everything changed since the last level
5199 @var{n}-1 dump (?)
5200 @end itemize
5201 @item how to use scripts for dumps (ie, the concept)
5202 @itemize +
5203 @item scripts to run after editing backup specs (details)
5204 @end itemize
5205 @item Backup Specs, what is it.
5206 @itemize +
5207 @item how to customize
5208 @item actual text of script [/sp/dump/backup-specs]
5209 @end itemize
5210 @item Problems
5211 @itemize +
5212 @item rsh doesn't work
5213 @item rtape isn't installed
5214 @item (others?)
5215 @end itemize
5216 @item the @option{--incremental} option of tar
5217 @item tapes
5218 @itemize +
5219 @item write protection
5220 @item types of media, different sizes and types, useful for different things
5221 @item files and tape marks
5222 one tape mark between files, two at end.
5223 @item positioning the tape
5224 MT writes two at end of write,
5225 backspaces over one when writing again.
5226 @end itemize
5227 @end itemize
5228 @end itemize
5229 }
5230
5231 This chapter documents both the provided shell scripts and @command{tar}
5232 options which are more specific to usage as a backup tool.
5233
5234 To @dfn{back up} a file system means to create archives that contain
5235 all the files in that file system. Those archives can then be used to
5236 restore any or all of those files (for instance if a disk crashes or a
5237 file is accidentally deleted). File system @dfn{backups} are also
5238 called @dfn{dumps}.
5239
5240 @menu
5241 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5242 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5243 * Backup Levels:: Levels of Backups
5244 * Backup Parameters:: Setting Parameters for Backups and Restoration
5245 * Scripted Backups:: Using the Backup Scripts
5246 * Scripted Restoration:: Using the Restore Script
5247 @end menu
5248
5249 @node Full Dumps
5250 @section Using @command{tar} to Perform Full Dumps
5251 @UNREVISED
5252
5253 @cindex full dumps
5254 @cindex dumps, full
5255
5256 @cindex corrupted archives
5257 Full dumps should only be made when no other people or programs
5258 are modifying files in the file system. If files are modified while
5259 @command{tar} is making the backup, they may not be stored properly in
5260 the archive, in which case you won't be able to restore them if you
5261 have to. (Files not being modified are written with no trouble, and do
5262 not corrupt the entire archive.)
5263
5264 You will want to use the @option{--label=@var{archive-label}}
5265 (@option{-V @var{archive-label}}) option to give the archive a
5266 volume label, so you can tell what this archive is even if the label
5267 falls off the tape, or anything like that.
5268
5269 Unless the file system you are dumping is guaranteed to fit on
5270 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5271 Make sure you have enough tapes on hand to complete the backup.
5272
5273 If you want to dump each file system separately you will need to use
5274 the @option{--one-file-system} option to prevent
5275 @command{tar} from crossing file system boundaries when storing
5276 (sub)directories.
5277
5278 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5279 option is not needed, since this is a complete copy of everything in
5280 the file system, and a full restore from this backup would only be
5281 done onto a completely
5282 empty disk.
5283
5284 Unless you are in a hurry, and trust the @command{tar} program (and your
5285 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5286 option, to make sure your files really made it onto the dump properly.
5287 This will also detect cases where the file was modified while (or just
5288 after) it was being archived. Not all media (notably cartridge tapes)
5289 are capable of being verified, unfortunately.
5290
5291 @node Incremental Dumps
5292 @section Using @command{tar} to Perform Incremental Dumps
5293
5294 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5295 stores additional metadata so that exact state of the file system
5296 can be restored when extracting the archive.
5297
5298 @GNUTAR{} currently offers two options for handling incremental
5299 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5300 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5301
5302 @opindex listed-incremental
5303 The option @option{--listed-incremental} instructs tar to operate on
5304 an incremental archive with additional metadata stored in a standalone
5305 file, called a @dfn{snapshot file}. The purpose of this file is to help
5306 determine which files have been changed, added or deleted since the
5307 last backup, so that the next incremental backup will contain only
5308 modified files. The name of the snapshot file is given as an argument
5309 to the option:
5310
5311 @table @option
5312 @item --listed-incremental=@var{file}
5313 @itemx -g @var{file}
5314 Handle incremental backups with snapshot data in @var{file}.
5315 @end table
5316
5317 To create an incremental backup, you would use
5318 @option{--listed-incremental} together with @option{--create}
5319 (@pxref{create}). For example:
5320
5321 @smallexample
5322 $ @kbd{tar --create \
5323 --file=archive.1.tar \
5324 --listed-incremental=/var/log/usr.snar \
5325 /usr}
5326 @end smallexample
5327
5328 This will create in @file{archive.1.tar} an incremental backup of
5329 the @file{/usr} file system, storing additional metadata in the file
5330 @file{/var/log/usr.snar}. If this file does not exist, it will be
5331 created. The created archive will then be a @dfn{level 0 backup};
5332 please see the next section for more on backup levels.
5333
5334 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5335 determines which files are modified. In this case only these files will be
5336 stored in the archive. Suppose, for example, that after running the
5337 above command, you delete file @file{/usr/doc/old} and create
5338 directory @file{/usr/local/db} with the following contents:
5339
5340 @smallexample
5341 $ @kbd{ls /usr/local/db}
5342 /usr/local/db/data
5343 /usr/local/db/index
5344 @end smallexample
5345
5346 Some time later you create another incremental backup. You will
5347 then see:
5348
5349 @smallexample
5350 $ @kbd{tar --create \
5351 --file=archive.2.tar \
5352 --listed-incremental=/var/log/usr.snar \
5353 /usr}
5354 tar: usr/local/db: Directory is new
5355 usr/local/db/
5356 usr/local/db/data
5357 usr/local/db/index
5358 @end smallexample
5359
5360 @noindent
5361 The created archive @file{archive.2.tar} will contain only these
5362 three members. This archive is called a @dfn{level 1 backup}. Notice
5363 that @file{/var/log/usr.snar} will be updated with the new data, so if
5364 you plan to create more @samp{level 1} backups, it is necessary to
5365 create a working copy of the snapshot file before running
5366 @command{tar}. The above example will then be modified as follows:
5367
5368 @smallexample
5369 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5370 $ @kbd{tar --create \
5371 --file=archive.2.tar \
5372 --listed-incremental=/var/log/usr.snar-1 \
5373 /usr}
5374 @end smallexample
5375
5376 Incremental dumps depend crucially on time stamps, so the results are
5377 unreliable if you modify a file's time stamps during dumping (e.g.,
5378 with the @option{--atime-preserve=replace} option), or if you set the clock
5379 backwards.
5380
5381 Metadata stored in snapshot files include device numbers, which,
5382 obviously is supposed to be a non-volatile value. However, it turns
5383 out that NFS devices have undependable values when an automounter
5384 gets in the picture. This can lead to a great deal of spurious
5385 redumping in incremental dumps, so it is somewhat useless to compare
5386 two NFS devices numbers over time. The solution implemented currently
5387 is to considers all NFS devices as being equal when it comes to
5388 comparing directories; this is fairly gross, but there does not seem
5389 to be a better way to go.
5390
5391 Note that incremental archives use @command{tar} extensions and may
5392 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
5393
5394 @xopindex{listed-incremental, using with @option{--extract}}
5395 @xopindex{extract, using with @option{--listed-incremental}}
5396 To extract from the incremental dumps, use
5397 @option{--listed-incremental} together with @option{--extract}
5398 option (@pxref{extracting files}). In this case, @command{tar} does
5399 not need to access snapshot file, since all the data necessary for
5400 extraction are stored in the archive itself. So, when extracting, you
5401 can give whatever argument to @option{--listed-incremental}, the usual
5402 practice is to use @option{--listed-incremental=/dev/null}.
5403 Alternatively, you can use @option{--incremental}, which needs no
5404 arguments. In general, @option{--incremental} (@option{-G}) can be
5405 used as a shortcut for @option{--listed-incremental} when listing or
5406 extracting incremental backups (for more information, regarding this
5407 option, @pxref{incremental-op}).
5408
5409 When extracting from the incremental backup @GNUTAR{} attempts to
5410 restore the exact state the file system had when the archive was
5411 created. In particular, it will @emph{delete} those files in the file
5412 system that did not exist in their directories when the archive was
5413 created. If you have created several levels of incremental files,
5414 then in order to restore the exact contents the file system had when
5415 the last level was created, you will need to restore from all backups
5416 in turn. Continuing our example, to restore the state of @file{/usr}
5417 file system, one would do@footnote{Notice, that since both archives
5418 were created without @option{-P} option (@pxref{absolute}), these
5419 commands should be run from the root file system.}:
5420
5421 @smallexample
5422 $ @kbd{tar --extract \
5423 --listed-incremental=/dev/null \
5424 --file archive.1.tar}
5425 $ @kbd{tar --extract \
5426 --listed-incremental=/dev/null \
5427 --file archive.2.tar}
5428 @end smallexample
5429
5430 To list the contents of an incremental archive, use @option{--list}
5431 (@pxref{list}), as usual. To obtain more information about the
5432 archive, use @option{--listed-incremental} or @option{--incremental}
5433 combined with two @option{--verbose} options@footnote{Two
5434 @option{--verbose} options were selected to avoid breaking usual
5435 verbose listing output (@option{--list --verbose}) when using in
5436 scripts.
5437
5438 @xopindex{incremental, using with @option{--list}}
5439 @xopindex{listed-incremental, using with @option{--list}}
5440 @xopindex{list, using with @option{--incremental}}
5441 @xopindex{list, using with @option{--listed-incremental}}
5442 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
5443 contents of the DUMPDIR header (with terminating nulls) when
5444 @option{--incremental} or @option{--listed-incremental} option was
5445 given, no matter what the verbosity level. This behavior, and,
5446 especially, the binary output it produced were considered inconvenient
5447 and were changed in version 1.16}:
5448
5449 @smallexample
5450 @kbd{tar --list --incremental --verbose --verbose archive.tar}
5451 @end smallexample
5452
5453 This command will print, for each directory in the archive, the list
5454 of files in that directory at the time the archive was created. This
5455 information is put out in a format which is both human-readable and
5456 unambiguous for a program: each file name is printed as
5457
5458 @smallexample
5459 @var{x} @var{file}
5460 @end smallexample
5461
5462 @noindent
5463 where @var{x} is a letter describing the status of the file: @samp{Y}
5464 if the file is present in the archive, @samp{N} if the file is not
5465 included in the archive, or a @samp{D} if the file is a directory (and
5466 is included in the archive). @xref{Dumpdir}, for the detailed
5467 description of dumpdirs and status codes. Each such
5468 line is terminated by a newline character. The last line is followed
5469 by an additional newline to indicate the end of the data.
5470
5471 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
5472 gives the same behavior as @option{--listed-incremental} when used
5473 with @option{--list} and @option{--extract} options. When used with
5474 @option{--create} option, it creates an incremental archive without
5475 creating snapshot file. Thus, it is impossible to create several
5476 levels of incremental backups with @option{--incremental} option.
5477
5478 @node Backup Levels
5479 @section Levels of Backups
5480
5481 An archive containing all the files in the file system is called a
5482 @dfn{full backup} or @dfn{full dump}. You could insure your data by
5483 creating a full dump every day. This strategy, however, would waste a
5484 substantial amount of archive media and user time, as unchanged files
5485 are daily re-archived.
5486
5487 It is more efficient to do a full dump only occasionally. To back up
5488 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
5489 one} dump archives all the files that have changed since the last full
5490 dump.
5491
5492 A typical dump strategy would be to perform a full dump once a week,
5493 and a level one dump once a day. This means some versions of files
5494 will in fact be archived more than once, but this dump strategy makes
5495 it possible to restore a file system to within one day of accuracy by
5496 only extracting two archives---the last weekly (full) dump and the
5497 last daily (level one) dump. The only information lost would be in
5498 files changed or created since the last daily backup. (Doing dumps
5499 more than once a day is usually not worth the trouble).
5500
5501 @GNUTAR{} comes with scripts you can use to do full
5502 and level-one (actually, even level-two and so on) dumps. Using
5503 scripts (shell programs) to perform backups and restoration is a
5504 convenient and reliable alternative to typing out file name lists
5505 and @command{tar} commands by hand.
5506
5507 Before you use these scripts, you need to edit the file
5508 @file{backup-specs}, which specifies parameters used by the backup
5509 scripts and by the restore script. This file is usually located
5510 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
5511 detailed description. Once the backup parameters are set, you can
5512 perform backups or restoration by running the appropriate script.
5513
5514 The name of the backup script is @code{backup}. The name of the
5515 restore script is @code{restore}. The following sections describe
5516 their use in detail.
5517
5518 @emph{Please Note:} The backup and restoration scripts are
5519 designed to be used together. While it is possible to restore files by
5520 hand from an archive which was created using a backup script, and to create
5521 an archive by hand which could then be extracted using the restore script,
5522 it is easier to use the scripts. @xref{Incremental Dumps}, before
5523 making such an attempt.
5524
5525 @node Backup Parameters
5526 @section Setting Parameters for Backups and Restoration
5527
5528 The file @file{backup-specs} specifies backup parameters for the
5529 backup and restoration scripts provided with @command{tar}. You must
5530 edit @file{backup-specs} to fit your system configuration and schedule
5531 before using these scripts.
5532
5533 Syntactically, @file{backup-specs} is a shell script, containing
5534 mainly variable assignments. However, any valid shell construct
5535 is allowed in this file. Particularly, you may wish to define
5536 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
5537 For more information about shell script syntax, please refer to
5538 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5539 g_02, the definition of the Shell Command Language}. See also
5540 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
5541
5542 The shell variables controlling behavior of @code{backup} and
5543 @code{restore} are described in the following subsections.
5544
5545 @menu
5546 * General-Purpose Variables::
5547 * Magnetic Tape Control::
5548 * User Hooks::
5549 * backup-specs example:: An Example Text of @file{Backup-specs}
5550 @end menu
5551
5552 @node General-Purpose Variables
5553 @subsection General-Purpose Variables
5554
5555 @defvr {Backup variable} ADMINISTRATOR
5556 The user name of the backup administrator. @code{Backup} scripts
5557 sends a backup report to this address.
5558 @end defvr
5559
5560 @defvr {Backup variable} BACKUP_HOUR
5561 The hour at which the backups are done. This can be a number from 0
5562 to 23, or the time specification in form @var{hours}:@var{minutes},
5563 or the string @samp{now}.
5564
5565 This variable is used by @code{backup}. Its value may be overridden
5566 using @option{--time} option (@pxref{Scripted Backups}).
5567 @end defvr
5568
5569 @defvr {Backup variable} TAPE_FILE
5570
5571 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
5572 is a remote archive (@pxref{remote-dev}), backup script will suppose
5573 that your @command{mt} is able to access remote devices. If @var{RSH}
5574 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
5575 invocations of @command{mt}.
5576 @end defvr
5577
5578 @defvr {Backup variable} BLOCKING
5579
5580 The blocking factor @command{tar} will use when writing the dump archive.
5581 @xref{Blocking Factor}.
5582 @end defvr
5583
5584 @defvr {Backup variable} BACKUP_DIRS
5585
5586 A list of file systems to be dumped (for @code{backup}), or restored
5587 (for @code{restore}). You can include any directory
5588 name in the list --- subdirectories on that file system will be
5589 included, regardless of how they may look to other networked machines.
5590 Subdirectories on other file systems will be ignored.
5591
5592 The host name specifies which host to run @command{tar} on, and should
5593 normally be the host that actually contains the file system. However,
5594 the host machine must have @GNUTAR{} installed, and
5595 must be able to access the directory containing the backup scripts and
5596 their support files using the same file name that is used on the
5597 machine where the scripts are run (i.e., what @command{pwd} will print
5598 when in that directory on that machine). If the host that contains
5599 the file system does not have this capability, you can specify another
5600 host as long as it can access the file system through NFS.
5601
5602 If the list of file systems is very long you may wish to put it
5603 in a separate file. This file is usually named
5604 @file{/etc/backup/dirs}, but this name may be overridden in
5605 @file{backup-specs} using @code{DIRLIST} variable.
5606 @end defvr
5607
5608 @defvr {Backup variable} DIRLIST
5609
5610 A path to the file containing the list of the file systems to backup
5611 or restore. By default it is @file{/etc/backup/dirs}.
5612 @end defvr
5613
5614 @defvr {Backup variable} BACKUP_FILES
5615
5616 A list of individual files to be dumped (for @code{backup}), or restored
5617 (for @code{restore}). These should be accessible from the machine on
5618 which the backup script is run.
5619
5620 If the list of file systems is very long you may wish to store it
5621 in a separate file. This file is usually named
5622 @file{/etc/backup/files}, but this name may be overridden in
5623 @file{backup-specs} using @code{FILELIST} variable.
5624 @end defvr
5625
5626 @defvr {Backup variable} FILELIST
5627
5628 A path to the file containing the list of the individual files to backup
5629 or restore. By default it is @file{/etc/backup/files}.
5630 @end defvr
5631
5632 @defvr {Backup variable} MT
5633
5634 Full file name of @command{mt} binary.
5635 @end defvr
5636
5637 @defvr {Backup variable} RSH
5638 @anchor{RSH}
5639 Full file name of @command{rsh} binary or its equivalent. You may wish to
5640 set it to @code{ssh}, to improve security. In this case you will have
5641 to use public key authentication.
5642 @end defvr
5643
5644 @defvr {Backup variable} RSH_COMMAND
5645
5646 Full file name of @command{rsh} binary on remote machines. This will
5647 be passed via @option{--rsh-command} option to the remote invocation
5648 of @GNUTAR{}.
5649 @end defvr
5650
5651 @defvr {Backup variable} VOLNO_FILE
5652
5653 Name of temporary file to hold volume numbers. This needs to be accessible
5654 by all the machines which have file systems to be dumped.
5655 @end defvr
5656
5657 @defvr {Backup variable} XLIST
5658
5659 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
5660 located on the remote machine and containing the list of files to
5661 be excluded from the backup. Exclude file lists are searched in
5662 /etc/tar-backup directory. A common use for exclude file lists
5663 is to exclude files containing security-sensitive information
5664 (e.g., @file{/etc/shadow} from backups).
5665
5666 This variable affects only @code{backup}.
5667 @end defvr
5668
5669 @defvr {Backup variable} SLEEP_TIME
5670
5671 Time to sleep between dumps of any two successive file systems
5672
5673 This variable affects only @code{backup}.
5674 @end defvr
5675
5676 @defvr {Backup variable} DUMP_REMIND_SCRIPT
5677
5678 Script to be run when it's time to insert a new tape in for the next
5679 volume. Administrators may want to tailor this script for their site.
5680 If this variable isn't set, @GNUTAR{} will display its built-in
5681 prompt, and will expect confirmation from the console. For the
5682 description of the default prompt, see @ref{change volume prompt}.
5683
5684 @end defvr
5685
5686 @defvr {Backup variable} SLEEP_MESSAGE
5687
5688 Message to display on the terminal while waiting for dump time. Usually
5689 this will just be some literal text.
5690 @end defvr
5691
5692 @defvr {Backup variable} TAR
5693
5694 Full file name of the @GNUTAR{} executable. If this is not set, backup
5695 scripts will search @command{tar} in the current shell path.
5696 @end defvr
5697
5698 @node Magnetic Tape Control
5699 @subsection Magnetic Tape Control
5700
5701 Backup scripts access tape device using special @dfn{hook functions}.
5702 These functions take a single argument -- the name of the tape
5703 device. Their names are kept in the following variables:
5704
5705 @defvr {Backup variable} MT_BEGIN
5706 The name of @dfn{begin} function. This function is called before
5707 accessing the drive. By default it retensions the tape:
5708
5709 @smallexample
5710 MT_BEGIN=mt_begin
5711
5712 mt_begin() @{
5713 mt -f "$1" retension
5714 @}
5715 @end smallexample
5716 @end defvr
5717
5718 @defvr {Backup variable} MT_REWIND
5719 The name of @dfn{rewind} function. The default definition is as
5720 follows:
5721
5722 @smallexample
5723 MT_REWIND=mt_rewind
5724
5725 mt_rewind() @{
5726 mt -f "$1" rewind
5727 @}
5728 @end smallexample
5729
5730 @end defvr
5731
5732 @defvr {Backup variable} MT_OFFLINE
5733 The name of the function switching the tape off line. By default
5734 it is defined as follows:
5735
5736 @smallexample
5737 MT_OFFLINE=mt_offline
5738
5739 mt_offline() @{
5740 mt -f "$1" offl
5741 @}
5742 @end smallexample
5743 @end defvr
5744
5745 @defvr {Backup variable} MT_STATUS
5746 The name of the function used to obtain the status of the archive device,
5747 including error count. Default definition:
5748
5749 @smallexample
5750 MT_STATUS=mt_status
5751
5752 mt_status() @{
5753 mt -f "$1" status
5754 @}
5755 @end smallexample
5756 @end defvr
5757
5758 @node User Hooks
5759 @subsection User Hooks
5760
5761 @dfn{User hooks} are shell functions executed before and after
5762 each @command{tar} invocation. Thus, there are @dfn{backup
5763 hooks}, which are executed before and after dumping each file
5764 system, and @dfn{restore hooks}, executed before and
5765 after restoring a file system. Each user hook is a shell function
5766 taking four arguments:
5767
5768 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
5769 Its arguments are:
5770
5771 @table @var
5772 @item level
5773 Current backup or restore level.
5774
5775 @item host
5776 Name or IP address of the host machine being dumped or restored.
5777
5778 @item fs
5779 Full path name to the file system being dumped or restored.
5780
5781 @item fsname
5782 File system name with directory separators replaced with colons. This
5783 is useful, e.g., for creating unique files.
5784 @end table
5785 @end deffn
5786
5787 Following variables keep the names of user hook functions
5788
5789 @defvr {Backup variable} DUMP_BEGIN
5790 Dump begin function. It is executed before dumping the file system.
5791 @end defvr
5792
5793 @defvr {Backup variable} DUMP_END
5794 Executed after dumping the file system.
5795 @end defvr
5796
5797 @defvr {Backup variable} RESTORE_BEGIN
5798 Executed before restoring the file system.
5799 @end defvr
5800
5801 @defvr {Backup variable} RESTORE_END
5802 Executed after restoring the file system.
5803 @end defvr
5804
5805 @node backup-specs example
5806 @subsection An Example Text of @file{Backup-specs}
5807
5808 The following is an example of @file{backup-specs}:
5809
5810 @smallexample
5811 # site-specific parameters for file system backup.
5812
5813 ADMINISTRATOR=friedman
5814 BACKUP_HOUR=1
5815 TAPE_FILE=/dev/nrsmt0
5816
5817 # Use @code{ssh} instead of the less secure @code{rsh}
5818 RSH=/usr/bin/ssh
5819 RSH_COMMAND=/usr/bin/ssh
5820
5821 # Override MT_STATUS function:
5822 my_status() @{
5823 mts -t $TAPE_FILE
5824 @}
5825 MT_STATUS=my_status
5826
5827 # Disable MT_OFFLINE function
5828 MT_OFFLINE=:
5829
5830 BLOCKING=124
5831 BACKUP_DIRS="
5832 albert:/fs/fsf
5833 apple-gunkies:/gd
5834 albert:/fs/gd2
5835 albert:/fs/gp
5836 geech:/usr/jla
5837 churchy:/usr/roland
5838 albert:/
5839 albert:/usr
5840 apple-gunkies:/
5841 apple-gunkies:/usr
5842 gnu:/hack
5843 gnu:/u
5844 apple-gunkies:/com/mailer/gnu
5845 apple-gunkies:/com/archive/gnu"
5846
5847 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5848
5849 @end smallexample
5850
5851 @node Scripted Backups
5852 @section Using the Backup Scripts
5853
5854 The syntax for running a backup script is:
5855
5856 @smallexample
5857 backup --level=@var{level} --time=@var{time}
5858 @end smallexample
5859
5860 The @option{level} option requests the dump level. Thus, to produce
5861 a full dump, specify @code{--level=0} (this is the default, so
5862 @option{--level} may be omitted if its value is @code{0}).
5863 @footnote{For backward compatibility, the @code{backup} will also
5864 try to deduce the requested dump level from the name of the
5865 script itself. If the name consists of a string @samp{level-}
5866 followed by a single decimal digit, that digit is taken as
5867 the dump level number. Thus, you may create a link from @code{backup}
5868 to @code{level-1} and then run @code{level-1} whenever you need to
5869 create a level one dump.}
5870
5871 The @option{--time} option determines when should the backup be
5872 run. @var{Time} may take three forms:
5873
5874 @table @asis
5875 @item @var{hh}:@var{mm}
5876
5877 The dump must be run at @var{hh} hours @var{mm} minutes.
5878
5879 @item @var{hh}
5880
5881 The dump must be run at @var{hh} hours
5882
5883 @item now
5884
5885 The dump must be run immediately.
5886 @end table
5887
5888 You should start a script with a tape or disk mounted. Once you
5889 start a script, it prompts you for new tapes or disks as it
5890 needs them. Media volumes don't have to correspond to archive
5891 files --- a multi-volume archive can be started in the middle of a
5892 tape that already contains the end of another multi-volume archive.
5893 The @code{restore} script prompts for media by its archive volume,
5894 so to avoid an error message you should keep track of which tape
5895 (or disk) contains which volume of the archive (@pxref{Scripted
5896 Restoration}).
5897
5898 The backup scripts write two files on the file system. The first is a
5899 record file in @file{/etc/tar-backup/}, which is used by the scripts
5900 to store and retrieve information about which files were dumped. This
5901 file is not meant to be read by humans, and should not be deleted by
5902 them. @xref{Snapshot Files}, for a more detailed explanation of this
5903 file.
5904
5905 The second file is a log file containing the names of the file systems
5906 and files dumped, what time the backup was made, and any error
5907 messages that were generated, as well as how much space was left in
5908 the media volume after the last volume of the archive was written.
5909 You should check this log file after every backup. The file name is
5910 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
5911 represents current date, and @var{n} represents current dump level number.
5912
5913 The script also prints the name of each system being dumped to the
5914 standard output.
5915
5916 Following is the full list of options accepted by @code{backup}
5917 script:
5918
5919 @table @option
5920 @item -l @var{level}
5921 @itemx --level=@var{level}
5922 Do backup level @var{level} (default 0).
5923
5924 @item -f
5925 @itemx --force
5926 Force backup even if today's log file already exists.
5927
5928 @item -v[@var{level}]
5929 @itemx --verbose[=@var{level}]
5930 Set verbosity level. The higher the level is, the more debugging
5931 information will be output during execution. Default @var{level}
5932 is 100, which means the highest debugging level.
5933
5934 @item -t @var{start-time}
5935 @itemx --time=@var{start-time}
5936 Wait till @var{time}, then do backup.
5937
5938 @item -h
5939 @itemx --help
5940 Display short help message and exit.
5941
5942 @item -V
5943 @itemx --version
5944 Display information about the program's name, version, origin and legal
5945 status, all on standard output, and then exit successfully.
5946 @end table
5947
5948
5949 @node Scripted Restoration
5950 @section Using the Restore Script
5951
5952 To restore files that were archived using a scripted backup, use the
5953 @code{restore} script. Its usage is quite straightforward. In the
5954 simplest form, invoke @code{restore --all}, it will
5955 then restore all the file systems and files specified in
5956 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
5957
5958 You may select the file systems (and/or files) to restore by
5959 giving @code{restore} list of @dfn{patterns} in its command
5960 line. For example, running
5961
5962 @smallexample
5963 restore 'albert:*'
5964 @end smallexample
5965
5966 @noindent
5967 will restore all file systems on the machine @samp{albert}. A more
5968 complicated example:
5969
5970 @smallexample
5971 restore 'albert:*' '*:/var'
5972 @end smallexample
5973
5974 @noindent
5975 This command will restore all file systems on the machine @samp{albert}
5976 as well as @file{/var} file system on all machines.
5977
5978 By default @code{restore} will start restoring files from the lowest
5979 available dump level (usually zero) and will continue through
5980 all available dump levels. There may be situations where such a
5981 thorough restore is not necessary. For example, you may wish to
5982 restore only files from the recent level one backup. To do so,
5983 use @option{--level} option, as shown in the example below:
5984
5985 @smallexample
5986 restore --level=1
5987 @end smallexample
5988
5989 The full list of options accepted by @code{restore} follows:
5990
5991 @table @option
5992 @item -a
5993 @itemx --all
5994 Restore all file systems and files specified in @file{backup-specs}
5995
5996 @item -l @var{level}
5997 @itemx --level=@var{level}
5998 Start restoring from the given backup level, instead of the default 0.
5999
6000 @item -v[@var{level}]
6001 @itemx --verbose[=@var{level}]
6002 Set verbosity level. The higher the level is, the more debugging
6003 information will be output during execution. Default @var{level}
6004 is 100, which means the highest debugging level.
6005
6006 @item -h
6007 @itemx --help
6008 Display short help message and exit.
6009
6010 @item -V
6011 @itemx --version
6012 Display information about the program's name, version, origin and legal
6013 status, all on standard output, and then exit successfully.
6014 @end table
6015
6016 You should start the restore script with the media containing the
6017 first volume of the archive mounted. The script will prompt for other
6018 volumes as they are needed. If the archive is on tape, you don't need
6019 to rewind the tape to to its beginning---if the tape head is
6020 positioned past the beginning of the archive, the script will rewind
6021 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6022 positioning.
6023
6024 @quotation
6025 @strong{Warning:} The script will delete files from the active file
6026 system if they were not in the file system when the archive was made.
6027 @end quotation
6028
6029 @xref{Incremental Dumps}, for an explanation of how the script makes
6030 that determination.
6031
6032 @node Choosing
6033 @chapter Choosing Files and Names for @command{tar}
6034 @UNREVISED
6035
6036 Certain options to @command{tar} enable you to specify a name for your
6037 archive. Other options let you decide which files to include or exclude
6038 from the archive, based on when or whether files were modified, whether
6039 the file names do or don't match specified patterns, or whether files
6040 are in specified directories.
6041
6042 This chapter discusses these options in detail.
6043
6044 @menu
6045 * file:: Choosing the Archive's Name
6046 * Selecting Archive Members::
6047 * files:: Reading Names from a File
6048 * exclude:: Excluding Some Files
6049 * wildcards:: Wildcards Patterns and Matching
6050 * quoting styles:: Ways of Quoting Special Characters in Names
6051 * transform:: Modifying File and Member Names
6052 * after:: Operating Only on New Files
6053 * recurse:: Descending into Directories
6054 * one:: Crossing File System Boundaries
6055 @end menu
6056
6057 @node file
6058 @section Choosing and Naming Archive Files
6059 @UNREVISED
6060
6061 @cindex Naming an archive
6062 @cindex Archive Name
6063 @cindex Choosing an archive file
6064 @cindex Where is the archive?
6065 By default, @command{tar} uses an archive file name that was compiled when
6066 it was built on the system; usually this name refers to some physical
6067 tape drive on the machine. However, the person who installed @command{tar}
6068 on the system may not have set the default to a meaningful value as far as
6069 most users are concerned. As a result, you will usually want to tell
6070 @command{tar} where to find (or create) the archive. The
6071 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6072 option allows you to either specify or name a file to use as the archive
6073 instead of the default archive file location.
6074
6075 @table @option
6076 @xopindex{file, short description}
6077 @item --file=@var{archive-name}
6078 @itemx -f @var{archive-name}
6079 Name the archive to create or operate on. Use in conjunction with
6080 any operation.
6081 @end table
6082
6083 For example, in this @command{tar} command,
6084
6085 @smallexample
6086 $ @kbd{tar -cvf collection.tar blues folk jazz}
6087 @end smallexample
6088
6089 @noindent
6090 @file{collection.tar} is the name of the archive. It must directly
6091 follow the @option{-f} option, since whatever directly follows @option{-f}
6092 @emph{will} end up naming the archive. If you neglect to specify an
6093 archive name, you may end up overwriting a file in the working directory
6094 with the archive you create since @command{tar} will use this file's name
6095 for the archive name.
6096
6097 An archive can be saved as a file in the file system, sent through a
6098 pipe or over a network, or written to an I/O device such as a tape,
6099 floppy disk, or CD write drive.
6100
6101 @cindex Writing new archives
6102 @cindex Archive creation
6103 If you do not name the archive, @command{tar} uses the value of the
6104 environment variable @env{TAPE} as the file name for the archive. If
6105 that is not available, @command{tar} uses a default, compiled-in archive
6106 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6107
6108 @cindex Standard input and output
6109 @cindex tar to standard input and output
6110 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6111 archive from standard input (when listing or extracting files), or
6112 writes it to standard output (when creating an archive). If you use
6113 @file{-} as an @var{archive-name} when modifying an archive,
6114 @command{tar} reads the original archive from its standard input and
6115 writes the entire new archive to its standard output.
6116
6117 The following example is a convenient way of copying directory
6118 hierarchy from @file{sourcedir} to @file{targetdir}.
6119
6120 @smallexample
6121 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6122 @end smallexample
6123
6124 The @option{-C} option allows to avoid using subshells:
6125
6126 @smallexample
6127 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6128 @end smallexample
6129
6130 In both examples above, the leftmost @command{tar} invocation archives
6131 the contents of @file{sourcedir} to the standard output, while the
6132 rightmost one reads this archive from its standard input and
6133 extracts it. The @option{-p} option tells it to restore permissions
6134 of the extracted files.
6135
6136 @cindex Remote devices
6137 @cindex tar to a remote device
6138 @anchor{remote-dev}
6139 To specify an archive file on a device attached to a remote machine,
6140 use the following:
6141
6142 @smallexample
6143 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6144 @end smallexample
6145
6146 @noindent
6147 @command{tar} will complete the remote connection, if possible, and
6148 prompt you for a username and password. If you use
6149 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6150 will complete the remote connection, if possible, using your username
6151 as the username on the remote machine.
6152
6153 @cindex Local and remote archives
6154 @anchor{local and remote archives}
6155 If the archive file name includes a colon (@samp{:}), then it is assumed
6156 to be a file on another machine. If the archive file is
6157 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6158 host @var{host}. The remote host is accessed using the @command{rsh}
6159 program, with a username of @var{user}. If the username is omitted
6160 (along with the @samp{@@} sign), then your user name will be used.
6161 (This is the normal @command{rsh} behavior.) It is necessary for the
6162 remote machine, in addition to permitting your @command{rsh} access, to
6163 have the @file{rmt} program installed (This command is included in
6164 the @GNUTAR{} distribution and by default is installed under
6165 @file{@var{prefix}/libexec/rmt}, were @var{prefix} means your
6166 installation prefix). If you need to use a file whose name includes a
6167 colon, then the remote tape drive behavior
6168 can be inhibited by using the @option{--force-local} option.
6169
6170 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6171 tries to minimize input and output operations. The Amanda backup
6172 system, when used with @GNUTAR{}, has an initial sizing pass which
6173 uses this feature.
6174
6175 @node Selecting Archive Members
6176 @section Selecting Archive Members
6177 @cindex Specifying files to act on
6178 @cindex Specifying archive members
6179
6180 @dfn{File Name arguments} specify which files in the file system
6181 @command{tar} operates on, when creating or adding to an archive, or which
6182 archive members @command{tar} operates on, when reading or deleting from
6183 an archive. @xref{Operations}.
6184
6185 To specify file names, you can include them as the last arguments on
6186 the command line, as follows:
6187 @smallexample
6188 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6189 @end smallexample
6190
6191 If a file name begins with dash (@samp{-}), precede it with
6192 @option{--add-file} option to prevent it from being treated as an
6193 option.
6194
6195 @anchor{input name quoting}
6196 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6197 name, replacing @dfn{escape sequences} according to the following
6198 table:
6199
6200 @multitable @columnfractions 0.20 0.60
6201 @headitem Escape @tab Replaced with
6202 @item \a @tab Audible bell (ASCII 7)
6203 @item \b @tab Backspace (ASCII 8)
6204 @item \f @tab Form feed (ASCII 12)
6205 @item \n @tab New line (ASCII 10)
6206 @item \r @tab Carriage return (ASCII 13)
6207 @item \t @tab Horizontal tabulation (ASCII 9)
6208 @item \v @tab Vertical tabulation (ASCII 11)
6209 @item \? @tab ASCII 127
6210 @item \@var{n} @tab ASCII @var{n} (@var{n} should be an octal number
6211 of up to 3 digits)
6212 @end multitable
6213
6214 A backslash followed by any other symbol is retained.
6215
6216 This default behavior is controlled by the following command line
6217 option:
6218
6219 @table @option
6220 @opindex unquote
6221 @item --unquote
6222 Enable unquoting input file or member names (default).
6223
6224 @opindex no-unquote
6225 @item --no-unquote
6226 Disable unquoting input file or member names.
6227 @end table
6228
6229 If you specify a directory name as a file name argument, all the files
6230 in that directory are operated on by @command{tar}.
6231
6232 If you do not specify files, @command{tar} behavior differs depending
6233 on the operation mode as described below:
6234
6235 When @command{tar} is invoked with @option{--create} (@option{-c}),
6236 @command{tar} will stop immediately, reporting the following:
6237
6238 @smallexample
6239 @group
6240 $ @kbd{tar cf a.tar}
6241 tar: Cowardly refusing to create an empty archive
6242 Try `tar --help' or `tar --usage' for more information.
6243 @end group
6244 @end smallexample
6245
6246 If you specify either @option{--list} (@option{-t}) or
6247 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6248 operates on all the archive members in the archive.
6249
6250 If run with @option{--diff} option, tar will compare the archive with
6251 the contents of the current working directory.
6252
6253 If you specify any other operation, @command{tar} does nothing.
6254
6255 By default, @command{tar} takes file names from the command line. However,
6256 there are other ways to specify file or member names, or to modify the
6257 manner in which @command{tar} selects the files or members upon which to
6258 operate. In general, these methods work both for specifying the names
6259 of files and archive members.
6260
6261 @node files
6262 @section Reading Names from a File
6263
6264 @cindex Reading file names from a file
6265 @cindex Lists of file names
6266 @cindex File Name arguments, alternatives
6267 Instead of giving the names of files or archive members on the command
6268 line, you can put the names into a file, and then use the
6269 @option{--files-from=@var{file-of-names}} (@option{-T
6270 @var{file-of-names}}) option to @command{tar}. Give the name of the
6271 file which contains the list of files to include as the argument to
6272 @option{--files-from}. In the list, the file names should be separated by
6273 newlines. You will frequently use this option when you have generated
6274 the list of files to archive with the @command{find} utility.
6275
6276 @table @option
6277 @opindex files-from
6278 @item --files-from=@var{file-name}
6279 @itemx -T @var{file-name}
6280 Get names to extract or create from file @var{file-name}.
6281 @end table
6282
6283 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6284 you specify either @code{--files-from=-} or @code{-T -}), then the file
6285 names are read from standard input.
6286
6287 Unless you are running @command{tar} with @option{--create}, you can not use
6288 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6289 command.
6290
6291 Any number of @option{-T} options can be given in the command line.
6292
6293 The following example shows how to use @command{find} to generate a list of
6294 files smaller than 400K in length and put that list into a file
6295 called @file{small-files}. You can then use the @option{-T} option to
6296 @command{tar} to specify the files from that file, @file{small-files}, to
6297 create the archive @file{little.tgz}. (The @option{-z} option to
6298 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6299 more information.)
6300
6301 @smallexample
6302 $ @kbd{find . -size -400 -print > small-files}
6303 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6304 @end smallexample
6305
6306 @noindent
6307 In the file list given by @option{-T} option, any file name beginning
6308 with @samp{-} character is considered a @command{tar} option and is
6309 processed accordingly.@footnote{Versions of @GNUTAR{} up to 1.15.1
6310 recognized only @option{-C} option in file lists, and only if the
6311 option and its argument occupied two consecutive lines.} For example,
6312 the common use of this feature is to change to another directory by
6313 specifying @option{-C} option:
6314
6315 @smallexample
6316 @group
6317 $ @kbd{cat list}
6318 -C/etc
6319 passwd
6320 hosts
6321 -C/lib
6322 libc.a
6323 $ @kbd{tar -c -f foo.tar --files-from list}
6324 @end group
6325 @end smallexample
6326
6327 @noindent
6328 In this example, @command{tar} will first switch to @file{/etc}
6329 directory and add files @file{passwd} and @file{hosts} to the
6330 archive. Then it will change to @file{/lib} directory and will archive
6331 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6332 contain:
6333
6334 @smallexample
6335 @group
6336 $ @kbd{tar tf foo.tar}
6337 passwd
6338 hosts
6339 libc.a
6340 @end group
6341 @end smallexample
6342
6343 @noindent
6344 @xopindex{directory, using in @option{--files-from} argument}
6345 Notice that the option parsing algorithm used with @option{-T} is
6346 stricter than the one used by shell. Namely, when specifying option
6347 arguments, you should observe the following rules:
6348
6349 @itemize @bullet
6350 @item
6351 When using short (single-letter) option form, its argument must
6352 immediately follow the option letter, without any intervening
6353 whitespace. For example: @code{-Cdir}.
6354
6355 @item
6356 When using long option form, the option argument must be separated
6357 from the option by a single equal sign. No whitespace is allowed on
6358 any side of the equal sign. For example: @code{--directory=dir}.
6359
6360 @item
6361 For both short and long option forms, the option argument can be given
6362 on the next line after the option name, e.g.:
6363
6364 @smallexample
6365 @group
6366 --directory
6367 dir
6368 @end group
6369 @end smallexample
6370
6371 @noindent
6372 and
6373
6374 @smallexample
6375 @group
6376 -C
6377 dir
6378 @end group
6379 @end smallexample
6380 @end itemize
6381
6382 @opindex add-file
6383 If you happen to have a file whose name starts with @samp{-},
6384 precede it with @option{--add-file} option to prevent it from
6385 being recognized as an option. For example: @code{--add-file=--my-file}.
6386
6387 @menu
6388 * nul::
6389 @end menu
6390
6391 @node nul
6392 @subsection @code{NUL} Terminated File Names
6393
6394 @cindex File names, terminated by @code{NUL}
6395 @cindex @code{NUL} terminated file names
6396 The @option{--null} option causes
6397 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
6398 to read file names terminated by a @code{NUL} instead of a newline, so
6399 files whose names contain newlines can be archived using
6400 @option{--files-from}.
6401
6402 @table @option
6403 @opindex null
6404 @item --null
6405 Only consider @code{NUL} terminated file names, instead of files that
6406 terminate in a newline.
6407 @end table
6408
6409 The @option{--null} option is just like the one in @acronym{GNU}
6410 @command{xargs} and @command{cpio}, and is useful with the
6411 @option{-print0} predicate of @acronym{GNU} @command{find}. In
6412 @command{tar}, @option{--null} also disables special handling for
6413 file names that begin with dash.
6414
6415 This example shows how to use @command{find} to generate a list of files
6416 larger than 800K in length and put that list into a file called
6417 @file{long-files}. The @option{-print0} option to @command{find} is just
6418 like @option{-print}, except that it separates files with a @code{NUL}
6419 rather than with a newline. You can then run @command{tar} with both the
6420 @option{--null} and @option{-T} options to specify that @command{tar} get the
6421 files from that file, @file{long-files}, to create the archive
6422 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
6423 @command{tar} to recognize the @code{NUL} separator between files.
6424
6425 @smallexample
6426 $ @kbd{find . -size +800 -print0 > long-files}
6427 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
6428 @end smallexample
6429
6430 @FIXME{say anything else here to conclude the section?}
6431
6432 @node exclude
6433 @section Excluding Some Files
6434 @UNREVISED
6435
6436 @cindex File names, excluding files by
6437 @cindex Excluding files by name and pattern
6438 @cindex Excluding files by file system
6439 To avoid operating on files whose names match a particular pattern,
6440 use the @option{--exclude} or @option{--exclude-from} options.
6441
6442 @table @option
6443 @opindex exclude
6444 @item --exclude=@var{pattern}
6445 Causes @command{tar} to ignore files that match the @var{pattern}.
6446 @end table
6447
6448 @findex exclude
6449 The @option{--exclude=@var{pattern}} option prevents any file or
6450 member whose name matches the shell wildcard (@var{pattern}) from
6451 being operated on.
6452 For example, to create an archive with all the contents of the directory
6453 @file{src} except for files whose names end in @file{.o}, use the
6454 command @samp{tar -cf src.tar --exclude='*.o' src}.
6455
6456 You may give multiple @option{--exclude} options.
6457
6458 @table @option
6459 @opindex exclude-from
6460 @item --exclude-from=@var{file}
6461 @itemx -X @var{file}
6462 Causes @command{tar} to ignore files that match the patterns listed in
6463 @var{file}.
6464 @end table
6465
6466 @findex exclude-from
6467 Use the @option{--exclude-from} option to read a
6468 list of patterns, one per line, from @var{file}; @command{tar} will
6469 ignore files matching those patterns. Thus if @command{tar} is
6470 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
6471 single line @file{*.o}, no files whose names end in @file{.o} will be
6472 added to the archive.
6473
6474 @table @option
6475 @opindex exclude-caches
6476 @item --exclude-caches
6477 Causes @command{tar} to ignore directories containing a cache directory tag.
6478 @end table
6479
6480 @findex exclude-caches
6481 When creating an archive, the @option{--exclude-caches} option causes
6482 @command{tar} to exclude all directories that contain a @dfn{cache
6483 directory tag}. A cache directory tag is a short file with the
6484 well-known name @file{CACHEDIR.TAG} and having a standard header
6485 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
6486 Various applications write cache directory tags into directories they
6487 use to hold regenerable, non-precious data, so that such data can be
6488 more easily excluded from backups.
6489
6490 @menu
6491 * problems with exclude::
6492 @end menu
6493
6494 @node problems with exclude
6495 @unnumberedsubsec Problems with Using the @code{exclude} Options
6496
6497 @xopindex{exclude, potential problems with}
6498 Some users find @samp{exclude} options confusing. Here are some common
6499 pitfalls:
6500
6501 @itemize @bullet
6502 @item
6503 The main operating mode of @command{tar} does not act on a path name
6504 explicitly listed on the command line if one of its file name
6505 components is excluded. In the example above, if
6506 you create an archive and exclude files that end with @samp{*.o}, but
6507 explicitly name the file @samp{dir.o/foo} after all the options have been
6508 listed, @samp{dir.o/foo} will be excluded from the archive.
6509
6510 @item
6511 You can sometimes confuse the meanings of @option{--exclude} and
6512 @option{--exclude-from}. Be careful: use @option{--exclude} when files
6513 to be excluded are given as a pattern on the command line. Use
6514 @option{--exclude-from} to introduce the name of a file which contains
6515 a list of patterns, one per line; each of these patterns can exclude
6516 zero, one, or many files.
6517
6518 @item
6519 When you use @option{--exclude=@var{pattern}}, be sure to quote the
6520 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
6521 like @samp{*}. If you do not do this, the shell might expand the
6522 @samp{*} itself using files at hand, so @command{tar} might receive a
6523 list of files instead of one pattern, or none at all, making the
6524 command somewhat illegal. This might not correspond to what you want.
6525
6526 For example, write:
6527
6528 @smallexample
6529 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
6530 @end smallexample
6531
6532 @noindent
6533 rather than:
6534
6535 @smallexample
6536 # @emph{Wrong!}
6537 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
6538 @end smallexample
6539
6540 @item
6541 You must use use shell syntax, or globbing, rather than @code{regexp}
6542 syntax, when using exclude options in @command{tar}. If you try to use
6543 @code{regexp} syntax to describe files to be excluded, your command
6544 might fail.
6545
6546 @item
6547 @FIXME{The change in semantics must have occurred before 1.11,
6548 so I doubt if it is worth mentioning at all. Anyway, should at
6549 least specify in which version the semantics changed.}
6550 In earlier versions of @command{tar}, what is now the
6551 @option{--exclude-from} option was called @option{--exclude} instead.
6552 Now, @option{--exclude} applies to patterns listed on the command
6553 line and @option{--exclude-from} applies to patterns listed in a
6554 file.
6555
6556 @end itemize
6557
6558 @node wildcards
6559 @section Wildcards Patterns and Matching
6560
6561 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
6562 @samp{*} or @samp{?} for example, are replaced and expanded into all
6563 existing files matching the given pattern. @GNUTAR{} can use wildcard
6564 patterns for matching (or globbing) archive members when extracting
6565 from or listing an archive. Wildcard patterns are also used for
6566 verifying volume labels of @command{tar} archives. This section has the
6567 purpose of explaining wildcard syntax for @command{tar}.
6568
6569 @FIXME{the next few paragraphs need work.}
6570
6571 A @var{pattern} should be written according to shell syntax, using wildcard
6572 characters to effect globbing. Most characters in the pattern stand
6573 for themselves in the matched string, and case is significant: @samp{a}
6574 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
6575 pattern matches any single character in the matched string. The character
6576 @samp{*} in the pattern matches zero, one, or more single characters in
6577 the matched string. The character @samp{\} says to take the following
6578 character of the pattern @emph{literally}; it is useful when one needs to
6579 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
6580
6581 The character @samp{[}, up to the matching @samp{]}, introduces a character
6582 class. A @dfn{character class} is a list of acceptable characters
6583 for the next single character of the matched string. For example,
6584 @samp{[abcde]} would match any of the first five letters of the alphabet.
6585 Note that within a character class, all of the ``special characters''
6586 listed above other than @samp{\} lose their special meaning; for example,
6587 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
6588 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
6589 the characters @samp{-} and @samp{]} must either come @emph{first} or
6590 @emph{last} in a character class.)
6591
6592 @cindex Excluding characters from a character class
6593 @cindex Character class, excluding characters from
6594 If the first character of the class after the opening @samp{[}
6595 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
6596 Rather than listing character to match, it lists those characters which
6597 are @emph{forbidden} as the next single character of the matched string.
6598
6599 Other characters of the class stand for themselves. The special
6600 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
6601 letters, is meant to represent all characters between @var{a} and
6602 @var{e}, inclusive.
6603
6604 @FIXME{need to add a sentence or so here to make this clear for those
6605 who don't have dan around.}
6606
6607 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
6608 special for wildcard matches. However, if a pattern completely matches
6609 a directory prefix of a matched string, then it matches the full matched
6610 string: thus, excluding a directory also excludes all the files beneath it.
6611
6612 @menu
6613 * controlling pattern-matching::
6614 @end menu
6615
6616 @node controlling pattern-matching
6617 @unnumberedsubsec Controlling Pattern-Matching
6618
6619 For the purposes of this section, we call @dfn{exclusion members} all
6620 member names obtained while processing @option{--exclude} and
6621 @option{--exclude-from} options, and @dfn{inclusion members} those
6622 member names that were given in the command line or read from the file
6623 specified with @option{--files-from} option.
6624
6625 These two pairs of member lists are used in the following operations:
6626 @option{--diff}, @option{--extract}, @option{--list},
6627 @option{--update}.
6628
6629 There are no inclusion members in create mode (@option{--create} and
6630 @option{--append}), since in this mode the names obtained from the
6631 command line refer to @emph{files}, not archive members.
6632
6633 By default, inclusion members are compared with archive members
6634 literally @footnote{Notice that earlier @GNUTAR{} versions used
6635 globbing for inclusion members, which contradicted to UNIX98
6636 specification and was not documented. @xref{Changes}, for more
6637 information on this and other changes.} and exclusion members are
6638 treated as globbing patterns. For example:
6639
6640 @smallexample
6641 @group
6642 $ @kbd{tar tf foo.tar}
6643 a.c
6644 b.c
6645 a.txt
6646 [remarks]
6647 # @i{Member names are used verbatim:}
6648 $ @kbd{tar -xf foo.tar -v '[remarks]'}
6649 [remarks]
6650 # @i{Exclude member names are globbed:}
6651 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
6652 a.txt
6653 [remarks]
6654 @end group
6655 @end smallexample
6656
6657 This behavior can be altered by using the following options:
6658
6659 @table @option
6660 @opindex wildcards
6661 @item --wildcards
6662 Treat all member names as wildcards.
6663
6664 @opindex no-wildcards
6665 @item --no-wildcards
6666 Treat all member names as literal strings.
6667 @end table
6668
6669 Thus, to extract files whose names end in @samp{.c}, you can use:
6670
6671 @smallexample
6672 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
6673 a.c
6674 b.c
6675 @end smallexample
6676
6677 @noindent
6678 Notice quoting of the pattern to prevent the shell from interpreting
6679 it.
6680
6681 The effect of @option{--wildcards} option is canceled by
6682 @option{--no-wildcards}. This can be used to pass part of
6683 the command line arguments verbatim and other part as globbing
6684 patterns. For example, the following invocation:
6685
6686 @smallexample
6687 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
6688 @end smallexample
6689
6690 @noindent
6691 instructs @command{tar} to extract from @file{foo.tar} all files whose
6692 names end in @samp{.txt} and the file named @file{[remarks]}.
6693
6694 Normally, a pattern matches a name if an initial subsequence of the
6695 name's components matches the pattern, where @samp{*}, @samp{?}, and
6696 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
6697 and wildcards can match @samp{/}.
6698
6699 Other than optionally stripping leading @samp{/} from names
6700 (@pxref{absolute}), patterns and names are used as-is. For
6701 example, trailing @samp{/} is not trimmed from a user-specified name
6702 before deciding whether to exclude it.
6703
6704 However, this matching procedure can be altered by the options listed
6705 below. These options accumulate. For example:
6706
6707 @smallexample
6708 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6709 @end smallexample
6710
6711 @noindent
6712 ignores case when excluding @samp{makefile}, but not when excluding
6713 @samp{readme}.
6714
6715 @table @option
6716 @opindex anchored
6717 @opindex no-anchored
6718 @item --anchored
6719 @itemx --no-anchored
6720 If anchored, a pattern must match an initial subsequence
6721 of the name's components. Otherwise, the pattern can match any
6722 subsequence. Default is @option{--no-anchored} for exclusion members
6723 and @option{--anchored} inclusion members.
6724
6725 @opindex ignore-case
6726 @opindex no-ignore-case
6727 @item --ignore-case
6728 @itemx --no-ignore-case
6729 When ignoring case, upper-case patterns match lower-case names and vice versa.
6730 When not ignoring case (the default), matching is case-sensitive.
6731
6732 @opindex wildcards-match-slash
6733 @opindex no-wildcards-match-slash
6734 @item --wildcards-match-slash
6735 @itemx --no-wildcards-match-slash
6736 When wildcards match slash (the default for exclusion members), a
6737 wildcard like @samp{*} in the pattern can match a @samp{/} in the
6738 name. Otherwise, @samp{/} is matched only by @samp{/}.
6739
6740 @end table
6741
6742 The @option{--recursion} and @option{--no-recursion} options
6743 (@pxref{recurse}) also affect how member patterns are interpreted. If
6744 recursion is in effect, a pattern matches a name if it matches any of
6745 the name's parent directories.
6746
6747 The following table summarizes pattern-matching default values:
6748
6749 @multitable @columnfractions .3 .7
6750 @headitem Members @tab Default settings
6751 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
6752 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
6753 @end multitable
6754
6755 @node quoting styles
6756 @section Quoting Member Names
6757
6758 When displaying member names, @command{tar} takes care to avoid
6759 ambiguities caused by certain characters. This is called @dfn{name
6760 quoting}. The characters in question are:
6761
6762 @itemize @bullet
6763 @item Non-printable control characters:
6764
6765 @multitable @columnfractions 0.20 0.10 0.60
6766 @headitem Character @tab ASCII @tab Character name
6767 @item \a @tab 7 @tab Audible bell
6768 @item \b @tab 8 @tab Backspace
6769 @item \f @tab 12 @tab Form feed
6770 @item \n @tab 10 @tab New line
6771 @item \r @tab 13 @tab Carriage return
6772 @item \t @tab 9 @tab Horizontal tabulation
6773 @item \v @tab 11 @tab Vertical tabulation
6774 @end multitable
6775
6776 @item Space (ASCII 32)
6777
6778 @item Single and double quotes (@samp{'} and @samp{"})
6779
6780 @item Backslash (@samp{\})
6781 @end itemize
6782
6783 The exact way @command{tar} uses to quote these characters depends on
6784 the @dfn{quoting style}. The default quoting style, called
6785 @dfn{escape} (see below), uses backslash notation to represent control
6786 characters, space and backslash. Using this quoting style, control
6787 characters are represented as listed in column @samp{Character} in the
6788 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
6789
6790 @GNUTAR{} offers seven distinct quoting styles, which can be selected
6791 using @option{--quoting-style} option:
6792
6793 @table @option
6794 @item --quoting-style=@var{style}
6795 @opindex quoting-style
6796
6797 Sets quoting style. Valid values for @var{style} argument are:
6798 literal, shell, shell-always, c, escape, locale, clocale.
6799 @end table
6800
6801 These styles are described in detail below. To illustrate their
6802 effect, we will use an imaginary tar archive @file{arch.tar}
6803 containing the following members:
6804
6805 @smallexample
6806 @group
6807 # 1. Contains horizontal tabulation character.
6808 a tab
6809 # 2. Contains newline character
6810 a
6811 newline
6812 # 3. Contains a space
6813 a space
6814 # 4. Contains double quotes
6815 a"double"quote
6816 # 5. Contains single quotes
6817 a'single'quote
6818 # 6. Contains a backslash character:
6819 a\backslash
6820 @end group
6821 @end smallexample
6822
6823 Here is how usual @command{ls} command would have listed them, if they
6824 had existed in the current working directory:
6825
6826 @smallexample
6827 @group
6828 $ @kbd{ls}
6829 a\ttab
6830 a\nnewline
6831 a\ space
6832 a"double"quote
6833 a'single'quote
6834 a\\backslash
6835 @end group
6836 @end smallexample
6837
6838 Quoting styles:
6839
6840 @table @samp
6841 @item literal
6842 No quoting, display each character as is:
6843
6844 @smallexample
6845 @group
6846 $ @kbd{tar tf arch.tar --quoting-style=literal}
6847 ./
6848 ./a space
6849 ./a'single'quote
6850 ./a"double"quote
6851 ./a\backslash
6852 ./a tab
6853 ./a
6854 newline
6855 @end group
6856 @end smallexample
6857
6858 @item shell
6859 Display characters the same way Bourne shell does:
6860 control characters, except @samp{\t} and @samp{\n}, are printed using
6861 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
6862 single quote is printed as @samp{\'}. If a name contains any quoted
6863 characters, it is enclosed in single quotes. In particular, if a name
6864 contains single quotes, it is printed as several single-quoted strings:
6865
6866 @smallexample
6867 @group
6868 $ @kbd{tar tf arch.tar --quoting-style=shell}
6869 ./
6870 './a space'
6871 './a'\''single'\''quote'
6872 './a"double"quote'
6873 './a\backslash'
6874 './a tab'
6875 './a
6876 newline'
6877 @end group
6878 @end smallexample
6879
6880 @item shell-always
6881 Same as @samp{shell}, but the names are always enclosed in single
6882 quotes:
6883
6884 @smallexample
6885 @group
6886 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
6887 './'
6888 './a space'
6889 './a'\''single'\''quote'
6890 './a"double"quote'
6891 './a\backslash'
6892 './a tab'
6893 './a
6894 newline'
6895 @end group
6896 @end smallexample
6897
6898 @item c
6899 Use the notation of the C programming language. All names are
6900 enclosed in double quotes. Control characters are quoted using
6901 backslash notations, double quotes are represented as @samp{\"},
6902 backslash characters are represented as @samp{\\}. Single quotes and
6903 spaces are not quoted:
6904
6905 @smallexample
6906 @group
6907 $ @kbd{tar tf arch.tar --quoting-style=c}
6908 "./"
6909 "./a space"
6910 "./a'single'quote"
6911 "./a\"double\"quote"
6912 "./a\\backslash"
6913 "./a\ttab"
6914 "./a\nnewline"
6915 @end group
6916 @end smallexample
6917
6918 @item escape
6919 Control characters are printed using backslash notation, a space is
6920 printed as @samp{\ } and a backslash as @samp{\\}. This is the
6921 default quoting style, unless it was changed when configured the
6922 package.
6923
6924 @smallexample
6925 @group
6926 $ @kbd{tar tf arch.tar --quoting-style=escape}
6927 ./
6928 ./a space
6929 ./a'single'quote
6930 ./a"double"quote
6931 ./a\\backslash
6932 ./a\ttab
6933 ./a\nnewline
6934 @end group
6935 @end smallexample
6936
6937 @item locale
6938 Control characters, single quote and backslash are printed using
6939 backslash notation. All names are quoted using left and right
6940 quotation marks, appropriate to the current locale. If it does not
6941 define quotation marks, use @samp{`} as left and @samp{'} as right
6942 quotation marks. Any occurrences of the right quotation mark in a
6943 name are escaped with @samp{\}, for example:
6944
6945 For example:
6946
6947 @smallexample
6948 @group
6949 $ @kbd{tar tf arch.tar --quoting-style=locale}
6950 `./'
6951 `./a space'
6952 `./a\'single\'quote'
6953 `./a"double"quote'
6954 `./a\\backslash'
6955 `./a\ttab'
6956 `./a\nnewline'
6957 @end group
6958 @end smallexample
6959
6960 @item clocale
6961 Same as @samp{locale}, but @samp{"} is used for both left and right
6962 quotation marks, if not provided by the currently selected locale:
6963
6964 @smallexample
6965 @group
6966 $ @kbd{tar tf arch.tar --quoting-style=clocale}
6967 "./"
6968 "./a space"
6969 "./a'single'quote"
6970 "./a\"double\"quote"
6971 "./a\\backslash"
6972 "./a\ttab"
6973 "./a\nnewline"
6974 @end group
6975 @end smallexample
6976 @end table
6977
6978 You can specify which characters should be quoted in addition to those
6979 implied by the current quoting style:
6980
6981 @table @option
6982 @item --quote-chars=@var{string}
6983 Always quote characters from @var{string}, even if the selected
6984 quoting style would not quote them.
6985 @end table
6986
6987 For example, using @samp{escape} quoting (compare with the usual
6988 escape listing above):
6989
6990 @smallexample
6991 @group
6992 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
6993 ./
6994 ./a\ space
6995 ./a'single'quote
6996 ./a\"double\"quote
6997 ./a\\backslash
6998 ./a\ttab
6999 ./a\nnewline
7000 @end group
7001 @end smallexample
7002
7003 To disable quoting of such additional characters, use the following
7004 option:
7005
7006 @table @option
7007 @item --no-quote-chars=@var{string}
7008 Remove characters listed in @var{string} from the list of quoted
7009 characters set by the previous @option{--quote-chars} option.
7010 @end table
7011
7012 This option is particularly useful if you have added
7013 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7014 and wish to disable it for the current invocation.
7015
7016 Note, that @option{--no-quote-chars} does @emph{not} disable those
7017 characters that are quoted by default in the selected quoting style.
7018
7019 @node transform
7020 @section Modifying File and Member Names
7021
7022 @command{Tar} archives contain detailed information about files stored
7023 in them and full file names are part of that information. When
7024 storing file to an archive, its file name is recorded in the archive
7025 along with the actual file contents. When restoring from an archive,
7026 a file is created on disk with exactly the same name as that stored
7027 in the archive. In the majority of cases this is the desired behavior
7028 of a file archiver. However, there are some cases when it is not.
7029
7030 First of all, it is often unsafe to extract archive members with
7031 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7032 takes special precautions when extracting such names and provides a
7033 special option for handling them, which is described in
7034 @ref{absolute}.
7035
7036 Secondly, you may wish to extract file names without some leading
7037 directory components, or with otherwise modified names. In other
7038 cases it is desirable to store files under differing names in the
7039 archive.
7040
7041 @GNUTAR{} provides two options for these needs.
7042
7043 @table @option
7044 @opindex strip-components
7045 @item --strip-components=@var{number}
7046 Strip given @var{number} of leading components from file names before
7047 extraction.
7048 @end table
7049
7050 For example, suppose you have archived whole @file{/usr} hierarchy to
7051 a tar archive named @file{usr.tar}. Among other files, this archive
7052 contains @file{usr/include/stdlib.h}, which you wish to extract to
7053 the current working directory. To do so, you type:
7054
7055 @smallexample
7056 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7057 @end smallexample
7058
7059 The option @option{--strip=2} instructs @command{tar} to strip the
7060 two leading components (@file{usr/} and @file{include/}) off the file
7061 name.
7062
7063 If you add to the above invocation @option{--verbose} (@option{-v})
7064 option, you will note that the verbose listing still contains the
7065 full file name, with the two removed components still in place. This
7066 can be inconvenient, so @command{tar} provides a special option for
7067 altering this behavior:
7068
7069 @anchor{show-transformed-names}
7070 @table @option
7071 @opindex show-transformed-names
7072 @item --show-transformed-names
7073 Display file or member names with all requested transformations
7074 applied.
7075 @end table
7076
7077 @noindent
7078 For example:
7079
7080 @smallexample
7081 @group
7082 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7083 usr/include/stdlib.h
7084 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7085 stdlib.h
7086 @end group
7087 @end smallexample
7088
7089 Notice that in both cases the file is @file{stdlib.h} extracted to the
7090 current working directory, @option{--show-transformed-names} affects
7091 only the way its name is displayed.
7092
7093 This option is especially useful for verifying whether the invocation
7094 will have the desired effect. Thus, before running
7095
7096 @smallexample
7097 $ @kbd{tar -x --strip=@var{n}}
7098 @end smallexample
7099
7100 @noindent
7101 it is often advisable to run
7102
7103 @smallexample
7104 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7105 @end smallexample
7106
7107 @noindent
7108 to make sure the command will produce the intended results.
7109
7110 In case you need to apply more complex modifications to the file name,
7111 @GNUTAR{} provides a general-purpose transformation option:
7112
7113 @table @option
7114 @opindex transform
7115 @item --transform=@var{expression}
7116 Modify file names using supplied @var{expression}.
7117 @end table
7118
7119 @noindent
7120 The @var{expression} is a @command{sed}-like replace expression of the
7121 form:
7122
7123 @smallexample
7124 s/@var{regexp}/@var{replace}/[@var{flags}]
7125 @end smallexample
7126
7127 @noindent
7128 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7129 replacement for each file name part that matches @var{regexp}. Both
7130 @var{regexp} and @var{replace} are described in detail in
7131 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7132
7133 Supported @var{flags} are:
7134
7135 @table @samp
7136 @item g
7137 Apply the replacement to @emph{all} matches to the @var{regexp}, not
7138 just the first.
7139
7140 @item i
7141 Use case-insensitive matching
7142
7143 @item x
7144 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
7145 regexps, Extended regular expressions, Extended regular expressions,
7146 sed, GNU sed}).
7147
7148 @item @var{number}
7149 Only replace the @var{number}th match of the @var{regexp}.
7150
7151 Note: the @var{posix} standard does not specify what should happen
7152 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
7153 follows the GNU @command{sed} implementation in this regard, so
7154 the interaction is defined to be: ignore matches before the
7155 @var{number}th, and then match and replace all matches from the
7156 @var{number}th on.
7157
7158 @end table
7159
7160 Any delimiter can be used in lieue of @samp{/}, the only requirement being
7161 that it be used consistently throughout the expression. For example,
7162 the following two expressions are equivalent:
7163
7164 @smallexample
7165 @group
7166 s/one/two/
7167 s,one,two,
7168 @end group
7169 @end smallexample
7170
7171 Changing delimiters is often useful when the @var{regex} contains
7172 slashes. For example, it is more convenient to write @code{s,/,-,} than
7173 @code{s/\//-/}.
7174
7175 Here are several examples of @option{--transform} usage:
7176
7177 @enumerate
7178 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
7179
7180 @smallexample
7181 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
7182 @end smallexample
7183
7184 @item Strip two leading directory components (equivalent to
7185 @option{--strip-components=2}):
7186
7187 @smallexample
7188 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
7189 @end smallexample
7190
7191 @item Prepend @file{/prefix/} to each file name:
7192
7193 @smallexample
7194 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
7195 @end smallexample
7196
7197 @item Convert each file name to lower case:
7198
7199 @smallexample
7200 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
7201 @end smallexample
7202
7203 @end enumerate
7204
7205 Unlike @option{--strip-components}, @option{--transform} can be used
7206 in any @GNUTAR{} operation mode. For example, the following command
7207 adds files to the archive while replacing the leading @file{usr/}
7208 component with @file{var/}:
7209
7210 @smallexample
7211 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
7212 @end smallexample
7213
7214 To test @option{--transform} effect we suggest using
7215 @option{--show-transformed-names} option:
7216
7217 @smallexample
7218 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
7219 --verbose --show-transformed-names /}
7220 @end smallexample
7221
7222 If both @option{--strip-components} and @option{--transform} are used
7223 together, then @option{--transform} is applied first, and the required
7224 number of components is then stripped from its result.
7225
7226 @node after
7227 @section Operating Only on New Files
7228 @UNREVISED
7229
7230 @cindex Excluding file by age
7231 @cindex Data Modification time, excluding files by
7232 @cindex Modification time, excluding files by
7233 @cindex Age, excluding files by
7234 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
7235 @option{-N @var{date}}) option causes @command{tar} to only work on
7236 files whose data modification or status change times are newer than
7237 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
7238 it is taken to be a file name; the data modification time of that file
7239 is used as the date. If you use this option when creating or appending
7240 to an archive, the archive will only include new files. If you use
7241 @option{--after-date} when extracting an archive, @command{tar} will
7242 only extract files newer than the @var{date} you specify.
7243
7244 If you only want @command{tar} to make the date comparison based on
7245 modification of the file's data (rather than status
7246 changes), then use the @option{--newer-mtime=@var{date}} option.
7247
7248 You may use these options with any operation. Note that these options
7249 differ from the @option{--update} (@option{-u}) operation in that they
7250 allow you to specify a particular date against which @command{tar} can
7251 compare when deciding whether or not to archive the files.
7252
7253 @table @option
7254 @opindex after-date
7255 @opindex newer
7256 @item --after-date=@var{date}
7257 @itemx --newer=@var{date}
7258 @itemx -N @var{date}
7259 Only store files newer than @var{date}.
7260
7261 Acts on files only if their data modification or status change times are
7262 later than @var{date}. Use in conjunction with any operation.
7263
7264 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
7265 name; the data modification time of that file is used as the date.
7266
7267 @opindex newer-mtime
7268 @item --newer-mtime=@var{date}
7269 Acts like @option{--after-date}, but only looks at data modification times.
7270 @end table
7271
7272 These options limit @command{tar} to operate only on files which have
7273 been modified after the date specified. A file's status is considered to have
7274 changed if its contents have been modified, or if its owner,
7275 permissions, and so forth, have been changed. (For more information on
7276 how to specify a date, see @ref{Date input formats}; remember that the
7277 entire date argument must be quoted if it contains any spaces.)
7278
7279 Gurus would say that @option{--after-date} tests both the data
7280 modification time (@code{mtime}, the time the contents of the file
7281 were last modified) and the status change time (@code{ctime}, the time
7282 the file's status was last changed: owner, permissions, etc.@:)
7283 fields, while @option{--newer-mtime} tests only the @code{mtime}
7284 field.
7285
7286 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
7287 @code{ctime} and processes the file if either one is more recent than
7288 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
7289 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
7290 contents of the file were looked at).
7291
7292 Date specifiers can have embedded spaces. Because of this, you may need
7293 to quote date arguments to keep the shell from parsing them as separate
7294 arguments. For example, the following command will add to the archive
7295 all the files modified less than two days ago:
7296
7297 @smallexample
7298 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
7299 @end smallexample
7300
7301 When any of these options is used with the option @option{--verbose}
7302 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
7303 date back to its textual representation and compare that with the
7304 one given with the option. If the two dates differ, @command{tar} will
7305 print a warning saying what date it will use. This is to help user
7306 ensure he is using the right date. For example:
7307
7308 @smallexample
7309 @group
7310 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
7311 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7312 13:19:37.232434
7313 @end group
7314 @end smallexample
7315
7316 @quotation
7317 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
7318 should not be used for incremental backups. @xref{Incremental Dumps},
7319 for proper way of creating incremental backups.
7320 @end quotation
7321
7322 @node recurse
7323 @section Descending into Directories
7324 @UNREVISED
7325 @cindex Avoiding recursion in directories
7326 @cindex Descending directories, avoiding
7327 @cindex Directories, avoiding recursion
7328 @cindex Recursion in directories, avoiding
7329
7330 @FIXME{arrggh! this is still somewhat confusing to me. :-< }
7331
7332 Usually, @command{tar} will recursively explore all directories (either
7333 those given on the command line or through the @option{--files-from}
7334 option) for the various files they contain. However, you may not always
7335 want @command{tar} to act this way.
7336
7337 @opindex no-recursion
7338 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
7339 into specified directories. If you specify @option{--no-recursion}, you can
7340 use the @command{find} utility for hunting through levels of directories to
7341 construct a list of file names which you could then pass to @command{tar}.
7342 @command{find} allows you to be more selective when choosing which files to
7343 archive; see @ref{files}, for more information on using @command{find} with
7344 @command{tar}, or look.
7345
7346 @table @option
7347 @item --no-recursion
7348 Prevents @command{tar} from recursively descending directories.
7349
7350 @opindex recursion
7351 @item --recursion
7352 Requires @command{tar} to recursively descend directories.
7353 This is the default.
7354 @end table
7355
7356 When you use @option{--no-recursion}, @GNUTAR{} grabs
7357 directory entries themselves, but does not descend on them
7358 recursively. Many people use @command{find} for locating files they
7359 want to back up, and since @command{tar} @emph{usually} recursively
7360 descends on directories, they have to use the @samp{@w{-not -type d}}
7361 test in their @command{find} invocation (@pxref{Type, Type, Type test,
7362 find, Finding Files}), as they usually do not want all the files in a
7363 directory. They then use the @option{--files-from} option to archive
7364 the files located via @command{find}.
7365
7366 The problem when restoring files archived in this manner is that the
7367 directories themselves are not in the archive; so the
7368 @option{--same-permissions} (@option{--preserve-permissions},
7369 @option{-p}) option does not affect them---while users might really
7370 like it to. Specifying @option{--no-recursion} is a way to tell
7371 @command{tar} to grab only the directory entries given to it, adding
7372 no new files on its own. To summarize, if you use @command{find} to
7373 create a list of files to be stored in an archive, use it as follows:
7374
7375 @smallexample
7376 @group
7377 $ @kbd{find @var{dir} @var{tests} | \
7378 tar -cf @var{archive} -T - --no-recursion}
7379 @end group
7380 @end smallexample
7381
7382 The @option{--no-recursion} option also applies when extracting: it
7383 causes @command{tar} to extract only the matched directory entries, not
7384 the files under those directories.
7385
7386 The @option{--no-recursion} option also affects how globbing patterns
7387 are interpreted (@pxref{controlling pattern-matching}).
7388
7389 The @option{--no-recursion} and @option{--recursion} options apply to
7390 later options and operands, and can be overridden by later occurrences
7391 of @option{--no-recursion} and @option{--recursion}. For example:
7392
7393 @smallexample
7394 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
7395 @end smallexample
7396
7397 @noindent
7398 creates an archive with one entry for @file{grape}, and the recursive
7399 contents of @file{grape/concord}, but no entries under @file{grape}
7400 other than @file{grape/concord}.
7401
7402 @node one
7403 @section Crossing File System Boundaries
7404 @cindex File system boundaries, not crossing
7405 @UNREVISED
7406
7407 @command{tar} will normally automatically cross file system boundaries in
7408 order to archive files which are part of a directory tree. You can
7409 change this behavior by running @command{tar} and specifying
7410 @option{--one-file-system}. This option only affects files that are
7411 archived because they are in a directory that is being archived;
7412 @command{tar} will still archive files explicitly named on the command line
7413 or through @option{--files-from}, regardless of where they reside.
7414
7415 @table @option
7416 @opindex one-file-system
7417 @item --one-file-system
7418 Prevents @command{tar} from crossing file system boundaries when
7419 archiving. Use in conjunction with any write operation.
7420 @end table
7421
7422 The @option{--one-file-system} option causes @command{tar} to modify its
7423 normal behavior in archiving the contents of directories. If a file in
7424 a directory is not on the same file system as the directory itself, then
7425 @command{tar} will not archive that file. If the file is a directory
7426 itself, @command{tar} will not archive anything beneath it; in other words,
7427 @command{tar} will not cross mount points.
7428
7429 This option is useful for making full or incremental archival backups of
7430 a file system. If this option is used in conjunction with
7431 @option{--verbose} (@option{-v}), files that are excluded are
7432 mentioned by name on the standard error.
7433
7434 @menu
7435 * directory:: Changing Directory
7436 * absolute:: Absolute File Names
7437 @end menu
7438
7439 @node directory
7440 @subsection Changing the Working Directory
7441
7442 @FIXME{need to read over this node now for continuity; i've switched
7443 things around some.}
7444
7445 @cindex Changing directory mid-stream
7446 @cindex Directory, changing mid-stream
7447 @cindex Working directory, specifying
7448 To change the working directory in the middle of a list of file names,
7449 either on the command line or in a file specified using
7450 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
7451 This will change the working directory to the specified directory
7452 after that point in the list.
7453
7454 @table @option
7455 @opindex directory
7456 @item --directory=@var{directory}
7457 @itemx -C @var{directory}
7458 Changes the working directory in the middle of a command line.
7459 @end table
7460
7461 For example,
7462
7463 @smallexample
7464 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
7465 @end smallexample
7466
7467 @noindent
7468 will place the files @file{grape} and @file{prune} from the current
7469 directory into the archive @file{jams.tar}, followed by the file
7470 @file{cherry} from the directory @file{food}. This option is especially
7471 useful when you have several widely separated files that you want to
7472 store in the same archive.
7473
7474 Note that the file @file{cherry} is recorded in the archive under the
7475 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
7476 archive will contain three files that all appear to have come from the
7477 same directory; if the archive is extracted with plain @samp{tar
7478 --extract}, all three files will be written in the current directory.
7479
7480 Contrast this with the command,
7481
7482 @smallexample
7483 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
7484 @end smallexample
7485
7486 @noindent
7487 which records the third file in the archive under the name
7488 @file{red/cherry} so that, if the archive is extracted using
7489 @samp{tar --extract}, the third file will be written in a subdirectory
7490 named @file{orange-colored}.
7491
7492 You can use the @option{--directory} option to make the archive
7493 independent of the original name of the directory holding the files.
7494 The following command places the files @file{/etc/passwd},
7495 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
7496 @file{foo.tar}:
7497
7498 @smallexample
7499 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
7500 @end smallexample
7501
7502 @noindent
7503 However, the names of the archive members will be exactly what they were
7504 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
7505 They will not appear to be related by file name to the original
7506 directories where those files were located.
7507
7508 Note that @option{--directory} options are interpreted consecutively. If
7509 @option{--directory} specifies a relative file name, it is interpreted
7510 relative to the then current directory, which might not be the same as
7511 the original current working directory of @command{tar}, due to a previous
7512 @option{--directory} option.
7513
7514 When using @option{--files-from} (@pxref{files}), you can put various
7515 @command{tar} options (including @option{-C}) in the file list. Notice,
7516 however, that in this case the option and its argument may not be
7517 separated by whitespace. If you use short option, its argument must
7518 either follow the option letter immediately, without any intervening
7519 whitespace, or occupy the next line. Otherwise, if you use long
7520 option, separate its argument by an equal sign.
7521
7522 For instance, the file list for the above example will be:
7523
7524 @smallexample
7525 @group
7526 -C/etc
7527 passwd
7528 hosts
7529 --directory=/lib
7530 libc.a
7531 @end group
7532 @end smallexample
7533
7534 @noindent
7535 To use it, you would invoke @command{tar} as follows:
7536
7537 @smallexample
7538 $ @kbd{tar -c -f foo.tar --files-from list}
7539 @end smallexample
7540
7541 The interpretation of @option{--directory} is disabled by
7542 @option{--null} option.
7543
7544 @node absolute
7545 @subsection Absolute File Names
7546 @UNREVISED
7547
7548 @table @option
7549 @opindex absolute-names
7550 @item --absolute-names
7551 @itemx -P
7552 Do not strip leading slashes from file names, and permit file names
7553 containing a @file{..} file name component.
7554 @end table
7555
7556 By default, @GNUTAR{} drops a leading @samp{/} on
7557 input or output, and complains about file names containing a @file{..}
7558 component. This option turns off this behavior.
7559
7560 When @command{tar} extracts archive members from an archive, it strips any
7561 leading slashes (@samp{/}) from the member name. This causes absolute
7562 member names in the archive to be treated as relative file names. This
7563 allows you to have such members extracted wherever you want, instead of
7564 being restricted to extracting the member in the exact directory named
7565 in the archive. For example, if the archive member has the name
7566 @file{/etc/passwd}, @command{tar} will extract it as if the name were
7567 really @file{etc/passwd}.
7568
7569 File names containing @file{..} can cause problems when extracting, so
7570 @command{tar} normally warns you about such files when creating an
7571 archive, and rejects attempts to extracts such files.
7572
7573 Other @command{tar} programs do not do this. As a result, if you
7574 create an archive whose member names start with a slash, they will be
7575 difficult for other people with a non-@GNUTAR{}
7576 program to use. Therefore, @GNUTAR{} also strips
7577 leading slashes from member names when putting members into the
7578 archive. For example, if you ask @command{tar} to add the file
7579 @file{/bin/ls} to an archive, it will do so, but the member name will
7580 be @file{bin/ls}.@footnote{A side effect of this is that when
7581 @option{--create} is used with @option{--verbose} the resulting output
7582 is not, generally speaking, the same as the one you'd get running
7583 @kbd{tar --list} command. This may be important if you use some
7584 scripts for comparing both outputs. @xref{listing member and file names},
7585 for the information on how to handle this case.}
7586
7587 If you use the @option{--absolute-names} (@option{-P}) option,
7588 @command{tar} will do none of these transformations.
7589
7590 To archive or extract files relative to the root directory, specify
7591 the @option{--absolute-names} (@option{-P}) option.
7592
7593 Normally, @command{tar} acts on files relative to the working
7594 directory---ignoring superior directory names when archiving, and
7595 ignoring leading slashes when extracting.
7596
7597 When you specify @option{--absolute-names} (@option{-P}),
7598 @command{tar} stores file names including all superior directory
7599 names, and preserves leading slashes. If you only invoked
7600 @command{tar} from the root directory you would never need the
7601 @option{--absolute-names} option, but using this option
7602 may be more convenient than switching to root.
7603
7604 @FIXME{Should be an example in the tutorial/wizardry section using this
7605 to transfer files between systems.}
7606
7607 @FIXME{Is write access an issue?}
7608
7609 @table @option
7610 @item --absolute-names
7611 Preserves full file names (including superior directory names) when
7612 archiving files. Preserves leading slash when extracting files.
7613
7614 @end table
7615
7616 @FIXME{this is still horrible; need to talk with dan on monday.}
7617
7618 @command{tar} prints out a message about removing the @samp{/} from
7619 file names. This message appears once per @GNUTAR{}
7620 invocation. It represents something which ought to be told; ignoring
7621 what it means can cause very serious surprises, later.
7622
7623 Some people, nevertheless, do not want to see this message. Wanting to
7624 play really dangerously, one may of course redirect @command{tar} standard
7625 error to the sink. For example, under @command{sh}:
7626
7627 @smallexample
7628 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
7629 @end smallexample
7630
7631 @noindent
7632 Another solution, both nicer and simpler, would be to change to
7633 the @file{/} directory first, and then avoid absolute notation.
7634 For example:
7635
7636 @smallexample
7637 $ @kbd{(cd / && tar -c -f archive.tar home)}
7638 # @i{or}:
7639 $ @kbd{tar -c -f archive.tar -C / home}
7640 @end smallexample
7641
7642 @include getdate.texi
7643
7644 @node Formats
7645 @chapter Controlling the Archive Format
7646
7647 @cindex Tar archive formats
7648 Due to historical reasons, there are several formats of tar archives.
7649 All of them are based on the same principles, but have some subtle
7650 differences that often make them incompatible with each other.
7651
7652 GNU tar is able to create and handle archives in a variety of formats.
7653 The most frequently used formats are (in alphabetical order):
7654
7655 @table @asis
7656 @item gnu
7657 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
7658 from an early @acronym{POSIX} standard, adding some improvements such as
7659 sparse file handling and incremental archives. Unfortunately these
7660 features were implemented in a way incompatible with other archive
7661 formats.
7662
7663 Archives in @samp{gnu} format are able to hold pathnames of unlimited
7664 length.
7665
7666 @item oldgnu
7667 Format used by @GNUTAR{} of versions prior to 1.12.
7668
7669 @item v7
7670 Archive format, compatible with the V7 implementation of tar. This
7671 format imposes a number of limitations. The most important of them
7672 are:
7673
7674 @enumerate
7675 @item The maximum length of a file name is limited to 99 characters.
7676 @item The maximum length of a symbolic link is limited to 99 characters.
7677 @item It is impossible to store special files (block and character
7678 devices, fifos etc.)
7679 @item Maximum value of user or group ID is limited to 2097151 (7777777
7680 octal)
7681 @item V7 archives do not contain symbolic ownership information (user
7682 and group name of the file owner).
7683 @end enumerate
7684
7685 This format has traditionally been used by Automake when producing
7686 Makefiles. This practice will change in the future, in the meantime,
7687 however this means that projects containing filenames more than 99
7688 characters long will not be able to use @GNUTAR{} @value{VERSION} and
7689 Automake prior to 1.9.
7690
7691 @item ustar
7692 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
7693 symbolic ownership information. It is also able to store
7694 special files. However, it imposes several restrictions as well:
7695
7696 @enumerate
7697 @item The maximum length of a file name is limited to 256 characters,
7698 provided that the filename can be split at directory separator in
7699 two parts, first of them being at most 155 bytes long. So, in most
7700 cases the maximum file name length will be shorter than 256
7701 characters.
7702 @item The maximum length of a symbolic link name is limited to
7703 100 characters.
7704 @item Maximum size of a file the archive is able to accommodate
7705 is 8GB
7706 @item Maximum value of UID/GID is 2097151.
7707 @item Maximum number of bits in device major and minor numbers is 21.
7708 @end enumerate
7709
7710 @item star
7711 Format used by J@"org Schilling @command{star}
7712 implementation. @GNUTAR{} is able to read @samp{star} archives but
7713 currently does not produce them.
7714
7715 @item posix
7716 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
7717 most flexible and feature-rich format. It does not impose any
7718 restrictions on file sizes or filename lengths. This format is quite
7719 recent, so not all tar implementations are able to handle it properly.
7720 However, this format is designed in such a way that any tar
7721 implementation able to read @samp{ustar} archives will be able to read
7722 most @samp{posix} archives as well, with the only exception that any
7723 additional information (such as long file names etc.) will in such
7724 case be extracted as plain text files along with the files it refers to.
7725
7726 This archive format will be the default format for future versions
7727 of @GNUTAR{}.
7728
7729 @end table
7730
7731 The following table summarizes the limitations of each of these
7732 formats:
7733
7734 @multitable @columnfractions .10 .20 .20 .20 .20
7735 @headitem Format @tab UID @tab File Size @tab Path Name @tab Devn
7736 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7737 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
7738 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
7739 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
7740 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
7741 @end multitable
7742
7743 The default format for @GNUTAR{} is defined at compilation
7744 time. You may check it by running @command{tar --help}, and examining
7745 the last lines of its output. Usually, @GNUTAR{} is configured
7746 to create archives in @samp{gnu} format, however, future version will
7747 switch to @samp{posix}.
7748
7749 @menu
7750 * Compression:: Using Less Space through Compression
7751 * Attributes:: Handling File Attributes
7752 * Portability:: Making @command{tar} Archives More Portable
7753 * cpio:: Comparison of @command{tar} and @command{cpio}
7754 @end menu
7755
7756 @node Compression
7757 @section Using Less Space through Compression
7758
7759 @menu
7760 * gzip:: Creating and Reading Compressed Archives
7761 * sparse:: Archiving Sparse Files
7762 @end menu
7763
7764 @node gzip
7765 @subsection Creating and Reading Compressed Archives
7766 @cindex Compressed archives
7767 @cindex Storing archives in compressed format
7768
7769 @GNUTAR{} is able to create and read compressed archives. It supports
7770 @command{gzip} and @command{bzip2} compression programs. For backward
7771 compatibility, it also supports @command{compress} command, although
7772 we strongly recommend against using it, since there is a patent
7773 covering the algorithm it uses and you could be sued for patent
7774 infringement merely by running @command{compress}! Besides, it is less
7775 effective than @command{gzip} and @command{bzip2}.
7776
7777 Creating a compressed archive is simple: you just specify a
7778 @dfn{compression option} along with the usual archive creation
7779 commands. The compression option is @option{-z} (@option{--gzip}) to
7780 create a @command{gzip} compressed archive, @option{-j}
7781 (@option{--bzip2}) to create a @command{bzip2} compressed archive, and
7782 @option{-Z} (@option{--compress}) to use @command{compress} program.
7783 For example:
7784
7785 @smallexample
7786 $ @kbd{tar cfz archive.tar.gz .}
7787 @end smallexample
7788
7789 Reading compressed archive is even simpler: you don't need to specify
7790 any additional options as @GNUTAR{} recognizes its format
7791 automatically. Thus, the following commands will list and extract the
7792 archive created in previous example:
7793
7794 @smallexample
7795 # List the compressed archive
7796 $ @kbd{tar tf archive.tar.gz}
7797 # Extract the compressed archive
7798 $ @kbd{tar xf archive.tar.gz}
7799 @end smallexample
7800
7801 The only case when you have to specify a decompression option while
7802 reading the archive is when reading from a pipe or from a tape drive
7803 that does not support random access. However, in this case @GNUTAR{}
7804 will indicate which option you should use. For example:
7805
7806 @smallexample
7807 $ @kbd{cat archive.tar.gz | tar tf -}
7808 tar: Archive is compressed. Use -z option
7809 tar: Error is not recoverable: exiting now
7810 @end smallexample
7811
7812 If you see such diagnostics, just add the suggested option to the
7813 invocation of @GNUTAR{}:
7814
7815 @smallexample
7816 $ @kbd{cat archive.tar.gz | tar tfz -}
7817 @end smallexample
7818
7819 Notice also, that there are several restrictions on operations on
7820 compressed archives. First of all, compressed archives cannot be
7821 modified, i.e., you cannot update (@option{--update} (@option{-u})) them or delete
7822 (@option{--delete}) members from them. Likewise, you cannot append
7823 another @command{tar} archive to a compressed archive using
7824 @option{--append} (@option{-r})). Secondly, multi-volume archives cannot be
7825 compressed.
7826
7827 The following table summarizes compression options used by @GNUTAR{}.
7828
7829 @table @option
7830 @opindex gzip
7831 @opindex ungzip
7832 @item -z
7833 @itemx --gzip
7834 @itemx --ungzip
7835 Filter the archive through @command{gzip}.
7836
7837 You can use @option{--gzip} and @option{--gunzip} on physical devices
7838 (tape drives, etc.) and remote files as well as on normal files; data
7839 to or from such devices or remote files is reblocked by another copy
7840 of the @command{tar} program to enforce the specified (or default) record
7841 size. The default compression parameters are used; if you need to
7842 override them, set @env{GZIP} environment variable, e.g.:
7843
7844 @smallexample
7845 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
7846 @end smallexample
7847
7848 @noindent
7849 Another way would be to avoid the @option{--gzip} (@option{--gunzip}, @option{--ungzip}, @option{-z}) option and run
7850 @command{gzip} explicitly:
7851
7852 @smallexample
7853 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
7854 @end smallexample
7855
7856 @cindex corrupted archives
7857 About corrupted compressed archives: @command{gzip}'ed files have no
7858 redundancy, for maximum compression. The adaptive nature of the
7859 compression scheme means that the compression tables are implicitly
7860 spread all over the archive. If you lose a few blocks, the dynamic
7861 construction of the compression tables becomes unsynchronized, and there
7862 is little chance that you could recover later in the archive.
7863
7864 There are pending suggestions for having a per-volume or per-file
7865 compression in @GNUTAR{}. This would allow for viewing the
7866 contents without decompression, and for resynchronizing decompression at
7867 every volume or file, in case of corrupted archives. Doing so, we might
7868 lose some compressibility. But this would have make recovering easier.
7869 So, there are pros and cons. We'll see!
7870
7871 @opindex bzip2
7872 @item -j
7873 @itemx --bzip2
7874 Filter the archive through @code{bzip2}. Otherwise like @option{--gzip}.
7875
7876 @opindex compress
7877 @opindex uncompress
7878 @item -Z
7879 @itemx --compress
7880 @itemx --uncompress
7881 Filter the archive through @command{compress}. Otherwise like @option{--gzip}.
7882
7883 The @acronym{GNU} Project recommends you not use
7884 @command{compress}, because there is a patent covering the algorithm it
7885 uses. You could be sued for patent infringement merely by running
7886 @command{compress}.
7887
7888 @opindex use-compress-program
7889 @item --use-compress-program=@var{prog}
7890 Use external compression program @var{prog}. Use this option if you
7891 have a compression program that @GNUTAR{} does not support. There
7892 are two requirements to which @var{prog} should comply:
7893
7894 First, when called without options, it should read data from standard
7895 input, compress it and output it on standard output.
7896
7897 Secondly, if called with @option{-d} argument, it should do exactly
7898 the opposite, i.e., read the compressed data from the standard input
7899 and produce uncompressed data on the standard output.
7900 @end table
7901
7902 @cindex gpg, using with tar
7903 @cindex gnupg, using with tar
7904 @cindex Using encrypted archives
7905 The @option{--use-compress-program} option, in particular, lets you
7906 implement your own filters, not necessarily dealing with
7907 compression/decompression. For example, suppose you wish to implement
7908 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
7909 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
7910 Manual}). The following script does that:
7911
7912 @smallexample
7913 @group
7914 #! /bin/sh
7915 case $1 in
7916 -d) gpg --decrypt - | gzip -d -c;;
7917 '') gzip -c | gpg -s ;;
7918 *) echo "Unknown option $1">&2; exit 1;;
7919 esac
7920 @end group
7921 @end smallexample
7922
7923 Suppose you name it @file{gpgz} and save it somewhere in your
7924 @env{PATH}. Then the following command will create a compressed
7925 archive signed with your private key:
7926
7927 @smallexample
7928 $ @kbd{tar -cf foo.tar.gpgz --use-compress=gpgz .}
7929 @end smallexample
7930
7931 @noindent
7932 Likewise, the following command will list its contents:
7933
7934 @smallexample
7935 $ @kbd{tar -tf foo.tar.gpgz --use-compress=gpgz .}
7936 @end smallexample
7937
7938 @ignore
7939 The above is based on the following discussion:
7940
7941 I have one question, or maybe it's a suggestion if there isn't a way
7942 to do it now. I would like to use @option{--gzip}, but I'd also like
7943 the output to be fed through a program like @acronym{GNU}
7944 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
7945 to use :-)), basically adding ECC protection on top of compression.
7946 It seems as if this should be quite easy to do, but I can't work out
7947 exactly how to go about it. Of course, I can pipe the standard output
7948 of @command{tar} through @command{ecc}, but then I lose (though I
7949 haven't started using it yet, I confess) the ability to have
7950 @command{tar} use @command{rmt} for it's I/O (I think).
7951
7952 I think the most straightforward thing would be to let me specify a
7953 general set of filters outboard of compression (preferably ordered,
7954 so the order can be automatically reversed on input operations, and
7955 with the options they require specifiable), but beggars shouldn't be
7956 choosers and anything you decide on would be fine with me.
7957
7958 By the way, I like @command{ecc} but if (as the comments say) it can't
7959 deal with loss of block sync, I'm tempted to throw some time at adding
7960 that capability. Supposing I were to actually do such a thing and
7961 get it (apparently) working, do you accept contributed changes to
7962 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
7963
7964 Isn't that exactly the role of the
7965 @option{--use-compress-prog=@var{program}} option?
7966 I never tried it myself, but I suspect you may want to write a
7967 @var{prog} script or program able to filter stdin to stdout to
7968 way you want. It should recognize the @option{-d} option, for when
7969 extraction is needed rather than creation.
7970
7971 It has been reported that if one writes compressed data (through the
7972 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
7973 the DLT compression mode, the data will actually get bigger and one will
7974 end up with less space on the tape.
7975 @end ignore
7976
7977 @node sparse
7978 @subsection Archiving Sparse Files
7979 @cindex Sparse Files
7980
7981 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
7982 in a file is a section of the file's contents which was never written.
7983 The contents of a hole reads as all zeros. On many operating systems,
7984 actual disk storage is not allocated for holes, but they are counted
7985 in the length of the file. If you archive such a file, @command{tar}
7986 could create an archive longer than the original. To have @command{tar}
7987 attempt to recognize the holes in a file, use @option{--sparse}
7988 (@option{-S}). When you use this option, then, for any file using
7989 less disk space than would be expected from its length, @command{tar}
7990 searches the file for consecutive stretches of zeros. It then records
7991 in the archive for the file where the consecutive stretches of zeros
7992 are, and only archives the ``real contents'' of the file. On
7993 extraction (using @option{--sparse} is not needed on extraction) any
7994 such files have holes created wherever the continuous stretches of zeros
7995 were found. Thus, if you use @option{--sparse}, @command{tar} archives
7996 won't take more space than the original.
7997
7998 @table @option
7999 @opindex sparse
8000 @item -S
8001 @itemx --sparse
8002 This option instructs @command{tar} to test each file for sparseness
8003 before attempting to archive it. If the file is found to be sparse it
8004 is treated specially, thus allowing to decrease the amount of space
8005 used by its image in the archive.
8006
8007 This option is meaningful only when creating or updating archives. It
8008 has no effect on extraction.
8009 @end table
8010
8011 Consider using @option{--sparse} when performing file system backups,
8012 to avoid archiving the expanded forms of files stored sparsely in the
8013 system.
8014
8015 Even if your system has no sparse files currently, some may be
8016 created in the future. If you use @option{--sparse} while making file
8017 system backups as a matter of course, you can be assured the archive
8018 will never take more space on the media than the files take on disk
8019 (otherwise, archiving a disk filled with sparse files might take
8020 hundreds of tapes). @xref{Incremental Dumps}.
8021
8022 However, be aware that @option{--sparse} option presents a serious
8023 drawback. Namely, in order to determine if the file is sparse
8024 @command{tar} has to read it before trying to archive it, so in total
8025 the file is read @strong{twice}. So, always bear in mind that the
8026 time needed to process all files with this option is roughly twice
8027 the time needed to archive them without it.
8028 @FIXME{A technical note:
8029
8030 Programs like @command{dump} do not have to read the entire file; by
8031 examining the file system directly, they can determine in advance
8032 exactly where the holes are and thus avoid reading through them. The
8033 only data it need read are the actual allocated data blocks.
8034 @GNUTAR{} uses a more portable and straightforward
8035 archiving approach, it would be fairly difficult that it does
8036 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
8037 1990-12-10:
8038
8039 @quotation
8040 What I did say is that you cannot tell the difference between a hole and an
8041 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
8042 best tells you how many holes there are; it doesn't tell you @emph{where}.
8043 Just as programs may, conceivably, care what @code{st_blocks} is (care
8044 to name one that does?), they may also care where the holes are (I have
8045 no examples of this one either, but it's equally imaginable).
8046
8047 I conclude from this that good archivers are not portable. One can
8048 arguably conclude that if you want a portable program, you can in good
8049 conscience restore files with as many holes as possible, since you can't
8050 get it right.
8051 @end quotation
8052 }
8053
8054 @cindex sparse formats, defined
8055 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
8056 sparse files using in three distinct ways, called @dfn{sparse
8057 formats}. A sparse format is identified by its @dfn{number},
8058 consisting, as usual of two decimal numbers, delimited by a dot. By
8059 default, format @samp{1.0} is used. If, for some reason, you wish to
8060 use an earlier format, you can select it using
8061 @option{--sparse-version} option.
8062
8063 @table @option
8064 @opindex sparse-version
8065 @item --sparse-version=@var{version}
8066
8067 Select the format to store sparse files in. Valid @var{version} values
8068 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
8069 for a detailed description of each format.
8070 @end table
8071
8072 Using @option{--sparse-format} option implies @option{--sparse}.
8073
8074 @node Attributes
8075 @section Handling File Attributes
8076 @UNREVISED
8077
8078 When @command{tar} reads files, it updates their access times. To
8079 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
8080 reset the access time retroactively or avoid changing it in the first
8081 place.
8082
8083 Handling of file attributes
8084
8085 @table @option
8086 @opindex atime-preserve
8087 @item --atime-preserve
8088 @itemx --atime-preserve=replace
8089 @itemx --atime-preserve=system
8090 Preserve the access times of files that are read. This works only for
8091 files that you own, unless you have superuser privileges.
8092
8093 @option{--atime-preserve=replace} works on most systems, but it also
8094 restores the data modification time and updates the status change
8095 time. Hence it doesn't interact with incremental dumps nicely
8096 (@pxref{Incremental Dumps}), and it can set access or data modification times
8097 incorrectly if other programs access the file while @command{tar} is
8098 running.
8099
8100 @option{--atime-preserve=system} avoids changing the access time in
8101 the first place, if the operating system supports this.
8102 Unfortunately, this may or may not work on any given operating system
8103 or file system. If @command{tar} knows for sure it won't work, it
8104 complains right away.
8105
8106 Currently @option{--atime-preserve} with no operand defaults to
8107 @option{--atime-preserve=replace}, but this is intended to change to
8108 @option{--atime-preserve=system} when the latter is better-supported.
8109
8110 @opindex touch
8111 @item -m
8112 @itemx --touch
8113 Do not extract data modification time.
8114
8115 When this option is used, @command{tar} leaves the data modification times
8116 of the files it extracts as the times when the files were extracted,
8117 instead of setting it to the times recorded in the archive.
8118
8119 This option is meaningless with @option{--list} (@option{-t}).
8120
8121 @opindex same-owner
8122 @item --same-owner
8123 Create extracted files with the same ownership they have in the
8124 archive.
8125
8126 This is the default behavior for the superuser,
8127 so this option is meaningful only for non-root users, when @command{tar}
8128 is executed on those systems able to give files away. This is
8129 considered as a security flaw by many people, at least because it
8130 makes quite difficult to correctly account users for the disk space
8131 they occupy. Also, the @code{suid} or @code{sgid} attributes of
8132 files are easily and silently lost when files are given away.
8133
8134 When writing an archive, @command{tar} writes the user id and user name
8135 separately. If it can't find a user name (because the user id is not
8136 in @file{/etc/passwd}), then it does not write one. When restoring,
8137 it tries to look the name (if one was written) up in
8138 @file{/etc/passwd}. If it fails, then it uses the user id stored in
8139 the archive instead.
8140
8141 @opindex no-same-owner
8142 @item --no-same-owner
8143 @itemx -o
8144 Do not attempt to restore ownership when extracting. This is the
8145 default behavior for ordinary users, so this option has an effect
8146 only for the superuser.
8147
8148 @opindex numeric-owner
8149 @item --numeric-owner
8150 The @option{--numeric-owner} option allows (ANSI) archives to be written
8151 without user/group name information or such information to be ignored
8152 when extracting. It effectively disables the generation and/or use
8153 of user/group name information. This option forces extraction using
8154 the numeric ids from the archive, ignoring the names.
8155
8156 This is useful in certain circumstances, when restoring a backup from
8157 an emergency floppy with different passwd/group files for example.
8158 It is otherwise impossible to extract files with the right ownerships
8159 if the password file in use during the extraction does not match the
8160 one belonging to the file system(s) being extracted. This occurs,
8161 for example, if you are restoring your files after a major crash and
8162 had booted from an emergency floppy with no password file or put your
8163 disk into another machine to do the restore.
8164
8165 The numeric ids are @emph{always} saved into @command{tar} archives.
8166 The identifying names are added at create time when provided by the
8167 system, unless @option{--old-archive} (@option{-o}) is used. Numeric ids could be
8168 used when moving archives between a collection of machines using
8169 a centralized management for attribution of numeric ids to users
8170 and groups. This is often made through using the NIS capabilities.
8171
8172 When making a @command{tar} file for distribution to other sites, it
8173 is sometimes cleaner to use a single owner for all files in the
8174 distribution, and nicer to specify the write permission bits of the
8175 files as stored in the archive independently of their actual value on
8176 the file system. The way to prepare a clean distribution is usually
8177 to have some Makefile rule creating a directory, copying all needed
8178 files in that directory, then setting ownership and permissions as
8179 wanted (there are a lot of possible schemes), and only then making a
8180 @command{tar} archive out of this directory, before cleaning
8181 everything out. Of course, we could add a lot of options to
8182 @GNUTAR{} for fine tuning permissions and ownership.
8183 This is not the good way, I think. @GNUTAR{} is
8184 already crowded with options and moreover, the approach just explained
8185 gives you a great deal of control already.
8186
8187 @xopindex{same-permissions, short description}
8188 @xopindex{preserve-permissions, short description}
8189 @item -p
8190 @itemx --same-permissions
8191 @itemx --preserve-permissions
8192 Extract all protection information.
8193
8194 This option causes @command{tar} to set the modes (access permissions) of
8195 extracted files exactly as recorded in the archive. If this option
8196 is not used, the current @code{umask} setting limits the permissions
8197 on extracted files. This option is by default enabled when
8198 @command{tar} is executed by a superuser.
8199
8200
8201 This option is meaningless with @option{--list} (@option{-t}).
8202
8203 @opindex preserve
8204 @item --preserve
8205 Same as both @option{--same-permissions} and @option{--same-order}.
8206
8207 The @option{--preserve} option has no equivalent short option name.
8208 It is equivalent to @option{--same-permissions} plus @option{--same-order}.
8209
8210 @FIXME{I do not see the purpose of such an option. (Neither I. FP.)
8211 Neither do I. --Sergey}
8212
8213 @end table
8214
8215 @node Portability
8216 @section Making @command{tar} Archives More Portable
8217
8218 Creating a @command{tar} archive on a particular system that is meant to be
8219 useful later on many other machines and with other versions of @command{tar}
8220 is more challenging than you might think. @command{tar} archive formats
8221 have been evolving since the first versions of Unix. Many such formats
8222 are around, and are not always compatible with each other. This section
8223 discusses a few problems, and gives some advice about making @command{tar}
8224 archives more portable.
8225
8226 One golden rule is simplicity. For example, limit your @command{tar}
8227 archives to contain only regular files and directories, avoiding
8228 other kind of special files. Do not attempt to save sparse files or
8229 contiguous files as such. Let's discuss a few more problems, in turn.
8230
8231 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
8232 archives and archive labels) in GNU and PAX formats.}
8233
8234 @menu
8235 * Portable Names:: Portable Names
8236 * dereference:: Symbolic Links
8237 * old:: Old V7 Archives
8238 * ustar:: Ustar Archives
8239 * gnu:: GNU and old GNU format archives.
8240 * posix:: @acronym{POSIX} archives
8241 * Checksumming:: Checksumming Problems
8242 * Large or Negative Values:: Large files, negative time stamps, etc.
8243 * Other Tars:: How to Extract GNU-Specific Data Using
8244 Other @command{tar} Implementations
8245 @end menu
8246
8247 @node Portable Names
8248 @subsection Portable Names
8249
8250 Use portable file and member names. A name is portable if it contains
8251 only ASCII letters and digits, @samp{/}, @samp{.}, @samp{_}, and
8252 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
8253 contain @samp{/-}. Avoid deep directory nesting. For portability to
8254 old Unix hosts, limit your file name components to 14 characters or
8255 less.
8256
8257 If you intend to have your @command{tar} archives to be read under
8258 MSDOS, you should not rely on case distinction for file names, and you
8259 might use the @acronym{GNU} @command{doschk} program for helping you
8260 further diagnosing illegal MSDOS names, which are even more limited
8261 than System V's.
8262
8263 @node dereference
8264 @subsection Symbolic Links
8265 @cindex File names, using symbolic links
8266 @cindex Symbolic link as file name
8267
8268 @opindex dereference
8269 Normally, when @command{tar} archives a symbolic link, it writes a
8270 block to the archive naming the target of the link. In that way, the
8271 @command{tar} archive is a faithful record of the file system contents.
8272 @option{--dereference} (@option{-h}) is used with @option{--create} (@option{-c}), and causes
8273 @command{tar} to archive the files symbolic links point to, instead of
8274 the links themselves. When this option is used, when @command{tar}
8275 encounters a symbolic link, it will archive the linked-to file,
8276 instead of simply recording the presence of a symbolic link.
8277
8278 The name under which the file is stored in the file system is not
8279 recorded in the archive. To record both the symbolic link name and
8280 the file name in the system, archive the file under both names. If
8281 all links were recorded automatically by @command{tar}, an extracted file
8282 might be linked to a file name that no longer exists in the file
8283 system.
8284
8285 If a linked-to file is encountered again by @command{tar} while creating
8286 the same archive, an entire second copy of it will be stored. (This
8287 @emph{might} be considered a bug.)
8288
8289 So, for portable archives, do not archive symbolic links as such,
8290 and use @option{--dereference} (@option{-h}): many systems do not support
8291 symbolic links, and moreover, your distribution might be unusable if
8292 it contains unresolved symbolic links.
8293
8294 @node old
8295 @subsection Old V7 Archives
8296 @cindex Format, old style
8297 @cindex Old style format
8298 @cindex Old style archives
8299 @cindex v7 archive format
8300
8301 Certain old versions of @command{tar} cannot handle additional
8302 information recorded by newer @command{tar} programs. To create an
8303 archive in V7 format (not ANSI), which can be read by these old
8304 versions, specify the @option{--format=v7} option in
8305 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
8306 accepts @option{--portability} or @option{--old-archive} for this
8307 option). When you specify it,
8308 @command{tar} leaves out information about directories, pipes, fifos,
8309 contiguous files, and device files, and specifies file ownership by
8310 group and user IDs instead of group and user names.
8311
8312 When updating an archive, do not use @option{--format=v7}
8313 unless the archive was created using this option.
8314
8315 In most cases, a @emph{new} format archive can be read by an @emph{old}
8316 @command{tar} program without serious trouble, so this option should
8317 seldom be needed. On the other hand, most modern @command{tar}s are
8318 able to read old format archives, so it might be safer for you to
8319 always use @option{--format=v7} for your distributions. Notice,
8320 however, that @samp{ustar} format is a better alternative, as it is
8321 free from many of @samp{v7}'s drawbacks.
8322
8323 @node ustar
8324 @subsection Ustar Archive Format
8325
8326 @cindex ustar archive format
8327 Archive format defined by @acronym{POSIX}.1-1988 specification is called
8328 @code{ustar}. Although it is more flexible than the V7 format, it
8329 still has many restrictions (@xref{Formats,ustar}, for the detailed
8330 description of @code{ustar} format). Along with V7 format,
8331 @code{ustar} format is a good choice for archives intended to be read
8332 with other implementations of @command{tar}.
8333
8334 To create archive in @code{ustar} format, use @option{--format=ustar}
8335 option in conjunction with the @option{--create} (@option{-c}).
8336
8337 @node gnu
8338 @subsection @acronym{GNU} and old @GNUTAR{} format
8339
8340 @cindex GNU archive format
8341 @cindex Old GNU archive format
8342 @GNUTAR{} was based on an early draft of the
8343 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
8344 @command{tar}, such as the support for file names longer than 100
8345 characters, use portions of the @command{tar} header record which were
8346 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
8347 @acronym{POSIX} have allocated the same parts of the header record for
8348 other purposes. As a result, @GNUTAR{} format is
8349 incompatible with the current @acronym{POSIX} specification, and with
8350 @command{tar} programs that follow it.
8351
8352 In the majority of cases, @command{tar} will be configured to create
8353 this format by default. This will change in the future releases, since
8354 we plan to make @samp{POSIX} format the default.
8355
8356 To force creation a @GNUTAR{} archive, use option
8357 @option{--format=gnu}.
8358
8359 @node posix
8360 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
8361
8362 @cindex POSIX archive format
8363 @cindex PAX archive format
8364 Starting from version 1.14 @GNUTAR{} features full support for
8365 @acronym{POSIX.1-2001} archives.
8366
8367 A @acronym{POSIX} conformant archive will be created if @command{tar}
8368 was given @option{--format=posix} (@option{--format=pax}) option. No
8369 special option is required to read and extract from a @acronym{POSIX}
8370 archive.
8371
8372 @menu
8373 * PAX keywords:: Controlling Extended Header Keywords.
8374 @end menu
8375
8376 @node PAX keywords
8377 @subsubsection Controlling Extended Header Keywords
8378
8379 @table @option
8380 @opindex pax-option
8381 @item --pax-option=@var{keyword-list}
8382 Handle keywords in @acronym{PAX} extended headers. This option is
8383 equivalent to @option{-o} option of the @command{pax} utility.
8384 @end table
8385
8386 @var{Keyword-list} is a comma-separated
8387 list of keyword options, each keyword option taking one of
8388 the following forms:
8389
8390 @table @code
8391 @item delete=@var{pattern}
8392 When used with one of archive-creation commands,
8393 this option instructs @command{tar} to omit from extended header records
8394 that it produces any keywords matching the string @var{pattern}.
8395
8396 When used in extract or list mode, this option instructs tar
8397 to ignore any keywords matching the given @var{pattern} in the extended
8398 header records. In both cases, matching is performed using the pattern
8399 matching notation described in @acronym{POSIX 1003.2}, 3.13
8400 (@pxref{wildcards}). For example:
8401
8402 @smallexample
8403 --pax-option delete=security.*
8404 @end smallexample
8405
8406 would suppress security-related information.
8407
8408 @item exthdr.name=@var{string}
8409
8410 This keyword allows user control over the name that is written into the
8411 ustar header blocks for the extended headers. The name is obtained
8412 from @var{string} after making the following substitutions:
8413
8414 @multitable @columnfractions .25 .55
8415 @headitem Meta-character @tab Replaced By
8416 @item %d @tab The directory name of the file, equivalent to the
8417 result of the @command{dirname} utility on the translated pathname.
8418 @item %f @tab The filename of the file, equivalent to the result
8419 of the @command{basename} utility on the translated pathname.
8420 @item %p @tab The process ID of the @command{tar} process.
8421 @item %% @tab A @samp{%} character.
8422 @end multitable
8423
8424 Any other @samp{%} characters in @var{string} produce undefined
8425 results.
8426
8427 If no option @samp{exthdr.name=string} is specified, @command{tar}
8428 will use the following default value:
8429
8430 @smallexample
8431 %d/PaxHeaders.%p/%f
8432 @end smallexample
8433
8434 @item globexthdr.name=@var{string}
8435 This keyword allows user control over the name that is written into
8436 the ustar header blocks for global extended header records. The name
8437 is obtained from the contents of @var{string}, after making
8438 the following substitutions:
8439
8440 @multitable @columnfractions .25 .55
8441 @headitem Meta-character @tab Replaced By
8442 @item %n @tab An integer that represents the
8443 sequence number of the global extended header record in the archive,
8444 starting at 1.
8445 @item %p @tab The process ID of the @command{tar} process.
8446 @item %% @tab A @samp{%} character.
8447 @end multitable
8448
8449 Any other @samp{%} characters in @var{string} produce undefined results.
8450
8451 If no option @samp{globexthdr.name=string} is specified, @command{tar}
8452 will use the following default value:
8453
8454 @smallexample
8455 $TMPDIR/GlobalHead.%p.%n
8456 @end smallexample
8457
8458 @noindent
8459 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
8460 environment variable. If @var{TMPDIR} is not set, @command{tar}
8461 uses @samp{/tmp}.
8462
8463 @item @var{keyword}=@var{value}
8464 When used with one of archive-creation commands, these keyword/value pairs
8465 will be included at the beginning of the archive in a global extended
8466 header record. When used with one of archive-reading commands,
8467 @command{tar} will behave as if it has encountered these keyword/value
8468 pairs at the beginning of the archive in a global extended header
8469 record.
8470
8471 @item @var{keyword}:=@var{value}
8472 When used with one of archive-creation commands, these keyword/value pairs
8473 will be included as records at the beginning of an extended header for
8474 each file. This is effectively equivalent to @var{keyword}=@var{value}
8475 form except that it creates no global extended header records.
8476
8477 When used with one of archive-reading commands, @command{tar} will
8478 behave as if these keyword/value pairs were included as records at the
8479 end of each extended header; thus, they will override any global or
8480 file-specific extended header record keywords of the same names.
8481 For example, in the command:
8482
8483 @smallexample
8484 tar --format=posix --create \
8485 --file archive --pax-option gname:=user .
8486 @end smallexample
8487
8488 the group name will be forced to a new value for all files
8489 stored in the archive.
8490 @end table
8491
8492 @node Checksumming
8493 @subsection Checksumming Problems
8494
8495 SunOS and HP-UX @command{tar} fail to accept archives created using
8496 @GNUTAR{} and containing non-ASCII file names, that
8497 is, file names having characters with the eight bit set, because they
8498 use signed checksums, while @GNUTAR{} uses unsigned
8499 checksums while creating archives, as per @acronym{POSIX} standards. On
8500 reading, @GNUTAR{} computes both checksums and
8501 accept any. It is somewhat worrying that a lot of people may go
8502 around doing backup of their files using faulty (or at least
8503 non-standard) software, not learning about it until it's time to
8504 restore their missing files with an incompatible file extractor, or
8505 vice versa.
8506
8507 @GNUTAR{} compute checksums both ways, and accept
8508 any on read, so @acronym{GNU} tar can read Sun tapes even with their
8509 wrong checksums. @GNUTAR{} produces the standard
8510 checksum, however, raising incompatibilities with Sun. That is to
8511 say, @GNUTAR{} has not been modified to
8512 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
8513 I've been told that more recent Sun @command{tar} now read standard
8514 archives, so maybe Sun did a similar patch, after all?
8515
8516 The story seems to be that when Sun first imported @command{tar}
8517 sources on their system, they recompiled it without realizing that
8518 the checksums were computed differently, because of a change in
8519 the default signing of @code{char}'s in their compiler. So they
8520 started computing checksums wrongly. When they later realized their
8521 mistake, they merely decided to stay compatible with it, and with
8522 themselves afterwards. Presumably, but I do not really know, HP-UX
8523 has chosen that their @command{tar} archives to be compatible with Sun's.
8524 The current standards do not favor Sun @command{tar} format. In any
8525 case, it now falls on the shoulders of SunOS and HP-UX users to get
8526 a @command{tar} able to read the good archives they receive.
8527
8528 @node Large or Negative Values
8529 @subsection Large or Negative Values
8530 @cindex large values
8531 @cindex future time stamps
8532 @cindex negative time stamps
8533 @UNREVISED{}
8534
8535 The above sections suggest to use @samp{oldest possible} archive
8536 format if in doubt. However, sometimes it is not possible. If you
8537 attempt to archive a file whose metadata cannot be represented using
8538 required format, @GNUTAR{} will print error message and ignore such a
8539 file. You will than have to switch to a format that is able to
8540 handle such values. The format summary table (@pxref{Formats}) will
8541 help you to do so.
8542
8543 In particular, when trying to archive files larger than 8GB or with
8544 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
8545 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
8546 @acronym{POSIX} archive formats. When considering which format to
8547 choose, bear in mind that the @acronym{GNU} format uses
8548 two's-complement base-256 notation to store values that do not fit
8549 into standard @acronym{ustar} range. Such archives can generally be
8550 read only by a @GNUTAR{} implementation. Moreover, they sometimes
8551 cannot be correctly restored on another hosts even by @GNUTAR{}. For
8552 example, using two's complement representation for negative time
8553 stamps that assumes a signed 32-bit @code{time_t} generates archives
8554 that are not portable to hosts with differing @code{time_t}
8555 representations.
8556
8557 On the other hand, @acronym{POSIX} archives, generally speaking, can
8558 be extracted by any tar implementation that understands older
8559 @acronym{ustar} format. The only exception are files larger than 8GB.
8560
8561 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
8562 POSIX-aware tars.}
8563
8564 @node Other Tars
8565 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
8566
8567 In previous sections you became acquainted with various quirks
8568 necessary to make your archives portable. Sometimes you may need to
8569 extract archives containing GNU-specific members using some
8570 third-party @command{tar} implementation or an older version of
8571 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
8572 but if it is for some reason impossible, this section will explain
8573 how to cope without it.
8574
8575 When we speak about @dfn{GNU-specific} members we mean two classes of
8576 them: members split between the volumes of a multi-volume archive and
8577 sparse members. You will be able to always recover such members if
8578 the archive is in PAX format. In addition split members can be
8579 recovered from archives in old GNU format. The following subsections
8580 describe the required procedures in detail.
8581
8582 @menu
8583 * Split Recovery:: Members Split Between Volumes
8584 * Sparse Recovery:: Sparse Members
8585 @end menu
8586
8587 @node Split Recovery
8588 @subsubsection Extracting Members Split Between Volumes
8589
8590 @cindex Mutli-volume archives, extracting using non-GNU tars
8591 If a member is split between several volumes of an old GNU format archive
8592 most third party @command{tar} implementation will fail to extract
8593 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
8594 This program is available from
8595 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
8596 home page}. It concatenates several archive volumes into a single
8597 valid archive. For example, if you have three volumes named from
8598 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
8599 extract them using a third-party @command{tar}:
8600
8601 @smallexample
8602 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
8603 @end smallexample
8604
8605 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
8606 You could use this approach for most (although not all) PAX
8607 format archives as well. However, extracting split members from a PAX
8608 archive is a much easier task, because PAX volumes are constructed in
8609 such a way that each part of a split member is extracted to a
8610 different file by @command{tar} implementations that are not aware of
8611 GNU extensions. More specifically, the very first part retains its
8612 original name, and all subsequent parts are named using the pattern:
8613
8614 @smallexample
8615 %d/GNUFileParts.%p/%f.%n
8616 @end smallexample
8617
8618 @noindent
8619 where symbols preceeded by @samp{%} are @dfn{macro characters} that
8620 have the following meaning:
8621
8622 @multitable @columnfractions .25 .55
8623 @headitem Meta-character @tab Replaced By
8624 @item %d @tab The directory name of the file, equivalent to the
8625 result of the @command{dirname} utility on its full name.
8626 @item %f @tab The file name of the file, equivalent to the result
8627 of the @command{basename} utility on its full name.
8628 @item %p @tab The process ID of the @command{tar} process that
8629 created the archive.
8630 @item %n @tab Ordinal number of this particular part.
8631 @end multitable
8632
8633 For example, if the file @file{var/longfile} was split during archive
8634 creation between three volumes, and the creator @command{tar} process
8635 had process ID @samp{27962}, then the member names will be:
8636
8637 @smallexample
8638 var/longfile
8639 var/GNUFileParts.27962/longfile.1
8640 var/GNUFileParts.27962/longfile.2
8641 @end smallexample
8642
8643 When you extract your archive using a third-party @command{tar}, these
8644 files will be created on your disk, and the only thing you will need
8645 to do to restore your file in its original form is concatenate them in
8646 the proper order, for example:
8647
8648 @smallexample
8649 @group
8650 $ @kbd{cd var}
8651 $ @kbd{cat GNUFileParts.27962/longfile.1 \
8652 GNUFileParts.27962/longfile.2 >> longfile}
8653 $ rm -f GNUFileParts.27962
8654 @end group
8655 @end smallexample
8656
8657 Notice, that if the @command{tar} implementation you use supports PAX
8658 format archives, it will probably emit warnings about unknown keywords
8659 during extraction. They will look like this:
8660
8661 @smallexample
8662 @group
8663 Tar file too small
8664 Unknown extended header keyword 'GNU.volume.filename' ignored.
8665 Unknown extended header keyword 'GNU.volume.size' ignored.
8666 Unknown extended header keyword 'GNU.volume.offset' ignored.
8667 @end group
8668 @end smallexample
8669
8670 @noindent
8671 You can safely ignore these warnings.
8672
8673 If your @command{tar} implementation is not PAX-aware, you will get
8674 more warnings and more files generated on your disk, e.g.:
8675
8676 @smallexample
8677 @group
8678 $ @kbd{tar xf vol-1.tar}
8679 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
8680 normal file
8681 Unexpected EOF in archive
8682 $ @kbd{tar xf vol-2.tar}
8683 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
8684 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
8685 'x', extracted as normal file
8686 @end group
8687 @end smallexample
8688
8689 Ignore these warnings. The @file{PaxHeaders.*} directories created
8690 will contain files with @dfn{extended header keywords} describing the
8691 extracted files. You can delete them, unless they describe sparse
8692 members. Read further to learn more about them.
8693
8694 @node Sparse Recovery
8695 @subsubsection Extracting Sparse Members
8696
8697 @cindex sparse files, extracting with non-GNU tars
8698 Any @command{tar} implementation will be able to extract sparse members from a
8699 PAX archive. However, the extracted files will be @dfn{condensed},
8700 i.e., any zero blocks will be removed from them. When we restore such
8701 a condensed file to its original form, by adding zero bloks (or
8702 @dfn{holes}) back to their original locations, we call this process
8703 @dfn{expanding} a compressed sparse file.
8704
8705 @pindex xsparse
8706 To expand a file, you will need a simple auxiliary program called
8707 @command{xsparse}. It is available in source form from
8708 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
8709 home page}.
8710
8711 @cindex sparse files v.1.0, extracting with non-GNU tars
8712 Let's begin with archive members in @dfn{sparse format
8713 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
8714 The condensed file will contain both file map and file data, so no
8715 additional data will be needed to restore it. If the original file
8716 name was @file{@var{dir}/@var{name}}, then the condensed file will be
8717 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
8718 @var{n} is a decimal number@footnote{technically speaking, @var{n} is a
8719 @dfn{process ID} of the @command{tar} process which created the
8720 archive (@pxref{PAX keywords}).}.
8721
8722 To expand a version 1.0 file, run @command{xsparse} as follows:
8723
8724 @smallexample
8725 $ @kbd{xsparse @file{cond-file}}
8726 @end smallexample
8727
8728 @noindent
8729 where @file{cond-file} is the name of the condensed file. The utility
8730 will deduce the name for the resulting expanded file using the
8731 following algorithm:
8732
8733 @enumerate 1
8734 @item If @file{cond-file} does not contain any directories,
8735 @file{../cond-file} will be used;
8736
8737 @item If @file{cond-file} has the form
8738 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
8739 are simple names, with no @samp{/} characters in them, the output file
8740 name will be @file{@var{dir}/@var{name}}.
8741
8742 @item Otherwise, if @file{cond-file} has the form
8743 @file{@var{dir}/@var{name}}, the output file name will be
8744 @file{@var{name}}.
8745 @end enumerate
8746
8747 In the unlikely case when this algorithm does not suite your needs,
8748 you can explicitly specify output file name as a second argument to
8749 the command:
8750
8751 @smallexample
8752 $ @kbd{xsparse @file{cond-file} @file{out-file}}
8753 @end smallexample
8754
8755 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
8756 first. In this mode, the command does not actually expand the file,
8757 but verbosely lists all actions it would be taking to do so. The dry
8758 run mode is enabled by @option{-n} command line argument:
8759
8760 @smallexample
8761 @group
8762 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
8763 Reading v.1.0 sparse map
8764 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8765 `/home/gray/sparsefile'
8766 Finished dry run
8767 @end group
8768 @end smallexample
8769
8770 To actually expand the file, you would run:
8771
8772 @smallexample
8773 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
8774 @end smallexample
8775
8776 @noindent
8777 The program behaves the same way all UNIX utilities do: it will keep
8778 quiet unless it has simething important to tell you (e.g. an error
8779 condition or something). If you wish it to produce verbose output,
8780 similar to that from the dry run mode, use @option{-v} option:
8781
8782 @smallexample
8783 @group
8784 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
8785 Reading v.1.0 sparse map
8786 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8787 `/home/gray/sparsefile'
8788 Done
8789 @end group
8790 @end smallexample
8791
8792 Additionally, if your @command{tar} implementation has extracted the
8793 @dfn{extended headers} for this file, you can instruct @command{xstar}
8794 to use them in order to verify the integrity of the expanded file.
8795 The option @option{-x} sets the name of the extended header file to
8796 use. Continuing our example:
8797
8798 @smallexample
8799 @group
8800 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
8801 /home/gray/GNUSparseFile.6058/sparsefile}
8802 Reading extended header file
8803 Found variable GNU.sparse.major = 1
8804 Found variable GNU.sparse.minor = 0
8805 Found variable GNU.sparse.name = sparsefile
8806 Found variable GNU.sparse.realsize = 217481216
8807 Reading v.1.0 sparse map
8808 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
8809 `/home/gray/sparsefile'
8810 Done
8811 @end group
8812 @end smallexample
8813
8814 @anchor{extracting sparse v.0.x}
8815 @cindex sparse files v.0.1, extracting with non-GNU tars
8816 @cindex sparse files v.0.0, extracting with non-GNU tars
8817 An @dfn{extended header} is a special @command{tar} archive header
8818 that precedes an archive member and contains a set of
8819 @dfn{variables}, describing the member properties that cannot be
8820 stored in the standard @code{ustar} header. While optional for
8821 expanding sparse version 1.0 members, use of extended headers is
8822 mandatory when expanding sparse members in older sparse formats: v.0.0
8823 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
8824 Formats}.) So, for this format, the question is: how to obtain
8825 extended headers from the archive?
8826
8827 If you use a @command{tar} implementation that does not support PAX
8828 format, extended headers for each member will be extracted as a
8829 separate file. If we represent the member name as
8830 @file{@var{dir}/@var{name}}, then the extended header file will be
8831 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
8832 @var{n} is an integer number.
8833
8834 Things become more difficult if your @command{tar} implementation
8835 does support PAX headers, because in this case you will have to
8836 manually extract the headers. We recommend the following algorithm:
8837
8838 @enumerate 1
8839 @item
8840 Consult the documentation of your @command{tar} implementation for an
8841 option that prints @dfn{block numbers} along with the archive
8842 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
8843 @command{star} has @option{-block-number}.
8844
8845 @item
8846 Obtain verbose listing using the @samp{block number} option, and
8847 find block numbers of the sparse member in question and the member
8848 immediately following it. For example, running @command{star} on our
8849 archive we obtain:
8850
8851 @smallexample
8852 @group
8853 $ @kbd{star -t -v -block-number -f arc.tar}
8854 @dots{}
8855 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
8856 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
8857 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
8858 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
8859 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
8860 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
8861 @dots{}
8862 @end group
8863 @end smallexample
8864
8865 @noindent
8866 (as usual, ignore the warnings about unknown keywords.)
8867
8868 @item
8869 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
8870 and @var{Bn} be the block number of the next member.
8871 Compute:
8872
8873 @smallexample
8874 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
8875 @end smallexample
8876
8877 @noindent
8878 This number gives the size of the extended header part in tar @dfn{blocks}.
8879 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
8880 = 7}.
8881
8882 @item
8883 Use @command{dd} to extract the headers:
8884
8885 @smallexample
8886 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
8887 @end smallexample
8888
8889 @noindent
8890 where @var{archive} is the archive name, @var{hname} is a name of the
8891 file to store the extended header in, @var{Bs} and @var{N} are
8892 computed in previous steps.
8893
8894 In our example, this command will be
8895
8896 @smallexample
8897 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
8898 @end smallexample
8899 @end enumerate
8900
8901 Finally, you can expand the condensed file, using the obtained header:
8902
8903 @smallexample
8904 @group
8905 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
8906 Reading extended header file
8907 Found variable GNU.sparse.size = 217481216
8908 Found variable GNU.sparse.numblocks = 208
8909 Found variable GNU.sparse.name = sparsefile
8910 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
8911 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
8912 Done
8913 @end group
8914 @end smallexample
8915
8916 @node cpio
8917 @section Comparison of @command{tar} and @command{cpio}
8918 @UNREVISED
8919
8920 @FIXME{Reorganize the following material}
8921
8922 The @command{cpio} archive formats, like @command{tar}, do have maximum
8923 pathname lengths. The binary and old ASCII formats have a max path
8924 length of 256, and the new ASCII and CRC ASCII formats have a max
8925 path length of 1024. @acronym{GNU} @command{cpio} can read and write archives
8926 with arbitrary pathname lengths, but other @command{cpio} implementations
8927 may crash unexplainedly trying to read them.
8928
8929 @command{tar} handles symbolic links in the form in which it comes in BSD;
8930 @command{cpio} doesn't handle symbolic links in the form in which it comes
8931 in System V prior to SVR4, and some vendors may have added symlinks
8932 to their system without enhancing @command{cpio} to know about them.
8933 Others may have enhanced it in a way other than the way I did it
8934 at Sun, and which was adopted by AT&T (and which is, I think, also
8935 present in the @command{cpio} that Berkeley picked up from AT&T and put
8936 into a later BSD release---I think I gave them my changes).
8937
8938 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
8939 can handle @command{tar} format input, and write it on output, and it
8940 probably handles symbolic links. They may not have bothered doing
8941 anything to enhance @command{tar} as a result.)
8942
8943 @command{cpio} handles special files; traditional @command{tar} doesn't.
8944
8945 @command{tar} comes with V7, System III, System V, and BSD source;
8946 @command{cpio} comes only with System III, System V, and later BSD
8947 (4.3-tahoe and later).
8948
8949 @command{tar}'s way of handling multiple hard links to a file can handle
8950 file systems that support 32-bit inumbers (e.g., the BSD file system);
8951 @command{cpio}s way requires you to play some games (in its "binary"
8952 format, i-numbers are only 16 bits, and in its "portable ASCII" format,
8953 they're 18 bits---it would have to play games with the "file system ID"
8954 field of the header to make sure that the file system ID/i-number pairs
8955 of different files were always different), and I don't know which
8956 @command{cpio}s, if any, play those games. Those that don't might get
8957 confused and think two files are the same file when they're not, and
8958 make hard links between them.
8959
8960 @command{tar}s way of handling multiple hard links to a file places only
8961 one copy of the link on the tape, but the name attached to that copy
8962 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
8963 way puts one copy for every link, but you can retrieve it using any
8964 of the names.
8965
8966 @quotation
8967 What type of check sum (if any) is used, and how is this calculated.
8968 @end quotation
8969
8970 See the attached manual pages for @command{tar} and @command{cpio} format.
8971 @command{tar} uses a checksum which is the sum of all the bytes in the
8972 @command{tar} header for a file; @command{cpio} uses no checksum.
8973
8974 @quotation
8975 If anyone knows why @command{cpio} was made when @command{tar} was present
8976 at the unix scene,
8977 @end quotation
8978
8979 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
8980 generally-available version of UNIX had @command{tar} at the time. I don't
8981 know whether any version that was generally available @emph{within AT&T}
8982 had @command{tar}, or, if so, whether the people within AT&T who did
8983 @command{cpio} knew about it.
8984
8985 On restore, if there is a corruption on a tape @command{tar} will stop at
8986 that point, while @command{cpio} will skip over it and try to restore the
8987 rest of the files.
8988
8989 The main difference is just in the command syntax and header format.
8990
8991 @command{tar} is a little more tape-oriented in that everything is blocked
8992 to start on a record boundary.
8993
8994 @quotation
8995 Is there any differences between the ability to recover crashed
8996 archives between the two of them. (Is there any chance of recovering
8997 crashed archives at all.)
8998 @end quotation
8999
9000 Theoretically it should be easier under @command{tar} since the blocking
9001 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
9002 However, modern @command{cpio}'s and variations have an option to just
9003 search for the next file header after an error with a reasonable chance
9004 of resyncing. However, lots of tape driver software won't allow you to
9005 continue past a media error which should be the only reason for getting
9006 out of sync unless a file changed sizes while you were writing the
9007 archive.
9008
9009 @quotation
9010 If anyone knows why @command{cpio} was made when @command{tar} was present
9011 at the unix scene, please tell me about this too.
9012 @end quotation
9013
9014 Probably because it is more media efficient (by not blocking everything
9015 and using only the space needed for the headers where @command{tar}
9016 always uses 512 bytes per file header) and it knows how to archive
9017 special files.
9018
9019 You might want to look at the freely available alternatives. The
9020 major ones are @command{afio}, @GNUTAR{}, and
9021 @command{pax}, each of which have their own extensions with some
9022 backwards compatibility.
9023
9024 Sparse files were @command{tar}red as sparse files (which you can
9025 easily test, because the resulting archive gets smaller, and
9026 @acronym{GNU} @command{cpio} can no longer read it).
9027
9028 @node Media
9029 @chapter Tapes and Other Archive Media
9030 @UNREVISED
9031
9032 A few special cases about tape handling warrant more detailed
9033 description. These special cases are discussed below.
9034
9035 Many complexities surround the use of @command{tar} on tape drives. Since
9036 the creation and manipulation of archives located on magnetic tape was
9037 the original purpose of @command{tar}, it contains many features making
9038 such manipulation easier.
9039
9040 Archives are usually written on dismountable media---tape cartridges,
9041 mag tapes, or floppy disks.
9042
9043 The amount of data a tape or disk holds depends not only on its size,
9044 but also on how it is formatted. A 2400 foot long reel of mag tape
9045 holds 40 megabytes of data when formatted at 1600 bits per inch. The
9046 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
9047
9048 Magnetic media are re-usable---once the archive on a tape is no longer
9049 needed, the archive can be erased and the tape or disk used over.
9050 Media quality does deteriorate with use, however. Most tapes or disks
9051 should be discarded when they begin to produce data errors. EXABYTE
9052 tape cartridges should be discarded when they generate an @dfn{error
9053 count} (number of non-usable bits) of more than 10k.
9054
9055 Magnetic media are written and erased using magnetic fields, and
9056 should be protected from such fields to avoid damage to stored data.
9057 Sticking a floppy disk to a filing cabinet using a magnet is probably
9058 not a good idea.
9059
9060 @menu
9061 * Device:: Device selection and switching
9062 * Remote Tape Server::
9063 * Common Problems and Solutions::
9064 * Blocking:: Blocking
9065 * Many:: Many archives on one tape
9066 * Using Multiple Tapes:: Using Multiple Tapes
9067 * label:: Including a Label in the Archive
9068 * verify::
9069 * Write Protection::
9070 @end menu
9071
9072 @node Device
9073 @section Device Selection and Switching
9074 @UNREVISED
9075
9076 @table @option
9077 @item -f [@var{hostname}:]@var{file}
9078 @itemx --file=[@var{hostname}:]@var{file}
9079 Use archive file or device @var{file} on @var{hostname}.
9080 @end table
9081
9082 This option is used to specify the file name of the archive @command{tar}
9083 works on.
9084
9085 If the file name is @samp{-}, @command{tar} reads the archive from standard
9086 input (when listing or extracting), or writes it to standard output
9087 (when creating). If the @samp{-} file name is given when updating an
9088 archive, @command{tar} will read the original archive from its standard
9089 input, and will write the entire new archive to its standard output.
9090
9091 If the file name contains a @samp{:}, it is interpreted as
9092 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
9093 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
9094 either case, @command{tar} will invoke the command @command{rsh} (or
9095 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
9096 machine. If you give an alternate login name, it will be given to the
9097 @command{rsh}.
9098 Naturally, the remote machine must have an executable
9099 @command{/usr/libexec/rmt}. This program is free software from the
9100 University of California, and a copy of the source code can be found
9101 with the sources for @command{tar}; it's compiled and installed by default.
9102 The exact path to this utility is determined when configuring the package.
9103 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
9104 your installation prefix. This location may also be overridden at
9105 runtime by using @option{rmt-command=@var{command}} option (@xref{Option Summary,
9106 ---rmt-command}, for detailed description of this option. @xref{Remote
9107 Tape Server}, for the description of @command{rmt} command).
9108
9109 If this option is not given, but the environment variable @env{TAPE}
9110 is set, its value is used; otherwise, old versions of @command{tar}
9111 used a default archive name (which was picked when @command{tar} was
9112 compiled). The default is normally set up to be the @dfn{first} tape
9113 drive or other transportable I/O medium on the system.
9114
9115 Starting with version 1.11.5, @GNUTAR{} uses
9116 standard input and standard output as the default device, and I will
9117 not try anymore supporting automatic device detection at installation
9118 time. This was failing really in too many cases, it was hopeless.
9119 This is now completely left to the installer to override standard
9120 input and standard output for default device, if this seems
9121 preferable. Further, I think @emph{most} actual usages of
9122 @command{tar} are done with pipes or disks, not really tapes,
9123 cartridges or diskettes.
9124
9125 Some users think that using standard input and output is running
9126 after trouble. This could lead to a nasty surprise on your screen if
9127 you forget to specify an output file name---especially if you are going
9128 through a network or terminal server capable of buffering large amounts
9129 of output. We had so many bug reports in that area of configuring
9130 default tapes automatically, and so many contradicting requests, that
9131 we finally consider the problem to be portably intractable. We could
9132 of course use something like @samp{/dev/tape} as a default, but this
9133 is @emph{also} running after various kind of trouble, going from hung
9134 processes to accidental destruction of real tapes. After having seen
9135 all this mess, using standard input and output as a default really
9136 sounds like the only clean choice left, and a very useful one too.
9137
9138 @GNUTAR{} reads and writes archive in records, I
9139 suspect this is the main reason why block devices are preferred over
9140 character devices. Most probably, block devices are more efficient
9141 too. The installer could also check for @samp{DEFTAPE} in
9142 @file{<sys/mtio.h>}.
9143
9144 @table @option
9145 @xopindex{force-local, short description}
9146 @item --force-local
9147 Archive file is local even if it contains a colon.
9148
9149 @opindex rsh-command
9150 @item --rsh-command=@var{command}
9151 Use remote @var{command} instead of @command{rsh}. This option exists
9152 so that people who use something other than the standard @command{rsh}
9153 (e.g., a Kerberized @command{rsh}) can access a remote device.
9154
9155 When this command is not used, the shell command found when
9156 the @command{tar} program was installed is used instead. This is
9157 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
9158 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
9159 The installer may have overridden this by defining the environment
9160 variable @env{RSH} @emph{at installation time}.
9161
9162 @item -[0-7][lmh]
9163 Specify drive and density.
9164
9165 @xopindex{multi-volume, short description}
9166 @item -M
9167 @itemx --multi-volume
9168 Create/list/extract multi-volume archive.
9169
9170 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
9171 that may be larger than will fit on the medium used to hold it.
9172 @xref{Multi-Volume Archives}.
9173
9174 @xopindex{tape-length, short description}
9175 @item -L @var{num}
9176 @itemx --tape-length=@var{num}
9177 Change tape after writing @var{num} x 1024 bytes.
9178
9179 This option might be useful when your tape drivers do not properly
9180 detect end of physical tapes. By being slightly conservative on the
9181 maximum tape length, you might avoid the problem entirely.
9182
9183 @xopindex{info-script, short description}
9184 @xopindex{new-volume-script, short description}
9185 @item -F @var{file}
9186 @itemx --info-script=@var{file}
9187 @itemx --new-volume-script=@var{file}
9188 Execute @file{file} at end of each tape. This implies
9189 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
9190 description of this option.
9191 @end table
9192
9193 @node Remote Tape Server
9194 @section The Remote Tape Server
9195
9196 @cindex remote tape drive
9197 @pindex rmt
9198 In order to access the tape drive on a remote machine, @command{tar}
9199 uses the remote tape server written at the University of California at
9200 Berkeley. The remote tape server must be installed as
9201 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
9202 want to use. @command{tar} calls @command{rmt} by running an
9203 @command{rsh} or @command{remsh} to the remote machine, optionally
9204 using a different login name if one is supplied.
9205
9206 A copy of the source for the remote tape server is provided. It is
9207 Copyright @copyright{} 1983 by the Regents of the University of
9208 California, but can be freely distributed. It is compiled and
9209 installed by default.
9210
9211 @cindex absolute file names
9212 Unless you use the @option{--absolute-names} (@option{-P}) option,
9213 @GNUTAR{} will not allow you to create an archive that contains
9214 absolute file names (a file name beginning with @samp{/}.) If you try,
9215 @command{tar} will automatically remove the leading @samp{/} from the
9216 file names it stores in the archive. It will also type a warning
9217 message telling you what it is doing.
9218
9219 When reading an archive that was created with a different
9220 @command{tar} program, @GNUTAR{} automatically
9221 extracts entries in the archive which have absolute file names as if
9222 the file names were not absolute. This is an important feature. A
9223 visitor here once gave a @command{tar} tape to an operator to restore;
9224 the operator used Sun @command{tar} instead of @GNUTAR{},
9225 and the result was that it replaced large portions of
9226 our @file{/bin} and friends with versions from the tape; needless to
9227 say, we were unhappy about having to recover the file system from
9228 backup tapes.
9229
9230 For example, if the archive contained a file @file{/usr/bin/computoy},
9231 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
9232 relative to the current directory. If you want to extract the files in
9233 an archive to the same absolute names that they had when the archive
9234 was created, you should do a @samp{cd /} before extracting the files
9235 from the archive, or you should either use the @option{--absolute-names}
9236 option, or use the command @samp{tar -C / @dots{}}.
9237
9238 @cindex Ultrix 3.1 and write failure
9239 Some versions of Unix (Ultrix 3.1 is known to have this problem),
9240 can claim that a short write near the end of a tape succeeded,
9241 when it actually failed. This will result in the -M option not
9242 working correctly. The best workaround at the moment is to use a
9243 significantly larger blocking factor than the default 20.
9244
9245 In order to update an archive, @command{tar} must be able to backspace the
9246 archive in order to reread or rewrite a record that was just read (or
9247 written). This is currently possible only on two kinds of files: normal
9248 disk files (or any other file that can be backspaced with @samp{lseek}),
9249 and industry-standard 9-track magnetic tape (or any other kind of tape
9250 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}.
9251
9252 This means that the @option{--append}, @option{--concatenate}, and
9253 @option{--delete} commands will not work on any other kind of file.
9254 Some media simply cannot be backspaced, which means these commands and
9255 options will never be able to work on them. These non-backspacing
9256 media include pipes and cartridge tape drives.
9257
9258 Some other media can be backspaced, and @command{tar} will work on them
9259 once @command{tar} is modified to do so.
9260
9261 Archives created with the @option{--multi-volume}, @option{--label}, and
9262 @option{--incremental} (@option{-G}) options may not be readable by other version
9263 of @command{tar}. In particular, restoring a file that was split over
9264 a volume boundary will require some careful work with @command{dd}, if
9265 it can be done at all. Other versions of @command{tar} may also create
9266 an empty file whose name is that of the volume header. Some versions
9267 of @command{tar} may create normal files instead of directories archived
9268 with the @option{--incremental} (@option{-G}) option.
9269
9270 @node Common Problems and Solutions
9271 @section Some Common Problems and their Solutions
9272
9273 @ifclear PUBLISH
9274
9275 @format
9276 errors from system:
9277 permission denied
9278 no such file or directory
9279 not owner
9280
9281 errors from @command{tar}:
9282 directory checksum error
9283 header format error
9284
9285 errors from media/system:
9286 i/o error
9287 device busy
9288 @end format
9289
9290 @end ifclear
9291
9292 @node Blocking
9293 @section Blocking
9294 @UNREVISED
9295
9296 @dfn{Block} and @dfn{record} terminology is rather confused, and it
9297 is also confusing to the expert reader. On the other hand, readers
9298 who are new to the field have a fresh mind, and they may safely skip
9299 the next two paragraphs, as the remainder of this manual uses those
9300 two terms in a quite consistent way.
9301
9302 John Gilmore, the writer of the public domain @command{tar} from which
9303 @GNUTAR{} was originally derived, wrote (June 1995):
9304
9305 @quotation
9306 The nomenclature of tape drives comes from IBM, where I believe
9307 they were invented for the IBM 650 or so. On IBM mainframes, what
9308 is recorded on tape are tape blocks. The logical organization of
9309 data is into records. There are various ways of putting records into
9310 blocks, including @code{F} (fixed sized records), @code{V} (variable
9311 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
9312 to a block), @code{VB} (variable size records, @var{n} to a block),
9313 @code{VSB} (variable spanned blocked: variable sized records that can
9314 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
9315 parameter specified this to the operating system.
9316
9317 The Unix man page on @command{tar} was totally confused about this.
9318 When I wrote @code{PD TAR}, I used the historically correct terminology
9319 (@command{tar} writes data records, which are grouped into blocks).
9320 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
9321 here), and now Fran@,{c}ois has migrated that terminology back
9322 into the source code too.
9323 @end quotation
9324
9325 The term @dfn{physical block} means the basic transfer chunk from or
9326 to a device, after which reading or writing may stop without anything
9327 being lost. In this manual, the term @dfn{block} usually refers to
9328 a disk physical block, @emph{assuming} that each disk block is 512
9329 bytes in length. It is true that some disk devices have different
9330 physical blocks, but @command{tar} ignore these differences in its own
9331 format, which is meant to be portable, so a @command{tar} block is always
9332 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
9333 The term @dfn{logical block} often represents the basic chunk of
9334 allocation of many disk blocks as a single entity, which the operating
9335 system treats somewhat atomically; this concept is only barely used
9336 in @GNUTAR{}.
9337
9338 The term @dfn{physical record} is another way to speak of a physical
9339 block, those two terms are somewhat interchangeable. In this manual,
9340 the term @dfn{record} usually refers to a tape physical block,
9341 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
9342 It is true that archives may be put on disk or used with pipes,
9343 but nevertheless, @command{tar} tries to read and write the archive one
9344 @dfn{record} at a time, whatever the medium in use. One record is made
9345 up of an integral number of blocks, and this operation of putting many
9346 disk blocks into a single tape block is called @dfn{reblocking}, or
9347 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
9348 the logical organization of many characters into something meaningful
9349 to the application. The term @dfn{unit record} describes a small set
9350 of characters which are transmitted whole to or by the application,
9351 and often refers to a line of text. Those two last terms are unrelated
9352 to what we call a @dfn{record} in @GNUTAR{}.
9353
9354 When writing to tapes, @command{tar} writes the contents of the archive
9355 in chunks known as @dfn{records}. To change the default blocking
9356 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
9357 @var{512-size}}) option. Each record will then be composed of
9358 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
9359 @xref{Standard}.) Each file written to the archive uses at least one
9360 full record. As a result, using a larger record size can result in
9361 more wasted space for small files. On the other hand, a larger record
9362 size can often be read and written much more efficiently.
9363
9364 Further complicating the problem is that some tape drives ignore the
9365 blocking entirely. For these, a larger record size can still improve
9366 performance (because the software layers above the tape drive still
9367 honor the blocking), but not as dramatically as on tape drives that
9368 honor blocking.
9369
9370 When reading an archive, @command{tar} can usually figure out the
9371 record size on itself. When this is the case, and a non-standard
9372 record size was used when the archive was created, @command{tar} will
9373 print a message about a non-standard blocking factor, and then operate
9374 normally. On some tape devices, however, @command{tar} cannot figure
9375 out the record size itself. On most of those, you can specify a
9376 blocking factor (with @option{--blocking-factor}) larger than the
9377 actual blocking factor, and then use the @option{--read-full-records}
9378 (@option{-B}) option. (If you specify a blocking factor with
9379 @option{--blocking-factor} and don't use the
9380 @option{--read-full-records} option, then @command{tar} will not
9381 attempt to figure out the recording size itself.) On some devices,
9382 you must always specify the record size exactly with
9383 @option{--blocking-factor} when reading, because @command{tar} cannot
9384 figure it out. In any case, use @option{--list} (@option{-t}) before
9385 doing any extractions to see whether @command{tar} is reading the archive
9386 correctly.
9387
9388 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
9389 putting them into records is to put a whole number of them (one or
9390 more) into each record. @command{tar} records are all the same size;
9391 at the end of the file there's a block containing all zeros, which
9392 is how you tell that the remainder of the last record(s) are garbage.
9393
9394 In a standard @command{tar} file (no options), the block size is 512
9395 and the record size is 10240, for a blocking factor of 20. What the
9396 @option{--blocking-factor} option does is sets the blocking factor,
9397 changing the record size while leaving the block size at 512 bytes.
9398 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
9399 most tape drives these days prefer much bigger records in order to
9400 stream and not waste tape. When writing tapes for myself, some tend
9401 to use a factor of the order of 2048, say, giving a record size of
9402 around one megabyte.
9403
9404 If you use a blocking factor larger than 20, older @command{tar}
9405 programs might not be able to read the archive, so we recommend this
9406 as a limit to use in practice. @GNUTAR{}, however,
9407 will support arbitrarily large record sizes, limited only by the
9408 amount of virtual memory or the physical characteristics of the tape
9409 device.
9410
9411 @menu
9412 * Format Variations:: Format Variations
9413 * Blocking Factor:: The Blocking Factor of an Archive
9414 @end menu
9415
9416 @node Format Variations
9417 @subsection Format Variations
9418 @cindex Format Parameters
9419 @cindex Format Options
9420 @cindex Options, archive format specifying
9421 @cindex Options, format specifying
9422 @UNREVISED
9423
9424 Format parameters specify how an archive is written on the archive
9425 media. The best choice of format parameters will vary depending on
9426 the type and number of files being archived, and on the media used to
9427 store the archive.
9428
9429 To specify format parameters when accessing or creating an archive,
9430 you can use the options described in the following sections.
9431 If you do not specify any format parameters, @command{tar} uses
9432 default parameters. You cannot modify a compressed archive.
9433 If you create an archive with the @option{--blocking-factor} option
9434 specified (@pxref{Blocking Factor}), you must specify that
9435 blocking-factor when operating on the archive. @xref{Formats}, for other
9436 examples of format parameter considerations.
9437
9438 @node Blocking Factor
9439 @subsection The Blocking Factor of an Archive
9440 @cindex Blocking Factor
9441 @cindex Record Size
9442 @cindex Number of blocks per record
9443 @cindex Number of bytes per record
9444 @cindex Bytes per record
9445 @cindex Blocks per record
9446 @UNREVISED
9447
9448 @opindex blocking-factor
9449 The data in an archive is grouped into blocks, which are 512 bytes.
9450 Blocks are read and written in whole number multiples called
9451 @dfn{records}. The number of blocks in a record (i.e., the size of a
9452 record in units of 512 bytes) is called the @dfn{blocking factor}.
9453 The @option{--blocking-factor=@var{512-size}} (@option{-b
9454 @var{512-size}}) option specifies the blocking factor of an archive.
9455 The default blocking factor is typically 20 (i.e., 10240 bytes), but
9456 can be specified at installation. To find out the blocking factor of
9457 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
9458 This may not work on some devices.
9459
9460 Records are separated by gaps, which waste space on the archive media.
9461 If you are archiving on magnetic tape, using a larger blocking factor
9462 (and therefore larger records) provides faster throughput and allows you
9463 to fit more data on a tape (because there are fewer gaps). If you are
9464 archiving on cartridge, a very large blocking factor (say 126 or more)
9465 greatly increases performance. A smaller blocking factor, on the other
9466 hand, may be useful when archiving small files, to avoid archiving lots
9467 of nulls as @command{tar} fills out the archive to the end of the record.
9468 In general, the ideal record size depends on the size of the
9469 inter-record gaps on the tape you are using, and the average size of the
9470 files you are archiving. @xref{create}, for information on
9471 writing archives.
9472
9473 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
9474
9475 Archives with blocking factors larger than 20 cannot be read
9476 by very old versions of @command{tar}, or by some newer versions
9477 of @command{tar} running on old machines with small address spaces.
9478 With @GNUTAR{}, the blocking factor of an archive is limited
9479 only by the maximum record size of the device containing the archive,
9480 or by the amount of available virtual memory.
9481
9482 Also, on some systems, not using adequate blocking factors, as sometimes
9483 imposed by the device drivers, may yield unexpected diagnostics. For
9484 example, this has been reported:
9485
9486 @smallexample
9487 Cannot write to /dev/dlt: Invalid argument
9488 @end smallexample
9489
9490 @noindent
9491 In such cases, it sometimes happen that the @command{tar} bundled by
9492 the system is aware of block size idiosyncrasies, while @GNUTAR{}
9493 requires an explicit specification for the block size,
9494 which it cannot guess. This yields some people to consider
9495 @GNUTAR{} is misbehaving, because by comparison,
9496 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
9497 for example, might resolve the problem.
9498
9499 If you use a non-default blocking factor when you create an archive, you
9500 must specify the same blocking factor when you modify that archive. Some
9501 archive devices will also require you to specify the blocking factor when
9502 reading that archive, however this is not typically the case. Usually, you
9503 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
9504 reports a non-default record size and then lists the archive members as
9505 it would normally. To extract files from an archive with a non-standard
9506 blocking factor (particularly if you're not sure what the blocking factor
9507 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
9508 specifying a blocking factor larger then the blocking factor of the archive
9509 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}.
9510 @xref{list}, for more information on the @option{--list} (@option{-t})
9511 operation. @xref{Reading}, for a more detailed explanation of that option.
9512
9513 @table @option
9514 @item --blocking-factor=@var{number}
9515 @itemx -b @var{number}
9516 Specifies the blocking factor of an archive. Can be used with any
9517 operation, but is usually not necessary with @option{--list} (@option{-t}).
9518 @end table
9519
9520 Device blocking
9521
9522 @table @option
9523 @item -b @var{blocks}
9524 @itemx --blocking-factor=@var{blocks}
9525 Set record size to @math{@var{blocks} * 512} bytes.
9526
9527 This option is used to specify a @dfn{blocking factor} for the archive.
9528 When reading or writing the archive, @command{tar}, will do reads and writes
9529 of the archive in records of @math{@var{block}*512} bytes. This is true
9530 even when the archive is compressed. Some devices requires that all
9531 write operations be a multiple of a certain size, and so, @command{tar}
9532 pads the archive out to the next record boundary.
9533
9534 The default blocking factor is set when @command{tar} is compiled, and is
9535 typically 20. Blocking factors larger than 20 cannot be read by very
9536 old versions of @command{tar}, or by some newer versions of @command{tar}
9537 running on old machines with small address spaces.
9538
9539 With a magnetic tape, larger records give faster throughput and fit
9540 more data on a tape (because there are fewer inter-record gaps).
9541 If the archive is in a disk file or a pipe, you may want to specify
9542 a smaller blocking factor, since a large one will result in a large
9543 number of null bytes at the end of the archive.
9544
9545 When writing cartridge or other streaming tapes, a much larger
9546 blocking factor (say 126 or more) will greatly increase performance.
9547 However, you must specify the same blocking factor when reading or
9548 updating the archive.
9549
9550 Apparently, Exabyte drives have a physical block size of 8K bytes.
9551 If we choose our blocksize as a multiple of 8k bytes, then the problem
9552 seems to disappear. Id est, we are using block size of 112 right
9553 now, and we haven't had the problem since we switched@dots{}
9554
9555 With @GNUTAR{} the blocking factor is limited only
9556 by the maximum record size of the device containing the archive, or by
9557 the amount of available virtual memory.
9558
9559 However, deblocking or reblocking is virtually avoided in a special
9560 case which often occurs in practice, but which requires all the
9561 following conditions to be simultaneously true:
9562 @itemize @bullet
9563 @item
9564 the archive is subject to a compression option,
9565 @item
9566 the archive is not handled through standard input or output, nor
9567 redirected nor piped,
9568 @item
9569 the archive is directly handled to a local disk, instead of any special
9570 device,
9571 @item
9572 @option{--blocking-factor} is not explicitly specified on the @command{tar}
9573 invocation.
9574 @end itemize
9575
9576 If the output goes directly to a local disk, and not through
9577 stdout, then the last write is not extended to a full record size.
9578 Otherwise, reblocking occurs. Here are a few other remarks on this
9579 topic:
9580
9581 @itemize @bullet
9582
9583 @item
9584 @command{gzip} will complain about trailing garbage if asked to
9585 uncompress a compressed archive on tape, there is an option to turn
9586 the message off, but it breaks the regularity of simply having to use
9587 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
9588 silently ignoring any number of trailing zeros. I'll ask Jean-loup
9589 Gailly, by sending a copy of this message to him.
9590
9591 @item
9592 @command{compress} does not show this problem, but as Jean-loup pointed
9593 out to Michael, @samp{compress -d} silently adds garbage after
9594 the result of decompression, which tar ignores because it already
9595 recognized its end-of-file indicator. So this bug may be safely
9596 ignored.
9597
9598 @item
9599 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
9600 but will still return an exit status of 2 which tar reports in turn.
9601 @command{tar} might ignore the exit status returned, but I hate doing
9602 that, as it weakens the protection @command{tar} offers users against
9603 other possible problems at decompression time. If @command{gzip} was
9604 silently skipping trailing zeros @emph{and} also avoiding setting the
9605 exit status in this innocuous case, that would solve this situation.
9606
9607 @item
9608 @command{tar} should become more solid at not stopping to read a pipe at
9609 the first null block encountered. This inelegantly breaks the pipe.
9610 @command{tar} should rather drain the pipe out before exiting itself.
9611 @end itemize
9612
9613 @xopindex{ignore-zeros, short description}
9614 @item -i
9615 @itemx --ignore-zeros
9616 Ignore blocks of zeros in archive (means EOF).
9617
9618 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
9619 of zeros in the archive. Normally a block of zeros indicates the
9620 end of the archive, but when reading a damaged archive, or one which
9621 was created by concatenating several archives together, this option
9622 allows @command{tar} to read the entire archive. This option is not on
9623 by default because many versions of @command{tar} write garbage after
9624 the zeroed blocks.
9625
9626 Note that this option causes @command{tar} to read to the end of the
9627 archive file, which may sometimes avoid problems when multiple files
9628 are stored on a single physical tape.
9629
9630 @xopindex{read-full-records, short description}
9631 @item -B
9632 @itemx --read-full-records
9633 Reblock as we read (for reading 4.2BSD pipes).
9634
9635 If @option{--read-full-records} is used, @command{tar}
9636 will not panic if an attempt to read a record from the archive does
9637 not return a full record. Instead, @command{tar} will keep reading
9638 until it has obtained a full
9639 record.
9640
9641 This option is turned on by default when @command{tar} is reading
9642 an archive from standard input, or from a remote machine. This is
9643 because on BSD Unix systems, a read of a pipe will return however
9644 much happens to be in the pipe, even if it is less than @command{tar}
9645 requested. If this option was not used, @command{tar} would fail as
9646 soon as it read an incomplete record from the pipe.
9647
9648 This option is also useful with the commands for updating an archive.
9649
9650 @end table
9651
9652 Tape blocking
9653
9654 @FIXME{Appropriate options should be moved here from elsewhere.}
9655
9656 @cindex blocking factor
9657 @cindex tape blocking
9658
9659 When handling various tapes or cartridges, you have to take care of
9660 selecting a proper blocking, that is, the number of disk blocks you
9661 put together as a single tape block on the tape, without intervening
9662 tape gaps. A @dfn{tape gap} is a small landing area on the tape
9663 with no information on it, used for decelerating the tape to a
9664 full stop, and for later regaining the reading or writing speed.
9665 When the tape driver starts reading a record, the record has to
9666 be read whole without stopping, as a tape gap is needed to stop the
9667 tape motion without loosing information.
9668
9669 @cindex Exabyte blocking
9670 @cindex DAT blocking
9671 Using higher blocking (putting more disk blocks per tape block) will use
9672 the tape more efficiently as there will be less tape gaps. But reading
9673 such tapes may be more difficult for the system, as more memory will be
9674 required to receive at once the whole record. Further, if there is a
9675 reading error on a huge record, this is less likely that the system will
9676 succeed in recovering the information. So, blocking should not be too
9677 low, nor it should be too high. @command{tar} uses by default a blocking of
9678 20 for historical reasons, and it does not really matter when reading or
9679 writing to disk. Current tape technology would easily accommodate higher
9680 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
9681 We were told that for some DLT drives, the blocking should be a multiple
9682 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
9683 Other manufacturers may use different recommendations for the same tapes.
9684 This might also depends of the buffering techniques used inside modern
9685 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
9686 Others request blocking to be some exponent of two.
9687
9688 So, there is no fixed rule for blocking. But blocking at read time
9689 should ideally be the same as blocking used at write time. At one place
9690 I know, with a wide variety of equipment, they found it best to use a
9691 blocking of 32 to guarantee that their tapes are fully interchangeable.
9692
9693 I was also told that, for recycled tapes, prior erasure (by the same
9694 drive unit that will be used to create the archives) sometimes lowers
9695 the error rates observed at rewriting time.
9696
9697 I might also use @option{--number-blocks} instead of
9698 @option{--block-number}, so @option{--block} will then expand to
9699 @option{--blocking-factor} unambiguously.
9700
9701 @node Many
9702 @section Many Archives on One Tape
9703
9704 @FIXME{Appropriate options should be moved here from elsewhere.}
9705
9706 @findex ntape @r{device}
9707 Most tape devices have two entries in the @file{/dev} directory, or
9708 entries that come in pairs, which differ only in the minor number for
9709 this device. Let's take for example @file{/dev/tape}, which often
9710 points to the only or usual tape device of a given system. There might
9711 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
9712 name is the @emph{rewinding} version of the device, while the name
9713 having @samp{nr} in it is the @emph{no rewinding} version of the same
9714 device.
9715
9716 A rewinding tape device will bring back the tape to its beginning point
9717 automatically when this device is opened or closed. Since @command{tar}
9718 opens the archive file before using it and closes it afterwards, this
9719 means that a simple:
9720
9721 @smallexample
9722 $ @kbd{tar cf /dev/tape @var{directory}}
9723 @end smallexample
9724
9725 @noindent
9726 will reposition the tape to its beginning both prior and after saving
9727 @var{directory} contents to it, thus erasing prior tape contents and
9728 making it so that any subsequent write operation will destroy what has
9729 just been saved.
9730
9731 @cindex tape positioning
9732 So, a rewinding device is normally meant to hold one and only one file.
9733 If you want to put more than one @command{tar} archive on a given tape, you
9734 will need to avoid using the rewinding version of the tape device. You
9735 will also have to pay special attention to tape positioning. Errors in
9736 positioning may overwrite the valuable data already on your tape. Many
9737 people, burnt by past experiences, will only use rewinding devices and
9738 limit themselves to one file per tape, precisely to avoid the risk of
9739 such errors. Be fully aware that writing at the wrong position on a
9740 tape loses all information past this point and most probably until the
9741 end of the tape, and this destroyed information @emph{cannot} be
9742 recovered.
9743
9744 To save @var{directory-1} as a first archive at the beginning of a
9745 tape, and leave that tape ready for a second archive, you should use:
9746
9747 @smallexample
9748 $ @kbd{mt -f /dev/nrtape rewind}
9749 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
9750 @end smallexample
9751
9752 @cindex tape marks
9753 @dfn{Tape marks} are special magnetic patterns written on the tape
9754 media, which are later recognizable by the reading hardware. These
9755 marks are used after each file, when there are many on a single tape.
9756 An empty file (that is to say, two tape marks in a row) signal the
9757 logical end of the tape, after which no file exist. Usually,
9758 non-rewinding tape device drivers will react to the close request issued
9759 by @command{tar} by first writing two tape marks after your archive, and by
9760 backspacing over one of these. So, if you remove the tape at that time
9761 from the tape drive, it is properly terminated. But if you write
9762 another file at the current position, the second tape mark will be
9763 erased by the new information, leaving only one tape mark between files.
9764
9765 So, you may now save @var{directory-2} as a second archive after the
9766 first on the same tape by issuing the command:
9767
9768 @smallexample
9769 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
9770 @end smallexample
9771
9772 @noindent
9773 and so on for all the archives you want to put on the same tape.
9774
9775 Another usual case is that you do not write all the archives the same
9776 day, and you need to remove and store the tape between two archive
9777 sessions. In general, you must remember how many files are already
9778 saved on your tape. Suppose your tape already has 16 files on it, and
9779 that you are ready to write the 17th. You have to take care of skipping
9780 the first 16 tape marks before saving @var{directory-17}, say, by using
9781 these commands:
9782
9783 @smallexample
9784 $ @kbd{mt -f /dev/nrtape rewind}
9785 $ @kbd{mt -f /dev/nrtape fsf 16}
9786 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
9787 @end smallexample
9788
9789 In all the previous examples, we put aside blocking considerations, but
9790 you should do the proper things for that as well. @xref{Blocking}.
9791
9792 @menu
9793 * Tape Positioning:: Tape Positions and Tape Marks
9794 * mt:: The @command{mt} Utility
9795 @end menu
9796
9797 @node Tape Positioning
9798 @subsection Tape Positions and Tape Marks
9799 @UNREVISED
9800
9801 Just as archives can store more than one file from the file system,
9802 tapes can store more than one archive file. To keep track of where
9803 archive files (or any other type of file stored on tape) begin and
9804 end, tape archive devices write magnetic @dfn{tape marks} on the
9805 archive media. Tape drives write one tape mark between files,
9806 two at the end of all the file entries.
9807
9808 If you think of data as a series of records "rrrr"'s, and tape marks as
9809 "*"'s, a tape might look like the following:
9810
9811 @smallexample
9812 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
9813 @end smallexample
9814
9815 Tape devices read and write tapes using a read/write @dfn{tape
9816 head}---a physical part of the device which can only access one
9817 point on the tape at a time. When you use @command{tar} to read or
9818 write archive data from a tape device, the device will begin reading
9819 or writing from wherever on the tape the tape head happens to be,
9820 regardless of which archive or what part of the archive the tape
9821 head is on. Before writing an archive, you should make sure that no
9822 data on the tape will be overwritten (unless it is no longer needed).
9823 Before reading an archive, you should make sure the tape head is at
9824 the beginning of the archive you want to read. You can do it manually
9825 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
9826 that automatically (@pxref{Scripted Restoration}).
9827
9828 If you want to add new archive file entries to a tape, you should
9829 advance the tape to the end of the existing file entries, backspace
9830 over the last tape mark, and write the new archive file. If you were
9831 to add two archives to the example above, the tape might look like the
9832 following:
9833
9834 @smallexample
9835 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
9836 @end smallexample
9837
9838 @node mt
9839 @subsection The @command{mt} Utility
9840 @UNREVISED
9841
9842 @FIXME{Is it true that this only works on non-block devices?
9843 should explain the difference, (fixed or variable).}
9844 @xref{Blocking Factor}.
9845
9846 You can use the @command{mt} utility to advance or rewind a tape past a
9847 specified number of archive files on the tape. This will allow you
9848 to move to the beginning of an archive before extracting or reading
9849 it, or to the end of all the archives before writing a new one.
9850 @FIXME{Why isn't there an "advance 'til you find two tape marks
9851 together"?}
9852
9853 The syntax of the @command{mt} command is:
9854
9855 @smallexample
9856 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
9857 @end smallexample
9858
9859 where @var{tapename} is the name of the tape device, @var{number} is
9860 the number of times an operation is performed (with a default of one),
9861 and @var{operation} is one of the following:
9862
9863 @FIXME{is there any use for record operations?}
9864
9865 @table @option
9866 @item eof
9867 @itemx weof
9868 Writes @var{number} tape marks at the current position on the tape.
9869
9870 @item fsf
9871 Moves tape position forward @var{number} files.
9872
9873 @item bsf
9874 Moves tape position back @var{number} files.
9875
9876 @item rewind
9877 Rewinds the tape. (Ignores @var{number}).
9878
9879 @item offline
9880 @itemx rewoff1
9881 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}).
9882
9883 @item status
9884 Prints status information about the tape unit.
9885
9886 @end table
9887
9888 @FIXME{Is there a better way to frob the spacing on the list?}
9889
9890 If you don't specify a @var{tapename}, @command{mt} uses the environment
9891 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
9892 the default device specified in your @file{sys/mtio.h} file
9893 (@code{DEFTAPE} variable). If this is not defined, the program will
9894 display a descriptive error message and exit with code 1.
9895
9896 @command{mt} returns a 0 exit status when the operation(s) were
9897 successful, 1 if the command was unrecognized, and 2 if an operation
9898 failed.
9899
9900 @node Using Multiple Tapes
9901 @section Using Multiple Tapes
9902
9903 Often you might want to write a large archive, one larger than will fit
9904 on the actual tape you are using. In such a case, you can run multiple
9905 @command{tar} commands, but this can be inconvenient, particularly if you
9906 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
9907 Therefore, @command{tar} provides a special mode for creating
9908 multi-volume archives.
9909
9910 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
9911 on several media volumes of fixed size. Although in this section we will
9912 often call @samp{volume} a @dfn{tape}, there is absolutely no
9913 requirement for multi-volume archives to be stored on tapes. Instead,
9914 they can use whatever media type the user finds convenient, they can
9915 even be located on files.
9916
9917 When creating a multi-volume archive, @GNUTAR{} continues to fill
9918 current volume until it runs out of space, then it switches to
9919 next volume (usually the operator is queried to replace the tape on
9920 this point), and continues working on the new volume. This operation
9921 continues until all requested files are dumped. If @GNUTAR{} detects
9922 end of media while dumping a file, such a file is archived in split
9923 form. Some very big files can even be split across several volumes.
9924
9925 Each volume is itself a valid @GNUTAR{} archive, so it can be read
9926 without any special options. Consequently any file member residing
9927 entirely on one volume can be extracted or otherwise operated upon
9928 without needing the other volume. Sure enough, to extract a split
9929 member you would need all volumes its parts reside on.
9930
9931 Multi-volume archives suffer from several limitations. In particular,
9932 they cannot be compressed.
9933
9934 @GNUTAR{} is able to create multi-volume archives of two formats
9935 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
9936
9937 @menu
9938 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
9939 * Tape Files:: Tape Files
9940 * Tarcat:: Concatenate Volumes into a Single Archive
9941
9942 @end menu
9943
9944 @node Multi-Volume Archives
9945 @subsection Archives Longer than One Tape or Disk
9946 @cindex Multi-volume archives
9947
9948 @opindex multi-volume
9949 To create an archive that is larger than will fit on a single unit of
9950 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
9951 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
9952 archive can be manipulated like any other archive (provided the
9953 @option{--multi-volume} option is specified), but is stored on more
9954 than one tape or disk.
9955
9956 When you specify @option{--multi-volume}, @command{tar} does not report an
9957 error when it comes to the end of an archive volume (when reading), or
9958 the end of the media (when writing). Instead, it prompts you to load
9959 a new storage volume. If the archive is on a magnetic tape, you
9960 should change tapes when you see the prompt; if the archive is on a
9961 floppy disk, you should change disks; etc.
9962
9963 @table @option
9964 @item --multi-volume
9965 @itemx -M
9966 Creates a multi-volume archive, when used in conjunction with
9967 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
9968 archive, specify @option{--multi-volume} in conjunction with that
9969 operation.
9970 For example:
9971
9972 @smallexample
9973 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
9974 @end smallexample
9975 @end table
9976
9977 The method @command{tar} uses to detect end of tape is not perfect, and
9978 fails on some operating systems or on some devices. If @command{tar}
9979 cannot detect the end of the tape itself, you can use
9980 @option{--tape-length} option to inform it about the capacity of the
9981 tape:
9982
9983 @anchor{tape-length}
9984 @table @option
9985 @opindex tape-length
9986 @item --tape-length=@var{size}
9987 @itemx -L @var{size}
9988 Set maximum length of a volume. The @var{size} argument should then
9989 be the usable size of the tape in units of 1024 bytes. This option
9990 selects @option{--multi-volume} automatically. For example:
9991
9992 @smallexample
9993 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
9994 @end smallexample
9995 @end table
9996
9997 @anchor{change volume prompt}
9998 When @GNUTAR{} comes to the end of a storage media, it asks you to
9999 change the volume. The built-in prompt for POSIX locale
10000 is@footnote{If you run @GNUTAR{} under a different locale, the
10001 translation to the locale's language will be used.}:
10002
10003 @smallexample
10004 Prepare volume #@var{n} for `@var{archive}' and hit return:
10005 @end smallexample
10006
10007 @noindent
10008 where @var{n} is the ordinal number of the volume to be created and
10009 @var{archive} is archive file or device name.
10010
10011 When prompting for a new tape, @command{tar} accepts any of the following
10012 responses:
10013
10014 @table @kbd
10015 @item ?
10016 Request @command{tar} to explain possible responses
10017 @item q
10018 Request @command{tar} to exit immediately.
10019 @item n @var{file-name}
10020 Request @command{tar} to write the next volume on the file @var{file-name}.
10021 @item !
10022 Request @command{tar} to run a subshell. This option can be disabled
10023 by giving @option{--restrict} command line option to
10024 @command{tar}@footnote{@xref{--restrict}, for more information about
10025 this option}.
10026 @item y
10027 Request @command{tar} to begin writing the next volume.
10028 @end table
10029
10030 (You should only type @samp{y} after you have changed the tape;
10031 otherwise @command{tar} will write over the volume it just finished.)
10032
10033 @cindex Volume number file
10034 @cindex volno file
10035 @anchor{volno-file}
10036 @opindex volno-file
10037 The volume number used by @command{tar} in its tape-changing prompt
10038 can be changed; if you give the
10039 @option{--volno-file=@var{file-of-number}} option, then
10040 @var{file-of-number} should be an non-existing file to be created, or
10041 else, a file already containing a decimal number. That number will be
10042 used as the volume number of the first volume written. When
10043 @command{tar} is finished, it will rewrite the file with the
10044 now-current volume number. (This does not change the volume number
10045 written on a tape label, as per @ref{label}, it @emph{only} affects
10046 the number used in the prompt.)
10047
10048 @cindex End-of-archive info script
10049 @cindex Info script
10050 @anchor{info-script}
10051 @opindex info-script
10052 @opindex new-volume-script
10053 If you want more elaborate behavior than this, you can write a special
10054 @dfn{new volume script}, that will be responsible for changing the
10055 volume, and instruct @command{tar} to use it instead of its normal
10056 prompting procedure:
10057
10058 @table @option
10059 @item --info-script=@var{script-name}
10060 @itemx --new-volume-script=@var{script-name}
10061 @itemx -F @var{script-name}
10062 Specify the full name of the volume script to use. The script can be
10063 used to eject cassettes, or to broadcast messages such as
10064 @samp{Someone please come change my tape} when performing unattended
10065 backups.
10066 @end table
10067
10068 The @var{script-name} is executed without any command line
10069 arguments. It inherits @command{tar}'s shell environment.
10070 Additional data is passed to it via the following
10071 environment variables:
10072
10073 @table @env
10074 @vrindex TAR_VERSION, info script environment variable
10075 @item TAR_VERSION
10076 @GNUTAR{} version number.
10077
10078 @vrindex TAR_ARCHIVE, info script environment variable
10079 @item TAR_ARCHIVE
10080 The name of the archive @command{tar} is processing.
10081
10082 @vrindex TAR_VOLUME, info script environment variable
10083 @item TAR_VOLUME
10084 Ordinal number of the volume @command{tar} is about to start.
10085
10086 @vrindex TAR_SUBCOMMAND, info script environment variable
10087 @item TAR_SUBCOMMAND
10088 Short option describing the operation @command{tar} is executing
10089 @xref{Operations}, for a complete list of subcommand options.
10090
10091 @vrindex TAR_FORMAT, info script environment variable
10092 @item TAR_FORMAT
10093 Format of the archive being processed. @xref{Formats}, for a complete
10094 list of archive format names.
10095 @end table
10096
10097 The volume script can instruct @command{tar} to use new archive name,
10098 by writing in to file descriptor 3 (see below for an example).
10099
10100 If the info script fails, @command{tar} exits; otherwise, it begins
10101 writing the next volume.
10102
10103 If you want @command{tar} to cycle through a series of files or tape
10104 drives, there are three approaches to choose from. First of all, you
10105 can give @command{tar} multiple @option{--file} options. In this case
10106 the specified files will be used, in sequence, as the successive
10107 volumes of the archive. Only when the first one in the sequence needs
10108 to be used again will @command{tar} prompt for a tape change (or run
10109 the info script). For example, suppose someone has two tape drives on
10110 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
10111 @GNUTAR{} to switch to the second drive when it needs to write the
10112 second tape, and then back to the first tape, etc., just do either of:
10113
10114 @smallexample
10115 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
10116 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
10117 @end smallexample
10118
10119 The second method is to use the @samp{n} response to the tape-change
10120 prompt.
10121
10122 Finally, the most flexible approach is to use a volume script, that
10123 writes new archive name to the file descriptor #3. For example, the
10124 following volume script will create a series of archive files, named
10125 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
10126 archive being created (as given by @option{--file} option) and
10127 @var{vol} is the ordinal number of the archive being created:
10128
10129 @smallexample
10130 @group
10131 #! /bin/sh
10132 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
10133
10134 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
10135 case $TAR_SUBCOMMAND in
10136 -c) ;;
10137 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
10138 ;;
10139 *) exit 1
10140 esac
10141
10142 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&3
10143 @end group
10144 @end smallexample
10145
10146 The same script cant be used while listing, comparing or extracting
10147 from the created archive. For example:
10148
10149 @smallexample
10150 @group
10151 # @r{Create a multi-volume archive:}
10152 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
10153 # @r{Extract from the created archive:}
10154 $ @kbd{tar -x -f archive.tar -F new-volume .}
10155 @end group
10156 @end smallexample
10157
10158 @noindent
10159 Notice, that the first command had to use @option{-L} option, since
10160 otherwise @GNUTAR{} will end up writing everything to file
10161 @file{archive.tar}.
10162
10163 You can read each individual volume of a multi-volume archive as if it
10164 were an archive by itself. For example, to list the contents of one
10165 volume, use @option{--list}, without @option{--multi-volume} specified.
10166 To extract an archive member from one volume (assuming it is described
10167 that volume), use @option{--extract}, again without
10168 @option{--multi-volume}.
10169
10170 If an archive member is split across volumes (i.e., its entry begins on
10171 one volume of the media and ends on another), you need to specify
10172 @option{--multi-volume} to extract it successfully. In this case, you
10173 should load the volume where the archive member starts, and use
10174 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
10175 volumes as it needs them. @xref{extracting archives}, for more
10176 information about extracting archives.
10177
10178 Multi-volume archives can be modified like any other archive. To add
10179 files to a multi-volume archive, you need to only mount the last
10180 volume of the archive media (and new volumes, if needed). For all
10181 other operations, you need to use the entire archive.
10182
10183 If a multi-volume archive was labeled using
10184 @option{--label=@var{archive-label}} (@pxref{label}) when it was
10185 created, @command{tar} will not automatically label volumes which are
10186 added later. To label subsequent volumes, specify
10187 @option{--label=@var{archive-label}} again in conjunction with the
10188 @option{--append}, @option{--update} or @option{--concatenate} operation.
10189
10190 Notice that multi-volume support is a GNU extension and the archives
10191 created in this mode should be read only using @GNUTAR{}. If you
10192 absolutely have to process such archives using a third-party @command{tar}
10193 implementation, read @ref{Split Recovery}.
10194
10195 @node Tape Files
10196 @subsection Tape Files
10197 @UNREVISED
10198
10199 To give the archive a name which will be recorded in it, use the
10200 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
10201 option. This will write a special block identifying
10202 @var{volume-label} as the name of the archive to the front of the
10203 archive which will be displayed when the archive is listed with
10204 @option{--list}. If you are creating a multi-volume archive with
10205 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
10206 volume label will have @samp{Volume @var{nnn}} appended to the name
10207 you give, where @var{nnn} is the number of the volume of the archive.
10208 (If you use the @option{--label=@var{volume-label}}) option when
10209 reading an archive, it checks to make sure the label on the tape
10210 matches the one you give. @xref{label}.
10211
10212 When @command{tar} writes an archive to tape, it creates a single
10213 tape file. If multiple archives are written to the same tape, one
10214 after the other, they each get written as separate tape files. When
10215 extracting, it is necessary to position the tape at the right place
10216 before running @command{tar}. To do this, use the @command{mt} command.
10217 For more information on the @command{mt} command and on the organization
10218 of tapes into a sequence of tape files, see @ref{mt}.
10219
10220 People seem to often do:
10221
10222 @smallexample
10223 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
10224 @end smallexample
10225
10226 or such, for pushing a common date in all volumes or an archive set.
10227
10228 @node Tarcat
10229 @subsection Concatenate Volumes into a Single Archive
10230
10231 @pindex tarcat
10232 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
10233 archive to a single @command{tar} archive. Simply concatenating all
10234 volumes into one will not work, since each volume carries an additional
10235 information at the beginning. @GNUTAR{} is shipped with the shell
10236 script @command{tarcat} designed for this purpose.
10237
10238 The script takes a list of files comprising a multi-volume archive
10239 and creates the resulting archive at the standard output. For example:
10240
10241 @smallexample
10242 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
10243 @end smallexample
10244
10245 The script implements a simple heuristics to determine the format of
10246 the first volume file and to decide how to process the rest of the
10247 files. However, it makes no attempt to verify whether the files are
10248 given in order or even if they are valid @command{tar} archives.
10249 It uses @command{dd} and does not filter its standard error, so you
10250 will usually see lots of spurious messages.
10251
10252 @FIXME{The script is not installed. Should we install it?}
10253
10254 @node label
10255 @section Including a Label in the Archive
10256 @cindex Labeling an archive
10257 @cindex Labels on the archive media
10258 @cindex Labeling multi-volume archives
10259 @UNREVISED
10260
10261 @opindex label
10262 To avoid problems caused by misplaced paper labels on the archive
10263 media, you can include a @dfn{label} entry---an archive member which
10264 contains the name of the archive---in the archive itself. Use the
10265 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10266 option in conjunction with the @option{--create} operation to include
10267 a label entry in the archive as it is being created.
10268
10269 @table @option
10270 @item --label=@var{archive-label}
10271 @itemx -V @var{archive-label}
10272 Includes an @dfn{archive-label} at the beginning of the archive when
10273 the archive is being created, when used in conjunction with the
10274 @option{--create} operation. Checks to make sure the archive label
10275 matches the one specified (when used in conjunction with any other
10276 operation.
10277 @end table
10278
10279 If you create an archive using both
10280 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
10281 and @option{--multi-volume} (@option{-M}), each volume of the archive
10282 will have an archive label of the form @samp{@var{archive-label}
10283 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
10284 next, and so on. @xref{Using Multiple Tapes}, for information on
10285 creating multiple volume archives.
10286
10287 @cindex Volume label, listing
10288 @cindex Listing volume label
10289 The volume label will be displayed by @option{--list} along with
10290 the file contents. If verbose display is requested, it will also be
10291 explicitly marked as in the example below:
10292
10293 @smallexample
10294 @group
10295 $ @kbd{tar --verbose --list --file=iamanarchive}
10296 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
10297 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
10298 @end group
10299 @end smallexample
10300
10301 @opindex test-label
10302 @anchor{--test-label option}
10303 However, @option{--list} option will cause listing entire
10304 contents of the archive, which may be undesirable (for example, if the
10305 archive is stored on a tape). You can request checking only the volume
10306 by specifying @option{--test-label} option. This option reads only the
10307 first block of an archive, so it can be used with slow storage
10308 devices. For example:
10309
10310 @smallexample
10311 @group
10312 $ @kbd{tar --test-label --file=iamanarchive}
10313 iamalabel
10314 @end group
10315 @end smallexample
10316
10317 If @option{--test-label} is used with a single command line
10318 argument, @command{tar} compares the volume label with the
10319 argument. It exits with code 0 if the two strings match, and with code
10320 2 otherwise. In this case no output is displayed. For example:
10321
10322 @smallexample
10323 @group
10324 $ @kbd{tar --test-label --file=iamanarchive 'iamalable'}
10325 @result{} 0
10326 $ @kbd{tar --test-label --file=iamanarchive 'iamalable' alabel}
10327 @result{} 1
10328 @end group
10329 @end smallexample
10330
10331 If you request any operation, other than @option{--create}, along
10332 with using @option{--label} option, @command{tar} will first check if
10333 the archive label matches the one specified and will refuse to proceed
10334 if it does not. Use this as a safety precaution to avoid accidentally
10335 overwriting existing archives. For example, if you wish to add files
10336 to @file{archive}, presumably labeled with string @samp{My volume},
10337 you will get:
10338
10339 @smallexample
10340 @group
10341 $ @kbd{tar -rf archive --label 'My volume' .}
10342 tar: Archive not labeled to match `My volume'
10343 @end group
10344 @end smallexample
10345
10346 @noindent
10347 in case its label does not match. This will work even if
10348 @file{archive} is not labeled at all.
10349
10350 Similarly, @command{tar} will refuse to list or extract the
10351 archive if its label doesn't match the @var{archive-label}
10352 specified. In those cases, @var{archive-label} argument is interpreted
10353 as a globbing-style pattern which must match the actual magnetic
10354 volume label. @xref{exclude}, for a precise description of how match
10355 is attempted@footnote{Previous versions of @command{tar} used full
10356 regular expression matching, or before that, only exact string
10357 matching, instead of wildcard matchers. We decided for the sake of
10358 simplicity to use a uniform matching device through
10359 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
10360 the volume label matcher will also suffix @var{archive-label} by
10361 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
10362 up. Since the volume numbering is automatically added in labels at
10363 creation time, it sounded logical to equally help the user taking care
10364 of it when the archive is being read.
10365
10366 The @option{--label} was once called @option{--volume}, but is not
10367 available under that name anymore.
10368
10369 You can also use @option{--label} to get a common information on
10370 all tapes of a series. For having this information different in each
10371 series created through a single script used on a regular basis, just
10372 manage to get some date string as part of the label. For example:
10373
10374 @smallexample
10375 @group
10376 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
10377 $ @kbd{tar --create --file=/dev/tape --multi-volume \
10378 --volume="Daily backup for `date +%Y-%m-%d`"}
10379 @end group
10380 @end smallexample
10381
10382 Also note that each label has its own date and time, which corresponds
10383 to when @GNUTAR{} initially attempted to write it,
10384 often soon after the operator launches @command{tar} or types the
10385 carriage return telling that the next tape is ready. Comparing date
10386 labels does give an idea of tape throughput only if the delays for
10387 rewinding tapes and the operator switching them were negligible, which
10388 is usually not the case.
10389
10390 @node verify
10391 @section Verifying Data as It is Stored
10392 @cindex Verifying a write operation
10393 @cindex Double-checking a write operation
10394
10395 @table @option
10396 @item -W
10397 @itemx --verify
10398 @opindex verify, short description
10399 Attempt to verify the archive after writing.
10400 @end table
10401
10402 This option causes @command{tar} to verify the archive after writing it.
10403 Each volume is checked after it is written, and any discrepancies
10404 are recorded on the standard error output.
10405
10406 Verification requires that the archive be on a back-space-able medium.
10407 This means pipes, some cartridge tape drives, and some other devices
10408 cannot be verified.
10409
10410 You can insure the accuracy of an archive by comparing files in the
10411 system with archive members. @command{tar} can compare an archive to the
10412 file system as the archive is being written, to verify a write
10413 operation, or can compare a previously written archive, to insure that
10414 it is up to date.
10415
10416 @xopindex{verify, using with @option{--create}}
10417 @xopindex{create, using with @option{--verify}}
10418 To check for discrepancies in an archive immediately after it is
10419 written, use the @option{--verify} (@option{-W}) option in conjunction with
10420 the @option{--create} operation. When this option is
10421 specified, @command{tar} checks archive members against their counterparts
10422 in the file system, and reports discrepancies on the standard error.
10423
10424 To verify an archive, you must be able to read it from before the end
10425 of the last written entry. This option is useful for detecting data
10426 errors on some tapes. Archives written to pipes, some cartridge tape
10427 drives, and some other devices cannot be verified.
10428
10429 One can explicitly compare an already made archive with the file
10430 system by using the @option{--compare} (@option{--diff}, @option{-d})
10431 option, instead of using the more automatic @option{--verify} option.
10432 @xref{compare}.
10433
10434 Note that these two options have a slightly different intent. The
10435 @option{--compare} option checks how identical are the logical contents of some
10436 archive with what is on your disks, while the @option{--verify} option is
10437 really for checking if the physical contents agree and if the recording
10438 media itself is of dependable quality. So, for the @option{--verify}
10439 operation, @command{tar} tries to defeat all in-memory cache pertaining to
10440 the archive, while it lets the speed optimization undisturbed for the
10441 @option{--compare} option. If you nevertheless use @option{--compare} for
10442 media verification, you may have to defeat the in-memory cache yourself,
10443 maybe by opening and reclosing the door latch of your recording unit,
10444 forcing some doubt in your operating system about the fact this is really
10445 the same volume as the one just written or read.
10446
10447 The @option{--verify} option would not be necessary if drivers were indeed
10448 able to detect dependably all write failures. This sometimes require many
10449 magnetic heads, some able to read after the writes occurred. One would
10450 not say that drivers unable to detect all cases are necessarily flawed,
10451 as long as programming is concerned.
10452
10453 The @option{--verify} (@option{-W}) option will not work in
10454 conjunction with the @option{--multi-volume} (@option{-M}) option or
10455 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
10456 and @option{--delete} operations. @xref{Operations}, for more
10457 information on these operations.
10458
10459 Also, since @command{tar} normally strips leading @samp{/} from file
10460 names (@pxref{absolute}), a command like @samp{tar --verify -cf
10461 /tmp/foo.tar /etc} will work as desired only if the working directory is
10462 @file{/}, as @command{tar} uses the archive's relative member names
10463 (e.g., @file{etc/motd}) when verifying the archive.
10464
10465 @node Write Protection
10466 @section Write Protection
10467
10468 Almost all tapes and diskettes, and in a few rare cases, even disks can
10469 be @dfn{write protected}, to protect data on them from being changed.
10470 Once an archive is written, you should write protect the media to prevent
10471 the archive from being accidentally overwritten or deleted. (This will
10472 protect the archive from being changed with a tape or floppy drive---it
10473 will not protect it from magnet fields or other physical hazards).
10474
10475 The write protection device itself is usually an integral part of the
10476 physical media, and can be a two position (write enabled/write
10477 disabled) switch, a notch which can be popped out or covered, a ring
10478 which can be removed from the center of a tape reel, or some other
10479 changeable feature.
10480
10481 @node Changes
10482 @appendix Changes
10483
10484 This appendix lists some important user-visible changes between
10485 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
10486 version of this document is available at
10487 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
10488 @GNUTAR{} documentation page}.
10489
10490 @table @asis
10491 @item Use of globbing patterns when listing and extracting.
10492
10493 Previous versions of GNU tar assumed shell-style globbing when
10494 extracting from or listing an archive. For example:
10495
10496 @smallexample
10497 $ @kbd{tar xf foo.tar '*.c'}
10498 @end smallexample
10499
10500 would extract all files whose names end in @samp{.c}. This behavior
10501 was not documented and was incompatible with traditional tar
10502 implementations. Therefore, starting from version 1.15.91, GNU tar
10503 no longer uses globbing by default. For example, the above invocation
10504 is now interpreted as a request to extract from the archive the file
10505 named @file{*.c}.
10506
10507 To facilitate transition to the new behavior for those users who got
10508 used to the previous incorrect one, @command{tar} will print a warning
10509 if it finds out that a requested member was not found in the archive
10510 and its name looks like a globbing pattern. For example:
10511
10512 @smallexample
10513 $ @kbd{tar xf foo.tar '*.c'}
10514 tar: Pattern matching characters used in file names. Please,
10515 tar: use --wildcards to enable pattern matching, or --no-wildcards to
10516 tar: suppress this warning.
10517 tar: *.c: Not found in archive
10518 tar: Error exit delayed from previous errors
10519 @end smallexample
10520
10521 To treat member names as globbing patterns, use --wildcards option.
10522 If you want to tar to mimic the behavior of versions prior to 1.15.91,
10523 add this option to your @env{TAR_OPTIONS} variable.
10524
10525 @xref{wildcards}, for the detailed discussion of the use of globbing
10526 patterns by @GNUTAR{}.
10527
10528 @item Use of short option @option{-o}.
10529
10530 Earlier versions of @GNUTAR{} understood @option{-o} command line
10531 option as a synonym for @option{--old-archive}.
10532
10533 @GNUTAR{} starting from version 1.13.90 understands this option as
10534 a synonym for @option{--no-same-owner}. This is compatible with
10535 UNIX98 @command{tar} implementations.
10536
10537 However, to facilitate transition, @option{-o} option retains its
10538 old semantics when it is used with one of archive-creation commands.
10539 Users are encouraged to use @option{--format=oldgnu} instead.
10540
10541 It is especially important, since versions of @acronym{GNU} Automake
10542 up to and including 1.8.4 invoke tar with this option to produce
10543 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
10544 of this issue and its implications.
10545
10546 @FIXME{Change the first argument to tar-formats when the new Automake is
10547 out. The proposition to add @anchor{} to the appropriate place of its
10548 docs was accepted by Automake people --Sergey 2006-05-25}.
10549 @xref{Options, tar-v7, Changing Automake's Behavior,
10550 automake, GNU Automake}, for a description on how to use various
10551 archive formats with @command{automake}.
10552
10553 Future versions of @GNUTAR{} will understand @option{-o} only as a
10554 synonym for @option{--no-same-owner}.
10555
10556 @item Use of short option @option{-l}
10557
10558 Earlier versions of @GNUTAR{} understood @option{-l} option as a
10559 synonym for @option{--one-file-system}. Since such usage contradicted
10560 to UNIX98 specification and harmed compatibility with other
10561 implementation, it was declared deprecated in version 1.14. However,
10562 to facilitate transition to its new semantics, it was supported by
10563 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
10564 variant of @option{--check-links} was introduced in version 1.15.91.
10565
10566 @item Use of options @option{--portability} and @option{--old-archive}
10567
10568 These options are deprecated. Please use @option{--format=v7} instead.
10569
10570 @item Use of option @option{--posix}
10571
10572 This option is deprecated. Please use @option{--format=posix} instead.
10573 @end table
10574
10575 @node Configuring Help Summary
10576 @appendix Configuring Help Summary
10577
10578 Running @kbd{tar --help} displays the short @command{tar} option
10579 summary (@pxref{help}). This summary is organized by @dfn{groups} of
10580 semantically close options. The options within each group are printed
10581 in the following order: a short option, eventually followed by a list
10582 of corresponding long option names, followed by a short description of
10583 the option. For example, here is an excerpt from the actual @kbd{tar
10584 --help} output:
10585
10586 @verbatim
10587 Main operation mode:
10588
10589 -A, --catenate, --concatenate append tar files to an archive
10590 -c, --create create a new archive
10591 -d, --diff, --compare find differences between archive and
10592 file system
10593 --delete delete from the archive
10594 @end verbatim
10595
10596 @vrindex ARGP_HELP_FMT, environment variable
10597 The exact visual representation of the help output is configurable via
10598 @env{ARGP_HELP_FMT} environment variable. The value of this variable
10599 is a comma-separated list of @dfn{format variable} assignments. There
10600 are two kinds of format variables. An @dfn{offset variable} keeps the
10601 offset of some part of help output text from the leftmost column on
10602 the screen. A @dfn{boolean} variable is a flag that toggles some
10603 output feature on or off. Depending on the type of the corresponding
10604 variable, there are two kinds of assignments:
10605
10606 @table @asis
10607 @item Offset assignment
10608
10609 The assignment to an offset variable has the following syntax:
10610
10611 @smallexample
10612 @var{variable}=@var{value}
10613 @end smallexample
10614
10615 @noindent
10616 where @var{variable} is the variable name, and @var{value} is a
10617 numeric value to be assigned to the variable.
10618
10619 @item Boolean assignment
10620
10621 To assign @code{true} value to a variable, simply put this variable name. To
10622 assign @code{false} value, prefix the variable name with @samp{no-}. For
10623 example:
10624
10625 @smallexample
10626 @group
10627 # Assign @code{true} value:
10628 dup-args
10629 # Assign @code{false} value:
10630 no-dup-args
10631 @end group
10632 @end smallexample
10633 @end table
10634
10635 Following variables are declared:
10636
10637 @deftypevr {Help Output} boolean dup-args
10638 If true, arguments for an option are shown with both short and long
10639 options, even when a given option has both forms, for example:
10640
10641 @smallexample
10642 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
10643 @end smallexample
10644
10645 If false, then if an option has both short and long forms, the
10646 argument is only shown with the long one, for example:
10647
10648 @smallexample
10649 -f, --file=ARCHIVE use archive file or device ARCHIVE
10650 @end smallexample
10651
10652 @noindent
10653 and a message indicating that the argument is applicable to both
10654 forms is printed below the options. This message can be disabled
10655 using @code{dup-args-note} (see below).
10656
10657 The default is false.
10658 @end deftypevr
10659
10660 @deftypevr {Help Output} boolean dup-args-note
10661 If this variable is true, which is the default, the following notice
10662 is displayed at the end of the help output:
10663
10664 @quotation
10665 Mandatory or optional arguments to long options are also mandatory or
10666 optional for any corresponding short options.
10667 @end quotation
10668
10669 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
10670 variables @code{dup-args} or @code{dup-args-note} should be set.
10671 @end deftypevr
10672
10673 @deftypevr {Help Output} offset short-opt-col
10674 Column in which short options start. Default is 2.
10675
10676 @smallexample
10677 @group
10678 $ @kbd{tar --help|grep ARCHIVE}
10679 -f, --file=ARCHIVE use archive file or device ARCHIVE
10680 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
10681 -f, --file=ARCHIVE use archive file or device ARCHIVE
10682 @end group
10683 @end smallexample
10684 @end deftypevr
10685
10686 @deftypevr {Help Output} offset long-opt-col
10687 Column in which long options start. Default is 6. For example:
10688
10689 @smallexample
10690 @group
10691 $ @kbd{tar --help|grep ARCHIVE}
10692 -f, --file=ARCHIVE use archive file or device ARCHIVE
10693 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
10694 -f, --file=ARCHIVE use archive file or device ARCHIVE
10695 @end group
10696 @end smallexample
10697 @end deftypevr
10698
10699 @deftypevr {Help Output} offset doc-opt-col
10700 Column in which @dfn{doc options} start. A doc option isn't actually
10701 an option, but rather an arbitrary piece of documentation that is
10702 displayed in much the same manner as the options. For example, in
10703 the description of @option{--format} option:
10704
10705 @smallexample
10706 @group
10707 -H, --format=FORMAT create archive of the given format.
10708
10709 FORMAT is one of the following:
10710
10711 gnu GNU tar 1.13.x format
10712 oldgnu GNU format as per tar <= 1.12
10713 pax POSIX 1003.1-2001 (pax) format
10714 posix same as pax
10715 ustar POSIX 1003.1-1988 (ustar) format
10716 v7 old V7 tar format
10717 @end group
10718 @end smallexample
10719
10720 @noindent
10721 the format names are doc options. Thus, if you set
10722 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
10723 will look as follows:
10724
10725 @smallexample
10726 @group
10727 -H, --format=FORMAT create archive of the given format.
10728
10729 FORMAT is one of the following:
10730
10731 gnu GNU tar 1.13.x format
10732 oldgnu GNU format as per tar <= 1.12
10733 pax POSIX 1003.1-2001 (pax) format
10734 posix same as pax
10735 ustar POSIX 1003.1-1988 (ustar) format
10736 v7 old V7 tar format
10737 @end group
10738 @end smallexample
10739 @end deftypevr
10740
10741 @deftypevr {Help Output} offset opt-doc-col
10742 Column in which option description starts. Default is 29.
10743
10744 @smallexample
10745 @group
10746 $ @kbd{tar --help|grep ARCHIVE}
10747 -f, --file=ARCHIVE use archive file or device ARCHIVE
10748 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
10749 -f, --file=ARCHIVE use archive file or device ARCHIVE
10750 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
10751 -f, --file=ARCHIVE
10752 use archive file or device ARCHIVE
10753 @end group
10754 @end smallexample
10755
10756 @noindent
10757 Notice, that the description starts on a separate line if
10758 @code{opt-doc-col} value is too small.
10759 @end deftypevr
10760
10761 @deftypevr {Help Output} offset header-col
10762 Column in which @dfn{group headers} are printed. A group header is a
10763 descriptive text preceding an option group. For example, in the
10764 following text:
10765
10766 @verbatim
10767 Main operation mode:
10768
10769 -A, --catenate, --concatenate append tar files to
10770 an archive
10771 -c, --create create a new archive
10772 @end verbatim
10773 @noindent
10774 @samp{Main operation mode:} is the group header.
10775
10776 The default value is 1.
10777 @end deftypevr
10778
10779 @deftypevr {Help Output} offset usage-indent
10780 Indentation of wrapped usage lines. Affects @option{--usage}
10781 output. Default is 12.
10782 @end deftypevr
10783
10784 @deftypevr {Help Output} offset rmargin
10785 Right margin of the text output. Used for wrapping.
10786 @end deftypevr
10787
10788 @node Tar Internals
10789 @appendix Tar Internals
10790 @include intern.texi
10791
10792 @node Genfile
10793 @appendix Genfile
10794 @include genfile.texi
10795
10796 @node Free Software Needs Free Documentation
10797 @appendix Free Software Needs Free Documentation
10798 @include freemanuals.texi
10799
10800 @node Copying This Manual
10801 @appendix Copying This Manual
10802
10803 @menu
10804 * GNU Free Documentation License:: License for copying this manual
10805 @end menu
10806
10807 @include fdl.texi
10808
10809 @node Index of Command Line Options
10810 @appendix Index of Command Line Options
10811
10812 This appendix contains an index of all @GNUTAR{} long command line
10813 options. The options are listed without the preceding double-dash.
10814 For a cross-reference of short command line options, @ref{Short Option Summary}.
10815
10816 @printindex op
10817
10818 @node Index
10819 @appendix Index
10820
10821 @printindex cp
10822
10823 @summarycontents
10824 @contents
10825 @bye
10826
10827 @c Local variables:
10828 @c texinfo-column-for-description: 32
10829 @c End:
This page took 0.500099 seconds and 5 git commands to generate.