b420f633da419dc10329ac4d0885600956b5463a
[debian/tar] / doc / tar.info-1
1 This is tar.info, produced by makeinfo version 4.13 from tar.texi.
2
3 This manual is for GNU `tar' (version 1.25, 5 November 2010), which
4 creates and extracts files from archives.
5
6    Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003,
7 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
8
9      Permission is granted to copy, distribute and/or modify this
10      document under the terms of the GNU Free Documentation License,
11      Version 1.3 or any later version published by the Free Software
12      Foundation; with no Invariant Sections, with the Front-Cover Texts
13      being "A GNU Manual", and with the Back-Cover Texts as in (a)
14      below.  A copy of the license is included in the section entitled
15      "GNU Free Documentation License".
16
17      (a) The FSF's Back-Cover Text is: "You have the freedom to copy
18      and modify this GNU manual.  Buying copies from the FSF supports
19      it in developing GNU and promoting software freedom."
20
21 INFO-DIR-SECTION Archiving
22 START-INFO-DIR-ENTRY
23 * Tar: (tar).                   Making tape (or disk) archives.
24 END-INFO-DIR-ENTRY
25
26 INFO-DIR-SECTION Individual utilities
27 START-INFO-DIR-ENTRY
28 * tar: (tar)tar invocation.                     Invoking GNU `tar'.
29 END-INFO-DIR-ENTRY
30
31 \1f
32 File: tar.info,  Node: Top,  Next: Introduction,  Up: (dir)
33
34 GNU tar: an archiver tool
35 *************************
36
37 This manual is for GNU `tar' (version 1.25, 5 November 2010), which
38 creates and extracts files from archives.
39
40    Copyright (C) 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2003,
41 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
42
43      Permission is granted to copy, distribute and/or modify this
44      document under the terms of the GNU Free Documentation License,
45      Version 1.3 or any later version published by the Free Software
46      Foundation; with no Invariant Sections, with the Front-Cover Texts
47      being "A GNU Manual", and with the Back-Cover Texts as in (a)
48      below.  A copy of the license is included in the section entitled
49      "GNU Free Documentation License".
50
51      (a) The FSF's Back-Cover Text is: "You have the freedom to copy
52      and modify this GNU manual.  Buying copies from the FSF supports
53      it in developing GNU and promoting software freedom."
54
55    The first part of this master menu lists the major nodes in this Info
56 document.  The rest of the menu lists all the lower level nodes.
57
58 * Menu:
59
60 * Introduction::
61 * Tutorial::
62 * tar invocation::
63 * operations::
64 * Backups::
65 * Choosing::
66 * Date input formats::
67 * Formats::
68 * Media::
69 * Reliability and security::
70
71 Appendices
72
73 * Changes::
74 * Configuring Help Summary::
75 * Fixing Snapshot Files::
76 * Tar Internals::
77 * Genfile::
78 * Free Software Needs Free Documentation::
79 * GNU Free Documentation License::
80 * Index of Command Line Options::
81 * Index::
82
83  --- The Detailed Node Listing ---
84
85 Introduction
86
87 * Book Contents::               What this Book Contains
88 * Definitions::                 Some Definitions
89 * What tar Does::               What `tar' Does
90 * Naming tar Archives::         How `tar' Archives are Named
91 * Authors::                     GNU `tar' Authors
92 * Reports::                     Reporting bugs or suggestions
93
94 Tutorial Introduction to `tar'
95
96 * assumptions::
97 * stylistic conventions::
98 * basic tar options::           Basic `tar' Operations and Options
99 * frequent operations::
100 * Two Frequent Options::
101 * create::                      How to Create Archives
102 * list::                        How to List Archives
103 * extract::                     How to Extract Members from an Archive
104 * going further::
105
106 Two Frequently Used Options
107
108 * file tutorial::
109 * verbose tutorial::
110 * help tutorial::
111
112 How to Create Archives
113
114 * prepare for examples::
115 * Creating the archive::
116 * create verbose::
117 * short create::
118 * create dir::
119
120 How to List Archives
121
122 * list dir::
123
124 How to Extract Members from an Archive
125
126 * extracting archives::
127 * extracting files::
128 * extract dir::
129 * extracting untrusted archives::
130 * failing commands::
131
132 Invoking GNU `tar'
133
134 * Synopsis::
135 * using tar options::
136 * Styles::
137 * All Options::
138 * help::
139 * defaults::
140 * verbose::
141 * checkpoints::
142 * warnings::
143 * interactive::
144
145 The Three Option Styles
146
147 * Long Options::                Long Option Style
148 * Short Options::               Short Option Style
149 * Old Options::                 Old Option Style
150 * Mixing::                      Mixing Option Styles
151
152 All `tar' Options
153
154 * Operation Summary::
155 * Option Summary::
156 * Short Option Summary::
157
158 GNU `tar' Operations
159
160 * Basic tar::
161 * Advanced tar::
162 * create options::
163 * extract options::
164 * backup::
165 * Applications::
166 * looking ahead::
167
168 Advanced GNU `tar' Operations
169
170 * Operations::
171 * append::
172 * update::
173 * concatenate::
174 * delete::
175 * compare::
176
177 How to Add Files to Existing Archives: `--append'
178
179 * appending files::             Appending Files to an Archive
180 * multiple::
181
182 Updating an Archive
183
184 * how to update::
185
186 Options Used by `--create'
187
188 * override::                  Overriding File Metadata.
189 * Ignore Failed Read::
190
191 Options Used by `--extract'
192
193 * Reading::                     Options to Help Read Archives
194 * Writing::                     Changing How `tar' Writes Files
195 * Scarce::                      Coping with Scarce Resources
196
197 Options to Help Read Archives
198
199 * read full records::
200 * Ignore Zeros::
201
202 Changing How `tar' Writes Files
203
204 * Dealing with Old Files::
205 * Overwrite Old Files::
206 * Keep Old Files::
207 * Keep Newer Files::
208 * Unlink First::
209 * Recursive Unlink::
210 * Data Modification Times::
211 * Setting Access Permissions::
212 * Directory Modification Times and Permissions::
213 * Writing to Standard Output::
214 * Writing to an External Program::
215 * remove files::
216
217 Coping with Scarce Resources
218
219 * Starting File::
220 * Same Order::
221
222 Performing Backups and Restoring Files
223
224 * Full Dumps::                  Using `tar' to Perform Full Dumps
225 * Incremental Dumps::           Using `tar' to Perform Incremental Dumps
226 * Backup Levels::               Levels of Backups
227 * Backup Parameters::           Setting Parameters for Backups and Restoration
228 * Scripted Backups::            Using the Backup Scripts
229 * Scripted Restoration::        Using the Restore Script
230
231 Setting Parameters for Backups and Restoration
232
233 * General-Purpose Variables::
234 * Magnetic Tape Control::
235 * User Hooks::
236 * backup-specs example::        An Example Text of `Backup-specs'
237
238 Choosing Files and Names for `tar'
239
240 * file::                        Choosing the Archive's Name
241 * Selecting Archive Members::
242 * files::                       Reading Names from a File
243 * exclude::                     Excluding Some Files
244 * wildcards::                   Wildcards Patterns and Matching
245 * quoting styles::              Ways of Quoting Special Characters in Names
246 * transform::                   Modifying File and Member Names
247 * after::                       Operating Only on New Files
248 * recurse::                     Descending into Directories
249 * one::                         Crossing File System Boundaries
250
251 Reading Names from a File
252
253 * nul::
254
255 Excluding Some Files
256
257 * problems with exclude::
258
259 Wildcards Patterns and Matching
260
261 * controlling pattern-matching::
262
263 Crossing File System Boundaries
264
265 * directory::                   Changing Directory
266 * absolute::                    Absolute File Names
267
268 Date input formats
269
270 * General date syntax::            Common rules.
271 * Calendar date items::            19 Dec 1994.
272 * Time of day items::              9:20pm.
273 * Time zone items::                EST, PDT, GMT.
274 * Day of week items::              Monday and others.
275 * Relative items in date strings:: next tuesday, 2 years ago.
276 * Pure numbers in date strings::   19931219, 1440.
277 * Seconds since the Epoch::        @1078100502.
278 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
279 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
280
281 Controlling the Archive Format
282
283 * Compression::                 Using Less Space through Compression
284 * Attributes::                  Handling File Attributes
285 * Portability::                 Making `tar' Archives More Portable
286 * cpio::                        Comparison of `tar' and `cpio'
287
288 Using Less Space through Compression
289
290 * gzip::                        Creating and Reading Compressed Archives
291 * sparse::                      Archiving Sparse Files
292
293 Creating and Reading Compressed Archives
294
295 * lbzip2::  Using lbzip2 with GNU `tar'.
296
297 Making `tar' Archives More Portable
298
299 * Portable Names::              Portable Names
300 * dereference::                 Symbolic Links
301 * hard links::                  Hard Links
302 * old::                         Old V7 Archives
303 * ustar::                       Ustar Archives
304 * gnu::                         GNU and old GNU format archives.
305 * posix::                       POSIX archives
306 * Checksumming::                Checksumming Problems
307 * Large or Negative Values::    Large files, negative time stamps, etc.
308 * Other Tars::                  How to Extract GNU-Specific Data Using
309                                 Other `tar' Implementations
310
311 GNU `tar' and POSIX `tar'
312
313 * PAX keywords:: Controlling Extended Header Keywords.
314
315 How to Extract GNU-Specific Data Using Other `tar' Implementations
316
317 * Split Recovery::       Members Split Between Volumes
318 * Sparse Recovery::      Sparse Members
319
320 Tapes and Other Archive Media
321
322 * Device::                      Device selection and switching
323 * Remote Tape Server::
324 * Common Problems and Solutions::
325 * Blocking::                    Blocking
326 * Many::                        Many archives on one tape
327 * Using Multiple Tapes::        Using Multiple Tapes
328 * label::                       Including a Label in the Archive
329 * verify::
330 * Write Protection::
331
332 Blocking
333
334 * Format Variations::           Format Variations
335 * Blocking Factor::             The Blocking Factor of an Archive
336
337 Many Archives on One Tape
338
339 * Tape Positioning::            Tape Positions and Tape Marks
340 * mt::                          The `mt' Utility
341
342 Using Multiple Tapes
343
344 * Multi-Volume Archives::       Archives Longer than One Tape or Disk
345 * Tape Files::                  Tape Files
346 * Tarcat::                      Concatenate Volumes into a Single Archive
347
348
349 Tar Internals
350
351 * Standard::           Basic Tar Format
352 * Extensions::         GNU Extensions to the Archive Format
353 * Sparse Formats::     Storing Sparse Files
354 * Snapshot Files::
355 * Dumpdir::
356
357 Storing Sparse Files
358
359 * Old GNU Format::
360 * PAX 0::                PAX Format, Versions 0.0 and 0.1
361 * PAX 1::                PAX Format, Version 1.0
362
363 Genfile
364
365 * Generate Mode::     File Generation Mode.
366 * Status Mode::       File Status Mode.
367 * Exec Mode::         Synchronous Execution mode.
368
369 Copying This Manual
370
371 * GNU Free Documentation License::  License for copying this manual
372
373 \1f
374 File: tar.info,  Node: Introduction,  Next: Tutorial,  Prev: Top,  Up: Top
375
376 1 Introduction
377 **************
378
379 GNU `tar' creates and manipulates "archives" which are actually
380 collections of many other files; the program provides users with an
381 organized and systematic method for controlling a large amount of data.
382 The name "tar" originally came from the phrase "Tape ARchive", but
383 archives need not (and these days, typically do not) reside on tapes.
384
385 * Menu:
386
387 * Book Contents::               What this Book Contains
388 * Definitions::                 Some Definitions
389 * What tar Does::               What `tar' Does
390 * Naming tar Archives::         How `tar' Archives are Named
391 * Authors::                     GNU `tar' Authors
392 * Reports::                     Reporting bugs or suggestions
393
394 \1f
395 File: tar.info,  Node: Book Contents,  Next: Definitions,  Up: Introduction
396
397 1.1 What this Book Contains
398 ===========================
399
400 The first part of this chapter introduces you to various terms that will
401 recur throughout the book.  It also tells you who has worked on GNU
402 `tar' and its documentation, and where you should send bug reports or
403 comments.
404
405    The second chapter is a tutorial (*note Tutorial::) which provides a
406 gentle introduction for people who are new to using `tar'.  It is meant
407 to be self-contained, not requiring any reading from subsequent
408 chapters to make sense.  It moves from topic to topic in a logical,
409 progressive order, building on information already explained.
410
411    Although the tutorial is paced and structured to allow beginners to
412 learn how to use `tar', it is not intended solely for beginners.  The
413 tutorial explains how to use the three most frequently used operations
414 (`create', `list', and `extract') as well as two frequently used
415 options (`file' and `verbose').  The other chapters do not refer to the
416 tutorial frequently; however, if a section discusses something which is
417 a complex variant of a basic concept, there may be a cross-reference to
418 that basic concept.  (The entire book, including the tutorial, assumes
419 that the reader understands some basic concepts of using a Unix-type
420 operating system; *note Tutorial::.)
421
422    The third chapter presents the remaining five operations, and
423 information about using `tar' options and option syntax.
424
425    The other chapters are meant to be used as a reference.  Each chapter
426 presents everything that needs to be said about a specific topic.
427
428    One of the chapters (*note Date input formats::) exists in its
429 entirety in other GNU manuals, and is mostly self-contained.  In
430 addition, one section of this manual (*note Standard::) contains a big
431 quote which is taken directly from `tar' sources.
432
433    In general, we give both long and short (abbreviated) option names
434 at least once in each section where the relevant option is covered, so
435 that novice readers will become familiar with both styles.  (A few
436 options have no short versions, and the relevant sections will indicate
437 this.)
438
439 \1f
440 File: tar.info,  Node: Definitions,  Next: What tar Does,  Prev: Book Contents,  Up: Introduction
441
442 1.2 Some Definitions
443 ====================
444
445 The `tar' program is used to create and manipulate `tar' archives.  An
446 "archive" is a single file which contains the contents of many files,
447 while still identifying the names of the files, their owner(s), and so
448 forth.  (In addition, archives record access permissions, user and
449 group, size in bytes, and data modification time.  Some archives also
450 record the file names in each archived directory, as well as other file
451 and directory information.)  You can use `tar' to "create" a new
452 archive in a specified directory.
453
454    The files inside an archive are called "members".  Within this
455 manual, we use the term "file" to refer only to files accessible in the
456 normal ways (by `ls', `cat', and so forth), and the term "member" to
457 refer only to the members of an archive.  Similarly, a "file name" is
458 the name of a file, as it resides in the file system, and a "member
459 name" is the name of an archive member within the archive.
460
461    The term "extraction" refers to the process of copying an archive
462 member (or multiple members) into a file in the file system.  Extracting
463 all the members of an archive is often called "extracting the archive".
464 The term "unpack" can also be used to refer to the extraction of many
465 or all the members of an archive.  Extracting an archive does not
466 destroy the archive's structure, just as creating an archive does not
467 destroy the copies of the files that exist outside of the archive.  You
468 may also "list" the members in a given archive (this is often thought
469 of as "printing" them to the standard output, or the command line), or
470 "append" members to a pre-existing archive.  All of these operations
471 can be performed using `tar'.
472
473 \1f
474 File: tar.info,  Node: What tar Does,  Next: Naming tar Archives,  Prev: Definitions,  Up: Introduction
475
476 1.3 What `tar' Does
477 ===================
478
479 The `tar' program provides the ability to create `tar' archives, as
480 well as various other kinds of manipulation.  For example, you can use
481 `tar' on previously created archives to extract files, to store
482 additional files, or to update or list files which were already stored.
483
484    Initially, `tar' archives were used to store files conveniently on
485 magnetic tape.  The name `tar' comes from this use; it stands for
486 `t'ape `ar'chiver.  Despite the utility's name, `tar' can direct its
487 output to available devices, files, or other programs (using pipes).
488 `tar' may even access remote devices or files (as archives).
489
490    You can use `tar' archives in many ways.  We want to stress a few of
491 them: storage, backup, and transportation.
492
493 Storage
494      Often, `tar' archives are used to store related files for
495      convenient file transfer over a network.  For example, the GNU
496      Project distributes its software bundled into `tar' archives, so
497      that all the files relating to a particular program (or set of
498      related programs) can be transferred as a single unit.
499
500      A magnetic tape can store several files in sequence.  However, the
501      tape has no names for these files; it only knows their relative
502      position on the tape.  One way to store several files on one tape
503      and retain their names is by creating a `tar' archive.  Even when
504      the basic transfer mechanism can keep track of names, as FTP can,
505      the nuisance of handling multiple files, directories, and multiple
506      links makes `tar' archives useful.
507
508      Archive files are also used for long-term storage.  You can think
509      of this as transportation from the present into the future.  (It
510      is a science-fiction idiom that you can move through time as well
511      as in space; the idea here is that `tar' can be used to move
512      archives in all dimensions, even time!)
513
514 Backup
515      Because the archive created by `tar' is capable of preserving file
516      information and directory structure, `tar' is commonly used for
517      performing full and incremental backups of disks.  A backup puts a
518      collection of files (possibly pertaining to many users and
519      projects) together on a disk or a tape.  This guards against
520      accidental destruction of the information in those files.  GNU
521      `tar' has special features that allow it to be used to make
522      incremental and full dumps of all the files in a file system.
523
524 Transportation
525      You can create an archive on one system, transfer it to another
526      system, and extract the contents there.  This allows you to
527      transport a group of files from one system to another.
528
529 \1f
530 File: tar.info,  Node: Naming tar Archives,  Next: Authors,  Prev: What tar Does,  Up: Introduction
531
532 1.4 How `tar' Archives are Named
533 ================================
534
535 Conventionally, `tar' archives are given names ending with `.tar'.
536 This is not necessary for `tar' to operate properly, but this manual
537 follows that convention in order to accustom readers to it and to make
538 examples more clear.
539
540    Often, people refer to `tar' archives as "`tar' files," and archive
541 members as "files" or "entries".  For people familiar with the
542 operation of `tar', this causes no difficulty.  However, in this
543 manual, we consistently refer to "archives" and "archive members" to
544 make learning to use `tar' easier for novice users.
545
546 \1f
547 File: tar.info,  Node: Authors,  Next: Reports,  Prev: Naming tar Archives,  Up: Introduction
548
549 1.5 GNU `tar' Authors
550 =====================
551
552 GNU `tar' was originally written by John Gilmore, and modified by many
553 people.  The GNU enhancements were written by Jay Fenlason, then Joy
554 Kendall, and the whole package has been further maintained by Thomas
555 Bushnell, n/BSG, Franc,ois Pinard, Paul Eggert, and finally Sergey
556 Poznyakoff with the help of numerous and kind users.
557
558    We wish to stress that `tar' is a collective work, and owes much to
559 all those people who reported problems, offered solutions and other
560 insights, or shared their thoughts and suggestions.  An impressive, yet
561 partial list of those contributors can be found in the `THANKS' file
562 from the GNU `tar' distribution.
563
564    Jay Fenlason put together a draft of a GNU `tar' manual, borrowing
565 notes from the original man page from John Gilmore.  This was withdrawn
566 in version 1.11.  Thomas Bushnell, n/BSG and Amy Gorin worked on a
567 tutorial and manual for GNU `tar'.  Franc,ois Pinard put version 1.11.8
568 of the manual together by taking information from all these sources and
569 merging them.  Melissa Weisshaus finally edited and redesigned the book
570 to create version 1.12.  The book for versions from 1.14 up to 1.25
571 were edited by the current maintainer, Sergey Poznyakoff.
572
573    For version 1.12, Daniel Hagerty contributed a great deal of
574 technical consulting.  In particular, he is the primary author of *note
575 Backups::.
576
577    In July, 2003 GNU `tar' was put on CVS at savannah.gnu.org (see
578 `http://savannah.gnu.org/projects/tar'), and active development and
579 maintenance work has started again.  Currently GNU `tar' is being
580 maintained by Paul Eggert, Sergey Poznyakoff and Jeff Bailey.
581
582    Support for POSIX archives was added by Sergey Poznyakoff.
583
584 \1f
585 File: tar.info,  Node: Reports,  Prev: Authors,  Up: Introduction
586
587 1.6 Reporting bugs or suggestions
588 =================================
589
590 If you find problems or have suggestions about this program or manual,
591 please report them to `bug-tar@gnu.org'.
592
593    When reporting a bug, please be sure to include as much detail as
594 possible, in order to reproduce it.
595
596 \1f
597 File: tar.info,  Node: Tutorial,  Next: tar invocation,  Prev: Introduction,  Up: Top
598
599 2 Tutorial Introduction to `tar'
600 ********************************
601
602 This chapter guides you through some basic examples of three `tar'
603 operations: `--create', `--list', and `--extract'.  If you already know
604 how to use some other version of `tar', then you may not need to read
605 this chapter.  This chapter omits most complicated details about how
606 `tar' works.
607
608 * Menu:
609
610 * assumptions::
611 * stylistic conventions::
612 * basic tar options::           Basic `tar' Operations and Options
613 * frequent operations::
614 * Two Frequent Options::
615 * create::                      How to Create Archives
616 * list::                        How to List Archives
617 * extract::                     How to Extract Members from an Archive
618 * going further::
619
620 \1f
621 File: tar.info,  Node: assumptions,  Next: stylistic conventions,  Up: Tutorial
622
623 2.1 Assumptions this Tutorial Makes
624 ===================================
625
626 This chapter is paced to allow beginners to learn about `tar' slowly.
627 At the same time, we will try to cover all the basic aspects of these
628 three operations.  In order to accomplish both of these tasks, we have
629 made certain assumptions about your knowledge before reading this
630 manual, and the hardware you will be using:
631
632    * Before you start to work through this tutorial, you should
633      understand what the terms "archive" and "archive member" mean
634      (*note Definitions::).  In addition, you should understand
635      something about how Unix-type operating systems work, and you
636      should know how to use some basic utilities.  For example, you
637      should know how to create, list, copy, rename, edit, and delete
638      files and directories; how to change between directories; and how
639      to figure out where you are in the file system.  You should have
640      some basic understanding of directory structure and how files are
641      named according to which directory they are in.  You should
642      understand concepts such as standard output and standard input,
643      what various definitions of the term `argument' mean, and the
644      differences between relative and absolute file names.
645
646    * This manual assumes that you are working from your own home
647      directory (unless we state otherwise).  In this tutorial, you will
648      create a directory to practice `tar' commands in.  When we show
649      file names, we will assume that those names are relative to your
650      home directory.  For example, my home directory is
651      `/home/fsf/melissa'.  All of my examples are in a subdirectory of
652      the directory named by that file name; the subdirectory is called
653      `practice'.
654
655    * In general, we show examples of archives which exist on (or can be
656      written to, or worked with from) a directory on a hard disk.  In
657      most cases, you could write those archives to, or work with them
658      on any other device, such as a tape drive.  However, some of the
659      later examples in the tutorial and next chapter will not work on
660      tape drives.  Additionally, working with tapes is much more
661      complicated than working with hard disks.  For these reasons, the
662      tutorial does not cover working with tape drives.  *Note Media::,
663      for complete information on using `tar' archives with tape drives.
664
665
666 \1f
667 File: tar.info,  Node: stylistic conventions,  Next: basic tar options,  Prev: assumptions,  Up: Tutorial
668
669 2.2 Stylistic Conventions
670 =========================
671
672 In the examples, `$' represents a typical shell prompt.  It precedes
673 lines you should type; to make this more clear, those lines are shown
674 in `this font', as opposed to lines which represent the computer's
675 response; those lines are shown in `this font', or sometimes `like
676 this'.
677
678 \1f
679 File: tar.info,  Node: basic tar options,  Next: frequent operations,  Prev: stylistic conventions,  Up: Tutorial
680
681 2.3 Basic `tar' Operations and Options
682 ======================================
683
684 `tar' can take a wide variety of arguments which specify and define the
685 actions it will have on the particular set of files or the archive.
686 The main types of arguments to `tar' fall into one of two classes:
687 operations, and options.
688
689    Some arguments fall into a class called "operations"; exactly one of
690 these is both allowed and required for any instance of using `tar'; you
691 may _not_ specify more than one.  People sometimes speak of "operating
692 modes".  You are in a particular operating mode when you have specified
693 the operation which specifies it; there are eight operations in total,
694 and thus there are eight operating modes.
695
696    The other arguments fall into the class known as "options".  You are
697 not required to specify any options, and you are allowed to specify more
698 than one at a time (depending on the way you are using `tar' at that
699 time).  Some options are used so frequently, and are so useful for
700 helping you type commands more carefully that they are effectively
701 "required".  We will discuss them in this chapter.
702
703    You can write most of the `tar' operations and options in any of
704 three forms: long (mnemonic) form, short form, and old style.  Some of
705 the operations and options have no short or "old" forms; however, the
706 operations and options which we will cover in this tutorial have
707 corresponding abbreviations.  We will indicate those abbreviations
708 appropriately to get you used to seeing them.  Note, that the "old
709 style" option forms exist in GNU `tar' for compatibility with Unix
710 `tar'.  In this book we present a full discussion of this way of
711 writing options and operations (*note Old Options::), and we discuss
712 the other two styles of writing options (*Note Long Options::, and
713 *note Short Options::).
714
715    In the examples and in the text of this tutorial, we usually use the
716 long forms of operations and options; but the "short" forms produce the
717 same result and can make typing long `tar' commands easier.  For
718 example, instead of typing
719
720      tar --create --verbose --file=afiles.tar apple angst aspic
721
722 you can type
723      tar -c -v -f afiles.tar apple angst aspic
724
725 or even
726      tar -cvf afiles.tar apple angst aspic
727
728 For more information on option syntax, see *note Advanced tar::.  In
729 discussions in the text, when we name an option by its long form, we
730 also give the corresponding short option in parentheses.
731
732    The term, "option", can be confusing at times, since "operations"
733 are often lumped in with the actual, _optional_ "options" in certain
734 general class statements.  For example, we just talked about "short and
735 long forms of options and operations".  However, experienced `tar'
736 users often refer to these by shorthand terms such as, "short and long
737 options".  This term assumes that the "operations" are included, also.
738 Context will help you determine which definition of "options" to use.
739
740    Similarly, the term "command" can be confusing, as it is often used
741 in two different ways.  People sometimes refer to `tar' "commands".  A
742 `tar' "command" is the entire command line of user input which tells
743 `tar' what to do -- including the operation, options, and any arguments
744 (file names, pipes, other commands, etc.).  However, you will also
745 sometimes hear the term "the `tar' command".  When the word "command"
746 is used specifically like this, a person is usually referring to the
747 `tar' _operation_, not the whole line.  Again, use context to figure
748 out which of the meanings the speaker intends.
749
750 \1f
751 File: tar.info,  Node: frequent operations,  Next: Two Frequent Options,  Prev: basic tar options,  Up: Tutorial
752
753 2.4 The Three Most Frequently Used Operations
754 =============================================
755
756 Here are the three most frequently used operations (both short and long
757 forms), as well as a brief description of their meanings.  The rest of
758 this chapter will cover how to use these operations in detail.  We will
759 present the rest of the operations in the next chapter.
760
761 `--create'
762 `-c'
763      Create a new `tar' archive.
764
765 `--list'
766 `-t'
767      List the contents of an archive.
768
769 `--extract'
770 `-x'
771      Extract one or more members from an archive.
772
773 \1f
774 File: tar.info,  Node: Two Frequent Options,  Next: create,  Prev: frequent operations,  Up: Tutorial
775
776 2.5 Two Frequently Used Options
777 ===============================
778
779 To understand how to run `tar' in the three operating modes listed
780 previously, you also need to understand how to use two of the options to
781 `tar': `--file' (which takes an archive file as an argument) and
782 `--verbose'.  (You are usually not _required_ to specify either of
783 these options when you run `tar', but they can be very useful in making
784 things more clear and helping you avoid errors.)
785
786 * Menu:
787
788 * file tutorial::
789 * verbose tutorial::
790 * help tutorial::
791
792 \1f
793 File: tar.info,  Node: file tutorial,  Next: verbose tutorial,  Up: Two Frequent Options
794
795 The `--file' Option
796 -------------------
797
798 `--file=ARCHIVE-NAME'
799 `-f ARCHIVE-NAME'
800      Specify the name of an archive file.
801
802    You can specify an argument for the `--file=ARCHIVE-NAME' (`-f
803 ARCHIVE-NAME') option whenever you use `tar'; this option determines
804 the name of the archive file that `tar' will work on.
805
806    If you don't specify this argument, then `tar' will examine the
807 environment variable `TAPE'.  If it is set, its value will be used as
808 the archive name.  Otherwise, `tar' will use the default archive,
809 determined at compile time. Usually it is standard output or some
810 physical tape drive attached to your machine (you can verify what the
811 default is by running `tar --show-defaults', *note defaults::).  If
812 there is no tape drive attached, or the default is not meaningful, then
813 `tar' will print an error message.  The error message might look
814 roughly like one of the following:
815
816      tar: can't open /dev/rmt8 : No such device or address
817      tar: can't open /dev/rsmt0 : I/O error
818
819 To avoid confusion, we recommend that you always specify an archive file
820 name by using `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') when writing
821 your `tar' commands.  For more information on using the
822 `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') option, see *note file::.
823
824 \1f
825 File: tar.info,  Node: verbose tutorial,  Next: help tutorial,  Prev: file tutorial,  Up: Two Frequent Options
826
827 The `--verbose' Option
828 ----------------------
829
830 `--verbose'
831 `-v'
832      Show the files being worked on as `tar' is running.
833
834    `--verbose' (`-v') shows details about the results of running `tar'.
835 This can be especially useful when the results might not be obvious.
836 For example, if you want to see the progress of `tar' as it writes
837 files into the archive, you can use the `--verbose' option.  In the
838 beginning, you may find it useful to use `--verbose' at all times; when
839 you are more accustomed to `tar', you will likely want to use it at
840 certain times but not at others.  We will use `--verbose' at times to
841 help make something clear, and we will give many examples both using
842 and not using `--verbose' to show the differences.
843
844    Each instance of `--verbose' on the command line increases the
845 verbosity level by one, so if you need more details on the output,
846 specify it twice.
847
848    When reading archives (`--list', `--extract', `--diff'), `tar' by
849 default prints only the names of the members being extracted.  Using
850 `--verbose' will show a full, `ls' style member listing.
851
852    In contrast, when writing archives (`--create', `--append',
853 `--update'), `tar' does not print file names by default.  So, a single
854 `--verbose' option shows the file names being added to the archive,
855 while two `--verbose' options enable the full listing.
856
857    For example, to create an archive in verbose mode:
858
859      $ tar -cvf afiles.tar apple angst aspic
860      apple
861      angst
862      aspic
863
864 Creating the same archive with the verbosity level 2 could give:
865
866      $ tar -cvvf afiles.tar apple angst aspic
867      -rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
868      -rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
869      -rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic
870
871 This works equally well using short or long forms of options.  Using
872 long forms, you would simply write out the mnemonic form of the option
873 twice, like this:
874
875      $ tar --create --verbose --verbose ...
876
877 Note that you must double the hyphens properly each time.
878
879    Later in the tutorial, we will give examples using
880 `--verbose --verbose'.
881
882    The full output consists of six fields:
883
884    * File type and permissions in symbolic form.  These are displayed
885      in the same format as the first column of `ls -l' output (*note
886      format=verbose: (fileutils)What information is listed.).
887
888    * Owner name and group separated by a slash character.  If these
889      data are not available (for example, when listing a `v7' format
890      archive), numeric ID values are printed instead.
891
892    * Size of the file, in bytes.
893
894    * File modification date in ISO 8601 format.
895
896    * File modification time.
897
898    * File name.  If the name contains any special characters (white
899      space, newlines, etc.) these are displayed in an unambiguous form
900      using so called "quoting style".  For the detailed discussion of
901      available styles and on how to use them, see *note quoting
902      styles::.
903
904      Depending on the file type, the name can be followed by some
905      additional information, described in the following table:
906
907     `-> LINK-NAME'
908           The file or archive member is a "symbolic link" and LINK-NAME
909           is the name of file it links to.
910
911     `link to LINK-NAME'
912           The file or archive member is a "hard link" and LINK-NAME is
913           the name of file it links to.
914
915     `--Long Link--'
916           The archive member is an old GNU format long link.  You will
917           normally not encounter this.
918
919     `--Long Name--'
920           The archive member is an old GNU format long name.  You will
921           normally not encounter this.
922
923     `--Volume Header--'
924           The archive member is a GNU "volume header" (*note Tape
925           Files::).
926
927     `--Continued at byte N--'
928           Encountered only at the beginning of a multi-volume archive
929           (*note Using Multiple Tapes::).  This archive member is a
930           continuation from the previous volume. The number N gives the
931           offset where the original file was split.
932
933     `unknown file type C'
934           An archive member of unknown type. C is the type character
935           from the archive header.  If you encounter such a message, it
936           means that either your archive contains proprietary member
937           types GNU `tar' is not able to handle, or the archive is
938           corrupted.
939
940
941    For example, here is an archive listing containing most of the
942 special suffixes explained above:
943
944      V--------- 0/0          1536 2006-06-09 13:07 MyVolume--Volume Header--
945      -rw-r--r-- gray/staff 456783 2006-06-09 12:06 aspic--Continued at
946      byte 32456--
947      -rw-r--r-- gray/staff  62373 2006-06-09 12:06 apple
948      lrwxrwxrwx gray/staff      0 2006-06-09 13:01 angst -> apple
949      -rw-r--r-- gray/staff  35793 2006-06-09 12:06 blues
950      hrw-r--r-- gray/staff      0 2006-06-09 12:06 music link to blues
951
952
953 \1f
954 File: tar.info,  Node: help tutorial,  Prev: verbose tutorial,  Up: Two Frequent Options
955
956 Getting Help: Using the `--help' Option
957 ---------------------------------------
958
959 `--help'
960      The `--help' option to `tar' prints out a very brief list of all
961      operations and option available for the current version of `tar'
962      available on your system.
963
964 \1f
965 File: tar.info,  Node: create,  Next: list,  Prev: Two Frequent Options,  Up: Tutorial
966
967 2.6 How to Create Archives
968 ==========================
969
970      _(This message will disappear, once this node revised.)_
971
972 One of the basic operations of `tar' is `--create' (`-c'), which you
973 use to create a `tar' archive.  We will explain `--create' first
974 because, in order to learn about the other operations, you will find it
975 useful to have an archive available to practice on.
976
977    To make this easier, in this section you will first create a
978 directory containing three files.  Then, we will show you how to create
979 an _archive_ (inside the new directory).  Both the directory, and the
980 archive are specifically for you to practice on.  The rest of this
981 chapter and the next chapter will show many examples using this
982 directory and the files you will create: some of those files may be
983 other directories and other archives.
984
985    The three files you will archive in this example are called `blues',
986 `folk', and `jazz'.  The archive is called `collection.tar'.
987
988    This section will proceed slowly, detailing how to use `--create' in
989 `verbose' mode, and showing examples using both short and long forms.
990 In the rest of the tutorial, and in the examples in the next chapter,
991 we will proceed at a slightly quicker pace.  This section moves more
992 slowly to allow beginning users to understand how `tar' works.
993
994 * Menu:
995
996 * prepare for examples::
997 * Creating the archive::
998 * create verbose::
999 * short create::
1000 * create dir::
1001
1002 \1f
1003 File: tar.info,  Node: prepare for examples,  Next: Creating the archive,  Up: create
1004
1005 2.6.1 Preparing a Practice Directory for Examples
1006 -------------------------------------------------
1007
1008 To follow along with this and future examples, create a new directory
1009 called `practice' containing files called `blues', `folk' and `jazz'.
1010 The files can contain any information you like: ideally, they should
1011 contain information which relates to their names, and be of different
1012 lengths.  Our examples assume that `practice' is a subdirectory of your
1013 home directory.
1014
1015    Now `cd' to the directory named `practice'; `practice' is now your
1016 "working directory".  (_Please note_: Although the full file name of
1017 this directory is `/HOMEDIR/practice', in our examples we will refer to
1018 this directory as `practice'; the HOMEDIR is presumed.)
1019
1020    In general, you should check that the files to be archived exist
1021 where you think they do (in the working directory) by running `ls'.
1022 Because you just created the directory and the files and have changed to
1023 that directory, you probably don't need to do that this time.
1024
1025    It is very important to make sure there isn't already a file in the
1026 working directory with the archive name you intend to use (in this case,
1027 `collection.tar'), or that you don't care about its contents.  Whenever
1028 you use `create', `tar' will erase the current contents of the file
1029 named by `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') if it exists.  `tar'
1030 will not tell you if you are about to overwrite an archive unless you
1031 specify an option which does this (*note backup::, for the information
1032 on how to do so).  To add files to an existing archive, you need to use
1033 a different option, such as `--append' (`-r'); see *note append:: for
1034 information on how to do this.
1035
1036 \1f
1037 File: tar.info,  Node: Creating the archive,  Next: create verbose,  Prev: prepare for examples,  Up: create
1038
1039 2.6.2 Creating the Archive
1040 --------------------------
1041
1042 To place the files `blues', `folk', and `jazz' into an archive named
1043 `collection.tar', use the following command:
1044
1045      $ tar --create --file=collection.tar blues folk jazz
1046
1047    The order of the arguments is not very important, _when using long
1048 option forms_.  You could also say:
1049
1050      $ tar blues --create folk --file=collection.tar jazz
1051
1052 However, you can see that this order is harder to understand; this is
1053 why we will list the arguments in the order that makes the commands
1054 easiest to understand (and we encourage you to do the same when you use
1055 `tar', to avoid errors).
1056
1057    Note that the sequence `--file=collection.tar' is considered to be
1058 _one_ argument.  If you substituted any other string of characters for
1059 `collection.tar',  then that string would become the name of the
1060 archive file you create.
1061
1062    The order of the options becomes more important when you begin to use
1063 short forms.  With short forms, if you type commands in the wrong order
1064 (even if you type them correctly in all other ways), you may end up with
1065 results you don't expect.  For this reason, it is a good idea to get
1066 into the habit of typing options in the order that makes inherent sense.
1067 *Note short create::, for more information on this.
1068
1069    In this example, you type the command as shown above: `--create' is
1070 the operation which creates the new archive (`collection.tar'), and
1071 `--file' is the option which lets you give it the name you chose.  The
1072 files, `blues', `folk', and `jazz', are now members of the archive,
1073 `collection.tar' (they are "file name arguments" to the `--create'
1074 operation.  *Note Choosing::, for the detailed discussion on these.)
1075 Now that they are in the archive, they are called _archive members_,
1076 not files.  (*note members: Definitions.).
1077
1078    When you create an archive, you _must_ specify which files you want
1079 placed in the archive.  If you do not specify any archive members, GNU
1080 `tar' will complain.
1081
1082    If you now list the contents of the working directory (`ls'), you
1083 will find the archive file listed as well as the files you saw
1084 previously:
1085
1086      blues   folk   jazz   collection.tar
1087
1088 Creating the archive `collection.tar' did not destroy the copies of the
1089 files in the directory.
1090
1091    Keep in mind that if you don't indicate an operation, `tar' will not
1092 run and will prompt you for one.  If you don't name any files, `tar'
1093 will complain.  You must have write access to the working directory, or
1094 else you will not be able to create an archive in that directory.
1095
1096    _Caution_: Do not attempt to use `--create' (`-c') to add files to
1097 an existing archive; it will delete the archive and write a new one.
1098 Use `--append' (`-r') instead.  *Note append::.
1099
1100 \1f
1101 File: tar.info,  Node: create verbose,  Next: short create,  Prev: Creating the archive,  Up: create
1102
1103 2.6.3 Running `--create' with `--verbose'
1104 -----------------------------------------
1105
1106 If you include the `--verbose' (`-v') option on the command line, `tar'
1107 will list the files it is acting on as it is working.  In verbose mode,
1108 the `create' example above would appear as:
1109
1110      $ tar --create --verbose --file=collection.tar blues folk jazz
1111      blues
1112      folk
1113      jazz
1114
1115    This example is just like the example we showed which did not use
1116 `--verbose', except that `tar' generated the remaining lines.
1117
1118    In the rest of the examples in this chapter, we will frequently use
1119 `verbose' mode so we can show actions or `tar' responses that you would
1120 otherwise not see, and which are important for you to understand.
1121
1122 \1f
1123 File: tar.info,  Node: short create,  Next: create dir,  Prev: create verbose,  Up: create
1124
1125 2.6.4 Short Forms with `create'
1126 -------------------------------
1127
1128 As we said before, the `--create' (`-c') operation is one of the most
1129 basic uses of `tar', and you will use it countless times.  Eventually,
1130 you will probably want to use abbreviated (or "short") forms of
1131 options.  A full discussion of the three different forms that options
1132 can take appears in *note Styles::; for now, here is what the previous
1133 example (including the `--verbose' (`-v') option) looks like using
1134 short option forms:
1135
1136      $ tar -cvf collection.tar blues folk jazz
1137      blues
1138      folk
1139      jazz
1140
1141 As you can see, the system responds the same no matter whether you use
1142 long or short option forms.
1143
1144    One difference between using short and long option forms is that,
1145 although the exact placement of arguments following options is no more
1146 specific when using short forms, it is easier to become confused and
1147 make a mistake when using short forms.  For example, suppose you
1148 attempted the above example in the following way:
1149
1150      $ tar -cfv collection.tar blues folk jazz
1151
1152 In this case, `tar' will make an archive file called `v', containing
1153 the files `blues', `folk', and `jazz', because the `v' is the closest
1154 "file name" to the `-f' option, and is thus taken to be the chosen
1155 archive file name.  `tar' will try to add a file called
1156 `collection.tar' to the `v' archive file; if the file `collection.tar'
1157 did not already exist, `tar' will report an error indicating that this
1158 file does not exist.  If the file `collection.tar' does already exist
1159 (e.g., from a previous command you may have run), then `tar' will add
1160 this file to the archive.  Because the `-v' option did not get
1161 registered, `tar' will not run under `verbose' mode, and will not
1162 report its progress.
1163
1164    The end result is that you may be quite confused about what happened,
1165 and possibly overwrite a file.  To illustrate this further, we will show
1166 you how an example we showed previously would look using short forms.
1167
1168    This example,
1169
1170      $ tar blues --create folk --file=collection.tar jazz
1171
1172 is confusing as it is.  When shown using short forms, however, it
1173 becomes much more so:
1174
1175      $ tar blues -c folk -f collection.tar jazz
1176
1177 It would be very easy to put the wrong string of characters immediately
1178 following the `-f', but doing that could sacrifice valuable data.
1179
1180    For this reason, we recommend that you pay very careful attention to
1181 the order of options and placement of file and archive names,
1182 especially when using short option forms.  Not having the option name
1183 written out mnemonically can affect how well you remember which option
1184 does what, and therefore where different names have to be placed.
1185
1186 \1f
1187 File: tar.info,  Node: create dir,  Prev: short create,  Up: create
1188
1189 2.6.5 Archiving Directories
1190 ---------------------------
1191
1192 You can archive a directory by specifying its directory name as a file
1193 name argument to `tar'.  The files in the directory will be archived
1194 relative to the working directory, and the directory will be re-created
1195 along with its contents when the archive is extracted.
1196
1197    To archive a directory, first move to its superior directory.  If you
1198 have followed the previous instructions in this tutorial, you should
1199 type:
1200
1201      $ cd ..
1202      $
1203
1204 This will put you into the directory which contains `practice', i.e.,
1205 your home directory.  Once in the superior directory, you can specify
1206 the subdirectory, `practice', as a file name argument.  To store
1207 `practice' in the new archive file `music.tar', type:
1208
1209      $ tar --create --verbose --file=music.tar practice
1210
1211 `tar' should output:
1212
1213      practice/
1214      practice/blues
1215      practice/folk
1216      practice/jazz
1217      practice/collection.tar
1218
1219    Note that the archive thus created is not in the subdirectory
1220 `practice', but rather in the current working directory--the directory
1221 from which `tar' was invoked.  Before trying to archive a directory
1222 from its superior directory, you should make sure you have write access
1223 to the superior directory itself, not only the directory you are trying
1224 archive with `tar'.  For example, you will probably not be able to
1225 store your home directory in an archive by invoking `tar' from the root
1226 directory; *Note absolute::.  (Note also that `collection.tar', the
1227 original archive file, has itself been archived.  `tar' will accept any
1228 file as a file to be archived, regardless of its content.  When
1229 `music.tar' is extracted, the archive file `collection.tar' will be
1230 re-written into the file system).
1231
1232    If you give `tar' a command such as
1233
1234      $ tar --create --file=foo.tar .
1235
1236 `tar' will report `tar: ./foo.tar is the archive; not dumped'.  This
1237 happens because `tar' creates the archive `foo.tar' in the current
1238 directory before putting any files into it.  Then, when `tar' attempts
1239 to add all the files in the directory `.' to the archive, it notices
1240 that the file `./foo.tar' is the same as the archive `foo.tar', and
1241 skips it.  (It makes no sense to put an archive into itself.)  GNU `tar'
1242 will continue in this case, and create the archive normally, except for
1243 the exclusion of that one file.  (_Please note:_ Other implementations
1244 of `tar' may not be so clever; they will enter an infinite loop when
1245 this happens, so you should not depend on this behavior unless you are
1246 certain you are running GNU `tar'.  In general, it is wise to always
1247 place the archive outside of the directory being dumped.)
1248
1249 \1f
1250 File: tar.info,  Node: list,  Next: extract,  Prev: create,  Up: Tutorial
1251
1252 2.7 How to List Archives
1253 ========================
1254
1255 Frequently, you will find yourself wanting to determine exactly what a
1256 particular archive contains.  You can use the `--list' (`-t') operation
1257 to get the member names as they currently appear in the archive, as
1258 well as various attributes of the files at the time they were archived.
1259 For example, you can examine the archive `collection.tar' that you
1260 created in the last section with the command,
1261
1262      $ tar --list --file=collection.tar
1263
1264 The output of `tar' would then be:
1265
1266      blues
1267      folk
1268      jazz
1269
1270 The archive `bfiles.tar' would list as follows:
1271
1272      ./birds
1273      baboon
1274      ./box
1275
1276 Be sure to use a `--file=ARCHIVE-NAME' (`-f ARCHIVE-NAME') option just
1277 as with `--create' (`-c') to specify the name of the archive.
1278
1279    If you use the `--verbose' (`-v') option with `--list', then `tar'
1280 will print out a listing reminiscent of `ls -l', showing owner, file
1281 size, and so forth.  This output is described in detail in *note
1282 verbose member listing::.
1283
1284    If you had used `--verbose' (`-v') mode, the example above would
1285 look like:
1286
1287      $ tar --list --verbose --file=collection.tar folk
1288      -rw-r--r-- myself user 62 1990-05-23 10:55 folk
1289
1290    It is important to notice that the output of `tar --list --verbose'
1291 does not necessarily match that produced by `tar --create --verbose'
1292 while creating the archive.  It is because GNU `tar', unless told
1293 explicitly not to do so, removes some directory prefixes from file
1294 names before storing them in the archive (*Note absolute::, for more
1295 information).  In other words, in verbose mode GNU `tar' shows "file
1296 names" when creating an archive and "member names" when listing it.
1297 Consider this example:
1298
1299      $ tar --create --verbose --file archive /etc/mail
1300      tar: Removing leading `/' from member names
1301      /etc/mail/
1302      /etc/mail/sendmail.cf
1303      /etc/mail/aliases
1304      $ tar --test --file archive
1305      etc/mail/
1306      etc/mail/sendmail.cf
1307      etc/mail/aliases
1308
1309    This default behavior can sometimes be inconvenient.  You can force
1310 GNU `tar' show member names when creating archive by supplying
1311 `--show-stored-names' option.
1312
1313 `--show-stored-names'
1314      Print member (as opposed to _file_) names when creating the
1315      archive.
1316
1317    You can specify one or more individual member names as arguments when
1318 using `list'.  In this case, `tar' will only list the names of members
1319 you identify.  For example, `tar --list --file=afiles.tar apple' would
1320 only print `apple'.
1321
1322    Because `tar' preserves file names, these must be specified as they
1323 appear in the archive (i.e., relative to the directory from which the
1324 archive was created).  Therefore, it is essential when specifying
1325 member names to `tar' that you give the exact member names.  For
1326 example, `tar --list --file=bfiles.tar birds' would produce an error
1327 message something like `tar: birds: Not found in archive', because
1328 there is no member named `birds', only one named `./birds'.  While the
1329 names `birds' and `./birds' name the same file, _member_ names by
1330 default are compared verbatim.
1331
1332    However, `tar --list --file=bfiles.tar baboon' would respond with
1333 `baboon', because this exact member name is in the archive file
1334 `bfiles.tar'.  If you are not sure of the exact file name, use
1335 "globbing patterns", for example:
1336
1337      $ tar --list --file=bfiles.tar --wildcards '*b*'
1338
1339 will list all members whose name contains `b'.  *Note wildcards::, for
1340 a detailed discussion of globbing patterns and related `tar' command
1341 line options.
1342
1343 * Menu:
1344
1345 * list dir::
1346
1347 \1f
1348 File: tar.info,  Node: list dir,  Up: list
1349
1350 Listing the Contents of a Stored Directory
1351 ------------------------------------------
1352
1353 To get information about the contents of an archived directory, use the
1354 directory name as a file name argument in conjunction with `--list'
1355 (`-t').  To find out file attributes, include the `--verbose' (`-v')
1356 option.
1357
1358    For example, to find out about files in the directory `practice', in
1359 the archive file `music.tar', type:
1360
1361      $ tar --list --verbose --file=music.tar practice
1362
1363    `tar' responds:
1364
1365      drwxrwxrwx myself user 0 1990-05-31 21:49 practice/
1366      -rw-r--r-- myself user 42 1990-05-21 13:29 practice/blues
1367      -rw-r--r-- myself user 62 1990-05-23 10:55 practice/folk
1368      -rw-r--r-- myself user 40 1990-05-21 13:30 practice/jazz
1369      -rw-r--r-- myself user 10240 1990-05-31 21:49 practice/collection.tar
1370
1371    When you use a directory name as a file name argument, `tar' acts on
1372 all the files (including sub-directories) in that directory.
1373
1374 \1f
1375 File: tar.info,  Node: extract,  Next: going further,  Prev: list,  Up: Tutorial
1376
1377 2.8 How to Extract Members from an Archive
1378 ==========================================
1379
1380 Creating an archive is only half the job--there is no point in storing
1381 files in an archive if you can't retrieve them.  The act of retrieving
1382 members from an archive so they can be used and manipulated as
1383 unarchived files again is called "extraction".  To extract files from
1384 an archive, use the `--extract' (`--get' or `-x') operation.  As with
1385 `--create', specify the name of the archive with `--file' (`-f')
1386 option. Extracting an archive does not modify the archive in any way;
1387 you can extract it multiple times if you want or need to.
1388
1389    Using `--extract', you can extract an entire archive, or specific
1390 files.  The files can be directories containing other files, or not.  As
1391 with `--create' (`-c') and `--list' (`-t'), you may use the short or the
1392 long form of the operation without affecting the performance.
1393
1394 * Menu:
1395
1396 * extracting archives::
1397 * extracting files::
1398 * extract dir::
1399 * extracting untrusted archives::
1400 * failing commands::
1401
1402 \1f
1403 File: tar.info,  Node: extracting archives,  Next: extracting files,  Up: extract
1404
1405 2.8.1 Extracting an Entire Archive
1406 ----------------------------------
1407
1408 To extract an entire archive, specify the archive file name only, with
1409 no individual file names as arguments.  For example,
1410
1411      $ tar -xvf collection.tar
1412
1413 produces this:
1414
1415      -rw-r--r-- me user     28 1996-10-18 16:31 jazz
1416      -rw-r--r-- me user     21 1996-09-23 16:44 blues
1417      -rw-r--r-- me user     20 1996-09-23 16:44 folk
1418
1419 \1f
1420 File: tar.info,  Node: extracting files,  Next: extract dir,  Prev: extracting archives,  Up: extract
1421
1422 2.8.2 Extracting Specific Files
1423 -------------------------------
1424
1425 To extract specific archive members, give their exact member names as
1426 arguments, as printed by `--list' (`-t').  If you had mistakenly
1427 deleted one of the files you had placed in the archive `collection.tar'
1428 earlier (say, `blues'), you can extract it from the archive without
1429 changing the archive's structure.  Its contents will be identical to
1430 the original file `blues' that you deleted.
1431
1432    First, make sure you are in the `practice' directory, and list the
1433 files in the directory.  Now, delete the file, `blues', and list the
1434 files in the directory again.
1435
1436    You can now extract the member `blues' from the archive file
1437 `collection.tar' like this:
1438
1439      $ tar --extract --file=collection.tar blues
1440
1441 If you list the files in the directory again, you will see that the file
1442 `blues' has been restored, with its original permissions, data
1443 modification times, and owner.(1)  (These parameters will be identical
1444 to those which the file had when you originally placed it in the
1445 archive; any changes you may have made before deleting the file from
1446 the file system, however, will _not_ have been made to the archive
1447 member.)  The archive file, `collection.tar', is the same as it was
1448 before you extracted `blues'.  You can confirm this by running `tar'
1449 with `--list' (`-t').
1450
1451    Remember that as with other operations, specifying the exact member
1452 name is important.  `tar --extract --file=bfiles.tar birds' will fail,
1453 because there is no member named `birds'.  To extract the member named
1454 `./birds', you must specify `tar --extract --file=bfiles.tar ./birds'.
1455 If you don't remember the exact member names, use `--list' (`-t') option
1456 (*note list::).  You can also extract those members that match a
1457 specific "globbing pattern".  For example, to extract from `bfiles.tar'
1458 all files that begin with `b', no matter their directory prefix, you
1459 could type:
1460
1461      $ tar -x -f bfiles.tar --wildcards --no-anchored 'b*'
1462
1463 Here, `--wildcards' instructs `tar' to treat command line arguments as
1464 globbing patterns and `--no-anchored' informs it that the patterns
1465 apply to member names after any `/' delimiter.  The use of globbing
1466 patterns is discussed in detail in *Note wildcards::.
1467
1468    You can extract a file to standard output by combining the above
1469 options with the `--to-stdout' (`-O') option (*note Writing to Standard
1470 Output::).
1471
1472    If you give the `--verbose' option, then `--extract' will print the
1473 names of the archive members as it extracts them.
1474
1475    ---------- Footnotes ----------
1476
1477    (1) This is only accidentally true, but not in general.  Whereas
1478 modification times are always restored, in most cases, one has to be
1479 root for restoring the owner, and use a special option for restoring
1480 permissions.  Here, it just happens that the restoring user is also the
1481 owner of the archived members, and that the current `umask' is
1482 compatible with original permissions.
1483
1484 \1f
1485 File: tar.info,  Node: extract dir,  Next: extracting untrusted archives,  Prev: extracting files,  Up: extract
1486
1487 2.8.3 Extracting Files that are Directories
1488 -------------------------------------------
1489
1490 Extracting directories which are members of an archive is similar to
1491 extracting other files.  The main difference to be aware of is that if
1492 the extracted directory has the same name as any directory already in
1493 the working directory, then files in the extracted directory will be
1494 placed into the directory of the same name.  Likewise, if there are
1495 files in the pre-existing directory with the same names as the members
1496 which you extract, the files from the extracted archive will replace
1497 the files already in the working directory (and possible
1498 subdirectories).  This will happen regardless of whether or not the
1499 files in the working directory were more recent than those extracted
1500 (there exist, however, special options that alter this behavior *note
1501 Writing::).
1502
1503    However, if a file was stored with a directory name as part of its
1504 file name, and that directory does not exist under the working
1505 directory when the file is extracted, `tar' will create the directory.
1506
1507    We can demonstrate how to use `--extract' to extract a directory
1508 file with an example.  Change to the `practice' directory if you
1509 weren't there, and remove the files `folk' and `jazz'.  Then, go back
1510 to the parent directory and extract the archive `music.tar'.  You may
1511 either extract the entire archive, or you may extract only the files
1512 you just deleted.  To extract the entire archive, don't give any file
1513 names as arguments after the archive name `music.tar'.  To extract only
1514 the files you deleted, use the following command:
1515
1516      $ tar -xvf music.tar practice/folk practice/jazz
1517      practice/folk
1518      practice/jazz
1519
1520 If you were to specify two `--verbose' (`-v') options, `tar' would have
1521 displayed more detail about the extracted files, as shown in the
1522 example below:
1523
1524      $ tar -xvvf music.tar practice/folk practice/jazz
1525      -rw-r--r-- me user     28 1996-10-18 16:31 practice/jazz
1526      -rw-r--r-- me user     20 1996-09-23 16:44 practice/folk
1527
1528 Because you created the directory with `practice' as part of the file
1529 names of each of the files by archiving the `practice' directory as
1530 `practice', you must give `practice' as part of the file names when you
1531 extract those files from the archive.
1532
1533 \1f
1534 File: tar.info,  Node: extracting untrusted archives,  Next: failing commands,  Prev: extract dir,  Up: extract
1535
1536 2.8.4 Extracting Archives from Untrusted Sources
1537 ------------------------------------------------
1538
1539 Extracting files from archives can overwrite files that already exist.
1540 If you receive an archive from an untrusted source, you should make a
1541 new directory and extract into that directory, so that you don't have
1542 to worry about the extraction overwriting one of your existing files.
1543 For example, if `untrusted.tar' came from somewhere else on the
1544 Internet, and you don't necessarily trust its contents, you can extract
1545 it as follows:
1546
1547      $ mkdir newdir
1548      $ cd newdir
1549      $ tar -xvf ../untrusted.tar
1550
1551    It is also a good practice to examine contents of the archive before
1552 extracting it, using `--list' (`-t') option, possibly combined with
1553 `--verbose' (`-v').
1554
1555 \1f
1556 File: tar.info,  Node: failing commands,  Prev: extracting untrusted archives,  Up: extract
1557
1558 2.8.5 Commands That Will Fail
1559 -----------------------------
1560
1561 Here are some sample commands you might try which will not work, and why
1562 they won't work.
1563
1564    If you try to use this command,
1565
1566      $ tar -xvf music.tar folk jazz
1567
1568 you will get the following response:
1569
1570      tar: folk: Not found in archive
1571      tar: jazz: Not found in archive
1572
1573 This is because these files were not originally _in_ the parent
1574 directory `..', where the archive is located; they were in the
1575 `practice' directory, and their file names reflect this:
1576
1577      $ tar -tvf music.tar
1578      practice/blues
1579      practice/folk
1580      practice/jazz
1581
1582 Likewise, if you try to use this command,
1583
1584      $ tar -tvf music.tar folk jazz
1585
1586 you would get a similar response.  Members with those names are not in
1587 the archive.  You must use the correct member names, or wildcards, in
1588 order to extract the files from the archive.
1589
1590    If you have forgotten the correct names of the files in the archive,
1591 use `tar --list --verbose' to list them correctly.
1592
1593 \1f
1594 File: tar.info,  Node: going further,  Prev: extract,  Up: Tutorial
1595
1596 2.9 Going Further Ahead in this Manual
1597 ======================================
1598
1599      _(This message will disappear, once this node revised.)_
1600
1601 \1f
1602 File: tar.info,  Node: tar invocation,  Next: operations,  Prev: Tutorial,  Up: Top
1603
1604 3 Invoking GNU `tar'
1605 ********************
1606
1607 This chapter is about how one invokes the GNU `tar' command, from the
1608 command synopsis (*note Synopsis::).  There are numerous options, and
1609 many styles for writing them.  One mandatory option specifies the
1610 operation `tar' should perform (*note Operation Summary::), other
1611 options are meant to detail how this operation should be performed
1612 (*note Option Summary::).  Non-option arguments are not always
1613 interpreted the same way, depending on what the operation is.
1614
1615    You will find in this chapter everything about option styles and
1616 rules for writing them (*note Styles::).  On the other hand, operations
1617 and options are fully described elsewhere, in other chapters.  Here,
1618 you will find only synthetic descriptions for operations and options,
1619 together with pointers to other parts of the `tar' manual.
1620
1621    Some options are so special they are fully described right in this
1622 chapter.  They have the effect of inhibiting the normal operation of
1623 `tar' or else, they globally alter the amount of feedback the user
1624 receives about what is going on.  These are the `--help' and
1625 `--version' (*note help::), `--verbose' (*note verbose::) and
1626 `--interactive' options (*note interactive::).
1627
1628 * Menu:
1629
1630 * Synopsis::
1631 * using tar options::
1632 * Styles::
1633 * All Options::
1634 * help::
1635 * defaults::
1636 * verbose::
1637 * checkpoints::
1638 * warnings::
1639 * interactive::
1640
1641 \1f
1642 File: tar.info,  Node: Synopsis,  Next: using tar options,  Up: tar invocation
1643
1644 3.1 General Synopsis of `tar'
1645 =============================
1646
1647 The GNU `tar' program is invoked as either one of:
1648
1649      tar OPTION... [NAME]...
1650      tar LETTER... [ARGUMENT]... [OPTION]... [NAME]...
1651
1652    The second form is for when old options are being used.
1653
1654    You can use `tar' to store files in an archive, to extract them from
1655 an archive, and to do other types of archive manipulation.  The primary
1656 argument to `tar', which is called the "operation", specifies which
1657 action to take.  The other arguments to `tar' are either "options",
1658 which change the way `tar' performs an operation, or file names or
1659 archive members, which specify the files or members `tar' is to act on.
1660
1661    You can actually type in arguments in any order, even if in this
1662 manual the options always precede the other arguments, to make examples
1663 easier to understand.  Further, the option stating the main operation
1664 mode (the `tar' main command) is usually given first.
1665
1666    Each NAME in the synopsis above is interpreted as an archive member
1667 name when the main command is one of `--compare' (`--diff', `-d'),
1668 `--delete', `--extract' (`--get', `-x'), `--list' (`-t') or `--update'
1669 (`-u').  When naming archive members, you must give the exact name of
1670 the member in the archive, as it is printed by `--list'.  For
1671 `--append' (`-r') and `--create' (`-c'), these NAME arguments specify
1672 the names of either files or directory hierarchies to place in the
1673 archive.  These files or hierarchies should already exist in the file
1674 system, prior to the execution of the `tar' command.
1675
1676    `tar' interprets relative file names as being relative to the
1677 working directory.  `tar' will make all file names relative (by
1678 removing leading slashes when archiving or restoring files), unless you
1679 specify otherwise (using the `--absolute-names' option).  *Note
1680 absolute::, for more information about `--absolute-names'.
1681
1682    If you give the name of a directory as either a file name or a member
1683 name, then `tar' acts recursively on all the files and directories
1684 beneath that directory.  For example, the name `/' identifies all the
1685 files in the file system to `tar'.
1686
1687    The distinction between file names and archive member names is
1688 especially important when shell globbing is used, and sometimes a
1689 source of confusion for newcomers.  *Note wildcards::, for more
1690 information about globbing.  The problem is that shells may only glob
1691 using existing files in the file system.  Only `tar' itself may glob on
1692 archive members, so when needed, you must ensure that wildcard
1693 characters reach `tar' without being interpreted by the shell first.
1694 Using a backslash before `*' or `?', or putting the whole argument
1695 between quotes, is usually sufficient for this.
1696
1697    Even if NAMEs are often specified on the command line, they can also
1698 be read from a text file in the file system, using the
1699 `--files-from=FILE-OF-NAMES' (`-T FILE-OF-NAMES') option.
1700
1701    If you don't use any file name arguments, `--append' (`-r'),
1702 `--delete' and `--concatenate' (`--catenate', `-A') will do nothing,
1703 while `--create' (`-c') will usually yield a diagnostic and inhibit
1704 `tar' execution.  The other operations of `tar' (`--list', `--extract',
1705 `--compare', and `--update') will act on the entire contents of the
1706 archive.
1707
1708    Besides successful exits, GNU `tar' may fail for many reasons.  Some
1709 reasons correspond to bad usage, that is, when the `tar' command line
1710 is improperly written.  Errors may be encountered later, while
1711 processing the archive or the files.  Some errors are recoverable, in
1712 which case the failure is delayed until `tar' has completed all its
1713 work.  Some errors are such that it would be not meaningful, or at
1714 least risky, to continue processing: `tar' then aborts processing
1715 immediately.  All abnormal exits, whether immediate or delayed, should
1716 always be clearly diagnosed on `stderr', after a line stating the
1717 nature of the error.
1718
1719    Possible exit codes of GNU `tar' are summarized in the following
1720 table:
1721
1722 0
1723      `Successful termination'.
1724
1725 1
1726      `Some files differ'.  If tar was invoked with `--compare'
1727      (`--diff', `-d') command line option, this means that some files
1728      in the archive differ from their disk counterparts (*note
1729      compare::).  If tar was given `--create', `--append' or `--update'
1730      option, this exit code means that some files were changed while
1731      being archived and so the resulting archive does not contain the
1732      exact copy of the file set.
1733
1734 2
1735      `Fatal error'.  This means that some fatal, unrecoverable error
1736      occurred.
1737
1738    If `tar' has invoked a subprocess and that subprocess exited with a
1739 nonzero exit code, `tar' exits with that code as well.  This can
1740 happen, for example, if `tar' was given some compression option (*note
1741 gzip::) and the external compressor program failed.  Another example is
1742 `rmt' failure during backup to the remote device (*note Remote Tape
1743 Server::).
1744
1745 \1f
1746 File: tar.info,  Node: using tar options,  Next: Styles,  Prev: Synopsis,  Up: tar invocation
1747
1748 3.2 Using `tar' Options
1749 =======================
1750
1751 GNU `tar' has a total of eight operating modes which allow you to
1752 perform a variety of tasks.  You are required to choose one operating
1753 mode each time you employ the `tar' program by specifying one, and only
1754 one operation as an argument to the `tar' command (the corresponding
1755 options may be found at *note frequent operations:: and *note
1756 Operations::).  Depending on circumstances, you may also wish to
1757 customize how the chosen operating mode behaves.  For example, you may
1758 wish to change the way the output looks, or the format of the files
1759 that you wish to archive may require you to do something special in
1760 order to make the archive look right.
1761
1762    You can customize and control `tar''s performance by running `tar'
1763 with one or more options (such as `--verbose' (`-v'), which we used in
1764 the tutorial).  As we said in the tutorial, "options" are arguments to
1765 `tar' which are (as their name suggests) optional. Depending on the
1766 operating mode, you may specify one or more options. Different options
1767 will have different effects, but in general they all change details of
1768 the operation, such as archive format, archive name, or level of user
1769 interaction.  Some options make sense with all operating modes, while
1770 others are meaningful only with particular modes. You will likely use
1771 some options frequently, while you will only use others infrequently, or
1772 not at all.  (A full list of options is available in *note All
1773 Options::.)
1774
1775    The `TAR_OPTIONS' environment variable specifies default options to
1776 be placed in front of any explicit options.  For example, if
1777 `TAR_OPTIONS' is `-v --unlink-first', `tar' behaves as if the two
1778 options `-v' and `--unlink-first' had been specified before any
1779 explicit options.  Option specifications are separated by whitespace.
1780 A backslash escapes the next character, so it can be used to specify an
1781 option containing whitespace or a backslash.
1782
1783    Note that `tar' options are case sensitive.  For example, the
1784 options `-T' and `-t' are different; the first requires an argument for
1785 stating the name of a file providing a list of NAMEs, while the second
1786 does not require an argument and is another way to write `--list'
1787 (`-t').
1788
1789    In addition to the eight operations, there are many options to
1790 `tar', and three different styles for writing both: long (mnemonic)
1791 form, short form, and old style.  These styles are discussed below.
1792 Both the options and the operations can be written in any of these three
1793 styles.
1794
1795 \1f
1796 File: tar.info,  Node: Styles,  Next: All Options,  Prev: using tar options,  Up: tar invocation
1797
1798 3.3 The Three Option Styles
1799 ===========================
1800
1801 There are three styles for writing operations and options to the command
1802 line invoking `tar'.  The different styles were developed at different
1803 times during the history of `tar'.  These styles will be presented
1804 below, from the most recent to the oldest.
1805
1806    Some options must take an argument(1).  Where you _place_ the
1807 arguments generally depends on which style of options you choose.  We
1808 will detail specific information relevant to each option style in the
1809 sections on the different option styles, below.  The differences are
1810 subtle, yet can often be very important; incorrect option placement can
1811 cause you to overwrite a number of important files.  We urge you to
1812 note these differences, and only use the option style(s) which makes
1813 the most sense to you until you feel comfortable with the others.
1814
1815    Some options _may_ take an argument.  Such options may have at most
1816 long and short forms, they do not have old style equivalent.  The rules
1817 for specifying an argument for such options are stricter than those for
1818 specifying mandatory arguments.  Please, pay special attention to them.
1819
1820 * Menu:
1821
1822 * Long Options::                Long Option Style
1823 * Short Options::               Short Option Style
1824 * Old Options::                 Old Option Style
1825 * Mixing::                      Mixing Option Styles
1826
1827    ---------- Footnotes ----------
1828
1829    (1) For example, `--file' (`-f') takes the name of an archive file
1830 as an argument.  If you do not supply an archive file name, `tar' will
1831 use a default, but this can be confusing; thus, we recommend that you
1832 always supply a specific archive file name.
1833
1834 \1f
1835 File: tar.info,  Node: Long Options,  Next: Short Options,  Up: Styles
1836
1837 3.3.1 Long Option Style
1838 -----------------------
1839
1840 Each option has at least one "long" (or "mnemonic") name starting with
1841 two dashes in a row, e.g., `--list'.  The long names are more clear than
1842 their corresponding short or old names.  It sometimes happens that a
1843 single long option has many different names which are synonymous, such
1844 as `--compare' and `--diff'.  In addition, long option names can be
1845 given unique abbreviations.  For example, `--cre' can be used in place
1846 of `--create' because there is no other long option which begins with
1847 `cre'.  (One way to find this out is by trying it and seeing what
1848 happens; if a particular abbreviation could represent more than one
1849 option, `tar' will tell you that that abbreviation is ambiguous and
1850 you'll know that that abbreviation won't work.  You may also choose to
1851 run `tar --help' to see a list of options.  Be aware that if you run
1852 `tar' with a unique abbreviation for the long name of an option you
1853 didn't want to use, you are stuck; `tar' will perform the command as
1854 ordered.)
1855
1856    Long options are meant to be obvious and easy to remember, and their
1857 meanings are generally easier to discern than those of their
1858 corresponding short options (see below).  For example:
1859
1860      $ tar --create --verbose --blocking-factor=20 --file=/dev/rmt0
1861
1862 gives a fairly good set of hints about what the command does, even for
1863 those not fully acquainted with `tar'.
1864
1865    Long options which require arguments take those arguments
1866 immediately following the option name.  There are two ways of
1867 specifying a mandatory argument.  It can be separated from the option
1868 name either by an equal sign, or by any amount of white space
1869 characters.  For example, the `--file' option (which tells the name of
1870 the `tar' archive) is given a file such as `archive.tar' as argument by
1871 using any of the following notations: `--file=archive.tar' or `--file
1872 archive.tar'.
1873
1874    In contrast, optional arguments must always be introduced using an
1875 equal sign.  For example, the `--backup' option takes an optional
1876 argument specifying backup type.  It must be used as
1877 `--backup=BACKUP-TYPE'.
1878
1879 \1f
1880 File: tar.info,  Node: Short Options,  Next: Old Options,  Prev: Long Options,  Up: Styles
1881
1882 3.3.2 Short Option Style
1883 ------------------------
1884
1885 Most options also have a "short option" name.  Short options start with
1886 a single dash, and are followed by a single character, e.g., `-t'
1887 (which is equivalent to `--list').  The forms are absolutely identical
1888 in function; they are interchangeable.
1889
1890    The short option names are faster to type than long option names.
1891
1892    Short options which require arguments take their arguments
1893 immediately following the option, usually separated by white space.  It
1894 is also possible to stick the argument right after the short option
1895 name, using no intervening space.  For example, you might write
1896 `-f archive.tar' or `-farchive.tar' instead of using
1897 `--file=archive.tar'.  Both `--file=ARCHIVE-NAME' and `-f ARCHIVE-NAME'
1898 denote the option which indicates a specific archive, here named
1899 `archive.tar'.
1900
1901    Short options which take optional arguments take their arguments
1902 immediately following the option letter, _without any intervening white
1903 space characters_.
1904
1905    Short options' letters may be clumped together, but you are not
1906 required to do this (as compared to old options; see below).  When
1907 short options are clumped as a set, use one (single) dash for them all,
1908 e.g., ``tar' -cvf'.  Only the last option in such a set is allowed to
1909 have an argument(1).
1910
1911    When the options are separated, the argument for each option which
1912 requires an argument directly follows that option, as is usual for Unix
1913 programs.  For example:
1914
1915      $ tar -c -v -b 20 -f /dev/rmt0
1916
1917    If you reorder short options' locations, be sure to move any
1918 arguments that belong to them.  If you do not move the arguments
1919 properly, you may end up overwriting files.
1920
1921    ---------- Footnotes ----------
1922
1923    (1) Clustering many options, the last of which has an argument, is a
1924 rather opaque way to write options.  Some wonder if GNU `getopt' should
1925 not even be made helpful enough for considering such usages as invalid.
1926
1927 \1f
1928 File: tar.info,  Node: Old Options,  Next: Mixing,  Prev: Short Options,  Up: Styles
1929
1930 3.3.3 Old Option Style
1931 ----------------------
1932
1933 Like short options, "old options" are single letters.  However, old
1934 options must be written together as a single clumped set, without
1935 spaces separating them or dashes preceding them(1).  This set of
1936 letters must be the first to appear on the command line, after the
1937 `tar' program name and some white space; old options cannot appear
1938 anywhere else.  The letter of an old option is exactly the same letter
1939 as the corresponding short option.  For example, the old option `t' is
1940 the same as the short option `-t', and consequently, the same as the
1941 long option `--list'.  So for example, the command `tar cv' specifies
1942 the option `-v' in addition to the operation `-c'.
1943
1944    When options that need arguments are given together with the command,
1945 all the associated arguments follow, in the same order as the options.
1946 Thus, the example given previously could also be written in the old
1947 style as follows:
1948
1949      $ tar cvbf 20 /dev/rmt0
1950
1951 Here, `20' is the argument of `-b' and `/dev/rmt0' is the argument of
1952 `-f'.
1953
1954    On the other hand, this old style syntax makes it difficult to match
1955 option letters with their corresponding arguments, and is often
1956 confusing.  In the command `tar cvbf 20 /dev/rmt0', for example, `20'
1957 is the argument for `-b', `/dev/rmt0' is the argument for `-f', and
1958 `-v' does not have a corresponding argument.  Even using short options
1959 like in `tar -c -v -b 20 -f /dev/rmt0' is clearer, putting all
1960 arguments next to the option they pertain to.
1961
1962    If you want to reorder the letters in the old option argument, be
1963 sure to reorder any corresponding argument appropriately.
1964
1965    This old way of writing `tar' options can surprise even experienced
1966 users.  For example, the two commands:
1967
1968      tar cfz archive.tar.gz file
1969      tar -cfz archive.tar.gz file
1970
1971 are quite different.  The first example uses `archive.tar.gz' as the
1972 value for option `f' and recognizes the option `z'.  The second
1973 example, however, uses `z' as the value for option `f' -- probably not
1974 what was intended.
1975
1976    Old options are kept for compatibility with old versions of `tar'.
1977
1978    This second example could be corrected in many ways, among which the
1979 following are equivalent:
1980
1981      tar -czf archive.tar.gz file
1982      tar -cf archive.tar.gz -z file
1983      tar cf archive.tar.gz -z file
1984
1985    As far as we know, all `tar' programs, GNU and non-GNU, support old
1986 options.  GNU `tar' supports them not only for historical reasons, but
1987 also because many people are used to them.  For compatibility with Unix
1988 `tar', the first argument is always treated as containing command and
1989 option letters even if it doesn't start with `-'.  Thus, `tar c' is
1990 equivalent to `tar -c': both of them specify the `--create' (`-c')
1991 command to create an archive.
1992
1993    ---------- Footnotes ----------
1994
1995    (1) Beware that if you precede options with a dash, you are
1996 announcing the short option style instead of the old option style;
1997 short options are decoded differently.
1998
1999 \1f
2000 File: tar.info,  Node: Mixing,  Prev: Old Options,  Up: Styles
2001
2002 3.3.4 Mixing Option Styles
2003 --------------------------
2004
2005 All three styles may be intermixed in a single `tar' command, so long
2006 as the rules for each style are fully respected(1).  Old style options
2007 and either of the modern styles of options may be mixed within a single
2008 `tar' command.  However, old style options must be introduced as the
2009 first arguments only, following the rule for old options (old options
2010 must appear directly after the `tar' command and some white space).
2011 Modern options may be given only after all arguments to the old options
2012 have been collected.  If this rule is not respected, a modern option
2013 might be falsely interpreted as the value of the argument to one of the
2014 old style options.
2015
2016    For example, all the following commands are wholly equivalent, and
2017 illustrate the many combinations and orderings of option styles.
2018
2019      tar --create --file=archive.tar
2020      tar --create -f archive.tar
2021      tar --create -farchive.tar
2022      tar --file=archive.tar --create
2023      tar --file=archive.tar -c
2024      tar -c --file=archive.tar
2025      tar -c -f archive.tar
2026      tar -c -farchive.tar
2027      tar -cf archive.tar
2028      tar -cfarchive.tar
2029      tar -f archive.tar --create
2030      tar -f archive.tar -c
2031      tar -farchive.tar --create
2032      tar -farchive.tar -c
2033      tar c --file=archive.tar
2034      tar c -f archive.tar
2035      tar c -farchive.tar
2036      tar cf archive.tar
2037      tar f archive.tar --create
2038      tar f archive.tar -c
2039      tar fc archive.tar
2040
2041    On the other hand, the following commands are _not_ equivalent to
2042 the previous set:
2043
2044      tar -f -c archive.tar
2045      tar -fc archive.tar
2046      tar -fcarchive.tar
2047      tar -farchive.tarc
2048      tar cfarchive.tar
2049
2050 These last examples mean something completely different from what the
2051 user intended (judging based on the example in the previous set which
2052 uses long options, whose intent is therefore very clear).  The first
2053 four specify that the `tar' archive would be a file named `-c', `c',
2054 `carchive.tar' or `archive.tarc', respectively.  The first two examples
2055 also specify a single non-option, NAME argument having the value
2056 `archive.tar'.  The last example contains only old style option letters
2057 (repeating option `c' twice), not all of which are meaningful (eg., `.',
2058 `h', or `i'), with no argument value.
2059
2060    ---------- Footnotes ----------
2061
2062    (1) Before GNU `tar' version 1.11.6, a bug prevented intermixing old
2063 style options with long options in some cases.
2064
2065 \1f
2066 File: tar.info,  Node: All Options,  Next: help,  Prev: Styles,  Up: tar invocation
2067
2068 3.4 All `tar' Options
2069 =====================
2070
2071 The coming manual sections contain an alphabetical listing of all `tar'
2072 operations and options, with brief descriptions and cross-references to
2073 more in-depth explanations in the body of the manual.  They also
2074 contain an alphabetically arranged table of the short option forms with
2075 their corresponding long option.  You can use this table as a reference
2076 for deciphering `tar' commands in scripts.
2077
2078 * Menu:
2079
2080 * Operation Summary::
2081 * Option Summary::
2082 * Short Option Summary::
2083
2084 \1f
2085 File: tar.info,  Node: Operation Summary,  Next: Option Summary,  Up: All Options
2086
2087 3.4.1 Operations
2088 ----------------
2089
2090 `--append'
2091 `-r'
2092      Appends files to the end of the archive.  *Note append::.
2093
2094 `--catenate'
2095 `-A'
2096      Same as `--concatenate'.  *Note concatenate::.
2097
2098 `--compare'
2099 `-d'
2100      Compares archive members with their counterparts in the file
2101      system, and reports differences in file size, mode, owner,
2102      modification date and contents.  *Note compare::.
2103
2104 `--concatenate'
2105 `-A'
2106      Appends other `tar' archives to the end of the archive.  *Note
2107      concatenate::.
2108
2109 `--create'
2110 `-c'
2111      Creates a new `tar' archive.  *Note create::.
2112
2113 `--delete'
2114      Deletes members from the archive.  Don't try this on an archive on
2115      a tape!  *Note delete::.
2116
2117 `--diff'
2118 `-d'
2119      Same `--compare'.  *Note compare::.
2120
2121 `--extract'
2122 `-x'
2123      Extracts members from the archive into the file system.  *Note
2124      extract::.
2125
2126 `--get'
2127 `-x'
2128      Same as `--extract'.  *Note extract::.
2129
2130 `--list'
2131 `-t'
2132      Lists the members in an archive.  *Note list::.
2133
2134 `--update'
2135 `-u'
2136      Adds files to the end of the archive, but only if they are newer
2137      than their counterparts already in the archive, or if they do not
2138      already exist in the archive. *Note update::.
2139
2140
2141 \1f
2142 File: tar.info,  Node: Option Summary,  Next: Short Option Summary,  Prev: Operation Summary,  Up: All Options
2143
2144 3.4.2 `tar' Options
2145 -------------------
2146
2147 `--absolute-names'
2148 `-P'
2149      Normally when creating an archive, `tar' strips an initial `/'
2150      from member names.  This option disables that behavior.  *Note
2151      absolute::.
2152
2153 `--after-date'
2154      (See `--newer', *note after::)
2155
2156 `--anchored'
2157      A pattern must match an initial subsequence of the name's
2158      components.  *Note controlling pattern-matching::.
2159
2160 `--atime-preserve'
2161 `--atime-preserve=replace'
2162 `--atime-preserve=system'
2163      Attempt to preserve the access time of files when reading them.
2164      This option currently is effective only on files that you own,
2165      unless you have superuser privileges.
2166
2167      `--atime-preserve=replace' remembers the access time of a file
2168      before reading it, and then restores the access time afterwards.
2169      This may cause problems if other programs are reading the file at
2170      the same time, as the times of their accesses will be lost.  On
2171      most platforms restoring the access time also requires `tar' to
2172      restore the data modification time too, so this option may also
2173      cause problems if other programs are writing the file at the same
2174      time (`tar' attempts to detect this situation, but cannot do so
2175      reliably due to race conditions).  Worse, on most platforms
2176      restoring the access time also updates the status change time,
2177      which means that this option is incompatible with incremental
2178      backups.
2179
2180      `--atime-preserve=system' avoids changing time stamps on files,
2181      without interfering with time stamp updates caused by other
2182      programs, so it works better with incremental backups.  However,
2183      it requires a special `O_NOATIME' option from the underlying
2184      operating and file system implementation, and it also requires
2185      that searching directories does not update their access times.  As
2186      of this writing (November 2005) this works only with Linux, and
2187      only with Linux kernels 2.6.8 and later.  Worse, there is
2188      currently no reliable way to know whether this feature actually
2189      works.  Sometimes `tar' knows that it does not work, and if you use
2190      `--atime-preserve=system' then `tar' complains and exits right
2191      away.  But other times `tar' might think that the option works
2192      when it actually does not.
2193
2194      Currently `--atime-preserve' with no operand defaults to
2195      `--atime-preserve=replace', but this may change in the future as
2196      support for `--atime-preserve=system' improves.
2197
2198      If your operating or file system does not support
2199      `--atime-preserve=system', you might be able to preserve access
2200      times reliably by using the `mount' command.  For example, you can
2201      mount the file system read-only, or access the file system via a
2202      read-only loopback mount, or use the `noatime' mount option
2203      available on some systems.  However, mounting typically requires
2204      superuser privileges and can be a pain to manage.
2205
2206 `--auto-compress'
2207 `-a'
2208      During a `--create' operation, enables automatic compressed format
2209      recognition based on the archive suffix.  The effect of this
2210      option is cancelled by `--no-auto-compress'.  *Note gzip::.
2211
2212 `--backup=BACKUP-TYPE'
2213      Rather than deleting files from the file system, `tar' will back
2214      them up using simple or numbered backups, depending upon
2215      BACKUP-TYPE.  *Note backup::.
2216
2217 `--block-number'
2218 `-R'
2219      With this option present, `tar' prints error messages for read
2220      errors with the block number in the archive file.  *Note
2221      block-number::.
2222
2223 `--blocking-factor=BLOCKING'
2224 `-b BLOCKING'
2225      Sets the blocking factor `tar' uses to BLOCKING x 512 bytes per
2226      record.  *Note Blocking Factor::.
2227
2228 `--bzip2'
2229 `-j'
2230      This option tells `tar' to read or write archives through `bzip2'.
2231      *Note gzip::.
2232
2233 `--check-device'
2234      Check device numbers when creating a list of modified files for
2235      incremental archiving.  This is the default.  *Note device
2236      numbers::, for a detailed description.
2237
2238 `--checkpoint[=NUMBER]'
2239      This option directs `tar' to print periodic checkpoint messages as
2240      it reads through the archive.  It is intended for when you want a
2241      visual indication that `tar' is still running, but don't want to
2242      see `--verbose' output.  You can also instruct `tar' to execute a
2243      list of actions on each checkpoint, see `--checkpoint-action'
2244      below.  For a detailed description, see *note checkpoints::.
2245
2246 `--checkpoint-action=ACTION'
2247      Instruct `tar' to execute an action upon hitting a breakpoint.
2248      Here we give only a brief outline.  *Note checkpoints::, for a
2249      complete description.
2250
2251      The ACTION argument can be one of the following:
2252
2253     bell
2254           Produce an audible bell on the console.
2255
2256     dot
2257     .
2258           Print a single dot on the standard listing stream.
2259
2260     echo
2261           Display a textual message on the standard error, with the
2262           status and number of the checkpoint.  This is the default.
2263
2264     echo=STRING
2265           Display STRING on the standard error.  Before output, the
2266           string is subject to meta-character expansion.
2267
2268     exec=COMMAND
2269           Execute the given COMMAND.
2270
2271     sleep=TIME
2272           Wait for TIME seconds.
2273
2274     ttyout=STRING
2275           Output STRING on the current console (`/dev/tty').
2276
2277      Several `--checkpoint-action' options can be specified.  The
2278      supplied actions will be executed in order of their appearance in
2279      the command line.
2280
2281      Using `--checkpoint-action' without `--checkpoint' assumes default
2282      checkpoint frequency of one checkpoint per 10 records.
2283
2284 `--check-links'
2285 `-l'
2286      If this option was given, `tar' will check the number of links
2287      dumped for each processed file.  If this number does not match the
2288      total number of hard links for the file, a warning message will be
2289      output (1).
2290
2291      *Note hard links::.
2292
2293 `--compress'
2294 `--uncompress'
2295 `-Z'
2296      `tar' will use the `compress' program when reading or writing the
2297      archive.  This allows you to directly act on archives while saving
2298      space.  *Note gzip::.
2299
2300 `--confirmation'
2301      (See `--interactive'.)  *Note interactive::.
2302
2303 `--delay-directory-restore'
2304      Delay setting modification times and permissions of extracted
2305      directories until the end of extraction. *Note Directory
2306      Modification Times and Permissions::.
2307
2308 `--dereference'
2309 `-h'
2310      When reading or writing a file to be archived, `tar' accesses the
2311      file that a symbolic link points to, rather than the symlink
2312      itself.  *Note dereference::.
2313
2314 `--directory=DIR'
2315 `-C DIR'
2316      When this option is specified, `tar' will change its current
2317      directory to DIR before performing any operations.  When this
2318      option is used during archive creation, it is order sensitive.
2319      *Note directory::.
2320
2321 `--exclude=PATTERN'
2322      When performing operations, `tar' will skip files that match
2323      PATTERN.  *Note exclude::.
2324
2325 `--exclude-backups'
2326      Exclude backup and lock files.  *Note exclude-backups: exclude.
2327
2328 `--exclude-from=FILE'
2329 `-X FILE'
2330      Similar to `--exclude', except `tar' will use the list of patterns
2331      in the file FILE.  *Note exclude::.
2332
2333 `--exclude-caches'
2334      Exclude from dump any directory containing a valid cache directory
2335      tag file, but still dump the directory node and the tag file
2336      itself.
2337
2338      *Note exclude-caches: exclude.
2339
2340 `--exclude-caches-under'
2341      Exclude from dump any directory containing a valid cache directory
2342      tag file, but still dump the directory node itself.
2343
2344      *Note exclude::.
2345
2346 `--exclude-caches-all'
2347      Exclude from dump any directory containing a valid cache directory
2348      tag file.  *Note exclude::.
2349
2350 `--exclude-tag=FILE'
2351      Exclude from dump any directory containing file named FILE, but
2352      dump the directory node and FILE itself.  *Note exclude-tag:
2353      exclude.
2354
2355 `--exclude-tag-under=FILE'
2356      Exclude from dump the contents of any directory containing file
2357      named FILE, but dump the directory node itself.  *Note
2358      exclude-tag-under: exclude.
2359
2360 `--exclude-tag-all=FILE'
2361      Exclude from dump any directory containing file named FILE.  *Note
2362      exclude-tag-all: exclude.
2363
2364 `--exclude-vcs'
2365      Exclude from dump directories and files, that are internal for some
2366      widely used version control systems.
2367
2368      *Note exclude-vcs: exclude.
2369
2370 `--file=ARCHIVE'
2371 `-f ARCHIVE'
2372      `tar' will use the file ARCHIVE as the `tar' archive it performs
2373      operations on, rather than `tar''s compilation dependent default.
2374      *Note file tutorial::.
2375
2376 `--files-from=FILE'
2377 `-T FILE'
2378      `tar' will use the contents of FILE as a list of archive members
2379      or files to operate on, in addition to those specified on the
2380      command-line.  *Note files::.
2381
2382 `--force-local'
2383      Forces `tar' to interpret the file name given to `--file' as a
2384      local file, even if it looks like a remote tape drive name.  *Note
2385      local and remote archives::.
2386
2387 `--format=FORMAT'
2388 `-H FORMAT'
2389      Selects output archive format.  FORMAT may be one of the following:
2390
2391     `v7'
2392           Creates an archive that is compatible with Unix V7 `tar'.
2393
2394     `oldgnu'
2395           Creates an archive that is compatible with GNU `tar' version
2396           1.12 or earlier.
2397
2398     `gnu'
2399           Creates archive in GNU tar 1.13 format.  Basically it is the
2400           same as `oldgnu' with the only difference in the way it
2401           handles long numeric fields.
2402
2403     `ustar'
2404           Creates a POSIX.1-1988 compatible archive.
2405
2406     `posix'
2407           Creates a POSIX.1-2001 archive.
2408
2409
2410      *Note Formats::, for a detailed discussion of these formats.
2411
2412 `--full-time'
2413      This option instructs `tar' to print file times to their full
2414      resolution.  Usually this means 1-second resolution, but that
2415      depends on the underlying file system.  The `--full-time' option
2416      takes effect only when detailed output (verbosity level 2 or
2417      higher) has been requested using the `--verbose' option, e.g.,
2418      when listing or extracting archives:
2419
2420           $ tar -t -v --full-time -f archive.tar
2421
2422      or, when creating an archive:
2423
2424           $ tar -c -vv --full-time -f archive.tar .
2425
2426      Notice, thar when creating the archive you need to specify
2427      `--verbose' twice to get a detailed output (*note verbose
2428      tutorial::).
2429
2430 `--group=GROUP'
2431      Files added to the `tar' archive will have a group ID of GROUP,
2432      rather than the group from the source file.  GROUP is first decoded
2433      as a group symbolic name, but if this interpretation fails, it has
2434      to be a decimal numeric group ID.  *Note override::.
2435
2436      Also see the comments for the `--owner=USER' option.
2437
2438 `--gzip'
2439 `--gunzip'
2440 `--ungzip'
2441 `-z'
2442      This option tells `tar' to read or write archives through `gzip',
2443      allowing `tar' to directly operate on several kinds of compressed
2444      archives transparently.  *Note gzip::.
2445
2446 `--hard-dereference'
2447      When creating an archive, dereference hard links and store the
2448      files they refer to, instead of creating usual hard link members.
2449
2450      *Note hard links::.
2451
2452 `--help'
2453 `-?'
2454      `tar' will print out a short message summarizing the operations and
2455      options to `tar' and exit. *Note help::.
2456
2457 `--ignore-case'
2458      Ignore case when matching member or file names with patterns.
2459      *Note controlling pattern-matching::.
2460
2461 `--ignore-command-error'
2462      Ignore exit codes of subprocesses. *Note Writing to an External
2463      Program::.
2464
2465 `--ignore-failed-read'
2466      Do not exit unsuccessfully merely because an unreadable file was
2467      encountered.  *Note Reading::.
2468
2469 `--ignore-zeros'
2470 `-i'
2471      With this option, `tar' will ignore zeroed blocks in the archive,
2472      which normally signals EOF.  *Note Reading::.
2473
2474 `--incremental'
2475 `-G'
2476      Informs `tar' that it is working with an old GNU-format
2477      incremental backup archive.  It is intended primarily for
2478      backwards compatibility only.  *Note Incremental Dumps::, for a
2479      detailed discussion of incremental archives.
2480
2481 `--index-file=FILE'
2482      Send verbose output to FILE instead of to standard output.
2483
2484 `--info-script=SCRIPT-FILE'
2485 `--new-volume-script=SCRIPT-FILE'
2486 `-F SCRIPT-FILE'
2487      When `tar' is performing multi-tape backups, SCRIPT-FILE is run at
2488      the end of each tape.  If SCRIPT-FILE exits with nonzero status,
2489      `tar' fails immediately.  *Note info-script::, for a detailed
2490      discussion of SCRIPT-FILE.
2491
2492 `--interactive'
2493 `--confirmation'
2494 `-w'
2495      Specifies that `tar' should ask the user for confirmation before
2496      performing potentially destructive options, such as overwriting
2497      files.  *Note interactive::.
2498
2499 `--keep-newer-files'
2500      Do not replace existing files that are newer than their archive
2501      copies when extracting files from an archive.
2502
2503 `--keep-old-files'
2504 `-k'
2505      Do not overwrite existing files when extracting files from an
2506      archive.  *Note Keep Old Files::.
2507
2508 `--label=NAME'
2509 `-V NAME'
2510      When creating an archive, instructs `tar' to write NAME as a name
2511      record in the archive.  When extracting or listing archives, `tar'
2512      will only operate on archives that have a label matching the
2513      pattern specified in NAME.  *Note Tape Files::.
2514
2515 `--level=N'
2516      Force incremental backup of level N.  As of GNU `tar' version
2517      1.25, the option `--level=0' truncates the snapshot file, thereby
2518      forcing the level 0 dump.  Other values of N are effectively
2519      ignored.  *Note --level=0::, for details and examples.
2520
2521      The use of this option is valid only in conjunction with the
2522      `--listed-incremental' option.  *Note Incremental Dumps::, for a
2523      detailed description.
2524
2525 `--listed-incremental=SNAPSHOT-FILE'
2526 `-g SNAPSHOT-FILE'
2527      During a `--create' operation, specifies that the archive that
2528      `tar' creates is a new GNU-format incremental backup, using
2529      SNAPSHOT-FILE to determine which files to backup.  With other
2530      operations, informs `tar' that the archive is in incremental
2531      format.  *Note Incremental Dumps::.
2532
2533 `--lzip'
2534      This option tells `tar' to read or write archives through `lzip'.
2535      *Note gzip::.
2536
2537 `--lzma'
2538      This option tells `tar' to read or write archives through `lzma'.
2539      *Note gzip::.
2540
2541 `--lzop'
2542      This option tells `tar' to read or write archives through `lzop'.
2543      *Note gzip::.
2544
2545 `--mode=PERMISSIONS'
2546      When adding files to an archive, `tar' will use PERMISSIONS for
2547      the archive members, rather than the permissions from the files.
2548      PERMISSIONS can be specified either as an octal number or as
2549      symbolic permissions, like with `chmod'. *Note override::.
2550
2551 `--mtime=DATE'
2552      When adding files to an archive, `tar' will use DATE as the
2553      modification time of members when creating archives, instead of
2554      their actual modification times.  The value of DATE can be either
2555      a textual date representation (*note Date input formats::) or a
2556      name of the existing file, starting with `/' or `.'.  In the
2557      latter case, the modification time of that file is used. *Note
2558      override::.
2559
2560 `--multi-volume'
2561 `-M'
2562      Informs `tar' that it should create or otherwise operate on a
2563      multi-volume `tar' archive.  *Note Using Multiple Tapes::.
2564
2565 `--new-volume-script'
2566      (see `--info-script')
2567
2568 `--newer=DATE'
2569 `--after-date=DATE'
2570 `-N'
2571      When creating an archive, `tar' will only add files that have
2572      changed since DATE.  If DATE begins with `/' or `.', it is taken
2573      to be the name of a file whose data modification time specifies
2574      the date.  *Note after::.
2575
2576 `--newer-mtime=DATE'
2577      Like `--newer', but add only files whose contents have changed (as
2578      opposed to just `--newer', which will also back up files for which
2579      any status information has changed).  *Note after::.
2580
2581 `--no-anchored'
2582      An exclude pattern can match any subsequence of the name's
2583      components.  *Note controlling pattern-matching::.
2584
2585 `--no-auto-compress'
2586      Disables automatic compressed format recognition based on the
2587      archive suffix.  *Note --auto-compress::.  *Note gzip::.
2588
2589 `--no-check-device'
2590      Do not check device numbers when creating a list of modified files
2591      for incremental archiving.  *Note device numbers::, for a detailed
2592      description.
2593
2594 `--no-delay-directory-restore'
2595      Modification times and permissions of extracted directories are
2596      set when all files from this directory have been extracted.  This
2597      is the default.  *Note Directory Modification Times and
2598      Permissions::.
2599
2600 `--no-ignore-case'
2601      Use case-sensitive matching.  *Note controlling pattern-matching::.
2602
2603 `--no-ignore-command-error'
2604      Print warnings about subprocesses that terminated with a nonzero
2605      exit code. *Note Writing to an External Program::.
2606
2607 `--no-null'
2608      If the `--null' option was given previously, this option cancels
2609      its effect, so that any following `--files-from' options will
2610      expect their file lists to be newline-terminated.
2611
2612 `--no-overwrite-dir'
2613      Preserve metadata of existing directories when extracting files
2614      from an archive.  *Note Overwrite Old Files::.
2615
2616 `--no-quote-chars=STRING'
2617      Remove characters listed in STRING from the list of quoted
2618      characters set by the previous `--quote-chars' option (*note
2619      quoting styles::).
2620
2621 `--no-recursion'
2622      With this option, `tar' will not recurse into directories.  *Note
2623      recurse::.
2624
2625 `--no-same-owner'
2626 `-o'
2627      When extracting an archive, do not attempt to preserve the owner
2628      specified in the `tar' archive.  This the default behavior for
2629      ordinary users.
2630
2631 `--no-same-permissions'
2632      When extracting an archive, subtract the user's umask from files
2633      from the permissions specified in the archive.  This is the
2634      default behavior for ordinary users.
2635
2636 `--no-seek'
2637      The archive media does not support seeks to arbitrary locations.
2638      Usually `tar' determines automatically whether the archive can be
2639      seeked or not.  Use this option to disable this mechanism.
2640
2641 `--no-unquote'
2642      Treat all input file or member names literally, do not interpret
2643      escape sequences.  *Note input name quoting::.
2644
2645 `--no-wildcards'
2646      Do not use wildcards.  *Note controlling pattern-matching::.
2647
2648 `--no-wildcards-match-slash'
2649      Wildcards do not match `/'.  *Note controlling pattern-matching::.
2650
2651 `--null'
2652      When `tar' is using the `--files-from' option, this option
2653      instructs `tar' to expect file names terminated with NUL, so `tar'
2654      can correctly work with file names that contain newlines.  *Note
2655      nul::.
2656
2657 `--numeric-owner'
2658      This option will notify `tar' that it should use numeric user and
2659      group IDs when creating a `tar' file, rather than names.  *Note
2660      Attributes::.
2661
2662 `-o'
2663      The function of this option depends on the action `tar' is
2664      performing.  When extracting files, `-o' is a synonym for
2665      `--no-same-owner', i.e., it prevents `tar' from restoring
2666      ownership of files being extracted.
2667
2668      When creating an archive, it is a synonym for `--old-archive'.
2669      This behavior is for compatibility with previous versions of GNU
2670      `tar', and will be removed in future releases.
2671
2672      *Note Changes::, for more information.
2673
2674 `--occurrence[=NUMBER]'
2675      This option can be used in conjunction with one of the subcommands
2676      `--delete', `--diff', `--extract' or `--list' when a list of files
2677      is given either on the command line or via `-T' option.
2678
2679      This option instructs `tar' to process only the NUMBERth
2680      occurrence of each named file.  NUMBER defaults to 1, so
2681
2682           tar -x -f archive.tar --occurrence filename
2683
2684      will extract the first occurrence of the member `filename' from
2685      `archive.tar' and will terminate without scanning to the end of
2686      the archive.
2687
2688 `--old-archive'
2689      Synonym for `--format=v7'.
2690
2691 `--one-file-system'
2692      Used when creating an archive.  Prevents `tar' from recursing into
2693      directories that are on different file systems from the current
2694      directory.
2695
2696 `--overwrite'
2697      Overwrite existing files and directory metadata when extracting
2698      files from an archive.  *Note Overwrite Old Files::.
2699
2700 `--overwrite-dir'
2701      Overwrite the metadata of existing directories when extracting
2702      files from an archive.  *Note Overwrite Old Files::.
2703
2704 `--owner=USER'
2705      Specifies that `tar' should use USER as the owner of members when
2706      creating archives, instead of the user associated with the source
2707      file.  USER is first decoded as a user symbolic name, but if this
2708      interpretation fails, it has to be a decimal numeric user ID.
2709      *Note override::.
2710
2711      This option does not affect extraction from archives.
2712
2713 `--pax-option=KEYWORD-LIST'
2714      This option enables creation of the archive in POSIX.1-2001 format
2715      (*note posix::) and modifies the way `tar' handles the extended
2716      header keywords.  KEYWORD-LIST is a comma-separated list of
2717      keyword options.  *Note PAX keywords::, for a detailed discussion.
2718
2719 `--portability'
2720 `--old-archive'
2721      Synonym for `--format=v7'.
2722
2723 `--posix'
2724      Same as `--format=posix'.
2725
2726 `--preserve'
2727      Synonymous with specifying both `--preserve-permissions' and
2728      `--same-order'.  *Note Setting Access Permissions::.
2729
2730 `--preserve-order'
2731      (See `--same-order'; *note Reading::.)
2732
2733 `--preserve-permissions'
2734 `--same-permissions'
2735 `-p'
2736      When `tar' is extracting an archive, it normally subtracts the
2737      users' umask from the permissions specified in the archive and uses
2738      that number as the permissions to create the destination file.
2739      Specifying this option instructs `tar' that it should use the
2740      permissions directly from the archive.  *Note Setting Access
2741      Permissions::.
2742
2743 `--quote-chars=STRING'
2744      Always quote characters from STRING, even if the selected quoting
2745      style would not quote them (*note quoting styles::).
2746
2747 `--quoting-style=STYLE'
2748      Set quoting style to use when printing member and file names
2749      (*note quoting styles::). Valid STYLE values are: `literal',
2750      `shell', `shell-always', `c', `escape', `locale', and `clocale'.
2751      Default quoting style is `escape', unless overridden while
2752      configuring the package.
2753
2754 `--read-full-records'
2755 `-B'
2756      Specifies that `tar' should reblock its input, for reading from
2757      pipes on systems with buggy implementations.  *Note Reading::.
2758
2759 `--record-size=SIZE[SUF]'
2760      Instructs `tar' to use SIZE bytes per record when accessing the
2761      archive.  The argument can be suffixed with a "size suffix", e.g.
2762      `--record-size=10K' for 10 Kilobytes.  *Note size-suffixes::, for
2763      a list of valid suffixes.   *Note Blocking Factor::, for a detailed
2764      description of this option.
2765
2766 `--recursion'
2767      With this option, `tar' recurses into directories (default).
2768      *Note recurse::.
2769
2770 `--recursive-unlink'
2771      Remove existing directory hierarchies before extracting
2772      directories of the same name from the archive.  *Note Recursive
2773      Unlink::.
2774
2775 `--remove-files'
2776      Directs `tar' to remove the source file from the file system after
2777      appending it to an archive.  *Note remove files::.
2778
2779 `--restrict'
2780      Disable use of some potentially harmful `tar' options.  Currently
2781      this option disables shell invocation from multi-volume menu
2782      (*note Using Multiple Tapes::).
2783
2784 `--rmt-command=CMD'
2785      Notifies `tar' that it should use CMD instead of the default
2786      `/usr/libexec/rmt' (*note Remote Tape Server::).
2787
2788 `--rsh-command=CMD'
2789      Notifies `tar' that is should use CMD to communicate with remote
2790      devices.  *Note Device::.
2791
2792 `--same-order'
2793 `--preserve-order'
2794 `-s'
2795      This option is an optimization for `tar' when running on machines
2796      with small amounts of memory.  It informs `tar' that the list of
2797      file arguments has already been sorted to match the order of files
2798      in the archive.  *Note Reading::.
2799
2800 `--same-owner'
2801      When extracting an archive, `tar' will attempt to preserve the
2802      owner specified in the `tar' archive with this option present.
2803      This is the default behavior for the superuser; this option has an
2804      effect only for ordinary users.  *Note Attributes::.
2805
2806 `--same-permissions'
2807      (See `--preserve-permissions'; *note Setting Access Permissions::.)
2808
2809 `--seek'
2810 `-n'
2811      Assume that the archive media supports seeks to arbitrary
2812      locations.  Usually `tar' determines automatically whether the
2813      archive can be seeked or not.  This option is intended for use in
2814      cases when such recognition fails.  It takes effect only if the
2815      archive is open for reading (e.g. with `--list' or `--extract'
2816      options).
2817
2818 `--show-defaults'
2819      Displays the default options used by `tar' and exits successfully.
2820      This option is intended for use in shell scripts.  Here is an
2821      example of what you can see using this option:
2822
2823           $ tar --show-defaults
2824           --format=gnu -f- -b20 --quoting-style=escape
2825           --rmt-command=/usr/libexec/rmt --rsh-command=/usr/bin/rsh
2826
2827      Notice, that this option outputs only one line.  The example output
2828      above has been split to fit page boundaries.
2829
2830 `--show-omitted-dirs'
2831      Instructs `tar' to mention the directories it is skipping when
2832      operating on a `tar' archive.  *Note show-omitted-dirs::.
2833
2834 `--show-transformed-names'
2835 `--show-stored-names'
2836      Display file or member names after applying any transformations
2837      (*note transform::).  In particular, when used in conjunction with
2838      one of the archive creation operations it instructs `tar' to list
2839      the member names stored in the archive, as opposed to the actual
2840      file names.  *Note listing member and file names::.
2841
2842 `--sparse'
2843 `-S'
2844      Invokes a GNU extension when adding files to an archive that
2845      handles sparse files efficiently.  *Note sparse::.
2846
2847 `--sparse-version=VERSION'
2848      Specifies the "format version" to use when archiving sparse files.
2849      Implies `--sparse'.  *Note sparse::. For the description of the
2850      supported sparse formats, *Note Sparse Formats::.
2851
2852 `--starting-file=NAME'
2853 `-K NAME'
2854      This option affects extraction only; `tar' will skip extracting
2855      files in the archive until it finds one that matches NAME.  *Note
2856      Scarce::.
2857
2858 `--strip-components=NUMBER'
2859      Strip given NUMBER of leading components from file names before
2860      extraction.  For example, if archive `archive.tar' contained
2861      `/some/file/name', then running
2862
2863           tar --extract --file archive.tar --strip-components=2
2864
2865      would extract this file to file `name'.
2866
2867 `--suffix=SUFFIX'
2868      Alters the suffix `tar' uses when backing up files from the default
2869      `~'.  *Note backup::.
2870
2871 `--tape-length=NUM[SUF]'
2872 `-L NUM[SUF]'
2873      Specifies the length of tapes that `tar' is writing as being
2874      NUM x 1024 bytes long.  If optional SUF is given, it specifies a
2875      multiplicative factor to be used instead of 1024.  For example,
2876      `-L2M' means 2 megabytes.  *Note size-suffixes::, for a list of
2877      allowed suffixes.  *Note Using Multiple Tapes::, for a detailed
2878      discussion of this option.
2879
2880 `--test-label'
2881      Reads the volume label.  If an argument is specified, test whether
2882      it matches the volume label.  *Note --test-label option::.
2883
2884 `--to-command=COMMAND'
2885      During extraction `tar' will pipe extracted files to the standard
2886      input of COMMAND.  *Note Writing to an External Program::.
2887
2888 `--to-stdout'
2889 `-O'
2890      During extraction, `tar' will extract files to stdout rather than
2891      to the file system.  *Note Writing to Standard Output::.
2892
2893 `--totals[=SIGNO]'
2894      Displays the total number of bytes transferred when processing an
2895      archive.  If an argument is given, these data are displayed on
2896      request, when signal SIGNO is delivered to `tar'.  *Note totals::.
2897
2898 `--touch'
2899 `-m'
2900      Sets the data modification time of extracted files to the
2901      extraction time, rather than the data modification time stored in
2902      the archive.  *Note Data Modification Times::.
2903
2904 `--transform=SED-EXPR'
2905 `--xform=SED-EXPR'
2906      Transform file or member names using `sed' replacement expression
2907      SED-EXPR.  For example,
2908
2909           $ tar cf archive.tar --transform 's,^\./,usr/,' .
2910
2911      will add to `archive' files from the current working directory,
2912      replacing initial `./' prefix with `usr/'. For the detailed
2913      discussion, *Note transform::.
2914
2915      To see transformed member names in verbose listings, use
2916      `--show-transformed-names' option (*note show-transformed-names::).
2917
2918 `--uncompress'
2919      (See `--compress', *note gzip::)
2920
2921 `--ungzip'
2922      (See `--gzip', *note gzip::)
2923
2924 `--unlink-first'
2925 `-U'
2926      Directs `tar' to remove the corresponding file from the file
2927      system before extracting it from the archive.  *Note Unlink
2928      First::.
2929
2930 `--unquote'
2931      Enable unquoting input file or member names (default).  *Note
2932      input name quoting::.
2933
2934 `--use-compress-program=PROG'
2935 `-I=PROG'
2936      Instructs `tar' to access the archive through PROG, which is
2937      presumed to be a compression program of some sort.  *Note gzip::.
2938
2939 `--utc'
2940      Display file modification dates in UTC.  This option implies
2941      `--verbose'.
2942
2943 `--verbose'
2944 `-v'
2945      Specifies that `tar' should be more verbose about the operations
2946      it is performing.  This option can be specified multiple times for
2947      some operations to increase the amount of information displayed.
2948      *Note verbose::.
2949
2950 `--verify'
2951 `-W'
2952      Verifies that the archive was correctly written when creating an
2953      archive.  *Note verify::.
2954
2955 `--version'
2956      Print information about the program's name, version, origin and
2957      legal status, all on standard output, and then exit successfully.
2958      *Note help::.
2959
2960 `--volno-file=FILE'
2961      Used in conjunction with `--multi-volume'.  `tar' will keep track
2962      of which volume of a multi-volume archive it is working in FILE.
2963      *Note volno-file::.
2964
2965 `--warning=KEYWORD'
2966      Enable or disable warning messages identified by KEYWORD.  The
2967      messages are suppressed if KEYWORD is prefixed with `no-'.  *Note
2968      warnings::.
2969
2970 `--wildcards'
2971      Use wildcards when matching member names with patterns.  *Note
2972      controlling pattern-matching::.
2973
2974 `--wildcards-match-slash'
2975      Wildcards match `/'.  *Note controlling pattern-matching::.
2976
2977 `--xz'
2978 `-J'
2979      Use `xz' for compressing or decompressing the archives.  *Note
2980      gzip::.
2981
2982
2983    ---------- Footnotes ----------
2984
2985    (1) Earlier versions of GNU `tar' understood `-l' as a synonym for
2986 `--one-file-system'.  The current semantics, which complies to UNIX98,
2987 was introduced with version 1.15.91. *Note Changes::, for more
2988 information.
2989
2990 \1f
2991 File: tar.info,  Node: Short Option Summary,  Prev: Option Summary,  Up: All Options
2992
2993 3.4.3 Short Options Cross Reference
2994 -----------------------------------
2995
2996 Here is an alphabetized list of all of the short option forms, matching
2997 them with the equivalent long option.
2998
2999 Short Option   Reference
3000 -------------------------------------------------------------------------- 
3001 -A             *note --concatenate::.
3002 -B             *note --read-full-records::.
3003 -C             *note --directory::.
3004 -F             *note --info-script::.
3005 -G             *note --incremental::.
3006 -J             *note --xz::.
3007 -K             *note --starting-file::.
3008 -L             *note --tape-length::.
3009 -M             *note --multi-volume::.
3010 -N             *note --newer::.
3011 -O             *note --to-stdout::.
3012 -P             *note --absolute-names::.
3013 -R             *note --block-number::.
3014 -S             *note --sparse::.
3015 -T             *note --files-from::.
3016 -U             *note --unlink-first::.
3017 -V             *note --label::.
3018 -W             *note --verify::.
3019 -X             *note --exclude-from::.
3020 -Z             *note --compress::.
3021 -b             *note --blocking-factor::.
3022 -c             *note --create::.
3023 -d             *note --compare::.
3024 -f             *note --file::.
3025 -g             *note --listed-incremental::.
3026 -h             *note --dereference::.
3027 -i             *note --ignore-zeros::.
3028 -j             *note --bzip2::.
3029 -k             *note --keep-old-files::.
3030 -l             *note --check-links::.
3031 -m             *note --touch::.
3032 -o             When creating, *note --no-same-owner::, when extracting --
3033                *note --portability::.
3034                
3035                   The latter usage is deprecated.  It is retained for
3036                compatibility with the earlier versions of GNU `tar'.  In
3037                future releases `-o' will be equivalent to
3038                `--no-same-owner' only.
3039 -p             *note --preserve-permissions::.
3040 -r             *note --append::.
3041 -s             *note --same-order::.
3042 -t             *note --list::.
3043 -u             *note --update::.
3044 -v             *note --verbose::.
3045 -w             *note --interactive::.
3046 -x             *note --extract::.
3047 -z             *note --gzip::.
3048
3049 \1f
3050 File: tar.info,  Node: help,  Next: defaults,  Prev: All Options,  Up: tar invocation
3051
3052 3.5 GNU `tar' documentation
3053 ===========================
3054
3055 Being careful, the first thing is really checking that you are using
3056 GNU `tar', indeed.  The `--version' option causes `tar' to print
3057 information about its name, version, origin and legal status, all on
3058 standard output, and then exit successfully.  For example,
3059 `tar --version' might print:
3060
3061      tar (GNU tar) 1.25
3062      Copyright (C) 2010 Free Software Foundation, Inc.
3063      Copyright (C) 2010 Free Software Foundation, Inc.
3064      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
3065      This is free software: you are free to change and redistribute it.
3066      There is NO WARRANTY, to the extent permitted by law.
3067
3068      Written by John Gilmore and Jay Fenlason.
3069
3070 The first occurrence of `tar' in the result above is the program name
3071 in the package (for example, `rmt' is another program), while the
3072 second occurrence of `tar' is the name of the package itself,
3073 containing possibly many programs.  The package is currently named
3074 `tar', after the name of the main program it contains(1).
3075
3076    Another thing you might want to do is checking the spelling or
3077 meaning of some particular `tar' option, without resorting to this
3078 manual, for once you have carefully read it.  GNU `tar' has a short
3079 help feature, triggerable through the `--help' option.  By using this
3080 option, `tar' will print a usage message listing all available options
3081 on standard output, then exit successfully, without doing anything else
3082 and ignoring all other options.  Even if this is only a brief summary,
3083 it may be several screens long.  So, if you are not using some kind of
3084 scrollable window, you might prefer to use something like:
3085
3086      $ tar --help | less
3087
3088 presuming, here, that you like using `less' for a pager.  Other popular
3089 pagers are `more' and `pg'.  If you know about some KEYWORD which
3090 interests you and do not want to read all the `--help' output, another
3091 common idiom is doing:
3092
3093      tar --help | grep KEYWORD
3094
3095 for getting only the pertinent lines.  Notice, however, that some `tar'
3096 options have long description lines and the above command will list
3097 only the first of them.
3098
3099    The exact look of the option summary displayed by `tar --help' is
3100 configurable. *Note Configuring Help Summary::, for a detailed
3101 description.
3102
3103    If you only wish to check the spelling of an option, running `tar
3104 --usage' may be a better choice.  This will display a terse list of
3105 `tar' options without accompanying explanations.
3106
3107    The short help output is quite succinct, and you might have to get
3108 back to the full documentation for precise points.  If you are reading
3109 this paragraph, you already have the `tar' manual in some form.  This
3110 manual is available in a variety of forms from
3111 `http://www.gnu.org/software/tar/manual'.  It may be printed out of the
3112 GNU `tar' distribution, provided you have TeX already installed
3113 somewhere, and a laser printer around.  Just configure the
3114 distribution, execute the command `make dvi', then print `doc/tar.dvi'
3115 the usual way (contact your local guru to know how).  If GNU `tar' has
3116 been conveniently installed at your place, this manual is also
3117 available in interactive, hypertextual form as an Info file.  Just call
3118 `info tar' or, if you do not have the `info' program handy, use the
3119 Info reader provided within GNU Emacs, calling `tar' from the main Info
3120 menu.
3121
3122    There is currently no `man' page for GNU `tar'.  If you observe such
3123 a `man' page on the system you are running, either it does not belong
3124 to GNU `tar', or it has not been produced by GNU.  Some package
3125 maintainers convert `tar --help' output to a man page, using
3126 `help2man'.  In any case, please bear in mind that the authoritative
3127 source of information about GNU `tar' is this Texinfo documentation.
3128
3129    ---------- Footnotes ----------
3130
3131    (1) There are plans to merge the `cpio' and `tar' packages into a
3132 single one which would be called `paxutils'.  So, who knows if, one of
3133 this days, the `--version' would not output `tar (GNU paxutils) 3.2'.
3134
3135 \1f
3136 File: tar.info,  Node: defaults,  Next: verbose,  Prev: help,  Up: tar invocation
3137
3138 3.6 Obtaining GNU `tar' default values
3139 ======================================
3140
3141 GNU `tar' has some predefined defaults that are used when you do not
3142 explicitly specify another values.  To obtain a list of such defaults,
3143 use `--show-defaults' option.  This will output the values in the form
3144 of `tar' command line options:
3145
3146      $ tar --show-defaults
3147      --format=gnu -f- -b20 --quoting-style=escape
3148      --rmt-command=/etc/rmt --rsh-command=/usr/bin/rsh
3149
3150 Notice, that this option outputs only one line.  The example output
3151 above has been split to fit page boundaries.
3152
3153 The above output shows that this version of GNU `tar' defaults to using
3154 `gnu' archive format (*note Formats::), it uses standard output as the
3155 archive, if no `--file' option has been given (*note file tutorial::),
3156 the default blocking factor is 20 (*note Blocking Factor::).  It also
3157 shows the default locations where `tar' will look for `rmt' and `rsh'
3158 binaries.
3159
3160 \1f
3161 File: tar.info,  Node: verbose,  Next: checkpoints,  Prev: defaults,  Up: tar invocation
3162
3163 3.7 Checking `tar' progress
3164 ===========================
3165
3166 Typically, `tar' performs most operations without reporting any
3167 information to the user except error messages.  When using `tar' with
3168 many options, particularly ones with complicated or
3169 difficult-to-predict behavior, it is possible to make serious mistakes.
3170 `tar' provides several options that make observing `tar' easier.  These
3171 options cause `tar' to print information as it progresses in its job,
3172 and you might want to use them just for being more careful about what
3173 is going on, or merely for entertaining yourself.  If you have
3174 encountered a problem when operating on an archive, however, you may
3175 need more information than just an error message in order to solve the
3176 problem.  The following options can be helpful diagnostic tools.
3177
3178    Normally, the `--list' (`-t') command to list an archive prints just
3179 the file names (one per line) and the other commands are silent. When
3180 used with most operations, the `--verbose' (`-v') option causes `tar'
3181 to print the name of each file or archive member as it is processed.
3182 This and the other options which make `tar' print status information
3183 can be useful in monitoring `tar'.
3184
3185    With `--create' or `--extract', `--verbose' used once just prints
3186 the names of the files or members as they are processed.  Using it
3187 twice causes `tar' to print a longer listing (*Note verbose member
3188 listing::, for the description) for each member.  Since `--list'
3189 already prints  the names of the members, `--verbose' used once with
3190 `--list' causes `tar' to print an `ls -l' type listing of the files in
3191 the archive.  The following examples both extract members with long
3192 list output:
3193
3194      $ tar --extract --file=archive.tar --verbose --verbose
3195      $ tar xvvf archive.tar
3196
3197    Verbose output appears on the standard output except when an archive
3198 is being written to the standard output, as with `tar --create --file=-
3199 --verbose' (`tar cfv -', or even `tar cv'--if the installer let
3200 standard output be the default archive).  In that case `tar' writes
3201 verbose output to the standard error stream.
3202
3203    If `--index-file=FILE' is specified, `tar' sends verbose output to
3204 FILE rather than to standard output or standard error.
3205
3206    The `--totals' option causes `tar' to print on the standard error
3207 the total amount of bytes transferred when processing an archive.  When
3208 creating or appending to an archive, this option prints the number of
3209 bytes written to the archive and the average speed at which they have
3210 been written, e.g.:
3211
3212      $ tar -c -f archive.tar --totals /home
3213      Total bytes written: 7924664320 (7.4GiB, 85MiB/s)
3214
3215    When reading an archive, this option displays the number of bytes
3216 read:
3217
3218      $ tar -x -f archive.tar --totals
3219      Total bytes read: 7924664320 (7.4GiB, 95MiB/s)
3220
3221    Finally, when deleting from an archive, the `--totals' option
3222 displays both numbers plus number of bytes removed from the archive:
3223
3224      $ tar --delete -f foo.tar --totals --wildcards '*~'
3225      Total bytes read: 9543680 (9.2MiB, 201MiB/s)
3226      Total bytes written: 3829760 (3.7MiB, 81MiB/s)
3227      Total bytes deleted: 1474048
3228
3229    You can also obtain this information on request.  When `--totals' is
3230 used with an argument, this argument is interpreted as a symbolic name
3231 of a signal, upon delivery of which the statistics is to be printed:
3232
3233 `--totals=SIGNO'
3234      Print statistics upon delivery of signal SIGNO.  Valid arguments
3235      are: `SIGHUP', `SIGQUIT', `SIGINT', `SIGUSR1' and `SIGUSR2'.
3236      Shortened names without `SIG' prefix are also accepted.
3237
3238    Both forms of `--totals' option can be used simultaneously.  Thus,
3239 `tar -x --totals --totals=USR1' instructs `tar' to extract all members
3240 from its default archive and print statistics after finishing the
3241 extraction, as well as when receiving signal `SIGUSR1'.
3242
3243    The `--checkpoint' option prints an occasional message as `tar'
3244 reads or writes the archive.  It is designed for those who don't need
3245 the more detailed (and voluminous) output of `--block-number' (`-R'),
3246 but do want visual confirmation that `tar' is actually making forward
3247 progress.  By default it prints a message each 10 records read or
3248 written.  This can be changed by giving it a numeric argument after an
3249 equal sign:
3250
3251      $ tar -c --checkpoint=1000 /var
3252      tar: Write checkpoint 1000
3253      tar: Write checkpoint 2000
3254      tar: Write checkpoint 3000
3255
3256    This example shows the default checkpoint message used by `tar'.  If
3257 you place a dot immediately after the equal sign, it will print a `.'
3258 at each checkpoint(1).  For example:
3259
3260      $ tar -c --checkpoint=.1000 /var
3261      ...
3262
3263    The `--checkpoint' option provides a flexible mechanism for
3264 executing arbitrary actions upon hitting checkpoints, see the next
3265 section (*note checkpoints::), for more information on it.
3266
3267    The `--show-omitted-dirs' option, when reading an archive--with
3268 `--list' or `--extract', for example--causes a message to be printed
3269 for each directory in the archive which is skipped.  This happens
3270 regardless of the reason for skipping: the directory might not have
3271 been named on the command line (implicitly or explicitly), it might be
3272 excluded by the use of the `--exclude=PATTERN' option, or some other
3273 reason.
3274
3275    If `--block-number' (`-R') is used, `tar' prints, along with every
3276 message it would normally produce, the block number within the archive
3277 where the message was triggered.  Also, supplementary messages are
3278 triggered when reading blocks full of NULs, or when hitting end of file
3279 on the archive.  As of now, if the archive is properly terminated with
3280 a NUL block, the reading of the file may stop before end of file is
3281 met, so the position of end of file will not usually show when
3282 `--block-number' (`-R') is used.  Note that GNU `tar' drains the
3283 archive before exiting when reading the archive from a pipe.
3284
3285    This option is especially useful when reading damaged archives, since
3286 it helps pinpoint the damaged sections.  It can also be used with
3287 `--list' (`-t') when listing a file-system backup tape, allowing you to
3288 choose among several backup tapes when retrieving a file later, in
3289 favor of the tape where the file appears earliest (closest to the front
3290 of the tape).  *Note backup::.
3291
3292    ---------- Footnotes ----------
3293
3294    (1) This is actually a shortcut for `--checkpoint=N
3295 --checkpoint-action=dot'.  *Note dot: checkpoints.
3296
3297 \1f
3298 File: tar.info,  Node: checkpoints,  Next: warnings,  Prev: verbose,  Up: tar invocation
3299
3300 3.8 Checkpoints
3301 ===============
3302
3303 A "checkpoint" is a moment of time before writing Nth record to the
3304 archive (a "write checkpoint"), or before reading Nth record from the
3305 archive (a "read checkpoint").  Checkpoints allow to periodically
3306 execute arbitrary actions.
3307
3308    The checkpoint facility is enabled using the following option:
3309
3310 `--checkpoint[=N]'
3311      Schedule checkpoints before writing or reading each Nth record.
3312      The default value for N is 10.
3313
3314    A list of arbitrary "actions" can be executed at each checkpoint.
3315 These actions include: pausing, displaying textual messages, and
3316 executing arbitrary external programs.  Actions are defined using the
3317 `--checkpoint-action' option.
3318
3319 `--checkpoint-action=ACTION'
3320      Execute an ACTION at each checkpoint.
3321
3322    The simplest value of ACTION is `echo'.  It instructs `tar' to
3323 display the default message on the standard error stream upon arriving
3324 at each checkpoint.  The default message is (in POSIX locale) `Write
3325 checkpoint N', for write checkpoints, and `Read checkpoint N', for read
3326 checkpoints.  Here, N represents ordinal number of the checkpoint.
3327
3328    In another locales, translated versions of this message are used.
3329
3330    This is the default action, so running:
3331
3332      $ tar -c --checkpoint=1000 --checkpoint-action=echo /var
3333
3334 is equivalent to:
3335
3336      $ tar -c --checkpoint=1000 /var
3337
3338    The `echo' action also allows to supply a customized message.  You
3339 do so by placing an equals sign and the message right after it, e.g.:
3340
3341      --checkpoint-action="echo=Hit %s checkpoint #%u"
3342
3343    The `%s' and `%u' in the above example are "meta-characters".  The
3344 `%s' meta-character is replaced with the "type" of the checkpoint:
3345 `write' or `read' (or a corresponding translated version in locales
3346 other than POSIX).  The `%u' meta-character is replaced with the
3347 ordinal number of the checkpoint.  Thus, the above example could
3348 produce the following output when used with the `--create' option:
3349
3350      tar: Hit write checkpoint #10
3351      tar: Hit write checkpoint #20
3352      tar: Hit write checkpoint #30
3353
3354    Aside from meta-character expansion, the message string is subject to
3355 "unquoting", during which the backslash "escape sequences" are replaced
3356 with their corresponding ASCII characters (*note escape sequences::).
3357 E.g. the following action will produce an audible bell and the message
3358 described above at each checkpoint:
3359
3360      --checkpoint-action='echo=\aHit %s checkpoint #%u'
3361
3362    There is also a special action which produces an audible signal:
3363 `bell'.  It is not equivalent to `echo='\a'', because `bell' sends the
3364 bell directly to the console (`/dev/tty'), whereas `echo='\a'' sends it
3365 to the standard error.
3366
3367    The `ttyout=STRING' action outputs STRING to `/dev/tty', so it can
3368 be used even if the standard output is redirected elsewhere.  The
3369 STRING is subject to the same modifications as with `echo' action.  In
3370 contrast to the latter, `ttyout' does not prepend `tar' executable name
3371 to the string, nor does it output a newline after it.  For example, the
3372 following action will print the checkpoint message at the same screen
3373 line, overwriting any previous message:
3374
3375      --checkpoint-action="ttyout=\rHit %s checkpoint #%u"
3376
3377    Another available checkpoint action is `dot' (or `.').  It instructs
3378 `tar' to print a single dot on the standard listing stream, e.g.:
3379
3380      $ tar -c --checkpoint=1000 --checkpoint-action=dot /var
3381      ...
3382
3383    For compatibility with previous GNU `tar' versions, this action can
3384 be abbreviated by placing a dot in front of the checkpoint frequency,
3385 as shown in the previous section.
3386
3387    Yet another action, `sleep', pauses `tar' for a specified amount of
3388 seconds.  The following example will stop for 30 seconds at each
3389 checkpoint:
3390
3391      $ tar -c --checkpoint=1000 --checkpoint-action=sleep=30
3392
3393    Finally, the `exec' action executes a given external program.  For
3394 example:
3395
3396      $ tar -c --checkpoint=1000 --checkpoint-action=exec=/sbin/cpoint
3397
3398    This program is executed using `/bin/sh -c', with no additional
3399 arguments.  Its exit code is ignored.  It gets a copy of `tar''s
3400 environment plus the following variables:
3401
3402 `TAR_VERSION'
3403      GNU `tar' version number.
3404
3405 `TAR_ARCHIVE'
3406      The name of the archive `tar' is processing.
3407
3408 `TAR_BLOCKING_FACTOR'
3409      Current blocking factor (*note Blocking::).
3410
3411 `TAR_CHECKPOINT'
3412      Number of the checkpoint.
3413
3414 `TAR_SUBCOMMAND'
3415      A short option describing the operation `tar' is executing.  *Note
3416      Operations::, for a complete list of subcommand options.
3417
3418 `TAR_FORMAT'
3419      Format of the archive being processed. *Note Formats::, for a
3420      complete list of archive format names.
3421
3422    Any number of actions can be defined, by supplying several
3423 `--checkpoint-action' options in the command line.  For example, the
3424 command below displays two messages, pauses execution for 30 seconds
3425 and executes the `/sbin/cpoint' script:
3426
3427      $ tar -c -f arc.tar \
3428             --checkpoint-action='\aecho=Hit %s checkpoint #%u' \
3429             --checkpoint-action='echo=Sleeping for 30 seconds' \
3430             --checkpoint-action='sleep=30' \
3431             --checkpoint-action='exec=/sbin/cpoint'
3432
3433    This example also illustrates the fact that `--checkpoint-action'
3434 can be used without `--checkpoint'.  In this case, the default
3435 checkpoint frequency (at each 10th record) is assumed.
3436
3437 \1f
3438 File: tar.info,  Node: warnings,  Next: interactive,  Prev: checkpoints,  Up: tar invocation
3439
3440 3.9 Controlling Warning Messages
3441 ================================
3442
3443 Sometimes, while performing the requested task, GNU `tar' notices some
3444 conditions that are not exactly errors, but which the user should be
3445 aware of.  When this happens, `tar' issues a "warning message"
3446 describing the condition.  Warning messages are output to the standard
3447 error and they do not affect the exit code of `tar' command.
3448
3449    GNU `tar' allows the user to suppress some or all of its warning
3450 messages:
3451
3452 `--warning=KEYWORD'
3453      Control display of the warning messages identified by KEYWORD.  If
3454      KEYWORD starts with the prefix `no-', such messages are
3455      suppressed.  Otherwise, they are enabled.
3456
3457      Multiple `--warning' messages accumulate.
3458
3459      The tables below list allowed values for KEYWORD along with the
3460      warning messages they control.
3461
3462 Keywords controlling `tar' operation
3463 ------------------------------------
3464
3465 all
3466      Enable all warning messages.  This is the default.  
3467
3468 none
3469      Disable all warning messages.  
3470
3471 filename-with-nuls
3472      `%s: file name read contains nul character' 
3473
3474 alone-zero-block
3475      `A lone zero block at %s'
3476
3477 Keywords applicable for `tar --create'
3478 --------------------------------------
3479
3480 cachedir
3481      `%s: contains a cache directory tag %s; %s' 
3482
3483 file-shrank
3484      `%s: File shrank by %s bytes; padding with zeros' 
3485
3486 xdev
3487      `%s: file is on a different filesystem; not dumped' 
3488
3489 file-ignored
3490      `%s: Unknown file type; file ignored'
3491      `%s: socket ignored'
3492      `%s: door ignored' 
3493
3494 file-unchanged
3495      `%s: file is unchanged; not dumped' 
3496
3497 ignore-archive
3498      `%s: file is the archive; not dumped' 
3499
3500 file-removed
3501      `%s: File removed before we read it' 
3502
3503 file-changed
3504      `%s: file changed as we read it'
3505
3506 Keywords applicable for `tar --extract'
3507 ---------------------------------------
3508
3509 timestamp
3510      `%s: implausibly old time stamp %s'
3511      `%s: time stamp %s is %s s in the future' 
3512
3513 contiguous-cast
3514      `Extracting contiguous files as regular files' 
3515
3516 symlink-cast
3517      `Attempting extraction of symbolic links as hard links' 
3518
3519 unknown-cast
3520      `%s: Unknown file type `%c', extracted as normal file' 
3521
3522 ignore-newer
3523      `Current %s is newer or same age' 
3524
3525 unknown-keyword
3526      `Ignoring unknown extended header keyword `%s'' 
3527
3528 decompress-program
3529      Controls verbose messages describing execution failures when trying
3530      alternative decompressor programs (*note alternative decompression
3531      programs::).  This warning is disabled by default (unless
3532      `--verbose' is used).  A common example of what you can get when
3533      using this warning is:
3534
3535           $ tar --warning=decompress-program -x -f archive.Z
3536           tar (child): cannot run compress: No such file or directory
3537           tar (child): trying gzip
3538
3539      This means that `tar' first tried to decompress `archive.Z' using
3540      `compress', and, when that failed, switched to `gzip'.
3541
3542 Keywords controlling incremental extraction:
3543 --------------------------------------------
3544
3545 rename-directory
3546      `%s: Directory has been renamed from %s'
3547      `%s: Directory has been renamed' 
3548
3549 new-directory
3550      `%s: Directory is new' 
3551
3552 xdev
3553      `%s: directory is on a different device: not purging' 
3554
3555 bad-dumpdir
3556      `Malformed dumpdir: 'X' never used'
3557
3558 \1f
3559 File: tar.info,  Node: interactive,  Prev: warnings,  Up: tar invocation
3560
3561 3.10 Asking for Confirmation During Operations
3562 ==============================================
3563
3564 Typically, `tar' carries out a command without stopping for further
3565 instructions.  In some situations however, you may want to exclude some
3566 files and archive members from the operation (for instance if disk or
3567 storage space is tight).  You can do this by excluding certain files
3568 automatically (*note Choosing::), or by performing an operation
3569 interactively, using the `--interactive' (`-w') option.  `tar' also
3570 accepts `--confirmation' for this option.
3571
3572    When the `--interactive' (`-w') option is specified, before reading,
3573 writing, or deleting files, `tar' first prints a message for each such
3574 file, telling what operation it intends to take, then asks for
3575 confirmation on the terminal.  The actions which require confirmation
3576 include adding a file to the archive, extracting a file from the
3577 archive, deleting a file from the archive, and deleting a file from
3578 disk.  To confirm the action, you must type a line of input beginning
3579 with `y'.  If your input line begins with anything other than `y',
3580 `tar' skips that file.
3581
3582    If `tar' is reading the archive from the standard input, `tar' opens
3583 the file `/dev/tty' to support the interactive communications.
3584
3585    Verbose output is normally sent to standard output, separate from
3586 other error messages.  However, if the archive is produced directly on
3587 standard output, then verbose output is mixed with errors on `stderr'.
3588 Producing the archive on standard output may be used as a way to avoid
3589 using disk space, when the archive is soon to be consumed by another
3590 process reading it, say.  Some people felt the need of producing an
3591 archive on stdout, still willing to segregate between verbose output
3592 and error output.  A possible approach would be using a named pipe to
3593 receive the archive, and having the consumer process to read from that
3594 named pipe.  This has the advantage of letting standard output free to
3595 receive verbose output, all separate from errors.
3596
3597 \1f
3598 File: tar.info,  Node: operations,  Next: Backups,  Prev: tar invocation,  Up: Top
3599
3600 4 GNU `tar' Operations
3601 **********************
3602
3603 * Menu:
3604
3605 * Basic tar::
3606 * Advanced tar::
3607 * create options::
3608 * extract options::
3609 * backup::
3610 * Applications::
3611 * looking ahead::
3612
3613 \1f
3614 File: tar.info,  Node: Basic tar,  Next: Advanced tar,  Up: operations
3615
3616 4.1 Basic GNU `tar' Operations
3617 ==============================
3618
3619 The basic `tar' operations, `--create' (`-c'), `--list' (`-t') and
3620 `--extract' (`--get', `-x'), are currently presented and described in
3621 the tutorial chapter of this manual.  This section provides some
3622 complementary notes for these operations.
3623
3624 `--create'
3625 `-c'
3626      Creating an empty archive would have some kind of elegance.  One
3627      can initialize an empty archive and later use `--append' (`-r')
3628      for adding all members.  Some applications would not welcome
3629      making an exception in the way of adding the first archive member.
3630      On the other hand, many people reported that it is dangerously too
3631      easy for `tar' to destroy a magnetic tape with an empty
3632      archive(1).  The two most common errors are:
3633
3634        1. Mistakingly using `create' instead of `extract', when the
3635           intent was to extract the full contents of an archive.  This
3636           error is likely: keys `c' and `x' are right next to each
3637           other on the QWERTY keyboard.  Instead of being unpacked, the
3638           archive then gets wholly destroyed.  When users speak about
3639           "exploding" an archive, they usually mean something else :-).
3640
3641        2. Forgetting the argument to `file', when the intent was to
3642           create an archive with a single file in it.  This error is
3643           likely because a tired user can easily add the `f' key to the
3644           cluster of option letters, by the mere force of habit,
3645           without realizing the full consequence of doing so.  The
3646           usual consequence is that the single file, which was meant to
3647           be saved, is rather destroyed.
3648
3649      So, recognizing the likelihood and the catastrophic nature of these
3650      errors, GNU `tar' now takes some distance from elegance, and
3651      cowardly refuses to create an archive when `--create' option is
3652      given, there are no arguments besides options, and `--files-from'
3653      (`-T') option is _not_ used.  To get around the cautiousness of
3654      GNU `tar' and nevertheless create an archive with nothing in it,
3655      one may still use, as the value for the `--files-from' option, a
3656      file with no names in it, as shown in the following commands:
3657
3658           tar --create --file=empty-archive.tar --files-from=/dev/null
3659           tar cfT empty-archive.tar /dev/null
3660
3661 `--extract'
3662 `--get'
3663 `-x'
3664      A socket is stored, within a GNU `tar' archive, as a pipe.
3665
3666 ``--list' (`-t')'
3667      GNU `tar' now shows dates as `1996-08-30', while it used to show
3668      them as `Aug 30 1996'. Preferably, people should get used to ISO
3669      8601 dates.  Local American dates should be made available again
3670      with full date localization support, once ready.  In the meantime,
3671      programs not being localizable for dates should prefer
3672      international dates, that's really the way to go.
3673
3674      Look up `http://www.cl.cam.ac.uk/~mgk25/iso-time.html' if you are
3675      curious, it contains a detailed explanation of the ISO 8601
3676      standard.
3677
3678
3679    ---------- Footnotes ----------
3680
3681    (1) This is well described in `Unix-haters Handbook', by Simson
3682 Garfinkel, Daniel Weise & Steven Strassmann, IDG Books, ISBN
3683 1-56884-203-1.
3684
3685 \1f
3686 File: tar.info,  Node: Advanced tar,  Next: create options,  Prev: Basic tar,  Up: operations
3687
3688 4.2 Advanced GNU `tar' Operations
3689 =================================
3690
3691 Now that you have learned the basics of using GNU `tar', you may want
3692 to learn about further ways in which `tar' can help you.
3693
3694    This chapter presents five, more advanced operations which you
3695 probably won't use on a daily basis, but which serve more specialized
3696 functions.  We also explain the different styles of options and why you
3697 might want to use one or another, or a combination of them in your `tar'
3698 commands.  Additionally, this chapter includes options which allow you
3699 to define the output from `tar' more carefully, and provide help and
3700 error correction in special circumstances.
3701
3702 * Menu:
3703
3704 * Operations::
3705 * append::
3706 * update::
3707 * concatenate::
3708 * delete::
3709 * compare::
3710
3711 \1f
3712 File: tar.info,  Node: Operations,  Next: append,  Up: Advanced tar
3713
3714 4.2.1 The Five Advanced `tar' Operations
3715 ----------------------------------------
3716
3717 In the last chapter, you learned about the first three operations to
3718 `tar'.  This chapter presents the remaining five operations to `tar':
3719 `--append', `--update', `--concatenate', `--delete', and `--compare'.
3720
3721    You are not likely to use these operations as frequently as those
3722 covered in the last chapter; however, since they perform specialized
3723 functions, they are quite useful when you do need to use them.  We will
3724 give examples using the same directory and files that you created in
3725 the last chapter.  As you may recall, the directory is called
3726 `practice', the files are `jazz', `blues', `folk', and the two archive
3727 files you created are `collection.tar' and `music.tar'.
3728
3729    We will also use the archive files `afiles.tar' and `bfiles.tar'.
3730 The archive `afiles.tar' contains the members `apple', `angst', and
3731 `aspic'; `bfiles.tar' contains the members `./birds', `baboon', and
3732 `./box'.
3733
3734    Unless we state otherwise, all practicing you do and examples you
3735 follow in this chapter will take place in the `practice' directory that
3736 you created in the previous chapter; see *note prepare for examples::.
3737 (Below in this section, we will remind you of the state of the examples
3738 where the last chapter left them.)
3739
3740    The five operations that we will cover in this chapter are:
3741
3742 `--append'
3743 `-r'
3744      Add new entries to an archive that already exists.
3745
3746 `--update'
3747 `-u'
3748      Add more recent copies of archive members to the end of an
3749      archive, if they exist.
3750
3751 `--concatenate'
3752 `--catenate'
3753 `-A'
3754      Add one or more pre-existing archives to the end of another
3755      archive.
3756
3757 `--delete'
3758      Delete items from an archive (does not work on tapes).
3759
3760 `--compare'
3761 `--diff'
3762 `-d'
3763      Compare archive members to their counterparts in the file system.
3764
3765 \1f
3766 File: tar.info,  Node: append,  Next: update,  Prev: Operations,  Up: Advanced tar
3767
3768 4.2.2 How to Add Files to Existing Archives: `--append'
3769 -------------------------------------------------------
3770
3771 If you want to add files to an existing archive, you don't need to
3772 create a new archive; you can use `--append' (`-r').  The archive must
3773 already exist in order to use `--append'.  (A related operation is the
3774 `--update' operation; you can use this to add newer versions of archive
3775 members to an existing archive.  To learn how to do this with
3776 `--update', *note update::.)
3777
3778    If you use `--append' to add a file that has the same name as an
3779 archive member to an archive containing that archive member, then the
3780 old member is not deleted.  What does happen, however, is somewhat
3781 complex.  `tar' _allows_ you to have infinite number of files with the
3782 same name.  Some operations treat these same-named members no
3783 differently than any other set of archive members: for example, if you
3784 view an archive with `--list' (`-t'), you will see all of those members
3785 listed, with their data modification times, owners, etc.
3786
3787    Other operations don't deal with these members as perfectly as you
3788 might prefer; if you were to use `--extract' to extract the archive,
3789 only the most recently added copy of a member with the same name as
3790 other members would end up in the working directory.  This is because
3791 `--extract' extracts an archive in the order the members appeared in
3792 the archive; the most recently archived members will be extracted last.
3793 Additionally, an extracted member will _replace_ a file of the same
3794 name which existed in the directory already, and `tar' will not prompt
3795 you about this(1).  Thus, only the most recently archived member will
3796 end up being extracted, as it will replace the one extracted before it,
3797 and so on.
3798
3799    There exists a special option that allows you to get around this
3800 behavior and extract (or list) only a particular copy of the file.
3801 This is `--occurrence' option.  If you run `tar' with this option, it
3802 will extract only the first copy of the file.  You may also give this
3803 option an argument specifying the number of copy to be extracted.
3804 Thus, for example if the archive `archive.tar' contained three copies
3805 of file `myfile', then the command
3806
3807      tar --extract --file archive.tar --occurrence=2 myfile
3808
3809 would extract only the second copy.  *Note --occurrence: Option
3810 Summary, for the description of `--occurrence' option.
3811
3812    If you want to replace an archive member, use `--delete' to delete
3813 the member you want to remove from the archive, and then use `--append'
3814 to add the member you want to be in the archive.  Note that you can not
3815 change the order of the archive; the most recently added member will
3816 still appear last.  In this sense, you cannot truly "replace" one
3817 member with another.  (Replacing one member with another will not work
3818 on certain types of media, such as tapes; see *note delete:: and *note
3819 Media::, for more information.)
3820
3821 * Menu:
3822
3823 * appending files::             Appending Files to an Archive
3824 * multiple::
3825
3826    ---------- Footnotes ----------
3827
3828    (1) Unless you give it `--keep-old-files' option, or the disk copy
3829 is newer than the one in the archive and you invoke `tar' with
3830 `--keep-newer-files' option.
3831
3832 \1f
3833 File: tar.info,  Node: appending files,  Next: multiple,  Up: append
3834
3835 4.2.2.1 Appending Files to an Archive
3836 .....................................
3837
3838 The simplest way to add a file to an already existing archive is the
3839 `--append' (`-r') operation, which writes specified files into the
3840 archive whether or not they are already among the archived files.
3841
3842    When you use `--append', you _must_ specify file name arguments, as
3843 there is no default.  If you specify a file that already exists in the
3844 archive, another copy of the file will be added to the end of the
3845 archive.  As with other operations, the member names of the newly added
3846 files will be exactly the same as their names given on the command
3847 line.  The `--verbose' (`-v') option will print out the names of the
3848 files as they are written into the archive.
3849
3850    `--append' cannot be performed on some tape drives, unfortunately,
3851 due to deficiencies in the formats those tape drives use.  The archive
3852 must be a valid `tar' archive, or else the results of using this
3853 operation will be unpredictable.  *Note Media::.
3854
3855    To demonstrate using `--append' to add a file to an archive, create
3856 a file called `rock' in the `practice' directory.  Make sure you are in
3857 the `practice' directory.  Then, run the following `tar' command to add
3858 `rock' to `collection.tar':
3859
3860      $ tar --append --file=collection.tar rock
3861
3862 If you now use the `--list' (`-t') operation, you will see that `rock'
3863 has been added to the archive:
3864
3865      $ tar --list --file=collection.tar
3866      -rw-r--r-- me user     28 1996-10-18 16:31 jazz
3867      -rw-r--r-- me user     21 1996-09-23 16:44 blues
3868      -rw-r--r-- me user     20 1996-09-23 16:44 folk
3869      -rw-r--r-- me user     20 1996-09-23 16:44 rock
3870
3871 \1f
3872 File: tar.info,  Node: multiple,  Prev: appending files,  Up: append
3873
3874 4.2.2.2 Multiple Members with the Same Name
3875 ...........................................
3876
3877 You can use `--append' (`-r') to add copies of files which have been
3878 updated since the archive was created.  (However, we do not recommend
3879 doing this since there is another `tar' option called `--update'; *Note
3880 update::, for more information.  We describe this use of `--append'
3881 here for the sake of completeness.)  When you extract the archive, the
3882 older version will be effectively lost.  This works because files are
3883 extracted from an archive in the order in which they were archived.
3884 Thus, when the archive is extracted, a file archived later in time will
3885 replace a file of the same name which was archived earlier, even though
3886 the older version of the file will remain in the archive unless you
3887 delete all versions of the file.
3888
3889    Supposing you change the file `blues' and then append the changed
3890 version to `collection.tar'.  As you saw above, the original `blues' is
3891 in the archive `collection.tar'.  If you change the file and append the
3892 new version of the file to the archive, there will be two copies in the
3893 archive.  When you extract the archive, the older version of the file
3894 will be extracted first, and then replaced by the newer version when it
3895 is extracted.
3896
3897    You can append the new, changed copy of the file `blues' to the
3898 archive in this way:
3899
3900      $ tar --append --verbose --file=collection.tar blues
3901      blues
3902
3903 Because you specified the `--verbose' option, `tar' has printed the
3904 name of the file being appended as it was acted on.  Now list the
3905 contents of the archive:
3906
3907      $ tar --list --verbose --file=collection.tar
3908      -rw-r--r-- me user     28 1996-10-18 16:31 jazz
3909      -rw-r--r-- me user     21 1996-09-23 16:44 blues
3910      -rw-r--r-- me user     20 1996-09-23 16:44 folk
3911      -rw-r--r-- me user     20 1996-09-23 16:44 rock
3912      -rw-r--r-- me user     58 1996-10-24 18:30 blues
3913
3914 The newest version of `blues' is now at the end of the archive (note
3915 the different creation dates and file sizes).  If you extract the
3916 archive, the older version of the file `blues' will be replaced by the
3917 newer version.  You can confirm this by extracting the archive and
3918 running `ls' on the directory.
3919
3920    If you wish to extract the first occurrence of the file `blues' from
3921 the archive, use `--occurrence' option, as shown in the following
3922 example:
3923
3924      $ tar --extract -vv --occurrence --file=collection.tar blues
3925      -rw-r--r-- me user     21 1996-09-23 16:44 blues
3926
3927    *Note Writing::, for more information on `--extract' and see *note
3928 -occurrence: Option Summary, for a description of `--occurrence' option.
3929
3930 \1f
3931 File: tar.info,  Node: update,  Next: concatenate,  Prev: append,  Up: Advanced tar
3932
3933 4.2.3 Updating an Archive
3934 -------------------------
3935
3936 In the previous section, you learned how to use `--append' to add a
3937 file to an existing archive.  A related operation is `--update' (`-u').
3938 The `--update' operation updates a `tar' archive by comparing the date
3939 of the specified archive members against the date of the file with the
3940 same name.  If the file has been modified more recently than the
3941 archive member, then the newer version of the file is added to the
3942 archive (as with `--append').
3943
3944    Unfortunately, you cannot use `--update' with magnetic tape drives.
3945 The operation will fail.
3946
3947    Both `--update' and `--append' work by adding to the end of the
3948 archive.  When you extract a file from the archive, only the version
3949 stored last will wind up in the file system, unless you use the
3950 `--backup' option.  *Note multiple::, for a detailed discussion.
3951
3952 * Menu:
3953
3954 * how to update::
3955
3956 \1f
3957 File: tar.info,  Node: how to update,  Up: update
3958
3959 4.2.3.1 How to Update an Archive Using `--update'
3960 .................................................
3961
3962 You must use file name arguments with the `--update' (`-u') operation.
3963 If you don't specify any files, `tar' won't act on any files and won't
3964 tell you that it didn't do anything (which may end up confusing you).
3965
3966    To see the `--update' option at work, create a new file,
3967 `classical', in your practice directory, and some extra text to the
3968 file `blues', using any text editor.  Then invoke `tar' with the
3969 `update' operation and the `--verbose' (`-v') option specified, using
3970 the names of all the files in the `practice' directory as file name
3971 arguments:
3972
3973      $ tar --update -v -f collection.tar blues folk rock classical
3974      blues
3975      classical
3976      $
3977
3978 Because we have specified verbose mode, `tar' prints out the names of
3979 the files it is working on, which in this case are the names of the
3980 files that needed to be updated.  If you run `tar --list' and look at
3981 the archive, you will see `blues' and `classical' at its end.  There
3982 will be a total of two versions of the member `blues'; the one at the
3983 end will be newer and larger, since you added text before updating it.
3984
3985    The reason `tar' does not overwrite the older file when updating it
3986 is because writing to the middle of a section of tape is a difficult
3987 process.  Tapes are not designed to go backward.  *Note Media::, for
3988 more information about tapes.
3989
3990    `--update' (`-u') is not suitable for performing backups for two
3991 reasons: it does not change directory content entries, and it lengthens
3992 the archive every time it is used.  The GNU `tar' options intended
3993 specifically for backups are more efficient.  If you need to run
3994 backups, please consult *note Backups::.
3995
3996 \1f
3997 File: tar.info,  Node: concatenate,  Next: delete,  Prev: update,  Up: Advanced tar
3998
3999 4.2.4 Combining Archives with `--concatenate'
4000 ---------------------------------------------
4001
4002 Sometimes it may be convenient to add a second archive onto the end of
4003 an archive rather than adding individual files to the archive.  To add
4004 one or more archives to the end of another archive, you should use the
4005 `--concatenate' (`--catenate', `-A') operation.
4006
4007    To use `--concatenate', give the first archive with `--file' option
4008 and name the rest of archives to be concatenated on the command line.
4009 The members, and their member names, will be copied verbatim from those
4010 archives to the first one(1).  The new, concatenated archive will be
4011 called by the same name as the one given with the `--file' option.  As
4012 usual, if you omit `--file', `tar' will use the value of the environment
4013 variable `TAPE', or, if this has not been set, the default archive name.
4014
4015    To demonstrate how `--concatenate' works, create two small archives
4016 called `bluesrock.tar' and `folkjazz.tar', using the relevant files
4017 from `practice':
4018
4019      $ tar -cvf bluesrock.tar blues rock
4020      blues
4021      rock
4022      $ tar -cvf folkjazz.tar folk jazz
4023      folk
4024      jazz
4025
4026 If you like, You can run `tar --list' to make sure the archives contain
4027 what they are supposed to:
4028
4029      $ tar -tvf bluesrock.tar
4030      -rw-r--r-- melissa user    105 1997-01-21 19:42 blues
4031      -rw-r--r-- melissa user     33 1997-01-20 15:34 rock
4032      $ tar -tvf jazzfolk.tar
4033      -rw-r--r-- melissa user     20 1996-09-23 16:44 folk
4034      -rw-r--r-- melissa user     65 1997-01-30 14:15 jazz
4035
4036    We can concatenate these two archives with `tar':
4037
4038      $ cd ..
4039      $ tar --concatenate --file=bluesrock.tar jazzfolk.tar
4040
4041    If you now list the contents of the `bluesrock.tar', you will see
4042 that now it also contains the archive members of `jazzfolk.tar':
4043
4044      $ tar --list --file=bluesrock.tar
4045      blues
4046      rock
4047      folk
4048      jazz
4049
4050    When you use `--concatenate', the source and target archives must
4051 already exist and must have been created using compatible format
4052 parameters.  Notice, that `tar' does not check whether the archives it
4053 concatenates have compatible formats, it does not even check if the
4054 files are really tar archives.
4055
4056    Like `--append' (`-r'), this operation cannot be performed on some
4057 tape drives, due to deficiencies in the formats those tape drives use.
4058
4059    It may seem more intuitive to you to want or try to use `cat' to
4060 concatenate two archives instead of using the `--concatenate'
4061 operation; after all, `cat' is the utility for combining files.
4062
4063    However, `tar' archives incorporate an end-of-file marker which must
4064 be removed if the concatenated archives are to be read properly as one
4065 archive.  `--concatenate' removes the end-of-archive marker from the
4066 target archive before each new archive is appended.  If you use `cat'
4067 to combine the archives, the result will not be a valid `tar' format
4068 archive.  If you need to retrieve files from an archive that was added
4069 to using the `cat' utility, use the `--ignore-zeros' (`-i') option.
4070 *Note Ignore Zeros::, for further information on dealing with archives
4071 improperly combined using the `cat' shell utility.
4072
4073    ---------- Footnotes ----------
4074
4075    (1) This can cause multiple members to have the same name.  For
4076 information on how this affects reading the archive, see *note
4077 multiple::.
4078
4079 \1f
4080 File: tar.info,  Node: delete,  Next: compare,  Prev: concatenate,  Up: Advanced tar
4081
4082 4.2.5 Removing Archive Members Using `--delete'
4083 -----------------------------------------------
4084
4085 You can remove members from an archive by using the `--delete' option.
4086 Specify the name of the archive with `--file' (`-f') and then specify
4087 the names of the members to be deleted; if you list no member names,
4088 nothing will be deleted.  The `--verbose' option will cause `tar' to
4089 print the names of the members as they are deleted. As with
4090 `--extract', you must give the exact member names when using `tar
4091 --delete'.  `--delete' will remove all versions of the named file from
4092 the archive.  The `--delete' operation can run very slowly.
4093
4094    Unlike other operations, `--delete' has no short form.
4095
4096    This operation will rewrite the archive.  You can only use
4097 `--delete' on an archive if the archive device allows you to write to
4098 any point on the media, such as a disk; because of this, it does not
4099 work on magnetic tapes.  Do not try to delete an archive member from a
4100 magnetic tape; the action will not succeed, and you will be likely to
4101 scramble the archive and damage your tape.  There is no safe way
4102 (except by completely re-writing the archive) to delete files from most
4103 kinds of magnetic tape.  *Note Media::.
4104
4105    To delete all versions of the file `blues' from the archive
4106 `collection.tar' in the `practice' directory, make sure you are in that
4107 directory, and then,
4108
4109      $ tar --list --file=collection.tar
4110      blues
4111      folk
4112      jazz
4113      rock
4114      $ tar --delete --file=collection.tar blues
4115      $ tar --list --file=collection.tar
4116      folk
4117      jazz
4118      rock
4119
4120    The `--delete' option has been reported to work properly when `tar'
4121 acts as a filter from `stdin' to `stdout'.
4122
4123 \1f
4124 File: tar.info,  Node: compare,  Prev: delete,  Up: Advanced tar
4125
4126 4.2.6 Comparing Archive Members with the File System
4127 ----------------------------------------------------
4128
4129 The `--compare' (`-d'), or `--diff' operation compares specified
4130 archive members against files with the same names, and then reports
4131 differences in file size, mode, owner, modification date and contents.
4132 You should _only_ specify archive member names, not file names.  If you
4133 do not name any members, then `tar' will compare the entire archive.
4134 If a file is represented in the archive but does not exist in the file
4135 system, `tar' reports a difference.
4136
4137    You have to specify the record size of the archive when modifying an
4138 archive with a non-default record size.
4139
4140    `tar' ignores files in the file system that do not have
4141 corresponding members in the archive.
4142
4143    The following example compares the archive members `rock', `blues'
4144 and `funk' in the archive `bluesrock.tar' with files of the same name
4145 in the file system.  (Note that there is no file, `funk'; `tar' will
4146 report an error message.)
4147
4148      $ tar --compare --file=bluesrock.tar rock blues funk
4149      rock
4150      blues
4151      tar: funk not found in archive
4152
4153    The spirit behind the `--compare' (`--diff', `-d') option is to
4154 check whether the archive represents the current state of files on
4155 disk, more than validating the integrity of the archive media.  For
4156 this latter goal, see *note verify::.
4157
4158 \1f
4159 File: tar.info,  Node: create options,  Next: extract options,  Prev: Advanced tar,  Up: operations
4160
4161 4.3 Options Used by `--create'
4162 ==============================
4163
4164 The previous chapter described the basics of how to use `--create'
4165 (`-c') to create an archive from a set of files.  *Note create::.  This
4166 section described advanced options to be used with `--create'.
4167
4168 * Menu:
4169
4170 * override::                  Overriding File Metadata.
4171 * Ignore Failed Read::
4172
4173 \1f
4174 File: tar.info,  Node: override,  Next: Ignore Failed Read,  Up: create options
4175
4176 4.3.1 Overriding File Metadata
4177 ------------------------------
4178
4179 As described above, a `tar' archive keeps, for each member it contains,
4180 its "metadata", such as modification time, mode and ownership of the
4181 file.  GNU `tar' allows to replace these data with other values when
4182 adding files to the archive.  The options described in this section
4183 affect creation of archives of any type.  For POSIX archives, see also
4184 *note PAX keywords::, for additional ways of controlling metadata,
4185 stored in the archive.
4186
4187 `--mode=PERMISSIONS'
4188      When adding files to an archive, `tar' will use PERMISSIONS for
4189      the archive members, rather than the permissions from the files.
4190      PERMISSIONS can be specified either as an octal number or as
4191      symbolic permissions, like with `chmod' (*Note Permissions:
4192      (fileutils)File permissions.  This reference also has useful
4193      information for those not being overly familiar with the UNIX
4194      permission system).  Using latter syntax allows for more
4195      flexibility.  For example, the value `a+rw' adds read and write
4196      permissions for everybody, while retaining executable bits on
4197      directories or on any other file already marked as executable:
4198
4199           $ tar -c -f archive.tar --mode='a+rw' .
4200
4201 `--mtime=DATE'
4202      When adding files to an archive, `tar' will use DATE as the
4203      modification time of members when creating archives, instead of
4204      their actual modification times.  The argument DATE can be either
4205      a textual date representation in almost arbitrary format (*note
4206      Date input formats::) or a name of an existing file, starting with
4207      `/' or `.'.  In the latter case, the modification time of that
4208      file will be used.
4209
4210      The following example will set the modification date to 00:00:00,
4211      January 1, 1970:
4212
4213           $ tar -c -f archive.tar --mtime='1970-01-01' .
4214
4215      When used with `--verbose' (*note verbose tutorial::) GNU `tar'
4216      will try to convert the specified date back to its textual
4217      representation and compare it with the one given with `--mtime'
4218      options.  If the two dates differ, `tar' will print a warning
4219      saying what date it will use.  This is to help user ensure he is
4220      using the right date.
4221
4222      For example:
4223
4224           $ tar -c -f archive.tar -v --mtime=yesterday .
4225           tar: Option --mtime: Treating date `yesterday' as 2006-06-20
4226           13:06:29.152478
4227           ...
4228
4229 `--owner=USER'
4230      Specifies that `tar' should use USER as the owner of members when
4231      creating archives, instead of the user associated with the source
4232      file.  The argument USER can be either an existing user symbolic
4233      name, or a decimal numeric user ID.
4234
4235      There is no value indicating a missing number, and `0' usually
4236      means `root'.  Some people like to force `0' as the value to offer
4237      in their distributions for the owner of files, because the `root'
4238      user is anonymous anyway, so that might as well be the owner of
4239      anonymous archives.  For example:
4240
4241           $ tar -c -f archive.tar --owner=0 .
4242
4243      or:
4244
4245           $ tar -c -f archive.tar --owner=root .
4246
4247 `--group=GROUP'
4248      Files added to the `tar' archive will have a group ID of GROUP,
4249      rather than the group from the source file.  The argument GROUP
4250      can be either an existing group symbolic name, or a decimal
4251      numeric group ID.
4252
4253 \1f
4254 File: tar.info,  Node: Ignore Failed Read,  Prev: override,  Up: create options
4255
4256 4.3.2 Ignore Fail Read
4257 ----------------------
4258
4259 `--ignore-failed-read'
4260      Do not exit with nonzero on unreadable files or directories.
4261
4262 \1f
4263 File: tar.info,  Node: extract options,  Next: backup,  Prev: create options,  Up: operations
4264
4265 4.4 Options Used by `--extract'
4266 ===============================
4267
4268 The previous chapter showed how to use `--extract' to extract an
4269 archive into the file system.  Various options cause `tar' to extract
4270 more information than just file contents, such as the owner, the
4271 permissions, the modification date, and so forth.  This section
4272 presents options to be used with `--extract' when certain special
4273 considerations arise.  You may review the information presented in
4274 *note extract:: for more basic information about the `--extract'
4275 operation.
4276
4277 * Menu:
4278
4279 * Reading::                     Options to Help Read Archives
4280 * Writing::                     Changing How `tar' Writes Files
4281 * Scarce::                      Coping with Scarce Resources
4282
4283 \1f
4284 File: tar.info,  Node: Reading,  Next: Writing,  Up: extract options
4285
4286 4.4.1 Options to Help Read Archives
4287 -----------------------------------
4288
4289 Normally, `tar' will request data in full record increments from an
4290 archive storage device.  If the device cannot return a full record,
4291 `tar' will report an error.  However, some devices do not always return
4292 full records, or do not require the last record of an archive to be
4293 padded out to the next record boundary.  To keep reading until you
4294 obtain a full record, or to accept an incomplete record if it contains
4295 an end-of-archive marker, specify the `--read-full-records' (`-B')
4296 option in conjunction with the `--extract' or `--list' operations.
4297 *Note Blocking::.
4298
4299    The `--read-full-records' (`-B') option is turned on by default when
4300 `tar' reads an archive from standard input, or from a remote machine.
4301 This is because on BSD Unix systems, attempting to read a pipe returns
4302 however much happens to be in the pipe, even if it is less than was
4303 requested.  If this option were not enabled, `tar' would fail as soon
4304 as it read an incomplete record from the pipe.
4305
4306    If you're not sure of the blocking factor of an archive, you can
4307 read the archive by specifying `--read-full-records' (`-B') and
4308 `--blocking-factor=512-SIZE' (`-b 512-SIZE'), using a blocking factor
4309 larger than what the archive uses.  This lets you avoid having to
4310 determine the blocking factor of an archive.  *Note Blocking Factor::.
4311
4312 * Menu:
4313
4314 * read full records::
4315 * Ignore Zeros::
4316
4317 \1f
4318 File: tar.info,  Node: read full records,  Next: Ignore Zeros,  Up: Reading
4319
4320 Reading Full Records
4321 ....................
4322
4323 `--read-full-records'
4324
4325 `-B'
4326      Use in conjunction with `--extract' (`--get', `-x') to read an
4327      archive which contains incomplete records, or one which has a
4328      blocking factor less than the one specified.
4329
4330 \1f
4331 File: tar.info,  Node: Ignore Zeros,  Prev: read full records,  Up: Reading
4332
4333 Ignoring Blocks of Zeros
4334 ........................
4335
4336 Normally, `tar' stops reading when it encounters a block of zeros
4337 between file entries (which usually indicates the end of the archive).
4338 `--ignore-zeros' (`-i') allows `tar' to completely read an archive
4339 which contains a block of zeros before the end (i.e., a damaged
4340 archive, or one that was created by concatenating several archives
4341 together).
4342
4343    The `--ignore-zeros' (`-i') option is turned off by default because
4344 many versions of `tar' write garbage after the end-of-archive entry,
4345 since that part of the media is never supposed to be read.  GNU `tar'
4346 does not write after the end of an archive, but seeks to maintain
4347 compatibility among archiving utilities.
4348
4349 `--ignore-zeros'
4350 `-i'
4351      To ignore blocks of zeros (i.e., end-of-archive entries) which may
4352      be encountered while reading an archive.  Use in conjunction with
4353      `--extract' or `--list'.
4354
4355 \1f
4356 File: tar.info,  Node: Writing,  Next: Scarce,  Prev: Reading,  Up: extract options
4357
4358 4.4.2 Changing How `tar' Writes Files
4359 -------------------------------------
4360
4361      _(This message will disappear, once this node revised.)_
4362
4363 * Menu:
4364
4365 * Dealing with Old Files::
4366 * Overwrite Old Files::
4367 * Keep Old Files::
4368 * Keep Newer Files::
4369 * Unlink First::
4370 * Recursive Unlink::
4371 * Data Modification Times::
4372 * Setting Access Permissions::
4373 * Directory Modification Times and Permissions::
4374 * Writing to Standard Output::
4375 * Writing to an External Program::
4376 * remove files::
4377
4378 \1f
4379 File: tar.info,  Node: Dealing with Old Files,  Next: Overwrite Old Files,  Up: Writing
4380
4381 Options Controlling the Overwriting of Existing Files
4382 .....................................................
4383
4384 When extracting files, if `tar' discovers that the extracted file
4385 already exists, it normally replaces the file by removing it before
4386 extracting it, to prevent confusion in the presence of hard or symbolic
4387 links.  (If the existing file is a symbolic link, it is removed, not
4388 followed.)  However, if a directory cannot be removed because it is
4389 nonempty, `tar' normally overwrites its metadata (ownership,
4390 permission, etc.).  The `--overwrite-dir' option enables this default
4391 behavior.  To be more cautious and preserve the metadata of such a
4392 directory, use the `--no-overwrite-dir' option.
4393
4394    To be even more cautious and prevent existing files from being
4395 replaced, use the `--keep-old-files' (`-k') option.  It causes `tar' to
4396 refuse to replace or update a file that already exists, i.e., a file
4397 with the same name as an archive member prevents extraction of that
4398 archive member.  Instead, it reports an error.
4399
4400    To be more aggressive about altering existing files, use the
4401 `--overwrite' option.  It causes `tar' to overwrite existing files and
4402 to follow existing symbolic links when extracting.
4403
4404    Some people argue that GNU `tar' should not hesitate to overwrite
4405 files with other files when extracting.  When extracting a `tar'
4406 archive, they expect to see a faithful copy of the state of the file
4407 system when the archive was created.  It is debatable that this would
4408 always be a proper behavior.  For example, suppose one has an archive
4409 in which `usr/local' is a link to `usr/local2'.  Since then, maybe the
4410 site removed the link and renamed the whole hierarchy from
4411 `/usr/local2' to `/usr/local'.  Such things happen all the time.  I
4412 guess it would not be welcome at all that GNU `tar' removes the whole
4413 hierarchy just to make room for the link to be reinstated (unless it
4414 _also_ simultaneously restores the full `/usr/local2', of course!)  GNU
4415 `tar' is indeed able to remove a whole hierarchy to reestablish a
4416 symbolic link, for example, but _only if_ `--recursive-unlink' is
4417 specified to allow this behavior.  In any case, single files are
4418 silently removed.
4419
4420    Finally, the `--unlink-first' (`-U') option can improve performance
4421 in some cases by causing `tar' to remove files unconditionally before
4422 extracting them.
4423
4424 \1f
4425 File: tar.info,  Node: Overwrite Old Files,  Next: Keep Old Files,  Prev: Dealing with Old Files,  Up: Writing
4426
4427 Overwrite Old Files
4428 ...................
4429
4430 `--overwrite'
4431      Overwrite existing files and directory metadata when extracting
4432      files from an archive.
4433
4434      This causes `tar' to write extracted files into the file system
4435      without regard to the files already on the system; i.e., files
4436      with the same names as archive members are overwritten when the
4437      archive is extracted.  It also causes `tar' to extract the
4438      ownership, permissions, and time stamps onto any preexisting files
4439      or directories.  If the name of a corresponding file name is a
4440      symbolic link, the file pointed to by the symbolic link will be
4441      overwritten instead of the symbolic link itself (if this is
4442      possible).  Moreover, special devices, empty directories and even
4443      symbolic links are automatically removed if they are in the way of
4444      extraction.
4445
4446      Be careful when using the `--overwrite' option, particularly when
4447      combined with the `--absolute-names' (`-P') option, as this
4448      combination can change the contents, ownership or permissions of
4449      any file on your system.  Also, many systems do not take kindly to
4450      overwriting files that are currently being executed.
4451
4452 `--overwrite-dir'
4453      Overwrite the metadata of directories when extracting files from an
4454      archive, but remove other files before extracting.
4455
4456 \1f
4457 File: tar.info,  Node: Keep Old Files,  Next: Keep Newer Files,  Prev: Overwrite Old Files,  Up: Writing
4458
4459 Keep Old Files
4460 ..............
4461
4462 `--keep-old-files'
4463 `-k'
4464      Do not replace existing files from archive.  The
4465      `--keep-old-files' (`-k') option prevents `tar' from replacing
4466      existing files with files with the same name from the archive. The
4467      `--keep-old-files' option is meaningless with `--list' (`-t').
4468      Prevents `tar' from replacing files in the file system during
4469      extraction.
4470
4471 \1f
4472 File: tar.info,  Node: Keep Newer Files,  Next: Unlink First,  Prev: Keep Old Files,  Up: Writing
4473
4474 Keep Newer Files
4475 ................
4476
4477 `--keep-newer-files'
4478      Do not replace existing files that are newer than their archive
4479      copies.  This option is meaningless with `--list' (`-t').
4480
4481 \1f
4482 File: tar.info,  Node: Unlink First,  Next: Recursive Unlink,  Prev: Keep Newer Files,  Up: Writing
4483
4484 Unlink First
4485 ............
4486
4487 `--unlink-first'
4488 `-U'
4489      Remove files before extracting over them.  This can make `tar' run
4490      a bit faster if you know in advance that the extracted files all
4491      need to be removed.  Normally this option slows `tar' down
4492      slightly, so it is disabled by default.
4493
4494 \1f
4495 File: tar.info,  Node: Recursive Unlink,  Next: Data Modification Times,  Prev: Unlink First,  Up: Writing
4496
4497 Recursive Unlink
4498 ................
4499
4500 `--recursive-unlink'
4501      When this option is specified, try removing files and directory
4502      hierarchies before extracting over them.  _This is a dangerous
4503      option!_
4504
4505    If you specify the `--recursive-unlink' option, `tar' removes
4506 _anything_ that keeps you from extracting a file as far as current
4507 permissions will allow it.  This could include removal of the contents
4508 of a full directory hierarchy.
4509
4510 \1f
4511 File: tar.info,  Node: Data Modification Times,  Next: Setting Access Permissions,  Prev: Recursive Unlink,  Up: Writing
4512
4513 Setting Data Modification Times
4514 ...............................
4515
4516 Normally, `tar' sets the data modification times of extracted files to
4517 the corresponding times recorded for the files in the archive, but
4518 limits the permissions of extracted files by the current `umask'
4519 setting.
4520
4521    To set the data modification times of extracted files to the time
4522 when the files were extracted, use the `--touch' (`-m') option in
4523 conjunction with `--extract' (`--get', `-x').
4524
4525 `--touch'
4526 `-m'
4527      Sets the data modification time of extracted archive members to
4528      the time they were extracted, not the time recorded for them in
4529      the archive.  Use in conjunction with `--extract' (`--get', `-x').
4530
4531 \1f
4532 File: tar.info,  Node: Setting Access Permissions,  Next: Directory Modification Times and Permissions,  Prev: Data Modification Times,  Up: Writing
4533
4534 Setting Access Permissions
4535 ..........................
4536
4537 To set the modes (access permissions) of extracted files to those
4538 recorded for those files in the archive, use `--same-permissions' in
4539 conjunction with the `--extract' (`--get', `-x') operation.
4540
4541 `--preserve-permissions'
4542 `--same-permissions'
4543 `-p'
4544      Set modes of extracted archive members to those recorded in the
4545      archive, instead of current umask settings.  Use in conjunction
4546      with `--extract' (`--get', `-x').
4547
4548 \1f
4549 File: tar.info,  Node: Directory Modification Times and Permissions,  Next: Writing to Standard Output,  Prev: Setting Access Permissions,  Up: Writing
4550
4551 Directory Modification Times and Permissions
4552 ............................................
4553
4554 After successfully extracting a file member, GNU `tar' normally
4555 restores its permissions and modification times, as described in the
4556 previous sections.  This cannot be done for directories, because after
4557 extracting a directory `tar' will almost certainly extract files into
4558 that directory and this will cause the directory modification time to
4559 be updated.  Moreover, restoring that directory permissions may not
4560 permit file creation within it.  Thus, restoring directory permissions
4561 and modification times must be delayed at least until all files have
4562 been extracted into that directory.  GNU `tar' restores directories
4563 using the following approach.
4564
4565    The extracted directories are created with the mode specified in the
4566 archive, as modified by the umask of the user, which gives sufficient
4567 permissions to allow file creation.  The meta-information about the
4568 directory is recorded in the temporary list of directories.  When
4569 preparing to extract next archive member, GNU `tar' checks if the
4570 directory prefix of this file contains the remembered directory.  If it
4571 does not, the program assumes that all files have been extracted into
4572 that directory, restores its modification time and permissions and
4573 removes its entry from the internal list.  This approach allows to
4574 correctly restore directory meta-information in the majority of cases,
4575 while keeping memory requirements sufficiently small.  It is based on
4576 the fact, that most `tar' archives use the predefined order of members:
4577 first the directory, then all the files and subdirectories in that
4578 directory.
4579
4580    However, this is not always true.  The most important exception are
4581 incremental archives (*note Incremental Dumps::).  The member order in
4582 an incremental archive is reversed: first all directory members are
4583 stored, followed by other (non-directory) members.  So, when extracting
4584 from incremental archives, GNU `tar' alters the above procedure.  It
4585 remembers all restored directories, and restores their meta-data only
4586 after the entire archive has been processed.  Notice, that you do not
4587 need to specify any special options for that, as GNU `tar'
4588 automatically detects archives in incremental format.
4589
4590    There may be cases, when such processing is required for normal
4591 archives too.  Consider the following example:
4592
4593      $ tar --no-recursion -cvf archive \
4594          foo foo/file1 bar bar/file foo/file2
4595      foo/
4596      foo/file1
4597      bar/
4598      bar/file
4599      foo/file2
4600
4601    During the normal operation, after encountering `bar' GNU `tar' will
4602 assume that all files from the directory `foo' were already extracted
4603 and will therefore restore its timestamp and permission bits.  However,
4604 after extracting `foo/file2' the directory timestamp will be offset
4605 again.
4606
4607    To correctly restore directory meta-information in such cases, use
4608 the `--delay-directory-restore' command line option:
4609
4610 `--delay-directory-restore'
4611      Delays restoring of the modification times and permissions of
4612      extracted directories until the end of extraction.  This way,
4613      correct meta-information is restored even if the archive has
4614      unusual member ordering.
4615
4616 `--no-delay-directory-restore'
4617      Cancel the effect of the previous `--delay-directory-restore'.
4618      Use this option if you have used `--delay-directory-restore' in
4619      `TAR_OPTIONS' variable (*note TAR_OPTIONS::) and wish to
4620      temporarily disable it.
4621
4622 \1f
4623 File: tar.info,  Node: Writing to Standard Output,  Next: Writing to an External Program,  Prev: Directory Modification Times and Permissions,  Up: Writing
4624
4625 Writing to Standard Output
4626 ..........................
4627
4628 To write the extracted files to the standard output, instead of
4629 creating the files on the file system, use `--to-stdout' (`-O') in
4630 conjunction with `--extract' (`--get', `-x').  This option is useful if
4631 you are extracting files to send them through a pipe, and do not need to
4632 preserve them in the file system.  If you extract multiple members,
4633 they appear on standard output concatenated, in the order they are
4634 found in the archive.
4635
4636 `--to-stdout'
4637 `-O'
4638      Writes files to the standard output.  Use only in conjunction with
4639      `--extract' (`--get', `-x').  When this option is used, instead of
4640      creating the files specified, `tar' writes the contents of the
4641      files extracted to its standard output.  This may be useful if you
4642      are only extracting the files in order to send them through a
4643      pipe.  This option is meaningless with `--list' (`-t').
4644
4645    This can be useful, for example, if you have a tar archive containing
4646 a big file and don't want to store the file on disk before processing
4647 it.  You can use a command like this:
4648
4649      tar -xOzf foo.tgz bigfile | process
4650
4651    or even like this if you want to process the concatenation of the
4652 files:
4653
4654      tar -xOzf foo.tgz bigfile1 bigfile2 | process
4655
4656    However, `--to-command' may be more convenient for use with multiple
4657 files. See the next section.
4658
4659 \1f
4660 File: tar.info,  Node: Writing to an External Program,  Next: remove files,  Prev: Writing to Standard Output,  Up: Writing
4661
4662 Writing to an External Program
4663 ..............................
4664
4665 You can instruct `tar' to send the contents of each extracted file to
4666 the standard input of an external program:
4667
4668 `--to-command=COMMAND'
4669      Extract files and pipe their contents to the standard input of
4670      COMMAND. When this option is used, instead of creating the files
4671      specified, `tar' invokes COMMAND and pipes the contents of the
4672      files to its standard output. The COMMAND may contain command line
4673      arguments. The program is executed via `sh -c'. Notice, that
4674      COMMAND is executed once for each regular file extracted.
4675      Non-regular files (directories, etc.) are ignored when this option
4676      is used.
4677
4678    The command can obtain the information about the file it processes
4679 from the following environment variables:
4680
4681 `TAR_FILETYPE'
4682      Type of the file. It is a single letter with the following meaning:
4683
4684      f       Regular file
4685      d       Directory
4686      l       Symbolic link
4687      h       Hard link
4688      b       Block device
4689      c       Character device
4690
4691      Currently only regular files are supported.
4692
4693 `TAR_MODE'
4694      File mode, an octal number.
4695
4696 `TAR_FILENAME'
4697      The name of the file.
4698
4699 `TAR_REALNAME'
4700      Name of the file as stored in the archive.
4701
4702 `TAR_UNAME'
4703      Name of the file owner.
4704
4705 `TAR_GNAME'
4706      Name of the file owner group.
4707
4708 `TAR_ATIME'
4709      Time of last access. It is a decimal number, representing seconds
4710      since the Epoch.  If the archive provides times with nanosecond
4711      precision, the nanoseconds are appended to the timestamp after a
4712      decimal point.
4713
4714 `TAR_MTIME'
4715      Time of last modification.
4716
4717 `TAR_CTIME'
4718      Time of last status change.
4719
4720 `TAR_SIZE'
4721      Size of the file.
4722
4723 `TAR_UID'
4724      UID of the file owner.
4725
4726 `TAR_GID'
4727      GID of the file owner.
4728
4729    Additionally, the following variables contain information about tar
4730 mode and the archive being processed:
4731
4732 `TAR_VERSION'
4733      GNU `tar' version number.
4734
4735 `TAR_ARCHIVE'
4736      The name of the archive `tar' is processing.
4737
4738 `TAR_BLOCKING_FACTOR'
4739      Current blocking factor (*note Blocking::).
4740
4741 `TAR_VOLUME'
4742      Ordinal number of the volume `tar' is processing.
4743
4744 `TAR_FORMAT'
4745      Format of the archive being processed. *Note Formats::, for a
4746      complete list of archive format names.
4747
4748    If COMMAND exits with a non-0 status, `tar' will print an error
4749 message similar to the following:
4750
4751      tar: 2345: Child returned status 1
4752
4753    Here, `2345' is the PID of the finished process.
4754
4755    If this behavior is not wanted, use `--ignore-command-error':
4756
4757 `--ignore-command-error'
4758      Ignore exit codes of subprocesses.  Notice that if the program
4759      exits on signal or otherwise terminates abnormally, the error
4760      message will be printed even if this option is used.
4761
4762 `--no-ignore-command-error'
4763      Cancel the effect of any previous `--ignore-command-error' option.
4764      This option is useful if you have set `--ignore-command-error' in
4765      `TAR_OPTIONS' (*note TAR_OPTIONS::) and wish to temporarily cancel
4766      it.
4767
4768 \1f
4769 File: tar.info,  Node: remove files,  Prev: Writing to an External Program,  Up: Writing
4770
4771 Removing Files
4772 ..............
4773
4774 `--remove-files'
4775      Remove files after adding them to the archive.
4776
4777 \1f
4778 File: tar.info,  Node: Scarce,  Prev: Writing,  Up: extract options
4779
4780 4.4.3 Coping with Scarce Resources
4781 ----------------------------------
4782
4783      _(This message will disappear, once this node revised.)_
4784
4785 * Menu:
4786
4787 * Starting File::
4788 * Same Order::
4789
4790 \1f
4791 File: tar.info,  Node: Starting File,  Next: Same Order,  Up: Scarce
4792
4793 Starting File
4794 .............
4795
4796 `--starting-file=NAME'
4797 `-K NAME'
4798      Starts an operation in the middle of an archive.  Use in
4799      conjunction with `--extract' (`--get', `-x') or `--list' (`-t').
4800
4801    If a previous attempt to extract files failed due to lack of disk
4802 space, you can use `--starting-file=NAME' (`-K NAME') to start
4803 extracting only after member NAME of the archive.  This assumes, of
4804 course, that there is now free space, or that you are now extracting
4805 into a different file system.  (You could also choose to suspend `tar',
4806 remove unnecessary files from the file system, and then resume the same
4807 `tar' operation.  In this case, `--starting-file' is not necessary.)
4808 See also *note interactive::, and *note exclude::.
4809
4810 \1f
4811 File: tar.info,  Node: Same Order,  Prev: Starting File,  Up: Scarce
4812
4813 Same Order
4814 ..........
4815
4816 `--same-order'
4817 `--preserve-order'
4818 `-s'
4819      To process large lists of file names on machines with small
4820      amounts of memory.  Use in conjunction with `--compare' (`--diff',
4821      `-d'), `--list' (`-t') or `--extract' (`--get', `-x').
4822
4823    The `--same-order' (`--preserve-order', `-s') option tells `tar'
4824 that the list of file names to be listed or extracted is sorted in the
4825 same order as the files in the archive.  This allows a large list of
4826 names to be used, even on a small machine that would not otherwise be
4827 able to hold all the names in memory at the same time.  Such a sorted
4828 list can easily be created by running `tar -t' on the archive and
4829 editing its output.
4830
4831    This option is probably never needed on modern computer systems.
4832
4833 \1f
4834 File: tar.info,  Node: backup,  Next: Applications,  Prev: extract options,  Up: operations
4835
4836 4.5 Backup options
4837 ==================
4838
4839 GNU `tar' offers options for making backups of files before writing new
4840 versions.  These options control the details of these backups.  They
4841 may apply to the archive itself before it is created or rewritten, as
4842 well as individual extracted members.  Other GNU programs (`cp',
4843 `install', `ln', and `mv', for example) offer similar options.
4844
4845    Backup options may prove unexpectedly useful when extracting archives
4846 containing many members having identical name, or when extracting
4847 archives on systems having file name limitations, making different
4848 members appear as having similar names through the side-effect of name
4849 truncation.
4850
4851    When any existing file is backed up before being overwritten by
4852 extraction, then clashing files are automatically be renamed to be
4853 unique, and the true name is kept for only the last file of a series of
4854 clashing files.  By using verbose mode, users may track exactly what
4855 happens.
4856
4857    At the detail level, some decisions are still experimental, and may
4858 change in the future, we are waiting comments from our users.  So,
4859 please do not learn to depend blindly on the details of the backup
4860 features.  For example, currently, directories themselves are never
4861 renamed through using these options, so, extracting a file over a
4862 directory still has good chances to fail.  Also, backup options apply
4863 to created archives, not only to extracted members.  For created
4864 archives, backups will not be attempted when the archive is a block or
4865 character device, or when it refers to a remote file.
4866
4867    For the sake of simplicity and efficiency, backups are made by
4868 renaming old files prior to creation or extraction, and not by copying.
4869 The original name is restored if the file creation fails.  If a failure
4870 occurs after a partial extraction of a file, both the backup and the
4871 partially extracted file are kept.
4872
4873 `--backup[=METHOD]'
4874      Back up files that are about to be overwritten or removed.
4875      Without this option, the original versions are destroyed.
4876
4877      Use METHOD to determine the type of backups made.  If METHOD is
4878      not specified, use the value of the `VERSION_CONTROL' environment
4879      variable.  And if `VERSION_CONTROL' is not set, use the `existing'
4880      method.
4881
4882      This option corresponds to the Emacs variable `version-control';
4883      the same values for METHOD are accepted as in Emacs.  This option
4884      also allows more descriptive names.  The valid METHODs are:
4885
4886     `t'
4887     `numbered'
4888           Always make numbered backups.
4889
4890     `nil'
4891     `existing'
4892           Make numbered backups of files that already have them, simple
4893           backups of the others.
4894
4895     `never'
4896     `simple'
4897           Always make simple backups.
4898
4899
4900 `--suffix=SUFFIX'
4901      Append SUFFIX to each backup file made with `--backup'.  If this
4902      option is not specified, the value of the `SIMPLE_BACKUP_SUFFIX'
4903      environment variable is used.  And if `SIMPLE_BACKUP_SUFFIX' is not
4904      set, the default is `~', just as in Emacs.
4905
4906
4907 \1f
4908 File: tar.info,  Node: Applications,  Next: looking ahead,  Prev: backup,  Up: operations
4909
4910 4.6 Notable `tar' Usages
4911 ========================
4912
4913      _(This message will disappear, once this node revised.)_
4914
4915 You can easily use archive files to transport a group of files from one
4916 system to another: put all relevant files into an archive on one
4917 computer system, transfer the archive to another system, and extract
4918 the contents there.  The basic transfer medium might be magnetic tape,
4919 Internet FTP, or even electronic mail (though you must encode the
4920 archive with `uuencode' in order to transport it properly by mail).
4921 Both machines do not have to use the same operating system, as long as
4922 they both support the `tar' program.
4923
4924    For example, here is how you might copy a directory's contents from
4925 one disk to another, while preserving the dates, modes, owners and
4926 link-structure of all the files therein.  In this case, the transfer
4927 medium is a "pipe":
4928
4929      $ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xf -)
4930
4931 You can avoid subshells by using `-C' option:
4932
4933      $ tar -C sourcedir -cf - . | tar -C targetdir -xf -
4934
4935 The command also works using long option forms:
4936
4937      $ (cd sourcedir; tar --create --file=- . ) \
4938             | (cd targetdir; tar --extract --file=-)
4939
4940 or
4941
4942      $ tar --directory sourcedir --create --file=- . \
4943             | tar --directory targetdir --extract --file=-
4944
4945 This is one of the easiest methods to transfer a `tar' archive.
4946
4947 \1f
4948 File: tar.info,  Node: looking ahead,  Prev: Applications,  Up: operations
4949
4950 4.7 Looking Ahead: The Rest of this Manual
4951 ==========================================
4952
4953 You have now seen how to use all eight of the operations available to
4954 `tar', and a number of the possible options.  The next chapter explains
4955 how to choose and change file and archive names, how to use files to
4956 store names of other files which you can then call as arguments to
4957 `tar' (this can help you save time if you expect to archive the same
4958 list of files a number of times), and so forth.
4959
4960    If there are too many files to conveniently list on the command line,
4961 you can list the names in a file, and `tar' will read that file.  *Note
4962 files::.
4963
4964    There are various ways of causing `tar' to skip over some files, and
4965 not archive them.  *Note Choosing::.
4966
4967 \1f
4968 File: tar.info,  Node: Backups,  Next: Choosing,  Prev: operations,  Up: Top
4969
4970 5 Performing Backups and Restoring Files
4971 ****************************************
4972
4973 GNU `tar' is distributed along with the scripts for performing backups
4974 and restores.  Even if there is a good chance those scripts may be
4975 satisfying to you, they are not the only scripts or methods available
4976 for doing backups and restore.  You may well create your own, or use
4977 more sophisticated packages dedicated to that purpose.
4978
4979    Some users are enthusiastic about `Amanda' (The Advanced Maryland
4980 Automatic Network Disk Archiver), a backup system developed by James da
4981 Silva `jds@cs.umd.edu' and available on many Unix systems.  This is
4982 free software, and it is available from `http://www.amanda.org'.
4983
4984    This chapter documents both the provided shell scripts and `tar'
4985 options which are more specific to usage as a backup tool.
4986
4987    To "back up" a file system means to create archives that contain all
4988 the files in that file system.  Those archives can then be used to
4989 restore any or all of those files (for instance if a disk crashes or a
4990 file is accidentally deleted).  File system "backups" are also called
4991 "dumps".
4992
4993 * Menu:
4994
4995 * Full Dumps::                  Using `tar' to Perform Full Dumps
4996 * Incremental Dumps::           Using `tar' to Perform Incremental Dumps
4997 * Backup Levels::               Levels of Backups
4998 * Backup Parameters::           Setting Parameters for Backups and Restoration
4999 * Scripted Backups::            Using the Backup Scripts
5000 * Scripted Restoration::        Using the Restore Script
5001
5002 \1f
5003 File: tar.info,  Node: Full Dumps,  Next: Incremental Dumps,  Up: Backups
5004
5005 5.1 Using `tar' to Perform Full Dumps
5006 =====================================
5007
5008      _(This message will disappear, once this node revised.)_
5009
5010 Full dumps should only be made when no other people or programs are
5011 modifying files in the file system.  If files are modified while `tar'
5012 is making the backup, they may not be stored properly in the archive,
5013 in which case you won't be able to restore them if you have to.  (Files
5014 not being modified are written with no trouble, and do not corrupt the
5015 entire archive.)
5016
5017    You will want to use the `--label=ARCHIVE-LABEL' (`-V
5018 ARCHIVE-LABEL') option to give the archive a volume label, so you can
5019 tell what this archive is even if the label falls off the tape, or
5020 anything like that.
5021
5022    Unless the file system you are dumping is guaranteed to fit on one
5023 volume, you will need to use the `--multi-volume' (`-M') option.  Make
5024 sure you have enough tapes on hand to complete the backup.
5025
5026    If you want to dump each file system separately you will need to use
5027 the `--one-file-system' option to prevent `tar' from crossing file
5028 system boundaries when storing (sub)directories.
5029
5030    The `--incremental' (`-G') (*note Incremental Dumps::) option is not
5031 needed, since this is a complete copy of everything in the file system,
5032 and a full restore from this backup would only be done onto a completely
5033 empty disk.
5034
5035    Unless you are in a hurry, and trust the `tar' program (and your
5036 tapes), it is a good idea to use the `--verify' (`-W') option, to make
5037 sure your files really made it onto the dump properly.  This will also
5038 detect cases where the file was modified while (or just after) it was
5039 being archived.  Not all media (notably cartridge tapes) are capable of
5040 being verified, unfortunately.
5041
5042 \1f
5043 File: tar.info,  Node: Incremental Dumps,  Next: Backup Levels,  Prev: Full Dumps,  Up: Backups
5044
5045 5.2 Using `tar' to Perform Incremental Dumps
5046 ============================================
5047
5048 "Incremental backup" is a special form of GNU `tar' archive that stores
5049 additional metadata so that exact state of the file system can be
5050 restored when extracting the archive.
5051
5052    GNU `tar' currently offers two options for handling incremental
5053 backups: `--listed-incremental=SNAPSHOT-FILE' (`-g SNAPSHOT-FILE') and
5054 `--incremental' (`-G').
5055
5056    The option `--listed-incremental' instructs tar to operate on an
5057 incremental archive with additional metadata stored in a standalone
5058 file, called a "snapshot file".  The purpose of this file is to help
5059 determine which files have been changed, added or deleted since the
5060 last backup, so that the next incremental backup will contain only
5061 modified files.  The name of the snapshot file is given as an argument
5062 to the option:
5063
5064 `--listed-incremental=FILE'
5065 `-g FILE'
5066      Handle incremental backups with snapshot data in FILE.
5067
5068    To create an incremental backup, you would use
5069 `--listed-incremental' together with `--create' (*note create::).  For
5070 example:
5071
5072      $ tar --create \
5073                 --file=archive.1.tar \
5074                 --listed-incremental=/var/log/usr.snar \
5075                 /usr
5076
5077    This will create in `archive.1.tar' an incremental backup of the
5078 `/usr' file system, storing additional metadata in the file
5079 `/var/log/usr.snar'.  If this file does not exist, it will be created.
5080 The created archive will then be a "level 0 backup"; please see the
5081 next section for more on backup levels.
5082
5083    Otherwise, if the file `/var/log/usr.snar' exists, it determines
5084 which files are modified.  In this case only these files will be stored
5085 in the archive.  Suppose, for example, that after running the above
5086 command, you delete file `/usr/doc/old' and create directory
5087 `/usr/local/db' with the following contents:
5088
5089      $ ls /usr/local/db
5090      /usr/local/db/data
5091      /usr/local/db/index
5092
5093    Some time later you create another incremental backup.  You will
5094 then see:
5095
5096      $ tar --create \
5097                 --file=archive.2.tar \
5098                 --listed-incremental=/var/log/usr.snar \
5099                 /usr
5100      tar: usr/local/db: Directory is new
5101      usr/local/db/
5102      usr/local/db/data
5103      usr/local/db/index
5104
5105 The created archive `archive.2.tar' will contain only these three
5106 members.  This archive is called a "level 1 backup".  Notice that
5107 `/var/log/usr.snar' will be updated with the new data, so if you plan
5108 to create more `level 1' backups, it is necessary to create a working
5109 copy of the snapshot file before running `tar'.  The above example will
5110 then be modified as follows:
5111
5112      $ cp /var/log/usr.snar /var/log/usr.snar-1
5113      $ tar --create \
5114                 --file=archive.2.tar \
5115                 --listed-incremental=/var/log/usr.snar-1 \
5116                 /usr
5117
5118    You can force `level 0' backups either by removing the snapshot file
5119 before running `tar', or by supplying the `--level=0' option, e.g.:
5120
5121      $ tar --create \
5122                 --file=archive.2.tar \
5123                 --listed-incremental=/var/log/usr.snar-0 \
5124                 --level=0 \
5125                 /usr
5126
5127    Incremental dumps depend crucially on time stamps, so the results are
5128 unreliable if you modify a file's time stamps during dumping (e.g.,
5129 with the `--atime-preserve=replace' option), or if you set the clock
5130 backwards.
5131
5132    Metadata stored in snapshot files include device numbers, which,
5133 obviously are supposed to be non-volatile values.  However, it turns
5134 out that NFS devices have undependable values when an automounter gets
5135 in the picture.  This can lead to a great deal of spurious redumping in
5136 incremental dumps, so it is somewhat useless to compare two NFS devices
5137 numbers over time.  The solution implemented currently is to consider
5138 all NFS devices as being equal when it comes to comparing directories;
5139 this is fairly gross, but there does not seem to be a better way to go.
5140
5141    Apart from using NFS, there are a number of cases where relying on
5142 device numbers can cause spurious redumping of unmodified files.  For
5143 example, this occurs when archiving LVM snapshot volumes.  To avoid
5144 this, use `--no-check-device' option:
5145
5146 `--no-check-device'
5147      Do not rely on device numbers when preparing a list of changed
5148      files for an incremental dump.
5149
5150 `--check-device'
5151      Use device numbers when preparing a list of changed files for an
5152      incremental dump.  This is the default behavior.  The purpose of
5153      this option is to undo the effect of the `--no-check-device' if it
5154      was given in `TAR_OPTIONS' environment variable (*note
5155      TAR_OPTIONS::).
5156
5157    There is also another way to cope with changing device numbers.  It
5158 is described in detail in *note Fixing Snapshot Files::.
5159
5160    Note that incremental archives use `tar' extensions and may not be
5161 readable by non-GNU versions of the `tar' program.
5162
5163    To extract from the incremental dumps, use `--listed-incremental'
5164 together with `--extract' option (*note extracting files::).  In this
5165 case, `tar' does not need to access snapshot file, since all the data
5166 necessary for extraction are stored in the archive itself.  So, when
5167 extracting, you can give whatever argument to `--listed-incremental',
5168 the usual practice is to use `--listed-incremental=/dev/null'.
5169 Alternatively, you can use `--incremental', which needs no arguments.
5170 In general, `--incremental' (`-G') can be used as a shortcut for
5171 `--listed-incremental' when listing or extracting incremental backups
5172 (for more information regarding this option, *note incremental-op::).
5173
5174    When extracting from the incremental backup GNU `tar' attempts to
5175 restore the exact state the file system had when the archive was
5176 created.  In particular, it will _delete_ those files in the file
5177 system that did not exist in their directories when the archive was
5178 created.  If you have created several levels of incremental files, then
5179 in order to restore the exact contents the file system  had when the
5180 last level was created, you will need to restore from all backups in
5181 turn.  Continuing our example, to restore the state of `/usr' file
5182 system, one would do(1):
5183
5184      $ tar --extract \
5185                 --listed-incremental=/dev/null \
5186                 --file archive.1.tar
5187      $ tar --extract \
5188                 --listed-incremental=/dev/null \
5189                 --file archive.2.tar
5190
5191    To list the contents of an incremental archive, use `--list' (*note
5192 list::), as usual.  To obtain more information about the archive, use
5193 `--listed-incremental' or `--incremental' combined with two `--verbose'
5194 options(2):
5195
5196      tar --list --incremental --verbose --verbose archive.tar
5197
5198    This command will print, for each directory in the archive, the list
5199 of files in that directory at the time the archive was created.  This
5200 information is put out in a format which is both human-readable and
5201 unambiguous for a program: each file name is printed as
5202
5203      X FILE
5204
5205 where X is a letter describing the status of the file: `Y' if the file
5206 is present in the archive, `N' if the file is not included in the
5207 archive, or a `D' if the file is a directory (and is included in the
5208 archive).  *Note Dumpdir::, for the detailed description of dumpdirs
5209 and status codes.  Each such line is terminated by a newline character.
5210 The last line is followed by an additional newline to indicate the end
5211 of the data.
5212
5213    The option `--incremental' (`-G') gives the same behavior as
5214 `--listed-incremental' when used with `--list' and `--extract' options.
5215 When used with `--create' option, it creates an incremental archive
5216 without creating snapshot file.  Thus, it is impossible to create
5217 several levels of incremental backups with `--incremental' option.
5218
5219    ---------- Footnotes ----------
5220
5221    (1) Notice, that since both archives were created without `-P'
5222 option (*note absolute::), these commands should be run from the root
5223 file system.
5224
5225    (2) Two `--verbose' options were selected to avoid breaking usual
5226 verbose listing output (`--list --verbose') when using in scripts.
5227
5228    Versions of GNU `tar' up to 1.15.1 used to dump verbatim binary
5229 contents of the DUMPDIR header (with terminating nulls) when
5230 `--incremental' or `--listed-incremental' option was given, no matter
5231 what the verbosity level.  This behavior, and, especially, the binary
5232 output it produced were considered inconvenient and were changed in
5233 version 1.16.
5234
5235 \1f
5236 File: tar.info,  Node: Backup Levels,  Next: Backup Parameters,  Prev: Incremental Dumps,  Up: Backups
5237
5238 5.3 Levels of Backups
5239 =====================
5240
5241 An archive containing all the files in the file system is called a
5242 "full backup" or "full dump".  You could insure your data by creating a
5243 full dump every day.  This strategy, however, would waste a substantial
5244 amount of archive media and user time, as unchanged files are daily
5245 re-archived.
5246
5247    It is more efficient to do a full dump only occasionally.  To back up
5248 files between full dumps, you can use "incremental dumps".  A "level
5249 one" dump archives all the files that have changed since the last full
5250 dump.
5251
5252    A typical dump strategy would be to perform a full dump once a week,
5253 and a level one dump once a day.  This means some versions of files
5254 will in fact be archived more than once, but this dump strategy makes
5255 it possible to restore a file system to within one day of accuracy by
5256 only extracting two archives--the last weekly (full) dump and the last
5257 daily (level one) dump.  The only information lost would be in files
5258 changed or created since the last daily backup.  (Doing dumps more than
5259 once a day is usually not worth the trouble.)
5260
5261    GNU `tar' comes with scripts you can use to do full and level-one
5262 (actually, even level-two and so on) dumps.  Using scripts (shell
5263 programs) to perform backups and restoration is a convenient and
5264 reliable alternative to typing out file name lists and `tar' commands
5265 by hand.
5266
5267    Before you use these scripts, you need to edit the file
5268 `backup-specs', which specifies parameters used by the backup scripts
5269 and by the restore script.  This file is usually located in
5270 `/etc/backup' directory.  *Note Backup Parameters::, for its detailed
5271 description.  Once the backup parameters are set, you can perform
5272 backups or restoration by running the appropriate script.
5273
5274    The name of the backup script is `backup'.  The name of the restore
5275 script is `restore'.  The following sections describe their use in
5276 detail.
5277
5278    _Please Note:_ The backup and restoration scripts are designed to be
5279 used together.  While it is possible to restore files by hand from an
5280 archive which was created using a backup script, and to create an
5281 archive by hand which could then be extracted using the restore script,
5282 it is easier to use the scripts.  *Note Incremental Dumps::, before
5283 making such an attempt.
5284
5285 \1f
5286 File: tar.info,  Node: Backup Parameters,  Next: Scripted Backups,  Prev: Backup Levels,  Up: Backups
5287
5288 5.4 Setting Parameters for Backups and Restoration
5289 ==================================================
5290
5291 The file `backup-specs' specifies backup parameters for the backup and
5292 restoration scripts provided with `tar'.  You must edit `backup-specs'
5293 to fit your system configuration and schedule before using these
5294 scripts.
5295
5296    Syntactically, `backup-specs' is a shell script, containing mainly
5297 variable assignments.  However, any valid shell construct is allowed in
5298 this file.  Particularly, you may wish to define functions within that
5299 script (e.g., see `RESTORE_BEGIN' below).  For more information about
5300 shell script syntax, please refer to the definition of the Shell
5301 Command Language
5302 (http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#ta
5303 g_02).  See also *note Bash Features: (bashref)Top.
5304
5305    The shell variables controlling behavior of `backup' and `restore'
5306 are described in the following subsections.
5307
5308 * Menu:
5309
5310 * General-Purpose Variables::
5311 * Magnetic Tape Control::
5312 * User Hooks::
5313 * backup-specs example::        An Example Text of `Backup-specs'
5314
5315 \1f
5316 File: tar.info,  Node: General-Purpose Variables,  Next: Magnetic Tape Control,  Up: Backup Parameters
5317
5318 5.4.1 General-Purpose Variables
5319 -------------------------------
5320
5321  -- Backup variable: ADMINISTRATOR
5322      The user name of the backup administrator.  `Backup' scripts sends
5323      a backup report to this address.
5324
5325  -- Backup variable: BACKUP_HOUR
5326      The hour at which the backups are done.  This can be a number from
5327      0 to 23, or the time specification in form HOURS:MINUTES, or the
5328      string `now'.
5329
5330      This variable is used by `backup'.  Its value may be overridden
5331      using `--time' option (*note Scripted Backups::).
5332
5333  -- Backup variable: TAPE_FILE
5334      The device `tar' writes the archive to.  If TAPE_FILE is a remote
5335      archive (*note remote-dev::), backup script will suppose that your
5336      `mt' is able to access remote devices.  If RSH (*note RSH::) is
5337      set, `--rsh-command' option will be added to invocations of `mt'.
5338
5339  -- Backup variable: BLOCKING
5340      The blocking factor `tar' will use when writing the dump archive.
5341      *Note Blocking Factor::.
5342
5343  -- Backup variable: BACKUP_DIRS
5344      A list of file systems to be dumped (for `backup'), or restored
5345      (for `restore').  You can include any directory name in the list
5346      -- subdirectories on that file system will be included, regardless
5347      of how they may look to other networked machines.  Subdirectories
5348      on other file systems will be ignored.
5349
5350      The host name specifies which host to run `tar' on, and should
5351      normally be the host that actually contains the file system.
5352      However, the host machine must have GNU `tar' installed, and must
5353      be able to access the directory containing the backup scripts and
5354      their support files using the same file name that is used on the
5355      machine where the scripts are run (i.e., what `pwd' will print
5356      when in that directory on that machine).  If the host that contains
5357      the file system does not have this capability, you can specify
5358      another host as long as it can access the file system through NFS.
5359
5360      If the list of file systems is very long you may wish to put it in
5361      a separate file.  This file is usually named `/etc/backup/dirs',
5362      but this name may be overridden in `backup-specs' using `DIRLIST'
5363      variable.
5364
5365  -- Backup variable: DIRLIST
5366      The name of the file that contains a list of file systems to backup
5367      or restore.  By default it is `/etc/backup/dirs'.
5368
5369  -- Backup variable: BACKUP_FILES
5370      A list of individual files to be dumped (for `backup'), or restored
5371      (for `restore').  These should be accessible from the machine on
5372      which the backup script is run.
5373
5374      If the list of individual files is very long you may wish to store
5375      it in a separate file.  This file is usually named
5376      `/etc/backup/files', but this name may be overridden in
5377      `backup-specs' using `FILELIST' variable.
5378
5379  -- Backup variable: FILELIST
5380      The name of the file that contains a list of individual files to
5381      backup or restore.  By default it is `/etc/backup/files'.
5382
5383  -- Backup variable: MT
5384      Full file name of `mt' binary.
5385
5386  -- Backup variable: RSH
5387      Full file name of `rsh' binary or its equivalent.  You may wish to
5388      set it to `ssh', to improve security.  In this case you will have
5389      to use public key authentication.
5390
5391  -- Backup variable: RSH_COMMAND
5392      Full file name of `rsh' binary on remote machines.  This will be
5393      passed via `--rsh-command' option to the remote invocation of GNU
5394      `tar'.
5395
5396  -- Backup variable: VOLNO_FILE
5397      Name of temporary file to hold volume numbers.  This needs to be
5398      accessible by all the machines which have file systems to be
5399      dumped.
5400
5401  -- Backup variable: XLIST
5402      Name of "exclude file list".  An "exclude file list" is a file
5403      located on the remote machine and containing the list of files to
5404      be excluded from the backup.  Exclude file lists are searched in
5405      /etc/tar-backup directory.  A common use for exclude file lists is
5406      to exclude files containing security-sensitive information (e.g.,
5407      `/etc/shadow' from backups).
5408
5409      This variable affects only `backup'.
5410
5411  -- Backup variable: SLEEP_TIME
5412      Time to sleep between dumps of any two successive file systems
5413
5414      This variable affects only `backup'.
5415
5416  -- Backup variable: DUMP_REMIND_SCRIPT
5417      Script to be run when it's time to insert a new tape in for the
5418      next volume.  Administrators may want to tailor this script for
5419      their site.  If this variable isn't set, GNU `tar' will display
5420      its built-in prompt, and will expect confirmation from the
5421      console.  For the description of the default prompt, see *note
5422      change volume prompt::.
5423
5424
5425  -- Backup variable: SLEEP_MESSAGE
5426      Message to display on the terminal while waiting for dump time.
5427      Usually this will just be some literal text.
5428
5429  -- Backup variable: TAR
5430      Full file name of the GNU `tar' executable.  If this is not set,
5431      backup scripts will search `tar' in the current shell path.
5432
5433 \1f
5434 File: tar.info,  Node: Magnetic Tape Control,  Next: User Hooks,  Prev: General-Purpose Variables,  Up: Backup Parameters
5435
5436 5.4.2 Magnetic Tape Control
5437 ---------------------------
5438
5439 Backup scripts access tape device using special "hook functions".
5440 These functions take a single argument -- the name of the tape device.
5441 Their names are kept in the following variables:
5442
5443  -- Backup variable: MT_BEGIN
5444      The name of "begin" function.  This function is called before
5445      accessing the drive.  By default it retensions the tape:
5446
5447           MT_BEGIN=mt_begin
5448
5449           mt_begin() {
5450               mt -f "$1" retension
5451           }
5452
5453  -- Backup variable: MT_REWIND
5454      The name of "rewind" function.  The default definition is as
5455      follows:
5456
5457           MT_REWIND=mt_rewind
5458
5459           mt_rewind() {
5460               mt -f "$1" rewind
5461           }
5462
5463
5464  -- Backup variable: MT_OFFLINE
5465      The name of the function switching the tape off line.  By default
5466      it is defined as follows:
5467
5468           MT_OFFLINE=mt_offline
5469
5470           mt_offline() {
5471               mt -f "$1" offl
5472           }
5473
5474  -- Backup variable: MT_STATUS
5475      The name of the function used to obtain the status of the archive
5476      device, including error count.  Default definition:
5477
5478           MT_STATUS=mt_status
5479
5480           mt_status() {
5481               mt -f "$1" status
5482           }
5483
5484 \1f
5485 File: tar.info,  Node: User Hooks,  Next: backup-specs example,  Prev: Magnetic Tape Control,  Up: Backup Parameters
5486
5487 5.4.3 User Hooks
5488 ----------------
5489
5490 "User hooks" are shell functions executed before and after each `tar'
5491 invocation.  Thus, there are "backup hooks", which are executed before
5492 and after dumping each file system, and "restore hooks", executed
5493 before and after restoring a file system.  Each user hook is a shell
5494 function taking four arguments:
5495
5496  -- User Hook Function: hook LEVEL HOST FS FSNAME
5497      Its arguments are:
5498
5499     LEVEL
5500           Current backup or restore level.
5501
5502     HOST
5503           Name or IP address of the host machine being dumped or
5504           restored.
5505
5506     FS
5507           Full file name of the file system being dumped or restored.
5508
5509     FSNAME
5510           File system name with directory separators replaced with
5511           colons.  This is useful, e.g., for creating unique files.
5512
5513    Following variables keep the names of user hook functions:
5514
5515  -- Backup variable: DUMP_BEGIN
5516      Dump begin function.  It is executed before dumping the file
5517      system.
5518
5519  -- Backup variable: DUMP_END
5520      Executed after dumping the file system.
5521
5522  -- Backup variable: RESTORE_BEGIN
5523      Executed before restoring the file system.
5524
5525  -- Backup variable: RESTORE_END
5526      Executed after restoring the file system.
5527
5528 \1f
5529 File: tar.info,  Node: backup-specs example,  Prev: User Hooks,  Up: Backup Parameters
5530
5531 5.4.4 An Example Text of `Backup-specs'
5532 ---------------------------------------
5533
5534 The following is an example of `backup-specs':
5535
5536      # site-specific parameters for file system backup.
5537
5538      ADMINISTRATOR=friedman
5539      BACKUP_HOUR=1
5540      TAPE_FILE=/dev/nrsmt0
5541
5542      # Use `ssh' instead of the less secure `rsh'
5543      RSH=/usr/bin/ssh
5544      RSH_COMMAND=/usr/bin/ssh
5545
5546      # Override MT_STATUS function:
5547      my_status() {
5548            mts -t $TAPE_FILE
5549      }
5550      MT_STATUS=my_status
5551
5552      # Disable MT_OFFLINE function
5553      MT_OFFLINE=:
5554
5555      BLOCKING=124
5556      BACKUP_DIRS="
5557              albert:/fs/fsf
5558              apple-gunkies:/gd
5559              albert:/fs/gd2
5560              albert:/fs/gp
5561              geech:/usr/jla
5562              churchy:/usr/roland
5563              albert:/
5564              albert:/usr
5565              apple-gunkies:/
5566              apple-gunkies:/usr
5567              gnu:/hack
5568              gnu:/u
5569              apple-gunkies:/com/mailer/gnu
5570              apple-gunkies:/com/archive/gnu"
5571
5572      BACKUP_FILES="/com/mailer/aliases /com/mailer/league*[a-z]"
5573
5574 \1f
5575 File: tar.info,  Node: Scripted Backups,  Next: Scripted Restoration,  Prev: Backup Parameters,  Up: Backups
5576
5577 5.5 Using the Backup Scripts
5578 ============================
5579
5580 The syntax for running a backup script is:
5581
5582      backup --level=LEVEL --time=TIME
5583
5584    The `--level' option requests the dump level.  Thus, to produce a
5585 full dump, specify `--level=0' (this is the default, so `--level' may
5586 be omitted if its value is `0')(1).
5587
5588    The `--time' option determines when should the backup be run.  TIME
5589 may take three forms:
5590
5591 HH:MM
5592      The dump must be run at HH hours MM minutes.
5593
5594 HH
5595      The dump must be run at HH hours.
5596
5597 now
5598      The dump must be run immediately.
5599
5600    You should start a script with a tape or disk mounted.  Once you
5601 start a script, it prompts you for new tapes or disks as it needs them.
5602 Media volumes don't have to correspond to archive files -- a
5603 multi-volume archive can be started in the middle of a tape that
5604 already contains the end of another multi-volume archive.  The
5605 `restore' script prompts for media by its archive volume, so to avoid
5606 an error message you should keep track of which tape (or disk) contains
5607 which volume of the archive (*note Scripted Restoration::).
5608
5609    The backup scripts write two files on the file system.  The first is
5610 a record file in `/etc/tar-backup/', which is used by the scripts to
5611 store and retrieve information about which files were dumped.  This
5612 file is not meant to be read by humans, and should not be deleted by
5613 them.  *Note Snapshot Files::, for a more detailed explanation of this
5614 file.
5615
5616    The second file is a log file containing the names of the file
5617 systems and files dumped, what time the backup was made, and any error
5618 messages that were generated, as well as how much space was left in the
5619 media volume after the last volume of the archive was written.  You
5620 should check this log file after every backup.  The file name is
5621 `log-MM-DD-YYYY-level-N', where MM-DD-YYYY represents current date, and
5622 N represents current dump level number.
5623
5624    The script also prints the name of each system being dumped to the
5625 standard output.
5626
5627    Following is the full list of options accepted by `backup' script:
5628
5629 `-l LEVEL'
5630 `--level=LEVEL'
5631      Do backup level LEVEL (default 0).
5632
5633 `-f'
5634 `--force'
5635      Force backup even if today's log file already exists.
5636
5637 `-v[LEVEL]'
5638 `--verbose[=LEVEL]'
5639      Set verbosity level.  The higher the level is, the more debugging
5640      information will be output during execution.  Default LEVEL is
5641      100, which means the highest debugging level.
5642
5643 `-t START-TIME'
5644 `--time=START-TIME'
5645      Wait till TIME, then do backup.
5646
5647 `-h'
5648 `--help'
5649      Display short help message and exit.
5650
5651 `-V'
5652 `--version'
5653      Display information about the program's name, version, origin and
5654      legal status, all on standard output, and then exit successfully.
5655
5656    ---------- Footnotes ----------
5657
5658    (1) For backward compatibility, the `backup' will also try to deduce
5659 the requested dump level from the name of the script itself.  If the
5660 name consists of a string `level-' followed by a single decimal digit,
5661 that digit is taken as the dump level number.  Thus, you may create a
5662 link from `backup' to `level-1' and then run `level-1' whenever you
5663 need to create a level one dump.
5664
5665 \1f
5666 File: tar.info,  Node: Scripted Restoration,  Prev: Scripted Backups,  Up: Backups
5667
5668 5.6 Using the Restore Script
5669 ============================
5670
5671 To restore files that were archived using a scripted backup, use the
5672 `restore' script.  Its usage is quite straightforward.  In the simplest
5673 form, invoke `restore --all', it will then restore all the file systems
5674 and files specified in `backup-specs' (*note BACKUP_DIRS:
5675 General-Purpose Variables.).
5676
5677    You may select the file systems (and/or files) to restore by giving
5678 `restore' a list of "patterns" in its command line.  For example,
5679 running
5680
5681      restore 'albert:*'
5682
5683 will restore all file systems on the machine `albert'.  A more
5684 complicated example:
5685
5686      restore 'albert:*' '*:/var'
5687
5688 This command will restore all file systems on the machine `albert' as
5689 well as `/var' file system on all machines.
5690
5691    By default `restore' will start restoring files from the lowest
5692 available dump level (usually zero) and will continue through all
5693 available dump levels.  There may be situations where such a thorough
5694 restore is not necessary.  For example, you may wish to restore only
5695 files from the recent level one backup.  To do so, use `--level'
5696 option, as shown in the example below:
5697
5698      restore --level=1
5699
5700    The full list of options accepted by `restore' follows:
5701
5702 `-a'
5703 `--all'
5704      Restore all file systems and files specified in `backup-specs'.
5705
5706 `-l LEVEL'
5707 `--level=LEVEL'
5708      Start restoring from the given backup level, instead of the
5709      default 0.
5710
5711 `-v[LEVEL]'
5712 `--verbose[=LEVEL]'
5713      Set verbosity level.  The higher the level is, the more debugging
5714      information will be output during execution.  Default LEVEL is
5715      100, which means the highest debugging level.
5716
5717 `-h'
5718 `--help'
5719      Display short help message and exit.
5720
5721 `-V'
5722 `--version'
5723      Display information about the program's name, version, origin and
5724      legal status, all on standard output, and then exit successfully.
5725
5726    You should start the restore script with the media containing the
5727 first volume of the archive mounted.  The script will prompt for other
5728 volumes as they are needed.  If the archive is on tape, you don't need
5729 to rewind the tape to to its beginning--if the tape head is positioned
5730 past the beginning of the archive, the script will rewind the tape as
5731 needed.  *Note Tape Positioning::, for a discussion of tape positioning.
5732
5733      *Warning:* The script will delete files from the active file
5734      system if they were not in the file system when the archive was
5735      made.
5736
5737    *Note Incremental Dumps::, for an explanation of how the script makes
5738 that determination.
5739
5740 \1f
5741 File: tar.info,  Node: Choosing,  Next: Date input formats,  Prev: Backups,  Up: Top
5742
5743 6 Choosing Files and Names for `tar'
5744 ************************************
5745
5746 Certain options to `tar' enable you to specify a name for your archive.
5747 Other options let you decide which files to include or exclude from the
5748 archive, based on when or whether files were modified, whether the file
5749 names do or don't match specified patterns, or whether files are in
5750 specified directories.
5751
5752    This chapter discusses these options in detail.
5753
5754 * Menu:
5755
5756 * file::                        Choosing the Archive's Name
5757 * Selecting Archive Members::
5758 * files::                       Reading Names from a File
5759 * exclude::                     Excluding Some Files
5760 * wildcards::                   Wildcards Patterns and Matching
5761 * quoting styles::              Ways of Quoting Special Characters in Names
5762 * transform::                   Modifying File and Member Names
5763 * after::                       Operating Only on New Files
5764 * recurse::                     Descending into Directories
5765 * one::                         Crossing File System Boundaries
5766
5767 \1f
5768 File: tar.info,  Node: file,  Next: Selecting Archive Members,  Up: Choosing
5769
5770 6.1 Choosing and Naming Archive Files
5771 =====================================
5772
5773 By default, `tar' uses an archive file name that was compiled when it
5774 was built on the system; usually this name refers to some physical tape
5775 drive on the machine.  However, the person who installed `tar' on the
5776 system may not have set the default to a meaningful value as far as
5777 most users are concerned.  As a result, you will usually want to tell
5778 `tar' where to find (or create) the archive.  The `--file=ARCHIVE-NAME'
5779 (`-f ARCHIVE-NAME') option allows you to either specify or name a file
5780 to use as the archive instead of the default archive file location.
5781
5782 `--file=ARCHIVE-NAME'
5783 `-f ARCHIVE-NAME'
5784      Name the archive to create or operate on.  Use in conjunction with
5785      any operation.
5786
5787    For example, in this `tar' command,
5788
5789      $ tar -cvf collection.tar blues folk jazz
5790
5791 `collection.tar' is the name of the archive.  It must directly follow
5792 the `-f' option, since whatever directly follows `-f' _will_ end up
5793 naming the archive.  If you neglect to specify an archive name, you may
5794 end up overwriting a file in the working directory with the archive you
5795 create since `tar' will use this file's name for the archive name.
5796
5797    An archive can be saved as a file in the file system, sent through a
5798 pipe or over a network, or written to an I/O device such as a tape,
5799 floppy disk, or CD write drive.
5800
5801    If you do not name the archive, `tar' uses the value of the
5802 environment variable `TAPE' as the file name for the archive.  If that
5803 is not available, `tar' uses a default, compiled-in archive name,
5804 usually that for tape unit zero (i.e., `/dev/tu00').
5805
5806    If you use `-' as an ARCHIVE-NAME, `tar' reads the archive from
5807 standard input (when listing or extracting files), or writes it to
5808 standard output (when creating an archive).  If you use `-' as an
5809 ARCHIVE-NAME when modifying an archive, `tar' reads the original
5810 archive from its standard input and writes the entire new archive to
5811 its standard output.
5812
5813    The following example is a convenient way of copying directory
5814 hierarchy from `sourcedir' to `targetdir'.
5815
5816      $ (cd sourcedir; tar -cf - .) | (cd targetdir; tar -xpf -)
5817
5818    The `-C' option allows to avoid using subshells:
5819
5820      $ tar -C sourcedir -cf - . | tar -C targetdir -xpf -
5821
5822    In both examples above, the leftmost `tar' invocation archives the
5823 contents of `sourcedir' to the standard output, while the rightmost one
5824 reads this archive from its standard input and extracts it.  The `-p'
5825 option tells it to restore permissions of the extracted files.
5826
5827    To specify an archive file on a device attached to a remote machine,
5828 use the following:
5829
5830      --file=HOSTNAME:/DEV/FILE-NAME
5831
5832 `tar' will set up the remote connection, if possible, and prompt you
5833 for a username and password.  If you use
5834 `--file=@HOSTNAME:/DEV/FILE-NAME', `tar' will attempt to set up the
5835 remote connection using your username as the username on the remote
5836 machine.
5837
5838    If the archive file name includes a colon (`:'), then it is assumed
5839 to be a file on another machine.  If the archive file is
5840 `USER@HOST:FILE', then FILE is used on the host HOST.  The remote host
5841 is accessed using the `rsh' program, with a username of USER.  If the
5842 username is omitted (along with the `@' sign), then your user name will
5843 be used.  (This is the normal `rsh' behavior.)  It is necessary for the
5844 remote machine, in addition to permitting your `rsh' access, to have
5845 the `rmt' program installed (this command is included in the GNU `tar'
5846 distribution and by default is installed under `PREFIX/libexec/rmt',
5847 where PREFIX means your installation prefix).  If you need to use a
5848 file whose name includes a colon, then the remote tape drive behavior
5849 can be inhibited by using the `--force-local' option.
5850
5851    When the archive is being created to `/dev/null', GNU `tar' tries to
5852 minimize input and output operations.  The Amanda backup system, when
5853 used with GNU `tar', has an initial sizing pass which uses this feature.
5854
5855 \1f
5856 File: tar.info,  Node: Selecting Archive Members,  Next: files,  Prev: file,  Up: Choosing
5857
5858 6.2 Selecting Archive Members
5859 =============================
5860
5861 "File Name arguments" specify which files in the file system `tar'
5862 operates on, when creating or adding to an archive, or which archive
5863 members `tar' operates on, when reading or deleting from an archive.
5864 *Note Operations::.
5865
5866    To specify file names, you can include them as the last arguments on
5867 the command line, as follows:
5868      tar OPERATION [OPTION1 OPTION2 ...] [FILE NAME-1 FILE NAME-2 ...]
5869
5870    If a file name begins with dash (`-'), precede it with `--add-file'
5871 option to prevent it from being treated as an option.
5872
5873    By default GNU `tar' attempts to "unquote" each file or member name,
5874 replacing "escape sequences" according to the following table:
5875
5876 Escape         Replaced with
5877 ----------------------------------------------------------- 
5878 \a             Audible bell (ASCII 7)
5879 \b             Backspace (ASCII 8)
5880 \f             Form feed (ASCII 12)
5881 \n             New line (ASCII 10)
5882 \r             Carriage return (ASCII 13)
5883 \t             Horizontal tabulation (ASCII 9)
5884 \v             Vertical tabulation (ASCII 11)
5885 \?             ASCII 127
5886 \N             ASCII N (N should be an octal number
5887                          of up to 3 digits)
5888
5889    A backslash followed by any other symbol is retained.
5890
5891    This default behavior is controlled by the following command line
5892 option:
5893
5894 `--unquote'
5895      Enable unquoting input file or member names (default).
5896
5897 `--no-unquote'
5898      Disable unquoting input file or member names.
5899
5900    If you specify a directory name as a file name argument, all the
5901 files in that directory are operated on by `tar'.
5902
5903    If you do not specify files, `tar' behavior differs depending on the
5904 operation mode as described below:
5905
5906    When `tar' is invoked with `--create' (`-c'), `tar' will stop
5907 immediately, reporting the following:
5908
5909      $ tar cf a.tar
5910      tar: Cowardly refusing to create an empty archive
5911      Try `tar --help' or `tar --usage' for more information.
5912
5913    If you specify either `--list' (`-t') or `--extract' (`--get',
5914 `-x'), `tar' operates on all the archive members in the archive.
5915
5916    If run with `--diff' option, tar will compare the archive with the
5917 contents of the current working directory.
5918
5919    If you specify any other operation, `tar' does nothing.
5920
5921    By default, `tar' takes file names from the command line.  However,
5922 there are other ways to specify file or member names, or to modify the
5923 manner in which `tar' selects the files or members upon which to
5924 operate.  In general, these methods work both for specifying the names
5925 of files and archive members.
5926
5927 \1f
5928 File: tar.info,  Node: files,  Next: exclude,  Prev: Selecting Archive Members,  Up: Choosing
5929
5930 6.3 Reading Names from a File
5931 =============================
5932
5933 Instead of giving the names of files or archive members on the command
5934 line, you can put the names into a file, and then use the
5935 `--files-from=FILE-OF-NAMES' (`-T FILE-OF-NAMES') option to `tar'.
5936 Give the name of the file which contains the list of files to include
5937 as the argument to `--files-from'.  In the list, the file names should
5938 be separated by newlines.  You will frequently use this option when you
5939 have generated the list of files to archive with the `find' utility.
5940
5941 `--files-from=FILE-NAME'
5942 `-T FILE-NAME'
5943      Get names to extract or create from file FILE-NAME.
5944
5945    If you give a single dash as a file name for `--files-from', (i.e.,
5946 you specify either `--files-from=-' or `-T -'), then the file names are
5947 read from standard input.
5948
5949    Unless you are running `tar' with `--create', you can not use both
5950 `--files-from=-' and `--file=-' (`-f -') in the same command.
5951
5952    Any number of `-T' options can be given in the command line.
5953
5954    The following example shows how to use `find' to generate a list of
5955 files smaller than 400K in length and put that list into a file called
5956 `small-files'.  You can then use the `-T' option to `tar' to specify
5957 the files from that file, `small-files', to create the archive
5958 `little.tgz'.  (The `-z' option to `tar' compresses the archive with
5959 `gzip'; *note gzip:: for more information.)
5960
5961      $ find . -size -400 -print > small-files
5962      $ tar -c -v -z -T small-files -f little.tgz
5963
5964 In the file list given by `-T' option, any file name beginning with `-'
5965 character is considered a `tar' option and is processed accordingly(1).
5966 For example, the common use of this feature is to change to another
5967 directory by specifying `-C' option:
5968
5969      $ cat list
5970      -C/etc
5971      passwd
5972      hosts
5973      -C/lib
5974      libc.a
5975      $ tar -c -f foo.tar --files-from list
5976
5977 In this example, `tar' will first switch to `/etc' directory and add
5978 files `passwd' and `hosts' to the archive.  Then it will change to
5979 `/lib' directory and will archive the file `libc.a'.  Thus, the
5980 resulting archive `foo.tar' will contain:
5981
5982      $ tar tf foo.tar
5983      passwd
5984      hosts
5985      libc.a
5986
5987
5988    Notice that the option parsing algorithm used with `-T' is stricter
5989 than the one used by shell.  Namely, when specifying option arguments,
5990 you should observe the following rules:
5991
5992    * When using short (single-letter) option form, its argument must
5993      immediately follow the option letter, without any intervening
5994      whitespace.  For example: `-Cdir'.
5995
5996    * When using long option form, the option argument must be separated
5997      from the option by a single equal sign.  No whitespace is allowed
5998      on any side of the equal sign.  For example: `--directory=dir'.
5999
6000    * For both short and long option forms, the option argument can be
6001      given on the next line after the option name, e.g.:
6002
6003           --directory
6004           dir
6005
6006      and
6007
6008           -C
6009           dir
6010
6011    If you happen to have a file whose name starts with `-', precede it
6012 with `--add-file' option to prevent it from being recognized as an
6013 option.  For example: `--add-file=--my-file'.
6014
6015 * Menu:
6016
6017 * nul::
6018
6019    ---------- Footnotes ----------
6020
6021    (1) Versions of GNU `tar' up to 1.15.1 recognized only `-C' option
6022 in file lists, and only if the option and its argument occupied two
6023 consecutive lines.
6024
6025 \1f
6026 File: tar.info,  Node: nul,  Up: files
6027
6028 6.3.1 `NUL'-Terminated File Names
6029 ---------------------------------
6030
6031 The `--null' option causes `--files-from=FILE-OF-NAMES' (`-T
6032 FILE-OF-NAMES') to read file names terminated by a `NUL' instead of a
6033 newline, so files whose names contain newlines can be archived using
6034 `--files-from'.
6035
6036 `--null'
6037      Only consider `NUL'-terminated file names, instead of files that
6038      terminate in a newline.
6039
6040 `--no-null'
6041      Undo the effect of any previous `--null' option.
6042
6043    The `--null' option is just like the one in GNU `xargs' and `cpio',
6044 and is useful with the `-print0' predicate of GNU `find'.  In `tar',
6045 `--null' also disables special handling for file names that begin with
6046 dash.
6047
6048    This example shows how to use `find' to generate a list of files
6049 larger than 800K in length and put that list into a file called
6050 `long-files'.  The `-print0' option to `find' is just like `-print',
6051 except that it separates files with a `NUL' rather than with a newline.
6052 You can then run `tar' with both the `--null' and `-T' options to
6053 specify that `tar' gets the files from that file, `long-files', to
6054 create the archive `big.tgz'.  The `--null' option to `tar' will cause
6055 `tar' to recognize the `NUL' separator between files.
6056
6057      $ find . -size +800 -print0 > long-files
6058      $ tar -c -v --null --files-from=long-files --file=big.tar
6059
6060    The `--no-null' option can be used if you need to read both
6061 `NUL'-terminated and newline-terminated files on the same command line.
6062 For example, if `flist' is a newline-terminated file, then the
6063 following command can be used to combine it with the above command:
6064
6065      $ find . -size +800 -print0 |
6066        tar -c -f big.tar --null -T - --no-null -T flist
6067
6068    This example uses short options for typographic reasons, to avoid
6069 very long lines.
6070
6071    GNU `tar' is able to automatically detect `NUL'-terminated file
6072 lists, so it is safe to use them even without the `--null' option.  In
6073 this case `tar' will print a warning and continue reading such a file
6074 as if `--null' were actually given:
6075
6076      $ find . -size +800 -print0 | tar -c -f big.tar -T -
6077      tar: -: file name read contains nul character
6078
6079    The null terminator, however, remains in effect only for this
6080 particular file, any following `-T' options will assume newline
6081 termination.  Of course, the null autodetection applies to these
6082 eventual surplus `-T' options as well.
6083
6084 \1f
6085 File: tar.info,  Node: exclude,  Next: wildcards,  Prev: files,  Up: Choosing
6086
6087 6.4 Excluding Some Files
6088 ========================
6089
6090 To avoid operating on files whose names match a particular pattern, use
6091 the `--exclude' or `--exclude-from' options.
6092
6093 `--exclude=PATTERN'
6094      Causes `tar' to ignore files that match the PATTERN.
6095
6096    The `--exclude=PATTERN' option prevents any file or member whose
6097 name matches the shell wildcard (PATTERN) from being operated on.  For
6098 example, to create an archive with all the contents of the directory
6099 `src' except for files whose names end in `.o', use the command `tar
6100 -cf src.tar --exclude='*.o' src'.
6101
6102    You may give multiple `--exclude' options.
6103
6104 `--exclude-from=FILE'
6105 `-X FILE'
6106      Causes `tar' to ignore files that match the patterns listed in
6107      FILE.
6108
6109    Use the `--exclude-from' option to read a list of patterns, one per
6110 line, from FILE; `tar' will ignore files matching those patterns.  Thus
6111 if `tar' is called as `tar -c -X foo .' and the file `foo' contains a
6112 single line `*.o', no files whose names end in `.o' will be added to
6113 the archive.
6114
6115    Notice, that lines from FILE are read verbatim. One of the frequent
6116 errors is leaving some extra whitespace after a file name, which is
6117 difficult to catch using text editors.
6118
6119    However, empty lines are OK.
6120
6121 `--exclude-vcs'
6122      Exclude files and directories used by following version control
6123      systems: `CVS', `RCS', `SCCS', `SVN', `Arch', `Bazaar',
6124      `Mercurial', and `Darcs'.
6125
6126      As of version 1.25, the following files are excluded:
6127
6128         * `CVS/', and everything under it
6129
6130         * `RCS/', and everything under it
6131
6132         * `SCCS/', and everything under it
6133
6134         * `.git/', and everything under it
6135
6136         * `.gitignore'
6137
6138         * `.cvsignore'
6139
6140         * `.svn/', and everything under it
6141
6142         * `.arch-ids/', and everything under it
6143
6144         * `{arch}/', and everything under it
6145
6146         * `=RELEASE-ID'
6147
6148         * `=meta-update'
6149
6150         * `=update'
6151
6152         * `.bzr'
6153
6154         * `.bzrignore'
6155
6156         * `.bzrtags'
6157
6158         * `.hg'
6159
6160         * `.hgignore'
6161
6162         * `.hgrags'
6163
6164         * `_darcs'
6165
6166 `--exclude-backups'
6167      Exclude backup and lock files.  This option causes exclusion of
6168      files that match the following shell globbing patterns:
6169
6170     .#*
6171
6172     *~
6173
6174     #*#
6175
6176
6177    When creating an archive, the `--exclude-caches' option family
6178 causes `tar' to exclude all directories that contain a "cache directory
6179 tag". A cache directory tag is a short file with the well-known name
6180 `CACHEDIR.TAG' and having a standard header specified in
6181 `http://www.brynosaurus.com/cachedir/spec.html'.  Various applications
6182 write cache directory tags into directories they use to hold
6183 regenerable, non-precious data, so that such data can be more easily
6184 excluded from backups.
6185
6186    There are three `exclude-caches' options, each providing a different
6187 exclusion semantics:
6188
6189 `--exclude-caches'
6190      Do not archive the contents of the directory, but archive the
6191      directory itself and the `CACHEDIR.TAG' file.
6192
6193 `--exclude-caches-under'
6194      Do not archive the contents of the directory, nor the
6195      `CACHEDIR.TAG' file, archive only the directory itself.
6196
6197 `--exclude-caches-all'
6198      Omit directories containing `CACHEDIR.TAG' file entirely.
6199
6200    Another option family, `--exclude-tag', provides a generalization of
6201 this concept.  It takes a single argument, a file name to look for.
6202 Any directory that contains this file will be excluded from the dump.
6203 Similarly to `exclude-caches', there are three options in this option
6204 family:
6205
6206 `--exclude-tag=FILE'
6207      Do not dump the contents of the directory, but dump the directory
6208      itself and the FILE.
6209
6210 `--exclude-tag-under=FILE'
6211      Do not dump the contents of the directory, nor the FILE, archive
6212      only the directory itself.
6213
6214 `--exclude-tag-all=FILE'
6215      Omit directories containing FILE file entirely.
6216
6217    Multiple `--exclude-tag*' options can be given.
6218
6219    For example, given this directory:
6220
6221      $ find dir
6222      dir
6223      dir/blues
6224      dir/jazz
6225      dir/folk
6226      dir/folk/tagfile
6227      dir/folk/sanjuan
6228      dir/folk/trote
6229
6230    The `--exclude-tag' will produce the following:
6231
6232      $ tar -cf archive.tar --exclude-tag=tagfile -v dir
6233      dir/
6234      dir/blues
6235      dir/jazz
6236      dir/folk/
6237      tar: dir/folk/: contains a cache directory tag tagfile;
6238        contents not dumped
6239      dir/folk/tagfile
6240
6241    Both the `dir/folk' directory and its tagfile are preserved in the
6242 archive, however the rest of files in this directory are not.
6243
6244    Now, using the `--exclude-tag-under' option will exclude `tagfile'
6245 from the dump, while still preserving the directory itself, as shown in
6246 this example:
6247
6248      $ tar -cf archive.tar --exclude-tag-under=tagfile -v dir
6249      dir/
6250      dir/blues
6251      dir/jazz
6252      dir/folk/
6253      ./tar: dir/folk/: contains a cache directory tag tagfile;
6254        contents not dumped
6255
6256    Finally, using `--exclude-tag-all' omits the `dir/folk' directory
6257 entirely:
6258
6259      $ tar -cf archive.tar --exclude-tag-all=tagfile -v dir
6260      dir/
6261      dir/blues
6262      dir/jazz
6263      ./tar: dir/folk/: contains a cache directory tag tagfile;
6264        directory not dumped
6265
6266 * Menu:
6267
6268 * problems with exclude::
6269
6270 \1f
6271 File: tar.info,  Node: problems with exclude,  Up: exclude
6272
6273 Problems with Using the `exclude' Options
6274 -----------------------------------------
6275
6276 Some users find `exclude' options confusing.  Here are some common
6277 pitfalls:
6278
6279    * The main operating mode of `tar' does not act on a file name
6280      explicitly listed on the command line, if one of its file name
6281      components is excluded.  In the example above, if you create an
6282      archive and exclude files that end with `*.o', but explicitly name
6283      the file `dir.o/foo' after all the options have been listed,
6284      `dir.o/foo' will be excluded from the archive.
6285
6286    * You can sometimes confuse the meanings of `--exclude' and
6287      `--exclude-from'.  Be careful: use `--exclude' when files to be
6288      excluded are given as a pattern on the command line.  Use
6289      `--exclude-from' to introduce the name of a file which contains a
6290      list of patterns, one per line; each of these patterns can exclude
6291      zero, one, or many files.
6292
6293    * When you use `--exclude=PATTERN', be sure to quote the PATTERN
6294      parameter, so GNU `tar' sees wildcard characters like `*'.  If you
6295      do not do this, the shell might expand the `*' itself using files
6296      at hand, so `tar' might receive a list of files instead of one
6297      pattern, or none at all, making the command somewhat illegal.
6298      This might not correspond to what you want.
6299
6300      For example, write:
6301
6302           $ tar -c -f ARCHIVE.TAR --exclude '*.o' DIRECTORY
6303
6304      rather than:
6305
6306           # _Wrong!_
6307           $ tar -c -f ARCHIVE.TAR --exclude *.o DIRECTORY
6308
6309    * You must use use shell syntax, or globbing, rather than `regexp'
6310      syntax, when using exclude options in `tar'.  If you try to use
6311      `regexp' syntax to describe files to be excluded, your command
6312      might fail.
6313
6314    *  In earlier versions of `tar', what is now the `--exclude-from'
6315      option was called `--exclude' instead.  Now, `--exclude' applies
6316      to patterns listed on the command line and `--exclude-from'
6317      applies to patterns listed in a file.
6318
6319
6320 \1f
6321 File: tar.info,  Node: wildcards,  Next: quoting styles,  Prev: exclude,  Up: Choosing
6322
6323 6.5 Wildcards Patterns and Matching
6324 ===================================
6325
6326 "Globbing" is the operation by which "wildcard" characters, `*' or `?'
6327 for example, are replaced and expanded into all existing files matching
6328 the given pattern.  GNU `tar' can use wildcard patterns for matching
6329 (or globbing) archive members when extracting from or listing an
6330 archive.  Wildcard patterns are also used for verifying volume labels
6331 of `tar' archives.  This section has the purpose of explaining wildcard
6332 syntax for `tar'.
6333
6334    A PATTERN should be written according to shell syntax, using wildcard
6335 characters to effect globbing.  Most characters in the pattern stand
6336 for themselves in the matched string, and case is significant: `a' will
6337 match only `a', and not `A'.  The character `?' in the pattern matches
6338 any single character in the matched string.  The character `*' in the
6339 pattern matches zero, one, or more single characters in the matched
6340 string.  The character `\' says to take the following character of the
6341 pattern _literally_; it is useful when one needs to match the `?', `*',
6342 `[' or `\' characters, themselves.
6343
6344    The character `[', up to the matching `]', introduces a character
6345 class.  A "character class" is a list of acceptable characters for the
6346 next single character of the matched string.  For example, `[abcde]'
6347 would match any of the first five letters of the alphabet.  Note that
6348 within a character class, all of the "special characters" listed above
6349 other than `\' lose their special meaning; for example, `[-\\[*?]]'
6350 would match any of the characters, `-', `\', `[', `*', `?', or `]'.
6351 (Due to parsing constraints, the characters `-' and `]' must either
6352 come _first_ or _last_ in a character class.)
6353
6354    If the first character of the class after the opening `[' is `!' or
6355 `^', then the meaning of the class is reversed.  Rather than listing
6356 character to match, it lists those characters which are _forbidden_ as
6357 the next single character of the matched string.
6358
6359    Other characters of the class stand for themselves.  The special
6360 construction `[A-E]', using an hyphen between two letters, is meant to
6361 represent all characters between A and E, inclusive.
6362
6363    Periods (`.') or forward slashes (`/') are not considered special
6364 for wildcard matches.  However, if a pattern completely matches a
6365 directory prefix of a matched string, then it matches the full matched
6366 string: thus, excluding a directory also excludes all the files beneath
6367 it.
6368
6369 * Menu:
6370
6371 * controlling pattern-matching::
6372
6373 \1f
6374 File: tar.info,  Node: controlling pattern-matching,  Up: wildcards
6375
6376 Controlling Pattern-Matching
6377 ----------------------------
6378
6379 For the purposes of this section, we call "exclusion members" all
6380 member names obtained while processing `--exclude' and `--exclude-from'
6381 options, and "inclusion members" those member names that were given in
6382 the command line or read from the file specified with `--files-from'
6383 option.
6384
6385    These two pairs of member lists are used in the following operations:
6386 `--diff', `--extract', `--list', `--update'.
6387
6388    There are no inclusion members in create mode (`--create' and
6389 `--append'), since in this mode the names obtained from the command
6390 line refer to _files_, not archive members.
6391
6392    By default, inclusion members are compared with archive members
6393 literally (1) and exclusion members are treated as globbing patterns.
6394 For example:
6395
6396      $ tar tf foo.tar
6397      a.c
6398      b.c
6399      a.txt
6400      [remarks]
6401      # Member names are used verbatim:
6402      $ tar -xf foo.tar -v '[remarks]'
6403      [remarks]
6404      # Exclude member names are globbed:
6405      $ tar -xf foo.tar -v --exclude '*.c'
6406      a.txt
6407      [remarks]
6408
6409    This behavior can be altered by using the following options:
6410
6411 `--wildcards'
6412      Treat all member names as wildcards.
6413
6414 `--no-wildcards'
6415      Treat all member names as literal strings.
6416
6417    Thus, to extract files whose names end in `.c', you can use:
6418
6419      $ tar -xf foo.tar -v --wildcards '*.c'
6420      a.c
6421      b.c
6422
6423 Notice quoting of the pattern to prevent the shell from interpreting it.
6424
6425    The effect of `--wildcards' option is canceled by `--no-wildcards'.
6426 This can be used to pass part of the command line arguments verbatim
6427 and other part as globbing patterns.  For example, the following
6428 invocation:
6429
6430      $ tar -xf foo.tar --wildcards '*.txt' --no-wildcards '[remarks]'
6431
6432 instructs `tar' to extract from `foo.tar' all files whose names end in
6433 `.txt' and the file named `[remarks]'.
6434
6435    Normally, a pattern matches a name if an initial subsequence of the
6436 name's components matches the pattern, where `*', `?', and `[...]' are
6437 the usual shell wildcards, `\' escapes wildcards, and wildcards can
6438 match `/'.
6439
6440    Other than optionally stripping leading `/' from names (*note
6441 absolute::), patterns and names are used as-is.  For example, trailing
6442 `/' is not trimmed from a user-specified name before deciding whether
6443 to exclude it.
6444
6445    However, this matching procedure can be altered by the options listed
6446 below.  These options accumulate.  For example:
6447
6448      --ignore-case --exclude='makefile' --no-ignore-case ---exclude='readme'
6449
6450 ignores case when excluding `makefile', but not when excluding `readme'.
6451
6452 `--anchored'
6453 `--no-anchored'
6454      If anchored, a pattern must match an initial subsequence of the
6455      name's components.  Otherwise, the pattern can match any
6456      subsequence.  Default is `--no-anchored' for exclusion members and
6457      `--anchored' inclusion members.
6458
6459 `--ignore-case'
6460 `--no-ignore-case'
6461      When ignoring case, upper-case patterns match lower-case names and
6462      vice versa.  When not ignoring case (the default), matching is
6463      case-sensitive.
6464
6465 `--wildcards-match-slash'
6466 `--no-wildcards-match-slash'
6467      When wildcards match slash (the default for exclusion members), a
6468      wildcard like `*' in the pattern can match a `/' in the name.
6469      Otherwise, `/' is matched only by `/'.
6470
6471
6472    The `--recursion' and `--no-recursion' options (*note recurse::)
6473 also affect how member patterns are interpreted.  If recursion is in
6474 effect, a pattern matches a name if it matches any of the name's parent
6475 directories.
6476
6477    The following table summarizes pattern-matching default values:
6478
6479 Members                Default settings
6480 -------------------------------------------------------------------------- 
6481 Inclusion              `--no-wildcards --anchored
6482                        --no-wildcards-match-slash'
6483 Exclusion              `--wildcards --no-anchored
6484                        --wildcards-match-slash'
6485
6486    ---------- Footnotes ----------
6487
6488    (1) Notice that earlier GNU `tar' versions used globbing for
6489 inclusion members, which contradicted to UNIX98 specification and was
6490 not documented. *Note Changes::, for more information on this and other
6491 changes.
6492
6493 \1f
6494 File: tar.info,  Node: quoting styles,  Next: transform,  Prev: wildcards,  Up: Choosing
6495
6496 6.6 Quoting Member Names
6497 ========================
6498
6499 When displaying member names, `tar' takes care to avoid ambiguities
6500 caused by certain characters.  This is called "name quoting".  The
6501 characters in question are:
6502
6503    * Non-printable control characters:
6504      Character     ASCII   Character name
6505      --------------------------------------------------------------- 
6506      \a            7       Audible bell
6507      \b            8       Backspace
6508      \f            12      Form feed
6509      \n            10      New line
6510      \r            13      Carriage return
6511      \t            9       Horizontal tabulation
6512      \v            11      Vertical tabulation
6513
6514    * Space (ASCII 32)
6515
6516    * Single and double quotes (`'' and `"')
6517
6518    * Backslash (`\')
6519
6520    The exact way `tar' uses to quote these characters depends on the
6521 "quoting style".  The default quoting style, called "escape" (see
6522 below), uses backslash notation to represent control characters, space
6523 and backslash.  Using this quoting style, control characters are
6524 represented as listed in column `Character' in the above table, a space
6525 is printed as `\ ' and a backslash as `\\'.
6526
6527    GNU `tar' offers seven distinct quoting styles, which can be selected
6528 using `--quoting-style' option:
6529
6530 `--quoting-style=STYLE'
6531      Sets quoting style.  Valid values for STYLE argument are: literal,
6532      shell, shell-always, c, escape, locale, clocale.
6533
6534    These styles are described in detail below.  To illustrate their
6535 effect, we will use an imaginary tar archive `arch.tar' containing the
6536 following members:
6537
6538      # 1. Contains horizontal tabulation character.
6539      a       tab
6540      # 2. Contains newline character
6541      a
6542      newline
6543      # 3. Contains a space
6544      a space
6545      # 4. Contains double quotes
6546      a"double"quote
6547      # 5. Contains single quotes
6548      a'single'quote
6549      # 6. Contains a backslash character:
6550      a\backslash
6551
6552    Here is how usual `ls' command would have listed them, if they had
6553 existed in the current working directory:
6554
6555      $ ls
6556      a\ttab
6557      a\nnewline
6558      a\ space
6559      a"double"quote
6560      a'single'quote
6561      a\\backslash
6562
6563    Quoting styles:
6564
6565 `literal'
6566      No quoting, display each character as is:
6567
6568           $ tar tf arch.tar --quoting-style=literal
6569           ./
6570           ./a space
6571           ./a'single'quote
6572           ./a"double"quote
6573           ./a\backslash
6574           ./a     tab
6575           ./a
6576           newline
6577
6578 `shell'
6579      Display characters the same way Bourne shell does: control
6580      characters, except `\t' and `\n', are printed using backslash
6581      escapes, `\t' and `\n' are printed as is, and a single quote is
6582      printed as `\''.  If a name contains any quoted characters, it is
6583      enclosed in single quotes.  In particular, if a name contains
6584      single quotes, it is printed as several single-quoted strings:
6585
6586           $ tar tf arch.tar --quoting-style=shell
6587           ./
6588           './a space'
6589           './a'\''single'\''quote'
6590           './a"double"quote'
6591           './a\backslash'
6592           './a    tab'
6593           './a
6594           newline'
6595
6596 `shell-always'
6597      Same as `shell', but the names are always enclosed in single
6598      quotes:
6599
6600           $ tar tf arch.tar --quoting-style=shell-always
6601           './'
6602           './a space'
6603           './a'\''single'\''quote'
6604           './a"double"quote'
6605           './a\backslash'
6606           './a    tab'
6607           './a
6608           newline'
6609
6610 `c'
6611      Use the notation of the C programming language.  All names are
6612      enclosed in double quotes.  Control characters are quoted using
6613      backslash notations, double quotes are represented as `\"',
6614      backslash characters are represented as `\\'.  Single quotes and
6615      spaces are not quoted:
6616
6617           $ tar tf arch.tar --quoting-style=c
6618           "./"
6619           "./a space"
6620           "./a'single'quote"
6621           "./a\"double\"quote"
6622           "./a\\backslash"
6623           "./a\ttab"
6624           "./a\nnewline"
6625
6626 `escape'
6627      Control characters are printed using backslash notation, a space is
6628      printed as `\ ' and a backslash as `\\'.  This is the default
6629      quoting style, unless it was changed when configured the package.
6630
6631           $ tar tf arch.tar --quoting-style=escape
6632           ./
6633           ./a space
6634           ./a'single'quote
6635           ./a"double"quote
6636           ./a\\backslash
6637           ./a\ttab
6638           ./a\nnewline
6639
6640 `locale'
6641      Control characters, single quote and backslash are printed using
6642      backslash notation.  All names are quoted using left and right
6643      quotation marks, appropriate to the current locale.  If it does not
6644      define quotation marks, use ``' as left and `'' as right quotation
6645      marks.  Any occurrences of the right quotation mark in a name are
6646      escaped with `\', for example:
6647
6648      For example:
6649
6650           $ tar tf arch.tar --quoting-style=locale
6651           `./'
6652           `./a space'
6653           `./a\'single\'quote'
6654           `./a"double"quote'
6655           `./a\\backslash'
6656           `./a\ttab'
6657           `./a\nnewline'
6658
6659 `clocale'
6660      Same as `locale', but `"' is used for both left and right
6661      quotation marks, if not provided by the currently selected locale:
6662
6663           $ tar tf arch.tar --quoting-style=clocale
6664           "./"
6665           "./a space"
6666           "./a'single'quote"
6667           "./a\"double\"quote"
6668           "./a\\backslash"
6669           "./a\ttab"
6670           "./a\nnewline"
6671
6672    You can specify which characters should be quoted in addition to
6673 those implied by the current quoting style:
6674
6675 `--quote-chars=STRING'
6676      Always quote characters from STRING, even if the selected quoting
6677      style would not quote them.
6678
6679    For example, using `escape' quoting (compare with the usual escape
6680 listing above):
6681
6682      $ tar tf arch.tar --quoting-style=escape --quote-chars=' "'
6683      ./
6684      ./a\ space
6685      ./a'single'quote
6686      ./a\"double\"quote
6687      ./a\\backslash
6688      ./a\ttab
6689      ./a\nnewline
6690
6691    To disable quoting of such additional characters, use the following
6692 option:
6693
6694 `--no-quote-chars=STRING'
6695      Remove characters listed in STRING from the list of quoted
6696      characters set by the previous `--quote-chars' option.
6697
6698    This option is particularly useful if you have added `--quote-chars'
6699 to your `TAR_OPTIONS' (*note TAR_OPTIONS::) and wish to disable it for
6700 the current invocation.
6701
6702    Note, that `--no-quote-chars' does _not_ disable those characters
6703 that are quoted by default in the selected quoting style.
6704
6705 \1f
6706 File: tar.info,  Node: transform,  Next: after,  Prev: quoting styles,  Up: Choosing
6707
6708 6.7 Modifying File and Member Names
6709 ===================================
6710
6711 `Tar' archives contain detailed information about files stored in them
6712 and full file names are part of that information.  When storing a file
6713 to an archive, its file name is recorded in it, along with the actual
6714 file contents.  When restoring from an archive, a file is created on
6715 disk with exactly the same name as that stored in the archive.  In the
6716 majority of cases this is the desired behavior of a file archiver.
6717 However, there are some cases when it is not.
6718
6719    First of all, it is often unsafe to extract archive members with
6720 absolute file names or those that begin with a `../'.  GNU `tar' takes
6721 special precautions when extracting such names and provides a special
6722 option for handling them, which is described in *note absolute::.
6723
6724    Secondly, you may wish to extract file names without some leading
6725 directory components, or with otherwise modified names.  In other cases
6726 it is desirable to store files under differing names in the archive.
6727
6728    GNU `tar' provides several options for these needs.
6729
6730 `--strip-components=NUMBER'
6731      Strip given NUMBER of leading components from file names before
6732      extraction.
6733
6734    For example, suppose you have archived whole `/usr' hierarchy to a
6735 tar archive named `usr.tar'.  Among other files, this archive contains
6736 `usr/include/stdlib.h', which you wish to extract to the current
6737 working directory.  To do so, you type:
6738
6739      $ tar -xf usr.tar --strip=2 usr/include/stdlib.h
6740
6741    The option `--strip=2' instructs `tar' to strip the two leading
6742 components (`usr/' and `include/') off the file name.
6743
6744    If you add the `--verbose' (`-v') option to the invocation above,
6745 you will note that the verbose listing still contains the full file
6746 name, with the two removed components still in place.  This can be
6747 inconvenient, so `tar' provides a special option for altering this
6748 behavior:
6749
6750 `--show-transformed-names'
6751      Display file or member names with all requested transformations
6752      applied.
6753
6754 For example:
6755
6756      $ tar -xf usr.tar -v --strip=2 usr/include/stdlib.h
6757      usr/include/stdlib.h
6758      $ tar -xf usr.tar -v --strip=2 --show-transformed usr/include/stdlib.h
6759      stdlib.h
6760
6761    Notice that in both cases the file `stdlib.h' is extracted to the
6762 current working directory, `--show-transformed-names' affects only the
6763 way its name is displayed.
6764
6765    This option is especially useful for verifying whether the invocation
6766 will have the desired effect.  Thus, before running
6767
6768      $ tar -x --strip=N
6769
6770 it is often advisable to run
6771
6772      $ tar -t -v --show-transformed --strip=N
6773
6774 to make sure the command will produce the intended results.
6775
6776    In case you need to apply more complex modifications to the file
6777 name, GNU `tar' provides a general-purpose transformation option:
6778
6779 `--transform=EXPRESSION'
6780 `--xform=EXPRESSION'
6781      Modify file names using supplied EXPRESSION.
6782
6783 The EXPRESSION is a `sed'-like replace expression of the form:
6784
6785      s/REGEXP/REPLACE/[FLAGS]
6786
6787 where REGEXP is a "regular expression", REPLACE is a replacement for
6788 each file name part that matches REGEXP.  Both REGEXP and REPLACE are
6789 described in detail in *note The "s" Command: (sed)The "s" Command.
6790
6791    Any delimiter can be used in lieu of `/', the only requirement being
6792 that it be used consistently throughout the expression. For example,
6793 the following two expressions are equivalent:
6794
6795      s/one/two/
6796      s,one,two,
6797
6798    Changing delimiters is often useful when the REGEX contains slashes.
6799 For example, it is more convenient to write `s,/,-,' than `s/\//-/'.
6800
6801    As in `sed', you can give several replace expressions, separated by
6802 a semicolon.
6803
6804    Supported FLAGS are:
6805
6806 `g'
6807      Apply the replacement to _all_ matches to the REGEXP, not just the
6808      first.
6809
6810 `i'
6811      Use case-insensitive matching.
6812
6813 `x'
6814      REGEXP is an "extended regular expression" (*note Extended regular
6815      expressions: (sed)Extended regexps.).
6816
6817 `NUMBER'
6818      Only replace the NUMBERth match of the REGEXP.
6819
6820      Note: the POSIX standard does not specify what should happen when
6821      you mix the `g' and NUMBER modifiers.  GNU `tar' follows the GNU
6822      `sed' implementation in this regard, so the interaction is defined
6823      to be: ignore matches before the NUMBERth, and then match and
6824      replace all matches from the NUMBERth on.
6825
6826
6827    In addition, several "transformation scope" flags are supported,
6828 that control to what files transformations apply.  These are:
6829
6830 `r'
6831      Apply transformation to regular archive members.
6832
6833 `R'
6834      Do not apply transformation to regular archive members.
6835
6836 `s'
6837      Apply transformation to symbolic link targets.
6838
6839 `S'
6840      Do not apply transformation to symbolic link targets.
6841
6842 `h'
6843      Apply transformation to hard link targets.
6844
6845 `H'
6846      Do not apply transformation to hard link targets.
6847
6848    Default is `rsh', which means to apply tranformations to both archive
6849 members and targets of symbolic and hard links.
6850
6851    Default scope flags can also be changed using `flags=' statement in
6852 the transform expression.  The flags set this way remain in force until
6853 next `flags=' statement or end of expression, whichever occurs first.
6854 For example:
6855
6856        --transform 'flags=S;s|^|/usr/local/|'
6857
6858    Here are several examples of `--transform' usage:
6859
6860   1. Extract `usr/' hierarchy into `usr/local/':
6861
6862           $ tar --transform='s,usr/,usr/local/,' -x -f arch.tar
6863
6864   2. Strip two leading directory components (equivalent to
6865      `--strip-components=2'):
6866
6867           $ tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar
6868
6869   3. Convert each file name to lower case:
6870
6871           $ tar --transform 's/.*/\L&/' -x -f arch.tar
6872
6873   4. Prepend `/prefix/'  to each file name:
6874
6875           $ tar --transform 's,^,/prefix/,' -x -f arch.tar
6876
6877   5. Archive the `/lib' directory, prepending `/usr/local' to each
6878      archive member:
6879
6880           $ tar --transform 's,^,/usr/local/,S' -c -f arch.tar /lib
6881
6882    Notice the use of flags in the last example.  The `/lib' directory
6883 often contains many symbolic links to files within it.  It may look,
6884 for example, like this:
6885
6886      $ ls -l
6887      drwxr-xr-x root/root       0 2008-07-08 16:20 /lib/
6888      -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /lib/libc-2.3.2.so
6889      lrwxrwxrwx root/root       0 2008-06-24 17:12 /lib/libc.so.6 -> libc-2.3.2.so
6890      ...
6891
6892    Using the expression `s,^,/usr/local/,' would mean adding
6893 `/usr/local' to both regular archive members and to link targets. In
6894 this case, `/lib/libc.so.6' would become:
6895
6896        /usr/local/lib/libc.so.6 -> /usr/local/libc-2.3.2.so
6897
6898    This is definitely not desired.  To avoid this, the `S' flag is
6899 used, which excludes symbolic link targets from filename
6900 transformations.  The result is:
6901
6902      $ tar --transform 's,^,/usr/local/,S', -c -v -f arch.tar \
6903             --show-transformed /lib
6904      drwxr-xr-x root/root       0 2008-07-08 16:20 /usr/local/lib/
6905      -rwxr-xr-x root/root 1250840 2008-05-25 07:44 /usr/local/lib/libc-2.3.2.so
6906      lrwxrwxrwx root/root       0 2008-06-24 17:12 /usr/local/lib/libc.so.6 \
6907       -> libc-2.3.2.so
6908
6909    Unlike `--strip-components', `--transform' can be used in any GNU
6910 `tar' operation mode.  For example, the following command adds files to
6911 the archive while replacing the leading `usr/' component with `var/':
6912
6913      $ tar -cf arch.tar --transform='s,^usr/,var/,' /
6914
6915    To test `--transform' effect we suggest using
6916 `--show-transformed-names' option:
6917
6918      $ tar -cf arch.tar --transform='s,^usr/,var/,' \
6919             --verbose --show-transformed-names /
6920
6921    If both `--strip-components' and `--transform' are used together,
6922 then `--transform' is applied first, and the required number of
6923 components is then stripped from its result.
6924
6925    You can use as many `--transform' options in a single command line
6926 as you want.  The specified expressions will then be applied in order
6927 of their appearance.  For example, the following two invocations are
6928 equivalent:
6929
6930      $ tar -cf arch.tar --transform='s,/usr/var,/var/' \
6931                              --transform='s,/usr/local,/usr/,'
6932      $ tar -cf arch.tar \
6933                     --transform='s,/usr/var,/var/;s,/usr/local,/usr/,'
6934
6935 \1f
6936 File: tar.info,  Node: after,  Next: recurse,  Prev: transform,  Up: Choosing
6937
6938 6.8 Operating Only on New Files
6939 ===============================
6940
6941 The `--after-date=DATE' (`--newer=DATE', `-N DATE') option causes `tar'
6942 to only work on files whose data modification or status change times
6943 are newer than the DATE given.  If DATE starts with `/' or `.', it is
6944 taken to be a file name; the data modification time of that file is
6945 used as the date. If you use this option when creating or appending to
6946 an archive, the archive will only include new files.  If you use
6947 `--after-date' when extracting an archive, `tar' will only extract
6948 files newer than the DATE you specify.
6949
6950    If you only want `tar' to make the date comparison based on
6951 modification of the file's data (rather than status changes), then use
6952 the `--newer-mtime=DATE' option.
6953
6954    You may use these options with any operation.  Note that these
6955 options differ from the `--update' (`-u') operation in that they allow
6956 you to specify a particular date against which `tar' can compare when
6957 deciding whether or not to archive the files.
6958
6959 `--after-date=DATE'
6960 `--newer=DATE'
6961 `-N DATE'
6962      Only store files newer than DATE.
6963
6964      Acts on files only if their data modification or status change
6965      times are later than DATE.  Use in conjunction with any operation.
6966
6967      If DATE starts with `/' or `.', it is taken to be a file name; the
6968      data modification time of that file is used as the date.
6969
6970 `--newer-mtime=DATE'
6971      Acts like `--after-date', but only looks at data modification
6972      times.
6973
6974    These options limit `tar' to operate only on files which have been
6975 modified after the date specified.  A file's status is considered to
6976 have changed if its contents have been modified, or if its owner,
6977 permissions, and so forth, have been changed.  (For more information on
6978 how to specify a date, see *note Date input formats::; remember that the
6979 entire date argument must be quoted if it contains any spaces.)
6980
6981    Gurus would say that `--after-date' tests both the data modification
6982 time (`mtime', the time the contents of the file were last modified)
6983 and the status change time (`ctime', the time the file's status was
6984 last changed: owner, permissions, etc.)  fields, while `--newer-mtime'
6985 tests only the `mtime' field.
6986
6987    To be precise, `--after-date' checks _both_ `mtime' and `ctime' and
6988 processes the file if either one is more recent than DATE, while
6989 `--newer-mtime' only checks `mtime' and disregards `ctime'.  Neither
6990 does it use `atime' (the last time the contents of the file were looked
6991 at).
6992
6993    Date specifiers can have embedded spaces.  Because of this, you may
6994 need to quote date arguments to keep the shell from parsing them as
6995 separate arguments.  For example, the following command will add to the
6996 archive all the files modified less than two days ago:
6997
6998      $ tar -cf foo.tar --newer-mtime '2 days ago'
6999
7000    When any of these options is used with the option `--verbose' (*note
7001 verbose tutorial::) GNU `tar' will try to convert the specified date
7002 back to its textual representation and compare that with the one given
7003 with the option.  If the two dates differ, `tar' will print a warning
7004 saying what date it will use.  This is to help user ensure he is using
7005 the right date.  For example:
7006
7007      $ tar -c -f archive.tar --after-date='10 days ago' .
7008      tar: Option --after-date: Treating date `10 days ago' as 2006-06-11
7009      13:19:37.232434
7010
7011      *Please Note:* `--after-date' and `--newer-mtime' should not be
7012      used for incremental backups.  *Note Incremental Dumps::, for
7013      proper way of creating incremental backups.
7014
7015 \1f
7016 File: tar.info,  Node: recurse,  Next: one,  Prev: after,  Up: Choosing
7017
7018 6.9 Descending into Directories
7019 ===============================
7020
7021 Usually, `tar' will recursively explore all directories (either those
7022 given on the command line or through the `--files-from' option) for the
7023 various files they contain.  However, you may not always want `tar' to
7024 act this way.
7025
7026    The `--no-recursion' option inhibits `tar''s recursive descent into
7027 specified directories.  If you specify `--no-recursion', you can use
7028 the `find' (*note find: (find)Top.)  utility for hunting through levels
7029 of directories to construct a list of file names which you could then
7030 pass to `tar'.  `find' allows you to be more selective when choosing
7031 which files to archive; see *note files::, for more information on
7032 using `find' with `tar'.
7033
7034 `--no-recursion'
7035      Prevents `tar' from recursively descending directories.
7036
7037 `--recursion'
7038      Requires `tar' to recursively descend directories.  This is the
7039      default.
7040
7041    When you use `--no-recursion', GNU `tar' grabs directory entries
7042 themselves, but does not descend on them recursively.  Many people use
7043 `find' for locating files they want to back up, and since `tar'
7044 _usually_ recursively descends on directories, they have to use the
7045 `-not -type d' test in their `find' invocation (*note Type:
7046 (find)Type.), as they usually do not want all the files in a directory.
7047 They then use the `--files-from' option to archive the files located
7048 via `find'.
7049
7050    The problem when restoring files archived in this manner is that the
7051 directories themselves are not in the archive; so the
7052 `--same-permissions' (`--preserve-permissions', `-p') option does not
7053 affect them--while users might really like it to.  Specifying
7054 `--no-recursion' is a way to tell `tar' to grab only the directory
7055 entries given to it, adding no new files on its own.  To summarize, if
7056 you use `find' to create a list of files to be stored in an archive,
7057 use it as follows:
7058
7059      $ find DIR TESTS | \
7060        tar -cf ARCHIVE -T - --no-recursion
7061
7062    The `--no-recursion' option also applies when extracting: it causes
7063 `tar' to extract only the matched directory entries, not the files
7064 under those directories.
7065
7066    The `--no-recursion' option also affects how globbing patterns are
7067 interpreted (*note controlling pattern-matching::).
7068
7069    The `--no-recursion' and `--recursion' options apply to later
7070 options and operands, and can be overridden by later occurrences of
7071 `--no-recursion' and `--recursion'.  For example:
7072
7073      $ tar -cf jams.tar --no-recursion grape --recursion grape/concord
7074
7075 creates an archive with one entry for `grape', and the recursive
7076 contents of `grape/concord', but no entries under `grape' other than
7077 `grape/concord'.
7078
7079 \1f
7080 File: tar.info,  Node: one,  Prev: recurse,  Up: Choosing
7081
7082 6.10 Crossing File System Boundaries
7083 ====================================
7084
7085 `tar' will normally automatically cross file system boundaries in order
7086 to archive files which are part of a directory tree.  You can change
7087 this behavior by running `tar' and specifying `--one-file-system'.
7088 This option only affects files that are archived because they are in a
7089 directory that is being archived; `tar' will still archive files
7090 explicitly named on the command line or through `--files-from',
7091 regardless of where they reside.
7092
7093 `--one-file-system'
7094      Prevents `tar' from crossing file system boundaries when
7095      archiving.  Use in conjunction with any write operation.
7096
7097    The `--one-file-system' option causes `tar' to modify its normal
7098 behavior in archiving the contents of directories.  If a file in a
7099 directory is not on the same file system as the directory itself, then
7100 `tar' will not archive that file.  If the file is a directory itself,
7101 `tar' will not archive anything beneath it; in other words, `tar' will
7102 not cross mount points.
7103
7104    This option is useful for making full or incremental archival
7105 backups of a file system.  If this option is used in conjunction with
7106 `--verbose' (`-v'), files that are excluded are mentioned by name on
7107 the standard error.
7108
7109 * Menu:
7110
7111 * directory::                   Changing Directory
7112 * absolute::                    Absolute File Names
7113
7114 \1f
7115 File: tar.info,  Node: directory,  Next: absolute,  Up: one
7116
7117 6.10.1 Changing the Working Directory
7118 -------------------------------------
7119
7120 To change the working directory in the middle of a list of file names,
7121 either on the command line or in a file specified using `--files-from'
7122 (`-T'), use `--directory' (`-C').  This will change the working
7123 directory to the specified directory after that point in the list.
7124
7125 `--directory=DIRECTORY'
7126 `-C DIRECTORY'
7127      Changes the working directory in the middle of a command line.
7128
7129    For example,
7130
7131      $ tar -c -f jams.tar grape prune -C food cherry
7132
7133 will place the files `grape' and `prune' from the current directory
7134 into the archive `jams.tar', followed by the file `cherry' from the
7135 directory `food'.  This option is especially useful when you have
7136 several widely separated files that you want to store in the same
7137 archive.
7138
7139    Note that the file `cherry' is recorded in the archive under the
7140 precise name `cherry', _not_ `food/cherry'.  Thus, the archive will
7141 contain three files that all appear to have come from the same
7142 directory; if the archive is extracted with plain `tar --extract', all
7143 three files will be written in the current directory.
7144
7145    Contrast this with the command,
7146
7147      $ tar -c -f jams.tar grape prune -C food red/cherry
7148
7149 which records the third file in the archive under the name `red/cherry'
7150 so that, if the archive is extracted using `tar --extract', the third
7151 file will be written in a subdirectory named `red'.
7152
7153    You can use the `--directory' option to make the archive independent
7154 of the original name of the directory holding the files.  The following
7155 command places the files `/etc/passwd', `/etc/hosts', and `/lib/libc.a'
7156 into the archive `foo.tar':
7157
7158      $ tar -c -f foo.tar -C /etc passwd hosts -C /lib libc.a
7159
7160 However, the names of the archive members will be exactly what they were
7161 on the command line: `passwd', `hosts', and `libc.a'.  They will not
7162 appear to be related by file name to the original directories where
7163 those files were located.
7164
7165    Note that `--directory' options are interpreted consecutively.  If
7166 `--directory' specifies a relative file name, it is interpreted
7167 relative to the then current directory, which might not be the same as
7168 the original current working directory of `tar', due to a previous
7169 `--directory' option.
7170
7171    When using `--files-from' (*note files::), you can put various `tar'
7172 options (including `-C') in the file list.  Notice, however, that in
7173 this case the option and its argument may not be separated by
7174 whitespace.  If you use short option, its argument must either follow
7175 the option letter immediately, without any intervening whitespace, or
7176 occupy the next line.  Otherwise, if you use long option, separate its
7177 argument by an equal sign.
7178
7179    For instance, the file list for the above example will be:
7180
7181      -C/etc
7182      passwd
7183      hosts
7184      --directory=/lib
7185      libc.a
7186
7187 To use it, you would invoke `tar' as follows:
7188
7189      $ tar -c -f foo.tar --files-from list
7190
7191    The interpretation of `--directory' is disabled by `--null' option.
7192
7193 \1f
7194 File: tar.info,  Node: absolute,  Prev: directory,  Up: one
7195
7196 6.10.2 Absolute File Names
7197 --------------------------
7198
7199 By default, GNU `tar' drops a leading `/' on input or output, and
7200 complains about file names containing a `..' component.  There is an
7201 option that turns off this behavior:
7202
7203 `--absolute-names'
7204 `-P'
7205      Do not strip leading slashes from file names, and permit file names
7206      containing a `..' file name component.
7207
7208    When `tar' extracts archive members from an archive, it strips any
7209 leading slashes (`/') from the member name.  This causes absolute
7210 member names in the archive to be treated as relative file names.  This
7211 allows you to have such members extracted wherever you want, instead of
7212 being restricted to extracting the member in the exact directory named
7213 in the archive.  For example, if the archive member has the name
7214 `/etc/passwd', `tar' will extract it as if the name were really
7215 `etc/passwd'.
7216
7217    File names containing `..' can cause problems when extracting, so
7218 `tar' normally warns you about such files when creating an archive, and
7219 rejects attempts to extracts such files.
7220
7221    Other `tar' programs do not do this.  As a result, if you create an
7222 archive whose member names start with a slash, they will be difficult
7223 for other people with a non-GNU `tar' program to use.  Therefore, GNU
7224 `tar' also strips leading slashes from member names when putting
7225 members into the archive.  For example, if you ask `tar' to add the file
7226 `/bin/ls' to an archive, it will do so, but the member name will be
7227 `bin/ls'(1).
7228
7229    If you use the `--absolute-names' (`-P') option, `tar' will do none
7230 of these transformations.
7231
7232    To archive or extract files relative to the root directory, specify
7233 the `--absolute-names' (`-P') option.
7234
7235    Normally, `tar' acts on files relative to the working
7236 directory--ignoring superior directory names when archiving, and
7237 ignoring leading slashes when extracting.
7238
7239    When you specify `--absolute-names' (`-P'), `tar' stores file names
7240 including all superior directory names, and preserves leading slashes.
7241 If you only invoked `tar' from the root directory you would never need
7242 the `--absolute-names' option, but using this option may be more
7243 convenient than switching to root.
7244
7245 `--absolute-names'
7246      Preserves full file names (including superior directory names) when
7247      archiving files.  Preserves leading slash when extracting files.
7248
7249
7250    `tar' prints out a message about removing the `/' from file names.
7251 This message appears once per GNU `tar' invocation.  It represents
7252 something which ought to be told; ignoring what it means can cause very
7253 serious surprises, later.
7254
7255    Some people, nevertheless, do not want to see this message.  Wanting
7256 to play really dangerously, one may of course redirect `tar' standard
7257 error to the sink.  For example, under `sh':
7258
7259      $ tar -c -f archive.tar /home 2> /dev/null
7260
7261 Another solution, both nicer and simpler, would be to change to the `/'
7262 directory first, and then avoid absolute notation.  For example:
7263
7264      $ tar -c -f archive.tar -C / home
7265
7266    *Note Integrity::, for some of the security-related implications of
7267 using this option.
7268
7269    ---------- Footnotes ----------
7270
7271    (1) A side effect of this is that when `--create' is used with
7272 `--verbose' the resulting output is not, generally speaking, the same
7273 as the one you'd get running `tar --list' command.  This may be
7274 important if you use some scripts for comparing both outputs.  *Note
7275 listing member and file names::, for the information on how to handle
7276 this case.
7277
7278 \1f
7279 File: tar.info,  Node: Date input formats,  Next: Formats,  Prev: Choosing,  Up: Top
7280
7281 7 Date input formats
7282 ********************
7283
7284 First, a quote:
7285
7286      Our units of temporal measurement, from seconds on up to months,
7287      are so complicated, asymmetrical and disjunctive so as to make
7288      coherent mental reckoning in time all but impossible.  Indeed, had
7289      some tyrannical god contrived to enslave our minds to time, to
7290      make it all but impossible for us to escape subjection to sodden
7291      routines and unpleasant surprises, he could hardly have done
7292      better than handing down our present system.  It is like a set of
7293      trapezoidal building blocks, with no vertical or horizontal
7294      surfaces, like a language in which the simplest thought demands
7295      ornate constructions, useless particles and lengthy
7296      circumlocutions.  Unlike the more successful patterns of language
7297      and science, which enable us to face experience boldly or at least
7298      level-headedly, our system of temporal calculation silently and
7299      persistently encourages our terror of time.
7300
7301      ...  It is as though architects had to measure length in feet,
7302      width in meters and height in ells; as though basic instruction
7303      manuals demanded a knowledge of five different languages.  It is
7304      no wonder then that we often look into our own immediate past or
7305      future, last Tuesday or a week from Sunday, with feelings of
7306      helpless confusion.  ...
7307
7308      -- Robert Grudin, `Time and the Art of Living'.
7309
7310    This section describes the textual date representations that GNU
7311 programs accept.  These are the strings you, as a user, can supply as
7312 arguments to the various programs.  The C interface (via the
7313 `parse_datetime' function) is not described here.
7314
7315 * Menu:
7316
7317 * General date syntax::            Common rules.
7318 * Calendar date items::            19 Dec 1994.
7319 * Time of day items::              9:20pm.
7320 * Time zone items::                EST, PDT, GMT.
7321 * Day of week items::              Monday and others.
7322 * Relative items in date strings:: next tuesday, 2 years ago.
7323 * Pure numbers in date strings::   19931219, 1440.
7324 * Seconds since the Epoch::        @1078100502.
7325 * Specifying time zone rules::     TZ="America/New_York", TZ="UTC0".
7326 * Authors of parse_datetime::      Bellovin, Eggert, Salz, Berets, et al.
7327
7328 \1f
7329 File: tar.info,  Node: General date syntax,  Next: Calendar date items,  Up: Date input formats
7330
7331 7.1 General date syntax
7332 =======================
7333
7334 A "date" is a string, possibly empty, containing many items separated
7335 by whitespace.  The whitespace may be omitted when no ambiguity arises.
7336 The empty string means the beginning of today (i.e., midnight).  Order
7337 of the items is immaterial.  A date string may contain many flavors of
7338 items:
7339
7340    * calendar date items
7341
7342    * time of day items
7343
7344    * time zone items
7345
7346    * day of the week items
7347
7348    * relative items
7349
7350    * pure numbers.
7351
7352 We describe each of these item types in turn, below.
7353
7354    A few ordinal numbers may be written out in words in some contexts.
7355 This is most useful for specifying day of the week items or relative
7356 items (see below).  Among the most commonly used ordinal numbers, the
7357 word `last' stands for -1, `this' stands for 0, and `first' and `next'
7358 both stand for 1.  Because the word `second' stands for the unit of
7359 time there is no way to write the ordinal number 2, but for convenience
7360 `third' stands for 3, `fourth' for 4, `fifth' for 5, `sixth' for 6,
7361 `seventh' for 7, `eighth' for 8, `ninth' for 9, `tenth' for 10,
7362 `eleventh' for 11 and `twelfth' for 12.
7363
7364    When a month is written this way, it is still considered to be
7365 written numerically, instead of being "spelled in full"; this changes
7366 the allowed strings.
7367
7368    In the current implementation, only English is supported for words
7369 and abbreviations like `AM', `DST', `EST', `first', `January',
7370 `Sunday', `tomorrow', and `year'.
7371
7372    The output of the `date' command is not always acceptable as a date
7373 string, not only because of the language problem, but also because
7374 there is no standard meaning for time zone items like `IST'.  When using
7375 `date' to generate a date string intended to be parsed later, specify a
7376 date format that is independent of language and that does not use time
7377 zone items other than `UTC' and `Z'.  Here are some ways to do this:
7378
7379      $ LC_ALL=C TZ=UTC0 date
7380      Mon Mar  1 00:21:42 UTC 2004
7381      $ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ'
7382      2004-03-01 00:21:42Z
7383      $ date --iso-8601=ns | tr T ' '  # --iso-8601 is a GNU extension.
7384      2004-02-29 16:21:42,692722128-0800
7385      $ date --rfc-2822  # a GNU extension
7386      Sun, 29 Feb 2004 16:21:42 -0800
7387      $ date +'%Y-%m-%d %H:%M:%S %z'  # %z is a GNU extension.
7388      2004-02-29 16:21:42 -0800
7389      $ date +'@%s.%N'  # %s and %N are GNU extensions.
7390      @1078100502.692722128
7391
7392    Alphabetic case is completely ignored in dates.  Comments may be
7393 introduced between round parentheses, as long as included parentheses
7394 are properly nested.  Hyphens not followed by a digit are currently
7395 ignored.  Leading zeros on numbers are ignored.
7396
7397    Invalid dates like `2005-02-29' or times like `24:00' are rejected.
7398 In the typical case of a host that does not support leap seconds, a
7399 time like `23:59:60' is rejected even if it corresponds to a valid leap
7400 second.
7401
7402 \1f
7403 File: tar.info,  Node: Calendar date items,  Next: Time of day items,  Prev: General date syntax,  Up: Date input formats
7404
7405 7.2 Calendar date items
7406 =======================
7407
7408 A "calendar date item" specifies a day of the year.  It is specified
7409 differently, depending on whether the month is specified numerically or
7410 literally.  All these strings specify the same calendar date:
7411
7412      1972-09-24     # ISO 8601.
7413      72-9-24        # Assume 19xx for 69 through 99,
7414                     # 20xx for 00 through 68.
7415      72-09-24       # Leading zeros are ignored.
7416      9/24/72        # Common U.S. writing.
7417      24 September 1972
7418      24 Sept 72     # September has a special abbreviation.
7419      24 Sep 72      # Three-letter abbreviations always allowed.
7420      Sep 24, 1972
7421      24-sep-72
7422      24sep72
7423
7424    The year can also be omitted.  In this case, the last specified year
7425 is used, or the current year if none.  For example:
7426
7427      9/24
7428      sep 24
7429
7430    Here are the rules.
7431
7432    For numeric months, the ISO 8601 format `YEAR-MONTH-DAY' is allowed,
7433 where YEAR is any positive number, MONTH is a number between 01 and 12,
7434 and DAY is a number between 01 and 31.  A leading zero must be present
7435 if a number is less than ten.  If YEAR is 68 or smaller, then 2000 is
7436 added to it; otherwise, if YEAR is less than 100, then 1900 is added to
7437 it.  The construct `MONTH/DAY/YEAR', popular in the United States, is
7438 accepted.  Also `MONTH/DAY', omitting the year.
7439
7440    Literal months may be spelled out in full: `January', `February',
7441 `March', `April', `May', `June', `July', `August', `September',
7442 `October', `November' or `December'.  Literal months may be abbreviated
7443 to their first three letters, possibly followed by an abbreviating dot.
7444 It is also permitted to write `Sept' instead of `September'.
7445
7446    When months are written literally, the calendar date may be given as
7447 any of the following:
7448
7449      DAY MONTH YEAR
7450      DAY MONTH
7451      MONTH DAY YEAR
7452      DAY-MONTH-YEAR
7453
7454    Or, omitting the year:
7455
7456      MONTH DAY
7457
7458 \1f
7459 File: tar.info,  Node: Time of day items,  Next: Time zone items,  Prev: Calendar date items,  Up: Date input formats
7460
7461 7.3 Time of day items
7462 =====================
7463
7464 A "time of day item" in date strings specifies the time on a given day.
7465 Here are some examples, all of which represent the same time:
7466
7467      20:02:00.000000
7468      20:02
7469      8:02pm
7470      20:02-0500      # In EST (U.S. Eastern Standard Time).
7471
7472    More generally, the time of day may be given as
7473 `HOUR:MINUTE:SECOND', where HOUR is a number between 0 and 23, MINUTE
7474 is a number between 0 and 59, and SECOND is a number between 0 and 59
7475 possibly followed by `.' or `,' and a fraction containing one or more
7476 digits.  Alternatively, `:SECOND' can be omitted, in which case it is
7477 taken to be zero.  On the rare hosts that support leap seconds, SECOND
7478 may be 60.
7479
7480    If the time is followed by `am' or `pm' (or `a.m.' or `p.m.'), HOUR
7481 is restricted to run from 1 to 12, and `:MINUTE' may be omitted (taken
7482 to be zero).  `am' indicates the first half of the day, `pm' indicates
7483 the second half of the day.  In this notation, 12 is the predecessor of
7484 1: midnight is `12am' while noon is `12pm'.  (This is the zero-oriented
7485 interpretation of `12am' and `12pm', as opposed to the old tradition
7486 derived from Latin which uses `12m' for noon and `12pm' for midnight.)
7487
7488    The time may alternatively be followed by a time zone correction,
7489 expressed as `SHHMM', where S is `+' or `-', HH is a number of zone
7490 hours and MM is a number of zone minutes.  The zone minutes term, MM,
7491 may be omitted, in which case the one- or two-digit correction is
7492 interpreted as a number of hours.  You can also separate HH from MM
7493 with a colon.  When a time zone correction is given this way, it forces
7494 interpretation of the time relative to Coordinated Universal Time
7495 (UTC), overriding any previous specification for the time zone or the
7496 local time zone.  For example, `+0530' and `+05:30' both stand for the
7497 time zone 5.5 hours ahead of UTC (e.g., India).  This is the best way to
7498 specify a time zone correction by fractional parts of an hour.  The
7499 maximum zone correction is 24 hours.
7500
7501    Either `am'/`pm' or a time zone correction may be specified, but not
7502 both.
7503
7504 \1f
7505 File: tar.info,  Node: Time zone items,  Next: Day of week items,  Prev: Time of day items,  Up: Date input formats
7506
7507 7.4 Time zone items
7508 ===================
7509
7510 A "time zone item" specifies an international time zone, indicated by a
7511 small set of letters, e.g., `UTC' or `Z' for Coordinated Universal
7512 Time.  Any included periods are ignored.  By following a
7513 non-daylight-saving time zone by the string `DST' in a separate word
7514 (that is, separated by some white space), the corresponding daylight
7515 saving time zone may be specified.  Alternatively, a
7516 non-daylight-saving time zone can be followed by a time zone
7517 correction, to add the two values.  This is normally done only for
7518 `UTC'; for example, `UTC+05:30' is equivalent to `+05:30'.
7519
7520    Time zone items other than `UTC' and `Z' are obsolescent and are not
7521 recommended, because they are ambiguous; for example, `EST' has a
7522 different meaning in Australia than in the United States.  Instead,
7523 it's better to use unambiguous numeric time zone corrections like
7524 `-0500', as described in the previous section.
7525
7526    If neither a time zone item nor a time zone correction is supplied,
7527 time stamps are interpreted using the rules of the default time zone
7528 (*note Specifying time zone rules::).
7529
7530 \1f
7531 File: tar.info,  Node: Day of week items,  Next: Relative items in date strings,  Prev: Time zone items,  Up: Date input formats
7532
7533 7.5 Day of week items
7534 =====================
7535
7536 The explicit mention of a day of the week will forward the date (only
7537 if necessary) to reach that day of the week in the future.
7538
7539    Days of the week may be spelled out in full: `Sunday', `Monday',
7540 `Tuesday', `Wednesday', `Thursday', `Friday' or `Saturday'.  Days may
7541 be abbreviated to their first three letters, optionally followed by a
7542 period.  The special abbreviations `Tues' for `Tuesday', `Wednes' for
7543 `Wednesday' and `Thur' or `Thurs' for `Thursday' are also allowed.
7544
7545    A number may precede a day of the week item to move forward
7546 supplementary weeks.  It is best used in expression like `third
7547 monday'.  In this context, `last DAY' or `next DAY' is also acceptable;
7548 they move one week before or after the day that DAY by itself would
7549 represent.
7550
7551    A comma following a day of the week item is ignored.
7552
7553 \1f
7554 File: tar.info,  Node: Relative items in date strings,  Next: Pure numbers in date strings,  Prev: Day of week items,  Up: Date input formats
7555
7556 7.6 Relative items in date strings
7557 ==================================
7558
7559 "Relative items" adjust a date (or the current date if none) forward or
7560 backward.  The effects of relative items accumulate.  Here are some
7561 examples:
7562
7563      1 year
7564      1 year ago
7565      3 years
7566      2 days
7567
7568    The unit of time displacement may be selected by the string `year'
7569 or `month' for moving by whole years or months.  These are fuzzy units,
7570 as years and months are not all of equal duration.  More precise units
7571 are `fortnight' which is worth 14 days, `week' worth 7 days, `day'
7572 worth 24 hours, `hour' worth 60 minutes, `minute' or `min' worth 60
7573 seconds, and `second' or `sec' worth one second.  An `s' suffix on
7574 these units is accepted and ignored.
7575
7576    The unit of time may be preceded by a multiplier, given as an
7577 optionally signed number.  Unsigned numbers are taken as positively
7578 signed.  No number at all implies 1 for a multiplier.  Following a
7579 relative item by the string `ago' is equivalent to preceding the unit
7580 by a multiplier with value -1.
7581
7582    The string `tomorrow' is worth one day in the future (equivalent to
7583 `day'), the string `yesterday' is worth one day in the past (equivalent
7584 to `day ago').
7585
7586    The strings `now' or `today' are relative items corresponding to
7587 zero-valued time displacement, these strings come from the fact a
7588 zero-valued time displacement represents the current time when not
7589 otherwise changed by previous items.  They may be used to stress other
7590 items, like in `12:00 today'.  The string `this' also has the meaning
7591 of a zero-valued time displacement, but is preferred in date strings
7592 like `this thursday'.
7593
7594    When a relative item causes the resulting date to cross a boundary
7595 where the clocks were adjusted, typically for daylight saving time, the
7596 resulting date and time are adjusted accordingly.
7597
7598    The fuzz in units can cause problems with relative items.  For
7599 example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because
7600 2003-06-31 is an invalid date.  To determine the previous month more
7601 reliably, you can ask for the month before the 15th of the current
7602 month.  For example:
7603
7604      $ date -R
7605      Thu, 31 Jul 2003 13:02:39 -0700
7606      $ date --date='-1 month' +'Last month was %B?'
7607      Last month was July?
7608      $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
7609      Last month was June!
7610
7611    Also, take care when manipulating dates around clock changes such as
7612 daylight saving leaps.  In a few cases these have added or subtracted
7613 as much as 24 hours from the clock, so it is often wise to adopt
7614 universal time by setting the `TZ' environment variable to `UTC0'
7615 before embarking on calendrical calculations.
7616
7617 \1f
7618 File: tar.info,  Node: Pure numbers in date strings,  Next: Seconds since the Epoch,  Prev: Relative items in date strings,  Up: Date input formats
7619
7620 7.7 Pure numbers in date strings
7621 ================================
7622
7623 The precise interpretation of a pure decimal number depends on the
7624 context in the date string.
7625
7626    If the decimal number is of the form YYYYMMDD and no other calendar
7627 date item (*note Calendar date items::) appears before it in the date
7628 string, then YYYY is read as the year, MM as the month number and DD as
7629 the day of the month, for the specified calendar date.
7630
7631    If the decimal number is of the form HHMM and no other time of day
7632 item appears before it in the date string, then HH is read as the hour
7633 of the day and MM as the minute of the hour, for the specified time of
7634 day.  MM can also be omitted.
7635
7636    If both a calendar date and a time of day appear to the left of a
7637 number in the date string, but no relative item, then the number
7638 overrides the year.
7639
7640 \1f
7641 File: tar.info,  Node: Seconds since the Epoch,  Next: Specifying time zone rules,  Prev: Pure numbers in date strings,  Up: Date input formats
7642
7643 7.8 Seconds since the Epoch
7644 ===========================
7645
7646 If you precede a number with `@', it represents an internal time stamp
7647 as a count of seconds.  The number can contain an internal decimal
7648 point (either `.' or `,'); any excess precision not supported by the
7649 internal representation is truncated toward minus infinity.  Such a
7650 number cannot be combined with any other date item, as it specifies a
7651 complete time stamp.
7652
7653    Internally, computer times are represented as a count of seconds
7654 since an epoch--a well-defined point of time.  On GNU and POSIX
7655 systems, the epoch is 1970-01-01 00:00:00 UTC, so `@0' represents this
7656 time, `@1' represents 1970-01-01 00:00:01 UTC, and so forth.  GNU and
7657 most other POSIX-compliant systems support such times as an extension
7658 to POSIX, using negative counts, so that `@-1' represents 1969-12-31
7659 23:59:59 UTC.
7660
7661    Traditional Unix systems count seconds with 32-bit two's-complement
7662 integers and can represent times from 1901-12-13 20:45:52 through
7663 2038-01-19 03:14:07 UTC.  More modern systems use 64-bit counts of
7664 seconds with nanosecond subcounts, and can represent all the times in
7665 the known lifetime of the universe to a resolution of 1 nanosecond.
7666
7667    On most hosts, these counts ignore the presence of leap seconds.
7668 For example, on most hosts `@915148799' represents 1998-12-31 23:59:59
7669 UTC, `@915148800' represents 1999-01-01 00:00:00 UTC, and there is no
7670 way to represent the intervening leap second 1998-12-31 23:59:60 UTC.
7671
7672 \1f
7673 File: tar.info,  Node: Specifying time zone rules,  Next: Authors of parse_datetime,  Prev: Seconds since the Epoch,  Up: Date input formats
7674
7675 7.9 Specifying time zone rules
7676 ==============================
7677
7678 Normally, dates are interpreted using the rules of the current time
7679 zone, which in turn are specified by the `TZ' environment variable, or
7680 by a system default if `TZ' is not set.  To specify a different set of
7681 default time zone rules that apply just to one date, start the date
7682 with a string of the form `TZ="RULE"'.  The two quote characters (`"')
7683 must be present in the date, and any quotes or backslashes within RULE
7684 must be escaped by a backslash.
7685
7686    For example, with the GNU `date' command you can answer the question
7687 "What time is it in New York when a Paris clock shows 6:30am on October
7688 31, 2004?" by using a date beginning with `TZ="Europe/Paris"' as shown
7689 in the following shell transcript:
7690
7691      $ export TZ="America/New_York"
7692      $ date --date='TZ="Europe/Paris" 2004-10-31 06:30'
7693      Sun Oct 31 01:30:00 EDT 2004
7694
7695    In this example, the `--date' operand begins with its own `TZ'
7696 setting, so the rest of that operand is processed according to
7697 `Europe/Paris' rules, treating the string `2004-10-31 06:30' as if it
7698 were in Paris.  However, since the output of the `date' command is
7699 processed according to the overall time zone rules, it uses New York
7700 time.  (Paris was normally six hours ahead of New York in 2004, but
7701 this example refers to a brief Halloween period when the gap was five
7702 hours.)
7703
7704    A `TZ' value is a rule that typically names a location in the `tz'
7705 database (http://www.twinsun.com/tz/tz-link.htm).  A recent catalog of
7706 location names appears in the TWiki Date and Time Gateway
7707 (http://twiki.org/cgi-bin/xtra/tzdate).  A few non-GNU hosts require a
7708 colon before a location name in a `TZ' setting, e.g.,
7709 `TZ=":America/New_York"'.
7710
7711    The `tz' database includes a wide variety of locations ranging from
7712 `Arctic/Longyearbyen' to `Antarctica/South_Pole', but if you are at sea
7713 and have your own private time zone, or if you are using a non-GNU host
7714 that does not support the `tz' database, you may need to use a POSIX
7715 rule instead.  Simple POSIX rules like `UTC0' specify a time zone
7716 without daylight saving time; other rules can specify simple daylight
7717 saving regimes.  *Note Specifying the Time Zone with `TZ': (libc)TZ
7718 Variable.
7719
7720 \1f
7721 File: tar.info,  Node: Authors of parse_datetime,  Prev: Specifying time zone rules,  Up: Date input formats
7722
7723 7.10 Authors of `parse_datetime'
7724 ================================
7725
7726 `parse_datetime' started life as `getdate', as originally implemented
7727 by Steven M. Bellovin (<smb@research.att.com>) while at the University
7728 of North Carolina at Chapel Hill.  The code was later tweaked by a
7729 couple of people on Usenet, then completely overhauled by Rich $alz
7730 (<rsalz@bbn.com>) and Jim Berets (<jberets@bbn.com>) in August, 1990.
7731 Various revisions for the GNU system were made by David MacKenzie, Jim
7732 Meyering, Paul Eggert and others, including renaming it to `get_date' to
7733 avoid a conflict with the alternative Posix function `getdate', and a
7734 later rename to `parse_datetime'.  The Posix function `getdate' can
7735 parse more locale-specific dates using `strptime', but relies on an
7736 environment variable and external file, and lacks the thread-safety of
7737 `parse_datetime'.
7738
7739    This chapter was originally produced by Franc,ois Pinard
7740 (<pinard@iro.umontreal.ca>) from the `parse_datetime.y' source code,
7741 and then edited by K. Berry (<kb@cs.umb.edu>).
7742