]> Dogcows Code - chaz/tar/blob - doc/tar.texi
Merge branch 'master' of ssh://git.sv.gnu.org/srv/git/tar
[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 @defcodeindex kw
25
26 @c Put everything in one index (arbitrarily chosen to be the concept index).
27 @syncodeindex fn cp
28 @syncodeindex ky cp
29 @syncodeindex pg cp
30 @syncodeindex vr cp
31 @syncodeindex kw cp
32
33 @copying
34
35 This manual is for @acronym{GNU} @command{tar} (version
36 @value{VERSION}, @value{UPDATED}), which creates and extracts files
37 from archives.
38
39 Copyright @copyright{} 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
40 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
41
42 @quotation
43 Permission is granted to copy, distribute and/or modify this document
44 under the terms of the GNU Free Documentation License, Version 1.3 or
45 any later version published by the Free Software Foundation; with no
46 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
47 and with the Back-Cover Texts as in (a) below. A copy of the license
48 is included in the section entitled ``GNU Free Documentation
49 License''.
50
51 (a) The FSF's Back-Cover Text is: ``You have the freedom to
52 copy and modify this GNU manual. Buying copies from the FSF
53 supports it in developing GNU and promoting software freedom.''
54 @end quotation
55 @end copying
56
57 @dircategory Archiving
58 @direntry
59 * Tar: (tar). Making tape (or disk) archives.
60 @end direntry
61
62 @dircategory Individual utilities
63 @direntry
64 * tar: (tar)tar invocation. Invoking @GNUTAR{}.
65 @end direntry
66
67 @shorttitlepage @acronym{GNU} @command{tar}
68
69 @titlepage
70 @title @acronym{GNU} tar: an archiver tool
71 @subtitle @value{RENDITION} @value{VERSION}, @value{UPDATED}
72 @author John Gilmore, Jay Fenlason et al.
73
74 @page
75 @vskip 0pt plus 1filll
76 @insertcopying
77 @end titlepage
78
79 @ifnottex
80 @node Top
81 @top @acronym{GNU} tar: an archiver tool
82
83 @insertcopying
84
85 @cindex file archival
86 @cindex archiving files
87
88 The first part of this master menu lists the major nodes in this Info
89 document. The rest of the menu lists all the lower level nodes.
90 @end ifnottex
91
92 @c The master menu goes here.
93 @c
94 @c NOTE: To update it from within Emacs, make sure mastermenu.el is
95 @c loaded and run texinfo-master-menu.
96 @c To update it from the command line, run
97 @c
98 @c make master-menu
99
100 @menu
101 * Introduction::
102 * Tutorial::
103 * tar invocation::
104 * operations::
105 * Backups::
106 * Choosing::
107 * Date input formats::
108 * Formats::
109 * Media::
110 * Reliability and security::
111
112 Appendices
113
114 * Changes::
115 * Configuring Help Summary::
116 * Fixing Snapshot Files::
117 * Tar Internals::
118 * Genfile::
119 * Free Software Needs Free Documentation::
120 * GNU Free Documentation License::
121 * Index of Command Line Options::
122 * Index::
123
124 @detailmenu
125 --- The Detailed Node Listing ---
126
127 Introduction
128
129 * Book Contents:: What this Book Contains
130 * Definitions:: Some Definitions
131 * What tar Does:: What @command{tar} Does
132 * Naming tar Archives:: How @command{tar} Archives are Named
133 * Authors:: @GNUTAR{} Authors
134 * Reports:: Reporting bugs or suggestions
135
136 Tutorial Introduction to @command{tar}
137
138 * assumptions::
139 * stylistic conventions::
140 * basic tar options:: Basic @command{tar} Operations and Options
141 * frequent operations::
142 * Two Frequent Options::
143 * create:: How to Create Archives
144 * list:: How to List Archives
145 * extract:: How to Extract Members from an Archive
146 * going further::
147
148 Two Frequently Used Options
149
150 * file tutorial::
151 * verbose tutorial::
152 * help tutorial::
153
154 How to Create Archives
155
156 * prepare for examples::
157 * Creating the archive::
158 * create verbose::
159 * short create::
160 * create dir::
161
162 How to List Archives
163
164 * list dir::
165
166 How to Extract Members from an Archive
167
168 * extracting archives::
169 * extracting files::
170 * extract dir::
171 * extracting untrusted archives::
172 * failing commands::
173
174 Invoking @GNUTAR{}
175
176 * Synopsis::
177 * using tar options::
178 * Styles::
179 * All Options::
180 * help::
181 * defaults::
182 * verbose::
183 * checkpoints::
184 * warnings::
185 * interactive::
186
187 The Three Option Styles
188
189 * Long Options:: Long Option Style
190 * Short Options:: Short Option Style
191 * Old Options:: Old Option Style
192 * Mixing:: Mixing Option Styles
193
194 All @command{tar} Options
195
196 * Operation Summary::
197 * Option Summary::
198 * Short Option Summary::
199
200 @GNUTAR{} Operations
201
202 * Basic tar::
203 * Advanced tar::
204 * create options::
205 * extract options::
206 * backup::
207 * Applications::
208 * looking ahead::
209
210 Advanced @GNUTAR{} Operations
211
212 * Operations::
213 * append::
214 * update::
215 * concatenate::
216 * delete::
217 * compare::
218
219 How to Add Files to Existing Archives: @option{--append}
220
221 * appending files:: Appending Files to an Archive
222 * multiple::
223
224 Updating an Archive
225
226 * how to update::
227
228 Options Used by @option{--create}
229
230 * override:: Overriding File Metadata.
231 * Ignore Failed Read::
232
233 Options Used by @option{--extract}
234
235 * Reading:: Options to Help Read Archives
236 * Writing:: Changing How @command{tar} Writes Files
237 * Scarce:: Coping with Scarce Resources
238
239 Options to Help Read Archives
240
241 * read full records::
242 * Ignore Zeros::
243
244 Changing How @command{tar} Writes Files
245
246 * Dealing with Old Files::
247 * Overwrite Old Files::
248 * Keep Old Files::
249 * Keep Newer Files::
250 * Unlink First::
251 * Recursive Unlink::
252 * Data Modification Times::
253 * Setting Access Permissions::
254 * Directory Modification Times and Permissions::
255 * Writing to Standard Output::
256 * Writing to an External Program::
257 * remove files::
258
259 Coping with Scarce Resources
260
261 * Starting File::
262 * Same Order::
263
264 Performing Backups and Restoring Files
265
266 * Full Dumps:: Using @command{tar} to Perform Full Dumps
267 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
268 * Backup Levels:: Levels of Backups
269 * Backup Parameters:: Setting Parameters for Backups and Restoration
270 * Scripted Backups:: Using the Backup Scripts
271 * Scripted Restoration:: Using the Restore Script
272
273 Setting Parameters for Backups and Restoration
274
275 * General-Purpose Variables::
276 * Magnetic Tape Control::
277 * User Hooks::
278 * backup-specs example:: An Example Text of @file{Backup-specs}
279
280 Choosing Files and Names for @command{tar}
281
282 * file:: Choosing the Archive's Name
283 * Selecting Archive Members::
284 * files:: Reading Names from a File
285 * exclude:: Excluding Some Files
286 * wildcards:: Wildcards Patterns and Matching
287 * quoting styles:: Ways of Quoting Special Characters in Names
288 * transform:: Modifying File and Member Names
289 * after:: Operating Only on New Files
290 * recurse:: Descending into Directories
291 * one:: Crossing File System Boundaries
292
293 Reading Names from a File
294
295 * nul::
296
297 Excluding Some Files
298
299 * problems with exclude::
300
301 Wildcards Patterns and Matching
302
303 * controlling pattern-matching::
304
305 Crossing File System Boundaries
306
307 * directory:: Changing Directory
308 * absolute:: Absolute File Names
309
310 Date input formats
311
312 * General date syntax:: Common rules.
313 * Calendar date items:: 19 Dec 1994.
314 * Time of day items:: 9:20pm.
315 * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}.
316 * Day of week items:: Monday and others.
317 * Relative items in date strings:: next tuesday, 2 years ago.
318 * Pure numbers in date strings:: 19931219, 1440.
319 * Seconds since the Epoch:: @@1078100502.
320 * Specifying time zone rules:: TZ="America/New_York", TZ="UTC0".
321 * Authors of parse_datetime:: Bellovin, Eggert, Salz, Berets, et al.
322
323 Controlling the Archive Format
324
325 * Compression:: Using Less Space through Compression
326 * Attributes:: Handling File Attributes
327 * Portability:: Making @command{tar} Archives More Portable
328 * cpio:: Comparison of @command{tar} and @command{cpio}
329
330 Using Less Space through Compression
331
332 * gzip:: Creating and Reading Compressed Archives
333 * sparse:: Archiving Sparse Files
334
335 Creating and Reading Compressed Archives
336
337 * lbzip2:: Using lbzip2 with @GNUTAR{}.
338
339 Making @command{tar} Archives More Portable
340
341 * Portable Names:: Portable Names
342 * dereference:: Symbolic Links
343 * hard links:: Hard Links
344 * old:: Old V7 Archives
345 * ustar:: Ustar Archives
346 * gnu:: GNU and old GNU format archives.
347 * posix:: @acronym{POSIX} archives
348 * Checksumming:: Checksumming Problems
349 * Large or Negative Values:: Large files, negative time stamps, etc.
350 * Other Tars:: How to Extract GNU-Specific Data Using
351 Other @command{tar} Implementations
352
353 @GNUTAR{} and @acronym{POSIX} @command{tar}
354
355 * PAX keywords:: Controlling Extended Header Keywords.
356
357 How to Extract GNU-Specific Data Using Other @command{tar} Implementations
358
359 * Split Recovery:: Members Split Between Volumes
360 * Sparse Recovery:: Sparse Members
361
362 Tapes and Other Archive Media
363
364 * Device:: Device selection and switching
365 * Remote Tape Server::
366 * Common Problems and Solutions::
367 * Blocking:: Blocking
368 * Many:: Many archives on one tape
369 * Using Multiple Tapes:: Using Multiple Tapes
370 * label:: Including a Label in the Archive
371 * verify::
372 * Write Protection::
373
374 Blocking
375
376 * Format Variations:: Format Variations
377 * Blocking Factor:: The Blocking Factor of an Archive
378
379 Many Archives on One Tape
380
381 * Tape Positioning:: Tape Positions and Tape Marks
382 * mt:: The @command{mt} Utility
383
384 Using Multiple Tapes
385
386 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
387 * Tape Files:: Tape Files
388 * Tarcat:: Concatenate Volumes into a Single Archive
389
390
391 Tar Internals
392
393 * Standard:: Basic Tar Format
394 * Extensions:: @acronym{GNU} Extensions to the Archive Format
395 * Sparse Formats:: Storing Sparse Files
396 * Snapshot Files::
397 * Dumpdir::
398
399 Storing Sparse Files
400
401 * Old GNU Format::
402 * PAX 0:: PAX Format, Versions 0.0 and 0.1
403 * PAX 1:: PAX Format, Version 1.0
404
405 Genfile
406
407 * Generate Mode:: File Generation Mode.
408 * Status Mode:: File Status Mode.
409 * Exec Mode:: Synchronous Execution mode.
410
411 Copying This Manual
412
413 * GNU Free Documentation License:: License for copying this manual
414
415 @end detailmenu
416 @end menu
417
418 @node Introduction
419 @chapter Introduction
420
421 @GNUTAR{} creates
422 and manipulates @dfn{archives} which are actually collections of
423 many other files; the program provides users with an organized and
424 systematic method for controlling a large amount of data.
425 The name ``tar'' originally came from the phrase ``Tape ARchive'', but
426 archives need not (and these days, typically do not) reside on tapes.
427
428 @menu
429 * Book Contents:: What this Book Contains
430 * Definitions:: Some Definitions
431 * What tar Does:: What @command{tar} Does
432 * Naming tar Archives:: How @command{tar} Archives are Named
433 * Authors:: @GNUTAR{} Authors
434 * Reports:: Reporting bugs or suggestions
435 @end menu
436
437 @node Book Contents
438 @section What this Book Contains
439
440 The first part of this chapter introduces you to various terms that will
441 recur throughout the book. It also tells you who has worked on @GNUTAR{}
442 and its documentation, and where you should send bug reports
443 or comments.
444
445 The second chapter is a tutorial (@pxref{Tutorial}) which provides a
446 gentle introduction for people who are new to using @command{tar}. It is
447 meant to be self-contained, not requiring any reading from subsequent
448 chapters to make sense. It moves from topic to topic in a logical,
449 progressive order, building on information already explained.
450
451 Although the tutorial is paced and structured to allow beginners to
452 learn how to use @command{tar}, it is not intended solely for beginners.
453 The tutorial explains how to use the three most frequently used
454 operations (@samp{create}, @samp{list}, and @samp{extract}) as well as
455 two frequently used options (@samp{file} and @samp{verbose}). The other
456 chapters do not refer to the tutorial frequently; however, if a section
457 discusses something which is a complex variant of a basic concept, there
458 may be a cross-reference to that basic concept. (The entire book,
459 including the tutorial, assumes that the reader understands some basic
460 concepts of using a Unix-type operating system; @pxref{Tutorial}.)
461
462 The third chapter presents the remaining five operations, and
463 information about using @command{tar} options and option syntax.
464
465 The other chapters are meant to be used as a reference. Each chapter
466 presents everything that needs to be said about a specific topic.
467
468 One of the chapters (@pxref{Date input formats}) exists in its
469 entirety in other @acronym{GNU} manuals, and is mostly self-contained.
470 In addition, one section of this manual (@pxref{Standard}) contains a
471 big quote which is taken directly from @command{tar} sources.
472
473 In general, we give both long and short (abbreviated) option names
474 at least once in each section where the relevant option is covered, so
475 that novice readers will become familiar with both styles. (A few
476 options have no short versions, and the relevant sections will
477 indicate this.)
478
479 @node Definitions
480 @section Some Definitions
481
482 @cindex archive
483 @cindex tar archive
484 The @command{tar} program is used to create and manipulate @command{tar}
485 archives. An @dfn{archive} is a single file which contains the contents
486 of many files, while still identifying the names of the files, their
487 owner(s), and so forth. (In addition, archives record access
488 permissions, user and group, size in bytes, and data modification time.
489 Some archives also record the file names in each archived directory, as
490 well as other file and directory information.) You can use @command{tar}
491 to @dfn{create} a new archive in a specified directory.
492
493 @cindex member
494 @cindex archive member
495 @cindex file name
496 @cindex member name
497 The files inside an archive are called @dfn{members}. Within this
498 manual, we use the term @dfn{file} to refer only to files accessible in
499 the normal ways (by @command{ls}, @command{cat}, and so forth), and the term
500 @dfn{member} to refer only to the members of an archive. Similarly, a
501 @dfn{file name} is the name of a file, as it resides in the file system,
502 and a @dfn{member name} is the name of an archive member within the
503 archive.
504
505 @cindex extraction
506 @cindex unpacking
507 The term @dfn{extraction} refers to the process of copying an archive
508 member (or multiple members) into a file in the file system. Extracting
509 all the members of an archive is often called @dfn{extracting the
510 archive}. The term @dfn{unpack} can also be used to refer to the
511 extraction of many or all the members of an archive. Extracting an
512 archive does not destroy the archive's structure, just as creating an
513 archive does not destroy the copies of the files that exist outside of
514 the archive. You may also @dfn{list} the members in a given archive
515 (this is often thought of as ``printing'' them to the standard output,
516 or the command line), or @dfn{append} members to a pre-existing archive.
517 All of these operations can be performed using @command{tar}.
518
519 @node What tar Does
520 @section What @command{tar} Does
521
522 @cindex tar
523 The @command{tar} program provides the ability to create @command{tar}
524 archives, as well as various other kinds of manipulation. For example,
525 you can use @command{tar} on previously created archives to extract files,
526 to store additional files, or to update or list files which were already
527 stored.
528
529 Initially, @command{tar} archives were used to store files conveniently on
530 magnetic tape. The name @command{tar} comes from this use; it stands for
531 @code{t}ape @code{ar}chiver. Despite the utility's name, @command{tar} can
532 direct its output to available devices, files, or other programs (using
533 pipes). @command{tar} may even access remote devices or files (as archives).
534
535 You can use @command{tar} archives in many ways. We want to stress a few
536 of them: storage, backup, and transportation.
537
538 @FIXME{the following table entries need a bit of work.}
539 @table @asis
540 @item Storage
541 Often, @command{tar} archives are used to store related files for
542 convenient file transfer over a network. For example, the
543 @acronym{GNU} Project distributes its software bundled into
544 @command{tar} archives, so that all the files relating to a particular
545 program (or set of related programs) can be transferred as a single
546 unit.
547
548 A magnetic tape can store several files in sequence. However, the tape
549 has no names for these files; it only knows their relative position on
550 the tape. One way to store several files on one tape and retain their
551 names is by creating a @command{tar} archive. Even when the basic transfer
552 mechanism can keep track of names, as FTP can, the nuisance of handling
553 multiple files, directories, and multiple links makes @command{tar}
554 archives useful.
555
556 Archive files are also used for long-term storage. You can think of
557 this as transportation from the present into the future. (It is a
558 science-fiction idiom that you can move through time as well as in
559 space; the idea here is that @command{tar} can be used to move archives in
560 all dimensions, even time!)
561
562 @item Backup
563 Because the archive created by @command{tar} is capable of preserving
564 file information and directory structure, @command{tar} is commonly
565 used for performing full and incremental backups of disks. A backup
566 puts a collection of files (possibly pertaining to many users and
567 projects) together on a disk or a tape. This guards against
568 accidental destruction of the information in those files.
569 @GNUTAR{} has special features that allow it to be
570 used to make incremental and full dumps of all the files in a
571 file system.
572
573 @item Transportation
574 You can create an archive on one system, transfer it to another system,
575 and extract the contents there. This allows you to transport a group of
576 files from one system to another.
577 @end table
578
579 @node Naming tar Archives
580 @section How @command{tar} Archives are Named
581
582 Conventionally, @command{tar} archives are given names ending with
583 @samp{.tar}. This is not necessary for @command{tar} to operate properly,
584 but this manual follows that convention in order to accustom readers to
585 it and to make examples more clear.
586
587 @cindex tar file
588 @cindex entry
589 @cindex tar entry
590 Often, people refer to @command{tar} archives as ``@command{tar} files,'' and
591 archive members as ``files'' or ``entries''. For people familiar with
592 the operation of @command{tar}, this causes no difficulty. However, in
593 this manual, we consistently refer to ``archives'' and ``archive
594 members'' to make learning to use @command{tar} easier for novice users.
595
596 @node Authors
597 @section @GNUTAR{} Authors
598
599 @GNUTAR{} was originally written by John Gilmore,
600 and modified by many people. The @acronym{GNU} enhancements were
601 written by Jay Fenlason, then Joy Kendall, and the whole package has
602 been further maintained by Thomas Bushnell, n/BSG, Fran@,{c}ois
603 Pinard, Paul Eggert, and finally Sergey Poznyakoff with the help of
604 numerous and kind users.
605
606 We wish to stress that @command{tar} is a collective work, and owes much to
607 all those people who reported problems, offered solutions and other
608 insights, or shared their thoughts and suggestions. An impressive, yet
609 partial list of those contributors can be found in the @file{THANKS}
610 file from the @GNUTAR{} distribution.
611
612 @FIXME{i want all of these names mentioned, Absolutely. BUT, i'm not
613 sure i want to spell out the history in this detail, at least not for
614 the printed book. i'm just not sure it needs to be said this way.
615 i'll think about it.}
616
617 @FIXME{History is more important, and surely more interesting, than
618 actual names. Quoting names without history would be meaningless. FP}
619
620 Jay Fenlason put together a draft of a @GNUTAR{}
621 manual, borrowing notes from the original man page from John Gilmore.
622 This was withdrawn in version 1.11. Thomas Bushnell, n/BSG and Amy
623 Gorin worked on a tutorial and manual for @GNUTAR{}.
624 Fran@,{c}ois Pinard put version 1.11.8 of the manual together by
625 taking information from all these sources and merging them. Melissa
626 Weisshaus finally edited and redesigned the book to create version
627 1.12. The book for versions from 1.14 up to @value{VERSION} were edited
628 by the current maintainer, Sergey Poznyakoff.
629
630 For version 1.12, Daniel Hagerty contributed a great deal of technical
631 consulting. In particular, he is the primary author of @ref{Backups}.
632
633 In July, 2003 @GNUTAR{} was put on CVS at savannah.gnu.org
634 (see @url{http://savannah.gnu.org/projects/tar}), and
635 active development and maintenance work has started
636 again. Currently @GNUTAR{} is being maintained by Paul Eggert, Sergey
637 Poznyakoff and Jeff Bailey.
638
639 Support for @acronym{POSIX} archives was added by Sergey Poznyakoff.
640
641 @node Reports
642 @section Reporting bugs or suggestions
643
644 @cindex bug reports
645 @cindex reporting bugs
646 If you find problems or have suggestions about this program or manual,
647 please report them to @file{bug-tar@@gnu.org}.
648
649 When reporting a bug, please be sure to include as much detail as
650 possible, in order to reproduce it. @FIXME{Be more specific, I'd
651 like to make this node as detailed as 'Bug reporting' node in Emacs
652 manual.}
653
654 @node Tutorial
655 @chapter Tutorial Introduction to @command{tar}
656
657 This chapter guides you through some basic examples of three @command{tar}
658 operations: @option{--create}, @option{--list}, and @option{--extract}. If
659 you already know how to use some other version of @command{tar}, then you
660 may not need to read this chapter. This chapter omits most complicated
661 details about how @command{tar} works.
662
663 @menu
664 * assumptions::
665 * stylistic conventions::
666 * basic tar options:: Basic @command{tar} Operations and Options
667 * frequent operations::
668 * Two Frequent Options::
669 * create:: How to Create Archives
670 * list:: How to List Archives
671 * extract:: How to Extract Members from an Archive
672 * going further::
673 @end menu
674
675 @node assumptions
676 @section Assumptions this Tutorial Makes
677
678 This chapter is paced to allow beginners to learn about @command{tar}
679 slowly. At the same time, we will try to cover all the basic aspects of
680 these three operations. In order to accomplish both of these tasks, we
681 have made certain assumptions about your knowledge before reading this
682 manual, and the hardware you will be using:
683
684 @itemize @bullet
685 @item
686 Before you start to work through this tutorial, you should understand
687 what the terms ``archive'' and ``archive member'' mean
688 (@pxref{Definitions}). In addition, you should understand something
689 about how Unix-type operating systems work, and you should know how to
690 use some basic utilities. For example, you should know how to create,
691 list, copy, rename, edit, and delete files and directories; how to
692 change between directories; and how to figure out where you are in the
693 file system. You should have some basic understanding of directory
694 structure and how files are named according to which directory they are
695 in. You should understand concepts such as standard output and standard
696 input, what various definitions of the term @samp{argument} mean, and the
697 differences between relative and absolute file names. @FIXME{and what
698 else?}
699
700 @item
701 This manual assumes that you are working from your own home directory
702 (unless we state otherwise). In this tutorial, you will create a
703 directory to practice @command{tar} commands in. When we show file names,
704 we will assume that those names are relative to your home directory.
705 For example, my home directory is @file{/home/fsf/melissa}. All of
706 my examples are in a subdirectory of the directory named by that file
707 name; the subdirectory is called @file{practice}.
708
709 @item
710 In general, we show examples of archives which exist on (or can be
711 written to, or worked with from) a directory on a hard disk. In most
712 cases, you could write those archives to, or work with them on any other
713 device, such as a tape drive. However, some of the later examples in
714 the tutorial and next chapter will not work on tape drives.
715 Additionally, working with tapes is much more complicated than working
716 with hard disks. For these reasons, the tutorial does not cover working
717 with tape drives. @xref{Media}, for complete information on using
718 @command{tar} archives with tape drives.
719
720 @FIXME{this is a cop out. need to add some simple tape drive info.}
721 @end itemize
722
723 @node stylistic conventions
724 @section Stylistic Conventions
725
726 In the examples, @samp{$} represents a typical shell prompt. It
727 precedes lines you should type; to make this more clear, those lines are
728 shown in @kbd{this font}, as opposed to lines which represent the
729 computer's response; those lines are shown in @code{this font}, or
730 sometimes @samp{like this}.
731
732 @c When we have lines which are too long to be
733 @c displayed in any other way, we will show them like this:
734
735 @node basic tar options
736 @section Basic @command{tar} Operations and Options
737
738 @command{tar} can take a wide variety of arguments which specify and define
739 the actions it will have on the particular set of files or the archive.
740 The main types of arguments to @command{tar} fall into one of two classes:
741 operations, and options.
742
743 Some arguments fall into a class called @dfn{operations}; exactly one of
744 these is both allowed and required for any instance of using @command{tar};
745 you may @emph{not} specify more than one. People sometimes speak of
746 @dfn{operating modes}. You are in a particular operating mode when you
747 have specified the operation which specifies it; there are eight
748 operations in total, and thus there are eight operating modes.
749
750 The other arguments fall into the class known as @dfn{options}. You are
751 not required to specify any options, and you are allowed to specify more
752 than one at a time (depending on the way you are using @command{tar} at
753 that time). Some options are used so frequently, and are so useful for
754 helping you type commands more carefully that they are effectively
755 ``required''. We will discuss them in this chapter.
756
757 You can write most of the @command{tar} operations and options in any
758 of three forms: long (mnemonic) form, short form, and old style. Some
759 of the operations and options have no short or ``old'' forms; however,
760 the operations and options which we will cover in this tutorial have
761 corresponding abbreviations. We will indicate those abbreviations
762 appropriately to get you used to seeing them. Note, that the ``old
763 style'' option forms exist in @GNUTAR{} for compatibility with Unix
764 @command{tar}. In this book we present a full discussion of this way
765 of writing options and operations (@pxref{Old Options}), and we discuss
766 the other two styles of writing options (@xref{Long Options}, and
767 @pxref{Short Options}).
768
769 In the examples and in the text of this tutorial, we usually use the
770 long forms of operations and options; but the ``short'' forms produce
771 the same result and can make typing long @command{tar} commands easier.
772 For example, instead of typing
773
774 @smallexample
775 @kbd{tar --create --verbose --file=afiles.tar apple angst aspic}
776 @end smallexample
777
778 @noindent
779 you can type
780 @smallexample
781 @kbd{tar -c -v -f afiles.tar apple angst aspic}
782 @end smallexample
783
784 @noindent
785 or even
786 @smallexample
787 @kbd{tar -cvf afiles.tar apple angst aspic}
788 @end smallexample
789
790 @noindent
791 For more information on option syntax, see @ref{Advanced tar}. In
792 discussions in the text, when we name an option by its long form, we
793 also give the corresponding short option in parentheses.
794
795 The term, ``option'', can be confusing at times, since ``operations''
796 are often lumped in with the actual, @emph{optional} ``options'' in certain
797 general class statements. For example, we just talked about ``short and
798 long forms of options and operations''. However, experienced @command{tar}
799 users often refer to these by shorthand terms such as, ``short and long
800 options''. This term assumes that the ``operations'' are included, also.
801 Context will help you determine which definition of ``options'' to use.
802
803 Similarly, the term ``command'' can be confusing, as it is often used in
804 two different ways. People sometimes refer to @command{tar} ``commands''.
805 A @command{tar} @dfn{command} is the entire command line of user input
806 which tells @command{tar} what to do --- including the operation, options,
807 and any arguments (file names, pipes, other commands, etc.). However,
808 you will also sometimes hear the term ``the @command{tar} command''. When
809 the word ``command'' is used specifically like this, a person is usually
810 referring to the @command{tar} @emph{operation}, not the whole line.
811 Again, use context to figure out which of the meanings the speaker
812 intends.
813
814 @node frequent operations
815 @section The Three Most Frequently Used Operations
816
817 Here are the three most frequently used operations (both short and long
818 forms), as well as a brief description of their meanings. The rest of
819 this chapter will cover how to use these operations in detail. We will
820 present the rest of the operations in the next chapter.
821
822 @table @option
823 @item --create
824 @itemx -c
825 Create a new @command{tar} archive.
826 @item --list
827 @itemx -t
828 List the contents of an archive.
829 @item --extract
830 @itemx -x
831 Extract one or more members from an archive.
832 @end table
833
834 @node Two Frequent Options
835 @section Two Frequently Used Options
836
837 To understand how to run @command{tar} in the three operating modes listed
838 previously, you also need to understand how to use two of the options to
839 @command{tar}: @option{--file} (which takes an archive file as an argument)
840 and @option{--verbose}. (You are usually not @emph{required} to specify
841 either of these options when you run @command{tar}, but they can be very
842 useful in making things more clear and helping you avoid errors.)
843
844 @menu
845 * file tutorial::
846 * verbose tutorial::
847 * help tutorial::
848 @end menu
849
850 @node file tutorial
851 @unnumberedsubsec The @option{--file} Option
852
853 @table @option
854 @xopindex{file, tutorial}
855 @item --file=@var{archive-name}
856 @itemx -f @var{archive-name}
857 Specify the name of an archive file.
858 @end table
859
860 You can specify an argument for the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option whenever you
861 use @command{tar}; this option determines the name of the archive file
862 that @command{tar} will work on.
863
864 @vrindex TAPE
865 If you don't specify this argument, then @command{tar} will examine
866 the environment variable @env{TAPE}. If it is set, its value will be
867 used as the archive name. Otherwise, @command{tar} will use the
868 default archive, determined at compile time. Usually it is
869 standard output or some physical tape drive attached to your machine
870 (you can verify what the default is by running @kbd{tar
871 --show-defaults}, @pxref{defaults}). If there is no tape drive
872 attached, or the default is not meaningful, then @command{tar} will
873 print an error message. The error message might look roughly like one
874 of the following:
875
876 @smallexample
877 tar: can't open /dev/rmt8 : No such device or address
878 tar: can't open /dev/rsmt0 : I/O error
879 @end smallexample
880
881 @noindent
882 To avoid confusion, we recommend that you always specify an archive file
883 name by using @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) when writing your @command{tar} commands.
884 For more information on using the @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) option, see
885 @ref{file}.
886
887 @node verbose tutorial
888 @unnumberedsubsec The @option{--verbose} Option
889
890 @table @option
891 @xopindex{verbose, introduced}
892 @item --verbose
893 @itemx -v
894 Show the files being worked on as @command{tar} is running.
895 @end table
896
897 @option{--verbose} (@option{-v}) shows details about the results of running
898 @command{tar}. This can be especially useful when the results might not be
899 obvious. For example, if you want to see the progress of @command{tar} as
900 it writes files into the archive, you can use the @option{--verbose}
901 option. In the beginning, you may find it useful to use
902 @option{--verbose} at all times; when you are more accustomed to
903 @command{tar}, you will likely want to use it at certain times but not at
904 others. We will use @option{--verbose} at times to help make something
905 clear, and we will give many examples both using and not using
906 @option{--verbose} to show the differences.
907
908 Each instance of @option{--verbose} on the command line increases the
909 verbosity level by one, so if you need more details on the output,
910 specify it twice.
911
912 When reading archives (@option{--list}, @option{--extract},
913 @option{--diff}), @command{tar} by default prints only the names of
914 the members being extracted. Using @option{--verbose} will show a full,
915 @command{ls} style member listing.
916
917 In contrast, when writing archives (@option{--create}, @option{--append},
918 @option{--update}), @command{tar} does not print file names by
919 default. So, a single @option{--verbose} option shows the file names
920 being added to the archive, while two @option{--verbose} options
921 enable the full listing.
922
923 For example, to create an archive in verbose mode:
924
925 @smallexample
926 $ @kbd{tar -cvf afiles.tar apple angst aspic}
927 apple
928 angst
929 aspic
930 @end smallexample
931
932 @noindent
933 Creating the same archive with the verbosity level 2 could give:
934
935 @smallexample
936 $ @kbd{tar -cvvf afiles.tar apple angst aspic}
937 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
938 -rw-r--r-- gray/staff 11481 2006-06-09 12:06 angst
939 -rw-r--r-- gray/staff 23152 2006-06-09 12:06 aspic
940 @end smallexample
941
942 @noindent
943 This works equally well using short or long forms of options. Using
944 long forms, you would simply write out the mnemonic form of the option
945 twice, like this:
946
947 @smallexample
948 $ @kbd{tar --create --verbose --verbose @dots{}}
949 @end smallexample
950
951 @noindent
952 Note that you must double the hyphens properly each time.
953
954 Later in the tutorial, we will give examples using @w{@option{--verbose
955 --verbose}}.
956
957 @anchor{verbose member listing}
958 The full output consists of six fields:
959
960 @itemize @bullet
961 @item File type and permissions in symbolic form.
962 These are displayed in the same format as the first column of
963 @command{ls -l} output (@pxref{What information is listed,
964 format=verbose, Verbose listing, fileutils, GNU file utilities}).
965
966 @item Owner name and group separated by a slash character.
967 If these data are not available (for example, when listing a @samp{v7} format
968 archive), numeric @acronym{ID} values are printed instead.
969
970 @item Size of the file, in bytes.
971
972 @item File modification date in ISO 8601 format.
973
974 @item File modification time.
975
976 @item File name.
977 If the name contains any special characters (white space, newlines,
978 etc.) these are displayed in an unambiguous form using so called
979 @dfn{quoting style}. For the detailed discussion of available styles
980 and on how to use them, see @ref{quoting styles}.
981
982 Depending on the file type, the name can be followed by some
983 additional information, described in the following table:
984
985 @table @samp
986 @item -> @var{link-name}
987 The file or archive member is a @dfn{symbolic link} and
988 @var{link-name} is the name of file it links to.
989
990 @item link to @var{link-name}
991 The file or archive member is a @dfn{hard link} and @var{link-name} is
992 the name of file it links to.
993
994 @item --Long Link--
995 The archive member is an old GNU format long link. You will normally
996 not encounter this.
997
998 @item --Long Name--
999 The archive member is an old GNU format long name. You will normally
1000 not encounter this.
1001
1002 @item --Volume Header--
1003 The archive member is a GNU @dfn{volume header} (@pxref{Tape Files}).
1004
1005 @item --Continued at byte @var{n}--
1006 Encountered only at the beginning of a multi-volume archive
1007 (@pxref{Using Multiple Tapes}). This archive member is a continuation
1008 from the previous volume. The number @var{n} gives the offset where
1009 the original file was split.
1010
1011 @item unknown file type @var{c}
1012 An archive member of unknown type. @var{c} is the type character from
1013 the archive header. If you encounter such a message, it means that
1014 either your archive contains proprietary member types @GNUTAR{} is not
1015 able to handle, or the archive is corrupted.
1016 @end table
1017
1018 @end itemize
1019
1020 For example, here is an archive listing containing most of the special
1021 suffixes explained above:
1022
1023 @smallexample
1024 @group
1025 V--------- 0/0 1536 2006-06-09 13:07 MyVolume--Volume Header--
1026 -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
1027 byte 32456--
1028 -rw-r--r-- gray/staff 62373 2006-06-09 12:06 apple
1029 lrwxrwxrwx gray/staff 0 2006-06-09 13:01 angst -> apple
1030 -rw-r--r-- gray/staff 35793 2006-06-09 12:06 blues
1031 hrw-r--r-- gray/staff 0 2006-06-09 12:06 music link to blues
1032 @end group
1033 @end smallexample
1034
1035 @smallexample
1036 @end smallexample
1037
1038 @node help tutorial
1039 @unnumberedsubsec Getting Help: Using the @option{--help} Option
1040
1041 @table @option
1042 @opindex help
1043 @item --help
1044
1045 The @option{--help} option to @command{tar} prints out a very brief list of
1046 all operations and option available for the current version of
1047 @command{tar} available on your system.
1048 @end table
1049
1050 @node create
1051 @section How to Create Archives
1052 @UNREVISED
1053
1054 @cindex Creation of the archive
1055 @cindex Archive, creation of
1056 One of the basic operations of @command{tar} is @option{--create} (@option{-c}), which
1057 you use to create a @command{tar} archive. We will explain
1058 @option{--create} first because, in order to learn about the other
1059 operations, you will find it useful to have an archive available to
1060 practice on.
1061
1062 To make this easier, in this section you will first create a directory
1063 containing three files. Then, we will show you how to create an
1064 @emph{archive} (inside the new directory). Both the directory, and
1065 the archive are specifically for you to practice on. The rest of this
1066 chapter and the next chapter will show many examples using this
1067 directory and the files you will create: some of those files may be
1068 other directories and other archives.
1069
1070 The three files you will archive in this example are called
1071 @file{blues}, @file{folk}, and @file{jazz}. The archive is called
1072 @file{collection.tar}.
1073
1074 This section will proceed slowly, detailing how to use @option{--create}
1075 in @code{verbose} mode, and showing examples using both short and long
1076 forms. In the rest of the tutorial, and in the examples in the next
1077 chapter, we will proceed at a slightly quicker pace. This section
1078 moves more slowly to allow beginning users to understand how
1079 @command{tar} works.
1080
1081 @menu
1082 * prepare for examples::
1083 * Creating the archive::
1084 * create verbose::
1085 * short create::
1086 * create dir::
1087 @end menu
1088
1089 @node prepare for examples
1090 @subsection Preparing a Practice Directory for Examples
1091
1092 To follow along with this and future examples, create a new directory
1093 called @file{practice} containing files called @file{blues}, @file{folk}
1094 and @file{jazz}. The files can contain any information you like:
1095 ideally, they should contain information which relates to their names,
1096 and be of different lengths. Our examples assume that @file{practice}
1097 is a subdirectory of your home directory.
1098
1099 Now @command{cd} to the directory named @file{practice}; @file{practice}
1100 is now your @dfn{working directory}. (@emph{Please note}: Although
1101 the full file name of this directory is
1102 @file{/@var{homedir}/practice}, in our examples we will refer to
1103 this directory as @file{practice}; the @var{homedir} is presumed.)
1104
1105 In general, you should check that the files to be archived exist where
1106 you think they do (in the working directory) by running @command{ls}.
1107 Because you just created the directory and the files and have changed to
1108 that directory, you probably don't need to do that this time.
1109
1110 It is very important to make sure there isn't already a file in the
1111 working directory with the archive name you intend to use (in this case,
1112 @samp{collection.tar}), or that you don't care about its contents.
1113 Whenever you use @samp{create}, @command{tar} will erase the current
1114 contents of the file named by @option{--file=@var{archive-name}} (@option{-f @var{archive-name}}) if it exists. @command{tar}
1115 will not tell you if you are about to overwrite an archive unless you
1116 specify an option which does this (@pxref{backup}, for the
1117 information on how to do so). To add files to an existing archive,
1118 you need to use a different option, such as @option{--append} (@option{-r}); see
1119 @ref{append} for information on how to do this.
1120
1121 @node Creating the archive
1122 @subsection Creating the Archive
1123
1124 @xopindex{create, introduced}
1125 To place the files @file{blues}, @file{folk}, and @file{jazz} into an
1126 archive named @file{collection.tar}, use the following command:
1127
1128 @smallexample
1129 $ @kbd{tar --create --file=collection.tar blues folk jazz}
1130 @end smallexample
1131
1132 The order of the arguments is not very important, @emph{when using long
1133 option forms}. You could also say:
1134
1135 @smallexample
1136 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1137 @end smallexample
1138
1139 @noindent
1140 However, you can see that this order is harder to understand; this is
1141 why we will list the arguments in the order that makes the commands
1142 easiest to understand (and we encourage you to do the same when you use
1143 @command{tar}, to avoid errors).
1144
1145 Note that the sequence
1146 @option{--file=@-collection.tar} is considered to be @emph{one} argument.
1147 If you substituted any other string of characters for
1148 @kbd{collection.tar}, then that string would become the name of the
1149 archive file you create.
1150
1151 The order of the options becomes more important when you begin to use
1152 short forms. With short forms, if you type commands in the wrong order
1153 (even if you type them correctly in all other ways), you may end up with
1154 results you don't expect. For this reason, it is a good idea to get
1155 into the habit of typing options in the order that makes inherent sense.
1156 @xref{short create}, for more information on this.
1157
1158 In this example, you type the command as shown above: @option{--create}
1159 is the operation which creates the new archive
1160 (@file{collection.tar}), and @option{--file} is the option which lets
1161 you give it the name you chose. The files, @file{blues}, @file{folk},
1162 and @file{jazz}, are now members of the archive, @file{collection.tar}
1163 (they are @dfn{file name arguments} to the @option{--create} operation.
1164 @xref{Choosing}, for the detailed discussion on these.) Now that they are
1165 in the archive, they are called @emph{archive members}, not files.
1166 (@pxref{Definitions,members}).
1167
1168 When you create an archive, you @emph{must} specify which files you
1169 want placed in the archive. If you do not specify any archive
1170 members, @GNUTAR{} will complain.
1171
1172 If you now list the contents of the working directory (@command{ls}), you will
1173 find the archive file listed as well as the files you saw previously:
1174
1175 @smallexample
1176 blues folk jazz collection.tar
1177 @end smallexample
1178
1179 @noindent
1180 Creating the archive @samp{collection.tar} did not destroy the copies of
1181 the files in the directory.
1182
1183 Keep in mind that if you don't indicate an operation, @command{tar} will not
1184 run and will prompt you for one. If you don't name any files, @command{tar}
1185 will complain. You must have write access to the working directory,
1186 or else you will not be able to create an archive in that directory.
1187
1188 @emph{Caution}: Do not attempt to use @option{--create} (@option{-c}) to add files to
1189 an existing archive; it will delete the archive and write a new one.
1190 Use @option{--append} (@option{-r}) instead. @xref{append}.
1191
1192 @node create verbose
1193 @subsection Running @option{--create} with @option{--verbose}
1194
1195 @xopindex{create, using with @option{--verbose}}
1196 @xopindex{verbose, using with @option{--create}}
1197 If you include the @option{--verbose} (@option{-v}) option on the command line,
1198 @command{tar} will list the files it is acting on as it is working. In
1199 verbose mode, the @code{create} example above would appear as:
1200
1201 @smallexample
1202 $ @kbd{tar --create --verbose --file=collection.tar blues folk jazz}
1203 blues
1204 folk
1205 jazz
1206 @end smallexample
1207
1208 This example is just like the example we showed which did not use
1209 @option{--verbose}, except that @command{tar} generated the remaining
1210 @iftex
1211 lines (note the different font styles).
1212 @end iftex
1213 @ifinfo
1214 lines.
1215 @end ifinfo
1216
1217 In the rest of the examples in this chapter, we will frequently use
1218 @code{verbose} mode so we can show actions or @command{tar} responses that
1219 you would otherwise not see, and which are important for you to
1220 understand.
1221
1222 @node short create
1223 @subsection Short Forms with @samp{create}
1224
1225 As we said before, the @option{--create} (@option{-c}) operation is one of the most
1226 basic uses of @command{tar}, and you will use it countless times.
1227 Eventually, you will probably want to use abbreviated (or ``short'')
1228 forms of options. A full discussion of the three different forms that
1229 options can take appears in @ref{Styles}; for now, here is what the
1230 previous example (including the @option{--verbose} (@option{-v}) option) looks like
1231 using short option forms:
1232
1233 @smallexample
1234 $ @kbd{tar -cvf collection.tar blues folk jazz}
1235 blues
1236 folk
1237 jazz
1238 @end smallexample
1239
1240 @noindent
1241 As you can see, the system responds the same no matter whether you use
1242 long or short option forms.
1243
1244 @FIXME{i don't like how this is worded:} One difference between using
1245 short and long option forms is that, although the exact placement of
1246 arguments following options is no more specific when using short forms,
1247 it is easier to become confused and make a mistake when using short
1248 forms. For example, suppose you attempted the above example in the
1249 following way:
1250
1251 @smallexample
1252 $ @kbd{tar -cfv collection.tar blues folk jazz}
1253 @end smallexample
1254
1255 @noindent
1256 In this case, @command{tar} will make an archive file called @file{v},
1257 containing the files @file{blues}, @file{folk}, and @file{jazz}, because
1258 the @samp{v} is the closest ``file name'' to the @option{-f} option, and
1259 is thus taken to be the chosen archive file name. @command{tar} will try
1260 to add a file called @file{collection.tar} to the @file{v} archive file;
1261 if the file @file{collection.tar} did not already exist, @command{tar} will
1262 report an error indicating that this file does not exist. If the file
1263 @file{collection.tar} does already exist (e.g., from a previous command
1264 you may have run), then @command{tar} will add this file to the archive.
1265 Because the @option{-v} option did not get registered, @command{tar} will not
1266 run under @samp{verbose} mode, and will not report its progress.
1267
1268 The end result is that you may be quite confused about what happened,
1269 and possibly overwrite a file. To illustrate this further, we will show
1270 you how an example we showed previously would look using short forms.
1271
1272 This example,
1273
1274 @smallexample
1275 $ @kbd{tar blues --create folk --file=collection.tar jazz}
1276 @end smallexample
1277
1278 @noindent
1279 is confusing as it is. When shown using short forms, however, it
1280 becomes much more so:
1281
1282 @smallexample
1283 $ @kbd{tar blues -c folk -f collection.tar jazz}
1284 @end smallexample
1285
1286 @noindent
1287 It would be very easy to put the wrong string of characters
1288 immediately following the @option{-f}, but doing that could sacrifice
1289 valuable data.
1290
1291 For this reason, we recommend that you pay very careful attention to
1292 the order of options and placement of file and archive names,
1293 especially when using short option forms. Not having the option name
1294 written out mnemonically can affect how well you remember which option
1295 does what, and therefore where different names have to be placed.
1296
1297 @node create dir
1298 @subsection Archiving Directories
1299
1300 @cindex Archiving Directories
1301 @cindex Directories, Archiving
1302 You can archive a directory by specifying its directory name as a
1303 file name argument to @command{tar}. The files in the directory will be
1304 archived relative to the working directory, and the directory will be
1305 re-created along with its contents when the archive is extracted.
1306
1307 To archive a directory, first move to its superior directory. If you
1308 have followed the previous instructions in this tutorial, you should
1309 type:
1310
1311 @smallexample
1312 $ @kbd{cd ..}
1313 $
1314 @end smallexample
1315
1316 @noindent
1317 This will put you into the directory which contains @file{practice},
1318 i.e., your home directory. Once in the superior directory, you can
1319 specify the subdirectory, @file{practice}, as a file name argument. To
1320 store @file{practice} in the new archive file @file{music.tar}, type:
1321
1322 @smallexample
1323 $ @kbd{tar --create --verbose --file=music.tar practice}
1324 @end smallexample
1325
1326 @noindent
1327 @command{tar} should output:
1328
1329 @smallexample
1330 practice/
1331 practice/blues
1332 practice/folk
1333 practice/jazz
1334 practice/collection.tar
1335 @end smallexample
1336
1337 Note that the archive thus created is not in the subdirectory
1338 @file{practice}, but rather in the current working directory---the
1339 directory from which @command{tar} was invoked. Before trying to archive a
1340 directory from its superior directory, you should make sure you have
1341 write access to the superior directory itself, not only the directory
1342 you are trying archive with @command{tar}. For example, you will probably
1343 not be able to store your home directory in an archive by invoking
1344 @command{tar} from the root directory; @xref{absolute}. (Note
1345 also that @file{collection.tar}, the original archive file, has itself
1346 been archived. @command{tar} will accept any file as a file to be
1347 archived, regardless of its content. When @file{music.tar} is
1348 extracted, the archive file @file{collection.tar} will be re-written
1349 into the file system).
1350
1351 If you give @command{tar} a command such as
1352
1353 @smallexample
1354 $ @kbd{tar --create --file=foo.tar .}
1355 @end smallexample
1356
1357 @noindent
1358 @command{tar} will report @samp{tar: ./foo.tar is the archive; not
1359 dumped}. This happens because @command{tar} creates the archive
1360 @file{foo.tar} in the current directory before putting any files into
1361 it. Then, when @command{tar} attempts to add all the files in the
1362 directory @file{.} to the archive, it notices that the file
1363 @file{./foo.tar} is the same as the archive @file{foo.tar}, and skips
1364 it. (It makes no sense to put an archive into itself.) @GNUTAR{}
1365 will continue in this case, and create the archive
1366 normally, except for the exclusion of that one file. (@emph{Please
1367 note:} Other implementations of @command{tar} may not be so clever;
1368 they will enter an infinite loop when this happens, so you should not
1369 depend on this behavior unless you are certain you are running
1370 @GNUTAR{}. In general, it is wise to always place the archive outside
1371 of the directory being dumped.)
1372
1373 @node list
1374 @section How to List Archives
1375
1376 @opindex list
1377 Frequently, you will find yourself wanting to determine exactly what a
1378 particular archive contains. You can use the @option{--list}
1379 (@option{-t}) operation to get the member names as they currently
1380 appear in the archive, as well as various attributes of the files at
1381 the time they were archived. For example, you can examine the archive
1382 @file{collection.tar} that you created in the last section with the
1383 command,
1384
1385 @smallexample
1386 $ @kbd{tar --list --file=collection.tar}
1387 @end smallexample
1388
1389 @noindent
1390 The output of @command{tar} would then be:
1391
1392 @smallexample
1393 blues
1394 folk
1395 jazz
1396 @end smallexample
1397
1398 @noindent
1399 The archive @file{bfiles.tar} would list as follows:
1400
1401 @smallexample
1402 ./birds
1403 baboon
1404 ./box
1405 @end smallexample
1406
1407 @noindent
1408 Be sure to use a @option{--file=@var{archive-name}} (@option{-f
1409 @var{archive-name}}) option just as with @option{--create}
1410 (@option{-c}) to specify the name of the archive.
1411
1412 @xopindex{list, using with @option{--verbose}}
1413 @xopindex{verbose, using with @option{--list}}
1414 If you use the @option{--verbose} (@option{-v}) option with
1415 @option{--list}, then @command{tar} will print out a listing
1416 reminiscent of @w{@samp{ls -l}}, showing owner, file size, and so
1417 forth. This output is described in detail in @ref{verbose member listing}.
1418
1419 If you had used @option{--verbose} (@option{-v}) mode, the example
1420 above would look like:
1421
1422 @smallexample
1423 $ @kbd{tar --list --verbose --file=collection.tar folk}
1424 -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1425 @end smallexample
1426
1427 @cindex listing member and file names
1428 @anchor{listing member and file names}
1429 It is important to notice that the output of @kbd{tar --list
1430 --verbose} does not necessarily match that produced by @kbd{tar
1431 --create --verbose} while creating the archive. It is because
1432 @GNUTAR{}, unless told explicitly not to do so, removes some directory
1433 prefixes from file names before storing them in the archive
1434 (@xref{absolute}, for more information). In other
1435 words, in verbose mode @GNUTAR{} shows @dfn{file names} when creating
1436 an archive and @dfn{member names} when listing it. Consider this
1437 example:
1438
1439 @smallexample
1440 @group
1441 $ @kbd{tar --create --verbose --file archive /etc/mail}
1442 tar: Removing leading `/' from member names
1443 /etc/mail/
1444 /etc/mail/sendmail.cf
1445 /etc/mail/aliases
1446 $ @kbd{tar --test --file archive}
1447 etc/mail/
1448 etc/mail/sendmail.cf
1449 etc/mail/aliases
1450 @end group
1451 @end smallexample
1452
1453 @opindex show-stored-names
1454 This default behavior can sometimes be inconvenient. You can force
1455 @GNUTAR{} show member names when creating archive by supplying
1456 @option{--show-stored-names} option.
1457
1458 @table @option
1459 @item --show-stored-names
1460 Print member (as opposed to @emph{file}) names when creating the archive.
1461 @end table
1462
1463 @cindex File name arguments, using @option{--list} with
1464 @xopindex{list, using with file name arguments}
1465 You can specify one or more individual member names as arguments when
1466 using @samp{list}. In this case, @command{tar} will only list the
1467 names of members you identify. For example, @w{@kbd{tar --list
1468 --file=afiles.tar apple}} would only print @file{apple}.
1469
1470 Because @command{tar} preserves file names, these must be specified as
1471 they appear in the archive (i.e., relative to the directory from which
1472 the archive was created). Therefore, it is essential when specifying
1473 member names to @command{tar} that you give the exact member names.
1474 For example, @w{@kbd{tar --list --file=bfiles.tar birds}} would produce an
1475 error message something like @samp{tar: birds: Not found in archive},
1476 because there is no member named @file{birds}, only one named
1477 @file{./birds}. While the names @file{birds} and @file{./birds} name
1478 the same file, @emph{member} names by default are compared verbatim.
1479
1480 However, @w{@kbd{tar --list --file=bfiles.tar baboon}} would respond
1481 with @file{baboon}, because this exact member name is in the archive file
1482 @file{bfiles.tar}. If you are not sure of the exact file name,
1483 use @dfn{globbing patterns}, for example:
1484
1485 @smallexample
1486 $ @kbd{tar --list --file=bfiles.tar --wildcards '*b*'}
1487 @end smallexample
1488
1489 @noindent
1490 will list all members whose name contains @samp{b}. @xref{wildcards},
1491 for a detailed discussion of globbing patterns and related
1492 @command{tar} command line options.
1493
1494 @menu
1495 * list dir::
1496 @end menu
1497
1498 @node list dir
1499 @unnumberedsubsec Listing the Contents of a Stored Directory
1500
1501 To get information about the contents of an archived directory,
1502 use the directory name as a file name argument in conjunction with
1503 @option{--list} (@option{-t}). To find out file attributes, include the
1504 @option{--verbose} (@option{-v}) option.
1505
1506 For example, to find out about files in the directory @file{practice}, in
1507 the archive file @file{music.tar}, type:
1508
1509 @smallexample
1510 $ @kbd{tar --list --verbose --file=music.tar practice}
1511 @end smallexample
1512
1513 @command{tar} responds:
1514
1515 @smallexample
1516 drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1517 -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1518 -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1519 -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1520 -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1521 @end smallexample
1522
1523 When you use a directory name as a file name argument, @command{tar} acts on
1524 all the files (including sub-directories) in that directory.
1525
1526 @node extract
1527 @section How to Extract Members from an Archive
1528 @cindex Extraction
1529 @cindex Retrieving files from an archive
1530 @cindex Resurrecting files from an archive
1531
1532 @opindex extract
1533 Creating an archive is only half the job---there is no point in storing
1534 files in an archive if you can't retrieve them. The act of retrieving
1535 members from an archive so they can be used and manipulated as
1536 unarchived files again is called @dfn{extraction}. To extract files
1537 from an archive, use the @option{--extract} (@option{--get} or
1538 @option{-x}) operation. As with @option{--create}, specify the name
1539 of the archive with @option{--file} (@option{-f}) option. Extracting
1540 an archive does not modify the archive in any way; you can extract it
1541 multiple times if you want or need to.
1542
1543 Using @option{--extract}, you can extract an entire archive, or specific
1544 files. The files can be directories containing other files, or not. As
1545 with @option{--create} (@option{-c}) and @option{--list} (@option{-t}), you may use the short or the
1546 long form of the operation without affecting the performance.
1547
1548 @menu
1549 * extracting archives::
1550 * extracting files::
1551 * extract dir::
1552 * extracting untrusted archives::
1553 * failing commands::
1554 @end menu
1555
1556 @node extracting archives
1557 @subsection Extracting an Entire Archive
1558
1559 To extract an entire archive, specify the archive file name only, with
1560 no individual file names as arguments. For example,
1561
1562 @smallexample
1563 $ @kbd{tar -xvf collection.tar}
1564 @end smallexample
1565
1566 @noindent
1567 produces this:
1568
1569 @smallexample
1570 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
1571 -rw-r--r-- me user 21 1996-09-23 16:44 blues
1572 -rw-r--r-- me user 20 1996-09-23 16:44 folk
1573 @end smallexample
1574
1575 @node extracting files
1576 @subsection Extracting Specific Files
1577
1578 To extract specific archive members, give their exact member names as
1579 arguments, as printed by @option{--list} (@option{-t}). If you had
1580 mistakenly deleted one of the files you had placed in the archive
1581 @file{collection.tar} earlier (say, @file{blues}), you can extract it
1582 from the archive without changing the archive's structure. Its
1583 contents will be identical to the original file @file{blues} that you
1584 deleted.
1585
1586 First, make sure you are in the @file{practice} directory, and list the
1587 files in the directory. Now, delete the file, @samp{blues}, and list
1588 the files in the directory again.
1589
1590 You can now extract the member @file{blues} from the archive file
1591 @file{collection.tar} like this:
1592
1593 @smallexample
1594 $ @kbd{tar --extract --file=collection.tar blues}
1595 @end smallexample
1596
1597 @noindent
1598 If you list the files in the directory again, you will see that the file
1599 @file{blues} has been restored, with its original permissions, data
1600 modification times, and owner.@footnote{This is only accidentally
1601 true, but not in general. Whereas modification times are always
1602 restored, in most cases, one has to be root for restoring the owner,
1603 and use a special option for restoring permissions. Here, it just
1604 happens that the restoring user is also the owner of the archived
1605 members, and that the current @code{umask} is compatible with original
1606 permissions.} (These parameters will be identical to those which
1607 the file had when you originally placed it in the archive; any changes
1608 you may have made before deleting the file from the file system,
1609 however, will @emph{not} have been made to the archive member.) The
1610 archive file, @samp{collection.tar}, is the same as it was before you
1611 extracted @samp{blues}. You can confirm this by running @command{tar} with
1612 @option{--list} (@option{-t}).
1613
1614 Remember that as with other operations, specifying the exact member
1615 name is important. @w{@kbd{tar --extract --file=bfiles.tar birds}}
1616 will fail, because there is no member named @file{birds}. To extract
1617 the member named @file{./birds}, you must specify @w{@kbd{tar
1618 --extract --file=bfiles.tar ./birds}}. If you don't remember the
1619 exact member names, use @option{--list} (@option{-t}) option
1620 (@pxref{list}). You can also extract those members that match a
1621 specific @dfn{globbing pattern}. For example, to extract from
1622 @file{bfiles.tar} all files that begin with @samp{b}, no matter their
1623 directory prefix, you could type:
1624
1625 @smallexample
1626 $ @kbd{tar -x -f bfiles.tar --wildcards --no-anchored 'b*'}
1627 @end smallexample
1628
1629 @noindent
1630 Here, @option{--wildcards} instructs @command{tar} to treat
1631 command line arguments as globbing patterns and @option{--no-anchored}
1632 informs it that the patterns apply to member names after any @samp{/}
1633 delimiter. The use of globbing patterns is discussed in detail in
1634 @xref{wildcards}.
1635
1636 You can extract a file to standard output by combining the above options
1637 with the @option{--to-stdout} (@option{-O}) option (@pxref{Writing to Standard
1638 Output}).
1639
1640 If you give the @option{--verbose} option, then @option{--extract}
1641 will print the names of the archive members as it extracts them.
1642
1643 @node extract dir
1644 @subsection Extracting Files that are Directories
1645
1646 Extracting directories which are members of an archive is similar to
1647 extracting other files. The main difference to be aware of is that if
1648 the extracted directory has the same name as any directory already in
1649 the working directory, then files in the extracted directory will be
1650 placed into the directory of the same name. Likewise, if there are
1651 files in the pre-existing directory with the same names as the members
1652 which you extract, the files from the extracted archive will replace
1653 the files already in the working directory (and possible
1654 subdirectories). This will happen regardless of whether or not the
1655 files in the working directory were more recent than those extracted
1656 (there exist, however, special options that alter this behavior
1657 @pxref{Writing}).
1658
1659 However, if a file was stored with a directory name as part of its file
1660 name, and that directory does not exist under the working directory when
1661 the file is extracted, @command{tar} will create the directory.
1662
1663 We can demonstrate how to use @option{--extract} to extract a directory
1664 file with an example. Change to the @file{practice} directory if you
1665 weren't there, and remove the files @file{folk} and @file{jazz}. Then,
1666 go back to the parent directory and extract the archive
1667 @file{music.tar}. You may either extract the entire archive, or you may
1668 extract only the files you just deleted. To extract the entire archive,
1669 don't give any file names as arguments after the archive name
1670 @file{music.tar}. To extract only the files you deleted, use the
1671 following command:
1672
1673 @smallexample
1674 $ @kbd{tar -xvf music.tar practice/folk practice/jazz}
1675 practice/folk
1676 practice/jazz
1677 @end smallexample
1678
1679 @noindent
1680 If you were to specify two @option{--verbose} (@option{-v}) options, @command{tar}
1681 would have displayed more detail about the extracted files, as shown
1682 in the example below:
1683
1684 @smallexample
1685 $ @kbd{tar -xvvf music.tar practice/folk practice/jazz}
1686 -rw-r--r-- me user 28 1996-10-18 16:31 practice/jazz
1687 -rw-r--r-- me user 20 1996-09-23 16:44 practice/folk
1688 @end smallexample
1689
1690 @noindent
1691 Because you created the directory with @file{practice} as part of the
1692 file names of each of the files by archiving the @file{practice}
1693 directory as @file{practice}, you must give @file{practice} as part
1694 of the file names when you extract those files from the archive.
1695
1696 @node extracting untrusted archives
1697 @subsection Extracting Archives from Untrusted Sources
1698
1699 Extracting files from archives can overwrite files that already exist.
1700 If you receive an archive from an untrusted source, you should make a
1701 new directory and extract into that directory, so that you don't have
1702 to worry about the extraction overwriting one of your existing files.
1703 For example, if @file{untrusted.tar} came from somewhere else on the
1704 Internet, and you don't necessarily trust its contents, you can
1705 extract it as follows:
1706
1707 @smallexample
1708 $ @kbd{mkdir newdir}
1709 $ @kbd{cd newdir}
1710 $ @kbd{tar -xvf ../untrusted.tar}
1711 @end smallexample
1712
1713 It is also a good practice to examine contents of the archive
1714 before extracting it, using @option{--list} (@option{-t}) option, possibly combined
1715 with @option{--verbose} (@option{-v}).
1716
1717 @node failing commands
1718 @subsection Commands That Will Fail
1719
1720 Here are some sample commands you might try which will not work, and why
1721 they won't work.
1722
1723 If you try to use this command,
1724
1725 @smallexample
1726 $ @kbd{tar -xvf music.tar folk jazz}
1727 @end smallexample
1728
1729 @noindent
1730 you will get the following response:
1731
1732 @smallexample
1733 tar: folk: Not found in archive
1734 tar: jazz: Not found in archive
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/blues
1745 practice/folk
1746 practice/jazz
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 @UNREVISED
1772
1773 @FIXME{need to write up a node here about the things that are going to
1774 be in the rest of the manual.}
1775
1776 @node tar invocation
1777 @chapter Invoking @GNUTAR{}
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 * checkpoints::
1810 * warnings::
1811 * interactive::
1812 @end menu
1813
1814 @node Synopsis
1815 @section General Synopsis of @command{tar}
1816
1817 The @GNUTAR{} program is invoked as either one of:
1818
1819 @smallexample
1820 @kbd{tar @var{option}@dots{} [@var{name}]@dots{}}
1821 @kbd{tar @var{letter}@dots{} [@var{argument}]@dots{} [@var{option}]@dots{} [@var{name}]@dots{}}
1822 @end smallexample
1823
1824 The second form is for when old options are being used.
1825
1826 You can use @command{tar} to store files in an archive, to extract them from
1827 an archive, and to do other types of archive manipulation. The primary
1828 argument to @command{tar}, which is called the @dfn{operation}, specifies
1829 which action to take. The other arguments to @command{tar} are either
1830 @dfn{options}, which change the way @command{tar} performs an operation,
1831 or file names or archive members, which specify the files or members
1832 @command{tar} is to act on.
1833
1834 You can actually type in arguments in any order, even if in this manual
1835 the options always precede the other arguments, to make examples easier
1836 to understand. Further, the option stating the main operation mode
1837 (the @command{tar} main command) is usually given first.
1838
1839 Each @var{name} in the synopsis above is interpreted as an archive member
1840 name when the main command is one of @option{--compare}
1841 (@option{--diff}, @option{-d}), @option{--delete}, @option{--extract}
1842 (@option{--get}, @option{-x}), @option{--list} (@option{-t}) or
1843 @option{--update} (@option{-u}). When naming archive members, you
1844 must give the exact name of the member in the archive, as it is
1845 printed by @option{--list}. For @option{--append} (@option{-r}) and
1846 @option{--create} (@option{-c}), these @var{name} arguments specify
1847 the names of either files or directory hierarchies to place in the archive.
1848 These files or hierarchies should already exist in the file system,
1849 prior to the execution of the @command{tar} command.
1850
1851 @command{tar} interprets relative file names as being relative to the
1852 working directory. @command{tar} will make all file names relative
1853 (by removing leading slashes when archiving or restoring files),
1854 unless you specify otherwise (using the @option{--absolute-names}
1855 option). @xref{absolute}, for more information about
1856 @option{--absolute-names}.
1857
1858 If you give the name of a directory as either a file name or a member
1859 name, then @command{tar} acts recursively on all the files and directories
1860 beneath that directory. For example, the name @file{/} identifies all
1861 the files in the file system to @command{tar}.
1862
1863 The distinction between file names and archive member names is especially
1864 important when shell globbing is used, and sometimes a source of confusion
1865 for newcomers. @xref{wildcards}, for more information about globbing.
1866 The problem is that shells may only glob using existing files in the
1867 file system. Only @command{tar} itself may glob on archive members, so when
1868 needed, you must ensure that wildcard characters reach @command{tar} without
1869 being interpreted by the shell first. Using a backslash before @samp{*}
1870 or @samp{?}, or putting the whole argument between quotes, is usually
1871 sufficient for this.
1872
1873 Even if @var{name}s are often specified on the command line, they
1874 can also be read from a text file in the file system, using the
1875 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}}) option.
1876
1877 If you don't use any file name arguments, @option{--append} (@option{-r}),
1878 @option{--delete} and @option{--concatenate} (@option{--catenate},
1879 @option{-A}) will do nothing, while @option{--create} (@option{-c})
1880 will usually yield a diagnostic and inhibit @command{tar} execution.
1881 The other operations of @command{tar} (@option{--list},
1882 @option{--extract}, @option{--compare}, and @option{--update})
1883 will act on the entire contents of the archive.
1884
1885 @cindex exit status
1886 @cindex return status
1887 Besides successful exits, @GNUTAR{} may fail for
1888 many reasons. Some reasons correspond to bad usage, that is, when the
1889 @command{tar} command line is improperly written. Errors may be
1890 encountered later, while processing the archive or the files. Some
1891 errors are recoverable, in which case the failure is delayed until
1892 @command{tar} has completed all its work. Some errors are such that
1893 it would be not meaningful, or at least risky, to continue processing:
1894 @command{tar} then aborts processing immediately. All abnormal exits,
1895 whether immediate or delayed, should always be clearly diagnosed on
1896 @code{stderr}, after a line stating the nature of the error.
1897
1898 Possible exit codes of @GNUTAR{} are summarized in the following
1899 table:
1900
1901 @table @asis
1902 @item 0
1903 @samp{Successful termination}.
1904
1905 @item 1
1906 @samp{Some files differ}. If tar was invoked with @option{--compare}
1907 (@option{--diff}, @option{-d}) command line option, this means that
1908 some files in the archive differ from their disk counterparts
1909 (@pxref{compare}). If tar was given @option{--create},
1910 @option{--append} or @option{--update} option, this exit code means
1911 that some files were changed while being archived and so the resulting
1912 archive does not contain the exact copy of the file set.
1913
1914 @item 2
1915 @samp{Fatal error}. This means that some fatal, unrecoverable error
1916 occurred.
1917 @end table
1918
1919 If @command{tar} has invoked a subprocess and that subprocess exited with a
1920 nonzero exit code, @command{tar} exits with that code as well.
1921 This can happen, for example, if @command{tar} was given some
1922 compression option (@pxref{gzip}) and the external compressor program
1923 failed. Another example is @command{rmt} failure during backup to the
1924 remote device (@pxref{Remote Tape Server}).
1925
1926 @node using tar options
1927 @section Using @command{tar} Options
1928
1929 @GNUTAR{} has a total of eight operating modes which
1930 allow you to perform a variety of tasks. You are required to choose
1931 one operating mode each time you employ the @command{tar} program by
1932 specifying one, and only one operation as an argument to the
1933 @command{tar} command (the corresponding options may be found
1934 at @ref{frequent operations} and @ref{Operations}). Depending on
1935 circumstances, you may also wish to customize how the chosen operating
1936 mode behaves. For example, you may wish to change the way the output
1937 looks, or the format of the files that you wish to archive may require
1938 you to do something special in order to make the archive look right.
1939
1940 You can customize and control @command{tar}'s performance by running
1941 @command{tar} with one or more options (such as @option{--verbose}
1942 (@option{-v}), which we used in the tutorial). As we said in the
1943 tutorial, @dfn{options} are arguments to @command{tar} which are (as
1944 their name suggests) optional. Depending on the operating mode, you
1945 may specify one or more options. Different options will have different
1946 effects, but in general they all change details of the operation, such
1947 as archive format, archive name, or level of user interaction. Some
1948 options make sense with all operating modes, while others are
1949 meaningful only with particular modes. You will likely use some
1950 options frequently, while you will only use others infrequently, or
1951 not at all. (A full list of options is available in @pxref{All Options}.)
1952
1953 @vrindex TAR_OPTIONS, environment variable
1954 @anchor{TAR_OPTIONS}
1955 The @env{TAR_OPTIONS} environment variable specifies default options to
1956 be placed in front of any explicit options. For example, if
1957 @code{TAR_OPTIONS} is @samp{-v --unlink-first}, @command{tar} behaves as
1958 if the two options @option{-v} and @option{--unlink-first} had been
1959 specified before any explicit options. Option specifications are
1960 separated by whitespace. A backslash escapes the next character, so it
1961 can be used to specify an option containing whitespace or a backslash.
1962
1963 Note that @command{tar} options are case sensitive. For example, the
1964 options @option{-T} and @option{-t} are different; the first requires an
1965 argument for stating the name of a file providing a list of @var{name}s,
1966 while the second does not require an argument and is another way to
1967 write @option{--list} (@option{-t}).
1968
1969 In addition to the eight operations, there are many options to
1970 @command{tar}, and three different styles for writing both: long (mnemonic)
1971 form, short form, and old style. These styles are discussed below.
1972 Both the options and the operations can be written in any of these three
1973 styles.
1974
1975 @FIXME{menu at end of this node. need to think of an actual outline
1976 for this chapter; probably do that after stuff from chapter 4 is
1977 incorporated.}
1978
1979 @node Styles
1980 @section The Three Option Styles
1981
1982 There are three styles for writing operations and options to the command
1983 line invoking @command{tar}. The different styles were developed at
1984 different times during the history of @command{tar}. These styles will be
1985 presented below, from the most recent to the oldest.
1986
1987 Some options must take an argument@footnote{For example, @option{--file}
1988 (@option{-f}) takes the name of an archive file as an argument. If
1989 you do not supply an archive file name, @command{tar} will use a
1990 default, but this can be confusing; thus, we recommend that you always
1991 supply a specific archive file name.}. Where you @emph{place} the
1992 arguments generally depends on which style of options you choose. We
1993 will detail specific information relevant to each option style in the
1994 sections on the different option styles, below. The differences are
1995 subtle, yet can often be very important; incorrect option placement
1996 can cause you to overwrite a number of important files. We urge you
1997 to note these differences, and only use the option style(s) which
1998 makes the most sense to you until you feel comfortable with the others.
1999
2000 Some options @emph{may} take an argument. Such options may have at
2001 most long and short forms, they do not have old style equivalent. The
2002 rules for specifying an argument for such options are stricter than
2003 those for specifying mandatory arguments. Please, pay special
2004 attention to them.
2005
2006 @menu
2007 * Long Options:: Long Option Style
2008 * Short Options:: Short Option Style
2009 * Old Options:: Old Option Style
2010 * Mixing:: Mixing Option Styles
2011 @end menu
2012
2013 @node Long Options
2014 @subsection Long Option Style
2015
2016 @cindex long options
2017 @cindex options, long style
2018 @cindex options, GNU style
2019 @cindex options, mnemonic names
2020 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
2021 dashes in a row, e.g., @option{--list}. The long names are more clear than
2022 their corresponding short or old names. It sometimes happens that a
2023 single long option has many different names which are
2024 synonymous, such as @option{--compare} and @option{--diff}. In addition,
2025 long option names can be given unique abbreviations. For example,
2026 @option{--cre} can be used in place of @option{--create} because there is no
2027 other long option which begins with @samp{cre}. (One way to find
2028 this out is by trying it and seeing what happens; if a particular
2029 abbreviation could represent more than one option, @command{tar} will tell
2030 you that that abbreviation is ambiguous and you'll know that that
2031 abbreviation won't work. You may also choose to run @samp{tar --help}
2032 to see a list of options. Be aware that if you run @command{tar} with a
2033 unique abbreviation for the long name of an option you didn't want to
2034 use, you are stuck; @command{tar} will perform the command as ordered.)
2035
2036 Long options are meant to be obvious and easy to remember, and their
2037 meanings are generally easier to discern than those of their
2038 corresponding short options (see below). For example:
2039
2040 @smallexample
2041 $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
2042 @end smallexample
2043
2044 @noindent
2045 gives a fairly good set of hints about what the command does, even
2046 for those not fully acquainted with @command{tar}.
2047
2048 @cindex arguments to long options
2049 @cindex long options with mandatory arguments
2050 Long options which require arguments take those arguments
2051 immediately following the option name. There are two ways of
2052 specifying a mandatory argument. It can be separated from the
2053 option name either by an equal sign, or by any amount of
2054 white space characters. For example, the @option{--file} option (which
2055 tells the name of the @command{tar} archive) is given a file such as
2056 @file{archive.tar} as argument by using any of the following notations:
2057 @option{--file=archive.tar} or @option{--file archive.tar}.
2058
2059 @cindex optional arguments to long options
2060 @cindex long options with optional arguments
2061 In contrast, optional arguments must always be introduced using
2062 an equal sign. For example, the @option{--backup} option takes
2063 an optional argument specifying backup type. It must be used
2064 as @option{--backup=@var{backup-type}}.
2065
2066 @node Short Options
2067 @subsection Short Option Style
2068
2069 @cindex short options
2070 @cindex options, short style
2071 @cindex options, traditional
2072 Most options also have a @dfn{short option} name. Short options start with
2073 a single dash, and are followed by a single character, e.g., @option{-t}
2074 (which is equivalent to @option{--list}). The forms are absolutely
2075 identical in function; they are interchangeable.
2076
2077 The short option names are faster to type than long option names.
2078
2079 @cindex arguments to short options
2080 @cindex short options with mandatory arguments
2081 Short options which require arguments take their arguments immediately
2082 following the option, usually separated by white space. It is also
2083 possible to stick the argument right after the short option name, using
2084 no intervening space. For example, you might write @w{@option{-f
2085 archive.tar}} or @option{-farchive.tar} instead of using
2086 @option{--file=archive.tar}. Both @option{--file=@var{archive-name}} and
2087 @w{@option{-f @var{archive-name}}} denote the option which indicates a
2088 specific archive, here named @file{archive.tar}.
2089
2090 @cindex optional arguments to short options
2091 @cindex short options with optional arguments
2092 Short options which take optional arguments take their arguments
2093 immediately following the option letter, @emph{without any intervening
2094 white space characters}.
2095
2096 Short options' letters may be clumped together, but you are not
2097 required to do this (as compared to old options; see below). When
2098 short options are clumped as a set, use one (single) dash for them
2099 all, e.g., @w{@samp{@command{tar} -cvf}}. Only the last option in
2100 such a set is allowed to have an argument@footnote{Clustering many
2101 options, the last of which has an argument, is a rather opaque way to
2102 write options. Some wonder if @acronym{GNU} @code{getopt} should not
2103 even be made helpful enough for considering such usages as invalid.}.
2104
2105 When the options are separated, the argument for each option which requires
2106 an argument directly follows that option, as is usual for Unix programs.
2107 For example:
2108
2109 @smallexample
2110 $ @kbd{tar -c -v -b 20 -f /dev/rmt0}
2111 @end smallexample
2112
2113 If you reorder short options' locations, be sure to move any arguments
2114 that belong to them. If you do not move the arguments properly, you may
2115 end up overwriting files.
2116
2117 @node Old Options
2118 @subsection Old Option Style
2119 @cindex options, old style
2120 @cindex old option style
2121
2122 Like short options, @dfn{old options} are single letters. However, old options
2123 must be written together as a single clumped set, without spaces separating
2124 them or dashes preceding them@footnote{Beware that if you precede options
2125 with a dash, you are announcing the short option style instead of the
2126 old option style; short options are decoded differently.}. This set
2127 of letters must be the first to appear on the command line, after the
2128 @command{tar} program name and some white space; old options cannot appear
2129 anywhere else. The letter of an old option is exactly the same letter as
2130 the corresponding short option. For example, the old option @samp{t} is
2131 the same as the short option @option{-t}, and consequently, the same as the
2132 long option @option{--list}. So for example, the command @w{@samp{tar
2133 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
2134
2135 @cindex arguments to old options
2136 @cindex old options with mandatory arguments
2137 When options that need arguments are given together with the command,
2138 all the associated arguments follow, in the same order as the options.
2139 Thus, the example given previously could also be written in the old
2140 style as follows:
2141
2142 @smallexample
2143 $ @kbd{tar cvbf 20 /dev/rmt0}
2144 @end smallexample
2145
2146 @noindent
2147 Here, @samp{20} is the argument of @option{-b} and @samp{/dev/rmt0} is
2148 the argument of @option{-f}.
2149
2150 On the other hand, this old style syntax makes it difficult to match
2151 option letters with their corresponding arguments, and is often
2152 confusing. In the command @w{@samp{tar cvbf 20 /dev/rmt0}}, for example,
2153 @samp{20} is the argument for @option{-b}, @samp{/dev/rmt0} is the
2154 argument for @option{-f}, and @option{-v} does not have a corresponding
2155 argument. Even using short options like in @w{@samp{tar -c -v -b 20 -f
2156 /dev/rmt0}} is clearer, putting all arguments next to the option they
2157 pertain to.
2158
2159 If you want to reorder the letters in the old option argument, be
2160 sure to reorder any corresponding argument appropriately.
2161
2162 This old way of writing @command{tar} options can surprise even experienced
2163 users. For example, the two commands:
2164
2165 @smallexample
2166 @kbd{tar cfz archive.tar.gz file}
2167 @kbd{tar -cfz archive.tar.gz file}
2168 @end smallexample
2169
2170 @noindent
2171 are quite different. The first example uses @file{archive.tar.gz} as
2172 the value for option @samp{f} and recognizes the option @samp{z}. The
2173 second example, however, uses @file{z} as the value for option
2174 @samp{f} --- probably not what was intended.
2175
2176 Old options are kept for compatibility with old versions of @command{tar}.
2177
2178 This second example could be corrected in many ways, among which the
2179 following are equivalent:
2180
2181 @smallexample
2182 @kbd{tar -czf archive.tar.gz file}
2183 @kbd{tar -cf archive.tar.gz -z file}
2184 @kbd{tar cf archive.tar.gz -z file}
2185 @end smallexample
2186
2187 @cindex option syntax, traditional
2188 As far as we know, all @command{tar} programs, @acronym{GNU} and
2189 non-@acronym{GNU}, support old options. @GNUTAR{}
2190 supports them not only for historical reasons, but also because many
2191 people are used to them. For compatibility with Unix @command{tar},
2192 the first argument is always treated as containing command and option
2193 letters even if it doesn't start with @samp{-}. Thus, @samp{tar c} is
2194 equivalent to @w{@samp{tar -c}:} both of them specify the
2195 @option{--create} (@option{-c}) command to create an archive.
2196
2197 @node Mixing
2198 @subsection Mixing Option Styles
2199
2200 @cindex options, mixing different styles
2201 All three styles may be intermixed in a single @command{tar} command,
2202 so long as the rules for each style are fully
2203 respected@footnote{Before @GNUTAR{} version 1.11.6,
2204 a bug prevented intermixing old style options with long options in
2205 some cases.}. Old style options and either of the modern styles of
2206 options may be mixed within a single @command{tar} command. However,
2207 old style options must be introduced as the first arguments only,
2208 following the rule for old options (old options must appear directly
2209 after the @command{tar} command and some white space). Modern options
2210 may be given only after all arguments to the old options have been
2211 collected. If this rule is not respected, a modern option might be
2212 falsely interpreted as the value of the argument to one of the old
2213 style options.
2214
2215 For example, all the following commands are wholly equivalent, and
2216 illustrate the many combinations and orderings of option styles.
2217
2218 @smallexample
2219 @kbd{tar --create --file=archive.tar}
2220 @kbd{tar --create -f archive.tar}
2221 @kbd{tar --create -farchive.tar}
2222 @kbd{tar --file=archive.tar --create}
2223 @kbd{tar --file=archive.tar -c}
2224 @kbd{tar -c --file=archive.tar}
2225 @kbd{tar -c -f archive.tar}
2226 @kbd{tar -c -farchive.tar}
2227 @kbd{tar -cf archive.tar}
2228 @kbd{tar -cfarchive.tar}
2229 @kbd{tar -f archive.tar --create}
2230 @kbd{tar -f archive.tar -c}
2231 @kbd{tar -farchive.tar --create}
2232 @kbd{tar -farchive.tar -c}
2233 @kbd{tar c --file=archive.tar}
2234 @kbd{tar c -f archive.tar}
2235 @kbd{tar c -farchive.tar}
2236 @kbd{tar cf archive.tar}
2237 @kbd{tar f archive.tar --create}
2238 @kbd{tar f archive.tar -c}
2239 @kbd{tar fc archive.tar}
2240 @end smallexample
2241
2242 On the other hand, the following commands are @emph{not} equivalent to
2243 the previous set:
2244
2245 @smallexample
2246 @kbd{tar -f -c archive.tar}
2247 @kbd{tar -fc archive.tar}
2248 @kbd{tar -fcarchive.tar}
2249 @kbd{tar -farchive.tarc}
2250 @kbd{tar cfarchive.tar}
2251 @end smallexample
2252
2253 @noindent
2254 These last examples mean something completely different from what the
2255 user intended (judging based on the example in the previous set which
2256 uses long options, whose intent is therefore very clear). The first
2257 four specify that the @command{tar} archive would be a file named
2258 @option{-c}, @samp{c}, @samp{carchive.tar} or @samp{archive.tarc},
2259 respectively. The first two examples also specify a single non-option,
2260 @var{name} argument having the value @samp{archive.tar}. The last
2261 example contains only old style option letters (repeating option
2262 @samp{c} twice), not all of which are meaningful (eg., @samp{.},
2263 @samp{h}, or @samp{i}), with no argument value. @FIXME{not sure i liked
2264 the first sentence of this paragraph..}
2265
2266 @node All Options
2267 @section All @command{tar} Options
2268
2269 The coming manual sections contain an alphabetical listing of all
2270 @command{tar} operations and options, with brief descriptions and
2271 cross-references to more in-depth explanations in the body of the manual.
2272 They also contain an alphabetically arranged table of the short option
2273 forms with their corresponding long option. You can use this table as
2274 a reference for deciphering @command{tar} commands in scripts.
2275
2276 @menu
2277 * Operation Summary::
2278 * Option Summary::
2279 * Short Option Summary::
2280 @end menu
2281
2282 @node Operation Summary
2283 @subsection Operations
2284
2285 @table @option
2286
2287 @opsummary{append}
2288 @item --append
2289 @itemx -r
2290
2291 Appends files to the end of the archive. @xref{append}.
2292
2293 @opsummary{catenate}
2294 @item --catenate
2295 @itemx -A
2296
2297 Same as @option{--concatenate}. @xref{concatenate}.
2298
2299 @opsummary{compare}
2300 @item --compare
2301 @itemx -d
2302
2303 Compares archive members with their counterparts in the file
2304 system, and reports differences in file size, mode, owner,
2305 modification date and contents. @xref{compare}.
2306
2307 @opsummary{concatenate}
2308 @item --concatenate
2309 @itemx -A
2310
2311 Appends other @command{tar} archives to the end of the archive.
2312 @xref{concatenate}.
2313
2314 @opsummary{create}
2315 @item --create
2316 @itemx -c
2317
2318 Creates a new @command{tar} archive. @xref{create}.
2319
2320 @opsummary{delete}
2321 @item --delete
2322
2323 Deletes members from the archive. Don't try this on an archive on a
2324 tape! @xref{delete}.
2325
2326 @opsummary{diff}
2327 @item --diff
2328 @itemx -d
2329
2330 Same @option{--compare}. @xref{compare}.
2331
2332 @opsummary{extract}
2333 @item --extract
2334 @itemx -x
2335
2336 Extracts members from the archive into the file system. @xref{extract}.
2337
2338 @opsummary{get}
2339 @item --get
2340 @itemx -x
2341
2342 Same as @option{--extract}. @xref{extract}.
2343
2344 @opsummary{list}
2345 @item --list
2346 @itemx -t
2347
2348 Lists the members in an archive. @xref{list}.
2349
2350 @opsummary{update}
2351 @item --update
2352 @itemx -u
2353
2354 Adds files to the end of the archive, but only if they are newer than
2355 their counterparts already in the archive, or if they do not already
2356 exist in the archive. @xref{update}.
2357
2358 @end table
2359
2360 @node Option Summary
2361 @subsection @command{tar} Options
2362
2363 @table @option
2364
2365 @opsummary{absolute-names}
2366 @item --absolute-names
2367 @itemx -P
2368
2369 Normally when creating an archive, @command{tar} strips an initial
2370 @samp{/} from member names. This option disables that behavior.
2371 @xref{absolute}.
2372
2373 @opsummary{after-date}
2374 @item --after-date
2375
2376 (See @option{--newer}, @pxref{after})
2377
2378 @opsummary{anchored}
2379 @item --anchored
2380 A pattern must match an initial subsequence of the name's components.
2381 @xref{controlling pattern-matching}.
2382
2383 @opsummary{atime-preserve}
2384 @item --atime-preserve
2385 @itemx --atime-preserve=replace
2386 @itemx --atime-preserve=system
2387
2388 Attempt to preserve the access time of files when reading them. This
2389 option currently is effective only on files that you own, unless you
2390 have superuser privileges.
2391
2392 @option{--atime-preserve=replace} remembers the access time of a file
2393 before reading it, and then restores the access time afterwards. This
2394 may cause problems if other programs are reading the file at the same
2395 time, as the times of their accesses will be lost. On most platforms
2396 restoring the access time also requires @command{tar} to restore the
2397 data modification time too, so this option may also cause problems if
2398 other programs are writing the file at the same time (@command{tar} attempts
2399 to detect this situation, but cannot do so reliably due to race
2400 conditions). Worse, on most platforms restoring the access time also
2401 updates the status change time, which means that this option is
2402 incompatible with incremental backups.
2403
2404 @option{--atime-preserve=system} avoids changing time stamps on files,
2405 without interfering with time stamp updates
2406 caused by other programs, so it works better with incremental backups.
2407 However, it requires a special @code{O_NOATIME} option from the
2408 underlying operating and file system implementation, and it also requires
2409 that searching directories does not update their access times. As of
2410 this writing (November 2005) this works only with Linux, and only with
2411 Linux kernels 2.6.8 and later. Worse, there is currently no reliable
2412 way to know whether this feature actually works. Sometimes
2413 @command{tar} knows that it does not work, and if you use
2414 @option{--atime-preserve=system} then @command{tar} complains and
2415 exits right away. But other times @command{tar} might think that the
2416 option works when it actually does not.
2417
2418 Currently @option{--atime-preserve} with no operand defaults to
2419 @option{--atime-preserve=replace}, but this may change in the future
2420 as support for @option{--atime-preserve=system} improves.
2421
2422 If your operating or file system does not support
2423 @option{--atime-preserve=@-system}, you might be able to preserve access
2424 times reliably by using the @command{mount} command. For example,
2425 you can mount the file system read-only, or access the file system via
2426 a read-only loopback mount, or use the @samp{noatime} mount option
2427 available on some systems. However, mounting typically requires
2428 superuser privileges and can be a pain to manage.
2429
2430 @opsummary{auto-compress}
2431 @item --auto-compress
2432 @itemx -a
2433
2434 During a @option{--create} operation, enables automatic compressed
2435 format recognition based on the archive suffix. The effect of this
2436 option is cancelled by @option{--no-auto-compress}. @xref{gzip}.
2437
2438 @opsummary{backup}
2439 @item --backup=@var{backup-type}
2440
2441 Rather than deleting files from the file system, @command{tar} will
2442 back them up using simple or numbered backups, depending upon
2443 @var{backup-type}. @xref{backup}.
2444
2445 @opsummary{block-number}
2446 @item --block-number
2447 @itemx -R
2448
2449 With this option present, @command{tar} prints error messages for read errors
2450 with the block number in the archive file. @xref{block-number}.
2451
2452 @opsummary{blocking-factor}
2453 @item --blocking-factor=@var{blocking}
2454 @itemx -b @var{blocking}
2455
2456 Sets the blocking factor @command{tar} uses to @var{blocking} x 512 bytes per
2457 record. @xref{Blocking Factor}.
2458
2459 @opsummary{bzip2}
2460 @item --bzip2
2461 @itemx -j
2462
2463 This option tells @command{tar} to read or write archives through
2464 @code{bzip2}. @xref{gzip}.
2465
2466 @opsummary{check-device}
2467 @item --check-device
2468 Check device numbers when creating a list of modified files for
2469 incremental archiving. This is the default. @xref{device numbers},
2470 for a detailed description.
2471
2472 @opsummary{checkpoint}
2473 @item --checkpoint[=@var{number}]
2474
2475 This option directs @command{tar} to print periodic checkpoint
2476 messages as it reads through the archive. It is intended for when you
2477 want a visual indication that @command{tar} is still running, but
2478 don't want to see @option{--verbose} output. You can also instruct
2479 @command{tar} to execute a list of actions on each checkpoint, see
2480 @option{--checkpoint-action} below. For a detailed description, see
2481 @ref{checkpoints}.
2482
2483 @opsummary{checkpoint-action}
2484 @item --checkpoint-action=@var{action}
2485 Instruct @command{tar} to execute an action upon hitting a
2486 breakpoint. Here we give only a brief outline. @xref{checkpoints},
2487 for a complete description.
2488
2489 The @var{action} argument can be one of the following:
2490
2491 @table @asis
2492 @item bell
2493 Produce an audible bell on the console.
2494
2495 @item dot
2496 @itemx .
2497 Print a single dot on the standard listing stream.
2498
2499 @item echo
2500 Display a textual message on the standard error, with the status and
2501 number of the checkpoint. This is the default.
2502
2503 @item echo=@var{string}
2504 Display @var{string} on the standard error. Before output, the string
2505 is subject to meta-character expansion.
2506
2507 @item exec=@var{command}
2508 Execute the given @var{command}.
2509
2510 @item sleep=@var{time}
2511 Wait for @var{time} seconds.
2512
2513 @item ttyout=@var{string}
2514 Output @var{string} on the current console (@file{/dev/tty}).
2515 @end table
2516
2517 Several @option{--checkpoint-action} options can be specified. The
2518 supplied actions will be executed in order of their appearance in the
2519 command line.
2520
2521 Using @option{--checkpoint-action} without @option{--checkpoint}
2522 assumes default checkpoint frequency of one checkpoint per 10 records.
2523
2524 @opsummary{check-links}
2525 @item --check-links
2526 @itemx -l
2527 If this option was given, @command{tar} will check the number of links
2528 dumped for each processed file. If this number does not match the
2529 total number of hard links for the file, a warning message will be
2530 output @footnote{Earlier versions of @GNUTAR{} understood @option{-l} as a
2531 synonym for @option{--one-file-system}. The current semantics, which
2532 complies to UNIX98, was introduced with version
2533 1.15.91. @xref{Changes}, for more information.}.
2534
2535 @xref{hard links}.
2536
2537 @opsummary{compress}
2538 @opsummary{uncompress}
2539 @item --compress
2540 @itemx --uncompress
2541 @itemx -Z
2542
2543 @command{tar} will use the @command{compress} program when reading or
2544 writing the archive. This allows you to directly act on archives
2545 while saving space. @xref{gzip}.
2546
2547 @opsummary{confirmation}
2548 @item --confirmation
2549
2550 (See @option{--interactive}.) @xref{interactive}.
2551
2552 @opsummary{delay-directory-restore}
2553 @item --delay-directory-restore
2554
2555 Delay setting modification times and permissions of extracted
2556 directories until the end of extraction. @xref{Directory Modification Times and Permissions}.
2557
2558 @opsummary{dereference}
2559 @item --dereference
2560 @itemx -h
2561
2562 When reading or writing a file to be archived, @command{tar} accesses
2563 the file that a symbolic link points to, rather than the symlink
2564 itself. @xref{dereference}.
2565
2566 @opsummary{directory}
2567 @item --directory=@var{dir}
2568 @itemx -C @var{dir}
2569
2570 When this option is specified, @command{tar} will change its current directory
2571 to @var{dir} before performing any operations. When this option is used
2572 during archive creation, it is order sensitive. @xref{directory}.
2573
2574 @opsummary{exclude}
2575 @item --exclude=@var{pattern}
2576
2577 When performing operations, @command{tar} will skip files that match
2578 @var{pattern}. @xref{exclude}.
2579
2580 @opsummary{exclude-backups}
2581 @item --exclude-backups
2582 Exclude backup and lock files. @xref{exclude,, exclude-backups}.
2583
2584 @opsummary{exclude-from}
2585 @item --exclude-from=@var{file}
2586 @itemx -X @var{file}
2587
2588 Similar to @option{--exclude}, except @command{tar} will use the list of
2589 patterns in the file @var{file}. @xref{exclude}.
2590
2591 @opsummary{exclude-caches}
2592 @item --exclude-caches
2593
2594 Exclude from dump any directory containing a valid cache directory
2595 tag file, but still dump the directory node and the tag file itself.
2596
2597 @xref{exclude,, exclude-caches}.
2598
2599 @opsummary{exclude-caches-under}
2600 @item --exclude-caches-under
2601
2602 Exclude from dump any directory containing a valid cache directory
2603 tag file, but still dump the directory node itself.
2604
2605 @xref{exclude}.
2606
2607 @opsummary{exclude-caches-all}
2608 @item --exclude-caches-all
2609
2610 Exclude from dump any directory containing a valid cache directory
2611 tag file. @xref{exclude}.
2612
2613 @opsummary{exclude-tag}
2614 @item --exclude-tag=@var{file}
2615
2616 Exclude from dump any directory containing file named @var{file}, but
2617 dump the directory node and @var{file} itself. @xref{exclude,, exclude-tag}.
2618
2619 @opsummary{exclude-tag-under}
2620 @item --exclude-tag-under=@var{file}
2621
2622 Exclude from dump the contents of any directory containing file
2623 named @var{file}, but dump the directory node itself. @xref{exclude,,
2624 exclude-tag-under}.
2625
2626 @opsummary{exclude-tag-all}
2627 @item --exclude-tag-all=@var{file}
2628
2629 Exclude from dump any directory containing file named @var{file}.
2630 @xref{exclude,,exclude-tag-all}.
2631
2632 @opsummary{exclude-vcs}
2633 @item --exclude-vcs
2634
2635 Exclude from dump directories and files, that are internal for some
2636 widely used version control systems.
2637
2638 @xref{exclude,,exclude-vcs}.
2639
2640 @opsummary{file}
2641 @item --file=@var{archive}
2642 @itemx -f @var{archive}
2643
2644 @command{tar} will use the file @var{archive} as the @command{tar} archive it
2645 performs operations on, rather than @command{tar}'s compilation dependent
2646 default. @xref{file tutorial}.
2647
2648 @opsummary{files-from}
2649 @item --files-from=@var{file}
2650 @itemx -T @var{file}
2651
2652 @command{tar} will use the contents of @var{file} as a list of archive members
2653 or files to operate on, in addition to those specified on the
2654 command-line. @xref{files}.
2655
2656 @opsummary{force-local}
2657 @item --force-local
2658
2659 Forces @command{tar} to interpret the file name given to @option{--file}
2660 as a local file, even if it looks like a remote tape drive name.
2661 @xref{local and remote archives}.
2662
2663 @opsummary{format}
2664 @item --format=@var{format}
2665 @itemx -H @var{format}
2666
2667 Selects output archive format. @var{Format} may be one of the
2668 following:
2669
2670 @table @samp
2671 @item v7
2672 Creates an archive that is compatible with Unix V7 @command{tar}.
2673
2674 @item oldgnu
2675 Creates an archive that is compatible with GNU @command{tar} version
2676 1.12 or earlier.
2677
2678 @item gnu
2679 Creates archive in GNU tar 1.13 format. Basically it is the same as
2680 @samp{oldgnu} with the only difference in the way it handles long
2681 numeric fields.
2682
2683 @item ustar
2684 Creates a @acronym{POSIX.1-1988} compatible archive.
2685
2686 @item posix
2687 Creates a @acronym{POSIX.1-2001 archive}.
2688
2689 @end table
2690
2691 @xref{Formats}, for a detailed discussion of these formats.
2692
2693 @opsummary{full-time}
2694 @item --full-time
2695 This option instructs @command{tar} to print file times to their full
2696 resolution. Usually this means 1-second resolution, but that depends
2697 on the underlying file system. The @option{--full-time} option takes
2698 effect only when detailed output (verbosity level 2 or higher) has
2699 been requested using the @option{--verbose} option, e.g., when listing
2700 or extracting archives:
2701
2702 @smallexample
2703 $ @kbd{tar -t -v --full-time -f archive.tar}
2704 @end smallexample
2705
2706 @noindent
2707 or, when creating an archive:
2708
2709 @smallexample
2710 $ @kbd{tar -c -vv --full-time -f archive.tar .}
2711 @end smallexample
2712
2713 Notice, thar when creating the archive you need to specify
2714 @option{--verbose} twice to get a detailed output (@pxref{verbose
2715 tutorial}).
2716
2717 @opsummary{group}
2718 @item --group=@var{group}
2719
2720 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
2721 rather than the group from the source file. @var{group} is first decoded
2722 as a group symbolic name, but if this interpretation fails, it has to be
2723 a decimal numeric group @acronym{ID}. @xref{override}.
2724
2725 Also see the comments for the @option{--owner=@var{user}} option.
2726
2727 @opsummary{gzip}
2728 @opsummary{gunzip}
2729 @opsummary{ungzip}
2730 @item --gzip
2731 @itemx --gunzip
2732 @itemx --ungzip
2733 @itemx -z
2734
2735 This option tells @command{tar} to read or write archives through
2736 @command{gzip}, allowing @command{tar} to directly operate on several
2737 kinds of compressed archives transparently. @xref{gzip}.
2738
2739 @opsummary{hard-dereference}
2740 @item --hard-dereference
2741 When creating an archive, dereference hard links and store the files
2742 they refer to, instead of creating usual hard link members.
2743
2744 @xref{hard links}.
2745
2746 @opsummary{help}
2747 @item --help
2748 @itemx -?
2749
2750 @command{tar} will print out a short message summarizing the operations and
2751 options to @command{tar} and exit. @xref{help}.
2752
2753 @opsummary{ignore-case}
2754 @item --ignore-case
2755 Ignore case when matching member or file names with
2756 patterns. @xref{controlling pattern-matching}.
2757
2758 @opsummary{ignore-command-error}
2759 @item --ignore-command-error
2760 Ignore exit codes of subprocesses. @xref{Writing to an External Program}.
2761
2762 @opsummary{ignore-failed-read}
2763 @item --ignore-failed-read
2764
2765 Do not exit unsuccessfully merely because an unreadable file was encountered.
2766 @xref{Reading}.
2767
2768 @opsummary{ignore-zeros}
2769 @item --ignore-zeros
2770 @itemx -i
2771
2772 With this option, @command{tar} will ignore zeroed blocks in the
2773 archive, which normally signals EOF. @xref{Reading}.
2774
2775 @opsummary{incremental}
2776 @item --incremental
2777 @itemx -G
2778
2779 Informs @command{tar} that it is working with an old
2780 @acronym{GNU}-format incremental backup archive. It is intended
2781 primarily for backwards compatibility only. @xref{Incremental Dumps},
2782 for a detailed discussion of incremental archives.
2783
2784 @opsummary{index-file}
2785 @item --index-file=@var{file}
2786
2787 Send verbose output to @var{file} instead of to standard output.
2788
2789 @opsummary{info-script}
2790 @opsummary{new-volume-script}
2791 @item --info-script=@var{script-file}
2792 @itemx --new-volume-script=@var{script-file}
2793 @itemx -F @var{script-file}
2794
2795 When @command{tar} is performing multi-tape backups, @var{script-file} is run
2796 at the end of each tape. If @var{script-file} exits with nonzero status,
2797 @command{tar} fails immediately. @xref{info-script}, for a detailed
2798 discussion of @var{script-file}.
2799
2800 @opsummary{interactive}
2801 @item --interactive
2802 @itemx --confirmation
2803 @itemx -w
2804
2805 Specifies that @command{tar} should ask the user for confirmation before
2806 performing potentially destructive options, such as overwriting files.
2807 @xref{interactive}.
2808
2809 @opsummary{keep-newer-files}
2810 @item --keep-newer-files
2811
2812 Do not replace existing files that are newer than their archive copies
2813 when extracting files from an archive.
2814
2815 @opsummary{keep-old-files}
2816 @item --keep-old-files
2817 @itemx -k
2818
2819 Do not overwrite existing files when extracting files from an archive.
2820 @xref{Keep Old Files}.
2821
2822 @opsummary{label}
2823 @item --label=@var{name}
2824 @itemx -V @var{name}
2825
2826 When creating an archive, instructs @command{tar} to write @var{name}
2827 as a name record in the archive. When extracting or listing archives,
2828 @command{tar} will only operate on archives that have a label matching
2829 the pattern specified in @var{name}. @xref{Tape Files}.
2830
2831 @opsummary{level}
2832 @item --level=@var{n}
2833 Force incremental backup of level @var{n}. As of @GNUTAR version
2834 @value{VERSION}, the option @option{--level=0} truncates the snapshot
2835 file, thereby forcing the level 0 dump. Other values of @var{n} are
2836 effectively ignored. @xref{--level=0}, for details and examples.
2837
2838 The use of this option is valid only in conjunction with the
2839 @option{--listed-incremental} option. @xref{Incremental Dumps},
2840 for a detailed description.
2841
2842 @opsummary{listed-incremental}
2843 @item --listed-incremental=@var{snapshot-file}
2844 @itemx -g @var{snapshot-file}
2845
2846 During a @option{--create} operation, specifies that the archive that
2847 @command{tar} creates is a new @acronym{GNU}-format incremental
2848 backup, using @var{snapshot-file} to determine which files to backup.
2849 With other operations, informs @command{tar} that the archive is in
2850 incremental format. @xref{Incremental Dumps}.
2851
2852 @opsummary{lzip}
2853 @item --lzip
2854
2855 This option tells @command{tar} to read or write archives through
2856 @command{lzip}. @xref{gzip}.
2857
2858 @opsummary{lzma}
2859 @item --lzma
2860
2861 This option tells @command{tar} to read or write archives through
2862 @command{lzma}. @xref{gzip}.
2863
2864 @item --lzop
2865
2866 This option tells @command{tar} to read or write archives through
2867 @command{lzop}. @xref{gzip}.
2868
2869 @opsummary{mode}
2870 @item --mode=@var{permissions}
2871
2872 When adding files to an archive, @command{tar} will use
2873 @var{permissions} for the archive members, rather than the permissions
2874 from the files. @var{permissions} can be specified either as an octal
2875 number or as symbolic permissions, like with
2876 @command{chmod}. @xref{override}.
2877
2878 @opsummary{mtime}
2879 @item --mtime=@var{date}
2880
2881 When adding files to an archive, @command{tar} will use @var{date} as
2882 the modification time of members when creating archives, instead of
2883 their actual modification times. The value of @var{date} can be
2884 either a textual date representation (@pxref{Date input formats}) or a
2885 name of the existing file, starting with @samp{/} or @samp{.}. In the
2886 latter case, the modification time of that file is used. @xref{override}.
2887
2888 @opsummary{multi-volume}
2889 @item --multi-volume
2890 @itemx -M
2891
2892 Informs @command{tar} that it should create or otherwise operate on a
2893 multi-volume @command{tar} archive. @xref{Using Multiple Tapes}.
2894
2895 @opsummary{new-volume-script}
2896 @item --new-volume-script
2897
2898 (see @option{--info-script})
2899
2900 @opsummary{newer}
2901 @item --newer=@var{date}
2902 @itemx --after-date=@var{date}
2903 @itemx -N
2904
2905 When creating an archive, @command{tar} will only add files that have changed
2906 since @var{date}. If @var{date} begins with @samp{/} or @samp{.}, it
2907 is taken to be the name of a file whose data modification time specifies
2908 the date. @xref{after}.
2909
2910 @opsummary{newer-mtime}
2911 @item --newer-mtime=@var{date}
2912
2913 Like @option{--newer}, but add only files whose
2914 contents have changed (as opposed to just @option{--newer}, which will
2915 also back up files for which any status information has
2916 changed). @xref{after}.
2917
2918 @opsummary{no-anchored}
2919 @item --no-anchored
2920 An exclude pattern can match any subsequence of the name's components.
2921 @xref{controlling pattern-matching}.
2922
2923 @opsummary{no-auto-compress}
2924 @item --no-auto-compress
2925
2926 Disables automatic compressed format recognition based on the archive
2927 suffix. @xref{--auto-compress}. @xref{gzip}.
2928
2929 @opsummary{no-check-device}
2930 @item --no-check-device
2931 Do not check device numbers when creating a list of modified files
2932 for incremental archiving. @xref{device numbers}, for
2933 a detailed description.
2934
2935 @opsummary{no-delay-directory-restore}
2936 @item --no-delay-directory-restore
2937
2938 Modification times and permissions of extracted
2939 directories are set when all files from this directory have been
2940 extracted. This is the default.
2941 @xref{Directory Modification Times and Permissions}.
2942
2943 @opsummary{no-ignore-case}
2944 @item --no-ignore-case
2945 Use case-sensitive matching.
2946 @xref{controlling pattern-matching}.
2947
2948 @opsummary{no-ignore-command-error}
2949 @item --no-ignore-command-error
2950 Print warnings about subprocesses that terminated with a nonzero exit
2951 code. @xref{Writing to an External Program}.
2952
2953 @opsummary{no-null}
2954 @item --no-null
2955
2956 If the @option{--null} option was given previously, this option
2957 cancels its effect, so that any following @option{--files-from}
2958 options will expect their file lists to be newline-terminated.
2959
2960 @opsummary{no-overwrite-dir}
2961 @item --no-overwrite-dir
2962
2963 Preserve metadata of existing directories when extracting files
2964 from an archive. @xref{Overwrite Old Files}.
2965
2966 @opsummary{no-quote-chars}
2967 @item --no-quote-chars=@var{string}
2968 Remove characters listed in @var{string} from the list of quoted
2969 characters set by the previous @option{--quote-chars} option
2970 (@pxref{quoting styles}).
2971
2972 @opsummary{no-recursion}
2973 @item --no-recursion
2974
2975 With this option, @command{tar} will not recurse into directories.
2976 @xref{recurse}.
2977
2978 @opsummary{no-same-owner}
2979 @item --no-same-owner
2980 @itemx -o
2981
2982 When extracting an archive, do not attempt to preserve the owner
2983 specified in the @command{tar} archive. This the default behavior
2984 for ordinary users.
2985
2986 @opsummary{no-same-permissions}
2987 @item --no-same-permissions
2988
2989 When extracting an archive, subtract the user's umask from files from
2990 the permissions specified in the archive. This is the default behavior
2991 for ordinary users.
2992
2993 @opsummary{no-seek}
2994 @item --no-seek
2995
2996 The archive media does not support seeks to arbitrary
2997 locations. Usually @command{tar} determines automatically whether
2998 the archive can be seeked or not. Use this option to disable this
2999 mechanism.
3000
3001 @opsummary{no-unquote}
3002 @item --no-unquote
3003 Treat all input file or member names literally, do not interpret
3004 escape sequences. @xref{input name quoting}.
3005
3006 @opsummary{no-wildcards}
3007 @item --no-wildcards
3008 Do not use wildcards.
3009 @xref{controlling pattern-matching}.
3010
3011 @opsummary{no-wildcards-match-slash}
3012 @item --no-wildcards-match-slash
3013 Wildcards do not match @samp{/}.
3014 @xref{controlling pattern-matching}.
3015
3016 @opsummary{null}
3017 @item --null
3018
3019 When @command{tar} is using the @option{--files-from} option, this option
3020 instructs @command{tar} to expect file names terminated with @acronym{NUL}, so
3021 @command{tar} can correctly work with file names that contain newlines.
3022 @xref{nul}.
3023
3024 @opsummary{numeric-owner}
3025 @item --numeric-owner
3026
3027 This option will notify @command{tar} that it should use numeric user
3028 and group IDs when creating a @command{tar} file, rather than names.
3029 @xref{Attributes}.
3030
3031 @item -o
3032 The function of this option depends on the action @command{tar} is
3033 performing. When extracting files, @option{-o} is a synonym for
3034 @option{--no-same-owner}, i.e., it prevents @command{tar} from
3035 restoring ownership of files being extracted.
3036
3037 When creating an archive, it is a synonym for
3038 @option{--old-archive}. This behavior is for compatibility
3039 with previous versions of @GNUTAR{}, and will be
3040 removed in future releases.
3041
3042 @xref{Changes}, for more information.
3043
3044 @opsummary{occurrence}
3045 @item --occurrence[=@var{number}]
3046
3047 This option can be used in conjunction with one of the subcommands
3048 @option{--delete}, @option{--diff}, @option{--extract} or
3049 @option{--list} when a list of files is given either on the command
3050 line or via @option{-T} option.
3051
3052 This option instructs @command{tar} to process only the @var{number}th
3053 occurrence of each named file. @var{Number} defaults to 1, so
3054
3055 @smallexample
3056 tar -x -f archive.tar --occurrence filename
3057 @end smallexample
3058
3059 @noindent
3060 will extract the first occurrence of the member @file{filename} from @file{archive.tar}
3061 and will terminate without scanning to the end of the archive.
3062
3063 @opsummary{old-archive}
3064 @item --old-archive
3065 Synonym for @option{--format=v7}.
3066
3067 @opsummary{one-file-system}
3068 @item --one-file-system
3069 Used when creating an archive. Prevents @command{tar} from recursing into
3070 directories that are on different file systems from the current
3071 directory.
3072
3073 @opsummary{overwrite}
3074 @item --overwrite
3075
3076 Overwrite existing files and directory metadata when extracting files
3077 from an archive. @xref{Overwrite Old Files}.
3078
3079 @opsummary{overwrite-dir}
3080 @item --overwrite-dir
3081
3082 Overwrite the metadata of existing directories when extracting files
3083 from an archive. @xref{Overwrite Old Files}.
3084
3085 @opsummary{owner}
3086 @item --owner=@var{user}
3087
3088 Specifies that @command{tar} should use @var{user} as the owner of members
3089 when creating archives, instead of the user associated with the source
3090 file. @var{user} is first decoded as a user symbolic name, but if
3091 this interpretation fails, it has to be a decimal numeric user @acronym{ID}.
3092 @xref{override}.
3093
3094 This option does not affect extraction from archives.
3095
3096 @opsummary{pax-option}
3097 @item --pax-option=@var{keyword-list}
3098 This option enables creation of the archive in @acronym{POSIX.1-2001}
3099 format (@pxref{posix}) and modifies the way @command{tar} handles the
3100 extended header keywords. @var{Keyword-list} is a comma-separated
3101 list of keyword options. @xref{PAX keywords}, for a detailed
3102 discussion.
3103
3104 @opsummary{portability}
3105 @item --portability
3106 @itemx --old-archive
3107 Synonym for @option{--format=v7}.
3108
3109 @opsummary{posix}
3110 @item --posix
3111 Same as @option{--format=posix}.
3112
3113 @opsummary{preserve}
3114 @item --preserve
3115
3116 Synonymous with specifying both @option{--preserve-permissions} and
3117 @option{--same-order}. @xref{Setting Access Permissions}.
3118
3119 @opsummary{preserve-order}
3120 @item --preserve-order
3121
3122 (See @option{--same-order}; @pxref{Reading}.)
3123
3124 @opsummary{preserve-permissions}
3125 @opsummary{same-permissions}
3126 @item --preserve-permissions
3127 @itemx --same-permissions
3128 @itemx -p
3129
3130 When @command{tar} is extracting an archive, it normally subtracts the
3131 users' umask from the permissions specified in the archive and uses
3132 that number as the permissions to create the destination file.
3133 Specifying this option instructs @command{tar} that it should use the
3134 permissions directly from the archive. @xref{Setting Access Permissions}.
3135
3136 @opsummary{quote-chars}
3137 @item --quote-chars=@var{string}
3138 Always quote characters from @var{string}, even if the selected
3139 quoting style would not quote them (@pxref{quoting styles}).
3140
3141 @opsummary{quoting-style}
3142 @item --quoting-style=@var{style}
3143 Set quoting style to use when printing member and file names
3144 (@pxref{quoting styles}). Valid @var{style} values are:
3145 @code{literal}, @code{shell}, @code{shell-always}, @code{c},
3146 @code{escape}, @code{locale}, and @code{clocale}. Default quoting
3147 style is @code{escape}, unless overridden while configuring the
3148 package.
3149
3150 @opsummary{read-full-records}
3151 @item --read-full-records
3152 @itemx -B
3153
3154 Specifies that @command{tar} should reblock its input, for reading
3155 from pipes on systems with buggy implementations. @xref{Reading}.
3156
3157 @opsummary{record-size}
3158 @item --record-size=@var{size}[@var{suf}]
3159
3160 Instructs @command{tar} to use @var{size} bytes per record when accessing the
3161 archive. The argument can be suffixed with a @dfn{size suffix}, e.g.
3162 @option{--record-size=10K} for 10 Kilobytes. @xref{size-suffixes},
3163 for a list of valid suffixes. @xref{Blocking Factor}, for a detailed
3164 description of this option.
3165
3166 @opsummary{recursion}
3167 @item --recursion
3168
3169 With this option, @command{tar} recurses into directories (default).
3170 @xref{recurse}.
3171
3172 @opsummary{recursive-unlink}
3173 @item --recursive-unlink
3174
3175 Remove existing
3176 directory hierarchies before extracting directories of the same name
3177 from the archive. @xref{Recursive Unlink}.
3178
3179 @opsummary{remove-files}
3180 @item --remove-files
3181
3182 Directs @command{tar} to remove the source file from the file system after
3183 appending it to an archive. @xref{remove files}.
3184
3185 @opsummary{restrict}
3186 @item --restrict
3187
3188 Disable use of some potentially harmful @command{tar} options.
3189 Currently this option disables shell invocation from multi-volume menu
3190 (@pxref{Using Multiple Tapes}).
3191
3192 @opsummary{rmt-command}
3193 @item --rmt-command=@var{cmd}
3194
3195 Notifies @command{tar} that it should use @var{cmd} instead of
3196 the default @file{/usr/libexec/rmt} (@pxref{Remote Tape Server}).
3197
3198 @opsummary{rsh-command}
3199 @item --rsh-command=@var{cmd}
3200
3201 Notifies @command{tar} that is should use @var{cmd} to communicate with remote
3202 devices. @xref{Device}.
3203
3204 @opsummary{same-order}
3205 @item --same-order
3206 @itemx --preserve-order
3207 @itemx -s
3208
3209 This option is an optimization for @command{tar} when running on machines with
3210 small amounts of memory. It informs @command{tar} that the list of file
3211 arguments has already been sorted to match the order of files in the
3212 archive. @xref{Reading}.
3213
3214 @opsummary{same-owner}
3215 @item --same-owner
3216
3217 When extracting an archive, @command{tar} will attempt to preserve the owner
3218 specified in the @command{tar} archive with this option present.
3219 This is the default behavior for the superuser; this option has an
3220 effect only for ordinary users. @xref{Attributes}.
3221
3222 @opsummary{same-permissions}
3223 @item --same-permissions
3224
3225 (See @option{--preserve-permissions}; @pxref{Setting Access Permissions}.)
3226
3227 @opsummary{seek}
3228 @item --seek
3229 @itemx -n
3230
3231 Assume that the archive media supports seeks to arbitrary
3232 locations. Usually @command{tar} determines automatically whether
3233 the archive can be seeked or not. This option is intended for use
3234 in cases when such recognition fails. It takes effect only if the
3235 archive is open for reading (e.g. with @option{--list} or
3236 @option{--extract} options).
3237
3238 @opsummary{show-defaults}
3239 @item --show-defaults
3240
3241 Displays the default options used by @command{tar} and exits
3242 successfully. This option is intended for use in shell scripts.
3243 Here is an example of what you can see using this option:
3244
3245 @smallexample
3246 $ @kbd{tar --show-defaults}
3247 --format=gnu -f- -b20 --quoting-style=escape
3248 --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
3249 @end smallexample
3250
3251 @noindent
3252 Notice, that this option outputs only one line. The example output
3253 above has been split to fit page boundaries.
3254
3255 @opsummary{show-omitted-dirs}
3256 @item --show-omitted-dirs
3257
3258 Instructs @command{tar} to mention the directories it is skipping when
3259 operating on a @command{tar} archive. @xref{show-omitted-dirs}.
3260
3261 @opsummary{show-transformed-names}
3262 @opsummary{show-stored-names}
3263 @item --show-transformed-names
3264 @itemx --show-stored-names
3265
3266 Display file or member names after applying any transformations
3267 (@pxref{transform}). In particular, when used in conjunction with one of
3268 the archive creation operations it instructs @command{tar} to list the
3269 member names stored in the archive, as opposed to the actual file
3270 names. @xref{listing member and file names}.
3271
3272 @opsummary{sparse}
3273 @item --sparse
3274 @itemx -S
3275
3276 Invokes a @acronym{GNU} extension when adding files to an archive that handles
3277 sparse files efficiently. @xref{sparse}.
3278
3279 @opsummary{sparse-version}
3280 @item --sparse-version=@var{version}
3281
3282 Specifies the @dfn{format version} to use when archiving sparse
3283 files. Implies @option{--sparse}. @xref{sparse}. For the description
3284 of the supported sparse formats, @xref{Sparse Formats}.
3285
3286 @opsummary{starting-file}
3287 @item --starting-file=@var{name}
3288 @itemx -K @var{name}
3289
3290 This option affects extraction only; @command{tar} will skip extracting
3291 files in the archive until it finds one that matches @var{name}.
3292 @xref{Scarce}.
3293
3294 @opsummary{strip-components}
3295 @item --strip-components=@var{number}
3296 Strip given @var{number} of leading components from file names before
3297 extraction. For example, if archive @file{archive.tar} contained
3298 @file{/some/file/name}, then running
3299
3300 @smallexample
3301 tar --extract --file archive.tar --strip-components=2
3302 @end smallexample
3303
3304 @noindent
3305 would extract this file to file @file{name}.
3306
3307 @opsummary{suffix}
3308 @item --suffix=@var{suffix}
3309
3310 Alters the suffix @command{tar} uses when backing up files from the default
3311 @samp{~}. @xref{backup}.
3312
3313 @opsummary{tape-length}
3314 @item --tape-length=@var{num}[@var{suf}]
3315 @itemx -L @var{num}[@var{suf}]
3316
3317 Specifies the length of tapes that @command{tar} is writing as being
3318 @w{@var{num} x 1024} bytes long. If optional @var{suf} is given, it
3319 specifies a multiplicative factor to be used instead of 1024. For
3320 example, @samp{-L2M} means 2 megabytes. @xref{size-suffixes}, for a
3321 list of allowed suffixes. @xref{Using Multiple Tapes}, for a detailed
3322 discussion of this option.
3323
3324 @opsummary{test-label}
3325 @item --test-label
3326
3327 Reads the volume label. If an argument is specified, test whether it
3328 matches the volume label. @xref{--test-label option}.
3329
3330 @opsummary{to-command}
3331 @item --to-command=@var{command}
3332
3333 During extraction @command{tar} will pipe extracted files to the
3334 standard input of @var{command}. @xref{Writing to an External Program}.
3335
3336 @opsummary{to-stdout}
3337 @item --to-stdout
3338 @itemx -O
3339
3340 During extraction, @command{tar} will extract files to stdout rather
3341 than to the file system. @xref{Writing to Standard Output}.
3342
3343 @opsummary{totals}
3344 @item --totals[=@var{signo}]
3345
3346 Displays the total number of bytes transferred when processing an
3347 archive. If an argument is given, these data are displayed on
3348 request, when signal @var{signo} is delivered to @command{tar}.
3349 @xref{totals}.
3350
3351 @opsummary{touch}
3352 @item --touch
3353 @itemx -m
3354
3355 Sets the data modification time of extracted files to the extraction time,
3356 rather than the data modification time stored in the archive.
3357 @xref{Data Modification Times}.
3358
3359 @opsummary{transform}
3360 @opsummary{xform}
3361 @item --transform=@var{sed-expr}
3362 @itemx --xform=@var{sed-expr}
3363 Transform file or member names using @command{sed} replacement expression
3364 @var{sed-expr}. For example,
3365
3366 @smallexample
3367 $ @kbd{tar cf archive.tar --transform 's,^\./,usr/,' .}
3368 @end smallexample
3369
3370 @noindent
3371 will add to @file{archive} files from the current working directory,
3372 replacing initial @samp{./} prefix with @samp{usr/}. For the detailed
3373 discussion, @xref{transform}.
3374
3375 To see transformed member names in verbose listings, use
3376 @option{--show-transformed-names} option
3377 (@pxref{show-transformed-names}).
3378
3379 @opsummary{uncompress}
3380 @item --uncompress
3381
3382 (See @option{--compress}, @pxref{gzip})
3383
3384 @opsummary{ungzip}
3385 @item --ungzip
3386
3387 (See @option{--gzip}, @pxref{gzip})
3388
3389 @opsummary{unlink-first}
3390 @item --unlink-first
3391 @itemx -U
3392
3393 Directs @command{tar} to remove the corresponding file from the file
3394 system before extracting it from the archive. @xref{Unlink First}.
3395
3396 @opsummary{unquote}
3397 @item --unquote
3398 Enable unquoting input file or member names (default). @xref{input
3399 name quoting}.
3400
3401 @opsummary{use-compress-program}
3402 @item --use-compress-program=@var{prog}
3403 @itemx -I=@var{prog}
3404
3405 Instructs @command{tar} to access the archive through @var{prog}, which is
3406 presumed to be a compression program of some sort. @xref{gzip}.
3407
3408 @opsummary{utc}
3409 @item --utc
3410
3411 Display file modification dates in @acronym{UTC}. This option implies
3412 @option{--verbose}.
3413
3414 @opsummary{verbose}
3415 @item --verbose
3416 @itemx -v
3417
3418 Specifies that @command{tar} should be more verbose about the
3419 operations it is performing. This option can be specified multiple
3420 times for some operations to increase the amount of information displayed.
3421 @xref{verbose}.
3422
3423 @opsummary{verify}
3424 @item --verify
3425 @itemx -W
3426
3427 Verifies that the archive was correctly written when creating an
3428 archive. @xref{verify}.
3429
3430 @opsummary{version}
3431 @item --version
3432
3433 Print information about the program's name, version, origin and legal
3434 status, all on standard output, and then exit successfully.
3435 @xref{help}.
3436
3437 @opsummary{volno-file}
3438 @item --volno-file=@var{file}
3439
3440 Used in conjunction with @option{--multi-volume}. @command{tar} will
3441 keep track of which volume of a multi-volume archive it is working in
3442 @var{file}. @xref{volno-file}.
3443
3444 @opsummary{warning}
3445 @item --warning=@var{keyword}
3446
3447 Enable or disable warning messages identified by @var{keyword}. The
3448 messages are suppressed if @var{keyword} is prefixed with @samp{no-}.
3449 @xref{warnings}.
3450
3451 @opsummary{wildcards}
3452 @item --wildcards
3453 Use wildcards when matching member names with patterns.
3454 @xref{controlling pattern-matching}.
3455
3456 @opsummary{wildcards-match-slash}
3457 @item --wildcards-match-slash
3458 Wildcards match @samp{/}.
3459 @xref{controlling pattern-matching}.
3460
3461 @opsummary{xz}
3462 @item --xz
3463 @itemx -J
3464 Use @command{xz} for compressing or decompressing the archives. @xref{gzip}.
3465
3466 @end table
3467
3468 @node Short Option Summary
3469 @subsection Short Options Cross Reference
3470
3471 Here is an alphabetized list of all of the short option forms, matching
3472 them with the equivalent long option.
3473
3474 @multitable @columnfractions 0.20 0.80
3475 @headitem Short Option @tab Reference
3476
3477 @item -A @tab @ref{--concatenate}.
3478
3479 @item -B @tab @ref{--read-full-records}.
3480
3481 @item -C @tab @ref{--directory}.
3482
3483 @item -F @tab @ref{--info-script}.
3484
3485 @item -G @tab @ref{--incremental}.
3486
3487 @item -J @tab @ref{--xz}.
3488
3489 @item -K @tab @ref{--starting-file}.
3490
3491 @item -L @tab @ref{--tape-length}.
3492
3493 @item -M @tab @ref{--multi-volume}.
3494
3495 @item -N @tab @ref{--newer}.
3496
3497 @item -O @tab @ref{--to-stdout}.
3498
3499 @item -P @tab @ref{--absolute-names}.
3500
3501 @item -R @tab @ref{--block-number}.
3502
3503 @item -S @tab @ref{--sparse}.
3504
3505 @item -T @tab @ref{--files-from}.
3506
3507 @item -U @tab @ref{--unlink-first}.
3508
3509 @item -V @tab @ref{--label}.
3510
3511 @item -W @tab @ref{--verify}.
3512
3513 @item -X @tab @ref{--exclude-from}.
3514
3515 @item -Z @tab @ref{--compress}.
3516
3517 @item -b @tab @ref{--blocking-factor}.
3518
3519 @item -c @tab @ref{--create}.
3520
3521 @item -d @tab @ref{--compare}.
3522
3523 @item -f @tab @ref{--file}.
3524
3525 @item -g @tab @ref{--listed-incremental}.
3526
3527 @item -h @tab @ref{--dereference}.
3528
3529 @item -i @tab @ref{--ignore-zeros}.
3530
3531 @item -j @tab @ref{--bzip2}.
3532
3533 @item -k @tab @ref{--keep-old-files}.
3534
3535 @item -l @tab @ref{--check-links}.
3536
3537 @item -m @tab @ref{--touch}.
3538
3539 @item -o @tab When creating, @ref{--no-same-owner}, when extracting ---
3540 @ref{--portability}.
3541
3542 The latter usage is deprecated. It is retained for compatibility with
3543 the earlier versions of @GNUTAR{}. In future releases
3544 @option{-o} will be equivalent to @option{--no-same-owner} only.
3545
3546 @item -p @tab @ref{--preserve-permissions}.
3547
3548 @item -r @tab @ref{--append}.
3549
3550 @item -s @tab @ref{--same-order}.
3551
3552 @item -t @tab @ref{--list}.
3553
3554 @item -u @tab @ref{--update}.
3555
3556 @item -v @tab @ref{--verbose}.
3557
3558 @item -w @tab @ref{--interactive}.
3559
3560 @item -x @tab @ref{--extract}.
3561
3562 @item -z @tab @ref{--gzip}.
3563
3564 @end multitable
3565
3566 @node help
3567 @section @GNUTAR{} documentation
3568
3569 @cindex Getting program version number
3570 @opindex version
3571 @cindex Version of the @command{tar} program
3572 Being careful, the first thing is really checking that you are using
3573 @GNUTAR{}, indeed. The @option{--version} option
3574 causes @command{tar} to print information about its name, version,
3575 origin and legal status, all on standard output, and then exit
3576 successfully. For example, @w{@samp{tar --version}} might print:
3577
3578 @smallexample
3579 tar (GNU tar) @value{VERSION}
3580 Copyright (C) 2010 Free Software Foundation, Inc.
3581 Copyright (C) 2010 Free Software Foundation, Inc.
3582 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3583 This is free software: you are free to change and redistribute it.
3584 There is NO WARRANTY, to the extent permitted by law.
3585
3586 Written by John Gilmore and Jay Fenlason.
3587 @end smallexample
3588
3589 @noindent
3590 The first occurrence of @samp{tar} in the result above is the program
3591 name in the package (for example, @command{rmt} is another program),
3592 while the second occurrence of @samp{tar} is the name of the package
3593 itself, containing possibly many programs. The package is currently
3594 named @samp{tar}, after the name of the main program it
3595 contains@footnote{There are plans to merge the @command{cpio} and
3596 @command{tar} packages into a single one which would be called
3597 @code{paxutils}. So, who knows if, one of this days, the
3598 @option{--version} would not output @w{@samp{tar (@acronym{GNU}
3599 paxutils) 3.2}}.}.
3600
3601 @cindex Obtaining help
3602 @cindex Listing all @command{tar} options
3603 @xopindex{help, introduction}
3604 Another thing you might want to do is checking the spelling or meaning
3605 of some particular @command{tar} option, without resorting to this
3606 manual, for once you have carefully read it. @GNUTAR{}
3607 has a short help feature, triggerable through the
3608 @option{--help} option. By using this option, @command{tar} will
3609 print a usage message listing all available options on standard
3610 output, then exit successfully, without doing anything else and
3611 ignoring all other options. Even if this is only a brief summary, it
3612 may be several screens long. So, if you are not using some kind of
3613 scrollable window, you might prefer to use something like:
3614
3615 @smallexample
3616 $ @kbd{tar --help | less}
3617 @end smallexample
3618
3619 @noindent
3620 presuming, here, that you like using @command{less} for a pager. Other
3621 popular pagers are @command{more} and @command{pg}. If you know about some
3622 @var{keyword} which interests you and do not want to read all the
3623 @option{--help} output, another common idiom is doing:
3624
3625 @smallexample
3626 tar --help | grep @var{keyword}
3627 @end smallexample
3628
3629 @noindent
3630 for getting only the pertinent lines. Notice, however, that some
3631 @command{tar} options have long description lines and the above
3632 command will list only the first of them.
3633
3634 The exact look of the option summary displayed by @kbd{tar --help} is
3635 configurable. @xref{Configuring Help Summary}, for a detailed description.
3636
3637 @opindex usage
3638 If you only wish to check the spelling of an option, running @kbd{tar
3639 --usage} may be a better choice. This will display a terse list of
3640 @command{tar} options without accompanying explanations.
3641
3642 The short help output is quite succinct, and you might have to get
3643 back to the full documentation for precise points. If you are reading
3644 this paragraph, you already have the @command{tar} manual in some
3645 form. This manual is available in a variety of forms from
3646 @url{http://www.gnu.org/software/tar/manual}. It may be printed out of the @GNUTAR{}
3647 distribution, provided you have @TeX{} already installed somewhere,
3648 and a laser printer around. Just configure the distribution, execute
3649 the command @w{@samp{make dvi}}, then print @file{doc/tar.dvi} the
3650 usual way (contact your local guru to know how). If @GNUTAR{}
3651 has been conveniently installed at your place, this
3652 manual is also available in interactive, hypertextual form as an Info
3653 file. Just call @w{@samp{info tar}} or, if you do not have the
3654 @command{info} program handy, use the Info reader provided within
3655 @acronym{GNU} Emacs, calling @samp{tar} from the main Info menu.
3656
3657 There is currently no @code{man} page for @GNUTAR{}.
3658 If you observe such a @code{man} page on the system you are running,
3659 either it does not belong to @GNUTAR{}, or it has not
3660 been produced by @acronym{GNU}. Some package maintainers convert
3661 @kbd{tar --help} output to a man page, using @command{help2man}. In
3662 any case, please bear in mind that the authoritative source of
3663 information about @GNUTAR{} is this Texinfo documentation.
3664
3665 @node defaults
3666 @section Obtaining @GNUTAR{} default values
3667
3668 @opindex show-defaults
3669 @GNUTAR{} has some predefined defaults that are used when you do not
3670 explicitly specify another values. To obtain a list of such
3671 defaults, use @option{--show-defaults} option. This will output the
3672 values in the form of @command{tar} command line options:
3673
3674 @smallexample
3675 @group
3676 $ @kbd{tar --show-defaults}
3677 --format=gnu -f- -b20 --quoting-style=escape
3678 --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3679 @end group
3680 @end smallexample
3681
3682 @noindent
3683 Notice, that this option outputs only one line. The example output above
3684 has been split to fit page boundaries.
3685
3686 @noindent
3687 The above output shows that this version of @GNUTAR{} defaults to
3688 using @samp{gnu} archive format (@pxref{Formats}), it uses standard
3689 output as the archive, if no @option{--file} option has been given
3690 (@pxref{file tutorial}), the default blocking factor is 20
3691 (@pxref{Blocking Factor}). It also shows the default locations where
3692 @command{tar} will look for @command{rmt} and @command{rsh} binaries.
3693
3694 @node verbose
3695 @section Checking @command{tar} progress
3696
3697 Typically, @command{tar} performs most operations without reporting any
3698 information to the user except error messages. When using @command{tar}
3699 with many options, particularly ones with complicated or
3700 difficult-to-predict behavior, it is possible to make serious mistakes.
3701 @command{tar} provides several options that make observing @command{tar}
3702 easier. These options cause @command{tar} to print information as it
3703 progresses in its job, and you might want to use them just for being
3704 more careful about what is going on, or merely for entertaining
3705 yourself. If you have encountered a problem when operating on an
3706 archive, however, you may need more information than just an error
3707 message in order to solve the problem. The following options can be
3708 helpful diagnostic tools.
3709
3710 @cindex Verbose operation
3711 @opindex verbose
3712 Normally, the @option{--list} (@option{-t}) command to list an archive
3713 prints just the file names (one per line) and the other commands are
3714 silent. When used with most operations, the @option{--verbose}
3715 (@option{-v}) option causes @command{tar} to print the name of each
3716 file or archive member as it is processed. This and the other options
3717 which make @command{tar} print status information can be useful in
3718 monitoring @command{tar}.
3719
3720 With @option{--create} or @option{--extract}, @option{--verbose} used
3721 once just prints the names of the files or members as they are processed.
3722 Using it twice causes @command{tar} to print a longer listing
3723 (@xref{verbose member listing}, for the description) for each member.
3724 Since @option{--list} already prints the names of the members,
3725 @option{--verbose} used once with @option{--list} causes @command{tar}
3726 to print an @samp{ls -l} type listing of the files in the archive.
3727 The following examples both extract members with long list output:
3728
3729 @smallexample
3730 $ @kbd{tar --extract --file=archive.tar --verbose --verbose}
3731 $ @kbd{tar xvvf archive.tar}
3732 @end smallexample
3733
3734 Verbose output appears on the standard output except when an archive is
3735 being written to the standard output, as with @samp{tar --create
3736 --file=- --verbose} (@samp{tar cfv -}, or even @samp{tar cv}---if the
3737 installer let standard output be the default archive). In that case
3738 @command{tar} writes verbose output to the standard error stream.
3739
3740 If @option{--index-file=@var{file}} is specified, @command{tar} sends
3741 verbose output to @var{file} rather than to standard output or standard
3742 error.
3743
3744 @anchor{totals}
3745 @cindex Obtaining total status information
3746 @opindex totals
3747 The @option{--totals} option causes @command{tar} to print on the
3748 standard error the total amount of bytes transferred when processing
3749 an archive. When creating or appending to an archive, this option
3750 prints the number of bytes written to the archive and the average
3751 speed at which they have been written, e.g.:
3752
3753 @smallexample
3754 @group
3755 $ @kbd{tar -c -f archive.tar --totals /home}
3756 Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3757 @end group
3758 @end smallexample
3759
3760 When reading an archive, this option displays the number of bytes
3761 read:
3762
3763 @smallexample
3764 @group
3765 $ @kbd{tar -x -f archive.tar --totals}
3766 Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3767 @end group
3768 @end smallexample
3769
3770 Finally, when deleting from an archive, the @option{--totals} option
3771 displays both numbers plus number of bytes removed from the archive:
3772
3773 @smallexample
3774 @group
3775 $ @kbd{tar --delete -f foo.tar --totals --wildcards '*~'}
3776 Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3777 Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3778 Total bytes deleted: 1474048
3779 @end group
3780 @end smallexample
3781
3782 You can also obtain this information on request. When
3783 @option{--totals} is used with an argument, this argument is
3784 interpreted as a symbolic name of a signal, upon delivery of which the
3785 statistics is to be printed:
3786
3787 @table @option
3788 @item --totals=@var{signo}
3789 Print statistics upon delivery of signal @var{signo}. Valid arguments
3790 are: @code{SIGHUP}, @code{SIGQUIT}, @code{SIGINT}, @code{SIGUSR1} and
3791 @code{SIGUSR2}. Shortened names without @samp{SIG} prefix are also
3792 accepted.
3793 @end table
3794
3795 Both forms of @option{--totals} option can be used simultaneously.
3796 Thus, @kbd{tar -x --totals --totals=USR1} instructs @command{tar} to
3797 extract all members from its default archive and print statistics
3798 after finishing the extraction, as well as when receiving signal
3799 @code{SIGUSR1}.
3800
3801 @anchor{Progress information}
3802 @cindex Progress information
3803 The @option{--checkpoint} option prints an occasional message
3804 as @command{tar} reads or writes the archive. It is designed for
3805 those who don't need the more detailed (and voluminous) output of
3806 @option{--block-number} (@option{-R}), but do want visual confirmation
3807 that @command{tar} is actually making forward progress. By default it
3808 prints a message each 10 records read or written. This can be changed
3809 by giving it a numeric argument after an equal sign:
3810
3811 @smallexample
3812 $ @kbd{tar -c --checkpoint=1000} /var
3813 tar: Write checkpoint 1000
3814 tar: Write checkpoint 2000
3815 tar: Write checkpoint 3000
3816 @end smallexample
3817
3818 This example shows the default checkpoint message used by
3819 @command{tar}. If you place a dot immediately after the equal
3820 sign, it will print a @samp{.} at each checkpoint@footnote{This is
3821 actually a shortcut for @option{--checkpoint=@var{n}
3822 --checkpoint-action=dot}. @xref{checkpoints, dot}.}. For example:
3823
3824 @smallexample
3825 $ @kbd{tar -c --checkpoint=.1000} /var
3826 ...
3827 @end smallexample
3828
3829 The @option{--checkpoint} option provides a flexible mechanism for
3830 executing arbitrary actions upon hitting checkpoints, see the next
3831 section (@pxref{checkpoints}), for more information on it.
3832
3833 @opindex show-omitted-dirs
3834 @anchor{show-omitted-dirs}
3835 The @option{--show-omitted-dirs} option, when reading an archive---with
3836 @option{--list} or @option{--extract}, for example---causes a message
3837 to be printed for each directory in the archive which is skipped.
3838 This happens regardless of the reason for skipping: the directory might
3839 not have been named on the command line (implicitly or explicitly),
3840 it might be excluded by the use of the
3841 @option{--exclude=@var{pattern}} option, or some other reason.
3842
3843 @opindex block-number
3844 @cindex Block number where error occurred
3845 @anchor{block-number}
3846 If @option{--block-number} (@option{-R}) is used, @command{tar} prints, along with
3847 every message it would normally produce, the block number within the
3848 archive where the message was triggered. Also, supplementary messages
3849 are triggered when reading blocks full of NULs, or when hitting end of
3850 file on the archive. As of now, if the archive is properly terminated
3851 with a NUL block, the reading of the file may stop before end of file
3852 is met, so the position of end of file will not usually show when
3853 @option{--block-number} (@option{-R}) is used. Note that @GNUTAR{}
3854 drains the archive before exiting when reading the
3855 archive from a pipe.
3856
3857 @cindex Error message, block number of
3858 This option is especially useful when reading damaged archives, since
3859 it helps pinpoint the damaged sections. It can also be used with
3860 @option{--list} (@option{-t}) when listing a file-system backup tape, allowing you to
3861 choose among several backup tapes when retrieving a file later, in
3862 favor of the tape where the file appears earliest (closest to the
3863 front of the tape). @xref{backup}.
3864
3865 @node checkpoints
3866 @section Checkpoints
3867 @cindex checkpoints, defined
3868 @opindex checkpoint
3869 @opindex checkpoint-action
3870
3871 A @dfn{checkpoint} is a moment of time before writing @var{n}th record to
3872 the archive (a @dfn{write checkpoint}), or before reading @var{n}th record
3873 from the archive (a @dfn{read checkpoint}). Checkpoints allow to
3874 periodically execute arbitrary actions.
3875
3876 The checkpoint facility is enabled using the following option:
3877
3878 @table @option
3879 @xopindex{checkpoint, defined}
3880 @item --checkpoint[=@var{n}]
3881 Schedule checkpoints before writing or reading each @var{n}th record.
3882 The default value for @var{n} is 10.
3883 @end table
3884
3885 A list of arbitrary @dfn{actions} can be executed at each checkpoint.
3886 These actions include: pausing, displaying textual messages, and
3887 executing arbitrary external programs. Actions are defined using
3888 the @option{--checkpoint-action} option.
3889
3890 @table @option
3891 @xopindex{checkpoint-action, defined}
3892 @item --checkpoint-action=@var{action}
3893 Execute an @var{action} at each checkpoint.
3894 @end table
3895
3896 @cindex @code{echo}, checkpoint action
3897 The simplest value of @var{action} is @samp{echo}. It instructs
3898 @command{tar} to display the default message on the standard error
3899 stream upon arriving at each checkpoint. The default message is (in
3900 @acronym{POSIX} locale) @samp{Write checkpoint @var{n}}, for write
3901 checkpoints, and @samp{Read checkpoint @var{n}}, for read checkpoints.
3902 Here, @var{n} represents ordinal number of the checkpoint.
3903
3904 In another locales, translated versions of this message are used.
3905
3906 This is the default action, so running:
3907
3908 @smallexample
3909 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=echo} /var
3910 @end smallexample
3911
3912 @noindent
3913 is equivalent to:
3914
3915 @smallexample
3916 $ @kbd{tar -c --checkpoint=1000} /var
3917 @end smallexample
3918
3919 The @samp{echo} action also allows to supply a customized message.
3920 You do so by placing an equals sign and the message right after it,
3921 e.g.:
3922
3923 @smallexample
3924 --checkpoint-action="echo=Hit %s checkpoint #%u"
3925 @end smallexample
3926
3927 The @samp{%s} and @samp{%u} in the above example are
3928 @dfn{meta-characters}. The @samp{%s} meta-character is replaced with
3929 the @dfn{type} of the checkpoint: @samp{write} or
3930 @samp{read} (or a corresponding translated version in locales other
3931 than @acronym{POSIX}). The @samp{%u} meta-character is replaced with
3932 the ordinal number of the checkpoint. Thus, the above example could
3933 produce the following output when used with the @option{--create}
3934 option:
3935
3936 @smallexample
3937 tar: Hit write checkpoint #10
3938 tar: Hit write checkpoint #20
3939 tar: Hit write checkpoint #30
3940 @end smallexample
3941
3942 Aside from meta-character expansion, the message string is subject to
3943 @dfn{unquoting}, during which the backslash @dfn{escape sequences} are
3944 replaced with their corresponding @acronym{ASCII} characters
3945 (@pxref{escape sequences}). E.g. the following action will produce an
3946 audible bell and the message described above at each checkpoint:
3947
3948 @smallexample
3949 --checkpoint-action='echo=\aHit %s checkpoint #%u'
3950 @end smallexample
3951
3952 @cindex @code{bell}, checkpoint action
3953 There is also a special action which produces an audible signal:
3954 @samp{bell}. It is not equivalent to @samp{echo='\a'}, because
3955 @samp{bell} sends the bell directly to the console (@file{/dev/tty}),
3956 whereas @samp{echo='\a'} sends it to the standard error.
3957
3958 @cindex @code{ttyout}, checkpoint action
3959 The @samp{ttyout=@var{string}} action outputs @var{string} to
3960 @file{/dev/tty}, so it can be used even if the standard output is
3961 redirected elsewhere. The @var{string} is subject to the same
3962 modifications as with @samp{echo} action. In contrast to the latter,
3963 @samp{ttyout} does not prepend @command{tar} executable name to the
3964 string, nor does it output a newline after it. For example, the
3965 following action will print the checkpoint message at the same screen
3966 line, overwriting any previous message:
3967
3968 @smallexample
3969 --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3970 @end smallexample
3971
3972 @cindex @code{dot}, checkpoint action
3973 Another available checkpoint action is @samp{dot} (or @samp{.}). It
3974 instructs @command{tar} to print a single dot on the standard listing
3975 stream, e.g.:
3976
3977 @smallexample
3978 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=dot} /var
3979 ...
3980 @end smallexample
3981
3982 For compatibility with previous @GNUTAR{} versions, this action can
3983 be abbreviated by placing a dot in front of the checkpoint frequency,
3984 as shown in the previous section.
3985
3986 @cindex @code{sleep}, checkpoint action
3987 Yet another action, @samp{sleep}, pauses @command{tar} for a specified
3988 amount of seconds. The following example will stop for 30 seconds at each
3989 checkpoint:
3990
3991 @smallexample
3992 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=sleep=30}
3993 @end smallexample
3994
3995 @cindex @code{exec}, checkpoint action
3996 Finally, the @code{exec} action executes a given external program.
3997 For example:
3998
3999 @smallexample
4000 $ @kbd{tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint}
4001 @end smallexample
4002
4003 This program is executed using @command{/bin/sh -c}, with no
4004 additional arguments. Its exit code is ignored. It gets a copy of
4005 @command{tar}'s environment plus the following variables:
4006
4007 @table @env
4008 @vrindex TAR_VERSION, checkpoint script environment
4009 @item TAR_VERSION
4010 @GNUTAR{} version number.
4011
4012 @vrindex TAR_ARCHIVE, checkpoint script environment
4013 @item TAR_ARCHIVE
4014 The name of the archive @command{tar} is processing.
4015
4016 @vrindex TAR_BLOCKING_FACTOR, checkpoint script environment
4017 @item TAR_BLOCKING_FACTOR
4018 Current blocking factor (@pxref{Blocking}).
4019
4020 @vrindex TAR_CHECKPOINT, checkpoint script environment
4021 @item TAR_CHECKPOINT
4022 Number of the checkpoint.
4023
4024 @vrindex TAR_SUBCOMMAND, checkpoint script environment
4025 @item TAR_SUBCOMMAND
4026 A short option describing the operation @command{tar} is executing.
4027 @xref{Operations}, for a complete list of subcommand options.
4028
4029 @vrindex TAR_FORMAT, checkpoint script environment
4030 @item TAR_FORMAT
4031 Format of the archive being processed. @xref{Formats}, for a complete
4032 list of archive format names.
4033 @end table
4034
4035 Any number of actions can be defined, by supplying several
4036 @option{--checkpoint-action} options in the command line. For
4037 example, the command below displays two messages, pauses
4038 execution for 30 seconds and executes the @file{/sbin/cpoint} script:
4039
4040 @example
4041 @group
4042 $ @kbd{tar -c -f arc.tar \
4043 --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
4044 --checkpoint-action='echo=Sleeping for 30 seconds' \
4045 --checkpoint-action='sleep=30' \
4046 --checkpoint-action='exec=/sbin/cpoint'}
4047 @end group
4048 @end example
4049
4050 This example also illustrates the fact that
4051 @option{--checkpoint-action} can be used without
4052 @option{--checkpoint}. In this case, the default checkpoint frequency
4053 (at each 10th record) is assumed.
4054
4055 @node warnings
4056 @section Controlling Warning Messages
4057
4058 Sometimes, while performing the requested task, @GNUTAR{} notices
4059 some conditions that are not exactly errors, but which the user
4060 should be aware of. When this happens, @command{tar} issues a
4061 @dfn{warning message} describing the condition. Warning messages
4062 are output to the standard error and they do not affect the exit
4063 code of @command{tar} command.
4064
4065 @xopindex{warning, explained}
4066 @GNUTAR{} allows the user to suppress some or all of its warning
4067 messages:
4068
4069 @table @option
4070 @item --warning=@var{keyword}
4071 Control display of the warning messages identified by @var{keyword}.
4072 If @var{keyword} starts with the prefix @samp{no-}, such messages are
4073 suppressed. Otherwise, they are enabled.
4074
4075 Multiple @option{--warning} messages accumulate.
4076
4077 The tables below list allowed values for @var{keyword} along with the
4078 warning messages they control.
4079 @end table
4080
4081 @subheading Keywords controlling @command{tar} operation
4082 @table @asis
4083 @kwindex all
4084 @item all
4085 Enable all warning messages. This is the default.
4086 @kwindex none
4087 @item none
4088 Disable all warning messages.
4089 @kwindex filename-with-nuls
4090 @cindex @samp{file name read contains nul character}, warning message
4091 @item filename-with-nuls
4092 @samp{%s: file name read contains nul character}
4093 @kwindex alone-zero-block
4094 @cindex @samp{A lone zero block at}, warning message
4095 @item alone-zero-block
4096 @samp{A lone zero block at %s}
4097 @end table
4098
4099 @subheading Keywords applicable for @command{tar --create}
4100 @table @asis
4101 @kwindex cachedir
4102 @cindex @samp{contains a cache directory tag}, warning message
4103 @item cachedir
4104 @samp{%s: contains a cache directory tag %s; %s}
4105 @kwindex file-shrank
4106 @cindex @samp{File shrank by %s bytes}, warning message
4107 @item file-shrank
4108 @samp{%s: File shrank by %s bytes; padding with zeros}
4109 @kwindex xdev
4110 @cindex @samp{file is on a different filesystem}, warning message
4111 @item xdev
4112 @samp{%s: file is on a different filesystem; not dumped}
4113 @kwindex file-ignored
4114 @cindex @samp{Unknown file type; file ignored}, warning message
4115 @cindex @samp{socket ignored}, warning message
4116 @cindex @samp{door ignored}, warning message
4117 @item file-ignored
4118 @samp{%s: Unknown file type; file ignored}
4119 @*@samp{%s: socket ignored}
4120 @*@samp{%s: door ignored}
4121 @kwindex file-unchanged
4122 @cindex @samp{file is unchanged; not dumped}, warning message
4123 @item file-unchanged
4124 @samp{%s: file is unchanged; not dumped}
4125 @kwindex ignore-archive
4126 @cindex @samp{file is the archive; not dumped}, warning message
4127 @kwindex ignore-archive
4128 @cindex @samp{file is the archive; not dumped}, warning message
4129 @item ignore-archive
4130 @samp{%s: file is the archive; not dumped}
4131 @kwindex file-removed
4132 @cindex @samp{File removed before we read it}, warning message
4133 @item file-removed
4134 @samp{%s: File removed before we read it}
4135 @kwindex file-changed
4136 @cindex @samp{file changed as we read it}, warning message
4137 @item file-changed
4138 @samp{%s: file changed as we read it}
4139 @end table
4140
4141 @subheading Keywords applicable for @command{tar --extract}
4142 @table @asis
4143 @kwindex timestamp
4144 @cindex @samp{implausibly old time stamp %s}, warning message
4145 @cindex @samp{time stamp %s is %s s in the future}, warning message
4146 @item timestamp
4147 @samp{%s: implausibly old time stamp %s}
4148 @*@samp{%s: time stamp %s is %s s in the future}
4149 @kwindex contiguous-cast
4150 @cindex @samp{Extracting contiguous files as regular files}, warning message
4151 @item contiguous-cast
4152 @samp{Extracting contiguous files as regular files}
4153 @kwindex symlink-cast
4154 @cindex @samp{Attempting extraction of symbolic links as hard links}, warning message
4155 @item symlink-cast
4156 @samp{Attempting extraction of symbolic links as hard links}
4157 @kwindex unknown-cast
4158 @cindex @samp{Unknown file type `%c', extracted as normal file}, warning message
4159 @item unknown-cast
4160 @samp{%s: Unknown file type `%c', extracted as normal file}
4161 @kwindex ignore-newer
4162 @cindex @samp{Current %s is newer or same age}, warning message
4163 @item ignore-newer
4164 @samp{Current %s is newer or same age}
4165 @kwindex unknown-keyword
4166 @cindex @samp{Ignoring unknown extended header keyword `%s'}, warning message
4167 @item unknown-keyword
4168 @samp{Ignoring unknown extended header keyword `%s'}
4169 @kwindex decompress-program
4170 @item decompress-program
4171 Controls verbose messages describing execution failures when trying
4172 alternative decompressor programs (@pxref{alternative decompression
4173 programs}). This warning is disabled by default (unless
4174 @option{--verbose} is used). A common example of what you can get
4175 when using this warning is:
4176
4177 @smallexample
4178 $ @kbd{tar --warning=decompress-program -x -f archive.Z}
4179 tar (child): cannot run compress: No such file or directory
4180 tar (child): trying gzip
4181 @end smallexample
4182
4183 This means that @command{tar} first tried to decompress
4184 @file{archive.Z} using @command{compress}, and, when that
4185 failed, switched to @command{gzip}.
4186 @end table
4187
4188 @subheading Keywords controlling incremental extraction:
4189 @table @asis
4190 @kwindex rename-directory
4191 @cindex @samp{%s: Directory has been renamed from %s}, warning message
4192 @cindex @samp{%s: Directory has been renamed}, warning message
4193 @item rename-directory
4194 @samp{%s: Directory has been renamed from %s}
4195 @*@samp{%s: Directory has been renamed}
4196 @kwindex new-directory
4197 @cindex @samp{%s: Directory is new}, warning message
4198 @item new-directory
4199 @samp{%s: Directory is new}
4200 @kwindex xdev
4201 @cindex @samp{%s: directory is on a different device: not purging}, warning message
4202 @item xdev
4203 @samp{%s: directory is on a different device: not purging}
4204 @kwindex bad-dumpdir
4205 @cindex @samp{Malformed dumpdir: 'X' never used}, warning message
4206 @item bad-dumpdir
4207 @samp{Malformed dumpdir: 'X' never used}
4208 @end table
4209
4210 @node interactive
4211 @section Asking for Confirmation During Operations
4212 @cindex Interactive operation
4213
4214 Typically, @command{tar} carries out a command without stopping for
4215 further instructions. In some situations however, you may want to
4216 exclude some files and archive members from the operation (for instance
4217 if disk or storage space is tight). You can do this by excluding
4218 certain files automatically (@pxref{Choosing}), or by performing
4219 an operation interactively, using the @option{--interactive} (@option{-w}) option.
4220 @command{tar} also accepts @option{--confirmation} for this option.
4221
4222 @opindex interactive
4223 When the @option{--interactive} (@option{-w}) option is specified, before
4224 reading, writing, or deleting files, @command{tar} first prints a message
4225 for each such file, telling what operation it intends to take, then asks
4226 for confirmation on the terminal. The actions which require
4227 confirmation include adding a file to the archive, extracting a file
4228 from the archive, deleting a file from the archive, and deleting a file
4229 from disk. To confirm the action, you must type a line of input
4230 beginning with @samp{y}. If your input line begins with anything other
4231 than @samp{y}, @command{tar} skips that file.
4232
4233 If @command{tar} is reading the archive from the standard input,
4234 @command{tar} opens the file @file{/dev/tty} to support the interactive
4235 communications.
4236
4237 Verbose output is normally sent to standard output, separate from
4238 other error messages. However, if the archive is produced directly
4239 on standard output, then verbose output is mixed with errors on
4240 @code{stderr}. Producing the archive on standard output may be used
4241 as a way to avoid using disk space, when the archive is soon to be
4242 consumed by another process reading it, say. Some people felt the need
4243 of producing an archive on stdout, still willing to segregate between
4244 verbose output and error output. A possible approach would be using a
4245 named pipe to receive the archive, and having the consumer process to
4246 read from that named pipe. This has the advantage of letting standard
4247 output free to receive verbose output, all separate from errors.
4248
4249 @node operations
4250 @chapter @GNUTAR{} Operations
4251
4252 @menu
4253 * Basic tar::
4254 * Advanced tar::
4255 * create options::
4256 * extract options::
4257 * backup::
4258 * Applications::
4259 * looking ahead::
4260 @end menu
4261
4262 @node Basic tar
4263 @section Basic @GNUTAR{} Operations
4264
4265 The basic @command{tar} operations, @option{--create} (@option{-c}),
4266 @option{--list} (@option{-t}) and @option{--extract} (@option{--get},
4267 @option{-x}), are currently presented and described in the tutorial
4268 chapter of this manual. This section provides some complementary notes
4269 for these operations.
4270
4271 @table @option
4272 @xopindex{create, complementary notes}
4273 @item --create
4274 @itemx -c
4275
4276 Creating an empty archive would have some kind of elegance. One can
4277 initialize an empty archive and later use @option{--append}
4278 (@option{-r}) for adding all members. Some applications would not
4279 welcome making an exception in the way of adding the first archive
4280 member. On the other hand, many people reported that it is
4281 dangerously too easy for @command{tar} to destroy a magnetic tape with
4282 an empty archive@footnote{This is well described in @cite{Unix-haters
4283 Handbook}, by Simson Garfinkel, Daniel Weise & Steven Strassmann, IDG
4284 Books, ISBN 1-56884-203-1.}. The two most common errors are:
4285
4286 @enumerate
4287 @item
4288 Mistakingly using @code{create} instead of @code{extract}, when the
4289 intent was to extract the full contents of an archive. This error
4290 is likely: keys @kbd{c} and @kbd{x} are right next to each other on
4291 the QWERTY keyboard. Instead of being unpacked, the archive then
4292 gets wholly destroyed. When users speak about @dfn{exploding} an
4293 archive, they usually mean something else :-).
4294
4295 @item
4296 Forgetting the argument to @code{file}, when the intent was to create
4297 an archive with a single file in it. This error is likely because a
4298 tired user can easily add the @kbd{f} key to the cluster of option
4299 letters, by the mere force of habit, without realizing the full
4300 consequence of doing so. The usual consequence is that the single
4301 file, which was meant to be saved, is rather destroyed.
4302 @end enumerate
4303
4304 So, recognizing the likelihood and the catastrophic nature of these
4305 errors, @GNUTAR{} now takes some distance from elegance, and
4306 cowardly refuses to create an archive when @option{--create} option is
4307 given, there are no arguments besides options, and
4308 @option{--files-from} (@option{-T}) option is @emph{not} used. To get
4309 around the cautiousness of @GNUTAR{} and nevertheless create an
4310 archive with nothing in it, one may still use, as the value for the
4311 @option{--files-from} option, a file with no names in it, as shown in
4312 the following commands:
4313
4314 @smallexample
4315 @kbd{tar --create --file=empty-archive.tar --files-from=/dev/null}
4316 @kbd{tar cfT empty-archive.tar /dev/null}
4317 @end smallexample
4318
4319 @xopindex{extract, complementary notes}
4320 @item --extract
4321 @itemx --get
4322 @itemx -x
4323
4324 A socket is stored, within a @GNUTAR{} archive, as a pipe.
4325
4326 @item @option{--list} (@option{-t})
4327
4328 @GNUTAR{} now shows dates as @samp{1996-08-30},
4329 while it used to show them as @samp{Aug 30 1996}. Preferably,
4330 people should get used to ISO 8601 dates. Local American dates should
4331 be made available again with full date localization support, once
4332 ready. In the meantime, programs not being localizable for dates
4333 should prefer international dates, that's really the way to go.
4334
4335 Look up @url{http://www.cl.cam.ac.uk/@/~mgk25/@/iso-time.html} if you
4336 are curious, it contains a detailed explanation of the ISO 8601 standard.
4337
4338 @end table
4339
4340 @node Advanced tar
4341 @section Advanced @GNUTAR{} Operations
4342
4343 Now that you have learned the basics of using @GNUTAR{}, you may want
4344 to learn about further ways in which @command{tar} can help you.
4345
4346 This chapter presents five, more advanced operations which you probably
4347 won't use on a daily basis, but which serve more specialized functions.
4348 We also explain the different styles of options and why you might want
4349 to use one or another, or a combination of them in your @command{tar}
4350 commands. Additionally, this chapter includes options which allow you to
4351 define the output from @command{tar} more carefully, and provide help and
4352 error correction in special circumstances.
4353
4354 @FIXME{check this after the chapter is actually revised to make sure
4355 it still introduces the info in the chapter correctly : ).}
4356
4357 @menu
4358 * Operations::
4359 * append::
4360 * update::
4361 * concatenate::
4362 * delete::
4363 * compare::
4364 @end menu
4365
4366 @node Operations
4367 @subsection The Five Advanced @command{tar} Operations
4368
4369 @cindex basic operations
4370 In the last chapter, you learned about the first three operations to
4371 @command{tar}. This chapter presents the remaining five operations to
4372 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
4373 @option{--delete}, and @option{--compare}.
4374
4375 You are not likely to use these operations as frequently as those
4376 covered in the last chapter; however, since they perform specialized
4377 functions, they are quite useful when you do need to use them. We
4378 will give examples using the same directory and files that you created
4379 in the last chapter. As you may recall, the directory is called
4380 @file{practice}, the files are @samp{jazz}, @samp{blues}, @samp{folk},
4381 and the two archive files you created are
4382 @samp{collection.tar} and @samp{music.tar}.
4383
4384 We will also use the archive files @samp{afiles.tar} and
4385 @samp{bfiles.tar}. The archive @samp{afiles.tar} contains the members @samp{apple},
4386 @samp{angst}, and @samp{aspic}; @samp{bfiles.tar} contains the members
4387 @samp{./birds}, @samp{baboon}, and @samp{./box}.
4388
4389 Unless we state otherwise, all practicing you do and examples you follow
4390 in this chapter will take place in the @file{practice} directory that
4391 you created in the previous chapter; see @ref{prepare for examples}.
4392 (Below in this section, we will remind you of the state of the examples
4393 where the last chapter left them.)
4394
4395 The five operations that we will cover in this chapter are:
4396
4397 @table @option
4398 @item --append
4399 @itemx -r
4400 Add new entries to an archive that already exists.
4401 @item --update
4402 @itemx -u
4403 Add more recent copies of archive members to the end of an archive, if
4404 they exist.
4405 @item --concatenate
4406 @itemx --catenate
4407 @itemx -A
4408 Add one or more pre-existing archives to the end of another archive.
4409 @item --delete
4410 Delete items from an archive (does not work on tapes).
4411 @item --compare
4412 @itemx --diff
4413 @itemx -d
4414 Compare archive members to their counterparts in the file system.
4415 @end table
4416
4417 @node append
4418 @subsection How to Add Files to Existing Archives: @option{--append}
4419
4420 @cindex appending files to existing archive
4421 @opindex append
4422 If you want to add files to an existing archive, you don't need to
4423 create a new archive; you can use @option{--append} (@option{-r}).
4424 The archive must already exist in order to use @option{--append}. (A
4425 related operation is the @option{--update} operation; you can use this
4426 to add newer versions of archive members to an existing archive. To learn how to
4427 do this with @option{--update}, @pxref{update}.)
4428
4429 If you use @option{--append} to add a file that has the same name as an
4430 archive member to an archive containing that archive member, then the
4431 old member is not deleted. What does happen, however, is somewhat
4432 complex. @command{tar} @emph{allows} you to have infinite number of files
4433 with the same name. Some operations treat these same-named members no
4434 differently than any other set of archive members: for example, if you
4435 view an archive with @option{--list} (@option{-t}), you will see all
4436 of those members listed, with their data modification times, owners, etc.
4437
4438 Other operations don't deal with these members as perfectly as you might
4439 prefer; if you were to use @option{--extract} to extract the archive,
4440 only the most recently added copy of a member with the same name as
4441 other members would end up in the working directory. This is because
4442 @option{--extract} extracts an archive in the order the members appeared
4443 in the archive; the most recently archived members will be extracted
4444 last. Additionally, an extracted member will @emph{replace} a file of
4445 the same name which existed in the directory already, and @command{tar}
4446 will not prompt you about this@footnote{Unless you give it
4447 @option{--keep-old-files} option, or the disk copy is newer than
4448 the one in the archive and you invoke @command{tar} with
4449 @option{--keep-newer-files} option.}. Thus, only the most recently archived
4450 member will end up being extracted, as it will replace the one
4451 extracted before it, and so on.
4452
4453 @cindex extracting @var{n}th copy of the file
4454 @xopindex{occurrence, described}
4455 There exists a special option that allows you to get around this
4456 behavior and extract (or list) only a particular copy of the file.
4457 This is @option{--occurrence} option. If you run @command{tar} with
4458 this option, it will extract only the first copy of the file. You
4459 may also give this option an argument specifying the number of
4460 copy to be extracted. Thus, for example if the archive
4461 @file{archive.tar} contained three copies of file @file{myfile}, then
4462 the command
4463
4464 @smallexample
4465 tar --extract --file archive.tar --occurrence=2 myfile
4466 @end smallexample
4467
4468 @noindent
4469 would extract only the second copy. @xref{Option
4470 Summary,---occurrence}, for the description of @option{--occurrence}
4471 option.
4472
4473 @FIXME{ hag -- you might want to incorporate some of the above into the
4474 MMwtSN node; not sure. i didn't know how to make it simpler...
4475
4476 There are a few ways to get around this. Xref to Multiple Members
4477 with the Same Name, maybe.}
4478
4479 @cindex Members, replacing with other members
4480 @cindex Replacing members with other members
4481 @xopindex{delete, using before --append}
4482 If you want to replace an archive member, use @option{--delete} to
4483 delete the member you want to remove from the archive, and then use
4484 @option{--append} to add the member you want to be in the archive. Note
4485 that you can not change the order of the archive; the most recently
4486 added member will still appear last. In this sense, you cannot truly
4487 ``replace'' one member with another. (Replacing one member with another
4488 will not work on certain types of media, such as tapes; see @ref{delete}
4489 and @ref{Media}, for more information.)
4490
4491 @menu
4492 * appending files:: Appending Files to an Archive
4493 * multiple::
4494 @end menu
4495
4496 @node appending files
4497 @subsubsection Appending Files to an Archive
4498 @cindex Adding files to an Archive
4499 @cindex Appending files to an Archive
4500 @cindex Archives, Appending files to
4501 @opindex append
4502
4503 The simplest way to add a file to an already existing archive is the
4504 @option{--append} (@option{-r}) operation, which writes specified
4505 files into the archive whether or not they are already among the
4506 archived files.
4507
4508 When you use @option{--append}, you @emph{must} specify file name
4509 arguments, as there is no default. If you specify a file that already
4510 exists in the archive, another copy of the file will be added to the
4511 end of the archive. As with other operations, the member names of the
4512 newly added files will be exactly the same as their names given on the
4513 command line. The @option{--verbose} (@option{-v}) option will print
4514 out the names of the files as they are written into the archive.
4515
4516 @option{--append} cannot be performed on some tape drives, unfortunately,
4517 due to deficiencies in the formats those tape drives use. The archive
4518 must be a valid @command{tar} archive, or else the results of using this
4519 operation will be unpredictable. @xref{Media}.
4520
4521 To demonstrate using @option{--append} to add a file to an archive,
4522 create a file called @file{rock} in the @file{practice} directory.
4523 Make sure you are in the @file{practice} directory. Then, run the
4524 following @command{tar} command to add @file{rock} to
4525 @file{collection.tar}:
4526
4527 @smallexample
4528 $ @kbd{tar --append --file=collection.tar rock}
4529 @end smallexample
4530
4531 @noindent
4532 If you now use the @option{--list} (@option{-t}) operation, you will see that
4533 @file{rock} has been added to the archive:
4534
4535 @smallexample
4536 $ @kbd{tar --list --file=collection.tar}
4537 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4538 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4539 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4540 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4541 @end smallexample
4542
4543 @node multiple
4544 @subsubsection Multiple Members with the Same Name
4545 @cindex members, multiple
4546 @cindex multiple members
4547
4548 You can use @option{--append} (@option{-r}) to add copies of files
4549 which have been updated since the archive was created. (However, we
4550 do not recommend doing this since there is another @command{tar}
4551 option called @option{--update}; @xref{update}, for more information.
4552 We describe this use of @option{--append} here for the sake of
4553 completeness.) When you extract the archive, the older version will
4554 be effectively lost. This works because files are extracted from an
4555 archive in the order in which they were archived. Thus, when the
4556 archive is extracted, a file archived later in time will replace a
4557 file of the same name which was archived earlier, even though the
4558 older version of the file will remain in the archive unless you delete
4559 all versions of the file.
4560
4561 Supposing you change the file @file{blues} and then append the changed
4562 version to @file{collection.tar}. As you saw above, the original
4563 @file{blues} is in the archive @file{collection.tar}. If you change the
4564 file and append the new version of the file to the archive, there will
4565 be two copies in the archive. When you extract the archive, the older
4566 version of the file will be extracted first, and then replaced by the
4567 newer version when it is extracted.
4568
4569 You can append the new, changed copy of the file @file{blues} to the
4570 archive in this way:
4571
4572 @smallexample
4573 $ @kbd{tar --append --verbose --file=collection.tar blues}
4574 blues
4575 @end smallexample
4576
4577 @noindent
4578 Because you specified the @option{--verbose} option, @command{tar} has
4579 printed the name of the file being appended as it was acted on. Now
4580 list the contents of the archive:
4581
4582 @smallexample
4583 $ @kbd{tar --list --verbose --file=collection.tar}
4584 -rw-r--r-- me user 28 1996-10-18 16:31 jazz
4585 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4586 -rw-r--r-- me user 20 1996-09-23 16:44 folk
4587 -rw-r--r-- me user 20 1996-09-23 16:44 rock
4588 -rw-r--r-- me user 58 1996-10-24 18:30 blues
4589 @end smallexample
4590
4591 @noindent
4592 The newest version of @file{blues} is now at the end of the archive
4593 (note the different creation dates and file sizes). If you extract
4594 the archive, the older version of the file @file{blues} will be
4595 replaced by the newer version. You can confirm this by extracting
4596 the archive and running @samp{ls} on the directory.
4597
4598 If you wish to extract the first occurrence of the file @file{blues}
4599 from the archive, use @option{--occurrence} option, as shown in
4600 the following example:
4601
4602 @smallexample
4603 $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
4604 -rw-r--r-- me user 21 1996-09-23 16:44 blues
4605 @end smallexample
4606
4607 @xref{Writing}, for more information on @option{--extract} and
4608 see @ref{Option Summary, --occurrence}, for a description of
4609 @option{--occurrence} option.
4610
4611 @node update
4612 @subsection Updating an Archive
4613 @cindex Updating an archive
4614 @opindex update
4615
4616 In the previous section, you learned how to use @option{--append} to
4617 add a file to an existing archive. A related operation is
4618 @option{--update} (@option{-u}). The @option{--update} operation
4619 updates a @command{tar} archive by comparing the date of the specified
4620 archive members against the date of the file with the same name. If
4621 the file has been modified more recently than the archive member, then
4622 the newer version of the file is added to the archive (as with
4623 @option{--append}).
4624
4625 Unfortunately, you cannot use @option{--update} with magnetic tape drives.
4626 The operation will fail.
4627
4628 @FIXME{other examples of media on which --update will fail? need to ask
4629 charles and/or mib/thomas/dave shevett..}
4630
4631 Both @option{--update} and @option{--append} work by adding to the end
4632 of the archive. When you extract a file from the archive, only the
4633 version stored last will wind up in the file system, unless you use
4634 the @option{--backup} option. @xref{multiple}, for a detailed discussion.
4635
4636 @menu
4637 * how to update::
4638 @end menu
4639
4640 @node how to update
4641 @subsubsection How to Update an Archive Using @option{--update}
4642 @opindex update
4643
4644 You must use file name arguments with the @option{--update}
4645 (@option{-u}) operation. If you don't specify any files,
4646 @command{tar} won't act on any files and won't tell you that it didn't
4647 do anything (which may end up confusing you).
4648
4649 @c note: the above parenthetical added because in fact, this
4650 @c behavior just confused the author. :-)
4651
4652 To see the @option{--update} option at work, create a new file,
4653 @file{classical}, in your practice directory, and some extra text to the
4654 file @file{blues}, using any text editor. Then invoke @command{tar} with
4655 the @samp{update} operation and the @option{--verbose} (@option{-v})
4656 option specified, using the names of all the files in the @file{practice}
4657 directory as file name arguments:
4658
4659 @smallexample
4660 $ @kbd{tar --update -v -f collection.tar blues folk rock classical}
4661 blues
4662 classical
4663 $
4664 @end smallexample
4665
4666 @noindent
4667 Because we have specified verbose mode, @command{tar} prints out the names
4668 of the files it is working on, which in this case are the names of the
4669 files that needed to be updated. If you run @samp{tar --list} and look
4670 at the archive, you will see @file{blues} and @file{classical} at its
4671 end. There will be a total of two versions of the member @samp{blues};
4672 the one at the end will be newer and larger, since you added text before
4673 updating it.
4674
4675 The reason @command{tar} does not overwrite the older file when updating
4676 it is because writing to the middle of a section of tape is a difficult
4677 process. Tapes are not designed to go backward. @xref{Media}, for more
4678 information about tapes.
4679
4680 @option{--update} (@option{-u}) is not suitable for performing backups for two
4681 reasons: it does not change directory content entries, and it
4682 lengthens the archive every time it is used. The @GNUTAR{}
4683 options intended specifically for backups are more
4684 efficient. If you need to run backups, please consult @ref{Backups}.
4685
4686 @node concatenate
4687 @subsection Combining Archives with @option{--concatenate}
4688
4689 @cindex Adding archives to an archive
4690 @cindex Concatenating Archives
4691 @opindex concatenate
4692 @opindex catenate
4693 @c @cindex @option{-A} described
4694 Sometimes it may be convenient to add a second archive onto the end of
4695 an archive rather than adding individual files to the archive. To add
4696 one or more archives to the end of another archive, you should use the
4697 @option{--concatenate} (@option{--catenate}, @option{-A}) operation.
4698
4699 To use @option{--concatenate}, give the first archive with
4700 @option{--file} option and name the rest of archives to be
4701 concatenated on the command line. The members, and their member
4702 names, will be copied verbatim from those archives to the first
4703 one@footnote{This can cause multiple members to have the same name. For
4704 information on how this affects reading the archive, see @ref{multiple}.}.
4705 The new, concatenated archive will be called by the same name as the
4706 one given with the @option{--file} option. As usual, if you omit
4707 @option{--file}, @command{tar} will use the value of the environment
4708 variable @env{TAPE}, or, if this has not been set, the default archive name.
4709
4710 @FIXME{There is no way to specify a new name...}
4711
4712 To demonstrate how @option{--concatenate} works, create two small archives
4713 called @file{bluesrock.tar} and @file{folkjazz.tar}, using the relevant
4714 files from @file{practice}:
4715
4716 @smallexample
4717 $ @kbd{tar -cvf bluesrock.tar blues rock}
4718 blues
4719 rock
4720 $ @kbd{tar -cvf folkjazz.tar folk jazz}
4721 folk
4722 jazz
4723 @end smallexample
4724
4725 @noindent
4726 If you like, You can run @samp{tar --list} to make sure the archives
4727 contain what they are supposed to:
4728
4729 @smallexample
4730 $ @kbd{tar -tvf bluesrock.tar}
4731 -rw-r--r-- melissa user 105 1997-01-21 19:42 blues
4732 -rw-r--r-- melissa user 33 1997-01-20 15:34 rock
4733 $ @kbd{tar -tvf jazzfolk.tar}
4734 -rw-r--r-- melissa user 20 1996-09-23 16:44 folk
4735 -rw-r--r-- melissa user 65 1997-01-30 14:15 jazz
4736 @end smallexample
4737
4738 We can concatenate these two archives with @command{tar}:
4739
4740 @smallexample
4741 $ @kbd{cd ..}
4742 $ @kbd{tar --concatenate --file=bluesrock.tar jazzfolk.tar}
4743 @end smallexample
4744
4745 If you now list the contents of the @file{bluesrock.tar}, you will see
4746 that now it also contains the archive members of @file{jazzfolk.tar}:
4747
4748 @smallexample
4749 $ @kbd{tar --list --file=bluesrock.tar}
4750 blues
4751 rock
4752 folk
4753 jazz
4754 @end smallexample
4755
4756 When you use @option{--concatenate}, the source and target archives must
4757 already exist and must have been created using compatible format
4758 parameters. Notice, that @command{tar} does not check whether the
4759 archives it concatenates have compatible formats, it does not
4760 even check if the files are really tar archives.
4761
4762 Like @option{--append} (@option{-r}), this operation cannot be performed on some
4763 tape drives, due to deficiencies in the formats those tape drives use.
4764
4765 @cindex @code{concatenate} vs @command{cat}
4766 @cindex @command{cat} vs @code{concatenate}
4767 It may seem more intuitive to you to want or try to use @command{cat} to
4768 concatenate two archives instead of using the @option{--concatenate}
4769 operation; after all, @command{cat} is the utility for combining files.
4770
4771 However, @command{tar} archives incorporate an end-of-file marker which
4772 must be removed if the concatenated archives are to be read properly as
4773 one archive. @option{--concatenate} removes the end-of-archive marker
4774 from the target archive before each new archive is appended. If you use
4775 @command{cat} to combine the archives, the result will not be a valid
4776 @command{tar} format archive. If you need to retrieve files from an
4777 archive that was added to using the @command{cat} utility, use the
4778 @option{--ignore-zeros} (@option{-i}) option. @xref{Ignore Zeros}, for further
4779 information on dealing with archives improperly combined using the
4780 @command{cat} shell utility.
4781
4782 @node delete
4783 @subsection Removing Archive Members Using @option{--delete}
4784 @cindex Deleting files from an archive
4785 @cindex Removing files from an archive
4786
4787 @opindex delete
4788 You can remove members from an archive by using the @option{--delete}
4789 option. Specify the name of the archive with @option{--file}
4790 (@option{-f}) and then specify the names of the members to be deleted;
4791 if you list no member names, nothing will be deleted. The
4792 @option{--verbose} option will cause @command{tar} to print the names
4793 of the members as they are deleted. As with @option{--extract}, you
4794 must give the exact member names when using @samp{tar --delete}.
4795 @option{--delete} will remove all versions of the named file from the
4796 archive. The @option{--delete} operation can run very slowly.
4797
4798 Unlike other operations, @option{--delete} has no short form.
4799
4800 @cindex Tapes, using @option{--delete} and
4801 @cindex Deleting from tape archives
4802 This operation will rewrite the archive. You can only use
4803 @option{--delete} on an archive if the archive device allows you to
4804 write to any point on the media, such as a disk; because of this, it
4805 does not work on magnetic tapes. Do not try to delete an archive member
4806 from a magnetic tape; the action will not succeed, and you will be
4807 likely to scramble the archive and damage your tape. There is no safe
4808 way (except by completely re-writing the archive) to delete files from
4809 most kinds of magnetic tape. @xref{Media}.
4810
4811 To delete all versions of the file @file{blues} from the archive
4812 @file{collection.tar} in the @file{practice} directory, make sure you
4813 are in that directory, and then,
4814
4815 @smallexample
4816 $ @kbd{tar --list --file=collection.tar}
4817 blues
4818 folk
4819 jazz
4820 rock
4821 $ @kbd{tar --delete --file=collection.tar blues}
4822 $ @kbd{tar --list --file=collection.tar}
4823 folk
4824 jazz
4825 rock
4826 @end smallexample
4827
4828 @FIXME{Check if the above listing is actually produced after running
4829 all the examples on collection.tar.}
4830
4831 The @option{--delete} option has been reported to work properly when
4832 @command{tar} acts as a filter from @code{stdin} to @code{stdout}.
4833
4834 @node compare
4835 @subsection Comparing Archive Members with the File System
4836 @cindex Verifying the currency of an archive
4837
4838 @opindex compare
4839 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
4840 specified archive members against files with the same names, and then
4841 reports differences in file size, mode, owner, modification date and
4842 contents. You should @emph{only} specify archive member names, not file
4843 names. If you do not name any members, then @command{tar} will compare the
4844 entire archive. If a file is represented in the archive but does not
4845 exist in the file system, @command{tar} reports a difference.
4846
4847 You have to specify the record size of the archive when modifying an
4848 archive with a non-default record size.
4849
4850 @command{tar} ignores files in the file system that do not have
4851 corresponding members in the archive.
4852
4853 The following example compares the archive members @file{rock},
4854 @file{blues} and @file{funk} in the archive @file{bluesrock.tar} with
4855 files of the same name in the file system. (Note that there is no file,
4856 @file{funk}; @command{tar} will report an error message.)
4857
4858 @smallexample
4859 $ @kbd{tar --compare --file=bluesrock.tar rock blues funk}
4860 rock
4861 blues
4862 tar: funk not found in archive
4863 @end smallexample
4864
4865 The spirit behind the @option{--compare} (@option{--diff},
4866 @option{-d}) option is to check whether the archive represents the
4867 current state of files on disk, more than validating the integrity of
4868 the archive media. For this latter goal, see @ref{verify}.
4869
4870 @node create options
4871 @section Options Used by @option{--create}
4872
4873 @xopindex{create, additional options}
4874 The previous chapter described the basics of how to use
4875 @option{--create} (@option{-c}) to create an archive from a set of files.
4876 @xref{create}. This section described advanced options to be used with
4877 @option{--create}.
4878
4879 @menu
4880 * override:: Overriding File Metadata.
4881 * Ignore Failed Read::
4882 @end menu
4883
4884 @node override
4885 @subsection Overriding File Metadata
4886
4887 As described above, a @command{tar} archive keeps, for each member it contains,
4888 its @dfn{metadata}, such as modification time, mode and ownership of
4889 the file. @GNUTAR{} allows to replace these data with other values
4890 when adding files to the archive. The options described in this
4891 section affect creation of archives of any type. For POSIX archives,
4892 see also @ref{PAX keywords}, for additional ways of controlling
4893 metadata, stored in the archive.
4894
4895 @table @option
4896 @opindex mode
4897 @item --mode=@var{permissions}
4898
4899 When adding files to an archive, @command{tar} will use
4900 @var{permissions} for the archive members, rather than the permissions
4901 from the files. @var{permissions} can be specified either as an octal
4902 number or as symbolic permissions, like with
4903 @command{chmod} (@xref{File permissions, Permissions, File
4904 permissions, fileutils, @acronym{GNU} file utilities}. This reference
4905 also has useful information for those not being overly familiar with
4906 the UNIX permission system). Using latter syntax allows for
4907 more flexibility. For example, the value @samp{a+rw} adds read and write
4908 permissions for everybody, while retaining executable bits on directories
4909 or on any other file already marked as executable:
4910
4911 @smallexample
4912 $ @kbd{tar -c -f archive.tar --mode='a+rw' .}
4913 @end smallexample
4914
4915 @item --mtime=@var{date}
4916 @opindex mtime
4917
4918 When adding files to an archive, @command{tar} will use @var{date} as
4919 the modification time of members when creating archives, instead of
4920 their actual modification times. The argument @var{date} can be
4921 either a textual date representation in almost arbitrary format
4922 (@pxref{Date input formats}) or a name of an existing file, starting
4923 with @samp{/} or @samp{.}. In the latter case, the modification time
4924 of that file will be used.
4925
4926 The following example will set the modification date to 00:00:00,
4927 January 1, 1970:
4928
4929 @smallexample
4930 $ @kbd{tar -c -f archive.tar --mtime='1970-01-01' .}
4931 @end smallexample
4932
4933 @noindent
4934 When used with @option{--verbose} (@pxref{verbose tutorial}) @GNUTAR{}
4935 will try to convert the specified date back to its textual
4936 representation and compare it with the one given with
4937 @option{--mtime} options. If the two dates differ, @command{tar} will
4938 print a warning saying what date it will use. This is to help user
4939 ensure he is using the right date.
4940
4941 For example:
4942
4943 @smallexample
4944 $ @kbd{tar -c -f archive.tar -v --mtime=yesterday .}
4945 tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4946 13:06:29.152478
4947 @dots{}
4948 @end smallexample
4949
4950 @item --owner=@var{user}
4951 @opindex owner
4952
4953 Specifies that @command{tar} should use @var{user} as the owner of members
4954 when creating archives, instead of the user associated with the source
4955 file. The argument @var{user} can be either an existing user symbolic
4956 name, or a decimal numeric user @acronym{ID}.
4957
4958 There is no value indicating a missing number, and @samp{0} usually means
4959 @code{root}. Some people like to force @samp{0} as the value to offer in
4960 their distributions for the owner of files, because the @code{root} user is
4961 anonymous anyway, so that might as well be the owner of anonymous
4962 archives. For example:
4963
4964 @smallexample
4965 $ @kbd{tar -c -f archive.tar --owner=0 .}
4966 @end smallexample
4967
4968 @noindent
4969 or:
4970
4971 @smallexample
4972 $ @kbd{tar -c -f archive.tar --owner=root .}
4973 @end smallexample
4974
4975 @item --group=@var{group}
4976 @opindex group
4977
4978 Files added to the @command{tar} archive will have a group @acronym{ID} of @var{group},
4979 rather than the group from the source file. The argument @var{group}
4980 can be either an existing group symbolic name, or a decimal numeric group @acronym{ID}.
4981 @end table
4982
4983 @node Ignore Failed Read
4984 @subsection Ignore Fail Read
4985
4986 @table @option
4987 @item --ignore-failed-read
4988 @opindex ignore-failed-read
4989 Do not exit with nonzero on unreadable files or directories.
4990 @end table
4991
4992 @node extract options
4993 @section Options Used by @option{--extract}
4994 @cindex options for use with @option{--extract}
4995
4996 @xopindex{extract, additional options}
4997 The previous chapter showed how to use @option{--extract} to extract
4998 an archive into the file system. Various options cause @command{tar} to
4999 extract more information than just file contents, such as the owner,
5000 the permissions, the modification date, and so forth. This section
5001 presents options to be used with @option{--extract} when certain special
5002 considerations arise. You may review the information presented in
5003 @ref{extract} for more basic information about the
5004 @option{--extract} operation.
5005
5006 @menu
5007 * Reading:: Options to Help Read Archives
5008 * Writing:: Changing How @command{tar} Writes Files
5009 * Scarce:: Coping with Scarce Resources
5010 @end menu
5011
5012 @node Reading
5013 @subsection Options to Help Read Archives
5014 @cindex Options when reading archives
5015
5016 @cindex Reading incomplete records
5017 @cindex Records, incomplete
5018 @opindex read-full-records
5019 Normally, @command{tar} will request data in full record increments from
5020 an archive storage device. If the device cannot return a full record,
5021 @command{tar} will report an error. However, some devices do not always
5022 return full records, or do not require the last record of an archive to
5023 be padded out to the next record boundary. To keep reading until you
5024 obtain a full record, or to accept an incomplete record if it contains
5025 an end-of-archive marker, specify the @option{--read-full-records} (@option{-B}) option
5026 in conjunction with the @option{--extract} or @option{--list} operations.
5027 @xref{Blocking}.
5028
5029 The @option{--read-full-records} (@option{-B}) option is turned on by default when
5030 @command{tar} reads an archive from standard input, or from a remote
5031 machine. This is because on @acronym{BSD} Unix systems, attempting to read a
5032 pipe returns however much happens to be in the pipe, even if it is
5033 less than was requested. If this option were not enabled, @command{tar}
5034 would fail as soon as it read an incomplete record from the pipe.
5035
5036 If you're not sure of the blocking factor of an archive, you can
5037 read the archive by specifying @option{--read-full-records} (@option{-B}) and
5038 @option{--blocking-factor=@var{512-size}} (@option{-b
5039 @var{512-size}}), using a blocking factor larger than what the archive
5040 uses. This lets you avoid having to determine the blocking factor
5041 of an archive. @xref{Blocking Factor}.
5042
5043 @menu
5044 * read full records::
5045 * Ignore Zeros::
5046 @end menu
5047
5048 @node read full records
5049 @unnumberedsubsubsec Reading Full Records
5050
5051 @FIXME{need sentence or so of intro here}
5052
5053 @table @option
5054 @opindex read-full-records
5055 @item --read-full-records
5056 @item -B
5057 Use in conjunction with @option{--extract} (@option{--get},
5058 @option{-x}) to read an archive which contains incomplete records, or
5059 one which has a blocking factor less than the one specified.
5060 @end table
5061
5062 @node Ignore Zeros
5063 @unnumberedsubsubsec Ignoring Blocks of Zeros
5064
5065 @cindex End-of-archive blocks, ignoring
5066 @cindex Ignoring end-of-archive blocks
5067 @opindex ignore-zeros
5068 Normally, @command{tar} stops reading when it encounters a block of zeros
5069 between file entries (which usually indicates the end of the archive).
5070 @option{--ignore-zeros} (@option{-i}) allows @command{tar} to
5071 completely read an archive which contains a block of zeros before the
5072 end (i.e., a damaged archive, or one that was created by concatenating
5073 several archives together).
5074
5075 The @option{--ignore-zeros} (@option{-i}) option is turned off by default because many
5076 versions of @command{tar} write garbage after the end-of-archive entry,
5077 since that part of the media is never supposed to be read. @GNUTAR{}
5078 does not write after the end of an archive, but seeks to
5079 maintain compatibility among archiving utilities.
5080
5081 @table @option
5082 @item --ignore-zeros
5083 @itemx -i
5084 To ignore blocks of zeros (i.e., end-of-archive entries) which may be
5085 encountered while reading an archive. Use in conjunction with
5086 @option{--extract} or @option{--list}.
5087 @end table
5088
5089 @node Writing
5090 @subsection Changing How @command{tar} Writes Files
5091 @UNREVISED
5092
5093 @FIXME{Introductory paragraph}
5094
5095 @menu
5096 * Dealing with Old Files::
5097 * Overwrite Old Files::
5098 * Keep Old Files::
5099 * Keep Newer Files::
5100 * Unlink First::
5101 * Recursive Unlink::
5102 * Data Modification Times::
5103 * Setting Access Permissions::
5104 * Directory Modification Times and Permissions::
5105 * Writing to Standard Output::
5106 * Writing to an External Program::
5107 * remove files::
5108 @end menu
5109
5110 @node Dealing with Old Files
5111 @unnumberedsubsubsec Options Controlling the Overwriting of Existing Files
5112
5113 @xopindex{overwrite-dir, introduced}
5114 When extracting files, if @command{tar} discovers that the extracted
5115 file already exists, it normally replaces the file by removing it before
5116 extracting it, to prevent confusion in the presence of hard or symbolic
5117 links. (If the existing file is a symbolic link, it is removed, not
5118 followed.) However, if a directory cannot be removed because it is
5119 nonempty, @command{tar} normally overwrites its metadata (ownership,
5120 permission, etc.). The @option{--overwrite-dir} option enables this
5121 default behavior. To be more cautious and preserve the metadata of
5122 such a directory, use the @option{--no-overwrite-dir} option.
5123
5124 @cindex Overwriting old files, prevention
5125 @xopindex{keep-old-files, introduced}
5126 To be even more cautious and prevent existing files from being replaced, use
5127 the @option{--keep-old-files} (@option{-k}) option. It causes @command{tar} to refuse
5128 to replace or update a file that already exists, i.e., a file with the
5129 same name as an archive member prevents extraction of that archive
5130 member. Instead, it reports an error.
5131
5132 @xopindex{overwrite, introduced}
5133 To be more aggressive about altering existing files, use the
5134 @option{--overwrite} option. It causes @command{tar} to overwrite
5135 existing files and to follow existing symbolic links when extracting.
5136
5137 @cindex Protecting old files
5138 Some people argue that @GNUTAR{} should not hesitate
5139 to overwrite files with other files when extracting. When extracting
5140 a @command{tar} archive, they expect to see a faithful copy of the
5141 state of the file system when the archive was created. It is debatable
5142 that this would always be a proper behavior. For example, suppose one
5143 has an archive in which @file{usr/local} is a link to
5144 @file{usr/local2}. Since then, maybe the site removed the link and
5145 renamed the whole hierarchy from @file{/usr/local2} to
5146 @file{/usr/local}. Such things happen all the time. I guess it would
5147 not be welcome at all that @GNUTAR{} removes the
5148 whole hierarchy just to make room for the link to be reinstated
5149 (unless it @emph{also} simultaneously restores the full
5150 @file{/usr/local2}, of course!) @GNUTAR{} is indeed
5151 able to remove a whole hierarchy to reestablish a symbolic link, for
5152 example, but @emph{only if} @option{--recursive-unlink} is specified
5153 to allow this behavior. In any case, single files are silently
5154 removed.
5155
5156 @xopindex{unlink-first, introduced}
5157 Finally, the @option{--unlink-first} (@option{-U}) option can improve performance in
5158 some cases by causing @command{tar} to remove files unconditionally
5159 before extracting them.
5160
5161 @node Overwrite Old Files
5162 @unnumberedsubsubsec Overwrite Old Files
5163
5164 @table @option
5165 @opindex overwrite
5166 @item --overwrite
5167 Overwrite existing files and directory metadata when extracting files
5168 from an archive.
5169
5170 This causes @command{tar} to write extracted files into the file system without
5171 regard to the files already on the system; i.e., files with the same
5172 names as archive members are overwritten when the archive is extracted.
5173 It also causes @command{tar} to extract the ownership, permissions,
5174 and time stamps onto any preexisting files or directories.
5175 If the name of a corresponding file name is a symbolic link, the file
5176 pointed to by the symbolic link will be overwritten instead of the
5177 symbolic link itself (if this is possible). Moreover, special devices,
5178 empty directories and even symbolic links are automatically removed if
5179 they are in the way of extraction.
5180
5181 Be careful when using the @option{--overwrite} option, particularly when
5182 combined with the @option{--absolute-names} (@option{-P}) option, as this combination
5183 can change the contents, ownership or permissions of any file on your
5184 system. Also, many systems do not take kindly to overwriting files that
5185 are currently being executed.
5186
5187 @opindex overwrite-dir
5188 @item --overwrite-dir
5189 Overwrite the metadata of directories when extracting files from an
5190 archive, but remove other files before extracting.
5191 @end table
5192
5193 @node Keep Old Files
5194 @unnumberedsubsubsec Keep Old Files
5195
5196 @table @option
5197 @opindex keep-old-files
5198 @item --keep-old-files
5199 @itemx -k
5200 Do not replace existing files from archive. The
5201 @option{--keep-old-files} (@option{-k}) option prevents @command{tar}
5202 from replacing existing files with files with the same name from the
5203 archive. The @option{--keep-old-files} option is meaningless with
5204 @option{--list} (@option{-t}). Prevents @command{tar} from replacing
5205 files in the file system during extraction.
5206 @end table
5207
5208 @node Keep Newer Files
5209 @unnumberedsubsubsec Keep Newer Files
5210
5211 @table @option
5212 @opindex keep-newer-files
5213 @item --keep-newer-files
5214 Do not replace existing files that are newer than their archive
5215 copies. This option is meaningless with @option{--list} (@option{-t}).
5216 @end table
5217
5218 @node Unlink First
5219 @unnumberedsubsubsec Unlink First
5220
5221 @table @option
5222 @opindex unlink-first
5223 @item --unlink-first
5224 @itemx -U
5225 Remove files before extracting over them.
5226 This can make @command{tar} run a bit faster if you know in advance
5227 that the extracted files all need to be removed. Normally this option
5228 slows @command{tar} down slightly, so it is disabled by default.
5229 @end table
5230
5231 @node Recursive Unlink
5232 @unnumberedsubsubsec Recursive Unlink
5233
5234 @table @option
5235 @opindex recursive-unlink
5236 @item --recursive-unlink
5237 When this option is specified, try removing files and directory hierarchies
5238 before extracting over them. @emph{This is a dangerous option!}
5239 @end table
5240
5241 If you specify the @option{--recursive-unlink} option,
5242 @command{tar} removes @emph{anything} that keeps you from extracting a file
5243 as far as current permissions will allow it. This could include removal
5244 of the contents of a full directory hierarchy.
5245
5246 @node Data Modification Times
5247 @unnumberedsubsubsec Setting Data Modification Times
5248
5249 @cindex Data modification times of extracted files
5250 @cindex Modification times of extracted files
5251 Normally, @command{tar} sets the data modification times of extracted
5252 files to the corresponding times recorded for the files in the archive, but
5253 limits the permissions of extracted files by the current @code{umask}
5254 setting.
5255
5256 To set the data modification times of extracted files to the time when
5257 the files were extracted, use the @option{--touch} (@option{-m}) option in
5258 conjunction with @option{--extract} (@option{--get}, @option{-x}).
5259
5260 @table @option
5261 @opindex touch
5262 @item --touch
5263 @itemx -m
5264 Sets the data modification time of extracted archive members to the time
5265 they were extracted, not the time recorded for them in the archive.
5266 Use in conjunction with @option{--extract} (@option{--get}, @option{-x}).
5267 @end table
5268
5269 @node Setting Access Permissions
5270 @unnumberedsubsubsec Setting Access Permissions
5271
5272 @cindex Permissions of extracted files
5273 @cindex Modes of extracted files
5274 To set the modes (access permissions) of extracted files to those
5275 recorded for those files in the archive, use @option{--same-permissions}
5276 in conjunction with the @option{--extract} (@option{--get},
5277 @option{-x}) operation.
5278
5279 @table @option
5280 @opindex preserve-permissions
5281 @opindex same-permissions
5282 @item --preserve-permissions
5283 @itemx --same-permissions
5284 @c @itemx --ignore-umask
5285 @itemx -p
5286 Set modes of extracted archive members to those recorded in the
5287 archive, instead of current umask settings. Use in conjunction with
5288 @option{--extract} (@option{--get}, @option{-x}).
5289 @end table
5290
5291 @node Directory Modification Times and Permissions
5292 @unnumberedsubsubsec Directory Modification Times and Permissions
5293
5294 After successfully extracting a file member, @GNUTAR{} normally
5295 restores its permissions and modification times, as described in the
5296 previous sections. This cannot be done for directories, because
5297 after extracting a directory @command{tar} will almost certainly
5298 extract files into that directory and this will cause the directory
5299 modification time to be updated. Moreover, restoring that directory
5300 permissions may not permit file creation within it. Thus, restoring
5301 directory permissions and modification times must be delayed at least
5302 until all files have been extracted into that directory. @GNUTAR{}
5303 restores directories using the following approach.
5304
5305 The extracted directories are created with the mode specified in the
5306 archive, as modified by the umask of the user, which gives sufficient
5307 permissions to allow file creation. The meta-information about the
5308 directory is recorded in the temporary list of directories. When
5309 preparing to extract next archive member, @GNUTAR{} checks if the
5310 directory prefix of this file contains the remembered directory. If
5311 it does not, the program assumes that all files have been extracted
5312 into that directory, restores its modification time and permissions
5313 and removes its entry from the internal list. This approach allows
5314 to correctly restore directory meta-information in the majority of
5315 cases, while keeping memory requirements sufficiently small. It is
5316 based on the fact, that most @command{tar} archives use the predefined
5317 order of members: first the directory, then all the files and
5318 subdirectories in that directory.
5319
5320 However, this is not always true. The most important exception are
5321 incremental archives (@pxref{Incremental Dumps}). The member order in
5322 an incremental archive is reversed: first all directory members are
5323 stored, followed by other (non-directory) members. So, when extracting
5324 from incremental archives, @GNUTAR{} alters the above procedure. It
5325 remembers all restored directories, and restores their meta-data
5326 only after the entire archive has been processed. Notice, that you do
5327 not need to specify any special options for that, as @GNUTAR{}
5328 automatically detects archives in incremental format.
5329
5330 There may be cases, when such processing is required for normal archives
5331 too. Consider the following example:
5332
5333 @smallexample
5334 @group
5335 $ @kbd{tar --no-recursion -cvf archive \
5336 foo foo/file1 bar bar/file foo/file2}
5337 foo/
5338 foo/file1
5339 bar/
5340 bar/file
5341 foo/file2
5342 @end group
5343 @end smallexample
5344
5345 During the normal operation, after encountering @file{bar}
5346 @GNUTAR{} will assume that all files from the directory @file{foo}
5347 were already extracted and will therefore restore its timestamp and
5348 permission bits. However, after extracting @file{foo/file2} the
5349 directory timestamp will be offset again.
5350
5351 To correctly restore directory meta-information in such cases, use
5352 the @option{--delay-directory-restore} command line option:
5353
5354 @table @option
5355 @opindex delay-directory-restore
5356 @item --delay-directory-restore
5357 Delays restoring of the modification times and permissions of extracted
5358 directories until the end of extraction. This way, correct
5359 meta-information is restored even if the archive has unusual member
5360 ordering.
5361
5362 @opindex no-delay-directory-restore
5363 @item --no-delay-directory-restore
5364 Cancel the effect of the previous @option{--delay-directory-restore}.
5365 Use this option if you have used @option{--delay-directory-restore} in
5366 @env{TAR_OPTIONS} variable (@pxref{TAR_OPTIONS}) and wish to
5367 temporarily disable it.
5368 @end table
5369
5370 @node Writing to Standard Output
5371 @unnumberedsubsubsec Writing to Standard Output
5372
5373 @cindex Writing extracted files to standard output
5374 @cindex Standard output, writing extracted files to
5375 To write the extracted files to the standard output, instead of
5376 creating the files on the file system, use @option{--to-stdout} (@option{-O}) in
5377 conjunction with @option{--extract} (@option{--get}, @option{-x}). This option is useful if you are
5378 extracting files to send them through a pipe, and do not need to
5379 preserve them in the file system. If you extract multiple members,
5380 they appear on standard output concatenated, in the order they are
5381 found in the archive.
5382
5383 @table @option
5384 @opindex to-stdout
5385 @item --to-stdout
5386 @itemx -O
5387 Writes files to the standard output. Use only in conjunction with
5388 @option{--extract} (@option{--get}, @option{-x}). When this option is
5389 used, instead of creating the files specified, @command{tar} writes
5390 the contents of the files extracted to its standard output. This may
5391 be useful if you are only extracting the files in order to send them
5392 through a pipe. This option is meaningless with @option{--list}
5393 (@option{-t}).
5394 @end table
5395
5396 This can be useful, for example, if you have a tar archive containing
5397 a big file and don't want to store the file on disk before processing
5398 it. You can use a command like this:
5399
5400 @smallexample
5401 tar -xOzf foo.tgz bigfile | process
5402 @end smallexample
5403
5404 or even like this if you want to process the concatenation of the files:
5405
5406 @smallexample
5407 tar -xOzf foo.tgz bigfile1 bigfile2 | process
5408 @end smallexample
5409
5410 However, @option{--to-command} may be more convenient for use with
5411 multiple files. See the next section.
5412
5413 @node Writing to an External Program
5414 @unnumberedsubsubsec Writing to an External Program
5415
5416 You can instruct @command{tar} to send the contents of each extracted
5417 file to the standard input of an external program:
5418
5419 @table @option
5420 @opindex to-command
5421 @item --to-command=@var{command}
5422 Extract files and pipe their contents to the standard input of
5423 @var{command}. When this option is used, instead of creating the
5424 files specified, @command{tar} invokes @var{command} and pipes the
5425 contents of the files to its standard output. The @var{command} may
5426 contain command line arguments. The program is executed via
5427 @code{sh -c}. Notice, that @var{command} is executed once for each regular file
5428 extracted. Non-regular files (directories, etc.) are ignored when this
5429 option is used.
5430 @end table
5431
5432 The command can obtain the information about the file it processes
5433 from the following environment variables:
5434
5435 @table @env
5436 @vrindex TAR_FILETYPE, to-command environment
5437 @item TAR_FILETYPE
5438 Type of the file. It is a single letter with the following meaning:
5439
5440 @multitable @columnfractions 0.10 0.90
5441 @item f @tab Regular file
5442 @item d @tab Directory
5443 @item l @tab Symbolic link
5444 @item h @tab Hard link
5445 @item b @tab Block device
5446 @item c @tab Character device
5447 @end multitable
5448
5449 Currently only regular files are supported.
5450
5451 @vrindex TAR_MODE, to-command environment
5452 @item TAR_MODE
5453 File mode, an octal number.
5454
5455 @vrindex TAR_FILENAME, to-command environment
5456 @item TAR_FILENAME
5457 The name of the file.
5458
5459 @vrindex TAR_REALNAME, to-command environment
5460 @item TAR_REALNAME
5461 Name of the file as stored in the archive.
5462
5463 @vrindex TAR_UNAME, to-command environment
5464 @item TAR_UNAME
5465 Name of the file owner.
5466
5467 @vrindex TAR_GNAME, to-command environment
5468 @item TAR_GNAME
5469 Name of the file owner group.
5470
5471 @vrindex TAR_ATIME, to-command environment
5472 @item TAR_ATIME
5473 Time of last access. It is a decimal number, representing seconds
5474 since the Epoch. If the archive provides times with nanosecond
5475 precision, the nanoseconds are appended to the timestamp after a
5476 decimal point.
5477
5478 @vrindex TAR_MTIME, to-command environment
5479 @item TAR_MTIME
5480 Time of last modification.
5481
5482 @vrindex TAR_CTIME, to-command environment
5483 @item TAR_CTIME
5484 Time of last status change.
5485
5486 @vrindex TAR_SIZE, to-command environment
5487 @item TAR_SIZE
5488 Size of the file.
5489
5490 @vrindex TAR_UID, to-command environment
5491 @item TAR_UID
5492 UID of the file owner.
5493
5494 @vrindex TAR_GID, to-command environment
5495 @item TAR_GID
5496 GID of the file owner.
5497 @end table
5498
5499 Additionally, the following variables contain information about
5500 tar mode and the archive being processed:
5501
5502 @table @env
5503 @vrindex TAR_VERSION, to-command environment
5504 @item TAR_VERSION
5505 @GNUTAR{} version number.
5506
5507 @vrindex TAR_ARCHIVE, to-command environment
5508 @item TAR_ARCHIVE
5509 The name of the archive @command{tar} is processing.
5510
5511 @vrindex TAR_BLOCKING_FACTOR, to-command environment
5512 @item TAR_BLOCKING_FACTOR
5513 Current blocking factor (@pxref{Blocking}).
5514
5515 @vrindex TAR_VOLUME, to-command environment
5516 @item TAR_VOLUME
5517 Ordinal number of the volume @command{tar} is processing.
5518
5519 @vrindex TAR_FORMAT, to-command environment
5520 @item TAR_FORMAT
5521 Format of the archive being processed. @xref{Formats}, for a complete
5522 list of archive format names.
5523 @end table
5524
5525 If @var{command} exits with a non-0 status, @command{tar} will print
5526 an error message similar to the following:
5527
5528 @smallexample
5529 tar: 2345: Child returned status 1
5530 @end smallexample
5531
5532 Here, @samp{2345} is the PID of the finished process.
5533
5534 If this behavior is not wanted, use @option{--ignore-command-error}:
5535
5536 @table @option
5537 @opindex ignore-command-error
5538 @item --ignore-command-error
5539 Ignore exit codes of subprocesses. Notice that if the program
5540 exits on signal or otherwise terminates abnormally, the error message
5541 will be printed even if this option is used.
5542
5543 @opindex no-ignore-command-error
5544 @item --no-ignore-command-error
5545 Cancel the effect of any previous @option{--ignore-command-error}
5546 option. This option is useful if you have set
5547 @option{--ignore-command-error} in @env{TAR_OPTIONS}
5548 (@pxref{TAR_OPTIONS}) and wish to temporarily cancel it.
5549 @end table
5550
5551 @node remove files
5552 @unnumberedsubsubsec Removing Files
5553
5554 @FIXME{The section is too terse. Something more to add? An example,
5555 maybe?}
5556
5557 @table @option
5558 @opindex remove-files
5559 @item --remove-files
5560 Remove files after adding them to the archive.
5561 @end table
5562
5563 @node Scarce
5564 @subsection Coping with Scarce Resources
5565 @UNREVISED
5566
5567 @cindex Small memory
5568 @cindex Running out of space
5569
5570 @menu
5571 * Starting File::
5572 * Same Order::
5573 @end menu
5574
5575 @node Starting File
5576 @unnumberedsubsubsec Starting File
5577
5578 @table @option
5579 @opindex starting-file
5580 @item --starting-file=@var{name}
5581 @itemx -K @var{name}
5582 Starts an operation in the middle of an archive. Use in conjunction
5583 with @option{--extract} (@option{--get}, @option{-x}) or @option{--list} (@option{-t}).
5584 @end table
5585
5586 @cindex Middle of the archive, starting in the
5587 If a previous attempt to extract files failed due to lack of disk
5588 space, you can use @option{--starting-file=@var{name}} (@option{-K
5589 @var{name}}) to start extracting only after member @var{name} of the
5590 archive. This assumes, of course, that there is now free space, or
5591 that you are now extracting into a different file system. (You could
5592 also choose to suspend @command{tar}, remove unnecessary files from
5593 the file system, and then resume the same @command{tar} operation.
5594 In this case, @option{--starting-file} is not necessary.) See also
5595 @ref{interactive}, and @ref{exclude}.
5596
5597 @node Same Order
5598 @unnumberedsubsubsec Same Order
5599
5600 @table @option
5601 @cindex Large lists of file names on small machines
5602 @opindex same-order
5603 @opindex preserve-order
5604 @item --same-order
5605 @itemx --preserve-order
5606 @itemx -s
5607 To process large lists of file names on machines with small amounts of
5608 memory. Use in conjunction with @option{--compare} (@option{--diff},
5609 @option{-d}), @option{--list} (@option{-t}) or @option{--extract}
5610 (@option{--get}, @option{-x}).
5611 @end table
5612
5613 The @option{--same-order} (@option{--preserve-order}, @option{-s}) option tells @command{tar} that the list of file
5614 names to be listed or extracted is sorted in the same order as the
5615 files in the archive. This allows a large list of names to be used,
5616 even on a small machine that would not otherwise be able to hold all
5617 the names in memory at the same time. Such a sorted list can easily be
5618 created by running @samp{tar -t} on the archive and editing its output.
5619
5620 This option is probably never needed on modern computer systems.
5621
5622 @node backup
5623 @section Backup options
5624
5625 @cindex backup options
5626
5627 @GNUTAR{} offers options for making backups of files
5628 before writing new versions. These options control the details of
5629 these backups. They may apply to the archive itself before it is
5630 created or rewritten, as well as individual extracted members. Other
5631 @acronym{GNU} programs (@command{cp}, @command{install}, @command{ln},
5632 and @command{mv}, for example) offer similar options.
5633
5634 Backup options may prove unexpectedly useful when extracting archives
5635 containing many members having identical name, or when extracting archives
5636 on systems having file name limitations, making different members appear
5637 as having similar names through the side-effect of name truncation.
5638 @FIXME{This is true only if we have a good scheme for truncated backup names,
5639 which I'm not sure at all: I suspect work is needed in this area.}
5640 When any existing file is backed up before being overwritten by extraction,
5641 then clashing files are automatically be renamed to be unique, and the
5642 true name is kept for only the last file of a series of clashing files.
5643 By using verbose mode, users may track exactly what happens.
5644
5645 At the detail level, some decisions are still experimental, and may
5646 change in the future, we are waiting comments from our users. So, please
5647 do not learn to depend blindly on the details of the backup features.
5648 For example, currently, directories themselves are never renamed through
5649 using these options, so, extracting a file over a directory still has
5650 good chances to fail. Also, backup options apply to created archives,
5651 not only to extracted members. For created archives, backups will not
5652 be attempted when the archive is a block or character device, or when it
5653 refers to a remote file.
5654
5655 For the sake of simplicity and efficiency, backups are made by renaming old
5656 files prior to creation or extraction, and not by copying. The original
5657 name is restored if the file creation fails. If a failure occurs after a
5658 partial extraction of a file, both the backup and the partially extracted
5659 file are kept.
5660
5661 @table @samp
5662 @item --backup[=@var{method}]
5663 @opindex backup
5664 @vindex VERSION_CONTROL
5665 @cindex backups
5666 Back up files that are about to be overwritten or removed.
5667 Without this option, the original versions are destroyed.
5668
5669 Use @var{method} to determine the type of backups made.
5670 If @var{method} is not specified, use the value of the @env{VERSION_CONTROL}
5671 environment variable. And if @env{VERSION_CONTROL} is not set,
5672 use the @samp{existing} method.
5673
5674 @vindex version-control @r{Emacs variable}
5675 This option corresponds to the Emacs variable @samp{version-control};
5676 the same values for @var{method} are accepted as in Emacs. This option
5677 also allows more descriptive names. The valid @var{method}s are:
5678
5679 @table @samp
5680 @item t
5681 @itemx numbered
5682 @cindex numbered @r{backup method}
5683 Always make numbered backups.
5684
5685 @item nil
5686 @itemx existing
5687 @cindex existing @r{backup method}
5688 Make numbered backups of files that already have them, simple backups
5689 of the others.
5690
5691 @item never
5692 @itemx simple
5693 @cindex simple @r{backup method}
5694 Always make simple backups.
5695
5696 @end table
5697
5698 @item --suffix=@var{suffix}
5699 @opindex suffix
5700 @cindex backup suffix
5701 @vindex SIMPLE_BACKUP_SUFFIX
5702 Append @var{suffix} to each backup file made with @option{--backup}. If this
5703 option is not specified, the value of the @env{SIMPLE_BACKUP_SUFFIX}
5704 environment variable is used. And if @env{SIMPLE_BACKUP_SUFFIX} is not
5705 set, the default is @samp{~}, just as in Emacs.
5706
5707 @end table
5708
5709 @node Applications
5710 @section Notable @command{tar} Usages
5711 @UNREVISED
5712
5713 @FIXME{Using Unix file linking capability to recreate directory
5714 structures---linking files into one subdirectory and then
5715 @command{tar}ring that directory.}
5716
5717 @FIXME{Nice hairy example using absolute-names, newer, etc.}
5718
5719 @findex uuencode
5720 You can easily use archive files to transport a group of files from
5721 one system to another: put all relevant files into an archive on one
5722 computer system, transfer the archive to another system, and extract
5723 the contents there. The basic transfer medium might be magnetic tape,
5724 Internet FTP, or even electronic mail (though you must encode the
5725 archive with @command{uuencode} in order to transport it properly by
5726 mail). Both machines do not have to use the same operating system, as
5727 long as they both support the @command{tar} program.
5728
5729 For example, here is how you might copy a directory's contents from
5730 one disk to another, while preserving the dates, modes, owners and
5731 link-structure of all the files therein. In this case, the transfer
5732 medium is a @dfn{pipe}:
5733
5734 @smallexample
5735 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)}
5736 @end smallexample
5737
5738 @noindent
5739 You can avoid subshells by using @option{-C} option:
5740
5741 @smallexample
5742 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xf -}
5743 @end smallexample
5744
5745 @noindent
5746 The command also works using long option forms:
5747
5748 @smallexample
5749 @group
5750 $ @kbd{(cd sourcedir; tar --create --file=- . ) \
5751 | (cd targetdir; tar --extract --file=-)}
5752 @end group
5753 @end smallexample
5754
5755 @noindent
5756 or
5757
5758 @smallexample
5759 @group
5760 $ @kbd{tar --directory sourcedir --create --file=- . \
5761 | tar --directory targetdir --extract --file=-}
5762 @end group
5763 @end smallexample
5764
5765 @noindent
5766 This is one of the easiest methods to transfer a @command{tar} archive.
5767
5768 @node looking ahead
5769 @section Looking Ahead: The Rest of this Manual
5770
5771 You have now seen how to use all eight of the operations available to
5772 @command{tar}, and a number of the possible options. The next chapter
5773 explains how to choose and change file and archive names, how to use
5774 files to store names of other files which you can then call as
5775 arguments to @command{tar} (this can help you save time if you expect to
5776 archive the same list of files a number of times), and so forth.
5777 @FIXME{in case it's not obvious, i'm making this up in some sense
5778 based on my limited memory of what the next chapter *really* does. i
5779 just wanted to flesh out this final section a little bit so i'd
5780 remember to stick it in here. :-)}
5781
5782 If there are too many files to conveniently list on the command line,
5783 you can list the names in a file, and @command{tar} will read that file.
5784 @xref{files}.
5785
5786 There are various ways of causing @command{tar} to skip over some files,
5787 and not archive them. @xref{Choosing}.
5788
5789 @node Backups
5790 @chapter Performing Backups and Restoring Files
5791 @cindex backups
5792
5793 @GNUTAR{} is distributed along with the scripts for performing backups
5794 and restores. Even if there is a good chance those scripts may be
5795 satisfying to you, they are not the only scripts or methods available for doing
5796 backups and restore. You may well create your own, or use more
5797 sophisticated packages dedicated to that purpose.
5798
5799 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
5800 Automatic Network Disk Archiver), a backup system developed by James
5801 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
5802 This is free software, and it is available from @uref{http://www.amanda.org}.
5803
5804 @FIXME{
5805
5806 Here is a possible plan for a future documentation about the backuping
5807 scripts which are provided within the @GNUTAR{}
5808 distribution.
5809
5810 @itemize @bullet
5811 @item dumps
5812 @itemize @minus
5813 @item what are dumps
5814 @item different levels of dumps
5815 @itemize +
5816 @item full dump = dump everything
5817 @item level 1, level 2 dumps etc
5818 A level @var{n} dump dumps everything changed since the last level
5819 @var{n}-1 dump (?)
5820 @end itemize
5821 @item how to use scripts for dumps (ie, the concept)
5822 @itemize +
5823 @item scripts to run after editing backup specs (details)
5824 @end itemize
5825 @item Backup Specs, what is it.
5826 @itemize +
5827 @item how to customize
5828 @item actual text of script [/sp/dump/backup-specs]
5829 @end itemize
5830 @item Problems
5831 @itemize +
5832 @item rsh doesn't work
5833 @item rtape isn't installed
5834 @item (others?)
5835 @end itemize
5836 @item the @option{--incremental} option of tar
5837 @item tapes
5838 @itemize +
5839 @item write protection
5840 @item types of media, different sizes and types, useful for different things
5841 @item files and tape marks
5842 one tape mark between files, two at end.
5843 @item positioning the tape
5844 MT writes two at end of write,
5845 backspaces over one when writing again.
5846 @end itemize
5847 @end itemize
5848 @end itemize
5849 }
5850
5851 This chapter documents both the provided shell scripts and @command{tar}
5852 options which are more specific to usage as a backup tool.
5853
5854 To @dfn{back up} a file system means to create archives that contain
5855 all the files in that file system. Those archives can then be used to
5856 restore any or all of those files (for instance if a disk crashes or a
5857 file is accidentally deleted). File system @dfn{backups} are also
5858 called @dfn{dumps}.
5859
5860 @menu
5861 * Full Dumps:: Using @command{tar} to Perform Full Dumps
5862 * Incremental Dumps:: Using @command{tar} to Perform Incremental Dumps
5863 * Backup Levels:: Levels of Backups
5864 * Backup Parameters:: Setting Parameters for Backups and Restoration
5865 * Scripted Backups:: Using the Backup Scripts
5866 * Scripted Restoration:: Using the Restore Script
5867 @end menu
5868
5869 @node Full Dumps
5870 @section Using @command{tar} to Perform Full Dumps
5871 @UNREVISED
5872
5873 @cindex full dumps
5874 @cindex dumps, full
5875
5876 @cindex corrupted archives
5877 Full dumps should only be made when no other people or programs
5878 are modifying files in the file system. If files are modified while
5879 @command{tar} is making the backup, they may not be stored properly in
5880 the archive, in which case you won't be able to restore them if you
5881 have to. (Files not being modified are written with no trouble, and do
5882 not corrupt the entire archive.)
5883
5884 You will want to use the @option{--label=@var{archive-label}}
5885 (@option{-V @var{archive-label}}) option to give the archive a
5886 volume label, so you can tell what this archive is even if the label
5887 falls off the tape, or anything like that.
5888
5889 Unless the file system you are dumping is guaranteed to fit on
5890 one volume, you will need to use the @option{--multi-volume} (@option{-M}) option.
5891 Make sure you have enough tapes on hand to complete the backup.
5892
5893 If you want to dump each file system separately you will need to use
5894 the @option{--one-file-system} option to prevent
5895 @command{tar} from crossing file system boundaries when storing
5896 (sub)directories.
5897
5898 The @option{--incremental} (@option{-G}) (@pxref{Incremental Dumps})
5899 option is not needed, since this is a complete copy of everything in
5900 the file system, and a full restore from this backup would only be
5901 done onto a completely
5902 empty disk.
5903
5904 Unless you are in a hurry, and trust the @command{tar} program (and your
5905 tapes), it is a good idea to use the @option{--verify} (@option{-W})
5906 option, to make sure your files really made it onto the dump properly.
5907 This will also detect cases where the file was modified while (or just
5908 after) it was being archived. Not all media (notably cartridge tapes)
5909 are capable of being verified, unfortunately.
5910
5911 @node Incremental Dumps
5912 @section Using @command{tar} to Perform Incremental Dumps
5913
5914 @dfn{Incremental backup} is a special form of @GNUTAR{} archive that
5915 stores additional metadata so that exact state of the file system
5916 can be restored when extracting the archive.
5917
5918 @GNUTAR{} currently offers two options for handling incremental
5919 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
5920 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
5921
5922 @xopindex{listed-incremental, described}
5923 The option @option{--listed-incremental} instructs tar to operate on
5924 an incremental archive with additional metadata stored in a standalone
5925 file, called a @dfn{snapshot file}. The purpose of this file is to help
5926 determine which files have been changed, added or deleted since the
5927 last backup, so that the next incremental backup will contain only
5928 modified files. The name of the snapshot file is given as an argument
5929 to the option:
5930
5931 @table @option
5932 @item --listed-incremental=@var{file}
5933 @itemx -g @var{file}
5934 Handle incremental backups with snapshot data in @var{file}.
5935 @end table
5936
5937 To create an incremental backup, you would use
5938 @option{--listed-incremental} together with @option{--create}
5939 (@pxref{create}). For example:
5940
5941 @smallexample
5942 $ @kbd{tar --create \
5943 --file=archive.1.tar \
5944 --listed-incremental=/var/log/usr.snar \
5945 /usr}
5946 @end smallexample
5947
5948 This will create in @file{archive.1.tar} an incremental backup of
5949 the @file{/usr} file system, storing additional metadata in the file
5950 @file{/var/log/usr.snar}. If this file does not exist, it will be
5951 created. The created archive will then be a @dfn{level 0 backup};
5952 please see the next section for more on backup levels.
5953
5954 Otherwise, if the file @file{/var/log/usr.snar} exists, it
5955 determines which files are modified. In this case only these files will be
5956 stored in the archive. Suppose, for example, that after running the
5957 above command, you delete file @file{/usr/doc/old} and create
5958 directory @file{/usr/local/db} with the following contents:
5959
5960 @smallexample
5961 $ @kbd{ls /usr/local/db}
5962 /usr/local/db/data
5963 /usr/local/db/index
5964 @end smallexample
5965
5966 Some time later you create another incremental backup. You will
5967 then see:
5968
5969 @smallexample
5970 $ @kbd{tar --create \
5971 --file=archive.2.tar \
5972 --listed-incremental=/var/log/usr.snar \
5973 /usr}
5974 tar: usr/local/db: Directory is new
5975 usr/local/db/
5976 usr/local/db/data
5977 usr/local/db/index
5978 @end smallexample
5979
5980 @noindent
5981 The created archive @file{archive.2.tar} will contain only these
5982 three members. This archive is called a @dfn{level 1 backup}. Notice
5983 that @file{/var/log/usr.snar} will be updated with the new data, so if
5984 you plan to create more @samp{level 1} backups, it is necessary to
5985 create a working copy of the snapshot file before running
5986 @command{tar}. The above example will then be modified as follows:
5987
5988 @smallexample
5989 $ @kbd{cp /var/log/usr.snar /var/log/usr.snar-1}
5990 $ @kbd{tar --create \
5991 --file=archive.2.tar \
5992 --listed-incremental=/var/log/usr.snar-1 \
5993 /usr}
5994 @end smallexample
5995
5996 @anchor{--level=0}
5997 @xopindex{level, described}
5998 You can force @samp{level 0} backups either by removing the snapshot
5999 file before running @command{tar}, or by supplying the
6000 @option{--level=0} option, e.g.:
6001
6002 @smallexample
6003 $ @kbd{tar --create \
6004 --file=archive.2.tar \
6005 --listed-incremental=/var/log/usr.snar-0 \
6006 --level=0 \
6007 /usr}
6008 @end smallexample
6009
6010 Incremental dumps depend crucially on time stamps, so the results are
6011 unreliable if you modify a file's time stamps during dumping (e.g.,
6012 with the @option{--atime-preserve=replace} option), or if you set the clock
6013 backwards.
6014
6015 @anchor{device numbers}
6016 @cindex Device numbers, using in incremental backups
6017 Metadata stored in snapshot files include device numbers, which,
6018 obviously are supposed to be non-volatile values. However, it turns
6019 out that @acronym{NFS} devices have undependable values when an automounter
6020 gets in the picture. This can lead to a great deal of spurious
6021 redumping in incremental dumps, so it is somewhat useless to compare
6022 two @acronym{NFS} devices numbers over time. The solution implemented
6023 currently is to consider all @acronym{NFS} devices as being equal
6024 when it comes to comparing directories; this is fairly gross, but
6025 there does not seem to be a better way to go.
6026
6027 Apart from using @acronym{NFS}, there are a number of cases where
6028 relying on device numbers can cause spurious redumping of unmodified
6029 files. For example, this occurs when archiving @acronym{LVM} snapshot
6030 volumes. To avoid this, use @option{--no-check-device} option:
6031
6032 @table @option
6033 @xopindex{no-check-device, described}
6034 @item --no-check-device
6035 Do not rely on device numbers when preparing a list of changed files
6036 for an incremental dump.
6037
6038 @xopindex{check-device, described}
6039 @item --check-device
6040 Use device numbers when preparing a list of changed files
6041 for an incremental dump. This is the default behavior. The purpose
6042 of this option is to undo the effect of the @option{--no-check-device}
6043 if it was given in @env{TAR_OPTIONS} environment variable
6044 (@pxref{TAR_OPTIONS}).
6045 @end table
6046
6047 There is also another way to cope with changing device numbers. It is
6048 described in detail in @ref{Fixing Snapshot Files}.
6049
6050 Note that incremental archives use @command{tar} extensions and may
6051 not be readable by non-@acronym{GNU} versions of the @command{tar} program.
6052
6053 @xopindex{listed-incremental, using with @option{--extract}}
6054 @xopindex{extract, using with @option{--listed-incremental}}
6055 To extract from the incremental dumps, use
6056 @option{--listed-incremental} together with @option{--extract}
6057 option (@pxref{extracting files}). In this case, @command{tar} does
6058 not need to access snapshot file, since all the data necessary for
6059 extraction are stored in the archive itself. So, when extracting, you
6060 can give whatever argument to @option{--listed-incremental}, the usual
6061 practice is to use @option{--listed-incremental=/dev/null}.
6062 Alternatively, you can use @option{--incremental}, which needs no
6063 arguments. In general, @option{--incremental} (@option{-G}) can be
6064 used as a shortcut for @option{--listed-incremental} when listing or
6065 extracting incremental backups (for more information regarding this
6066 option, @pxref{incremental-op}).
6067
6068 When extracting from the incremental backup @GNUTAR{} attempts to
6069 restore the exact state the file system had when the archive was
6070 created. In particular, it will @emph{delete} those files in the file
6071 system that did not exist in their directories when the archive was
6072 created. If you have created several levels of incremental files,
6073 then in order to restore the exact contents the file system had when
6074 the last level was created, you will need to restore from all backups
6075 in turn. Continuing our example, to restore the state of @file{/usr}
6076 file system, one would do@footnote{Notice, that since both archives
6077 were created without @option{-P} option (@pxref{absolute}), these
6078 commands should be run from the root file system.}:
6079
6080 @smallexample
6081 $ @kbd{tar --extract \
6082 --listed-incremental=/dev/null \
6083 --file archive.1.tar}
6084 $ @kbd{tar --extract \
6085 --listed-incremental=/dev/null \
6086 --file archive.2.tar}
6087 @end smallexample
6088
6089 To list the contents of an incremental archive, use @option{--list}
6090 (@pxref{list}), as usual. To obtain more information about the
6091 archive, use @option{--listed-incremental} or @option{--incremental}
6092 combined with two @option{--verbose} options@footnote{Two
6093 @option{--verbose} options were selected to avoid breaking usual
6094 verbose listing output (@option{--list --verbose}) when using in
6095 scripts.
6096
6097 @xopindex{incremental, using with @option{--list}}
6098 @xopindex{listed-incremental, using with @option{--list}}
6099 @xopindex{list, using with @option{--incremental}}
6100 @xopindex{list, using with @option{--listed-incremental}}
6101 Versions of @GNUTAR{} up to 1.15.1 used to dump verbatim binary
6102 contents of the DUMPDIR header (with terminating nulls) when
6103 @option{--incremental} or @option{--listed-incremental} option was
6104 given, no matter what the verbosity level. This behavior, and,
6105 especially, the binary output it produced were considered inconvenient
6106 and were changed in version 1.16.}:
6107
6108 @smallexample
6109 @kbd{tar --list --incremental --verbose --verbose archive.tar}
6110 @end smallexample
6111
6112 This command will print, for each directory in the archive, the list
6113 of files in that directory at the time the archive was created. This
6114 information is put out in a format which is both human-readable and
6115 unambiguous for a program: each file name is printed as
6116
6117 @smallexample
6118 @var{x} @var{file}
6119 @end smallexample
6120
6121 @noindent
6122 where @var{x} is a letter describing the status of the file: @samp{Y}
6123 if the file is present in the archive, @samp{N} if the file is not
6124 included in the archive, or a @samp{D} if the file is a directory (and
6125 is included in the archive). @xref{Dumpdir}, for the detailed
6126 description of dumpdirs and status codes. Each such
6127 line is terminated by a newline character. The last line is followed
6128 by an additional newline to indicate the end of the data.
6129
6130 @anchor{incremental-op}The option @option{--incremental} (@option{-G})
6131 gives the same behavior as @option{--listed-incremental} when used
6132 with @option{--list} and @option{--extract} options. When used with
6133 @option{--create} option, it creates an incremental archive without
6134 creating snapshot file. Thus, it is impossible to create several
6135 levels of incremental backups with @option{--incremental} option.
6136
6137 @node Backup Levels
6138 @section Levels of Backups
6139
6140 An archive containing all the files in the file system is called a
6141 @dfn{full backup} or @dfn{full dump}. You could insure your data by
6142 creating a full dump every day. This strategy, however, would waste a
6143 substantial amount of archive media and user time, as unchanged files
6144 are daily re-archived.
6145
6146 It is more efficient to do a full dump only occasionally. To back up
6147 files between full dumps, you can use @dfn{incremental dumps}. A @dfn{level
6148 one} dump archives all the files that have changed since the last full
6149 dump.
6150
6151 A typical dump strategy would be to perform a full dump once a week,
6152 and a level one dump once a day. This means some versions of files
6153 will in fact be archived more than once, but this dump strategy makes
6154 it possible to restore a file system to within one day of accuracy by
6155 only extracting two archives---the last weekly (full) dump and the
6156 last daily (level one) dump. The only information lost would be in
6157 files changed or created since the last daily backup. (Doing dumps
6158 more than once a day is usually not worth the trouble.)
6159
6160 @GNUTAR{} comes with scripts you can use to do full
6161 and level-one (actually, even level-two and so on) dumps. Using
6162 scripts (shell programs) to perform backups and restoration is a
6163 convenient and reliable alternative to typing out file name lists
6164 and @command{tar} commands by hand.
6165
6166 Before you use these scripts, you need to edit the file
6167 @file{backup-specs}, which specifies parameters used by the backup
6168 scripts and by the restore script. This file is usually located
6169 in @file{/etc/backup} directory. @xref{Backup Parameters}, for its
6170 detailed description. Once the backup parameters are set, you can
6171 perform backups or restoration by running the appropriate script.
6172
6173 The name of the backup script is @code{backup}. The name of the
6174 restore script is @code{restore}. The following sections describe
6175 their use in detail.
6176
6177 @emph{Please Note:} The backup and restoration scripts are
6178 designed to be used together. While it is possible to restore files by
6179 hand from an archive which was created using a backup script, and to create
6180 an archive by hand which could then be extracted using the restore script,
6181 it is easier to use the scripts. @xref{Incremental Dumps}, before
6182 making such an attempt.
6183
6184 @node Backup Parameters
6185 @section Setting Parameters for Backups and Restoration
6186
6187 The file @file{backup-specs} specifies backup parameters for the
6188 backup and restoration scripts provided with @command{tar}. You must
6189 edit @file{backup-specs} to fit your system configuration and schedule
6190 before using these scripts.
6191
6192 Syntactically, @file{backup-specs} is a shell script, containing
6193 mainly variable assignments. However, any valid shell construct
6194 is allowed in this file. Particularly, you may wish to define
6195 functions within that script (e.g., see @code{RESTORE_BEGIN} below).
6196 For more information about shell script syntax, please refer to
6197 @url{http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
6198 g_02, the definition of the Shell Command Language}. See also
6199 @ref{Top,,Bash Features,bashref,Bash Reference Manual}.
6200
6201 The shell variables controlling behavior of @code{backup} and
6202 @code{restore} are described in the following subsections.
6203
6204 @menu
6205 * General-Purpose Variables::
6206 * Magnetic Tape Control::
6207 * User Hooks::
6208 * backup-specs example:: An Example Text of @file{Backup-specs}
6209 @end menu
6210
6211 @node General-Purpose Variables
6212 @subsection General-Purpose Variables
6213
6214 @defvr {Backup variable} ADMINISTRATOR
6215 The user name of the backup administrator. @code{Backup} scripts
6216 sends a backup report to this address.
6217 @end defvr
6218
6219 @defvr {Backup variable} BACKUP_HOUR
6220 The hour at which the backups are done. This can be a number from 0
6221 to 23, or the time specification in form @var{hours}:@var{minutes},
6222 or the string @samp{now}.
6223
6224 This variable is used by @code{backup}. Its value may be overridden
6225 using @option{--time} option (@pxref{Scripted Backups}).
6226 @end defvr
6227
6228 @defvr {Backup variable} TAPE_FILE
6229
6230 The device @command{tar} writes the archive to. If @var{TAPE_FILE}
6231 is a remote archive (@pxref{remote-dev}), backup script will suppose
6232 that your @command{mt} is able to access remote devices. If @var{RSH}
6233 (@pxref{RSH}) is set, @option{--rsh-command} option will be added to
6234 invocations of @command{mt}.
6235 @end defvr
6236
6237 @defvr {Backup variable} BLOCKING
6238
6239 The blocking factor @command{tar} will use when writing the dump archive.
6240 @xref{Blocking Factor}.
6241 @end defvr
6242
6243 @defvr {Backup variable} BACKUP_DIRS
6244
6245 A list of file systems to be dumped (for @code{backup}), or restored
6246 (for @code{restore}). You can include any directory
6247 name in the list --- subdirectories on that file system will be
6248 included, regardless of how they may look to other networked machines.
6249 Subdirectories on other file systems will be ignored.
6250
6251 The host name specifies which host to run @command{tar} on, and should
6252 normally be the host that actually contains the file system. However,
6253 the host machine must have @GNUTAR{} installed, and
6254 must be able to access the directory containing the backup scripts and
6255 their support files using the same file name that is used on the
6256 machine where the scripts are run (i.e., what @command{pwd} will print
6257 when in that directory on that machine). If the host that contains
6258 the file system does not have this capability, you can specify another
6259 host as long as it can access the file system through @acronym{NFS}.
6260
6261 If the list of file systems is very long you may wish to put it
6262 in a separate file. This file is usually named
6263 @file{/etc/backup/dirs}, but this name may be overridden in
6264 @file{backup-specs} using @code{DIRLIST} variable.
6265 @end defvr
6266
6267 @defvr {Backup variable} DIRLIST
6268
6269 The name of the file that contains a list of file systems to backup
6270 or restore. By default it is @file{/etc/backup/dirs}.
6271 @end defvr
6272
6273 @defvr {Backup variable} BACKUP_FILES
6274
6275 A list of individual files to be dumped (for @code{backup}), or restored
6276 (for @code{restore}). These should be accessible from the machine on
6277 which the backup script is run.
6278
6279 If the list of individual files is very long you may wish to store it
6280 in a separate file. This file is usually named
6281 @file{/etc/backup/files}, but this name may be overridden in
6282 @file{backup-specs} using @code{FILELIST} variable.
6283 @end defvr
6284
6285 @defvr {Backup variable} FILELIST
6286
6287 The name of the file that contains a list of individual files to backup
6288 or restore. By default it is @file{/etc/backup/files}.
6289 @end defvr
6290
6291 @defvr {Backup variable} MT
6292
6293 Full file name of @command{mt} binary.
6294 @end defvr
6295
6296 @defvr {Backup variable} RSH
6297 @anchor{RSH}
6298 Full file name of @command{rsh} binary or its equivalent. You may wish to
6299 set it to @code{ssh}, to improve security. In this case you will have
6300 to use public key authentication.
6301 @end defvr
6302
6303 @defvr {Backup variable} RSH_COMMAND
6304
6305 Full file name of @command{rsh} binary on remote machines. This will
6306 be passed via @option{--rsh-command} option to the remote invocation
6307 of @GNUTAR{}.
6308 @end defvr
6309
6310 @defvr {Backup variable} VOLNO_FILE
6311
6312 Name of temporary file to hold volume numbers. This needs to be accessible
6313 by all the machines which have file systems to be dumped.
6314 @end defvr
6315
6316 @defvr {Backup variable} XLIST
6317
6318 Name of @dfn{exclude file list}. An @dfn{exclude file list} is a file
6319 located on the remote machine and containing the list of files to
6320 be excluded from the backup. Exclude file lists are searched in
6321 /etc/tar-backup directory. A common use for exclude file lists
6322 is to exclude files containing security-sensitive information
6323 (e.g., @file{/etc/shadow} from backups).
6324
6325 This variable affects only @code{backup}.
6326 @end defvr
6327
6328 @defvr {Backup variable} SLEEP_TIME
6329
6330 Time to sleep between dumps of any two successive file systems
6331
6332 This variable affects only @code{backup}.
6333 @end defvr
6334
6335 @defvr {Backup variable} DUMP_REMIND_SCRIPT
6336
6337 Script to be run when it's time to insert a new tape in for the next
6338 volume. Administrators may want to tailor this script for their site.
6339 If this variable isn't set, @GNUTAR{} will display its built-in
6340 prompt, and will expect confirmation from the console. For the
6341 description of the default prompt, see @ref{change volume prompt}.
6342
6343 @end defvr
6344
6345 @defvr {Backup variable} SLEEP_MESSAGE
6346
6347 Message to display on the terminal while waiting for dump time. Usually
6348 this will just be some literal text.
6349 @end defvr
6350
6351 @defvr {Backup variable} TAR
6352
6353 Full file name of the @GNUTAR{} executable. If this is not set, backup
6354 scripts will search @command{tar} in the current shell path.
6355 @end defvr
6356
6357 @node Magnetic Tape Control
6358 @subsection Magnetic Tape Control
6359
6360 Backup scripts access tape device using special @dfn{hook functions}.
6361 These functions take a single argument --- the name of the tape
6362 device. Their names are kept in the following variables:
6363
6364 @defvr {Backup variable} MT_BEGIN
6365 The name of @dfn{begin} function. This function is called before
6366 accessing the drive. By default it retensions the tape:
6367
6368 @smallexample
6369 MT_BEGIN=mt_begin
6370
6371 mt_begin() @{
6372 mt -f "$1" retension
6373 @}
6374 @end smallexample
6375 @end defvr
6376
6377 @defvr {Backup variable} MT_REWIND
6378 The name of @dfn{rewind} function. The default definition is as
6379 follows:
6380
6381 @smallexample
6382 MT_REWIND=mt_rewind
6383
6384 mt_rewind() @{
6385 mt -f "$1" rewind
6386 @}
6387 @end smallexample
6388
6389 @end defvr
6390
6391 @defvr {Backup variable} MT_OFFLINE
6392 The name of the function switching the tape off line. By default
6393 it is defined as follows:
6394
6395 @smallexample
6396 MT_OFFLINE=mt_offline
6397
6398 mt_offline() @{
6399 mt -f "$1" offl
6400 @}
6401 @end smallexample
6402 @end defvr
6403
6404 @defvr {Backup variable} MT_STATUS
6405 The name of the function used to obtain the status of the archive device,
6406 including error count. Default definition:
6407
6408 @smallexample
6409 MT_STATUS=mt_status
6410
6411 mt_status() @{
6412 mt -f "$1" status
6413 @}
6414 @end smallexample
6415 @end defvr
6416
6417 @node User Hooks
6418 @subsection User Hooks
6419
6420 @dfn{User hooks} are shell functions executed before and after
6421 each @command{tar} invocation. Thus, there are @dfn{backup
6422 hooks}, which are executed before and after dumping each file
6423 system, and @dfn{restore hooks}, executed before and
6424 after restoring a file system. Each user hook is a shell function
6425 taking four arguments:
6426
6427 @deffn {User Hook Function} hook @var{level} @var{host} @var{fs} @var{fsname}
6428 Its arguments are:
6429
6430 @table @var
6431 @item level
6432 Current backup or restore level.
6433
6434 @item host
6435 Name or IP address of the host machine being dumped or restored.
6436
6437 @item fs
6438 Full file name of the file system being dumped or restored.
6439
6440 @item fsname
6441 File system name with directory separators replaced with colons. This
6442 is useful, e.g., for creating unique files.
6443 @end table
6444 @end deffn
6445
6446 Following variables keep the names of user hook functions:
6447
6448 @defvr {Backup variable} DUMP_BEGIN
6449 Dump begin function. It is executed before dumping the file system.
6450 @end defvr
6451
6452 @defvr {Backup variable} DUMP_END
6453 Executed after dumping the file system.
6454 @end defvr
6455
6456 @defvr {Backup variable} RESTORE_BEGIN
6457 Executed before restoring the file system.
6458 @end defvr
6459
6460 @defvr {Backup variable} RESTORE_END
6461 Executed after restoring the file system.
6462 @end defvr
6463
6464 @node backup-specs example
6465 @subsection An Example Text of @file{Backup-specs}
6466
6467 The following is an example of @file{backup-specs}:
6468
6469 @smallexample
6470 # site-specific parameters for file system backup.
6471
6472 ADMINISTRATOR=friedman
6473 BACKUP_HOUR=1
6474 TAPE_FILE=/dev/nrsmt0
6475
6476 # Use @code{ssh} instead of the less secure @code{rsh}
6477 RSH=/usr/bin/ssh
6478 RSH_COMMAND=/usr/bin/ssh
6479
6480 # Override MT_STATUS function:
6481 my_status() @{
6482 mts -t $TAPE_FILE
6483 @}
6484 MT_STATUS=my_status
6485
6486 # Disable MT_OFFLINE function
6487 MT_OFFLINE=:
6488
6489 BLOCKING=124
6490 BACKUP_DIRS="
6491 albert:/fs/fsf
6492 apple-gunkies:/gd
6493 albert:/fs/gd2
6494 albert:/fs/gp
6495 geech:/usr/jla
6496 churchy:/usr/roland
6497 albert:/
6498 albert:/usr
6499 apple-gunkies:/
6500 apple-gunkies:/usr
6501 gnu:/hack
6502 gnu:/u
6503 apple-gunkies:/com/mailer/gnu
6504 apple-gunkies:/com/archive/gnu"
6505
6506 BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
6507
6508 @end smallexample
6509
6510 @node Scripted Backups
6511 @section Using the Backup Scripts
6512
6513 The syntax for running a backup script is:
6514
6515 @smallexample
6516 backup --level=@var{level} --time=@var{time}
6517 @end smallexample
6518
6519 The @option{--level} option requests the dump level. Thus, to produce
6520 a full dump, specify @code{--level=0} (this is the default, so
6521 @option{--level} may be omitted if its value is
6522 @code{0})@footnote{For backward compatibility, the @code{backup} will also
6523 try to deduce the requested dump level from the name of the
6524 script itself. If the name consists of a string @samp{level-}
6525 followed by a single decimal digit, that digit is taken as
6526 the dump level number. Thus, you may create a link from @code{backup}
6527 to @code{level-1} and then run @code{level-1} whenever you need to
6528 create a level one dump.}.
6529
6530 The @option{--time} option determines when should the backup be
6531 run. @var{Time} may take three forms:
6532
6533 @table @asis
6534 @item @var{hh}:@var{mm}
6535
6536 The dump must be run at @var{hh} hours @var{mm} minutes.
6537
6538 @item @var{hh}
6539
6540 The dump must be run at @var{hh} hours.
6541
6542 @item now
6543
6544 The dump must be run immediately.
6545 @end table
6546
6547 You should start a script with a tape or disk mounted. Once you
6548 start a script, it prompts you for new tapes or disks as it
6549 needs them. Media volumes don't have to correspond to archive
6550 files --- a multi-volume archive can be started in the middle of a
6551 tape that already contains the end of another multi-volume archive.
6552 The @code{restore} script prompts for media by its archive volume,
6553 so to avoid an error message you should keep track of which tape
6554 (or disk) contains which volume of the archive (@pxref{Scripted
6555 Restoration}).
6556
6557 The backup scripts write two files on the file system. The first is a
6558 record file in @file{/etc/tar-backup/}, which is used by the scripts
6559 to store and retrieve information about which files were dumped. This
6560 file is not meant to be read by humans, and should not be deleted by
6561 them. @xref{Snapshot Files}, for a more detailed explanation of this
6562 file.
6563
6564 The second file is a log file containing the names of the file systems
6565 and files dumped, what time the backup was made, and any error
6566 messages that were generated, as well as how much space was left in
6567 the media volume after the last volume of the archive was written.
6568 You should check this log file after every backup. The file name is
6569 @file{log-@var{mm-dd-yyyy}-level-@var{n}}, where @var{mm-dd-yyyy}
6570 represents current date, and @var{n} represents current dump level number.
6571
6572 The script also prints the name of each system being dumped to the
6573 standard output.
6574
6575 Following is the full list of options accepted by @code{backup}
6576 script:
6577
6578 @table @option
6579 @item -l @var{level}
6580 @itemx --level=@var{level}
6581 Do backup level @var{level} (default 0).
6582
6583 @item -f
6584 @itemx --force
6585 Force backup even if today's log file already exists.
6586
6587 @item -v[@var{level}]
6588 @itemx --verbose[=@var{level}]
6589 Set verbosity level. The higher the level is, the more debugging
6590 information will be output during execution. Default @var{level}
6591 is 100, which means the highest debugging level.
6592
6593 @item -t @var{start-time}
6594 @itemx --time=@var{start-time}
6595 Wait till @var{time}, then do backup.
6596
6597 @item -h
6598 @itemx --help
6599 Display short help message and exit.
6600
6601 @item -V
6602 @itemx --version
6603 Display information about the program's name, version, origin and legal
6604 status, all on standard output, and then exit successfully.
6605 @end table
6606
6607
6608 @node Scripted Restoration
6609 @section Using the Restore Script
6610
6611 To restore files that were archived using a scripted backup, use the
6612 @code{restore} script. Its usage is quite straightforward. In the
6613 simplest form, invoke @code{restore --all}, it will
6614 then restore all the file systems and files specified in
6615 @file{backup-specs} (@pxref{General-Purpose Variables,BACKUP_DIRS}).
6616
6617 You may select the file systems (and/or files) to restore by
6618 giving @code{restore} a list of @dfn{patterns} in its command
6619 line. For example, running
6620
6621 @smallexample
6622 restore 'albert:*'
6623 @end smallexample
6624
6625 @noindent
6626 will restore all file systems on the machine @samp{albert}. A more
6627 complicated example:
6628
6629 @smallexample
6630 restore 'albert:*' '*:/var'
6631 @end smallexample
6632
6633 @noindent
6634 This command will restore all file systems on the machine @samp{albert}
6635 as well as @file{/var} file system on all machines.
6636
6637 By default @code{restore} will start restoring files from the lowest
6638 available dump level (usually zero) and will continue through
6639 all available dump levels. There may be situations where such a
6640 thorough restore is not necessary. For example, you may wish to
6641 restore only files from the recent level one backup. To do so,
6642 use @option{--level} option, as shown in the example below:
6643
6644 @smallexample
6645 restore --level=1
6646 @end smallexample
6647
6648 The full list of options accepted by @code{restore} follows:
6649
6650 @table @option
6651 @item -a
6652 @itemx --all
6653 Restore all file systems and files specified in @file{backup-specs}.
6654
6655 @item -l @var{level}
6656 @itemx --level=@var{level}
6657 Start restoring from the given backup level, instead of the default 0.
6658
6659 @item -v[@var{level}]
6660 @itemx --verbose[=@var{level}]
6661 Set verbosity level. The higher the level is, the more debugging
6662 information will be output during execution. Default @var{level}
6663 is 100, which means the highest debugging level.
6664
6665 @item -h
6666 @itemx --help
6667 Display short help message and exit.
6668
6669 @item -V
6670 @itemx --version
6671 Display information about the program's name, version, origin and legal
6672 status, all on standard output, and then exit successfully.
6673 @end table
6674
6675 You should start the restore script with the media containing the
6676 first volume of the archive mounted. The script will prompt for other
6677 volumes as they are needed. If the archive is on tape, you don't need
6678 to rewind the tape to to its beginning---if the tape head is
6679 positioned past the beginning of the archive, the script will rewind
6680 the tape as needed. @xref{Tape Positioning}, for a discussion of tape
6681 positioning.
6682
6683 @quotation
6684 @strong{Warning:} The script will delete files from the active file
6685 system if they were not in the file system when the archive was made.
6686 @end quotation
6687
6688 @xref{Incremental Dumps}, for an explanation of how the script makes
6689 that determination.
6690
6691 @node Choosing
6692 @chapter Choosing Files and Names for @command{tar}
6693
6694 Certain options to @command{tar} enable you to specify a name for your
6695 archive. Other options let you decide which files to include or exclude
6696 from the archive, based on when or whether files were modified, whether
6697 the file names do or don't match specified patterns, or whether files
6698 are in specified directories.
6699
6700 This chapter discusses these options in detail.
6701
6702 @menu
6703 * file:: Choosing the Archive's Name
6704 * Selecting Archive Members::
6705 * files:: Reading Names from a File
6706 * exclude:: Excluding Some Files
6707 * wildcards:: Wildcards Patterns and Matching
6708 * quoting styles:: Ways of Quoting Special Characters in Names
6709 * transform:: Modifying File and Member Names
6710 * after:: Operating Only on New Files
6711 * recurse:: Descending into Directories
6712 * one:: Crossing File System Boundaries
6713 @end menu
6714
6715 @node file
6716 @section Choosing and Naming Archive Files
6717
6718 @cindex Naming an archive
6719 @cindex Archive Name
6720 @cindex Choosing an archive file
6721 @cindex Where is the archive?
6722 @opindex file
6723 By default, @command{tar} uses an archive file name that was compiled when
6724 it was built on the system; usually this name refers to some physical
6725 tape drive on the machine. However, the person who installed @command{tar}
6726 on the system may not have set the default to a meaningful value as far as
6727 most users are concerned. As a result, you will usually want to tell
6728 @command{tar} where to find (or create) the archive. The
6729 @option{--file=@var{archive-name}} (@option{-f @var{archive-name}})
6730 option allows you to either specify or name a file to use as the archive
6731 instead of the default archive file location.
6732
6733 @table @option
6734 @xopindex{file, short description}
6735 @item --file=@var{archive-name}
6736 @itemx -f @var{archive-name}
6737 Name the archive to create or operate on. Use in conjunction with
6738 any operation.
6739 @end table
6740
6741 For example, in this @command{tar} command,
6742
6743 @smallexample
6744 $ @kbd{tar -cvf collection.tar blues folk jazz}
6745 @end smallexample
6746
6747 @noindent
6748 @file{collection.tar} is the name of the archive. It must directly
6749 follow the @option{-f} option, since whatever directly follows @option{-f}
6750 @emph{will} end up naming the archive. If you neglect to specify an
6751 archive name, you may end up overwriting a file in the working directory
6752 with the archive you create since @command{tar} will use this file's name
6753 for the archive name.
6754
6755 An archive can be saved as a file in the file system, sent through a
6756 pipe or over a network, or written to an I/O device such as a tape,
6757 floppy disk, or CD write drive.
6758
6759 @cindex Writing new archives
6760 @cindex Archive creation
6761 If you do not name the archive, @command{tar} uses the value of the
6762 environment variable @env{TAPE} as the file name for the archive. If
6763 that is not available, @command{tar} uses a default, compiled-in archive
6764 name, usually that for tape unit zero (i.e., @file{/dev/tu00}).
6765
6766 @cindex Standard input and output
6767 @cindex tar to standard input and output
6768 If you use @file{-} as an @var{archive-name}, @command{tar} reads the
6769 archive from standard input (when listing or extracting files), or
6770 writes it to standard output (when creating an archive). If you use
6771 @file{-} as an @var{archive-name} when modifying an archive,
6772 @command{tar} reads the original archive from its standard input and
6773 writes the entire new archive to its standard output.
6774
6775 The following example is a convenient way of copying directory
6776 hierarchy from @file{sourcedir} to @file{targetdir}.
6777
6778 @smallexample
6779 $ @kbd{(cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)}
6780 @end smallexample
6781
6782 The @option{-C} option allows to avoid using subshells:
6783
6784 @smallexample
6785 $ @kbd{tar -C sourcedir -cf - . | tar -C targetdir -xpf -}
6786 @end smallexample
6787
6788 In both examples above, the leftmost @command{tar} invocation archives
6789 the contents of @file{sourcedir} to the standard output, while the
6790 rightmost one reads this archive from its standard input and
6791 extracts it. The @option{-p} option tells it to restore permissions
6792 of the extracted files.
6793
6794 @cindex Remote devices
6795 @cindex tar to a remote device
6796 @anchor{remote-dev}
6797 To specify an archive file on a device attached to a remote machine,
6798 use the following:
6799
6800 @smallexample
6801 @kbd{--file=@var{hostname}:/@var{dev}/@var{file-name}}
6802 @end smallexample
6803
6804 @noindent
6805 @command{tar} will set up the remote connection, if possible, and
6806 prompt you for a username and password. If you use
6807 @option{--file=@@@var{hostname}:/@var{dev}/@var{file-name}}, @command{tar}
6808 will attempt to set up the remote connection using your username
6809 as the username on the remote machine.
6810
6811 @cindex Local and remote archives
6812 @anchor{local and remote archives}
6813 If the archive file name includes a colon (@samp{:}), then it is assumed
6814 to be a file on another machine. If the archive file is
6815 @samp{@var{user}@@@var{host}:@var{file}}, then @var{file} is used on the
6816 host @var{host}. The remote host is accessed using the @command{rsh}
6817 program, with a username of @var{user}. If the username is omitted
6818 (along with the @samp{@@} sign), then your user name will be used.
6819 (This is the normal @command{rsh} behavior.) It is necessary for the
6820 remote machine, in addition to permitting your @command{rsh} access, to
6821 have the @file{rmt} program installed (this command is included in
6822 the @GNUTAR{} distribution and by default is installed under
6823 @file{@var{prefix}/libexec/rmt}, where @var{prefix} means your
6824 installation prefix). If you need to use a file whose name includes a
6825 colon, then the remote tape drive behavior
6826 can be inhibited by using the @option{--force-local} option.
6827
6828 When the archive is being created to @file{/dev/null}, @GNUTAR{}
6829 tries to minimize input and output operations. The Amanda backup
6830 system, when used with @GNUTAR{}, has an initial sizing pass which
6831 uses this feature.
6832
6833 @node Selecting Archive Members
6834 @section Selecting Archive Members
6835 @cindex Specifying files to act on
6836 @cindex Specifying archive members
6837
6838 @dfn{File Name arguments} specify which files in the file system
6839 @command{tar} operates on, when creating or adding to an archive, or which
6840 archive members @command{tar} operates on, when reading or deleting from
6841 an archive. @xref{Operations}.
6842
6843 To specify file names, you can include them as the last arguments on
6844 the command line, as follows:
6845 @smallexample
6846 @kbd{tar} @var{operation} [@var{option1} @var{option2} @dots{}] [@var{file name-1} @var{file name-2} @dots{}]
6847 @end smallexample
6848
6849 If a file name begins with dash (@samp{-}), precede it with
6850 @option{--add-file} option to prevent it from being treated as an
6851 option.
6852
6853 @anchor{input name quoting}
6854 By default @GNUTAR{} attempts to @dfn{unquote} each file or member
6855 name, replacing @dfn{escape sequences} according to the following
6856 table:
6857
6858 @multitable @columnfractions 0.20 0.60
6859 @headitem Escape @tab Replaced with
6860 @item \a @tab Audible bell (@acronym{ASCII} 7)
6861 @item \b @tab Backspace (@acronym{ASCII} 8)
6862 @item \f @tab Form feed (@acronym{ASCII} 12)
6863 @item \n @tab New line (@acronym{ASCII} 10)
6864 @item \r @tab Carriage return (@acronym{ASCII} 13)
6865 @item \t @tab Horizontal tabulation (@acronym{ASCII} 9)
6866 @item \v @tab Vertical tabulation (@acronym{ASCII} 11)
6867 @item \? @tab @acronym{ASCII} 127
6868 @item \@var{n} @tab @acronym{ASCII} @var{n} (@var{n} should be an octal number
6869 of up to 3 digits)
6870 @end multitable
6871
6872 A backslash followed by any other symbol is retained.
6873
6874 This default behavior is controlled by the following command line
6875 option:
6876
6877 @table @option
6878 @opindex unquote
6879 @item --unquote
6880 Enable unquoting input file or member names (default).
6881
6882 @opindex no-unquote
6883 @item --no-unquote
6884 Disable unquoting input file or member names.
6885 @end table
6886
6887 If you specify a directory name as a file name argument, all the files
6888 in that directory are operated on by @command{tar}.
6889
6890 If you do not specify files, @command{tar} behavior differs depending
6891 on the operation mode as described below:
6892
6893 When @command{tar} is invoked with @option{--create} (@option{-c}),
6894 @command{tar} will stop immediately, reporting the following:
6895
6896 @smallexample
6897 @group
6898 $ @kbd{tar cf a.tar}
6899 tar: Cowardly refusing to create an empty archive
6900 Try `tar --help' or `tar --usage' for more information.
6901 @end group
6902 @end smallexample
6903
6904 If you specify either @option{--list} (@option{-t}) or
6905 @option{--extract} (@option{--get}, @option{-x}), @command{tar}
6906 operates on all the archive members in the archive.
6907
6908 If run with @option{--diff} option, tar will compare the archive with
6909 the contents of the current working directory.
6910
6911 If you specify any other operation, @command{tar} does nothing.
6912
6913 By default, @command{tar} takes file names from the command line. However,
6914 there are other ways to specify file or member names, or to modify the
6915 manner in which @command{tar} selects the files or members upon which to
6916 operate. In general, these methods work both for specifying the names
6917 of files and archive members.
6918
6919 @node files
6920 @section Reading Names from a File
6921
6922 @cindex Reading file names from a file
6923 @cindex Lists of file names
6924 @cindex File Name arguments, alternatives
6925 @cindex @command{find}, using with @command{tar}
6926 Instead of giving the names of files or archive members on the command
6927 line, you can put the names into a file, and then use the
6928 @option{--files-from=@var{file-of-names}} (@option{-T
6929 @var{file-of-names}}) option to @command{tar}. Give the name of the
6930 file which contains the list of files to include as the argument to
6931 @option{--files-from}. In the list, the file names should be separated by
6932 newlines. You will frequently use this option when you have generated
6933 the list of files to archive with the @command{find} utility.
6934
6935 @table @option
6936 @opindex files-from
6937 @item --files-from=@var{file-name}
6938 @itemx -T @var{file-name}
6939 Get names to extract or create from file @var{file-name}.
6940 @end table
6941
6942 If you give a single dash as a file name for @option{--files-from}, (i.e.,
6943 you specify either @code{--files-from=-} or @code{-T -}), then the file
6944 names are read from standard input.
6945
6946 Unless you are running @command{tar} with @option{--create}, you can not use
6947 both @code{--files-from=-} and @code{--file=-} (@code{-f -}) in the same
6948 command.
6949
6950 Any number of @option{-T} options can be given in the command line.
6951
6952 The following example shows how to use @command{find} to generate a list of
6953 files smaller than 400K in length and put that list into a file
6954 called @file{small-files}. You can then use the @option{-T} option to
6955 @command{tar} to specify the files from that file, @file{small-files}, to
6956 create the archive @file{little.tgz}. (The @option{-z} option to
6957 @command{tar} compresses the archive with @command{gzip}; @pxref{gzip} for
6958 more information.)
6959
6960 @smallexample
6961 $ @kbd{find . -size -400 -print > small-files}
6962 $ @kbd{tar -c -v -z -T small-files -f little.tgz}
6963 @end smallexample
6964
6965 @noindent
6966 In the file list given by @option{-T} option, any file name beginning
6967 with @samp{-} character is considered a @command{tar} option and is
6968 processed accordingly@footnote{Versions of @GNUTAR{} up to 1.15.1
6969 recognized only @option{-C} option in file lists, and only if the
6970 option and its argument occupied two consecutive lines.}. For example,
6971 the common use of this feature is to change to another directory by
6972 specifying @option{-C} option:
6973
6974 @smallexample
6975 @group
6976 $ @kbd{cat list}
6977 -C/etc
6978 passwd
6979 hosts
6980 -C/lib
6981 libc.a
6982 $ @kbd{tar -c -f foo.tar --files-from list}
6983 @end group
6984 @end smallexample
6985
6986 @noindent
6987 In this example, @command{tar} will first switch to @file{/etc}
6988 directory and add files @file{passwd} and @file{hosts} to the
6989 archive. Then it will change to @file{/lib} directory and will archive
6990 the file @file{libc.a}. Thus, the resulting archive @file{foo.tar} will
6991 contain:
6992
6993 @smallexample
6994 @group
6995 $ @kbd{tar tf foo.tar}
6996 passwd
6997 hosts
6998 libc.a
6999 @end group
7000 @end smallexample
7001
7002 @noindent
7003 @xopindex{directory, using in @option{--files-from} argument}
7004 Notice that the option parsing algorithm used with @option{-T} is
7005 stricter than the one used by shell. Namely, when specifying option
7006 arguments, you should observe the following rules:
7007
7008 @itemize @bullet
7009 @item
7010 When using short (single-letter) option form, its argument must
7011 immediately follow the option letter, without any intervening
7012 whitespace. For example: @code{-Cdir}.
7013
7014 @item
7015 When using long option form, the option argument must be separated
7016 from the option by a single equal sign. No whitespace is allowed on
7017 any side of the equal sign. For example: @code{--directory=dir}.
7018
7019 @item
7020 For both short and long option forms, the option argument can be given
7021 on the next line after the option name, e.g.:
7022
7023 @smallexample
7024 @group
7025 --directory
7026 dir
7027 @end group
7028 @end smallexample
7029
7030 @noindent
7031 and
7032
7033 @smallexample
7034 @group
7035 -C
7036 dir
7037 @end group
7038 @end smallexample
7039 @end itemize
7040
7041 @opindex add-file
7042 If you happen to have a file whose name starts with @samp{-},
7043 precede it with @option{--add-file} option to prevent it from
7044 being recognized as an option. For example: @code{--add-file=--my-file}.
7045
7046 @menu
7047 * nul::
7048 @end menu
7049
7050 @node nul
7051 @subsection @code{NUL}-Terminated File Names
7052
7053 @cindex File names, terminated by @code{NUL}
7054 @cindex @code{NUL}-terminated file names
7055 The @option{--null} option causes
7056 @option{--files-from=@var{file-of-names}} (@option{-T @var{file-of-names}})
7057 to read file names terminated by a @code{NUL} instead of a newline, so
7058 files whose names contain newlines can be archived using
7059 @option{--files-from}.
7060
7061 @table @option
7062 @xopindex{null, described}
7063 @item --null
7064 Only consider @code{NUL}-terminated file names, instead of files that
7065 terminate in a newline.
7066
7067 @xopindex{no-null, described}
7068 @item --no-null
7069 Undo the effect of any previous @option{--null} option.
7070 @end table
7071
7072 The @option{--null} option is just like the one in @acronym{GNU}
7073 @command{xargs} and @command{cpio}, and is useful with the
7074 @option{-print0} predicate of @acronym{GNU} @command{find}. In
7075 @command{tar}, @option{--null} also disables special handling for
7076 file names that begin with dash.
7077
7078 This example shows how to use @command{find} to generate a list of files
7079 larger than 800K in length and put that list into a file called
7080 @file{long-files}. The @option{-print0} option to @command{find} is just
7081 like @option{-print}, except that it separates files with a @code{NUL}
7082 rather than with a newline. You can then run @command{tar} with both the
7083 @option{--null} and @option{-T} options to specify that @command{tar} gets the
7084 files from that file, @file{long-files}, to create the archive
7085 @file{big.tgz}. The @option{--null} option to @command{tar} will cause
7086 @command{tar} to recognize the @code{NUL} separator between files.
7087
7088 @smallexample
7089 $ @kbd{find . -size +800 -print0 > long-files}
7090 $ @kbd{tar -c -v --null --files-from=long-files --file=big.tar}
7091 @end smallexample
7092
7093 The @option{--no-null} option can be used if you need to read both
7094 @code{NUL}-terminated and newline-terminated files on the same command line.
7095 For example, if @file{flist} is a newline-terminated file, then the
7096 following command can be used to combine it with the above command:
7097
7098 @smallexample
7099 @group
7100 $ @kbd{find . -size +800 -print0 |
7101 tar -c -f big.tar --null -T - --no-null -T flist}
7102 @end group
7103 @end smallexample
7104
7105 This example uses short options for typographic reasons, to avoid
7106 very long lines.
7107
7108 @GNUTAR is able to automatically detect @code{NUL}-terminated file lists, so
7109 it is safe to use them even without the @option{--null} option. In
7110 this case @command{tar} will print a warning and continue reading such
7111 a file as if @option{--null} were actually given:
7112
7113 @smallexample
7114 @group
7115 $ @kbd{find . -size +800 -print0 | tar -c -f big.tar -T -}
7116 tar: -: file name read contains nul character
7117 @end group
7118 @end smallexample
7119
7120 The null terminator, however, remains in effect only for this
7121 particular file, any following @option{-T} options will assume
7122 newline termination. Of course, the null autodetection applies
7123 to these eventual surplus @option{-T} options as well.
7124
7125 @node exclude
7126 @section Excluding Some Files
7127
7128 @cindex File names, excluding files by
7129 @cindex Excluding files by name and pattern
7130 @cindex Excluding files by file system
7131 @opindex exclude
7132 @opindex exclude-from
7133 To avoid operating on files whose names match a particular pattern,
7134 use the @option{--exclude} or @option{--exclude-from} options.
7135
7136 @table @option
7137 @opindex exclude
7138 @item --exclude=@var{pattern}
7139 Causes @command{tar} to ignore files that match the @var{pattern}.
7140 @end table
7141
7142 @findex exclude
7143 The @option{--exclude=@var{pattern}} option prevents any file or
7144 member whose name matches the shell wildcard (@var{pattern}) from
7145 being operated on.
7146 For example, to create an archive with all the contents of the directory
7147 @file{src} except for files whose names end in @file{.o}, use the
7148 command @samp{tar -cf src.tar --exclude='*.o' src}.
7149
7150 You may give multiple @option{--exclude} options.
7151
7152 @table @option
7153 @opindex exclude-from
7154 @item --exclude-from=@var{file}
7155 @itemx -X @var{file}
7156 Causes @command{tar} to ignore files that match the patterns listed in
7157 @var{file}.
7158 @end table
7159
7160 @findex exclude-from
7161 Use the @option{--exclude-from} option to read a
7162 list of patterns, one per line, from @var{file}; @command{tar} will
7163 ignore files matching those patterns. Thus if @command{tar} is
7164 called as @w{@samp{tar -c -X foo .}} and the file @file{foo} contains a
7165 single line @file{*.o}, no files whose names end in @file{.o} will be
7166 added to the archive.
7167
7168 Notice, that lines from @var{file} are read verbatim. One of the
7169 frequent errors is leaving some extra whitespace after a file name,
7170 which is difficult to catch using text editors.
7171
7172 However, empty lines are OK.
7173
7174 @table @option
7175 @cindex version control system, excluding files
7176 @cindex VCS, excluding files
7177 @cindex SCCS, excluding files
7178 @cindex RCS, excluding files
7179 @cindex CVS, excluding files
7180 @cindex SVN, excluding files
7181 @cindex git, excluding files
7182 @cindex Bazaar, excluding files
7183 @cindex Arch, excluding files
7184 @cindex Mercurial, excluding files
7185 @cindex Darcs, excluding files
7186 @opindex exclude-vcs
7187 @item --exclude-vcs
7188 Exclude files and directories used by following version control
7189 systems: @samp{CVS}, @samp{RCS}, @samp{SCCS}, @samp{SVN}, @samp{Arch},
7190 @samp{Bazaar}, @samp{Mercurial}, and @samp{Darcs}.
7191
7192 As of version @value{VERSION}, the following files are excluded:
7193
7194 @itemize @bullet
7195 @item @file{CVS/}, and everything under it
7196 @item @file{RCS/}, and everything under it
7197 @item @file{SCCS/}, and everything under it
7198 @item @file{.git/}, and everything under it
7199 @item @file{.gitignore}
7200 @item @file{.cvsignore}
7201 @item @file{.svn/}, and everything under it
7202 @item @file{.arch-ids/}, and everything under it
7203 @item @file{@{arch@}/}, and everything under it
7204 @item @file{=RELEASE-ID}
7205 @item @file{=meta-update}
7206 @item @file{=update}
7207 @item @file{.bzr}
7208 @item @file{.bzrignore}
7209 @item @file{.bzrtags}
7210 @item @file{.hg}
7211 @item @file{.hgignore}
7212 @item @file{.hgrags}
7213 @item @file{_darcs}
7214 @end itemize
7215
7216 @opindex exclude-backups
7217 @item --exclude-backups
7218 Exclude backup and lock files. This option causes exclusion of files
7219 that match the following shell globbing patterns:
7220
7221 @table @asis
7222 @item .#*
7223 @item *~
7224 @item #*#
7225 @end table
7226
7227 @end table
7228
7229 @findex exclude-caches
7230 When creating an archive, the @option{--exclude-caches} option family
7231 causes @command{tar} to exclude all directories that contain a @dfn{cache
7232 directory tag}. A cache directory tag is a short file with the
7233 well-known name @file{CACHEDIR.TAG} and having a standard header
7234 specified in @url{http://www.brynosaurus.com/cachedir/spec.html}.
7235 Various applications write cache directory tags into directories they
7236 use to hold regenerable, non-precious data, so that such data can be
7237 more easily excluded from backups.
7238
7239 There are three @samp{exclude-caches} options, each providing a different
7240 exclusion semantics:
7241
7242 @table @option
7243 @opindex exclude-caches
7244 @item --exclude-caches
7245 Do not archive the contents of the directory, but archive the
7246 directory itself and the @file{CACHEDIR.TAG} file.
7247
7248 @opindex exclude-caches-under
7249 @item --exclude-caches-under
7250 Do not archive the contents of the directory, nor the
7251 @file{CACHEDIR.TAG} file, archive only the directory itself.
7252
7253 @opindex exclude-caches-all
7254 @item --exclude-caches-all
7255 Omit directories containing @file{CACHEDIR.TAG} file entirely.
7256 @end table
7257
7258 @findex exclude-tag
7259 Another option family, @option{--exclude-tag}, provides a generalization of
7260 this concept. It takes a single argument, a file name to look for.
7261 Any directory that contains this file will be excluded from the dump.
7262 Similarly to @samp{exclude-caches}, there are three options in this
7263 option family:
7264
7265 @table @option
7266 @opindex exclude-tag
7267 @item --exclude-tag=@var{file}
7268 Do not dump the contents of the directory, but dump the
7269 directory itself and the @var{file}.
7270
7271 @opindex exclude-tag-under
7272 @item --exclude-tag-under=@var{file}
7273 Do not dump the contents of the directory, nor the
7274 @var{file}, archive only the directory itself.
7275
7276 @opindex exclude-tag-all
7277 @item --exclude-tag-all=@var{file}
7278 Omit directories containing @var{file} file entirely.
7279 @end table
7280
7281 Multiple @option{--exclude-tag*} options can be given.
7282
7283 For example, given this directory:
7284
7285 @smallexample
7286 @group
7287 $ @kbd{find dir}
7288 dir
7289 dir/blues
7290 dir/jazz
7291 dir/folk
7292 dir/folk/tagfile
7293 dir/folk/sanjuan
7294 dir/folk/trote
7295 @end group
7296 @end smallexample
7297
7298 The @option{--exclude-tag} will produce the following:
7299
7300 @smallexample
7301 $ @kbd{tar -cf archive.tar --exclude-tag=tagfile -v dir}
7302 dir/
7303 dir/blues
7304 dir/jazz
7305 dir/folk/
7306 tar: dir/folk/: contains a cache directory tag tagfile;
7307 contents not dumped
7308 dir/folk/tagfile
7309 @end smallexample
7310
7311 Both the @file{dir/folk} directory and its tagfile are preserved in
7312 the archive, however the rest of files in this directory are not.
7313
7314 Now, using the @option{--exclude-tag-under} option will exclude
7315 @file{tagfile} from the dump, while still preserving the directory
7316 itself, as shown in this example:
7317
7318 @smallexample
7319 $ @kbd{tar -cf archive.tar --exclude-tag-under=tagfile -v dir}
7320 dir/
7321 dir/blues
7322 dir/jazz
7323 dir/folk/
7324 ./tar: dir/folk/: contains a cache directory tag tagfile;
7325 contents not dumped
7326 @end smallexample
7327
7328 Finally, using @option{--exclude-tag-all} omits the @file{dir/folk}
7329 directory entirely:
7330
7331 @smallexample
7332 $ @kbd{tar -cf archive.tar --exclude-tag-all=tagfile -v dir}
7333 dir/
7334 dir/blues
7335 dir/jazz
7336 ./tar: dir/folk/: contains a cache directory tag tagfile;
7337 directory not dumped
7338 @end smallexample
7339
7340 @menu
7341 * problems with exclude::
7342 @end menu
7343
7344 @node problems with exclude
7345 @unnumberedsubsec Problems with Using the @code{exclude} Options
7346
7347 @xopindex{exclude, potential problems with}
7348 Some users find @samp{exclude} options confusing. Here are some common
7349 pitfalls:
7350
7351 @itemize @bullet
7352 @item
7353 The main operating mode of @command{tar} does not act on a file name
7354 explicitly listed on the command line, if one of its file name
7355 components is excluded. In the example above, if
7356 you create an archive and exclude files that end with @samp{*.o}, but
7357 explicitly name the file @samp{dir.o/foo} after all the options have been
7358 listed, @samp{dir.o/foo} will be excluded from the archive.
7359
7360 @item
7361 You can sometimes confuse the meanings of @option{--exclude} and
7362 @option{--exclude-from}. Be careful: use @option{--exclude} when files
7363 to be excluded are given as a pattern on the command line. Use
7364 @option{--exclude-from} to introduce the name of a file which contains
7365 a list of patterns, one per line; each of these patterns can exclude
7366 zero, one, or many files.
7367
7368 @item
7369 When you use @option{--exclude=@var{pattern}}, be sure to quote the
7370 @var{pattern} parameter, so @GNUTAR{} sees wildcard characters
7371 like @samp{*}. If you do not do this, the shell might expand the
7372 @samp{*} itself using files at hand, so @command{tar} might receive a
7373 list of files instead of one pattern, or none at all, making the
7374 command somewhat illegal. This might not correspond to what you want.
7375
7376 For example, write:
7377
7378 @smallexample
7379 $ @kbd{tar -c -f @var{archive.tar} --exclude '*.o' @var{directory}}
7380 @end smallexample
7381
7382 @noindent
7383 rather than:
7384
7385 @smallexample
7386 # @emph{Wrong!}
7387 $ @kbd{tar -c -f @var{archive.tar} --exclude *.o @var{directory}}
7388 @end smallexample
7389
7390 @item
7391 You must use use shell syntax, or globbing, rather than @code{regexp}
7392 syntax, when using exclude options in @command{tar}. If you try to use
7393 @code{regexp} syntax to describe files to be excluded, your command
7394 might fail.
7395
7396 @item
7397 @FIXME{The change in semantics must have occurred before 1.11,
7398 so I doubt if it is worth mentioning at all. Anyway, should at
7399 least specify in which version the semantics changed.}
7400 In earlier versions of @command{tar}, what is now the
7401 @option{--exclude-from} option was called @option{--exclude} instead.
7402 Now, @option{--exclude} applies to patterns listed on the command
7403 line and @option{--exclude-from} applies to patterns listed in a
7404 file.
7405
7406 @end itemize
7407
7408 @node wildcards
7409 @section Wildcards Patterns and Matching
7410
7411 @dfn{Globbing} is the operation by which @dfn{wildcard} characters,
7412 @samp{*} or @samp{?} for example, are replaced and expanded into all
7413 existing files matching the given pattern. @GNUTAR{} can use wildcard
7414 patterns for matching (or globbing) archive members when extracting
7415 from or listing an archive. Wildcard patterns are also used for
7416 verifying volume labels of @command{tar} archives. This section has the
7417 purpose of explaining wildcard syntax for @command{tar}.
7418
7419 @FIXME{the next few paragraphs need work.}
7420
7421 A @var{pattern} should be written according to shell syntax, using wildcard
7422 characters to effect globbing. Most characters in the pattern stand
7423 for themselves in the matched string, and case is significant: @samp{a}
7424 will match only @samp{a}, and not @samp{A}. The character @samp{?} in the
7425 pattern matches any single character in the matched string. The character
7426 @samp{*} in the pattern matches zero, one, or more single characters in
7427 the matched string. The character @samp{\} says to take the following
7428 character of the pattern @emph{literally}; it is useful when one needs to
7429 match the @samp{?}, @samp{*}, @samp{[} or @samp{\} characters, themselves.
7430
7431 The character @samp{[}, up to the matching @samp{]}, introduces a character
7432 class. A @dfn{character class} is a list of acceptable characters
7433 for the next single character of the matched string. For example,
7434 @samp{[abcde]} would match any of the first five letters of the alphabet.
7435 Note that within a character class, all of the ``special characters''
7436 listed above other than @samp{\} lose their special meaning; for example,
7437 @samp{[-\\[*?]]} would match any of the characters, @samp{-}, @samp{\},
7438 @samp{[}, @samp{*}, @samp{?}, or @samp{]}. (Due to parsing constraints,
7439 the characters @samp{-} and @samp{]} must either come @emph{first} or
7440 @emph{last} in a character class.)
7441
7442 @cindex Excluding characters from a character class
7443 @cindex Character class, excluding characters from
7444 If the first character of the class after the opening @samp{[}
7445 is @samp{!} or @samp{^}, then the meaning of the class is reversed.
7446 Rather than listing character to match, it lists those characters which
7447 are @emph{forbidden} as the next single character of the matched string.
7448
7449 Other characters of the class stand for themselves. The special
7450 construction @samp{[@var{a}-@var{e}]}, using an hyphen between two
7451 letters, is meant to represent all characters between @var{a} and
7452 @var{e}, inclusive.
7453
7454 @FIXME{need to add a sentence or so here to make this clear for those
7455 who don't have dan around.}
7456
7457 Periods (@samp{.}) or forward slashes (@samp{/}) are not considered
7458 special for wildcard matches. However, if a pattern completely matches
7459 a directory prefix of a matched string, then it matches the full matched
7460 string: thus, excluding a directory also excludes all the files beneath it.
7461
7462 @menu
7463 * controlling pattern-matching::
7464 @end menu
7465
7466 @node controlling pattern-matching
7467 @unnumberedsubsec Controlling Pattern-Matching
7468
7469 For the purposes of this section, we call @dfn{exclusion members} all
7470 member names obtained while processing @option{--exclude} and
7471 @option{--exclude-from} options, and @dfn{inclusion members} those
7472 member names that were given in the command line or read from the file
7473 specified with @option{--files-from} option.
7474
7475 These two pairs of member lists are used in the following operations:
7476 @option{--diff}, @option{--extract}, @option{--list},
7477 @option{--update}.
7478
7479 There are no inclusion members in create mode (@option{--create} and
7480 @option{--append}), since in this mode the names obtained from the
7481 command line refer to @emph{files}, not archive members.
7482
7483 By default, inclusion members are compared with archive members
7484 literally @footnote{Notice that earlier @GNUTAR{} versions used
7485 globbing for inclusion members, which contradicted to UNIX98
7486 specification and was not documented. @xref{Changes}, for more
7487 information on this and other changes.} and exclusion members are
7488 treated as globbing patterns. For example:
7489
7490 @smallexample
7491 @group
7492 $ @kbd{tar tf foo.tar}
7493 a.c
7494 b.c
7495 a.txt
7496 [remarks]
7497 # @i{Member names are used verbatim:}
7498 $ @kbd{tar -xf foo.tar -v '[remarks]'}
7499 [remarks]
7500 # @i{Exclude member names are globbed:}
7501 $ @kbd{tar -xf foo.tar -v --exclude '*.c'}
7502 a.txt
7503 [remarks]
7504 @end group
7505 @end smallexample
7506
7507 This behavior can be altered by using the following options:
7508
7509 @table @option
7510 @opindex wildcards
7511 @item --wildcards
7512 Treat all member names as wildcards.
7513
7514 @opindex no-wildcards
7515 @item --no-wildcards
7516 Treat all member names as literal strings.
7517 @end table
7518
7519 Thus, to extract files whose names end in @samp{.c}, you can use:
7520
7521 @smallexample
7522 $ @kbd{tar -xf foo.tar -v --wildcards '*.c'}
7523 a.c
7524 b.c
7525 @end smallexample
7526
7527 @noindent
7528 Notice quoting of the pattern to prevent the shell from interpreting
7529 it.
7530
7531 The effect of @option{--wildcards} option is canceled by
7532 @option{--no-wildcards}. This can be used to pass part of
7533 the command line arguments verbatim and other part as globbing
7534 patterns. For example, the following invocation:
7535
7536 @smallexample
7537 $ @kbd{tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'}
7538 @end smallexample
7539
7540 @noindent
7541 instructs @command{tar} to extract from @file{foo.tar} all files whose
7542 names end in @samp{.txt} and the file named @file{[remarks]}.
7543
7544 Normally, a pattern matches a name if an initial subsequence of the
7545 name's components matches the pattern, where @samp{*}, @samp{?}, and
7546 @samp{[...]} are the usual shell wildcards, @samp{\} escapes wildcards,
7547 and wildcards can match @samp{/}.
7548
7549 Other than optionally stripping leading @samp{/} from names
7550 (@pxref{absolute}), patterns and names are used as-is. For
7551 example, trailing @samp{/} is not trimmed from a user-specified name
7552 before deciding whether to exclude it.
7553
7554 However, this matching procedure can be altered by the options listed
7555 below. These options accumulate. For example:
7556
7557 @smallexample
7558 --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
7559 @end smallexample
7560
7561 @noindent
7562 ignores case when excluding @samp{makefile}, but not when excluding
7563 @samp{readme}.
7564
7565 @table @option
7566 @opindex anchored
7567 @opindex no-anchored
7568 @item --anchored
7569 @itemx --no-anchored
7570 If anchored, a pattern must match an initial subsequence
7571 of the name's components. Otherwise, the pattern can match any
7572 subsequence. Default is @option{--no-anchored} for exclusion members
7573 and @option{--anchored} inclusion members.
7574
7575 @opindex ignore-case
7576 @opindex no-ignore-case
7577 @item --ignore-case
7578 @itemx --no-ignore-case
7579 When ignoring case, upper-case patterns match lower-case names and vice versa.
7580 When not ignoring case (the default), matching is case-sensitive.
7581
7582 @opindex wildcards-match-slash
7583 @opindex no-wildcards-match-slash
7584 @item --wildcards-match-slash
7585 @itemx --no-wildcards-match-slash
7586 When wildcards match slash (the default for exclusion members), a
7587 wildcard like @samp{*} in the pattern can match a @samp{/} in the
7588 name. Otherwise, @samp{/} is matched only by @samp{/}.
7589
7590 @end table
7591
7592 The @option{--recursion} and @option{--no-recursion} options
7593 (@pxref{recurse}) also affect how member patterns are interpreted. If
7594 recursion is in effect, a pattern matches a name if it matches any of
7595 the name's parent directories.
7596
7597 The following table summarizes pattern-matching default values:
7598
7599 @multitable @columnfractions .3 .7
7600 @headitem Members @tab Default settings
7601 @item Inclusion @tab @option{--no-wildcards --anchored --no-wildcards-match-slash}
7602 @item Exclusion @tab @option{--wildcards --no-anchored --wildcards-match-slash}
7603 @end multitable
7604
7605 @node quoting styles
7606 @section Quoting Member Names
7607
7608 When displaying member names, @command{tar} takes care to avoid
7609 ambiguities caused by certain characters. This is called @dfn{name
7610 quoting}. The characters in question are:
7611
7612 @itemize @bullet
7613 @item Non-printable control characters:
7614 @anchor{escape sequences}
7615 @multitable @columnfractions 0.20 0.10 0.60
7616 @headitem Character @tab @acronym{ASCII} @tab Character name
7617 @item \a @tab 7 @tab Audible bell
7618 @item \b @tab 8 @tab Backspace
7619 @item \f @tab 12 @tab Form feed
7620 @item \n @tab 10 @tab New line
7621 @item \r @tab 13 @tab Carriage return
7622 @item \t @tab 9 @tab Horizontal tabulation
7623 @item \v @tab 11 @tab Vertical tabulation
7624 @end multitable
7625
7626 @item Space (@acronym{ASCII} 32)
7627
7628 @item Single and double quotes (@samp{'} and @samp{"})
7629
7630 @item Backslash (@samp{\})
7631 @end itemize
7632
7633 The exact way @command{tar} uses to quote these characters depends on
7634 the @dfn{quoting style}. The default quoting style, called
7635 @dfn{escape} (see below), uses backslash notation to represent control
7636 characters, space and backslash. Using this quoting style, control
7637 characters are represented as listed in column @samp{Character} in the
7638 above table, a space is printed as @samp{\ } and a backslash as @samp{\\}.
7639
7640 @GNUTAR{} offers seven distinct quoting styles, which can be selected
7641 using @option{--quoting-style} option:
7642
7643 @table @option
7644 @item --quoting-style=@var{style}
7645 @opindex quoting-style
7646
7647 Sets quoting style. Valid values for @var{style} argument are:
7648 literal, shell, shell-always, c, escape, locale, clocale.
7649 @end table
7650
7651 These styles are described in detail below. To illustrate their
7652 effect, we will use an imaginary tar archive @file{arch.tar}
7653 containing the following members:
7654
7655 @smallexample
7656 @group
7657 # 1. Contains horizontal tabulation character.
7658 a tab
7659 # 2. Contains newline character
7660 a
7661 newline
7662 # 3. Contains a space
7663 a space
7664 # 4. Contains double quotes
7665 a"double"quote
7666 # 5. Contains single quotes
7667 a'single'quote
7668 # 6. Contains a backslash character:
7669 a\backslash
7670 @end group
7671 @end smallexample
7672
7673 Here is how usual @command{ls} command would have listed them, if they
7674 had existed in the current working directory:
7675
7676 @smallexample
7677 @group
7678 $ @kbd{ls}
7679 a\ttab
7680 a\nnewline
7681 a\ space
7682 a"double"quote
7683 a'single'quote
7684 a\\backslash
7685 @end group
7686 @end smallexample
7687
7688 Quoting styles:
7689
7690 @table @samp
7691 @item literal
7692 No quoting, display each character as is:
7693
7694 @smallexample
7695 @group
7696 $ @kbd{tar tf arch.tar --quoting-style=literal}
7697 ./
7698 ./a space
7699 ./a'single'quote
7700 ./a"double"quote
7701 ./a\backslash
7702 ./a tab
7703 ./a
7704 newline
7705 @end group
7706 @end smallexample
7707
7708 @item shell
7709 Display characters the same way Bourne shell does:
7710 control characters, except @samp{\t} and @samp{\n}, are printed using
7711 backslash escapes, @samp{\t} and @samp{\n} are printed as is, and a
7712 single quote is printed as @samp{\'}. If a name contains any quoted
7713 characters, it is enclosed in single quotes. In particular, if a name
7714 contains single quotes, it is printed as several single-quoted strings:
7715
7716 @smallexample
7717 @group
7718 $ @kbd{tar tf arch.tar --quoting-style=shell}
7719 ./
7720 './a space'
7721 './a'\''single'\''quote'
7722 './a"double"quote'
7723 './a\backslash'
7724 './a tab'
7725 './a
7726 newline'
7727 @end group
7728 @end smallexample
7729
7730 @item shell-always
7731 Same as @samp{shell}, but the names are always enclosed in single
7732 quotes:
7733
7734 @smallexample
7735 @group
7736 $ @kbd{tar tf arch.tar --quoting-style=shell-always}
7737 './'
7738 './a space'
7739 './a'\''single'\''quote'
7740 './a"double"quote'
7741 './a\backslash'
7742 './a tab'
7743 './a
7744 newline'
7745 @end group
7746 @end smallexample
7747
7748 @item c
7749 Use the notation of the C programming language. All names are
7750 enclosed in double quotes. Control characters are quoted using
7751 backslash notations, double quotes are represented as @samp{\"},
7752 backslash characters are represented as @samp{\\}. Single quotes and
7753 spaces are not quoted:
7754
7755 @smallexample
7756 @group
7757 $ @kbd{tar tf arch.tar --quoting-style=c}
7758 "./"
7759 "./a space"
7760 "./a'single'quote"
7761 "./a\"double\"quote"
7762 "./a\\backslash"
7763 "./a\ttab"
7764 "./a\nnewline"
7765 @end group
7766 @end smallexample
7767
7768 @item escape
7769 Control characters are printed using backslash notation, a space is
7770 printed as @samp{\ } and a backslash as @samp{\\}. This is the
7771 default quoting style, unless it was changed when configured the
7772 package.
7773
7774 @smallexample
7775 @group
7776 $ @kbd{tar tf arch.tar --quoting-style=escape}
7777 ./
7778 ./a space
7779 ./a'single'quote
7780 ./a"double"quote
7781 ./a\\backslash
7782 ./a\ttab
7783 ./a\nnewline
7784 @end group
7785 @end smallexample
7786
7787 @item locale
7788 Control characters, single quote and backslash are printed using
7789 backslash notation. All names are quoted using left and right
7790 quotation marks, appropriate to the current locale. If it does not
7791 define quotation marks, use @samp{`} as left and @samp{'} as right
7792 quotation marks. Any occurrences of the right quotation mark in a
7793 name are escaped with @samp{\}, for example:
7794
7795 For example:
7796
7797 @smallexample
7798 @group
7799 $ @kbd{tar tf arch.tar --quoting-style=locale}
7800 `./'
7801 `./a space'
7802 `./a\'single\'quote'
7803 `./a"double"quote'
7804 `./a\\backslash'
7805 `./a\ttab'
7806 `./a\nnewline'
7807 @end group
7808 @end smallexample
7809
7810 @item clocale
7811 Same as @samp{locale}, but @samp{"} is used for both left and right
7812 quotation marks, if not provided by the currently selected locale:
7813
7814 @smallexample
7815 @group
7816 $ @kbd{tar tf arch.tar --quoting-style=clocale}
7817 "./"
7818 "./a space"
7819 "./a'single'quote"
7820 "./a\"double\"quote"
7821 "./a\\backslash"
7822 "./a\ttab"
7823 "./a\nnewline"
7824 @end group
7825 @end smallexample
7826 @end table
7827
7828 You can specify which characters should be quoted in addition to those
7829 implied by the current quoting style:
7830
7831 @table @option
7832 @item --quote-chars=@var{string}
7833 Always quote characters from @var{string}, even if the selected
7834 quoting style would not quote them.
7835 @end table
7836
7837 For example, using @samp{escape} quoting (compare with the usual
7838 escape listing above):
7839
7840 @smallexample
7841 @group
7842 $ @kbd{tar tf arch.tar --quoting-style=escape --quote-chars=' "'}
7843 ./
7844 ./a\ space
7845 ./a'single'quote
7846 ./a\"double\"quote
7847 ./a\\backslash
7848 ./a\ttab
7849 ./a\nnewline
7850 @end group
7851 @end smallexample
7852
7853 To disable quoting of such additional characters, use the following
7854 option:
7855
7856 @table @option
7857 @item --no-quote-chars=@var{string}
7858 Remove characters listed in @var{string} from the list of quoted
7859 characters set by the previous @option{--quote-chars} option.
7860 @end table
7861
7862 This option is particularly useful if you have added
7863 @option{--quote-chars} to your @env{TAR_OPTIONS} (@pxref{TAR_OPTIONS})
7864 and wish to disable it for the current invocation.
7865
7866 Note, that @option{--no-quote-chars} does @emph{not} disable those
7867 characters that are quoted by default in the selected quoting style.
7868
7869 @node transform
7870 @section Modifying File and Member Names
7871
7872 @command{Tar} archives contain detailed information about files stored
7873 in them and full file names are part of that information. When
7874 storing a file to an archive, its file name is recorded in it,
7875 along with the actual file contents. When restoring from an archive,
7876 a file is created on disk with exactly the same name as that stored
7877 in the archive. In the majority of cases this is the desired behavior
7878 of a file archiver. However, there are some cases when it is not.
7879
7880 First of all, it is often unsafe to extract archive members with
7881 absolute file names or those that begin with a @file{../}. @GNUTAR{}
7882 takes special precautions when extracting such names and provides a
7883 special option for handling them, which is described in
7884 @ref{absolute}.
7885
7886 Secondly, you may wish to extract file names without some leading
7887 directory components, or with otherwise modified names. In other
7888 cases it is desirable to store files under differing names in the
7889 archive.
7890
7891 @GNUTAR{} provides several options for these needs.
7892
7893 @table @option
7894 @opindex strip-components
7895 @item --strip-components=@var{number}
7896 Strip given @var{number} of leading components from file names before
7897 extraction.
7898 @end table
7899
7900 For example, suppose you have archived whole @file{/usr} hierarchy to
7901 a tar archive named @file{usr.tar}. Among other files, this archive
7902 contains @file{usr/include/stdlib.h}, which you wish to extract to
7903 the current working directory. To do so, you type:
7904
7905 @smallexample
7906 $ @kbd{tar -xf usr.tar --strip=2 usr/include/stdlib.h}
7907 @end smallexample
7908
7909 The option @option{--strip=2} instructs @command{tar} to strip the
7910 two leading components (@file{usr/} and @file{include/}) off the file
7911 name.
7912
7913 If you add the @option{--verbose} (@option{-v}) option to the invocation
7914 above, you will note that the verbose listing still contains the
7915 full file name, with the two removed components still in place. This
7916 can be inconvenient, so @command{tar} provides a special option for
7917 altering this behavior:
7918
7919 @anchor{show-transformed-names}
7920 @table @option
7921 @opindex show-transformed-names
7922 @item --show-transformed-names
7923 Display file or member names with all requested transformations
7924 applied.
7925 @end table
7926
7927 @noindent
7928 For example:
7929
7930 @smallexample
7931 @group
7932 $ @kbd{tar -xf usr.tar -v --strip=2 usr/include/stdlib.h}
7933 usr/include/stdlib.h
7934 $ @kbd{tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h}
7935 stdlib.h
7936 @end group
7937 @end smallexample
7938
7939 Notice that in both cases the file @file{stdlib.h} is extracted to the
7940 current working directory, @option{--show-transformed-names} affects
7941 only the way its name is displayed.
7942
7943 This option is especially useful for verifying whether the invocation
7944 will have the desired effect. Thus, before running
7945
7946 @smallexample
7947 $ @kbd{tar -x --strip=@var{n}}
7948 @end smallexample
7949
7950 @noindent
7951 it is often advisable to run
7952
7953 @smallexample
7954 $ @kbd{tar -t -v --show-transformed --strip=@var{n}}
7955 @end smallexample
7956
7957 @noindent
7958 to make sure the command will produce the intended results.
7959
7960 In case you need to apply more complex modifications to the file name,
7961 @GNUTAR{} provides a general-purpose transformation option:
7962
7963 @table @option
7964 @opindex transform
7965 @opindex xform
7966 @item --transform=@var{expression}
7967 @itemx --xform=@var{expression}
7968 Modify file names using supplied @var{expression}.
7969 @end table
7970
7971 @noindent
7972 The @var{expression} is a @command{sed}-like replace expression of the
7973 form:
7974
7975 @smallexample
7976 s/@var{regexp}/@var{replace}/[@var{flags}]
7977 @end smallexample
7978
7979 @noindent
7980 where @var{regexp} is a @dfn{regular expression}, @var{replace} is a
7981 replacement for each file name part that matches @var{regexp}. Both
7982 @var{regexp} and @var{replace} are described in detail in
7983 @ref{The "s" Command, The "s" Command, The `s' Command, sed, GNU sed}.
7984
7985 Any delimiter can be used in lieu of @samp{/}, the only requirement being
7986 that it be used consistently throughout the expression. For example,
7987 the following two expressions are equivalent:
7988
7989 @smallexample
7990 @group
7991 s/one/two/
7992 s,one,two,
7993 @end group
7994 @end smallexample
7995
7996 Changing delimiters is often useful when the @var{regex} contains
7997 slashes. For example, it is more convenient to write @code{s,/,-,} than
7998 @code{s/\//-/}.
7999
8000 As in @command{sed}, you can give several replace expressions,
8001 separated by a semicolon.
8002
8003 Supported @var{flags} are:
8004
8005 @table @samp
8006 @item g
8007 Apply the replacement to @emph{all} matches to the @var{regexp}, not
8008 just the first.
8009
8010 @item i
8011 Use case-insensitive matching.
8012
8013 @item x
8014 @var{regexp} is an @dfn{extended regular expression} (@pxref{Extended
8015 regexps, Extended regular expressions, Extended regular expressions,
8016 sed, GNU sed}).
8017
8018 @item @var{number}
8019 Only replace the @var{number}th match of the @var{regexp}.
8020
8021 Note: the @acronym{POSIX} standard does not specify what should happen
8022 when you mix the @samp{g} and @var{number} modifiers. @GNUTAR{}
8023 follows the GNU @command{sed} implementation in this regard, so
8024 the interaction is defined to be: ignore matches before the
8025 @var{number}th, and then match and replace all matches from the
8026 @var{number}th on.
8027
8028 @end table
8029
8030 In addition, several @dfn{transformation scope} flags are supported,
8031 that control to what files transformations apply. These are:
8032
8033 @table @samp
8034 @item r
8035 Apply transformation to regular archive members.
8036
8037 @item R
8038 Do not apply transformation to regular archive members.
8039
8040 @item s
8041 Apply transformation to symbolic link targets.
8042
8043 @item S
8044 Do not apply transformation to symbolic link targets.
8045
8046 @item h
8047 Apply transformation to hard link targets.
8048
8049 @item H
8050 Do not apply transformation to hard link targets.
8051 @end table
8052
8053 Default is @samp{rsh}, which means to apply tranformations to both archive
8054 members and targets of symbolic and hard links.
8055
8056 Default scope flags can also be changed using @samp{flags=} statement
8057 in the transform expression. The flags set this way remain in force
8058 until next @samp{flags=} statement or end of expression, whichever
8059 occurs first. For example:
8060
8061 @smallexample
8062 --transform 'flags=S;s|^|/usr/local/|'
8063 @end smallexample
8064
8065 Here are several examples of @option{--transform} usage:
8066
8067 @enumerate
8068 @item Extract @file{usr/} hierarchy into @file{usr/local/}:
8069
8070 @smallexample
8071 $ @kbd{tar --transform='s,usr/,usr/local/,' -x -f arch.tar}
8072 @end smallexample
8073
8074 @item Strip two leading directory components (equivalent to
8075 @option{--strip-components=2}):
8076
8077 @smallexample
8078 $ @kbd{tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar}
8079 @end smallexample
8080
8081 @item Convert each file name to lower case:
8082
8083 @smallexample
8084 $ @kbd{tar --transform 's/.*/\L&/' -x -f arch.tar}
8085 @end smallexample
8086
8087 @item Prepend @file{/prefix/} to each file name:
8088
8089 @smallexample
8090 $ @kbd{tar --transform 's,^,/prefix/,' -x -f arch.tar}
8091 @end smallexample
8092
8093 @item Archive the @file{/lib} directory, prepending @samp{/usr/local}
8094 to each archive member:
8095
8096 @smallexample
8097 $ @kbd{tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib}
8098 @end smallexample
8099 @end enumerate
8100
8101 Notice the use of flags in the last example. The @file{/lib}
8102 directory often contains many symbolic links to files within it.
8103 It may look, for example, like this:
8104
8105 @smallexample
8106 $ @kbd{ls -l}
8107 drwxr-xr-x root/root 0 2008-07-08 16:20 /lib/
8108 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
8109 lrwxrwxrwx root/root 0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
8110 ...
8111 @end smallexample
8112
8113 Using the expression @samp{s,^,/usr/local/,} would mean adding
8114 @samp{/usr/local} to both regular archive members and to link
8115 targets. In this case, @file{/lib/libc.so.6} would become:
8116
8117 @smallexample
8118 /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
8119 @end smallexample
8120
8121 This is definitely not desired. To avoid this, the @samp{S} flag
8122 is used, which excludes symbolic link targets from filename
8123 transformations. The result is:
8124
8125 @smallexample
8126 $ @kbd{tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
8127 --show-transformed /lib}
8128 drwxr-xr-x root/root 0 2008-07-08 16:20 /usr/local/lib/
8129 -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
8130 lrwxrwxrwx root/root 0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
8131 -> libc-2.3.2.so
8132 @end smallexample
8133
8134 Unlike @option{--strip-components}, @option{--transform} can be used
8135 in any @GNUTAR{} operation mode. For example, the following command
8136 adds files to the archive while replacing the leading @file{usr/}
8137 component with @file{var/}:
8138
8139 @smallexample
8140 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' /}
8141 @end smallexample
8142
8143 To test @option{--transform} effect we suggest using
8144 @option{--show-transformed-names} option:
8145
8146 @smallexample
8147 $ @kbd{tar -cf arch.tar --transform='s,^usr/,var/,' \
8148 --verbose --show-transformed-names /}
8149 @end smallexample
8150
8151 If both @option{--strip-components} and @option{--transform} are used
8152 together, then @option{--transform} is applied first, and the required
8153 number of components is then stripped from its result.
8154
8155 You can use as many @option{--transform} options in a single command
8156 line as you want. The specified expressions will then be applied in
8157 order of their appearance. For example, the following two invocations
8158 are equivalent:
8159
8160 @smallexample
8161 $ @kbd{tar -cf arch.tar --transform='s,/usr/var,/var/' \
8162 --transform='s,/usr/local,/usr/,'}
8163 $ @kbd{tar -cf arch.tar \
8164 --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'}
8165 @end smallexample
8166
8167 @node after
8168 @section Operating Only on New Files
8169
8170 @cindex Excluding file by age
8171 @cindex Data Modification time, excluding files by
8172 @cindex Modification time, excluding files by
8173 @cindex Age, excluding files by
8174 The @option{--after-date=@var{date}} (@option{--newer=@var{date}},
8175 @option{-N @var{date}}) option causes @command{tar} to only work on
8176 files whose data modification or status change times are newer than
8177 the @var{date} given. If @var{date} starts with @samp{/} or @samp{.},
8178 it is taken to be a file name; the data modification time of that file
8179 is used as the date. If you use this option when creating or appending
8180 to an archive, the archive will only include new files. If you use
8181 @option{--after-date} when extracting an archive, @command{tar} will
8182 only extract files newer than the @var{date} you specify.
8183
8184 If you only want @command{tar} to make the date comparison based on
8185 modification of the file's data (rather than status
8186 changes), then use the @option{--newer-mtime=@var{date}} option.
8187
8188 @cindex --after-date and --update compared
8189 @cindex --newer-mtime and --update compared
8190 You may use these options with any operation. Note that these options
8191 differ from the @option{--update} (@option{-u}) operation in that they
8192 allow you to specify a particular date against which @command{tar} can
8193 compare when deciding whether or not to archive the files.
8194
8195 @table @option
8196 @opindex after-date
8197 @opindex newer
8198 @item --after-date=@var{date}
8199 @itemx --newer=@var{date}
8200 @itemx -N @var{date}
8201 Only store files newer than @var{date}.
8202
8203 Acts on files only if their data modification or status change times are
8204 later than @var{date}. Use in conjunction with any operation.
8205
8206 If @var{date} starts with @samp{/} or @samp{.}, it is taken to be a file
8207 name; the data modification time of that file is used as the date.
8208
8209 @opindex newer-mtime
8210 @item --newer-mtime=@var{date}
8211 Acts like @option{--after-date}, but only looks at data modification times.
8212 @end table
8213
8214 These options limit @command{tar} to operate only on files which have
8215 been modified after the date specified. A file's status is considered to have
8216 changed if its contents have been modified, or if its owner,
8217 permissions, and so forth, have been changed. (For more information on
8218 how to specify a date, see @ref{Date input formats}; remember that the
8219 entire date argument must be quoted if it contains any spaces.)
8220
8221 Gurus would say that @option{--after-date} tests both the data
8222 modification time (@code{mtime}, the time the contents of the file
8223 were last modified) and the status change time (@code{ctime}, the time
8224 the file's status was last changed: owner, permissions, etc.@:)
8225 fields, while @option{--newer-mtime} tests only the @code{mtime}
8226 field.
8227
8228 To be precise, @option{--after-date} checks @emph{both} @code{mtime} and
8229 @code{ctime} and processes the file if either one is more recent than
8230 @var{date}, while @option{--newer-mtime} only checks @code{mtime} and
8231 disregards @code{ctime}. Neither does it use @code{atime} (the last time the
8232 contents of the file were looked at).
8233
8234 Date specifiers can have embedded spaces. Because of this, you may need
8235 to quote date arguments to keep the shell from parsing them as separate
8236 arguments. For example, the following command will add to the archive
8237 all the files modified less than two days ago:
8238
8239 @smallexample
8240 $ @kbd{tar -cf foo.tar --newer-mtime '2 days ago'}
8241 @end smallexample
8242
8243 When any of these options is used with the option @option{--verbose}
8244 (@pxref{verbose tutorial}) @GNUTAR{} will try to convert the specified
8245 date back to its textual representation and compare that with the
8246 one given with the option. If the two dates differ, @command{tar} will
8247 print a warning saying what date it will use. This is to help user
8248 ensure he is using the right date. For example:
8249
8250 @smallexample
8251 @group
8252 $ @kbd{tar -c -f archive.tar --after-date='10 days ago' .}
8253 tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
8254 13:19:37.232434
8255 @end group
8256 @end smallexample
8257
8258 @quotation
8259 @strong{Please Note:} @option{--after-date} and @option{--newer-mtime}
8260 should not be used for incremental backups. @xref{Incremental Dumps},
8261 for proper way of creating incremental backups.
8262 @end quotation
8263
8264 @node recurse
8265 @section Descending into Directories
8266 @cindex Avoiding recursion in directories
8267 @cindex Descending directories, avoiding
8268 @cindex Directories, avoiding recursion
8269 @cindex Recursion in directories, avoiding
8270
8271 Usually, @command{tar} will recursively explore all directories (either
8272 those given on the command line or through the @option{--files-from}
8273 option) for the various files they contain. However, you may not always
8274 want @command{tar} to act this way.
8275
8276 @opindex no-recursion
8277 @cindex @command{find}, using with @command{tar}
8278 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
8279 into specified directories. If you specify @option{--no-recursion}, you can
8280 use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
8281 utility for hunting through levels of directories to
8282 construct a list of file names which you could then pass to @command{tar}.
8283 @command{find} allows you to be more selective when choosing which files to
8284 archive; see @ref{files}, for more information on using @command{find} with
8285 @command{tar}.
8286
8287 @table @option
8288 @item --no-recursion
8289 Prevents @command{tar} from recursively descending directories.
8290
8291 @opindex recursion
8292 @item --recursion
8293 Requires @command{tar} to recursively descend directories.
8294 This is the default.
8295 @end table
8296
8297 When you use @option{--no-recursion}, @GNUTAR{} grabs
8298 directory entries themselves, but does not descend on them
8299 recursively. Many people use @command{find} for locating files they
8300 want to back up, and since @command{tar} @emph{usually} recursively
8301 descends on directories, they have to use the @samp{@w{-not -type d}}
8302 test in their @command{find} invocation (@pxref{Type, Type, Type test,
8303 find, Finding Files}), as they usually do not want all the files in a
8304 directory. They then use the @option{--files-from} option to archive
8305 the files located via @command{find}.
8306
8307 The problem when restoring files archived in this manner is that the
8308 directories themselves are not in the archive; so the
8309 @option{--same-permissions} (@option{--preserve-permissions},
8310 @option{-p}) option does not affect them---while users might really
8311 like it to. Specifying @option{--no-recursion} is a way to tell
8312 @command{tar} to grab only the directory entries given to it, adding
8313 no new files on its own. To summarize, if you use @command{find} to
8314 create a list of files to be stored in an archive, use it as follows:
8315
8316 @smallexample
8317 @group
8318 $ @kbd{find @var{dir} @var{tests} | \
8319 tar -cf @var{archive} -T - --no-recursion}
8320 @end group
8321 @end smallexample
8322
8323 The @option{--no-recursion} option also applies when extracting: it
8324 causes @command{tar} to extract only the matched directory entries, not
8325 the files under those directories.
8326
8327 The @option{--no-recursion} option also affects how globbing patterns
8328 are interpreted (@pxref{controlling pattern-matching}).
8329
8330 The @option{--no-recursion} and @option{--recursion} options apply to
8331 later options and operands, and can be overridden by later occurrences
8332 of @option{--no-recursion} and @option{--recursion}. For example:
8333
8334 @smallexample
8335 $ @kbd{tar -cf jams.tar --no-recursion grape --recursion grape/concord}
8336 @end smallexample
8337
8338 @noindent
8339 creates an archive with one entry for @file{grape}, and the recursive
8340 contents of @file{grape/concord}, but no entries under @file{grape}
8341 other than @file{grape/concord}.
8342
8343 @node one
8344 @section Crossing File System Boundaries
8345 @cindex File system boundaries, not crossing
8346
8347 @command{tar} will normally automatically cross file system boundaries in
8348 order to archive files which are part of a directory tree. You can
8349 change this behavior by running @command{tar} and specifying
8350 @option{--one-file-system}. This option only affects files that are
8351 archived because they are in a directory that is being archived;
8352 @command{tar} will still archive files explicitly named on the command line
8353 or through @option{--files-from}, regardless of where they reside.
8354
8355 @table @option
8356 @opindex one-file-system
8357 @item --one-file-system
8358 Prevents @command{tar} from crossing file system boundaries when
8359 archiving. Use in conjunction with any write operation.
8360 @end table
8361
8362 The @option{--one-file-system} option causes @command{tar} to modify its
8363 normal behavior in archiving the contents of directories. If a file in
8364 a directory is not on the same file system as the directory itself, then
8365 @command{tar} will not archive that file. If the file is a directory
8366 itself, @command{tar} will not archive anything beneath it; in other words,
8367 @command{tar} will not cross mount points.
8368
8369 This option is useful for making full or incremental archival backups of
8370 a file system. If this option is used in conjunction with
8371 @option{--verbose} (@option{-v}), files that are excluded are
8372 mentioned by name on the standard error.
8373
8374 @menu
8375 * directory:: Changing Directory
8376 * absolute:: Absolute File Names
8377 @end menu
8378
8379 @node directory
8380 @subsection Changing the Working Directory
8381
8382 @FIXME{need to read over this node now for continuity; i've switched
8383 things around some.}
8384
8385 @cindex Changing directory mid-stream
8386 @cindex Directory, changing mid-stream
8387 @cindex Working directory, specifying
8388 To change the working directory in the middle of a list of file names,
8389 either on the command line or in a file specified using
8390 @option{--files-from} (@option{-T}), use @option{--directory} (@option{-C}).
8391 This will change the working directory to the specified directory
8392 after that point in the list.
8393
8394 @table @option
8395 @opindex directory
8396 @item --directory=@var{directory}
8397 @itemx -C @var{directory}
8398 Changes the working directory in the middle of a command line.
8399 @end table
8400
8401 For example,
8402
8403 @smallexample
8404 $ @kbd{tar -c -f jams.tar grape prune -C food cherry}
8405 @end smallexample
8406
8407 @noindent
8408 will place the files @file{grape} and @file{prune} from the current
8409 directory into the archive @file{jams.tar}, followed by the file
8410 @file{cherry} from the directory @file{food}. This option is especially
8411 useful when you have several widely separated files that you want to
8412 store in the same archive.
8413
8414 Note that the file @file{cherry} is recorded in the archive under the
8415 precise name @file{cherry}, @emph{not} @file{food/cherry}. Thus, the
8416 archive will contain three files that all appear to have come from the
8417 same directory; if the archive is extracted with plain @samp{tar
8418 --extract}, all three files will be written in the current directory.
8419
8420 Contrast this with the command,
8421
8422 @smallexample
8423 $ @kbd{tar -c -f jams.tar grape prune -C food red/cherry}
8424 @end smallexample
8425
8426 @noindent
8427 which records the third file in the archive under the name
8428 @file{red/cherry} so that, if the archive is extracted using
8429 @samp{tar --extract}, the third file will be written in a subdirectory
8430 named @file{red}.
8431
8432 You can use the @option{--directory} option to make the archive
8433 independent of the original name of the directory holding the files.
8434 The following command places the files @file{/etc/passwd},
8435 @file{/etc/hosts}, and @file{/lib/libc.a} into the archive
8436 @file{foo.tar}:
8437
8438 @smallexample
8439 $ @kbd{tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a}
8440 @end smallexample
8441
8442 @noindent
8443 However, the names of the archive members will be exactly what they were
8444 on the command line: @file{passwd}, @file{hosts}, and @file{libc.a}.
8445 They will not appear to be related by file name to the original
8446 directories where those files were located.
8447
8448 Note that @option{--directory} options are interpreted consecutively. If
8449 @option{--directory} specifies a relative file name, it is interpreted
8450 relative to the then current directory, which might not be the same as
8451 the original current working directory of @command{tar}, due to a previous
8452 @option{--directory} option.
8453
8454 When using @option{--files-from} (@pxref{files}), you can put various
8455 @command{tar} options (including @option{-C}) in the file list. Notice,
8456 however, that in this case the option and its argument may not be
8457 separated by whitespace. If you use short option, its argument must
8458 either follow the option letter immediately, without any intervening
8459 whitespace, or occupy the next line. Otherwise, if you use long
8460 option, separate its argument by an equal sign.
8461
8462 For instance, the file list for the above example will be:
8463
8464 @smallexample
8465 @group
8466 -C/etc
8467 passwd
8468 hosts
8469 --directory=/lib
8470 libc.a
8471 @end group
8472 @end smallexample
8473
8474 @noindent
8475 To use it, you would invoke @command{tar} as follows:
8476
8477 @smallexample
8478 $ @kbd{tar -c -f foo.tar --files-from list}
8479 @end smallexample
8480
8481 The interpretation of @option{--directory} is disabled by
8482 @option{--null} option.
8483
8484 @node absolute
8485 @subsection Absolute File Names
8486 @cindex absolute file names
8487 @cindex file names, absolute
8488
8489 By default, @GNUTAR{} drops a leading @samp{/} on
8490 input or output, and complains about file names containing a @file{..}
8491 component. There is an option that turns off this behavior:
8492
8493 @table @option
8494 @opindex absolute-names
8495 @item --absolute-names
8496 @itemx -P
8497 Do not strip leading slashes from file names, and permit file names
8498 containing a @file{..} file name component.
8499 @end table
8500
8501 When @command{tar} extracts archive members from an archive, it strips any
8502 leading slashes (@samp{/}) from the member name. This causes absolute
8503 member names in the archive to be treated as relative file names. This
8504 allows you to have such members extracted wherever you want, instead of
8505 being restricted to extracting the member in the exact directory named
8506 in the archive. For example, if the archive member has the name
8507 @file{/etc/passwd}, @command{tar} will extract it as if the name were
8508 really @file{etc/passwd}.
8509
8510 File names containing @file{..} can cause problems when extracting, so
8511 @command{tar} normally warns you about such files when creating an
8512 archive, and rejects attempts to extracts such files.
8513
8514 Other @command{tar} programs do not do this. As a result, if you
8515 create an archive whose member names start with a slash, they will be
8516 difficult for other people with a non-@GNUTAR{}
8517 program to use. Therefore, @GNUTAR{} also strips
8518 leading slashes from member names when putting members into the
8519 archive. For example, if you ask @command{tar} to add the file
8520 @file{/bin/ls} to an archive, it will do so, but the member name will
8521 be @file{bin/ls}@footnote{A side effect of this is that when
8522 @option{--create} is used with @option{--verbose} the resulting output
8523 is not, generally speaking, the same as the one you'd get running
8524 @kbd{tar --list} command. This may be important if you use some
8525 scripts for comparing both outputs. @xref{listing member and file names},
8526 for the information on how to handle this case.}.
8527
8528 If you use the @option{--absolute-names} (@option{-P}) option,
8529 @command{tar} will do none of these transformations.
8530
8531 To archive or extract files relative to the root directory, specify
8532 the @option{--absolute-names} (@option{-P}) option.
8533
8534 Normally, @command{tar} acts on files relative to the working
8535 directory---ignoring superior directory names when archiving, and
8536 ignoring leading slashes when extracting.
8537
8538 When you specify @option{--absolute-names} (@option{-P}),
8539 @command{tar} stores file names including all superior directory
8540 names, and preserves leading slashes. If you only invoked
8541 @command{tar} from the root directory you would never need the
8542 @option{--absolute-names} option, but using this option
8543 may be more convenient than switching to root.
8544
8545 @FIXME{Should be an example in the tutorial/wizardry section using this
8546 to transfer files between systems.}
8547
8548 @table @option
8549 @item --absolute-names
8550 Preserves full file names (including superior directory names) when
8551 archiving files. Preserves leading slash when extracting files.
8552
8553 @end table
8554
8555 @command{tar} prints out a message about removing the @samp{/} from
8556 file names. This message appears once per @GNUTAR{}
8557 invocation. It represents something which ought to be told; ignoring
8558 what it means can cause very serious surprises, later.
8559
8560 Some people, nevertheless, do not want to see this message. Wanting to
8561 play really dangerously, one may of course redirect @command{tar} standard
8562 error to the sink. For example, under @command{sh}:
8563
8564 @smallexample
8565 $ @kbd{tar -c -f archive.tar /home 2> /dev/null}
8566 @end smallexample
8567
8568 @noindent
8569 Another solution, both nicer and simpler, would be to change to
8570 the @file{/} directory first, and then avoid absolute notation.
8571 For example:
8572
8573 @smallexample
8574 $ @kbd{tar -c -f archive.tar -C / home}
8575 @end smallexample
8576
8577 @xref{Integrity}, for some of the security-related implications
8578 of using this option.
8579
8580 @include parse-datetime.texi
8581
8582 @node Formats
8583 @chapter Controlling the Archive Format
8584
8585 @cindex Tar archive formats
8586 Due to historical reasons, there are several formats of tar archives.
8587 All of them are based on the same principles, but have some subtle
8588 differences that often make them incompatible with each other.
8589
8590 GNU tar is able to create and handle archives in a variety of formats.
8591 The most frequently used formats are (in alphabetical order):
8592
8593 @table @asis
8594 @item gnu
8595 Format used by @GNUTAR{} versions up to 1.13.25. This format derived
8596 from an early @acronym{POSIX} standard, adding some improvements such as
8597 sparse file handling and incremental archives. Unfortunately these
8598 features were implemented in a way incompatible with other archive
8599 formats.
8600
8601 Archives in @samp{gnu} format are able to hold file names of unlimited
8602 length.
8603
8604 @item oldgnu
8605 Format used by @GNUTAR{} of versions prior to 1.12.
8606
8607 @item v7
8608 Archive format, compatible with the V7 implementation of tar. This
8609 format imposes a number of limitations. The most important of them
8610 are:
8611
8612 @enumerate
8613 @item The maximum length of a file name is limited to 99 characters.
8614 @item The maximum length of a symbolic link is limited to 99 characters.
8615 @item It is impossible to store special files (block and character
8616 devices, fifos etc.)
8617 @item Maximum value of user or group @acronym{ID} is limited to 2097151 (7777777
8618 octal)
8619 @item V7 archives do not contain symbolic ownership information (user
8620 and group name of the file owner).
8621 @end enumerate
8622
8623 This format has traditionally been used by Automake when producing
8624 Makefiles. This practice will change in the future, in the meantime,
8625 however this means that projects containing file names more than 99
8626 characters long will not be able to use @GNUTAR{} @value{VERSION} and
8627 Automake prior to 1.9.
8628
8629 @item ustar
8630 Archive format defined by @acronym{POSIX.1-1988} specification. It stores
8631 symbolic ownership information. It is also able to store
8632 special files. However, it imposes several restrictions as well:
8633
8634 @enumerate
8635 @item The maximum length of a file name is limited to 256 characters,
8636 provided that the file name can be split at a directory separator in
8637 two parts, first of them being at most 155 bytes long. So, in most
8638 cases the maximum file name length will be shorter than 256
8639 characters.
8640 @item The maximum length of a symbolic link name is limited to
8641 100 characters.
8642 @item Maximum size of a file the archive is able to accommodate
8643 is 8GB
8644 @item Maximum value of UID/GID is 2097151.
8645 @item Maximum number of bits in device major and minor numbers is 21.
8646 @end enumerate
8647
8648 @item star
8649 Format used by J@"org Schilling @command{star}
8650 implementation. @GNUTAR{} is able to read @samp{star} archives but
8651 currently does not produce them.
8652
8653 @item posix
8654 Archive format defined by @acronym{POSIX.1-2001} specification. This is the
8655 most flexible and feature-rich format. It does not impose any
8656 restrictions on file sizes or file name lengths. This format is quite
8657 recent, so not all tar implementations are able to handle it properly.
8658 However, this format is designed in such a way that any tar
8659 implementation able to read @samp{ustar} archives will be able to read
8660 most @samp{posix} archives as well, with the only exception that any
8661 additional information (such as long file names etc.) will in such
8662 case be extracted as plain text files along with the files it refers to.
8663
8664 This archive format will be the default format for future versions
8665 of @GNUTAR{}.
8666
8667 @end table
8668
8669 The following table summarizes the limitations of each of these
8670 formats:
8671
8672 @multitable @columnfractions .10 .20 .20 .20 .20
8673 @headitem Format @tab UID @tab File Size @tab File Name @tab Devn
8674 @item gnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8675 @item oldgnu @tab 1.8e19 @tab Unlimited @tab Unlimited @tab 63
8676 @item v7 @tab 2097151 @tab 8GB @tab 99 @tab n/a
8677 @item ustar @tab 2097151 @tab 8GB @tab 256 @tab 21
8678 @item posix @tab Unlimited @tab Unlimited @tab Unlimited @tab Unlimited
8679 @end multitable
8680
8681 The default format for @GNUTAR{} is defined at compilation
8682 time. You may check it by running @command{tar --help}, and examining
8683 the last lines of its output. Usually, @GNUTAR{} is configured
8684 to create archives in @samp{gnu} format, however, future version will
8685 switch to @samp{posix}.
8686
8687 @menu
8688 * Compression:: Using Less Space through Compression
8689 * Attributes:: Handling File Attributes
8690 * Portability:: Making @command{tar} Archives More Portable
8691 * cpio:: Comparison of @command{tar} and @command{cpio}
8692 @end menu
8693
8694 @node Compression
8695 @section Using Less Space through Compression
8696
8697 @menu
8698 * gzip:: Creating and Reading Compressed Archives
8699 * sparse:: Archiving Sparse Files
8700 @end menu
8701
8702 @node gzip
8703 @subsection Creating and Reading Compressed Archives
8704 @cindex Compressed archives
8705 @cindex Storing archives in compressed format
8706
8707 @cindex gzip
8708 @cindex bzip2
8709 @cindex lzip
8710 @cindex lzma
8711 @cindex lzop
8712 @cindex compress
8713 @GNUTAR{} is able to create and read compressed archives. It supports
8714 a wide variety of compression programs, namely: @command{gzip},
8715 @command{bzip2}, @command{lzip}, @command{lzma}, @command{lzop},
8716 @command{xz} and traditional @command{compress}. The latter is
8717 supported mostly for backward compatibility, and we recommend
8718 against using it, because it is by far less effective than the other
8719 compression programs@footnote{It also had patent problems in the past.}.
8720
8721 Creating a compressed archive is simple: you just specify a
8722 @dfn{compression option} along with the usual archive creation
8723 commands. The compression option is @option{-z} (@option{--gzip}) to
8724 create a @command{gzip} compressed archive, @option{-j}
8725 (@option{--bzip2}) to create a @command{bzip2} compressed archive,
8726 @option{--lzip} to create an @asis{lzip} compressed archive,
8727 @option{-J} (@option{--xz}) to create an @asis{XZ} archive,
8728 @option{--lzma} to create an @asis{LZMA} compressed
8729 archive, @option{--lzop} to create an @asis{LSOP} archive, and
8730 @option{-Z} (@option{--compress}) to use @command{compress} program.
8731 For example:
8732
8733 @smallexample
8734 $ @kbd{tar cfz archive.tar.gz .}
8735 @end smallexample
8736
8737 You can also let @GNUTAR{} select the compression program based on
8738 the suffix of the archive file name. This is done using
8739 @option{--auto-compress} (@option{-a}) command line option. For
8740 example, the following invocation will use @command{bzip2} for
8741 compression:
8742
8743 @smallexample
8744 $ @kbd{tar cfa archive.tar.bz2 .}
8745 @end smallexample
8746
8747 @noindent
8748 whereas the following one will use @command{lzma}:
8749
8750 @smallexample
8751 $ @kbd{tar cfa archive.tar.lzma .}
8752 @end smallexample
8753
8754 For a complete list of file name suffixes recognized by @GNUTAR{},
8755 see @ref{auto-compress}.
8756
8757 Reading compressed archive is even simpler: you don't need to specify
8758 any additional options as @GNUTAR{} recognizes its format
8759 automatically. Thus, the following commands will list and extract the
8760 archive created in previous example:
8761
8762 @smallexample
8763 # List the compressed archive
8764 $ @kbd{tar tf archive.tar.gz}
8765 # Extract the compressed archive
8766 $ @kbd{tar xf archive.tar.gz}
8767 @end smallexample
8768
8769 The format recognition algorithm is based on @dfn{signatures}, a
8770 special byte sequences in the beginning of file, that are specific for
8771 certain compression formats. If this approach fails, @command{tar}
8772 falls back to using archive name suffix to determine its format
8773 (@pxref{auto-compress}, for a list of recognized suffixes).
8774
8775 @anchor{alternative decompression programs}
8776 @cindex alternative decompression programs
8777 Some compression programs are able to handle different compression
8778 formats. @GNUTAR{} uses this, if the principal decompressor for the
8779 given format is not available. For example, if @command{compress} is
8780 not installed, @command{tar} will try to use @command{gzip}. As of
8781 version @value{VERSION} the following alternatives are
8782 tried@footnote{To verbosely trace the decompressor selection, use the
8783 @option{--warning=decompress-program} option
8784 (@pxref{warnings,decompress-program}).}:
8785
8786 @multitable @columnfractions 0.3 0.3 0.3
8787 @headitem Format @tab Main decompressor @tab Alternatives
8788 @item compress @tab compress @tab gzip
8789 @item lzma @tab lzma @tab xz
8790 @item bzip2 @tab bzip2 @tab lbzip2
8791 @end multitable
8792
8793 The only case when you have to specify a decompression option while
8794 reading the archive is when reading from a pipe or from a tape drive
8795 that does not support random access. However, in this case @GNUTAR{}
8796 will indicate which option you should use. For example:
8797
8798 @smallexample
8799 $ @kbd{cat archive.tar.gz | tar tf -}
8800 tar: Archive is compressed. Use -z option
8801 tar: Error is not recoverable: exiting now
8802 @end smallexample
8803
8804 If you see such diagnostics, just add the suggested option to the
8805 invocation of @GNUTAR{}:
8806
8807 @smallexample
8808 $ @kbd{cat archive.tar.gz | tar tfz -}
8809 @end smallexample
8810
8811 Notice also, that there are several restrictions on operations on
8812 compressed archives. First of all, compressed archives cannot be
8813 modified, i.e., you cannot update (@option{--update}, alias @option{-u})
8814 them or delete (@option{--delete}) members from them or
8815 add (@option{--append}, alias @option{-r}) members to them. Likewise, you
8816 cannot append another @command{tar} archive to a compressed archive using
8817 @option{--concatenate} (@option{-A}). Secondly, multi-volume
8818 archives cannot be compressed.
8819
8820 The following options allow to select a particular compressor program:
8821
8822 @table @option
8823 @opindex gzip
8824 @opindex ungzip
8825 @item -z
8826 @itemx --gzip
8827 @itemx --ungzip
8828 Filter the archive through @command{gzip}.
8829
8830 @opindex xz
8831 @item -J
8832 @itemx --xz
8833 Filter the archive through @code{xz}.
8834
8835 @item -j
8836 @itemx --bzip2
8837 Filter the archive through @code{bzip2}.
8838
8839 @opindex lzip
8840 @item --lzip
8841 Filter the archive through @command{lzip}.
8842
8843 @opindex lzma
8844 @item --lzma
8845 Filter the archive through @command{lzma}.
8846
8847 @opindex lzop
8848 @item --lzop
8849 Filter the archive through @command{lzop}.
8850
8851 @opindex compress
8852 @opindex uncompress
8853 @item -Z
8854 @itemx --compress
8855 @itemx --uncompress
8856 Filter the archive through @command{compress}.
8857 @end table
8858
8859 When any of these options is given, @GNUTAR{} searches the compressor
8860 binary in the current path and invokes it. The name of the compressor
8861 program is specified at compilation time using a corresponding
8862 @option{--with-@var{compname}} option to @command{configure}, e.g.
8863 @option{--with-bzip2} to select a specific @command{bzip2} binary.
8864 @xref{lbzip2}, for a detailed discussion.
8865
8866 The output produced by @command{tar --help} shows the actual
8867 compressor names along with each of these options.
8868
8869 You can use any of these options on physical devices (tape drives,
8870 etc.) and remote files as well as on normal files; data to or from
8871 such devices or remote files is reblocked by another copy of the
8872 @command{tar} program to enforce the specified (or default) record
8873 size. The default compression parameters are used. Most compression
8874 programs allow to override these by setting a program-specific
8875 environment variable. For example, when using @command{gzip} you can
8876 use @env{GZIP} as in the example below:
8877
8878 @smallexample
8879 $ @kbd{GZIP=--best tar cfz archive.tar.gz subdir}
8880 @end smallexample
8881
8882 @noindent
8883 Another way would be to use the @option{-I} option instead (see
8884 below), e.g.:
8885
8886 @smallexample
8887 $ @kbd{tar -cf archive.tar.gz -I 'gzip --best' subdir}
8888 @end smallexample
8889
8890 @noindent
8891 Finally, the third, traditional, way to achieve the same result is to
8892 use pipe:
8893
8894 @smallexample
8895 $ @kbd{tar cf - subdir | gzip --best -c - > archive.tar.gz}
8896 @end smallexample
8897
8898 @cindex corrupted archives
8899 About corrupted compressed archives: compressed files have no
8900 redundancy, for maximum compression. The adaptive nature of the
8901 compression scheme means that the compression tables are implicitly
8902 spread all over the archive. If you lose a few blocks, the dynamic
8903 construction of the compression tables becomes unsynchronized, and there
8904 is little chance that you could recover later in the archive.
8905
8906 Another compression options provide a better control over creating
8907 compressed archives. These are:
8908
8909 @table @option
8910 @anchor{auto-compress}
8911 @opindex auto-compress
8912 @item --auto-compress
8913 @itemx -a
8914 Select a compression program to use by the archive file name
8915 suffix. The following suffixes are recognized:
8916
8917 @multitable @columnfractions 0.3 0.6
8918 @headitem Suffix @tab Compression program
8919 @item @samp{.gz} @tab @command{gzip}
8920 @item @samp{.tgz} @tab @command{gzip}
8921 @item @samp{.taz} @tab @command{gzip}
8922 @item @samp{.Z} @tab @command{compress}
8923 @item @samp{.taZ} @tab @command{compress}
8924 @item @samp{.bz2} @tab @command{bzip2}
8925 @item @samp{.tz2} @tab @command{bzip2}
8926 @item @samp{.tbz2} @tab @command{bzip2}
8927 @item @samp{.tbz} @tab @command{bzip2}
8928 @item @samp{.lz} @tab @command{lzip}
8929 @item @samp{.lzma} @tab @command{lzma}
8930 @item @samp{.tlz} @tab @command{lzma}
8931 @item @samp{.lzo} @tab @command{lzop}
8932 @item @samp{.xz} @tab @command{xz}
8933 @end multitable
8934
8935 @opindex use-compress-program
8936 @item --use-compress-program=@var{prog}
8937 @itemx -I=@var{prog}
8938 Use external compression program @var{prog}. Use this option if you
8939 are not happy with the compression program associated with the suffix
8940 at compile time or if you have a compression program that @GNUTAR{}
8941 does not support. There are two requirements to which @var{prog}
8942 should comply:
8943
8944 First, when called without options, it should read data from standard
8945 input, compress it and output it on standard output.
8946
8947 Secondly, if called with @option{-d} argument, it should do exactly
8948 the opposite, i.e., read the compressed data from the standard input
8949 and produce uncompressed data on the standard output.
8950 @end table
8951
8952 @cindex gpg, using with tar
8953 @cindex gnupg, using with tar
8954 @cindex Using encrypted archives
8955 The @option{--use-compress-program} option, in particular, lets you
8956 implement your own filters, not necessarily dealing with
8957 compression/decompression. For example, suppose you wish to implement
8958 PGP encryption on top of compression, using @command{gpg} (@pxref{Top,
8959 gpg, gpg ---- encryption and signing tool, gpg, GNU Privacy Guard
8960 Manual}). The following script does that:
8961
8962 @smallexample
8963 @group
8964 #! /bin/sh
8965 case $1 in
8966 -d) gpg --decrypt - | gzip -d -c;;
8967 '') gzip -c | gpg -s;;
8968 *) echo "Unknown option $1">&2; exit 1;;
8969 esac
8970 @end group
8971 @end smallexample
8972
8973 Suppose you name it @file{gpgz} and save it somewhere in your
8974 @env{PATH}. Then the following command will create a compressed
8975 archive signed with your private key:
8976
8977 @smallexample
8978 $ @kbd{tar -cf foo.tar.gpgz -Igpgz .}
8979 @end smallexample
8980
8981 @noindent
8982 Likewise, the command below will list its contents:
8983
8984 @smallexample
8985 $ @kbd{tar -tf foo.tar.gpgz -Igpgz .}
8986 @end smallexample
8987
8988 @ignore
8989 The above is based on the following discussion:
8990
8991 I have one question, or maybe it's a suggestion if there isn't a way
8992 to do it now. I would like to use @option{--gzip}, but I'd also like
8993 the output to be fed through a program like @acronym{GNU}
8994 @command{ecc} (actually, right now that's @samp{exactly} what I'd like
8995 to use :-)), basically adding ECC protection on top of compression.
8996 It seems as if this should be quite easy to do, but I can't work out
8997 exactly how to go about it. Of course, I can pipe the standard output
8998 of @command{tar} through @command{ecc}, but then I lose (though I
8999 haven't started using it yet, I confess) the ability to have
9000 @command{tar} use @command{rmt} for it's I/O (I think).
9001
9002 I think the most straightforward thing would be to let me specify a
9003 general set of filters outboard of compression (preferably ordered,
9004 so the order can be automatically reversed on input operations, and
9005 with the options they require specifiable), but beggars shouldn't be
9006 choosers and anything you decide on would be fine with me.
9007
9008 By the way, I like @command{ecc} but if (as the comments say) it can't
9009 deal with loss of block sync, I'm tempted to throw some time at adding
9010 that capability. Supposing I were to actually do such a thing and
9011 get it (apparently) working, do you accept contributed changes to
9012 utilities like that? (Leigh Clayton @file{loc@@soliton.com}, May 1995).
9013
9014 Isn't that exactly the role of the
9015 @option{--use-compress-prog=@var{program}} option?
9016 I never tried it myself, but I suspect you may want to write a
9017 @var{prog} script or program able to filter stdin to stdout to
9018 way you want. It should recognize the @option{-d} option, for when
9019 extraction is needed rather than creation.
9020
9021 It has been reported that if one writes compressed data (through the
9022 @option{--gzip} or @option{--compress} options) to a DLT and tries to use
9023 the DLT compression mode, the data will actually get bigger and one will
9024 end up with less space on the tape.
9025 @end ignore
9026
9027 @menu
9028 * lbzip2:: Using lbzip2 with @GNUTAR{}.
9029 @end menu
9030
9031 @node lbzip2
9032 @subsubsection Using lbzip2 with @GNUTAR{}.
9033 @cindex lbzip2
9034 @cindex Laszlo Ersek
9035 @command{Lbzip2} is a multithreaded utility for handling
9036 @samp{bzip2} compression, written by Laszlo Ersek. It makes use of
9037 multiple processors to speed up its operation and in general works
9038 considerably faster than @command{bzip2}. For a detailed description
9039 of @command{lbzip2} see @uref{http://freshmeat.net/@/projects/@/lbzip2} and
9040 @uref{http://www.linuxinsight.com/@/lbzip2-parallel-bzip2-utility.html,
9041 lbzip2: parallel bzip2 utility}.
9042
9043 Recent versions of @command{lbzip2} are mostly command line compatible
9044 with @command{bzip2}, which makes it possible to automatically invoke
9045 it via the @option{--bzip2} @GNUTAR{} command line option. To do so,
9046 @GNUTAR{} must be configured with the @option{--with-bzip2} command
9047 line option, like this:
9048
9049 @smallexample
9050 $ @kbd{./configure --with-bzip2=lbzip2 [@var{other-options}]}
9051 @end smallexample
9052
9053 Once configured and compiled this way, @command{tar --help} will show the
9054 following:
9055
9056 @smallexample
9057 @group
9058 $ @kbd{tar --help | grep -- --bzip2}
9059 -j, --bzip2 filter the archive through lbzip2
9060 @end group
9061 @end smallexample
9062
9063 @noindent
9064 which means that running @command{tar --bzip2} will invoke @command{lbzip2}.
9065
9066 @node sparse
9067 @subsection Archiving Sparse Files
9068 @cindex Sparse Files
9069
9070 Files in the file system occasionally have @dfn{holes}. A @dfn{hole}
9071 in a file is a section of the file's contents which was never written.
9072 The contents of a hole reads as all zeros. On many operating systems,
9073 actual disk storage is not allocated for holes, but they are counted
9074 in the length of the file. If you archive such a file, @command{tar}
9075 could create an archive longer than the original. To have @command{tar}
9076 attempt to recognize the holes in a file, use @option{--sparse}
9077 (@option{-S}). When you use this option, then, for any file using
9078 less disk space than would be expected from its length, @command{tar}
9079 searches the file for consecutive stretches of zeros. It then records
9080 in the archive for the file where the consecutive stretches of zeros
9081 are, and only archives the ``real contents'' of the file. On
9082 extraction (using @option{--sparse} is not needed on extraction) any
9083 such files have holes created wherever the continuous stretches of zeros
9084 were found. Thus, if you use @option{--sparse}, @command{tar} archives
9085 won't take more space than the original.
9086
9087 @table @option
9088 @opindex sparse
9089 @item -S
9090 @itemx --sparse
9091 This option instructs @command{tar} to test each file for sparseness
9092 before attempting to archive it. If the file is found to be sparse it
9093 is treated specially, thus allowing to decrease the amount of space
9094 used by its image in the archive.
9095
9096 This option is meaningful only when creating or updating archives. It
9097 has no effect on extraction.
9098 @end table
9099
9100 Consider using @option{--sparse} when performing file system backups,
9101 to avoid archiving the expanded forms of files stored sparsely in the
9102 system.
9103
9104 Even if your system has no sparse files currently, some may be
9105 created in the future. If you use @option{--sparse} while making file
9106 system backups as a matter of course, you can be assured the archive
9107 will never take more space on the media than the files take on disk
9108 (otherwise, archiving a disk filled with sparse files might take
9109 hundreds of tapes). @xref{Incremental Dumps}.
9110
9111 However, be aware that @option{--sparse} option presents a serious
9112 drawback. Namely, in order to determine if the file is sparse
9113 @command{tar} has to read it before trying to archive it, so in total
9114 the file is read @strong{twice}. So, always bear in mind that the
9115 time needed to process all files with this option is roughly twice
9116 the time needed to archive them without it.
9117 @FIXME{A technical note:
9118
9119 Programs like @command{dump} do not have to read the entire file; by
9120 examining the file system directly, they can determine in advance
9121 exactly where the holes are and thus avoid reading through them. The
9122 only data it need read are the actual allocated data blocks.
9123 @GNUTAR{} uses a more portable and straightforward
9124 archiving approach, it would be fairly difficult that it does
9125 otherwise. Elizabeth Zwicky writes to @file{comp.unix.internals}, on
9126 1990-12-10:
9127
9128 @quotation
9129 What I did say is that you cannot tell the difference between a hole and an
9130 equivalent number of nulls without reading raw blocks. @code{st_blocks} at
9131 best tells you how many holes there are; it doesn't tell you @emph{where}.
9132 Just as programs may, conceivably, care what @code{st_blocks} is (care
9133 to name one that does?), they may also care where the holes are (I have
9134 no examples of this one either, but it's equally imaginable).
9135
9136 I conclude from this that good archivers are not portable. One can
9137 arguably conclude that if you want a portable program, you can in good
9138 conscience restore files with as many holes as possible, since you can't
9139 get it right.
9140 @end quotation
9141 }
9142
9143 @cindex sparse formats, defined
9144 When using @samp{POSIX} archive format, @GNUTAR{} is able to store
9145 sparse files using in three distinct ways, called @dfn{sparse
9146 formats}. A sparse format is identified by its @dfn{number},
9147 consisting, as usual of two decimal numbers, delimited by a dot. By
9148 default, format @samp{1.0} is used. If, for some reason, you wish to
9149 use an earlier format, you can select it using
9150 @option{--sparse-version} option.
9151
9152 @table @option
9153 @opindex sparse-version
9154 @item --sparse-version=@var{version}
9155
9156 Select the format to store sparse files in. Valid @var{version} values
9157 are: @samp{0.0}, @samp{0.1} and @samp{1.0}. @xref{Sparse Formats},
9158 for a detailed description of each format.
9159 @end table
9160
9161 Using @option{--sparse-format} option implies @option{--sparse}.
9162
9163 @node Attributes
9164 @section Handling File Attributes
9165 @cindex atrributes, files
9166 @cindex file attributes
9167
9168 When @command{tar} reads files, it updates their access times. To
9169 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
9170 reset the access time retroactively or avoid changing it in the first
9171 place.
9172
9173 @table @option
9174 @opindex atime-preserve
9175 @item --atime-preserve
9176 @itemx --atime-preserve=replace
9177 @itemx --atime-preserve=system
9178 Preserve the access times of files that are read. This works only for
9179 files that you own, unless you have superuser privileges.
9180
9181 @option{--atime-preserve=replace} works on most systems, but it also
9182 restores the data modification time and updates the status change
9183 time. Hence it doesn't interact with incremental dumps nicely
9184 (@pxref{Incremental Dumps}), and it can set access or data modification times
9185 incorrectly if other programs access the file while @command{tar} is
9186 running.
9187
9188 @option{--atime-preserve=system} avoids changing the access time in
9189 the first place, if the operating system supports this.
9190 Unfortunately, this may or may not work on any given operating system
9191 or file system. If @command{tar} knows for sure it won't work, it
9192 complains right away.
9193
9194 Currently @option{--atime-preserve} with no operand defaults to
9195 @option{--atime-preserve=replace}, but this is intended to change to
9196 @option{--atime-preserve=system} when the latter is better-supported.
9197
9198 @opindex touch
9199 @item -m
9200 @itemx --touch
9201 Do not extract data modification time.
9202
9203 When this option is used, @command{tar} leaves the data modification times
9204 of the files it extracts as the times when the files were extracted,
9205 instead of setting it to the times recorded in the archive.
9206
9207 This option is meaningless with @option{--list} (@option{-t}).
9208
9209 @opindex same-owner
9210 @item --same-owner
9211 Create extracted files with the same ownership they have in the
9212 archive.
9213
9214 This is the default behavior for the superuser,
9215 so this option is meaningful only for non-root users, when @command{tar}
9216 is executed on those systems able to give files away. This is
9217 considered as a security flaw by many people, at least because it
9218 makes quite difficult to correctly account users for the disk space
9219 they occupy. Also, the @code{suid} or @code{sgid} attributes of
9220 files are easily and silently lost when files are given away.
9221
9222 When writing an archive, @command{tar} writes the user @acronym{ID} and user name
9223 separately. If it can't find a user name (because the user @acronym{ID} is not
9224 in @file{/etc/passwd}), then it does not write one. When restoring,
9225 it tries to look the name (if one was written) up in
9226 @file{/etc/passwd}. If it fails, then it uses the user @acronym{ID} stored in
9227 the archive instead.
9228
9229 @opindex no-same-owner
9230 @item --no-same-owner
9231 @itemx -o
9232 Do not attempt to restore ownership when extracting. This is the
9233 default behavior for ordinary users, so this option has an effect
9234 only for the superuser.
9235
9236 @opindex numeric-owner
9237 @item --numeric-owner
9238 The @option{--numeric-owner} option allows (ANSI) archives to be written
9239 without user/group name information or such information to be ignored
9240 when extracting. It effectively disables the generation and/or use
9241 of user/group name information. This option forces extraction using
9242 the numeric ids from the archive, ignoring the names.
9243
9244 This is useful in certain circumstances, when restoring a backup from
9245 an emergency floppy with different passwd/group files for example.
9246 It is otherwise impossible to extract files with the right ownerships
9247 if the password file in use during the extraction does not match the
9248 one belonging to the file system(s) being extracted. This occurs,
9249 for example, if you are restoring your files after a major crash and
9250 had booted from an emergency floppy with no password file or put your
9251 disk into another machine to do the restore.
9252
9253 The numeric ids are @emph{always} saved into @command{tar} archives.
9254 The identifying names are added at create time when provided by the
9255 system, unless @option{--format=oldgnu} is used. Numeric ids could be
9256 used when moving archives between a collection of machines using
9257 a centralized management for attribution of numeric ids to users
9258 and groups. This is often made through using the NIS capabilities.
9259
9260 When making a @command{tar} file for distribution to other sites, it
9261 is sometimes cleaner to use a single owner for all files in the
9262 distribution, and nicer to specify the write permission bits of the
9263 files as stored in the archive independently of their actual value on
9264 the file system. The way to prepare a clean distribution is usually
9265 to have some Makefile rule creating a directory, copying all needed
9266 files in that directory, then setting ownership and permissions as
9267 wanted (there are a lot of possible schemes), and only then making a
9268 @command{tar} archive out of this directory, before cleaning
9269 everything out. Of course, we could add a lot of options to
9270 @GNUTAR{} for fine tuning permissions and ownership.
9271 This is not the good way, I think. @GNUTAR{} is
9272 already crowded with options and moreover, the approach just explained
9273 gives you a great deal of control already.
9274
9275 @xopindex{same-permissions, short description}
9276 @xopindex{preserve-permissions, short description}
9277 @item -p
9278 @itemx --same-permissions
9279 @itemx --preserve-permissions
9280 Extract all protection information.
9281
9282 This option causes @command{tar} to set the modes (access permissions) of
9283 extracted files exactly as recorded in the archive. If this option
9284 is not used, the current @code{umask} setting limits the permissions
9285 on extracted files. This option is by default enabled when
9286 @command{tar} is executed by a superuser.
9287
9288
9289 This option is meaningless with @option{--list} (@option{-t}).
9290
9291 @opindex preserve
9292 @item --preserve
9293 Same as both @option{--same-permissions} and @option{--same-order}.
9294
9295 This option is deprecated, and will be removed in @GNUTAR{} version 1.23.
9296
9297 @end table
9298
9299 @node Portability
9300 @section Making @command{tar} Archives More Portable
9301
9302 Creating a @command{tar} archive on a particular system that is meant to be
9303 useful later on many other machines and with other versions of @command{tar}
9304 is more challenging than you might think. @command{tar} archive formats
9305 have been evolving since the first versions of Unix. Many such formats
9306 are around, and are not always compatible with each other. This section
9307 discusses a few problems, and gives some advice about making @command{tar}
9308 archives more portable.
9309
9310 One golden rule is simplicity. For example, limit your @command{tar}
9311 archives to contain only regular files and directories, avoiding
9312 other kind of special files. Do not attempt to save sparse files or
9313 contiguous files as such. Let's discuss a few more problems, in turn.
9314
9315 @FIXME{Discuss GNU extensions (incremental backups, multi-volume
9316 archives and archive labels) in GNU and PAX formats.}
9317
9318 @menu
9319 * Portable Names:: Portable Names
9320 * dereference:: Symbolic Links
9321 * hard links:: Hard Links
9322 * old:: Old V7 Archives
9323 * ustar:: Ustar Archives
9324 * gnu:: GNU and old GNU format archives.
9325 * posix:: @acronym{POSIX} archives
9326 * Checksumming:: Checksumming Problems
9327 * Large or Negative Values:: Large files, negative time stamps, etc.
9328 * Other Tars:: How to Extract GNU-Specific Data Using
9329 Other @command{tar} Implementations
9330 @end menu
9331
9332 @node Portable Names
9333 @subsection Portable Names
9334
9335 Use portable file and member names. A name is portable if it contains
9336 only @acronym{ASCII} letters and digits, @samp{/}, @samp{.}, @samp{_}, and
9337 @samp{-}; it cannot be empty, start with @samp{-} or @samp{//}, or
9338 contain @samp{/-}. Avoid deep directory nesting. For portability to
9339 old Unix hosts, limit your file name components to 14 characters or
9340 less.
9341
9342 If you intend to have your @command{tar} archives to be read under
9343 MSDOS, you should not rely on case distinction for file names, and you
9344 might use the @acronym{GNU} @command{doschk} program for helping you
9345 further diagnosing illegal MSDOS names, which are even more limited
9346 than System V's.
9347
9348 @node dereference
9349 @subsection Symbolic Links
9350 @cindex File names, using symbolic links
9351 @cindex Symbolic link as file name
9352
9353 @opindex dereference
9354 Normally, when @command{tar} archives a symbolic link, it writes a
9355 block to the archive naming the target of the link. In that way, the
9356 @command{tar} archive is a faithful record of the file system contents.
9357 When @option{--dereference} (@option{-h}) is used with
9358 @option{--create} (@option{-c}), @command{tar} archives the files
9359 symbolic links point to, instead of
9360 the links themselves.
9361
9362 When creating portable archives, use @option{--dereference}
9363 (@option{-h}): some systems do not support
9364 symbolic links, and moreover, your distribution might be unusable if
9365 it contains unresolved symbolic links.
9366
9367 When reading from an archive, the @option{--dereference} (@option{-h})
9368 option causes @command{tar} to follow an already-existing symbolic
9369 link when @command{tar} writes or reads a file named in the archive.
9370 Ordinarily, @command{tar} does not follow such a link, though it may
9371 remove the link before writing a new file. @xref{Dealing with Old
9372 Files}.
9373
9374 The @option{--dereference} option is unsafe if an untrusted user can
9375 modify directories while @command{tar} is running. @xref{Security}.
9376
9377 @node hard links
9378 @subsection Hard Links
9379 @cindex File names, using hard links
9380 @cindex hard links, dereferencing
9381 @cindex dereferencing hard links
9382
9383 Normally, when @command{tar} archives a hard link, it writes a
9384 block to the archive naming the target of the link (a @samp{1} type
9385 block). In that way, the actual file contents is stored in file only
9386 once. For example, consider the following two files:
9387
9388 @smallexample
9389 @group
9390 $ ls
9391 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one
9392 -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
9393 @end group
9394 @end smallexample
9395
9396 Here, @file{jeden} is a link to @file{one}. When archiving this
9397 directory with a verbose level 2, you will get an output similar to
9398 the following:
9399
9400 @smallexample
9401 $ tar cfvv ../archive.tar .
9402 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9403 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9404 hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
9405 @end smallexample
9406
9407 The last line shows that, instead of storing two copies of the file,
9408 @command{tar} stored it only once, under the name @file{jeden}, and
9409 stored file @file{one} as a hard link to this file.
9410
9411 It may be important to know that all hard links to the given file are
9412 stored in the archive. For example, this may be necessary for exact
9413 reproduction of the file system. The following option does that:
9414
9415 @table @option
9416 @xopindex{check-links, described}
9417 @item --check-links
9418 @itemx -l
9419 Check the number of links dumped for each processed file. If this
9420 number does not match the total number of hard links for the file, print
9421 a warning message.
9422 @end table
9423
9424 For example, trying to archive only file @file{jeden} with this option
9425 produces the following diagnostics:
9426
9427 @smallexample
9428 $ tar -c -f ../archive.tar -l jeden
9429 tar: Missing links to `jeden'.
9430 @end smallexample
9431
9432 Although creating special records for hard links helps keep a faithful
9433 record of the file system contents and makes archives more compact, it
9434 may present some difficulties when extracting individual members from
9435 the archive. For example, trying to extract file @file{one} from the
9436 archive created in previous examples produces, in the absense of file
9437 @file{jeden}:
9438
9439 @smallexample
9440 $ tar xf archive.tar ./one
9441 tar: ./one: Cannot hard link to `./jeden': No such file or directory
9442 tar: Error exit delayed from previous errors
9443 @end smallexample
9444
9445 The reason for this behavior is that @command{tar} cannot seek back in
9446 the archive to the previous member (in this case, @file{one}), to
9447 extract it@footnote{There are plans to fix this in future releases.}.
9448 If you wish to avoid such problems at the cost of a bigger archive,
9449 use the following option:
9450
9451 @table @option
9452 @xopindex{hard-dereference, described}
9453 @item --hard-dereference
9454 Dereference hard links and store the files they refer to.
9455 @end table
9456
9457 For example, trying this option on our two sample files, we get two
9458 copies in the archive, each of which can then be extracted
9459 independently of the other:
9460
9461 @smallexample
9462 @group
9463 $ tar -c -vv -f ../archive.tar --hard-dereference .
9464 drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./
9465 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden
9466 -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
9467 @end group
9468 @end smallexample
9469
9470 @node old
9471 @subsection Old V7 Archives
9472 @cindex Format, old style
9473 @cindex Old style format
9474 @cindex Old style archives
9475 @cindex v7 archive format
9476
9477 Certain old versions of @command{tar} cannot handle additional
9478 information recorded by newer @command{tar} programs. To create an
9479 archive in V7 format (not ANSI), which can be read by these old
9480 versions, specify the @option{--format=v7} option in
9481 conjunction with the @option{--create} (@option{-c}) (@command{tar} also
9482 accepts @option{--portability} or @option{--old-archive} for this
9483 option). When you specify it,
9484 @command{tar} leaves out information about directories, pipes, fifos,
9485 contiguous files, and device files, and specifies file ownership by
9486 group and user IDs instead of group and user names.
9487
9488 When updating an archive, do not use @option{--format=v7}
9489 unless the archive was created using this option.
9490
9491 In most cases, a @emph{new} format archive can be read by an @emph{old}
9492 @command{tar} program without serious trouble, so this option should
9493 seldom be needed. On the other hand, most modern @command{tar}s are
9494 able to read old format archives, so it might be safer for you to
9495 always use @option{--format=v7} for your distributions. Notice,
9496 however, that @samp{ustar} format is a better alternative, as it is
9497 free from many of @samp{v7}'s drawbacks.
9498
9499 @node ustar
9500 @subsection Ustar Archive Format
9501
9502 @cindex ustar archive format
9503 Archive format defined by @acronym{POSIX}.1-1988 specification is called
9504 @code{ustar}. Although it is more flexible than the V7 format, it
9505 still has many restrictions (@pxref{Formats,ustar}, for the detailed
9506 description of @code{ustar} format). Along with V7 format,
9507 @code{ustar} format is a good choice for archives intended to be read
9508 with other implementations of @command{tar}.
9509
9510 To create archive in @code{ustar} format, use @option{--format=ustar}
9511 option in conjunction with the @option{--create} (@option{-c}).
9512
9513 @node gnu
9514 @subsection @acronym{GNU} and old @GNUTAR{} format
9515
9516 @cindex GNU archive format
9517 @cindex Old GNU archive format
9518 @GNUTAR{} was based on an early draft of the
9519 @acronym{POSIX} 1003.1 @code{ustar} standard. @acronym{GNU} extensions to
9520 @command{tar}, such as the support for file names longer than 100
9521 characters, use portions of the @command{tar} header record which were
9522 specified in that @acronym{POSIX} draft as unused. Subsequent changes in
9523 @acronym{POSIX} have allocated the same parts of the header record for
9524 other purposes. As a result, @GNUTAR{} format is
9525 incompatible with the current @acronym{POSIX} specification, and with
9526 @command{tar} programs that follow it.
9527
9528 In the majority of cases, @command{tar} will be configured to create
9529 this format by default. This will change in future releases, since
9530 we plan to make @samp{POSIX} format the default.
9531
9532 To force creation a @GNUTAR{} archive, use option
9533 @option{--format=gnu}.
9534
9535 @node posix
9536 @subsection @GNUTAR{} and @acronym{POSIX} @command{tar}
9537
9538 @cindex POSIX archive format
9539 @cindex PAX archive format
9540 Starting from version 1.14 @GNUTAR{} features full support for
9541 @acronym{POSIX.1-2001} archives.
9542
9543 A @acronym{POSIX} conformant archive will be created if @command{tar}
9544 was given @option{--format=posix} (@option{--format=pax}) option. No
9545 special option is required to read and extract from a @acronym{POSIX}
9546 archive.
9547
9548 @menu
9549 * PAX keywords:: Controlling Extended Header Keywords.
9550 @end menu
9551
9552 @node PAX keywords
9553 @subsubsection Controlling Extended Header Keywords
9554
9555 @table @option
9556 @opindex pax-option
9557 @item --pax-option=@var{keyword-list}
9558 Handle keywords in @acronym{PAX} extended headers. This option is
9559 equivalent to @option{-o} option of the @command{pax} utility.
9560 @end table
9561
9562 @var{Keyword-list} is a comma-separated
9563 list of keyword options, each keyword option taking one of
9564 the following forms:
9565
9566 @table @code
9567 @item delete=@var{pattern}
9568 When used with one of archive-creation commands,
9569 this option instructs @command{tar} to omit from extended header records
9570 that it produces any keywords matching the string @var{pattern}.
9571
9572 When used in extract or list mode, this option instructs tar
9573 to ignore any keywords matching the given @var{pattern} in the extended
9574 header records. In both cases, matching is performed using the pattern
9575 matching notation described in @acronym{POSIX 1003.2}, 3.13
9576 (@pxref{wildcards}). For example:
9577
9578 @smallexample
9579 --pax-option delete=security.*
9580 @end smallexample
9581
9582 would suppress security-related information.
9583
9584 @item exthdr.name=@var{string}
9585
9586 This keyword allows user control over the name that is written into the
9587 ustar header blocks for the extended headers. The name is obtained
9588 from @var{string} after making the following substitutions:
9589
9590 @multitable @columnfractions .25 .55
9591 @headitem Meta-character @tab Replaced By
9592 @item %d @tab The directory name of the file, equivalent to the
9593 result of the @command{dirname} utility on the translated file name.
9594 @item %f @tab The name of the file with the directory information
9595 stripped, equivalent to the result of the @command{basename} utility
9596 on the translated file name.
9597 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9598 @item %% @tab A @samp{%} character.
9599 @end multitable
9600
9601 Any other @samp{%} characters in @var{string} produce undefined
9602 results.
9603
9604 If no option @samp{exthdr.name=string} is specified, @command{tar}
9605 will use the following default value:
9606
9607 @smallexample
9608 %d/PaxHeaders.%p/%f
9609 @end smallexample
9610
9611 @item exthdr.mtime=@var{value}
9612
9613 This keyword defines the value of the @samp{mtime} field that
9614 is written into the ustar header blocks for the extended headers.
9615 By default, the @samp{mtime} field is set to the modification time
9616 of the archive member described by that extended headers.
9617
9618 @item globexthdr.name=@var{string}
9619 This keyword allows user control over the name that is written into
9620 the ustar header blocks for global extended header records. The name
9621 is obtained from the contents of @var{string}, after making
9622 the following substitutions:
9623
9624 @multitable @columnfractions .25 .55
9625 @headitem Meta-character @tab Replaced By
9626 @item %n @tab An integer that represents the
9627 sequence number of the global extended header record in the archive,
9628 starting at 1.
9629 @item %p @tab The process @acronym{ID} of the @command{tar} process.
9630 @item %% @tab A @samp{%} character.
9631 @end multitable
9632
9633 Any other @samp{%} characters in @var{string} produce undefined results.
9634
9635 If no option @samp{globexthdr.name=string} is specified, @command{tar}
9636 will use the following default value:
9637
9638 @smallexample
9639 $TMPDIR/GlobalHead.%p.%n
9640 @end smallexample
9641
9642 @noindent
9643 where @samp{$TMPDIR} represents the value of the @var{TMPDIR}
9644 environment variable. If @var{TMPDIR} is not set, @command{tar}
9645 uses @samp{/tmp}.
9646
9647 @item globexthdr.mtime=@var{value}
9648
9649 This keyword defines the value of the @samp{mtime} field that
9650 is written into the ustar header blocks for the global extended headers.
9651 By default, the @samp{mtime} field is set to the time when
9652 @command{tar} was invoked.
9653
9654 @item @var{keyword}=@var{value}
9655 When used with one of archive-creation commands, these keyword/value pairs
9656 will be included at the beginning of the archive in a global extended
9657 header record. When used with one of archive-reading commands,
9658 @command{tar} will behave as if it has encountered these keyword/value
9659 pairs at the beginning of the archive in a global extended header
9660 record.
9661
9662 @item @var{keyword}:=@var{value}
9663 When used with one of archive-creation commands, these keyword/value pairs
9664 will be included as records at the beginning of an extended header for
9665 each file. This is effectively equivalent to @var{keyword}=@var{value}
9666 form except that it creates no global extended header records.
9667
9668 When used with one of archive-reading commands, @command{tar} will
9669 behave as if these keyword/value pairs were included as records at the
9670 end of each extended header; thus, they will override any global or
9671 file-specific extended header record keywords of the same names.
9672 For example, in the command:
9673
9674 @smallexample
9675 tar --format=posix --create \
9676 --file archive --pax-option gname:=user .
9677 @end smallexample
9678
9679 the group name will be forced to a new value for all files
9680 stored in the archive.
9681 @end table
9682
9683 In any of the forms described above, the @var{value} may be
9684 a string enclosed in curly braces. In that case, the string
9685 between the braces is understood either as a textual time
9686 representation, as described in @ref{Date input formats}, or a name of
9687 the existing file, starting with @samp{/} or @samp{.}. In the latter
9688 case, the modification time of that file is used.
9689
9690 For example, to set all modification times to the current date, you
9691 use the following option:
9692
9693 @smallexample
9694 --pax-option='mtime:=@{now@}'
9695 @end smallexample
9696
9697 Note quoting of the option's argument.
9698
9699 @cindex archives, binary equivalent
9700 @cindex binary equivalent archives, creating
9701 As another example, here is the option that ensures that any two
9702 archives created using it, will be binary equivalent if they have the
9703 same contents:
9704
9705 @smallexample
9706 --pax-option=exthdr.name=%d/PaxHeaders/%f,atime:=0
9707 @end smallexample
9708
9709 @node Checksumming
9710 @subsection Checksumming Problems
9711
9712 SunOS and HP-UX @command{tar} fail to accept archives created using
9713 @GNUTAR{} and containing non-@acronym{ASCII} file names, that
9714 is, file names having characters with the eight bit set, because they
9715 use signed checksums, while @GNUTAR{} uses unsigned
9716 checksums while creating archives, as per @acronym{POSIX} standards. On
9717 reading, @GNUTAR{} computes both checksums and
9718 accepts any. It is somewhat worrying that a lot of people may go
9719 around doing backup of their files using faulty (or at least
9720 non-standard) software, not learning about it until it's time to
9721 restore their missing files with an incompatible file extractor, or
9722 vice versa.
9723
9724 @GNUTAR{} computes checksums both ways, and accept
9725 any on read, so @acronym{GNU} tar can read Sun tapes even with their
9726 wrong checksums. @GNUTAR{} produces the standard
9727 checksum, however, raising incompatibilities with Sun. That is to
9728 say, @GNUTAR{} has not been modified to
9729 @emph{produce} incorrect archives to be read by buggy @command{tar}'s.
9730 I've been told that more recent Sun @command{tar} now read standard
9731 archives, so maybe Sun did a similar patch, after all?
9732
9733 The story seems to be that when Sun first imported @command{tar}
9734 sources on their system, they recompiled it without realizing that
9735 the checksums were computed differently, because of a change in
9736 the default signing of @code{char}'s in their compiler. So they
9737 started computing checksums wrongly. When they later realized their
9738 mistake, they merely decided to stay compatible with it, and with
9739 themselves afterwards. Presumably, but I do not really know, HP-UX
9740 has chosen that their @command{tar} archives to be compatible with Sun's.
9741 The current standards do not favor Sun @command{tar} format. In any
9742 case, it now falls on the shoulders of SunOS and HP-UX users to get
9743 a @command{tar} able to read the good archives they receive.
9744
9745 @node Large or Negative Values
9746 @subsection Large or Negative Values
9747 @cindex large values
9748 @cindex future time stamps
9749 @cindex negative time stamps
9750 @UNREVISED
9751
9752 The above sections suggest to use @samp{oldest possible} archive
9753 format if in doubt. However, sometimes it is not possible. If you
9754 attempt to archive a file whose metadata cannot be represented using
9755 required format, @GNUTAR{} will print error message and ignore such a
9756 file. You will than have to switch to a format that is able to
9757 handle such values. The format summary table (@pxref{Formats}) will
9758 help you to do so.
9759
9760 In particular, when trying to archive files larger than 8GB or with
9761 timestamps not in the range 1970-01-01 00:00:00 through 2242-03-16
9762 12:56:31 @sc{utc}, you will have to chose between @acronym{GNU} and
9763 @acronym{POSIX} archive formats. When considering which format to
9764 choose, bear in mind that the @acronym{GNU} format uses
9765 two's-complement base-256 notation to store values that do not fit
9766 into standard @acronym{ustar} range. Such archives can generally be
9767 read only by a @GNUTAR{} implementation. Moreover, they sometimes
9768 cannot be correctly restored on another hosts even by @GNUTAR{}. For
9769 example, using two's complement representation for negative time
9770 stamps that assumes a signed 32-bit @code{time_t} generates archives
9771 that are not portable to hosts with differing @code{time_t}
9772 representations.
9773
9774 On the other hand, @acronym{POSIX} archives, generally speaking, can
9775 be extracted by any tar implementation that understands older
9776 @acronym{ustar} format. The only exception are files larger than 8GB.
9777
9778 @FIXME{Describe how @acronym{POSIX} archives are extracted by non
9779 POSIX-aware tars.}
9780
9781 @node Other Tars
9782 @subsection How to Extract GNU-Specific Data Using Other @command{tar} Implementations
9783
9784 In previous sections you became acquainted with various quirks
9785 necessary to make your archives portable. Sometimes you may need to
9786 extract archives containing GNU-specific members using some
9787 third-party @command{tar} implementation or an older version of
9788 @GNUTAR{}. Of course your best bet is to have @GNUTAR{} installed,
9789 but if it is for some reason impossible, this section will explain
9790 how to cope without it.
9791
9792 When we speak about @dfn{GNU-specific} members we mean two classes of
9793 them: members split between the volumes of a multi-volume archive and
9794 sparse members. You will be able to always recover such members if
9795 the archive is in PAX format. In addition split members can be
9796 recovered from archives in old GNU format. The following subsections
9797 describe the required procedures in detail.
9798
9799 @menu
9800 * Split Recovery:: Members Split Between Volumes
9801 * Sparse Recovery:: Sparse Members
9802 @end menu
9803
9804 @node Split Recovery
9805 @subsubsection Extracting Members Split Between Volumes
9806
9807 @cindex Mutli-volume archives, extracting using non-GNU tars
9808 If a member is split between several volumes of an old GNU format archive
9809 most third party @command{tar} implementation will fail to extract
9810 it. To extract it, use @command{tarcat} program (@pxref{Tarcat}).
9811 This program is available from
9812 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/tarcat.html, @GNUTAR{}
9813 home page}. It concatenates several archive volumes into a single
9814 valid archive. For example, if you have three volumes named from
9815 @file{vol-1.tar} to @file{vol-3.tar}, you can do the following to
9816 extract them using a third-party @command{tar}:
9817
9818 @smallexample
9819 $ @kbd{tarcat vol-1.tar vol-2.tar vol-3.tar | tar xf -}
9820 @end smallexample
9821
9822 @cindex Mutli-volume archives in PAX format, extracting using non-GNU tars
9823 You could use this approach for most (although not all) PAX
9824 format archives as well. However, extracting split members from a PAX
9825 archive is a much easier task, because PAX volumes are constructed in
9826 such a way that each part of a split member is extracted to a
9827 different file by @command{tar} implementations that are not aware of
9828 GNU extensions. More specifically, the very first part retains its
9829 original name, and all subsequent parts are named using the pattern:
9830
9831 @smallexample
9832 %d/GNUFileParts.%p/%f.%n
9833 @end smallexample
9834
9835 @noindent
9836 where symbols preceeded by @samp{%} are @dfn{macro characters} that
9837 have the following meaning:
9838
9839 @multitable @columnfractions .25 .55
9840 @headitem Meta-character @tab Replaced By
9841 @item %d @tab The directory name of the file, equivalent to the
9842 result of the @command{dirname} utility on its full name.
9843 @item %f @tab The file name of the file, equivalent to the result
9844 of the @command{basename} utility on its full name.
9845 @item %p @tab The process @acronym{ID} of the @command{tar} process that
9846 created the archive.
9847 @item %n @tab Ordinal number of this particular part.
9848 @end multitable
9849
9850 For example, if the file @file{var/longfile} was split during archive
9851 creation between three volumes, and the creator @command{tar} process
9852 had process @acronym{ID} @samp{27962}, then the member names will be:
9853
9854 @smallexample
9855 var/longfile
9856 var/GNUFileParts.27962/longfile.1
9857 var/GNUFileParts.27962/longfile.2
9858 @end smallexample
9859
9860 When you extract your archive using a third-party @command{tar}, these
9861 files will be created on your disk, and the only thing you will need
9862 to do to restore your file in its original form is concatenate them in
9863 the proper order, for example:
9864
9865 @smallexample
9866 @group
9867 $ @kbd{cd var}
9868 $ @kbd{cat GNUFileParts.27962/longfile.1 \
9869 GNUFileParts.27962/longfile.2 >> longfile}
9870 $ rm -f GNUFileParts.27962
9871 @end group
9872 @end smallexample
9873
9874 Notice, that if the @command{tar} implementation you use supports PAX
9875 format archives, it will probably emit warnings about unknown keywords
9876 during extraction. They will look like this:
9877
9878 @smallexample
9879 @group
9880 Tar file too small
9881 Unknown extended header keyword 'GNU.volume.filename' ignored.
9882 Unknown extended header keyword 'GNU.volume.size' ignored.
9883 Unknown extended header keyword 'GNU.volume.offset' ignored.
9884 @end group
9885 @end smallexample
9886
9887 @noindent
9888 You can safely ignore these warnings.
9889
9890 If your @command{tar} implementation is not PAX-aware, you will get
9891 more warnings and more files generated on your disk, e.g.:
9892
9893 @smallexample
9894 @group
9895 $ @kbd{tar xf vol-1.tar}
9896 var/PaxHeaders.27962/longfile: Unknown file type 'x', extracted as
9897 normal file
9898 Unexpected EOF in archive
9899 $ @kbd{tar xf vol-2.tar}
9900 tmp/GlobalHead.27962.1: Unknown file type 'g', extracted as normal file
9901 GNUFileParts.27962/PaxHeaders.27962/sparsefile.1: Unknown file type
9902 'x', extracted as normal file
9903 @end group
9904 @end smallexample
9905
9906 Ignore these warnings. The @file{PaxHeaders.*} directories created
9907 will contain files with @dfn{extended header keywords} describing the
9908 extracted files. You can delete them, unless they describe sparse
9909 members. Read further to learn more about them.
9910
9911 @node Sparse Recovery
9912 @subsubsection Extracting Sparse Members
9913
9914 @cindex sparse files, extracting with non-GNU tars
9915 Any @command{tar} implementation will be able to extract sparse members from a
9916 PAX archive. However, the extracted files will be @dfn{condensed},
9917 i.e., any zero blocks will be removed from them. When we restore such
9918 a condensed file to its original form, by adding zero blocks (or
9919 @dfn{holes}) back to their original locations, we call this process
9920 @dfn{expanding} a compressed sparse file.
9921
9922 @pindex xsparse
9923 To expand a file, you will need a simple auxiliary program called
9924 @command{xsparse}. It is available in source form from
9925 @uref{http://www.gnu.org/@/software/@/tar/@/utils/@/xsparse.html, @GNUTAR{}
9926 home page}.
9927
9928 @cindex sparse files v.1.0, extracting with non-GNU tars
9929 Let's begin with archive members in @dfn{sparse format
9930 version 1.0}@footnote{@xref{PAX 1}.}, which are the easiest to expand.
9931 The condensed file will contain both file map and file data, so no
9932 additional data will be needed to restore it. If the original file
9933 name was @file{@var{dir}/@var{name}}, then the condensed file will be
9934 named @file{@var{dir}/@/GNUSparseFile.@var{n}/@/@var{name}}, where
9935 @var{n} is a decimal number@footnote{Technically speaking, @var{n} is a
9936 @dfn{process @acronym{ID}} of the @command{tar} process which created the
9937 archive (@pxref{PAX keywords}).}.
9938
9939 To expand a version 1.0 file, run @command{xsparse} as follows:
9940
9941 @smallexample
9942 $ @kbd{xsparse @file{cond-file}}
9943 @end smallexample
9944
9945 @noindent
9946 where @file{cond-file} is the name of the condensed file. The utility
9947 will deduce the name for the resulting expanded file using the
9948 following algorithm:
9949
9950 @enumerate 1
9951 @item If @file{cond-file} does not contain any directories,
9952 @file{../cond-file} will be used;
9953
9954 @item If @file{cond-file} has the form
9955 @file{@var{dir}/@var{t}/@var{name}}, where both @var{t} and @var{name}
9956 are simple names, with no @samp{/} characters in them, the output file
9957 name will be @file{@var{dir}/@var{name}}.
9958
9959 @item Otherwise, if @file{cond-file} has the form
9960 @file{@var{dir}/@var{name}}, the output file name will be
9961 @file{@var{name}}.
9962 @end enumerate
9963
9964 In the unlikely case when this algorithm does not suit your needs,
9965 you can explicitly specify output file name as a second argument to
9966 the command:
9967
9968 @smallexample
9969 $ @kbd{xsparse @file{cond-file} @file{out-file}}
9970 @end smallexample
9971
9972 It is often a good idea to run @command{xsparse} in @dfn{dry run} mode
9973 first. In this mode, the command does not actually expand the file,
9974 but verbosely lists all actions it would be taking to do so. The dry
9975 run mode is enabled by @option{-n} command line argument:
9976
9977 @smallexample
9978 @group
9979 $ @kbd{xsparse -n /home/gray/GNUSparseFile.6058/sparsefile}
9980 Reading v.1.0 sparse map
9981 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
9982 `/home/gray/sparsefile'
9983 Finished dry run
9984 @end group
9985 @end smallexample
9986
9987 To actually expand the file, you would run:
9988
9989 @smallexample
9990 $ @kbd{xsparse /home/gray/GNUSparseFile.6058/sparsefile}
9991 @end smallexample
9992
9993 @noindent
9994 The program behaves the same way all UNIX utilities do: it will keep
9995 quiet unless it has simething important to tell you (e.g. an error
9996 condition or something). If you wish it to produce verbose output,
9997 similar to that from the dry run mode, use @option{-v} option:
9998
9999 @smallexample
10000 @group
10001 $ @kbd{xsparse -v /home/gray/GNUSparseFile.6058/sparsefile}
10002 Reading v.1.0 sparse map
10003 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
10004 `/home/gray/sparsefile'
10005 Done
10006 @end group
10007 @end smallexample
10008
10009 Additionally, if your @command{tar} implementation has extracted the
10010 @dfn{extended headers} for this file, you can instruct @command{xstar}
10011 to use them in order to verify the integrity of the expanded file.
10012 The option @option{-x} sets the name of the extended header file to
10013 use. Continuing our example:
10014
10015 @smallexample
10016 @group
10017 $ @kbd{xsparse -v -x /home/gray/PaxHeaders.6058/sparsefile \
10018 /home/gray/GNUSparseFile.6058/sparsefile}
10019 Reading extended header file
10020 Found variable GNU.sparse.major = 1
10021 Found variable GNU.sparse.minor = 0
10022 Found variable GNU.sparse.name = sparsefile
10023 Found variable GNU.sparse.realsize = 217481216
10024 Reading v.1.0 sparse map
10025 Expanding file `/home/gray/GNUSparseFile.6058/sparsefile' to
10026 `/home/gray/sparsefile'
10027 Done
10028 @end group
10029 @end smallexample
10030
10031 @anchor{extracting sparse v.0.x}
10032 @cindex sparse files v.0.1, extracting with non-GNU tars
10033 @cindex sparse files v.0.0, extracting with non-GNU tars
10034 An @dfn{extended header} is a special @command{tar} archive header
10035 that precedes an archive member and contains a set of
10036 @dfn{variables}, describing the member properties that cannot be
10037 stored in the standard @code{ustar} header. While optional for
10038 expanding sparse version 1.0 members, the use of extended headers is
10039 mandatory when expanding sparse members in older sparse formats: v.0.0
10040 and v.0.1 (The sparse formats are described in detail in @ref{Sparse
10041 Formats}.) So, for these formats, the question is: how to obtain
10042 extended headers from the archive?
10043
10044 If you use a @command{tar} implementation that does not support PAX
10045 format, extended headers for each member will be extracted as a
10046 separate file. If we represent the member name as
10047 @file{@var{dir}/@var{name}}, then the extended header file will be
10048 named @file{@var{dir}/@/PaxHeaders.@var{n}/@/@var{name}}, where
10049 @var{n} is an integer number.
10050
10051 Things become more difficult if your @command{tar} implementation
10052 does support PAX headers, because in this case you will have to
10053 manually extract the headers. We recommend the following algorithm:
10054
10055 @enumerate 1
10056 @item
10057 Consult the documentation of your @command{tar} implementation for an
10058 option that prints @dfn{block numbers} along with the archive
10059 listing (analogous to @GNUTAR{}'s @option{-R} option). For example,
10060 @command{star} has @option{-block-number}.
10061
10062 @item
10063 Obtain verbose listing using the @samp{block number} option, and
10064 find block numbers of the sparse member in question and the member
10065 immediately following it. For example, running @command{star} on our
10066 archive we obtain:
10067
10068 @smallexample
10069 @group
10070 $ @kbd{star -t -v -block-number -f arc.tar}
10071 @dots{}
10072 star: Unknown extended header keyword 'GNU.sparse.size' ignored.
10073 star: Unknown extended header keyword 'GNU.sparse.numblocks' ignored.
10074 star: Unknown extended header keyword 'GNU.sparse.name' ignored.
10075 star: Unknown extended header keyword 'GNU.sparse.map' ignored.
10076 block 56: 425984 -rw-r--r-- gray/users Jun 25 14:46 2006 GNUSparseFile.28124/sparsefile
10077 block 897: 65391 -rw-r--r-- gray/users Jun 24 20:06 2006 README
10078 @dots{}
10079 @end group
10080 @end smallexample
10081
10082 @noindent
10083 (as usual, ignore the warnings about unknown keywords.)
10084
10085 @item
10086 Let @var{size} be the size of the sparse member, @var{Bs} be its block number
10087 and @var{Bn} be the block number of the next member.
10088 Compute:
10089
10090 @smallexample
10091 @var{N} = @var{Bs} - @var{Bn} - @var{size}/512 - 2
10092 @end smallexample
10093
10094 @noindent
10095 This number gives the size of the extended header part in tar @dfn{blocks}.
10096 In our example, this formula gives: @code{897 - 56 - 425984 / 512 - 2
10097 = 7}.
10098
10099 @item
10100 Use @command{dd} to extract the headers:
10101
10102 @smallexample
10103 @kbd{dd if=@var{archive} of=@var{hname} bs=512 skip=@var{Bs} count=@var{N}}
10104 @end smallexample
10105
10106 @noindent
10107 where @var{archive} is the archive name, @var{hname} is a name of the
10108 file to store the extended header in, @var{Bs} and @var{N} are
10109 computed in previous steps.
10110
10111 In our example, this command will be
10112
10113 @smallexample
10114 $ @kbd{dd if=arc.tar of=xhdr bs=512 skip=56 count=7}
10115 @end smallexample
10116 @end enumerate
10117
10118 Finally, you can expand the condensed file, using the obtained header:
10119
10120 @smallexample
10121 @group
10122 $ @kbd{xsparse -v -x xhdr GNUSparseFile.6058/sparsefile}
10123 Reading extended header file
10124 Found variable GNU.sparse.size = 217481216
10125 Found variable GNU.sparse.numblocks = 208
10126 Found variable GNU.sparse.name = sparsefile
10127 Found variable GNU.sparse.map = 0,2048,1050624,2048,@dots{}
10128 Expanding file `GNUSparseFile.28124/sparsefile' to `sparsefile'
10129 Done
10130 @end group
10131 @end smallexample
10132
10133 @node cpio
10134 @section Comparison of @command{tar} and @command{cpio}
10135 @UNREVISED
10136
10137 @FIXME{Reorganize the following material}
10138
10139 The @command{cpio} archive formats, like @command{tar}, do have maximum
10140 file name lengths. The binary and old @acronym{ASCII} formats have a maximum file
10141 length of 256, and the new @acronym{ASCII} and @acronym{CRC ASCII} formats have a max
10142 file length of 1024. @acronym{GNU} @command{cpio} can read and write archives
10143 with arbitrary file name lengths, but other @command{cpio} implementations
10144 may crash unexplainedly trying to read them.
10145
10146 @command{tar} handles symbolic links in the form in which it comes in @acronym{BSD};
10147 @command{cpio} doesn't handle symbolic links in the form in which it comes
10148 in System V prior to SVR4, and some vendors may have added symlinks
10149 to their system without enhancing @command{cpio} to know about them.
10150 Others may have enhanced it in a way other than the way I did it
10151 at Sun, and which was adopted by AT&T (and which is, I think, also
10152 present in the @command{cpio} that Berkeley picked up from AT&T and put
10153 into a later @acronym{BSD} release---I think I gave them my changes).
10154
10155 (SVR4 does some funny stuff with @command{tar}; basically, its @command{cpio}
10156 can handle @command{tar} format input, and write it on output, and it
10157 probably handles symbolic links. They may not have bothered doing
10158 anything to enhance @command{tar} as a result.)
10159
10160 @command{cpio} handles special files; traditional @command{tar} doesn't.
10161
10162 @command{tar} comes with V7, System III, System V, and @acronym{BSD} source;
10163 @command{cpio} comes only with System III, System V, and later @acronym{BSD}
10164 (4.3-tahoe and later).
10165
10166 @command{tar}'s way of handling multiple hard links to a file can handle
10167 file systems that support 32-bit i-numbers (e.g., the @acronym{BSD} file system);
10168 @command{cpio}s way requires you to play some games (in its ``binary''
10169 format, i-numbers are only 16 bits, and in its ``portable @acronym{ASCII}'' format,
10170 they're 18 bits---it would have to play games with the "file system @acronym{ID}"
10171 field of the header to make sure that the file system @acronym{ID}/i-number pairs
10172 of different files were always different), and I don't know which
10173 @command{cpio}s, if any, play those games. Those that don't might get
10174 confused and think two files are the same file when they're not, and
10175 make hard links between them.
10176
10177 @command{tar}s way of handling multiple hard links to a file places only
10178 one copy of the link on the tape, but the name attached to that copy
10179 is the @emph{only} one you can use to retrieve the file; @command{cpio}s
10180 way puts one copy for every link, but you can retrieve it using any
10181 of the names.
10182
10183 @quotation
10184 What type of check sum (if any) is used, and how is this calculated.
10185 @end quotation
10186
10187 See the attached manual pages for @command{tar} and @command{cpio} format.
10188 @command{tar} uses a checksum which is the sum of all the bytes in the
10189 @command{tar} header for a file; @command{cpio} uses no checksum.
10190
10191 @quotation
10192 If anyone knows why @command{cpio} was made when @command{tar} was present
10193 at the unix scene,
10194 @end quotation
10195
10196 It wasn't. @command{cpio} first showed up in PWB/UNIX 1.0; no
10197 generally-available version of UNIX had @command{tar} at the time. I don't
10198 know whether any version that was generally available @emph{within AT&T}
10199 had @command{tar}, or, if so, whether the people within AT&T who did
10200 @command{cpio} knew about it.
10201
10202 On restore, if there is a corruption on a tape @command{tar} will stop at
10203 that point, while @command{cpio} will skip over it and try to restore the
10204 rest of the files.
10205
10206 The main difference is just in the command syntax and header format.
10207
10208 @command{tar} is a little more tape-oriented in that everything is blocked
10209 to start on a record boundary.
10210
10211 @quotation
10212 Is there any differences between the ability to recover crashed
10213 archives between the two of them. (Is there any chance of recovering
10214 crashed archives at all.)
10215 @end quotation
10216
10217 Theoretically it should be easier under @command{tar} since the blocking
10218 lets you find a header with some variation of @samp{dd skip=@var{nn}}.
10219 However, modern @command{cpio}'s and variations have an option to just
10220 search for the next file header after an error with a reasonable chance
10221 of resyncing. However, lots of tape driver software won't allow you to
10222 continue past a media error which should be the only reason for getting
10223 out of sync unless a file changed sizes while you were writing the
10224 archive.
10225
10226 @quotation
10227 If anyone knows why @command{cpio} was made when @command{tar} was present
10228 at the unix scene, please tell me about this too.
10229 @end quotation
10230
10231 Probably because it is more media efficient (by not blocking everything
10232 and using only the space needed for the headers where @command{tar}
10233 always uses 512 bytes per file header) and it knows how to archive
10234 special files.
10235
10236 You might want to look at the freely available alternatives. The
10237 major ones are @command{afio}, @GNUTAR{}, and
10238 @command{pax}, each of which have their own extensions with some
10239 backwards compatibility.
10240
10241 Sparse files were @command{tar}red as sparse files (which you can
10242 easily test, because the resulting archive gets smaller, and
10243 @acronym{GNU} @command{cpio} can no longer read it).
10244
10245 @node Media
10246 @chapter Tapes and Other Archive Media
10247 @UNREVISED
10248
10249 A few special cases about tape handling warrant more detailed
10250 description. These special cases are discussed below.
10251
10252 Many complexities surround the use of @command{tar} on tape drives. Since
10253 the creation and manipulation of archives located on magnetic tape was
10254 the original purpose of @command{tar}, it contains many features making
10255 such manipulation easier.
10256
10257 Archives are usually written on dismountable media---tape cartridges,
10258 mag tapes, or floppy disks.
10259
10260 The amount of data a tape or disk holds depends not only on its size,
10261 but also on how it is formatted. A 2400 foot long reel of mag tape
10262 holds 40 megabytes of data when formatted at 1600 bits per inch. The
10263 physically smaller EXABYTE tape cartridge holds 2.3 gigabytes.
10264
10265 Magnetic media are re-usable---once the archive on a tape is no longer
10266 needed, the archive can be erased and the tape or disk used over.
10267 Media quality does deteriorate with use, however. Most tapes or disks
10268 should be discarded when they begin to produce data errors. EXABYTE
10269 tape cartridges should be discarded when they generate an @dfn{error
10270 count} (number of non-usable bits) of more than 10k.
10271
10272 Magnetic media are written and erased using magnetic fields, and
10273 should be protected from such fields to avoid damage to stored data.
10274 Sticking a floppy disk to a filing cabinet using a magnet is probably
10275 not a good idea.
10276
10277 @menu
10278 * Device:: Device selection and switching
10279 * Remote Tape Server::
10280 * Common Problems and Solutions::
10281 * Blocking:: Blocking
10282 * Many:: Many archives on one tape
10283 * Using Multiple Tapes:: Using Multiple Tapes
10284 * label:: Including a Label in the Archive
10285 * verify::
10286 * Write Protection::
10287 @end menu
10288
10289 @node Device
10290 @section Device Selection and Switching
10291 @UNREVISED
10292
10293 @table @option
10294 @item -f [@var{hostname}:]@var{file}
10295 @itemx --file=[@var{hostname}:]@var{file}
10296 Use archive file or device @var{file} on @var{hostname}.
10297 @end table
10298
10299 This option is used to specify the file name of the archive @command{tar}
10300 works on.
10301
10302 If the file name is @samp{-}, @command{tar} reads the archive from standard
10303 input (when listing or extracting), or writes it to standard output
10304 (when creating). If the @samp{-} file name is given when updating an
10305 archive, @command{tar} will read the original archive from its standard
10306 input, and will write the entire new archive to its standard output.
10307
10308 If the file name contains a @samp{:}, it is interpreted as
10309 @samp{hostname:file name}. If the @var{hostname} contains an @dfn{at}
10310 sign (@samp{@@}), it is treated as @samp{user@@hostname:file name}. In
10311 either case, @command{tar} will invoke the command @command{rsh} (or
10312 @command{remsh}) to start up an @command{/usr/libexec/rmt} on the remote
10313 machine. If you give an alternate login name, it will be given to the
10314 @command{rsh}.
10315 Naturally, the remote machine must have an executable
10316 @command{/usr/libexec/rmt}. This program is free software from the
10317 University of California, and a copy of the source code can be found
10318 with the sources for @command{tar}; it's compiled and installed by default.
10319 The exact path to this utility is determined when configuring the package.
10320 It is @file{@var{prefix}/libexec/rmt}, where @var{prefix} stands for
10321 your installation prefix. This location may also be overridden at
10322 runtime by using the @option{--rmt-command=@var{command}} option (@xref{Option Summary,
10323 ---rmt-command}, for detailed description of this option. @xref{Remote
10324 Tape Server}, for the description of @command{rmt} command).
10325
10326 If this option is not given, but the environment variable @env{TAPE}
10327 is set, its value is used; otherwise, old versions of @command{tar}
10328 used a default archive name (which was picked when @command{tar} was
10329 compiled). The default is normally set up to be the @dfn{first} tape
10330 drive or other transportable I/O medium on the system.
10331
10332 Starting with version 1.11.5, @GNUTAR{} uses
10333 standard input and standard output as the default device, and I will
10334 not try anymore supporting automatic device detection at installation
10335 time. This was failing really in too many cases, it was hopeless.
10336 This is now completely left to the installer to override standard
10337 input and standard output for default device, if this seems
10338 preferable. Further, I think @emph{most} actual usages of
10339 @command{tar} are done with pipes or disks, not really tapes,
10340 cartridges or diskettes.
10341
10342 Some users think that using standard input and output is running
10343 after trouble. This could lead to a nasty surprise on your screen if
10344 you forget to specify an output file name---especially if you are going
10345 through a network or terminal server capable of buffering large amounts
10346 of output. We had so many bug reports in that area of configuring
10347 default tapes automatically, and so many contradicting requests, that
10348 we finally consider the problem to be portably intractable. We could
10349 of course use something like @samp{/dev/tape} as a default, but this
10350 is @emph{also} running after various kind of trouble, going from hung
10351 processes to accidental destruction of real tapes. After having seen
10352 all this mess, using standard input and output as a default really
10353 sounds like the only clean choice left, and a very useful one too.
10354
10355 @GNUTAR{} reads and writes archive in records, I
10356 suspect this is the main reason why block devices are preferred over
10357 character devices. Most probably, block devices are more efficient
10358 too. The installer could also check for @samp{DEFTAPE} in
10359 @file{<sys/mtio.h>}.
10360
10361 @table @option
10362 @xopindex{force-local, short description}
10363 @item --force-local
10364 Archive file is local even if it contains a colon.
10365
10366 @opindex rsh-command
10367 @item --rsh-command=@var{command}
10368 Use remote @var{command} instead of @command{rsh}. This option exists
10369 so that people who use something other than the standard @command{rsh}
10370 (e.g., a Kerberized @command{rsh}) can access a remote device.
10371
10372 When this command is not used, the shell command found when
10373 the @command{tar} program was installed is used instead. This is
10374 the first found of @file{/usr/ucb/rsh}, @file{/usr/bin/remsh},
10375 @file{/usr/bin/rsh}, @file{/usr/bsd/rsh} or @file{/usr/bin/nsh}.
10376 The installer may have overridden this by defining the environment
10377 variable @env{RSH} @emph{at installation time}.
10378
10379 @item -[0-7][lmh]
10380 Specify drive and density.
10381
10382 @xopindex{multi-volume, short description}
10383 @item -M
10384 @itemx --multi-volume
10385 Create/list/extract multi-volume archive.
10386
10387 This option causes @command{tar} to write a @dfn{multi-volume} archive---one
10388 that may be larger than will fit on the medium used to hold it.
10389 @xref{Multi-Volume Archives}.
10390
10391 @xopindex{tape-length, short description}
10392 @item -L @var{num}
10393 @itemx --tape-length=@var{size}[@var{suf}]
10394 Change tape after writing @var{size} units of data. Unless @var{suf} is
10395 given, @var{size} is treated as kilobytes, i.e. @samp{@var{size} x
10396 1024} bytes. The following suffixes alter this behavior:
10397
10398 @float Table, size-suffixes
10399 @caption{Size Suffixes}
10400 @multitable @columnfractions 0.2 0.3 0.3
10401 @headitem Suffix @tab Units @tab Byte Equivalent
10402 @item b @tab Blocks @tab @var{size} x 512
10403 @item B @tab Kilobytes @tab @var{size} x 1024
10404 @item c @tab Bytes @tab @var{size}
10405 @item G @tab Gigabytes @tab @var{size} x 1024^3
10406 @item K @tab Kilobytes @tab @var{size} x 1024
10407 @item k @tab Kilobytes @tab @var{size} x 1024
10408 @item M @tab Megabytes @tab @var{size} x 1024^2
10409 @item P @tab Petabytes @tab @var{size} x 1024^5
10410 @item T @tab Terabytes @tab @var{size} x 1024^4
10411 @item w @tab Words @tab @var{size} x 2
10412 @end multitable
10413 @end float
10414
10415 This option might be useful when your tape drivers do not properly
10416 detect end of physical tapes. By being slightly conservative on the
10417 maximum tape length, you might avoid the problem entirely.
10418
10419 @xopindex{info-script, short description}
10420 @xopindex{new-volume-script, short description}
10421 @item -F @var{file}
10422 @itemx --info-script=@var{file}
10423 @itemx --new-volume-script=@var{file}
10424 Execute @file{file} at end of each tape. This implies
10425 @option{--multi-volume} (@option{-M}). @xref{info-script}, for a detailed
10426 description of this option.
10427 @end table
10428
10429 @node Remote Tape Server
10430 @section Remote Tape Server
10431
10432 @cindex remote tape drive
10433 @pindex rmt
10434 In order to access the tape drive on a remote machine, @command{tar}
10435 uses the remote tape server written at the University of California at
10436 Berkeley. The remote tape server must be installed as
10437 @file{@var{prefix}/libexec/rmt} on any machine whose tape drive you
10438 want to use. @command{tar} calls @command{rmt} by running an
10439 @command{rsh} or @command{remsh} to the remote machine, optionally
10440 using a different login name if one is supplied.
10441
10442 A copy of the source for the remote tape server is provided. It is
10443 Copyright @copyright{} 1983 by the Regents of the University of
10444 California, but can be freely distributed. It is compiled and
10445 installed by default.
10446
10447 @cindex absolute file names
10448 Unless you use the @option{--absolute-names} (@option{-P}) option,
10449 @GNUTAR{} will not allow you to create an archive that contains
10450 absolute file names (a file name beginning with @samp{/}.) If you try,
10451 @command{tar} will automatically remove the leading @samp{/} from the
10452 file names it stores in the archive. It will also type a warning
10453 message telling you what it is doing.
10454
10455 When reading an archive that was created with a different
10456 @command{tar} program, @GNUTAR{} automatically
10457 extracts entries in the archive which have absolute file names as if
10458 the file names were not absolute. This is an important feature. A
10459 visitor here once gave a @command{tar} tape to an operator to restore;
10460 the operator used Sun @command{tar} instead of @GNUTAR{},
10461 and the result was that it replaced large portions of
10462 our @file{/bin} and friends with versions from the tape; needless to
10463 say, we were unhappy about having to recover the file system from
10464 backup tapes.
10465
10466 For example, if the archive contained a file @file{/usr/bin/computoy},
10467 @GNUTAR{} would extract the file to @file{usr/bin/computoy},
10468 relative to the current directory. If you want to extract the files in
10469 an archive to the same absolute names that they had when the archive
10470 was created, you should do a @samp{cd /} before extracting the files
10471 from the archive, or you should either use the @option{--absolute-names}
10472 option, or use the command @samp{tar -C / @dots{}}.
10473
10474 @cindex Ultrix 3.1 and write failure
10475 Some versions of Unix (Ultrix 3.1 is known to have this problem),
10476 can claim that a short write near the end of a tape succeeded,
10477 when it actually failed. This will result in the -M option not
10478 working correctly. The best workaround at the moment is to use a
10479 significantly larger blocking factor than the default 20.
10480
10481 In order to update an archive, @command{tar} must be able to backspace the
10482 archive in order to reread or rewrite a record that was just read (or
10483 written). This is currently possible only on two kinds of files: normal
10484 disk files (or any other file that can be backspaced with @samp{lseek}),
10485 and industry-standard 9-track magnetic tape (or any other kind of tape
10486 that can be backspaced with the @code{MTIOCTOP} @code{ioctl}).
10487
10488 This means that the @option{--append}, @option{--concatenate}, and
10489 @option{--delete} commands will not work on any other kind of file.
10490 Some media simply cannot be backspaced, which means these commands and
10491 options will never be able to work on them. These non-backspacing
10492 media include pipes and cartridge tape drives.
10493
10494 Some other media can be backspaced, and @command{tar} will work on them
10495 once @command{tar} is modified to do so.
10496
10497 Archives created with the @option{--multi-volume}, @option{--label}, and
10498 @option{--incremental} (@option{-G}) options may not be readable by other version
10499 of @command{tar}. In particular, restoring a file that was split over
10500 a volume boundary will require some careful work with @command{dd}, if
10501 it can be done at all. Other versions of @command{tar} may also create
10502 an empty file whose name is that of the volume header. Some versions
10503 of @command{tar} may create normal files instead of directories archived
10504 with the @option{--incremental} (@option{-G}) option.
10505
10506 @node Common Problems and Solutions
10507 @section Some Common Problems and their Solutions
10508
10509 @ifclear PUBLISH
10510
10511 @format
10512 errors from system:
10513 permission denied
10514 no such file or directory
10515 not owner
10516
10517 errors from @command{tar}:
10518 directory checksum error
10519 header format error
10520
10521 errors from media/system:
10522 i/o error
10523 device busy
10524 @end format
10525
10526 @end ifclear
10527
10528 @node Blocking
10529 @section Blocking
10530 @cindex block
10531 @cindex record
10532
10533 @dfn{Block} and @dfn{record} terminology is rather confused, and it
10534 is also confusing to the expert reader. On the other hand, readers
10535 who are new to the field have a fresh mind, and they may safely skip
10536 the next two paragraphs, as the remainder of this manual uses those
10537 two terms in a quite consistent way.
10538
10539 John Gilmore, the writer of the public domain @command{tar} from which
10540 @GNUTAR{} was originally derived, wrote (June 1995):
10541
10542 @quotation
10543 The nomenclature of tape drives comes from IBM, where I believe
10544 they were invented for the IBM 650 or so. On IBM mainframes, what
10545 is recorded on tape are tape blocks. The logical organization of
10546 data is into records. There are various ways of putting records into
10547 blocks, including @code{F} (fixed sized records), @code{V} (variable
10548 sized records), @code{FB} (fixed blocked: fixed size records, @var{n}
10549 to a block), @code{VB} (variable size records, @var{n} to a block),
10550 @code{VSB} (variable spanned blocked: variable sized records that can
10551 occupy more than one block), etc. The @code{JCL} @samp{DD RECFORM=}
10552 parameter specified this to the operating system.
10553
10554 The Unix man page on @command{tar} was totally confused about this.
10555 When I wrote @code{PD TAR}, I used the historically correct terminology
10556 (@command{tar} writes data records, which are grouped into blocks).
10557 It appears that the bogus terminology made it into @acronym{POSIX} (no surprise
10558 here), and now Fran@,{c}ois has migrated that terminology back
10559 into the source code too.
10560 @end quotation
10561
10562 The term @dfn{physical block} means the basic transfer chunk from or
10563 to a device, after which reading or writing may stop without anything
10564 being lost. In this manual, the term @dfn{block} usually refers to
10565 a disk physical block, @emph{assuming} that each disk block is 512
10566 bytes in length. It is true that some disk devices have different
10567 physical blocks, but @command{tar} ignore these differences in its own
10568 format, which is meant to be portable, so a @command{tar} block is always
10569 512 bytes in length, and @dfn{block} always mean a @command{tar} block.
10570 The term @dfn{logical block} often represents the basic chunk of
10571 allocation of many disk blocks as a single entity, which the operating
10572 system treats somewhat atomically; this concept is only barely used
10573 in @GNUTAR{}.
10574
10575 The term @dfn{physical record} is another way to speak of a physical
10576 block, those two terms are somewhat interchangeable. In this manual,
10577 the term @dfn{record} usually refers to a tape physical block,
10578 @emph{assuming} that the @command{tar} archive is kept on magnetic tape.
10579 It is true that archives may be put on disk or used with pipes,
10580 but nevertheless, @command{tar} tries to read and write the archive one
10581 @dfn{record} at a time, whatever the medium in use. One record is made
10582 up of an integral number of blocks, and this operation of putting many
10583 disk blocks into a single tape block is called @dfn{reblocking}, or
10584 more simply, @dfn{blocking}. The term @dfn{logical record} refers to
10585 the logical organization of many characters into something meaningful
10586 to the application. The term @dfn{unit record} describes a small set
10587 of characters which are transmitted whole to or by the application,
10588 and often refers to a line of text. Those two last terms are unrelated
10589 to what we call a @dfn{record} in @GNUTAR{}.
10590
10591 When writing to tapes, @command{tar} writes the contents of the archive
10592 in chunks known as @dfn{records}. To change the default blocking
10593 factor, use the @option{--blocking-factor=@var{512-size}} (@option{-b
10594 @var{512-size}}) option. Each record will then be composed of
10595 @var{512-size} blocks. (Each @command{tar} block is 512 bytes.
10596 @xref{Standard}.) Each file written to the archive uses at least one
10597 full record. As a result, using a larger record size can result in
10598 more wasted space for small files. On the other hand, a larger record
10599 size can often be read and written much more efficiently.
10600
10601 Further complicating the problem is that some tape drives ignore the
10602 blocking entirely. For these, a larger record size can still improve
10603 performance (because the software layers above the tape drive still
10604 honor the blocking), but not as dramatically as on tape drives that
10605 honor blocking.
10606
10607 When reading an archive, @command{tar} can usually figure out the
10608 record size on itself. When this is the case, and a non-standard
10609 record size was used when the archive was created, @command{tar} will
10610 print a message about a non-standard blocking factor, and then operate
10611 normally. On some tape devices, however, @command{tar} cannot figure
10612 out the record size itself. On most of those, you can specify a
10613 blocking factor (with @option{--blocking-factor}) larger than the
10614 actual blocking factor, and then use the @option{--read-full-records}
10615 (@option{-B}) option. (If you specify a blocking factor with
10616 @option{--blocking-factor} and don't use the
10617 @option{--read-full-records} option, then @command{tar} will not
10618 attempt to figure out the recording size itself.) On some devices,
10619 you must always specify the record size exactly with
10620 @option{--blocking-factor} when reading, because @command{tar} cannot
10621 figure it out. In any case, use @option{--list} (@option{-t}) before
10622 doing any extractions to see whether @command{tar} is reading the archive
10623 correctly.
10624
10625 @command{tar} blocks are all fixed size (512 bytes), and its scheme for
10626 putting them into records is to put a whole number of them (one or
10627 more) into each record. @command{tar} records are all the same size;
10628 at the end of the file there's a block containing all zeros, which
10629 is how you tell that the remainder of the last record(s) are garbage.
10630
10631 In a standard @command{tar} file (no options), the block size is 512
10632 and the record size is 10240, for a blocking factor of 20. What the
10633 @option{--blocking-factor} option does is sets the blocking factor,
10634 changing the record size while leaving the block size at 512 bytes.
10635 20 was fine for ancient 800 or 1600 bpi reel-to-reel tape drives;
10636 most tape drives these days prefer much bigger records in order to
10637 stream and not waste tape. When writing tapes for myself, some tend
10638 to use a factor of the order of 2048, say, giving a record size of
10639 around one megabyte.
10640
10641 If you use a blocking factor larger than 20, older @command{tar}
10642 programs might not be able to read the archive, so we recommend this
10643 as a limit to use in practice. @GNUTAR{}, however,
10644 will support arbitrarily large record sizes, limited only by the
10645 amount of virtual memory or the physical characteristics of the tape
10646 device.
10647
10648 @menu
10649 * Format Variations:: Format Variations
10650 * Blocking Factor:: The Blocking Factor of an Archive
10651 @end menu
10652
10653 @node Format Variations
10654 @subsection Format Variations
10655 @cindex Format Parameters
10656 @cindex Format Options
10657 @cindex Options, archive format specifying
10658 @cindex Options, format specifying
10659 @UNREVISED
10660
10661 Format parameters specify how an archive is written on the archive
10662 media. The best choice of format parameters will vary depending on
10663 the type and number of files being archived, and on the media used to
10664 store the archive.
10665
10666 To specify format parameters when accessing or creating an archive,
10667 you can use the options described in the following sections.
10668 If you do not specify any format parameters, @command{tar} uses
10669 default parameters. You cannot modify a compressed archive.
10670 If you create an archive with the @option{--blocking-factor} option
10671 specified (@pxref{Blocking Factor}), you must specify that
10672 blocking-factor when operating on the archive. @xref{Formats}, for other
10673 examples of format parameter considerations.
10674
10675 @node Blocking Factor
10676 @subsection The Blocking Factor of an Archive
10677 @cindex Blocking Factor
10678 @cindex Record Size
10679 @cindex Number of blocks per record
10680 @cindex Number of bytes per record
10681 @cindex Bytes per record
10682 @cindex Blocks per record
10683 @UNREVISED
10684
10685 @opindex blocking-factor
10686 The data in an archive is grouped into blocks, which are 512 bytes.
10687 Blocks are read and written in whole number multiples called
10688 @dfn{records}. The number of blocks in a record (i.e., the size of a
10689 record in units of 512 bytes) is called the @dfn{blocking factor}.
10690 The @option{--blocking-factor=@var{512-size}} (@option{-b
10691 @var{512-size}}) option specifies the blocking factor of an archive.
10692 The default blocking factor is typically 20 (i.e., 10240 bytes), but
10693 can be specified at installation. To find out the blocking factor of
10694 an existing archive, use @samp{tar --list --file=@var{archive-name}}.
10695 This may not work on some devices.
10696
10697 Records are separated by gaps, which waste space on the archive media.
10698 If you are archiving on magnetic tape, using a larger blocking factor
10699 (and therefore larger records) provides faster throughput and allows you
10700 to fit more data on a tape (because there are fewer gaps). If you are
10701 archiving on cartridge, a very large blocking factor (say 126 or more)
10702 greatly increases performance. A smaller blocking factor, on the other
10703 hand, may be useful when archiving small files, to avoid archiving lots
10704 of nulls as @command{tar} fills out the archive to the end of the record.
10705 In general, the ideal record size depends on the size of the
10706 inter-record gaps on the tape you are using, and the average size of the
10707 files you are archiving. @xref{create}, for information on
10708 writing archives.
10709
10710 @FIXME{Need example of using a cartridge with blocking factor=126 or more.}
10711
10712 Archives with blocking factors larger than 20 cannot be read
10713 by very old versions of @command{tar}, or by some newer versions
10714 of @command{tar} running on old machines with small address spaces.
10715 With @GNUTAR{}, the blocking factor of an archive is limited
10716 only by the maximum record size of the device containing the archive,
10717 or by the amount of available virtual memory.
10718
10719 Also, on some systems, not using adequate blocking factors, as sometimes
10720 imposed by the device drivers, may yield unexpected diagnostics. For
10721 example, this has been reported:
10722
10723 @smallexample
10724 Cannot write to /dev/dlt: Invalid argument
10725 @end smallexample
10726
10727 @noindent
10728 In such cases, it sometimes happen that the @command{tar} bundled by
10729 the system is aware of block size idiosyncrasies, while @GNUTAR{}
10730 requires an explicit specification for the block size,
10731 which it cannot guess. This yields some people to consider
10732 @GNUTAR{} is misbehaving, because by comparison,
10733 @cite{the bundle @command{tar} works OK}. Adding @w{@kbd{-b 256}},
10734 for example, might resolve the problem.
10735
10736 If you use a non-default blocking factor when you create an archive, you
10737 must specify the same blocking factor when you modify that archive. Some
10738 archive devices will also require you to specify the blocking factor when
10739 reading that archive, however this is not typically the case. Usually, you
10740 can use @option{--list} (@option{-t}) without specifying a blocking factor---@command{tar}
10741 reports a non-default record size and then lists the archive members as
10742 it would normally. To extract files from an archive with a non-standard
10743 blocking factor (particularly if you're not sure what the blocking factor
10744 is), you can usually use the @option{--read-full-records} (@option{-B}) option while
10745 specifying a blocking factor larger then the blocking factor of the archive
10746 (i.e., @samp{tar --extract --read-full-records --blocking-factor=300}).
10747 @xref{list}, for more information on the @option{--list} (@option{-t})
10748 operation. @xref{Reading}, for a more detailed explanation of that option.
10749
10750 @table @option
10751 @item --blocking-factor=@var{number}
10752 @itemx -b @var{number}
10753 Specifies the blocking factor of an archive. Can be used with any
10754 operation, but is usually not necessary with @option{--list} (@option{-t}).
10755 @end table
10756
10757 Device blocking
10758
10759 @table @option
10760 @item -b @var{blocks}
10761 @itemx --blocking-factor=@var{blocks}
10762 Set record size to @math{@var{blocks}*512} bytes.
10763
10764 This option is used to specify a @dfn{blocking factor} for the archive.
10765 When reading or writing the archive, @command{tar}, will do reads and writes
10766 of the archive in records of @math{@var{block}*512} bytes. This is true
10767 even when the archive is compressed. Some devices requires that all
10768 write operations be a multiple of a certain size, and so, @command{tar}
10769 pads the archive out to the next record boundary.
10770
10771 The default blocking factor is set when @command{tar} is compiled, and is
10772 typically 20. Blocking factors larger than 20 cannot be read by very
10773 old versions of @command{tar}, or by some newer versions of @command{tar}
10774 running on old machines with small address spaces.
10775
10776 With a magnetic tape, larger records give faster throughput and fit
10777 more data on a tape (because there are fewer inter-record gaps).
10778 If the archive is in a disk file or a pipe, you may want to specify
10779 a smaller blocking factor, since a large one will result in a large
10780 number of null bytes at the end of the archive.
10781
10782 When writing cartridge or other streaming tapes, a much larger
10783 blocking factor (say 126 or more) will greatly increase performance.
10784 However, you must specify the same blocking factor when reading or
10785 updating the archive.
10786
10787 Apparently, Exabyte drives have a physical block size of 8K bytes.
10788 If we choose our blocksize as a multiple of 8k bytes, then the problem
10789 seems to disappear. Id est, we are using block size of 112 right
10790 now, and we haven't had the problem since we switched@dots{}
10791
10792 With @GNUTAR{} the blocking factor is limited only
10793 by the maximum record size of the device containing the archive, or by
10794 the amount of available virtual memory.
10795
10796 However, deblocking or reblocking is virtually avoided in a special
10797 case which often occurs in practice, but which requires all the
10798 following conditions to be simultaneously true:
10799 @itemize @bullet
10800 @item
10801 the archive is subject to a compression option,
10802 @item
10803 the archive is not handled through standard input or output, nor
10804 redirected nor piped,
10805 @item
10806 the archive is directly handled to a local disk, instead of any special
10807 device,
10808 @item
10809 @option{--blocking-factor} is not explicitly specified on the @command{tar}
10810 invocation.
10811 @end itemize
10812
10813 If the output goes directly to a local disk, and not through
10814 stdout, then the last write is not extended to a full record size.
10815 Otherwise, reblocking occurs. Here are a few other remarks on this
10816 topic:
10817
10818 @itemize @bullet
10819
10820 @item
10821 @command{gzip} will complain about trailing garbage if asked to
10822 uncompress a compressed archive on tape, there is an option to turn
10823 the message off, but it breaks the regularity of simply having to use
10824 @samp{@var{prog} -d} for decompression. It would be nice if gzip was
10825 silently ignoring any number of trailing zeros. I'll ask Jean-loup
10826 Gailly, by sending a copy of this message to him.
10827
10828 @item
10829 @command{compress} does not show this problem, but as Jean-loup pointed
10830 out to Michael, @samp{compress -d} silently adds garbage after
10831 the result of decompression, which tar ignores because it already
10832 recognized its end-of-file indicator. So this bug may be safely
10833 ignored.
10834
10835 @item
10836 @samp{gzip -d -q} will be silent about the trailing zeros indeed,
10837 but will still return an exit status of 2 which tar reports in turn.
10838 @command{tar} might ignore the exit status returned, but I hate doing
10839 that, as it weakens the protection @command{tar} offers users against
10840 other possible problems at decompression time. If @command{gzip} was
10841 silently skipping trailing zeros @emph{and} also avoiding setting the
10842 exit status in this innocuous case, that would solve this situation.
10843
10844 @item
10845 @command{tar} should become more solid at not stopping to read a pipe at
10846 the first null block encountered. This inelegantly breaks the pipe.
10847 @command{tar} should rather drain the pipe out before exiting itself.
10848 @end itemize
10849
10850 @xopindex{ignore-zeros, short description}
10851 @item -i
10852 @itemx --ignore-zeros
10853 Ignore blocks of zeros in archive (means EOF).
10854
10855 The @option{--ignore-zeros} (@option{-i}) option causes @command{tar} to ignore blocks
10856 of zeros in the archive. Normally a block of zeros indicates the
10857 end of the archive, but when reading a damaged archive, or one which
10858 was created by concatenating several archives together, this option
10859 allows @command{tar} to read the entire archive. This option is not on
10860 by default because many versions of @command{tar} write garbage after
10861 the zeroed blocks.
10862
10863 Note that this option causes @command{tar} to read to the end of the
10864 archive file, which may sometimes avoid problems when multiple files
10865 are stored on a single physical tape.
10866
10867 @xopindex{read-full-records, short description}
10868 @item -B
10869 @itemx --read-full-records
10870 Reblock as we read (for reading 4.2@acronym{BSD} pipes).
10871
10872 If @option{--read-full-records} is used, @command{tar}
10873 will not panic if an attempt to read a record from the archive does
10874 not return a full record. Instead, @command{tar} will keep reading
10875 until it has obtained a full
10876 record.
10877
10878 This option is turned on by default when @command{tar} is reading
10879 an archive from standard input, or from a remote machine. This is
10880 because on @acronym{BSD} Unix systems, a read of a pipe will return however
10881 much happens to be in the pipe, even if it is less than @command{tar}
10882 requested. If this option was not used, @command{tar} would fail as
10883 soon as it read an incomplete record from the pipe.
10884
10885 This option is also useful with the commands for updating an archive.
10886
10887 @end table
10888
10889 Tape blocking
10890
10891 @FIXME{Appropriate options should be moved here from elsewhere.}
10892
10893 @cindex blocking factor
10894 @cindex tape blocking
10895
10896 When handling various tapes or cartridges, you have to take care of
10897 selecting a proper blocking, that is, the number of disk blocks you
10898 put together as a single tape block on the tape, without intervening
10899 tape gaps. A @dfn{tape gap} is a small landing area on the tape
10900 with no information on it, used for decelerating the tape to a
10901 full stop, and for later regaining the reading or writing speed.
10902 When the tape driver starts reading a record, the record has to
10903 be read whole without stopping, as a tape gap is needed to stop the
10904 tape motion without losing information.
10905
10906 @cindex Exabyte blocking
10907 @cindex DAT blocking
10908 Using higher blocking (putting more disk blocks per tape block) will use
10909 the tape more efficiently as there will be less tape gaps. But reading
10910 such tapes may be more difficult for the system, as more memory will be
10911 required to receive at once the whole record. Further, if there is a
10912 reading error on a huge record, this is less likely that the system will
10913 succeed in recovering the information. So, blocking should not be too
10914 low, nor it should be too high. @command{tar} uses by default a blocking of
10915 20 for historical reasons, and it does not really matter when reading or
10916 writing to disk. Current tape technology would easily accommodate higher
10917 blockings. Sun recommends a blocking of 126 for Exabytes and 96 for DATs.
10918 We were told that for some DLT drives, the blocking should be a multiple
10919 of 4Kb, preferably 64Kb (@w{@kbd{-b 128}}) or 256 for decent performance.
10920 Other manufacturers may use different recommendations for the same tapes.
10921 This might also depends of the buffering techniques used inside modern
10922 tape controllers. Some imposes a minimum blocking, or a maximum blocking.
10923 Others request blocking to be some exponent of two.
10924
10925 So, there is no fixed rule for blocking. But blocking at read time
10926 should ideally be the same as blocking used at write time. At one place
10927 I know, with a wide variety of equipment, they found it best to use a
10928 blocking of 32 to guarantee that their tapes are fully interchangeable.
10929
10930 I was also told that, for recycled tapes, prior erasure (by the same
10931 drive unit that will be used to create the archives) sometimes lowers
10932 the error rates observed at rewriting time.
10933
10934 I might also use @option{--number-blocks} instead of
10935 @option{--block-number}, so @option{--block} will then expand to
10936 @option{--blocking-factor} unambiguously.
10937
10938 @node Many
10939 @section Many Archives on One Tape
10940
10941 @FIXME{Appropriate options should be moved here from elsewhere.}
10942
10943 @findex ntape @r{device}
10944 Most tape devices have two entries in the @file{/dev} directory, or
10945 entries that come in pairs, which differ only in the minor number for
10946 this device. Let's take for example @file{/dev/tape}, which often
10947 points to the only or usual tape device of a given system. There might
10948 be a corresponding @file{/dev/nrtape} or @file{/dev/ntape}. The simpler
10949 name is the @emph{rewinding} version of the device, while the name
10950 having @samp{nr} in it is the @emph{no rewinding} version of the same
10951 device.
10952
10953 A rewinding tape device will bring back the tape to its beginning point
10954 automatically when this device is opened or closed. Since @command{tar}
10955 opens the archive file before using it and closes it afterwards, this
10956 means that a simple:
10957
10958 @smallexample
10959 $ @kbd{tar cf /dev/tape @var{directory}}
10960 @end smallexample
10961
10962 @noindent
10963 will reposition the tape to its beginning both prior and after saving
10964 @var{directory} contents to it, thus erasing prior tape contents and
10965 making it so that any subsequent write operation will destroy what has
10966 just been saved.
10967
10968 @cindex tape positioning
10969 So, a rewinding device is normally meant to hold one and only one file.
10970 If you want to put more than one @command{tar} archive on a given tape, you
10971 will need to avoid using the rewinding version of the tape device. You
10972 will also have to pay special attention to tape positioning. Errors in
10973 positioning may overwrite the valuable data already on your tape. Many
10974 people, burnt by past experiences, will only use rewinding devices and
10975 limit themselves to one file per tape, precisely to avoid the risk of
10976 such errors. Be fully aware that writing at the wrong position on a
10977 tape loses all information past this point and most probably until the
10978 end of the tape, and this destroyed information @emph{cannot} be
10979 recovered.
10980
10981 To save @var{directory-1} as a first archive at the beginning of a
10982 tape, and leave that tape ready for a second archive, you should use:
10983
10984 @smallexample
10985 $ @kbd{mt -f /dev/nrtape rewind}
10986 $ @kbd{tar cf /dev/nrtape @var{directory-1}}
10987 @end smallexample
10988
10989 @cindex tape marks
10990 @dfn{Tape marks} are special magnetic patterns written on the tape
10991 media, which are later recognizable by the reading hardware. These
10992 marks are used after each file, when there are many on a single tape.
10993 An empty file (that is to say, two tape marks in a row) signal the
10994 logical end of the tape, after which no file exist. Usually,
10995 non-rewinding tape device drivers will react to the close request issued
10996 by @command{tar} by first writing two tape marks after your archive, and by
10997 backspacing over one of these. So, if you remove the tape at that time
10998 from the tape drive, it is properly terminated. But if you write
10999 another file at the current position, the second tape mark will be
11000 erased by the new information, leaving only one tape mark between files.
11001
11002 So, you may now save @var{directory-2} as a second archive after the
11003 first on the same tape by issuing the command:
11004
11005 @smallexample
11006 $ @kbd{tar cf /dev/nrtape @var{directory-2}}
11007 @end smallexample
11008
11009 @noindent
11010 and so on for all the archives you want to put on the same tape.
11011
11012 Another usual case is that you do not write all the archives the same
11013 day, and you need to remove and store the tape between two archive
11014 sessions. In general, you must remember how many files are already
11015 saved on your tape. Suppose your tape already has 16 files on it, and
11016 that you are ready to write the 17th. You have to take care of skipping
11017 the first 16 tape marks before saving @var{directory-17}, say, by using
11018 these commands:
11019
11020 @smallexample
11021 $ @kbd{mt -f /dev/nrtape rewind}
11022 $ @kbd{mt -f /dev/nrtape fsf 16}
11023 $ @kbd{tar cf /dev/nrtape @var{directory-17}}
11024 @end smallexample
11025
11026 In all the previous examples, we put aside blocking considerations, but
11027 you should do the proper things for that as well. @xref{Blocking}.
11028
11029 @menu
11030 * Tape Positioning:: Tape Positions and Tape Marks
11031 * mt:: The @command{mt} Utility
11032 @end menu
11033
11034 @node Tape Positioning
11035 @subsection Tape Positions and Tape Marks
11036 @UNREVISED
11037
11038 Just as archives can store more than one file from the file system,
11039 tapes can store more than one archive file. To keep track of where
11040 archive files (or any other type of file stored on tape) begin and
11041 end, tape archive devices write magnetic @dfn{tape marks} on the
11042 archive media. Tape drives write one tape mark between files,
11043 two at the end of all the file entries.
11044
11045 If you think of data as a series of records "rrrr"'s, and tape marks as
11046 "*"'s, a tape might look like the following:
11047
11048 @smallexample
11049 rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------
11050 @end smallexample
11051
11052 Tape devices read and write tapes using a read/write @dfn{tape
11053 head}---a physical part of the device which can only access one
11054 point on the tape at a time. When you use @command{tar} to read or
11055 write archive data from a tape device, the device will begin reading
11056 or writing from wherever on the tape the tape head happens to be,
11057 regardless of which archive or what part of the archive the tape
11058 head is on. Before writing an archive, you should make sure that no
11059 data on the tape will be overwritten (unless it is no longer needed).
11060 Before reading an archive, you should make sure the tape head is at
11061 the beginning of the archive you want to read. You can do it manually
11062 via @code{mt} utility (@pxref{mt}). The @code{restore} script does
11063 that automatically (@pxref{Scripted Restoration}).
11064
11065 If you want to add new archive file entries to a tape, you should
11066 advance the tape to the end of the existing file entries, backspace
11067 over the last tape mark, and write the new archive file. If you were
11068 to add two archives to the example above, the tape might look like the
11069 following:
11070
11071 @smallexample
11072 rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------
11073 @end smallexample
11074
11075 @node mt
11076 @subsection The @command{mt} Utility
11077 @UNREVISED
11078
11079 @FIXME{Is it true that this only works on non-block devices?
11080 should explain the difference, (fixed or variable).}
11081 @xref{Blocking Factor}.
11082
11083 You can use the @command{mt} utility to advance or rewind a tape past a
11084 specified number of archive files on the tape. This will allow you
11085 to move to the beginning of an archive before extracting or reading
11086 it, or to the end of all the archives before writing a new one.
11087 @FIXME{Why isn't there an "advance 'til you find two tape marks
11088 together"?}
11089
11090 The syntax of the @command{mt} command is:
11091
11092 @smallexample
11093 @kbd{mt [-f @var{tapename}] @var{operation} [@var{number}]}
11094 @end smallexample
11095
11096 where @var{tapename} is the name of the tape device, @var{number} is
11097 the number of times an operation is performed (with a default of one),
11098 and @var{operation} is one of the following:
11099
11100 @FIXME{is there any use for record operations?}
11101
11102 @table @option
11103 @item eof
11104 @itemx weof
11105 Writes @var{number} tape marks at the current position on the tape.
11106
11107 @item fsf
11108 Moves tape position forward @var{number} files.
11109
11110 @item bsf
11111 Moves tape position back @var{number} files.
11112
11113 @item rewind
11114 Rewinds the tape. (Ignores @var{number}.)
11115
11116 @item offline
11117 @itemx rewoff1
11118 Rewinds the tape and takes the tape device off-line. (Ignores @var{number}.)
11119
11120 @item status
11121 Prints status information about the tape unit.
11122
11123 @end table
11124
11125 If you don't specify a @var{tapename}, @command{mt} uses the environment
11126 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
11127 the default device specified in your @file{sys/mtio.h} file
11128 (@code{DEFTAPE} variable). If this is not defined, the program will
11129 display a descriptive error message and exit with code 1.
11130
11131 @command{mt} returns a 0 exit status when the operation(s) were
11132 successful, 1 if the command was unrecognized, and 2 if an operation
11133 failed.
11134
11135 @node Using Multiple Tapes
11136 @section Using Multiple Tapes
11137
11138 Often you might want to write a large archive, one larger than will fit
11139 on the actual tape you are using. In such a case, you can run multiple
11140 @command{tar} commands, but this can be inconvenient, particularly if you
11141 are using options like @option{--exclude=@var{pattern}} or dumping entire file systems.
11142 Therefore, @command{tar} provides a special mode for creating
11143 multi-volume archives.
11144
11145 @dfn{Multi-volume} archive is a single @command{tar} archive, stored
11146 on several media volumes of fixed size. Although in this section we will
11147 often call @samp{volume} a @dfn{tape}, there is absolutely no
11148 requirement for multi-volume archives to be stored on tapes. Instead,
11149 they can use whatever media type the user finds convenient, they can
11150 even be located on files.
11151
11152 When creating a multi-volume archive, @GNUTAR{} continues to fill
11153 current volume until it runs out of space, then it switches to
11154 next volume (usually the operator is queried to replace the tape on
11155 this point), and continues working on the new volume. This operation
11156 continues until all requested files are dumped. If @GNUTAR{} detects
11157 end of media while dumping a file, such a file is archived in split
11158 form. Some very big files can even be split across several volumes.
11159
11160 Each volume is itself a valid @GNUTAR{} archive, so it can be read
11161 without any special options. Consequently any file member residing
11162 entirely on one volume can be extracted or otherwise operated upon
11163 without needing the other volume. Sure enough, to extract a split
11164 member you would need all volumes its parts reside on.
11165
11166 Multi-volume archives suffer from several limitations. In particular,
11167 they cannot be compressed.
11168
11169 @GNUTAR{} is able to create multi-volume archives of two formats
11170 (@pxref{Formats}): @samp{GNU} and @samp{POSIX}.
11171
11172 @menu
11173 * Multi-Volume Archives:: Archives Longer than One Tape or Disk
11174 * Tape Files:: Tape Files
11175 * Tarcat:: Concatenate Volumes into a Single Archive
11176
11177 @end menu
11178
11179 @node Multi-Volume Archives
11180 @subsection Archives Longer than One Tape or Disk
11181 @cindex Multi-volume archives
11182
11183 @opindex multi-volume
11184 To create an archive that is larger than will fit on a single unit of
11185 the media, use the @option{--multi-volume} (@option{-M}) option in conjunction with
11186 the @option{--create} option (@pxref{create}). A @dfn{multi-volume}
11187 archive can be manipulated like any other archive (provided the
11188 @option{--multi-volume} option is specified), but is stored on more
11189 than one tape or file.
11190
11191 When you specify @option{--multi-volume}, @command{tar} does not report an
11192 error when it comes to the end of an archive volume (when reading), or
11193 the end of the media (when writing). Instead, it prompts you to load
11194 a new storage volume. If the archive is on a magnetic tape, you
11195 should change tapes when you see the prompt; if the archive is on a
11196 floppy disk, you should change disks; etc.
11197
11198 @table @option
11199 @item --multi-volume
11200 @itemx -M
11201 Creates a multi-volume archive, when used in conjunction with
11202 @option{--create} (@option{-c}). To perform any other operation on a multi-volume
11203 archive, specify @option{--multi-volume} in conjunction with that
11204 operation.
11205 For example:
11206
11207 @smallexample
11208 $ @kbd{tar --create --multi-volume --file=/dev/tape @var{files}}
11209 @end smallexample
11210 @end table
11211
11212 The method @command{tar} uses to detect end of tape is not perfect, and
11213 fails on some operating systems or on some devices. If @command{tar}
11214 cannot detect the end of the tape itself, you can use
11215 @option{--tape-length} option to inform it about the capacity of the
11216 tape:
11217
11218 @anchor{tape-length}
11219 @table @option
11220 @opindex tape-length
11221 @item --tape-length=@var{size}[@var{suf}]
11222 @itemx -L @var{size}[@var{suf}]
11223 Set maximum length of a volume. The @var{suf}, if given, specifies
11224 units in which @var{size} is expressed, e.g. @samp{2M} mean 2
11225 megabytes (@pxref{size-suffixes}, for a list of allowed size
11226 suffixes). Without @var{suf}, units of 1024 bytes (kilobyte) are
11227 assumed.
11228
11229 This option selects @option{--multi-volume} automatically. For example:
11230
11231 @smallexample
11232 $ @kbd{tar --create --tape-length=41943040 --file=/dev/tape @var{files}}
11233 @end smallexample
11234
11235 @noindent
11236 or, which is equivalent:
11237
11238 @smallexample
11239 $ @kbd{tar --create --tape-length=4G --file=/dev/tape @var{files}}
11240 @end smallexample
11241 @end table
11242
11243 @anchor{change volume prompt}
11244 When @GNUTAR{} comes to the end of a storage media, it asks you to
11245 change the volume. The built-in prompt for POSIX locale
11246 is@footnote{If you run @GNUTAR{} under a different locale, the
11247 translation to the locale's language will be used.}:
11248
11249 @smallexample
11250 Prepare volume #@var{n} for `@var{archive}' and hit return:
11251 @end smallexample
11252
11253 @noindent
11254 where @var{n} is the ordinal number of the volume to be created and
11255 @var{archive} is archive file or device name.
11256
11257 When prompting for a new tape, @command{tar} accepts any of the following
11258 responses:
11259
11260 @table @kbd
11261 @item ?
11262 Request @command{tar} to explain possible responses.
11263 @item q
11264 Request @command{tar} to exit immediately.
11265 @item n @var{file-name}
11266 Request @command{tar} to write the next volume on the file @var{file-name}.
11267 @item !
11268 Request @command{tar} to run a subshell. This option can be disabled
11269 by giving @option{--restrict} command line option to
11270 @command{tar}@footnote{@xref{--restrict}, for more information about
11271 this option.}.
11272 @item y
11273 Request @command{tar} to begin writing the next volume.
11274 @end table
11275
11276 (You should only type @samp{y} after you have changed the tape;
11277 otherwise @command{tar} will write over the volume it just finished.)
11278
11279 @cindex Volume number file
11280 @cindex volno file
11281 @anchor{volno-file}
11282 @opindex volno-file
11283 The volume number used by @command{tar} in its tape-changing prompt
11284 can be changed; if you give the
11285 @option{--volno-file=@var{file-of-number}} option, then
11286 @var{file-of-number} should be an non-existing file to be created, or
11287 else, a file already containing a decimal number. That number will be
11288 used as the volume number of the first volume written. When
11289 @command{tar} is finished, it will rewrite the file with the
11290 now-current volume number. (This does not change the volume number
11291 written on a tape label, as per @ref{label}, it @emph{only} affects
11292 the number used in the prompt.)
11293
11294 @cindex End-of-archive info script
11295 @cindex Info script
11296 @anchor{info-script}
11297 @opindex info-script
11298 @opindex new-volume-script
11299 If you want more elaborate behavior than this, you can write a special
11300 @dfn{new volume script}, that will be responsible for changing the
11301 volume, and instruct @command{tar} to use it instead of its normal
11302 prompting procedure:
11303
11304 @table @option
11305 @item --info-script=@var{script-name}
11306 @itemx --new-volume-script=@var{script-name}
11307 @itemx -F @var{script-name}
11308 Specify the full name of the volume script to use. The script can be
11309 used to eject cassettes, or to broadcast messages such as
11310 @samp{Someone please come change my tape} when performing unattended
11311 backups.
11312 @end table
11313
11314 The @var{script-name} is executed without any command line
11315 arguments. It inherits @command{tar}'s shell environment.
11316 Additional data is passed to it via the following
11317 environment variables:
11318
11319 @table @env
11320 @vrindex TAR_VERSION, info script environment variable
11321 @item TAR_VERSION
11322 @GNUTAR{} version number.
11323
11324 @vrindex TAR_ARCHIVE, info script environment variable
11325 @item TAR_ARCHIVE
11326 The name of the archive @command{tar} is processing.
11327
11328 @vrindex TAR_BLOCKING_FACTOR, info script environment variable
11329 @item TAR_BLOCKING_FACTOR
11330 Current blocking factor (@pxref{Blocking}).
11331
11332 @vrindex TAR_VOLUME, info script environment variable
11333 @item TAR_VOLUME
11334 Ordinal number of the volume @command{tar} is about to start.
11335
11336 @vrindex TAR_SUBCOMMAND, info script environment variable
11337 @item TAR_SUBCOMMAND
11338 A short option describing the operation @command{tar} is executing.
11339 @xref{Operations}, for a complete list of subcommand options.
11340
11341 @vrindex TAR_FORMAT, info script environment variable
11342 @item TAR_FORMAT
11343 Format of the archive being processed. @xref{Formats}, for a complete
11344 list of archive format names.
11345
11346 @vrindex TAR_FD, info script environment variable
11347 @item TAR_FD
11348 File descriptor which can be used to communicate the new volume
11349 name to @command{tar}.
11350 @end table
11351
11352 The volume script can instruct @command{tar} to use new archive name,
11353 by writing in to file descriptor @env{$TAR_FD} (see below for an example).
11354
11355 If the info script fails, @command{tar} exits; otherwise, it begins
11356 writing the next volume.
11357
11358 If you want @command{tar} to cycle through a series of files or tape
11359 drives, there are three approaches to choose from. First of all, you
11360 can give @command{tar} multiple @option{--file} options. In this case
11361 the specified files will be used, in sequence, as the successive
11362 volumes of the archive. Only when the first one in the sequence needs
11363 to be used again will @command{tar} prompt for a tape change (or run
11364 the info script). For example, suppose someone has two tape drives on
11365 a system named @file{/dev/tape0} and @file{/dev/tape1}. For having
11366 @GNUTAR{} to switch to the second drive when it needs to write the
11367 second tape, and then back to the first tape, etc., just do either of:
11368
11369 @smallexample
11370 $ @kbd{tar --create --multi-volume --file=/dev/tape0 --file=/dev/tape1 @var{files}}
11371 $ @kbd{tar cMff /dev/tape0 /dev/tape1 @var{files}}
11372 @end smallexample
11373
11374 The second method is to use the @samp{n} response to the tape-change
11375 prompt.
11376
11377 Finally, the most flexible approach is to use a volume script, that
11378 writes new archive name to the file descriptor @env{$TAR_FD}. For example, the
11379 following volume script will create a series of archive files, named
11380 @file{@var{archive}-@var{vol}}, where @var{archive} is the name of the
11381 archive being created (as given by @option{--file} option) and
11382 @var{vol} is the ordinal number of the archive being created:
11383
11384 @smallexample
11385 @group
11386 #! /bin/sh
11387 echo Preparing volume $TAR_VOLUME of $TAR_ARCHIVE.
11388
11389 name=`expr $TAR_ARCHIVE : '\(.*\)-.*'`
11390 case $TAR_SUBCOMMAND in
11391 -c) ;;
11392 -d|-x|-t) test -r $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME || exit 1
11393 ;;
11394 *) exit 1
11395 esac
11396
11397 echo $@{name:-$TAR_ARCHIVE@}-$TAR_VOLUME >&$TAR_FD
11398 @end group
11399 @end smallexample
11400
11401 The same script can be used while listing, comparing or extracting
11402 from the created archive. For example:
11403
11404 @smallexample
11405 @group
11406 # @r{Create a multi-volume archive:}
11407 $ @kbd{tar -c -L1024 -f archive.tar -F new-volume .}
11408 # @r{Extract from the created archive:}
11409 $ @kbd{tar -x -f archive.tar -F new-volume .}
11410 @end group
11411 @end smallexample
11412
11413 @noindent
11414 Notice, that the first command had to use @option{-L} option, since
11415 otherwise @GNUTAR{} will end up writing everything to file
11416 @file{archive.tar}.
11417
11418 You can read each individual volume of a multi-volume archive as if it
11419 were an archive by itself. For example, to list the contents of one
11420 volume, use @option{--list}, without @option{--multi-volume} specified.
11421 To extract an archive member from one volume (assuming it is described
11422 that volume), use @option{--extract}, again without
11423 @option{--multi-volume}.
11424
11425 If an archive member is split across volumes (i.e., its entry begins on
11426 one volume of the media and ends on another), you need to specify
11427 @option{--multi-volume} to extract it successfully. In this case, you
11428 should load the volume where the archive member starts, and use
11429 @samp{tar --extract --multi-volume}---@command{tar} will prompt for later
11430 volumes as it needs them. @xref{extracting archives}, for more
11431 information about extracting archives.
11432
11433 Multi-volume archives can be modified like any other archive. To add
11434 files to a multi-volume archive, you need to only mount the last
11435 volume of the archive media (and new volumes, if needed). For all
11436 other operations, you need to use the entire archive.
11437
11438 If a multi-volume archive was labeled using
11439 @option{--label=@var{archive-label}} (@pxref{label}) when it was
11440 created, @command{tar} will not automatically label volumes which are
11441 added later. To label subsequent volumes, specify
11442 @option{--label=@var{archive-label}} again in conjunction with the
11443 @option{--append}, @option{--update} or @option{--concatenate} operation.
11444
11445 Notice that multi-volume support is a GNU extension and the archives
11446 created in this mode should be read only using @GNUTAR{}. If you
11447 absolutely have to process such archives using a third-party @command{tar}
11448 implementation, read @ref{Split Recovery}.
11449
11450 @node Tape Files
11451 @subsection Tape Files
11452 @cindex labeling archives
11453 @opindex label
11454 @UNREVISED
11455
11456 To give the archive a name which will be recorded in it, use the
11457 @option{--label=@var{volume-label}} (@option{-V @var{volume-label}})
11458 option. This will write a special block identifying
11459 @var{volume-label} as the name of the archive to the front of the
11460 archive which will be displayed when the archive is listed with
11461 @option{--list}. If you are creating a multi-volume archive with
11462 @option{--multi-volume} (@pxref{Using Multiple Tapes}), then the
11463 volume label will have @samp{Volume @var{nnn}} appended to the name
11464 you give, where @var{nnn} is the number of the volume of the archive.
11465 If you use the @option{--label=@var{volume-label}} option when
11466 reading an archive, it checks to make sure the label on the tape
11467 matches the one you gave. @xref{label}.
11468
11469 When @command{tar} writes an archive to tape, it creates a single
11470 tape file. If multiple archives are written to the same tape, one
11471 after the other, they each get written as separate tape files. When
11472 extracting, it is necessary to position the tape at the right place
11473 before running @command{tar}. To do this, use the @command{mt} command.
11474 For more information on the @command{mt} command and on the organization
11475 of tapes into a sequence of tape files, see @ref{mt}.
11476
11477 People seem to often do:
11478
11479 @smallexample
11480 @kbd{--label="@var{some-prefix} `date +@var{some-format}`"}
11481 @end smallexample
11482
11483 or such, for pushing a common date in all volumes or an archive set.
11484
11485 @node Tarcat
11486 @subsection Concatenate Volumes into a Single Archive
11487
11488 @pindex tarcat
11489 Sometimes it is necessary to convert existing @GNUTAR{} multi-volume
11490 archive to a single @command{tar} archive. Simply concatenating all
11491 volumes into one will not work, since each volume carries an additional
11492 information at the beginning. @GNUTAR{} is shipped with the shell
11493 script @command{tarcat} designed for this purpose.
11494
11495 The script takes a list of files comprising a multi-volume archive
11496 and creates the resulting archive at the standard output. For example:
11497
11498 @smallexample
11499 @kbd{tarcat vol.1 vol.2 vol.3 | tar tf -}
11500 @end smallexample
11501
11502 The script implements a simple heuristics to determine the format of
11503 the first volume file and to decide how to process the rest of the
11504 files. However, it makes no attempt to verify whether the files are
11505 given in order or even if they are valid @command{tar} archives.
11506 It uses @command{dd} and does not filter its standard error, so you
11507 will usually see lots of spurious messages.
11508
11509 @FIXME{The script is not installed. Should we install it?}
11510
11511 @node label
11512 @section Including a Label in the Archive
11513 @cindex Labeling an archive
11514 @cindex Labels on the archive media
11515 @cindex Labeling multi-volume archives
11516
11517 @opindex label
11518 To avoid problems caused by misplaced paper labels on the archive
11519 media, you can include a @dfn{label} entry --- an archive member which
11520 contains the name of the archive --- in the archive itself. Use the
11521 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11522 option@footnote{Until version 1.10, that option was called
11523 @option{--volume}, but is not available under that name anymore.} in
11524 conjunction with the @option{--create} operation to include a label
11525 entry in the archive as it is being created.
11526
11527 @table @option
11528 @item --label=@var{archive-label}
11529 @itemx -V @var{archive-label}
11530 Includes an @dfn{archive-label} at the beginning of the archive when
11531 the archive is being created, when used in conjunction with the
11532 @option{--create} operation. Checks to make sure the archive label
11533 matches the one specified (when used in conjunction with any other
11534 operation).
11535 @end table
11536
11537 If you create an archive using both
11538 @option{--label=@var{archive-label}} (@option{-V @var{archive-label}})
11539 and @option{--multi-volume} (@option{-M}), each volume of the archive
11540 will have an archive label of the form @samp{@var{archive-label}
11541 Volume @var{n}}, where @var{n} is 1 for the first volume, 2 for the
11542 next, and so on. @xref{Using Multiple Tapes}, for information on
11543 creating multiple volume archives.
11544
11545 @cindex Volume label, listing
11546 @cindex Listing volume label
11547 The volume label will be displayed by @option{--list} along with
11548 the file contents. If verbose display is requested, it will also be
11549 explicitly marked as in the example below:
11550
11551 @smallexample
11552 @group
11553 $ @kbd{tar --verbose --list --file=iamanarchive}
11554 V--------- 0 0 0 1992-03-07 12:01 iamalabel--Volume Header--
11555 -rw-r--r-- ringo user 40 1990-05-21 13:30 iamafilename
11556 @end group
11557 @end smallexample
11558
11559 @opindex test-label
11560 @anchor{--test-label option}
11561 However, @option{--list} option will cause listing entire
11562 contents of the archive, which may be undesirable (for example, if the
11563 archive is stored on a tape). You can request checking only the volume
11564 label by specifying @option{--test-label} option. This option reads only the
11565 first block of an archive, so it can be used with slow storage
11566 devices. For example:
11567
11568 @smallexample
11569 @group
11570 $ @kbd{tar --test-label --file=iamanarchive}
11571 iamalabel
11572 @end group
11573 @end smallexample
11574
11575 If @option{--test-label} is used with one or more command line
11576 arguments, @command{tar} compares the volume label with each
11577 argument. It exits with code 0 if a match is found, and with code 1
11578 otherwise@footnote{Note that @GNUTAR{} versions up to 1.23 indicated
11579 mismatch with an exit code 2 and printed a spurious diagnostics on
11580 stderr.}. No output is displayed, unless you also used the
11581 @option{--verbose} option. For example:
11582
11583 @smallexample
11584 @group
11585 $ @kbd{tar --test-label --file=iamanarchive 'iamalabel'}
11586 @result{} 0
11587 $ @kbd{tar --test-label --file=iamanarchive 'alabel'}
11588 @result{} 1
11589 @end group
11590 @end smallexample
11591
11592 When used with the @option{--verbose} option, @command{tar}
11593 prints the actual volume label (if any), and a verbose diagnostics in
11594 case of a mismatch:
11595
11596 @smallexample
11597 @group
11598 $ @kbd{tar --test-label --verbose --file=iamanarchive 'iamalabel'}
11599 iamalabel
11600 @result{} 0
11601 $ @kbd{tar --test-label --verbose --file=iamanarchive 'alabel'}
11602 iamalabel
11603 tar: Archive label mismatch
11604 @result{} 1
11605 @end group
11606 @end smallexample
11607
11608 If you request any operation, other than @option{--create}, along
11609 with using @option{--label} option, @command{tar} will first check if
11610 the archive label matches the one specified and will refuse to proceed
11611 if it does not. Use this as a safety precaution to avoid accidentally
11612 overwriting existing archives. For example, if you wish to add files
11613 to @file{archive}, presumably labeled with string @samp{My volume},
11614 you will get:
11615
11616 @smallexample
11617 @group
11618 $ @kbd{tar -rf archive --label 'My volume' .}
11619 tar: Archive not labeled to match `My volume'
11620 @end group
11621 @end smallexample
11622
11623 @noindent
11624 in case its label does not match. This will work even if
11625 @file{archive} is not labeled at all.
11626
11627 Similarly, @command{tar} will refuse to list or extract the
11628 archive if its label doesn't match the @var{archive-label}
11629 specified. In those cases, @var{archive-label} argument is interpreted
11630 as a globbing-style pattern which must match the actual magnetic
11631 volume label. @xref{exclude}, for a precise description of how match
11632 is attempted@footnote{Previous versions of @command{tar} used full
11633 regular expression matching, or before that, only exact string
11634 matching, instead of wildcard matchers. We decided for the sake of
11635 simplicity to use a uniform matching device through
11636 @command{tar}.}. If the switch @option{--multi-volume} (@option{-M}) is being used,
11637 the volume label matcher will also suffix @var{archive-label} by
11638 @w{@samp{ Volume [1-9]*}} if the initial match fails, before giving
11639 up. Since the volume numbering is automatically added in labels at
11640 creation time, it sounded logical to equally help the user taking care
11641 of it when the archive is being read.
11642
11643 You can also use @option{--label} to get a common information on
11644 all tapes of a series. For having this information different in each
11645 series created through a single script used on a regular basis, just
11646 manage to get some date string as part of the label. For example:
11647
11648 @smallexample
11649 @group
11650 $ @kbd{tar cfMV /dev/tape "Daily backup for `date +%Y-%m-%d`"}
11651 $ @kbd{tar --create --file=/dev/tape --multi-volume \
11652 --label="Daily backup for `date +%Y-%m-%d`"}
11653 @end group
11654 @end smallexample
11655
11656 Some more notes about volume labels:
11657
11658 @itemize @bullet
11659 @item Each label has its own date and time, which corresponds
11660 to the time when @GNUTAR{} initially attempted to write it,
11661 often soon after the operator launches @command{tar} or types the
11662 carriage return telling that the next tape is ready.
11663
11664 @item Comparing date labels to get an idea of tape throughput is
11665 unreliable. It gives correct results only if the delays for rewinding
11666 tapes and the operator switching them were negligible, which is
11667 usually not the case.
11668 @end itemize
11669
11670 @node verify
11671 @section Verifying Data as It is Stored
11672 @cindex Verifying a write operation
11673 @cindex Double-checking a write operation
11674
11675 @table @option
11676 @item -W
11677 @itemx --verify
11678 @opindex verify, short description
11679 Attempt to verify the archive after writing.
11680 @end table
11681
11682 This option causes @command{tar} to verify the archive after writing it.
11683 Each volume is checked after it is written, and any discrepancies
11684 are recorded on the standard error output.
11685
11686 Verification requires that the archive be on a back-space-able medium.
11687 This means pipes, some cartridge tape drives, and some other devices
11688 cannot be verified.
11689
11690 You can insure the accuracy of an archive by comparing files in the
11691 system with archive members. @command{tar} can compare an archive to the
11692 file system as the archive is being written, to verify a write
11693 operation, or can compare a previously written archive, to insure that
11694 it is up to date.
11695
11696 @xopindex{verify, using with @option{--create}}
11697 @xopindex{create, using with @option{--verify}}
11698 To check for discrepancies in an archive immediately after it is
11699 written, use the @option{--verify} (@option{-W}) option in conjunction with
11700 the @option{--create} operation. When this option is
11701 specified, @command{tar} checks archive members against their counterparts
11702 in the file system, and reports discrepancies on the standard error.
11703
11704 To verify an archive, you must be able to read it from before the end
11705 of the last written entry. This option is useful for detecting data
11706 errors on some tapes. Archives written to pipes, some cartridge tape
11707 drives, and some other devices cannot be verified.
11708
11709 One can explicitly compare an already made archive with the file
11710 system by using the @option{--compare} (@option{--diff}, @option{-d})
11711 option, instead of using the more automatic @option{--verify} option.
11712 @xref{compare}.
11713
11714 Note that these two options have a slightly different intent. The
11715 @option{--compare} option checks how identical are the logical contents of some
11716 archive with what is on your disks, while the @option{--verify} option is
11717 really for checking if the physical contents agree and if the recording
11718 media itself is of dependable quality. So, for the @option{--verify}
11719 operation, @command{tar} tries to defeat all in-memory cache pertaining to
11720 the archive, while it lets the speed optimization undisturbed for the
11721 @option{--compare} option. If you nevertheless use @option{--compare} for
11722 media verification, you may have to defeat the in-memory cache yourself,
11723 maybe by opening and reclosing the door latch of your recording unit,
11724 forcing some doubt in your operating system about the fact this is really
11725 the same volume as the one just written or read.
11726
11727 The @option{--verify} option would not be necessary if drivers were indeed
11728 able to detect dependably all write failures. This sometimes require many
11729 magnetic heads, some able to read after the writes occurred. One would
11730 not say that drivers unable to detect all cases are necessarily flawed,
11731 as long as programming is concerned.
11732
11733 The @option{--verify} (@option{-W}) option will not work in
11734 conjunction with the @option{--multi-volume} (@option{-M}) option or
11735 the @option{--append} (@option{-r}), @option{--update} (@option{-u})
11736 and @option{--delete} operations. @xref{Operations}, for more
11737 information on these operations.
11738
11739 Also, since @command{tar} normally strips leading @samp{/} from file
11740 names (@pxref{absolute}), a command like @samp{tar --verify -cf
11741 /tmp/foo.tar /etc} will work as desired only if the working directory is
11742 @file{/}, as @command{tar} uses the archive's relative member names
11743 (e.g., @file{etc/motd}) when verifying the archive.
11744
11745 @node Write Protection
11746 @section Write Protection
11747
11748 Almost all tapes and diskettes, and in a few rare cases, even disks can
11749 be @dfn{write protected}, to protect data on them from being changed.
11750 Once an archive is written, you should write protect the media to prevent
11751 the archive from being accidentally overwritten or deleted. (This will
11752 protect the archive from being changed with a tape or floppy drive---it
11753 will not protect it from magnet fields or other physical hazards.)
11754
11755 The write protection device itself is usually an integral part of the
11756 physical media, and can be a two position (write enabled/write
11757 disabled) switch, a notch which can be popped out or covered, a ring
11758 which can be removed from the center of a tape reel, or some other
11759 changeable feature.
11760
11761 @node Reliability and security
11762 @chapter Reliability and Security
11763
11764 The @command{tar} command reads and writes files as any other
11765 application does, and is subject to the usual caveats about
11766 reliability and security. This section contains some commonsense
11767 advice on the topic.
11768
11769 @menu
11770 * Reliability::
11771 * Security::
11772 @end menu
11773
11774 @node Reliability
11775 @section Reliability
11776
11777 Ideally, when @command{tar} is creating an archive, it reads from a
11778 file system that is not being modified, and encounters no errors or
11779 inconsistencies while reading and writing. If this is the case, the
11780 archive should faithfully reflect what was read. Similarly, when
11781 extracting from an archive, ideally @command{tar} ideally encounters
11782 no errors and the extracted files faithfully reflect what was in the
11783 archive.
11784
11785 However, when reading or writing real-world file systems, several
11786 things can go wrong; these include permissions problems, corruption of
11787 data, and race conditions.
11788
11789 @menu
11790 * Permissions problems::
11791 * Data corruption and repair::
11792 * Race conditions::
11793 @end menu
11794
11795 @node Permissions problems
11796 @subsection Permissions Problems
11797
11798 If @command{tar} encounters errors while reading or writing files, it
11799 normally reports an error and exits with nonzero status. The work it
11800 does may therefore be incomplete. For example, when creating an
11801 archive, if @command{tar} cannot read a file then it cannot copy the
11802 file into the archive.
11803
11804 @node Data corruption and repair
11805 @subsection Data Corruption and Repair
11806
11807 If an archive becomes corrupted by an I/O error, this may corrupt the
11808 data in an extracted file. Worse, it may corrupt the file's metadata,
11809 which may cause later parts of the archive to become misinterpreted.
11810 An tar-format archive contains a checksum that most likely will detect
11811 errors in the metadata, but it will not detect errors in the data.
11812
11813 If data corruption is a concern, you can compute and check your own
11814 checksums of an archive by using other programs, such as
11815 @command{cksum}.
11816
11817 When attempting to recover from a read error or data corruption in an
11818 archive, you may need to skip past the questionable data and read the
11819 rest of the archive. This requires some expertise in the archive
11820 format and in other software tools.
11821
11822 @node Race conditions
11823 @subsection Race conditions
11824
11825 If some other process is modifying the file system while @command{tar}
11826 is reading or writing files, the result may well be inconsistent due
11827 to race conditions. For example, if another process creates some
11828 files in a directory while @command{tar} is creating an archive
11829 containing the directory's files, @command{tar} may see some of the
11830 files but not others, or it may see a file that is in the process of
11831 being created. The resulting archive may not be a snapshot of the
11832 file system at any point in time. If an application such as a
11833 database system depends on an accurate snapshot, restoring from the
11834 @command{tar} archive of a live file system may therefore break that
11835 consistency and may break the application. The simplest way to avoid
11836 the consistency issues is to avoid making other changes to the file
11837 system while tar is reading it or writing it.
11838
11839 When creating an archive, several options are available to avoid race
11840 conditions. Some hosts have a way of snapshotting a file system, or
11841 of temporarily suspending all changes to a file system, by (say)
11842 suspending the only virtual machine that can modify a file system; if
11843 you use these facilities and have @command{tar -c} read from a
11844 snapshot when creating an archive, you can avoid inconsistency
11845 problems. More drastically, before starting @command{tar} you could
11846 suspend or shut down all processes other than @command{tar} that have
11847 access to the file system, or you could unmount the file system and
11848 then mount it read-only.
11849
11850 When extracting from an archive, one approach to avoid race conditions
11851 is to create a directory that no other process can write to, and
11852 extract into that.
11853
11854 @node Security
11855 @section Security
11856
11857 In some cases @command{tar} may be used in an adversarial situation,
11858 where an untrusted user is attempting to gain information about or
11859 modify otherwise-inaccessible files. Dealing with untrusted data
11860 (that is, data generated by an untrusted user) typically requires
11861 extra care, because even the smallest mistake in the use of
11862 @command{tar} is more likely to be exploited by an adversary than by a
11863 race condition.
11864
11865 @menu
11866 * Privacy::
11867 * Integrity::
11868 * Live untrusted data::
11869 * Security rules of thumb::
11870 @end menu
11871
11872 @node Privacy
11873 @subsection Privacy
11874
11875 Standard privacy concerns apply when using @command{tar}. For
11876 example, suppose you are archiving your home directory into a file
11877 @file{/archive/myhome.tar}. Any secret information in your home
11878 directory, such as your SSH secret keys, are copied faithfully into
11879 the archive. Therefore, if your home directory contains any file that
11880 should not be read by some other user, the archive itself should be
11881 not be readable by that user. And even if the archive's data are
11882 inaccessible to untrusted users, its metadata (such as size or
11883 last-modified date) may reveal some information about your home
11884 directory; if the metadata are intended to be private, the archive's
11885 parent directory should also be inaccessible to untrusted users.
11886
11887 One precaution is to create @file{/archive} so that it is not
11888 accessible to any user, unless that user also has permission to access
11889 all the files in your home directory.
11890
11891 Similarly, when extracting from an archive, take care that the
11892 permissions of the extracted files are not more generous than what you
11893 want. Even if the archive itself is readable only to you, files
11894 extracted from it have their own permissions that may differ.
11895
11896 @node Integrity
11897 @subsection Integrity
11898
11899 When creating archives, take care that they are not writable by a
11900 untrusted user; otherwise, that user could modify the archive, and
11901 when you later extract from the archive you will get incorrect data.
11902
11903 When @command{tar} extracts from an archive, by default it writes into
11904 files relative to the working directory. If the archive was generated
11905 by an untrusted user, that user therefore can write into any file
11906 under the working directory. If the working directory contains a
11907 symbolic link to another directory, the untrusted user can also write
11908 into any file under the referenced directory. When extracting from an
11909 untrusted archive, it is therefore good practice to create an empty
11910 directory and run @command{tar} in that directory.
11911
11912 When extracting from two or more untrusted archives, each one should
11913 be extracted independently, into different empty directories.
11914 Otherwise, the first archive could create a symbolic link into an area
11915 outside the working directory, and the second one could follow the
11916 link and overwrite data that is not under the working directory. For
11917 example, when restoring from a series of incremental dumps, the
11918 archives should have been created by a trusted process, as otherwise
11919 the incremental restores might alter data outside the working
11920 directory.
11921
11922 If you use the @option{--absolute-names} (@option{-P}) option when
11923 extracting, @command{tar} respects any file names in the archive, even
11924 file names that begin with @file{/} or contain @file{..}. As this
11925 lets the archive overwrite any file in your system that you can write,
11926 the @option{--absolute-names} (@option{-P}) option should be used only
11927 for trusted archives.
11928
11929 Conversely, with the @option{--keep-old-files} (@option{-k}) option,
11930 @command{tar} refuses to replace existing files when extracting; and
11931 with the @option{--no-overwrite-dir} option, @command{tar} refuses to
11932 replace the permissions or ownership of already-existing directories.
11933 These options may help when extracting from untrusted archives.
11934
11935 @node Live untrusted data
11936 @subsection Dealing with Live Untrusted Data
11937
11938 Extra care is required when creating from or extracting into a file
11939 system that is accessible to untrusted users. For example, superusers
11940 who invoke @command{tar} must be wary about its actions being hijacked
11941 by an adversary who is reading or writing the file system at the same
11942 time that @command{tar} is operating.
11943
11944 When creating an archive from a live file system, @command{tar} is
11945 vulnerable to denial-of-service attacks. For example, an adversarial
11946 user could create the illusion of an indefinitely-deep directory
11947 hierarchy @file{d/e/f/g/...} by creating directories one step ahead of
11948 @command{tar}, or the illusion of an indefinitely-long file by
11949 creating a sparse file but arranging for blocks to be allocated just
11950 before @command{tar} reads them. There is no easy way for
11951 @command{tar} to distinguish these scenarios from legitimate uses, so
11952 you may need to monitor @command{tar}, just as you'd need to monitor
11953 any other system service, to detect such attacks.
11954
11955 While a superuser is extracting from an archive into a live file
11956 system, an untrusted user might replace a directory with a symbolic
11957 link, in hopes that @command{tar} will follow the symbolic link and
11958 extract data into files that the untrusted user does not have access
11959 to. Even if the archive was generated by the superuser, it may
11960 contain a file such as @file{d/etc/passwd} that the untrusted user
11961 earlier created in order to break in; if the untrusted user replaces
11962 the directory @file{d/etc} with a symbolic link to @file{/etc} while
11963 @command{tar} is running, @command{tar} will overwrite
11964 @file{/etc/passwd}. This attack can be prevented by extracting into a
11965 directory that is inaccessible to untrusted users.
11966
11967 Similar attacks via symbolic links are also possible when creating an
11968 archive, if the untrusted user can modify an ancestor of a top-level
11969 argument of @command{tar}. For example, an untrusted user that can
11970 modify @file{/home/eve} can hijack a running instance of @samp{tar -cf
11971 - /home/eve/Documents/yesterday} by replacing
11972 @file{/home/eve/Documents} with a symbolic link to some other
11973 location. Attacks like these can be prevented by making sure that
11974 untrusted users cannot modify any files that are top-level arguments
11975 to @command{tar}, or any ancestor directories of these files.
11976
11977 @node Security rules of thumb
11978 @subsection Security Rules of Thumb
11979
11980 This section briefly summarizes rules of thumb for avoiding security
11981 pitfalls.
11982
11983 @itemize @bullet
11984
11985 @item
11986 Protect archives at least as much as you protect any of the files
11987 being archived.
11988
11989 @item
11990 Extract from an untrusted archive only into an otherwise-empty
11991 directory. This directory and its parent should be accessible only to
11992 trusted users. For example:
11993
11994 @example
11995 @group
11996 $ @kbd{chmod go-rwx .}
11997 $ @kbd{mkdir -m go-rwx dir}
11998 $ @kbd{cd dir}
11999 $ @kbd{tar -xvf /archives/got-it-off-the-net.tar.gz}
12000 @end group
12001 @end example
12002
12003 As a corollary, do not do an incremental restore from an untrusted archive.
12004
12005 @item
12006 Do not let untrusted users access files extracted from untrusted
12007 archives without checking first for problems such as setuid programs.
12008
12009 @item
12010 Do not let untrusted users modify directories that are ancestors of
12011 top-level arguments of @command{tar}. For example, while you are
12012 executing @samp{tar -cf /archive/u-home.tar /u/home}, do not let an
12013 untrusted user modify @file{/}, @file{/archive}, or @file{/u}.
12014
12015 @item
12016 Pay attention to the diagnostics and exit status of @command{tar}.
12017
12018 @item
12019 When archiving live file systems, monitor running instances of
12020 @command{tar} to detect denial-of-service attacks.
12021
12022 @item
12023 Avoid unusual options such as @option{--absolute-names} (@option{-P}),
12024 @option{--dereference} (@option{-h}), @option{--overwrite},
12025 @option{--recursive-unlink}, and @option{--remove-files} unless you
12026 understand their security implications.
12027
12028 @end itemize
12029
12030 @node Changes
12031 @appendix Changes
12032
12033 This appendix lists some important user-visible changes between
12034 version @GNUTAR{} @value{VERSION} and previous versions. An up-to-date
12035 version of this document is available at
12036 @uref{http://www.gnu.org/@/software/@/tar/manual/changes.html,the
12037 @GNUTAR{} documentation page}.
12038
12039 @table @asis
12040 @item Use of globbing patterns when listing and extracting.
12041
12042 Previous versions of GNU tar assumed shell-style globbing when
12043 extracting from or listing an archive. For example:
12044
12045 @smallexample
12046 $ @kbd{tar xf foo.tar '*.c'}
12047 @end smallexample
12048
12049 would extract all files whose names end in @samp{.c}. This behavior
12050 was not documented and was incompatible with traditional tar
12051 implementations. Therefore, starting from version 1.15.91, GNU tar
12052 no longer uses globbing by default. For example, the above invocation
12053 is now interpreted as a request to extract from the archive the file
12054 named @file{*.c}.
12055
12056 To facilitate transition to the new behavior for those users who got
12057 used to the previous incorrect one, @command{tar} will print a warning
12058 if it finds out that a requested member was not found in the archive
12059 and its name looks like a globbing pattern. For example:
12060
12061 @smallexample
12062 $ @kbd{tar xf foo.tar '*.c'}
12063 tar: Pattern matching characters used in file names. Please,
12064 tar: use --wildcards to enable pattern matching, or --no-wildcards to
12065 tar: suppress this warning.
12066 tar: *.c: Not found in archive
12067 tar: Error exit delayed from previous errors
12068 @end smallexample
12069
12070 To treat member names as globbing patterns, use the @option{--wildcards} option.
12071 If you want to tar to mimic the behavior of versions prior to 1.15.91,
12072 add this option to your @env{TAR_OPTIONS} variable.
12073
12074 @xref{wildcards}, for the detailed discussion of the use of globbing
12075 patterns by @GNUTAR{}.
12076
12077 @item Use of short option @option{-o}.
12078
12079 Earlier versions of @GNUTAR{} understood @option{-o} command line
12080 option as a synonym for @option{--old-archive}.
12081
12082 @GNUTAR{} starting from version 1.13.90 understands this option as
12083 a synonym for @option{--no-same-owner}. This is compatible with
12084 UNIX98 @command{tar} implementations.
12085
12086 However, to facilitate transition, @option{-o} option retains its
12087 old semantics when it is used with one of archive-creation commands.
12088 Users are encouraged to use @option{--format=oldgnu} instead.
12089
12090 It is especially important, since versions of @acronym{GNU} Automake
12091 up to and including 1.8.4 invoke tar with this option to produce
12092 distribution tarballs. @xref{Formats,v7}, for the detailed discussion
12093 of this issue and its implications.
12094
12095 @xref{Options, tar-formats, Changing Automake's Behavior,
12096 automake, GNU Automake}, for a description on how to use various
12097 archive formats with @command{automake}.
12098
12099 Future versions of @GNUTAR{} will understand @option{-o} only as a
12100 synonym for @option{--no-same-owner}.
12101
12102 @item Use of short option @option{-l}
12103
12104 Earlier versions of @GNUTAR{} understood @option{-l} option as a
12105 synonym for @option{--one-file-system}. Since such usage contradicted
12106 to UNIX98 specification and harmed compatibility with other
12107 implementations, it was declared deprecated in version 1.14. However,
12108 to facilitate transition to its new semantics, it was supported by
12109 versions 1.15 and 1.15.90. The present use of @option{-l} as a short
12110 variant of @option{--check-links} was introduced in version 1.15.91.
12111
12112 @item Use of options @option{--portability} and @option{--old-archive}
12113
12114 These options are deprecated. Please use @option{--format=v7} instead.
12115
12116 @item Use of option @option{--posix}
12117
12118 This option is deprecated. Please use @option{--format=posix} instead.
12119 @end table
12120
12121 @node Configuring Help Summary
12122 @appendix Configuring Help Summary
12123
12124 Running @kbd{tar --help} displays the short @command{tar} option
12125 summary (@pxref{help}). This summary is organized by @dfn{groups} of
12126 semantically close options. The options within each group are printed
12127 in the following order: a short option, eventually followed by a list
12128 of corresponding long option names, followed by a short description of
12129 the option. For example, here is an excerpt from the actual @kbd{tar
12130 --help} output:
12131
12132 @verbatim
12133 Main operation mode:
12134
12135 -A, --catenate, --concatenate append tar files to an archive
12136 -c, --create create a new archive
12137 -d, --diff, --compare find differences between archive and
12138 file system
12139 --delete delete from the archive
12140 @end verbatim
12141
12142 @vrindex ARGP_HELP_FMT, environment variable
12143 The exact visual representation of the help output is configurable via
12144 @env{ARGP_HELP_FMT} environment variable. The value of this variable
12145 is a comma-separated list of @dfn{format variable} assignments. There
12146 are two kinds of format variables. An @dfn{offset variable} keeps the
12147 offset of some part of help output text from the leftmost column on
12148 the screen. A @dfn{boolean} variable is a flag that toggles some
12149 output feature on or off. Depending on the type of the corresponding
12150 variable, there are two kinds of assignments:
12151
12152 @table @asis
12153 @item Offset assignment
12154
12155 The assignment to an offset variable has the following syntax:
12156
12157 @smallexample
12158 @var{variable}=@var{value}
12159 @end smallexample
12160
12161 @noindent
12162 where @var{variable} is the variable name, and @var{value} is a
12163 numeric value to be assigned to the variable.
12164
12165 @item Boolean assignment
12166
12167 To assign @code{true} value to a variable, simply put this variable name. To
12168 assign @code{false} value, prefix the variable name with @samp{no-}. For
12169 example:
12170
12171 @smallexample
12172 @group
12173 # Assign @code{true} value:
12174 dup-args
12175 # Assign @code{false} value:
12176 no-dup-args
12177 @end group
12178 @end smallexample
12179 @end table
12180
12181 Following variables are declared:
12182
12183 @deftypevr {Help Output} boolean dup-args
12184 If true, arguments for an option are shown with both short and long
12185 options, even when a given option has both forms, for example:
12186
12187 @smallexample
12188 -f ARCHIVE, --file=ARCHIVE use archive file or device ARCHIVE
12189 @end smallexample
12190
12191 If false, then if an option has both short and long forms, the
12192 argument is only shown with the long one, for example:
12193
12194 @smallexample
12195 -f, --file=ARCHIVE use archive file or device ARCHIVE
12196 @end smallexample
12197
12198 @noindent
12199 and a message indicating that the argument is applicable to both
12200 forms is printed below the options. This message can be disabled
12201 using @code{dup-args-note} (see below).
12202
12203 The default is false.
12204 @end deftypevr
12205
12206 @deftypevr {Help Output} boolean dup-args-note
12207 If this variable is true, which is the default, the following notice
12208 is displayed at the end of the help output:
12209
12210 @quotation
12211 Mandatory or optional arguments to long options are also mandatory or
12212 optional for any corresponding short options.
12213 @end quotation
12214
12215 Setting @code{no-dup-args-note} inhibits this message. Normally, only one of
12216 variables @code{dup-args} or @code{dup-args-note} should be set.
12217 @end deftypevr
12218
12219 @deftypevr {Help Output} offset short-opt-col
12220 Column in which short options start. Default is 2.
12221
12222 @smallexample
12223 @group
12224 $ @kbd{tar --help|grep ARCHIVE}
12225 -f, --file=ARCHIVE use archive file or device ARCHIVE
12226 $ @kbd{ARGP_HELP_FMT=short-opt-col=6 tar --help|grep ARCHIVE}
12227 -f, --file=ARCHIVE use archive file or device ARCHIVE
12228 @end group
12229 @end smallexample
12230 @end deftypevr
12231
12232 @deftypevr {Help Output} offset long-opt-col
12233 Column in which long options start. Default is 6. For example:
12234
12235 @smallexample
12236 @group
12237 $ @kbd{tar --help|grep ARCHIVE}
12238 -f, --file=ARCHIVE use archive file or device ARCHIVE
12239 $ @kbd{ARGP_HELP_FMT=long-opt-col=16 tar --help|grep ARCHIVE}
12240 -f, --file=ARCHIVE use archive file or device ARCHIVE
12241 @end group
12242 @end smallexample
12243 @end deftypevr
12244
12245 @deftypevr {Help Output} offset doc-opt-col
12246 Column in which @dfn{doc options} start. A doc option isn't actually
12247 an option, but rather an arbitrary piece of documentation that is
12248 displayed in much the same manner as the options. For example, in
12249 the description of @option{--format} option:
12250
12251 @smallexample
12252 @group
12253 -H, --format=FORMAT create archive of the given format.
12254
12255 FORMAT is one of the following:
12256
12257 gnu GNU tar 1.13.x format
12258 oldgnu GNU format as per tar <= 1.12
12259 pax POSIX 1003.1-2001 (pax) format
12260 posix same as pax
12261 ustar POSIX 1003.1-1988 (ustar) format
12262 v7 old V7 tar format
12263 @end group
12264 @end smallexample
12265
12266 @noindent
12267 the format names are doc options. Thus, if you set
12268 @kbd{ARGP_HELP_FMT=doc-opt-col=6} the above part of the help output
12269 will look as follows:
12270
12271 @smallexample
12272 @group
12273 -H, --format=FORMAT create archive of the given format.
12274
12275 FORMAT is one of the following:
12276
12277 gnu GNU tar 1.13.x format
12278 oldgnu GNU format as per tar <= 1.12
12279 pax POSIX 1003.1-2001 (pax) format
12280 posix same as pax
12281 ustar POSIX 1003.1-1988 (ustar) format
12282 v7 old V7 tar format
12283 @end group
12284 @end smallexample
12285 @end deftypevr
12286
12287 @deftypevr {Help Output} offset opt-doc-col
12288 Column in which option description starts. Default is 29.
12289
12290 @smallexample
12291 @group
12292 $ @kbd{tar --help|grep ARCHIVE}
12293 -f, --file=ARCHIVE use archive file or device ARCHIVE
12294 $ @kbd{ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE}
12295 -f, --file=ARCHIVE use archive file or device ARCHIVE
12296 $ @kbd{ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE}
12297 -f, --file=ARCHIVE
12298 use archive file or device ARCHIVE
12299 @end group
12300 @end smallexample
12301
12302 @noindent
12303 Notice, that the description starts on a separate line if
12304 @code{opt-doc-col} value is too small.
12305 @end deftypevr
12306
12307 @deftypevr {Help Output} offset header-col
12308 Column in which @dfn{group headers} are printed. A group header is a
12309 descriptive text preceding an option group. For example, in the
12310 following text:
12311
12312 @verbatim
12313 Main operation mode:
12314
12315 -A, --catenate, --concatenate append tar files to
12316 an archive
12317 -c, --create create a new archive
12318 @end verbatim
12319 @noindent
12320 @samp{Main operation mode:} is the group header.
12321
12322 The default value is 1.
12323 @end deftypevr
12324
12325 @deftypevr {Help Output} offset usage-indent
12326 Indentation of wrapped usage lines. Affects @option{--usage}
12327 output. Default is 12.
12328 @end deftypevr
12329
12330 @deftypevr {Help Output} offset rmargin
12331 Right margin of the text output. Used for wrapping.
12332 @end deftypevr
12333
12334 @node Fixing Snapshot Files
12335 @appendix Fixing Snapshot Files
12336 @include tar-snapshot-edit.texi
12337
12338 @node Tar Internals
12339 @appendix Tar Internals
12340 @include intern.texi
12341
12342 @node Genfile
12343 @appendix Genfile
12344 @include genfile.texi
12345
12346 @node Free Software Needs Free Documentation
12347 @appendix Free Software Needs Free Documentation
12348 @include freemanuals.texi
12349
12350 @node GNU Free Documentation License
12351 @appendix GNU Free Documentation License
12352
12353 @include fdl.texi
12354
12355 @node Index of Command Line Options
12356 @appendix Index of Command Line Options
12357
12358 This appendix contains an index of all @GNUTAR{} long command line
12359 options. The options are listed without the preceding double-dash.
12360 For a cross-reference of short command line options, see
12361 @ref{Short Option Summary}.
12362
12363 @printindex op
12364
12365 @node Index
12366 @appendix Index
12367
12368 @printindex cp
12369
12370 @summarycontents
12371 @contents
12372 @bye
12373
12374 @c Local variables:
12375 @c texinfo-column-for-description: 32
12376 @c End:
This page took 0.563717 seconds and 5 git commands to generate.